@vestcards/shared 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1195 +1,1315 @@
1
- var Oe = Object.defineProperty;
2
- var Fe = (t, e, i) => e in t ? Oe(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i;
3
- var _ = (t, e, i) => Fe(t, typeof e != "symbol" ? e + "" : e, i);
4
- import { r as V, a as Ne, b as fe } from "./fsrs-sJJWxUiC.js";
5
- import "date-fns/locale";
6
- import { isSameDay as Ie } from "date-fns";
7
- import "date-fns-tz";
8
- const Pe = 0.9, Ft = 50, Nt = 200, It = 10, Pt = 10;
9
- var h = ((t) => (t[t.New = 0] = "New", t[t.Learning = 1] = "Learning", t[t.Review = 2] = "Review", t[t.Relearning = 3] = "Relearning", t))(h || {}), l = ((t) => (t[t.Manual = 0] = "Manual", t[t.Again = 1] = "Again", t[t.Hard = 2] = "Hard", t[t.Good = 3] = "Good", t[t.Easy = 4] = "Easy", t))(l || {});
10
- class d {
11
- static card(e) {
12
- return { ...e, state: d.state(e.state), due: d.time(e.due), last_review: e.last_review ? d.time(e.last_review) : void 0 };
13
- }
14
- static rating(e) {
15
- if (typeof e == "string") {
16
- const i = e.charAt(0).toUpperCase(), r = e.slice(1).toLowerCase(), s = l[`${i}${r}`];
17
- if (s === void 0) throw new Error(`Invalid rating:[${e}]`);
18
- return s;
19
- } else if (typeof e == "number") return e;
20
- throw new Error(`Invalid rating:[${e}]`);
21
- }
22
- static state(e) {
23
- if (typeof e == "string") {
24
- const i = e.charAt(0).toUpperCase(), r = e.slice(1).toLowerCase(), s = h[`${i}${r}`];
25
- if (s === void 0) throw new Error(`Invalid state:[${e}]`);
26
- return s;
27
- } else if (typeof e == "number") return e;
28
- throw new Error(`Invalid state:[${e}]`);
29
- }
30
- static time(e) {
31
- if (typeof e == "object" && e instanceof Date) return e;
32
- if (typeof e == "string") {
33
- const i = Date.parse(e);
34
- if (isNaN(i)) throw new Error(`Invalid date:[${e}]`);
35
- return new Date(i);
36
- } else if (typeof e == "number") return new Date(e);
37
- throw new Error(`Invalid date:[${e}]`);
38
- }
39
- static review_log(e) {
40
- return { ...e, due: d.time(e.due), rating: d.rating(e.rating), state: d.state(e.state), review: d.time(e.review) };
41
- }
42
- }
43
- Date.prototype.scheduler = function(t, e) {
44
- return Ae(this, t, e);
45
- }, Date.prototype.diff = function(t, e) {
46
- return Te(this, t, e);
1
+ import { t as e } from "./date-DS8JYZte.js";
2
+ import { i as t, n, r } from "./fsrs-D2XsH28s.js";
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 {
5
+ static card(t) {
6
+ return {
7
+ ...t,
8
+ state: e.state(t.state),
9
+ due: e.time(t.due),
10
+ last_review: t.last_review ? e.time(t.last_review) : void 0
11
+ };
12
+ }
13
+ static rating(e) {
14
+ if (typeof e == "string") {
15
+ let t = u[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
16
+ if (t === void 0) throw Error(`Invalid rating:[${e}]`);
17
+ return t;
18
+ } else if (typeof e == "number") return e;
19
+ throw Error(`Invalid rating:[${e}]`);
20
+ }
21
+ static state(e) {
22
+ if (typeof e == "string") {
23
+ let t = l[`${e.charAt(0).toUpperCase()}${e.slice(1).toLowerCase()}`];
24
+ if (t === void 0) throw Error(`Invalid state:[${e}]`);
25
+ return t;
26
+ } else if (typeof e == "number") return e;
27
+ throw Error(`Invalid state:[${e}]`);
28
+ }
29
+ static time(e) {
30
+ if (typeof e == "object" && e instanceof Date) return e;
31
+ if (typeof e == "string") {
32
+ let t = Date.parse(e);
33
+ if (isNaN(t)) throw Error(`Invalid date:[${e}]`);
34
+ return new Date(t);
35
+ } else if (typeof e == "number") return new Date(e);
36
+ throw Error(`Invalid date:[${e}]`);
37
+ }
38
+ static review_log(t) {
39
+ return {
40
+ ...t,
41
+ due: e.time(t.due),
42
+ rating: e.rating(t.rating),
43
+ state: e.state(t.state),
44
+ review: e.time(t.review)
45
+ };
46
+ }
47
+ }, f = "4.7.1";
48
+ Date.prototype.scheduler = function(e, t) {
49
+ return p(this, e, t);
50
+ }, Date.prototype.diff = function(e, t) {
51
+ return m(this, e, t);
47
52
  }, Date.prototype.format = function() {
48
- return ke(this);
49
- }, Date.prototype.dueFormat = function(t, e, i) {
50
- return je(this, t, e, i);
53
+ return ee(this);
54
+ }, Date.prototype.dueFormat = function(e, t, n) {
55
+ return te(this, e, t, n);
51
56
  };
52
- function Ae(t, e, i) {
53
- return new Date(i ? d.time(t).getTime() + e * 24 * 60 * 60 * 1e3 : d.time(t).getTime() + e * 60 * 1e3);
54
- }
55
- function Te(t, e, i) {
56
- if (!t || !e) throw new Error("Invalid date");
57
- const r = d.time(t).getTime() - d.time(e).getTime();
58
- let s = 0;
59
- switch (i) {
60
- case "days":
61
- s = Math.floor(r / (1440 * 60 * 1e3));
62
- break;
63
- case "minutes":
64
- s = Math.floor(r / (60 * 1e3));
65
- break;
66
- }
67
- return s;
68
- }
69
- function ke(t) {
70
- const e = d.time(t), i = e.getFullYear(), r = e.getMonth() + 1, s = e.getDate(), n = e.getHours(), a = e.getMinutes(), o = e.getSeconds();
71
- return `${i}-${D(r)}-${D(s)} ${D(n)}:${D(a)}:${D(o)}`;
72
- }
73
- function D(t) {
74
- return t < 10 ? `0${t}` : `${t}`;
75
- }
76
- const L = [60, 60, 24, 31, 12], G = ["second", "min", "hour", "day", "month", "year"];
77
- function je(t, e, i, r = G) {
78
- t = d.time(t), e = d.time(e), r.length !== G.length && (r = G);
79
- let s = t.getTime() - e.getTime(), n;
80
- for (s /= 1e3, n = 0; n < L.length && !(s < L[n]); n++) s /= L[n];
81
- return `${Math.floor(s)}${i ? r[n] : ""}`;
82
- }
83
- const he = Object.freeze([l.Again, l.Hard, l.Good, l.Easy]), He = [{ start: 2.5, end: 7, factor: 0.15 }, { start: 7, end: 20, factor: 0.1 }, { start: 20, end: 1 / 0, factor: 0.05 }];
84
- function $e(t, e, i) {
85
- let r = 1;
86
- for (const a of He) r += a.factor * Math.max(Math.min(t, a.end) - a.start, 0);
87
- t = Math.min(t, i);
88
- let s = Math.max(2, Math.round(t - r));
89
- const n = Math.min(Math.round(t + r), i);
90
- return t > e && (s = Math.max(s, e + 1)), s = Math.min(s, n), { min_ivl: s, max_ivl: n };
91
- }
92
- function b(t, e, i) {
93
- return Math.min(Math.max(t, e), i);
94
- }
95
- function Le(t, e) {
96
- const i = Date.UTC(t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate()), r = Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate());
97
- return Math.floor((r - i) / 864e5);
98
- }
99
- const Ge = 0.9, Ue = 36500, qe = Object.freeze([0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 46e-4, 1.54575, 0.1192, 1.01925, 1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655, 0.6621]), We = !1, Ye = !0, p = 0.01, N = 100, ie = Object.freeze([Object.freeze([p, N]), Object.freeze([p, N]), Object.freeze([p, N]), Object.freeze([p, N]), Object.freeze([1, 10]), Object.freeze([1e-3, 4]), Object.freeze([1e-3, 4]), Object.freeze([1e-3, 0.75]), Object.freeze([0, 4.5]), Object.freeze([0, 0.8]), Object.freeze([1e-3, 3.5]), Object.freeze([1e-3, 5]), Object.freeze([1e-3, 0.25]), Object.freeze([1e-3, 0.9]), Object.freeze([0, 4]), Object.freeze([0, 1]), Object.freeze([1, 6]), Object.freeze([0, 2]), Object.freeze([0, 2])]), W = (t) => {
100
- let e = [...qe];
101
- return t != null && t.w && (t.w.length === 19 ? e = [...t.w] : t.w.length === 17 && (e = t == null ? void 0 : t.w.concat([0, 0]), e[4] = +(e[5] * 2 + e[4]).toFixed(8), e[5] = +(Math.log(e[5] * 3 + 1) / 3).toFixed(8), e[6] = +(e[6] + 0.5).toFixed(8), console.debug("[FSRS V5]auto fill w to 19 length"))), e = e.map((i, r) => b(i, ie[r][0], ie[r][1])), { request_retention: (t == null ? void 0 : t.request_retention) || Ge, maximum_interval: (t == null ? void 0 : t.maximum_interval) || Ue, w: e, enable_fuzz: (t == null ? void 0 : t.enable_fuzz) ?? We, enable_short_term: (t == null ? void 0 : t.enable_short_term) ?? Ye };
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);
59
+ }
60
+ function m(e, t, n) {
61
+ if (!e || !t) throw Error("Invalid date");
62
+ let r = d.time(e).getTime() - d.time(t).getTime(), i = 0;
63
+ switch (n) {
64
+ case "days":
65
+ i = Math.floor(r / (1440 * 60 * 1e3));
66
+ break;
67
+ case "minutes":
68
+ i = Math.floor(r / (60 * 1e3));
69
+ break;
70
+ }
71
+ return i;
72
+ }
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();
75
+ return `${n}-${h(r)}-${h(i)} ${h(a)}:${h(o)}:${h(s)}`;
76
+ }
77
+ function h(e) {
78
+ return e < 10 ? `0${e}` : `${e}`;
79
+ }
80
+ var g = [
81
+ 60,
82
+ 60,
83
+ 24,
84
+ 31,
85
+ 12
86
+ ], _ = [
87
+ "second",
88
+ "min",
89
+ "hour",
90
+ "day",
91
+ "month",
92
+ "year"
93
+ ];
94
+ function te(e, t, n, r = _) {
95
+ e = d.time(e), t = d.time(t), r.length !== _.length && (r = _);
96
+ let i = e.getTime() - t.getTime(), a;
97
+ for (i /= 1e3, a = 0; a < g.length && !(i < g[a]); a++) i /= g[a];
98
+ return `${Math.floor(i)}${n ? r[a] : ""}`;
99
+ }
100
+ var ne = Object.freeze([
101
+ u.Again,
102
+ u.Hard,
103
+ u.Good,
104
+ u.Easy
105
+ ]), re = [
106
+ {
107
+ start: 2.5,
108
+ end: 7,
109
+ factor: .15
110
+ },
111
+ {
112
+ start: 7,
113
+ end: 20,
114
+ factor: .1
115
+ },
116
+ {
117
+ start: 20,
118
+ end: Infinity,
119
+ factor: .05
120
+ }
121
+ ];
122
+ function ie(e, t, n) {
123
+ let r = 1;
124
+ for (let t of re) r += t.factor * Math.max(Math.min(e, t.end) - t.start, 0);
125
+ e = Math.min(e, n);
126
+ let i = Math.max(2, Math.round(e - r)), a = Math.min(Math.round(e + r), n);
127
+ return e > t && (i = Math.max(i, t + 1)), i = Math.min(i, a), {
128
+ min_ivl: i,
129
+ max_ivl: a
130
+ };
131
+ }
132
+ function v(e, t, n) {
133
+ return Math.min(Math.max(e, t), n);
134
+ }
135
+ function ae(e, t) {
136
+ let n = Date.UTC(e.getUTCFullYear(), e.getUTCMonth(), e.getUTCDate()), r = Date.UTC(t.getUTCFullYear(), t.getUTCMonth(), t.getUTCDate());
137
+ return Math.floor((r - n) / 864e5);
138
+ }
139
+ var oe = Object.freeze([
140
+ .40255,
141
+ 1.18385,
142
+ 3.173,
143
+ 15.69105,
144
+ 7.1949,
145
+ .5345,
146
+ 1.4604,
147
+ .0046,
148
+ 1.54575,
149
+ .1192,
150
+ 1.01925,
151
+ 1.9395,
152
+ .11,
153
+ .29605,
154
+ 2.2698,
155
+ .2315,
156
+ 2.9898,
157
+ .51655,
158
+ .6621
159
+ ]);
160
+ `${f}`;
161
+ var y = .01, se = Object.freeze([
162
+ Object.freeze([y, 100]),
163
+ Object.freeze([y, 100]),
164
+ Object.freeze([y, 100]),
165
+ Object.freeze([y, 100]),
166
+ Object.freeze([1, 10]),
167
+ Object.freeze([.001, 4]),
168
+ Object.freeze([.001, 4]),
169
+ Object.freeze([.001, .75]),
170
+ Object.freeze([0, 4.5]),
171
+ Object.freeze([0, .8]),
172
+ Object.freeze([.001, 3.5]),
173
+ Object.freeze([.001, 5]),
174
+ Object.freeze([.001, .25]),
175
+ Object.freeze([.001, .9]),
176
+ Object.freeze([0, 4]),
177
+ Object.freeze([0, 1]),
178
+ Object.freeze([1, 6]),
179
+ Object.freeze([0, 2]),
180
+ Object.freeze([0, 2])
181
+ ]), 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])), {
184
+ request_retention: e?.request_retention || .9,
185
+ maximum_interval: e?.maximum_interval || 36500,
186
+ w: t,
187
+ enable_fuzz: e?.enable_fuzz ?? !1,
188
+ enable_short_term: e?.enable_short_term ?? !0
189
+ };
102
190
  };
