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
65 changes: 53 additions & 12 deletions apps/site/src/components/Aurora.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
// follows every upgrade. The package does not export its package.json, so
// it is read by path; only the version string reaches the page.
import { version as gmtVersion } from "../../node_modules/@northguild/gmt/package.json";
// The aurora's own colours, which only the sky uses.
import "@northguild/theme/tokens-aurora.css";
---

<div class="aurora" aria-hidden="true">
Expand Down Expand Up @@ -155,7 +157,7 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
import type { SiteTimes } from "../scripts/aurora.ahead";
import type {
AuroraMessage,
PageBox,
PageTarget,
SkyLabel,
SkyLine,
WorkerMessage,
Expand All @@ -169,6 +171,9 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
"--gmt-teal",
"--gmt-dst-purple",
"--gmt-ice",
"--gmt-aurora-green",
"--gmt-aurora-red",
"--gmt-aurora-fringe",
];

// The visitor can switch site in the popover, which always shows the site
Expand Down Expand Up @@ -210,23 +215,47 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
// Huginn's fly-in draws in the header, title, intro and cards as he
// reaches them. Base.astro hides them (`ng-await`) until the worker says
// he has reached each one; without a fly-in they come in by the usual
// entrance instead. The panes go first (the header, then the cards):
// the worker plans his path through the first two.
// entrance instead. Coming back to the page (`ng-return`, see Base.astro)
// he flies home from the distance instead, and the header stays as it
// was: only the title, intro and cards wait for him. Each says what it is (`data-ng-target`): the worker reaches the
// header and cards in their own ways, and plans his path by the cards.
const page = document.documentElement;
const returning = page.classList.contains("ng-return");
const panes = page.classList.contains("ng-await")
? [
...document.querySelectorAll<HTMLElement>(".ng-enter-pane"),
...document.querySelectorAll<HTMLElement>(".ng-enter-text"),
]
...document.querySelectorAll<HTMLElement>(
".ng-enter-pane, .ng-enter-text",
),
].filter((el) => !returning || el.dataset.ngTarget !== "header")
: [];
function isAwaiting(): boolean {
return page.classList.contains("ng-await");
}
function paneBoxes(): PageBox[] {
function targetKind(el: HTMLElement): PageTarget["kind"] {
const kind = el.dataset.ngTarget;
return kind === "header" || kind === "card" ? kind : "text";
}
// The card for the page this visit came back from: the one whose docs sit
// above it on this site (`data-ng-path`, "/gmt/" for any of the GMT
// docs). Only the card's own docs path counts, not its other links, which
// may lead off the site. -1 if none.
function cardCameFrom(): number {
const path = page.dataset.ngFrom ?? "";
if (!returning || !path) return -1;
return panes.findIndex((el) => {
const docs = el.dataset.ngPath ?? "";
return (
el.dataset.ngTarget === "card" &&
docs.length > 1 &&
path.startsWith(docs)
);
});
}
function pageTargets(): PageTarget[] {
if (!isAwaiting()) return [];
return panes.map((el) => {
const r = el.getBoundingClientRect();
return [r.left, r.top, r.width, r.height];
return { kind: targetKind(el), box: [r.left, r.top, r.width, r.height] };
});
}
function showAllPanes(): void {
Expand Down Expand Up @@ -257,12 +286,15 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
el.classList.add("ng-brushed");
}
// His flight draws the panes in. This is only a safety net for a stalled
// worker, late enough never to start a pane ahead of him in a normal flight.
// or slow worker: on a first visit late enough never to start a pane ahead
// of him in a normal flight; coming back, the page is in by 3 s whatever
// he is doing.
function brushRemainingPanes(): void {
panes.forEach((_, i) => brushPane(i, lastAngle, 1));
}
if (panes.length) {
setTimeout(brushRemainingPanes, Math.max(0, 8000 - performance.now()));
const by = returning ? 3000 : 8000;
setTimeout(brushRemainingPanes, Math.max(0, by - performance.now()));
}

// All WebGL runs in the worker. Without OffscreenCanvas the CSS gradient
Expand Down Expand Up @@ -294,7 +326,16 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
site: chosen,
still: motion.matches,
hidden: document.hidden,
targets: paneBoxes(),
targets: pageTargets(),
flyIn: returning ? "return" : "first",
from: cardCameFrom(),
// Dev only (Base.astro): `?aurora=active` or `?aurora=calm`.
activity:
page.dataset.aurora === "active"
? 1
: page.dataset.aurora === "calm"
? 0
: -1,
},
[offscreen],
);
Expand Down Expand Up @@ -336,7 +377,7 @@ import { version as gmtVersion } from "../../node_modules/@northguild/gmt/packag
type: "size",
width: canvas.clientWidth,
height: canvas.clientHeight,
targets: paneBoxes(),
targets: pageTargets(),
}),
150,
);
Expand Down
9 changes: 9 additions & 0 deletions apps/site/src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const links = [

<header
class:list={["gmt-glass", "site-header", { "ng-enter-pane": entrance }]}
data-ng-target={entrance ? "header" : undefined}
>
<div class="wordmark"><NorthGuildMark />NorthGuild</div>
<nav aria-label="NorthGuild community">
Expand Down Expand Up @@ -80,7 +81,15 @@ const links = [
display: flex;
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. */
.gmt-icon-button {
color: var(--gmt-ice-dim);
text-decoration: none;
}
.gmt-icon-button:hover,
.gmt-icon-button:focus-visible {
color: var(--gmt-ice);
}
</style>
10 changes: 9 additions & 1 deletion apps/site/src/components/RepoCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ interface Props {
order?: number;
}
const { name, description, docsHref, githubHref, order = 0 } = Astro.props;
// Where the docs sit on this site ("/gmt/"): coming back from any page under
// it, Huginn flies home from this card's side (Aurora.astro).
const docsPath = new URL(docsHref, Astro.site).pathname;
---

<article class="gmt-glass repo-card ng-enter-pane" style={`--order: ${order}`}>
<article
class="gmt-glass repo-card ng-enter-pane"
data-ng-target="card"
data-ng-path={docsPath}
style={`--order: ${order}`}
>
<h2>{name}</h2>
<p>{description}</p>
<div class="links">
Expand Down
68 changes: 62 additions & 6 deletions apps/site/src/layouts/Base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,73 @@ const ogAlt =
type="font/woff2"
crossorigin
/>
{
entrance && import.meta.env.DEV && (
<script is:inline>
// Dev only: `?huginn=return` or `?huginn=first` picks the fly-in to
// preview, whatever page came before, and `&from=/gmt/` (any path)
// the page to come back from. Reload for a new flight. `?aurora=active`
// or `?aurora=calm` holds the aurora in a surge or quiet.
{
const query = new URLSearchParams(location.search);
const page = document.documentElement;
page.dataset.huginn = query.get("huginn") || "";
page.dataset.ngFrom = query.get("from") || "";
page.dataset.aurora = query.get("aurora") || "";
}
</script>
)
}
{
entrance && (
<script is:inline>
// Huginn's fly-in paints the header and cards in as he passes
// (Aurora.astro); they wait for him, hidden. Only where the sky can
// run with motion, and never for more than 4 s: if he has not
// passed the first by then, the usual entrance plays.
"use strict";
// Coming back from another of the site's pages (the GMT or worktree
// docs), or by Back or Forward: the header is already up, so it
// stays put and only the title, intro and cards come in again. A
// fresh visit or a reload plays the whole entrance. The page came
// back from is kept (`data-ng-from`) so Huginn can fly home from
// its card's side; Back and Forward do not say which page that was.
// In a block, so nothing here is left on the window.
{
// The path of the page this visit came back from, "" when that is
// not known (Back or Forward), or null when it is not a return.
function cameBackFrom() {
try {
const visit = performance.getEntriesByType("navigation")[0];
if (visit && visit.type === "back_forward") return "";
if (visit && visit.type !== "navigate") return null;
const from = new URL(document.referrer);
return from.origin === location.origin &&
from.pathname !== location.pathname
? from.pathname
: null;
} catch {
return null;
}
}
const page = document.documentElement;
const back = cameBackFrom();
const flyIn =
page.dataset.huginn || (back === null ? "first" : "return");
if (flyIn === "return") page.classList.add("ng-return");
if (back) page.dataset.ngFrom = back;
// Huginn's fly-in paints the page in as he passes (Aurora.astro);
// it waits for him, hidden. Only where the sky can run with motion,
// and never for more than 4 s: if he has not reached the first box
// by then, the usual entrance plays.
if (
!matchMedia("(prefers-reduced-motion: reduce)").matches &&
"transferControlToOffscreen" in HTMLCanvasElement.prototype
) {
document.documentElement.classList.add("ng-await");
page.classList.add("ng-await");
setTimeout(function showIfHuginnIsLate() {
if (!document.querySelector(".ng-brushed")) {
document.documentElement.classList.remove("ng-await");
page.classList.remove("ng-await");
}
}, 4000);
}
}
</script>
)
}
Expand Down Expand Up @@ -218,6 +267,13 @@ const ogAlt =
animation-name: none;
opacity: 0;
}
/* Coming back (`ng-return`, set in the head): the header is already up
and stays as it is. The title, intro and cards come in again, by
Huginn's homecoming or the usual entrance. */
html.ng-return :is(.ng-enter-pane, .ng-enter-text)[data-ng-target="header"] {
animation-name: none;
opacity: 1;
}
:is(.ng-enter-pane, .ng-enter-text).ng-brushed {
--ng-sweep: linear-gradient(
var(--ng-angle, 135deg),
Expand Down
Loading
Loading