@khanacademy/perseus 4.0.1 → 5.0.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 (210) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/highlighting/highlightable-content.d.ts +4 -4
  3. package/dist/components/highlighting/highlightable-content.js.flow +4 -7
  4. package/dist/components/highlighting/ui/highlight-renderer.d.ts +6 -6
  5. package/dist/components/highlighting/ui/highlight-renderer.js.flow +6 -8
  6. package/dist/components/highlighting/ui/highlight-set-renderer.d.ts +5 -5
  7. package/dist/components/highlighting/ui/highlight-set-renderer.js.flow +5 -8
  8. package/dist/components/highlighting/ui/highlight-tooltip.d.ts +2 -2
  9. package/dist/components/highlighting/ui/highlight-tooltip.js.flow +2 -4
  10. package/dist/components/highlighting/ui/highlighting-ui.d.ts +3 -3
  11. package/dist/components/highlighting/ui/highlighting-ui.js.flow +2 -2
  12. package/dist/components/highlighting/ui/selection-tracker.d.ts +5 -5
  13. package/dist/components/highlighting/ui/selection-tracker.js.flow +5 -7
  14. package/dist/components/highlighting/word-indexer.d.ts +2 -2
  15. package/dist/components/highlighting/word-indexer.js.flow +2 -2
  16. package/dist/components/inline-icon.d.ts +35 -1
  17. package/dist/components/inline-icon.js.flow +11 -1
  18. package/dist/components/simple-keypad-input.d.ts +1 -1
  19. package/dist/components/simple-keypad-input.js.flow +1 -1
  20. package/dist/components/tex-buttons.d.ts +2 -2
  21. package/dist/components/tex-buttons.js.flow +2 -2
  22. package/dist/error-boundary.d.ts +4 -4
  23. package/dist/error-boundary.js.flow +4 -6
  24. package/dist/es/index.js +53 -233
  25. package/dist/es/index.js.map +1 -1
  26. package/dist/index.js +53 -233
  27. package/dist/index.js.map +1 -1
  28. package/dist/multi-items/multi-renderer.d.ts +1 -1
  29. package/dist/multi-items/multi-renderer.js.flow +1 -1
  30. package/dist/multi-items/prop-type-builders.d.ts +1 -1
  31. package/dist/multi-items/shape-types.d.ts +1 -1
  32. package/dist/multi-items/shape-types.js.flow +1 -1
  33. package/dist/multi-items/tree-types.d.ts +1 -1
  34. package/dist/multi-items/tree-types.js.flow +1 -1
  35. package/dist/perseus-types.d.ts +0 -1
  36. package/dist/perseus-types.js.flow +0 -1
  37. package/dist/widgets/__stories__/test-keypad-context-wrapper.d.ts +6 -0
  38. package/dist/widgets/__stories__/test-keypad-context-wrapper.js.flow +12 -0
  39. package/dist/widgets/expression.d.ts +2 -2
  40. package/dist/widgets/expression.js.flow +2 -2
  41. package/dist/widgets/interaction/element-container.d.ts +5 -4
  42. package/dist/widgets/interaction/element-container.js.flow +6 -11
  43. package/dist/widgets/label-image/marker.d.ts +4 -4
  44. package/dist/widgets/label-image/marker.js.flow +4 -6
  45. package/dist/widgets/numeric-input.d.ts +0 -2
  46. package/dist/widgets/numeric-input.js.flow +0 -4
  47. package/dist/widgets/radio/base-radio.d.ts +7 -1
  48. package/dist/widgets/radio/base-radio.js.flow +7 -1
  49. package/dist/widgets/radio/choice-icon/choice-icon.d.ts +1 -1
  50. package/dist/widgets/radio/choice-icon/choice-icon.js.flow +1 -1
  51. package/dist/widgets/radio/choice-icon/cross-out-line.d.ts +2 -2
  52. package/dist/widgets/radio/choice-icon/cross-out-line.js.flow +2 -2
  53. package/dist/widgets/radio/focus-ring.d.ts +8 -1
  54. package/dist/widgets/radio/focus-ring.js.flow +8 -1
  55. package/dist/widgets/radio/option-status.d.ts +2 -2
  56. package/dist/widgets/radio/option-status.js.flow +2 -2
  57. package/dist/widgets/video-transcript-link.d.ts +1 -1
  58. package/dist/widgets/video-transcript-link.js.flow +1 -1
  59. package/package.json +4 -4
  60. package/src/__stories__/item-renderer.stories.tsx +2 -6
  61. package/src/__stories__/server-item-renderer.stories.tsx +2 -6
  62. package/src/__testdata__/item-renderer.testdata.ts +1 -1
  63. package/src/__testdata__/renderer.testdata.ts +1 -1
  64. package/src/__tests__/item-renderer.test.tsx +1 -2
  65. package/src/__tests__/renderer-api.test.tsx +1 -5
  66. package/src/__tests__/renderer.test.tsx +1 -1
  67. package/src/components/__stories__/button-group.stories.tsx +2 -6
  68. package/src/components/__stories__/fixed-to-responsive.stories.tsx +14 -16
  69. package/src/components/__stories__/graph.stories.tsx +3 -5
  70. package/src/components/__stories__/graphie.stories.tsx +3 -5
  71. package/src/components/__stories__/hud.stories.tsx +2 -6
  72. package/src/components/__stories__/icon.stories.tsx +1 -1
  73. package/src/components/__stories__/image-loader.stories.tsx +4 -4
  74. package/src/components/__stories__/info-tip.stories.tsx +2 -6
  75. package/src/components/__stories__/inline-icon.stories.tsx +4 -8
  76. package/src/components/__stories__/input-with-examples.stories.tsx +6 -10
  77. package/src/components/__stories__/lint.stories.tsx +12 -12
  78. package/src/components/__stories__/math-input.stories.tsx +4 -8
  79. package/src/components/__stories__/math-output.stories.tsx +3 -5
  80. package/src/components/__stories__/multi-button-group.stories.tsx +2 -6
  81. package/src/components/__stories__/number-input.stories.tsx +6 -8
  82. package/src/components/__stories__/prop-check-box.stories.tsx +9 -9
  83. package/src/components/__stories__/range-input.stories.tsx +4 -6
  84. package/src/components/__stories__/simple-keypad-input.stories.tsx +2 -4
  85. package/src/components/__stories__/sortable.stories.tsx +15 -15
  86. package/src/components/__stories__/stub-tag-editor.stories.tsx +5 -9
  87. package/src/components/__stories__/svg-image.stories.tsx +10 -18
  88. package/src/components/__stories__/tex.stories.tsx +1 -3
  89. package/src/components/__stories__/text-buttons.stories.tsx +10 -22
  90. package/src/components/__stories__/text-input.stories.tsx +4 -10
  91. package/src/components/__stories__/text-list-editor.stories.tsx +1 -3
  92. package/src/components/__stories__/zoomable-tex.stories.tsx +6 -4
  93. package/src/components/__stories__/zoomable.stories.tsx +1 -3
  94. package/src/components/fixed-to-responsive.tsx +0 -1
  95. package/src/components/graph.tsx +0 -4
  96. package/src/components/highlighting/highlightable-content.tsx +4 -7
  97. package/src/components/highlighting/ui/highlight-renderer.tsx +6 -9
  98. package/src/components/highlighting/ui/highlight-set-renderer.tsx +5 -8
  99. package/src/components/highlighting/ui/highlight-tooltip.tsx +2 -2
  100. package/src/components/highlighting/ui/highlighting-ui.tsx +5 -15
  101. package/src/components/highlighting/ui/selection-tracker.tsx +6 -9
  102. package/src/components/highlighting/word-indexer.tsx +2 -6
  103. package/src/components/inline-icon.tsx +2 -2
  104. package/src/components/math-input.tsx +0 -2
  105. package/src/components/number-input.tsx +0 -2
  106. package/src/components/simple-keypad-input.tsx +2 -2
  107. package/src/components/tex-buttons.tsx +2 -2
  108. package/src/components/text-list-editor.tsx +0 -4
  109. package/src/components/visibility-observer/__stories__/visibility-observer.stories.tsx +1 -3
  110. package/src/components/zoomable-tex.tsx +0 -2
  111. package/src/components/zoomable.tsx +0 -4
  112. package/src/definition-context.tsx +0 -1
  113. package/src/error-boundary.tsx +4 -7
  114. package/src/hints-renderer.tsx +1 -1
  115. package/src/interactive2/__tests__/movable-point.test.ts +0 -1
  116. package/src/item-renderer.tsx +0 -5
  117. package/src/mixins/changeable.ts +1 -1
  118. package/src/multi-items/__stories__/multi-renderer.stories.tsx +1 -5
  119. package/src/multi-items/__tests__/items.test.ts +3 -13
  120. package/src/multi-items/__tests__/multi-renderer.test.tsx +3 -4
  121. package/src/multi-items/__tests__/prop-type-builders.test.ts +1 -1
  122. package/src/multi-items/__tests__/trees.test.ts +2 -10
  123. package/src/multi-items/multi-renderer.tsx +7 -10
  124. package/src/multi-items/prop-type-builders.ts +1 -1
  125. package/src/multi-items/shape-types.ts +1 -1
  126. package/src/multi-items/tree-types.ts +1 -1
  127. package/src/perseus-markdown.tsx +0 -2
  128. package/src/perseus-types.ts +1 -4
  129. package/src/renderer.tsx +2 -5
  130. package/src/server-item-renderer.tsx +0 -3
  131. package/src/util/graphie.ts +3 -3
  132. package/src/util/interactive.ts +0 -4
  133. package/src/util/math.ts +0 -3
  134. package/src/widgets/__stories__/categorizer.stories.tsx +1 -1
  135. package/src/widgets/__stories__/cs-program.stories.tsx +1 -1
  136. package/src/widgets/__stories__/definition.stories.tsx +3 -7
  137. package/src/widgets/__stories__/dropdown.stories.tsx +1 -1
  138. package/src/widgets/__stories__/explanation.stories.tsx +2 -2
  139. package/src/widgets/__stories__/expression.stories.tsx +113 -13
  140. package/src/widgets/__stories__/graded-group-set.stories.tsx +1 -1
  141. package/src/widgets/__stories__/graded-group.stories.tsx +1 -1
  142. package/src/widgets/__stories__/grapher.stories.tsx +7 -21
  143. package/src/widgets/__stories__/group.stories.tsx +1 -1
  144. package/src/widgets/__stories__/iframe.stories.tsx +1 -1
  145. package/src/widgets/__stories__/image.stories.tsx +2 -2
  146. package/src/widgets/__stories__/input-number.stories.tsx +3 -12
  147. package/src/widgets/__stories__/interaction.stories.tsx +1 -1
  148. package/src/widgets/__stories__/interactive-graph.stories.tsx +9 -9
  149. package/src/widgets/__stories__/matcher.stories.tsx +1 -1
  150. package/src/widgets/__stories__/matrix.stories.tsx +1 -1
  151. package/src/widgets/__stories__/number-line.stories.tsx +1 -1
  152. package/src/widgets/__stories__/numeric-input.stories.tsx +3 -5
  153. package/src/widgets/__stories__/orderer.stories.tsx +1 -1
  154. package/src/widgets/__stories__/passage-ref.stories.tsx +2 -2
  155. package/src/widgets/__stories__/passage.stories.tsx +3 -9
  156. package/src/widgets/__stories__/radio.stories.tsx +3 -5
  157. package/src/widgets/__stories__/sorter.stories.tsx +1 -1
  158. package/src/widgets/__stories__/{on-screen-keypad.stories.tsx → test-keypad-context-wrapper.tsx} +15 -57
  159. package/src/widgets/__stories__/transformer.stories.tsx +1 -1
  160. package/src/widgets/__stories__/unit.stories.tsx +1 -3
  161. package/src/widgets/__stories__/video-transcript-link.stories.tsx +2 -6
  162. package/src/widgets/__stories__/video.stories.tsx +1 -1
  163. package/src/widgets/__testdata__/expression.testdata.ts +16 -12
  164. package/src/widgets/__testdata__/group.testdata.ts +0 -2
  165. package/src/widgets/__testdata__/numeric-input.testdata.ts +0 -1
  166. package/src/widgets/__testdata__/transformer.testdata.ts +0 -1
  167. package/src/widgets/__tests__/group.test.tsx +0 -2
  168. package/src/widgets/__tests__/radio/focus-ring.test.tsx +0 -1
  169. package/src/widgets/__tests__/radio.test.ts +1 -1
  170. package/src/widgets/expression.tsx +4 -4
  171. package/src/widgets/graded-group-set.tsx +0 -4
  172. package/src/widgets/graded-group.tsx +0 -4
  173. package/src/widgets/grapher/util.tsx +1 -5
  174. package/src/widgets/grapher.tsx +0 -5
  175. package/src/widgets/group.tsx +0 -1
  176. package/src/widgets/interaction/element-container.tsx +7 -8
  177. package/src/widgets/interaction.tsx +0 -1
  178. package/src/widgets/interactive-graph.tsx +3 -62
  179. package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +2 -4
  180. package/src/widgets/label-image/__stories__/marker.stories.tsx +9 -19
  181. package/src/widgets/label-image/marker.tsx +4 -4
  182. package/src/widgets/label-image.tsx +1 -1
  183. package/src/widgets/measurer.tsx +0 -1
  184. package/src/widgets/number-line.tsx +0 -2
  185. package/src/widgets/numeric-input.tsx +0 -3
  186. package/src/widgets/orderer.tsx +0 -3
  187. package/src/widgets/passage/passage-markdown.tsx +3 -3
  188. package/src/widgets/passage-ref-target.tsx +0 -1
  189. package/src/widgets/passage.tsx +1 -1
  190. package/src/widgets/plotter.tsx +0 -1
  191. package/src/widgets/radio/__stories__/base-radio.stories.tsx +13 -21
  192. package/src/widgets/radio/__stories__/choice-icon.stories.tsx +9 -11
  193. package/src/widgets/radio/__stories__/choice-none-above.stories.tsx +1 -1
  194. package/src/widgets/radio/__stories__/choice.stories.tsx +4 -4
  195. package/src/widgets/radio/__stories__/focus-ring.stories.tsx +1 -1
  196. package/src/widgets/radio/__stories__/option-status.stories.tsx +2 -4
  197. package/src/widgets/radio/base-radio.tsx +2 -2
  198. package/src/widgets/radio/choice-icon/choice-icon.tsx +5 -5
  199. package/src/widgets/radio/choice-icon/cross-out-line.tsx +1 -3
  200. package/src/widgets/radio/choice-none-above.tsx +2 -2
  201. package/src/widgets/radio/choice.tsx +1 -3
  202. package/src/widgets/radio/focus-ring.tsx +1 -1
  203. package/src/widgets/radio/option-status.tsx +2 -4
  204. package/src/widgets/radio/widget.tsx +0 -1
  205. package/src/widgets/reaction-diagram.tsx +2 -2
  206. package/src/widgets/transformer.tsx +1 -16
  207. package/src/widgets/video-transcript-link.tsx +1 -1
  208. package/src/widgets.ts +1 -1
  209. package/src/zoom.ts +0 -3
  210. package/tsconfig.tsbuildinfo +1 -1
