@khanacademy/perseus 20.3.1 → 20.4.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.
@@ -1,6 +1,8 @@
1
1
  import type { Coord } from "./interactive2/types";
2
- export type Range = [number, number];
2
+ import type { Interval, vec } from "mafs";
3
+ export type Range = Interval;
3
4
  export type Size = [number, number];
5
+ export type CollinearTuple = readonly [vec.Vector2, vec.Vector2];
4
6
  type StyleParams = {
5
7
  fill?: string;
6
8
  stroke?: string;
@@ -313,7 +315,7 @@ export type PerseusImageWidgetOptions = {
313
315
  backgroundImage: PerseusImageBackground;
314
316
  static?: boolean;
315
317
  labels?: ReadonlyArray<PerseusImageLabel>;
316
- range?: [Range, Range];
318
+ range?: [Interval, Interval];
317
319
  box?: Size;
318
320
  };
319
321
  export type PerseusImageLabel = {
@@ -371,11 +373,11 @@ export type PerseusGraphTypeCircle = {
371
373
  } & PerseusGraphTypeCommon;
372
374
  export type PerseusGraphTypeLinear = {
373
375
  type: "linear";
374
- coords?: ReadonlyArray<Coord>;
376
+ coords?: CollinearTuple;
375
377
  } & PerseusGraphTypeCommon;
376
378
  export type PerseusGraphTypeLinearSystem = {
377
379
  type: "linear-system";
378
- coords?: ReadonlyArray<ReadonlyArray<Coord>>;
380
+ coords?: ReadonlyArray<CollinearTuple>;
379
381
  } & PerseusGraphTypeCommon;
380
382
  export type PerseusGraphTypePoint = {
381
383
  type: "point";
@@ -398,7 +400,7 @@ export type PerseusGraphTypeQuadratic = {
398
400
  export type PerseusGraphTypeSegment = {
399
401
  type: "segment";
400
402
  numSegments?: number;
401
- coords?: ReadonlyArray<ReadonlyArray<Coord>>;
403
+ coords?: ReadonlyArray<CollinearTuple>;
402
404
  } & PerseusGraphTypeCommon;
403
405
  export type PerseusGraphTypeSinusoid = {
404
406
  type: "sinusoid";
@@ -406,7 +408,7 @@ export type PerseusGraphTypeSinusoid = {
406
408
  } & PerseusGraphTypeCommon;
407
409
  export type PerseusGraphTypeRay = {
408
410
  type: "ray";
409
- coords?: ReadonlyArray<Coord>;
411
+ coords?: CollinearTuple;
410
412
  } & PerseusGraphTypeCommon;
411
413
  export type PerseusLabelImageWidgetOptions = {
412
414
  choices: ReadonlyArray<string>;
@@ -609,7 +611,7 @@ export type PerseusInteractionGraph = {
609
611
  editableSettings?: ReadonlyArray<"canvas" | "graph">;
610
612
  box: Size;
611
613
  labels: ReadonlyArray<string>;
612
- range: [Range, Range];
614
+ range: [Interval, Interval];
613
615
  gridStep: [number, number];
614
616
  /**
615
617
  * The type of markings to display on the graph.
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import { vec } from "mafs";
3
+ import type { Interval } from "mafs";
4
+ export declare const MovableLine: (props: {
5
+ start: vec.Vector2;
6
+ end: vec.Vector2;
7
+ onMove: (delta: vec.Vector2) => unknown;
8
+ stroke?: string | undefined;
9
+ extend?: {
10
+ start: boolean;
11
+ end: boolean;
12
+ range: [Interval, Interval];
13
+ } | undefined;
14
+ }) => JSX.Element;
@@ -3,6 +3,7 @@ import { vec } from "mafs";
3
3
  type Props = {
4
4
  point: vec.Vector2;
5
5
  onMove: (newPoint: vec.Vector2) => unknown;
6
+ color?: string;
6
7
  };
7
- export declare const MovablePoint: (props: Props) => JSX.Element;
8
+ export declare const StyledMovablePoint: (props: Props) => JSX.Element;
8
9
  export {};
@@ -1 +1,3 @@
1
1
  export { SegmentGraph } from "./segment";
2
+ export { LinearGraph } from "./linear";
3
+ export { RayGraph } from "./ray";
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { MafsGraphProps, LinearGraphState } from "../types";
3
+ type LinearGraphProps = MafsGraphProps<LinearGraphState>;
4
+ export declare const LinearGraph: (props: LinearGraphProps) => JSX.Element;
5
+ export {};
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { MafsGraphProps, RayGraphState } from "../types";
3
+ type Props = MafsGraphProps<RayGraphState>;
4
+ export declare const RayGraph: (props: Props) => JSX.Element;
5
+ export {};
@@ -1,6 +1,5 @@
1
1
  /// <reference types="react" />
2
- import type { SegmentGraphState } from "../interactive-graph-state";
3
- import type { MafsGraphProps } from "../types";
2
+ import type { MafsGraphProps, SegmentGraphState } from "../types";
4
3
  type SegmentProps = MafsGraphProps<SegmentGraphState>;
5
4
  export declare const SegmentGraph: (props: SegmentProps) => JSX.Element;
6
5
  export {};
@@ -0,0 +1,9 @@
1
+ import type { CollinearTuple } from "../../../perseus-types";
2
+ import type { Interval, vec } from "mafs";
3
+ export interface InteractiveLineProps {
4
+ collinearPair: Readonly<CollinearTuple>;
5
+ snaps: [number, number];
6
+ range: [x: Interval, y: Interval];
7
+ onMovePoint: (endpointIndex: number, destination: vec.Vector2) => unknown;
8
+ onMoveLine: (delta: vec.Vector2) => unknown;
9
+ }
@@ -8,10 +8,10 @@ export interface MoveControlPoint {
8
8
  destination: vec.Vector2;
9
9
  }
10
10
  export declare function moveControlPoint(objectIndex: number, pointIndex: number, destination: vec.Vector2): MoveControlPoint;
11
- export declare const MOVE_SEGMENT = "move-segment";
11
+ export declare const MOVE_LINE = "move-line";
12
12
  export interface MoveSegment {
13
- type: typeof MOVE_SEGMENT;
14
- segmentIndex: number;
13
+ type: typeof MOVE_LINE;
14
+ lineIndex: number;
15
15
  delta: vec.Vector2;
16
16
  }
17
- export declare function moveSegment(segmentIndex: number, delta: vec.Vector2): MoveSegment;
17
+ export declare function moveSegment(lineIndex: number, delta: vec.Vector2): MoveSegment;
@@ -1,3 +1,3 @@
1
- import type { InteractiveGraphAction } from "./interactive-graph-action";
2
- import type { InteractiveGraphState } from "./interactive-graph-state";
1
+ import { type InteractiveGraphAction } from "./interactive-graph-action";
2
+ import type { InteractiveGraphState } from "./types";
3
3
  export declare function interactiveGraphReducer(state: Readonly<InteractiveGraphState>, action: InteractiveGraphAction): InteractiveGraphState;
@@ -1,19 +1,10 @@
1
+ import type { InteractiveGraphState } from "./types";
1
2
  import type { PerseusGraphType } from "../../perseus-types";
2
3
  import type { Interval, vec } from "mafs";
3
- export type InteractiveGraphState = SegmentGraphState;
4
- export interface SegmentGraphState extends InteractiveGraphStateCommon {
5
- type: "segment";
6
- segments: Segment[];
7
- }
8
- export interface InteractiveGraphStateCommon {
9
- hasBeenInteractedWith: boolean;
10
- range: [Interval, Interval];
11
- snapStep: vec.Vector2;
12
- }
13
- export type Segment = [vec.Vector2, vec.Vector2];
14
4
  export declare function initializeGraphState(params: {
15
5
  range: [Interval, Interval];
16
6
  step: vec.Vector2;
17
7
  snapStep: vec.Vector2;
18
8
  graph: PerseusGraphType;
19
9
  }): InteractiveGraphState;
10
+ export declare function getGradableGraph<GraphType extends PerseusGraphType>(state: InteractiveGraphState, initialGraph: GraphType): GraphType;
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import type { Widget } from "../../renderer";
3
3
  import "mafs/core.css";
4
4
  import "./mafs-styles.css";
5
- export declare const MafsGraph: React.ForwardRefExoticComponent<import("../../perseus-types").PerseusInteractiveGraphWidgetOptions & {
5
+ export declare const MafsGraph: React.ForwardRefExoticComponent<import("../..").PerseusInteractiveGraphWidgetOptions & {
6
6
  widgetId: string;
7
7
  alignment: string | null | undefined;
8
8
  static: boolean | null | undefined;
@@ -42,7 +42,7 @@ export declare const MafsGraph: React.ForwardRefExoticComponent<import("../../pe
42
42
  crossOutEnabled?: boolean | undefined;
43
43
  editorChangeDelay?: number | undefined;
44
44
  flags?: Record<string, boolean | Record<string, boolean>> | undefined;
45
- onWidgetStartProps?: ((widgets: import("../../perseus-types").PerseusWidgetsMap) => import("../../perseus-types").PerseusWidgetsMap) | undefined;
45
+ onWidgetStartProps?: ((widgets: import("../..").PerseusWidgetsMap) => import("../..").PerseusWidgetsMap) | undefined;
46
46
  }> & {
47
47
  GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
48
48
  baseElements: {
@@ -67,7 +67,7 @@ export declare const MafsGraph: React.ForwardRefExoticComponent<import("../../pe
67
67
  onFocus: (blurPath: import("../..").FocusPath) => void;
68
68
  onBlur: (blurPath: import("../..").FocusPath) => void;
69
69
  findWidgets: (arg1: import("../../types").FilterCriterion) => readonly any[];
70
- reviewModeRubric: import("../../perseus-types").PerseusInteractiveGraphWidgetOptions;
70
+ reviewModeRubric: import("../..").PerseusInteractiveGraphWidgetOptions;
71
71
  onChange: import("../..").ChangeHandler;
72
72
  trackInteraction: (extraData?: {} | undefined) => void;
73
73
  isLastUsedWidget: boolean;
@@ -1,9 +1,22 @@
1
1
  import type { InteractiveGraphAction } from "./interactive-graph-action";
2
- import type { InteractiveGraphState } from "./interactive-graph-state";
3
- import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
2
+ import type { CollinearTuple, PerseusGraphTypeLinearSystem, PerseusGraphTypeRay, PerseusGraphTypeSegment, PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
4
3
  import type { WidgetProps } from "../../types";
4
+ import type { Interval, vec } from "mafs";
5
5
  export type InteractiveGraphProps = WidgetProps<PerseusInteractiveGraphWidgetOptions, PerseusInteractiveGraphWidgetOptions>;
6
6
  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;
11
+ export interface InteractiveGraphStateCommon {
12
+ hasBeenInteractedWith: boolean;
13
+ range: [Interval, Interval];
14
+ snapStep: vec.Vector2;
15
+ }
16
+ export type SegmentGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeSegment, "type" | "coords">;
17
+ export type LinearGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeLinearSystem, "coords"> & {
18
+ type: "linear" | "linear-system";
19
+ };
20
+ export type RayGraphState = InteractiveGraphStateCommon & Pick<PerseusGraphTypeRay, "type"> & {
21
+ coords: readonly CollinearTuple[];
22
+ };
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.3.1",
6
+ "version": "20.4.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },