@khanacademy/perseus 21.5.0 → 21.6.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 CHANGED
@@ -3518,6 +3518,9 @@ body.mobile .framework-perseus table.perseus-widget-table-of-values.non-markdown
3518
3518
  font-size: 18px;
3519
3519
  }
3520
3520
  }
3521
+ .perseus-widget-editor-content .locked-figure-accordion h2 {
3522
+ padding-top: 0;
3523
+ }
3521
3524
  .keypad-input {
3522
3525
  outline: none !important;
3523
3526
  }
package/dist/es/index.js CHANGED
@@ -30,7 +30,7 @@ import { OptionItem, SingleSelect, MultiSelect } from '@khanacademy/wonder-block
30
30
  import caretDown from '@phosphor-icons/core/assets/regular/caret-down.svg';
31
31
  import caretUp from '@phosphor-icons/core/assets/regular/caret-up.svg';
32
32
  import debounce$2 from 'lodash.debounce';
33
- import { Point as Point$2, useTransformContext, vec, useMovable, Text as Text$1, Polygon, Coordinates, Mafs } from 'mafs';
33
+ import { Line as Line$3, Point as Point$2, useTransformContext, vec, useMovable, Text as Text$1, Polygon, Coordinates, Mafs } from 'mafs';
34
34
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
35
35
  import questionIcon from '@phosphor-icons/core/regular/question.svg';
36
36
  import { LabelSmall, LabelMedium } from '@khanacademy/wonder-blocks-typography';
@@ -45,14 +45,12 @@ function _extends() {
45
45
  _extends = Object.assign ? Object.assign.bind() : function (target) {
46
46
  for (var i = 1; i < arguments.length; i++) {
47
47
  var source = arguments[i];
48
-
49
48
  for (var key in source) {
50
49
  if (Object.prototype.hasOwnProperty.call(source, key)) {
51
50
  target[key] = source[key];
52
51
  }
53
52
  }
54
53
  }
55
-
56
54
  return target;
57
55
  };
58
56
  return _extends.apply(this, arguments);
@@ -63,13 +61,11 @@ function _objectWithoutPropertiesLoose(source, excluded) {
63
61
  var target = {};
64
62
  var sourceKeys = Object.keys(source);
65
63
  var key, i;
66
-
67
64
  for (i = 0; i < sourceKeys.length; i++) {
68
65
  key = sourceKeys[i];
69
66
  if (excluded.indexOf(key) >= 0) continue;
70
67
  target[key] = source[key];
71
68
  }
72
-
73
69
  return target;
74
70
  }
75
71
 
@@ -4255,7 +4251,6 @@ function _classPrivateFieldBase(receiver, privateKey) {
4255
4251
  if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
4256
4252
  throw new TypeError("attempted to use private field on non-instance");
4257
4253
  }
4258
-
4259
4254
  return receiver;
4260
4255
  }
4261
4256
 
@@ -22758,7 +22753,7 @@ const FocusRing = function FocusRing(props) {
22758
22753
  borderRadius
22759
22754
  };
22760
22755
  return /*#__PURE__*/React.createElement("span", {
22761
- "data-test-id": "focus-ring",
22756
+ "data-testid": "focus-ring",
22762
22757
  className: css(styles$z.ring),
22763
22758
  style: style
22764
22759
  }, children);
