mirror of
https://github.com/deunix-educ/PyQuest.git
synced 2026-11-25 08:19:44 +01:00
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:
@@ -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');
|
||||
@@ -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');
|
||||
Reference in New Issue
Block a user