"use strict";(self.webpackChunkWebComponents=self.webpackChunkWebComponents||[]).push([[824],{8824:(e,t,i)=>{i.r(t),i.d(t,{ShowEval:()=>o});var s=i(78673),n=i(34089);class o extends s.A{constructor(e){super(e),this.divid=e.orig.id,this.containerDiv=e.orig,this.containerDiv.classList.add("showEval");let t=[];for(let i of e.raw)t.push(i.replace(/\\/g,""));this.steps=t.slice(),this.currentStep=0,this.createTrace=(0,n.Qt)(e.orig,"tracemode"),this.currentStepDiv=document.createElement("div"),this.currentStepDiv.classList.add("currentStepDiv"),this.containerDiv.appendChild(this.currentStepDiv);for(const e of["pre","eval","post"]){let t=document.createElement("span");t.classList.add(e),this.currentStepDiv.appendChild(t)}this.annoDiv=document.createElement("div"),this.annoDiv.classList.add("anno"),this.currentStepDiv.appendChild(this.annoDiv),this.evalSpan=this.currentStepDiv.querySelector(".eval"),this.setNextButton(`#${this.divid}_nextStep`),this.setResetButton(`#${this.divid}_reset`);for(var i=0;i<this.steps.length;i++){var s=this.steps[i];let e,t;s.includes("##")?(e=s.indexOf("##"),t=s.substring(e+2,s.length)):(e=s.length,t=!1),this.steps[i]=[s.substring(0,s.indexOf("{{")),s.substring(s.indexOf("{{")+2,s.indexOf("}}{{")),s.substring(s.indexOf("}}{{")+4,s.indexOf("}}",s.indexOf("}}{{")+4)),s.substring(s.indexOf("}}",s.indexOf("}}{{")+4)+2,e)],this.steps[i].push(t)}this.reset(),this.caption="ShowEval",this.addCaption("runestone"),this.indicate_component_ready()}setNextButton(e){const t=document.querySelector(e);t?.addEventListener("click",(()=>{this.evaluateStep(t)}))}setResetButton(e){document.querySelector(e)?.addEventListener("click",(()=>{this.reset()}))}reset(){for(const e of this.containerDiv.querySelectorAll(".previousStep"))e.remove();this.setStep(0),this.logBookEvent({event:"showeval",act:"reset",div_id:this.containerDiv.id})}setStep(e){this.currentStep=e;let t=this.getWidth(this.steps[this.currentStep][1]);this.steps[e][4]?(this.annoDiv.innerHTML=this.steps[e][4],this.annoDiv.style.display=""):this.annoDiv.style.display="none",this.evalSpan.style.width=t+"px",this.currentStepDiv.querySelector(".pre").innerHTML=this.steps[e][0],this.evalSpan.innerHTML=this.steps[e][1],this.currentStepDiv.querySelector(".post").innerHTML=this.steps[e][3]}getWidth(e){var t=document.createElement("div");t.classList.add("showEval","evalCont"),t.style.display="none",t.innerHTML=e,document.body.appendChild(t);var i=t.offsetWidth+1;return t.remove(),i}createPreviousStepDiv(e){let t=document.createElement("div");t.classList.add("previousStep"),t.innerHTML=this.steps[e][0]+this.steps[e][1]+this.steps[e][3],this.currentStepDiv.before(t)}evaluateStep(e,t){if(this.annoDiv.style.display="none",e&&(e.disabled=!0),void 0===t&&(t=this.currentStep),this.currentStep>=this.steps.length)return void(e&&(e.disabled=!1));var i=0;this.createTrace&&(this.createPreviousStepDiv(t),this.currentStepDiv.style.display="none",i=200);let s=this.getWidth(this.steps[t][2]);var n=this.evalSpan,o=this;n.style.color="red",this.fadeToOpacity(this.currentStepDiv,1,i,(function(){window.setTimeout((function(){o.fadeToOpacity(n,0,400,(function(){o.animateWidth(n,s,400,(function(){n.innerHTML=o.steps[t][2],o.fadeToOpacity(n,1,400,(function(){window.setTimeout((function(){n.style.color="#333",o.currentStep+=1,o.currentStep<o.steps.length&&o.setStep(o.currentStep),e&&(e.disabled=!1)}),600)}))}))}))}),600)})),this.logBookEvent({event:"showeval",act:"next",div_id:this.containerDiv.id})}fadeToOpacity(e,t,i,s){if(0===i)return e.style.opacity=t,1===t&&"none"===e.style.display&&(e.style.display=""),void(s&&s());var n=parseFloat(window.getComputedStyle(e).opacity)||0,o=performance.now();1===t&&"none"===e.style.display&&(e.style.display="",e.style.opacity=n),requestAnimationFrame((function r(a){var d=a-o,c=Math.min(d/i,1);e.style.opacity=n+(t-n)*c,c<1?requestAnimationFrame(r):s&&s()}))}animateWidth(e,t,i,s){var n=e.offsetWidth,o=performance.now();requestAnimationFrame((function r(a){var d=a-o,c=Math.min(d/i,1);e.style.width=n+(t-n)*c+"px",c<1?requestAnimationFrame(r):s&&s()}))}}document.addEventListener("runestone:login-complete",(function(){for(let t of document.querySelectorAll("[data-component=showeval]")){var e={orig:t,useRunestoneServices:eBookConfig.useRunestoneServices};e.raw=window.raw_steps[t.id],t.closest("[data-component=timedAssessment]")||(window.componentMap[t.id]=new o(e))}})),void 0===window.component_factory&&(window.component_factory={}),window.component_factory.showeval=function(e){return new o(e)}}}]);
//# sourceMappingURL=824.8725219672be093f.js.map