@khanacademy/perseus 56.2.0 → 57.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.
package/dist/index.js CHANGED
@@ -16854,7 +16854,7 @@ class Zoomable extends React__namespace.Component {
16854
16854
  * measurements.
16855
16855
  */
16856
16856
  const computeMathBounds = (parentNode, parentBounds) => {
16857
- const textElement = parentNode.querySelector(".katex-html") || parentNode.querySelector(".MathJax");
16857
+ const textElement = parentNode.querySelector(".MathJax");
16858
16858
  const textBounds = {
16859
16859
  // @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'offsetWidth' does not exist on type 'Element'.
16860
16860
  width: textElement.offsetWidth,
@@ -19177,14 +19177,7 @@ class Renderer extends React__namespace.Component {
19177
19177
  }))));
19178
19178
  }
19179
19179
  if (node.type === "math") {
19180
- // Replace uses of \begin{align}...\end{align} which KaTeX doesn't
19181
- // support (yet) with \begin{aligned}...\end{aligned} which renders
19182
- // the same is supported by KaTeX. It does the same for align*.
19183
- // TODO(kevinb) update content to use aligned instead of align.
19184
- // TODO(LEMS-1608) Remove this replacement as MathJax supports the
19185
- // "align" macro correctly (and, in fact, it is not synonymous with
19186
- // "aligned").
19187
- const tex = node.content.replace(/\{align[*]?\}/g, "{aligned}");
19180
+ const tex = node.content;
19188
19181
 
19189
19182
  // We render math here instead of in perseus-markdown.jsx
19190
19183
  // because we need to pass it our onRender callback.
@@ -24419,7 +24412,8 @@ const _choiceTransform = (widgetOptions, strings, problemNum) => {
24419
24412
  const choices = widgetOptions.choices.map((choice, i) => {
24420
24413
  return {
24421
24414
  ...choice,
24422
- originalIndex: i
24415
+ originalIndex: i,
24416
+ correct: Boolean(choice.correct)
24423
24417
  };
24424
24418
  });
24425
24419
 
@@ -25420,7 +25414,7 @@ class GradedGroupAnswerBar extends React__namespace.Component {
25420
25414
  }, nextQuestion));
25421
25415
  }
25422
25416
  }
25423
- const fontSize = 17;
25417
+ const fontSize$1 = 17;
25424
25418
  const styles$j = {
25425
25419
  answerBar: {
25426
25420
  display: "flex",
@@ -25445,7 +25439,7 @@ const styles$j = {
25445
25439
  flexDirection: "row",
25446
25440
  alignItems: "center",
25447
25441
  fontWeight: "bold",
25448
- fontSize: fontSize
25442
+ fontSize: fontSize$1
25449
25443
  }
25450
25444
  };
25451
25445
 
@@ -28132,6 +28126,7 @@ const defaultGraphConfig = {
28132
28126
  width: 0,
28133
28127
  height: 0,
28134
28128
  labels: [],
28129
+ labelLocation: "onAxis",
28135
28130
  disableKeyboardInteraction: false,
28136
28131
  interactiveColor: "var(--mafs-blue)"
28137
28132
  };
@@ -28355,6 +28350,8 @@ function escapeIfUnescaped(character) {
28355
28350
  }
28356
28351
  }
28357
28352
 
28353
+ // Exported for testing purposes
28354
+ const fontSize = 14;
28358
28355
  function AxisLabels(_ref) {
28359
28356
  let {
28360
28357
  i18n
@@ -28363,24 +28360,26 @@ function AxisLabels(_ref) {
28363
28360
  range,
28364
28361
  labels,
28365
28362
  width,
28366
- height
28363
+ height,
28364
+ labelLocation
28367
28365
  } = useGraphConfig();
28368
28366
  const {
28369
28367
  strings
28370
28368
  } = i18n;
28371
- const yAxisLabelLocation = [0, range[Y][MAX]];
28372
- const xAxisLabelLocation = [range[X][MAX], 0];
28373
- const [xAxisLabelText, yAxisLabelText] = labels;
28374
28369
  const graphInfo = {
28375
28370
  range,
28376
28371
  width,
28377
28372
  height
28378
28373
  };
28379
- const [x1, y1] = pointToPixel(xAxisLabelLocation, graphInfo);
28380
- // The default location for the y-axis-label is at the maximum y point
28381
- // This is just underneath the tick line for that point. The -24 moves the
28382
- // label up one grid square, so it sits on top of the graph
28383
- const [x2, y2] = mafs.vec.add(pointToPixel(yAxisLabelLocation, graphInfo), [0, -24]);
28374
+
28375
+ // Get the position of the main axis labels
28376
+ const [xAxisLabelLocation, yAxisLabelLocation] = getLabelPosition(graphInfo, labelLocation);
28377
+ const [xAxisLabelText, yAxisLabelText] = labels;
28378
+
28379
+ // If the labels are rotated, we need to center the
28380
+ // x-axis label along the bottom of the graph.
28381
+ const xLabelTransform = labelLocation === "onAxis" ? "translate(7px, -50%)" : "translate(-50%, -50%)";
28382
+ const yLabelTransform = labelLocation === "onAxis" ? "translate(-50%, 0px)" : "translate(-50%, 0px) rotate(-90deg)";
28384
28383
  const {
28385
28384
  TeX
28386
28385
  } = getDependencies();
@@ -28388,22 +28387,53 @@ function AxisLabels(_ref) {
28388
28387
  "aria-label": strings.xAxis,
28389
28388
  style: {
28390
28389
  position: "absolute",
28391
- left: x1,
28392
- top: y1,
28393
- fontSize: "14px",
28394
- transform: "translate(7px, -50%)"
28390
+ left: xAxisLabelLocation[X],
28391
+ top: xAxisLabelLocation[Y],
28392
+ fontSize: fontSize + "px",
28393
+ transform: xLabelTransform
28395
28394
  }
28396
28395
  }, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(xAxisLabelText))), /*#__PURE__*/React__default["default"].createElement("span", {
28397
28396
  "aria-label": strings.yAxis,
28398
28397
  style: {
28399
28398
  position: "absolute",
28400
- left: x2,
28401
- top: y2,
28402
- fontSize: "14px",
28403
- transform: "translate(-50%, 0px)"
28399
+ left: yAxisLabelLocation[X],
28400
+ top: yAxisLabelLocation[Y],
28401
+ fontSize: fontSize + "px",
28402
+ transform: yLabelTransform
28404
28403
  }
28405
28404
  }, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(yAxisLabelText))));
