Add drawing canvas (canvas module, DrawingView, drawing_* tests) and levels 13-14 (classes, saved patterns)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
denis
2026-10-16 17:40:53 +02:00
parent 4689d25700
commit d3b7c611f1
46 changed files with 1250 additions and 22 deletions
+10
View File
@@ -3,6 +3,7 @@
import { el, renderInline, uniqueId } from './dom.js';
import { CodeEditor } from './CodeEditor.js';
import { DrawingView } from './DrawingView.js';
import { GuideBubble } from './GuideBubble.js';
import { HintPanel } from './HintPanel.js';
@@ -12,6 +13,7 @@ export class CellView extends EventTarget {
#root;
#editor;
#output;
#drawing;
#feedback;
#guideSlot;
#hintPanel;
@@ -59,6 +61,7 @@ export class CellView extends EventTarget {
const resetButton = el('button', { type: 'button', class: 'btn', text: i18n.t('cell.reset'), onclick: () => this.reset() });
this.#output = el('pre', { id: outputId, class: 'cell-output', 'aria-live': 'polite', 'aria-label': i18n.t('cell.output') });
this.#drawing = new DrawingView(i18n);
this.#feedback = el('div', { class: 'cell-feedback', role: 'status' });
this.#guideSlot = el('div', { class: 'cell-guide' });
this.#hintPanel = new HintPanel(i18n, hints, { onReveal: () => this.dispatchEvent(new CustomEvent('hint')) });
@@ -86,6 +89,7 @@ export class CellView extends EventTarget {
el('p', { id: `${editorId}-hint`, class: 'cell-shortcut', text: i18n.t('cell.shortcut') }),
el('div', { class: 'cell-actions' }, this.#runButton, this.#stopButton, resetButton, this.#hintPanel.element),
this.#output,
this.#drawing.element,
this.#inputForm,
this.#feedback,
this.#guideSlot,
@@ -115,6 +119,7 @@ export class CellView extends EventTarget {
clearOutput() {
this.#output.textContent = '';
this.#drawing.clear();
this.#feedback.replaceChildren();
this.#guideSlot.replaceChildren();
}
@@ -129,6 +134,11 @@ export class CellView extends EventTarget {
this.#guideSlot.replaceChildren(new GuideBubble(message).element);
}
/** Affiche le dessin produit par `canvas.line` (rien si aucun trait). */
showDrawing(segments) {
this.#drawing.render(segments ?? []);
}
appendOutput(text) {
this.#output.append(document.createTextNode(text));
}