@khanacademy/perseus 25.0.0 → 25.1.1

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.
@@ -106,6 +106,8 @@ export declare const ApiOptions: {
106
106
  } & {
107
107
  "interactive-graph-locked-features-m2"?: boolean | undefined;
108
108
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
109
+ } & {
110
+ "start-coords-ui"?: boolean | undefined;
109
111
  }) | undefined;
110
112
  } | undefined;
111
113
  onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -417,24 +417,29 @@ export type PerseusGraphTypeAngle = {
417
417
  snapDegrees?: number;
418
418
  match?: "congruent";
419
419
  coords?: [Coord, Coord, Coord];
420
+ startCoords?: [Coord, Coord, Coord];
420
421
  };
421
422
  export type PerseusGraphTypeCircle = {
422
423
  type: "circle";
423
424
  center?: Coord;
424
425
  radius?: number;
426
+ startCoords?: Coord;
425
427
  } & PerseusGraphTypeCommon;
426
428
  export type PerseusGraphTypeLinear = {
427
429
  type: "linear";
428
430
  coords?: CollinearTuple;
431
+ startCoords?: CollinearTuple;
429
432
  } & PerseusGraphTypeCommon;
430
433
  export type PerseusGraphTypeLinearSystem = {
431
434
  type: "linear-system";
432
435
  coords?: CollinearTuple[];
436
+ startCoords?: CollinearTuple[];
433
437
  } & PerseusGraphTypeCommon;
434
438
  export type PerseusGraphTypePoint = {
435
439
  type: "point";
436
440
  numPoints?: number | "unlimited";
437
441
  coords?: ReadonlyArray<Coord>;
442
+ startCoords?: ReadonlyArray<Coord>;
438
443
  } & PerseusGraphTypeCommon;
439
444
  export type PerseusGraphTypePolygon = {
440
445
  type: "polygon";
@@ -444,23 +449,28 @@ export type PerseusGraphTypePolygon = {
444
449
  snapTo?: "grid" | "angles" | "sides";
445
450
  match?: "similar" | "congruent" | "approx";
446
451
  coords?: ReadonlyArray<Coord>;
452
+ startCoords?: ReadonlyArray<Coord>;
447
453
  } & PerseusGraphTypeCommon;
448
454
  export type PerseusGraphTypeQuadratic = {
449
455
  type: "quadratic";
450
456
  coords?: [Coord, Coord, Coord];
457
+ startCoords?: [Coord, Coord, Coord];
451
458
  } & PerseusGraphTypeCommon;
452
459
  export type PerseusGraphTypeSegment = {
453
460
  type: "segment";
454
461
  numSegments?: number;
455
462
  coords?: CollinearTuple[];
463
+ startCoords?: CollinearTuple[];
456
464
  } & PerseusGraphTypeCommon;
457
465
  export type PerseusGraphTypeSinusoid = {
458
466
  type: "sinusoid";
459
467
  coords?: ReadonlyArray<Coord>;
468
+ startCoords?: ReadonlyArray<Coord>;
460
469
  } & PerseusGraphTypeCommon;
461
470
  export type PerseusGraphTypeRay = {
462
471
  type: "ray";
463
472
  coords?: CollinearTuple;
473
+ startCoords?: CollinearTuple;
464
474
  } & PerseusGraphTypeCommon;
465
475
  export type PerseusLabelImageWidgetOptions = {
466
476
  choices: ReadonlyArray<string>;
@@ -153,6 +153,8 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
153
153
  } & {
154
154
  "interactive-graph-locked-features-m2"?: boolean | undefined;
155
155
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
156
+ } & {
157
+ "start-coords-ui"?: boolean | undefined;
156
158
  }) | undefined;
157
159
  } | undefined;
158
160
  onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
package/dist/types.d.ts CHANGED
@@ -79,6 +79,7 @@ type TrackInteractionArgs = {
79
79
  } & Partial<TrackingGradedGroupExtraArguments> & Partial<TrackingSequenceExtraArguments>;
