@khanacademy/perseus 24.1.0 → 24.3.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 (32) hide show
  1. package/dist/es/index.css +7 -0
  2. package/dist/es/index.js +655 -130
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.css +7 -0
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +678 -141
  7. package/dist/index.js.map +1 -1
  8. package/dist/perseus-api.d.ts +2 -0
  9. package/dist/perseus-types.d.ts +17 -2
  10. package/dist/server-item-renderer.d.ts +2 -0
  11. package/dist/types.d.ts +1 -1
  12. package/dist/widgets/expression.d.ts +12 -0
  13. package/dist/widgets/interactive-graph.d.ts +1 -1
  14. package/dist/widgets/interactive-graphs/graphs/angle.d.ts +5 -0
  15. package/dist/widgets/interactive-graphs/graphs/components/{angle.d.ts → angle-indicators.d.ts} +12 -2
  16. package/dist/widgets/interactive-graphs/graphs/components/movable-line.d.ts +11 -0
  17. package/dist/widgets/interactive-graphs/graphs/components/text-label.d.ts +1 -1
  18. package/dist/widgets/interactive-graphs/graphs/index.d.ts +1 -0
  19. package/dist/widgets/interactive-graphs/interactive-graph-question-builder.d.ts +3 -1
  20. package/dist/widgets/interactive-graphs/locked-figures/locked-function.d.ts +4 -0
  21. package/dist/widgets/interactive-graphs/mafs-supported-graph-types.d.ts +1 -1
  22. package/dist/widgets/interactive-graphs/math/angles.d.ts +3 -0
  23. package/dist/widgets/interactive-graphs/math/box.d.ts +4 -0
  24. package/dist/widgets/interactive-graphs/math/clamp.d.ts +1 -0
  25. package/dist/widgets/interactive-graphs/math/coordinates.d.ts +2 -0
  26. package/dist/widgets/interactive-graphs/math/index.d.ts +6 -0
  27. package/dist/widgets/interactive-graphs/math/interval.d.ts +5 -0
  28. package/dist/widgets/interactive-graphs/math/snap.d.ts +2 -0
  29. package/dist/widgets/interactive-graphs/types.d.ts +9 -1
  30. package/dist/widgets/interactive-graphs/utils.d.ts +0 -2
  31. package/dist/widgets/label-image.d.ts +4 -0
  32. package/package.json +2 -2
