ts-fsrs 4.5.2 → 4.6.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/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var o=(r=>(r[r.New=0]="New",r[r.Learning=1]="Learning",r[r.Review=2]="Review",r[r.Relearning=3]="Relearning",r))(o||{}),l=(r=>(r[r.Manual=0]="Manual",r[r.Again=1]="Again",r[r.Hard=2]="Hard",r[r.Good=3]="Good",r[r.Easy=4]="Easy",r))(l||{});class h{static card(t){return{...t,state:h.state(t.state),due:h.time(t.due),last_review:t.last_review?h.time(t.last_review):void 0}}static rating(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),i=t.slice(1).toLowerCase(),a=l[`${e}${i}`];if(a===void 0)throw new Error(`Invalid rating:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid rating:[${t}]`)}static state(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),i=t.slice(1).toLowerCase(),a=o[`${e}${i}`];if(a===void 0)throw new Error(`Invalid state:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid state:[${t}]`)}static time(t){if(typeof t=="object"&&t instanceof Date)return t;if(typeof t=="string"){const e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid date:[${t}]`);return new Date(e)}else if(typeof t=="number")return new Date(t);throw new Error(`Invalid date:[${t}]`)}static review_log(t){return{...t,due:h.time(t.due),rating:h.rating(t.rating),state:h.state(t.state),review:h.time(t.review)}}}const A=.9,$=36500,L=[.40255,1.18385,3.173,15.69105,7.1949,.5345,1.4604,.0046,1.54575,.1192,1.01925,1.9395,.11,.29605,2.2698,.2315,2.9898,.51655,.6621],G=!1,C=!0,j="v4.5.2 using FSRS-5.0",M=r=>{let t=L;return r?.w&&(r.w.length===19?t=r?.w:r.w.length===17&&(t=r?.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"))),{request_retention:r?.request_retention||A,maximum_interval:r?.maximum_interval||$,w:t,enable_fuzz:r?.enable_fuzz??G,enable_short_term:r?.enable_short_term??C}};function w(r,t){const e={due:r?h.time(r):new Date,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:0,lapses:0,state:o.New,last_review:void 0};return t&&typeof t=="function"?t(e):e}Date.prototype.scheduler=function(r,t){return k(this,r,t)},Date.prototype.diff=function(r,t){return z(this,r,t)},Date.prototype.format=function(){return I(this)},Date.prototype.dueFormat=function(r,t,e){return N(this,r,t,e)};function k(r,t,e){return new Date(e?_(r).getTime()+t*24*60*60*1e3:_(r).getTime()+t*60*1e3)}function z(r,t,e){if(!r||!t)throw new Error("Invalid date");const i=_(r).getTime()-_(t).getTime();let a=0;switch(e){case"days":a=Math.floor(i/(24*60*60*1e3));break;case"minutes":a=Math.floor(i/(60*1e3));break}return a}function I(r){const t=_(r),e=t.getFullYear(),i=t.getMonth()+1,a=t.getDate(),s=t.getHours(),n=t.getMinutes(),d=t.getSeconds();return`${e}-${m(i)}-${m(a)} ${m(s)}:${m(n)}:${m(d)}`}function m(r){return r<10?`0${r}`:`${r}`}const S=[60,60,24,31,12],R=["second","min","hour","day","month","year"];function N(r,t,e,i=R){r=_(r),t=_(t),i.length!==R.length&&(i=R);let a=r.getTime()-t.getTime(),s;for(a/=1e3,s=0;s<S.length&&!(a<S[s]);s++)a/=S[s];return`${Math.floor(a)}${e?i[s]:""}`}function _(r){return h.time(r)}function W(r){return h.state(r)}function B(r){return h.rating(r)}const T=[l.Again,l.Hard,l.Good,l.Easy],J=[{start:2.5,end:7,factor:.15},{start:7,end:20,factor:.1},{start:20,end:1/0,factor:.05}];function U(r,t,e){let i=1;for(const n of J)i+=n.factor*Math.max(Math.min(r,n.end)-n.start,0);r=Math.min(r,e);let a=Math.max(2,Math.round(r-i));const s=Math.min(Math.round(r+i),e);return r>t&&(a=Math.max(a,t+1)),a=Math.min(a,s),{min_ivl:a,max_ivl:s}}function p(r,t,e){return Math.min(Math.max(r,t),e)}function q(r,t){const e=Date.UTC(r.getUTCFullYear(),r.getUTCMonth(),r.getUTCDate()),i=Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate());return Math.floor((i-e)/864e5)}class K{c;s0;s1;s2;constructor(t){const e=Q();this.c=1,this.s0=e(" "),this.s1=e(" "),this.s2=e(" "),t==null&&(t=+new Date),this.s0-=e(t),this.s0<0&&(this.s0+=1),this.s1-=e(t),this.s1<0&&(this.s1+=1),this.s2-=e(t),this.s2<0&&(this.s2+=1)}next(){const t=2091639*this.s0+this.c*23283064365386963e-26;return this.s0=this.s1,this.s1=this.s2,this.s2=t-(this.c=t|0),this.s2}set state(t){this.c=t.c,this.s0=t.s0,this.s1=t.s1,this.s2=t.s2}get state(){return{c:this.c,s0:this.s0,s1:this.s1,s2:this.s2}}}function Q(){let r=4022871197;return function(t){t=String(t);for(let e=0;e<t.length;e++){r+=t.charCodeAt(e);let i=.02519603282416938*r;r=i>>>0,i-=r,i*=r,r=i>>>0,i-=r,r+=i*4294967296}return(r>>>0)*23283064365386963e-26}}function X(r){const t=new K(r),e=()=>t.next();return e.int32=()=>t.next()*4294967296|0,e.double=()=>e()+(e()*2097152|0)*11102230246251565e-32,e.state=()=>t.state,e.importState=i=>(t.state=i,e),e}const E=-.5,D=19/81;class Y{param;intervalModifier;_seed;constructor(t){this.param=new Proxy(M(t),this.params_handler_proxy()),this.intervalModifier=this.calculate_interval_modifier(this.param.request_retention)}get interval_modifier(){return this.intervalModifier}set seed(t){this._seed=t}calculate_interval_modifier(t){if(t<=0||t>1)throw new Error("Requested retention rate should be in the range (0,1]");return+((Math.pow(t,1/E)-1)/D).toFixed(8)}get parameters(){return this.param}set parameters(t){this.update_parameters(t)}params_handler_proxy(){const t=this;return{set:function(e,i,a){return i==="request_retention"&&Number.isFinite(a)&&(t.intervalModifier=t.calculate_interval_modifier(Number(a))),Reflect.set(e,i,a),!0}}}update_parameters(t){const e=M(t);for(const i in e)if(i in this.param){const a=i;this.param[a]=e[a]}}init_stability(t){return Math.max(this.param.w[t-1],.1)}init_difficulty(t){return this.constrain_difficulty(this.param.w[4]-Math.exp((t-1)*this.param.w[5])+1)}apply_fuzz(t,e){if(!this.param.enable_fuzz||t<2.5)return Math.round(t);const i=X(this._seed)(),{min_ivl:a,max_ivl:s}=U(t,e,this.param.maximum_interval);return Math.floor(i*(s-a+1)+a)}next_interval(t,e){const i=Math.min(Math.max(1,Math.round(t*this.intervalModifier)),this.param.maximum_interval);return this.apply_fuzz(i,e)}linear_damping(t,e){return+(t*(10-e)/9).toFixed(8)}next_difficulty(t,e){const i=-this.param.w[6]*(e-3),a=t+this.linear_damping(i,t);return this.constrain_difficulty(this.mean_reversion(this.init_difficulty(l.Easy),a))}constrain_difficulty(t){return Math.min(Math.max(+t.toFixed(8),1),10)}mean_reversion(t,e){return+(this.param.w[7]*t+(1-this.param.w[7])*e).toFixed(8)}next_recall_stability(t,e,i,a){const s=l.Hard===a?this.param.w[15]:1,n=l.Easy===a?this.param.w[16]:1;return+p(e*(1+Math.exp(this.param.w[8])*(11-t)*Math.pow(e,-this.param.w[9])*(Math.exp((1-i)*this.param.w[10])-1)*s*n),.01,36500).toFixed(8)}next_forget_stability(t,e,i){return+p(this.param.w[11]*Math.pow(t,-this.param.w[12])*(Math.pow(e+1,this.param.w[13])-1)*Math.exp((1-i)*this.param.w[14]),.01,36500).toFixed(8)}next_short_term_stability(t,e){return+p(t*Math.exp(this.param.w[17]*(e-3+this.param.w[18])),.01,36500).toFixed(8)}forgetting_curve(t,e){return+Math.pow(1+D*t/e,E).toFixed(8)}}function F(){const r=this.review_time.getTime(),t=this.current.reps,e=this.current.difficulty*this.current.stability;return`${r}_${t}_${e}`}function Z(r){return function(){const t=Reflect.get(this.current,r)??0,e=this.current.reps;return String(t+e||0)}}var v=(r=>(r.SCHEDULER="Scheduler",r.SEED="Seed",r))(v||{});class H{last;current;review_time;next=new Map;algorithm;initSeedStrategy;constructor(t,e,i,a={seed:F}){this.algorithm=i,this.initSeedStrategy=a.seed.bind(this),this.last=h.card(t),this.current=h.card(t),this.review_time=h.time(e),this.init()}init(){const{state:t,last_review:e}=this.current;let i=0;t!==o.New&&e&&(i=q(e,this.review_time)),this.current.last_review=this.review_time,this.current.elapsed_days=i,this.current.reps+=1,this.algorithm.seed=this.initSeedStrategy()}preview(){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)}}*previewIterator(){for(const t of T)yield this.review(t)}review(t){const{state:e}=this.last;let i;switch(e){case o.New:i=this.newState(t);break;case o.Learning:case o.Relearning:i=this.learningState(t);break;case o.Review:i=this.reviewState(t);break}if(i)return i;throw new Error("Invalid grade")}buildLog(t){const{last_review:e,due:i,elapsed_days:a}=this.last;return{rating:t,state:this.current.state,due:e||i,stability:this.current.stability,difficulty:this.current.difficulty,elapsed_days:this.current.elapsed_days,last_elapsed_days:a,scheduled_days:this.current.scheduled_days,review:this.review_time}}}class O extends H{newState(t){const e=this.next.get(t);if(e)return e;const i=h.card(this.current);switch(i.difficulty=this.algorithm.init_difficulty(t),i.stability=this.algorithm.init_stability(t),t){case l.Again:i.scheduled_days=0,i.due=this.review_time.scheduler(1),i.state=o.Learning;break;case l.Hard:i.scheduled_days=0,i.due=this.review_time.scheduler(5),i.state=o.Learning;break;case l.Good:i.scheduled_days=0,i.due=this.review_time.scheduler(10),i.state=o.Learning;break;case l.Easy:{const s=this.algorithm.next_interval(i.stability,this.current.elapsed_days);i.scheduled_days=s,i.due=this.review_time.scheduler(s,!0),i.state=o.Review;break}default:throw new Error("Invalid grade")}const a={card:i,log:this.buildLog(t)};return this.next.set(t,a),a}learningState(t){const e=this.next.get(t);if(e)return e;const{state:i,difficulty:a,stability:s}=this.last,n=h.card(this.current),d=this.current.elapsed_days;switch(n.difficulty=this.algorithm.next_difficulty(a,t),n.stability=this.algorithm.next_short_term_stability(s,t),t){case l.Again:{n.scheduled_days=0,n.due=this.review_time.scheduler(5,!1),n.state=i;break}case l.Hard:{n.scheduled_days=0,n.due=this.review_time.scheduler(10),n.state=i;break}case l.Good:{const c=this.algorithm.next_interval(n.stability,d);n.scheduled_days=c,n.due=this.review_time.scheduler(c,!0),n.state=o.Review;break}case l.Easy:{const c=this.algorithm.next_short_term_stability(s,l.Good),f=this.algorithm.next_interval(c,d),y=Math.max(this.algorithm.next_interval(n.stability,d),f+1);n.scheduled_days=y,n.due=this.review_time.scheduler(y,!0),n.state=o.Review;break}default:throw new Error("Invalid grade")}const u={card:n,log:this.buildLog(t)};return this.next.set(t,u),u}reviewState(t){const e=this.next.get(t);if(e)return e;const i=this.current.elapsed_days,{difficulty:a,stability:s}=this.last,n=this.algorithm.forgetting_curve(i,s),d=h.card(this.current),u=h.card(this.current),c=h.card(this.current),f=h.card(this.current);this.next_ds(d,u,c,f,a,s,n),this.next_interval(d,u,c,f,i),this.next_state(d,u,c,f),d.lapses+=1;const y={card:d,log:this.buildLog(l.Again)},x={card:u,log:super.buildLog(l.Hard)},g={card:c,log:super.buildLog(l.Good)},b={card:f,log:super.buildLog(l.Easy)};return this.next.set(l.Again,y),this.next.set(l.Hard,x),this.next.set(l.Good,g),this.next.set(l.Easy,b),this.next.get(t)}next_ds(t,e,i,a,s,n,d){t.difficulty=this.algorithm.next_difficulty(s,l.Again);const u=n/Math.exp(this.algorithm.parameters.w[17]*this.algorithm.parameters.w[18]);t.stability=Math.min(+u.toFixed(8),this.algorithm.next_forget_stability(s,n,d)),e.difficulty=this.algorithm.next_difficulty(s,l.Hard),e.stability=this.algorithm.next_recall_stability(s,n,d,l.Hard),i.difficulty=this.algorithm.next_difficulty(s,l.Good),i.stability=this.algorithm.next_recall_stability(s,n,d,l.Good),a.difficulty=this.algorithm.next_difficulty(s,l.Easy),a.stability=this.algorithm.next_recall_stability(s,n,d,l.Easy)}next_interval(t,e,i,a,s){let n,d;n=this.algorithm.next_interval(e.stability,s),d=this.algorithm.next_interval(i.stability,s),n=Math.min(n,d),d=Math.max(d,n+1);const u=Math.max(this.algorithm.next_interval(a.stability,s),d+1);t.scheduled_days=0,t.due=this.review_time.scheduler(5),e.scheduled_days=n,e.due=this.review_time.scheduler(n,!0),i.scheduled_days=d,i.due=this.review_time.scheduler(d,!0),a.scheduled_days=u,a.due=this.review_time.scheduler(u,!0)}next_state(t,e,i,a){t.state=o.Relearning,e.state=o.Review,i.state=o.Review,a.state=o.Review}}class P extends H{newState(t){const e=this.next.get(t);if(e)return e;this.current.scheduled_days=0,this.current.elapsed_days=0;const i=h.card(this.current),a=h.card(this.current),s=h.card(this.current),n=h.card(this.current);this.init_ds(i,a,s,n);const d=0;return this.next_interval(i,a,s,n,d),this.next_state(i,a,s,n),this.update_next(i,a,s,n),this.next.get(t)}init_ds(t,e,i,a){t.difficulty=this.algorithm.init_difficulty(l.Again),t.stability=this.algorithm.init_stability(l.Again),e.difficulty=this.algorithm.init_difficulty(l.Hard),e.stability=this.algorithm.init_stability(l.Hard),i.difficulty=this.algorithm.init_difficulty(l.Good),i.stability=this.algorithm.init_stability(l.Good),a.difficulty=this.algorithm.init_difficulty(l.Easy),a.stability=this.algorithm.init_stability(l.Easy)}learningState(t){return this.reviewState(t)}reviewState(t){const e=this.next.get(t);if(e)return e;const i=this.current.elapsed_days,{difficulty:a,stability:s}=this.last,n=this.algorithm.forgetting_curve(i,s),d=h.card(this.current),u=h.card(this.current),c=h.card(this.current),f=h.card(this.current);return this.next_ds(d,u,c,f,a,s,n),this.next_interval(d,u,c,f,i),this.next_state(d,u,c,f),d.lapses+=1,this.update_next(d,u,c,f),this.next.get(t)}next_ds(t,e,i,a,s,n,d){t.difficulty=this.algorithm.next_difficulty(s,l.Again),t.stability=Math.min(n,this.algorithm.next_forget_stability(s,n,d)),e.difficulty=this.algorithm.next_difficulty(s,l.Hard),e.stability=this.algorithm.next_recall_stability(s,n,d,l.Hard),i.difficulty=this.algorithm.next_difficulty(s,l.Good),i.stability=this.algorithm.next_recall_stability(s,n,d,l.Good),a.difficulty=this.algorithm.next_difficulty(s,l.Easy),a.stability=this.algorithm.next_recall_stability(s,n,d,l.Easy)}next_interval(t,e,i,a,s){let n,d,u,c;n=this.algorithm.next_interval(t.stability,s),d=this.algorithm.next_interval(e.stability,s),u=this.algorithm.next_interval(i.stability,s),c=this.algorithm.next_interval(a.stability,s),n=Math.min(n,d),d=Math.max(d,n+1),u=Math.max(u,d+1),c=Math.max(c,u+1),t.scheduled_days=n,t.due=this.review_time.scheduler(n,!0),e.scheduled_days=d,e.due=this.review_time.scheduler(d,!0),i.scheduled_days=u,i.due=this.review_time.scheduler(u,!0),a.scheduled_days=c,a.due=this.review_time.scheduler(c,!0)}next_state(t,e,i,a){t.state=o.Review,e.state=o.Review,i.state=o.Review,a.state=o.Review}update_next(t,e,i,a){const s={card:t,log:this.buildLog(l.Again)},n={card:e,log:super.buildLog(l.Hard)},d={card:i,log:super.buildLog(l.Good)},u={card:a,log:super.buildLog(l.Easy)};this.next.set(l.Again,s),this.next.set(l.Hard,n),this.next.set(l.Good,d),this.next.set(l.Easy,u)}}class tt{fsrs;constructor(t){this.fsrs=t}replay(t,e,i){return this.fsrs.next(t,e,i)}handleManualRating(t,e,i,a,s,n,d){if(typeof e>"u")throw new Error("reschedule: state is required for manual rating");let u,c;if(e===o.New)u={rating:l.Manual,state:e,due:d??i,stability:t.stability,difficulty:t.difficulty,elapsed_days:a,last_elapsed_days:t.elapsed_days,scheduled_days:t.scheduled_days,review:i},c=w(i),c.last_review=i;else{if(typeof d>"u")throw new Error("reschedule: due is required for manual rating");const f=d.diff(i,"days");u={rating:l.Manual,state:t.state,due:t.last_review||t.due,stability:t.stability,difficulty:t.difficulty,elapsed_days:a,last_elapsed_days:t.elapsed_days,scheduled_days:t.scheduled_days,review:i},c={...t,state:e,due:d,last_review:i,stability:s||t.stability,difficulty:n||t.difficulty,elapsed_days:a,scheduled_days:f,reps:t.reps+1}}return{card:c,log:u}}reschedule(t,e){const i=[];let a=w(t.due);for(const s of e){let n;if(s.review=h.time(s.review),s.rating===l.Manual){let d=0;a.state!==o.New&&a.last_review&&(d=s.review.diff(a.last_review,"days")),n=this.handleManualRating(a,s.state,s.review,d,s.stability,s.difficulty,s.due?h.time(s.due):void 0)}else n=this.replay(a,s.review,s.rating);i.push(n),a=n.card}return i}calculateManualRecord(t,e,i,a){if(!i)return null;const{card:s,log:n}=i,d=h.card(t);return d.due.getTime()===s.due.getTime()?null:(d.scheduled_days=s.due.diff(d.due,"days"),this.handleManualRating(d,s.state,h.time(e),n.elapsed_days,a?s.stability:void 0,a?s.difficulty:void 0,s.due))}}class V extends Y{strategyHandler=new Map;Scheduler;constructor(t){super(t);const{enable_short_term:e}=this.parameters;this.Scheduler=e?O:P}params_handler_proxy(){const t=this;return{set:function(e,i,a){return i==="request_retention"&&Number.isFinite(a)?t.intervalModifier=t.calculate_interval_modifier(Number(a)):i==="enable_short_term"&&(t.Scheduler=a===!0?O:P),Reflect.set(e,i,a),!0}}}useStrategy(t,e){return this.strategyHandler.set(t,e),this}clearStrategy(t){return t?this.strategyHandler.delete(t):this.strategyHandler.clear(),this}getScheduler(t,e){const i=this.strategyHandler.get(v.SEED),a=this.strategyHandler.get(v.SCHEDULER)||this.Scheduler,s=i||F;return new a(t,e,this,{seed:s})}repeat(t,e,i){const a=this.getScheduler(t,e).preview();return i&&typeof i=="function"?i(a):a}next(t,e,i,a){const s=this.getScheduler(t,e),n=h.rating(i);if(n===l.Manual)throw new Error("Cannot review a manual rating");const d=s.review(n);return a&&typeof a=="function"?a(d):d}get_retrievability(t,e,i=!0){const a=h.card(t);e=e?h.time(e):new Date;const s=a.state!==o.New?Math.max(e.diff(a.last_review,"days"),0):0,n=a.state!==o.New?this.forgetting_curve(s,+a.stability.toFixed(8)):0;return i?`${(n*100).toFixed(2)}%`:n}rollback(t,e,i){const a=h.card(t),s=h.review_log(e);if(s.rating===l.Manual)throw new Error("Cannot rollback a manual rating");let n,d,u;switch(s.state){case o.New:n=s.due,d=void 0,u=0;break;case o.Learning:case o.Relearning:case o.Review:n=s.review,d=s.due,u=a.lapses-(s.rating===l.Again&&s.state===o.Review?1:0);break}const c={...a,due:n,stability:s.stability,difficulty:s.difficulty,elapsed_days:s.last_elapsed_days,scheduled_days:s.scheduled_days,reps:Math.max(0,a.reps-1),lapses:Math.max(0,u),state:s.state,last_review:d};return i&&typeof i=="function"?i(c):c}forget(t,e,i=!1,a){const s=h.card(t);e=h.time(e);const n=s.state===o.New?0:e.diff(s.last_review,"days"),d={rating:l.Manual,state:s.state,due:s.due,stability:s.stability,difficulty:s.difficulty,elapsed_days:0,last_elapsed_days:s.elapsed_days,scheduled_days:n,review:e},u={card:{...s,due:e,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:i?0:s.reps,lapses:i?0:s.lapses,state:o.New,last_review:s.last_review},log:d};return a&&typeof a=="function"?a(u):u}reschedule(t,e=[],i={}){const{recordLogHandler:a,reviewsOrderBy:s,skipManual:n=!0,now:d=new Date,update_memory_state:u=!1}=i;s&&typeof s=="function"&&e.sort(s),n&&(e=e.filter(b=>b.rating!==l.Manual));const c=new tt(this),f=c.reschedule(i.first_card||w(),e),y=f.length,x=h.card(t),g=c.calculateManualRecord(x,d,y?f[y-1]:void 0,u);return a&&typeof a=="function"?{collections:f.map(a),reschedule_item:g?a(g):null}:{collections:f,reschedule_item:g}}}const et=r=>new V(r||{});exports.AbstractScheduler=H,exports.DECAY=E,exports.DefaultInitSeedStrategy=F,exports.FACTOR=D,exports.FSRS=V,exports.FSRSAlgorithm=Y,exports.FSRSVersion=j,exports.GenSeedStrategyWithCardId=Z,exports.Grades=T,exports.Rating=l,exports.State=o,exports.StrategyMode=v,exports.TypeConvert=h,exports.clamp=p,exports.createEmptyCard=w,exports.dateDiffInDays=q,exports.date_diff=z,exports.date_scheduler=k,exports.default_enable_fuzz=G,exports.default_enable_short_term=C,exports.default_maximum_interval=$,exports.default_request_retention=A,exports.default_w=L,exports.fixDate=_,exports.fixRating=B,exports.fixState=W,exports.formatDate=I,exports.fsrs=et,exports.generatorParameters=M,exports.get_fuzz_range=U,exports.show_diff_message=N,module.exports=Object.assign(exports.default||{},exports);
1
+ "use strict";var u=(r=>(r[r.New=0]="New",r[r.Learning=1]="Learning",r[r.Review=2]="Review",r[r.Relearning=3]="Relearning",r))(u||{}),d=(r=>(r[r.Manual=0]="Manual",r[r.Again=1]="Again",r[r.Hard=2]="Hard",r[r.Good=3]="Good",r[r.Easy=4]="Easy",r))(d||{});class h{static card(t){return{...t,state:h.state(t.state),due:h.time(t.due),last_review:t.last_review?h.time(t.last_review):void 0}}static rating(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),i=t.slice(1).toLowerCase(),a=d[`${e}${i}`];if(a===void 0)throw new Error(`Invalid rating:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid rating:[${t}]`)}static state(t){if(typeof t=="string"){const e=t.charAt(0).toUpperCase(),i=t.slice(1).toLowerCase(),a=u[`${e}${i}`];if(a===void 0)throw new Error(`Invalid state:[${t}]`);return a}else if(typeof t=="number")return t;throw new Error(`Invalid state:[${t}]`)}static time(t){if(typeof t=="object"&&t instanceof Date)return t;if(typeof t=="string"){const e=Date.parse(t);if(isNaN(e))throw new Error(`Invalid date:[${t}]`);return new Date(e)}else if(typeof t=="number")return new Date(t);throw new Error(`Invalid date:[${t}]`)}static review_log(t){return{...t,due:h.time(t.due),rating:h.rating(t.rating),state:h.state(t.state),review:h.time(t.review)}}}const H=.9,A=36500,L=[.40255,1.18385,3.173,15.69105,7.1949,.5345,1.4604,.0046,1.54575,.1192,1.01925,1.9395,.11,.29605,2.2698,.2315,2.9898,.51655,.6621],G=!1,I=!0,j="v4.6.0 using FSRS-5.0",M=r=>{let t=L;return r?.w&&(r.w.length===19?t=r?.w:r.w.length===17&&(t=r?.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"))),{request_retention:r?.request_retention||H,maximum_interval:r?.maximum_interval||A,w:t,enable_fuzz:r?.enable_fuzz??G,enable_short_term:r?.enable_short_term??I}};function v(r,t){const e={due:r?h.time(r):new Date,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:0,lapses:0,state:u.New,last_review:void 0};return t&&typeof t=="function"?t(e):e}Date.prototype.scheduler=function(r,t){return C(this,r,t)},Date.prototype.diff=function(r,t){return k(this,r,t)},Date.prototype.format=function(){return z(this)},Date.prototype.dueFormat=function(r,t,e){return N(this,r,t,e)};function C(r,t,e){return new Date(e?y(r).getTime()+t*24*60*60*1e3:y(r).getTime()+t*60*1e3)}function k(r,t,e){if(!r||!t)throw new Error("Invalid date");const i=y(r).getTime()-y(t).getTime();let a=0;switch(e){case"days":a=Math.floor(i/(24*60*60*1e3));break;case"minutes":a=Math.floor(i/(60*1e3));break}return a}function z(r){const t=y(r),e=t.getFullYear(),i=t.getMonth()+1,a=t.getDate(),s=t.getHours(),n=t.getMinutes(),l=t.getSeconds();return`${e}-${w(i)}-${w(a)} ${w(s)}:${w(n)}:${w(l)}`}function w(r){return r<10?`0${r}`:`${r}`}const S=[60,60,24,31,12],E=["second","min","hour","day","month","year"];function N(r,t,e,i=E){r=y(r),t=y(t),i.length!==E.length&&(i=E);let a=r.getTime()-t.getTime(),s;for(a/=1e3,s=0;s<S.length&&!(a<S[s]);s++)a/=S[s];return`${Math.floor(a)}${e?i[s]:""}`}function y(r){return h.time(r)}function W(r){return h.state(r)}function B(r){return h.rating(r)}const T=[d.Again,d.Hard,d.Good,d.Easy],J=[{start:2.5,end:7,factor:.15},{start:7,end:20,factor:.1},{start:20,end:1/0,factor:.05}];function U(r,t,e){let i=1;for(const n of J)i+=n.factor*Math.max(Math.min(r,n.end)-n.start,0);r=Math.min(r,e);let a=Math.max(2,Math.round(r-i));const s=Math.min(Math.round(r+i),e);return r>t&&(a=Math.max(a,t+1)),a=Math.min(a,s),{min_ivl:a,max_ivl:s}}function p(r,t,e){return Math.min(Math.max(r,t),e)}function q(r,t){const e=Date.UTC(r.getUTCFullYear(),r.getUTCMonth(),r.getUTCDate()),i=Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate());return Math.floor((i-e)/864e5)}class K{c;s0;s1;s2;constructor(t){const e=Q();this.c=1,this.s0=e(" "),this.s1=e(" "),this.s2=e(" "),t==null&&(t=+new Date),this.s0-=e(t),this.s0<0&&(this.s0+=1),this.s1-=e(t),this.s1<0&&(this.s1+=1),this.s2-=e(t),this.s2<0&&(this.s2+=1)}next(){const t=2091639*this.s0+this.c*23283064365386963e-26;return this.s0=this.s1,this.s1=this.s2,this.s2=t-(this.c=t|0),this.s2}set state(t){this.c=t.c,this.s0=t.s0,this.s1=t.s1,this.s2=t.s2}get state(){return{c:this.c,s0:this.s0,s1:this.s1,s2:this.s2}}}function Q(){let r=4022871197;return function(t){t=String(t);for(let e=0;e<t.length;e++){r+=t.charCodeAt(e);let i=.02519603282416938*r;r=i>>>0,i-=r,i*=r,r=i>>>0,i-=r,r+=i*4294967296}return(r>>>0)*23283064365386963e-26}}function X(r){const t=new K(r),e=()=>t.next();return e.int32=()=>t.next()*4294967296|0,e.double=()=>e()+(e()*2097152|0)*11102230246251565e-32,e.state=()=>t.state,e.importState=i=>(t.state=i,e),e}const R=-.5,D=19/81;class Y{param;intervalModifier;_seed;constructor(t){this.param=new Proxy(M(t),this.params_handler_proxy()),this.intervalModifier=this.calculate_interval_modifier(this.param.request_retention)}get interval_modifier(){return this.intervalModifier}set seed(t){this._seed=t}calculate_interval_modifier(t){if(t<=0||t>1)throw new Error("Requested retention rate should be in the range (0,1]");return+((Math.pow(t,1/R)-1)/D).toFixed(8)}get parameters(){return this.param}set parameters(t){this.update_parameters(t)}params_handler_proxy(){const t=this;return{set:function(e,i,a){return i==="request_retention"&&Number.isFinite(a)&&(t.intervalModifier=t.calculate_interval_modifier(Number(a))),Reflect.set(e,i,a),!0}}}update_parameters(t){const e=M(t);for(const i in e)if(i in this.param){const a=i;this.param[a]=e[a]}}init_stability(t){return Math.max(this.param.w[t-1],.1)}init_difficulty(t){return this.constrain_difficulty(this.param.w[4]-Math.exp((t-1)*this.param.w[5])+1)}apply_fuzz(t,e){if(!this.param.enable_fuzz||t<2.5)return Math.round(t);const i=X(this._seed)(),{min_ivl:a,max_ivl:s}=U(t,e,this.param.maximum_interval);return Math.floor(i*(s-a+1)+a)}next_interval(t,e){const i=Math.min(Math.max(1,Math.round(t*this.intervalModifier)),this.param.maximum_interval);return this.apply_fuzz(i,e)}linear_damping(t,e){return+(t*(10-e)/9).toFixed(8)}next_difficulty(t,e){const i=-this.param.w[6]*(e-3),a=t+this.linear_damping(i,t);return this.constrain_difficulty(this.mean_reversion(this.init_difficulty(d.Easy),a))}constrain_difficulty(t){return Math.min(Math.max(+t.toFixed(8),1),10)}mean_reversion(t,e){return+(this.param.w[7]*t+(1-this.param.w[7])*e).toFixed(8)}next_recall_stability(t,e,i,a){const s=d.Hard===a?this.param.w[15]:1,n=d.Easy===a?this.param.w[16]:1;return+p(e*(1+Math.exp(this.param.w[8])*(11-t)*Math.pow(e,-this.param.w[9])*(Math.exp((1-i)*this.param.w[10])-1)*s*n),.01,36500).toFixed(8)}next_forget_stability(t,e,i){return+p(this.param.w[11]*Math.pow(t,-this.param.w[12])*(Math.pow(e+1,this.param.w[13])-1)*Math.exp((1-i)*this.param.w[14]),.01,36500).toFixed(8)}next_short_term_stability(t,e){return+p(t*Math.exp(this.param.w[17]*(e-3+this.param.w[18])),.01,36500).toFixed(8)}forgetting_curve(t,e){return+Math.pow(1+D*t/e,R).toFixed(8)}next_state(t,e,i){const{difficulty:a,stability:s}=t??{difficulty:0,stability:0};if(e<0)throw new Error(`Invalid delta_t "${e}"`);if(i<0||i>4)throw new Error(`Invalid grade "${i}"`);if(a===0&&s===0)return{difficulty:this.init_difficulty(i),stability:this.init_stability(i)};if(i===0)return{difficulty:a,stability:s};if(a<1||s<.01)throw new Error(`Invalid memory state { difficulty: ${a}, stability: ${s} }`);const n=this.forgetting_curve(e,s),l=this.next_recall_stability(a,s,n,i),o=this.next_forget_stability(a,s,n),c=this.next_short_term_stability(s,i);let f=l;if(i===1){let[_,m]=[0,0];this.param.enable_short_term&&(_=this.param.w[17],m=this.param.w[18]);const g=s/Math.exp(_*m);f=p(g,.01,o)}return e===0&&this.param.enable_short_term&&(f=c),{difficulty:this.next_difficulty(a,i),stability:f}}}function F(){const r=this.review_time.getTime(),t=this.current.reps,e=this.current.difficulty*this.current.stability;return`${r}_${t}_${e}`}function Z(r){return function(){const t=Reflect.get(this.current,r)??0,e=this.current.reps;return String(t+e||0)}}var x=(r=>(r.SCHEDULER="Scheduler",r.SEED="Seed",r))(x||{});class ${last;current;review_time;next=new Map;algorithm;initSeedStrategy;constructor(t,e,i,a={seed:F}){this.algorithm=i,this.initSeedStrategy=a.seed.bind(this),this.last=h.card(t),this.current=h.card(t),this.review_time=h.time(e),this.init()}init(){const{state:t,last_review:e}=this.current;let i=0;t!==u.New&&e&&(i=q(e,this.review_time)),this.current.last_review=this.review_time,this.current.elapsed_days=i,this.current.reps+=1,this.algorithm.seed=this.initSeedStrategy()}preview(){return{[d.Again]:this.review(d.Again),[d.Hard]:this.review(d.Hard),[d.Good]:this.review(d.Good),[d.Easy]:this.review(d.Easy),[Symbol.iterator]:this.previewIterator.bind(this)}}*previewIterator(){for(const t of T)yield this.review(t)}review(t){const{state:e}=this.last;let i;switch(e){case u.New:i=this.newState(t);break;case u.Learning:case u.Relearning:i=this.learningState(t);break;case u.Review:i=this.reviewState(t);break}if(i)return i;throw new Error("Invalid grade")}buildLog(t){const{last_review:e,due:i,elapsed_days:a}=this.last;return{rating:t,state:this.current.state,due:e||i,stability:this.current.stability,difficulty:this.current.difficulty,elapsed_days:this.current.elapsed_days,last_elapsed_days:a,scheduled_days:this.current.scheduled_days,review:this.review_time}}}class O extends ${newState(t){const e=this.next.get(t);if(e)return e;const i=h.card(this.current);switch(i.difficulty=this.algorithm.init_difficulty(t),i.stability=this.algorithm.init_stability(t),t){case d.Again:i.scheduled_days=0,i.due=this.review_time.scheduler(1),i.state=u.Learning;break;case d.Hard:i.scheduled_days=0,i.due=this.review_time.scheduler(5),i.state=u.Learning;break;case d.Good:i.scheduled_days=0,i.due=this.review_time.scheduler(10),i.state=u.Learning;break;case d.Easy:{const s=this.algorithm.next_interval(i.stability,this.current.elapsed_days);i.scheduled_days=s,i.due=this.review_time.scheduler(s,!0),i.state=u.Review;break}default:throw new Error("Invalid grade")}const a={card:i,log:this.buildLog(t)};return this.next.set(t,a),a}learningState(t){const e=this.next.get(t);if(e)return e;const{state:i,difficulty:a,stability:s}=this.last,n=h.card(this.current),l=this.current.elapsed_days;switch(n.difficulty=this.algorithm.next_difficulty(a,t),n.stability=this.algorithm.next_short_term_stability(s,t),t){case d.Again:{n.scheduled_days=0,n.due=this.review_time.scheduler(5,!1),n.state=i;break}case d.Hard:{n.scheduled_days=0,n.due=this.review_time.scheduler(10),n.state=i;break}case d.Good:{const c=this.algorithm.next_interval(n.stability,l);n.scheduled_days=c,n.due=this.review_time.scheduler(c,!0),n.state=u.Review;break}case d.Easy:{const c=this.algorithm.next_short_term_stability(s,d.Good),f=this.algorithm.next_interval(c,l),_=Math.max(this.algorithm.next_interval(n.stability,l),f+1);n.scheduled_days=_,n.due=this.review_time.scheduler(_,!0),n.state=u.Review;break}default:throw new Error("Invalid grade")}const o={card:n,log:this.buildLog(t)};return this.next.set(t,o),o}reviewState(t){const e=this.next.get(t);if(e)return e;const i=this.current.elapsed_days,{difficulty:a,stability:s}=this.last,n=this.algorithm.forgetting_curve(i,s),l=h.card(this.current),o=h.card(this.current),c=h.card(this.current),f=h.card(this.current);this.next_ds(l,o,c,f,a,s,n),this.next_interval(l,o,c,f,i),this.next_state(l,o,c,f),l.lapses+=1;const _={card:l,log:this.buildLog(d.Again)},m={card:o,log:super.buildLog(d.Hard)},g={card:c,log:super.buildLog(d.Good)},b={card:f,log:super.buildLog(d.Easy)};return this.next.set(d.Again,_),this.next.set(d.Hard,m),this.next.set(d.Good,g),this.next.set(d.Easy,b),this.next.get(t)}next_ds(t,e,i,a,s,n,l){t.difficulty=this.algorithm.next_difficulty(s,d.Again);const o=n/Math.exp(this.algorithm.parameters.w[17]*this.algorithm.parameters.w[18]);t.stability=Math.min(+o.toFixed(8),this.algorithm.next_forget_stability(s,n,l)),e.difficulty=this.algorithm.next_difficulty(s,d.Hard),e.stability=this.algorithm.next_recall_stability(s,n,l,d.Hard),i.difficulty=this.algorithm.next_difficulty(s,d.Good),i.stability=this.algorithm.next_recall_stability(s,n,l,d.Good),a.difficulty=this.algorithm.next_difficulty(s,d.Easy),a.stability=this.algorithm.next_recall_stability(s,n,l,d.Easy)}next_interval(t,e,i,a,s){let n,l;n=this.algorithm.next_interval(e.stability,s),l=this.algorithm.next_interval(i.stability,s),n=Math.min(n,l),l=Math.max(l,n+1);const o=Math.max(this.algorithm.next_interval(a.stability,s),l+1);t.scheduled_days=0,t.due=this.review_time.scheduler(5),e.scheduled_days=n,e.due=this.review_time.scheduler(n,!0),i.scheduled_days=l,i.due=this.review_time.scheduler(l,!0),a.scheduled_days=o,a.due=this.review_time.scheduler(o,!0)}next_state(t,e,i,a){t.state=u.Relearning,e.state=u.Review,i.state=u.Review,a.state=u.Review}}class P extends ${newState(t){const e=this.next.get(t);if(e)return e;this.current.scheduled_days=0,this.current.elapsed_days=0;const i=h.card(this.current),a=h.card(this.current),s=h.card(this.current),n=h.card(this.current);this.init_ds(i,a,s,n);const l=0;return this.next_interval(i,a,s,n,l),this.next_state(i,a,s,n),this.update_next(i,a,s,n),this.next.get(t)}init_ds(t,e,i,a){t.difficulty=this.algorithm.init_difficulty(d.Again),t.stability=this.algorithm.init_stability(d.Again),e.difficulty=this.algorithm.init_difficulty(d.Hard),e.stability=this.algorithm.init_stability(d.Hard),i.difficulty=this.algorithm.init_difficulty(d.Good),i.stability=this.algorithm.init_stability(d.Good),a.difficulty=this.algorithm.init_difficulty(d.Easy),a.stability=this.algorithm.init_stability(d.Easy)}learningState(t){return this.reviewState(t)}reviewState(t){const e=this.next.get(t);if(e)return e;const i=this.current.elapsed_days,{difficulty:a,stability:s}=this.last,n=this.algorithm.forgetting_curve(i,s),l=h.card(this.current),o=h.card(this.current),c=h.card(this.current),f=h.card(this.current);return this.next_ds(l,o,c,f,a,s,n),this.next_interval(l,o,c,f,i),this.next_state(l,o,c,f),l.lapses+=1,this.update_next(l,o,c,f),this.next.get(t)}next_ds(t,e,i,a,s,n,l){t.difficulty=this.algorithm.next_difficulty(s,d.Again),t.stability=Math.min(n,this.algorithm.next_forget_stability(s,n,l)),e.difficulty=this.algorithm.next_difficulty(s,d.Hard),e.stability=this.algorithm.next_recall_stability(s,n,l,d.Hard),i.difficulty=this.algorithm.next_difficulty(s,d.Good),i.stability=this.algorithm.next_recall_stability(s,n,l,d.Good),a.difficulty=this.algorithm.next_difficulty(s,d.Easy),a.stability=this.algorithm.next_recall_stability(s,n,l,d.Easy)}next_interval(t,e,i,a,s){let n,l,o,c;n=this.algorithm.next_interval(t.stability,s),l=this.algorithm.next_interval(e.stability,s),o=this.algorithm.next_interval(i.stability,s),c=this.algorithm.next_interval(a.stability,s),n=Math.min(n,l),l=Math.max(l,n+1),o=Math.max(o,l+1),c=Math.max(c,o+1),t.scheduled_days=n,t.due=this.review_time.scheduler(n,!0),e.scheduled_days=l,e.due=this.review_time.scheduler(l,!0),i.scheduled_days=o,i.due=this.review_time.scheduler(o,!0),a.scheduled_days=c,a.due=this.review_time.scheduler(c,!0)}next_state(t,e,i,a){t.state=u.Review,e.state=u.Review,i.state=u.Review,a.state=u.Review}update_next(t,e,i,a){const s={card:t,log:this.buildLog(d.Again)},n={card:e,log:super.buildLog(d.Hard)},l={card:i,log:super.buildLog(d.Good)},o={card:a,log:super.buildLog(d.Easy)};this.next.set(d.Again,s),this.next.set(d.Hard,n),this.next.set(d.Good,l),this.next.set(d.Easy,o)}}class tt{fsrs;constructor(t){this.fsrs=t}replay(t,e,i){return this.fsrs.next(t,e,i)}handleManualRating(t,e,i,a,s,n,l){if(typeof e>"u")throw new Error("reschedule: state is required for manual rating");let o,c;if(e===u.New)o={rating:d.Manual,state:e,due:l??i,stability:t.stability,difficulty:t.difficulty,elapsed_days:a,last_elapsed_days:t.elapsed_days,scheduled_days:t.scheduled_days,review:i},c=v(i),c.last_review=i;else{if(typeof l>"u")throw new Error("reschedule: due is required for manual rating");const f=l.diff(i,"days");o={rating:d.Manual,state:t.state,due:t.last_review||t.due,stability:t.stability,difficulty:t.difficulty,elapsed_days:a,last_elapsed_days:t.elapsed_days,scheduled_days:t.scheduled_days,review:i},c={...t,state:e,due:l,last_review:i,stability:s||t.stability,difficulty:n||t.difficulty,elapsed_days:a,scheduled_days:f,reps:t.reps+1}}return{card:c,log:o}}reschedule(t,e){const i=[];let a=v(t.due);for(const s of e){let n;if(s.review=h.time(s.review),s.rating===d.Manual){let l=0;a.state!==u.New&&a.last_review&&(l=s.review.diff(a.last_review,"days")),n=this.handleManualRating(a,s.state,s.review,l,s.stability,s.difficulty,s.due?h.time(s.due):void 0)}else n=this.replay(a,s.review,s.rating);i.push(n),a=n.card}return i}calculateManualRecord(t,e,i,a){if(!i)return null;const{card:s,log:n}=i,l=h.card(t);return l.due.getTime()===s.due.getTime()?null:(l.scheduled_days=s.due.diff(l.due,"days"),this.handleManualRating(l,s.state,h.time(e),n.elapsed_days,a?s.stability:void 0,a?s.difficulty:void 0,s.due))}}class V extends Y{strategyHandler=new Map;Scheduler;constructor(t){super(t);const{enable_short_term:e}=this.parameters;this.Scheduler=e?O:P}params_handler_proxy(){const t=this;return{set:function(e,i,a){return i==="request_retention"&&Number.isFinite(a)?t.intervalModifier=t.calculate_interval_modifier(Number(a)):i==="enable_short_term"&&(t.Scheduler=a===!0?O:P),Reflect.set(e,i,a),!0}}}useStrategy(t,e){return this.strategyHandler.set(t,e),this}clearStrategy(t){return t?this.strategyHandler.delete(t):this.strategyHandler.clear(),this}getScheduler(t,e){const i=this.strategyHandler.get(x.SEED),a=this.strategyHandler.get(x.SCHEDULER)||this.Scheduler,s=i||F;return new a(t,e,this,{seed:s})}repeat(t,e,i){const a=this.getScheduler(t,e).preview();return i&&typeof i=="function"?i(a):a}next(t,e,i,a){const s=this.getScheduler(t,e),n=h.rating(i);if(n===d.Manual)throw new Error("Cannot review a manual rating");const l=s.review(n);return a&&typeof a=="function"?a(l):l}get_retrievability(t,e,i=!0){const a=h.card(t);e=e?h.time(e):new Date;const s=a.state!==u.New?Math.max(e.diff(a.last_review,"days"),0):0,n=a.state!==u.New?this.forgetting_curve(s,+a.stability.toFixed(8)):0;return i?`${(n*100).toFixed(2)}%`:n}rollback(t,e,i){const a=h.card(t),s=h.review_log(e);if(s.rating===d.Manual)throw new Error("Cannot rollback a manual rating");let n,l,o;switch(s.state){case u.New:n=s.due,l=void 0,o=0;break;case u.Learning:case u.Relearning:case u.Review:n=s.review,l=s.due,o=a.lapses-(s.rating===d.Again&&s.state===u.Review?1:0);break}const c={...a,due:n,stability:s.stability,difficulty:s.difficulty,elapsed_days:s.last_elapsed_days,scheduled_days:s.scheduled_days,reps:Math.max(0,a.reps-1),lapses:Math.max(0,o),state:s.state,last_review:l};return i&&typeof i=="function"?i(c):c}forget(t,e,i=!1,a){const s=h.card(t);e=h.time(e);const n=s.state===u.New?0:e.diff(s.last_review,"days"),l={rating:d.Manual,state:s.state,due:s.due,stability:s.stability,difficulty:s.difficulty,elapsed_days:0,last_elapsed_days:s.elapsed_days,scheduled_days:n,review:e},o={card:{...s,due:e,stability:0,difficulty:0,elapsed_days:0,scheduled_days:0,reps:i?0:s.reps,lapses:i?0:s.lapses,state:u.New,last_review:s.last_review},log:l};return a&&typeof a=="function"?a(o):o}reschedule(t,e=[],i={}){const{recordLogHandler:a,reviewsOrderBy:s,skipManual:n=!0,now:l=new Date,update_memory_state:o=!1}=i;s&&typeof s=="function"&&e.sort(s),n&&(e=e.filter(b=>b.rating!==d.Manual));const c=new tt(this),f=c.reschedule(i.first_card||v(),e),_=f.length,m=h.card(t),g=c.calculateManualRecord(m,l,_?f[_-1]:void 0,o);return a&&typeof a=="function"?{collections:f.map(a),reschedule_item:g?a(g):null}:{collections:f,reschedule_item:g}}}const et=r=>new V(r||{});exports.AbstractScheduler=$,exports.DECAY=R,exports.DefaultInitSeedStrategy=F,exports.FACTOR=D,exports.FSRS=V,exports.FSRSAlgorithm=Y,exports.FSRSVersion=j,exports.GenSeedStrategyWithCardId=Z,exports.Grades=T,exports.Rating=d,exports.State=u,exports.StrategyMode=x,exports.TypeConvert=h,exports.clamp=p,exports.createEmptyCard=v,exports.dateDiffInDays=q,exports.date_diff=k,exports.date_scheduler=C,exports.default_enable_fuzz=G,exports.default_enable_short_term=I,exports.default_maximum_interval=A,exports.default_request_retention=H,exports.default_w=L,exports.fixDate=y,exports.fixRating=B,exports.fixState=W,exports.formatDate=z,exports.fsrs=et,exports.generatorParameters=M,exports.get_fuzz_range=U,exports.show_diff_message=N,module.exports=Object.assign(exports.default||{},exports);
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/fsrs/models.ts","../src/fsrs/convert.ts","../src/fsrs/default.ts","../src/fsrs/help.ts","../src/fsrs/alea.ts","../src/fsrs/algorithm.ts","../src/fsrs/strategies/seed.ts","../src/fsrs/strategies/types.ts","../src/fsrs/abstract_scheduler.ts","../src/fsrs/impl/basic_scheduler.ts","../src/fsrs/impl/long_term_scheduler.ts","../src/fsrs/reschedule.ts","../src/fsrs/fsrs.ts"],"sourcesContent":["export type StateType = 'New' | 'Learning' | 'Review' | 'Relearning'\n\nexport enum State {\n New = 0,\n Learning = 1,\n Review = 2,\n Relearning = 3,\n}\n\nexport type RatingType = 'Manual' | 'Again' | 'Hard' | 'Good' | 'Easy'\n\nexport enum Rating {\n Manual = 0,\n Again = 1,\n Hard = 2,\n Good = 3,\n Easy = 4,\n}\n\ntype ExcludeManual<T> = Exclude<T, Rating.Manual>\n\nexport type Grade = ExcludeManual<Rating>\n\nexport interface ReviewLog {\n rating: Rating // Rating of the review (Again, Hard, Good, Easy)\n state: State // State of the review (New, Learning, Review, Relearning)\n due: Date // Date of the last scheduling\n stability: number // Memory stability during the review\n difficulty: number // Difficulty of the card during the review\n elapsed_days: number // Number of days elapsed since the last review\n last_elapsed_days: number // Number of days between the last two reviews\n scheduled_days: number // Number of days until the next review\n review: Date // Date of the review\n}\n\nexport type RecordLogItem = {\n card: Card\n log: ReviewLog\n}\nexport type RecordLog = {\n [key in Grade]: RecordLogItem\n}\n\nexport interface Card {\n due: Date // Due date\n stability: number // Stability\n difficulty: number // Difficulty level\n elapsed_days: number // Number of days elapsed\n scheduled_days: number // Number of days scheduled\n reps: number // Repetition count\n lapses: number // Number of lapses or mistakes\n state: State // Card's state (New, Learning, Review, Relearning)\n last_review?: Date // Date of the last review (optional)\n}\n\nexport interface CardInput extends Omit<Card, 'state' | 'due' | 'last_review'> {\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n last_review?: DateInput | null // Date of the last review (optional)\n}\n\nexport type DateInput = Date | number | string\n\nexport interface ReviewLogInput\n extends Omit<ReviewLog, 'rating' | 'state' | 'due' | 'review'> {\n rating: RatingType | Rating // Rating of the review (Again, Hard, Good, Easy)\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n review: DateInput // Date of the last review\n}\n\nexport interface FSRSParameters {\n request_retention: number\n maximum_interval: number\n w: number[]\n enable_fuzz: boolean\n enable_short_term: boolean\n}\n\nexport interface FSRSReview {\n /**\n * 0-4: Manual, Again, Hard, Good, Easy\n * = revlog.rating\n */\n rating: Rating\n /**\n * The number of days that passed\n * = revlog.elapsed_days\n * = round(revlog[-1].review - revlog[-2].review)\n */\n delta_t: number\n}\n\nexport type FSRSHistory = Partial<\n Omit<ReviewLog, 'rating' | 'review' | 'elapsed_days'>\n> &\n (\n | {\n rating: Grade\n review: DateInput | Date\n }\n | {\n rating: Rating.Manual\n due: DateInput | Date\n state: State\n review: DateInput | Date\n }\n )\n","import {\n Card,\n CardInput,\n DateInput,\n Rating,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\n\nexport class TypeConvert {\n static card<T extends Card | CardInput>(card: T): Card {\n return {\n ...card,\n state: TypeConvert.state(card.state),\n due: TypeConvert.time(card.due),\n last_review: card.last_review\n ? TypeConvert.time(card.last_review)\n : undefined,\n } as Card\n }\n static rating(value: unknown): Rating {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = Rating[`${firstLetter}${restOfString}` as keyof typeof Rating]\n if (ret === undefined) {\n throw new Error(`Invalid rating:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as Rating\n }\n throw new Error(`Invalid rating:[${value}]`)\n }\n static state(value: unknown): State {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = State[`${firstLetter}${restOfString}` as keyof typeof State]\n if (ret === undefined) {\n throw new Error(`Invalid state:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as State\n }\n throw new Error(`Invalid state:[${value}]`)\n }\n static time(value: unknown): Date {\n if (typeof value === 'object' && value instanceof Date) {\n return value\n } else if (typeof value === 'string') {\n const timestamp = Date.parse(value)\n if (!isNaN(timestamp)) {\n return new Date(timestamp)\n } else {\n throw new Error(`Invalid date:[${value}]`)\n }\n } else if (typeof value === 'number') {\n return new Date(value)\n }\n throw new Error(`Invalid date:[${value}]`)\n }\n static review_log(log: ReviewLogInput | ReviewLog): ReviewLog {\n return {\n ...log,\n due: TypeConvert.time(log.due),\n rating: TypeConvert.rating(log.rating),\n state: TypeConvert.state(log.state),\n review: TypeConvert.time(log.review),\n } satisfies ReviewLog\n }\n}\n","import { Card, DateInput, FSRSParameters, State } from './models'\nimport { TypeConvert } from './convert'\n\nexport const default_request_retention = 0.9\nexport const default_maximum_interval = 36500\nexport const default_w = [\n 0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 0.0046, 1.54575,\n 0.1192, 1.01925, 1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655,\n 0.6621,\n]\nexport const default_enable_fuzz = false\nexport const default_enable_short_term = true\n\nexport const FSRSVersion: string = 'v4.5.2 using FSRS-5.0'\n\nexport const generatorParameters = (\n props?: Partial<FSRSParameters>\n): FSRSParameters => {\n let w = default_w\n if (props?.w) {\n if (props.w.length === 19) {\n w = props?.w\n } else if (props.w.length === 17) {\n w = props?.w.concat([0.0, 0.0])\n w[4] = +(w[5] * 2.0 + w[4]).toFixed(8)\n w[5] = +(Math.log(w[5] * 3.0 + 1.0) / 3.0).toFixed(8)\n w[6] = +(w[6] + 0.5).toFixed(8)\n console.debug('[FSRS V5]auto fill w to 19 length')\n }\n }\n return {\n request_retention: props?.request_retention || default_request_retention,\n maximum_interval: props?.maximum_interval || default_maximum_interval,\n w: w,\n enable_fuzz: props?.enable_fuzz ?? default_enable_fuzz,\n enable_short_term: props?.enable_short_term ?? default_enable_short_term,\n } satisfies FSRSParameters\n}\n\n/**\n * Create an empty card\n * @param now Current time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * ```\n * @example\n * ```\n * interface CardUnChecked\n * extends Omit<Card, \"due\" | \"last_review\" | \"state\"> {\n * cid: string;\n * due: Date | number;\n * last_review: Date | null | number;\n * state: StateType;\n * }\n *\n * function cardAfterHandler(card: Card) {\n * return {\n * ...card,\n * cid: \"test001\",\n * state: State[card.state],\n * last_review: card.last_review ?? null,\n * } as CardUnChecked;\n * }\n *\n * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);\n * ```\n */\nexport function createEmptyCard<R = Card>(\n now?: DateInput,\n afterHandler?: (card: Card) => R\n): R {\n const emptyCard: Card = {\n due: now ? TypeConvert.time(now) : new Date(),\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: 0,\n lapses: 0,\n state: State.New,\n last_review: undefined,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(emptyCard)\n } else {\n return emptyCard as R\n }\n}\n","import type { int, unit } from './types'\nimport type { DateInput, Grade } from './models'\nimport { Rating, State } from './models'\nimport { TypeConvert } from './convert'\n\ndeclare global {\n export interface Date {\n scheduler(t: int, isDay?: boolean): Date\n\n diff(pre: Date, unit: unit): int\n\n format(): string\n\n dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string\n }\n}\n\nDate.prototype.scheduler = function (t: int, isDay?: boolean): Date {\n return date_scheduler(this, t, isDay)\n}\n\n/**\n * 当前时间与之前的时间差值\n * @param pre 比当前时间还要之前\n * @param unit 单位: days | minutes\n */\nDate.prototype.diff = function (pre: Date, unit: unit): int {\n return date_diff(this, pre, unit) as int\n}\n\nDate.prototype.format = function (): string {\n return formatDate(this)\n}\n\nDate.prototype.dueFormat = function (\n last_review: Date,\n unit?: boolean,\n timeUnit?: string[]\n) {\n return show_diff_message(this, last_review, unit, timeUnit)\n}\n\n/**\n * 计算日期和时间的偏移,并返回一个新的日期对象。\n * @param now 当前日期和时间\n * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟\n * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移\n * @returns 偏移后的日期和时间对象\n */\nexport function date_scheduler(\n now: DateInput,\n t: number,\n isDay?: boolean\n): Date {\n return new Date(\n isDay\n ? fixDate(now).getTime() + t * 24 * 60 * 60 * 1000\n : fixDate(now).getTime() + t * 60 * 1000\n )\n}\n\nexport function date_diff(now: DateInput, pre: DateInput, unit: unit): number {\n if (!now || !pre) {\n throw new Error('Invalid date')\n }\n const diff = fixDate(now).getTime() - fixDate(pre).getTime()\n let r = 0\n switch (unit) {\n case 'days':\n r = Math.floor(diff / (24 * 60 * 60 * 1000))\n break\n case 'minutes':\n r = Math.floor(diff / (60 * 1000))\n break\n }\n return r\n}\n\nexport function formatDate(dateInput: DateInput): string {\n const date = fixDate(dateInput)\n const year: number = date.getFullYear()\n const month: number = date.getMonth() + 1\n const day: number = date.getDate()\n const hours: number = date.getHours()\n const minutes: number = date.getMinutes()\n const seconds: number = date.getSeconds()\n\n return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(\n minutes\n )}:${padZero(seconds)}`\n}\n\nfunction padZero(num: number): string {\n return num < 10 ? `0${num}` : `${num}`\n}\n\nconst TIMEUNIT = [60, 60, 24, 31, 12]\nconst TIMEUNITFORMAT = ['second', 'min', 'hour', 'day', 'month', 'year']\n\nexport function show_diff_message(\n due: DateInput,\n last_review: DateInput,\n unit?: boolean,\n timeUnit: string[] = TIMEUNITFORMAT\n): string {\n due = fixDate(due)\n last_review = fixDate(last_review)\n if (timeUnit.length !== TIMEUNITFORMAT.length) {\n timeUnit = TIMEUNITFORMAT\n }\n let diff = due.getTime() - last_review.getTime()\n let i\n diff /= 1000\n for (i = 0; i < TIMEUNIT.length; i++) {\n if (diff < TIMEUNIT[i]) {\n break\n } else {\n diff /= TIMEUNIT[i]\n }\n }\n return `${Math.floor(diff)}${unit ? timeUnit[i] : ''}`\n}\n\n/**\n *\n * @deprecated Use TypeConvert.time instead\n */\nexport function fixDate(value: unknown) {\n return TypeConvert.time(value)\n}\n\n/**\n * @deprecated Use TypeConvert.state instead\n */\nexport function fixState(value: unknown): State {\n return TypeConvert.state(value)\n}\n\n/**\n * @deprecated Use TypeConvert.rating instead\n */\nexport function fixRating(value: unknown): Rating {\n return TypeConvert.rating(value)\n}\n\nexport const Grades: Readonly<Grade[]> = [\n Rating.Again,\n Rating.Hard,\n Rating.Good,\n Rating.Easy,\n] as const\n\nconst FUZZ_RANGES = [\n {\n start: 2.5,\n end: 7.0,\n factor: 0.15,\n },\n {\n start: 7.0,\n end: 20.0,\n factor: 0.1,\n },\n {\n start: 20.0,\n end: Infinity,\n factor: 0.05,\n },\n] as const\n\nexport function get_fuzz_range(\n interval: number,\n elapsed_days: number,\n maximum_interval: number\n) {\n let delta = 1.0\n for (const range of FUZZ_RANGES) {\n delta +=\n range.factor * Math.max(Math.min(interval, range.end) - range.start, 0.0)\n }\n interval = Math.min(interval, maximum_interval)\n let min_ivl = Math.max(2, Math.round(interval - delta))\n const max_ivl = Math.min(Math.round(interval + delta), maximum_interval)\n if (interval > elapsed_days) {\n min_ivl = Math.max(min_ivl, elapsed_days + 1)\n }\n min_ivl = Math.min(min_ivl, max_ivl)\n return { min_ivl, max_ivl }\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max)\n}\n\nexport function dateDiffInDays(last: Date, cur: Date) {\n // Discard the time and time-zone information.\n const utc1 = Date.UTC(\n last.getUTCFullYear(),\n last.getUTCMonth(),\n last.getUTCDate()\n )\n const utc2 = Date.UTC(\n cur.getUTCFullYear(),\n cur.getUTCMonth(),\n cur.getUTCDate()\n )\n\n return Math.floor((utc2 - utc1) / 86400000 /** 1000 * 60 * 60 * 24*/)\n}\n","// https://github.com/davidbau/seedrandom/blob/released/lib/alea.js\n// A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010\n// http://baagoe.com/en/RandomMusings/javascript/\n// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror\n// Original work is under MIT license -\n\n// Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\ntype State = {\n c: number\n s0: number\n s1: number\n s2: number\n}\n\nclass Alea {\n private c: number\n private s0: number\n private s1: number\n private s2: number\n\n constructor(seed?: number | string) {\n const mash = Mash()\n this.c = 1\n this.s0 = mash(' ')\n this.s1 = mash(' ')\n this.s2 = mash(' ')\n if (seed == null) seed = +new Date()\n this.s0 -= mash(seed)\n if (this.s0 < 0) this.s0 += 1\n this.s1 -= mash(seed)\n if (this.s1 < 0) this.s1 += 1\n this.s2 -= mash(seed)\n if (this.s2 < 0) this.s2 += 1\n }\n\n next(): number {\n const t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10 // 2^-32\n this.s0 = this.s1\n this.s1 = this.s2\n this.s2 = t - (this.c = t | 0)\n return this.s2\n }\n\n set state(state: State) {\n this.c = state.c\n this.s0 = state.s0\n this.s1 = state.s1\n this.s2 = state.s2\n }\n\n get state(): State {\n return {\n c: this.c,\n s0: this.s0,\n s1: this.s1,\n s2: this.s2,\n }\n }\n}\n\nfunction Mash() {\n let n = 0xefc8249d\n return function mash(data: string | number): number {\n data = String(data)\n for (let i = 0; i < data.length; i++) {\n n += data.charCodeAt(i)\n let h = 0.02519603282416938 * n\n n = h >>> 0\n h -= n\n h *= n\n n = h >>> 0\n h -= n\n n += h * 0x100000000 // 2^32\n }\n return (n >>> 0) * 2.3283064365386963e-10 // 2^-32\n }\n}\n\nfunction alea(seed?: number | string) {\n const xg = new Alea(seed)\n const prng = () => xg.next()\n\n prng.int32 = () => (xg.next() * 0x100000000) | 0\n prng.double = () =>\n prng() + ((prng() * 0x200000) | 0) * 1.1102230246251565e-16 // 2^-53\n prng.state = () => xg.state\n prng.importState = (state: State) => {\n xg.state = state\n return prng\n }\n return prng\n}\n\nexport { alea }\n","import { generatorParameters } from './default'\nimport { FSRSParameters, Grade, Rating } from './models'\nimport type { int } from './types'\nimport { clamp, get_fuzz_range } from './help'\nimport { alea } from './alea'\n\n/**\n * @default DECAY = -0.5\n */\nexport const DECAY: number = -0.5\n/**\n * FACTOR = Math.pow(0.9, 1 / DECAY) - 1= 19 / 81\n *\n * $$\\text{FACTOR} = \\frac{19}{81}$$\n * @default FACTOR = 19 / 81\n */\nexport const FACTOR: number = 19 / 81\n\n/**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n */\nexport class FSRSAlgorithm {\n protected param!: FSRSParameters\n protected intervalModifier!: number\n protected _seed?: string\n\n constructor(params: Partial<FSRSParameters>) {\n this.param = new Proxy(\n generatorParameters(params),\n this.params_handler_proxy()\n )\n this.intervalModifier = this.calculate_interval_modifier(\n this.param.request_retention\n )\n }\n\n get interval_modifier(): number {\n return this.intervalModifier\n }\n\n set seed(seed: string) {\n this._seed = seed\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n *\n * The formula used is: $$I(r,s) = (r^{\\frac{1}{DECAY}} - 1) / FACTOR \\times s$$\n * @param request_retention 0<request_retention<=1,Requested retention rate\n * @throws {Error} Requested retention rate should be in the range (0,1]\n */\n calculate_interval_modifier(request_retention: number): number {\n if (request_retention <= 0 || request_retention > 1) {\n throw new Error('Requested retention rate should be in the range (0,1]')\n }\n return +((Math.pow(request_retention, 1 / DECAY) - 1) / FACTOR).toFixed(8)\n }\n\n /**\n * Get the parameters of the algorithm.\n */\n get parameters(): FSRSParameters {\n return this.param\n }\n\n /**\n * Set the parameters of the algorithm.\n * @param params Partial<FSRSParameters>\n */\n set parameters(params: Partial<FSRSParameters>) {\n this.update_parameters(params)\n }\n\n protected params_handler_proxy(): ProxyHandler<FSRSParameters> {\n const _this = this satisfies FSRSAlgorithm\n return {\n set: function (\n target: FSRSParameters,\n prop: keyof FSRSParameters,\n value: FSRSParameters[keyof FSRSParameters]\n ) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n }\n Reflect.set(target, prop, value)\n return true\n },\n }\n }\n\n private update_parameters(params: Partial<FSRSParameters>): void {\n const _params = generatorParameters(params)\n for (const key in _params) {\n if (key in this.param) {\n const paramKey = key as keyof FSRSParameters\n this.param[paramKey] = _params[paramKey] as never\n }\n }\n }\n\n /**\n * The formula used is :\n * $$ S_0(G) = w_{G-1}$$\n * $$S_0 = \\max \\lbrace S_0,0.1\\rbrace $$\n\n * @param g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return Stability (interval when R=90%)\n */\n init_stability(g: Grade): number {\n return Math.max(this.param.w[g - 1], 0.1)\n }\n\n /**\n * The formula used is :\n * $$D_0(G) = w_4 - e^{(G-1) \\cdot w_5} + 1 $$\n * $$D_0 = \\min \\lbrace \\max \\lbrace D_0(G),1 \\rbrace,10 \\rbrace$$\n * where the $$D_0(1)=w_4$$ when the first rating is good.\n *\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} Difficulty $$D \\in [1,10]$$\n */\n init_difficulty(g: Grade): number {\n return this.constrain_difficulty(\n this.param.w[4] - Math.exp((g - 1) * this.param.w[5]) + 1\n )\n }\n\n /**\n * If fuzzing is disabled or ivl is less than 2.5, it returns the original interval.\n * @param {number} ivl - The interval to be fuzzed.\n * @param {number} elapsed_days t days since the last review\n * @return {number} - The fuzzed interval.\n **/\n apply_fuzz(ivl: number, elapsed_days: number): int {\n if (!this.param.enable_fuzz || ivl < 2.5) return Math.round(ivl) as int\n const generator = alea(this._seed) // I do not want others to directly access the seed externally.\n const fuzz_factor = generator()\n const { min_ivl, max_ivl } = get_fuzz_range(\n ivl,\n elapsed_days,\n this.param.maximum_interval\n )\n return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl) as int\n }\n\n /**\n * @see The formula used is : {@link FSRSAlgorithm.calculate_interval_modifier}\n * @param {number} s - Stability (interval when R=90%)\n * @param {number} elapsed_days t days since the last review\n */\n next_interval(s: number, elapsed_days: number): int {\n const newInterval = Math.min(\n Math.max(1, Math.round(s * this.intervalModifier)),\n this.param.maximum_interval\n ) as int\n return this.apply_fuzz(newInterval, elapsed_days)\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/issues/697\n */\n linear_damping(delta_d: number, old_d: number): number {\n return +(delta_d * (10 - old_d) / 9).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$\\text{delta}_d = -w_6 \\cdot (g - 3)$$\n * $$\\text{next}_d = D + \\text{linear damping}(\\text{delta}_d , D)$$\n * $$D^\\prime(D,R) = w_7 \\cdot D_0(4) +(1 - w_7) \\cdot \\text{next}_d$$\n * @param {number} d Difficulty $$D \\in [1,10]$$\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} $$\\text{next}_D$$\n */\n next_difficulty(d: number, g: Grade): number {\n const delta_d = -this.param.w[6] * (g - 3)\n const next_d = d + this.linear_damping(delta_d, d)\n return this.constrain_difficulty(\n this.mean_reversion(this.init_difficulty(Rating.Easy), next_d)\n )\n }\n\n /**\n * The formula used is :\n * $$\\min \\lbrace \\max \\lbrace D_0,1 \\rbrace,10\\rbrace$$\n * @param {number} difficulty $$D \\in [1,10]$$\n */\n constrain_difficulty(difficulty: number): number {\n return Math.min(Math.max(+difficulty.toFixed(8), 1), 10)\n }\n\n /**\n * The formula used is :\n * $$w_7 \\cdot \\text{init} +(1 - w_7) \\cdot \\text{current}$$\n * @param {number} init $$w_2 : D_0(3) = w_2 + (R-2) \\cdot w_3= w_2$$\n * @param {number} current $$D - w_6 \\cdot (R - 2)$$\n * @return {number} difficulty\n */\n mean_reversion(init: number, current: number): number {\n return +(this.param.w[7] * init + (1 - this.param.w[7]) * current).toFixed(\n 8\n )\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_r(D,S,R,G) = S\\cdot(e^{w_8}\\cdot (11-D)\\cdot S^{-w_9}\\cdot(e^{w_{10}\\cdot(1-R)}-1)\\cdot w_{15}(\\text{if} G=2) \\cdot w_{16}(\\text{if} G=4)+1)$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n * @return {number} S^\\prime_r new stability after recall\n */\n next_recall_stability(d: number, s: number, r: number, g: Grade): number {\n const hard_penalty = Rating.Hard === g ? this.param.w[15] : 1\n const easy_bound = Rating.Easy === g ? this.param.w[16] : 1\n return +clamp(\n s *\n (1 +\n Math.exp(this.param.w[8]) *\n (11 - d) *\n Math.pow(s, -this.param.w[9]) *\n (Math.exp((1 - r) * this.param.w[10]) - 1) *\n hard_penalty *\n easy_bound),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_f(D,S,R) = w_{11}\\cdot D^{-w_{12}}\\cdot ((S+1)^{w_{13}}-1) \\cdot e^{w_{14}\\cdot(1-R)}$$\n * enable_short_term = true : $$S^\\prime_f \\in \\min \\lbrace \\max \\lbrace S^\\prime_f,0.01\\rbrace, \\frac{S}{e^{w_{17} \\cdot w_{18}}} \\rbrace$$\n * enable_short_term = false : $$S^\\prime_f \\in \\min \\lbrace \\max \\lbrace S^\\prime_f,0.01\\rbrace, S \\rbrace$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @return {number} S^\\prime_f new stability after forgetting\n */\n next_forget_stability(d: number, s: number, r: number): number {\n return +clamp(\n this.param.w[11] *\n Math.pow(d, -this.param.w[12]) *\n (Math.pow(s + 1, this.param.w[13]) - 1) *\n Math.exp((1 - r) * this.param.w[14]),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_s(S,G) = S \\cdot e^{w_{17} \\cdot (G-3+w_{18})}$$\n * @param {number} s Stability (interval when R=90%)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n */\n next_short_term_stability(s: number, g: Grade): number {\n return +clamp(\n s * Math.exp(this.param.w[17] * (g - 3 + this.param.w[18])),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$R(t,S) = (1 + \\text{FACTOR} \\times \\frac{t}{9 \\cdot S})^{\\text{DECAY}}$$\n * @param {number} elapsed_days t days since the last review\n * @param {number} stability Stability (interval when R=90%)\n * @return {number} r Retrievability (probability of recall)\n */\n forgetting_curve(elapsed_days: number, stability: number): number {\n return +Math.pow(1 + (FACTOR * elapsed_days) / stability, DECAY).toFixed(8)\n }\n}\n","import type { AbstractScheduler } from '../abstract_scheduler'\nimport type { TSeedStrategy } from './types'\n\nexport function DefaultInitSeedStrategy(this: AbstractScheduler): string {\n const time = this.review_time.getTime()\n const reps = this.current.reps\n const mul = this.current.difficulty * this.current.stability\n return `${time}_${reps}_${mul}`\n}\n\n/**\n * Generates a seed strategy function for card IDs.\n *\n * @param card_id_field - The field name of the card ID in the current object.\n * @returns A function that generates a seed based on the card ID and repetitions.\n *\n * @remarks\n * The returned function uses the `card_id_field` to retrieve the card ID from the current object.\n * It then adds the number of repetitions (`reps`) to the card ID to generate the seed.\n *\n * @example\n * ```typescript\n * const seedStrategy = GenCardIdSeedStrategy('card_id');\n * const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy)\n * const card = createEmptyCard<Card & { card_id: number }>()\n * card.card_id = 555\n * const record = f.repeat(card, new Date())\n * ```\n */\nexport function GenSeedStrategyWithCardId(\n card_id_field: string | number\n): TSeedStrategy {\n return function (this: AbstractScheduler): string {\n // https://github.com/open-spaced-repetition/ts-fsrs/issues/131#issuecomment-2408426225\n const card_id = Reflect.get(this.current, card_id_field) ?? 0\n const reps = this.current.reps\n // ex1\n // card_id:string + reps:number = 'e2ecb1f7-8d15-420b-bec4-c7212ad2e5dc' + 4\n // = 'e2ecb1f7-8d15-420b-bec4-c7212ad2e5dc4'\n\n // ex2\n // card_id:number + reps:number = 1732452519198 + 4\n // = '17324525191984'\n return String(card_id + reps || 0)\n }\n}\n","import type { AbstractScheduler } from '../abstract_scheduler'\nimport type { FSRSAlgorithm } from '../algorithm'\nimport type { Card, CardInput, DateInput } from '../models'\nimport type { IScheduler } from '../types'\n\nexport enum StrategyMode {\n SCHEDULER = 'Scheduler',\n SEED = 'Seed',\n}\n\nexport type TSeedStrategy = (this: AbstractScheduler) => string\nexport type TSchedulerStrategy<T extends CardInput | Card = CardInput | Card> =\n new (\n card: T,\n now: DateInput,\n algorithm: FSRSAlgorithm,\n strategies: { seed: TSeedStrategy }\n ) => IScheduler\n\nexport type TStrategyHandler<E = StrategyMode> =\n E extends StrategyMode.SCHEDULER\n ? TSchedulerStrategy\n : E extends StrategyMode.SEED\n ? TSeedStrategy\n : never\n","import { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport { dateDiffInDays, Grades } from './help'\nimport {\n type Card,\n type Grade,\n type RecordLogItem,\n State,\n Rating,\n type ReviewLog,\n type CardInput,\n type DateInput,\n} from './models'\nimport { DefaultInitSeedStrategy } from './strategies'\nimport type { TSeedStrategy } from './strategies/types'\nimport type { IPreview, IScheduler } from './types'\n\nexport abstract class AbstractScheduler implements IScheduler {\n protected last: Card\n protected current: Card\n protected review_time: Date\n protected next: Map<Grade, RecordLogItem> = new Map()\n protected algorithm: FSRSAlgorithm\n private initSeedStrategy: TSeedStrategy\n\n constructor(\n card: CardInput | Card,\n now: DateInput,\n algorithm: FSRSAlgorithm,\n strategies: {\n seed: TSeedStrategy\n } = {\n seed: DefaultInitSeedStrategy,\n }\n ) {\n this.algorithm = algorithm\n this.initSeedStrategy = strategies.seed.bind(this)\n\n this.last = TypeConvert.card(card)\n this.current = TypeConvert.card(card)\n this.review_time = TypeConvert.time(now)\n this.init()\n }\n\n private init() {\n const { state, last_review } = this.current\n let interval = 0 // card.state === State.New => 0\n if (state !== State.New && last_review) {\n interval = dateDiffInDays(last_review, this.review_time)\n }\n this.current.last_review = this.review_time\n this.current.elapsed_days = interval\n this.current.reps += 1\n this.algorithm.seed = this.initSeedStrategy()\n }\n\n public preview(): IPreview {\n return {\n [Rating.Again]: this.review(Rating.Again),\n [Rating.Hard]: this.review(Rating.Hard),\n [Rating.Good]: this.review(Rating.Good),\n [Rating.Easy]: this.review(Rating.Easy),\n [Symbol.iterator]: this.previewIterator.bind(this),\n } satisfies IPreview\n }\n\n private *previewIterator(): IterableIterator<RecordLogItem> {\n for (const grade of Grades) {\n yield this.review(grade)\n }\n }\n\n public review(grade: Grade): RecordLogItem {\n const { state } = this.last\n let item: RecordLogItem | undefined\n switch (state) {\n case State.New:\n item = this.newState(grade)\n break\n case State.Learning:\n case State.Relearning:\n item = this.learningState(grade)\n break\n case State.Review:\n item = this.reviewState(grade)\n break\n }\n if (item) {\n return item\n }\n throw new Error('Invalid grade')\n }\n\n protected abstract newState(grade: Grade): RecordLogItem\n\n protected abstract learningState(grade: Grade): RecordLogItem\n\n protected abstract reviewState(grade: Grade): RecordLogItem\n\n protected buildLog(rating: Grade): ReviewLog {\n const { last_review, due, elapsed_days } = this.last\n\n return {\n rating: rating,\n state: this.current.state,\n due: last_review || due,\n stability: this.current.stability,\n difficulty: this.current.difficulty,\n elapsed_days: this.current.elapsed_days,\n last_elapsed_days: elapsed_days,\n scheduled_days: this.current.scheduled_days,\n review: this.review_time,\n } satisfies ReviewLog\n }\n}\n","import { AbstractScheduler } from '../abstract_scheduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class BasicScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const next = TypeConvert.card(this.current)\n next.difficulty = this.algorithm.init_difficulty(grade)\n next.stability = this.algorithm.init_stability(grade)\n\n switch (grade) {\n case Rating.Again:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(1 as int)\n next.state = State.Learning\n break\n case Rating.Hard:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int)\n next.state = State.Learning\n break\n case Rating.Good:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = State.Learning\n break\n case Rating.Easy: {\n const easy_interval = this.algorithm.next_interval(\n next.stability,\n this.current.elapsed_days\n )\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override learningState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const { state, difficulty, stability } = this.last\n const next = TypeConvert.card(this.current)\n const interval = this.current.elapsed_days\n next.difficulty = this.algorithm.next_difficulty(difficulty, grade)\n next.stability = this.algorithm.next_short_term_stability(stability, grade)\n\n switch (grade) {\n case Rating.Again: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int, false)\n next.state = state\n break\n }\n case Rating.Hard: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = state\n break\n }\n case Rating.Good: {\n const good_interval = this.algorithm.next_interval(\n next.stability,\n interval\n )\n next.scheduled_days = good_interval\n next.due = this.review_time.scheduler(good_interval as int, true)\n next.state = State.Review\n break\n }\n case Rating.Easy: {\n const good_stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Good\n )\n const good_interval = this.algorithm.next_interval(\n good_stability,\n interval\n )\n const easy_interval = Math.max(\n this.algorithm.next_interval(next.stability, interval),\n good_interval + 1\n ) as int\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n const nextSMin =\n stability /\n Math.exp(\n this.algorithm.parameters.w[17] * this.algorithm.parameters.w[18]\n )\n next_again.stability = Math.min(\n +nextSMin.toFixed(8),\n this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n )\n\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let hard_interval: int, good_interval: int\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n hard_interval = Math.min(hard_interval, good_interval) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n const easy_interval = Math.max(\n this.algorithm.next_interval(next_easy.stability, interval),\n good_interval + 1\n ) as int\n next_again.scheduled_days = 0\n next_again.due = this.review_time.scheduler(5 as int)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Relearning\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n}\n","import { AbstractScheduler } from '../abstract_scheduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class LongTermScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n\n this.current.scheduled_days = 0\n this.current.elapsed_days = 0\n\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.init_ds(next_again, next_hard, next_good, next_easy)\n const first_interval = 0\n\n this.next_interval(\n next_again,\n next_hard,\n next_good,\n next_easy,\n first_interval\n )\n\n this.next_state(next_again, next_hard, next_good, next_easy)\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n private init_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ): void {\n next_again.difficulty = this.algorithm.init_difficulty(Rating.Again)\n next_again.stability = this.algorithm.init_stability(Rating.Again)\n\n next_hard.difficulty = this.algorithm.init_difficulty(Rating.Hard)\n next_hard.stability = this.algorithm.init_stability(Rating.Hard)\n\n next_good.difficulty = this.algorithm.init_difficulty(Rating.Good)\n next_good.stability = this.algorithm.init_stability(Rating.Good)\n\n next_easy.difficulty = this.algorithm.init_difficulty(Rating.Easy)\n next_easy.stability = this.algorithm.init_stability(Rating.Easy)\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/ts-fsrs/issues/98#issuecomment-2241923194\n */\n protected override learningState(grade: Grade): RecordLogItem {\n return this.reviewState(grade)\n }\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n next_again.stability = Math.min(\n stability,\n this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n )\n\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review/New next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let again_interval: int,\n hard_interval: int,\n good_interval: int,\n easy_interval: int\n again_interval = this.algorithm.next_interval(\n next_again.stability,\n interval\n )\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n easy_interval = this.algorithm.next_interval(next_easy.stability, interval)\n\n again_interval = Math.min(again_interval, hard_interval) as int\n hard_interval = Math.max(hard_interval, again_interval + 1) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n easy_interval = Math.max(easy_interval, good_interval + 1) as int\n\n next_again.scheduled_days = again_interval\n next_again.due = this.review_time.scheduler(again_interval, true)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review/New next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Review\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n\n private update_next(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n }\n}\n","import { TypeConvert } from './convert'\nimport { createEmptyCard } from './default'\nimport type { FSRS } from './fsrs'\nimport {\n type Card,\n type CardInput,\n DateInput,\n type FSRSHistory,\n type Grade,\n Rating,\n type RecordLogItem,\n type ReviewLog,\n State,\n} from './models'\n\n/**\n * The `Reschedule` class provides methods to handle the rescheduling of cards based on their review history.\n * determine the next review dates and update the card's state accordingly.\n */\nexport class Reschedule {\n private fsrs: FSRS\n /**\n * Creates an instance of the `Reschedule` class.\n * @param fsrs - An instance of the FSRS class used for scheduling.\n */\n constructor(fsrs: FSRS) {\n this.fsrs = fsrs\n }\n\n /**\n * Replays a review for a card and determines the next review date based on the given rating.\n * @param card - The card being reviewed.\n * @param reviewed - The date the card was reviewed.\n * @param rating - The grade given to the card during the review.\n * @returns A `RecordLogItem` containing the updated card and review log.\n */\n replay(card: Card, reviewed: Date, rating: Grade): RecordLogItem {\n return this.fsrs.next(card, reviewed, rating)\n }\n\n /**\n * Processes a manual review for a card, allowing for custom state, stability, difficulty, and due date.\n * @param card - The card being reviewed.\n * @param state - The state of the card after the review.\n * @param reviewed - The date the card was reviewed.\n * @param elapsed_days - The number of days since the last review.\n * @param stability - (Optional) The stability of the card.\n * @param difficulty - (Optional) The difficulty of the card.\n * @param due - (Optional) The due date for the next review.\n * @returns A `RecordLogItem` containing the updated card and review log.\n * @throws Will throw an error if the state or due date is not provided when required.\n */\n handleManualRating(\n card: Card,\n state: State,\n reviewed: Date,\n elapsed_days: number,\n stability?: number,\n difficulty?: number,\n due?: Date\n ): RecordLogItem {\n if (typeof state === 'undefined') {\n throw new Error('reschedule: state is required for manual rating')\n }\n let log: ReviewLog\n let next_card: Card\n if (<State>state === State.New) {\n log = {\n rating: Rating.Manual,\n state: state,\n due: <Date>due ?? reviewed,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: elapsed_days,\n last_elapsed_days: card.elapsed_days,\n scheduled_days: card.scheduled_days,\n review: <Date>reviewed,\n } satisfies ReviewLog\n next_card = createEmptyCard<Card>(reviewed)\n next_card.last_review = reviewed\n } else {\n if (typeof due === 'undefined') {\n throw new Error('reschedule: due is required for manual rating')\n }\n const scheduled_days = due.diff(reviewed as Date, 'days')\n log = {\n rating: Rating.Manual,\n state: <State>card.state,\n due: card.last_review || card.due,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: elapsed_days,\n last_elapsed_days: card.elapsed_days,\n scheduled_days: card.scheduled_days,\n review: <Date>reviewed,\n } satisfies ReviewLog\n next_card = {\n ...card,\n state: <State>state,\n due: <Date>due,\n last_review: <Date>reviewed,\n stability: stability || card.stability,\n difficulty: difficulty || card.difficulty,\n elapsed_days: elapsed_days,\n scheduled_days: scheduled_days,\n reps: card.reps + 1,\n } satisfies Card\n }\n\n return { card: next_card, log }\n }\n\n /**\n * Reschedules a card based on its review history.\n *\n * @param current_card - The card to be rescheduled.\n * @param reviews - An array of review history objects.\n * @returns An array of record log items representing the rescheduling process.\n */\n reschedule(current_card: CardInput, reviews: FSRSHistory[]) {\n const collections: RecordLogItem[] = []\n let cur_card = createEmptyCard<Card>(current_card.due)\n for (const review of reviews) {\n let item: RecordLogItem\n review.review = TypeConvert.time(review.review)\n if (review.rating === Rating.Manual) {\n // ref: abstract_scheduler.ts#init\n let interval = 0\n if (cur_card.state !== State.New && cur_card.last_review) {\n interval = review.review.diff(cur_card.last_review as Date, 'days')\n }\n item = this.handleManualRating(\n cur_card,\n review.state,\n review.review,\n interval,\n review.stability,\n review.difficulty,\n review.due ? TypeConvert.time(review.due) : undefined\n )\n } else {\n item = this.replay(cur_card, review.review, review.rating)\n }\n collections.push(item)\n cur_card = item.card\n }\n return collections\n }\n\n calculateManualRecord(\n current_card: CardInput,\n now: DateInput,\n record_log_item?: RecordLogItem,\n update_memory?: boolean\n ): RecordLogItem | null {\n if (!record_log_item) {\n return null\n }\n // if first_card === recordItem.card then return null\n const { card: reschedule_card, log } = record_log_item\n const cur_card = <Card>TypeConvert.card(current_card) // copy card\n if (cur_card.due.getTime() === reschedule_card.due.getTime()) {\n return null\n }\n cur_card.scheduled_days = reschedule_card.due.diff(\n cur_card.due as Date,\n 'days'\n )\n return this.handleManualRating(\n cur_card,\n reschedule_card.state,\n TypeConvert.time(now),\n log.elapsed_days,\n update_memory ? reschedule_card.stability : undefined,\n update_memory ? reschedule_card.difficulty : undefined,\n reschedule_card.due\n )\n }\n}\n","import {\n Card,\n CardInput,\n DateInput,\n FSRSHistory,\n FSRSParameters,\n Grade,\n Rating,\n RecordLogItem,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\nimport {\n type IPreview,\n type IReschedule,\n type RescheduleOptions,\n type IScheduler,\n} from './types'\nimport { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport BasicScheduler from './impl/basic_scheduler'\nimport LongTermScheduler from './impl/long_term_scheduler'\nimport { createEmptyCard } from './default'\nimport { Reschedule } from './reschedule'\nimport { DefaultInitSeedStrategy } from './strategies/seed'\nimport {\n StrategyMode,\n type TSeedStrategy,\n type TSchedulerStrategy,\n type TStrategyHandler,\n} from './strategies/types'\n\nexport class FSRS extends FSRSAlgorithm {\n private strategyHandler = new Map<StrategyMode, TStrategyHandler>()\n private Scheduler: TSchedulerStrategy\n constructor(param: Partial<FSRSParameters>) {\n super(param)\n const { enable_short_term } = this.parameters\n this.Scheduler = enable_short_term ? BasicScheduler : LongTermScheduler\n }\n\n protected override params_handler_proxy(): ProxyHandler<FSRSParameters> {\n const _this = this satisfies FSRS\n return {\n set: function (\n target: FSRSParameters,\n prop: keyof FSRSParameters,\n value: FSRSParameters[keyof FSRSParameters]\n ) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n } else if (prop === 'enable_short_term') {\n _this.Scheduler = value === true ? BasicScheduler : LongTermScheduler\n }\n Reflect.set(target, prop, value)\n return true\n },\n }\n }\n\n useStrategy<T extends StrategyMode>(\n mode: T,\n handler: TStrategyHandler<T>\n ): this {\n this.strategyHandler.set(mode, handler)\n return this\n }\n\n clearStrategy(mode?: StrategyMode): this {\n if (mode) {\n this.strategyHandler.delete(mode)\n } else {\n this.strategyHandler.clear()\n }\n return this\n }\n\n private getScheduler(card: CardInput | Card, now: DateInput): IScheduler {\n const seedStrategy = this.strategyHandler.get(StrategyMode.SEED) as\n | TSeedStrategy\n | undefined\n\n // Strategy scheduler\n const schedulerStrategy = this.strategyHandler.get(\n StrategyMode.SCHEDULER\n ) as TSchedulerStrategy | undefined\n\n const Scheduler = schedulerStrategy || this.Scheduler\n const Seed = seedStrategy || DefaultInitSeedStrategy\n const instance = new Scheduler(card, now, this, {\n seed: Seed,\n })\n\n return instance\n }\n\n /**\n * Display the collection of cards and logs for the four scenarios after scheduling the card at the current time.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date());\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n * function repeatAfterHandler(recordLog: RecordLog) {\n * const record: { [key in Grade]: RepeatRecordLog } = {} as {\n * [key in Grade]: RepeatRecordLog;\n * };\n * for (const grade of Grades) {\n * record[grade] = {\n * card: {\n * ...(recordLog[grade].card as Card & { cid: string }),\n * due: recordLog[grade].card.due.getTime(),\n * state: State[recordLog[grade].card.state] as StateType,\n * last_review: recordLog[grade].card.last_review\n * ? recordLog[grade].card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLog[grade].log,\n * cid: (recordLog[grade].card as Card & { cid: string }).cid,\n * due: recordLog[grade].log.due.getTime(),\n * review: recordLog[grade].log.review.getTime(),\n * state: State[recordLog[grade].log.state] as StateType,\n * rating: Rating[recordLog[grade].log.rating] as RatingType,\n * },\n * };\n * }\n * return record;\n * }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date(), repeatAfterHandler);\n * ```\n */\n repeat<R = IPreview>(\n card: CardInput | Card,\n now: DateInput,\n afterHandler?: (recordLog: IPreview) => R\n ): R {\n const instance = this.getScheduler(card, now)\n const recordLog = instance.preview()\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLog)\n } else {\n return recordLog as R\n }\n }\n\n /**\n * Display the collection of cards and logs for the card scheduled at the current time, after applying a specific grade rating.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param grade Rating of the review (Again, Hard, Good, Easy)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLogItem = f.next(card, new Date(), Rating.Again);\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface NextRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n function nextAfterHandler(recordLogItem: RecordLogItem) {\n const recordItem = {\n card: {\n ...(recordLogItem.card as Card & { cid: string }),\n due: recordLogItem.card.due.getTime(),\n state: State[recordLogItem.card.state] as StateType,\n last_review: recordLogItem.card.last_review\n ? recordLogItem.card.last_review!.getTime()\n : null,\n },\n log: {\n ...recordLogItem.log,\n cid: (recordLogItem.card as Card & { cid: string }).cid,\n due: recordLogItem.log.due.getTime(),\n review: recordLogItem.log.review.getTime(),\n state: State[recordLogItem.log.state] as StateType,\n rating: Rating[recordLogItem.log.rating] as RatingType,\n },\n };\n return recordItem\n }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLogItem = f.repeat(card, new Date(), Rating.Again, nextAfterHandler);\n * ```\n */\n next<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n grade: Grade,\n afterHandler?: (recordLog: RecordLogItem) => R\n ): R {\n const instance = this.getScheduler(card, now)\n const g = TypeConvert.rating(grade)\n if (g === Rating.Manual) {\n throw new Error('Cannot review a manual rating')\n }\n const recordLogItem = instance.review(g)\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n * Get the retrievability of the card\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param format default:true , Convert the result to another type. (Optional)\n * @returns The retrievability of the card,if format is true, the result is a string, otherwise it is a number\n */\n get_retrievability<T extends boolean>(\n card: CardInput | Card,\n now?: DateInput,\n format: T = true as T\n ): T extends true ? string : number {\n const processedCard = TypeConvert.card(card)\n now = now ? TypeConvert.time(now) : new Date()\n const t =\n processedCard.state !== State.New\n ? Math.max(now.diff(processedCard.last_review as Date, 'days'), 0)\n : 0\n const r =\n processedCard.state !== State.New\n ? this.forgetting_curve(t, +processedCard.stability.toFixed(8))\n : 0\n return (format ? `${(r * 100).toFixed(2)}%` : r) as T extends true\n ? string\n : number\n }\n\n /**\n *\n * @param card Card to be processed\n * @param log last review log\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now);\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now);\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log);\n * ```\n *\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);\n * ```\n */\n rollback<R = Card>(\n card: CardInput | Card,\n log: ReviewLogInput,\n afterHandler?: (prevCard: Card) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n const processedLog = TypeConvert.review_log(log)\n if (processedLog.rating === Rating.Manual) {\n throw new Error('Cannot rollback a manual rating')\n }\n let last_due, last_review, last_lapses\n switch (processedLog.state) {\n case State.New:\n last_due = processedLog.due\n last_review = undefined\n last_lapses = 0\n break\n case State.Learning:\n case State.Relearning:\n case State.Review:\n last_due = processedLog.review\n last_review = processedLog.due\n last_lapses =\n processedCard.lapses -\n (processedLog.rating === Rating.Again &&\n processedLog.state === State.Review\n ? 1\n : 0)\n break\n }\n\n const prevCard: Card = {\n ...processedCard,\n due: last_due,\n stability: processedLog.stability,\n difficulty: processedLog.difficulty,\n elapsed_days: processedLog.last_elapsed_days,\n scheduled_days: processedLog.scheduled_days,\n reps: Math.max(0, processedCard.reps - 1),\n lapses: Math.max(0, last_lapses),\n state: processedLog.state,\n last_review: last_review,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(prevCard)\n } else {\n return prevCard as R\n }\n }\n\n /**\n *\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param reset_count Should the review count information(reps,lapses) be reset. (Optional)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCard = createEmptyCard(now);\n * const scheduling_cards = f.repeat(emptyCard, now);\n * const { card, log } = scheduling_cards[Rating.Hard];\n * const forgetCard = f.forget(card, new Date(), true);\n * ```\n *\n * @example\n * ```\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked; //see method: fsrs.repeat()\n * }\n *\n * function forgetAfterHandler(recordLogItem: RecordLogItem): RepeatRecordLog {\n * return {\n * card: {\n * ...(recordLogItem.card as Card & { cid: string }),\n * due: recordLogItem.card.due.getTime(),\n * state: State[recordLogItem.card.state] as StateType,\n * last_review: recordLogItem.card.last_review\n * ? recordLogItem.card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLogItem.log,\n * cid: (recordLogItem.card as Card & { cid: string }).cid,\n * due: recordLogItem.log.due.getTime(),\n * review: recordLogItem.log.review.getTime(),\n * state: State[recordLogItem.log.state] as StateType,\n * rating: Rating[recordLogItem.log.rating] as RatingType,\n * },\n * };\n * }\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card } = repeatFormAfterHandler[Rating.Hard];\n * const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);\n * ```\n */\n forget<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n reset_count: boolean = false,\n afterHandler?: (recordLogItem: RecordLogItem) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n now = TypeConvert.time(now)\n const scheduled_days =\n processedCard.state === State.New\n ? 0\n : now.diff(processedCard.last_review as Date, 'days')\n const forget_log: ReviewLog = {\n rating: Rating.Manual,\n state: processedCard.state,\n due: processedCard.due,\n stability: processedCard.stability,\n difficulty: processedCard.difficulty,\n elapsed_days: 0,\n last_elapsed_days: processedCard.elapsed_days,\n scheduled_days: scheduled_days,\n review: now,\n }\n const forget_card: Card = {\n ...processedCard,\n due: now,\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: reset_count ? 0 : processedCard.reps,\n lapses: reset_count ? 0 : processedCard.lapses,\n state: State.New,\n last_review: processedCard.last_review,\n }\n const recordLogItem: RecordLogItem = { card: forget_card, log: forget_log }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n * Reschedules the current card and returns the rescheduled collections and reschedule item.\n *\n * @template T - The type of the record log item.\n * @param {CardInput | Card} current_card - The current card to be rescheduled.\n * @param {Array<FSRSHistory>} reviews - The array of FSRSHistory objects representing the reviews.\n * @param {Partial<RescheduleOptions<T>>} options - The optional reschedule options.\n * @returns {IReschedule<T>} - The rescheduled collections and reschedule item.\n * \n * @example\n * ```\n const f = fsrs()\n const grades: Grade[] = [Rating.Good, Rating.Good, Rating.Good, Rating.Good]\n const reviews_at = [\n new Date(2024, 8, 13),\n new Date(2024, 8, 13),\n new Date(2024, 8, 17),\n new Date(2024, 8, 28),\n ]\n\n const reviews: FSRSHistory[] = []\n for (let i = 0; i < grades.length; i++) {\n reviews.push({\n rating: grades[i],\n review: reviews_at[i],\n })\n }\n\n const results_short = scheduler.reschedule(\n createEmptyCard(),\n reviews,\n {\n skipManual: false,\n }\n )\n console.log(results_short)\n * ```\n */\n reschedule<T = RecordLogItem>(\n current_card: CardInput | Card,\n reviews: FSRSHistory[] = [],\n options: Partial<RescheduleOptions<T>> = {}\n ): IReschedule<T> {\n const {\n recordLogHandler,\n reviewsOrderBy,\n skipManual: skipManual = true,\n now: now = new Date(),\n update_memory_state: updateMemoryState = false,\n } = options\n if (reviewsOrderBy && typeof reviewsOrderBy === 'function') {\n reviews.sort(reviewsOrderBy)\n }\n if (skipManual) {\n reviews = reviews.filter((review) => review.rating !== Rating.Manual)\n }\n const rescheduleSvc = new Reschedule(this)\n\n const collections = rescheduleSvc.reschedule(\n options.first_card || createEmptyCard(),\n reviews\n )\n const len = collections.length\n const cur_card = TypeConvert.card(current_card)\n const manual_item = rescheduleSvc.calculateManualRecord(\n cur_card,\n now,\n len ? collections[len - 1] : undefined,\n updateMemoryState\n )\n\n if (recordLogHandler && typeof recordLogHandler === 'function') {\n return {\n collections: collections.map(recordLogHandler),\n reschedule_item: manual_item ? recordLogHandler(manual_item) : null,\n }\n }\n return {\n collections,\n reschedule_item: manual_item,\n } as IReschedule<T>\n }\n}\n\n/**\n * Create a new instance of TS-FSRS\n * @param params FSRSParameters\n * @example\n * ```typescript\n * const f = fsrs();\n * ```\n * @example\n * ```typescript\n * const params: FSRSParameters = generatorParameters({ maximum_interval: 1000 });\n * const f = fsrs(params);\n * ```\n * @example\n * ```typescript\n * const f = fsrs({ maximum_interval: 1000 });\n * ```\n */\nexport const fsrs = (params?: Partial<FSRSParameters>) => {\n return new FSRS(params || {})\n}\n"],"names":["State","t","Rating","e","TypeConvert","card","value","firstLetter","restOfString","ret","timestamp","log","default_request_retention","default_maximum_interval","default_w","default_enable_fuzz","default_enable_short_term","FSRSVersion","generatorParameters","props","w","createEmptyCard","now","afterHandler","emptyCard","isDay","date_scheduler","pre","unit","date_diff","formatDate","last_review","timeUnit","show_diff_message","fixDate","diff","r","dateInput","date","year","month","day","hours","minutes","seconds","padZero","num","TIMEUNIT","TIMEUNITFORMAT","due","i","fixState","fixRating","Grades","FUZZ_RANGES","get_fuzz_range","interval","elapsed_days","maximum_interval","delta","range","min_ivl","max_ivl","clamp","min","max","dateDiffInDays","last","cur","utc1","utc2","Alea","seed","mash","Mash","state","n","data","h","alea","xg","prng","DECAY","FACTOR","FSRSAlgorithm","params","request_retention","_this","target","prop","_params","key","paramKey","g","ivl","fuzz_factor","s","newInterval","delta_d","old_d","d","next_d","difficulty","init","current","hard_penalty","easy_bound","stability","DefaultInitSeedStrategy","time","reps","mul","GenSeedStrategyWithCardId","card_id_field","card_id","StrategyMode","AbstractScheduler","algorithm","strategies","grade","item","rating","BasicScheduler","exist","next","easy_interval","good_interval","good_stability","retrievability","next_again","next_hard","next_good","next_easy","item_again","item_hard","item_good","item_easy","nextSMin","hard_interval","LongTermScheduler","first_interval","again_interval","Reschedule","fsrs","reviewed","next_card","scheduled_days","current_card","reviews","collections","cur_card","review","record_log_item","update_memory","reschedule_card","FSRS","param","enable_short_term","mode","handler","seedStrategy","Scheduler","Seed","recordLog","instance","recordLogItem","format","processedCard","processedLog","last_due","last_lapses","prevCard","reset_count","forget_log","options","recordLogHandler","reviewsOrderBy","skipManual","updateMemoryState","rescheduleSvc","len","manual_item"],"mappings":"aAEO,IAAKA,GAAAA,IACVA,EAAAA,EAAA,IAAM,CAAN,EAAA,MACAA,IAAA,SAAW,CAAA,EAAX,WACAA,EAAAC,EAAA,OAAS,GAAT,SACAD,EAAAA,EAAA,WAAa,CAAb,EAAA,aAJUA,IAAAA,GASA,CAAA,CAAA,EAAAE,GAAAA,IACVA,EAAAA,EAAA,OAAS,CAAT,EAAA,SACAA,IAAA,MAAQ,CAAA,EAAR,QACAA,EAAAC,EAAA,KAAO,GAAP,OACAD,EAAAA,EAAA,KAAO,CAAP,EAAA,OACAA,IAAA,KAAO,CAAA,EAAP,OALUA,IAAAA,GAAA,CAAA,CAAA,ECDC,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,EAAKtE,GAAU,CAAE,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/fsrs/models.ts","../src/fsrs/convert.ts","../src/fsrs/default.ts","../src/fsrs/help.ts","../src/fsrs/alea.ts","../src/fsrs/algorithm.ts","../src/fsrs/strategies/seed.ts","../src/fsrs/strategies/types.ts","../src/fsrs/abstract_scheduler.ts","../src/fsrs/impl/basic_scheduler.ts","../src/fsrs/impl/long_term_scheduler.ts","../src/fsrs/reschedule.ts","../src/fsrs/fsrs.ts"],"sourcesContent":["export type StateType = 'New' | 'Learning' | 'Review' | 'Relearning'\n\nexport enum State {\n New = 0,\n Learning = 1,\n Review = 2,\n Relearning = 3,\n}\n\nexport type RatingType = 'Manual' | 'Again' | 'Hard' | 'Good' | 'Easy'\n\nexport enum Rating {\n Manual = 0,\n Again = 1,\n Hard = 2,\n Good = 3,\n Easy = 4,\n}\n\ntype ExcludeManual<T> = Exclude<T, Rating.Manual>\n\nexport type Grade = ExcludeManual<Rating>\n\nexport interface ReviewLog {\n rating: Rating // Rating of the review (Again, Hard, Good, Easy)\n state: State // State of the review (New, Learning, Review, Relearning)\n due: Date // Date of the last scheduling\n stability: number // Memory stability during the review\n difficulty: number // Difficulty of the card during the review\n elapsed_days: number // Number of days elapsed since the last review\n last_elapsed_days: number // Number of days between the last two reviews\n scheduled_days: number // Number of days until the next review\n review: Date // Date of the review\n}\n\nexport type RecordLogItem = {\n card: Card\n log: ReviewLog\n}\nexport type RecordLog = {\n [key in Grade]: RecordLogItem\n}\n\nexport interface Card {\n due: Date // Due date\n stability: number // Stability\n difficulty: number // Difficulty level\n elapsed_days: number // Number of days elapsed\n scheduled_days: number // Number of days scheduled\n reps: number // Repetition count\n lapses: number // Number of lapses or mistakes\n state: State // Card's state (New, Learning, Review, Relearning)\n last_review?: Date // Date of the last review (optional)\n}\n\nexport interface CardInput extends Omit<Card, 'state' | 'due' | 'last_review'> {\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n last_review?: DateInput | null // Date of the last review (optional)\n}\n\nexport type DateInput = Date | number | string\n\nexport interface ReviewLogInput\n extends Omit<ReviewLog, 'rating' | 'state' | 'due' | 'review'> {\n rating: RatingType | Rating // Rating of the review (Again, Hard, Good, Easy)\n state: StateType | State // Card's state (New, Learning, Review, Relearning)\n due: DateInput // Due date\n review: DateInput // Date of the last review\n}\n\nexport interface FSRSParameters {\n request_retention: number\n maximum_interval: number\n w: number[]\n enable_fuzz: boolean\n enable_short_term: boolean\n}\n\nexport interface FSRSReview {\n /**\n * 0-4: Manual, Again, Hard, Good, Easy\n * = revlog.rating\n */\n rating: Rating\n /**\n * The number of days that passed\n * = revlog.elapsed_days\n * = round(revlog[-1].review - revlog[-2].review)\n */\n delta_t: number\n}\n\nexport type FSRSHistory = Partial<\n Omit<ReviewLog, 'rating' | 'review' | 'elapsed_days'>\n> &\n (\n | {\n rating: Grade\n review: DateInput | Date\n }\n | {\n rating: Rating.Manual\n due: DateInput | Date\n state: State\n review: DateInput | Date\n }\n )\n\nexport interface FSRSState {\n stability: number\n difficulty: number\n}\n","import {\n Card,\n CardInput,\n DateInput,\n Rating,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\n\nexport class TypeConvert {\n static card<T extends Card | CardInput>(card: T): Card {\n return {\n ...card,\n state: TypeConvert.state(card.state),\n due: TypeConvert.time(card.due),\n last_review: card.last_review\n ? TypeConvert.time(card.last_review)\n : undefined,\n } as Card\n }\n static rating(value: unknown): Rating {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = Rating[`${firstLetter}${restOfString}` as keyof typeof Rating]\n if (ret === undefined) {\n throw new Error(`Invalid rating:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as Rating\n }\n throw new Error(`Invalid rating:[${value}]`)\n }\n static state(value: unknown): State {\n if (typeof value === 'string') {\n const firstLetter = value.charAt(0).toUpperCase()\n const restOfString = value.slice(1).toLowerCase()\n const ret = State[`${firstLetter}${restOfString}` as keyof typeof State]\n if (ret === undefined) {\n throw new Error(`Invalid state:[${value}]`)\n }\n return ret\n } else if (typeof value === 'number') {\n return value as State\n }\n throw new Error(`Invalid state:[${value}]`)\n }\n static time(value: unknown): Date {\n if (typeof value === 'object' && value instanceof Date) {\n return value\n } else if (typeof value === 'string') {\n const timestamp = Date.parse(value)\n if (!isNaN(timestamp)) {\n return new Date(timestamp)\n } else {\n throw new Error(`Invalid date:[${value}]`)\n }\n } else if (typeof value === 'number') {\n return new Date(value)\n }\n throw new Error(`Invalid date:[${value}]`)\n }\n static review_log(log: ReviewLogInput | ReviewLog): ReviewLog {\n return {\n ...log,\n due: TypeConvert.time(log.due),\n rating: TypeConvert.rating(log.rating),\n state: TypeConvert.state(log.state),\n review: TypeConvert.time(log.review),\n } satisfies ReviewLog\n }\n}\n","import { Card, DateInput, FSRSParameters, State } from './models'\nimport { TypeConvert } from './convert'\n\nexport const default_request_retention = 0.9\nexport const default_maximum_interval = 36500\nexport const default_w = [\n 0.40255, 1.18385, 3.173, 15.69105, 7.1949, 0.5345, 1.4604, 0.0046, 1.54575,\n 0.1192, 1.01925, 1.9395, 0.11, 0.29605, 2.2698, 0.2315, 2.9898, 0.51655,\n 0.6621,\n]\nexport const default_enable_fuzz = false\nexport const default_enable_short_term = true\n\nexport const FSRSVersion: string = 'v4.6.0 using FSRS-5.0'\n\nexport const generatorParameters = (\n props?: Partial<FSRSParameters>\n): FSRSParameters => {\n let w = default_w\n if (props?.w) {\n if (props.w.length === 19) {\n w = props?.w\n } else if (props.w.length === 17) {\n w = props?.w.concat([0.0, 0.0])\n w[4] = +(w[5] * 2.0 + w[4]).toFixed(8)\n w[5] = +(Math.log(w[5] * 3.0 + 1.0) / 3.0).toFixed(8)\n w[6] = +(w[6] + 0.5).toFixed(8)\n console.debug('[FSRS V5]auto fill w to 19 length')\n }\n }\n return {\n request_retention: props?.request_retention || default_request_retention,\n maximum_interval: props?.maximum_interval || default_maximum_interval,\n w: w,\n enable_fuzz: props?.enable_fuzz ?? default_enable_fuzz,\n enable_short_term: props?.enable_short_term ?? default_enable_short_term,\n } satisfies FSRSParameters\n}\n\n/**\n * Create an empty card\n * @param now Current time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * ```\n * @example\n * ```\n * interface CardUnChecked\n * extends Omit<Card, \"due\" | \"last_review\" | \"state\"> {\n * cid: string;\n * due: Date | number;\n * last_review: Date | null | number;\n * state: StateType;\n * }\n *\n * function cardAfterHandler(card: Card) {\n * return {\n * ...card,\n * cid: \"test001\",\n * state: State[card.state],\n * last_review: card.last_review ?? null,\n * } as CardUnChecked;\n * }\n *\n * const card: CardUnChecked = createEmptyCard(new Date(), cardAfterHandler);\n * ```\n */\nexport function createEmptyCard<R = Card>(\n now?: DateInput,\n afterHandler?: (card: Card) => R\n): R {\n const emptyCard: Card = {\n due: now ? TypeConvert.time(now) : new Date(),\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: 0,\n lapses: 0,\n state: State.New,\n last_review: undefined,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(emptyCard)\n } else {\n return emptyCard as R\n }\n}\n","import type { int, unit } from './types'\nimport type { DateInput, Grade } from './models'\nimport { Rating, State } from './models'\nimport { TypeConvert } from './convert'\n\ndeclare global {\n export interface Date {\n scheduler(t: int, isDay?: boolean): Date\n\n diff(pre: Date, unit: unit): int\n\n format(): string\n\n dueFormat(last_review: Date, unit?: boolean, timeUnit?: string[]): string\n }\n}\n\nDate.prototype.scheduler = function (t: int, isDay?: boolean): Date {\n return date_scheduler(this, t, isDay)\n}\n\n/**\n * 当前时间与之前的时间差值\n * @param pre 比当前时间还要之前\n * @param unit 单位: days | minutes\n */\nDate.prototype.diff = function (pre: Date, unit: unit): int {\n return date_diff(this, pre, unit) as int\n}\n\nDate.prototype.format = function (): string {\n return formatDate(this)\n}\n\nDate.prototype.dueFormat = function (\n last_review: Date,\n unit?: boolean,\n timeUnit?: string[]\n) {\n return show_diff_message(this, last_review, unit, timeUnit)\n}\n\n/**\n * 计算日期和时间的偏移,并返回一个新的日期对象。\n * @param now 当前日期和时间\n * @param t 时间偏移量,当 isDay 为 true 时表示天数,为 false 时表示分钟\n * @param isDay (可选)是否按天数单位进行偏移,默认为 false,表示按分钟单位计算偏移\n * @returns 偏移后的日期和时间对象\n */\nexport function date_scheduler(\n now: DateInput,\n t: number,\n isDay?: boolean\n): Date {\n return new Date(\n isDay\n ? fixDate(now).getTime() + t * 24 * 60 * 60 * 1000\n : fixDate(now).getTime() + t * 60 * 1000\n )\n}\n\nexport function date_diff(now: DateInput, pre: DateInput, unit: unit): number {\n if (!now || !pre) {\n throw new Error('Invalid date')\n }\n const diff = fixDate(now).getTime() - fixDate(pre).getTime()\n let r = 0\n switch (unit) {\n case 'days':\n r = Math.floor(diff / (24 * 60 * 60 * 1000))\n break\n case 'minutes':\n r = Math.floor(diff / (60 * 1000))\n break\n }\n return r\n}\n\nexport function formatDate(dateInput: DateInput): string {\n const date = fixDate(dateInput)\n const year: number = date.getFullYear()\n const month: number = date.getMonth() + 1\n const day: number = date.getDate()\n const hours: number = date.getHours()\n const minutes: number = date.getMinutes()\n const seconds: number = date.getSeconds()\n\n return `${year}-${padZero(month)}-${padZero(day)} ${padZero(hours)}:${padZero(\n minutes\n )}:${padZero(seconds)}`\n}\n\nfunction padZero(num: number): string {\n return num < 10 ? `0${num}` : `${num}`\n}\n\nconst TIMEUNIT = [60, 60, 24, 31, 12]\nconst TIMEUNITFORMAT = ['second', 'min', 'hour', 'day', 'month', 'year']\n\nexport function show_diff_message(\n due: DateInput,\n last_review: DateInput,\n unit?: boolean,\n timeUnit: string[] = TIMEUNITFORMAT\n): string {\n due = fixDate(due)\n last_review = fixDate(last_review)\n if (timeUnit.length !== TIMEUNITFORMAT.length) {\n timeUnit = TIMEUNITFORMAT\n }\n let diff = due.getTime() - last_review.getTime()\n let i\n diff /= 1000\n for (i = 0; i < TIMEUNIT.length; i++) {\n if (diff < TIMEUNIT[i]) {\n break\n } else {\n diff /= TIMEUNIT[i]\n }\n }\n return `${Math.floor(diff)}${unit ? timeUnit[i] : ''}`\n}\n\n/**\n *\n * @deprecated Use TypeConvert.time instead\n */\nexport function fixDate(value: unknown) {\n return TypeConvert.time(value)\n}\n\n/**\n * @deprecated Use TypeConvert.state instead\n */\nexport function fixState(value: unknown): State {\n return TypeConvert.state(value)\n}\n\n/**\n * @deprecated Use TypeConvert.rating instead\n */\nexport function fixRating(value: unknown): Rating {\n return TypeConvert.rating(value)\n}\n\nexport const Grades: Readonly<Grade[]> = [\n Rating.Again,\n Rating.Hard,\n Rating.Good,\n Rating.Easy,\n] as const\n\nconst FUZZ_RANGES = [\n {\n start: 2.5,\n end: 7.0,\n factor: 0.15,\n },\n {\n start: 7.0,\n end: 20.0,\n factor: 0.1,\n },\n {\n start: 20.0,\n end: Infinity,\n factor: 0.05,\n },\n] as const\n\nexport function get_fuzz_range(\n interval: number,\n elapsed_days: number,\n maximum_interval: number\n) {\n let delta = 1.0\n for (const range of FUZZ_RANGES) {\n delta +=\n range.factor * Math.max(Math.min(interval, range.end) - range.start, 0.0)\n }\n interval = Math.min(interval, maximum_interval)\n let min_ivl = Math.max(2, Math.round(interval - delta))\n const max_ivl = Math.min(Math.round(interval + delta), maximum_interval)\n if (interval > elapsed_days) {\n min_ivl = Math.max(min_ivl, elapsed_days + 1)\n }\n min_ivl = Math.min(min_ivl, max_ivl)\n return { min_ivl, max_ivl }\n}\n\nexport function clamp(value: number, min: number, max: number): number {\n return Math.min(Math.max(value, min), max)\n}\n\nexport function dateDiffInDays(last: Date, cur: Date) {\n // Discard the time and time-zone information.\n const utc1 = Date.UTC(\n last.getUTCFullYear(),\n last.getUTCMonth(),\n last.getUTCDate()\n )\n const utc2 = Date.UTC(\n cur.getUTCFullYear(),\n cur.getUTCMonth(),\n cur.getUTCDate()\n )\n\n return Math.floor((utc2 - utc1) / 86400000 /** 1000 * 60 * 60 * 24*/)\n}\n","// https://github.com/davidbau/seedrandom/blob/released/lib/alea.js\n// A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010\n// http://baagoe.com/en/RandomMusings/javascript/\n// https://github.com/nquinlan/better-random-numbers-for-javascript-mirror\n// Original work is under MIT license -\n\n// Copyright (C) 2010 by Johannes Baagøe <baagoe@baagoe.org>\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy\n// of this software and associated documentation files (the \"Software\"), to deal\n// in the Software without restriction, including without limitation the rights\n// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n// copies of the Software, and to permit persons to whom the Software is\n// furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n// THE SOFTWARE.\n\ntype State = {\n c: number\n s0: number\n s1: number\n s2: number\n}\n\nclass Alea {\n private c: number\n private s0: number\n private s1: number\n private s2: number\n\n constructor(seed?: number | string) {\n const mash = Mash()\n this.c = 1\n this.s0 = mash(' ')\n this.s1 = mash(' ')\n this.s2 = mash(' ')\n if (seed == null) seed = +new Date()\n this.s0 -= mash(seed)\n if (this.s0 < 0) this.s0 += 1\n this.s1 -= mash(seed)\n if (this.s1 < 0) this.s1 += 1\n this.s2 -= mash(seed)\n if (this.s2 < 0) this.s2 += 1\n }\n\n next(): number {\n const t = 2091639 * this.s0 + this.c * 2.3283064365386963e-10 // 2^-32\n this.s0 = this.s1\n this.s1 = this.s2\n this.s2 = t - (this.c = t | 0)\n return this.s2\n }\n\n set state(state: State) {\n this.c = state.c\n this.s0 = state.s0\n this.s1 = state.s1\n this.s2 = state.s2\n }\n\n get state(): State {\n return {\n c: this.c,\n s0: this.s0,\n s1: this.s1,\n s2: this.s2,\n }\n }\n}\n\nfunction Mash() {\n let n = 0xefc8249d\n return function mash(data: string | number): number {\n data = String(data)\n for (let i = 0; i < data.length; i++) {\n n += data.charCodeAt(i)\n let h = 0.02519603282416938 * n\n n = h >>> 0\n h -= n\n h *= n\n n = h >>> 0\n h -= n\n n += h * 0x100000000 // 2^32\n }\n return (n >>> 0) * 2.3283064365386963e-10 // 2^-32\n }\n}\n\nfunction alea(seed?: number | string) {\n const xg = new Alea(seed)\n const prng = () => xg.next()\n\n prng.int32 = () => (xg.next() * 0x100000000) | 0\n prng.double = () =>\n prng() + ((prng() * 0x200000) | 0) * 1.1102230246251565e-16 // 2^-53\n prng.state = () => xg.state\n prng.importState = (state: State) => {\n xg.state = state\n return prng\n }\n return prng\n}\n\nexport { alea }\n","import { generatorParameters } from './default'\nimport { FSRSParameters, FSRSState, Grade, Rating } from './models'\nimport type { int } from './types'\nimport { clamp, get_fuzz_range } from './help'\nimport { alea } from './alea'\n\n/**\n * @default DECAY = -0.5\n */\nexport const DECAY: number = -0.5\n/**\n * FACTOR = Math.pow(0.9, 1 / DECAY) - 1= 19 / 81\n *\n * $$\\text{FACTOR} = \\frac{19}{81}$$\n * @default FACTOR = 19 / 81\n */\nexport const FACTOR: number = 19 / 81\n\n/**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n */\nexport class FSRSAlgorithm {\n protected param!: FSRSParameters\n protected intervalModifier!: number\n protected _seed?: string\n\n constructor(params: Partial<FSRSParameters>) {\n this.param = new Proxy(\n generatorParameters(params),\n this.params_handler_proxy()\n )\n this.intervalModifier = this.calculate_interval_modifier(\n this.param.request_retention\n )\n }\n\n get interval_modifier(): number {\n return this.intervalModifier\n }\n\n set seed(seed: string) {\n this._seed = seed\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/wiki/The-Algorithm#fsrs-45\n *\n * The formula used is: $$I(r,s) = (r^{\\frac{1}{DECAY}} - 1) / FACTOR \\times s$$\n * @param request_retention 0<request_retention<=1,Requested retention rate\n * @throws {Error} Requested retention rate should be in the range (0,1]\n */\n calculate_interval_modifier(request_retention: number): number {\n if (request_retention <= 0 || request_retention > 1) {\n throw new Error('Requested retention rate should be in the range (0,1]')\n }\n return +((Math.pow(request_retention, 1 / DECAY) - 1) / FACTOR).toFixed(8)\n }\n\n /**\n * Get the parameters of the algorithm.\n */\n get parameters(): FSRSParameters {\n return this.param\n }\n\n /**\n * Set the parameters of the algorithm.\n * @param params Partial<FSRSParameters>\n */\n set parameters(params: Partial<FSRSParameters>) {\n this.update_parameters(params)\n }\n\n protected params_handler_proxy(): ProxyHandler<FSRSParameters> {\n const _this = this satisfies FSRSAlgorithm\n return {\n set: function (\n target: FSRSParameters,\n prop: keyof FSRSParameters,\n value: FSRSParameters[keyof FSRSParameters]\n ) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n }\n Reflect.set(target, prop, value)\n return true\n },\n }\n }\n\n private update_parameters(params: Partial<FSRSParameters>): void {\n const _params = generatorParameters(params)\n for (const key in _params) {\n if (key in this.param) {\n const paramKey = key as keyof FSRSParameters\n this.param[paramKey] = _params[paramKey] as never\n }\n }\n }\n\n /**\n * The formula used is :\n * $$ S_0(G) = w_{G-1}$$\n * $$S_0 = \\max \\lbrace S_0,0.1\\rbrace $$\n\n * @param g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return Stability (interval when R=90%)\n */\n init_stability(g: Grade): number {\n return Math.max(this.param.w[g - 1], 0.1)\n }\n\n /**\n * The formula used is :\n * $$D_0(G) = w_4 - e^{(G-1) \\cdot w_5} + 1 $$\n * $$D_0 = \\min \\lbrace \\max \\lbrace D_0(G),1 \\rbrace,10 \\rbrace$$\n * where the $$D_0(1)=w_4$$ when the first rating is good.\n *\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} Difficulty $$D \\in [1,10]$$\n */\n init_difficulty(g: Grade): number {\n return this.constrain_difficulty(\n this.param.w[4] - Math.exp((g - 1) * this.param.w[5]) + 1\n )\n }\n\n /**\n * If fuzzing is disabled or ivl is less than 2.5, it returns the original interval.\n * @param {number} ivl - The interval to be fuzzed.\n * @param {number} elapsed_days t days since the last review\n * @return {number} - The fuzzed interval.\n **/\n apply_fuzz(ivl: number, elapsed_days: number): int {\n if (!this.param.enable_fuzz || ivl < 2.5) return Math.round(ivl) as int\n const generator = alea(this._seed) // I do not want others to directly access the seed externally.\n const fuzz_factor = generator()\n const { min_ivl, max_ivl } = get_fuzz_range(\n ivl,\n elapsed_days,\n this.param.maximum_interval\n )\n return Math.floor(fuzz_factor * (max_ivl - min_ivl + 1) + min_ivl) as int\n }\n\n /**\n * @see The formula used is : {@link FSRSAlgorithm.calculate_interval_modifier}\n * @param {number} s - Stability (interval when R=90%)\n * @param {number} elapsed_days t days since the last review\n */\n next_interval(s: number, elapsed_days: number): int {\n const newInterval = Math.min(\n Math.max(1, Math.round(s * this.intervalModifier)),\n this.param.maximum_interval\n ) as int\n return this.apply_fuzz(newInterval, elapsed_days)\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/fsrs4anki/issues/697\n */\n linear_damping(delta_d: number, old_d: number): number {\n return +(delta_d * (10 - old_d) / 9).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$\\text{delta}_d = -w_6 \\cdot (g - 3)$$\n * $$\\text{next}_d = D + \\text{linear damping}(\\text{delta}_d , D)$$\n * $$D^\\prime(D,R) = w_7 \\cdot D_0(4) +(1 - w_7) \\cdot \\text{next}_d$$\n * @param {number} d Difficulty $$D \\in [1,10]$$\n * @param {Grade} g Grade (rating at Anki) [1.again,2.hard,3.good,4.easy]\n * @return {number} $$\\text{next}_D$$\n */\n next_difficulty(d: number, g: Grade): number {\n const delta_d = -this.param.w[6] * (g - 3)\n const next_d = d + this.linear_damping(delta_d, d)\n return this.constrain_difficulty(\n this.mean_reversion(this.init_difficulty(Rating.Easy), next_d)\n )\n }\n\n /**\n * The formula used is :\n * $$\\min \\lbrace \\max \\lbrace D_0,1 \\rbrace,10\\rbrace$$\n * @param {number} difficulty $$D \\in [1,10]$$\n */\n constrain_difficulty(difficulty: number): number {\n return Math.min(Math.max(+difficulty.toFixed(8), 1), 10)\n }\n\n /**\n * The formula used is :\n * $$w_7 \\cdot \\text{init} +(1 - w_7) \\cdot \\text{current}$$\n * @param {number} init $$w_2 : D_0(3) = w_2 + (R-2) \\cdot w_3= w_2$$\n * @param {number} current $$D - w_6 \\cdot (R - 2)$$\n * @return {number} difficulty\n */\n mean_reversion(init: number, current: number): number {\n return +(this.param.w[7] * init + (1 - this.param.w[7]) * current).toFixed(\n 8\n )\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_r(D,S,R,G) = S\\cdot(e^{w_8}\\cdot (11-D)\\cdot S^{-w_9}\\cdot(e^{w_{10}\\cdot(1-R)}-1)\\cdot w_{15}(\\text{if} G=2) \\cdot w_{16}(\\text{if} G=4)+1)$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n * @return {number} S^\\prime_r new stability after recall\n */\n next_recall_stability(d: number, s: number, r: number, g: Grade): number {\n const hard_penalty = Rating.Hard === g ? this.param.w[15] : 1\n const easy_bound = Rating.Easy === g ? this.param.w[16] : 1\n return +clamp(\n s *\n (1 +\n Math.exp(this.param.w[8]) *\n (11 - d) *\n Math.pow(s, -this.param.w[9]) *\n (Math.exp((1 - r) * this.param.w[10]) - 1) *\n hard_penalty *\n easy_bound),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_f(D,S,R) = w_{11}\\cdot D^{-w_{12}}\\cdot ((S+1)^{w_{13}}-1) \\cdot e^{w_{14}\\cdot(1-R)}$$\n * enable_short_term = true : $$S^\\prime_f \\in \\min \\lbrace \\max \\lbrace S^\\prime_f,0.01\\rbrace, \\frac{S}{e^{w_{17} \\cdot w_{18}}} \\rbrace$$\n * enable_short_term = false : $$S^\\prime_f \\in \\min \\lbrace \\max \\lbrace S^\\prime_f,0.01\\rbrace, S \\rbrace$$\n * @param {number} d Difficulty D \\in [1,10]\n * @param {number} s Stability (interval when R=90%)\n * @param {number} r Retrievability (probability of recall)\n * @return {number} S^\\prime_f new stability after forgetting\n */\n next_forget_stability(d: number, s: number, r: number): number {\n return +clamp(\n this.param.w[11] *\n Math.pow(d, -this.param.w[12]) *\n (Math.pow(s + 1, this.param.w[13]) - 1) *\n Math.exp((1 - r) * this.param.w[14]),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$S^\\prime_s(S,G) = S \\cdot e^{w_{17} \\cdot (G-3+w_{18})}$$\n * @param {number} s Stability (interval when R=90%)\n * @param {Grade} g Grade (Rating[0.again,1.hard,2.good,3.easy])\n */\n next_short_term_stability(s: number, g: Grade): number {\n return +clamp(\n s * Math.exp(this.param.w[17] * (g - 3 + this.param.w[18])),\n 0.01,\n 36500.0\n ).toFixed(8)\n }\n\n /**\n * The formula used is :\n * $$R(t,S) = (1 + \\text{FACTOR} \\times \\frac{t}{9 \\cdot S})^{\\text{DECAY}}$$\n * @param {number} elapsed_days t days since the last review\n * @param {number} stability Stability (interval when R=90%)\n * @return {number} r Retrievability (probability of recall)\n */\n forgetting_curve(elapsed_days: number, stability: number): number {\n return +Math.pow(1 + (FACTOR * elapsed_days) / stability, DECAY).toFixed(8)\n }\n\n /**\n * Calculates the next state of memory based on the current state, time elapsed, and grade.\n *\n * @param memory_state - The current state of memory, which can be null.\n * @param t - The time elapsed since the last review.\n * @param {Rating} g Grade (Rating[0.Manual,1.Again,2.Hard,3.Good,4.Easy])\n * @returns The next state of memory with updated difficulty and stability.\n */\n next_state(memory_state: FSRSState | null, t: number, g: number): FSRSState {\n const { difficulty: d, stability: s } = memory_state ?? {\n difficulty: 0,\n stability: 0,\n }\n if (t < 0) {\n throw new Error(`Invalid delta_t \"${t}\"`)\n }\n if (g < 0 || g > 4) {\n throw new Error(`Invalid grade \"${g}\"`)\n }\n if (d === 0 && s === 0) {\n return {\n difficulty: this.init_difficulty(g),\n stability: this.init_stability(g),\n }\n }\n if (g === 0) {\n return {\n difficulty: d,\n stability: s,\n }\n }\n if (d < 1 || s < 0.01) {\n throw new Error(`Invalid memory state { difficulty: ${d}, stability: ${s} }`)\n }\n const r = this.forgetting_curve(t, s)\n const s_after_success = this.next_recall_stability(d, s, r, g)\n const s_after_fail = this.next_forget_stability(d, s, r)\n const s_after_short_term = this.next_short_term_stability(s, g)\n let new_s = s_after_success\n if (g === 1) {\n let [w_17, w_18] = [0, 0]\n if (this.param.enable_short_term) {\n w_17 = this.param.w[17]\n w_18 = this.param.w[18]\n }\n const next_s_min = s / Math.exp(w_17 * w_18)\n new_s = clamp(next_s_min, 0.01, s_after_fail)\n }\n if (t === 0 && this.param.enable_short_term) {\n new_s = s_after_short_term\n }\n\n const new_d = this.next_difficulty(d, g)\n return { difficulty: new_d, stability: new_s }\n }\n}\n","import type { AbstractScheduler } from '../abstract_scheduler'\nimport type { TSeedStrategy } from './types'\n\nexport function DefaultInitSeedStrategy(this: AbstractScheduler): string {\n const time = this.review_time.getTime()\n const reps = this.current.reps\n const mul = this.current.difficulty * this.current.stability\n return `${time}_${reps}_${mul}`\n}\n\n/**\n * Generates a seed strategy function for card IDs.\n *\n * @param card_id_field - The field name of the card ID in the current object.\n * @returns A function that generates a seed based on the card ID and repetitions.\n *\n * @remarks\n * The returned function uses the `card_id_field` to retrieve the card ID from the current object.\n * It then adds the number of repetitions (`reps`) to the card ID to generate the seed.\n *\n * @example\n * ```typescript\n * const seedStrategy = GenCardIdSeedStrategy('card_id');\n * const f = fsrs().useStrategy(StrategyMode.SEED, seedStrategy)\n * const card = createEmptyCard<Card & { card_id: number }>()\n * card.card_id = 555\n * const record = f.repeat(card, new Date())\n * ```\n */\nexport function GenSeedStrategyWithCardId(\n card_id_field: string | number\n): TSeedStrategy {\n return function (this: AbstractScheduler): string {\n // https://github.com/open-spaced-repetition/ts-fsrs/issues/131#issuecomment-2408426225\n const card_id = Reflect.get(this.current, card_id_field) ?? 0\n const reps = this.current.reps\n // ex1\n // card_id:string + reps:number = 'e2ecb1f7-8d15-420b-bec4-c7212ad2e5dc' + 4\n // = 'e2ecb1f7-8d15-420b-bec4-c7212ad2e5dc4'\n\n // ex2\n // card_id:number + reps:number = 1732452519198 + 4\n // = '17324525191984'\n return String(card_id + reps || 0)\n }\n}\n","import type { AbstractScheduler } from '../abstract_scheduler'\nimport type { FSRSAlgorithm } from '../algorithm'\nimport type { Card, CardInput, DateInput } from '../models'\nimport type { IScheduler } from '../types'\n\nexport enum StrategyMode {\n SCHEDULER = 'Scheduler',\n SEED = 'Seed',\n}\n\nexport type TSeedStrategy = (this: AbstractScheduler) => string\nexport type TSchedulerStrategy<T extends CardInput | Card = CardInput | Card> =\n new (\n card: T,\n now: DateInput,\n algorithm: FSRSAlgorithm,\n strategies: { seed: TSeedStrategy }\n ) => IScheduler\n\nexport type TStrategyHandler<E = StrategyMode> =\n E extends StrategyMode.SCHEDULER\n ? TSchedulerStrategy\n : E extends StrategyMode.SEED\n ? TSeedStrategy\n : never\n","import { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport { dateDiffInDays, Grades } from './help'\nimport {\n type Card,\n type Grade,\n type RecordLogItem,\n State,\n Rating,\n type ReviewLog,\n type CardInput,\n type DateInput,\n} from './models'\nimport { DefaultInitSeedStrategy } from './strategies'\nimport type { TSeedStrategy } from './strategies/types'\nimport type { IPreview, IScheduler } from './types'\n\nexport abstract class AbstractScheduler implements IScheduler {\n protected last: Card\n protected current: Card\n protected review_time: Date\n protected next: Map<Grade, RecordLogItem> = new Map()\n protected algorithm: FSRSAlgorithm\n private initSeedStrategy: TSeedStrategy\n\n constructor(\n card: CardInput | Card,\n now: DateInput,\n algorithm: FSRSAlgorithm,\n strategies: {\n seed: TSeedStrategy\n } = {\n seed: DefaultInitSeedStrategy,\n }\n ) {\n this.algorithm = algorithm\n this.initSeedStrategy = strategies.seed.bind(this)\n\n this.last = TypeConvert.card(card)\n this.current = TypeConvert.card(card)\n this.review_time = TypeConvert.time(now)\n this.init()\n }\n\n private init() {\n const { state, last_review } = this.current\n let interval = 0 // card.state === State.New => 0\n if (state !== State.New && last_review) {\n interval = dateDiffInDays(last_review, this.review_time)\n }\n this.current.last_review = this.review_time\n this.current.elapsed_days = interval\n this.current.reps += 1\n this.algorithm.seed = this.initSeedStrategy()\n }\n\n public preview(): IPreview {\n return {\n [Rating.Again]: this.review(Rating.Again),\n [Rating.Hard]: this.review(Rating.Hard),\n [Rating.Good]: this.review(Rating.Good),\n [Rating.Easy]: this.review(Rating.Easy),\n [Symbol.iterator]: this.previewIterator.bind(this),\n } satisfies IPreview\n }\n\n private *previewIterator(): IterableIterator<RecordLogItem> {\n for (const grade of Grades) {\n yield this.review(grade)\n }\n }\n\n public review(grade: Grade): RecordLogItem {\n const { state } = this.last\n let item: RecordLogItem | undefined\n switch (state) {\n case State.New:\n item = this.newState(grade)\n break\n case State.Learning:\n case State.Relearning:\n item = this.learningState(grade)\n break\n case State.Review:\n item = this.reviewState(grade)\n break\n }\n if (item) {\n return item\n }\n throw new Error('Invalid grade')\n }\n\n protected abstract newState(grade: Grade): RecordLogItem\n\n protected abstract learningState(grade: Grade): RecordLogItem\n\n protected abstract reviewState(grade: Grade): RecordLogItem\n\n protected buildLog(rating: Grade): ReviewLog {\n const { last_review, due, elapsed_days } = this.last\n\n return {\n rating: rating,\n state: this.current.state,\n due: last_review || due,\n stability: this.current.stability,\n difficulty: this.current.difficulty,\n elapsed_days: this.current.elapsed_days,\n last_elapsed_days: elapsed_days,\n scheduled_days: this.current.scheduled_days,\n review: this.review_time,\n } satisfies ReviewLog\n }\n}\n","import { AbstractScheduler } from '../abstract_scheduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class BasicScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const next = TypeConvert.card(this.current)\n next.difficulty = this.algorithm.init_difficulty(grade)\n next.stability = this.algorithm.init_stability(grade)\n\n switch (grade) {\n case Rating.Again:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(1 as int)\n next.state = State.Learning\n break\n case Rating.Hard:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int)\n next.state = State.Learning\n break\n case Rating.Good:\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = State.Learning\n break\n case Rating.Easy: {\n const easy_interval = this.algorithm.next_interval(\n next.stability,\n this.current.elapsed_days\n )\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override learningState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const { state, difficulty, stability } = this.last\n const next = TypeConvert.card(this.current)\n const interval = this.current.elapsed_days\n next.difficulty = this.algorithm.next_difficulty(difficulty, grade)\n next.stability = this.algorithm.next_short_term_stability(stability, grade)\n\n switch (grade) {\n case Rating.Again: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(5 as int, false)\n next.state = state\n break\n }\n case Rating.Hard: {\n next.scheduled_days = 0\n next.due = this.review_time.scheduler(10 as int)\n next.state = state\n break\n }\n case Rating.Good: {\n const good_interval = this.algorithm.next_interval(\n next.stability,\n interval\n )\n next.scheduled_days = good_interval\n next.due = this.review_time.scheduler(good_interval as int, true)\n next.state = State.Review\n break\n }\n case Rating.Easy: {\n const good_stability = this.algorithm.next_short_term_stability(\n stability,\n Rating.Good\n )\n const good_interval = this.algorithm.next_interval(\n good_stability,\n interval\n )\n const easy_interval = Math.max(\n this.algorithm.next_interval(next.stability, interval),\n good_interval + 1\n ) as int\n next.scheduled_days = easy_interval\n next.due = this.review_time.scheduler(easy_interval as int, true)\n next.state = State.Review\n break\n }\n default:\n throw new Error('Invalid grade')\n }\n const item = {\n card: next,\n log: this.buildLog(grade),\n } satisfies RecordLogItem\n this.next.set(grade, item)\n return item\n }\n\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n const nextSMin =\n stability /\n Math.exp(\n this.algorithm.parameters.w[17] * this.algorithm.parameters.w[18]\n )\n next_again.stability = Math.min(\n +nextSMin.toFixed(8),\n this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n )\n\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let hard_interval: int, good_interval: int\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n hard_interval = Math.min(hard_interval, good_interval) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n const easy_interval = Math.max(\n this.algorithm.next_interval(next_easy.stability, interval),\n good_interval + 1\n ) as int\n next_again.scheduled_days = 0\n next_again.due = this.review_time.scheduler(5 as int)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Relearning\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n}\n","import { AbstractScheduler } from '../abstract_scheduler'\nimport { TypeConvert } from '../convert'\nimport {\n type Card,\n type Grade,\n Rating,\n type RecordLogItem,\n State,\n} from '../models'\nimport type { int } from '../types'\n\nexport default class LongTermScheduler extends AbstractScheduler {\n protected override newState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n\n this.current.scheduled_days = 0\n this.current.elapsed_days = 0\n\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.init_ds(next_again, next_hard, next_good, next_easy)\n const first_interval = 0\n\n this.next_interval(\n next_again,\n next_hard,\n next_good,\n next_easy,\n first_interval\n )\n\n this.next_state(next_again, next_hard, next_good, next_easy)\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n private init_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ): void {\n next_again.difficulty = this.algorithm.init_difficulty(Rating.Again)\n next_again.stability = this.algorithm.init_stability(Rating.Again)\n\n next_hard.difficulty = this.algorithm.init_difficulty(Rating.Hard)\n next_hard.stability = this.algorithm.init_stability(Rating.Hard)\n\n next_good.difficulty = this.algorithm.init_difficulty(Rating.Good)\n next_good.stability = this.algorithm.init_stability(Rating.Good)\n\n next_easy.difficulty = this.algorithm.init_difficulty(Rating.Easy)\n next_easy.stability = this.algorithm.init_stability(Rating.Easy)\n }\n\n /**\n * @see https://github.com/open-spaced-repetition/ts-fsrs/issues/98#issuecomment-2241923194\n */\n protected override learningState(grade: Grade): RecordLogItem {\n return this.reviewState(grade)\n }\n protected override reviewState(grade: Grade): RecordLogItem {\n const exist = this.next.get(grade)\n if (exist) {\n return exist\n }\n const interval = this.current.elapsed_days\n const { difficulty, stability } = this.last\n const retrievability = this.algorithm.forgetting_curve(interval, stability)\n const next_again = TypeConvert.card(this.current)\n const next_hard = TypeConvert.card(this.current)\n const next_good = TypeConvert.card(this.current)\n const next_easy = TypeConvert.card(this.current)\n\n this.next_ds(\n next_again,\n next_hard,\n next_good,\n next_easy,\n difficulty,\n stability,\n retrievability\n )\n\n this.next_interval(next_again, next_hard, next_good, next_easy, interval)\n this.next_state(next_again, next_hard, next_good, next_easy)\n next_again.lapses += 1\n\n this.update_next(next_again, next_hard, next_good, next_easy)\n return this.next.get(grade)!\n }\n\n /**\n * Review next_ds\n */\n private next_ds(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n difficulty: number,\n stability: number,\n retrievability: number\n ): void {\n next_again.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Again\n )\n next_again.stability = Math.min(\n stability,\n this.algorithm.next_forget_stability(\n difficulty,\n stability,\n retrievability\n )\n )\n\n next_hard.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Hard\n )\n next_hard.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Hard\n )\n next_good.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Good\n )\n next_good.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Good\n )\n next_easy.difficulty = this.algorithm.next_difficulty(\n difficulty,\n Rating.Easy\n )\n next_easy.stability = this.algorithm.next_recall_stability(\n difficulty,\n stability,\n retrievability,\n Rating.Easy\n )\n }\n\n /**\n * Review/New next_interval\n */\n private next_interval(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card,\n interval: number\n ): void {\n let again_interval: int,\n hard_interval: int,\n good_interval: int,\n easy_interval: int\n again_interval = this.algorithm.next_interval(\n next_again.stability,\n interval\n )\n hard_interval = this.algorithm.next_interval(next_hard.stability, interval)\n good_interval = this.algorithm.next_interval(next_good.stability, interval)\n easy_interval = this.algorithm.next_interval(next_easy.stability, interval)\n\n again_interval = Math.min(again_interval, hard_interval) as int\n hard_interval = Math.max(hard_interval, again_interval + 1) as int\n good_interval = Math.max(good_interval, hard_interval + 1) as int\n easy_interval = Math.max(easy_interval, good_interval + 1) as int\n\n next_again.scheduled_days = again_interval\n next_again.due = this.review_time.scheduler(again_interval, true)\n\n next_hard.scheduled_days = hard_interval\n next_hard.due = this.review_time.scheduler(hard_interval, true)\n\n next_good.scheduled_days = good_interval\n next_good.due = this.review_time.scheduler(good_interval, true)\n\n next_easy.scheduled_days = easy_interval\n next_easy.due = this.review_time.scheduler(easy_interval, true)\n }\n\n /**\n * Review/New next_state\n */\n private next_state(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n next_again.state = State.Review\n // next_again.lapses += 1\n\n next_hard.state = State.Review\n\n next_good.state = State.Review\n\n next_easy.state = State.Review\n }\n\n private update_next(\n next_again: Card,\n next_hard: Card,\n next_good: Card,\n next_easy: Card\n ) {\n const item_again = {\n card: next_again,\n log: this.buildLog(Rating.Again),\n } satisfies RecordLogItem\n const item_hard = {\n card: next_hard,\n log: super.buildLog(Rating.Hard),\n } satisfies RecordLogItem\n const item_good = {\n card: next_good,\n log: super.buildLog(Rating.Good),\n } satisfies RecordLogItem\n const item_easy = {\n card: next_easy,\n log: super.buildLog(Rating.Easy),\n } satisfies RecordLogItem\n\n this.next.set(Rating.Again, item_again)\n this.next.set(Rating.Hard, item_hard)\n this.next.set(Rating.Good, item_good)\n this.next.set(Rating.Easy, item_easy)\n }\n}\n","import { TypeConvert } from './convert'\nimport { createEmptyCard } from './default'\nimport type { FSRS } from './fsrs'\nimport {\n type Card,\n type CardInput,\n DateInput,\n type FSRSHistory,\n type Grade,\n Rating,\n type RecordLogItem,\n type ReviewLog,\n State,\n} from './models'\n\n/**\n * The `Reschedule` class provides methods to handle the rescheduling of cards based on their review history.\n * determine the next review dates and update the card's state accordingly.\n */\nexport class Reschedule {\n private fsrs: FSRS\n /**\n * Creates an instance of the `Reschedule` class.\n * @param fsrs - An instance of the FSRS class used for scheduling.\n */\n constructor(fsrs: FSRS) {\n this.fsrs = fsrs\n }\n\n /**\n * Replays a review for a card and determines the next review date based on the given rating.\n * @param card - The card being reviewed.\n * @param reviewed - The date the card was reviewed.\n * @param rating - The grade given to the card during the review.\n * @returns A `RecordLogItem` containing the updated card and review log.\n */\n replay(card: Card, reviewed: Date, rating: Grade): RecordLogItem {\n return this.fsrs.next(card, reviewed, rating)\n }\n\n /**\n * Processes a manual review for a card, allowing for custom state, stability, difficulty, and due date.\n * @param card - The card being reviewed.\n * @param state - The state of the card after the review.\n * @param reviewed - The date the card was reviewed.\n * @param elapsed_days - The number of days since the last review.\n * @param stability - (Optional) The stability of the card.\n * @param difficulty - (Optional) The difficulty of the card.\n * @param due - (Optional) The due date for the next review.\n * @returns A `RecordLogItem` containing the updated card and review log.\n * @throws Will throw an error if the state or due date is not provided when required.\n */\n handleManualRating(\n card: Card,\n state: State,\n reviewed: Date,\n elapsed_days: number,\n stability?: number,\n difficulty?: number,\n due?: Date\n ): RecordLogItem {\n if (typeof state === 'undefined') {\n throw new Error('reschedule: state is required for manual rating')\n }\n let log: ReviewLog\n let next_card: Card\n if (<State>state === State.New) {\n log = {\n rating: Rating.Manual,\n state: state,\n due: <Date>due ?? reviewed,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: elapsed_days,\n last_elapsed_days: card.elapsed_days,\n scheduled_days: card.scheduled_days,\n review: <Date>reviewed,\n } satisfies ReviewLog\n next_card = createEmptyCard<Card>(reviewed)\n next_card.last_review = reviewed\n } else {\n if (typeof due === 'undefined') {\n throw new Error('reschedule: due is required for manual rating')\n }\n const scheduled_days = due.diff(reviewed as Date, 'days')\n log = {\n rating: Rating.Manual,\n state: <State>card.state,\n due: card.last_review || card.due,\n stability: card.stability,\n difficulty: card.difficulty,\n elapsed_days: elapsed_days,\n last_elapsed_days: card.elapsed_days,\n scheduled_days: card.scheduled_days,\n review: <Date>reviewed,\n } satisfies ReviewLog\n next_card = {\n ...card,\n state: <State>state,\n due: <Date>due,\n last_review: <Date>reviewed,\n stability: stability || card.stability,\n difficulty: difficulty || card.difficulty,\n elapsed_days: elapsed_days,\n scheduled_days: scheduled_days,\n reps: card.reps + 1,\n } satisfies Card\n }\n\n return { card: next_card, log }\n }\n\n /**\n * Reschedules a card based on its review history.\n *\n * @param current_card - The card to be rescheduled.\n * @param reviews - An array of review history objects.\n * @returns An array of record log items representing the rescheduling process.\n */\n reschedule(current_card: CardInput, reviews: FSRSHistory[]) {\n const collections: RecordLogItem[] = []\n let cur_card = createEmptyCard<Card>(current_card.due)\n for (const review of reviews) {\n let item: RecordLogItem\n review.review = TypeConvert.time(review.review)\n if (review.rating === Rating.Manual) {\n // ref: abstract_scheduler.ts#init\n let interval = 0\n if (cur_card.state !== State.New && cur_card.last_review) {\n interval = review.review.diff(cur_card.last_review as Date, 'days')\n }\n item = this.handleManualRating(\n cur_card,\n review.state,\n review.review,\n interval,\n review.stability,\n review.difficulty,\n review.due ? TypeConvert.time(review.due) : undefined\n )\n } else {\n item = this.replay(cur_card, review.review, review.rating)\n }\n collections.push(item)\n cur_card = item.card\n }\n return collections\n }\n\n calculateManualRecord(\n current_card: CardInput,\n now: DateInput,\n record_log_item?: RecordLogItem,\n update_memory?: boolean\n ): RecordLogItem | null {\n if (!record_log_item) {\n return null\n }\n // if first_card === recordItem.card then return null\n const { card: reschedule_card, log } = record_log_item\n const cur_card = <Card>TypeConvert.card(current_card) // copy card\n if (cur_card.due.getTime() === reschedule_card.due.getTime()) {\n return null\n }\n cur_card.scheduled_days = reschedule_card.due.diff(\n cur_card.due as Date,\n 'days'\n )\n return this.handleManualRating(\n cur_card,\n reschedule_card.state,\n TypeConvert.time(now),\n log.elapsed_days,\n update_memory ? reschedule_card.stability : undefined,\n update_memory ? reschedule_card.difficulty : undefined,\n reschedule_card.due\n )\n }\n}\n","import {\n Card,\n CardInput,\n DateInput,\n FSRSHistory,\n FSRSParameters,\n Grade,\n Rating,\n RecordLogItem,\n ReviewLog,\n ReviewLogInput,\n State,\n} from './models'\nimport {\n type IPreview,\n type IReschedule,\n type RescheduleOptions,\n type IScheduler,\n} from './types'\nimport { FSRSAlgorithm } from './algorithm'\nimport { TypeConvert } from './convert'\nimport BasicScheduler from './impl/basic_scheduler'\nimport LongTermScheduler from './impl/long_term_scheduler'\nimport { createEmptyCard } from './default'\nimport { Reschedule } from './reschedule'\nimport { DefaultInitSeedStrategy } from './strategies/seed'\nimport {\n StrategyMode,\n type TSeedStrategy,\n type TSchedulerStrategy,\n type TStrategyHandler,\n} from './strategies/types'\n\nexport class FSRS extends FSRSAlgorithm {\n private strategyHandler = new Map<StrategyMode, TStrategyHandler>()\n private Scheduler: TSchedulerStrategy\n constructor(param: Partial<FSRSParameters>) {\n super(param)\n const { enable_short_term } = this.parameters\n this.Scheduler = enable_short_term ? BasicScheduler : LongTermScheduler\n }\n\n protected override params_handler_proxy(): ProxyHandler<FSRSParameters> {\n const _this = this satisfies FSRS\n return {\n set: function (\n target: FSRSParameters,\n prop: keyof FSRSParameters,\n value: FSRSParameters[keyof FSRSParameters]\n ) {\n if (prop === 'request_retention' && Number.isFinite(value)) {\n _this.intervalModifier = _this.calculate_interval_modifier(\n Number(value)\n )\n } else if (prop === 'enable_short_term') {\n _this.Scheduler = value === true ? BasicScheduler : LongTermScheduler\n }\n Reflect.set(target, prop, value)\n return true\n },\n }\n }\n\n useStrategy<T extends StrategyMode>(\n mode: T,\n handler: TStrategyHandler<T>\n ): this {\n this.strategyHandler.set(mode, handler)\n return this\n }\n\n clearStrategy(mode?: StrategyMode): this {\n if (mode) {\n this.strategyHandler.delete(mode)\n } else {\n this.strategyHandler.clear()\n }\n return this\n }\n\n private getScheduler(card: CardInput | Card, now: DateInput): IScheduler {\n const seedStrategy = this.strategyHandler.get(StrategyMode.SEED) as\n | TSeedStrategy\n | undefined\n\n // Strategy scheduler\n const schedulerStrategy = this.strategyHandler.get(\n StrategyMode.SCHEDULER\n ) as TSchedulerStrategy | undefined\n\n const Scheduler = schedulerStrategy || this.Scheduler\n const Seed = seedStrategy || DefaultInitSeedStrategy\n const instance = new Scheduler(card, now, this, {\n seed: Seed,\n })\n\n return instance\n }\n\n /**\n * Display the collection of cards and logs for the four scenarios after scheduling the card at the current time.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date());\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n * function repeatAfterHandler(recordLog: RecordLog) {\n * const record: { [key in Grade]: RepeatRecordLog } = {} as {\n * [key in Grade]: RepeatRecordLog;\n * };\n * for (const grade of Grades) {\n * record[grade] = {\n * card: {\n * ...(recordLog[grade].card as Card & { cid: string }),\n * due: recordLog[grade].card.due.getTime(),\n * state: State[recordLog[grade].card.state] as StateType,\n * last_review: recordLog[grade].card.last_review\n * ? recordLog[grade].card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLog[grade].log,\n * cid: (recordLog[grade].card as Card & { cid: string }).cid,\n * due: recordLog[grade].log.due.getTime(),\n * review: recordLog[grade].log.review.getTime(),\n * state: State[recordLog[grade].log.state] as StateType,\n * rating: Rating[recordLog[grade].log.rating] as RatingType,\n * },\n * };\n * }\n * return record;\n * }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLog = f.repeat(card, new Date(), repeatAfterHandler);\n * ```\n */\n repeat<R = IPreview>(\n card: CardInput | Card,\n now: DateInput,\n afterHandler?: (recordLog: IPreview) => R\n ): R {\n const instance = this.getScheduler(card, now)\n const recordLog = instance.preview()\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLog)\n } else {\n return recordLog as R\n }\n }\n\n /**\n * Display the collection of cards and logs for the card scheduled at the current time, after applying a specific grade rating.\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param grade Rating of the review (Again, Hard, Good, Easy)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const card: Card = createEmptyCard(new Date());\n * const f = fsrs();\n * const recordLogItem = f.next(card, new Date(), Rating.Again);\n * ```\n * @example\n * ```\n * interface RevLogUnchecked\n * extends Omit<ReviewLog, \"due\" | \"review\" | \"state\" | \"rating\"> {\n * cid: string;\n * due: Date | number;\n * state: StateType;\n * review: Date | number;\n * rating: RatingType;\n * }\n *\n * interface NextRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked;\n * }\n *\n function nextAfterHandler(recordLogItem: RecordLogItem) {\n const recordItem = {\n card: {\n ...(recordLogItem.card as Card & { cid: string }),\n due: recordLogItem.card.due.getTime(),\n state: State[recordLogItem.card.state] as StateType,\n last_review: recordLogItem.card.last_review\n ? recordLogItem.card.last_review!.getTime()\n : null,\n },\n log: {\n ...recordLogItem.log,\n cid: (recordLogItem.card as Card & { cid: string }).cid,\n due: recordLogItem.log.due.getTime(),\n review: recordLogItem.log.review.getTime(),\n state: State[recordLogItem.log.state] as StateType,\n rating: Rating[recordLogItem.log.rating] as RatingType,\n },\n };\n return recordItem\n }\n * const card: Card = createEmptyCard(new Date(), cardAfterHandler); //see method: createEmptyCard\n * const f = fsrs();\n * const recordLogItem = f.repeat(card, new Date(), Rating.Again, nextAfterHandler);\n * ```\n */\n next<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n grade: Grade,\n afterHandler?: (recordLog: RecordLogItem) => R\n ): R {\n const instance = this.getScheduler(card, now)\n const g = TypeConvert.rating(grade)\n if (g === Rating.Manual) {\n throw new Error('Cannot review a manual rating')\n }\n const recordLogItem = instance.review(g)\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n * Get the retrievability of the card\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param format default:true , Convert the result to another type. (Optional)\n * @returns The retrievability of the card,if format is true, the result is a string, otherwise it is a number\n */\n get_retrievability<T extends boolean>(\n card: CardInput | Card,\n now?: DateInput,\n format: T = true as T\n ): T extends true ? string : number {\n const processedCard = TypeConvert.card(card)\n now = now ? TypeConvert.time(now) : new Date()\n const t =\n processedCard.state !== State.New\n ? Math.max(now.diff(processedCard.last_review as Date, 'days'), 0)\n : 0\n const r =\n processedCard.state !== State.New\n ? this.forgetting_curve(t, +processedCard.stability.toFixed(8))\n : 0\n return (format ? `${(r * 100).toFixed(2)}%` : r) as T extends true\n ? string\n : number\n }\n\n /**\n *\n * @param card Card to be processed\n * @param log last review log\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now);\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now);\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log);\n * ```\n *\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card, log } = repeatFormAfterHandler[Rating.Hard];\n * const rollbackFromAfterHandler = f.rollback(card, log, cardAfterHandler);\n * ```\n */\n rollback<R = Card>(\n card: CardInput | Card,\n log: ReviewLogInput,\n afterHandler?: (prevCard: Card) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n const processedLog = TypeConvert.review_log(log)\n if (processedLog.rating === Rating.Manual) {\n throw new Error('Cannot rollback a manual rating')\n }\n let last_due, last_review, last_lapses\n switch (processedLog.state) {\n case State.New:\n last_due = processedLog.due\n last_review = undefined\n last_lapses = 0\n break\n case State.Learning:\n case State.Relearning:\n case State.Review:\n last_due = processedLog.review\n last_review = processedLog.due\n last_lapses =\n processedCard.lapses -\n (processedLog.rating === Rating.Again &&\n processedLog.state === State.Review\n ? 1\n : 0)\n break\n }\n\n const prevCard: Card = {\n ...processedCard,\n due: last_due,\n stability: processedLog.stability,\n difficulty: processedLog.difficulty,\n elapsed_days: processedLog.last_elapsed_days,\n scheduled_days: processedLog.scheduled_days,\n reps: Math.max(0, processedCard.reps - 1),\n lapses: Math.max(0, last_lapses),\n state: processedLog.state,\n last_review: last_review,\n }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(prevCard)\n } else {\n return prevCard as R\n }\n }\n\n /**\n *\n * @param card Card to be processed\n * @param now Current time or scheduled time\n * @param reset_count Should the review count information(reps,lapses) be reset. (Optional)\n * @param afterHandler Convert the result to another type. (Optional)\n * @example\n * ```\n * const now = new Date();\n * const f = fsrs();\n * const emptyCard = createEmptyCard(now);\n * const scheduling_cards = f.repeat(emptyCard, now);\n * const { card, log } = scheduling_cards[Rating.Hard];\n * const forgetCard = f.forget(card, new Date(), true);\n * ```\n *\n * @example\n * ```\n * interface RepeatRecordLog {\n * card: CardUnChecked; //see method: createEmptyCard\n * log: RevLogUnchecked; //see method: fsrs.repeat()\n * }\n *\n * function forgetAfterHandler(recordLogItem: RecordLogItem): RepeatRecordLog {\n * return {\n * card: {\n * ...(recordLogItem.card as Card & { cid: string }),\n * due: recordLogItem.card.due.getTime(),\n * state: State[recordLogItem.card.state] as StateType,\n * last_review: recordLogItem.card.last_review\n * ? recordLogItem.card.last_review!.getTime()\n * : null,\n * },\n * log: {\n * ...recordLogItem.log,\n * cid: (recordLogItem.card as Card & { cid: string }).cid,\n * due: recordLogItem.log.due.getTime(),\n * review: recordLogItem.log.review.getTime(),\n * state: State[recordLogItem.log.state] as StateType,\n * rating: Rating[recordLogItem.log.rating] as RatingType,\n * },\n * };\n * }\n * const now = new Date();\n * const f = fsrs();\n * const emptyCardFormAfterHandler = createEmptyCard(now, cardAfterHandler); //see method: createEmptyCard\n * const repeatFormAfterHandler = f.repeat(emptyCardFormAfterHandler, now, repeatAfterHandler); //see method: fsrs.repeat()\n * const { card } = repeatFormAfterHandler[Rating.Hard];\n * const forgetFromAfterHandler = f.forget(card, date_scheduler(now, 1, true), false, forgetAfterHandler);\n * ```\n */\n forget<R = RecordLogItem>(\n card: CardInput | Card,\n now: DateInput,\n reset_count: boolean = false,\n afterHandler?: (recordLogItem: RecordLogItem) => R\n ): R {\n const processedCard = TypeConvert.card(card)\n now = TypeConvert.time(now)\n const scheduled_days =\n processedCard.state === State.New\n ? 0\n : now.diff(processedCard.last_review as Date, 'days')\n const forget_log: ReviewLog = {\n rating: Rating.Manual,\n state: processedCard.state,\n due: processedCard.due,\n stability: processedCard.stability,\n difficulty: processedCard.difficulty,\n elapsed_days: 0,\n last_elapsed_days: processedCard.elapsed_days,\n scheduled_days: scheduled_days,\n review: now,\n }\n const forget_card: Card = {\n ...processedCard,\n due: now,\n stability: 0,\n difficulty: 0,\n elapsed_days: 0,\n scheduled_days: 0,\n reps: reset_count ? 0 : processedCard.reps,\n lapses: reset_count ? 0 : processedCard.lapses,\n state: State.New,\n last_review: processedCard.last_review,\n }\n const recordLogItem: RecordLogItem = { card: forget_card, log: forget_log }\n if (afterHandler && typeof afterHandler === 'function') {\n return afterHandler(recordLogItem)\n } else {\n return recordLogItem as R\n }\n }\n\n /**\n * Reschedules the current card and returns the rescheduled collections and reschedule item.\n *\n * @template T - The type of the record log item.\n * @param {CardInput | Card} current_card - The current card to be rescheduled.\n * @param {Array<FSRSHistory>} reviews - The array of FSRSHistory objects representing the reviews.\n * @param {Partial<RescheduleOptions<T>>} options - The optional reschedule options.\n * @returns {IReschedule<T>} - The rescheduled collections and reschedule item.\n * \n * @example\n * ```\n const f = fsrs()\n const grades: Grade[] = [Rating.Good, Rating.Good, Rating.Good, Rating.Good]\n const reviews_at = [\n new Date(2024, 8, 13),\n new Date(2024, 8, 13),\n new Date(2024, 8, 17),\n new Date(2024, 8, 28),\n ]\n\n const reviews: FSRSHistory[] = []\n for (let i = 0; i < grades.length; i++) {\n reviews.push({\n rating: grades[i],\n review: reviews_at[i],\n })\n }\n\n const results_short = scheduler.reschedule(\n createEmptyCard(),\n reviews,\n {\n skipManual: false,\n }\n )\n console.log(results_short)\n * ```\n */\n reschedule<T = RecordLogItem>(\n current_card: CardInput | Card,\n reviews: FSRSHistory[] = [],\n options: Partial<RescheduleOptions<T>> = {}\n ): IReschedule<T> {\n const {\n recordLogHandler,\n reviewsOrderBy,\n skipManual: skipManual = true,\n now: now = new Date(),\n update_memory_state: updateMemoryState = false,\n } = options\n if (reviewsOrderBy && typeof reviewsOrderBy === 'function') {\n reviews.sort(reviewsOrderBy)\n }\n if (skipManual) {\n reviews = reviews.filter((review) => review.rating !== Rating.Manual)\n }\n const rescheduleSvc = new Reschedule(this)\n\n const collections = rescheduleSvc.reschedule(\n options.first_card || createEmptyCard(),\n reviews\n )\n const len = collections.length\n const cur_card = TypeConvert.card(current_card)\n const manual_item = rescheduleSvc.calculateManualRecord(\n cur_card,\n now,\n len ? collections[len - 1] : undefined,\n updateMemoryState\n )\n\n if (recordLogHandler && typeof recordLogHandler === 'function') {\n return {\n collections: collections.map(recordLogHandler),\n reschedule_item: manual_item ? recordLogHandler(manual_item) : null,\n }\n }\n return {\n collections,\n reschedule_item: manual_item,\n } as IReschedule<T>\n }\n}\n\n/**\n * Create a new instance of TS-FSRS\n * @param params FSRSParameters\n * @example\n * ```typescript\n * const f = fsrs();\n * ```\n * @example\n * ```typescript\n * const params: FSRSParameters = generatorParameters({ maximum_interval: 1000 });\n * const f = fsrs(params);\n * ```\n * @example\n * ```typescript\n * const f = fsrs({ maximum_interval: 1000 });\n * ```\n */\nexport const fsrs = (params?: Partial<FSRSParameters>) => {\n return new FSRS(params || {})\n}\n"],"names":["State","t","Rating","e","TypeConvert","card","value","firstLetter","restOfString","ret","timestamp","log","default_request_retention","default_maximum_interval","default_w","default_enable_fuzz","default_enable_short_term","FSRSVersion","generatorParameters","props","w","createEmptyCard","now","afterHandler","emptyCard","isDay","date_scheduler","pre","unit","date_diff","formatDate","last_review","timeUnit","show_diff_message","fixDate","diff","r","dateInput","date","year","month","day","hours","minutes","seconds","padZero","num","TIMEUNIT","TIMEUNITFORMAT","due","i","fixState","fixRating","Grades","FUZZ_RANGES","get_fuzz_range","interval","elapsed_days","maximum_interval","delta","range","min_ivl","max_ivl","clamp","min","max","dateDiffInDays","last","cur","utc1","utc2","Alea","seed","mash","Mash","state","n","data","h","alea","xg","prng","DECAY","FACTOR","FSRSAlgorithm","params","request_retention","_this","target","prop","_params","key","paramKey","g","ivl","fuzz_factor","s","newInterval","delta_d","old_d","d","next_d","difficulty","init","current","hard_penalty","easy_bound","stability","memory_state","s_after_success","s_after_fail","s_after_short_term","new_s","w_17","w_18","next_s_min","DefaultInitSeedStrategy","time","reps","mul","GenSeedStrategyWithCardId","card_id_field","card_id","StrategyMode","AbstractScheduler","algorithm","strategies","grade","item","rating","BasicScheduler","exist","next","easy_interval","good_interval","good_stability","retrievability","next_again","next_hard","next_good","next_easy","item_again","item_hard","item_good","item_easy","nextSMin","hard_interval","LongTermScheduler","first_interval","again_interval","Reschedule","fsrs","reviewed","next_card","scheduled_days","current_card","reviews","collections","cur_card","review","record_log_item","update_memory","reschedule_card","FSRS","param","enable_short_term","mode","handler","seedStrategy","Scheduler","Seed","recordLog","instance","recordLogItem","format","processedCard","processedLog","last_due","last_lapses","prevCard","reset_count","forget_log","options","recordLogHandler","reviewsOrderBy","skipManual","updateMemoryState","rescheduleSvc","len","manual_item"],"mappings":"aAEO,IAAKA,GAAAA,IACVA,EAAAA,EAAA,IAAM,CAAN,EAAA,MACAA,IAAA,SAAW,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