@khanacademy/perseus 20.4.0 → 20.5.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.js CHANGED
@@ -32,6 +32,7 @@ import caretDown from '@phosphor-icons/core/assets/regular/caret-down.svg';
32
32
  import caretUp from '@phosphor-icons/core/assets/regular/caret-up.svg';
33
33
  import debounce$2 from 'lodash.debounce';
34
34
  import { Point as Point$2, vec, useTransformContext, useMovable, Vector, Coordinates, Mafs } from 'mafs';
35
+ import { color } from '@khanacademy/wonder-blocks-tokens';
35
36
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
36
37
  import questionIcon from '@phosphor-icons/core/regular/question.svg';
37
38
  import { LabelSmall, LabelMedium } from '@khanacademy/wonder-blocks-typography';
@@ -28125,6 +28126,17 @@ Graph.defaultProps = {
28125
28126
  isMobile: false
28126
28127
  };
28127
28128
 
28129
+ /**
28130
+ * Takes a style object with color names and converts them to actual
28131
+ * Wonder Blocks color values. This way, we can use colors and their
28132
+ * names in the editor UI without having to convert them back and forth.
28133
+ */
28134
+ function convertStyle(style) {
28135
+ return _extends({}, style, {
28136
+ stroke: color[(style == null ? void 0 : style.stroke) || "blue"],
28137
+ fill: color[(style == null ? void 0 : style.fill) || "blue"]
28138
+ });
28139
+ }
28128
28140
  const GraphLockedLayer = props => {
28129
28141
  const {
28130
28142
  lockedFigures
@@ -28138,7 +28150,7 @@ const GraphLockedLayer = props => {
28138
28150
  x: x,
28139
28151
  y: y,
28140
28152
  svgCircleProps: {
28141
- style: figure.style
28153
+ style: convertStyle(figure.style)
28142
28154
  }
28143
28155
  });
28144
28156
  }
@@ -28418,7 +28430,8 @@ const LinearGraph = props => {
28418
28430
  };
28419
28431
  const LineView = props => {
28420
28432
  const {
28421
- onMoveLine: onMoveSegment,
28433
+ onMoveLine,
28434
+ onMovePoint,
28422
28435
  collinearPair: [start, end],
28423
28436
  range,
28424
28437
  stroke
@@ -28426,7 +28439,7 @@ const LineView = props => {
28426
28439
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MovableLine, {
28427
28440
  start: start,
28428
28441
  end: end,
28429
- onMove: onMoveSegment,
28442
+ onMove: onMoveLine,
28430
28443
  extend: {
28431
28444
  start: true,
28432
28445
  end: true,
@@ -28436,18 +28449,49 @@ const LineView = props => {
28436
28449
  }), /*#__PURE__*/React.createElement(StyledMovablePoint, {
28437
28450
  point: start,
28438
28451
  onMove: newPoint => {
28439
- props.onMovePoint(0, newPoint);
28452
+ onMovePoint(0, newPoint);
28440
28453
  },
28441
28454
  color: stroke
28442
28455
  }), /*#__PURE__*/React.createElement(StyledMovablePoint, {
28443
28456
  point: end,
28444
28457
  onMove: newPoint => {
28445
- props.onMovePoint(1, newPoint);
28458
+ onMovePoint(1, newPoint);
28446
28459
  },
28447
28460
  color: stroke
28448
28461
  }));
28449
28462
  };
28450
28463
 
28464
+ const RayGraph = props => {
28465
+ const {
28466
+ dispatch
28467
+ } = props;
28468
+ const {
28469
+ coords: lines,
28470
+ range
28471
+ } = props.graphState;
28472
+
28473
+ // a ray only has one line
28474
+ const [start, end] = lines[0];
28475
+ const handleMoveLine = delta => dispatch(moveSegment(0, delta));
28476
+ const handleMovePoint = (newPoint, pointIndex) => dispatch(moveControlPoint(0, pointIndex, newPoint));
28477
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(MovableLine, {
28478
+ start: start,
28479
+ end: end,
28480
+ onMove: handleMoveLine,
28481
+ extend: {
28482
+ end: true,
28483
+ start: false,
28484
+ range
28485
+ }
28486
+ }), /*#__PURE__*/React.createElement(StyledMovablePoint, {
28487
+ point: start,
28488
+ onMove: newPoint => handleMovePoint(newPoint, 0)
28489
+ }), /*#__PURE__*/React.createElement(StyledMovablePoint, {
28490
+ point: end,
28491
+ onMove: newPoint => handleMovePoint(newPoint, 1)
28492
+ }));
28493
+ };
28494
+
28451
28495
  const renderLineLabel = (n, [min, max]) => n !== -1 && n !== min && n !== max;
28452
28496
  const axisOptions = (props, index) => ({
28453
28497
  axis: props.markings === "graph",
@@ -28565,11 +28609,11 @@ function updateAtIndex(args) {
28565
28609
  }
28566
28610
  function setAtIndex(args) {
28567
28611
  const {
28568
- array,
28612
+ array = [],
28569
28613
  index,
28570
28614
  newValue
28571
28615
  } = args;
28572
- const copy = [...(array || [])];
28616
+ const copy = [...array];
28573
28617
  copy[index] = newValue;
28574
28618
  // restoring readonly to array
28575
28619
  return copy;
@@ -28615,16 +28659,16 @@ function initializeGraphState(params) {
28615
28659
  range
28616
28660
  })
28617
28661
  };
28618
- // Ray can also fall through into this case-- same type, same default coords
28619
28662
  case "linear":
28620
28663
  case "linear-system":
28664
+ case "ray":
28621
28665
  return {
28622
28666
  type: graph.type,
28623
28667
  hasBeenInteractedWith: false,
28624
28668
  range,
28625
28669
  snapStep,
28626
- // A linear graph has a single tuple of points, while a linear
28627
- // system has two tuples of points.
28670
+ // Linear and ray graphs have a single tuple of points, while a
28671
+ // linear system has two tuples of points.
28628
28672
  coords: getLineCoords(graph, range, step)
28629
28673
  };
28630
28674
  }
@@ -28669,9 +28713,9 @@ function getGradableGraph(state, initialGraph) {
28669
28713
  return _extends({}, initialGraph, {
28670
28714
  coords: state.coords
28671
28715
  });
28672
- // RAY has the same type as below; can fall through
28673
28716
  // coords: CollinearTuple
28674
28717
  case state.type === "linear" && initialGraph.type === "linear":
28718
+ case state.type === "ray" && initialGraph.type === "ray":
28675
28719
  return _extends({}, initialGraph, {
28676
28720
  coords: (_state$coords = state.coords) == null ? void 0 : _state$coords[0]
28677
28721
  });
@@ -29399,6 +29443,11 @@ const renderGraph = props => {
29399
29443
  graphState: state,
29400
29444
  dispatch: dispatch
29401
29445
  });
29446
+ case "ray":
29447
+ return /*#__PURE__*/React.createElement(RayGraph, {
29448
+ graphState: state,
29449
+ dispatch: dispatch
29450
+ });
29402
29451
  default:
29403
29452
  return new UnreachableCaseError(type);
29404
29453
  }
@@ -41444,7 +41493,7 @@ const init = function init(options) {
41444
41493
 
41445
41494
  // This file is processed by a Rollup plugin (replace) to inject the production
41446
41495
  const libName = "@khanacademy/perseus";
41447
- const libVersion = "20.4.0";
41496
+ const libVersion = "20.5.0";
41448
41497
  addLibraryVersionToPerseusDebug(libName, libVersion);
41449
41498
 
41450
41499
  const apiVersion = {