('[data-nav-region="shell"]');
+ nav.shellHref = shell ? active.getAttribute('href') : null;
+ nav.shellArea = shell?.dataset.navArea ?? null;
+
+ if (!synthKey(active, 'Enter')) active.click();
+}
+
+function doBack() {
+ markActive();
+ if (nav.editing) return exitEdit();
+ synthKey(document.activeElement, 'Escape');
+}
+
+function pressDir(dir: Direction, now: number) {
+ const state = nav.held.get(dir);
+ if (!state) {
+ nav.held.set(dir, { firedAt: now, repeating: false });
+ doMove(dir);
+ } else if (!state.repeating && now - state.firedAt >= REPEAT_DELAY_MS) {
+ state.repeating = true;
+ state.firedAt = now;
+ doMove(dir);
+ } else if (state.repeating && now - state.firedAt >= REPEAT_INTERVAL_MS) {
+ state.firedAt = now;
+ doMove(dir);
+ }
+}
+
+function poll() {
+ const now = performance.now();
+ const frame = decodeInput(navigator.getGamepads());
+
+ nav.stickDir = resolveStick(frame.axX, frame.axY, nav.stickDir);
+ const pressedDirs = pressedDirections(frame, nav.stickDir);
+
+ const { buttons } = frame;
+ if (buttons.has(BUTTON_A) && !nav.prevButtons.has(BUTTON_A)) doActivate();
+ if (buttons.has(BUTTON_B) && !nav.prevButtons.has(BUTTON_B)) doBack();
+ nav.prevButtons = buttons;
+
+ for (const dir of pressedDirs) pressDir(dir, now);
+ for (const dir of Array.from(nav.held.keys())) {
+ if (!pressedDirs.has(dir)) nav.held.delete(dir);
+ }
+
+ nav.rafId = nav.pads.size > 0 ? requestAnimationFrame(poll) : 0;
+}
+
+function startLoop() {
+ if (!nav.rafId) nav.rafId = requestAnimationFrame(poll);
+}
+
+function onConnect(e: GamepadEvent) {
+ const wasEmpty = nav.pads.size === 0;
+ nav.pads.add(e.gamepad.index);
+ if (wasEmpty) activateListeners();
+ startLoop();
+ markActive();
+ nav.shellHref = null;
+ placeCursorSoon();
+}
+
+function onDisconnect(e: GamepadEvent) {
+ nav.pads.delete(e.gamepad.index);
+ if (nav.pads.size === 0) deactivateListeners();
+}
+
+function onInterrupt() {
+ resetHeld();
+}
+
+function onUserInput(e: Event) {
+ if (!e.isTrusted) return;
+ clearActive();
+}
+
+/** Focus is still measurable during the blur, so a later move can resume. */
+function onFocusOut(e: FocusEvent) {
+ const el = e.target as HTMLElement | null;
+ if (!el || el === document.body || !el.getClientRects().length) return;
+ nav.origin = el.getBoundingClientRect();
+}
+
+function activateListeners() {
+ if (nav.listening) return;
+ nav.listening = true;
+ document.addEventListener('focusout', onFocusOut, true);
+ window.addEventListener('pointerdown', onUserInput, true);
+ window.addEventListener('keydown', onUserInput, true);
+}
+
+function deactivateListeners() {
+ if (!nav.listening) return;
+ nav.listening = false;
+ document.removeEventListener('focusout', onFocusOut, true);
+ window.removeEventListener('pointerdown', onUserInput, true);
+ window.removeEventListener('keydown', onUserInput, true);
+ clearActive();
+}
+
+function start() {
+ if (++nav.starts > 1) return;
+ if (typeof navigator === 'undefined' || !navigator.getGamepads) return;
+
+ window.addEventListener('gamepadconnected', onConnect);
+ window.addEventListener('gamepaddisconnected', onDisconnect);
+ window.addEventListener('blur', onInterrupt);
+ document.addEventListener('visibilitychange', onInterrupt);
+
+ for (const pad of navigator.getGamepads()) {
+ if (pad) nav.pads.add(pad.index);
+ }
+ if (nav.pads.size) {
+ activateListeners();
+ startLoop();
+ }
+}
+
+function stop() {
+ if (--nav.starts > 0) return;
+
+ if (nav.rafId) cancelAnimationFrame(nav.rafId);
+ nav.rafId = 0;
+ window.removeEventListener('gamepadconnected', onConnect);
+ window.removeEventListener('gamepaddisconnected', onDisconnect);
+ window.removeEventListener('blur', onInterrupt);
+ document.removeEventListener('visibilitychange', onInterrupt);
+ deactivateListeners();
+ resetHeld();
+ nav.pads.clear();
+ nav.origin = null;
+}
+
+export function useControllerNav() {
+ const { config } = useConfig();
+ const location = useLocation();
+ const enabled = config?.controllerNav !== false;
+
+ useEffect(() => {
+ if (!enabled) return;
+ start();
+ return stop;
+ }, [enabled]);
+
+ useEffect(() => {
+ nav.origin = null;
+ if (!enabled || !isActive()) return;
+ placeCursorSoon();
+ }, [location.pathname, enabled]);
+}
diff --git a/gui/app/src/hooks/pointer-drag.ts b/gui/app/src/hooks/pointer-drag.ts
index 584a815a6..de4e9016f 100644
--- a/gui/app/src/hooks/pointer-drag.ts
+++ b/gui/app/src/hooks/pointer-drag.ts
@@ -1,6 +1,14 @@
import { atom, useAtomValue, useSetAtom } from 'jotai';
import { selectAtom } from 'jotai/utils';
-import { MouseEvent, PointerEvent, useEffect, useRef, useState } from 'react';
+import {
+ KeyboardEvent as ReactKeyboardEvent,
+ MouseEvent,
+ PointerEvent,
+ useEffect,
+ useRef,
+ useState,
+} from 'react';
+import { a11yClick } from '@/utils/a11y';
const DRAG_THRESHOLD = 6;
@@ -38,8 +46,18 @@ export const createPointerDrag = (codec: DropTargetCodec) => {
[codec.attribute]: codec.serialize(target),
});
- /** A null payload means there is nothing to drag here. */
- const useDraggable = (payload: P | null, onDrop: (target: T | null) => void) => {
+ /**
+ * A null payload means there is nothing to drag here.
+ *
+ * Passing `onTap` also makes the surface activatable: it fires on a click
+ * that was not the tail of a drag, and on Enter or Space via the returned
+ * `tapProps` (spread those onto the element alongside `dragProps`).
+ */
+ const useDraggable = (
+ payload: P | null,
+ onDrop: (target: T | null) => void,
+ onTap?: () => void
+ ) => {
const setDrag = useSetAtom(stateAtom);
const [start, setStart] = useState<{ x: number; y: number } | null>(null);
const [isDragging, setIsDragging] = useState(false);
@@ -94,7 +112,9 @@ export const createPointerDrag = (codec: DropTargetCodec) => {
suppressNextClickRef.current = false;
e.preventDefault();
e.stopPropagation();
+ return;
}
+ onTap?.();
};
useEffect(() => {
@@ -115,6 +135,17 @@ export const createPointerDrag = (codec: DropTargetCodec) => {
onPointerCancel,
onClick,
},
+ tapProps: onTap
+ ? {
+ role: 'button',
+ tabIndex: 0,
+ onKeyDown: (e: ReactKeyboardEvent) => {
+ if (!a11yClick(e)) return;
+ e.preventDefault();
+ onTap();
+ },
+ }
+ : undefined,
isDragging,
};
};
diff --git a/gui/app/src/utils/a11y.ts b/gui/app/src/utils/a11y.ts
index 084f246b8..444df5253 100644
--- a/gui/app/src/utils/a11y.ts
+++ b/gui/app/src/utils/a11y.ts
@@ -4,18 +4,85 @@ import { error } from './logging';
// :focus-visible outline). These two cover cases that a global rule can't:
// FOCUS_RING_PEER - the real focus target is a visually-hidden `peer` input.
// FOCUS_RING_WITHIN - the ring belongs on a wrapper, keyed off a focused child.
+// The `.controller-active` variants drop the `-visible` requirement, since
+// gamepad navigation focuses programmatically and never sets :focus-visible.
export const FOCUS_RING_PEER =
- 'peer-focus:ring-0 peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-accent-background-10';
+ 'peer-focus:ring-0 peer-focus-visible:outline-none peer-focus-visible:ring-2 peer-focus-visible:ring-accent-background-10 ' +
+ '[.controller-active_&]:peer-focus:ring-2 [.controller-active_&]:peer-focus:ring-accent-background-10';
export const FOCUS_RING_WITHIN =
- 'has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-accent-background-10';
+ 'has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-accent-background-10 ' +
+ '[.controller-active_&]:has-[:focus]:ring-2 [.controller-active_&]:has-[:focus]:ring-accent-background-10';
-export function a11yClick(event: React.KeyboardEvent | React.MouseEvent) {
+export function a11yClick(event: React.KeyboardEvent | React.MouseEvent): boolean {
if (event.type === 'click') {
return true;
} else if (event.type === 'keydown') {
const keyboard = event as React.KeyboardEvent;
return keyboard.key === 'Enter' || keyboard.key === ' ';
}
+ return false;
+}
+
+/** Number, or a custom stepper returning the next value from the current one. */
+export type Step = number | ((value: number, add: boolean) => number);
+
+/**
+ * Arrow / Home / End / PageUp / PageDown handling for numeric widgets. Clamps
+ * to `[min, max]` and only ever hands `onChange` a number. Without a `bigStep`,
+ * PageUp and PageDown fall back to `step`.
+ */
+export function stepKeys({
+ value,
+ min,
+ max,
+ step,
+ bigStep,
+ onChange,
+ disabled,
+}: {
+ value: number;
+ min: number;
+ max: number;
+ step: Step;
+ bigStep?: Step;
+ onChange: (value: number) => void;
+ disabled?: boolean;
+}) {
+ const apply = (by: Step, add: boolean) =>
+ typeof by === 'number' ? value + (add ? by : -by) : by(value, add);
+
+ return (e: React.KeyboardEvent) => {
+ if (disabled) return;
+
+ let next: number;
+ switch (e.key) {
+ case 'ArrowUp':
+ case 'ArrowRight':
+ next = apply(step, true);
+ break;
+ case 'ArrowDown':
+ case 'ArrowLeft':
+ next = apply(step, false);
+ break;
+ case 'PageUp':
+ next = apply(bigStep ?? step, true);
+ break;
+ case 'PageDown':
+ next = apply(bigStep ?? step, false);
+ break;
+ case 'Home':
+ next = min;
+ break;
+ case 'End':
+ next = max;
+ break;
+ default:
+ return;
+ }
+
+ e.preventDefault();
+ onChange(Math.min(max, Math.max(min, +next.toFixed(4))));
+ };
}
export function waitUntil(
diff --git a/gui/app/src/utils/focus-nav.ts b/gui/app/src/utils/focus-nav.ts
new file mode 100644
index 000000000..081cbf74e
--- /dev/null
+++ b/gui/app/src/utils/focus-nav.ts
@@ -0,0 +1,262 @@
+/**
+ * Spatial focus navigation over the DOM: which elements can take focus, and
+ * which one lies nearest in a given direction. No input-device knowledge and no
+ * state, so it is driven by whatever wants to move a cursor around.
+ */
+
+export type Direction = 'up' | 'down' | 'left' | 'right';
+
+/** Everything a user can put focus on. */
+export const FOCUSABLE_SELECTOR = [
+ 'a[href]',
+ 'button',
+ 'input:not([type="hidden"])',
+ 'select',
+ 'textarea',
+ '[tabindex]:not([tabindex="-1"])',
+ '[role="button"]',
+ '[role="link"]',
+ '[role="menuitem"]',
+ '[role="radio"]',
+ '[role="tab"]',
+ '[role="checkbox"]',
+ '[role="switch"]',
+ '[role="combobox"]',
+ '[role="spinbutton"]',
+ '[role="slider"]',
+].join(',');
+
+export const ARROW_KEY: Record = {
+ up: 'ArrowUp',
+ down: 'ArrowDown',
+ left: 'ArrowLeft',
+ right: 'ArrowRight',
+};
+
+export function isFocusable(el: HTMLElement): boolean {
+ // Natively disabled elements cannot take focus at all, so there is nothing to
+ // aim at. `aria-disabled` ones can, and should: a control that is off for a
+ // reason usually carries a tooltip saying why, and that is worth reaching.
+ if ((el as HTMLButtonElement).disabled) return false;
+ // Radios are exempt from the tabindex check: a browser reports -1 for the
+ // unchecked members of a group, but the cursor still has to reach them.
+ const isRadio = el.tagName === 'INPUT' && (el as HTMLInputElement).type === 'radio';
+ if (el.tabIndex < 0 && !isRadio) return false;
+ if (el.closest('[aria-hidden="true"], [inert]')) return false;
+ if (el.hasAttribute('hidden')) return false;
+ if (el.getClientRects().length === 0) return false;
+ const cs = getComputedStyle(el);
+ if (cs.visibility === 'hidden' || cs.visibility === 'collapse') return false;
+ if (cs.display === 'contents') return false;
+ return true;
+}
+
+export function collectFocusables(root: ParentNode = document): HTMLElement[] {
+ return Array.from(root.querySelectorAll(FOCUSABLE_SELECTOR)).filter(
+ isFocusable
+ );
+}
+
+/**
+ * A layout marks each of its areas `data-nav-region="page"` or `"shell"`, shell
+ * meaning the furniture around the content: top bar, navbar, settings sidebar.
+ *
+ * Two things come from that. The cursor starts in a page region rather than in
+ * the shell, and a move prefers to stay in the region it began in. Areas are
+ * marked one by one because a grid places them as siblings, so there is no
+ * wrapper to point at, and because the navbar and the top bar have to count as
+ * different regions even though both are shell.
+ */
+export function pageRegions(): HTMLElement[] {
+ return Array.from(document.querySelectorAll('[data-nav-region="page"]'));
+}
+
+/**
+ * Visible right now, as opposed to merely present. Something scrolled above the
+ * viewport reports a negative `top` and would win "topmost"; something inside a
+ * collapsed panel still reports a full-size rect while clipped to nothing.
+ */
+function onScreen(el: HTMLElement, r: DOMRect): boolean {
+ if (r.bottom <= 0 || r.right <= 0) return false;
+ if (r.top >= window.innerHeight || r.left >= window.innerWidth) return false;
+
+ for (let n = el.parentElement; n; n = n.parentElement) {
+ const cs = getComputedStyle(n);
+ if (cs.overflowX === 'visible' && cs.overflowY === 'visible') continue;
+ const b = n.getBoundingClientRect();
+ if (b.width < 1 || b.height < 1) return false;
+ if (r.bottom <= b.top || r.top >= b.bottom) return false;
+ if (r.right <= b.left || r.left >= b.right) return false;
+ }
+ return true;
+}
+
+/**
+ * Where the cursor starts. `data-nav-entry` is how a page says so, because the
+ * starting control is a design decision rather than something derivable.
+ *
+ * Without one, fall back to topmost then leftmost of the page's visible
+ * controls. Geometric rather than DOM order, since a grid places its areas in
+ * whatever order the template says: in the main layout the toolbar renders
+ * after the content yet sits above it.
+ *
+ * Returns nothing when the page has no visible controls yet, meaning it is
+ * still rendering.
+ */
+export function firstFocusable(): HTMLElement | undefined {
+ const entry = document.querySelector('[data-nav-entry]');
+ if (entry) {
+ if (isFocusable(entry)) return entry;
+ const inside = collectFocusables(entry)[0];
+ if (inside) return inside;
+ }
+
+ const regions = pageRegions();
+ const visible = (
+ regions.length
+ ? regions.flatMap((region) => collectFocusables(region))
+ : collectFocusables()
+ )
+ .map((el) => ({ el, r: el.getBoundingClientRect() }))
+ .filter(({ el, r }) => onScreen(el, r));
+ if (!visible.length) return undefined;
+
+ // The topmost control need not be the first one: a header row is usually
+ // `items-center`, so a taller right-aligned action sits a few pixels above
+ // the rest of its row. Rows are found by vertical overlap for that reason,
+ // never by a pixel threshold, and the leftmost of the first row wins.
+ const highest = visible.reduce((a, b) => (b.r.top < a.r.top ? b : a));
+ const firstRow = visible.filter(
+ ({ r }) => r.top < highest.r.bottom && r.bottom > highest.r.top
+ );
+ return firstRow.reduce((a, b) => (b.r.left < a.r.left ? b : a)).el;
+}
+
+/**
+ * Best focus target from origin rect `o` moving in `dir`, or null. `from` is the
+ * element the move starts at, excluded from the results.
+ *
+ * Candidates are ranked by region before distance: the region the move started
+ * in, then any page region, then the shell. The top bar spans the window and the
+ * navbar runs its full height, so on distance alone either one steals moves that
+ * had a perfectly good target in the page. Every region stays reachable, just
+ * only once the better-ranked ones have nothing left in the travel direction.
+ */
+export function pickBest(
+ o: DOMRect,
+ dir: Direction,
+ from?: Element | null
+): HTMLElement | null {
+ const oCx = o.left + o.width / 2;
+ const oCy = o.top + o.height / 2;
+ const horizontal = dir === 'left' || dir === 'right';
+
+ const regionOf = (el: Element) => el.closest('[data-nav-region]');
+ // Null origin region means there is nothing to compare against, as when
+ // resuming from a remembered rect whose element is long gone.
+ const originRegion = from ? regionOf(from) : null;
+ const rankOf = (el: Element) => {
+ const region = regionOf(el);
+ if (originRegion && region === originRegion) return 0;
+ return region?.getAttribute('data-nav-region') === 'page' ? 1 : 2;
+ };
+
+ let best: HTMLElement | null = null;
+ let bestScore = Infinity;
+ let bestRank = Infinity;
+
+ for (const el of collectFocusables()) {
+ if (el === from) continue;
+ const c = el.getBoundingClientRect();
+ if (c.width === 0 && c.height === 0) continue;
+ const cCx = c.left + c.width / 2;
+ const cCy = c.top + c.height / 2;
+
+ // Must lie strictly in the travel direction.
+ let primaryGap: number;
+ if (dir === 'right') {
+ if (c.left < o.right - 2 || cCx <= oCx) continue;
+ primaryGap = c.left - o.right;
+ } else if (dir === 'left') {
+ if (c.right > o.left + 2 || cCx >= oCx) continue;
+ primaryGap = o.left - c.right;
+ } else if (dir === 'down') {
+ if (c.top < o.bottom - 2 || cCy <= oCy) continue;
+ primaryGap = c.top - o.bottom;
+ } else {
+ if (c.bottom > o.top + 2 || cCy >= oCy) continue;
+ primaryGap = o.top - c.bottom;
+ }
+ primaryGap = Math.max(0, primaryGap);
+
+ const [oStart, oEnd, cStart, cEnd] = horizontal
+ ? [o.top, o.bottom, c.top, c.bottom]
+ : [o.left, o.right, c.left, c.right];
+ const overlapLen = Math.max(0, Math.min(oEnd, cEnd) - Math.max(oStart, cStart));
+ const crossGap =
+ overlapLen > 0 ? 0 : Math.max(oStart, cStart) - Math.min(oEnd, cEnd);
+ const overlapRatio =
+ overlapLen / Math.max(1, Math.min(oEnd - oStart, cEnd - cStart));
+
+ // Candidates that only touch at a corner.
+ if (primaryGap <= 2 && overlapRatio === 0) continue;
+
+ const euclid = Math.hypot(cCx - oCx, cCy - oCy);
+ const score =
+ primaryGap * 1 + crossGap * 2 + euclid * 0.25 + (1 - overlapRatio) * 100;
+
+ const rank = rankOf(el);
+ if (rank > bestRank) continue;
+ if (rank === bestRank && score >= bestScore) continue;
+ best = el;
+ bestScore = score;
+ bestRank = rank;
+ }
+
+ return best;
+}
+
+/**
+ * Nearest ancestor of `el` that scrolls along `dir`'s axis and is not already
+ * at its edge that way.
+ */
+export function scrollableToward(el: HTMLElement, dir: Direction): HTMLElement | null {
+ const vertical = dir === 'up' || dir === 'down';
+ for (let n = el.parentElement; n; n = n.parentElement) {
+ const overflow = vertical
+ ? getComputedStyle(n).overflowY
+ : getComputedStyle(n).overflowX;
+ if (overflow !== 'auto' && overflow !== 'scroll') continue;
+ const pos = vertical ? n.scrollTop : n.scrollLeft;
+ const span = vertical ? n.clientHeight : n.clientWidth;
+ const max = vertical
+ ? n.scrollHeight - n.clientHeight
+ : n.scrollWidth - n.clientWidth;
+ // `overflow-y: auto` makes the computed `overflow-x` auto as well, so a
+ // plain vertical column looks sideways-scrollable for the few pixels a
+ // scrollbar or a scaled child adds. Require real distance, or the column
+ // swallows every horizontal move made inside it.
+ if (max <= Math.max(8, span * 0.1)) continue;
+ const atEdge = dir === 'up' || dir === 'left' ? pos <= 1 : pos >= max - 1;
+ if (!atEdge) return n;
+ }
+ return null;
+}
+
+/**
+ * Dispatch a real keydown so widgets run their own logic. `code` matters to
+ * handlers that read it, such as the keybind recorder.
+ *
+ * @returns whether something consumed it.
+ */
+export function synthKey(target: EventTarget | null, key: string): boolean {
+ if (!target) return false;
+ const ev = new KeyboardEvent('keydown', {
+ key,
+ code: key,
+ bubbles: true,
+ cancelable: true,
+ });
+ target.dispatchEvent(ev);
+ return ev.defaultPrevented;
+}
diff --git a/gui/app/src/utils/gamepad.ts b/gui/app/src/utils/gamepad.ts
new file mode 100644
index 000000000..3754b87c5
--- /dev/null
+++ b/gui/app/src/utils/gamepad.ts
@@ -0,0 +1,71 @@
+import type { Direction } from './focus-nav';
+
+export const BUTTON_A = 0;
+export const BUTTON_B = 1;
+
+const DPAD: Record = {
+ 12: 'up',
+ 13: 'down',
+ 14: 'left',
+ 15: 'right',
+};
+
+const DEADZONE_ENTER = 0.35;
+const DEADZONE_EXIT = 0.25;
+/** How far the other axis must lead before a diagonal hold switches axis. */
+const AXIS_SWITCH_RATIO = 1.4;
+
+export interface GamepadFrame {
+ buttons: Set;
+ axX: number;
+ axY: number;
+}
+
+export function decodeInput(pads: (Gamepad | null)[]): GamepadFrame {
+ const buttons = new Set();
+ const stronger = (a: number, b: number) => (Math.abs(a) > Math.abs(b) ? a : b);
+ let axX = 0;
+ let axY = 0;
+
+ for (const pad of pads) {
+ if (!pad) continue;
+ pad.buttons.forEach((b, i) => b.pressed && buttons.add(i));
+ axX = stronger(pad.axes[0] ?? 0, axX);
+ axY = stronger(pad.axes[1] ?? 0, axY);
+ }
+ return { buttons, axX, axY };
+}
+
+export function pressedDirections(
+ frame: GamepadFrame,
+ stickDir: Direction | null
+): Set {
+ const dirs = new Set();
+ for (const i of frame.buttons) if (DPAD[i]) dirs.add(DPAD[i]);
+ if (stickDir) dirs.add(stickDir);
+ return dirs;
+}
+
+export function resolveStick(
+ axX: number,
+ axY: number,
+ prev: Direction | null
+): Direction | null {
+ const ax = Math.abs(axX);
+ const ay = Math.abs(axY);
+ const mag = Math.max(ax, ay);
+
+ if (mag < DEADZONE_EXIT) return null;
+ // Between the deadzones: hold what is committed, commit to nothing new.
+ if (mag < DEADZONE_ENTER && !prev) return null;
+
+ const wasHoriz = prev === 'left' || prev === 'right';
+ const wasVert = prev === 'up' || prev === 'down';
+ const horiz = wasHoriz
+ ? ax * AXIS_SWITCH_RATIO >= ay
+ : wasVert
+ ? ax >= ay * AXIS_SWITCH_RATIO
+ : ax > ay;
+
+ return horiz ? (axX > 0 ? 'right' : 'left') : axY > 0 ? 'down' : 'up';
+}
diff --git a/gui/app/tailwind.config.ts b/gui/app/tailwind.config.ts
index 329f16dfd..679b39767 100644
--- a/gui/app/tailwind.config.ts
+++ b/gui/app/tailwind.config.ts
@@ -371,6 +371,24 @@ const config = {
outline: '2px solid rgb(var(--accent-background-10))',
outlineOffset: '2px',
},
+ // Gamepad navigation: programmatic .focus() doesn't trigger
+ // :focus-visible, so force the same ring while a controller is driving.
+ 'html.controller-active :focus': {
+ outline: '2px solid rgb(var(--accent-background-10))',
+ outlineOffset: '2px',
+ },
+ [`html.controller-active :is(${formEls}):focus`]: {
+ boxShadow: 'none',
+ outline: '2px solid rgb(var(--accent-background-10))',
+ outlineOffset: '2px',
+ },
+ // "Edit mode": the cursor has stepped into a value widget and arrows
+ // now change its value. The extra `:focus` keeps this ahead of the
+ // plain focus rule above.
+ 'html.controller-active .nav-editing:focus': {
+ outline: '3px solid rgb(var(--accent-background-10))',
+ outlineOffset: '3px',
+ },
});
}),
],