toolbox-x 2.0.14 → 2.2.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 (53) hide show
  1. package/dist/{Color-B2SgCGbm.d.mts → Color-CInCJvH7.d.mts} +98 -14
  2. package/dist/{Color-asKZqwDF.d.cts → Color-CVRcGmWe.d.cts} +98 -14
  3. package/dist/{Stylog-CRNMQ_uV.d.cts → Stylog-00MmV27Z.d.cts} +1 -1
  4. package/dist/{Stylog-Cvzo5z86.d.mts → Stylog-Bi1f4CR9.d.mts} +1 -1
  5. package/dist/{basics-Dald7J6c.mjs → basics-20lm69yy.mjs} +5 -98
  6. package/dist/{basics-Bb5ovcvz.cjs → basics-byj0VH1c.cjs} +5 -140
  7. package/dist/colors.cjs +130 -24
  8. package/dist/colors.d.cts +2 -2
  9. package/dist/colors.d.mts +2 -2
  10. package/dist/colors.mjs +130 -24
  11. package/dist/constants.cjs +14 -14
  12. package/dist/constants.mjs +1 -1
  13. package/dist/{convert-Cqy2Llek.cjs → convert-BjKz_hhr.cjs} +6 -2
  14. package/dist/{convert-lXdkXPJR.mjs → convert-DRZXcjcS.mjs} +6 -2
  15. package/dist/date.cjs +6 -6
  16. package/dist/date.mjs +4 -4
  17. package/dist/dom.cjs +9 -8
  18. package/dist/dom.mjs +4 -3
  19. package/dist/{guards-D8Iz6EEy.cjs → guards-BSwFQX1M.cjs} +3 -3
  20. package/dist/{guards-DziDBD0p.mjs → guards-CNG9gnvL.mjs} +1 -1
  21. package/dist/guards-CqbVT4L5.cjs +156 -0
  22. package/dist/{guards-DGN95D2h.cjs → guards-CrfVwk0-.cjs} +1 -1
  23. package/dist/guards-DKGBsd6x.mjs +115 -0
  24. package/dist/{guards-D1et4U32.mjs → guards-Dc9MB9on.mjs} +3 -3
  25. package/dist/guards.cjs +37 -36
  26. package/dist/guards.d.cts +1 -1
  27. package/dist/guards.d.mts +1 -1
  28. package/dist/guards.mjs +5 -4
  29. package/dist/hash.cjs +8 -8
  30. package/dist/hash.mjs +8 -8
  31. package/dist/index.cjs +12 -12
  32. package/dist/index.d.cts +2 -3
  33. package/dist/index.d.mts +2 -3
  34. package/dist/index.mjs +12 -12
  35. package/dist/{parse-DUJ0YThn.mjs → parse-TuFyLeVH.mjs} +3 -3
  36. package/dist/{parse-CbVVRoFY.cjs → parse-jh637S25.cjs} +4 -4
  37. package/dist/pluralizer.cjs +1 -1
  38. package/dist/pluralizer.mjs +1 -1
  39. package/dist/{query-B4Lrr5Vt.mjs → query-BomnyWh3.mjs} +5 -5
  40. package/dist/{query-BUBCpo-q.cjs → query-sWSi-d7u.cjs} +10 -10
  41. package/dist/{specials-dkYP1Nh2.cjs → specials-DU8u108m.cjs} +1 -1
  42. package/dist/{specials-Hq5Ncd6y.mjs → specials-krf7zsqI.mjs} +1 -1
  43. package/dist/stylog.cjs +3 -3
  44. package/dist/stylog.d.cts +2 -2
  45. package/dist/stylog.d.mts +2 -2
  46. package/dist/stylog.mjs +3 -3
  47. package/dist/types/colors.d.cts +1 -1
  48. package/dist/types/colors.d.mts +1 -1
  49. package/dist/types/stylog.d.cts +1 -1
  50. package/dist/types/stylog.d.mts +1 -1
  51. package/dist/{utilities-DPscNbS1.mjs → utilities-BSv8VbnM.mjs} +1 -1
  52. package/dist/{utilities-CWV1GPGY.cjs → utilities-BVpk3LKy.cjs} +1 -1
  53. package/package.json +6 -6
package/dist/colors.cjs CHANGED
@@ -17,8 +17,9 @@
17
17
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
18
  const require_primitives = require('./primitives-CBGICrDR.cjs');
19
19
  const require_css_colors = require('./css-colors-DC7oZ46Y.cjs');
20
- const require_guards = require('./guards-DGN95D2h.cjs');
21
- const require_convert = require('./convert-Cqy2Llek.cjs');
20
+ const require_guards = require('./guards-CrfVwk0-.cjs');
21
+ const require_convert = require('./convert-BjKz_hhr.cjs');
22
+ const require_utilities = require('./utilities-BVpk3LKy.cjs');
22
23
  const require_constants = require('./constants-BOs8tjzp.cjs');
23
24
 
24
25
  //#region src/colors/random.ts
@@ -158,6 +159,18 @@ var Color = class Color {
158
159
  yield this.hsla;
159
160
  }
160
161
  /**
162
+ * Allows the color to be used in string and number contexts.
163
+ * @param hint The hint to determine the conversion type.
164
+ */
165
+ [Symbol.toPrimitive](hint) {
166
+ if (hint === "string") return this.hex8;
167
+ else if (hint === "number") {
168
+ const hex = this.hex8.endsWith("FF") ? this.hex : this.hex8;
169
+ return parseInt(hex.replace("#", "0x"), 16);
170
+ }
171
+ return this;
172
+ }
173
+ /**
161
174
  * @private Convert `Hex6` color format to `Hex8` by applying `100%` opacity.
162
175
  * @param hex `Hex6` color to convert to `Hex8`.
163
176
  */
