@polyfen/polykit-tokens 0.0.0-stage → 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.
@@ -0,0 +1,417 @@
1
+ /**
2
+ * Color pairs that scripts/check-contrast.mjs measures, per theme.
3
+ *
4
+ * fg and bg are token keys (color.ink, palette.slate.700). kind decides the minimum ratio:
5
+ * text 4.5:1 (WCAG 1.4.3)
6
+ * graphic 3:1 (WCAG 1.4.11): icons, shapes, focus rings, control edges
7
+ * canvas: 'neutral' measures the pair on the cool slate canvas (data-canvas="neutral").
8
+ *
9
+ * A pair that fails on purpose carries an exception for that theme, with the reason. An
10
+ * exception on a pair that now passes is an error, so this list cannot go stale.
11
+ */
12
+
13
+ const BOTH = ['light', 'dark'];
14
+
15
+ export const EXCEPTIONS = {
16
+ controlBorder: {
17
+ ref: 'PLAN O5',
18
+ reason:
19
+ 'Form-control borders match the reference design, below 3:1 on light surfaces. Override --pk-color-border-control with slate 400 (3.62:1) for strict AA; see strict-control-border.',
20
+ },
21
+ roundCheckEdge: {
22
+ ref: 'PLAN O5',
23
+ reason:
24
+ 'The round check keeps the reference design 2px border-strong ring, 2.30:1 on light surfaces. The tick and the solid success fill carry the state, and the button always has a name. Same decision as the control borders (O5): a strict project would darken --pk-color-border-strong, or the checkbox edge (glyph-neutral, 3.62:1) is the model.',
25
+ },
26
+ switchOff: {
27
+ ref: 'PLAN O5',
28
+ reason:
29
+ 'The switch keeps the reference design border-strong track and white thumb in its off state: 2.30:1 between them in the light theme. The thumb position and the track turning ink when on carry the state, and the switch always has a name. Same decision as the control borders (O5); a strict project would darken --pk-color-border-strong.',
30
+ },
31
+ accentShape: {
32
+ ref: 'PRINCIPLES 4',
33
+ reason:
34
+ 'Orange is a shape or indicator on light surfaces, never text, and always paired with a second cue such as weight, ink or fill.',
35
+ },
36
+ fieldFocus: {
37
+ ref: 'PLAN O5',
38
+ reason:
39
+ 'Form fields keep the reference design accent focus ring (below 3:1 on light surfaces). Strict projects use --pk-color-focus, which passes.',
40
+ },
41
+ tabFocus: {
42
+ ref: 'PLAN 7.3',
43
+ reason:
44
+ 'Tabs keep the reference design accent focus ring, below 3:1 on the light canvas. Strict projects set --pk-color-focus-field to the focus color, which passes.',
45
+ },
46
+ statusShape: {
47
+ ref: 'PRINCIPLES 3, 4',
48
+ reason:
49
+ 'Success green is a shape on light surfaces; the word or success-ink text carries the meaning.',
50
+ },
51
+ warningDot: {
52
+ ref: 'PRINCIPLES 3',
53
+ reason: 'The attention dot is decorative; the adjacent text states what needs attention.',
54
+ },
55
+ monogramLetter: {
56
+ ref: 'PLAN 7.5',
57
+ reason:
58
+ 'The monogram letter is the first letter of a name that is always written out beside it, and the monogram is aria-hidden. White on the lighter categorical hues is 3.4 to 4.4:1, below 4.5:1. The plan fixes the hues (at least 3:1 as shapes); the soft text shadow helps the letter read but does not change the measurement.',
59
+ },
60
+ tileIcon: {
61
+ ref: 'PLAN 7.5',
62
+ reason:
63
+ 'The icon tile draws the hue over a tint of itself (14% in light, 22% in dark; 16% for the small tile), which leaves green and teal (and amber, on the small tile) just under 3:1 in the light theme, and indigo, purple and gray just under it on the warm dark surface. The icon is decoration: the category is always named in text beside it.',
64
+ },
65
+ selectedTint: {
66
+ ref: 'PRINCIPLES 3',
67
+ reason:
68
+ 'On the accent tint of a selected row or a pressed stat tile, a few shape colors (danger red, accent orange, warning, medium priority, and the teal row bar) are just under 3:1 in the light theme. Each is paired with text that says the same thing: the priority label, the status word, the stat label, the category name.',
69
+ },
70
+ doneStrike: {
71
+ ref: 'PLAN 7.5',
72
+ reason:
73
+ 'The line through a done row title is border-strong on the surface, 2.30:1 in the light theme. The title also turns muted, and a done row carries a status word (such as a Done pill) for anyone who cannot see the line.',
74
+ },
75
+ provisionalChart: {
76
+ ref: 'PLAN v3',
77
+ reason: 'Provisional chart palette, revisited with the data-viz work.',
78
+ },
79
+ };
80
+
81
+ const text = (fg, bg, extra = {}) => ({ fg, bg, kind: 'text', themes: BOTH, ...extra });
82
+ const graphic = (fg, bg, extra = {}) => ({ fg, bg, kind: 'graphic', themes: BOTH, ...extra });
83
+ const color = (name) => `color.${name}`;
84
+
85
+ const SURFACES = ['canvas', 'surface', 'sunken', 'hover'];
86
+ const BOTH_EXCEPT = (reason) => ({ light: reason, dark: reason });
87
+ const SELECTED_TINT_FAILS = ['danger', 'accent', 'warning'];
88
+ const CATEGORIES = ['rose', 'green', 'indigo', 'sky', 'purple', 'amber', 'teal', 'gray'];
89
+
90
+ const BADGE_TONES = [
91
+ 'neutral',
92
+ 'accent',
93
+ 'secondary',
94
+ 'success',
95
+ 'danger',
96
+ 'info',
97
+ 'purple',
98
+ 'magenta',
99
+ ];
100
+
101
+ /** Hues whose white monogram letter is under 4.5:1 (the rest pass). Listed so a change is noticed. */
102
+ const MONOGRAM_FAILS = ['rose', 'green', 'sky', 'amber', 'teal'];
103
+ const TILE_FAILS_LIGHT = { tint: ['green', 'teal'], small: ['green', 'teal', 'amber'] };
104
+ /** On the warm dark surface the 22% tint is a little lighter, so these sit just under 3:1. */
105
+ const TILE_FAILS_DARK = { tint: ['indigo', 'purple', 'gray'], small: [] };
106
+
107
+ /** A hue as the icon tile paints it: over a tint of itself on the surface. */
108
+ const tile = (name, share, light = [], dark = []) => {
109
+ const exceptions = {
110
+ ...(light.includes(name) ? { light: EXCEPTIONS.tileIcon } : {}),
111
+ ...(dark.includes(name) ? { dark: EXCEPTIONS.tileIcon } : {}),
112
+ };
113
+ const excused = Object.keys(exceptions).length > 0;
114
+ return graphic(color(`cat-${name}`), color('surface'), {
115
+ mix: { color: color(`cat-${name}`), over: color('surface'), share },
116
+ group: excused ? 'Exceptions' : 'Graphics',
117
+ label: `${name} icon tile${share === 'tint' ? '' : ' (small)'}`,
118
+ exceptions: excused ? exceptions : undefined,
119
+ });
120
+ };
121
+
122
+ export const pairs = [
123
+ // Body text on every surface
124
+ ...['ink', 'ink-secondary', 'ink-muted'].flatMap((fg) =>
125
+ SURFACES.map((bg) => text(color(fg), color(bg), { group: 'Text' })),
126
+ ),
127
+ text(color('ink'), color('accent-tint'), { group: 'Text' }),
128
+ text(color('ink-inverse'), color('ink'), { group: 'Text' }),
129
+
130
+ // Status text
131
+ text(color('danger-ink'), color('canvas'), { group: 'Text' }),
132
+ text(color('danger-ink'), color('surface'), { group: 'Text' }),
133
+ text(color('danger-ink'), color('danger-tint'), { group: 'Text' }),
134
+ text(color('success-ink'), color('canvas'), { group: 'Text' }),
135
+ text(color('success-ink'), color('surface'), { group: 'Text' }),
136
+ text(color('success-ink'), color('success-tint'), { group: 'Text' }),
137
+ text(color('on-accent-tint'), color('accent-tint'), { group: 'Text' }),
138
+ text(color('on-accent-tint'), color('accent-tint-strong'), { group: 'Text' }),
139
+ text(color('on-accent'), color('accent'), { group: 'Text', label: 'accent button' }),
140
+ text(color('frame-ink'), color('danger-strong'), { group: 'Text', label: 'error toast' }),
141
+ text(color('ink'), color('danger-tint'), { group: 'Text', label: 'link in a danger banner' }),
142
+ text(color('ink'), color('success-tint'), { group: 'Text', label: 'link in a success banner' }),
143
+
144
+ // The full status set (Phase 8c): warning and info text on their tints and the page, and every
145
+ // tone's text on the cool tint's page and surface
146
+ ...['warning', 'info'].flatMap((tone) => [
147
+ text(color(`${tone}-ink`), color(`${tone}-tint`), { group: 'Text' }),
148
+ text(color(`${tone}-ink`), color('surface'), { group: 'Text' }),
149
+ text(color(`${tone}-ink`), color('canvas'), { group: 'Text' }),
150
+ text(color('ink'), color(`${tone}-tint`), { group: 'Text', label: `link in a ${tone} banner` }),
151
+ ]),
152
+ ...['danger', 'success', 'warning', 'info'].flatMap((tone) =>
153
+ ['canvas', 'surface'].map((bg) =>
154
+ text(color(`${tone}-ink`), color(bg), { canvas: 'neutral', group: 'Cool tint' }),
155
+ ),
156
+ ),
157
+ // Calendar entries: text on the event and all-day tints, in both tints (overdue is the
158
+ // danger tint, measured with the status set)
159
+ ...[
160
+ ['info', 0.12, 'ink', 'calendar event'],
161
+ ['info', 0.18, 'ink', 'calendar all-day event'],
162
+ ].flatMap(([hue, share, fg, label]) =>
163
+ [undefined, 'neutral'].map((canvas) =>
164
+ text(color(fg), color('surface'), {
165
+ mix: { color: color(hue), over: color('surface'), share },
166
+ group: canvas ? 'Cool tint' : 'Text',
167
+ label,
168
+ ...(canvas ? { canvas } : {}),
169
+ }),
170
+ ),
171
+ ),
172
+
173
+ // A progress bar on its track, and the current page of a pagination
174
+ graphic(color('ink'), color('sunken'), { group: 'Graphics', label: 'progress bar on its track' }),
175
+ graphic(color('ink'), color('sunken'), {
176
+ canvas: 'neutral',
177
+ group: 'Cool tint',
178
+ label: 'progress bar on its track',
179
+ }),
180
+
181
+ // Text on a pressed control, in both tints
182
+ text(color('ink'), color('pressed'), { group: 'Text', label: 'pressed control' }),
183
+ text(color('ink'), color('pressed'), {
184
+ canvas: 'neutral',
185
+ group: 'Cool tint',
186
+ label: 'pressed control',
187
+ }),
188
+ // Placeholder and caption text: on every surface, in both tints
189
+ ...['placeholder', 'caption'].flatMap((fg) =>
190
+ SURFACES.flatMap((bg) => [
191
+ text(color(fg), color(bg), { group: 'Text' }),
192
+ text(color(fg), color(bg), { canvas: 'neutral', group: 'Cool tint' }),
193
+ ]),
194
+ ),
195
+
196
+ // The secondary accent: the primary's pairs. The default brand has no secondary, so it is
197
+ // the primary here, with the same exceptions; brands with one are measured on their own.
198
+ text(color('on-accent-secondary-tint'), color('accent-secondary-tint'), { group: 'Text' }),
199
+ text(color('on-accent-secondary-tint'), color('accent-secondary-tint-strong'), { group: 'Text' }),
200
+ text(color('on-accent-secondary'), color('accent-secondary'), {
201
+ group: 'Text',
202
+ label: 'secondary accent button',
203
+ }),
204
+ text(color('accent-secondary'), color('surface'), { themes: ['dark'], group: 'Text' }),
205
+ ...['canvas', 'surface'].map((bg) =>
206
+ graphic(color('accent-secondary'), color(bg), {
207
+ group: 'Exceptions',
208
+ exceptions: { light: EXCEPTIONS.accentShape },
209
+ }),
210
+ ),
211
+
212
+ // Dark theme: the 400 and 500 steps pass as text (PRINCIPLES 4)
213
+ text(color('accent'), color('surface'), { themes: ['dark'], group: 'Text' }),
214
+ text(color('danger'), color('surface'), { themes: ['dark'], group: 'Text' }),
215
+ text(color('success'), color('surface'), { themes: ['dark'], group: 'Text' }),
216
+
217
+ // Dark frame
218
+ text(color('frame-ink'), color('frame'), { group: 'Frame' }),
219
+ text(color('frame-muted'), color('frame'), { group: 'Frame' }),
220
+ text(color('frame-faint'), color('frame'), { group: 'Frame' }),
221
+ graphic(color('accent'), color('frame'), { group: 'Frame' }),
222
+ // The icon of a frame button (pk-button--frame), such as Chat, on its fill (rest and hover).
223
+ // Pressed, the fill is frame-active and the icon is frame-ink.
224
+ graphic(color('accent'), color('frame-hover'), { over: color('frame'), group: 'Frame' }),
225
+ text(color('frame-muted'), color('frame-hover'), { over: color('frame'), group: 'Frame' }),
226
+ text(color('frame-ink'), color('frame-hover'), { over: color('frame'), group: 'Frame' }),
227
+ text(color('frame-ink'), color('frame-active'), { over: color('frame'), group: 'Frame' }),
228
+ text(color('frame-muted'), color('frame-field-focus'), {
229
+ over: color('frame'),
230
+ group: 'Frame',
231
+ label: 'search placeholder, focused',
232
+ }),
233
+ text(color('frame-ink'), color('frame-field-focus'), {
234
+ over: color('frame'),
235
+ group: 'Frame',
236
+ label: 'search text, focused',
237
+ }),
238
+ graphic(color('frame-faint'), color('frame-hover'), {
239
+ over: color('frame'),
240
+ group: 'Frame',
241
+ label: 'search icon',
242
+ }),
243
+ graphic(color('focus-field'), color('frame'), { group: 'Frame', label: 'search focus border' }),
244
+
245
+ // Neutral slate canvas
246
+ ...['ink', 'ink-secondary', 'ink-muted'].flatMap((fg) =>
247
+ ['canvas', 'surface', 'sunken', 'hover'].map((bg) =>
248
+ text(color(fg), color(bg), { canvas: 'neutral', group: 'Cool tint' }),
249
+ ),
250
+ ),
251
+
252
+ // Code blocks: the syntax colors, on the surface, in both tints
253
+ ...['keyword', 'name', 'value'].flatMap((part) => [
254
+ text(color(`code-${part}`), color('surface'), {
255
+ group: 'Text',
256
+ label: `code highlight (${part})`,
257
+ }),
258
+ text(color(`code-${part}`), color('surface'), {
259
+ canvas: 'neutral',
260
+ group: 'Cool tint',
261
+ label: `code highlight (${part})`,
262
+ }),
263
+ ]),
264
+
265
+ // Selected rows and pressed stat tiles sit on the accent tint
266
+ text(color('ink-secondary'), color('accent-tint'), { group: 'Text' }),
267
+ text(color('ink-muted'), color('accent-tint'), { group: 'Text' }),
268
+ text(color('danger-ink'), color('accent-tint'), { group: 'Text' }),
269
+ text(color('danger-ink'), color('hover'), { group: 'Text' }), // overdue in an open row
270
+
271
+ // Badge tones: the ink on its own background, from the badge tokens
272
+ ...BADGE_TONES.map((tone) =>
273
+ text(color(`badge-${tone}-ink`), color(`badge-${tone}-bg`), {
274
+ group: 'Badges',
275
+ label: `${tone} badge`,
276
+ }),
277
+ ),
278
+
279
+ // Graphics: categorical hues and priority icons on both page surfaces
280
+ ...CATEGORIES.flatMap((name) =>
281
+ ['canvas', 'surface'].map((bg) =>
282
+ graphic(color(`cat-${name}`), color(bg), { group: 'Graphics' }),
283
+ ),
284
+ ),
285
+ ...['high', 'medium', 'low'].flatMap((name) =>
286
+ ['canvas', 'surface'].map((bg) =>
287
+ graphic(color(`priority-${name}`), color(bg), { group: 'Graphics' }),
288
+ ),
289
+ ),
290
+ graphic(color('glyph-neutral'), color('surface'), {
291
+ group: 'Graphics',
292
+ label: 'glyph-neutral (checkbox edge)',
293
+ }),
294
+ graphic(color('glyph-strong'), color('surface'), { group: 'Graphics' }),
295
+ graphic(color('ink-muted'), color('surface'), { group: 'Graphics', label: 'typing dots' }),
296
+ graphic(color('ink-muted'), color('canvas'), { group: 'Graphics', label: 'typing dots' }),
297
+ graphic(color('ink-inverse'), color('success-ink'), {
298
+ group: 'Graphics',
299
+ label: 'round check tick (pressed)',
300
+ }),
301
+ graphic(color('focus'), color('canvas'), { group: 'Graphics' }),
302
+ graphic(color('focus'), color('surface'), { group: 'Graphics' }),
303
+ graphic(color('danger'), color('surface'), { group: 'Graphics' }),
304
+ graphic(color('info'), color('surface'), { group: 'Graphics' }),
305
+ graphic('palette.slate.400', color('surface'), {
306
+ group: 'Graphics',
307
+ label: 'strict-control-border',
308
+ }),
309
+
310
+ // Monogram: the fill against the frame it sits in, and the letter on the fill
311
+ ...CATEGORIES.map((name) =>
312
+ graphic(color(`cat-${name}`), color('frame'), {
313
+ group: 'Graphics',
314
+ label: `${name} monogram on the frame`,
315
+ }),
316
+ ),
317
+ ...CATEGORIES.map((name) =>
318
+ text(color('on-category'), color(`cat-${name}`), {
319
+ group: MONOGRAM_FAILS.includes(name) ? 'Exceptions' : 'Graphics',
320
+ label: `${name} monogram letter`,
321
+ exceptions: MONOGRAM_FAILS.includes(name)
322
+ ? BOTH_EXCEPT(EXCEPTIONS.monogramLetter)
323
+ : undefined,
324
+ }),
325
+ ),
326
+
327
+ // Icon tile: each hue over its own tint, large (theme tint) and small (16%)
328
+ ...CATEGORIES.map((name) => tile(name, 'tint', TILE_FAILS_LIGHT.tint, TILE_FAILS_DARK.tint)),
329
+ ...CATEGORIES.map((name) => tile(name, 0.16, TILE_FAILS_LIGHT.small, TILE_FAILS_DARK.small)),
330
+
331
+ // Glyph tones on the surface, and everything graphic on the accent tint (selected row, pressed tile)
332
+ graphic(color('warning'), color('surface'), {
333
+ group: 'Exceptions',
334
+ label: 'warning glyph',
335
+ exceptions: { light: EXCEPTIONS.warningDot },
336
+ }),
337
+ ...['glyph-neutral', 'glyph-strong', 'danger', 'accent', 'warning'].map((name) =>
338
+ graphic(color(name), color('accent-tint'), {
339
+ group: SELECTED_TINT_FAILS.includes(name) ? 'Exceptions' : 'Graphics',
340
+ label: `${name} on the accent tint`,
341
+ exceptions: SELECTED_TINT_FAILS.includes(name)
342
+ ? { light: EXCEPTIONS.selectedTint }
343
+ : undefined,
344
+ }),
345
+ ),
346
+ ...['high', 'medium', 'low'].map((name) =>
347
+ graphic(color(`priority-${name}`), color('accent-tint'), {
348
+ group: name === 'medium' ? 'Exceptions' : 'Graphics',
349
+ label: `priority ${name} on the accent tint`,
350
+ exceptions: name === 'medium' ? { light: EXCEPTIONS.selectedTint } : undefined,
351
+ }),
352
+ ),
353
+ ...CATEGORIES.map((name) =>
354
+ graphic(color(`cat-${name}`), color('accent-tint'), {
355
+ group: name === 'teal' ? 'Exceptions' : 'Graphics',
356
+ label: `${name} row bar on the accent tint`,
357
+ exceptions: name === 'teal' ? { light: EXCEPTIONS.selectedTint } : undefined,
358
+ }),
359
+ ),
360
+ ...['high', 'medium', 'low'].map((name) =>
361
+ graphic(color(`priority-${name}`), color('hover'), {
362
+ group: 'Graphics',
363
+ label: `priority ${name} in an open row`,
364
+ }),
365
+ ),
366
+ graphic(color('border-strong'), color('surface'), {
367
+ group: 'Exceptions',
368
+ label: 'done row strike-through',
369
+ exceptions: { light: EXCEPTIONS.doneStrike },
370
+ }),
371
+
372
+ // Known deviations, each with its reason
373
+ graphic(color('border-strong'), color('surface'), {
374
+ group: 'Exceptions',
375
+ label: 'round check edge, switch track (off)',
376
+ exceptions: { light: EXCEPTIONS.roundCheckEdge },
377
+ }),
378
+ graphic(color('ink-inverse'), color('border-strong'), {
379
+ group: 'Exceptions',
380
+ label: 'switch thumb (off)',
381
+ exceptions: { light: EXCEPTIONS.switchOff },
382
+ }),
383
+ graphic(color('border-control'), color('surface'), {
384
+ group: 'Exceptions',
385
+ exceptions: { light: EXCEPTIONS.controlBorder },
386
+ }),
387
+ graphic(color('focus-field'), color('surface'), {
388
+ group: 'Exceptions',
389
+ exceptions: { light: EXCEPTIONS.fieldFocus },
390
+ }),
391
+ graphic(color('focus-field'), color('canvas'), {
392
+ group: 'Exceptions',
393
+ label: 'tab focus ring',
394
+ exceptions: { light: EXCEPTIONS.tabFocus },
395
+ }),
396
+ graphic(color('accent'), color('canvas'), {
397
+ group: 'Exceptions',
398
+ exceptions: { light: EXCEPTIONS.accentShape },
399
+ }),
400
+ graphic(color('accent'), color('surface'), {
401
+ group: 'Exceptions',
402
+ exceptions: { light: EXCEPTIONS.accentShape },
403
+ }),
404
+ graphic(color('success'), color('surface'), {
405
+ group: 'Exceptions',
406
+ exceptions: { light: EXCEPTIONS.statusShape },
407
+ }),
408
+ graphic(color('warning'), color('canvas'), {
409
+ group: 'Exceptions',
410
+ exceptions: { light: EXCEPTIONS.warningDot },
411
+ }),
412
+ graphic(color('chart-1'), color('surface'), {
413
+ group: 'Exceptions',
414
+ exceptions: { light: EXCEPTIONS.provisionalChart },
415
+ }),
416
+ ...[2, 3, 4, 5].map((n) => graphic(color(`chart-${n}`), color('surface'), { group: 'Graphics' })),
417
+ ];