o&&(o=m.length)}let c=k("");e.appendChild(c);let n=Math.max(o*15,24),h=W(n);if(t.gapInputs[this.inputId]=h,h.addEventListener("keyup",()=>{t.editingEnabled!=!1&&(this.question.editedQuestion(),h.value=h.value.toUpperCase(),this.question.student[this.inputId]=h.value.trim())}),c.appendChild(h),this.question.showSolution&&(this.question.student[this.inputId]=h.value=l[0],l.length>1)){let p=k("["+l.join("|")+"]");p.style.fontSize="small",p.style.textDecoration="underline",c.appendChild(p)}}},I=class{static{f(this,"TermInput")}constructor(e,t,s,i,l,o,c=!1){s in t.student||(t.student[s]=""),this.question=t,this.inputId=s,this.outerSpan=k(""),this.outerSpan.style.position="relative",e.appendChild(this.outerSpan),this.inputElement=W(Math.max(i*12,48)),this.outerSpan.appendChild(this.inputElement),this.equationPreviewDiv=w(),this.equationPreviewDiv.classList.add("equationPreview"),this.equationPreviewDiv.style.display="none",this.outerSpan.appendChild(this.equationPreviewDiv),this.inputElement.addEventListener("click",()=>{t.editingEnabled!=!1&&(this.question.editedQuestion(),this.edited())}),this.inputElement.addEventListener("keyup",()=>{t.editingEnabled!=!1&&(this.question.editedQuestion(),this.edited())}),this.inputElement.addEventListener("focus",()=>{t.editingEnabled!=!1}),this.inputElement.addEventListener("focusout",()=>{this.equationPreviewDiv.innerHTML="",this.equationPreviewDiv.style.display="none"}),this.inputElement.addEventListener("keydown",n=>{if(t.editingEnabled==!1){n.preventDefault();return}let h="abcdefghijklmnopqrstuvwxyz";h+="ABCDEFGHIJKLMNOPQRSTUVWXYZ",h+="0123456789",h+="+-*/^(). <>=|",o&&(h="-0123456789"),n.key.length<3&&h.includes(n.key)==!1&&n.preventDefault();let p=this.inputElement.value.length*12;this.inputElement.offsetWidth0&&!s?"block":"none",this.question.student[this.inputId]=e}},H=class{static{f(this,"MatrixInput")}constructor(e,t,s,i){this.parent=e,this.question=t,this.inputId=s,this.matExpected=new E(0,0),this.matExpected.fromString(i),this.matStudent=new E(this.matExpected.m==1?1:3,this.matExpected.n==1?1:3),t.showSolution&&this.matStudent.fromMatrix(this.matExpected),this.genMatrixDom(!0)}genMatrixDom(e){let t=w();this.parent.innerHTML="",this.parent.appendChild(t),t.style.position="relative",t.style.display="inline-block";let s=document.createElement("table");t.appendChild(s);let i=this.matExpected.getMaxCellStrlen();for(let u=0;u=10,this.matStudent.n<=1,this.matStudent.m>=10,this.matStudent.m<=1];for(let u=0;u<4;u++){if(m[u]==!1)continue;let g=k(l[u]);n[u]!=888&&(g.style.top=""+n[u]+"px"),h[u]!=888&&(g.style.bottom=""+h[u]+"px"),p[u]!=888&&(g.style.right=""+p[u]+"px"),g.classList.add("matrixResizeButton"),t.appendChild(g),d[u]?g.style.opacity="0.5":g.addEventListener("click",()=>{for(let v=0;v=5&&(this.feedbackSpan.innerHTML=" "+this.numCorrect+" / "+this.numChecked);break}this.questionDiv.style.backgroundColor=t,this.questionDiv.style.borderColor=e}populateDom(e=!1){if(this.parentDiv.innerHTML="",this.questionDiv=w(),this.parentDiv.appendChild(this.questionDiv),this.questionDiv.classList.add("question"),this.feedbackPopupDiv=w(),this.feedbackPopupDiv.classList.add("questionFeedback"),this.questionDiv.appendChild(this.feedbackPopupDiv),this.feedbackPopupDiv.innerHTML="awesome",this.debug&&"src_line"in this.src){let i=w();i.classList.add("debugInfo"),i.innerHTML="Source code: lines "+this.src.src_line+"..",this.questionDiv.appendChild(i)}if(this.titleDiv=w(),this.questionDiv.appendChild(this.titleDiv),this.titleDiv.classList.add("questionTitle"),this.titleDiv.innerHTML=this.src.title,this.src.error.length>0){let i=k(this.src.error);this.questionDiv.appendChild(i),i.style.color="red";return}let t=this.getCurrentInstance();if(t!=null&&"__svg_image"in t){let i=t.__svg_image.v,l=w();this.questionDiv.appendChild(l);let o=document.createElement("img");l.appendChild(o),o.classList.add("img"),o.src="data:image/svg+xml;base64,"+i}for(let i of this.src.text.c)this.questionDiv.appendChild(this.generateText(i));let s=w();if(s.innerHTML="",s.classList.add("button-group"),this.questionDiv.appendChild(s),this.hasCheckButton=Object.keys(this.expected).length>0,this.hasCheckButton&&(this.checkAndRepeatBtn=F(),s.appendChild(this.checkAndRepeatBtn),this.checkAndRepeatBtn.innerHTML=P,this.checkAndRepeatBtn.style.backgroundColor="black",e&&(this.checkAndRepeatBtn.style.height="0",this.checkAndRepeatBtn.style.visibility="hidden")),this.feedbackSpan=k(""),this.feedbackSpan.style.userSelect="none",s.appendChild(this.feedbackSpan),this.debug){if(this.src.variables.length>0){let o=w();o.classList.add("debugInfo"),o.innerHTML="Variables generated by Python Code",this.questionDiv.appendChild(o);let c=w();c.classList.add("debugCode"),this.questionDiv.appendChild(c);let n=this.getCurrentInstance(),h="",p=[...this.src.variables];p.sort();for(let m of p){let d=n[m].t,u=n[m].v;switch(d){case"vector":u="["+u+"]";break;case"set":u="{"+u+"}";break}h+=d+" "+m+" = "+u+"
"}c.innerHTML=h}let i=["python_src_html","text_src_html"],l=["Python Source Code","Text Source Code"];for(let o=0;o0){let n=w();n.classList.add("debugInfo"),n.innerHTML=l[o],this.questionDiv.appendChild(n);let h=w();h.classList.add("debugCode"),this.questionDiv.append(h),h.innerHTML=this.src[c]}}}this.hasCheckButton&&this.checkAndRepeatBtn.addEventListener("click",()=>{this.state==x.passed?(this.state=x.init,this.editingEnabled=!0,this.reset(),this.populateDom()):R(this)})}generateMathString(e){let t="";switch(e.t){case"math":case"display-math":for(let s of e.c){let i=this.generateMathString(s);s.t==="var"&&t.includes("!PM")&&(i.startsWith("{-")?(i="{"+i.substring(2),t=t.replaceAll("!PM","-")):t=t.replaceAll("!PM","+")),t+=i}break;case"text":return e.d;case"plus_minus":{t+=" !PM ";break}case"var":{let s=this.getCurrentInstance(),i=s[e.d].t,l=s[e.d].v;switch(i){case"vector":return"\\left["+l+"\\right]";case"set":return"\\left\\{"+l+"\\right\\}";case"complex":{let o=l.split(","),c=parseFloat(o[0]),n=parseFloat(o[1]);return a.const(c,n).toTexString()}case"matrix":{let o=new E(0,0);return o.fromString(l),t=o.toTeXString(e.d.includes("augmented"),this.language!="de"),t}case"term":{try{t=b.parse(l).toTexString()}catch{}break}default:t=l}}}return e.t==="plus_minus"?t:"{"+t+"}"}generateText(e,t=!1){switch(e.t){case"paragraph":case"span":{let s=document.createElement(e.t=="span"||t?"span":"p");for(let i of e.c)s.appendChild(this.generateText(i));return s.style.userSelect="none",s}case"text":return k(e.d);case"code":{let s=k(e.d);return s.classList.add("code"),s}case"italic":case"bold":{let s=k("");return s.append(...e.c.map(i=>this.generateText(i))),e.t==="bold"?s.style.fontWeight="bold":s.style.fontStyle="italic",s}case"math":case"display-math":{let s=this.generateMathString(e);return L(s,e.t==="display-math")}case"string_var":{let s=k(""),i=this.getCurrentInstance(),l=i[e.d].t,o=i[e.d].v;return l==="string"?s.innerHTML=o:(s.innerHTML="EXPECTED VARIABLE OF TYPE STRING",s.style.color="red"),s}case"gap":{let s=k("");return new B(s,this,"",e.d),s}case"input":case"input2":{let s=e.t==="input2",i=k("");i.style.verticalAlign="text-bottom";let l=e.d,o=this.getCurrentInstance()[l];if(this.expected[l]=o.v,this.types[l]=o.t,!s)switch(o.t){case"set":i.append(L("\\{"),k(" "));break;case"vector":i.append(L("["),k(" "));break}if(o.t==="string")new B(i,this,l,this.expected[l]);else if(o.t==="vector"||o.t==="set"){let c=o.v.split(","),n=c.length;for(let h=0;h0&&i.appendChild(k(" , "));let p=l+"-"+h;new I(i,this,p,c[h].length,c[h],!1)}}else if(o.t==="matrix"){let c=w();i.appendChild(c),new H(c,this,l,o.v)}else if(o.t==="complex"){let c=o.v.split(",");new I(i,this,l+"-0",c[0].length,c[0],!1),i.append(k(" "),L("+"),k(" ")),new I(i,this,l+"-1",c[1].length,c[1],!1),i.append(k(" "),L("i"))}else{let c=o.t==="int";new I(i,this,l,o.v.length,o.v,c)}if(!s)switch(o.t){case"set":i.append(k(" "),L("\\}"));break;case"vector":i.append(k(" "),L("]"));break}return i}case"itemize":return j(e.c.map(s=>O(this.generateText(s))));case"single-choice":case"multi-choice":{let s=e.t=="multi-choice";s||(this.includesSingleChoice=!0);let i=document.createElement("table"),l=e.c.length,o=this.debug==!1,c=z(l,o),n=s?X:G,h=s?Z:Y,p=[],m=[];for(let d=0;d{this.editingEnabled!=!1&&(this.editedQuestion(),this.student[v]=this.student[v]==="true"?"false":"true",this.student[v]==="true"?T.innerHTML=n:T.innerHTML=h)}):C.addEventListener("click",()=>{if(this.editingEnabled!=!1){this.editedQuestion();for(let D of m)this.student[D]="false";this.student[v]="true";for(let D=0;D{r.feedbackPopupDiv.style.display="none"},1e3),r.editingEnabled=!0,r.state===x.passed?(r.editingEnabled=!1,r.src.instances.length>1?r.checkAndRepeatBtn.innerHTML=J:r.checkAndRepeatBtn.style.visibility="hidden"):r.checkAndRepeatBtn!=null&&(r.checkAndRepeatBtn.innerHTML=P)}f(R,"evalQuestion");function be(r,e){new q(r,e)}f(be,"init");var q=class{static{f(this,"Quiz")}constructor(e,t){this.quizSrc=e,["en","de","es","it","fr"].includes(this.quizSrc.lang)==!1&&(this.quizSrc.lang="en"),this.debug=t,this.debug&&(document.getElementById("debug").style.display="block"),this.questions=[],this.timeLeft=e.timer,this.timeLimited=e.timer>0,this.fillPageMetadata(),this.timeLimited?(document.getElementById("timer-info").style.display="block",document.getElementById("timer-info-text").innerHTML=oe[this.quizSrc.lang],document.getElementById("start-btn").addEventListener("click",()=>{document.getElementById("timer-info").style.display="none",this.generateQuestions(),this.runTimer()})):this.generateQuestions()}fillPageMetadata(){if(document.getElementById("date").innerHTML=this.quizSrc.date,document.getElementById("title").innerHTML=this.quizSrc.title,document.getElementById("author").innerHTML=this.quizSrc.author,this.quizSrc.info.length>0)document.getElementById("courseInfo1").innerHTML=this.quizSrc.info;else{document.getElementById("courseInfo1").innerHTML=$[this.quizSrc.lang];let e=''+te[this.quizSrc.lang]+"";document.getElementById("courseInfo2").innerHTML=ee[this.quizSrc.lang].replace("*",e)}document.getElementById("data-policy").innerHTML=le[this.quizSrc.lang]}generateQuestions(){let e=document.getElementById("questions"),t=1;for(let s of this.quizSrc.questions){s.title=""+t+". "+s.title;let i=w();e.appendChild(i);let l=new V(i,s,this.quizSrc.lang,this.debug);l.showSolution=this.debug,this.questions.push(l),l.populateDom(this.timeLimited),this.debug&&s.error.length==0&&l.hasCheckButton&&l.checkAndRepeatBtn.click(),t++}}runTimer(){document.getElementById("stop-now").style.display="block",document.getElementById("stop-now-btn").innerHTML=ae[this.quizSrc.lang],document.getElementById("stop-now-btn").addEventListener("click",()=>{this.timeLeft=1});let e=document.getElementById("timer");e.style.display="block",e.innerHTML=he(this.timeLeft);let t=setInterval(()=>{this.timeLeft--,e.innerHTML=he(this.timeLeft),this.timeLeft<=0&&this.stopTimer(t)},1e3)}stopTimer(e){document.getElementById("stop-now").style.display="none",clearInterval(e);let t=0,s=0;for(let l of this.questions){let o=l.src.points;s+=o,R(l),l.state===x.passed&&(t+=o),l.editingEnabled=!1}document.getElementById("questions-eval").style.display="block";let i=document.getElementById("questions-eval-percentage");i.innerHTML=s==0?"":""+t+" / "+s+" "+re[this.quizSrc.lang]+"
"+Math.round(t/s*100)+" %"}};function he(r){let e=Math.floor(r/60),t=r%60;return e+":"+(""+t).padStart(2,"0")}f(he,"formatTime");return ge(ke);})();pysell.init(quizSrc,debug);