@paulperigault/tokens 0.0.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/dist/customize/derive-overrides.d.ts +13 -0
- package/dist/customize/derive-overrides.js +40 -0
- package/dist/customize/derive-roles.d.ts +18 -0
- package/dist/customize/derive-roles.js +40 -0
- package/dist/customize/font-stack.d.ts +5 -0
- package/dist/customize/font-stack.js +26 -0
- package/dist/customize/hue.d.ts +8 -0
- package/dist/customize/hue.js +20 -0
- package/dist/customize/index.d.ts +8 -0
- package/dist/customize/index.js +5 -0
- package/dist/customize/input.d.ts +11 -0
- package/dist/customize/input.js +26 -0
- package/dist/customize/result.d.ts +16 -0
- package/dist/customize/result.js +18 -0
- package/dist/customize/settle.d.ts +8 -0
- package/dist/customize/settle.js +16 -0
- package/dist/lib/color-data.d.ts +30 -0
- package/dist/lib/color-data.js +28 -0
- package/dist/lib/color.d.ts +24 -0
- package/dist/lib/color.js +105 -0
- package/dist/lib/contrast.d.ts +13 -0
- package/dist/lib/contrast.js +90 -0
- package/dist/palette/domain/categorical.d.ts +7 -0
- package/dist/palette/domain/categorical.js +42 -0
- package/dist/palette/domain/color/cvd.d.ts +18 -0
- package/dist/palette/domain/color/cvd.js +29 -0
- package/dist/palette/domain/color/delta-e.d.ts +2 -0
- package/dist/palette/domain/color/delta-e.js +73 -0
- package/dist/palette/domain/color/gamut.d.ts +5 -0
- package/dist/palette/domain/color/gamut.js +24 -0
- package/dist/palette/domain/color/lab.d.ts +8 -0
- package/dist/palette/domain/color/lab.js +21 -0
- package/dist/palette/domain/color/vision.d.ts +11 -0
- package/dist/palette/domain/color/vision.js +28 -0
- package/dist/palette/domain/derive.d.ts +8 -0
- package/dist/palette/domain/derive.js +55 -0
- package/dist/palette/domain/ink.d.ts +12 -0
- package/dist/palette/domain/ink.js +13 -0
- package/dist/palette/domain/ramps.d.ts +8 -0
- package/dist/palette/domain/ramps.js +43 -0
- package/dist/palette/domain/result.d.ts +10 -0
- package/dist/palette/domain/result.js +6 -0
- package/dist/palette/domain/thresholds.d.ts +12 -0
- package/dist/palette/domain/thresholds.js +12 -0
- package/dist/palette/domain/tokens.d.ts +6 -0
- package/dist/palette/domain/tokens.js +25 -0
- package/dist/palette/domain/types.d.ts +22 -0
- package/dist/palette/domain/types.js +1 -0
- package/dist/palette/errors.d.ts +10 -0
- package/dist/palette/errors.js +14 -0
- package/dist/palette/index.d.ts +10 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/infrastructure/guards.d.ts +2 -0
- package/dist/palette/infrastructure/guards.js +1 -0
- package/dist/palette/infrastructure/series-ink.d.ts +12 -0
- package/dist/palette/infrastructure/series-ink.js +30 -0
- package/dist/palette/infrastructure/theme-base.d.ts +7 -0
- package/dist/palette/infrastructure/theme-base.js +44 -0
- package/generated/tokens.css +95 -0
- package/generated/tokens.d.ts +76 -0
- package/generated/tokens.json +240 -0
- package/package.json +66 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { gammaToLinear, inSrgbGamut, oklchToSrgb, parseOklch } from "./color.js";
|
|
2
|
+
// WCAG 2.2 (W3C, 2023), définitions « relative luminance » et « contrast ratio ».
|
|
3
|
+
// Linéarisation par gammaToLinear (seuil 0.04045 de l'IEC 61966-2-1) ; le 0.03928 historique de
|
|
4
|
+
// WCAG ne change aucun canal 8 bits (note de WCAG 2.2).
|
|
5
|
+
const WCAG_RED = 0.2126;
|
|
6
|
+
const WCAG_GREEN = 0.7152;
|
|
7
|
+
const WCAG_BLUE = 0.0722;
|
|
8
|
+
const WCAG_FLARE = 0.05;
|
|
9
|
+
// APCA 0.0.98G-4g, Andrew Somers (Myndex), apca-w3 0.1.9 / SAPC-APCA, constantes « G-4g ».
|
|
10
|
+
// Informatif seulement : WCAG 3 n'a pas d'algorithme de contraste arrêté, jamais bloquant.
|
|
11
|
+
const APCA = Object.freeze({
|
|
12
|
+
mainTrc: 2.4,
|
|
13
|
+
red: 0.2126729,
|
|
14
|
+
green: 0.7151522,
|
|
15
|
+
blue: 0.072175,
|
|
16
|
+
normBg: 0.56,
|
|
17
|
+
normTxt: 0.57,
|
|
18
|
+
revTxt: 0.62,
|
|
19
|
+
revBg: 0.65,
|
|
20
|
+
blkThrs: 0.022,
|
|
21
|
+
blkClmp: 1.414,
|
|
22
|
+
scaleBoW: 1.14,
|
|
23
|
+
scaleWoB: 1.14,
|
|
24
|
+
loBoWoffset: 0.027,
|
|
25
|
+
loWoBoffset: 0.027,
|
|
26
|
+
deltaYmin: 0.0005,
|
|
27
|
+
loClip: 0.1,
|
|
28
|
+
});
|
|
29
|
+
const LC_SCALE = 100;
|
|
30
|
+
const BYTE_MAX = 255;
|
|
31
|
+
const HEX_RADIX = 16;
|
|
32
|
+
const HEX_PATTERN = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
|
|
33
|
+
const clampUnit = (value) => Math.min(1, Math.max(0, value));
|
|
34
|
+
function hexToSrgb(text) {
|
|
35
|
+
const match = HEX_PATTERN.exec(text);
|
|
36
|
+
if (!match)
|
|
37
|
+
throw new TypeError(`contraste : « ${text} » attendu #rrggbb.`);
|
|
38
|
+
const channel = (pair = '') => Number.parseInt(pair, HEX_RADIX) / BYTE_MAX;
|
|
39
|
+
return { r: channel(match[1]), g: channel(match[2]), b: channel(match[3]) };
|
|
40
|
+
}
|
|
41
|
+
function oklchToRenderedSrgb(color) {
|
|
42
|
+
if (!inSrgbGamut(color)) {
|
|
43
|
+
const { l, c, h } = color;
|
|
44
|
+
throw new RangeError(`contraste : oklch(${l} ${c} ${h}) hors gamut sRGB.`);
|
|
45
|
+
}
|
|
46
|
+
const { r, g, b } = oklchToSrgb(color);
|
|
47
|
+
return { r: clampUnit(r), g: clampUnit(g), b: clampUnit(b) };
|
|
48
|
+
}
|
|
49
|
+
/** `oklch(…)`, `#rrggbb` ou `{ l, c, h }` → sRGB gamma dans [0, 1]. */
|
|
50
|
+
function toSrgb(color) {
|
|
51
|
+
if (typeof color === 'object')
|
|
52
|
+
return oklchToRenderedSrgb(color);
|
|
53
|
+
const text = color.trim();
|
|
54
|
+
if (text.startsWith('#'))
|
|
55
|
+
return hexToSrgb(text);
|
|
56
|
+
return oklchToRenderedSrgb(parseOklch(text));
|
|
57
|
+
}
|
|
58
|
+
/** Luminance relative WCAG 2.x, de canaux sRGB gamma dans [0, 1]. */
|
|
59
|
+
export function relativeLuminance({ r, g, b }) {
|
|
60
|
+
return WCAG_RED * gammaToLinear(r) + WCAG_GREEN * gammaToLinear(g) + WCAG_BLUE * gammaToLinear(b);
|
|
61
|
+
}
|
|
62
|
+
/** Rapport de contraste WCAG 2, de 1 à 21, indépendant de l'ordre des couleurs. */
|
|
63
|
+
export function contrastRatio(a, b) {
|
|
64
|
+
const first = relativeLuminance(toSrgb(a));
|
|
65
|
+
const second = relativeLuminance(toSrgb(b));
|
|
66
|
+
return (Math.max(first, second) + WCAG_FLARE) / (Math.min(first, second) + WCAG_FLARE);
|
|
67
|
+
}
|
|
68
|
+
/** Luminance APCA : puissance simple (pas la courbe sRGB), puis rehaussement des noirs. */
|
|
69
|
+
function apcaLuminance({ r, g, b }) {
|
|
70
|
+
const { mainTrc, blkThrs, blkClmp } = APCA;
|
|
71
|
+
const y = APCA.red * r ** mainTrc + APCA.green * g ** mainTrc + APCA.blue * b ** mainTrc;
|
|
72
|
+
return y > blkThrs ? y : y + (blkThrs - y) ** blkClmp;
|
|
73
|
+
}
|
|
74
|
+
function normalPolarity(textY, backgroundY) {
|
|
75
|
+
const sapc = (backgroundY ** APCA.normBg - textY ** APCA.normTxt) * APCA.scaleBoW;
|
|
76
|
+
return sapc < APCA.loClip ? 0 : sapc - APCA.loBoWoffset;
|
|
77
|
+
}
|
|
78
|
+
function reversePolarity(textY, backgroundY) {
|
|
79
|
+
const sapc = (backgroundY ** APCA.revBg - textY ** APCA.revTxt) * APCA.scaleWoB;
|
|
80
|
+
return sapc > -APCA.loClip ? 0 : sapc + APCA.loWoBoffset;
|
|
81
|
+
}
|
|
82
|
+
/** Lc APCA signé : positif = texte sombre sur fond clair, négatif = texte clair sur fond sombre. */
|
|
83
|
+
export function apcaLc(text, background) {
|
|
84
|
+
const textY = apcaLuminance(toSrgb(text));
|
|
85
|
+
const backgroundY = apcaLuminance(toSrgb(background));
|
|
86
|
+
if (Math.abs(backgroundY - textY) < APCA.deltaYmin)
|
|
87
|
+
return 0;
|
|
88
|
+
const polarity = backgroundY > textY ? normalPolarity : reversePolarity;
|
|
89
|
+
return polarity(textY, backgroundY) * LC_SCALE;
|
|
90
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Oklch } from '../../lib/color.ts';
|
|
2
|
+
import type { ThemeBase } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Couleurs de série : l'accent d'abord, puis, une à une, la candidate la plus éloignée de celles
|
|
5
|
+
* déjà prises (farthest-point sampling), la distance étant le pire ΔE00 des quatre visions.
|
|
6
|
+
*/
|
|
7
|
+
export declare function deriveCategorical(base: ThemeBase, hue: number): Oklch[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { contrastRatio } from "../../lib/contrast.js";
|
|
2
|
+
import { fitToGamut } from "./color/gamut.js";
|
|
3
|
+
import { visionDistance, visionLabs } from "./color/vision.js";
|
|
4
|
+
import { CATEGORICAL_COUNT, MIN_GRAPHIC_CONTRAST } from "./thresholds.js";
|
|
5
|
+
const HUE_STEP = 15;
|
|
6
|
+
const FULL_TURN = 360;
|
|
7
|
+
const LIGHTNESS_FROM = 0.2;
|
|
8
|
+
const LIGHTNESS_TO = 0.98;
|
|
9
|
+
const LIGHTNESS_STEP = 0.04;
|
|
10
|
+
/** Multiplicateurs du chroma de l'accent : des tons plus ou moins vifs que lui. */
|
|
11
|
+
const CHROMA_FACTORS = Object.values({ muted: 0.5, same: 1, vivid: 1.6, vivider: 2.4 });
|
|
12
|
+
/** En deçà, la couleur se lit comme un gris : elle ne serait plus « une couleur de série ». */
|
|
13
|
+
const MIN_CHROMA = 0.06;
|
|
14
|
+
/** Une série ne doit pas se confondre avec le texte courant. */
|
|
15
|
+
const MIN_DELTA_FROM_TEXT = 10;
|
|
16
|
+
const range = (from, to, step) => Array.from({ length: Math.floor((to - from) / step) + 1 }, (_, index) => from + index * step);
|
|
17
|
+
const grid = (hue, chroma) => range(0, FULL_TURN - HUE_STEP, HUE_STEP).flatMap((offset) => range(LIGHTNESS_FROM, LIGHTNESS_TO, LIGHTNESS_STEP).flatMap((l) => CHROMA_FACTORS.map((factor) => fitToGamut({ l, c: chroma * factor, h: (hue + offset) % FULL_TURN }))));
|
|
18
|
+
function candidates(base, hue) {
|
|
19
|
+
const text = visionLabs(base.fg);
|
|
20
|
+
return grid(hue, base.accent.c)
|
|
21
|
+
.filter((color) => color.c >= MIN_CHROMA && contrastRatio(color, base.bg) >= MIN_GRAPHIC_CONTRAST)
|
|
22
|
+
.map((color) => ({ color, labs: visionLabs(color) }))
|
|
23
|
+
.filter(({ labs }) => visionDistance(labs, text) >= MIN_DELTA_FROM_TEXT);
|
|
24
|
+
}
|
|
25
|
+
const distanceToChosen = (candidate, chosen) => Math.min(...chosen.map((other) => visionDistance(candidate.labs, other.labs)));
|
|
26
|
+
/**
|
|
27
|
+
* Couleurs de série : l'accent d'abord, puis, une à une, la candidate la plus éloignée de celles
|
|
28
|
+
* déjà prises (farthest-point sampling), la distance étant le pire ΔE00 des quatre visions.
|
|
29
|
+
*/
|
|
30
|
+
export function deriveCategorical(base, hue) {
|
|
31
|
+
const accent = fitToGamut({ ...base.accent, h: hue });
|
|
32
|
+
const chosen = [{ color: accent, labs: visionLabs(accent) }];
|
|
33
|
+
const pool = candidates(base, hue);
|
|
34
|
+
while (chosen.length < CATEGORICAL_COUNT && pool.length > 0) {
|
|
35
|
+
const scores = pool.map((candidate) => distanceToChosen(candidate, chosen));
|
|
36
|
+
const best = scores.indexOf(Math.max(...scores));
|
|
37
|
+
const [picked] = pool.splice(best, 1);
|
|
38
|
+
if (picked)
|
|
39
|
+
chosen.push(picked);
|
|
40
|
+
}
|
|
41
|
+
return chosen.map(({ color }) => color);
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rgb } from '../../../lib/color.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Simulation des dichromacies : Machado, Oliveira et Fernandes (2009), « A Physiologically-based
|
|
4
|
+
* Model for Simulation of Color Vision Deficiency », IEEE TVCG 15(6), gravité 1,0.
|
|
5
|
+
* Matrices appliquées en sRGB linéaire.
|
|
6
|
+
*/
|
|
7
|
+
export type CvdKind = 'protanopia' | 'deuteranopia' | 'tritanopia';
|
|
8
|
+
interface Row3 {
|
|
9
|
+
readonly r: number;
|
|
10
|
+
readonly g: number;
|
|
11
|
+
readonly b: number;
|
|
12
|
+
}
|
|
13
|
+
type Matrix3 = readonly [Row3, Row3, Row3];
|
|
14
|
+
export declare const CVD_KINDS: readonly CvdKind[];
|
|
15
|
+
export declare const CVD_MATRICES: Record<CvdKind, Matrix3>;
|
|
16
|
+
/** Couleur perçue par une personne atteinte, en sRGB linéaire borné à [0, 1]. */
|
|
17
|
+
export declare function simulateCvd(color: Rgb, kind: CvdKind): Rgb;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export const CVD_KINDS = ['protanopia', 'deuteranopia', 'tritanopia'];
|
|
2
|
+
export const CVD_MATRICES = {
|
|
3
|
+
protanopia: [
|
|
4
|
+
{ r: 0.152286, g: 1.052583, b: -0.204868 },
|
|
5
|
+
{ r: 0.114503, g: 0.786281, b: 0.099216 },
|
|
6
|
+
{ r: -0.003882, g: -0.048116, b: 1.051998 },
|
|
7
|
+
],
|
|
8
|
+
deuteranopia: [
|
|
9
|
+
{ r: 0.367322, g: 0.860646, b: -0.227968 },
|
|
10
|
+
{ r: 0.280085, g: 0.672501, b: 0.047413 },
|
|
11
|
+
{ r: -0.01182, g: 0.04294, b: 0.968881 },
|
|
12
|
+
],
|
|
13
|
+
tritanopia: [
|
|
14
|
+
{ r: 1.255528, g: -0.076749, b: -0.178779 },
|
|
15
|
+
{ r: -0.078411, g: 0.930809, b: 0.147602 },
|
|
16
|
+
{ r: 0.004733, g: 0.691367, b: 0.3039 },
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
20
|
+
const dot = (row, { r, g, b }) => row.r * r + row.g * g + row.b * b;
|
|
21
|
+
/** Couleur perçue par une personne atteinte, en sRGB linéaire borné à [0, 1]. */
|
|
22
|
+
export function simulateCvd(color, kind) {
|
|
23
|
+
const [row1, row2, row3] = CVD_MATRICES[kind];
|
|
24
|
+
return {
|
|
25
|
+
r: clamp01(dot(row1, color)),
|
|
26
|
+
g: clamp01(dot(row2, color)),
|
|
27
|
+
b: clamp01(dot(row3, color)),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CIEDE2000 : CIE 142-2001 ; implémentation de Sharma, Wu et Dalal (2005), « The CIEDE2000
|
|
3
|
+
* color-difference formula », Color Research & Application 30(1), avec leurs données d'essai.
|
|
4
|
+
*/
|
|
5
|
+
const HALF_TURN = 180;
|
|
6
|
+
const FULL_TURN = 360;
|
|
7
|
+
const DEG = Math.PI / HALF_TURN;
|
|
8
|
+
const TWO = 2;
|
|
9
|
+
const SEVEN = 7;
|
|
10
|
+
const CHROMA_REFERENCE = 25;
|
|
11
|
+
const K = {
|
|
12
|
+
pow25: CHROMA_REFERENCE ** SEVEN,
|
|
13
|
+
lMid: 50,
|
|
14
|
+
lSmooth: 20,
|
|
15
|
+
sl: 0.015,
|
|
16
|
+
sc: 0.045,
|
|
17
|
+
sh: 0.015,
|
|
18
|
+
rotCentre: 275,
|
|
19
|
+
rotWidth: 25,
|
|
20
|
+
rotMax: 30,
|
|
21
|
+
};
|
|
22
|
+
/** Termes du poids de teinte T : coefficient, multiple de h̄, décalage en degrés. */
|
|
23
|
+
const T_TERMS = [
|
|
24
|
+
{ weight: -0.17, multiple: 1, shift: -30 },
|
|
25
|
+
{ weight: 0.24, multiple: 2, shift: 0 },
|
|
26
|
+
{ weight: 0.32, multiple: 3, shift: 6 },
|
|
27
|
+
{ weight: -0.2, multiple: 4, shift: -63 },
|
|
28
|
+
];
|
|
29
|
+
const square = (value) => value * value;
|
|
30
|
+
const pow7 = (value) => value ** SEVEN;
|
|
31
|
+
const half = (value) => value / TWO;
|
|
32
|
+
const chromaFactor = (cBar) => Math.sqrt(pow7(cBar) / (pow7(cBar) + K.pow25));
|
|
33
|
+
const hueAngle = (a, b) => {
|
|
34
|
+
if (a === 0 && b === 0)
|
|
35
|
+
return 0;
|
|
36
|
+
const angle = Math.atan2(b, a) / DEG;
|
|
37
|
+
return angle < 0 ? angle + FULL_TURN : angle;
|
|
38
|
+
};
|
|
39
|
+
const meanHue = (h1, h2, achromatic) => {
|
|
40
|
+
const sum = h1 + h2;
|
|
41
|
+
if (achromatic)
|
|
42
|
+
return sum;
|
|
43
|
+
if (Math.abs(h1 - h2) <= HALF_TURN)
|
|
44
|
+
return half(sum);
|
|
45
|
+
return half(sum + (sum < FULL_TURN ? FULL_TURN : -FULL_TURN));
|
|
46
|
+
};
|
|
47
|
+
const deltaHue = (h1, h2, achromatic) => {
|
|
48
|
+
const diff = h2 - h1;
|
|
49
|
+
if (achromatic || Math.abs(diff) <= HALF_TURN)
|
|
50
|
+
return achromatic ? 0 : diff;
|
|
51
|
+
return diff > HALF_TURN ? diff - FULL_TURN : diff + FULL_TURN;
|
|
52
|
+
};
|
|
53
|
+
const hueWeight = (hBar) => T_TERMS.reduce((sum, { weight, multiple, shift }) => sum + weight * Math.cos((multiple * hBar + shift) * DEG), 1);
|
|
54
|
+
const rotation = (hBar, cBar) => {
|
|
55
|
+
const delta = K.rotMax * Math.exp(-square((hBar - K.rotCentre) / K.rotWidth));
|
|
56
|
+
return -Math.sin(TWO * delta * DEG) * TWO * chromaFactor(cBar);
|
|
57
|
+
};
|
|
58
|
+
export function deltaE2000(x, y) {
|
|
59
|
+
const g = half(1 - chromaFactor(half(Math.hypot(x.a, x.b) + Math.hypot(y.a, y.b))));
|
|
60
|
+
const [a1, a2] = [(1 + g) * x.a, (1 + g) * y.a];
|
|
61
|
+
const [c1, c2] = [Math.hypot(a1, x.b), Math.hypot(a2, y.b)];
|
|
62
|
+
const [h1, h2] = [hueAngle(a1, x.b), hueAngle(a2, y.b)];
|
|
63
|
+
const gray = c1 * c2 === 0;
|
|
64
|
+
const dH = TWO * Math.sqrt(c1 * c2) * Math.sin(half(deltaHue(h1, h2, gray) * DEG));
|
|
65
|
+
const lBar = half(x.l + y.l);
|
|
66
|
+
const cBar = half(c1 + c2);
|
|
67
|
+
const hBar = meanHue(h1, h2, gray);
|
|
68
|
+
const sl = 1 + (K.sl * square(lBar - K.lMid)) / Math.sqrt(K.lSmooth + square(lBar - K.lMid));
|
|
69
|
+
const tl = (y.l - x.l) / sl;
|
|
70
|
+
const tc = (c2 - c1) / (1 + K.sc * cBar);
|
|
71
|
+
const th = dH / (1 + K.sh * cBar * hueWeight(hBar));
|
|
72
|
+
return Math.sqrt(square(tl) + square(tc) + square(th) + rotation(hBar, cBar) * tc * th);
|
|
73
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Oklch, Rgb } from '../../../lib/color.ts';
|
|
2
|
+
/** Réduit le chroma (clarté et teinte conservées) jusqu'à tenir dans sRGB : pas de rognage. */
|
|
3
|
+
export declare function fitToGamut(color: Oklch): Oklch;
|
|
4
|
+
/** sRGB linéaire, borné à [0, 1] (bruit d'arrondi aux bords du gamut). */
|
|
5
|
+
export declare function toLinear(color: Oklch): Rgb;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { inSrgbGamut, oklchToLinearSrgb } from "../../../lib/color.js";
|
|
2
|
+
const BISECTION_STEPS = 24;
|
|
3
|
+
const HALF = 0.5;
|
|
4
|
+
/** Réduit le chroma (clarté et teinte conservées) jusqu'à tenir dans sRGB : pas de rognage. */
|
|
5
|
+
export function fitToGamut(color) {
|
|
6
|
+
if (inSrgbGamut(color))
|
|
7
|
+
return color;
|
|
8
|
+
let low = 0;
|
|
9
|
+
let high = color.c;
|
|
10
|
+
for (let step = 0; step < BISECTION_STEPS; step += 1) {
|
|
11
|
+
const mid = (low + high) * HALF;
|
|
12
|
+
if (inSrgbGamut({ ...color, c: mid }))
|
|
13
|
+
low = mid;
|
|
14
|
+
else
|
|
15
|
+
high = mid;
|
|
16
|
+
}
|
|
17
|
+
return { ...color, c: low };
|
|
18
|
+
}
|
|
19
|
+
const clamp01 = (value) => Math.min(1, Math.max(0, value));
|
|
20
|
+
/** sRGB linéaire, borné à [0, 1] (bruit d'arrondi aux bords du gamut). */
|
|
21
|
+
export function toLinear(color) {
|
|
22
|
+
const { r, g, b } = oklchToLinearSrgb(color);
|
|
23
|
+
return { r: clamp01(r), g: clamp01(g), b: clamp01(b) };
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Rgb } from '../../../lib/color.ts';
|
|
2
|
+
/** CIE L*a*b* (illuminant D65) depuis du sRGB linéaire (IEC 61966-2-1, CIE 15). */
|
|
3
|
+
export interface Lab {
|
|
4
|
+
readonly l: number;
|
|
5
|
+
readonly a: number;
|
|
6
|
+
readonly b: number;
|
|
7
|
+
}
|
|
8
|
+
export declare function linearSrgbToLab(color: Rgb): Lab;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const SRGB_TO_XYZ_D65 = [
|
|
2
|
+
{ r: 0.4124564, g: 0.3575761, b: 0.1804375, white: 0.95047 },
|
|
3
|
+
{ r: 0.2126729, g: 0.7151522, b: 0.072175, white: 1 },
|
|
4
|
+
{ r: 0.0193339, g: 0.119192, b: 0.9503041, white: 1.08883 },
|
|
5
|
+
];
|
|
6
|
+
const LAB = {
|
|
7
|
+
epsilon: 0.008856,
|
|
8
|
+
kappa: 903.3,
|
|
9
|
+
scale: 116,
|
|
10
|
+
offset: 16,
|
|
11
|
+
aScale: 500,
|
|
12
|
+
bScale: 200,
|
|
13
|
+
};
|
|
14
|
+
const f = (t) => t > LAB.epsilon ? Math.cbrt(t) : (LAB.kappa * t + LAB.offset) / LAB.scale;
|
|
15
|
+
const channel = (row, { r, g, b }) => f((row.r * r + row.g * g + row.b * b) / row.white);
|
|
16
|
+
export function linearSrgbToLab(color) {
|
|
17
|
+
const [fx, fy, fz] = SRGB_TO_XYZ_D65.map((row) => channel(row, color));
|
|
18
|
+
if (fx === undefined || fy === undefined || fz === undefined)
|
|
19
|
+
return { l: 0, a: 0, b: 0 };
|
|
20
|
+
return { l: LAB.scale * fy - LAB.offset, a: LAB.aScale * (fx - fy), b: LAB.bScale * (fy - fz) };
|
|
21
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Oklch } from '../../../lib/color.ts';
|
|
2
|
+
import type { Lab } from './lab.ts';
|
|
3
|
+
/** Couleur vue en vision normale puis en protanopie, deutéranopie et tritanopie. */
|
|
4
|
+
export type VisionLabs = readonly Lab[];
|
|
5
|
+
export declare function visionLabs(color: Oklch): VisionLabs;
|
|
6
|
+
/** Pire ΔE00 des quatre visions : deux couleurs sont aussi distinctes que leur pire cas. */
|
|
7
|
+
export declare function visionDistance(a: VisionLabs, b: VisionLabs): number;
|
|
8
|
+
/** Plus petit écart de toutes les paires d'une liste (Infinity si moins de deux couleurs). */
|
|
9
|
+
export declare function minPairDistance(colors: readonly Oklch[]): number;
|
|
10
|
+
/** Plus petit écart entre voisins d'une rampe ordonnée. */
|
|
11
|
+
export declare function minStepDistance(colors: readonly Oklch[]): number;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CVD_KINDS, simulateCvd } from "./cvd.js";
|
|
2
|
+
import { deltaE2000 } from "./delta-e.js";
|
|
3
|
+
import { toLinear } from "./gamut.js";
|
|
4
|
+
import { linearSrgbToLab } from "./lab.js";
|
|
5
|
+
export function visionLabs(color) {
|
|
6
|
+
const linear = toLinear(color);
|
|
7
|
+
return [linear, ...CVD_KINDS.map((kind) => simulateCvd(linear, kind))].map(linearSrgbToLab);
|
|
8
|
+
}
|
|
9
|
+
/** Pire ΔE00 des quatre visions : deux couleurs sont aussi distinctes que leur pire cas. */
|
|
10
|
+
export function visionDistance(a, b) {
|
|
11
|
+
return Math.min(...a.map((lab, index) => deltaE2000(lab, b[index] ?? lab)));
|
|
12
|
+
}
|
|
13
|
+
/** Plus petit écart de toutes les paires d'une liste (Infinity si moins de deux couleurs). */
|
|
14
|
+
export function minPairDistance(colors) {
|
|
15
|
+
const labs = colors.map(visionLabs);
|
|
16
|
+
let min = Number.POSITIVE_INFINITY;
|
|
17
|
+
for (const [i, first] of labs.entries()) {
|
|
18
|
+
for (const second of labs.slice(i + 1))
|
|
19
|
+
min = Math.min(min, visionDistance(first, second));
|
|
20
|
+
}
|
|
21
|
+
return min;
|
|
22
|
+
}
|
|
23
|
+
/** Plus petit écart entre voisins d'une rampe ordonnée. */
|
|
24
|
+
export function minStepDistance(colors) {
|
|
25
|
+
const labs = colors.map(visionLabs);
|
|
26
|
+
const steps = labs.slice(1).map((lab, index) => visionDistance(labs[index] ?? lab, lab));
|
|
27
|
+
return Math.min(...steps);
|
|
28
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Result } from './result.ts';
|
|
2
|
+
import type { Palettes, Theme, ThemeBase } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Dérive les trois palettes d'une teinte d'accent (degrés OKLCH) pour un thème. La clarté et le
|
|
5
|
+
* chroma de l'accent viennent des jetons (`base`) : seule la teinte change. Refuse (erreur typée)
|
|
6
|
+
* une teinte dont la dérivation échoue au contrôle.
|
|
7
|
+
*/
|
|
8
|
+
export declare function derivePalettes(hue: number, theme: Theme, base: ThemeBase): Result<Palettes>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { contrastRatio } from "../../lib/contrast.js";
|
|
2
|
+
import { fitToGamut } from "./color/gamut.js";
|
|
3
|
+
import { minPairDistance, minStepDistance } from "./color/vision.js";
|
|
4
|
+
import { fail, ok } from "./result.js";
|
|
5
|
+
import { deriveCategorical } from "./categorical.js";
|
|
6
|
+
import { deriveDiverging, deriveSequential } from "./ramps.js";
|
|
7
|
+
import { CATEGORICAL_COUNT, MIN_CATEGORICAL_DELTA, MIN_STEP_DELTA, MIN_TEXT_CONTRAST, } from "./thresholds.js";
|
|
8
|
+
const FULL_TURN = 360;
|
|
9
|
+
const normalizeHue = (hue) => ((hue % FULL_TURN) + FULL_TURN) % FULL_TURN;
|
|
10
|
+
const finite = (color) => Number.isFinite(color.l) && Number.isFinite(color.c) && Number.isFinite(color.h);
|
|
11
|
+
function checkBase(base) {
|
|
12
|
+
const colors = [base.accent, base.onAccent, base.bg, base.fg, base.line];
|
|
13
|
+
return colors.every(finite)
|
|
14
|
+
? ok(base)
|
|
15
|
+
: fail('palette.bad-base', 'Jetons de thème : couleurs OKLCH finies attendues.');
|
|
16
|
+
}
|
|
17
|
+
function checkPalettes(palettes) {
|
|
18
|
+
const { accent, onAccent, categorical, sequential, diverging } = palettes;
|
|
19
|
+
if (contrastRatio(onAccent, accent) < MIN_TEXT_CONTRAST) {
|
|
20
|
+
return fail('palette.contrast-failed', "Le texte sur l'accent passe sous 4,5:1.", 'onAccent');
|
|
21
|
+
}
|
|
22
|
+
if (categorical.length < CATEGORICAL_COUNT ||
|
|
23
|
+
minPairDistance(categorical) < MIN_CATEGORICAL_DELTA) {
|
|
24
|
+
return fail('palette.cvd-failed', 'Catégorielle : ΔE00 sous 10 selon la simulation.', 'categorical');
|
|
25
|
+
}
|
|
26
|
+
if (minStepDistance(sequential) < MIN_STEP_DELTA) {
|
|
27
|
+
return fail('palette.sequential-failed', 'Séquentielle : pas voisins sous ΔE00 3.', 'sequential');
|
|
28
|
+
}
|
|
29
|
+
if (minStepDistance(diverging) < MIN_STEP_DELTA) {
|
|
30
|
+
return fail('palette.diverging-failed', 'Divergente : pas voisins sous ΔE00 3.', 'diverging');
|
|
31
|
+
}
|
|
32
|
+
return ok(palettes);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Dérive les trois palettes d'une teinte d'accent (degrés OKLCH) pour un thème. La clarté et le
|
|
36
|
+
* chroma de l'accent viennent des jetons (`base`) : seule la teinte change. Refuse (erreur typée)
|
|
37
|
+
* une teinte dont la dérivation échoue au contrôle.
|
|
38
|
+
*/
|
|
39
|
+
export function derivePalettes(hue, theme, base) {
|
|
40
|
+
if (!Number.isFinite(hue))
|
|
41
|
+
return fail('palette.bad-hue', 'La teinte doit être un nombre fini.');
|
|
42
|
+
const checked = checkBase(base);
|
|
43
|
+
if (!checked.ok)
|
|
44
|
+
return checked;
|
|
45
|
+
const h = normalizeHue(hue);
|
|
46
|
+
return checkPalettes({
|
|
47
|
+
theme,
|
|
48
|
+
hue: h,
|
|
49
|
+
accent: fitToGamut({ ...base.accent, h }),
|
|
50
|
+
onAccent: base.onAccent,
|
|
51
|
+
categorical: deriveCategorical(base, h),
|
|
52
|
+
sequential: deriveSequential(base, h, theme),
|
|
53
|
+
diverging: deriveDiverging(base, h, theme),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Oklch } from '../../lib/color.ts';
|
|
2
|
+
/** Neutre de texte d'un thème : `fg` (texte) ou `bg` (fond de page). */
|
|
3
|
+
export type Ink = 'fg' | 'bg';
|
|
4
|
+
export interface Inks {
|
|
5
|
+
readonly fg: Oklch;
|
|
6
|
+
readonly bg: Oklch;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Neutre le plus contrasté pour écrire sur `background`, ou `null` si aucun n'atteint `min`
|
|
10
|
+
* (WCAG 2.2, 1.4.3) : le texte n'a alors pas sa place sur cette couleur.
|
|
11
|
+
*/
|
|
12
|
+
export declare function inkOn(background: Oklch, inks: Inks, min?: number): Ink | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { contrastRatio } from "../../lib/contrast.js";
|
|
2
|
+
import { MIN_TEXT_CONTRAST } from "./thresholds.js";
|
|
3
|
+
/**
|
|
4
|
+
* Neutre le plus contrasté pour écrire sur `background`, ou `null` si aucun n'atteint `min`
|
|
5
|
+
* (WCAG 2.2, 1.4.3) : le texte n'a alors pas sa place sur cette couleur.
|
|
6
|
+
*/
|
|
7
|
+
export function inkOn(background, inks, min = MIN_TEXT_CONTRAST) {
|
|
8
|
+
const onFg = contrastRatio(inks.fg, background);
|
|
9
|
+
const onBg = contrastRatio(inks.bg, background);
|
|
10
|
+
if (Math.max(onFg, onBg) < min)
|
|
11
|
+
return null;
|
|
12
|
+
return onFg >= onBg ? 'fg' : 'bg';
|
|
13
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Oklch } from '../../lib/color.ts';
|
|
2
|
+
import type { Theme, ThemeBase } from './types.ts';
|
|
3
|
+
/** 7 pas d'une seule teinte, clarté monotone du plus pâle à l'accent (Brewer, 2003, pour le principe). */
|
|
4
|
+
export declare function deriveSequential(base: ThemeBase, hue: number, theme: Theme): Oklch[];
|
|
5
|
+
/** Extrémité opposée : teinte à 180°, clarté décalée vers le fond. */
|
|
6
|
+
export declare function oppositeEnd(base: ThemeBase, hue: number, theme: Theme): Oklch;
|
|
7
|
+
/** Accent, centre neutre (`--pp-color-line`), teinte opposée : 7 pas égaux. */
|
|
8
|
+
export declare function deriveDiverging(base: ThemeBase, hue: number, theme: Theme): Oklch[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { fitToGamut } from "./color/gamut.js";
|
|
2
|
+
import { DIVERGING_COUNT, SEQUENTIAL_COUNT } from "./thresholds.js";
|
|
3
|
+
const HALF_TURN = 180;
|
|
4
|
+
const TWO_SIDES = 2;
|
|
5
|
+
const FULL_TURN = 360;
|
|
6
|
+
/** Part du chroma de l'accent au pas le plus pâle de la séquentielle. */
|
|
7
|
+
const PALE_CHROMA_SHARE = 0.2;
|
|
8
|
+
/** Écart de clarté entre le pas le plus pâle et l'accent. */
|
|
9
|
+
const PALE_LIGHTNESS_GAP = 0.45;
|
|
10
|
+
/** Clarté de l'extrémité opposée décalée de celle de l'accent : elle s'en distingue même sans la teinte (tritanopie). */
|
|
11
|
+
const OPPOSITE_SHIFT = 0.12;
|
|
12
|
+
const mix = (from, to, t) => from + (to - from) * t;
|
|
13
|
+
const towardBackground = (theme) => (theme === 'light' ? 1 : -1);
|
|
14
|
+
/** 7 pas d'une seule teinte, clarté monotone du plus pâle à l'accent (Brewer, 2003, pour le principe). */
|
|
15
|
+
export function deriveSequential(base, hue, theme) {
|
|
16
|
+
const from = base.accent.l + towardBackground(theme) * PALE_LIGHTNESS_GAP;
|
|
17
|
+
return Array.from({ length: SEQUENTIAL_COUNT }, (_, index) => {
|
|
18
|
+
const t = index / (SEQUENTIAL_COUNT - 1);
|
|
19
|
+
const chroma = mix(base.accent.c * PALE_CHROMA_SHARE, base.accent.c, t);
|
|
20
|
+
return fitToGamut({ l: mix(from, base.accent.l, t), c: chroma, h: hue });
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** Extrémité opposée : teinte à 180°, clarté décalée vers le fond. */
|
|
24
|
+
export function oppositeEnd(base, hue, theme) {
|
|
25
|
+
return fitToGamut({
|
|
26
|
+
l: base.accent.l + towardBackground(theme) * OPPOSITE_SHIFT,
|
|
27
|
+
c: base.accent.c,
|
|
28
|
+
h: (hue + HALF_TURN) % FULL_TURN,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Accent, centre neutre (`--pp-color-line`), teinte opposée : 7 pas égaux. */
|
|
32
|
+
export function deriveDiverging(base, hue, theme) {
|
|
33
|
+
const accent = fitToGamut({ ...base.accent, h: hue });
|
|
34
|
+
const opposite = oppositeEnd(base, hue, theme);
|
|
35
|
+
const middle = (DIVERGING_COUNT - 1) / TWO_SIDES;
|
|
36
|
+
return Array.from({ length: DIVERGING_COUNT }, (_, index) => {
|
|
37
|
+
if (index === middle)
|
|
38
|
+
return base.line;
|
|
39
|
+
const end = index < middle ? accent : opposite;
|
|
40
|
+
const t = Math.abs(index - middle) / middle;
|
|
41
|
+
return fitToGamut({ l: mix(base.line.l, end.l, t), c: mix(base.line.c, end.c, t), h: end.h });
|
|
42
|
+
});
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PaletteError, PaletteErrorCode } from '../errors.ts';
|
|
2
|
+
export type Result<T> = {
|
|
3
|
+
readonly ok: true;
|
|
4
|
+
readonly value: T;
|
|
5
|
+
} | {
|
|
6
|
+
readonly ok: false;
|
|
7
|
+
readonly error: PaletteError;
|
|
8
|
+
};
|
|
9
|
+
export declare const ok: <T>(value: T) => Result<T>;
|
|
10
|
+
export declare const fail: <T = never>(code: PaletteErrorCode, message: string, path?: string) => Result<T>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Seuils de l'ADR-0007 (conventions, confirmées par les tests de ce paquet). */
|
|
2
|
+
export declare const CATEGORICAL_COUNT = 6;
|
|
3
|
+
export declare const SEQUENTIAL_COUNT = 7;
|
|
4
|
+
export declare const DIVERGING_COUNT = 7;
|
|
5
|
+
/** ΔE00 minimal entre toute paire de la catégorielle, après simulation des daltonismes. */
|
|
6
|
+
export declare const MIN_CATEGORICAL_DELTA = 10;
|
|
7
|
+
/** ΔE00 minimal entre pas voisins d'une rampe. */
|
|
8
|
+
export declare const MIN_STEP_DELTA = 3;
|
|
9
|
+
/** Contraste minimal d'un tracé contre le fond : WCAG 2.2, critère 1.4.11. */
|
|
10
|
+
export declare const MIN_GRAPHIC_CONTRAST = 3;
|
|
11
|
+
/** Contraste minimal du texte sur l'accent : WCAG 2.2, critère 1.4.3. */
|
|
12
|
+
export declare const MIN_TEXT_CONTRAST = 4.5;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Seuils de l'ADR-0007 (conventions, confirmées par les tests de ce paquet). */
|
|
2
|
+
export const CATEGORICAL_COUNT = 6;
|
|
3
|
+
export const SEQUENTIAL_COUNT = 7;
|
|
4
|
+
export const DIVERGING_COUNT = 7;
|
|
5
|
+
/** ΔE00 minimal entre toute paire de la catégorielle, après simulation des daltonismes. */
|
|
6
|
+
export const MIN_CATEGORICAL_DELTA = 10;
|
|
7
|
+
/** ΔE00 minimal entre pas voisins d'une rampe. */
|
|
8
|
+
export const MIN_STEP_DELTA = 3;
|
|
9
|
+
/** Contraste minimal d'un tracé contre le fond : WCAG 2.2, critère 1.4.11. */
|
|
10
|
+
export const MIN_GRAPHIC_CONTRAST = 3;
|
|
11
|
+
/** Contraste minimal du texte sur l'accent : WCAG 2.2, critère 1.4.3. */
|
|
12
|
+
export const MIN_TEXT_CONTRAST = 4.5;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Palettes } from './types.ts';
|
|
2
|
+
export type TokenMap = Readonly<Record<string, string>>;
|
|
3
|
+
/** Variables CSS d'un thème : accent, texte sur accent, puis les trois palettes numérotées de 1. */
|
|
4
|
+
export declare function paletteTokens(palettes: Palettes): TokenMap;
|
|
5
|
+
/** Valeurs `light-dark(clair, sombre)` : une seule déclaration par variable. */
|
|
6
|
+
export declare function lightDarkTokens(light: Palettes, dark: Palettes): TokenMap;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { formatOklch } from "../../lib/color.js";
|
|
2
|
+
/** Variables CSS d'un thème : accent, texte sur accent, puis les trois palettes numérotées de 1. */
|
|
3
|
+
export function paletteTokens(palettes) {
|
|
4
|
+
const entries = [
|
|
5
|
+
['--pp-color-accent', formatOklch(palettes.accent)],
|
|
6
|
+
['--pp-color-on-accent', formatOklch(palettes.onAccent)],
|
|
7
|
+
];
|
|
8
|
+
const ramp = (prefix, colors) => {
|
|
9
|
+
for (const [index, color] of colors.entries()) {
|
|
10
|
+
entries.push([`--pp-chart-${prefix}${index + 1}`, formatOklch(color)]);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
ramp('', palettes.categorical);
|
|
14
|
+
ramp('seq-', palettes.sequential);
|
|
15
|
+
ramp('div-', palettes.diverging);
|
|
16
|
+
return Object.fromEntries(entries);
|
|
17
|
+
}
|
|
18
|
+
/** Valeurs `light-dark(clair, sombre)` : une seule déclaration par variable. */
|
|
19
|
+
export function lightDarkTokens(light, dark) {
|
|
20
|
+
const sombre = paletteTokens(dark);
|
|
21
|
+
return Object.fromEntries(Object.entries(paletteTokens(light)).map(([name, value]) => [
|
|
22
|
+
name,
|
|
23
|
+
`light-dark(${value}, ${sombre[name] ?? value})`,
|
|
24
|
+
]));
|
|
25
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Oklch } from '../../lib/color.ts';
|
|
2
|
+
export type Theme = 'light' | 'dark';
|
|
3
|
+
/** Jetons neutres et accent d'un thème, lus dans `tokens.json` : rien n'est codé en dur ici. */
|
|
4
|
+
export interface ThemeBase {
|
|
5
|
+
readonly accent: Oklch;
|
|
6
|
+
readonly onAccent: Oklch;
|
|
7
|
+
readonly bg: Oklch;
|
|
8
|
+
readonly fg: Oklch;
|
|
9
|
+
readonly line: Oklch;
|
|
10
|
+
}
|
|
11
|
+
export interface Palettes {
|
|
12
|
+
readonly theme: Theme;
|
|
13
|
+
readonly hue: number;
|
|
14
|
+
readonly accent: Oklch;
|
|
15
|
+
readonly onAccent: Oklch;
|
|
16
|
+
/** 6 couleurs, l'accent en tête ; les n premières servent n séries. */
|
|
17
|
+
readonly categorical: readonly Oklch[];
|
|
18
|
+
/** 7 pas de clarté monotone vers l'accent. */
|
|
19
|
+
readonly sequential: readonly Oklch[];
|
|
20
|
+
/** 7 pas : accent, centre neutre (`--pp-color-line`), teinte opposée. */
|
|
21
|
+
readonly diverging: readonly Oklch[];
|
|
22
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Erreurs typées de la dérivation de palettes : union fermée à champ `code`. */
|
|
2
|
+
export declare const PALETTE_ERROR_CODES: readonly ["palette.bad-hue", "palette.bad-base", "palette.cvd-failed", "palette.contrast-failed", "palette.sequential-failed", "palette.diverging-failed"];
|
|
3
|
+
export type PaletteErrorCode = (typeof PALETTE_ERROR_CODES)[number];
|
|
4
|
+
export interface PaletteError {
|
|
5
|
+
readonly code: PaletteErrorCode;
|
|
6
|
+
readonly message: string;
|
|
7
|
+
/** Chemin de la valeur fautive, vide si global. */
|
|
8
|
+
readonly path: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const paletteError: (code: PaletteErrorCode, message: string, path?: string) => PaletteError;
|