diff --git a/apps/site/src/components/Aurora.astro b/apps/site/src/components/Aurora.astro index 5473efa..a55f5bc 100644 --- a/apps/site/src/components/Aurora.astro +++ b/apps/site/src/components/Aurora.astro @@ -162,6 +162,8 @@ import "@northguild/theme/tokens-aurora.css"; SkyLine, WorkerMessage, } from "../scripts/aurora.worker"; + import { cue, HUGINN_EVENT, PLACE_EVENT } from "../scripts/sound/cue"; + import { onSoundChange, readSound } from "../scripts/sound/settings"; // Order matches what the worker destructures. const TOKENS = [ @@ -203,6 +205,12 @@ import "@northguild/theme/tokens-aurora.css"; // The part of the popover under the switcher, which scrolls. const details = document.querySelector(".sky-info-body"); function showChosenSite(): void { + // The place drawn, for the air the sound plays under it. + const place = ids[site] ?? ""; + if (document.documentElement.dataset.skySite !== place) { + document.documentElement.dataset.skySite = place; + document.dispatchEvent(new CustomEvent(PLACE_EVENT)); + } sections.forEach((el, i) => (el.hidden = i !== site)); choices.forEach((button, i) => button.setAttribute("aria-pressed", String(i === site)), @@ -263,10 +271,12 @@ import "@northguild/theme/tokens-aurora.css"; } let lastAngle = 135; // Sweep the pane in toward `angle` (a CSS gradient angle), drifting a - // little along his line, over `duration` seconds. - function brushPane(i: number, angle: number, duration: number): void { + // little along his line, over `duration` seconds. Returns whether it did. + function brushPane(i: number, angle: number, duration: number): boolean { const el = panes[i]; - if (!el || !isAwaiting() || el.classList.contains("ng-brushed")) return; + if (!el || !isAwaiting() || el.classList.contains("ng-brushed")) { + return false; + } lastAngle = angle; const a = (angle * Math.PI) / 180; const [dx, dy] = [Math.sin(a), -Math.cos(a)]; @@ -292,6 +302,23 @@ import "@northguild/theme/tokens-aurora.css"; el.style.setProperty("--ng-dy", Math.max(dy, -roomY).toFixed(3)); el.style.setProperty("--ng-brush-duration", `${duration}s`); el.classList.add("ng-brushed"); + return true; + } + // The draw-in's sound (Silk rustle, scripts/sound/voices.ts): the aurora's + // faint rustle over the sweep, panned to the box and drifting the way the + // light crosses it. Only for his own brushes: a pane painted in by the + // safety net, or all at once, is silent. + function brushSound(i: number, angle: number, duration: number): void { + const el = panes[i]; + if (!el) return; + const r = el.getBoundingClientRect(); + const middle = (r.left + r.width / 2) / (innerWidth || 1); + cue("brush", i, { + duration, + kind: targetKind(el), + pan: Math.min(1, Math.max(-1, (middle - 0.5) * 1.6)), + drift: Math.sign(Math.sin((angle * Math.PI) / 180)), + }); } // His flight draws the panes in. This is only a safety net for a stalled // or slow worker: on a first visit late enough never to start a pane ahead @@ -347,11 +374,24 @@ import "@northguild/theme/tokens-aurora.css"; }, [offscreen], ); + // Huginn's sounds come only while the reader has sound on. + sendToWorker({ type: "sound", on: !readSound().muted }); + onSoundChange((settings) => + sendToWorker({ type: "sound", on: !settings.muted }), + ); worker.onmessage = ({ data }: MessageEvent) => { if (typeof data === "object") { - if ("brush" in data) { + if ("huginn" in data) { + document.dispatchEvent( + new CustomEvent(HUGINN_EVENT, { detail: data.huginn }), + ); + } else if ("brush" in data) { + const angle = data.angle ?? 135; + const duration = data.duration ?? 1; if (data.brush < 0) showAllPanes(); - else brushPane(data.brush, data.angle ?? 135, data.duration ?? 1); + else if (brushPane(data.brush, angle, duration)) { + brushSound(data.brush, angle, duration); + } } else if ("pick" in data) { showPick(data.pick); } else if ("times" in data) { diff --git a/apps/site/src/components/Header.astro b/apps/site/src/components/Header.astro index 2cd37ca..1ed6454 100644 --- a/apps/site/src/components/Header.astro +++ b/apps/site/src/components/Header.astro @@ -26,25 +26,110 @@ const links = [ data-ng-target={entrance ? "header" : undefined} >
NorthGuild
- + + + + + + + + + + + diff --git a/apps/site/src/layouts/Base.astro b/apps/site/src/layouts/Base.astro index 950c886..87e2fc6 100644 --- a/apps/site/src/layouts/Base.astro +++ b/apps/site/src/layouts/Base.astro @@ -77,6 +77,23 @@ const ogAlt = type="font/woff2" crossorigin /> + { entrance && import.meta.env.DEV && ( + + diff --git a/packages/theme/README.md b/packages/theme/README.md index f4c09ca..2bb0977 100644 --- a/packages/theme/README.md +++ b/packages/theme/README.md @@ -36,5 +36,8 @@ NorthGuild's own. - `.gmt-sonar-loop`: the same ping on a permanent loop. - `.gmt-field`: bevelled text input. - `.gmt-button`: small bevelled button. +- `.gmt-panel`: a `[popover]` panel that slides and fades in and out with a sheen. +- `.gmt-toggle-button`: small bevelled button lit while `aria-pressed="true"`. +- `.gmt-fader`: an 11-notch volume fader on ``; set `--gmt-range-pct`. A `prefers-reduced-motion` reset collapses all animation and transition time. diff --git a/packages/theme/primitives.css b/packages/theme/primitives.css index 3776c19..bd6143b 100644 --- a/packages/theme/primitives.css +++ b/packages/theme/primitives.css @@ -311,6 +311,278 @@ } +/* + * Source: apps/dox/src/styles/gmt-primitives.css lines 484-551 (native panels), + * apps/dox/src/widgets/primitives/range/range.module.css (the fader) and + * apps/dox/src/widgets/builders/button.module.css (the pressed button) + * (gmt commit 458860e7730d714b90c63768d9e9758dd1025c01). Made classes here + * where the docs use CSS modules. + */ + +/* ---- Panel ---- + * A popover panel: bevelled, on the raised surface, coming and going with a + * short move and a fade over 240 ms on the sweep curve, one band of ice + * light crossing it each way. Put it on a `[popover]`. Closing keeps it shown, + * and in the top layer, until the fade ends. `--gmt-panel-from` is where it + * comes from, half a rem above by default. + */ +.gmt-panel { + box-sizing: border-box; + margin: 0; + padding: 1rem; + border: 1px solid var(--gmt-border); + border-radius: var(--gmt-bevel-md); + corner-shape: bevel; + background: var(--gmt-surface-2); + color: var(--gmt-ice); + font-size: var(--gmt-text-sm); + overflow: visible; + opacity: 0; + translate: var(--gmt-panel-from, 0 -0.5rem); + transition: + opacity var(--gmt-duration-med) var(--gmt-ease-sweep), + translate var(--gmt-duration-med) var(--gmt-ease-sweep), + display var(--gmt-duration-med) allow-discrete, + overlay var(--gmt-duration-med) allow-discrete; +} + +/* The sheen, over the content and never in the way of a press. Closed, the + animation has another name, so each open and each close starts it again. */ +.gmt-panel::after { + position: absolute; + inset: 0; + border-radius: inherit; + corner-shape: inherit; + content: ""; + pointer-events: none; + background-image: var(--gmt-sheen); + background-repeat: no-repeat; + background-size: 250% 100%; + background-position: 110% 0; + animation: gmt-panel-sheen-out var(--gmt-duration-med) ease-in-out; +} + +.gmt-panel:popover-open { + opacity: 1; + translate: 0 0; +} + +@starting-style { + .gmt-panel:popover-open { + opacity: 0; + translate: var(--gmt-panel-from, 0 -0.5rem); + } +} + +.gmt-panel:popover-open::after { + animation-name: gmt-panel-sheen; +} + +@keyframes gmt-panel-sheen { + from { + background-position: -10% 0; + } +} + +@keyframes gmt-panel-sheen-out { + from { + background-position: -10% 0; + } +} + +@media (prefers-reduced-motion: reduce) { + .gmt-panel { + --gmt-panel-from: 0 0; + } + .gmt-panel::after { + animation: none; + } +} + +@media (forced-colors: active), (prefers-contrast: more) { + .gmt-panel::after { + display: none; + } +} + +@media (forced-colors: active) { + .gmt-panel { + border-color: CanvasText; + background: Canvas; + color: CanvasText; + } +} + +/* ---- Toggle button ---- + * A small bevelled button that holds a state (`aria-pressed`), lit while + * pressed. Sized by the caller; an icon alone sits centred. + */ +.gmt-toggle-button { + appearance: none; + box-sizing: border-box; + display: inline-flex; + align-items: center; + justify-content: center; + min-inline-size: var(--gmt-target-min); + min-block-size: var(--gmt-target-min); + padding: 0; + border: 1px solid var(--gmt-hairline); + border-radius: var(--gmt-radius-sm); + corner-shape: bevel; + background-color: var(--gmt-surface-2); + color: var(--gmt-ice); + font: inherit; + cursor: pointer; + transition: + background-color var(--gmt-motion-fast) var(--gmt-easing), + border-color var(--gmt-motion-fast) var(--gmt-easing); +} + +.gmt-toggle-button:hover { + border-color: var(--gmt-cyan); +} + +.gmt-toggle-button:focus-visible { + outline: 2px solid var(--gmt-cyan); + outline-offset: 2px; +} + +.gmt-toggle-button[aria-pressed="true"] { + border-color: var(--gmt-cyan); + background-color: color-mix(in srgb, var(--gmt-cyan) 22%, var(--gmt-surface-2)); +} + +@media (forced-colors: active) { + .gmt-toggle-button { + border-color: ButtonText; + background-color: ButtonFace; + color: ButtonText; + } + .gmt-toggle-button[aria-pressed="true"] { + background-color: Highlight; + color: HighlightText; + } +} + +/* ---- Fader ---- + * A volume fader on a native `` of 11 steps: bevelled ice + * notches, a square bevelled thumb. The notches and the fill share one + * coordinate system, the track less one thumb, so each notch sits where the + * thumb's centre stops. The page sets `--gmt-range-pct` (0 to 100) to fill it. + */ +.gmt-fader { + --fader-thumb-w: 0.875rem; + --fader-thumb-h: 1.5rem; + --fader-track-h: 0.75rem; + --fader-span: calc(100% - var(--fader-thumb-w) + 1px); + --fader-notches: repeating-linear-gradient( + to right, + color-mix(in srgb, var(--gmt-ice) 55%, transparent) 0 1px, + transparent 1px calc((100% - 1px) / 10) + ); + --fader-fill: linear-gradient( + to right, + color-mix(in srgb, var(--gmt-cyan) 55%, transparent) + calc(var(--gmt-range-pct, 0) * 1%), + transparent 0 + ); + + appearance: none; + margin: 0; + inline-size: 8rem; + block-size: var(--fader-thumb-h); + min-block-size: var(--gmt-target-min); + background: transparent; + cursor: pointer; +} + +.gmt-fader:focus-visible { + outline: 2px solid var(--gmt-cyan); + outline-offset: 2px; +} + +.gmt-fader::-webkit-slider-runnable-track { + box-sizing: border-box; + block-size: var(--fader-track-h); + border: 1px solid var(--gmt-border); + border-radius: var(--gmt-bevel-sm); + corner-shape: bevel; + background-color: color-mix(in srgb, var(--gmt-ice) 14%, transparent); + background-image: var(--fader-notches), var(--fader-fill); + background-size: var(--fader-span) 100%; + background-position: calc(var(--fader-thumb-w) / 2 - 0.5px) 0; + background-repeat: no-repeat; +} + +.gmt-fader::-webkit-slider-thumb { + appearance: none; + box-sizing: border-box; + inline-size: var(--fader-thumb-w); + block-size: var(--fader-thumb-h); + translate: 0 calc((var(--fader-track-h) - var(--fader-thumb-h)) / 2 - 1px); + border: 1px solid var(--gmt-border); + border-radius: var(--gmt-bevel-sm); + corner-shape: bevel; + background: var(--gmt-ice); +} + +.gmt-fader::-moz-range-track { + box-sizing: border-box; + block-size: var(--fader-track-h); + border: 1px solid var(--gmt-border); + border-radius: var(--gmt-bevel-sm); + corner-shape: bevel; + background-color: color-mix(in srgb, var(--gmt-ice) 14%, transparent); + background-image: var(--fader-notches), var(--fader-fill); + background-size: var(--fader-span) 100%; + background-position: calc(var(--fader-thumb-w) / 2 - 0.5px) 0; + background-repeat: no-repeat; +} + +.gmt-fader::-moz-range-progress { + background: transparent; +} + +.gmt-fader::-moz-range-thumb { + box-sizing: border-box; + inline-size: var(--fader-thumb-w); + block-size: var(--fader-thumb-h); + border: 1px solid var(--gmt-border); + border-radius: var(--gmt-bevel-sm); + corner-shape: bevel; + background: var(--gmt-ice); +} + +@media (forced-colors: active) { + .gmt-fader { + --fader-notches: repeating-linear-gradient( + to right, + ButtonText 0 1px, + transparent 1px calc((100% - 1px) / 10) + ); + --fader-fill: linear-gradient( + to right, + Highlight calc(var(--gmt-range-pct, 0) * 1%), + transparent 0 + ); + } + .gmt-fader::-webkit-slider-runnable-track { + border-color: ButtonText; + background-color: ButtonFace; + } + .gmt-fader::-moz-range-track { + border-color: ButtonText; + background-color: ButtonFace; + } + .gmt-fader::-webkit-slider-thumb { + border-color: ButtonText; + background: Highlight; + } + .gmt-fader::-moz-range-thumb { + border-color: ButtonText; + background: Highlight; + } +} /* Reduced motion ---- */ @media (prefers-reduced-motion: reduce) { diff --git a/packages/theme/tokens.css b/packages/theme/tokens.css index 40a77b4..21cb4d4 100644 --- a/packages/theme/tokens.css +++ b/packages/theme/tokens.css @@ -468,3 +468,25 @@ font-display: swap; src: url("./fonts/michroma-latin-400-normal.woff2") format("woff2"); } + +/* + * Source: apps/dox/src/styles/gmt-tokens.css lines 117, 119-127, 329-330, 361-362 + * (gmt commit 458860e7730d714b90c63768d9e9758dd1025c01). + * The Settings panel's shape, its sheen and its motion. + */ +:root { + --gmt-ease-sweep: cubic-bezier(0.25, 0.6, 0.2, 1); + --gmt-ice-bright: #e6f6ff; + --gmt-sheen: linear-gradient( + 105deg, + transparent 38%, + color-mix(in oklab, var(--gmt-ice-bright) 10%, transparent) 45%, + color-mix(in oklab, var(--gmt-ice-bright) 24%, transparent) 50%, + color-mix(in oklab, var(--gmt-ice-bright) 10%, transparent) 55%, + transparent 62% + ); + --gmt-target-min: 24px; + --gmt-motion-fast: var(--gmt-duration-fast); + --gmt-bevel-md: 10px; + --gmt-bevel-sm: 6px; +}