Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions apps/site/src/components/Aurora.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -203,6 +205,12 @@ import "@northguild/theme/tokens-aurora.css";
// The part of the popover under the switcher, which scrolls.
const details = document.querySelector<HTMLElement>(".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)),
Expand Down Expand Up @@ -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)];
Expand All @@ -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
Expand Down Expand Up @@ -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<WorkerMessage>) => {
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) {
Expand Down
184 changes: 165 additions & 19 deletions apps/site/src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,110 @@ const links = [
data-ng-target={entrance ? "header" : undefined}
>
<div class="wordmark"><NorthGuildMark />NorthGuild</div>
<nav aria-label="NorthGuild community">
{
links.map((l) => (
<a
class="gmt-icon-button gmt-sonar-focus"
href={l.href}
target="_blank"
rel="noopener noreferrer"
aria-label={`${l.label} (opens in a new tab)`}
<div class="actions">
<nav aria-label="NorthGuild community">
{
links.map((l) => (
<a
class="gmt-icon-button gmt-sonar-focus"
href={l.href}
target="_blank"
rel="noopener noreferrer"
aria-label={`${l.label} (opens in a new tab)`}
title={l.label}
>
<svg viewBox="0 0 24 24" aria-hidden="true" fill="currentColor">
<path d={l.path} />
</svg>
</a>
))
}
</nav>
{/* The Settings gear, last in the bar as on the GMT docs, and its panel:
the mute button beside the volume fader. scripts/sound/control.ts
wires them; Base.astro sets `data-sound` before first paint so the
speaker is drawn right from the first frame. */}
<button
type="button"
class="gmt-icon-button gmt-sonar-focus settings-button"
popovertarget="ng-settings"
aria-label="Settings"
aria-expanded="false"
title="Settings"
>
{/* Lucide's `settings` gear (ISC), filled, its view box cropped so it
stands as tall as GitHub's mark; the hub is cut out by even-odd. */}
<svg
viewBox="1 1 22 22"
fill="currentColor"
fill-rule="evenodd"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path
d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915ZM15 12a3 3 0 1 0-6 0 3 3 0 0 0 6 0Z"
></path>
</svg>
</button>
<div
id="ng-settings"
class="gmt-panel settings-panel"
popover
role="group"
aria-label="Settings"
>
<div class="sound">
<button
type="button"
id="ng-sound-mute"
class="gmt-toggle-button mute"
aria-label="Mute sound"
aria-pressed="true"
data-cue
>
<svg
class="speaker"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<svg viewBox="0 0 24 24" aria-hidden="true" fill="currentColor">
<path d={l.path} />
</svg>
</a>
))
}
</nav>
<path d="M4 9.5v5h3.5L12 18.5v-13L7.5 9.5z"></path>
<path data-slash d="M16 9.5l5 5M21 9.5l-5 5"></path>
<path data-waves d="M16 9a4 4 0 0 1 0 6M18.5 6.5a8 8 0 0 1 0 11"></path>
</svg>
</button>
<input
type="range"
id="ng-sound-fader"
class="gmt-fader"
min="1"
max="11"
step="1"
value="5"
aria-label="Volume"
aria-valuetext="Volume 5 of 11, muted"
style="--gmt-range-pct: 40"
/>
</div>
</div>
</div>
</header>

<script>
import { startCue } from "../scripts/sound/cue";
import { mountSoundControl } from "../scripts/sound/control";

mountSoundControl();
startCue();
</script>

<style>
/* A light frost: what is behind (stars, constellation lines) shows through
softened instead of vanishing. */
Expand Down Expand Up @@ -77,19 +162,80 @@ const links = [
color: var(--gmt-ice);
letter-spacing: 0.04em;
}
/* GitHub, Discord and the gear: one gap between all three, as on the docs. */
.actions,
nav {
display: flex;
align-items: center;
gap: 1rem;
}
/* The icons in the shield's quiet ice rather than the theme's cyan: grey
at rest, ice on hover or focus. The focus ring and its sonar ping stay
the theme's. */
at rest, ice on hover or focus, and the gear while its panel is open.
The focus ring and its ping stay the theme's. */
.gmt-icon-button {
color: var(--gmt-ice-dim);
text-decoration: none;
}
/* A button does not take the page's font size, and the icon buttons are
sized in em: without this the gear is smaller than GitHub and Discord. */
.settings-button {
font: inherit;
}
.gmt-icon-button:hover,
.gmt-icon-button:focus-visible {
.gmt-icon-button:focus-visible,
.settings-button:has(+ .settings-panel:popover-open) {
color: var(--gmt-ice);
}

/* The panel: the speaker beside a fader that fills the rest, in the top
layer under the gear, so opening it and dragging the fader move nothing
in the bar. Fixed insets are the fallback where anchor positioning is
missing: under the bar's right end. */
.settings-panel {
inline-size: min(16rem, calc(100vw - 2rem));
inset: auto;
inset-block-start: calc(3.5rem + 0.25rem);
inset-inline-end: 16px;
}
/* The speaker beside the fader, in their own grid: the panel itself keeps
its own display, so its layout holds while it fades out on close. */
.sound {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
align-items: center;
gap: 0.75rem;
}
.mute {
inline-size: 2rem;
block-size: 2rem;
}
.mute svg {
inline-size: 20px;
block-size: 20px;
}
.settings-panel .gmt-fader {
inline-size: 100%;
}
/* The speaker reads `data-sound` on <html>, set before first paint, so a
muted visitor never sees it on. */
:global(:root[data-sound="off"]) .speaker [data-waves],
:global(:root:not([data-sound="off"])) .speaker [data-slash] {
display: none;
}

@supports (position-area: bottom) {
.settings-button {
anchor-name: --ng-settings;
}
/* Right-aligned to the gear where it fits; on a narrow bar, where that
would cross the 1rem gutter, centred under it instead. */
.settings-panel {
position-anchor: --ng-settings;
position-area: bottom span-left;
position-try-fallbacks: bottom;
inset: auto;
margin-block-start: 0.25rem;
margin-inline-start: 1rem;
}
}
</style>
17 changes: 17 additions & 0 deletions apps/site/src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ const ogAlt =
type="font/woff2"
crossorigin
/>
<script is:inline>
"use strict";
// The sound choice (scripts/sound/settings.ts), before first paint, so
// the Settings panel's speaker is drawn right on the first frame. The
// same key and rule as the GMT docs: sound is on only when a record of
// this version says unmuted; anything else reads as muted.
{
let muted = true;
try {
const saved = JSON.parse(localStorage.getItem("dox:sound"));
if (saved && saved.v === 1 && saved.muted === false) muted = false;
} catch {
// Unreadable or blocked: muted.
}
document.documentElement.dataset.sound = muted ? "off" : "on";
}
</script>
{
entrance && import.meta.env.DEV && (
<script is:inline>
Expand Down
Loading
Loading