@khanacademy/perseus 19.1.6 → 19.1.8
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/components/graph.d.ts +0 -1
- package/dist/components/graphie.d.ts +0 -1
- package/dist/es/index.js +545 -591
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +564 -601
- package/dist/index.js.map +1 -1
- package/dist/interactive2/movable-point.d.ts +195 -1
- package/dist/interactive2/movable.d.ts +1 -1
- package/dist/interactive2/types.d.ts +4 -2
- package/dist/interactive2.d.ts +2 -1
- package/dist/server-item-renderer.d.ts +2 -2
- package/dist/util/graphie.d.ts +12 -2
- package/dist/widgets/expression.d.ts +6 -6
- package/package.json +3 -3
package/dist/es/index.js
CHANGED
|
@@ -250,7 +250,11 @@ class MathInput extends React.Component {
|
|
|
250
250
|
display: "flex",
|
|
251
251
|
padding: 1
|
|
252
252
|
},
|
|
253
|
-
onClick:
|
|
253
|
+
onClick: e => {
|
|
254
|
+
// Prevent the click into the input from registering
|
|
255
|
+
// so that the keypad popover doesn't close when
|
|
256
|
+
// switching focus to the input.
|
|
257
|
+
e.stopPropagation();
|
|
254
258
|
const mathField = this.mathField();
|
|
255
259
|
if (!mathField) {
|
|
256
260
|
return;
|
|
@@ -3975,10 +3979,10 @@ FixedToResponsive.defaultProps = {
|
|
|
3975
3979
|
|
|
3976
3980
|
/* Local helper methods. */
|
|
3977
3981
|
|
|
3978
|
-
function getKey$
|
|
3982
|
+
function getKey$2(eventName, id) {
|
|
3979
3983
|
return eventName + ":" + id;
|
|
3980
3984
|
}
|
|
3981
|
-
function getEventName$
|
|
3985
|
+
function getEventName$2(key) {
|
|
3982
3986
|
return key.split(":")[0];
|
|
3983
3987
|
}
|
|
3984
3988
|
const MovableHelperMethods = {
|
|
@@ -4055,7 +4059,7 @@ const MovableHelperMethods = {
|
|
|
4055
4059
|
|
|
4056
4060
|
// If there's an existing handler, replace it by using its index in
|
|
4057
4061
|
// `this.state[eventName]`; otherwise, add this handler to the end
|
|
4058
|
-
const key = getKey$
|
|
4062
|
+
const key = getKey$2(eventName, id);
|
|
4059
4063
|
const index = this._listenerMap[key] = this._listenerMap[key] || this.state[eventName].length;
|
|
4060
4064
|
this.state[eventName][index] = func;
|
|
4061
4065
|
},
|
|
@@ -4067,7 +4071,7 @@ const MovableHelperMethods = {
|
|
|
4067
4071
|
*/
|
|
4068
4072
|
unlisten: function (eventName, id) {
|
|
4069
4073
|
this._listenerMap = this._listenerMap || {};
|
|
4070
|
-
const key = getKey$
|
|
4074
|
+
const key = getKey$2(eventName, id);
|
|
4071
4075
|
const index = this._listenerMap[key];
|
|
4072
4076
|
if (index !== undefined) {
|
|
4073
4077
|
// Remove handler from list of event handlers and listenerMap
|
|
@@ -4077,7 +4081,7 @@ const MovableHelperMethods = {
|
|
|
4077
4081
|
// Re-index existing events: if they occur after `index`, decrement
|
|
4078
4082
|
const keys = _.keys(this._listenerMap);
|
|
4079
4083
|
_.each(keys, function (key) {
|
|
4080
|
-
if (getEventName$
|
|
4084
|
+
if (getEventName$2(key) === eventName &&
|
|
4081
4085
|
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
4082
4086
|
this._listenerMap[key] > index) {
|
|
4083
4087
|
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
@@ -4211,22 +4215,13 @@ function _classPrivateFieldKey(name) {
|
|
|
4211
4215
|
return "__private_" + id$1++ + "_" + name;
|
|
4212
4216
|
}
|
|
4213
4217
|
|
|
4214
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4215
|
-
|
|
4216
|
-
function getDefaultExportFromCjs (x) {
|
|
4217
|
-
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
4218
|
-
}
|
|
4219
|
-
|
|
4220
|
-
var raphael = {exports: {}};
|
|
4221
|
-
|
|
4222
4218
|
/*!
|
|
4223
4219
|
* Raphael 1.5.2 - JavaScript Vector Library
|
|
4224
4220
|
*
|
|
4225
4221
|
* Copyright (c) 2010 Dmitry Baranovskiy (http://raphaeljs.com)
|
|
4226
4222
|
* Licensed under the MIT (http://raphaeljs.com/license.html) license.
|
|
4227
4223
|
*/
|
|
4228
|
-
|
|
4229
|
-
(function () {
|
|
4224
|
+
var Raphael$1 = (function () {
|
|
4230
4225
|
var setAttr;
|
|
4231
4226
|
if ("".trim) {
|
|
4232
4227
|
setAttr = function (node, att, value) {
|
|
@@ -8403,7 +8398,7 @@ var raphael = {exports: {}};
|
|
|
8403
8398
|
};
|
|
8404
8399
|
R.el = elproto;
|
|
8405
8400
|
R.st = Set[proto];
|
|
8406
|
-
|
|
8401
|
+
return R;
|
|
8407
8402
|
})();
|
|
8408
8403
|
|
|
8409
8404
|
/**
|
|
@@ -8860,7 +8855,7 @@ class Graphie$1 {
|
|
|
8860
8855
|
};
|
|
8861
8856
|
this.el = el;
|
|
8862
8857
|
$(el).css("position", "relative");
|
|
8863
|
-
this.raphael =
|
|
8858
|
+
this.raphael = Raphael$1(el);
|
|
8864
8859
|
|
|
8865
8860
|
// For a sometimes-reproducible IE8 bug; doesn't affect SVG browsers at all
|
|
8866
8861
|
$(el).children("div").css("position", "absolute");
|
|
@@ -9217,7 +9212,7 @@ class Graphie$1 {
|
|
|
9217
9212
|
// wrapper.setAttribute("data-graphie-type", "ellipse");
|
|
9218
9213
|
|
|
9219
9214
|
// Create Raphael canvas
|
|
9220
|
-
const localRaphael =
|
|
9215
|
+
const localRaphael = Raphael$1(wrapper, width, height);
|
|
9221
9216
|
const visibleShape = localRaphael.ellipse(width / 2, height / 2, scaledRadii[0], scaledRadii[1]);
|
|
9222
9217
|
return {
|
|
9223
9218
|
wrapper: wrapper,
|
|
@@ -9284,7 +9279,7 @@ class Graphie$1 {
|
|
|
9284
9279
|
});
|
|
9285
9280
|
|
|
9286
9281
|
// Create Raphael canvas
|
|
9287
|
-
const localRaphael =
|
|
9282
|
+
const localRaphael = Raphael$1(wrapper, width, height);
|
|
9288
9283
|
|
|
9289
9284
|
// Calculate path
|
|
9290
9285
|
const visibleShape = localRaphael.path(createPath(points));
|
|
@@ -9347,7 +9342,7 @@ class Graphie$1 {
|
|
|
9347
9342
|
});
|
|
9348
9343
|
|
|
9349
9344
|
// Create Raphael canvas
|
|
9350
|
-
const localRaphael =
|
|
9345
|
+
const localRaphael = Raphael$1(wrapper, width, height);
|
|
9351
9346
|
|
|
9352
9347
|
// Calculate path
|
|
9353
9348
|
const path = "M" + start[0] + " " + start[1] + " " + "L" + end[0] + " " + end[1];
|
|
@@ -9431,7 +9426,7 @@ class Graphie$1 {
|
|
|
9431
9426
|
postprocessDrawingResult(result) {
|
|
9432
9427
|
// Bad heuristic for recognizing Raphael elements and sets
|
|
9433
9428
|
const type = result.constructor.prototype;
|
|
9434
|
-
if (type ===
|
|
9429
|
+
if (type === Raphael$1.el || type === Raphael$1.st) {
|
|
9435
9430
|
result.attr(this.currentStyle);
|
|
9436
9431
|
if (this.currentStyle.arrows) {
|
|
9437
9432
|
result = this.addArrowheads(result);
|
|
@@ -9446,7 +9441,7 @@ class Graphie$1 {
|
|
|
9446
9441
|
}
|
|
9447
9442
|
addArrowheads(path) {
|
|
9448
9443
|
const type = path.constructor.prototype;
|
|
9449
|
-
if (type ===
|
|
9444
|
+
if (type === Raphael$1.el) {
|
|
9450
9445
|
if (path.type === "path" && typeof path.arrowheadsDrawn === "undefined") {
|
|
9451
9446
|
const w = path.attr("stroke-width");
|
|
9452
9447
|
const s = 0.6 + 0.4 * w;
|
|
@@ -9474,7 +9469,7 @@ class Graphie$1 {
|
|
|
9474
9469
|
set.push(head);
|
|
9475
9470
|
return set;
|
|
9476
9471
|
}
|
|
9477
|
-
} else if (type ===
|
|
9472
|
+
} else if (type === Raphael$1.st) {
|
|
9478
9473
|
for (let i = 0, l = path.items.length; i < l; i++) {
|
|
9479
9474
|
this.addArrowheads(path.items[i]);
|
|
9480
9475
|
}
|
|
@@ -9535,6 +9530,9 @@ class Graphie$1 {
|
|
|
9535
9530
|
getMouseCoord(event) {
|
|
9536
9531
|
throw new Error("getMouseCoord is a stub, and is not implemented");
|
|
9537
9532
|
}
|
|
9533
|
+
|
|
9534
|
+
// This is a stub that's overridden in interactive.ts
|
|
9535
|
+
addMouseLayer(options) {}
|
|
9538
9536
|
}
|
|
9539
9537
|
const labelDirections = {
|
|
9540
9538
|
center: [-0.5, -0.5],
|
|
@@ -10645,7 +10643,7 @@ _.extend(GraphUtils.Graphie.prototype, {
|
|
|
10645
10643
|
setDrawingAreaAvailable: function () {}
|
|
10646
10644
|
}, options);
|
|
10647
10645
|
const mouselayerZIndex = 2;
|
|
10648
|
-
graph.mouselayer =
|
|
10646
|
+
graph.mouselayer = Raphael$1(graph.raphael.canvas.parentNode, graph.xpixels, graph.ypixels);
|
|
10649
10647
|
$(graph.mouselayer.canvas).css("z-index", mouselayerZIndex);
|
|
10650
10648
|
if (options.onClick || options.onMouseDown || options.onMouseMove || options.onMouseOver || options.onMouseOut) {
|
|
10651
10649
|
const canvasClickTarget = graph.mouselayer.rect(0, 0, graph.xpixels, graph.ypixels).attr({
|
|
@@ -13985,7 +13983,7 @@ class Movable {
|
|
|
13985
13983
|
|
|
13986
13984
|
// If there's an existing handler, replace it by using its index in
|
|
13987
13985
|
// `this.state[eventName]`; otherwise, add this handler to the end
|
|
13988
|
-
const key = getKey(eventName, id);
|
|
13986
|
+
const key = getKey$1(eventName, id);
|
|
13989
13987
|
const index = this._listenerMap[key] = this._listenerMap[key] || this.state[eventName].length;
|
|
13990
13988
|
this.state[eventName][index] = func;
|
|
13991
13989
|
}
|
|
@@ -13998,7 +13996,7 @@ class Movable {
|
|
|
13998
13996
|
*/
|
|
13999
13997
|
unlisten(eventName, id) {
|
|
14000
13998
|
this._listenerMap = this._listenerMap || {};
|
|
14001
|
-
const key = getKey(eventName, id);
|
|
13999
|
+
const key = getKey$1(eventName, id);
|
|
14002
14000
|
const index = this._listenerMap[key];
|
|
14003
14001
|
if (index !== undefined) {
|
|
14004
14002
|
// Remove handler from list of event handlers and listenerMap
|
|
@@ -14008,7 +14006,7 @@ class Movable {
|
|
|
14008
14006
|
// Re-index existing events: if they occur after `index`, decrement
|
|
14009
14007
|
const keys = _.keys(this._listenerMap);
|
|
14010
14008
|
keys.forEach(key => {
|
|
14011
|
-
if (getEventName(key) === eventName && this._listenerMap[key] > index) {
|
|
14009
|
+
if (getEventName$1(key) === eventName && this._listenerMap[key] > index) {
|
|
14012
14010
|
this._listenerMap[key]--;
|
|
14013
14011
|
}
|
|
14014
14012
|
});
|
|
@@ -14042,10 +14040,10 @@ class Movable {
|
|
|
14042
14040
|
return this.state.mouseTarget;
|
|
14043
14041
|
}
|
|
14044
14042
|
}
|
|
14045
|
-
function getKey(eventName, id) {
|
|
14043
|
+
function getKey$1(eventName, id) {
|
|
14046
14044
|
return eventName + ":" + id;
|
|
14047
14045
|
}
|
|
14048
|
-
function getEventName(key) {
|
|
14046
|
+
function getEventName$1(key) {
|
|
14049
14047
|
return key.split(":")[0];
|
|
14050
14048
|
}
|
|
14051
14049
|
|
|
@@ -14994,31 +14992,31 @@ const DEFAULT_STATE$1 = {
|
|
|
14994
14992
|
mouseTarget: null,
|
|
14995
14993
|
touchOffset: null
|
|
14996
14994
|
};
|
|
14995
|
+
// TODO(benchristel): this is a memory leak. We add items to
|
|
14996
|
+
// tooltipResetFunctions, but never remove them.
|
|
14997
14997
|
const tooltipResetFunctions = [];
|
|
14998
|
-
|
|
14999
|
-
|
|
15000
|
-
|
|
15001
|
-
|
|
15002
|
-
|
|
15003
|
-
|
|
15004
|
-
|
|
14998
|
+
class MovablePoint$5 {
|
|
14999
|
+
constructor(graphie, movable, options) {
|
|
15000
|
+
this.graphie = void 0;
|
|
15001
|
+
this.movable = void 0;
|
|
15002
|
+
this.state = void 0;
|
|
15003
|
+
// @ts-expect-error - TS2564: Property 'prevState' has no initializer and is not definitely assigned in the constructor.
|
|
15004
|
+
this.prevState = void 0;
|
|
15005
|
+
this._tooltip = void 0;
|
|
15006
|
+
this._listenerMap = {};
|
|
15007
|
+
this.graphie = graphie;
|
|
15008
|
+
this.movable = movable;
|
|
15009
|
+
// @ts-expect-error - TS2740: Type '{ id: string; }' is missing the following properties from type 'State': add, added, constraints, coord, and 19 more.
|
|
15010
|
+
this.state = {
|
|
15005
15011
|
id: _.uniqueId("movablePoint")
|
|
15006
|
-
}
|
|
15007
|
-
|
|
15008
|
-
|
|
15009
|
-
|
|
15010
|
-
|
|
15011
|
-
|
|
15012
|
-
|
|
15013
|
-
|
|
15014
|
-
InteractiveUtil.createGettersFor(MovablePoint$5, _.extend({}, DEFAULT_PROPS$1, DEFAULT_STATE$1));
|
|
15015
|
-
InteractiveUtil.addMovableHelperMethodsTo(MovablePoint$5);
|
|
15016
|
-
_.extend(MovablePoint$5.prototype, {
|
|
15017
|
-
cloneState: function () {
|
|
15018
|
-
return _.extend(this.movable.cloneState(), this.state);
|
|
15019
|
-
},
|
|
15020
|
-
_createDefaultState: function () {
|
|
15021
|
-
return _.extend({
|
|
15012
|
+
};
|
|
15013
|
+
this.modify(_extends({}, DEFAULT_STATE$1, options));
|
|
15014
|
+
}
|
|
15015
|
+
modify(options) {
|
|
15016
|
+
this.update(_.extend(this._createDefaultState(), options));
|
|
15017
|
+
}
|
|
15018
|
+
_createDefaultState() {
|
|
15019
|
+
return _extends({
|
|
15022
15020
|
id: this.state.id
|
|
15023
15021
|
}, normalizeOptions$1(
|
|
15024
15022
|
// Defaults are copied from MovablePointOptions.*.standard
|
|
@@ -15028,69 +15026,14 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15028
15026
|
// - they don't need getters created for them
|
|
15029
15027
|
// TODO(jack): Consider "default" once we es3ify perseus
|
|
15030
15028
|
objective_.pluck(MovablePointOptions, "standard")
|
|
15031
|
-
|
|
15032
15029
|
// We only update props here, because we want things on state to
|
|
15033
15030
|
// be persistent, and updated appropriately in modify()
|
|
15034
15031
|
), DEFAULT_PROPS$1);
|
|
15035
|
-
}
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
* Analogous to React.js's replaceProps
|
|
15041
|
-
*/
|
|
15042
|
-
modify: function (options) {
|
|
15043
|
-
this.update(_.extend(this._createDefaultState(), options));
|
|
15044
|
-
},
|
|
15045
|
-
/**
|
|
15046
|
-
* Displays a tooltip above the point, replacing any previous contents. If
|
|
15047
|
-
* there is no tooltip initialized, adds the tooltip.
|
|
15048
|
-
*
|
|
15049
|
-
* If the type of contents is string, the contents will be rendered with
|
|
15050
|
-
* KaTeX. Otherwise, the content will be assumed to be a DOM node and will
|
|
15051
|
-
* be appended inside the tooltip.
|
|
15052
|
-
*/
|
|
15053
|
-
_showTooltip: function (contents) {
|
|
15054
|
-
if (!this._tooltip) {
|
|
15055
|
-
this._tooltip = document.createElement("div");
|
|
15056
|
-
this._tooltip.className = "tooltip-content";
|
|
15057
|
-
this.state.visibleShape.wrapper.className = "tooltip";
|
|
15058
|
-
this.state.visibleShape.wrapper.appendChild(this._tooltip);
|
|
15059
|
-
|
|
15060
|
-
// Only one tooltip should be displayed at a time, so store a list
|
|
15061
|
-
// of all the tooltips initialized.
|
|
15062
|
-
tooltipResetFunctions.push(() => {
|
|
15063
|
-
if (this.state.added) {
|
|
15064
|
-
this._hideTooltip();
|
|
15065
|
-
}
|
|
15066
|
-
});
|
|
15067
|
-
}
|
|
15068
|
-
if (this._tooltip.firstChild) {
|
|
15069
|
-
this._tooltip.removeChild(this._tooltip.firstChild);
|
|
15070
|
-
}
|
|
15071
|
-
this.state.visibleShape.wrapper.className = "tooltip visible";
|
|
15072
|
-
this._tooltip.appendChild(document.createElement("span"));
|
|
15073
|
-
if (typeof contents === "string") {
|
|
15074
|
-
processMath(this._tooltip.firstChild, contents, false);
|
|
15075
|
-
} else if (typeof contents === "function") {
|
|
15076
|
-
contents(this._tooltip.firstChild);
|
|
15077
|
-
} else {
|
|
15078
|
-
this._tooltip.firstChild.appendChild(contents);
|
|
15079
|
-
}
|
|
15080
|
-
},
|
|
15081
|
-
_hideTooltip: function () {
|
|
15082
|
-
if (this._tooltip) {
|
|
15083
|
-
// Without the visible class, tooltips have display: none set
|
|
15084
|
-
this.state.visibleShape.wrapper.className = "tooltip";
|
|
15085
|
-
}
|
|
15086
|
-
},
|
|
15087
|
-
/**
|
|
15088
|
-
* Adjusts constructor parameters without changing previous settings
|
|
15089
|
-
* for any option not specified
|
|
15090
|
-
*
|
|
15091
|
-
* Analogous to React.js's setProps
|
|
15092
|
-
*/
|
|
15093
|
-
update: function (options) {
|
|
15032
|
+
}
|
|
15033
|
+
cloneState() {
|
|
15034
|
+
return _extends({}, this.movable.cloneState(), this.state);
|
|
15035
|
+
}
|
|
15036
|
+
update(options) {
|
|
15094
15037
|
const self = this;
|
|
15095
15038
|
const graphie = self.graphie;
|
|
15096
15039
|
const state = _.extend(self.state, normalizeOptions$1(options));
|
|
@@ -15240,11 +15183,15 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15240
15183
|
showTrashTooltip();
|
|
15241
15184
|
const content = svgElem.getElementsByClassName("tooltip-content")[0];
|
|
15242
15185
|
content.style.filter = "none";
|
|
15186
|
+
|
|
15187
|
+
// @ts-expect-error - this._tooltip.firstChild is possibly null
|
|
15243
15188
|
this._tooltip.firstChild.addEventListener("touchstart", e => {
|
|
15244
15189
|
// Prevent creation of a new point when the event is
|
|
15245
15190
|
// propagated up the DOM.
|
|
15246
15191
|
e.stopPropagation();
|
|
15247
15192
|
}, true);
|
|
15193
|
+
|
|
15194
|
+
// @ts-expect-error - this._tooltip.firstChild is possibly null
|
|
15248
15195
|
this._tooltip.firstChild.addEventListener("touchend", e => {
|
|
15249
15196
|
// Remove the point and prevent creation of a
|
|
15250
15197
|
// new point.
|
|
@@ -15266,6 +15213,7 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15266
15213
|
|
|
15267
15214
|
// Trigger an add event if this hasn't been added before
|
|
15268
15215
|
if (!state.added) {
|
|
15216
|
+
// @ts-expect-error - type {} is missing properties from State
|
|
15269
15217
|
self.prevState = {};
|
|
15270
15218
|
self._fireEvent(state.add, self.cloneState(), self.prevState);
|
|
15271
15219
|
state.added = true;
|
|
@@ -15277,38 +15225,187 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15277
15225
|
|
|
15278
15226
|
// Trigger a modify event
|
|
15279
15227
|
self._fireEvent(state.modify, self.cloneState(), self.prevState);
|
|
15280
|
-
}
|
|
15281
|
-
|
|
15282
|
-
|
|
15283
|
-
this._fireEvent(this.state.
|
|
15284
|
-
|
|
15285
|
-
|
|
15286
|
-
|
|
15287
|
-
// TODO(jack): This should really be moved off of
|
|
15288
|
-
// movablePoint.state and only kept on movable.state
|
|
15289
|
-
this.state.mouseTarget = null;
|
|
15290
|
-
},
|
|
15291
|
-
constrain: function () {
|
|
15228
|
+
}
|
|
15229
|
+
draw() {
|
|
15230
|
+
const currState = this.cloneState();
|
|
15231
|
+
this._fireEvent(this.state.draw, currState, this.prevState);
|
|
15232
|
+
this.prevState = currState;
|
|
15233
|
+
}
|
|
15234
|
+
constrain() {
|
|
15292
15235
|
const result = this._applyConstraints(this.coord(), this.coord());
|
|
15293
15236
|
if (point.is(result)) {
|
|
15294
15237
|
this.setCoord(result);
|
|
15295
15238
|
}
|
|
15296
15239
|
return result !== false;
|
|
15297
|
-
}
|
|
15298
|
-
|
|
15240
|
+
}
|
|
15241
|
+
|
|
15242
|
+
/**
|
|
15243
|
+
* Fire an onSomething type event to all functions in listeners
|
|
15244
|
+
*/
|
|
15245
|
+
_fireEvent(listeners, ...args) {
|
|
15246
|
+
for (const listener of listeners) {
|
|
15247
|
+
listener.call(this, ...args);
|
|
15248
|
+
}
|
|
15249
|
+
}
|
|
15250
|
+
|
|
15251
|
+
/**
|
|
15252
|
+
* Combine the array of constraints functions
|
|
15253
|
+
* Returns either an [x, y] coordinate or false
|
|
15254
|
+
*/
|
|
15255
|
+
_applyConstraints(current, previous, extraOptions) {
|
|
15256
|
+
let skipRemaining = false;
|
|
15257
|
+
return this.state.constraints.reduce((memo, constraint) => {
|
|
15258
|
+
// A move that has been cancelled won't be propagated to later
|
|
15259
|
+
// constraints calls
|
|
15260
|
+
if (memo === false) {
|
|
15261
|
+
return false;
|
|
15262
|
+
}
|
|
15263
|
+
if (skipRemaining) {
|
|
15264
|
+
return memo;
|
|
15265
|
+
}
|
|
15266
|
+
const result = constraint.call(this, memo, previous, _extends({
|
|
15267
|
+
onSkipRemaining: () => {
|
|
15268
|
+
skipRemaining = true;
|
|
15269
|
+
}
|
|
15270
|
+
}, extraOptions));
|
|
15271
|
+
if (result === false) {
|
|
15272
|
+
// Returning false cancels the move
|
|
15273
|
+
return false;
|
|
15274
|
+
}
|
|
15275
|
+
if (point.is(result, 2)) {
|
|
15276
|
+
// Returning a coord from constraints overrides the move
|
|
15277
|
+
return result;
|
|
15278
|
+
}
|
|
15279
|
+
if (result === true || result == null) {
|
|
15280
|
+
// Returning true or undefined allow the move to occur
|
|
15281
|
+
return memo;
|
|
15282
|
+
}
|
|
15283
|
+
// Anything else is an error
|
|
15284
|
+
throw new PerseusError("Constraint returned invalid result: " + result, Errors.Internal);
|
|
15285
|
+
}, current);
|
|
15286
|
+
}
|
|
15287
|
+
|
|
15288
|
+
/**
|
|
15289
|
+
* Displays a tooltip above the point, replacing any previous contents. If
|
|
15290
|
+
* there is no tooltip initialized, adds the tooltip.
|
|
15291
|
+
*
|
|
15292
|
+
* If the type of contents is string, the contents will be rendered with
|
|
15293
|
+
* KaTeX. Otherwise, the content will be assumed to be a DOM node and will
|
|
15294
|
+
* be appended inside the tooltip.
|
|
15295
|
+
*/
|
|
15296
|
+
_showTooltip(contents) {
|
|
15297
|
+
if (!this._tooltip) {
|
|
15298
|
+
this._tooltip = document.createElement("div");
|
|
15299
|
+
this._tooltip.className = "tooltip-content";
|
|
15300
|
+
this.state.visibleShape.wrapper.className = "tooltip";
|
|
15301
|
+
this.state.visibleShape.wrapper.appendChild(this._tooltip);
|
|
15302
|
+
|
|
15303
|
+
// Only one tooltip should be displayed at a time, so store a list
|
|
15304
|
+
// of all the tooltips initialized.
|
|
15305
|
+
tooltipResetFunctions.push(() => {
|
|
15306
|
+
if (this.state.added) {
|
|
15307
|
+
this._hideTooltip();
|
|
15308
|
+
}
|
|
15309
|
+
});
|
|
15310
|
+
}
|
|
15311
|
+
if (this._tooltip.firstChild) {
|
|
15312
|
+
this._tooltip.removeChild(this._tooltip.firstChild);
|
|
15313
|
+
}
|
|
15314
|
+
this.state.visibleShape.wrapper.className = "tooltip visible";
|
|
15315
|
+
this._tooltip.appendChild(document.createElement("span"));
|
|
15316
|
+
if (typeof contents === "string") {
|
|
15317
|
+
// @ts-expect-error - this._tooltip.firstChild is possibly 'null'.
|
|
15318
|
+
processMath(this._tooltip.firstChild, contents, false);
|
|
15319
|
+
} else if (typeof contents === "function") {
|
|
15320
|
+
contents(this._tooltip.firstChild);
|
|
15321
|
+
} else {
|
|
15322
|
+
// @ts-expect-error - this._tooltip.firstChild is possibly 'null'.
|
|
15323
|
+
this._tooltip.firstChild.appendChild(contents);
|
|
15324
|
+
}
|
|
15325
|
+
}
|
|
15326
|
+
_hideTooltip() {
|
|
15327
|
+
if (this._tooltip) {
|
|
15328
|
+
// Without the visible class, tooltips have display: none set
|
|
15329
|
+
this.state.visibleShape.wrapper.className = "tooltip";
|
|
15330
|
+
}
|
|
15331
|
+
}
|
|
15332
|
+
coord() {
|
|
15333
|
+
return this.state.coord;
|
|
15334
|
+
}
|
|
15335
|
+
setCoord(coord) {
|
|
15299
15336
|
assert$6(point.is(coord, 2));
|
|
15300
15337
|
this.state.coord = _.clone(coord);
|
|
15301
15338
|
this.draw();
|
|
15302
|
-
}
|
|
15303
|
-
setCoordConstrained
|
|
15339
|
+
}
|
|
15340
|
+
setCoordConstrained(coord) {
|
|
15304
15341
|
assert$6(point.is(coord, 2));
|
|
15305
15342
|
const result = this._applyConstraints(coord, this.coord());
|
|
15306
15343
|
if (result !== false) {
|
|
15307
15344
|
this.state.coord = _.clone(result);
|
|
15308
15345
|
this.draw();
|
|
15309
15346
|
}
|
|
15310
|
-
}
|
|
15311
|
-
|
|
15347
|
+
}
|
|
15348
|
+
|
|
15349
|
+
/**
|
|
15350
|
+
* Add a listener to any event: startMove, constraints, onMove, onMoveEnd,
|
|
15351
|
+
* etc. If a listener is already bound to the given eventName and id, then
|
|
15352
|
+
* it is overwritten by func.
|
|
15353
|
+
*
|
|
15354
|
+
* eventName: the string name of the event to listen to. one of:
|
|
15355
|
+
* "onMoveStart", "onMove", "onMoveEnd", "draw", "remove"
|
|
15356
|
+
*
|
|
15357
|
+
* id: a string id that can be used to remove this event at a later time
|
|
15358
|
+
* note: adding multiple listeners with the same id is undefined behavior
|
|
15359
|
+
*
|
|
15360
|
+
* func: the function to call when the event happens, which is called
|
|
15361
|
+
* with the event's standard parameters [usually (coord, prevCoord) or
|
|
15362
|
+
* (state, prevState)]
|
|
15363
|
+
*/
|
|
15364
|
+
// TODO(benchristel): listen() is duplicated in movable.ts
|
|
15365
|
+
listen(eventName, id, func) {
|
|
15366
|
+
this._listenerMap = this._listenerMap || {};
|
|
15367
|
+
|
|
15368
|
+
// If there's an existing handler, replace it by using its index in
|
|
15369
|
+
// `this.state[eventName]`; otherwise, add this handler to the end
|
|
15370
|
+
const key = getKey(eventName, id);
|
|
15371
|
+
const index = this._listenerMap[key] = this._listenerMap[key] || this.state[eventName].length;
|
|
15372
|
+
this.state[eventName][index] = func;
|
|
15373
|
+
}
|
|
15374
|
+
|
|
15375
|
+
/**
|
|
15376
|
+
* Remove a previously added listener, by the id specified in the
|
|
15377
|
+
* corresponding listen() call
|
|
15378
|
+
*
|
|
15379
|
+
* If the given id has not been registered already, this is a no-op
|
|
15380
|
+
*/
|
|
15381
|
+
// TODO(benchristel): I don't think unlisten is used. Delete it?
|
|
15382
|
+
// TODO(benchristel): unlisten is duplicated in movable.ts
|
|
15383
|
+
unlisten(eventName, id) {
|
|
15384
|
+
this._listenerMap = this._listenerMap || {};
|
|
15385
|
+
const key = getKey(eventName, id);
|
|
15386
|
+
const index = this._listenerMap[key];
|
|
15387
|
+
if (index !== undefined) {
|
|
15388
|
+
// Remove handler from list of event handlers and listenerMap
|
|
15389
|
+
this.state[eventName].splice(index, 1);
|
|
15390
|
+
delete this._listenerMap[key];
|
|
15391
|
+
|
|
15392
|
+
// Re-index existing events: if they occur after `index`, decrement
|
|
15393
|
+
const keys = _.keys(this._listenerMap);
|
|
15394
|
+
_.each(keys, key => {
|
|
15395
|
+
if (getEventName(key) === eventName && this._listenerMap[key] > index) {
|
|
15396
|
+
this._listenerMap[key]--;
|
|
15397
|
+
}
|
|
15398
|
+
}, this);
|
|
15399
|
+
}
|
|
15400
|
+
}
|
|
15401
|
+
grab(coord) {
|
|
15402
|
+
// Provide an explicit touchOffset override, so that we track the user's
|
|
15403
|
+
// finger when a point has been grabbed.
|
|
15404
|
+
this.state.touchOffset = [0, 0];
|
|
15405
|
+
this.movable.grab(coord);
|
|
15406
|
+
this.moveTo(coord);
|
|
15407
|
+
}
|
|
15408
|
+
moveTo(coord) {
|
|
15312
15409
|
// The caller has the option of adding an onMove() method to the
|
|
15313
15410
|
// movablePoint object we return as a sort of event handler
|
|
15314
15411
|
// By returning false from onMove(), the move can be vetoed,
|
|
@@ -15320,8 +15417,11 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15320
15417
|
const result = this._applyConstraints(coord, state.coord, state.onRemove ? {
|
|
15321
15418
|
onOutOfBounds: () => {
|
|
15322
15419
|
this.state.outOfBounds = true;
|
|
15323
|
-
}
|
|
15324
|
-
|
|
15420
|
+
},
|
|
15421
|
+
onSkipRemaining: () => {}
|
|
15422
|
+
} : {
|
|
15423
|
+
onSkipRemaining: () => {}
|
|
15424
|
+
});
|
|
15325
15425
|
if (result === false) {
|
|
15326
15426
|
return;
|
|
15327
15427
|
}
|
|
@@ -15335,49 +15435,98 @@ _.extend(MovablePoint$5.prototype, {
|
|
|
15335
15435
|
this._fireEvent(state.onMove, state.coord, prevCoord);
|
|
15336
15436
|
this.draw();
|
|
15337
15437
|
}
|
|
15338
|
-
}
|
|
15339
|
-
|
|
15340
|
-
|
|
15341
|
-
|
|
15342
|
-
|
|
15343
|
-
|
|
15344
|
-
|
|
15345
|
-
|
|
15346
|
-
|
|
15438
|
+
}
|
|
15439
|
+
remove() {
|
|
15440
|
+
this.state.added = false;
|
|
15441
|
+
this._fireEvent(this.state.remove);
|
|
15442
|
+
if (this.movable) {
|
|
15443
|
+
this.movable.remove();
|
|
15444
|
+
}
|
|
15445
|
+
// TODO(jack): This should really be moved off of
|
|
15446
|
+
// movablePoint.state and only kept on movable.state
|
|
15447
|
+
this.state.mouseTarget = null;
|
|
15448
|
+
}
|
|
15449
|
+
pointSize() {
|
|
15450
|
+
return this.state.pointSize;
|
|
15451
|
+
}
|
|
15452
|
+
static() {
|
|
15453
|
+
return this.state.static;
|
|
15454
|
+
}
|
|
15455
|
+
cursor() {
|
|
15456
|
+
return this.state.cursor;
|
|
15457
|
+
}
|
|
15458
|
+
normalStyle() {
|
|
15459
|
+
return this.state.normalStyle;
|
|
15460
|
+
}
|
|
15461
|
+
highlightStyle() {
|
|
15462
|
+
return this.state.highlightStyle;
|
|
15463
|
+
}
|
|
15464
|
+
shadow() {
|
|
15465
|
+
return this.state.shadow;
|
|
15466
|
+
}
|
|
15467
|
+
tooltip() {
|
|
15468
|
+
return this.state.tooltip;
|
|
15469
|
+
}
|
|
15470
|
+
added() {
|
|
15471
|
+
return this.state.added;
|
|
15472
|
+
}
|
|
15473
|
+
hasMoved() {
|
|
15474
|
+
return this.state.hasMoved;
|
|
15475
|
+
}
|
|
15476
|
+
visibleShape() {
|
|
15477
|
+
return this.state.visibleShape;
|
|
15478
|
+
}
|
|
15479
|
+
outOfBounds() {
|
|
15480
|
+
return this.state.outOfBounds;
|
|
15481
|
+
}
|
|
15482
|
+
mouseTarget() {
|
|
15483
|
+
return this.state.mouseTarget;
|
|
15484
|
+
}
|
|
15485
|
+
touchOffset() {
|
|
15486
|
+
return this.state.touchOffset;
|
|
15487
|
+
}
|
|
15488
|
+
|
|
15489
|
+
/**
|
|
15490
|
+
* Forwarding methods to this.movable:
|
|
15491
|
+
*/
|
|
15492
|
+
isHovering() {
|
|
15493
|
+
return this.movable.isHovering();
|
|
15494
|
+
}
|
|
15495
|
+
isDragging() {
|
|
15496
|
+
return this.movable.isDragging();
|
|
15497
|
+
}
|
|
15498
|
+
|
|
15347
15499
|
// Change z-order to back
|
|
15348
|
-
toBack
|
|
15500
|
+
toBack() {
|
|
15349
15501
|
this.movable.toBack();
|
|
15350
15502
|
if (this.state.visibleShape) {
|
|
15351
15503
|
this.state.visibleShape.toBack();
|
|
15352
15504
|
}
|
|
15353
|
-
}
|
|
15505
|
+
}
|
|
15506
|
+
|
|
15354
15507
|
// Change z-order to front
|
|
15355
|
-
toFront
|
|
15508
|
+
toFront() {
|
|
15356
15509
|
if (this.state.visibleShape) {
|
|
15357
15510
|
this.state.visibleShape.toFront();
|
|
15358
15511
|
}
|
|
15359
15512
|
this.movable.toFront();
|
|
15360
|
-
},
|
|
15361
|
-
/**
|
|
15362
|
-
* Forwarding methods to this.movable:
|
|
15363
|
-
*/
|
|
15364
|
-
isHovering: function () {
|
|
15365
|
-
return this.movable.isHovering();
|
|
15366
|
-
},
|
|
15367
|
-
isDragging: function () {
|
|
15368
|
-
return this.movable.isDragging();
|
|
15369
|
-
},
|
|
15370
|
-
mouseTarget: function () {
|
|
15371
|
-
return this.movable.mouseTarget();
|
|
15372
|
-
},
|
|
15373
|
-
grab: function (coord) {
|
|
15374
|
-
// Provide an explicit touchOffset override, so that we track the user's
|
|
15375
|
-
// finger when a point has been grabbed.
|
|
15376
|
-
this.state.touchOffset = [0, 0];
|
|
15377
|
-
this.movable.grab(coord);
|
|
15378
|
-
this.moveTo(coord);
|
|
15379
15513
|
}
|
|
15380
|
-
}
|
|
15514
|
+
}
|
|
15515
|
+
MovablePoint$5.add = MovablePointOptions.add;
|
|
15516
|
+
MovablePoint$5.modify = MovablePointOptions.modify;
|
|
15517
|
+
MovablePoint$5.draw = MovablePointOptions.draw;
|
|
15518
|
+
MovablePoint$5.remove = MovablePointOptions.remove;
|
|
15519
|
+
MovablePoint$5.onMoveStart = MovablePointOptions.onMoveStart;
|
|
15520
|
+
MovablePoint$5.constraints = MovablePointOptions.constraints;
|
|
15521
|
+
MovablePoint$5.onMove = MovablePointOptions.onMove;
|
|
15522
|
+
MovablePoint$5.onMoveEnd = MovablePointOptions.onMoveEnd;
|
|
15523
|
+
MovablePoint$5.onClick = MovablePointOptions.onClick;
|
|
15524
|
+
function getKey(eventName, id) {
|
|
15525
|
+
return eventName + ":" + id;
|
|
15526
|
+
}
|
|
15527
|
+
function getEventName(key) {
|
|
15528
|
+
return key.split(":")[0];
|
|
15529
|
+
}
|
|
15381
15530
|
|
|
15382
15531
|
/* eslint-disable @babel/no-invalid-this */
|
|
15383
15532
|
function sum(array) {
|
|
@@ -16318,11 +16467,9 @@ class Graphie extends React.Component {
|
|
|
16318
16467
|
});
|
|
16319
16468
|
// Only add the mouselayer if we actually want one.
|
|
16320
16469
|
if (this.props.addMouseLayer) {
|
|
16321
|
-
// @ts-expect-error - TS2339: Property 'addMouseLayer' does not exist on type 'Graphie'.
|
|
16322
16470
|
graphie.addMouseLayer({
|
|
16323
16471
|
onClick: this.props.onClick,
|
|
16324
16472
|
onMouseDown: this.props.onMouseDown,
|
|
16325
|
-
onMouseUp: this.props.onMouseUp,
|
|
16326
16473
|
onMouseMove: this.props.onMouseMove,
|
|
16327
16474
|
setDrawingAreaAvailable: this.props.setDrawingAreaAvailable
|
|
16328
16475
|
});
|
|
@@ -26338,11 +26485,7 @@ class FunctionGrapher extends React.Component {
|
|
|
26338
26485
|
key: i,
|
|
26339
26486
|
coord: coord,
|
|
26340
26487
|
static: this.props.static,
|
|
26341
|
-
constraints: [
|
|
26342
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
26343
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
26344
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
26345
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
26488
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
26346
26489
|
// Always enforce that this is a function
|
|
26347
26490
|
const isFunction = _.all(this._coords(), (otherCoord, j) => {
|
|
26348
26491
|
return i === j || !otherCoord || !number.equal(coord[0], otherCoord[0]);
|
|
@@ -27929,22 +28072,20 @@ class Graph extends React.Component {
|
|
|
27929
28072
|
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
27930
28073
|
// eslint-disable-next-line @babel/no-invalid-this
|
|
27931
28074
|
this.props.onMouseDown(coord);
|
|
27932
|
-
}, this) :
|
|
28075
|
+
}, this) : undefined;
|
|
27933
28076
|
const onMouseOver = $instructionsWrapper ? function () {
|
|
27934
28077
|
$instructionsWrapper && $instructionsWrapper.css("opacity", invisible);
|
|
27935
|
-
} :
|
|
28078
|
+
} : undefined;
|
|
27936
28079
|
const onMouseOut = $instructionsWrapper ? function () {
|
|
27937
28080
|
$instructionsWrapper && $instructionsWrapper.css("opacity", visible);
|
|
27938
|
-
} :
|
|
28081
|
+
} : undefined;
|
|
27939
28082
|
/* eslint-enable indent */
|
|
27940
28083
|
|
|
27941
|
-
// @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
|
|
27942
28084
|
graphie.addMouseLayer({
|
|
27943
28085
|
onClick: this.props.onClick,
|
|
27944
28086
|
onMouseDown: onMouseDown,
|
|
27945
28087
|
onMouseOver: onMouseOver,
|
|
27946
28088
|
onMouseOut: onMouseOut,
|
|
27947
|
-
onMouseUp: this.props.onMouseUp,
|
|
27948
28089
|
onMouseMove: this.props.onMouseMove,
|
|
27949
28090
|
allowScratchpad: true,
|
|
27950
28091
|
setDrawingAreaAvailable: this.props.setDrawingAreaAvailable
|
|
@@ -28299,11 +28440,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28299
28440
|
const points = self.points = _.map(coords, coord => {
|
|
28300
28441
|
return Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28301
28442
|
coord: coord,
|
|
28302
|
-
constraints: [
|
|
28303
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28304
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28305
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28306
|
-
Interactive2.MovablePoint.constraints.snap()],
|
|
28443
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap()],
|
|
28307
28444
|
onMove: () => {
|
|
28308
28445
|
const graph = _.extend({}, self.props.graph, {
|
|
28309
28446
|
coords: _.invoke(points, "coord")
|
|
@@ -28374,11 +28511,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28374
28511
|
let pointA = null;
|
|
28375
28512
|
pointA = this.pointA = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28376
28513
|
coord: coords[0],
|
|
28377
|
-
constraints: [
|
|
28378
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28379
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28380
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28381
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28514
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28382
28515
|
return !pointA ||
|
|
28383
28516
|
// @ts-expect-error - TS2531 - Object is possibly 'null'.
|
|
28384
28517
|
coord[0] !== pointB.coord()[0] &&
|
|
@@ -28394,11 +28527,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28394
28527
|
let pointB = null;
|
|
28395
28528
|
pointB = this.pointB = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28396
28529
|
coord: coords[1],
|
|
28397
|
-
constraints: [
|
|
28398
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28399
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28400
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28401
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28530
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28402
28531
|
return !pointB ||
|
|
28403
28532
|
// @ts-expect-error - TS2531 - Object is possibly 'null'.
|
|
28404
28533
|
coord[0] !== pointA.coord()[0] &&
|
|
@@ -28414,11 +28543,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28414
28543
|
let pointC = null;
|
|
28415
28544
|
pointC = this.pointC = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28416
28545
|
coord: coords[2],
|
|
28417
|
-
constraints: [
|
|
28418
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28419
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28420
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28421
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28546
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28422
28547
|
return !pointC ||
|
|
28423
28548
|
// @ts-expect-error - TS2531 - Object is possibly 'null'.
|
|
28424
28549
|
coord[0] !== pointA.coord()[0] &&
|
|
@@ -28491,22 +28616,14 @@ class InteractiveGraph extends React.Component {
|
|
|
28491
28616
|
let pointA = null;
|
|
28492
28617
|
pointA = this.pointA = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28493
28618
|
coord: coords[0],
|
|
28494
|
-
constraints: [
|
|
28495
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28496
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28497
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28498
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28619
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28499
28620
|
return !pointA || coord[0] !== pointB.coord()[0];
|
|
28500
28621
|
}],
|
|
28501
28622
|
onMove: onMoveHandler
|
|
28502
28623
|
});
|
|
28503
28624
|
const pointB = this.pointB = Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28504
28625
|
coord: coords[1],
|
|
28505
|
-
constraints: [
|
|
28506
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28507
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28508
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28509
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28626
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28510
28627
|
// @ts-expect-error - TS2339 - Property 'coord' does not exist on type 'never'.
|
|
28511
28628
|
return !pointA || coord[0] !== pointA.coord()[0];
|
|
28512
28629
|
}],
|
|
@@ -28590,11 +28707,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28590
28707
|
const coord = segmentCoords[i];
|
|
28591
28708
|
segmentPoints.push(Interactive2.addMaybeMobileMovablePoint(this, {
|
|
28592
28709
|
coord: coord,
|
|
28593
|
-
constraints: [
|
|
28594
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28595
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28596
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28597
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28710
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
28598
28711
|
const otherSegment = segmentPoints[1 - i];
|
|
28599
28712
|
if (!otherSegment) {
|
|
28600
28713
|
// segment hasn't been defined yet
|
|
@@ -28669,11 +28782,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28669
28782
|
let point$1 = null;
|
|
28670
28783
|
point$1 = Interactive2.addMaybeMobileMovablePoint(this, _extends({
|
|
28671
28784
|
coord: coord,
|
|
28672
|
-
constraints: [
|
|
28673
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28674
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
28675
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28676
|
-
Interactive2.MovablePoint.constraints.snap(), function (coord) {
|
|
28785
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), function (coord) {
|
|
28677
28786
|
// TODO(jack): There ought to be a
|
|
28678
28787
|
// MovablePoint.constraints.avoid
|
|
28679
28788
|
// default that lets you do things like this
|
|
@@ -28957,11 +29066,7 @@ class InteractiveGraph extends React.Component {
|
|
|
28957
29066
|
};
|
|
28958
29067
|
const point$1 = Interactive2.addMaybeMobileMovablePoint(this, _extends({
|
|
28959
29068
|
coord: coord,
|
|
28960
|
-
constraints: [
|
|
28961
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28962
|
-
Interactive2.MovablePoint.constraints.bound(), snapToGrid ?
|
|
28963
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
28964
|
-
Interactive2.MovablePoint.constraints.snap() : null, graphConstraint],
|
|
29069
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), snapToGrid ? Interactive2.MovablePoint.constraints.snap() : null, graphConstraint],
|
|
28965
29070
|
onMoveStart: () => {
|
|
28966
29071
|
if (this.isClickToAddPoints()) {
|
|
28967
29072
|
this.setTrashCanVisibility(1);
|
|
@@ -29053,11 +29158,7 @@ class InteractiveGraph extends React.Component {
|
|
|
29053
29158
|
const coord = segment[_i];
|
|
29054
29159
|
points.push(createPoint({
|
|
29055
29160
|
coord: coord,
|
|
29056
|
-
constraints: [
|
|
29057
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
29058
|
-
Interactive2.MovablePoint.constraints.bound(),
|
|
29059
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
29060
|
-
Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
29161
|
+
constraints: [Interactive2.MovablePoint.constraints.bound(), Interactive2.MovablePoint.constraints.snap(), coord => {
|
|
29061
29162
|
const otherPoint = points[1 - _i];
|
|
29062
29163
|
if (!otherPoint) {
|
|
29063
29164
|
// point hasn't been defined yet
|
|
@@ -33792,7 +33893,6 @@ const Measurer = createReactClass({
|
|
|
33792
33893
|
range: range,
|
|
33793
33894
|
scale: scale
|
|
33794
33895
|
});
|
|
33795
|
-
// @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
|
|
33796
33896
|
graphie.addMouseLayer({
|
|
33797
33897
|
allowScratchpad: true,
|
|
33798
33898
|
setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
|
|
@@ -38301,7 +38401,6 @@ class Plotter extends React.Component {
|
|
|
38301
38401
|
scale: c.scale,
|
|
38302
38402
|
isMobile: this.props.apiOptions.isMobile
|
|
38303
38403
|
});
|
|
38304
|
-
// @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
|
|
38305
38404
|
graphie.addMouseLayer({
|
|
38306
38405
|
allowScratchpad: true,
|
|
38307
38406
|
setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
|
|
@@ -38710,7 +38809,6 @@ class Plotter extends React.Component {
|
|
|
38710
38809
|
if (i > 0) {
|
|
38711
38810
|
c.graph.lines[i] = Interactive2.addMovableLine(graphie, {
|
|
38712
38811
|
points: [c.graph.points[i - 1], c.graph.points[i]],
|
|
38713
|
-
// @ts-expect-error - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
|
|
38714
38812
|
constraints: Interactive2.MovablePoint.constraints.fixed(),
|
|
38715
38813
|
normalStyle: {
|
|
38716
38814
|
stroke: KhanColors.BLUE_C,
|
|
@@ -40338,366 +40436,222 @@ var Table$1 = {
|
|
|
40338
40436
|
isLintable: true
|
|
40339
40437
|
};
|
|
40340
40438
|
|
|
40341
|
-
var
|
|
40342
|
-
|
|
40343
|
-
|
|
40344
|
-
|
|
40345
|
-
|
|
40346
|
-
|
|
40347
|
-
|
|
40348
|
-
|
|
40349
|
-
|
|
40350
|
-
|
|
40351
|
-
|
|
40352
|
-
|
|
40353
|
-
|
|
40354
|
-
|
|
40355
|
-
|
|
40356
|
-
|
|
40357
|
-
|
|
40358
|
-
|
|
40359
|
-
|
|
40360
|
-
|
|
40361
|
-
|
|
40362
|
-
|
|
40363
|
-
|
|
40364
|
-
|
|
40365
|
-
|
|
40366
|
-
|
|
40367
|
-
|
|
40368
|
-
|
|
40369
|
-
|
|
40370
|
-
|
|
40371
|
-
|
|
40372
|
-
|
|
40373
|
-
|
|
40374
|
-
|
|
40375
|
-
|
|
40376
|
-
|
|
40377
|
-
|
|
40378
|
-
|
|
40379
|
-
|
|
40380
|
-
|
|
40381
|
-
|
|
40382
|
-
|
|
40383
|
-
|
|
40384
|
-
|
|
40385
|
-
|
|
40386
|
-
|
|
40387
|
-
|
|
40388
|
-
|
|
40389
|
-
|
|
40390
|
-
|
|
40391
|
-
|
|
40392
|
-
|
|
40393
|
-
|
|
40394
|
-
|
|
40395
|
-
|
|
40396
|
-
|
|
40397
|
-
|
|
40398
|
-
|
|
40399
|
-
|
|
40400
|
-
|
|
40401
|
-
|
|
40402
|
-
|
|
40403
|
-
|
|
40404
|
-
|
|
40405
|
-
|
|
40406
|
-
|
|
40407
|
-
|
|
40408
|
-
|
|
40409
|
-
|
|
40410
|
-
|
|
40411
|
-
|
|
40412
|
-
|
|
40413
|
-
|
|
40414
|
-
|
|
40415
|
-
|
|
40416
|
-
|
|
40417
|
-
|
|
40418
|
-
|
|
40419
|
-
|
|
40420
|
-
|
|
40421
|
-
|
|
40422
|
-
|
|
40423
|
-
|
|
40424
|
-
|
|
40425
|
-
|
|
40426
|
-
|
|
40427
|
-
|
|
40428
|
-
|
|
40429
|
-
|
|
40430
|
-
|
|
40431
|
-
|
|
40432
|
-
|
|
40433
|
-
|
|
40434
|
-
|
|
40435
|
-
|
|
40436
|
-
|
|
40437
|
-
|
|
40438
|
-
|
|
40439
|
-
|
|
40440
|
-
|
|
40441
|
-
|
|
40442
|
-
|
|
40443
|
-
|
|
40444
|
-
|
|
40445
|
-
|
|
40446
|
-
|
|
40447
|
-
|
|
40448
|
-
|
|
40449
|
-
|
|
40450
|
-
|
|
40451
|
-
|
|
40452
|
-
|
|
40453
|
-
|
|
40454
|
-
|
|
40455
|
-
|
|
40456
|
-
|
|
40457
|
-
|
|
40458
|
-
|
|
40459
|
-
|
|
40460
|
-
|
|
40461
|
-
|
|
40462
|
-
|
|
40463
|
-
|
|
40464
|
-
|
|
40465
|
-
|
|
40466
|
-
|
|
40467
|
-
|
|
40468
|
-
|
|
40469
|
-
|
|
40470
|
-
|
|
40471
|
-
|
|
40472
|
-
|
|
40473
|
-
|
|
40474
|
-
|
|
40475
|
-
|
|
40476
|
-
|
|
40477
|
-
|
|
40478
|
-
|
|
40479
|
-
|
|
40480
|
-
|
|
40481
|
-
|
|
40482
|
-
|
|
40483
|
-
|
|
40484
|
-
|
|
40485
|
-
|
|
40486
|
-
|
|
40487
|
-
|
|
40488
|
-
|
|
40489
|
-
|
|
40490
|
-
|
|
40491
|
-
|
|
40492
|
-
|
|
40493
|
-
|
|
40494
|
-
|
|
40495
|
-
|
|
40496
|
-
|
|
40497
|
-
|
|
40498
|
-
|
|
40499
|
-
|
|
40500
|
-
|
|
40501
|
-
|
|
40502
|
-
|
|
40503
|
-
|
|
40504
|
-
|
|
40505
|
-
|
|
40506
|
-
|
|
40507
|
-
|
|
40508
|
-
|
|
40509
|
-
|
|
40510
|
-
|
|
40511
|
-
|
|
40512
|
-
|
|
40513
|
-
|
|
40514
|
-
|
|
40515
|
-
|
|
40516
|
-
|
|
40517
|
-
|
|
40518
|
-
|
|
40519
|
-
|
|
40520
|
-
|
|
40521
|
-
|
|
40522
|
-
|
|
40523
|
-
|
|
40524
|
-
|
|
40525
|
-
|
|
40526
|
-
|
|
40527
|
-
|
|
40528
|
-
|
|
40529
|
-
|
|
40530
|
-
|
|
40531
|
-
|
|
40532
|
-
|
|
40533
|
-
|
|
40534
|
-
|
|
40535
|
-
|
|
40536
|
-
|
|
40537
|
-
|
|
40538
|
-
|
|
40539
|
-
|
|
40540
|
-
|
|
40541
|
-
|
|
40542
|
-
|
|
40543
|
-
|
|
40544
|
-
|
|
40545
|
-
|
|
40546
|
-
|
|
40547
|
-
|
|
40548
|
-
|
|
40549
|
-
|
|
40550
|
-
|
|
40551
|
-
|
|
40552
|
-
|
|
40553
|
-
|
|
40554
|
-
|
|
40555
|
-
|
|
40556
|
-
|
|
40557
|
-
lens.prototype.merge = function (lensArr, props) {
|
|
40558
|
-
this._wrapped = lens(this._wrapped).mod(lensArr, function (oldProps) {
|
|
40559
|
-
return merge(oldProps, props);
|
|
40560
|
-
}).freeze();
|
|
40561
|
-
return this;
|
|
40562
|
-
};
|
|
40563
|
-
|
|
40564
|
-
// Lens must have length >= 1 or there would be nothing to return
|
|
40565
|
-
lens.prototype.del = function (lensArr) {
|
|
40566
|
-
var obj = this._wrapped;
|
|
40567
|
-
var ops = dispatch(obj);
|
|
40568
|
-
if (lensArr.length === 1) {
|
|
40569
|
-
this._wrapped = ops.del(obj, lensArr[0]);
|
|
40570
|
-
} else {
|
|
40571
|
-
var monocle = lensArr[0];
|
|
40572
|
-
var shortLens = lensArr.slice(1);
|
|
40573
|
-
var newObj = clone(obj);
|
|
40574
|
-
newObj[monocle] = lens(obj[monocle]).del(shortLens).freeze();
|
|
40575
|
-
this._wrapped = newObj;
|
|
40576
|
-
}
|
|
40577
|
-
return this;
|
|
40578
|
-
};
|
|
40579
|
-
lens.prototype.set = function (lensArr, set) {
|
|
40580
|
-
return this.mod(lensArr, function () {
|
|
40581
|
-
return set;
|
|
40582
|
-
});
|
|
40583
|
-
};
|
|
40584
|
-
module.exports = lens;
|
|
40585
|
-
|
|
40586
|
-
/***/
|
|
40587
|
-
}, /* 2 */
|
|
40588
|
-
/***/function (module, exports) {
|
|
40589
|
-
var get = function get(arr, monocle) {
|
|
40590
|
-
return arr[monocle];
|
|
40591
|
-
};
|
|
40592
|
-
var set = function set(arr, monocle, val) {
|
|
40593
|
-
var newArr = arr.splice();
|
|
40594
|
-
newArr[monocle] = val;
|
|
40595
|
-
return newArr;
|
|
40596
|
-
};
|
|
40597
|
-
var mod = function mod(arr, monocle, f) {
|
|
40598
|
-
var newArr = arr.slice();
|
|
40599
|
-
newArr[monocle] = f(arr[monocle]);
|
|
40600
|
-
return newArr;
|
|
40601
|
-
};
|
|
40602
|
-
var del = function del(arr, monocle) {
|
|
40603
|
-
var newArr = arr.slice();
|
|
40604
|
-
newArr.splice(monocle, 1);
|
|
40605
|
-
return newArr;
|
|
40606
|
-
};
|
|
40607
|
-
|
|
40608
|
-
/*
|
|
40609
|
-
// Lens must point to a member of an array. We'll insert into that array.
|
|
40610
|
-
lens.prototype.insertAt = function(lensArr, toInsert) {
|
|
40611
|
-
var obj = this._wrapped;
|
|
40612
|
-
|
|
40613
|
-
var arrLens = lensArr.slice(0, -1);
|
|
40614
|
-
var arr = lens(obj).get(arrLens).slice(); // slice to copy
|
|
40615
|
-
|
|
40616
|
-
var arrIdx = lensArr[lensArr.length-1];
|
|
40617
|
-
arr.splice(arrIdx, 0, toInsert);
|
|
40618
|
-
return lens(obj).set(arrLens, arr);
|
|
40619
|
-
};
|
|
40620
|
-
|
|
40621
|
-
lens.prototype.insertBefore = lens.prototype.insertAt;
|
|
40622
|
-
lens.prototype.insertAfter = function(lensArr, toInsert) {
|
|
40623
|
-
var newLens = lensArr.slice();
|
|
40624
|
-
newLens[newLens.length-1] += 1;
|
|
40625
|
-
return lens(this._wrapped).insertAt(newLens, toInsert);
|
|
40626
|
-
};
|
|
40627
|
-
*/
|
|
40628
|
-
|
|
40629
|
-
module.exports = {
|
|
40630
|
-
get: get,
|
|
40631
|
-
set: set,
|
|
40632
|
-
mod: mod,
|
|
40633
|
-
del: del
|
|
40634
|
-
};
|
|
40635
|
-
|
|
40636
|
-
/***/
|
|
40637
|
-
}, /* 3 */
|
|
40638
|
-
/***/function (module, exports, __webpack_require__) {
|
|
40639
|
-
var clone = __webpack_require__(0).clone;
|
|
40640
|
-
var get = function get(obj, monocle) {
|
|
40641
|
-
return obj[monocle];
|
|
40642
|
-
};
|
|
40643
|
-
var set = function set(obj, monocle, val) {
|
|
40644
|
-
var newObj = clone(obj);
|
|
40645
|
-
newObj[monocle] = val;
|
|
40646
|
-
return newObj;
|
|
40647
|
-
};
|
|
40648
|
-
var mod = function mod(obj, monocle, f) {
|
|
40649
|
-
var newObj = clone(obj);
|
|
40650
|
-
newObj[monocle] = f(obj[monocle]);
|
|
40651
|
-
return newObj;
|
|
40652
|
-
};
|
|
40653
|
-
var del = function del(obj, monocle) {
|
|
40654
|
-
var newObj = clone(obj);
|
|
40655
|
-
delete newObj[monocle];
|
|
40656
|
-
return newObj;
|
|
40657
|
-
};
|
|
40658
|
-
module.exports = {
|
|
40659
|
-
get: get,
|
|
40660
|
-
set: set,
|
|
40661
|
-
mod: mod,
|
|
40662
|
-
del: del
|
|
40663
|
-
};
|
|
40664
|
-
|
|
40665
|
-
/***/
|
|
40666
|
-
}, /* 4 */
|
|
40667
|
-
/***/function (module, exports) {
|
|
40668
|
-
var get = function get(arr, monocle) {
|
|
40669
|
-
return arr[monocle];
|
|
40670
|
-
};
|
|
40671
|
-
var set = function set(arr, monocle, val) {
|
|
40672
|
-
var newArr = arr.splice();
|
|
40673
|
-
newArr[monocle] = val;
|
|
40674
|
-
return newArr;
|
|
40675
|
-
};
|
|
40676
|
-
var mod = function mod(arr, monocle, f) {
|
|
40677
|
-
var newArr = arr.splice();
|
|
40678
|
-
newArr[monocle] = f(arr[monocle]);
|
|
40679
|
-
return newArr;
|
|
40680
|
-
};
|
|
40681
|
-
var del = function del(arr, monocle) {
|
|
40682
|
-
var newArr = arr.slice();
|
|
40683
|
-
newArr.splice(monocle);
|
|
40684
|
-
return newArr;
|
|
40685
|
-
};
|
|
40686
|
-
module.exports = {
|
|
40687
|
-
get: get,
|
|
40688
|
-
set: set,
|
|
40689
|
-
mod: mod,
|
|
40690
|
-
del: del
|
|
40691
|
-
};
|
|
40692
|
-
|
|
40693
|
-
/***/
|
|
40694
|
-
}
|
|
40695
|
-
/******/])
|
|
40696
|
-
);
|
|
40697
|
-
});
|
|
40698
|
-
} (hubble));
|
|
40699
|
-
|
|
40700
|
-
var lens = /*@__PURE__*/getDefaultExportFromCjs(hubble.exports);
|
|
40439
|
+
var isObject = function isObject(obj) {
|
|
40440
|
+
return obj === Object(obj);
|
|
40441
|
+
};
|
|
40442
|
+
var merge = function merge() {
|
|
40443
|
+
var obj = {};
|
|
40444
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
40445
|
+
var source = arguments[i];
|
|
40446
|
+
if (source) {
|
|
40447
|
+
for (var prop in source) {
|
|
40448
|
+
obj[prop] = source[prop];
|
|
40449
|
+
}
|
|
40450
|
+
}
|
|
40451
|
+
}
|
|
40452
|
+
return obj;
|
|
40453
|
+
};
|
|
40454
|
+
var clone = function clone(obj) {
|
|
40455
|
+
if (!isObject(obj)) {
|
|
40456
|
+
return obj;
|
|
40457
|
+
}
|
|
40458
|
+
return Array.isArray(obj) ? obj.slice() : merge(obj);
|
|
40459
|
+
};
|
|
40460
|
+
|
|
40461
|
+
/* TODO batch *all* mutations
|
|
40462
|
+
* idea: freeze / thaw implementations for all types
|
|
40463
|
+
* lens constructor thaws, freeze delegates to type's freeze
|
|
40464
|
+
*/
|
|
40465
|
+
|
|
40466
|
+
// equivalents, without requiring it
|
|
40467
|
+
// find the implementation to use for a given object
|
|
40468
|
+
var dispatch = function dispatch(x) {
|
|
40469
|
+
if (Array.isArray(x)) {
|
|
40470
|
+
return arr;
|
|
40471
|
+
} else if (isObject(x)) {
|
|
40472
|
+
return obj;
|
|
40473
|
+
} else if (typeof x === "string") {
|
|
40474
|
+
return str;
|
|
40475
|
+
}
|
|
40476
|
+
};
|
|
40477
|
+
|
|
40478
|
+
// This is underscore with a different name
|
|
40479
|
+
var lens = function lens(obj) {
|
|
40480
|
+
if (obj instanceof lens) {
|
|
40481
|
+
return obj;
|
|
40482
|
+
}
|
|
40483
|
+
if (!(this instanceof lens)) {
|
|
40484
|
+
return new lens(obj);
|
|
40485
|
+
}
|
|
40486
|
+
var ops = dispatch(obj);
|
|
40487
|
+
this._wrapped = ops.thaw ? ops.thaw(obj) : obj;
|
|
40488
|
+
};
|
|
40489
|
+
lens.prototype.freeze = function () {
|
|
40490
|
+
var obj = this._wrapped;
|
|
40491
|
+
var ops = dispatch(obj);
|
|
40492
|
+
return ops.freeze ? ops.freeze(obj) : obj;
|
|
40493
|
+
};
|
|
40494
|
+
lens.prototype.zoom = function (lensArr) {
|
|
40495
|
+
if (this._zoomStack === undefined) {
|
|
40496
|
+
this._zoomStack = [];
|
|
40497
|
+
}
|
|
40498
|
+
this._zoomStack.push({
|
|
40499
|
+
zoom: lensArr,
|
|
40500
|
+
wrapped: this._wrapped
|
|
40501
|
+
});
|
|
40502
|
+
this._wrapped = lens(this._wrapped).get(lensArr);
|
|
40503
|
+
return this;
|
|
40504
|
+
};
|
|
40505
|
+
lens.prototype.deZoom = function () {
|
|
40506
|
+
var frame = this._zoomStack.pop();
|
|
40507
|
+
this._wrapped = lens(frame.wrapped).set(frame.zoom, this._wrapped).freeze();
|
|
40508
|
+
return this;
|
|
40509
|
+
};
|
|
40510
|
+
lens.prototype.get = function (lensArr) {
|
|
40511
|
+
var obj = this._wrapped;
|
|
40512
|
+
for (var i = 0; i < lensArr.length; i++) {
|
|
40513
|
+
obj = dispatch(obj).get(obj, lensArr[i]);
|
|
40514
|
+
}
|
|
40515
|
+
return obj;
|
|
40516
|
+
};
|
|
40517
|
+
lens.prototype.mod = function (lensArr, f) {
|
|
40518
|
+
var obj = this._wrapped;
|
|
40519
|
+
var newObj = clone(obj);
|
|
40520
|
+
var ops = dispatch(obj);
|
|
40521
|
+
if (lensArr.length === 0) {
|
|
40522
|
+
this._wrapped = f(this._wrapped);
|
|
40523
|
+
} else if (lensArr.length === 1) {
|
|
40524
|
+
this._wrapped = ops.mod(newObj, lensArr[0], f);
|
|
40525
|
+
} else {
|
|
40526
|
+
var monocle = lensArr[0];
|
|
40527
|
+
var shortLens = lensArr.slice(1);
|
|
40528
|
+
|
|
40529
|
+
// newObj = ops.mod(obj[monocle], shortLens, f);
|
|
40530
|
+
|
|
40531
|
+
newObj[monocle] = lens(obj[monocle]).mod(shortLens, f).freeze();
|
|
40532
|
+
this._wrapped = newObj;
|
|
40533
|
+
}
|
|
40534
|
+
return this;
|
|
40535
|
+
};
|
|
40536
|
+
|
|
40537
|
+
// TODO - move to individual files
|
|
40538
|
+
lens.prototype.merge = function (lensArr, props) {
|
|
40539
|
+
this._wrapped = lens(this._wrapped).mod(lensArr, function (oldProps) {
|
|
40540
|
+
return merge(oldProps, props);
|
|
40541
|
+
}).freeze();
|
|
40542
|
+
return this;
|
|
40543
|
+
};
|
|
40544
|
+
|
|
40545
|
+
// Lens must have length >= 1 or there would be nothing to return
|
|
40546
|
+
lens.prototype.del = function (lensArr) {
|
|
40547
|
+
var obj = this._wrapped;
|
|
40548
|
+
var ops = dispatch(obj);
|
|
40549
|
+
if (lensArr.length === 1) {
|
|
40550
|
+
this._wrapped = ops.del(obj, lensArr[0]);
|
|
40551
|
+
} else {
|
|
40552
|
+
var monocle = lensArr[0];
|
|
40553
|
+
var shortLens = lensArr.slice(1);
|
|
40554
|
+
var newObj = clone(obj);
|
|
40555
|
+
newObj[monocle] = lens(obj[monocle]).del(shortLens).freeze();
|
|
40556
|
+
this._wrapped = newObj;
|
|
40557
|
+
}
|
|
40558
|
+
return this;
|
|
40559
|
+
};
|
|
40560
|
+
lens.prototype.set = function (lensArr, set) {
|
|
40561
|
+
return this.mod(lensArr, function () {
|
|
40562
|
+
return set;
|
|
40563
|
+
});
|
|
40564
|
+
};
|
|
40565
|
+
|
|
40566
|
+
// ARRAY FUNCTIONS
|
|
40567
|
+
|
|
40568
|
+
const arr = {
|
|
40569
|
+
get: function (arr, monocle) {
|
|
40570
|
+
return arr[monocle];
|
|
40571
|
+
},
|
|
40572
|
+
set: function (arr, monocle, val) {
|
|
40573
|
+
var newArr = arr.splice();
|
|
40574
|
+
newArr[monocle] = val;
|
|
40575
|
+
return newArr;
|
|
40576
|
+
},
|
|
40577
|
+
mod: function (arr, monocle, f) {
|
|
40578
|
+
var newArr = arr.slice();
|
|
40579
|
+
newArr[monocle] = f(arr[monocle]);
|
|
40580
|
+
return newArr;
|
|
40581
|
+
},
|
|
40582
|
+
del: function (arr, monocle) {
|
|
40583
|
+
var newArr = arr.slice();
|
|
40584
|
+
newArr.splice(monocle, 1);
|
|
40585
|
+
return newArr;
|
|
40586
|
+
}
|
|
40587
|
+
};
|
|
40588
|
+
|
|
40589
|
+
/*
|
|
40590
|
+
// Lens must point to a member of an array. We'll insert into that array.
|
|
40591
|
+
lens.prototype.insertAt = function(lensArr, toInsert) {
|
|
40592
|
+
var obj = this._wrapped;
|
|
40593
|
+
|
|
40594
|
+
var arrLens = lensArr.slice(0, -1);
|
|
40595
|
+
var arr = lens(obj).get(arrLens).slice(); // slice to copy
|
|
40596
|
+
|
|
40597
|
+
var arrIdx = lensArr[lensArr.length-1];
|
|
40598
|
+
arr.splice(arrIdx, 0, toInsert);
|
|
40599
|
+
return lens(obj).set(arrLens, arr);
|
|
40600
|
+
};
|
|
40601
|
+
|
|
40602
|
+
lens.prototype.insertBefore = lens.prototype.insertAt;
|
|
40603
|
+
lens.prototype.insertAfter = function(lensArr, toInsert) {
|
|
40604
|
+
var newLens = lensArr.slice();
|
|
40605
|
+
newLens[newLens.length-1] += 1;
|
|
40606
|
+
return lens(this._wrapped).insertAt(newLens, toInsert);
|
|
40607
|
+
};
|
|
40608
|
+
*/
|
|
40609
|
+
|
|
40610
|
+
// OBJECT FUNCTIONS
|
|
40611
|
+
|
|
40612
|
+
const obj = {
|
|
40613
|
+
get: function (obj, monocle) {
|
|
40614
|
+
return obj[monocle];
|
|
40615
|
+
},
|
|
40616
|
+
set: function (obj, monocle, val) {
|
|
40617
|
+
var newObj = clone(obj);
|
|
40618
|
+
newObj[monocle] = val;
|
|
40619
|
+
return newObj;
|
|
40620
|
+
},
|
|
40621
|
+
mod: function (obj, monocle, f) {
|
|
40622
|
+
var newObj = clone(obj);
|
|
40623
|
+
newObj[monocle] = f(obj[monocle]);
|
|
40624
|
+
return newObj;
|
|
40625
|
+
},
|
|
40626
|
+
del: function (obj, monocle) {
|
|
40627
|
+
var newObj = clone(obj);
|
|
40628
|
+
delete newObj[monocle];
|
|
40629
|
+
return newObj;
|
|
40630
|
+
}
|
|
40631
|
+
};
|
|
40632
|
+
|
|
40633
|
+
// STRING FUNCTIONS
|
|
40634
|
+
|
|
40635
|
+
const str = {
|
|
40636
|
+
get: function (arr, monocle) {
|
|
40637
|
+
return arr[monocle];
|
|
40638
|
+
},
|
|
40639
|
+
set: function (arr, monocle, val) {
|
|
40640
|
+
var newArr = arr.splice();
|
|
40641
|
+
newArr[monocle] = val;
|
|
40642
|
+
return newArr;
|
|
40643
|
+
},
|
|
40644
|
+
mod: function (arr, monocle, f) {
|
|
40645
|
+
var newArr = arr.splice();
|
|
40646
|
+
newArr[monocle] = f(arr[monocle]);
|
|
40647
|
+
return newArr;
|
|
40648
|
+
},
|
|
40649
|
+
del: function (arr, monocle) {
|
|
40650
|
+
var newArr = arr.slice();
|
|
40651
|
+
newArr.splice(monocle);
|
|
40652
|
+
return newArr;
|
|
40653
|
+
}
|
|
40654
|
+
};
|
|
40701
40655
|
|
|
40702
40656
|
/* eslint-disable eqeqeq, @typescript-eslint/no-unused-vars */
|
|
40703
40657
|
/*
|
|
@@ -41600,7 +41554,7 @@ const init = function init(options) {
|
|
|
41600
41554
|
|
|
41601
41555
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
41602
41556
|
const libName = "@khanacademy/perseus";
|
|
41603
|
-
const libVersion = "19.1.
|
|
41557
|
+
const libVersion = "19.1.8";
|
|
41604
41558
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
41605
41559
|
|
|
41606
41560
|
const apiVersion = {
|