+${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=j("details",{class:"reference-group"});r.open=n.includes(s);const o=j("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(){xe.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(j("p",{class:"hint"},p("web_learn_intro")));for(const e of DL()){this.body.append(j("h3",{class:"learn-section"},e.name));const t=j("ol",{class:"learn-list"});for(const n of e.lessons){const a=xe.lesson(n.id),s=a.done?"✓":a.step>0?p("web_learn_step_of_fmt",a.step+1,n.steps.length):"",r=j("button",{class:"learn-item"+(a.done?" done":""),"data-lesson":n.id},j("span",{class:"learn-num"},String(n.number)),j("span",{class:"learn-item-text"},j("strong",{},n.robot?`🤖 ${n.title}`:n.title),j("small",{},n.summary)),j("span",{class:"learn-status"},s));r.addEventListener("click",()=>this.openLesson(n.id)),t.append(j("li",{},r))}this.body.append(t)}this.body.append(this.renderTeacherBox())}renderLesson(e){var u;const t=xe.lesson(e.id),n=Math.min(t.step,e.steps.length-1),a=e.steps[n],s=j("button",{class:"learn-back"},`← ${p("web_learn_all_lessons")}`);s.addEventListener("click",()=>this.openLesson(void 0));const r=j("nav",{class:"learn-progress","aria-label":p("web_learn_step_of_fmt",n+1,e.steps.length)});r.append(...e.steps.map((m,c)=>{const d=p("web_learn_step_fmt",c+1,m.title),h=c
this.goToStep(e,c)),g})),this.body.append(j("div",{class:"learn-lesson-head"},j("div",{class:"learn-head-row"},s,this.stepNav(e,n,t.done,"learn-nav learn-nav-top")),j("p",{class:"learn-kicker"},`${p("web_learn_lesson_fmt",e.number)} · ${e.section}${e.robot?" · 🤖 VisuBot":""}`),j("h2",{class:"learn-title"},j("span",{class:"learn-num","aria-hidden":"true"},String(e.number)),e.title),r,j("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 m=j("button",{class:"learn-return"},`↩ ${p("web_learn_back_to_checklist")}`);return m.addEventListener("click",()=>{this.returnTo=void 0,this.goToStep(e,o.step),this.body.scrollTop=o.scroll}),m};o&&this.body.append(l()),a.blocks.forEach((m,c)=>this.body.append(this.renderBlock(m,`${n}-${c}`,e))),fm(this.body),dL(this.body),this.openNeededColumns(a.blocks),gm(this.body,Va),this.body.append(this.stepNav(e,n,t.done,"learn-nav")),o&&this.body.append(l())}stepNav(e,t,n,a){const s=j("div",{class:a}),r=j("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=j("button",{class:"primary"},n?`✓ ${p("web_learn_done")}`:p("web_learn_finish"));o.addEventListener("click",()=>{xe.updateLesson(e.id,{done:!0});const l=Ot.find(u=>u.number===e.number+1);this.openLesson(l==null?void 0:l.id)}),s.append(o)}return s}goToStep(e,t){xe.updateLesson(e.id,{step:t}),this.render(),this.body.scrollTop=0}openNeededColumns(e){const t=e.flatMap(n=>n.kind==="exercise"?[n.exercise]:[]);OL(this.body)?(this.host.showEditor(),AL(this.body)&&this.host.reveal(["palette"])):PL(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(),ML(this.body)&&this.host.showLiveCode()}renderTaskList(){this.body.append(j("p",{class:"hint"},p("web_learn_tasks_intro")));const e=j("ul",{class:"learn-list"});for(const t of An){const n=this.taskExercises(t),a=n.length>0&&n.every(o=>xe.exercise(o.id).done),s=Ot.find(o=>o.number===t.after),r=j("button",{class:"learn-item"+(a?" done":""),"data-task":t.id},j("span",{class:"learn-num","aria-label":p("web_learn_level_fmt",t.level)},"★".repeat(t.level)),j("span",{class:"learn-item-text"},j("strong",{},t.title),j("small",{},s?p("web_learn_after_fmt",s.number,s.title):"")),j("span",{class:"learn-status"},a?"✓":""));r.addEventListener("click",()=>{this.taskId=t.id,this.persist(),this.render(),this.body.scrollTop=0}),e.append(j("li",{},r))}this.body.append(e,this.renderTeacherBox())}renderTeacherBox(){const e=j("details",{class:"learn-teacher"},j("summary",{},p("web_learn_teacher")));if(am()){e.setAttribute("open","");const s=j("button",{},p("web_learn_teacher_off"));return s.addEventListener("click",()=>{aL(),this.render()}),e.append(j("p",{},p("web_learn_teacher_on")),s),e}const t=j("input",{type:"password",autocomplete:"off","aria-label":p("web_learn_teacher_code"),placeholder:p("web_learn_teacher_code")}),n=j("p",{class:"learn-result",role:"status"}),a=j("form",{class:"group"},t,j("button",{type:"submit"},p("web_learn_teacher_unlock")));return a.addEventListener("submit",async s=>{s.preventDefault(),await iL(t.value)?this.render():(n.className="learn-result info",n.textContent=p("web_learn_teacher_wrong"))}),e.append(j("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=j("button",{class:"learn-back"},`← ${p("web_learn_all_tasks")}`);t.addEventListener("click",()=>{this.taskId=void 0,this.persist(),this.render()});const n=Ot.find(a=>a.number===e.after);if(this.body.append(t,j("h2",{class:"learn-title"},e.title)),n){const a=j("button",{class:"link-button"},p("web_learn_after_fmt",n.number,n.title));a.addEventListener("click",()=>this.openLesson(n.id)),this.body.append(j("p",{class:"learn-kicker"},a))}e.blocks.forEach((a,s)=>this.body.append(this.renderBlock(a,`task-${s}`))),fm(this.body),this.openNeededColumns(e.blocks),gm(this.body,Va)}renderBlock(e,t,n){switch(e.kind){case"markdown":return this.withOpenButtons(tt("div",{class:"learn-text"},jn(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 gL(e.game,ca);case"rescueGame":return vL(e.game,ca);case"caesar":return uL(e.key,e.text);case"cloze":return wL(e.cloze);case"pap":return jL(e.pap);case"textFile":return pg(e.name,e.content);case"robotModel":return cL(e.focus,e.view,e.spin);case"robotQuiz":return hL(e.tasks,e.done)}}renderBrag(e,t=!1){const n=j("aside",{class:"learn-brag"});n.append(j("img",{src:ca,alt:"",width:"48",height:"48"}));const a=j("div",{},j("p",{class:"learn-brag-title"},p(t?"web_learn_ludwig_tip":"web_learn_brag")));return a.append(tt("div",{class:"learn-text"},jn(e))),n.append(a),n}renderGame(e){const n=j("section",{class:"learn-game"}),a=j("div",{class:"learn-game-head"});a.append(j("img",{src:ca,alt:"",width:"40",height:"40"}),j("strong",{},p("web_game_title")));const s=j("p",{class:"learn-game-status"}),r=j("div",{class:"learn-game-stage"});n.append(a,s,r);let o=0,l=0;const u=()=>{const d=Tb(e,o,10);s.textContent=`${p("web_game_round_fmt",o+1,10)} · ${p("web_game_score_fmt",l)}`;const h=j("div",{class:"learn-game-values mono"});for(const[w,z]of jb(d))h.append(j("code",{},`${w} = ${z}`));const g=j("div",{class:"group learn-game-answers"}),f=j("button",{class:"learn-game-true"},`✓ ${p("web_game_true")}`),x=j("button",{class:"learn-game-false"},`✗ ${p("web_game_false")}`);g.append(f,x);const b=j("div",{class:"learn-game-feedback",role:"status"}),v=w=>{f.disabled=x.disabled=!0;const z=w===d.answer;z&&l++,s.textContent=`${p("web_game_round_fmt",o+1,10)} · ${p("web_game_score_fmt",l)}`,b.className=`learn-game-feedback ${z?"right":"wrong"}`;const I=j("div",{class:"learn-game-steps mono"});kb(d.condition,d.values).forEach((S,_)=>I.append(j("div",{},`${_?"→ ":""}${S}`)));const k=j("button",{class:"primary"},o+1<10?p("web_game_next"):p("web_game_finish"));k.addEventListener("click",()=>{o++,o<10?u():m()}),b.replaceChildren(j("p",{},p(z?"web_game_right":"web_game_wrong")),I,k),k.focus()};f.addEventListener("click",()=>v(!0)),x.addEventListener("click",()=>v(!1)),r.replaceChildren(h,j("div",{class:"learn-game-condition mono"},d.condition),g,b)},m=()=>{s.textContent="";const d=j("button",{class:"primary"},p("web_game_again"));d.addEventListener("click",()=>{o=l=0,u()}),r.replaceChildren(j("p",{class:"learn-game-result"},p("web_game_done_fmt",l,10)),j("p",{},p(l===10?"web_game_perfect":l>=10*.7?"web_game_good":"web_game_practice")),d)},c=j("button",{class:"primary"},p("web_game_start"));return c.addEventListener("click",u),r.append(j("p",{},p("web_game_intro")),c),n}renderImages(e,t){const n=j("figure",{class:"learn-figure"}),a=j("div",{class:"learn-images"});for(const s of e){const r=jr(s);r&&a.append(j("img",{src:r,alt:"",loading:"lazy"}))}return n.append(a),t&&n.append(tt("figcaption",{},Pe(t))),n}renderGraphic(e,t,n){const a=j("figure",{class:"learn-figure"}),s=jr(e),r=n?jr(n):void 0;if(s&&r){const o=j("img",{class:"learn-graphic",src:s,alt:"",loading:"lazy"}),l=j("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,j("p",{class:"learn-graphic-hint"},p("web_learn_graphic_labels")))}else s&&a.append(j("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=j("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=si(e),a=j("figure",{class:"learn-figure"});if(!n)return a;const s=this.host.preview(n);s&&a.append(j("div",{class:"learn-preview",dir:"ltr"},s)),t&&a.append(tt("figcaption",{},Pe(t)));const r=j("button",{},p("web_learn_open_in_editor"));return r.addEventListener("click",()=>this.host.openDiagram(n,e)),a.append(r),a}renderExercise(e){const t=j("section",{class:"learn-exercise","data-exercise":e.id}),n=()=>xe.exercise(e.id),a=j("span",{class:"learn-badge"},`✓ ${p("web_learn_solved")}`);a.hidden=!n().done,t.append(j("h4",{},`${p("web_learn_exercise")}: ${e.title}`,a),EL(e),tt("div",{class:"learn-text"},jn(e.task)));const s=j("div",{class:"learn-result",role:"status"}),r=j("div",{class:"learn-hints"}),o=j("div",{class:"group"}),l=j("button",{class:"primary"},p("web_learn_open_exercise"));l.addEventListener("click",()=>{const c=n().xml;let d=xm(e);if(c)try{d=Hl(c)}catch{}this.host.openExercise(e,d)});const u=j("button",{},p("web_learn_check"));if(u.addEventListener("click",()=>{const c=this.host.exerciseDocument(e.id);if(!c){s.className="learn-result info",s.textContent=p("web_learn_open_first");return}if(c.elements.every(Jl)){s.className="learn-result info",s.textContent=p("web_learn_empty");return}this.host.stopSimulation();const d=vb(c,e.tests,this.host.subprogramsFor(e.id),Qa),h=yb(c),g=e.requires.map(b=>b==="forZaehlSchleife"?"forSchleife":b).filter(b=>b in T&&!h.has(T[b])),f=e.loopDepth!==void 0&&Wo(c.elements)b.passed)&&g.length===0&&!f;this.showResult(s,d,g,x,f),x&&(xe.updateExercise(e.id,{done:!0}),a.hidden=!1)}),o.append(l,u),e.hints.length>0){const c=j("button",{},p("web_learn_hint"));c.addEventListener("click",()=>{const d=r.children.length;if(d>=e.hints.length)return;const h=e.hints.length>1?`**${p("web_learn_hint_fmt",d+1,e.hints.length)}:** `:"";r.append(tt("aside",{class:"lesson-note"},jn(h+e.hints[d]))),c.textContent=p("web_learn_hint_more"),c.toggleAttribute("disabled",d+1>=e.hints.length)}),o.append(c)}const m=j("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}xe.resetExercise(e.id),this.host.resetExercise(e.id,xm(e)),a.hidden=!0,s.replaceChildren(),s.className="learn-result",m.dataset.confirm="",m.textContent=p("web_learn_reset")}),o.append(m),t.append(o,r,s),am()&&e.solution){const c=si(e.solution);if(c){const d=j("details",{class:"learn-solution"},j("summary",{},p("web_learn_solution")));d.addEventListener("toggle",()=>{if(!d.open||d.querySelector(".learn-preview"))return;const h=this.host.preview(c);h&&d.append(j("div",{class:"learn-preview",dir:"ltr"},h));const g=j("button",{},p("web_learn_open_in_editor"));g.addEventListener("click",()=>{this.host.openDiagram(c,e.solution);for(const f of e.subprograms){const x=si(f);x&&this.host.openDiagram(x,f)}});for(const f of e.subprograms){const x=si(f),b=x&&this.host.preview(x);b&&d.append(j("div",{class:"learn-preview",dir:"ltr"},b))}d.append(g)}),t.append(d)}}return t}showResult(e,t,n,a,s){var o,l,u,m,c;e.className="learn-result "+(a?"ok":"fail"),e.replaceChildren(j("p",{class:"learn-result-head"},a?`🎉 ${p("web_learn_passed")}`:p("web_learn_failed")));for(const d of n)e.append(j("p",{},`✗ ${p("web_learn_missing_fmt",BL(T[d]))}`));s&&e.append(j("p",{},`✗ ${p("web_visubot_depth_fmt",s)}`));const r=j("ul",{class:"learn-tests",dir:"auto"});for(const d of t){const h=d.test.world?t.filter(b=>b.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(([b,v])=>`mbot.${b}() = ${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}`],x=j("div",{class:"learn-test-detail"});if(d.test.drive&&x.append(j("span",{},`${p("web_learn_expected")}: `,j("code",{},ii(d.test.drive)||"–")),j("span",{},`${p("web_learn_actual")}: `,j("code",{},ii(d.result.drive??[])||"–"))),d.test.actions&&x.append(j("span",{},`${p("web_learn_expected")}: `,j("code",{},ii(d.test.actions)||"–")),j("span",{},`${p("web_learn_actual")}: `,j("code",{},ii(d.result.actions??[])||"–"))),d.test.led!==void 0){const b=v=>p(v?"web_visubot_led_on":"web_visubot_led_off");x.append(j("span",{},`💡 ${p("web_learn_expected")}: ${b(d.test.led)} · ${p("web_learn_actual")}: ${b(d.result.led)}`))}if(d.test.tone!==void 0){const b=v=>p(v?"web_visubot_tone_yes":"web_visubot_tone_no");x.append(j("span",{},`🔊 ${p("web_learn_expected")}: ${b(d.test.tone)} · ${p("web_learn_actual")}: ${b(d.result.tone)}`))}d.test.screen!==void 0&&x.append(j("span",{},`📺 ${p("web_learn_expected")}: `,j("code",{},d.test.screen),` · ${p("web_learn_actual")}: `,j("code",{},d.result.screen??"–"))),d.test.world&&(((l=(o=Qa(d.test.world))==null?void 0:o.goals)!=null&&l.length||(m=(u=Qa(d.test.world))==null?void 0:u.targets)!=null&&m.length)&&x.append(j("span",{},d.result.atGoal?`✓ ${p("web_visubot_goal_reached")}`:`✗ ${p("web_visubot_goal_missed")}`)),d.result.bumps&&x.append(j("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)&&x.append(j("span",{},`${p("web_learn_expected")}: `,j("code",{},d.test.expected.join(" | ")||"–")),j("span",{},`${p("web_learn_actual")}: `,j("code",{},d.result.outputs.join(" | ")||"–")));for(const b of d.test.files??[])x.append(j("span",{},`📄 ${b.name}, ${p("web_learn_expected")}: `,j("code",{},b.lines.join(" | ")||"–")),j("span",{},`📄 ${b.name}, ${p("web_learn_actual")}: `,j("code",{},Kh((c=d.result.files)==null?void 0:c.get(b.name)).join(" | ")||"–")));!d.passed&&!d.result.error&&bb(d.result.outputs,d.test.expected)&&x.append(j("span",{class:"learn-error"},p("web_learn_missing_line_break"))),d.result.error&&x.append(j("span",{class:"learn-error"},n1(d.result.error))),d.result.missingInput&&x.append(j("span",{class:"learn-error"},p("web_learn_missing_input"))),d.result.tooManySteps&&x.append(j("span",{class:"learn-error"},p("web_learn_too_many_steps"))),!d.passed&&d.result.unusedInputs&&x.append(j("span",{class:"learn-error"},p("web_learn_unused_input"))),r.append(j("li",{class:d.passed?"ok":"fail"},...f,x))}e.append(r)}renderCompetences(e){const t=j("aside",{class:"learn-competences"},j("p",{class:"learn-competences-title"},p("web_learn_competences_intro"))),n=j("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=j("div",{class:"learn-checklist-wrap"}),r=j("p",{class:"learn-rating-legend"});for(const l of a)r.append(j("span",{},`${l.icon} ${l.label}`));const o=j("ul",{class:"learn-checklist"});return s.append(r,o),e.forEach((l,u)=>{var v;const m=`${t}-${u}`,c=n?(v=xe.lesson(n.id).checks)==null?void 0:v[m]:void 0;let d=c===!0?"sun":c||void 0;const h=tt("span",{class:"learn-check-text"},Pe(l.text)),g=j("span",{class:"learn-rating",role:"group","aria-label":h.textContent??""}),f=a.map(w=>{const z=j("button",{class:"learn-rating-button",title:w.label,"aria-label":w.label},w.icon);return z.addEventListener("click",()=>{if(d=d===w.value?void 0:w.value,x(),!n)return;const I={...xe.lesson(n.id).checks??{}};d?I[m]=d:delete I[m],xe.updateLesson(n.id,{checks:Object.keys(I).length?I:void 0})}),z}),x=()=>{f.forEach((w,z)=>w.setAttribute("aria-pressed",String(a[z].value===d))),b.dataset.rating=d??""};g.append(...f);const b=j("li",{},h,g);if(n&&l.step!==void 0){const w=l.step,z=p("web_learn_step_fmt",w+1,n.steps[w].title),I=j("button",{class:"link-button learn-check-link",title:z,"aria-label":`${p("web_learn_review")}: ${z}`},p("web_learn_review"));I.addEventListener("click",()=>{this.returnTo={lesson:n.id,step:xe.lesson(n.id).step,scroll:this.body.scrollTop},this.goToStep(n,w)}),b.append(I)}x(),o.append(b)}),s}renderQuiz(e,t,n){const a=j("div",{class:"learn-quiz"}),s=j("p",{class:"learn-score",role:"status"}),r=()=>n?xe.lesson(n.id).quiz??{}:{},o=j("div",{class:"learn-review"}),l=()=>{const u=r(),m=(f,x)=>f.pairs?f.pairs.every((b,v)=>u[`${t}-${x}-${v}`]!==void 0):u[`${t}-${x}`]!==void 0,c=(f,x)=>{var b;return!!(f.pairs?f.pairs.every((v,w)=>bm(f)[u[`${t}-${x}-${w}`]]===f.pairs[w].right):(b=f.options[u[`${t}-${x}`]])!=null&&b.correct)},d=e.filter(m).length,h=e.filter(c).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=>c(e[f],f))};return e.forEach((u,m)=>{const c=`${t}-${m}`,d=j("fieldset",{},tt("legend",{},Pe(u.question))),h=tt("p",{class:"learn-explanation"},Pe(u.explanation??""));if(u.pairs){d.append(this.renderMatch(u,c,r,n,h,l),h),a.append(d);return}const g=f=>{d.querySelectorAll("button").forEach((x,b)=>{x.classList.toggle("right",f!==void 0&&u.options[b].correct),x.classList.toggle("wrong",f===b&&!u.options[b].correct),x.setAttribute("aria-pressed",String(f===b))}),h.hidden=f===void 0||!u.explanation};u.options.forEach((f,x)=>{const b=tt("button",{class:"learn-option"},Pe(f.text));b.addEventListener("click",()=>{n&&xe.updateLesson(n.id,{quiz:{...r(),[c]:x}}),g(x),l()}),d.append(b)}),d.append(h),g(r()[c]),a.append(d)}),a.append(s,o),l(),a}fillChecklistReview(e,t,n,a){const s={sun:"☀️",cloud:"⛅",umbrella:"☂️"},r=xe.lesson(t.id).checks??{},o=[];let l=0;t.steps.forEach((u,m)=>u.blocks.forEach((c,d)=>{c.kind==="checklist"&&c.items.forEach((h,g)=>{const f=r[`${m}-${d}-${g}`],x=f===!0?"sun":f||void 0,b=h.step===void 0?[]:n.map((k,S)=>k.step===h.step?S:-1).filter(k=>k>=0),v=b.filter(k=>!a(k));let w="";x==="sun"&&v.length?w=p("web_learn_review_overrated_fmt",v.map(k=>k+1).join(", ")):x&&x!=="sun"&&b.length&&!v.length&&(w=p("web_learn_review_underrated")),w&&l++;const z=j("li",{class:w?"learn-review-deviation":""}),I=tt("span",{class:"learn-check-text"},Pe(h.text));if(w&&I.append(j("br",{}),j("em",{},w)),z.append(I,j("span",{class:"learn-review-icon","aria-label":p(x?`web_learn_rating_${x}`:"web_learn_review_unrated")},x?s[x]:"–")),w&&x==="sun"&&h.step!==void 0){const k=h.step,S=j("button",{class:"link-button learn-check-link"},p("web_learn_review"));S.addEventListener("click",()=>{this.returnTo={lesson:t.id,step:xe.lesson(t.id).step,scroll:this.body.scrollTop},this.goToStep(t,k)}),z.append(S)}o.push(z)})})),o.length&&e.append(j("p",{class:"learn-review-title"},`📋 ${p("web_learn_review_title")}`),j("p",{},p(l?"web_learn_review_hint":"web_learn_review_match")),j("ul",{class:"learn-checklist"},...o))}renderMatch(e,t,n,a,s,r){const o=e.pairs,l=bm(e),u=j("div",{class:"learn-match"});let m={};const c=()=>a?n():m,d=x=>a?xe.updateLesson(a.id,{quiz:x}):m=x,h=x=>c()[`${t}-${x}`],g=o.map(x=>{const b=j("select",{class:"learn-match-select"});b.append(j("option",{value:""},"–")),l.forEach((w,z)=>b.append(j("option",{value:String(z)},w)));const v=tt("label",{class:"learn-match-left"},Pe(x.left));return v.append(b),u.append(v),b}),f=()=>{const x=o.every((b,v)=>h(v)!==void 0);g.forEach((b,v)=>{const w=h(v);b.value=w===void 0?"":String(w),b.classList.toggle("right",x&&l[w]===o[v].right),b.classList.toggle("wrong",x&&l[w]!==o[v].right)}),s.hidden=!x||!e.explanation};return g.forEach((x,b)=>x.addEventListener("change",()=>{const v={...c()};x.value===""?delete v[`${t}-${b}`]:v[`${t}-${b}`]=Number(x.value),d(v),f(),r()})),f(),u}}function bm(i){return(i.pairs??[]).map(e=>e.right).sort((e,t)=>e.localeCompare(t,"de"))}function EL(i){const e=og(i),t=e==="beide"?"web_learn_solve_in_both":e==="code"?"web_learn_solve_in_code":"web_learn_solve_in_editor",n={editor:p("web_editor_title"),code:p("web_live_title")},a=e==="beide"?["editor","code"]:[e==="code"?"code":"editor"],s=j("p",{class:`learn-where learn-where-${e}`});for(const r of p(t,...a).split(/(\u0001(?:editor|code))/))if(r==="editor"||r==="code"){const o=r.slice(1);s.append(j("span",{class:`area-name area-${o}`},n[o]))}else r&&s.append(r);return s}const NL=""+new URL("visubot-CyGFOI9V.webp",import.meta.url).href,tr="visustruct.visubot";function nr(){try{return localStorage.getItem(tr)}catch{return null}}function hi(){const i=nr();return i==="1"||i==="kurs"?"on":"off"}const kg=()=>nr()==="2";function Sg(){try{localStorage.setItem(tr,"2")}catch{}}const Tg=()=>nr()==="3";function jg(){try{localStorage.setItem(tr,"3")}catch{}}const JL=()=>nr()!==null;function Ar(i){try{localStorage.setItem(tr,i==="on"?"1":"0")}catch{}}const FL=`
VisuBot`,Vn=()=>hi()!=="off",vm=i=>i.replace(/[&<>"]/g,e=>({"&":"&","<":"<",">":">",'"':"""})[e]);function Fo(){const i=kg()?"object":Tg()?"flow":hi(),e=(n,a)=>``,t={off:"web_visubot_world_visustruct_hint",on:"web_visubot_world_visubot_hint",object:"web_visuobject_world_hint",flow:"web_visuflow_world_hint"}[i];return`
${e("off","VisuStruct")}${e("on","VisuBot")}${e("object","VisuObject")}${e("flow","VisuFlow")}
- ${vm(p(t))}`}class NL{constructor(e=ji){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 xs(e),this.element=document.createElement("section"),this.element.className="visubot",this.element.innerHTML=`${p("web_visubot_world")}
${p("web_visubot_world_in_preview")}
${FL()}${JL()}`,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=pe.listen(()=>this.updateLive()),this.setupControls(),this.check=this.element.querySelector(".visubot-check"),this.setupCheck(),this.updateLive(),this.updateStatus()}show(){this.loading??(this.loading=K(async()=>{const{Robot3D:e}=await import("./robot3d-OZU43-FL.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]??ji,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 xs(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;pe.run(e.dataset.py).then(()=>t?new Promise(a=>setTimeout(a,Number(n))).then(()=>pe.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&&pe.connected;){for(const e of this.check.querySelectorAll("[data-sensor]")){if(!this.check.open||!pe.connected)break;const t=e.dataset.sensor,n=await pe.ask(Ct[t].python).catch(()=>{});n!==void 0&&(e.textContent=typeof Ct[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 pe.connected}async prepareLive(e,t=[]){const n={};for(const a of new Set(["getDistance","getLine",...t])){const s=await pe.ask(Ct[a].python);typeof Ct[a].simulated=="boolean"?n[a]=s===!0||typeof s=="number"&&s!==0:typeof Ct[a].simulated=="string"?n[a]=typeof s=="string"?s:String(Ct[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){pe.disconnect(e instanceof Error?e.message:String(e))}updateLive(){this.liveStatus.textContent=Cg(),this.liveStatus.classList.toggle("connected",pe.connected),this.check.hidden=!pe.connected,pe.connected||(this.check.open=!1),this.updateStatus()}follow(e,t){var a,s,r,o;for(;this.appliedl!==0);this.world.tick(m0),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&&pe.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 $1;function jg(i,e){try{$1??($1=new AudioContext);const t=$1.createOscillator(),n=$1.createGain();t.type="square",t.frequency.value=Math.max(20,Math.min(2e4,i)),n.gain.value=.05,t.connect(n).connect($1.destination);const a=$1.currentTime+Math.min(Math.max(e,0),5e3)/1e3;t.start(),t.stop(a)}catch{}}function FL(){const i=(t,n,a,s,r)=>``,e=(t,n,a)=>``;return`🎛 ${p("web_visubot_controls")}
+ ${vm(p(t))}`}class RL{constructor(e=_i){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 xs(e),this.element=document.createElement("section"),this.element.className="visubot",this.element.innerHTML=`${p("web_visubot_world")}
${p("web_visubot_world_in_preview")}
${GL()}${HL()}`,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=pe.listen(()=>this.updateLive()),this.setupControls(),this.check=this.element.querySelector(".visubot-check"),this.setupCheck(),this.updateLive(),this.updateStatus()}show(){this.loading??(this.loading=K(async()=>{const{Robot3D:e}=await import("./robot3d-BOvRTAxq.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]??_i,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 xs(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;pe.run(e.dataset.py).then(()=>t?new Promise(a=>setTimeout(a,Number(n))).then(()=>pe.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&&pe.connected;){for(const e of this.check.querySelectorAll("[data-sensor]")){if(!this.check.open||!pe.connected)break;const t=e.dataset.sensor,n=await pe.ask(Ct[t].python).catch(()=>{});n!==void 0&&(e.textContent=typeof Ct[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 pe.connected}async prepareLive(e,t=[]){const n={};for(const a of new Set(["getDistance","getLine",...t])){const s=await pe.ask(Ct[a].python);typeof Ct[a].simulated=="boolean"?n[a]=s===!0||typeof s=="number"&&s!==0:typeof Ct[a].simulated=="string"?n[a]=typeof s=="string"?s:String(Ct[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){pe.disconnect(e instanceof Error?e.message:String(e))}updateLive(){this.liveStatus.textContent=Cg(),this.liveStatus.classList.toggle("connected",pe.connected),this.check.hidden=!pe.connected,pe.connected||(this.check.open=!1),this.updateStatus()}follow(e,t){var a,s,r,o;for(;this.appliedl!==0);this.world.tick(m0),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&&pe.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 Y1;function _g(i,e){try{Y1??(Y1=new AudioContext);const t=Y1.createOscillator(),n=Y1.createGain();t.type="square",t.frequency.value=Math.max(20,Math.min(2e4,i)),n.gain.value=.05,t.connect(n).connect(Y1.destination);const a=Y1.currentTime+Math.min(Math.max(e,0),5e3)/1e3;t.start(),t.stop(a)}catch{}}function GL(){const i=(t,n,a,s,r)=>``,e=(t,n,a)=>``;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)}
@@ -67236,45 +67248,45 @@ ${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 JL(){const i=a=>a.replace(/"/g,"""),e=(a,s,r,o=1e3)=>`
+ `,this.body=this.element.querySelector(".files-body");const e=(t,n)=>this.element.querySelector(`[data-files=${t}]`).addEventListener("click",n);e("hide",()=>this.host.hide()),e("new-folder",()=>void this.newFolder()),e("switch",()=>void this.switchWorkspace()),this.body.addEventListener("click",t=>void this.onTreeClick(t)),this.render()}async restore(){if(Pg(fa)==="browser")this.workspace=ym();else if(ha()){const e=await $L();e!=null&&e.ready?this.workspace=await wm(e.handle):this.pending=e==null?void 0:e.handle}await this.render(),this.workspace||this.startDialog()}async startDialog(){var r;const e=p("web_learn_start_folder"),t=(o,l,u=!1,m)=>`
${m?`
${te(m)}
`:""}`,n=ha()?[this.pending?t("reconnect",`${se.open} ${te(p("web_learn_start_continue_fmt",this.pending.name))}`,!0):"",t("pick",`${se.open} ${te(p("web_learn_start_open"))}`,!this.pending),t("create",`${se.newFolder} ${te(p("web_learn_start_create_fmt",e))}`,!1,p("web_learn_start_create_hint"))]:[t("browser",te(p("web_files_browser")),!0,p("web_files_browser_hint"))],a=document.createElement("div");a.className="confirm",a.innerHTML=`
${te(p("web_visubot_world_title"))}
-
${Jo()}
+
${Fo()}
${te(p("web_learn_start_title"))}
${te(p("web_learn_start_hint"))}
${n.join("")}
${te(p("web_learn_start_without_hint"))}
-
`;const s=()=>a.remove();a.addEventListener("click",o=>{var m,c;const l=(m=o.target.closest("[data-world]"))==null?void 0:m.dataset.world;if(l){this.host.chooseWorld(l).then(()=>a.querySelector(".start-world").innerHTML=Jo());return}const u=(c=o.target.closest("[data-start]"))==null?void 0:c.dataset.start;u&&(s(),u==="reconnect"?this.reconnect():u==="pick"?this.connectFolder():u==="create"?this.connectFolder(e):u==="browser"&&this.useBrowser())}),a.addEventListener("keydown",o=>o.key==="Escape"&&s()),document.body.append(a),(r=a.querySelector(".files-start"))==null||r.focus()}async connectFolder(e){try{this.workspace=await qL(e),this.pending=void 0,xa(fa,"folder")}catch{}await this.render()}async reconnect(){this.pending&&(this.workspace=await wm(this.pending),this.workspace&&(this.pending=void 0),await this.render())}async useBrowser(){this.workspace=ym(),xa(fa,"browser"),await this.render()}async switchWorkspace(){if(ha())return this.connectFolder();this.workspace=void 0,xa(fa,null),await UL(),await this.render()}async syncProgress(e){if(this.progressWorkspace=e,!e)return;const t=!this.hadWorkspace;this.hadWorkspace=!0;try{const n=await e.root.has(ga)?ga:await e.root.has(pa)?pa:void 0;(!n||!xe.loadFile(await e.root.read(n),t))&&(t||xe.clear()),this.host.progressLoaded(),await this.writeProgress(e),await e.root.has(pa)&&(await e.root.remove(pa),await this.render())}catch{}}async writeProgress(e){if(e===this.progressWorkspace)try{const t=!await e.root.has(ga);await e.root.write(ga,xe.toFile()),t&&await this.render()}catch{}}progressChanged(){const e=this.progressWorkspace;e&&(window.clearTimeout(this.progressTimer),this.progressTimer=window.setTimeout(()=>void this.writeProgress(e),1e3))}async render(){const e=++this.rendering,t=this.workspace;if(t!==this.progressWorkspace&&this.syncProgress(t),this.element.querySelector("[data-files=new-folder]").hidden=!t,this.element.querySelector("[data-files=switch]").hidden=!t,!t){this.body.innerHTML=this.startHTML();return}const n=[],a=async(o,l,u)=>{const m=(await o.list()).sort(eb);for(const c of m){const d=l?`${l}/${c.name}`:c.name;if(c.kind==="directory"){const h=this.expanded.has(d);n.push(`
+
`;const s=()=>a.remove();a.addEventListener("click",o=>{var m,c;const l=(m=o.target.closest("[data-world]"))==null?void 0:m.dataset.world;if(l){this.host.chooseWorld(l).then(()=>a.querySelector(".start-world").innerHTML=Fo());return}const u=(c=o.target.closest("[data-start]"))==null?void 0:c.dataset.start;u&&(s(),u==="reconnect"?this.reconnect():u==="pick"?this.connectFolder():u==="create"?this.connectFolder(e):u==="browser"&&this.useBrowser())}),a.addEventListener("keydown",o=>o.key==="Escape"&&s()),document.body.append(a),(r=a.querySelector(".files-start"))==null||r.focus()}async connectFolder(e){try{this.workspace=await YL(e),this.pending=void 0,xa(fa,"folder")}catch{}await this.render()}async reconnect(){this.pending&&(this.workspace=await wm(this.pending),this.workspace&&(this.pending=void 0),await this.render())}async useBrowser(){this.workspace=ym(),xa(fa,"browser"),await this.render()}async switchWorkspace(){if(ha())return this.connectFolder();this.workspace=void 0,xa(fa,null),await XL(),await this.render()}async syncProgress(e){if(this.progressWorkspace=e,!e)return;const t=!this.hadWorkspace;this.hadWorkspace=!0;try{const n=await e.root.has(ga)?ga:await e.root.has(pa)?pa:void 0;(!n||!xe.loadFile(await e.root.read(n),t))&&(t||xe.clear()),this.host.progressLoaded(),await this.writeProgress(e),await e.root.has(pa)&&(await e.root.remove(pa),await this.render())}catch{}}async writeProgress(e){if(e===this.progressWorkspace)try{const t=!await e.root.has(ga);await e.root.write(ga,xe.toFile()),t&&await this.render()}catch{}}progressChanged(){const e=this.progressWorkspace;e&&(window.clearTimeout(this.progressTimer),this.progressTimer=window.setTimeout(()=>void this.writeProgress(e),1e3))}async render(){const e=++this.rendering,t=this.workspace;if(t!==this.progressWorkspace&&this.syncProgress(t),this.element.querySelector("[data-files=new-folder]").hidden=!t,this.element.querySelector("[data-files=switch]").hidden=!t,!t){this.body.innerHTML=this.startHTML();return}const n=[],a=async(o,l,u)=>{const m=(await o.list()).sort(eb);for(const c of m){const d=l?`${l}/${c.name}`:c.name;if(c.kind==="directory"){const h=this.expanded.has(d);n.push(`
`),h&&await a(await o.dir(c.name),d,u+1)}else if(/\.(visustruct|java|json)$/i.test(c.name)){if(/\.java$/i.test(c.name)&&m.some(g=>g.name===c.name.replace(/\.java$/i,".visustruct")))continue;const h=/\.(visustruct|java)$/i.test(c.name);n.push(`
${h?``:""}
-
`)}}};try{await a(t.root,"",0)}catch(o){n.push(`
${te(o.message)}
`)}if(e!==this.rendering)return;const s=t.kind==="folder"?`📁 ${te(t.root.name)}`:te(p("web_files_in_browser")),r=p("web_files_save_hint_fmt",Bu());this.body.innerHTML=`
+
`)}}};try{await a(t.root,"",0)}catch(o){n.push(`