@khanacademy/perseus 77.1.0 → 77.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.
@@ -0,0 +1,12 @@
1
+ import { type I18nContextType } from "../../../components/i18n-context";
2
+ import type { LogarithmGraphState, Dispatch, InteractiveGraphElementSuite } from "../types";
3
+ import type { Coord } from "@khanacademy/perseus-core";
4
+ import type { Interval, vec } from "mafs";
5
+ export declare function renderLogarithmGraph(state: LogarithmGraphState, dispatch: Dispatch, i18n: I18nContextType): InteractiveGraphElementSuite;
6
+ export declare const constrainAsymptoteKeyboard: (p: vec.Vector2, coords: ReadonlyArray<Coord>, snapStep: vec.Vector2) => vec.Vector2;
7
+ export declare const getLogarithmKeyboardConstraint: (coords: ReadonlyArray<Coord>, asymptote: number, snapStep: vec.Vector2, pointIndex: number, range: [Interval, Interval]) => {
8
+ up: vec.Vector2;
9
+ down: vec.Vector2;
10
+ left: vec.Vector2;
11
+ right: vec.Vector2;
12
+ };
@@ -36,3 +36,28 @@ export declare function getPolygonSideString(sideLength: number, pointIndex: num
36
36
  * The radius scales with the range so it's visible at all graph sizes.
37
37
  */
38
38
  export declare function calculateScaledRadius(range: [Interval, Interval]): number;
39
+ /**
40
+ * Shared keyboard constraint logic for asymptote-based graph points
41
+ * (exponential, logarithm). Computes the next valid position for each
42
+ * arrow-key direction, skipping up to 3 snap steps to avoid positions
43
+ * rejected by the caller's `isValidPosition` predicate.
44
+ *
45
+ * The per-graph validity rules differ (exponential checks Y vs asymptote and
46
+ * X vs other point; logarithm checks X vs asymptote and Y vs other point),
47
+ * so they are injected via the callback.
48
+ */
49
+ export declare function getAsymptoteGraphKeyboardConstraint(coords: ReadonlyArray<Coord>, snapStep: vec.Vector2, pointIndex: number, isValidPosition: (coord: vec.Vector2) => boolean): {
50
+ up: vec.Vector2;
51
+ down: vec.Vector2;
52
+ left: vec.Vector2;
53
+ right: vec.Vector2;
54
+ };
55
+ /**
56
+ * Shared keyboard constraint for asymptote movement (exponential, logarithm).
57
+ * When the next snapped position would land between or on the curve points,
58
+ * snaps past all of them in the direction of travel using a midpoint heuristic.
59
+ *
60
+ * @param orientation - "horizontal" for exponential (asymptote moves on Y-axis),
61
+ * "vertical" for logarithm (asymptote moves on X-axis).
62
+ */
63
+ export declare function constrainAsymptoteKeyboardMovement(p: vec.Vector2, coords: ReadonlyArray<Coord>, snapStep: vec.Vector2, orientation: "horizontal" | "vertical"): vec.Vector2;
@@ -130,6 +130,12 @@ declare class InteractiveGraphQuestionBuilder {
130
130
  snapDegrees?: number;
131
131
  match?: "congruent";
132
132
  }): InteractiveGraphQuestionBuilder;
