@davidnugent2425/manim-web-questions 0.1.0-dev.1 → 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.
- package/README.md +55 -76
- package/dist/index.js +418 -380
- package/dist/types/arrow.d.ts +2 -6
- package/dist/types/basis-transform-scene.d.ts +11 -0
- package/dist/types/drag-target-scene.d.ts +10 -2
- package/dist/types/frame.d.ts +33 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/plane-scene.d.ts +9 -19
- package/dist/types/plane.d.ts +4 -3
- package/dist/types/polygon-drag-scene.d.ts +7 -0
- package/dist/types/reference-vector.d.ts +1 -1
- package/dist/types/theme.d.ts +58 -38
- package/package.json +19 -17
package/dist/types/arrow.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { Arrow, type Vector3Tuple } from 'manim-web';
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
/**
|
|
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;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
|
14
|
-
* is pinned (rather than the library default 14x8) so a plane sized to overrun the
|
|
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
|
-
/**
|
|
19
|
-
|
|
20
|
-
|
|
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>;
|
package/dist/types/plane.d.ts
CHANGED
|
@@ -10,15 +10,16 @@ export interface PlaneConfig {
|
|
|
10
10
|
readonly includeTicks?: boolean;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* NumberPlane styled to the
|
|
14
|
-
* sub-grid,
|
|
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 (
|
|
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;
|
package/dist/types/theme.d.ts
CHANGED
|
@@ -1,47 +1,67 @@
|
|
|
1
|
-
export
|
|
2
|
-
/**
|
|
3
|
-
readonly vector:
|
|
4
|
-
/**
|
|
5
|
-
readonly grid:
|
|
6
|
-
/**
|
|
7
|
-
readonly axis:
|
|
8
|
-
/**
|
|
9
|
-
readonly referenceGrid:
|
|
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:
|
|
12
|
-
/**
|
|
13
|
-
readonly correct:
|
|
14
|
-
/**
|
|
15
|
-
readonly wrong:
|
|
16
|
-
/**
|
|
17
|
-
readonly yellow:
|
|
18
|
-
/**
|
|
19
|
-
readonly purple:
|
|
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
|
|
23
|
-
export
|
|
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:
|
|
25
|
+
readonly axis: number;
|
|
26
26
|
/** The vector label (×1.8 source ≈ 86 → tuned 50). */
|
|
27
|
-
readonly vector:
|
|
27
|
+
readonly vector: number;
|
|
28
28
|
/** Component-guide labels beside dashed answer guides. */
|
|
29
|
-
readonly component:
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
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.
|
|
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": ">=
|
|
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
|
+
}
|