@khanacademy/perseus 23.0.0 → 23.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.
@@ -97,11 +97,12 @@ export declare const ApiOptions: {
97
97
  polygon?: boolean | undefined;
98
98
  linear?: boolean | undefined;
99
99
  quadratic?: boolean | undefined;
100
+ sinusoid?: boolean | undefined;
100
101
  segment?: boolean | undefined;
101
102
  "linear-system"?: boolean | undefined;
102
103
  ray?: boolean | undefined;
103
104
  } & {
104
- "interactive-graph-locked-features-m1"?: boolean | undefined;
105
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
105
106
  }) | undefined;
106
107
  } | undefined;
107
108
  onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -2,7 +2,7 @@ import type { Coord } from "./interactive2/types";
2
2
  import type { Interval, vec } from "mafs";
3
3
  export type Range = Interval;
4
4
  export type Size = [number, number];
5
- export type CollinearTuple = readonly [vec.Vector2, vec.Vector2];
5
+ export type CollinearTuple = [vec.Vector2, vec.Vector2];
6
6
  export type ShowSolutions = "all" | "selected" | "none";
7
7
  export type PerseusWidgetsMap = {
8
8
  [key in `categorizer ${number}`]: CategorizerWidget;
@@ -349,7 +349,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
349
349
  declare const lockedFigureColorNames: readonly ["green", "grayH", "purple", "pink", "red"];
350
350
  export type LockedFigureColor = (typeof lockedFigureColorNames)[number];
351
351
  export declare const lockedFigureColors: Record<LockedFigureColor, string>;
352
- export type LockedFigure = LockedPointType | LockedLineType;
352
+ export type LockedFigure = LockedPointType | LockedLineType | LockedEllipseType | LockedVectorType;
353
353
  export type LockedFigureType = LockedFigure["type"];
354
354
  export type LockedPointType = {
355
355
  type: "point";
@@ -366,6 +366,22 @@ export type LockedLineType = {
366
366
  showPoint1: boolean;
367
367
  showPoint2: boolean;
368
368
  };
369
+ export type LockedEllipseFillType = "none" | "solid" | "translucent";
370
+ export declare const lockedEllipseFillStyles: Record<LockedEllipseFillType, number>;
371
+ export type LockedEllipseType = {
372
+ type: "ellipse";
373
+ center: Coord;
374
+ radius: [x: number, y: number];
375
+ angle: number;
376
+ color: LockedFigureColor;
377
+ fillStyle: LockedEllipseFillType;
378
+ strokeStyle: "solid" | "dashed";
379
+ };
380
+ export type LockedVectorType = {
381
+ type: "vector";
382
+ points: [tail: Coord, tip: Coord];
383
+ color: LockedFigureColor;
384
+ };
369
385
  export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
370
386
  export type PerseusGraphTypeCommon = {
371
387
  coord?: Coord;
@@ -390,7 +406,7 @@ export type PerseusGraphTypeLinear = {
390
406
  } & PerseusGraphTypeCommon;
391
407
  export type PerseusGraphTypeLinearSystem = {
392
408
  type: "linear-system";
393
- coords?: ReadonlyArray<CollinearTuple>;
409
+ coords?: CollinearTuple[];
394
410
  } & PerseusGraphTypeCommon;
395
411
  export type PerseusGraphTypePoint = {
396
412
  type: "point";
@@ -413,7 +429,7 @@ export type PerseusGraphTypeQuadratic = {
413
429
  export type PerseusGraphTypeSegment = {
414
430
  type: "segment";
415
431
  numSegments?: number;
416
- coords?: ReadonlyArray<CollinearTuple>;
432
+ coords?: CollinearTuple[];
417
433
  } & PerseusGraphTypeCommon;
418
434
  export type PerseusGraphTypeSinusoid = {
419
435
  type: "sinusoid";
@@ -144,11 +144,12 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
144
144
  polygon?: boolean | undefined;
145
145
  linear?: boolean | undefined;
146
146
  quadratic?: boolean | undefined;
147
+ sinusoid?: boolean | undefined;
147
148
  segment?: boolean | undefined;
148
149
  "linear-system"?: boolean | undefined;
149
150
  ray?: boolean | undefined;
150
151
  } & {
151
- "interactive-graph-locked-features-m1"?: boolean | undefined;
152
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
152
153
  }) | undefined;
153
154
  } | undefined;
154
155
  onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
package/dist/types.d.ts CHANGED
@@ -77,8 +77,8 @@ 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"];
81
- export declare const InteractiveGraphLockedFeaturesFlags: readonly ["interactive-graph-locked-features-m1"];
80
+ export declare const MafsGraphTypeFlags: readonly ["segment", "linear", "linear-system", "ray", "polygon", "circle", "quadratic", "sinusoid"];
81
+ export declare const InteractiveGraphLockedFeaturesFlags: readonly ["interactive-graph-locked-features-m2"];
82
82
  /**
83
83
  * APIOptions provides different ways to customize the behaviour of Perseus.
84
84
  *
@@ -14,6 +14,7 @@ export declare function sign(val: number): 0 | 1 | -1;
14
14
  export declare function ccw(a: Coord, b: Coord, c: Coord): number;
15
15
  export declare function collinear(a: Coord, b: Coord, c: Coord): boolean;
16
16
  export declare function intersects(ab: Line, cd: Line): boolean;
17
+ export declare function polygonSidesIntersect(vertices: Coord[]): boolean;
17
18
  export declare function vector(a: any, b: any): number[];
18
19
  export declare function reverseVector(vector: Coord): Coord;
19
20
  export declare function clockwise(points: Coord[]): boolean;
@@ -138,11 +138,12 @@ declare const _default: Readonly<{
138
138
  polygon?: boolean | undefined;
139
139
  linear?: boolean | undefined;
140
140
  quadratic?: boolean | undefined;
141
+ sinusoid?: boolean | undefined;
141
142
  segment?: boolean | undefined;
142
143
  "linear-system"?: boolean | undefined;
143
144
  ray?: boolean | undefined;
144
145
  } & {
145
- "interactive-graph-locked-features-m1"?: boolean | undefined;
146
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
146
147
  }) | undefined;
147
148
  } | undefined;
148
149
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -213,11 +214,12 @@ declare const _default: Readonly<{
213
214
  polygon?: boolean | undefined;
214
215
  linear?: boolean | undefined;
215
216
  quadratic?: boolean | undefined;
217
+ sinusoid?: boolean | undefined;
216
218
  segment?: boolean | undefined;
217
219
  "linear-system"?: boolean | undefined;
218
220
  ray?: boolean | undefined;
219
221
  } & {
220
- "interactive-graph-locked-features-m1"?: boolean | undefined;
222
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
221
223
  }) | undefined;
222
224
  } | undefined;
223
225
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -288,11 +290,12 @@ declare const _default: Readonly<{
288
290
  polygon?: boolean | undefined;
289
291
  linear?: boolean | undefined;
290
292
  quadratic?: boolean | undefined;
293
+ sinusoid?: boolean | undefined;
291
294
  segment?: boolean | undefined;
292
295
  "linear-system"?: boolean | undefined;
293
296
  ray?: boolean | undefined;
294
297
  } & {
295
- "interactive-graph-locked-features-m1"?: boolean | undefined;
298
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
296
299
  }) | undefined;
297
300
  } | undefined;
298
301
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -360,11 +363,12 @@ declare const _default: Readonly<{
360
363
  polygon?: boolean | undefined;
361
364
  linear?: boolean | undefined;
362
365
  quadratic?: boolean | undefined;
366
+ sinusoid?: boolean | undefined;
363
367
  segment?: boolean | undefined;
364
368
  "linear-system"?: boolean | undefined;
365
369
  ray?: boolean | undefined;
366
370
  } & {
367
- "interactive-graph-locked-features-m1"?: boolean | undefined;
371
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
368
372
  }) | undefined;
369
373
  } | undefined;
370
374
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -435,11 +439,12 @@ declare const _default: Readonly<{
435
439
  polygon?: boolean | undefined;
436
440
  linear?: boolean | undefined;
437
441
  quadratic?: boolean | undefined;
442
+ sinusoid?: boolean | undefined;
438
443
  segment?: boolean | undefined;
439
444
  "linear-system"?: boolean | undefined;
440
445
  ray?: boolean | undefined;
441
446
  } & {
442
- "interactive-graph-locked-features-m1"?: boolean | undefined;
447
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
443
448
  }) | undefined;
444
449
  } | undefined;
445
450
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -510,11 +515,12 @@ declare const _default: Readonly<{
510
515
  polygon?: boolean | undefined;
511
516
  linear?: boolean | undefined;
512
517
  quadratic?: boolean | undefined;
518
+ sinusoid?: boolean | undefined;
513
519
  segment?: boolean | undefined;
514
520
  "linear-system"?: boolean | undefined;
515
521
  ray?: boolean | undefined;
516
522
  } & {
517
- "interactive-graph-locked-features-m1"?: boolean | undefined;
523
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
518
524
  }) | undefined;
519
525
  } | undefined;
520
526
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -0,0 +1 @@
1
+ export type CSSCursor = "move" | "ew-resize";
@@ -1,10 +1,12 @@
1
1
  import * as React from "react";
2
+ import type { CSSCursor } from "./css-cursor";
2
3
  import type { vec } from "mafs";
3
4
  type Props = {
4
5
  point: vec.Vector2;
5
6
  color?: string | undefined;
6
7
  dragging: boolean;
7
8
  focusBehavior: FocusBehaviorConfig;
9
+ cursor?: CSSCursor | undefined;
8
10
  };
9
11
  type FocusBehaviorConfig = {
10
12
  type: "uncontrolled";
@@ -1,9 +1,11 @@
1
1
  /// <reference types="react" />
2
+ import type { CSSCursor } from "./css-cursor";
2
3
  import type { vec } from "mafs";
3
4
  type Props = {
4
5
  point: vec.Vector2;
5
6
  onMove: (newPoint: vec.Vector2) => unknown;
6
7
  color?: string;
8
+ cursor?: CSSCursor | undefined;
7
9
  };
8
10
  export declare const StyledMovablePoint: (props: Props) => JSX.Element;
9
11
  export {};
@@ -1,6 +1,8 @@
1
1
  export { SegmentGraph } from "./segment";
2
2
  export { LinearGraph } from "./linear";
3
+ export { LinearSystemGraph } from "./linear-system";
3
4
  export { RayGraph } from "./ray";
4
5
  export { PolygonGraph } from "./polygon";
5
6
  export { CircleGraph } from "./circle";
6
7
  export { QuadraticGraph } from "./quadratic";
8
+ export { SinusoidGraph } from "./sinusoid";
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { MafsGraphProps, LinearSystemGraphState } from "../types";
3
+ type LinearSystemGraphProps = MafsGraphProps<LinearSystemGraphState>;
4
+ export declare const LinearSystemGraph: (props: LinearSystemGraphProps) => JSX.Element;
5
+ export {};
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import type { MafsGraphProps, LinearGraphState } from "../types";
3
3
  type LinearGraphProps = MafsGraphProps<LinearGraphState>;
4
- export declare const LinearGraph: (props: LinearGraphProps) => JSX.Element;
4
+ export declare const LinearGraph: (props: LinearGraphProps, key: number) => JSX.Element;
5
5
  export {};
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import type { Coord } from "../../../interactive2/types";
3
+ import type { SinusoidGraphState, MafsGraphProps } from "../types";
4
+ type SinusoidGraphProps = MafsGraphProps<SinusoidGraphState>;
5
+ export type SineCoefficient = {
6
+ amplitude: number;
7
+ angularFrequency: number;
8
+ phase: number;
9
+ verticalOffset: number;
10
+ };
11
+ export declare function SinusoidGraph(props: SinusoidGraphProps): JSX.Element;
12
+ export declare const computeSine: (x: number, sinusoidCoefficients: SineCoefficient) => number;
13
+ export declare const getSinusoidCoefficients: (coords: ReadonlyArray<Coord>) => SineCoefficient;
14
+ export {};
@@ -1,4 +1,4 @@
1
- import type { PerseusRenderer } from "../../perseus-types";
1
+ import type { LockedEllipseFillType, LockedFigureColor, PerseusRenderer } from "../../perseus-types";
2
2
  import type { vec } from "mafs";
3
3
  export declare function interactiveGraphQuestionBuilder(): InteractiveGraphQuestionBuilder;
4
4
  declare class InteractiveGraphQuestionBuilder {
@@ -23,6 +23,13 @@ declare class InteractiveGraphQuestionBuilder {
23
23
  withCircle(): InteractiveGraphQuestionBuilder;
24
24
  addLockedPointAt(x: number, y: number): InteractiveGraphQuestionBuilder;
25
25
  addLockedLine(point1: vec.Vector2, point2: vec.Vector2): InteractiveGraphQuestionBuilder;
26
+ addLockedEllipse(center: vec.Vector2, radius: [x: number, y: number], options?: {
27
+ angle?: number;
28
+ color?: LockedFigureColor;
29
+ fillStyle?: LockedEllipseFillType;
30
+ strokeStyle?: "solid" | "dashed";
31
+ }): InteractiveGraphQuestionBuilder;
32
+ addLockedVector(tail: vec.Vector2, tip: vec.Vector2, color?: LockedFigureColor): InteractiveGraphQuestionBuilder;
26
33
  private createLockedPoint;
27
34
  private addLockedFigure;
28
35
  }
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import { type LockedEllipseType } from "../../perseus-types";
3
+ declare const LockedEllipse: (props: LockedEllipseType) => JSX.Element;
4
+ export default LockedEllipse;
@@ -0,0 +1,4 @@
1
+ /// <reference types="react" />
2
+ import type { LockedVectorType } from "../../perseus-types";
3
+ declare const LockedVector: (props: LockedVectorType) => JSX.Element;
4
+ export default LockedVector;
@@ -1,3 +1,3 @@
1
- export declare const mafsSupportedGraphTypes: readonly ["segment", "linear", "linear-system", "ray", "polygon", "point", "circle", "quadratic"];
1
+ export declare const mafsSupportedGraphTypes: readonly ["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>;
@@ -4,7 +4,7 @@ export type InitializeGraphStateParam = {
4
4
  range: InteractiveGraphProps["range"];
5
5
  step: InteractiveGraphProps["step"];
6
6
  snapStep: InteractiveGraphProps["snapStep"];
7
- graph: InteractiveGraphProps["graph"];
7
+ graph: PerseusGraphType;
8
8
  };
9
9
  export declare function initializeGraphState(params: InitializeGraphStateParam): InteractiveGraphState;
10
10
  export declare function getGradableGraph(state: InteractiveGraphState, initialGraph: PerseusGraphType): PerseusGraphType;
@@ -1,5 +1,5 @@
1
1
  import type { InteractiveGraphAction } from "./reducer/interactive-graph-action";
2
- import type { PerseusGraphType, PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
2
+ import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
3
3
  import type { WidgetProps } from "../../types";
4
4
  import type { Coord } from "@khanacademy/perseus";
5
5
  import type { Interval, vec } from "mafs";
@@ -8,12 +8,7 @@ export type MafsGraphProps<T extends InteractiveGraphState> = {
8
8
  graphState: T;
9
9
  dispatch: (action: InteractiveGraphAction) => unknown;
10
10
  };
11
- export interface InitializeGraphStateParams<T extends PerseusGraphType> {
12
- graph: T;
13
- range: [Interval, Interval];
14
- step: vec.Vector2;
15
- }
16
- export type InteractiveGraphState = SegmentGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState;
11
+ export type InteractiveGraphState = SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState;
17
12
  export interface InteractiveGraphStateCommon {
18
13
  hasBeenInteractedWith: boolean;
19
14
  range: [xRange: Interval, yRange: Interval];
@@ -24,7 +19,11 @@ export interface SegmentGraphState extends InteractiveGraphStateCommon {
24
19
  coords: PairOfPoints[];
25
20
  }
26
21
  export interface LinearGraphState extends InteractiveGraphStateCommon {
27
- type: "linear" | "linear-system";
22
+ type: "linear";
23
+ coords: PairOfPoints;
24
+ }
25
+ export interface LinearSystemGraphState extends InteractiveGraphStateCommon {
26
+ type: "linear-system";
28
27
  coords: PairOfPoints[];
29
28
  }
30
29
  export interface PointGraphState extends InteractiveGraphStateCommon {
@@ -33,7 +32,7 @@ export interface PointGraphState extends InteractiveGraphStateCommon {
33
32
  }
34
33
  export interface RayGraphState extends InteractiveGraphStateCommon {
35
34
  type: "ray";
36
- coords: PairOfPoints[];
35
+ coords: PairOfPoints;
37
36
  }
38
37
  export interface PolygonGraphState extends InteractiveGraphStateCommon {
39
38
  type: "polygon";
@@ -50,6 +49,10 @@ export interface QuadraticGraphState extends InteractiveGraphStateCommon {
50
49
  type: "quadratic";
51
50
  coords: [Coord, Coord, Coord];
52
51
  }
52
+ export interface SinusoidGraphState extends InteractiveGraphStateCommon {
53
+ type: "sinusoid";
54
+ coords: [vec.Vector2, vec.Vector2];
55
+ }
53
56
  export type PairOfPoints = [Coord, Coord];
54
57
  export type GraphDimensions = {
55
58
  range: [Interval, Interval];
@@ -132,11 +132,12 @@ declare const _default: Readonly<{
132
132
  polygon?: boolean | undefined;
133
133
  linear?: boolean | undefined;
134
134
  quadratic?: boolean | undefined;
135
+ sinusoid?: boolean | undefined;
135
136
  segment?: boolean | undefined;
136
137
  "linear-system"?: boolean | undefined;
137
138
  ray?: boolean | undefined;
138
139
  } & {
139
- "interactive-graph-locked-features-m1"?: boolean | undefined;
140
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
140
141
  }) | undefined;
141
142
  } | undefined;
142
143
  onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
@@ -191,11 +192,12 @@ declare const _default: Readonly<{
191
192
  polygon?: boolean | undefined;
192
193
  linear?: boolean | undefined;
193
194
  quadratic?: boolean | undefined;
195
+ sinusoid?: boolean | undefined;
194
196
  segment?: boolean | undefined;
195
197
  "linear-system"?: boolean | undefined;
196
198
  ray?: boolean | undefined;
197
199
  } & {
198
- "interactive-graph-locked-features-m1"?: boolean | undefined;
200
+ "interactive-graph-locked-features-m2"?: boolean | undefined;
199
201
  }) | undefined;
200
202
  } | undefined;
201
203
  onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | 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": "23.0.0",
6
+ "version": "23.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },