dracosh 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +78 -2
  4. package/assets/sounds/ask.wav +0 -0
  5. package/assets/sounds/badge.wav +0 -0
  6. package/assets/sounds/close.wav +0 -0
  7. package/assets/sounds/combo.wav +0 -0
  8. package/assets/sounds/correct-0.wav +0 -0
  9. package/assets/sounds/correct-1.wav +0 -0
  10. package/assets/sounds/correct-2.wav +0 -0
  11. package/assets/sounds/correct-3.wav +0 -0
  12. package/assets/sounds/correct-4.wav +0 -0
  13. package/assets/sounds/correct-5.wav +0 -0
  14. package/assets/sounds/evolve.wav +0 -0
  15. package/assets/sounds/goal.wav +0 -0
  16. package/assets/sounds/wrong.wav +0 -0
  17. package/data/tips.json +1362 -0
  18. package/package.json +47 -4
  19. package/src/alerts.js +37 -0
  20. package/src/anki.js +36 -0
  21. package/src/cli.js +116 -0
  22. package/src/commands.js +28 -0
  23. package/src/dates.js +15 -0
  24. package/src/demo.js +11 -0
  25. package/src/diff.js +46 -0
  26. package/src/hint.js +12 -0
  27. package/src/judge.js +57 -0
  28. package/src/parse.js +42 -0
  29. package/src/progress.js +363 -0
  30. package/src/quiet.js +32 -0
  31. package/src/scheduler.js +82 -0
  32. package/src/session.js +129 -0
  33. package/src/settings.js +43 -0
  34. package/src/store.js +61 -0
  35. package/src/tips.js +47 -0
  36. package/src/ui/AnswerInput.js +82 -0
  37. package/src/ui/App.js +369 -0
  38. package/src/ui/Badges.js +64 -0
  39. package/src/ui/Companion.js +60 -0
  40. package/src/ui/Confetti.js +46 -0
  41. package/src/ui/Evolution.js +58 -0
  42. package/src/ui/Hatch.js +99 -0
  43. package/src/ui/Header.js +116 -0
  44. package/src/ui/Mascot.js +128 -0
  45. package/src/ui/Missed.js +52 -0
  46. package/src/ui/Preview.js +181 -0
  47. package/src/ui/Settings.js +65 -0
  48. package/src/ui/Stats.js +108 -0
  49. package/src/ui/Summary.js +34 -0
  50. package/src/ui/Tip.js +25 -0
  51. package/src/ui/icons.js +209 -0
  52. package/src/ui/kit.js +63 -0
  53. package/src/vacation.js +51 -0
  54. package/src/words.js +16 -0
