@thi.ng/color-palettes 1.0.6 → 1.0.8
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/package.json +13 -13
- package/query.d.ts +0 -106
- package/query.js +0 -135
- package/themes.d.ts +0 -3
- package/themes.js +0 -24
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/color-palettes",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Collection of 200+ image based color themes & composable theme query filters",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"build": "yarn clean && tsc --declaration",
|
|
28
|
-
"clean": "rimraf '*.js' '*.d.ts' '*.map' doc",
|
|
28
|
+
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
29
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
30
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
31
31
|
"doc:readme": "yarn doc:stats && tools:readme",
|
|
@@ -36,19 +36,19 @@
|
|
|
36
36
|
"tool:swatches": "tools:node-esm tools/swatches.ts"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.7.
|
|
40
|
-
"@thi.ng/base-n": "^2.4.
|
|
41
|
-
"@thi.ng/checks": "^3.3.
|
|
42
|
-
"@thi.ng/color": "^5.4.
|
|
43
|
-
"@thi.ng/errors": "^2.2.
|
|
44
|
-
"@thi.ng/hex": "^2.3.
|
|
39
|
+
"@thi.ng/api": "^8.7.4",
|
|
40
|
+
"@thi.ng/base-n": "^2.4.3",
|
|
41
|
+
"@thi.ng/checks": "^3.3.10",
|
|
42
|
+
"@thi.ng/color": "^5.4.4",
|
|
43
|
+
"@thi.ng/errors": "^2.2.13",
|
|
44
|
+
"@thi.ng/hex": "^2.3.7"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@microsoft/api-extractor": "^7.34.
|
|
48
|
-
"@thi.ng/testament": "^0.3.
|
|
49
|
-
"rimraf": "^4.
|
|
47
|
+
"@microsoft/api-extractor": "^7.34.4",
|
|
48
|
+
"@thi.ng/testament": "^0.3.13",
|
|
49
|
+
"rimraf": "^4.4.0",
|
|
50
50
|
"tools": "^0.0.1",
|
|
51
|
-
"typedoc": "^0.23.
|
|
51
|
+
"typedoc": "^0.23.26",
|
|
52
52
|
"typescript": "^4.9.5"
|
|
53
53
|
},
|
|
54
54
|
"keywords": [
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"parent": "@thi.ng/color",
|
|
91
91
|
"year": 2021
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "cc46c097a3a173fb1ef41f57a858d03037063141\n"
|
|
94
94
|
}
|
package/query.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ColorPredicate, ThemeColor, ThemePredicate } from "./api.js";
|
|
2
|
-
/**
|
|
3
|
-
* Higher order theme filter. Takes a predicate function which will be applied
|
|
4
|
-
* to a single {@link ThemeColor}. Returns a new function which accepts a single
|
|
5
|
-
* {@link Theme} and returns true iff the given predicate succeeds for at least
|
|
6
|
-
* `threshold` colors in the theme (all colors by default).
|
|
7
|
-
*
|
|
8
|
-
* @param pred
|
|
9
|
-
* @param threshold
|
|
10
|
-
*/
|
|
11
|
-
export declare const defFilter: (pred: ColorPredicate, threshold?: number) => ThemePredicate;
|
|
12
|
-
/**
|
|
13
|
-
* Higher order theme filter. Takes a number of theme predicate (e.g. those
|
|
14
|
-
* provided by this package) and returns new predicate function which only
|
|
15
|
-
* succeeds if *all* given predicates pass.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* // compose combined query filter
|
|
20
|
-
* const pastels = comp(
|
|
21
|
-
* // require all theme colors to max 25% chroma
|
|
22
|
-
* filterChroma(0, 0.25),
|
|
23
|
-
* // require at least 3 theme colors to be min 50% luma
|
|
24
|
-
* filterLuma(0.5, 1, 3)
|
|
25
|
-
* );
|
|
26
|
-
*
|
|
27
|
-
* [...cssThemes()].filter(pastels)
|
|
28
|
-
* // [
|
|
29
|
-
* // [ '#453f38', '#746b5d', '#b39777', '#c1c2b2', '#e3dccf', '#f1ede7' ],
|
|
30
|
-
* // [ '#857b84', '#b1a7b0', '#d0c7d0', '#e7e0e8', '#faeceb', '#e4e9fa' ]
|
|
31
|
-
* // ]
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* @param filters
|
|
35
|
-
= */
|
|
36
|
-
export declare const comp: (...filters: ThemePredicate[]) => ThemePredicate;
|
|
37
|
-
/**
|
|
38
|
-
* Theme predicate which ensures colors are within the given normalized hue
|
|
39
|
-
* range ([0..1] interval). See {@link defFilter} for more details.
|
|
40
|
-
*
|
|
41
|
-
* @remarks
|
|
42
|
-
* Internally converts colors to LCH (unless already the case). Therefore also
|
|
43
|
-
* uses LCH hues (which are slightly offset compared to HSV/HSL).
|
|
44
|
-
*
|
|
45
|
-
* If `max < min`, the filter will consider hues in both the `[min..1] and
|
|
46
|
-
* [0..max]` intervals (i.e. angular wraparound on color wheel).
|
|
47
|
-
*
|
|
48
|
-
* @param min
|
|
49
|
-
* @param max
|
|
50
|
-
* @param threshold
|
|
51
|
-
*/
|
|
52
|
-
export declare const filterHue: (min: number, max: number, threshold?: number) => ThemePredicate;
|
|
53
|
-
/**
|
|
54
|
-
* Theme predicate which ensures colors are within the given normalized chroma
|
|
55
|
-
* range ([0..1] interval). See {@link defFilter} for more details.
|
|
56
|
-
*
|
|
57
|
-
* @remarks
|
|
58
|
-
* Internally converts colors to LCH (unless already the case).
|
|
59
|
-
*
|
|
60
|
-
* @param min
|
|
61
|
-
* @param max
|
|
62
|
-
* @param threshold
|
|
63
|
-
*/
|
|
64
|
-
export declare const filterChroma: (min: number, max: number, threshold?: number) => ThemePredicate;
|
|
65
|
-
/**
|
|
66
|
-
* Theme predicate which ensures colors are within the given normalized
|
|
67
|
-
* luminance range ([0..1] interval). See {@link defFilter} for more details.
|
|
68
|
-
*
|
|
69
|
-
* @param min
|
|
70
|
-
* @param max
|
|
71
|
-
* @param threshold
|
|
72
|
-
*/
|
|
73
|
-
export declare const filterLuma: (min: number, max: number, threshold?: number) => ThemePredicate;
|
|
74
|
-
/**
|
|
75
|
-
* Theme predicate which ensures colors are within the given normalized distance
|
|
76
|
-
* in LCH space.
|
|
77
|
-
*
|
|
78
|
-
* @remarks
|
|
79
|
-
* Internally converts colors to LCH (unless already the case).
|
|
80
|
-
*
|
|
81
|
-
* See {@link defFilter} &
|
|
82
|
-
* [`distLch()`](https://docs.thi.ng/umbrella/color/functions/distLch.html) for
|
|
83
|
-
* more details.
|
|
84
|
-
*
|
|
85
|
-
* @param min
|
|
86
|
-
* @param max
|
|
87
|
-
* @param threshold
|
|
88
|
-
*/
|
|
89
|
-
export declare const filterProximityLCH: (color: ThemeColor, eps: number, threshold?: number) => ThemePredicate;
|
|
90
|
-
/**
|
|
91
|
-
* Theme predicate which ensures colors are within the given normalized distance
|
|
92
|
-
* in RGB space.
|
|
93
|
-
*
|
|
94
|
-
* @remarks
|
|
95
|
-
* Internally converts colors to sRGB (unless already the case).
|
|
96
|
-
*
|
|
97
|
-
* See {@link defFilter} &
|
|
98
|
-
* [`distEucledian3()`](https://docs.thi.ng/umbrella/color/functions/distEucledian3.html)
|
|
99
|
-
* for more details.
|
|
100
|
-
*
|
|
101
|
-
* @param min
|
|
102
|
-
* @param max
|
|
103
|
-
* @param threshold
|
|
104
|
-
*/
|
|
105
|
-
export declare const filterProximityRGB: (color: ThemeColor, eps: number, threshold?: number) => ThemePredicate;
|
|
106
|
-
//# sourceMappingURL=query.d.ts.map
|
package/query.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import { distEucledian3, distLch } from "@thi.ng/color/distance";
|
|
2
|
-
import { lch } from "@thi.ng/color/lch/lch";
|
|
3
|
-
import { luminance } from "@thi.ng/color/luminance";
|
|
4
|
-
import { srgb } from "@thi.ng/color/srgb/srgb";
|
|
5
|
-
/**
|
|
6
|
-
* Higher order theme filter. Takes a predicate function which will be applied
|
|
7
|
-
* to a single {@link ThemeColor}. Returns a new function which accepts a single
|
|
8
|
-
* {@link Theme} and returns true iff the given predicate succeeds for at least
|
|
9
|
-
* `threshold` colors in the theme (all colors by default).
|
|
10
|
-
*
|
|
11
|
-
* @param pred
|
|
12
|
-
* @param threshold
|
|
13
|
-
*/
|
|
14
|
-
export const defFilter = (pred, threshold) => (theme) => {
|
|
15
|
-
const $thresh = threshold ?? theme.length;
|
|
16
|
-
for (let i = theme.length, n = 0; i-- > 0;) {
|
|
17
|
-
if (pred(theme[i])) {
|
|
18
|
-
if (++n >= $thresh)
|
|
19
|
-
return true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Higher order theme filter. Takes a number of theme predicate (e.g. those
|
|
26
|
-
* provided by this package) and returns new predicate function which only
|
|
27
|
-
* succeeds if *all* given predicates pass.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```ts
|
|
31
|
-
* // compose combined query filter
|
|
32
|
-
* const pastels = comp(
|
|
33
|
-
* // require all theme colors to max 25% chroma
|
|
34
|
-
* filterChroma(0, 0.25),
|
|
35
|
-
* // require at least 3 theme colors to be min 50% luma
|
|
36
|
-
* filterLuma(0.5, 1, 3)
|
|
37
|
-
* );
|
|
38
|
-
*
|
|
39
|
-
* [...cssThemes()].filter(pastels)
|
|
40
|
-
* // [
|
|
41
|
-
* // [ '#453f38', '#746b5d', '#b39777', '#c1c2b2', '#e3dccf', '#f1ede7' ],
|
|
42
|
-
* // [ '#857b84', '#b1a7b0', '#d0c7d0', '#e7e0e8', '#faeceb', '#e4e9fa' ]
|
|
43
|
-
* // ]
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @param filters
|
|
47
|
-
= */
|
|
48
|
-
export const comp = (...filters) => (theme) => filters.every((f) => f(theme));
|
|
49
|
-
/**
|
|
50
|
-
* Theme predicate which ensures colors are within the given normalized hue
|
|
51
|
-
* range ([0..1] interval). See {@link defFilter} for more details.
|
|
52
|
-
*
|
|
53
|
-
* @remarks
|
|
54
|
-
* Internally converts colors to LCH (unless already the case). Therefore also
|
|
55
|
-
* uses LCH hues (which are slightly offset compared to HSV/HSL).
|
|
56
|
-
*
|
|
57
|
-
* If `max < min`, the filter will consider hues in both the `[min..1] and
|
|
58
|
-
* [0..max]` intervals (i.e. angular wraparound on color wheel).
|
|
59
|
-
*
|
|
60
|
-
* @param min
|
|
61
|
-
* @param max
|
|
62
|
-
* @param threshold
|
|
63
|
-
*/
|
|
64
|
-
export const filterHue = (min, max, threshold) => defFilter((col) => {
|
|
65
|
-
let hue = __isLCH(col) ? col[2] : lch(col)[2];
|
|
66
|
-
hue = hue - Math.floor(hue);
|
|
67
|
-
return min <= max ? hue >= min && hue <= max : hue >= min || hue <= max;
|
|
68
|
-
}, threshold);
|
|
69
|
-
/**
|
|
70
|
-
* Theme predicate which ensures colors are within the given normalized chroma
|
|
71
|
-
* range ([0..1] interval). See {@link defFilter} for more details.
|
|
72
|
-
*
|
|
73
|
-
* @remarks
|
|
74
|
-
* Internally converts colors to LCH (unless already the case).
|
|
75
|
-
*
|
|
76
|
-
* @param min
|
|
77
|
-
* @param max
|
|
78
|
-
* @param threshold
|
|
79
|
-
*/
|
|
80
|
-
export const filterChroma = (min, max, threshold) => defFilter((col) => {
|
|
81
|
-
const sat = __isLCH(col) ? col[1] : lch(col)[1];
|
|
82
|
-
return sat >= min && sat <= max;
|
|
83
|
-
}, threshold);
|
|
84
|
-
/**
|
|
85
|
-
* Theme predicate which ensures colors are within the given normalized
|
|
86
|
-
* luminance range ([0..1] interval). See {@link defFilter} for more details.
|
|
87
|
-
*
|
|
88
|
-
* @param min
|
|
89
|
-
* @param max
|
|
90
|
-
* @param threshold
|
|
91
|
-
*/
|
|
92
|
-
export const filterLuma = (min, max, threshold) => defFilter((col) => {
|
|
93
|
-
const l = luminance(col);
|
|
94
|
-
return l >= min && l <= max;
|
|
95
|
-
}, threshold);
|
|
96
|
-
/**
|
|
97
|
-
* Theme predicate which ensures colors are within the given normalized distance
|
|
98
|
-
* in LCH space.
|
|
99
|
-
*
|
|
100
|
-
* @remarks
|
|
101
|
-
* Internally converts colors to LCH (unless already the case).
|
|
102
|
-
*
|
|
103
|
-
* See {@link defFilter} &
|
|
104
|
-
* [`distLch()`](https://docs.thi.ng/umbrella/color/functions/distLch.html) for
|
|
105
|
-
* more details.
|
|
106
|
-
*
|
|
107
|
-
* @param min
|
|
108
|
-
* @param max
|
|
109
|
-
* @param threshold
|
|
110
|
-
*/
|
|
111
|
-
export const filterProximityLCH = (color, eps, threshold) => {
|
|
112
|
-
const $color = __isLCH(color) ? color : lch(color);
|
|
113
|
-
return defFilter((x) => distLch($color, __isLCH(x) ? x : lch(x)) < eps, threshold);
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Theme predicate which ensures colors are within the given normalized distance
|
|
117
|
-
* in RGB space.
|
|
118
|
-
*
|
|
119
|
-
* @remarks
|
|
120
|
-
* Internally converts colors to sRGB (unless already the case).
|
|
121
|
-
*
|
|
122
|
-
* See {@link defFilter} &
|
|
123
|
-
* [`distEucledian3()`](https://docs.thi.ng/umbrella/color/functions/distEucledian3.html)
|
|
124
|
-
* for more details.
|
|
125
|
-
*
|
|
126
|
-
* @param min
|
|
127
|
-
* @param max
|
|
128
|
-
* @param threshold
|
|
129
|
-
*/
|
|
130
|
-
export const filterProximityRGB = (color, eps, threshold) => {
|
|
131
|
-
const $color = __isRGB(color) ? color : srgb(color);
|
|
132
|
-
return defFilter((x) => distEucledian3($color, __isRGB(x) ? x : srgb(x)) < eps, threshold);
|
|
133
|
-
};
|
|
134
|
-
const __isLCH = (x) => typeof x !== "string" && x.mode === "lch";
|
|
135
|
-
const __isRGB = (x) => typeof x !== "string" && x.mode === "srgb";
|
package/themes.d.ts
DELETED
package/themes.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { U24 } from "@thi.ng/hex";
|
|
2
|
-
import { BINARY } from "./binary.js";
|
|
3
|
-
export const themeAsSRGB = (id) => {
|
|
4
|
-
const theme = [];
|
|
5
|
-
id *= 18;
|
|
6
|
-
for (let i = 0; i < 6; i++, id += 3) {
|
|
7
|
-
theme.push([
|
|
8
|
-
BINARY[id] / 255,
|
|
9
|
-
BINARY[id + 1] / 255,
|
|
10
|
-
BINARY[id + 2] / 255,
|
|
11
|
-
1,
|
|
12
|
-
]);
|
|
13
|
-
}
|
|
14
|
-
return theme;
|
|
15
|
-
};
|
|
16
|
-
export const themeAsCSS = (id) => {
|
|
17
|
-
const theme = [];
|
|
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 theme;
|
|
24
|
-
};
|