@khanacademy/perseus 20.6.0 → 20.7.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.
@@ -0,0 +1,90 @@
1
+ export declare enum WidgetType {
2
+ Categorizer = "categorizer",
3
+ CSProgram = "cs-program",
4
+ Definition = "definition",
5
+ Dropdown = "dropdown",
6
+ Explanation = "explanation",
7
+ Expression = "expression",
8
+ GradedGroup = "graded-group",
9
+ GradedGroupAnswerBar = "graded-group-answer-bar",
10
+ GradedGroupSet = "graded-group-set",
11
+ Grapher = "grapher",
12
+ Group = "group",
13
+ Iframe = "iframe",
14
+ Image = "image",
15
+ InputNumber = "input-number",
16
+ Interaction = "interaction",
17
+ InteractiveGraph = "interactive-graph",
18
+ InteractiveNumberLine = "interactive-number-line",
19
+ LabelImage = "label-image",
20
+ Matcher = "matcher",
21
+ Matrix = "matrix",
22
+ Measurer = "measurer",
23
+ Molecule = "molecule",
24
+ NumberLine = "number-line",
25
+ NumericInput = "numeric-input",
26
+ Orderer = "orderer",
27
+ Passage = "passage",
28
+ PassageRef = "passage-ref",
29
+ PassageRefTarget = "passage-ref-target",
30
+ Plotter = "plotter",
31
+ Protractor = "protractor",
32
+ PythonProgram = "python-program",
33
+ Radio = "radio",
34
+ Sorter = "sorter",
35
+ Table = "table",
36
+ Unit = "unit",
37
+ Video = "video",
38
+ VideoTranscriptLink = "video-transcript-link"
39
+ }
40
+ export type WidgetId = `${WidgetType} ${number}`;
41
+ export declare const QUESTION_WIDGETS: ReadonlyArray<string>;
42
+ /**
43
+ * Regex for widget placeholders in a string.
44
+ *
45
+ * First capture group is the widget ID (ex. 'radio 1')
46
+ * Second capture group is the widget type (ex. "radio)
47
+ * exec return will look like: ['[[☃ radio 1]]', 'radio 1', 'radio']
48
+ */
49
+ export declare function getWidgetRegex(): RegExp;
50
+ /**
51
+ * Add a widget placeholder using the provided widget type and instance number.
52
+ * ex. addWidget(WidgetType.Radio, 1) => "[[☃ radio 1]]"
53
+ *
54
+ * @param {WidgetType} widgetType
55
+ * @param {number} instance
56
+ * @returns {string}
57
+ */
58
+ export declare function addWidget(widgetType: WidgetType, instance: number): string;
59
+ /**
60
+ * Extract all widget IDs, which includes the widget type and instance number.
61
+ * example output: ['radio 1', 'categorizer 1', 'categorizor 2']
62
+ *
63
+ * Content should contain Perseus widget placeholders,
64
+ * which look like: '[[☃ radio 1]]'.
65
+ *
66
+ * @param {string} content
67
+ * @returns {Array<WidgetId>} widgets
68
+ */
69
+ export declare function getAllWidgetIds(content: string): Array<WidgetId>;
70
+ /**
71
+ * Extract all widget types from a Perseus JSON content string.
72
+ * This does not include the instance number and prevents duplicates.
73
+ * example output: ['radio', 'categorizer']
74
+ *
75
+ * @param {string} content
76
+ * @returns {Array<WidgetId>}
77
+ */
78
+ export declare function getAllWidgetTypes(content: string): Array<WidgetId>;
79
+ /**
80
+ * Extract the widget IDs of all widgets considered question widgets. Widget IDs
81
+ * include widget type and instance number.
82
+ * example output: ['radio 1', 'categorizer 1']
83
+ *
84
+ * Content should contain Perseus widget placeholders,
85
+ * which look like: '[[☃ radio 1]]'.
86
+ *
87
+ * @param {string} content
88
+ * @returns Array<WidgetId>
89
+ */
90
+ export declare function getQuestionWidgetIds(content: string): Array<WidgetId>;
@@ -1,3 +1,4 @@
1
1
  export { SegmentGraph } from "./segment";
