@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.
Files changed (57) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/es/index.css +209 -128
  3. package/dist/es/index.js +1026 -3516
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.css +209 -128
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +917 -3409
  8. package/dist/index.js.map +1 -1
  9. package/dist/mixins/changeable.d.ts +1 -1
  10. package/dist/perseus-api.d.ts +1 -0
  11. package/dist/perseus-types.d.ts +2 -109
  12. package/dist/renderer.d.ts +2 -4
  13. package/dist/server-item-renderer.d.ts +1 -0
  14. package/dist/strings.js +0 -29
  15. package/dist/types.d.ts +4 -4
  16. package/dist/util/geometry.d.ts +2 -0
  17. package/dist/util/graphie.d.ts +107 -1
  18. package/dist/util/math.d.ts +2 -0
  19. package/dist/util/parse-perseus-json.d.ts +3 -3
  20. package/dist/widgets/expression.d.ts +8 -2
  21. package/dist/widgets/label-image.d.ts +2 -0
  22. package/dist/widgets.d.ts +1 -1
  23. package/package.json +3 -4
  24. package/src/__testdata__/renderer.testdata.ts +152 -0
  25. package/src/__tests__/renderer.test.tsx +17 -0
  26. package/src/__tests__/widgets.test.ts +0 -1
  27. package/src/components/math-input.tsx +4 -6
  28. package/src/extra-widgets.ts +0 -2
  29. package/src/index.ts +8 -4
  30. package/src/mixins/changeable.ts +1 -1
  31. package/src/perseus-types.ts +1 -154
  32. package/src/renderer.tsx +14 -8
  33. package/src/styles/perseus-renderer.less +0 -1
  34. package/src/types.ts +9 -5
  35. package/src/util/geometry.test.ts +75 -0
  36. package/src/util/geometry.ts +19 -0
  37. package/src/util/graphie.test.ts +1291 -0
  38. package/src/util/graphie.ts +832 -784
  39. package/src/util/interactive.ts +23 -51
  40. package/src/util/math.test.ts +11 -0
  41. package/src/util/math.ts +8 -0
  42. package/src/util/parse-perseus-json.test.ts +3 -3
  43. package/src/util/parse-perseus-json.ts +4 -4
  44. package/src/util/register-all-widgets-for-testing.ts +1 -3
  45. package/src/widgets/__tests__/__snapshots__/input-number.test.ts.snap +4 -2
  46. package/src/widgets/__tests__/__snapshots__/numeric-input.test.ts.snap +4 -2
  47. package/src/widgets/__tests__/expression-mobile.test.tsx +8 -5
  48. package/src/widgets/__tests__/renderQuestion.tsx +11 -3
  49. package/src/widgets/expression.tsx +1 -23
  50. package/src/widgets/label-image.tsx +0 -1
  51. package/src/widgets.ts +1 -9
  52. package/tsconfig-build.tsbuildinfo +1 -1
  53. package/dist/widgets/transformer.d.ts +0 -94
  54. package/src/styles/widgets/transformer.less +0 -29
  55. package/src/widgets/__stories__/transformer.stories.tsx +0 -14
  56. package/src/widgets/__testdata__/transformer.testdata.ts +0 -107
  57. package/src/widgets/transformer.tsx +0 -2936
@@ -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(