@astl/player 0.0.0-stage → 0.1.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.
Files changed (107) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +202 -0
  3. package/README.md +36 -2
  4. package/dist/a11y.d.ts +41 -0
  5. package/dist/a11y.d.ts.map +1 -0
  6. package/dist/a11y.js +101 -0
  7. package/dist/a11y.js.map +1 -0
  8. package/dist/attempt/controller.d.ts +104 -0
  9. package/dist/attempt/controller.d.ts.map +1 -0
  10. package/dist/attempt/controller.js +325 -0
  11. package/dist/attempt/controller.js.map +1 -0
  12. package/dist/checker/http.d.ts +17 -0
  13. package/dist/checker/http.d.ts.map +1 -0
  14. package/dist/checker/http.js +115 -0
  15. package/dist/checker/http.js.map +1 -0
  16. package/dist/define.d.ts +35 -0
  17. package/dist/define.d.ts.map +1 -0
  18. package/dist/define.js +84 -0
  19. package/dist/define.js.map +1 -0
  20. package/dist/element/base.d.ts +83 -0
  21. package/dist/element/base.d.ts.map +1 -0
  22. package/dist/element/base.js +239 -0
  23. package/dist/element/base.js.map +1 -0
  24. package/dist/index.d.ts +14 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +8 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/interaction/index.d.ts +12 -0
  29. package/dist/interaction/index.d.ts.map +1 -0
  30. package/dist/interaction/index.js +4 -0
  31. package/dist/interaction/index.js.map +1 -0
  32. package/dist/interaction/keys.d.ts +11 -0
  33. package/dist/interaction/keys.d.ts.map +1 -0
  34. package/dist/interaction/keys.js +13 -0
  35. package/dist/interaction/keys.js.map +1 -0
  36. package/dist/interaction/pick-and-place.d.ts +120 -0
  37. package/dist/interaction/pick-and-place.d.ts.map +1 -0
  38. package/dist/interaction/pick-and-place.js +395 -0
  39. package/dist/interaction/pick-and-place.js.map +1 -0
  40. package/dist/interaction/roving-focus.d.ts +44 -0
  41. package/dist/interaction/roving-focus.d.ts.map +1 -0
  42. package/dist/interaction/roving-focus.js +115 -0
  43. package/dist/interaction/roving-focus.js.map +1 -0
  44. package/dist/messages/en.json +53 -0
  45. package/dist/messages/help/en.json +14 -0
  46. package/dist/messages/help/pl.json +14 -0
  47. package/dist/messages/pl.json +53 -0
  48. package/dist/messages.d.ts +7 -0
  49. package/dist/messages.d.ts.map +1 -0
  50. package/dist/messages.js +18 -0
  51. package/dist/messages.js.map +1 -0
  52. package/dist/player/book.d.ts +13 -0
  53. package/dist/player/book.d.ts.map +1 -0
  54. package/dist/player/book.js +65 -0
  55. package/dist/player/book.js.map +1 -0
  56. package/dist/player/help.d.ts +55 -0
  57. package/dist/player/help.d.ts.map +1 -0
  58. package/dist/player/help.js +484 -0
  59. package/dist/player/help.js.map +1 -0
  60. package/dist/player/player.d.ts +87 -0
  61. package/dist/player/player.d.ts.map +1 -0
  62. package/dist/player/player.js +1229 -0
  63. package/dist/player/player.js.map +1 -0
  64. package/dist/player/styled.d.ts +10 -0
  65. package/dist/player/styled.d.ts.map +1 -0
  66. package/dist/player/styled.js +213 -0
  67. package/dist/player/styled.js.map +1 -0
  68. package/dist/player/styles.d.ts +3 -0
  69. package/dist/player/styles.d.ts.map +1 -0
  70. package/dist/player/styles.js +355 -0
  71. package/dist/player/styles.js.map +1 -0
  72. package/dist/player/templates.d.ts +25 -0
  73. package/dist/player/templates.d.ts.map +1 -0
  74. package/dist/player/templates.js +101 -0
  75. package/dist/player/templates.js.map +1 -0
  76. package/dist/player/view.d.ts +44 -0
  77. package/dist/player/view.d.ts.map +1 -0
  78. package/dist/player/view.js +231 -0
  79. package/dist/player/view.js.map +1 -0
  80. package/dist/runtime.d.ts +45 -0
  81. package/dist/runtime.d.ts.map +1 -0
  82. package/dist/runtime.js +48 -0
  83. package/dist/runtime.js.map +1 -0
  84. package/package.json +45 -3
  85. package/src/a11y.ts +134 -0
  86. package/src/attempt/controller.ts +381 -0
  87. package/src/checker/http.ts +149 -0
  88. package/src/define.ts +114 -0
  89. package/src/element/base.ts +310 -0
  90. package/src/index.ts +18 -0
  91. package/src/interaction/index.ts +11 -0
  92. package/src/interaction/keys.ts +16 -0
  93. package/src/interaction/pick-and-place.ts +464 -0
  94. package/src/interaction/roving-focus.ts +133 -0
  95. package/src/messages/en.json +53 -0
  96. package/src/messages/help/en.json +14 -0
  97. package/src/messages/help/pl.json +14 -0
  98. package/src/messages/pl.json +53 -0
  99. package/src/messages.ts +21 -0
  100. package/src/player/book.ts +70 -0
  101. package/src/player/help.ts +585 -0
  102. package/src/player/player.ts +1368 -0
  103. package/src/player/styled.ts +247 -0
  104. package/src/player/styles.ts +355 -0
  105. package/src/player/templates.ts +142 -0
  106. package/src/player/view.ts +294 -0
  107. package/src/runtime.ts +95 -0