@@ -181,11 +194,12 @@ var Color = class Color {
181
194
  return `hsla(${h}, ${s}%, ${l}%, 1)`;
182
195
  }
183
196
  /**
184
- * @instance Applies or modifies the opacity of a color and returns a new instance.
197
+ * @instance Sets the opacity of this color to the given **absolute** percentage and returns a new instance.
185
198
  *
186
199
  * @remarks
200
+ * - This is an **absolute setter**: passing `50` means "set opacity to exactly 50%", regardless of the current opacity.
187
201
  * - For solid colors ({@link Hex6}/{@link RGB}/{@link HSL}): Adds an alpha channel with the specified opacity.
188
- * - For alpha colors ({@link Hex8}/{@link RGBA}/{@link HSLA}): Updates the existing alpha channel.
202
+ * - For alpha colors ({@link Hex8}/{@link RGBA}/{@link HSLA}): Replaces the existing alpha channel.
189
203
  *
190
204
  * @param opacity - A number between `0-100` representing the opacity percentage.
191
205
  * @returns A new instance of `Color` containing all color formats with the applied opacity.
@@ -204,40 +218,81 @@ var Color = class Color {
204
218
  return new Color(`${this.hex.slice(0, 7)}${require_convert.percentToHex(opacity)}`.toUpperCase());
205
219
  }
206
220
  /**
207
- * @instance Darkens the color by reducing the lightness by the given percentage.
208
- * @param percent - The percentage to darken (`0–100`).
209
- * @returns A new `Color` instance with the modified darkness.
221
+ * @instance Darkens the color by **subtracting** the given percentage points from the current lightness in HSL space.
222
+ *
223
+ * @remarks
224
+ * - This is a **relative adjustment**: passing `20` means "reduce lightness by 20 percentage points" from its current value.
225
+ * - Lightness is clamped to `0%` at minimum.
226
+ * - The original alpha (opacity) is preserved in the returned color.
227
+ *
228
+ * @param percent - The percentage points to subtract from lightness (`0–100`).
229
+ * @returns A new `Color` instance with the reduced lightness.
230
+ *
231
+ * @example
232
+ * const blue = new Color("#0000ff"); // hsl(240, 100%, 50%)
233
+ * const darkerBlue = blue.applyDarkness(20);
234
+ * console.log(darkerBlue.hsl); // hsl(240, 100%, 30%)
210
235
  */
211
236
  applyDarkness(percent) {
212
237
  const [h, s, l, a] = require_convert.extractAlphaColorValues(this.hsla);
213
238
  return new Color(`hsl(${h}, ${s}%, ${Math.max(0, l - percent)}%)`).applyOpacity(a * 100);
214
239
  }
215
240
  /**
216
- * @instance Lightens the color by increasing the lightness by the given percentage.
217
- * @param percent - The percentage to brighten (`0–100`).
218
- * @returns A new `Color` instance with the modified lightness.
241
+ * @instance Lightens the color by **adding** the given percentage points to the current lightness in HSL space.
242
+ *
243
+ * @remarks
244
+ * - This is a **relative adjustment**: passing `30` means "increase lightness by 30 percentage points" from its current value.
245
+ * - Lightness is clamped to `100%` at maximum.
246
+ * - The original alpha (opacity) is preserved in the returned color.
247
+ *
248
+ * @param percent - The percentage points to add to lightness (`0–100`).
249
+ * @returns A new `Color` instance with the increased lightness.
250
+ *
251
+ * @example
252
+ * const green = new Color("#008000"); // hsl(120, 100%, 25.1%)
253
+ * const lighterGreen = green.applyBrightness(30);
254
+ * console.log(lighterGreen.hsl); // hsl(120, 100%, 55.1%)
219
255
  */
220
256
  applyBrightness(percent) {
221
257
  const [h, s, l, a] = require_convert.extractAlphaColorValues(this.hsla);
222
258
  return new Color(`hsl(${h}, ${s}%, ${Math.min(100, l + percent)}%)`).applyOpacity(a * 100);
223
259
  }
224
260
  /**
225
- * @instance Reduces the saturation of the color to make it appear duller.
226
- * @param percent - The percentage to reduce saturation (`0–100`).
227
- * @returns A new `Color` instance with the modified saturation.
261
+ * @instance Desaturates the color by **subtracting** the given percentage points from the current saturation in HSL space.
262
+ *
263
+ * @remarks
264
+ * - This is a **relative adjustment**: passing `50` means "reduce saturation by 50 percentage points" from its current value.
265
+ * - Saturation is clamped to `0%` at minimum (fully desaturated / grayscale).
266
+ * - The original alpha (opacity) is preserved in the returned color.
267
+ *
268
+ * @param percent - The percentage points to subtract from saturation (`0–100`).
269
+ * @returns A new `Color` instance with the reduced saturation.
270
+ *
271
+ * @example
272
+ * const pink = new Color("#ff69b4"); // hsl(330, 100%, 70.59%)
273
+ * const dullPink = pink.applyDullness(50);
274
+ * console.log(dullPink.hsl); // hsl(330, 50%, 70.59%)
228
275
  */
229
276
  applyDullness(percent) {
230
277
  const [h, s, l, a] = require_convert.extractAlphaColorValues(this.hsla);
231
278
  return new Color(`hsl(${h}, ${Math.max(0, s - percent)}%, ${l}%)`).applyOpacity(a * 100);
232
279
  }
