Skip to content

Commit

Permalink
Merge branch 'main' into sr-linear-interactive-elements
Browse files Browse the repository at this point in the history
  • Loading branch information
nishasy committed Jan 21, 2025
2 parents 8e9201d + 93eb5a0 commit f20fb25
Show file tree
Hide file tree
Showing 223 changed files with 2,415 additions and 3,708 deletions.
5 changes: 0 additions & 5 deletions .changeset/tidy-baboons-tie.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/wild-keys-sit.md

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/storybook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
projectToken: ${{ secrets.CHROMATIC_APP_CODE }}
autoAcceptChanges: "main"
onlyStoryFiles: "**/*regression.stories.tsx"
onlyStoryFiles: "**/*-regression.stories.tsx"
# NOTE: We cannot enable `onlyChanged` because it is
# incompatible with `onlyStoryFiles` which we use above.
# onlyChanged: true # Enable TurboSnap!
10 changes: 10 additions & 0 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ const preview: Preview = {
// These parameters apply to all stories, both inside and outside the fixture
// framework.
parameters: {
// Disables Chromatic's snapshotting on a global level
// We disable snapshotting globally because we have enabled
// turbosnaps for `-regression.stories.tsx` files. If we have
// snapshots enabled globally, we pay for turbosnaps even for
// skipped stories/tests (which is all of them).
// We then enable snapshots for `-regression.stories.tsx` files in
// each of those files (unfortunately, this is how we have to do
// it).
chromatic: {disableSnapshot: true},

options: {
storySort: {
order: ["Perseus", "PerseusEditor", "Math-Input", "*"],
Expand Down
2 changes: 1 addition & 1 deletion config/test/custom-matchers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Ok here we are

import type {PerseusScore} from "../../packages/perseus/src/types";
import type {PerseusScore} from "../../packages/perseus-score/src/validation.types";

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
Expand Down
17 changes: 17 additions & 0 deletions dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# @khanacademy/perseus-dev-ui

## 5.1.1

### Patch Changes

- [#2101](https://github.com/Khan/perseus/pull/2101) [`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae) Thanks [@handeyeco](https://github.com/handeyeco)! - Move scorers and validators to `perseus-score`

* [#2109](https://github.com/Khan/perseus/pull/2109) [`41ffd4a71`](https://github.com/Khan/perseus/commit/41ffd4a71673399657d7024c206af4fa4e0be267) Thanks [@dependabot](https://github.com/apps/dependabot)! - Updating our wonder-blocks packages with the latest versions.

* Updated dependencies [[`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae), [`41ffd4a71`](https://github.com/Khan/perseus/commit/41ffd4a71673399657d7024c206af4fa4e0be267)]:
- @khanacademy/kmath@0.3.0
- @khanacademy/perseus-core@3.2.0
- @khanacademy/math-input@22.2.1
- @khanacademy/kas@0.4.11
- @khanacademy/perseus-linter@1.2.13
- @khanacademy/pure-markdown@0.3.22
- @khanacademy/simple-markdown@0.13.15

## 5.1.0

### Minor Changes
Expand Down
4 changes: 3 additions & 1 deletion dev/flipbook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ import {
} from "./flipbook-model";
import {Header} from "./header";

import type {APIOptions, PerseusScore} from "../packages/perseus/src";
import type {APIOptions} from "../packages/perseus/src";
import type {
InteractiveGraphWidget,
PerseusRenderer,
PerseusWidget,
} from "../packages/perseus-core/src/data-schema";
import type {PerseusScore} from "../packages/perseus-score/src/validation.types";
import type {PropsFor} from "@khanacademy/wonder-blocks-core";

import "../packages/perseus/src/styles/perseus-renderer.less";

const exampleCommands = `
Expand Down
34 changes: 17 additions & 17 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus dev UI",
"author": "Khan Academy",
"license": "MIT",
"version": "5.1.0",
"version": "5.1.1",
"private": true,
"repository": {
"type": "git",
Expand All @@ -14,22 +14,22 @@
"dev": "vite"
},
"dependencies": {
"@khanacademy/kas": "^0.4.10",
"@khanacademy/kmath": "^0.2.0",
"@khanacademy/math-input": "^22.2.0",
"@khanacademy/perseus-core": "3.1.0",
"@khanacademy/perseus-linter": "^1.2.12",
"@khanacademy/pure-markdown": "^0.3.21",
"@khanacademy/simple-markdown": "^0.13.14",
"@khanacademy/wonder-blocks-banner": "4.0.3",
"@khanacademy/wonder-blocks-icon": "5.0.3",
"@khanacademy/wonder-blocks-icon-button": "6.0.3",
"@khanacademy/wonder-blocks-link": "7.0.3",
"@khanacademy/wonder-blocks-search-field": "4.0.1",
"@khanacademy/wonder-blocks-timing": "6.0.0",
"@khanacademy/wonder-blocks-tokens": "3.0.0",
"@khanacademy/wonder-blocks-toolbar": "5.0.3",
"@khanacademy/wonder-blocks-tooltip": "4.0.1",
"@khanacademy/kas": "^0.4.11",
"@khanacademy/kmath": "^0.3.0",
"@khanacademy/math-input": "^22.2.1",
"@khanacademy/perseus-core": "3.2.0",
"@khanacademy/perseus-linter": "^1.2.13",
"@khanacademy/pure-markdown": "^0.3.22",
"@khanacademy/simple-markdown": "^0.13.15",
"@khanacademy/wonder-blocks-banner": "4.0.5",
"@khanacademy/wonder-blocks-icon": "5.0.5",
"@khanacademy/wonder-blocks-icon-button": "6.0.5",
"@khanacademy/wonder-blocks-link": "7.0.5",
"@khanacademy/wonder-blocks-search-field": "4.0.5",
"@khanacademy/wonder-blocks-timing": "6.0.1",
"@khanacademy/wonder-blocks-tokens": "3.0.1",
"@khanacademy/wonder-blocks-toolbar": "5.0.5",
"@khanacademy/wonder-blocks-tooltip": "4.0.3",
"@khanacademy/wonder-stuff-core": "1.5.4",
"@phosphor-icons/core": "^2.0.2"
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"@khanacademy/eslint-config": "^5.0.1",
"@khanacademy/eslint-plugin": "^3.1.1",
"@khanacademy/mathjax-renderer": "^2.1.1",
"@khanacademy/wonder-blocks-button": "7.0.3",
"@khanacademy/wonder-blocks-layout": "3.0.3",
"@khanacademy/wonder-blocks-button": "7.0.5",
"@khanacademy/wonder-blocks-layout": "3.0.5",
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
"@popperjs/core": "^2.10.2",
"@rollup/plugin-alias": "^3.1.9",
Expand Down
7 changes: 7 additions & 0 deletions packages/kas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @khanacademy/kas

## 0.4.11

### Patch Changes

- Updated dependencies [[`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae)]:
- @khanacademy/perseus-core@3.2.0

## 0.4.10

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/kas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A lightweight JavaScript CAS for comparing expressions and equations.",
"author": "Khan Academy",
"license": "MIT",
"version": "0.4.10",
"version": "0.4.11",
"publishConfig": {
"access": "public"
},
Expand All @@ -27,7 +27,7 @@
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"dependencies": {
"@khanacademy/perseus-core": "3.1.0"
"@khanacademy/perseus-core": "3.2.0"
},
"devDependencies": {
"jison": "0.4.15",
Expand Down
7 changes: 7 additions & 0 deletions packages/keypad-context/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @khanacademy/keypad-context

## 1.0.14

### Patch Changes

- Updated dependencies [[`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae)]:
- @khanacademy/perseus-core@3.2.0

## 1.0.13

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/keypad-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus keypad context",
"author": "Khan Academy",
"license": "MIT",
"version": "1.0.13",
"version": "1.0.14",
"publishConfig": {
"access": "public"
},
Expand All @@ -26,7 +26,7 @@
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"dependencies": {
"@khanacademy/perseus-core": "3.1.0"
"@khanacademy/perseus-core": "3.2.0"
},
"devDependencies": {
"react": "^18.2.0"
Expand Down
11 changes: 11 additions & 0 deletions packages/kmath/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# @khanacademy/kmath

## 0.3.0

### Minor Changes

- [#2101](https://github.com/Khan/perseus/pull/2101) [`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae) Thanks [@handeyeco](https://github.com/handeyeco)! - Move scorers and validators to `perseus-score`

### Patch Changes

- Updated dependencies [[`9cabe689a`](https://github.com/Khan/perseus/commit/9cabe689a7aa143f95adf4556bf5c10d654a66ae)]:
- @khanacademy/perseus-core@3.2.0

## 0.2.0

### Minor Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/kmath/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Khan Academy's Javascript Numeric Math Utilities",
"author": "Khan Academy",
"license": "MIT",
"version": "0.2.0",
"version": "0.3.0",
"publishConfig": {
"access": "public"
},
Expand All @@ -25,7 +25,7 @@
"test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
},
"dependencies": {
"@khanacademy/perseus-core": "3.1.0"
"@khanacademy/perseus-core": "3.2.0"
},
"devDependencies": {
"perseus-build-settings": "^0.4.3",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
import {clockwise} from "../../../util/geometry";
// This file contains helper functions for working with angles.

import type {Coord} from "@khanacademy/perseus";
import type {vec} from "mafs";
import {clockwise} from "./geometry";

// This file contains helper functions for working with angles.
import type {Coord} from "@khanacademy/perseus-core";

export function convertDegreesToRadians(degrees: number): number {
return (degrees / 180) * Math.PI;
}

// Returns a value between -180 and 180, inclusive. The angle is measured
// between the positive x-axis and the given vector.
export function calculateAngleInDegrees([x, y]: vec.Vector2): number {
export function calculateAngleInDegrees([x, y]: Coord): number {
return (Math.atan2(y, x) * 180) / Math.PI;
}

// Converts polar coordinates to cartesian. The th(eta) parameter is in degrees.
export function polar(r: number | vec.Vector2, th: number): vec.Vector2 {
export function polar(r: number | Coord, th: number): Coord {
if (typeof r === "number") {
r = [r, r];
}
Expand All @@ -26,10 +25,7 @@ export function polar(r: number | vec.Vector2, th: number): vec.Vector2 {
// This function calculates the angle between two points and an optional vertex.
// If the vertex is not provided, the angle is measured between the two points.
// This does not account for reflex angles or clockwise position.
export const getAngleFromVertex = (
point: vec.Vector2,
vertex: vec.Vector2,
): number => {
export const getAngleFromVertex = (point: Coord, vertex: Coord): number => {
const x = point[0] - vertex[0];
const y = point[1] - vertex[1];
if (!x && !y) {
Expand Down
62 changes: 62 additions & 0 deletions packages/kmath/src/coefficients.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type {SineCoefficient} from "./geometry";
import type {Coord} from "@khanacademy/perseus-core";

export type NamedSineCoefficient = {
amplitude: number;
angularFrequency: number;
phase: number;
verticalOffset: number;
};

// TODO: there's another, very similar getSinusoidCoefficients function
// they should probably be merged
export function getSinusoidCoefficients(
coords: ReadonlyArray<Coord>,
): SineCoefficient {
// It's assumed that p1 is the root and p2 is the first peak
const p1 = coords[0];
const p2 = coords[1];

// Resulting coefficients are canonical for this sine curve
const amplitude = p2[1] - p1[1];
const angularFrequency = Math.PI / (2 * (p2[0] - p1[0]));
const phase = p1[0] * angularFrequency;
const verticalOffset = p1[1];

return [amplitude, angularFrequency, phase, verticalOffset];
}

export type QuadraticCoefficient = [number, number, number];

// TODO: there's another, very similar getQuadraticCoefficients function
// they should probably be merged
export function getQuadraticCoefficients(
coords: ReadonlyArray<Coord>,
): QuadraticCoefficient {
const p1 = coords[0];
const p2 = coords[1];
const p3 = coords[2];

const denom = (p1[0] - p2[0]) * (p1[0] - p3[0]) * (p2[0] - p3[0]);
if (denom === 0) {
// Many of the callers assume that the return value is always defined.
// @ts-expect-error - TS2322 - Type 'undefined' is not assignable to type 'QuadraticCoefficient'.
return;
}
const a =
(p3[0] * (p2[1] - p1[1]) +
p2[0] * (p1[1] - p3[1]) +
p1[0] * (p3[1] - p2[1])) /
denom;
const b =
(p3[0] * p3[0] * (p1[1] - p2[1]) +
p2[0] * p2[0] * (p3[1] - p1[1]) +
p1[0] * p1[0] * (p2[1] - p3[1])) /
denom;
const c =
(p2[0] * p3[0] * (p2[0] - p3[0]) * p1[1] +
p3[0] * p1[0] * (p3[0] - p1[0]) * p2[1] +
p1[0] * p2[0] * (p1[0] - p2[0]) * p3[1]) /
denom;
return [a, b, c];
}
File renamed without changes.
Loading

0 comments on commit f20fb25

Please sign in to comment.