@@ -0,0 +1,60 @@
1
+ import { Fragment, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { STAGES } from "../progress.js";
4
+ import { html, PANEL_WIDTH, theme } from "./kit.js";
5
+ import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
6
+
7
+ const MOODS = [
8
+ { face: "idle", label: "calm" },
9
+ { face: "smile", label: "content" },
10
+ { face: "happy", label: "right!" },
11
+ { face: "sad", label: "wrong" },
12
+ { face: "happy", label: "combo", hot: true }
13
+ ];
14
+
15
+ const requirement = (stage, locked) => (stage.from === 0 ? "from the start" : `${locked ? "needs " : ""}${stage.from} days`);
16
+
17
+ // Every form of the companion (dark silhouettes for the ones you haven't reached) and its moods.
18
+ export function Companion({ current, best, onClose }) {
19
+ const [shown, setShown] = useState(current);
20
+ useInput((input, key) => {
21
+ if (key.escape || input === "q") return onClose();
22
+ if (key.leftArrow) return setShown((s) => Math.max(0, s - 1));
23
+ if (key.rightArrow) return setShown((s) => Math.min(STAGES.length - 1, s + 1));
24
+ });
25
+
26
+ return html`
27
+ <${Fragment}>
28
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
29
+ <${Text} bold color=${theme.accent}>Companion<//>
30
+ <${Text} dimColor>It evolves with your best streak (best: ${best} days) and never loses a form.<//>
31
+
32
+ <${Box} marginTop=${1} flexWrap="wrap">
33
+ ${STAGES.map((stage, i) => {
34
+ const locked = i > current;
35
+ return html`
36
+ <${Box} key=${stage.name} width=${22} flexDirection="column" marginBottom=${1}>
37
+ <${Box} flexDirection="column"><${Mascot} stage=${i} locked=${locked} face=${locked ? "idle" : "smile"} /><//>
38
+ <${Text} bold=${i === current} color=${i === current ? theme.accent : undefined} dimColor=${locked}>${stage.name}${i === current ? " ← now" : ""}<//>
39
+ <${Text} dimColor>${requirement(stage, locked)}<//>
40
+ <//>
41
+ `;
42
+ })}
43
+ <//>
44
+
45
+ <${Text} bold>Moods <${Text} dimColor>of ${STAGES[shown].name} · ←/→ to switch form<//><//>
46
+ <${Box} marginTop=${1}>
47
+ ${MOODS.map(
48
+ (mood) => html`
49
+ <${Box} key=${mood.label} width=${MASCOT_WIDTH + 1} flexDirection="column">
50
+ <${Mascot} stage=${shown} face=${mood.face} hot=${Boolean(mood.hot)} locked=${shown > current} />
51
+ <${Text} dimColor>${mood.label}<//>
52
+ <//>
53
+ `
54
+ )}
55
+ <//>
56
+ <//>
57
+ <${Box} paddingX=${1}><${Text} dimColor>←/→ form · esc back<//><//>
58
+ <//>
59
+ `;
60
+ }
@@ -0,0 +1,46 @@
1
+ import { useEffect, useMemo, useState } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { html, theme } from "./kit.js";
4
+
5
+ const ROWS = 4;
6
+ const FRAME_MS = 100;
7
+ const COLORS = [theme.accent, theme.good, theme.warn, "#7dd3fc", "#f0abfc"];
8
+ const GLYPHS = ["▪", "▘", "▝", "▖", "▗", "•"];
9
+
10
+ // A short burst of falling pixels over the card, played once when the daily goal lands.
11
+ export function Confetti({ width, onDone }) {
12
+ const particles = useMemo(
13
+ () =>
14
+ Array.from({ length: Math.floor(width / 2.5) }, () => ({
15
+ col: Math.floor(Math.random() * width),
16
+ delay: Math.floor(Math.random() * 7),
17
+ color: COLORS[Math.floor(Math.random() * COLORS.length)],
18
+ glyph: GLYPHS[Math.floor(Math.random() * GLYPHS.length)]
19
+ })),
20
+ [width]
21
+ );
22
+ const total = ROWS + 7 + 1;
23
+ const [frame, setFrame] = useState(0);
24
+ useEffect(() => {
25
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
26
+ return () => clearInterval(id);
27
+ }, []);
28
+ useEffect(() => {
29
+ if (frame > total) onDone();
30
+ }, [frame, total, onDone]);
31
+
32
+ const rows = Array.from({ length: ROWS }, (_, r) => {
33
+ const here = particles.filter((p) => frame - p.delay === r).sort((a, b) => a.col - b.col);
34
+ const cells = [];
35
+ let at = 0;
36
+ for (const p of here) {
37
+ if (p.col < at) continue; // two particles on one cell: draw the first
38
+ cells.push(html`<${Text} key=${`g${p.col}`}>${" ".repeat(p.col - at)}<//>`);
39
+ cells.push(html`<${Text} key=${`p${p.col}`} color=${p.color}>${p.glyph}<//>`);
40
+ at = p.col + 1;
41
+ }
42
+ return html`<${Text} key=${r}>${cells.length ? cells : " "}<//>`;
43
+ });
44
+
45
+ return html`<${Box} flexDirection="column" paddingX=${1}>${rows}<//>`;
46
+ }
@@ -0,0 +1,58 @@
1
+ import { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, PANEL_WIDTH, theme } from "./kit.js";
4
+ import { Mascot } from "./Mascot.js";
5
+
6
+ const FRAME_MS = 120;
7
+ const FLASH_FROM = 6; // frames 0..5: the old form, wondering
8
+ const REVEAL_AT = 16; // frames 6..15: white-out flashing, then the new form
9
+ const SPARKS = ["✦", "·", "✧", "*"];
10
+
11
+ const article = (name) => (/^[aeiou]/i.test(name) ? "an" : "a");
12
+
13
+ // a loose ring of sparkles around the sprite; which ones show varies per frame
14
+ function sparkleRow(frame, seed, width) {
15
+ const chars = [];
16
+ for (let i = 0; i < width; i++) {
17
+ chars.push((i * 7 + seed * 13 + frame * 3) % 11 === 0 ? SPARKS[(i + frame) % SPARKS.length] : " ");
18
+ }
19
+ return chars.join("");
20
+ }
21
+
22
+ // The full-screen moment when the companion evolves: old form → white flashes → new form.
23
+ // Any key fast-forwards to the reveal; Enter/Esc then closes it.
24
+ export function Evolution({ from, to, name, onClose }) {
25
+ const [frame, setFrame] = useState(0);
26
+ useEffect(() => {
27
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
28
+ return () => clearInterval(id);
29
+ }, []);
30
+ const revealed = frame >= REVEAL_AT;
31
+ useInput(() => {
32
+ if (!revealed) return setFrame(REVEAL_AT);
33
+ onClose();
34
+ });
35
+
36
+ const flashing = frame >= FLASH_FROM && !revealed;
37
+ const stage = revealed ? to : from;
38
+ const sparks = flashing || (revealed && frame < REVEAL_AT + 8);
39
+
40
+ return html`
41
+ <${Fragment}>
42
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH} alignItems="center">
43
+ <${Text} bold color=${theme.warn}>✦ Evolution ✦<//>
44
+ <${Box} flexDirection="column" marginTop=${1} alignItems="center">
45
+ <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 1, 30) : " "}<//>
46
+ <${Mascot} stage=${stage} face=${revealed ? "happy" : "idle"} flash=${flashing && frame % 2 === 0} scale=${2} />
47
+ <${Text} color=${theme.warn}>${sparks ? sparkleRow(frame, 2, 30) : " "}<//>
48
+ <//>
49
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
50
+ ${revealed
51
+ ? html`<${Text} bold color=${theme.accent}>Your companion evolved into ${article(name)} ${name}!<//>`
52
+ : html`<${Text} dimColor>Something is happening…<//>`}
53
+ <//>
54
+ <//>
55
+ <${Box} paddingX=${1}><${Text} dimColor>${revealed ? "enter continue" : "any key to hurry it up"}<//><//>
56
+ <//>
57
+ `;
58
+ }
@@ -0,0 +1,99 @@
1
+ import React, { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, PANEL_WIDTH, theme } from "./kit.js";
4
+ import { Mascot } from "./Mascot.js";
5
+
6
+ const FRAME_MS = 110;
7
+ // a cream egg with green dragon spots: O outline, L shell, D shade, S spot, K crack
8
+ const EGG = [
9
+ "............",
10
+ "....OOOO....",
11
+ "...OLLLLO...",
12
+ "..OLLSSLLO..",
13
+ "..OLLLLLLO..",
14
+ ".OLSLLLLSLO.",
15
+ ".OLLLLLLLLO.",
16
+ ".OLLLLSLLLO.",
17
+ "..ODDDDDDO..",
18
+ "...OOOOOO..."
19
+ ];
20
+ const EGG_COLORS = { O: "#5a5040", L: "#f3ead7", D: "#cdbf9f", S: "#58a66d", K: "#2a241c" };
21
+ const FLASH_COLORS = { O: "#d8e8dc", L: "#ffffff", D: "#eef6f0", S: "#ffffff", K: "#ffffff" };
22
+ const CRACKS = [
23
+ [[4, 5, "K"], [5, 6, "K"], [4, 7, "K"]],
24
+ [[6, 3, "K"], [5, 4, "K"], [6, 5, "K"], [5, 8, "K"], [6, 8, "K"], [3, 4, "K"]]
25
+ ];
26
+
27
+ // the timeline, in frames: rest → wobble → crack → wobble → crack → shake → flash → dragon
28
+ const CRACK_AT = [16, 26];
29
+ const FLASH_AT = 36;
30
+ const REVEAL_AT = 41;
31
+
32
+ const wobble = (frame) => {
33
+ if (frame < 8) return 0;
34
+ const speed = frame < CRACK_AT[1] ? 2 : 1; // the egg shakes faster once it's badly cracked
35
+ return Math.floor(frame / speed) % 2 === 0 ? 1 : -1;
36
+ };
37
+
38
+ function eggGrid(frame) {
39
+ const grid = EGG.map((row) => [...row]);
40
+ CRACKS.forEach((edits, i) => {
41
+ if (frame >= CRACK_AT[i]) edits.forEach(([r, c, p]) => (grid[r][c] = p));
42
+ });
43
+ const dx = wobble(frame);
44
+ return dx ? grid.map((row) => row.map((_, c) => row[c - dx] ?? ".")) : grid;
45
+ }
46
+
47
+ // one text row per pixel row, two characters per pixel: the same 2× scale as the evolution ceremony
48
+ function BigPixels({ grid, colors }) {
49
+ return html`
50
+ <${Fragment}>
51
+ ${grid.map(
52
+ (row, r) => html`<${Text} key=${r}>${row.map((p, c) => React.createElement(Text, { key: c, color: colors[p] }, colors[p] ? "██" : " "))}<//>`
53
+ )}
54
+ <//>
55
+ `;
56
+ }
57
+
58
+ // First launch ever: the dragon hatches. Any key skips ahead; after the reveal, any key starts the quiz.
59
+ export function Hatch({ onDone, play = () => {} }) {
60
+ const [frame, setFrame] = useState(0);
61
+ useEffect(() => {
62
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
63
+ return () => clearInterval(id);
64
+ }, []);
65
+ useEffect(() => {
66
+ if (CRACK_AT.includes(frame)) play("close");
67
+ if (frame === REVEAL_AT) play("evolve");
68
+ }, [frame]);
69
+
70
+ const revealed = frame >= REVEAL_AT;
71
+ useInput(() => (revealed ? onDone() : setFrame(REVEAL_AT)));
72
+
73
+ const flashing = frame >= FLASH_AT && !revealed;
74
+ const caption = revealed ? "" : frame >= CRACK_AT[0] ? "it's hatching…" : "something stirs inside…";
75
+
76
+ return html`
77
+ <${Fragment}>
78
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} paddingY=${1} width=${PANEL_WIDTH} alignItems="center">
79
+ <${Text} bold color=${theme.accent}>Dracosh<//>
80
+ <${Box} flexDirection="column" marginTop=${1} alignItems="center">
81
+ ${revealed
82
+ ? html`<${Mascot} stage=${0} face="happy" scale=${2} />`
83
+ : html`<${BigPixels} grid=${eggGrid(frame)} colors=${flashing && frame % 2 === 0 ? FLASH_COLORS : EGG_COLORS} />`}
84
+ <//>
85
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
86
+ ${revealed
87
+ ? html`
88
+ <${Fragment}>
89
+ <${Text} bold color=${theme.good}>Your dragon has hatched!<//>
90
+ <${Text} dimColor>Answer words to keep it happy. It grows with your streak.<//>
91
+ <//>
92
+ `
93
+ : html`<${Text} dimColor>${caption}<//>`}
94
+ <//>
95
+ <//>
96
+ <${Box} paddingX=${1}><${Text} dimColor>${revealed ? "any key to start" : "any key to skip"}<//><//>
97
+ <//>
98
+ `;
99
+ }
@@ -0,0 +1,116 @@
1
+ import { useEffect, useState } from "react";
2
+ import { Box, Text } from "ink";
3
+ import { formatInterval } from "../settings.js";
4
+ import { formatDay } from "../vacation.js";
5
+ import { AnimatedBar, html, theme } from "./kit.js";
6
+ import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
7
+
8
+ const FRAME_MS = 90;
9
+ // pixel offsets per animation frame: a hop up for a right answer, a head-shake for a miss
10
+ const MOVES = {
11
+ jump: [{ dy: 1 }, { dy: 1 }, { dy: 1 }, {}],
12
+ shake: [{ dx: 1 }, {}, { dx: 1 }, {}]
13
+ };
14
+
15
+ // Replays MOVES[event.kind] once whenever `event` changes, then settles back to stillness.
16
+ export function useMove(event) {
17
+ const [frame, setFrame] = useState(-1);
18
+ useEffect(() => {
19
+ if (!event) return undefined;
20
+ const frames = MOVES[event.kind] ?? [];
21
+ setFrame(frames.length ? 0 : -1);
22
+ let i = 0;
23
+ const id = setInterval(() => {
24
+ i += 1;
25
+ if (i >= frames.length) {
26
+ clearInterval(id);
27
+ setFrame(-1);
28
+ } else {
29
+ setFrame(i);
30
+ }
31
+ }, FRAME_MS);
32
+ return () => clearInterval(id);
33
+ }, [event]);
34
+ return frame < 0 ? {} : (MOVES[event.kind] ?? [])[frame] ?? {};
35
+ }
36
+
37
+ const BLINK_MS = 140;
38
+ const BLINK_GAP_MS = [2500, 7000];
39
+ const DOUBLE_BLINK_CHANCE = 0.25;
40
+
41
+ // Blinks at random moments, now and then twice in a row, like something alive.
42
+ export function useBlink() {
43
+ const [closed, setClosed] = useState(false);
44
+ useEffect(() => {
45
+ let timer;
46
+ const schedule = (ms) => (timer = setTimeout(blink, ms));
47
+ const randomGap = () => BLINK_GAP_MS[0] + Math.random() * (BLINK_GAP_MS[1] - BLINK_GAP_MS[0]);
48
+ function blink(again = Math.random() < DOUBLE_BLINK_CHANCE) {
49
+ setClosed(true);
50
+ timer = setTimeout(() => {
51
+ setClosed(false);
52
+ timer = again ? setTimeout(() => blink(false), BLINK_MS * 1.5) : schedule(randomGap());
53
+ }, BLINK_MS);
54
+ }
55
+ schedule(randomGap());
56
+ return () => clearTimeout(timer);
57
+ }, []);
58
+ return closed;
59
+ }
60
+
61
+ // only calm faces blink: a beaming or crying dragon keeps its expression
62
+ const BLINKABLE = new Set(["idle", "smile"]);
63
+
64
+ const SNORE_ROWS = 5; // as tall as the sprite
65
+
66
+ // Little z's drifting up beside a sleeping dragon: a lowercase z low down, a capital Z near the top.
67
+ export function Snore({ tick }) {
68
+ const step = Math.floor(tick / 2); // half the clock speed: a slow, drowsy drift
69
+ return html`
70
+ <${Box} flexDirection="column" width=${3}>
71
+ ${Array.from({ length: SNORE_ROWS }, (_, r) => {
72
+ const on = (r + step) % 3 === 0 && r < SNORE_ROWS - 1;
73
+ return html`<${Text} key=${r} color=${theme.accent} dimColor=${r > 1}>${on ? (r < 2 ? " Z" : "z ") : " "}<//>`;
74
+ })}
75
+ <//>
76
+ `;
77
+ }
78
+
79
+ export function Header({ deck, everyMs, wordCount, stats, combo, face, event, tick = 0, asleep = false }) {
80
+ const { streak, today, goal, companion } = stats;
81
+ const move = useMove(event);
82
+ const blinking = useBlink();
83
+ const hot = combo >= 3 && !asleep;
84
+ const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
85
+ return html`
86
+ <${Box} paddingX=${1}>
87
+ <${Box} width=${MASCOT_WIDTH + 3}>
88
+ <${Box} flexDirection="column" width=${MASCOT_WIDTH}>
89
+ <${Mascot} face=${shown} hot=${hot} flicker=${hot && tick % 2 === 0} stage=${companion.index} dx=${move.dx ?? 0} dy=${move.dy ?? 0} />
90
+ <//>
91
+ ${asleep && html`<${Snore} tick=${tick} />`}
92
+ <//>
93
+ <${Box} flexDirection="column" justifyContent="center">
94
+ <${Box}>
95
+ <${Text} bold color=${theme.accent}>Dracosh<//>
96
+ <${Text} dimColor> ${deck}${wordCount ? ` · ${wordCount} words` : ""} · every ${formatInterval(everyMs)}<//>
97
+ <//>
98
+ <${Box}>
99
+ ${streak.days > 0
100
+ ? html`<${Text} color=${theme.warn} bold>🔥 ${streak.days}-day streak<//>`
101
+ : html`<${Text} dimColor>no streak yet<//>`}
102
+ ${streak.atRisk && html`<${Text} color=${theme.warn}> · at risk today<//>`}
103
+ ${stats.vacation.activeUntil && html`<${Text} color=${theme.accent}> · on vacation until ${formatDay(stats.vacation.activeUntil)}<//>`}
104
+ ${streak.freezes > 0 && html`<${Text} dimColor> · ${streak.freezes} freeze${streak.freezes > 1 ? "s" : ""}<//>`}
105
+ <//>
106
+ <${Box}>
107
+ <${Text} dimColor>today <//>
108
+ <${AnimatedBar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
109
+ <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
110
+ ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
111
+ ${combo >= 2 && html`<${Text} color=${theme.warn} bold> combo ×${combo}<//>`}
112
+ <//>
113
+ <//>
114
+ <//>
115
+ `;
116
+ }
@@ -0,0 +1,128 @@
1
+ import React from "react";
2
+ import { Text } from "ink";
3
+ import { html } from "./kit.js";
4
+
5
+ // A tiny flashcard creature, drawn as pixels: every text row stacks two pixel rows using half blocks (▀ ▄ █).
6
+ // Proper pixel art: O = dark outline, L = top highlight, B = body, D = bottom shade.
7
+ // Its form (accessories) comes from the evolution stage, its expression from how you are doing.
8
+ const WIDTH = 12;
9
+ const BASE = [
10
+ "............",
11
+ "..OOOOOOOO..",
12
+ ".OLLLLLLLLO.",
13
+ ".OBBEBBEBBO.",
14
+ ".OBBEBBEBBO.",
15
+ ".OBBBBBBBBO.",
16
+ ".ODBBBBBBDO.",
17
+ "..OOOOOOOO..",
18
+ "...OO..OO...",
19
+ "............"
20
+ ];
21
+
22
+ // a little green dragon: scale-green body, cream belly, bone horns, golden spikes
23
+ const PALETTES = {
24
+ normal: { B: "#58a66d", L: "#8ed49a", D: "#3d7a4d", O: "#1e3b27", E: "#132019", C: "#f2a9b8", T: "#7dd3fc" },
25
+ // two hot variants: alternating them per tick makes the combo glow flicker like dragon fire
26
+ hot: { B: "#fbbf24", L: "#fde68a", D: "#d97706", O: "#7c4a03", E: "#3b2300", C: "#fef3c7", T: "#7dd3fc" },
27
+ hot2: { B: "#f59e0b", L: "#fcd34d", D: "#c2610a", O: "#6b3f03", E: "#3b2300", C: "#fde68a", T: "#7dd3fc" },
28
+ // the white-out frames of the evolution ceremony
29
+ flash: { B: "#eaf6ec", L: "#ffffff", D: "#cfe6d4", O: "#9db8a4", E: "#eaf6ec", C: "#ffffff", T: "#ffffff" }
30
+ };
31
+ const ACCESSORY_COLORS = { H: "#e8dcc8", W: "#2f6b45", P: "#e6d79a", S: "#d9a441", G: "#fcd34d" };
32
+ const FLASH_ACCESSORIES = { H: "#ffffff", W: "#cfe6d4", P: "#ffffff", S: "#ffffff", G: "#ffffff" };
33
+
34
+ // What each evolution stage adds on top of the previous one: [row, col, pixel]
35
+ const STAGE_EDITS = [
36
+ [], // 0 Hatchling
37
+ [[0, 3, "H"], [1, 3, "H"], [0, 8, "H"], [1, 8, "H"]], // 1 Imp: horns
38
+ [[3, 0, "W"], [4, 0, "W"], [3, 11, "W"], [4, 11, "W"]], // 2 Whelp: little wings
39
+ [[5, 4, "P"], [5, 5, "P"], [5, 6, "P"], [5, 7, "P"], [6, 4, "P"], [6, 5, "P"], [6, 6, "P"], [6, 7, "P"], [6, 11, "W"], [7, 10, "W"]], // 3 Drake: belly and tail
40
+ [[0, 5, "S"], [0, 6, "S"], [2, 0, "W"], [2, 11, "W"], [5, 0, "W"], [5, 11, "W"]], // 4 Dragon: head spikes, bigger wings
41
+ [[0, 4, "G"], [0, 5, "G"], [0, 6, "G"], [0, 7, "G"]] // 5 Legend: halo (and golden horns, see below)
42
+ ];
43
+ const LEGEND = STAGE_EDITS.length - 1;
44
+
45
+ const OPEN_EYES = []; // the base already has them
46
+ const SHUT_EYES = [[3, 4, "B"], [3, 7, "B"]]; // only the lower eye pixel stays: half-closed
47
+ const SMILE = [[5, 4, "E"], [6, 5, "E"], [6, 6, "E"], [5, 7, "E"]];
48
+ const GRIN = [[5, 4, "E"], [5, 7, "E"], [6, 4, "E"], [6, 5, "E"], [6, 6, "E"], [6, 7, "E"]];
49
+ const FROWN = [[6, 4, "E"], [5, 5, "E"], [5, 6, "E"], [6, 7, "E"]];
50
+
51
+ // [row, col, pixel] edits for each expression, applied last
52
+ const FACES = {
53
+ idle: [...OPEN_EYES, [5, 5, "E"], [5, 6, "E"]], // straight little mouth
54
+ blink: [...SHUT_EYES, [5, 5, "E"], [5, 6, "E"]],
55
+ smile: SMILE, // content: today's goal is done
56
+ happy: [...SHUT_EYES, ...GRIN, [4, 2, "C"], [4, 9, "C"]], // beaming, with blushing cheeks
57
+ sad: [...FROWN, [5, 8, "T"]], // a tear under the right eye
58
+ sleep: [...SHUT_EYES] // eyes shut, mouth relaxed away
59
+ };
60
+
61
+ // `shift` nudges the whole grid by dx columns / dy pixel rows (half a text row) for jump and shake frames
62
+ export function drawSprite(face, stage = 0, { dx = 0, dy = 0 } = {}) {
63
+ const grid = BASE.map((row) => [...row]);
64
+ const apply = (edits) => edits.forEach(([r, c, pixel]) => (grid[r][c] = pixel));
65
+ STAGE_EDITS.slice(0, stage + 1).forEach(apply);
66
+ apply(FACES[face] ?? FACES.idle);
67
+ if (!dx && !dy) return grid;
68
+ return grid.map((_, r) => grid[r].map((_, c) => grid[r + dy]?.[c + dx] ?? "."));
69
+ }
70
+
71
+ // one text row from two stacked pixel rows
72
+ function cell(top, bottom, palette, key) {
73
+ const t = palette[top];
74
+ const b = palette[bottom];
75
+ if (!t && !b) return React.createElement(Text, { key }, " ");
76
+ if (t && !b) return React.createElement(Text, { key, color: t }, "▀");
77
+ if (!t && b) return React.createElement(Text, { key, color: b }, "▄");
78
+ if (t === b) return React.createElement(Text, { key, color: t }, "█");
79
+ return React.createElement(Text, { key, color: t, backgroundColor: b }, "▀");
80
+ }
81
+
82
+ // Any pixel-letter grid rendered with half blocks; the mascot and the badge icons share it.
83
+ export function PixelGrid({ grid, palette }) {
84
+ const rows = [];
85
+ for (let r = 0; r < grid.length; r += 2) {
86
+ const cells = [];
87
+ for (let c = 0; c < grid[r].length; c++) cells.push(cell(grid[r][c], grid[r + 1]?.[c], palette, c));
88
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
89
+ }
90
+ return html`<${React.Fragment}>${rows}<//>`;
91
+ }
92
+
93
+ const LOCKED = { B: "#3a3f47", L: "#454b54", D: "#31363d", O: "#23272d", E: "#1f2328", C: "#3a3f47", T: "#3a3f47", H: "#4a5058", W: "#4a5058", P: "#4a5058", S: "#4a5058", G: "#4a5058" };
94
+
95
+ function paletteFor({ locked, flash, hot, flicker, stage }) {
96
+ if (locked) return LOCKED;
97
+ if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash };
98
+ const body = hot ? (flicker ? PALETTES.hot2 : PALETTES.hot) : PALETTES.normal;
99
+ const palette = { ...ACCESSORY_COLORS, ...body };
100
+ if (stage >= LEGEND) palette.H = ACCESSORY_COLORS.G; // Legend: golden horns under the halo
101
+ return palette;
102
+ }
103
+
104
+ // `locked` draws a dark silhouette (a form you haven't reached yet); `flash` whites it out (evolution);
105
+ // `flicker` alternates the hot palette; `scale: 2` draws one text row per pixel row, two chars per pixel.
106
+ export function Mascot({ face = "idle", hot = false, stage = 0, locked = false, flash = false, flicker = false, scale = 1, dx = 0, dy = 0 }) {
107
+ const palette = paletteFor({ locked, flash, hot, flicker, stage });
108
+ const grid = drawSprite(face, stage, { dx, dy });
109
+ const rows = [];
110
+ if (scale === 2) {
111
+ for (let r = 0; r < grid.length; r++) {
112
+ const cells = grid[r].map((pixel, c) => {
113
+ const color = palette[pixel];
114
+ return React.createElement(Text, { key: c, color }, color ? "██" : " ");
115
+ });
116
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
117
+ }
118
+ } else {
119
+ for (let r = 0; r < grid.length; r += 2) {
120
+ const cells = [];
121
+ for (let c = 0; c < WIDTH; c++) cells.push(cell(grid[r][c], grid[r + 1][c], palette, c));
122
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
123
+ }
124
+ }
125
+ return html`<${React.Fragment}>${rows}<//>`;
126
+ }
127
+
128
+ export const MASCOT_WIDTH = WIDTH;
@@ -0,0 +1,52 @@
1
+ import { Fragment, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, PANEL_WIDTH, theme } from "./kit.js";
4
+
5
+ const MAX_ROWS = 10;
6
+
7
+ const dayLabel = (offset, date) => (offset === 0 ? "today" : offset === -1 ? `yesterday · ${date}` : date);
8
+
9
+ // Words you got wrong on a day, with what you typed and whether you got them right afterwards.
10
+ export function Missed({ getMissed, onClose }) {
11
+ const [offset, setOffset] = useState(0);
12
+ useInput((input, key) => {
13
+ if (key.escape || key.return || input === "q") return onClose();
14
+ if (key.leftArrow) return setOffset((o) => o - 1);
15
+ if (key.rightArrow) return setOffset((o) => Math.min(0, o + 1));
16
+ });
17
+
18
+ const { date, items } = getMissed(offset);
19
+ const shown = items.slice(0, MAX_ROWS);
20
+
21
+ return html`
22
+ <${Fragment}>
23
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${PANEL_WIDTH}>
24
+ <${Box}>
25
+ <${Text} bold color=${theme.accent}>Missed<//>
26
+ <${Text} dimColor> ${dayLabel(offset, date)} · ${items.length} word${items.length === 1 ? "" : "s"}<//>
27
+ <//>
28
+ ${items.length === 0
29
+ ? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "Nothing missed so far today." : "Nothing missed that day."}<//><//>`
30
+ : html`
31
+ <${Box} flexDirection="column" marginTop=${1}>
32
+ ${shown.map(
33
+ (item) => html`
34
+ <${Box} key=${item.key} flexDirection="column" marginBottom=${1}>
35
+ <${Text}>
36
+ <${Text} color=${item.recovered ? theme.good : theme.bad} bold>${item.recovered ? "✓" : "✗"}<//>
37
+ <${Text} bold> ${item.prompt}<//>
38
+ <${Text} dimColor> ${item.label}${item.times > 1 ? ` · missed ${item.times}×` : ""}<//>
39
+ <//>
40
+ <${Text}> ${item.expected.join(", ")}<//>
41
+ <${Text} dimColor> you wrote: ${item.answer}${item.recovered ? " · got it right since" : ""}<//>
42
+ <//>
43
+ `
44
+ )}
45
+ ${items.length > MAX_ROWS && html`<${Text} dimColor>…and ${items.length - MAX_ROWS} more<//>`}
46
+ <//>
47
+ `}
48
+ <//>
49
+ <${Box} paddingX=${1}><${Text} dimColor>←/→ day · esc back<//><//>
50
+ <//>
51
+ `;
52
+ }