@@ -22829,7 +22824,7 @@ const CrossOutLine = function CrossOutLine(props) {
22829
22824
  height: CROSS_OUT_LINE_SIZE,
22830
22825
  viewBox: `0 0 ${CROSS_OUT_LINE_SIZE} ${CROSS_OUT_LINE_SIZE}`,
22831
22826
  className: css(styles$x.crossOutLine),
22832
- "data-test-id": "choice-icon__cross-out-line"
22827
+ "data-testid": "choice-icon__cross-out-line"
22833
22828
  }, /*#__PURE__*/React.createElement("line", {
22834
22829
  // The line stretches from the bottom-left to top-right.
22835
22830
  // We don't quite go to the _very_ corner, because the cute
@@ -22932,7 +22927,7 @@ const ChoiceIcon = function ChoiceIcon(props) {
22932
22927
  }, /*#__PURE__*/React.createElement("div", {
22933
22928
  // @ts-expect-error - TS2322 - Type '{ backgroundColor: string | null | undefined; borderColor: string; color: string; borderRadius: number; }' is not assignable to type 'Properties<string | number, string & {}>'.
22934
22929
  style: dynamicStyles,
22935
- "data-test-id": "choice-icon__library-choice-icon",
22930
+ "data-testid": "choice-icon__library-choice-icon",
22936
22931
  className: css(styles$w.circle, showCorrectness && correct && styles$w.circleCorrect, showCorrectness && !correct && styles$w.circleIncorrect, showCorrectness && !correct && (checked || previouslyAnswered) && styles$w.circleIncorrectAnswered)
22937
22932
  // used in BaseRadio editMode to check
22938
22933
  // if we actually clicked on the radio icon
@@ -23282,7 +23277,7 @@ const Choice = function Choice(props) {
23282
23277
  color: color.offBlack64
23283
23278
  })))), showRationale && /*#__PURE__*/React.createElement("div", {
23284
23279
  className: rationaleClassName,
23285
- "data-test-id": `perseus-radio-rationale-content-${pos}`
23280
+ "data-testid": `perseus-radio-rationale-content-${pos}`
23286
23281
  }, rationale));
23287
23282
  };
