Apply visual identity: palette B, Atkinson/JetBrains fonts, split CSS, syntax-highlighted editor, owl icon

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
denis
2026-10-16 14:53:50 +02:00
parent 6e63a51a1b
commit 6b4b89a742
27 changed files with 994 additions and 255 deletions
+31
View File
@@ -295,3 +295,34 @@ test('navigation : lien direct vers un niveau, tiroirs accessibles, précédent/
assert.equal(await page.locator('.drawer-left.is-open').count(), 0);
assert.deepEqual(errors, []);
});
test('éditeur : coloration syntaxique, textarea réel, polices de la charte', { skip, timeout: 120000 }, async () => {
const page = await (await browser.newContext()).newPage();
const errors = [];
page.on('pageerror', (error) => errors.push(error.message));
await page.goto(`${base}#/levels/06-lists`);
await page.waitForSelector('.explain', { timeout: 60000 });
await page.locator('.notebook-action button').click();
const textarea = page.locator('.cell textarea');
await textarea.waitFor();
// Le contrôle reste un vrai textarea accessible ; la coloration est décorative (aria-hidden).
assert.equal(await page.locator('.code-highlight').getAttribute('aria-hidden'), 'true');
assert.equal(await textarea.getAttribute('aria-label'), 'Éditeur de code Python');
await textarea.fill('for n in range(3):\n print("a", n) # fin');
await page.waitForFunction(() => document.querySelectorAll('.code-highlight .tok-keyword').length === 2);
assert.equal(await page.locator('.code-highlight .tok-string').textContent(), '"a"');
assert.equal(await page.locator('.code-highlight .tok-comment').textContent(), '# fin');
// Charte : polices auto-hébergées effectivement chargées, sans ligature.
const fonts = await page.evaluate(async () => {
await document.fonts.ready;
return {
ui: document.fonts.check('16px "Atkinson Hyperlegible"'),
code: document.fonts.check('16px "JetBrains Mono"'),
ligatures: getComputedStyle(document.querySelector('.code-editor')).fontVariantLigatures,
};
});
assert.deepEqual(fonts, { ui: true, code: true, ligatures: 'none' });
assert.deepEqual(errors, []);
});
+39
View File
@@ -0,0 +1,39 @@
// Le tokenizer de coloration est sans perte, tolérant, et classe correctement les cas courants.
import assert from 'node:assert';
import { tokenizePython } from '../../app/js/ui/highlightPython.js';
const join = (tokens) => tokens.map((token) => token.text).join('');
const typed = (code) => tokenizePython(code).filter((token) => token.type !== 'text').map((token) => `${token.type}:${token.text}`);
const samples = [
'print("Bonjour", name) # salut\n',
"x = f'{a} é' + \"b\\\"c\"\n",
'def add(a, b):\n return a + b\n\nclass Foo:\n pass',
'total = 1_000 + 3.14e-2 + .5 + 0\n',
'"""docstring\nsur deux lignes"""\n',
'chaîne = "non fermée\nautre = 1',
"'''triple non fermée",
'if age >= 18 and not done:\n print(True, None)',
'',
'\t \n\n',
'é = 1; ñ = "ü"',
];
for (const code of samples) {
assert.equal(join(tokenizePython(code)), code, `sans perte : ${JSON.stringify(code)}`);
}
assert.deepEqual(typed('print("Bonjour", name) # salut'), ['builtin:print', 'string:"Bonjour"', 'comment:# salut']);
assert.deepEqual(typed('def add(a, b):'), ['keyword:def', 'def:add']);
assert.deepEqual(typed('class Foo:'), ['keyword:class', 'def:Foo']);
assert.deepEqual(typed('x = 3.14 + 1_000'), ['number:3.14', 'number:1_000']);
assert.deepEqual(typed('if a and not b: pass'), ['keyword:if', 'keyword:and', 'keyword:not', 'keyword:pass']);
assert.deepEqual(typed('# commentaire "pas une chaîne"'), ['comment:# commentaire "pas une chaîne"']);
assert.deepEqual(typed('"un # dans une chaîne"'), ['string:"un # dans une chaîne"']);
assert.deepEqual(typed("f'{x}'"), ["string:f'{x}'"]);
assert.deepEqual(typed('"""a\nb"""'), ['string:"""a\nb"""']);
assert.deepEqual(typed('while True:'), ['keyword:while', 'keyword:True']);
// Une chaîne non fermée s'arrête à la fin de la ligne : la suivante est colorée normalement.
assert.deepEqual(typed('s = "ouverte\ny = 2'), ['string:"ouverte', 'number:2']);
// Identifiant contenant un mot-clé : pas de faux positif.
assert.deepEqual(typed('printer = format_name'), []);
console.log('highlight ok');
+61
View File
@@ -0,0 +1,61 @@
// Garde-fou d'accessibilité : lit app/css/themes.css et vérifie les rapports de contraste WCAG
// des jetons (clair et sombre) — texte courant ≥ 4,5 : 1, composants et focus ≥ 3 : 1.
import { readFileSync } from 'node:fs';
import assert from 'node:assert';
const css = readFileSync(new URL('../../app/css/themes.css', import.meta.url), 'utf8');
/** Jetons d'un bloc de règles : { nom: '#rrggbb' }. */
function tokens(block) {
return Object.fromEntries([...block.matchAll(/--([\w-]+):\s*(#[0-9a-fA-F]{6})/g)].map((m) => [m[1], m[2]]));
}
const lightBlock = css.match(/:root \{([\s\S]*?)\n\}/)[1];
const darkBlock = css.match(/:root\[data-theme="dark"\] \{([\s\S]*?)\n\}/)[1];
const autoDarkBlock = css.match(/:root:not\(\[data-theme="light"\]\) \{([\s\S]*?)\n \}/)[1];
function luminance(hex) {
const channel = (offset) => {
const value = parseInt(hex.slice(offset, offset + 2), 16) / 255;
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
};
return 0.2126 * channel(1) + 0.7152 * channel(3) + 0.0722 * channel(5);
}
const ratio = (a, b) => {
const [high, low] = [luminance(a), luminance(b)].sort((x, y) => y - x);
return (high + 0.05) / (low + 0.05);
};
// Le thème sombre « automatique » (préférence système) et le sombre forcé doivent être identiques.
assert.deepEqual(tokens(autoDarkBlock), tokens(darkBlock), 'sombre auto ≠ sombre forcé');
const light = tokens(lightBlock);
const dark = { ...light, ...tokens(darkBlock) };
const failures = [];
for (const [mode, c] of [['clair', light], ['sombre', dark]]) {
const checks = [
['texte / fond', c.text, c.bg, 4.5],
['texte / surface', c.text, c.surface, 4.5],
['texte atténué / fond', c.muted, c.bg, 4.5],
['texte atténué / surface', c.muted, c.surface, 4.5],
['bouton principal', c['accent-text'], c.accent, 4.5],
['accent / fond (liens, cadre)', c.accent, c.bg, 3],
['focus / fond', c.focus, c.bg, 3],
['focus / surface', c.focus, c.surface, 3],
['XP (hl) / fond', c.hl, c.bg, 4.5],
['réussite / surface', c.ok, c.surface, 4.5],
['réussite / fond', c.ok, c.bg, 4.5],
['erreur / surface', c.ko, c.surface, 4.5],
['erreur / fond', c.ko, c.bg, 4.5],
['bordure / fond', c.border, c.bg, 1.5], // décorative : non exigée par WCAG pour du texte
...['keyword', 'string', 'number', 'comment', 'builtin', 'def'].map((name) => [`code ${name} / fond du code`, c[`tok-${name}`], c.code, 4.5]),
['code texte / fond du code', c.text, c.code, 4.5],
];
for (const [label, foreground, background, minimum] of checks) {
assert.ok(foreground && background, `jeton manquant pour « ${label} » (${mode})`);
const value = ratio(foreground, background);
if (value < minimum) failures.push(`${mode} · ${label} : ${value.toFixed(2)} < ${minimum}`);
}
}
assert.deepEqual(failures, []);
console.log('theme contrast ok');