@khanacademy/perseus 21.2.2 → 21.3.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 +33 -2
- package/dist/es/index.js +75 -52
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +33 -2
- package/dist/index.js +74 -51
- package/dist/index.js.map +1 -1
- package/dist/widgets/interactive-graphs/index.d.ts +1 -1
- package/dist/widgets/interactive-graphs/mafs-graph.d.ts +9 -4
- package/package.json +1 -1
package/dist/index.css
CHANGED
|
@@ -4291,9 +4291,13 @@ html body .mq-editable-field .mq-selection .mq-nthroot-container * {
|
|
|
4291
4291
|
--movable-line-stroke-weight-active: 4px;
|
|
4292
4292
|
}
|
|
4293
4293
|
|
|
4294
|
-
.MafsView
|
|
4294
|
+
.MafsView > svg {
|
|
4295
|
+
/* Chrome/Safari bugfix for LEMS-1906 */
|
|
4296
|
+
display: block;
|
|
4297
|
+
}
|
|
4298
|
+
|
|
4299
|
+
.MafsView .movable-line:hover,
|
|
4295
4300
|
.movable-dragging {
|
|
4296
|
-
outline: none;
|
|
4297
4301
|
--movable-line-stroke-weight: var(--movable-line-stroke-weight-active);
|
|
4298
4302
|
}
|
|
4299
4303
|
|
|
@@ -4302,6 +4306,22 @@ html body .mq-editable-field .mq-selection .mq-nthroot-container * {
|
|
|
4302
4306
|
outline: none;
|
|
4303
4307
|
}
|
|
4304
4308
|
|
|
4309
|
+
.MafsView
|
|
4310
|
+
.movable-line
|
|
4311
|
+
:is(.movable-line-focus-outline, .movable-line-focus-outline-gap) {
|
|
4312
|
+
stroke: transparent;
|
|
4313
|
+
}
|
|
4314
|
+
|
|
4315
|
+
.MafsView .movable-line:focus-visible .movable-line-focus-outline {
|
|
4316
|
+
stroke: var(--mafs-blue);
|
|
4317
|
+
stroke-width: 10px;
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4320
|
+
.MafsView .movable-line:focus-visible .movable-line-focus-outline-gap {
|
|
4321
|
+
stroke: white;
|
|
4322
|
+
stroke-width: 6px;
|
|
4323
|
+
}
|
|
4324
|
+
|
|
4305
4325
|
.MafsView .movable-point-hitbox {
|
|
4306
4326
|
fill: transparent;
|
|
4307
4327
|
}
|
|
@@ -4372,3 +4392,14 @@ html body .mq-editable-field .mq-selection .mq-nthroot-container * {
|
|
|
4372
4392
|
.MafsView .movable-point:focus-visible .movable-point-focus-outline {
|
|
4373
4393
|
visibility: visible;
|
|
4374
4394
|
}
|
|
4395
|
+
|
|
4396
|
+
@font-face {
|
|
4397
|
+
font-family: Mafs-MJXTEX;
|
|
4398
|
+
src: url("https://cdn.kastatic.org/fonts/mathjax/MathJax_Main-Regular.woff")
|
|
4399
|
+
format("woff");
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4402
|
+
.MafsView .axis-ticks text {
|
|
4403
|
+
font-size: 14px;
|
|
4404
|
+
font-family: "Mafs-MJXTEX";
|
|
4405
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -28391,14 +28391,6 @@ function changeRange(range) {
|
|
|
28391
28391
|
};
|
|
28392
28392
|
}
|
|
28393
28393
|
|
|
28394
|
-
const GraphStateContext = /*#__PURE__*/React.createContext({
|
|
28395
|
-
state: {},
|
|
28396
|
-
dispatch: () => {}
|
|
28397
|
-
});
|
|
28398
|
-
function useGraphState() {
|
|
28399
|
-
return React__default["default"].useContext(GraphStateContext);
|
|
28400
|
-
}
|
|
28401
|
-
|
|
28402
28394
|
/**
|
|
28403
28395
|
* 44 is touch best practice and AAA compliant for WCAG
|
|
28404
28396
|
* https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
|
|
@@ -28487,9 +28479,6 @@ const getLines = points => points.map((point, i) => {
|
|
|
28487
28479
|
|
|
28488
28480
|
const defaultStroke = "var(--movable-line-stroke-color)";
|
|
28489
28481
|
const MovableLine = props => {
|
|
28490
|
-
const {
|
|
28491
|
-
state
|
|
28492
|
-
} = useGraphState();
|
|
28493
28482
|
const {
|
|
28494
28483
|
start,
|
|
28495
28484
|
end,
|
|
@@ -28514,12 +28503,13 @@ const MovableLine = props => {
|
|
|
28514
28503
|
onMove: newPoint => {
|
|
28515
28504
|
onMove(mafs.vec.sub(newPoint, midpoint));
|
|
28516
28505
|
},
|
|
28517
|
-
constrain: p =>
|
|
28506
|
+
constrain: p => p
|
|
28518
28507
|
});
|
|
28519
28508
|
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement("g", {
|
|
28520
28509
|
ref: line,
|
|
28521
28510
|
tabIndex: 0,
|
|
28522
28511
|
className: "movable-line",
|
|
28512
|
+
"data-test-id": "movable-line",
|
|
28523
28513
|
style: {
|
|
28524
28514
|
cursor: dragging ? "grabbing" : "grab"
|
|
28525
28515
|
}
|
|
@@ -28530,6 +28520,16 @@ const MovableLine = props => {
|
|
|
28530
28520
|
stroke: "transparent",
|
|
28531
28521
|
strokeWidth: TARGET_SIZE
|
|
28532
28522
|
}
|
|
28523
|
+
}), /*#__PURE__*/React__namespace.createElement(SVGLine, {
|
|
28524
|
+
start: startPtPx,
|
|
28525
|
+
end: endPtPx,
|
|
28526
|
+
className: "movable-line-focus-outline",
|
|
28527
|
+
style: {}
|
|
28528
|
+
}), /*#__PURE__*/React__namespace.createElement(SVGLine, {
|
|
28529
|
+
start: startPtPx,
|
|
28530
|
+
end: endPtPx,
|
|
28531
|
+
className: "movable-line-focus-outline-gap",
|
|
28532
|
+
style: {}
|
|
28533
28533
|
}), /*#__PURE__*/React__namespace.createElement(SVGLine, {
|
|
28534
28534
|
start: startPtPx,
|
|
28535
28535
|
end: endPtPx,
|
|
@@ -28537,7 +28537,8 @@ const MovableLine = props => {
|
|
|
28537
28537
|
stroke,
|
|
28538
28538
|
strokeWidth: "var(--movable-line-stroke-weight)"
|
|
28539
28539
|
},
|
|
28540
|
-
dragging: dragging
|
|
28540
|
+
dragging: dragging,
|
|
28541
|
+
testId: "movable-line__line"
|
|
28541
28542
|
})), startExtend && /*#__PURE__*/React__namespace.createElement(mafs.Vector, {
|
|
28542
28543
|
tail: start,
|
|
28543
28544
|
tip: startExtend,
|
|
@@ -28553,18 +28554,30 @@ function SVGLine(props) {
|
|
|
28553
28554
|
start,
|
|
28554
28555
|
end,
|
|
28555
28556
|
style,
|
|
28556
|
-
dragging
|
|
28557
|
+
dragging,
|
|
28558
|
+
className,
|
|
28559
|
+
testId
|
|
28557
28560
|
} = props;
|
|
28561
|
+
const draggingClass = dragging ? "movable-dragging" : "";
|
|
28558
28562
|
return /*#__PURE__*/React__namespace.createElement("line", {
|
|
28559
28563
|
x1: start[0],
|
|
28560
28564
|
y1: start[1],
|
|
28561
28565
|
x2: end[0],
|
|
28562
28566
|
y2: end[1],
|
|
28563
28567
|
style: style,
|
|
28564
|
-
className:
|
|
28568
|
+
className: `${className} ${draggingClass}`,
|
|
28569
|
+
"data-test-id": testId
|
|
28565
28570
|
});
|
|
28566
28571
|
}
|
|
28567
28572
|
|
|
28573
|
+
const GraphStateContext = /*#__PURE__*/React.createContext({
|
|
28574
|
+
state: {},
|
|
28575
|
+
dispatch: () => {}
|
|
28576
|
+
});
|
|
28577
|
+
function useGraphState() {
|
|
28578
|
+
return React__default["default"].useContext(GraphStateContext);
|
|
28579
|
+
}
|
|
28580
|
+
|
|
28568
28581
|
// The hitbox size of 48px by 48px is preserved from the legacy interactive
|
|
28569
28582
|
// graph.
|
|
28570
28583
|
const hitboxSizePx = 48;
|
|
@@ -28596,7 +28609,8 @@ const StyledMovablePoint = props => {
|
|
|
28596
28609
|
touchAction: "none",
|
|
28597
28610
|
outline: "none",
|
|
28598
28611
|
"--movable-point-color": color
|
|
28599
|
-
}
|
|
28612
|
+
},
|
|
28613
|
+
"data-test-id": "movable-point"
|
|
28600
28614
|
}, /*#__PURE__*/React__namespace.createElement("circle", {
|
|
28601
28615
|
className: "movable-point-hitbox",
|
|
28602
28616
|
r: hitboxSizePx / 2,
|
|
@@ -28620,7 +28634,8 @@ const StyledMovablePoint = props => {
|
|
|
28620
28634
|
cy: y,
|
|
28621
28635
|
style: {
|
|
28622
28636
|
fill: color
|
|
28623
|
-
}
|
|
28637
|
+
},
|
|
28638
|
+
"data-test-id": "movable-point__center"
|
|
28624
28639
|
}));
|
|
28625
28640
|
};
|
|
28626
28641
|
|
|
@@ -29086,7 +29101,13 @@ const YGridTick = _ref => {
|
|
|
29086
29101
|
x2: xPosition + tickSize / 2,
|
|
29087
29102
|
y2: yPosition,
|
|
29088
29103
|
style: tickStyle
|
|
29089
|
-
})
|
|
29104
|
+
}), y !== -1 && /*#__PURE__*/React__namespace.createElement("text", {
|
|
29105
|
+
height: 20,
|
|
29106
|
+
width: 50,
|
|
29107
|
+
textAnchor: "end",
|
|
29108
|
+
x: xPosition - 10,
|
|
29109
|
+
y: yPosition + 5
|
|
29110
|
+
}, y.toString()));
|
|
29090
29111
|
};
|
|
29091
29112
|
const XGridTick = _ref2 => {
|
|
29092
29113
|
let {
|
|
@@ -29102,13 +29123,23 @@ const XGridTick = _ref2 => {
|
|
|
29102
29123
|
x2: xPosition,
|
|
29103
29124
|
y2: yPosition - tickSize / 2,
|
|
29104
29125
|
style: tickStyle
|
|
29105
|
-
})
|
|
29126
|
+
}), x !== -1 && /*#__PURE__*/React__namespace.createElement("text", {
|
|
29127
|
+
height: 20,
|
|
29128
|
+
width: 50,
|
|
29129
|
+
textAnchor: "middle",
|
|
29130
|
+
x: xPosition,
|
|
29131
|
+
y: yPosition + 25
|
|
29132
|
+
}, x.toString()));
|
|
29106
29133
|
};
|
|
29107
29134
|
function generateTickLocations(tickStep, min, max) {
|
|
29108
29135
|
const ticks = [];
|
|
29136
|
+
|
|
29137
|
+
// Add ticks in the positive direction
|
|
29109
29138
|
for (let i = 0 + tickStep; i < max; i += tickStep) {
|
|
29110
29139
|
ticks.push(i);
|
|
29111
29140
|
}
|
|
29141
|
+
|
|
29142
|
+
// Add ticks in the negative direction
|
|
29112
29143
|
for (let i = 0 - tickStep; i > min; i -= tickStep) {
|
|
29113
29144
|
ticks.push(i);
|
|
29114
29145
|
}
|
|
@@ -29137,24 +29168,6 @@ const AxisTicks = props => {
|
|
|
29137
29168
|
}));
|
|
29138
29169
|
};
|
|
29139
29170
|
|
|
29140
|
-
/**
|
|
29141
|
-
* lineLabelText get the text that should
|
|
29142
|
-
* be displayed for a specific tick place
|
|
29143
|
-
*
|
|
29144
|
-
* @param {number} n the tick number
|
|
29145
|
-
* @param {number} tickStep how frequently a label should appear
|
|
29146
|
-
* @param {vec.Vector2} range the min/max range on the axis
|
|
29147
|
-
*/
|
|
29148
|
-
const lineLabelText = (n, tickStep, range) => {
|
|
29149
|
-
const [min, max] = range;
|
|
29150
|
-
const isOnStep = n % tickStep === 0;
|
|
29151
|
-
const isNegativeOne = n === -1;
|
|
29152
|
-
const isMin = n === min;
|
|
29153
|
-
const isMax = n === max;
|
|
29154
|
-
const shouldRender = isOnStep && !isNegativeOne && !isMin && !isMax;
|
|
29155
|
-
return shouldRender ? `${n}` : "";
|
|
29156
|
-
};
|
|
29157
|
-
|
|
29158
29171
|
/**
|
|
29159
29172
|
* axisOptions determine axis options for Mafs
|
|
29160
29173
|
*
|
|
@@ -29166,12 +29179,10 @@ const lineLabelText = (n, tickStep, range) => {
|
|
|
29166
29179
|
* @param {number} axisIndex which axis we're getting options for
|
|
29167
29180
|
*/
|
|
29168
29181
|
const axisOptions = (props, axisIndex) => {
|
|
29169
|
-
const axisStep = props.tickStep[axisIndex];
|
|
29170
|
-
const axisRange = props.range[axisIndex];
|
|
29171
29182
|
return {
|
|
29172
29183
|
axis: props.markings === "graph",
|
|
29173
29184
|
lines: props.gridStep[axisIndex],
|
|
29174
|
-
labels:
|
|
29185
|
+
labels: false
|
|
29175
29186
|
};
|
|
29176
29187
|
};
|
|
29177
29188
|
const Grid = props => {
|
|
@@ -30418,9 +30429,22 @@ const renderGraph = props => {
|
|
|
30418
30429
|
return new wonderStuffCore.UnreachableCaseError(type);
|
|
30419
30430
|
}
|
|
30420
30431
|
};
|
|
30421
|
-
const
|
|
30422
|
-
const [width, height] = props.box;
|
|
30432
|
+
const StatefulMafsGraph = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
30423
30433
|
const [state, dispatch] = React__namespace.useReducer(interactiveGraphReducer, props, initializeGraphState);
|
|
30434
|
+
React.useImperativeHandle(ref, () => ({
|
|
30435
|
+
getUserInput: () => getGradableGraph(state, props.graph)
|
|
30436
|
+
}));
|
|
30437
|
+
return /*#__PURE__*/React__namespace.createElement(MafsGraph, _extends({
|
|
30438
|
+
state: state,
|
|
30439
|
+
dispatch: dispatch
|
|
30440
|
+
}, props));
|
|
30441
|
+
});
|
|
30442
|
+
const MafsGraph = props => {
|
|
30443
|
+
const {
|
|
30444
|
+
state,
|
|
30445
|
+
dispatch
|
|
30446
|
+
} = props;
|
|
30447
|
+
const [width, height] = props.box;
|
|
30424
30448
|
const prevState = React.useRef(state);
|
|
30425
30449
|
React.useEffect(() => {
|
|
30426
30450
|
if (prevState.current !== state) {
|
|
@@ -30435,16 +30459,13 @@ const MafsGraph = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
|
30435
30459
|
const [xSnap, ySnap] = props.snapStep;
|
|
30436
30460
|
React.useEffect(() => {
|
|
30437
30461
|
dispatch(changeSnapStep([xSnap, ySnap]));
|
|
30438
|
-
}, [xSnap, ySnap]);
|
|
30462
|
+
}, [dispatch, xSnap, ySnap]);
|
|
30439
30463
|
|
|
30440
30464
|
// Destructuring first to keep useEffect from making excess calls
|
|
30441
30465
|
const [[xMinRange, xMaxRange], [yMinRange, yMaxRange]] = props.range;
|
|
30442
30466
|
React.useEffect(() => {
|
|
30443
30467
|
dispatch(changeRange([[xMinRange, xMaxRange], [yMinRange, yMaxRange]]));
|
|
30444
|
-
}, [xMinRange, xMaxRange, yMinRange, yMaxRange]);
|
|
30445
|
-
React__namespace.useImperativeHandle(ref, () => ({
|
|
30446
|
-
getUserInput: () => getGradableGraph(state, props.graph)
|
|
30447
|
-
}));
|
|
30468
|
+
}, [dispatch, xMinRange, xMaxRange, yMinRange, yMaxRange]);
|
|
30448
30469
|
return /*#__PURE__*/React__namespace.createElement(GraphStateContext.Provider, {
|
|
30449
30470
|
value: {
|
|
30450
30471
|
state,
|
|
@@ -30454,7 +30475,9 @@ const MafsGraph = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
|
30454
30475
|
style: {
|
|
30455
30476
|
width,
|
|
30456
30477
|
height,
|
|
30457
|
-
position: "relative"
|
|
30478
|
+
position: "relative",
|
|
30479
|
+
padding: "25px 25px 0 0",
|
|
30480
|
+
boxSizing: "content-box"
|
|
30458
30481
|
}
|
|
30459
30482
|
}, /*#__PURE__*/React__namespace.createElement(LegacyGrid, {
|
|
30460
30483
|
box: props.box,
|
|
@@ -30488,7 +30511,7 @@ const MafsGraph = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
|
|
30488
30511
|
state,
|
|
30489
30512
|
dispatch
|
|
30490
30513
|
})))));
|
|
30491
|
-
}
|
|
30514
|
+
};
|
|
30492
30515
|
|
|
30493
30516
|
const {
|
|
30494
30517
|
DeprecationMixin
|
|
@@ -31764,7 +31787,7 @@ class InteractiveGraph extends React__namespace.Component {
|
|
|
31764
31787
|
const box = getInteractiveBoxFromSizeClass(this.props.containerSizeClass);
|
|
31765
31788
|
const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, box[0]);
|
|
31766
31789
|
const snapStep = this.props.snapStep || Util.snapStepFromGridStep(gridStep);
|
|
31767
|
-
return /*#__PURE__*/React__namespace.createElement(
|
|
31790
|
+
return /*#__PURE__*/React__namespace.createElement(StatefulMafsGraph, _extends({}, this.props, {
|
|
31768
31791
|
ref: this.mafsRef,
|
|
31769
31792
|
gridStep: gridStep,
|
|
31770
31793
|
snapStep: snapStep,
|
|
@@ -42495,7 +42518,7 @@ const init = function (options) {
|
|
|
42495
42518
|
|
|
42496
42519
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
42497
42520
|
const libName = "@khanacademy/perseus";
|
|
42498
|
-
const libVersion = "21.
|
|
42521
|
+
const libVersion = "21.3.0";
|
|
42499
42522
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
42500
42523
|
|
|
42501
42524
|
const apiVersion = {
|