@algorisys/tinyfly 0.114.0 → 0.116.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.
Files changed (69) hide show
  1. package/README.md +13 -8
  2. package/docs/api-reference.md +2 -1
  3. package/docs/character-appearance.md +27 -2
  4. package/docs/editor-guide.md +1 -1
  5. package/docs/examples.md +1 -1
  6. package/docs/getting-started.md +1 -1
  7. package/docs/gsap-compat.md +1 -1
  8. package/docs/llm-guide.md +18 -0
  9. package/docs/maps.md +2 -2
  10. package/docs/math.md +280 -0
  11. package/docs/teaching.md +1 -1
  12. package/lib/addons/characters.js +2646 -2584
  13. package/lib/addons/{cricket-play-BZNhfgOK.js → cricket-play-C5CkNOc6.js} +2187 -2005
  14. package/lib/addons/math.js +2864 -0
  15. package/lib/addons/sports.js +1 -1
  16. package/lib/browser/tinyfly-math.iife.js +53 -0
  17. package/lib/browser/tinyfly.iife.js +12 -12
  18. package/lib/browser/tinyfly.js +4948 -4699
  19. package/lib/browser/tinyfly.umd.js +12 -12
  20. package/lib/embed/tinyfly-embed.iife.js +1 -1
  21. package/lib/embed/tinyfly-embed.js +8 -0
  22. package/lib/player/tinyfly-player.es.js +8 -0
  23. package/lib/player/tinyfly-player.iife.js +1 -1
  24. package/lib/player/tinyfly-player.umd.js +1 -1
  25. package/lib/types/characters/capabilities.d.ts +8 -0
  26. package/lib/types/characters/character.d.ts +4 -0
  27. package/lib/types/characters/index.d.ts +2 -0
  28. package/lib/types/characters/look/illustrated-pen.d.ts +36 -0
  29. package/lib/types/characters/look/illustration-color.d.ts +13 -0
  30. package/lib/types/characters/look/pen.d.ts +18 -5
  31. package/lib/types/math/browser-entry.d.ts +3 -0
  32. package/lib/types/math/embed/auto-mount-math.d.ts +7 -0
  33. package/lib/types/math/embed/explorable.d.ts +46 -0
  34. package/lib/types/math/embed/mount-math.d.ts +31 -0
  35. package/lib/types/math/expr/differentiate.d.ts +7 -0
  36. package/lib/types/math/expr/evaluate.d.ts +21 -0
  37. package/lib/types/math/expr/parse-expression.d.ts +50 -0
  38. package/lib/types/math/figure/derived.d.ts +17 -0
  39. package/lib/types/math/figure/display-list.d.ts +87 -0
  40. package/lib/types/math/figure/figure-spec.d.ts +239 -0
  41. package/lib/types/math/figure/item-context.d.ts +33 -0
  42. package/lib/types/math/figure/items/calculus.d.ts +7 -0
  43. package/lib/types/math/figure/items/curves.d.ts +7 -0
  44. package/lib/types/math/figure/items/grid.d.ts +5 -0
  45. package/lib/types/math/figure/items/regions.d.ts +5 -0
  46. package/lib/types/math/figure/items/text.d.ts +5 -0
  47. package/lib/types/math/figure/items/vectors.d.ts +9 -0
  48. package/lib/types/math/figure/layout-figure.d.ts +13 -0
  49. package/lib/types/math/figure/plane.d.ts +20 -0
  50. package/lib/types/math/figure/validate-spec.d.ts +2 -0
  51. package/lib/types/math/index.d.ts +43 -0
  52. package/lib/types/math/linear/mat2.d.ts +41 -0
  53. package/lib/types/math/linear/vec2.d.ts +18 -0
  54. package/lib/types/math/presets/calculus.d.ts +59 -0
  55. package/lib/types/math/presets/linear-algebra.d.ts +42 -0
  56. package/lib/types/math/render/arrow.d.ts +10 -0
  57. package/lib/types/math/render/display-list-to-svg.d.ts +10 -0
  58. package/lib/types/math/render/draw-display-list.d.ts +6 -0
  59. package/lib/types/math/steps/math-steps.d.ts +34 -0
  60. package/lib/types/math/targets/math-target.d.ts +43 -0
  61. package/lib/types/math/tex/equation-morph.d.ts +21 -0
  62. package/lib/types/math/tex/glyph-metrics.d.ts +24 -0
  63. package/lib/types/math/tex/tex-layout.d.ts +59 -0
  64. package/lib/types/math/tex/tex-parser.d.ts +88 -0
  65. package/lib/types/player/player.d.ts +6 -0
  66. package/llms-full.txt +388 -12
  67. package/llms.txt +32 -31
  68. package/package.json +6 -2
  69. package/skills/tinyfly/SKILL.md +13 -1
