actual-css 0.19.5 → 0.20.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 (73) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +4 -4
  3. package/components.json +6 -3
  4. package/dist/actual.full.css +266 -55
  5. package/dist/actual.full.js +2 -2
  6. package/dist/actual.full.min.css +1 -1
  7. package/dist/types/menu.d.ts +2 -5
  8. package/docs/pages/components/accordion.md +11 -6
  9. package/docs/pages/components/alert.md +64 -62
  10. package/docs/pages/components/avatar.md +12 -12
  11. package/docs/pages/components/badge.md +15 -15
  12. package/docs/pages/components/breadcrumb.md +10 -8
  13. package/docs/pages/components/button.md +66 -7
  14. package/docs/pages/components/card.md +21 -21
  15. package/docs/pages/components/dialog.md +97 -69
  16. package/docs/pages/components/drawer.md +33 -33
  17. package/docs/pages/components/indicator.md +12 -12
  18. package/docs/pages/components/navbar.md +41 -9
  19. package/docs/pages/components/pagination.md +7 -7
  20. package/docs/pages/components/progress.md +18 -13
  21. package/docs/pages/components/rating.md +19 -19
  22. package/docs/pages/components/reveal.md +2 -0
  23. package/docs/pages/components/segmented.md +35 -31
  24. package/docs/pages/components/skeleton.md +10 -8
  25. package/docs/pages/components/spinner.md +21 -15
  26. package/docs/pages/components/table.md +26 -28
  27. package/docs/pages/enhancements/flyout.md +94 -43
  28. package/docs/pages/enhancements/in-view.md +3 -1
  29. package/docs/pages/enhancements/scrollspy.md +51 -18
  30. package/docs/pages/enhancements/tabs.md +43 -37
  31. package/docs/pages/enhancements/tooltip.md +4 -2
  32. package/docs/pages/forms/ajax.md +66 -0
  33. package/docs/pages/forms/choice-cards.md +8 -8
  34. package/docs/pages/forms/color-swatches.md +12 -12
  35. package/docs/pages/forms/form-actions.md +23 -0
  36. package/docs/pages/forms/joined-controls.md +7 -7
  37. package/docs/pages/forms/labels.md +11 -11
  38. package/docs/pages/forms/overview.md +35 -29
  39. package/docs/pages/forms/states-and-sizes.md +9 -9
  40. package/docs/pages/forms/switch.md +35 -4
  41. package/docs/pages/forms/validation.md +16 -16
  42. package/docs/pages/foundations/theming.md +32 -2
  43. package/docs/pages/foundations/tokens.md +7 -5
  44. package/docs/pages/guides/coding-agents.md +18 -0
  45. package/docs/pages/guides/introduction.md +1 -1
  46. package/package.json +4 -1
  47. package/reserved-classes.json +1 -0
  48. package/skills/actual-css/SKILL.md +7 -0
  49. package/src/cli/actual-css.js +1 -1
  50. package/src/css/components/badge.css +10 -6
  51. package/src/css/components/button.css +20 -7
  52. package/src/css/components/join.css +14 -4
  53. package/src/css/components/meter.css +14 -0
  54. package/src/css/components/navbar.css +83 -1
  55. package/src/css/components/pagination.css +3 -1
  56. package/src/css/components/segmented.css +27 -7
  57. package/src/css/components/timeline.css +3 -1
  58. package/src/css/core/theme.css +11 -9
  59. package/src/css/core/tokens.css +7 -1
  60. package/src/css/core/variants.css +2 -0
  61. package/src/css/effects/reveal.css +15 -6
  62. package/src/css/forms/control.css +11 -1
  63. package/src/css/forms/form.css +14 -4
  64. package/src/css/forms/switch.css +32 -7
  65. package/src/js/ajax.js +18 -1
  66. package/src/js/context-menu.js +1 -3
  67. package/src/js/flyout.js +14 -5
  68. package/src/js/in-view.js +41 -30
  69. package/src/js/menu.js +9 -21
  70. package/src/js/surface.js +38 -0
  71. package/src/tooling/design-tokens.js +1 -0
  72. package/src/tooling/theme-contrast.js +22 -11
  73. package/tokens.json +1 -0
