@vestcards/shared 1.3.0 → 1.5.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.
@@ -1,7 +1,20 @@
1
- import { t as e } from "./date-DS8JYZte.js";
1
+ import { t as e } from "./date-D5P-dKAx.js";
2
2
  import { i as t, n, r } from "./fsrs-D2XsH28s.js";
3
3
  //#region src/spaced-repetition/config.ts
4
- var i = .9, a = 50, o = 200, s = 10, c = 10, l = ((e) => (e[e.New = 0] = "New", e[e.Learning = 1] = "Learning", e[e.Review = 2] = "Review", e[e.Relearning = 3] = "Relearning", e))(l || {}), u = ((e) => (e[e.Manual = 0] = "Manual", e[e.Again = 1] = "Again", e[e.Hard = 2] = "Hard", e[e.Good = 3] = "Good", e[e.Easy = 4] = "Easy", e))(u || {}), d = class e {
4
+ var i = .9, a = .1542, o = i ** (-1 / a) - 1, s = 50, c = {
5
+ learnDailyLimit: {
6
+ recommended: 200,
7
+ min: 100,
8
+ max: 500,
9
+ step: 50
10
+ },
11
+ newCardsPerDeckDailyLimit: {
12
+ recommended: 10,
13
+ min: 1,
14
+ max: 50,
15
+ step: 5
16
+ }
17
+ }, l = 10, u = (e, t) => e === c.learnDailyLimit.recommended && t === c.newCardsPerDeckDailyLimit.recommended, d = ((e) => (e[e.New = 0] = "New", e[e.Learning = 1] = "Learning", e[e.Review = 2] = "Review", e[e.Relearning = 3] = "Relearning", e))(d || {}), f = ((e) => (e[e.Manual = 0] = "Manual", e[e.Again = 1] = "Again", e[e.Hard = 2] = "Hard", e[e.Good = 3] = "Good", e[e.Easy = 4] = "Easy", e))(f || {}), p = class e {
5
18
  static card(t) {
6
19
  return {
7
20
  ...t,
@@ -12,7 +25,7 @@ var i = .9, a = 50, o = 200, s = 10, c = 10, l = ((e) => (e[e.New = 0] = "New",
12
25
  }
13
26
  static rating(e) {
14
27
  if (typeof e == "string") {
15
- let t = u[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
28
+ let t = f[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
16
29
  if (t === void 0) throw Error(`Invalid rating:[${e}]`);
17
30
  return t;
18
31
  } else if (typeof e == "number") return e;
@@ -20,7 +33,7 @@ var i = .9, a = 50, o = 200, s = 10, c = 10, l = ((e) => (e[e.New = 0] = "New",
20
33
  }
21
34
  static state(e) {
22
35
  if (typeof e == "string") {
23
- let t = l[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
36
+ let t = d[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
24
37
  if (t === void 0) throw Error(`Invalid state:[${e}]`);
25
38
  return t;
26
39
  } else if (typeof e == "number") return e;
@@ -44,22 +57,22 @@ var i = .9, a = 50, o = 200, s = 10, c = 10, l = ((e) => (e[e.New = 0] = "New",
44
57
  review: e.time(t.review)
45
58
  };
46
59
  }
47
- }, f = "4.7.1";
60
+ }, m = "4.7.1";
48
61
  Date.prototype.scheduler = function(e, t) {
49
- return p(this, e, t);
62
+ return ee(this, e, t);
50
63
  }, Date.prototype.diff = function(e, t) {
51
- return m(this, e, t);
64
+ return te(this, e, t);
52
65
  }, Date.prototype.format = function() {
53
- return ee(this);
66
+ return ne(this);
54
67
  }, Date.prototype.dueFormat = function(e, t, n) {
55
- return te(this, e, t, n);
68
+ return re(this, e, t, n);
56
69
  };
57
- function p(e, t, n) {
58
- return new Date(n ? d.time(e).getTime() + t * 24 * 60 * 60 * 1e3 : d.time(e).getTime() + t * 60 * 1e3);
70
+ function ee(e, t, n) {
71
+ return new Date(n ? p.time(e).getTime() + t * 24 * 60 * 60 * 1e3 : p.time(e).getTime() + t * 60 * 1e3);
59
72
  }
60
- function m(e, t, n) {
73
+ function te(e, t, n) {
61
74
  if (!e || !t) throw Error("Invalid date");
62
- let r = d.time(e).getTime() - d.time(t).getTime(), i = 0;
75
+ let r = p.time(e).getTime() - p.time(t).getTime(), i = 0;
63
76
  switch (n) {
64
77
  case "days":
65
78
  i = Math.floor(r / (1440 * 60 * 1e3));
@@ -70,8 +83,8 @@ function m(e, t, n) {
70
83
  }
71
84
  return i;
72
85
  }
73
- function ee(e) {
74
- let t = d.time(e), n = t.getFullYear(), r = t.getMonth() + 1, i = t.getDate(), a = t.getHours(), o = t.getMinutes(), s = t.getSeconds();
86
+ function ne(e) {
87
+ let t = p.time(e), n = t.getFullYear(), r = t.getMonth() + 1, i = t.getDate(), a = t.getHours(), o = t.getMinutes(), s = t.getSeconds();
75
88
  return `${n}-${h(r)}-${h(i)} ${h(a)}:${h(o)}:${h(s)}`;
76
89
  }
77
90
  function h(e) {
@@ -91,18 +104,18 @@ var g = [
91
104
  "month",
92
105
  "year"
93
106
  ];
94
- function te(e, t, n, r = _) {
95
- e = d.time(e), t = d.time(t), r.length !== _.length && (r = _);
107
+ function re(e, t, n, r = _) {
108
+ e = p.time(e), t = p.time(t), r.length !== _.length && (r = _);
96
109
  let i = e.getTime() - t.getTime(), a;
97
110
  for (i /= 1e3, a = 0; a < g.length && !(i < g[a]); a++) i /= g[a];
98
111
  return `${Math.floor(i)}${n ? r[a] : ""}`;
99
112
  }
100
- var ne = Object.freeze([
101
- u.Again,
102
- u.Hard,
103
- u.Good,
104
- u.Easy
105
- ]), re = [
113
+ var ie = Object.freeze([
114
+ f.Again,
115
+ f.Hard,
116
+ f.Good,
117
+ f.Easy
118
+ ]), ae = [
106
119
  {
107
120
  start: 2.5,
108
121
  end: 7,
@@ -119,9 +132,9 @@ var ne = Object.freeze([
119
132
  factor: .05
120
133
  }
121
134
  ];
122
- function ie(e, t, n) {
135
+ function oe(e, t, n) {
123
136
  let r = 1;
124
- for (let t of re) r += t.factor * Math.max(Math.min(e, t.end) - t.start, 0);
137
+ for (let t of ae) r += t.factor * Math.max(Math.min(e, t.end) - t.start, 0);
125
138
  e = Math.min(e, n);
126
139
  let i = Math.max(2, Math.round(e - r)), a = Math.min(Math.round(e + r), n);
127
140
  return e > t && (i = Math.max(i, t + 1)), i = Math.min(i, a), {
@@ -132,11 +145,11 @@ function ie(e, t, n) {
132
145
  function v(e, t, n) {
133
146
  return Math.min(Math.max(e, t), n);
134
147
  }
135
- function ae(e, t) {
148
+ function se(e, t) {
136
149
  let n = Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate()), r = Date.UTC(t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate());
137
150
  return Math.floor((r - n) / 864e5);
138
151
  }
139
- var oe = Object.freeze([
152
+ var ce = Object.freeze([
140
153
  .40255,
141
154
  1.18385,
142
155
  3.173,
@@ -157,8 +170,8 @@ var oe = Object.freeze([
157
170
  .51655,
158
171
  .6621
159
172
  ]);
160
- `${f}`;
161
- var y = .01, se = Object.freeze([
173
+ `${m}`;
174
+ var y = .01, le = Object.freeze([
162
175
  Object.freeze([y, 100]),
163
176
  Object.freeze([y, 100]),
164
177
  Object.freeze([y, 100]),
@@ -179,8 +192,8 @@ var y = .01, se = Object.freeze([
179
192
  Object.freeze([0, 2]),
180
193
  Object.freeze([0, 2])
181
194
  ]), b = (e) => {
182
- let t = [...oe];
183
- return e?.w && (e.w.length === 19 ? t = [...e.w] : e.w.length === 17 && (t = e?.w.concat([0, 0]), t[4] = +(t[5] * 2 + t[4]).toFixed(8), t[5] = +(Math.log(t[5] * 3 + 1) / 3).toFixed(8), t[6] = +(t[6] + .5).toFixed(8), console.debug("[FSRS V5]auto fill w to 19 length"))), t = t.map((e, t) => v(e, se[t][0], se[t][1])), {
195
+ let t = [...ce];
196
+ return e?.w && (e.w.length === 19 ? t = [...e.w] : e.w.length === 17 && (t = e?.w.concat([0, 0]), t[4] = +(t[5] * 2 + t[4]).toFixed(8), t[5] = +(Math.log(t[5] * 3 + 1) / 3).toFixed(8), t[6] = +(t[6] + .5).toFixed(8), console.debug("[FSRS V5]auto fill w to 19 length"))), t = t.map((e, t) => v(e, le[t][0], le[t][1])), {
184
197
  request_retention: e?.request_retention || .9,
185
198
  maximum_interval: e?.maximum_interval || 36500,
186
199
  w: t,
@@ -190,25 +203,25 @@ var y = .01, se = Object.freeze([
190
203
  };
191
204
  function x(e, t) {
192
205
  let n = {
193
- due: e ? d.time(e) : /* @__PURE__ */ new Date(),
206
+ due: e ? p.time(e) : /* @__PURE__ */ new Date(),
194
207
  stability: 0,
195
208
  difficulty: 0,
196
209
  elapsed_days: 0,
197
210
  scheduled_days: 0,
198
211
  reps: 0,
199
212
  lapses: 0,
200
- state: l.New,
213
+ state: d.New,
201
214
  last_review: void 0
202
215
  };
203
216
  return t && typeof t == "function" ? t(n) : n;
204
217
  }
205
- var ce = class {
218
+ var ue = class {
206
219
  c;
207
220
  s0;
208
221
  s1;
209
222
  s2;
210
223
  constructor(e) {
211
- let t = le();
224
+ let t = de();
212
225
  this.c = 1, this.s0 = t(" "), this.s1 = t(" "), this.s2 = t(" "), e ??= +/* @__PURE__ */ new Date(), this.s0 -= t(e), this.s0 < 0 && (this.s0 += 1), this.s1 -= t(e), this.s1 < 0 && (this.s1 += 1), this.s2 -= t(e), this.s2 < 0 && (this.s2 += 1);
213
226
  }
214
227
  next() {
@@ -227,7 +240,7 @@ var ce = class {
227
240
  };
228
241
  }
229
242
  };
230
- function le() {
243
+ function de() {
231
244
  let e = 4022871197;
232
245
  return function(t) {
233
246
  t = String(t);
@@ -239,15 +252,15 @@ function le() {
239
252
  return (e >>> 0) * 23283064365386963e-26;
240
253
  };
241
254
  }
242
- function ue(e) {
243
- let t = new ce(e), n = () => t.next();
255
+ function fe(e) {
256
+ let t = new ue(e), n = () => t.next();
244
257
  return n.int32 = () => t.next() * 4294967296 | 0, n.double = () => n() + (n() * 2097152 | 0) * 11102230246251565e-32, n.state = () => t.state, n.importState = (e) => (t.state = e, n), n;
245
258
  }
246
- var de = -.5, fe = 19 / 81;
247
- function pe(e, t) {
248
- return +((1 + fe * e / t) ** +de).toFixed(8);
259
+ var pe = -.5, me = 19 / 81;
260
+ function he(e, t) {
261
+ return +((1 + me * e / t) ** +pe).toFixed(8);
249
262
  }
250
- var me = class {
263
+ var ge = class {
251
264
  param;
252
265
  intervalModifier;
253
266
  _seed;
@@ -262,7 +275,7 @@ var me = class {
262
275
  }
263
276
  calculate_interval_modifier(e) {
264
277
  if (e <= 0 || e > 1) throw Error("Requested retention rate should be in the range (0,1]");
265
- return +((e ** (1 / de) - 1) / fe).toFixed(8);
278
+ return +((e ** (1 / pe) - 1) / me).toFixed(8);
266
279
  }
267
280
  get parameters() {
268
281
  return this.param;
@@ -291,7 +304,7 @@ var me = class {
291
304
  }
292
305
  apply_fuzz(e, t) {
293
306
  if (!this.param.enable_fuzz || e < 2.5) return Math.round(e);
294
- let n = ue(this._seed)(), { min_ivl: r, max_ivl: i } = ie(e, t, this.param.maximum_interval);
307
+ let n = fe(this._seed)(), { min_ivl: r, max_ivl: i } = oe(e, t, this.param.maximum_interval);
295
308
  return Math.floor(n * (i - r + 1) + r);
296
309
  }
297
310
  next_interval(e, t) {
@@ -303,7 +316,7 @@ var me = class {
303
316
  }
304
317
  next_difficulty(e, t) {
305
318
  let n = -this.param.w[6] * (t - 3), r = e + this.linear_damping(n, e);
306
- return this.constrain_difficulty(this.mean_reversion(this.init_difficulty(u.Easy), r));
319
+ return this.constrain_difficulty(this.mean_reversion(this.init_difficulty(f.Easy), r));
307
320
  }
308
321
  constrain_difficulty(e) {
309
322
  return Math.min(Math.max(+e.toFixed(8), 1), 10);
@@ -312,7 +325,7 @@ var me = class {
312
325
  return +(this.param.w[7] * e + (1 - this.param.w[7]) * t).toFixed(8);
313
326
  }
314
327
  next_recall_stability(e, t, n, r) {
315
- let i = u.Hard === r ? this.param.w[15] : 1, a = u.Easy === r ? this.param.w[16] : 1;
328
+ let i = f.Hard === r ? this.param.w[15] : 1, a = f.Easy === r ? this.param.w[16] : 1;
316
329
  return +v(t * (1 + Math.exp(this.param.w[8]) * (11 - e) * t ** +-this.param.w[9] * (Math.exp((1 - n) * this.param.w[10]) - 1) * i * a), y, 36500).toFixed(8);
317
330
  }
318
331
  next_forget_stability(e, t, n) {
@@ -321,7 +334,7 @@ var me = class {
321
334
  next_short_term_stability(e, t) {
322
335
  return +v(e * Math.exp(this.param.w[17] * (t - 3 + this.param.w[18])), y, 36500).toFixed(8);
323
336
  }
324
- forgetting_curve = pe;
337
+ forgetting_curve = he;
325
338
  next_state(e, t, n) {
326
339
  let { difficulty: r, stability: i } = e ?? {
327
340
  difficulty: 0,
@@ -349,46 +362,46 @@ var me = class {
349
362
  };
350
363
  }
351
364
  };
352
- function he() {
365
+ function _e() {
353
366
  return `${this.review_time.getTime()}_${this.current.reps}_${this.current.difficulty * this.current.stability}`;
354
367
  }
355
- var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge = class {
368
+ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ve = class {
356
369
  last;
357
370
  current;
358
371
  review_time;
359
372
  next = /* @__PURE__ */ new Map();
360
373
  algorithm;
361
374
  initSeedStrategy;
362
- constructor(e, t, n, r = { seed: he }) {
363
- this.algorithm = n, this.initSeedStrategy = r.seed.bind(this), this.last = d.card(e), this.current = d.card(e), this.review_time = d.time(t), this.init();
375
+ constructor(e, t, n, r = { seed: _e }) {
376
+ this.algorithm = n, this.initSeedStrategy = r.seed.bind(this), this.last = p.card(e), this.current = p.card(e), this.review_time = p.time(t), this.init();
364
377
  }
365
378
  init() {
366
379
  let { state: e, last_review: t } = this.current, n = 0;
367
- e !== l.New && t && (n = ae(t, this.review_time)), this.current.last_review = this.review_time, this.current.elapsed_days = n, this.current.reps += 1, this.algorithm.seed = this.initSeedStrategy();
380
+ e !== d.New && t && (n = se(t, this.review_time)), this.current.last_review = this.review_time, this.current.elapsed_days = n, this.current.reps += 1, this.algorithm.seed = this.initSeedStrategy();
368
381
  }
369
382
  preview() {
370
383
  return {
371
- [u.Again]: this.review(u.Again),
372
- [u.Hard]: this.review(u.Hard),
373
- [u.Good]: this.review(u.Good),
374
- [u.Easy]: this.review(u.Easy),
384
+ [f.Again]: this.review(f.Again),
385
+ [f.Hard]: this.review(f.Hard),
386
+ [f.Good]: this.review(f.Good),
387
+ [f.Easy]: this.review(f.Easy),
375
388
  [Symbol.iterator]: this.previewIterator.bind(this)
376
389
  };
377
390
  }
378
391
  *previewIterator() {
379
- for (let e of ne) yield this.review(e);
392
+ for (let e of ie) yield this.review(e);
380
393
  }
381
394
  review(e) {
382
395
  let { state: t } = this.last, n;
383
396
  switch (t) {
384
- case l.New:
397
+ case d.New:
385
398
  n = this.newState(e);
386
399
  break;
387
- case l.Learning:
388
- case l.Relearning:
400
+ case d.Learning:
401
+ case d.Relearning:
389
402
  n = this.learningState(e);
390
403
  break;
391
- case l.Review:
404
+ case d.Review:
392
405
  n = this.reviewState(e);
393
406
  break;
394
407
  }
@@ -409,24 +422,24 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
409
422
  review: this.review_time
410
423
  };
411
424
  }
412
- }, _e = class extends ge {
425
+ }, ye = class extends ve {
413
426
  newState(e) {
414
427
  let t = this.next.get(e);
415
428
  if (t) return t;
416
- let n = d.card(this.current);
429
+ let n = p.card(this.current);
417
430
  switch (n.difficulty = this.algorithm.init_difficulty(e), n.stability = this.algorithm.init_stability(e), e) {
418
- case u.Again:
419
- n.scheduled_days = 0, n.due = this.review_time.scheduler(1), n.state = l.Learning;
431
+ case f.Again:
432
+ n.scheduled_days = 0, n.due = this.review_time.scheduler(1), n.state = d.Learning;
420
433
  break;
421
- case u.Hard:
422
- n.scheduled_days = 0, n.due = this.review_time.scheduler(5), n.state = l.Learning;
434
+ case f.Hard:
435
+ n.scheduled_days = 0, n.due = this.review_time.scheduler(5), n.state = d.Learning;
423
436
  break;
424
- case u.Good:
425
- n.scheduled_days = 0, n.due = this.review_time.scheduler(10), n.state = l.Learning;
437
+ case f.Good:
438
+ n.scheduled_days = 0, n.due = this.review_time.scheduler(10), n.state = d.Learning;
426
439
  break;
427
- case u.Easy: {
440
+ case f.Easy: {
428
441
  let e = this.algorithm.next_interval(n.stability, this.current.elapsed_days);
429
- n.scheduled_days = e, n.due = this.review_time.scheduler(e, !0), n.state = l.Review;
442
+ n.scheduled_days = e, n.due = this.review_time.scheduler(e, !0), n.state = d.Review;
430
443
  break;
431
444
  }
432
445
  default: throw Error("Invalid grade");
@@ -440,22 +453,22 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
440
453
  learningState(e) {
441
454
  let t = this.next.get(e);
442
455
  if (t) return t;
443
- let { state: n, difficulty: r, stability: i } = this.last, a = d.card(this.current), o = this.current.elapsed_days;
456
+ let { state: n, difficulty: r, stability: i } = this.last, a = p.card(this.current), o = this.current.elapsed_days;
444
457
  switch (a.difficulty = this.algorithm.next_difficulty(r, e), a.stability = this.algorithm.next_short_term_stability(i, e), e) {
445
- case u.Again:
458
+ case f.Again:
446
459
  a.scheduled_days = 0, a.due = this.review_time.scheduler(5, !1), a.state = n;
447
460
  break;
448
- case u.Hard:
461
+ case f.Hard:
449
462
  a.scheduled_days = 0, a.due = this.review_time.scheduler(10), a.state = n;
450
463
  break;
451
- case u.Good: {
464
+ case f.Good: {
452
465
  let e = this.algorithm.next_interval(a.stability, o);
453
- a.scheduled_days = e, a.due = this.review_time.scheduler(e, !0), a.state = l.Review;
466
+ a.scheduled_days = e, a.due = this.review_time.scheduler(e, !0), a.state = d.Review;
454
467
  break;
455
468
  }
456
- case u.Easy: {
457
- let e = this.algorithm.next_short_term_stability(i, u.Good), t = this.algorithm.next_interval(e, o), n = Math.max(this.algorithm.next_interval(a.stability, o), t + 1);
458
- a.scheduled_days = n, a.due = this.review_time.scheduler(n, !0), a.state = l.Review;
469
+ case f.Easy: {
470
+ let e = this.algorithm.next_short_term_stability(i, f.Good), t = this.algorithm.next_interval(e, o), n = Math.max(this.algorithm.next_interval(a.stability, o), t + 1);
471
+ a.scheduled_days = n, a.due = this.review_time.scheduler(n, !0), a.state = d.Review;
459
472
  break;
460
473
  }
461
474
  default: throw Error("Invalid grade");
@@ -469,27 +482,27 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
469
482
  reviewState(e) {
470
483
  let t = this.next.get(e);
471
484
  if (t) return t;
472
- let n = this.current.elapsed_days, { difficulty: r, stability: i } = this.last, a = this.algorithm.forgetting_curve(n, i), o = d.card(this.current), s = d.card(this.current), c = d.card(this.current), l = d.card(this.current);
485
+ let n = this.current.elapsed_days, { difficulty: r, stability: i } = this.last, a = this.algorithm.forgetting_curve(n, i), o = p.card(this.current), s = p.card(this.current), c = p.card(this.current), l = p.card(this.current);
473
486
  this.next_ds(o, s, c, l, r, i, a), this.next_interval(o, s, c, l, n), this.next_state(o, s, c, l), o.lapses += 1;
474
- let f = {
487
+ let u = {
475
488
  card: o,
476
- log: this.buildLog(u.Again)
477
- }, p = {
489
+ log: this.buildLog(f.Again)
490
+ }, d = {
478
491
  card: s,
479
- log: super.buildLog(u.Hard)
492
+ log: super.buildLog(f.Hard)
480
493
  }, m = {
481
494
  card: c,
482
- log: super.buildLog(u.Good)
495
+ log: super.buildLog(f.Good)
483
496
  }, ee = {
484
497
  card: l,
485
- log: super.buildLog(u.Easy)
498
+ log: super.buildLog(f.Easy)
486
499
  };
487
- return this.next.set(u.Again, f), this.next.set(u.Hard, p), this.next.set(u.Good, m), this.next.set(u.Easy, ee), this.next.get(e);
500
+ return this.next.set(f.Again, u), this.next.set(f.Hard, d), this.next.set(f.Good, m), this.next.set(f.Easy, ee), this.next.get(e);
488
501
  }
489
502
  next_ds(e, t, n, r, i, a, o) {
490
- e.difficulty = this.algorithm.next_difficulty(i, u.Again);
503
+ e.difficulty = this.algorithm.next_difficulty(i, f.Again);
491
504
  let s = a / Math.exp(this.algorithm.parameters.w[17] * this.algorithm.parameters.w[18]), c = this.algorithm.next_forget_stability(i, a, o);
492
- e.stability = v(+s.toFixed(8), y, c), t.difficulty = this.algorithm.next_difficulty(i, u.Hard), t.stability = this.algorithm.next_recall_stability(i, a, o, u.Hard), n.difficulty = this.algorithm.next_difficulty(i, u.Good), n.stability = this.algorithm.next_recall_stability(i, a, o, u.Good), r.difficulty = this.algorithm.next_difficulty(i, u.Easy), r.stability = this.algorithm.next_recall_stability(i, a, o, u.Easy);
505
+ e.stability = v(+s.toFixed(8), y, c), t.difficulty = this.algorithm.next_difficulty(i, f.Hard), t.stability = this.algorithm.next_recall_stability(i, a, o, f.Hard), n.difficulty = this.algorithm.next_difficulty(i, f.Good), n.stability = this.algorithm.next_recall_stability(i, a, o, f.Good), r.difficulty = this.algorithm.next_difficulty(i, f.Easy), r.stability = this.algorithm.next_recall_stability(i, a, o, f.Easy);
493
506
  }
494
507
  next_interval(e, t, n, r, i) {
495
508
  let a, o;
@@ -498,18 +511,18 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
498
511
  e.scheduled_days = 0, e.due = this.review_time.scheduler(5), t.scheduled_days = a, t.due = this.review_time.scheduler(a, !0), n.scheduled_days = o, n.due = this.review_time.scheduler(o, !0), r.scheduled_days = s, r.due = this.review_time.scheduler(s, !0);
499
512
  }
500
513
  next_state(e, t, n, r) {
501
- e.state = l.Relearning, t.state = l.Review, n.state = l.Review, r.state = l.Review;
514
+ e.state = d.Relearning, t.state = d.Review, n.state = d.Review, r.state = d.Review;
502
515
  }
503
- }, ve = class extends ge {
516
+ }, be = class extends ve {
504
517
  newState(e) {
505
518
  let t = this.next.get(e);
506
519
  if (t) return t;
507
520
  this.current.scheduled_days = 0, this.current.elapsed_days = 0;
508
- let n = d.card(this.current), r = d.card(this.current), i = d.card(this.current), a = d.card(this.current);
521
+ let n = p.card(this.current), r = p.card(this.current), i = p.card(this.current), a = p.card(this.current);
509
522
  return this.init_ds(n, r, i, a), this.next_interval(n, r, i, a, 0), this.next_state(n, r, i, a), this.update_next(n, r, i, a), this.next.get(e);
510
523
  }
511
524
  init_ds(e, t, n, r) {
512
- e.difficulty = this.algorithm.init_difficulty(u.Again), e.stability = this.algorithm.init_stability(u.Again), t.difficulty = this.algorithm.init_difficulty(u.Hard), t.stability = this.algorithm.init_stability(u.Hard), n.difficulty = this.algorithm.init_difficulty(u.Good), n.stability = this.algorithm.init_stability(u.Good), r.difficulty = this.algorithm.init_difficulty(u.Easy), r.stability = this.algorithm.init_stability(u.Easy);
525
+ e.difficulty = this.algorithm.init_difficulty(f.Again), e.stability = this.algorithm.init_stability(f.Again), t.difficulty = this.algorithm.init_difficulty(f.Hard), t.stability = this.algorithm.init_stability(f.Hard), n.difficulty = this.algorithm.init_difficulty(f.Good), n.stability = this.algorithm.init_stability(f.Good), r.difficulty = this.algorithm.init_difficulty(f.Easy), r.stability = this.algorithm.init_stability(f.Easy);
513
526
  }
514
527
  learningState(e) {
515
528
  return this.reviewState(e);
@@ -517,36 +530,36 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
517
530
  reviewState(e) {
518
531
  let t = this.next.get(e);
519
532
  if (t) return t;
520
- let n = this.current.elapsed_days, { difficulty: r, stability: i } = this.last, a = this.algorithm.forgetting_curve(n, i), o = d.card(this.current), s = d.card(this.current), c = d.card(this.current), l = d.card(this.current);
533
+ let n = this.current.elapsed_days, { difficulty: r, stability: i } = this.last, a = this.algorithm.forgetting_curve(n, i), o = p.card(this.current), s = p.card(this.current), c = p.card(this.current), l = p.card(this.current);
521
534
  return this.next_ds(o, s, c, l, r, i, a), this.next_interval(o, s, c, l, n), this.next_state(o, s, c, l), o.lapses += 1, this.update_next(o, s, c, l), this.next.get(e);
522
535
  }
523
536
  next_ds(e, t, n, r, i, a, o) {
524
- e.difficulty = this.algorithm.next_difficulty(i, u.Again), e.stability = v(a, y, this.algorithm.next_forget_stability(i, a, o)), t.difficulty = this.algorithm.next_difficulty(i, u.Hard), t.stability = this.algorithm.next_recall_stability(i, a, o, u.Hard), n.difficulty = this.algorithm.next_difficulty(i, u.Good), n.stability = this.algorithm.next_recall_stability(i, a, o, u.Good), r.difficulty = this.algorithm.next_difficulty(i, u.Easy), r.stability = this.algorithm.next_recall_stability(i, a, o, u.Easy);
537
+ e.difficulty = this.algorithm.next_difficulty(i, f.Again), e.stability = v(a, y, this.algorithm.next_forget_stability(i, a, o)), t.difficulty = this.algorithm.next_difficulty(i, f.Hard), t.stability = this.algorithm.next_recall_stability(i, a, o, f.Hard), n.difficulty = this.algorithm.next_difficulty(i, f.Good), n.stability = this.algorithm.next_recall_stability(i, a, o, f.Good), r.difficulty = this.algorithm.next_difficulty(i, f.Easy), r.stability = this.algorithm.next_recall_stability(i, a, o, f.Easy);
525
538
  }
526
539
  next_interval(e, t, n, r, i) {
527
540
  let a, o, s, c;
528
541
  a = this.algorithm.next_interval(e.stability, i), o = this.algorithm.next_interval(t.stability, i), s = this.algorithm.next_interval(n.stability, i), c = this.algorithm.next_interval(r.stability, i), a = Math.min(a, o), o = Math.max(o, a + 1), s = Math.max(s, o + 1), c = Math.max(c, s + 1), e.scheduled_days = a, e.due = this.review_time.scheduler(a, !0), t.scheduled_days = o, t.due = this.review_time.scheduler(o, !0), n.scheduled_days = s, n.due = this.review_time.scheduler(s, !0), r.scheduled_days = c, r.due = this.review_time.scheduler(c, !0);
529
542
  }
530
543
  next_state(e, t, n, r) {
531
- e.state = l.Review, t.state = l.Review, n.state = l.Review, r.state = l.Review;
544
+ e.state = d.Review, t.state = d.Review, n.state = d.Review, r.state = d.Review;
532
545
  }
533
546
  update_next(e, t, n, r) {
534
547
  let i = {
535
548
  card: e,
536
- log: this.buildLog(u.Again)
549
+ log: this.buildLog(f.Again)
537
550
  }, a = {
538
551
  card: t,
539
- log: super.buildLog(u.Hard)
552
+ log: super.buildLog(f.Hard)
540
553
  }, o = {
541
554
  card: n,
542
- log: super.buildLog(u.Good)
555
+ log: super.buildLog(f.Good)
543
556
  }, s = {
544
557
  card: r,
545
- log: super.buildLog(u.Easy)
558
+ log: super.buildLog(f.Easy)
546
559
  };
547
- this.next.set(u.Again, i), this.next.set(u.Hard, a), this.next.set(u.Good, o), this.next.set(u.Easy, s);
560
+ this.next.set(f.Again, i), this.next.set(f.Hard, a), this.next.set(f.Good, o), this.next.set(f.Easy, s);
548
561
  }
549
- }, ye = class {
562
+ }, xe = class {
550
563
  fsrs;
551
564
  constructor(e) {
552
565
  this.fsrs = e;
@@ -557,8 +570,8 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
557
570
  handleManualRating(e, t, n, r, i, a, o) {
558
571
  if (typeof t > "u") throw Error("reschedule: state is required for manual rating");
559
572
  let s, c;
560
- if (t === l.New) s = {
561
- rating: u.Manual,
573
+ if (t === d.New) s = {
574
+ rating: f.Manual,
562
575
  state: t,
563
576
  due: o ?? n,
564
577
  stability: e.stability,
@@ -572,7 +585,7 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
572
585
  if (typeof o > "u") throw Error("reschedule: due is required for manual rating");
573
586
  let l = o.diff(n, "days");
574
587
  s = {
575
- rating: u.Manual,
588
+ rating: f.Manual,
576
589
  state: e.state,
577
590
  due: e.last_review || e.due,
578
591
  stability: e.stability,
@@ -602,9 +615,9 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
602
615
  let n = [], r = x(e.due);
603
616
  for (let e of t) {
604
617
  let t;
605
- if (e.review = d.time(e.review), e.rating === u.Manual) {
618
+ if (e.review = p.time(e.review), e.rating === f.Manual) {
606
619
  let n = 0;
607
- r.state !== l.New && r.last_review && (n = e.review.diff(r.last_review, "days")), t = this.handleManualRating(r, e.state, e.review, n, e.stability, e.difficulty, e.due ? d.time(e.due) : void 0);
620
+ r.state !== d.New && r.last_review && (n = e.review.diff(r.last_review, "days")), t = this.handleManualRating(r, e.state, e.review, n, e.stability, e.difficulty, e.due ? p.time(e.due) : void 0);
608
621
  } else t = this.replay(r, e.review, e.rating);
609
622
  n.push(t), r = t.card;
610
623
  }
@@ -612,21 +625,21 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
612
625
  }
613
626
  calculateManualRecord(e, t, n, r) {
614
627
  if (!n) return null;
615
- let { card: i, log: a } = n, o = d.card(e);
616
- return o.due.getTime() === i.due.getTime() ? null : (o.scheduled_days = i.due.diff(o.due, "days"), this.handleManualRating(o, i.state, d.time(t), a.elapsed_days, r ? i.stability : void 0, r ? i.difficulty : void 0, i.due));
628
+ let { card: i, log: a } = n, o = p.card(e);
629
+ return o.due.getTime() === i.due.getTime() ? null : (o.scheduled_days = i.due.diff(o.due, "days"), this.handleManualRating(o, i.state, p.time(t), a.elapsed_days, r ? i.stability : void 0, r ? i.difficulty : void 0, i.due));
617
630
  }
618
- }, be = class extends me {
631
+ }, Se = class extends ge {
619
632
  strategyHandler = /* @__PURE__ */ new Map();
620
633
  Scheduler;
621
634
  constructor(e) {
622
635
  super(e);
623
636
  let { enable_short_term: t } = this.parameters;
624
- this.Scheduler = t ? _e : ve;
637
+ this.Scheduler = t ? ye : be;
625
638
  }
626
639
  params_handler_proxy() {
627
640
  let e = this;
628
641
  return { set: function(t, n, r) {
629
- return n === "request_retention" && Number.isFinite(r) ? e.intervalModifier = e.calculate_interval_modifier(Number(r)) : n === "enable_short_term" && (e.Scheduler = r === !0 ? _e : ve), Reflect.set(t, n, r), !0;
642
+ return n === "request_retention" && Number.isFinite(r) ? e.intervalModifier = e.calculate_interval_modifier(Number(r)) : n === "enable_short_term" && (e.Scheduler = r === !0 ? ye : be), Reflect.set(t, n, r), !0;
630
643
  } };
631
644
  }
632
645
  useStrategy(e, t) {
@@ -637,36 +650,36 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
637
650
  }
638
651
  getScheduler(e, t) {
639
652
  let n = this.strategyHandler.get(S.SEED);
640
- return new ((this.strategyHandler.get(S.SCHEDULER)) || this.Scheduler)(e, t, this, { seed: n || he });
653
+ return new ((this.strategyHandler.get(S.SCHEDULER)) || this.Scheduler)(e, t, this, { seed: n || _e });
641
654
  }
642
655
  repeat(e, t, n) {
643
656
  let r = this.getScheduler(e, t).preview();
644
657
  return n && typeof n == "function" ? n(r) : r;
645
658
  }
646
659
  next(e, t, n, r) {
647
- let i = this.getScheduler(e, t), a = d.rating(n);
648
- if (a === u.Manual) throw Error("Cannot review a manual rating");
660
+ let i = this.getScheduler(e, t), a = p.rating(n);
661
+ if (a === f.Manual) throw Error("Cannot review a manual rating");
649
662
  let o = i.review(a);
650
663
  return r && typeof r == "function" ? r(o) : o;
651
664
  }
652
665
  get_retrievability(e, t, n = !0) {
653
- let r = d.card(e);
654
- t = t ? d.time(t) : /* @__PURE__ */ new Date();
655
- let i = r.state === l.New ? 0 : Math.max(t.diff(r.last_review, "days"), 0), a = r.state === l.New ? 0 : this.forgetting_curve(i, +r.stability.toFixed(8));
666
+ let r = p.card(e);
667
+ t = t ? p.time(t) : /* @__PURE__ */ new Date();
668
+ let i = r.state === d.New ? 0 : Math.max(t.diff(r.last_review, "days"), 0), a = r.state === d.New ? 0 : this.forgetting_curve(i, +r.stability.toFixed(8));
656
669
  return n ? `${(a * 100).toFixed(2)}%` : a;
657
670
  }
658
671
  rollback(e, t, n) {
659
- let r = d.card(e), i = d.review_log(t);
660
- if (i.rating === u.Manual) throw Error("Cannot rollback a manual rating");
672
+ let r = p.card(e), i = p.review_log(t);
673
+ if (i.rating === f.Manual) throw Error("Cannot rollback a manual rating");
661
674
  let a, o, s;
662
675
  switch (i.state) {
663
- case l.New:
676
+ case d.New:
664
677
  a = i.due, o = void 0, s = 0;
665
678
  break;
666
- case l.Learning:
667
- case l.Relearning:
668
- case l.Review:
669
- a = i.review, o = i.due, s = r.lapses - +(i.rating === u.Again && i.state === l.Review);
679
+ case d.Learning:
680
+ case d.Relearning:
681
+ case d.Review:
682
+ a = i.review, o = i.due, s = r.lapses - +(i.rating === f.Again && i.state === d.Review);
670
683
  break;
671
684
  }
672
685
  let c = {
@@ -684,10 +697,10 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
684
697
  return n && typeof n == "function" ? n(c) : c;
685
698
  }
686
699
  forget(e, t, n = !1, r) {
687
- let i = d.card(e);
688
- t = d.time(t);
689
- let a = i.state === l.New ? 0 : t.diff(i.last_review, "days"), o = {
690
- rating: u.Manual,
700
+ let i = p.card(e);
701
+ t = p.time(t);
702
+ let a = i.state === d.New ? 0 : t.diff(i.last_review, "days"), o = {
703
+ rating: f.Manual,
691
704
  state: i.state,
692
705
  due: i.due,
693
706
  stability: i.stability,
@@ -706,7 +719,7 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
706
719
  scheduled_days: 0,
707
720
  reps: n ? 0 : i.reps,
708
721
  lapses: n ? 0 : i.lapses,
709
- state: l.New,
722
+ state: d.New,
710
723
  last_review: i.last_review
711
724
  },
712
725
  log: o
@@ -715,8 +728,8 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
715
728
  }
716
729
  reschedule(e, t = [], n = {}) {
717
730
  let { recordLogHandler: r, reviewsOrderBy: i, skipManual: a = !0, now: o = /* @__PURE__ */ new Date(), update_memory_state: s = !1 } = n;
718
- i && typeof i == "function" && t.sort(i), a && (t = t.filter((e) => e.rating !== u.Manual));
719
- let c = new ye(this), l = c.reschedule(n.first_card || x(), t), f = l.length, p = d.card(e), m = c.calculateManualRecord(p, o, f ? l[f - 1] : void 0, s);
731
+ i && typeof i == "function" && t.sort(i), a && (t = t.filter((e) => e.rating !== f.Manual));
732
+ let c = new xe(this), l = c.reschedule(n.first_card || x(), t), u = l.length, d = p.card(e), m = c.calculateManualRecord(d, o, u ? l[u - 1] : void 0, s);
720
733
  return r && typeof r == "function" ? {
721
734
  collections: l.map(r),
722
735
  reschedule_item: m ? r(m) : null
@@ -725,14 +738,14 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
725
738
  reschedule_item: m
726
739
  };
727
740
  }
728
- }, xe = ((e) => new be(e || {}))(b({
741
+ }, Ce = ((e) => new Se(e || {}))(b({
729
742
  request_retention: i,
730
743
  enable_fuzz: !0,
731
744
  maximum_interval: 100
732
- })), Se = (e) => e.due ? e : {
745
+ })), we = (e) => e.due ? e : {
733
746
  ...e,
734
747
  due: /* @__PURE__ */ new Date()
735
- }, Ce = (e) => t.indexOf(e), we = (e) => ({
748
+ }, Te = (e) => t.indexOf(e), Ee = (e) => ({
736
749
  due: e.due,
737
750
  stability: e.stability,
738
751
  difficulty: e.difficulty,
@@ -740,19 +753,19 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
740
753
  scheduled_days: e.scheduledDays,
741
754
  reps: e.reps,
742
755
  lapses: e.lapses,
743
- state: Ce(e.state),
756
+ state: Te(e.state),
744
757
  last_review: e.lastReview
745
- }), Te = (e, t, n) => {
746
- let r = /* @__PURE__ */ new Date(), i = we(Se(e));
747
- return xe.repeat(i, r, (r) => {
748
- let i = r[ke(t)], a = C(i.card, e), o = i.log;
758
+ }), De = (e, t, n) => {
759
+ let r = /* @__PURE__ */ new Date(), i = Ee(we(e));
760
+ return Ce.repeat(i, r, (r) => {
761
+ let i = r[je(t)], a = C(i.card, e), o = i.log;
749
762
  return {
750
763
  nextCard: a,
751
764
  reviewLog: {
752
765
  id: 0,
753
766
  cardReviewId: e.id,
754
767
  grade: t,
755
- state: Oe(o.state),
768
+ state: Ae(o.state),
756
769
  due: o.due,
757
770
  stability: o.stability,
758
771
  difficulty: o.difficulty,
@@ -765,18 +778,18 @@ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge =
765
778
  };
766
779
  });
767
780
  };
768
- function Ee(e) {
769
- let t = /* @__PURE__ */ new Date(), n = we(Se(e)), i = xe.repeat(n, t), a = Object.fromEntries(r.map((e) => [e, /* @__PURE__ */ new Date()]));
770
- for (let e of ne) {
771
- let t = i[e].card.due, n = De(e);
781
+ function Oe(e) {
782
+ let t = /* @__PURE__ */ new Date(), n = Ee(we(e)), i = Ce.repeat(n, t), a = Object.fromEntries(r.map((e) => [e, /* @__PURE__ */ new Date()]));
783
+ for (let e of ie) {
784
+ let t = i[e].card.due, n = ke(e);
772
785
  a[n] = t;
773
786
  }
774
787
  return a;
775
788
  }
776
- function De(e) {
789
+ function ke(e) {
777
790
  return r[e];
778
791
  }
779
- function Oe(e) {
792
+ function Ae(e) {
780
793
  return t[e];
781
794
  }
782
795
  function C(e, t) {
@@ -789,16 +802,16 @@ function C(e, t) {
789
802
  scheduledDays: e.scheduled_days,
790
803
  reps: e.reps,
791
804
  lapses: e.lapses,
792
- state: Oe(e.state),
805
+ state: Ae(e.state),
793
806
  lastReview: e.last_review ?? null
794
807
  };
795
808
  }
796
- function ke(e) {
809
+ function je(e) {
797
810
  let t = r.indexOf(e);
798
811
  if (t === -1) throw Error(`Invalid rating: ${e}`);
799
812
  return t;
800
813
  }
801
- function Ae(e, t) {
814
+ function Me(e, t) {
802
815
  let r = x();
803
816
  return {
804
817
  id: "",
@@ -816,8 +829,16 @@ function Ae(e, t) {
816
829
  };
817
830
  }
818
831
  //#endregion
832
+ //#region src/spaced-repetition/retention.ts
833
+ function Ne(e, t) {
834
+ return t <= 0 ? 0 : (1 + o * e / t) ** -a;
835
+ }
836
+ function Pe(e, t) {
837
+ return Ne(e, t) * 100;
838
+ }
839
+ //#endregion
819
840
  //#region ../../node_modules/immer/dist/immer.mjs
820
- var je = Symbol.for("immer-nothing"), Me = Symbol.for("immer-draftable"), w = Symbol.for("immer-state"), Ne = process.env.NODE_ENV === "production" ? [] : [
841
+ var Fe = Symbol.for("immer-nothing"), Ie = Symbol.for("immer-draftable"), w = Symbol.for("immer-state"), Le = process.env.NODE_ENV === "production" ? [] : [
821
842
  function(e) {
822
843
  return `The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`;
823
844
  },
@@ -847,7 +868,7 @@ var je = Symbol.for("immer-nothing"), Me = Symbol.for("immer-draftable"), w = Sy
847
868
  ];
848
869
  function T(e, ...t) {
849
870
  if (process.env.NODE_ENV !== "production") {
850
- let n = Ne[e], r = typeof n == "function" ? n.apply(null, t) : n;
871
+ let n = Le[e], r = typeof n == "function" ? n.apply(null, t) : n;
851
872
  throw Error(`[Immer] ${r}`);
852
873
  }
853
874
  throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`);
@@ -857,18 +878,18 @@ function D(e) {
857
878
  return !!e && !!e[w];
858
879
  }
859
880
  function O(e) {
860
- return e ? Ie(e) || Array.isArray(e) || !!e[Me] || !!e.constructor?.[Me] || M(e) || N(e) : !1;
881
+ return e ? Be(e) || Array.isArray(e) || !!e[Ie] || !!e.constructor?.[Ie] || M(e) || N(e) : !1;
861
882
  }
862
- var Pe = Object.prototype.constructor.toString(), Fe = /* @__PURE__ */ new WeakMap();
863
- function Ie(e) {
883
+ var Re = Object.prototype.constructor.toString(), ze = /* @__PURE__ */ new WeakMap();
884
+ function Be(e) {
864
885
  if (!e || typeof e != "object") return !1;
865
886
  let t = Object.getPrototypeOf(e);
866
887
  if (t === null || t === Object.prototype) return !0;
867
888
  let n = Object.hasOwnProperty.call(t, "constructor") && t.constructor;
868
889
  if (n === Object) return !0;
869
890
  if (typeof n != "function") return !1;
870
- let r = Fe.get(n);
871
- return r === void 0 && (r = Function.toString.call(n), Fe.set(n, r)), r === Pe;
891
+ let r = ze.get(n);
892
+ return r === void 0 && (r = Function.toString.call(n), ze.set(n, r)), r === Re;
872
893
  }
873
894
  function k(e, t, n = !0) {
874
895
  A(e) === 0 ? (n ? Reflect.ownKeys(e) : Object.keys(e)).forEach((n) => {
@@ -882,11 +903,11 @@ function A(e) {
882
903
  function j(e, t) {
883
904
  return A(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
884
905
  }
885
- function Le(e, t, n) {
906
+ function Ve(e, t, n) {
886
907
  let r = A(e);
887
908
  r === 2 ? e.set(t, n) : r === 3 ? e.add(n) : e[t] = n;
888
909
  }
889
- function Re(e, t) {
910
+ function He(e, t) {
890
911
  return e === t ? e !== 0 || 1 / e == 1 / t : e !== e && t !== t;
891
912
  }
892
913
  function M(e) {
@@ -902,7 +923,7 @@ function F(e, t) {
902
923
  if (M(e)) return new Map(e);
903
924
  if (N(e)) return new Set(e);
904
925
  if (Array.isArray(e)) return Array.prototype.slice.call(e);
905
- let n = Ie(e);
926
+ let n = Be(e);
906
927
  if (t === !0 || t === "class_only" && !n) {
907
928
  let t = Object.getOwnPropertyDescriptors(e);
908
929
  delete t[w];
@@ -930,23 +951,23 @@ function I(e, t = !1) {
930
951
  delete: L
931
952
  }), Object.freeze(e), t && Object.values(e).forEach((e) => I(e, !0)), e);
932
953
  }
933
- function ze() {
954
+ function Ue() {
934
955
  T(2);
935
956
  }
936
- var L = { value: ze };
957
+ var L = { value: Ue };
937
958
  function R(e) {
938
959
  return typeof e != "object" || !e ? !0 : Object.isFrozen(e);
939
960
  }
940
- var Be = {};
961
+ var We = {};
941
962
  function z(e) {
942
- let t = Be[e];
963
+ let t = We[e];
943
964
  return t || T(0, e), t;
944
965
  }
945
966
  var B;
946
- function Ve() {
967
+ function Ge() {
947
968
  return B;
948
969
  }
949
- function He(e, t) {
970
+ function Ke(e, t) {
950
971
  return {
951
972
  drafts_: [],
952
973
  parent_: e,
@@ -955,47 +976,47 @@ function He(e, t) {
955
976
  unfinalizedDrafts_: 0
956
977
  };
957
978
  }
958
- function Ue(e, t) {
979
+ function qe(e, t) {
959
980
  t && (z("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
960
981
  }
961
982
  function V(e) {
962
- H(e), e.drafts_.forEach(Ge), e.drafts_ = null;
983
+ H(e), e.drafts_.forEach(Ye), e.drafts_ = null;
963
984
  }
964
985
  function H(e) {
965
986
  e === B && (B = e.parent_);
966
987
  }
967
- function We(e) {
968
- return B = He(B, e);
988
+ function Je(e) {
989
+ return B = Ke(B, e);
969
990
  }
970
- function Ge(e) {
991
+ function Ye(e) {
971
992
  let t = e[w];
972
993
  t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
973
994
  }
974
- function Ke(e, t) {
995
+ function Xe(e, t) {
975
996
  t.unfinalizedDrafts_ = t.drafts_.length;
976
997
  let n = t.drafts_[0];
977
- return e !== void 0 && e !== n ? (n[w].modified_ && (V(t), T(4)), O(e) && (e = U(t, e), t.parent_ || W(t, e)), t.patches_ && z("Patches").generateReplacementPatches_(n[w].base_, e, t.patches_, t.inversePatches_)) : e = U(t, n, []), V(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e === je ? void 0 : e;
998
+ return e !== void 0 && e !== n ? (n[w].modified_ && (V(t), T(4)), O(e) && (e = U(t, e), t.parent_ || W(t, e)), t.patches_ && z("Patches").generateReplacementPatches_(n[w].base_, e, t.patches_, t.inversePatches_)) : e = U(t, n, []), V(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e === Fe ? void 0 : e;
978
999
  }
979
1000
  function U(e, t, n) {
980
1001
  if (R(t)) return t;
981
1002
  let r = e.immer_.shouldUseStrictIteration(), i = t[w];
982
- if (!i) return k(t, (r, a) => qe(e, i, t, r, a, n), r), t;
1003
+ if (!i) return k(t, (r, a) => Ze(e, i, t, r, a, n), r), t;
983
1004
  if (i.scope_ !== e) return t;
984
1005
  if (!i.modified_) return W(e, i.base_, !0), i.base_;
985
1006
  if (!i.finalized_) {
986
1007
  i.finalized_ = !0, i.scope_.unfinalizedDrafts_--;
987
1008
  let t = i.copy_, a = t, o = !1;
988
- i.type_ === 3 && (a = new Set(t), t.clear(), o = !0), k(a, (r, a) => qe(e, i, t, r, a, n, o), r), W(e, t, !1), n && e.patches_ && z("Patches").generatePatches_(i, n, e.patches_, e.inversePatches_);
1009
+ i.type_ === 3 && (a = new Set(t), t.clear(), o = !0), k(a, (r, a) => Ze(e, i, t, r, a, n, o), r), W(e, t, !1), n && e.patches_ && z("Patches").generatePatches_(i, n, e.patches_, e.inversePatches_);
989
1010
  }
990
1011
  return i.copy_;
991
1012
  }
992
- function qe(e, t, n, r, i, a, o) {
1013
+ function Ze(e, t, n, r, i, a, o) {
993
1014
  if (i == null || typeof i != "object" && !o) return;
994
1015
  let s = R(i);
995
1016
  if (!(s && !o)) {
996
1017
  if (process.env.NODE_ENV !== "production" && i === n && T(5), D(i)) {
997
1018
  let o = U(e, i, a && t && t.type_ !== 3 && !j(t.assigned_, r) ? a.concat(r) : void 0);
998
- if (Le(n, r, o), D(o)) e.canAutoFreeze_ = !1;
1019
+ if (Ve(n, r, o), D(o)) e.canAutoFreeze_ = !1;
999
1020
  else return;
1000
1021
  } else o && n.add(i);
1001
1022
  if (O(i) && !s) {
@@ -1007,10 +1028,10 @@ function qe(e, t, n, r, i, a, o) {
1007
1028
  function W(e, t, n = !1) {
1008
1029
  !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && I(t, n);
1009
1030
  }
1010
- function Je(e, t) {
1031
+ function Qe(e, t) {
1011
1032
  let n = Array.isArray(e), r = {
1012
1033
  type_: +!!n,
1013
- scope_: t ? t.scope_ : Ve(),
1034
+ scope_: t ? t.scope_ : Ge(),
1014
1035
  modified_: !1,
1015
1036
  finalized_: !1,
1016
1037
  assigned_: {},
@@ -1029,7 +1050,7 @@ var G = {
1029
1050
  get(e, t) {
1030
1051
  if (t === w) return e;
1031
1052
  let n = P(e);
1032
- if (!j(n, t)) return Ye(e, n, t);
1053
+ if (!j(n, t)) return $e(e, n, t);
1033
1054
  let r = n[t];
1034
1055
  return e.finalized_ || !O(r) ? r : r === q(e.base_, t) ? (Y(e), e.copy_[t] = X(r, e)) : r;
1035
1056
  },
@@ -1040,12 +1061,12 @@ var G = {
1040
1061
  return Reflect.ownKeys(P(e));
1041
1062
  },
1042
1063
  set(e, t, n) {
1043
- let r = Xe(P(e), t);
1064
+ let r = et(P(e), t);
1044
1065
  if (r?.set) return r.set.call(e.draft_, n), !0;
1045
1066
  if (!e.modified_) {
1046
1067
  let r = q(P(e), t), i = r?.[w];
1047
1068
  if (i && i.base_ === n) return e.copy_[t] = n, e.assigned_[t] = !1, !0;
1048
- if (Re(n, r) && (n !== void 0 || j(e.base_, t))) return !0;
1069
+ if (He(n, r) && (n !== void 0 || j(e.base_, t))) return !0;
1049
1070
  Y(e), J(e);
1050
1071
  }
1051
1072
  return e.copy_[t] === n && (n !== void 0 || t in e.copy_) || Number.isNaN(n) && Number.isNaN(e.copy_[t]) ? !0 : (e.copy_[t] = n, e.assigned_[t] = !0, !0);
@@ -1085,11 +1106,11 @@ function q(e, t) {
1085
1106
  let n = e[w];
1086
1107
  return (n ? P(n) : e)[t];
1087
1108
  }
1088
- function Ye(e, t, n) {
1089
- let r = Xe(t, n);
1109
+ function $e(e, t, n) {
1110
+ let r = et(t, n);
1090
1111
  return r ? "value" in r ? r.value : r.get?.call(e.draft_) : void 0;
1091
1112
  }
1092
- function Xe(e, t) {
1113
+ function et(e, t) {
1093
1114
  if (!(t in e)) return;
1094
1115
  let n = E(e);
1095
1116
  for (; n;) {
@@ -1104,7 +1125,7 @@ function J(e) {
1104
1125
  function Y(e) {
1105
1126
  e.copy_ ||= F(e.base_, e.scope_.immer_.useStrictShallowCopy_);
1106
1127
  }
1107
- var Ze = class {
1128
+ var tt = class {
1108
1129
  constructor(e) {
1109
1130
  this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !0, this.produce = (e, t, n) => {
1110
1131
  if (typeof e == "function" && typeof t != "function") {
@@ -1118,15 +1139,15 @@ var Ze = class {
1118
1139
  typeof t != "function" && T(6), n !== void 0 && typeof n != "function" && T(7);
1119
1140
  let r;
1120
1141
  if (O(e)) {
1121
- let i = We(this), a = X(e, void 0), o = !0;
1142
+ let i = Je(this), a = X(e, void 0), o = !0;
1122
1143
  try {
1123
1144
  r = t(a), o = !1;
1124
1145
  } finally {
1125
1146
  o ? V(i) : H(i);
1126
1147
  }
1127
- return Ue(i, n), Ke(r, i);
1148
+ return qe(i, n), Xe(r, i);
1128
1149
  } else if (!e || typeof e != "object") {
1129
- if (r = t(e), r === void 0 && (r = e), r === je && (r = void 0), this.autoFreeze_ && I(r, !0), n) {
1150
+ if (r = t(e), r === void 0 && (r = e), r === Fe && (r = void 0), this.autoFreeze_ && I(r, !0), n) {
1130
1151
  let t = [], i = [];
1131
1152
  z("Patches").generateReplacementPatches_(e, r, t, i), n(t, i);
1132
1153
  }
@@ -1145,15 +1166,15 @@ var Ze = class {
1145
1166
  }, typeof e?.autoFreeze == "boolean" && this.setAutoFreeze(e.autoFreeze), typeof e?.useStrictShallowCopy == "boolean" && this.setUseStrictShallowCopy(e.useStrictShallowCopy), typeof e?.useStrictIteration == "boolean" && this.setUseStrictIteration(e.useStrictIteration);
1146
1167
  }
1147
1168
  createDraft(e) {
1148
- O(e) || T(8), D(e) && (e = Qe(e));
1149
- let t = We(this), n = X(e, void 0);
1169
+ O(e) || T(8), D(e) && (e = nt(e));
1170
+ let t = Je(this), n = X(e, void 0);
1150
1171
  return n[w].isManual_ = !0, H(t), n;
1151
1172
  }
1152
1173
  finishDraft(e, t) {
1153
1174
  let n = e && e[w];
1154
1175
  (!n || !n.isManual_) && T(9);
1155
1176
  let { scope_: r } = n;
1156
- return Ue(r, t), Ke(void 0, r);
1177
+ return qe(r, t), Xe(void 0, r);
1157
1178
  }
1158
1179
  setAutoFreeze(e) {
1159
1180
  this.autoFreeze_ = e;
@@ -1182,13 +1203,13 @@ var Ze = class {
1182
1203
  }
1183
1204
  };
1184
1205
  function X(e, t) {
1185
- let n = M(e) ? z("MapSet").proxyMap_(e, t) : N(e) ? z("MapSet").proxySet_(e, t) : Je(e, t);
1186
- return (t ? t.scope_ : Ve()).drafts_.push(n), n;
1206
+ let n = M(e) ? z("MapSet").proxyMap_(e, t) : N(e) ? z("MapSet").proxySet_(e, t) : Qe(e, t);
1207
+ return (t ? t.scope_ : Ge()).drafts_.push(n), n;
1187
1208
  }
1188
- function Qe(e) {
1189
- return D(e) || T(10, e), Z(e);
1209
+ function nt(e) {
1210
+ return D(e) || T(10, e), rt(e);
1190
1211
  }
1191
- function Z(e) {
1212
+ function rt(e) {
1192
1213
  if (!O(e) || R(e)) return e;
1193
1214
  let t = e[w], n, r = !0;
1194
1215
  if (t) {
@@ -1196,13 +1217,13 @@ function Z(e) {
1196
1217
  t.finalized_ = !0, n = F(e, t.scope_.immer_.useStrictShallowCopy_), r = t.scope_.immer_.shouldUseStrictIteration();
1197
1218
  } else n = F(e, !0);
1198
1219
  return k(n, (e, t) => {
1199
- Le(n, e, Z(t));
1220
+ Ve(n, e, rt(t));
1200
1221
  }, r), t && (t.finalized_ = !1), n;
1201
1222
  }
1202
- var $e = new Ze().produce;
1223
+ var Z = new tt().produce;
1203
1224
  //#endregion
1204
1225
  //#region src/spaced-repetition/utils.ts
1205
- function et(e, t) {
1226
+ function it(e, t) {
1206
1227
  let n = e + t, r = 0;
1207
1228
  for (let e = 0; e < n.length; e++) {
1208
1229
  let t = n.charCodeAt(e);
@@ -1210,10 +1231,10 @@ function et(e, t) {
1210
1231
  }
1211
1232
  return r;
1212
1233
  }
1213
- function tt(e, t) {
1214
- return (et(e, t) >>> 0) / 4294967295;
1234
+ function at(e, t) {
1235
+ return (it(e, t) >>> 0) / 4294967295;
1215
1236
  }
1216
- function nt(e, t = /* @__PURE__ */ new Set()) {
1237
+ function ot(e, t = /* @__PURE__ */ new Set()) {
1217
1238
  if (e.reviewCards.length === 0 && e.newCards.length === 0) return;
1218
1239
  if (e.reviewCards.length === 0) return Q(e.newCards, t) ?? e.newCards[0];
1219
1240
  if (e.newCards.length === 0) return Q(e.reviewCards, t) ?? e.reviewCards[0];
@@ -1221,42 +1242,42 @@ function nt(e, t = /* @__PURE__ */ new Set()) {
1221
1242
  if (!n) return r ?? e.newCards[0];
1222
1243
  if (!r) return n ?? e.reviewCards[0];
1223
1244
  let i = e.newCards.length, a = (.33 + i / (i + e.reviewCards.length)) / 2;
1224
- return tt(n.card.id, r.card.id) < a ? n : r;
1245
+ return at(n.card.id, r.card.id) < a ? n : r;
1225
1246
  }
1226
1247
  function Q(e, t) {
1227
1248
  return e.find((e) => !t.has(e.card.id));
1228
1249
  }
1229
- function rt(e, t) {
1250
+ function st(e, t) {
1230
1251
  let n = $(e, t);
1231
- return n ? $e(e, (e) => {
1232
- at(e, n);
1252
+ return n ? Z(e, (e) => {
1253
+ lt(e, n);
1233
1254
  }) : e;
1234
1255
  }
1235
- function it(t, n, r) {
1256
+ function ct(t, n, r) {
1236
1257
  let i = $(n, r);
1237
1258
  if (!i) return n;
1238
- let { nextCard: a } = Te(i.cardReview, t, 30), o = a.due && (0, e.isSameDay)(a.due, /* @__PURE__ */ new Date());
1239
- return $e(n, (e) => {
1240
- at(e, i), o && ot(e, {
1259
+ let { nextCard: a } = De(i.cardReview, t, 30), o = a.due && (0, e.isSameDay)(a.due, /* @__PURE__ */ new Date());
1260
+ return Z(n, (e) => {
1261
+ lt(e, i), o && ut(e, {
1241
1262
  ...i,
1242
1263
  cardReview: a
1243
1264
  });
1244
1265
  });
1245
1266
  }
1246
- function at(e, t) {
1247
- t.cardReview.state === "New" ? e.newCards = e.newCards.filter((e) => e.card.id !== t.card.id) : e.reviewCards = e.reviewCards.filter((e) => e.card.id !== t.card.id), st(e, t.cardReview.state, "decrease");
1267
+ function lt(e, t) {
1268
+ t.cardReview.state === "New" ? e.newCards = e.newCards.filter((e) => e.card.id !== t.card.id) : e.reviewCards = e.reviewCards.filter((e) => e.card.id !== t.card.id), dt(e, t.cardReview.state, "decrease");
1248
1269
  }
1249
- function ot(e, t) {
1270
+ function ut(e, t) {
1250
1271
  if (t.cardReview.state === "New") {
1251
1272
  let n = e.newCards.findIndex((e) => e.cardReview.due && t.cardReview.due && e.cardReview.due >= t.cardReview.due || e.cardReview.difficulty >= t.cardReview.difficulty);
1252
1273
  n === -1 ? e.newCards.push(t) : e.newCards.splice(n, 0, t);
1253
1274
  } else {
1254
- let n = ct(e, e.reviewCards);
1275
+ let n = ft(e, e.reviewCards);
1255
1276
  e.reviewCards.splice(n, 0, t);
1256
1277
  }
1257
- st(e, t.cardReview.state, "increase");
1278
+ dt(e, t.cardReview.state, "increase");
1258
1279
  }
1259
- function st(e, t, n) {
1280
+ function dt(e, t, n) {
1260
1281
  let r = n === "increase" ? 1 : -1;
1261
1282
  switch (t) {
1262
1283
  case "New":
@@ -1278,14 +1299,14 @@ function st(e, t, n) {
1278
1299
  function $(e, t) {
1279
1300
  return e.newCards.find((e) => e.card.id === t) ?? e.reviewCards.find((e) => e.card.id === t);
1280
1301
  }
1281
- function ct(e, t) {
1302
+ function ft(e, t) {
1282
1303
  if (t.length === 0) return 0;
1283
1304
  let n = Math.max(4, Math.floor(t.length / 3));
1284
1305
  return Math.min(n, t.length);
1285
1306
  }
1286
1307
  //#endregion
1287
1308
  //#region src/spaced-repetition/session-manager.ts
1288
- var lt = 5, ut = {
1309
+ var pt = 5, mt = {
1289
1310
  newCards: [],
1290
1311
  reviewCards: [],
1291
1312
  stats: {
@@ -1294,8 +1315,9 @@ var lt = 5, ut = {
1294
1315
  review: 0,
1295
1316
  total: 0
1296
1317
  }
1297
- }, dt = class {
1318
+ }, ht = class {
1298
1319
  recentlyReviewed = /* @__PURE__ */ new Set();
1320
+ reviewHistory = [];
1299
1321
  _reviewsCompleted = 0;
1300
1322
  _correctGrades = 0;
1301
1323
  getProgress() {
@@ -1305,11 +1327,32 @@ var lt = 5, ut = {
1305
1327
  };
1306
1328
  }
1307
1329
  nextCard(e) {
1308
- return nt(e, this.recentlyReviewed);
1330
+ return ot(e, this.recentlyReviewed);
1309
1331
  }
1310
1332
  onRate(e, t) {
1311
- return this.recentlyReviewed.add(e), this.recentlyReviewed.size > 5 && this.recentlyReviewed.delete(this.recentlyReviewed.values().next().value), this._reviewsCompleted++, (t === "Good" || t === "Easy") && this._correctGrades++, this.getProgress();
1333
+ if (this.reviewHistory.push({
1334
+ cardId: e,
1335
+ rating: t
1336
+ }), this.recentlyReviewed.add(e), this.recentlyReviewed.size > 5) {
1337
+ let e = this.recentlyReviewed.values().next().value;
1338
+ typeof e == "string" && this.recentlyReviewed.delete(e);
1339
+ }
1340
+ return this._reviewsCompleted++, (t === "Good" || t === "Easy") && this._correctGrades++, this.getProgress();
1341
+ }
1342
+ undoRate(e, t) {
1343
+ let n = this.reviewHistory.at(-1);
1344
+ return !n || n.cardId !== e || n.rating !== t ? this.getProgress() : (this.reviewHistory = this.reviewHistory.slice(0, -1), this.rebuildStateFromHistory(), this.getProgress());
1345
+ }
1346
+ rebuildStateFromHistory() {
1347
+ this.recentlyReviewed = /* @__PURE__ */ new Set(), this._reviewsCompleted = 0, this._correctGrades = 0;
1348
+ for (let e of this.reviewHistory) {
1349
+ if (this.recentlyReviewed.add(e.cardId), this.recentlyReviewed.size > 5) {
1350
+ let e = this.recentlyReviewed.values().next().value;
1351
+ typeof e == "string" && this.recentlyReviewed.delete(e);
1352
+ }
1353
+ this._reviewsCompleted++, (e.rating === "Good" || e.rating === "Easy") && this._correctGrades++;
1354
+ }
1312
1355
  }
1313
1356
  };
1314
1357
  //#endregion
1315
- export { i as FSRS_RETENTION, dt as FlashcardSessionManager, a as MAX_CARDS_TO_FETCH, o as MAX_LEARN_PER_DAY, s as MAX_NEW_PER_DECK_DAY, lt as RECENTLY_REVIEWED_SET_SIZE, c as THRESHOLD_CARDS_FOR_REFETCH, ut as defaultSessionData, nt as getNextCardFromSession, Ee as getReviewDateForEachRating, $ as getSessionCard, Te as gradeCard, C as mergeFsrsCard, Ae as newCardReview, it as removeCardFromSessionData, rt as skipCardFromSessionData };
1358
+ export { i as FSRS_RETENTION, o as FSRS_RETENTION_FACTOR, a as FSRS_RETRIEVABILITY_DECAY, ht as FlashcardSessionManager, c as LEARNING_SETTINGS_LIMITS, s as MAX_CARDS_TO_FETCH, pt as RECENTLY_REVIEWED_SET_SIZE, l as THRESHOLD_CARDS_FOR_REFETCH, Pe as calculateRetentionPercentage, Ne as calculateRetrievability, mt as defaultSessionData, ot as getNextCardFromSession, Oe as getReviewDateForEachRating, $ as getSessionCard, De as gradeCard, u as isRecommendedLearningSettings, C as mergeFsrsCard, Me as newCardReview, ct as removeCardFromSessionData, st as skipCardFromSessionData };