@@ -0,0 +1,247 @@
1
+ /**
2
+ * Authors' styles and layouts in the player, in a module of its own: a view that has neither never loads it. Without it
3
+ * (or when its chunk fails) `cleanView` removes every `style`, and the exercise plays unstyled.
4
+ *
5
+ * A view is engine output, and is still read as hostile here: each `style` goes through `cleanStyle` again. Declarations
6
+ * are written with `el.style.setProperty`, on the mounted copy of the view: a strict CSP (`style-src 'self'`) blocks a
7
+ * `style` attribute, and allows the CSSOM.
8
+ *
9
+ * What an author writes for a light page is changed in four ways, which is why nothing here is a plain copy:
10
+ * - a colour becomes `light-dark(as written, lightness inverted)`, so it follows the player's `color-scheme`; text keeps
11
+ * the nearest lightness that can be read on its ground, because inverting a colour of middle lightness changes nothing;
12
+ * - in `hc` a colour resolves to `--astl-author-ink` or `--astl-author-ground`, set only there. A custom property, not
13
+ * `!important` in the sheet, because it also reaches the copies components keep of their content in shadow roots;
14
+ * - a font size is clamped: relative sizes compound through nesting;
15
+ * - a width stays within its box: an inline `max-width` would beat any cap in a sheet.
16
+ */
17
+ import { INERT_STYLE } from '@astl/core';
18
+ import {
19
+ cleanStyle,
20
+ overStyleColor,
21
+ parseStyleColor,
22
+ type StyleColor,
23
+ type StyleDeclaration,
24
+ styleContrast,
25
+ } from '@astl/core/declarations';
26
+ import { tokens } from '@astl/tokens';
27
+ import { css } from 'lit';
28
+
29
+ /**
30
+ * The contrast text keeps on its ground in the dark: the one the engine asks of the light page (WCAG AA), and a little
31
+ * more, because this module knows the theme's surfaces and not those of the looks, a shade lighter (a test holds the
32
+ * built-in ones to 4.5).
33
+ */
34
+ const MIN_CONTRAST = 4.6;
35
+ const RAW_COLOR = /#[0-9a-f]+|rgba?\([^()]*\)/g;
36
+ const LENGTH = /^[\d.]/;
37
+ const MEASURES: ReadonlySet<string> = new Set(['width', 'max-width', 'inline-size', 'max-inline-size']);
38
+
39
+ /** Off in `hc`: what is drawn on (a fill, a shadow) goes; what is drawn with (text, lines) takes the text colour. */
40
+ const offWith = (name: string): string =>
41
+ name === 'background-color' || name === 'box-shadow' ? '--astl-author-ground' : '--astl-author-ink';
42
+
43
+ const hex = (value: string): StyleColor => parseStyleColor(value) as StyleColor;
44
+ /** The lighter of the theme's surfaces: text sits on both. */
45
+ const DARK_SURFACE = hex(tokens.themes.dark['surface-raised']);
46
+ const DARK_INK = hex(tokens.themes.dark.ink);
47
+
48
+ /** Hue (0 to 6), saturation and lightness (0 to 1). */
49
+ type Hsl = readonly [hue: number, saturation: number, lightness: number];
50
+
51
+ function toHsl([red, green, blue]: StyleColor): Hsl {
52
+ const [r, g, b] = [red / 255, green / 255, blue / 255];
53
+ const max = Math.max(r, g, b);
54
+ const min = Math.min(r, g, b);
55
+ const lightness = (max + min) / 2;
56
+ const chroma = max - min;
57
+ if (chroma === 0) return [0, 0, lightness];
58
+ const hue =
59
+ max === r ? ((g - b) / chroma + 6) % 6 : max === g ? (b - r) / chroma + 2 : (r - g) / chroma + 4;
60
+ return [hue, chroma / (1 - Math.abs(2 * lightness - 1)), lightness];
61
+ }
62
+
63
+ function fromHsl([hue, saturation, lightness]: Hsl, alpha: number): StyleColor {
64
+ const a = saturation * Math.min(lightness, 1 - lightness);
65
+ const channel = (at: number): number => {
66
+ const k = (at + hue * 2) % 12;
67
+ return Math.round((lightness - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))) * 255);
68
+ };
69
+ return [channel(0), channel(8), channel(4), alpha];
70
+ }
71
+
72
+ /** The author's lightness inverted, with hue and saturation kept. */
73
+ function inverted(color: StyleColor): StyleColor {
74
+ const [hue, saturation, lightness] = toHsl(color);
75
+ return fromHsl([hue, saturation, 1 - lightness], color[3]);
76
+ }
77
+
78
+ const contrastOn = (ink: StyleColor, ground: StyleColor): number =>
79
+ styleContrast(overStyleColor(ink, ground), ground);
80
+
81
+ /** `color` with the lightness nearest its own that can be read on `ground`, hue and saturation kept. */
82
+ function legible(color: StyleColor, ground: StyleColor): StyleColor {
83
+ if (contrastOn(color, ground) >= MIN_CONTRAST) return color;
84
+ const [hue, saturation, lightness] = toHsl(color);
85
+ const at = (l: number) => fromHsl([hue, saturation, l], color[3]);
86
+ let reads = contrastOn(at(1), ground) >= contrastOn(at(0), ground) ? 1 : 0;
87
+ let fails = lightness;
88
+ for (let step = 0; step < 8; step++) {
89
+ const middle = (reads + fails) / 2;
90
+ if (contrastOn(at(middle), ground) >= MIN_CONTRAST) reads = middle;
91
+ else fails = middle;
92
+ }
93
+ return at(reads);
94
+ }
95
+
96
+ const written = ([red, green, blue, alpha]: StyleColor): string => {
97
+ const channels = [red, green, blue].map(Math.round).join(', ');
98
+ return alpha === 1 ? `rgb(${channels})` : `rgba(${channels}, ${alpha})`;
99
+ };
100
+
101
+ /** What is known of the dark theme at an element: the ground, and whether an author's colour is the text colour. */
102
+ interface DarkContext {
103
+ readonly ground: StyleColor;
104
+ readonly inked: boolean;
105
+ }
106
+
107
+ const declared = (declarations: readonly StyleDeclaration[], name: string): StyleColor | null => {
108
+ const value = declarations.find(([property]) => property === name)?.[1];
109
+ return value === undefined ? null : parseStyleColor(value);
110
+ };
111
+
112
+ /** The dark theme at an element with these declarations, inside `around`. */
113
+ function darkContext(declarations: readonly StyleDeclaration[], around: DarkContext): DarkContext {
114
+ const inked = around.inked || declared(declarations, 'color') !== null;
115
+ const fill = declared(declarations, 'background-color');
116
+ if (fill === null) return { ground: around.ground, inked };
117
+ const dark = overStyleColor(inverted(fill), around.ground);
118
+ // Without an author's colour, the text is the theme's: the fill is what has to give way.
119
+ return { ground: inked ? dark : legible(dark, DARK_INK), inked };
120
+ }
121
+
122
+ /** A declaration as it is written on the mounted element. */
123
+ function painted(name: string, value: string, context: DarkContext): string {
124
+ if (name === 'font-family') return value;
125
+ if (name === 'font-size') return LENGTH.test(value) ? `clamp(0.625rem, ${value}, 6rem)` : value;
126
+ if (MEASURES.has(name)) return LENGTH.test(value) && !value.endsWith('%') ? `min(${value}, 100%)` : value;
127
+ return value.replace(RAW_COLOR, (raw) => {
128
+ const color = hex(raw);
129
+ const dark =
130
+ name === 'color'
131
+ ? legible(inverted(color), context.ground)
132
+ : name === 'background-color'
133
+ ? context.ground
134
+ : inverted(color);
135
+ return `var(${offWith(name)}, light-dark(${raw}, ${written(dark)}))`;
136
+ });
137
+ }
138
+
139
+ /** Styles taken from a view, by element of the fragment, as they will be written. */
140
+ export type TakenStyles = ReadonlyMap<Element, readonly StyleDeclaration[]>;
141
+
142
+ /** Takes every `style` (read under its parsing name) out of a read view, before `cleanView` removes what is left. */
143
+ export function takeStyles(fragment: DocumentFragment): TakenStyles {
144
+ const taken = new Map<Element, readonly StyleDeclaration[]>();
145
+ const contexts = new Map<Element, DarkContext>();
146
+ const page: DarkContext = { ground: DARK_SURFACE, inked: false };
147
+ // In document order, so what is around an element has been read before it.
148
+ for (const el of Array.from(fragment.querySelectorAll(`[${INERT_STYLE}]`))) {
149
+ const { declarations } = cleanStyle(el.getAttribute(INERT_STYLE) ?? '');
150
+ el.removeAttribute(INERT_STYLE);
151
+ let around = page;
152
+ for (let up = el.parentElement; up !== null; up = up.parentElement) {
153
+ const known = contexts.get(up);
154
+ if (known !== undefined) {
155
+ around = known;
156
+ break;
157
+ }
158
+ }
159
+ const context = darkContext(declarations, around);
160
+ contexts.set(el, context);
161
+ taken.set(
162
+ el,
163
+ declarations.map(([name, value]): StyleDeclaration => [name, painted(name, value, context)]),
164
+ );
165
+ }
166
+ return taken;
167
+ }
168
+
169
+ /** Writes taken styles on `content`, the copy of the cleaned `fragment` that gets mounted: same shape, same order. */
170
+ export function applyStyles(taken: TakenStyles, fragment: DocumentFragment, content: DocumentFragment): void {
171
+ const copies = content.querySelectorAll<HTMLElement>('*');
172
+ fragment.querySelectorAll('*').forEach((el, index) => {
173
+ for (const [name, value] of taken.get(el) ?? []) copies[index]?.style.setProperty(name, value);
174
+ });
175
+ }
176
+
177
+ // Pages hold their floats. `:not([hidden])` because `.canvas astl-page` would otherwise beat `astl-page[hidden]`.
178
+ // An author's `display` must not bring back what the player or a component hides.
179
+ // A page never scrolls sideways whatever is nested in it: the caps stop one element, not ten inside each other.
180
+ // On a narrow player only what an author set gives way, so a coloured word gets no padding; `auto` margins centre.
181
+ const styledSheet = css`
182
+ .canvas {
183
+ container-type: inline-size;
184
+ }
185
+ .canvas astl-doc,
186
+ .canvas astl-page:not([hidden]) {
187
+ display: flow-root;
188
+ }
189
+ .canvas astl-page {
190
+ overflow-x: clip;
191
+ overflow-clip-margin: var(--astl-space-5);
192
+ }
193
+ .canvas [style][hidden] {
194
+ display: none !important;
195
+ }
196
+ .canvas [style] {
197
+ box-sizing: border-box;
198
+ max-inline-size: 100%;
199
+ }
200
+ .canvas astl-columns {
201
+ display: flex;
202
+ flex-wrap: wrap;
203
+ clear: both;
204
+ gap: var(--astl-space-4);
205
+ margin-block-end: var(--astl-space-4);
206
+ }
207
+ .canvas astl-columns > astl-column {
208
+ flex: 1 1 0;
209
+ min-inline-size: min(10rem, 100%);
210
+ }
211
+ .canvas astl-columns > astl-column > :first-child {
212
+ margin-block-start: 0;
213
+ }
214
+ .canvas astl-columns > astl-column > :last-child {
215
+ margin-block-end: 0;
216
+ }
217
+ :host([data-theme='hc']) {
218
+ --astl-author-ink: currentcolor;
219
+ --astl-author-ground: transparent;
220
+ }
221
+ @container (max-inline-size: 30rem) {
222
+ .canvas [style*='float'] {
223
+ float: none !important;
224
+ inline-size: auto !important;
225
+ }
226
+ .canvas [style*='margin']:not([style*='auto']) {
227
+ margin-inline: 0 !important;
228
+ }
229
+ .canvas [style*='padding'] {
230
+ padding-inline: min(var(--astl-space-3), 5%) !important;
231
+ }
232
+ .canvas img[style*='float'] {
233
+ display: block;
234
+ }
235
+ }
236
+ `.styleSheet;
237
+
238
+ /** Adopts the stylesheet of styles and layouts in a player's root, once. */
239
+ export function adoptStyledSheet(root: Node): void {
240
+ if (
241
+ styledSheet !== undefined &&
242
+ root instanceof ShadowRoot &&
243
+ !root.adoptedStyleSheets.includes(styledSheet)
244
+ ) {
245
+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, styledSheet];
246
+ }
247
+ }
@@ -0,0 +1,355 @@
1
+ import { tokensCss } from '@astl/tokens';
2
+ import { type CSSResultGroup, css, unsafeCSS } from 'lit';
3
+ import { verdictStyles, visuallyHidden } from '../a11y.js';
4
+
5
+ export const playerStyles: CSSResultGroup = [
6
+ // Tokens sit on :host so host pages can override any --astl-* property on <astl-player> itself.
7
+ unsafeCSS(tokensCss(':host')),
8
+ visuallyHidden,
9
+ verdictStyles,
10
+ css`
11
+ :host {
12
+ display: block;
13
+ color: var(--astl-ink);
14
+ }
15
+ :host([hidden]) {
16
+ display: none;
17
+ }
18
+ .root {
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: var(--astl-space-4);
22
+ padding: var(--astl-space-4);
23
+ background: var(--astl-canvas);
24
+ color: var(--astl-ink);
25
+ font-family: var(--astl-font-body);
26
+ font-size: var(--astl-size-ui);
27
+ line-height: 1.4;
28
+ }
29
+ .root > * {
30
+ box-sizing: border-box;
31
+ inline-size: 100%;
32
+ max-inline-size: 760px;
33
+ margin-inline: auto;
34
+ }
35
+ .status {
36
+ margin-block: 0;
37
+ color: var(--astl-ink-muted);
38
+ }
39
+ .problem {
40
+ margin-block: 0;
41
+ padding-block: var(--astl-space-3);
42
+ padding-inline: var(--astl-space-4);
43
+ border: var(--astl-outline-width) solid var(--astl-danger);
44
+ border-radius: var(--astl-radius-m);
45
+ background: var(--astl-danger-soft);
46
+ color: var(--astl-ink);
47
+ }
48
+ `,
49
+ // The compiler's issues for the author: plain text, one per line, wrapped inside the column.
50
+ css`
51
+ .problem-details {
52
+ margin-block: 0;
53
+ padding-block: var(--astl-space-3);
54
+ padding-inline: var(--astl-space-4);
55
+ border: var(--astl-outline-width) solid var(--astl-line);
56
+ border-radius: var(--astl-radius-m);
57
+ background: var(--astl-surface);
58
+ color: var(--astl-ink);
59
+ white-space: pre-wrap;
60
+ overflow-wrap: anywhere;
61
+ }
62
+
63
+ .header {
64
+ display: flex;
65
+ flex-wrap: wrap;
66
+ align-items: center;
67
+ gap: var(--astl-space-3) var(--astl-space-5);
68
+ }
69
+ .counter {
70
+ margin-block: 0;
71
+ font-weight: 600;
72
+ }
73
+ .progress {
74
+ display: flex;
75
+ flex-wrap: wrap;
76
+ gap: var(--astl-space-1);
77
+ margin: 0;
78
+ padding: 0;
79
+ list-style: none;
80
+ }
81
+ .segment {
82
+ box-sizing: border-box;
83
+ display: inline-flex;
84
+ align-items: center;
85
+ justify-content: center;
86
+ gap: var(--astl-space-1);
87
+ min-inline-size: var(--astl-target-min);
88
+ min-block-size: var(--astl-target-min);
89
+ padding-inline: var(--astl-space-2);
90
+ border: var(--astl-outline-width) solid var(--astl-outline);
91
+ border-radius: var(--astl-radius-m);
92
+ background: var(--astl-surface);
93
+ color: var(--astl-ink);
94
+ font: inherit;
95
+ font-weight: 600;
96
+ text-decoration: none;
97
+ }
98
+ button.segment {
99
+ cursor: pointer;
100
+ }
101
+ `,
102
+ // Answered state by shape: a full circle for a fully answered page, a half full one for a partly answered one.
103
+ css`
104
+ .segment-icon {
105
+ flex: none;
106
+ inline-size: 0.875em;
107
+ block-size: 0.875em;
108
+ }
109
+ `,
110
+ // The one current-page cue: a filled button (plus aria-current).
111
+ css`
112
+ .segment[aria-current='step'] {
113
+ border-color: var(--astl-accent);
114
+ background: var(--astl-accent);
115
+ color: var(--astl-on-accent);
116
+ }
117
+ .timer {
118
+ margin-block: 0;
119
+ margin-inline-start: auto;
120
+ font-variant-numeric: tabular-nums;
121
+ font-weight: 600;
122
+ }
123
+ .timer-label {
124
+ color: var(--astl-ink-muted);
125
+ font-weight: 400;
126
+ }
127
+ `,
128
+ // The card's edge keeps it visible where surface and canvas are the same colour (hc).
129
+ css`
130
+ .canvas {
131
+ border: var(--astl-outline-width) solid var(--astl-line);
132
+ padding: var(--astl-space-5);
133
+ border-radius: var(--astl-radius-l);
134
+ background: var(--astl-surface);
135
+ color: var(--astl-ink);
136
+ font-size: var(--astl-size-content);
137
+ line-height: var(--astl-line-height-content);
138
+ overflow-wrap: break-word;
139
+ }
140
+ .canvas[hidden],
141
+ astl-page[hidden] {
142
+ display: none;
143
+ }
144
+ astl-doc,
145
+ astl-page {
146
+ display: block;
147
+ }
148
+ .canvas :where(p, ul, ol, blockquote) {
149
+ margin-block: 0 var(--astl-space-4);
150
+ }
151
+ .canvas :where(h2, h3, h4) {
152
+ margin-block: var(--astl-space-5) var(--astl-space-3);
153
+ font-family: var(--astl-font-display);
154
+ line-height: 1.25;
155
+ }
156
+ `,
157
+ // The card's padding is the space at its edges: no extra margin above a page's first block or below its last.
158
+ css`
159
+ .canvas astl-page > :first-child {
160
+ margin-block-start: 0;
161
+ }
162
+ .canvas astl-page > :last-child {
163
+ margin-block-end: 0;
164
+ }
165
+ `,
166
+ // After the content headings and more specific than them: the page heading opens the card, no space above.
167
+ css`
168
+ .canvas .astl-page-heading {
169
+ margin-block: 0 var(--astl-space-4);
170
+ font-size: 1.3em;
171
+ }
172
+ .canvas :where(ul, ol) {
173
+ padding-inline-start: var(--astl-space-5);
174
+ }
175
+ `,
176
+ // Only real links look like links (a sanitised link without a safe href is plain text).
177
+ css`
178
+ .canvas a[href] {
179
+ color: var(--astl-accent);
180
+ }
181
+ .canvas code {
182
+ font-family: var(--astl-font-mono);
183
+ font-size: 0.9em;
184
+ }
185
+ .canvas mark {
186
+ background: var(--astl-warning-soft);
187
+ color: var(--astl-ink);
188
+ }
189
+ .canvas blockquote {
190
+ margin-inline: 0;
191
+ padding-inline-start: var(--astl-space-4);
192
+ border-inline-start: var(--astl-outline-width) solid var(--astl-line);
193
+ }
194
+ `,
195
+ // A component puts the pictures of a child on lines of their own (a card's picture above its label) by setting
196
+ // --astl-picture-display: block on that child from its shadow root: its own CSS cannot reach the pictures inside.
197
+ css`
198
+ .canvas img {
199
+ display: var(--astl-picture-display, inline);
200
+ max-inline-size: 100%;
201
+ block-size: auto;
202
+ vertical-align: middle;
203
+ }
204
+ .canvas figure {
205
+ margin-block: 0 var(--astl-space-4);
206
+ margin-inline: 0;
207
+ }
208
+ .canvas figure img {
209
+ display: block;
210
+ }
211
+ .canvas figcaption {
212
+ margin-block-start: var(--astl-space-2);
213
+ color: var(--astl-ink-muted);
214
+ font-size: var(--astl-size-small);
215
+ }
216
+ .astl-notice {
217
+ display: inline-block;
218
+ margin-block: var(--astl-space-1);
219
+ padding-block: var(--astl-space-1);
220
+ padding-inline: var(--astl-space-3);
221
+ border: var(--astl-outline-width) solid var(--astl-warning);
222
+ border-radius: var(--astl-radius-m);
223
+ background: var(--astl-warning-soft);
224
+ color: var(--astl-ink);
225
+ font-size: var(--astl-size-small);
226
+ line-height: 1.4;
227
+ }
228
+
229
+ .result {
230
+ padding-block: var(--astl-space-4);
231
+ padding-inline: var(--astl-space-5);
232
+ border: var(--astl-outline-width) solid var(--astl-line);
233
+ border-radius: var(--astl-radius-l);
234
+ background: var(--astl-surface);
235
+ }
236
+ .result-title {
237
+ margin-block: 0 var(--astl-space-2);
238
+ font-size: 1.125rem;
239
+ }
240
+ .score {
241
+ margin-block: 0 var(--astl-space-2);
242
+ font-size: 1.25rem;
243
+ font-weight: 700;
244
+ }
245
+ .counts {
246
+ display: flex;
247
+ flex-wrap: wrap;
248
+ gap: var(--astl-space-2) var(--astl-space-4);
249
+ margin: 0;
250
+ padding: 0;
251
+ list-style: none;
252
+ }
253
+ .passed,
254
+ .teacher,
255
+ .practice {
256
+ margin-block: var(--astl-space-2) 0;
257
+ font-weight: 600;
258
+ }
259
+
260
+ .footer {
261
+ display: flex;
262
+ flex-wrap: wrap;
263
+ align-items: center;
264
+ gap: var(--astl-space-3);
265
+ }
266
+ .nav,
267
+ .actions {
268
+ display: flex;
269
+ flex-wrap: wrap;
270
+ align-items: center;
271
+ gap: var(--astl-space-2);
272
+ }
273
+ .actions {
274
+ margin-inline-start: auto;
275
+ }
276
+ .hint {
277
+ color: var(--astl-ink-muted);
278
+ font-size: var(--astl-size-small);
279
+ }
280
+ .button {
281
+ box-sizing: border-box;
282
+ min-inline-size: var(--astl-target-min);
283
+ min-block-size: var(--astl-target-min);
284
+ padding-block: var(--astl-space-2);
285
+ padding-inline: var(--astl-space-4);
286
+ border: var(--astl-outline-width) solid var(--astl-outline);
287
+ border-radius: var(--astl-radius-m);
288
+ background: var(--astl-surface);
289
+ color: var(--astl-ink);
290
+ font: inherit;
291
+ font-weight: 600;
292
+ cursor: pointer;
293
+ transition: background-color var(--astl-duration-fast);
294
+ }
295
+ .button:hover {
296
+ background: var(--astl-accent-soft);
297
+ }
298
+ .button.primary {
299
+ border-color: var(--astl-accent);
300
+ background: var(--astl-accent);
301
+ color: var(--astl-on-accent);
302
+ }
303
+ .button.primary:hover {
304
+ text-decoration: underline;
305
+ }
306
+ `,
307
+ // Unavailable, as the authoring kit draws it: a dashed edge and no fill, so it shows without colour too (in hc the
308
+ // line and muted colours are as dark as the enabled ones). A button is never an answer box, so the dashed edge
309
+ // never reads as a verdict.
310
+ css`
311
+ .button:disabled,
312
+ .button[aria-disabled='true'] {
313
+ border-color: var(--astl-line);
314
+ border-style: dashed;
315
+ background: transparent;
316
+ color: var(--astl-ink-muted);
317
+ text-decoration: none;
318
+ cursor: not-allowed;
319
+ }
320
+ .practice-only {
321
+ margin-block: 0;
322
+ color: var(--astl-ink-muted);
323
+ }
324
+ .confirm {
325
+ display: flex;
326
+ flex-wrap: wrap;
327
+ align-items: center;
328
+ gap: var(--astl-space-3);
329
+ inline-size: 100%;
330
+ padding-block: var(--astl-space-3);
331
+ padding-inline: var(--astl-space-4);
332
+ border: var(--astl-outline-width) solid var(--astl-warning);
333
+ border-radius: var(--astl-radius-m);
334
+ background: var(--astl-warning-soft);
335
+ color: var(--astl-ink);
336
+ }
337
+ .confirm p {
338
+ margin-block: 0;
339
+ }
340
+ :focus-visible {
341
+ outline: var(--astl-focus-width) solid var(--astl-focus);
342
+ outline-offset: var(--astl-focus-offset);
343
+ }
344
+ `,
345
+ // Forced colours draw a Canvas backplate behind text, which hides a HighlightText label on a Highlight fill. The
346
+ // filled controls use only system colours there (the forced tokens), so they keep their own.
347
+ css`
348
+ @media (forced-colors: active) {
349
+ .button.primary,
350
+ .segment[aria-current='step'] {
351
+ forced-color-adjust: none;
352
+ }
353
+ }
354
+ `,
355
+ ];