+${a}`));this.body.append(s),this.foldReference(s)}}foldReference(e){const t="visustruct.reference.open";let n=[];try{n=JSON.parse(localStorage.getItem(t)??"[]")}catch{}for(const a of[...e.querySelectorAll("h2")]){const s=a.textContent??"",r=_("details",{class:"reference-group"});r.open=n.includes(s);const o=_("summary",{},s);for(a.replaceWith(r),r.append(o);r.nextSibling&&r.nextSibling.nodeName!=="H2";)r.append(r.nextSibling);r.addEventListener("toggle",()=>{n=r.open?[...new Set([...n,s])]:n.filter(l=>l!==s);try{localStorage.setItem(t,JSON.stringify(n))}catch{}})}}showReference(){this.tab="reference",this.persist(),this.render()}persist(){be.setView({tab:this.tab,lesson:this.lessonId,task:this.taskId})}openLesson(e){this.tab="lessons",this.lessonId=e,this.returnTo=void 0,this.persist(),this.render(),this.body.scrollTop=0}renderLessonList(){this.body.append(_("p",{class:"hint"},p("web_learn_intro")));for(const e of fZ()){this.body.append(_("h3",{class:"learn-section"},e.name));const t=_("ol",{class:"learn-list"});for(const n of e.lessons){const a=be.lesson(n.id),s=a.done?"✓":a.step>0?p("web_learn_step_of_fmt",a.step+1,n.steps.length):"",r=_("button",{class:"learn-item"+(a.done?" done":""),"data-lesson":n.id},_("span",{class:"learn-num"},String(n.number)),_("span",{class:"learn-item-text"},_("strong",{},n.robot?`🤖 ${n.title}`:n.title),_("small",{},n.summary)),_("span",{class:"learn-status"},s));r.addEventListener("click",()=>this.openLesson(n.id)),t.append(_("li",{},r))}this.body.append(t)}this.body.append(this.renderTeacherBox())}renderLesson(e){var u;const t=be.lesson(e.id),n=Math.min(t.step,e.steps.length-1),a=e.steps[n],s=_("button",{class:"learn-back"},`← ${p("web_learn_all_lessons")}`);s.addEventListener("click",()=>this.openLesson(void 0));const r=_("nav",{class:"learn-progress","aria-label":p("web_learn_step_of_fmt",n+1,e.steps.length)});r.append(...e.steps.map((c,m)=>{const d=p("web_learn_step_fmt",m+1,c.title),h=m
this.goToStep(e,m)),g})),this.body.append(_("div",{class:"learn-lesson-head"},_("div",{class:"learn-head-row"},s,this.stepNav(e,n,t.done,"learn-nav learn-nav-top")),_("p",{class:"learn-kicker"},`${p("web_learn_lesson_fmt",e.number)} · ${e.section}${e.robot?" · 🤖 VisuBot":""}`),_("h2",{class:"learn-title"},_("span",{class:"learn-num","aria-hidden":"true"},String(e.number)),e.title),r,_("h3",{class:"learn-step-title"},`${n+1}. ${a.title}`)));const o=((u=this.returnTo)==null?void 0:u.lesson)===e.id&&this.returnTo.step!==n?this.returnTo:void 0,l=()=>{const c=_("button",{class:"learn-return"},`↩ ${p("web_learn_back_to_checklist")}`);return c.addEventListener("click",()=>{this.returnTo=void 0,this.goToStep(e,o.step),this.body.scrollTop=o.scroll}),c};o&&this.body.append(l()),a.blocks.forEach((c,m)=>this.body.append(this.renderBlock(c,`${n}-${m}`,e))),lc(this.body),qB(this.body),this.openNeededColumns(a.blocks),rc(this.body,Na),this.body.append(this.stepNav(e,n,t.done,"learn-nav")),o&&this.body.append(l())}stepNav(e,t,n,a){const s=_("div",{class:a}),r=_("button",{},`← ${p("web_learn_back")}`);if(r.disabled=t===0,r.addEventListener("click",()=>this.goToStep(e,t-1)),s.append(r),tthis.goToStep(e,t+1)),s.append(o)}else{const o=_("button",{class:"primary"},n?`✓ ${p("web_learn_done")}`:p("web_learn_finish"));o.addEventListener("click",()=>{be.updateLesson(e.id,{done:!0});const l=Pt.find(u=>u.number===e.number+1);this.openLesson(l==null?void 0:l.id)}),s.append(o)}return s}goToStep(e,t){be.updateLesson(e.id,{step:t}),this.render(),this.body.scrollTop=0}openNeededColumns(e){const t=e.flatMap(n=>n.kind==="exercise"?[n.exercise]:[]);hZ(this.body)?(this.host.showEditor(),mZ(this.body)&&this.host.reveal(["palette"])):dZ(this.body)?this.host.showFiles():t.some(n=>n.code!=="java")?this.host.showEditor():(t.length>0||this.body.querySelector(".lesson-code[data-lang=java]"))&&this.host.showJava(),gZ(this.body)&&this.host.showLiveCode()}renderTaskList(){this.body.append(_("p",{class:"hint"},p("web_learn_tasks_intro")));const e=_("ul",{class:"learn-list"});for(const t of An){const n=this.taskExercises(t),a=n.length>0&&n.every(o=>be.exercise(o.id).done),s=Pt.find(o=>o.number===t.after),r=_("button",{class:"learn-item"+(a?" done":""),"data-task":t.id},_("span",{class:"learn-num","aria-label":p("web_learn_level_fmt",t.level)},"★".repeat(t.level)),_("span",{class:"learn-item-text"},_("strong",{},t.title),_("small",{},s?p("web_learn_after_fmt",s.number,s.title):"")),_("span",{class:"learn-status"},a?"✓":""));r.addEventListener("click",()=>{this.taskId=t.id,this.persist(),this.render(),this.body.scrollTop=0}),e.append(_("li",{},r))}this.body.append(e,this.renderTeacherBox())}renderTeacherBox(){const e=_("details",{class:"learn-teacher"},_("summary",{},p("web_learn_teacher")));if($u()){e.setAttribute("open","");const s=_("button",{},p("web_learn_teacher_off"));return s.addEventListener("click",()=>{WB(),this.render()}),e.append(_("p",{},p("web_learn_teacher_on")),s),e}const t=_("input",{type:"password",autocomplete:"off","aria-label":p("web_learn_teacher_code"),placeholder:p("web_learn_teacher_code")}),n=_("p",{class:"learn-result",role:"status"}),a=_("form",{class:"group"},t,_("button",{type:"submit"},p("web_learn_teacher_unlock")));return a.addEventListener("submit",async s=>{s.preventDefault(),await EB(t.value)?this.render():(n.className="learn-result info",n.textContent=p("web_learn_teacher_wrong"))}),e.append(_("p",{class:"hint"},p("web_learn_teacher_intro")),a,n),e}taskExercises(e){return e.blocks.flatMap(t=>t.kind==="exercise"?[t.exercise]:[])}renderTask(e){const t=_("button",{class:"learn-back"},`← ${p("web_learn_all_tasks")}`);t.addEventListener("click",()=>{this.taskId=void 0,this.persist(),this.render()});const n=Pt.find(a=>a.number===e.after);if(this.body.append(t,_("h2",{class:"learn-title"},e.title)),n){const a=_("button",{class:"link-button"},p("web_learn_after_fmt",n.number,n.title));a.addEventListener("click",()=>this.openLesson(n.id)),this.body.append(_("p",{class:"learn-kicker"},a))}e.blocks.forEach((a,s)=>this.body.append(this.renderBlock(a,`task-${s}`))),lc(this.body),this.openNeededColumns(e.blocks),rc(this.body,Na)}renderBlock(e,t,n){switch(e.kind){case"markdown":return this.withOpenButtons(tt("div",{class:"learn-text"},Tn(e.text)));case"diagram":return this.renderDiagram(e.file,e.caption);case"exercise":return this.renderExercise(e.exercise);case"competences":return this.renderCompetences(e.items);case"checklist":return this.renderChecklist(e.items,t,n);case"quiz":return this.renderQuiz(e.questions,t,n);case"brag":return this.renderBrag(e.text,e.tip);case"images":return this.renderImages(e.files,e.caption);case"graphic":return this.renderGraphic(e.file,e.caption,e.labeled);case"game":return this.renderGame(e.game);case"roundGame":return UB(e.game,ra);case"rescueGame":return eZ(e.game,ra);case"caesar":return GB(e.key,e.text);case"cloze":return nZ(e.cloze);case"pap":return lZ(e.pap);case"textFile":return ig(e.name,e.content);case"robotModel":return VB(e.focus,e.view,e.spin);case"robotQuiz":return QB(e.tasks,e.done)}}renderBrag(e,t=!1){const n=_("aside",{class:"learn-brag"});n.append(_("img",{src:ra,alt:"",width:"48",height:"48"}));const a=_("div",{},_("p",{class:"learn-brag-title"},p(t?"web_learn_ludwig_tip":"web_learn_brag")));return a.append(tt("div",{class:"learn-text"},Tn(e))),n.append(a),n}renderGame(e){const n=_("section",{class:"learn-game"}),a=_("div",{class:"learn-game-head"});a.append(_("img",{src:ra,alt:"",width:"40",height:"40"}),_("strong",{},p("web_game_title")));const s=_("p",{class:"learn-game-status"}),r=_("div",{class:"learn-game-stage"});n.append(a,s,r);let o=0,l=0;const u=()=>{const d=ux(e,o,10);s.textContent=`${p("web_game_round_fmt",o+1,10)} · ${p("web_game_score_fmt",l)}`;const h=_("div",{class:"learn-game-values mono"});for(const[w,I]of cx(d))h.append(_("code",{},`${w} = ${I}`));const g=_("div",{class:"group learn-game-answers"}),f=_("button",{class:"learn-game-true"},`✓ ${p("web_game_true")}`),b=_("button",{class:"learn-game-false"},`✗ ${p("web_game_false")}`);g.append(f,b);const x=_("div",{class:"learn-game-feedback",role:"status"}),v=w=>{f.disabled=b.disabled=!0;const I=w===d.answer;I&&l++,s.textContent=`${p("web_game_round_fmt",o+1,10)} · ${p("web_game_score_fmt",l)}`,x.className=`learn-game-feedback ${I?"right":"wrong"}`;const z=_("div",{class:"learn-game-steps mono"});ox(d.condition,d.values).forEach((T,O)=>z.append(_("div",{},`${O?"→ ":""}${T}`)));const k=_("button",{class:"primary"},o+1<10?p("web_game_next"):p("web_game_finish"));k.addEventListener("click",()=>{o++,o<10?u():c()}),x.replaceChildren(_("p",{},p(I?"web_game_right":"web_game_wrong")),z,k),k.focus()};f.addEventListener("click",()=>v(!0)),b.addEventListener("click",()=>v(!1)),r.replaceChildren(h,_("div",{class:"learn-game-condition mono"},d.condition),g,x)},c=()=>{s.textContent="";const d=_("button",{class:"primary"},p("web_game_again"));d.addEventListener("click",()=>{o=l=0,u()}),r.replaceChildren(_("p",{class:"learn-game-result"},p("web_game_done_fmt",l,10)),_("p",{},p(l===10?"web_game_perfect":l>=10*.7?"web_game_good":"web_game_practice")),d)},m=_("button",{class:"primary"},p("web_game_start"));return m.addEventListener("click",u),r.append(_("p",{},p("web_game_intro")),m),n}renderImages(e,t){const n=_("figure",{class:"learn-figure"}),a=_("div",{class:"learn-images"});for(const s of e){const r=yr(s);r&&a.append(_("img",{src:r,alt:"",loading:"lazy"}))}return n.append(a),t&&n.append(tt("figcaption",{},Pe(t))),n}renderGraphic(e,t,n){const a=_("figure",{class:"learn-figure"}),s=yr(e),r=n?yr(n):void 0;if(s&&r){const o=_("img",{class:"learn-graphic",src:s,alt:"",loading:"lazy"}),l=_("button",{class:"learn-graphic-toggle",type:"button",title:p("web_learn_graphic_labels"),"aria-pressed":"false"},o);l.addEventListener("click",()=>{const u=l.getAttribute("aria-pressed")!=="true";l.setAttribute("aria-pressed",String(u)),o.src=u?r:s}),a.append(l,_("p",{class:"learn-graphic-hint"},p("web_learn_graphic_labels")))}else s&&a.append(_("img",{class:"learn-graphic",src:s,alt:"",loading:"lazy"}));return t&&a.append(tt("figcaption",{},Pe(t))),a}withOpenButtons(e){for(const t of e.querySelectorAll("pre.lesson-code[data-open=editor]")){const n=t.textContent??"",a=_("button",{class:"learn-open-code"},p("web_learn_open_in_editor"));a.addEventListener("click",()=>this.host.openJavaCode(n)),t.after(a)}return e}renderDiagram(e,t){const n=ti(e),a=_("figure",{class:"learn-figure"});if(!n)return a;const s=this.host.preview(n);s&&a.append(_("div",{class:"learn-preview",dir:"ltr"},s)),t&&a.append(tt("figcaption",{},Pe(t)));const r=_("button",{},p("web_learn_open_in_editor"));return r.addEventListener("click",()=>this.host.openDiagram(n,e)),a.append(r),a}renderExercise(e){const t=_("section",{class:"learn-exercise","data-exercise":e.id}),n=()=>be.exercise(e.id),a=_("span",{class:"learn-badge"},`✓ ${p("web_learn_solved")}`);a.hidden=!n().done;const s=e.code==="java"?p("web_learn_solve_in_code",p("web_live_title")):p("web_learn_solve_in_editor",p("web_editor_title"));t.append(_("h4",{},`${p("web_learn_exercise")}: ${e.title}`,a),_("p",{class:"learn-where"},s),tt("div",{class:"learn-text"},Tn(e.task)));const r=_("div",{class:"learn-result",role:"status"}),o=_("div",{class:"learn-hints"}),l=_("div",{class:"group"}),u=_("button",{class:"primary"},p("web_learn_open_exercise"));u.addEventListener("click",()=>{const d=n().xml;let h=uc(e);if(d)try{h=El(d)}catch{}this.host.openExercise(e,h)});const c=_("button",{},p("web_learn_check"));if(c.addEventListener("click",()=>{const d=this.host.exerciseDocument(e.id);if(!d){r.className="learn-result info",r.textContent=p("web_learn_open_first");return}if(d.elements.every(Bl)){r.className="learn-result info",r.textContent=p("web_learn_empty");return}this.host.stopSimulation();const h=nx(d,e.tests,this.host.subprogramsFor(e.id),Fa),g=ix(d),f=e.requires.map(v=>v==="forZaehlSchleife"?"forSchleife":v).filter(v=>v in S&&!g.has(S[v])),b=e.loopDepth!==void 0&&Po(d.elements)v.passed)&&f.length===0&&!b;this.showResult(r,h,f,x,b),x&&(be.updateExercise(e.id,{done:!0}),a.hidden=!1)}),l.append(u,c),e.hints.length>0){const d=_("button",{},p("web_learn_hint"));d.addEventListener("click",()=>{const h=o.children.length;if(h>=e.hints.length)return;const g=e.hints.length>1?`**${p("web_learn_hint_fmt",h+1,e.hints.length)}:** `:"";o.append(tt("aside",{class:"lesson-note"},Tn(g+e.hints[h]))),d.textContent=p("web_learn_hint_more"),d.toggleAttribute("disabled",h+1>=e.hints.length)}),l.append(d)}const m=_("button",{class:"danger-text"},p("web_learn_reset"));if(m.addEventListener("click",()=>{if(m.dataset.confirm!=="1"){m.dataset.confirm="1",m.textContent=p("web_learn_reset_confirm"),setTimeout(()=>{m.dataset.confirm="",m.textContent=p("web_learn_reset")},4e3);return}be.resetExercise(e.id),this.host.resetExercise(e.id,uc(e)),a.hidden=!0,r.replaceChildren(),r.className="learn-result",m.dataset.confirm="",m.textContent=p("web_learn_reset")}),l.append(m),t.append(l,o,r),$u()&&e.solution){const d=ti(e.solution);if(d){const h=_("details",{class:"learn-solution"},_("summary",{},p("web_learn_solution")));h.addEventListener("toggle",()=>{if(!h.open||h.querySelector(".learn-preview"))return;const g=this.host.preview(d);g&&h.append(_("div",{class:"learn-preview",dir:"ltr"},g));const f=_("button",{},p("web_learn_open_in_editor"));f.addEventListener("click",()=>{this.host.openDiagram(d,e.solution);for(const b of e.subprograms){const x=ti(b);x&&this.host.openDiagram(x,b)}});for(const b of e.subprograms){const x=ti(b),v=x&&this.host.preview(x);v&&h.append(_("div",{class:"learn-preview",dir:"ltr"},v))}h.append(f)}),t.append(h)}}return t}showResult(e,t,n,a,s){var o,l,u,c,m;e.className="learn-result "+(a?"ok":"fail"),e.replaceChildren(_("p",{class:"learn-result-head"},a?`🎉 ${p("web_learn_passed")}`:p("web_learn_failed")));for(const d of n)e.append(_("p",{},`✗ ${p("web_learn_missing_fmt",bZ(S[d]))}`));s&&e.append(_("p",{},`✗ ${p("web_visubot_depth_fmt",s)}`));const r=_("ul",{class:"learn-tests",dir:"auto"});for(const d of t){const h=d.test.world?t.filter(x=>x.test.world).indexOf(d)+1:0,g=d.test.world?`🗺 ${p("web_visubot_world_fmt",h)}`:d.test.actions?`🤖 ${p("web_visubot_actions")}`:d.test.sensors?`🎛 ${Object.entries(d.test.sensors).map(([x,v])=>`mbot.${x}() = ${v.join(" → ")}`).join(", ")}`:d.test.drive?`🤖 ${p("web_visubot_drive")}`:d.test.inputs.length?p("web_learn_input_fmt",d.test.inputs.join(", ")):p("web_learn_no_input"),f=[`${d.passed?"✓":"✗"} ${g}`],b=_("div",{class:"learn-test-detail"});if(d.test.drive&&b.append(_("span",{},`${p("web_learn_expected")}: `,_("code",{},X1(d.test.drive)||"–")),_("span",{},`${p("web_learn_actual")}: `,_("code",{},X1(d.result.drive??[])||"–"))),d.test.actions&&b.append(_("span",{},`${p("web_learn_expected")}: `,_("code",{},X1(d.test.actions)||"–")),_("span",{},`${p("web_learn_actual")}: `,_("code",{},X1(d.result.actions??[])||"–"))),d.test.led!==void 0){const x=v=>p(v?"web_visubot_led_on":"web_visubot_led_off");b.append(_("span",{},`💡 ${p("web_learn_expected")}: ${x(d.test.led)} · ${p("web_learn_actual")}: ${x(d.result.led)}`))}if(d.test.tone!==void 0){const x=v=>p(v?"web_visubot_tone_yes":"web_visubot_tone_no");b.append(_("span",{},`🔊 ${p("web_learn_expected")}: ${x(d.test.tone)} · ${p("web_learn_actual")}: ${x(d.result.tone)}`))}d.test.screen!==void 0&&b.append(_("span",{},`📺 ${p("web_learn_expected")}: `,_("code",{},d.test.screen),` · ${p("web_learn_actual")}: `,_("code",{},d.result.screen??"–"))),d.test.world&&(((l=(o=Fa(d.test.world))==null?void 0:o.goals)!=null&&l.length||(c=(u=Fa(d.test.world))==null?void 0:u.targets)!=null&&c.length)&&b.append(_("span",{},d.result.atGoal?`✓ ${p("web_visubot_goal_reached")}`:`✗ ${p("web_visubot_goal_missed")}`)),d.result.bumps&&b.append(_("span",{class:"learn-error"},`⚠︎ ${p("web_visubot_bumps")}: ${d.result.bumps}`))),(!d.test.drive&&!d.test.world&&!d.test.sensors&&!d.test.actions||d.result.outputs.length)&&b.append(_("span",{},`${p("web_learn_expected")}: `,_("code",{},d.test.expected.join(" | ")||"–")),_("span",{},`${p("web_learn_actual")}: `,_("code",{},d.result.outputs.join(" | ")||"–")));for(const x of d.test.files??[])b.append(_("span",{},`📄 ${x.name}, ${p("web_learn_expected")}: `,_("code",{},x.lines.join(" | ")||"–")),_("span",{},`📄 ${x.name}, ${p("web_learn_actual")}: `,_("code",{},Jh((m=d.result.files)==null?void 0:m.get(x.name)).join(" | ")||"–")));d.result.error&&b.append(_("span",{class:"learn-error"},t1(d.result.error))),d.result.missingInput&&b.append(_("span",{class:"learn-error"},p("web_learn_missing_input"))),d.result.tooManySteps&&b.append(_("span",{class:"learn-error"},p("web_learn_too_many_steps"))),!d.passed&&d.result.unusedInputs&&b.append(_("span",{class:"learn-error"},p("web_learn_unused_input"))),r.append(_("li",{class:d.passed?"ok":"fail"},...f,b))}e.append(r)}renderCompetences(e){const t=_("aside",{class:"learn-competences"},_("p",{class:"learn-competences-title"},p("web_learn_competences_intro"))),n=_("ul",{});for(const a of e)n.append(tt("li",{},Pe(a)));return t.append(n),t}renderChecklist(e,t,n){const a=[{value:"umbrella",icon:"☂️",label:p("web_learn_rating_umbrella")},{value:"cloud",icon:"⛅",label:p("web_learn_rating_cloud")},{value:"sun",icon:"☀️",label:p("web_learn_rating_sun")}],s=_("div",{class:"learn-checklist-wrap"}),r=_("p",{class:"learn-rating-legend"});for(const l of a)r.append(_("span",{},`${l.icon} ${l.label}`));const o=_("ul",{class:"learn-checklist"});return s.append(r,o),e.forEach((l,u)=>{var v;const c=`${t}-${u}`,m=n?(v=be.lesson(n.id).checks)==null?void 0:v[c]:void 0;let d=m===!0?"sun":m||void 0;const h=tt("span",{class:"learn-check-text"},Pe(l.text)),g=_("span",{class:"learn-rating",role:"group","aria-label":h.textContent??""}),f=a.map(w=>{const I=_("button",{class:"learn-rating-button",title:w.label,"aria-label":w.label},w.icon);return I.addEventListener("click",()=>{if(d=d===w.value?void 0:w.value,b(),!n)return;const z={...be.lesson(n.id).checks??{}};d?z[c]=d:delete z[c],be.updateLesson(n.id,{checks:Object.keys(z).length?z:void 0})}),I}),b=()=>{f.forEach((w,I)=>w.setAttribute("aria-pressed",String(a[I].value===d))),x.dataset.rating=d??""};g.append(...f);const x=_("li",{},h,g);if(n&&l.step!==void 0){const w=l.step,I=p("web_learn_step_fmt",w+1,n.steps[w].title),z=_("button",{class:"link-button learn-check-link",title:I,"aria-label":`${p("web_learn_review")}: ${I}`},p("web_learn_review"));z.addEventListener("click",()=>{this.returnTo={lesson:n.id,step:be.lesson(n.id).step,scroll:this.body.scrollTop},this.goToStep(n,w)}),x.append(z)}b(),o.append(x)}),s}renderQuiz(e,t,n){const a=_("div",{class:"learn-quiz"}),s=_("p",{class:"learn-score",role:"status"}),r=()=>n?be.lesson(n.id).quiz??{}:{},o=_("div",{class:"learn-review"}),l=()=>{const u=r(),c=(f,b)=>f.pairs?f.pairs.every((x,v)=>u[`${t}-${b}-${v}`]!==void 0):u[`${t}-${b}`]!==void 0,m=(f,b)=>{var x;return!!(f.pairs?f.pairs.every((v,w)=>cc(f)[u[`${t}-${b}-${w}`]]===f.pairs[w].right):(x=f.options[u[`${t}-${b}`]])!=null&&x.correct)},d=e.filter(c).length,h=e.filter(m).length,g=d===e.length;s.textContent=g?p("web_learn_score_fmt",h,e.length):"",o.replaceChildren(),g&&n&&this.fillChecklistReview(o,n,e,f=>m(e[f],f))};return e.forEach((u,c)=>{const m=`${t}-${c}`,d=_("fieldset",{},tt("legend",{},Pe(u.question))),h=tt("p",{class:"learn-explanation"},Pe(u.explanation??""));if(u.pairs){d.append(this.renderMatch(u,m,r,n,h,l),h),a.append(d);return}const g=f=>{d.querySelectorAll("button").forEach((b,x)=>{b.classList.toggle("right",f!==void 0&&u.options[x].correct),b.classList.toggle("wrong",f===x&&!u.options[x].correct),b.setAttribute("aria-pressed",String(f===x))}),h.hidden=f===void 0||!u.explanation};u.options.forEach((f,b)=>{const x=tt("button",{class:"learn-option"},Pe(f.text));x.addEventListener("click",()=>{n&&be.updateLesson(n.id,{quiz:{...r(),[m]:b}}),g(b),l()}),d.append(x)}),d.append(h),g(r()[m]),a.append(d)}),a.append(s,o),l(),a}fillChecklistReview(e,t,n,a){const s={sun:"☀️",cloud:"⛅",umbrella:"☂️"},r=be.lesson(t.id).checks??{},o=[];let l=0;t.steps.forEach((u,c)=>u.blocks.forEach((m,d)=>{m.kind==="checklist"&&m.items.forEach((h,g)=>{const f=r[`${c}-${d}-${g}`],b=f===!0?"sun":f||void 0,x=h.step===void 0?[]:n.map((k,T)=>k.step===h.step?T:-1).filter(k=>k>=0),v=x.filter(k=>!a(k));let w="";b==="sun"&&v.length?w=p("web_learn_review_overrated_fmt",v.map(k=>k+1).join(", ")):b&&b!=="sun"&&x.length&&!v.length&&(w=p("web_learn_review_underrated")),w&&l++;const I=_("li",{class:w?"learn-review-deviation":""}),z=tt("span",{class:"learn-check-text"},Pe(h.text));if(w&&z.append(_("br",{}),_("em",{},w)),I.append(z,_("span",{class:"learn-review-icon","aria-label":p(b?`web_learn_rating_${b}`:"web_learn_review_unrated")},b?s[b]:"–")),w&&b==="sun"&&h.step!==void 0){const k=h.step,T=_("button",{class:"link-button learn-check-link"},p("web_learn_review"));T.addEventListener("click",()=>{this.returnTo={lesson:t.id,step:be.lesson(t.id).step,scroll:this.body.scrollTop},this.goToStep(t,k)}),I.append(T)}o.push(I)})})),o.length&&e.append(_("p",{class:"learn-review-title"},`📋 ${p("web_learn_review_title")}`),_("p",{},p(l?"web_learn_review_hint":"web_learn_review_match")),_("ul",{class:"learn-checklist"},...o))}renderMatch(e,t,n,a,s,r){const o=e.pairs,l=cc(e),u=_("div",{class:"learn-match"});let c={};const m=()=>a?n():c,d=b=>a?be.updateLesson(a.id,{quiz:b}):c=b,h=b=>m()[`${t}-${b}`],g=o.map(b=>{const x=_("select",{class:"learn-match-select"});x.append(_("option",{value:""},"–")),l.forEach((w,I)=>x.append(_("option",{value:String(I)},w)));const v=tt("label",{class:"learn-match-left"},Pe(b.left));return v.append(x),u.append(v),x}),f=()=>{const b=o.every((x,v)=>h(v)!==void 0);g.forEach((x,v)=>{const w=h(v);x.value=w===void 0?"":String(w),x.classList.toggle("right",b&&l[w]===o[v].right),x.classList.toggle("wrong",b&&l[w]!==o[v].right)}),s.hidden=!b||!e.explanation};return g.forEach((b,x)=>b.addEventListener("change",()=>{const v={...m()};b.value===""?delete v[`${t}-${x}`]:v[`${t}-${x}`]=Number(b.value),d(v),f(),r()})),f(),u}}function cc(i){return(i.pairs??[]).map(e=>e.right).sort((e,t)=>e.localeCompare(t,"de"))}const yZ=""+new URL("visubot-CyGFOI9V.webp",import.meta.url).href,u0="visustruct.visubot";function c0(){try{return localStorage.getItem(u0)}catch{return null}}function ui(){const i=c0();return i==="1"||i==="kurs"?"on":"off"}const dg=()=>c0()==="2";function hg(){try{localStorage.setItem(u0,"2")}catch{}}const wZ=()=>c0()!==null;function Ir(i){try{localStorage.setItem(u0,i==="on"?"1":"0")}catch{}}const zZ=` VisuBot `,Hn=()=>ui()!=="off",mc=i=>i.replace(/[&<>"]/g,e=>({"&":"&","<":"<",">":">",'"':"""})[e]);function Zo(){const i=dg()?"object":ui(),e=(n,a)=>`${a} `,t={off:"web_visubot_world_visustruct_hint",on:"web_visubot_world_visubot_hint",object:"web_visuobject_world_hint"}[i];return`
${e("off","VisuStruct")}${e("on","🤖 VisuBot")}${e("object","VisuObject")}
- ${mc(p(t))} `}class yZ{constructor(e=Ii){y(this,"element");y(this,"world");y(this,"view");y(this,"loading");y(this,"status");y(this,"stage");y(this,"picker");y(this,"applied",0);y(this,"sent",0);y(this,"liveStatus");y(this,"viewport");y(this,"stopListening");y(this,"realSensors");y(this,"controls",{getBrightness:50,getLoudness:0,getPitch:0,getRoll:0});y(this,"pressTimers",new Map);y(this,"check");y(this,"checking",!1);y(this,"onWorldChange");this.world=new ds(e),this.element=document.createElement("section"),this.element.className="visubot",this.element.innerHTML=`${p("web_visubot_world")}
${p("web_visubot_world_in_preview")}
${wZ()}${zZ()}`,this.stage=this.element.querySelector(".visubot-stage"),this.picker=this.element.querySelector(".visubot-worlds"),this.status=this.element.querySelector(".visubot-status"),this.liveStatus=this.element.querySelector(".visubot-live"),this.viewport=this.element.querySelector(".visubot-viewport"),this.stopListening=ge.listen(()=>this.updateLive()),this.setupControls(),this.check=this.element.querySelector(".visubot-check"),this.setupCheck(),this.updateLive(),this.updateStatus()}show(){this.loading??(this.loading=ee(async()=>{const{Robot3D:e}=await import("./robot3d-DUSoN3EA.js");return{Robot3D:e}},[],import.meta.url).then(({Robot3D:e})=>{this.view=new e(this.stage),this.view.setWorld(this.world.setup),this.view.place(this.world.pose,this.world.trail),this.view.setLeds(this.world.leds)}).catch(()=>{this.stage.textContent=p("web_visubot_no_3d")}))}restoreViewport(){this.viewport.parentElement!==this.element&&this.liveStatus.after(this.viewport)}setWorlds(e){this.picker.replaceChildren(),this.picker.hidden=e.length<2,e.forEach((t,n)=>{const a=document.createElement("button");a.textContent=p("web_visubot_world_fmt",n+1),a.addEventListener("click",()=>this.useWorld(t,a)),this.picker.append(a)}),this.useWorld(e[0]??Ii,this.picker.firstElementChild)}useWorld(e,t){var n,a,s,r,o;for(const l of this.picker.children)l.classList.toggle("active",l===t);e!==this.world.setup&&(this.world=new ds(e),this.applied=0,this.sent=0,(n=this.view)==null||n.setWorld(e),(a=this.view)==null||a.place(this.world.pose,this.world.trail),(s=this.view)==null||s.setLed(void 0),(r=this.view)==null||r.setScreen(void 0),this.updateStatus(),(o=this.onWorldChange)==null||o.call(this))}reset(){var e,t,n;this.world.reset(),this.applied=0,this.sent=0,this.realSensors=void 0,(e=this.view)==null||e.place(this.world.pose,this.world.trail),(t=this.view)==null||t.setLed(void 0),(n=this.view)==null||n.setScreen(void 0),this.updateStatus()}prepare(e){e.robotSensors={...this.controls,...this.world.sensors()}}setupControls(){for(const e of this.element.querySelectorAll(".visubot-controls input[type=range]")){const t=e.parentElement.querySelector("output"),n=()=>{this.controls[e.name]=Number(e.value),t.textContent=e.value};e.addEventListener("input",n),n()}for(const e of this.element.querySelectorAll(".visubot-controls button[name]"))e.addEventListener("click",()=>{const t=e.name;this.controls[t]=!0,e.classList.add("pressed"),window.clearTimeout(this.pressTimers.get(t)),this.pressTimers.set(t,window.setTimeout(()=>{this.controls[t]=!1,e.classList.remove("pressed")},1e3))})}setupCheck(){for(const e of this.check.querySelectorAll("button[data-py]"))e.addEventListener("click",()=>{const{after:t,wait:n}=e.dataset;ge.run(e.dataset.py).then(()=>t?new Promise(a=>setTimeout(a,Number(n))).then(()=>ge.run(t)):void 0).catch(a=>this.liveFailed(a))});this.check.addEventListener("toggle",()=>void this.readCheck())}async readCheck(){if(!this.checking){this.checking=!0;try{for(;this.check.open&&ge.connected;){for(const e of this.check.querySelectorAll("[data-sensor]")){if(!this.check.open||!ge.connected)break;const t=e.dataset.sensor,n=await ge.ask(Ot[t].python).catch(()=>{});n!==void 0&&(e.textContent=typeof Ot[t].simulated=="boolean"?n===!0||typeof n=="number"&&n!==0?"✓":"–":String(typeof n=="number"?Math.round(n*10)/10:n))}await new Promise(e=>setTimeout(e,200))}}finally{this.checking=!1}}}get live(){return ge.connected}async prepareLive(e,t=[]){const n={};for(const a of new Set(["getDistance","getLine",...t])){const s=await ge.ask(Ot[a].python);typeof Ot[a].simulated=="boolean"?n[a]=s===!0||typeof s=="number"&&s!==0:typeof Ot[a].simulated=="string"?n[a]=typeof s=="string"?s:String(Ot[a].simulated):n[a]=typeof s=="number"?a==="getDistance"?Math.round(s):s:0}this.realSensors=n,e.robotSensors={...this.controls,...this.world.sensors(),...n}}async drive(e){for(;this.sentsetTimeout(n,t.args[0]))}}liveFailed(e){ge.disconnect(e instanceof Error?e.message:String(e))}updateLive(){this.liveStatus.textContent=pg(),this.liveStatus.classList.toggle("connected",ge.connected),this.check.hidden=!ge.connected,ge.connected||(this.check.open=!1),this.updateStatus()}follow(e,t){var a,s,r,o;for(;this.appliedl!==0);this.world.tick(i0),n&&((o=this.view)==null||o.moveTo(this.world.pose,this.world.trail,t)),this.updateStatus()}dispose(){var e;this.stopListening();for(const t of this.pressTimers.values())window.clearTimeout(t);(e=this.view)==null||e.dispose(),this.view=void 0,this.loading=void 0}updateStatus(){const e=this.world.lineState().toString(2).padStart(4,"0"),t=[`${p("web_visubot_distance")}: ${this.world.distance()} cm`,`${p("web_visubot_line")}: ${e}`];this.world.bumps>0&&t.push(`⚠︎ ${p("web_visubot_bumps")}: ${this.world.bumps}`),this.world.screen!==void 0&&t.push(`📺 ${this.world.screen}`),this.realSensors&&ge.connected&&t.push(`🤖 ${p("web_visubot_distance")}: ${this.realSensors.getDistance} cm · ${p("web_visubot_line")}: ${Number(this.realSensors.getLine).toString(2).padStart(4,"0")}`),this.status.textContent=t.join(" · ")}}let H1;function gg(i,e){try{H1??(H1=new AudioContext);const t=H1.createOscillator(),n=H1.createGain();t.type="square",t.frequency.value=Math.max(20,Math.min(2e4,i)),n.gain.value=.05,t.connect(n).connect(H1.destination);const a=H1.currentTime+Math.min(Math.max(e,0),5e3)/1e3;t.start(),t.stop(a)}catch{}}function wZ(){const i=(t,n,a,s,r)=>`${p(n)} `,e=(t,n,a)=>`${n} `;return`🎛 ${p("web_visubot_controls")}
+ ${mc(p(t))} `}class IZ{constructor(e=Ii){y(this,"element");y(this,"world");y(this,"view");y(this,"loading");y(this,"status");y(this,"stage");y(this,"picker");y(this,"applied",0);y(this,"sent",0);y(this,"liveStatus");y(this,"viewport");y(this,"stopListening");y(this,"realSensors");y(this,"controls",{getBrightness:50,getLoudness:0,getPitch:0,getRoll:0});y(this,"pressTimers",new Map);y(this,"check");y(this,"checking",!1);y(this,"onWorldChange");this.world=new ds(e),this.element=document.createElement("section"),this.element.className="visubot",this.element.innerHTML=`${p("web_visubot_world")}
${p("web_visubot_world_in_preview")}
${kZ()}${SZ()}`,this.stage=this.element.querySelector(".visubot-stage"),this.picker=this.element.querySelector(".visubot-worlds"),this.status=this.element.querySelector(".visubot-status"),this.liveStatus=this.element.querySelector(".visubot-live"),this.viewport=this.element.querySelector(".visubot-viewport"),this.stopListening=ge.listen(()=>this.updateLive()),this.setupControls(),this.check=this.element.querySelector(".visubot-check"),this.setupCheck(),this.updateLive(),this.updateStatus()}show(){this.loading??(this.loading=ee(async()=>{const{Robot3D:e}=await import("./robot3d-F7Of_tVr.js");return{Robot3D:e}},[],import.meta.url).then(({Robot3D:e})=>{this.view=new e(this.stage),this.view.setWorld(this.world.setup),this.view.place(this.world.pose,this.world.trail),this.view.setLeds(this.world.leds)}).catch(()=>{this.stage.textContent=p("web_visubot_no_3d")}))}restoreViewport(){this.viewport.parentElement!==this.element&&this.liveStatus.after(this.viewport)}setWorlds(e){this.picker.replaceChildren(),this.picker.hidden=e.length<2,e.forEach((t,n)=>{const a=document.createElement("button");a.textContent=p("web_visubot_world_fmt",n+1),a.addEventListener("click",()=>this.useWorld(t,a)),this.picker.append(a)}),this.useWorld(e[0]??Ii,this.picker.firstElementChild)}useWorld(e,t){var n,a,s,r,o;for(const l of this.picker.children)l.classList.toggle("active",l===t);e!==this.world.setup&&(this.world=new ds(e),this.applied=0,this.sent=0,(n=this.view)==null||n.setWorld(e),(a=this.view)==null||a.place(this.world.pose,this.world.trail),(s=this.view)==null||s.setLed(void 0),(r=this.view)==null||r.setScreen(void 0),this.updateStatus(),(o=this.onWorldChange)==null||o.call(this))}reset(){var e,t,n;this.world.reset(),this.applied=0,this.sent=0,this.realSensors=void 0,(e=this.view)==null||e.place(this.world.pose,this.world.trail),(t=this.view)==null||t.setLed(void 0),(n=this.view)==null||n.setScreen(void 0),this.updateStatus()}prepare(e){e.robotSensors={...this.controls,...this.world.sensors()}}setupControls(){for(const e of this.element.querySelectorAll(".visubot-controls input[type=range]")){const t=e.parentElement.querySelector("output"),n=()=>{this.controls[e.name]=Number(e.value),t.textContent=e.value};e.addEventListener("input",n),n()}for(const e of this.element.querySelectorAll(".visubot-controls button[name]"))e.addEventListener("click",()=>{const t=e.name;this.controls[t]=!0,e.classList.add("pressed"),window.clearTimeout(this.pressTimers.get(t)),this.pressTimers.set(t,window.setTimeout(()=>{this.controls[t]=!1,e.classList.remove("pressed")},1e3))})}setupCheck(){for(const e of this.check.querySelectorAll("button[data-py]"))e.addEventListener("click",()=>{const{after:t,wait:n}=e.dataset;ge.run(e.dataset.py).then(()=>t?new Promise(a=>setTimeout(a,Number(n))).then(()=>ge.run(t)):void 0).catch(a=>this.liveFailed(a))});this.check.addEventListener("toggle",()=>void this.readCheck())}async readCheck(){if(!this.checking){this.checking=!0;try{for(;this.check.open&&ge.connected;){for(const e of this.check.querySelectorAll("[data-sensor]")){if(!this.check.open||!ge.connected)break;const t=e.dataset.sensor,n=await ge.ask(Ot[t].python).catch(()=>{});n!==void 0&&(e.textContent=typeof Ot[t].simulated=="boolean"?n===!0||typeof n=="number"&&n!==0?"✓":"–":String(typeof n=="number"?Math.round(n*10)/10:n))}await new Promise(e=>setTimeout(e,200))}}finally{this.checking=!1}}}get live(){return ge.connected}async prepareLive(e,t=[]){const n={};for(const a of new Set(["getDistance","getLine",...t])){const s=await ge.ask(Ot[a].python);typeof Ot[a].simulated=="boolean"?n[a]=s===!0||typeof s=="number"&&s!==0:typeof Ot[a].simulated=="string"?n[a]=typeof s=="string"?s:String(Ot[a].simulated):n[a]=typeof s=="number"?a==="getDistance"?Math.round(s):s:0}this.realSensors=n,e.robotSensors={...this.controls,...this.world.sensors(),...n}}async drive(e){for(;this.sentsetTimeout(n,t.args[0]))}}liveFailed(e){ge.disconnect(e instanceof Error?e.message:String(e))}updateLive(){this.liveStatus.textContent=pg(),this.liveStatus.classList.toggle("connected",ge.connected),this.check.hidden=!ge.connected,ge.connected||(this.check.open=!1),this.updateStatus()}follow(e,t){var a,s,r,o;for(;this.appliedl!==0);this.world.tick(i0),n&&((o=this.view)==null||o.moveTo(this.world.pose,this.world.trail,t)),this.updateStatus()}dispose(){var e;this.stopListening();for(const t of this.pressTimers.values())window.clearTimeout(t);(e=this.view)==null||e.dispose(),this.view=void 0,this.loading=void 0}updateStatus(){const e=this.world.lineState().toString(2).padStart(4,"0"),t=[`${p("web_visubot_distance")}: ${this.world.distance()} cm`,`${p("web_visubot_line")}: ${e}`];this.world.bumps>0&&t.push(`⚠︎ ${p("web_visubot_bumps")}: ${this.world.bumps}`),this.world.screen!==void 0&&t.push(`📺 ${this.world.screen}`),this.realSensors&&ge.connected&&t.push(`🤖 ${p("web_visubot_distance")}: ${this.realSensors.getDistance} cm · ${p("web_visubot_line")}: ${Number(this.realSensors.getLine).toString(2).padStart(4,"0")}`),this.status.textContent=t.join(" · ")}}let H1;function gg(i,e){try{H1??(H1=new AudioContext);const t=H1.createOscillator(),n=H1.createGain();t.type="square",t.frequency.value=Math.max(20,Math.min(2e4,i)),n.gain.value=.05,t.connect(n).connect(H1.destination);const a=H1.currentTime+Math.min(Math.max(e,0),5e3)/1e3;t.start(),t.stop(a)}catch{}}function kZ(){const i=(t,n,a,s,r)=>`${p(n)} `,e=(t,n,a)=>`${n} `;return`🎛 ${p("web_visubot_controls")}
${p("web_visubot_controls_hint")}
${i("getBrightness","web_visubot_sensor_brightness",0,100,50)}
${i("getLoudness","web_visubot_sensor_loudness",0,100,0)}
@@ -63555,7 +63612,7 @@ ${a}`));this.body.append(s),this.foldReference(s)}}foldReference(e){const t="vis
${e("isJoystickLeft","←","web_visubot_sensor_joy_left")}${e("isJoystickRight","→","web_visubot_sensor_joy_right")}
${e("isShaken",`〰 ${p("web_visubot_shake")}`,"web_visubot_sensor_shake")}
- `}function zZ(){const i=a=>a.replace(/"/g,"""),e=(a,s,r,o=1e3)=>`🔧 ${p("web_visubot_check")}
${p("web_visubot_check_hint")}
${e("cyberpi.led.on(255, 0, 0)","web_visubot_el_led")}${e("cyberpi.led.off()","web_visubot_el_led_off")}
@@ -63565,13 +63622,13 @@ ${a}`));this.body.append(s),this.foldReference(s)}}foldReference(e){const t="vis
${e("mbot2.drive_power(30, -30)","web_visubot_check_forward",t)}${e("mbot2.drive_power(30, 30)","web_visubot_check_spin",t)}
- `}function pg(){return ge.connecting?p("web_visubot_connecting"):ge.connected?`✓ ${p("web_visubot_connected")}`:ge.error?`⚠︎ ${p("web_visubot_link_error")}: ${ge.error}`:""}async function IZ(){if(ge.connected||ge.connecting)return ge.disconnect();try{await ge.connect()}catch(i){await ge.disconnect(i.name==="NotFoundError"?void 0:i.message)}}const ht=i=>()=>Oe(S.anweisung,{textLines:[i]}),kZ=[{key:"web_visubot_el_forward",group:"drive",type:S.anweisung,make:ht("mbot.forward()")},{key:"web_visubot_el_backward",group:"drive",type:S.anweisung,make:ht("mbot.backward()")},{key:"web_visubot_el_right",group:"drive",type:S.anweisung,make:ht("mbot.turnRight()")},{key:"web_visubot_el_left",group:"drive",type:S.anweisung,make:ht("mbot.turnLeft()")},{key:"web_visubot_el_drive",group:"wheels",type:S.anweisung,make:ht("mbot.drive(30, 30)")},{key:"web_visubot_el_stop",group:"wheels",type:S.anweisung,make:ht("mbot.stop()")},{key:"web_visubot_el_led",group:"output",type:S.anweisung,make:ht("mbot.setLed(255, 0, 0)")},{key:"web_visubot_el_led_off",group:"output",type:S.anweisung,make:ht("mbot.ledOff()")},{key:"web_visubot_el_led_color",group:"output",type:S.anweisung,make:ht('mbot.led(0).setColor("grün")')},{key:"web_visubot_el_tone",group:"output",type:S.anweisung,make:ht("mbot.playTone(440, 300)")},{key:"web_visubot_el_text",group:"output",type:S.anweisung,make:ht('mbot.showText("Hallo")')},{key:"web_visubot_el_wait",group:"wait",type:S.anweisung,make:ht("mbot.pause(100)")},{key:"web_visubot_el_emotion",group:"emotion",type:S.anweisung,make:ht('mbot.emotion("smile")')},{key:"web_visubot_el_timer",group:"wait",type:S.anweisung,make:ht("mbot.resetTimer()")}],fg=[{key:"web_visubot_sensor_distance",group:"distance",text:"mbot.getDistance()"},{key:"web_visubot_sensor_line",group:"line",text:"mbot.getLine()"},{key:"web_visubot_sensor_line_left",group:"line",text:"mbot.isLineLeft()"},{key:"web_visubot_sensor_line_right",group:"line",text:"mbot.isLineRight()"},{key:"web_visubot_sensor_color",group:"color",get text(){return`mbot.getColor().equals("${ch("red")}")`}},{key:"web_visubot_sensor_button_a",group:"buttons",text:"mbot.isButtonA()"},{key:"web_visubot_sensor_button_b",group:"buttons",text:"mbot.isButtonB()"},{key:"web_visubot_sensor_joy_up",group:"buttons",text:"mbot.isJoystickUp()"},{key:"web_visubot_sensor_joy_down",group:"buttons",text:"mbot.isJoystickDown()"},{key:"web_visubot_sensor_joy_left",group:"buttons",text:"mbot.isJoystickLeft()"},{key:"web_visubot_sensor_joy_right",group:"buttons",text:"mbot.isJoystickRight()"},{key:"web_visubot_sensor_brightness",group:"light",text:"mbot.getBrightness()"},{key:"web_visubot_sensor_loudness",group:"light",text:"mbot.getLoudness()"},{key:"web_visubot_sensor_pitch",group:"tilt",text:"mbot.getPitch()"},{key:"web_visubot_sensor_roll",group:"tilt",text:"mbot.getRoll()"},{key:"web_visubot_sensor_shake",group:"tilt",text:"mbot.isShaken()"},{key:"web_visubot_sensor_timer",group:"timer",text:"mbot.getTimer()"},{key:"web_visubot_sensor_battery",group:"timer",text:"mbot.getBattery()"}],la=()=>typeof window.showDirectoryPicker=="function";class Us{constructor(e){this.handle=e}get name(){return this.handle.name}async list(){const e=[];for await(const t of this.handle.values())t.name.startsWith(".")||e.push({kind:t.kind,name:t.name});return e}async dir(e,t=!1){return new Us(await this.handle.getDirectoryHandle(e,{create:t}))}async read(e){return(await(await this.handle.getFileHandle(e)).getFile()).text()}async write(e,t){const a=await(await this.handle.getFileHandle(e,{create:!0})).createWritable();await a.write(t),await a.close()}async has(e){try{return await this.handle.getFileHandle(e),!0}catch{try{return await this.handle.getDirectoryHandle(e),!0}catch{return!1}}}async remove(e){await this.handle.removeEntry(e,{recursive:!0})}}const SZ="visustruct-workspace";function TZ(){return new Promise((i,e)=>{const t=indexedDB.open(SZ,1);t.onupgradeneeded=()=>{t.result.createObjectStore("files"),t.result.createObjectStore("meta")},t.onsuccess=()=>i(t.result),t.onerror=()=>e(t.error)})}async function Tt(i,e,t){const n=await TZ();return new Promise((a,s)=>{const r=t(n.transaction(i,e).objectStore(i));r.onsuccess=()=>a(r.result),r.onerror=()=>s(r.error)})}class m0{constructor(e,t){this.name=e,this.path=t}key(e){return this.path+e}async list(){const e=await Tt("files","readonly",n=>n.getAllKeys()),t=new Map;for(const n of e){if(!n.startsWith(this.path)||n===this.path)continue;const a=n.slice(this.path.length),s=a.indexOf("/"),r=s<0?a:a.slice(0,s);t.has(r)||t.set(r,{kind:s<0?"file":"directory",name:r})}return[...t.values()]}async dir(e,t=!1){const n=this.key(e)+"/";if(!(await Tt("files","readonly",s=>s.count(n))>0)){if(!t)throw new DOMException(e,"NotFoundError");await Tt("files","readwrite",s=>s.put("",n))}return new m0(e,n)}async read(e){const t=await Tt("files","readonly",n=>n.get(this.key(e)));if(typeof t!="string")throw new DOMException(e,"NotFoundError");return t}async write(e,t){await Tt("files","readwrite",n=>n.put(t,this.key(e)))}async has(e){const t=await Tt("files","readonly",a=>a.count(this.key(e))),n=await Tt("files","readonly",a=>a.count(this.key(e)+"/"));return t+n>0}async remove(e){const t=this.key(e);await Tt("files","readwrite",n=>n.delete(t)),await Tt("files","readwrite",n=>n.delete(IDBKeyRange.bound(t+"/",t+"/")))}}async function _Z(i,e="folder"){const t=await window.showDirectoryPicker({id:e==="folder"?"visustruct-workspace":e,mode:"readwrite"}),n=i&&t.name!==i?await t.getDirectoryHandle(i,{create:!0}):t;return await Tt("meta","readwrite",a=>a.put(n,e)),{kind:"folder",root:new Us(n)}}function dc(){return{kind:"browser",root:new m0("VisuStruct","")}}async function OZ(i="folder"){var e;try{const t=await Tt("meta","readonly",a=>a.get(i));if(!t)return;const n=await((e=t.queryPermission)==null?void 0:e.call(t,{mode:"readwrite"}))??"granted";return{handle:t,ready:n==="granted"}}catch{return}}async function hc(i){var t;return(await((t=i.requestPermission)==null?void 0:t.call(i,{mode:"readwrite"}))??"granted")==="granted"?{kind:"folder",root:new Us(i)}:void 0}async function AZ(i="folder"){try{await Tt("meta","readwrite",e=>e.delete(i))}catch{}}const ua="learnProgress.json",ca="lernstand.json",ma="visustruct.files.mode",gc="visustruct.files.expanded";function CZ(i){try{const e=JSON.parse(bg(i)??"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}}function bg(i){try{return localStorage.getItem(i)}catch{return null}}function da(i,e){try{e===null?localStorage.removeItem(i):localStorage.setItem(i,e)}catch{}}const te=i=>i.replace(/&/g,"&").replace(//g,">").replace(/"/g,""");function pc(i){return new Promise(e=>{const t=document.createElement("div");t.className="confirm";const n=(i.choices??[]).map(o=>`