@@ -0,0 +1,87 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ import type { TexLayout, TexPiece } from '../tex/tex-layout';
3
+ /**
4
+ * What a figure looks like at one moment, as plain shapes in screen pixels
5
+ * (y down). Layout produces it as a pure function of the figure and its
6
+ * values; the canvas and SVG renderers only draw it, so a figure looks the
7
+ * same in a video, a canvas demo and an embedded SVG.
8
+ */
9
+ export type Shape = {
10
+ type: 'line';
11
+ id: string;
12
+ points: Vec2[];
13
+ closed?: boolean;
14
+ stroke?: string;
15
+ width?: number;
16
+ fill?: string;
17
+ opacity?: number;
18
+ dash?: number[];
19
+ } | {
20
+ type: 'arrow';
21
+ id: string;
22
+ points: Vec2[];
23
+ stroke: string;
24
+ width: number;
25
+ /** Arrowhead length, px */
26
+ head: number;
27
+ opacity?: number;
28
+ } | {
29
+ type: 'circle';
30
+ id: string;
31
+ x: number;
32
+ y: number;
33
+ r: number;
34
+ fill?: string;
35
+ stroke?: string;
36
+ width?: number;
37
+ opacity?: number;
38
+ } | {
39
+ type: 'text';
40
+ id: string;
41
+ text: string;
42
+ x: number;
43
+ y: number;
44
+ /** Font size, px */
45
+ size: number;
46
+ /** CSS font family */
47
+ font: string;
48
+ italic?: boolean;
49
+ color: string;
50
+ align: 'left' | 'center' | 'right';
51
+ opacity?: number;
52
+ };
53
+ export interface DisplayList {
54
+ width: number;
55
+ height: number;
56
+ background?: string;
57
+ shapes: Shape[];
58
+ }
59
+ /** Font for axis numbers and plain labels. */
60
+ export declare const UI_FONT = "system-ui, -apple-system, \"Segoe UI\", sans-serif";
61
+ /**
62
+ * The first `fraction` (0..1) of a run of polylines by total length, as
63
+ * though one pen drew them in order: what "draw it on" shows part way.
64
+ */
65
+ export declare function trimPolylines(lines: Vec2[][], fraction: number): Vec2[][];
66
+ export interface TexPlacement {
67
+ /** Where the layout's anchor point lands, px */
68
+ x: number;
69
+ y: number;
70
+ /** Font size, px (1 em of the layout) */
71
+ size: number;
72
+ color: string;
73
+ /** Which point of the layout sits at x, y (default centre/middle) */
74
+ align?: 'left' | 'center' | 'right';
75
+ baseline?: 'baseline' | 'middle';
76
+ opacity?: number;
77
+ /** Prefixed to every piece's id, so several equations in one figure stay apart */
78
+ idPrefix: string;
79
+ }
80
+ /** The origin (left edge, baseline) of a layout placed by `place`, in px. */
81
+ export declare function texOrigin(layout: TexLayout, place: Pick<TexPlacement, 'x' | 'y' | 'size' | 'align' | 'baseline'>): Vec2;
82
+ /** Typeset pieces (in ems, from a layout or a morph) as shapes at a placement. */
83
+ export declare function texPiecesToShapes(pieces: (TexPiece & {
84
+ opacity?: number;
85
+ })[], origin: Vec2, place: TexPlacement): Shape[];
86
+ /** A whole layout as shapes. */
87
+ export declare function texToShapes(layout: TexLayout, place: TexPlacement): Shape[];
@@ -0,0 +1,239 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ /**
3
+ * A maths figure as plain JSON: a coordinate plane and the items drawn on it.
4
+ *
5
+ * Everything that moves is a **value**: a number (`k`), a vector (`v: [1, 2]`)
6
+ * or a matrix (`M: [a, b, c, d]`). Items refer to values by name, and a
7
+ * timeline animates them as flat props on the figure's target, with no code:
8
+ *
9
+ * - a value by its name: `M` keyed from `[1, 0, 0, 1]` to `[2, 1, 0, 1]`
10
+ * warps the grid; `k` keyed from 1 to 3 reshapes `sin(k x)`
11
+ * - `ITEM.draw` (0..1): draws an item on, like a pen
12
+ * - `ITEM.opacity` (0..1)
13
+ * - `ITEM.step` on an equation: 0, 1, 2 … shows each step; in between, terms
14
+ * glide from one step to the next
15
+ *
16
+ * The same figure and values always give the same picture.
17
+ */
18
+ export interface MathFigureSpec {
19
+ /** Size in px */
20
+ width: number;
21
+ height: number;
22
+ /** World x range shown (default [-5, 5]) */
23
+ x?: [number, number];
24
+ /** World y range shown (default: centred on 0, with the same scale as x) */
25
+ y?: [number, number];
26
+ /** Colour scheme (default `dark`, the classic look of maths videos) */
27
+ theme?: MathThemeName;
28
+ /** Background colour; `none` for transparent (default: the theme's) */
29
+ background?: string;
30
+ /** Starting values: numbers, `[x, y]` vectors, `[a, b, c, d]` matrices */
31
+ values?: Record<string, number | number[]>;
32
+ items: MathItem[];
33
+ }
34
+ /** A point or vector given directly, or the name of a value holding one. */
35
+ export type VecRef = Vec2 | string;
36
+ /** A number given directly, or the name of a number value (so a timeline can move it). */
37
+ export type NumRef = number | string;
38
+ interface ItemBase {
39
+ /** Unique within the figure; names the item's props (`grid.draw`) */
40
+ id: string;
41
+ /** Colour: a theme colour name (`blue`, `green`, `red`, `yellow`, `ink`, …) or any CSS colour */
42
+ color?: string;
43
+ /** Drawn part, 0..1 (default 1); animate `ID.draw` */
44
+ draw?: number;
45
+ /** 0..1 (default 1); animate `ID.opacity` */
46
+ opacity?: number;
47
+ }
48
+ /** Lines of the plane, warped by a matrix value: the picture of a linear map. */
49
+ export interface GridItem extends ItemBase {
50
+ kind: 'grid';
51
+ /** World units between lines (default 1) */
52
+ step?: number;
53
+ /** Name of a matrix value applied to the grid */
54
+ transform?: string;
55
+ /** Also draw the untransformed grid, faintly, underneath (default false) */
56
+ ghost?: boolean;
57
+ }
58
+ export interface AxesItem extends ItemBase {
59
+ kind: 'axes';
60
+ /** World units between ticks (default 1); 0 for none */
61
+ ticks?: number;
62
+ /** Number the ticks (default true) */
63
+ labels?: boolean;
64
+ }
65
+ export interface VectorItem extends ItemBase {
66
+ kind: 'vector';
67
+ /** The tip */
68
+ to: VecRef;
69
+ /** The tail (default the origin) */
70
+ from?: VecRef;
71
+ /** Name of a matrix value applied to both ends */
72
+ transform?: string;
73
+ /** TeX label by the tip */
74
+ label?: string;
75
+ /** Where the label goes: beyond the tip (default) or beside the middle, on the left of travel */
76
+ labelAt?: 'tip' | 'middle';
77
+ /** Line width in px at a 600 px figure (default 4) */
78
+ width?: number;
79
+ }
80
+ /** î and ĵ, optionally carried by a matrix value. */
81
+ export interface BasisItem extends ItemBase {
82
+ kind: 'basis';
83
+ transform?: string;
84
+ /** Label the vectors î and ĵ (default true) */
85
+ labels?: boolean;
86
+ }
87
+ export interface PointItem extends ItemBase {
88
+ kind: 'point';
89
+ /** Where it is; or give `on` and `x` to put it on a curve */
90
+ at?: VecRef;
91
+ /** A function of x the point rides on: the point is (x, f(x)) */
92
+ on?: string;
93
+ /** The point's x on `on` (a number or a number value) */
94
+ x?: NumRef;
95
+ transform?: string;
96
+ label?: string;
97
+ /** px at a 600 px figure (default 6) */
98
+ radius?: number;
99
+ /** An open circle: a value the function does not take (a hole, a limit) */
100
+ hollow?: boolean;
101
+ }
102
+ /** y = f(x) from an expression (see expr/parse-expression.ts); number values are its parameters. */
103
+ export interface FunctionItem extends ItemBase {
104
+ kind: 'function';
105
+ expr: string;
106
+ /** Plot this derivative of it instead (1: f′, 2: f″ …), worked out exactly */
107
+ derivative?: number;
108
+ /** x range drawn (default the figure's) */
109
+ domain?: [number, number];
110
+ width?: number;
111
+ /** Dashed line (default false) */
112
+ dashed?: boolean;
113
+ }
114
+ /** The tangent to y = f(x) at x = at; with `h`, the secant through at and at + h instead. */
115
+ export interface TangentItem extends ItemBase {
116
+ kind: 'tangent';
117
+ expr: string;
118
+ at: NumRef;
119
+ /** Secant step: the line through (at, f(at)) and (at + h, f(at + h)); 0 or absent is the tangent */
120
+ h?: NumRef;
121
+ /** World x units the line spans, centred on `at` (default the whole view) */
122
+ length?: number;
123
+ /** Mark the point(s) it touches (default true) */
124
+ points?: boolean;
125
+ /** TeX by the point; `\val{ID.slope}` shows the slope */
126
+ label?: string;
127
+ width?: number;
128
+ }
129
+ /** Rectangles (or trapezoids) under y = f(x): a Riemann sum. */
130
+ export interface RiemannItem extends ItemBase {
131
+ kind: 'riemann';
132
+ expr: string;
133
+ from: NumRef;
134
+ to: NumRef;
135
+ /** How many pieces (rounded; animate it to watch them thin out) */
136
+ n: NumRef;
137
+ /** Where each rectangle meets the curve (default `left`) */
138
+ rule?: 'left' | 'right' | 'midpoint' | 'trapezoid';
139
+ /** Fill opacity (default 0.35) */
140
+ fillOpacity?: number;
141
+ }
142
+ /** The region between y = f(x) and y = lower(x) (default the x axis) from `from` to `to`. */
143
+ export interface AreaItem extends ItemBase {
144
+ kind: 'area';
145
+ expr: string;
146
+ from: NumRef;
147
+ to: NumRef;
148
+ /** The lower boundary, a function of x (default 0) */
149
+ lower?: string;
150
+ /** Colour where the region is below the lower boundary (default `red`) */
151
+ negativeColor?: string;
152
+ fillOpacity?: number;
153
+ }
154
+ /** The Taylor polynomial of y = f(x) about x = at; a fractional order blends into the next term. */
155
+ export interface TaylorItem extends ItemBase {
156
+ kind: 'taylor';
157
+ expr: string;
158
+ at: NumRef;
159
+ /** Degree, 0..20 (animate it to add terms one by one) */
160
+ order: NumRef;
161
+ domain?: [number, number];
162
+ width?: number;
163
+ }
164
+ /** (x(t), y(t)) from two expressions. */
165
+ export interface ParametricItem extends ItemBase {
166
+ kind: 'parametric';
167
+ x: string;
168
+ y: string;
169
+ /** t range (default [0, 2π]) */
170
+ t?: [number, number];
171
+ transform?: string;
172
+ width?: number;
173
+ }
174
+ /** A filled polygon (default the unit square), optionally carried by a matrix: its area shows the determinant. */
175
+ export interface PolygonItem extends ItemBase {
176
+ kind: 'polygon';
177
+ points?: Vec2[];
178
+ transform?: string;
179
+ /** Fill opacity (default 0.3) */
180
+ fillOpacity?: number;
181
+ /** TeX label at its centre; `\val{M.det}` shows the matrix's determinant */
182
+ label?: string;
183
+ }
184
+ /** A line through the origin along a vector: a span, or (with `eigen`) a matrix's eigenvectors. */
185
+ export interface LineItem extends ItemBase {
186
+ kind: 'line';
187
+ /** Direction */
188
+ along?: VecRef;
189
+ /** Instead of `along`: one line per real eigenvector of this matrix value */
190
+ eigen?: string;
191
+ dashed?: boolean;
192
+ width?: number;
193
+ }
194
+ /** TeX placed in world or screen coordinates. */
195
+ export interface LabelItem extends ItemBase {
196
+ kind: 'label';
197
+ tex: string;
198
+ /** Where, in world units (or px with `screen: true`) */
199
+ at: VecRef;
200
+ screen?: boolean;
201
+ /** Font size, px at a 600 px figure (default 28) */
202
+ size?: number;
203
+ align?: 'left' | 'center' | 'right';
204
+ /** A soft panel behind the text, so it reads over a grid (default true for `screen` labels) */
205
+ backdrop?: boolean;
206
+ }
207
+ /** An equation worked in steps; `ID.step` moves between them, terms gliding. */
208
+ export interface EquationItem extends ItemBase {
209
+ kind: 'equation';
210
+ /** TeX for each step */
211
+ steps: string[];
212
+ /** Which step (default 0); fractional values are part way to the next */
213
+ step?: number;
214
+ at: VecRef;
215
+ screen?: boolean;
216
+ size?: number;
217
+ align?: 'left' | 'center' | 'right';
218
+ /** A soft panel behind the text (default true for `screen` equations) */
219
+ backdrop?: boolean;
220
+ }
221
+ export type MathItem = GridItem | AxesItem | VectorItem | BasisItem | PointItem | FunctionItem | ParametricItem | PolygonItem | LineItem | LabelItem | EquationItem | TangentItem | RiemannItem | AreaItem | TaylorItem;
222
+ export type MathItemKind = MathItem['kind'];
223
+ export declare const ITEM_KINDS: readonly MathItemKind[];
224
+ export type MathThemeName = 'dark' | 'light' | 'chalk';
225
+ export interface MathTheme {
226
+ background: string;
227
+ ink: string;
228
+ grid: string;
229
+ ghost: string;
230
+ axes: string;
231
+ colors: Record<string, string>;
232
+ }
233
+ /**
234
+ * Colour schemes. `dark` follows the long-standing maths-video palette (blue
235
+ * grid, green î, red ĵ, yellow highlights); `light` suits lesson pages;
236
+ * `chalk` is a blackboard.
237
+ */
238
+ export declare const MATH_THEMES: Record<MathThemeName, MathTheme>;
239
+ export {};
@@ -0,0 +1,33 @@
1
+ import { type Mat2 } from '../linear/mat2';
2
+ import { type Vec2 } from '../linear/vec2';
3
+ import type { MathTheme, NumRef, VecRef } from './figure-spec';
4
+ import type { Plane } from './plane';
5
+ /** Values by name, as the figure holds them at one moment. */
6
+ export type Values = Record<string, number | number[]>;
7
+ /** What an item's layout reads: where it is, the values, its colours and how much of it shows. */
8
+ export interface ItemContext {
9
+ plane: Plane;
10
+ theme: MathTheme;
11
+ values: Values;
12
+ /**
13
+ * Numbers for expressions and `\val{…}`: every number value, plus for each
14
+ * matrix `M.a M.b M.c M.d M.det` and for each vector `v.x v.y v.length`.
15
+ */
16
+ scope: Record<string, number>;
17
+ /** Drawn part, 0..1 */
18
+ draw: number;
19
+ /** 0..1 */
20
+ opacity: number;
21
+ /** The item's own props (`step` for an equation) */
22
+ prop(name: string): number | undefined;
23
+ }
24
+ /** Numbers for expressions and TeX values, from all values (see ItemContext.scope). */
25
+ export declare function scopeOf(values: Values): Record<string, number>;
26
+ /** A theme colour by name, or the CSS colour as given, or the fallback. */
27
+ export declare function colorOf(theme: MathTheme, color: string | undefined, fallback: string): string;
28
+ /** A vector given directly or by value name. */
29
+ export declare function vecOf(values: Values, ref: VecRef): Vec2;
30
+ /** A matrix value by name; the identity when no name is given. */
31
+ export declare function matrixOf(values: Values, name: string | undefined): Mat2;
32
+ /** A number given directly or by the name of a number value. */
33
+ export declare function numOf(values: Values, ref: NumRef): number;
@@ -0,0 +1,7 @@
1
+ import type { AreaItem, RiemannItem, TangentItem, TaylorItem } from '../figure-spec';
2
+ import { type Shape } from '../display-list';
3
+ import { type ItemContext } from '../item-context';
4
+ export declare function layoutTangent(item: TangentItem, ctx: ItemContext): Shape[];
5
+ export declare function layoutRiemann(item: RiemannItem, ctx: ItemContext): Shape[];
6
+ export declare function layoutArea(item: AreaItem, ctx: ItemContext): Shape[];
7
+ export declare function layoutTaylor(item: TaylorItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,7 @@
1
+ import type { FunctionItem, ParametricItem } from '../figure-spec';
2
+ import { type Shape } from '../display-list';
3
+ import { type ItemContext } from '../item-context';
4
+ /** y = f(x) from x0 to x1 as drawn-on runs, broken at gaps and asymptotes. */
5
+ export declare function curveRuns(id: string, f: (x: number) => number, x0: number, x1: number, color: string, width: number, ctx: ItemContext, dash?: number[]): Shape[];
6
+ export declare function layoutFunction(item: FunctionItem, ctx: ItemContext): Shape[];
7
+ export declare function layoutParametric(item: ParametricItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,5 @@
1
+ import type { AxesItem, GridItem } from '../figure-spec';
2
+ import { type Shape } from '../display-list';
3
+ import { type ItemContext } from '../item-context';
4
+ export declare function layoutGrid(item: GridItem, ctx: ItemContext): Shape[];
5
+ export declare function layoutAxes(item: AxesItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,5 @@
1
+ import type { LineItem, PolygonItem } from '../figure-spec';
2
+ import { type Shape } from '../display-list';
3
+ import { type ItemContext } from '../item-context';
4
+ export declare function layoutPolygon(item: PolygonItem, ctx: ItemContext): Shape[];
5
+ export declare function layoutLine(item: LineItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,5 @@
1
+ import type { EquationItem, LabelItem } from '../figure-spec';
2
+ import { type Shape } from '../display-list';
3
+ import { type ItemContext } from '../item-context';
4
+ export declare function layoutLabel(item: LabelItem, ctx: ItemContext): Shape[];
5
+ export declare function layoutEquation(item: EquationItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,9 @@
1
+ import { type Vec2 } from '../../linear/vec2';
2
+ import type { BasisItem, PointItem, VectorItem } from '../figure-spec';
3
+ import { type Shape } from '../display-list';
4
+ import { type ItemContext } from '../item-context';
5
+ /** A TeX label just beyond `tip`, pushed out along `direction` (screen px). */
6
+ export declare function tipLabel(tex: string, tip: Vec2, direction: Vec2, color: string, id: string, ctx: ItemContext): Shape[];
7
+ export declare function layoutVector(item: VectorItem, ctx: ItemContext): Shape[];
8
+ export declare function layoutBasis(item: BasisItem, ctx: ItemContext): Shape[];
9
+ export declare function layoutPoint(item: PointItem, ctx: ItemContext): Shape[];
@@ -0,0 +1,13 @@
1
+ import { type MathFigureSpec } from './figure-spec';
2
+ import type { DisplayList } from './display-list';
3
+ /**
4
+ * Animated values for a figure, as a timeline writes them on its target:
5
+ * a value by name (`M`, `k`, `v`) or an item prop (`grid.draw`, `eq.step`).
6
+ */
7
+ export type MathProps = Record<string, number | number[] | string>;
8
+ /**
9
+ * The figure at one moment: its spec with these props applied, as shapes.
10
+ * Pure and deterministic. Items draw in the order they are listed, so later
11
+ * items sit on top. Validate the spec once with `validateMathFigure` first.
12
+ */
13
+ export declare function layoutFigure(spec: MathFigureSpec, props?: MathProps): DisplayList;
@@ -0,0 +1,20 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ import type { MathFigureSpec } from './figure-spec';
3
+ /**
4
+ * The mapping between world units (maths axes, y up) and the figure's pixels
5
+ * (y down). Pure data plus two functions; no drawing.
6
+ */
7
+ export interface Plane {
8
+ width: number;
9
+ height: number;
10
+ x: [number, number];
11
+ y: [number, number];
12
+ /** px per world unit, horizontally and vertically */
13
+ unitX: number;
14
+ unitY: number;
15
+ /** Line widths and text sizes are given at a 600 px figure; this scales them */
16
+ scale: number;
17
+ toScreen(p: Vec2): Vec2;
18
+ toWorld(p: Vec2): Vec2;
19
+ }
20
+ export declare function planeOf(spec: Pick<MathFigureSpec, 'width' | 'height' | 'x' | 'y'>): Plane;
@@ -0,0 +1,2 @@
1
+ import { type MathFigureSpec } from './figure-spec';
2
+ export declare function validateMathFigure(spec: MathFigureSpec): MathFigureSpec;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * @algorisys/tinyfly/math: maths teaching animations.
3
+ *
4
+ * A figure is JSON (a coordinate plane and items: grids, axes, vectors,
5
+ * functions, polygons, equations); its values (numbers, vectors, matrices)
6
+ * and its items' draw / opacity / step are animated by ordinary timeline
7
+ * tracks. One pure layout step turns figure + values into shapes, drawn on a
8
+ * canvas (videos, Workers, live demos) or as SVG (lesson embeds, static
9
+ * export), so every output shows the same picture.
10
+ */
11
+ export * as vec2 from './linear/vec2';
12
+ export * as mat2 from './linear/mat2';
13
+ export type { Vec2 } from './linear/vec2';
14
+ export type { Mat2, Eigenpair } from './linear/mat2';
15
+ export { parseExpression, expressionNames, ExpressionError, FUNCTIONS, CONSTANTS, type Expression as MathExpression } from './expr/parse-expression';
16
+ export { evaluate, compile, compileDerivative, type Scope } from './expr/evaluate';
17
+ export { differentiate, nthDerivative, expressionToString } from './expr/differentiate';
18
+ export { integrate } from './figure/derived';
19
+ export { parseTex, TexError, TEX_COMMANDS, SYMBOLS, type TexNode, type TexClass } from './tex/tex-parser';
20
+ export { layoutTex, type TexLayout, type TexPiece, type TexGlyph, type TexRule, type TexStroke, type TexLayoutOptions } from './tex/tex-layout';
21
+ export { morphEquation, type MorphPiece, type PlacedLayout } from './tex/equation-morph';
22
+ export { MATH_FONT } from './tex/glyph-metrics';
23
+ export * from './figure/figure-spec';
24
+ export { validateMathFigure } from './figure/validate-spec';
25
+ export { layoutFigure, type MathProps } from './figure/layout-figure';
26
+ export { planeOf, type Plane } from './figure/plane';
27
+ export { texToShapes, trimPolylines, type DisplayList, type Shape, type TexPlacement } from './figure/display-list';
28
+ export { drawDisplayList } from './render/draw-display-list';
29
+ export { displayListToSvg, displayListToSvgContent } from './render/display-list-to-svg';
30
+ export { mathTarget, mathFigureProps, type MathCanvasTarget } from './targets/math-target';
31
+ export { mathSteps, type MathSteps } from './steps/math-steps';
32
+ export { mountMath, mountAllMath, type MountedMathFigure } from './embed/mount-math';
33
+ export { mathExplorable, type MathExplorable, type ExplorableOptions, type SliderControl, type DragHandle } from './embed/explorable';
34
+ export { linearMapFigure, determinantFigure, eigenFigure, vectorSumFigure, spanFigure, MATRIX_TEX, type PresetOptions, } from './presets/linear-algebra';
35
+ export { tangentFigure, secantFigure, riemannFigure, areaFigure, taylorFigure, limitFigure, type CalculusOptions } from './presets/calculus';
36
+ import type { MathFigureSpec } from './figure/figure-spec';
37
+ import { type MathProps } from './figure/layout-figure';
38
+ /** A figure checked up front: returns it unchanged, or throws a message that says how to fix it. */
39
+ export declare function mathFigure(spec: MathFigureSpec): MathFigureSpec;
40
+ /** A figure at some values as a standalone SVG document (for static pages, RSS, email, print). */
41
+ export declare function mathFigureToSvg(spec: MathFigureSpec, props?: MathProps, options?: {
42
+ title?: string;
43
+ }): string;
@@ -0,0 +1,41 @@
1
+ import type { Vec2 } from './vec2';
2
+ /**
3
+ * 2×2 matrices as `[a, b, c, d]`, row by row:
4
+ *
5
+ * | a b |
6
+ * | c d |
7
+ *
8
+ * so the first column `[a, c]` is where î lands and the second `[b, d]` is
9
+ * where ĵ lands. A flat number array is what a timeline track interpolates,
10
+ * element by element: keying `[1, 0, 0, 1]` to a matrix M moves every point
11
+ * in a straight line from where it starts to where M sends it, which is the
12
+ * classic "watch the grid transform" animation. Every function is pure.
13
+ */
14
+ export type Mat2 = [number, number, number, number];
15
+ export declare const IDENTITY: Mat2;
16
+ /** M·v */
17
+ export declare const apply: ([a, b, c, d]: Mat2, [x, y]: Vec2) => Vec2;
18
+ /** A·B: apply B first, then A. */
19
+ export declare function multiply(A: Mat2, B: Mat2): Mat2;
20
+ /** The signed factor areas are scaled by; negative when orientation flips. */
21
+ export declare const determinant: ([a, b, c, d]: Mat2) => number;
22
+ /** The inverse, or undefined when the matrix squashes the plane (determinant 0). */
23
+ export declare function inverse(m: Mat2): Mat2 | undefined;
24
+ /** Element-wise blend from `from` (t = 0) to `to` (t = 1). */
25
+ export declare const lerp: (from: Mat2, to: Mat2, t: number) => Mat2;
26
+ /** A rotation by `radians`, counter-clockwise in maths axes (y up). */
27
+ export declare const rotation: (radians: number) => Mat2;
28
+ export interface Eigenpair {
29
+ value: number;
30
+ /** Unit length */
31
+ vector: Vec2;
32
+ }
33
+ /**
34
+ * The real eigenvalues and unit eigenvectors, largest value first. Empty
35
+ * when the eigenvalues are complex (a rotation turns every direction). A
36
+ * repeated eigenvalue gives one pair, or two when every vector is an
37
+ * eigenvector (a uniform scale).
38
+ */
39
+ export declare function eigen(m: Mat2): Eigenpair[];
40
+ /** True when `value` is four finite numbers. */
41
+ export declare function isMat2(value: unknown): value is Mat2;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * 2D vectors as plain `[x, y]` tuples: the same shape a timeline track
3
+ * interpolates element by element, so a vector can be keyed directly.
4
+ * Every function is pure and returns a new tuple.
5
+ */
6
+ export type Vec2 = [number, number];
7
+ export declare const add: (a: Vec2, b: Vec2) => Vec2;
8
+ export declare const sub: (a: Vec2, b: Vec2) => Vec2;
9
+ export declare const scale: (a: Vec2, k: number) => Vec2;
10
+ export declare const dot: (a: Vec2, b: Vec2) => number;
11
+ /** The z of the 3D cross product: the signed area of the parallelogram on a and b. */
12
+ export declare const cross: (a: Vec2, b: Vec2) => number;
13
+ export declare const length: (a: Vec2) => number;
14
+ /** `a` scaled to length 1; the zero vector stays zero. */
15
+ export declare function normalize(a: Vec2): Vec2;
16
+ export declare const lerp: (a: Vec2, b: Vec2, t: number) => Vec2;
17
+ /** True when `value` is a finite `[x, y]`. */
18
+ export declare function isVec2(value: unknown): value is Vec2;
@@ -0,0 +1,59 @@
1
+ import type { MathFigureSpec, MathThemeName } from '../figure/figure-spec';
2
+ /**
3
+ * Ready-made calculus figures. Each returns a plain MathFigureSpec whose
4
+ * moving parts are number values, so a timeline (or a slider) slides the
5
+ * point, shrinks the secant, adds rectangles or Taylor terms:
6
+ *
7
+ * - tangentFigure: value `a`, the point of tangency
8
+ * - secantFigure: values `a` and `h`; key `h` toward 0 to watch the secant become the tangent
9
+ * - riemannFigure: value `n`, the number of rectangles
10
+ * - areaFigure: value `b`, the right end of the shaded area
11
+ * - taylorFigure: value `order`, the degree (fractional values grow the next term in)
12
+ * - limitFigure: value `p`, a point sliding along the curve toward the hole at `at`
13
+ */
14
+ export interface CalculusOptions {
15
+ width?: number;
16
+ height?: number;
17
+ theme?: MathThemeName;
18
+ /** World x range (default [-5, 5]) */
19
+ x?: [number, number];
20
+ /** World y range (default: centred on 0 with square units) */
21
+ y?: [number, number];
22
+ /** The function, an expression in x */
23
+ expr: string;
24
+ }
25
+ /** The tangent at x = a, with its slope shown. */
26
+ export declare function tangentFigure(options: CalculusOptions & {
27
+ at?: number;
28
+ }): MathFigureSpec;
29
+ /** The secant through x = a and x = a + h; shrink `h` to 0 and it becomes the tangent. */
30
+ export declare function secantFigure(options: CalculusOptions & {
31
+ at?: number;
32
+ h?: number;
33
+ }): MathFigureSpec;
34
+ /** n rectangles under the curve from `from` to `to`, their total beside the exact area. */
35
+ export declare function riemannFigure(options: CalculusOptions & {
36
+ from: number;
37
+ to: number;
38
+ n?: number;
39
+ rule?: 'left' | 'right' | 'midpoint' | 'trapezoid';
40
+ }): MathFigureSpec;
41
+ /** The area under the curve from `from` to b, growing as `b` moves. */
42
+ export declare function areaFigure(options: CalculusOptions & {
43
+ from: number;
44
+ to: number;
45
+ }): MathFigureSpec;
46
+ /** Taylor polynomials of the function about x = at, degree `order`. */
47
+ export declare function taylorFigure(options: CalculusOptions & {
48
+ at?: number;
49
+ order?: number;
50
+ }): MathFigureSpec;
51
+ /**
52
+ * A limit: a point sliding along the curve toward x = at, where the function
53
+ * has a hole (pass `limit`, the value it approaches, to draw the hole there).
54
+ */
55
+ export declare function limitFigure(options: CalculusOptions & {
56
+ at: number;
57
+ limit: number;
58
+ from?: number;
59
+ }): MathFigureSpec;
@@ -0,0 +1,42 @@
1
+ import { type Mat2 } from '../linear/mat2';
2
+ import type { Vec2 } from '../linear/vec2';
3
+ import type { MathFigureSpec, MathThemeName } from '../figure/figure-spec';
4
+ /**
5
+ * Ready-made linear algebra figures. Each returns a plain MathFigureSpec, so
6
+ * it can be changed, saved as JSON or extended with more items. The matrix is
7
+ * the value `M`: start it at the identity and key it to a matrix to watch the
8
+ * plane transform (see steps/math-lesson.ts `applyMatrix`).
9
+ */
10
+ export interface PresetOptions {
11
+ width?: number;
12
+ height?: number;
13
+ theme?: MathThemeName;
14
+ /** World x range (default [-5, 5]) */
15
+ x?: [number, number];
16
+ /** Starting matrix (default the identity) */
17
+ matrix?: Mat2;
18
+ }
19
+ /** TeX for the live matrix `M`, as `[a b; c d]` with its current entries. */
20
+ export declare const MATRIX_TEX = "\\begin{bmatrix} \\val{M.a} & \\val{M.b} \\\\ \\val{M.c} & \\val{M.d} \\end{bmatrix}";
21
+ /** The grid, î and ĵ carried by `M`, with the unit square and the matrix shown live. */
22
+ export declare function linearMapFigure(options?: PresetOptions): MathFigureSpec;
23
+ /** The unit square becomes a parallelogram whose area is the determinant. */
24
+ export declare function determinantFigure(options?: PresetOptions): MathFigureSpec;
25
+ /**
26
+ * Eigenvectors: the lines that stay put. Set `matrix` to the target, start
27
+ * `M` at the identity and key it there; the eigenlines are those of the
28
+ * target (value `A`), so they are visible before the plane moves.
29
+ */
30
+ export declare function eigenFigure(options: PresetOptions & {
31
+ matrix: Mat2;
32
+ }): MathFigureSpec;
33
+ /** u + v, tip to tail, with the sum. */
34
+ export declare function vectorSumFigure(options: PresetOptions & {
35
+ u: Vec2;
36
+ v: Vec2;
37
+ }): MathFigureSpec;
38
+ /** Every combination a u + b v: two vectors and the line or plane they span. */
39
+ export declare function spanFigure(options: PresetOptions & {
40
+ u: Vec2;
41
+ v?: Vec2;
42
+ }): MathFigureSpec;