@terpjs/contract 0.30.0 → 0.31.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/openapi.json +38 -0
- package/package.json +2 -2
- package/scripts/build-tokens.mjs +45 -5
- package/src/schema.d.ts +4 -0
- package/src/tokens.contrast.test.js +139 -76
- package/src/tokens.css +167 -141
- package/src/tokens.manifest.json +660 -320
- package/src/tokens.manifest.test.js +16 -2
- package/src/tokens.themes.test.js +34 -2
- package/themes.json +26 -17
- package/token-pairs.json +310 -37
- package/tokens.contrast.json +6 -2
- package/{tokens.dark.json → tokens.evening.json} +15 -11
- package/tokens.json +13 -9
- package/{tokens.midnight.json → tokens.night.json} +19 -15
- package/tokens.twilight.json +51 -47
package/openapi.json
CHANGED
|
@@ -1639,6 +1639,44 @@
|
|
|
1639
1639
|
"get": {
|
|
1640
1640
|
"operationId": "audit.list_events",
|
|
1641
1641
|
"parameters": [
|
|
1642
|
+
{
|
|
1643
|
+
"description": "Only events about records of this type -- the model's name, e.g. 'User'.",
|
|
1644
|
+
"in": "query",
|
|
1645
|
+
"name": "target_type",
|
|
1646
|
+
"required": false,
|
|
1647
|
+
"schema": {
|
|
1648
|
+
"anyOf": [
|
|
1649
|
+
{
|
|
1650
|
+
"maxLength": 128,
|
|
1651
|
+
"type": "string"
|
|
1652
|
+
},
|
|
1653
|
+
{
|
|
1654
|
+
"type": "null"
|
|
1655
|
+
}
|
|
1656
|
+
],
|
|
1657
|
+
"description": "Only events about records of this type -- the model's name, e.g. 'User'.",
|
|
1658
|
+
"title": "Target Type"
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
{
|
|
1662
|
+
"description": "Only events about the record with this id.",
|
|
1663
|
+
"in": "query",
|
|
1664
|
+
"name": "target_id",
|
|
1665
|
+
"required": false,
|
|
1666
|
+
"schema": {
|
|
1667
|
+
"anyOf": [
|
|
1668
|
+
{
|
|
1669
|
+
"maxLength": 128,
|
|
1670
|
+
"type": "string"
|
|
1671
|
+
},
|
|
1672
|
+
{
|
|
1673
|
+
"type": "null"
|
|
1674
|
+
}
|
|
1675
|
+
],
|
|
1676
|
+
"description": "Only events about the record with this id.",
|
|
1677
|
+
"title": "Target Id"
|
|
1678
|
+
}
|
|
1679
|
+
},
|
|
1642
1680
|
{
|
|
1643
1681
|
"description": "Rows to skip.",
|
|
1644
1682
|
"in": "query",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/contract",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Terp frontend contract \u2014 the OpenAPI-generated TypeScript client, design tokens, and the stack-agnostic module/route/nav + auth types.",
|
|
6
6
|
"exports": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"openapi-typescript": "^7.13.0",
|
|
25
25
|
"style-dictionary": "^5.5.5",
|
|
26
|
-
"vitest": "^5.0.
|
|
26
|
+
"vitest": "^5.0.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"openapi-fetch": "^0.17.0",
|
package/scripts/build-tokens.mjs
CHANGED
|
@@ -48,6 +48,24 @@ const AA_NORMAL_TEXT = 4.5;
|
|
|
48
48
|
*/
|
|
49
49
|
const UI_COMPONENT = 3;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* The APCA lightness contrast (Lc) each way of reading a text pairing must reach, beside the
|
|
53
|
+
* WCAG ratio rather than instead of it (ADR 0170). WCAG 2's ratio flatters light text on a dark
|
|
54
|
+
* ground, so a dark theme can pass AA everywhere and still set its secondary text at a level
|
|
55
|
+
* APCA rates as hard to read; Lc is measured the way a reader perceives it in both polarities.
|
|
56
|
+
*
|
|
57
|
+
* Published with the algorithm's version because an Lc means nothing without its constants:
|
|
58
|
+
* a consumer measuring with another APCA build would hold the same palette to different
|
|
59
|
+
* numbers. The floors are APCA's own levels: 90 its preferred level for fluent text, 75 its
|
|
60
|
+
* minimum for body text, 60 its minimum for content text that is not read as body text, which
|
|
61
|
+
* is how this sheet reads a count or a position. Every theme is held to them, the
|
|
62
|
+
* high-contrast one included, because the reading belongs to the text and not to the palette.
|
|
63
|
+
*/
|
|
64
|
+
const APCA = {
|
|
65
|
+
version: "0.0.98G-4g",
|
|
66
|
+
minimumLc: { body: 90, secondary: 75, incidental: 60 },
|
|
67
|
+
};
|
|
68
|
+
|
|
51
69
|
const registry = read("themes.json");
|
|
52
70
|
const themes = registry.themes;
|
|
53
71
|
const base = themes.find((theme) => theme.name === registry.base);
|
|
@@ -63,9 +81,24 @@ if (!themes.some((theme) => theme.name === registry.systemDark)) {
|
|
|
63
81
|
if (registry.systemDark === registry.base) {
|
|
64
82
|
throw new Error("themes.json: systemDark must not be the base theme");
|
|
65
83
|
}
|
|
84
|
+
// Every name a theme answers to: its own, then the names it had before a rename. An alias is a
|
|
85
|
+
// data-theme value like any other, so it must be one, and no two themes may claim one name --
|
|
86
|
+
// the selector would then paint whichever block came last.
|
|
87
|
+
const namesOf = (theme) => [theme.name, ...(theme.aliases ?? [])];
|
|
88
|
+
const claimed = new Map();
|
|
89
|
+
for (const theme of themes) {
|
|
90
|
+
for (const name of namesOf(theme)) {
|
|
91
|
+
if (claimed.has(name)) {
|
|
92
|
+
throw new Error(`themes.json: "${name}" names both ${claimed.get(name)} and ${theme.name}`);
|
|
93
|
+
}
|
|
94
|
+
claimed.set(name, theme.name);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
66
97
|
for (const theme of themes) {
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
for (const name of namesOf(theme)) {
|
|
99
|
+
if (!/^[a-z][a-z0-9-]*$/.test(name)) {
|
|
100
|
+
throw new Error(`themes.json: "${name}" is not usable as a data-theme value`);
|
|
101
|
+
}
|
|
69
102
|
}
|
|
70
103
|
if (theme.appearance !== "light" && theme.appearance !== "dark") {
|
|
71
104
|
throw new Error(`themes.json: ${theme.name} appearance must be "light" or "dark"`);
|
|
@@ -142,9 +175,11 @@ const appearanceSwitch = (appearance) =>
|
|
|
142
175
|
const themeBlocks = overlays
|
|
143
176
|
.map(
|
|
144
177
|
(theme) => `
|
|
145
|
-
/* ${theme.label}: an explicit choice via <html data-theme="${theme.name}"
|
|
178
|
+
/* ${theme.label}: an explicit choice via <html data-theme="${theme.name}">${
|
|
179
|
+
theme.aliases?.length ? `, or its earlier name${theme.aliases.length > 1 ? "s" : ""} ${theme.aliases.map((alias) => `"${alias}"`).join(", ")}` : ""
|
|
180
|
+
}.
|
|
146
181
|
${theme.description} */
|
|
147
|
-
[data-theme='${
|
|
182
|
+
${namesOf(theme).map((name) => `[data-theme='${name}']`).join(",\n")} {
|
|
148
183
|
color-scheme: ${theme.appearance};
|
|
149
184
|
${appearanceSwitch(theme.appearance)}
|
|
150
185
|
${compiled.get(theme.name)}
|
|
@@ -233,9 +268,12 @@ const manifest = {
|
|
|
233
268
|
// alone rather than hard-coding the list it happens to know about.
|
|
234
269
|
base: registry.base,
|
|
235
270
|
systemDark: registry.systemDark,
|
|
236
|
-
themes: themes.map(({ name, label, appearance, description, minimumContrast }) => ({
|
|
271
|
+
themes: themes.map(({ name, label, appearance, description, minimumContrast, aliases }) => ({
|
|
237
272
|
name,
|
|
238
273
|
label,
|
|
274
|
+
// The names this theme had before a rename. Accept them wherever a theme is named, and map
|
|
275
|
+
// them to `name`; the stylesheet already paints them as this theme.
|
|
276
|
+
aliases: aliases ?? [],
|
|
239
277
|
appearance,
|
|
240
278
|
description,
|
|
241
279
|
// The ratio this theme's declared text pairings must reach, published as a NUMBER on every
|
|
@@ -264,6 +302,8 @@ const manifest = {
|
|
|
264
302
|
// The floor for the `nonTextPairs` section below — flat across themes, unlike the per-theme
|
|
265
303
|
// text floor above. Named at the top level so the two sections cannot be read as sharing a bar.
|
|
266
304
|
nonTextMinimumContrast: UI_COMPONENT,
|
|
305
|
+
// The second bar a text pairing is held to, keyed by the `reading` each pairing declares.
|
|
306
|
+
apca: APCA,
|
|
267
307
|
textPairs: pairs.textPairs,
|
|
268
308
|
// Both sections, because a consumer that can only see the text pairings would read the
|
|
269
309
|
// absence of a boundary pairing as "no requirement" rather than "held elsewhere".
|
package/src/schema.d.ts
CHANGED
|
@@ -1225,6 +1225,10 @@ export interface operations {
|
|
|
1225
1225
|
"audit.list_events": {
|
|
1226
1226
|
parameters: {
|
|
1227
1227
|
query?: {
|
|
1228
|
+
/** @description Only events about records of this type -- the model's name, e.g. 'User'. */
|
|
1229
|
+
target_type?: string | null;
|
|
1230
|
+
/** @description Only events about the record with this id. */
|
|
1231
|
+
target_id?: string | null;
|
|
1228
1232
|
/** @description Rows to skip. */
|
|
1229
1233
|
skip?: number;
|
|
1230
1234
|
/** @description Maximum rows to return. */
|
|
@@ -13,9 +13,10 @@ import { parseRules } from "./css-rules.js";
|
|
|
13
13
|
// checks spelling, the theme test checks completeness, and neither knows that
|
|
14
14
|
// `--color-status-warning` is only ever painted on `--color-status-warning-soft`.
|
|
15
15
|
//
|
|
16
|
-
// So the pairings are declared here, as data, and held to WCAG 2.1 contrast
|
|
17
|
-
//
|
|
18
|
-
//
|
|
16
|
+
// So the pairings are declared here, as data, and held to WCAG 2.1 contrast — and the text
|
|
17
|
+
// pairings to APCA lightness contrast as well, at the level their reading asks for (ADR 0170).
|
|
18
|
+
// Each entry is a pairing some framework component actually renders; decorative boundaries
|
|
19
|
+
// are deliberately absent, because WCAG sets no ratio for a divider and asserting one would
|
|
19
20
|
// only teach the next reader to ignore this file.
|
|
20
21
|
|
|
21
22
|
const here = (name) => fileURLToPath(new URL(name, import.meta.url));
|
|
@@ -107,43 +108,27 @@ const NON_TEXT_PAIRS = PAIRS.nonTextPairs;
|
|
|
107
108
|
const BELOW_AA = new Map([]);
|
|
108
109
|
|
|
109
110
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* fixed: the fix is the token value, and moving it repaints every bordered control in the
|
|
120
|
-
* package, which is a decision about how the framework looks and not a side effect of adding a
|
|
121
|
-
* gate. The contrast theme already clears it at 10.37, which is what shows the fix is a value
|
|
122
|
-
* and not a structure.
|
|
123
|
-
*
|
|
124
|
-
* Unlike {@link BELOW_AA} the entries are not confined to the themes that predate the gate, and
|
|
125
|
-
* pretending otherwise would be the dishonest option — every palette inherited the same
|
|
126
|
-
* 300-step boundary, so the defect is one token's value seen five times rather than five
|
|
127
|
-
* independent mistakes. The guard below is therefore different in kind: the allowance may name
|
|
128
|
-
* only the control-boundary pairings. A new pairing cannot be added to it at all.
|
|
111
|
+
* The APCA build {@link apcaContrast} implements, which the manifest must name: an Lc floor is
|
|
112
|
+
* only a number under the constants it was measured with, so a manifest that moved to another
|
|
113
|
+
* build would be publishing floors this gate no longer measures.
|
|
114
|
+
*/
|
|
115
|
+
const APCA_VERSION = "0.0.98G-4g";
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The Lc each way of reading a text pairing must reach, read from the MANIFEST for the reason
|
|
119
|
+
* {@link floorFor} gives: the published floor and the enforced floor are one number.
|
|
129
120
|
*/
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
["midnight/control-boundary-on-surface", 1.5506],
|
|
137
|
-
["twilight/control-boundary-on-canvas", 1.982],
|
|
138
|
-
["twilight/control-boundary-on-surface", 1.7807],
|
|
139
|
-
]);
|
|
140
|
-
|
|
141
|
-
/** The only pairings {@link BELOW_UI} is allowed to name. */
|
|
142
|
-
const CONTROL_BOUNDARY_IDS = ["control-boundary-on-canvas", "control-boundary-on-surface"];
|
|
143
|
-
|
|
144
|
-
/** The declarations of the one rule whose selector is exactly `selector`. */
|
|
121
|
+
const MINIMUM_LC = manifest.apca.minimumLc;
|
|
122
|
+
|
|
123
|
+
/** The ordered steps of the neutral ramp: 0 and 50 are the surface and the canvas, not steps. */
|
|
124
|
+
const RAMP_STEPS = [100, 200, 300, 400, 500, 600, 700, 800, 900];
|
|
125
|
+
|
|
126
|
+
/** The declarations of the one rule whose selector list names `selector`. */
|
|
145
127
|
function declarationsFor(selector) {
|
|
146
|
-
const matches = parseRules(tokensCss).filter((rule) =>
|
|
128
|
+
const matches = parseRules(tokensCss).filter((rule) =>
|
|
129
|
+
// A renamed theme's rule lists its earlier names beside its own (themes.json aliases).
|
|
130
|
+
rule.selector.split(",").map((part) => part.trim()).includes(selector),
|
|
131
|
+
);
|
|
147
132
|
if (matches.length !== 1) {
|
|
148
133
|
throw new Error(
|
|
149
134
|
`expected exactly one \`${selector}\` rule in tokens.css, found ${matches.length}`,
|
|
@@ -172,13 +157,16 @@ function linearise(channel) {
|
|
|
172
157
|
return scaled <= 0.04045 ? scaled / 12.92 : ((scaled + 0.055) / 1.055) ** 2.4;
|
|
173
158
|
}
|
|
174
159
|
|
|
175
|
-
/**
|
|
176
|
-
function
|
|
160
|
+
/** The red, green and blue channels of a `#rrggbb` value, 0 – 255. */
|
|
161
|
+
function channels(hex) {
|
|
177
162
|
const match = /^#([0-9a-f]{6})$/i.exec(hex);
|
|
178
163
|
if (!match) throw new Error(`not a six-digit hex colour: ${hex}`);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
164
|
+
return [0, 2, 4].map((offset) => Number.parseInt(match[1].slice(offset, offset + 2), 16));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Relative luminance of a `#rrggbb` value. */
|
|
168
|
+
function relativeLuminance(hex) {
|
|
169
|
+
const [red, green, blue] = channels(hex).map(linearise);
|
|
182
170
|
return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
|
|
183
171
|
}
|
|
184
172
|
|
|
@@ -190,6 +178,32 @@ function contrastRatio(a, b) {
|
|
|
190
178
|
return (lighter + 0.05) / (darker + 0.05);
|
|
191
179
|
}
|
|
192
180
|
|
|
181
|
+
/**
|
|
182
|
+
* APCA lightness contrast (Lc) of `text` on `background`, by the APCA-W3 0.0.98G-4g constants.
|
|
183
|
+
*
|
|
184
|
+
* Unlike the WCAG ratio it is not symmetric: dark text on a light ground is measured with one
|
|
185
|
+
* pair of exponents and light text on a dark ground with another, which is what lets it rate
|
|
186
|
+
* light-on-dark the way it reads instead of flattering it. Positive for dark text on light,
|
|
187
|
+
* negative for light text on dark; a floor is held against the magnitude. Near-black is
|
|
188
|
+
* soft-clamped before the exponents, and a result under the low clip reads as no contrast.
|
|
189
|
+
*/
|
|
190
|
+
function apcaContrast(text, background) {
|
|
191
|
+
const luminance = (hex) => {
|
|
192
|
+
const [red, green, blue] = channels(hex).map((channel) => (channel / 255) ** 2.4);
|
|
193
|
+
const y = 0.2126729 * red + 0.7151522 * green + 0.072175 * blue;
|
|
194
|
+
return y > 0.022 ? y : y + (0.022 - y) ** 1.414;
|
|
195
|
+
};
|
|
196
|
+
const textY = luminance(text);
|
|
197
|
+
const backgroundY = luminance(background);
|
|
198
|
+
if (Math.abs(backgroundY - textY) < 0.0005) return 0;
|
|
199
|
+
if (backgroundY > textY) {
|
|
200
|
+
const sapc = (backgroundY ** 0.56 - textY ** 0.57) * 1.14;
|
|
201
|
+
return sapc < 0.1 ? 0 : (sapc - 0.027) * 100;
|
|
202
|
+
}
|
|
203
|
+
const sapc = (backgroundY ** 0.65 - textY ** 0.62) * 1.14;
|
|
204
|
+
return sapc > -0.1 ? 0 : (sapc + 0.027) * 100;
|
|
205
|
+
}
|
|
206
|
+
|
|
193
207
|
/**
|
|
194
208
|
* The ratio a theme's pairings must reach — read from the MANIFEST, not from `themes.json`.
|
|
195
209
|
*
|
|
@@ -225,7 +239,7 @@ const casesFor = (list, floorOf) =>
|
|
|
225
239
|
/** Every text pairing, in every registered theme, tagged with its `BELOW_AA` key. */
|
|
226
240
|
const cases = casesFor(TEXT_PAIRS, floorFor);
|
|
227
241
|
|
|
228
|
-
/** The measured ratio for one case, with the painted values for the failure message. */
|
|
242
|
+
/** The measured ratio and Lc for one case, with the painted values for the failure message. */
|
|
229
243
|
function measure({ fg, bg, declarations }) {
|
|
230
244
|
const foreground = declarations.get(fg);
|
|
231
245
|
const background = declarations.get(bg);
|
|
@@ -233,6 +247,7 @@ function measure({ fg, bg, declarations }) {
|
|
|
233
247
|
expect(background, `${bg} is not declared`).toBeDefined();
|
|
234
248
|
return {
|
|
235
249
|
ratio: contrastRatio(foreground, background),
|
|
250
|
+
lc: apcaContrast(foreground, background),
|
|
236
251
|
painted: `${fg} (${foreground}) on ${bg} (${background})`,
|
|
237
252
|
};
|
|
238
253
|
}
|
|
@@ -240,10 +255,11 @@ function measure({ fg, bg, declarations }) {
|
|
|
240
255
|
const meetsAa = cases.filter(({ key }) => !BELOW_AA.has(key));
|
|
241
256
|
const knownGaps = cases.filter(({ key }) => BELOW_AA.has(key));
|
|
242
257
|
|
|
243
|
-
/** The same
|
|
258
|
+
/** The same text cases, tagged with the Lc their reading asks for. No ratchet: none falls short. */
|
|
259
|
+
const lcCases = cases.map((testCase) => ({ ...testCase, minimumLc: MINIMUM_LC[testCase.reading] }));
|
|
260
|
+
|
|
261
|
+
/** The non-text section. Its bar is flat, so every floor is the same. */
|
|
244
262
|
const uiCases = casesFor(NON_TEXT_PAIRS, () => UI_COMPONENT);
|
|
245
|
-
const meetsUi = uiCases.filter(({ key }) => !BELOW_UI.has(key));
|
|
246
|
-
const uiGaps = uiCases.filter(({ key }) => BELOW_UI.has(key));
|
|
247
263
|
|
|
248
264
|
describe("token sheet text contrast", () => {
|
|
249
265
|
it("measures a known ratio correctly", () => {
|
|
@@ -255,6 +271,40 @@ describe("token sheet text contrast", () => {
|
|
|
255
271
|
expect(contrastRatio("#767676", "#ffffff")).toBeCloseTo(4.5422, 4);
|
|
256
272
|
});
|
|
257
273
|
|
|
274
|
+
it("measures a known lightness contrast correctly", () => {
|
|
275
|
+
// The reference values APCA publishes for this build, so each constant is pinned by a case
|
|
276
|
+
// that moves when it does: both polarities, the soft clamp near black (#000, #123), and the
|
|
277
|
+
// low clip that reads a faint difference as none at all.
|
|
278
|
+
expect(apcaContrast("#888888", "#ffffff")).toBeCloseTo(63.056469930209424, 10);
|
|
279
|
+
expect(apcaContrast("#ffffff", "#888888")).toBeCloseTo(-68.54146436644962, 10);
|
|
280
|
+
expect(apcaContrast("#000000", "#aaaaaa")).toBeCloseTo(58.146262578561334, 10);
|
|
281
|
+
expect(apcaContrast("#aaaaaa", "#000000")).toBeCloseTo(-56.24113336839742, 10);
|
|
282
|
+
expect(apcaContrast("#112233", "#ddeeff")).toBeCloseTo(91.66830811481631, 10);
|
|
283
|
+
expect(apcaContrast("#ddeeff", "#112233")).toBeCloseTo(-93.06770049484275, 10);
|
|
284
|
+
expect(apcaContrast("#112233", "#444444")).toBeCloseTo(8.32326136957393, 10);
|
|
285
|
+
expect(apcaContrast("#444444", "#112233")).toBeCloseTo(-7.526878460278154, 10);
|
|
286
|
+
expect(apcaContrast("#fafafa", "#ffffff")).toBe(0);
|
|
287
|
+
expect(apcaContrast("#ffffff", "#fafafa")).toBe(0);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("measures with the APCA build the manifest names", () => {
|
|
291
|
+
expect(manifest.apca.version).toBe(APCA_VERSION);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("says how every text pairing is read, in a reading the manifest publishes a floor for", () => {
|
|
295
|
+
// A pairing without a reading would be held to WCAG alone, which is the model that let the
|
|
296
|
+
// dark themes' secondary text through at Lc 41 — so a missing or misspelt reading fails here
|
|
297
|
+
// rather than quietly measuring against an undefined floor.
|
|
298
|
+
const readings = Object.keys(MINIMUM_LC);
|
|
299
|
+
expect(
|
|
300
|
+
TEXT_PAIRS.filter((pair) => !readings.includes(pair.reading)).map((pair) => pair.id),
|
|
301
|
+
).toEqual([]);
|
|
302
|
+
// And every reading is used, so the manifest never publishes a floor nothing is held to.
|
|
303
|
+
expect(
|
|
304
|
+
readings.filter((reading) => !TEXT_PAIRS.some((pair) => pair.reading === reading)),
|
|
305
|
+
).toEqual([]);
|
|
306
|
+
});
|
|
307
|
+
|
|
258
308
|
it("gives every pairing a unique id, across both sections", () => {
|
|
259
309
|
// The id is the ratchet key and the manifest's handle. A duplicate would silently make
|
|
260
310
|
// one pairing's allowance apply to another, and labels cannot substitute — they repeat
|
|
@@ -283,7 +333,8 @@ describe("token sheet text contrast", () => {
|
|
|
283
333
|
// A theme authored against this gate has no reason to land below AA, so an allowance for a
|
|
284
334
|
// newer theme would be a design mistake being recorded as history. Naming the two
|
|
285
335
|
// grandfathered themes explicitly is what stops the table from becoming a general amnesty.
|
|
286
|
-
|
|
336
|
+
// midday and evening are light and dark renamed (themes.json `aliases`), not new themes.
|
|
337
|
+
const grandfathered = new Set(["midday", "evening"]);
|
|
287
338
|
const themeOf = (key) => key.slice(0, key.indexOf("/"));
|
|
288
339
|
expect([...BELOW_AA.keys()].filter((key) => !grandfathered.has(themeOf(key)))).toEqual([]);
|
|
289
340
|
});
|
|
@@ -303,6 +354,11 @@ describe("token sheet text contrast", () => {
|
|
|
303
354
|
expect(ratio, painted).toBeGreaterThanOrEqual(testCase.floor);
|
|
304
355
|
});
|
|
305
356
|
|
|
357
|
+
it.each(lcCases)("$theme: $id ($label) reads at Lc $minimumLc as $reading text", (testCase) => {
|
|
358
|
+
const { lc, painted } = measure(testCase);
|
|
359
|
+
expect(Math.abs(lc), painted).toBeGreaterThanOrEqual(testCase.minimumLc);
|
|
360
|
+
});
|
|
361
|
+
|
|
306
362
|
it("holds the high-contrast theme to AAA rather than AA", () => {
|
|
307
363
|
// A theme called "high contrast" that only cleared the same bar as every other theme would
|
|
308
364
|
// be a name doing the work a measurement should. The floor is declared per theme in
|
|
@@ -369,38 +425,45 @@ describe("token sheet non-text contrast", () => {
|
|
|
369
425
|
expect(uiCases).toHaveLength(registry.themes.length * NON_TEXT_PAIRS.length);
|
|
370
426
|
});
|
|
371
427
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
expect([...BELOW_UI.keys()]).toEqual([...BELOW_UI.keys()].sort());
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it("lets the allowance name the control boundary and nothing else", () => {
|
|
381
|
-
// The one guard that keeps this from becoming a general amnesty. BELOW_AA restricts its
|
|
382
|
-
// allowance by THEME, which works there because a new theme has no excuse to ship below AA.
|
|
383
|
-
// That reasoning does not transfer: this defect is one token value that every palette
|
|
384
|
-
// inherited, so it shows up in themes that postdate the gate through no fault of their own.
|
|
385
|
-
// Restricting by PAIRING instead says the same thing the theme rule says — no new debt —
|
|
386
|
-
// without pretending the existing debt is older than it is.
|
|
387
|
-
const idOf = (key) => key.slice(key.indexOf("/") + 1);
|
|
388
|
-
expect([...BELOW_UI.keys()].filter((key) => !CONTROL_BOUNDARY_IDS.includes(idOf(key)))).toEqual(
|
|
389
|
-
[],
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it.each(meetsUi)("$theme: $id ($label) reaches $floor:1 as a non-text pairing", (testCase) => {
|
|
428
|
+
// No allowance table, unlike the text suite. This one held the control outline at its
|
|
429
|
+
// measured floors until the outline moved onto its own token at 3:1 (ADR 0170), and those two
|
|
430
|
+
// pairings were the only ones it was allowed to name — so with them paid, a non-text pairing
|
|
431
|
+
// below the bar is a failure rather than a gap to record.
|
|
432
|
+
it.each(uiCases)("$theme: $id ($label) reaches $floor:1 as a non-text pairing", (testCase) => {
|
|
394
433
|
const { ratio, painted } = measure(testCase);
|
|
395
434
|
expect(ratio, painted).toBeGreaterThanOrEqual(testCase.floor);
|
|
396
435
|
});
|
|
436
|
+
});
|
|
397
437
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
438
|
+
describe("token sheet neutral ramp", () => {
|
|
439
|
+
// The steps are read as an order: disabled ink short of the label it disables, a field's label
|
|
440
|
+
// past the hint under it, a scrollbar's hover past its rest. A value moved for contrast on its
|
|
441
|
+
// own can land past its neighbour and invert those without a single pairing failing, which is
|
|
442
|
+
// what the first draft of ADR 0170's palette did in three of the four themes it moved.
|
|
443
|
+
// Measured from 100 because 0 and 50 are the surface and the canvas, whose order is the
|
|
444
|
+
// theme's own: a dark theme sets its canvas below its surface.
|
|
445
|
+
it.each(registry.themes)("$name: the neutral ramp runs one way, away from the ground", (theme) => {
|
|
446
|
+
expect(["light", "dark"], `${theme.name} appearance`).toContain(theme.appearance);
|
|
447
|
+
const declarations = THEMES[theme.name];
|
|
448
|
+
const luminance = RAMP_STEPS.map((step) =>
|
|
449
|
+
relativeLuminance(declarations.get(`--color-neutral-${step}`)),
|
|
450
|
+
);
|
|
451
|
+
const outward = theme.appearance === "dark" ? 1 : -1;
|
|
452
|
+
const backwards = RAMP_STEPS.filter(
|
|
453
|
+
(step, index) => index > 0 && (luminance[index] - luminance[index - 1]) * outward < 0,
|
|
404
454
|
);
|
|
455
|
+
expect(backwards, "steps that turn back towards the ground").toEqual([]);
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
// The hovered field's border is neutral-500 and its resting outline --color-border-strong, so
|
|
459
|
+
// the hover reads as a step towards the reader only while 500 sits past the outline. The ramp
|
|
460
|
+
// test cannot see that — the outline is not a step — and the contrast theme's first outline,
|
|
461
|
+
// #000000, put its hover border back towards the ground.
|
|
462
|
+
it.each(registry.themes)("$name: a hovered field's border sits past its resting outline", (theme) => {
|
|
463
|
+
const declarations = THEMES[theme.name];
|
|
464
|
+
const outline = relativeLuminance(declarations.get("--color-border-strong"));
|
|
465
|
+
const hover = relativeLuminance(declarations.get("--color-neutral-500"));
|
|
466
|
+
const outward = theme.appearance === "dark" ? 1 : -1;
|
|
467
|
+
expect((hover - outline) * outward, "neutral-500 against border-strong").toBeGreaterThan(0);
|
|
405
468
|
});
|
|
406
469
|
});
|