@@ -96,8 +96,10 @@ export declare const ApiOptions: {
96
96
  circle?: boolean | undefined;
97
97
  polygon?: boolean | undefined;
98
98
  linear?: boolean | undefined;
99
+ point?: boolean | undefined;
99
100
  quadratic?: boolean | undefined;
100
101
  sinusoid?: boolean | undefined;
102
+ angle?: boolean | undefined;
101
103
  "linear-system"?: boolean | undefined;
102
104
  ray?: boolean | undefined;
103
105
  segment?: boolean | undefined;
@@ -1,6 +1,10 @@
1
1
  import type { Coord } from "./interactive2/types";
2
2
  import type { Interval, vec } from "mafs";
3
3
  export type Range = Interval;
4
+ export type Domain = {
5
+ min?: number;
6
+ max?: number;
7
+ };
4
8
  export type Size = [number, number];
5
9
  export type CollinearTuple = [vec.Vector2, vec.Vector2];
6
10
  export type ShowSolutions = "all" | "selected" | "none";
@@ -349,7 +353,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
349
353
  declare const lockedFigureColorNames: readonly ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
350
354
  export type LockedFigureColor = (typeof lockedFigureColorNames)[number];
351
355
  export declare const lockedFigureColors: Record<LockedFigureColor, string>;
352
- export type LockedFigure = LockedPointType | LockedLineType | LockedVectorType | LockedEllipseType | LockedPolygonType;
356
+ export type LockedFigure = LockedPointType | LockedLineType | LockedVectorType | LockedEllipseType | LockedPolygonType | LockedFunctionType;
353
357
  export type LockedFigureType = LockedFigure["type"];
354
358
  export type LockedPointType = {
355
359
  type: "point";
@@ -390,6 +394,17 @@ export type LockedPolygonType = {
390
394
  fillStyle: LockedFigureFillType;
391
395
  strokeStyle: "solid" | "dashed";
392
396
  };
397
+ export type LockedFunctionType = {
398
+ type: "function";
399
+ color: LockedFigureColor;
400
+ strokeStyle: "solid" | "dashed";
401
+ equation: string;
402
+ equationParsed?: {
403
+ [k: string]: any;
404
+ };
405
+ directionalAxis: "x" | "y";
406
+ domain?: Domain;
407
+ };
393
408
  export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
394
409
  export type PerseusGraphTypeCommon = {
395
410
  coord?: Coord;
@@ -401,7 +416,7 @@ export type PerseusGraphTypeAngle = {
401
416
  angleOffsetDeg?: number;
402
417
  snapDegrees?: number;
403
418
  match?: "congruent";
404
- coords?: ReadonlyArray<Coord>;
419
+ coords?: [Coord, Coord, Coord];
405
420
  };
406
421
  export type PerseusGraphTypeCircle = {
407
422
  type: "circle";
@@ -143,8 +143,10 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
143
143
  circle?: boolean | undefined;
144
144
  polygon?: boolean | undefined;
145
145
  linear?: boolean | undefined;
146
+ point?: boolean | undefined;
146
147
  quadratic?: boolean | undefined;
147
148
  sinusoid?: boolean | undefined;
149
+ angle?: boolean | undefined;
148
150
  "linear-system"?: boolean | undefined;
149
151
  ray?: boolean | undefined;
150
152
  segment?: boolean | undefined;
package/dist/types.d.ts CHANGED
@@ -77,7 +77,7 @@ type TrackInteractionArgs = {
77
77
  id: string;
78
78
  correct?: boolean;
79
79
  } & Partial<TrackingGradedGroupExtraArguments> & Partial<TrackingSequenceExtraArguments>;
80
- export declare const MafsGraphTypeFlags: readonly ["segment", "linear", "linear-system", "ray", "polygon", "circle", "quadratic", "sinusoid"];
80
+ export declare const MafsGraphTypeFlags: readonly ["angle", "segment", "linear", "linear-system", "ray", "polygon", "circle", "quadratic", "sinusoid", "point"];
81
81
  export declare const InteractiveGraphLockedFeaturesFlags: readonly ["interactive-graph-locked-features-m2", "interactive-graph-locked-features-m2b"];
82
82
  /**
83
83
  * APIOptions provides different ways to customize the behaviour of Perseus.
@@ -137,8 +137,10 @@ declare const _default: Readonly<{
137
137
  circle?: boolean | undefined;
138
138
  polygon?: boolean | undefined;
139
139
  linear?: boolean | undefined;
140
+ point?: boolean | undefined;
140
141
  quadratic?: boolean | undefined;
141
142
  sinusoid?: boolean | undefined;
143
+ angle?: boolean | undefined;
142
144
  "linear-system"?: boolean | undefined;
143
145
  ray?: boolean | undefined;
144
146
  segment?: boolean | undefined;
@@ -214,8 +216,10 @@ declare const _default: Readonly<{
214
216
  circle?: boolean | undefined;
215
217
  polygon?: boolean | undefined;
216
218
  linear?: boolean | undefined;
219
+ point?: boolean | undefined;
217
220
  quadratic?: boolean | undefined;
218
221
  sinusoid?: boolean | undefined;
222
+ angle?: boolean | undefined;
219
223
  "linear-system"?: boolean | undefined;
220
224
  ray?: boolean | undefined;
221
225
  segment?: boolean | undefined;
@@ -291,8 +295,10 @@ declare const _default: Readonly<{
291
295
  circle?: boolean | undefined;
292
296
  polygon?: boolean | undefined;
293
297
  linear?: boolean | undefined;
298
+ point?: boolean | undefined;
294
299
  quadratic?: boolean | undefined;
295
300
  sinusoid?: boolean | undefined;
301
+ angle?: boolean | undefined;
296
302
  "linear-system"?: boolean | undefined;
297
303
  ray?: boolean | undefined;
298
304
  segment?: boolean | undefined;
@@ -365,8 +371,10 @@ declare const _default: Readonly<{
365
371
  circle?: boolean | undefined;
366
372
  polygon?: boolean | undefined;
367
373
  linear?: boolean | undefined;
374
+ point?: boolean | undefined;
368
375
  quadratic?: boolean | undefined;
369
376
  sinusoid?: boolean | undefined;
377
+ angle?: boolean | undefined;
370
378
  "linear-system"?: boolean | undefined;
371
379
  ray?: boolean | undefined;
372
380
  segment?: boolean | undefined;
@@ -442,8 +450,10 @@ declare const _default: Readonly<{
442
450
  circle?: boolean | undefined;
443
451
  polygon?: boolean | undefined;
444
452
  linear?: boolean | undefined;
453
+ point?: boolean | undefined;
445
454
  quadratic?: boolean | undefined;
446
455
  sinusoid?: boolean | undefined;
456
+ angle?: boolean | undefined;
447
457
  "linear-system"?: boolean | undefined;
448
458
  ray?: boolean | undefined;
449
459
  segment?: boolean | undefined;
@@ -519,8 +529,10 @@ declare const _default: Readonly<{
519
529
  circle?: boolean | undefined;
520
530
  polygon?: boolean | undefined;
521
531
  linear?: boolean | undefined;
532
+ point?: boolean | undefined;
522
533
  quadratic?: boolean | undefined;
523
534
  sinusoid?: boolean | undefined;
535
+ angle?: boolean | undefined;
524
536
  "linear-system"?: boolean | undefined;
525
537
  ray?: boolean | undefined;
526
538
  segment?: boolean | undefined;
@@ -147,7 +147,7 @@ declare class InteractiveGraph extends React.Component<Props, State> {
147
147
  * @param {object} graph Like props.graph or props.correct
148
148
  * @param {object} props of an InteractiveGraph instance
149
149
  */
150
- static getAngleCoords(graph: PerseusGraphTypeAngle, props: Props): ReadonlyArray<Coord>;
150
+ static getAngleCoords(graph: PerseusGraphTypeAngle, props: Props): [Coord, Coord, Coord];
151
151
  static normalizeCoords(coordsList: ReadonlyArray<Coord>, ranges: [Range, Range]): ReadonlyArray<Coord>;
152
152
  static getEquationString(props: Props): string;
153
153
  static pointsFromNormalized(props: Props, coordsList: ReadonlyArray<Coord>, noSnap?: boolean): ReadonlyArray<Coord>;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { AngleGraphState, MafsGraphProps } from "../types";
3
+ type AngleGraphProps = MafsGraphProps<AngleGraphState>;
4
+ export declare function AngleGraph(props: AngleGraphProps): JSX.Element;
5
+ export {};
@@ -2,7 +2,7 @@
2
2
  import { vec } from "mafs";
3
3
  import type { CollinearTuple } from "../../../../perseus-types";
4
4
  import type { Interval } from "mafs";
5
- interface Props {
5
+ interface PolygonAngleProps {
6
6
  centerPoint: vec.Vector2;
7
7
  endPoints: [vec.Vector2, vec.Vector2];
8
8
  polygonLines: readonly CollinearTuple[];
@@ -11,7 +11,17 @@ interface Props {
11
11
  showAngles: boolean;
12
12
  snapTo: "grid" | "angles" | "sides";
13
13
  }
14
- export declare const Angle: ({ centerPoint, endPoints, range, polygonLines, showAngles, snapTo, }: Props) => JSX.Element | null;
14
+ export declare const PolygonAngle: ({ centerPoint, endPoints, range, polygonLines, showAngles, snapTo, }: PolygonAngleProps) => JSX.Element | null;
15
+ interface AngleProps {
16
+ vertex: vec.Vector2;
17
+ coords: [vec.Vector2, vec.Vector2];
18
+ showAngles: boolean;
19
+ allowReflexAngles: boolean;
20
+ angleOffsetDeg: number;
21
+ snapDegrees: number;
22
+ range: [Interval, Interval];
23
+ }
24
+ export declare const Angle: ({ vertex, coords, showAngles, allowReflexAngles, range, }: AngleProps) => JSX.Element;
15
25
  /**
16
26
  * Determines if an angle is an inside (false) or outside (true) angle.
17
27
  * They way, we know to flip the `largeArc` and `sweepArc` flags.
@@ -12,5 +12,16 @@ type Props = {
12
12
  };
13
13
  };
14
14
  export declare const MovableLine: (props: Props) => JSX.Element;
15
+ type LineProps = {
16
+ start: vec.Vector2;
17
+ end: vec.Vector2;
18
+ onMove: (delta: vec.Vector2) => unknown;
19
+ stroke?: string | undefined;
20
+ extend?: undefined | {
21
+ start: boolean;
22
+ end: boolean;
23
+ };
24
+ };
25
+ export declare const Line: (props: LineProps) => JSX.Element;
15
26
  export declare function trimRange(range: [Interval, Interval], graphDimensionsInPixels: vec.Vector2): [Interval, Interval];
16
27
  export {};
@@ -1,6 +1,6 @@
1
1
  import type { TextProps } from "mafs";
2
2
  import type { PropsWithChildren } from "react";
3
- type Props = PropsWithChildren<Pick<TextProps, "x" | "y" | "attach" | "attachDistance">>;
3
+ type Props = PropsWithChildren<Pick<TextProps, "x" | "y" | "attach" | "attachDistance" | "color">>;
4
4
  export declare const TextLabel: ({ children, ...rest }: Props) => JSX.Element;
5
5
  export declare const SvgDefs: () => JSX.Element;
6
6
  export {};
@@ -6,3 +6,4 @@ export { PolygonGraph } from "./polygon";
6
6
  export { CircleGraph } from "./circle";
7
7
  export { QuadraticGraph } from "./quadratic";
8
8
  export { SinusoidGraph } from "./sinusoid";
9
+ export { AngleGraph } from "./angle";
@@ -1,6 +1,7 @@
1
- import type { LockedFigureFillType, LockedFigureColor, PerseusRenderer, CollinearTuple } from "../../perseus-types";
1
+ import type { CollinearTuple, LockedFigureColor, LockedFigureFillType, LockedFunctionType, PerseusRenderer } from "../../perseus-types";
2
2
  import type { Coord } from "@khanacademy/perseus";
3
3
  import type { vec } from "mafs";
4
+ export type LockedFunctionOptions = Omit<Partial<LockedFunctionType>, "type" | "equation">;
4
5
  export declare function interactiveGraphQuestionBuilder(): InteractiveGraphQuestionBuilder;
5
6
  declare class InteractiveGraphQuestionBuilder {
6
7
  private gridStep;
@@ -46,6 +47,7 @@ declare class InteractiveGraphQuestionBuilder {
46
47
  fillStyle?: LockedFigureFillType;
47
48
  strokeStyle?: "solid" | "dashed";
48
49
  }): InteractiveGraphQuestionBuilder;
50
+ addLockedFunction(equation: string, options?: LockedFunctionOptions): this;
49
51
  private createLockedPoint;
50
52
  private addLockedFigure;
51
53
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { LockedFunctionType } from "../../../perseus-types";
3
+ declare const LockedFunction: (props: LockedFunctionType) => JSX.Element;
4
+ export default LockedFunction;
@@ -1,3 +1,3 @@
1
- export declare const mafsSupportedGraphTypes: readonly ["segment", "linear", "linear-system", "ray", "polygon", "point", "circle", "quadratic", "sinusoid"];
1
+ export declare const mafsSupportedGraphTypes: readonly ["angle", "segment", "linear", "linear-system", "ray", "polygon", "point", "circle", "quadratic", "sinusoid"];
2
2
  export type MafsSupportedGraphType = (typeof mafsSupportedGraphTypes)[number];
3
3
  export declare const trueForAllMafsSupportedGraphTypes: Record<MafsSupportedGraphType, true>;
@@ -0,0 +1,3 @@
1
+ import type { vec } from "mafs";
2
+ export declare function polar(r: number | vec.Vector2, th: number): vec.Vector2;
3
+ export declare const findAngle: (point1: vec.Vector2, point2: vec.Vector2, vertex?: vec.Vector2) => number;
@@ -0,0 +1,4 @@
1
+ import type { Interval, vec } from "mafs";
2
+ export type Box = [x: Interval, y: Interval];
3
+ export declare function clampToBox(box: Box, point: vec.Vector2): vec.Vector2;
4
+ export declare function inset(amount: vec.Vector2, box: Box): Box;
@@ -0,0 +1 @@
1
+ export declare function clamp(value: number, min: number, max: number): number;
@@ -0,0 +1,2 @@
1
+ export declare const X = 0;
2
+ export declare const Y = 1;
@@ -0,0 +1,6 @@
1
+ export { clamp } from "./clamp";
2
+ export { snap } from "./snap";
3
+ export { inset, clampToBox } from "./box";
4
+ export { X, Y } from "./coordinates";
5
+ export { MIN, MAX, size } from "./interval";
6
+ export { findAngle, polar } from "./angles";
@@ -0,0 +1,5 @@
1
+ import type { Interval } from "mafs";
2
+ export declare const MIN = 0;
3
+ export declare const MAX = 1;
4
+ export declare function size([min, max]: Interval): number;
5
+ export declare function trim(amount: number, interval: Interval): Interval;
@@ -0,0 +1,2 @@
1
+ import type { vec } from "mafs";
2
+ export declare function snap(snapStep: vec.Vector2, point: vec.Vector2): vec.Vector2;
@@ -8,7 +8,7 @@ export type MafsGraphProps<T extends InteractiveGraphState> = {
8
8
  graphState: T;
9
9
  dispatch: (action: InteractiveGraphAction) => unknown;
10
10
  };
11
- export type InteractiveGraphState = SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState;
11
+ export type InteractiveGraphState = AngleGraphState | SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState;
12
12
  export interface InteractiveGraphStateCommon {
13
13
  hasBeenInteractedWith: boolean;
14
14
  range: [xRange: Interval, yRange: Interval];
@@ -54,6 +54,14 @@ export interface SinusoidGraphState extends InteractiveGraphStateCommon {
54
54
  type: "sinusoid";
55
55
  coords: [vec.Vector2, vec.Vector2];
56
56
  }
57
+ export interface AngleGraphState extends InteractiveGraphStateCommon {
58
+ type: "angle";
59
+ showAngles?: boolean;
60
+ allowReflexAngles?: boolean;
61
+ angleOffsetDeg?: number;
62
+ snapDegrees?: number;
63
+ coords: [Coord, Coord, Coord];
64
+ }
57
65
  export type PairOfPoints = [Coord, Coord];
58
66
  export type GraphDimensions = {
59
67
  range: [Interval, Interval];
@@ -8,10 +8,8 @@ import type { Interval, vec } from "mafs";
8
8
  export declare const TARGET_SIZE = 44;
9
9
  export declare const normalizePoints: <A extends Coord[]>(range: PerseusInteractiveGraphWidgetOptions["range"], step: PerseusInteractiveGraphWidgetOptions["step"], coordsList: A, noSnap?: boolean) => A;
10
10
  export declare const normalizeCoords: <A extends Coord[]>(coordsList: A, ranges: PerseusInteractiveGraphWidgetOptions["range"]) => A;
11
- export declare function snap(snapStep: vec.Vector2, point: vec.Vector2): vec.Vector2;
12
11
  export declare function bound({ snapStep, range, point, }: {
13
12
  snapStep: vec.Vector2;
14
13
  range: [Interval, Interval];
15
14
  point: vec.Vector2;
16
15
  }): vec.Vector2;
17
- export declare function clamp(value: number, min: number, max: number): number;
@@ -131,8 +131,10 @@ declare const _default: Readonly<{
131
131
  circle?: boolean | undefined;
132
132
  polygon?: boolean | undefined;
133
133
  linear?: boolean | undefined;
134
+ point?: boolean | undefined;
134
135
  quadratic?: boolean | undefined;
135
136
  sinusoid?: boolean | undefined;
137
+ angle?: boolean | undefined;
136
138
  "linear-system"?: boolean | undefined;
137
139
  ray?: boolean | undefined;
138
140
  segment?: boolean | undefined;
@@ -192,8 +194,10 @@ declare const _default: Readonly<{
192
194
  circle?: boolean | undefined;
193
195
  polygon?: boolean | undefined;
194
196
  linear?: boolean | undefined;
197
+ point?: boolean | undefined;
195
198
  quadratic?: boolean | undefined;
196
199
  sinusoid?: boolean | undefined;
200
+ angle?: boolean | undefined;
197
201
  "linear-system"?: boolean | undefined;
198
202
  ray?: boolean | undefined;
199
203
  segment?: boolean | undefined;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core Perseus API (includes renderers and widgets)",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "24.1.0",
6
+ "version": "24.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -41,7 +41,7 @@
41
41
  "dependencies": {
42
42
  "@khanacademy/kas": "^0.3.9",
43
43
  "@khanacademy/kmath": "^0.1.12",
44
- "@khanacademy/math-input": "^19.1.0",
44
+ "@khanacademy/math-input": "^19.2.0",
45
45
  "@khanacademy/perseus-core": "1.4.2",
46
46
  "@khanacademy/perseus-linter": "^0.4.0",
47
47
  "@khanacademy/pure-markdown": "^0.3.5",