Tarot example: the draw played as an animation, and a love reading
CI / test (push) Successful in 1m32s
CI / build (push) Successful in 5m11s
CI / deploy (push) Skipped

The example page now plays each reading: cards are picked from the
fanned deck, laid out and turned over, then the written reading
appears below. A second example, a five-card love reading, sits next
to the work one in a tab. The fan and the spread are shared with the
real draw (TarotSpread).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-20 15:51:23 +00:00
co-authored by Claude Opus 5.5
parent b0fc547b73
commit 2e2e4b113d
7 changed files with 339 additions and 102 deletions
@@ -0,0 +1,102 @@
"use client";
import { useEffect, useState } from "react";
import type { TarotContent, TarotReading } from "@/lib/tarot";
import { TarotResult } from "./TarotResult";
import { TarotFan, TarotSlots } from "./TarotSpread";
export interface TarotExample {
id: string;
label: string;
signs: string;
spread_name: string;
question: string;
cards: TarotReading["cards"];
content: TarotContent;
}
/** The fan cards the demo "picks", in order. */
const PICKS = [4, 13, 8, 17, 2];
/**
* Plays a reading: the cards are picked from the fanned deck one by one,
* laid out, turned over, then the written reading appears below. The text is
* on the page from the start (hidden while the animation plays).
*/
function Demo({ example }: { example: TarotExample }) {
const n = example.cards.length;
const done = 3 * n + 2;
const [step, setStep] = useState(0);
// Without motion the end state shows at once.
useEffect(() => {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) setStep(done);
}, [done]);
useEffect(() => {
if (step >= done) return;
const picking = step <= 2 * n;
const delay = step === 0 ? 900 : picking ? (step % 2 === 1 ? 420 : 520) : 680;
const t = setTimeout(() => setStep((s) => s + 1), delay);
return () => clearTimeout(t);
}, [step, done, n]);
const pickedCount = Math.min(n, Math.floor(step / 2));
const lifted = step % 2 === 1 && step < 2 * n ? PICKS[(step - 1) / 2] : null;
const revealed = Math.max(0, Math.min(n, step - (2 * n + 1)));
const finished = step >= done;
return (
<div className="tarot-demo">
<div className="tarot-stage-head">
<span className="eyebrow">{example.spread_name}</span>
<p className="tarot-question">„{example.question}”</p>
<p className="hint">A kérdés és a képlet kitalált ({example.signs}).</p>
</div>
<TarotSlots count={n} filled={pickedCount} cards={example.cards} revealed={revealed} />
{!finished && <TarotFan picked={PICKS.slice(0, pickedCount)} lifted={lifted} />}
<p className="hint tarot-demo-status" aria-live="polite">
{finished ? (
<button type="button" className="btn btn-sm btn-ghost" onClick={() => setStep(0)}>
↻ Húzás újra
</button>
) : pickedCount < n ? (
`Lapválasztás a pakliból: ${pickedCount}/${n}`
) : (
"A lapok felfordulnak…"
)}
</p>
<div className={finished ? "tarot-demo-text is-shown" : "tarot-demo-text"}>
<TarotResult cards={example.cards} question={null} content={example.content} />
</div>
</div>
);
}
/** The example readings, one tab each. */
export function TarotDemo({ examples }: { examples: TarotExample[] }) {
const [active, setActive] = useState(examples[0]?.id);
const example = examples.find((e) => e.id === active) ?? examples[0];
if (!example) return null;
return (
<section className="card" aria-label="Példajóslások">
<div className="tab-list" role="tablist" aria-label="Példák">
{examples.map((e) => (
<button
key={e.id}
type="button"
role="tab"
className="tab"
aria-selected={e.id === example.id}
onClick={() => setActive(e.id)}
>
{e.label}
</button>
))}
</div>
<Demo key={example.id} example={example} />
</section>
);
}
@@ -0,0 +1,106 @@
"use client";
import { tarotCard, type TarotReading } from "@/lib/tarot";
import { TarotCard, TarotCardBack } from "./TarotCard";
/** Face-down cards in the fan to pick from. */
export const FAN = 21;
/**
* The shuffled deck fanned out. With `onPick` the cards are buttons; without
* it (the demo) they are only a picture, and `lifted` is the card about to go.
*/
export function TarotFan({
picked,
lifted,
onPick,
}: {
picked: number[];
lifted?: number | null;
onPick?: (i: number) => void;
}) {
return (
<div
className="tarot-fan"
role={onPick ? "group" : undefined}
aria-label={onPick ? "A megkevert pakli" : undefined}
aria-hidden={onPick ? undefined : true}
>
{Array.from({ length: FAN }).map((_, i) => {
const className = [
"tarot-fan-card",
picked.includes(i) ? "is-picked" : "",
lifted === i ? "is-lifted" : "",
]
.filter(Boolean)
.join(" ");
const style = { "--i": i - (FAN - 1) / 2 } as React.CSSProperties;
return onPick ? (
<button
key={i}
type="button"
className={className}
style={style}
onClick={() => onPick(i)}
disabled={picked.includes(i)}
aria-label={`${i + 1}. lap kiválasztása`}
>
<TarotCardBack />
</button>
) : (
<span key={i} className={className} style={style}>
<TarotCardBack />
</span>
);
})}
</div>
);
}
/**
* The places of the spread: empty, a face-down card (`filled`), or the drawn
* card turning over (the first `revealed` of `cards`).
*/
export function TarotSlots({
count,
filled,
cards,
revealed,
}: {
count: number;
filled: number;
cards?: TarotReading["cards"];
revealed: number;
}) {
return (
<ol className="tarot-slots" data-count={count}>
{Array.from({ length: count }).map((_, i) => {
const drawn = cards?.[i];
const card = drawn && i < filled ? tarotCard(drawn.card) : undefined;
const flipped = !!card && i < revealed;
return (
<li key={i} className="tarot-slot">
<div className={flipped ? "tarot-flip is-flipped" : "tarot-flip"}>
{i < filled ? (
<div className="tarot-flip-inner">
<TarotCardBack className="tarot-face tarot-back" />
{card && <TarotCard card={card} reversed={drawn?.reversed} className="tarot-face tarot-front" />}
</div>
) : (
<div className="tarot-slot-empty" aria-hidden="true" />
)}
</div>
<span className="tarot-slot-title">{drawn?.position ?? `${i + 1}. lap`}</span>
{flipped && card && (
<span className="hint">
{card.nameHu}
{drawn?.reversed ? " · fordított" : ""}
</span>
)}
</li>
);
})}
</ol>
);
}
@@ -8,11 +8,10 @@ import { SPREADS, TAROT_QUESTION_MAX, tarotCard, type SpreadId, type TarotReadin
import type { PayMethod, UnitBalance } from "@/lib/types";
import { PackageChooser } from "../PackageCards";
import { TarotCard, TarotCardBack } from "./TarotCard";
import { TarotCard } from "./TarotCard";
import { TarotLive } from "./TarotLive";
import { TarotFan, TarotSlots } from "./TarotSpread";
/** Face-down cards in the fan to pick from. */
const FAN = 21;
/** Pause between two cards turning over. */
const REVEAL_MS = 650;
@@ -224,52 +223,9 @@ export function TarotTable({
</p>
</div>
<ol className="tarot-slots" data-count={slots}>
{Array.from({ length: slots }).map((_, i) => {
const drawn = current?.cards[i];
const card = drawn ? tarotCard(drawn.card) : undefined;
const flipped = !!card && i < revealed;
return (
<li key={i} className="tarot-slot">
<div className={flipped ? "tarot-flip is-flipped" : "tarot-flip"}>
{i < picked.length || drawn ? (
<div className="tarot-flip-inner">
<TarotCardBack className="tarot-face tarot-back" />
{card && <TarotCard card={card} reversed={drawn?.reversed} className="tarot-face tarot-front" />}
</div>
) : (
<div className="tarot-slot-empty" aria-hidden="true" />
)}
</div>
<span className="tarot-slot-title">{drawn?.position ?? `${i + 1}. lap`}</span>
{flipped && card && (
<span className="hint">
{card.nameHu}
{drawn?.reversed ? " · fordított" : ""}
</span>
)}
</li>
);
})}
</ol>
<TarotSlots count={slots} filled={current ? slots : picked.length} cards={current?.cards} revealed={revealed} />
{phase === "picking" && (
<div className="tarot-fan" role="group" aria-label="A megkevert pakli">
{Array.from({ length: FAN }).map((_, i) => (
<button
key={i}
type="button"
className={picked.includes(i) ? "tarot-fan-card is-picked" : "tarot-fan-card"}
style={{ "--i": i - (FAN - 1) / 2 } as React.CSSProperties}
onClick={() => pick(i)}
disabled={picked.includes(i)}
aria-label={`${i + 1}. lap kiválasztása`}
>
<TarotCardBack />
</button>
))}
</div>
)}
{phase === "picking" && <TarotFan picked={picked} onPick={pick} />}
{phase === "picking" && (
<div className="form-actions">
<button type="button" className="btn btn-ghost" onClick={again}>