dracosh 0.2.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.
Files changed (57) hide show
  1. package/README.md +25 -17
  2. package/locales/de.json +1098 -0
  3. package/locales/en.json +1081 -0
  4. package/locales/fr.json +1148 -0
  5. package/locales/pl.json +1173 -0
  6. package/locales/uk.json +1174 -0
  7. package/package.json +2 -2
  8. package/src/alerts.js +71 -4
  9. package/src/backup.js +2 -1
  10. package/src/cardline.js +71 -0
  11. package/src/cli.js +41 -54
  12. package/src/commands.js +14 -12
  13. package/src/demo.js +11 -0
  14. package/src/diff.js +20 -10
  15. package/src/i18n.js +68 -0
  16. package/src/judge.js +164 -13
  17. package/src/language.js +355 -0
  18. package/src/library.js +91 -38
  19. package/src/lock.js +2 -1
  20. package/src/manage.js +193 -58
  21. package/src/pause.js +1 -2
  22. package/src/progress.js +119 -63
  23. package/src/quiet.js +3 -2
  24. package/src/scheduler.js +26 -9
  25. package/src/session.js +118 -36
  26. package/src/settings.js +14 -6
  27. package/src/starter.js +36 -27
  28. package/src/store.js +11 -8
  29. package/src/tips.js +12 -3
  30. package/src/ui/AddCard.js +449 -81
  31. package/src/ui/AnswerInput.js +22 -10
  32. package/src/ui/App.js +209 -57
  33. package/src/ui/BadgeUnlock.js +5 -4
  34. package/src/ui/Badges.js +9 -8
  35. package/src/ui/Choice.js +14 -9
  36. package/src/ui/Companion.js +13 -13
  37. package/src/ui/Confetti.js +2 -2
  38. package/src/ui/Decks.js +167 -9
  39. package/src/ui/DieRoll.js +9 -9
  40. package/src/ui/Evolution.js +7 -7
  41. package/src/ui/Hatch.js +7 -6
  42. package/src/ui/Header.js +58 -16
  43. package/src/ui/Help.js +43 -25
  44. package/src/ui/Languages.js +167 -0
  45. package/src/ui/Mascot.js +1 -2
  46. package/src/ui/Missed.js +13 -12
  47. package/src/ui/Preview.js +48 -29
  48. package/src/ui/Reset.js +13 -14
  49. package/src/ui/Settings.js +27 -19
  50. package/src/ui/Stats.js +24 -23
  51. package/src/ui/Summary.js +30 -15
  52. package/src/ui/TheOne.js +7 -6
  53. package/src/ui/icons.js +1 -2
  54. package/src/ui/kit.js +34 -6
  55. package/src/vacation.js +2 -1
  56. package/src/words.js +8 -2
  57. package/data/tips.json +0 -32
package/src/progress.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { dateLocale, t } from "./i18n.js";
1
2
  import { addDays, dayKey, daysBetween, weekStart } from "./dates.js";
2
3
  import { BOX_INTERVALS_DAYS } from "./scheduler.js";
3
4
 
@@ -11,19 +12,27 @@ const FALL_MIN = 30; // a lost streak this long counts as a fall for "Dragon's d
11
12
  // The die's faces: winning "Dragon's die" rolls one, and the dragon keeps that element for good.
12
13
  export const ELEMENTS = ["earth", "wind", "water", "ice", "fire", "cosmos"];
13
14
  export const rollElement = (random = Math.random) => ELEMENTS[Math.floor(random() * ELEMENTS.length)];
14
- export const ELEMENT_ADJECTIVE = { earth: "Earth", wind: "Wind", water: "Water", ice: "Ice", fire: "Fire", cosmos: "Cosmic" };
15
+ export const elementName = (element) => t(`dragon.elements.${element}.name`);
16
+ export const elementAdjective = (element) => t(`dragon.elements.${element}.adjective`);
15
17
 
16
18
  // what the dragon is called: its form, with its element in front once it has one ("Ice Drake")