23288
23283
  const styles$u = StyleSheet.create({
@@ -28168,43 +28163,99 @@ Graph.defaultProps = {
28168
28163
  isMobile: false
28169
28164
  };
28170
28165
 
28171
- /**
28172
- * Takes a style object with color names and converts them to actual
28173
- * Wonder Blocks color values. This way, we can use colors and their
28174
- * names in the editor UI without having to convert them back and forth.
28175
- */
28176
- function convertStyle(style) {
28177
- return _extends({}, style, {
28178
- stroke: color[(style == null ? void 0 : style.stroke) || "blue"],
28179
- fill: color[(style == null ? void 0 : style.fill) || "blue"]
28166
+ const LockedLine = props => {
28167
+ const {
28168
+ color: color$1,
28169
+ lineStyle,
28170
+ kind,
28171
+ points,
28172
+ showStartPoint,
28173
+ showEndPoint
28174
+ } = props;
28175
+ const [point1, point2] = points;
28176
+ let line;
28177
+ if (kind === "line" || kind === "segment") {
28178
+ const LineType = kind === "segment" ? Line$3.Segment : Line$3.ThroughPoints;
28179
+ line = /*#__PURE__*/React.createElement(LineType, {
28180
+ point1: point1.coord,
28181
+ point2: point2.coord,
28182
+ color: color[color$1],
28183
+ style: lineStyle
28184
+ });
28185
+ } else {
28186
+ // TODO(LEMS-1928): Implement rays
28187
+ return null;
28188
+ }
28189
+ return /*#__PURE__*/React.createElement("g", {
28190
+ className: "locked-line"
28191
+ }, line, showStartPoint && /*#__PURE__*/React.createElement(Point$2, {
28192
+ x: point1.coord[0],
28193
+ y: point1.coord[1],
28194
+ svgCircleProps: {
28195
+ style: {
28196
+ fill: point1.filled ? color[point1.color] : color.white,
28197
+ stroke: color[point1.color],
28198
+ strokeWidth: spacing.xxxxSmall_2
28199
+ }
28200
+ }
28201
+ }), showEndPoint && /*#__PURE__*/React.createElement(Point$2, {
28202
+ x: point2.coord[0],
28203
+ y: point2.coord[1],
28204
+ svgCircleProps: {
28205
+ style: {
28206
+ fill: point2.filled ? color[point2.color] : color.white,
28207
+ stroke: color[point2.color],
28208
+ strokeWidth: spacing.xxxxSmall_2
28209
+ }
28210
+ }
28211
+ }));
28212
+ };
28213
+
28214
+ const LockedPoint = props => {
28215
+ const {
28216
+ color: color$1,
28217
+ coord,
28218
+ filled
28219
+ } = props;
28220
+ const [x, y] = coord;
28221
+ return /*#__PURE__*/React.createElement(Point$2, {
28222
+ x: x,
28223
+ y: y,
28224
+ svgCircleProps: {
28225
+ style: {
28226
+ fill: filled ? color[color$1] : color.white,
28227
+ stroke: color[color$1],
28228
+ strokeWidth: spacing.xxxxSmall_2
28229
+ }
28230
+ }
28180
28231
  });
28181
- }
28232
+ };
28233
+
28182
28234
  const GraphLockedLayer = props => {
28183
28235
  const {
28184
28236
  lockedFigures
28185
28237
  } = props;
28186
28238
  return /*#__PURE__*/React.createElement(React.Fragment, null, lockedFigures.map((figure, index) => {
28239
+ let Figure;
28187
28240
  switch (figure.type) {
28188
28241
  case "point":
28189
- const [x, y] = figure.coord;
28190
- return /*#__PURE__*/React.createElement(Point$2, {
28191
- key: `${figure.type}-${index}`,
28192
- x: x,
28193
- y: y,
28194
- svgCircleProps: {
28195
- style: convertStyle(figure.style)
28196
- }
28197
- });
28242
+ Figure = LockedPoint;
28243
+ break;
28244
+ case "line":
28245
+ Figure = LockedLine;
28246
+ break;
28247
+ default:
28248
+ /**
28249
+ * Devlopment-time future-proofing: This should
28250
+ * fail during type-checking if we add a new locked
28251
+ * shape type and forget to handle it in any other
28252
+ * switch case here.
28253
+ */
28254
+ throw new UnreachableCaseError(figure);
28198
28255
  }
28199
-
28200
- /**
28201
- * Devlopment-time future-proofing: This `never` should
28202
- * fail during type-checking if we add a new locked
28203
- * shape type and forget to handle it in any other
28204
- * switch case here.
28205
- */
28206
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
28207
- throw new UnreachableCaseError(figure.type);
28256
+ return /*#__PURE__*/React.createElement(Figure, _extends({
28257
+ key: `${figure.type}-${index}`
28258
+ }, figure));
28208
28259
  }));
28209
28260
  };
28210
28261
 
@@ -28353,7 +28404,7 @@ function SVGLine(props) {
28353
28404
  y2: end[1],
28354
28405
  style: style,
28355
28406
  className: `${className}`,
28356
- "data-test-id": testId
28407
+ "data-testid": testId
28357
28408
  });
28358
28409
  }
28359
28410
 
@@ -28482,7 +28533,7 @@ const MovableLine = props => {
28482
28533
  ref: line,
28483
28534
  tabIndex: 0,
28484
28535
  className: "movable-line",
28485
- "data-test-id": "movable-line",
28536
+ "data-testid": "movable-line",
28486
28537
  style: {
28487
28538
  cursor: dragging ? "grabbing" : "grab"
28488
28539
  }
@@ -28584,7 +28635,7 @@ const StyledMovablePoint = props => {
28584
28635
  style: {
28585
28636
  "--movable-point-color": color$1
28586
28637
  },
28587
- "data-test-id": "movable-point"
28638
+ "data-testid": "movable-point"
28588
28639
  }, /*#__PURE__*/React.createElement("circle", {
28589
28640
  className: "movable-point-hitbox",
28590
28641
  r: hitboxSizePx / 2,
@@ -28609,7 +28660,7 @@ const StyledMovablePoint = props => {
28609
28660
  style: {
28610
28661
  fill: color$1
28611
28662
  },
28612
- "data-test-id": "movable-point__center"
28663
+ "data-testid": "movable-point__center"
28613
28664
  })));
28614
28665
  };
28615
28666
 
@@ -28628,8 +28679,7 @@ const SegmentGraph = props => {
28628
28679
  },
28629
28680
  onMovePoint: (endpointIndex, destination) => {
28630
28681
  dispatch(moveControlPoint(endpointIndex, destination, i));
28631
- },
28632
- "data-testid": "segment" + i
28682
+ }
28633
28683
  })));
28634
28684
  };
