dracosh 0.1.0 → 0.3.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.
- package/README.md +49 -22
- package/assets/sounds/badge-1.wav +0 -0
- package/assets/sounds/badge-2.wav +0 -0
- package/assets/sounds/badge-3.wav +0 -0
- package/assets/sounds/badge-4.wav +0 -0
- package/locales/de.json +1046 -0
- package/locales/en.json +1029 -0
- package/locales/fr.json +1094 -0
- package/locales/pl.json +1117 -0
- package/locales/uk.json +1118 -0
- package/package.json +2 -2
- package/src/alerts.js +7 -4
- package/src/backup.js +96 -0
- package/src/cardline.js +71 -0
- package/src/cli.js +106 -38
- package/src/commands.js +15 -13
- package/src/demo.js +11 -0
- package/src/diff.js +13 -7
- package/src/i18n.js +68 -0
- package/src/judge.js +51 -12
- package/src/library.js +154 -0
- package/src/lock.js +64 -0
- package/src/manage.js +165 -0
- package/src/pause.js +22 -0
- package/src/progress.js +202 -93
- package/src/quiet.js +4 -3
- package/src/scheduler.js +39 -30
- package/src/session.js +181 -33
- package/src/settings.js +15 -13
- package/src/starter.js +47 -0
- package/src/store.js +58 -17
- package/src/tips.js +17 -25
- package/src/ui/AddCard.js +496 -0
- package/src/ui/AnswerInput.js +28 -13
- package/src/ui/App.js +360 -89
- package/src/ui/BadgeUnlock.js +51 -0
- package/src/ui/Badges.js +79 -20
- package/src/ui/Choice.js +38 -0
- package/src/ui/Companion.js +24 -39
- package/src/ui/Confetti.js +2 -2
- package/src/ui/Decks.js +99 -0
- package/src/ui/DieRoll.js +104 -0
- package/src/ui/Evolution.js +11 -10
- package/src/ui/Hatch.js +9 -7
- package/src/ui/Header.js +62 -19
- package/src/ui/Help.js +74 -0
- package/src/ui/Mascot.js +89 -40
- package/src/ui/Missed.js +15 -13
- package/src/ui/Preview.js +123 -29
- package/src/ui/Reset.js +71 -0
- package/src/ui/Settings.js +34 -23
- package/src/ui/Stats.js +28 -24
- package/src/ui/Summary.js +18 -10
- package/src/ui/TheOne.js +122 -0
- package/src/ui/icons.js +156 -25
- package/src/ui/kit.js +87 -2
- package/src/vacation.js +9 -3
- package/src/words.js +22 -14
- package/assets/sounds/badge.wav +0 -0
- package/data/tips.json +0 -1362
- package/src/ui/Tip.js +0 -25
package/src/ui/TheOne.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { t } from "../i18n.js";
|
|
2
|
+
import React, { Fragment, useEffect, useState } from "react";
|
|
3
|
+
import { Box, useInput } from "ink";
|
|
4
|
+
import { RING } from "./icons.js";
|
|
5
|
+
import { html, KeyHints, Text, theme, usePanelWidth } from "./kit.js";
|
|
6
|
+
|
|
7
|
+
const FRAME_MS = 110;
|
|
8
|
+
const WIDTH = 16; // pixels; each is drawn two characters wide
|
|
9
|
+
const HEIGHT = 15;
|
|
10
|
+
const LAVA_TOP = 11; // first row of lava; the ring is hidden wherever it's below this
|
|
11
|
+
const RING_LEFT = 4;
|
|
12
|
+
const RING_REST = 2; // the ring's top row once it's fully out
|
|
13
|
+
|
|
14
|
+
// timeline, in frames: bubbling lava → the ring rises (one row every 2 frames) → it cools → reveal
|
|
15
|
+
const RISE_FROM = 10;
|
|
16
|
+
const RISE_TO = RISE_FROM + (LAVA_TOP - RING_REST) * 2;
|
|
17
|
+
const COOLED_AT = RISE_TO + 6;
|
|
18
|
+
const REVEAL_AT = COOLED_AT + 4;
|
|
19
|
+
|
|
20
|
+
const LAVA = { R: "#9f1d0d", O: "#ea580c", Y: "#fbbf24" };
|
|
21
|
+
// the ring glows while it comes out of the lava, then cools down to gold
|
|
22
|
+
const HEAT = [
|
|
23
|
+
{ G: "#ff7a1a", D: "#c2410c", W: "#fde68a" },
|
|
24
|
+
{ G: "#fbbf24", D: "#d97706", W: "#fef3c7" },
|
|
25
|
+
RING.palette
|
|
26
|
+
];
|
|
27
|
+
const SPARKS = ["✦", "·", "✧", "*"];
|
|
28
|
+
|
|
29
|
+
function lavaColor(x, y, frame) {
|
|
30
|
+
const n = (x * 7 + y * 3 + Math.floor(frame / 2) * 5) % 9;
|
|
31
|
+
if (y === LAVA_TOP && (x + Math.floor(frame / 2)) % 5 === 0) return null; // a wavy surface
|
|
32
|
+
return n < 2 ? LAVA.Y : n < 6 ? LAVA.O : LAVA.R;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// a few bubbles popping just above the surface
|
|
36
|
+
function bubbleColor(x, y, frame) {
|
|
37
|
+
for (const [bx, offset] of [[3, 0], [9, 2], [13, 4]]) {
|
|
38
|
+
const t = (frame + offset) % 6;
|
|
39
|
+
if (x === bx && t < 3 && y === LAVA_TOP - 1 - t) return LAVA.O;
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function ringTop(frame) {
|
|
45
|
+
if (frame < RISE_FROM) return LAVA_TOP + 1; // still fully submerged
|
|
46
|
+
return Math.max(RING_REST, LAVA_TOP - Math.floor((frame - RISE_FROM) / 2));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function heatOf(frame) {
|
|
50
|
+
if (frame < RISE_TO + 2) return HEAT[0];
|
|
51
|
+
return frame < COOLED_AT ? HEAT[1] : HEAT[2];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// → rows of colors (null = empty) for one frame
|
|
55
|
+
function scene(frame) {
|
|
56
|
+
const top = ringTop(frame);
|
|
57
|
+
const heat = heatOf(frame);
|
|
58
|
+
return Array.from({ length: HEIGHT }, (_, y) =>
|
|
59
|
+
Array.from({ length: WIDTH }, (_, x) => {
|
|
60
|
+
if (y >= LAVA_TOP) return lavaColor(x, y, frame);
|
|
61
|
+
const ry = y - top;
|
|
62
|
+
const rx = x - RING_LEFT;
|
|
63
|
+
const pixel = RING.grid[ry]?.[rx];
|
|
64
|
+
if (pixel && pixel !== ".") return heat[pixel];
|
|
65
|
+
return bubbleColor(x, y, frame);
|
|
66
|
+
})
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function BigScene({ rows }) {
|
|
71
|
+
return html`
|
|
72
|
+
<${Fragment}>
|
|
73
|
+
${rows.map(
|
|
74
|
+
(row, r) => html`<${Text} key=${r}>${row.map((color, c) => React.createElement(Text, { key: c, color }, color ? "██" : " "))}<//>`
|
|
75
|
+
)}
|
|
76
|
+
<//>
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const sparkleRow = (frame, seed) =>
|
|
81
|
+
Array.from({ length: 30 }, (_, i) => ((i * 7 + seed * 13 + frame * 3) % 11 === 0 ? SPARKS[(i + frame) % SPARKS.length] : " ")).join("");
|
|
82
|
+
|
|
83
|
+
// The ceremony for "The One", the badge for collecting every other badge: a ring rises from the lava.
|
|
84
|
+
// Any key skips to the end; after the reveal, any key closes it.
|
|
85
|
+
export function TheOne({ onClose, play = () => {} }) {
|
|
86
|
+
const panel = usePanelWidth();
|
|
87
|
+
const [frame, setFrame] = useState(0);
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
const id = setInterval(() => setFrame((f) => f + 1), FRAME_MS);
|
|
90
|
+
return () => clearInterval(id);
|
|
91
|
+
}, []);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (frame === RISE_FROM) play("close");
|
|
94
|
+
if (frame === REVEAL_AT) play("evolve");
|
|
95
|
+
}, [frame]);
|
|
96
|
+
|
|
97
|
+
const revealed = frame >= REVEAL_AT;
|
|
98
|
+
useInput(() => (revealed ? onClose() : setFrame(REVEAL_AT)));
|
|
99
|
+
const caption = t(frame < RISE_FROM ? "theOne.stirring" : "theOne.rises");
|
|
100
|
+
|
|
101
|
+
return html`
|
|
102
|
+
<${Fragment}>
|
|
103
|
+
<${Box} flexDirection="column" borderStyle="round" borderColor=${theme.warn} paddingX=${2} paddingY=${1} width=${panel} alignItems="center">
|
|
104
|
+
<${Text} color=${theme.warn}>${revealed ? sparkleRow(frame, 1) : " "}<//>
|
|
105
|
+
<${Box} flexDirection="column" alignItems="center">
|
|
106
|
+
<${BigScene} rows=${scene(frame)} />
|
|
107
|
+
<//>
|
|
108
|
+
<${Box} marginTop=${1} flexDirection="column" alignItems="center">
|
|
109
|
+
${revealed
|
|
110
|
+
? html`
|
|
111
|
+
<${Fragment}>
|
|
112
|
+
<${Text} bold color=${RING.palette.G}>${t("theOne.title")}<//>
|
|
113
|
+
<${Text} dimColor>${t("theOne.line")}<//>
|
|
114
|
+
<//>
|
|
115
|
+
`
|
|
116
|
+
: html`<${Text} dimColor>${caption}<//>`}
|
|
117
|
+
<//>
|
|
118
|
+
<//>
|
|
119
|
+
<${Box} paddingX=${1}><${KeyHints} text=${t(revealed ? "theOne.keysContinue" : "theOne.keysSkip")} /><//>
|
|
120
|
+
<//>
|
|
121
|
+
`;
|
|
122
|
+
}
|
package/src/ui/icons.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BADGES } from "../progress.js";
|
|
2
|
+
import { html, Text } from "./kit.js";
|
|
2
3
|
import { PixelGrid } from "./Mascot.js";
|
|
3
4
|
|
|
4
5
|
// 8×8 pixel icons for the badge groups, drawn with the same half-block technique as the mascot.
|
|
@@ -44,7 +45,7 @@ const ICONS = {
|
|
|
44
45
|
]
|
|
45
46
|
},
|
|
46
47
|
star: {
|
|
47
|
-
palette: { S: "#fbbf24", W: "#fef3c7" },
|
|
48
|
+
palette: { S: "#fbbf24", W: "#fef3c7", R: "#60a5fa" },
|
|
48
49
|
grid: [
|
|
49
50
|
"...S....",
|
|
50
51
|
"..SSS...",
|
|
@@ -89,10 +90,10 @@ const ICONS = {
|
|
|
89
90
|
"..MM..W.",
|
|
90
91
|
".MM.....",
|
|
91
92
|
".MM.....",
|
|
92
|
-
".MM
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
93
|
+
".MM.....",
|
|
94
|
+
".MM.....",
|
|
95
|
+
"..MM..W.",
|
|
96
|
+
"...MMM.."
|
|
96
97
|
]
|
|
97
98
|
},
|
|
98
99
|
calendar: {
|
|
@@ -121,19 +122,6 @@ const ICONS = {
|
|
|
121
122
|
"........"
|
|
122
123
|
]
|
|
123
124
|
},
|
|
124
|
-
arrows: {
|
|
125
|
-
palette: { A: "#4ade80", B: "#9d7cd8" },
|
|
126
|
-
grid: [
|
|
127
|
-
"..A.....",
|
|
128
|
-
".AA.....",
|
|
129
|
-
"AAAAAAA.",
|
|
130
|
-
".AA.....",
|
|
131
|
-
".....BB.",
|
|
132
|
-
".BBBBBBB",
|
|
133
|
-
".....BB.",
|
|
134
|
-
"....B..."
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
125
|
heart: {
|
|
138
126
|
palette: { H: "#f87171", W: "#fecaca" },
|
|
139
127
|
grid: [
|
|
@@ -162,22 +150,72 @@ const ICONS = {
|
|
|
162
150
|
}
|
|
163
151
|
};
|
|
164
152
|
|
|
153
|
+
// the ring for the badge that needs every other one
|
|
154
|
+
ICONS.ring = {
|
|
155
|
+
palette: { G: "#fcd34d", D: "#b45309", W: "#fef9c3" },
|
|
156
|
+
grid: [
|
|
157
|
+
"..GGGG..",
|
|
158
|
+
".GW..GG.",
|
|
159
|
+
"GW....DG",
|
|
160
|
+
"G......G",
|
|
161
|
+
"G......G",
|
|
162
|
+
"GG....DG",
|
|
163
|
+
".GD..DG.",
|
|
164
|
+
"..DDDD.."
|
|
165
|
+
]
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const RING = ICONS.ring;
|
|
169
|
+
|
|
170
|
+
// "Dragon's die": a die showing five
|
|
171
|
+
ICONS.die = {
|
|
172
|
+
palette: { W: "#f4f4f5", D: "#c7c9d1", P: "#2a2440" },
|
|
173
|
+
grid: [
|
|
174
|
+
".WWWWWW.",
|
|
175
|
+
"WPPWWPPW",
|
|
176
|
+
"WPPWWPPW",
|
|
177
|
+
"WWWPPWWD",
|
|
178
|
+
"WWWPPWWD",
|
|
179
|
+
"WPPWWPPD",
|
|
180
|
+
"WPPWWPPD",
|
|
181
|
+
".DDDDDD."
|
|
182
|
+
]
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// what a hidden badge shows until it's won
|
|
186
|
+
ICONS.secret = {
|
|
187
|
+
palette: { Q: "#6b7280" },
|
|
188
|
+
grid: [
|
|
189
|
+
"..QQQQ..",
|
|
190
|
+
".QQ..QQ.",
|
|
191
|
+
".....QQ.",
|
|
192
|
+
"....QQ..",
|
|
193
|
+
"...QQ...",
|
|
194
|
+
"...QQ...",
|
|
195
|
+
"........",
|
|
196
|
+
"...QQ..."
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
|
|
165
200
|
// which icon each badge gets, by badge id
|
|
166
201
|
const ICON_FOR = {
|
|
167
202
|
hello: "trophy",
|
|
168
203
|
"first-steps": "trophy",
|
|
169
204
|
century: "trophy",
|
|
170
|
-
"five-hundred": "trophy",
|
|
171
205
|
thousand: "trophy",
|
|
172
|
-
"
|
|
206
|
+
"five-thousand": "trophy",
|
|
207
|
+
"ten-thousand": "trophy",
|
|
208
|
+
"dragons-hoard": "trophy",
|
|
173
209
|
"on-a-roll": "flame",
|
|
174
210
|
week: "flame",
|
|
175
211
|
fortnight: "flame",
|
|
176
212
|
month: "flame",
|
|
177
213
|
"hundred-days": "flame",
|
|
214
|
+
dragonheart: "flame",
|
|
178
215
|
keeper: "book",
|
|
179
216
|
collector: "book",
|
|
180
217
|
dictionary: "book",
|
|
218
|
+
lexicon: "book",
|
|
181
219
|
explorer: "compass",
|
|
182
220
|
flawless: "star",
|
|
183
221
|
overachiever: "star",
|
|
@@ -195,15 +233,108 @@ const ICON_FOR = {
|
|
|
195
233
|
regular: "calendar",
|
|
196
234
|
machine: "calendar",
|
|
197
235
|
"hundred-club": "calendar",
|
|
198
|
-
"
|
|
236
|
+
"one-ring": "ring",
|
|
237
|
+
"dragons-die": "die"
|
|
199
238
|
};
|
|
200
239
|
|
|
201
240
|
const LOCKED_COLOR = "#4a5058";
|
|
202
241
|
|
|
203
|
-
|
|
242
|
+
// Rank colors for the badge groups that climb (more answers, longer streaks…): the higher, the rarer.
|
|
243
|
+
const TIERS = [
|
|
244
|
+
{ name: "bronze", main: "#d08a4e", shade: "#8a4f1c", light: "#f3c9a0" },
|
|
245
|
+
{ name: "silver", main: "#c9d1d9", shade: "#7d8794", light: "#ffffff" },
|
|
246
|
+
{ name: "gold", main: "#fcd34d", shade: "#b45309", light: "#fef3c7" },
|
|
247
|
+
{ name: "emerald", main: "#34d399", shade: "#047857", light: "#d1fae5" },
|
|
248
|
+
{ name: "diamond", main: "#7dd3fc", shade: "#2b6f99", light: "#e0f2fe" },
|
|
249
|
+
{ name: "amethyst", main: "#c084fc", shade: "#6b21a8", light: "#f3e8ff" },
|
|
250
|
+
{ name: "ruby", main: "#f87171", shade: "#991b1b", light: "#fee2e2" }
|
|
251
|
+
];
|
|
252
|
+
// Badges that share an icon but need telling apart get their own grid: the calendars mark the days
|
|
253
|
+
// each one asks for, from a weekend to a month nearly full; the day badges are a star (no miss),
|
|
254
|
+
// a crown (double the goal) and a medal (a marathon); a heart with a mended crack is a mistake put right.
|
|
255
|
+
const CALENDAR_PAGE = (days) => [".C.CC.C.", "RRRRRRRR", ...days.map((row) => `C${row}C`), "CCCCCCCC", "........"];
|
|
256
|
+
const OWN_GRIDS = {
|
|
257
|
+
weekend: CALENDAR_PAGE(["WWWWWW", "WWWWGG", "WWWWWW", "WWWWGG"]),
|
|
258
|
+
"perfect-week": CALENDAR_PAGE(["WWWWWW", "GGGGGG", "WWWWWW", "WWWWWW"]),
|
|
259
|
+
regular: CALENDAR_PAGE(["GWGGWG", "GGWGGW", "WGGWGG", "WWWWWW"]),
|
|
260
|
+
machine: CALENDAR_PAGE(["GGGGGG", "GGGGWG", "GGGGGG", "GGWWWW"]),
|
|
261
|
+
"hundred-club": CALENDAR_PAGE(["GGGGGG", "GGGGGG", "GGGGGG", "GGGGGG"]),
|
|
262
|
+
overachiever: [
|
|
263
|
+
"........",
|
|
264
|
+
"W..W..W.",
|
|
265
|
+
"S..S..S.",
|
|
266
|
+
"SS.S.SS.",
|
|
267
|
+
"SSSSSSS.",
|
|
268
|
+
"SRSWSRS.",
|
|
269
|
+
"SSSSSSS.",
|
|
270
|
+
"........"
|
|
271
|
+
],
|
|
272
|
+
marathon: [
|
|
273
|
+
"RR....RR",
|
|
274
|
+
".RR..RR.",
|
|
275
|
+
"..RRRR..",
|
|
276
|
+
"..SSSS..",
|
|
277
|
+
".SSWSSS.",
|
|
278
|
+
".SWSSSS.",
|
|
279
|
+
".SSSSSS.",
|
|
280
|
+
"..SSSS.."
|
|
281
|
+
],
|
|
282
|
+
redemption: [
|
|
283
|
+
"........",
|
|
284
|
+
".HH..HH.",
|
|
285
|
+
"HWH.HHHH",
|
|
286
|
+
"HWHH.HHH",
|
|
287
|
+
".HH.HHH.",
|
|
288
|
+
"..HH.H..",
|
|
289
|
+
"...HH...",
|
|
290
|
+
"........"
|
|
291
|
+
]
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// which palette letters of a tiered icon take the tier's main / shade / light color
|
|
295
|
+
const TIER_ROLES = {
|
|
296
|
+
trophy: { G: "main", D: "shade", W: "light" },
|
|
297
|
+
flame: { Y: "main", R: "shade", W: "light" },
|
|
298
|
+
book: { B: "main", D: "shade" },
|
|
299
|
+
bolt: { Y: "main", W: "light" },
|
|
300
|
+
calendar: { R: "main" }
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// the badge's rank within its group, in the order BADGES lists them (easiest first); null if the group isn't tiered
|
|
304
|
+
function tierOf(id) {
|
|
305
|
+
const icon = ICON_FOR[id];
|
|
306
|
+
if (!TIER_ROLES[icon]) return null;
|
|
307
|
+
const group = BADGES.filter((badge) => ICON_FOR[badge.id] === icon).map((badge) => badge.id);
|
|
308
|
+
return TIERS[Math.min(group.indexOf(id), TIERS.length - 1)];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function paletteFor(id, icon) {
|
|
312
|
+
const tier = tierOf(id);
|
|
313
|
+
if (!tier) return icon.palette;
|
|
314
|
+
const roles = TIER_ROLES[ICON_FOR[id]];
|
|
315
|
+
return Object.fromEntries(Object.entries(icon.palette).map(([key, color]) => [key, roles[key] ? tier[roles[key]] : color]));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// the color that stands for an unlocked badge in lists: its rank color, or gold for untiered ones
|
|
319
|
+
export const badgeColor = (id) => tierOf(id)?.main ?? TIERS[2].main;
|
|
320
|
+
|
|
321
|
+
const fillIn = (row) => row.replace(/(?<=[^.].*)\.(?=.*[^.])/g, "G");
|
|
322
|
+
|
|
323
|
+
// `locked` greys the icon out; `flash` whites it out (a frame of a badge lighting up in /badges);
|
|
324
|
+
// `secret` replaces a hidden badge that isn't won yet with a question mark
|
|
325
|
+
export function BadgeIcon({ id, locked = false, flash = false, secret = false }) {
|
|
326
|
+
if (secret) return html`<${PixelGrid} grid=${ICONS.secret.grid.map((row) => [...row])} palette=${ICONS.secret.palette} />`;
|
|
204
327
|
const icon = ICONS[ICON_FOR[id]] ?? ICONS.star;
|
|
205
|
-
const
|
|
206
|
-
|
|
328
|
+
const flat = (color) => Object.fromEntries(Object.keys(icon.palette).map((k) => [k, color]));
|
|
329
|
+
const palette = flash ? flat("#ffffff") : locked ? flat(LOCKED_COLOR) : paletteFor(id, icon);
|
|
330
|
+
// a locked ring is drawn filled in, so its silhouette doesn't give away what it is
|
|
331
|
+
const own = OWN_GRIDS[id] ?? icon.grid;
|
|
332
|
+
const grid = locked && !flash && id === "one-ring" ? own.map(fillIn) : own;
|
|
333
|
+
return html`<${PixelGrid} grid=${grid.map((row) => [...row])} palette=${palette} />`;
|
|
207
334
|
}
|
|
208
335
|
|
|
336
|
+
// The streak flame: a small triangle in fire orange, the height of the letters next to it.
|
|
337
|
+
// (Pixel blocks fill the whole line height and look too big beside text.)
|
|
338
|
+
export const Flame = () => html`<${Text} color="#f97316">▴<//>`;
|
|
339
|
+
|
|
209
340
|
export const ICON_WIDTH = 8;
|
package/src/ui/kit.js
CHANGED
|
@@ -1,20 +1,105 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Text } from "ink";
|
|
1
|
+
import React, { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
import { Text as InkText, Transform, useStdout } from "ink";
|
|
3
3
|
import htm from "htm";
|
|
4
|
+
import { t } from "../i18n.js";
|
|
4
5
|
|
|
5
6
|
export const html = htm.bind(React.createElement);
|
|
6
7
|
|
|
8
|
+
// Ink wraps with wrap-ansi and keeps the spaces, so when a word ends exactly at the edge, the space
|
|
9
|
+
// after it starts the next line (" elle viendra…"). In a text without line breaks of its own, any
|
|
10
|
+
// line after the first comes from wrapping, and a space at its start is that leftover: it goes.
|
|
11
|
+
// A space painted inverse or on a background (the answer line's cursor) is something to see: it stays.
|
|
12
|
+
const unspill = (line, index) => {
|
|
13
|
+
if (index === 0) return line;
|
|
14
|
+
const [, codes, space] = /^((?:\x1b\[[\d;]*m)*)(\s*)/.exec(line);
|
|
15
|
+
return !space || /\x1b\[(?:7|4\d|10\d)[;m]/.test(codes) ? line : codes + line.slice(codes.length + space.length);
|
|
16
|
+
};
|
|
17
|
+
const InsideText = createContext(false);
|
|
18
|
+
const hasLineBreak = (node) =>
|
|
19
|
+
typeof node === "string" ? node.includes("\n") : Array.isArray(node) ? node.some(hasLineBreak) : Boolean(node?.props) && hasLineBreak(node.props.children);
|
|
20
|
+
|
|
21
|
+
// Ink's Text, minus that space. Only the outermost Text wraps, so only it gets the fix; a Text that
|
|
22
|
+
// truncates instead of wrapping, or has line breaks of its own (indentation may follow them), is
|
|
23
|
+
// left as it is. Every UI file takes Text from here.
|
|
24
|
+
export function Text(props) {
|
|
25
|
+
const nested = useContext(InsideText);
|
|
26
|
+
const text = React.createElement(InkText, props);
|
|
27
|
+
if (nested || (props.wrap && props.wrap !== "wrap") || hasLineBreak(props.children)) return text;
|
|
28
|
+
return React.createElement(InsideText.Provider, { value: true }, React.createElement(Transform, { transform: unspill }, text));
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
// Dracosh palette: soft violet accents and a green dragon on dark, gold for fire and glory
|
|
8
32
|
export const theme = {
|
|
9
33
|
accent: "#9d7cd8",
|
|
10
34
|
good: "#4ade80",
|
|
11
35
|
bad: "#f87171",
|
|
12
36
|
warn: "#fbbf24",
|
|
37
|
+
text: "#c9ccd3",
|
|
38
|
+
hint: "#8b919c", // the words in key hints: quieter than text, easier to read than dim
|
|
13
39
|
track: "#3a3f47"
|
|
14
40
|
};
|
|
15
41
|
|
|
42
|
+
// Text where `backticks` mark something to type: shown in the accent color on a faint violet
|
|
43
|
+
// background, like code in docs. Used for the tour's cards; `plain` shows the text as it is.
|
|
44
|
+
export function Marked({ text, plain = false, ...props }) {
|
|
45
|
+
if (plain) return React.createElement(Text, props, text);
|
|
46
|
+
const parts = text.split(/`([^`]+)`/);
|
|
47
|
+
return React.createElement(
|
|
48
|
+
Text,
|
|
49
|
+
props,
|
|
50
|
+
...parts.map((part, i) => (i % 2 ? React.createElement(Text, { key: i, color: theme.accent, backgroundColor: "#2a2440", bold: true }, part) : part))
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// the key at the start of a hint segment: "enter", "esc", "/add", "↑/↓", "any key", "q"…; the
|
|
55
|
+
// longer key names come from the locale ("échap", "dowolny klawisz")
|
|
56
|
+
const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
57
|
+
const keyPattern = () => new RegExp(`^(${[...t("keyHints.keyNames").split("|").map((name) => escapeRegExp(name).replace(/ /g, "[ \u00a0]")), "↑/↓", "←/→", "\\/\\S*", "[\\p{L}\\d]"].join("|")})(?=[\\s,]|$)`, "u");
|
|
58
|
+
|
|
59
|
+
// A footer like "enter submit · / commands · esc quit": each key stands out, the words after it
|
|
60
|
+
// stay quiet, and the dots between them fade back. A narrow pane wraps it between hints, never
|
|
61
|
+
// between a key and what it does.
|
|
62
|
+
export function KeyHints({ text }) {
|
|
63
|
+
const parts = text.split(" · ").map((part) => part.replace(/ /g, "\u00a0"));
|
|
64
|
+
const KEY = keyPattern();
|
|
65
|
+
return React.createElement(
|
|
66
|
+
Text,
|
|
67
|
+
null,
|
|
68
|
+
...parts.flatMap((part, i) => {
|
|
69
|
+
const key = KEY.exec(part)?.[0];
|
|
70
|
+
const rest = key ? part.slice(key.length) : part;
|
|
71
|
+
return [
|
|
72
|
+
i > 0 && React.createElement(Text, { key: `s${i}`, color: "#5a606b" }, " · "),
|
|
73
|
+
key && React.createElement(Text, { key: `k${i}`, color: theme.text }, key),
|
|
74
|
+
React.createElement(Text, { key: `r${i}`, color: theme.hint }, rest)
|
|
75
|
+
].filter(Boolean);
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
16
80
|
// every full-width panel (card, stats, settings…) shares this width
|
|
17
81
|
export const PANEL_WIDTH = 72;
|
|
82
|
+
const MIN_PANEL_WIDTH = 30;
|
|
83
|
+
|
|
84
|
+
// How many terminal cells text takes: CJK characters and emoji take two. Close enough for labels
|
|
85
|
+
// and deck names; whole characters (not UTF-16 halves) are counted, so an emoji is never cut in two.
|
|
86
|
+
const WIDE = /[\u1100-\u115f\u2e80-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\p{Extended_Pictographic}]/u;
|
|
87
|
+
export const cellWidth = (text) => Array.from(text).reduce((sum, ch) => sum + (WIDE.test(ch) ? 2 : 1), 0);
|
|
88
|
+
export function cutToWidth(text, cells) {
|
|
89
|
+
if (cellWidth(text) <= cells) return text;
|
|
90
|
+
let out = "";
|
|
91
|
+
for (const ch of text) {
|
|
92
|
+
if (cellWidth(out + ch) > cells - 1) break;
|
|
93
|
+
out += ch;
|
|
94
|
+
}
|
|
95
|
+
return `${out}…`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// the panel width for this terminal: PANEL_WIDTH, or less in a narrow window (some terminals report 0)
|
|
99
|
+
export function usePanelWidth() {
|
|
100
|
+
const { stdout } = useStdout();
|
|
101
|
+
return Math.max(MIN_PANEL_WIDTH, Math.min((stdout?.columns || PANEL_WIDTH + 2) - 2, PANEL_WIDTH));
|
|
102
|
+
}
|
|
18
103
|
|
|
19
104
|
// A thin line: the filled part in `color`, the rest as a dim track. Plain box-drawing characters render
|
|
20
105
|
// at exactly one cell in every terminal font, unlike the geometric-shape glyphs a font may substitute.
|
package/src/vacation.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { addDays, daysBetween } from "./dates.js";
|
|
2
|
+
import { dateLocale } from "./i18n.js";
|
|
2
3
|
|
|
3
4
|
const MAX_DAYS = 120; // a typo like "2062" shouldn't switch the streak off for years
|
|
4
5
|
|
|
5
|
-
export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString(
|
|
6
|
+
export const formatDay = (key) => new Date(`${key}T12:00:00`).toLocaleDateString(dateLocale(), { day: "numeric", month: "short" });
|
|
6
7
|
export const formatRange = (from, to) => (from === to ? formatDay(from) : `${formatDay(from)} – ${formatDay(to)}`);
|
|
7
8
|
|
|
8
9
|
// a real calendar date as "YYYY-MM-DD", or null ("31.02" and the like)
|
|
@@ -25,7 +26,7 @@ function parseDate(text, today) {
|
|
|
25
26
|
return key && key < today ? valid(`${thisYear + 1}-${pad(month)}-${pad(day)}`) : key;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
//
|
|
29
|
+
// days-off arguments (see /pause in pause.js) → { action: "list" } | { action: "off" } | { action: "add", from, to } | null (not understood)
|
|
29
30
|
// "" list what is planned
|
|
30
31
|
// "off" cancel current and future vacations
|
|
31
32
|
// "7" / "7d" 7 days starting today
|
|
@@ -46,6 +47,11 @@ export function parseVacation(args, today) {
|
|
|
46
47
|
const dates = parts.map((part) => parseDate(part, today));
|
|
47
48
|
if (dates.some((date) => !date)) return null;
|
|
48
49
|
const [a, b = a] = dates;
|
|
49
|
-
|
|
50
|
+
// A day and month without a year means the next one to come, so a range that already started
|
|
51
|
+
// ("28.12 3.01" on 30 December, "24.12 2.01" on New Year's Day) gets its start back a year.
|
|
52
|
+
// Of the readings that make sense, the shortest wins; a reversed range is read the other way round.
|
|
53
|
+
const back = (key, part) => (/^\d{1,2}\.\d{1,2}$/.test(part) ? valid(`${Number(key.slice(0, 4)) - 1}${key.slice(4)}`) : null);
|
|
54
|
+
const readings = [[a, b], [back(a, parts[0]), b], [b, a]].filter(([x, y]) => x && y && x <= y);
|
|
55
|
+
const [from, to] = readings.sort(([x1, y1], [x2, y2]) => daysBetween(x1, y1) - daysBetween(x2, y2))[0];
|
|
50
56
|
return daysBetween(from, to) < MAX_DAYS ? { action: "add", from, to } : null;
|
|
51
57
|
}
|
package/src/words.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { t } from "./i18n.js";
|
|
2
|
+
import { cardsOf, findDeck, toWords } from "./library.js";
|
|
3
|
+
import { loadLibrary } from "./store.js";
|
|
4
4
|
|
|
5
|
-
// words
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
// The words of one library deck, read fresh every time, so cards added from another terminal
|
|
6
|
+
// (with /add) show up at the next question. `deckRef` is a deck name or id; empty = your first own
|
|
7
|
+
// deck, or the tour while you have none.
|
|
8
|
+
export function missingDeck(library, deckRef) {
|
|
9
|
+
const names = library.decks.map((d) => `"${d.name}"`).join(", ");
|
|
10
|
+
return new Error(deckRef ? t("errors.noDeck", { deck: deckRef, decks: names || t("errors.noDecksYet") }) : t("errors.emptyLibrary"));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function loadWords(deckRef) {
|
|
14
|
+
const library = await loadLibrary();
|
|
15
|
+
const deck = deckRef ? findDeck(library, deckRef) : (library.decks.find((d) => !d.tour) ?? library.decks[0]);
|
|
16
|
+
if (!deck) throw missingDeck(library, deckRef);
|
|
17
|
+
return { words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, languages: deck.languages, directions: deck.directions, tour: Boolean(deck.tour) } };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// every deck of yours (not the tour), for "is anything still waiting today?"
|
|
21
|
+
export async function loadAllWords() {
|
|
22
|
+
const library = await loadLibrary();
|
|
23
|
+
return library.decks.filter((deck) => !deck.tour).map((deck) => ({ words: toWords(cardsOf(library, deck.id)), deck: { name: deck.name, directions: deck.directions } }));
|
|
16
24
|
}
|
package/assets/sounds/badge.wav
DELETED
|
Binary file
|