Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .claude/skills/leetcode-solution-page/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ step. This skill adds the judgement the procedure can't encode.
computed.
8. **`npm run check`**, `npm run verify -- <slug>` again, then the browser:
every approach × language highlights a line on every step, the page opens on
step 1, and nothing scrolls sideways at 400px in either language.
step 1, and nothing scrolls sideways at 400px or 320px in either language.
`npm run audit -- <slug>` checks these, and that a shared link reopens the
same step.

## Part 2

Expand Down Expand Up @@ -93,6 +95,13 @@ Gotchas and proofs go in collapsed notes phrased as questions.
**Snapshots copy state.** A step that shares a mutable array with the next
draws the final state on every frame.

**A kit change is measured on every lesson.** A change to `stepper.js`,
`stage.js` or the shared CSS lands on all pages, so judge it across all of
them before choosing: Part 1 looked lopsided on x-sum, but measured on all 46
lessons the taller column went either way, and the fix that suited x-sum
made most pages worse. Script the measurement in a browser, and when the
choice changes how pages look, show a before and after.

## Burmese

English-only is acceptable, because a missing Burmese side falls back to
Expand Down
52 changes: 39 additions & 13 deletions .claude/skills/leetcode-solution-page/references/lesson-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ bespoke stage, `x-sum`.
`node scripts/check-lessons.mjs` fails a lesson that is missing any part
marked ✓.

