2 lines
1.4 KiB
JavaScript
2 lines
1.4 KiB
JavaScript
function p(t){const e=t<0,c=Math.abs(Math.round(t)),o=Math.floor(c/60),n=c%60;return(e?"−":"")+o+":"+(n<10?"0":"")+n}function w(t){return t.map(e=>Number.isFinite(e)&&e>0?e:0)}function b(t){return Number.isFinite(t)&&t>0?t:0}function k(t){const e=w(t.budgets),c=e.reduce((i,l)=>i+l,0),o=t.targetSeconds>0?t.targetSeconds:c,n=e.length===0?0:Math.max(0,Math.min(e.length-1,Math.trunc(t.index)||0)),a=b(t.elapsed),r=b(t.slideElapsed),s=e[n]??0,g=s-r;let h="",u=!1;if(!t.idle){let i=Math.min(r,s);for(let f=0;f<n;f++)i+=e[f]??0;const l=Math.round(i-a);u=l<0,h=l>=0?"zapas "+p(l):"opóźnienie "+p(-l)}return{slide:s?p(g):"—",total:p(o-a),pace:h,slideOver:s>0&&g<0,totalOver:a>o,late:u,idle:t.idle,paused:t.paused,hidden:t.hidden,elapsed:Math.floor(a),slideElapsed:Math.floor(r)}}function m(t){const e=w(t.budgets),c=e.map(()=>0);let o=0,n=0,a=0,r=!1;function s(d){return e.length===0?0:Math.max(0,Math.min(e.length-1,d))}function g(){return n===0&&o===0}function h(){return k({budgets:e,targetSeconds:t.targetSeconds,index:a,slideElapsed:c[a]??0,elapsed:o,idle:g(),paused:n===0&&o>0,hidden:r})}function u(){if(!n)return;const d=t.now(),M=(d-n)/1e3;n=d,e.length>0&&(c[a]+=M),o+=M}function i(d){a=s(d),n===0&&o===0&&(n=t.now())}function l(d){a=s(d)}function f(){!o&&!n||(u(),n=n?0:t.now())}function x(){for(let d=0;d<c.length;d++)c[d]=0;o=0,n=0}return{go:i,seek:l,tick:u,pause:f,reset:x,toggleHidden(){r=!r},view:h}}export{k as a,m as c};
|