@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
@@ -1,16 +1,21 @@
1
1
  import type { ReactNode } from 'react';
2
+ /** What assistive technology hears after a term or a diagram part's name. */
3
+ export type TermLabels = {
4
+ readonly hint: string;
5
+ };
2
6
  export type TermProps = {
3
7
  /** The record the term names, by the id the figures use for it: a series, a run, a step. */
4
8
  readonly inspects: string;
5
9
  /** The words in the sentence. */
6
10
  readonly children: ReactNode;
11
+ readonly labels?: Partial<TermLabels> | undefined;
7
12
  };
8
13
  /**
9
14
  * A word in prose that points into the figures: hovering or focusing "the base run" highlights that run in every chart
10
15
  * of the enclosing `ChartLink`. A press does the same on touch. Its dotted underline takes the record's hue when a
11
16
  * `ToneScope` names it, so the sentence doubles as a legend.
12
17
  */
13
- export declare function Term({ inspects, children }: TermProps): ReactNode;
18
+ export declare function Term({ inspects, children, labels }: TermProps): ReactNode;
14
19
  export type DiagramPartProps = {
15
20
  /** The record this part of the diagram stands for, by the id the figures and terms use for it. */
16
21
  readonly inspects: string;
@@ -21,9 +26,10 @@ export type DiagramPartProps = {
21
26
  * emphasis while the link inspects this record.
22
27
  */
23
28
  readonly children: ReactNode;
29
+ readonly labels?: Partial<TermLabels> | undefined;
24
30
  };
25
31
  /**
26
32
  * A part of a hand-drawn SVG diagram linked to the figures both ways: pointing at it or focusing it highlights its
27
33
  * record in every chart of the enclosing `ChartLink`. It is emphasized whenever a chart or a `Term` inspects it.
28
34
  */
29
- export declare function DiagramPart({ inspects, label, children }: DiagramPartProps): ReactNode;
35
+ export declare function DiagramPart({ inspects, label, children, labels }: DiagramPartProps): ReactNode;
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react';
2
+ export type TeXProps = {
3
+ /** The TeX source, such as `p_i = e^{z_i / T} / \sum_j e^{z_j / T}`. */
4
+ readonly children: string;
5
+ /** A block of its own, centred between paragraphs. Inline in the sentence by default. */
6
+ readonly isDisplay?: boolean | undefined;
7
+ };
8
+ /**
9
+ * Mathematics in TeX. The article's `math` function typesets it; without one the TeX source shows in the monospace
10
+ * face. Assistive technology always reads the source, so the formula means the same with or without a typesetter.
11
+ */
12
+ export declare function TeX({ children, isDisplay }: TeXProps): ReactNode;
@@ -0,0 +1,13 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ArticleScope } from './article-context.ts';
3
+ export type ViewProps = {
4
+ readonly article: ArticleScope;
5
+ /** The title, byline and summary. */
6
+ readonly header: ReactNode;
7
+ readonly children: ReactNode;
8
+ };
9
+ /**
10
+ * The article view: a scrolling essay with a contents list that follows the reading position. Scrolling a beat into the
11
+ * reading band makes it the lesson's beat, and a beat set elsewhere, such as by an agent, scrolls into view.
12
+ */
13
+ export declare function EssayView({ article, header, children }: ViewProps): ReactNode;
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from './view-essay.tsx';
3
+ /**
4
+ * The present view: one beat per slide, with its notes, walked by Right, Space and Left through scrolly steps, reveal
5
+ * steps and beats. Moving to a beat shows its first declared state, coming back included; a scrolly step lays its
6
+ * values over that state, so on entry its first step wins. Keys inside a control, such as a slider, stay with it.
7
+ */
8
+ export declare function PresentView({ article, children }: ViewProps): ReactNode;
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from './view-essay.tsx';
3
+ /**
4
+ * The sheet view, for authors, reviewers and agents: every beat at each of its declared states, small and read-only,
5
+ * with its tutor notes, then a list of checks. Each cell holds its own read-only lesson.
6
+ */
7
+ export declare function SheetView({ article }: ViewProps): ReactNode;
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from './view-essay.tsx';
3
+ /**
4
+ * The static view: every beat open at its first state, every reveal shown, each figure followed by its description, and
5
+ * nothing that needs a script to be read. Feed readers, printers and readers without JavaScript get this view.
6
+ */
7
+ export declare function StaticView({ article, header, children }: ViewProps): ReactNode;
@@ -0,0 +1,34 @@
1
+ import type { ReactElement } from 'react';
2
+ /** An element found in an article's markup, with its props as plain values to read. */
3
+ export type MarkupElement = ReactElement<Readonly<Record<string, unknown>>>;
4
+ /** Where an element sits: the beat and the figure around it, when there are any. */
5
+ export type MarkupPlace = {
6
+ readonly beat: string | null;
7
+ readonly figure: string | null;
8
+ };
9
+ /** One element of the markup and its place. */
10
+ export type MarkupEntry = {
11
+ readonly element: MarkupElement;
12
+ readonly place: MarkupPlace;
13
+ };
14
+ /** Decides the place of an element's props from the element and the place around it. */
15
+ export type PlaceOf = (input: {
16
+ readonly element: MarkupElement;
17
+ readonly place: MarkupPlace;
18
+ readonly prop: string;
19
+ }) => MarkupPlace;
20
+ /** What `walkMarkup` walks: the markup, the place it starts in, and how an element's props find their place. */
21
+ export type MarkupWalk = {
22
+ readonly node: unknown;
23
+ readonly place: MarkupPlace;
24
+ readonly placeOf: PlaceOf;
25
+ };
26
+ /**
27
+ * Walks markup the author wrote, in reading order, through children and every prop that holds elements, such as a
28
+ * caption or a scrolly's figure. Components the author defined are not rendered, so their own output is not seen.
29
+ *
30
+ * @yields Each element with the beat and the figure around it.
31
+ */
32
+ export declare function walkMarkup({ node, place, placeOf }: MarkupWalk): Generator<MarkupEntry>;
33
+ /** The text a prop holds, or undefined when it holds something else. */
34
+ export declare function textProp(element: MarkupElement, prop: string): string | undefined;
@@ -0,0 +1,136 @@
1
+ import type { ValueFormat } from '../../../charts/src/index.ts';
2
+ /** A number the reader changes, with its range, its step grid and how it is written. */
3
+ export type NumberParam = {
4
+ readonly kind: 'number';
5
+ readonly label: string;
6
+ /** The value the lesson opens with. */
7
+ readonly value: number;
8
+ readonly min: number;
9
+ readonly max: number;
10
+ /** The grid values land on. A player advances by one step at a time. */
11
+ readonly step: number;
12
+ /** `log` gives each tenfold the same drag distance, for rates and other ratios. */
13
+ readonly scale?: 'linear' | 'log' | undefined;
14
+ readonly format: ValueFormat;
15
+ };
16
+ /** One of a few named options, such as which card is dealt. */
17
+ export type ChoiceParam = {
18
+ readonly kind: 'choice';
19
+ readonly label: string;
20
+ /** The id of the option the lesson opens with. */
21
+ readonly value: string;
22
+ readonly options: ReadonlyArray<{
23
+ readonly id: string;
24
+ readonly label: string;
25
+ }>;
26
+ };
27
+ /** A yes or no setting, such as whether an answer is revealed. */
28
+ export type ToggleParam = {
29
+ readonly kind: 'toggle';
30
+ readonly label: string;
31
+ readonly value: ToggleValue;
32
+ };
33
+ /** Whether a toggle is on. */
34
+ export type ToggleValue = boolean;
35
+ /** A value the reader, the application or an agent may set. */
36
+ export type LessonParam = NumberParam | ChoiceParam | ToggleParam;
37
+ /** What a param or derived value holds. */
38
+ export type LessonValue = number | string | boolean;
39
+ /** The params of a lesson, by name. */
40
+ export type LessonParams = Readonly<Record<string, LessonParam>>;
41
+ /** A named state of the lesson: the values a beat shows at one moment. Plain data. */
42
+ export type LessonState = {
43
+ readonly id: string;
44
+ readonly label: string;
45
+ readonly values: Readonly<Record<string, LessonValue>>;
46
+ };
47
+ /** One beat of the essay as data, so an agent can read the outline without rendering it. */
48
+ export type LessonBeat = {
49
+ readonly id: string;
50
+ readonly title: string;
51
+ /** Tutor notes. Never shown to the reader. */
52
+ readonly goal?: string | undefined;
53
+ readonly misconception?: string | undefined;
54
+ readonly hints?: ReadonlyArray<string> | undefined;
55
+ /** How many reveal steps the beat has after its first view. Defaults to 0. */
56
+ readonly steps?: number | undefined;
57
+ /** The states worth seeing on a beat sheet and in the static view. The first is the beat's opening state. */
58
+ readonly states?: ReadonlyArray<LessonState> | undefined;
59
+ };
60
+ /** A derived value as a lesson keeps it: its label and format. */
61
+ export type LessonDerived = {
62
+ readonly label: string;
63
+ readonly format: ValueFormat;
64
+ };
65
+ type ParamValue<Param> = Param extends NumberParam ? number : Param extends ChoiceParam ? Param['options'][number]['id'] : Param extends ToggleParam ? boolean : never;
66
+ /** The value of each param, typed by its kind: a number, an option id or a boolean. */
67
+ export type ParamValues<Params extends LessonParams> = {
68
+ readonly [Name in keyof Params]: ParamValue<Params[Name]>;
69
+ };
70
+ /** Every value a lesson's readers see: its params and its derived numbers. */
71
+ export type LessonValues<Params extends LessonParams, Derived extends string> = string extends Derived ? Readonly<Record<string, LessonValue>> : ParamValues<Params> & Readonly<Record<Derived, number>>;
72
+ /** How an author declares a derived value: `from` is a pure function of the params and earlier derived values. */
73
+ export type LessonDerivedInput<Values> = LessonDerived & {
74
+ readonly from: (values: Values) => number;
75
+ };
76
+ /** A lesson made by `defineLesson`: the params, derived values and beats every part of the lesson reads. */
77
+ export type LessonDefinition<Params extends LessonParams = LessonParams, Derived extends string = string, Beat extends string = string> = {
78
+ readonly id: string;
79
+ readonly title: string;
80
+ readonly params: Params;
81
+ readonly derived: Readonly<Record<Derived, LessonDerived>>;
82
+ readonly beats: ReadonlyArray<LessonBeat & {
83
+ readonly id: Beat;
84
+ }>;
85
+ /** The opening value of every param. */
86
+ readonly defaults: ParamValues<Params>;
87
+ /** Every value, params and derived, at the opening values. */
88
+ readonly initial: LessonValues<Params, Derived>;
89
+ /** Every derived value from a full set of param values, in declaration order. */
90
+ readonly compute: (values: Readonly<Record<string, LessonValue>>) => Readonly<Record<string, number>>;
91
+ /** The names each derived value reads, from evaluating it over the defaults and every beat state. */
92
+ readonly reads: Readonly<Record<string, ReadonlyArray<string>>>;
93
+ };
94
+ /** What an author writes to declare a lesson. */
95
+ export type LessonInput<Params extends LessonParams, Derived extends string, Beat extends string> = {
96
+ readonly id: string;
97
+ readonly title: string;
98
+ readonly params: Params;
99
+ /** Values computed from params and from derived values declared earlier. `from` must be pure. */
100
+ readonly derived?: Readonly<Record<Derived, LessonDerivedInput<LessonValues<Params, Derived>>>> | undefined;
101
+ readonly beats?: ReadonlyArray<LessonBeat & {
102
+ readonly id: Beat;
103
+ }> | undefined;
104
+ };
105
+ /** Any lesson, whatever its params. Untyped parts take this. */
106
+ export type AnyLesson = LessonDefinition;
107
+ /** The graph of a lesson: its values and which values each derived value reads. */
108
+ export type LessonGraph = {
109
+ readonly nodes: ReadonlyArray<{
110
+ readonly name: string;
111
+ readonly kind: 'param' | 'derived';
112
+ readonly label: string;
113
+ }>;
114
+ readonly edges: ReadonlyArray<{
115
+ readonly from: string;
116
+ readonly to: string;
117
+ }>;
118
+ };
119
+ /** Why `value` cannot be the value of `param`, or undefined when it can. */
120
+ export declare function paramProblem({ name, param, value, }: {
121
+ readonly name: string;
122
+ readonly param: LessonParam;
123
+ readonly value: unknown;
124
+ }): string | undefined;
125
+ /**
126
+ * Declares a lesson: its params with their ranges, steps and formats, the values derived from them, and its beats as
127
+ * plain data. Every prose value, control, figure, player and agent of the lesson reads these names. A duplicate or
128
+ * unknown name, a default out of range or a beat state naming an undeclared param throws an `Error` naming it.
129
+ */
130
+ export declare function defineLesson<const Params extends LessonParams, const Derived extends string = never, const Beat extends string = string>(definition: LessonInput<Params, Derived, Beat>): LessonDefinition<Params, Derived, Beat>;
131
+ /**
132
+ * Which values each derived value reads, found by evaluating it over the defaults and every beat state. Draw it as a
133
+ * derivation diagram, or check that a lesson's figures read the values its prose sets.
134
+ */
135
+ export declare function lessonGraph(lesson: AnyLesson): LessonGraph;
136
+ export {};
@@ -0,0 +1,24 @@
1
+ export { isMotionReduced, onFrame } from '../time/clock.ts';
2
+ export type { Pace, Tween } from '../time/tween.ts';
3
+ export { createTween } from '../time/tween.ts';
4
+ export { useTween } from '../time/use-tween.ts';
5
+ export { LessonLocale, useLessonLocale } from './lesson-locale.ts';
6
+ export type { AnyLesson, ChoiceParam, LessonBeat, LessonDefinition, LessonDerived, LessonDerivedInput, LessonGraph, LessonInput, LessonParam, LessonParams, LessonState, LessonValue, LessonValues, NumberParam, ParamValues, ToggleParam, ToggleValue, } from './define-lesson.ts';
7
+ export { defineLesson, lessonGraph } from './define-lesson.ts';
8
+ export type { LessonApi, LessonChangeOrigin, LessonPlaceChangeDetails, LessonPlaceChangeReason, LessonPlaceOrigin, LessonPlayingChangeDetails, LessonValuesChangeDetails, LessonValuesChangeReason, } from './lesson-store.ts';
9
+ export type { LessonPlayer, LessonPlayingChangeReason, PlayOrigin, PlaybackPace } from './lesson-player.ts';
10
+ export { playbackPaces } from './lesson-player.ts';
11
+ export type { LessonProps } from './lesson.tsx';
12
+ export { Lesson } from './lesson.tsx';
13
+ export type { LessonControls } from './use-lesson.ts';
14
+ export { useLesson, useLessonContext } from './use-lesson.ts';
15
+ export type { BoundValueChangeDetails, BoundValueProps, BoundValueScale } from './bound-value.tsx';
16
+ export { BoundValue } from './bound-value.tsx';
17
+ export type { ParamProps, ValueLabels, ValueProps } from './param.tsx';
18
+ export { Param, Value } from './param.tsx';
19
+ export type { ParamControlProps } from './param-controls.tsx';
20
+ export { ParamChoice, ParamSlider, ParamToggle } from './param-controls.tsx';
21
+ export type { PlaybackControls, PlaybackProps } from './playback.tsx';
22
+ export { Playback, usePlayback } from './playback.tsx';
23
+ export type { TransportLabels, TransportProps } from './transport.tsx';
24
+ export { Transport } from './transport.tsx';
@@ -0,0 +1,12 @@
1
+ import type { ChangeDetails } from '@ui-sdk/core';
2
+ import type { SelectValueChangeReason } from '@ui-sdk/react/select';
3
+ import type { ReactNode } from 'react';
4
+ import type { ChoiceParam } from './define-lesson.ts';
5
+ export type InlineChoiceProps = {
6
+ readonly param: ChoiceParam;
7
+ readonly value: string;
8
+ readonly isDisabled: boolean;
9
+ readonly onChange: (value: string, details: ChangeDetails<SelectValueChangeReason>) => void;
10
+ };
11
+ /** One option of a choice param, picked from a short list that opens from the word in the sentence. */
12
+ export declare function InlineChoice({ param, value, isDisabled, onChange }: InlineChoiceProps): ReactNode;
@@ -0,0 +1,18 @@
1
+ import type { AnyLesson, LessonValue } from './define-lesson.ts';
2
+ import type { LessonApi, LessonStoreState } from './lesson-store.ts';
3
+ /** What the nearest `Lesson` shares with the parts inside it. */
4
+ export type LessonScope = {
5
+ readonly lesson: AnyLesson;
6
+ readonly api: LessonApi;
7
+ readonly state: LessonStoreState;
8
+ /** Every value: the params and the derived values computed from them. */
9
+ readonly values: Readonly<Record<string, LessonValue>>;
10
+ readonly locale: string;
11
+ /** The lesson around this one, when lessons are nested. */
12
+ readonly outer: LessonScope | null;
13
+ };
14
+ export declare const LessonContext: import("react").Context<LessonScope | null>;
15
+ /** The nearest lesson. Throws a clear `Error` naming the part outside any `Lesson`. */
16
+ export declare function useLessonScope(part: string): LessonScope;
17
+ /** The nearest lesson that renders `lesson`, walking out through nested lessons. */
18
+ export declare function scopeOf(scope: LessonScope | null, lesson: AnyLesson): LessonScope | null;
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from 'react';
2
+ /**
3
+ * Throws the error a lesson gives for a value or a name it does not take. The message names the lesson and the value at
4
+ * fault, so the author or the agent that made the call can fix it.
5
+ */
6
+ export declare function failLesson(lesson: string, message: string): never;
7
+ /** Throws the error a lesson part gives when it is used outside every `Lesson`. */
8
+ export declare function failOutside(part: string): never;
9
+ /** The short inline error a lesson part shows in place of itself when the author gave it a name or value it lacks. */
10
+ export declare function LessonError({ children }: {
11
+ readonly children: string;
12
+ }): ReactNode;
@@ -0,0 +1,4 @@
1
+ /** The locale of the nearest lesson, which its figures and values fall back to. */
2
+ export declare const LessonLocale: import("react").Context<string | null>;
3
+ /** The locale the nearest `Lesson` was given, or null outside a lesson. */
4
+ export declare function useLessonLocale(): string | null;
@@ -0,0 +1,17 @@
1
+ import type { AnyLesson, LessonParam, LessonValue } from './define-lesson.ts';
2
+ /** A full set of param values, by name. */
3
+ export type LessonParamValues = Readonly<Record<string, LessonValue>>;
4
+ /** What a caller or an agent hands `setParam`: number text and `"true"` become values, an option's label its id. */
5
+ export declare function coercedValue(param: LessonParam, value: unknown): unknown;
6
+ /**
7
+ * Reads the values a reader saved under `storageKey` and the ones the address bar links to, then writes the values back
8
+ * once they rest. The address bar names each value `lessonId.name` and leaves out the ones at their defaults.
9
+ */
10
+ export declare function connectPersistence({ lesson, shouldSyncUrl, storageKey, read, subscribe, restore, }: {
11
+ readonly lesson: AnyLesson;
12
+ readonly shouldSyncUrl: boolean;
13
+ readonly storageKey: string | undefined;
14
+ readonly read: () => LessonParamValues;
15
+ readonly subscribe: (listener: () => void) => () => void;
16
+ readonly restore: (values: LessonParamValues) => void;
17
+ }): () => void;
@@ -0,0 +1,51 @@
1
+ import type { ChangeSource } from '@ui-sdk/core';
2
+ import type { StepRange } from '@ui-sdk/core/number';
3
+ /** How fast a player moves its param, in steps per second. */
4
+ export declare const playbackPaces: {
5
+ readonly fast: 12;
6
+ readonly regular: 6;
7
+ readonly slow: 2;
8
+ };
9
+ /** A player's pace, from `playbackPaces`. */
10
+ export type PlaybackPace = keyof typeof playbackPaces;
11
+ /** A number param that a `Playback` drives: where it starts, where it ends and how fast it goes. */
12
+ export type LessonPlayer = {
13
+ readonly name: string;
14
+ readonly from: number;
15
+ readonly to: number;
16
+ readonly pace: PlaybackPace;
17
+ readonly isLooping: boolean;
18
+ };
19
+ /** Why a player started or stopped: a press, the end of its run or a hidden tab, or a call. */
20
+ export type LessonPlayingChangeReason = 'press' | 'playback' | 'imperative';
21
+ /** What a start or stop says about itself: its reason, and the event and source when a reader caused it. */
22
+ export type PlayOrigin = {
23
+ readonly reason: LessonPlayingChangeReason;
24
+ readonly event?: Event | undefined;
25
+ readonly source?: ChangeSource | undefined;
26
+ };
27
+ /** What the players need from the store. */
28
+ type PlayerHost = {
29
+ /** The param playing now, or null. */
30
+ readonly playing: () => string | null;
31
+ /** Asks to start or stop a player. False when the application refused. */
32
+ readonly setPlaying: (name: string | null, origin?: PlayOrigin) => boolean;
33
+ readonly publish: (players: Readonly<Record<string, LessonPlayer>>) => void;
34
+ readonly value: (name: string) => number;
35
+ /** The step grid of a number param: its min and step, with the player's end as the max. */
36
+ readonly grid: (player: LessonPlayer) => StepRange;
37
+ readonly move: (name: string, value: number) => void;
38
+ readonly refuse: (message: string) => never;
39
+ };
40
+ /** The players of one lesson, which move their params on the shared clock. */
41
+ export type LessonPlayers = {
42
+ readonly register: (player: LessonPlayer) => () => void;
43
+ readonly play: (name?: string, origin?: PlayOrigin) => void;
44
+ readonly pause: (origin?: PlayOrigin) => void;
45
+ };
46
+ /**
47
+ * Makes a lesson's players. A player advances its param one step at a time at its pace, stops at its end or starts over
48
+ * from `from`, and stops when the tab is hidden. With reduced motion, play shows the end at once.
49
+ */
50
+ export declare function createPlayers(host: PlayerHost): LessonPlayers;
51
+ export {};
@@ -0,0 +1,84 @@
1
+ import type { ChangeDetails, ChangeSource, PrimitiveContext } from '@ui-sdk/core';
2
+ import type { AnyLesson } from './define-lesson.ts';
3
+ import type { LessonParamValues } from './lesson-persistence.ts';
4
+ import type { LessonPlayer, LessonPlayingChangeReason, PlayOrigin } from './lesson-player.ts';
5
+ /** Why the values changed: a control or a key the reader used, a player, a reset, a value read back, or a call. */
6
+ export type LessonValuesChangeReason = 'drag' | 'step-key' | 'track-press' | 'accessibility-adjust' | 'item-press' | 'list-navigation' | 'clear-press' | 'press' | 'playback' | 'scroll' | 'shortcut' | 'reset' | 'restore' | 'imperative';
7
+ /** Why the beat or the reveal step changed: a key in a presentation, scrolling, a press, or a call. */
8
+ export type LessonPlaceChangeReason = 'shortcut' | 'scroll' | 'link-press' | 'press' | 'restore' | 'imperative';
9
+ /** What a player starting or stopping reports: its reason, its event and its source, and `cancel()` to refuse it. */
10
+ export type LessonPlayingChangeDetails = ChangeDetails<LessonPlayingChangeReason>;
11
+ /** What a values change reports: its reason, its event and its source, and `cancel()` to refuse it. */
12
+ export type LessonValuesChangeDetails = ChangeDetails<LessonValuesChangeReason>;
13
+ /** What a beat or step change reports: its reason, its event and its source, and `cancel()` to refuse it. */
14
+ export type LessonPlaceChangeDetails = ChangeDetails<LessonPlaceChangeReason>;
15
+ /** What a change says about itself. Controls pass their own details through. */
16
+ export type LessonChangeOrigin<Reason extends string = LessonValuesChangeReason> = {
17
+ readonly reason: Reason;
18
+ readonly event?: Event | undefined;
19
+ readonly source?: ChangeSource | undefined;
20
+ };
21
+ export type LessonPlaceOrigin = LessonChangeOrigin<LessonPlaceChangeReason>;
22
+ export type LessonStoreOptions = {
23
+ readonly lesson: AnyLesson;
24
+ readonly values?: LessonParamValues | undefined;
25
+ readonly defaultValues?: LessonParamValues | undefined;
26
+ readonly onValuesChange?: ((values: LessonParamValues, details: LessonValuesChangeDetails) => void) | undefined;
27
+ readonly beat?: string | null | undefined;
28
+ readonly defaultBeat?: string | null | undefined;
29
+ readonly onBeatChange?: ((beat: string | null, details: LessonPlaceChangeDetails) => void) | undefined;
30
+ readonly step?: number | undefined;
31
+ readonly defaultStep?: number | undefined;
32
+ readonly onStepChange?: ((step: number, details: LessonPlaceChangeDetails) => void) | undefined;
33
+ readonly onPlayingChange?: ((playing: string | null, details: LessonPlayingChangeDetails) => void) | undefined;
34
+ /** Who started the player that is running, so its steps are attributed to the same source. */
35
+ readonly playSource?: (() => ChangeSource) | undefined;
36
+ /** Steps the markup adds to a beat after its declared reveal steps, such as a scrolly's steps in a presentation. */
37
+ readonly addedSteps?: Readonly<Record<string, number>> | undefined;
38
+ readonly isReadOnly?: boolean | undefined;
39
+ readonly shouldSyncUrl?: boolean | undefined;
40
+ readonly storageKey?: string | undefined;
41
+ };
42
+ /** The lesson as the store holds it. Agents read `values`, `beat` and `step`. */
43
+ export type LessonStoreState = {
44
+ readonly values: LessonParamValues;
45
+ readonly beat: string | null;
46
+ readonly step: number;
47
+ /** The param a player is moving now, or null. */
48
+ readonly playing: string | null;
49
+ readonly players: Readonly<Record<string, LessonPlayer>>;
50
+ readonly isReadOnly: boolean;
51
+ };
52
+ /** What the lesson store does: every change a part, a player or an agent asks of the lesson goes through it. */
53
+ export type LessonApi = {
54
+ /** Sets one param to a value of its kind, with the change's origin. Throws when the value is out of range. */
55
+ readonly apply: (name: string, value: unknown, origin: LessonChangeOrigin) => boolean;
56
+ /** Sets one param: a number in its range, an option's id or label, or true or false. */
57
+ readonly setParam: (name: string, value: unknown) => boolean;
58
+ /** Sets several params in one change, so readers of the change see one move and not one per param. */
59
+ readonly setParams: (values: Readonly<Record<string, unknown>>, origin?: LessonChangeOrigin) => boolean;
60
+ /** Shows a state a beat declares: its values are set in one change. Looks in the current beat first. */
61
+ readonly showState: (state: string, origin?: LessonChangeOrigin) => boolean;
62
+ /** Puts every param back to the value the lesson opened with. */
63
+ readonly reset: (origin?: LessonChangeOrigin) => boolean;
64
+ /** Moves to a beat, at its first reveal step unless `step` says otherwise. */
65
+ readonly setBeat: (beat: string, step?: number, origin?: LessonPlaceOrigin) => boolean;
66
+ /** Shows the next reveal step, or the next beat at its first step. */
67
+ readonly next: (origin?: LessonPlaceOrigin) => boolean;
68
+ /** Hides the last reveal step, or goes back to the previous beat with every step shown. */
69
+ readonly previous: (origin?: LessonPlaceOrigin) => boolean;
70
+ /** Starts the player of a number param, or the only player when there is one. */
71
+ readonly play: (name?: string, origin?: PlayOrigin) => void;
72
+ /** Stops the player that is running. */
73
+ readonly pause: (origin?: PlayOrigin) => void;
74
+ /** Adds a player for a number param. Returns the function that removes it. */
75
+ readonly register: (player: LessonPlayer) => () => void;
76
+ /** Reads saved and linked values once the lesson is on the page, then keeps them current. */
77
+ readonly connect: () => () => void;
78
+ };
79
+ /** The store's opening state, from the lesson and the values, beat and step it is given. */
80
+ export declare function lessonState(options: LessonStoreOptions): LessonStoreState;
81
+ /** The keys the store takes from the options on every render. */
82
+ export declare function lessonSync(options: LessonStoreOptions): Partial<LessonStoreState>;
83
+ /** The store's api, built once per lesson from the primitive's context. */
84
+ export declare function lessonApi(context: PrimitiveContext<LessonStoreOptions, LessonStoreState, 'root'>): LessonApi;
@@ -0,0 +1,39 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { LessonDefinition, LessonParams, ParamValues } from './define-lesson.ts';
3
+ import type { LessonPlaceChangeDetails, LessonPlayingChangeDetails, LessonValuesChangeDetails } from './lesson-store.ts';
4
+ export type LessonProps<Params extends LessonParams, Derived extends string, Beat extends string> = {
5
+ readonly lesson: LessonDefinition<Params, Derived, Beat>;
6
+ /** The locale every value, figure and control of the lesson is written in. */
7
+ readonly locale: string;
8
+ /** The param values the application holds. Names left out keep their defaults. */
9
+ readonly values?: Partial<ParamValues<Params>> | undefined;
10
+ /** The values the lesson opens with, over its declared defaults. `reset` returns to them. */
11
+ readonly defaultValues?: Partial<ParamValues<Params>> | undefined;
12
+ /** Hears every requested change with its reason and source. `details.cancel()` refuses it. */
13
+ readonly onValuesChange?: ((values: ParamValues<Params>, details: LessonValuesChangeDetails) => void) | undefined;
14
+ /** The current beat id, held by the application. */
15
+ readonly beat?: Beat | null | undefined;
16
+ readonly defaultBeat?: Beat | null | undefined;
17
+ readonly onBeatChange?: ((beat: Beat | null, details: LessonPlaceChangeDetails) => void) | undefined;
18
+ /** The reveal step inside the beat, from 0. */
19
+ readonly step?: number | undefined;
20
+ readonly defaultStep?: number | undefined;
21
+ readonly onStepChange?: ((step: number, details: LessonPlaceChangeDetails) => void) | undefined;
22
+ /** Hears a player start (the param's name) or stop (null), with who asked. `details.cancel()` refuses it. */
23
+ readonly onPlayingChange?: ((playing: string | null, details: LessonPlayingChangeDetails) => void) | undefined;
24
+ /** Reads values from the query string once the lesson is on the page, and writes them back as they change. */
25
+ readonly shouldSyncUrl?: boolean | undefined;
26
+ /** Keeps the values in local storage under this key, so they last across visits. */
27
+ readonly storageKey?: string | undefined;
28
+ /** A frozen copy, such as a beat sheet's cell: controls are disabled, and no change, agent action or player runs. */
29
+ readonly isReadOnly?: boolean | undefined;
30
+ /** Steps the markup adds to a beat after its declared reveal steps, by beat id, such as a scrolly's steps. */
31
+ readonly addedSteps?: Readonly<Record<string, number>> | undefined;
32
+ readonly children?: ReactNode;
33
+ };
34
+ /**
35
+ * Holds one lesson's state for everything inside it: prose values, controls, figures, players and agents read and set
36
+ * the same named values. Pass `values` and `onValuesChange` to hold them in the application, or `defaultValues` to let
37
+ * the lesson hold them; beats and reveal steps work the same way. Nested lessons are independent of each other.
38
+ */
39
+ export declare function Lesson<Params extends LessonParams, Derived extends string, Beat extends string>({ lesson, locale, values, defaultValues, onValuesChange, beat, defaultBeat, onBeatChange, step, defaultStep, onStepChange, onPlayingChange, shouldSyncUrl, storageKey, isReadOnly, addedSteps, children, }: LessonProps<Params, Derived, Beat>): ReactNode;
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from 'react';
2
+ export type ParamControlProps = {
3
+ /** The param's name in the lesson. */
4
+ readonly name: string;
5
+ };
6
+ /**
7
+ * A labelled slider for a number param, for a figure's footer or a control panel. A log param slides evenly through
8
+ * each tenfold. It reads and sets the same value as every `Param` and figure of the lesson.
9
+ */
10
+ export declare function ParamSlider({ name }: ParamControlProps): ReactNode;
11
+ /** A labelled segmented control for a choice param with a few options. */
12
+ export declare function ParamChoice({ name }: ParamControlProps): ReactNode;
13
+ /** A labelled switch for a toggle param. */
14
+ export declare function ParamToggle({ name }: ParamControlProps): ReactNode;
@@ -0,0 +1,34 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { LessonParam } from './define-lesson.ts';
3
+ import type { LessonScope } from './lesson-context.ts';
4
+ /** The words a toggle's value reads as in prose. */
5
+ export type ValueLabels = {
6
+ readonly on: string;
7
+ readonly off: string;
8
+ };
9
+ export type ParamProps = {
10
+ /** The param's name in the lesson. */
11
+ readonly name: string;
12
+ };
13
+ export type ValueProps = {
14
+ /** A param's or a derived value's name in the lesson. */
15
+ readonly name: string;
16
+ readonly labels?: Partial<ValueLabels> | undefined;
17
+ };
18
+ /** The param named `name`, or the inline error a part shows when the lesson declares none. */
19
+ export declare function lessonParam(scope: LessonScope, name: string): {
20
+ readonly param: LessonParam;
21
+ } | {
22
+ readonly error: string;
23
+ };
24
+ /**
25
+ * A param inside a sentence that the reader changes in place: a number to drag or step, an option picked from a short
26
+ * list, or a switch. Every other part of the lesson that reads the name follows. A name the lesson lacks shows an
27
+ * inline error; a read-only lesson shows the value as text.
28
+ */
29
+ export declare function Param({ name }: ParamProps): ReactNode;
30
+ /**
31
+ * A param or derived value written in its declared format, inside a sentence. It updates on every change; assistive
32
+ * technology hears it politely once it rests, so a drag or a player does not flood a screen reader.
33
+ */
34
+ export declare function Value({ name, labels }: ValueProps): ReactNode;
@@ -0,0 +1,42 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { NumberParam } from './define-lesson.ts';
3
+ import type { LessonScope } from './lesson-context.ts';
4
+ import type { PlaybackPace, PlayOrigin } from './lesson-player.ts';
5
+ import type { LessonChangeOrigin } from './lesson-store.ts';
6
+ export type PlaybackProps = {
7
+ /** The number param the player moves. */
8
+ readonly name: string;
9
+ /** Where play starts and starts over. Defaults to the param's min. */
10
+ readonly from?: number | undefined;
11
+ /** Where play ends. Defaults to the param's max. */
12
+ readonly to?: number | undefined;
13
+ /** How many steps a second: `fast`, `regular` or `slow`. */
14
+ readonly pace?: PlaybackPace | undefined;
15
+ /** Starts over from `from` at the end instead of stopping there. */
16
+ readonly isLooping?: boolean | undefined;
17
+ };
18
+ /** What `usePlayback` returns: whether the player runs, and the calls that run, stop and move it. */
19
+ export type PlaybackControls = {
20
+ readonly isPlaying: boolean;
21
+ /** Starts playing. At the end it starts over from `from`; with reduced motion it shows the end at once. */
22
+ readonly play: (origin?: PlayOrigin) => void;
23
+ readonly pause: (origin?: PlayOrigin) => void;
24
+ readonly toggle: (origin?: PlayOrigin) => void;
25
+ /** Moves the param by whole steps, within the player's range, and pauses. */
26
+ readonly stepBy: (steps: number, origin?: LessonChangeOrigin) => void;
27
+ /** Moves the param to a value within the player's range, and pauses. */
28
+ readonly seek: (value: number, origin?: LessonChangeOrigin) => void;
29
+ };
30
+ /** The range a player moves its param through: its `from` and `to`, or the param's bounds before it registers. */
31
+ export declare function playerRange(scope: LessonScope, name: string, param: NumberParam): {
32
+ readonly from: number;
33
+ readonly to: number;
34
+ };
35
+ /**
36
+ * Drives a number param over time, one step at a time on the lesson's shared clock: a training step, a token index, a
37
+ * temperature sweep. It renders nothing; a `Transport` or `usePlayback` plays it. It pauses when the tab is hidden or
38
+ * the reader changes the value, and with reduced motion play shows the end at once.
39
+ */
40
+ export declare function Playback({ name, from, to, pace, isLooping }: PlaybackProps): ReactNode;
41
+ /** Plays, pauses and moves the player of a number param in the nearest lesson. */
42
+ export declare function usePlayback(name: string): PlaybackControls;