@websublime/line-schemas 0.2.0 → 0.2.1
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/dist/contrast-table.d.ts +22 -9
- package/dist/contrast-table.d.ts.map +1 -1
- package/dist/contrast-table.js +48 -8
- package/dist/contrast-table.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/contrast-table.ts +56 -11
- package/src/index.ts +2 -0
package/dist/contrast-table.d.ts
CHANGED
|
@@ -1,23 +1,36 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { Hue } from './hues.js';
|
|
3
3
|
/**
|
|
4
|
-
* The on-color for a step-9
|
|
5
|
-
* foreground is white (`#fff`); for the bright hues listed in
|
|
6
|
-
* {@link BLACK_CONTRAST_HUES} it is black (`#000`).
|
|
4
|
+
* The on-color for a step-9 solid fill: black (`#000`) or white (`#fff`).
|
|
7
5
|
*/
|
|
8
6
|
export type ContrastColor = '#000' | '#fff';
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* The 20 saturated hues whose step-9 solid takes black text in both modes (AM-092). For each of them `#000` has a
|
|
9
|
+
* higher WCAG 2.1 contrast ratio than `#fff` against the Radix step 9, which is the same colour in light and dark.
|
|
10
|
+
* The other five saturated hues (indigo, iris, plum, purple, violet) take white; the six {@link GRAY_HUES} take
|
|
11
|
+
* black in light mode and white in dark.
|
|
12
12
|
*/
|
|
13
|
-
export declare const BLACK_CONTRAST_HUES: readonly ['amber', '
|
|
13
|
+
export declare const BLACK_CONTRAST_HUES: readonly ['amber', 'blue', 'bronze', 'brown', 'crimson', 'cyan', 'gold', 'grass', 'green', 'jade', 'lime', 'mint', 'orange', 'pink', 'red', 'ruby', 'sky', 'teal', 'tomato', 'yellow'];
|
|
14
14
|
export type BlackContrastHue = (typeof BLACK_CONTRAST_HUES)[number];
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Light-mode on-color per hue (AM-092): `'#000'` for the {@link BLACK_CONTRAST_HUES} and the {@link GRAY_HUES},
|
|
17
|
+
* `'#fff'` for every other hue. Each value is whichever of black and white has the higher WCAG 2.1 contrast ratio
|
|
18
|
+
* against the hue's light-mode Radix step 9. {@link PER_HUE_CONTRAST_DARK} holds the dark-mode values, and
|
|
19
|
+
* {@link contrastFor} reads the table of a mode. `scripts/validate-contrast.mjs` gates both tables at 4.5:1.
|
|
19
20
|
*/
|
|
20
21
|
export declare const PER_HUE_CONTRAST: Record<Hue, ContrastColor>;
|
|
22
|
+
/**
|
|
23
|
+
* Dark-mode on-color per hue (AM-092): `'#fff'` for the {@link GRAY_HUES}, whose dark step 9 is darker than their
|
|
24
|
+
* light one, and {@link PER_HUE_CONTRAST}'s value for every other hue, whose step 9 is the same in both modes.
|
|
25
|
+
*/
|
|
26
|
+
export declare const PER_HUE_CONTRAST_DARK: Record<Hue, ContrastColor>;
|
|
27
|
+
/**
|
|
28
|
+
* The on-color for `hue`'s step-9 solid in `mode` (AM-092): {@link PER_HUE_CONTRAST} in light mode,
|
|
29
|
+
* {@link PER_HUE_CONTRAST_DARK} in dark. The `line-colors` palette generator emits one value when the two modes
|
|
30
|
+
* agree and `light-dark(light, dark)` when they differ.
|
|
31
|
+
*/
|
|
32
|
+
export declare const contrastFor: (hue: Hue, mode: 'light' | 'dark') => ContrastColor;
|
|
21
33
|
export declare const ContrastColorSchema: z.ZodUnion<[z.ZodLiteral<"#000">, z.ZodLiteral<"#fff">]>;
|
|
34
|
+
/** Parses either contrast table. */
|
|
22
35
|
export declare const PerHueContrastSchema: z.ZodRecord<z.ZodEnum<["amber", "blue", "bronze", "brown", "crimson", "cyan", "gold", "grass", "green", "indigo", "iris", "jade", "lime", "mauve", "mint", "neutral", "olive", "orange", "pink", "plum", "purple", "red", "ruby", "sage", "sand", "sky", "slate", "teal", "tomato", "violet", "yellow"]>, z.ZodUnion<[z.ZodLiteral<"#000">, z.ZodLiteral<"#fff">]>>;
|
|
23
36
|
//# sourceMappingURL=contrast-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contrast-table.d.ts","sourceRoot":"","sources":["../src/contrast-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC
|
|
1
|
+
{"version":3,"file":"contrast-table.d.ts","sourceRoot":"","sources":["../src/contrast-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAGrC;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,MAAM,CAAC;AAE5C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAC9B,OAAO,EACP,MAAM,EACN,QAAQ,EACR,OAAO,EACP,SAAS,EACT,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,MAAM,EACN,KAAK,EACL,MAAM,EACN,QAAQ,EACR,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAMpE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,GAAG,EAAE,aAAa,CAMvD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,GAAG,EAAE,aAAa,CAM5D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,QAAS,GAAG,QAAQ,OAAO,GAAG,MAAM,KAAG,aACI,CAAC;AAEpE,eAAO,MAAM,mBAAmB,0DAAkD,CAAC;AAEnF,oCAAoC;AACpC,eAAO,MAAM,oBAAoB,qWAA2C,CAAC"}
|
package/dist/contrast-table.js
CHANGED
|
@@ -1,20 +1,60 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { HUES, HueSchema } from './hues.js';
|
|
2
|
+
import { GRAY_HUES, HUES, HueSchema } from './hues.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The 20 saturated hues whose step-9 solid takes black text in both modes (AM-092). For each of them `#000` has a
|
|
5
|
+
* higher WCAG 2.1 contrast ratio than `#fff` against the Radix step 9, which is the same colour in light and dark.
|
|
6
|
+
* The other five saturated hues (indigo, iris, plum, purple, violet) take white; the six {@link GRAY_HUES} take
|
|
7
|
+
* black in light mode and white in dark.
|
|
6
8
|
*/
|
|
7
|
-
export const BLACK_CONTRAST_HUES = [
|
|
9
|
+
export const BLACK_CONTRAST_HUES = [
|
|
10
|
+
'amber',
|
|
11
|
+
'blue',
|
|
12
|
+
'bronze',
|
|
13
|
+
'brown',
|
|
14
|
+
'crimson',
|
|
15
|
+
'cyan',
|
|
16
|
+
'gold',
|
|
17
|
+
'grass',
|
|
18
|
+
'green',
|
|
19
|
+
'jade',
|
|
20
|
+
'lime',
|
|
21
|
+
'mint',
|
|
22
|
+
'orange',
|
|
23
|
+
'pink',
|
|
24
|
+
'red',
|
|
25
|
+
'ruby',
|
|
26
|
+
'sky',
|
|
27
|
+
'teal',
|
|
28
|
+
'tomato',
|
|
29
|
+
'yellow',
|
|
30
|
+
];
|
|
8
31
|
const BLACK_CONTRAST_HUE_SET = new Set(BLACK_CONTRAST_HUES);
|
|
32
|
+
const GRAY_HUE_SET = new Set(GRAY_HUES);
|
|
9
33
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
34
|
+
* Light-mode on-color per hue (AM-092): `'#000'` for the {@link BLACK_CONTRAST_HUES} and the {@link GRAY_HUES},
|
|
35
|
+
* `'#fff'` for every other hue. Each value is whichever of black and white has the higher WCAG 2.1 contrast ratio
|
|
36
|
+
* against the hue's light-mode Radix step 9. {@link PER_HUE_CONTRAST_DARK} holds the dark-mode values, and
|
|
37
|
+
* {@link contrastFor} reads the table of a mode. `scripts/validate-contrast.mjs` gates both tables at 4.5:1.
|
|
13
38
|
*/
|
|
14
39
|
export const PER_HUE_CONTRAST = HUES.reduce((acc, hue) => {
|
|
15
|
-
acc[hue] = BLACK_CONTRAST_HUE_SET.has(hue) ? '#000' : '#fff';
|
|
40
|
+
acc[hue] = BLACK_CONTRAST_HUE_SET.has(hue) || GRAY_HUE_SET.has(hue) ? '#000' : '#fff';
|
|
16
41
|
return acc;
|
|
17
42
|
}, {});
|
|
43
|
+
/**
|
|
44
|
+
* Dark-mode on-color per hue (AM-092): `'#fff'` for the {@link GRAY_HUES}, whose dark step 9 is darker than their
|
|
45
|
+
* light one, and {@link PER_HUE_CONTRAST}'s value for every other hue, whose step 9 is the same in both modes.
|
|
46
|
+
*/
|
|
47
|
+
export const PER_HUE_CONTRAST_DARK = HUES.reduce((acc, hue) => {
|
|
48
|
+
acc[hue] = GRAY_HUE_SET.has(hue) ? '#fff' : PER_HUE_CONTRAST[hue];
|
|
49
|
+
return acc;
|
|
50
|
+
}, {});
|
|
51
|
+
/**
|
|
52
|
+
* The on-color for `hue`'s step-9 solid in `mode` (AM-092): {@link PER_HUE_CONTRAST} in light mode,
|
|
53
|
+
* {@link PER_HUE_CONTRAST_DARK} in dark. The `line-colors` palette generator emits one value when the two modes
|
|
54
|
+
* agree and `light-dark(light, dark)` when they differ.
|
|
55
|
+
*/
|
|
56
|
+
export const contrastFor = (hue, mode) => (mode === 'dark' ? PER_HUE_CONTRAST_DARK : PER_HUE_CONTRAST)[hue];
|
|
18
57
|
export const ContrastColorSchema = z.union([z.literal('#000'), z.literal('#fff')]);
|
|
58
|
+
/** Parses either contrast table. */
|
|
19
59
|
export const PerHueContrastSchema = z.record(HueSchema, ContrastColorSchema);
|
|
20
60
|
//# sourceMappingURL=contrast-table.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contrast-table.js","sourceRoot":"","sources":["../src/contrast-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"contrast-table.js","sourceRoot":"","sources":["../src/contrast-table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAOvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,MAAM;IACN,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,QAAQ;IACR,QAAQ;CACA,CAAC;AAIX,MAAM,sBAAsB,GAAqB,IAAI,GAAG,CAAM,mBAAmB,CAAC,CAAC;AAEnF,MAAM,YAAY,GAAqB,IAAI,GAAG,CAAM,SAAS,CAAC,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA+B,IAAI,CAAC,MAAM,CACrE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACX,GAAG,CAAC,GAAG,CAAC,GAAG,sBAAsB,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;IACtF,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAgC,CACjC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA+B,IAAI,CAAC,MAAM,CAC1E,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;IACX,GAAG,CAAC,GAAG,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAClE,OAAO,GAAG,CAAC;AACb,CAAC,EACD,EAAgC,CACjC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAQ,EAAE,IAAsB,EAAiB,EAAE,CAC7E,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,GAAG,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEnF,oCAAoC;AACpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type { Alias } from './aliases.js';
|
|
2
2
|
export { ALIASES, AliasSchema } from './aliases.js';
|
|
3
3
|
export type { BlackContrastHue, ContrastColor } from './contrast-table.js';
|
|
4
|
-
export { BLACK_CONTRAST_HUES, ContrastColorSchema, PER_HUE_CONTRAST, PerHueContrastSchema, } from './contrast-table.js';
|
|
4
|
+
export { BLACK_CONTRAST_HUES, ContrastColorSchema, contrastFor, PER_HUE_CONTRAST, PER_HUE_CONTRAST_DARK, PerHueContrastSchema, } from './contrast-table.js';
|
|
5
5
|
export type { AccentHue, GrayHue, Hue } from './hues.js';
|
|
6
6
|
export { ACCENT_HUES, AccentHueSchema, GRAY_HUES, GrayHueSchema, HUES, HueSchema, } from './hues.js';
|
|
7
7
|
export type { Role } from './roles.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,GACV,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,YAAY,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACpD,YAAY,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EACL,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,GACV,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This barrel re-exports every contract module. The contrast table is also
|
|
4
4
|
// available via the `./contrast-table` subpath export (see package.json).
|
|
5
5
|
export { ALIASES, AliasSchema } from './aliases.js';
|
|
6
|
-
export { BLACK_CONTRAST_HUES, ContrastColorSchema, PER_HUE_CONTRAST, PerHueContrastSchema, } from './contrast-table.js';
|
|
6
|
+
export { BLACK_CONTRAST_HUES, ContrastColorSchema, contrastFor, PER_HUE_CONTRAST, PER_HUE_CONTRAST_DARK, PerHueContrastSchema, } from './contrast-table.js';
|
|
7
7
|
export { ACCENT_HUES, AccentHueSchema, GRAY_HUES, GrayHueSchema, HUES, HueSchema, } from './hues.js';
|
|
8
8
|
export { ROLES, RoleSchema } from './roles.js';
|
|
9
9
|
export { SEMANTIC_MAP, SemanticMapSchema } from './semantic-map.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAG1E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,GACV,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAG1E,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,WAAW,EACX,eAAe,EACf,SAAS,EACT,aAAa,EACb,IAAI,EACJ,SAAS,GACV,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
|
package/package.json
CHANGED
package/src/contrast-table.ts
CHANGED
|
@@ -1,37 +1,82 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import type { Hue } from './hues.js';
|
|
3
|
-
import { HUES, HueSchema } from './hues.js';
|
|
3
|
+
import { GRAY_HUES, HUES, HueSchema } from './hues.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* The on-color for a step-9
|
|
7
|
-
* foreground is white (`#fff`); for the bright hues listed in
|
|
8
|
-
* {@link BLACK_CONTRAST_HUES} it is black (`#000`).
|
|
6
|
+
* The on-color for a step-9 solid fill: black (`#000`) or white (`#fff`).
|
|
9
7
|
*/
|
|
10
8
|
export type ContrastColor = '#000' | '#fff';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
11
|
+
* The 20 saturated hues whose step-9 solid takes black text in both modes (AM-092). For each of them `#000` has a
|
|
12
|
+
* higher WCAG 2.1 contrast ratio than `#fff` against the Radix step 9, which is the same colour in light and dark.
|
|
13
|
+
* The other five saturated hues (indigo, iris, plum, purple, violet) take white; the six {@link GRAY_HUES} take
|
|
14
|
+
* black in light mode and white in dark.
|
|
15
15
|
*/
|
|
16
|
-
export const BLACK_CONTRAST_HUES = [
|
|
16
|
+
export const BLACK_CONTRAST_HUES = [
|
|
17
|
+
'amber',
|
|
18
|
+
'blue',
|
|
19
|
+
'bronze',
|
|
20
|
+
'brown',
|
|
21
|
+
'crimson',
|
|
22
|
+
'cyan',
|
|
23
|
+
'gold',
|
|
24
|
+
'grass',
|
|
25
|
+
'green',
|
|
26
|
+
'jade',
|
|
27
|
+
'lime',
|
|
28
|
+
'mint',
|
|
29
|
+
'orange',
|
|
30
|
+
'pink',
|
|
31
|
+
'red',
|
|
32
|
+
'ruby',
|
|
33
|
+
'sky',
|
|
34
|
+
'teal',
|
|
35
|
+
'tomato',
|
|
36
|
+
'yellow',
|
|
37
|
+
] as const;
|
|
17
38
|
|
|
18
39
|
export type BlackContrastHue = (typeof BLACK_CONTRAST_HUES)[number];
|
|
19
40
|
|
|
20
41
|
const BLACK_CONTRAST_HUE_SET: ReadonlySet<Hue> = new Set<Hue>(BLACK_CONTRAST_HUES);
|
|
21
42
|
|
|
43
|
+
const GRAY_HUE_SET: ReadonlySet<Hue> = new Set<Hue>(GRAY_HUES);
|
|
44
|
+
|
|
22
45
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
46
|
+
* Light-mode on-color per hue (AM-092): `'#000'` for the {@link BLACK_CONTRAST_HUES} and the {@link GRAY_HUES},
|
|
47
|
+
* `'#fff'` for every other hue. Each value is whichever of black and white has the higher WCAG 2.1 contrast ratio
|
|
48
|
+
* against the hue's light-mode Radix step 9. {@link PER_HUE_CONTRAST_DARK} holds the dark-mode values, and
|
|
49
|
+
* {@link contrastFor} reads the table of a mode. `scripts/validate-contrast.mjs` gates both tables at 4.5:1.
|
|
26
50
|
*/
|
|
27
51
|
export const PER_HUE_CONTRAST: Record<Hue, ContrastColor> = HUES.reduce(
|
|
28
52
|
(acc, hue) => {
|
|
29
|
-
acc[hue] = BLACK_CONTRAST_HUE_SET.has(hue) ? '#000' : '#fff';
|
|
53
|
+
acc[hue] = BLACK_CONTRAST_HUE_SET.has(hue) || GRAY_HUE_SET.has(hue) ? '#000' : '#fff';
|
|
54
|
+
return acc;
|
|
55
|
+
},
|
|
56
|
+
{} as Record<Hue, ContrastColor>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Dark-mode on-color per hue (AM-092): `'#fff'` for the {@link GRAY_HUES}, whose dark step 9 is darker than their
|
|
61
|
+
* light one, and {@link PER_HUE_CONTRAST}'s value for every other hue, whose step 9 is the same in both modes.
|
|
62
|
+
*/
|
|
63
|
+
export const PER_HUE_CONTRAST_DARK: Record<Hue, ContrastColor> = HUES.reduce(
|
|
64
|
+
(acc, hue) => {
|
|
65
|
+
acc[hue] = GRAY_HUE_SET.has(hue) ? '#fff' : PER_HUE_CONTRAST[hue];
|
|
30
66
|
return acc;
|
|
31
67
|
},
|
|
32
68
|
{} as Record<Hue, ContrastColor>,
|
|
33
69
|
);
|
|
34
70
|
|
|
71
|
+
/**
|
|
72
|
+
* The on-color for `hue`'s step-9 solid in `mode` (AM-092): {@link PER_HUE_CONTRAST} in light mode,
|
|
73
|
+
* {@link PER_HUE_CONTRAST_DARK} in dark. The `line-colors` palette generator emits one value when the two modes
|
|
74
|
+
* agree and `light-dark(light, dark)` when they differ.
|
|
75
|
+
*/
|
|
76
|
+
export const contrastFor = (hue: Hue, mode: 'light' | 'dark'): ContrastColor =>
|
|
77
|
+
(mode === 'dark' ? PER_HUE_CONTRAST_DARK : PER_HUE_CONTRAST)[hue];
|
|
78
|
+
|
|
35
79
|
export const ContrastColorSchema = z.union([z.literal('#000'), z.literal('#fff')]);
|
|
36
80
|
|
|
81
|
+
/** Parses either contrast table. */
|
|
37
82
|
export const PerHueContrastSchema = z.record(HueSchema, ContrastColorSchema);
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,9 @@ export type { BlackContrastHue, ContrastColor } from './contrast-table.js';
|
|
|
9
9
|
export {
|
|
10
10
|
BLACK_CONTRAST_HUES,
|
|
11
11
|
ContrastColorSchema,
|
|
12
|
+
contrastFor,
|
|
12
13
|
PER_HUE_CONTRAST,
|
|
14
|
+
PER_HUE_CONTRAST_DARK,
|
|
13
15
|
PerHueContrastSchema,
|
|
14
16
|
} from './contrast-table.js';
|
|
15
17
|
export type { AccentHue, GrayHue, Hue } from './hues.js';
|