@khanacademy/perseus 21.1.0 → 21.2.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.
- package/dist/es/index.js +227 -64
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +235 -72
- package/dist/index.js.map +1 -1
- package/dist/perseus-api.d.ts +1 -1
- package/dist/perseus-types.d.ts +6 -2
- package/dist/server-item-renderer.d.ts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/util.d.ts +3 -0
- package/dist/widgets/expression.d.ts +6 -6
- package/dist/widgets/interactive-graph.d.ts +4 -1
- package/dist/widgets/interactive-graphs/axis-ticks.d.ts +8 -0
- package/dist/widgets/interactive-graphs/graphs/components/movable-line.d.ts +6 -4
- package/dist/widgets/interactive-graphs/grid.d.ts +14 -3
- package/dist/widgets/interactive-graphs/mafs-graph.d.ts +2 -2
- package/dist/widgets/interactive-graphs/reducer/interactive-graph-action.d.ts +14 -1
- package/dist/widgets/interactive-graphs/utils.d.ts +2 -0
- package/dist/widgets/label-image.d.ts +2 -2
- package/package.json +1 -1
package/dist/perseus-api.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare const ApiOptions: {
|
|
|
96
96
|
crossOutEnabled?: boolean | undefined;
|
|
97
97
|
editorChangeDelay?: number | undefined;
|
|
98
98
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
99
|
-
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) =>
|
|
99
|
+
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
100
100
|
}> & {
|
|
101
101
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
102
102
|
baseElements: {
|
package/dist/perseus-types.d.ts
CHANGED
|
@@ -250,6 +250,10 @@ export type PerseusGradedGroupWidgetOptions = {
|
|
|
250
250
|
export type PerseusGradedGroupSetWidgetOptions = {
|
|
251
251
|
gradedGroups: ReadonlyArray<PerseusGradedGroupWidgetOptions>;
|
|
252
252
|
};
|
|
253
|
+
export type GraphRange = [
|
|
254
|
+
x: [min: number, max: number],
|
|
255
|
+
y: [min: number, max: number]
|
|
256
|
+
];
|
|
253
257
|
export type PerseusGrapherWidgetOptions = {
|
|
254
258
|
availableTypes: ReadonlyArray<"absolute_value" | "exponential" | "linear" | "logarithm" | "quadratic" | "sinusoid" | "tangent">;
|
|
255
259
|
correct: {
|
|
@@ -296,7 +300,7 @@ export type PerseusGrapherWidgetOptions = {
|
|
|
296
300
|
gridStep?: [number, number];
|
|
297
301
|
labels: [string, string];
|
|
298
302
|
markings: "graph" | "none" | "grid";
|
|
299
|
-
range:
|
|
303
|
+
range: GraphRange;
|
|
300
304
|
rulerLabel: "";
|
|
301
305
|
rulerTicks: number;
|
|
302
306
|
showProtractor?: boolean;
|
|
@@ -341,7 +345,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
|
|
|
341
345
|
showTooltips?: boolean;
|
|
342
346
|
rulerLabel: string;
|
|
343
347
|
rulerTicks: number;
|
|
344
|
-
range:
|
|
348
|
+
range: GraphRange;
|
|
345
349
|
graph: PerseusGraphType;
|
|
346
350
|
correct: PerseusGraphType;
|
|
347
351
|
lockedFigures?: ReadonlyArray<LockedFigure>;
|
|
@@ -138,7 +138,7 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
|
|
|
138
138
|
crossOutEnabled?: boolean | undefined;
|
|
139
139
|
editorChangeDelay?: number | undefined;
|
|
140
140
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
141
|
-
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) =>
|
|
141
|
+
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
142
142
|
}> | undefined;
|
|
143
143
|
linterContext?: PerseusLinter.LinterContextProps | undefined;
|
|
144
144
|
onRendered?: ((isRendered: boolean) => void) | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -205,7 +205,7 @@ export type APIOptions = Readonly<{
|
|
|
205
205
|
* This is useful for when we need to know how a widget has shuffled its
|
|
206
206
|
* the available choices.
|
|
207
207
|
*/
|
|
208
|
-
onWidgetStartProps?: (widgets: PerseusWidgetsMap) =>
|
|
208
|
+
onWidgetStartProps?: (widgets: PerseusWidgetsMap) => void;
|
|
209
209
|
}>;
|
|
210
210
|
type TeXProps = {
|
|
211
211
|
children: string;
|
package/dist/util.d.ts
CHANGED
|
@@ -188,6 +188,8 @@ declare function getWordBeforeCursor(textarea: HTMLTextAreaElement): WordAndPosi
|
|
|
188
188
|
* @param {int} pos - The position where the cursor will be moved
|
|
189
189
|
*/
|
|
190
190
|
declare function moveCursor(textarea: HTMLTextAreaElement, pos: number): void;
|
|
191
|
+
type Cloneable = null | undefined | boolean | string | number | Cloneable[] | readonly Cloneable[];
|
|
192
|
+
declare function deepClone<T extends Cloneable>(obj: T): T;
|
|
191
193
|
declare const Util: {
|
|
192
194
|
readonly inputPathsEqual: typeof inputPathsEqual;
|
|
193
195
|
readonly nestedMap: <T, M>(children: T | ReadonlyArray<T>, func: (arg1: T) => M, context: unknown) => M | ReadonlyArray<M>;
|
|
@@ -242,5 +244,6 @@ declare const Util: {
|
|
|
242
244
|
};
|
|
243
245
|
readonly unescapeMathMode: (label: string) => string;
|
|
244
246
|
readonly random: RNG;
|
|
247
|
+
readonly deepClone: typeof deepClone;
|
|
245
248
|
};
|
|
246
249
|
export default Util;
|
|
@@ -124,7 +124,7 @@ declare const _default: Readonly<{
|
|
|
124
124
|
crossOutEnabled?: boolean | undefined;
|
|
125
125
|
editorChangeDelay?: number | undefined;
|
|
126
126
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
127
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
127
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
128
128
|
}> & {
|
|
129
129
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
130
130
|
baseElements: {
|
|
@@ -191,7 +191,7 @@ declare const _default: Readonly<{
|
|
|
191
191
|
crossOutEnabled?: boolean | undefined;
|
|
192
192
|
editorChangeDelay?: number | undefined;
|
|
193
193
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
194
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
194
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
195
195
|
}> & {
|
|
196
196
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
197
197
|
baseElements: {
|
|
@@ -258,7 +258,7 @@ declare const _default: Readonly<{
|
|
|
258
258
|
crossOutEnabled?: boolean | undefined;
|
|
259
259
|
editorChangeDelay?: number | undefined;
|
|
260
260
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
261
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
261
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
262
262
|
}> & {
|
|
263
263
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
264
264
|
baseElements: {
|
|
@@ -322,7 +322,7 @@ declare const _default: Readonly<{
|
|
|
322
322
|
crossOutEnabled?: boolean | undefined;
|
|
323
323
|
editorChangeDelay?: number | undefined;
|
|
324
324
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
325
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
325
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
326
326
|
}> & {
|
|
327
327
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
328
328
|
baseElements: {
|
|
@@ -389,7 +389,7 @@ declare const _default: Readonly<{
|
|
|
389
389
|
crossOutEnabled?: boolean | undefined;
|
|
390
390
|
editorChangeDelay?: number | undefined;
|
|
391
391
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
392
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
392
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
393
393
|
}> & {
|
|
394
394
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
395
395
|
baseElements: {
|
|
@@ -456,7 +456,7 @@ declare const _default: Readonly<{
|
|
|
456
456
|
crossOutEnabled?: boolean | undefined;
|
|
457
457
|
editorChangeDelay?: number | undefined;
|
|
458
458
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
459
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
459
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
460
460
|
}> & {
|
|
461
461
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
462
462
|
baseElements: {
|
|
@@ -5,7 +5,10 @@ import type { Widget } from "../renderer";
|
|
|
5
5
|
import type { ChangeHandler, PerseusScore, WidgetProps } from "../types";
|
|
6
6
|
import type { QuadraticCoefficient, SineCoefficient, Range } from "../util/geometry";
|
|
7
7
|
type RenderProps = PerseusInteractiveGraphWidgetOptions;
|
|
8
|
-
type Rubric =
|
|
8
|
+
export type Rubric = {
|
|
9
|
+
correct: PerseusGraphType;
|
|
10
|
+
graph: PerseusGraphType;
|
|
11
|
+
};
|
|
9
12
|
type Props = WidgetProps<RenderProps, Rubric>;
|
|
10
13
|
type State = any;
|
|
11
14
|
type DefaultProps = {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function generateTickLocations(tickStep: number, min: number, max: number): number[];
|
|
3
|
+
type Props = {
|
|
4
|
+
tickStep: [number, number];
|
|
5
|
+
range: [[number, number], [number, number]];
|
|
6
|
+
};
|
|
7
|
+
export declare const AxisTicks: (props: Props) => JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { vec } from "mafs";
|
|
3
3
|
import type { Interval } from "mafs";
|
|
4
|
-
|
|
4
|
+
type Props = {
|
|
5
5
|
start: vec.Vector2;
|
|
6
6
|
end: vec.Vector2;
|
|
7
7
|
onMove: (delta: vec.Vector2) => unknown;
|
|
8
|
-
stroke?: string
|
|
8
|
+
stroke?: string;
|
|
9
9
|
extend?: {
|
|
10
10
|
start: boolean;
|
|
11
11
|
end: boolean;
|
|
12
12
|
range: [Interval, Interval];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const MovableLine: (props: Props) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { GraphRange } from "../../perseus-types";
|
|
2
3
|
import type { SizeClass } from "../../util/sizing-utils";
|
|
4
|
+
import type { vec } from "mafs";
|
|
3
5
|
interface GridProps {
|
|
4
|
-
|
|
5
|
-
gridStep:
|
|
6
|
-
range:
|
|
6
|
+
tickStep: vec.Vector2;
|
|
7
|
+
gridStep: vec.Vector2;
|
|
8
|
+
range: GraphRange;
|
|
7
9
|
containerSizeClass: SizeClass;
|
|
8
10
|
markings: "graph" | "grid" | "none";
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* lineLabelText get the text that should
|
|
14
|
+
* be displayed for a specific tick place
|
|
15
|
+
*
|
|
16
|
+
* @param {number} n the tick number
|
|
17
|
+
* @param {number} tickStep how frequently a label should appear
|
|
18
|
+
* @param {vec.Vector2} range the min/max range on the axis
|
|
19
|
+
*/
|
|
20
|
+
export declare const lineLabelText: (n: number, tickStep: number, range: vec.Vector2) => string;
|
|
10
21
|
export declare const Grid: (props: GridProps) => JSX.Element | null;
|
|
11
22
|
export {};
|
|
@@ -3,7 +3,7 @@ import type { InteractiveGraphProps } from "./types";
|
|
|
3
3
|
import type { Widget } from "../../renderer";
|
|
4
4
|
import "mafs/core.css";
|
|
5
5
|
import "./mafs-styles.css";
|
|
6
|
-
export type
|
|
6
|
+
export type Props = {
|
|
7
7
|
box: [number, number];
|
|
8
8
|
backgroundImage?: InteractiveGraphProps["backgroundImage"];
|
|
9
9
|
graph: InteractiveGraphProps["graph"];
|
|
@@ -16,6 +16,6 @@ export type MafsWrapperProps = {
|
|
|
16
16
|
markings: InteractiveGraphProps["markings"];
|
|
17
17
|
onChange: InteractiveGraphProps["onChange"];
|
|
18
18
|
};
|
|
19
|
-
export declare const MafsGraph: React.ForwardRefExoticComponent<
|
|
19
|
+
export declare const MafsGraph: React.ForwardRefExoticComponent<Props & {
|
|
20
20
|
children?: React.ReactNode;
|
|
21
21
|
} & React.RefAttributes<Partial<Widget>>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Props as MafsGraphProps } from "../mafs-graph";
|
|
1
2
|
import type { vec } from "mafs";
|
|
2
|
-
export type InteractiveGraphAction = MoveControlPoint | MoveLine | MoveAll | MovePoint;
|
|
3
|
+
export type InteractiveGraphAction = MoveControlPoint | MoveLine | MoveAll | MovePoint | ChangeSnapStep | ChangeRange;
|
|
3
4
|
export declare const MOVE_CONTROL_POINT = "move-control-point";
|
|
4
5
|
export interface MoveControlPoint {
|
|
5
6
|
type: typeof MOVE_CONTROL_POINT;
|
|
@@ -31,4 +32,16 @@ export interface MovePoint {
|
|
|
31
32
|
destination: vec.Vector2;
|
|
32
33
|
}
|
|
33
34
|
export declare function movePoint(index: number, destination: vec.Vector2): MovePoint;
|
|
35
|
+
export declare const CHANGE_SNAP_STEP = "change-snap-step";
|
|
36
|
+
export interface ChangeSnapStep {
|
|
37
|
+
type: typeof CHANGE_SNAP_STEP;
|
|
38
|
+
snapStep: MafsGraphProps["snapStep"];
|
|
39
|
+
}
|
|
40
|
+
export declare function changeSnapStep(snapStep: MafsGraphProps["snapStep"]): ChangeSnapStep;
|
|
41
|
+
export declare const CHANGE_RANGE = "change-range";
|
|
42
|
+
export interface ChangeRange {
|
|
43
|
+
type: typeof CHANGE_RANGE;
|
|
44
|
+
range: MafsGraphProps["range"];
|
|
45
|
+
}
|
|
46
|
+
export declare function changeRange(range: MafsGraphProps["range"]): ChangeRange;
|
|
34
47
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Coord } from "../../interactive2/types";
|
|
2
2
|
import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
|
|
3
|
+
import type { vec } from "mafs";
|
|
3
4
|
/**
|
|
4
5
|
* 44 is touch best practice and AAA compliant for WCAG
|
|
5
6
|
* https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
|
|
@@ -7,3 +8,4 @@ import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
|
|
|
7
8
|
export declare const TARGET_SIZE = 44;
|
|
8
9
|
export declare const normalizePoints: <A extends Coord[]>(range: PerseusInteractiveGraphWidgetOptions["range"], step: PerseusInteractiveGraphWidgetOptions["step"], coordsList: A, noSnap?: boolean) => A;
|
|
9
10
|
export declare const normalizeCoords: <A extends Coord[]>(coordsList: A, ranges: PerseusInteractiveGraphWidgetOptions["range"]) => A;
|
|
11
|
+
export declare function snap(snapStep: vec.Vector2, point: vec.Vector2): vec.Vector2;
|
|
@@ -123,7 +123,7 @@ declare const _default: Readonly<{
|
|
|
123
123
|
crossOutEnabled?: boolean | undefined;
|
|
124
124
|
editorChangeDelay?: number | undefined;
|
|
125
125
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
126
|
-
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) =>
|
|
126
|
+
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
|
|
127
127
|
}>;
|
|
128
128
|
choices: readonly string[];
|
|
129
129
|
imageAlt: string;
|
|
@@ -172,7 +172,7 @@ declare const _default: Readonly<{
|
|
|
172
172
|
crossOutEnabled?: boolean | undefined;
|
|
173
173
|
editorChangeDelay?: number | undefined;
|
|
174
174
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
175
|
-
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) =>
|
|
175
|
+
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
|
|
176
176
|
}>;
|
|
177
177
|
choices: readonly string[];
|
|
178
178
|
imageAlt: string;
|