color-value-tools 1.2.1 → 1.2.2
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/README.md +18 -0
- package/dist/cjs/a11y.d.ts +40 -0
- package/dist/cjs/a11y.js +253 -0
- package/dist/cjs/cache.d.ts +9 -0
- package/dist/cjs/cache.js +38 -0
- package/dist/cjs/convert/format.d.ts +3 -0
- package/dist/cjs/convert/format.js +42 -0
- package/dist/cjs/convert/index.d.ts +2 -0
- package/dist/cjs/convert/index.js +18 -0
- package/dist/cjs/convert/spaces.d.ts +189 -0
- package/dist/cjs/convert/spaces.js +556 -0
- package/dist/cjs/index.d.ts +6 -397
- package/dist/cjs/index.js +20 -1466
- package/dist/cjs/internal/named-colors.d.ts +1 -0
- package/dist/cjs/internal/named-colors.js +165 -0
- package/dist/cjs/internal/transfer.d.ts +2 -0
- package/dist/cjs/internal/transfer.js +12 -0
- package/dist/cjs/manipulate.d.ts +15 -0
- package/dist/cjs/manipulate.js +223 -0
- package/dist/cjs/palette.d.ts +40 -0
- package/dist/cjs/palette.js +164 -0
- package/dist/cjs/parse.d.ts +102 -0
- package/dist/cjs/parse.js +257 -0
- package/dist/cli/{bin/cli.js → cli.js} +28 -26
- package/dist/esm/a11y.d.ts +40 -0
- package/dist/esm/a11y.js +237 -0
- package/dist/esm/cache.d.ts +9 -0
- package/dist/esm/cache.js +31 -0
- package/dist/esm/convert/format.d.ts +3 -0
- package/dist/esm/convert/format.js +37 -0
- package/dist/esm/convert/index.d.ts +2 -0
- package/dist/esm/convert/index.js +2 -0
- package/dist/esm/convert/spaces.d.ts +189 -0
- package/dist/esm/convert/spaces.js +520 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +6 -1368
- package/dist/esm/internal/named-colors.d.ts +1 -0
- package/dist/esm/internal/named-colors.js +162 -0
- package/dist/esm/internal/transfer.d.ts +2 -0
- package/dist/esm/internal/transfer.js +8 -0
- package/dist/esm/manipulate.d.ts +15 -0
- package/dist/esm/manipulate.js +210 -0
- package/dist/esm/package.json +3 -1
- package/dist/esm/palette.d.ts +40 -0
- package/dist/esm/palette.js +145 -0
- package/dist/esm/parse.d.ts +102 -0
- package/dist/esm/parse.js +241 -0
- package/package.json +100 -8
- package/dist/cli/src/index.js +0 -1468
package/dist/esm/a11y.js
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
// Luminance, WCAG contrast, perceptual difference and color-blindness simulation.
|
|
2
|
+
import { normalizeColor } from './parse.js';
|
|
3
|
+
import { rgbToHex, rgbToLab } from './convert/spaces.js';
|
|
4
|
+
export function relativeLuminance(color) {
|
|
5
|
+
var _a, _b, _c;
|
|
6
|
+
const n = normalizeColor(color);
|
|
7
|
+
const r = ((_a = n.r) !== null && _a !== void 0 ? _a : 0) / 255;
|
|
8
|
+
const g = ((_b = n.g) !== null && _b !== void 0 ? _b : 0) / 255;
|
|
9
|
+
const b = ((_c = n.b) !== null && _c !== void 0 ? _c : 0) / 255;
|
|
10
|
+
const srgbToLin = (c) => (c <= 0.03928 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4));
|
|
11
|
+
const R = srgbToLin(r), G = srgbToLin(g), B = srgbToLin(b);
|
|
12
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
13
|
+
}
|
|
14
|
+
export function contrastRatio(a, b) {
|
|
15
|
+
const L1 = relativeLuminance(a);
|
|
16
|
+
const L2 = relativeLuminance(b);
|
|
17
|
+
const light = Math.max(L1, L2);
|
|
18
|
+
const dark = Math.min(L1, L2);
|
|
19
|
+
return +((light + 0.05) / (dark + 0.05)).toFixed(2);
|
|
20
|
+
}
|
|
21
|
+
export function isDark(color, threshold = 0.5) {
|
|
22
|
+
return relativeLuminance(color) < threshold;
|
|
23
|
+
}
|
|
24
|
+
export function isLight(color, threshold = 0.5) {
|
|
25
|
+
return !isDark(color, threshold);
|
|
26
|
+
}
|
|
27
|
+
export function wcagLevel(foreground, background) {
|
|
28
|
+
const ratio = contrastRatio(foreground, background);
|
|
29
|
+
if (ratio >= 7)
|
|
30
|
+
return 'AAA';
|
|
31
|
+
if (ratio >= 4.5)
|
|
32
|
+
return 'AA';
|
|
33
|
+
if (ratio >= 3)
|
|
34
|
+
return 'AA-large';
|
|
35
|
+
return 'fail';
|
|
36
|
+
}
|
|
37
|
+
export function bestTextColor(background) {
|
|
38
|
+
const onBlack = contrastRatio(background, '#000000');
|
|
39
|
+
const onWhite = contrastRatio(background, '#ffffff');
|
|
40
|
+
return onBlack >= onWhite ? '#000000' : '#ffffff';
|
|
41
|
+
}
|
|
42
|
+
export function bestContrastColor(background, candidates) {
|
|
43
|
+
let best = candidates[0];
|
|
44
|
+
let bestRatio = -1;
|
|
45
|
+
for (const c of candidates) {
|
|
46
|
+
const ratio = contrastRatio(background, c);
|
|
47
|
+
if (ratio > bestRatio) {
|
|
48
|
+
bestRatio = ratio;
|
|
49
|
+
best = c;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return best;
|
|
53
|
+
}
|
|
54
|
+
export function colorDeltaE(c1, c2) {
|
|
55
|
+
var _a, _b, _c, _d, _e, _f;
|
|
56
|
+
const n1 = normalizeColor(c1);
|
|
57
|
+
const n2 = normalizeColor(c2);
|
|
58
|
+
const lab1 = rgbToLab({ r: (_a = n1.r) !== null && _a !== void 0 ? _a : 0, g: (_b = n1.g) !== null && _b !== void 0 ? _b : 0, b: (_c = n1.b) !== null && _c !== void 0 ? _c : 0 });
|
|
59
|
+
const lab2 = rgbToLab({ r: (_d = n2.r) !== null && _d !== void 0 ? _d : 0, g: (_e = n2.g) !== null && _e !== void 0 ? _e : 0, b: (_f = n2.b) !== null && _f !== void 0 ? _f : 0 });
|
|
60
|
+
// CIEDE2000
|
|
61
|
+
const deg = (rad) => rad * (180 / Math.PI);
|
|
62
|
+
const rad = (d) => d * (Math.PI / 180);
|
|
63
|
+
const { L: L1, a: a1, b: b1 } = lab1;
|
|
64
|
+
const { L: L2, a: a2, b: b2 } = lab2;
|
|
65
|
+
const dL = L2 - L1;
|
|
66
|
+
const Lm = (L1 + L2) / 2;
|
|
67
|
+
const C1 = Math.sqrt(a1 * a1 + b1 * b1);
|
|
68
|
+
const C2 = Math.sqrt(a2 * a2 + b2 * b2);
|
|
69
|
+
const Cm = (C1 + C2) / 2;
|
|
70
|
+
const Cm7 = Math.pow(Cm, 7);
|
|
71
|
+
const G = 0.5 * (1 - Math.sqrt(Cm7 / (Cm7 + Math.pow(25, 7))));
|
|
72
|
+
const a1p = a1 * (1 + G), a2p = a2 * (1 + G);
|
|
73
|
+
const C1p = Math.sqrt(a1p * a1p + b1 * b1);
|
|
74
|
+
const C2p = Math.sqrt(a2p * a2p + b2 * b2);
|
|
75
|
+
const dCp = C2p - C1p;
|
|
76
|
+
const Cmp = (C1p + C2p) / 2;
|
|
77
|
+
let h1p = deg(Math.atan2(b1, a1p));
|
|
78
|
+
if (h1p < 0)
|
|
79
|
+
h1p += 360;
|
|
80
|
+
let h2p = deg(Math.atan2(b2, a2p));
|
|
81
|
+
if (h2p < 0)
|
|
82
|
+
h2p += 360;
|
|
83
|
+
let dhp;
|
|
84
|
+
if (Math.abs(h1p - h2p) <= 180)
|
|
85
|
+
dhp = h2p - h1p;
|
|
86
|
+
else if (h2p <= h1p)
|
|
87
|
+
dhp = h2p - h1p + 360;
|
|
88
|
+
else
|
|
89
|
+
dhp = h2p - h1p - 360;
|
|
90
|
+
const dHp = 2 * Math.sqrt(C1p * C2p) * Math.sin(rad(dhp / 2));
|
|
91
|
+
let Hmp;
|
|
92
|
+
if (Math.abs(h1p - h2p) <= 180)
|
|
93
|
+
Hmp = (h1p + h2p) / 2;
|
|
94
|
+
else if (h1p + h2p < 360)
|
|
95
|
+
Hmp = (h1p + h2p + 360) / 2;
|
|
96
|
+
else
|
|
97
|
+
Hmp = (h1p + h2p - 360) / 2;
|
|
98
|
+
const T = 1 -
|
|
99
|
+
0.17 * Math.cos(rad(Hmp - 30)) +
|
|
100
|
+
0.24 * Math.cos(rad(2 * Hmp)) +
|
|
101
|
+
0.32 * Math.cos(rad(3 * Hmp + 6)) -
|
|
102
|
+
0.2 * Math.cos(rad(4 * Hmp - 63));
|
|
103
|
+
const SL = 1 + (0.015 * Math.pow(Lm - 50, 2)) / Math.sqrt(20 + Math.pow(Lm - 50, 2));
|
|
104
|
+
const SC = 1 + 0.045 * Cmp;
|
|
105
|
+
const SH = 1 + 0.015 * Cmp * T;
|
|
106
|
+
const Cmp7 = Math.pow(Cmp, 7);
|
|
107
|
+
const RC = 2 * Math.sqrt(Cmp7 / (Cmp7 + Math.pow(25, 7)));
|
|
108
|
+
const dTheta = 30 * Math.exp(-Math.pow((Hmp - 275) / 25, 2));
|
|
109
|
+
const RT = -Math.sin(rad(2 * dTheta)) * RC;
|
|
110
|
+
return +Math.sqrt(Math.pow(dL / SL, 2) +
|
|
111
|
+
Math.pow(dCp / SC, 2) +
|
|
112
|
+
Math.pow(dHp / SH, 2) +
|
|
113
|
+
RT * (dCp / SC) * (dHp / SH)).toFixed(4);
|
|
114
|
+
}
|
|
115
|
+
// ─── Color blindness simulation ────────────────────────────────────
|
|
116
|
+
function _simulateCB(color, matrix) {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
const n = normalizeColor(color);
|
|
119
|
+
// linearize
|
|
120
|
+
const lin = (v) => {
|
|
121
|
+
const c = v / 255;
|
|
122
|
+
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
123
|
+
};
|
|
124
|
+
const enc = (v) => {
|
|
125
|
+
const c = v <= 0.0031308 ? 12.92 * v : 1.055 * Math.pow(v, 1 / 2.4) - 0.055;
|
|
126
|
+
return Math.round(Math.max(0, Math.min(1, c)) * 255);
|
|
127
|
+
};
|
|
128
|
+
const r = lin((_a = n.r) !== null && _a !== void 0 ? _a : 0), g = lin((_b = n.g) !== null && _b !== void 0 ? _b : 0), b = lin((_c = n.b) !== null && _c !== void 0 ? _c : 0);
|
|
129
|
+
const nr = enc(matrix[0][0] * r + matrix[0][1] * g + matrix[0][2] * b);
|
|
130
|
+
const ng = enc(matrix[1][0] * r + matrix[1][1] * g + matrix[1][2] * b);
|
|
131
|
+
const nb = enc(matrix[2][0] * r + matrix[2][1] * g + matrix[2][2] * b);
|
|
132
|
+
return rgbToHex({ r: nr, g: ng, b: nb });
|
|
133
|
+
}
|
|
134
|
+
const _PROTANOPIA_M = [
|
|
135
|
+
[0.56667, 0.43333, 0.0],
|
|
136
|
+
[0.55833, 0.44167, 0.0],
|
|
137
|
+
[0.0, 0.24167, 0.75833],
|
|
138
|
+
];
|
|
139
|
+
const _DEUTERANOPIA_M = [
|
|
140
|
+
[0.625, 0.375, 0.0],
|
|
141
|
+
[0.7, 0.3, 0.0],
|
|
142
|
+
[0.0, 0.3, 0.7],
|
|
143
|
+
];
|
|
144
|
+
const _TRITANOPIA_M = [
|
|
145
|
+
[0.95, 0.05, 0.0],
|
|
146
|
+
[0.0, 0.43333, 0.56667],
|
|
147
|
+
[0.0, 0.475, 0.525],
|
|
148
|
+
];
|
|
149
|
+
export function simulateProtanopia(color) {
|
|
150
|
+
return _simulateCB(color, _PROTANOPIA_M);
|
|
151
|
+
}
|
|
152
|
+
export function simulateDeuteranopia(color) {
|
|
153
|
+
return _simulateCB(color, _DEUTERANOPIA_M);
|
|
154
|
+
}
|
|
155
|
+
export function simulateTritanopia(color) {
|
|
156
|
+
return _simulateCB(color, _TRITANOPIA_M);
|
|
157
|
+
}
|
|
158
|
+
export function simulateColorBlindness(color, type) {
|
|
159
|
+
if (type === 'protanopia')
|
|
160
|
+
return simulateProtanopia(color);
|
|
161
|
+
if (type === 'deuteranopia')
|
|
162
|
+
return simulateDeuteranopia(color);
|
|
163
|
+
return simulateTritanopia(color);
|
|
164
|
+
}
|
|
165
|
+
export function isReadableOnBackground(textColor, background, options) {
|
|
166
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
167
|
+
const level = (_a = options === null || options === void 0 ? void 0 : options.level) !== null && _a !== void 0 ? _a : 'AA';
|
|
168
|
+
const large = (_b = options === null || options === void 0 ? void 0 : options.largeText) !== null && _b !== void 0 ? _b : false;
|
|
169
|
+
const minRequired = level === 'AAA' ? (large ? 4.5 : 7) : large ? 3 : 4.5;
|
|
170
|
+
// The specific effective background color that minRatio was actually
|
|
171
|
+
// computed against — wcagLevel below is derived from this same color
|
|
172
|
+
// (never a hardcoded '#ffffff') so it can't disagree with minRatio/readable.
|
|
173
|
+
let minRatio;
|
|
174
|
+
let effectiveBackground;
|
|
175
|
+
if (typeof background === 'string') {
|
|
176
|
+
effectiveBackground = background;
|
|
177
|
+
minRatio = contrastRatio(textColor, background);
|
|
178
|
+
}
|
|
179
|
+
else if (background.type === 'semi-transparent') {
|
|
180
|
+
const underlay = (_c = background.underlay) !== null && _c !== void 0 ? _c : '#ffffff';
|
|
181
|
+
const fg = normalizeColor(background.color);
|
|
182
|
+
const bg = normalizeColor(underlay);
|
|
183
|
+
const alpha = (_d = fg.a) !== null && _d !== void 0 ? _d : 1;
|
|
184
|
+
const cr = Math.round(((_e = fg.r) !== null && _e !== void 0 ? _e : 0) * alpha + ((_f = bg.r) !== null && _f !== void 0 ? _f : 255) * (1 - alpha));
|
|
185
|
+
const cg = Math.round(((_g = fg.g) !== null && _g !== void 0 ? _g : 0) * alpha + ((_h = bg.g) !== null && _h !== void 0 ? _h : 255) * (1 - alpha));
|
|
186
|
+
const cb = Math.round(((_j = fg.b) !== null && _j !== void 0 ? _j : 0) * alpha + ((_k = bg.b) !== null && _k !== void 0 ? _k : 255) * (1 - alpha));
|
|
187
|
+
effectiveBackground = rgbToHex({ r: cr, g: cg, b: cb });
|
|
188
|
+
minRatio = contrastRatio(textColor, effectiveBackground);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// The worst-case stop (lowest ratio) drives both minRatio and wcagLevel.
|
|
192
|
+
let worstStop = background.stops[0];
|
|
193
|
+
let worstRatio = Infinity;
|
|
194
|
+
for (const stop of background.stops) {
|
|
195
|
+
const ratio = contrastRatio(textColor, stop);
|
|
196
|
+
if (ratio < worstRatio) {
|
|
197
|
+
worstRatio = ratio;
|
|
198
|
+
worstStop = stop;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
effectiveBackground = worstStop;
|
|
202
|
+
minRatio = worstRatio;
|
|
203
|
+
}
|
|
204
|
+
const wLevel = wcagLevel(textColor, effectiveBackground);
|
|
205
|
+
return {
|
|
206
|
+
readable: minRatio >= minRequired,
|
|
207
|
+
minContrastRatio: +minRatio.toFixed(2),
|
|
208
|
+
wcagLevel: wLevel,
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export function bestContrastPalette(background, palettes, options) {
|
|
212
|
+
let bestIdx = 0;
|
|
213
|
+
let bestScore = -1;
|
|
214
|
+
let bestMin = 0, bestAvg = 0;
|
|
215
|
+
palettes.forEach((palette, idx) => {
|
|
216
|
+
var _a;
|
|
217
|
+
const ratios = palette.map((c) => contrastRatio(background, c));
|
|
218
|
+
const weights = (_a = options === null || options === void 0 ? void 0 : options.weights) !== null && _a !== void 0 ? _a : ratios.map(() => 1);
|
|
219
|
+
const totalW = weights.reduce((s, w) => s + w, 0);
|
|
220
|
+
const avg = ratios.reduce((s, r, i) => { var _a; return s + r * ((_a = weights[i]) !== null && _a !== void 0 ? _a : 1); }, 0) / totalW;
|
|
221
|
+
const min = Math.min(...ratios);
|
|
222
|
+
// Score: weighted avg with heavy penalty on minimum
|
|
223
|
+
const score = avg * 0.4 + min * 0.6;
|
|
224
|
+
if (score > bestScore) {
|
|
225
|
+
bestScore = score;
|
|
226
|
+
bestIdx = idx;
|
|
227
|
+
bestMin = min;
|
|
228
|
+
bestAvg = avg;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return {
|
|
232
|
+
paletteIndex: bestIdx,
|
|
233
|
+
palette: palettes[bestIdx],
|
|
234
|
+
minContrastRatio: +bestMin.toFixed(2),
|
|
235
|
+
avgContrastRatio: +bestAvg.toFixed(2),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { normalizeColor } from './parse.js';
|
|
2
|
+
export declare function clearColorCache(): void;
|
|
3
|
+
export declare function getCacheStats(): {
|
|
4
|
+
size: number;
|
|
5
|
+
hits: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function enableCache(): void;
|
|
8
|
+
export declare function disableCache(): void;
|
|
9
|
+
export declare function normalizeColorCached(input: string): ReturnType<typeof normalizeColor>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Memoized normalizeColor() for performance-sensitive code.
|
|
2
|
+
import { normalizeColor } from './parse.js';
|
|
3
|
+
let _cacheEnabled = true;
|
|
4
|
+
const _normalizeCache = new Map();
|
|
5
|
+
let _cacheHits = 0;
|
|
6
|
+
export function clearColorCache() {
|
|
7
|
+
_normalizeCache.clear();
|
|
8
|
+
_cacheHits = 0;
|
|
9
|
+
}
|
|
10
|
+
export function getCacheStats() {
|
|
11
|
+
return { size: _normalizeCache.size, hits: _cacheHits };
|
|
12
|
+
}
|
|
13
|
+
export function enableCache() {
|
|
14
|
+
_cacheEnabled = true;
|
|
15
|
+
}
|
|
16
|
+
export function disableCache() {
|
|
17
|
+
_cacheEnabled = false;
|
|
18
|
+
}
|
|
19
|
+
// Cached normalizer wrapper — use this in performance-sensitive contexts
|
|
20
|
+
export function normalizeColorCached(input) {
|
|
21
|
+
if (!_cacheEnabled)
|
|
22
|
+
return normalizeColor(input);
|
|
23
|
+
const cached = _normalizeCache.get(input);
|
|
24
|
+
if (cached) {
|
|
25
|
+
_cacheHits++;
|
|
26
|
+
return cached;
|
|
27
|
+
}
|
|
28
|
+
const result = normalizeColor(input);
|
|
29
|
+
_normalizeCache.set(input, result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Formatters that accept any supported CSS color string.
|
|
2
|
+
import { normalizeColor } from '../parse.js';
|
|
3
|
+
import { rgbToDisplayP3, rgbToHex, rgbToOklch } from './spaces.js';
|
|
4
|
+
export function toDisplayP3Hex(color) {
|
|
5
|
+
const n = normalizeColorRaw(color);
|
|
6
|
+
const p3 = rgbToDisplayP3({ r: n.r, g: n.g, b: n.b });
|
|
7
|
+
return rgbToHex({
|
|
8
|
+
r: Math.round(Math.max(0, Math.min(255, p3.r * 255))),
|
|
9
|
+
g: Math.round(Math.max(0, Math.min(255, p3.g * 255))),
|
|
10
|
+
b: Math.round(Math.max(0, Math.min(255, p3.b * 255))),
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
// Internal raw normalizer (no cache, no circular dep issues)
|
|
14
|
+
function normalizeColorRaw(color) {
|
|
15
|
+
var _a, _b, _c, _d;
|
|
16
|
+
const n = normalizeColor(color);
|
|
17
|
+
return { r: (_a = n.r) !== null && _a !== void 0 ? _a : 0, g: (_b = n.g) !== null && _b !== void 0 ? _b : 0, b: (_c = n.b) !== null && _c !== void 0 ? _c : 0, a: (_d = n.a) !== null && _d !== void 0 ? _d : 1 };
|
|
18
|
+
}
|
|
19
|
+
// ─── Formatting ───────────────────────────────────────────────────────────────
|
|
20
|
+
export function toOklchString(color, alpha) {
|
|
21
|
+
var _a, _b, _c;
|
|
22
|
+
const n = normalizeColor(color);
|
|
23
|
+
const { L, C, H } = rgbToOklch({ r: (_a = n.r) !== null && _a !== void 0 ? _a : 0, g: (_b = n.g) !== null && _b !== void 0 ? _b : 0, b: (_c = n.b) !== null && _c !== void 0 ? _c : 0 });
|
|
24
|
+
const Lr = +L.toFixed(4), Cr = +C.toFixed(4), Hr = +H.toFixed(2);
|
|
25
|
+
if (alpha !== undefined)
|
|
26
|
+
return `oklch(${Lr} ${Cr} ${Hr} / ${+alpha.toFixed(3)})`;
|
|
27
|
+
return `oklch(${Lr} ${Cr} ${Hr})`;
|
|
28
|
+
}
|
|
29
|
+
export function toColorP3String(color, alpha) {
|
|
30
|
+
var _a, _b, _c;
|
|
31
|
+
const n = normalizeColor(color);
|
|
32
|
+
const p3 = rgbToDisplayP3({ r: (_a = n.r) !== null && _a !== void 0 ? _a : 0, g: (_b = n.g) !== null && _b !== void 0 ? _b : 0, b: (_c = n.b) !== null && _c !== void 0 ? _c : 0 });
|
|
33
|
+
const r = +p3.r.toFixed(4), g = +p3.g.toFixed(4), b = +p3.b.toFixed(4);
|
|
34
|
+
if (alpha !== undefined)
|
|
35
|
+
return `color(display-p3 ${r} ${g} ${b} / ${+alpha.toFixed(3)})`;
|
|
36
|
+
return `color(display-p3 ${r} ${g} ${b})`;
|
|
37
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
export declare function rgbToDisplayP3(rgb: {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
}): {
|
|
6
|
+
r: number;
|
|
7
|
+
g: number;
|
|
8
|
+
b: number;
|
|
9
|
+
};
|
|
10
|
+
export declare function displayP3ToRgb(p3: {
|
|
11
|
+
r: number;
|
|
12
|
+
g: number;
|
|
13
|
+
b: number;
|
|
14
|
+
}): {
|
|
15
|
+
r: number;
|
|
16
|
+
g: number;
|
|
17
|
+
b: number;
|
|
18
|
+
};
|
|
19
|
+
export declare function shortHexToRgba(hex: string): {
|
|
20
|
+
r: number;
|
|
21
|
+
g: number;
|
|
22
|
+
b: number;
|
|
23
|
+
a: number;
|
|
24
|
+
} | null;
|
|
25
|
+
export declare function normalizeHex(hex: string): string;
|
|
26
|
+
export declare function hexToRgb(hex: string): [number, number, number];
|
|
27
|
+
export declare function hexToRgba(hex: string, opacity?: number): string;
|
|
28
|
+
export declare function hexToHsl(hex: string): [number, number, number];
|
|
29
|
+
export declare function hslToHex(h: number, s: number, l: number): string;
|
|
30
|
+
export declare function rgbToHex({ r, g, b }: {
|
|
31
|
+
r: number;
|
|
32
|
+
g: number;
|
|
33
|
+
b: number;
|
|
34
|
+
}): string;
|
|
35
|
+
export declare function rgbaToHex({ r, g, b, a }: {
|
|
36
|
+
r: number;
|
|
37
|
+
g: number;
|
|
38
|
+
b: number;
|
|
39
|
+
a: number;
|
|
40
|
+
}): string;
|
|
41
|
+
export declare function rgbToRgbaString({ r, g, b }: {
|
|
42
|
+
r: number;
|
|
43
|
+
g: number;
|
|
44
|
+
b: number;
|
|
45
|
+
}, a: number): string;
|
|
46
|
+
export declare function rgbaStringToRgba(str: string): {
|
|
47
|
+
r: number;
|
|
48
|
+
g: number;
|
|
49
|
+
b: number;
|
|
50
|
+
a: number;
|
|
51
|
+
} | null;
|
|
52
|
+
export declare function rgbToHsl({ r, g, b, }: {
|
|
53
|
+
r: number;
|
|
54
|
+
g: number;
|
|
55
|
+
b: number;
|
|
56
|
+
}): [number, number, number];
|
|
57
|
+
export declare function hslToRgb(h: number, s: number, l: number): {
|
|
58
|
+
r: number;
|
|
59
|
+
g: number;
|
|
60
|
+
b: number;
|
|
61
|
+
};
|
|
62
|
+
export declare function rgbToHsv({ r, g, b, }: {
|
|
63
|
+
r: number;
|
|
64
|
+
g: number;
|
|
65
|
+
b: number;
|
|
66
|
+
}): [number, number, number];
|
|
67
|
+
export declare function hsvToRgb(h: number, s: number, v: number): {
|
|
68
|
+
r: number;
|
|
69
|
+
g: number;
|
|
70
|
+
b: number;
|
|
71
|
+
};
|
|
72
|
+
export declare function hexToHsv(hex: string): [number, number, number];
|
|
73
|
+
export declare function hsvToHex(h: number, s: number, v: number): string;
|
|
74
|
+
export declare function hex8ToRgba(hex: string): {
|
|
75
|
+
r: number;
|
|
76
|
+
g: number;
|
|
77
|
+
b: number;
|
|
78
|
+
a: number;
|
|
79
|
+
} | null;
|
|
80
|
+
export declare function rgbaToHex8({ r, g, b, a }: {
|
|
81
|
+
r: number;
|
|
82
|
+
g: number;
|
|
83
|
+
b: number;
|
|
84
|
+
a: number;
|
|
85
|
+
}): string;
|
|
86
|
+
export declare function rgbToCmyk({ r, g, b }: {
|
|
87
|
+
r: number;
|
|
88
|
+
g: number;
|
|
89
|
+
b: number;
|
|
90
|
+
}): {
|
|
91
|
+
c: number;
|
|
92
|
+
m: number;
|
|
93
|
+
y: number;
|
|
94
|
+
k: number;
|
|
95
|
+
};
|
|
96
|
+
export declare function cmykToRgb({ c, m, y, k }: {
|
|
97
|
+
c: number;
|
|
98
|
+
m: number;
|
|
99
|
+
y: number;
|
|
100
|
+
k: number;
|
|
101
|
+
}): {
|
|
102
|
+
r: number;
|
|
103
|
+
g: number;
|
|
104
|
+
b: number;
|
|
105
|
+
};
|
|
106
|
+
export declare function rgbToLab({ r, g, b }: {
|
|
107
|
+
r: number;
|
|
108
|
+
g: number;
|
|
109
|
+
b: number;
|
|
110
|
+
}): {
|
|
111
|
+
L: number;
|
|
112
|
+
a: number;
|
|
113
|
+
b: number;
|
|
114
|
+
};
|
|
115
|
+
export declare function labToRgb({ L, a, b }: {
|
|
116
|
+
L: number;
|
|
117
|
+
a: number;
|
|
118
|
+
b: number;
|
|
119
|
+
}): {
|
|
120
|
+
r: number;
|
|
121
|
+
g: number;
|
|
122
|
+
b: number;
|
|
123
|
+
};
|
|
124
|
+
export declare function rgbToLch({ r, g, b }: {
|
|
125
|
+
r: number;
|
|
126
|
+
g: number;
|
|
127
|
+
b: number;
|
|
128
|
+
}): {
|
|
129
|
+
L: number;
|
|
130
|
+
C: number;
|
|
131
|
+
H: number;
|
|
132
|
+
};
|
|
133
|
+
export declare function lchToRgb({ L, C, H }: {
|
|
134
|
+
L: number;
|
|
135
|
+
C: number;
|
|
136
|
+
H: number;
|
|
137
|
+
}): {
|
|
138
|
+
r: number;
|
|
139
|
+
g: number;
|
|
140
|
+
b: number;
|
|
141
|
+
};
|
|
142
|
+
export declare function rgbToHwb({ r, g, b, }: {
|
|
143
|
+
r: number;
|
|
144
|
+
g: number;
|
|
145
|
+
b: number;
|
|
146
|
+
}): [number, number, number];
|
|
147
|
+
export declare function hwbToRgb(H: number, W: number, B: number): {
|
|
148
|
+
r: number;
|
|
149
|
+
g: number;
|
|
150
|
+
b: number;
|
|
151
|
+
};
|
|
152
|
+
export declare function toHwbString(H: number, W: number, B: number, alpha?: number): string;
|
|
153
|
+
export declare function rgbToOklab({ r, g, b }: {
|
|
154
|
+
r: number;
|
|
155
|
+
g: number;
|
|
156
|
+
b: number;
|
|
157
|
+
}): {
|
|
158
|
+
L: number;
|
|
159
|
+
a: number;
|
|
160
|
+
b: number;
|
|
161
|
+
};
|
|
162
|
+
export declare function oklabToRgb({ L, a, b }: {
|
|
163
|
+
L: number;
|
|
164
|
+
a: number;
|
|
165
|
+
b: number;
|
|
166
|
+
}): {
|
|
167
|
+
r: number;
|
|
168
|
+
g: number;
|
|
169
|
+
b: number;
|
|
170
|
+
};
|
|
171
|
+
export declare function rgbToOklch({ r, g, b }: {
|
|
172
|
+
r: number;
|
|
173
|
+
g: number;
|
|
174
|
+
b: number;
|
|
175
|
+
}): {
|
|
176
|
+
L: number;
|
|
177
|
+
C: number;
|
|
178
|
+
H: number;
|
|
179
|
+
};
|
|
180
|
+
export declare function oklchToRgb({ L, C, H }: {
|
|
181
|
+
L: number;
|
|
182
|
+
C: number;
|
|
183
|
+
H: number;
|
|
184
|
+
}): {
|
|
185
|
+
r: number;
|
|
186
|
+
g: number;
|
|
187
|
+
b: number;
|
|
188
|
+
};
|
|
189
|
+
export declare function toHslString(h: number, s: number, l: number, alpha?: number): string;
|