@davidnugent2425/manim-web-questions 0.1.0-dev.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.
- package/README.md +114 -0
- package/dist/index.js +877 -0
- package/dist/types/answer-reveal.d.ts +10 -0
- package/dist/types/arrow.d.ts +14 -0
- package/dist/types/basis-transform-scene.d.ts +37 -0
- package/dist/types/component-guides.d.ts +16 -0
- package/dist/types/coords.d.ts +32 -0
- package/dist/types/drag-target-scene.d.ts +82 -0
- package/dist/types/epoch.d.ts +9 -0
- package/dist/types/grab.d.ts +10 -0
- package/dist/types/grade.d.ts +5 -0
- package/dist/types/index.d.ts +23 -0
- package/dist/types/interactive-scene.d.ts +26 -0
- package/dist/types/mathtex.d.ts +6 -0
- package/dist/types/matrix2.d.ts +27 -0
- package/dist/types/plane-scene.d.ts +33 -0
- package/dist/types/plane.d.ts +24 -0
- package/dist/types/polygon-drag-scene.d.ts +33 -0
- package/dist/types/question.d.ts +35 -0
- package/dist/types/rails.d.ts +6 -0
- package/dist/types/reference-vector.d.ts +19 -0
- package/dist/types/snapping.d.ts +14 -0
- package/dist/types/state.d.ts +8 -0
- package/dist/types/target.d.ts +2 -0
- package/dist/types/theme.d.ts +47 -0
- package/dist/types/vector-probes.d.ts +57 -0
- package/package.json +65 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MathTex, Mobject, Scene, Vector3Tuple } from 'manim-web';
|
|
2
|
+
/** A correct answer is consumed — the green answer arrow replaces it — while a wrong one
|
|
3
|
+
* stays where the user dropped it, recolored red. */
|
|
4
|
+
export declare const consumeOrRedden: (scene: Scene, ok: boolean, dot: Mobject & {
|
|
5
|
+
setColor(color: string): unknown;
|
|
6
|
+
}, arrow?: Mobject & {
|
|
7
|
+
setColor(color: string): unknown;
|
|
8
|
+
}) => void;
|
|
9
|
+
/** A label ALWAYS migrates to its green answer and turns green, right or wrong. */
|
|
10
|
+
export declare const migrateLabel: (label: MathTex, to: Vector3Tuple) => void;
|
|
@@ -0,0 +1,14 @@
|
|
|
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. */
|
|
8
|
+
export declare const createArrow: (start: Vector3Tuple, end: Vector3Tuple, style?: ArrowStyle, color?: string) => Arrow;
|
|
9
|
+
/**
|
|
10
|
+
* Retarget a follower arrow. MUST use putStartAndEndOn — Arrow renders its shaft AND
|
|
11
|
+
* tip as children, so `become()` only copies base-point geometry and the arrowhead
|
|
12
|
+
* would stay frozen at its old position. putStartAndEndOn regenerates both.
|
|
13
|
+
*/
|
|
14
|
+
export declare const retargetArrow: (arrow: Arrow, start: Vector3Tuple, end: Vector3Tuple) => void;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type Matrix2, type Vec2 } from './matrix2';
|
|
2
|
+
import type { QuestionMount } from './question';
|
|
3
|
+
/** The basis vectors are always handled as a pair; `Basis<T>` names that pairing. */
|
|
4
|
+
export interface Basis<T> {
|
|
5
|
+
i: T;
|
|
6
|
+
j: T;
|
|
7
|
+
}
|
|
8
|
+
export interface BasisTransformSpec {
|
|
9
|
+
/** Scene name reported by the dev-only `window.__test.question` probe. */
|
|
10
|
+
question: string;
|
|
11
|
+
/** The transformation the user must build by placing î and ĵ. */
|
|
12
|
+
target: Matrix2;
|
|
13
|
+
/** Accept open-ended matrices with a predicate instead of the exact target. */
|
|
14
|
+
accept?(m: Matrix2): boolean;
|
|
15
|
+
/** Name the two vectors something other than î and ĵ, for questions where the pair is
|
|
16
|
+
* not a basis (a pair of vectors whose cross product the reader is aiming at). */
|
|
17
|
+
labels?: Basis<string>;
|
|
18
|
+
/** Draw the live blue grid the pair transforms. On by default; off for questions about
|
|
19
|
+
* the two vectors themselves, where a transforming grid would imply they are a basis. */
|
|
20
|
+
liveGrid?: boolean;
|
|
21
|
+
/** Number the axes, for a question read as positions on a fixed plane rather than as a
|
|
22
|
+
* transformation of the space. Off by default: under a live grid the numbers would sit
|
|
23
|
+
* on a grid that has moved away from them. */
|
|
24
|
+
axisNumbers?: boolean;
|
|
25
|
+
/** Shade the parallelogram the pair spans — the area their cross product measures. */
|
|
26
|
+
spanPolygon?: boolean;
|
|
27
|
+
/** Carry a fixed input vector through the user's transformation, drawn as it lands. */
|
|
28
|
+
trackVector?: {
|
|
29
|
+
grid: Vec2;
|
|
30
|
+
latex: string;
|
|
31
|
+
};
|
|
32
|
+
/** Spell the revealed answer out in dashed guides labelled with its components. Off by
|
|
33
|
+
* default: a bare pair of answer arrows is the norm, and on an open-ended question the
|
|
34
|
+
* numbers would read as *the* answer. */
|
|
35
|
+
revealComponents?: boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare const createBasisTransformScene: (spec: BasisTransformSpec) => QuestionMount;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type NumberPlane, type Scene, type Vector3Tuple } from 'manim-web';
|
|
2
|
+
export interface ComponentGuidesOptions {
|
|
3
|
+
scene: Scene;
|
|
4
|
+
plane: NumberPlane;
|
|
5
|
+
origin: Vector3Tuple;
|
|
6
|
+
/** The answer arrow's tip, in world units. */
|
|
7
|
+
tip: Vector3Tuple;
|
|
8
|
+
/** The answer vector in grid units, whose components label the guides. */
|
|
9
|
+
vector: readonly [number, number];
|
|
10
|
+
/** Which side each label sits on (a manim direction such as `DOWN`): the x guide's, then
|
|
11
|
+
* the y guide's. */
|
|
12
|
+
labelDirections: readonly [Vector3Tuple, Vector3Tuple];
|
|
13
|
+
/** The scene as of label-render time, or null once it has been torn down. */
|
|
14
|
+
liveScene(): Scene | null;
|
|
15
|
+
}
|
|
16
|
+
export declare const addComponentGuides: ({ scene, plane, origin, tip, vector, labelDirections, liveScene, }: ComponentGuidesOptions) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Scene } from 'manim-web';
|
|
2
|
+
export interface CameraFrame {
|
|
3
|
+
/** Camera's visible WORLD width (scene.camera.frameWidth). */
|
|
4
|
+
readonly frameWidth: number;
|
|
5
|
+
/** Camera's visible WORLD height (scene.camera.frameHeight). */
|
|
6
|
+
readonly frameHeight: number;
|
|
7
|
+
}
|
|
8
|
+
/** Bounding client rect of the interactive `<canvas>` in page pixels. */
|
|
9
|
+
export interface Rect {
|
|
10
|
+
readonly left: number;
|
|
11
|
+
readonly top: number;
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly height: number;
|
|
14
|
+
}
|
|
15
|
+
export interface Point2 {
|
|
16
|
+
readonly x: number;
|
|
17
|
+
readonly y: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Map a world coordinate to page-pixel screen coordinates.
|
|
21
|
+
* This is the exact inverse of maloyan's Draggable._screenToWorld (frameWidth/Height
|
|
22
|
+
* in 2D, y flipped).
|
|
23
|
+
*/
|
|
24
|
+
export declare const worldToScreen: (world: Point2, frame: CameraFrame, rect: Rect) => Point2;
|
|
25
|
+
/** Inverse of worldToScreen: page-pixel → world coordinate. */
|
|
26
|
+
export declare const screenToWorld: (screen: Point2, frame: CameraFrame, rect: Rect) => Point2;
|
|
27
|
+
/**
|
|
28
|
+
* Map a world point to page-pixel screen coordinates, reading the camera frame and
|
|
29
|
+
* canvas rect off a live scene. Reuses the pure `worldToScreen` camera math. Returns
|
|
30
|
+
* null when the scene has no attached canvas (e.g. before it has mounted).
|
|
31
|
+
*/
|
|
32
|
+
export declare const sceneWorldToScreen: (scene: Scene, wx: number, wy: number) => Point2 | null;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Arrow, Dot, MathTex, type Draggable, type NumberPlane, type Scene, type Vector3Tuple } from 'manim-web';
|
|
2
|
+
import type { Point2 } from './coords';
|
|
3
|
+
import type { QuestionMount } from './question';
|
|
4
|
+
import { type SceneCtx } from './interactive-scene';
|
|
5
|
+
export declare const GRID = 0.5;
|
|
6
|
+
export declare const RANGE = 6;
|
|
7
|
+
export declare const DOT_MARGIN = 0.17;
|
|
8
|
+
export declare const DRAG_FORGIVENESS = 0.5;
|
|
9
|
+
/** Tolerance in grid units: a 0.17 dot-radius tolerance plus 0.2 slack. */
|
|
10
|
+
export declare const MARGIN = 0.37;
|
|
11
|
+
/** Filled text reads stronger than a stroked line, so hint labels stay above their arrows. */
|
|
12
|
+
export declare const HINT_LABEL_OPACITY = 0.7;
|
|
13
|
+
/** The live scene state, shared by the hooks and the dev probes. `extra` is whatever the
|
|
14
|
+
* question needs to keep across build → grade → teardown (its own arrows, counters). */
|
|
15
|
+
export interface DragTargetCtx<Extra> extends SceneCtx {
|
|
16
|
+
scene: Scene | null;
|
|
17
|
+
dragger: Draggable | null;
|
|
18
|
+
plane: NumberPlane | null;
|
|
19
|
+
/** The user's draggable answer dot, optional tailing arrow, and floating label. */
|
|
20
|
+
dot: Dot | null;
|
|
21
|
+
arrow: Arrow | null;
|
|
22
|
+
label: MathTex | null;
|
|
23
|
+
/** False after a correct answer consumes the user's dot and optional arrow. */
|
|
24
|
+
answerVisible: boolean;
|
|
25
|
+
/** Whether the label is on screen: a question can hold it back until the reveal. */
|
|
26
|
+
labelVisible: boolean;
|
|
27
|
+
/** The answer position used for the latest reveal, if grading has happened. */
|
|
28
|
+
revealed: readonly [number, number] | null;
|
|
29
|
+
extra: Extra;
|
|
30
|
+
}
|
|
31
|
+
/** What a question's `decorate` hook gets: the built plane plus the epoch guard it must
|
|
32
|
+
* re-check after every await, since a reset/dispose can supersede a build mid-flight. */
|
|
33
|
+
export interface DecorateEnv {
|
|
34
|
+
scene: Scene;
|
|
35
|
+
plane: NumberPlane;
|
|
36
|
+
origin: Vector3Tuple;
|
|
37
|
+
/** Dot radius in world units, so decorations can size themselves to the answer dot. */
|
|
38
|
+
dotRadius: number;
|
|
39
|
+
isCurrent(): boolean;
|
|
40
|
+
}
|
|
41
|
+
/** What a question's `reveal` hook gets: the graded scene plus the answer's world tip. */
|
|
42
|
+
export interface RevealEnv {
|
|
43
|
+
scene: Scene;
|
|
44
|
+
plane: NumberPlane;
|
|
45
|
+
origin: Vector3Tuple;
|
|
46
|
+
correctTip: Vector3Tuple;
|
|
47
|
+
ok: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface DragTargetSpec<Extra> {
|
|
50
|
+
/** Scene name reported by the dev-only `window.__test.question` probe. */
|
|
51
|
+
question: string;
|
|
52
|
+
/** The answer's position in grid units, and where the dot starts (deliberately wrong). */
|
|
53
|
+
target: readonly [number, number];
|
|
54
|
+
start: readonly [number, number];
|
|
55
|
+
/** Tolerance in grid units; defaults to the shared MARGIN. */
|
|
56
|
+
margin?: number;
|
|
57
|
+
/** Accept open-ended answers with a predicate instead of the exact target. */
|
|
58
|
+
accept?(v: readonly [number, number]): boolean;
|
|
59
|
+
/** Constrain the draggable answer to the x-axis. */
|
|
60
|
+
axis?: 'x';
|
|
61
|
+
/** Whether to show the arrow tailing the draggable answer. */
|
|
62
|
+
arrow?: boolean;
|
|
63
|
+
/** The label that hugs the draggable dot, and where it sits relative to it. */
|
|
64
|
+
labelLatex: string;
|
|
65
|
+
labelPoint(dot: Point2): Vector3Tuple;
|
|
66
|
+
/** Keep the label off screen until grading reveals the answer, for a question where the
|
|
67
|
+
* label IS the answer. Off by default: the label names the vector being dragged. */
|
|
68
|
+
hideLabelUntilReveal?: boolean;
|
|
69
|
+
/** Where that label migrates to once graded, given the green answer arrow's tip. */
|
|
70
|
+
gradedLabelPoint(correctTip: Vector3Tuple): Vector3Tuple;
|
|
71
|
+
/** Fresh per-mount question state (arrows, counters) exposed to the hooks as `extra`. */
|
|
72
|
+
createExtra(): Extra;
|
|
73
|
+
/** Draw the question's fixed content, before the draggable answer goes on top. */
|
|
74
|
+
decorate?(ctx: DragTargetCtx<Extra>, env: DecorateEnv): Promise<void>;
|
|
75
|
+
/** Draw the question's answer reveal (hints, guides), before the green answer arrow. */
|
|
76
|
+
reveal?(ctx: DragTargetCtx<Extra>, env: RevealEnv): void;
|
|
77
|
+
/** Reset `extra` back to its fresh state on teardown. */
|
|
78
|
+
resetExtra?(extra: Extra): void;
|
|
79
|
+
/** Question-specific dev probes, merged into the standard vector probe set. */
|
|
80
|
+
probes?(ctx: DragTargetCtx<Extra>): Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
export declare const createDragTargetScene: <Extra>(spec: DragTargetSpec<Extra>) => QuestionMount;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface BuildEpoch {
|
|
2
|
+
/** Start a new build; returns the token the caller must re-check after each await. */
|
|
3
|
+
begin(): number;
|
|
4
|
+
/** Invalidate any currently in-flight build (call from teardown before nulling ctx). */
|
|
5
|
+
supersede(): void;
|
|
6
|
+
/** True while `token` is still current, i.e. the build still owns the scene. */
|
|
7
|
+
isCurrent(token: number): boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare const createBuildEpoch: () => BuildEpoch;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Mobject } from 'manim-web';
|
|
2
|
+
/**
|
|
3
|
+
* Widen a draggable mobject's grab area with an invisible concentric circle so a drag
|
|
4
|
+
* starts within `forgiveness` world units of it (matching the scene's relaxed grab
|
|
5
|
+
* `isInside(buff: 0.5)`), rather than only its exact bounding box.
|
|
6
|
+
*
|
|
7
|
+
* The circle must keep SOME geometry (nonzero strokeWidth) or getBoundingBoxImpl
|
|
8
|
+
* won't count it; the stroke is then hidden with setStrokeOpacity(0) so nothing renders.
|
|
9
|
+
*/
|
|
10
|
+
export declare const addGrabForgiveness: (target: Mobject, radius: number, forgiveness: number) => void;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Point2 } from './coords';
|
|
2
|
+
/** Euclidean distance between two grid-space points. */
|
|
3
|
+
export declare const distance: (a: Point2, b: Point2) => number;
|
|
4
|
+
/** True when a user answer lies within `margin` grid-units of the target. */
|
|
5
|
+
export declare const withinMargin: (user: Point2, target: Point2, margin: number) => boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './question';
|
|
2
|
+
export * from './interactive-scene';
|
|
3
|
+
export * from './plane-scene';
|
|
4
|
+
export * from './plane';
|
|
5
|
+
export * from './drag-target-scene';
|
|
6
|
+
export * from './basis-transform-scene';
|
|
7
|
+
export * from './polygon-drag-scene';
|
|
8
|
+
export * from './coords';
|
|
9
|
+
export * from './snapping';
|
|
10
|
+
export * from './grab';
|
|
11
|
+
export * from './arrow';
|
|
12
|
+
export * from './mathtex';
|
|
13
|
+
export * from './rails';
|
|
14
|
+
export * from './target';
|
|
15
|
+
export * from './answer-reveal';
|
|
16
|
+
export * from './component-guides';
|
|
17
|
+
export * from './reference-vector';
|
|
18
|
+
export * from './vector-probes';
|
|
19
|
+
export * from './grade';
|
|
20
|
+
export * from './matrix2';
|
|
21
|
+
export * from './state';
|
|
22
|
+
export * from './epoch';
|
|
23
|
+
export * from './theme';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type BuildEpoch } from './epoch';
|
|
2
|
+
import type { GradeResult, QuestionMount } from './question';
|
|
3
|
+
/** The small slice of a scene context the factory touches (scene + dragger disposal). */
|
|
4
|
+
export interface SceneCtx {
|
|
5
|
+
scene: {
|
|
6
|
+
dispose(): void;
|
|
7
|
+
} | null;
|
|
8
|
+
dragger: {
|
|
9
|
+
dispose(): void;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
12
|
+
/** Per-question parts the factory composes into a self-contained `QuestionMount`. */
|
|
13
|
+
export interface InteractiveSceneParts<Ctx extends SceneCtx> {
|
|
14
|
+
/** Fresh per-mount context (fields start null / empty, as today). */
|
|
15
|
+
createCtx(): Ctx;
|
|
16
|
+
/** Rebuild the scene into `container`. Honor the epoch guard between awaits. */
|
|
17
|
+
build(ctx: Ctx, container: HTMLElement, epoch: BuildEpoch): Promise<void>;
|
|
18
|
+
/** Grade the current answer; locks interaction and returns the verdict, or `null` when
|
|
19
|
+
* the async build has not finished and there is nothing to grade. */
|
|
20
|
+
grade(ctx: Ctx): GradeResult | null;
|
|
21
|
+
/** Optional per-question resource teardown (runs under the factory's lifecycle). */
|
|
22
|
+
teardown?(ctx: Ctx): void;
|
|
23
|
+
/** Dev/test probe object (browser e2e); stripped from production builds via DEV. */
|
|
24
|
+
devHook?(ctx: Ctx): Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export declare const createInteractiveScene: <Ctx extends SceneCtx>(parts: InteractiveSceneParts<Ctx>) => QuestionMount;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MathTex, type MathTexOptions } from 'manim-web';
|
|
2
|
+
/**
|
|
3
|
+
* Create a MathTex and await its async glyph render before returning. MathTex renders
|
|
4
|
+
* lazily via MathJax, so awaiting waitForRender() avoids empty text on the first frame.
|
|
5
|
+
*/
|
|
6
|
+
export declare const renderMathTex: (opts: MathTexOptions) => Promise<MathTex>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A vector in grid units. */
|
|
2
|
+
export type Vec2 = readonly [number, number];
|
|
3
|
+
/** A 2x2 matrix in row-major order, `[[a, b], [c, d]]`: column 1 is where î lands,
|
|
4
|
+
* column 2 is where ĵ lands. */
|
|
5
|
+
export type Matrix2 = readonly [Vec2, Vec2];
|
|
6
|
+
/** The transformation that leaves every vector where it is. */
|
|
7
|
+
export declare const IDENTITY: Matrix2;
|
|
8
|
+
/** Dot product of two vectors. */
|
|
9
|
+
export declare const dot: (a: Vec2, b: Vec2) => number;
|
|
10
|
+
/** The 2D cross product `a x b`: the signed area of the parallelogram they span, positive
|
|
11
|
+
* when `b` is counter-clockwise of `a`. */
|
|
12
|
+
export declare const cross: (a: Vec2, b: Vec2) => number;
|
|
13
|
+
/** Determinant of a 2x2 matrix. */
|
|
14
|
+
export declare const determinant: (m: Matrix2) => number;
|
|
15
|
+
/** Rank of a 2x2 matrix, treating determinant-sized values within `tol` as singular. */
|
|
16
|
+
export declare const rank: (m: Matrix2, tol?: number) => 0 | 1 | 2;
|
|
17
|
+
/** Where the basis vectors land under `m` (its columns). */
|
|
18
|
+
export declare const basisOf: (m: Matrix2) => {
|
|
19
|
+
i: Vec2;
|
|
20
|
+
j: Vec2;
|
|
21
|
+
};
|
|
22
|
+
/** The transformation that lands î on `i` and ĵ on `j`. */
|
|
23
|
+
export declare const matrixFromBasis: (i: Vec2, j: Vec2) => Matrix2;
|
|
24
|
+
/** Transform `v` by `m`. */
|
|
25
|
+
export declare const applyMatrix: (m: Matrix2, v: Vec2) => Vec2;
|
|
26
|
+
/** The composition `a · b`: the single transformation that applies `b` first, then `a`. */
|
|
27
|
+
export declare const composeMatrix: (a: Matrix2, b: Matrix2) => Matrix2;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MathTex, NumberPlane, Scene } from 'manim-web';
|
|
2
|
+
import type { BuildEpoch } from './epoch';
|
|
3
|
+
export interface VectorPlaneScene {
|
|
4
|
+
scene: Scene;
|
|
5
|
+
plane: NumberPlane;
|
|
6
|
+
origin: [number, number, number];
|
|
7
|
+
}
|
|
8
|
+
export interface VectorPlaneSceneOptions {
|
|
9
|
+
readonly includeTicks?: boolean;
|
|
10
|
+
readonly includeAxisLabels?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
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.
|
|
16
|
+
*/
|
|
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[]>;
|
|
33
|
+
export declare const createVectorPlaneScene: (container: HTMLElement, epoch: BuildEpoch, token: number, options?: VectorPlaneSceneOptions) => Promise<VectorPlaneScene | null>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { MathTex, NumberPlane } from 'manim-web';
|
|
2
|
+
export interface PlaneConfig {
|
|
3
|
+
/** Visible axis ranges with a unit-1 step, e.g. [-6, 6, 1]. */
|
|
4
|
+
readonly xRange: readonly [number, number, number];
|
|
5
|
+
readonly yRange: readonly [number, number, number];
|
|
6
|
+
/** Axis lengths in world units; size each to overrun its visible edge so the axis
|
|
7
|
+
* is clipped at the frame border rather than visibly ending mid-frame. */
|
|
8
|
+
readonly xLength: number;
|
|
9
|
+
readonly yLength: number;
|
|
10
|
+
readonly includeTicks?: boolean;
|
|
11
|
+
}
|
|
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.
|
|
15
|
+
*/
|
|
16
|
+
export declare const createNumberPlane: (cfg: PlaneConfig) => NumberPlane;
|
|
17
|
+
/** Build an integer sequence from start..end inclusive with the given step, never
|
|
18
|
+
* including zero (the origin on a symmetric axis is not labelled). */
|
|
19
|
+
export declare const integerRange: (from: number, to: number, step?: number) => number[];
|
|
20
|
+
/**
|
|
21
|
+
* Place integer tick labels along the x- and y-axes (white, FONT.axis), positioned
|
|
22
|
+
* just off each axis. Labels are awaited (rendered) before being returned.
|
|
23
|
+
*/
|
|
24
|
+
export declare const createAxisLabels: (plane: NumberPlane, xs: readonly number[], ys: readonly number[]) => Promise<MathTex[]>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { QuestionMount } from './question';
|
|
2
|
+
import type { Vec2 } from './matrix2';
|
|
3
|
+
/** The polygon's corners in drawing order, in grid units. */
|
|
4
|
+
export type PolygonCorners = readonly Vec2[];
|
|
5
|
+
/** A corner the question holds still: the origin, or the tip of a reference vector. */
|
|
6
|
+
interface FixedVertexSpec {
|
|
7
|
+
readonly kind: 'fixed';
|
|
8
|
+
readonly at: Vec2;
|
|
9
|
+
}
|
|
10
|
+
/** A corner the user drags. `pin` confines it to the two rails through that point; without
|
|
11
|
+
* one it moves freely. */
|
|
12
|
+
interface DraggableVertexSpec {
|
|
13
|
+
readonly kind: 'draggable';
|
|
14
|
+
readonly start: Vec2;
|
|
15
|
+
readonly target: Vec2;
|
|
16
|
+
readonly pin?: Vec2;
|
|
17
|
+
}
|
|
18
|
+
export type PolygonVertexSpec = FixedVertexSpec | DraggableVertexSpec;
|
|
19
|
+
interface PolygonArrowSpec {
|
|
20
|
+
vector: Vec2;
|
|
21
|
+
latex: string;
|
|
22
|
+
color: string;
|
|
23
|
+
labelOffset: Vec2;
|
|
24
|
+
labelScale: number;
|
|
25
|
+
}
|
|
26
|
+
export interface PolygonDragSpec {
|
|
27
|
+
question: string;
|
|
28
|
+
/** The polygon's corners in drawing order. */
|
|
29
|
+
vertices: readonly PolygonVertexSpec[];
|
|
30
|
+
arrows: readonly PolygonArrowSpec[];
|
|
31
|
+
}
|
|
32
|
+
export declare const createPolygonDragScene: (spec: PolygonDragSpec) => QuestionMount;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** A verdict carries correctness only: the wording shown for a right or wrong answer is
|
|
2
|
+
* the host's to choose. */
|
|
3
|
+
export interface GradeResult {
|
|
4
|
+
readonly ok: boolean;
|
|
5
|
+
/** The correct answer target (grid units), when an interactive scene exposes one. */
|
|
6
|
+
readonly correct?: readonly number[];
|
|
7
|
+
}
|
|
8
|
+
export type SceneState = {
|
|
9
|
+
readonly kind: 'idle';
|
|
10
|
+
}
|
|
11
|
+
/** Graded before the async build finished: there is nothing to grade yet, so the host
|
|
12
|
+
* says so rather than showing a wrong verdict. */
|
|
13
|
+
| {
|
|
14
|
+
readonly kind: 'not-ready';
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'graded';
|
|
17
|
+
readonly result: GradeResult;
|
|
18
|
+
};
|
|
19
|
+
export type SceneStateListener = (state: SceneState) => void;
|
|
20
|
+
/** The lifecycle handle a mounted scene returns to its host. */
|
|
21
|
+
export interface SceneApi {
|
|
22
|
+
/** Grade the current answer; locks interaction and returns the verdict, or `null` when
|
|
23
|
+
* the scene is not built yet and nothing was graded. */
|
|
24
|
+
checkAnswer(): GradeResult | null;
|
|
25
|
+
/** Reset to a fresh, un-graded scene WITHOUT reloading the page. */
|
|
26
|
+
reset(): void;
|
|
27
|
+
/** Tear down event listeners and DOM the scene created. */
|
|
28
|
+
dispose(): void;
|
|
29
|
+
/** Current state (for hosts that don't want to wait for the first event). */
|
|
30
|
+
getState(): SceneState;
|
|
31
|
+
/** Subscribe to state changes. Returns an unsubscribe function. */
|
|
32
|
+
onState(listener: SceneStateListener): () => void;
|
|
33
|
+
}
|
|
34
|
+
/** Mounts a scene into a host-provided container and returns its API. */
|
|
35
|
+
export type QuestionMount = (container: HTMLElement) => SceneApi;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Project pointer positions onto the positive horizontal/vertical rails from a pinned corner.
|
|
2
|
+
* A pointer within the threshold of the pin's height stays horizontal; otherwise it switches
|
|
3
|
+
* to the vertical rail.
|
|
4
|
+
*/
|
|
5
|
+
import type { Vec2 } from './matrix2';
|
|
6
|
+
export declare const projectToRail: (pin: Vec2, point: Vec2, range: number) => Vec2;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type Arrow, type MathTex, type NumberPlane, type Scene, type Vector3Tuple } from 'manim-web';
|
|
2
|
+
import { type ArrowStyle } from './arrow';
|
|
3
|
+
import type { Vec2 } from './matrix2';
|
|
4
|
+
export declare const REFERENCE_LABEL_OFFSET: Vec2;
|
|
5
|
+
export declare const DRAGGED_VECTOR_LABEL_OFFSET: Vec2;
|
|
6
|
+
export declare const applyDraggedVectorLabelOffset: (tip: readonly [number, number]) => Vector3Tuple;
|
|
7
|
+
export interface ReferenceVector {
|
|
8
|
+
arrow: Arrow;
|
|
9
|
+
label: MathTex;
|
|
10
|
+
}
|
|
11
|
+
export interface ReferenceVectorSpec {
|
|
12
|
+
vector: Vec2;
|
|
13
|
+
labelLatex: string;
|
|
14
|
+
color: string;
|
|
15
|
+
labelOffset?: Vec2;
|
|
16
|
+
labelScale?: number;
|
|
17
|
+
arrowStyle?: ArrowStyle;
|
|
18
|
+
}
|
|
19
|
+
export declare const createReferenceVector: (scene: Scene, plane: NumberPlane, origin: Vector3Tuple, spec: ReferenceVectorSpec, isCurrent: () => boolean) => Promise<ReferenceVector | null>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface SnapSpec {
|
|
2
|
+
/** Snap step in grid units (e.g. 0.5). */
|
|
3
|
+
readonly grid: number;
|
|
4
|
+
/** Clamp coordinates to ±range (the draggable's travel bounds). */
|
|
5
|
+
readonly range: number;
|
|
6
|
+
}
|
|
7
|
+
/** Clamp v into [min, max]. */
|
|
8
|
+
export declare const clamp: (v: number, min: number, max: number) => number;
|
|
9
|
+
/** Round a free coordinate to the nearest `grid` step, clamped to ±`range`. */
|
|
10
|
+
export declare const snapCoord: (v: number, spec: SnapSpec) => number;
|
|
11
|
+
/** Distance from `v` to its nearest grid line (positive ≥ 0). */
|
|
12
|
+
export declare const gridError: (v: number, grid: number) => number;
|
|
13
|
+
/** Snap both x and y in one call. */
|
|
14
|
+
export declare const snapPoint: (x: number, y: number, spec: SnapSpec) => [number, number];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type StateListener<S> = (state: S) => void;
|
|
2
|
+
export interface StateMachine<S> {
|
|
3
|
+
getState(): S;
|
|
4
|
+
setState(state: S): void;
|
|
5
|
+
/** Subscribe. Returns an unsubscribe function. */
|
|
6
|
+
onState(listener: StateListener<S>): () => void;
|
|
7
|
+
}
|
|
8
|
+
export declare const createStateMachine: <S>(initial: S) => StateMachine<S>;
|
|
@@ -0,0 +1,47 @@
|
|
|
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";
|
|
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
|
+
};
|
|
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: {
|
|
24
|
+
/** Axis integer labels (×1.3 source ≈ 62 → tuned 40). */
|
|
25
|
+
readonly axis: 40;
|
|
26
|
+
/** The vector label (×1.8 source ≈ 86 → tuned 50). */
|
|
27
|
+
readonly vector: 50;
|
|
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. */
|
|
32
|
+
export declare const LEGACY_LABEL_SCALE: {
|
|
33
|
+
readonly basis: 1;
|
|
34
|
+
readonly vector: number;
|
|
35
|
+
};
|
|
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
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { NumberPlane, Scene } from 'manim-web';
|
|
2
|
+
/** Best-effort color reader used by the dev hooks (getColor() or a raw _color). */
|
|
3
|
+
export declare const colorOf: (m: unknown) => unknown;
|
|
4
|
+
/** The dev-hook surface shared by every vector scene's e2e probes (a strict superset of
|
|
5
|
+
* what `e2e/helpers.ts` consumes). A scene adds its own `question` name and any probes
|
|
6
|
+
* specific to it (hints, consumed-vector visibility, layout measurements). */
|
|
7
|
+
export interface VectorProbe {
|
|
8
|
+
readGrid(): [number, number] | null;
|
|
9
|
+
gridToScreen(gx: number, gy: number): {
|
|
10
|
+
x: number;
|
|
11
|
+
y: number;
|
|
12
|
+
} | null;
|
|
13
|
+
worldToScreen(wx: number, wy: number): {
|
|
14
|
+
x: number;
|
|
15
|
+
y: number;
|
|
16
|
+
} | null;
|
|
17
|
+
dotPosition(): {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
} | null;
|
|
21
|
+
arrowTip(): {
|
|
22
|
+
x: number;
|
|
23
|
+
y: number;
|
|
24
|
+
} | null;
|
|
25
|
+
labelGlyphs(): number | undefined;
|
|
26
|
+
dotColor(): string | null;
|
|
27
|
+
labelColor(): string | null;
|
|
28
|
+
labelCenter(): {
|
|
29
|
+
x: number;
|
|
30
|
+
y: number;
|
|
31
|
+
} | null;
|
|
32
|
+
correctVectorEnd(): [number, number, number] | null;
|
|
33
|
+
}
|
|
34
|
+
/** The scene slices a vector scene must hand in to build the standard probe set. */
|
|
35
|
+
export interface VectorProbeSource {
|
|
36
|
+
plane: NumberPlane | null;
|
|
37
|
+
scene: Scene | null;
|
|
38
|
+
/** The user's draggable answer dot. */
|
|
39
|
+
dot: {
|
|
40
|
+
position: {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
};
|
|
44
|
+
} | null;
|
|
45
|
+
/** The vector arrow tailing the dot. */
|
|
46
|
+
arrow: {
|
|
47
|
+
getEnd(): [number, number, number];
|
|
48
|
+
} | null;
|
|
49
|
+
/** The vector's floating label (MathTex). */
|
|
50
|
+
label: {
|
|
51
|
+
children: unknown[];
|
|
52
|
+
getCenter(): [number, number, number];
|
|
53
|
+
} | null;
|
|
54
|
+
/** The correct answer tip's world point, or null when the plane isn't built yet. */
|
|
55
|
+
correctEnd(): [number, number, number] | null;
|
|
56
|
+
}
|
|
57
|
+
export declare const vectorProbes: (getSource: () => VectorProbeSource) => VectorProbe;
|