@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.
@@ -1,10 +1,6 @@
1
1
  import { Arrow, type Vector3Tuple } from 'manim-web';
2
- export interface ArrowStyle {
3
- readonly stroke: number;
4
- readonly tipLength: number;
5
- readonly tipWidth: number;
6
- }
7
- /** Create an arrow from `start` to `end` with the faithful 3b1b geometry and color. */
2
+ import { type ArrowStyle } from './theme';
3
+ /** Create an arrow from `start` to `end` with the active theme's geometry and color. */
8
4
  export declare const createArrow: (start: Vector3Tuple, end: Vector3Tuple, style?: ArrowStyle, color?: string) => Arrow;
9
5
  /**
10
6
  * Retarget a follower arrow. MUST use putStartAndEndOn — Arrow renders its shaft AND
@@ -1,3 +1,4 @@
1
+ import { type FrameConfig } from './frame';
1
2
  import { type Matrix2, type Vec2 } from './matrix2';
2
3
  import type { QuestionMount } from './question';
3
4
  /** The basis vectors are always handled as a pair; `Basis<T>` names that pairing. */
@@ -33,5 +34,15 @@ export interface BasisTransformSpec {
33
34
  * default: a bare pair of answer arrows is the norm, and on an open-ended question the
34
35
  * numbers would read as *the* answer. */
35
36
  revealComponents?: boolean;
37
+ /** Canvas and plane geometry; defaults to the stock 700x440 / 8-unit / ±6 frame. */
38
+ frame?: Partial<FrameConfig>;
39
+ /** Snap grid step in grid units; defaults to whole units (1). */
40
+ snapGrid?: number;
41
+ /** Travel bounds in grid units either side of the origin. Defaults to bounds derived
42
+ * from the frame: far enough to reach any on-screen target, never off-canvas. */
43
+ dragLimit?: {
44
+ readonly x: number;
45
+ readonly y: number;
46
+ };
36
47
  }
37
48
  export declare const createBasisTransformScene: (spec: BasisTransformSpec) => QuestionMount;
