@adea-ai/themes 0.9.9 → 0.9.10

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/src/policy.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The catalogue's policy: the contrast floors, the repair budgets and the accent
3
+ * preference.
4
+ *
5
+ * Kept apart from the normalizer, which applies them, so that the accent axis —
6
+ * which the normalizer now consults to fit the interaction rungs around the primary
7
+ * tint — can read the same numbers without the two modules importing each other.
8
+ * `normalize.ts` re-exports everything here.
9
+ */
10
+
11
+ import type { AnsiKey } from './schema.js'
12
+
13
+ /**
14
+ * The contrast floors.
15
+ *
16
+ * These are the catalogue's policy, and they are the reason an external palette
17
+ * can be admitted at all: nothing enters the catalogue on taste. `text` sits at
18
+ * the WCAG AA body-text floor; `border` is measured on the non-text scale, where
19
+ * the requirement is perceptibility rather than legibility.
20
+ */
21
+ export const CONTRAST_FLOORS = Object.freeze({
22
+ text: 4.5,
23
+ textMuted: 4.5,
24
+ /** Large or non-essential text, per WCAG 1.4.3. */
25
+ textSubtle: 3,
26
+ accent: 4.5,
27
+ /**
28
+ * The accent on a raised surface, where it is a fill rather than a label.
29
+ *
30
+ * The same two-tier reasoning as `statusRaised`: a button or a selected tab is a
31
+ * user-interface component, which WCAG holds to 3:1, and the pairing that
32
+ * actually carries text — the accent's own label — is measured separately at 4.5
33
+ * against the accent itself. Holding the accent to 4.5 on every surface instead
34
+ * made Everforest Light's every hue collapse into its body text, because that
35
+ * palette's colours are all around 2:1 on its own canvas.
36
+ */
37
+ accentRaised: 3,
38
+ accentForeground: 4.5,
39
+ /**
40
+ * Status colours drawn on the canvas, where they are read as small text.
41
+ */
42
+ status: 4.5,
43
+ /**
44
+ * Status colours drawn on a raised surface, where they are an indicator.
45
+ *
46
+ * The two-tier policy is deliberate and it is not a relaxation for convenience.
47
+ * A status role on a card is nearly always a dot, an icon or a chip's own fill —
48
+ * a graphical object, which WCAG holds to 3:1 — and it is that way because the
49
+ * alternative does not exist: Ayu Light and Everforest Light are muted palettes
50
+ * built for a near-white canvas and neither contains a yellow that is legible as
51
+ * small text on one. Forcing 4.5:1 there required blending the warning colour
52
+ * 94% of the way to the body text, which produces a warning that is the same
53
+ * colour as the text beside it and is therefore not a warning at all.
54
+ *
55
+ * A component that renders small status *text* on a raised surface should put it
56
+ * on the role's `-subtle` fill, which is a tint of the canvas and is measured at
57
+ * the body floor.
58
+ */
59
+ statusRaised: 3,
60
+ /** A divider is decorative; it must be seen, not read. */
61
+ border: 1.15,
62
+ borderMuted: 1.08,
63
+ /** A raised surface must be distinguishable from the canvas it sits on. */
64
+ surface: 1.03,
65
+ /** A selection must be visible under the text it selects. */
66
+ selection: 1.2,
67
+ } as const)
68
+
69
+ /** How far the normalizer may move a colour's lightness before it gives up. */
70
+ export const REPAIR_BUDGET = Object.freeze({
71
+ /** Body text: some palettes publish a foreground that fails on their own canvas. */
72
+ text: 0.2,
73
+ status: 0.24,
74
+ accent: 0.24,
75
+ })
76
+
77
+ /** The accent preference order, best first. */
78
+ export const ACCENT_PREFERENCE = [
79
+ 'blue',
80
+ 'magenta',
81
+ 'cyan',
82
+ 'green',
83
+ ] as const satisfies readonly AnsiKey[]
84
+
85
+ /** The smallest chroma a colour needs before it reads as "a colour" rather than grey. */
86
+ export const MINIMUM_ACCENT_CHROMA = 0.035
package/src/validate.ts CHANGED
@@ -15,10 +15,11 @@
15
15
  * than a legibility one.
16
16
  *
17
17
  * Not measured: a colour against itself, and the surface ladder against anything
18
- * but the canvas. A rung's job is to be distinguishable from the canvas, not to
19
- * carry text — components put text on `background`, and the ladder is decoration on
20
- * top of it. Measuring the ladder against every foreground would produce failures
21
- * no theme could pass and no component would care about.
18
+ * but the canvas and body text. A rung's job is to be distinguishable from the
19
+ * canvas, and measuring it against every foreground would produce failures no theme
20
+ * could pass and no component would care about. Body text is the exception: it is
21
+ * drawn on every rung, the hover and active rungs included, because a hovered or
22
+ * pressed row keeps its label.
22
23
  *
23
24
  * ## Why the validator is exported
24
25
  *
@@ -77,6 +78,10 @@ export const REQUIRED_PAIRINGS: readonly Pairing[] = Object.freeze([
77
78
  { role: 'textMuted', against: ['background'], minimum: CONTRAST_FLOORS.textMuted },
78
79
  { role: 'text', against: ['surface'], minimum: CONTRAST_FLOORS.text },
79
80
  { role: 'text', against: ['surfaceElevated'], minimum: CONTRAST_FLOORS.text },
81
+ // A hovered or pressed row keeps its label, so the interaction rungs carry the
82
+ // body floor too. The normalizer fits the rungs to it; see `fitInteractionRungs`.
83
+ { role: 'text', against: ['surfaceHover'], minimum: CONTRAST_FLOORS.text },
84
+ { role: 'text', against: ['surfaceActive'], minimum: CONTRAST_FLOORS.text },
80
85
  { role: 'textMuted', against: ['surface'], minimum: CONTRAST_FLOORS.textMuted },
81
86
  { role: 'textSubtle', against: ['background'], minimum: CONTRAST_FLOORS.textSubtle },
82
87
  { role: 'accent', against: ['background'], minimum: CONTRAST_FLOORS.accent },