a200832cfb
docs/LETTER.md holds slots as comments only, so the player sees no change
until the author writes. The app bundles the letter at build time, a small
Markdown subset renders without {@html}, only https: and tel: become links,
and lint:copy now reads the letter. Review found turbo replaying a stale
build after the letter changed; docs/LETTER.md is now in its cache key.
91 lines
2.2 KiB
Svelte
91 lines
2.2 KiB
Svelte
<script lang="ts">
|
|
import { PRODUCT_NAME } from '@rosea/schema';
|
|
import { en } from './copy/en.js';
|
|
import Letter from './letter/Letter.svelte';
|
|
import { parseLetter } from './letter/parse.js';
|
|
|
|
/** The author's Markdown from docs/LETTER.md. Empty means there is no way to the page. */
|
|
let { letter = '' }: { letter?: string } = $props();
|
|
|
|
const LETTER_HASH = '#letter';
|
|
// Any hash but the letter's is the garden. A bare '#' is not a valid link target.
|
|
const GARDEN_HASH = '#garden';
|
|
|
|
const blocks = $derived(parseLetter(letter));
|
|
let hash = $state(location.hash);
|
|
const view = $derived(hash === LETTER_HASH && blocks.length > 0 ? 'letter' : 'home');
|
|
|
|
let heading = $state<HTMLHeadingElement>();
|
|
// Focus follows the view only after the player moved, never on the first load.
|
|
let moved = false;
|
|
|
|
$effect(() => {
|
|
const onChange = (): void => {
|
|
moved = true;
|
|
hash = location.hash;
|
|
};
|
|
window.addEventListener('hashchange', onChange);
|
|
return () => window.removeEventListener('hashchange', onChange);
|
|
});
|
|
|
|
$effect(() => {
|
|
// Read `heading` first: an effect tracks only what it reads, and `moved` is not state.
|
|
const target = heading;
|
|
if (moved) target?.focus();
|
|
});
|
|
</script>
|
|
|
|
{#if view === 'letter'}
|
|
<main class="shell page">
|
|
<h1 bind:this={heading} tabindex="-1">{en.letter.title}</h1>
|
|
<Letter {blocks} />
|
|
<a href={GARDEN_HASH}>{en.letter.back}</a>
|
|
</main>
|
|
{:else}
|
|
<main class="shell">
|
|
<h1 bind:this={heading} tabindex="-1">{PRODUCT_NAME}</h1>
|
|
<p>{en.shell.preparing}</p>
|
|
{#if blocks.length > 0}
|
|
<a href={LETTER_HASH}>{en.letter.title}</a>
|
|
{/if}
|
|
</main>
|
|
{/if}
|
|
|
|
<style>
|
|
.shell {
|
|
min-height: 100dvh;
|
|
display: grid;
|
|
place-content: center;
|
|
gap: var(--space-2);
|
|
padding: var(--space-4);
|
|
text-align: center;
|
|
}
|
|
|
|
.page {
|
|
place-content: start center;
|
|
text-align: start;
|
|
}
|
|
|
|
h1 {
|
|
margin: 0;
|
|
font-family: var(--font-display);
|
|
font-weight: 400;
|
|
font-size: clamp(2rem, 8vw, 3.5rem);
|
|
letter-spacing: 0.02em;
|
|
color: var(--rose);
|
|
}
|
|
|
|
h1:focus {
|
|
outline: none;
|
|
}
|
|
|
|
p {
|
|
margin: 0;
|
|
color: var(--ink-soft);
|
|
}
|
|
|
|
a {
|
|
color: var(--rose);
|
|
}
|
|
</style>
|