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,121 @@
1
+ import React, { Fragment, useEffect, useState } from "react";
2
+ import { Box, Text, useInput } from "ink";
3
+ import { RING } from "./icons.js";
4
+ import { html, KeyHints, theme, usePanelWidth } from "./kit.js";
5
+
6
+ const FRAME_MS = 110;
7
+ const WIDTH = 16; // pixels; each is drawn two characters wide
8
+ const HEIGHT = 15;
9
+ const LAVA_TOP = 11; // first row of lava; the ring is hidden wherever it's below this
10
+ const RING_LEFT = 4;
11
+ const RING_REST = 2; // the ring's top row once it's fully out
12
+
13
+ // timeline, in frames: bubbling lava → the ring rises (one row every 2 frames) → it cools → reveal
14
+ const RISE_FROM = 10;
15
+ const RISE_TO = RISE_FROM + (LAVA_TOP - RING_REST) * 2;
16
+ const COOLED_AT = RISE_TO + 6;
17
+ const REVEAL_AT = COOLED_AT + 4;
18
+
19
+ const LAVA = { R: "#9f1d0d", O: "#ea580c", Y: "#fbbf24" };
20
+ // the ring glows while it comes out of the lava, then cools down to gold
21
+ const HEAT = [
22
+ { G: "#ff7a1a", D: "#c2410c", W: "#fde68a" },
23
+ { G: "#fbbf24", D: "#d97706", W: "#fef3c7" },
24
+ RING.palette
25
+ ];
26
+ const SPARKS = ["✦", "·", "✧", "*"];
27
+
28
+ function lavaColor(x, y, frame) {
29
+ const n = (x * 7 + y * 3 + Math.floor(frame / 2) * 5) % 9;
30
+ if (y === LAVA_TOP && (x + Math.floor(frame / 2)) % 5 === 0) return null; // a wavy surface
31
+ return n < 2 ? LAVA.Y : n < 6 ? LAVA.O : LAVA.R;
32
+ }
33
+
34
+ // a few bubbles popping just above the surface
35
+ function bubbleColor(x, y, frame) {
36
+ for (const [bx, offset] of [[3, 0], [9, 2], [13, 4]]) {
37
+ const t = (frame + offset) % 6;
38
+ if (x === bx && t < 3 && y === LAVA_TOP - 1 - t) return LAVA.O;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function ringTop(frame) {
44
+ if (frame < RISE_FROM) return LAVA_TOP + 1; // still fully submerged
45
+ return Math.max(RING_REST, LAVA_TOP - Math.floor((frame - RISE_FROM) / 2));
46
+ }
47
+
48
+ function heatOf(frame) {
49
+ if (frame < RISE_TO + 2) return HEAT[0];
50
+ return frame < COOLED_AT ? HEAT[1] : HEAT[2];
51
+ }
52
+
53
+ // → rows of colors (null = empty) for one frame
54
+ function scene(frame) {
55
+ const top = ringTop(frame);
56
+ const heat = heatOf(frame);
57
+ return Array.from({ length: HEIGHT }, (_, y) =>
58
+ Array.from({ length: WIDTH }, (_, x) => {
59
+ if (y >= LAVA_TOP) return lavaColor(x, y, frame);
60
+ const ry = y - top;
61
+ const rx = x - RING_LEFT;
62
+ const pixel = RING.grid[ry]?.[rx];
63
+ if (pixel && pixel !== ".") return heat[pixel];
64
+ return bubbleColor(x, y, frame);
65
+ })
66
+ );
67
+ }
68
+
69
+ function BigScene({ rows }) {
70
+ return html`
71
+ <${Fragment}>
72
+ ${rows.map(
73
+ (row, r) => html`<${Text} key=${r}>${row.map((color, c) => React.createElement(Text, { key: c, color }, color ? "██" : " "))}<//>`
74
+ )}
75
+ <//>
76
+ `;
77
+ }
78
+
79
+ const sparkleRow = (frame, seed) =>
80
+ Array.from({ length: 30 }, (_, i) => ((i * 7 + seed * 13 + frame * 3) % 11 === 0 ? SPARKS[(i + frame) % SPARKS.length] : " ")).join("");
81
+
82
+ // The ceremony for "The One", the badge for collecting every other badge: a ring rises from the lava.
83
+ // Any key skips to the end; after the reveal, any key closes it.
84
+ export function TheOne({ onClose, play = () => {} }) {
85
+ const panel = usePanelWidth();
86
+ const [frame, setFrame] = useState(0);
87
+ useEffect(() => {
88
+ const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
89
+ return () => clearInterval(id);
90
+ }, []);
91
+ useEffect(() => {
92
+ if (frame === RISE_FROM) play("close");
93
+ if (frame === REVEAL_AT) play("evolve");
94
+ }, [frame]);
95
+
96
+ const revealed = frame >= REVEAL_AT;
97
+ useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
98
+ const caption = frame < RISE_FROM ? "the lava is stirring…" : "something rises…";
99
+
100
+ return html`
101
+ <${Fragment}>
102
+ <${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
103
+ <${Text} color=${theme.warn}>${revealed ? sparkleRow(frame, 1) : " "}<//>
104
+ <${Box} flexDirection="column" alignItems="center">
105
+ <${BigScene} rows=${scene(frame)} />
106
+ <//>
107
+ <${Box} marginTop=${1} flexDirection="column" alignItems="center">
108
+ ${revealed
109
+ ? html`
110
+ <${Fragment}>
111
+ <${Text} bold color=${RING.palette.G}>The One...<//>
112
+ <${Text} dimColor>Every badge is yours. The hoard is complete.<//>
113
+ <//>
114
+ `
115
+ : html`<${Text} dimColor>${caption}<//>`}
116
+ <//>
117
+ <//>
118
+ <${Box} paddingX=${1}><${KeyHints} text=${revealed ? "any key to continue" : "any key to skip"} /><//>
119
+ <//>
120
+ `;
121
+ }
@@ -0,0 +1,341 @@
1
+ import { Text } from "ink";
2
+ import { BADGES } from "../progress.js";
3
+ import { html } from "./kit.js";
4
+ import { PixelGrid } from "./Mascot.js";
5
+
6
+ // 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
7
+ // Letters are per-icon palette keys; "." is transparent.
8
+ const ICONS = {
9
+ trophy: {
10
+ palette: { G: "#fcd34d", D: "#b45309", W: "#fef3c7" },
11
+ grid: [
12
+ ".GGGGGG.",
13
+ "GDGWGGDG",
14
+ "GDGGGGDG",
15
+ ".DGGGGD.",
16
+ "..DGGD..",
17
+ "...GG...",
18
+ "..DGGD..",
19
+ ".GGGGGG."
20
+ ]
21
+ },
22
+ flame: {
23
+ palette: { R: "#f97316", Y: "#fbbf24", W: "#fef3c7" },
24
+ grid: [
25
+ "...R....",
26
+ "...RR.R.",
27
+ "..RRRR..",
28
+ ".RRYYRR.",
29
+ ".RYYYYR.",
30
+ ".RYWWYR.",
31
+ "..YWWY..",
32
+ "...YY..."
33
+ ]
34
+ },
35
+ book: {
36
+ palette: { B: "#9d7cd8", D: "#6b4fa0", W: "#efe6f7", L: "#cbb8e8" },
37
+ grid: [
38
+ "........",
39
+ ".BBBBBB.",
40
+ "DBWWWWB.",
41
+ "DBWLLWB.",
42
+ "DBWWWWB.",
43
+ "DBWLLWB.",
44
+ ".BBBBBB.",
45
+ "........"
46
+ ]
47
+ },
48
+ star: {
49
+ palette: { S: "#fbbf24", W: "#fef3c7", R: "#60a5fa" },
50
+ grid: [
51
+ "...S....",
52
+ "..SSS...",
53
+ "SSSWSSS.",
54
+ ".SSWSS..",
55
+ "..SSS...",
56
+ ".SS.SS..",
57
+ "SS...SS.",
58
+ "........"
59
+ ]
60
+ },
61
+ bolt: {
62
+ palette: { Y: "#fbbf24", W: "#fef3c7" },
63
+ grid: [
64
+ "...YYY..",
65
+ "..YYY...",
66
+ ".YYYYY..",
67
+ "...YWY..",
68
+ "..YYY...",
69
+ ".YYY....",
70
+ ".YY.....",
71
+ "Y......."
72
+ ]
73
+ },
74
+ sun: {
75
+ palette: { Y: "#fbbf24", O: "#f97316" },
76
+ grid: [
77
+ "Y..YY..Y",
78
+ "..YYYY..",
79
+ ".YYOOYY.",
80
+ "YYOOOOYY",
81
+ "YYOOOOYY",
82
+ ".YYOOYY.",
83
+ "..YYYY..",
84
+ "Y..YY..Y"
85
+ ]
86
+ },
87
+ moon: {
88
+ palette: { M: "#7dd3fc", W: "#fef3c7" },
89
+ grid: [
90
+ "...MMM..",
91
+ "..MM..W.",
92
+ ".MM.....",
93
+ ".MM.....",
94
+ ".MM.....",
95
+ ".MM.....",
96
+ "..MM..W.",
97
+ "...MMM.."
98
+ ]
99
+ },
100
+ calendar: {
101
+ palette: { C: "#9aa4b2", R: "#f87171", W: "#f4f4f5", G: "#4ade80" },
102
+ grid: [
103
+ ".C.CC.C.",
104
+ "RRRRRRRR",
105
+ "CWWWWWWC",
106
+ "CWGWGWWC",
107
+ "CWWWWWWC",
108
+ "CWGWWGWC",
109
+ "CCCCCCCC",
110
+ "........"
111
+ ]
112
+ },
113
+ snowflake: {
114
+ palette: { I: "#7dd3fc", W: "#e0f2fe" },
115
+ grid: [
116
+ "...I....",
117
+ ".I.I.I..",
118
+ "..IWI...",
119
+ "IIIWIII.",
120
+ "..IWI...",
121
+ ".I.I.I..",
122
+ "...I....",
123
+ "........"
124
+ ]
125
+ },
126
+ heart: {
127
+ palette: { H: "#f87171", W: "#fecaca" },
128
+ grid: [
129
+ "........",
130
+ ".HH..HH.",
131
+ "HWHHHHHH",
132
+ "HWHHHHHH",
133
+ ".HHHHHH.",
134
+ "..HHHH..",
135
+ "...HH...",
136
+ "........"
137
+ ]
138
+ },
139
+ compass: {
140
+ palette: { C: "#9aa4b2", W: "#f4f4f5", R: "#f87171", B: "#64748b" },
141
+ grid: [
142
+ "..CCCC..",
143
+ ".CWWWWC.",
144
+ "CWWWRWWC",
145
+ "CWWRRWWC",
146
+ "CWWBBWWC",
147
+ ".CWBWWC.",
148
+ "..CCCC..",
149
+ "........"
150
+ ]
151
+ }
152
+ };
153
+
154
+ // the ring for the badge that needs every other one
155
+ ICONS.ring = {
156
+ palette: { G: "#fcd34d", D: "#b45309", W: "#fef9c3" },
157
+ grid: [
158
+ "..GGGG..",
159
+ ".GW..GG.",
160
+ "GW....DG",
161
+ "G......G",
162
+ "G......G",
163
+ "GG....DG",
164
+ ".GD..DG.",
165
+ "..DDDD.."
166
+ ]
167
+ };
168
+
169
+ export const RING = ICONS.ring;
170
+
171
+ // "Dragon's die": a die showing five
172
+ ICONS.die = {
173
+ palette: { W: "#f4f4f5", D: "#c7c9d1", P: "#2a2440" },
174
+ grid: [
175
+ ".WWWWWW.",
176
+ "WPPWWPPW",
177
+ "WPPWWPPW",
178
+ "WWWPPWWD",
179
+ "WWWPPWWD",
180
+ "WPPWWPPD",
181
+ "WPPWWPPD",
182
+ ".DDDDDD."
183
+ ]
184
+ };
185
+
186
+ // what a hidden badge shows until it's won
187
+ ICONS.secret = {
188
+ palette: { Q: "#6b7280" },
189
+ grid: [
190
+ "..QQQQ..",
191
+ ".QQ..QQ.",
192
+ ".....QQ.",
193
+ "....QQ..",
194
+ "...QQ...",
195
+ "...QQ...",
196
+ "........",
197
+ "...QQ..."
198
+ ]
199
+ };
200
+
201
+ // which icon each badge gets, by badge id
202
+ const ICON_FOR = {
203
+ hello: "trophy",
204
+ "first-steps": "trophy",
205
+ century: "trophy",
206
+ thousand: "trophy",
207
+ "five-thousand": "trophy",
208
+ "ten-thousand": "trophy",
209
+ "dragons-hoard": "trophy",
210
+ "on-a-roll": "flame",
211
+ week: "flame",
212
+ fortnight: "flame",
213
+ month: "flame",
214
+ "hundred-days": "flame",
215
+ dragonheart: "flame",
216
+ keeper: "book",
217
+ collector: "book",
218
+ dictionary: "book",
219
+ lexicon: "book",
220
+ explorer: "compass",
221
+ flawless: "star",
222
+ overachiever: "star",
223
+ marathon: "star",
224
+ "hot-streak": "bolt",
225
+ unstoppable: "bolt",
226
+ "combo-master": "bolt",
227
+ "early-bird": "sun",
228
+ "night-owl": "moon",
229
+ comeback: "heart",
230
+ redemption: "heart",
231
+ frozen: "snowflake",
232
+ weekend: "calendar",
233
+ "perfect-week": "calendar",
234
+ regular: "calendar",
235
+ machine: "calendar",
236
+ "hundred-club": "calendar",
237
+ "one-ring": "ring",
238
+ "dragons-die": "die"
239
+ };
240
+
241
+ const LOCKED_COLOR = "#4a5058";
242
+
243
+ // Rank colors for the badge groups that climb (more answers, longer streaks…): the higher, the rarer.
244
+ const TIERS = [
245
+ { name: "bronze", main: "#d08a4e", shade: "#8a4f1c", light: "#f3c9a0" },
246
+ { name: "silver", main: "#c9d1d9", shade: "#7d8794", light: "#ffffff" },
247
+ { name: "gold", main: "#fcd34d", shade: "#b45309", light: "#fef3c7" },
248
+ { name: "emerald", main: "#34d399", shade: "#047857", light: "#d1fae5" },
249
+ { name: "diamond", main: "#7dd3fc", shade: "#2b6f99", light: "#e0f2fe" },
250
+ { name: "amethyst", main: "#c084fc", shade: "#6b21a8", light: "#f3e8ff" },
251
+ { name: "ruby", main: "#f87171", shade: "#991b1b", light: "#fee2e2" }
252
+ ];
253
+ // Badges that share an icon but need telling apart get their own grid: the calendars mark the days
254
+ // each one asks for, from a weekend to a month nearly full; the day badges are a star (no miss),
255
+ // a crown (double the goal) and a medal (a marathon); a heart with a mended crack is a mistake put right.
256
+ const CALENDAR_PAGE = (days) => [".C.CC.C.", "RRRRRRRR", ...days.map((row) => `C${row}C`), "CCCCCCCC", "........"];
257
+ const OWN_GRIDS = {
258
+ weekend: CALENDAR_PAGE(["WWWWWW", "WWWWGG", "WWWWWW", "WWWWGG"]),
259
+ "perfect-week": CALENDAR_PAGE(["WWWWWW", "GGGGGG", "WWWWWW", "WWWWWW"]),
260
+ regular: CALENDAR_PAGE(["GWGGWG", "GGWGGW", "WGGWGG", "WWWWWW"]),
261
+ machine: CALENDAR_PAGE(["GGGGGG", "GGGGWG", "GGGGGG", "GGWWWW"]),
262
+ "hundred-club": CALENDAR_PAGE(["GGGGGG", "GGGGGG", "GGGGGG", "GGGGGG"]),
263
+ overachiever: [
264
+ "........",
265
+ "W..W..W.",
266
+ "S..S..S.",
267
+ "SS.S.SS.",
268
+ "SSSSSSS.",
269
+ "SRSWSRS.",
270
+ "SSSSSSS.",
271
+ "........"
272
+ ],
273
+ marathon: [
274
+ "RR....RR",
275
+ ".RR..RR.",
276
+ "..RRRR..",
277
+ "..SSSS..",
278
+ ".SSWSSS.",
279
+ ".SWSSSS.",
280
+ ".SSSSSS.",
281
+ "..SSSS.."
282
+ ],
283
+ redemption: [
284
+ "........",
285
+ ".HH..HH.",
286
+ "HWH.HHHH",
287
+ "HWHH.HHH",
288
+ ".HH.HHH.",
289
+ "..HH.H..",
290
+ "...HH...",
291
+ "........"
292
+ ]
293
+ };
294
+
295
+ // which palette letters of a tiered icon take the tier's main / shade / light color
296
+ const TIER_ROLES = {
297
+ trophy: { G: "main", D: "shade", W: "light" },
298
+ flame: { Y: "main", R: "shade", W: "light" },
299
+ book: { B: "main", D: "shade" },
300
+ bolt: { Y: "main", W: "light" },
301
+ calendar: { R: "main" }
302
+ };
303
+
304
+ // the badge's rank within its group, in the order BADGES lists them (easiest first); null if the group isn't tiered
305
+ function tierOf(id) {
306
+ const icon = ICON_FOR[id];
307
+ if (!TIER_ROLES[icon]) return null;
308
+ const group = BADGES.filter((badge) => ICON_FOR[badge.id] === icon).map((badge) => badge.id);
309
+ return TIERS[Math.min(group.indexOf(id), TIERS.length - 1)];
310
+ }
311
+
312
+ function paletteFor(id, icon) {
313
+ const tier = tierOf(id);
314
+ if (!tier) return icon.palette;
315
+ const roles = TIER_ROLES[ICON_FOR[id]];
316
+ return Object.fromEntries(Object.entries(icon.palette).map(([key, color]) => [key, roles[key] ? tier[roles[key]] : color]));
317
+ }
318
+
319
+ // the color that stands for an unlocked badge in lists: its rank color, or gold for untiered ones
320
+ export const badgeColor = (id) => tierOf(id)?.main ?? TIERS[2].main;
321
+
322
+ const fillIn = (row) => row.replace(/(?<=[^.].*)\.(?=.*[^.])/g, "G");
323
+
324
+ // `locked` greys the icon out; `flash` whites it out (a frame of a badge lighting up in /badges);
325
+ // `secret` replaces a hidden badge that isn't won yet with a question mark
326
+ export function BadgeIcon({ id, locked = false, flash = false, secret = false }) {
327
+ if (secret) return html`<${PixelGrid} grid=${ICONS.secret.grid.map((row) => [...row])} palette=${ICONS.secret.palette} />`;
328
+ const icon = ICONS[ICON_FOR[id]] ?? ICONS.star;
329
+ const flat = (color) => Object.fromEntries(Object.keys(icon.palette).map((k) => [k, color]));
330
+ const palette = flash ? flat("#ffffff") : locked ? flat(LOCKED_COLOR) : paletteFor(id, icon);
331
+ // a locked ring is drawn filled in, so its silhouette doesn't give away what it is
332
+ const own = OWN_GRIDS[id] ?? icon.grid;
333
+ const grid = locked && !flash && id === "one-ring" ? own.map(fillIn) : own;
334
+ return html`<${PixelGrid} grid=${grid.map((row) => [...row])} palette=${palette} />`;
335
+ }
336
+
337
+ // The streak flame: a small triangle in fire orange, the height of the letters next to it.
338
+ // (Pixel blocks fill the whole line height and look too big beside text.)
339
+ export const Flame = () => html`<${Text} color="#f97316">▴<//>`;
340
+
341
+ export const ICON_WIDTH = 8;
package/src/ui/kit.js ADDED
@@ -0,0 +1,120 @@
1
+ import React, { useEffect, useState } from "react";
2
+ import { Text, useStdout } from "ink";
3
+ import htm from "htm";
4
+
5
+ export const html = htm.bind(React.createElement);
6
+
7
+ // Dracosh palette: soft violet accents and a green dragon on dark, gold for fire and glory
8
+ export const theme = {
9
+ accent: "#9d7cd8",
10
+ good: "#4ade80",
11
+ bad: "#f87171",
12
+ warn: "#fbbf24",
13
+ text: "#c9ccd3",
14
+ hint: "#8b919c", // the words in key hints: quieter than text, easier to read than dim
15
+ track: "#3a3f47"
16
+ };
17
+
18
+ // Text where `backticks` mark something to type: shown in the accent color on a faint violet
19
+ // background, like code in docs. Used for the tour's cards; `plain` shows the text as it is.
20
+ export function Marked({ text, plain = false, ...props }) {
21
+ if (plain) return React.createElement(Text, props, text);
22
+ const parts = text.split(/`([^`]+)`/);
23
+ return React.createElement(
24
+ Text,
25
+ props,
26
+ ...parts.map((part, i) => (i % 2 ? React.createElement(Text, { key: i, color: theme.accent, backgroundColor: "#2a2440", bold: true }, part) : part))
27
+ );
28
+ }
29
+
30
+ // the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…
31
+ const KEY = /^(any key|↑\/↓|←\/→|enter|esc|tab|\/\S*|[a-z0-9])(?=\s|$)/;
32
+
33
+ // A footer like "enter submit · / commands · esc quit": each key stands out, the words after it
34
+ // stay quiet, and the dots between them fade back.
35
+ export function KeyHints({ text }) {
36
+ const parts = text.split(" · ");
37
+ return React.createElement(
38
+ Text,
39
+ null,
40
+ ...parts.flatMap((part, i) => {
41
+ const key = KEY.exec(part)?.[0];
42
+ const rest = key ? part.slice(key.length) : part;
43
+ return [
44
+ i > 0 && React.createElement(Text, { key: `s${i}`, color: "#5a606b" }, " · "),
45
+ key && React.createElement(Text, { key: `k${i}`, color: theme.text }, key),
46
+ React.createElement(Text, { key: `r${i}`, color: theme.hint }, rest)
47
+ ].filter(Boolean);
48
+ })
49
+ );
50
+ }
51
+
52
+ // every full-width panel (card, stats, settings…) shares this width
53
+ export const PANEL_WIDTH = 72;
54
+ const MIN_PANEL_WIDTH = 30;
55
+
56
+ // How many terminal cells text takes: CJK characters and emoji take two. Close enough for labels
57
+ // and deck names; whole characters (not UTF-16 halves) are counted, so an emoji is never cut in two.
58
+ const WIDE = /[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\p{Extended_Pictographic}]/u;
59
+ export const cellWidth = (text) => Array.from(text).reduce((sum, ch) => sum + (WIDE.test(ch) ? 2 : 1), 0);
60
+ export function cutToWidth(text, cells) {
61
+ if (cellWidth(text) <= cells) return text;
62
+ let out = "";
63
+ for (const ch of text) {
64
+ if (cellWidth(out + ch) > cells - 1) break;
65
+ out += ch;
66
+ }
67
+ return `${out}…`;
68
+ }
69
+
70
+ // the panel width for this terminal: PANEL_WIDTH, or less in a narrow window (some terminals report 0)
71
+ export function usePanelWidth() {
72
+ const { stdout } = useStdout();
73
+ return Math.max(MIN_PANEL_WIDTH, Math.min((stdout?.columns || PANEL_WIDTH + 2) - 2, PANEL_WIDTH));
74
+ }
75
+
76
+ // A thin line: the filled part in `color`, the rest as a dim track. Plain box-drawing characters render
77
+ // at exactly one cell in every terminal font, unlike the geometric-shape glyphs a font may substitute.
78
+ export function Bar({ value, max, width = 10, color = theme.accent }) {
79
+ const filled = max > 0 ? Math.round(width * Math.min(value / max, 1)) : 0;
80
+ return html`<${Text}><${Text} color=${color}>${"━".repeat(filled)}<//><${Text} color=${theme.track}>${"━".repeat(width - filled)}<//><//>`;
81
+ }
82
+
83
+ // Like Bar, but the fill slides to its new value one cell at a time instead of jumping.
84
+ export function AnimatedBar({ value, max, width = 10, color = theme.accent, stepMs = 45 }) {
85
+ const target = max > 0 ? Math.round(width * Math.min(value / max, 1)) : 0;
86
+ const [filled, setFilled] = useState(0);
87
+ useEffect(() => {
88
+ const id = setInterval(() => {
89
+ setFilled((f) => {
90
+ if (f === target) {
91
+ clearInterval(id);
92
+ return f;
93
+ }
94
+ return f + Math.sign(target - f);
95
+ });
96
+ }, stepMs);
97
+ return () => clearInterval(id);
98
+ }, [target, stepMs]);
99
+ return html`<${Text}><${Text} color=${color}>${"━".repeat(filled)}<//><${Text} color=${theme.track}>${"━".repeat(Math.max(0, width - filled))}<//><//>`;
100
+ }
101
+
102
+ // Text that types itself in. The hidden tail is padded with spaces so the layout doesn't jump while typing.
103
+ export function Typewriter({ text, dimColor = false, color, charsPerTick = 2, tickMs = 30 }) {
104
+ const [shown, setShown] = useState(0);
105
+ useEffect(() => {
106
+ setShown(0);
107
+ const id = setInterval(() => {
108
+ setShown((n) => {
109
+ if (n >= text.length) {
110
+ clearInterval(id);
111
+ return n;
112
+ }
113
+ return n + charsPerTick;
114
+ });
115
+ }, tickMs);
116
+ return () => clearInterval(id);
117
+ }, [text, charsPerTick, tickMs]);
118
+ const visible = text.slice(0, shown);
119
+ return html`<${Text} color=${color} dimColor=${dimColor}>${shown >= text.length ? text : visible + " ".repeat(text.length - visible.length)}<//>`;
120
+ }
@@ -0,0 +1,56 @@
1
+ import { addDays, daysBetween } from "./dates.js";
2
+
3
+ const MAX_DAYS = 120; // a typo like "2062" shouldn't switch the streak off for years
4
+
5
+ export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString("en-GB", { day: "numeric", month: "short" });
6
+ export const formatRange = (from, to) => (from === to ? formatDay(from) : `${formatDay(from)} – ${formatDay(to)}`);
7
+
8
+ // a real calendar date as "YYYY-MM-DD", or null ("31.02" and the like)
9
+ function valid(key) {
10
+ const date = new Date(`${key}T12:00:00`);
11
+ return !Number.isNaN(date.getTime()) && date.toLocaleDateString("sv") === key ? key : null;
12
+ }
13
+
14
+ // "2026-12-24", "24.12.2026", or "24.12" (the next 24 December on or after today)
15
+ function parseDate(text, today) {
16
+ const pad = (n) => String(n).padStart(2, "0");
17
+ const iso = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
18
+ if (iso) return valid(text);
19
+ const dotted = /^(\d{1,2})\.(\d{1,2})(?:\.(\d{4}))?$/.exec(text);
20
+ if (!dotted) return null;
21
+ const [, day, month, year] = dotted;
22
+ if (year) return valid(`${year}-${pad(month)}-${pad(day)}`);
23
+ const thisYear = Number(today.slice(0, 4));
24
+ const key = valid(`${thisYear}-${pad(month)}-${pad(day)}`);
25
+ return key && key < today ? valid(`${thisYear + 1}-${pad(month)}-${pad(day)}`) : key;
26
+ }
27
+
28
+ // days-off arguments (see /pause in pause.js) → { action: "list" } | { action: "off" } | { action: "add", from, to } | null (not understood)
29
+ // "" list what is planned
30
+ // "off" cancel current and future vacations
31
+ // "7" / "7d" 7 days starting today
32
+ // "24.12 2.01" a range (also "24.12..2.01", "2026-12-24 to 2027-01-02"); a single date means one day
33
+ export function parseVacation(args, today) {
34
+ const text = args.trim().toLowerCase();
35
+ if (!text) return { action: "list" };
36
+ if (["off", "cancel", "clear"].includes(text)) return { action: "off" };
37
+
38
+ const days = /^(\d+)\s*d?$/.exec(text);
39
+ if (days) {
40
+ const n = Number(days[1]);
41
+ return n >= 1 && n <= MAX_DAYS ? { action: "add", from: today, to: addDays(today, n - 1) } : null;
42
+ }
43
+
44
+ const parts = text.split(/\s+|\.\.|\bto\b/).filter(Boolean);
45
+ if (parts.length < 1 || parts.length > 2) return null;
46
+ const dates = parts.map((part) => parseDate(part, today));
47
+ if (dates.some((date) => !date)) return null;
48
+ const [a, b = a] = dates;
49
+ // A day and month without a year means the next one to come, so a range that already started
50
+ // ("28.12 3.01" on 30 December, "24.12 2.01" on New Year's Day) gets its start back a year.
51
+ // Of the readings that make sense, the shortest wins; a reversed range is read the other way round.
52
+ const back = (key, part) => (/^\d{1,2}\.\d{1,2}$/.test(part) ? valid(`${Number(key.slice(0, 4)) - 1}${key.slice(4)}`) : null);
53
+ const readings = [[a, b], [back(a, parts[0]), b], [b, a]].filter(([x, y]) => x && y && x <= y);
54
+ const [from, to] = readings.sort(([x1, y1], [x2, y2]) => daysBetween(x1, y1) - daysBetween(x2, y2))[0];
55
+ return daysBetween(from, to) < MAX_DAYS ? { action: "add", from, to } : null;
56
+ }
package/src/words.js ADDED
@@ -0,0 +1,23 @@
1
+ import { cardsOf, findDeck, toWords } from "./library.js";
2
+ import { loadLibrary } from "./store.js";
3
+
4
+ // The words of one library deck, read fresh every time, so cards added from another terminal
5
+ // (with /add) show up at the next question. `deckRef` is a deck name or id; empty = your first own
6
+ // deck, or the tour while you have none.
7
+ export function missingDeck(library, deckRef) {
8
+ const names = library.decks.map((d) => `"${d.name}"`).join(", ");
9
+ return new Error(deckRef ? `There's no deck called "${deckRef}". Your decks: ${names || "none yet"}.` : "Your library has no decks yet.");
10
+ }
11
+
12
+ export async function loadWords(deckRef) {
13
+ const library = await loadLibrary();
14
+ const deck = deckRef ? findDeck(library, deckRef) : (library.decks.find((d) => !d.tour) ?? library.decks[0]);
15
+ if (!deck) throw missingDeck(library, deckRef);
16
+ return { words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, languages: deck.languages, directions: deck.directions, tour: Boolean(deck.tour) } };
17
+ }
18
+
19
+ // every deck of yours (not the tour), for "is anything still waiting today?"
20
+ export async function loadAllWords() {
21
+ const library = await loadLibrary();
22
+ return library.decks.filter((deck) => !deck.tour).map((deck) => ({ words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, directions: deck.directions } }));
23
+ }