@khanacademy/perseus 24.3.0 → 25.1.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.
@@ -1,45 +1,5 @@
1
+ import type { ErrorKind } from "@khanacademy/perseus-core";
1
2
  import type { Metadata } from "@khanacademy/wonder-stuff-core";
2
- /**
3
- * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
4
- */
5
- export declare const Errors: Readonly<{
6
- /**
7
- * @property {ErrorKind} Unknown The kind of error is not known.
8
- */
9
- Unknown: "Unknown";
10
- /**
11
- * @property {ErrorKind} Internal The error is internal to the executing code.
12
- */
13
- Internal: "Internal";
14
- /**
15
- * @property {ErrorKind} InvalidInput There was a problem with the provided
16
- * input, such as the wrong format or a null value.
17
- */
18
- InvalidInput: "InvalidInput";
19
- /**
20
- * @property {ErrorKind} NotAllowed There was a problem due to the state of
21
- * the system not matching the requested operation or input. For example,
22
- * trying to create a username that is valid, but is already taken by
23
- * another user. Use {@link InvalidInput} instead when the input isn't
24
- * valid regardless of the state of the system. Use {@link NotFound} when
25
- * the failure is due to not being able to find a resource.
26
- */
27
- NotAllowed: "NotAllowed";
28
- /**
29
- * @property {ErrorKind} TransientService There was a problem when making a
30
- * request to a service.
31
- */
32
- TransientService: "TransientService";
33
- /**
34
- * @property {ErrorKind} Service There was a non-transient problem when
35
- * making a request to service.
36
- */
37
- Service: "Service";
38
- }>;
39
- /**
40
- * @type {ErrorKind} The kind of error being reported
41
- */
42
- export type ErrorKind = (typeof Errors)[keyof typeof Errors];
43
3
  export type LogErrorOptions = {
44
4
  cause?: Error | null | undefined;
45
5
  loggedMetadata?: Metadata | null | undefined;
@@ -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>;
@@ -105,7 +105,7 @@ export declare class ServerItemRenderer extends React.Component<Props, State> im
105
105
  setAssetStatus: (assetKey: string, status: boolean) => void;
106
106
  render(): React.ReactNode;
107
107
  }
