Initial public release
Luxe 0.1.0: a coding agent harness for the terminal. See README.md to get started and CHANGELOG.md for releases.
This commit is contained in:
61
web/src/components/CopyMarkdown.svelte
Normal file
61
web/src/components/CopyMarkdown.svelte
Normal file
@@ -0,0 +1,61 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* A page of the guide as markdown: copied, for pasting into an agent, or opened as a file.
|
||||
*
|
||||
* Copies the served `.md` rather than the page's text, so a prompt gets the source
|
||||
* with its code blocks and links intact, not the rendered page flattened.
|
||||
*/
|
||||
let { href }: { href: string } = $props();
|
||||
|
||||
let state = $state<"idle" | "copied" | "failed">("idle");
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
|
||||
async function copy() {
|
||||
try {
|
||||
const response = await fetch(href);
|
||||
if (!response.ok) throw new Error(String(response.status));
|
||||
await navigator.clipboard.writeText(await response.text());
|
||||
state = "copied";
|
||||
} catch {
|
||||
state = "failed";
|
||||
}
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => (state = "idle"), 1600);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="markdown">
|
||||
<button class="markdown__copy" onclick={copy}>
|
||||
{state === "copied" ? "Copied" : state === "failed" ? "Copy failed" : "Copy as Markdown"}
|
||||
</button>
|
||||
<a class="markdown__view" {href}>View as Markdown</a>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.markdown {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
margin-top: var(--space-3);
|
||||
font-size: var(--step--1);
|
||||
}
|
||||
|
||||
.markdown__copy {
|
||||
font: inherit;
|
||||
letter-spacing: 0.06em;
|
||||
padding: 0.4em 0.9em;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
background: var(--luxe-selected-bg);
|
||||
color: var(--luxe-muted);
|
||||
transition: color 150ms var(--ease);
|
||||
}
|
||||
|
||||
.markdown__copy:hover {
|
||||
color: var(--luxe-accent);
|
||||
}
|
||||
|
||||
.markdown__view {
|
||||
color: var(--luxe-muted);
|
||||
}
|
||||
</style>
|
||||
318
web/src/components/Demo.svelte
Normal file
318
web/src/components/Demo.svelte
Normal file
@@ -0,0 +1,318 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* A recorded terminal session, played rather than described.
|
||||
*
|
||||
* The recordings are asciicast, not video: a few hundred kilobytes each, sharp at any DPI, and
|
||||
* the text inside stays selectable — you can copy a command out of a demo. The player is ~180 KB
|
||||
* of JavaScript, which is why this island is `client:visible` and its CSS is imported here rather
|
||||
* than in the page's critical path.
|
||||
*
|
||||
* **Two recordings per demo, and the reason is arithmetic.** A cast is drawn at a fixed size per
|
||||
* character, so the column count *is* the type size. The 150 columns that make the workspace
|
||||
* legible on a laptop come out at 2.7px a character on a phone, which is the same as not being
|
||||
* there; the ~72 that read on a phone waste two thirds of a desktop page. So each script is shot
|
||||
* at both sizes and the media query picks one. The two takes are separate sessions against a real
|
||||
* model, so they do not say identical things — each is honest about the same feature.
|
||||
*
|
||||
* **One theme.** A recording bakes its colors in, and they are the colors the page is set in.
|
||||
*/
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import "asciinema-player/dist/bundle/asciinema-player.css";
|
||||
|
||||
interface Props {
|
||||
/** URL of the wide recording. */
|
||||
src: string;
|
||||
/** Columns it was recorded at, which sets the type size. */
|
||||
cols: number;
|
||||
/** Rows, used to reserve the right box before the player loads. */
|
||||
rows: number;
|
||||
/** URL of the narrow recording, for phones. */
|
||||
mobile?: string;
|
||||
/** Columns the narrow recording was shot at. */
|
||||
mobileCols?: number;
|
||||
mobileRows?: number;
|
||||
/** Caption under the frame. */
|
||||
caption: string;
|
||||
}
|
||||
const { src, cols, rows, mobile, mobileCols = 72, mobileRows = 24, caption }: Props = $props();
|
||||
|
||||
/**
|
||||
* The row pitch, and it is a measurement rather than a preference.
|
||||
*
|
||||
* Ghostty draws box-drawing and block characters itself, so a rule runs unbroken down a column no
|
||||
* matter how the rows are spaced. A browser cannot: it typesets the glyph, and the glyph is only
|
||||
* as tall as the font drew it. JetBrains Mono's `█` measures exactly 1.32em, so any line height
|
||||
* above that opens a seam under every row — which is what put hairlines through every border,
|
||||
* every composer and every slab in the demos while the same session looked perfect in a real
|
||||
* terminal.
|
||||
*
|
||||
* Set to the glyph, the rules tile. Descenders are not clipped by it because 1.32em is the face's
|
||||
* own full extent, ascender to descender, not a tightened version of it.
|
||||
*/
|
||||
const LINE_HEIGHT = 1.32;
|
||||
|
||||
/**
|
||||
* JetBrains Mono's advance, as a fraction of its font size. Measured, not guessed: the player
|
||||
* sets the terminal to `150ch` and a `ch` here comes out at 0.6 of the font size.
|
||||
*
|
||||
* It matters because the width below is what *sets* the type size, and a wrong figure reserves
|
||||
* the wrong box: the demo then stands taller or shorter than the player draws it and the page
|
||||
* jumps when it hydrates.
|
||||
*/
|
||||
const ADVANCE = 0.6;
|
||||
|
||||
/**
|
||||
* The largest a cell is allowed to get.
|
||||
*
|
||||
* Past this a demo stops reading as a terminal on a page and starts reading as an application
|
||||
* somebody embedded. The size actually used is usually smaller — the interesting constraint is
|
||||
* the `--cell` sum in the stylesheet.
|
||||
*/
|
||||
const MAX_CELL = 10;
|
||||
|
||||
/**
|
||||
* How many cell-widths tall a row is: the advance is 0.6 of the type size, and a row is 1.32 of
|
||||
* that type size.
|
||||
*
|
||||
* Written down because the stylesheet solves for a cell that makes the whole demo fit the screen,
|
||||
* and a second copy of this arithmetic that disagreed would reserve the wrong box and make the
|
||||
* page jump when the player arrives.
|
||||
*/
|
||||
const ROW_CELLS = LINE_HEIGHT / ADVANCE;
|
||||
|
||||
|
||||
/** Below this the wide cut is unreadable, so the narrow one plays instead. */
|
||||
const NARROW_BELOW = 720;
|
||||
|
||||
/**
|
||||
* How much of a demo has to be on screen before it starts.
|
||||
*
|
||||
* `client:visible` hydrates the island the moment its first pixel crosses the viewport, which for
|
||||
* something this tall means the demo begins while it is still almost entirely below the fold —
|
||||
* the reader arrives partway through a take that is already explaining itself. Waiting for most
|
||||
* of it to be in view costs nothing and means the first frame is the first thing seen.
|
||||
*/
|
||||
const PLAY_WHEN_VISIBLE = 0.55;
|
||||
|
||||
let mount: HTMLDivElement;
|
||||
let player: { dispose(): void; addEventListener?(event: string, fn: () => void): void } | null =
|
||||
null;
|
||||
let figure: HTMLElement;
|
||||
let started = false;
|
||||
let narrow = $state(false);
|
||||
let ended = $state(false);
|
||||
let query: MediaQueryList | null = null;
|
||||
|
||||
const active = $derived(narrow && mobile ? mobile : src);
|
||||
const activeCols = $derived(narrow && mobile ? mobileCols : cols);
|
||||
const activeRows = $derived(narrow && mobile ? mobileRows : rows);
|
||||
|
||||
async function create() {
|
||||
const { create: createPlayer } = await import("asciinema-player");
|
||||
// The player sizes the terminal by *measuring* a character, so measuring before the webfont
|
||||
// arrives measures the fallback — and the terminal then sits at the wrong scale for the rest of
|
||||
// its life. `font-display: swap` guarantees that race unless we wait it out. Asked for by name:
|
||||
// `fonts.ready` only waits for faces already loading, and nothing has drawn the terminal's yet,
|
||||
// so on a cold load it resolved at once and Firefox sized the first demo to the fallback.
|
||||
await Promise.all(
|
||||
["1em", "bold 1em"].map((style) =>
|
||||
document.fonts.load(`${style} "JetBrainsMono Nerd Font Mono"`).catch(() => []),
|
||||
),
|
||||
);
|
||||
await document.fonts.ready;
|
||||
player?.dispose();
|
||||
mount.replaceChildren();
|
||||
ended = false;
|
||||
player = createPlayer(active, mount, {
|
||||
// Plays once and stops on its last frame. It used to loop, on the theory that a demo halted
|
||||
// on a still reads as a broken image — but these end somewhere worth looking at, and a loop
|
||||
// restarting under a reader mid-sentence is worse than a stop. Replay is one button.
|
||||
autoPlay: true,
|
||||
loop: false,
|
||||
controls: false,
|
||||
fit: "width",
|
||||
terminalFontFamily:
|
||||
"'JetBrainsMono Nerd Font Mono', 'AdwaitaMono Nerd Font Mono', 'JetBrains Mono', ui-monospace, monospace",
|
||||
terminalLineHeight: LINE_HEIGHT,
|
||||
});
|
||||
player?.addEventListener?.("ended", () => {
|
||||
ended = true;
|
||||
});
|
||||
|
||||
// The player measures its wrapper once on create. Our width override lands in the same frame,
|
||||
// so nudge it to measure again rather than living with whatever it saw first.
|
||||
requestAnimationFrame(() => window.dispatchEvent(new Event("resize")));
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
query = window.matchMedia(`(max-width: ${NARROW_BELOW - 1}px)`);
|
||||
narrow = query.matches;
|
||||
// Re-created rather than re-sourced: the player owns a terminal sized to the old cast, and
|
||||
// handing it a different geometry mid-life leaves it drawing at the previous scale.
|
||||
const swap = () => {
|
||||
const next = query!.matches;
|
||||
if (next === narrow) return;
|
||||
narrow = next;
|
||||
if (started) create();
|
||||
};
|
||||
query.addEventListener("change", swap);
|
||||
|
||||
// Started when it is actually being looked at, not when the island hydrates. Once only: a demo
|
||||
// that restarts every time it scrolls back into view is a demo nobody can leave and return to.
|
||||
const watcher = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
if (!entry.isIntersecting || started) return;
|
||||
started = true;
|
||||
watcher.disconnect();
|
||||
create();
|
||||
},
|
||||
{ threshold: PLAY_WHEN_VISIBLE },
|
||||
);
|
||||
watcher.observe(figure);
|
||||
|
||||
return () => {
|
||||
query?.removeEventListener("change", swap);
|
||||
watcher.disconnect();
|
||||
};
|
||||
});
|
||||
|
||||
onDestroy(() => player?.dispose());
|
||||
</script>
|
||||
|
||||
<figure
|
||||
bind:this={figure}
|
||||
class="demo"
|
||||
style="--cols: {activeCols}; --rows: {activeRows}; --max-cell: {MAX_CELL}px; --row-cells: {ROW_CELLS}"
|
||||
>
|
||||
<div class="demo__plate plate">
|
||||
<div class="demo__frame" style="--aspect: {activeCols * ADVANCE} / {activeRows * LINE_HEIGHT}">
|
||||
<div class="demo__mount" bind:this={mount}></div>
|
||||
</div>
|
||||
</div>
|
||||
<figcaption class="demo__caption muted">
|
||||
<span>{caption}</span>
|
||||
<!-- Only after it has ended: a control offering to restart something already playing is one
|
||||
more thing to read past. -->
|
||||
{#if ended}
|
||||
<button class="demo__replay" type="button" onclick={create}>
|
||||
<span aria-hidden="true">↺</span> Replay
|
||||
</button>
|
||||
{/if}
|
||||
</figcaption>
|
||||
</figure>
|
||||
|
||||
<style>
|
||||
/* Wide enough for its own columns, even when that is wider than the measure the prose is set to.
|
||||
A three-pane surface squeezed into a reading column reads as a diff viewer, which is the one
|
||||
thing it is not. Centered with `translate` rather than `transform`, because the section's
|
||||
scroll-driven reveal owns `transform` and would overwrite it. */
|
||||
/* As large as fits, which turns out to be a question about the screen's *height*.
|
||||
|
||||
One size per character cannot be right twice. Seven pixels left a 150-column demo sitting in
|
||||
the middle third of a 2560px display looking like a thumbnail; nine filled that display and
|
||||
made the same demo 826px tall, which does not fit a 1366x768 laptop along with its own caption.
|
||||
The binding constraint is vertical — rows times the row pitch — so that is what the cell is
|
||||
solved for, and the width follows from it.
|
||||
|
||||
The 8.75rem is everything that has to share the screen with the terminal: the plate's padding,
|
||||
the caption under it, and air above and below so it is not wedged against the fold. */
|
||||
.demo {
|
||||
--cell: min(var(--max-cell), calc((100svh - 8.75rem) / (var(--rows) * var(--row-cells))));
|
||||
/* Never wider than whatever is holding it.
|
||||
|
||||
This used to cap at `--page` and center itself with `left: 50%; translate: -50%`, which is
|
||||
the full-bleed trick and only works when the parent *is* the page. Inside a grid track it
|
||||
measured the page, came out wider than its column, and hung off the left edge of the screen.
|
||||
A plain `100%` cap and auto margins let the same demo sit in the hero, in a section's media
|
||||
track, or in a single stacked column without knowing which. */
|
||||
width: min(calc(var(--cols) * var(--cell) + 2 * var(--space-3)), 100%);
|
||||
margin-inline: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* The terminal's own background, not the site's raised surface.
|
||||
|
||||
Luxe paints a background into most of its cells rather than leaving them default, so a plate
|
||||
in any other color splits the picture in two: painted cells become dark rectangles and
|
||||
unpainted ones show the plate through. It reads as a corrupted capture, and it is the reason
|
||||
these looked broken in a browser while the recording itself was clean. `--luxe-capture-bg` is
|
||||
generated from the dark theme and does not follow the page's mode, because the recording does
|
||||
not either. */
|
||||
.demo__frame {
|
||||
/* Reserve the box before the player exists, or the page jumps when it arrives — but only as a
|
||||
minimum: once the player is up it owns its own height, and a hard aspect box would either
|
||||
crop it or leave a band of dead canvas under it. */
|
||||
min-height: 0;
|
||||
aspect-ratio: var(--aspect);
|
||||
padding: var(--space-3);
|
||||
background: var(--luxe-capture-bg);
|
||||
}
|
||||
|
||||
:global(.demo__frame:has(.ap-player)) {
|
||||
aspect-ratio: auto;
|
||||
}
|
||||
|
||||
.demo__mount {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.demo__caption {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: baseline;
|
||||
gap: var(--space-3);
|
||||
font-size: var(--step--1);
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
|
||||
/* Sits in the caption rather than over the demo: an overlay would cover the last frame, which is
|
||||
the one the demo spent half a minute earning. */
|
||||
.demo__replay {
|
||||
flex: none;
|
||||
font: inherit;
|
||||
color: var(--luxe-accent);
|
||||
background: none;
|
||||
border: var(--border);
|
||||
border-color: currentcolor;
|
||||
padding: 0.15em 0.7em;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.2s var(--ease);
|
||||
}
|
||||
|
||||
.demo__replay:hover,
|
||||
.demo__replay:focus-visible {
|
||||
background: var(--luxe-user-msg-bg);
|
||||
}
|
||||
|
||||
/* The player brings its own palette; point it at the recording's. */
|
||||
.demo__frame :global(.ap-player) {
|
||||
--term-color-background: transparent;
|
||||
--term-color-foreground: var(--luxe-capture-fg);
|
||||
}
|
||||
|
||||
/* `.ap-term`, not `.ap-terminal` — the latter is not a class the player has ever defined, so the
|
||||
rule silently did nothing and the player's own background sat inside our plate as a second,
|
||||
slightly wrong rectangle. */
|
||||
.demo__frame :global(.ap-term) {
|
||||
background: transparent !important;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* Fractional advances. Chrome otherwise rounds each glyph's advance to a whole pixel at these
|
||||
sizes, so a 120-column line is 120 times the rounding error off the width the player sized it
|
||||
for: a demo at 10.86px drew each 6.52px cell as 7 and ran 7% off the right of its frame,
|
||||
cutting the model's name at the statusline's edge, while one at 8.68px came up 4% short. Which
|
||||
one a reader got depended on their window. */
|
||||
.demo__frame :global(.ap-term),
|
||||
.demo__frame :global(.ap-term *) {
|
||||
text-rendering: geometricPrecision;
|
||||
}
|
||||
|
||||
/* `fit: "width"` scales the terminal to its *wrapper*, and the wrapper is content-sized by
|
||||
default — so without this the demo renders at whatever the font's natural size happens to be
|
||||
and leaves the frame half empty. */
|
||||
.demo__frame :global(.ap-wrapper),
|
||||
.demo__frame :global(.ap-player) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
148
web/src/components/DocsSearch.svelte
Normal file
148
web/src/components/DocsSearch.svelte
Normal file
@@ -0,0 +1,148 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* Full-text search over the manual, via Pagefind.
|
||||
*
|
||||
* Pagefind indexes the *built* site rather than the source, so what it searches is exactly what a
|
||||
* reader sees. The index is fetched on first keystroke, not on page load — it is a few hundred
|
||||
* kilobytes, and most visits never search.
|
||||
*/
|
||||
type Result = { url: string; meta: { title?: string }; excerpt: string };
|
||||
|
||||
let query = $state("");
|
||||
let results = $state<Result[]>([]);
|
||||
let active = $state(false);
|
||||
let pagefind: { search(q: string): Promise<{ results: { data(): Promise<Result> }[] }> } | null =
|
||||
null;
|
||||
|
||||
async function load() {
|
||||
if (pagefind) return pagefind;
|
||||
// Built into /pagefind/ *after* this bundle, by indexing the output it belongs to. The path is
|
||||
// assembled at runtime so neither Vite nor TypeScript tries to resolve a file that cannot exist
|
||||
// until the build that produced them both has finished.
|
||||
const url = ["", "pagefind", "pagefind.js"].join("/");
|
||||
pagefind = await import(/* @vite-ignore */ url);
|
||||
return pagefind;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
if (query.trim().length < 2) {
|
||||
results = [];
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const engine = await load();
|
||||
const found = await engine!.search(query);
|
||||
results = await Promise.all(found.results.slice(0, 8).map((r) => r.data()));
|
||||
} catch {
|
||||
// No index in `astro dev` — the search box is inert there rather than throwing.
|
||||
results = [];
|
||||
}
|
||||
}
|
||||
|
||||
function onKey(event: KeyboardEvent) {
|
||||
if (event.key === "Escape") {
|
||||
query = "";
|
||||
results = [];
|
||||
(event.target as HTMLInputElement).blur();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onkeydown={(e) => {
|
||||
if (e.key === "/" && document.activeElement?.tagName !== "INPUT") {
|
||||
e.preventDefault();
|
||||
document.getElementById("docs-search")?.focus();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
<div class="search" class:is-open={active && results.length > 0}>
|
||||
<input
|
||||
id="docs-search"
|
||||
class="search__input"
|
||||
type="search"
|
||||
placeholder="Search /"
|
||||
aria-label="Search documentation"
|
||||
bind:value={query}
|
||||
oninput={run}
|
||||
onfocus={() => (active = true)}
|
||||
onblur={() => setTimeout(() => (active = false), 150)}
|
||||
onkeydown={onKey}
|
||||
/>
|
||||
|
||||
{#if active && results.length > 0}
|
||||
<ol class="search__results plate">
|
||||
{#each results as result (result.url)}
|
||||
<li>
|
||||
<a class="search__hit" href={result.url}>
|
||||
<span class="search__title">{result.meta.title ?? "Untitled"}</span>
|
||||
<span class="search__excerpt">{@html result.excerpt}</span>
|
||||
</a>
|
||||
</li>
|
||||
{/each}
|
||||
</ol>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.search {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.search__input {
|
||||
width: 100%;
|
||||
font: inherit;
|
||||
font-size: var(--step--1);
|
||||
padding: 0.55em 0.8em;
|
||||
border: 0;
|
||||
background: var(--luxe-user-msg-bg);
|
||||
color: var(--luxe-text);
|
||||
}
|
||||
|
||||
.search__input::placeholder {
|
||||
color: var(--luxe-dim);
|
||||
}
|
||||
|
||||
.search__results {
|
||||
position: absolute;
|
||||
z-index: 6;
|
||||
top: calc(100% + 0.4rem);
|
||||
left: 0;
|
||||
width: max(100%, 22rem);
|
||||
max-height: 26rem;
|
||||
overflow-y: auto;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 1px;
|
||||
}
|
||||
|
||||
.search__hit {
|
||||
display: grid;
|
||||
gap: 0.2rem;
|
||||
padding: 0.6rem 0.8rem;
|
||||
text-decoration: none;
|
||||
background: var(--luxe-user-msg-bg);
|
||||
}
|
||||
|
||||
.search__hit:hover {
|
||||
background: var(--luxe-selected-bg);
|
||||
}
|
||||
|
||||
.search__title {
|
||||
color: var(--luxe-accent);
|
||||
font-size: var(--step--1);
|
||||
}
|
||||
|
||||
.search__excerpt {
|
||||
color: var(--luxe-muted);
|
||||
font-size: var(--step--1);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.search__excerpt :global(mark) {
|
||||
background: none;
|
||||
color: var(--luxe-text);
|
||||
font-weight: 700;
|
||||
}
|
||||
</style>
|
||||
127
web/src/components/InstallTabs.svelte
Normal file
127
web/src/components/InstallTabs.svelte
Normal file
@@ -0,0 +1,127 @@
|
||||
<script lang="ts">
|
||||
/** The install command, per channel, with a copy button. */
|
||||
|
||||
type Channel = { id: string; label: string; command: string; note?: string };
|
||||
|
||||
const channels: Channel[] = [
|
||||
{ id: "cargo", label: "cargo", command: "cargo install luxe-cli" },
|
||||
{
|
||||
id: "source",
|
||||
label: "source",
|
||||
command: "git clone https://github.com/evanwhittaker/luxe && cd luxe && cargo build --release",
|
||||
},
|
||||
];
|
||||
|
||||
let active = $state(channels[0]);
|
||||
let copied = $state(false);
|
||||
let timer: ReturnType<typeof setTimeout>;
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(active.command);
|
||||
copied = true;
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => (copied = false), 1600);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="install plate">
|
||||
<div class="install__inner">
|
||||
<div class="install__tabs" role="tablist" aria-label="Install method">
|
||||
{#each channels as channel (channel.id)}
|
||||
<button
|
||||
role="tab"
|
||||
aria-selected={active.id === channel.id}
|
||||
class="install__tab"
|
||||
class:is-active={active.id === channel.id}
|
||||
onclick={() => (active = channel)}
|
||||
>
|
||||
{channel.label}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="install__row">
|
||||
<code class="install__command"><span class="install__prompt" aria-hidden="true">$</span>{active.command}</code>
|
||||
<button class="install__copy" onclick={copy} aria-label="Copy install command">
|
||||
{copied ? "copied" : "copy"}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.install {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.install__inner {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.install__tabs {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
border-bottom: 1px solid var(--luxe-border-muted);
|
||||
}
|
||||
|
||||
.install__tab {
|
||||
font: inherit;
|
||||
font-size: var(--step--1);
|
||||
letter-spacing: 0.1em;
|
||||
padding: 0.75em 1.2em;
|
||||
background: none;
|
||||
border: 0;
|
||||
border-bottom: 2px solid transparent;
|
||||
color: var(--luxe-muted);
|
||||
cursor: pointer;
|
||||
transition: color 150ms var(--ease), border-color 150ms var(--ease);
|
||||
}
|
||||
|
||||
.install__tab:hover {
|
||||
color: var(--luxe-text);
|
||||
}
|
||||
|
||||
.install__tab.is-active {
|
||||
color: var(--luxe-accent);
|
||||
border-bottom-color: var(--luxe-accent);
|
||||
}
|
||||
|
||||
.install__row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-3);
|
||||
padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
|
||||
}
|
||||
|
||||
.install__command {
|
||||
flex: 1;
|
||||
color: var(--luxe-text);
|
||||
font-size: var(--step-0);
|
||||
overflow-x: auto;
|
||||
white-space: nowrap;
|
||||
scrollbar-width: thin;
|
||||
}
|
||||
|
||||
.install__prompt {
|
||||
color: var(--luxe-dim);
|
||||
margin-right: 0.8em;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.install__copy {
|
||||
flex: none;
|
||||
font: inherit;
|
||||
font-size: var(--step--1);
|
||||
letter-spacing: 0.1em;
|
||||
padding: 0.5em 1em;
|
||||
border: 0;
|
||||
cursor: pointer;
|
||||
background: var(--luxe-selected-bg);
|
||||
color: var(--luxe-muted);
|
||||
transition: color 150ms var(--ease);
|
||||
}
|
||||
|
||||
.install__copy:hover {
|
||||
color: var(--luxe-accent);
|
||||
}
|
||||
</style>
|
||||
234
web/src/components/Refine.astro
Normal file
234
web/src/components/Refine.astro
Normal file
@@ -0,0 +1,234 @@
|
||||
---
|
||||
/**
|
||||
* A few words in a heading that edit themselves, once, when the heading scrolls into view.
|
||||
*
|
||||
* The hero refines one word by restyling it. Section headings take the same gesture one step
|
||||
* further, the way an editor would: a caret lands at the end of the old words, drags a selection
|
||||
* back across them, and types the new ones over it. It reads as the page being revised, which is
|
||||
* the whole idea of the product, and it only ever happens once per heading.
|
||||
*
|
||||
* The finished heading is the one in the markup. The words are real text, styled like the hero's
|
||||
* `em`, so with no JavaScript, with reduced motion, or to a crawler, the heading is the final
|
||||
* sentence. When the script takes over it hides that text visually (a screen reader still reads
|
||||
* it, and only it) and draws the animation from a `data-` attribute through `::before`, which is
|
||||
* neither announced inside `aria-hidden` nor copied with a selection.
|
||||
*/
|
||||
interface Props {
|
||||
/** What the heading says before it's revised. */
|
||||
from: string;
|
||||
/** What it says after, and what every reader without the animation gets. */
|
||||
to: string;
|
||||
}
|
||||
const { from, to } = Astro.props;
|
||||
---
|
||||
|
||||
<span class="refine" data-refine data-from={from} data-to={to}
|
||||
><span class="refine__text">{to}</span><span class="refine__vis" aria-hidden="true"
|
||||
><span class="refine__caret"></span></span
|
||||
></span
|
||||
>
|
||||
|
||||
<script>
|
||||
// Timings in ms. The drag is quick because pulling a cursor across a word is the fastest thing
|
||||
// a person does; the holds are long enough to read what changed.
|
||||
const BLINK = 900;
|
||||
const DRAG_STEP = 55;
|
||||
const HOLD = 520;
|
||||
const TYPE_BASE = 70;
|
||||
const TYPE_SPREAD = 60;
|
||||
const LINGER = 1100;
|
||||
|
||||
const calm = matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const wait = (ms: number) => new Promise((done) => setTimeout(done, ms));
|
||||
|
||||
// Keystroke gaps that look typed rather than metronomic, and come out the same on every visit.
|
||||
const gap = (i: number, ch: string) =>
|
||||
TYPE_BASE + ((i * 37 + ch.charCodeAt(0) * 11) % TYPE_SPREAD) + (ch === " " ? 40 : 0);
|
||||
|
||||
async function play(el: HTMLElement, heading: HTMLElement) {
|
||||
const vis = el.querySelector<HTMLElement>(".refine__vis")!;
|
||||
const from = el.dataset.from ?? "";
|
||||
const to = el.dataset.to ?? "";
|
||||
|
||||
el.dataset.state = "caret";
|
||||
await wait(BLINK);
|
||||
|
||||
// Right to left, a character at a time: the cursor lands past the end and pulls back.
|
||||
el.dataset.state = "select";
|
||||
vis.dataset.sel = from;
|
||||
for (let k = 1; k <= from.length; k++) {
|
||||
const left = 100 - (k / from.length) * 100;
|
||||
vis.style.setProperty("--sel-left", `${left}%`);
|
||||
await wait(DRAG_STEP);
|
||||
}
|
||||
await wait(HOLD);
|
||||
|
||||
// The first keystroke replaces the selection, the rest extend it.
|
||||
el.dataset.state = "type";
|
||||
vis.dataset.sel = "";
|
||||
for (let i = 0; i < to.length; i++) {
|
||||
vis.dataset.text = to.slice(0, i + 1);
|
||||
await wait(gap(i, to[i]));
|
||||
}
|
||||
|
||||
el.dataset.state = "linger";
|
||||
await wait(LINGER);
|
||||
el.dataset.state = "done";
|
||||
el.classList.remove("refine--break");
|
||||
heading.classList.remove("refine-hold");
|
||||
heading.style.removeProperty("min-height");
|
||||
}
|
||||
|
||||
function arm(el: HTMLElement) {
|
||||
const heading = (el.closest("h1, h2, h3") as HTMLElement | null) ?? el;
|
||||
const vis = el.querySelector<HTMLElement>(".refine__vis")!;
|
||||
|
||||
// Measured finished, then set back to the old words, so a revision that wraps differently
|
||||
// cannot move the paragraph under the heading while it plays.
|
||||
const top = () => el.getBoundingClientRect().top - heading.getBoundingClientRect().top;
|
||||
vis.dataset.text = el.dataset.to ?? "";
|
||||
el.dataset.state = "done";
|
||||
el.classList.add("is-live");
|
||||
heading.style.minHeight = `${heading.getBoundingClientRect().height}px`;
|
||||
const finalTop = top();
|
||||
vis.dataset.text = el.dataset.from ?? "";
|
||||
el.dataset.state = "pending";
|
||||
|
||||
// The old words break where the finished heading will, or the line reflows mid-gesture: a
|
||||
// longer revision that wraps gets its line break up front, and a shorter one that fits on the
|
||||
// line holds the old words there too, overhanging by a few letters for a second or two.
|
||||
const pendingTop = top();
|
||||
if (finalTop > pendingTop + 1) el.classList.add("refine--break");
|
||||
else if (pendingTop > finalTop + 1) heading.classList.add("refine-hold");
|
||||
|
||||
const watcher = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
if (!entry.isIntersecting) return;
|
||||
watcher.disconnect();
|
||||
setTimeout(() => play(el, heading), 250);
|
||||
},
|
||||
// All of it on screen, and clear of the bottom quarter, so it plays where it's being read
|
||||
{ threshold: 1, rootMargin: "0px 0px -25% 0px" },
|
||||
);
|
||||
watcher.observe(el);
|
||||
}
|
||||
|
||||
if (!calm.matches) {
|
||||
document.querySelectorAll<HTMLElement>("[data-refine]").forEach(arm);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/* Resting state: the finished words, set like the hero's refined one. */
|
||||
.refine {
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
font-style: italic;
|
||||
color: var(--luxe-accent);
|
||||
}
|
||||
|
||||
.refine__vis {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.refine--break::before {
|
||||
content: "\A";
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
:global(.refine-hold) {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* === Animated === */
|
||||
|
||||
.refine.is-live .refine__text {
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
clip-path: inset(50%);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.refine.is-live .refine__vis {
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
/* Room for the highlight to sit in, taken back from the margin so the line does not re-wrap. */
|
||||
padding-inline: 0.08em;
|
||||
margin-inline: -0.08em;
|
||||
user-select: none;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.refine.is-live .refine__vis::before {
|
||||
content: attr(data-text);
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
/* The old words are set like the rest of the heading until they are replaced. */
|
||||
.refine.is-live:is([data-state="pending"], [data-state="caret"], [data-state="select"]) {
|
||||
font-style: normal;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* The selection: the same words again, in the site's `::selection` colors, clipped to however
|
||||
much has been dragged over so far. A background cannot invert the text it sits behind, and
|
||||
light text on the accent would be unreadable. */
|
||||
.refine.is-live .refine__vis::after {
|
||||
content: attr(data-sel);
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
padding-inline: inherit;
|
||||
white-space: pre;
|
||||
background: var(--luxe-accent);
|
||||
color: var(--luxe-background);
|
||||
clip-path: inset(0 0 0 var(--sel-left, 100%));
|
||||
}
|
||||
|
||||
.refine.is-live:not([data-state="select"]) .refine__vis::after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* A text cursor, not a block: this is an editor, and the hero's block caret belongs to the
|
||||
terminal it prints the logotype in. */
|
||||
.refine__caret {
|
||||
position: absolute;
|
||||
top: 0.12em;
|
||||
bottom: 0.08em;
|
||||
left: calc(100% - 0.06em);
|
||||
width: 0.06em;
|
||||
background: var(--luxe-accent);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.refine.is-live[data-state="select"] .refine__caret {
|
||||
left: var(--sel-left, 100%);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.refine.is-live[data-state="type"] .refine__caret {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.refine.is-live:is([data-state="caret"], [data-state="linger"]) .refine__caret {
|
||||
animation: refine-blink 900ms steps(1, end) infinite;
|
||||
}
|
||||
|
||||
@keyframes refine-blink {
|
||||
0%,
|
||||
49% {
|
||||
opacity: 1;
|
||||
}
|
||||
50%,
|
||||
100% {
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.refine__caret {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
101
web/src/components/Shot.astro
Normal file
101
web/src/components/Shot.astro
Normal file
@@ -0,0 +1,101 @@
|
||||
---
|
||||
/**
|
||||
* A terminal capture, in a plate.
|
||||
*
|
||||
* Luxe's own theme, generated from the production view path. SVG: crisp at any zoom, and the text
|
||||
* inside is real text.
|
||||
*
|
||||
* **The markup is inlined, and it has to be.** An SVG loaded through `<img src>` is a document of
|
||||
* its own in secure static mode: it cannot see the embedding page's `@font-face`, so the subset
|
||||
* webfont this site ships never reached a single screenshot. That is invisible to anyone who has
|
||||
* the face installed, which is anyone who works on Luxe. For everyone else the stack fell through
|
||||
* to a system mono advancing some other width than the one the exporter pins `textLength` to, so
|
||||
* every row was squeezed or stretched by the difference, and every Nerd Font icon in the picture
|
||||
* drew as tofu. `<img>` also makes the text unselectable, which is half the reason these are
|
||||
* vectors at all.
|
||||
*
|
||||
* Inline, the face the page already loads for its own body text applies here too, and several on
|
||||
* one page cross-compress inside the HTML rather than being fetched one at a time.
|
||||
*
|
||||
* The asset itself stays font-independent, so a capture pasted into a README still degrades to the
|
||||
* reader's own font — losing shine, not information, which is the standing rule for glyphs.
|
||||
*/
|
||||
interface Props {
|
||||
/** Fixture scenario name, e.g. `guided-review-wide`. */
|
||||
name: string;
|
||||
/** What the picture shows. Also the accessible name, so it has to say something. */
|
||||
caption: string;
|
||||
class?: string;
|
||||
}
|
||||
const { name, caption, class: className = "" } = Astro.props;
|
||||
|
||||
const shots = import.meta.glob<string>("../assets/generated/*.svg", {
|
||||
query: "?raw",
|
||||
import: "default",
|
||||
eager: true,
|
||||
});
|
||||
|
||||
const escapeXml = (value: string) =>
|
||||
value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
|
||||
/**
|
||||
* One capture's markup, with what an inline copy needs spliced into its root tag.
|
||||
*
|
||||
* `role="img"` and the name are the whole accessibility story here: without them a screen reader
|
||||
* walks the `<text>` rows and reads a terminal dump aloud, where the `<img>` this replaced had an
|
||||
* `alt` and was done. With them the capture is announced once, by its caption, and the rows inside
|
||||
* are skipped — while still being selectable by anyone who wants to copy a command out of it.
|
||||
*/
|
||||
const capture = (theme: string, variant: string) => {
|
||||
const key = `../assets/generated/${name}.${theme}.svg`;
|
||||
const svg = shots[key];
|
||||
if (!svg) throw new Error(`no capture for ${name}.${theme} — run scripts/site-assets.sh`);
|
||||
const root = svg.match(/^<svg\b[^>]*>/)?.[0];
|
||||
if (!root) throw new Error(`${key} has no <svg> root to annotate`);
|
||||
|
||||
const label = escapeXml(caption);
|
||||
return svg.replace(
|
||||
root,
|
||||
`${root.slice(0, -1)} class="shot__img shot__img--${variant}" role="img" ` +
|
||||
`aria-label="${label}"><title>${label}</title>`,
|
||||
);
|
||||
};
|
||||
---
|
||||
|
||||
<figure class:list={["shot", className]}>
|
||||
<div class="shot__plate plate">
|
||||
<div class="shot__frame">
|
||||
<Fragment set:html={capture("luxe", "dark")} />
|
||||
</div>
|
||||
</div>
|
||||
<figcaption class="shot__caption muted">{caption}</figcaption>
|
||||
</figure>
|
||||
|
||||
<style>
|
||||
.shot {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.shot__frame {
|
||||
padding: var(--space-3);
|
||||
}
|
||||
|
||||
/* `:global`, because the capture arrives as markup rather than as elements this component
|
||||
authored, so Astro's scope attribute is never on it. Anchored to `.shot__frame`, which is
|
||||
scoped, so the rule still cannot reach past this component.
|
||||
|
||||
`height: auto` resolves against the root's own `width`/`height`, which is where a capture's
|
||||
aspect ratio comes from — the export writes both, and a rewrite that dropped them would
|
||||
collapse every frame. */
|
||||
.shot__frame :global(.shot__img) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
|
||||
.shot__caption {
|
||||
font-size: var(--step--1);
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
</style>
|
||||
176
web/src/components/Still.astro
Normal file
176
web/src/components/Still.astro
Normal file
@@ -0,0 +1,176 @@
|
||||
---
|
||||
/**
|
||||
* A frame lifted out of a real recording.
|
||||
*
|
||||
* Some surfaces do not survive being watched. Guided Review puts a chapter's argument beside the
|
||||
* code it argues about, and a reader meeting that for the first time needs to stop on it — played
|
||||
* at demo speed it registers as motion rather than as information. So these come from the same
|
||||
* captures the demos do, cut with `scripts/cast-still.py`, and there is still one source of truth
|
||||
* for what Luxe looks like.
|
||||
*
|
||||
* A recording bakes its colors in, and the site is drawn in the same theme it was recorded in.
|
||||
*
|
||||
* The markup is inlined for the reason `Shot` documents: an SVG behind `<img src>` is its own
|
||||
* document, cannot see this page's `@font-face`, and would draw every Nerd Font icon as tofu for
|
||||
* everyone who does not already have the face installed.
|
||||
*/
|
||||
interface Props {
|
||||
/** Capture basename, e.g. `palette`. */
|
||||
name: string;
|
||||
/**
|
||||
* Where the picture comes from: a frame cut out of a recording (the default), or a fixture
|
||||
* `scripts/site-assets.sh` generates from the production view path.
|
||||
*
|
||||
* Either way it is Luxe's own theme, so a fixture and a recording beside it are one product.
|
||||
*/
|
||||
from?: "captures" | "generated";
|
||||
/**
|
||||
* A cropped cut of the same moment, for phones.
|
||||
*
|
||||
* The same arithmetic that governs the demos: a 150-column capture shrunk to a 340px column is
|
||||
* about two pixels a character, which is a picture of a screenshot rather than a screenshot. A
|
||||
* *crop* keeps the type readable by showing less — the guide pane without the diff beside it,
|
||||
* the comment box without the surface around it — which is the right trade on a phone, where
|
||||
* nobody was going to read three panes anyway.
|
||||
*/
|
||||
narrow?: string;
|
||||
/** What the picture shows. Also the accessible name, so it has to say something. */
|
||||
caption: string;
|
||||
/**
|
||||
* Cap on how wide the plate draws, in rem.
|
||||
*
|
||||
* A 150-column capture wants roughly 74rem to stay legible; a cropped detail wants far less and
|
||||
* looks like a mistake blown up to full width.
|
||||
*/
|
||||
width?: number;
|
||||
class?: string;
|
||||
}
|
||||
const { name, narrow, caption, from = "captures", width = 74, class: className = "" } = Astro.props;
|
||||
|
||||
const recorded = import.meta.glob<string>("../assets/captures/*.svg", {
|
||||
query: "?raw",
|
||||
import: "default",
|
||||
eager: true,
|
||||
});
|
||||
const generated = import.meta.glob<string>("../assets/generated/*.luxe.svg", {
|
||||
query: "?raw",
|
||||
import: "default",
|
||||
eager: true,
|
||||
});
|
||||
const source = (basename: string) => {
|
||||
const key =
|
||||
from === "generated"
|
||||
? `../assets/generated/${basename}.luxe.svg`
|
||||
: `../assets/captures/${basename}.svg`;
|
||||
return { key, svg: from === "generated" ? generated[key] : recorded[key] };
|
||||
};
|
||||
|
||||
const escapeXml = (value: string) =>
|
||||
value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
|
||||
|
||||
// `role="img"` and the label are the whole accessibility story: without them a screen reader walks
|
||||
// the `<text>` rows and reads a terminal dump aloud. With them it is announced once, by its
|
||||
// caption, while the text inside stays selectable for anyone who wants to copy a line out of it.
|
||||
//
|
||||
// Only one of the two cuts is ever exposed: the hidden one is `aria-hidden`, or a reader meets the
|
||||
// same picture twice.
|
||||
const label = escapeXml(caption);
|
||||
|
||||
/**
|
||||
* The wide cut's aspect, read out of its own viewBox.
|
||||
*
|
||||
* A still obeys the same rule a demo does — as large as fits, never wider than the page — and
|
||||
* fitting is a question about height. Without this a short laptop drew a 1184px still beside a
|
||||
* 993px demo in the same section, which is two answers to one question.
|
||||
*/
|
||||
const wideBox = (source(name).svg ?? "").match(/viewBox="0 0 ([\d.]+) ([\d.]+)"/);
|
||||
const aspect = wideBox ? Number(wideBox[1]) / Number(wideBox[2]) : 4;
|
||||
|
||||
const capture = (basename: string, variant: string) => {
|
||||
const { key, svg } = source(basename);
|
||||
if (!svg) {
|
||||
const how =
|
||||
from === "generated"
|
||||
? "add it to SHOTS in scripts/site-assets.sh"
|
||||
: "cut one with scripts/cast-still.py";
|
||||
throw new Error(`no still called ${basename} — ${how}`);
|
||||
}
|
||||
const root = svg.match(/^<svg\b[^>]*>/)?.[0];
|
||||
if (!root) throw new Error(`${key} has no <svg> root to annotate`);
|
||||
const described = variant === "wide" ? `role="img" aria-label="${label}"` : 'aria-hidden="true"';
|
||||
return svg.replace(
|
||||
root,
|
||||
`${root.slice(0, -1)} class="still__img still__img--${variant}" ${described}>` +
|
||||
(variant === "wide" ? `<title>${label}</title>` : ""),
|
||||
);
|
||||
};
|
||||
---
|
||||
|
||||
<figure
|
||||
class:list={["still", className]}
|
||||
style={`--still-width: ${width}rem; --still-aspect: ${aspect.toFixed(3)}`}
|
||||
>
|
||||
<div class="still__plate plate">
|
||||
<div class="still__frame">
|
||||
<Fragment set:html={capture(name, "wide")} />
|
||||
{narrow && <Fragment set:html={capture(narrow, "narrow")} />}
|
||||
</div>
|
||||
</div>
|
||||
<figcaption class="still__caption muted">{caption}</figcaption>
|
||||
</figure>
|
||||
|
||||
<style>
|
||||
/* As wide as asked for, as wide as the viewport's height allows, and never wider than whatever
|
||||
is holding it — the last of those being the one that matters now that a capture sits in a grid
|
||||
track rather than across the page. Without it a 74rem still overran its 64rem column and ate
|
||||
the gap between the picture and the text about it, with no page overflow to give it away. */
|
||||
.still {
|
||||
width: min(
|
||||
var(--still-width),
|
||||
calc((100svh - 8.75rem) * var(--still-aspect)),
|
||||
100%
|
||||
);
|
||||
margin-inline: auto;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* The terminal's own background, for the reason `Demo` documents at length: Luxe paints a
|
||||
background into most cells, so a plate in any other color turns the painted ones into
|
||||
rectangles. Generated from the dark theme, and it does not follow the page's mode because the
|
||||
capture does not either. */
|
||||
.still__frame {
|
||||
padding: var(--space-3);
|
||||
background: var(--luxe-capture-bg);
|
||||
}
|
||||
|
||||
/* `:global`, because the capture arrives as markup rather than as elements this component
|
||||
authored, so Astro's scope attribute is never on it. Anchored to the scoped `.still__frame`,
|
||||
so the rule still cannot reach past this component. */
|
||||
.still__frame :global(.still__img) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.still__frame :global(.still__img--narrow) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* The same breakpoint the demos switch cuts at, so a section does not swap one and keep the
|
||||
other. Only applied where a narrow cut was supplied — `:has` keeps the wide one visible when
|
||||
there is nothing to swap to. */
|
||||
@media (max-width: 719px) {
|
||||
.still__frame:has(.still__img--narrow) :global(.still__img--wide) {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.still__frame :global(.still__img--narrow) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
.still__caption {
|
||||
font-size: var(--step--1);
|
||||
margin-top: var(--space-3);
|
||||
}
|
||||
</style>
|
||||
61
web/src/components/StillSwitch.astro
Normal file
61
web/src/components/StillSwitch.astro
Normal file
@@ -0,0 +1,61 @@
|
||||
---
|
||||
/**
|
||||
* Two stills of one surface in two states, shown one at a time by a pair of buttons elsewhere.
|
||||
*
|
||||
* For a thing that looks different depending on the room it gets, like peek beside the
|
||||
* conversation on a wide terminal and in its place on a narrow one. The buttons are
|
||||
* [`SwitchButtons`], placed wherever the words about the pictures are: this names itself by `id`
|
||||
* and they find it. A carousel that turns on its own was the alternative, and a picture that
|
||||
* changes while you are reading it is a picture you cannot read.
|
||||
*
|
||||
* Both stills sit in one grid cell and the hidden one keeps its space, so the frame is the height
|
||||
* of the taller one whichever is showing and nothing below it moves on a switch. Without
|
||||
* JavaScript both simply show, one above the other, and the buttons stay hidden.
|
||||
*/
|
||||
interface Props {
|
||||
/** What the buttons point at. */
|
||||
id: string;
|
||||
}
|
||||
const { id } = Astro.props;
|
||||
---
|
||||
|
||||
<div class="switch" id={id} data-still-switch>
|
||||
<div class="switch__panel"><slot name="first" /></div>
|
||||
<div class="switch__panel"><slot name="second" /></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll<HTMLElement>("[data-still-switch]").forEach((root) => {
|
||||
const panels = [...root.querySelectorAll<HTMLElement>(":scope > .switch__panel")];
|
||||
const group = document.querySelector<HTMLElement>(`[data-switch-for="${root.id}"]`);
|
||||
if (!group) return;
|
||||
const buttons = [...group.querySelectorAll<HTMLButtonElement>("button")];
|
||||
const show = (at: number) => {
|
||||
buttons.forEach((button, index) => button.setAttribute("aria-pressed", String(index === at)));
|
||||
panels.forEach((panel, index) => panel.toggleAttribute("data-off", index !== at));
|
||||
};
|
||||
buttons.forEach((button, index) => button.addEventListener("click", () => show(index)));
|
||||
root.classList.add("switch--live");
|
||||
group.hidden = false;
|
||||
show(0);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.switch--live {
|
||||
display: grid;
|
||||
}
|
||||
|
||||
.switch--live > .switch__panel {
|
||||
grid-area: 1 / 1;
|
||||
}
|
||||
|
||||
/* Kept in the layout, so the cell stays the taller picture's height */
|
||||
.switch__panel[data-off] {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.switch:not(.switch--live) > .switch__panel + .switch__panel {
|
||||
margin-top: var(--space-5);
|
||||
}
|
||||
</style>
|
||||
73
web/src/components/SwitchButtons.astro
Normal file
73
web/src/components/SwitchButtons.astro
Normal file
@@ -0,0 +1,73 @@
|
||||
---
|
||||
/**
|
||||
* The buttons for a [`StillSwitch`], wherever the words about its pictures are.
|
||||
*
|
||||
* Hidden until the switch's script finds them, so a reader without JavaScript is not offered a
|
||||
* control that does nothing.
|
||||
*/
|
||||
interface Props {
|
||||
/** The `id` of the `StillSwitch` these drive. */
|
||||
for: string;
|
||||
/** What each state is called, in the order of the switch's `first` and `second` slots. */
|
||||
labels: [string, string];
|
||||
/** Names the pair for assistive technology. */
|
||||
label: string;
|
||||
}
|
||||
const { for: target, labels, label } = Astro.props;
|
||||
---
|
||||
|
||||
<div class="switch-buttons" role="group" aria-label={label} aria-controls={target} data-switch-for={target} hidden>
|
||||
{
|
||||
labels.map((name, index) => (
|
||||
<button type="button" aria-pressed={index === 0 ? "true" : "false"}>
|
||||
{name}
|
||||
</button>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.switch-buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
margin-top: var(--space-4);
|
||||
}
|
||||
|
||||
.switch-buttons[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* On the right-hand column the buttons line up with the text above them */
|
||||
:global(.duo--flip) .switch-buttons {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
font-size: var(--step--1);
|
||||
padding: 0.3em 0.8em;
|
||||
color: var(--luxe-muted);
|
||||
background: none;
|
||||
border: 1px solid var(--luxe-border-muted);
|
||||
cursor: pointer;
|
||||
transition:
|
||||
color 150ms var(--ease),
|
||||
border-color 150ms var(--ease);
|
||||
}
|
||||
|
||||
button:hover {
|
||||
color: var(--luxe-text);
|
||||
}
|
||||
|
||||
button[aria-pressed="true"] {
|
||||
color: var(--luxe-accent);
|
||||
border-color: var(--luxe-accent);
|
||||
}
|
||||
|
||||
@media (max-width: 68rem) {
|
||||
:global(.duo--flip) .switch-buttons {
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
283
web/src/components/ThemeGallery.svelte
Normal file
283
web/src/components/ThemeGallery.svelte
Normal file
@@ -0,0 +1,283 @@
|
||||
<script lang="ts">
|
||||
/**
|
||||
* Every built-in theme, previewed on the real UI, the way `/theme` previews them.
|
||||
*
|
||||
* A palette is not something you can judge from its name, which is why the terminal's picker
|
||||
* repaints the whole app as the cursor moves. The page does the same: pointing at a theme, or
|
||||
* tabbing onto it, repaints the dashboard in that palette at once, and clicking pins it so you can
|
||||
* move the mouse away and keep looking.
|
||||
*
|
||||
* The picture arrives as the slot, drawn once at build time by `fixture_svg --palette`: every
|
||||
* color in it is `var(--pN, …)`, and `palette` says what each `N` is in each theme. So this sets
|
||||
* a dozen custom properties on the frame and the browser repaints the rest. It used to be an HTML
|
||||
* mock of the app, which showed the colors and nothing of how Luxe actually uses them.
|
||||
*
|
||||
* With `cycle`, the gallery takes turns on its own every few seconds, so a reader who never
|
||||
* touches it still sees what the themes are. Pointing at a chip holds that theme, pointing at the
|
||||
* picture holds whichever is up so it can be read, and a click pins one and ends the turns. It
|
||||
* turns only while it is on screen, and never for a reader who asked for reduced motion.
|
||||
*/
|
||||
import { onMount, type Snippet } from "svelte";
|
||||
|
||||
interface Props {
|
||||
/** Resolved tokens per theme, generated from `luxe-core`'s theme files. */
|
||||
themes: Record<string, Record<string, string>>;
|
||||
/** What each of the preview's variables is, per theme (`theme-preview.json`). */
|
||||
palette: Record<string, Record<string, string>>;
|
||||
/** The variable the preview paints its canvas with, so the frame around it matches. */
|
||||
canvas: string;
|
||||
/** List every token with its value under the preview. */
|
||||
swatches?: boolean;
|
||||
/** Take turns through the themes on a timer. */
|
||||
cycle?: boolean;
|
||||
/** Put the theme chips under the picture rather than over it. */
|
||||
chipsBelow?: boolean;
|
||||
/** The preview itself. */
|
||||
children?: Snippet;
|
||||
}
|
||||
const {
|
||||
themes,
|
||||
palette,
|
||||
canvas,
|
||||
swatches = false,
|
||||
cycle = false,
|
||||
chipsBelow = false,
|
||||
children,
|
||||
}: Props = $props();
|
||||
|
||||
/** How long each theme stays up before the next takes its turn. */
|
||||
const TURN_MS = 3500;
|
||||
/** How long a theme someone pointed at stays up after the pointer leaves it. */
|
||||
const LINGER_MS = 1200;
|
||||
|
||||
// `$derived`, like every other read of the props below: a plain `const` would take the key list
|
||||
// once and keep serving it after the prop changed.
|
||||
const names = $derived(Object.keys(themes).filter((name) => name in palette));
|
||||
let pinned = $state("luxe");
|
||||
let pointed = $state<string | null>(null);
|
||||
// Held while the pointer is over the picture, and for good once a chip has been clicked
|
||||
let reading = $state(false);
|
||||
let chosen = $state(false);
|
||||
let gallery: HTMLDivElement;
|
||||
|
||||
// Leaving a chip keeps its theme up a moment: a preview that snapped back the instant the pointer
|
||||
// left took the picture away while it was still being looked at. Pointing at another chip cancels
|
||||
// the wait, and the rotation holds while it runs, since `pointed` is still set.
|
||||
let lingering: ReturnType<typeof setTimeout> | undefined;
|
||||
const point = (name: string) => {
|
||||
clearTimeout(lingering);
|
||||
pointed = name;
|
||||
};
|
||||
const release = () => {
|
||||
clearTimeout(lingering);
|
||||
lingering = setTimeout(() => (pointed = null), LINGER_MS);
|
||||
};
|
||||
|
||||
onMount(() => {
|
||||
if (!cycle || matchMedia("(prefers-reduced-motion: reduce)").matches) return;
|
||||
let visible = false;
|
||||
const watcher = new IntersectionObserver(([entry]) => (visible = entry.isIntersecting), {
|
||||
threshold: 0.4,
|
||||
});
|
||||
watcher.observe(gallery);
|
||||
const timer = setInterval(() => {
|
||||
if (!visible || document.hidden || pointed || reading || chosen) return;
|
||||
const at = names.indexOf(pinned);
|
||||
pinned = names[(at + 1) % names.length];
|
||||
}, TURN_MS);
|
||||
return () => {
|
||||
clearInterval(timer);
|
||||
clearTimeout(lingering);
|
||||
watcher.disconnect();
|
||||
};
|
||||
});
|
||||
|
||||
const showing = $derived(pointed ?? pinned);
|
||||
const tokens = $derived(themes[showing] ?? {});
|
||||
|
||||
/** The preview's palette, as inline custom properties on its frame. */
|
||||
const style = $derived(
|
||||
Object.entries(palette[showing] ?? {})
|
||||
.map(([name, hex]) => `--${name}: ${hex}`)
|
||||
.concat(`--preview-canvas: var(--${canvas})`)
|
||||
.join("; "),
|
||||
);
|
||||
</script>
|
||||
|
||||
<!-- Defined once and placed above or below the picture, in document order, so tabbing through the
|
||||
chips follows what the eye sees rather than a CSS reordering of it. -->
|
||||
{#snippet chips()}
|
||||
<div class="gallery__chips" role="group" aria-label="Preview a theme">
|
||||
{#each names as name (name)}
|
||||
<button
|
||||
type="button"
|
||||
class="chip"
|
||||
class:chip--showing={showing === name}
|
||||
aria-pressed={pinned === name}
|
||||
style={`--chip-bg: ${themes[name].background}; --chip-ink: ${themes[name].accent}`}
|
||||
onmouseenter={() => point(name)}
|
||||
onmouseleave={release}
|
||||
onfocus={() => point(name)}
|
||||
onblur={release}
|
||||
onclick={() => {
|
||||
// Pin *and* point: the pointer is still resting on this chip, and `pointed` outranks
|
||||
// `pinned`, so setting only the pin would leave a click that visibly did nothing.
|
||||
pinned = name;
|
||||
point(name);
|
||||
chosen = true;
|
||||
}}
|
||||
>
|
||||
<span class="chip__dot" aria-hidden="true"></span>
|
||||
{name}
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
<div class="gallery" bind:this={gallery}>
|
||||
{#if !chipsBelow}
|
||||
{@render chips()}
|
||||
{/if}
|
||||
|
||||
<!-- `aria-live` would announce every hover; the label names the theme on screen instead. -->
|
||||
<figure
|
||||
class="preview plate"
|
||||
onmouseenter={() => (reading = true)}
|
||||
onmouseleave={() => (reading = false)}
|
||||
>
|
||||
<div class="preview__frame" {style} role="img" aria-label="The Luxe dashboard in {showing}">
|
||||
{@render children?.()}
|
||||
</div>
|
||||
</figure>
|
||||
|
||||
{#if chipsBelow}
|
||||
{@render chips()}
|
||||
{/if}
|
||||
|
||||
{#if swatches}
|
||||
<dl class="swatches">
|
||||
{#each Object.entries(tokens) as [name, hex] (name)}
|
||||
<div class="swatch">
|
||||
<span class="swatch__chip" style={`background: ${hex}`}></span>
|
||||
<dt>{name}</dt>
|
||||
<dd>{hex}</dd>
|
||||
</div>
|
||||
{/each}
|
||||
</dl>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.gallery {
|
||||
display: grid;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
|
||||
.gallery__chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.chip {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5em;
|
||||
padding: 0.35em 0.8em;
|
||||
font: inherit;
|
||||
font-size: var(--step--1);
|
||||
color: var(--luxe-text);
|
||||
background: var(--luxe-user-msg-bg);
|
||||
border: 1px solid var(--luxe-border);
|
||||
border-radius: 999px;
|
||||
cursor: pointer;
|
||||
transition:
|
||||
border-color 120ms ease,
|
||||
transform 120ms ease;
|
||||
}
|
||||
|
||||
.chip:hover,
|
||||
.chip:focus-visible {
|
||||
border-color: var(--luxe-accent);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
/* Whichever theme is on screen, so a pointed-at chip is the only one lit rather than one of two */
|
||||
.chip--showing {
|
||||
border-color: var(--luxe-accent);
|
||||
color: var(--luxe-accent);
|
||||
}
|
||||
|
||||
/* The chip wears the theme it names: its own background, its own accent. */
|
||||
.chip__dot {
|
||||
width: 0.85em;
|
||||
height: 0.85em;
|
||||
border-radius: 50%;
|
||||
background: var(--chip-bg);
|
||||
box-shadow: inset 0 0 0 2px var(--chip-ink);
|
||||
}
|
||||
|
||||
.preview {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.preview__frame {
|
||||
padding: var(--space-3);
|
||||
background: var(--preview-canvas);
|
||||
transition: background-color 180ms ease;
|
||||
}
|
||||
|
||||
/* `:global`, because the picture arrives as markup this component did not author. Easing the
|
||||
fills stops the page flickering as the pointer crosses the row of chips. */
|
||||
.preview__frame :global(svg) {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.preview__frame :global(svg *) {
|
||||
transition:
|
||||
fill 180ms ease,
|
||||
stroke 180ms ease;
|
||||
}
|
||||
|
||||
.swatches {
|
||||
display: grid;
|
||||
padding-bottom: var(--space-2);
|
||||
grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
|
||||
gap: var(--space-1) var(--space-3);
|
||||
margin: 0;
|
||||
font-size: var(--step--2);
|
||||
}
|
||||
|
||||
.swatch {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6em;
|
||||
}
|
||||
|
||||
.swatch__chip {
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
border: 1px solid var(--luxe-border);
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.swatch dt {
|
||||
color: var(--luxe-text);
|
||||
}
|
||||
|
||||
.swatch dd {
|
||||
margin: 0;
|
||||
color: var(--luxe-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.chip,
|
||||
.preview__frame,
|
||||
.preview__frame :global(svg *) {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
39
web/src/components/ThemePreview.astro
Normal file
39
web/src/components/ThemePreview.astro
Normal file
@@ -0,0 +1,39 @@
|
||||
---
|
||||
/**
|
||||
* The theme gallery with its picture: the dashboard, drawn once for every theme.
|
||||
*
|
||||
* `scripts/site-assets.sh` writes the two halves, `theme-preview.svg` (every color a CSS variable)
|
||||
* and `theme-preview.json` (what each variable is per theme). The picture goes in as the gallery's
|
||||
* slot so it is in the HTML once, rather than serialized a second time into the island's props.
|
||||
*/
|
||||
import ThemeGallery from "./ThemeGallery.svelte";
|
||||
import svg from "../assets/generated/theme-preview.svg?raw";
|
||||
import palette from "../assets/generated/theme-preview.json";
|
||||
import catalog from "../assets/generated/themes.json";
|
||||
|
||||
interface Props {
|
||||
/** List every token of the theme on show, for the page that is about the palettes. */
|
||||
swatches?: boolean;
|
||||
/** Take turns through the themes on their own. */
|
||||
cycle?: boolean;
|
||||
/** Put the theme chips under the picture, where they read better on a narrow screen. */
|
||||
chipsBelow?: boolean;
|
||||
}
|
||||
const { swatches = false, cycle = false, chipsBelow = false } = Astro.props;
|
||||
|
||||
// The frame around the picture wears the picture's own canvas, which is its first rectangle
|
||||
const canvas = svg.match(/^<svg[^>]*>\s*<rect [^>]*fill="var\(--(p\d+),/)?.[1];
|
||||
if (!canvas) throw new Error("theme-preview.svg has no canvas variable — run scripts/site-assets.sh");
|
||||
---
|
||||
|
||||
<ThemeGallery
|
||||
client:visible
|
||||
themes={catalog as Record<string, Record<string, string>>}
|
||||
{palette}
|
||||
{canvas}
|
||||
{swatches}
|
||||
{cycle}
|
||||
{chipsBelow}
|
||||
>
|
||||
<Fragment set:html={svg} />
|
||||
</ThemeGallery>
|
||||
240
web/src/components/Wordmark.astro
Normal file
240
web/src/components/Wordmark.astro
Normal file
@@ -0,0 +1,240 @@
|
||||
---
|
||||
/**
|
||||
* The logotype, and the light that crosses it.
|
||||
*
|
||||
* The paths are read at build time out of the generated `wordmark.svg`, which is itself derived from
|
||||
* the art constants the TUI draws — so there is one drawing, not a web copy of one.
|
||||
*
|
||||
* Two motions, both the terminal's, to the millisecond.
|
||||
*
|
||||
* The **drift** is the brushed-metal one: each letter swings between the accent and the accent cut
|
||||
* back toward the canvas, a half-period apart across the mark, so one slow wave runs `l` to `.` and
|
||||
* never folds back. 7 s, because it is a reflection moving rather than an indicator — fast enough
|
||||
* to read as motion if you look, slow enough that you never catch it starting.
|
||||
*
|
||||
* The **shine** is the punctuation: a band leaning `/` crosses in 1.6 s, then the mark rests for 5 s.
|
||||
* It is drawn in the terminal's own grid rather than in the SVG's — see `band` below — because the
|
||||
* lean is one cell per row, and a cell is twice as tall as it is wide.
|
||||
*
|
||||
* Same numbers as `DRIFT_TICKS`/`DRIFT_DEPTH`/`SWEEP_TICKS`/`REST_TICKS`/`LEAN`/`BAND`, because a
|
||||
* signature that moves differently in two places is two signatures. The colors and the shine's
|
||||
* strength come from the generated tokens rather than percentages restated here, for the same
|
||||
* reason.
|
||||
*/
|
||||
import wordmark from "../assets/generated/wordmark.svg?raw";
|
||||
|
||||
interface Props {
|
||||
/** Play the shine. Off for a mark that is decoration rather than the page's subject. */
|
||||
shine?: boolean;
|
||||
/** Play the drift. Off only where the mark must hold still — the social card is a screenshot. */
|
||||
drift?: boolean;
|
||||
class?: string;
|
||||
}
|
||||
const { shine = false, drift = true, class: className = "" } = Astro.props;
|
||||
|
||||
// The four letter paths, in order. Everything else about the file is regenerated shape.
|
||||
const paths = [...wordmark.matchAll(/<path[^>]*d="([^"]+)"/g)].map((m) => m[1]);
|
||||
const viewBox = wordmark.match(/viewBox="([^"]+)"/)?.[1] ?? "0 0 540 176";
|
||||
const [, , width, height] = viewBox.split(/\s+/).map(Number);
|
||||
|
||||
// The grid the art is drawn on, carried by the generated file. Everything about the shine is stated
|
||||
// in cells, exactly as the terminal states it, and one `scale()` puts it back into the SVG's box.
|
||||
const [cellW, cellH] = (wordmark.match(/data-cell="([^"]+)"/)?.[1] ?? "10 22")
|
||||
.split(/\s+/)
|
||||
.map(Number);
|
||||
const columns = width / cellW;
|
||||
const rows = height / cellH;
|
||||
|
||||
/**
|
||||
* The highlight, in cells — the terminal's `LEAN`, `BAND` and `Pass`, not a reading of them.
|
||||
*
|
||||
* The band's iso-lines are `column + LEAN * row = k`, so the gradient runs along the *normal* to
|
||||
* those lines, `(1, LEAN)`. Stating that in the SVG's box means an angle, and an angle derived by
|
||||
* eye comes out mirrored: the gradient vector is perpendicular to the stripe you are trying to
|
||||
* draw, so `/` and `\` look like the same arithmetic until you see it move.
|
||||
*/
|
||||
const LEAN = 1;
|
||||
const BAND = 0.3;
|
||||
const span = columns - 1 + LEAN * (rows - 1);
|
||||
const half = Math.max(span * BAND, 1);
|
||||
const travel = span + 2 * half;
|
||||
// The gradient's own reach along `(1, LEAN)`: far enough that `axis` falls by `2 * half` over it.
|
||||
const reach = (2 * half) / (1 + LEAN * LEAN);
|
||||
// The band is nonzero only where `axis` is inside that span, which bounds the rect exactly.
|
||||
const bandWidth = 2 * half + LEAN * rows;
|
||||
// Where the band waits between passes: a cell clear of the mark rather than touching it. Flush
|
||||
// with the first letter, a mark moving by fractional pixels could antialias a hairline of the band
|
||||
// down its left edge. The sweep travels the extra cell, so the pass itself is unchanged.
|
||||
const PARK = 1;
|
||||
|
||||
// Smooth 0→1 with zero slope at both ends — the terminal's `smoothstep`, sampled rather than
|
||||
// approximated with an easing curve. A linear ramp is what the shine had, and it creases along the
|
||||
// ridge and stops dead at each shoulder: a stripe laid over the letters instead of light crossing
|
||||
// them. Seventeen stops put the error below a level part in a thousand.
|
||||
const smoothstep = (t: number) => t * t * (3 - 2 * t);
|
||||
const stops = Array.from({ length: 17 }, (_, i) => i / 16).map((offset) => ({
|
||||
offset,
|
||||
opacity: smoothstep(1 - Math.abs(2 * offset - 1)),
|
||||
}));
|
||||
|
||||
// Unique per instance: two wordmarks on a page must not share a mask id.
|
||||
const uid = `lx-${Math.random().toString(36).slice(2, 8)}`;
|
||||
|
||||
// Where each letter sits in the drift, as a fraction of the loop. Half a period is spread across
|
||||
// the mark (the terminal's `DRIFT_SPREAD`), and the offsets are negative so every letter is already
|
||||
// mid-swing on the first frame — otherwise the whole mark starts lit together and pulses once,
|
||||
// which is a logo blinking at you rather than metal catching the light.
|
||||
const phase = (i: number) => (-1 + (i / Math.max(paths.length - 1, 1)) * 0.5).toFixed(4);
|
||||
---
|
||||
|
||||
<svg
|
||||
class:list={["wordmark", className, { "wordmark--drift": drift }]}
|
||||
viewBox={viewBox}
|
||||
role="img"
|
||||
aria-label="Luxe"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
>
|
||||
<title>Luxe</title>
|
||||
{
|
||||
shine && (
|
||||
<defs>
|
||||
<mask id={`${uid}-mask`} maskUnits="userSpaceOnUse" x="0" y="0" width={width} height={height}>
|
||||
{paths.map((d) => <path d={d} fill="#fff" />)}
|
||||
</mask>
|
||||
{/* In cells, along the normal to the band's iso-lines: offset 0 sits at `axis = -2 * half`
|
||||
and offset 1 at `axis = 0`, so the ridge lands halfway and the profile either side of it
|
||||
is the terminal's own falloff. */}
|
||||
<linearGradient
|
||||
id={`${uid}-band`}
|
||||
gradientUnits="userSpaceOnUse"
|
||||
x1={-reach}
|
||||
y1={-reach * LEAN}
|
||||
x2="0"
|
||||
y2="0"
|
||||
>
|
||||
{stops.map(({ offset, opacity }) => (
|
||||
<stop
|
||||
offset={offset.toFixed(4)}
|
||||
stop-color="#fff"
|
||||
stop-opacity={opacity.toFixed(4)}
|
||||
/>
|
||||
))}
|
||||
</linearGradient>
|
||||
</defs>
|
||||
)
|
||||
}
|
||||
<g class="wordmark__ink">
|
||||
{
|
||||
paths.map((d, i) => (
|
||||
<path d={d} fill={`var(--luxe-wordmark-${i + 1})`} style={`--drift-phase: ${phase(i)}`} />
|
||||
))
|
||||
}
|
||||
</g>
|
||||
{
|
||||
shine && (
|
||||
/* The mask belongs on the wrapper, never on the band. An element's own transform redefines the
|
||||
user space its `userSpaceOnUse` mask resolves in, so a masked rect drags the letters along
|
||||
with it and the two never meet — a shine that is present in the DOM, throws nothing, and
|
||||
paints nothing on any page. `site-smoke.mjs` checks the pixels rather than the markup. */
|
||||
<g mask={`url(#${uid}-mask)`} class="wordmark__shine">
|
||||
{/* One scale, and everything inside is cells: the rect, the gradient, and the sweep's own
|
||||
travel. The scale is anisotropic, which is the point — it shears the band by exactly the
|
||||
cell's 1:2.2, so the stripe lands at the angle the terminal draws and not near it. */}
|
||||
<g transform={`scale(${cellW} ${cellH})`}>
|
||||
<rect
|
||||
class="wordmark__band"
|
||||
x={-bandWidth - PARK}
|
||||
y="0"
|
||||
width={bandWidth}
|
||||
height={rows}
|
||||
fill={`url(#${uid}-band)`}
|
||||
/>
|
||||
</g>
|
||||
</g>
|
||||
)
|
||||
}
|
||||
</svg>
|
||||
|
||||
<style define:vars={{ sweepWidth: `${travel + PARK}px` }}>
|
||||
.wordmark {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* 212 ticks of the terminal's 33 ms animation clock. Deliberately not a divisor of the sweep's
|
||||
6.6 s: the two lights would land in step every pass and read as one loop repeating. */
|
||||
.wordmark--drift .wordmark__ink path {
|
||||
animation: wordmark-drift 6.996s linear infinite;
|
||||
animation-delay: calc(var(--drift-phase, 0) * 6.996s);
|
||||
}
|
||||
|
||||
/* The terminal's `DEPTH * (1 - cos(turn)) / 2`, sampled every eighth of a turn. Written out
|
||||
rather than approximated with an easing curve: a raised cosine is what makes the swing read as
|
||||
one light moving over metal instead of a group of letters taking turns fading. */
|
||||
@keyframes wordmark-drift {
|
||||
0%,
|
||||
100% {
|
||||
fill: var(--luxe-wordmark-lit);
|
||||
}
|
||||
12.5%,
|
||||
87.5% {
|
||||
fill: color-mix(in oklab, var(--luxe-wordmark-dim) 15%, var(--luxe-wordmark-lit));
|
||||
}
|
||||
25%,
|
||||
75% {
|
||||
fill: color-mix(in oklab, var(--luxe-wordmark-dim) 50%, var(--luxe-wordmark-lit));
|
||||
}
|
||||
37.5%,
|
||||
62.5% {
|
||||
fill: color-mix(in oklab, var(--luxe-wordmark-dim) 85%, var(--luxe-wordmark-lit));
|
||||
}
|
||||
50% {
|
||||
fill: var(--luxe-wordmark-dim);
|
||||
}
|
||||
}
|
||||
|
||||
/* How far the shine may push, which the terminal decides per theme: a light theme's letters are
|
||||
saturated mid-tones on near-white and wash out long before a dark theme's do. The stops carry
|
||||
the shape, this carries the strength. */
|
||||
.wordmark__shine {
|
||||
opacity: var(--luxe-wordmark-shine, 0.62);
|
||||
}
|
||||
|
||||
/* 1.6 s of travel in a 6.6 s cycle is 24.2% — the rest of the loop is the rest between passes.
|
||||
Holding the band off-canvas for three quarters of the cycle is the whole point: a shine that
|
||||
repeats promptly stops reading as light and starts reading as a strobe. The travel is in cells,
|
||||
because the band is drawn inside the scale that puts the grid back into the SVG's box. */
|
||||
/* `--shine-delay` holds the first pass off, for a caller that has an opening of its own.
|
||||
The front page types the logotype in before anything else happens, and a shine crossing letters
|
||||
that have not been drawn yet is light with nothing to fall on. Only the first pass is delayed:
|
||||
the cycle carries on every 6.6s after it. */
|
||||
.wordmark__band {
|
||||
animation: wordmark-sweep 6.6s linear var(--shine-delay, 0s) infinite;
|
||||
will-change: transform;
|
||||
}
|
||||
|
||||
@keyframes wordmark-sweep {
|
||||
0% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
24.2% {
|
||||
transform: translateX(var(--sweepWidth));
|
||||
}
|
||||
100% {
|
||||
transform: translateX(var(--sweepWidth));
|
||||
}
|
||||
}
|
||||
|
||||
/* A logo that flashes is exactly what a vestibular trigger looks like. Both motions stop; the
|
||||
paths keep the still fills, which are the frame the terminal freezes at `STILL_TICK`. */
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.wordmark__band {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.wordmark--drift .wordmark__ink path {
|
||||
animation: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user