@khanacademy/perseus 19.1.1 → 19.1.2

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
@@ -9647,15 +9647,6 @@ const GraphUtils = {
9647
9647
  getDistance: function (point1, point2) {
9648
9648
  return kmath.point.distanceToPoint(point1, point2);
9649
9649
  },
9650
- /**
9651
- * Round the given coordinates to a given snap value
9652
- * (e.g., nearest 0.2 increment)
9653
- */
9654
- snapCoord: function (coord, snap) {
9655
- return coord.map(function (val, i) {
9656
- return KhanMath.roundToNearest(snap[i], val);
9657
- });
9658
- },
9659
9650
  // Find the angle in degrees between two or three points
9660
9651
  findAngle: function (point1, point2, vertex) {
9661
9652
  if (vertex === undefined) {
@@ -16175,6 +16166,9 @@ const {
16175
16166
  } = InteractiveUtil;
16176
16167
  class Graphie extends React__namespace.Component {
16177
16168
  graphieDivRef = /*#__PURE__*/React__namespace.createRef();
16169
+ _graphie = new Graphie$1(document.createElement("div"));
16170
+ _movables = {};
16171
+ movables = {};
16178
16172
  static defaultProps = {
16179
16173
  range: [[-10, 10], [-10, 10]],
16180
16174
  options: {},
@@ -16217,7 +16211,6 @@ class Graphie extends React__namespace.Component {
16217
16211
  * Use it for good and not evil.
16218
16212
  */
16219
16213
  getGraphie = () => {
16220
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16221
16214
  return this._graphie;
16222
16215
  };
16223
16216
 
@@ -16239,10 +16232,12 @@ class Graphie extends React__namespace.Component {
16239
16232
  };
16240
16233
  return [ensureMinSize(this.props.box[0]), ensureMinSize(this.props.box[1])];
16241
16234
  };
16235
+
16236
+ // @ts-expect-error - TS2322: Type '() => number[]' is not assignable to type '() => Coord'.
16242
16237
  _scale = () => {
16243
16238
  const box = this._box();
16244
16239
  const range = this._range();
16245
- return ___default["default"].map(box, (pixelDim, i) => {
16240
+ return box.map((pixelDim, i) => {
16246
16241
  const unitDim = range[i][1] - range[i][0];
16247
16242
  return pixelDim / unitDim;
16248
16243
  });
@@ -16250,9 +16245,10 @@ class Graphie extends React__namespace.Component {
16250
16245
  _setupGraphie = () => {
16251
16246
  this._removeMovables();
16252
16247
  const graphieDiv = ReactDOM__default["default"].findDOMNode(this.graphieDivRef.current);
16253
- // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
16254
- $__default["default"](graphieDiv).empty();
16255
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16248
+ if (graphieDiv == null || graphieDiv instanceof Text) {
16249
+ throw new Error("No graphie container div found");
16250
+ }
16251
+ graphieDiv.innerHTML = "";
16256
16252
  const graphie = this._graphie = createGraphie(graphieDiv);
16257
16253
 
16258
16254
  // This has to be called before addMouseLayer. You can re-init
@@ -16264,6 +16260,7 @@ class Graphie extends React__namespace.Component {
16264
16260
  });
16265
16261
  // Only add the mouselayer if we actually want one.
16266
16262
  if (this.props.addMouseLayer) {
16263
+ // @ts-expect-error - TS2339: Property 'addMouseLayer' does not exist on type 'Graphie'.
16267
16264
  graphie.addMouseLayer({
16268
16265
  onClick: this.props.onClick,
16269
16266
  onMouseDown: this.props.onMouseDown,
@@ -16272,12 +16269,13 @@ class Graphie extends React__namespace.Component {
16272
16269
  setDrawingAreaAvailable: this.props.setDrawingAreaAvailable
16273
16270
  });
16274
16271
  }
16272
+
16273
+ // @ts-expect-error - TS2339: Property 'snap' does not exist on type 'Graphie'.
16275
16274
  graphie.snap = this.props.options.snapStep || [1, 1];
16276
16275
  if (this.props.responsive) {
16277
16276
  // Overwrite fixed styles set in init()
16278
16277
  // TODO(alex): Either make this component always responsive by
16279
16278
  // itself, or always wrap it in other components so that it is.
16280
- // @ts-expect-error - TS2769 - No overload matches this call. | TS2554 - Expected 2 arguments, but got 1.
16281
16279
  $__default["default"](graphieDiv).css({
16282
16280
  width: "100%",
16283
16281
  height: "100%"
@@ -16291,9 +16289,7 @@ class Graphie extends React__namespace.Component {
16291
16289
  };
16292
16290
  _removeMovables = () => {
16293
16291
  // _.invoke works even when this._movables is undefined
16294
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16295
16292
  ___default["default"].invoke(this._movables, "remove");
16296
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16297
16293
  this._movables = {};
16298
16294
  };
16299
16295
 
@@ -16390,7 +16386,6 @@ class Graphie extends React__namespace.Component {
16390
16386
  newMovables[key].toFront();
16391
16387
  }
16392
16388
  if (ref) {
16393
- // @ts-expect-error - TS2339 - Property 'movables' does not exist on type 'Graphie'.
16394
16389
  this.movables[ref] = newMovables[key];
16395
16390
  }
16396
16391
  return newMovables[key];
@@ -16399,15 +16394,10 @@ class Graphie extends React__namespace.Component {
16399
16394
 
16400
16395
  // Sort of like react diffing, but for movables
16401
16396
  _updateMovables = () => {
16402
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16403
16397
  const graphie = this._graphie;
16404
-
16405
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16406
16398
  const oldMovables = this._movables;
16407
16399
  const newMovables = {};
16408
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16409
16400
  this._movables = newMovables;
16410
- // @ts-expect-error - TS2339 - Property 'movables' does not exist on type 'Graphie'.
16411
16401
  this.movables = {};
16412
16402
 
16413
16403
  // @ts-expect-error - TS2345 - Argument of type 'ReactNode' is not assignable to parameter of type 'readonly any[]'.
@@ -18538,10 +18528,13 @@ const registerWidgets = widgets => {
18538
18528
  */
18539
18529
  const replaceWidget = (name, replacementName) => {
18540
18530
  const substituteWidget = widgets[replacementName];
18541
- if (!substituteWidget && Log) {
18531
+
18532
+ // If the replacement widget isn't found, we need to throw. Otherwise after
18533
+ // removing the deprecated widget, we'll have data asking for a widget type
18534
+ // that doesn't exist at all.
18535
+ if (!substituteWidget) {
18542
18536
  const errorMsg = `Failed to replace ${name} with ${replacementName}`;
18543
- Log.error(errorMsg, Errors.Internal);
18544
- return;
18537
+ throw new PerseusError(errorMsg, Errors.Internal);
18545
18538
  }
18546
18539
  registerWidget(name, substituteWidget);
18547
18540
  };
@@ -27923,21 +27916,23 @@ class Graph extends React__namespace.Component {
27923
27916
  // `\text{Dollars}` to the Graph widget.
27924
27917
  const labels = this.props.labels.map(label => Util.unescapeMathMode(label));
27925
27918
  const range = this.props.range;
27919
+ // @ts-expect-error - TS2345: Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
27926
27920
  const graphie = this._graphie = GraphUtils.createGraphie(graphieDiv);
27927
27921
  const gridConfig = this._getGridConfig();
27922
+ // @ts-expect-error - TS2339: Property 'snap' does not exist on type 'Graphie'.
27928
27923
  graphie.snap = this.props.snapStep;
27929
27924
  if (this.props.markings === "graph") {
27930
27925
  graphie.graphInit({
27931
27926
  range: range,
27932
- scale: ___default["default"].pluck(gridConfig, "scale"),
27927
+ scale: kmath.vector.map(gridConfig, g => g.scale),
27933
27928
  axisArrows: "<->",
27934
27929
  labelFormat: function (s) {
27935
27930
  return "\\small{" + s + "}";
27936
27931
  },
27937
27932
  gridStep: this.props.gridStep,
27938
- tickStep: ___default["default"].pluck(gridConfig, "tickStep"),
27933
+ tickStep: kmath.vector.map(gridConfig, g => g.tickStep),
27939
27934
  labelStep: 1,
27940
- unityLabels: ___default["default"].pluck(gridConfig, "unityLabel"),
27935
+ unityLabels: kmath.vector.map(gridConfig, g => g.unityLabel),
27941
27936
  isMobile: this.props.isMobile
27942
27937
  });
27943
27938
  graphie.label([0, range[1][1]], labels[1], this.props.isMobile ? "below right" : "above");
@@ -27945,7 +27940,7 @@ class Graph extends React__namespace.Component {
27945
27940
  } else if (this.props.markings === "grid") {
27946
27941
  graphie.graphInit({
27947
27942
  range: range,
27948
- scale: ___default["default"].pluck(gridConfig, "scale"),
27943
+ scale: kmath.vector.map(gridConfig, g => g.scale),
27949
27944
  gridStep: this.props.gridStep,
27950
27945
  axes: false,
27951
27946
  ticks: false,
@@ -27955,7 +27950,7 @@ class Graph extends React__namespace.Component {
27955
27950
  } else if (this.props.markings === "none") {
27956
27951
  graphie.init({
27957
27952
  range: range,
27958
- scale: ___default["default"].pluck(gridConfig, "scale"),
27953
+ scale: kmath.vector.map(gridConfig, g => g.scale),
27959
27954
  isMobile: this.props.isMobile
27960
27955
  });
27961
27956
  }
@@ -28002,6 +27997,7 @@ class Graph extends React__namespace.Component {
28002
27997
  } : null;
28003
27998
  /* eslint-enable indent */
28004
27999
 
28000
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
28005
28001
  graphie.addMouseLayer({
28006
28002
  onClick: this.props.onClick,
28007
28003
  onMouseDown: onMouseDown,
@@ -28027,10 +28023,7 @@ class Graph extends React__namespace.Component {
28027
28023
  }
28028
28024
  };
28029
28025
  _getGridConfig = () => {
28030
- const self = this;
28031
- return ___default["default"].map(self.props.step, function (step, i) {
28032
- return Util.gridDimensionConfig(step, self.props.range[i], self.props.box[i], self.props.gridStep[i]);
28033
- });
28026
+ return kmath.vector.map(this.props.step, (step, i) => Util.gridDimensionConfig(step, this.props.range[i], this.props.box[i], this.props.gridStep[i]));
28034
28027
  };
28035
28028
  _updateProtractor = () => {
28036
28029
  if (this.protractor) {
@@ -33802,6 +33795,7 @@ const Measurer = createReactClass__default["default"]({
33802
33795
  const graphieDiv = ReactDOM__default["default"].findDOMNode(this.refs.graphieDiv);
33803
33796
  // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
33804
33797
  $__default["default"](graphieDiv).empty();
33798
+ // @ts-expect-error - Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
33805
33799
  const graphie = this.graphie = GraphUtils.createGraphie(graphieDiv);
33806
33800
  const scale = [40, 40];
33807
33801
  const range = [[0, this.props.box[0] / scale[0]], [0, this.props.box[1] / scale[1]]];
@@ -33809,6 +33803,7 @@ const Measurer = createReactClass__default["default"]({
33809
33803
  range: range,
33810
33804
  scale: scale
33811
33805
  });
33806
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
33812
33807
  graphie.addMouseLayer({
33813
33808
  allowScratchpad: true,
33814
33809
  setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
@@ -33817,12 +33812,14 @@ const Measurer = createReactClass__default["default"]({
33817
33812
  this.protractor.remove();
33818
33813
  }
33819
33814
  if (this.props.showProtractor) {
33815
+ // @ts-expect-error - Property 'protractor' does not exist on type 'Graphie'.
33820
33816
  this.protractor = graphie.protractor([this.props.protractorX, this.props.protractorY]);
33821
33817
  }
33822
33818
  if (this.ruler) {
33823
33819
  this.ruler.remove();
33824
33820
  }
33825
33821
  if (this.props.showRuler) {
33822
+ // @ts-expect-error - Property 'ruler' does not exist on type 'Graphie'.
33826
33823
  this.ruler = graphie.ruler({
33827
33824
  center: [(range[0][0] + range[0][1]) / 2, (range[1][0] + range[1][1]) / 2],
33828
33825
  label: this.props.rulerLabel,
@@ -38241,6 +38238,7 @@ class Plotter extends React__namespace.Component {
38241
38238
  const graphieDiv = ReactDOM__default["default"].findDOMNode(self.refs.graphieDiv);
38242
38239
  // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
38243
38240
  $__default["default"](graphieDiv).empty();
38241
+ // @ts-expect-error - Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
38244
38242
  const graphie = GraphUtils.createGraphie(graphieDiv);
38245
38243
 
38246
38244
  // TODO(jakesandlund): It's not the react way to hang
@@ -38348,6 +38346,7 @@ class Plotter extends React__namespace.Component {
38348
38346
  scale: c.scale,
38349
38347
  isMobile: this.props.apiOptions.isMobile
38350
38348
  });
38349
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
38351
38350
  graphie.addMouseLayer({
38352
38351
  allowScratchpad: true,
38353
38352
  setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
@@ -41616,7 +41615,7 @@ const init = function (options) {
41616
41615
 
41617
41616
  // This file is processed by a Rollup plugin (replace) to inject the production
41618
41617
  const libName = "@khanacademy/perseus";
41619
- const libVersion = "19.1.1";
41618
+ const libVersion = "19.1.2";
41620
41619
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
41621
41620
 
41622
41621
  const apiVersion = {