108
- declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps, "item" | "problemNum" | "keypadElement" | "showSolutions" | "reviewMode" | "dependencies" | "hintsVisible"> & {
108
+ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps, "problemNum" | "keypadElement" | "showSolutions" | "reviewMode" | "item" | "dependencies" | "hintsVisible"> & {
109
109
  apiOptions?: Readonly<{
110
110
  isArticle?: boolean | undefined;
111
111
  onInputError?: ((widgetId: any, value: string, message?: string | null | undefined) => unknown) | undefined;
@@ -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;
@@ -254,9 +258,9 @@ declare const _default: Readonly<{
254
258
  times: boolean;
255
259
  value: string;
256
260
  }, "onChange" | "analytics" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
261
+ value?: string | undefined;
257
262
  onFocus?: ((blurPath: import("../types").FocusPath) => void) | undefined;
258
263
  onBlur?: ((blurPath: import("../types").FocusPath) => void) | undefined;
259
- value?: string | undefined;
260
264
  buttonSets?: import("../perseus-types").LegacyButtonSets | undefined;
261
265
  apiOptions?: Readonly<Readonly<{
262
266
  isArticle?: boolean | 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;
@@ -488,9 +498,9 @@ declare const _default: Readonly<{
488
498
  times: boolean;
489
499
  value: string;
490
500
  }, "onChange" | "analytics" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
501
+ value?: string | undefined;
491
502
  onFocus?: ((blurPath: import("../types").FocusPath) => void) | undefined;
492
503
  onBlur?: ((blurPath: import("../types").FocusPath) => void) | undefined;
493
- value?: string | undefined;
494
504
  buttonSets?: import("../perseus-types").LegacyButtonSets | undefined;
495
505
  apiOptions?: Readonly<Readonly<{
496
506
  isArticle?: boolean | 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,4 @@
1
- import type { CollinearTuple } from "../../../perseus-types";
2
1
  import type { Interval, vec } from "mafs";
3
- export declare function calculateAngleInDegrees([x, y]: vec.Vector2): number;
4
2
  /**
5
3
  * Given a ray and a rectangular box, find the point where the ray intersects
6
4
  * the edge of the box. Assumes the `initialPoint` is inside the box.
@@ -9,4 +7,3 @@ export declare function calculateAngleInDegrees([x, y]: vec.Vector2): number;
9
7
  * @param box - The box with which to intersect the ray, in the form [[xMin, xMax], [yMin, yMax]]
10
8
  */
11
9
  export declare const getIntersectionOfRayWithBox: (initialPoint: vec.Vector2, throughPoint: vec.Vector2, box: [x: Interval, y: Interval]) => [number, number];
12
- export declare const getLines: (points: readonly vec.Vector2[]) => CollinearTuple[];
@@ -1 +1 @@
1
- export { StatefulMafsGraph } from "./mafs-graph";
1
+ export { StatefulMafsGraph } from "./stateful-mafs-graph";
@@ -1,27 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { type InteractiveGraphAction } from "./reducer/interactive-graph-action";
3
3
  import type { InteractiveGraphState, InteractiveGraphProps } from "./types";
4
- import type { PerseusGraphType } from "../../perseus-types";
5
- import type { Widget } from "../../renderer";
6
4
  import "mafs/core.css";
7
5
  import "./mafs-styles.css";
8
- export type StatefulMafsGraphProps = {
9
- box: [number, number];
10
- backgroundImage?: InteractiveGraphProps["backgroundImage"];
11
- graph: PerseusGraphType;
12
- lockedFigures?: InteractiveGraphProps["lockedFigures"];
13
- range: InteractiveGraphProps["range"];
14
- snapStep: InteractiveGraphProps["snapStep"];
15
- step: InteractiveGraphProps["step"];
16
- gridStep: InteractiveGraphProps["gridStep"];
17
- containerSizeClass: InteractiveGraphProps["containerSizeClass"];
18
- markings: InteractiveGraphProps["markings"];
19
- onChange: InteractiveGraphProps["onChange"];
20
- showTooltips: Required<InteractiveGraphProps["showTooltips"]>;
21
- showProtractor: boolean;
22
- labels: InteractiveGraphProps["labels"];
23
- };
24
- export declare const StatefulMafsGraph: React.ForwardRefExoticComponent<StatefulMafsGraphProps & React.RefAttributes<Partial<Widget>>>;
25
6
  export type MafsGraphProps = {
26
7
  box: [number, number];
27
8
  backgroundImage?: InteractiveGraphProps["backgroundImage"];
@@ -1,3 +1,5 @@
1
1
  import type { vec } from "mafs";
2
+ export declare function convertDegreesToRadians(degrees: number): number;
3
+ export declare function calculateAngleInDegrees([x, y]: vec.Vector2): number;
2
4
  export declare function polar(r: number | vec.Vector2, th: number): vec.Vector2;
3
5
  export declare const findAngle: (point1: vec.Vector2, point2: vec.Vector2, vertex?: vec.Vector2) => number;
@@ -0,0 +1,3 @@
1
+ import type { vec } from "mafs";
2
+ export type Segment = [vec.Vector2, vec.Vector2];
3
+ export declare const segmentsIntersect: ([[a, b], [c, d]]: Segment, [[p, q], [r, s]]: Segment) => boolean;
@@ -3,4 +3,6 @@ export { snap } from "./snap";
3
3
  export { inset, clampToBox } from "./box";
4
4
  export { X, Y } from "./coordinates";
5
5
  export { MIN, MAX, size } from "./interval";
6
- export { findAngle, polar } from "./angles";
6
+ export { lerp } from "./interpolation";
7
+ export { segmentsIntersect } from "./geometry";
8
+ export { calculateAngleInDegrees, convertDegreesToRadians, findAngle, polar, } from "./angles";
@@ -0,0 +1 @@
1
+ export declare function lerp(a: number, b: number, fraction: number): 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;
@@ -0,0 +1,21 @@
1
+ import * as React from "react";
2
+ import type { InteractiveGraphProps } from "./types";
3
+ import type { Widget } from "../../renderer";
4
+ import type { PerseusGraphType } from "@khanacademy/perseus";
5
+ export type StatefulMafsGraphProps = {
6
+ box: [number, number];
7
+ backgroundImage?: InteractiveGraphProps["backgroundImage"];
8
+ graph: PerseusGraphType;
9
+ lockedFigures?: InteractiveGraphProps["lockedFigures"];
10
+ range: InteractiveGraphProps["range"];
11
+ snapStep: InteractiveGraphProps["snapStep"];
12
+ step: InteractiveGraphProps["step"];
13
+ gridStep: InteractiveGraphProps["gridStep"];
14
+ containerSizeClass: InteractiveGraphProps["containerSizeClass"];
15
+ markings: InteractiveGraphProps["markings"];
16
+ onChange: InteractiveGraphProps["onChange"];
17
+ showTooltips: Required<InteractiveGraphProps["showTooltips"]>;
18
+ showProtractor: boolean;
19
+ labels: InteractiveGraphProps["labels"];
20
+ };
21
+ export declare const StatefulMafsGraph: React.ForwardRefExoticComponent<StatefulMafsGraphProps & React.RefAttributes<Partial<Widget>>>;
@@ -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": "24.3.0",
6
+ "version": "25.1.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -39,13 +39,13 @@
39
39
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
40
40
  },
41
41
  "dependencies": {
42
- "@khanacademy/kas": "^0.3.9",
43
- "@khanacademy/kmath": "^0.1.12",
44
- "@khanacademy/math-input": "^19.2.0",
45
- "@khanacademy/perseus-core": "1.4.2",
46
- "@khanacademy/perseus-linter": "^0.4.0",
47
- "@khanacademy/pure-markdown": "^0.3.5",
48
- "@khanacademy/simple-markdown": "^0.12.0",
42
+ "@khanacademy/kas": "^0.3.10",
43
+ "@khanacademy/kmath": "^0.1.13",
44
+ "@khanacademy/math-input": "^19.2.1",
45
+ "@khanacademy/perseus-core": "1.5.0",
46
+ "@khanacademy/perseus-linter": "^1.0.0",
47
+ "@khanacademy/pure-markdown": "^0.3.6",
48
+ "@khanacademy/simple-markdown": "^0.12.1",
49
49
  "@use-gesture/react": "^10.2.27",
50
50
  "mafs": "0.18.7"
51
51
  },
@@ -1,11 +0,0 @@
1
- import type { ErrorKind } from "./logging/log";
2
- import type { Metadata } from "@khanacademy/wonder-stuff-core";
3
- type Options = {
4
- metadata?: Metadata | null | undefined;
5
- };
6
- export declare class PerseusError extends Error {
7
- kind: ErrorKind;
8
- metadata: Metadata | null | undefined;
9
- constructor(message: string, kind: ErrorKind, options?: Options);
10
- }
11
- export {};