233
280
  /**
234
- * @instance Softens the color toward white by reducing saturation and increasing lightness based on a percentage.
281
+ * @instance Softens the color toward white by **proportionally** reducing saturation and increasing lightness.
235
282
  *
236
283
  * @remarks
237
- * This creates a soft UI-like white shade effect (similar to some UI libraries' light color scale).
284
+ * - This is a **proportional blend**: passing `40` means "move 40% of the *remaining distance* toward pure white".
285
+ * - Unlike {@link applyBrightness} or {@link applyDullness}, the effect scales relative to the current distance from white, producing a natural pastel/tint effect.
286
+ * - This creates a soft UI-like white shade effect (similar to some UI libraries' light color scale).
287
+ * - The original alpha (opacity) is preserved in the returned color.
238
288
  *
239
289
  * @param percent - Value from `0` to `100` representing how far to push the color toward white.
240
290
  * @returns A new `Color` instance shifted toward white.
291
+ *
292
+ * @example
293
+ * const purple = new Color("#800080"); // hsl(300, 100%, 25.1%)
294
+ * const softPurple = purple.applyWhiteShade(40);
295
+ * console.log(softPurple.hsl); // hsl(300, 60%, 55.06%)
241
296
  */
242
297
  applyWhiteShade(percent) {
243
298
  const [h, s, l, a] = require_convert.extractAlphaColorValues(this.hsla);
@@ -258,14 +313,14 @@ var Color = class Color {
258
313
  */
259
314
  blendWith(other, weight = .5) {
260
315
  const w = Math.max(0, Math.min(1, weight));
261
- const converted = Color.isCSSColor(other) ? new Color(other) : new Color(other);
262
- const [r1, b1, g1, a1] = require_convert.extractAlphaColorValues(this.rgba);
263
- const [r2, b2, g2, a2] = require_convert.extractAlphaColorValues(converted.rgba);
316
+ const converted = new Color(other);
317
+ const [r1, g1, b1, a1] = require_convert.extractAlphaColorValues(this.rgba);
318
+ const [r2, g2, b2, a2] = require_convert.extractAlphaColorValues(converted.rgba);
264
319
  const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
265
- const blendChannel = (c1, c2) => {
320
+ const _blendChannel = (c1, c2) => {
266
321
  return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
267
322
  };
268
- return new Color(`rgba(${blendChannel(r1, r2)}, ${blendChannel(g1, g2)}, ${blendChannel(b1, b2)}, ${alpha})`);
323
+ return new Color(`rgba(${_blendChannel(r1, r2)}, ${_blendChannel(g1, g2)}, ${_blendChannel(b1, b2)}, ${alpha})`);
269
324
  }
270
325
  /**
271
326
  * @instance Calculates the contrast ratio between this color and another color (WCAG).
@@ -273,11 +328,11 @@ var Color = class Color {
273
328
  * @returns A number representing the contrast ratio (rounded to 2 decimal places).
274
329
  */
275
330
  contrastRatio(other) {
276
- const newColor = Color.isCSSColor(other) ? new Color(other) : new Color(other);
331
+ const newColor = new Color(other);
277
332
  const luminance = (rgb) => {
278
333
  const [r, g, b] = require_convert.extractSolidColorValues(rgb).map((v) => {
279
334
  const c = v / 255;
280
- return c <= .03928 ? c / 12.92 : Math.pow((c + .055) / 1.055, 2.4);
335
+ return c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
281
336
  });
282
337
  return .2126 * r + .7152 * g + .0722 * b;
283
338
  };
@@ -353,6 +408,35 @@ var Color = class Color {
353
408
  ].map((c) => c.applyOpacity(a * 100));
354
409
  }
355
410
  /**
411
+ * @instance Generates a color palette of evenly distributed hues based on the current color's saturation, lightness, and alpha.
412
+ *
413
+ * @remarks
414
+ * - Colors are spaced evenly around the color wheel (`360° / count` apart), starting from the current hue.
415
+ * - Saturation, lightness, and alpha from the source color are preserved across all generated colors.
416
+ *
417
+ * @typeParam N - A literal number type representing the palette size.
418
+ * @param count - The number of colors to generate in the palette (must be a positive integer ≥ `1`). Default: `7`.
419
+ * @param step - The step value (degree) to be added to the hue of the previous color. Default: `360 / count`.
420
+ * @returns Array of `Color` instances with the specified count.
421
+ *
422
+ * @example
423
+ * const red = new Color("#ff0000");
424
+ * const palette = red.generatePalette(4);
425
+ * console.log(palette.map((color) => color.hex));
426
+ * // ['#FF0000', '#80FF00', '#00FFFF', '#8000FF']
427
+ */
428
+ generatePalette(count, step) {
429
+ const [h, s, l, a] = require_convert.extractAlphaColorValues(this.hsla);
430
+ const clampedCount = require_utilities.clampNumber(count ?? 7, 1, 360);
431
+ const calculatedStep = step ? require_utilities.clampNumber(step, 1, 360) : 360 / clampedCount;
432
+ const colors = [];
433
+ for (let i = 0; i < clampedCount; i++) {
434
+ const color = new Color(`hsl(${(h + calculatedStep * i) % 360}, ${s}%, ${l}%)`).applyOpacity(a * 100);
435
+ colors.push(color);
436
+ }
437
+ return colors;
438
+ }
439
+ /**
356
440
  * @instance Gets the `WCAG` accessibility rating between this and another color.
357
441
  * @param other - The other color to test contrast against.
358
442
  * @returns `'Fail'`, `'AA'`, or `'AAA'` based on `WCAG 2.1` contrast standards.
@@ -374,6 +458,28 @@ var Color = class Color {
374
458
  return (r * 299 + g * 587 + b * 114) / 1e3 > Math.min(255, Math.max(0, threshold));
375
459
  }
376
460
  /**
461
+ * @instance Convert the color to string.
462
+ * @returns The `Hex8` representation of the color.
463
+ *
464
+ * @remarks
465
+ * - Called by `String()`, `Object.prototype.toString()` or in template literals.
466
+ * - Uses the same implementation as `toJSON()`.
467
+ */
468
+ toString() {
469
+ return this.hex8;
470
+ }
471
+ /**
472
+ * @instance Convert the color to JSON.
473
+ * @returns The `Hex8` representation of the color.
474
+ *
475
+ * @remarks
476
+ * - Called by `JSON.stringify()`.
477
+ * - It uses the same implementation as `toString()`.
478
+ */
479
+ toJSON() {
480
+ return this.hex8;
481
+ }
482
+ /**
377
483
  * @static Checks if a color is in {@link Hex6} format.
378
484
  *
379
485
  * @param color Color to check.
@@ -525,10 +631,10 @@ function getColorForInitial(input = "", opacity = 100) {
525
631
  return require_guards._applyOpacity(DEFAULT, hexOpacity);
526
632
  } else if (Array.isArray(input)) {
527
633
  if (input?.length < 1) return [...require_constants.ALPHABET_COLOR_PALETTE, ...require_constants.NUMBER_COLOR_PALETTE].map((color) => require_guards._applyOpacity(color, hexOpacity));
528
- return input.map((el) => {
634
+ return input.flatMap((el) => {
529
635
  if (Array.isArray(el)) return getColorForInitial(el, opacity);
530
636
  return getColorForInitial(el, opacity);
531
- }).flat();
637
+ });
532
638
  }
533
639
  return require_guards._applyOpacity(DEFAULT, hexOpacity);
534
640
  }
package/dist/colors.d.cts CHANGED
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { er as Percent } from "./object-DyVg8BFt.cjs";
18
- import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "./Color-asKZqwDF.cjs";
18
+ import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "./Color-CVRcGmWe.cjs";
19
19
 
20
20
  //#region src/colors/convert.d.ts
21
21
  /**
@@ -203,7 +203,7 @@ declare function convertColorCode(color: HSLA): {
203
203
  //#endregion
204
204
  //#region src/colors/initials.d.ts
205
205
  /**
206
- * * Generates a hex (`Hex8` format) color based on the first character (initial) of a string or number.
206
+ * * Generates a hex (`Hex8` format) color based on the first character (initial) of a string or number.
207
207
  *
208
208
  * - For numbers, it uses 10 predefined colors (0-9).
209
209
  * - For letters, it uses 26 predefined colors (A-Z).
package/dist/colors.d.mts CHANGED
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { er as Percent } from "./object-DyVg8BFt.mjs";
18
- import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "./Color-B2SgCGbm.mjs";
18
+ import { C as RandomColorOptions, S as RandomColor, T as SolidValues, _ as Hex, a as AlphaValues, b as RGB, g as HSLA, h as HSL, l as ColorInputArray, n as $ColorType, t as Color, v as Hex6, x as RGBA, y as Hex8 } from "./Color-CInCJvH7.mjs";
19
19
 
20
20
  //#region src/colors/convert.d.ts
21
21
  /**
@@ -203,7 +203,7 @@ declare function convertColorCode(color: HSLA): {
203
203
  //#endregion
204
204
  //#region src/colors/initials.d.ts
205
205
  /**
206
- * * Generates a hex (`Hex8` format) color based on the first character (initial) of a string or number.
206
+ * * Generates a hex (`Hex8` format) color based on the first character (initial) of a string or number.
207
207
  *
208
208
  * - For numbers, it uses 10 predefined colors (0-9).
209
209
  * - For letters, it uses 26 predefined colors (A-Z).
package/dist/colors.mjs CHANGED
@@ -16,8 +16,9 @@
16
16
 
17
17
  import { a as isNonEmptyString, c as isNumber, d as isString } from "./primitives-Djsevc69.mjs";
18
18
  import { t as CSS_COLORS } from "./css-colors-B-y4TmeC.mjs";
19
- import { c as _applyOpacity, l as _generateRandomHSL, n as isHSL, o as isRGB, r as isHSLA, s as isRGBA, u as _isSimilarToLast } from "./guards-DziDBD0p.mjs";
20
- import { _ as extractSolidColorValues, a as convertHexToRgb, c as convertHslaToHex8, d as convertRgbToHsl, f as convertRgbToRgba, g as extractAlphaColorValues, h as applyOpacityToHex, i as convertHexToHsl, l as convertHslaToRgba, m as convertRgbaToHsla, n as convertHex8ToHsla, o as convertHslToHex, p as convertRgbaToHex8, r as convertHex8ToRgba, s as convertHslToRgb, t as convertColorCode, u as convertRgbToHex, v as percentToHex } from "./convert-lXdkXPJR.mjs";
19
+ import { c as _applyOpacity, l as _generateRandomHSL, n as isHSL, o as isRGB, r as isHSLA, s as isRGBA, u as _isSimilarToLast } from "./guards-CNG9gnvL.mjs";
20
+ import { _ as extractSolidColorValues, a as convertHexToRgb, c as convertHslaToHex8, d as convertRgbToHsl, f as convertRgbToRgba, g as extractAlphaColorValues, h as applyOpacityToHex, i as convertHexToHsl, l as convertHslaToRgba, m as convertRgbaToHsla, n as convertHex8ToHsla, o as convertHslToHex, p as convertRgbaToHex8, r as convertHex8ToRgba, s as convertHslToRgb, t as convertColorCode, u as convertRgbToHex, v as percentToHex } from "./convert-DRZXcjcS.mjs";
21
+ import { t as clampNumber } from "./utilities-BSv8VbnM.mjs";
21
22
  import { n as NUMBER_COLOR_PALETTE, t as ALPHABET_COLOR_PALETTE } from "./constants-DCZL77t-.mjs";
22
23
 
23
24
  //#region src/colors/random.ts
@@ -157,6 +158,18 @@ var Color = class Color {
157
158
  yield this.hsla;
158
159
  }
159
160
  /**
161
+ * Allows the color to be used in string and number contexts.
162
+ * @param hint The hint to determine the conversion type.
163
+ */
164
+ [Symbol.toPrimitive](hint) {
165
+ if (hint === "string") return this.hex8;
166
+ else if (hint === "number") {
167
+ const hex = this.hex8.endsWith("FF") ? this.hex : this.hex8;
168
+ return parseInt(hex.replace("#", "0x"), 16);
169
+ }
170
+ return this;
171
+ }
172
+ /**
160
173
  * @private Convert `Hex6` color format to `Hex8` by applying `100%` opacity.
161
174
  * @param hex `Hex6` color to convert to `Hex8`.
162
175
  */
@@ -180,11 +193,12 @@ var Color = class Color {
180
193
  return `hsla(${h}, ${s}%, ${l}%, 1)`;
181
194
  }
182
195
  /**
183
- * @instance Applies or modifies the opacity of a color and returns a new instance.
196
+ * @instance Sets the opacity of this color to the given **absolute** percentage and returns a new instance.
184
197
  *
185
198
  * @remarks
199
+ * - This is an **absolute setter**: passing `50` means "set opacity to exactly 50%", regardless of the current opacity.
186
200
  * - For solid colors ({@link Hex6}/{@link RGB}/{@link HSL}): Adds an alpha channel with the specified opacity.
187
- * - For alpha colors ({@link Hex8}/{@link RGBA}/{@link HSLA}): Updates the existing alpha channel.
201
+ * - For alpha colors ({@link Hex8}/{@link RGBA}/{@link HSLA}): Replaces the existing alpha channel.
188
202
  *
189
203
  * @param opacity - A number between `0-100` representing the opacity percentage.
190
204
  * @returns A new instance of `Color` containing all color formats with the applied opacity.
@@ -203,40 +217,81 @@ var Color = class Color {
203
217
  return new Color(`${this.hex.slice(0, 7)}${percentToHex(opacity)}`.toUpperCase());
204
218
  }
205
219
  /**
206
- * @instance Darkens the color by reducing the lightness by the given percentage.
207
- * @param percent - The percentage to darken (`0–100`).
208
- * @returns A new `Color` instance with the modified darkness.
220
+ * @instance Darkens the color by **subtracting** the given percentage points from the current lightness in HSL space.
221
+ *
222
+ * @remarks
223
+ * - This is a **relative adjustment**: passing `20` means "reduce lightness by 20 percentage points" from its current value.
224
+ * - Lightness is clamped to `0%` at minimum.
225
+ * - The original alpha (opacity) is preserved in the returned color.
226
+ *
227
+ * @param percent - The percentage points to subtract from lightness (`0–100`).
228
+ * @returns A new `Color` instance with the reduced lightness.
229
+ *
230
+ * @example
231
+ * const blue = new Color("#0000ff"); // hsl(240, 100%, 50%)
232
+ * const darkerBlue = blue.applyDarkness(20);
233
+ * console.log(darkerBlue.hsl); // hsl(240, 100%, 30%)
209
234
  */
210
235
  applyDarkness(percent) {
211
236
  const [h, s, l, a] = extractAlphaColorValues(this.hsla);
212
237
  return new Color(`hsl(${h}, ${s}%, ${Math.max(0, l - percent)}%)`).applyOpacity(a * 100);
213
238
  }
214
239
  /**
215
- * @instance Lightens the color by increasing the lightness by the given percentage.
216
- * @param percent - The percentage to brighten (`0–100`).
217
- * @returns A new `Color` instance with the modified lightness.
240
+ * @instance Lightens the color by **adding** the given percentage points to the current lightness in HSL space.
241
+ *
242
+ * @remarks
243
+ * - This is a **relative adjustment**: passing `30` means "increase lightness by 30 percentage points" from its current value.
244
+ * - Lightness is clamped to `100%` at maximum.
245
+ * - The original alpha (opacity) is preserved in the returned color.
246
+ *
247
+ * @param percent - The percentage points to add to lightness (`0–100`).
248
+ * @returns A new `Color` instance with the increased lightness.
249
+ *
250
+ * @example
251
+ * const green = new Color("#008000"); // hsl(120, 100%, 25.1%)
252
+ * const lighterGreen = green.applyBrightness(30);
253
+ * console.log(lighterGreen.hsl); // hsl(120, 100%, 55.1%)
218
254
  */
219
255
  applyBrightness(percent) {
220
256
  const [h, s, l, a] = extractAlphaColorValues(this.hsla);
221
257
  return new Color(`hsl(${h}, ${s}%, ${Math.min(100, l + percent)}%)`).applyOpacity(a * 100);
222
258
  }
223
259
  /**
224
- * @instance Reduces the saturation of the color to make it appear duller.
225
- * @param percent - The percentage to reduce saturation (`0–100`).
226
- * @returns A new `Color` instance with the modified saturation.
260
+ * @instance Desaturates the color by **subtracting** the given percentage points from the current saturation in HSL space.
261
+ *
262
+ * @remarks
263
+ * - This is a **relative adjustment**: passing `50` means "reduce saturation by 50 percentage points" from its current value.
264
+ * - Saturation is clamped to `0%` at minimum (fully desaturated / grayscale).
265
+ * - The original alpha (opacity) is preserved in the returned color.
266
+ *
267
+ * @param percent - The percentage points to subtract from saturation (`0–100`).
268
+ * @returns A new `Color` instance with the reduced saturation.
269
+ *
270
+ * @example
271
+ * const pink = new Color("#ff69b4"); // hsl(330, 100%, 70.59%)
272
+ * const dullPink = pink.applyDullness(50);
273
+ * console.log(dullPink.hsl); // hsl(330, 50%, 70.59%)
227
274
  */
228
275
  applyDullness(percent) {
229
276
  const [h, s, l, a] = extractAlphaColorValues(this.hsla);
230
277
  return new Color(`hsl(${h}, ${Math.max(0, s - percent)}%, ${l}%)`).applyOpacity(a * 100);
231
278
  }
232
279
  /**
233
- * @instance Softens the color toward white by reducing saturation and increasing lightness based on a percentage.
280
+ * @instance Softens the color toward white by **proportionally** reducing saturation and increasing lightness.
234
281
  *
235
282
  * @remarks
236
- * This creates a soft UI-like white shade effect (similar to some UI libraries' light color scale).
283
+ * - This is a **proportional blend**: passing `40` means "move 40% of the *remaining distance* toward pure white".
284
+ * - Unlike {@link applyBrightness} or {@link applyDullness}, the effect scales relative to the current distance from white, producing a natural pastel/tint effect.
285
+ * - This creates a soft UI-like white shade effect (similar to some UI libraries' light color scale).
286
+ * - The original alpha (opacity) is preserved in the returned color.
237
287
  *
238
288
  * @param percent - Value from `0` to `100` representing how far to push the color toward white.
239
289
  * @returns A new `Color` instance shifted toward white.
290
+ *
291
+ * @example
292
+ * const purple = new Color("#800080"); // hsl(300, 100%, 25.1%)
293
+ * const softPurple = purple.applyWhiteShade(40);
294
+ * console.log(softPurple.hsl); // hsl(300, 60%, 55.06%)
240
295
  */
241
296
  applyWhiteShade(percent) {
242
297
  const [h, s, l, a] = extractAlphaColorValues(this.hsla);
@@ -257,14 +312,14 @@ var Color = class Color {
257
312
  */
258
313
  blendWith(other, weight = .5) {
259
314
  const w = Math.max(0, Math.min(1, weight));
260
- const converted = Color.isCSSColor(other) ? new Color(other) : new Color(other);
261
- const [r1, b1, g1, a1] = extractAlphaColorValues(this.rgba);
262
- const [r2, b2, g2, a2] = extractAlphaColorValues(converted.rgba);
315
+ const converted = new Color(other);
316
+ const [r1, g1, b1, a1] = extractAlphaColorValues(this.rgba);
317
+ const [r2, g2, b2, a2] = extractAlphaColorValues(converted.rgba);
263
318
  const alpha = Math.round((a1 * (1 - w) + a2 * w) * 100) / 100;
264
- const blendChannel = (c1, c2) => {
319
+ const _blendChannel = (c1, c2) => {
265
320
  return Math.round((c1 * a1 * (1 - w) + c2 * a2 * w) / alpha);
266
321
  };
267
- return new Color(`rgba(${blendChannel(r1, r2)}, ${blendChannel(g1, g2)}, ${blendChannel(b1, b2)}, ${alpha})`);
322
+ return new Color(`rgba(${_blendChannel(r1, r2)}, ${_blendChannel(g1, g2)}, ${_blendChannel(b1, b2)}, ${alpha})`);
268
323
  }
269
324
  /**
270
325
  * @instance Calculates the contrast ratio between this color and another color (WCAG).
@@ -272,11 +327,11 @@ var Color = class Color {
272
327
  * @returns A number representing the contrast ratio (rounded to 2 decimal places).
273
328
  */
274
329
  contrastRatio(other) {
275
- const newColor = Color.isCSSColor(other) ? new Color(other) : new Color(other);
330
+ const newColor = new Color(other);
276
331
  const luminance = (rgb) => {
277
332
  const [r, g, b] = extractSolidColorValues(rgb).map((v) => {
278
333
  const c = v / 255;
279
- return c <= .03928 ? c / 12.92 : Math.pow((c + .055) / 1.055, 2.4);
334
+ return c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4;
280
335
  });
281
336
  return .2126 * r + .7152 * g + .0722 * b;
282
337
  };
@@ -352,6 +407,35 @@ var Color = class Color {
352
407
  ].map((c) => c.applyOpacity(a * 100));
353
408
  }
354
409
  /**
410
+ * @instance Generates a color palette of evenly distributed hues based on the current color's saturation, lightness, and alpha.
411
+ *
412
+ * @remarks
413
+ * - Colors are spaced evenly around the color wheel (`360° / count` apart), starting from the current hue.
414
+ * - Saturation, lightness, and alpha from the source color are preserved across all generated colors.
415
+ *
416
+ * @typeParam N - A literal number type representing the palette size.
417
+ * @param count - The number of colors to generate in the palette (must be a positive integer ≥ `1`). Default: `7`.
418
+ * @param step - The step value (degree) to be added to the hue of the previous color. Default: `360 / count`.
419
+ * @returns Array of `Color` instances with the specified count.
420
+ *
421
+ * @example
422
+ * const red = new Color("#ff0000");
423
+ * const palette = red.generatePalette(4);
424
+ * console.log(palette.map((color) => color.hex));
425
+ * // ['#FF0000', '#80FF00', '#00FFFF', '#8000FF']
426
+ */
427
+ generatePalette(count, step) {
428
+ const [h, s, l, a] = extractAlphaColorValues(this.hsla);
429
+ const clampedCount = clampNumber(count ?? 7, 1, 360);
430
+ const calculatedStep = step ? clampNumber(step, 1, 360) : 360 / clampedCount;
431
+ const colors = [];
432
+ for (let i = 0; i < clampedCount; i++) {
433
+ const color = new Color(`hsl(${(h + calculatedStep * i) % 360}, ${s}%, ${l}%)`).applyOpacity(a * 100);
434
+ colors.push(color);
435
+ }
436
+ return colors;
437
+ }
438
+ /**
355
439
  * @instance Gets the `WCAG` accessibility rating between this and another color.
356
440
  * @param other - The other color to test contrast against.
357
441
  * @returns `'Fail'`, `'AA'`, or `'AAA'` based on `WCAG 2.1` contrast standards.
@@ -373,6 +457,28 @@ var Color = class Color {
373
457
  return (r * 299 + g * 587 + b * 114) / 1e3 > Math.min(255, Math.max(0, threshold));
374
458
  }
375
459
  /**
460
+ * @instance Convert the color to string.
461
+ * @returns The `Hex8` representation of the color.
462
+ *
463
+ * @remarks
464
+ * - Called by `String()`, `Object.prototype.toString()` or in template literals.
465
+ * - Uses the same implementation as `toJSON()`.
466
+ */
467
+ toString() {
468
+ return this.hex8;
469
+ }
470
+ /**
471
+ * @instance Convert the color to JSON.
472
+ * @returns The `Hex8` representation of the color.
473
+ *
474
+ * @remarks
475
+ * - Called by `JSON.stringify()`.
476
+ * - It uses the same implementation as `toString()`.
477
+ */
478
+ toJSON() {
479
+ return this.hex8;
480
+ }
481
+ /**
376
482
  * @static Checks if a color is in {@link Hex6} format.
377
483
  *
378
484
  * @param color Color to check.
@@ -524,10 +630,10 @@ function getColorForInitial(input = "", opacity = 100) {
524
630
  return _applyOpacity(DEFAULT, hexOpacity);
525
631
  } else if (Array.isArray(input)) {
526
632
  if (input?.length < 1) return [...ALPHABET_COLOR_PALETTE, ...NUMBER_COLOR_PALETTE].map((color) => _applyOpacity(color, hexOpacity));
527
- return input.map((el) => {
633
+ return input.flatMap((el) => {
528
634
  if (Array.isArray(el)) return getColorForInitial(el, opacity);
529
635
  return getColorForInitial(el, opacity);
530
- }).flat();
636
+ });
531
637
  }
532
638
  return _applyOpacity(DEFAULT, hexOpacity);
533
639
  }
@@ -17,10 +17,10 @@
17
17
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
18
18
  const require_constants = require('./constants-D_HkIg02.cjs');
19
19
  const require_css_colors = require('./css-colors-DC7oZ46Y.cjs');
20
- const require_constants$1 = require('./constants-BOs8tjzp.cjs');
21
- const require_constants$2 = require('./constants-CgFaV72Z.cjs');
20
+ const require_constants$1 = require('./constants-B3nc8psr.cjs');
21
+ const require_constants$2 = require('./constants-BOs8tjzp.cjs');
22
+ const require_constants$3 = require('./constants-CgFaV72Z.cjs');
22
23
  const require_timezone = require('./timezone-CSz7R0L6.cjs');
23
- const require_constants$3 = require('./constants-B3nc8psr.cjs');
24
24
  const require_constants$4 = require('./constants-DIBRCBIP.cjs');
25
25
  const require_countries = require('./countries-C0x58zVg.cjs');
26
26
  const require_constants$5 = require('./constants-ZnFGKd7G.cjs');
@@ -376,17 +376,17 @@ const SEASON_PRESETS = /* @__PURE__ */ Object.freeze({
376
376
  });
377
377
 
378
378
  //#endregion
379
- exports.ALPHABET_COLOR_PALETTE = require_constants$1.ALPHABET_COLOR_PALETTE;
379
+ exports.ALPHABET_COLOR_PALETTE = require_constants$2.ALPHABET_COLOR_PALETTE;
380
380
  exports.AUSTRALIA_SEASONS = AUSTRALIA_SEASONS;
381
381
  exports.BANGLADESH_SEASONS = BANGLADESH_SEASONS;
382
382
  exports.CATEGORIZED_UNITS = require_constants$4.UNITS;
383
383
  exports.COUNTRIES = require_countries.COUNTRIES;
384
384
  exports.CSS_COLORS = require_css_colors.CSS_COLORS;
385
- exports.CURRENCY_CODES = require_constants$3.CURRENCY_CODES;
386
- exports.CURRENCY_LOCALES = require_constants$3.CURRENCY_LOCALES;
385
+ exports.CURRENCY_CODES = require_constants$1.CURRENCY_CODES;
386
+ exports.CURRENCY_LOCALES = require_constants$1.CURRENCY_LOCALES;
387
387
  exports.ETHIOPIA_SEASONS = ETHIOPIA_SEASONS;
388
- exports.FRANKFURTER_CURRENCIES = require_constants$3.FRANKFURTER_CURRENCIES;
389
- exports.GENERAL_UNITS = require_constants$3.UNITS;
388
+ exports.FRANKFURTER_CURRENCIES = require_constants$1.FRANKFURTER_CURRENCIES;
389
+ exports.GENERAL_UNITS = require_constants$1.UNITS;
390
390
  exports.HTTP_CODES = require_constants$5.HTTP_STATUS_CODES;
391
391
  exports.HTTP_STATUS = require_constants$5.HTTP_STATUS_CODES;
392
392
  exports.HTTP_STATUS_CODES = require_constants$5.HTTP_STATUS_CODES;
@@ -395,11 +395,11 @@ exports.INDIA_IMD_SEASONS = INDIA_IMD_SEASONS;
395
395
  exports.INDIA_TAMIL_SEASONS = INDIA_TAMIL_SEASONS;
396
396
  exports.INDIA_VEDIC_SEASONS = INDIA_VEDIC_SEASONS;
397
397
  exports.JAPAN_SEASONS = JAPAN_SEASONS;
398
- exports.LOCALE_CODES = require_constants$3.LOCALE_CODES;
398
+ exports.LOCALE_CODES = require_constants$1.LOCALE_CODES;
399
399
  exports.LOWERCASED_WORDS = require_constants.LOWERCASE;
400
- exports.MONTHS = require_constants$2.MONTHS;
400
+ exports.MONTHS = require_constants$3.MONTHS;
401
401
  exports.NATIVE_TZ_IDS = require_timezone.NATIVE_TZ_IDS;
402
- exports.NUMBER_COLOR_PALETTE = require_constants$1.NUMBER_COLOR_PALETTE;
402
+ exports.NUMBER_COLOR_PALETTE = require_constants$2.NUMBER_COLOR_PALETTE;
403
403
  exports.PHILIPPINES_SEASONS = PHILIPPINES_SEASONS;
404
404
  exports.SEASON_PRESETS = SEASON_PRESETS;
405
405
  exports.STATUS_CODES = require_constants$5.HTTP_STATUS_CODES;
@@ -409,7 +409,7 @@ exports.TIME_ZONE_IDS = require_timezone.TIME_ZONE_IDS;
409
409
  exports.TIME_ZONE_LABELS = require_timezone.TIME_ZONE_LABELS;
410
410
  exports.TZ_ABBREVIATIONS = require_timezone.TIME_ZONES;
411
411
  exports.US_ACADEMIC_SEASONS = US_ACADEMIC_SEASONS;
412
- exports.VEDIC_ZODIAC_SIGNS = require_constants$2.VEDIC_ZODIAC_SIGNS;
413
- exports.WEEK_DAYS = require_constants$2.DAYS;
412
+ exports.VEDIC_ZODIAC_SIGNS = require_constants$3.VEDIC_ZODIAC_SIGNS;
413
+ exports.WEEK_DAYS = require_constants$3.DAYS;
414
414
  exports.WESTERN_SEASONS = DEFAULT_SEASONS;
415
- exports.WESTERN_ZODIAC_SIGNS = require_constants$2.WESTERN_ZODIAC_SIGNS;
415
+ exports.WESTERN_ZODIAC_SIGNS = require_constants$3.WESTERN_ZODIAC_SIGNS;
@@ -16,10 +16,10 @@
16
16
 
17
17
  import { t as LOWERCASE } from "./constants-B0zJiNqH.mjs";
18
18
  import { t as CSS_COLORS } from "./css-colors-B-y4TmeC.mjs";
19
+ import { a as LOCALE_CODES, i as FRANKFURTER_CURRENCIES, n as CURRENCY_CODES, p as UNITS$1, r as CURRENCY_LOCALES } from "./constants-ZyfpysiQ.mjs";
19
20
  import { n as NUMBER_COLOR_PALETTE, t as ALPHABET_COLOR_PALETTE } from "./constants-DCZL77t-.mjs";
20
21
  import { c as WESTERN_ZODIAC_SIGNS, n as DAYS, r as MONTHS, s as VEDIC_ZODIAC_SIGNS } from "./constants-GZL_CT1W.mjs";
21
22
  import { a as TIME_ZONE_IDS, i as TIME_ZONES_NATIVE, n as NATIVE_TZ_IDS, o as TIME_ZONE_LABELS, r as TIME_ZONES, t as IANA_TZ_IDS } from "./timezone-avZ4TvDx.mjs";
22
- import { a as LOCALE_CODES, i as FRANKFURTER_CURRENCIES, n as CURRENCY_CODES, p as UNITS$1, r as CURRENCY_LOCALES } from "./constants-ZyfpysiQ.mjs";
23
23
  import { r as UNITS } from "./constants-ByLTHWQm.mjs";
24
24
  import { t as COUNTRIES } from "./countries-CMxHxKiK.mjs";
25
25
  import { t as HTTP_STATUS_CODES } from "./constants-BLAcLxOu.mjs";
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  const require_primitives = require('./primitives-CBGICrDR.cjs');
18
- const require_guards = require('./guards-DGN95D2h.cjs');
18
+ const require_guards = require('./guards-CrfVwk0-.cjs');
19
19
 
20
20
  //#region src/colors/utils.ts
21
21
  /**
@@ -160,7 +160,11 @@ const convertRgbToHsl = (r, g, b) => {
160
160
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
161
161
  */
162
162
  const convertHslToHex = (h, s, l) => {
163
- const rgb = convertHslToRgb(h, s, l).match(/\d+/g).map(Number);
163
+ const rgb = convertHslToRgb(h, s, l).match(/\d+/g)?.map(Number) ?? [
164
+ 0,
165
+ 0,
166
+ 0
167
+ ];
164
168
  return convertRgbToHex(rgb[0], rgb[1], rgb[2]);
165
169
  };
166
170
  /**
@@ -15,7 +15,7 @@
15
15
  */
16
16
 
17
17
  import { a as isNonEmptyString, c as isNumber } from "./primitives-Djsevc69.mjs";
18
- import { a as isHex8, c as _applyOpacity, d as _isValidAlpha, i as isHex6, n as isHSL, o as isRGB, r as isHSLA, s as isRGBA } from "./guards-DziDBD0p.mjs";
18
+ import { a as isHex8, c as _applyOpacity, d as _isValidAlpha, i as isHex6, n as isHSL, o as isRGB, r as isHSLA, s as isRGBA } from "./guards-CNG9gnvL.mjs";
19
19
 
20
20
  //#region src/colors/utils.ts
21
21
  /**
@@ -160,7 +160,11 @@ const convertRgbToHsl = (r, g, b) => {
160
160
  * @returns A string representing the color in Hex format (e.g., `#FF0000`).
161
161
  */
162
162
  const convertHslToHex = (h, s, l) => {
163
- const rgb = convertHslToRgb(h, s, l).match(/\d+/g).map(Number);
163
+ const rgb = convertHslToRgb(h, s, l).match(/\d+/g)?.map(Number) ?? [
164
+ 0,
165
+ 0,
166
+ 0
167
+ ];
164
168
  return convertRgbToHex(rgb[0], rgb[1], rgb[2]);
165
169
  };
166
170
  /**