@mechane-ai/elements 0.47.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +288 -5
  2. package/bin/mechane-elements-catalog.mjs +104 -12
  3. package/dist/article-BXZr10QQ.js +1904 -0
  4. package/dist/article.js +1 -0
  5. package/dist/catalog.json +1389 -75
  6. package/dist/{categorical-values-DdfGIowV.js → categorical-values-BpVq8cFj.js} +1 -1
  7. package/dist/{cells--Bd1fQFR.js → cells-xVmnQ9oQ.js} +1 -1
  8. package/dist/charts/cartesian.js +1 -1
  9. package/dist/charts/cells.js +1 -1
  10. package/dist/charts/comparison.js +1 -1
  11. package/dist/charts/distribution.js +1 -1
  12. package/dist/charts/figure.js +12 -12
  13. package/dist/charts/graph.js +1 -1
  14. package/dist/charts/hierarchy.js +1 -1
  15. package/dist/charts/image.js +1 -1
  16. package/dist/charts/matrix.js +3 -2
  17. package/dist/charts/plot.js +4 -4
  18. package/dist/charts/relationship.js +1 -1
  19. package/dist/charts/text.js +1 -1
  20. package/dist/charts/timeline.js +1 -1
  21. package/dist/charts/trend.js +1 -1
  22. package/dist/charts.js +2 -2
  23. package/dist/clock-DSm5lkNE.js +16 -0
  24. package/dist/collections.js +1 -1
  25. package/dist/describe-lesson-BmREzDpt.js +175 -0
  26. package/dist/{dumbbell-plot-B2ZTgQaI.js → dumbbell-plot-DQdTxDeO.js} +6 -5
  27. package/dist/{embedding-map-CGM_k6lC.js → embedding-map-CF-J-8JW.js} +5 -5
  28. package/dist/{figure-frame-wRkIEAwe.js → figure-frame-BJ3REgTA.js} +1 -1
  29. package/dist/forms.js +1 -1
  30. package/dist/{image-grid-CVA4SOy_.js → image-grid-Dl2sjIMB.js} +3 -3
  31. package/dist/kits/evaluation.js +5 -5
  32. package/dist/kits/interpretability.js +9 -9
  33. package/dist/kits/operations.js +4 -4
  34. package/dist/kits/training.js +4 -4
  35. package/dist/lesson/agent.js +811 -0
  36. package/dist/lesson/spec.js +661 -0
  37. package/dist/lesson.js +5 -0
  38. package/dist/mdx.js +227 -0
  39. package/dist/packages/charts/src/matrix/index.d.ts +1 -0
  40. package/dist/packages/charts/src/plot/plot-marks.d.ts +7 -3
  41. package/dist/packages/teaching/src/agent/index.d.ts +11 -0
  42. package/dist/packages/teaching/src/agent/learner-trace.d.ts +84 -0
  43. package/dist/packages/teaching/src/agent/lesson-bridge.d.ts +59 -0
  44. package/dist/packages/teaching/src/agent/lesson-tour.d.ts +63 -0
  45. package/dist/packages/teaching/src/agent/tutor-tools.d.ts +86 -0
  46. package/dist/packages/teaching/src/article/article-checks.d.ts +9 -0
  47. package/dist/packages/teaching/src/article/article-context.d.ts +49 -0
  48. package/dist/packages/teaching/src/article/article-error.d.ts +12 -0
  49. package/dist/packages/teaching/src/article/article-labels.d.ts +54 -0
  50. package/dist/packages/teaching/src/article/article-layout.stylex.d.ts +14 -0
  51. package/dist/packages/teaching/src/article/article-outline.d.ts +9 -0
  52. package/dist/packages/teaching/src/article/article.d.ts +42 -0
  53. package/dist/packages/teaching/src/article/beat-steps.d.ts +18 -0
  54. package/dist/packages/teaching/src/article/beat.d.ts +16 -0
  55. package/dist/packages/teaching/src/article/challenge.d.ts +29 -0
  56. package/dist/packages/teaching/src/article/exercise-styles.d.ts +76 -0
  57. package/dist/packages/teaching/src/article/figure.d.ts +51 -0
  58. package/dist/packages/teaching/src/article/index.d.ts +31 -0
  59. package/dist/packages/teaching/src/article/lesson-values.d.ts +5 -0
  60. package/dist/packages/teaching/src/article/notes.d.ts +36 -0
  61. package/dist/packages/teaching/src/article/outline-types.d.ts +73 -0
  62. package/dist/packages/teaching/src/article/predict.d.ts +58 -0
  63. package/dist/packages/teaching/src/article/progress-store.d.ts +64 -0
  64. package/dist/packages/teaching/src/article/scrolly.d.ts +26 -0
  65. package/dist/packages/{kits/src/explainers → teaching/src/article}/term.d.ts +8 -2
  66. package/dist/packages/teaching/src/article/tex.d.ts +12 -0
  67. package/dist/packages/teaching/src/article/view-essay.d.ts +13 -0
  68. package/dist/packages/teaching/src/article/view-present.d.ts +8 -0
  69. package/dist/packages/teaching/src/article/view-sheet.d.ts +7 -0
  70. package/dist/packages/teaching/src/article/view-static.d.ts +7 -0
  71. package/dist/packages/teaching/src/article/walk.d.ts +34 -0
  72. package/dist/packages/teaching/src/lesson/define-lesson.d.ts +136 -0
  73. package/dist/packages/teaching/src/lesson/index.d.ts +24 -0
  74. package/dist/packages/teaching/src/lesson/inline-choice.d.ts +12 -0
  75. package/dist/packages/teaching/src/lesson/lesson-context.d.ts +18 -0
  76. package/dist/packages/teaching/src/lesson/lesson-error.d.ts +12 -0
  77. package/dist/packages/teaching/src/lesson/lesson-locale.d.ts +4 -0
  78. package/dist/packages/teaching/src/lesson/lesson-persistence.d.ts +17 -0
  79. package/dist/packages/teaching/src/lesson/lesson-player.d.ts +51 -0
  80. package/dist/packages/teaching/src/lesson/lesson-store.d.ts +84 -0
  81. package/dist/packages/teaching/src/lesson/lesson.d.ts +39 -0
  82. package/dist/packages/teaching/src/lesson/param-controls.d.ts +14 -0
  83. package/dist/packages/teaching/src/lesson/param.d.ts +34 -0
  84. package/dist/packages/teaching/src/lesson/playback.d.ts +42 -0
  85. package/dist/packages/teaching/src/lesson/transport.d.ts +19 -0
  86. package/dist/packages/teaching/src/lesson/use-lesson.d.ts +36 -0
  87. package/dist/packages/teaching/src/mdx/essay-components.d.ts +79 -0
  88. package/dist/packages/teaching/src/mdx/essay-markdown.d.ts +41 -0
  89. package/dist/packages/teaching/src/mdx/essay.d.ts +32 -0
  90. package/dist/packages/teaching/src/mdx/index.d.ts +9 -0
  91. package/dist/packages/teaching/src/mdx/requested-view.d.ts +6 -0
  92. package/dist/packages/teaching/src/scene/flow/flow-layout.d.ts +38 -0
  93. package/dist/packages/teaching/src/scene/flow/flow-pulse.d.ts +16 -0
  94. package/dist/packages/teaching/src/scene/flow/scene-flow.d.ts +81 -0
  95. package/dist/packages/teaching/src/scene/index.d.ts +77 -0
  96. package/dist/packages/teaching/src/scene/morph/morph-scope.d.ts +28 -0
  97. package/dist/packages/teaching/src/scene/plane/plane-hit.d.ts +22 -0
  98. package/dist/packages/teaching/src/scene/plane/plane-label.d.ts +23 -0
  99. package/dist/packages/teaching/src/scene/plane/plane-labels.d.ts +42 -0
  100. package/dist/packages/teaching/src/scene/plane/plane-math.d.ts +45 -0
  101. package/dist/packages/teaching/src/scene/plane/scene-axes.d.ts +30 -0
  102. package/dist/packages/teaching/src/scene/plane/scene-curve.d.ts +42 -0
  103. package/dist/packages/teaching/src/scene/plane/scene-point.d.ts +59 -0
  104. package/dist/packages/teaching/src/scene/plane/scene-projection.d.ts +27 -0
  105. package/dist/packages/teaching/src/scene/plane/scene-region.d.ts +38 -0
  106. package/dist/packages/teaching/src/scene/plane/scene-rule.d.ts +35 -0
  107. package/dist/packages/teaching/src/scene/plane/scene-vector.d.ts +39 -0
  108. package/dist/packages/teaching/src/scene/scene-bracket.d.ts +24 -0
  109. package/dist/packages/teaching/src/scene/scene-callout.d.ts +26 -0
  110. package/dist/packages/teaching/src/scene/scene-context.d.ts +179 -0
  111. package/dist/packages/teaching/src/scene/scene-custom.d.ts +31 -0
  112. package/dist/packages/teaching/src/scene/scene-geometry.d.ts +181 -0
  113. package/dist/packages/teaching/src/scene/scene-group.d.ts +28 -0
  114. package/dist/packages/teaching/src/scene/scene-highlight.d.ts +19 -0
  115. package/dist/packages/teaching/src/scene/scene-layer.d.ts +16 -0
  116. package/dist/packages/teaching/src/scene/scene-node.d.ts +67 -0
  117. package/dist/packages/teaching/src/scene/scene-obstacles.d.ts +27 -0
  118. package/dist/packages/teaching/src/scene/scene-registry.d.ts +79 -0
  119. package/dist/packages/teaching/src/scene/scene-stagger.d.ts +43 -0
  120. package/dist/packages/teaching/src/scene/scene-style.d.ts +14 -0
  121. package/dist/packages/teaching/src/scene/scene-validate.d.ts +65 -0
  122. package/dist/packages/teaching/src/scene/scene-wire.d.ts +45 -0
  123. package/dist/packages/teaching/src/scene/scene.d.ts +36 -0
  124. package/dist/packages/teaching/src/scene/shapes/cell-color.d.ts +11 -0
  125. package/dist/packages/teaching/src/scene/shapes/cell-grid.d.ts +69 -0
  126. package/dist/packages/teaching/src/scene/shapes/scene-card.d.ts +114 -0
  127. package/dist/packages/teaching/src/scene/shapes/scene-cells.d.ts +84 -0
  128. package/dist/packages/teaching/src/scene/shapes/scene-slot.d.ts +37 -0
  129. package/dist/packages/teaching/src/scene/shapes/scene-stack.d.ts +46 -0
  130. package/dist/packages/teaching/src/scene/shapes/scene-token.d.ts +63 -0
  131. package/dist/packages/teaching/src/scene/shapes/scene-tokens.d.ts +40 -0
  132. package/dist/packages/teaching/src/scene/shapes/stack-book.d.ts +35 -0
  133. package/dist/packages/teaching/src/scene/shapes/stack-layout.d.ts +63 -0
  134. package/dist/packages/teaching/src/scene/shapes/token-layout.d.ts +39 -0
  135. package/dist/packages/teaching/src/spec/advice.d.ts +23 -0
  136. package/dist/packages/teaching/src/spec/chart-names.d.ts +2 -0
  137. package/dist/packages/teaching/src/spec/describe-lesson.d.ts +85 -0
  138. package/dist/packages/teaching/src/spec/explainer-guide.d.ts +21 -0
  139. package/dist/packages/teaching/src/spec/findings.d.ts +39 -0
  140. package/dist/packages/teaching/src/spec/index.d.ts +14 -0
  141. package/dist/packages/teaching/src/spec/lesson-plan.d.ts +43 -0
  142. package/dist/packages/teaching/src/spec/validate-plan.d.ts +11 -0
  143. package/dist/packages/teaching/src/time/clock.d.ts +7 -0
  144. package/dist/packages/teaching/src/time/tween.d.ts +19 -0
  145. package/dist/packages/teaching/src/time/use-tween.d.ts +6 -0
  146. package/dist/param-CqKUTHaO.js +450 -0
  147. package/dist/{plot-layout-BEuoOHbs.js → plot-layout-CZVSJ-le.js} +2 -1
  148. package/dist/{plot-marks-A64v7aTw.js → plot-marks-uozcbOIX.js} +15 -12
  149. package/dist/{plot-surface-CJTIqtck.js → plot-surface-CbVBvgqZ.js} +1 -1
  150. package/dist/{reference-lines-CWA8VeUR.js → reference-lines-BDcttOp0.js} +2 -2
  151. package/dist/scene-0z2gbaDE.js +4938 -0
  152. package/dist/scene.js +1 -0
  153. package/dist/{slope-chart-DT22h_ym.js → slope-chart-BKVEAVCs.js} +5 -5
  154. package/dist/{src-1EHkSFS-.js → src-BD6xlvDt.js} +2 -2
  155. package/dist/{src-D5NXRJZe.js → src-Dcfq8vE4.js} +1 -1
  156. package/dist/styles2.css +475 -18
  157. package/dist/{time-series-IB3CB93O.js → time-series-BgzGNOk0.js} +12 -10
  158. package/dist/{token-heatmap-C00DnoNO.js → token-heatmap-BrW1OsKD.js} +2 -2
  159. package/dist/{token-predictions-Cxx29iDr.js → token-predictions-yerq_Oet.js} +4 -4
  160. package/dist/transport-BJweqDPj.js +715 -0
  161. package/dist/{tree-diagram-DsckNKaW.js → tree-diagram-D09BRqE-.js} +4 -4
  162. package/dist/{treemap-9_DpLCW9.js → treemap-CW4WsJNL.js} +4 -4
  163. package/dist/use-tween-5HZ55_9d.js +72 -0
  164. package/dist/{violin-plot-BhPHKXsN.js → violin-plot-DrtPZ1-T.js} +5 -4
  165. package/dist/{waterfall-CGksuTy5.js → waterfall-DYLSnGjm.js} +4 -4
  166. package/package.json +26 -5
  167. package/recipes/counting-cards.tsx +656 -0
  168. package/recipes/explorable-essay.tsx +172 -0
  169. package/skills/extend-elements/SKILL.md +21 -0
  170. package/skills/plan-lesson/SKILL.md +86 -0
  171. package/skills/plan-lesson/references/plan-format.md +114 -0
  172. package/skills/plan-lesson/references/worked-plan.md +171 -0
  173. package/skills/review-elements/SKILL.md +4 -2
  174. package/skills/review-explainer/SKILL.md +97 -0
  175. package/skills/upgrade-elements/references/releases.md +65 -0
  176. package/skills/use-elements/SKILL.md +18 -16
  177. package/skills/use-elements/references/kits.md +2 -20
  178. package/skills/use-elements/references/teaching.md +36 -0
  179. package/skills/write-explainer/SKILL.md +112 -0
  180. package/skills/write-explainer/references/article.md +164 -0
  181. package/skills/write-explainer/references/lesson.md +148 -0
  182. package/skills/write-explainer/references/mdx.md +78 -0
  183. package/skills/write-explainer/references/scene-parts.md +273 -0
  184. package/skills/write-explainer/references/scene.md +168 -0
  185. package/skills/write-explainer/references/tutor.md +104 -0
  186. package/skills/write-explainer/references/worked-essay.md +459 -0
  187. package/templates/essay/AGENTS.md +14 -0
  188. package/templates/essay/README.md +59 -0
  189. package/templates/essay/index.html +17 -0
  190. package/templates/essay/package.template.json +21 -0
  191. package/templates/essay/plan.json +96 -0
  192. package/templates/essay/src/essay.mdx +97 -0
  193. package/templates/essay/src/figures.tsx +92 -0
  194. package/templates/essay/src/lesson.ts +83 -0
  195. package/templates/essay/src/main.tsx +53 -0
  196. package/templates/essay/src/mdx.d.ts +7 -0
  197. package/templates/essay/tsconfig.template.json +15 -0
  198. package/templates/essay/vite.config.template.txt +8 -0
  199. package/dist/kits/explainers.js +0 -452
  200. package/dist/packages/kits/src/explainers/figures.d.ts +0 -31
  201. package/dist/packages/kits/src/explainers/index.d.ts +0 -8
  202. package/dist/packages/kits/src/explainers/story-steps.d.ts +0 -46
  203. /package/dist/packages/{kits/src/explainers → teaching/src/article}/linked-target.d.ts +0 -0
  204. /package/dist/packages/{kits/src/explainers → teaching/src/lesson}/bound-value.d.ts +0 -0
