@khanacademy/perseus 18.0.1 → 19.1.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/CHANGELOG.md +36 -0
- package/dist/es/index.css +209 -128
- package/dist/es/index.js +1026 -3516
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +209 -128
- package/dist/index.d.ts +3 -3
- package/dist/index.js +917 -3409
- package/dist/index.js.map +1 -1
- package/dist/mixins/changeable.d.ts +1 -1
- package/dist/perseus-api.d.ts +1 -0
- package/dist/perseus-types.d.ts +2 -109
- package/dist/renderer.d.ts +2 -4
- package/dist/server-item-renderer.d.ts +1 -0
- package/dist/strings.js +0 -29
- package/dist/types.d.ts +4 -4
- package/dist/util/geometry.d.ts +2 -0
- package/dist/util/graphie.d.ts +107 -1
- package/dist/util/math.d.ts +2 -0
- package/dist/util/parse-perseus-json.d.ts +3 -3
- package/dist/widgets/expression.d.ts +8 -2
- package/dist/widgets/label-image.d.ts +2 -0
- package/dist/widgets.d.ts +1 -1
- package/package.json +3 -4
- package/src/__testdata__/renderer.testdata.ts +152 -0
- package/src/__tests__/renderer.test.tsx +17 -0
- package/src/__tests__/widgets.test.ts +0 -1
- package/src/components/math-input.tsx +4 -6
- package/src/extra-widgets.ts +0 -2
- package/src/index.ts +8 -4
- package/src/mixins/changeable.ts +1 -1
- package/src/perseus-types.ts +1 -154
- package/src/renderer.tsx +14 -8
- package/src/styles/perseus-renderer.less +0 -1
- package/src/types.ts +9 -5
- package/src/util/geometry.test.ts +75 -0
- package/src/util/geometry.ts +19 -0
- package/src/util/graphie.test.ts +1291 -0
- package/src/util/graphie.ts +832 -784
- package/src/util/interactive.ts +23 -51
- package/src/util/math.test.ts +11 -0
- package/src/util/math.ts +8 -0
- package/src/util/parse-perseus-json.test.ts +3 -3
- package/src/util/parse-perseus-json.ts +4 -4
- package/src/util/register-all-widgets-for-testing.ts +1 -3
- package/src/widgets/__tests__/__snapshots__/input-number.test.ts.snap +4 -2
- package/src/widgets/__tests__/__snapshots__/numeric-input.test.ts.snap +4 -2
- package/src/widgets/__tests__/expression-mobile.test.tsx +8 -5
- package/src/widgets/__tests__/renderQuestion.tsx +11 -3
- package/src/widgets/expression.tsx +1 -23
- package/src/widgets/label-image.tsx +0 -1
- package/src/widgets.ts +1 -9
- package/tsconfig-build.tsbuildinfo +1 -1
- package/dist/widgets/transformer.d.ts +0 -94
- package/src/styles/widgets/transformer.less +0 -29
- package/src/widgets/__stories__/transformer.stories.tsx +0 -14
- package/src/widgets/__testdata__/transformer.testdata.ts +0 -107
- package/src/widgets/transformer.tsx +0 -2936
package/src/util/geometry.ts
CHANGED
|
@@ -7,6 +7,8 @@ import _ from "underscore";
|
|
|
7
7
|
|
|
8
8
|
import Util from "../util";
|
|
9
9
|
|
|
10
|
+
import {sum} from "./math";
|
|
11
|
+
|
|
10
12
|
import type {Coord, Line} from "../interactive2/types";
|
|
11
13
|
|
|
12
14
|
const {eq, deepEq} = Util;
|
|
@@ -83,6 +85,23 @@ export function vector(a, b) {
|
|
|
83
85
|
});
|
|
84
86
|
}
|
|
85
87
|
|
|
88
|
+
export function reverseVector(vector: Coord): Coord {
|
|
89
|
+
return [-vector[0], -vector[1]];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Returns whether connecting the given sequence of `points` forms a clockwise
|
|
93
|
+
// path (assuming a closed loop, where the last point connects back to the
|
|
94
|
+
// first).
|
|
95
|
+
export function clockwise(points: Coord[]): boolean {
|
|
96
|
+
const segments = _.zip(points, points.slice(1).concat(points.slice(0, 1)));
|
|
97
|
+
const areas = _.map(segments, function (segment) {
|
|
98
|
+
const p1 = segment[0];
|
|
99
|
+
const p2 = segment[1];
|
|
100
|
+
return (p2[0] - p1[0]) * (p2[1] + p1[1]);
|
|
101
|
+
});
|
|
102
|
+
return sum(areas) > 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
86
105
|
export function magnitude(v: ReadonlyArray<Coord>): number {
|
|
87
106
|
return Math.sqrt(
|
|
88
107
|
_.reduce(
|