العودة إلى المشروع

دليل

دليل الوحدات: نوع تمرين جديد

نوع تمرين جديد في مجلّد واحد: الملفّات، والقواعد التي تتحقّق منها الاختبارات، والأوامر.

مدّة القراءة: 9 دقائقهذا الدليل بالإنجليزية فقطالمصدر على GitHub

المحتويات 6
  1. Your first module in 10 minutes
  2. Its summary view (summary.js, optional)
  3. The files
  4. Classic scripts
  5. Rules the tests check
  6. Commands

A component is one folder, components/<name>/ (name = [a-z][a-z0-9_]+). Nothing else names it. Start it with python3 slk.py component new <name> (below), or copy classify/. Contract: docs/ARCHITECTURE.md §4.

Your first module in 10 minutes

  1. Make it (1 min): python3 slk.py component new star_note (a question: the child writes one answer) or python3 slk.py component new star_note --display (a box the child reads: never answered, scored or put on a test sheet, like callout and diagram). It writes the folder below, bundles it and writes its golden outputs: node tests/run.mjs and python3 -m unittest discover tests already pass.
  2. Draw it once (5 min): draw.js holds C.draw(v, ctx, opts), the ONE drawing that paper.js (the sheet and its key), play.js (the app), slide.js (the film) and summary.js (the lesson summary) all reuse. Change it, the schema and the card in component.json (every field, its limits, the common mistakes; ≤ 11 lines).
  3. Check it (3 min): python3 slk.py bundle, then SLK_UPDATE_GOLDEN=star_note node tests/run.mjs and READ the new golden/*.html; python3 slk.py card star_note: could a cheap model write a valid item from it alone?
  4. Try it (1 min): add its example to a copy of a lesson, python3 slk.py check <lesson.json>, then python3 slk.py summary <lesson.json> to see its summary view beside the others.
  5. Offer it (later): to list it on the kit's front page, add assets/home/modules/<name>.webp (its film slide at t = 1) and its card in the three languages of index.html (tests/test_home.py then checks all three).

Its summary view (summary.js, optional)

The lesson summary asks each item's component for summary.render(item, ctx): the REVISION view, the answer shown, compact, printable on A4 and readable at 360 px, no interaction, every text escaped. Return null when there is nothing worth revising (ctx.gap(text): a text with … or __ is a question). The result: {html, caption?, size?: "s"|"m"|"l", cls?, speech?: [text], place?: "start"|"end", media?: true}; flags on C.summary: always: true (shown outside the skill's budget, up to max: orders to learn, a labelled picture, display items) or spare: true (only a place the other views left: a filled-in text). Colours: var(--c) and var(--cs), the skill's own. ctx gives arrow (the reading direction), more(list, one) (the rest, on screen only), picture(media) ("" for a picture the summary already showed: each book picture once), shown(media) (ask first when you draw a picture another way) and limits. Reuse your own drawing: compare/summary.js prints the key's table, number_line/summary.js calls the sheet's C.line, label_image/summary.js draws the picture with leader lines by the shared SLK.kit.callouts. Models: sequence, classify, match, chain, transform, cloze.

The files

FileWhat it holds
component.jsonname (= folder), version, aliases (each names ONE component: never another's name or alias, slk.py bundle refuses a clash; an alias that is one of a field's enum values also fills that field, e.g. "type": "tip" → a callout with "kind": "tip"), answer (selected · produced · action · none), marking (auto · boxes · by_hand · none; both none = display-only, below), verb {ar, fr, en}, schema (the item fields), optional checks (below), optional "listen": false (the play shell hides its Listen button: a timed reading), optional "summary_top": true (its summary.top(d, ctx) draws a block under the summary's title: the lesson map), optional "own_media": {field: [values]} (an item with those values draws its own media, e.g. a picture diagram with its labels: the app, the film and the summary do not show that picture again), card, example. The full shape is COMPONENT_SCHEMA in tools/slk_cmd_bundle.py (in the app: SLK.componentSchema)
sample.jsoptional SLK.components.<name>.sample(item, rng, env) -> variant (env: null or {lesson, events}, see docs/ARCHITECTURE.md §4). Deterministic: use only rng(), rng.int/pick/shuffle/sample. item already has its schema defaults. An item that cannot be shown gets variant.problem (a sentence for a model): the app's loader then rejects it and lists it in the fix request, and so does slk.py check (it runs the app's loader with Node). Set variant.response when the answer kind depends on the drawn task (paper records keep it), and variant.helped: true when the sheet prints its own help (its paper answer is then never "alone")
paper.jspaper.render(v, ctx) and paper.key(v, ctx): HTML strings, no DOM. Optional paper.points(v) (default 1) and paper.missing(v, ctx) (a reason the item cannot be printed here, e.g. its picture is not on the device: the sheet leaves it out, points too)
play.jsplay.mount(el, v, ctx, report): build inside el only; call report({correct, score, max, response, detail}) once. Optional support: "oral_only" / "unknown" and by: "parent_tap" / "parent_override" in the report when the adult judged a spoken answer (fact does); the shell keeps them. Throw when v.problem is set
style.cssoptional; bundled as SLK.components.<name>.css. Prefix every rule with your own classes (.c-<name>, .xx-…). Mark a part that must stay with the one before it on paper with break-before: avoid
slide.jsslide.render(v, ctx, t) (HTML for a 1280 × 720 stage, revealed step by step in teaching order as t goes 0 → 1, answer shown at 1 with nothing left hidden or moving; pure function of t; escape everything; dir/lang on the root) and slide.css. Helpers: SLK.film.steps/phase/ease/enter/size/pick. Every component has one (tests/film_slides.test.mjs fails without it; the film would fall back to the paper view, scaled). Colours: plain ones inside .sl-card (a card stays light in every look), var(--fs-accent), var(--fs-muted) or currentColor on the board, so a dark look (chalkboard) keeps them readable. Models: classify/slide.js, a generator's column_arithmetic/slide.js
summary.jsoptional summary.render(item, ctx) -> {html, caption?, size?, cls?, speech?, place?, media?} or null: the item's REVISION view in the lesson summary (the answer shown, compact, A4 and 360 px, no interaction, escaped). Optional always/max (shown outside the skill's budget), spare (only a place the other views left) and top(d, ctx) (with "summary_top": true: a block under the title). summary.css: its styles (prefixed classes; var(--c) / var(--cs) = the skill's colours). Contract: docs/ARCHITECTURE.md §4; models: sequence/summary.js, classify/summary.js, match/summary.js. Without it, the item does not appear in the summary
draw.jsoptional, any name: shared drawing code the other files call (slk.py component new puts the ONE drawing there, reused by paper, play, slide and summary). Every *.js of the folder is bundled: sample, paper, play, slide first, then the rest by name
display-only"answer": "none", "marking": "none": an item to READ (a callout, a diagram), never answered, scored, scheduled or printed on a sheet; still ships paper.js (the box; key = ""), play.js (the card; no report needed), slide.js, summary.js
golden/<case>.json{about, seed, lang, dir, digits, item}, plus "refused": true for a broken item the app must reject (its views still print it, with a note in the key); the tests keep <case>.paper.html, .key.html, .variant.json, and .summary.html with a summary.js ("" = no view)

Classic scripts

Every JS file is a classic script: (function (root) { var SLK = root.SLK = root.SLK || {}; … })(typeof globalThis !== "undefined" ? globalThis : this); and adds to SLK.components.<name> (create it if missing). No import, no fetch, nothing global besides that.

Rules the tests check

  • Escape every lesson text. In strings use SLK.kit.show(text, ctx) (escape + the lesson's digits) or SLK.kit.esc(text). In play.js set text with textContent (use SLK.kit.digits(text, ctx)), never innerHTML.
  • paper.render gives only the child's part: no item number, points or tick boxes (the paper shell adds them).
  • play.mount must work at 360 px, with touch and mouse, in RTL and LTR. Use buttons (44 px+), ctx.dir. It shows its own check button; the shell shows "Next", records the first report and the help used.
  • ctx = {lang, dir, digits, g, number, points, t(key, vars), assetUrl}. Shared words: ctx.t("check"). Words only your component needs live in your files, in ar / fr / en, first person for the child (أَلْمِسُ…, Je classe…). ctx.assetUrl(path) gives a picture's address or null (then show the text instead). The shells draw the item's own media picture above it: do not draw item.media yourself.
  • Checks across fields that the schema cannot say go in component.json "checks", run by both loaders (the app and slk.py check): {"rule": "one_of", "field": "answer", "in": "options", "key": "text"} (every answer text is one of the options, forgiving vowel marks, accents, case and punctuation) and {"rule": "has_blank", "field": "text"} (the text holds a {blank}) and {"rule": "item_ref", "field": "from", "types": [...]} (the id of another item of the lesson, of one of these types); an optional "fix" replaces the message. Finer problems (an answer that fits two options) come from sample.js problem: the app's loader and slk.py check (through Node) both see them.
  • The hostile-text test replaces every text and every key of nested objects with an <img onerror> string (the same text always gets the same string, and a text with a {blank} keeps one). So keys inside nested objects cannot be fixed words (use a keyed object, like passage questions, or plain lists, like truefalse), and a text field needs maxLength ≥ 40.
  • The card: ≤ 11 lines (the generated header and example make it ≤ 15). Line 1 = one-line purpose. Say every field, the limits, and the common mistakes. A cheap model given only the card must write a valid item.
  • No internal words on screen (component, variant, support, evidence, barrier, JSON…).

Commands

Then run, from the kit folder:

python3 slk.py component new <name> [--display]   # a new working folder, bundled, goldens written
python3 slk.py bundle                 # regenerate app/components.js (never edit it by hand)
python3 slk.py card <name>            # read your card as a model will
SLK_UPDATE_GOLDEN=<name> node tests/run.mjs   # write only your goldens (or =1 for all), then read them
node tests/run.mjs && python3 -m unittest discover tests

Builders working in a scratch copy can use python3 slk.py bundle --out PATH and --components DIR.