17
- export const dragonName = (stage, element = null) => (element ? `${ELEMENT_ADJECTIVE[element]} ${STAGES[stage].name}` : STAGES[stage].name);
19
+ export const dragonName = (stage, element = null) => (element ? t("dragon.named", { element: elementAdjective(element), stage: STAGES[stage].name }) : STAGES[stage].name);
18
20
 
19
21
  // The companion evolves permanently with your best streak, so a broken streak never takes a form away.
22
+ const stage = (id, from) => ({
23
+ id,
24
+ from,
25
+ get name() {
26
+ return t(`dragon.stages.${id}`);
27
+ }
28
+ });
20
29
  export const STAGES = [
21
- { name: "Hatchling", from: 0 },
22
- { name: "Imp", from: 7 },
23
- { name: "Whelp", from: 30 },
24
- { name: "Drake", from: 90 },
25
- { name: "Dragon", from: 180 },
26
- { name: "Legend", from: 365 }
30
+ stage("hatchling", 0),
31
+ stage("imp", 7),
32
+ stage("whelp", 30),
33
+ stage("drake", 90),
34
+ stage("dragon", 180),
35
+ stage("legend", 365)
27
36
  ];
28
37
 
29
38
  export function stageFor(bestStreak) {
@@ -43,6 +52,7 @@ export function ensureProgress(state, now = Date.now()) {
43
52
  vacations: []
44
53
  };
45
54
  state.progress.vacations ??= [];
55
+ delete state.progress.quiet; // a test build's single stretch, before quietDays
46
56
  // badges already shown in /badges; ones unlocked before this was tracked count as seen, so they don't all flash at once
47
57
  state.progress.seenBadges ??= Object.keys(state.progress.badges);
48
58
  return state.progress;
@@ -52,8 +62,35 @@ export function ensureProgress(state, now = Date.now()) {
52
62
 
53
63
  const NO_RULES = { skipWeekends: false };
54
64
 
65
+ // A day with nothing to practise: opened and nothing was waiting, or, after a day done, before the next
66
+ // card came back, whether Dracosh was opened or not. Each such stretch is kept in `quietDays` as
67
+ // { from, until } (the days strictly between); a later one never wipes an earlier one out.
68
+ const KEPT_QUIET = 30;
69
+ function nothingToDo(progress, key) {
70
+ if (progress.days?.[key]?.nothingDue) return true;
71
+ return (progress.quietDays ?? []).some((q) => key > q.from && key < q.until);
72
+ }
73
+
74
+ // The day is done and nothing comes back before `until` (a day key): the days between are rest days.
75
+ // Settling again inside a stretch moves its end, never its start.
76
+ export function markQuiet(progress, today, until) {
77
+ if (!until || until <= today) return;
78
+ const list = (progress.quietDays ??= []);
79
+ const last = list.at(-1);
80
+ if (last && today >= last.from && today < last.until) last.until = until;
81
+ else list.push({ from: today, until });
82
+ progress.quietDays = list.slice(-KEPT_QUIET);
83
+ }
84
+
85
+ // Something turned up to practise today (cards added, a deck or a direction switched on): the stretch
86
+ // it falls in ends here, so the days ahead aren't rest days any more
87
+ export function markWorkWaiting(progress, today) {
88
+ const last = progress.quietDays?.at(-1);
89
+ if (last && today >= last.from && today < last.until) last.until = today > last.from ? today : addDays(today, 1);
90
+ }
91
+
55
92
  export function isRestDay(progress, key, rules = NO_RULES) {
56
- if (progress.days?.[key]?.nothingDue) return true; // opened, but no card anywhere was waiting
93
+ if (nothingToDo(progress, key)) return true;
57
94
  if (rules.skipWeekends) {
58
95
  const weekday = new Date(`${key}T12:00:00`).getDay();
59
96
  if (weekday === 0 || weekday === 6) return true;
@@ -159,66 +196,75 @@ function perfectWeek(progress, today) {
159
196
 
160
197
  // `s` = stats from collectStats() plus `event`: what this very answer was (correct, hour, days since last activity)
161
198
  export const BADGES = [
162
- { id: "hello", name: "Hello!", desc: "your first correct answer", test: (s) => s.totalCorrect >= 1 },
163
- { id: "first-steps", name: "First steps", desc: "10 correct answers", test: (s) => s.totalCorrect >= 10 },
164
- { id: "century", name: "Century", desc: "100 correct answers", test: (s) => s.totalCorrect >= 100 },
165
- { id: "thousand", name: "Thousand", desc: "1,000 correct answers", test: (s) => s.totalCorrect >= 1000 },
166
- { id: "five-thousand", name: "Five thousand", desc: "5,000 correct answers", test: (s) => s.totalCorrect >= 5000 },
167
- { id: "ten-thousand", name: "Ten thousand", desc: "10,000 correct answers", test: (s) => s.totalCorrect >= 10000 },
168
- { id: "dragons-hoard", name: "Dragon's hoard", desc: "20,000 correct answers", test: (s) => s.totalCorrect >= 20000 },
169
-
170
- { id: "on-a-roll", name: "On a roll", desc: "3-day streak", test: (s) => s.bestStreak >= 3 },
171
- { id: "week", name: "Full week", desc: "7-day streak", test: (s) => s.bestStreak >= 7 },
172
- { id: "fortnight", name: "Fortnight", desc: "14-day streak", test: (s) => s.bestStreak >= 14 },
173
- { id: "month", name: "Iron habit", desc: "30-day streak", test: (s) => s.bestStreak >= 30 },
174
- { id: "hundred-days", name: "Centurion", desc: "100-day streak", test: (s) => s.bestStreak >= 100 },
175
- { id: "dragonheart", name: "Dragonheart", desc: "180-day streak", test: (s) => s.bestStreak >= 180 },
176
-
177
- { id: "keeper", name: "Word keeper", desc: "10 cards mastered", test: (s) => s.mastered >= 10 },
178
- { id: "collector", name: "Collector", desc: "25 cards mastered", test: (s) => s.mastered >= 25 },
179
- { id: "dictionary", name: "Walking dictionary", desc: "50 cards mastered", test: (s) => s.mastered >= 50 },
180
- { id: "lexicon", name: "Living lexicon", desc: "150 cards mastered", test: (s) => s.mastered >= 150 },
181
- { id: "explorer", name: "Explorer", desc: "250 cards practised", test: (s) => s.practiced >= 250 },
182
-
183
- { id: "flawless", name: "Flawless", desc: "10+ answers in a day, no miss", test: (s) => s.today.asked >= 10 && s.today.correct === s.today.asked },
184
- { id: "overachiever", name: "Overachiever", desc: "double your daily goal in a day", test: (s) => s.today.correct >= s.goal * 2 },
185
- { id: "marathon", name: "Marathon", desc: "30 correct answers in a day", test: (s) => s.today.correct >= 30 },
186
-
187
- { id: "hot-streak", name: "Hot streak", desc: "10 correct in a row", test: (s) => s.bestCombo >= 10 },
188
- { id: "unstoppable", name: "Unstoppable", desc: "25 correct in a row", test: (s) => s.bestCombo >= 25 },
189
- { id: "combo-master", name: "Combo master", desc: "50 correct in a row", test: (s) => s.bestCombo >= 50 },
190
-
191
- { id: "early-bird", name: "Early bird", desc: "a correct answer before 8:00", test: (s) => s.event.correct && s.event.hour < 8 },
192
- { id: "night-owl", name: "Night owl", desc: "a correct answer after 23:00", test: (s) => s.event.correct && s.event.hour >= 23 },
193
-
194
- { id: "comeback", name: "Welcome back", desc: "back after 5+ days away", test: (s) => s.event.correct && s.event.daysAway >= COMEBACK_AFTER_DAYS },
195
- { id: "redemption", name: "Redemption", desc: "5 words missed today, got right later the same day", test: (s) => s.recoveredToday >= 5 },
196
- { id: "frozen", name: "Frozen in time", desc: "a freeze saved your streak", test: (s) => s.freezesUsed >= 1 },
197
- { id: "weekend", name: "Weekend warrior", desc: "goal on both Saturday and Sunday", test: (s) => s.weekendDone },
198
- { id: "perfect-week", name: "Perfect week", desc: "goal every day, Monday to Sunday", test: (s) => s.perfectWeek },
199
- { id: "regular", name: "Regular", desc: "goal on 20 days in one month", test: (s) => s.goalDaysThisMonth >= 20 },
200
- { id: "machine", name: "The machine", desc: "goal on 25 days in one month", test: (s) => s.goalDaysThisMonth >= 25 },
201
- { id: "hundred-club", name: "Hundred club", desc: "goal reached on 100 days in total", test: (s) => s.totalGoalDays >= 100 },
199
+ { id: "hello", test: (s) => s.totalCorrect >= 1 },
200
+ { id: "first-steps", test: (s) => s.totalCorrect >= 10 },
201
+ { id: "century", test: (s) => s.totalCorrect >= 100 },
202
+ { id: "thousand", test: (s) => s.totalCorrect >= 1000 },
203
+ { id: "five-thousand", test: (s) => s.totalCorrect >= 5000 },
204
+ { id: "ten-thousand", test: (s) => s.totalCorrect >= 10000 },
205
+ { id: "dragons-hoard", test: (s) => s.totalCorrect >= 20000 },
206
+
207
+ { id: "on-a-roll", test: (s) => s.bestStreak >= 3 },
208
+ { id: "week", test: (s) => s.bestStreak >= 7 },
209
+ { id: "fortnight", test: (s) => s.bestStreak >= 14 },
210
+ { id: "month", test: (s) => s.bestStreak >= 30 },
211
+ { id: "hundred-days", test: (s) => s.bestStreak >= 100 },
212
+ { id: "dragonheart", test: (s) => s.bestStreak >= 180 },
213
+
214
+ { id: "keeper", test: (s) => s.mastered >= 10 },
215
+ { id: "collector", test: (s) => s.mastered >= 25 },
216
+ { id: "dictionary", test: (s) => s.mastered >= 50 },
217
+ { id: "lexicon", test: (s) => s.mastered >= 150 },
218
+ { id: "explorer", test: (s) => s.practiced >= 250 },
219
+
220
+ { id: "flawless", test: (s) => s.today.asked >= 10 && s.today.correct === s.today.asked },
221
+ { id: "overachiever", test: (s) => s.today.correct >= s.goal * 2 },
222
+ { id: "marathon", test: (s) => s.today.correct >= 30 },
223
+
224
+ { id: "hot-streak", test: (s) => s.bestCombo >= 10 },
225
+ { id: "unstoppable", test: (s) => s.bestCombo >= 25 },
226
+ { id: "combo-master", test: (s) => s.bestCombo >= 50 },
227
+
228
+ { id: "early-bird", test: (s) => s.event.correct && s.event.hour < 8 },
229
+ { id: "night-owl", test: (s) => s.event.correct && s.event.hour >= 23 },
230
+
231
+ { id: "comeback", test: (s) => s.event.correct && s.event.daysAway >= COMEBACK_AFTER_DAYS },
232
+ { id: "redemption", test: (s) => s.recoveredToday >= 5 },
233
+ { id: "frozen", test: (s) => s.freezesUsed >= 1 },
234
+ { id: "weekend", test: (s) => s.weekendDone },
235
+ { id: "perfect-week", test: (s) => s.perfectWeek },
236
+ { id: "regular", test: (s) => s.goalDaysThisMonth >= 20 },
237
+ { id: "machine", test: (s) => s.goalDaysThisMonth >= 25 },
238
+ { id: "hundred-club", test: (s) => s.totalGoalDays >= 100 },
202
239
 
203
240
 
204
241
  // keep this one last: it checks the others, including any unlocked earlier in the same answer
205
- { id: "one-ring", name: "The One...", desc: "every other badge", test: (s) => BADGES.every((b) => b.id === "one-ring" || b.hidden || s.badges[b.id]) },
242
+ { id: "one-ring", test: (s) => BADGES.every((b) => b.id === "one-ring" || b.hidden || s.badges[b.id]) },
206
243
 
207
244
  // hidden: shown as "???" until won, and not needed for The One
208
245
  {
209
246
  id: "dragons-die",
210
- name: "Dragon's die",
211
- desc: "lost a 30+ day streak, then built a longer one",
212
247
  hidden: true,
213
248
  test: (s) => s.fallenStreak >= FALL_MIN && s.streakCount > s.fallenStreak
214
249
  }
215
250
  ];
216
251
 
252
+ // a badge's name and description come from the locale (badges.<id>), read each time they're shown
253
+ for (const badge of BADGES) {
254
+ Object.defineProperties(badge, {
255
+ name: { get: () => t(`badges.${badge.id}.name`), enumerable: true },
256
+ desc: { get: () => t(`badges.${badge.id}.desc`), enumerable: true }
257
+ });
258
+ }
259
+
217
260
  // progress is kept per card and direction ("id:en-pl"); badges count cards
218
261
  const cardOf = (key) => key.slice(0, key.lastIndexOf(":"));
219
262
 
220
- // a card is mastered once every direction it's been asked in has reached the last box
221
- function masteredCards(items) {
263
+ // a card is mastered once every direction it's asked in has reached the last box; a direction its deck
264
+ // no longer asks (`dormant`, kept for when it's turned back on) doesn't hold it back
265
+ function masteredCards(items, dormant = []) {
266
+ const resting = new Set(dormant);
267
+ items = items.filter(([key]) => !resting.has(key));
222
268
  const byCard = new Map();
223
269
  for (const [key, entry] of items) byCard.set(cardOf(key), (byCard.get(cardOf(key)) ?? true) && entry.box === MAX_BOX);
224
270
  return [...byCard.values()].filter(Boolean).length;
@@ -249,7 +295,7 @@ function collectStats(state, now, goal) {
249
295
  bestStreak: progress.streak.best,
250
296
  bestCombo: progress.bestCombo ?? 0,
251
297
  freezesUsed: progress.streak.freezesUsed ?? 0,
252
- mastered: masteredCards(items),
298
+ mastered: masteredCards(items, state.dormant),
253
299
  practiced: new Set(items.map(([key]) => cardOf(key))).size,
254
300
  goalDaysThisMonth: goalDaysInMonth(progress, todayKey),
255
301
  totalGoalDays: Object.values(progress.days).filter((d) => d.goalMet).length,
@@ -270,17 +316,17 @@ function award(state, progress, day, today, { correct, goal, rules, now, daysAwa
270
316
  if (caughtUp) day.caughtUp = true;
271
317
  const stageBefore = stageFor(progress.streak.best);
272
318
  const streak = completeDay(progress, today, rules);
273
- cheers.push({ kind: "goal", text: `${caughtUp ? "All done for today" : "Daily goal reached"} · ${streak}-day streak` });
319
+ cheers.push({ kind: "goal", text: t(caughtUp ? "cheers.allDone" : "cheers.goal", { count: streak }) });
274
320
  const stageAfter = stageFor(progress.streak.best);
275
321
  if (stageAfter.index > stageBefore.index)
276
- cheers.push({ kind: "evolve", text: `Your companion evolved into a${/^[aeiou]/i.test(stageAfter.name) ? "n" : ""} ${stageAfter.name}!` });
322
+ cheers.push({ kind: "evolve", text: t("cheers.evolved", { name: stageAfter.name }) });
277
323
  }
278
324
 
279
325
  const stats = { ...collectStats(state, now, goal), event: { correct, hour: new Date(now).getHours(), daysAway } };
280
326
  for (const badge of BADGES) {
281
327
  if (!progress.badges[badge.id] && badge.test(stats)) {
282
328
  progress.badges[badge.id] = today;
283
- cheers.push({ kind: "badge", id: badge.id, name: badge.name, desc: badge.desc, text: `Badge unlocked: ${badge.name} · ${badge.desc}` });
329
+ cheers.push({ kind: "badge", id: badge.id, name: badge.name, desc: badge.desc, text: t("cheers.badge", { name: badge.name, desc: badge.desc }) });
284
330
  // rolled and saved right away, before any animation, so quitting mid-roll can't reroll it
285
331
  if (badge.id === "dragons-die" && !progress.element && !progress.elementDropped) {
286
332
  progress.element = rollElement(random);
@@ -300,7 +346,7 @@ export function applyAnswer(state, { result, goal, rules = NO_RULES, combo = 0,
300
346
  const day = dayOf(progress, today);
301
347
  const correct = result !== "wrong";
302
348
  // full days away since the last correct answer (a wrong first answer back doesn't end the absence)
303
- const daysAway = progress.lastActiveDay ? daysBetween(progress.lastActiveDay, today) - 1 : 0;
349
+ const daysAway = awayDays(progress, today);
304
350
 
305
351
  day.asked += 1;
306
352
  day.correct += correct ? 1 : 0;
@@ -309,13 +355,22 @@ export function applyAnswer(state, { result, goal, rules = NO_RULES, combo = 0,
309
355
  return { cheers: award(state, progress, day, today, { correct, goal, rules, now, daysAway, random }) };
310
356
  }
311
357
 
358
+ // full days since the last correct answer, not counting days with nothing to practise: coming back after
359
+ // those isn't a comeback (a vacation still is)
360
+ function awayDays(progress, today) {
361
+ if (!progress.lastActiveDay) return 0;
362
+ let away = 0;
363
+ for (let key = addDays(progress.lastActiveDay, 1); key < today; key = addDays(key, 1)) if (!nothingToDo(progress, key)) away += 1;
364
+ return away;
365
+ }
366
+
312
367
  // A wrong answer the user then declared right: it was already counted as asked, so only credit the correct one
313
368
  export function applyOverrule(state, { goal, rules = NO_RULES, combo = 0, now = Date.now(), random = Math.random }) {
314
369
  const progress = ensureProgress(state, now);
315
370
  const today = dayKey(now);
316
371
  const day = dayOf(progress, today);
317
372
 
318
- const daysAway = progress.lastActiveDay ? daysBetween(progress.lastActiveDay, today) - 1 : 0;
373
+ const daysAway = awayDays(progress, today);
319
374
  day.correct += 1;
320
375
  progress.bestCombo = Math.max(progress.bestCombo ?? 0, combo);
321
376
  progress.lastActiveDay = today;
@@ -325,10 +380,12 @@ export function applyOverrule(state, { goal, rules = NO_RULES, combo = 0, now =
325
380
  // Nothing left to practise today in the whole library → cheers. After at least one right answer today
326
381
  // that counts as the goal (see award); with nothing answered at all the day only becomes a rest day, so just
327
382
  // opening Dracosh never builds a streak. Nothing happens once the goal is met.
328
- export function applyCaughtUp(state, { goal, rules = NO_RULES, now = Date.now(), random = Math.random }) {
383
+ // `nextDue`: when the next card anywhere comes back (null: none ever), so the days until then count as rest.
384
+ export function applyCaughtUp(state, { goal, rules = NO_RULES, now = Date.now(), nextDue, random = Math.random }) {
329
385
  const progress = ensureProgress(state, now);
330
386
  const today = dayKey(now);
331
387
  const day = dayOf(progress, today);
388
+ if (nextDue) markQuiet(progress, today, dayKey(nextDue));
332
389
  if (day.goalMet) return { cheers: [] };
333
390
  if (!day.asked) {
334
391
  day.nothingDue = true;
@@ -367,7 +424,6 @@ export function snapshot(state, { goal, rules = NO_RULES, now = Date.now() }) {
367
424
  };
368
425
  }
369
426
 
370
- const MONTH_NAMES = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
371
427
 
372
428
  // One calendar month, weeks Monday..Sunday: each day has the number of correct answers and whether the goal was met.
373
429
  // `offset` moves back (negative) or forward from the current month.
@@ -391,7 +447,7 @@ export function calendarMonth(state, { offset = 0, rules = NO_RULES, now = Date.
391
447
  for (let i = 0; i < padded.length; i += 7) weeks.push([...padded.slice(i, i + 7), ...Array(Math.max(0, i + 7 - padded.length)).fill(null)]);
392
448
 
393
449
  return {
394
- label: `${MONTH_NAMES[first.getMonth()]} ${first.getFullYear()}`,
450
+ label: new Intl.DateTimeFormat(dateLocale(), { month: "long", year: "numeric" }).format(first),
395
451
  weeks,
396
452
  goalDays: cells.filter((c) => c.goalMet).length,
397
453
  correct: cells.reduce((sum, c) => sum + c.correct, 0),
package/src/quiet.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { dateLocale, t } from "./i18n.js";
1
2
  const MINUTE = 60_000;
2
3
  const HOUR = 60 * MINUTE;
3
4
 
@@ -16,7 +17,7 @@ export function quietEnd(ms, quiet) {
16
17
  return end.getTime();
17
18
  }
18
19
 
19
- export const formatQuiet = (quiet) => (quiet ? `${String(quiet.from).padStart(2, "0")}:00–${String(quiet.to).padStart(2, "0")}:00` : "off");
20
+ export const formatQuiet = (quiet) => (quiet ? `${String(quiet.from).padStart(2, "0")}:00–${String(quiet.to).padStart(2, "0")}:00` : t("settings.off"));
20
21
 
21
22
  // /pause durations: "" → 1 h, "30", "30m", "2h", "90s" → milliseconds, "off" → "off", anything else → null
22
23
  export function parseSnooze(arg) {
@@ -29,4 +30,4 @@ export function parseSnooze(arg) {
29
30
  return amount > 0 ? amount : null;
30
31
  }
31
32
 
32
- export const formatClock = (ms) => new Date(ms).toLocaleTimeString("en-GB", { hour: "2-digit", minute: "2-digit" });
33
+ export const formatClock = (ms) => new Date(ms).toLocaleTimeString(dateLocale(), { hour: "2-digit", minute: "2-digit" });
package/src/scheduler.js CHANGED
@@ -15,6 +15,24 @@ export function newToday(state, now) {
15
15
  return state.newToday?.date === dayKey(now) ? state.newToday.count : 0;
16
16
  }
17
17
 
18
+ // A review is waiting for the whole day it falls due, from midnight: a card answered at 17:00 yesterday
19
+ // can be done this morning. But never sooner than half a day after it was answered, so a sitting across
20
+ // midnight doesn't ask it again minutes later. A card just missed (streak 0) comes back at its minute.
21
+ const MIN_GAP = 12 * 60 * MINUTE;
22
+ export function readyAt(entry) {
23
+ if (!entry.streak) return entry.due;
24
+ const day = new Date(entry.due);
25
+ day.setHours(0, 0, 0, 0);
26
+ return Math.min(entry.due, Math.max(day.getTime(), (entry.last ?? 0) + MIN_GAP));
27
+ }
28
+
29
+ // the same time of day, `days` calendar days later (a day with a clock change is still one day)
30
+ function daysLater(now, days) {
31
+ const date = new Date(now);
32
+ date.setDate(date.getDate() + days);
33
+ return date.getTime();
34
+ }
35
+
18
36
  const NEW_RATIO = 0.3; // when both due and unseen items exist, this share of questions introduces a new one
19
37
  const MAX_OVERDUE_WEIGHT_DAYS = 3;
20
38
 
@@ -32,20 +50,19 @@ function pickDue(due, now, random) {
32
50
  return due[due.length - 1];
33
51
  }
34
52
 
35
- // Mixes due reviews with new words (up to the daily cap), at random; with nothing to do, practises a soon-due item.
36
- // Never asks the same note twice in a row when there is any alternative. A `tour` deck is different:
37
- // each card is asked once, in deck order, and never comes back as a review (null when it's done).
38
53
  // What to ask next: a due review or a new card (up to the daily cap), mixed at random; null when there
39
54
  // is nothing to do right now. Cards are never asked before they're due: answering early would move them
40
55
  // up the boxes without the spacing that makes them stick. Never the same note twice in a row while
41
56
  // anything else is waiting. A `tour` deck is different: each card is asked once, in deck order, and
42
- // never comes back as a review.
57
+ // never comes back as a review. A word's own `directions` (a cloze card's gaps) replace the deck's.
43
58
  export function pickNext({ words, state, now = Date.now(), lastNoteId = null, directions = DIRECTIONS, tour = false, random = Math.random }) {
44
- const candidates = words.flatMap((word) => directions.map((direction) => ({ word, direction, entry: state.items[itemKey(word.noteId, direction)] })));
59
+ const candidates = words.flatMap((word) => (word.directions ?? directions).map((direction) => ({ word, direction, entry: state.items[itemKey(word.noteId, direction)] })));
45
60
  if (tour) return candidates.find((c) => !c.entry) ?? null;
46
61
 
47
62
  const canIntroduce = newToday(state, now) < NEW_PER_DAY;
48
- const waiting = candidates.filter((c) => (c.entry ? c.entry.due <= now : canIntroduce));
63
+ // the other way round of a card already started is no new card: the daily limit counts cards
64
+ const started = new Set(candidates.filter((c) => c.entry).map((c) => c.word.noteId));
65
+ const waiting = candidates.filter((c) => (c.entry ? readyAt(c.entry) <= now : canIntroduce || started.has(c.word.noteId)));
49
66
  if (!waiting.length) return null;
50
67
  const pool = waiting.some((c) => c.word.noteId !== lastNoteId) ? waiting.filter((c) => c.word.noteId !== lastNoteId) : waiting;
51
68
 
@@ -60,9 +77,9 @@ export function pickNext({ words, state, now = Date.now(), lastNoteId = null, di
60
77
  export function nextDueAt({ words, state, now = Date.now(), directions = DIRECTIONS }) {
61
78
  let next = null;
62
79
  for (const word of words) {
63
- for (const direction of directions) {
80
+ for (const direction of word.directions ?? directions) {
64
81
  const entry = state.items[itemKey(word.noteId, direction)];
65
- const at = entry ? entry.due : startOfTomorrow(now);
82
+ const at = entry ? readyAt(entry) : startOfTomorrow(now);
66
83
  if (next === null || at < next) next = at;
67
84
  }
68
85
  }
@@ -81,7 +98,7 @@ export function grade(entry, correct, now = Date.now(), { hinted = false } = {})
81
98
  // right after a miss the card starts over at box 1 (back tomorrow) instead of skipping ahead
82
99
  const relearning = prev.seen > 0 && prev.streak === 0;
83
100
  const box = hinted || relearning ? Math.max(prev.box, 1) : Math.min(prev.box + 1, BOX_INTERVALS_DAYS.length);
84
- return { ...prev, box, due: now + BOX_INTERVALS_DAYS[box - 1] * DAY, seen: prev.seen + 1, correct: prev.correct + 1, streak: prev.streak + 1, last: now };
101
+ return { ...prev, box, due: daysLater(now, BOX_INTERVALS_DAYS[box - 1]), seen: prev.seen + 1, correct: prev.correct + 1, streak: prev.streak + 1, last: now };
85
102
  }
86
103
  return { ...prev, box: 1, due: now + RELEARN_DELAY, seen: prev.seen + 1, wrong: prev.wrong + 1, streak: 0, last: now };
87
104
  }