package/src/js/flyout.js CHANGED
@@ -6,6 +6,10 @@ import { connectMenu, focusFirstMenuItem, focusLastMenuItem } from "./menu.js";
6
6
  import { closeSurface, isSurfaceOpen, openSurface, retainSurface } from "./surface.js";
7
7
 
8
8
  const triggerMap = new WeakMap();
9
+ // Which trigger opened each panel. Only that one sends Tab into the panel: a
10
+ // second trigger after the panel would otherwise send focus back in forever
11
+ // (link, second trigger, link…), since the panel's last stop leads to it.
12
+ const openers = new WeakMap();
9
13
 
10
14
  function readFlyoutOptions(panel) {
11
15
  const opts = { autoClose: "true" };
@@ -37,11 +41,13 @@ function isAriaMenu(panel) {
37
41
  }
38
42
 
39
43
  function openFlyout(panel, trigger) {
40
- return openSurface(panel, {
44
+ const opened = openSurface(panel, {
41
45
  trigger,
42
46
  source: trigger,
43
47
  ...readFlyoutOptions(panel),
44
48
  });
49
+ if (opened) openers.set(panel, trigger);
50
+ return opened;
45
51
  }
46
52
 
47
53
  function openAndFocusPanel(flyout, trigger) {
@@ -87,7 +93,12 @@ function onTriggerKeydown(e) {
87
93
  else openAndFocusPanel(panel, trigger);
88
94
  break;
89
95
  case "Tab":
90
- if (isSurfaceOpen(panel) && !e.shiftKey && focusFirstDescendant(panel)) {
96
+ if (
97
+ isSurfaceOpen(panel) &&
98
+ openers.get(panel) === trigger &&
99
+ !e.shiftKey &&
100
+ focusFirstDescendant(panel)
101
+ ) {
91
102
  e.preventDefault();
92
103
  }
93
104
  break;
@@ -160,9 +171,7 @@ function resolvePanel(trigger, state) {
160
171
  state.panel = panel;
161
172
 
162
173
  if (isMenuFlyout(panel)) {
163
- state.releaseMenu = connectMenu(panel, {
164
- close: (menu) => closeSurface(menu),
165
- });
174
+ state.releaseMenu = connectMenu(panel);
166
175
  }
167
176
  if (!trigger.hasAttribute("aria-haspopup") && isAriaMenu(panel)) {
168
177
  trigger.setAttribute("aria-haspopup", "menu");
package/src/js/in-view.js CHANGED
@@ -17,9 +17,10 @@
17
17
  *
18
18
  * A pending element keeps its text in the accessibility tree and in the tab
19
19
  * order; effects hide it with opacity alone. `focusin` releases it at once and
20
- * finishes the entrance it started, so keyboard focus never lands on invisible
21
- * or fading content. In-page find still matches the text, because nothing is
22
- * removed from the layer.
20
+ * finishes its entrance, also when the element was already released and the
21
+ * entrance is still running or waiting out a delay, so keyboard focus never
22
+ * lands on invisible or fading content. In-page find still matches the text,
23
+ * because nothing is removed from the layer.
23
24
  *
24
25
  * One initial IntersectionObserver per document protects content already in
25
26
  * view. Optional data-in-view-margin values share additional observers for
@@ -82,31 +83,42 @@ function triggerFor(connection, margin) {
82
83
  return observer;
83
84
  }
84
85
 
86
+ // Releasing the state also records the entrance it leaves running, so focus
87
+ // can finish it later. The entrance is what the release started, found by
88
+ // difference, plus what already runs on the element and its direct children:
89
+ // an element visible at load never goes pending and plays its first-render
90
+ // entrance instead. The runtime still names no effect, and a deeper component's
91
+ // own motion is left alone.
85
92
  function reveal(record) {
86
93
  if (record.done) return;
87
94
  record.done = true;
88
- record.element.classList.remove(CLASSES.pending);
89
- record.initialObserver.unobserve(record.element);
90
- record.observer.unobserve(record.element);
91
- }
92
-
93
- // Focus reached a pending element: the content must be usable on this frame,
94
- // not after an entrance. Only the animations that releasing the state started
95
- // are finished, found by difference, so the runtime still names no effect and
96
- // leaves a nested component's own motion alone. A CSS :focus-within override
97
- // cannot do this: it lapses on blur and the entrance replays from the start.
98
- function revealNow(record) {
99
- if (record.done) return;
100
95
  const { element } = record;
101
96
  const running = new Set(element.getAnimations({ subtree: true }));
102
- reveal(record);
97
+ element.classList.remove(CLASSES.pending);
98
+ record.initialObserver.unobserve(element);
99
+ record.observer.unobserve(element);
103
100
  // getAnimations() flushes style, so the entrance released above is listed.
104
- for (const animation of element.getAnimations({ subtree: true })) {
105
- if (running.has(animation)) continue;
101
+ record.entrance = element.getAnimations({ subtree: true }).filter((animation) => {
102
+ const target = animation.effect?.target;
103
+ const owned = target === element || target?.parentElement === element;
106
104
  // finish() throws on an animation that never ends.
107
- if (animation.effect?.getComputedTiming().endTime === Infinity) continue;
108
- animation.finish();
105
+ return (
106
+ (owned || !running.has(animation)) &&
107
+ animation.effect?.getComputedTiming().endTime !== Infinity
108
+ );
109
+ });
110
+ }
111
+
112
+ // Focus entered the element: the content must be usable on this frame, not at
113
+ // the end of an entrance, whether the element was pending, just released or
114
+ // still playing its first-render entrance. A CSS :focus-within override cannot
115
+ // do this: on blur the entrance resumes from its timeline, or replays.
116
+ function revealNow(record) {
117
+ reveal(record);
118
+ for (const animation of record.entrance) {
119
+ if (animation.playState !== "finished") animation.finish();
109
120
  }
121
+ record.entrance = [];
110
122
  }
111
123
 
112
124
  function cleanup(record, records) {
@@ -127,24 +139,23 @@ function connect(element) {
127
139
  initialObserver: observer,
128
140
  observer: triggerFor(connection, element.getAttribute("data-in-view-margin")),
129
141
  done: false,
142
+ entrance: [],
130
143
  controller: new AbortController(),
131
144
  };
132
145
  records.set(element, record);
133
146
 
134
- // Focus may already sit inside the element before this registration (an
135
- // autofocused control, a second runtime copy attaching late). Hiding it then
136
- // would leave focus invisible until the observer's first callback.
137
- if (element.contains(element.ownerDocument.activeElement)) {
138
- reveal(record);
139
- return () => cleanup(record, records);
140
- }
141
-
142
147
  // Focus moves the page first, so this is the guarantee, not the observer:
143
- // the element is visible by the time its descendant takes focus.
148
+ // the element is visible by the time its descendant takes focus. It stays
149
+ // after the release, while the entrance may still run.
144
150
  element.addEventListener("focusin", () => revealNow(record), {
145
151
  signal: record.controller.signal,
146
152
  });
147
- observer.observe(element);
153
+
154
+ // Focus may already sit inside the element before this registration (an
155
+ // autofocused control, a second runtime copy attaching late). Hiding it then
156
+ // would leave focus invisible until the observer's first callback.
157
+ if (element.contains(element.ownerDocument.activeElement)) revealNow(record);
158
+ else observer.observe(element);
148
159
 
149
160
  return () => cleanup(record, records);
150
161
  }
package/src/js/menu.js CHANGED
@@ -61,7 +61,7 @@ export function focusLastMenuItem(menu) {
61
61
  lastItem(getMenuItems(menu))?.focus();
62
62
  }
63
63
 
64
- export function onMenuKeydown(e, { close, navigate = true }) {
64
+ export function onMenuKeydown(e, { navigate = true } = {}) {
65
65
  if (shouldIgnoreKey(e)) return;
66
66
  const menu = e.currentTarget;
67
67
  if (navigate) {
@@ -77,16 +77,10 @@ export function onMenuKeydown(e, { close, navigate = true }) {
77
77
  }
78
78
  }
79
79
 
80
- switch (e.key) {
81
- case "Tab":
82
- close(menu);
83
- break;
84
- case "Enter":
85
- case " ":
86
- if (activateCurrentItem(menu)) {
87
- e.preventDefault();
88
- }
89
- break;
80
+ // No Tab case: the browser moves focus, and surface.js closes the menu once
81
+ // focus lands outside it, without bouncing focus through the trigger first.
82
+ if ((e.key === "Enter" || e.key === " ") && activateCurrentItem(menu)) {
83
+ e.preventDefault();
90
84
  }
91
85
  }
92
86
 
@@ -96,7 +90,7 @@ export function onMenuKeydown(e, { close, navigate = true }) {
96
90
  // Each retain returns a release(); the wiring is torn down on the last one.
97
91
  const menuConnections = new WeakMap();
98
92
 
99
- export function connectMenu(menu, { close }) {
93
+ export function connectMenu(menu) {
100
94
  let entry = menuConnections.get(menu);
101
95
 
102
96
  if (!entry) {
@@ -109,15 +103,9 @@ export function connectMenu(menu, { close }) {
109
103
  signal: controller.signal,
110
104
  })
111
105
  : null;
112
- menu.addEventListener(
113
- "keydown",
114
- (event) =>
115
- onMenuKeydown(event, {
116
- close: () => close(menu),
117
- navigate: !focusGroup,
118
- }),
119
- { signal: controller.signal },
120
- );
106
+ menu.addEventListener("keydown", (event) => onMenuKeydown(event, { navigate: !focusGroup }), {
107
+ signal: controller.signal,
108
+ });
121
109
  menu.addEventListener(
122
110
  "click",
123
111
  (event) => {
package/src/js/surface.js CHANGED
@@ -428,9 +428,47 @@ function onDocumentClick(e) {
428
428
  }
429
429
  }
430
430
 
431
+ /*
432
+ * Focus that lands outside an open surface closes it, without moving focus:
433
+ * Tab, Shift+Tab or a script took it somewhere on purpose. Left open, the
434
+ * panel could cover the very control that just received focus (WCAG 2.4.11).
435
+ * Listening to where focus arrives, not to the Tab key, covers every route
436
+ * and leaves the browser's own sequential navigation untouched.
437
+ *
438
+ * What keeps a surface open: focus inside it, or on what opened it — any
439
+ * trigger naming it through aria-controls, the anchor, the source region of a
440
+ * context menu, or the element focus returns to. A context menu's trigger may
441
+ * be a point, so each one is checked as a Node. autoClose "false" is the
442
+ * application's explicit claim on closing, so focus leaves it alone too.
443
+ */
444
+ function keepsSurfaceOpen(menu, state, target) {
445
+ if (menu.contains(target)) return true;
446
+ const owners = [
447
+ state.trigger,
448
+ state.source,
449
+ surfaceFocusReturns.get(menu),
450
+ ...linkedTriggers(menu),
451
+ ];
452
+ return owners.some((owner) => owner instanceof Node && owner.contains(target));
453
+ }
454
+
455
+ function onDocumentFocusIn(e) {
456
+ // composedPath() reaches past a shadow host to the element that took focus.
457
+ const target = e.composedPath()[0] ?? e.target;
458
+ if (!(target instanceof Node)) return;
459
+
460
+ for (const menu of [...openSurfaces]) {
461
+ if (menu.ownerDocument !== e.currentTarget) continue;
462
+ const state = surfaceMap.get(menu);
463
+ if (!state || state.autoClose === "false") continue;
464
+ if (!keepsSurfaceOpen(menu, state, target)) closeSurface(menu, { restoreFocus: false });
465
+ }
466
+ }
467
+
431
468
  function ensureDocumentClick(menu) {
432
469
  const doc = menu.ownerDocument;
433
470
  if (!doc || clickBoundDocuments.has(doc)) return;
434
471
  clickBoundDocuments.add(doc);
435
472
  doc.addEventListener("click", onDocumentClick);
473
+ doc.addEventListener("focusin", onDocumentFocusIn);
436
474
  }
@@ -85,6 +85,7 @@ export const FOUNDATIONS = {
85
85
  "font-size-md",
86
86
  "font-size-lg",
87
87
  "control-font-size",
88
+ "btn-font-size",
88
89
  ],
89
90
  size: ["control-size-sm", "control-size-md", "control-size-lg", "control-size", "bar-height"],
90
91
  offset: ["focus-outline-offset"],
@@ -5,8 +5,8 @@
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, radio and unchecked switch against
9
- * --surface (3:1)
8
+ * - what identifies a resting control against --surface (3:1): the edge of a
9
+ * field, checkbox and radio, the track edge or knob of an unchecked switch
10
10
  * - soft ink against the resting and the hovered soft fill (4.5:1), on each
11
11
  * surface a soft element sits on
12
12
  * - the solid pairs, -fg on the intent fill (4.5:1); a fill painted by a
@@ -75,8 +75,9 @@ function islandMarkup(id, scheme) {
75
75
  /* Controls whose resting edge is all that identifies them (WCAG 1.4.11): the
76
76
  edge against the surface around them needs 3:1. The field is read on its
77
77
  block-end side, the one an underline-only theme (material) keeps. An
78
- unchecked switch is one of them: its track fill is a quiet --border, so the
79
- edge is what tells it apart from the surface. */
78
+ unchecked switch is read on its track edge or its knob, whichever is
79
+ stronger: the core track is the --border-control edge, and a theme may move
80
+ the cue to a dark knob on a quiet track (docs/pages/forms/switch.md). */
80
81
  export const CONTROLS = [
81
82
  ["field", '<input class="input">'],
82
83
  ["checkbox", '<input class="check" type="checkbox">'],
@@ -144,7 +145,7 @@ export async function measureContrast({ css, themes, label = "default" }) {
144
145
  const colors = await view.evaluate(`(() => {
145
146
  const rgba = ${RASTERIZE};
146
147
  return [...document.querySelectorAll("[id^=island-]")].map((island) => {
147
- const cs = (el) => getComputedStyle(el);
148
+ const cs = (el, pseudo = null) => getComputedStyle(el, pseudo);
148
149
  const pairs = {};
149
150
  for (const el of island.querySelectorAll("[data-pair]")) {
150
151
  // The invalid field's block-end border carries --form-invalid-border,
@@ -205,11 +206,17 @@ export async function measureContrast({ css, themes, label = "default" }) {
205
206
  }
206
207
  const box = island.querySelector("[data-controls]");
207
208
  const controls = { backdrop: rgba(cs(box).backgroundColor), edges: {} };
209
+ // The cues that can identify each control; the best one counts. A field
210
+ // shows its lower edge, a switch its track edge or its knob (the core
211
+ // pill, or a theme's dark knob on a quiet track), any other control its
212
+ // edge.
213
+ const cues = {
214
+ field: (s) => [s.borderBlockEndColor],
215
+ switch: (s, el) => [cs(el, "::before").backgroundColor, s.borderTopColor],
216
+ };
208
217
  for (const el of box.querySelectorAll("[data-control]")) {
209
- const s = cs(el);
210
- controls.edges[el.dataset.control] = rgba(
211
- el.dataset.control === "field" ? s.borderBlockEndColor : s.borderTopColor,
212
- );
218
+ const read = cues[el.dataset.control] ?? ((s) => [s.borderTopColor]);
219
+ controls.edges[el.dataset.control] = read(cs(el), el).map(rgba);
213
220
  }
214
221
  return { pairs, soft, solid, controls };
215
222
  });
@@ -264,7 +271,11 @@ export async function measureContrast({ css, themes, label = "default" }) {
264
271
  value:
265
272
  controls.backdrop[3] < 255
266
273
  ? null
267
- : ratio(composite(controls.edges[kind], controls.backdrop), controls.backdrop),
274
+ : Math.max(
275
+ ...controls.edges[kind].map((cue) =>
276
+ ratio(composite(cue, controls.backdrop), controls.backdrop),
277
+ ),
278
+ ),
268
279
  })),
269
280
  focusSurface: pair("focus-surface"),
270
281
  focusSolid: pair("focus-solid"),
@@ -362,7 +373,7 @@ export function formatContrast(rows) {
362
373
  );
363
374
  }
364
375
 
365
- lines.push("", "Control edge at rest (--border-control vs --surface), needs 3:1.", "");
376
+ lines.push("", "Control cue at rest (edge, or a switch's knob, vs --surface), needs 3:1.", "");
366
377
  lines.push(`${"theme".padEnd(width)} scheme control ratio`);
367
378
  for (const row of rows) {
368
379
  for (const { kind, value } of row.controls ?? []) {
package/tokens.json CHANGED
@@ -8,6 +8,7 @@
8
8
  "--border-control",
9
9
  "--border-control-mix",
10
10
  "--border-width",
11
+ "--btn-font-size",
11
12
  "--choice-control-size",
12
13
  "--control-default-bg",
13
14
  "--control-font-size",