From 2ae61bdc448a48e98bea34420ea966789dfcf515 Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 10:06:50 +0630 Subject: [PATCH 1/3] Fold part 3 to the chosen approach, keep its language tabs in reach MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Each part 3 solution's heading is a disclosure button (aria-expanded, aria-controls). The approach chosen in 2·1 starts open, the others fold to their heading; choosing another approach opens it too. Folds hold across the five language panes, a page-language switch and deep links. Copy still copies a folded solution. - The part 3 language tabs stick under the masthead until part 3 ends. - On phones the language tabs keep to one row (two rows of touch-sized tabs made a 94px sticky bar) and scroll sideways only at ~320px, where the selected tab is kept in view without moving the page. --- src/lib/stepper.js | 36 +++++++++++++++++++++++++++++++----- src/styles/lesson.css | 25 +++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/lib/stepper.js b/src/lib/stepper.js index d9a97a4..c58a93a 100644 --- a/src/lib/stepper.js +++ b/src/lib/stepper.js @@ -48,6 +48,10 @@ const selectTabs = (tabs, isOn) => tabs.forEach((b) => { const on = isOn(b); b.setAttribute('aria-selected', String(on)); b.tabIndex = on ? 0 : -1; + // a tab row that scrolls sideways (a narrow phone) shows its selected tab — + // moving the row only, never the page + const row = b.parentElement; + if (on && row.scrollWidth > row.clientWidth) row.scrollLeft = b.offsetLeft - (row.clientWidth - b.offsetWidth) / 2; }); /* Arrow keys, Home and End inside a tablist: move to that tab and select it. */ @@ -117,6 +121,7 @@ export function mountLesson(cfg) { timer: null, // set while playing input: structuredClone(cfg.input), varNames: [], + open: null, // part 3 solutions shown open }; /* ---------------- building ---------------- */ @@ -417,6 +422,7 @@ export function mountLesson(cfg) { stop(); state.mode = card.dataset.mode; selectTabs(root.querySelectorAll('[data-mode]'), (b) => b.dataset.mode === state.mode); + showSolution(state, state.mode, true); rebuild(); return; } @@ -550,7 +556,7 @@ export function mountLesson(cfg) { function paintAll() { paint(); renderExamples(cfg, loadInput); - renderSolutions(cfg, state.lang); + renderSolutions(cfg, state); rebuild(state.i); } @@ -636,10 +642,25 @@ function approachBlock(a, cost) { `; } -function renderSolutions(cfg, activeLang) { +/* Part 3 opens on the approach the reader chose in 2·1; the others fold to + * their heading, copyable still. Choosing another approach in 2·1 opens that + * one too. A lesson with a single approach has nothing to fold. */ +function showSolution(state, mode, open) { + if (!state.open) return; + if (open) state.open.add(mode); else state.open.delete(mode); + document.querySelectorAll(`#solutions .src[data-src="${mode}"]`).forEach((src) => { + src.querySelector('.src-toggle')?.setAttribute('aria-expanded', String(open)); + src.querySelector('pre.full').hidden = !open; + }); +} + +function renderSolutions(cfg, state) { const host = document.getElementById('solutions'); if (!host) return; const langs = cfg.languages; + const activeLang = state.lang; + const folds = cfg.modes.length > 1; + state.open ??= new Set([state.mode]); // verification[lang] is one badge for every approach, or { [mode]: badge } // when one approach in that language behaves differently from the other. @@ -657,15 +678,18 @@ function renderSolutions(cfg, activeLang) { ${cfg.modes.map((m) => { const meta = cfg.solutions?.[m.id] || {}; const lines = (cfg.code[m.id]?.[l.id] || []).map(([, html]) => html).join('\n'); + const open = !folds || state.open.has(m.id); + const id = `src-${l.id}-${m.id}`; + const title = `${esc(pick(m.name))}${m.sub ? ` · ${esc(pick(m.sub))}` : ''}${meta.tag ? `${esc(meta.tag)}` : ''}`; return ` -
+
-

${esc(pick(m.name))}${m.sub ? ` · ${esc(pick(m.sub))}` : ''}${meta.tag ? `${esc(meta.tag)}` : ''}

+

${folds ? `` : title}