@@ -2,8 +2,8 @@ import { Arrow, Dot, MathTex, type Draggable, type NumberPlane, type Scene, type
2
2
  import type { Point2 } from './coords';
3
3
  import type { QuestionMount } from './question';
4
4
  import { type SceneCtx } from './interactive-scene';
5
+ import { type FrameConfig } from './frame';
5
6
  export declare const GRID = 0.5;
6
- export declare const RANGE = 6;
7
7
  export declare const DOT_MARGIN = 0.17;
8
8
  export declare const DRAG_FORGIVENESS = 0.5;
9
9
  /** Tolerance in grid units: a 0.17 dot-radius tolerance plus 0.2 slack. */
@@ -52,7 +52,15 @@ export interface DragTargetSpec<Extra> {
52
52
  /** The answer's position in grid units, and where the dot starts (deliberately wrong). */
53
53
  target: readonly [number, number];
54
54
  start: readonly [number, number];
55
- /** Tolerance in grid units; defaults to the shared MARGIN. */
55
+ /** Canvas and plane geometry; defaults to the stock 700x440 / 8-unit / ±6 frame. */
56
+ frame?: Partial<FrameConfig>;
57
+ /** Snap grid step in grid units; defaults to half units (`GRID`, 0.5). */
58
+ snapGrid?: number;
59
+ /** Clamp the dot to ±range grid units; defaults to the frame's x range. */
60
+ range?: number;
61
+ /** Grab-forgiveness radius in world units; defaults to `DRAG_FORGIVENESS` (0.5). */
62
+ dragForgiveness?: number;
63
+ /** Tolerance in grid units; defaults to `MARGIN` (0.37). */
56
64
  margin?: number;
57
65
  /** Accept open-ended answers with a predicate instead of the exact target. */
58
66
  accept?(v: readonly [number, number]): boolean;
@@ -0,0 +1,33 @@
1
+ export interface FrameConfig {
2
+ /** Canvas size in px. */
3
+ readonly width: number;
4
+ readonly height: number;
5
+ /** Camera frame height in world units; width follows the canvas aspect. */
6
+ readonly frameHeight: number;
7
+ /** Grid units either side of the origin along x. */
8
+ readonly xRange: number;
9
+ /** World units the full ±xRange spans. */
10
+ readonly xLength: number;
11
+ }
12
+ /** The stock quiz-canvas frame: 700x440 px, an 8-unit camera frame, ±6 over 13. */
13
+ export declare const DEFAULT_FRAME: FrameConfig;
14
+ /** Fill a spec's partial frame with the stock defaults. */
15
+ export declare const resolveFrame: (frame?: Partial<FrameConfig>) => FrameConfig;
16
+ export interface FrameMetrics {
17
+ /** Camera frame width in world units (frameHeight × canvas aspect). */
18
+ readonly frameWidth: number;
19
+ /** World units per grid unit. */
20
+ readonly unit: number;
21
+ /** Grid rows either side of the origin: enough that the plane still overruns the
22
+ * camera frame vertically at the shared unit. */
23
+ readonly yRange: number;
24
+ /** Grid rows the camera frame shows vertically, to one decimal: enough for a
25
+ * uniformly-scaled plane to cover the frame, and round-ish so its unit ticks stay
26
+ * on screen. */
27
+ readonly plotYRange: number;
28
+ /** Rows the frame shows whole, so no axis label is drawn off-canvas. */
29
+ readonly yLabelRange: number;
30
+ /** Columns the frame shows whole. */
31
+ readonly xLabelRange: number;
32
+ }
33
+ export declare const frameMetrics: (cfg: FrameConfig) => FrameMetrics;
@@ -1,5 +1,6 @@
1
1
  export * from './question';
2
2
  export * from './interactive-scene';
3
+ export * from './frame';
3
4
  export * from './plane-scene';
4
5
  export * from './plane';
5
6
  export * from './drag-target-scene';
@@ -20,7 +20,13 @@ export interface InteractiveSceneParts<Ctx extends SceneCtx> {
20
20
  grade(ctx: Ctx): GradeResult | null;
21
21
  /** Optional per-question resource teardown (runs under the factory's lifecycle). */
22
22
  teardown?(ctx: Ctx): void;
23
- /** Dev/test probe object (browser e2e); stripped from production builds via DEV. */
23
+ /** Dev/test probe object (browser e2e); registered only in dev builds or after
24
+ * `enableTestHook()`. */
24
25
  devHook?(ctx: Ctx): Record<string, unknown>;
25
26
  }
27
+ /** Opt in to `window.__test` probe registration at runtime. Dev builds register the
28
+ * hook unconditionally; a consumer of the packaged build (where `import.meta.env.DEV`
29
+ * has been compiled away) calls this before mounting — typically guarded by its own
30
+ * dev flag — to drive browser e2e against its scenes. */
31
+ export declare const enableTestHook: () => void;
26
32
  export declare const createInteractiveScene: <Ctx extends SceneCtx>(parts: InteractiveSceneParts<Ctx>) => QuestionMount;
@@ -1,33 +1,23 @@
1
1
  import { MathTex, NumberPlane, Scene } from 'manim-web';
2
2
  import type { BuildEpoch } from './epoch';
3
+ import { type FrameConfig } from './frame';
3
4
  export interface VectorPlaneScene {
4
5
  scene: Scene;
5
6
  plane: NumberPlane;
6
7
  origin: [number, number, number];
7
8
  }
8
9
  export interface VectorPlaneSceneOptions {
10
+ readonly frame?: Partial<FrameConfig>;
9
11
  readonly includeTicks?: boolean;
10
12
  readonly includeAxisLabels?: boolean;
11
13
  }
12
14
  /**
13
- * The empty scene every quiz canvas opens with: a fixed 700x440 canvas whose camera frame
14
- * is pinned (rather than the library default 14x8) so a plane sized to overrun the frame is
15
- * clipped edge-to-edge with no letterbox margins.
15
+ * The empty scene every question canvas opens with: a fixed-size canvas whose camera
16
+ * frame is pinned (rather than the library default 14x8) so a plane sized to overrun the
17
+ * frame is clipped edge-to-edge with no letterbox margins.
16
18
  */
17
- export declare const createFramedScene: (container: HTMLElement) => Scene;
18
- /** The camera frame's aspect, for planes that must be scaled uniformly across both axes. */
19
- export declare const FRAME: {
20
- readonly height: 8;
21
- readonly width: number;
22
- };
23
- /** The x-axis fixes the world-units-per-grid-unit scale every plane shares; a plane sizes its
24
- * y-axis by reusing `unit`, so a grid cell is a square. */
25
- export declare const PLANE_SCALE: {
26
- readonly xRange: 6;
27
- readonly xLength: 13;
28
- readonly unit: number;
29
- };
30
- /** Integer labels along both axes of a plane at the shared unit scale, limited to what the
31
- * camera frame shows whole. */
32
- export declare const createFrameAxisLabels: (plane: NumberPlane) => Promise<MathTex[]>;
19
+ export declare const createFramedScene: (container: HTMLElement, frame: FrameConfig) => Scene;
20
+ /** Integer labels along both axes of a plane at the frame's unit scale, limited to what
21
+ * the camera frame shows whole. */
22
+ export declare const createFrameAxisLabels: (plane: NumberPlane, frame: FrameConfig) => Promise<MathTex[]>;
33
23
  export declare const createVectorPlaneScene: (container: HTMLElement, epoch: BuildEpoch, token: number, options?: VectorPlaneSceneOptions) => Promise<VectorPlaneScene | null>;
@@ -10,15 +10,16 @@ export interface PlaneConfig {
10
10
  readonly includeTicks?: boolean;
11
11
  }
12
12
  /**
13
- * NumberPlane styled to the faithful 3b1b look: BLUE_D grid lines, a faded 0.5
14
- * sub-grid, LIGHT_GREY axes with optional tick marks, and axes that overrun the visible frame.
13
+ * NumberPlane styled to the active theme (the default is the faithful 3b1b look):
14
+ * themed grid lines, a faded 0.5 sub-grid, themed axes with optional tick marks, and
15
+ * axes that overrun the visible frame.
15
16
  */
16
17
  export declare const createNumberPlane: (cfg: PlaneConfig) => NumberPlane;
17
18
  /** Build an integer sequence from start..end inclusive with the given step, never
18
19
  * including zero (the origin on a symmetric axis is not labelled). */
19
20
  export declare const integerRange: (from: number, to: number, step?: number) => number[];
20
21
  /**
21
- * Place integer tick labels along the x- and y-axes (white, FONT.axis), positioned
22
+ * Place integer tick labels along the x- and y-axes (themed color and size), positioned
22
23
  * just off each axis. Labels are awaited (rendered) before being returned.
23
24
  */
24
25
  export declare const createAxisLabels: (plane: NumberPlane, xs: readonly number[], ys: readonly number[]) => Promise<MathTex[]>;
@@ -1,4 +1,5 @@
1
1
  import type { QuestionMount } from './question';
2
+ import { type FrameConfig } from './frame';
2
3
  import type { Vec2 } from './matrix2';
3
4
  /** The polygon's corners in drawing order, in grid units. */
4
5
  export type PolygonCorners = readonly Vec2[];
@@ -28,6 +29,12 @@ export interface PolygonDragSpec {
28
29
  /** The polygon's corners in drawing order. */
29
30
  vertices: readonly PolygonVertexSpec[];
30
31
  arrows: readonly PolygonArrowSpec[];
32
+ /** Canvas and plane geometry; defaults to the stock 700x440 / 8-unit / ±6 frame. */
33
+ frame?: Partial<FrameConfig>;
34
+ /** Snap grid step in grid units; defaults to half units (0.5). */
35
+ snapGrid?: number;
36
+ /** Clamp corners (and end rails) at ±range grid units; defaults to the frame's x range. */
37
+ range?: number;
31
38
  }
32
39
  export declare const createPolygonDragScene: (spec: PolygonDragSpec) => QuestionMount;
33
40
  export {};
@@ -1,6 +1,6 @@
1
1
  import { type Arrow, type MathTex, type NumberPlane, type Scene, type Vector3Tuple } from 'manim-web';
2
- import { type ArrowStyle } from './arrow';
3
2
  import type { Vec2 } from './matrix2';
3
+ import { type ArrowStyle } from './theme';
4
4
  export declare const REFERENCE_LABEL_OFFSET: Vec2;
5
5
  export declare const DRAGGED_VECTOR_LABEL_OFFSET: Vec2;
6
6
  export declare const applyDraggedVectorLabelOffset: (tip: readonly [number, number]) => Vector3Tuple;
@@ -1,47 +1,67 @@
1
- export declare const PALETTE: {
2
- /** Manim BLUE_C — the interactive vector (dot / arrow / vector label). */
3
- readonly vector: "#58C4DD";
4
- /** Manim BLUE_D — numberplane grid lines. */
5
- readonly grid: "#29ABCA";
6
- /** Manim LIGHT_GREY — axes + tick marks. */
7
- readonly axis: "#BBBBBB";
8
- /** Manim GREY — the static reference grid a transformed grid moves away from. */
9
- readonly referenceGrid: "#888888";
1
+ export interface Palette {
2
+ /** The interactive vector (dot / arrow / vector label). Default manim BLUE_C. */
3
+ readonly vector: string;
4
+ /** Numberplane grid lines. Default manim BLUE_D. */
5
+ readonly grid: string;
6
+ /** Axes + tick marks. Default manim LIGHT_GREY. */
7
+ readonly axis: string;
8
+ /** The static reference grid a transformed grid moves away from. Default manim GREY. */
9
+ readonly referenceGrid: string;
10
10
  /** Axis integer labels. */
11
- readonly axisLabel: "#FFFFFF";
12
- /** Manim GREEN_C — the correct answer / feedback. */
13
- readonly correct: "#83C167";
14
- /** Manim RED_C — a wrong answer. */
15
- readonly wrong: "#FC6255";
16
- /** Manim YELLOW_C — an input vector (e.g. v̂ in vector addition). */
17
- readonly yellow: "#FFFF00";
18
- /** Manim PURPLE_C — an input vector (e.g. ŵ in vector addition). */
19
- readonly purple: "#9A72AC";
20
- };
11
+ readonly axisLabel: string;
12
+ /** The correct answer / feedback. Default manim GREEN_C. */
13
+ readonly correct: string;
14
+ /** A wrong answer. Default manim RED_C. */
15
+ readonly wrong: string;
16
+ /** An input vector (e.g. v̂ in vector addition). Default manim YELLOW_C. */
17
+ readonly yellow: string;
18
+ /** An input vector (e.g. ŵ in vector addition). Default manim PURPLE_C. */
19
+ readonly purple: string;
20
+ }
21
21
  /** MathTex font sizes. maloyan default ≈48pt; the source scene scaled to 1.3×/1.8×
22
- * and these were tuned down for visual parity. */
23
- export declare const FONT: {
22
+ * and the defaults were tuned down for visual parity. */
23
+ export interface FontSizes {
24
24
  /** Axis integer labels (×1.3 source ≈ 62 → tuned 40). */
25
- readonly axis: 40;
25
+ readonly axis: number;
26
26
  /** The vector label (×1.8 source ≈ 86 → tuned 50). */
27
- readonly vector: 50;
27
+ readonly vector: number;
28
28
  /** Component-guide labels beside dashed answer guides. */
29
- readonly component: 34;
30
- };
31
- /** Legacy reference labels were scaled 2:1.5; these values rebase that ratio on FONT.vector. */
29
+ readonly component: number;
30
+ }
31
+ /** Arrow geometry. Note maloyan `tipWidth` is a HALF-width, so 0.175 == full 0.35. */
32
+ export interface ArrowStyle {
33
+ readonly stroke: number;
34
+ readonly tipLength: number;
35
+ readonly tipWidth: number;
36
+ }
37
+ /** The faded 0.5 sub-grid. A 0.5 opacity reads slightly faint in maloyan, so the
38
+ * defaults are nudged a touch stronger. */
39
+ export interface FadedGridStyle {
40
+ readonly opacity: number;
41
+ readonly stroke: number;
42
+ }
43
+ export interface Theme {
44
+ readonly palette: Palette;
45
+ readonly font: FontSizes;
46
+ readonly arrow: ArrowStyle;
47
+ readonly fadedGrid: FadedGridStyle;
48
+ }
49
+ /** Per-section partial: override only the keys a host cares about. */
50
+ export interface ThemeOverrides {
51
+ readonly palette?: Partial<Palette>;
52
+ readonly font?: Partial<FontSizes>;
53
+ readonly arrow?: Partial<ArrowStyle>;
54
+ readonly fadedGrid?: Partial<FadedGridStyle>;
55
+ }
56
+ /** The faithful 3Blue1Brown / Manim look. */
57
+ export declare const defaultTheme: Theme;
58
+ /** The active theme. Scenes read it at draw time, so set the theme before mounting. */
59
+ export declare const theme: () => Theme;
60
+ /** Apply `overrides` over the default theme (not over a previous override). */
61
+ export declare const setTheme: (overrides: ThemeOverrides) => void;
62
+ /** Legacy reference labels were scaled 2:1.5; these values rebase that ratio on
63
+ * `font.vector`. */
32
64
  export declare const LEGACY_LABEL_SCALE: {
33
65
  readonly basis: 1;
34
66
  readonly vector: number;
35
67
  };
36
- /** Arrow geometry. Note maloyan `tipWidth` is a HALF-width, so 0.175 == full 0.35. */
37
- export declare const ARROW: {
38
- readonly stroke: 5;
39
- readonly tipLength: 0.35;
40
- readonly tipWidth: 0.175;
41
- };
42
- /** The faded 0.5 sub-grid. A 0.5 opacity reads slightly faint in maloyan, so these
43
- * are nudged a touch stronger. */
44
- export declare const FADED_GRID: {
45
- readonly opacity: 0.7;
46
- readonly stroke: 0.75;
47
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@davidnugent2425/manim-web-questions",
3
- "version": "0.1.0-dev.0",
3
+ "version": "0.1.0-dev.2",
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",