actual-css 0.16.1 → 0.17.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/README.md +8 -4
  3. package/components.json +19 -4
  4. package/dist/actual.full.css +464 -80
  5. package/dist/actual.full.js +2 -1
  6. package/dist/actual.full.min.css +1 -1
  7. package/docs/design-notes/app-ui.md +37 -3
  8. package/docs/design-notes/enhancement-contract.md +3 -1
  9. package/docs/navigation.json +17 -3
  10. package/docs/pages/components/accordion.md +8 -0
  11. package/docs/pages/components/alert.md +47 -17
  12. package/docs/pages/components/app-navigation.md +2 -2
  13. package/docs/pages/components/aura.md +2 -2
  14. package/docs/pages/components/badge.md +4 -3
  15. package/docs/pages/components/button.md +3 -0
  16. package/docs/pages/components/card.md +1 -1
  17. package/docs/pages/components/chat.md +2 -2
  18. package/docs/pages/components/dialog.md +36 -0
  19. package/docs/pages/components/drawer.md +52 -8
  20. package/docs/pages/components/fab.md +2 -1
  21. package/docs/pages/components/list.md +1 -1
  22. package/docs/pages/components/meter.md +1 -1
  23. package/docs/pages/components/navbar.md +27 -3
  24. package/docs/pages/components/overview.md +17 -0
  25. package/docs/pages/components/rating.md +111 -12
  26. package/docs/pages/components/segmented.md +36 -1
  27. package/docs/pages/components/shimmer.md +2 -2
  28. package/docs/pages/components/spinner.md +2 -0
  29. package/docs/pages/components/table.md +77 -0
  30. package/docs/pages/components/timeline.md +3 -1
  31. package/docs/pages/enhancements/flyout.md +83 -14
  32. package/docs/pages/enhancements/overview.md +2 -2
  33. package/docs/pages/enhancements/status-bar.md +1 -1
  34. package/docs/pages/enhancements/tabs.md +5 -0
  35. package/docs/pages/examples/overview.md +5 -1
  36. package/docs/pages/forms/ajax.md +101 -0
  37. package/docs/pages/forms/choice-cards.md +1 -1
  38. package/docs/pages/forms/color-swatches.md +31 -2
  39. package/docs/pages/forms/detached-actions.md +1 -1
  40. package/docs/pages/forms/floating-field.md +5 -3
  41. package/docs/pages/forms/form-actions.md +1 -1
  42. package/docs/pages/forms/input-policy.md +1 -1
  43. package/docs/pages/forms/joined-controls.md +9 -4
  44. package/docs/pages/forms/otp.md +2 -2
  45. package/docs/pages/forms/overview.md +1 -1
  46. package/docs/pages/forms/password.md +1 -1
  47. package/docs/pages/forms/states-and-sizes.md +1 -1
  48. package/docs/pages/forms/sticky-actions.md +1 -1
  49. package/docs/pages/forms/unsaved-changes.md +198 -0
  50. package/docs/pages/foundations/philosophy.md +2 -1
  51. package/docs/pages/foundations/theming.md +4 -3
  52. package/docs/pages/foundations/tokens.md +30 -5
  53. package/docs/pages/foundations/typography.md +1 -1
  54. package/docs/pages/guides/introduction.md +1 -1
  55. package/docs/pages/guides/progressive-enhancement.md +31 -50
  56. package/docs/pages/guides/upgrading.md +15 -2
  57. package/docs/pages/layout/app-layout.md +1 -1
  58. package/docs/pages/layout/app-shell.md +1 -1
  59. package/docs/pages/layout/choosing.md +5 -0
  60. package/docs/pages/layout/column-layout.md +23 -9
  61. package/docs/pages/layout/media.md +1 -1
  62. package/docs/pages/layout/overview.md +1 -1
  63. package/docs/pages/layout/scroll-snap.md +1 -1
  64. package/docs/pages/layout/scroll-target.md +1 -1
  65. package/docs/pages/layout/sidebar-layout.md +1 -1
  66. package/docs/pages/layout/sidebar-shell.md +68 -0
  67. package/docs/pages/patterns/code-block.md +1 -1
  68. package/docs/pages/patterns/empty-state.md +74 -0
  69. package/docs/pages/patterns/exclusive-accordion.md +1 -1
  70. package/docs/pages/patterns/hierarchical-nav.md +41 -20
  71. package/docs/pages/patterns/icon-input.md +1 -1
  72. package/docs/pages/patterns/intent-nesting.md +1 -1
  73. package/docs/pages/patterns/navigation-list.md +5 -62
  74. package/docs/pages/patterns/overview.md +1 -1
  75. package/docs/pages/patterns/stat.md +61 -0
  76. package/docs/pages/patterns/structured-lists.md +1 -1
  77. package/docs/pages/utilities/accessibility.md +32 -10
  78. package/docs/pages/utilities/flex.md +1 -1
  79. package/docs/pages/utilities/links.md +1 -1
  80. package/docs/pages/utilities/list.md +1 -1
  81. package/docs/pages/utilities/shape.md +1 -1
  82. package/docs/pages/utilities/sizing-wrapping.md +1 -1
  83. package/docs/pages/utilities/spacing.md +1 -1
  84. package/docs/pages/utilities/text.md +1 -1
  85. package/package.json +4 -1
  86. package/reserved-classes.json +2 -0
  87. package/src/cli/actual-css.js +4 -4
  88. package/src/css/components/accordion.css +10 -6
  89. package/src/css/components/alert.css +4 -0
  90. package/src/css/components/busy.css +25 -0
  91. package/src/css/components/button.css +3 -0
  92. package/src/css/components/drawer.css +37 -3
  93. package/src/css/components/flyout.css +37 -0
  94. package/src/css/components/join.css +14 -0
  95. package/src/css/components/modal.css +3 -0
  96. package/src/css/components/navbar.css +102 -38
  97. package/src/css/components/rating.css +50 -5
  98. package/src/css/components/segmented.css +25 -2
  99. package/src/css/core/theme.css +20 -1
  100. package/src/css/core/tokens.css +4 -1
  101. package/src/css/forms/color-swatch.css +38 -19
  102. package/src/css/forms/custom-select.css +10 -0
  103. package/src/css/forms/input-icon.css +5 -3
  104. package/src/css/layout/index.css +2 -0
  105. package/src/css/layout/sidebar-shell.css +67 -0
  106. package/src/css/typography/prose.css +6 -0
  107. package/src/js/ajax.js +148 -0
  108. package/src/js/dialog.js +59 -2
  109. package/src/js/dirty.js +140 -0
  110. package/src/js/dismiss.js +25 -0
  111. package/src/js/events.js +17 -0
  112. package/src/js/focus.js +12 -0
  113. package/src/js/form-submission.js +34 -0
  114. package/src/js/full.js +2 -0
  115. package/src/js/tab.js +16 -2
  116. package/src/js/validation.js +12 -4
  117. package/src/tooling/design-tokens.js +1 -0
  118. package/src/tooling/theme-contrast.js +44 -4
  119. package/tokens.json +1 -0
