1import{Controller}from"@hotwired/stimulus";const circleRadius=9,circleCircumference=2*circleRadius*Math.PI;export default class extends Controller{static values={timerLength:Number,activityUpdatePath:String,userControls:Boolean,instanceActive:Boolean,instanceUnlocked:Boolean};static targets=["controls","active","paused","expired","reset","progress"];initialize(){this.timeElapsed=0,this.startedAt=null,this.instanceActiveValue&&this.instanceUnlockedValue?this.play():this.timerState="uninitialized"}connect(){this.renderButtons(),this.renderProgressCircle(),this.renderHeaderTimer()}playButton(){clearTimeout(this.currentTimeout),"active"!==this.timerState&&this.updateServerActivity("unlock"),this.timerState="active",this.startedAt=Date.now()-1e3*this.timeElapsed,this.renderButtons(),this.continueTimer()}play(){clearTimeout(this.currentTimeout),"active"!==this.timerState&&(this.timerState="active"),this.startedAt=Date.now()-1e3*this.timeElapsed,this.renderButtons(),this.continueTimer()}pause(){clearTimeout(this.currentTimeout),this.timeElapsed=(Date.now()-this.startedAt)/1e3,this.timerState="paused",this.renderButtons()}resetButton(){clearTimeout(this.currentTimeout),this.timeElapsed=0,this.playButton()}expire(e){clearTimeout(this.currentTimeout),this.timerState="expired",this.timeElapsed=0,e&&this.updateServerActivity("lock"),this.renderProgressCircle(),this.renderButtons(),this.renderHeaderTimer()}continueTimer(){this.currentTimeout=setTimeout(this.updateTimerTime.bind(this),1e3)}updateTimerTime(){this.timeElapsed=(Date.now()-this.startedAt)/1e3,this.renderProgressCircle(),this.renderHeaderTimer(),this.timeElapsed>=this.timerLengthValue?(this.timeElapsed=this.timerLengthValue,this.expire(!0)):this.continueTimer()}disconnect(){clearTimeout(this.currentTimeout)}instanceUnlockedValueChanged(e){e&&this.instanceActiveValue&&!this.paused()?this.play():e||this.expire(!1)}instanceActiveValueChanged(e){e&&this.instanceUnlockedValue&&!this.paused()?this.play():e||"active"!==this.timerState||this.expire(!1)}paused(){return"paused"===this.timerState}secondsRemaining(){return Math.round(this.timerLengthValue-this.timeElapsed)}renderHeaderTimer(){const e=this.secondsRemaining(),t=document.getElementById("header-timer"),i=this.application.getControllerForElementAndIdentifier(t,"charts--header-timer");i&&i.update(e)}renderButtons(){this.controlsTargets.forEach((e=>{const t=`controls ${this.timerState}`;e.dataset["charts-TimerTarget"]===t?e.classList.remove("hidden"):"controls progress"===e.dataset["charts-TimerTarget"]||e.classList.add("hidden")}))}renderProgressCircle(){this.progressTarget.innerHTML=this.timerProgressCircle()}timerProgressCircle(){const e=this.secondsRemaining(),t=this.timeElapsed/this.timerLengthValue*circleCircumference;let i=null;i=this.timeElapsed>=this.timerLengthValue||0===this.timeElapsed?0:t+circleCircumference;let r="";r=this.userControlsValue?"w-[25px]":"w-[50px] md:w-[75px]";const s=`<div class="text-xl mt-[-40px] md:mt-[-54px]" style='text-align: center;' >${e}</div>`;return`\n <div class="${r}">\n <svg viewBox="0 0 25 25" class='w-full h-full'>\n <linearGradient id='gradient' gradientTransform='rotate(90)'>\n <stop style='stop-color: #007ACC;' offset='0'/>\n <stop style='stop-color: #945DC3;' offset='83.92%'/>\n </linearGradient>\n <circle id='backgroundCircle' cx='50%' cy='50%' r=${circleRadius}\n fill='transparent'\n stroke='white'\n stroke-width='5px'\n stroke-dasharray=${circleCircumference} // assign full circumference of circle\n stroke-dashoffset=0 // asign subset of circle circumference\n transform-origin='center'\n />\n <circle id='progressCircle' cx='50%' cy='50%' r=${circleRadius}\n fill='transparent'\n stroke='url(#gradient)'\n stroke-width='5px'\n stroke-dasharray=${circleCircumference} //assign full circumference of circle\n stroke-dashoffset= ${i} // asign subset of circle circumference\n transform-origin='center'\n transform='rotate(-90)'\n />\n ${this.userControlsValue?"":s}\n </svg>\n </div>\n `}getMetaValue(e){return document.head.querySelector(`meta[name='${e}']`).getAttribute("content")}updateServerActivity(e){fetch(this.activityUpdatePathValue,{method:"PUT",headers:{"Content-Type":"application/json","X-CSRF-Token":this.getMetaValue("csrf-token"),Accept:"text/vnd.turbo-stream.html, text/html, application/xhtml+xml"},body:JSON.stringify({presentation_action:e})}).then((e=>e.text())).then((e=>{Turbo.renderStreamMessage(e)}))}}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.