@khanacademy/perseus 23.1.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.
@@ -102,7 +102,6 @@ export declare const ApiOptions: {
102
102
  "linear-system"?: boolean | undefined;
103
103
  ray?: boolean | undefined;
104
104
  } & {
105
- "interactive-graph-locked-features-m1"?: boolean | undefined;
106
105
  "interactive-graph-locked-features-m2"?: boolean | undefined;
107
106
  }) | undefined;
108
107
  } | 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 | LockedCircleType;
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,14 +366,22 @@ export type LockedLineType = {
366
366
  showPoint1: boolean;
367
367
  showPoint2: boolean;
368
368
  };
369
- export type LockedCircleType = {
370
- type: "circle";
369
+ export type LockedEllipseFillType = "none" | "solid" | "translucent";
370
+ export declare const lockedEllipseFillStyles: Record<LockedEllipseFillType, number>;
371
+ export type LockedEllipseType = {
372
+ type: "ellipse";
371
373
  center: Coord;
372
- radius: number;
374
+ radius: [x: number, y: number];
375
+ angle: number;
373
376
  color: LockedFigureColor;
374
- fillStyle: "none" | "solid" | "translucent";
377
+ fillStyle: LockedEllipseFillType;
375
378
  strokeStyle: "solid" | "dashed";
376
379
  };
380
+ export type LockedVectorType = {
381
+ type: "vector";
382
+ points: [tail: Coord, tip: Coord];
383
+ color: LockedFigureColor;
384
+ };
377
385
  export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
378
386
  export type PerseusGraphTypeCommon = {
379
387
  coord?: Coord;
@@ -398,7 +406,7 @@ export type PerseusGraphTypeLinear = {
398
406
  } & PerseusGraphTypeCommon;
399
407
  export type PerseusGraphTypeLinearSystem = {
400
408
  type: "linear-system";
401
- coords?: ReadonlyArray<CollinearTuple>;
409
+ coords?: CollinearTuple[];
402
410
  } & PerseusGraphTypeCommon;
403
411
  export type PerseusGraphTypePoint = {
404
412
  type: "point";
@@ -421,7 +429,7 @@ export type PerseusGraphTypeQuadratic = {
421
429
  export type PerseusGraphTypeSegment = {
422
430
  type: "segment";
423
431
  numSegments?: number;
424
- coords?: ReadonlyArray<CollinearTuple>;
432
+ coords?: CollinearTuple[];
425
433
  } & PerseusGraphTypeCommon;
426
434
  export type PerseusGraphTypeSinusoid = {
427
435
  type: "sinusoid";
@@ -149,7 +149,6 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
149
149
  "linear-system"?: boolean | undefined;
150
150
  ray?: boolean | undefined;
151
151
  } & {
152
- "interactive-graph-locked-features-m1"?: boolean | undefined;
153
152
  "interactive-graph-locked-features-m2"?: boolean | undefined;
154
153
  }) | undefined;
155
154
  } | undefined;
package/dist/types.d.ts CHANGED
@@ -78,7 +78,7 @@ type TrackInteractionArgs = {
78
78
  correct?: boolean;
79
79
  } & Partial<TrackingGradedGroupExtraArguments> & Partial<TrackingSequenceExtraArguments>;
80
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-m1", "interactive-graph-locked-features-m2"];
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;
@@ -143,7 +143,6 @@ declare const _default: Readonly<{
143
143
  "linear-system"?: boolean | undefined;
144
144
  ray?: boolean | undefined;
145
145
  } & {
146
- "interactive-graph-locked-features-m1"?: boolean | undefined;
147
146
  "interactive-graph-locked-features-m2"?: boolean | undefined;
148
147
  }) | undefined;
149
148
  } | undefined;
@@ -220,7 +219,6 @@ declare const _default: Readonly<{
220
219
  "linear-system"?: boolean | undefined;
221
220
  ray?: boolean | undefined;
222
221
  } & {
223
- "interactive-graph-locked-features-m1"?: boolean | undefined;
224
222
  "interactive-graph-locked-features-m2"?: boolean | undefined;
225
223
  }) | undefined;
