@davidnugent2425/manim-web-questions 0.1.0-dev.0 → 0.1.0-dev.2

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.
package/README.md CHANGED
@@ -17,9 +17,9 @@ see [Installing](#installing)).
17
17
  `GradeResult` (`{ ok, correct? }`) carries correctness only — display wording stays
18
18
  the host's choice.
19
19
  - **The scene lifecycle factory** (`interactive-scene.ts`) — owns the build epoch, the
20
- idle/not-ready/graded state machine, teardown, and a dev-only `window.__test` hook
21
- (stripped from production builds) for driving scenes deterministically in browser
22
- tests.
20
+ idle/not-ready/graded state machine, teardown, and a `window.__test` hook for driving
21
+ scenes deterministically in browser tests — on in dev builds, otherwise off unless a
22
+ consumer opts in with `enableTestHook()`.
23
23
  - **Three scene families**, one layer above the factory:
24
24
  - `drag-target-scene.ts` — drag a vector onto a target (snap-on-release grid, margin
25
25
  grading, answer reveal), with `decorate`/`reveal` hooks and predicate grading for
@@ -31,8 +31,10 @@ see [Installing](#installing)).
31
31
  - **The interaction kit** — the shared building blocks scenes compose: coordinate math,
32
32
  snapping, grab forgiveness, arrows, async MathTex, rails, targets, answer reveal,
33
33
  guides, and probes.
34
- - **Pure helpers and the theme** — margin grading, 2×2 matrix math, the scene state
35
- machine, build epochs, and the faithful 3b1b/manim palette (`theme.ts`).
34
+ - **Pure helpers, the frame, and the theme** — margin grading, 2×2 matrix math, the
35
+ scene state machine, build epochs, the configurable canvas/plane geometry
36
+ (`frame.ts`), and the themable palette/font/arrow styling defaulting to the faithful
37
+ 3b1b/manim look (`theme.ts`).
36
38
 
37
39
  [CONTEXT.md](CONTEXT.md) holds the module-by-module inventory. The only runtime
38
40
  dependency is `manim-web`.
@@ -65,6 +67,100 @@ checkButton.onclick = () => api.checkAnswer();
65
67
  resetButton.onclick = () => api.reset();
66
68
  ```
67
69
 
70
+ ## Hosting
71
+
72
+ A host provides three things: a container element, controls that call the `SceneApi`,
73
+ and verdict UI rendered from emitted `SceneState`. The scene never touches DOM outside
74
+ its container.
75
+
76
+ ### Plain HTML
77
+
78
+ The repo's own e2e harness ([`e2e/harness/`](e2e/harness/)) is a complete plain-HTML
79
+ host — a picker, a mount `<div>`, Check/Reset buttons, and a verdict line. The core of
80
+ it:
81
+
82
+ ```ts
83
+ let api: SceneApi | null = null;
84
+ let unsubscribe: (() => void) | null = null;
85
+
86
+ const show = (state: SceneState): void => {
87
+ verdict.textContent =
88
+ state.kind === 'graded' ? (state.result.ok ? 'Correct!' : 'Not quite.') : '';
89
+ checkButton.disabled = state.kind === 'graded';
90
+ };
91
+
92
+ const mount = (questionMount: QuestionMount): void => {
93
+ unsubscribe?.(); // drop the old subscription first
94
+ api?.dispose(); // then tear the old scene down
95
+ api = questionMount(host);
96
+ unsubscribe = api.onState(show);
97
+ show(api.getState());
98
+ };
99
+ ```
100
+
101
+ ### Vue
102
+
103
+ Mount in `onMounted`, dispose in `onBeforeUnmount`, and mirror state into a `ref`:
104
+
105
+ ```vue
106
+ <script setup lang="ts">
107
+ import { onBeforeUnmount, onMounted, ref } from 'vue';
108
+ import type { QuestionMount, SceneApi, SceneState } from '@davidnugent2425/manim-web-questions';
109
+
110
+ const props = defineProps<{ mount: QuestionMount }>();
111
+ const host = ref<HTMLDivElement | null>(null);
112
+ const state = ref<SceneState>({ kind: 'idle' });
113
+ let api: SceneApi | null = null;
114
+ let unsubscribe: (() => void) | null = null;
115
+
116
+ onMounted(() => {
117
+ api = props.mount(host.value!);
118
+ unsubscribe = api.onState((s) => (state.value = s));
119
+ });
120
+ onBeforeUnmount(() => {
121
+ unsubscribe?.();
122
+ api?.dispose();
123
+ });
124
+ </script>
125
+
126
+ <template>
127
+ <div ref="host" />
128
+ <button :disabled="state.kind === 'graded'" @click="api?.checkAnswer()">Check</button>
129
+ <button @click="api?.reset()">Reset</button>
130
+ <p v-if="state.kind === 'graded'">{{ state.result.ok ? 'Correct!' : 'Not quite.' }}</p>
131
+ </template>
132
+ ```
133
+
134
+ [community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes) is
135
+ a full Vue host built this way.
136
+
137
+ ## Configuration
138
+
139
+ Every scene family renders a 700×440 canvas showing ±6 grid units by default, and each
140
+ spec can override the geometry and its interaction steps:
141
+
142
+ ```ts
143
+ createDragTargetScene({
144
+ // ...
145
+ frame: { width: 440, height: 440, xRange: 4, xLength: 8 }, // FrameConfig, all optional
146
+ snapGrid: 1, // drop snapping step in grid units (default 0.5; basis scenes default 1)
147
+ range: 4, // clamp for drops, in grid units (defaults to the frame's xRange)
148
+ });
149
+
150
+ // Basis-transform scenes clamp per axis instead of a single range:
151
+ // dragLimit: { x: 2, y: 2 } (defaults to bounds derived from the frame).
152
+ ```
153
+
154
+ Styling is a package-level theme: `theme()` returns the active `Theme` (palette, font
155
+ sizes, arrow and faded-grid styling), which defaults to the faithful 3b1b/manim look
156
+ (`defaultTheme`). Override it before mounting; each call starts from the defaults:
157
+
158
+ ```ts
159
+ import { setTheme } from '@davidnugent2425/manim-web-questions';
160
+
161
+ setTheme({ palette: { vector: '#FF00AA', correct: '#00B3B3' } });
162
+ ```
163
+
68
164
  ### Real-world example
69
165
 
70
166
  **[community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes)**