80
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
+ export declare const InteractiveGraphEditorFlags: readonly ["start-coords-ui"];
82
83
  /**
83
84
  * APIOptions provides different ways to customize the behaviour of Perseus.
84
85
  *
@@ -206,6 +207,8 @@ export type APIOptions = Readonly<{
206
207
  [Key in (typeof MafsGraphTypeFlags)[number]]?: boolean;
207
208
  } & {
208
209
  [Key in (typeof InteractiveGraphLockedFeaturesFlags)[number]]?: boolean;
210
+ } & {
211
+ [Key in (typeof InteractiveGraphEditorFlags)[number]]?: boolean;
209
212
  });
210
213
  };
211
214
  /**
@@ -147,6 +147,8 @@ declare const _default: Readonly<{
147
147
  } & {
148
148
  "interactive-graph-locked-features-m2"?: boolean | undefined;
149
149
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
150
+ } & {
151
+ "start-coords-ui"?: boolean | undefined;
150
152
  }) | undefined;
151
153
  } | undefined;
152
154
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -226,6 +228,8 @@ declare const _default: Readonly<{
226
228
  } & {
227
229
  "interactive-graph-locked-features-m2"?: boolean | undefined;
228
230
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
231
+ } & {
232
+ "start-coords-ui"?: boolean | undefined;
229
233
  }) | undefined;
230
234
  } | undefined;
231
235
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -305,6 +309,8 @@ declare const _default: Readonly<{
305
309
  } & {
306
310
  "interactive-graph-locked-features-m2"?: boolean | undefined;
307
311
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
312
+ } & {
313
+ "start-coords-ui"?: boolean | undefined;
308
314
  }) | undefined;
309
315
  } | undefined;
310
316
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -381,6 +387,8 @@ declare const _default: Readonly<{
381
387
  } & {
382
388
  "interactive-graph-locked-features-m2"?: boolean | undefined;
383
389
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
390
+ } & {
391
+ "start-coords-ui"?: boolean | undefined;
384
392
  }) | undefined;
385
393
  } | undefined;
386
394
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -460,6 +468,8 @@ declare const _default: Readonly<{
460
468
  } & {
461
469
  "interactive-graph-locked-features-m2"?: boolean | undefined;
462
470
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
471
+ } & {
472
+ "start-coords-ui"?: boolean | undefined;
463
473
  }) | undefined;
464
474
  } | undefined;
465
475
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -539,6 +549,8 @@ declare const _default: Readonly<{
539
549
  } & {
540
550
  "interactive-graph-locked-features-m2"?: boolean | undefined;
541
551
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
552
+ } & {
553
+ "start-coords-ui"?: boolean | undefined;
542
554
  }) | undefined;
543
555
  } | undefined;
544
556
  onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
- import type { GraphRange } from "../../perseus-types";
3
- import type { SizeClass } from "../../util/sizing-utils";
2
+ import type { GraphRange } from "../../../perseus-types";
3
+ import type { SizeClass } from "../../../util/sizing-utils";
4
4
  import type { vec } from "mafs";
5
5
  interface GridProps {
6
6
  tickStep: vec.Vector2;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { PerseusImageBackground } from "../../perseus-types";
2
+ import type { PerseusImageBackground } from "../../../perseus-types";
3
3
  interface Props {
4
4
  box: [number, number];
5
5
  backgroundImage?: PerseusImageBackground;
@@ -4,6 +4,8 @@ import type { vec } from "mafs";
4
4
  export type LockedFunctionOptions = Omit<Partial<LockedFunctionType>, "type" | "equation">;
5
5
  export declare function interactiveGraphQuestionBuilder(): InteractiveGraphQuestionBuilder;
6
6
  declare class InteractiveGraphQuestionBuilder {
7
+ private content;
8
+ private backgroundImage?;
7
9
  private gridStep;
8
10
  private labels;
9
11
  private markings;
@@ -15,6 +17,14 @@ declare class InteractiveGraphQuestionBuilder {
15
17
  private interactiveFigureConfig;
16
18
  private lockedFigures;
17
19
  build(): PerseusRenderer;
20
+ withContent(content: string): InteractiveGraphQuestionBuilder;
21
+ withBackgroundImage(url: string, height: number, width: number, options?: {
22
+ scale?: number;
23
+ bottom?: number;
24
+ left?: number;
25
+ right?: number;
26
+ top?: number;
27
+ }): InteractiveGraphQuestionBuilder;
18
28
  withGridStep(x: number, y: number): InteractiveGraphQuestionBuilder;
19
29
  withAxisLabels(x: string, y: string): InteractiveGraphQuestionBuilder;
20
30
  withMarkings(markings: "graph" | "grid" | "none"): InteractiveGraphQuestionBuilder;
@@ -23,17 +33,69 @@ declare class InteractiveGraphQuestionBuilder {
23
33
  withSnapStep(x: number, y: number): InteractiveGraphQuestionBuilder;
24
34
  withTickStep(x: number, y: number): InteractiveGraphQuestionBuilder;
25
35
  withProtractor(): InteractiveGraphQuestionBuilder;
26
- withSegments(startCoords: CollinearTuple[]): InteractiveGraphQuestionBuilder;
27
- withNumSegments(numSegments: number): InteractiveGraphQuestionBuilder;
28
- withLinear(startCoords?: CollinearTuple): InteractiveGraphQuestionBuilder;
29
- withLinearSystem(startCoords?: CollinearTuple[]): InteractiveGraphQuestionBuilder;
30
- withRay(startCoords?: CollinearTuple): InteractiveGraphQuestionBuilder;
31
- withCircle(startCoords?: Coord): InteractiveGraphQuestionBuilder;
32
- withQuadratic(startCoords?: [Coord, Coord, Coord]): InteractiveGraphQuestionBuilder;
33
- withSinusoid(startCoords?: [Coord, Coord]): InteractiveGraphQuestionBuilder;
34
- withPolygon(snapTo: "grid" | "angles" | "sides"): InteractiveGraphQuestionBuilder;
35
- addLockedPointAt(x: number, y: number): InteractiveGraphQuestionBuilder;
36
- addLockedLine(point1: vec.Vector2, point2: vec.Vector2): InteractiveGraphQuestionBuilder;
36
+ withSegments(options?: {
37
+ numSegments?: number;
38
+ startCoords?: CollinearTuple[];
39
+ coords?: CollinearTuple[];
40
+ }): InteractiveGraphQuestionBuilder;
41
+ withLinear(options?: {
42
+ coords?: CollinearTuple;
43
+ startCoords?: CollinearTuple;
44
+ }): InteractiveGraphQuestionBuilder;
45
+ withLinearSystem(options?: {
46
+ coords?: CollinearTuple[];
47
+ startCoords?: CollinearTuple[];
48
+ }): InteractiveGraphQuestionBuilder;
49
+ withRay(options?: {
50
+ coords?: CollinearTuple;
51
+ startCoords?: CollinearTuple;
52
+ }): InteractiveGraphQuestionBuilder;
53
+ withCircle(options?: {
54
+ center?: Coord;
55
+ radius?: number;
56
+ startCoords?: Coord;
57
+ }): InteractiveGraphQuestionBuilder;
58
+ withQuadratic(options?: {
59
+ coords?: [Coord, Coord, Coord];
60
+ startCoords?: [Coord, Coord, Coord];
61
+ }): InteractiveGraphQuestionBuilder;
62
+ withSinusoid(options?: {
63
+ coords?: [Coord, Coord];
64
+ startCoords?: [Coord, Coord];
65
+ }): InteractiveGraphQuestionBuilder;
66
+ withPolygon(snapTo: "grid" | "angles" | "sides", options?: {
67
+ match?: "similar" | "congruent" | "approx";
68
+ numSides?: number | "unlimited";
69
+ showAngles?: boolean;
70
+ showSides?: boolean;
71
+ coords?: Coord[];
72
+ startCoords?: Coord[];
73
+ }): InteractiveGraphQuestionBuilder;
74
+ withPoints(numPoints: number | "unlimited", options?: {
75
+ coords?: Coord[];
76
+ startCoords?: Coord[];
77
+ }): InteractiveGraphQuestionBuilder;
78
+ withAngle(options?: {
79
+ coords?: [Coord, Coord, Coord];
80
+ startCoords?: [Coord, Coord, Coord];
81
+ showAngles?: boolean;
82
+ allowReflexAngles?: boolean;
83
+ angleOffsetDeg?: number;
84
+ snapDegrees?: number;
85
+ match?: "congruent";
86
+ }): InteractiveGraphQuestionBuilder;
87
+ addLockedPointAt(x: number, y: number, options?: {
88
+ color?: LockedFigureColor;
89
+ filled?: boolean;
90
+ }): InteractiveGraphQuestionBuilder;
91
+ addLockedLine(point1: vec.Vector2, point2: vec.Vector2, options?: {
92
+ kind?: "line" | "ray" | "segment";
93
+ lineStyle?: "solid" | "dashed";
94
+ color?: LockedFigureColor;
95
+ filled?: [boolean, boolean];
96
+ showPoint1?: boolean;
97
+ showPoint2?: boolean;
98
+ }): InteractiveGraphQuestionBuilder;
37
99
  addLockedVector(tail: vec.Vector2, tip: vec.Vector2, color?: LockedFigureColor): InteractiveGraphQuestionBuilder;
38
100
  addLockedEllipse(center: vec.Vector2, radius: [x: number, y: number], options?: {
39
101
  angle?: number;
@@ -1,5 +1,5 @@
1
- import type { PerseusGraphType } from "../../../perseus-types";
2
- import type { InteractiveGraphState } from "../types";
1
+ import type { PerseusGraphType, PerseusGraphTypeLinear, PerseusGraphTypeRay } from "../../../perseus-types";
2
+ import type { InteractiveGraphState, PairOfPoints } from "../types";
3
3
  import type { Interval } from "mafs";
4
4
  export type InitializeGraphStateParams = {
5
5
  range: [x: Interval, y: Interval];
@@ -8,3 +8,4 @@ export type InitializeGraphStateParams = {
8
8
  graph: PerseusGraphType;
9
9
  };
10
10
  export declare function initializeGraphState(params: InitializeGraphStateParams): InteractiveGraphState;
11
+ export declare function getLineCoords(graph: PerseusGraphTypeRay | PerseusGraphTypeLinear, range: [x: Interval, y: Interval], step: [x: number, y: number]): PairOfPoints;
@@ -1,55 +1,84 @@
1
1
  import type { InitializeGraphStateParams } from "./initialize-graph-state";
2
2
  import type { Interval, vec } from "mafs";
3
- export type InteractiveGraphAction = Reinitialize | MoveControlPoint | MoveLine | MoveAll | MovePoint | MoveCenter | MoveRadiusPoint | ChangeSnapStep | ChangeRange;
4
- export declare const REINITIALIZE = "reinitialize";
5
- export interface Reinitialize {
6
- type: typeof REINITIALIZE;
7
- params: InitializeGraphStateParams;
8
- }
9
- export declare function reinitialize(params: InitializeGraphStateParams): Reinitialize;
10
- export declare const MOVE_CONTROL_POINT = "move-control-point";
11
- export interface MoveControlPoint {
12
- type: typeof MOVE_CONTROL_POINT;
13
- itemIndex: number;
14
- pointIndex: number;
15
- destination: vec.Vector2;
16
- }
17
- export declare function moveControlPoint(pointIndex: number, destination: vec.Vector2, itemIndex: number): MoveControlPoint;
18
- export declare const MOVE_ALL = "move-all";
3
+ export type InteractiveGraphAction = Reinitialize | MovePointInFigure | MoveLine | MoveAll | MovePoint | MoveCenter | MoveRadiusPoint | ChangeSnapStep | ChangeRange;
4
+ export declare const actions: {
5
+ angle: {
6
+ movePoint: typeof movePoint;
7
+ };
8
+ circle: {
9
+ moveCenter: typeof moveCenter;
10
+ moveRadiusPoint: typeof moveRadiusPoint;
11
+ };
12
+ linear: {
13
+ moveLine: (delta: vec.Vector2) => MoveLine;
14
+ movePoint: (pointIndex: any, destination: any) => MovePointInFigure;
15
+ };
16
+ linearSystem: {
17
+ moveLine: typeof moveLine;
18
+ movePointInFigure: typeof movePointInFigure;
19
+ };
20
+ pointGraph: {
21
+ movePoint: typeof movePoint;
22
+ };
23
+ polygon: {
24
+ movePoint: typeof movePoint;
25
+ moveAll: typeof moveAll;
26
+ };
27
+ quadratic: {
28
+ movePoint: typeof movePoint;
29
+ };
30
+ ray: {
31
+ moveRay: (delta: vec.Vector2) => MoveLine;
32
+ movePoint: (pointIndex: any, destination: any) => MovePointInFigure;
33
+ };
34
+ segment: {
35
+ movePointInFigure: typeof movePointInFigure;
36
+ moveLine: typeof moveLine;
37
+ };
38
+ sinusoid: {
39
+ movePoint: typeof movePoint;
40
+ };
41
+ };
19
42
  export declare const MOVE_LINE = "move-line";
20
- interface MoveItem {
21
- delta: vec.Vector2;
22
- itemIndex?: number;
23
- }
24
- export interface MoveLine extends MoveItem {
43
+ export interface MoveLine {
25
44
  type: typeof MOVE_LINE;
45
+ itemIndex: number;
46
+ delta: vec.Vector2;
26
47
  }
27
- export interface MoveAll extends MoveItem {
48
+ declare function moveLine(itemIndex: number, delta: vec.Vector2): MoveLine;
49
+ export declare const MOVE_ALL = "move-all";
50
+ export interface MoveAll {
28
51
  type: typeof MOVE_ALL;
52
+ delta: vec.Vector2;
29
53
  }
30
- /** This action assumes the state.coords holds an array of collinear tuples that define lines */
31
- export declare function moveLine(itemIndex: number, delta: vec.Vector2): MoveLine;
32
- /** This action assumes a flat array of vectors */
33
- export declare const moveAll: (delta: vec.Vector2) => MoveAll;
54
+ declare function moveAll(delta: vec.Vector2): MoveAll;
34
55
  export declare const MOVE_POINT = "move-point";
