108 lines
3.1 KiB
Svelte
108 lines
3.1 KiB
Svelte
<script lang="ts">
|
|
import { Button } from '@domi/ui';
|
|
import type { PetalNow } from '@rosea/engine';
|
|
import type { HopeSentence } from '@rosea/schema';
|
|
import { tick } from 'svelte';
|
|
import { en } from '../copy/en.js';
|
|
// The art board's stand-in until real art is accepted (docs/ART.md).
|
|
import folded from '../../../../art/placeholders/petal-folded.svg?url';
|
|
|
|
/**
|
|
* The rose's folded petal (day-sentence.md). The engine decides which sentence and
|
|
* whether it is open; this shows it and hands the player's tap back.
|
|
*/
|
|
let { petal, sentences, onopen }: { petal: PetalNow; sentences: readonly HopeSentence[]; onopen: () => void } = $props();
|
|
|
|
const uid = $props.id();
|
|
/** Today's open petal is shown; the player can fold it away and back for the rest of the day. */
|
|
let showing = $state(true);
|
|
let words = $state<HTMLElement>();
|
|
|
|
const find = (id: string | null): HopeSentence | undefined => (id === null ? undefined : sentences.find((s) => s.id === id));
|
|
const today = $derived(petal.kind === 'open' ? find(petal.id) : undefined);
|
|
const remembered = $derived(petal.kind === 'open' ? find(petal.remembered) : undefined);
|
|
const source = (s: HopeSentence): string => en.rose.petal.source(s.source.work, s.source.author, s.source.translation);
|
|
|
|
async function open(): Promise<void> {
|
|
onopen();
|
|
showing = true;
|
|
// The player acted, so focus follows them to the words.
|
|
await tick();
|
|
words?.focus();
|
|
}
|
|
</script>
|
|
|
|
{#if petal.kind === 'folded'}
|
|
<div class="petal">
|
|
<img src={folded} alt={en.rose.petal.folded} width="56" height="56" />
|
|
<Button onclick={() => void open()}>{en.rose.petal.open}</Button>
|
|
</div>
|
|
{:else if petal.kind === 'open' && today}
|
|
<div class="petal">
|
|
<Button variant="quiet" aria-expanded={showing} aria-controls="{uid}-words" onclick={() => (showing = !showing)}>{en.rose.petal.today}</Button>
|
|
{#if showing}
|
|
<div id="{uid}-words" class="words" tabindex="-1" bind:this={words}>
|
|
<figure>
|
|
<blockquote>{today.text.en}</blockquote>
|
|
<figcaption>{source(today)}</figcaption>
|
|
</figure>
|
|
{#if remembered}
|
|
<p class="remember">{en.rose.petal.remember}</p>
|
|
<figure>
|
|
<blockquote>{remembered.text.en}</blockquote>
|
|
<figcaption>{source(remembered)}</figcaption>
|
|
</figure>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
{/if}
|
|
|
|
<style>
|
|
.petal {
|
|
display: grid;
|
|
justify-items: center;
|
|
gap: var(--space-2);
|
|
}
|
|
|
|
img {
|
|
width: 3.5rem;
|
|
height: auto;
|
|
}
|
|
|
|
.words {
|
|
display: grid;
|
|
gap: var(--space-3);
|
|
max-width: 24rem;
|
|
padding: var(--space-3);
|
|
border-radius: 1.25rem;
|
|
background: color-mix(in srgb, var(--rose) 10%, var(--paper));
|
|
}
|
|
|
|
.words:focus {
|
|
outline: none;
|
|
}
|
|
|
|
figure {
|
|
margin: 0;
|
|
display: grid;
|
|
gap: var(--space-1);
|
|
}
|
|
|
|
blockquote {
|
|
margin: 0;
|
|
font-family: var(--font-display);
|
|
font-size: 1.15rem;
|
|
line-height: 1.45;
|
|
color: var(--ink);
|
|
}
|
|
|
|
figcaption,
|
|
.remember {
|
|
margin: 0;
|
|
font-size: 0.85rem;
|
|
color: var(--ink-soft);
|
|
}
|
|
|
|
</style>
|