Files
StudyDiary/.obsidian/plugins/slides-extended/plugin/elapsed-time-bar/elapsed-time-bar.js
CrazyJasonwell fb40c9b109 add all
2025-10-25 20:35:10 +08:00

7 lines
2.3 KiB
JavaScript
Executable File

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
window.ElapsedTimeBar=window.ElapsedTimeBar||{id:"ElapsedTimeBar",start:(e,s)=>{t.start(e,s)},reset:()=>{t.reset()},pause:()=>{t.pause()},resume:()=>{t.resume()}};var t={id:"ElapsedTimeBar",barColor:"rgb(200,0,0)",pausedBarColor:"rgba(200,0,0,.6)",isPaused:!1,isFinished:!1,allottedTime:null,timeProgressBar:null,startTime:null,pauseTime:null,pauseTimeDuration:0,handleReady(){let e=Reveal.getConfig();if(!e.allottedTime){console.warn('"allottedTime" property is required by the ElapsedTimeBar plugin.');return}this.barColor=e.barColor||this.barColor,this.pausedBarColor=e.pausedBarColor||this.pausedBarColor;let s,i=document.querySelector(".progress");e.progressBarHeight?(s=`${Number.parseInt(e.progressBarHeight,10)}px`,i&&(i.style.height=s)):e.progress&&i?s=`${i.getBoundingClientRect().height}px`:s="3px";let r=document.createElement("div");r.classList.add("progress");for(let[a,o]of Object.entries({display:"block",position:"fixed",bottom:e.progress?s:0,width:"100%",height:s}))r.style[a]=o;document.querySelector(".reveal").appendChild(r),this.timeProgressBar=document.createElement("div");for(let[a,o]of Object.entries({height:"100%",willChange:"width"}))this.timeProgressBar.style[a]=o;r.appendChild(this.timeProgressBar),this.start(e.allottedTime)},loop(){if(this.isPaused)return;let s=+new Date-this.startTime-this.pauseTimeDuration;s>this.allottedTime?(this.timeProgressBar.style.width="100%",this.isFinished=!0):(this.timeProgressBar.style.width=`${s/this.allottedTime*100}%`,requestAnimationFrame(this.loop.bind(this)))},setBarColor(){this.isPaused?this.timeProgressBar.style.backgroundColor=this.pausedBarColor:this.timeProgressBar.style.backgroundColor=this.barColor},start(e,s=0){this.isFinished=!1,this.isPaused=!1,this.allottedTime=e,this.startTime=+new Date-s,this.pauseTimeDuration=0,this.setBarColor(),this.loop()},reset(){this.start(this.allottedTime)},pause(){this.isPaused||(this.isPaused=!0,this.pauseTime=+new Date,this.setBarColor())},resume(){this.isPaused&&(this.isPaused=!1,this.pauseTimeDuration+=new Date-this.pauseTime,this.pauseTime=null,this.setBarColor(),this.loop())}};Reveal.isReady()?t.handleReady():Reveal.addEventListener("ready",()=>t.handleReady());