103
- function P(t, e) {
104
- const i = { due: t ? d.time(t) : /* @__PURE__ */ new Date(), stability: 0, difficulty: 0, elapsed_days: 0, scheduled_days: 0, reps: 0, lapses: 0, state: h.New, last_review: void 0 };
105
- return e && typeof e == "function" ? e(i) : i;
106
- }
107
- class Ke {
108
- constructor(e) {
109
- _(this, "c");
110
- _(this, "s0");
111
- _(this, "s1");
112
- _(this, "s2");
113
- const i = Be();
114
- this.c = 1, this.s0 = i(" "), this.s1 = i(" "), this.s2 = i(" "), e == null && (e = +/* @__PURE__ */ new Date()), this.s0 -= i(e), this.s0 < 0 && (this.s0 += 1), this.s1 -= i(e), this.s1 < 0 && (this.s1 += 1), this.s2 -= i(e), this.s2 < 0 && (this.s2 += 1);
115
- }
116
- next() {
117
- const e = 2091639 * this.s0 + this.c * 23283064365386963e-26;
118
- return this.s0 = this.s1, this.s1 = this.s2, this.s2 = e - (this.c = e | 0), this.s2;
119
- }
120
- set state(e) {
121
- this.c = e.c, this.s0 = e.s0, this.s1 = e.s1, this.s2 = e.s2;
122
- }
123
- get state() {
124
- return { c: this.c, s0: this.s0, s1: this.s1, s2: this.s2 };
125
- }
126
- }
127
- function Be() {
128
- let t = 4022871197;
129
- return function(e) {
130
- e = String(e);
131
- for (let i = 0; i < e.length; i++) {
132
- t += e.charCodeAt(i);
133
- let r = 0.02519603282416938 * t;
134
- t = r >>> 0, r -= t, r *= t, t = r >>> 0, r -= t, t += r * 4294967296;
135
- }
136
- return (t >>> 0) * 23283064365386963e-26;
137
- };
138
- }
139
- function Xe(t) {
140
- const e = new Ke(t), i = () => e.next();
141
- return i.int32 = () => e.next() * 4294967296 | 0, i.double = () => i() + (i() * 2097152 | 0) * 11102230246251565e-32, i.state = () => e.state, i.importState = (r) => (e.state = r, i), i;
142
- }
143
- const _e = -0.5, ye = 19 / 81;
144
- function Ze(t, e) {
145
- return +Math.pow(1 + ye * t / e, _e).toFixed(8);
146
- }
147
- class Je {
148
- constructor(e) {
149
- _(this, "param");
150
- _(this, "intervalModifier");
151
- _(this, "_seed");
152
- _(this, "forgetting_curve", Ze);
153
- this.param = new Proxy(W(e), this.params_handler_proxy()), this.intervalModifier = this.calculate_interval_modifier(this.param.request_retention);
154
- }
155
- get interval_modifier() {
156
- return this.intervalModifier;
157
- }
158
- set seed(e) {
159
- this._seed = e;
160
- }
161
- calculate_interval_modifier(e) {
162
- if (e <= 0 || e > 1) throw new Error("Requested retention rate should be in the range (0,1]");
163
- return +((Math.pow(e, 1 / _e) - 1) / ye).toFixed(8);
164
- }
165
- get parameters() {
166
- return this.param;
167
- }
168
- set parameters(e) {
169
- this.update_parameters(e);
170
- }
171
- params_handler_proxy() {
172
- const e = this;
173
- return { set: function(i, r, s) {
174
- return r === "request_retention" && Number.isFinite(s) && (e.intervalModifier = e.calculate_interval_modifier(Number(s))), Reflect.set(i, r, s), !0;
175
- } };
176
- }
177
- update_parameters(e) {
178
- const i = W(e);
179
- for (const r in i) if (r in this.param) {
180
- const s = r;
181
- this.param[s] = i[s];
182
- }
183
- }
184
- init_stability(e) {
185
- return Math.max(this.param.w[e - 1], 0.1);
186
- }
187
- init_difficulty(e) {
188
- return this.constrain_difficulty(this.param.w[4] - Math.exp((e - 1) * this.param.w[5]) + 1);
189
- }
190
- apply_fuzz(e, i) {
191
- if (!this.param.enable_fuzz || e < 2.5) return Math.round(e);
192
- const r = Xe(this._seed)(), { min_ivl: s, max_ivl: n } = $e(e, i, this.param.maximum_interval);
193
- return Math.floor(r * (n - s + 1) + s);
194
- }
195
- next_interval(e, i) {
196
- const r = Math.min(Math.max(1, Math.round(e * this.intervalModifier)), this.param.maximum_interval);
197
- return this.apply_fuzz(r, i);
198
- }
199
- linear_damping(e, i) {
200
- return +(e * (10 - i) / 9).toFixed(8);
201
- }
202
- next_difficulty(e, i) {
203
- const r = -this.param.w[6] * (i - 3), s = e + this.linear_damping(r, e);
204
- return this.constrain_difficulty(this.mean_reversion(this.init_difficulty(l.Easy), s));
205
- }
206
- constrain_difficulty(e) {
207
- return Math.min(Math.max(+e.toFixed(8), 1), 10);
208
- }
209
- mean_reversion(e, i) {
210
- return +(this.param.w[7] * e + (1 - this.param.w[7]) * i).toFixed(8);
211
- }
212
- next_recall_stability(e, i, r, s) {
213
- const n = l.Hard === s ? this.param.w[15] : 1, a = l.Easy === s ? this.param.w[16] : 1;
214
- return +b(i * (1 + Math.exp(this.param.w[8]) * (11 - e) * Math.pow(i, -this.param.w[9]) * (Math.exp((1 - r) * this.param.w[10]) - 1) * n * a), p, 36500).toFixed(8);
215
- }
216
- next_forget_stability(e, i, r) {
217
- return +b(this.param.w[11] * Math.pow(e, -this.param.w[12]) * (Math.pow(i + 1, this.param.w[13]) - 1) * Math.exp((1 - r) * this.param.w[14]), p, 36500).toFixed(8);
218
- }
219
- next_short_term_stability(e, i) {
220
- return +b(e * Math.exp(this.param.w[17] * (i - 3 + this.param.w[18])), p, 36500).toFixed(8);
221
- }
222
- next_state(e, i, r) {
223
- const { difficulty: s, stability: n } = e ?? { difficulty: 0, stability: 0 };
224
- if (i < 0) throw new Error(`Invalid delta_t "${i}"`);
225
- if (r < 0 || r > 4) throw new Error(`Invalid grade "${r}"`);
226
- if (s === 0 && n === 0) return { difficulty: this.init_difficulty(r), stability: this.init_stability(r) };
227
- if (r === 0) return { difficulty: s, stability: n };
228
- if (s < 1 || n < p) throw new Error(`Invalid memory state { difficulty: ${s}, stability: ${n} }`);
229
- const a = this.forgetting_curve(i, n), o = this.next_recall_stability(s, n, a, r), c = this.next_forget_stability(s, n, a), u = this.next_short_term_stability(n, r);
230
- let f = o;
231
- if (r === 1) {
232
- let [y, g] = [0, 0];
233
- this.param.enable_short_term && (y = this.param.w[17], g = this.param.w[18]);
234
- const E = n / Math.exp(y * g);
235
- f = b(+E.toFixed(8), p, c);
236
- }
237
- return i === 0 && this.param.enable_short_term && (f = u), { difficulty: this.next_difficulty(s, r), stability: f };
238
- }
239
- }
240
- function me() {
241
- const t = this.review_time.getTime(), e = this.current.reps, i = this.current.difficulty * this.current.stability;
242
- return `${t}_${e}_${i}`;
243
- }
244
- var Y = ((t) => (t.SCHEDULER = "Scheduler", t.SEED = "Seed", t))(Y || {});
245
- class we {
246
- constructor(e, i, r, s = { seed: me }) {
247
- _(this, "last");
248
- _(this, "current");
249
- _(this, "review_time");
250
- _(this, "next", /* @__PURE__ */ new Map());
251
- _(this, "algorithm");
252
- _(this, "initSeedStrategy");
253
- this.algorithm = r, this.initSeedStrategy = s.seed.bind(this), this.last = d.card(e), this.current = d.card(e), this.review_time = d.time(i), this.init();
254
- }
255
- init() {
256
- const { state: e, last_review: i } = this.current;
257
- let r = 0;
258
- e !== h.New && i && (r = Le(i, this.review_time)), this.current.last_review = this.review_time, this.current.elapsed_days = r, this.current.reps += 1, this.algorithm.seed = this.initSeedStrategy();
259
- }
260
- preview() {
261
- return { [l.Again]: this.review(l.Again), [l.Hard]: this.review(l.Hard), [l.Good]: this.review(l.Good), [l.Easy]: this.review(l.Easy), [Symbol.iterator]: this.previewIterator.bind(this) };
262
- }
263
- *previewIterator() {
264
- for (const e of he) yield this.review(e);
265
- }
266
- review(e) {
267
- const { state: i } = this.last;
268
- let r;
269
- switch (i) {
270
- case h.New:
271
- r = this.newState(e);
272
- break;
273
- case h.Learning:
274
- case h.Relearning:
275
- r = this.learningState(e);
276
- break;
277
- case h.Review:
278
- r = this.reviewState(e);
279
- break;
280
- }
281
- if (r) return r;
282
- throw new Error("Invalid grade");
283
- }
284
- buildLog(e) {
285
- const { last_review: i, due: r, elapsed_days: s } = this.last;
286
- return { rating: e, state: this.current.state, due: i || r, stability: this.current.stability, difficulty: this.current.difficulty, elapsed_days: this.current.elapsed_days, last_elapsed_days: s, scheduled_days: this.current.scheduled_days, review: this.review_time };
287
- }
288
- }
289
- class re extends we {
290
- newState(e) {
291
- const i = this.next.get(e);
292
- if (i) return i;
293
- const r = d.card(this.current);
294
- switch (r.difficulty = this.algorithm.init_difficulty(e), r.stability = this.algorithm.init_stability(e), e) {
295
- case l.Again:
296
- r.scheduled_days = 0, r.due = this.review_time.scheduler(1), r.state = h.Learning;
297
- break;
298
- case l.Hard:
299
- r.scheduled_days = 0, r.due = this.review_time.scheduler(5), r.state = h.Learning;
300
- break;
301
- case l.Good:
302
- r.scheduled_days = 0, r.due = this.review_time.scheduler(10), r.state = h.Learning;
303
- break;
304
- case l.Easy: {
305
- const n = this.algorithm.next_interval(r.stability, this.current.elapsed_days);
306
- r.scheduled_days = n, r.due = this.review_time.scheduler(n, !0), r.state = h.Review;
307
- break;
308
- }
309
- default:
310
- throw new Error("Invalid grade");
311
- }
312
- const s = { card: r, log: this.buildLog(e) };
313
- return this.next.set(e, s), s;
314
- }
315
- learningState(e) {
316
- const i = this.next.get(e);
317
- if (i) return i;
318
- const { state: r, difficulty: s, stability: n } = this.last, a = d.card(this.current), o = this.current.elapsed_days;
319
- switch (a.difficulty = this.algorithm.next_difficulty(s, e), a.stability = this.algorithm.next_short_term_stability(n, e), e) {
320
- case l.Again: {
321
- a.scheduled_days = 0, a.due = this.review_time.scheduler(5, !1), a.state = r;
322
- break;
323
- }
324
- case l.Hard: {
325
- a.scheduled_days = 0, a.due = this.review_time.scheduler(10), a.state = r;
326
- break;
327
- }
328
- case l.Good: {
329
- const u = this.algorithm.next_interval(a.stability, o);
330
- a.scheduled_days = u, a.due = this.review_time.scheduler(u, !0), a.state = h.Review;
331
- break;
332
- }
333
- case l.Easy: {
334
- const u = this.algorithm.next_short_term_stability(n, l.Good), f = this.algorithm.next_interval(u, o), y = Math.max(this.algorithm.next_interval(a.stability, o), f + 1);
335
- a.scheduled_days = y, a.due = this.review_time.scheduler(y, !0), a.state = h.Review;
336
- break;
337
- }
338
- default:
339
- throw new Error("Invalid grade");
340
- }
341
- const c = { card: a, log: this.buildLog(e) };
342
- return this.next.set(e, c), c;
343
- }
344
- reviewState(e) {
345
- const i = this.next.get(e);
346
- if (i) return i;
347
- const r = this.current.elapsed_days, { difficulty: s, stability: n } = this.last, a = this.algorithm.forgetting_curve(r, n), o = d.card(this.current), c = d.card(this.current), u = d.card(this.current), f = d.card(this.current);
348
- this.next_ds(o, c, u, f, s, n, a), this.next_interval(o, c, u, f, r), this.next_state(o, c, u, f), o.lapses += 1;
349
- const y = { card: o, log: this.buildLog(l.Again) }, g = { card: c, log: super.buildLog(l.Hard) }, E = { card: u, log: super.buildLog(l.Good) }, R = { card: f, log: super.buildLog(l.Easy) };
350
- return this.next.set(l.Again, y), this.next.set(l.Hard, g), this.next.set(l.Good, E), this.next.set(l.Easy, R), this.next.get(e);
351
- }
352
- next_ds(e, i, r, s, n, a, o) {
353
- e.difficulty = this.algorithm.next_difficulty(n, l.Again);
354
- const c = a / Math.exp(this.algorithm.parameters.w[17] * this.algorithm.parameters.w[18]), u = this.algorithm.next_forget_stability(n, a, o);
355
- e.stability = b(+c.toFixed(8), p, u), i.difficulty = this.algorithm.next_difficulty(n, l.Hard), i.stability = this.algorithm.next_recall_stability(n, a, o, l.Hard), r.difficulty = this.algorithm.next_difficulty(n, l.Good), r.stability = this.algorithm.next_recall_stability(n, a, o, l.Good), s.difficulty = this.algorithm.next_difficulty(n, l.Easy), s.stability = this.algorithm.next_recall_stability(n, a, o, l.Easy);
356
- }
357
- next_interval(e, i, r, s, n) {
358
- let a, o;
359
- a = this.algorithm.next_interval(i.stability, n), o = this.algorithm.next_interval(r.stability, n), a = Math.min(a, o), o = Math.max(o, a + 1);
360
- const c = Math.max(this.algorithm.next_interval(s.stability, n), o + 1);
361
- e.scheduled_days = 0, e.due = this.review_time.scheduler(5), i.scheduled_days = a, i.due = this.review_time.scheduler(a, !0), r.scheduled_days = o, r.due = this.review_time.scheduler(o, !0), s.scheduled_days = c, s.due = this.review_time.scheduler(c, !0);
362
- }
363
- next_state(e, i, r, s) {
364
- e.state = h.Relearning, i.state = h.Review, r.state = h.Review, s.state = h.Review;
365
- }
366
- }
367
- class se extends we {
368
- newState(e) {
369
- const i = this.next.get(e);
370
- if (i) return i;
371
- this.current.scheduled_days = 0, this.current.elapsed_days = 0;
372
- const r = d.card(this.current), s = d.card(this.current), n = d.card(this.current), a = d.card(this.current);
373
- return this.init_ds(r, s, n, a), this.next_interval(r, s, n, a, 0), this.next_state(r, s, n, a), this.update_next(r, s, n, a), this.next.get(e);
374
- }
375
- init_ds(e, i, r, s) {
376
- e.difficulty = this.algorithm.init_difficulty(l.Again), e.stability = this.algorithm.init_stability(l.Again), i.difficulty = this.algorithm.init_difficulty(l.Hard), i.stability = this.algorithm.init_stability(l.Hard), r.difficulty = this.algorithm.init_difficulty(l.Good), r.stability = this.algorithm.init_stability(l.Good), s.difficulty = this.algorithm.init_difficulty(l.Easy), s.stability = this.algorithm.init_stability(l.Easy);
377
- }
378
- learningState(e) {
379
- return this.reviewState(e);
380
- }
381
- reviewState(e) {
382
- const i = this.next.get(e);
383
- if (i) return i;
384
- const r = this.current.elapsed_days, { difficulty: s, stability: n } = this.last, a = this.algorithm.forgetting_curve(r, n), o = d.card(this.current), c = d.card(this.current), u = d.card(this.current), f = d.card(this.current);
385
- return this.next_ds(o, c, u, f, s, n, a), this.next_interval(o, c, u, f, r), this.next_state(o, c, u, f), o.lapses += 1, this.update_next(o, c, u, f), this.next.get(e);
386
- }
387
- next_ds(e, i, r, s, n, a, o) {
388
- e.difficulty = this.algorithm.next_difficulty(n, l.Again);
389
- const c = this.algorithm.next_forget_stability(n, a, o);
390
- e.stability = b(a, p, c), i.difficulty = this.algorithm.next_difficulty(n, l.Hard), i.stability = this.algorithm.next_recall_stability(n, a, o, l.Hard), r.difficulty = this.algorithm.next_difficulty(n, l.Good), r.stability = this.algorithm.next_recall_stability(n, a, o, l.Good), s.difficulty = this.algorithm.next_difficulty(n, l.Easy), s.stability = this.algorithm.next_recall_stability(n, a, o, l.Easy);
391
- }
392
- next_interval(e, i, r, s, n) {
393
- let a, o, c, u;
394
- a = this.algorithm.next_interval(e.stability, n), o = this.algorithm.next_interval(i.stability, n), c = this.algorithm.next_interval(r.stability, n), u = this.algorithm.next_interval(s.stability, n), a = Math.min(a, o), o = Math.max(o, a + 1), c = Math.max(c, o + 1), u = Math.max(u, c + 1), e.scheduled_days = a, e.due = this.review_time.scheduler(a, !0), i.scheduled_days = o, i.due = this.review_time.scheduler(o, !0), r.scheduled_days = c, r.due = this.review_time.scheduler(c, !0), s.scheduled_days = u, s.due = this.review_time.scheduler(u, !0);
395
- }
396
- next_state(e, i, r, s) {
397
- e.state = h.Review, i.state = h.Review, r.state = h.Review, s.state = h.Review;
398
- }
399
- update_next(e, i, r, s) {
400
- const n = { card: e, log: this.buildLog(l.Again) }, a = { card: i, log: super.buildLog(l.Hard) }, o = { card: r, log: super.buildLog(l.Good) }, c = { card: s, log: super.buildLog(l.Easy) };
401
- this.next.set(l.Again, n), this.next.set(l.Hard, a), this.next.set(l.Good, o), this.next.set(l.Easy, c);
402
- }
403
- }
404
- class Qe {
405
- constructor(e) {
406
- _(this, "fsrs");
407
- this.fsrs = e;
408
- }
409
- replay(e, i, r) {
410
- return this.fsrs.next(e, i, r);
411
- }
412
- handleManualRating(e, i, r, s, n, a, o) {
413
- if (typeof i > "u") throw new Error("reschedule: state is required for manual rating");
414
- let c, u;
415
- if (i === h.New) c = { rating: l.Manual, state: i, due: o ?? r, stability: e.stability, difficulty: e.difficulty, elapsed_days: s, last_elapsed_days: e.elapsed_days, scheduled_days: e.scheduled_days, review: r }, u = P(r), u.last_review = r;
416
- else {
417
- if (typeof o > "u") throw new Error("reschedule: due is required for manual rating");
418
- const f = o.diff(r, "days");
419
- c = { rating: l.Manual, state: e.state, due: e.last_review || e.due, stability: e.stability, difficulty: e.difficulty, elapsed_days: s, last_elapsed_days: e.elapsed_days, scheduled_days: e.scheduled_days, review: r }, u = { ...e, state: i, due: o, last_review: r, stability: n || e.stability, difficulty: a || e.difficulty, elapsed_days: s, scheduled_days: f, reps: e.reps + 1 };
420
- }
421
- return { card: u, log: c };
422
- }
423
- reschedule(e, i) {
424
- const r = [];
425
- let s = P(e.due);
426
- for (const n of i) {
427
- let a;
428
- if (n.review = d.time(n.review), n.rating === l.Manual) {
429
- let o = 0;
430
- s.state !== h.New && s.last_review && (o = n.review.diff(s.last_review, "days")), a = this.handleManualRating(s, n.state, n.review, o, n.stability, n.difficulty, n.due ? d.time(n.due) : void 0);
431
- } else a = this.replay(s, n.review, n.rating);
432
- r.push(a), s = a.card;
433
- }
434
- return r;
435
- }
436
- calculateManualRecord(e, i, r, s) {
437
- if (!r) return null;
438
- const { card: n, log: a } = r, o = d.card(e);
439
- return o.due.getTime() === n.due.getTime() ? null : (o.scheduled_days = n.due.diff(o.due, "days"), this.handleManualRating(o, n.state, d.time(i), a.elapsed_days, s ? n.stability : void 0, s ? n.difficulty : void 0, n.due));
440
- }
441
- }
442
- class Ve extends Je {
443
- constructor(i) {
444
- super(i);
445
- _(this, "strategyHandler", /* @__PURE__ */ new Map());
446
- _(this, "Scheduler");
447
- const { enable_short_term: r } = this.parameters;
448
- this.Scheduler = r ? re : se;
449
- }
450
- params_handler_proxy() {
451
- const i = this;
452
- return { set: function(r, s, n) {
453
- return s === "request_retention" && Number.isFinite(n) ? i.intervalModifier = i.calculate_interval_modifier(Number(n)) : s === "enable_short_term" && (i.Scheduler = n === !0 ? re : se), Reflect.set(r, s, n), !0;
454
- } };
455
- }
456
- useStrategy(i, r) {
457
- return this.strategyHandler.set(i, r), this;
458
- }
459
- clearStrategy(i) {
460
- return i ? this.strategyHandler.delete(i) : this.strategyHandler.clear(), this;
461
- }
462
- getScheduler(i, r) {
463
- const s = this.strategyHandler.get(Y.SEED), n = this.strategyHandler.get(Y.SCHEDULER) || this.Scheduler, a = s || me;
464
- return new n(i, r, this, { seed: a });
465
- }
466
- repeat(i, r, s) {
467
- const n = this.getScheduler(i, r).preview();
468
- return s && typeof s == "function" ? s(n) : n;
469
- }
470
- next(i, r, s, n) {
471
- const a = this.getScheduler(i, r), o = d.rating(s);
472
- if (o === l.Manual) throw new Error("Cannot review a manual rating");
473
- const c = a.review(o);
474
- return n && typeof n == "function" ? n(c) : c;
475
- }
476
- get_retrievability(i, r, s = !0) {
477
- const n = d.card(i);
478
- r = r ? d.time(r) : /* @__PURE__ */ new Date();
479
- const a = n.state !== h.New ? Math.max(r.diff(n.last_review, "days"), 0) : 0, o = n.state !== h.New ? this.forgetting_curve(a, +n.stability.toFixed(8)) : 0;
480
- return s ? `${(o * 100).toFixed(2)}%` : o;
481
- }
482
- rollback(i, r, s) {
483
- const n = d.card(i), a = d.review_log(r);
484
- if (a.rating === l.Manual) throw new Error("Cannot rollback a manual rating");
485
- let o, c, u;
486
- switch (a.state) {
487
- case h.New:
488
- o = a.due, c = void 0, u = 0;
489
- break;
490
- case h.Learning:
491
- case h.Relearning:
492
- case h.Review:
493
- o = a.review, c = a.due, u = n.lapses - (a.rating === l.Again && a.state === h.Review ? 1 : 0);
494
- break;
495
- }
496
- const f = { ...n, due: o, stability: a.stability, difficulty: a.difficulty, elapsed_days: a.last_elapsed_days, scheduled_days: a.scheduled_days, reps: Math.max(0, n.reps - 1), lapses: Math.max(0, u), state: a.state, last_review: c };
497
- return s && typeof s == "function" ? s(f) : f;
498
- }
499
- forget(i, r, s = !1, n) {
500
- const a = d.card(i);
501
- r = d.time(r);
502
- const o = a.state === h.New ? 0 : r.diff(a.last_review, "days"), c = { rating: l.Manual, state: a.state, due: a.due, stability: a.stability, difficulty: a.difficulty, elapsed_days: 0, last_elapsed_days: a.elapsed_days, scheduled_days: o, review: r }, u = { card: { ...a, due: r, stability: 0, difficulty: 0, elapsed_days: 0, scheduled_days: 0, reps: s ? 0 : a.reps, lapses: s ? 0 : a.lapses, state: h.New, last_review: a.last_review }, log: c };
503
- return n && typeof n == "function" ? n(u) : u;
504
- }
505
- reschedule(i, r = [], s = {}) {
506
- const { recordLogHandler: n, reviewsOrderBy: a, skipManual: o = !0, now: c = /* @__PURE__ */ new Date(), update_memory_state: u = !1 } = s;
507
- a && typeof a == "function" && r.sort(a), o && (r = r.filter((ze) => ze.rating !== l.Manual));
508
- const f = new Qe(this), y = f.reschedule(s.first_card || P(), r), g = y.length, E = d.card(i), R = f.calculateManualRecord(E, c, g ? y[g - 1] : void 0, u);
509
- return n && typeof n == "function" ? { collections: y.map(n), reschedule_item: R ? n(R) : null } : { collections: y, reschedule_item: R };
510
- }
511
- }
512
- const et = (t) => new Ve(t || {}), tt = W({
513
- request_retention: Pe,
514
- enable_fuzz: !0,
515
- maximum_interval: 100
516
- }), pe = et(tt), ge = (t) => t.due ? t : { ...t, due: /* @__PURE__ */ new Date() }, it = (t) => fe.indexOf(t), ve = (t) => ({
517
- due: t.due,
518
- stability: t.stability,
519
- difficulty: t.difficulty,
520
- elapsed_days: t.elapsedDays,
521
- scheduled_days: t.scheduledDays,
522
- reps: t.reps,
523
- lapses: t.lapses,
524
- state: it(t.state),
525
- last_review: t.lastReview
526
- }), rt = (t, e, i) => {
527
- const r = /* @__PURE__ */ new Date(), s = ve(ge(t));
528
- return pe.repeat(s, r, (a) => {
529
- const o = at(e), c = a[o], u = nt(c.card, t), f = c.log, y = {
530
- id: 0,
531
- // will be set by the database
532
- cardReviewId: t.id,
533
- grade: e,
534
- state: be(f.state),
535
- due: f.due,
536
- stability: f.stability,
537
- difficulty: f.difficulty,
538
- elapsedDays: f.elapsed_days,
539
- lastElapsedDays: f.last_elapsed_days,
540
- scheduledDays: f.scheduled_days,
541
- review: f.review,
542
- duration: i
543
- };
544
- return { nextCard: u, reviewLog: y };
545
- });
191
+ function x(e, t) {
192
+ let n = {
193
+ due: e ? d.time(e) : /* @__PURE__ */ new Date(),
194
+ stability: 0,
195
+ difficulty: 0,
196
+ elapsed_days: 0,
197
+ scheduled_days: 0,
198
+ reps: 0,
199
+ lapses: 0,
200
+ state: l.New,
201
+ last_review: void 0
202
+ };
203
+ return t && typeof t == "function" ? t(n) : n;
204
+ }
205
+ var ce = class {
206
+ c;
207
+ s0;
208
+ s1;
209
+ s2;
210
+ constructor(e) {
211
+ let t = le();
212
+ 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
+ }
214
+ next() {
215
+ let e = 2091639 * this.s0 + this.c * 23283064365386963e-26;
216
+ return this.s0 = this.s1, this.s1 = this.s2, this.s2 = e - (this.c = e | 0), this.s2;
217
+ }
218
+ set state(e) {
219
+ this.c = e.c, this.s0 = e.s0, this.s1 = e.s1, this.s2 = e.s2;
220
+ }
221
+ get state() {
222
+ return {
223
+ c: this.c,
224
+ s0: this.s0,
225
+ s1: this.s1,
226
+ s2: this.s2
227
+ };
228
+ }
546
229
  };
547
- function At(t) {
548
- const e = /* @__PURE__ */ new Date(), i = ve(ge(t)), r = pe.repeat(i, e), s = Object.fromEntries(V.map((n) => [n, /* @__PURE__ */ new Date()]));
549
- for (const n of he) {
550
- const a = r[n].card.due, o = st(n);
551
- s[o] = a;
552
- }
553
- return s;
554
- }
555
- function st(t) {
556
- return V[t];
557
- }
558
- function be(t) {
559
- return fe[t];
560
- }
561
- function nt(t, e) {
562
- return {
563
- ...e,
564
- due: t.due,
565
- stability: t.stability,
566
- difficulty: t.difficulty,
567
- elapsedDays: t.elapsed_days,
568
- scheduledDays: t.scheduled_days,
569
- reps: t.reps,
570
- lapses: t.lapses,
571
- state: be(t.state),
572
- lastReview: t.last_review ?? null
573
- };
574
- }
575
- function at(t) {
576
- const e = V.indexOf(t);
577
- if (e === -1)
578
- throw new Error(`Invalid rating: ${t}`);
579
- return e;
580
- }
581
- function Tt(t, e) {
582
- const i = P();
583
- return {
584
- id: "",
585
- due: null,
586
- stability: i.stability,
587
- difficulty: i.difficulty,
588
- elapsedDays: i.elapsed_days,
589
- scheduledDays: i.scheduled_days,
590
- reps: i.reps,
591
- lapses: i.lapses,
592
- state: Ne.New,
593
- lastReview: i.last_review ?? null,
594
- userDeckStudyId: t,
595
- cardId: e
596
- };
597
- }
598
- var xe = Symbol.for("immer-nothing"), ne = Symbol.for("immer-draftable"), w = Symbol.for("immer-state"), ot = process.env.NODE_ENV !== "production" ? [
599
- // All error codes, starting by 0:
600
- function(t) {
601
- return `The plugin for '${t}' has not been loaded into Immer. To enable the plugin, import and call \`enable${t}()\` when initializing your application.`;
602
- },
603
- function(t) {
604
- return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${t}'`;
605
- },
606
- "This object has been frozen and should not be mutated",
607
- function(t) {
608
- return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + t;
609
- },
610
- "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
611
- "Immer forbids circular references",
612
- "The first or second argument to `produce` must be a function",
613
- "The third argument to `produce` must be a function or undefined",
614
- "First argument to `createDraft` must be a plain object, an array, or an immerable object",
615
- "First argument to `finishDraft` must be a draft returned by `createDraft`",
616
- function(t) {
617
- return `'current' expects a draft, got: ${t}`;
618
- },
619
- "Object.defineProperty() cannot be used on an Immer draft",
620
- "Object.setPrototypeOf() cannot be used on an Immer draft",
621
- "Immer only supports deleting array indices",
622
- "Immer only supports setting array indices and the 'length' property",
623
- function(t) {
624
- return `'original' expects a draft, got: ${t}`;
625
- }
626
- // Note: if more errors are added, the errorOffset in Patches.ts should be increased
627
- // See Patches.ts for additional errors
628
- ] : [];
629
- function m(t, ...e) {
630
- if (process.env.NODE_ENV !== "production") {
631
- const i = ot[t], r = typeof i == "function" ? i.apply(null, e) : i;
632
- throw new Error(`[Immer] ${r}`);
633
- }
634
- throw new Error(
635
- `[Immer] minified error nr: ${t}. Full error at: https://bit.ly/3cXEKWf`
636
- );
637
- }
638
- var C = Object.getPrototypeOf;
639
- function S(t) {
640
- return !!t && !!t[w];
641
- }
642
- function x(t) {
643
- var e;
644
- return t ? Me(t) || Array.isArray(t) || !!t[ne] || !!((e = t.constructor) != null && e[ne]) || F(t) || H(t) : !1;
645
- }
646
- var lt = Object.prototype.constructor.toString(), ae = /* @__PURE__ */ new WeakMap();
647
- function Me(t) {
648
- if (!t || typeof t != "object")
649
- return !1;
650
- const e = Object.getPrototypeOf(t);
651
- if (e === null || e === Object.prototype)
652
- return !0;
653
- const i = Object.hasOwnProperty.call(e, "constructor") && e.constructor;
654
- if (i === Object)
655
- return !0;
656
- if (typeof i != "function")
657
- return !1;
658
- let r = ae.get(i);
659
- return r === void 0 && (r = Function.toString.call(i), ae.set(i, r)), r === lt;
660
- }
661
- function A(t, e, i = !0) {
662
- j(t) === 0 ? (i ? Reflect.ownKeys(t) : Object.keys(t)).forEach((s) => {
663
- e(s, t[s], t);
664
- }) : t.forEach((r, s) => e(s, r, t));
665
- }
666
- function j(t) {
667
- const e = t[w];
668
- return e ? e.type_ : Array.isArray(t) ? 1 : F(t) ? 2 : H(t) ? 3 : 0;
669
- }
670
- function K(t, e) {
671
- return j(t) === 2 ? t.has(e) : Object.prototype.hasOwnProperty.call(t, e);
672
- }
673
- function Se(t, e, i) {
674
- const r = j(t);
675
- r === 2 ? t.set(e, i) : r === 3 ? t.add(i) : t[e] = i;
676
- }
677
- function ct(t, e) {
678
- return t === e ? t !== 0 || 1 / t === 1 / e : t !== t && e !== e;
679
- }
680
- function F(t) {
681
- return t instanceof Map;
682
- }
683
- function H(t) {
684
- return t instanceof Set;
685
- }
686
- function v(t) {
687
- return t.copy_ || t.base_;
688
- }
689
- function B(t, e) {
690
- if (F(t))
691
- return new Map(t);
692
- if (H(t))
693
- return new Set(t);
694
- if (Array.isArray(t))
695
- return Array.prototype.slice.call(t);
696
- const i = Me(t);
697
- if (e === !0 || e === "class_only" && !i) {
698
- const r = Object.getOwnPropertyDescriptors(t);
699
- delete r[w];
700
- let s = Reflect.ownKeys(r);
701
- for (let n = 0; n < s.length; n++) {
702
- const a = s[n], o = r[a];
703
- o.writable === !1 && (o.writable = !0, o.configurable = !0), (o.get || o.set) && (r[a] = {
704
- configurable: !0,
705
- writable: !0,
706
- // could live with !!desc.set as well here...
707
- enumerable: o.enumerable,
708
- value: t[a]
709
- });
710
- }
711
- return Object.create(C(t), r);
712
- } else {
713
- const r = C(t);
714
- if (r !== null && i)
715
- return { ...t };
716
- const s = Object.create(r);
717
- return Object.assign(s, t);
718
- }
719
- }
720
- function ee(t, e = !1) {
721
- return $(t) || S(t) || !x(t) || (j(t) > 1 && Object.defineProperties(t, {
722
- set: I,
723
- add: I,
724
- clear: I,
725
- delete: I
726
- }), Object.freeze(t), e && Object.values(t).forEach((i) => ee(i, !0))), t;
727
- }
728
- function ut() {
729
- m(2);
730
- }
731
- var I = {
732
- value: ut
230
+ function le() {
231
+ let e = 4022871197;
232
+ return function(t) {
233
+ t = String(t);
234
+ for (let n = 0; n < t.length; n++) {
235
+ e += t.charCodeAt(n);
236
+ let r = .02519603282416938 * e;
237
+ e = r >>> 0, r -= e, r *= e, e = r >>> 0, r -= e, e += r * 4294967296;
238
+ }
239
+ return (e >>> 0) * 23283064365386963e-26;
240
+ };
241
+ }
242
+ function ue(e) {
243
+ let t = new ce(e), n = () => t.next();
244
+ 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
+ }
246
+ var de = -.5, fe = 19 / 81;
247
+ function pe(e, t) {
248
+ return +((1 + fe * e / t) ** +de).toFixed(8);
249
+ }
250
+ var me = class {
251
+ param;
252
+ intervalModifier;
253
+ _seed;
254
+ constructor(e) {
255
+ this.param = new Proxy(b(e), this.params_handler_proxy()), this.intervalModifier = this.calculate_interval_modifier(this.param.request_retention);
256
+ }
257
+ get interval_modifier() {
258
+ return this.intervalModifier;
259
+ }
260
+ set seed(e) {
261
+ this._seed = e;
262
+ }
263
+ calculate_interval_modifier(e) {
264
+ 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);
266
+ }
267
+ get parameters() {
268
+ return this.param;
269
+ }
270
+ set parameters(e) {
271
+ this.update_parameters(e);
272
+ }
273
+ params_handler_proxy() {
274
+ let e = this;
275
+ return { set: function(t, n, r) {
276
+ return n === "request_retention" && Number.isFinite(r) && (e.intervalModifier = e.calculate_interval_modifier(Number(r))), Reflect.set(t, n, r), !0;
277
+ } };
278
+ }
279
+ update_parameters(e) {
280
+ let t = b(e);
281
+ for (let e in t) if (e in this.param) {
282
+ let n = e;
283
+ this.param[n] = t[n];
284
+ }
285
+ }
286
+ init_stability(e) {
287
+ return Math.max(this.param.w[e - 1], .1);
288
+ }
289
+ init_difficulty(e) {
290
+ return this.constrain_difficulty(this.param.w[4] - Math.exp((e - 1) * this.param.w[5]) + 1);
291
+ }
292
+ apply_fuzz(e, t) {
293
+ 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);
295
+ return Math.floor(n * (i - r + 1) + r);
296
+ }
297
+ next_interval(e, t) {
298
+ let n = Math.min(Math.max(1, Math.round(e * this.intervalModifier)), this.param.maximum_interval);
299
+ return this.apply_fuzz(n, t);
300
+ }
301
+ linear_damping(e, t) {
302
+ return +(e * (10 - t) / 9).toFixed(8);
303
+ }
304
+ next_difficulty(e, t) {
305
+ 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));
307
+ }
308
+ constrain_difficulty(e) {
309
+ return Math.min(Math.max(+e.toFixed(8), 1), 10);
310
+ }
311
+ mean_reversion(e, t) {
312
+ return +(this.param.w[7] * e + (1 - this.param.w[7]) * t).toFixed(8);
313
+ }
314
+ 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;
316
+ 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
+ }
318
+ next_forget_stability(e, t, n) {
319
+ return +v(this.param.w[11] * e ** +-this.param.w[12] * ((t + 1) ** +this.param.w[13] - 1) * Math.exp((1 - n) * this.param.w[14]), y, 36500).toFixed(8);
320
+ }
321
+ next_short_term_stability(e, t) {
322
+ return +v(e * Math.exp(this.param.w[17] * (t - 3 + this.param.w[18])), y, 36500).toFixed(8);
323
+ }
324
+ forgetting_curve = pe;
325
+ next_state(e, t, n) {
326
+ let { difficulty: r, stability: i } = e ?? {
327
+ difficulty: 0,
328
+ stability: 0
329
+ };
330
+ if (t < 0) throw Error(`Invalid delta_t "${t}"`);
331
+ if (n < 0 || n > 4) throw Error(`Invalid grade "${n}"`);
332
+ if (r === 0 && i === 0) return {
333
+ difficulty: this.init_difficulty(n),
334
+ stability: this.init_stability(n)
335
+ };
336
+ if (n === 0) return {
337
+ difficulty: r,
338
+ stability: i
339
+ };
340
+ if (r < 1 || i < .01) throw Error(`Invalid memory state { difficulty: ${r}, stability: ${i} }`);
341
+ let a = this.forgetting_curve(t, i), o = this.next_recall_stability(r, i, a, n), s = this.next_forget_stability(r, i, a), c = this.next_short_term_stability(i, n), l = o;
342
+ if (n === 1) {
343
+ let [e, t] = [0, 0];
344
+ this.param.enable_short_term && (e = this.param.w[17], t = this.param.w[18]), l = v(+(i / Math.exp(e * t)).toFixed(8), y, s);
345
+ }
346
+ return t === 0 && this.param.enable_short_term && (l = c), {
347
+ difficulty: this.next_difficulty(r, n),
348
+ stability: l
349
+ };
350
+ }
733
351
  };
