@pie-qti/theme 1.0.0-beta.4 → 1.0.0-beta.5

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.
Files changed (3) hide show
  1. package/README.md +108 -13
  2. package/dist/tokens.css +63 -3
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -20,19 +20,114 @@ The default token stylesheet provides readable light and dark fallback palettes:
20
20
  </div>
21
21
  ```
22
22
 
23
+ Override any token on `:root` or on a container that wraps the player:
24
+
25
+ ```css
26
+ .my-player {
27
+ --pie-qti-primary: #146eb3;
28
+ --pie-qti-font-family: 'Atkinson Hyperlegible', sans-serif;
29
+ }
30
+ ```
31
+
23
32
  ## Token Contract
24
33
 
25
- Core tokens include:
26
-
27
- - `--pie-qti-primary`
28
- - `--pie-qti-secondary`
29
- - `--pie-qti-accent`
30
- - `--pie-qti-base-100`
31
- - `--pie-qti-base-200`
32
- - `--pie-qti-base-300`
33
- - `--pie-qti-base-content`
34
- - `--pie-qti-info`
35
- - `--pie-qti-success`
36
- - `--pie-qti-warning`
37
- - `--pie-qti-error`
34
+ ### Which token to use
35
+
36
+ | Purpose | Token | Contrast guarantee (WCAG 2.2 AA) |
37
+ | ------- | ----- | -------------------------------- |
38
+ | Body text on base surfaces | `--pie-qti-base-content` | ≥ 4.5:1 on `base-100` and `base-200` |
39
+ | Message/state **text** (feedback, validation, status) on base surfaces | `--pie-qti-error-text`, `--pie-qti-warning-text`, `--pie-qti-success-text`, `--pie-qti-info-text` | ≥ 4.5:1 on `base-100` and `base-200` |
40
+ | **Fills** (buttons, badges, alert backgrounds) | `--pie-qti-primary`, `--pie-qti-secondary`, `--pie-qti-accent`, `--pie-qti-neutral`, `--pie-qti-info`, `--pie-qti-success`, `--pie-qti-warning`, `--pie-qti-error` | — |
41
+ | Text **on a fill** | the fill's `*-content` token, for example `--pie-qti-error-content` on `--pie-qti-error` | ≥ 4.5:1 on its own fill |
42
+ | Control **boundaries** (inputs, selects, file inputs) and other non-text cues | `--pie-qti-border-strong` | ≥ 3:1 on `base-100` and `base-200` |
43
+ | Focus indicator | `--pie-qti-focus` | ≥ 3:1 on `base-100` and `base-200` |
44
+ | Surfaces | `--pie-qti-base-100` (page), `--pie-qti-base-200` (raised/tinted), `--pie-qti-base-300` (subtle dividers) | — |
45
+
46
+ Rules of thumb:
47
+
48
+ - Never use a state fill (`--pie-qti-error`, `--pie-qti-success`, …) as a text
49
+ colour: the fills are tuned as backgrounds and fall well below 4.5:1 as text.
50
+ - State-coloured non-text cues (icons, correctness outlines) may use the
51
+ matching `*-text` token, which exceeds the 3:1 non-text requirement.
52
+ - `--pie-qti-base-300` is a decorative divider colour (about 1.1:1 to 1.2:1);
53
+ do not use it for control boundaries that must be perceivable.
54
+ - Draw focus as `outline: 2px solid var(--pie-qti-focus, #4338ca);
55
+ outline-offset: 2px;` on `:focus-visible`, without transparency.
56
+ - Colour must not be the only cue: pair state colours with text or an icon
57
+ (WCAG 1.4.1).
58
+
59
+ The guarantees cover the default palettes in `tokens.css` and are enforced by
60
+ `tests/theme-contrast.test.ts`. Hosts that override colour tokens own the
61
+ contrast of their overrides. The DaisyUI bridge derives `--pie-qti-focus` and
62
+ the `*-content` tokens so that they keep these guarantees in every stock
63
+ DaisyUI theme (text on fills in engines with relative colour syntax); see its
64
+ [contrast guarantees](../theme-daisyui/README.md#contrast-guarantees).
65
+
66
+ ### Default values and measured contrast
67
+
68
+ Ratios are against `--pie-qti-base-100` / `--pie-qti-base-200` of the same
69
+ theme. The light values equal the fallbacks components use when no theme
70
+ stylesheet is loaded.
71
+
72
+ | Token | Light | Light ratio | Dark | Dark ratio |
73
+ | ----- | ----- | ----------- | ---- | ---------- |
74
+ | `--pie-qti-base-content` | `oklch(21% 0 0)` | 17.76 / 16.72 | `oklch(97% 0.01 255)` | 14.75 / 15.95 |
75
+ | `--pie-qti-error-text` | `#b91c1c` | 6.47 / 6.09 | `#f87171` | 5.79 / 6.26 |
76
+ | `--pie-qti-warning-text` | `#92400e` | 7.09 / 6.68 | `#fbbf24` | 9.60 / 10.38 |
77
+ | `--pie-qti-success-text` | `#15803d` | 5.02 / 4.72 | `#4ade80` | 9.20 / 9.94 |
78
+ | `--pie-qti-info-text` | `#1d4ed8` | 6.70 / 6.31 | `#60a5fa` | 6.30 / 6.82 |
79
+ | `--pie-qti-border-strong` | `#767676` | 4.54 / 4.28 | `#9ca3af` | 6.31 / 6.82 |
80
+ | `--pie-qti-focus` | `var(--pie-qti-primary)` | 8.32 / 7.84 | `var(--pie-qti-primary)` | 4.28 / 4.63 |
81
+
82
+ Every `*-content` token reaches at least 4.5:1 on its fill in both themes
83
+ (lowest: `--pie-qti-secondary-content` on `--pie-qti-secondary`, 4.85:1 in the
84
+ light theme).
85
+
86
+ ### Colour tokens
87
+
88
+ - `--pie-qti-primary`, `--pie-qti-primary-content`
89
+ - `--pie-qti-secondary`, `--pie-qti-secondary-content`
90
+ - `--pie-qti-accent`, `--pie-qti-accent-content`
91
+ - `--pie-qti-neutral`, `--pie-qti-neutral-content`
92
+ - `--pie-qti-base-100`, `--pie-qti-base-200`, `--pie-qti-base-300`, `--pie-qti-base-content`
93
+ - `--pie-qti-info`, `--pie-qti-info-content`, `--pie-qti-info-text`
94
+ - `--pie-qti-success`, `--pie-qti-success-content`, `--pie-qti-success-text`
95
+ - `--pie-qti-warning`, `--pie-qti-warning-content`, `--pie-qti-warning-text`
96
+ - `--pie-qti-error`, `--pie-qti-error-content`, `--pie-qti-error-text`
97
+ - `--pie-qti-border-strong`
38
98
  - `--pie-qti-focus`
99
+
100
+ ### Typography, spacing, and shape tokens
101
+
102
+ These are shared by both themes. The font tokens inherit from the host by
103
+ default so players follow the embedding application's typography.
104
+
105
+ | Token | Default | Use |
106
+ | ----- | ------- | --- |
107
+ | `--pie-qti-font-family` | `inherit` | Player shell font family |
108
+ | `--pie-qti-font-size-base` | `1rem` | Base font size |
109
+ | `--pie-qti-line-height` | `1.5` | Body line height |
110
+ | `--pie-qti-radius` | `0.5rem` | Containers: cards, panels, alerts |
111
+ | `--pie-qti-radius-sm` | `0.25rem` | Small elements: fields, chips |
112
+ | `--pie-qti-space-1` | `0.25rem` | Spacing scale step 1 |
113
+ | `--pie-qti-space-2` | `0.5rem` | Spacing scale step 2 |
114
+ | `--pie-qti-space-3` | `0.75rem` | Spacing scale step 3 |
115
+ | `--pie-qti-space-4` | `1rem` | Spacing scale step 4 |
116
+ | `--pie-qti-space-5` | `1.5rem` | Spacing scale step 5 |
117
+ | `--pie-qti-space-6` | `2rem` | Spacing scale step 6 |
118
+ | `--pie-qti-control-min-size` | `2.75rem` | Minimum interactive control size (44px touch target) |
119
+
120
+ Candidate PNP text appearance (font size, font family, line height) also
121
+ updates `--pie-qti-font-size-base`, `--pie-qti-font-family`, and
122
+ `--pie-qti-line-height`, so chrome sized from these tokens keeps the
123
+ candidate's preferences. PNP colour schemes redraw the message/state text,
124
+ border, and focus tokens in the scheme's two colours. A candidate's own text or
125
+ background colour redraws them in the text colour (the candidate's, or the
126
+ theme's when only a background is set), and the background colour also covers
127
+ `--pie-qti-base-200` surfaces, so they keep the contrast the candidate chose.
128
+
129
+ ### Dark theme and var() references
130
+
131
+ `--pie-qti-focus` resolves `var(--pie-qti-primary)` where it is declared, so a
132
+ theme that changes `--pie-qti-primary` on a nested container must redeclare
133
+ `--pie-qti-focus` there as well (the dark palette does).
package/dist/tokens.css CHANGED
@@ -4,6 +4,22 @@
4
4
  * These defaults keep QTI players readable in hosts that do not load a theme
5
5
  * bridge. Host apps may override any --pie-qti-* variable on :root or on a
6
6
  * container that wraps QTI player elements.
7
+ *
8
+ * Contrast guarantees (WCAG 2.2 AA, enforced by tests/theme-contrast.test.ts):
9
+ * - Text tokens (--pie-qti-error-text/-warning-text/-success-text/-info-text,
10
+ * --pie-qti-base-content, and every --pie-qti-*-content): >= 4.5:1 on
11
+ * --pie-qti-base-100 and --pie-qti-base-200 within the same theme.
12
+ * - Non-text tokens (--pie-qti-border-strong, --pie-qti-focus): >= 3:1 on
13
+ * --pie-qti-base-100 and --pie-qti-base-200 within the same theme.
14
+ *
15
+ * Text vs fills vs borders:
16
+ * - Message/state TEXT (feedback, alerts, labels) uses the *-text tokens.
17
+ * - Fills (badge, button, alert backgrounds) use the state tokens
18
+ * (--pie-qti-error, --pie-qti-warning, ...) paired with their *-content
19
+ * token for text ON that fill.
20
+ * - Control boundaries (input/button borders, non-text cues) use
21
+ * --pie-qti-border-strong; --pie-qti-focus is reserved for :focus-visible
22
+ * outlines.
7
23
  */
8
24
 
9
25
  :root,
@@ -11,7 +27,7 @@
11
27
  --pie-qti-primary: oklch(45% 0.24 277);
12
28
  --pie-qti-primary-content: oklch(98% 0.01 277);
13
29
  --pie-qti-secondary: oklch(65% 0.241 354.308);
14
- --pie-qti-secondary-content: oklch(98% 0.01 354.308);
30
+ --pie-qti-secondary-content: oklch(22% 0.08 354.308);
15
31
  --pie-qti-accent: oklch(77% 0.152 181.912);
16
32
  --pie-qti-accent-content: oklch(20% 0.03 181.912);
17
33
  --pie-qti-neutral: oklch(32% 0 0);
@@ -27,8 +43,40 @@
27
43
  --pie-qti-warning: oklch(82% 0.189 84.429);
28
44
  --pie-qti-warning-content: oklch(20% 0.04 84.429);
29
45
  --pie-qti-error: oklch(71% 0.194 13.428);
30
- --pie-qti-error-content: oklch(98% 0.01 13.428);
46
+ --pie-qti-error-content: oklch(25% 0.1 13.428);
31
47
  --pie-qti-focus: var(--pie-qti-primary);
48
+
49
+ /*
50
+ * Message/state text colors on base surfaces (>= 4.5:1 on base-100/base-200).
51
+ * Light values match the component fallbacks:
52
+ * #b91c1c, #92400e, #15803d, #1d4ed8.
53
+ */
54
+ --pie-qti-error-text: #b91c1c;
55
+ --pie-qti-warning-text: #92400e;
56
+ --pie-qti-success-text: #15803d;
57
+ --pie-qti-info-text: #1d4ed8;
58
+
59
+ /* Control boundaries and other non-text cues (>= 3:1 on base-100/base-200). */
60
+ --pie-qti-border-strong: #767676;
61
+
62
+ /*
63
+ * Typography, spacing, and shape tokens for player shells. They inherit
64
+ * from the host by default so the shell follows the embedding app's
65
+ * typography; override them on :root or a container to restyle a player.
66
+ */
67
+ --pie-qti-font-family: inherit;
68
+ --pie-qti-font-size-base: 1rem;
69
+ --pie-qti-line-height: 1.5;
70
+ --pie-qti-radius: 0.5rem;
71
+ --pie-qti-radius-sm: 0.25rem;
72
+ --pie-qti-space-1: 0.25rem;
73
+ --pie-qti-space-2: 0.5rem;
74
+ --pie-qti-space-3: 0.75rem;
75
+ --pie-qti-space-4: 1rem;
76
+ --pie-qti-space-5: 1.5rem;
77
+ --pie-qti-space-6: 2rem;
78
+ /* Minimum interactive control size (WCAG 2.2 target size baseline). */
79
+ --pie-qti-control-min-size: 2.75rem;
32
80
  }
33
81
 
34
82
  [data-qti-theme='dark'] {
@@ -51,6 +99,18 @@
51
99
  --pie-qti-warning: oklch(82% 0.189 84.429);
52
100
  --pie-qti-warning-content: oklch(15% 0.04 84.429);
53
101
  --pie-qti-error: oklch(71% 0.194 13.428);
54
- --pie-qti-error-content: oklch(98% 0.01 13.428);
102
+ --pie-qti-error-content: oklch(25% 0.1 13.428);
55
103
  --pie-qti-focus: var(--pie-qti-primary);
104
+
105
+ /*
106
+ * Message/state text colors on dark base surfaces
107
+ * (#f87171, #fbbf24, #4ade80, #60a5fa) and control boundaries
108
+ * (#9ca3af); all verified >= 4.5:1 (text) / >= 3:1 (non-text) against
109
+ * base-100 and base-200.
110
+ */
111
+ --pie-qti-error-text: #f87171;
112
+ --pie-qti-warning-text: #fbbf24;
113
+ --pie-qti-success-text: #4ade80;
114
+ --pie-qti-info-text: #60a5fa;
115
+ --pie-qti-border-strong: #9ca3af;
56
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/theme",
3
- "version": "1.0.0-beta.4",
3
+ "version": "1.0.0-beta.5",
4
4
  "description": "Shared PIE QTI theme tokens and CSS variable contracts",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@biomejs/biome": "^2.6.2",
26
+ "@biomejs/biome": "^2.6.4",
27
27
  "typescript": "^5.9.3"
28
28
  },
29
29
  "exports": {