35
56
  export interface MovePoint {
36
57
  type: typeof MOVE_POINT;
37
58
  index: number;
38
59
  destination: vec.Vector2;
39
60
  }
40
- export declare function movePoint(index: number, destination: vec.Vector2): MovePoint;
61
+ declare function movePoint(index: number, destination: vec.Vector2): MovePoint;
62
+ export declare const MOVE_POINT_IN_FIGURE = "move-point-in-figure";
63
+ export interface MovePointInFigure {
64
+ type: typeof MOVE_POINT_IN_FIGURE;
65
+ figureIndex: number;
66
+ pointIndex: number;
67
+ destination: vec.Vector2;
68
+ }
69
+ declare function movePointInFigure(figureIndex: number, pointIndex: number, destination: vec.Vector2): MovePointInFigure;
41
70
  export declare const MOVE_CENTER = "move-center";
42
71
  export interface MoveCenter {
43
72
  type: typeof MOVE_CENTER;
44
73
  destination: vec.Vector2;
45
74
  }
46
- export declare function moveCenter(destination: vec.Vector2): MoveCenter;
75
+ declare function moveCenter(destination: vec.Vector2): MoveCenter;
47
76
  export declare const MOVE_RADIUS_POINT = "MOVE_RADIUS_POINT";
48
77
  export interface MoveRadiusPoint {
49
78
  type: typeof MOVE_RADIUS_POINT;
50
79
  destination: vec.Vector2;
51
80
  }
