dracosh 0.0.0-stage → 0.2.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 (70) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +10 -0
  3. package/README.md +100 -2
  4. package/assets/sounds/ask.wav +0 -0
  5. package/assets/sounds/badge-1.wav +0 -0
  6. package/assets/sounds/badge-2.wav +0 -0
  7. package/assets/sounds/badge-3.wav +0 -0
  8. package/assets/sounds/badge-4.wav +0 -0
  9. package/assets/sounds/close.wav +0 -0
  10. package/assets/sounds/combo.wav +0 -0
  11. package/assets/sounds/correct-0.wav +0 -0
  12. package/assets/sounds/correct-1.wav +0 -0
  13. package/assets/sounds/correct-2.wav +0 -0
  14. package/assets/sounds/correct-3.wav +0 -0
  15. package/assets/sounds/correct-4.wav +0 -0
  16. package/assets/sounds/correct-5.wav +0 -0
  17. package/assets/sounds/evolve.wav +0 -0
  18. package/assets/sounds/goal.wav +0 -0
  19. package/assets/sounds/wrong.wav +0 -0
  20. package/data/tips.json +32 -0
  21. package/package.json +47 -4
  22. package/src/alerts.js +38 -0
  23. package/src/anki.js +36 -0
  24. package/src/backup.js +95 -0
  25. package/src/cli.js +197 -0
  26. package/src/commands.js +28 -0
  27. package/src/dates.js +15 -0
  28. package/src/demo.js +11 -0
  29. package/src/diff.js +46 -0
  30. package/src/hint.js +12 -0
  31. package/src/judge.js +78 -0
  32. package/src/library.js +127 -0
  33. package/src/lock.js +63 -0
  34. package/src/manage.js +75 -0
  35. package/src/parse.js +42 -0
  36. package/src/pause.js +23 -0
  37. package/src/progress.js +455 -0
  38. package/src/quiet.js +32 -0
  39. package/src/scheduler.js +94 -0
  40. package/src/session.js +227 -0
  41. package/src/settings.js +38 -0
  42. package/src/starter.js +38 -0
  43. package/src/store.js +100 -0
  44. package/src/tips.js +30 -0
  45. package/src/ui/AddCard.js +172 -0
  46. package/src/ui/AnswerInput.js +85 -0
  47. package/src/ui/App.js +509 -0
  48. package/src/ui/BadgeUnlock.js +50 -0
  49. package/src/ui/Badges.js +122 -0
  50. package/src/ui/Choice.js +33 -0
  51. package/src/ui/Companion.js +45 -0
  52. package/src/ui/Confetti.js +46 -0
  53. package/src/ui/Decks.js +49 -0
  54. package/src/ui/DieRoll.js +104 -0
  55. package/src/ui/Evolution.js +59 -0
  56. package/src/ui/Hatch.js +100 -0
  57. package/src/ui/Header.js +117 -0
  58. package/src/ui/Help.js +68 -0
  59. package/src/ui/Mascot.js +178 -0
  60. package/src/ui/Missed.js +53 -0
  61. package/src/ui/Preview.js +256 -0
  62. package/src/ui/Reset.js +72 -0
  63. package/src/ui/Settings.js +69 -0
  64. package/src/ui/Stats.js +111 -0
  65. package/src/ui/Summary.js +41 -0
  66. package/src/ui/TheOne.js +121 -0
  67. package/src/ui/icons.js +341 -0
  68. package/src/ui/kit.js +120 -0
  69. package/src/vacation.js +56 -0
  70. package/src/words.js +23 -0
