diff --git a/apps/showcase/src/App.tsx b/apps/showcase/src/App.tsx index bf5bc41..a3b6210 100644 --- a/apps/showcase/src/App.tsx +++ b/apps/showcase/src/App.tsx @@ -8,7 +8,6 @@ import { BlinkCursor, useNexus, } from "@nexus-cyberdeck/react"; -import type { NexusTheme } from "@nexus-cyberdeck/react"; import { HomePage } from "./pages/HomePage.js"; import NexusCyberdeck from "./graph/NexusCyberdeck.js"; import GlitchLab from "./effects/GlitchLab.jsx"; @@ -16,6 +15,7 @@ import { href, useRoute } from "./router.js"; import { DOC_GROUPS, findPage } from "./site.js"; import type { DocPage } from "./site.js"; import { PageHeader } from "./components/Spec.js"; +import { SitePalette, useSitePalette } from "./components/SitePalette.js"; type View = | { kind: "home" } @@ -24,9 +24,9 @@ type View = | { kind: "doc"; page: DocPage } | { kind: "not-found" }; -// Home, Graph and Glitch Lab are self-contained full-viewport "console" -// experiences — docked panels, no page-level padding or scroll. Graph and -// Glitch Lab in particular render their own WebGL surfaces (see README: +// Home, Graph and Glitch Lab are full-bleed: no docs sidebar or page column. +// Graph and Glitch Lab are full-viewport "console" experiences — docked +// panels, no page-level scroll — and render their own WebGL surfaces (see README: // "the graph itself ... is a product, not a design system") and ignore the // site CRT toggle — Glitch Lab especially, since CRT composite is itself // one of its shader effects, not something to layer a second time. Every @@ -71,8 +71,9 @@ function Shell() { const path = useRoute().join("/"); const view = resolve(path); const title = titleOf(view); - const fullBleed = view.kind === "home" || view.kind === "graph" || view.kind === "glitch"; - const { theme, setTheme, crt, setCrt } = useNexus(); + const docked = view.kind === "graph" || view.kind === "glitch"; + // Theme and CRT are switched from the site palette (SitePalette.tsx). + const { crt } = useNexus(); const main = useRef(null); // The route last shown. Null until the first one, which is the document's own // load. Comparing routes rather than counting runs is what keeps StrictMode's @@ -101,149 +102,145 @@ function Shell() { }, [title]); return ( -
- {/* skip link — first tab stop, WCAG 2.4.1 */} - {/* The click is handled here rather than by the browser: the hash + +
+ {/* skip link — first tab stop, WCAG 2.4.1 */} + {/* The click is handled here rather than by the browser: the hash belongs to the router, and following "#main" would navigate to a route called "main". */} - { - e.preventDefault(); - main.current?.focus(); - }} - > - Skip to content - - - {/* A banner landmark: screen-reader users can jump to it, and it gives - the site chrome a name distinct from the theme controls the Home - page renders in its own panel. */} - -
{ + e.preventDefault(); + main.current?.focus(); }} > -
- NEXUS - - DS v{__NX_VERSION__} - -
+ Skip to content + - -
- - THEME - - {(["hud-aa", "hud"] as NexusTheme[]).map((t) => ( - - ))} - +
-
- -
+ + - {/* tabIndex=0 because this element scrolls. A scrollable region that is + {/* tabIndex=0 because this element scrolls. A scrollable region that is not focusable cannot be scrolled by keyboard at all when it holds no focusable content of its own — which is exactly the Tokens page, a long column of swatches with nothing to tab to. It doubles as the skip link's landing target. */} -
's visible height (100cqh) and scroll on its own. - containerType: view.kind === "doc" ? "size" : undefined, - }} - > - {view.kind === "home" && } - {view.kind === "graph" && } - {view.kind === "glitch" && } - {view.kind === "doc" && ( -
- - {/* Sized as the page column was before the sidebar existed: the +
like a docs + // page — which also gives it the scroll reset on navigation. + overflow: docked ? "hidden" : "auto", + // A size container on docs pages, so the sticky sidebar can cap its + // height at
's visible height (100cqh) and scroll on its own. + containerType: view.kind === "doc" ? "size" : undefined, + }} + > + {view.kind === "home" && } + {view.kind === "graph" && } + {view.kind === "glitch" && } + {view.kind === "doc" && ( +
+ + {/* Sized as the page column was before the sidebar existed: the visual baselines capture each example at this width. */} -
- - {/* Mounted as a component, never called as a function: a page's +
+ + {/* Mounted as a component, never called as a function: a page's hooks must belong to the page, or moving between pages with different hooks breaks the shell's own hook order. Keyed by path so each page starts from fresh state. */} - + +
-
- )} - {view.kind === "not-found" && ( -
- -
- )} -
-
+ )} + {view.kind === "not-found" && ( +
+ +
+ )} +
+
+
+ ); +} + +/** + * The site palette's visible way in, for anyone not reaching for ⌘K or "/" — + * and the only control for theme and CRT, which the palette lists first. + */ +function SearchButton() { + const { open } = useSitePalette(); + return ( + ); } diff --git a/apps/showcase/src/components/SignalMonitor.tsx b/apps/showcase/src/components/SignalMonitor.tsx new file mode 100644 index 0000000..3e21a3b --- /dev/null +++ b/apps/showcase/src/components/SignalMonitor.tsx @@ -0,0 +1,278 @@ +import { useEffect, useRef, useState } from "react"; +import type { FocusEvent, PointerEvent } from "react"; +import { Button, Panel } from "@nexus-cyberdeck/react"; +import { configFor, fireEvent, shuffleSeed, useGlitchEngine } from "../effects/glitchEngine.js"; +import { createAudio } from "../effects/glitchAudio.js"; + +/* ============================================================================ + showcase — SignalMonitor + Home's hero: a small CRT running Glitch Lab's own signal path and + synthesiser (effects/glitchEngine.js, effects/glitchAudio.js). The pointer + tunes it — across for colour bleed, down for tracking. Each visit lands on + a channel chosen at random (the graph, with a new layout every time; the + test bars; or the HUD). Jolt fires one of Glitch Lab's faults. + With Sound on, faults are voiced, and the room — tape hiss, mains hum, the + flyback whine — comes up while the pointer or focus is on the monitor. + + Held to the system's own flash rule (WCAG 2.3.1): nothing fires by itself, + one fault runs at a time, and the faults offered are the ones that move + the picture rather than flash it. Under reduced motion the screen is a + still frame that redraws only when it is tuned or changed, and the faults + and the sound are withdrawn with their controls. + + Sound needs the page to have had a press first — browsers allow audio only + after one — so a hover before any press is silent. + ========================================================================== */ + +type Cfg = ReturnType; +type Audio = NonNullable>; + +const CHANNELS = ["GRAPH", "BARS", "HUD"] as const; + +// Faults that displace, ghost or shift colour. Dropout, signal loss, data +// corruption, head crash and cold boot all flash or blank the picture. +const SAFE_FAULTS = ["scrub", "interference", "degauss"] as const; + +const VOLUME = 0.45; +// The room: Glitch Lab's bed with the 15.7 kHz whine kept low, faded so it +// can follow a hover without clicking. +const ROOM = { hiss: 0.4, hum: 0.35, whine: 0.12, fade: 0.25 }; + +/** + * The monitor's resting signal: Glitch Lab's BROADCAST preset, with three + * changes for a screen that sits in a square frame on a page. + * + * - More bend, overscanned. The barrel curve is what reads as a television; + * overscan scales the bent picture out until its corners meet the frame, + * so lines still bow but no black shows past the glass. Degauss's bulge + * overscans with it. + * - Full mix. At BROADCAST's 0.85, 15% of the flat picture showed through + * wherever the bent one did not reach. + * - No hologram flicker. Degauss fades that layer in, and its shader + * otherwise dims at random on a 20 Hz clock; at zero, nothing on this + * screen steps in brightness. + * + * Glitch Lab keeps the preset as it is. + */ +function rest(): Cfg { + const cfg = configFor("BROADCAST"); + Object.assign(cfg["crt"]!, { amt: 1, curve: 0.9, overscan: 1 }); + cfg["holo"]!.flicker = 0; + return cfg; +} + +/** Pointer position, 0–1 on each axis, to the knobs it turns. */ +function tune(x: number, y: number): Cfg { + const cfg = rest(); + Object.assign(cfg["chroma"]!, { on: 1, amt: 0.5 + x * 0.5, width: 4 + x * 20, lag: -2 + x * 12 }); + Object.assign(cfg["tracking"]!, { on: 1, amt: y, shift: y * 0.12, height: 0.06 + y * 0.18 }); + return cfg; +} + +/** Whether the page has had the press browsers require before audio may start. */ +const mayPlay = () => + (navigator as Navigator & { userActivation?: { hasBeenActive: boolean } }).userActivation + ?.hasBeenActive ?? true; + +export function SignalMonitor() { + const hostRef = useRef(null); + const cfgRef = useRef(rest()); + const srcRef = useRef(0); + const seedRef = useRef(0); + const activeRef = useRef([]); + const queueRef = useRef([]); + const stillRef = useRef(false); + const audioRef = useRef