@khanacademy/perseus 56.1.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/es/index.css +22 -1519
- package/dist/es/index.js +63 -42
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +22 -1519
- package/dist/index.js +63 -42
- package/dist/index.js.map +1 -1
- package/dist/widgets/interactive-graphs/backgrounds/axis-labels.d.ts +5 -0
- package/dist/widgets/interactive-graphs/interactive-graph-question-builder.d.ts +3 -1
- package/dist/widgets/interactive-graphs/mafs-graph.d.ts +1 -0
- package/dist/widgets/interactive-graphs/reducer/use-graph-config.d.ts +2 -1
- package/dist/widgets/interactive-graphs/stateful-mafs-graph.d.ts +1 -0
- package/package.json +7 -7
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(".
|
|
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,
|
|
@@ -18350,17 +18350,6 @@ class WidgetContainer extends React__namespace.Component {
|
|
|
18350
18350
|
widget_id: this.props.id
|
|
18351
18351
|
},
|
|
18352
18352
|
onError: error => {
|
|
18353
|
-
// TODO(LEMS-2826): Remove analytics event in LEMS-2826 in favor of ti below.
|
|
18354
|
-
analytics.onAnalyticsEvent({
|
|
18355
|
-
type: "perseus:widget-rendering-error",
|
|
18356
|
-
payload: {
|
|
18357
|
-
widgetSubType: subType,
|
|
18358
|
-
widgetType: type,
|
|
18359
|
-
widgetId: this.props.id,
|
|
18360
|
-
message: error.message,
|
|
18361
|
-
userAgent: userAgent
|
|
18362
|
-
}
|
|
18363
|
-
});
|
|
18364
18353
|
analytics.onAnalyticsEvent({
|
|
18365
18354
|
type: "perseus:widget-rendering-error:ti",
|
|
18366
18355
|
payload: {
|
|
@@ -19188,14 +19177,7 @@ class Renderer extends React__namespace.Component {
|
|
|
19188
19177
|
}))));
|
|
19189
19178
|
}
|
|
19190
19179
|
if (node.type === "math") {
|
|
19191
|
-
|
|
19192
|
-
// support (yet) with \begin{aligned}...\end{aligned} which renders
|
|
19193
|
-
// the same is supported by KaTeX. It does the same for align*.
|
|
19194
|
-
// TODO(kevinb) update content to use aligned instead of align.
|
|
19195
|
-
// TODO(LEMS-1608) Remove this replacement as MathJax supports the
|
|
19196
|
-
// "align" macro correctly (and, in fact, it is not synonymous with
|
|
19197
|
-
// "aligned").
|
|
19198
|
-
const tex = node.content.replace(/\{align[*]?\}/g, "{aligned}");
|
|
19180
|
+
const tex = node.content;
|
|
19199
19181
|
|
|
19200
19182
|
// We render math here instead of in perseus-markdown.jsx
|
|
19201
19183
|
// because we need to pass it our onRender callback.
|
|
@@ -24430,7 +24412,8 @@ const _choiceTransform = (widgetOptions, strings, problemNum) => {
|
|
|
24430
24412
|
const choices = widgetOptions.choices.map((choice, i) => {
|
|
24431
24413
|
return {
|
|
24432
24414
|
...choice,
|
|
24433
|
-
originalIndex: i
|
|
24415
|
+
originalIndex: i,
|
|
24416
|
+
correct: Boolean(choice.correct)
|
|
24434
24417
|
};
|
|
24435
24418
|
});
|
|
24436
24419
|
|
|
@@ -25431,7 +25414,7 @@ class GradedGroupAnswerBar extends React__namespace.Component {
|
|
|
25431
25414
|
}, nextQuestion));
|
|
25432
25415
|
}
|
|
25433
25416
|
}
|
|
25434
|
-
const fontSize = 17;
|
|
25417
|
+
const fontSize$1 = 17;
|
|
25435
25418
|
const styles$j = {
|
|
25436
25419
|
answerBar: {
|
|
25437
25420
|
display: "flex",
|
|
@@ -25456,7 +25439,7 @@ const styles$j = {
|
|
|
25456
25439
|
flexDirection: "row",
|
|
25457
25440
|
alignItems: "center",
|
|
25458
25441
|
fontWeight: "bold",
|
|
25459
|
-
fontSize: fontSize
|
|
25442
|
+
fontSize: fontSize$1
|
|
25460
25443
|
}
|
|
25461
25444
|
};
|
|
25462
25445
|
|
|
@@ -28143,6 +28126,7 @@ const defaultGraphConfig = {
|
|
|
28143
28126
|
width: 0,
|
|
28144
28127
|
height: 0,
|
|
28145
28128
|
labels: [],
|
|
28129
|
+
labelLocation: "onAxis",
|
|
28146
28130
|
disableKeyboardInteraction: false,
|
|
28147
28131
|
interactiveColor: "var(--mafs-blue)"
|
|
28148
28132
|
};
|
|
@@ -28366,6 +28350,8 @@ function escapeIfUnescaped(character) {
|
|
|
28366
28350
|
}
|
|
28367
28351
|
}
|
|
28368
28352
|
|
|
28353
|
+
// Exported for testing purposes
|
|
28354
|
+
const fontSize = 14;
|
|
28369
28355
|
function AxisLabels(_ref) {
|
|
28370
28356
|
let {
|
|
28371
28357
|
i18n
|
|
@@ -28374,24 +28360,26 @@ function AxisLabels(_ref) {
|
|
|
28374
28360
|
range,
|
|
28375
28361
|
labels,
|
|
28376
28362
|
width,
|
|
28377
|
-
height
|
|
28363
|
+
height,
|
|
28364
|
+
labelLocation
|
|
28378
28365
|
} = useGraphConfig();
|
|
28379
28366
|
const {
|
|
28380
28367
|
strings
|
|
28381
28368
|
} = i18n;
|
|
28382
|
-
const yAxisLabelLocation = [0, range[Y][MAX]];
|
|
28383
|
-
const xAxisLabelLocation = [range[X][MAX], 0];
|
|
28384
|
-
const [xAxisLabelText, yAxisLabelText] = labels;
|
|
28385
28369
|
const graphInfo = {
|
|
28386
28370
|
range,
|
|
28387
28371
|
width,
|
|
28388
28372
|
height
|
|
28389
28373
|
};
|
|
28390
|
-
|
|
28391
|
-
//
|
|
28392
|
-
|
|
28393
|
-
|
|
28394
|
-
|
|
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)";
|
|
28395
28383
|
const {
|
|
28396
28384
|
TeX
|
|
28397
28385
|
} = getDependencies();
|
|
@@ -28399,22 +28387,53 @@ function AxisLabels(_ref) {
|
|
|
28399
28387
|
"aria-label": strings.xAxis,
|
|
28400
28388
|
style: {
|
|
28401
28389
|
position: "absolute",
|
|
28402
|
-
left:
|
|
28403
|
-
top:
|
|
28404
|
-
fontSize: "
|
|
28405
|
-
transform:
|
|
28390
|
+
left: xAxisLabelLocation[X],
|
|
28391
|
+
top: xAxisLabelLocation[Y],
|
|
28392
|
+
fontSize: fontSize + "px",
|
|
28393
|
+
transform: xLabelTransform
|
|
28406
28394
|
}
|
|
28407
28395
|
}, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(xAxisLabelText))), /*#__PURE__*/React__default["default"].createElement("span", {
|
|
28408
28396
|
"aria-label": strings.yAxis,
|
|
28409
28397
|
style: {
|
|
28410
28398
|
position: "absolute",
|
|
28411
|
-
left:
|
|
28412
|
-
top:
|
|
28413
|
-
fontSize: "
|
|
28414
|
-
transform:
|
|
28399
|
+
left: yAxisLabelLocation[X],
|
|
28400
|
+
top: yAxisLabelLocation[Y],
|
|
28401
|
+
fontSize: fontSize + "px",
|
|
28402
|
+
transform: yLabelTransform
|
|
28415
28403
|
}
|
|
28416
28404
|
}, /*#__PURE__*/React__default["default"].createElement(TeX, null, replaceOutsideTeX(yAxisLabelText))));
|
|
28417
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
|
+
};
|
|
28418
28437
|
|
|
28419
28438
|
// The size of the ticks and labels in pixels
|
|
28420
28439
|
const tickSize = 10;
|
|
@@ -30324,7 +30343,7 @@ const PolygonAngle = _ref => {
|
|
|
30324
30343
|
}), /*#__PURE__*/React__namespace.createElement("feComposite", {
|
|
30325
30344
|
operator: "over",
|
|
30326
30345
|
in: "SourceGraphic"
|
|
30327
|
-
}))), !isOutside &&
|
|
30346
|
+
}))), !isOutside && isRightPolygonAngle(angle) ? /*#__PURE__*/React__namespace.createElement(RightAngleSquare, {
|
|
30328
30347
|
start: [x1, y1],
|
|
30329
30348
|
vertex: [x2, y2],
|
|
30330
30349
|
end: [x3, y3]
|
|
@@ -34755,6 +34774,7 @@ const MafsGraph = props => {
|
|
|
34755
34774
|
state,
|
|
34756
34775
|
dispatch,
|
|
34757
34776
|
labels,
|
|
34777
|
+
labelLocation,
|
|
34758
34778
|
readOnly,
|
|
34759
34779
|
fullGraphAriaLabel,
|
|
34760
34780
|
fullGraphAriaDescription
|
|
@@ -34835,6 +34855,7 @@ const MafsGraph = props => {
|
|
|
34835
34855
|
width,
|
|
34836
34856
|
height,
|
|
34837
34857
|
labels,
|
|
34858
|
+
labelLocation,
|
|
34838
34859
|
disableKeyboardInteraction: disableInteraction,
|
|
34839
34860
|
// If the graph is read-only or static, we want to make it
|
|
34840
34861
|
// visually clear that the graph is no longer interactive.
|
|
@@ -41962,7 +41983,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
|
|
|
41962
41983
|
|
|
41963
41984
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
41964
41985
|
const libName = "@khanacademy/perseus";
|
|
41965
|
-
const libVersion = "
|
|
41986
|
+
const libVersion = "57.0.0";
|
|
41966
41987
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
41967
41988
|
|
|
41968
41989
|
const apiVersion = {
|