734
- function $(t) {
735
- return t === null || typeof t != "object" ? !0 : Object.isFrozen(t);
736
- }
737
- var dt = {};
738
- function M(t) {
739
- const e = dt[t];
740
- return e || m(0, t), e;
741
- }
742
- var z;
743
- function Ee() {
744
- return z;
745
- }
746
- function ft(t, e) {
747
- return {
748
- drafts_: [],
749
- parent_: t,
750
- immer_: e,
751
- // Whenever the modified draft contains a draft from another scope, we
752
- // need to prevent auto-freezing so the unowned draft can be finalized.
753
- canAutoFreeze_: !0,
754
- unfinalizedDrafts_: 0
755
- };
756
- }
757
- function oe(t, e) {
758
- e && (M("Patches"), t.patches_ = [], t.inversePatches_ = [], t.patchListener_ = e);
759
- }
760
- function X(t) {
761
- Z(t), t.drafts_.forEach(ht), t.drafts_ = null;
762
- }
763
- function Z(t) {
764
- t === z && (z = t.parent_);
765
- }
766
- function le(t) {
767
- return z = ft(z, t);
768
- }
769
- function ht(t) {
770
- const e = t[w];
771
- e.type_ === 0 || e.type_ === 1 ? e.revoke_() : e.revoked_ = !0;
772
- }
773
- function ce(t, e) {
774
- e.unfinalizedDrafts_ = e.drafts_.length;
775
- const i = e.drafts_[0];
776
- return t !== void 0 && t !== i ? (i[w].modified_ && (X(e), m(4)), x(t) && (t = T(e, t), e.parent_ || k(e, t)), e.patches_ && M("Patches").generateReplacementPatches_(
777
- i[w].base_,
778
- t,
779
- e.patches_,
780
- e.inversePatches_
781
- )) : t = T(e, i, []), X(e), e.patches_ && e.patchListener_(e.patches_, e.inversePatches_), t !== xe ? t : void 0;
782
- }
783
- function T(t, e, i) {
784
- if ($(e))
785
- return e;
786
- const r = t.immer_.shouldUseStrictIteration(), s = e[w];
787
- if (!s)
788
- return A(
789
- e,
790
- (n, a) => ue(t, s, e, n, a, i),
791
- r
792
- ), e;
793
- if (s.scope_ !== t)
794
- return e;
795
- if (!s.modified_)
796
- return k(t, s.base_, !0), s.base_;
797
- if (!s.finalized_) {
798
- s.finalized_ = !0, s.scope_.unfinalizedDrafts_--;
799
- const n = s.copy_;
800
- let a = n, o = !1;
801
- s.type_ === 3 && (a = new Set(n), n.clear(), o = !0), A(
802
- a,
803
- (c, u) => ue(
804
- t,
805
- s,
806
- n,
807
- c,
808
- u,
809
- i,
810
- o
811
- ),
812
- r
813
- ), k(t, n, !1), i && t.patches_ && M("Patches").generatePatches_(
814
- s,
815
- i,
816
- t.patches_,
817
- t.inversePatches_
818
- );
819
- }
820
- return s.copy_;
821
- }
822
- function ue(t, e, i, r, s, n, a) {
823
- if (s == null || typeof s != "object" && !a)
824
- return;
825
- const o = $(s);
826
- if (!(o && !a)) {
827
- if (process.env.NODE_ENV !== "production" && s === i && m(5), S(s)) {
828
- const c = n && e && e.type_ !== 3 && // Set objects are atomic since they have no keys.
829
- !K(e.assigned_, r) ? n.concat(r) : void 0, u = T(t, s, c);
830
- if (Se(i, r, u), S(u))
831
- t.canAutoFreeze_ = !1;
832
- else
833
- return;
834
- } else a && i.add(s);
835
- if (x(s) && !o) {
836
- if (!t.immer_.autoFreeze_ && t.unfinalizedDrafts_ < 1 || e && e.base_ && e.base_[r] === s && o)
837
- return;
838
- T(t, s), (!e || !e.scope_.parent_) && typeof r != "symbol" && (F(i) ? i.has(r) : Object.prototype.propertyIsEnumerable.call(i, r)) && k(t, s);
839
- }
840
- }
841
- }
842
- function k(t, e, i = !1) {
843
- !t.parent_ && t.immer_.autoFreeze_ && t.canAutoFreeze_ && ee(e, i);
844
- }
845
- function _t(t, e) {
846
- const i = Array.isArray(t), r = {
847
- type_: i ? 1 : 0,
848
- // Track which produce call this is associated with.
849
- scope_: e ? e.scope_ : Ee(),
850
- // True for both shallow and deep changes.
851
- modified_: !1,
852
- // Used during finalization.
853
- finalized_: !1,
854
- // Track which properties have been assigned (true) or deleted (false).
855
- assigned_: {},
856
- // The parent draft state.
857
- parent_: e,
858
- // The base state.
859
- base_: t,
860
- // The base proxy.
861
- draft_: null,
862
- // set below
863
- // The base copy with any updated values.
864
- copy_: null,
865
- // Called by the `produce` function.
866
- revoke_: null,
867
- isManual_: !1
868
- };
869
- let s = r, n = te;
870
- i && (s = [r], n = O);
871
- const { revoke: a, proxy: o } = Proxy.revocable(s, n);
872
- return r.draft_ = o, r.revoke_ = a, o;
873
- }
874
- var te = {
875
- get(t, e) {
876
- if (e === w)
877
- return t;
878
- const i = v(t);
879
- if (!K(i, e))
880
- return yt(t, i, e);
881
- const r = i[e];
882
- return t.finalized_ || !x(r) ? r : r === U(t.base_, e) ? (q(t), t.copy_[e] = Q(r, t)) : r;
883
- },
884
- has(t, e) {
885
- return e in v(t);
886
- },
887
- ownKeys(t) {
888
- return Reflect.ownKeys(v(t));
889
- },
890
- set(t, e, i) {
891
- const r = Re(v(t), e);
892
- if (r != null && r.set)
893
- return r.set.call(t.draft_, i), !0;
894
- if (!t.modified_) {
895
- const s = U(v(t), e), n = s == null ? void 0 : s[w];
896
- if (n && n.base_ === i)
897
- return t.copy_[e] = i, t.assigned_[e] = !1, !0;
898
- if (ct(i, s) && (i !== void 0 || K(t.base_, e)))
899
- return !0;
900
- q(t), J(t);
901
- }
902
- return t.copy_[e] === i && // special case: handle new props with value 'undefined'
903
- (i !== void 0 || e in t.copy_) || // special case: NaN
904
- Number.isNaN(i) && Number.isNaN(t.copy_[e]) || (t.copy_[e] = i, t.assigned_[e] = !0), !0;
905
- },
906
- deleteProperty(t, e) {
907
- return U(t.base_, e) !== void 0 || e in t.base_ ? (t.assigned_[e] = !1, q(t), J(t)) : delete t.assigned_[e], t.copy_ && delete t.copy_[e], !0;
908
- },
909
- // Note: We never coerce `desc.value` into an Immer draft, because we can't make
910
- // the same guarantee in ES5 mode.
911
- getOwnPropertyDescriptor(t, e) {
912
- const i = v(t), r = Reflect.getOwnPropertyDescriptor(i, e);
913
- return r && {
914
- writable: !0,
915
- configurable: t.type_ !== 1 || e !== "length",
916
- enumerable: r.enumerable,
917
- value: i[e]
918
- };
919
- },
920
- defineProperty() {
921
- m(11);
922
- },
923
- getPrototypeOf(t) {
924
- return C(t.base_);
925
- },
926
- setPrototypeOf() {
927
- m(12);
928
- }
929
- }, O = {};
930
- A(te, (t, e) => {
931
- O[t] = function() {
932
- return arguments[0] = arguments[0][0], e.apply(this, arguments);
933
- };
934
- });
935
- O.deleteProperty = function(t, e) {
936
- return process.env.NODE_ENV !== "production" && isNaN(parseInt(e)) && m(13), O.set.call(this, t, e, void 0);
352
+ function he() {
353
+ return `${this.review_time.getTime()}_${this.current.reps}_${this.current.difficulty * this.current.stability}`;
354
+ }
355
+ var S = ((e) => (e.SCHEDULER = "Scheduler", e.SEED = "Seed", e))(S || {}), ge = class {
356
+ last;
357
+ current;
358
+ review_time;
359
+ next = /* @__PURE__ */ new Map();
360
+ algorithm;
361
+ 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();
364
+ }
365
+ init() {
366
+ 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();
368
+ }
369
+ preview() {
370
+ 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),
375
+ [Symbol.iterator]: this.previewIterator.bind(this)
376
+ };
377
+ }
378
+ *previewIterator() {
379
+ for (let e of ne) yield this.review(e);
380
+ }
381
+ review(e) {
382
+ let { state: t } = this.last, n;
383
+ switch (t) {
384
+ case l.New:
385
+ n = this.newState(e);
386
+ break;
387
+ case l.Learning:
388
+ case l.Relearning:
389
+ n = this.learningState(e);
390
+ break;
391
+ case l.Review:
392
+ n = this.reviewState(e);
393
+ break;
394
+ }
395
+ if (n) return n;
396
+ throw Error("Invalid grade");
397
+ }
398
+ buildLog(e) {
399
+ let { last_review: t, due: n, elapsed_days: r } = this.last;
400
+ return {
401
+ rating: e,
402
+ state: this.current.state,
403
+ due: t || n,
404
+ stability: this.current.stability,
405
+ difficulty: this.current.difficulty,
406
+ elapsed_days: this.current.elapsed_days,
407
+ last_elapsed_days: r,
408
+ scheduled_days: this.current.scheduled_days,
409
+ review: this.review_time
410
+ };
411
+ }
412
+ }, _e = class extends ge {
413
+ newState(e) {
414
+ let t = this.next.get(e);
415
+ if (t) return t;
416
+ let n = d.card(this.current);
417
+ 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;
420
+ break;
421
+ case u.Hard:
422
+ n.scheduled_days = 0, n.due = this.review_time.scheduler(5), n.state = l.Learning;
423
+ break;
424
+ case u.Good:
425
+ n.scheduled_days = 0, n.due = this.review_time.scheduler(10), n.state = l.Learning;
426
+ break;
427
+ case u.Easy: {
428
+ 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;
430
+ break;
431
+ }
432
+ default: throw Error("Invalid grade");
433
+ }
434
+ let r = {
435
+ card: n,
436
+ log: this.buildLog(e)
437
+ };
438
+ return this.next.set(e, r), r;
439
+ }
440
+ learningState(e) {
441
+ let t = this.next.get(e);
442
+ if (t) return t;
443
+ let { state: n, difficulty: r, stability: i } = this.last, a = d.card(this.current), o = this.current.elapsed_days;
444
+ switch (a.difficulty = this.algorithm.next_difficulty(r, e), a.stability = this.algorithm.next_short_term_stability(i, e), e) {
445
+ case u.Again:
446
+ a.scheduled_days = 0, a.due = this.review_time.scheduler(5, !1), a.state = n;
447
+ break;
448
+ case u.Hard:
449
+ a.scheduled_days = 0, a.due = this.review_time.scheduler(10), a.state = n;
450
+ break;
451
+ case u.Good: {
452
+ 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;
454
+ break;
455
+ }
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;
459
+ break;
460
+ }
461
+ default: throw Error("Invalid grade");
462
+ }
463
+ let s = {
464
+ card: a,
465
+ log: this.buildLog(e)
466
+ };
467
+ return this.next.set(e, s), s;
468
+ }
469
+ reviewState(e) {
470
+ let t = this.next.get(e);
471
+ 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);
473
+ 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 = {
475
+ card: o,
476
+ log: this.buildLog(u.Again)
477
+ }, p = {
478
+ card: s,
479
+ log: super.buildLog(u.Hard)
480
+ }, m = {
481
+ card: c,
482
+ log: super.buildLog(u.Good)
483
+ }, ee = {
484
+ card: l,
485
+ log: super.buildLog(u.Easy)
486
+ };
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);
488
+ }
489
+ next_ds(e, t, n, r, i, a, o) {
490
+ e.difficulty = this.algorithm.next_difficulty(i, u.Again);
491
+ 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);
493
+ }
494
+ next_interval(e, t, n, r, i) {
495
+ let a, o;
496
+ a = this.algorithm.next_interval(t.stability, i), o = this.algorithm.next_interval(n.stability, i), a = Math.min(a, o), o = Math.max(o, a + 1);
497
+ let s = Math.max(this.algorithm.next_interval(r.stability, i), o + 1);
498
+ 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
+ }
500
+ next_state(e, t, n, r) {
501
+ e.state = l.Relearning, t.state = l.Review, n.state = l.Review, r.state = l.Review;
502
+ }
503
+ }, ve = class extends ge {
504
+ newState(e) {
505
+ let t = this.next.get(e);
506
+ if (t) return t;
507
+ 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);
509
+ 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
+ }
511
+ 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);
513
+ }
514
+ learningState(e) {
515
+ return this.reviewState(e);
516
+ }
517
+ reviewState(e) {
518
+ let t = this.next.get(e);
519
+ 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);
521
+ 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
+ }
523
+ 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);
525
+ }
526
+ next_interval(e, t, n, r, i) {
527
+ let a, o, s, c;
528
+ 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
+ }
530
+ next_state(e, t, n, r) {
531
+ e.state = l.Review, t.state = l.Review, n.state = l.Review, r.state = l.Review;
532
+ }
533
+ update_next(e, t, n, r) {
534
+ let i = {
535
+ card: e,
536
+ log: this.buildLog(u.Again)
537
+ }, a = {
538
+ card: t,
539
+ log: super.buildLog(u.Hard)
540
+ }, o = {
541
+ card: n,
542
+ log: super.buildLog(u.Good)
543
+ }, s = {
544
+ card: r,
545
+ log: super.buildLog(u.Easy)
546
+ };
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);
548
+ }
549
+ }, ye = class {
550
+ fsrs;
551
+ constructor(e) {
552
+ this.fsrs = e;
553
+ }
554
+ replay(e, t, n) {
555
+ return this.fsrs.next(e, t, n);
556
+ }
557
+ handleManualRating(e, t, n, r, i, a, o) {
558
+ if (typeof t > "u") throw Error("reschedule: state is required for manual rating");
559
+ let s, c;
560
+ if (t === l.New) s = {
561
+ rating: u.Manual,
562
+ state: t,
563
+ due: o ?? n,
564
+ stability: e.stability,
565
+ difficulty: e.difficulty,
566
+ elapsed_days: r,
567
+ last_elapsed_days: e.elapsed_days,
568
+ scheduled_days: e.scheduled_days,
569
+ review: n
570
+ }, c = x(n), c.last_review = n;
571
+ else {
572
+ if (typeof o > "u") throw Error("reschedule: due is required for manual rating");
573
+ let l = o.diff(n, "days");
574
+ s = {
575
+ rating: u.Manual,
576
+ state: e.state,
577
+ due: e.last_review || e.due,
578
+ stability: e.stability,
579
+ difficulty: e.difficulty,
580
+ elapsed_days: r,
581
+ last_elapsed_days: e.elapsed_days,
582
+ scheduled_days: e.scheduled_days,
583
+ review: n
584
+ }, c = {
585
+ ...e,
586
+ state: t,
587
+ due: o,
588
+ last_review: n,
589
+ stability: i || e.stability,
590
+ difficulty: a || e.difficulty,
591
+ elapsed_days: r,
592
+ scheduled_days: l,
593
+ reps: e.reps + 1
594
+ };
595
+ }
596
+ return {
597
+ card: c,
598
+ log: s
599
+ };
600
+ }
601
+ reschedule(e, t) {
602
+ let n = [], r = x(e.due);
603
+ for (let e of t) {
604
+ let t;
605
+ if (e.review = d.time(e.review), e.rating === u.Manual) {
606
+ 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);
608
+ } else t = this.replay(r, e.review, e.rating);
609
+ n.push(t), r = t.card;
610
+ }
611
+ return n;
612
+ }
613
+ calculateManualRecord(e, t, n, r) {
614
+ 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));
617
+ }
618
+ }, be = class extends me {
619
+ strategyHandler = /* @__PURE__ */ new Map();
620
+ Scheduler;
621
+ constructor(e) {
622
+ super(e);
623
+ let { enable_short_term: t } = this.parameters;
624
+ this.Scheduler = t ? _e : ve;
625
+ }
626
+ params_handler_proxy() {
627
+ let e = this;
628
+ 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;
630
+ } };
631
+ }
632
+ useStrategy(e, t) {
633
+ return this.strategyHandler.set(e, t), this;
634
+ }
635
+ clearStrategy(e) {
636
+ return e ? this.strategyHandler.delete(e) : this.strategyHandler.clear(), this;
637
+ }
638
+ getScheduler(e, t) {
639
+ let n = this.strategyHandler.get(S.SEED);
640
+ return new ((this.strategyHandler.get(S.SCHEDULER)) || this.Scheduler)(e, t, this, { seed: n || he });
641
+ }
642
+ repeat(e, t, n) {
643
+ let r = this.getScheduler(e, t).preview();
644
+ return n && typeof n == "function" ? n(r) : r;
645
+ }
646
+ 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");
649
+ let o = i.review(a);
650
+ return r && typeof r == "function" ? r(o) : o;
651
+ }
652
+ 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));
656
+ return n ? `${(a * 100).toFixed(2)}%` : a;
657
+ }
658
+ 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");
661
+ let a, o, s;
662
+ switch (i.state) {
663
+ case l.New:
664
+ a = i.due, o = void 0, s = 0;
665
+ 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);
670
+ break;
671
+ }
672
+ let c = {
673
+ ...r,
674
+ due: a,
675
+ stability: i.stability,
676
+ difficulty: i.difficulty,
677
+ elapsed_days: i.last_elapsed_days,
678
+ scheduled_days: i.scheduled_days,
679
+ reps: Math.max(0, r.reps - 1),
680
+ lapses: Math.max(0, s),
681
+ state: i.state,
682
+ last_review: o
683
+ };
684
+ return n && typeof n == "function" ? n(c) : c;
685
+ }
686
+ 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,
691
+ state: i.state,
692
+ due: i.due,
693
+ stability: i.stability,
694
+ difficulty: i.difficulty,
695
+ elapsed_days: 0,
696
+ last_elapsed_days: i.elapsed_days,
697
+ scheduled_days: a,
698
+ review: t
699
+ }, s = {
700
+ card: {
701
+ ...i,
702
+ due: t,
703
+ stability: 0,
704
+ difficulty: 0,
705
+ elapsed_days: 0,
706
+ scheduled_days: 0,
707
+ reps: n ? 0 : i.reps,
708
+ lapses: n ? 0 : i.lapses,
709
+ state: l.New,
710
+ last_review: i.last_review
711
+ },
712
+ log: o
713
+ };
714
+ return r && typeof r == "function" ? r(s) : s;
715
+ }
716
+ reschedule(e, t = [], n = {}) {
717
+ 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);
720
+ return r && typeof r == "function" ? {
721
+ collections: l.map(r),
722
+ reschedule_item: m ? r(m) : null
723
+ } : {
724
+ collections: l,
725
+ reschedule_item: m
726
+ };
727
+ }
728
+ }, xe = ((e) => new be(e || {}))(b({
729
+ request_retention: i,
730
+ enable_fuzz: !0,
731
+ maximum_interval: 100
732
+ })), Se = (e) => e.due ? e : {
733
+ ...e,
734
+ due: /* @__PURE__ */ new Date()
735
+ }, Ce = (e) => t.indexOf(e), we = (e) => ({
736
+ due: e.due,
737
+ stability: e.stability,
738
+ difficulty: e.difficulty,
739
+ elapsed_days: e.elapsedDays,
740
+ scheduled_days: e.scheduledDays,
741
+ reps: e.reps,
742
+ lapses: e.lapses,
743
+ state: Ce(e.state),
744
+ 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;
749
+ return {
750
+ nextCard: a,
751
+ reviewLog: {
752
+ id: 0,
753
+ cardReviewId: e.id,
754
+ grade: t,
755
+ state: Oe(o.state),
756
+ due: o.due,
757
+ stability: o.stability,
758
+ difficulty: o.difficulty,
759
+ elapsedDays: o.elapsed_days,
760
+ lastElapsedDays: o.last_elapsed_days,
761
+ scheduledDays: o.scheduled_days,
762
+ review: o.review,
763
+ duration: n
764
+ }
765
+ };
766
+ });
937
767
  };
