SPB Git

Repository Public

renderer.fixture.ts 9.5 KB 107 lines typescript

1import { mustParseSheet, type Sheet, type SheetInput } from "@/schema";23type BlockInput = SheetInput["blocks"][number];45export const DIAGRAM: BlockInput = {6  id: "dg", type: "diagram", kind: "architecture", direction: "LR", routing: "orthogonal", title: "Pipeline", caption: "Flux de **données**", alt: "Schéma du pipeline",7  nodes: [8    { id: "in", label: "Entrée", shape: "pill", tone: "blue", icon: "document" },9    { id: "router", label: "Routeur", sublabel: "choisit k experts", shape: "diamond", tone: "amber", group: "core" },10    { id: "e1", label: "Expert 1", shape: "round", tone: "teal", group: "core", icon: "brain" },11    { id: "e2", label: "Expert 2", shape: "hexagon", tone: "teal", group: "core" },12    { id: "db", label: "Cache", shape: "cylinder", tone: "violet", icon: "database" },13    { id: "sum", label: "Σ", shape: "circle", tone: "green" },14    { id: "note", label: "Note de conception assez longue pour être coupée", shape: "note", tone: "neutral" },15    { id: "out", label: "Sortie", shape: "rect", tone: "blue" },16  ],17  edges: [18    { id: "a", from: "in", to: "router", label: "jetons" }, { id: "b", from: "router", to: "e1", style: "dashed" }, { id: "c", from: "router", to: "e2", style: "dotted", tone: "amber" },19    { id: "d", from: "e1", to: "sum" }, { id: "e", from: "e2", to: "sum" }, { id: "f", from: "sum", to: "out", arrow: "both" }, { id: "g", from: "db", to: "e1", arrow: "none", fromPort: "top", toPort: "bottom" },20    { id: "h", from: "note", to: "note" }, { id: "i", from: "in", to: "out", label: "raccourci" },21  ],22  groups: [{ id: "core", label: "Cœur", tone: "teal" }],23  legend: [{ label: "Flux principal", tone: "neutral", shape: "arrow" }, { label: "Optionnel", tone: "amber", shape: "dashed" }],24  animation: { steps: [{ title: "Lecture", text: "Les jetons *entrent*.", nodes: ["in"], edges: ["a"] }, { title: "Routage", nodes: ["router", "e1"], edges: ["b"] }, { title: "Somme", nodes: ["sum", "out"], edges: ["d", "e", "f"] }] },25};2627export const CHART: BlockInput = {28  id: "ch", type: "chart", kind: "line", title: "Perte", caption: "Courbe d'apprentissage", dataKind: "synthetic", alt: "Perte par époque", sourceIds: ["s1"],29  x: { label: "Époque", type: "number" }, y: { label: "Perte", unit: "nats" },30  series: [31    { name: "Entraînement", tone: "blue", points: [{ x: 0, y: 2.3, lo: 2.1, hi: 2.5 }, { x: 1, y: 1.4, lo: 1.2, hi: 1.6 }, { x: 2, y: 0.9, lo: 0.8, hi: 1.0 }, { x: 3, y: 0.7, lo: 0.6, hi: 0.8 }] },32    { name: "Validation", tone: "red", points: [{ x: 0, y: 2.4 }, { x: 1, y: 1.6 }, { x: 2, y: 1.2 }, { x: 3, y: 1.15 }] },33  ],34  annotations: [{ x: 2, y: 1.2, label: "Début du surapprentissage" }, { x: 1, label: "Changement de pas" }, { y: 1, label: "Seuil" }, { label: "Note libre" }],35};3637export const MATRIX: BlockInput = {38  id: "mx", type: "matrix", title: "Corrélations", caption: "Matrice", dataKind: "illustrative", scale: "diverging", decimals: 2, alt: "Matrice de corrélation",39  rowLabels: ["A", "B", "C"], colLabels: ["A", "B", "Très long libellé"], values: [[1, 0.4, -0.7], [0.4, 1, 0.1], [-0.7, 0.1, 1]],40};4142export const SVG_BLOCK: BlockInput = {43  id: "sv", type: "svg", caption: "Illustration", alt: "Un cercle",44  tree: { tag: "svg", attrs: { viewBox: "0 0 100 60" }, children: [45    { tag: "defs", attrs: {}, children: [{ tag: "linearGradient", attrs: { id: "g1" }, children: [{ tag: "stop", attrs: { offset: "0", "stop-color": "#1d4ed8" }, children: [] }, { tag: "stop", attrs: { offset: "1", "stop-color": "#0f766e" }, children: [] }] }] },46    { tag: "circle", attrs: { cx: "50", cy: "30", r: "20", fill: "url(#g1)", "stroke-width": "2", style: "stroke: #000; position: fixed" }, children: [] },47    { tag: "text", attrs: { x: "50", y: "55", "text-anchor": "middle", "font-size": "8" }, children: ["Légende <b>"] },48  ] },49};5051export const TIMELINE: BlockInput = {52  id: "tl", type: "timeline", orientation: "horizontal",53  items: [{ when: "1986", title: "ARCH → GARCH", text: "Bollerslev généralise le modèle.", tone: "blue" }, { when: "2017", title: "Transformers", tone: "violet" }, { when: "2024", title: "MoE à grande échelle", text: "Routage épars.", tone: "teal" }],54};5556const leaf: BlockInput[] = [57  { id: "h1", type: "heading", level: 1, text: "Mélange d'experts", eyebrow: "Architecture" },58  { id: "p1", type: "paragraph", lead: true, text: "Un **routeur** choisit $k$ experts[^s1]. Voir [la doc](https://example.org/doc) et `top_k`." },59  { id: "h2", type: "heading", level: 2, text: "Principe" },60  { id: "l1", type: "list", style: "check", span: 6, items: ["Premier *point*", "Second point"] },61  { id: "l2", type: "list", style: "number", span: 6, items: ["Un", "Deux"] },62  { id: "eq", type: "equation", latex: "y = \\sum_{i=1}^{k} g_i(x)\\, f_i(x)", label: "(1)", explanation: "Somme pondérée.", derivation: "derived", variables: [{ symbol: "g_i", meaning: "poids du routeur", unit: "—" }, { symbol: "f_i", meaning: "sortie de l'expert $i$" }] },63  { id: "co", type: "callout", tone: "warning", title: "Attention", text: "Le routage est **discret**.\n\nSecond paragraphe." },64  { id: "tb", type: "table", caption: "Comparatif", headerColumn: true, columns: [{ label: "Modèle" }, { label: "Paramètres", align: "right" }], rows: [["A", "7 G"], ["B", "47 G"]] },65  { id: "ca", type: "cards", columns: 3, items: [{ title: "Routeur", text: "Choisit.", icon: "route", tone: "blue", badge: "clé" }, { title: "Expert", text: "Calcule.", tone: "teal" }, { title: "Somme", text: "", icon: "sigma", tone: "green" }] },66  { id: "st", type: "steps", items: [{ title: "Encoder", text: "Jetons → vecteurs." }, { title: "Router", text: "Top-k.", icon: "split" }] },67  { id: "lg", type: "legend", title: "Légende", items: [{ label: "Flux", tone: "blue", shape: "arrow" }, { label: "Bloc", tone: "teal", shape: "square" }, { label: "Nœud", tone: "red", shape: "circle" }, { label: "Lien", tone: "amber", shape: "line" }, { label: "Option", tone: "pink", shape: "dashed" }] },68  DIAGRAM, TIMELINE, MATRIX,69  { id: "cd", type: "code", language: "python", caption: "Routage top-k", code: "# top-k\ndef route(x, k=2):\n    scores = gate(x)  # logits\n    return scores.topk(k), \"ok\"\n" },70  CHART,71  { id: "ch2", type: "chart", kind: "bar", dataKind: "empirical", x: { label: "Modèle", type: "category" }, y: { label: "Score", scale: "linear", min: 0 }, series: [{ name: "v1", tone: "teal", points: [{ x: "A", y: 3, lo: 2, hi: 4 }, { x: "B", y: 5 }] }], span: 6 },72  { id: "ch3", type: "chart", kind: "histogram", dataKind: "synthetic", x: { label: "Rendement", unit: "%" }, y: { label: "Fréquence" }, series: [{ name: "n", points: [{ x: -1, y: 2 }, { x: 0, y: 9 }, { x: 1, y: 4 }] }], span: 6 },73  { id: "ch4", type: "chart", kind: "scatter", dataKind: "illustrative", x: { label: "x", scale: "log" }, y: { label: "y", scale: "log" }, series: [{ name: "a", tone: "violet", points: [{ x: 1, y: 10 }, { x: 10, y: 100, lo: 50, hi: 200 }, { x: 0, y: 5 }] }, { name: "b", tone: "amber", points: [{ x: 100, y: 1000 }] }], span: 6 },74  { id: "ch5", type: "chart", kind: "area", dataKind: "illustrative", x: { label: "Mois", type: "category" }, y: { label: "Volume" }, series: [{ name: "v", tone: "green", points: [{ x: "jan", y: 1 }, { x: "fév", y: -2 }, { x: "mar", y: 3 }] }], span: 6 },75  SVG_BLOCK,76  { id: "im", type: "image", assetRef: "fig1", caption: "Une figure" },77  { id: "cp", type: "comparison", caption: "Dense ou épars", columns: [{ title: "Dense", tone: "neutral" }, { title: "MoE", tone: "blue", badge: "épars" }], rows: [{ label: "Coût", cells: ["$O(n)$", "$O(k)$"] }, { label: "Mémoire", cells: ["faible", "élevée"] }], verdict: "Le MoE gagne en calcul." },78  { id: "ac", type: "accordion", items: [{ title: "Pourquoi ?", text: "Parce que.\n\nEt aussi." }, { title: "Comment ?", text: "Ainsi." }] },79  { id: "qz", type: "quiz", question: "Combien d'experts sont actifs ?", choices: [{ text: "Tous", correct: false, explanation: "Non : seulement $k$." }, { text: "$k$", correct: true }] },80  { id: "sm", type: "simulation", kind: "moe-routing", title: "Routage", params: { k: 2 } },81  { id: "dv", type: "divider" },82];8384/** A document that contains every block type (tabs included). */85export function fullDocument(overrides: Partial<SheetInput> = {}): Sheet {86  return mustParseSheet({87    schemaVersion: 1,88    metadata: { title: "Mélange d'experts", locale: "fr", example: true },89    theme: { preset: "scientific-light", accent: "blue" },90    blocks: [91      ...leaf,92      { id: "tabs", type: "tabs", tabs: [93        { id: "t1", label: "Idée", blocks: [{ id: "tp", type: "paragraph", text: "Contenu du premier onglet." }, { id: "th", type: "heading", level: 1, text: "Titre dans un onglet" }] },94        { id: "t2", label: "Détails", blocks: [{ id: "tq", type: "quiz", question: "Vrai ?", choices: [{ text: "Oui", correct: true }, { text: "Non", correct: false }] }, { ...DIAGRAM, id: "dg2" } as BlockInput & { type: "diagram" }] },95      ] } as BlockInput,96      { id: "rf", type: "references", title: "Sources" },97    ],98    sources: [99      { id: "s1", type: "article", title: "Adaptive Mixtures of Local Experts", authors: ["R. Jacobs", "M. Jordan"], year: 1991, container: "Neural Computation", doi: "10.1162/neco.1991.3.1.79", status: "resolved" },100      { id: "s2", type: "web", title: "Une page", url: "https://example.org/page", status: "unverified" },101      { id: "s3", type: "report", title: "Rapport", status: "unreachable", note: "À revoir." },102    ],103    assets: [{ id: "fig1", kind: "image", assetId: "3f2b8c1e-4d5a-4e6f-8a9b-0c1d2e3f4a5b", alt: "Schéma d'une figure", credit: "S.-P. Boucher" }],104    ...overrides,105  });106}107
Files main
Menu

Theme