@@ -0,0 +1,661 @@
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "../describe-lesson-BmREzDpt.js";
2
+ // packages/teaching/src/spec/advice.ts
3
+ var l = 7, u = /\b(recap|summary|review|so far|together)\b/iu;
4
+ function d(e, t) {
5
+ return new Set(e.states.flatMap((e) => Object.entries(e).flatMap(([e, n]) => Object.hasOwn(t, e) && t[e] !== n ? [e] : [])));
6
+ }
7
+ function f(e) {
8
+ return e.flatMap((e, t) => e.hasGoal ? [] : [n(`beats[${t}].goal`, `Beat "${e.id}" has no goal. Add one sentence the reader should be able to say after it.`)]);
9
+ }
10
+ function p({ defaults: e, beats: t }) {
11
+ let r = t.map((t) => d(t, e));
12
+ return t.flatMap((e, t) => {
13
+ let i = new Set(r.slice(0, t).flatMap((e) => [...e])), a = [...r[t] ?? []].filter((e) => !i.has(e));
14
+ return a.length > 1 ? [n(`beats[${t}].states`, `Beat "${e.id}" introduces ${a.length} new params (${a.join(", ")}). Introduce one per beat, so the reader can tell what each one does.`)] : [];
15
+ });
16
+ }
17
+ function m({ defaults: e, beats: t }) {
18
+ let r = new Set(t.flatMap((t) => [...d(t, e)]));
19
+ return Object.keys(e).filter((e) => !r.has(e)).map((e) => n(`params.${e}`, `No beat state changes "${e}". Add a state that moves it, so a beat sheet and a tutor can show what it does.`));
20
+ }
21
+ function h(e) {
22
+ let t = [
23
+ -1,
24
+ ...e.flatMap((e, t) => u.test(e.title) ? [t] : []),
25
+ e.length
26
+ ];
27
+ return t.slice(1).flatMap((e, r) => {
28
+ let i = (t[r] ?? -1) + 1;
29
+ return e - i > l ? [n(`beats[${i}]`, `Beats ${i + 1} to ${e} run ${e - i} beats with no recap. Add a beat titled "Recap" that restates the idea so far.`)] : [];
30
+ });
31
+ }
32
+ function g(e) {
33
+ return [
34
+ ...f(e.beats),
35
+ ...p(e),
36
+ ...m(e),
37
+ ...h(e.beats)
38
+ ];
39
+ }
40
+ function _(e) {
41
+ return g({
42
+ defaults: e.defaults,
43
+ beats: e.beats.map((e) => ({
44
+ id: e.id,
45
+ title: e.title,
46
+ hasGoal: (e.goal ?? "").trim().length > 0,
47
+ states: (e.states ?? []).map((e) => e.values)
48
+ }))
49
+ });
50
+ }
51
+ // packages/teaching/src/spec/explainer-guide.ts
52
+ var v = /* @__PURE__ */ "Lesson.Param.Value.ParamSlider.ParamChoice.ParamToggle.Playback.Transport.Scene.SceneNode.SceneWire.SceneGroup.SceneBracket.SceneCallout.SceneHighlight.SceneCustom.SceneAxes.SceneCurve.ScenePoint.SceneVector.SceneProjection.SceneRegion.SceneRule.SceneCard.SceneStack.SceneSlot.SceneCells.SceneToken.SceneTokens.SceneFlow.LessonFlow.MorphScope.Article.Beat.Figure.FigureReference.Reveal.Scrolly.Predict.Challenge.Aside.Footnote.Cite.References.TeX.Term.DiagramPart".split("."), y = "@mechane-ai/elements/lesson", b = "@mechane-ai/elements/scene", x = "@mechane-ai/elements/article", S = {
53
+ Lesson: {
54
+ entry: y,
55
+ question: "Which values does this explainer let me change, and do the words and pictures agree on them?",
56
+ guidance: "Wrap every explainer in one Lesson, declared once with defineLesson; an Article renders it for you. Set shouldSyncUrl to keep the values in the address bar. Use a second Lesson only for an independent copy.",
57
+ example: "const lesson = defineLesson({\n id: 'softmax',\n title: 'How temperature reshapes a softmax',\n params: { temperature: { kind: 'number', label: 'Temperature', value: 1, min: 0.1, max: 10, step: 0.01, scale: 'log', format: { maximumFractionDigits: 2 } } },\n derived: { entropy: { label: 'Entropy', format: { style: 'unit', unit: 'bit', maximumFractionDigits: 2 }, from: ({ temperature }) => entropyOf(temperature) } },\n beats: [{ id: 'scores', title: 'Scores become probabilities', goal: 'Dividing by a temperature flattens or sharpens the distribution.' }],\n});\n\n<Lesson lesson={lesson} locale=\"en-US\" shouldSyncUrl>…</Lesson>"
58
+ },
59
+ Param: {
60
+ entry: y,
61
+ question: "What happens if I change this number in the sentence?",
62
+ guidance: "Use it inside prose, where the reader meets a value: a number drags, a choice opens a picker, a toggle switches. Use ParamSlider for a labelled control under a figure.",
63
+ example: "<p>\n Divide every score by a temperature of <Param name=\"temperature\" /> before the softmax.\n</p>"
64
+ },
65
+ Value: {
66
+ entry: y,
67
+ question: "What is the result right now?",
68
+ guidance: "Use it to write a param or a derived value in prose, in its declared format, so the sentence follows every change. Use Param instead when the reader should change the value there.",
69
+ example: "<p>\n The followed token now gets <Value name=\"probability\" /> of the probability.\n</p>"
70
+ },
71
+ ParamSlider: {
72
+ entry: y,
73
+ question: "How does the figure change as I sweep this value?",
74
+ guidance: "Use it under a figure for a number param the reader sweeps through its range. Inside a sentence, use Param; for a time-like param the lesson plays, use Transport.",
75
+ example: "<Figure id=\"bars\" caption=\"Probabilities after the softmax.\" description=\"Four bars, one per token, that sum to one.\" reads={['temperature']}>\n <TokenBars />\n <ParamSlider name=\"temperature\" />\n</Figure>"
76
+ },
77
+ ParamChoice: {
78
+ entry: y,
79
+ question: "What if it were this option instead of that one?",
80
+ guidance: "Use it for a choice param with two to five options shown side by side. In a sentence use Param, which opens an inline picker.",
81
+ example: "<ParamChoice name=\"token\" />"
82
+ },
83
+ ParamToggle: {
84
+ entry: y,
85
+ question: "What changes when I turn this on?",
86
+ guidance: "Use it for a yes or no param under a figure, such as showing an answer or masking tokens. In a sentence use Param.",
87
+ example: "<ParamToggle name=\"isTopTwo\" />"
88
+ },
89
+ Playback: {
90
+ entry: y,
91
+ question: "How does this unfold over time?",
92
+ guidance: "Use it to drive a number param step by step, such as training steps or tokens generated. It renders nothing: pair it with a Transport so the reader can pause and scrub.",
93
+ example: "<Playback name=\"trainStep\" pace=\"regular\" />\n<Transport for=\"trainStep\" />"
94
+ },
95
+ Transport: {
96
+ entry: y,
97
+ question: "Can I pause it, step through it, or go back?",
98
+ guidance: "Use it beside every Playback. It plays, pauses, steps and scrubs the same param. Use ParamSlider when the value has no natural order in time.",
99
+ example: "<Transport for=\"trainStep\" />"
100
+ },
101
+ Scene: {
102
+ entry: b,
103
+ question: "How are these parts connected, and what moves when a value changes?",
104
+ guidance: "Use it for a diagram whose objects keep their identity across states: give each object an id and change its props. Use a chart when the picture is data on axes.",
105
+ example: "<Scene title=\"A weighted sum\" description=\"Two inputs feed one output.\" x={[0, 4]} y={[0, 2]}>\n <SceneNode id=\"a\" at={[0.5, 1.5]} label=\"Input a\" text=\"a\" />\n <SceneNode id=\"b\" at={[0.5, 0.5]} label=\"Input b\" text=\"b\" />\n <SceneNode id=\"sum\" at={[3.5, 1]} label=\"Weighted sum\" text=\"Σ\" />\n <SceneWire from=\"a\" to=\"sum\" weight={0.8} hasArrow />\n <SceneWire from=\"b\" to=\"sum\" weight={0.2} hasArrow />\n</Scene>"
106
+ },
107
+ SceneNode: {
108
+ entry: b,
109
+ question: "What is this thing, and where did it go?",
110
+ guidance: "Use it for each named thing in a scene: a token, a neuron, a card. Change at, size, tone, turn or lift and it eases there; isShown fades it.",
111
+ example: "<SceneNode id=\"queen\" at={[1, 1.5]} label=\"Queen of Hearts, weight 0.8\" text=\"Q♥\" size=\"medium\" turn={isRevealed ? 0 : 1} />"
112
+ },
113
+ SceneWire: {
114
+ entry: b,
115
+ question: "What feeds into what, and how strongly?",
116
+ guidance: "Use it between two nodes; weight sets its thickness and it stays attached while they move. Its text sits beside the stroke, above a level wire and right of an upright one; set textSide when that side collides. Use SceneFlow for a whole derivation graph.",
117
+ example: "<SceneWire from=\"queen\" to=\"sum\" label=\"Weight 0.8\" weight={0.8} text=\"0.8\" textSide=\"bottom\" hasArrow />"
118
+ },
119
+ SceneGroup: {
120
+ entry: b,
121
+ question: "Which of these belong together?",
122
+ guidance: "Use it to box several nodes as one named part, such as a layer. Use SceneBracket when the grouping is a span along one side.",
123
+ example: "<SceneGroup id=\"hidden\" label=\"Hidden layer\" around={['h1', 'h2', 'h3']} />"
124
+ },
125
+ SceneBracket: {
126
+ entry: b,
127
+ question: "What does this run of things add up to?",
128
+ guidance: "Use it to mark a span of nodes along one side with a short name, such as a context window. Use SceneGroup to enclose them.",
129
+ example: "<SceneBracket of={['t1', 't2', 't3']} side=\"bottom\" label=\"The context window, three tokens\" text=\"context\" />"
130
+ },
131
+ SceneCallout: {
132
+ entry: b,
133
+ question: "Why does this part matter?",
134
+ guidance: "Use it for one short note pointing at one object. Keep it to a sentence; longer explanation belongs in the prose beside the figure.",
135
+ example: "<SceneCallout to=\"sum\" side=\"right\">The weighted sum</SceneCallout>"
136
+ },
137
+ SceneHighlight: {
138
+ entry: b,
139
+ question: "Where should I look now?",
140
+ guidance: "Use it to draw the eye to one or a few objects for the current beat. Use the scene focus to zoom instead when the rest is noise.",
141
+ example: "<SceneHighlight of={['queen', 'sum']} />"
142
+ },
143
+ SceneCustom: {
144
+ entry: b,
145
+ question: "What does this shape look like, when no scene part draws it?",
146
+ guidance: "Use it for a drawing the scene parts lack, with the scene scales and tones it hands you. Prefer a named part when one exists, so the drawing stays inspectable.",
147
+ example: "<SceneCustom>\n {({ x, y, color, tone }) => (\n <circle cx={x.position(2)} cy={y.position(1)} r={6} fill={color(tone({ id: 'sum', index: 0 }))} />\n )}\n</SceneCustom>"
148
+ },
149
+ SceneAxes: {
150
+ entry: b,
151
+ question: "What do the positions in this picture measure?",
152
+ guidance: "Use it in a Scene whose box is a coordinate plane, for ticks, axis titles with units, and a grid that follow the camera. Leave it out of a diagram whose positions mean nothing.",
153
+ example: "<SceneAxes x={{ label: 'Input z' }} y={{ label: 'Output σ(z)', ticks: [0, 0.5, 1] }} grid=\"both\" />"
154
+ },
155
+ SceneCurve: {
156
+ entry: b,
157
+ question: "What is the shape of this function?",
158
+ guidance: "Use it in a Scene to draw a function, with of, or a path of points, in data units; it eases to a new shape. Use CurveChart for measured data with a legend and readout.",
159
+ example: "<Scene title=\"The sigmoid\" description=\"σ(z) rises from 0 to 1.\" x={[-6, 6]} y={[0, 1]}>\n <SceneAxes x={{ label: 'Input z' }} y={{ label: 'Output σ(z)' }} />\n <SceneCurve id=\"sigmoid\" of={sigmoid} resolution=\"fine\" label=\"The sigmoid, rising from 0 to 1\" />\n</Scene>"
160
+ },
161
+ ScenePoint: {
162
+ entry: b,
163
+ question: "Where is this one value on the plane, and what if I move it?",
164
+ guidance: "Use it for a single marked point. With sets, the reader drags it or moves it with the arrow keys and it writes lesson params on their step grid; at reads them back, and along keeps it on a curve. Use ScatterPlot for many records.",
165
+ example: "<ScenePoint id=\"probe\" at={[values.temperature, values.entropy]} along={entropyOf} sets={{ x: 'temperature' }} label={`Temperature ${values.temperature.toFixed(2)}`} />"
166
+ },
167
+ SceneVector: {
168
+ entry: b,
169
+ question: "Which way does this push, and how far?",
170
+ guidance: "Use it for an arrow with a direction and a length, such as a gradient step; both ends ease. Use SceneWire to connect two objects.",
171
+ example: "<SceneVector id=\"gradient\" from={[1, 1]} to={[0.6, 0.7]} text=\"step\" label=\"Gradient step\" />"
172
+ },
173
+ SceneProjection: {
174
+ entry: b,
175
+ question: "What are this point’s values on each axis?",
176
+ guidance: "Use it with SceneAxes to drop dashed lines from a ScenePoint, named by of, to both axes and write its values there. Use SceneRule for a fixed threshold.",
177
+ example: "<SceneProjection id=\"drop\" of=\"probe\" format={{ maximumFractionDigits: 2 }} />"
178
+ },
179
+ SceneRegion: {
180
+ entry: b,
181
+ question: "Which part of the plane is this?",
182
+ guidance: "Use it to shade a zone: above or below a value, between two values, or a polygon of points. Keep it pale: a region is context, not data.",
183
+ example: "<SceneRegion id=\"positive\" above={0.5} tone=\"positive\" text=\"Positive\" label=\"Classified as positive\" />"
184
+ },
185
+ SceneRule: {
186
+ entry: b,
187
+ question: "Where is the threshold?",
188
+ guidance: "Use it for one horizontal or vertical line at a value, such as a target or an asymptote, with a short text. Use SceneCurve for any other line.",
189
+ example: "<SceneRule id=\"threshold\" y={0.5} text=\"Threshold\" label=\"Threshold at 0.5\" />"
190
+ },
191
+ SceneCard: {
192
+ entry: b,
193
+ question: "What is on the other side of this, and which comes first?",
194
+ guidance: "Use it for an object that turns over, lifts or deals out, like a playing card or a hidden answer. Use SceneNode for a flat label, and SceneStack to lay several out.",
195
+ example: "<SceneCard id=\"queen\" at={[1, 1]} rank=\"Q\" suit=\"heart\" isFaceUp={isRevealed} label=\"Queen of Hearts\" />"
196
+ },
197
+ SceneStack: {
198
+ entry: b,
199
+ question: "How are these cards laid out together?",
200
+ guidance: "Use it to place SceneCards, by id, as a pile, a fan, a row or a column; change the list and the cards move. Give it a stagger to deal: cards it takes in one step set off one after another, and a card that moves alone sets off at once. Place a lone card with its own at.",
201
+ example: "<SceneStack id=\"hand\" at={[2, 1]} cards={['queen', 'seven']} layout=\"fan\" stagger=\"regular\" label=\"Your hand\" />"
202
+ },
203
+ SceneSlot: {
204
+ entry: b,
205
+ question: "Where does this go?",
206
+ guidance: "Use it for an empty place a card or token is dealt to, such as a table or an answer box; isActive marks the one that is next. Use SceneGroup to enclose objects already there.",
207
+ example: "<SceneSlot id=\"table\" at={[3, 1]} text=\"Table\" label=\"The table, where a played card lands\" isActive />"
208
+ },
209
+ SceneCells: {
210
+ entry: b,
211
+ question: "What is inside this vector or matrix, cell by cell?",
212
+ guidance: "Use it for a small grid of values that moves and changes inside a scene: a flat list is one row, a list of lists is a matrix. Use Matrix for a large grid with axes and a scale legend.",
213
+ example: "<SceneCells id=\"weights\" at={[2, 1]} values={[[0.2, -0.4, 0.1], [0.7, 0.3, -0.2]]} rowLabels={['h1', 'h2']} format={{ maximumFractionDigits: 1 }} label=\"Weight matrix\" />"
214
+ },
215
+ SceneToken: {
216
+ entry: b,
217
+ question: "Which piece of text is this, and where does it go?",
218
+ guidance: "Use it for one token that moves through a diagram with its text in monospace and, optionally, its probability. Use SceneTokens for a run of them, and TokenGrid for a long run as data.",
219
+ example: "<SceneToken id=\"t3\" at={[1, 1]} text=\" sat\" probability={0.42} label=\"Token 3, sat\" />"
220
+ },
221
+ SceneTokens: {
222
+ entry: b,
223
+ question: "How is this text split into tokens?",
224
+ guidance: "Use it for a prompt or a short output laid out as tokens that wrap at wrapWidth. Use SceneToken for a single token that moves on its own.",
225
+ example: "<SceneTokens id=\"prompt\" at={[0, 1]} tokens={[{ text: 'The' }, { text: ' cat' }, { text: ' sat', probability: 0.42 }]} label=\"The prompt, three tokens\" />"
226
+ },
227
+ SceneFlow: {
228
+ entry: b,
229
+ question: "How is this result computed from the values I can change?",
230
+ guidance: "Use it inside a Scene to draw the lesson derivation graph, from lessonGraph, with live values, in the part of the box at names. Use LessonFlow when the flow is the whole figure.",
231
+ example: "<Scene title=\"The forward pass\" description=\"Each value, wired to what it reads.\" x={[0, 6]} y={[0, 3]}>\n <SceneNode id=\"stage\" at={[0, 1.5]} text=\"Forward\" />\n <SceneFlow at={{ x: [1, 6], y: [0, 3] }} names={['entropy']} formula={{ entropy: '−Σ p log₂ p' }} />\n</Scene>"
232
+ },
233
+ LessonFlow: {
234
+ entry: b,
235
+ question: "Which values does this result depend on?",
236
+ guidance: "Use it as a figure of its own that draws the lesson derivation graph, sized to fit, with params as inline controls. Draw a hand-placed Scene when the layout carries meaning.",
237
+ example: "<LessonFlow title=\"How entropy is computed\" description=\"Each value, wired to the values it reads.\" names={['entropy']} formula={{ entropy: '−Σ p log₂ p' }} />"
238
+ },
239
+ MorphScope: {
240
+ entry: b,
241
+ question: "Is this the same thing I saw in the diagram, now shown as data?",
242
+ guidance: "Use it when an object in a scene becomes a mark in a chart, so the reader follows its identity: name each figure and show one. Use it sparingly, for one key transition.",
243
+ example: "<MorphScope figures={{ cards: <CardScene />, counts: <CountChart /> }} show={isCounted ? 'counts' : 'cards'} />"
244
+ },
245
+ Article: {
246
+ entry: x,
247
+ question: "What is this essay about, and where am I in it?",
248
+ guidance: "Use it once around a whole explainer: it renders the lesson, the contents and the article, present, static and sheet views from the same children.",
249
+ example: "<Article lesson={lesson} locale=\"en-US\" title=\"How temperature reshapes a softmax\" summary=\"A synthetic four-token example.\">\n <Beat id=\"scores\">…</Beat>\n <Beat id=\"training\">…</Beat>\n</Article>"
250
+ },
251
+ Beat: {
252
+ entry: x,
253
+ question: "What is this section trying to show me?",
254
+ guidance: "Use one per lesson beat: its title, tutor notes, steps and states come from the definition. Keep each beat to one idea and one new param.",
255
+ example: "<Beat id=\"scores\">\n <p>Divide every score by <Param name=\"temperature\" />.</p>\n <Figure id=\"bars\" caption=\"Probabilities after the softmax.\" description=\"Four bars that sum to one.\" reads={['temperature']}>\n <TokenBars />\n </Figure>\n</Beat>"
256
+ },
257
+ Figure: {
258
+ entry: x,
259
+ question: "What am I looking at here?",
260
+ guidance: "Wrap every scene or chart in a beat with a Figure: a caption, a description for the static view, and the values it reads. Size text keeps it to the prose column.",
261
+ example: "<Figure id=\"bet-split\" caption=\"Your bet, split across the two cards.\" description=\"Two cards with the share of the bet on each.\" reads={['bet']} size=\"text\">\n <BetScene />\n</Figure>"
262
+ },
263
+ FigureReference: {
264
+ entry: x,
265
+ question: "Which figure is this sentence talking about?",
266
+ guidance: "Use it in prose to point at a Figure by id; it writes the figure number and links to it in every view. Do not write figure numbers by hand.",
267
+ example: "<p>As <FigureReference to=\"bars\" /> shows, a cold softmax piles the probability on one token.</p>"
268
+ },
269
+ Reveal: {
270
+ entry: x,
271
+ question: "What comes next, once I am ready?",
272
+ guidance: "Use it to show content from a reveal step of the beat on. Declare the step count in the beat definition; do not hide content the static view needs.",
273
+ example: "<Reveal at={1}>\n <p>Training sharpens the scores, so the same temperature now gives <Value name=\"probability\" />.</p>\n</Reveal>"
274
+ },
275
+ Scrolly: {
276
+ entry: x,
277
+ question: "How does the picture change as I read on?",
278
+ guidance: "Use it for one sticky figure that moves through states as steps of prose scroll past; each step sets values or a beat state. Use Reveal and Transport when the reader should drive the pace.",
279
+ example: "<Scrolly figure={<Figure id=\"deal\" caption=\"The deal.\" description=\"Cards dealt one by one.\" reads={['dealt']}><BetScene /></Figure>}>\n <ScrollyStep id=\"first\" values={{ dealt: 1 }}>The first card is dealt.</ScrollyStep>\n <ScrollyStep id=\"second\" state=\"both-dealt\">Then the second.</ScrollyStep>\n</Scrolly>"
280
+ },
281
+ Predict: {
282
+ entry: x,
283
+ question: "What do I expect to happen before I see it?",
284
+ guidance: "Use it before a result the reader could guess wrong: options with an answer id, or a number with its range, format and an answer or answerFrom. The answer stays hidden, from readers and agents, until the reader commits.",
285
+ example: "<Predict id=\"entropy-guess\" prompt=\"At this temperature, how many bits of entropy are left?\" min={0} max={2} step={0.05} format={{ style: 'unit', unit: 'bit', maximumFractionDigits: 2 }} answerFrom=\"entropy\" tolerance={0.15}>\n <p>A cold softmax piles most of the probability on the top token, so little uncertainty is left.</p>\n</Predict>"
286
+ },
287
+ Challenge: {
288
+ entry: x,
289
+ question: "Can I make it do this myself?",
290
+ guidance: "Use it to set a goal the reader reaches by moving params, checked from the values by name, with hints in order. Only the reader reaching it counts; an agent never completes it.",
291
+ example: "<Challenge id=\"low-entropy\" prompt=\"Find a temperature that leaves under 0.5 bits of entropy.\" isReached={(values) => Number(values['entropy']) < 0.5} hints={['Lower the temperature.']}>\n <p>Lower temperatures concentrate the distribution.</p>\n</Challenge>"
292
+ },
293
+ Aside: {
294
+ entry: x,
295
+ question: "Is there more to this, if I want it?",
296
+ guidance: "Use it for a digression a curious reader may skip. Use Footnote for a short source or caveat.",
297
+ example: "<Aside>Temperature 1 leaves the scores as the model gave them.</Aside>"
298
+ },
299
+ Footnote: {
300
+ entry: x,
301
+ question: "Where does this claim come from, or what is the caveat?",
302
+ guidance: "Use it for a one-sentence caveat or source attached to a sentence, with an id unique in the article. Use Cite for a reference in the bibliography.",
303
+ example: "<p>The scores are synthetic.<Footnote id=\"synthetic\">They were chosen by hand to make the example clear.</Footnote></p>"
304
+ },
305
+ Cite: {
306
+ entry: x,
307
+ question: "Who showed this first?",
308
+ guidance: "Use it to cite an entry of the References list by id. Keep the reference data in one References block at the end.",
309
+ example: "<p>Explorable explanations<Cite id=\"victor2011\" /> let the reader change the example.</p>"
310
+ },
311
+ References: {
312
+ entry: x,
313
+ question: "Where can I read more?",
314
+ guidance: "Use it once, after the last beat, with every entry a Cite names. Keep the data in one list so the static and sheet views number them the same.",
315
+ example: "<References items={[{ id: 'victor2011', authors: ['Bret Victor'], title: 'Explorable Explanations', year: 2011, url: 'https://worrydream.com/ExplorableExplanations/' }]} />"
316
+ },
317
+ TeX: {
318
+ entry: x,
319
+ question: "What is the exact formula?",
320
+ guidance: "Use it for TeX the application typesets through the Article math prop; without one it shows the source. Use Value for a number that changes.",
321
+ example: "<p>Surprise is <TeX>{String.raw`-\\log_2 p`}</TeX> bits.</p>\n<TeX isDisplay>{String.raw`H = -\\sum_i p_i \\log_2 p_i`}</TeX>"
322
+ },
323
+ Term: {
324
+ entry: x,
325
+ question: "Which part of the figure does this word mean?",
326
+ guidance: "Use it for a word in prose that names an object in a figure: hovering or focusing it inspects that object. Use plain text for words with no figure object.",
327
+ example: "<p>The <Term inspects=\"queen\">Queen</Term> carries most of the bet.</p>"
328
+ },
329
+ DiagramPart: {
330
+ entry: x,
331
+ question: "Which record of the chart is this part of the drawing?",
332
+ guidance: "Use it around the shapes of a hand-drawn SVG diagram that stand for one record, so pointing at either highlights both. Use a Scene when the diagram should move between states.",
333
+ example: "<svg viewBox=\"0 0 120 60\" role=\"img\" aria-label=\"Two cards\">\n <DiagramPart inspects=\"queen\" label=\"Queen of Hearts\">\n <rect x={10} y={10} width={30} height={40} />\n </DiagramPart>\n</svg>"
334
+ }
335
+ }, C = v.map((e) => ({
336
+ part: e,
337
+ ...S[e]
338
+ })), w = Object.values({
339
+ BarChart: "BarChart",
340
+ BridgeChart: "BridgeChart",
341
+ BreakdownBar: "BreakdownBar",
342
+ ScatterPlot: "ScatterPlot",
343
+ LineChart: "LineChart",
344
+ AreaChart: "AreaChart",
345
+ SmallMultiples: "SmallMultiples",
346
+ Sparkline: "Sparkline",
347
+ Histogram: "Histogram",
348
+ ECDF: "ECDF",
349
+ IntervalPlot: "IntervalPlot",
350
+ RankedBars: "RankedBars",
351
+ BoxPlot: "BoxPlot",
352
+ ViolinPlot: "ViolinPlot",
353
+ StripPlot: "StripPlot",
354
+ Ridgeline: "Ridgeline",
355
+ Matrix: "Matrix",
356
+ TokenHeatmap: "TokenHeatmap",
357
+ ConfusionMatrix: "ConfusionMatrix",
358
+ CorrelationMatrix: "CorrelationMatrix",
359
+ AttentionMatrix: "AttentionMatrix",
360
+ CalendarHeatmap: "CalendarHeatmap",
361
+ RelationGraph: "RelationGraph",
362
+ FlowDiagram: "FlowDiagram",
363
+ AttributionGraph: "AttributionGraph",
364
+ TreeDiagram: "TreeDiagram",
365
+ Treemap: "Treemap",
366
+ Icicle: "Icicle",
367
+ Waterfall: "Waterfall",
368
+ EventStrip: "EventStrip",
369
+ CurveChart: "CurveChart",
370
+ RunsChart: "RunsChart",
371
+ SlopeChart: "SlopeChart",
372
+ BumpChart: "BumpChart",
373
+ HorizonChart: "HorizonChart",
374
+ DotPlot: "DotPlot",
375
+ DumbbellPlot: "DumbbellPlot",
376
+ BulletBar: "BulletBar",
377
+ ContourPlot: "ContourPlot",
378
+ ScatterMatrix: "ScatterMatrix",
379
+ ParallelCoordinates: "ParallelCoordinates",
380
+ EmbeddingMap: "EmbeddingMap",
381
+ DensityMap: "DensityMap",
382
+ TokenExamples: "TokenExamples",
383
+ TokenPredictions: "TokenPredictions",
384
+ TokenGrid: "TokenGrid",
385
+ TokenLinks: "TokenLinks",
386
+ ImageGrid: "ImageGrid",
387
+ AttributionOverlay: "AttributionOverlay",
388
+ ImageAtlas: "ImageAtlas"
389
+ }), T = /* @__PURE__ */ new Set([
390
+ "number",
391
+ "choice",
392
+ "toggle"
393
+ ]), E = /* @__PURE__ */ new Set(["predict", "challenge"]), D = /* @__PURE__ */ new Set(["linear", "log"]), O = [
394
+ "value",
395
+ "min",
396
+ "max",
397
+ "step"
398
+ ], k = 3, A = [...v, ...w];
399
+ function j(e) {
400
+ return typeof e == "string" && e.trim().length > 0;
401
+ }
402
+ function M(t, n, r) {
403
+ let i = t.get(n), a = typeof i == "string" ? "an empty string" : s(i);
404
+ return j(i) ? [] : [e(`${r}.${n}`, `${n} must be a non-empty string, not ${a}.`)];
405
+ }
406
+ function N(e, t, n) {
407
+ return e.has(t) && e.get(t) !== void 0 ? M(e, t, n) : [];
408
+ }
409
+ function P(t, n, r) {
410
+ let i = t.get(n);
411
+ return typeof i == "number" && Number.isFinite(i) ? [] : [e(`${r}.${n}`, `${n} must be a finite number, not ${s(i)}.`)];
412
+ }
413
+ function F(t, n, r) {
414
+ let i = t.get(n);
415
+ if (!Array.isArray(i)) return { findings: [e(`${r}.${n}`, `${n} must be an array of names, not ${s(i)}.`)] };
416
+ let a = i.filter((e) => typeof e == "string");
417
+ return a.length === i.length ? {
418
+ findings: [],
419
+ value: a
420
+ } : { findings: [e(`${r}.${n}`, `${n} must hold only names, as strings.`)] };
421
+ }
422
+ function I(n, r) {
423
+ let i = O.flatMap((e) => P(n, e, r)), o = n.get("scale"), s = o === void 0 || typeof o == "string" && D.has(o), c = a(n.get("format")) !== void 0, l = [
424
+ ...i,
425
+ ...s ? [] : [e(`${r}.scale`, "scale must be \"linear\" or \"log\".")],
426
+ ...c ? [] : [e(`${r}.format`, "format must be Intl.NumberFormat options, such as { \"maximumFractionDigits\": 2 }.")]
427
+ ];
428
+ if (i.length > 0) return { findings: l };
429
+ let [u, d, f, p] = O.map((e) => Number(n.get(e))), m = {
430
+ kind: "number",
431
+ min: d ?? 0,
432
+ max: f ?? 0
433
+ }, h = t("the default", m, u), g = [
434
+ ...l,
435
+ ...m.min < m.max ? [] : [e(`${r}.max`, `max must be above min (${m.min}).`)],
436
+ ...(p ?? 0) > 0 ? [] : [e(`${r}.step`, "step must be above zero.")],
437
+ ...o === "log" && m.min <= 0 ? [e(`${r}.min`, "A log scale needs min above zero. Use a linear scale, or start at a small positive value.")] : [],
438
+ ...h === void 0 ? [] : [e(`${r}.value`, h)]
439
+ ];
440
+ return g.length > 0 ? { findings: g } : {
441
+ findings: g,
442
+ value: m
443
+ };
444
+ }
445
+ function L(n, r) {
446
+ let i = n.get("options");
447
+ if (!Array.isArray(i) || i.length === 0) return { findings: [e(`${r}.options`, "options must be a non-empty array of { id, label }.")] };
448
+ let o = i.map((e, t) => {
449
+ let n = a(e) ?? /* @__PURE__ */ new Map(), i = `${r}.options[${t}]`;
450
+ return {
451
+ id: n.get("id"),
452
+ findings: [...M(n, "id", i), ...M(n, "label", i)]
453
+ };
454
+ }), s = o.map(({ id: e }) => String(e)), c = s.flatMap((t, n) => s.indexOf(t) === n ? [] : [e(`${r}.options[${n}].id`, `Two options share the id "${t}".`)]), l = {
455
+ kind: "choice",
456
+ ids: [...new Set(s)]
457
+ }, u = t("the default", l, n.get("value")), d = [
458
+ ...o.flatMap((e) => e.findings),
459
+ ...c,
460
+ ...u === void 0 ? [] : [e(`${r}.value`, u)]
461
+ ];
462
+ return d.length > 0 ? { findings: d } : {
463
+ findings: d,
464
+ value: l
465
+ };
466
+ }
467
+ function R(t, n) {
468
+ let r = `params.${t}`, i = a(n);
469
+ if (i === void 0) return { findings: [e(r, `A param must be an object with kind, label and value, not ${s(n)}.`)] };
470
+ let o = String(i.get("kind"));
471
+ if (!T.has(o)) return { findings: [e(`${r}.kind`, "kind must be \"number\", \"choice\" or \"toggle\".")] };
472
+ let c = M(i, "label", r), l = o === "number" ? I(i, r) : o === "choice" ? L(i, r) : z(i, r), u = [...c, ...l.findings];
473
+ return u.length > 0 ? { findings: u } : l;
474
+ }
475
+ function z(t, n) {
476
+ return typeof t.get("value") == "boolean" ? {
477
+ findings: [],
478
+ value: { kind: "toggle" }
479
+ } : { findings: [e(`${n}.value`, "A toggle param opens at true or false.")] };
480
+ }
481
+ function* B(e, t) {
482
+ let n = /* @__PURE__ */ new Set(), r = { paths: [[t]] };
483
+ for (; r.paths.length > 0;) yield* r.paths, r.paths = r.paths.flatMap((r) => {
484
+ let i = r.at(-1) ?? t;
485
+ return (r.length > 1 && i === t ? [] : e.get(i) ?? []).filter((e) => {
486
+ let t = !n.has(e);
487
+ return n.add(e), t;
488
+ }).map((e) => [...r, e]);
489
+ });
490
+ }
491
+ function V(e, t) {
492
+ return [...B(e, t)].find((e) => e.length > 1 && e.at(-1) === t);
493
+ }
494
+ function H({ entries: t, params: n }) {
495
+ let r = t.map(([e]) => e), i = /* @__PURE__ */ new Set([...n, ...r]), o = t.map(([t, r]) => {
496
+ let o = `derived.${t}`, s = a(r);
497
+ if (s === void 0) return {
498
+ name: t,
499
+ reads: [],
500
+ findings: [e(o, "A derived value must be an object with label, format, reads and formula.")]
501
+ };
502
+ let c = F(s, "reads", o), l = (c.value ?? []).filter((e) => !i.has(e));
503
+ return {
504
+ name: t,
505
+ reads: c.value ?? [],
506
+ findings: [
507
+ ...n.has(t) ? [e(o, `"${t}" is declared as both a param and a derived value.`)] : [],
508
+ ...M(s, "label", o),
509
+ ...M(s, "formula", o),
510
+ ...a(s.get("format")) === void 0 ? [e(`${o}.format`, "format must be Intl.NumberFormat options.")] : [],
511
+ ...c.findings,
512
+ ...l.map((t) => e(`${o}.reads`, `"${t}" is not a param or a derived value. Declare it, or read one of: ${[...i].join(", ")}.`))
513
+ ]
514
+ };
515
+ }), s = new Map(o.map(({ name: e, reads: t }) => [e, t.filter((e) => r.includes(e))])), c = o.flatMap(({ name: t, reads: n }) => {
516
+ let i = n.filter((e) => r.indexOf(e) >= r.indexOf(t)), a = V(s, t);
517
+ return a === void 0 ? i.map((n) => e(`derived.${t}.reads`, `"${t}" reads "${n}", which is declared after it. defineLesson computes in order, so move "${n}" above it.`)) : [e(`derived.${t}.reads`, `Derived values read each other in a loop: ${a.join(" → ")}. Break the loop so each is computed from earlier values.`)];
518
+ });
519
+ return {
520
+ findings: [...o.flatMap((e) => e.findings), ...c],
521
+ value: s
522
+ };
523
+ }
524
+ function U({ input: n, path: r, names: i }) {
525
+ let o = a(n);
526
+ if (o === void 0) return [e(r, `A state must be an object with id, label and values, not ${s(n)}.`)];
527
+ let c = a(o.get("values")), l = [...c ?? []].flatMap(([n, a]) => {
528
+ let o = i.rules.get(n), s = `${r}.values.${n}`;
529
+ if (o !== void 0) {
530
+ let r = t(n, o, a);
531
+ return r === void 0 ? [] : [e(s, r)];
532
+ }
533
+ return i.derived.has(n) ? [e(s, `"${n}" is a derived value; a state sets params only, and the derived values follow.`)] : i.params.has(n) ? [] : [e(s, `"${n}" is not a param. The params: ${[...i.params].join(", ")}.`)];
534
+ });
535
+ return [
536
+ ...M(o, "id", r),
537
+ ...M(o, "label", r),
538
+ ...c === void 0 ? [e(`${r}.values`, "values must be an object of param names and values.")] : [],
539
+ ...l
540
+ ];
541
+ }
542
+ function W(e) {
543
+ let t = e.toLowerCase();
544
+ return A.find((e) => e.toLowerCase().includes(t) || t.includes(e.toLowerCase()));
545
+ }
546
+ function G({ input: t, path: n, names: r }) {
547
+ let i = a(t);
548
+ if (i === void 0) return [e(n, "figure must be an object with part and question.")];
549
+ let o = i.get("part"), s = typeof o == "string" && A.includes(o), c = typeof o == "string" && o.length > 0 ? W(o) : void 0, l = c === void 0 ? " Choose a part from explainerGuide or a chart from chartGuide." : ` Did you mean ${c}?`, u = i.has("shows") ? F(i, "shows", n) : {
550
+ findings: [],
551
+ value: []
552
+ }, d = /* @__PURE__ */ new Set([...r.params, ...r.derived]);
553
+ return [
554
+ ...s ? [] : [e(`${n}.part`, `"${String(o)}" is not a teaching part or a chart.${l}`)],
555
+ ...M(i, "question", n),
556
+ ...u.findings,
557
+ ...(u.value ?? []).flatMap((t) => d.has(t) ? [] : [e(`${n}.shows`, `"${t}" is not a param or a derived value.`)])
558
+ ];
559
+ }
560
+ function K(t, n) {
561
+ let r = a(t);
562
+ return r === void 0 ? [e(n, "ask must be an object with kind and prompt.")] : [...E.has(String(r.get("kind"))) ? [] : [e(`${n}.kind`, "kind must be \"predict\" or \"challenge\".")], ...M(r, "prompt", n)];
563
+ }
564
+ function q(t, n) {
565
+ return t.has("hints") && F(t, "hints", n).findings.length > 0 ? [e(`${n}.hints`, "hints must be an array of sentences.")] : [];
566
+ }
567
+ function J({ input: t, index: n, names: r }) {
568
+ let i = `beats[${n}]`, o = a(t);
569
+ if (o === void 0) return [e(i, `A beat must be an object with id and title, not ${s(t)}.`)];
570
+ let c = o.get("steps"), l = c === void 0 || Number.isInteger(c) && Number(c) >= 0, u = o.get("states"), d = Array.isArray(u) ? u : [], f = d.map((e) => a(e)?.get("id"));
571
+ return [
572
+ ...M(o, "id", i),
573
+ ...M(o, "title", i),
574
+ ...N(o, "goal", i),
575
+ ...N(o, "misconception", i),
576
+ ...q(o, i),
577
+ ...l ? [] : [e(`${i}.steps`, "steps must be a whole number from 0.")],
578
+ ...u === void 0 || Array.isArray(u) ? [] : [e(`${i}.states`, "states must be an array.")],
579
+ ...d.flatMap((e, t) => U({
580
+ input: e,
581
+ path: `${i}.states[${t}]`,
582
+ names: r
583
+ })),
584
+ ...f.flatMap((t, n) => f.indexOf(t) === n ? [] : [e(`${i}.states[${n}].id`, `Two states of this beat share the id "${String(t)}".`)]),
585
+ ...o.get("figure") === void 0 ? [] : G({
586
+ input: o.get("figure"),
587
+ path: `${i}.figure`,
588
+ names: r
589
+ }),
590
+ ...o.get("ask") === void 0 ? [] : K(o.get("ask"), `${i}.ask`)
591
+ ];
592
+ }
593
+ function Y({ beats: e, derived: t }) {
594
+ let r = e.slice(0, k).some((e) => e.get("ask") !== void 0), i = e.map((e) => a(e.get("figure"))), o = new Set(i.flatMap((e) => {
595
+ let t = e?.get("shows");
596
+ return Array.isArray(t) ? t.map(String) : [];
597
+ })), s = new Set([...t.values()].flat());
598
+ return [
599
+ ...r || e.length === 0 ? [] : [n("beats", "None of the first three beats asks for a prediction or a challenge. Add a Predict early, so the reader commits to a guess.")],
600
+ ...i.flatMap((e, t) => e === void 0 ? [n(`beats[${t}].figure`, "This beat shows no figure. Give it one, or fold its prose into the beat before.")] : []),
601
+ ...[...t.keys()].filter((e) => !o.has(e) && !s.has(e)).map((e) => n(`derived.${e}`, `No figure shows "${e}" and no value reads it. List it in a figure's shows, or remove it.`))
602
+ ];
603
+ }
604
+ function X(t) {
605
+ let n = a(t);
606
+ if (n === void 0) return {
607
+ isValid: !1,
608
+ findings: [e("", `A lesson plan is an object with id, title, audience, idea, params and beats, not ${s(t)}.`)]
609
+ };
610
+ let r = a(n.get("params")), i = n.get("derived") === void 0 ? /* @__PURE__ */ new Map() : a(n.get("derived")), o = n.get("beats"), c = Array.isArray(o) ? o : [], l = [...r ?? []].map(([e, t]) => ({
611
+ name: e,
612
+ ...R(e, t)
613
+ })), u = new Map(l.flatMap(({ name: e, value: t }) => t === void 0 ? [] : [[e, t]])), d = new Set(l.map(({ name: e }) => e)), f = H({
614
+ entries: [...i ?? []],
615
+ params: d
616
+ }), p = {
617
+ rules: u,
618
+ params: d,
619
+ derived: new Set(i?.keys())
620
+ }, m = c.map((e) => a(e) ?? /* @__PURE__ */ new Map()), h = m.map((e) => e.get("id")), _ = [
621
+ ...[
622
+ "id",
623
+ "title",
624
+ "audience",
625
+ "idea"
626
+ ].flatMap((e) => M(n, e, "").map((t) => ({
627
+ ...t,
628
+ path: e
629
+ }))),
630
+ ...r === void 0 ? [e("params", "params must be an object of named params.")] : [],
631
+ ...l.flatMap(({ findings: e }) => e),
632
+ ...i === void 0 ? [e("derived", "derived must be an object of named derived values.")] : [],
633
+ ...f.findings,
634
+ ...c.length === 0 ? [e("beats", "beats must be a non-empty array.")] : [],
635
+ ...c.flatMap((e, t) => J({
636
+ input: e,
637
+ index: t,
638
+ names: p
639
+ })),
640
+ ...h.flatMap((t, n) => h.indexOf(t) === n ? [] : [e(`beats[${n}].id`, `Two beats share the id "${String(t)}".`)])
641
+ ], v = [...g({
642
+ defaults: Object.fromEntries(l.map(({ name: e }) => [e, a(r?.get(e))?.get("value")])),
643
+ beats: m.map((e, t) => {
644
+ let n = e.get("states");
645
+ return {
646
+ id: typeof e.get("id") == "string" ? String(e.get("id")) : `#${t}`,
647
+ title: typeof e.get("title") == "string" ? String(e.get("title")) : "",
648
+ hasGoal: j(e.get("goal")),
649
+ states: (Array.isArray(n) ? n : []).map((e) => Object.fromEntries(a(a(e)?.get("values")) ?? []))
650
+ };
651
+ })
652
+ }), ...Y({
653
+ beats: m,
654
+ derived: f.value ?? /* @__PURE__ */ new Map()
655
+ })];
656
+ return {
657
+ isValid: _.length === 0,
658
+ findings: [..._, ...v]
659
+ };
660
+ }
661
+ export { _ as checkLesson, c as describeLesson, C as explainerGuide, v as explainerParts, i as lessonWalk, X as validateLessonPlan, r as valueProblem, o as writtenValue };