@vestcards/shared 0.5.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fsrs-C8QUsZ5l.js +10 -0
- package/dist/fsrs-HJutnIWm.cjs +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +88 -32
- package/dist/index.js +10 -5
- package/dist/spaced-repetition.cjs +1 -0
- package/dist/spaced-repetition.d.ts +133 -0
- package/dist/spaced-repetition.js +1195 -0
- package/package.json +9 -2
|
@@ -0,0 +1,1195 @@
|
|
|
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-C8QUsZ5l.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);
|
|
47
|
+
}, Date.prototype.format = function() {
|
|
48
|
+
return ke(this);
|
|
49
|
+
}, Date.prototype.dueFormat = function(t, e, i) {
|
|
50
|
+
return je(this, t, e, i);
|
|
51
|
+
};
|
|
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 };
|
|
102
|
+
};
|
|
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
|
+
});
|
|
546
|
+
};
|
|
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
|
|
733
|
+
};
|
|
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);
|
|
937
|
+
};
|
|
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]);
|
|
940
|
+
};
|
|
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
|
+
}
|
|
1068
|
+
};
|
|
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
|
|
1195
|
+
};
|