2
2
  export { LinearGraph } from "./linear";
3
3
  export { RayGraph } from "./ray";
4
+ export { PolygonGraph } from "./polygon";
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { MafsGraphProps, PolygonGraphState } from "../types";
3
+ type Props = MafsGraphProps<PolygonGraphState>;
4
+ export declare const PolygonGraph: (props: Props) => JSX.Element;
5
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { vec } from "mafs";
2
+ export type InteractiveGraphAction = MoveControlPoint | MoveLine | MoveAll;
3
+ export declare const MOVE_CONTROL_POINT = "move-control-point";
4
+ export interface MoveControlPoint {
5
+ type: typeof MOVE_CONTROL_POINT;
6
+ itemIndex?: number;
7
+ pointIndex: number;
8
+ destination: vec.Vector2;
9
+ }
10
+ export declare function moveControlPoint(pointIndex: number, destination: vec.Vector2, itemIndex?: number): MoveControlPoint;
11
+ export declare const MOVE_ALL = "move-all";
12
+ export declare const MOVE_LINE = "move-line";
13
+ interface MoveItem {
14
+ delta: vec.Vector2;
15
+ itemIndex?: number;
16
+ }
17
+ export interface MoveLine extends MoveItem {
18
+ type: typeof MOVE_LINE;
19
+ }
20
+ export interface MoveAll extends MoveItem {
21
+ type: typeof MOVE_ALL;
22
+ }
23
+ /** This action assumes the state.coords holds an array of collinear tuples that define lines */
24
+ export declare function moveLine(itemIndex: number, delta: vec.Vector2): MoveLine;
25
+ /** This action assumes a flat array of vectors */
26
+ export declare const moveAll: (delta: vec.Vector2) => MoveAll;
27
+ export {};
@@ -0,0 +1,3 @@
1
+ import { type InteractiveGraphAction } from "./interactive-graph-action";
2
+ import type { InteractiveGraphState } from "../types";
3
+ export declare function interactiveGraphReducer<GraphState extends InteractiveGraphState>(state: Readonly<GraphState>, action: InteractiveGraphAction): GraphState;
@@ -1,5 +1,5 @@
1
- import type { InteractiveGraphState } from "./types";
2
- import type { PerseusGraphType } from "../../perseus-types";
1
+ import type { PerseusGraphType } from "../../../perseus-types";
2
+ import type { InteractiveGraphState } from "../types";
3
3
  import type { Interval, vec } from "mafs";