@@ -0,0 +1,117 @@
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 { Flame } from "./icons.js";
7
+ import { Mascot, MASCOT_WIDTH } from "./Mascot.js";
8
+
9
+ const FRAME_MS = 90;
10
+ // pixel offsets per animation frame: a hop up for a right answer, a head-shake for a miss
11
+ const MOVES = {
12
+ jump: [{ dy: 1 }, { dy: 1 }, { dy: 1 }, {}],
13
+ shake: [{ dx: 1 }, {}, { dx: 1 }, {}]
14
+ };
15
+
16
+ // Replays MOVES[event.kind] once whenever `event` changes, then settles back to stillness.
17
+ export function useMove(event) {
18
+ const [frame, setFrame] = useState(-1);
19
+ useEffect(() => {
20
+ if (!event) return undefined;
21
+ const frames = MOVES[event.kind] ?? [];
22
+ setFrame(frames.length ? 0 : -1);
23
+ let i = 0;
24
+ const id = setInterval(() => {
25
+ i += 1;
26
+ if (i >= frames.length) {
27
+ clearInterval(id);
28
+ setFrame(-1);
29
+ } else {
30
+ setFrame(i);
31
+ }
32
+ }, FRAME_MS);
33
+ return () => clearInterval(id);
34
+ }, [event]);
35
+ return frame < 0 ? {} : (MOVES[event.kind] ?? [])[frame] ?? {};
36
+ }
37
+
38
+ const BLINK_MS = 140;
39
+ const BLINK_GAP_MS = [2500, 7000];
40
+ const DOUBLE_BLINK_CHANCE = 0.25;
41
+
42
+ // Blinks at random moments, now and then twice in a row, like something alive.
43
+ export function useBlink() {
44
+ const [closed, setClosed] = useState(false);
45
+ useEffect(() => {
46
+ let timer;
47
+ const schedule = (ms) => (timer = setTimeout(blink, ms));
48
+ const randomGap = () => BLINK_GAP_MS[0] + Math.random() * (BLINK_GAP_MS[1] - BLINK_GAP_MS[0]);
49
+ function blink(again = Math.random() < DOUBLE_BLINK_CHANCE) {
50
+ setClosed(true);
51
+ timer = setTimeout(() => {
52
+ setClosed(false);
53
+ timer = again ? setTimeout(() => blink(false), BLINK_MS * 1.5) : schedule(randomGap());
54
+ }, BLINK_MS);
55
+ }
56
+ schedule(randomGap());
57
+ return () => clearTimeout(timer);
58
+ }, []);
59
+ return closed;
60
+ }
61
+
62
+ // only calm faces blink: a beaming or crying dragon keeps its expression
63
+ const BLINKABLE = new Set(["idle", "smile"]);
64
+
65
+ const SNORE_ROWS = 5; // as tall as the sprite
66
+
67
+ // Little z's drifting up beside a sleeping dragon: a lowercase z low down, a capital Z near the top.
68
+ export function Snore({ tick }) {
69
+ const step = Math.floor(tick / 2); // half the clock speed: a slow, drowsy drift
70
+ return html`
71
+ <${Box} flexDirection="column" width=${3}>
72
+ ${Array.from({ length: SNORE_ROWS }, (_, r) => {
73
+ const on = (r + step) % 3 === 0 && r < SNORE_ROWS - 1;
74
+ return html`<${Text} key=${r} color=${theme.accent} dimColor=${r > 1}>${on ? (r < 2 ? " Z" : "z ") : " "}<//>`;
75
+ })}
76
+ <//>
77
+ `;
78
+ }
79
+
80
+ export function Header({ deck, everyMs, wordCount, stats, combo, face, event, tick = 0, asleep = false }) {
81
+ const { streak, today, goal, companion } = stats;
82
+ const move = useMove(event);
83
+ const blinking = useBlink();
84
+ const hot = combo >= 3 && !asleep;
85
+ const shown = asleep ? "sleep" : blinking && BLINKABLE.has(face) ? "blink" : face;
86
+ return html`
87
+ <${Box} paddingX=${1}>
88
+ <${Box} width=${MASCOT_WIDTH + 3} flexShrink=${0}>
89
+ <${Box} flexDirection="column" width=${MASCOT_WIDTH}>
90
+ <${Mascot} face=${shown} hot=${hot} flicker=${hot && tick % 2 === 0} stage=${companion.index} element=${companion.element} dx=${move.dx ?? 0} dy=${move.dy ?? 0} />
91
+ <//>
92
+ ${asleep && html`<${Snore} tick=${tick} />`}
93
+ <//>
94
+ <${Box} flexDirection="column" justifyContent="center">
95
+ <${Box}>
96
+ <${Box} flexShrink=${0}><${Text} bold color=${theme.accent}>Dracosh<//><//>
97
+ <${Text} dimColor wrap="truncate-end"> ${deck}${wordCount ? ` · ${wordCount} card${wordCount === 1 ? "" : "s"}` : ""} · every ${formatInterval(everyMs)}<//>
98
+ <//>
99
+ <${Box}>
100
+ ${streak.days > 0
101
+ ? html`<${Box}><${Flame} /><${Text} color=${theme.warn} bold> ${streak.days}-day streak<//><//>`
102
+ : html`<${Text} dimColor>no streak yet<//>`}
103
+ ${streak.atRisk && html`<${Text} color=${theme.warn}> · at risk today<//>`}
104
+ ${stats.vacation.activeUntil && html`<${Text} color=${theme.accent}> · days off until ${formatDay(stats.vacation.activeUntil)}<//>`}
105
+ ${streak.freezes > 0 && html`<${Text} dimColor> · ${streak.freezes} freeze${streak.freezes > 1 ? "s" : ""}<//>`}
106
+ <//>
107
+ <${Box}>
108
+ <${Text} dimColor>today <//>
109
+ <${AnimatedBar} value=${today.correct} max=${goal} width=${12} color=${today.goalMet ? theme.good : theme.accent} />
110
+ <${Text} dimColor> ${Math.min(today.correct, goal)}/${goal}<//>
111
+ ${today.goalMet && html`<${Text} color=${theme.good}> goal reached<//>`}
112
+ ${combo >= 2 && html`<${Text} color=${theme.warn} bold> combo ×${combo}<//>`}
113
+ <//>
114
+ <//>
115
+ <//>
116
+ `;
117
+ }
package/src/ui/Help.js ADDED
@@ -0,0 +1,68 @@
1
+ import { Fragment } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { MAX_FREEZES } from "../progress.js";
4
+ import { BOX_INTERVALS_DAYS } from "../scheduler.js";
5
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
6
+
7
+ const KEYS = [
8
+ ["Enter", "submit your answer (empty shows the answer); between cards, ask the next one"],
9
+ ["/", "open the commands"],
10
+ ["Esc", "clear what you typed, or quit"],
11
+ ["q", "quit, between cards"],
12
+ ["any key", "wakes a sleeping dragon"]
13
+ ];
14
+
15
+ const HOW = [
16
+ `A right answer moves a card to a later box: it comes back in ${BOX_INTERVALS_DAYS.slice(0, -1).join(", ")}, then ${BOX_INTERVALS_DAYS.at(-1)} days. A miss sends it back to the first box.`,
17
+ "One wrong letter in a longer word still counts, and you see the right spelling.",
18
+ "Reach your daily goal to keep your streak going; a day where you did every card there was counts too. Your dragon grows with your best streak.",
19
+ `A freeze covers a day you missed. You start with ${MAX_FREEZES} and get one back each week, ${MAX_FREEZES} at most.`
20
+ ];
21
+
22
+ const OUTSIDE = [
23
+ ['dracosh --deck "Polish"', "quiz another deck"],
24
+ ["dracosh --data", "where your cards and backups are"],
25
+ ["dracosh restore", "bring back a backup"],
26
+ ["dracosh --help", "every option"]
27
+ ];
28
+
29
+ function Rows({ rows, width }) {
30
+ return rows.map(
31
+ ([left, right]) => html`
32
+ <${Box} key=${left}>
33
+ <${Box} width=${width} flexShrink=${0}><${Text} color=${theme.accent}>${left}<//><//>
34
+ <${Text}>${right}<//>
35
+ <//>
36
+ `
37
+ );
38
+ }
39
+
40
+ const Section = ({ title, children }) => html`
41
+ <${Box} flexDirection="column" marginTop=${1}>
42
+ <${Text} bold>${title}<//>
43
+ ${children}
44
+ <//>
45
+ `;
46
+
47
+ // How Dracosh works, on one screen: the keys, the rules behind the boxes and the streak,
48
+ // and what you can do from the shell.
49
+ export function Help({ onClose }) {
50
+ const panel = usePanelWidth();
51
+ useInput((input, key) => {
52
+ if (key.escape || key.return || input === "q") onClose();
53
+ });
54
+
55
+ return html`
56
+ <${Fragment}>
57
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
58
+ <${Text} bold color=${theme.accent}>Help<//>
59
+ <${Section} title="Keys"><${Rows} rows=${KEYS} width=${10} /><//>
60
+ <${Section} title="How it works">
61
+ ${HOW.map((line) => html`<${Box} key=${line}><${Box} width=${2} flexShrink=${0}><${Text} dimColor>·<//><//><${Text}>${line}<//><//>`)}
62
+ <//>
63
+ <${Section} title="Outside the quiz"><${Rows} rows=${OUTSIDE} width=${26} /><//>
64
+ <//>
65
+ <${Box} paddingX=${1}><${KeyHints} text="esc back" /><//>
66
+ <//>
67
+ `;
68
+ }
@@ -0,0 +1,178 @@
1
+ import React from "react";
2
+ import { Text } from "ink";
3
+ import { html } from "./kit.js";
4
+
5
+ // A little dragon, 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 (horns, wings, tail…) comes from the evolution stage, its expression from how you are doing.
8
+ const WIDTH = 14;
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
+ // The dragon's element, rolled once with "Dragon's die": its own body and accessory colors, plus a few
35
+ // details (X, Y) drawn before the evolution accessories, so horns, wings and the crown always show.
36
+ const ELEMENT_LOOKS = {
37
+ earth: {
38
+ body: { B: "#8b6d47", L: "#b8955f", D: "#5e4630", O: "#2e2216" },
39
+ accents: { H: "#d9cbb0", W: "#6b4f2e", P: "#c9b48a", S: "#a07c4f" },
40
+ colors: { X: "#7fb045", Y: "#6b5a44" },
41
+ details: [[2, 4, "X"], [2, 5, "X"], [2, 9, "X"], [6, 3, "Y"], [6, 10, "Y"]] // moss on the head, pebbles below
42
+ },
43
+ wind: {
44
+ body: { B: "#b4bfbc", L: "#e3e8e6", D: "#8a9592", O: "#4a5452" },
45
+ accents: { H: "#f0f3f2", W: "#9aa5a2", P: "#d5dcda", S: "#e3e8e6" },
46
+ colors: { X: "#eef2f1" },
47
+ details: [[3, 0, "X"], [4, 0, "X"], [4, 13, "X"], [8, 1, "X"]] // wisps of air around it
48
+ },
49
+ water: {
50
+ body: { B: "#3b82c4", L: "#7cb8e8", D: "#245d94", O: "#13304d" },
51
+ accents: { H: "#cfe8ff", W: "#1e5a8f", P: "#a5d3f5", S: "#7cb8e8" },
52
+ colors: { X: "#5fb3f0", Y: "#bfe3ff" },
53
+ details: [[1, 6, "X"], [1, 7, "X"], [3, 13, "Y"]] // a fin on the head, a drop of water
54
+ },
55
+ ice: {
56
+ body: { B: "#bfe6f5", L: "#ffffff", D: "#86c0d8", O: "#3d6f86" },
57
+ accents: { H: "#e0f7ff", W: "#86c0d8", P: "#ffffff", S: "#e0f7ff" },
58
+ colors: { X: "#e0f7ff", Y: "#ffffff" },
59
+ details: [[0, 3, "X"], [0, 10, "X"], [6, 4, "Y"], [6, 9, "Y"]] // crystal spikes, frost
60
+ },
61
+ fire: {
62
+ body: { B: "#e4572e", L: "#f59e5b", D: "#a8341c", O: "#4a140a" },
63
+ accents: { H: "#fde68a", W: "#a8341c", P: "#fbbf24", S: "#fbbf24" },
64
+ colors: { X: "#fbbf24", Y: "#fde68a" },
65
+ details: [[0, 5, "X"], [0, 8, "X"], [3, 0, "Y"], [3, 13, "Y"]] // flame tips, embers
66
+ },
67
+ cosmos: {
68
+ body: { B: "#3b2f7a", L: "#5b4bb0", D: "#30266a", O: "#2a2163", E: "#05030f", C: "#c084fc" },
69
+ accents: { H: "#c4b5fd", W: "#261d55", P: "#5b4bb0", S: "#c4b5fd" },
70
+ colors: { X: "#fef3c7" },
71
+ details: [[2, 3, "X"], [2, 10, "X"], [5, 10, "X"], [6, 3, "X"]] // stars on its body
72
+ }
73
+ };
74
+
75
+ // one color that stands for each element in text (names, the die's pips)
76
+ export const ELEMENT_COLOR = { earth: "#a07c4f", wind: "#b4bfbc", water: "#3b82c4", ice: "#bfe6f5", fire: "#e4572e", cosmos: "#8b7cf6" };
77
+
78
+ // What each evolution stage adds on top of the previous one: [row, col, pixel]. The wings rise over
79
+ // the shoulders and never frame the face, so the later forms read as a dragon, not a maned lion.
80
+ const STAGE_EDITS = [
81
+ [], // 0 Hatchling
82
+ [[0, 4, "H"], [1, 4, "H"], [0, 9, "H"], [1, 9, "H"]], // 1 Imp: upright horns
83
+ [[0, 0, "W"], [1, 0, "W"], [1, 1, "W"], [2, 1, "W"], [0, 13, "W"], [1, 13, "W"], [1, 12, "W"], [2, 12, "W"]], // 2 Whelp: little bat wings
84
+ [[5, 5, "P"], [5, 6, "P"], [5, 7, "P"], [5, 8, "P"], [6, 5, "P"], [6, 6, "P"], [6, 7, "P"], [6, 8, "P"], [6, 12, "W"], [7, 13, "W"], [8, 12, "S"], [8, 13, "S"]], // 3 Drake: belly, curled tail with a spade
85
+ [[0, 1, "W"], [0, 12, "W"], [7, 12, "W"], [0, 6, "S"], [0, 7, "S"]], // 4 Dragon: wider wings, a thicker tail, a crest
86
+ [[0, 5, "G"], [0, 6, "G"], [0, 7, "G"], [0, 8, "G"]] // 5 Legend: a crown (and golden horns, see below)
87
+ ];
88
+ const LEGEND = STAGE_EDITS.length - 1;
89
+
90
+ const OPEN_EYES = []; // the base already has them
91
+ const SHUT_EYES = [[3, 5, "B"], [3, 8, "B"]]; // only the lower eye pixel stays: half-closed
92
+ const SMILE = [[5, 5, "E"], [6, 6, "E"], [6, 7, "E"], [5, 8, "E"]];
93
+ const GRIN = [[5, 5, "E"], [5, 8, "E"], [6, 5, "E"], [6, 6, "E"], [6, 7, "E"], [6, 8, "E"]];
94
+ const FROWN = [[6, 5, "E"], [5, 6, "E"], [5, 7, "E"], [6, 8, "E"]];
95
+
96
+ // [row, col, pixel] edits for each expression, applied last
97
+ const FACES = {
98
+ idle: [...OPEN_EYES, [5, 6, "E"], [5, 7, "E"]], // straight little mouth
99
+ blink: [...SHUT_EYES, [5, 6, "E"], [5, 7, "E"]],
100
+ smile: SMILE, // content: today's goal is done
101
+ happy: [...SHUT_EYES, ...GRIN, [4, 3, "C"], [4, 10, "C"]], // beaming, with blushing cheeks
102
+ sad: [...FROWN, [5, 9, "T"]], // a tear under the right eye
103
+ sleep: [...SHUT_EYES] // eyes shut, mouth relaxed away
104
+ };
105
+
106
+ // `dx`/`dy` nudge the whole grid by columns / pixel rows (half a text row) for jump and shake frames
107
+ export function drawSprite(face, stage = 0, { dx = 0, dy = 0, element = null } = {}) {
108
+ const grid = BASE.map((row) => [...row]);
109
+ const apply = (edits) => edits.forEach(([r, c, pixel]) => (grid[r][c] = pixel));
110
+ if (ELEMENT_LOOKS[element]) apply(ELEMENT_LOOKS[element].details);
111
+ STAGE_EDITS.slice(0, stage + 1).forEach(apply);
112
+ apply(FACES[face] ?? FACES.idle);
113
+ if (!dx && !dy) return grid;
114
+ return grid.map((_, r) => grid[r].map((_, c) => grid[r + dy]?.[c + dx] ?? "."));
115
+ }
116
+
117
+ // one text row from two stacked pixel rows
118
+ function cell(top, bottom, palette, key) {
119
+ const t = palette[top];
120
+ const b = palette[bottom];
121
+ if (!t && !b) return React.createElement(Text, { key }, " ");
122
+ if (t && !b) return React.createElement(Text, { key, color: t }, "▀");
123
+ if (!t && b) return React.createElement(Text, { key, color: b }, "▄");
124
+ if (t === b) return React.createElement(Text, { key, color: t }, "█");
125
+ return React.createElement(Text, { key, color: t, backgroundColor: b }, "▀");
126
+ }
127
+
128
+ // Any pixel-letter grid rendered with half blocks; the mascot and the badge icons share it.
129
+ export function PixelGrid({ grid, palette }) {
130
+ const rows = [];
131
+ for (let r = 0; r < grid.length; r += 2) {
132
+ const cells = [];
133
+ for (let c = 0; c < grid[r].length; c++) cells.push(cell(grid[r][c], grid[r + 1]?.[c], palette, c));
134
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
135
+ }
136
+ return html`<${React.Fragment}>${rows}<//>`;
137
+ }
138
+
139
+ // A form you haven't reached: one flat color, no eyes or shading, so only the outline gives it away
140
+ const SILHOUETTE = "#2c3038";
141
+ const LOCKED = Object.fromEntries([..."BLDOECTHWPSGXY"].map((key) => [key, SILHOUETTE]));
142
+
143
+ function paletteFor({ locked, flash, hot, flicker, stage, element }) {
144
+ if (locked) return LOCKED;
145
+ if (flash) return { ...FLASH_ACCESSORIES, ...PALETTES.flash, X: "#ffffff", Y: "#ffffff" };
146
+ const look = ELEMENT_LOOKS[element];
147
+ const body = hot ? (flicker ? PALETTES.hot2 : PALETTES.hot) : { ...PALETTES.normal, ...look?.body };
148
+ const palette = { ...ACCESSORY_COLORS, ...look?.accents, ...look?.colors, ...body };
149
+ if (stage >= LEGEND) palette.H = ACCESSORY_COLORS.G; // Legend: golden horns under the halo
150
+ return palette;
151
+ }
152
+
153
+ // `locked` draws a dark silhouette (a form you haven't reached yet); `flash` whites it out (evolution);
154
+ // `flicker` alternates the hot palette; `scale: 2` draws one text row per pixel row, two chars per pixel.
155
+ // `element` is the dragon's rolled element ("earth" … "cosmos"), or null for the default green dragon
156
+ export function Mascot({ face = "idle", hot = false, stage = 0, locked = false, flash = false, flicker = false, scale = 1, dx = 0, dy = 0, element = null }) {
157
+ const palette = paletteFor({ locked, flash, hot, flicker, stage, element });
158
+ const grid = drawSprite(face, stage, { dx, dy, element });
159
+ const rows = [];
160
+ if (scale === 2) {
161
+ for (let r = 0; r < grid.length; r++) {
162
+ const cells = grid[r].map((pixel, c) => {
163
+ const color = palette[pixel];
164
+ return React.createElement(Text, { key: c, color }, color ? "██" : " ");
165
+ });
166
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
167
+ }
168
+ } else {
169
+ for (let r = 0; r < grid.length; r += 2) {
170
+ const cells = [];
171
+ for (let c = 0; c < grid[r].length; c++) cells.push(cell(grid[r][c], grid[r + 1][c], palette, c));
172
+ rows.push(html`<${Text} key=${r}>${cells}<//>`);
173
+ }
174
+ }
175
+ return html`<${React.Fragment}>${rows}<//>`;
176
+ }
177
+
178
+ export const MASCOT_WIDTH = WIDTH;
@@ -0,0 +1,53 @@
1
+ import { Fragment, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { html, KeyHints, theme, usePanelWidth } 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 panel = usePanelWidth();
12
+ const [offset, setOffset] = useState(0);
13
+ useInput((input, key) => {
14
+ if (key.escape || key.return || input === "q") return onClose();
15
+ if (key.leftArrow) return setOffset((o) => o - 1);
16
+ if (key.rightArrow) return setOffset((o) => Math.min(0, o + 1));
17
+ });
18
+
19
+ const { date, items } = getMissed(offset);
20
+ const shown = items.slice(0, MAX_ROWS);
21
+
22
+ return html`
23
+ <${Fragment}>
24
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.accent} paddingX=${2} width=${panel}>
25
+ <${Box}>
26
+ <${Text} bold color=${theme.accent}>Missed<//>
27
+ <${Text} dimColor> ${dayLabel(offset, date)} · ${items.length} card${items.length === 1 ? "" : "s"}<//>
28
+ <//>
29
+ ${items.length === 0
30
+ ? html`<${Box} marginTop=${1}><${Text} dimColor>${offset === 0 ? "Nothing missed so far today." : "Nothing missed that day."}<//><//>`
31
+ : html`
32
+ <${Box} flexDirection="column" marginTop=${1}>
33
+ ${shown.map(
34
+ (item) => html`
35
+ <${Box} key=${item.key} flexDirection="column" marginBottom=${1}>
36
+ <${Text}>
37
+ <${Text} color=${item.recovered ? theme.good : theme.bad} bold>${item.recovered ? "✓" : "✗"}<//>
38
+ <${Text} bold> ${item.prompt}<//>
39
+ <${Text} dimColor> ${item.label}${item.times > 1 ? ` · missed ${item.times}×` : ""}<//>
40
+ <//>
41
+ <${Text}> ${item.expected.join(", ")}<//>
42
+ <${Text} dimColor> ${item.answer ? `you wrote: ${item.answer}` : "no answer"}${item.recovered ? " · got it right since" : ""}<//>
43
+ <//>
44
+ `
45
+ )}
46
+ ${items.length > MAX_ROWS && html`<${Text} dimColor>…and ${items.length - MAX_ROWS} more<//>`}
47
+ <//>
48
+ `}
49
+ <//>
50
+ <${Box} paddingX=${1}><${KeyHints} text="←/→ day · esc back" /><//>
51
+ <//>
52
+ `;
53
+ }