@khanacademy/perseus 33.2.0 → 33.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.
@@ -95,6 +95,7 @@ export declare const ApiOptions: {
95
95
  mafs?: false | ({
96
96
  circle?: boolean | undefined;
97
97
  polygon?: boolean | undefined;
98
+ none?: boolean | undefined;
98
99
  linear?: boolean | undefined;
99
100
  quadratic?: boolean | undefined;
100
101
  sinusoid?: boolean | undefined;
@@ -387,6 +387,7 @@ export type LockedFigureColor = (typeof lockedFigureColorNames)[number];
387
387
  export declare const lockedFigureColors: Record<LockedFigureColor, string>;
388
388
  export type LockedFigure = LockedPointType | LockedLineType | LockedVectorType | LockedEllipseType | LockedPolygonType | LockedFunctionType | LockedLabelType;
389
389
  export type LockedFigureType = LockedFigure["type"];
390
+ export type LockedLineStyle = "solid" | "dashed";
390
391
  export type LockedPointType = {
391
392
  type: "point";
392
393
  coord: Coord;
@@ -398,7 +399,7 @@ export type LockedLineType = {
398
399
  kind: "line" | "ray" | "segment";
399
400
  points: [point1: LockedPointType, point2: LockedPointType];
400
401
  color: LockedFigureColor;
401
- lineStyle: "solid" | "dashed";
402
+ lineStyle: LockedLineStyle;
402
403
  showPoint1: boolean;
403
404
  showPoint2: boolean;
404
405
  };
@@ -416,7 +417,7 @@ export type LockedEllipseType = {
416
417
  angle: number;
417
418
  color: LockedFigureColor;
418
419
  fillStyle: LockedFigureFillType;
419
- strokeStyle: "solid" | "dashed";
420
+ strokeStyle: LockedLineStyle;
420
421
  };
421
422
  export type LockedPolygonType = {
422
423
  type: "polygon";
@@ -424,12 +425,12 @@ export type LockedPolygonType = {
424
425
  color: LockedFigureColor;
425
426
  showVertices: boolean;
426
427
  fillStyle: LockedFigureFillType;
427
- strokeStyle: "solid" | "dashed";
428
+ strokeStyle: LockedLineStyle;
428
429
  };
429
430
  export type LockedFunctionType = {
430
431
  type: "function";
431
432
  color: LockedFigureColor;
432
- strokeStyle: "solid" | "dashed";
433
+ strokeStyle: LockedLineStyle;
433
434
  equation: string;
434
435
  directionalAxis: "x" | "y";
435
436
  domain?: Interval;
@@ -441,7 +442,7 @@ export type LockedLabelType = {
441
442
  color: LockedFigureColor;
442
443
  size: "small" | "medium" | "large";
443
444
  };
444
- export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
445
+ export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypeNone | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
445
446
  export type PerseusGraphTypeCommon = {
446
447
  coord?: Coord;
447
448
  };
@@ -474,6 +475,9 @@ export type PerseusGraphTypeLinearSystem = {
474
475
  coords?: CollinearTuple[] | null;
475
476
  startCoords?: CollinearTuple[];
476
477
  } & PerseusGraphTypeCommon;
478
+ export type PerseusGraphTypeNone = {
479
+ type: "none";
480
+ };
477
481
  export type PerseusGraphTypePoint = {
478
482
  type: "point";
479
483
  numPoints?: number | "unlimited";
@@ -140,6 +140,7 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<SharedRendererProps
140
140
  mafs?: false | ({
141
141
  circle?: boolean | undefined;
142
142
  polygon?: boolean | undefined;
143
+ none?: boolean | undefined;
143
144
  linear?: boolean | undefined;
144
145
  quadratic?: boolean | undefined;
145
146
  sinusoid?: boolean | undefined;
package/dist/types.d.ts CHANGED
@@ -74,7 +74,7 @@ type TrackInteractionArgs = {
74
74
  id: string;
75
75
  correct?: boolean;
76
76
  } & Partial<TrackingGradedGroupExtraArguments> & Partial<TrackingSequenceExtraArguments>;
77
- export declare const MafsGraphTypeFlags: readonly ["angle", "segment", "linear", "linear-system", "ray", "polygon", "circle", "quadratic", "sinusoid", "point", "unlimited-point"];
77
+ export declare const MafsGraphTypeFlags: readonly ["angle", "segment", "linear", "linear-system", "ray", "polygon", "circle", "quadratic", "sinusoid", "point", "unlimited-point", "none"];
78
78
  export declare const InteractiveGraphLockedFeaturesFlags: readonly ["interactive-graph-locked-features-labels"];
79
79
  /**
80
80
  * APIOptions provides different ways to customize the behaviour of Perseus.
package/dist/util.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Range } from "./perseus-types";
3
3
  import type { PerseusStrings } from "./strings";
4
4
  import type { Widget, PerseusScore } from "./types";
5
5
  import type { KEScore } from "@khanacademy/perseus-core";
6
+ import type * as React from "react";
6
7
  type WordPosition = {
7
8
  start: number;
8
9
  end: number;
@@ -173,7 +174,7 @@ declare function extractPointerLocation(event: any): Position | null | undefined
173
174
  * Pass this function as the touchstart for an element to
174
175
  * avoid sending the touch to the mobile scratchpad
175
176
  */
176
- declare function captureScratchpadTouchStart(e: TouchEvent): void;
177
+ declare function captureScratchpadTouchStart(e: React.TouchEvent): void;
177
178
  declare function getImageSize(url: string, callback: (width: number, height: number) => void): void;
178
179
  /**
179
180
  * Gets the word right before where the textarea cursor is
@@ -141,6 +141,7 @@ declare const _default: Readonly<{
141
141
  mafs?: false | ({
142
142
  circle?: boolean | undefined;
143
143
  polygon?: boolean | undefined;
144
+ none?: boolean | undefined;
144
145
  linear?: boolean | undefined;
145
146
  quadratic?: boolean | undefined;
146
147
  sinusoid?: boolean | undefined;
@@ -220,6 +221,7 @@ declare const _default: Readonly<{
220
221
  mafs?: false | ({
221
222
  circle?: boolean | undefined;
222
223
  polygon?: boolean | undefined;
224
+ none?: boolean | undefined;
223
225
  linear?: boolean | undefined;
224
226
  quadratic?: boolean | undefined;
225
227
  sinusoid?: boolean | undefined;
@@ -299,6 +301,7 @@ declare const _default: Readonly<{
299
301
  mafs?: false | ({
300
302
  circle?: boolean | undefined;
301
303
  polygon?: boolean | undefined;
304
+ none?: boolean | undefined;
302
305
  linear?: boolean | undefined;
303
306
  quadratic?: boolean | undefined;
304
307
  sinusoid?: boolean | undefined;
@@ -377,6 +380,7 @@ declare const _default: Readonly<{
377
380
  mafs?: false | ({
378
381
  circle?: boolean | undefined;
379
382
  polygon?: boolean | undefined;
383
+ none?: boolean | undefined;
380
384
  linear?: boolean | undefined;
381
385
  quadratic?: boolean | undefined;
382
386
  sinusoid?: boolean | undefined;
@@ -456,6 +460,7 @@ declare const _default: Readonly<{
456
460
  mafs?: false | ({
457
461
  circle?: boolean | undefined;
458
462
  polygon?: boolean | undefined;
463
+ none?: boolean | undefined;
459
464
  linear?: boolean | undefined;
460
465
  quadratic?: boolean | undefined;
461
466
  sinusoid?: boolean | undefined;
@@ -535,6 +540,7 @@ declare const _default: Readonly<{
535
540
  mafs?: false | ({
536
541
  circle?: boolean | undefined;
537
542
  polygon?: boolean | undefined;
543
+ none?: boolean | undefined;
538
544
  linear?: boolean | undefined;
539
545
  quadratic?: boolean | undefined;
540
546
  sinusoid?: boolean | undefined;
@@ -68,6 +68,8 @@ declare class LegacyInteractiveGraph extends React.Component<Props, State> {
68
68
  };
69
69
  addLine: (arg1: string) => void;
70
70
  removeLine: () => void;
71
+ addNoneControls: () => void;
72
+ removeNoneControls: () => void;
71
73
  addLinearControls: () => void;
72
74
  removeLinearControls: () => void;
73
75
  addQuadraticControls: () => void;
@@ -146,6 +148,7 @@ declare class InteractiveGraph extends React.Component<Props, State> {
146
148
  static normalizeCoords(coordsList: ReadonlyArray<Coord>, ranges: [Range, Range]): ReadonlyArray<Coord>;
147
149
  static getEquationString(props: Props): string;
148
150
  static pointsFromNormalized(props: Props, coordsList: ReadonlyArray<Coord>, noSnap?: boolean): ReadonlyArray<Coord>;
151
+ static getNoneEquationString(): string;
149
152
  static getLinearEquationString(props: Props): string;
150
153
  static getCurrentQuadraticCoefficients(props: Props): QuadraticCoefficient;
151
154
  static defaultQuadraticCoords(props: Props): QuadraticGraphState["coords"];
@@ -17,7 +17,7 @@ type ControlledFocusBehavior = {
17
17
  type UncontrolledFocusBehavior = {
18
18
  type: "uncontrolled";
19
19
  tabIndex: number;
20
- onFocusChange: (isFocused: boolean) => unknown;
20
+ onFocusChange?: (event: React.FocusEvent, isFocused: boolean) => unknown;
21
21
  };
22
22
  export declare const MovablePointView: React.ForwardRefExoticComponent<Props & React.RefAttributes<SVGGElement>>;
23
23
  export {};
@@ -5,10 +5,11 @@ import type { vec } from "mafs";
5
5
  type Props = {
6
6
  point: vec.Vector2;
7
7
  onMove?: (newPoint: vec.Vector2) => unknown;
8
+ onClick?: () => unknown;
8
9
  color?: string;
9
10
  cursor?: CSSCursor | undefined;
10
11
  constrain?: KeyboardMovementConstraint;
11
- onFocusChange?: (isFocused: boolean) => unknown;
12
+ onFocusChange?: (event: React.FocusEvent, isFocused: boolean) => unknown;
12
13
  };
13
14
  export declare const MovablePoint: (props: Props) => React.JSX.Element;
14
15
  export {};
@@ -1,7 +1,12 @@
1
1
  import type { Coord } from "../../interactive2/types";
2
- import type { CollinearTuple, LockedFigureColor, LockedFigureFillType, LockedFunctionType, PerseusRenderer } from "../../perseus-types";
3
- import type { vec } from "mafs";
4
- export type LockedFunctionOptions = Omit<Partial<LockedFunctionType>, "type" | "equation">;
2
+ import type { CollinearTuple, LockedFigureColor, LockedFigureFillType, LockedLineStyle, PerseusRenderer } from "../../perseus-types";
3
+ import type { Interval, vec } from "mafs";
4
+ export type LockedFunctionOptions = {
5
+ color?: LockedFigureColor;
6
+ strokeStyle?: LockedLineStyle;
7
+ directionalAxis?: "x" | "y";
8
+ domain?: Interval;
9
+ };
5
10
  export declare function interactiveGraphQuestionBuilder(): InteractiveGraphQuestionBuilder;
6
11
  declare class InteractiveGraphQuestionBuilder {
7
12
  private content;
@@ -45,6 +50,7 @@ declare class InteractiveGraphQuestionBuilder {
45
50
  startCoords?: CollinearTuple[];
46
51
  coords?: CollinearTuple[];
47
52
  }): InteractiveGraphQuestionBuilder;
53
+ withNoInteractiveFigure(): this;
48
54
  withLinear(options?: {
49
55
  coords?: CollinearTuple;
50
56
  startCoords?: CollinearTuple;
@@ -100,7 +106,7 @@ declare class InteractiveGraphQuestionBuilder {
100
106
  }): InteractiveGraphQuestionBuilder;
101
107
  addLockedLine(point1: vec.Vector2, point2: vec.Vector2, options?: {
102
108
  kind?: "line" | "ray" | "segment";
103
- lineStyle?: "solid" | "dashed";
109
+ lineStyle?: LockedLineStyle;
104
110
  color?: LockedFigureColor;
105
111
  filled?: [boolean, boolean];
106
112
  showPoint1?: boolean;
@@ -23,6 +23,7 @@ export type MafsGraphProps = {
23
23
  readOnly: boolean;
24
24
  static: boolean | null | undefined;
25
25
  };
26
+ export declare const REMOVE_BUTTON_ID = "perseus_mafs_remove_button";
26
27
  export declare const MafsGraph: (props: MafsGraphProps) => React.JSX.Element;
27
28
  export declare const calculateNestedSVGCoords: (range: vec.Vector2[], width: number, height: number) => {
28
29
  viewboxX: number;
@@ -1,6 +1,6 @@
1
1
  import type { InitializeGraphStateParams } from "./initialize-graph-state";
2
2
  import type { Interval, vec } from "mafs";
3
- export type InteractiveGraphAction = Reinitialize | MovePointInFigure | MoveLine | MoveAll | MovePoint | MoveCenter | MoveRadiusPoint | ChangeSnapStep | ChangeRange | AddPoint | RemovePoint | FocusPoint | BlurPoint | DeleteIntent;
3
+ export type InteractiveGraphAction = Reinitialize | MovePointInFigure | MoveLine | MoveAll | MovePoint | MoveCenter | MoveRadiusPoint | ChangeSnapStep | ChangeRange | AddPoint | RemovePoint | FocusPoint | BlurPoint | DeleteIntent | ClickPoint;
4
4
  export declare const actions: {
5
5
  global: {
6
6
  deleteIntent: typeof deleteIntent;
@@ -26,6 +26,7 @@ export declare const actions: {
26
26
  removePoint: typeof removePoint;
27
27
  focusPoint: typeof focusPoint;
28
28
  blurPoint: typeof blurPoint;
29
+ clickPoint: typeof clickPoint;
29
30
  };
30
31
  polygon: {
31
32
  movePoint: typeof movePoint;
@@ -81,6 +82,12 @@ export interface BlurPoint {
81
82
  type: typeof BLUR_POINT;
82
83
  }
83
84
  declare function blurPoint(): BlurPoint;
85
+ export declare const CLICK_POINT = "click-point";
86
+ export interface ClickPoint {
87
+ type: typeof CLICK_POINT;
88
+ index: number;
89
+ }
90
+ declare function clickPoint(index: number): ClickPoint;
84
91
  export declare const MOVE_ALL = "move-all";
85
92
  export interface MoveAll {
86
93
  type: typeof MOVE_ALL;
@@ -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 = AngleGraphState | SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState;
11
+ export type InteractiveGraphState = AngleGraphState | SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | NoneGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState;
12
12
  export interface InteractiveGraphStateCommon {
13
13
  hasBeenInteractedWith: boolean;
14
14
  range: [xRange: Interval, yRange: Interval];
@@ -26,12 +26,15 @@ export interface LinearSystemGraphState extends InteractiveGraphStateCommon {
26
26
  type: "linear-system";
27
27
  coords: PairOfPoints[];
28
28
  }
29
+ export interface NoneGraphState extends InteractiveGraphStateCommon {
30
+ type: "none";
31
+ }
29
32
  export interface PointGraphState extends InteractiveGraphStateCommon {
30
33
  type: "point";
31
34
  coords: Coord[];
32
35
  numPoints?: number | "unlimited";
33
36
  focusedPointIndex: number | null;
34
- previouslyFocusedPointIndex: number | null;
37
+ showRemovePointButton: boolean;
35
38
  }
36
39
  export interface RayGraphState extends InteractiveGraphStateCommon {
37
40
  type: "ray";
@@ -133,6 +133,7 @@ declare const _default: Readonly<{
133
133
  mafs?: false | ({
134
134
  circle?: boolean | undefined;
135
135
  polygon?: boolean | undefined;
136
+ none?: boolean | undefined;
136
137
  linear?: boolean | undefined;
137
138
  quadratic?: boolean | undefined;
138
139
  sinusoid?: boolean | undefined;
@@ -196,6 +197,7 @@ declare const _default: Readonly<{
196
197
  mafs?: false | ({
197
198
  circle?: boolean | undefined;
198
199
  polygon?: boolean | undefined;
200
+ none?: boolean | undefined;
199
201
  linear?: boolean | undefined;
200
202
  quadratic?: boolean | undefined;
201
203
  sinusoid?: 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": "33.2.0",
6
+ "version": "33.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -48,6 +48,7 @@
48
48
  "@khanacademy/perseus-linter": "^1.2.0",
49
49
  "@khanacademy/pure-markdown": "^0.3.8",
50
50
  "@khanacademy/simple-markdown": "^0.13.1",
51
+ "@types/classnames": "2.2.0",
51
52
  "@use-gesture/react": "^10.2.27",
52
53
  "mafs": "0.19.0",
53
54
  "uuid": "^10.0.0"