4
4
  export declare function initializeGraphState(params: {
5
5
  range: [Interval, Interval];
@@ -1,5 +1,5 @@
1
- import type { InteractiveGraphAction } from "./interactive-graph-action";
2
- import type { CollinearTuple, PerseusGraphTypeLinearSystem, PerseusGraphTypeRay, PerseusGraphTypeSegment, PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
1
+ import type { InteractiveGraphAction } from "./reducer/interactive-graph-action";
2
+ import type { CollinearTuple, PerseusGraphType, PerseusGraphTypeLinearSystem, PerseusGraphTypePolygon, PerseusGraphTypeRay, PerseusGraphTypeSegment, PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
3
3
  import type { WidgetProps } from "../../types";
4
4
  import type { Interval, vec } from "mafs";
5
5
  export type InteractiveGraphProps = WidgetProps<PerseusInteractiveGraphWidgetOptions, PerseusInteractiveGraphWidgetOptions>;
@@ -7,16 +7,22 @@ export type MafsGraphProps<T extends InteractiveGraphState> = {
7
7
  graphState: T;
8
8
  dispatch: (action: InteractiveGraphAction) => unknown;
9
9
  };
10
- export type InteractiveGraphState = SegmentGraphState | LinearGraphState | RayGraphState;
10
+ export interface InitializeGraphStateParams<T extends PerseusGraphType> {
11
+ graph: T;
12
+ range: [Interval, Interval];
13
+ step: vec.Vector2;
14
+ }
15
+ export type InteractiveGraphState = SegmentGraphState | LinearGraphState | RayGraphState | PolygonGraphState;
11
16
  export interface InteractiveGraphStateCommon {
12
17
  hasBeenInteractedWith: boolean;
13
18
  range: [Interval, Interval];
14
19
  snapStep: vec.Vector2;
15
20
  }
16
- export type SegmentGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeSegment, "type" | "coords">;
17
- export type LinearGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeLinearSystem, "coords"> & {
21
+ export type SegmentGraphState = InteractiveGraphStateCommon & Omit<PerseusGraphTypeSegment, "numSegments">;
22
+ export type LinearGraphState = InteractiveGraphStateCommon & Omit<PerseusGraphTypeLinearSystem, "type"> & {
18
23
  type: "linear" | "linear-system";
19
24
  };
20
- export type RayGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeRay, "type"> & {
25
+ export type RayGraphState = InteractiveGraphStateCommon & Omit<PerseusGraphTypeRay, "coords"> & {
21
26
  coords: readonly CollinearTuple[];
22
27
  };
28
+ export type PolygonGraphState = InteractiveGraphStateCommon & PerseusGraphTypePolygon;
@@ -1,4 +1,9 @@
1
1
  import type { Coord } from "../../interactive2/types";
2
2
  import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
3
+ /**
4
+ * 44 is touch best practice and AAA compliant for WCAG
5
+ * https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
6
+ */
7
+ export declare const TARGET_SIZE = 44;
3
8
  export declare const normalizePoints: <A extends readonly Coord[]>(range: PerseusInteractiveGraphWidgetOptions["range"], step: PerseusInteractiveGraphWidgetOptions["step"], coordsList: A, noSnap?: boolean) => A;
4
9
  export declare const normalizeCoords: <A extends readonly Coord[]>(coordsList: A, ranges: PerseusInteractiveGraphWidgetOptions["range"]) => A;
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": "20.6.0",
6
+ "version": "20.7.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -25,7 +25,7 @@
25
25
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
26
26
  },
27
27
  "dependencies": {
28
- "@khanacademy/kas": "^0.3.8",
28
+ "@khanacademy/kas": "^0.3.9",
29
29
  "@khanacademy/kmath": "^0.1.12",
30
30
  "@khanacademy/math-input": "^17.3.0",
31
31
  "@khanacademy/perseus-core": "1.4.2",
@@ -62,8 +62,6 @@
62
62
  "aphrodite": "^1.2.5",
63
63
  "classnames": "^1.1.4",
64
64
  "create-react-class": "^15.6.3",
65
- "eslint-import-resolver-alias": "^1.1.2",
66
- "eslint-plugin-import": "^2.26.0",
67
65
  "intersection-observer": "^0.12.0",
68
66
  "jquery": "^2.1.1",
69
67
  "katex": "^0.11.1",
@@ -1,17 +0,0 @@
1
- import type { vec } from "mafs";
2
- export type InteractiveGraphAction = MoveControlPoint | MoveSegment;
3
- export declare const MOVE_CONTROL_POINT = "move-control-point";
4
- export interface MoveControlPoint {
5
- type: typeof MOVE_CONTROL_POINT;
6
- objectIndex: number;
7
- pointIndex: number;
8
- destination: vec.Vector2;
9
- }
10
- export declare function moveControlPoint(objectIndex: number, pointIndex: number, destination: vec.Vector2): MoveControlPoint;
11
- export declare const MOVE_LINE = "move-line";
12
- export interface MoveSegment {
13
- type: typeof MOVE_LINE;
14
- lineIndex: number;
15
- delta: vec.Vector2;
16
- }
17
- export declare function moveSegment(lineIndex: number, delta: vec.Vector2): MoveSegment;
@@ -1,3 +0,0 @@
1
- import { type InteractiveGraphAction } from "./interactive-graph-action";
2
- import type { InteractiveGraphState } from "./types";
3
- export declare function interactiveGraphReducer(state: Readonly<InteractiveGraphState>, action: InteractiveGraphAction): InteractiveGraphState;