@paulperigault/tokens 0.1.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/README.md
CHANGED
|
@@ -2,11 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
Design tokens DTCG 2025.10 de paulperigault.fr : CSS, JSON et types générés ; couleur et contraste.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Publié sur npmjs. Série `0.x` : l'API peut changer d'une version à l'autre, lire le
|
|
6
|
+
[CHANGELOG](https://github.com/PaulPerigault/design-system/blob/main/packages/tokens/CHANGELOG.md)
|
|
7
|
+
avant une mise à jour. Aucune dépendance d'exécution.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @paulperigault/tokens
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Node 24 ou plus récent.
|
|
16
|
+
|
|
17
|
+
## Exemple
|
|
18
|
+
|
|
19
|
+
En CSS, les tokens sont des propriétés `--pp-*` posées sur `:root` :
|
|
20
|
+
|
|
21
|
+
```css
|
|
22
|
+
@import '@paulperigault/tokens/tokens.css';
|
|
23
|
+
|
|
24
|
+
.note {
|
|
25
|
+
color: var(--pp-color-fg);
|
|
26
|
+
background-color: var(--pp-color-surface);
|
|
27
|
+
padding: var(--pp-space-m);
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Les couleurs utilisent `light-dark()` et suivent `prefers-color-scheme` ; `data-theme="light"` ou
|
|
32
|
+
`data-theme="dark"` sur `<html>` force l'un des deux thèmes.
|
|
33
|
+
|
|
34
|
+
En TypeScript, le contraste WCAG 2 accepte un hexadécimal ou un texte `oklch(…)` :
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { contrastRatio } from '@paulperigault/tokens/contrast';
|
|
38
|
+
|
|
39
|
+
contrastRatio('#171921', '#ffffff'); // 17,54…
|
|
40
|
+
contrastRatio('oklch(47% 0.19 270.7)', '#ffffff'); // 7,24… (accent clair)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Sous-chemins
|
|
44
|
+
|
|
45
|
+
| Import | Contenu |
|
|
46
|
+
| ----------------------------------- | ---------------------------------------------------------------- |
|
|
47
|
+
| `@paulperigault/tokens/tokens.css` | propriétés `--pp-*`, thèmes clair et sombre |
|
|
48
|
+
| `@paulperigault/tokens/tokens.json` | les mêmes valeurs en JSON |
|
|
49
|
+
| `@paulperigault/tokens/types` | type `TokenName` (union des noms `--pp-*`) |
|
|
50
|
+
| `@paulperigault/tokens/color` | OKLCH vers sRGB, gamut, `parseOklch`, `formatOklch` |
|
|
51
|
+
| `@paulperigault/tokens/contrast` | `contrastRatio` (WCAG 2), `apcaLc`, `relativeLuminance` |
|
|
52
|
+
| `@paulperigault/tokens/palette` | dérivation des palettes de graphiques (réexportée par `dataviz`) |
|
|
53
|
+
| `@paulperigault/tokens/customize` | `parseBuildInput`, `deriveOverrides` (voir la section suivante) |
|
|
6
54
|
|
|
7
55
|
## Entrées du build : teinte d'accent et pile de police
|
|
8
56
|
|
|
9
|
-
Contrat d'un projet externe (ADR-0006 décision 3, ADR-0007 décision 4)
|
|
57
|
+
Contrat d'un projet externe (ADR-0006 décision 3, ADR-0007 décision 4). La ligne de commande
|
|
58
|
+
ci-dessous se lance depuis `packages/tokens` dans le dépôt (`scripts/` n'est pas publié) ; un site
|
|
59
|
+
généré par `@paulperigault/create` passe les mêmes entrées par `--accent-hue` et `--font-stack`.
|
|
10
60
|
|
|
11
61
|
| Entrée | Valeur | Sorties régénérées |
|
|
12
62
|
| ----------------- | --------------------------------------------- | ---------------------------------------------------------------------------------- |
|
|
@@ -35,3 +85,17 @@ En code : `parseBuildInput` et `deriveOverrides` (`@paulperigault/tokens/customi
|
|
|
35
85
|
|
|
36
86
|
Limites : les rampes `--pp-chart-seq-*` et `--pp-chart-div-*` sont dérivées mais pas émises (le
|
|
37
87
|
défaut ne les porte pas). Décisions : D-056, D-057.
|
|
88
|
+
|
|
89
|
+
## Provenance
|
|
90
|
+
|
|
91
|
+
Chaque version est publiée par le workflow `release` du dépôt, avec une attestation de
|
|
92
|
+
provenance npm. Dans un projet qui installe ce paquet, `npm audit signatures` vérifie les
|
|
93
|
+
signatures du registre et les attestations. Détails :
|
|
94
|
+
[publication npm](https://github.com/PaulPerigault/design-system/blob/main/docs/process/publication.md).
|
|
95
|
+
|
|
96
|
+
## Licence et liens
|
|
97
|
+
|
|
98
|
+
- Licence MIT : [LICENSE](https://github.com/PaulPerigault/design-system/blob/main/packages/tokens/LICENSE)
|
|
99
|
+
- Documentation : <https://design.paulperigault.dev>
|
|
100
|
+
- Source : <https://github.com/PaulPerigault/design-system/tree/main/packages/tokens>
|
|
101
|
+
- Versions : [CHANGELOG.md](https://github.com/PaulPerigault/design-system/blob/main/packages/tokens/CHANGELOG.md)
|
|
@@ -5,12 +5,14 @@ import type { Result } from './result.ts';
|
|
|
5
5
|
/** Rôles qui portent la teinte d'accent, et surface contre laquelle ils sont mesurés. */
|
|
6
6
|
export interface RoleBase {
|
|
7
7
|
readonly focus: Oklch;
|
|
8
|
+
readonly accentText: Oklch;
|
|
8
9
|
readonly running: Oklch;
|
|
10
|
+
readonly info: Oklch;
|
|
9
11
|
readonly surface: Oklch;
|
|
10
12
|
}
|
|
11
13
|
export type ThemeSource = ThemeBase & RoleBase;
|
|
12
14
|
/**
|
|
13
|
-
* Dérive focus et statut « en cours » : clarté et chroma des jetons, teinte de l'accent (déjà
|
|
15
|
+
* Dérive focus, texte d'accent et statut « en cours » : clarté et chroma des jetons, teinte de l'accent (déjà
|
|
14
16
|
* normalisée par la dérivation des palettes). Le contraste est mesuré sur la valeur émise.
|
|
15
17
|
*/
|
|
16
18
|
export declare function deriveRoles(hue: number, theme: Theme, source: ThemeSource): Result<TokenMap>;
|
|
@@ -8,7 +8,9 @@ const RATIO_DIGITS = 2;
|
|
|
8
8
|
/** Seuils de `roles.json` : anneau de focus 1.4.11 (3:1), statut en texte 1.4.3 (4,5:1). */
|
|
9
9
|
const ROLES = [
|
|
10
10
|
{ token: '--pp-color-focus', key: 'focus', min: MIN_GRAPHIC_CONTRAST },
|
|
11
|
+
{ token: '--pp-color-accent-text', key: 'accentText', min: MIN_TEXT_CONTRAST },
|
|
11
12
|
{ token: '--pp-color-status-running', key: 'running', min: MIN_TEXT_CONTRAST },
|
|
13
|
+
{ token: '--pp-color-status-info', key: 'info', min: MIN_TEXT_CONTRAST },
|
|
12
14
|
];
|
|
13
15
|
function measure(token, color, min, grounds) {
|
|
14
16
|
return grounds
|
|
@@ -17,7 +19,7 @@ function measure(token, color, min, grounds) {
|
|
|
17
19
|
.map(([name, ratio]) => `${token} à ${ratio.toFixed(RATIO_DIGITS)}:1 sur ${name}, ${min}:1`);
|
|
18
20
|
}
|
|
19
21
|
/**
|
|
20
|
-
* Dérive focus et statut « en cours » : clarté et chroma des jetons, teinte de l'accent (déjà
|
|
22
|
+
* Dérive focus, texte d'accent et statut « en cours » : clarté et chroma des jetons, teinte de l'accent (déjà
|
|
21
23
|
* normalisée par la dérivation des palettes). Le contraste est mesuré sur la valeur émise.
|
|
22
24
|
*/
|
|
23
25
|
export function deriveRoles(hue, theme, source) {
|
package/generated/tokens.css
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
--pp-chart-5: light-dark(oklch(44% 0.1781 0.7), oklch(72% 0.1514 75.7));
|
|
11
11
|
--pp-chart-6: light-dark(oklch(64% 0.2025 285.7), oklch(60% 0.1 165.7));
|
|
12
12
|
--pp-color-accent: light-dark(oklch(47% 0.19 270.7), oklch(78% 0.1 270.7));
|
|
13
|
+
--pp-color-accent-text: light-dark(oklch(47% 0.19 270.7), oklch(78% 0.1 270.7));
|
|
13
14
|
--pp-color-bg: light-dark(oklch(98.5% 0.004 270.7), oklch(20.1% 0.0124 270.7));
|
|
14
15
|
--pp-color-control: light-dark(oklch(60% 0.02 270.7), oklch(60% 0.02 270.7));
|
|
15
16
|
--pp-color-fg: light-dark(oklch(21.5% 0.016 270.7), oklch(94.5% 0.008 270.7));
|
|
@@ -20,6 +21,7 @@
|
|
|
20
21
|
--pp-color-on-accent: light-dark(oklch(99.5% 0.002 270.7), oklch(20.1% 0.0124 270.7));
|
|
21
22
|
--pp-color-status-degraded: light-dark(oklch(50% 0.1 70), oklch(82% 0.11 75));
|
|
22
23
|
--pp-color-status-failed: light-dark(oklch(50% 0.17 25), oklch(76% 0.13 25));
|
|
24
|
+
--pp-color-status-info: light-dark(oklch(47% 0.19 270.7), oklch(78% 0.1 270.7));
|
|
23
25
|
--pp-color-status-passed: light-dark(oklch(47% 0.105 155), oklch(80% 0.13 155));
|
|
24
26
|
--pp-color-status-running: light-dark(oklch(47% 0.19 270.7), oklch(78% 0.1 270.7));
|
|
25
27
|
--pp-color-surface: light-dark(oklch(95.8% 0.007 270.7), oklch(25% 0.014 270.7));
|
|
@@ -61,6 +63,7 @@
|
|
|
61
63
|
--pp-size-focus-width: 2px;
|
|
62
64
|
--pp-size-measure: 36rem;
|
|
63
65
|
--pp-size-page: 72rem;
|
|
66
|
+
--pp-size-prose: 36rem;
|
|
64
67
|
--pp-size-rule: 1px;
|
|
65
68
|
--pp-size-target-min: 1.5rem;
|
|
66
69
|
--pp-space-2xl: 4rem;
|
package/generated/tokens.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type TokenName =
|
|
|
7
7
|
| '--pp-chart-5'
|
|
8
8
|
| '--pp-chart-6'
|
|
9
9
|
| '--pp-color-accent'
|
|
10
|
+
| '--pp-color-accent-text'
|
|
10
11
|
| '--pp-color-bg'
|
|
11
12
|
| '--pp-color-control'
|
|
12
13
|
| '--pp-color-fg'
|
|
@@ -17,6 +18,7 @@ export type TokenName =
|
|
|
17
18
|
| '--pp-color-on-accent'
|
|
18
19
|
| '--pp-color-status-degraded'
|
|
19
20
|
| '--pp-color-status-failed'
|
|
21
|
+
| '--pp-color-status-info'
|
|
20
22
|
| '--pp-color-status-passed'
|
|
21
23
|
| '--pp-color-status-running'
|
|
22
24
|
| '--pp-color-surface'
|
|
@@ -56,6 +58,7 @@ export type TokenName =
|
|
|
56
58
|
| '--pp-size-focus-width'
|
|
57
59
|
| '--pp-size-measure'
|
|
58
60
|
| '--pp-size-page'
|
|
61
|
+
| '--pp-size-prose'
|
|
59
62
|
| '--pp-size-rule'
|
|
60
63
|
| '--pp-size-target-min'
|
|
61
64
|
| '--pp-space-2xl'
|
package/generated/tokens.json
CHANGED
|
@@ -29,6 +29,10 @@
|
|
|
29
29
|
"oklch": "oklch(47% 0.19 270.7)",
|
|
30
30
|
"hex": "#3749c3"
|
|
31
31
|
},
|
|
32
|
+
"--pp-color-accent-text": {
|
|
33
|
+
"oklch": "oklch(47% 0.19 270.7)",
|
|
34
|
+
"hex": "#3749c3"
|
|
35
|
+
},
|
|
32
36
|
"--pp-color-bg": {
|
|
33
37
|
"oklch": "oklch(98.5% 0.004 270.7)",
|
|
34
38
|
"hex": "#f9fafd"
|
|
@@ -69,6 +73,10 @@
|
|
|
69
73
|
"oklch": "oklch(50% 0.17 25)",
|
|
70
74
|
"hex": "#b02a2d"
|
|
71
75
|
},
|
|
76
|
+
"--pp-color-status-info": {
|
|
77
|
+
"oklch": "oklch(47% 0.19 270.7)",
|
|
78
|
+
"hex": "#3749c3"
|
|
79
|
+
},
|
|
72
80
|
"--pp-color-status-passed": {
|
|
73
81
|
"oklch": "oklch(47% 0.105 155)",
|
|
74
82
|
"hex": "#196c40"
|
|
@@ -111,6 +119,10 @@
|
|
|
111
119
|
"oklch": "oklch(78% 0.1 270.7)",
|
|
112
120
|
"hex": "#9fb4f8"
|
|
113
121
|
},
|
|
122
|
+
"--pp-color-accent-text": {
|
|
123
|
+
"oklch": "oklch(78% 0.1 270.7)",
|
|
124
|
+
"hex": "#9fb4f8"
|
|
125
|
+
},
|
|
114
126
|
"--pp-color-bg": {
|
|
115
127
|
"oklch": "oklch(20.1% 0.0124 270.7)",
|
|
116
128
|
"hex": "#14161c"
|
|
@@ -151,6 +163,10 @@
|
|
|
151
163
|
"oklch": "oklch(76% 0.13 25)",
|
|
152
164
|
"hex": "#f98f87"
|
|
153
165
|
},
|
|
166
|
+
"--pp-color-status-info": {
|
|
167
|
+
"oklch": "oklch(78% 0.1 270.7)",
|
|
168
|
+
"hex": "#9fb4f8"
|
|
169
|
+
},
|
|
154
170
|
"--pp-color-status-passed": {
|
|
155
171
|
"oklch": "oklch(80% 0.13 155)",
|
|
156
172
|
"hex": "#72d699"
|
|
@@ -202,6 +218,7 @@
|
|
|
202
218
|
"--pp-size-focus-width": "2px",
|
|
203
219
|
"--pp-size-measure": "36rem",
|
|
204
220
|
"--pp-size-page": "72rem",
|
|
221
|
+
"--pp-size-prose": "36rem",
|
|
205
222
|
"--pp-size-rule": "1px",
|
|
206
223
|
"--pp-size-target-min": "1.5rem",
|
|
207
224
|
"--pp-space-2xl": "4rem",
|
package/package.json
CHANGED