${badge(l.id, m.id)} ${meta.desc ? `

${pick(meta.desc)}

` : `

${esc(pick(m.cost))}

`}
-
${lines}
+
${lines}
`; }).join('')}
`).join('')}`; @@ -675,6 +699,8 @@ function renderSolutions(cfg, activeLang) { const langBtn = e.target.closest('[data-lang]'); // the live code panel's tab switches every tab and pane on the page if (langBtn) return document.querySelector(`#lesson [data-lang="${langBtn.dataset.lang}"]`)?.click(); + const fold = e.target.closest('.src-toggle'); + if (fold) return showSolution(state, fold.closest('.src').dataset.src, fold.getAttribute('aria-expanded') !== 'true'); const copy = e.target.closest('[data-copy]'); if (copy) { const text = copy.closest('.src').querySelector('pre.full').textContent; diff --git a/src/styles/lesson.css b/src/styles/lesson.css index 4af8239..21003ec 100644 --- a/src/styles/lesson.css +++ b/src/styles/lesson.css @@ -201,6 +201,30 @@ td.mono{font-variant-numeric:tabular-nums} .lang:hover{color:var(--accent)} .lang[aria-selected="true"]{background:var(--surface);color:var(--ink);font-weight:600;box-shadow:0 1px 2px rgba(0,0,0,.12)} .src-head h3{margin-right:auto} +/* A folding solution: its heading is the button, a chevron shows which way. */ +.src-toggle{ + display:inline-flex;align-items:baseline;gap:9px;text-align:left;cursor:pointer; + font:inherit;letter-spacing:inherit;color:inherit;background:none;border:0;padding:0;margin:0; +} +.src-toggle::before{ + content:"";flex:0 0 auto;width:7px;height:7px;align-self:center;margin-top:-3px; + border-right:2px solid var(--ink-3);border-bottom:2px solid var(--ink-3);transform:rotate(45deg); +} +.src-toggle[aria-expanded="false"]::before{transform:rotate(-45deg);margin-top:0} +.src-toggle:hover{color:var(--accent)} +.src:has(pre.full[hidden]) .src-head{margin-bottom:0} +@media (prefers-reduced-motion: no-preference){.src-toggle::before{transition:transform .15s}} +/* The language tabs stay in reach while the reader scrolls part 3, and let go + at its end; a solution scrolled to by focus lands below them. */ +#solutions > .lang-bar{position:sticky;top:56px;z-index:4} +#solutions .src{scroll-margin-top:120px} +/* On a phone the language tabs keep to one row — two rows of touch-sized + tabs made a 94px sticky bar — and scroll sideways if they must. */ +@media (max-width:560px){ + .lang-bar{flex-wrap:nowrap;overflow-x:auto;scrollbar-width:none} + .lang-bar::-webkit-scrollbar{display:none} + .lang-bar .lang{flex:0 0 auto;padding-inline:10px} +} .tagpill{ font-family:"IBM Plex Mono",monospace;font-size:10.5px;font-weight:500;color:var(--accent); background:var(--accent-soft);border-radius:5px;padding:2px 7px;margin-left:8px; @@ -476,5 +500,6 @@ td.mono{font-variant-numeric:tabular-nums} so rows keep their line breaks. */ @media (pointer:coarse),(max-width:560px){ .chip,.lang,.lang-bar.mini .lang,.lang-opt,.copy,.btn.ex-load{min-height:40px} + .src-toggle{min-height:40px;align-items:center} .jump a{min-height:40px} } From ac6cac0d5ab441ef0003813aee89c7fb03b5ad05 Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 11:28:36 +0630 Subject: [PATCH 2/3] Part 1: the statement and the widget end on one line The two cards stretch to their row's height instead of aligning to the top, so the shorter one keeps its spare room inside its own card rather than leaving a hole beside the taller one. Which is taller varies by lesson (the statement on 20 of 46, the widget on 26), so this fixes both directions; below 900px they stack as before. --- src/styles/lesson.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/styles/lesson.css b/src/styles/lesson.css index 21003ec..ae75253 100644 --- a/src/styles/lesson.css +++ b/src/styles/lesson.css @@ -164,7 +164,9 @@ td.mono{font-variant-numeric:tabular-nums} } /* ---------- the question ---------- */ -.question{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.05fr);gap:18px;margin-bottom:22px;align-items:start} +/* The statement and the widget end on one line: whichever is shorter keeps + its spare room inside its own card rather than leaving a hole in the page. */ +.question{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.05fr);gap:18px;margin-bottom:22px;align-items:stretch} @media (max-width:900px){.question{grid-template-columns:minmax(0,1fr)}} .q-statement{background:var(--surface);border:1px solid var(--line);border-radius:var(--radius);padding:18px;box-shadow:var(--shadow)} .constraints{display:flex;flex-wrap:wrap;gap:6px;margin-top:13px} From 5c8c34de85020e37ed89ff6a1a3b35aa0bc9154a Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 11:40:08 +0630 Subject: [PATCH 3/3] Say what an empty spot means instead of drawing a dot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - An answer slot not yet filled shows a faint "?" and reads "not yet" to a screen reader, instead of "·" (slots() in stage.js, used by 40 lessons; product-of-array-except-self and rotate-image's hand-built slots use the same blank()). - x-sum's third brute-force step reads "not summed yet", like the two above it, instead of "—" and a 30px "·" that looked like "▪". - basic-calculator's empty running-call panel says "no call running". - A .vh utility hides text from sight but not from screen readers. Dots that are notation stay: an empty n-queens square, a table cell not computed yet, an unknown bit, the dummy list node. --- src/lessons/basic-calculator/lesson.js | 2 +- src/lessons/product-of-array-except-self/lesson.js | 4 ++-- src/lessons/rotate-image/lesson.js | 4 ++-- src/lessons/x-sum/lesson.js | 6 ++++-- src/lib/stage.js | 8 +++++++- src/styles/base.css | 2 ++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/lessons/basic-calculator/lesson.js b/src/lessons/basic-calculator/lesson.js index e7304f1..530f58c 100644 --- a/src/lessons/basic-calculator/lesson.js +++ b/src/lessons/basic-calculator/lesson.js @@ -177,7 +177,7 @@ function draw(s) { const items = s.frames.map((f) => `expr() · total ${f.total} · sign ${sgn(f.sign)} · num ${f.num}`); return stagePanel(pick(t('The call stack — one expr() per open bracket', 'call stack — ဖွင့်ထားသော ကွင်းတစ်ခုလျှင် expr() တစ်ခု')), pick(t(`${s.frames.length} deep`, `${s.frames.length} ဆင့်`)), stack(items)) - + stageGap + stagePanel(pick(t('The running call', 'run နေသော call')), '', s.frames.length ? now : stageEmpty('—')); + + stageGap + stagePanel(pick(t('The running call', 'run နေသော call')), '', s.frames.length ? now : stageEmpty(pick(t('no call running', 'run နေသော call မရှိ')))); } function answer(s) { diff --git a/src/lessons/product-of-array-except-self/lesson.js b/src/lessons/product-of-array-except-self/lesson.js index dfee47f..82e6aca 100644 --- a/src/lessons/product-of-array-except-self/lesson.js +++ b/src/lessons/product-of-array-except-self/lesson.js @@ -9,7 +9,7 @@ */ import { mountLesson } from '../../lib/stepper.js'; import { pick, onLangChange } from '../../lib/i18n.js'; -import { cells, readout, stagePanel } from '../../lib/stage.js'; +import { blank, cells, readout, stagePanel } from '../../lib/stage.js'; import { t, exampleTitle, LANGUAGES, k, c, stageRow, stageGap, intList, presetChips, widgetLabel } from '../../lib/kit.js'; const MAX_LEN = 10; @@ -178,7 +178,7 @@ function draw(s, { nums }) { /* The answer card: a slot per index, filled once that answer is final. */ function answer(s) { const done = s.view === 'brute' ? s.answer.map((v) => v != null) : s.final; - const html = s.answer.map((v, i) => `${done[i] ? v : '·'}`).join(''); + const html = s.answer.map((v, i) => `${done[i] ? v : blank()}`).join(''); return { html, note: s.finished ? t('every product, no division', 'မြှောက်လဒ် အားလုံး၊ စားခြင်း မပါ') : t('one product per index', 'index တစ်ခုစီ မြှောက်လဒ် တစ်ခု') }; } diff --git a/src/lessons/rotate-image/lesson.js b/src/lessons/rotate-image/lesson.js index d02e67d..14db0b0 100644 --- a/src/lessons/rotate-image/lesson.js +++ b/src/lessons/rotate-image/lesson.js @@ -8,7 +8,7 @@ */ import { mountLesson } from '../../lib/stepper.js'; import { pick, onLangChange } from '../../lib/i18n.js'; -import { cells, slots, stagePanel, readout } from '../../lib/stage.js'; +import { blank, cells, slots, stagePanel, readout } from '../../lib/stage.js'; import { t, exampleTitle, LANGUAGES, k, c, labelledRows, stageGap, presetChips, widgetLabel } from '../../lib/kit.js'; const MAX_N = 5; @@ -135,7 +135,7 @@ function draw(s, { matrix: input }) { function answer(s) { return { - html: s.finished ? slots(s.matrix.map((r) => `[${r.join(',')}]`), { total: s.matrix.length }) : '·', + html: s.finished ? slots(s.matrix.map((r) => `[${r.join(',')}]`), { total: s.matrix.length }) : `${blank()}`, note: s.finished ? t('matrix, turned in place', 'နေရာတွင်ပင် လှည့်ထားသော matrix') : t('nothing to return — the matrix is the answer', 'ပြန်ပေးစရာ မရှိ — matrix ကိုယ်တိုင် အဖြေ'), }; } diff --git a/src/lessons/x-sum/lesson.js b/src/lessons/x-sum/lesson.js index cb1940e..396777b 100644 --- a/src/lessons/x-sum/lesson.js +++ b/src/lessons/x-sum/lesson.js @@ -119,6 +119,7 @@ const L = { notCounted: t('not counted yet', 'မရေတွက်ရသေး'), rankHead: (n) => t(`rank by [count, value], keep ${n}`, `[count, value] ဖြင့် အဆင့်ခွဲပြီး ${n} ခု ထားသည်`), notRanked: t('not ranked yet', 'အဆင့် မခွဲရသေး'), + notSummed: t('not summed yet', 'မပေါင်းရသေး'), sumHead: t('sum the survivors', 'ကျန်ရစ်သူများကို ပေါင်းသည်'), cutKeep: (n) => t(`cut · keep ${n}`, `ဖြတ်မျဉ်း · ${n} ခု ထားသည်`), qNothing: t('nothing kept', 'ဘာမှ မကျန်'), @@ -425,8 +426,9 @@ function drawBrute(s, { k }) { + `
2${pick(L.rankHead(s.keep))}
` + `
${s.stage >= 2 ? rankHTML : `${pick(L.notRanked)}`}
` + `
3${pick(L.sumHead)}
` - + `
${s.stage >= 3 ? kept.map((e) => `${e.v}×${e.c}`).join(' + ') : '—'}` - + `${s.stage >= 3 ? s.sum : '·'}X-SUM
` + + (s.stage >= 3 + ? `
${kept.map((e) => `${e.v}×${e.c}`).join(' + ')}${s.sum}X-SUM
` + : `${pick(L.notSummed)}`) + '' + ''; } diff --git a/src/lib/stage.js b/src/lib/stage.js index b386139..57d28fe 100644 --- a/src/lib/stage.js +++ b/src/lib/stage.js @@ -10,6 +10,7 @@ */ import { esc } from './stepper.js'; +import { pick } from './i18n.js'; const tones = (t) => (t ? ` t-${t}` : ''); @@ -46,6 +47,11 @@ export function cells(items, o = {}) { return hasMarks ? `
${html}
` : html; } +/* What an answer slot holds before its value is known: a faint "?" on + * screen, "not yet" to a screen reader. */ +const NOT_YET = { en: 'not yet', my: 'မရသေး' }; +export const blank = () => `${esc(pick(NOT_YET))}`; + /* The answer card's slots: filled ones hold a value, `just` marks the one * this step wrote. */ export function slots(values, o = {}) { @@ -53,7 +59,7 @@ export function slots(values, o = {}) { let html = ''; for (let i = 0; i < total; i++) { const filled = i < values.length; - html += `${filled ? esc(values[i]) : '·'}`; + html += `${filled ? esc(values[i]) : blank()}`; } return html; } diff --git a/src/styles/base.css b/src/styles/base.css index 0486054..5c55d00 100644 --- a/src/styles/base.css +++ b/src/styles/base.css @@ -26,6 +26,8 @@ h1{font-size:clamp(28px,4.6vw,42px);letter-spacing:-.022em;line-height:1.05} h2,.as-h2{font-size:19px;letter-spacing:-.01em} h3,.as-h3{font-size:14px;letter-spacing:-.005em;font-weight:600} p{margin:0} +/* Read by a screen reader, not shown. */ +.vh{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0} code,.mono{font-family:"IBM Plex Mono",ui-monospace,SFMono-Regular,Menlo,monospace;font-variant-numeric:tabular-nums} .eyebrow{ font-family:"IBM Plex Mono",monospace;font-size:11.5px;letter-spacing:.14em;