dracosh 0.3.0 → 0.4.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/src/session.js CHANGED
@@ -1,27 +1,35 @@
1
1
  import { t as say } from "./i18n.js"; // `t` and `text` are taken here (the clock, an answer)
2
- import { blankGap } from "./cardline.js";
3
- import { closestCandidate, judge } from "./judge.js";
4
- import { addVacation, applyAnswer, applyCaughtUp, applyOverrule, calendarMonth, cancelVacations, ensureProgress, markBadgesSeen, missedOn, recordMiss, snapshot, undoMiss, unseenBadges, vacationInfo } from "./progress.js";
5
- import { describeDue, grade, itemKey, nextDueAt, pickNext, startOfTomorrow } from "./scheduler.js";
2
+ import { blankGap, plainFront } from "./cardline.js";
3
+ import { ALMOST, closestCandidate, judge } from "./judge.js";
4
+ import { addVacation, applyAnswer, applyCaughtUp, markWorkWaiting, applyOverrule, calendarMonth, cancelVacations, ensureProgress, markBadgesSeen, missedOn, recordMiss, snapshot, undoMiss, unseenBadges, vacationInfo } from "./progress.js";
5
+ import { BOX_INTERVALS_DAYS, describeDue, grade, itemKey, nextDueAt, pickNext, startOfTomorrow } from "./scheduler.js";
6
6
  import { recordAnswer, saveState } from "./store.js";
7
7
  import { createTipDeck } from "./tips.js";
8
8
  import { dayKey } from "./dates.js";
9
9
  import { parsePause } from "./pause.js";
10
10
  import { formatRange } from "./vacation.js";
11
11
 
12
- const LABELS = { "en-pl": "EN → PL", "pl-en": "PL → EN" };
13
12
 
