@fluixi/utils 1.0.0-alpha.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +73 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/array/advanced.cjs +1 -0
- package/dist/lib/array/advanced.d.ts +1116 -0
- package/dist/lib/array/advanced.d.ts.map +1 -0
- package/dist/lib/array/advanced.js +2429 -0
- package/dist/lib/array/advanced.mjs +1 -0
- package/dist/lib/array/array.cjs +1 -0
- package/dist/lib/array/array.d.ts +6 -0
- package/dist/lib/array/array.d.ts.map +1 -0
- package/dist/lib/array/array.js +31 -0
- package/dist/lib/array/array.mjs +1 -0
- package/dist/lib/array/index.cjs +1 -0
- package/dist/lib/array/index.d.ts +4 -0
- package/dist/lib/array/index.d.ts.map +1 -0
- package/dist/lib/array/index.js +3 -0
- package/dist/lib/array/index.mjs +1 -0
- package/dist/lib/array/utils.cjs +1 -0
- package/dist/lib/array/utils.d.ts +100 -0
- package/dist/lib/array/utils.d.ts.map +1 -0
- package/dist/lib/array/utils.js +165 -0
- package/dist/lib/array/utils.mjs +1 -0
- package/dist/lib/color/color.cjs +1 -0
- package/dist/lib/color/color.d.ts +366 -0
- package/dist/lib/color/color.d.ts.map +1 -0
- package/dist/lib/color/color.js +722 -0
- package/dist/lib/color/color.mjs +1 -0
- package/dist/lib/color/constants.cjs +1 -0
- package/dist/lib/color/constants.d.ts +361 -0
- package/dist/lib/color/constants.d.ts.map +1 -0
- package/dist/lib/color/constants.js +358 -0
- package/dist/lib/color/constants.mjs +1 -0
- package/dist/lib/color/conversions.cjs +1 -0
- package/dist/lib/color/conversions.d.ts +166 -0
- package/dist/lib/color/conversions.d.ts.map +1 -0
- package/dist/lib/color/conversions.js +766 -0
- package/dist/lib/color/conversions.mjs +1 -0
- package/dist/lib/color/helpers.cjs +1 -0
- package/dist/lib/color/helpers.d.ts +75 -0
- package/dist/lib/color/helpers.d.ts.map +1 -0
- package/dist/lib/color/helpers.js +419 -0
- package/dist/lib/color/helpers.mjs +1 -0
- package/dist/lib/color/index.cjs +1 -0
- package/dist/lib/color/index.d.ts +12 -0
- package/dist/lib/color/index.d.ts.map +1 -0
- package/dist/lib/color/index.js +15 -0
- package/dist/lib/color/index.mjs +1 -0
- package/dist/lib/color/types.cjs +1 -0
- package/dist/lib/color/types.d.ts +179 -0
- package/dist/lib/color/types.d.ts.map +1 -0
- package/dist/lib/color/types.js +1 -0
- package/dist/lib/color/types.mjs +0 -0
- package/dist/lib/color/utils.cjs +1 -0
- package/dist/lib/color/utils.d.ts +199 -0
- package/dist/lib/color/utils.d.ts.map +1 -0
- package/dist/lib/color/utils.js +858 -0
- package/dist/lib/color/utils.mjs +1 -0
- package/dist/lib/compare/comparators.cjs +1 -0
- package/dist/lib/compare/comparators.d.ts +65 -0
- package/dist/lib/compare/comparators.d.ts.map +1 -0
- package/dist/lib/compare/comparators.js +210 -0
- package/dist/lib/compare/comparators.mjs +1 -0
- package/dist/lib/compare/index.cjs +1 -0
- package/dist/lib/compare/index.d.ts +2 -0
- package/dist/lib/compare/index.d.ts.map +1 -0
- package/dist/lib/compare/index.js +1 -0
- package/dist/lib/compare/index.mjs +1 -0
- package/dist/lib/crypto/hash.cjs +1 -0
- package/dist/lib/crypto/hash.d.ts +6 -0
- package/dist/lib/crypto/hash.d.ts.map +1 -0
- package/dist/lib/crypto/hash.js +53 -0
- package/dist/lib/crypto/hash.mjs +1 -0
- package/dist/lib/crypto/index.cjs +1 -0
- package/dist/lib/crypto/index.d.ts +2 -0
- package/dist/lib/crypto/index.d.ts.map +1 -0
- package/dist/lib/crypto/index.js +1 -0
- package/dist/lib/crypto/index.mjs +1 -0
- package/dist/lib/dom/events.cjs +1 -0
- package/dist/lib/dom/events.d.ts +159 -0
- package/dist/lib/dom/events.d.ts.map +1 -0
- package/dist/lib/dom/events.js +50 -0
- package/dist/lib/dom/events.mjs +1 -0
- package/dist/lib/dom/index.cjs +1 -0
- package/dist/lib/dom/index.d.ts +3 -0
- package/dist/lib/dom/index.d.ts.map +1 -0
- package/dist/lib/dom/index.js +2 -0
- package/dist/lib/dom/index.mjs +1 -0
- package/dist/lib/dom/utils.cjs +1 -0
- package/dist/lib/dom/utils.d.ts +6 -0
- package/dist/lib/dom/utils.d.ts.map +1 -0
- package/dist/lib/dom/utils.js +37 -0
- package/dist/lib/dom/utils.mjs +1 -0
- package/dist/lib/functions/functions.cjs +1 -0
- package/dist/lib/functions/functions.d.ts +329 -0
- package/dist/lib/functions/functions.d.ts.map +1 -0
- package/dist/lib/functions/functions.js +585 -0
- package/dist/lib/functions/functions.mjs +1 -0
- package/dist/lib/functions/index.cjs +1 -0
- package/dist/lib/functions/index.d.ts +3 -0
- package/dist/lib/functions/index.d.ts.map +1 -0
- package/dist/lib/functions/index.js +1 -0
- package/dist/lib/functions/index.mjs +1 -0
- package/dist/lib/functions/types.cjs +1 -0
- package/dist/lib/functions/types.d.ts +2 -0
- package/dist/lib/functions/types.d.ts.map +1 -0
- package/dist/lib/functions/types.js +1 -0
- package/dist/lib/functions/types.mjs +0 -0
- package/dist/lib/helpers.cjs +1 -0
- package/dist/lib/helpers.d.ts +13 -0
- package/dist/lib/helpers.d.ts.map +1 -0
- package/dist/lib/helpers.js +66 -0
- package/dist/lib/helpers.mjs +1 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.ts +6 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/maths/constants.cjs +1 -0
- package/dist/lib/maths/constants.d.ts +84 -0
- package/dist/lib/maths/constants.d.ts.map +1 -0
- package/dist/lib/maths/constants.js +79 -0
- package/dist/lib/maths/constants.mjs +1 -0
- package/dist/lib/maths/fn/advanced.cjs +1 -0
- package/dist/lib/maths/fn/advanced.d.ts +149 -0
- package/dist/lib/maths/fn/advanced.d.ts.map +1 -0
- package/dist/lib/maths/fn/advanced.js +264 -0
- package/dist/lib/maths/fn/advanced.mjs +1 -0
- package/dist/lib/maths/fn/basic.cjs +1 -0
- package/dist/lib/maths/fn/basic.d.ts +182 -0
- package/dist/lib/maths/fn/basic.d.ts.map +1 -0
- package/dist/lib/maths/fn/basic.js +343 -0
- package/dist/lib/maths/fn/basic.mjs +1 -0
- package/dist/lib/maths/fn/complex.cjs +1 -0
- package/dist/lib/maths/fn/complex.d.ts +153 -0
- package/dist/lib/maths/fn/complex.d.ts.map +1 -0
- package/dist/lib/maths/fn/complex.js +383 -0
- package/dist/lib/maths/fn/complex.mjs +1 -0
- package/dist/lib/maths/fn/index.cjs +1 -0
- package/dist/lib/maths/fn/index.d.ts +10 -0
- package/dist/lib/maths/fn/index.d.ts.map +1 -0
- package/dist/lib/maths/fn/index.js +9 -0
- package/dist/lib/maths/fn/index.mjs +1 -0
- package/dist/lib/maths/fn/trigo.cjs +1 -0
- package/dist/lib/maths/fn/trigo.d.ts +147 -0
- package/dist/lib/maths/fn/trigo.d.ts.map +1 -0
- package/dist/lib/maths/fn/trigo.js +227 -0
- package/dist/lib/maths/fn/trigo.mjs +1 -0
- package/dist/lib/maths/fn/vector.cjs +1 -0
- package/dist/lib/maths/fn/vector.d.ts +512 -0
- package/dist/lib/maths/fn/vector.d.ts.map +1 -0
- package/dist/lib/maths/fn/vector.js +1136 -0
- package/dist/lib/maths/fn/vector.mjs +1 -0
- package/dist/lib/maths/formatter.cjs +1 -0
- package/dist/lib/maths/formatter.d.ts +35 -0
- package/dist/lib/maths/formatter.d.ts.map +1 -0
- package/dist/lib/maths/formatter.js +56 -0
- package/dist/lib/maths/formatter.mjs +1 -0
- package/dist/lib/maths/guards.cjs +1 -0
- package/dist/lib/maths/guards.d.ts +166 -0
- package/dist/lib/maths/guards.d.ts.map +1 -0
- package/dist/lib/maths/guards.js +315 -0
- package/dist/lib/maths/guards.mjs +1 -0
- package/dist/lib/maths/index.cjs +1 -0
- package/dist/lib/maths/index.d.ts +24 -0
- package/dist/lib/maths/index.d.ts.map +1 -0
- package/dist/lib/maths/index.js +29 -0
- package/dist/lib/maths/index.mjs +1 -0
- package/dist/lib/maths/parser.cjs +1 -0
- package/dist/lib/maths/parser.d.ts +20 -0
- package/dist/lib/maths/parser.d.ts.map +1 -0
- package/dist/lib/maths/parser.js +78 -0
- package/dist/lib/maths/parser.mjs +1 -0
- package/dist/lib/maths/random.cjs +1 -0
- package/dist/lib/maths/random.d.ts +27 -0
- package/dist/lib/maths/random.d.ts.map +1 -0
- package/dist/lib/maths/random.js +49 -0
- package/dist/lib/maths/random.mjs +1 -0
- package/dist/lib/maths/types/advanced.cjs +1 -0
- package/dist/lib/maths/types/advanced.d.ts +357 -0
- package/dist/lib/maths/types/advanced.d.ts.map +1 -0
- package/dist/lib/maths/types/advanced.js +5 -0
- package/dist/lib/maths/types/advanced.mjs +0 -0
- package/dist/lib/maths/types/basic.cjs +1 -0
- package/dist/lib/maths/types/basic.d.ts +95 -0
- package/dist/lib/maths/types/basic.d.ts.map +1 -0
- package/dist/lib/maths/types/basic.js +5 -0
- package/dist/lib/maths/types/basic.mjs +0 -0
- package/dist/lib/maths/types/index.cjs +1 -0
- package/dist/lib/maths/types/index.d.ts +4 -0
- package/dist/lib/maths/types/index.d.ts.map +1 -0
- package/dist/lib/maths/types/index.js +3 -0
- package/dist/lib/maths/types/index.mjs +0 -0
- package/dist/lib/maths/types/negative.cjs +1 -0
- package/dist/lib/maths/types/negative.d.ts +51 -0
- package/dist/lib/maths/types/negative.d.ts.map +1 -0
- package/dist/lib/maths/types/negative.js +5 -0
- package/dist/lib/maths/types/negative.mjs +0 -0
- package/dist/lib/maths/types/operations.cjs +1 -0
- package/dist/lib/maths/types/operations.d.ts +188 -0
- package/dist/lib/maths/types/operations.d.ts.map +1 -0
- package/dist/lib/maths/types/operations.js +6 -0
- package/dist/lib/maths/types/operations.mjs +0 -0
- package/dist/lib/object/clone.cjs +1 -0
- package/dist/lib/object/clone.d.ts +46 -0
- package/dist/lib/object/clone.d.ts.map +1 -0
- package/dist/lib/object/clone.js +104 -0
- package/dist/lib/object/clone.mjs +1 -0
- package/dist/lib/object/diff.cjs +1 -0
- package/dist/lib/object/diff.d.ts +203 -0
- package/dist/lib/object/diff.d.ts.map +1 -0
- package/dist/lib/object/diff.js +805 -0
- package/dist/lib/object/diff.mjs +1 -0
- package/dist/lib/object/getter-setter.cjs +1 -0
- package/dist/lib/object/getter-setter.d.ts +361 -0
- package/dist/lib/object/getter-setter.d.ts.map +1 -0
- package/dist/lib/object/getter-setter.js +1771 -0
- package/dist/lib/object/getter-setter.mjs +1 -0
- package/dist/lib/object/index.cjs +6 -0
- package/dist/lib/object/index.d.ts +13 -0
- package/dist/lib/object/index.d.ts.map +1 -0
- package/dist/lib/object/index.js +12 -0
- package/dist/lib/object/index.mjs +6 -0
- package/dist/lib/object/merge.cjs +1 -0
- package/dist/lib/object/merge.d.ts +93 -0
- package/dist/lib/object/merge.d.ts.map +1 -0
- package/dist/lib/object/merge.js +474 -0
- package/dist/lib/object/merge.mjs +1 -0
- package/dist/lib/object/object.cjs +1 -0
- package/dist/lib/object/object.d.ts +128 -0
- package/dist/lib/object/object.d.ts.map +1 -0
- package/dist/lib/object/object.js +432 -0
- package/dist/lib/object/object.mjs +1 -0
- package/dist/lib/object/omit.cjs +1 -0
- package/dist/lib/object/omit.d.ts +351 -0
- package/dist/lib/object/omit.d.ts.map +1 -0
- package/dist/lib/object/omit.js +656 -0
- package/dist/lib/object/omit.mjs +1 -0
- package/dist/lib/object/reconcile.cjs +1 -0
- package/dist/lib/object/reconcile.d.ts +7 -0
- package/dist/lib/object/reconcile.d.ts.map +1 -0
- package/dist/lib/object/reconcile.js +122 -0
- package/dist/lib/object/reconcile.mjs +1 -0
- package/dist/lib/object/selector.cjs +1 -0
- package/dist/lib/object/selector.d.ts +50 -0
- package/dist/lib/object/selector.d.ts.map +1 -0
- package/dist/lib/object/selector.js +371 -0
- package/dist/lib/object/selector.mjs +1 -0
- package/dist/lib/object/sort.cjs +1 -0
- package/dist/lib/object/sort.d.ts +149 -0
- package/dist/lib/object/sort.d.ts.map +1 -0
- package/dist/lib/object/sort.js +298 -0
- package/dist/lib/object/sort.mjs +1 -0
- package/dist/lib/object/transform.cjs +1 -0
- package/dist/lib/object/transform.d.ts +620 -0
- package/dist/lib/object/transform.d.ts.map +1 -0
- package/dist/lib/object/transform.js +1058 -0
- package/dist/lib/object/transform.mjs +1 -0
- package/dist/lib/object/types.cjs +1 -0
- package/dist/lib/object/types.d.ts +250 -0
- package/dist/lib/object/types.d.ts.map +1 -0
- package/dist/lib/object/types.js +1 -0
- package/dist/lib/object/types.mjs +0 -0
- package/dist/lib/object/utils.cjs +6 -0
- package/dist/lib/object/utils.d.ts +165 -0
- package/dist/lib/object/utils.d.ts.map +1 -0
- package/dist/lib/object/utils.js +444 -0
- package/dist/lib/object/utils.mjs +6 -0
- package/dist/lib/primitive/boolean/boolean.cjs +1 -0
- package/dist/lib/primitive/boolean/boolean.d.ts +276 -0
- package/dist/lib/primitive/boolean/boolean.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/boolean.js +615 -0
- package/dist/lib/primitive/boolean/boolean.mjs +1 -0
- package/dist/lib/primitive/boolean/index.cjs +1 -0
- package/dist/lib/primitive/boolean/index.d.ts +3 -0
- package/dist/lib/primitive/boolean/index.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/index.js +2 -0
- package/dist/lib/primitive/boolean/index.mjs +1 -0
- package/dist/lib/primitive/boolean/types.cjs +1 -0
- package/dist/lib/primitive/boolean/types.d.ts +14 -0
- package/dist/lib/primitive/boolean/types.d.ts.map +1 -0
- package/dist/lib/primitive/boolean/types.js +1 -0
- package/dist/lib/primitive/boolean/types.mjs +0 -0
- package/dist/lib/primitive/date/date.cjs +1 -0
- package/dist/lib/primitive/date/date.d.ts +641 -0
- package/dist/lib/primitive/date/date.d.ts.map +1 -0
- package/dist/lib/primitive/date/date.js +1998 -0
- package/dist/lib/primitive/date/date.mjs +1 -0
- package/dist/lib/primitive/date/index.cjs +1 -0
- package/dist/lib/primitive/date/index.d.ts +3 -0
- package/dist/lib/primitive/date/index.d.ts.map +1 -0
- package/dist/lib/primitive/date/index.js +2 -0
- package/dist/lib/primitive/date/index.mjs +1 -0
- package/dist/lib/primitive/date/types.cjs +1 -0
- package/dist/lib/primitive/date/types.d.ts +205 -0
- package/dist/lib/primitive/date/types.d.ts.map +1 -0
- package/dist/lib/primitive/date/types.js +7 -0
- package/dist/lib/primitive/date/types.mjs +0 -0
- package/dist/lib/primitive/index.cjs +5 -0
- package/dist/lib/primitive/index.d.ts +5 -0
- package/dist/lib/primitive/index.d.ts.map +1 -0
- package/dist/lib/primitive/index.js +4 -0
- package/dist/lib/primitive/index.mjs +5 -0
- package/dist/lib/primitive/string/index.cjs +5 -0
- package/dist/lib/primitive/string/index.d.ts +3 -0
- package/dist/lib/primitive/string/index.d.ts.map +1 -0
- package/dist/lib/primitive/string/index.js +2 -0
- package/dist/lib/primitive/string/index.mjs +5 -0
- package/dist/lib/primitive/string/parser-2.cjs +8 -0
- package/dist/lib/primitive/string/parser-2.d.ts +17 -0
- package/dist/lib/primitive/string/parser-2.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser-2.js +656 -0
- package/dist/lib/primitive/string/parser-2.mjs +8 -0
- package/dist/lib/primitive/string/parser.cjs +3 -0
- package/dist/lib/primitive/string/parser.d.ts +9 -0
- package/dist/lib/primitive/string/parser.d.ts.map +1 -0
- package/dist/lib/primitive/string/parser.js +775 -0
- package/dist/lib/primitive/string/parser.mjs +3 -0
- package/dist/lib/primitive/string/string.cjs +5 -0
- package/dist/lib/primitive/string/string.d.ts +535 -0
- package/dist/lib/primitive/string/string.d.ts.map +1 -0
- package/dist/lib/primitive/string/string.js +1301 -0
- package/dist/lib/primitive/string/string.mjs +5 -0
- package/dist/lib/primitive/string/types.cjs +1 -0
- package/dist/lib/primitive/string/types.d.ts +318 -0
- package/dist/lib/primitive/string/types.d.ts.map +1 -0
- package/dist/lib/primitive/string/types.js +5 -0
- package/dist/lib/primitive/string/types.mjs +0 -0
- package/dist/lib/primitive/types.cjs +1 -0
- package/dist/lib/primitive/types.d.ts +27 -0
- package/dist/lib/primitive/types.d.ts.map +1 -0
- package/dist/lib/primitive/types.js +1 -0
- package/dist/lib/primitive/types.mjs +0 -0
- package/dist/lib/url/index.cjs +1 -0
- package/dist/lib/url/index.d.ts +3 -0
- package/dist/lib/url/index.d.ts.map +1 -0
- package/dist/lib/url/index.js +2 -0
- package/dist/lib/url/index.mjs +1 -0
- package/dist/lib/url/parser.cjs +1 -0
- package/dist/lib/url/parser.d.ts +216 -0
- package/dist/lib/url/parser.d.ts.map +1 -0
- package/dist/lib/url/parser.js +488 -0
- package/dist/lib/url/parser.mjs +1 -0
- package/dist/lib/url/types.cjs +1 -0
- package/dist/lib/url/types.d.ts +18 -0
- package/dist/lib/url/types.d.ts.map +1 -0
- package/dist/lib/url/types.js +1 -0
- package/dist/lib/url/types.mjs +0 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +150 -0
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
import { adjustColor, calculateContrastRatio, calculateLuminance, createContrastColor, formatRgba, generatePalette, isValidColor, mixColors, parseColor, parseRgbaColor, RGB_PATTERNS, rgbaToCmyk, rgbaToHex, rgbaToHsl, rgbaToHsv, } from './utils.js';
|
|
2
|
+
import { rgbToHsl, rgbToHsv, rgbToHwb, rgbToCmyk, rgbToXyz, rgbToLab, rgbToLch, rgbToOklab, rgbToOklch, hslToRgb, hsvToRgb, hwbToRgb, cmykToRgb, xyzToRgb, labToRgb, lchToRgb, oklchToRgb, convertColor, getSupportedFormats, isValidFormat, getConversionPath, } from './conversions.js';
|
|
3
|
+
/**
|
|
4
|
+
* Color class for object-oriented color manipulation
|
|
5
|
+
*/
|
|
6
|
+
export class Color {
|
|
7
|
+
_r = 0;
|
|
8
|
+
_g = 0;
|
|
9
|
+
_b = 0;
|
|
10
|
+
_a = 1;
|
|
11
|
+
/**
|
|
12
|
+
* Parse any RGB/RGBA format
|
|
13
|
+
*/
|
|
14
|
+
static parseRgbString(colorString) {
|
|
15
|
+
return parseRgbaColor(colorString);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check if string matches any RGB pattern
|
|
19
|
+
*/
|
|
20
|
+
static isRgbFormat(colorString) {
|
|
21
|
+
return Object.values(RGB_PATTERNS).some((pattern) => pattern.test(colorString.trim()));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get the specific RGB pattern that matches
|
|
25
|
+
*/
|
|
26
|
+
static getRgbPatternMatch(colorString) {
|
|
27
|
+
const str = colorString.trim();
|
|
28
|
+
for (const [name, pattern] of Object.entries(RGB_PATTERNS)) {
|
|
29
|
+
if (pattern.test(str)) {
|
|
30
|
+
return name;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert RGB values to modern CSS syntax
|
|
37
|
+
*/
|
|
38
|
+
static toModernRgbSyntax(r, g, b, a) {
|
|
39
|
+
const components = [r, g, b];
|
|
40
|
+
if (a !== undefined && a !== 1) {
|
|
41
|
+
return `rgb(${components.join(' ')} / ${a})`;
|
|
42
|
+
}
|
|
43
|
+
return `rgb(${components.join(' ')})`;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Convert RGB values to legacy syntax
|
|
47
|
+
*/
|
|
48
|
+
static toLegacyRgbSyntax(r, g, b, a) {
|
|
49
|
+
const components = [r, g, b];
|
|
50
|
+
if (a !== undefined && a !== 1) {
|
|
51
|
+
return `rgba(${components.join(', ')}, ${a})`;
|
|
52
|
+
}
|
|
53
|
+
return `rgb(${components.join(', ')})`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Normalize RGB string to a consistent format
|
|
57
|
+
*/
|
|
58
|
+
static normalizeRgbString(colorString, format = 'modern') {
|
|
59
|
+
const rgba = parseRgbaColor(colorString);
|
|
60
|
+
if (!rgba)
|
|
61
|
+
return null;
|
|
62
|
+
const [r, g, b, a] = rgba;
|
|
63
|
+
if (format === 'modern') {
|
|
64
|
+
return this.toModernRgbSyntax(r, g, b, a);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return this.toLegacyRgbSyntax(r, g, b, a);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new Color instance
|
|
72
|
+
* @param color - Color representation (string, array, object, or another Color)
|
|
73
|
+
*/
|
|
74
|
+
constructor(color = '#000000') {
|
|
75
|
+
this.set(color);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Sets the color from any representation
|
|
79
|
+
* @param color - Color representation
|
|
80
|
+
* @returns This Color instance for chaining
|
|
81
|
+
*/
|
|
82
|
+
set(color) {
|
|
83
|
+
if (typeof color === 'string') {
|
|
84
|
+
const rgb = parseColor(color);
|
|
85
|
+
if (rgb) {
|
|
86
|
+
[this._r, this._g, this._b, this._a] = rgb;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (Array.isArray(color)) {
|
|
90
|
+
[this._r = 0, this._g = 0, this._b = 0, this._a = 1] = color;
|
|
91
|
+
}
|
|
92
|
+
else if (color instanceof Color) {
|
|
93
|
+
[this._r, this._g, this._b, this._a] = [
|
|
94
|
+
color._r,
|
|
95
|
+
color._g,
|
|
96
|
+
color._b,
|
|
97
|
+
color._a,
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
else if (typeof color === 'object') {
|
|
101
|
+
// Handle all color space objects
|
|
102
|
+
return this.setFromObject(color);
|
|
103
|
+
}
|
|
104
|
+
this._clamp();
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Clamps color values to valid ranges
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
_clamp() {
|
|
112
|
+
this._r = Math.max(0, Math.min(255, Math.round(this._r)));
|
|
113
|
+
this._g = Math.max(0, Math.min(255, Math.round(this._g)));
|
|
114
|
+
this._b = Math.max(0, Math.min(255, Math.round(this._b)));
|
|
115
|
+
this._a = Math.max(0, Math.min(1, this._a));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the red component
|
|
119
|
+
*/
|
|
120
|
+
get r() {
|
|
121
|
+
return this._r;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Sets the red component
|
|
125
|
+
*/
|
|
126
|
+
set r(value) {
|
|
127
|
+
this._r = value;
|
|
128
|
+
this._clamp();
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets the green component
|
|
132
|
+
*/
|
|
133
|
+
get g() {
|
|
134
|
+
return this._g;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Sets the green component
|
|
138
|
+
*/
|
|
139
|
+
set g(value) {
|
|
140
|
+
this._g = value;
|
|
141
|
+
this._clamp();
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Gets the blue component
|
|
145
|
+
*/
|
|
146
|
+
get b() {
|
|
147
|
+
return this._b;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Sets the blue component
|
|
151
|
+
*/
|
|
152
|
+
set b(value) {
|
|
153
|
+
this._b = value;
|
|
154
|
+
this._clamp();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Gets the alpha component
|
|
158
|
+
*/
|
|
159
|
+
get a() {
|
|
160
|
+
return this._a;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Sets the alpha component
|
|
164
|
+
*/
|
|
165
|
+
set a(value) {
|
|
166
|
+
this._a = value;
|
|
167
|
+
this._clamp();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Gets the RGB array
|
|
171
|
+
*/
|
|
172
|
+
get rgb() {
|
|
173
|
+
return [this._r, this._g, this._b];
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Gets the RGBA array
|
|
177
|
+
*/
|
|
178
|
+
get rgba() {
|
|
179
|
+
return [this._r, this._g, this._b, this._a];
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Converts to hex string
|
|
183
|
+
* @returns Hex color string
|
|
184
|
+
*/
|
|
185
|
+
toHex() {
|
|
186
|
+
return rgbaToHex(this._r, this._g, this._b, this._a);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Converts to RGB string
|
|
190
|
+
* @returns RGB color string
|
|
191
|
+
*/
|
|
192
|
+
toRgb() {
|
|
193
|
+
return formatRgba(this._r, this._g, this._b);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Converts to RGBA string
|
|
197
|
+
* @returns RGBA color string
|
|
198
|
+
*/
|
|
199
|
+
toRgba() {
|
|
200
|
+
return formatRgba(this._r, this._g, this._b, this._a);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Gets RGB object
|
|
204
|
+
* @returns RGB color object
|
|
205
|
+
*/
|
|
206
|
+
getRgbObject() {
|
|
207
|
+
return { r: this._r, g: this._g, b: this._b, a: this._a };
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Converts to HSL string
|
|
211
|
+
* @returns HSL/HSLA color string
|
|
212
|
+
*/
|
|
213
|
+
toHsl() {
|
|
214
|
+
return rgbaToHsl(this._r, this._g, this._b, this._a);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets HSL object
|
|
218
|
+
* @returns HSL color object
|
|
219
|
+
*/
|
|
220
|
+
getHslObject() {
|
|
221
|
+
return rgbToHsl(this.getRgbObject());
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Converts to HSV string
|
|
225
|
+
* @returns HSV/HSVA color string
|
|
226
|
+
*/
|
|
227
|
+
toHsv() {
|
|
228
|
+
return rgbaToHsv(this._r, this._g, this._b, this._a);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Gets HSV object
|
|
232
|
+
* @returns HSV color object
|
|
233
|
+
*/
|
|
234
|
+
getHsvObject() {
|
|
235
|
+
return rgbToHsv(this.getRgbObject());
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Converts to HWB string
|
|
239
|
+
* @returns HWB color string
|
|
240
|
+
*/
|
|
241
|
+
toHwb() {
|
|
242
|
+
const hwb = rgbToHwb(this.getRgbObject());
|
|
243
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
244
|
+
return `hwb(${Math.round(hwb.h)} ${Math.round(hwb.w)}% ${Math.round(hwb.b)}%${alphaStr})`;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Gets HWB object
|
|
248
|
+
* @returns HWB color object
|
|
249
|
+
*/
|
|
250
|
+
getHwbObject() {
|
|
251
|
+
return rgbToHwb(this.getRgbObject());
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Converts to CMYK string
|
|
255
|
+
* @returns CMYK color string
|
|
256
|
+
*/
|
|
257
|
+
toCmyk() {
|
|
258
|
+
return rgbaToCmyk(this._r, this._g, this._b, this._a);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gets CMYK object
|
|
262
|
+
* @returns CMYK color object
|
|
263
|
+
*/
|
|
264
|
+
getCmykObject() {
|
|
265
|
+
return rgbToCmyk(this.getRgbObject());
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Converts to XYZ string
|
|
269
|
+
* @returns XYZ color string
|
|
270
|
+
*/
|
|
271
|
+
toXyz() {
|
|
272
|
+
const xyz = rgbToXyz(this.getRgbObject());
|
|
273
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
274
|
+
return `color(xyz ${xyz.x.toFixed(4)} ${xyz.y.toFixed(4)} ${xyz.z.toFixed(4)}${alphaStr})`;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Gets XYZ object
|
|
278
|
+
* @returns XYZ color object
|
|
279
|
+
*/
|
|
280
|
+
getXyzObject() {
|
|
281
|
+
return rgbToXyz(this.getRgbObject());
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Converts to LAB string
|
|
285
|
+
* @returns LAB color string
|
|
286
|
+
*/
|
|
287
|
+
toLab() {
|
|
288
|
+
const lab = rgbToLab(this.getRgbObject());
|
|
289
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
290
|
+
return `lab(${lab.l.toFixed(2)}% ${lab.a.toFixed(2)} ${lab.b.toFixed(2)}${alphaStr})`;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Gets LAB object
|
|
294
|
+
* @returns LAB color object
|
|
295
|
+
*/
|
|
296
|
+
getLabObject() {
|
|
297
|
+
return rgbToLab(this.getRgbObject());
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Converts to LCH string
|
|
301
|
+
* @returns LCH color string
|
|
302
|
+
*/
|
|
303
|
+
toLch() {
|
|
304
|
+
const lch = rgbToLch(this.getRgbObject());
|
|
305
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
306
|
+
return `lch(${lch.l.toFixed(2)}% ${lch.c.toFixed(2)} ${lch.h.toFixed(2)}${alphaStr})`;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Gets LCH object
|
|
310
|
+
* @returns LCH color object
|
|
311
|
+
*/
|
|
312
|
+
getLchObject() {
|
|
313
|
+
return rgbToLch(this.getRgbObject());
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Converts to OKLAB string
|
|
317
|
+
* @returns OKLAB color string
|
|
318
|
+
*/
|
|
319
|
+
toOklab() {
|
|
320
|
+
const oklab = rgbToOklab(this.getRgbObject());
|
|
321
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
322
|
+
return `oklab(${oklab.l.toFixed(4)} ${oklab.a.toFixed(4)} ${oklab.b.toFixed(4)}${alphaStr})`;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Gets OKLAB object
|
|
326
|
+
* @returns OKLAB color object
|
|
327
|
+
*/
|
|
328
|
+
getOklabObject() {
|
|
329
|
+
return rgbToOklab(this.getRgbObject());
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Converts to OKLCH string
|
|
333
|
+
* @returns OKLCH color string
|
|
334
|
+
*/
|
|
335
|
+
toOklch() {
|
|
336
|
+
const oklch = rgbToOklch(this.getRgbObject());
|
|
337
|
+
const alphaStr = this._a < 1 ? ` / ${Math.round(this._a * 100) / 100}` : '';
|
|
338
|
+
return `oklch(${oklch.l.toFixed(4)} ${oklch.c.toFixed(4)} ${oklch.h.toFixed(2)}${alphaStr})`;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Gets OKLCH object
|
|
342
|
+
* @returns OKLCH color object
|
|
343
|
+
*/
|
|
344
|
+
getOklchObject() {
|
|
345
|
+
return rgbToOklch(this.getRgbObject());
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Adjusts the color
|
|
349
|
+
* @param options - Adjustment options
|
|
350
|
+
* @returns This Color instance for chaining
|
|
351
|
+
*/
|
|
352
|
+
adjust(options) {
|
|
353
|
+
const adjusted = adjustColor(this.toHex(), options);
|
|
354
|
+
this.set(adjusted);
|
|
355
|
+
return this;
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Lightens the color
|
|
359
|
+
* @param amount - Lighten amount (0-100)
|
|
360
|
+
* @returns This Color instance for chaining
|
|
361
|
+
*/
|
|
362
|
+
lighten(amount) {
|
|
363
|
+
return this.adjust({ lightness: amount });
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Darkens the color
|
|
367
|
+
* @param amount - Darken amount (0-100)
|
|
368
|
+
* @returns This Color instance for chaining
|
|
369
|
+
*/
|
|
370
|
+
darken(amount) {
|
|
371
|
+
return this.adjust({ lightness: -amount });
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Saturates the color
|
|
375
|
+
* @param amount - Saturate amount (0-100)
|
|
376
|
+
* @returns This Color instance for chaining
|
|
377
|
+
*/
|
|
378
|
+
saturate(amount) {
|
|
379
|
+
return this.adjust({ saturation: amount });
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Desaturates the color
|
|
383
|
+
* @param amount - Desaturate amount (0-100)
|
|
384
|
+
* @returns This Color instance for chaining
|
|
385
|
+
*/
|
|
386
|
+
desaturate(amount) {
|
|
387
|
+
return this.adjust({ saturation: -amount });
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Rotates the hue
|
|
391
|
+
* @param degrees - Hue rotation in degrees
|
|
392
|
+
* @returns This Color instance for chaining
|
|
393
|
+
*/
|
|
394
|
+
rotate(degrees) {
|
|
395
|
+
return this.adjust({ hue: degrees });
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Sets the alpha value
|
|
399
|
+
* @param alpha - Alpha value (0-1)
|
|
400
|
+
* @returns This Color instance for chaining
|
|
401
|
+
*/
|
|
402
|
+
alpha(alpha) {
|
|
403
|
+
this._a = Math.max(0, Math.min(1, alpha));
|
|
404
|
+
return this;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Mixes with another color
|
|
408
|
+
* @param color - Color to mix with
|
|
409
|
+
* @param percentage - Mix percentage (0-100)
|
|
410
|
+
* @param colorSpace - Color space for mixing
|
|
411
|
+
* @returns This Color instance for chaining
|
|
412
|
+
*/
|
|
413
|
+
mix(color, percentage = 50, colorSpace = 'srgb') {
|
|
414
|
+
const mixed = mixColors({
|
|
415
|
+
color: this.toHex(),
|
|
416
|
+
with: color,
|
|
417
|
+
percentage,
|
|
418
|
+
colorSpace,
|
|
419
|
+
});
|
|
420
|
+
this.set(mixed);
|
|
421
|
+
return this;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Gets the contrasting color
|
|
425
|
+
* @param options - Contrast options
|
|
426
|
+
* @returns Contrasting Color instance
|
|
427
|
+
*/
|
|
428
|
+
getContrastColor(options = {}) {
|
|
429
|
+
const contrast = createContrastColor(this.toHex(), options);
|
|
430
|
+
return new Color(contrast);
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Gets the relative luminance
|
|
434
|
+
* @returns Relative luminance (0-1)
|
|
435
|
+
*/
|
|
436
|
+
getLuminance() {
|
|
437
|
+
return calculateLuminance(this._r, this._g, this._b);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Calculates contrast ratio with another color
|
|
441
|
+
* @param color - Color to compare with
|
|
442
|
+
* @returns Contrast ratio (1-21)
|
|
443
|
+
*/
|
|
444
|
+
getContrastRatio(color) {
|
|
445
|
+
const otherColor = color instanceof Color ? color.toHex() : color;
|
|
446
|
+
return calculateContrastRatio(this.toHex(), otherColor);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Generates a palette from this color
|
|
450
|
+
* @param options - Palette options
|
|
451
|
+
* @returns Object with color shades
|
|
452
|
+
*/
|
|
453
|
+
getPalette(options = {}) {
|
|
454
|
+
return generatePalette(this.toHex(), options);
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Clones the color
|
|
458
|
+
* @returns New Color instance with same values
|
|
459
|
+
*/
|
|
460
|
+
clone() {
|
|
461
|
+
return new Color(this.rgba);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Converts to string in specified format
|
|
465
|
+
* @param format - Output format
|
|
466
|
+
* @returns Color string
|
|
467
|
+
*/
|
|
468
|
+
toString(format = 'hex') {
|
|
469
|
+
switch (format) {
|
|
470
|
+
case 'hex':
|
|
471
|
+
return this.toHex();
|
|
472
|
+
case 'rgb':
|
|
473
|
+
return this.toRgb();
|
|
474
|
+
case 'rgba':
|
|
475
|
+
return this.toRgba();
|
|
476
|
+
case 'hsl':
|
|
477
|
+
return this.toHsl();
|
|
478
|
+
case 'hsla':
|
|
479
|
+
return this.toHsl();
|
|
480
|
+
case 'hsv':
|
|
481
|
+
return this.toHsv();
|
|
482
|
+
case 'hsva':
|
|
483
|
+
return this.toHsv();
|
|
484
|
+
case 'hwb':
|
|
485
|
+
return this.toHwb();
|
|
486
|
+
case 'cmyk':
|
|
487
|
+
return this.toCmyk();
|
|
488
|
+
case 'xyz':
|
|
489
|
+
return this.toXyz();
|
|
490
|
+
case 'lab':
|
|
491
|
+
return this.toLab();
|
|
492
|
+
case 'lch':
|
|
493
|
+
return this.toLch();
|
|
494
|
+
case 'oklab':
|
|
495
|
+
return this.toOklab();
|
|
496
|
+
case 'oklch':
|
|
497
|
+
return this.toOklch();
|
|
498
|
+
default:
|
|
499
|
+
return this.toHex();
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Convert to any format with options
|
|
504
|
+
* @param format - Target format
|
|
505
|
+
* @param options - Conversion options
|
|
506
|
+
* @returns Converted color object
|
|
507
|
+
*/
|
|
508
|
+
convertTo(format, options = {}) {
|
|
509
|
+
return convertColor(this.getRgbObject(), format, options);
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Set color from any color space object
|
|
513
|
+
* @param color - Color object in any supported format
|
|
514
|
+
* @returns This Color instance for chaining
|
|
515
|
+
*/
|
|
516
|
+
setFromObject(color) {
|
|
517
|
+
let rgb;
|
|
518
|
+
if ('r' in color && 'g' in color && 'b' in color) {
|
|
519
|
+
rgb = color;
|
|
520
|
+
}
|
|
521
|
+
else if ('h' in color && 's' in color && 'l' in color) {
|
|
522
|
+
rgb = hslToRgb(color);
|
|
523
|
+
}
|
|
524
|
+
else if ('h' in color && 's' in color && 'v' in color) {
|
|
525
|
+
rgb = hsvToRgb(color);
|
|
526
|
+
}
|
|
527
|
+
else if ('h' in color && 'w' in color && 'b' in color) {
|
|
528
|
+
rgb = hwbToRgb(color);
|
|
529
|
+
}
|
|
530
|
+
else if ('c' in color && 'm' in color && 'y' in color && 'k' in color) {
|
|
531
|
+
rgb = cmykToRgb(color);
|
|
532
|
+
}
|
|
533
|
+
else if ('x' in color && 'y' in color && 'z' in color) {
|
|
534
|
+
rgb = xyzToRgb(color);
|
|
535
|
+
}
|
|
536
|
+
else if ('l' in color && 'a' in color && 'b' in color) {
|
|
537
|
+
rgb = labToRgb(color);
|
|
538
|
+
}
|
|
539
|
+
else if ('l' in color && 'c' in color && 'h' in color) {
|
|
540
|
+
// Check if it's OKLCH or LCH based on value ranges
|
|
541
|
+
const lchColor = color;
|
|
542
|
+
rgb =
|
|
543
|
+
lchColor.l <= 1 ? oklchToRgb(color) : lchToRgb(lchColor);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
throw new Error('Unknown color format');
|
|
547
|
+
}
|
|
548
|
+
this._r = rgb.r;
|
|
549
|
+
this._g = rgb.g;
|
|
550
|
+
this._b = rgb.b;
|
|
551
|
+
this._a = rgb.a ?? 1;
|
|
552
|
+
this._clamp();
|
|
553
|
+
return this;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Get color harmony colors
|
|
557
|
+
* @param options - Harmony options
|
|
558
|
+
* @returns Array of Color instances
|
|
559
|
+
*/
|
|
560
|
+
getHarmony(options = {}) {
|
|
561
|
+
const { type = 'complementary', count = 5, angleOffset = 30 } = options;
|
|
562
|
+
const hsl = this.getHslObject();
|
|
563
|
+
const colors = [];
|
|
564
|
+
switch (type) {
|
|
565
|
+
case 'complementary':
|
|
566
|
+
colors.push(new Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a }));
|
|
567
|
+
break;
|
|
568
|
+
case 'analogous':
|
|
569
|
+
colors.push(new Color({
|
|
570
|
+
h: (hsl.h - angleOffset + 360) % 360,
|
|
571
|
+
s: hsl.s,
|
|
572
|
+
l: hsl.l,
|
|
573
|
+
a: hsl.a,
|
|
574
|
+
}), new Color({
|
|
575
|
+
h: (hsl.h + angleOffset) % 360,
|
|
576
|
+
s: hsl.s,
|
|
577
|
+
l: hsl.l,
|
|
578
|
+
a: hsl.a,
|
|
579
|
+
}));
|
|
580
|
+
break;
|
|
581
|
+
case 'triadic':
|
|
582
|
+
colors.push(new Color({ h: (hsl.h + 120) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 240) % 360, s: hsl.s, l: hsl.l, a: hsl.a }));
|
|
583
|
+
break;
|
|
584
|
+
case 'tetradic':
|
|
585
|
+
colors.push(new Color({ h: (hsl.h + 90) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 270) % 360, s: hsl.s, l: hsl.l, a: hsl.a }));
|
|
586
|
+
break;
|
|
587
|
+
case 'split-complementary':
|
|
588
|
+
colors.push(new Color({ h: (hsl.h + 150) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 210) % 360, s: hsl.s, l: hsl.l, a: hsl.a }));
|
|
589
|
+
break;
|
|
590
|
+
case 'square':
|
|
591
|
+
colors.push(new Color({ h: (hsl.h + 90) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 180) % 360, s: hsl.s, l: hsl.l, a: hsl.a }), new Color({ h: (hsl.h + 270) % 360, s: hsl.s, l: hsl.l, a: hsl.a }));
|
|
592
|
+
break;
|
|
593
|
+
case 'monochromatic':
|
|
594
|
+
const step = 100 / (count + 1);
|
|
595
|
+
for (let i = 1; i <= count; i++) {
|
|
596
|
+
colors.push(new Color({
|
|
597
|
+
h: hsl.h,
|
|
598
|
+
s: hsl.s,
|
|
599
|
+
l: Math.max(0, Math.min(100, step * i)),
|
|
600
|
+
a: hsl.a,
|
|
601
|
+
}));
|
|
602
|
+
}
|
|
603
|
+
break;
|
|
604
|
+
}
|
|
605
|
+
return colors;
|
|
606
|
+
}
|
|
607
|
+
/**
|
|
608
|
+
* Get supported color formats
|
|
609
|
+
* @returns Array of supported format names
|
|
610
|
+
*/
|
|
611
|
+
static getSupportedFormats() {
|
|
612
|
+
return getSupportedFormats();
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* Check if format is valid
|
|
616
|
+
* @param format - Format to check
|
|
617
|
+
* @returns True if format is supported
|
|
618
|
+
*/
|
|
619
|
+
static isValidFormat(format) {
|
|
620
|
+
return isValidFormat(format);
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Get conversion path between formats
|
|
624
|
+
* @param from - Source format
|
|
625
|
+
* @param to - Target format
|
|
626
|
+
* @returns Array of formats in conversion path
|
|
627
|
+
*/
|
|
628
|
+
static getConversionPath(from, to) {
|
|
629
|
+
return getConversionPath(from, to);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Checks if the color is valid
|
|
633
|
+
* @returns True if color is valid
|
|
634
|
+
*/
|
|
635
|
+
isValid() {
|
|
636
|
+
return isValidColor(this.toHex());
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Creates a Color instance from string
|
|
640
|
+
* @param color - Color string
|
|
641
|
+
* @returns Color instance or null if invalid
|
|
642
|
+
*/
|
|
643
|
+
static fromString(color) {
|
|
644
|
+
if (!isValidColor(color)) {
|
|
645
|
+
return null;
|
|
646
|
+
}
|
|
647
|
+
return new Color(color);
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Creates a random Color
|
|
651
|
+
* @returns Random Color instance
|
|
652
|
+
*/
|
|
653
|
+
static random() {
|
|
654
|
+
const r = Math.floor(Math.random() * 256);
|
|
655
|
+
const g = Math.floor(Math.random() * 256);
|
|
656
|
+
const b = Math.floor(Math.random() * 256);
|
|
657
|
+
return new Color([r, g, b, 1]);
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Predefined colors
|
|
661
|
+
*/
|
|
662
|
+
static get transparent() {
|
|
663
|
+
return new Color('transparent');
|
|
664
|
+
}
|
|
665
|
+
static get white() {
|
|
666
|
+
return new Color('#ffffff');
|
|
667
|
+
}
|
|
668
|
+
static get black() {
|
|
669
|
+
return new Color('#000000');
|
|
670
|
+
}
|
|
671
|
+
static get red() {
|
|
672
|
+
return new Color('#ff0000');
|
|
673
|
+
}
|
|
674
|
+
static get green() {
|
|
675
|
+
return new Color('#00ff00');
|
|
676
|
+
}
|
|
677
|
+
static get blue() {
|
|
678
|
+
return new Color('#0000ff');
|
|
679
|
+
}
|
|
680
|
+
static get yellow() {
|
|
681
|
+
return new Color('#ffff00');
|
|
682
|
+
}
|
|
683
|
+
static get cyan() {
|
|
684
|
+
return new Color('#00ffff');
|
|
685
|
+
}
|
|
686
|
+
static get magenta() {
|
|
687
|
+
return new Color('#ff00ff');
|
|
688
|
+
}
|
|
689
|
+
static get gray() {
|
|
690
|
+
return new Color('#808080');
|
|
691
|
+
}
|
|
692
|
+
static get lightGray() {
|
|
693
|
+
return new Color('#d3d3d3');
|
|
694
|
+
}
|
|
695
|
+
static get darkGray() {
|
|
696
|
+
return new Color('#a9a9a9');
|
|
697
|
+
}
|
|
698
|
+
static get orange() {
|
|
699
|
+
return new Color('#ffa500');
|
|
700
|
+
}
|
|
701
|
+
static get purple() {
|
|
702
|
+
return new Color('#800080');
|
|
703
|
+
}
|
|
704
|
+
static get pink() {
|
|
705
|
+
return new Color('#ffc0cb');
|
|
706
|
+
}
|
|
707
|
+
static get brown() {
|
|
708
|
+
return new Color('#a52a2a');
|
|
709
|
+
}
|
|
710
|
+
static get teal() {
|
|
711
|
+
return new Color('#008080');
|
|
712
|
+
}
|
|
713
|
+
static get lime() {
|
|
714
|
+
return new Color('#00ff00');
|
|
715
|
+
}
|
|
716
|
+
static get indigo() {
|
|
717
|
+
return new Color('#4b0082');
|
|
718
|
+
}
|
|
719
|
+
static get violet() {
|
|
720
|
+
return new Color('#ee82ee');
|
|
721
|
+
}
|
|
722
|
+
}
|