52
- export declare function moveRadiusPoint(destination: vec.Vector2): MoveRadiusPoint;
81
+ declare function moveRadiusPoint(destination: vec.Vector2): MoveRadiusPoint;
53
82
  export declare const CHANGE_SNAP_STEP = "change-snap-step";
54
83
  export interface ChangeSnapStep {
55
84
  type: typeof CHANGE_SNAP_STEP;
@@ -62,4 +91,10 @@ export interface ChangeRange {
62
91
  range: [x: Interval, y: Interval];
63
92
  }
64
93
  export declare function changeRange(range: [x: Interval, y: Interval]): ChangeRange;
94
+ export declare const REINITIALIZE = "reinitialize";
95
+ export interface Reinitialize {
96
+ type: typeof REINITIALIZE;
97
+ params: InitializeGraphStateParams;
98
+ }
99
+ export declare function reinitialize(params: InitializeGraphStateParams): Reinitialize;
65
100
  export {};
@@ -141,6 +141,8 @@ declare const _default: Readonly<{
141
141
  } & {
142
142
  "interactive-graph-locked-features-m2"?: boolean | undefined;
143
143
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
144
+ } & {
145
+ "start-coords-ui"?: boolean | undefined;
144
146
  }) | undefined;
145
147
  } | undefined;
146
148
  onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
@@ -204,6 +206,8 @@ declare const _default: Readonly<{
204
206
  } & {
205
207
  "interactive-graph-locked-features-m2"?: boolean | undefined;
206
208
  "interactive-graph-locked-features-m2b"?: boolean | undefined;
209
+ } & {
210
+ "start-coords-ui"?: boolean | undefined;
207
211
  }) | undefined;
208
212
  } | undefined;
209
213
  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": "25.0.0",
6
+ "version": "25.1.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },