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

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 (3) hide show
  1. package/README.md +55 -172
  2. package/dist/index.js +2 -7
  3. package/package.json +19 -17
package/README.md CHANGED
@@ -1,47 +1,29 @@
1
1
  # manim-web-questions
2
2
 
3
- Graded interactive [manim-web](https://github.com/maloyan/manim-web) scenes: a
4
- framework-agnostic mount/grade contract, reusable scene families, and an interaction
5
- kit. A **scene** renders to a `<canvas>`, the user manipulates it (drag, click) to
6
- answer, and the host grades it through a typed API — no UI framework required on either
7
- side.
8
-
9
- Published as **`@davidnugent2425/manim-web-questions`** (currently dev prereleases only;
10
- see [Installing](#installing)).
11
-
12
- ## What's here
13
-
14
- - **The scene contract** (`question.ts`) — the typed API an interactive exposes to any
15
- host: `mount(container) → SceneApi` with `checkAnswer(): GradeResult | null`,
16
- `reset()`, `dispose()`, and `getState()`/`onState(cb)` state subscription. A
17
- `GradeResult` (`{ ok, correct? }`) carries correctness only — display wording stays
18
- the host's choice.
19
- - **The scene lifecycle factory** (`interactive-scene.ts`) — owns the build epoch, the
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
- - **Three scene families**, one layer above the factory:
24
- - `drag-target-scene.ts` — drag a vector onto a target (snap-on-release grid, margin
25
- grading, answer reveal), with `decorate`/`reveal` hooks and predicate grading for
26
- open-ended answers;
27
- - `basis-transform-scene.ts` — drag î and ĵ to perform a linear transformation, with
28
- opt-in labels, span parallelogram, and carried vector;
29
- - `polygon-drag-scene.ts` — drag polygon corners, freely or along an L-shaped rail,
30
- with per-corner margin grading.
31
- - **The interaction kit** — the shared building blocks scenes compose: coordinate math,
32
- snapping, grab forgiveness, arrows, async MathTex, rails, targets, answer reveal,
33
- guides, and probes.
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`).
38
-
39
- [CONTEXT.md](CONTEXT.md) holds the module-by-module inventory. The only runtime
40
- dependency is `manim-web`.
41
-
42
- ## Example
43
-
44
- A minimal host mounts a scene and renders its own UI from emitted state:
3
+ Graded interactive [manim-web](https://github.com/maloyan/manim-web) scenes for the browser.
4
+ A scene renders to a `<canvas>`, the reader manipulates it (drag, click) to answer, and the
5
+ host grades it through a small typed API. No UI framework is required on either side, and
6
+ the only runtime dependency is `manim-web`.
7
+
8
+ ## Install
9
+
10
+ > Not on the public registry yet. Once it lands the install line becomes
11
+ > `npm install <FINAL_NPM_PACKAGE_NAME>` and the package page will live at
12
+ > `https://www.npmjs.com/package/<FINAL_NPM_PACKAGE_NAME>`.
13
+
14
+ Development prereleases are published under the `dev` dist-tag (there is no `latest` yet):
15
+
16
+ ```bash
17
+ npm install @davidnugent2425/manim-web-questions@dev
18
+ ```
19
+
20
+ Node 22 or newer (Node 20 reached end of life in April 2026). The published artifact is
21
+ `dist/` (ESM plus type declarations), so any bundler that understands ESM works.
22
+
23
+ ## Use it
24
+
25
+ Pick a scene family, hand it a spec, mount the returned function into an element, and drive
26
+ it through the returned `SceneApi`:
45
27
 
46
28
  ```ts
47
29
  import { createDragTargetScene, type SceneState } from '@davidnugent2425/manim-web-questions';
@@ -56,155 +38,56 @@ const mount = createDragTargetScene({
56
38
  createExtra: () => ({}),
57
39
  });
58
40
 
59
- const api = mount(document.getElementById('scene-container')!);
41
+ const api = mount(document.getElementById('scene')!);
42
+
60
43
  api.onState((state: SceneState) => {
61
- if (state.kind === 'graded') {
62
- showVerdict(state.result.ok); // wording/UI is the host's job
63
- }
44
+ if (state.kind === 'graded') showVerdict(state.result.ok); // wording is yours
64
45
  });
65
46
 
66
47
  checkButton.onclick = () => api.checkAnswer();
67
48
  resetButton.onclick = () => api.reset();
68
49
  ```
69
50
 
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
51
+ That is the whole integration surface. A host supplies a container, controls that call
52
+ `checkAnswer()` / `reset()`, and verdict UI rendered from emitted state. The scene never
53
+ touches DOM outside its container and never decides wording, so grading results carry
54
+ correctness only.
102
55
 
103
- Mount in `onMounted`, dispose in `onBeforeUnmount`, and mirror state into a `ref`:
56
+ Three scene families ship today: dragging one vector onto a target, dragging î and ĵ to
57
+ perform a linear transformation, and dragging polygon corners. Canvas geometry, snapping
58
+ and drag limits are per-scene options, and colors, fonts and arrow styling come from a
59
+ package-wide theme that defaults to the familiar 3b1b look.
104
60
 
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
- ```
61
+ [**Scene families, options and the interaction kit**](src/README.md) covers all of that in
62
+ detail, including a plain-HTML host and a Vue host you can copy.
63
+ [community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes) is a
64
+ full Vue host built on this package, with fourteen lessons of linear-algebra questions. Its
65
+ lesson list, and one of its questions running a scene from here:
133
66
 
134
- [community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes) is
135
- a full Vue host built this way.
67
+ | A host built on this package | One of its graded scenes |
68
+ | ------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
69
+ | ![The community-3b1b-quizzes lesson list, one row per chapter with a poster and a start link](docs/images/quizzes-lessons.webp) | ![The basis vectors dragged to shear a shaded parallelogram over a grid](docs/images/quizzes-interactive.webp) |
136
70
 
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
-
164
- ### Real-world example
165
-
166
- **[community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes)**
167
- is the flagship consumer: a Vue 3 quiz shell with fourteen lessons of linear-algebra
168
- comprehension questions for 3Blue1Brown's catalogue, whose interactive questions are all
169
- built from this package's scene families.
170
-
171
- ## Installing
172
-
173
- Only dev prereleases exist so far, published under the `dev` dist-tag (there is no
174
- `latest` yet):
175
-
176
- ```bash
177
- pnpm add @davidnugent2425/manim-web-questions@dev
178
- ```
179
-
180
- ## Development
71
+ ## Develop
181
72
 
182
73
  ```bash
183
74
  pnpm install
184
75
  pnpm typecheck && pnpm lint && pnpm format:check && pnpm test
185
- pnpm build # dist/index.js + dist/types/
186
- pnpm exec playwright install chromium # once
187
- pnpm test:e2e # browser mechanics suite against the e2e/harness fixtures
188
- npm pack --dry-run
76
+ pnpm build
77
+ pnpm dev # plain HTML page mounting the fixture scenes, http://localhost:8080
189
78
  ```
190
79
 
191
- `pnpm dev` serves the e2e harness (a plain HTML page mounting the fixture scenes) on
192
- http://localhost:8080 for interactive poking.
193
-
194
- CI runs all of these on every push. Publishing is manual and maintainer-only, never CI:
195
- dev prereleases (`0.1.0-dev.N`) go out with `npm publish --tag dev` so nothing lands on
196
- `latest`, and every publish goes to the user-scoped `@davidnugent2425/manim-web-questions`
197
- (the unscoped name is deliberately unclaimed). `prepack` rebuilds `dist/`, and
198
- `publishConfig.access: "public"` is set, so no extra flags are needed.
199
-
200
- ## Supply chain
80
+ `pnpm test:e2e` runs the browser suite in Chromium, see [e2e/README.md](e2e/README.md).
81
+ Dependency installs go through a 7-day release-age gate and a no-downgrade trust policy, and
82
+ skip auto-installing optional peers, all set in `pnpm-workspace.yaml`. CI runs everything above on every push. Publishing is maintainer-only, see
83
+ [RELEASING.md](RELEASING.md).
201
84
 
202
- `pnpm-workspace.yaml` enforces a 7-day `minimumReleaseAge` on dependency versions and a
203
- `no-downgrade` trust policy; see the comments there for the typia pin rationale.
85
+ [CONTRIBUTING.md](CONTRIBUTING.md) has the rules of the road for new scenes, and
86
+ [CONTEXT.md](CONTEXT.md) holds the shared vocabulary.
204
87
 
205
88
  ## Provenance
206
89
 
207
90
  Extracted from
208
- [community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes),
209
- where the layer was built question-by-question; this repository retains that full git
210
- history, so `git log`/`git blame` reach back through the extraction.
91
+ [community-3b1b-quizzes](https://github.com/davidnugent2425/community-3b1b-quizzes), where
92
+ the layer grew question by question. This repository keeps that full git history, so
93
+ `git log` and `git blame` reach back through the extraction.
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Arrow as e, Circle as t, DashedLine as n, Dot as r, Line as i, MathTex as a, NumberPlane as o, PURPLE as s, Polygon as c, Scene as l, VGroup as u, YELLOW as d, makeDraggable as f } from "manim-web";
2
- //#region src/epoch.ts
2
+ // src/epoch.ts
3
3
  var p = () => {
4
4
  let e = 0;
5
5
  return {
@@ -207,11 +207,7 @@ var p = () => {
207
207
  let t = new a(e);
208
208
  return await t.waitForRender(), t;
209
209
  }, F = (e, t, n) => Math.min(n, Math.max(t, e)), I = (e, t) => F(Math.round(e / t.grid) * t.grid, -t.range, t.range), te = (e, t) => Math.abs(e - Math.round(e / t) * t), L = (e, t, n) => [I(e, n), I(t, n)], ne = (e, t) => Math.hypot(e.x - t.x, e.y - t.y), R = (e, t, n) => ne(e, t) <= n, z = (e, t, n, r) => {
210
- if (t) {
211
- e.remove(n), r && e.remove(r);
212
- return;
213
- }
214
- n.setColor(C().palette.wrong), r?.setColor(C().palette.wrong);
210
+ t ? (e.remove(n), r && e.remove(r)) : (n.setColor(C().palette.wrong), r?.setColor(C().palette.wrong));
215
211
  }, B = (e, t) => {
216
212
  e.setColor(C().palette.correct), e.moveTo(t);
217
213
  }, re = (e, t, n) => {
@@ -922,5 +918,4 @@ var p = () => {
922
918
  r?.add(n), r?.render();
923
919
  });
924
920
  };
925
- //#endregion
926
921
  export { v as DEFAULT_FRAME, se as DOT_MARGIN, Q as DRAGGED_VECTOR_LABEL_OFFSET, ce as DRAG_FORGIVENESS, oe as GRID, ue as HINT_LABEL_OPACITY, W as IDENTITY, T as LEGACY_LABEL_SCALE, le as MARGIN, ze as REFERENCE_LABEL_OFFSET, ot as addComponentGuides, j as addGrabForgiveness, Be as applyDraggedVectorLabelOffset, q as applyMatrix, G as basisOf, F as clamp, H as colorOf, ge as composeMatrix, z as consumeOrRedden, M as createArrow, O as createAxisLabels, Re as createBasisTransformScene, p as createBuildEpoch, de as createDragTargetScene, k as createFrameAxisLabels, ee as createFramedScene, _ as createInteractiveScene, E as createNumberPlane, it as createPolygonDragScene, Ve as createReferenceVector, m as createStateMachine, A as createVectorPlaneScene, pe as cross, x as defaultTheme, me as determinant, ne as distance, fe as dot, g as enableTestHook, b as frameMetrics, te as gridError, D as integerRange, Ge as isAtTarget, K as matrixFromBasis, B as migrateLabel, We as projectToRail, he as rank, P as renderMathTex, y as resolveFrame, N as retargetArrow, V as sceneWorldToScreen, ie as screenToWorld, w as setTheme, I as snapCoord, L as snapPoint, C as theme, ae as vectorProbes, R as withinMargin, re as worldToScreen };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davidnugent2425/manim-web-questions",
3
- "version": "0.1.0-dev.2",
3
+ "version": "0.1.0-dev.3",
4
4
  "description": "Graded interactive manim-web scenes: a framework-agnostic mount/grade contract, reusable scene families, and an interaction kit",
5
5
  "keywords": [
6
6
  "manim",
@@ -19,8 +19,9 @@
19
19
  },
20
20
  "homepage": "https://github.com/davidnugent2425/manim-web-questions#readme",
21
21
  "type": "module",
22
+ "packageManager": "pnpm@11.23.0",
22
23
  "engines": {
23
- "node": ">=20"
24
+ "node": ">=22"
24
25
  },
25
26
  "publishConfig": {
26
27
  "access": "public"
@@ -37,23 +38,10 @@
37
38
  "./package.json": "./package.json"
38
39
  },
39
40
  "sideEffects": false,
40
- "dependencies": {
41
- "manim-web": "^0.3.24"
42
- },
43
- "devDependencies": {
44
- "@playwright/test": "^1.62.1",
45
- "@types/node": "^26.2.0",
46
- "eslint": "^10.8.1",
47
- "eslint-config-prettier": "^10.1.8",
48
- "prettier": "^3.9.6",
49
- "typescript": "^5.9.3",
50
- "typescript-eslint": "^8.67.0",
51
- "vite": "^8.2.1",
52
- "vitest": "^4.1.10"
53
- },
54
41
  "scripts": {
55
42
  "build": "vite build && tsc --project tsconfig.build.json",
56
43
  "dev": "vite --config vite.e2e.config.ts",
44
+ "prepack": "pnpm build",
57
45
  "typecheck": "tsc --noEmit -p tsconfig.json",
58
46
  "test": "vitest run",
59
47
  "test:watch": "vitest",
@@ -61,5 +49,19 @@
61
49
  "lint": "eslint .",
62
50
  "format": "prettier --write .",
63
51
  "format:check": "prettier --check ."
52
+ },
53
+ "dependencies": {
54
+ "manim-web": "^0.3.24"
55
+ },
56
+ "devDependencies": {
57
+ "@playwright/test": "^1.65.1",
58
+ "@types/node": "^26.6.6",
59
+ "eslint": "^10.15.0",
60
+ "eslint-config-prettier": "^10.1.8",
61
+ "prettier": "^3.10.1",
62
+ "typescript": "^5.9.3",
63
+ "typescript-eslint": "^8.72.2",
64
+ "vite": "^8.3.8",
65
+ "vitest": "^4.1.12"
64
66
  }
65
- }
67
+ }