28406
28405
  }
28406
+ const getLabelPosition = (graphInfo, labelLocation) => {
28407
+ // If the labels are placed along the edge of the graph, we need to place them at the
28408
+ // center of the graph, which is the average of the min and max values of the axes.
28409
+ if (labelLocation === "alongEdge") {
28410
+ // Offset the labels by a certain amount based on the range of the graph, to ensure that
28411
+ // the labels do not overlap with the axis tick if they are out of the graph bounds.
28412
+ const xAxisLabelOffset = graphInfo.range[Y][MIN] >= 0 ? [0, fontSize * 3] // Move the label down by 3 font sizes if the y-axis min is positive
28413
+ : [0, fontSize]; // Move the label down by 1 font size if the y-axis min is negative
28414
+ const yAxisLabelOffset = graphInfo.range[X][MIN] >= 0 ? [-fontSize * 3, -fontSize] // Move the label left by 3 font sizes if the x-axis min is positive
28415
+ : [-fontSize, -fontSize]; // Move the label left by 1 font size if the x-axis min is negative
28416
+
28417
+ // Calculate the location of the labels to be halfway between the min and max values of the axes
28418
+ const xAxisLabelLocation = [(graphInfo.range[X][MIN] + graphInfo.range[X][MAX]) / 2, graphInfo.range[Y][MIN]];
28419
+ const yAxisLabelLocation = [graphInfo.range[X][MIN], (graphInfo.range[Y][MIN] + graphInfo.range[Y][MAX]) / 2];
28420
+
28421
+ // Convert the Vector2 coordinates to pixel coordinates and add the offsets
28422
+ const xLabel = mafs.vec.add(pointToPixel(xAxisLabelLocation, graphInfo), xAxisLabelOffset);
28423
+ const yLabel = mafs.vec.add(pointToPixel(yAxisLabelLocation, graphInfo), yAxisLabelOffset);
28424
+ return [xLabel, yLabel];
28425
+ }
28426
+
28427
+ // Otherwise, the labels are placed on the axes (default), and we need to
28428
+ // place them at the end of the axis, which is the maximum value of the axis.
28429
+ const xLabelInitial = [graphInfo.range[X][MAX], 0];
28430
+ const yLabelInitial = [0, graphInfo.range[Y][MAX]];
28431
+ const yLabelOffset = [0, -fontSize * 2]; // Move the y-axis label up by 2 font sizes
28432
+
28433
+ const xLabel = pointToPixel(xLabelInitial, graphInfo);
28434
+ const yLabel = mafs.vec.add(pointToPixel(yLabelInitial, graphInfo), yLabelOffset);
28435
+ return [xLabel, yLabel];
28436
+ };
28407
28437
 
28408
28438
  // The size of the ticks and labels in pixels
28409
28439
  const tickSize = 10;
@@ -34744,6 +34774,7 @@ const MafsGraph = props => {
34744
34774
  state,
34745
34775
  dispatch,
34746
34776
  labels,
34777
+ labelLocation,
34747
34778
  readOnly,
34748
34779
  fullGraphAriaLabel,
34749
34780
  fullGraphAriaDescription
@@ -34824,6 +34855,7 @@ const MafsGraph = props => {
34824
34855
  width,
34825
34856
  height,
34826
34857
  labels,
34858
+ labelLocation,
34827
34859
  disableKeyboardInteraction: disableInteraction,
34828
34860
  // If the graph is read-only or static, we want to make it
34829
34861
  // visually clear that the graph is no longer interactive.
@@ -41951,7 +41983,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
41951
41983
 
41952
41984
  // This file is processed by a Rollup plugin (replace) to inject the production
41953
41985
  const libName = "@khanacademy/perseus";
41954
- const libVersion = "56.2.0";
41986
+ const libVersion = "57.0.0";
41955
41987
  addLibraryVersionToPerseusDebug(libName, libVersion);
41956
41988
 
41957
41989
  const apiVersion = {