938
- O.set = function(t, e, i) {
939
- return process.env.NODE_ENV !== "production" && e !== "length" && isNaN(parseInt(e)) && m(14), te.set.call(this, t[0], e, i, t[0]);
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);
772
+ a[n] = t;
773
+ }
774
+ return a;
775
+ }
776
+ function De(e) {
777
+ return r[e];
778
+ }
779
+ function Oe(e) {
780
+ return t[e];
781
+ }
782
+ function C(e, t) {
783
+ return {
784
+ ...t,
785
+ due: e.due,
786
+ stability: e.stability,
787
+ difficulty: e.difficulty,
788
+ elapsedDays: e.elapsed_days,
789
+ scheduledDays: e.scheduled_days,
790
+ reps: e.reps,
791
+ lapses: e.lapses,
792
+ state: Oe(e.state),
793
+ lastReview: e.last_review ?? null
794
+ };
795
+ }
796
+ function ke(e) {
797
+ let t = r.indexOf(e);
798
+ if (t === -1) throw Error(`Invalid rating: ${e}`);
799
+ return t;
800
+ }
801
+ function Ae(e, t) {
802
+ let r = x();
803
+ return {
804
+ id: "",
805
+ due: null,
806
+ stability: r.stability,
807
+ difficulty: r.difficulty,
808
+ elapsedDays: r.elapsed_days,
809
+ scheduledDays: r.scheduled_days,
810
+ reps: r.reps,
811
+ lapses: r.lapses,
812
+ state: n.New,
813
+ lastReview: r.last_review ?? null,
814
+ userDeckStudyId: e,
815
+ cardId: t
816
+ };
817
+ }
818
+ //#endregion
819
+ //#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" ? [] : [
821
+ function(e) {
822
+ 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
+ },
824
+ function(e) {
825
+ return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${e}'`;
826
+ },
827
+ "This object has been frozen and should not be mutated",
828
+ function(e) {
829
+ return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + e;
830
+ },
831
+ "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
832
+ "Immer forbids circular references",
833
+ "The first or second argument to `produce` must be a function",
834
+ "The third argument to `produce` must be a function or undefined",
835
+ "First argument to `createDraft` must be a plain object, an array, or an immerable object",
836
+ "First argument to `finishDraft` must be a draft returned by `createDraft`",
837
+ function(e) {
838
+ return `'current' expects a draft, got: ${e}`;
839
+ },
840
+ "Object.defineProperty() cannot be used on an Immer draft",
841
+ "Object.setPrototypeOf() cannot be used on an Immer draft",
842
+ "Immer only supports deleting array indices",
843
+ "Immer only supports setting array indices and the 'length' property",
844
+ function(e) {
845
+ return `'original' expects a draft, got: ${e}`;
846
+ }
847
+ ];
848
+ function T(e, ...t) {
849
+ if (process.env.NODE_ENV !== "production") {
850
+ let n = Ne[e], r = typeof n == "function" ? n.apply(null, t) : n;
851
+ throw Error(`[Immer] ${r}`);
852
+ }
853
+ throw Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`);
854
+ }
855
+ var E = Object.getPrototypeOf;
856
+ function D(e) {
857
+ return !!e && !!e[w];
858
+ }
859
+ function O(e) {
860
+ return e ? Ie(e) || Array.isArray(e) || !!e[Me] || !!e.constructor?.[Me] || M(e) || N(e) : !1;
861
+ }
862
+ var Pe = Object.prototype.constructor.toString(), Fe = /* @__PURE__ */ new WeakMap();
863
+ function Ie(e) {
864
+ if (!e || typeof e != "object") return !1;
865
+ let t = Object.getPrototypeOf(e);
866
+ if (t === null || t === Object.prototype) return !0;
867
+ let n = Object.hasOwnProperty.call(t, "constructor") && t.constructor;
868
+ if (n === Object) return !0;
869
+ 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;
872
+ }
873
+ function k(e, t, n = !0) {
874
+ A(e) === 0 ? (n ? Reflect.ownKeys(e) : Object.keys(e)).forEach((n) => {
875
+ t(n, e[n], e);
876
+ }) : e.forEach((n, r) => t(r, n, e));
877
+ }
878
+ function A(e) {
879
+ let t = e[w];
880
+ return t ? t.type_ : Array.isArray(e) ? 1 : M(e) ? 2 : N(e) ? 3 : 0;
881
+ }
882
+ function j(e, t) {
883
+ return A(e) === 2 ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t);
884
+ }
885
+ function Le(e, t, n) {
886
+ let r = A(e);
887
+ r === 2 ? e.set(t, n) : r === 3 ? e.add(n) : e[t] = n;
888
+ }
889
+ function Re(e, t) {
890
+ return e === t ? e !== 0 || 1 / e == 1 / t : e !== e && t !== t;
891
+ }
892
+ function M(e) {
893
+ return e instanceof Map;
894
+ }
895
+ function N(e) {
896
+ return e instanceof Set;
897
+ }
898
+ function P(e) {
899
+ return e.copy_ || e.base_;
900
+ }
901
+ function F(e, t) {
902
+ if (M(e)) return new Map(e);
903
+ if (N(e)) return new Set(e);
904
+ if (Array.isArray(e)) return Array.prototype.slice.call(e);
905
+ let n = Ie(e);
906
+ if (t === !0 || t === "class_only" && !n) {
907
+ let t = Object.getOwnPropertyDescriptors(e);
908
+ delete t[w];
909
+ let n = Reflect.ownKeys(t);
910
+ for (let r = 0; r < n.length; r++) {
911
+ let i = n[r], a = t[i];
912
+ a.writable === !1 && (a.writable = !0, a.configurable = !0), (a.get || a.set) && (t[i] = {
913
+ configurable: !0,
914
+ writable: !0,
915
+ enumerable: a.enumerable,
916
+ value: e[i]
917
+ });
918
+ }
919
+ return Object.create(E(e), t);
920
+ } else {
921
+ let t = E(e);
922
+ return t !== null && n ? { ...e } : Object.assign(Object.create(t), e);
923
+ }
924
+ }
925
+ function I(e, t = !1) {
926
+ return R(e) || D(e) || !O(e) ? e : (A(e) > 1 && Object.defineProperties(e, {
927
+ set: L,
928
+ add: L,
929
+ clear: L,
930
+ delete: L
931
+ }), Object.freeze(e), t && Object.values(e).forEach((e) => I(e, !0)), e);
932
+ }
933
+ function ze() {
934
+ T(2);
935
+ }
936
+ var L = { value: ze };
937
+ function R(e) {
938
+ return typeof e != "object" || !e ? !0 : Object.isFrozen(e);
939
+ }
940
+ var Be = {};
941
+ function z(e) {
942
+ let t = Be[e];
943
+ return t || T(0, e), t;
944
+ }
945
+ var B;
946
+ function Ve() {
947
+ return B;
948
+ }
949
+ function He(e, t) {
950
+ return {
951
+ drafts_: [],
952
+ parent_: e,
953
+ immer_: t,
954
+ canAutoFreeze_: !0,
955
+ unfinalizedDrafts_: 0
956
+ };
957
+ }
958
+ function Ue(e, t) {
959
+ t && (z("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t);
960
+ }
961
+ function V(e) {
962
+ H(e), e.drafts_.forEach(Ge), e.drafts_ = null;
963
+ }
964
+ function H(e) {
965
+ e === B && (B = e.parent_);
966
+ }
967
+ function We(e) {
968
+ return B = He(B, e);
969
+ }
970
+ function Ge(e) {
971
+ let t = e[w];
972
+ t.type_ === 0 || t.type_ === 1 ? t.revoke_() : t.revoked_ = !0;
973
+ }
974
+ function Ke(e, t) {
975
+ t.unfinalizedDrafts_ = t.drafts_.length;
976
+ 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;
978
+ }
979
+ function U(e, t, n) {
980
+ if (R(t)) return t;
981
+ 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;
983
+ if (i.scope_ !== e) return t;
984
+ if (!i.modified_) return W(e, i.base_, !0), i.base_;
985
+ if (!i.finalized_) {
986
+ i.finalized_ = !0, i.scope_.unfinalizedDrafts_--;
987
+ 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_);
989
+ }
990
+ return i.copy_;
991
+ }
992
+ function qe(e, t, n, r, i, a, o) {
993
+ if (i == null || typeof i != "object" && !o) return;
994
+ let s = R(i);
995
+ if (!(s && !o)) {
996
+ if (process.env.NODE_ENV !== "production" && i === n && T(5), D(i)) {
997
+ 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;
999
+ else return;
1000
+ } else o && n.add(i);
1001
+ if (O(i) && !s) {
1002
+ if (!e.immer_.autoFreeze_ && e.unfinalizedDrafts_ < 1 || t && t.base_ && t.base_[r] === i && s) return;
1003
+ U(e, i), (!t || !t.scope_.parent_) && typeof r != "symbol" && (M(n) ? n.has(r) : Object.prototype.propertyIsEnumerable.call(n, r)) && W(e, i);
1004
+ }
1005
+ }
1006
+ }
1007
+ function W(e, t, n = !1) {
1008
+ !e.parent_ && e.immer_.autoFreeze_ && e.canAutoFreeze_ && I(t, n);
1009
+ }
1010
+ function Je(e, t) {
1011
+ let n = Array.isArray(e), r = {
1012
+ type_: +!!n,
1013
+ scope_: t ? t.scope_ : Ve(),
1014
+ modified_: !1,
1015
+ finalized_: !1,
1016
+ assigned_: {},
1017
+ parent_: t,
1018
+ base_: e,
1019
+ draft_: null,
1020
+ copy_: null,
1021
+ revoke_: null,
1022
+ isManual_: !1
1023
+ }, i = r, a = G;
1024
+ n && (i = [r], a = K);
1025
+ let { revoke: o, proxy: s } = Proxy.revocable(i, a);
1026
+ return r.draft_ = s, r.revoke_ = o, s;
1027
+ }
1028
+ var G = {
1029
+ get(e, t) {
1030
+ if (t === w) return e;
1031
+ let n = P(e);
1032
+ if (!j(n, t)) return Ye(e, n, t);
1033
+ let r = n[t];
1034
+ return e.finalized_ || !O(r) ? r : r === q(e.base_, t) ? (Y(e), e.copy_[t] = X(r, e)) : r;
1035
+ },
1036
+ has(e, t) {
1037
+ return t in P(e);
1038
+ },
1039
+ ownKeys(e) {
1040
+ return Reflect.ownKeys(P(e));
1041
+ },
1042
+ set(e, t, n) {
1043
+ let r = Xe(P(e), t);
1044
+ if (r?.set) return r.set.call(e.draft_, n), !0;
1045
+ if (!e.modified_) {
1046
+ let r = q(P(e), t), i = r?.[w];
1047
+ 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;
1049
+ Y(e), J(e);
1050
+ }
1051
+ 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);
1052
+ },
1053
+ deleteProperty(e, t) {
1054
+ return q(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, Y(e), J(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0;
1055
+ },
1056
+ getOwnPropertyDescriptor(e, t) {
1057
+ let n = P(e), r = Reflect.getOwnPropertyDescriptor(n, t);
1058
+ return r && {
1059
+ writable: !0,
1060
+ configurable: e.type_ !== 1 || t !== "length",
1061
+ enumerable: r.enumerable,
1062
+ value: n[t]
1063
+ };
1064
+ },
1065
+ defineProperty() {
1066
+ T(11);
1067
+ },
1068
+ getPrototypeOf(e) {
1069
+ return E(e.base_);
1070
+ },
1071
+ setPrototypeOf() {
1072
+ T(12);
1073
+ }
1074
+ }, K = {};
1075
+ k(G, (e, t) => {
1076
+ K[e] = function() {
1077
+ return arguments[0] = arguments[0][0], t.apply(this, arguments);
1078
+ };
1079
+ }), K.deleteProperty = function(e, t) {
1080
+ return process.env.NODE_ENV !== "production" && isNaN(parseInt(t)) && T(13), K.set.call(this, e, t, void 0);
1081
+ }, K.set = function(e, t, n) {
1082
+ return process.env.NODE_ENV !== "production" && t !== "length" && isNaN(parseInt(t)) && T(14), G.set.call(this, e[0], t, n, e[0]);
940
1083
  };
941
- function U(t, e) {
942
- const i = t[w];
943
- return (i ? v(i) : t)[e];
944
- }
945
- function yt(t, e, i) {
946
- var s;
947
- const r = Re(e, i);
948
- return r ? "value" in r ? r.value : (
949
- // This is a very special case, if the prop is a getter defined by the
950
- // prototype, we should invoke it with the draft as context!
951
- (s = r.get) == null ? void 0 : s.call(t.draft_)
952
- ) : void 0;
953
- }
954
- function Re(t, e) {
955
- if (!(e in t))
956
- return;
957
- let i = C(t);
958
- for (; i; ) {
959
- const r = Object.getOwnPropertyDescriptor(i, e);
960
- if (r)
961
- return r;
962
- i = C(i);
963
- }
964
- }
965
- function J(t) {
966
- t.modified_ || (t.modified_ = !0, t.parent_ && J(t.parent_));
967
- }
968
- function q(t) {
969
- t.copy_ || (t.copy_ = B(
970
- t.base_,
971
- t.scope_.immer_.useStrictShallowCopy_
972
- ));
973
- }
974
- var mt = class {
975
- constructor(t) {
976
- this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !0, this.produce = (e, i, r) => {
977
- if (typeof e == "function" && typeof i != "function") {
978
- const n = i;
979
- i = e;
980
- const a = this;
981
- return function(c = n, ...u) {
982
- return a.produce(c, (f) => i.call(this, f, ...u));
983
- };
984
- }
985
- typeof i != "function" && m(6), r !== void 0 && typeof r != "function" && m(7);
986
- let s;
987
- if (x(e)) {
988
- const n = le(this), a = Q(e, void 0);
989
- let o = !0;
990
- try {
991
- s = i(a), o = !1;
992
- } finally {
993
- o ? X(n) : Z(n);
994
- }
995
- return oe(n, r), ce(s, n);
996
- } else if (!e || typeof e != "object") {
997
- if (s = i(e), s === void 0 && (s = e), s === xe && (s = void 0), this.autoFreeze_ && ee(s, !0), r) {
998
- const n = [], a = [];
999
- M("Patches").generateReplacementPatches_(e, s, n, a), r(n, a);
1000
- }
1001
- return s;
1002
- } else
1003
- m(1, e);
1004
- }, this.produceWithPatches = (e, i) => {
1005
- if (typeof e == "function")
1006
- return (a, ...o) => this.produceWithPatches(a, (c) => e(c, ...o));
1007
- let r, s;
1008
- return [this.produce(e, i, (a, o) => {
1009
- r = a, s = o;
1010
- }), r, s];
1011
- }, typeof (t == null ? void 0 : t.autoFreeze) == "boolean" && this.setAutoFreeze(t.autoFreeze), typeof (t == null ? void 0 : t.useStrictShallowCopy) == "boolean" && this.setUseStrictShallowCopy(t.useStrictShallowCopy), typeof (t == null ? void 0 : t.useStrictIteration) == "boolean" && this.setUseStrictIteration(t.useStrictIteration);
1012
- }
1013
- createDraft(t) {
1014
- x(t) || m(8), S(t) && (t = wt(t));
1015
- const e = le(this), i = Q(t, void 0);
1016
- return i[w].isManual_ = !0, Z(e), i;
1017
- }
1018
- finishDraft(t, e) {
1019
- const i = t && t[w];
1020
- (!i || !i.isManual_) && m(9);
1021
- const { scope_: r } = i;
1022
- return oe(r, e), ce(void 0, r);
1023
- }
1024
- /**
1025
- * Pass true to automatically freeze all copies created by Immer.
1026
- *
1027
- * By default, auto-freezing is enabled.
1028
- */
1029
- setAutoFreeze(t) {
1030
- this.autoFreeze_ = t;
1031
- }
1032
- /**
1033
- * Pass true to enable strict shallow copy.
1034
- *
1035
- * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
1036
- */
1037
- setUseStrictShallowCopy(t) {
1038
- this.useStrictShallowCopy_ = t;
1039
- }
1040
- /**
1041
- * Pass false to use faster iteration that skips non-enumerable properties
1042
- * but still handles symbols for compatibility.
1043
- *
1044
- * By default, strict iteration is enabled (includes all own properties).
1045
- */
1046
- setUseStrictIteration(t) {
1047
- this.useStrictIteration_ = t;
1048
- }
1049
- shouldUseStrictIteration() {
1050
- return this.useStrictIteration_;
1051
- }
1052
- applyPatches(t, e) {
1053
- let i;
1054
- for (i = e.length - 1; i >= 0; i--) {
1055
- const s = e[i];
1056
- if (s.path.length === 0 && s.op === "replace") {
1057
- t = s.value;
1058
- break;
1059
- }
1060
- }
1061
- i > -1 && (e = e.slice(i + 1));
1062
- const r = M("Patches").applyPatches_;
1063
- return S(t) ? r(t, e) : this.produce(
1064
- t,
1065
- (s) => r(s, e)
1066
- );
1067
- }
1084
+ function q(e, t) {
1085
+ let n = e[w];
1086
+ return (n ? P(n) : e)[t];
1087
+ }
1088
+ function Ye(e, t, n) {
1089
+ let r = Xe(t, n);
1090
+ return r ? "value" in r ? r.value : r.get?.call(e.draft_) : void 0;
1091
+ }
1092
+ function Xe(e, t) {
1093
+ if (!(t in e)) return;
1094
+ let n = E(e);
1095
+ for (; n;) {
1096
+ let e = Object.getOwnPropertyDescriptor(n, t);
1097
+ if (e) return e;
1098
+ n = E(n);
1099
+ }
1100
+ }
1101
+ function J(e) {
1102
+ e.modified_ || (e.modified_ = !0, e.parent_ && J(e.parent_));
1103
+ }
1104
+ function Y(e) {
1105
+ e.copy_ ||= F(e.base_, e.scope_.immer_.useStrictShallowCopy_);
1106
+ }
1107
+ var Ze = class {
1108
+ constructor(e) {
1109
+ this.autoFreeze_ = !0, this.useStrictShallowCopy_ = !1, this.useStrictIteration_ = !0, this.produce = (e, t, n) => {
1110
+ if (typeof e == "function" && typeof t != "function") {
1111
+ let n = t;
1112
+ t = e;
1113
+ let r = this;
1114
+ return function(e = n, ...i) {
1115
+ return r.produce(e, (e) => t.call(this, e, ...i));
1116
+ };
1117
+ }
1118
+ typeof t != "function" && T(6), n !== void 0 && typeof n != "function" && T(7);
1119
+ let r;
1120
+ if (O(e)) {
1121
+ let i = We(this), a = X(e, void 0), o = !0;
1122
+ try {
1123
+ r = t(a), o = !1;
1124
+ } finally {
1125
+ o ? V(i) : H(i);
1126
+ }
1127
+ return Ue(i, n), Ke(r, i);
1128
+ } 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) {
1130
+ let t = [], i = [];
1131
+ z("Patches").generateReplacementPatches_(e, r, t, i), n(t, i);
1132
+ }
1133
+ return r;
1134
+ } else T(1, e);
1135
+ }, this.produceWithPatches = (e, t) => {
1136
+ if (typeof e == "function") return (t, ...n) => this.produceWithPatches(t, (t) => e(t, ...n));
1137
+ let n, r;
1138
+ return [
1139
+ this.produce(e, t, (e, t) => {
1140
+ n = e, r = t;
1141
+ }),
1142
+ n,
1143
+ r
1144
+ ];
1145
+ }, 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
+ }
1147
+ createDraft(e) {
1148
+ O(e) || T(8), D(e) && (e = Qe(e));
1149
+ let t = We(this), n = X(e, void 0);
1150
+ return n[w].isManual_ = !0, H(t), n;
1151
+ }
1152
+ finishDraft(e, t) {
1153
+ let n = e && e[w];
1154
+ (!n || !n.isManual_) && T(9);
1155
+ let { scope_: r } = n;
1156
+ return Ue(r, t), Ke(void 0, r);
1157
+ }
1158
+ setAutoFreeze(e) {
1159
+ this.autoFreeze_ = e;
1160
+ }
1161
+ setUseStrictShallowCopy(e) {
1162
+ this.useStrictShallowCopy_ = e;
1163
+ }
1164
+ setUseStrictIteration(e) {
1165
+ this.useStrictIteration_ = e;
1166
+ }
1167
+ shouldUseStrictIteration() {
1168
+ return this.useStrictIteration_;
1169
+ }
1170
+ applyPatches(e, t) {
1171
+ let n;
1172
+ for (n = t.length - 1; n >= 0; n--) {
1173
+ let r = t[n];
1174
+ if (r.path.length === 0 && r.op === "replace") {
1175
+ e = r.value;
1176
+ break;
1177
+ }
1178
+ }
1179
+ n > -1 && (t = t.slice(n + 1));
1180
+ let r = z("Patches").applyPatches_;
1181
+ return D(e) ? r(e, t) : this.produce(e, (e) => r(e, t));
1182
+ }
1068
1183
  };
1069
- function Q(t, e) {
1070
- const i = F(t) ? M("MapSet").proxyMap_(t, e) : H(t) ? M("MapSet").proxySet_(t, e) : _t(t, e);
1071
- return (e ? e.scope_ : Ee()).drafts_.push(i), i;
1072
- }
1073
- function wt(t) {
1074
- return S(t) || m(10, t), De(t);
1075
- }
1076
- function De(t) {
1077
- if (!x(t) || $(t))
1078
- return t;
1079
- const e = t[w];
1080
- let i, r = !0;
1081
- if (e) {
1082
- if (!e.modified_)
1083
- return e.base_;
1084
- e.finalized_ = !0, i = B(t, e.scope_.immer_.useStrictShallowCopy_), r = e.scope_.immer_.shouldUseStrictIteration();
1085
- } else
1086
- i = B(t, !0);
1087
- return A(
1088
- i,
1089
- (s, n) => {
1090
- Se(i, s, De(n));
1091
- },
1092
- r
1093
- ), e && (e.finalized_ = !1), i;
1094
- }
1095
- var pt = new mt(), gt = pt.produce;
1096
- function vt(t, e) {
1097
- const i = t + e;
1098
- let r = 0;
1099
- for (let s = 0; s < i.length; s++) {
1100
- const n = i.charCodeAt(s);
1101
- r = (r << 5) - r + n, r |= 0;
1102
- }
1103
- return r;
1104
- }
1105
- function bt(t, e) {
1106
- return (vt(t, e) >>> 0) / 4294967295;
1107
- }
1108
- function kt(t, e = /* @__PURE__ */ new Set()) {
1109
- if (t.reviewCards.length === 0 && t.newCards.length === 0)
1110
- return;
1111
- if (t.reviewCards.length === 0)
1112
- return t.newCards[0];
1113
- if (t.newCards.length === 0)
1114
- return t.reviewCards[0];
1115
- const i = de(t.newCards, e), r = de(t.reviewCards, e);
1116
- if (!i) return r ?? t.newCards[0];
1117
- if (!r) return i ?? t.reviewCards[0];
1118
- const s = t.newCards.length, n = t.reviewCards.length, a = s + n, o = 0.33, c = s / a, u = (o + c) / 2;
1119
- return bt(i.card.id, r.card.id) < u ? i : r;
1120
- }
1121
- function de(t, e) {
1122
- return t.find((i) => !e.has(i.card.id));
1123
- }
1124
- function jt(t, e, i) {
1125
- const r = St(e, i);
1126
- if (!r)
1127
- return e;
1128
- const { nextCard: s } = rt(r.cardReview, t, 30), n = s.due && Ie(s.due, /* @__PURE__ */ new Date());
1129
- return gt(e, (a) => {
1130
- if (xt(a, r), n) {
1131
- const o = {
1132
- ...r,
1133
- cardReview: s
1134
- };
1135
- Mt(a, o);
1136
- }
1137
- });
1138
- }
1139
- function xt(t, e) {
1140
- e.cardReview.state === "New" ? t.newCards = t.newCards.filter((i) => i.card.id !== e.card.id) : t.reviewCards = t.reviewCards.filter((i) => i.card.id !== e.card.id), Ce(t, e.cardReview.state, "decrease");
1141
- }
1142
- function Mt(t, e) {
1143
- if (e.cardReview.state === "New") {
1144
- const i = t.newCards.findIndex(
1145
- (r) => r.cardReview.due && e.cardReview.due && r.cardReview.due >= e.cardReview.due || r.cardReview.difficulty >= e.cardReview.difficulty
1146
- );
1147
- i === -1 ? t.newCards.push(e) : t.newCards.splice(i, 0, e);
1148
- } else {
1149
- const i = Et(t, t.reviewCards);
1150
- t.reviewCards.splice(i, 0, e);
1151
- }
1152
- Ce(t, e.cardReview.state, "increase");
1153
- }
1154
- function Ce(t, e, i) {
1155
- const r = i === "increase" ? 1 : -1;
1156
- switch (e) {
1157
- case "New":
1158
- t.stats.new += r;
1159
- break;
1160
- case "Learning":
1161
- case "Relearning":
1162
- t.stats.learning += r;
1163
- break;
1164
- case "Review":
1165
- t.stats.review += r;
1166
- break;
1167
- default:
1168
- t.stats.new += r;
1169
- break;
1170
- }
1171
- t.stats.total += r;
1172
- }
1173
- function St(t, e) {
1174
- return t.newCards.find((i) => i.card.id === e) ?? t.reviewCards.find((i) => i.card.id === e);
1175
- }
1176
- function Et(t, e) {
1177
- if (e.length === 0)
1178
- return 0;
1179
- const i = Math.max(4, Math.floor(e.length / 3));
1180
- return Math.min(i, e.length);
1181
- }
1182
- export {
1183
- Pe as FSRS_RETENTION,
1184
- Ft as MAX_CARDS_TO_FETCH,
1185
- Nt as MAX_LEARN_PER_DAY,
1186
- It as MAX_NEW_PER_DECK_DAY,
1187
- Pt as THRESHOLD_CARDS_FOR_REFETCH,
1188
- kt as getNextCardFromSession,
1189
- At as getReviewDateForEachRating,
1190
- St as getSessionCard,
1191
- rt as gradeCard,
1192
- nt as mergeFsrsCard,
1193
- Tt as newCardReview,
1194
- jt as removeCardFromSessionData
1184
+ 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;
1187
+ }
1188
+ function Qe(e) {
1189
+ return D(e) || T(10, e), Z(e);
1190
+ }
1191
+ function Z(e) {
1192
+ if (!O(e) || R(e)) return e;
1193
+ let t = e[w], n, r = !0;
1194
+ if (t) {
1195
+ if (!t.modified_) return t.base_;
1196
+ t.finalized_ = !0, n = F(e, t.scope_.immer_.useStrictShallowCopy_), r = t.scope_.immer_.shouldUseStrictIteration();
1197
+ } else n = F(e, !0);
1198
+ return k(n, (e, t) => {
1199
+ Le(n, e, Z(t));
1200
+ }, r), t && (t.finalized_ = !1), n;
1201
+ }
1202
+ var $e = new Ze().produce;
1203
+ //#endregion
1204
+ //#region src/spaced-repetition/utils.ts
1205
+ function et(e, t) {
1206
+ let n = e + t, r = 0;
1207
+ for (let e = 0; e < n.length; e++) {
1208
+ let t = n.charCodeAt(e);
1209
+ r = (r << 5) - r + t, r |= 0;
1210
+ }
1211
+ return r;
1212
+ }
1213
+ function tt(e, t) {
1214
+ return (et(e, t) >>> 0) / 4294967295;
1215
+ }
1216
+ function nt(e, t = /* @__PURE__ */ new Set()) {
1217
+ if (e.reviewCards.length === 0 && e.newCards.length === 0) return;
1218
+ if (e.reviewCards.length === 0) return Q(e.newCards, t) ?? e.newCards[0];
1219
+ if (e.newCards.length === 0) return Q(e.reviewCards, t) ?? e.reviewCards[0];
1220
+ let n = Q(e.newCards, t), r = Q(e.reviewCards, t);
1221
+ if (!n) return r ?? e.newCards[0];
1222
+ if (!r) return n ?? e.reviewCards[0];
1223
+ 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;
1225
+ }
1226
+ function Q(e, t) {
1227
+ return e.find((e) => !t.has(e.card.id));
1228
+ }
1229
+ function rt(e, t) {
1230
+ let n = $(e, t);
1231
+ return n ? $e(e, (e) => {
1232
+ at(e, n);
1233
+ }) : e;
1234
+ }
1235
+ function it(t, n, r) {
1236
+ let i = $(n, r);
1237
+ 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, {
1241
+ ...i,
1242
+ cardReview: a
1243
+ });
1244
+ });
1245
+ }
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");
1248
+ }
1249
+ function ot(e, t) {
1250
+ if (t.cardReview.state === "New") {
1251
+ 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
+ n === -1 ? e.newCards.push(t) : e.newCards.splice(n, 0, t);
1253
+ } else {
1254
+ let n = ct(e, e.reviewCards);
1255
+ e.reviewCards.splice(n, 0, t);
1256
+ }
1257
+ st(e, t.cardReview.state, "increase");
1258
+ }
1259
+ function st(e, t, n) {
1260
+ let r = n === "increase" ? 1 : -1;
1261
+ switch (t) {
1262
+ case "New":
1263
+ e.stats.new += r;
1264
+ break;
1265
+ case "Learning":
1266
+ case "Relearning":
1267
+ e.stats.learning += r;
1268
+ break;
1269
+ case "Review":
1270
+ e.stats.review += r;
1271
+ break;
1272
+ default:
1273
+ e.stats.new += r;
1274
+ break;
1275
+ }
1276
+ e.stats.total += r;
1277
+ }
1278
+ function $(e, t) {
1279
+ return e.newCards.find((e) => e.card.id === t) ?? e.reviewCards.find((e) => e.card.id === t);
1280
+ }
1281
+ function ct(e, t) {
1282
+ if (t.length === 0) return 0;
1283
+ let n = Math.max(4, Math.floor(t.length / 3));
1284
+ return Math.min(n, t.length);
1285
+ }
1286
+ //#endregion
1287
+ //#region src/spaced-repetition/session-manager.ts
1288
+ var lt = 5, ut = {
1289
+ newCards: [],
1290
+ reviewCards: [],
1291
+ stats: {
1292
+ new: 0,
1293
+ learning: 0,
1294
+ review: 0,
1295
+ total: 0
1296
+ }
1297
+ }, dt = class {
1298
+ recentlyReviewed = /* @__PURE__ */ new Set();
1299
+ _reviewsCompleted = 0;
1300
+ _correctGrades = 0;
1301
+ getProgress() {
1302
+ return {
1303
+ reviewsCompleted: this._reviewsCompleted,
1304
+ correctGrades: this._correctGrades
1305
+ };
1306
+ }
1307
+ nextCard(e) {
1308
+ return nt(e, this.recentlyReviewed);
1309
+ }
1310
+ 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();
1312
+ }
1195
1313
  };
1314
+ //#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 };