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:
+7
-3
@@ -30,7 +30,7 @@ vrai navigateur (Chromium) avec 4 niveaux jouables.
|
||||
| Erreurs | `app/js/core/ErrorTranslator.js` + `app/js/i18n/errors.{fr,en}.json` |
|
||||
| Progression | `app/js/core/ProgressStore.js`, `KeyValueStores.js` (IndexedDB/mémoire), `SettingsStore.js` |
|
||||
| Audio / voix | `app/js/core/AudioEngine.js` (sons synthétisés), `VoiceEngine.js` (mp3 Piper + repli speechSynthesis), `speechKey.js` ; `scripts/generate_voice.py`, `voice_key.py` |
|
||||
| UI | `app/js/ui/` (CellView, CellManager, NotebookView, HintPanel, ProgressMap, BadgeToast, SettingsPanel, dom.js), `app/js/i18n/{i18n.js,fr.json,en.json}`, `app/css/app.css` |
|
||||
| UI | `app/js/ui/` (CellView, CellManager, NotebookView, HintPanel, ProgressMap, BadgeToast, SettingsPanel, dom.js), `app/js/i18n/{i18n.js,fr.json,en.json}`, `app/css/{themes,base,cells}.css`, `ui/CodeEditor.js`, `ui/highlightPython.js` |
|
||||
| Shell PWA | `app/index.html`, `app/js/main.js`, `app/service-worker.js`, `app/manifest.webmanifest` |
|
||||
| Tooling | `Makefile`, `scripts/{dev_server,validate_levels,build}.py`, `scripts/vendor_pyodide.sh` |
|
||||
| Tests | `tests/js/*.test.mjs` (node:test), `tests/python/`, `backend/sync/tests.py`, `tests/e2e/` (Chromium) |
|
||||
@@ -80,8 +80,12 @@ vrai navigateur (Chromium) avec 4 niveaux jouables.
|
||||
`ui/Drawer.js`, en-tête avec niveau courant + précédent/suivant, lien direct `#/levels/<id>`,
|
||||
historique navigateur). **Étape 1 faite** : page de propositions `docs/design/identity/index.html` (3 palettes
|
||||
avec contrastes WCAG calculés, 3 typographies auto-hébergeables OFL, 3 mascottes + messages
|
||||
fr/en) ; **recommandation : palette B, typo 2, mascotte 1 (Chouette)** — *en attente du choix de
|
||||
l'utilisateur*. **Reste** : identité visuelle
|
||||
fr/en) ; **recommandation : palette B, typo 2, mascotte 1 (Chouette)** — **choix validé par l'utilisateur** (voir
|
||||
`docs/design/07-visual-identity.md`). **Étape 2 faite** : CSS découpé (`themes`/`base`/`cells`),
|
||||
palette B + typo 2 auto-hébergée, éditeur coloré (`CodeEditor`, `highlightPython`), icône
|
||||
chouette + PNG (`make icons`), test de contraste des thèmes. **Étape 3 restante** : carte de
|
||||
progression graphique + personnage-guide (chouette) aux messages variés fr/en, badges
|
||||
illustrés, feedback coloré doublé de texte. Anciennes notes : **Reste** : identité visuelle
|
||||
(palette, typo, logo), découpage CSS (`base`/`themes`/`cells`), coloration syntaxique de
|
||||
l'éditeur, carte de progression graphique, personnage-guide aux messages variés fr/en,
|
||||
badges illustrés, feedback coloré (vert/rouge, toujours doublé d'un texte). Procéder en 3
|
||||
|
||||
@@ -5,7 +5,7 @@ VENV := .venv
|
||||
VENV_PY := $(VENV)/bin/python
|
||||
PORT ?= 8000
|
||||
|
||||
.PHONY: help install vendor-pyodide dev validate-levels build test test-js test-python test-backend test-e2e typecheck voice check-voice clean
|
||||
.PHONY: help install vendor-pyodide dev validate-levels build test test-js test-python test-backend test-e2e typecheck icons voice check-voice clean
|
||||
|
||||
help: ## Affiche cette aide
|
||||
@grep -E '^[a-z-]+:.*##' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " %-16s %s\n", $$1, $$2}'
|
||||
@@ -48,6 +48,10 @@ test-e2e: ## Tests bout en bout dans Chromium (CHROMIUM=/chemin/navigateur)
|
||||
typecheck: $(VENV)/.installed ## Vérifie les types Python avec pyright
|
||||
$(VENV)/bin/pyright
|
||||
|
||||
icons: ## Régénère les icônes PNG depuis app/icons/icon.svg (Chromium requis)
|
||||
npm --prefix tests/e2e install --silent
|
||||
node scripts/render_icons.mjs
|
||||
|
||||
voice: ## Génère la narration (Piper → mp3) pour les textes de niveaux ; voir levels/AUDIO-CREDITS.md
|
||||
$(PYTHON) -m venv .venv-voice
|
||||
.venv-voice/bin/pip install --quiet -r requirements-voice.txt
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright 2020 Braille Institute of America, Inc. AtkinsonHyperlegible-Italic.ttf: Copyright 2020 Braille Institute of America, Inc. AtkinsonHyperlegible-Bold.ttf: Copyright 2020 Braille Institute of America, Inc. AtkinsonHyperlegible-BoldItalic.ttf: Copyright 2020 Braille Institute of America, Inc.
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
@@ -0,0 +1,93 @@
|
||||
Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono) JetBrainsMono-Italic[wght].ttf: Copyright 2020 The JetBrains Mono Project Authors (https://github.com/JetBrains/JetBrainsMono)
|
||||
|
||||
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
||||
This license is copied below, and is also available with a FAQ at:
|
||||
http://scripts.sil.org/OFL
|
||||
|
||||
|
||||
-----------------------------------------------------------
|
||||
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
||||
-----------------------------------------------------------
|
||||
|
||||
PREAMBLE
|
||||
The goals of the Open Font License (OFL) are to stimulate worldwide
|
||||
development of collaborative font projects, to support the font creation
|
||||
efforts of academic and linguistic communities, and to provide a free and
|
||||
open framework in which fonts may be shared and improved in partnership
|
||||
with others.
|
||||
|
||||
The OFL allows the licensed fonts to be used, studied, modified and
|
||||
redistributed freely as long as they are not sold by themselves. The
|
||||
fonts, including any derivative works, can be bundled, embedded,
|
||||
redistributed and/or sold with any software provided that any reserved
|
||||
names are not used by derivative works. The fonts and derivatives,
|
||||
however, cannot be released under any other type of license. The
|
||||
requirement for fonts to remain under this license does not apply
|
||||
to any document created using the fonts or their derivatives.
|
||||
|
||||
DEFINITIONS
|
||||
"Font Software" refers to the set of files released by the Copyright
|
||||
Holder(s) under this license and clearly marked as such. This may
|
||||
include source files, build scripts and documentation.
|
||||
|
||||
"Reserved Font Name" refers to any names specified as such after the
|
||||
copyright statement(s).
|
||||
|
||||
"Original Version" refers to the collection of Font Software components as
|
||||
distributed by the Copyright Holder(s).
|
||||
|
||||
"Modified Version" refers to any derivative made by adding to, deleting,
|
||||
or substituting -- in part or in whole -- any of the components of the
|
||||
Original Version, by changing formats or by porting the Font Software to a
|
||||
new environment.
|
||||
|
||||
"Author" refers to any designer, engineer, programmer, technical
|
||||
writer or other person who contributed to the Font Software.
|
||||
|
||||
PERMISSION & CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
||||
redistribute, and sell modified and unmodified copies of the Font
|
||||
Software, subject to the following conditions:
|
||||
|
||||
1) Neither the Font Software nor any of its individual components,
|
||||
in Original or Modified Versions, may be sold by itself.
|
||||
|
||||
2) Original or Modified Versions of the Font Software may be bundled,
|
||||
redistributed and/or sold with any software, provided that each copy
|
||||
contains the above copyright notice and this license. These can be
|
||||
included either as stand-alone text files, human-readable headers or
|
||||
in the appropriate machine-readable metadata fields within text or
|
||||
binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No Modified Version of the Font Software may use the Reserved Font
|
||||
Name(s) unless explicit written permission is granted by the corresponding
|
||||
Copyright Holder. This restriction only applies to the primary font name as
|
||||
presented to the users.
|
||||
|
||||
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
||||
Software shall not be used to promote, endorse or advertise any
|
||||
Modified Version, except to acknowledge the contribution(s) of the
|
||||
Copyright Holder(s) and the Author(s) or with their explicit written
|
||||
permission.
|
||||
|
||||
5) The Font Software, modified or unmodified, in part or in whole,
|
||||
must be distributed entirely under this license, and must not be
|
||||
distributed under any other license. The requirement for fonts to
|
||||
remain under this license does not apply to any document created
|
||||
using the Font Software.
|
||||
|
||||
TERMINATION
|
||||
This license becomes null and void if any of the above conditions are
|
||||
not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
||||
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
||||
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
||||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+159
-225
@@ -1,57 +1,10 @@
|
||||
/* Styles de l'application : jetons de thème, clair/sombre, taille réglable, focus visible. */
|
||||
|
||||
:root {
|
||||
--bg: #ffffff;
|
||||
--surface: #f4f6fa;
|
||||
--text: #1b1f27;
|
||||
--muted: #4a5365;
|
||||
--border: #b8c0cf;
|
||||
--accent: #1d4ed8;
|
||||
--accent-text: #ffffff;
|
||||
--ok: #146c2e;
|
||||
--ko: #a31515;
|
||||
--focus: #b45309;
|
||||
/* Réglable par SettingsPanel : html { font-size: calc(var(--font-scale) * 100%) } */
|
||||
--font-scale: 1;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not([data-theme="light"]) {
|
||||
--bg: #12151c;
|
||||
--surface: #1c212c;
|
||||
--text: #eceff5;
|
||||
--muted: #b3bccd;
|
||||
--border: #4a5365;
|
||||
--accent: #8ab4ff;
|
||||
--accent-text: #0b1020;
|
||||
--ok: #6ee08a;
|
||||
--ko: #ff8a8a;
|
||||
--focus: #ffcc66;
|
||||
}
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #12151c;
|
||||
--surface: #1c212c;
|
||||
--text: #eceff5;
|
||||
--muted: #b3bccd;
|
||||
--border: #4a5365;
|
||||
--accent: #8ab4ff;
|
||||
--accent-text: #0b1020;
|
||||
--ok: #6ee08a;
|
||||
--ko: #ff8a8a;
|
||||
--focus: #ffcc66;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: calc(var(--font-scale) * 100%);
|
||||
}
|
||||
/* Base : corps de page, focus, boutons, en-tête, notebook, tiroirs, toasts, réglages. */
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
font-family: var(--font-ui);
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
@@ -60,26 +13,33 @@ body {
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.notebook {
|
||||
max-width: 48rem;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
/* L'attribut hidden doit toujours l'emporter sur les règles display des composants. */
|
||||
[hidden] {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.notebook-status {
|
||||
color: var(--muted);
|
||||
min-height: 1.5em;
|
||||
code,
|
||||
pre {
|
||||
font-family: var(--font-code);
|
||||
/* Pas de ligatures : un débutant doit voir exactement les caractères tapés (>= et non ≥). */
|
||||
font-variant-ligatures: none;
|
||||
}
|
||||
|
||||
.explain,
|
||||
.cell {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin: 1rem 0;
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
}
|
||||
|
||||
.skip-link:focus {
|
||||
left: 1rem;
|
||||
top: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
z-index: 30;
|
||||
}
|
||||
|
||||
/* Boutons */
|
||||
.btn {
|
||||
min-height: 2.75rem; /* cible tactile confortable (WCAG 2.5.8) */
|
||||
padding: 0.4rem 1rem;
|
||||
@@ -102,167 +62,6 @@ body {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.cell-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
.code-editor {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
|
||||
font-size: 1rem;
|
||||
padding: 0.75rem;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
tab-size: 4;
|
||||
}
|
||||
|
||||
.cell-shortcut {
|
||||
margin: 0.25rem 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
.cell-output {
|
||||
min-height: 1.5rem;
|
||||
margin: 0.5rem 0;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--bg);
|
||||
border-left: 4px solid var(--border);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.feedback-ok {
|
||||
color: var(--ok);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.feedback-ko,
|
||||
.error-title {
|
||||
color: var(--ko);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.hint-list {
|
||||
flex-basis: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.toast-region {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-width: calc(100vw - 2rem);
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
border: 2px solid var(--accent);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.level-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.level-button {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
margin: 0.25rem 0;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.level-button.is-current {
|
||||
border-width: 3px;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.setting {
|
||||
display: grid;
|
||||
grid-template-columns: 8rem 1fr;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
.setting select,
|
||||
.setting input[type="range"] {
|
||||
width: 100%;
|
||||
min-height: 2.5rem;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.setting input[type="checkbox"] {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
.setting > .btn:only-child {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
* {
|
||||
animation: none !important;
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.skip-link {
|
||||
position: absolute;
|
||||
left: -9999px;
|
||||
}
|
||||
|
||||
.skip-link:focus {
|
||||
left: 1rem;
|
||||
top: 1rem;
|
||||
padding: 0.5rem 1rem;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.explain > :first-child,
|
||||
.cell > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.level-button {
|
||||
flex-wrap: wrap;
|
||||
gap: 0.25rem 0.75rem;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.level-title {
|
||||
flex: 1 1 8rem;
|
||||
}
|
||||
|
||||
.level-state {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* En-tête : accès aux niveaux (gauche), niveau courant avec navigation (centre), réglages (droite). */
|
||||
.app-header {
|
||||
display: grid;
|
||||
@@ -281,6 +80,18 @@ body {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.brand {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.brand img {
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.app-heading h1 {
|
||||
margin: 0;
|
||||
font-size: 1.25rem;
|
||||
@@ -306,6 +117,59 @@ body {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Notebook */
|
||||
.notebook {
|
||||
max-width: 48rem;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
.notebook-status {
|
||||
color: var(--muted);
|
||||
min-height: 1.5em;
|
||||
}
|
||||
|
||||
.explain {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.explain > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.explain code {
|
||||
background: var(--code);
|
||||
padding: 0.05rem 0.3rem;
|
||||
border-radius: 0.25rem;
|
||||
}
|
||||
|
||||
/* Notifications */
|
||||
.toast-region {
|
||||
position: fixed;
|
||||
right: 1rem;
|
||||
bottom: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.5rem;
|
||||
max-width: calc(100vw - 2rem);
|
||||
z-index: 40;
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: flex;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
padding: 0.75rem 1rem;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
border: 2px solid var(--accent);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
/* Tiroirs coulissants. Fermés : visibility:hidden (hors navigation clavier), ouverts : glissent. */
|
||||
.drawer-overlay {
|
||||
position: fixed;
|
||||
@@ -375,6 +239,7 @@ body {
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
/* Progression */
|
||||
.progress-bar {
|
||||
width: 100%;
|
||||
height: 1rem;
|
||||
@@ -383,7 +248,69 @@ body {
|
||||
|
||||
.progress-count {
|
||||
margin: 0 0 0.25rem;
|
||||
font-weight: 600;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.level-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.level-button {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
gap: 0.25rem 0.75rem;
|
||||
width: 100%;
|
||||
margin: 0.25rem 0;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--surface);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.level-button.is-current {
|
||||
border-width: 3px;
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.level-title {
|
||||
flex: 1 1 8rem;
|
||||
}
|
||||
|
||||
.level-state {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* Réglages */
|
||||
.setting {
|
||||
display: grid;
|
||||
grid-template-columns: 8rem 1fr;
|
||||
gap: 0.75rem;
|
||||
align-items: center;
|
||||
margin: 0.75rem 0;
|
||||
}
|
||||
|
||||
.setting select,
|
||||
.setting input[type="range"] {
|
||||
width: 100%;
|
||||
min-height: 2.5rem;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.setting input[type="checkbox"] {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
justify-self: start;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
.setting > .btn:only-child {
|
||||
grid-column: 1 / -1;
|
||||
}
|
||||
|
||||
@media (max-width: 40rem) {
|
||||
@@ -396,3 +323,10 @@ body {
|
||||
grid-row: 2;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
* {
|
||||
animation: none !important;
|
||||
transition: none !important;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
/* Cellules de code : éditeur coloré, actions, sortie, retours de validation, indices, saisie. */
|
||||
|
||||
.cell {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.5rem;
|
||||
padding: 1rem;
|
||||
margin: 1rem 0;
|
||||
}
|
||||
|
||||
.cell > :first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.cell-actions {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.5rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
.cell-shortcut {
|
||||
margin: 0.25rem 0;
|
||||
color: var(--muted);
|
||||
font-size: 0.875rem;
|
||||
}
|
||||
|
||||
/* Éditeur : un <textarea> réel (clavier, lecteurs d'écran) dont le texte est rendu transparent, au-dessus
|
||||
d'un <pre> qui affiche le même code coloré. Même police, mêmes marges et même retour à la ligne. */
|
||||
.code-editor-wrap {
|
||||
position: relative;
|
||||
background: var(--code);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.code-editor-wrap:focus-within {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px var(--accent);
|
||||
}
|
||||
|
||||
.code-highlight,
|
||||
.code-editor {
|
||||
margin: 0;
|
||||
padding: 0.75rem;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
font-family: var(--font-code);
|
||||
font-size: 1rem;
|
||||
line-height: 1.5;
|
||||
tab-size: 4;
|
||||
white-space: pre;
|
||||
overflow: auto;
|
||||
border: 0;
|
||||
letter-spacing: 0;
|
||||
word-spacing: 0;
|
||||
font-variant-ligatures: none;
|
||||
}
|
||||
|
||||
.code-highlight {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
color: var(--text);
|
||||
pointer-events: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.code-editor {
|
||||
position: relative;
|
||||
display: block;
|
||||
resize: none;
|
||||
background: transparent;
|
||||
color: transparent;
|
||||
caret-color: var(--text);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.code-editor::selection {
|
||||
background: color-mix(in srgb, var(--accent) 35%, transparent);
|
||||
}
|
||||
|
||||
.tok-keyword {
|
||||
color: var(--tok-keyword);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.tok-string {
|
||||
color: var(--tok-string);
|
||||
}
|
||||
|
||||
.tok-number {
|
||||
color: var(--tok-number);
|
||||
}
|
||||
|
||||
.tok-comment {
|
||||
color: var(--tok-comment);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.tok-builtin {
|
||||
color: var(--tok-builtin);
|
||||
}
|
||||
|
||||
.tok-def {
|
||||
color: var(--tok-def);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.cell-output {
|
||||
min-height: 1.5rem;
|
||||
margin: 0.5rem 0;
|
||||
padding: 0.5rem 0.75rem;
|
||||
background: var(--bg);
|
||||
border-left: 4px solid var(--border);
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.feedback-ok {
|
||||
color: var(--ok);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.feedback-ko,
|
||||
.error-title {
|
||||
color: var(--ko);
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.hint-list {
|
||||
flex-basis: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.cell-input {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
margin: 0.5rem 0;
|
||||
}
|
||||
|
||||
.cell-input-field {
|
||||
flex: 1 1 12rem;
|
||||
min-height: 2.5rem;
|
||||
padding: 0.25rem 0.5rem;
|
||||
font-family: var(--font-code);
|
||||
font-variant-ligatures: none;
|
||||
font-size: 1rem;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 0.375rem;
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/* Identité visuelle : palette « Forêt & Corail », typographie Atkinson Hyperlegible + JetBrains Mono.
|
||||
Jetons de couleur clair/sombre (rapports de contraste vérifiés par tests/js/theme-contrast.test.mjs),
|
||||
polices auto-hébergées (COEP : aucune ressource cross-origin), taille de texte réglable. */
|
||||
|
||||
@font-face {
|
||||
font-family: "Atkinson Hyperlegible";
|
||||
src: url("../assets/fonts/atkinson-hyperlegible-latin-400-normal.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Atkinson Hyperlegible";
|
||||
src: url("../assets/fonts/atkinson-hyperlegible-latin-700-normal.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrains Mono";
|
||||
src: url("../assets/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
|
||||
font-weight: 400;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrains Mono";
|
||||
src: url("../assets/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
|
||||
font-weight: 700;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
:root {
|
||||
--font-ui: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
--font-code: "JetBrains Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
|
||||
/* Réglable par SettingsPanel : html { font-size: calc(var(--font-scale) * 100%) } */
|
||||
--font-scale: 1;
|
||||
|
||||
/* Clair */
|
||||
--bg: #ffffff;
|
||||
--surface: #f3f7f6;
|
||||
--code: #ebf2f0;
|
||||
--text: #16231f;
|
||||
--muted: #475b55;
|
||||
--border: #b4c4bf;
|
||||
--accent: #0f766e;
|
||||
--accent-text: #ffffff;
|
||||
--hl: #c2410c; /* corail : XP, focus */
|
||||
--focus: #c2410c;
|
||||
--ok: #166534;
|
||||
--ko: #b42318;
|
||||
--tok-keyword: #9a3412;
|
||||
--tok-string: #166534;
|
||||
--tok-number: #1d4ed8;
|
||||
--tok-comment: #4f625c;
|
||||
--tok-builtin: #0f766e;
|
||||
--tok-def: #6d28d9;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root:not([data-theme="light"]) {
|
||||
--bg: #0f1715;
|
||||
--surface: #18231f;
|
||||
--code: #121c19;
|
||||
--text: #e8f1ee;
|
||||
--muted: #a9bdb6;
|
||||
--border: #41544e;
|
||||
--accent: #5eead4;
|
||||
--accent-text: #04201c;
|
||||
--hl: #fdba74;
|
||||
--focus: #fdba74;
|
||||
--ok: #86efac;
|
||||
--ko: #fda4af;
|
||||
--tok-keyword: #fdba74;
|
||||
--tok-string: #86efac;
|
||||
--tok-number: #93c5fd;
|
||||
--tok-comment: #9db0a9;
|
||||
--tok-builtin: #5eead4;
|
||||
--tok-def: #c4b5fd;
|
||||
}
|
||||
}
|
||||
|
||||
:root[data-theme="dark"] {
|
||||
--bg: #0f1715;
|
||||
--surface: #18231f;
|
||||
--code: #121c19;
|
||||
--text: #e8f1ee;
|
||||
--muted: #a9bdb6;
|
||||
--border: #41544e;
|
||||
--accent: #5eead4;
|
||||
--accent-text: #04201c;
|
||||
--hl: #fdba74;
|
||||
--focus: #fdba74;
|
||||
--ok: #86efac;
|
||||
--ko: #fda4af;
|
||||
--tok-keyword: #fdba74;
|
||||
--tok-string: #86efac;
|
||||
--tok-number: #93c5fd;
|
||||
--tok-comment: #9db0a9;
|
||||
--tok-builtin: #5eead4;
|
||||
--tok-def: #c4b5fd;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: calc(var(--font-scale) * 100%);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
+13
-3
@@ -1,5 +1,15 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-label="PyQuest">
|
||||
<rect width="512" height="512" rx="96" fill="#1d4ed8"/>
|
||||
<path d="M150 200l-70 56 70 56M362 200l70 56-70 56" fill="none" stroke="#ffffff" stroke-width="36" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<path d="M286 150l-60 212" fill="none" stroke="#ffcc66" stroke-width="36" stroke-linecap="round"/>
|
||||
<rect width="512" height="512" fill="#0f766e"/>
|
||||
<g transform="translate(96 88) scale(2.67)">
|
||||
<ellipse cx="60" cy="68" rx="38" ry="42" fill="#d7ebe6"/>
|
||||
<path d="M30 38 L38 14 L52 30 Z M90 38 L82 14 L68 30 Z" fill="#d7ebe6"/>
|
||||
<circle cx="44" cy="58" r="15" fill="#ffffff"/>
|
||||
<circle cx="76" cy="58" r="15" fill="#ffffff"/>
|
||||
<circle cx="46" cy="59" r="7" fill="#16231f"/>
|
||||
<circle cx="74" cy="59" r="7" fill="#16231f"/>
|
||||
<circle cx="48" cy="56" r="2.2" fill="#ffffff"/>
|
||||
<circle cx="76" cy="56" r="2.2" fill="#ffffff"/>
|
||||
<path d="M54 72 L66 72 L60 84 Z" fill="#ea580c"/>
|
||||
<ellipse cx="60" cy="92" rx="22" ry="14" fill="#ffffff" opacity="0.75"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 417 B After Width: | Height: | Size: 834 B |
+8
-2
@@ -3,11 +3,14 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="theme-color" content="#1d4ed8">
|
||||
<meta name="theme-color" content="#0f766e">
|
||||
<title>PyQuest</title>
|
||||
<link rel="manifest" href="manifest.webmanifest">
|
||||
<link rel="icon" href="icons/icon.svg" type="image/svg+xml">
|
||||
<link rel="stylesheet" href="css/app.css">
|
||||
<link rel="apple-touch-icon" href="icons/icon-180.png">
|
||||
<link rel="stylesheet" href="css/themes.css">
|
||||
<link rel="stylesheet" href="css/base.css">
|
||||
<link rel="stylesheet" href="css/cells.css">
|
||||
</head>
|
||||
<body>
|
||||
<a class="skip-link" href="#main">Aller au contenu / Skip to content</a>
|
||||
@@ -15,7 +18,10 @@
|
||||
<header class="app-header">
|
||||
<button type="button" class="btn" id="levels-toggle"></button>
|
||||
<div class="app-heading">
|
||||
<div class="brand">
|
||||
<img src="icons/icon.svg" alt="" width="32" height="32">
|
||||
<h1 id="app-title">PyQuest</h1>
|
||||
</div>
|
||||
<nav class="level-nav" id="level-nav">
|
||||
<button type="button" class="btn" id="level-prev"><span aria-hidden="true">‹</span></button>
|
||||
<span class="level-current" id="level-current"></span>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Émet les événements 'run' (detail: { code }), 'stop' et 'reset'. Aucune logique d'exécution ici.
|
||||
|
||||
import { el, renderInline, uniqueId } from './dom.js';
|
||||
import { CodeEditor } from './CodeEditor.js';
|
||||
import { HintPanel } from './HintPanel.js';
|
||||
|
||||
export class CellView extends EventTarget {
|
||||
@@ -33,19 +34,16 @@ export class CellView extends EventTarget {
|
||||
|
||||
const editorId = uniqueId('editor');
|
||||
const outputId = uniqueId('output');
|
||||
this.#editor = el('textarea', {
|
||||
this.#editor = new CodeEditor({
|
||||
value: starter,
|
||||
attrs: {
|
||||
id: editorId,
|
||||
class: 'code-editor',
|
||||
spellcheck: 'false',
|
||||
autocapitalize: 'off',
|
||||
autocomplete: 'off',
|
||||
autocorrect: 'off',
|
||||
rows: Math.max(3, starter.split('\n').length + 1),
|
||||
'aria-label': i18n.t('cell.editor'),
|
||||
'aria-describedby': `${editorId}-hint`,
|
||||
onkeydown: (event) => this.#onKeyDown(event),
|
||||
},
|
||||
onKeyDown: (event) => this.#onKeyDown(event),
|
||||
});
|
||||
this.#editor.value = starter;
|
||||
|
||||
this.#runButton = el('button', { type: 'button', class: 'btn btn-primary cell-run', text: i18n.t('cell.run'), onclick: () => this.#emitRun() });
|
||||
this.#stopButton = el('button', {
|
||||
@@ -79,7 +77,7 @@ export class CellView extends EventTarget {
|
||||
'section',
|
||||
{ class: 'cell', tabindex: '-1' },
|
||||
el('p', { class: 'cell-instruction' }, renderInline(instruction)),
|
||||
this.#editor,
|
||||
this.#editor.element,
|
||||
el('p', { id: `${editorId}-hint`, class: 'cell-shortcut', text: i18n.t('cell.shortcut') }),
|
||||
el('div', { class: 'cell-actions' }, this.#runButton, this.#stopButton, resetButton, new HintPanel(i18n, hints).element),
|
||||
this.#output,
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Éditeur de code coloré. Un <textarea> réel reste le contrôle (clavier, lecteurs d'écran,
|
||||
// saisie mobile) ; un <pre> placé derrière affiche le même code coloré (aria-hidden).
|
||||
|
||||
import { el } from './dom.js';
|
||||
import { tokenizePython } from './highlightPython.js';
|
||||
|
||||
const MIN_ROWS = 3;
|
||||
|
||||
export class CodeEditor {
|
||||
#root;
|
||||
#textarea;
|
||||
#highlight;
|
||||
|
||||
/**
|
||||
* @param {object} options
|
||||
* @param {string} options.value
|
||||
* @param {Record<string, string>} [options.attrs] Attributs du textarea (id, aria-label…).
|
||||
* @param {(event: KeyboardEvent) => void} [options.onKeyDown]
|
||||
*/
|
||||
constructor({ value, attrs = {}, onKeyDown = () => {} }) {
|
||||
this.#highlight = el('pre', { class: 'code-highlight', 'aria-hidden': 'true' });
|
||||
this.#textarea = el('textarea', {
|
||||
class: 'code-editor',
|
||||
wrap: 'off',
|
||||
spellcheck: 'false',
|
||||
autocapitalize: 'off',
|
||||
autocomplete: 'off',
|
||||
autocorrect: 'off',
|
||||
...attrs,
|
||||
oninput: () => this.#render(),
|
||||
onscroll: () => this.#syncScroll(),
|
||||
onkeydown: onKeyDown,
|
||||
});
|
||||
this.#root = el('div', { class: 'code-editor-wrap' }, this.#highlight, this.#textarea);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
get element() {
|
||||
return this.#root;
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this.#textarea.value;
|
||||
}
|
||||
|
||||
set value(code) {
|
||||
this.#textarea.value = code;
|
||||
this.#render();
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.#textarea.focus();
|
||||
}
|
||||
|
||||
#render() {
|
||||
const code = this.#textarea.value;
|
||||
this.#textarea.rows = Math.max(MIN_ROWS, code.split('\n').length + 1);
|
||||
const nodes = tokenizePython(code).map(({ type, text }) =>
|
||||
type === 'text' ? document.createTextNode(text) : el('span', { class: `tok-${type}`, text }),
|
||||
);
|
||||
this.#highlight.replaceChildren(...nodes);
|
||||
this.#syncScroll();
|
||||
}
|
||||
|
||||
#syncScroll() {
|
||||
this.#highlight.scrollTop = this.#textarea.scrollTop;
|
||||
this.#highlight.scrollLeft = this.#textarea.scrollLeft;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Coloration syntaxique Python minimale, sans dépendance : découpe le code en jetons typés.
|
||||
// Tolérante (jamais d'exception sur du code incomplet) et sans perte : la concaténation des
|
||||
// textes des jetons redonne exactement le code d'entrée.
|
||||
|
||||
const KEYWORDS = new Set([
|
||||
'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del',
|
||||
'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal',
|
||||
'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield',
|
||||
]);
|
||||
|
||||
const BUILTINS = new Set([
|
||||
'abs', 'all', 'any', 'bool', 'dict', 'enumerate', 'filter', 'float', 'input', 'int', 'isinstance', 'len', 'list',
|
||||
'map', 'max', 'min', 'open', 'print', 'range', 'reversed', 'round', 'set', 'sorted', 'str', 'sum', 'tuple', 'type', 'zip',
|
||||
]);
|
||||
|
||||
// Ordre des alternatives = priorité : commentaire, chaîne triple, chaîne simple, nombre, identifiant, autre.
|
||||
// Les rétro-références comptent aussi les groupes nommés : \3 = guillemets triples, \5 = guillemet simple.
|
||||
const TOKEN = new RegExp(
|
||||
[
|
||||
String.raw`(?<comment>#[^\n]*)`,
|
||||
String.raw`(?<triple>(?:[rRuUbBfF]{0,2})("""|''')[\s\S]*?(?:\3|$))`,
|
||||
String.raw`(?<string>(?:[rRuUbBfF]{0,2})(["'])(?:\\.|(?!\5)[^\\\n])*(?:\5|(?=\n)|$))`,
|
||||
String.raw`(?<number>\d+(?:_\d+)*(?:\.\d+)?(?:[eE][+-]?\d+)?|\.\d+)`,
|
||||
String.raw`(?<identifier>[A-Za-z_À-ÿ][\wÀ-ÿ]*)`,
|
||||
String.raw`(?<other>[\s\S])`,
|
||||
].join('|'),
|
||||
'y',
|
||||
);
|
||||
|
||||
/**
|
||||
* @param {string} code
|
||||
* @returns {{type: 'keyword'|'string'|'number'|'comment'|'builtin'|'def'|'text', text: string}[]}
|
||||
*/
|
||||
export function tokenizePython(code) {
|
||||
const tokens = [];
|
||||
let expectName = false; // vrai juste après `def` ou `class` : le prochain identifiant est un nom défini
|
||||
TOKEN.lastIndex = 0;
|
||||
while (TOKEN.lastIndex < code.length) {
|
||||
const match = TOKEN.exec(code);
|
||||
const { comment, triple, string, number, identifier } = match.groups;
|
||||
let type = 'text';
|
||||
if (comment !== undefined) {
|
||||
type = 'comment';
|
||||
} else if (triple !== undefined || string !== undefined) {
|
||||
type = 'string';
|
||||
} else if (number !== undefined) {
|
||||
type = 'number';
|
||||
} else if (identifier !== undefined) {
|
||||
if (KEYWORDS.has(identifier)) {
|
||||
type = 'keyword';
|
||||
expectName = identifier === 'def' || identifier === 'class';
|
||||
} else {
|
||||
type = expectName ? 'def' : BUILTINS.has(identifier) ? 'builtin' : 'text';
|
||||
expectName = false;
|
||||
}
|
||||
}
|
||||
// Les espaces entre `def` et le nom ne rompent pas l'attente ; tout autre jeton la rompt.
|
||||
if (identifier === undefined && !/^\s+$/.test(match[0])) {
|
||||
expectName = false;
|
||||
}
|
||||
// Fusionne les jetons « texte » adjacents pour limiter le nombre de nœuds.
|
||||
const last = tokens.at(-1);
|
||||
if (type === 'text' && last?.type === 'text') {
|
||||
last.text += match[0];
|
||||
} else {
|
||||
tokens.push({ type, text: match[0] });
|
||||
}
|
||||
}
|
||||
return tokens;
|
||||
}
|
||||
@@ -6,10 +6,32 @@
|
||||
"start_url": "./",
|
||||
"scope": "./",
|
||||
"display": "standalone",
|
||||
"background_color": "#12151c",
|
||||
"theme_color": "#1d4ed8",
|
||||
"background_color": "#0f1715",
|
||||
"theme_color": "#0f766e",
|
||||
"icons": [
|
||||
{ "src": "icons/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" },
|
||||
{ "src": "icons/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "maskable" }
|
||||
{
|
||||
"src": "icons/icon-192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "any"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon-512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png",
|
||||
"purpose": "maskable"
|
||||
},
|
||||
{
|
||||
"src": "icons/icon.svg",
|
||||
"sizes": "any",
|
||||
"type": "image/svg+xml",
|
||||
"purpose": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
// - Pyodide vendorisé, niveaux, scripts : mis en cache à la première utilisation (hors ligne ensuite).
|
||||
// Les en-têtes COOP/COEP du document viennent du serveur ; ce worker ne les fabrique pas.
|
||||
|
||||
const CACHE_VERSION = 'pyquest-v2';
|
||||
const CACHE_VERSION = 'pyquest-v3';
|
||||
|
||||
const SHELL = ['./', 'index.html', 'manifest.webmanifest', 'css/app.css', 'icons/icon.svg', 'js/main.js'];
|
||||
const SHELL = ['./', 'index.html', 'manifest.webmanifest', 'css/themes.css', 'css/base.css', 'css/cells.css', 'icons/icon.svg', 'js/main.js'];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(caches.open(CACHE_VERSION).then((cache) => cache.addAll(SHELL)));
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# Identité visuelle (décidée le 2026-10-16)
|
||||
|
||||
Choix de l'utilisateur parmi les propositions de [`identity/index.html`](identity/index.html)
|
||||
(rapports de contraste calculés, polices et dessins comparés) :
|
||||
|
||||
| Élément | Choix | Mise en œuvre |
|
||||
|---|---|---|
|
||||
| Palette | **B — Forêt & Corail** (vert-bleu profond, accent corail pour XP et focus) | `app/css/themes.css` (jetons clair/sombre, y compris couleurs de coloration syntaxique) |
|
||||
| Typographie | **2 — Atkinson Hyperlegible + JetBrains Mono** | `app/assets/fonts/` (woff2 latin, licences OFL), `@font-face` dans `themes.css`, ligatures désactivées dans le code |
|
||||
| Mascotte | **1 — Chouette** | icône de l'application (`app/icons/icon.svg`, PNG 180/192/512 via `make icons`) ; personnage-guide à intégrer à l'étape 3 |
|
||||
|
||||
## Organisation du CSS
|
||||
|
||||
- `themes.css` : polices, jetons de couleur (clair, sombre, automatique), taille de texte.
|
||||
- `base.css` : page, boutons, en-tête, notebook, tiroirs, toasts, progression, réglages.
|
||||
- `cells.css` : cellules, éditeur coloré, sortie, retours de validation, indices, saisie `input()`.
|
||||
|
||||
## Garde-fous
|
||||
|
||||
- `tests/js/theme-contrast.test.mjs` lit `themes.css` et vérifie les rapports de contraste WCAG
|
||||
(texte ≥ 4,5 : 1, composants et focus ≥ 3 : 1, couleurs de coloration incluses), thèmes clair et sombre.
|
||||
- La coloration syntaxique (`app/js/ui/highlightPython.js`, `CodeEditor.js`) est décorative :
|
||||
le contrôle reste un `<textarea>` réel, le calque coloré est `aria-hidden`.
|
||||
+1
-1
@@ -12,7 +12,7 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
DIST = ROOT / "dist"
|
||||
PRECACHED_SUFFIXES = {".html", ".css", ".js", ".mjs", ".json", ".svg", ".webmanifest", ".py"}
|
||||
PRECACHED_SUFFIXES = {".html", ".css", ".js", ".mjs", ".json", ".svg", ".png", ".woff2", ".webmanifest", ".py"}
|
||||
NOT_PRECACHED = {"service-worker.js"}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Rasterise app/icons/icon.svg en PNG (apple-touch-icon et icônes du manifeste) avec Chromium.
|
||||
// Usage : make icons (nécessite tests/e2e/node_modules, donc `npm --prefix tests/e2e install`)
|
||||
import { chromium } from '../tests/e2e/node_modules/playwright-core/index.mjs';
|
||||
import { readFileSync } from 'node:fs';
|
||||
|
||||
const root = new URL('../', import.meta.url).pathname;
|
||||
const svg = readFileSync(`${root}app/icons/icon.svg`, 'utf8');
|
||||
const executablePath = process.env.CHROMIUM ?? '/usr/bin/chromium';
|
||||
const sizes = { 'icon-180.png': 180, 'icon-192.png': 192, 'icon-512.png': 512 };
|
||||
|
||||
const browser = await chromium.launch({ executablePath, args: ['--no-sandbox'] });
|
||||
try {
|
||||
for (const [name, size] of Object.entries(sizes)) {
|
||||
const page = await browser.newPage({ viewport: { width: size, height: size } });
|
||||
await page.setContent(`<style>html,body{margin:0}svg{display:block;width:${size}px;height:${size}px}</style>${svg}`);
|
||||
await page.screenshot({ path: `${root}app/icons/${name}` });
|
||||
await page.close();
|
||||
console.log(`app/icons/${name}`);
|
||||
}
|
||||
} finally {
|
||||
await browser.close();
|
||||
}
|
||||
@@ -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, []);
|
||||
});
|
||||
|
||||
@@ -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