14
- // the tag on the card's border: the language pair for a language deck, the deck's name otherwise
15
- function labelOf(deck, direction) {
16
- if (!deck) return LABELS[direction] ?? "";
17
- if (direction.startsWith("c")) return deck.name; // a cloze gap: no direction to show
18
- if (!deck.languages) return deck.name;
19
- const { front, back } = deck.languages;
20
- const [from, to] = direction === "en-pl" ? [front, back] : [back, front];
21
- return `${from.toUpperCase()} → ${to.toUpperCase()}`;
13
+ // the tag on the card's border: the deck's name (language codes like "DE → UK" read as countries)
14
+ function labelOf(deck) {
15
+ return deck?.name ?? "";
22
16
  }
23
17
  const COMBO_CHEER_EVERY = 5;
24
18
 
19
+ // Pronunciation reads the side in the language you're learning in this deck (learningSide), whichever way
20
+ // the card asks: the answer (a cloze card: its whole sentence), or the question. Nothing in a deck that
21
+ // isn't for a language. `answer`: the right answer you gave (one of several), read instead of the first.
22
+ export function toSpeak(question, answer = null) {
23
+ const lang = question.learningLanguage;
24
+ if (question.tour || !lang) return null;
25
+ const cloze = question.direction.startsWith("c");
26
+ const given = answer && question.expected.includes(answer) ? answer : question.expected[0];
27
+ if (question.answerLanguage === lang) return { text: cloze ? plainFront(question.word.word) : given, lang };
28
+ // a cloze card's prompt is its sentence with a gap: nothing to read there
29
+ if (!cloze && question.promptLanguage === lang) return { text: question.prompt.split(" / ")[0], lang };
30
+ return null;
31
+ }
32
+
25
33
  // Quiz logic without any I/O of its own: words, settings and persistence are injected, the UI only renders what this returns.
26
34
  // `loadAllWords` → [{ words, deck }] for every deck of yours: "all done for today" means the whole library.
27
35
  export function createSession({ loadWords, loadAllWords, state, getSettings, save = saveState, now = Date.now, tipDeck = createTipDeck({ state }) }) {
@@ -36,13 +44,18 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
36
44
  async function settleDay() {
37
45
  const decks = loadAllWords ? await loadAllWords() : [current].filter((d) => !d.deck?.tour);
38
46
  const t = now();
47
+ let nextDue = null;
39
48
  for (const { words, deck } of decks) {
40
49
  const directions = directionsOf(deck);
41
- if (pickNext({ words, state, now: t, directions })) return { done: false, cheers: [] };
50
+ if (pickNext({ words, state, now: t, directions })) {
51
+ markWorkWaiting(ensureProgress(state, t), dayKey(t));
52
+ return { done: false, cheers: [] };
53
+ }
42
54
  const due = nextDueAt({ words, state, now: t, directions });
43
55
  if (due !== null && due < startOfTomorrow(t)) return { done: false, cheers: [] };
56
+ if (due !== null && (nextDue === null || due < nextDue)) nextDue = due;
44
57
  }
45
- const { cheers } = applyCaughtUp(state, { goal: getSettings().dailyGoal, rules: rules(), now: t });
58
+ const { cheers } = applyCaughtUp(state, { goal: getSettings().dailyGoal, rules: rules(), now: t, nextDue });
46
59
  await save(state);
47
60
  return { done: true, cheers };
48
61
  }
@@ -59,10 +72,13 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
59
72
  current = { words, deck };
60
73
  inTour = Boolean(deck?.tour);
61
74
  const item = pickNext({ words, state, now: now(), lastNoteId, directions: directionsOf(deck), tour: deck?.tour });
75
+ if (item && !deck?.tour) markWorkWaiting(ensureProgress(state, now()), dayKey(now())); // not a rest day after all
62
76
  // nothing to ask is a normal state, not an error: the UI shows a way on (a finished tour, a new
63
77
  // deck) or when the next card is due. Done with everything for today counts as the daily goal.
64
78
  if (!item) {
65
- const empty = { empty: true, tour: Boolean(deck?.tour), count: words.length, nextDue: null, cheers: [], dayDone: false };
79
+ // new cards held back by the daily limit, so "all done" doesn't hide them
80
+ const heldNew = deck?.tour ? 0 : words.filter((word) => !(word.directions ?? directionsOf(deck)).some((d) => state.items[itemKey(word.noteId, d)])).length;
81
+ const empty = { empty: true, tour: Boolean(deck?.tour), count: words.length, nextDue: null, cheers: [], dayDone: false, heldNew };
66
82
  if (!deck?.tour && words.length) {
67
83
  empty.nextDue = nextDueAt({ words, state, now: now(), directions: directionsOf(deck) });
68
84
  const day = await settleDay();
@@ -86,11 +102,15 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
86
102
  return {
87
103
  word: item.word,
88
104
  direction: item.direction,
89
- label: labelOf(deck, item.direction),
105
+ label: labelOf(deck),
90
106
  prompt,
91
107
  expected,
92
108
  // a cloze card's back is a hint under the sentence ("Cieszę się na to")
93
109
  context: gap !== null ? item.word.translations.join(" / ") : "",
110
+ // what the answer is written in, when the deck's languages are known: its own spellings count
111
+ answerLanguage: (forward ? deck?.languages?.back : deck?.languages?.front) ?? null,
112
+ promptLanguage: (forward ? deck?.languages?.front : deck?.languages?.back) ?? null,
113
+ learningLanguage: deck?.learning?.lang ?? null,
94
114
  wordCount: words.length,
95
115
  tour: Boolean(deck?.tour) // the tour marks what to type with `backticks`
96
116
  };
@@ -107,7 +127,7 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
107
127
  async function answer(question, text, { hinted = false } = {}) {
108
128
  const key = itemKey(question.word.noteId, question.direction);
109
129
  // answers you once declared right (/correct) count for this card from now on
110
- const result = judge(text, [...question.expected, ...(state.accepted?.[key] ?? [])]);
130
+ const result = judge(text, [...question.expected, ...(state.accepted?.[key] ?? [])], { lang: question.answerLanguage, otherLang: question.promptLanguage, learning: question.learningLanguage ?? null });
111
131
  return record(question, { result, text, hinted });
112
132
  }
113
133
 
@@ -126,7 +146,11 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
126
146
  const t = now();
127
147
  const before = state.items[key];
128
148
  const comboBefore = totals.combo;
129
- const entry = grade(before, correct, t, { hinted });
149
+ // almost right (an article left out, an umlaut left plain) counts, but the card doesn't move up, like with a hint
150
+ const almost = ALMOST.includes(result);
151
+ const entry = grade(before, correct, t, { hinted: hinted || almost });
152
+ const would = almost ? grade(before, true, t, { hinted }) : entry; // a hint alone would have held it too
153
+ const held = would.box > entry.box ? { days: BOX_INTERVALS_DAYS[entry.box - 1], would: BOX_INTERVALS_DAYS[would.box - 1] } : null;
130
154
  recordAnswer(state, question.word.noteId, question.direction, entry, t, { countNew: !question.tour });
131
155
 
132
156
  totals.asked += 1;
@@ -145,8 +169,8 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
145
169
  // the last card of the day settles it right away, so quitting now doesn't lose the goal
146
170
  if (!question.tour) cheers.push(...(await settleDay()).cheers);
147
171
  // given/closest feed the per-letter diff the UI shows after a miss or a forgiven typo
148
- const closest = result === "exact" || !text ? null : closestCandidate(text, [...question.expected, ...(state.accepted?.[key] ?? [])]);
149
- return { result, hinted: hinted && correct, dueIn: describeDue(entry, t), combo: totals.combo, cheers, given: text, closest, nextDue: upNext() };
172
+ const closest = result === "exact" || !text ? null : closestCandidate(text, [...question.expected, ...(state.accepted?.[key] ?? [])], { lang: question.answerLanguage });
173
+ return { result, held, hinted: hinted && correct, dueIn: describeDue(entry, t), combo: totals.combo, cheers, given: text, closest, nextDue: upNext() };
150
174
  }
151
175
 
152
176
  // Re-grade the last wrong answer as correct and remember the answer for this card.
@@ -273,5 +297,13 @@ export function createSession({ loadWords, loadAllWords, state, getSettings, sav
273
297
  return fresh;
274
298
  }
275
299
 
276
- return { totals, next, answer, reveal, selfGrade, setDirections, forgetKeys, overrule, canOverrule, wrongAnswer, stats, month, missed, nextTip, pause, isFirstRun, markHatched, openBadges, forget, reset, inTour: () => inTour };
300
+ // cards added (or a direction switched on): there's work today, whether or not it's asked yet, so a
301
+ // quiet stretch ends here
302
+ async function workAdded() {
303
+ markWorkWaiting(ensureProgress(state, now()), dayKey(now()));
304
+ await save(state);
305
+ await settleDay(); // nothing askable after all (a direction switched off): the quiet stretch goes on
306
+ }
307
+
308
+ return { totals, next, answer, workAdded, reveal, selfGrade, setDirections, forgetKeys, overrule, canOverrule, wrongAnswer, stats, month, missed, nextTip, pause, isFirstRun, markHatched, openBadges, forget, reset, inTour: () => inTour };
277
309
  }
package/src/settings.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { LANGUAGES, systemLanguage, t } from "./i18n.js";
2
2
 
3
- export const DEFAULTS = { everyMs: 600_000, rhythm: "minutes", sound: true, volume: 0.5, dailyGoal: 20, tips: "sometimes", quiet: null, skipWeekends: true, deck: null };
3
+ export const DEFAULTS = { everyMs: 600_000, rhythm: "minutes", sound: true, speak: false, volume: 0.5, dailyGoal: 20, tips: "sometimes", quiet: null, skipWeekends: true, deck: null };
4
4
 
5
5
  export const INTERVALS = [60_000, 120_000, 300_000, 600_000, 900_000, 1_200_000, 1_800_000, 2_700_000, 3_600_000];
6
6
  export const GOALS = [5, 10, 15, 20, 25, 30, 40, 50, 75, 100, 150, 200];
@@ -33,6 +33,7 @@ export function normalizeSettings(raw = {}) {
33
33
  everyMs: isNumber(raw.everyMs) && raw.everyMs >= 1000 ? raw.everyMs : DEFAULTS.everyMs,
34
34
  rhythm: RHYTHMS.includes(raw.rhythm) ? raw.rhythm : DEFAULTS.rhythm,
35
35
  sound: typeof raw.sound === "boolean" ? raw.sound : DEFAULTS.sound,
36
+ speak: typeof raw.speak === "boolean" ? raw.speak : DEFAULTS.speak,
36
37
  volume: isNumber(raw.volume) && raw.volume >= 0 && raw.volume <= 1 ? raw.volume : DEFAULTS.volume,
37
38
  dailyGoal: isNumber(raw.dailyGoal) && raw.dailyGoal >= 1 ? Math.round(raw.dailyGoal) : DEFAULTS.dailyGoal,
38
39
  tips: normalizeTips(raw.tips),
package/src/store.js CHANGED
@@ -82,7 +82,8 @@ export const saveState = (state) => writeJson(STATE_FILE, state);
82
82
  // `countNew: false` keeps a card out of the daily cap on new cards (the tour's don't use it up)
83
83
  export function recordAnswer(state, noteId, direction, entry, now = Date.now(), { countNew = true } = {}) {
84
84
  const key = itemKey(noteId, direction);
85
- const isNew = countNew && !state.items[key];
85
+ // a new card counts once towards the daily limit, whichever way it's asked first
86
+ const isNew = countNew && !state.items[key] && !Object.keys(state.items).some((k) => k.startsWith(`${noteId}:`));
86
87
  const date = dayKey(now);
87
88
  state.items[key] = entry;
88
89
  if (isNew) state.newToday = { date, count: newToday(state, now) + 1 };
package/src/ui/AddCard.js CHANGED
@@ -3,6 +3,8 @@ import { Box, useInput } from "ink";
3
3
  import { MAX_DECK_NAME, typedSides } from "../library.js";
4
4
  import { blankGap, formatLine, gapsOf, parseBack, parseLine, plainFront } from "../cardline.js";
5
5
  import { normalize } from "../judge.js";
6
+ import { isKnown, languageName } from "../language.js";
7
+ import { LanguagePicker, pairText } from "./Languages.js";
6
8
  import { AnswerInput } from "./AnswerInput.js";
7
9
  import { Choice, choiceHints } from "./Choice.js";
8
10
  import { t } from "../i18n.js";
@@ -144,13 +146,32 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
144
146
  if (deck.isNew && !card.cloze) {
145
147
  setDirection(0);
146
148
  setSample(card);
149
+ setLangs(null);
150
+ actions.languagesOf(deck.name).then((found) => {
151
+ setLangs(found);
152
+ shownPair.current = pairText(found);
153
+ }, () => {});
147
154
  picking.current = false;
148
155
  typedAhead.current = "";
149
156
  return setStep("direction");
150
157
  }
151
158
  setStep("line");
159
+ noticeLanguages();
152
160
  };
153
161
 
162
+ // As cards come in, the guess at the deck's languages firms up: a new guess is said once, so a
163
+ // wrong one doesn't go unnoticed
164
+ const shownPair = useRef(null);
165
+ function noticeLanguages() {
166
+ actions.languagesOf(deck?.name ?? "").then((found) => {
167
+ const pair = pairText(found);
168
+ const tells = isKnown(found.front) && isKnown(found.back);
169
+ // it stays under the field until the next card is saved
170
+ setLanguageNote(found.guessed && tells && shownPair.current !== pair ? pair : "");
171
+ if (tells) shownPair.current = pair;
172
+ }, () => {});
173
+ }
174
+
154
175
  async function save(fields) {
155
176
  if (busy.current) return;
156
177
  busy.current = true;
@@ -253,6 +274,7 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
253
274
  function pickDeck(index) {
254
275
  if (index === decks.length) return setStep("deck");
255
276
  setDeck({ name: decks[index].name, directions: decks[index].directions, isNew: false });
277
+ actions.languagesOf(decks[index].name).then((found) => (shownPair.current = pairText(found)), () => {});
256
278
  clearField();
257
279
  setStep("line");
258
280
  }
@@ -261,6 +283,10 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
261
283
  // choice and go into the field, so nothing typed is lost
262
284
  // Typing the next card right away keeps option 1: the keys wait in `typedAhead` until the field is back.
263
285
  // `picking` stays set for the rest of the step, so a key that lands while the pick saves can't pick again.
286
+ const [langs, setLangs] = useState(null); // the new deck's languages, as guessed from its first card
287
+ const [languageNote, setLanguageNote] = useState(""); // a new guess at the deck's languages
288
+ const writes = useRef(Promise.resolve()); // library writes one after another, so none overwrites another
289
+ const inTurn = (write) => (writes.current = writes.current.catch(() => {}).then(write));
264
290
  const typedAhead = useRef("");
265
291
  const picking = useRef(false);
266
292
  const pickedByChoice = useRef(false);
@@ -270,7 +296,7 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
270
296
  picking.current = true;
271
297
  const chosen = ["forward", "backward", "both"][index];
272
298
  try {
273
- await actions.setDirections(deck.name, chosen);
299
+ await inTurn(() => actions.setDirections(deck.name, chosen));
274
300
  setDeck((d) => ({ ...d, directions: chosen, isNew: false }));
275
301
  setMessage(t("add.directionSet", { how: askedAs(sample, chosen) }));
276
302
  } catch (err) {
@@ -323,6 +349,7 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
323
349
  useInput(
324
350
  (input, key) => {
325
351
  if (pickedByChoice.current) return void (pickedByChoice.current = false);
352
+ if (key.rightArrow && langs && !picking.current) return setStep("languages");
326
353
  if (picking.current && (key.backspace || key.delete)) return void (typedAhead.current = typedAhead.current.slice(0, -1));
327
354
  if (!input || key.ctrl || key.meta || key.tab || key.escape || key.return) return;
328
355
  if (!picking.current && /^[1-3]$/.test(input)) return; // Choice's own key
@@ -355,6 +382,19 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
355
382
  { isActive: step === "review" }
356
383
  );
357
384
 
385
+ async function saveLanguages(languages) {
386
+ setStep("direction");
387
+ try {
388
+ const saved = await inTurn(() => actions.setLanguages(deck.name, languages));
389
+ setLangs(saved);
390
+ shownPair.current = pairText(saved);
391
+ } catch (err) {
392
+ setError(err.message);
393
+ }
394
+ }
395
+
396
+ if (step === "languages") return html`<${LanguagePicker} deck=${deck.name} sample=${sample} languages=${langs} learning=${langs.learning} home=${langs.home} onDone=${saveLanguages} onCancel=${() => setStep("direction")} />`;
397
+
358
398
  const title =
359
399
  step === "pick" ? t("add.titlePick") : step === "deck" ? t(decks.length ? "add.titleNew" : "add.titleFirst") : step === "review" || step === "fix" ? t("add.paste.title", { deck: deck.name }) : t("add.titleCard", { deck: deck?.name ?? "" });
360
400
  const fieldLabel = step === "deck" ? "deck" : step === "back" ? "back" : step === "line" || step === "fix" ? "line" : null;
@@ -378,6 +418,7 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
378
418
  <//>
379
419
  `}
380
420
  ${message && html`<${Box} marginTop=${1}><${Text} color=${theme.good}>${message}<//><//>`}
421
+ ${languageNote && step === "line" && html`<${Text} dimColor>${t("add.languagesNow", { pair: languageNote })}<//>`}
381
422
  ${step === "back" && draft && html`<${Box} marginTop=${1}><${Text} dimColor>${draft.front} =<//><//>`}
382
423
  ${fieldLabel &&
383
424
  html`
@@ -436,7 +477,10 @@ export function AddCard({ current, actions, onDone, startNew = false }) {
436
477
  }}
437
478
  />
438
479
  <//>
439
- <${Box} marginTop=${1}><${Text} dimColor>${t("add.directionLater")}<//><//>
480
+ ${langs && html`<${Box} marginTop=${1}><${Text} dimColor>${isKnown(langs.front) || isKnown(langs.back) ? t("add.languagesLine", { pair: pairText(langs) }) : t("add.languagesSoon")}<//><//>`}
481
+ ${langs?.learning && html`<${Text} color=${langs.learning.sure ? undefined : theme.warn} dimColor=${langs.learning.sure}>${t("add.learningLine", { language: languageName(langs.learning.lang) })}<//>`}
482
+ ${langs?.learning && !langs.learning.sure && html`<${Text} color=${theme.warn}>${t("add.learningGuess")}<//>`}
483
+ <${Box} marginTop=${langs ? 0 : 1}><${Text} dimColor>${t("add.directionLater")}<//><//>
440
484
  <//>
441
485
  `}
442
486
  ${(step === "review" || step === "fix") &&
package/src/ui/App.js CHANGED
@@ -2,13 +2,15 @@ import { Fragment, useCallback, useEffect, useRef, useState } from "react";
2
2
  import { Box, useApp, useInput, useStdout } from "ink";
3
3
  import { commandsFor } from "../commands.js";
4
4
  import { accentMarks, diffChars } from "../diff.js";
5
+ import { ALMOST } from "../judge.js";
6
+ import { toSpeak } from "../session.js";
5
7
  import { AnswerInput } from "./AnswerInput.js";
6
8
  import { Header } from "./Header.js";
7
9
  import { setLanguage, t } from "../i18n.js";
8
10
  import { Bar, cellWidth, cutToWidth, html, KeyHints, Marked, Text, theme, Typewriter, usePanelWidth } from "./kit.js";
9
11
  import { hintTarget, makeHint } from "../hint.js";
10
12
  import { formatClock, inQuietHours, quietEnd } from "../quiet.js";
11
- import { startOfTomorrow } from "../scheduler.js";
13
+ import { NEW_PER_DAY, startOfTomorrow } from "../scheduler.js";
12
14
  import { formatDay } from "../vacation.js";
13
15
  import { dayKey } from "../dates.js";
14
16
  import { shouldShowTip } from "../tips.js";
@@ -42,6 +44,8 @@ const CHEER_STYLE = {
42
44
  combo: { icon: "»", color: theme.warn }
43
45
  };
44
46
 
47
+ const QUIET_NIGHT_UNTIL = 7; // o'clock: no "new card" sound before then when a day's cards come in
48
+
45
49
  function clock(ms) {
46
50
  const total = Math.max(0, Math.ceil(ms / 1000));
47
51
  return `${Math.floor(total / 60)}:${String(total % 60).padStart(2, "0")}`;
@@ -49,11 +53,12 @@ function clock(ms) {
49
53
 
50
54
  // your answer with every letter judged: green lined up with the expected word, underlined didn't
51
55
  function AnswerDiff({ given, closest }) {
52
- const parts = diffChars(given, closest);
56
+ const parts = diffChars(given, closest, { gaps: true });
57
+ if (parts.every((p) => p.ok)) return null; // the same letters after all: nothing to mark
53
58
  return html`
54
59
  <${Text}>
55
60
  <${Text} dimColor>${t("quiz.youWrote")}<//>
56
- ${parts.map((p, i) => html`<${Text} key=${i} color=${p.ok ? theme.good : theme.text} underline=${!p.ok}>${p.ch}<//>`)}
61
+ ${parts.map((p, i) => html`<${Text} key=${i} color=${p.missing ? theme.bad : p.ok ? theme.good : theme.text} underline=${!p.ok && !p.missing}>${p.ch}<//>`)}
57
62
  <//>
58
63
  `;
59
64
  }
@@ -75,7 +80,9 @@ function Verdict({ outcome, question }) {
75
80
  const showDiff = outcome.closest && outcome.given && !outcome.overruled && (wrong || outcome.result === "typo");
76
81
  return html`
77
82
  <${Box} flexDirection="column">
78
- <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}<//>
83
+ <${Text} color=${wrong ? theme.bad : theme.good} bold>${wrong ? "✗" : "✓"} ${outcome.result === "accent" || outcome.result === "umlaut" || outcome.result === "article-umlaut" ? html`<${AccentedAnswers} expected=${question.expected} given=${outcome.given} closest=${outcome.closest} />` : question.expected.join(" / ")}${outcome.result === "typo" ? t("quiz.closeEnough") : ""}<//>
84
+ ${ALMOST.includes(outcome.result) &&
85
+ html`<${Text} color=${theme.warn}>${t(`quiz.almost.${outcome.result}`)}${outcome.held ? ` ${t("quiz.almost.held", { now: t("quiz.almost.days", { count: outcome.held.days }), would: t("quiz.almost.days", { count: outcome.held.would }) })}` : ""}<//>`}
79
86
  ${showDiff && html`<${AnswerDiff} given=${outcome.given} closest=${outcome.closest} />`}
80
87
  ${question.word.example && html`<${Box} marginTop=${1}>${question.tour ? html`<${Marked} dimColor text=${question.word.example} />` : html`<${Text} dimColor italic>“${question.word.example}”<//>`}<//>`}
81
88
  ${(outcome.hinted || outcome.overruled) &&
@@ -143,7 +150,7 @@ function whenDue(at, now) {
143
150
  }
144
151
 
145
152
  // what the quiz shows when the deck has nothing to ask: no countdown, just the way on
146
- function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
153
+ function EmptyDeck({ deck, tour, count, nextDue, dayDone, heldNew = 0, now, width }) {
147
154
  const [title, next] = tour
148
155
  ? [t("quiz.empty.tourTitle"), t("quiz.empty.tourNext")]
149
156
  : !count
@@ -151,7 +158,7 @@ function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
151
158
  : nextDue >= startOfTomorrow(now) && !dayDone
152
159
  ? [t("quiz.empty.deckDoneTitle", { deck }), t("quiz.empty.deckDoneNext", { when: whenDue(nextDue, now) })]
153
160
  : nextDue >= startOfTomorrow(now)
154
- ? [t("quiz.empty.dayDoneTitle"), t("quiz.empty.dayDoneNext", { when: whenDue(nextDue, now) })]
161
+ ? [t("quiz.empty.dayDoneTitle"), t(heldNew > 0 ? "quiz.empty.dayDoneHeldNext" : "quiz.empty.dayDoneNext", { when: whenDue(nextDue, now) })]
155
162
  : [t("quiz.empty.laterTitle"), t("quiz.empty.laterNext", { when: whenDue(nextDue, now) })];
156
163
  return html`
157
164
  <${Box} flexDirection="column" width=${width}>
@@ -159,6 +166,7 @@ function EmptyDeck({ deck, tour, count, nextDue, dayDone, now, width }) {
159
166
  <${Box} flexDirection="column" borderStyle="round" borderTop=${false} borderColor=${theme.accent} paddingX=${2} paddingY=${1}>
160
167
  <${Text} bold>${title}<//>
161
168
  <${Text}>${next}<//>
169
+ ${!tour && heldNew > 0 && html`<${Box} marginTop=${1}><${Text} dimColor>${t("quiz.empty.newTomorrow", { count: heldNew, max: NEW_PER_DAY })}<//><//>`}
162
170
  <//>
163
171
  <//>
164
172
  `;
@@ -259,7 +267,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
259
267
  return waitForNext();
260
268
  }
261
269
  setQuestion(null);
262
- setEmpty({ tour: err.tour, count: err.count, nextDue: err.nextDue, dayDone: err.dayDone });
270
+ setEmpty({ tour: err.tour, count: err.count, nextDue: err.nextDue, dayDone: err.dayDone, heldNew: err.heldNew });
263
271
  setOutcome(err.cheers.length ? { result: "done", cheers: err.cheers } : null);
264
272
  if (err.cheers.length) celebrate({ result: "exact", cheers: err.cheers, combo: session.totals.combo });
265
273
  setPhase("empty");
@@ -279,7 +287,8 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
279
287
  // with nothing to practise, the quiz picks up again by itself once the next card is due
280
288
  useEffect(() => {
281
289
  if (phase !== "empty" || !empty?.nextDue || screen !== "quiz" || confirming || now < empty.nextDue || pauseEnd(now)) return;
282
- alerts.ask();
290
+ // a new day's cards are ready from midnight: they wait quietly till morning instead of chiming at night
291
+ if (new Date(now).getHours() >= QUIET_NIGHT_UNTIL) alerts.ask();
283
292
  ask();
284
293
  }, [now, phase, empty, screen, confirming, ask, alerts]);
285
294
 
@@ -396,7 +405,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
396
405
  if (snooze === "off") setSnoozeUntil(0);
397
406
  if (typeof snooze === "number") {
398
407
  setSnoozeUntil(Date.now() + snooze);
399
- return phase === "asking" ? setNotice(t("quiz.pausedUntilNotice", { time: formatClock(Date.now() + snooze) })) : undefined; // while waiting, the status line says it
408
+ return phase !== "waiting" ? setNotice(t("quiz.pausedUntilNotice", { time: formatClock(Date.now() + snooze) })) : undefined; // while waiting, the status line says it
400
409
  }
401
410
  const paused = list && snoozeRef.current > Date.now() ? t("quiz.pausedUntilList", { time: formatClock(snoozeRef.current) }) : "";
402
411
  setNotice(paused + message);
@@ -431,7 +440,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
431
440
  const next = { ...previous, ...patch };
432
441
  settingsRef.current = next;
433
442
  setSettings(next);
434
- alerts.configure({ sound: next.sound, volume: next.volume });
443
+ alerts.configure({ sound: next.sound, volume: next.volume, speak: next.speak });
435
444
  persistSettings(patch).catch(() => {});
436
445
  if (patch.everyMs && phase === "waiting") setNextAt((at) => at - previous.everyMs + patch.everyMs);
437
446
  if (patch.rhythm) {
@@ -469,11 +478,19 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
469
478
  if (!text) {
470
479
  if (Date.now() - shownAt.current < SETTLE_MS) return;
471
480
  session.reveal(question);
481
+ say(question);
472
482
  shownAt.current = Date.now();
473
483
  setNudge(false);
474
484
  return setPhase("grading");
475
485
  }
476
- await settle(() => session.answer(question, text, { hinted: hintLevel > 0 }));
486
+ const result = await settle(() => session.answer(question, text, { hinted: hintLevel > 0 }));
487
+ if (result) say(question, result.closest);
488
+ }
489
+
490
+ // pronunciation (/settings), once the answer is out
491
+ function say(q, answer) {
492
+ const spoken = toSpeak(q, answer);
493
+ if (spoken) alerts.speak(spoken.text, spoken.lang);
477
494
  }
478
495
 
479
496
  const gradeSelf = (knew) => settle(() => session.selfGrade(question, knew, { hinted: hintLevel > 0 }));
@@ -491,8 +508,10 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
491
508
  if (length !== null && sessionDone.current === length) setNotice(t("quiz.sessionDone", { count: length }));
492
509
  setOutcome(result);
493
510
  celebrate(result);
511
+ return result;
494
512
  } catch (err) {
495
513
  setProblem(t("quiz.saveFailed", { error: err.message }));
514
+ return null;
496
515
  } finally {
497
516
  busy.current = false;
498
517
  waitForNext(nextDue);
@@ -532,6 +551,7 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
532
551
  setScreen("quiz");
533
552
  if (removed.length) session.forget(removed).catch(() => {});
534
553
  if (stale.length) session.forgetKeys(stale).catch(() => {});
554
+ if (added) session.workAdded().catch(() => {});
535
555
  const switching = started && (removed.length || phase === "empty" || addNew);
536
556
  if (switching) switchDeck(started);
537
557
  else if (phase === "empty" && added) ask();
@@ -585,8 +605,9 @@ export function App({ session, deck: initialDeck, initialSettings, alerts, persi
585
605
  ${screen === "add" && html`<${AddCard} current=${deck} actions=${library} onDone=${addDone} startNew=${addNew} />`}
586
606
  ${screen === "decks" && html`<${Decks} current=${deck} actions=${library} onDirections=${async (cardIds, directions) => {
587
607
  await session.setDirections(cardIds, directions);
608
+ await session.workAdded();
588
609
  if (phase === "asking" && question && cardIds.includes(question.word.noteId)) ask(); // the open card follows the new way at once
589
- }} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
610
+ }} onLanguages=${(name) => name === deck && phase === "asking" && ask()} onPick=${switchDeck} onNew=${() => (setAddNew(true), setScreen("add"))} onClose=${() => setScreen("quiz")} />`}
590
611
  ${!["settings", "reset", "add", "decks"].includes(screen) &&
591
612
  html`
592
613
  <${Fragment}>
@@ -40,7 +40,7 @@ export function BadgeUnlock({ id, name, desc, delay = 0, sound = badgeSound(0),
40
40
  const sparks = frame < SPARKS_UNTIL ? ` ${Array.from({ length: 3 }, (_, i) => SPARKS[(frame + i) % SPARKS.length]).join(" ")}` : "";
41
41
 
42
42
  return html`
43
- <${Box}>
43
+ <${Text}>
44
44
  <${Text} color=${color}>✦ <//>
45
45
  <${Text} color=${theme.warn}>${t("badgeUnlock.label")}<//>
46
46
  <${Text} bold color=${color}>${name}<//>