@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.
- package/dist/chunk-BK-Lzi7j.cjs +1 -0
- package/dist/date-DS8JYZte.js +103 -0
- package/dist/date-DoLsSDIb.cjs +1 -0
- package/dist/date.cjs +1 -1
- package/dist/date.d.ts +1 -1
- package/dist/date.js +2 -71
- package/dist/fsrs-D2XsH28s.js +23 -0
- package/dist/fsrs-DO2rNRTM.cjs +1 -0
- package/dist/hooks.cjs +1 -1
- package/dist/hooks.js +14 -14
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +220 -245
- package/dist/spaced-repetition.cjs +1 -1
- package/dist/spaced-repetition.d.ts +33 -0
- package/dist/spaced-repetition.js +1306 -1186
- package/dist/theme-Bt1AkSvq.cjs +1 -0
- package/dist/theme-DfRHdgzh.js +111 -0
- package/dist/theme.cjs +1 -1
- package/dist/theme.js +2 -19
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +37 -32
- package/package.json +6 -6
- package/dist/colors-G1GHbBJq.js +0 -120
- package/dist/colors-c6Q-ORB_.cjs +0 -1
- package/dist/fsrs-DEA3eLGO.cjs +0 -1
- package/dist/fsrs-sJJWxUiC.js +0 -14
|
@@ -1,1195 +1,1315 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
}, Date.prototype.dueFormat = function(
|
|
50
|
-
|
|
53
|
+
return ee(this);
|
|
54
|
+
}, Date.prototype.dueFormat = function(e, t, n) {
|
|
55
|
+
return te(this, e, t, n);
|
|
51
56
|
};
|
|
52
|
-
function
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
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
|
|
735
|
-
|
|
736
|
-
}
|
|
737
|
-
var
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
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
|
-
|
|
939
|
-
|
|
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
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
}
|
|
945
|
-
function
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
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
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
}
|
|
1073
|
-
function
|
|
1074
|
-
|
|
1075
|
-
}
|
|
1076
|
-
function
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
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 };
|