226
224
  } | undefined;
@@ -297,7 +295,6 @@ declare const _default: Readonly<{
297
295
  "linear-system"?: boolean | undefined;
298
296
  ray?: boolean | undefined;
299
297
  } & {
300
- "interactive-graph-locked-features-m1"?: boolean | undefined;
301
298
  "interactive-graph-locked-features-m2"?: boolean | undefined;
302
299
  }) | undefined;
303
300
  } | undefined;
@@ -371,7 +368,6 @@ declare const _default: Readonly<{
371
368
  "linear-system"?: boolean | undefined;
372
369
  ray?: boolean | undefined;
373
370
  } & {
374
- "interactive-graph-locked-features-m1"?: boolean | undefined;
375
371
  "interactive-graph-locked-features-m2"?: boolean | undefined;
376
372
  }) | undefined;
377
373
  } | undefined;
@@ -448,7 +444,6 @@ declare const _default: Readonly<{
448
444
  "linear-system"?: boolean | undefined;
449
445
  ray?: boolean | undefined;
450
446
  } & {
451
- "interactive-graph-locked-features-m1"?: boolean | undefined;
452
447
  "interactive-graph-locked-features-m2"?: boolean | undefined;
453
448
  }) | undefined;
454
449
  } | undefined;
@@ -525,7 +520,6 @@ declare const _default: Readonly<{
525
520
  "linear-system"?: boolean | undefined;
526
521
  ray?: boolean | undefined;
527
522
  } & {
528
- "interactive-graph-locked-features-m1"?: boolean | undefined;
529
523
  "interactive-graph-locked-features-m2"?: boolean | undefined;
530
524
  }) | undefined;
531
525
  } | 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,5 +1,6 @@
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";
@@ -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 {};
@@ -1,4 +1,4 @@
1
- import type { LockedFigureColor, 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,11 +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
- addLockedCircle(center: vec.Vector2, radius: number, options?: {
26
+ addLockedEllipse(center: vec.Vector2, radius: [x: number, y: number], options?: {
27
+ angle?: number;
27
28
  color?: LockedFigureColor;
28
- fillStyle?: "none" | "solid" | "translucent";
29
+ fillStyle?: LockedEllipseFillType;
29
30
  strokeStyle?: "solid" | "dashed";
30
31
  }): InteractiveGraphQuestionBuilder;
32
+ addLockedVector(tail: vec.Vector2, tip: vec.Vector2, color?: LockedFigureColor): InteractiveGraphQuestionBuilder;
31
33
  private createLockedPoint;
32
34
  private addLockedFigure;
33
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;
@@ -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 | SinusoidGraphState;
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";
@@ -137,7 +137,6 @@ declare const _default: Readonly<{
137
137
  "linear-system"?: boolean | undefined;
138
138
  ray?: boolean | undefined;
139
139
  } & {
140
- "interactive-graph-locked-features-m1"?: boolean | undefined;
141
140
  "interactive-graph-locked-features-m2"?: boolean | undefined;
142
141
  }) | undefined;
143
142
  } | undefined;
@@ -198,7 +197,6 @@ declare const _default: Readonly<{
198
197
  "linear-system"?: boolean | undefined;
199
198
  ray?: boolean | undefined;
200
199
  } & {
201
- "interactive-graph-locked-features-m1"?: boolean | undefined;
202
200
  "interactive-graph-locked-features-m2"?: boolean | undefined;
203
201
  }) | undefined;
204
202
  } | 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.1.0",
6
+ "version": "23.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -1,4 +0,0 @@
1
- /// <reference types="react" />
2
- import { type LockedCircleType } from "../../perseus-types";
3
- declare const LockedCircle: (props: LockedCircleType) => JSX.Element;
4
- export default LockedCircle;