@khanacademy/perseus 19.1.3 → 19.1.4
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/CHANGELOG.md +11 -0
- package/dist/es/index.js +25 -57
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +38 -42
- package/dist/index.js.map +1 -1
- package/dist/interactive2/interactive-util.d.ts +1 -1
- package/dist/interactive2/movable.d.ts +20 -1
- package/dist/util/graphie.d.ts +1 -1
- package/package.json +2 -2
- package/src/interactive2/__tests__/movable-mock.ts +2 -1
- package/src/interactive2/__tests__/movable.test.ts +157 -0
- package/src/interactive2/interactive-util.test.ts +93 -0
- package/src/interactive2/interactive-util.ts +19 -15
- package/src/interactive2/movable-helper-methods.ts +7 -2
- package/src/interactive2/movable-line.ts +1 -12
- package/src/interactive2/movable-point.tsx +1 -9
- package/src/interactive2/movable-polygon.ts +1 -9
- package/src/interactive2/movable.ts +49 -44
- package/src/util/graphie.ts +3 -1
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -4009,8 +4009,13 @@ const MovableHelperMethods = {
|
|
|
4009
4009
|
/**
|
|
4010
4010
|
* Fire an onSomething type event to all functions in listeners
|
|
4011
4011
|
*/
|
|
4012
|
-
_fireEvent: function (listeners
|
|
4013
|
-
|
|
4012
|
+
_fireEvent: function (listeners) {
|
|
4013
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
4014
|
+
args[_key - 1] = arguments[_key];
|
|
4015
|
+
}
|
|
4016
|
+
for (const listener of listeners) {
|
|
4017
|
+
listener.call(this, ...args);
|
|
4018
|
+
}
|
|
4014
4019
|
},
|
|
4015
4020
|
/**
|
|
4016
4021
|
* Combine the array of constraints functions
|
|
@@ -4148,6 +4153,7 @@ function computeCanUse3dTransform() {
|
|
|
4148
4153
|
// @ts-expect-error - TS2538 - Type 'null' cannot be used as an index type. | TS2538 - Type 'undefined' cannot be used as an index type.
|
|
4149
4154
|
return !!el.style[prefix];
|
|
4150
4155
|
}
|
|
4156
|
+
const FUNCTION_ARRAY_OPTIONS = ["add", "modify", "draw", "remove", "constraints", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
|
|
4151
4157
|
const InteractiveUtil = {
|
|
4152
4158
|
assert: function (isTrue, message) {
|
|
4153
4159
|
if (!isTrue) {
|
|
@@ -4191,21 +4197,16 @@ const InteractiveUtil = {
|
|
|
4191
4197
|
/**
|
|
4192
4198
|
* Convert all function-or-array arguments to arrays of functions
|
|
4193
4199
|
*/
|
|
4194
|
-
normalizeOptions: function (
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
// normalizeOptions once in this.modify
|
|
4200
|
-
const result = ___default["default"].clone(options);
|
|
4201
|
-
___default["default"].each(arrayOptionNames, function (eventName) {
|
|
4202
|
-
const funcOrArray = options[eventName];
|
|
4200
|
+
normalizeOptions: function (options) {
|
|
4201
|
+
const result = {
|
|
4202
|
+
...options
|
|
4203
|
+
};
|
|
4204
|
+
FUNCTION_ARRAY_OPTIONS.forEach(function (eventName) {
|
|
4203
4205
|
// Only propagate values which were set; not present values
|
|
4204
4206
|
// shouldn't be added to options because we'd like them to
|
|
4205
4207
|
// fall through to defaults
|
|
4206
|
-
if (
|
|
4207
|
-
|
|
4208
|
-
result[eventName] = funcArray;
|
|
4208
|
+
if (options[eventName] !== undefined) {
|
|
4209
|
+
result[eventName] = InteractiveUtil.arrayify(options[eventName]);
|
|
4209
4210
|
}
|
|
4210
4211
|
});
|
|
4211
4212
|
return result;
|
|
@@ -8717,6 +8718,9 @@ class Graphie$1 {
|
|
|
8717
8718
|
init(options) {
|
|
8718
8719
|
let scale = options.scale || [40, 40];
|
|
8719
8720
|
scale = typeof scale === "number" ? [scale, scale] : scale;
|
|
8721
|
+
|
|
8722
|
+
// TODO(jeremy): This can be removed once we're confident that callers
|
|
8723
|
+
// obey the Typescript types.
|
|
8720
8724
|
if (options.range == null) {
|
|
8721
8725
|
throw new PerseusError("range should be specified in graph init", Errors.Internal);
|
|
8722
8726
|
}
|
|
@@ -13742,10 +13746,6 @@ var GraphieClasses = {
|
|
|
13742
13746
|
const normalizeOptions$3 = InteractiveUtil.normalizeOptions;
|
|
13743
13747
|
const assert$8 = InteractiveUtil.assert;
|
|
13744
13748
|
|
|
13745
|
-
// state parameters that should be converted into an array of
|
|
13746
|
-
// functions
|
|
13747
|
-
const FUNCTION_ARRAY_OPTIONS$3 = ["add", "modify", "draw", "remove", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
|
|
13748
|
-
|
|
13749
13749
|
// Default "props" and "state". Both are added to this.state and
|
|
13750
13750
|
// receive magic getter methods (this.isHovering() etc).
|
|
13751
13751
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -13765,7 +13765,7 @@ const DEFAULT_STATE$3 = {
|
|
|
13765
13765
|
const Movable = function (graphie, options) {
|
|
13766
13766
|
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
13767
13767
|
___default["default"].extend(this, {
|
|
13768
|
-
graphie
|
|
13768
|
+
graphie,
|
|
13769
13769
|
state: {
|
|
13770
13770
|
// Set here because this must be unique for each instance
|
|
13771
13771
|
id: ___default["default"].uniqueId("movable")
|
|
@@ -13780,10 +13780,12 @@ InteractiveUtil.createGettersFor(Movable, ___default["default"].extend({}, DEFAU
|
|
|
13780
13780
|
InteractiveUtil.addMovableHelperMethodsTo(Movable);
|
|
13781
13781
|
___default["default"].extend(Movable.prototype, {
|
|
13782
13782
|
cloneState: function () {
|
|
13783
|
-
return
|
|
13783
|
+
return {
|
|
13784
|
+
...this.state
|
|
13785
|
+
};
|
|
13784
13786
|
},
|
|
13785
13787
|
_createDefaultState: function () {
|
|
13786
|
-
return
|
|
13788
|
+
return {
|
|
13787
13789
|
id: this.state.id,
|
|
13788
13790
|
add: [],
|
|
13789
13791
|
modify: [],
|
|
@@ -13792,11 +13794,11 @@ ___default["default"].extend(Movable.prototype, {
|
|
|
13792
13794
|
onMoveStart: [],
|
|
13793
13795
|
onMove: [],
|
|
13794
13796
|
onMoveEnd: [],
|
|
13795
|
-
onClick: []
|
|
13796
|
-
|
|
13797
|
+
onClick: [],
|
|
13797
13798
|
// We only update props here, because we want things on state to
|
|
13798
13799
|
// be persistent, and updated appropriately in modify()
|
|
13799
|
-
|
|
13800
|
+
...DEFAULT_PROPS$3
|
|
13801
|
+
};
|
|
13800
13802
|
},
|
|
13801
13803
|
/**
|
|
13802
13804
|
* Resets the object to its state as if it were constructed with
|
|
@@ -13805,7 +13807,10 @@ ___default["default"].extend(Movable.prototype, {
|
|
|
13805
13807
|
* Analogous to React.js's replaceProps
|
|
13806
13808
|
*/
|
|
13807
13809
|
modify: function (options) {
|
|
13808
|
-
this.update(
|
|
13810
|
+
this.update({
|
|
13811
|
+
...this._createDefaultState(),
|
|
13812
|
+
...options
|
|
13813
|
+
});
|
|
13809
13814
|
},
|
|
13810
13815
|
/**
|
|
13811
13816
|
* Simulates a mouse grab event on the movable object.
|
|
@@ -13853,7 +13858,7 @@ ___default["default"].extend(Movable.prototype, {
|
|
|
13853
13858
|
const self = this;
|
|
13854
13859
|
const graphie = self.graphie;
|
|
13855
13860
|
const prevState = self.cloneState();
|
|
13856
|
-
const state = ___default["default"].extend(self.state, normalizeOptions$3(
|
|
13861
|
+
const state = ___default["default"].extend(self.state, normalizeOptions$3(options));
|
|
13857
13862
|
|
|
13858
13863
|
// the invisible shape in front of the point that gets mouse events
|
|
13859
13864
|
if (state.mouseTarget && !prevState.mouseTarget) {
|
|
@@ -14279,7 +14284,6 @@ var MovableLineOptions = {
|
|
|
14279
14284
|
*/
|
|
14280
14285
|
const assert$7 = InteractiveUtil.assert;
|
|
14281
14286
|
const normalizeOptions$2 = InteractiveUtil.normalizeOptions;
|
|
14282
|
-
const FUNCTION_ARRAY_OPTIONS$2 = ["add", "draw", "remove", "onMoveStart", "constraints", "onMove", "onMoveEnd"];
|
|
14283
14287
|
|
|
14284
14288
|
// Default "props" and "state". Both are added to this.state and
|
|
14285
14289
|
// receive magic getter methods (this.cursor() etc).
|
|
@@ -14332,7 +14336,7 @@ ___default["default"].extend(MovableLine$4.prototype, {
|
|
|
14332
14336
|
_createDefaultState: function () {
|
|
14333
14337
|
return ___default["default"].extend({
|
|
14334
14338
|
id: this.state.id
|
|
14335
|
-
}, normalizeOptions$2(
|
|
14339
|
+
}, normalizeOptions$2(
|
|
14336
14340
|
// Defaults are copied from MovableLineOptions.*.standard
|
|
14337
14341
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
14338
14342
|
// because they:
|
|
@@ -14359,7 +14363,7 @@ ___default["default"].extend(MovableLine$4.prototype, {
|
|
|
14359
14363
|
update: function (options) {
|
|
14360
14364
|
const self = this;
|
|
14361
14365
|
const graphie = this.graphie;
|
|
14362
|
-
const state = self.state = ___default["default"].extend(self.state, normalizeOptions$2(
|
|
14366
|
+
const state = self.state = ___default["default"].extend(self.state, normalizeOptions$2(options));
|
|
14363
14367
|
|
|
14364
14368
|
// Default things inside the state.normalStyle object, because
|
|
14365
14369
|
// _.extend is not deep.
|
|
@@ -14867,10 +14871,6 @@ const {
|
|
|
14867
14871
|
processMath
|
|
14868
14872
|
} = Tex$1;
|
|
14869
14873
|
|
|
14870
|
-
// State parameters that should be converted into an array of
|
|
14871
|
-
// functions
|
|
14872
|
-
const FUNCTION_ARRAY_OPTIONS$1 = ___default["default"].keys(MovablePointOptions);
|
|
14873
|
-
|
|
14874
14874
|
// Default "props" and "state". Both are added to this.state and
|
|
14875
14875
|
// receive magic getter methods (this.coord() etc).
|
|
14876
14876
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -14923,7 +14923,7 @@ ___default["default"].extend(MovablePoint$5.prototype, {
|
|
|
14923
14923
|
_createDefaultState: function () {
|
|
14924
14924
|
return ___default["default"].extend({
|
|
14925
14925
|
id: this.state.id
|
|
14926
|
-
}, normalizeOptions$1(
|
|
14926
|
+
}, normalizeOptions$1(
|
|
14927
14927
|
// Defaults are copied from MovablePointOptions.*.standard
|
|
14928
14928
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
14929
14929
|
// because they:
|
|
@@ -14996,7 +14996,7 @@ ___default["default"].extend(MovablePoint$5.prototype, {
|
|
|
14996
14996
|
update: function (options) {
|
|
14997
14997
|
const self = this;
|
|
14998
14998
|
const graphie = self.graphie;
|
|
14999
|
-
const state = ___default["default"].extend(self.state, normalizeOptions$1(
|
|
14999
|
+
const state = ___default["default"].extend(self.state, normalizeOptions$1(options));
|
|
15000
15000
|
assert$6(kmath.point.is(state.coord));
|
|
15001
15001
|
|
|
15002
15002
|
// Default things inside the state.normalStyle object, because
|
|
@@ -15603,10 +15603,6 @@ var MovablePolygonOptions = {
|
|
|
15603
15603
|
const assert$5 = InteractiveUtil.assert;
|
|
15604
15604
|
const normalizeOptions = InteractiveUtil.normalizeOptions;
|
|
15605
15605
|
|
|
15606
|
-
// State parameters that should be converted into an array of
|
|
15607
|
-
// functions
|
|
15608
|
-
const FUNCTION_ARRAY_OPTIONS = ___default["default"].keys(MovablePolygonOptions);
|
|
15609
|
-
|
|
15610
15606
|
// Default "props" and "state". Both are added to this.state and
|
|
15611
15607
|
// receive magic getter methods (this.points() etc).
|
|
15612
15608
|
// However, properties in DEFAULT_PROPS are updated on `modify()`,
|
|
@@ -15666,7 +15662,7 @@ ___default["default"].extend(MovablePolygon.prototype, {
|
|
|
15666
15662
|
_createDefaultState: function () {
|
|
15667
15663
|
return ___default["default"].extend({
|
|
15668
15664
|
id: this.state.id
|
|
15669
|
-
}, normalizeOptions(
|
|
15665
|
+
}, normalizeOptions(
|
|
15670
15666
|
// Defaults are copied from MovablePolygonOptions.*.standard
|
|
15671
15667
|
// These defaults are set here instead of DEFAULT_PROPS/STATE
|
|
15672
15668
|
// because they:
|
|
@@ -15697,7 +15693,7 @@ ___default["default"].extend(MovablePolygon.prototype, {
|
|
|
15697
15693
|
update: function (options) {
|
|
15698
15694
|
const self = this;
|
|
15699
15695
|
const graphie = self.graphie;
|
|
15700
|
-
const state = ___default["default"].extend(self.state, normalizeOptions(
|
|
15696
|
+
const state = ___default["default"].extend(self.state, normalizeOptions(options));
|
|
15701
15697
|
|
|
15702
15698
|
// Default things inside the state.normalStyle object, because
|
|
15703
15699
|
// _.extend is not deep.
|
|
@@ -41615,7 +41611,7 @@ const init = function (options) {
|
|
|
41615
41611
|
|
|
41616
41612
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
41617
41613
|
const libName = "@khanacademy/perseus";
|
|
41618
|
-
const libVersion = "19.1.
|
|
41614
|
+
const libVersion = "19.1.4";
|
|
41619
41615
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
41620
41616
|
|
|
41621
41617
|
const apiVersion = {
|