From 5d429421b0be10671ce424e4879360b7a645a686 Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 01:51:39 +0630 Subject: [PATCH 1/4] Stepper keys, screen-reader narration and native dark controls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Space on a focused button, link or disclosure presses it instead of toggling playback; Alt/Ctrl/Cmd combos go to the browser (Alt+← is Back). - Approach and language tabs take ←/→/Home/End and use a roving tabindex, so only the selected tab is a Tab stop. - The narration is a polite live region, muted while autoplay runs; the scrubber announces "Step 2 of 12: tally" via aria-valuetext. - tokens.css sets color-scheme per theme, so scrollbars, range tracks and spinners are drawn dark on the dark theme. --- src/lib/stepper.js | 55 ++++++++++++++++++++++++++++++++++++------- src/styles/tokens.css | 7 +++++- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/lib/stepper.js b/src/lib/stepper.js index 35cd81a..82b0066 100644 --- a/src/lib/stepper.js +++ b/src/lib/stepper.js @@ -41,10 +41,33 @@ const $ = (sel, el = document) => el.querySelector(sel); const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"' }[c])); const nameOf = (k) => (typeof k === 'string' ? k : k?.en ?? ''); +/* A tab's selection attributes. Only the selected tab sits in the Tab order; + * the arrow keys move between the rest (tabKeys below). */ +const tabAttrs = (on) => `aria-selected="${on}" tabindex="${on ? 0 : -1}"`; +const selectTabs = (tabs, isOn) => tabs.forEach((b) => { + const on = isOn(b); + b.setAttribute('aria-selected', String(on)); + b.tabIndex = on ? 0 : -1; +}); + +/* Arrow keys, Home and End inside a tablist: move to that tab and select it. */ +function tabKeys(e) { + const tab = e.target.closest('[role="tab"]'); + if (!tab || e.altKey || e.ctrlKey || e.metaKey) return; + const tabs = [...tab.closest('[role="tablist"]').querySelectorAll('[role="tab"]')]; + const i = tabs.indexOf(tab); + const j = { ArrowRight: i + 1, ArrowLeft: i - 1, Home: 0, End: tabs.length - 1 }[e.key]; + if (j == null) return; + e.preventDefault(); + const to = tabs[(j + tabs.length) % tabs.length]; + to.click(); + to.focus(); +} + /* The code-language tabs: `mini` above the live code, plain above part 3. */ const langBar = (langs, active, cls = '') => `
${langs.map((l) => - ``).join('')} + ``).join('')}
`; /* Chrome owned by the engine rather than by any one lesson. */ @@ -58,6 +81,7 @@ const UI = { pause: { en: 'Pause', my: 'ရပ်' }, scrub: { en: 'Scrub through steps', my: 'အဆင့်များကို ဆွဲကြည့်ရန်' }, step: { en: 'step', my: 'အဆင့်' }, + stepOf: { en: 'Step {i} of {n}', my: 'အဆင့် {i} / {n}' }, answer: { en: 'answer', my: 'answer' }, codeLive: { en: 'The code, live', my: 'အလုပ်လုပ်နေသော code' }, input: { en: 'Input', my: 'Input' }, @@ -146,7 +170,7 @@ export function mountLesson(cfg) { ` : ''; const tabs = cfg.modes.map((m) => ` - ${meta.desc ? `

${pick(meta.desc)}

` : `

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

`} diff --git a/src/styles/base.css b/src/styles/base.css index 94fc4eb..0486054 100644 --- a/src/styles/base.css +++ b/src/styles/base.css @@ -19,10 +19,12 @@ body{ -webkit-font-smoothing:antialiased; } .wrap{max-width:1140px;margin:0 auto;padding-inline:20px;padding-block:32px 56px} -h1,h2,h3{font-family:Archivo,"IBM Plex Sans",sans-serif;font-weight:700;text-wrap:balance;margin:0} +/* .as-h2 and .as-h3 give a deeper heading the look of a shallower one, so the + outline can nest properly without the page changing how it looks. */ +h1,h2,h3,.as-h2,.as-h3{font-family:Archivo,"IBM Plex Sans",sans-serif;font-weight:700;text-wrap:balance;margin:0} h1{font-size:clamp(28px,4.6vw,42px);letter-spacing:-.022em;line-height:1.05} -h2{font-size:19px;letter-spacing:-.01em} -h3{font-size:14px;letter-spacing:-.005em;font-weight:600} +h2,.as-h2{font-size:19px;letter-spacing:-.01em} +h3,.as-h3{font-size:14px;letter-spacing:-.005em;font-weight:600} p{margin:0} code,.mono{font-family:"IBM Plex Mono",ui-monospace,SFMono-Regular,Menlo,monospace;font-variant-numeric:tabular-nums} .eyebrow{ diff --git a/src/styles/lesson.css b/src/styles/lesson.css index 6b9fe26..4af8239 100644 --- a/src/styles/lesson.css +++ b/src/styles/lesson.css @@ -26,6 +26,10 @@ input:focus-visible,button:focus-visible,select:focus-visible{outline:2px solid /* A widget chip that is the current choice (presetChips marks it aria-pressed). */ .chip[aria-pressed="true"]{border-color:var(--accent);color:var(--accent);background:var(--accent-soft);font-weight:600} .warn{color:var(--down);font-size:12.5px;flex-basis:100%} +/* A field that does not parse, and the player still showing the last input + that did: dimmed, not hidden, so the reader can compare. */ +input.bad{border-color:var(--down);box-shadow:0 0 0 1px var(--down)} +.player.is-stale [data-strip],.player.is-stale .narration,.player.is-stale .bench{opacity:.5;transition:opacity .15s} /* ---------- array strip ---------- */ .strip-head{display:flex;flex-wrap:wrap;gap:10px;justify-content:space-between;align-items:baseline;margin-bottom:12px} @@ -196,7 +200,7 @@ 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 h2{margin-right:auto} +.src-head h3{margin-right:auto} .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; @@ -250,9 +254,13 @@ td.mono{font-variant-numeric:tabular-nums} background:var(--surface);border:1px solid var(--line);border-radius:999px;padding:5px 13px 5px 8px; } .jump a:hover{border-color:var(--accent);color:var(--accent)} -/* The problem on LeetCode, after the part chips. */ -.jump a.lc{padding-left:13px} -.jump a.lc b{width:auto;padding:0 6px;border-radius:999px} +/* The problem on LeetCode, after the part chips: a plain link past a rule, + not another pill, so leaving the page does not look like moving down it. */ +.jump a.lc{background:none;border-color:transparent;color:var(--ink-3);padding-inline:6px;text-underline-offset:3px} +.jump a.lc:hover{border-color:transparent;text-decoration:underline} +.jump a.lc b{width:auto;height:auto;padding:0;border-radius:0;background:none;color:inherit;font-weight:600} +.jump a:not(.lc) + a.lc{position:relative;margin-left:9px} +.jump a:not(.lc) + a.lc::before{content:"";position:absolute;left:-9px;top:50%;height:16px;margin-top:-8px;border-left:1px solid var(--line-2)} .jump b{ font-family:"IBM Plex Mono",monospace;font-size:11px;color:var(--accent);background:var(--accent-soft); width:18px;height:18px;border-radius:50%;display:flex;align-items:center;justify-content:center; @@ -317,6 +325,7 @@ td.mono{font-variant-numeric:tabular-nums} /* Burmese stacks tall: give it room, and never let the script be squeezed */ :root[data-ui="my"] body{line-height:1.85;font-size:15px} :root[data-ui="my"] h1,:root[data-ui="my"] h2,:root[data-ui="my"] h3, +:root[data-ui="my"] .as-h2,:root[data-ui="my"] .as-h3, :root[data-ui="my"] .atab-name,:root[data-ui="my"] .part h2{ font-family:"Noto Sans Myanmar","Padauk",Archivo,sans-serif;line-height:1.5;letter-spacing:0; } @@ -461,3 +470,11 @@ td.mono{font-variant-numeric:tabular-nums} .report h3{margin:0 0 6px;font-size:16px} .report p{margin:0 0 12px;color:var(--ink-2);font-size:14px;line-height:1.55} .report-links{display:flex;flex-wrap:wrap;gap:8px} + +/* ---------- touch ---------- */ +/* On a touch screen the small controls grow to 40px tall — taller, not wider, + 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} + .jump a{min-height:40px} +} diff --git a/src/styles/site.css b/src/styles/site.css index 3310116..823174c 100644 --- a/src/styles/site.css +++ b/src/styles/site.css @@ -159,3 +159,10 @@ a.ptitle::after{content:"";position:absolute;inset:0;border-radius:inherit} .site-foot a:hover{color:var(--accent)} .site-foot .foot-link{color:var(--accent);text-decoration:underline;text-underline-offset:2px} .site-foot .sep{margin-inline-start:auto} + +/* On a touch screen the masthead's links and theme button grow to 40px, still + inside its 56px bar. */ +@media (pointer:coarse),(max-width:560px){ + .masthead nav a{display:inline-flex;align-items:center;min-height:40px} + .theme-btn{width:40px;height:40px} +} From d01186c8d7dba8a8bd2f8aac01ba67afca2ba68c Mon Sep 17 00:00:00 2001 From: devmtnaing Date: Sun, 27 Sep 2026 09:22:06 +0630 Subject: [PATCH 4/4] Shareable walkthrough links The walkthrough's place lives in the query string: approach, step, code language and any input the reader typed, e.g. /leetcode/x-sum?approach=heap&step=7&lang=python&nums=1,1,2,2,3 - Read before the first paint; unknown values fall back to the defaults and the step is clamped. Values at their defaults are left out, so an untouched page keeps its plain address. - Written with replaceState after each paint, debounced (Safari throws when replaceState is called too often during a scrubber drag). - Opening a shared link scrolls to the player; reload and Back do not. - "Report an issue" carries the same state in its page URL. - Comma lists travel without spaces when the field parses them the same. --- src/lib/stepper.js | 71 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/lib/stepper.js b/src/lib/stepper.js index a9ab1e6..d9a97a4 100644 --- a/src/lib/stepper.js +++ b/src/lib/stepper.js @@ -282,6 +282,7 @@ export function mountLesson(cfg) { const where = pick(UI.stepOf).replace('{i}', state.i + 1).replace('{n}', state.steps.length); scrub.setAttribute('aria-valuetext', pick(s.tag) ? `${where}: ${pick(s.tag)}` : where); $('[data-count]', root).textContent = `${state.i + 1} / ${state.steps.length}`; + writeAddress(); } function listing() { @@ -443,6 +444,71 @@ export function mountLesson(cfg) { if (name) { e.preventDefault(); act(name); } }); + /* ---------------- the address ---------------- */ + + // The reader's place — approach, step, code language and any input they + // typed — lives in the query string, so a copied link reopens that exact + // step: ?approach=heap&step=7&lang=python&nums=1,2,3. Values still at their + // defaults are left out, so an untouched page keeps its plain address. + const start = { mode: state.mode, lang: state.lang, input: structuredClone(cfg.input) }; + const fieldText = (c, input) => format(c, input[c.key]); + + function readAddress() { + const q = new URLSearchParams(location.search); + if (cfg.modes.some((m) => m.id === q.get('approach'))) state.mode = q.get('approach'); + if (langs.some((l) => l.id === q.get('lang'))) state.lang = q.get('lang'); + for (const c of cfg.controls || []) { + if (!q.has(c.key)) continue; + try { state.input[c.key] = c.parse ? c.parse(q.get(c.key)) : q.get(c.key); } catch { /* keep the default */ } + } + const step = Number(q.get('step')); + state.i = Number.isInteger(step) && step > 0 ? step - 1 : 0; + return ['approach', 'lang', 'step', ...(cfg.controls || []).map((c) => c.key)].some((k) => q.has(k)); + } + + // Readable in the address bar: commas, brackets and colons stay as typed. + const enc = (v) => encodeURIComponent(v).replace(/%20/g, '+').replace(/%2C/g, ',').replace(/%5B/g, '[').replace(/%5D/g, ']').replace(/%3A/g, ':'); + // "1, 2, 3" travels as "1,2,3" — but only when the field reads it back the + // same, so a sentence like "A man, a plan" keeps its spaces. + function compact(c, v) { + const tight = v.replace(/,\s+/g, ','); + if (tight === v || !c.parse) return v; + try { return fieldText(c, { [c.key]: c.parse(tight) }) === v ? tight : v; } catch { return v; } + } + function query() { + const q = []; + if (state.mode !== start.mode) q.push(['approach', state.mode]); + if (state.i > 0) q.push(['step', state.i + 1]); + if (state.lang !== start.lang) q.push(['lang', state.lang]); + for (const c of cfg.controls || []) { + const v = fieldText(c, state.input); + if (v !== fieldText(c, start.input)) q.push([c.key, compact(c, v)]); + } + return q.map(([k, v]) => `${k}=${enc(v)}`).join('&'); + } + + // Debounced: a scrubber drag paints dozens of steps a second, and Safari + // throws once a page calls replaceState too often. + let addressTimer = null; + function writeAddress() { + clearTimeout(addressTimer); + addressTimer = setTimeout(() => { + const q = query(); + const url = `${location.pathname}${q ? `?${q}` : ''}${location.hash}`; + try { if (url !== location.pathname + location.search + location.hash) history.replaceState(history.state, '', url); } catch { /* rate-limited */ } + // "Report an issue" names the page with the same state, so a report + // lands on the step it is about. + const report = document.querySelector('.report a[href*="/issues/new"]'); + if (report) { + const u = new URL(report.href); + const page = new URL(u.searchParams.get('page')); + page.search = q; + u.searchParams.set('page', page.href); + report.href = u.href; + } + }, 150); + } + /* ---------------- hover to inspect ---------------- */ const tip = document.createElement('div'); @@ -488,7 +554,12 @@ export function mountLesson(cfg) { rebuild(state.i); } + const shared = readAddress(); paintAll(); + // Arriving from a shared link, not a reload or Back: open on the player. + if (shared && !location.hash && performance.getEntriesByType('navigation')[0]?.type === 'navigate') { + $('[data-run]', root)?.scrollIntoView({ block: 'start' }); + } if (cfg.widget) { const host = document.getElementById('q-widget'); if (host) cfg.widget(host);