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.
- package/LICENSE +202 -0
- package/NOTICE +10 -0
- package/README.md +78 -2
- package/assets/sounds/ask.wav +0 -0
- package/assets/sounds/badge.wav +0 -0
- package/assets/sounds/close.wav +0 -0
- package/assets/sounds/combo.wav +0 -0
- package/assets/sounds/correct-0.wav +0 -0
- package/assets/sounds/correct-1.wav +0 -0
- package/assets/sounds/correct-2.wav +0 -0
- package/assets/sounds/correct-3.wav +0 -0
- package/assets/sounds/correct-4.wav +0 -0
- package/assets/sounds/correct-5.wav +0 -0
- package/assets/sounds/evolve.wav +0 -0
- package/assets/sounds/goal.wav +0 -0
- package/assets/sounds/wrong.wav +0 -0
- package/data/tips.json +1362 -0
- package/package.json +47 -4
- package/src/alerts.js +37 -0
- package/src/anki.js +36 -0
- package/src/cli.js +116 -0
- package/src/commands.js +28 -0
- package/src/dates.js +15 -0
- package/src/demo.js +11 -0
- package/src/diff.js +46 -0
- package/src/hint.js +12 -0
- package/src/judge.js +57 -0
- package/src/parse.js +42 -0
- package/src/progress.js +363 -0
- package/src/quiet.js +32 -0
- package/src/scheduler.js +82 -0
- package/src/session.js +129 -0
- package/src/settings.js +43 -0
- package/src/store.js +61 -0
- package/src/tips.js +47 -0
- package/src/ui/AnswerInput.js +82 -0
- package/src/ui/App.js +369 -0
- package/src/ui/Badges.js +64 -0
- package/src/ui/Companion.js +60 -0
- package/src/ui/Confetti.js +46 -0
- package/src/ui/Evolution.js +58 -0
- package/src/ui/Hatch.js +99 -0
- package/src/ui/Header.js +116 -0
- package/src/ui/Mascot.js +128 -0
- package/src/ui/Missed.js +52 -0
- package/src/ui/Preview.js +181 -0
- package/src/ui/Settings.js +65 -0
- package/src/ui/Stats.js +108 -0
- package/src/ui/Summary.js +34 -0
- package/src/ui/Tip.js +25 -0
- package/src/ui/icons.js +209 -0
- package/src/ui/kit.js +63 -0
- package/src/vacation.js +51 -0
- package/src/words.js +16 -0
package/src/ui/kit.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { Text } 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
|
+
track: "#3a3f47"
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// every full-width panel (card, stats, settings…) shares this width
|
|
17
|
+
export const PANEL_WIDTH = 72;
|
|
18
|
+
|
|
19
|
+
// A thin line: the filled part in `color`, the rest as a dim track. Plain box-drawing characters render
|
|
20
|
+
// at exactly one cell in every terminal font, unlike the geometric-shape glyphs a font may substitute.
|
|
21
|
+
export function Bar({ value, max, width = 10, color = theme.accent }) {
|
|
22
|
+
const filled = max > 0 ? Math.round(width * Math.min(value / max, 1)) : 0;
|
|
23
|
+
return html`<${Text}><${Text} color=${color}>${"━".repeat(filled)}<//><${Text} color=${theme.track}>${"━".repeat(width - filled)}<//><//>`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Like Bar, but the fill slides to its new value one cell at a time instead of jumping.
|
|
27
|
+
export function AnimatedBar({ value, max, width = 10, color = theme.accent, stepMs = 45 }) {
|
|
28
|
+
const target = max > 0 ? Math.round(width * Math.min(value / max, 1)) : 0;
|
|
29
|
+
const [filled, setFilled] = useState(0);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const id = setInterval(() => {
|
|
32
|
+
setFilled((f) => {
|
|
33
|
+
if (f === target) {
|
|
34
|
+
clearInterval(id);
|
|
35
|
+
return f;
|
|
36
|
+
}
|
|
37
|
+
return f + Math.sign(target - f);
|
|
38
|
+
});
|
|
39
|
+
}, stepMs);
|
|
40
|
+
return () => clearInterval(id);
|
|
41
|
+
}, [target, stepMs]);
|
|
42
|
+
return html`<${Text}><${Text} color=${color}>${"━".repeat(filled)}<//><${Text} color=${theme.track}>${"━".repeat(Math.max(0, width - filled))}<//><//>`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Text that types itself in. The hidden tail is padded with spaces so the layout doesn't jump while typing.
|
|
46
|
+
export function Typewriter({ text, dimColor = false, color, charsPerTick = 2, tickMs = 30 }) {
|
|
47
|
+
const [shown, setShown] = useState(0);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
setShown(0);
|
|
50
|
+
const id = setInterval(() => {
|
|
51
|
+
setShown((n) => {
|
|
52
|
+
if (n >= text.length) {
|
|
53
|
+
clearInterval(id);
|
|
54
|
+
return n;
|
|
55
|
+
}
|
|
56
|
+
return n + charsPerTick;
|
|
57
|
+
});
|
|
58
|
+
}, tickMs);
|
|
59
|
+
return () => clearInterval(id);
|
|
60
|
+
}, [text, charsPerTick, tickMs]);
|
|
61
|
+
const visible = text.slice(0, shown);
|
|
62
|
+
return html`<${Text} color=${color} dimColor=${dimColor}>${shown >= text.length ? text : visible + " ".repeat(text.length - visible.length)}<//>`;
|
|
63
|
+
}
|
package/src/vacation.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
// "/vacation" arguments → { 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
|
+
const [from, to] = a <= b ? [a, b] : [b, a];
|
|
50
|
+
return daysBetween(from, to) < MAX_DAYS ? { action: "add", from, to } : null;
|
|
51
|
+
}
|
package/src/words.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fetchNotes } from "./anki.js";
|
|
2
|
+
import { parseNotes } from "./parse.js";
|
|
3
|
+
import { loadWordsCache, saveWordsCache } from "./store.js";
|
|
4
|
+
|
|
5
|
+
// words come from Anki; if it's closed, fall back to the last successful read
|
|
6
|
+
export async function loadWords(deck) {
|
|
7
|
+
try {
|
|
8
|
+
const { words, skipped } = parseNotes(await fetchNotes(deck));
|
|
9
|
+
await saveWordsCache(deck, words);
|
|
10
|
+
return { words, skipped, cached: false };
|
|
11
|
+
} catch (err) {
|
|
12
|
+
const cache = await loadWordsCache();
|
|
13
|
+
if (cache?.deck === deck && cache.words.length) return { words: cache.words, skipped: 0, cached: true };
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|