133
+ withLogarithm(options?: {
134
+ coords?: [Coord, Coord];
135
+ asymptote?: number;
136
+ startCoords?: [Coord, Coord];
137
+ startAsymptote?: number;
138
+ }): InteractiveGraphQuestionBuilder;
133
139
  withAbsoluteValue(options?: {
134
140
  coords?: [Coord, Coord];
135
141
  startCoords?: [Coord, Coord];
@@ -161,9 +161,9 @@ declare class InteractiveGraph extends React.Component<Props, State> {
161
161
  problemNum: number | null | undefined;
162
162
  apiOptions: Readonly<Readonly<{
163
163
  isArticle?: boolean;
164
- onFocusChange?: (newFocusPath: import("../..").FocusPath, oldFocusPath: import("../..").FocusPath, keypadHeight? /**
164
+ onFocusChange?: (newFocusPath: import("../..").FocusPath, oldFocusPath: import("../..").FocusPath, keypadHeight?: number, focusedElement? /**
165
165
  * Whether to show the arrows on the axis.
166
- */: number, focusedElement?: HTMLElement) => unknown;
166
+ */: HTMLElement) => unknown;
167
167
  showAlignmentOptions?: boolean;
168
168
  readOnly?: boolean;
169
169
  editingDisabled?: boolean;
@@ -261,6 +261,8 @@ declare class InteractiveGraph extends React.Component<Props, State> {
261
261
  static getSinusoidEquationString(props: Props): string;
262
262
  static defaultExponentialCoords(props: Props): Coord[];
263
263
  static getExponentialEquationString(props: Props): string;
264
+ static defaultLogarithmCoords(props: Props): Coord[];
265
+ static getLogarithmEquationString(props: Props): string;
264
266
  static getAbsoluteValueEquationString(props: Props): string;
265
267
  static getCurrentTangentCoefficients(props: Props): TangentCoefficient;
266
268
  static defaultTangentCoords(props: Props): Coord[];
@@ -1,6 +1,6 @@
1
1
  import type { Coord } from "../../../interactive2/types";
2
2
  import type { InteractiveGraphState, PairOfPoints } from "../types";
3
- import type { PerseusGraphType, PerseusGraphTypeAbsoluteValue, PerseusGraphTypeAngle, PerseusGraphTypeCircle, PerseusGraphTypeLinear, PerseusGraphTypeLinearSystem, PerseusGraphTypePoint, PerseusGraphTypePolygon, PerseusGraphTypeQuadratic, PerseusGraphTypeRay, PerseusGraphTypeSegment, PerseusGraphTypeSinusoid, PerseusGraphTypeExponential, PerseusGraphTypeTangent } from "@khanacademy/perseus-core";
3
+ import type { PerseusGraphType, PerseusGraphTypeAbsoluteValue, PerseusGraphTypeAngle, PerseusGraphTypeCircle, PerseusGraphTypeLinear, PerseusGraphTypeLinearSystem, PerseusGraphTypePoint, PerseusGraphTypePolygon, PerseusGraphTypeQuadratic, PerseusGraphTypeRay, PerseusGraphTypeSegment, PerseusGraphTypeSinusoid, PerseusGraphTypeExponential, PerseusGraphTypeTangent, PerseusGraphTypeLogarithm } from "@khanacademy/perseus-core";
4
4
  import type { Interval } from "mafs";
5
5
  export type InitializeGraphStateParams = {
6
6
  range: [x: Interval, y: Interval];
@@ -26,6 +26,10 @@ export declare function getExponentialCoords(graph: PerseusGraphTypeExponential,
26
26
  coords: [Coord, Coord];
27
27
  asymptote: number;
28
28
  };
29
+ export declare function getLogarithmCoords(graph: PerseusGraphTypeLogarithm, range: [x: Interval, y: Interval], step: [x: number, y: number]): {
30
+ coords: [Coord, Coord];
31
+ asymptote: number;
32
+ };
29
33
  export declare const getAngleCoords: (params: {
30
34
  graph: PerseusGraphTypeAngle;
31
35
  range: [x: Interval, y: Interval];
@@ -60,6 +60,10 @@ export declare const actions: {
60
60
  movePoint: typeof movePoint;
61
61
  moveCenter: typeof moveCenter;
62
62
  };
63
+ logarithm: {
64
+ movePoint: typeof movePoint;
65
+ moveCenter: typeof moveCenter;
66
+ };
63
67
  absoluteValue: {
64
68
  movePoint: typeof movePoint;
65
69
  };
@@ -15,7 +15,7 @@ export type InteractiveGraphElementSuite = {
15
15
  graph: ReactNode;
16
16
  interactiveElementsDescription: ReactNode;
17
17
  };
18
- export type InteractiveGraphState = AbsoluteValueGraphState | AngleGraphState | SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | NoneGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState | ExponentialGraphState | TangentGraphState;
18
+ export type InteractiveGraphState = AbsoluteValueGraphState | AngleGraphState | SegmentGraphState | LinearSystemGraphState | LinearGraphState | RayGraphState | NoneGraphState | PolygonGraphState | PointGraphState | CircleGraphState | QuadraticGraphState | SinusoidGraphState | ExponentialGraphState | TangentGraphState | LogarithmGraphState;
19
19
  export type UnlimitedGraphState = PointGraphState | PolygonGraphState;
20
20
  export interface InteractiveGraphStateCommon {
21
21
  hasBeenInteractedWith: boolean;
@@ -91,6 +91,12 @@ export interface TangentGraphState extends InteractiveGraphStateCommon {
91
91
  type: "tangent";
92
92
  coords: [vec.Vector2, vec.Vector2];
93
93
  }
94
+ export interface LogarithmGraphState extends InteractiveGraphStateCommon {
95
+ type: "logarithm";
96
+ coords: [vec.Vector2, vec.Vector2];
97
+ /** The x-value of the vertical asymptote (x = asymptote). */
98
+ asymptote: number;
99
+ }
94
100
  export interface AngleGraphState extends InteractiveGraphStateCommon {
95
101
  type: "angle";
96
102
  showAngles?: boolean;
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": "77.1.0",
6
+ "version": "77.2.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -42,15 +42,15 @@
42
42
  "tiny-invariant": "1.3.1",
43
43
  "uuid": "^10.0.0",
44
44
  "@khanacademy/kas": "2.2.1",
45
- "@khanacademy/keypad-context": "3.2.41",
46
- "@khanacademy/kmath": "2.3.1",
47
- "@khanacademy/math-input": "26.4.12",
48
- "@khanacademy/perseus-core": "24.0.0",
49
- "@khanacademy/perseus-score": "8.5.0",
45
+ "@khanacademy/keypad-context": "3.2.42",
46
+ "@khanacademy/kmath": "2.4.0",
47
+ "@khanacademy/math-input": "26.4.13",
48
+ "@khanacademy/perseus-core": "24.1.0",
49
+ "@khanacademy/perseus-linter": "4.9.2",
50
+ "@khanacademy/perseus-score": "8.6.0",
50
51
  "@khanacademy/perseus-utils": "2.1.5",
51
52
  "@khanacademy/pure-markdown": "2.2.7",
52
- "@khanacademy/simple-markdown": "2.2.2",
53
- "@khanacademy/perseus-linter": "4.9.1"
53
+ "@khanacademy/simple-markdown": "2.2.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@khanacademy/wonder-blocks-announcer": "1.1.0",