**Header** — eyebrow (`LeetCode 1 · Easy`), title, lede, the three jump chips
and a "View on LeetCode ↗" chip per problem in `links`, English/မြန်မာ switch
top right.
**Header** — eyebrow (`LeetCode 1 · Easy`), title, lede, the three jump chips,
then a plain "View on LeetCode ↗" link per problem in `links` past a divider
(a link that leaves the page, so it isn't a chip), English/မြန်မာ switch top
right.

**1 · The question**
- Statement card: LeetCode's prose verbatim (`statement.html`), constraints as
Expand All @@ -44,7 +45,9 @@ top right.
`<input type=range>` and `<output>`, `.q-presets` chips, an amber `.q-tie`
line for the sentence, and a `.ledger` whose `.expr` holds a **formula** (it
renders mono) and whose `.total` holds one big number with a `<small>`
label. Set the panel's right-hand note via `#q-label`.
label. Set the panel's right-hand note via `#q-label`. The kit's chips and
buttons grow to 40px on a touch screen; a clickable element the widget
draws itself (a board square) is at least 40px tall there too.
- ✓ Example cards: input, output, a `why` list explaining the answer, and a
"Load into the stepper" button.
- The traps disclosure, phrased as "N ways the statement bites".
Expand All @@ -60,7 +63,9 @@ top right.
array strip (`cfg.strip`; `noStrip: true` only when the input is genuinely
not a row), transport with the narration under it, then the stage and ✓ the
answer beside "The code, live" with hoverable variables and any `caveats`
note under it. Don't add boxes inside the player. ✓ Under the player, the
note under it. Don't add boxes inside the player. The transport and
narration stay under the masthead while the reader scrolls the stage and
code, and the strip wraps onto more rows on a narrow screen. ✓ Under the player, the
`playHint` line from `page.js`: the keys (`←` `→` step · `space`
play/pause), what the reader can edit "above" and any limits ("up to 12
values"), and what rebuilds. The layout renders it after `#lesson` and the
Expand All @@ -70,9 +75,12 @@ top right.
storing?"). A takeaway goes in the notes — never as a part of its own.
Label anything computed rather than measured.

**3 · The whole solution** — language tabs, then one block per approach with a
✓ caption (`solutions[mode].desc`, optional `tag` such as `3321`), a
verification badge and a Copy button.
**3 · The whole solution** — language tabs that stay in reach while it
scrolls, then one block per approach with a ✓ caption (`solutions[mode].desc`,
optional `tag` such as `3321`), a verification badge and a Copy button. The
approach chosen in 2·1 is open and the rest fold to their heading. `modes[0]`
is the one a page opens on, in 2·2 and here, so list first the approach a
reader should meet first.

## The folder a lesson writes

Expand Down Expand Up @@ -101,8 +109,17 @@ is empty ("root = null"), `labelledRows` for a strip card with two inputs
(`labelledRows(rows, { grid: true })` for a board or matrix, its columns
lined up; the widget's board is a `.q-grid` of `.q-arr` rows). Controls parse with `intList({ min, max, lo, hi, distinct, check })`
and `intValue({ lo, hi })` — they reject rather than trim, and `check` takes
the lesson's own rule (sorted, a majority exists). A control shows a list back
as `1, 2, 3` by itself; give it a `format` only for another shape. The part 1 widget uses `presetChips(sets, active)` for its chips
the lesson's own rule (sorted, a majority exists). A rejection's message is a
short phrase ("integers, separated by commas"): the kit marks the field and
follows it with "the walkthrough below still shows the last input that
worked". A control shows a list back as `1, 2, 3` by itself; give it a
`format` only for another shape.

**Ids and keys are addresses.** The walkthrough's place lives in the query
string — `?approach=heap&step=7&lang=python&nums=1,2,3` — so a mode's `id`
and a control's `key` are part of every link a reader shares. Keep them
short and stable once published, and make `parse(format(v))` give back `v`
for every control, so a shared link reopens the same input. The part 1 widget uses `presetChips(sets, active)` for its chips
(the active one is `aria-pressed`, which lesson.css draws as selected; a
widget's own toggle chips should set it too) and `widgetLabel(text)` for the
note beside its heading. Anything a lesson draws uses a class from `lesson.css`, `kit.css`
Expand Down Expand Up @@ -168,7 +185,7 @@ fails a lesson whose `page.js` leaves one out.
| Function | Draws |
| --- | --- |
| `cells(items, o)` | the strip's cells — for `cfg.strip` |
| `slots(values, o)` | the answer card's slots — for `cfg.answer` |
| `slots(values, o)` | the answer card's slots — for `cfg.answer`; an unfilled one shows `?` and reads "not yet" |
| `stagePanel(title, note, inner)` | a titled block inside the stage |
| `kv` `stack` `chain` `tree` `bars` `readout` `strip` `panels` | the auxiliary shapes |
| `trieOutline({ nodes, ends, at, made, miss })` | a trie, one row per node named by its prefix |
Expand All @@ -180,7 +197,15 @@ matched), `leaving` (red dashed, dropped or failed), `done` (faded, settled).

A stage the primitives can't draw (x-sum's shelves and heaps) is the lesson's
own markup, styled by its `style.css` or, if another lesson would use it, by
`kit.css`.
`kit.css`. Its headings sit under `stagePanel`'s `<h4>`, so they are
`<h5 class="as-h3">` (x-sum's brute-force steps), keeping the page outline
unbroken while looking like any other small heading.

**Empty says what it is waiting for.** Before a value exists, show words — a
`stageEmpty('root = null')`, an `<span class="empty">not counted yet</span>` —
or a slot from `slots()`; a slot the lesson builds by hand takes `blank()`
from `stage.js`. A `·` belongs where it is notation: an empty board square, a
table cell not yet computed, an unknown bit.

## Traps

Expand All @@ -204,7 +229,8 @@ node scripts/check-lessons.mjs # every lesson — structure and forma
node scripts/check-lessons.mjs two-sum # one
python3 scripts/verify/run.py <slug> # every listing × 5 languages, then every walkthrough
python3 scripts/verify/run.py <slug> --from DIR # listing files, before they are in lesson.js
npm run build && npm run audit -- <slug> # in a browser: a lit line on every step, presets, errors, 400px
npm run build && npm run audit -- <slug> # in a browser: a lit line on every step, presets, errors,
# 400px and 320px, heading order, empty states, keys, shared links
```

`npm run audit` needs Chromium once: `npx playwright install chromium`.
Expand Down
10 changes: 7 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ npm run dev # then open your page next to /leetcode/two-sum

The audit drives the built page in Chromium (once: `npx playwright install
chromium`): every approach × language highlights a line on every step, every
preset loads, nothing throws, and nothing scrolls sideways at 400px in either
language. What it cannot tell you is whether the page reads well — open it
preset loads, nothing throws, nothing scrolls sideways at 400px or 320px in
either language, headings never skip a level, an empty answer says "?" or
words rather than a bare dot, space and the arrow keys do what a focused
control expects, and a shared link reopens the same step. What it cannot
tell you is whether the page reads well — open it
beside another one and look.

## Burmese
Expand All @@ -205,7 +208,8 @@ collects phrasings a native reader should check. Help there is very welcome.
- [ ] `npm run verify -- <slug>` passes, with Go and Rust run (not skipped)
- [ ] every badge says what was actually run; every trap output was produced by running it
- [ ] `npm run build` succeeds, then `npm run audit -- <slug>` passes: a line lit on
every step, presets load, no page errors, nothing too wide at 400px
every step, presets load, no page errors, nothing too wide at 400px or
320px, and a shared link reopens the same step
- [ ] opens on step 1, and reads well beside another page at the same width
- [ ] if you changed how every page is built (`src/lib/`, `src/layouts/`,
`lesson.css`, `kit.css`, the checker), the skill in
Expand Down
113 changes: 105 additions & 8 deletions scripts/audit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
// · every input field accepts the text it shows, and rejects junk
// · no page errors
// · nothing wider than the screen at 400px, in both page languages, for
// every approach and code language
// every approach and code language — and at 320px, a small phone
// · headings never skip a level, on any step
// · nothing waiting for a value shows a bare "·" or "—": answer slots,
// empty-stage notes and ledgers say "?" or words (a dot in a stage cell
// is notation, and allowed)
// · keys: space on a focused button presses it rather than playing, and
// an arrow on an approach tab moves between tabs rather than stepping
// · a shared link reopens the same approach, step, code language and
// input, and "Report an issue" carries it
// · a toned row in a key/value table is actually coloured (a later CSS
// rule once turned every highlighted row grey)
// · the home page loads, lists every lesson, and fits at 400px
Expand Down Expand Up @@ -71,7 +79,25 @@ function serve() {
/* Runs inside the page: step every frame of every approach × code language. */
async function stepEverything() {
const wait = () => new Promise((r) => setTimeout(r, 0));
const out = { frames: 0, noHot: [], presets: [], greyTone: [], fields: [] };
const out = { frames: 0, noHot: [], presets: [], greyTone: [], fields: [], outline: new Map(), blank: new Map() };
// One line per approach and problem, naming the first step it shows on.
const once = (map, mode, i, what) => { if (!map.has(`${mode}: ${what}`)) map.set(`${mode}: ${what}`, i); };
// Heading levels in page order may step down any amount, up only by one.
const outline = (mode, i) => {
const hs = [...document.querySelectorAll('h1,h2,h3,h4,h5,h6')].filter((h) => h.getClientRects().length);
for (let j = 1; j < hs.length; j++) {
const [a, b] = [+hs[j - 1].tagName[1], +hs[j].tagName[1]];
if (b > a + 1) once(out.outline, mode, i, `h${a} "${hs[j - 1].textContent.trim().slice(0, 30)}" → h${b} "${hs[j].textContent.trim().slice(0, 30)}"`);
}
};
// A spot waiting for a value whose own text is only a dot or dash.
const PLACEHOLDER = /^[·•▪—–.…-]+$/;
const blank = (mode, i) => {
for (const el of document.querySelectorAll('#lesson [data-answer] *, #lesson .stage-empty, #lesson .ledger .expr, #lesson .ledger .total')) {
const own = [...el.childNodes].filter((n) => n.nodeType === 3).map((n) => n.textContent).join('').trim();
if (PLACEHOLDER.test(own)) once(out.blank, mode, i, `"${own}" in .${[...el.classList].join('.') || el.tagName.toLowerCase()}`);
}
};
const toneless = (el) => ![...el.classList].some((c) => c.startsWith('t-'));
const plainRowBg = () => {
const plain = [...document.querySelectorAll('#lesson .st-row:not(.head):not(.on)')].find(toneless);
Expand All @@ -89,6 +115,8 @@ async function stepEverything() {
const toned = document.querySelector('#lesson .st-row.t-up, #lesson .st-row.t-warn');
const plain = plainRowBg();
if (toned && plain && getComputedStyle(toned).backgroundColor === plain) out.greyTone.push(`${mode}/step ${i}`);
outline(mode, i);
blank(mode, i);
}
}
// each field re-reads its own text without complaint, and flags garbage
Expand All @@ -109,24 +137,28 @@ async function stepEverything() {
if (warn && !warn.hidden) out.presets.push(`${mode}: "${chip.textContent.trim()}" → ${warn.textContent.trim()}`);
}
}
return out;
const lines = (map) => [...map].map(([what, i]) => `${what} (from step ${i})`);
return { ...out, outline: lines(out.outline), blank: lines(out.blank) };
}

/* Runs inside the page at 400px: the widest the page gets, anywhere. */
async function widestAt400() {
/* Runs inside the page at a phone width: the widest the page gets, anywhere.
* `everyLang` walks each code language too; at 320px one is enough, since the
* page's width does not depend on which listing the code panel holds. */
async function widest(everyLang) {
const wait = () => new Promise((r) => setTimeout(r, 15));
const found = [];
for (const mode of [...document.querySelectorAll('#lesson .atab')].map((b) => b.dataset.mode)) {
document.querySelector(`#lesson .atab[data-mode="${mode}"]`).click(); await wait();
const scrub = document.querySelector('#lesson [data-scrub]');
for (const lang of [...document.querySelectorAll('#lesson .lang-bar.mini .lang')].map((b) => b.dataset.lang)) {
const langs = [...document.querySelectorAll('#lesson .lang-bar.mini .lang')].map((b) => b.dataset.lang);
for (const lang of everyLang ? langs : langs.slice(0, 1)) {
document.querySelector(`#lesson .lang-bar.mini .lang[data-lang="${lang}"]`).click(); await wait();
for (const ui of ['en', 'my']) {
document.querySelector(`[data-lang-opt="${ui}"]`).click(); await wait();
for (const i of [0, Math.floor(Number(scrub.max) / 2), Number(scrub.max)]) {
scrub.value = String(i); scrub.dispatchEvent(new Event('input', { bubbles: true })); await wait();
const over = document.documentElement.scrollWidth - window.innerWidth;
if (over > 0) found.push(`${mode}/${lang}/${ui}/step ${i}: ${over}px too wide`);
if (over > 0) found.push(`${innerWidth}px ${mode}/${lang}/${ui}/step ${i}: ${over}px too wide`);
}
}
}
Expand All @@ -135,6 +167,63 @@ async function widestAt400() {
return found;
}

/* Real key presses, then a shared link opened fresh. The page is English
* (main's init script), so the play button reads "Play" when stopped. */
async function keysAndLink(page, url) {
const found = [];
await page.goto(url);
await page.waitForSelector('#lesson .atab');
if (new URL(page.url()).search) found.push(`an untouched page has a query: ${new URL(page.url()).search}`);
const count = () => page.$eval('#lesson [data-count]', (e) => e.textContent.trim());
const playLabel = () => page.$eval('#lesson [data-act="play"]', (e) => e.textContent.trim());

await page.focus('#lesson [data-act="next"]');
await page.keyboard.press(' ');
if (!(await count()).startsWith('2 /') || (await playLabel()) !== 'Play') {
found.push(`space on a focused Next: step ${await count()}, play button "${await playLabel()}" (want step 2, not playing)`);
await page.click('#lesson [data-act="play"]').catch(() => {});
}
if ((await page.$$('#lesson .atab')).length > 1) {
await page.focus('#lesson .atab[aria-selected="true"]');
await page.keyboard.press('ArrowRight');
const tab = await page.evaluate(() => {
const t = [...document.querySelectorAll('#lesson .atab')];
return [t.indexOf(document.activeElement), t.findIndex((x) => x.getAttribute('aria-selected') === 'true')];
});
if (tab[0] !== 1 || tab[1] !== 1) found.push(`→ on an approach tab: focus on tab ${tab[0]}, tab ${tab[1]} selected (want 1 and 1)`);
if (!(await count()).startsWith('1 /')) found.push(`→ on an approach tab stepped the walkthrough: ${await count()}`);
}

// Change everything a link carries, then open the address in a fresh load.
await page.evaluate(() => {
document.querySelector('#lesson .lang-bar.mini .lang:last-child').click();
document.querySelector('#lesson [data-preset]:last-child')?.click();
for (let i = 0; i < 3; i++) document.querySelector('#lesson [data-act="next"]').click();
});
await page.waitForTimeout(300); // the address is written after a 150ms debounce
const where = () => page.evaluate(() => ({
mode: document.querySelector('#lesson .atab[aria-selected="true"]')?.dataset.mode,
step: document.querySelector('#lesson [data-count]').textContent.trim(),
lang: document.querySelector('#lesson .lang-bar.mini [aria-selected="true"]')?.dataset.lang,
part3: document.querySelector('#solutions [data-pane]:not([hidden])')?.dataset.pane,
fields: [...document.querySelectorAll('#lesson [data-field]')].map((e) => e.value),
}));
const before = await where();
const link = page.url();
const report = await page.evaluate(() => {
const a = document.querySelector('.report a[href*="/issues/new"]');
return a ? new URL(new URL(a.href).searchParams.get('page')).search : null;
});
if (report !== null && report !== new URL(link).search) found.push(`"Report an issue" names ${report || 'no state'}, the page is at ${new URL(link).search}`);
await page.goto(link);
await page.waitForSelector('#lesson .atab');
const after = await where();
for (const k of Object.keys(before)) {
if (JSON.stringify(before[k]) !== JSON.stringify(after[k])) found.push(`shared link ${new URL(link).search} reopens ${k} as ${JSON.stringify(after[k])}, not ${JSON.stringify(before[k])}`);
}
return found;
}

async function main() {
const server = await serve();
const BASE = `http://127.0.0.1:${server.address().port}`;
Expand Down Expand Up @@ -172,7 +261,12 @@ async function main() {
await page.emulateMedia({ colorScheme: 'light' });
await page.setViewportSize({ width: 400, height: 850 });
await page.waitForTimeout(100);
const wide = await page.evaluate(widestAt400);
const wide = await page.evaluate(widest, true);
await page.setViewportSize({ width: 320, height: 700 });
await page.waitForTimeout(100);
wide.push(...await page.evaluate(widest, false));
await page.setViewportSize({ width: 1300, height: 900 });
const keys = await keysAndLink(page, `${BASE}/leetcode/${slug}`);
page.off('pageerror', onError);
report(`${slug} (${r.frames} frames)`, [
...errors,
Expand All @@ -181,6 +275,9 @@ async function main() {
...r.fields,
...r.greyTone.map((x) => `toned table row renders grey: ${x}`),
...wide,
...r.outline.map((x) => `heading skips a level: ${x}`),
...r.blank.map((x) => `placeholder instead of words: ${x}`),
...keys,
...new Set(a11y),
]);
}
Expand Down
Loading