@@ -0,0 +1,140 @@
1
+ /*
2
+ * Dirty — optional unsaved-changes tracking for forms.
3
+ *
4
+ * Opt in with data-enhance="dirty". The form carries data-dirty while the
5
+ * data it would submit differs from its baseline, and dispatches
6
+ * actual:dirty-change ({ form, dirty }) after each transition. The event
7
+ * reports state; it cannot veto it.
8
+ *
9
+ * The module observes, it never submits and never guards navigation: the
10
+ * transport (native, fetch, htmx, a library) decides when data is saved and
11
+ * tells the module through FormDirty.markClean().
12
+ *
13
+ * Comparison runs on FormData, so it covers exactly what would be submitted:
14
+ * disabled and unnamed controls do not count, form-associated controls
15
+ * outside the <form> do. Controls marked data-dirty-ignore are left out by
16
+ * name (CSRF tokens, computed fields).
17
+ */
18
+
19
+ import { registerEnhancement } from "./enhance.js";
20
+ import { EVENTS } from "./events.js";
21
+
22
+ const ATTR = "data-dirty";
23
+ const IGNORE_ATTR = "data-dirty-ignore";
24
+
25
+ // Baselines outlive the enhancer instance on purpose: a form removed and
26
+ // reinserted keeps its baseline, so moving or re-parenting it does not
27
+ // silently mark unsaved edits as clean.
28
+ const baselines = new WeakMap();
29
+ const connected = new WeakSet();
30
+
31
+ function isFormElement(el) {
32
+ return typeof HTMLFormElement !== "undefined" && el instanceof HTMLFormElement;
33
+ }
34
+
35
+ function ignoredNames(form) {
36
+ const names = new Set();
37
+ for (const el of form.elements) {
38
+ if (el.hasAttribute(IGNORE_ATTR) && el.name) names.add(el.name);
39
+ }
40
+ return names;
41
+ }
42
+
43
+ // A file is compared by identity hints, not content: two different files with
44
+ // the same name, size and timestamp read as unchanged. An empty file input
45
+ // still yields an entry, whose lastModified is "now" — normalized so an
46
+ // untouched input stays clean.
47
+ function fileKey(file) {
48
+ if (file.name === "" && file.size === 0) return [];
49
+ return [file.name, file.size, file.lastModified];
50
+ }
51
+
52
+ /**
53
+ * Serializes the data the form would submit, in submission order.
54
+ * new FormData(form) fires the form's formdata event, so an entry a listener
55
+ * adds there counts too; a volatile one (a nonce) keeps the form dirty unless
56
+ * it shares a name with a data-dirty-ignore control.
57
+ */
58
+ function capture(form) {
59
+ if (!isFormElement(form)) throw new TypeError("FormDirty expects an HTMLFormElement.");
60
+ const ignored = ignoredNames(form);
61
+ const entries = [];
62
+ for (const [name, value] of new FormData(form)) {
63
+ if (ignored.has(name)) continue;
64
+ entries.push([name, typeof value === "string" ? value : fileKey(value)]);
65
+ }
66
+ // JSON keeps names and values unambiguous: no separator a value can forge.
67
+ return JSON.stringify(entries);
68
+ }
69
+
70
+ function refresh(form) {
71
+ if (!connected.has(form)) return;
72
+ const dirty = capture(form) !== baselines.get(form);
73
+ if (dirty === form.hasAttribute(ATTR)) return;
74
+ form.toggleAttribute(ATTR, dirty);
75
+ form.dispatchEvent(
76
+ new CustomEvent(EVENTS.dirtyChange, { bubbles: true, detail: { form, dirty } }),
77
+ );
78
+ }
79
+
80
+ function connectForm(form) {
81
+ if (!baselines.has(form)) baselines.set(form, capture(form));
82
+ connected.add(form);
83
+
84
+ const controller = new AbortController();
85
+ const options = { signal: controller.signal };
86
+ const update = () => refresh(form);
87
+ const onEdit = ({ target }) => {
88
+ // A form-associated custom element exposes no .form on its host, but it
89
+ // is listed in form.elements like any native control.
90
+ if (target.form === form || Array.prototype.includes.call(form.elements, target)) update();
91
+ };
92
+
93
+ // Listen on the root: a control associated through form="…" sits outside
94
+ // the <form>, so its events never bubble through it.
95
+ const root = form.getRootNode();
96
+ root.addEventListener("input", onEdit, options);
97
+ root.addEventListener("change", onEdit, options);
98
+ // The reset event fires before the controls revert, and microtasks would
99
+ // run between listeners of a user-initiated reset — still too early. A task
100
+ // runs after the reset algorithm completes.
101
+ form.addEventListener("reset", () => setTimeout(update), options);
102
+
103
+ refresh(form);
104
+
105
+ // Release listeners only: data-dirty and the baseline stay, like validation
106
+ // state, so a reinserted form resumes where it was.
107
+ return () => {
108
+ controller.abort();
109
+ connected.delete(form);
110
+ };
111
+ }
112
+
113
+ // biome-ignore lint/complexity/noStaticOnlyClass: Stable public namespace, like FormValidator.
114
+ export class FormDirty {
115
+ /**
116
+ * Opaque snapshot of what the form would submit. Take it at submit time
117
+ * and pass it to markClean() once that submission is saved, so edits
118
+ * made during the request stay dirty.
119
+ */
120
+ static capture(form) {
121
+ return capture(form);
122
+ }
123
+
124
+ /**
125
+ * Makes `snapshot` (default: current data) the new baseline. Also valid
126
+ * before the form is enhanced: connection keeps an existing baseline.
127
+ */
128
+ static markClean(form, snapshot) {
129
+ if (!isFormElement(form)) return;
130
+ baselines.set(form, snapshot ?? capture(form));
131
+ refresh(form);
132
+ }
133
+
134
+ /** Re-evaluates an enhanced form after programmatic edits or added controls. */
135
+ static refresh(form) {
136
+ if (isFormElement(form)) refresh(form);
137
+ }
138
+ }
139
+
140
+ registerEnhancement("dirty", (el) => (isFormElement(el) ? connectForm(el) : undefined));
package/src/js/dismiss.js CHANGED
@@ -1,13 +1,32 @@
1
1
  /*
2
2
  * Dismiss command — the generic `--dismiss` action. Hides the resolved target
3
3
  * and emits the bubbling `actual:dismiss` event.
4
+ *
5
+ * Focus contract: when focus is inside the target (the usual case, a close
6
+ * button in an alert), it moves to the next tab stop after the target, else to
7
+ * the nearest ancestor with an explicit tabindex; with neither, the browser's
8
+ * focus fixup applies. Focus outside the target is left alone, and so is focus
9
+ * a listener of `actual:dismiss` placed itself (a surface restores its opener).
4
10
  */