28635
28685
  const SegmentView = props => {
@@ -28659,8 +28709,7 @@ const LinearGraph = props => {
28659
28709
  dispatch
28660
28710
  } = props;
28661
28711
  const {
28662
- coords: lines,
28663
- type
28712
+ coords: lines
28664
28713
  } = props.graphState;
28665
28714
  const colors = ["var(--movable-line-stroke-color)", "var(--mafs-violet)"];
28666
28715
  return /*#__PURE__*/React.createElement(React.Fragment, null, lines == null ? void 0 : lines.map((line, i) => /*#__PURE__*/React.createElement(LineView, {
@@ -28669,10 +28718,7 @@ const LinearGraph = props => {
28669
28718
  onMoveLine: delta => {
28670
28719
  dispatch(moveLine(i, delta));
28671
28720
  },
28672
- onMovePoint: (endpointIndex, destination) => dispatch(moveControlPoint(endpointIndex, destination, i))
28673
- // "linear" or "linear-system" + index
28674
- ,
28675
- "data-testid": type + i,
28721
+ onMovePoint: (endpointIndex, destination) => dispatch(moveControlPoint(endpointIndex, destination, i)),
28676
28722
  stroke: colors[i]
28677
28723
  })));
28678
28724
  };
@@ -28912,7 +28958,6 @@ const PolygonGraph = props => {
28912
28958
  } = props;
28913
28959
  const {
28914
28960
  coords,
28915
- type,
28916
28961
  showAngles,
28917
28962
  showSides,
28918
28963
  range,
@@ -28983,8 +29028,7 @@ const PolygonGraph = props => {
28983
29028
  }), points.map((point, i) => /*#__PURE__*/React.createElement(StyledMovablePoint, {
28984
29029
  key: "point-" + i,
28985
29030
  point: point,
28986
- onMove: destination => dispatch(movePoint(i, destination)),
28987
- "data-testid": type + i
29031
+ onMove: destination => dispatch(movePoint(i, destination))
28988
29032
  })));
28989
29033
  };
28990
29034
 
@@ -42489,7 +42533,7 @@ const init = function init(options) {
42489
42533
 
42490
42534
  // This file is processed by a Rollup plugin (replace) to inject the production
42491
42535
  const libName = "@khanacademy/perseus";
42492
- const libVersion = "21.5.0";
42536
+ const libVersion = "21.6.0";
42493
42537
  addLibraryVersionToPerseusDebug(libName, libVersion);
42494
42538
 
42495
42539
  const apiVersion = {
@@ -43617,6 +43661,7 @@ const PerseusExpressionAnswerFormConsidered = ["correct", "wrong", "ungraded"];
43617
43661
 
43618
43662
  // 2D range: xMin, xMax, yMin, yMax
43619
43663
 
43664
+ const lockedFigureColors = ["purple", "blue", "teal", "green", "gold", "red", "pink"];
43620
43665
  const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
43621
43666
 
43622
43667
  /**
@@ -45587,5 +45632,5 @@ const EditorJsonify = {
45587
45632
  }
45588
45633
  };
45589
45634
 
45590
- export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, QUESTION_WIDGETS, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, addWidget, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, contentHasWidgetType, convertWidgetNameToEnum, displaySigFigs, generateTestCategorizerWidget, generateTestExpressionWidget, generateTestInteractiveGraphWidget, generateTestNumericInputWidget, generateTestPerseusItem, generateTestRadioWidget, genericPerseusItemData, getAnswerFromUserInput, getAnswersFromWidgets, getCorrectAnswerForWidgetId, getValidWidgetIds, getWidgetFromWidgetMap, getWidgetIdsFromContent, getWidgetIdsFromContentByType, getWidgetTypeByWidgetId, getWidgetsFromWidgetMap, getWidgetsMapFromItemData, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, isWidgetIdInContent, isWrongAnswerSupported, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, shouldHaveIndividualAnswer, traverse, violatingWidgets, allWidgets as widgets };
45635
+ export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, QUESTION_WIDGETS, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, addWidget, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, contentHasWidgetType, convertWidgetNameToEnum, displaySigFigs, generateTestCategorizerWidget, generateTestExpressionWidget, generateTestInteractiveGraphWidget, generateTestNumericInputWidget, generateTestPerseusItem, generateTestRadioWidget, genericPerseusItemData, getAnswerFromUserInput, getAnswersFromWidgets, getCorrectAnswerForWidgetId, getValidWidgetIds, getWidgetFromWidgetMap, getWidgetIdsFromContent, getWidgetIdsFromContentByType, getWidgetTypeByWidgetId, getWidgetsFromWidgetMap, getWidgetsMapFromItemData, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, isWidgetIdInContent, isWrongAnswerSupported, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, lockedFigureColors, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, shouldHaveIndividualAnswer, traverse, violatingWidgets, allWidgets as widgets };
45591
45636
  //# sourceMappingURL=index.js.map