@@ -1281,9 +1281,7 @@ const ShapeTypes = {
1281
1281
  fixed: !options.translatable && !options.editable,
1282
1282
  },
1283
1283
  visible: options.showPoints,
1284
- // $FlowFixMe[prop-missing]
1285
1284
  snapX: (options.snap && options.snap[0]) || 0,
1286
- // $FlowFixMe[prop-missing]
1287
1285
  snapY: (options.snap && options.snap[1]) || 0,
1288
1286
  bounded: false, // Don't bound it when placing it on the graph
1289
1287
  onMove: onMove,
@@ -2111,7 +2109,6 @@ class Transformer extends React.Component<Props> {
2111
2109
  transform = {
2112
2110
  type: "translation",
2113
2111
  // NOTE(kevib): these should be numbers
2114
- // $FlowFixMe[incompatible-type]
2115
2112
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'. | TS2322 - Type 'null' is not assignable to type 'number'.
2116
2113
  vector: [null, null],
2117
2114
  };
@@ -2120,11 +2117,9 @@ class Transformer extends React.Component<Props> {
2120
2117
  transform = {
2121
2118
  type: "rotation",
2122
2119
  // NOTE(kevib): these should be numbers
2123
- // $FlowFixMe[incompatible-type]
2124
2120
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'. | TS2322 - Type 'null' is not assignable to type 'number'.
2125
2121
  center: [null, null],
2126
2122
  // NOTE(kevib): this should be a number
2127
- // $FlowFixMe[incompatible-type]
2128
2123
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'.
2129
2124
  angleDeg: null,
2130
2125
  };
@@ -2135,11 +2130,9 @@ class Transformer extends React.Component<Props> {
2135
2130
  type: "reflection",
2136
2131
  line: [
2137
2132
  // NOTE(kevib): these should be numbers
2138
- // $FlowFixMe[incompatible-type]
2139
2133
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'. | TS2322 - Type 'null' is not assignable to type 'number'.
2140
2134
  [null, null],
2141
2135
  // NOTE(kevib): these should be numbers
2142
- // $FlowFixMe[incompatible-type]
2143
2136
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'. | TS2322 - Type 'null' is not assignable to type 'number'.
2144
2137
  [null, null],
2145
2138
  ],
@@ -2149,11 +2142,9 @@ class Transformer extends React.Component<Props> {
2149
2142
  transform = {
2150
2143
  type: "dilation",
2151
2144
  // NOTE(kevib): these should be numbers
2152
- // $FlowFixMe[incompatible-type]
2153
2145
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'. | TS2322 - Type 'null' is not assignable to type 'number'.
2154
2146
  center: [null, null],
2155
2147
  // NOTE(kevib): this should be a number
2156
- // $FlowFixMe[incompatible-type]
2157
2148
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'null' is not assignable to type 'number'.
2158
2149
  scale: null,
2159
2150
  };
@@ -2381,7 +2372,6 @@ class Transformer extends React.Component<Props> {
2381
2372
  if (reflectRotateHandle) {
2382
2373
  $(reflectRotateHandle).on("move", function () {
2383
2374
  const rotateHandleApprox = self.snapCoord(
2384
- // $FlowFixMe[incompatible-use]
2385
2375
  // @ts-expect-error [FEI-5003] - TS2531 - Object is possibly 'null'.
2386
2376
  reflectRotateHandle.coord,
2387
2377
  );
@@ -2476,7 +2466,6 @@ class Transformer extends React.Component<Props> {
2476
2466
  hoverWidth: this.scaleToCurrentRange(0.4),
2477
2467
  onMove: function (newAngle, oldAngle) {
2478
2468
  const transform = self.getRotationTransformFromAngle(
2479
- // $FlowFixMe[incompatible-use]
2480
2469
  self.rotatePoint.coord,
2481
2470
  newAngle - oldAngle,
2482
2471
  );
@@ -2530,9 +2519,7 @@ class Transformer extends React.Component<Props> {
2530
2519
  self.doTransform({
2531
2520
  type: "dilation",
2532
2521
  // NOTE(kevinb): It's hard to convince that this.dilationCircle
2533
- // will still be defined here.
2534
- // $FlowFixMe[incompatible-use]
2535
- center: self.dilationCircle.centerPoint.coord,
2522
+ // will still be defined here. center: self.dilationCircle.centerPoint.coord,
2536
2523
  scale: newRadius / oldRadius,
2537
2524
  });
2538
2525
  },
@@ -2569,7 +2556,6 @@ class Transformer extends React.Component<Props> {
2569
2556
  origOnMoveEnd(args);
2570
2557
  }
2571
2558
  self.changeTool("dilation", {
2572
- // $FlowFixMe[incompatible-use]
2573
2559
  coord: self.dilationCircle.centerPoint.coord,
2574
2560
  });
2575
2561
  };
@@ -2750,7 +2736,6 @@ class Transformer extends React.Component<Props> {
2750
2736
  // handle coordinates in formal mode without movement, since
2751
2737
  // the movablepoints never move
2752
2738
  shape: {
2753
- // $FlowFixMe[incompatible-use]
2754
2739
  type: this.shape.type,
2755
2740
  coords: this.getCoords(),
2756
2741
  options: this.shape?.getOptions(),
@@ -31,7 +31,7 @@ type Props = {
31
31
  /**
32
32
  * Video Transcript Link Component.
33
33
  */
34
- const VideoTranscriptLink: React.FC<Props> = (props): React.ReactElement => {
34
+ const VideoTranscriptLink = (props: Props): React.ReactElement => {
35
35
  const {location} = props;
36
36
  const {useVideo} = getDependencies();
37
37
  const [id, kind] = IS_URL.test(location)
package/src/widgets.ts CHANGED
@@ -363,7 +363,7 @@ const validAlignments: ReadonlyArray<Alignment> = [
363
363
  * invalid.
364
364
  */
365
365
  // TODO(alex): Change this to run as a testcase (vs. being run at runtime)
366
- // TODO(LP-10707): I think this can be completely removed because our Flow types
366
+ // TODO(LP-10707): I think this can be completely removed because our TypeScript types
367
367
  // enforce this!
368
368
  export const validateAlignments = () => {
369
369
  _.each(widgets, function (widgetInfo) {
package/src/zoom.ts CHANGED
@@ -399,15 +399,12 @@ Zoom.prototype._calculateZoom = function () {
399
399
  const viewportAspectRatio = viewportWidth / viewportHeight;
400
400
 
401
401
  if (
402
- // $FlowFixMe[invalid-compare]
403
402
  originalFullImageWidth < viewportWidth &&
404
- // $FlowFixMe[invalid-compare]
405
403
  originalFullImageHeight < viewportHeight
406
404
  ) {
407
405
  this._imgScaleFactor = maxScaleFactor;
408
406
  } else if (imageAspectRatio < viewportAspectRatio) {
409
407
  this._imgScaleFactor =
410
- // $FlowFixMe[unsafe-addition]
411
408
  (viewportHeight / originalFullImageHeight) * maxScaleFactor;
412
409
  } else {
413
410
  this._imgScaleFactor =