5
11
 
6
12
  import { registerCommands } from "./command.js";
7
13
  import { EVENTS } from "./events.js";
14
+ import { isElementVisible, nextTabStop } from "./focus.js";
15
+
16
+ function focusSuccessor(target) {
17
+ const next = nextTabStop(target);
18
+ if (next) return next;
19
+ const region = target.parentElement?.closest("[tabindex]");
20
+ return region && isElementVisible(region) && !region.closest("[inert]") ? region : null;
21
+ }
8
22
 
9
23
  registerCommands("--dismiss", {
10
24
  handle(_event, trigger, target) {
25
+ const doc = target.ownerDocument;
26
+ // Resolved before hiding: a browser may move focus as soon as the focused
27
+ // element is hidden, so a check made afterwards would miss it, and the
28
+ // successor search needs the target's descendants still visible to skip.
29
+ const successor = target.contains(doc.activeElement) ? focusSuccessor(target) : null;
11
30
  target.hidden = true;
12
31
  target.dispatchEvent(
13
32
  new CustomEvent(EVENTS.dismiss, {
@@ -15,5 +34,11 @@ registerCommands("--dismiss", {
15
34
  detail: { trigger },
16
35
  }),
17
36
  );
37
+ // Only when focus is still stranded: in the hidden target, or dropped to
38
+ // <body> by the browser. No scroll: the next Tab scrolls to the successor.
39
+ const active = doc.activeElement;
40
+ if (successor && (!active || active === doc.body || target.contains(active))) {
41
+ successor.focus({ preventScroll: true });
42
+ }
18
43
  },
19
44
  });
package/src/js/events.js CHANGED
@@ -13,6 +13,23 @@ export const EVENTS = {
13
13
  // Dispatched by a form after validation blocks submission.
14
14
  // detail: { form, firstInvalid, message }
15
15
  invalid: `${ACTUAL_EVENT_PREFIX}:invalid`,
16
+ // Dispatched by a dirty-tracked form after data-dirty flips.
17
+ // detail: { form, dirty }
18
+ dirtyChange: `${ACTUAL_EVENT_PREFIX}:dirty-change`,
19
+ // Dispatched by an ajax form when its request starts.
20
+ // detail: { form, submitter }
21
+ ajaxStart: `${ACTUAL_EVENT_PREFIX}:ajax-start`,
22
+ // Dispatched by an ajax form with any HTTP response: after display, or
23
+ // before navigating to a redirect. From the root when display replaced the
24
+ // form.
25
+ // detail: { form, submitter, response }
26
+ ajaxResponse: `${ACTUAL_EVENT_PREFIX}:ajax-response`,
27
+ // Dispatched by an ajax form when the request fails (network, CORS).
28
+ // detail: { form, submitter, error }
29
+ ajaxError: `${ACTUAL_EVENT_PREFIX}:ajax-error`,
30
+ // Dispatched by a tablist after its selection changed, never at connect.
31
+ // detail: { tab, panel, previousTab }
32
+ tabChange: `${ACTUAL_EVENT_PREFIX}:tab-change`,
16
33
  // Cancelable: dispatched by dialog.js before handling native cancel close.
17
34
  // detail: { dialog, sourceEvent }
18
35
  dialogCancel: `${ACTUAL_EVENT_PREFIX}:dialog-cancel`,
package/src/js/focus.js CHANGED
@@ -59,6 +59,18 @@ function isRadioTabStop(el) {
59
59
  );
60
60
  }
61
61
 
62
+ /* The first tab stop after `node` in document order, outside `node` itself.
63
+ Document order, not tabindex order: positive tabindex is not a supported
64
+ pattern here. */
65
+ export function nextTabStop(node) {
66
+ return getFocusable(node.ownerDocument)
67
+ .filter(isRadioTabStop)
68
+ .find(
69
+ (el) =>
70
+ !node.contains(el) && node.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_FOLLOWING,
71
+ );
72
+ }
73
+
62
74
  export function focusFirstDescendant(root) {
63
75
  const target = getFocusable(root).filter(isRadioTabStop)[0];
64
76
  target?.focus();
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Form submission settings as the browser resolves them.
3
+ *
4
+ * A control named "action", "method", "enctype" or "target" shadows the
5
+ * form's own property (form.action returns the <input>), so the values are
6
+ * read through the HTMLFormElement prototype, never as form[name].
7
+ */
8
+
9
+ function formProperty(form, name) {
10
+ return Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, name).get.call(form);
11
+ }
12
+
13
+ /**
14
+ * Reads action, method, enctype or target: a submitter's form* attribute
15
+ * overrides the form's own, as natively. Reflected values, so method and
16
+ * enctype come back lowercase and action as an absolute URL.
17
+ */
18
+ export function submissionSetting(form, submitter, name) {
19
+ return submitter?.hasAttribute(`form${name}`)
20
+ ? submitter[`form${name[0].toUpperCase()}${name.slice(1)}`]
21
+ : formProperty(form, name);
22
+ }
23
+
24
+ /**
25
+ * The browsing context name the submission goes to, "" for the page itself.
26
+ * Without a target attribute the form falls back to <base target>; an empty
27
+ * formtarget="" is still an attribute and means the page itself.
28
+ */
29
+ export function submissionTarget(form, submitter) {
30
+ if (submitter?.hasAttribute("formtarget") || form.hasAttribute("target")) {
31
+ return submissionSetting(form, submitter, "target");
32
+ }
33
+ return form.ownerDocument.querySelector("base[target]")?.target ?? "";
34
+ }
package/src/js/full.js CHANGED
@@ -25,6 +25,8 @@ import "./mask.js";
25
25
  import "./password.js";
26
26
  import "./range.js";
27
27
  import "./validation.js";
28
+ import "./dirty.js";
29
+ import "./ajax.js";
28
30
  import "./status.js";
29
31
  import "./index.js";
30
32
 
package/src/js/tab.js CHANGED
@@ -11,6 +11,8 @@
11
11
  * [hidden], disabled and panel-less tabs are skipped
12
12
  * Overflow: a horizontal strip shows its whole selected tab, at connect and
13
13
  * on every selection
14
+ * Event: actual:tab-change bubbles from the tablist when the selection
15
+ * changes, not at connect
14
16
  *
15
17
  * Self-registers via registerEnhancement: injected tablists wire automatically.
16
18
  * The tab→panel map is rebuilt from the live tablist on each interaction,
@@ -19,6 +21,7 @@
19
21
  */
20
22
 
21
23
  import { registerEnhancement } from "./enhance.js";
24
+ import { EVENTS } from "./events.js";
22
25
  import { ensureInlineVisible } from "./inline-visible.js";
23
26
  import { itemForKey, shouldIgnoreKey } from "./keys.js";
24
27
  import { afterParse } from "./parsed.js";
@@ -68,12 +71,16 @@ function makePanelFocusable(panel) {
68
71
  }
69
72
  }
70
73
 
71
- function activate(tab) {
74
+ /* Every selection path runs through here, so the change event cannot be
75
+ forgotten by one of them. Initialization passes notify: false: it settles
76
+ the markup's state, it is not a transition; read aria-selected for that. */
77
+ function activate(tab, { notify = true } = {}) {
72
78
  if (!tab || isTabDisabled(tab) || !panelFor(tab)) return;
73
79
  const list = tab.closest(TABLIST_SELECTOR);
74
80
  if (!list) return;
75
81
  const tabs = tabsOf(list);
76
82
  const panels = panelsOf(tabs);
83
+ const previousTab = tabs.find((t) => t.getAttribute("aria-selected") === "true") ?? null;
77
84
 
78
85
  for (const t of tabs) {
79
86
  t.setAttribute("aria-selected", "false");
@@ -89,6 +96,13 @@ function activate(tab) {
89
96
  makePanelFocusable(panel);
90
97
  panel.hidden = false;
91
98
  }
99
+
100
+ // After the DOM update, so a listener reads the new state.
101
+ if (notify && tab !== previousTab) {
102
+ list.dispatchEvent(
103
+ new CustomEvent(EVENTS.tabChange, { bubbles: true, detail: { tab, panel, previousTab } }),
104
+ );
105
+ }
92
106
  }
93
107
 
94
108
  /* An overflowing horizontal strip shows the whole tab. At connect a
@@ -110,7 +124,7 @@ function initialize(list) {
110
124
  const tabs = activatableTabs(list);
111
125
  if (!tabs.length) return;
112
126
  const selected = tabs.find((tab) => tab.getAttribute("aria-selected") === "true") || tabs[0];
113
- activate(selected);
127
+ activate(selected, { notify: false });
114
128
  reveal(list, selected);
115
129
  }
116
130
 
@@ -269,13 +269,21 @@ function validateField(el, trigger) {
269
269
 
270
270
  if (!wantsTrigger && !alreadyInvalid) return;
271
271
 
272
- if (checkRules(el)) {
273
- markValid(el);
274
- } else {
275
- markInvalid(el);
272
+ const valid = checkRules(el);
273
+ for (const member of radioGroup(el)) {
274
+ if (valid) markValid(member);
275
+ else markInvalid(member);
276
276
  }
277
277
  }
278
278
 
279
+ // A radio's validity is its group's: picking one fills a required group, so
280
+ // the result applies to every radio of the name. Marking only the picked one
281
+ // left its siblings aria-invalid and the field error showing.
282
+ function radioGroup(el) {
283
+ if (el.type !== "radio" || !el.name || !el.form) return [el];
284
+ return [...el.form.elements].filter((other) => other.type === "radio" && other.name === el.name);
285
+ }
286
+
279
287
  function connectForm(form) {
280
288
  const existing = connectedForms.get(form);
281
289
  if (existing) return existing;
@@ -128,6 +128,7 @@ export const NOT_EXPORTED = {
128
128
  "soft-border-mix",
129
129
  "soft-hover-alpha",
130
130
  "soft-fg-mix",
131
+ "border-control-mix",
131
132
  "focus-outline-color",
132
133
  ],
133
134
  "soft recipe, exported with the components": [
@@ -5,6 +5,7 @@
5
5
  * (`bun run report:theme-contrast`).
6
6
  *
7
7
  * Measured per island (one per color scheme the theme declares):
8
+ * - the resting edge of a field, checkbox and radio against --surface (3:1)
8
9
  * - soft ink against the resting and the hovered soft fill (4.5:1), on each
9
10
  * surface a soft element sits on
10
11
  * - the solid pairs, -fg on the intent fill (4.5:1); a fill painted by a
@@ -64,9 +65,21 @@ function islandMarkup(id, scheme) {
64
65
  <span data-pair="focus-solid" style="color: var(--focus); background: var(--surface-solid)"></span>
65
66
  <span data-pair="inverse" style="color: var(--surface-solid-fg); background: var(--surface-solid)"></span>
66
67
  <input class="input" aria-invalid="true" data-pair="invalid-field" aria-label="t">
68
+ <div data-controls style="background: var(--surface)">
69
+ ${CONTROLS.map(([kind, markup]) => markup.replace("<input", `<input data-control="${kind}" aria-label="t"`)).join("")}
70
+ </div>
67
71
  </div>`;
68
72
  }
69
73
 
74
+ /* Controls whose resting edge is all that identifies them (WCAG 1.4.11): the
75
+ edge against the surface around them needs 3:1. The field is read on its
76
+ block-end side, the one an underline-only theme (material) keeps. */
77
+ export const CONTROLS = [
78
+ ["field", '<input class="input">'],
79
+ ["checkbox", '<input class="check" type="checkbox">'],
80
+ ["radio", '<input class="radio" type="radio">'],
81
+ ];
82
+
70
83
  const ratio = (fg, bg) => (fg[3] < 255 || bg[3] < 255 ? null : contrast(fg, bg));
71
84
 
72
85
  /*
@@ -186,12 +199,20 @@ export async function measureContrast({ css, themes, label = "default" }) {
186
199
  selected,
187
200
  };
188
201
  }
189
- return { pairs, soft, solid };
202
+ const box = island.querySelector("[data-controls]");
203
+ const controls = { backdrop: rgba(cs(box).backgroundColor), edges: {} };
204
+ for (const el of box.querySelectorAll("[data-control]")) {
205
+ const s = cs(el);
206
+ controls.edges[el.dataset.control] = rgba(
207
+ el.dataset.control === "field" ? s.borderBlockEndColor : s.borderTopColor,
208
+ );
209
+ }
210
+ return { pairs, soft, solid, controls };
190
211
  });
191
212
  })()`);
192
213
 
193
214
  return islands.map(({ theme, scheme }, i) => {
194
- const { pairs, soft, solid } = colors[i];
215
+ const { pairs, soft, solid, controls } = colors[i];
195
216
  const pair = (key) => ratio(pairs[key].fg, pairs[key].bg);
196
217
  // Fill over the surface, then ink over the fill: the colors the page shows.
197
218
  const shown = (fg, fill, backdrop) => {
@@ -210,8 +231,9 @@ export async function measureContrast({ css, themes, label = "default" }) {
210
231
  intent,
211
232
  value: solid[intent] ? ratio(solid[intent].fg, solid[intent].bg) : null,
212
233
  })),
213
- // Selected ink on a regular surface (--state-selected-text): text needs
214
- // 4.5:1, the current step's ring is a non-text accent at 3:1.
234
+ // Selected ink on a regular surface (--state-selected-text for tab and
235
+ // step; --text on its tint for the current nav link): text needs 4.5:1,
236
+ // the current step's ring is a non-text accent at 3:1.
215
237
  selected: SURFACES.flatMap((surface) => {
216
238
  const { selected } = soft[surface];
217
239
  return [
@@ -231,6 +253,15 @@ export async function measureContrast({ css, themes, label = "default" }) {
231
253
  hover: shown(fills[intent].fg, fills[intent].hover, backdrop),
232
254
  }));
233
255
  }),
256
+ // A translucent edge is composited over the surface; a translucent
257
+ // surface has no defined backdrop and reads n/a.
258
+ controls: CONTROLS.map(([kind]) => ({
259
+ kind,
260
+ value:
261
+ controls.backdrop[3] < 255
262
+ ? null
263
+ : ratio(composite(controls.edges[kind], controls.backdrop), controls.backdrop),
264
+ })),
234
265
  focusSurface: pair("focus-surface"),
235
266
  focusSolid: pair("focus-solid"),
236
267
  invalidFocus: pair("invalid-field"),
@@ -327,6 +358,15 @@ export function formatContrast(rows) {
327
358
  );
328
359
  }
329
360
 
361
+ lines.push("", "Control edge at rest (--border-control vs --surface), needs 3:1.", "");
362
+ lines.push(`${"theme".padEnd(width)} scheme control ratio`);
363
+ for (const row of rows) {
364
+ for (const { kind, value } of row.controls ?? []) {
365
+ const c = cell(value, 3);
366
+ lines.push(`${head(row)} ${kind.padEnd(9)} ${c.text.padStart(8)}${flag([c], 3)}`);
367
+ }
368
+ }
369
+
330
370
  // Documented exception (focus.css): an invalid field focuses in
331
371
  // --form-invalid-border. The line is inset, so it reads against the
332
372
  // field's own background, not the surface around it.
package/tokens.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "--bar-height",
7
7
  "--border",
8
8
  "--border-control",
9
+ "--border-control-mix",
9
10
  "--border-width",
10
11
  "--choice-control-size",
11
12
  "--control-default-bg",