@thi.ng/color-palettes 1.2.16 → 1.2.17
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/CHANGELOG.md +1 -1
- package/api.js +0 -1
- package/binary.js +9 -5
- package/filter.js +40 -127
- package/package.json +13 -10
- package/theme.js +63 -106
package/CHANGELOG.md
CHANGED
package/api.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/binary.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
// thing:no-export
|
|
2
|
-
// generated @ 20230425-163127 - DO NOT EDIT!
|
|
3
1
|
import { BASE64 } from "@thi.ng/base-n/64";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
const NUM_THEMES = 220;
|
|
3
|
+
const BINARY = BASE64.decodeBytes(
|
|
4
|
+
"61CiIIzUTrQIlucxxB7G+z38sxcEdezIO7OmB4mS3M5sM9oq3HvZJacd693CcegKniFIx+xqJZKTR54pYMf6iObPoRoez+/a1mi4BZaHP6uob9s5ihgisTtP5GeZF0y/MHbYIJkIL6MlONMuH0W7R0yBaGSHZ4mgk7rEsRcLBnXav0C2ybmYsOUzHBRduzhTq3Wr/4D0mdLgpvcDyiUvyjpLzta8kfOZngI9kyExdSc+PeoIK2KdDcbqsJqF/8iUxwI1yklbJqnZSeYbaQM+msj+yqHIjHSgWK8ok7antwKnuz6+rxTsffw55IKyLIyqZnyXUcLqiA2pqURj71OSGJf2Rs5cdukCryJ3++haFZubPaqSeb4DpeWTzijJ/lpeO2WReq8syM4lovXswzY+U8ucA2WPJbSlU7boggkdjEOKrVy/jN1EMab0A2WW3woTkjpNROI4GHmWjn0YzZewmSFHYeMEN5LTV7LrT3qew8j6ogUDhDJK7IL46b6g5dGONOatbQLckRAMuDgrTZeWnuzdydyKXfIRDr5i728lG1aOdnqVgsXeqTFJERUsCsjh2Wv0SLM9noPBFw7C+diEwBUigp1HunzBneLryxsbPIjLWq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OftjSpZ37+g2nCwH3D21W41JXa5zMWH/umkrAMA/UVR1Y9e2qsH7dQdGew/cR/Pqk3g2Gj20IHiBb+5RbzvjcfN+8y99IPWKqkMc66Buf5+wBMnyFFv7r60K8B0SvZLfQpOnQFKww/I10C3FIGaUH0klInVkQYcRbzRMScooTlIfi2yUvkRNN1oE2upr8GrXx78BMcA6252wO6mvCxVrRM/r1T9vg0TSBUj3NgU5IX8vC0ZvyYaQKj11nqsF62DWhhrSuH2fhKJsU9Guk/IjyMTcRLWGnmAQKukaOeitQaYtBM7v+Vn",
|
|
5
|
+
new Uint8Array(NUM_THEMES * 18)
|
|
6
|
+
);
|
|
7
|
+
export {
|
|
8
|
+
BINARY,
|
|
9
|
+
NUM_THEMES
|
|
10
|
+
};
|
package/filter.js
CHANGED
|
@@ -5,139 +5,52 @@ import { hue as $hue } from "@thi.ng/color/hue";
|
|
|
5
5
|
import { lch } from "@thi.ng/color/lch/lch";
|
|
6
6
|
import { luminance } from "@thi.ng/color/luminance";
|
|
7
7
|
import { srgb } from "@thi.ng/color/srgb/srgb";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @param pred
|
|
15
|
-
* @param threshold
|
|
16
|
-
*/
|
|
17
|
-
export const defFilter = (pred, threshold) => (theme) => {
|
|
18
|
-
const $thresh = threshold ?? theme.length;
|
|
19
|
-
for (let i = theme.length, n = 0; i-- > 0;) {
|
|
20
|
-
if (pred(theme[i])) {
|
|
21
|
-
if (++n >= $thresh)
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
8
|
+
const defFilter = (pred, threshold) => (theme) => {
|
|
9
|
+
const $thresh = threshold ?? theme.length;
|
|
10
|
+
for (let i = theme.length, n = 0; i-- > 0; ) {
|
|
11
|
+
if (pred(theme[i])) {
|
|
12
|
+
if (++n >= $thresh)
|
|
13
|
+
return true;
|
|
24
14
|
}
|
|
25
|
-
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
26
17
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* // pre-compose combined query filter
|
|
35
|
-
* const pastels = compFilter(
|
|
36
|
-
* // require all theme colors to have max 25% chroma
|
|
37
|
-
* chroma(0, 0.25),
|
|
38
|
-
* // require at least 3 theme colors to have min 50% luma
|
|
39
|
-
* luma(0.5, 1, 3)
|
|
40
|
-
* );
|
|
41
|
-
*
|
|
42
|
-
* [...cssThemes(pastels)]
|
|
43
|
-
* // [
|
|
44
|
-
* // [ '#453f38', '#746b5d', '#b39777', '#c1c2b2', '#e3dccf', '#f1ede7' ],
|
|
45
|
-
* // [ '#857b84', '#b1a7b0', '#d0c7d0', '#e7e0e8', '#faeceb', '#e4e9fa' ]
|
|
46
|
-
* // ]
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @param filters
|
|
50
|
-
= */
|
|
51
|
-
export const compFilter = (...filters) => filters.length > 1
|
|
52
|
-
? (theme) => filters.every((f) => f(theme))
|
|
53
|
-
: (theme) => filters[0](theme);
|
|
54
|
-
/**
|
|
55
|
-
* Theme predicate which ensures colors are within the given normalized hue
|
|
56
|
-
* range ([0..1] interval). See {@link defFilter} for more details.
|
|
57
|
-
*
|
|
58
|
-
* @remarks
|
|
59
|
-
* Since LCH uses different hue values than the more familiar HSV/HSL color
|
|
60
|
-
* wheel, LCH colors too will be first converted to HSV to ensure uniform
|
|
61
|
-
* results.
|
|
62
|
-
*
|
|
63
|
-
* If `max < min`, the filter will consider hues in both the `[min..1] and
|
|
64
|
-
* [0..max]` intervals (i.e. angular wraparound on color wheel).
|
|
65
|
-
*
|
|
66
|
-
* @param min
|
|
67
|
-
* @param max
|
|
68
|
-
* @param threshold
|
|
69
|
-
*/
|
|
70
|
-
export const hue = (min, max, threshold) => defFilter((col) => {
|
|
71
|
-
let h = $hue(isPrimitive(col) ? hsv(col) : col);
|
|
72
|
-
h = h - Math.floor(h);
|
|
73
|
-
return min <= max ? h >= min && h <= max : h >= min || h <= max;
|
|
18
|
+
const compFilter = (...filters) => filters.length > 1 ? (theme) => filters.every((f) => f(theme)) : (theme) => filters[0](theme);
|
|
19
|
+
const hue = (min, max, threshold) => defFilter((col) => {
|
|
20
|
+
let h = $hue(isPrimitive(col) ? hsv(col) : col);
|
|
21
|
+
h = h - Math.floor(h);
|
|
22
|
+
return min <= max ? h >= min && h <= max : h >= min || h <= max;
|
|
74
23
|
}, threshold);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*
|
|
79
|
-
* @remarks
|
|
80
|
-
* Internally converts colors to LCH (unless already the case).
|
|
81
|
-
*
|
|
82
|
-
* @param min
|
|
83
|
-
* @param max
|
|
84
|
-
* @param threshold
|
|
85
|
-
*/
|
|
86
|
-
export const chroma = (min, max, threshold) => defFilter((col) => {
|
|
87
|
-
const sat = __isLCH(col) ? col[1] : lch(col)[1];
|
|
88
|
-
return sat >= min && sat <= max;
|
|
24
|
+
const chroma = (min, max, threshold) => defFilter((col) => {
|
|
25
|
+
const sat = __isLCH(col) ? col[1] : lch(col)[1];
|
|
26
|
+
return sat >= min && sat <= max;
|
|
89
27
|
}, threshold);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
*
|
|
94
|
-
* @param min
|
|
95
|
-
* @param max
|
|
96
|
-
* @param threshold
|
|
97
|
-
*/
|
|
98
|
-
export const luma = (min, max, threshold) => defFilter((col) => {
|
|
99
|
-
const l = luminance(col);
|
|
100
|
-
return l >= min && l <= max;
|
|
28
|
+
const luma = (min, max, threshold) => defFilter((col) => {
|
|
29
|
+
const l = luminance(col);
|
|
30
|
+
return l >= min && l <= max;
|
|
101
31
|
}, threshold);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
*
|
|
109
|
-
* See {@link defFilter} &
|
|
110
|
-
* [`distLch()`](https://docs.thi.ng/umbrella/color/functions/distLch.html) for
|
|
111
|
-
* more details.
|
|
112
|
-
*
|
|
113
|
-
* @param min
|
|
114
|
-
* @param max
|
|
115
|
-
* @param threshold
|
|
116
|
-
*/
|
|
117
|
-
export const proximityLCH = (color, eps, threshold) => {
|
|
118
|
-
const $color = __isLCH(color) ? color : lch(color);
|
|
119
|
-
return defFilter((x) => distLch($color, __isLCH(x) ? x : lch(x)) < eps, threshold);
|
|
32
|
+
const proximityLCH = (color, eps, threshold) => {
|
|
33
|
+
const $color = __isLCH(color) ? color : lch(color);
|
|
34
|
+
return defFilter(
|
|
35
|
+
(x) => distLch($color, __isLCH(x) ? x : lch(x)) < eps,
|
|
36
|
+
threshold
|
|
37
|
+
);
|
|
120
38
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
*
|
|
128
|
-
* See {@link defFilter} &
|
|
129
|
-
* [`distEucledian3()`](https://docs.thi.ng/umbrella/color/functions/distEucledian3.html)
|
|
130
|
-
* for more details.
|
|
131
|
-
*
|
|
132
|
-
* @param min
|
|
133
|
-
* @param max
|
|
134
|
-
* @param threshold
|
|
135
|
-
*/
|
|
136
|
-
export const proximityRGB = (color, eps, threshold) => {
|
|
137
|
-
const $color = __isRGB(color) ? color : srgb(color);
|
|
138
|
-
return defFilter((x) => distEucledian3($color, __isRGB(x) ? x : srgb(x)) < eps, threshold);
|
|
39
|
+
const proximityRGB = (color, eps, threshold) => {
|
|
40
|
+
const $color = __isRGB(color) ? color : srgb(color);
|
|
41
|
+
return defFilter(
|
|
42
|
+
(x) => distEucledian3($color, __isRGB(x) ? x : srgb(x)) < eps,
|
|
43
|
+
threshold
|
|
44
|
+
);
|
|
139
45
|
};
|
|
140
|
-
/** @internal */
|
|
141
46
|
const __isLCH = (x) => !isPrimitive(x) && x.mode === "lch";
|
|
142
|
-
/** @internal */
|
|
143
47
|
const __isRGB = (x) => !isPrimitive(x) && x.mode === "srgb";
|
|
48
|
+
export {
|
|
49
|
+
chroma,
|
|
50
|
+
compFilter,
|
|
51
|
+
defFilter,
|
|
52
|
+
hue,
|
|
53
|
+
luma,
|
|
54
|
+
proximityLCH,
|
|
55
|
+
proximityRGB
|
|
56
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color-palettes",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.17",
|
|
4
4
|
"description": "Collection of 200+ image based color themes & composable theme query filters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,26 +24,29 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:binary": "tools:node-esm tools/encode.ts",
|
|
29
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
30
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
31
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
32
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
33
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
31
34
|
"doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
|
|
32
35
|
"pub": "yarn npm publish --access public",
|
|
33
36
|
"test": "bun test",
|
|
34
|
-
"build:binary": "tools:node-esm tools/encode.ts",
|
|
35
37
|
"tool:swatches": "tools:node-esm tools/swatches.ts"
|
|
36
38
|
},
|
|
37
39
|
"dependencies": {
|
|
38
|
-
"@thi.ng/api": "^8.9.
|
|
39
|
-
"@thi.ng/base-n": "^2.5.
|
|
40
|
-
"@thi.ng/checks": "^3.4.
|
|
41
|
-
"@thi.ng/color": "^5.6.
|
|
42
|
-
"@thi.ng/errors": "^2.4.
|
|
43
|
-
"@thi.ng/hex": "^2.3.
|
|
40
|
+
"@thi.ng/api": "^8.9.12",
|
|
41
|
+
"@thi.ng/base-n": "^2.5.20",
|
|
42
|
+
"@thi.ng/checks": "^3.4.12",
|
|
43
|
+
"@thi.ng/color": "^5.6.4",
|
|
44
|
+
"@thi.ng/errors": "^2.4.6",
|
|
45
|
+
"@thi.ng/hex": "^2.3.24"
|
|
44
46
|
},
|
|
45
47
|
"devDependencies": {
|
|
46
48
|
"@microsoft/api-extractor": "^7.38.3",
|
|
49
|
+
"esbuild": "^0.19.8",
|
|
47
50
|
"rimraf": "^5.0.5",
|
|
48
51
|
"tools": "^0.0.1",
|
|
49
52
|
"typedoc": "^0.25.4",
|
|
@@ -88,5 +91,5 @@
|
|
|
88
91
|
"parent": "@thi.ng/color",
|
|
89
92
|
"year": 2021
|
|
90
93
|
},
|
|
91
|
-
"gitHead": "
|
|
94
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
92
95
|
}
|
package/theme.js
CHANGED
|
@@ -4,116 +4,73 @@ import { assert } from "@thi.ng/errors/assert";
|
|
|
4
4
|
import { U24 } from "@thi.ng/hex";
|
|
5
5
|
import { BINARY, NUM_THEMES } from "./binary.js";
|
|
6
6
|
import { compFilter } from "./filter.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// (<any>theme).__id = id;
|
|
18
|
-
id *= 18;
|
|
19
|
-
for (let i = 0; i < 6; i++, id += 3) {
|
|
20
|
-
theme.push("#" +
|
|
21
|
-
U24((BINARY[id] << 16) | (BINARY[id + 1] << 8) | BINARY[id + 2]));
|
|
22
|
-
}
|
|
23
|
-
return reverse ? theme.reverse() : theme;
|
|
7
|
+
const asCSS = (id, reverse = false) => {
|
|
8
|
+
__ensureID(id);
|
|
9
|
+
const theme = [];
|
|
10
|
+
id *= 18;
|
|
11
|
+
for (let i = 0; i < 6; i++, id += 3) {
|
|
12
|
+
theme.push(
|
|
13
|
+
"#" + U24(BINARY[id] << 16 | BINARY[id + 1] << 8 | BINARY[id + 2])
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
return reverse ? theme.reverse() : theme;
|
|
24
17
|
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const theme = [];
|
|
36
|
-
id *= 18;
|
|
37
|
-
for (let i = 0; i < 6; i++, id += 3) {
|
|
38
|
-
theme.push((0xff000000 |
|
|
39
|
-
(BINARY[id] << 16) |
|
|
40
|
-
(BINARY[id + 1] << 8) |
|
|
41
|
-
BINARY[id + 2]) >>>
|
|
42
|
-
0);
|
|
43
|
-
}
|
|
44
|
-
return reverse ? theme.reverse() : theme;
|
|
18
|
+
const asInt = (id, reverse = false) => {
|
|
19
|
+
__ensureID(id);
|
|
20
|
+
const theme = [];
|
|
21
|
+
id *= 18;
|
|
22
|
+
for (let i = 0; i < 6; i++, id += 3) {
|
|
23
|
+
theme.push(
|
|
24
|
+
(4278190080 | BINARY[id] << 16 | BINARY[id + 1] << 8 | BINARY[id + 2]) >>> 0
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return reverse ? theme.reverse() : theme;
|
|
45
28
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
__ensureID(id);
|
|
63
|
-
const theme = [];
|
|
64
|
-
// (<any>theme).__id = id;
|
|
65
|
-
id *= 18;
|
|
66
|
-
for (let i = 0; i < 6; i++, id += 3) {
|
|
67
|
-
theme.push(srgb(BINARY[id] / 255, BINARY[id + 1] / 255, BINARY[id + 2] / 255, 1));
|
|
68
|
-
}
|
|
69
|
-
return reverse ? theme.reverse() : theme;
|
|
29
|
+
const asLCH = (id, reverse = false) => asRGB(id, reverse).map((x) => lch(x));
|
|
30
|
+
const asRGB = (id, reverse = false) => {
|
|
31
|
+
__ensureID(id);
|
|
32
|
+
const theme = [];
|
|
33
|
+
id *= 18;
|
|
34
|
+
for (let i = 0; i < 6; i++, id += 3) {
|
|
35
|
+
theme.push(
|
|
36
|
+
srgb(
|
|
37
|
+
BINARY[id] / 255,
|
|
38
|
+
BINARY[id + 1] / 255,
|
|
39
|
+
BINARY[id + 2] / 255,
|
|
40
|
+
1
|
|
41
|
+
)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return reverse ? theme.reverse() : theme;
|
|
70
45
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
* @param preds
|
|
76
|
-
*/
|
|
77
|
-
export const cssThemes = (...preds) => __themes(asCSS, preds);
|
|
78
|
-
/**
|
|
79
|
-
* Yields iterator of packed ARGB integer themes (via {@link asInt}). Yields all
|
|
80
|
-
* themes unless specific theme IDs or filter predicates are provided.
|
|
81
|
-
*
|
|
82
|
-
* @param preds
|
|
83
|
-
*/
|
|
84
|
-
export const intThemes = (...preds) => __themes(asInt, preds);
|
|
85
|
-
/**
|
|
86
|
-
* Yields iterator of LCH themes (via {@link asLCH}). Yields all
|
|
87
|
-
* themes unless specific theme IDs or filter predicates are provided.
|
|
88
|
-
*
|
|
89
|
-
* @param preds
|
|
90
|
-
*/
|
|
91
|
-
export const lchThemes = (...preds) => __themes(asLCH, preds);
|
|
92
|
-
/**
|
|
93
|
-
* Yields iterator of RGB themes (via {@link asRGB}). Yields all
|
|
94
|
-
* themes unless specific theme IDs or filter predicates are provided.
|
|
95
|
-
*
|
|
96
|
-
* @param preds
|
|
97
|
-
*/
|
|
98
|
-
export const rgbThemes = (...preds) => __themes(asRGB, preds);
|
|
99
|
-
/** @internal */
|
|
46
|
+
const cssThemes = (...preds) => __themes(asCSS, preds);
|
|
47
|
+
const intThemes = (...preds) => __themes(asInt, preds);
|
|
48
|
+
const lchThemes = (...preds) => __themes(asLCH, preds);
|
|
49
|
+
const rgbThemes = (...preds) => __themes(asRGB, preds);
|
|
100
50
|
function* __themes(fn, preds) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (preds.length) {
|
|
110
|
-
for (let id of preds)
|
|
111
|
-
yield fn(id);
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
for (let i = 0; i < NUM_THEMES; i++)
|
|
115
|
-
yield fn(i);
|
|
51
|
+
if (preds.length && typeof preds[0] === "function") {
|
|
52
|
+
const pred = compFilter(...preds);
|
|
53
|
+
for (let i = 0; i < NUM_THEMES; i++) {
|
|
54
|
+
const theme = fn(i);
|
|
55
|
+
if (pred(theme))
|
|
56
|
+
yield theme;
|
|
116
57
|
}
|
|
58
|
+
} else if (preds.length) {
|
|
59
|
+
for (let id of preds)
|
|
60
|
+
yield fn(id);
|
|
61
|
+
} else {
|
|
62
|
+
for (let i = 0; i < NUM_THEMES; i++)
|
|
63
|
+
yield fn(i);
|
|
64
|
+
}
|
|
117
65
|
}
|
|
118
|
-
/** @internal */
|
|
119
66
|
const __ensureID = (id) => assert(id >= 0 && id < NUM_THEMES, `invalid theme ID`);
|
|
67
|
+
export {
|
|
68
|
+
asCSS,
|
|
69
|
+
asInt,
|
|
70
|
+
asLCH,
|
|
71
|
+
asRGB,
|
|
72
|
+
cssThemes,
|
|
73
|
+
intThemes,
|
|
74
|
+
lchThemes,
|
|
75
|
+
rgbThemes
|
|
76
|
+
};
|