@khanacademy/perseus-core 3.0.5 → 3.2.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/index.js CHANGED
@@ -43,9 +43,2546 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
43
43
  }
44
44
  };
45
45
 
46
+ // Current version.
47
+ var VERSION = '1.13.3';
48
+
49
+ // Establish the root object, `window` (`self`) in the browser, `global`
50
+ // on the server, or `this` in some virtual machines. We use `self`
51
+ // instead of `window` for `WebWorker` support.
52
+ var root = (typeof self == 'object' && self.self === self && self) ||
53
+ (typeof global == 'object' && global.global === global && global) ||
54
+ Function('return this')() ||
55
+ {};
56
+
57
+ // Save bytes in the minified (but not gzipped) version:
58
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype;
59
+ var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
60
+
61
+ // Create quick reference variables for speed access to core prototypes.
62
+ var push = ArrayProto.push,
63
+ slice = ArrayProto.slice,
64
+ toString = ObjProto.toString,
65
+ hasOwnProperty = ObjProto.hasOwnProperty;
66
+
67
+ // Modern feature detection.
68
+ var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
69
+ supportsDataView = typeof DataView !== 'undefined';
70
+
71
+ // All **ECMAScript 5+** native function implementations that we hope to use
72
+ // are declared here.
73
+ var nativeIsArray = Array.isArray,
74
+ nativeKeys = Object.keys,
75
+ nativeCreate = Object.create,
76
+ nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
77
+
78
+ // Create references to these builtin functions because we override them.
79
+ var _isNaN = isNaN,
80
+ _isFinite = isFinite;
81
+
82
+ // Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
83
+ var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
84
+ var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
85
+ 'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
86
+
87
+ // The largest integer that can be represented exactly.
88
+ var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
89
+
90
+ // Some functions take a variable number of arguments, or a few expected
91
+ // arguments at the beginning and then a variable number of values to operate
92
+ // on. This helper accumulates all remaining arguments past the function’s
93
+ // argument length (or an explicit `startIndex`), into an array that becomes
94
+ // the last argument. Similar to ES6’s "rest parameter".
95
+ function restArguments(func, startIndex) {
96
+ startIndex = startIndex == null ? func.length - 1 : +startIndex;
97
+ return function() {
98
+ var length = Math.max(arguments.length - startIndex, 0),
99
+ rest = Array(length),
100
+ index = 0;
101
+ for (; index < length; index++) {
102
+ rest[index] = arguments[index + startIndex];
103
+ }
104
+ switch (startIndex) {
105
+ case 0: return func.call(this, rest);
106
+ case 1: return func.call(this, arguments[0], rest);
107
+ case 2: return func.call(this, arguments[0], arguments[1], rest);
108
+ }
109
+ var args = Array(startIndex + 1);
110
+ for (index = 0; index < startIndex; index++) {
111
+ args[index] = arguments[index];
112
+ }
113
+ args[startIndex] = rest;
114
+ return func.apply(this, args);
115
+ };
116
+ }
117
+
118
+ // Is a given variable an object?
119
+ function isObject(obj) {
120
+ var type = typeof obj;
121
+ return type === 'function' || (type === 'object' && !!obj);
122
+ }
123
+
124
+ // Is a given value equal to null?
125
+ function isNull(obj) {
126
+ return obj === null;
127
+ }
128
+
129
+ // Is a given variable undefined?
130
+ function isUndefined(obj) {
131
+ return obj === void 0;
132
+ }
133
+
134
+ // Is a given value a boolean?
135
+ function isBoolean(obj) {
136
+ return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
137
+ }
138
+
139
+ // Is a given value a DOM element?
140
+ function isElement(obj) {
141
+ return !!(obj && obj.nodeType === 1);
142
+ }
143
+
144
+ // Internal function for creating a `toString`-based type tester.
145
+ function tagTester(name) {
146
+ var tag = '[object ' + name + ']';
147
+ return function(obj) {
148
+ return toString.call(obj) === tag;
149
+ };
150
+ }
151
+
152
+ var isString = tagTester('String');
153
+
154
+ var isNumber = tagTester('Number');
155
+
156
+ var isDate = tagTester('Date');
157
+
158
+ var isRegExp = tagTester('RegExp');
159
+
160
+ var isError = tagTester('Error');
161
+
162
+ var isSymbol = tagTester('Symbol');
163
+
164
+ var isArrayBuffer = tagTester('ArrayBuffer');
165
+
166
+ var isFunction = tagTester('Function');
167
+
168
+ // Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
169
+ // v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
170
+ var nodelist = root.document && root.document.childNodes;
171
+ if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
172
+ isFunction = function(obj) {
173
+ return typeof obj == 'function' || false;
174
+ };
175
+ }
176
+
177
+ var isFunction$1 = isFunction;
178
+
179
+ var hasObjectTag = tagTester('Object');
180
+
181
+ // In IE 10 - Edge 13, `DataView` has string tag `'[object Object]'`.
182
+ // In IE 11, the most common among them, this problem also applies to
183
+ // `Map`, `WeakMap` and `Set`.
184
+ var hasStringTagBug = (
185
+ supportsDataView && hasObjectTag(new DataView(new ArrayBuffer(8)))
186
+ ),
187
+ isIE11 = (typeof Map !== 'undefined' && hasObjectTag(new Map));
188
+
189
+ var isDataView = tagTester('DataView');
190
+
191
+ // In IE 10 - Edge 13, we need a different heuristic
192
+ // to determine whether an object is a `DataView`.
193
+ function ie10IsDataView(obj) {
194
+ return obj != null && isFunction$1(obj.getInt8) && isArrayBuffer(obj.buffer);
195
+ }
196
+
197
+ var isDataView$1 = (hasStringTagBug ? ie10IsDataView : isDataView);
198
+
199
+ // Is a given value an array?
200
+ // Delegates to ECMA5's native `Array.isArray`.
201
+ var isArray = nativeIsArray || tagTester('Array');
202
+
203
+ // Internal function to check whether `key` is an own property name of `obj`.
204
+ function has$1(obj, key) {
205
+ return obj != null && hasOwnProperty.call(obj, key);
206
+ }
207
+
208
+ var isArguments = tagTester('Arguments');
209
+
210
+ // Define a fallback version of the method in browsers (ahem, IE < 9), where
211
+ // there isn't any inspectable "Arguments" type.
212
+ (function() {
213
+ if (!isArguments(arguments)) {
214
+ isArguments = function(obj) {
215
+ return has$1(obj, 'callee');
216
+ };
217
+ }
218
+ }());
219
+
220
+ var isArguments$1 = isArguments;
221
+
222
+ // Is a given object a finite number?
223
+ function isFinite$1(obj) {
224
+ return !isSymbol(obj) && _isFinite(obj) && !isNaN(parseFloat(obj));
225
+ }
226
+
227
+ // Is the given value `NaN`?
228
+ function isNaN$1(obj) {
229
+ return isNumber(obj) && _isNaN(obj);
230
+ }
231
+
232
+ // Predicate-generating function. Often useful outside of Underscore.
233
+ function constant(value) {
234
+ return function() {
235
+ return value;
236
+ };
237
+ }
238
+
239
+ // Common internal logic for `isArrayLike` and `isBufferLike`.
240
+ function createSizePropertyCheck(getSizeProperty) {
241
+ return function(collection) {
242
+ var sizeProperty = getSizeProperty(collection);
243
+ return typeof sizeProperty == 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
244
+ }
245
+ }
246
+
247
+ // Internal helper to generate a function to obtain property `key` from `obj`.
248
+ function shallowProperty(key) {
249
+ return function(obj) {
250
+ return obj == null ? void 0 : obj[key];
251
+ };
252
+ }
253
+
254
+ // Internal helper to obtain the `byteLength` property of an object.
255
+ var getByteLength = shallowProperty('byteLength');
256
+
257
+ // Internal helper to determine whether we should spend extensive checks against
258
+ // `ArrayBuffer` et al.
259
+ var isBufferLike = createSizePropertyCheck(getByteLength);
260
+
261
+ // Is a given value a typed array?
262
+ var typedArrayPattern = /\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;
263
+ function isTypedArray(obj) {
264
+ // `ArrayBuffer.isView` is the most future-proof, so use it when available.
265
+ // Otherwise, fall back on the above regular expression.
266
+ return nativeIsView ? (nativeIsView(obj) && !isDataView$1(obj)) :
267
+ isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
268
+ }
269
+
270
+ var isTypedArray$1 = supportsArrayBuffer ? isTypedArray : constant(false);
271
+
272
+ // Internal helper to obtain the `length` property of an object.
273
+ var getLength = shallowProperty('length');
274
+
275
+ // Internal helper to create a simple lookup structure.
276
+ // `collectNonEnumProps` used to depend on `_.contains`, but this led to
277
+ // circular imports. `emulatedSet` is a one-off solution that only works for
278
+ // arrays of strings.
279
+ function emulatedSet(keys) {
280
+ var hash = {};
281
+ for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
282
+ return {
283
+ contains: function(key) { return hash[key] === true; },
284
+ push: function(key) {
285
+ hash[key] = true;
286
+ return keys.push(key);
287
+ }
288
+ };
289
+ }
290
+
291
+ // Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
292
+ // be iterated by `for key in ...` and thus missed. Extends `keys` in place if
293
+ // needed.
294
+ function collectNonEnumProps(obj, keys) {
295
+ keys = emulatedSet(keys);
296
+ var nonEnumIdx = nonEnumerableProps.length;
297
+ var constructor = obj.constructor;
298
+ var proto = (isFunction$1(constructor) && constructor.prototype) || ObjProto;
299
+
300
+ // Constructor is a special case.
301
+ var prop = 'constructor';
302
+ if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop);
303
+
304
+ while (nonEnumIdx--) {
305
+ prop = nonEnumerableProps[nonEnumIdx];
306
+ if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
307
+ keys.push(prop);
308
+ }
309
+ }
310
+ }
311
+
312
+ // Retrieve the names of an object's own properties.
313
+ // Delegates to **ECMAScript 5**'s native `Object.keys`.
314
+ function keys(obj) {
315
+ if (!isObject(obj)) return [];
316
+ if (nativeKeys) return nativeKeys(obj);
317
+ var keys = [];
318
+ for (var key in obj) if (has$1(obj, key)) keys.push(key);
319
+ // Ahem, IE < 9.
320
+ if (hasEnumBug) collectNonEnumProps(obj, keys);
321
+ return keys;
322
+ }
323
+
324
+ // Is a given array, string, or object empty?
325
+ // An "empty" object has no enumerable own-properties.
326
+ function isEmpty(obj) {
327
+ if (obj == null) return true;
328
+ // Skip the more expensive `toString`-based type checks if `obj` has no
329
+ // `.length`.
330
+ var length = getLength(obj);
331
+ if (typeof length == 'number' && (
332
+ isArray(obj) || isString(obj) || isArguments$1(obj)
333
+ )) return length === 0;
334
+ return getLength(keys(obj)) === 0;
335
+ }
336
+
337
+ // Returns whether an object has a given set of `key:value` pairs.
338
+ function isMatch(object, attrs) {
339
+ var _keys = keys(attrs), length = _keys.length;
340
+ if (object == null) return !length;
341
+ var obj = Object(object);
342
+ for (var i = 0; i < length; i++) {
343
+ var key = _keys[i];
344
+ if (attrs[key] !== obj[key] || !(key in obj)) return false;
345
+ }
346
+ return true;
347
+ }
348
+
349
+ // If Underscore is called as a function, it returns a wrapped object that can
350
+ // be used OO-style. This wrapper holds altered versions of all functions added
351
+ // through `_.mixin`. Wrapped objects may be chained.
352
+ function _$1(obj) {
353
+ if (obj instanceof _$1) return obj;
354
+ if (!(this instanceof _$1)) return new _$1(obj);
355
+ this._wrapped = obj;
356
+ }
357
+
358
+ _$1.VERSION = VERSION;
359
+
360
+ // Extracts the result from a wrapped and chained object.
361
+ _$1.prototype.value = function() {
362
+ return this._wrapped;
363
+ };
364
+
365
+ // Provide unwrapping proxies for some methods used in engine operations
366
+ // such as arithmetic and JSON stringification.
367
+ _$1.prototype.valueOf = _$1.prototype.toJSON = _$1.prototype.value;
368
+
369
+ _$1.prototype.toString = function() {
370
+ return String(this._wrapped);
371
+ };
372
+
373
+ // Internal function to wrap or shallow-copy an ArrayBuffer,
374
+ // typed array or DataView to a new view, reusing the buffer.
375
+ function toBufferView(bufferSource) {
376
+ return new Uint8Array(
377
+ bufferSource.buffer || bufferSource,
378
+ bufferSource.byteOffset || 0,
379
+ getByteLength(bufferSource)
380
+ );
381
+ }
382
+
383
+ // We use this string twice, so give it a name for minification.
384
+ var tagDataView = '[object DataView]';
385
+
386
+ // Internal recursive comparison function for `_.isEqual`.
387
+ function eq(a, b, aStack, bStack) {
388
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
389
+ // See the [Harmony `egal` proposal](https://wiki.ecmascript.org/doku.php?id=harmony:egal).
390
+ if (a === b) return a !== 0 || 1 / a === 1 / b;
391
+ // `null` or `undefined` only equal to itself (strict comparison).
392
+ if (a == null || b == null) return false;
393
+ // `NaN`s are equivalent, but non-reflexive.
394
+ if (a !== a) return b !== b;
395
+ // Exhaust primitive checks
396
+ var type = typeof a;
397
+ if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
398
+ return deepEq(a, b, aStack, bStack);
399
+ }
400
+
401
+ // Internal recursive comparison function for `_.isEqual`.
402
+ function deepEq(a, b, aStack, bStack) {
403
+ // Unwrap any wrapped objects.
404
+ if (a instanceof _$1) a = a._wrapped;
405
+ if (b instanceof _$1) b = b._wrapped;
406
+ // Compare `[[Class]]` names.
407
+ var className = toString.call(a);
408
+ if (className !== toString.call(b)) return false;
409
+ // Work around a bug in IE 10 - Edge 13.
410
+ if (hasStringTagBug && className == '[object Object]' && isDataView$1(a)) {
411
+ if (!isDataView$1(b)) return false;
412
+ className = tagDataView;
413
+ }
414
+ switch (className) {
415
+ // These types are compared by value.
416
+ case '[object RegExp]':
417
+ // RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
418
+ case '[object String]':
419
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
420
+ // equivalent to `new String("5")`.
421
+ return '' + a === '' + b;
422
+ case '[object Number]':
423
+ // `NaN`s are equivalent, but non-reflexive.
424
+ // Object(NaN) is equivalent to NaN.
425
+ if (+a !== +a) return +b !== +b;
426
+ // An `egal` comparison is performed for other numeric values.
427
+ return +a === 0 ? 1 / +a === 1 / b : +a === +b;
428
+ case '[object Date]':
429
+ case '[object Boolean]':
430
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
431
+ // millisecond representations. Note that invalid dates with millisecond representations
432
+ // of `NaN` are not equivalent.
433
+ return +a === +b;
434
+ case '[object Symbol]':
435
+ return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
436
+ case '[object ArrayBuffer]':
437
+ case tagDataView:
438
+ // Coerce to typed array so we can fall through.
439
+ return deepEq(toBufferView(a), toBufferView(b), aStack, bStack);
440
+ }
441
+
442
+ var areArrays = className === '[object Array]';
443
+ if (!areArrays && isTypedArray$1(a)) {
444
+ var byteLength = getByteLength(a);
445
+ if (byteLength !== getByteLength(b)) return false;
446
+ if (a.buffer === b.buffer && a.byteOffset === b.byteOffset) return true;
447
+ areArrays = true;
448
+ }
449
+ if (!areArrays) {
450
+ if (typeof a != 'object' || typeof b != 'object') return false;
451
+
452
+ // Objects with different constructors are not equivalent, but `Object`s or `Array`s
453
+ // from different frames are.
454
+ var aCtor = a.constructor, bCtor = b.constructor;
455
+ if (aCtor !== bCtor && !(isFunction$1(aCtor) && aCtor instanceof aCtor &&
456
+ isFunction$1(bCtor) && bCtor instanceof bCtor)
457
+ && ('constructor' in a && 'constructor' in b)) {
458
+ return false;
459
+ }
460
+ }
461
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
462
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
463
+
464
+ // Initializing stack of traversed objects.
465
+ // It's done here since we only need them for objects and arrays comparison.
466
+ aStack = aStack || [];
467
+ bStack = bStack || [];
468
+ var length = aStack.length;
469
+ while (length--) {
470
+ // Linear search. Performance is inversely proportional to the number of
471
+ // unique nested structures.
472
+ if (aStack[length] === a) return bStack[length] === b;
473
+ }
474
+
475
+ // Add the first object to the stack of traversed objects.
476
+ aStack.push(a);
477
+ bStack.push(b);
478
+
479
+ // Recursively compare objects and arrays.
480
+ if (areArrays) {
481
+ // Compare array lengths to determine if a deep comparison is necessary.
482
+ length = a.length;
483
+ if (length !== b.length) return false;
484
+ // Deep compare the contents, ignoring non-numeric properties.
485
+ while (length--) {
486
+ if (!eq(a[length], b[length], aStack, bStack)) return false;
487
+ }
488
+ } else {
489
+ // Deep compare objects.
490
+ var _keys = keys(a), key;
491
+ length = _keys.length;
492
+ // Ensure that both objects contain the same number of properties before comparing deep equality.
493
+ if (keys(b).length !== length) return false;
494
+ while (length--) {
495
+ // Deep compare each member
496
+ key = _keys[length];
497
+ if (!(has$1(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
498
+ }
499
+ }
500
+ // Remove the first object from the stack of traversed objects.
501
+ aStack.pop();
502
+ bStack.pop();
503
+ return true;
504
+ }
505
+
506
+ // Perform a deep comparison to check if two objects are equal.
507
+ function isEqual(a, b) {
508
+ return eq(a, b);
509
+ }
510
+
511
+ // Retrieve all the enumerable property names of an object.
512
+ function allKeys(obj) {
513
+ if (!isObject(obj)) return [];
514
+ var keys = [];
515
+ for (var key in obj) keys.push(key);
516
+ // Ahem, IE < 9.
517
+ if (hasEnumBug) collectNonEnumProps(obj, keys);
518
+ return keys;
519
+ }
520
+
521
+ // Since the regular `Object.prototype.toString` type tests don't work for
522
+ // some types in IE 11, we use a fingerprinting heuristic instead, based
523
+ // on the methods. It's not great, but it's the best we got.
524
+ // The fingerprint method lists are defined below.
525
+ function ie11fingerprint(methods) {
526
+ var length = getLength(methods);
527
+ return function(obj) {
528
+ if (obj == null) return false;
529
+ // `Map`, `WeakMap` and `Set` have no enumerable keys.
530
+ var keys = allKeys(obj);
531
+ if (getLength(keys)) return false;
532
+ for (var i = 0; i < length; i++) {
533
+ if (!isFunction$1(obj[methods[i]])) return false;
534
+ }
535
+ // If we are testing against `WeakMap`, we need to ensure that
536
+ // `obj` doesn't have a `forEach` method in order to distinguish
537
+ // it from a regular `Map`.
538
+ return methods !== weakMapMethods || !isFunction$1(obj[forEachName]);
539
+ };
540
+ }
541
+
542
+ // In the interest of compact minification, we write
543
+ // each string in the fingerprints only once.
544
+ var forEachName = 'forEach',
545
+ hasName = 'has',
546
+ commonInit = ['clear', 'delete'],
547
+ mapTail = ['get', hasName, 'set'];
548
+
549
+ // `Map`, `WeakMap` and `Set` each have slightly different
550
+ // combinations of the above sublists.
551
+ var mapMethods = commonInit.concat(forEachName, mapTail),
552
+ weakMapMethods = commonInit.concat(mapTail),
553
+ setMethods = ['add'].concat(commonInit, forEachName, hasName);
554
+
555
+ var isMap = isIE11 ? ie11fingerprint(mapMethods) : tagTester('Map');
556
+
557
+ var isWeakMap = isIE11 ? ie11fingerprint(weakMapMethods) : tagTester('WeakMap');
558
+
559
+ var isSet = isIE11 ? ie11fingerprint(setMethods) : tagTester('Set');
560
+
561
+ var isWeakSet = tagTester('WeakSet');
562
+
563
+ // Retrieve the values of an object's properties.
564
+ function values(obj) {
565
+ var _keys = keys(obj);
566
+ var length = _keys.length;
567
+ var values = Array(length);
568
+ for (var i = 0; i < length; i++) {
569
+ values[i] = obj[_keys[i]];
570
+ }
571
+ return values;
572
+ }
573
+
574
+ // Convert an object into a list of `[key, value]` pairs.
575
+ // The opposite of `_.object` with one argument.
576
+ function pairs(obj) {
577
+ var _keys = keys(obj);
578
+ var length = _keys.length;
579
+ var pairs = Array(length);
580
+ for (var i = 0; i < length; i++) {
581
+ pairs[i] = [_keys[i], obj[_keys[i]]];
582
+ }
583
+ return pairs;
584
+ }
585
+
586
+ // Invert the keys and values of an object. The values must be serializable.
587
+ function invert(obj) {
588
+ var result = {};
589
+ var _keys = keys(obj);
590
+ for (var i = 0, length = _keys.length; i < length; i++) {
591
+ result[obj[_keys[i]]] = _keys[i];
592
+ }
593
+ return result;
594
+ }
595
+
596
+ // Return a sorted list of the function names available on the object.
597
+ function functions(obj) {
598
+ var names = [];
599
+ for (var key in obj) {
600
+ if (isFunction$1(obj[key])) names.push(key);
601
+ }
602
+ return names.sort();
603
+ }
604
+
605
+ // An internal function for creating assigner functions.
606
+ function createAssigner(keysFunc, defaults) {
607
+ return function(obj) {
608
+ var length = arguments.length;
609
+ if (defaults) obj = Object(obj);
610
+ if (length < 2 || obj == null) return obj;
611
+ for (var index = 1; index < length; index++) {
612
+ var source = arguments[index],
613
+ keys = keysFunc(source),
614
+ l = keys.length;
615
+ for (var i = 0; i < l; i++) {
616
+ var key = keys[i];
617
+ if (!defaults || obj[key] === void 0) obj[key] = source[key];
618
+ }
619
+ }
620
+ return obj;
621
+ };
622
+ }
623
+
624
+ // Extend a given object with all the properties in passed-in object(s).
625
+ var extend = createAssigner(allKeys);
626
+
627
+ // Assigns a given object with all the own properties in the passed-in
628
+ // object(s).
629
+ // (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
630
+ var extendOwn = createAssigner(keys);
631
+
632
+ // Fill in a given object with default properties.
633
+ var defaults = createAssigner(allKeys, true);
634
+
635
+ // Create a naked function reference for surrogate-prototype-swapping.
636
+ function ctor() {
637
+ return function(){};
638
+ }
639
+
640
+ // An internal function for creating a new object that inherits from another.
641
+ function baseCreate(prototype) {
642
+ if (!isObject(prototype)) return {};
643
+ if (nativeCreate) return nativeCreate(prototype);
644
+ var Ctor = ctor();
645
+ Ctor.prototype = prototype;
646
+ var result = new Ctor;
647
+ Ctor.prototype = null;
648
+ return result;
649
+ }
650
+
651
+ // Creates an object that inherits from the given prototype object.
652
+ // If additional properties are provided then they will be added to the
653
+ // created object.
654
+ function create(prototype, props) {
655
+ var result = baseCreate(prototype);
656
+ if (props) extendOwn(result, props);
657
+ return result;
658
+ }
659
+
660
+ // Create a (shallow-cloned) duplicate of an object.
661
+ function clone(obj) {
662
+ if (!isObject(obj)) return obj;
663
+ return isArray(obj) ? obj.slice() : extend({}, obj);
664
+ }
665
+
666
+ // Invokes `interceptor` with the `obj` and then returns `obj`.
667
+ // The primary purpose of this method is to "tap into" a method chain, in
668
+ // order to perform operations on intermediate results within the chain.
669
+ function tap(obj, interceptor) {
670
+ interceptor(obj);
671
+ return obj;
672
+ }
673
+
674
+ // Normalize a (deep) property `path` to array.
675
+ // Like `_.iteratee`, this function can be customized.
676
+ function toPath$1(path) {
677
+ return isArray(path) ? path : [path];
678
+ }
679
+ _$1.toPath = toPath$1;
680
+
681
+ // Internal wrapper for `_.toPath` to enable minification.
682
+ // Similar to `cb` for `_.iteratee`.
683
+ function toPath(path) {
684
+ return _$1.toPath(path);
685
+ }
686
+
687
+ // Internal function to obtain a nested property in `obj` along `path`.
688
+ function deepGet(obj, path) {
689
+ var length = path.length;
690
+ for (var i = 0; i < length; i++) {
691
+ if (obj == null) return void 0;
692
+ obj = obj[path[i]];
693
+ }
694
+ return length ? obj : void 0;
695
+ }
696
+
697
+ // Get the value of the (deep) property on `path` from `object`.
698
+ // If any property in `path` does not exist or if the value is
699
+ // `undefined`, return `defaultValue` instead.
700
+ // The `path` is normalized through `_.toPath`.
701
+ function get(object, path, defaultValue) {
702
+ var value = deepGet(object, toPath(path));
703
+ return isUndefined(value) ? defaultValue : value;
704
+ }
705
+
706
+ // Shortcut function for checking if an object has a given property directly on
707
+ // itself (in other words, not on a prototype). Unlike the internal `has`
708
+ // function, this public version can also traverse nested properties.
709
+ function has(obj, path) {
710
+ path = toPath(path);
711
+ var length = path.length;
712
+ for (var i = 0; i < length; i++) {
713
+ var key = path[i];
714
+ if (!has$1(obj, key)) return false;
715
+ obj = obj[key];
716
+ }
717
+ return !!length;
718
+ }
719
+
720
+ // Keep the identity function around for default iteratees.
721
+ function identity(value) {
722
+ return value;
723
+ }
724
+
725
+ // Returns a predicate for checking whether an object has a given set of
726
+ // `key:value` pairs.
727
+ function matcher(attrs) {
728
+ attrs = extendOwn({}, attrs);
729
+ return function(obj) {
730
+ return isMatch(obj, attrs);
731
+ };
732
+ }
733
+
734
+ // Creates a function that, when passed an object, will traverse that object’s
735
+ // properties down the given `path`, specified as an array of keys or indices.
736
+ function property(path) {
737
+ path = toPath(path);
738
+ return function(obj) {
739
+ return deepGet(obj, path);
740
+ };
741
+ }
742
+
743
+ // Internal function that returns an efficient (for current engines) version
744
+ // of the passed-in callback, to be repeatedly applied in other Underscore
745
+ // functions.
746
+ function optimizeCb(func, context, argCount) {
747
+ if (context === void 0) return func;
748
+ switch (argCount == null ? 3 : argCount) {
749
+ case 1: return function(value) {
750
+ return func.call(context, value);
751
+ };
752
+ // The 2-argument case is omitted because we’re not using it.
753
+ case 3: return function(value, index, collection) {
754
+ return func.call(context, value, index, collection);
755
+ };
756
+ case 4: return function(accumulator, value, index, collection) {
757
+ return func.call(context, accumulator, value, index, collection);
758
+ };
759
+ }
760
+ return function() {
761
+ return func.apply(context, arguments);
762
+ };
763
+ }
764
+
765
+ // An internal function to generate callbacks that can be applied to each
766
+ // element in a collection, returning the desired result — either `_.identity`,
767
+ // an arbitrary callback, a property matcher, or a property accessor.
768
+ function baseIteratee(value, context, argCount) {
769
+ if (value == null) return identity;
770
+ if (isFunction$1(value)) return optimizeCb(value, context, argCount);
771
+ if (isObject(value) && !isArray(value)) return matcher(value);
772
+ return property(value);
773
+ }
774
+
775
+ // External wrapper for our callback generator. Users may customize
776
+ // `_.iteratee` if they want additional predicate/iteratee shorthand styles.
777
+ // This abstraction hides the internal-only `argCount` argument.
778
+ function iteratee(value, context) {
779
+ return baseIteratee(value, context, Infinity);
780
+ }
781
+ _$1.iteratee = iteratee;
782
+
783
+ // The function we call internally to generate a callback. It invokes
784
+ // `_.iteratee` if overridden, otherwise `baseIteratee`.
785
+ function cb(value, context, argCount) {
786
+ if (_$1.iteratee !== iteratee) return _$1.iteratee(value, context);
787
+ return baseIteratee(value, context, argCount);
788
+ }
789
+
790
+ // Returns the results of applying the `iteratee` to each element of `obj`.
791
+ // In contrast to `_.map` it returns an object.
792
+ function mapObject$1(obj, iteratee, context) {
793
+ iteratee = cb(iteratee, context);
794
+ var _keys = keys(obj),
795
+ length = _keys.length,
796
+ results = {};
797
+ for (var index = 0; index < length; index++) {
798
+ var currentKey = _keys[index];
799
+ results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
800
+ }
801
+ return results;
802
+ }
803
+
804
+ // Predicate-generating function. Often useful outside of Underscore.
805
+ function noop(){}
806
+
807
+ // Generates a function for a given object that returns a given property.
808
+ function propertyOf(obj) {
809
+ if (obj == null) return noop;
810
+ return function(path) {
811
+ return get(obj, path);
812
+ };
813
+ }
814
+
815
+ // Run a function **n** times.
816
+ function times(n, iteratee, context) {
817
+ var accum = Array(Math.max(0, n));
818
+ iteratee = optimizeCb(iteratee, context, 1);
819
+ for (var i = 0; i < n; i++) accum[i] = iteratee(i);
820
+ return accum;
821
+ }
822
+
823
+ // Return a random integer between `min` and `max` (inclusive).
824
+ function random(min, max) {
825
+ if (max == null) {
826
+ max = min;
827
+ min = 0;
828
+ }
829
+ return min + Math.floor(Math.random() * (max - min + 1));
830
+ }
831
+
832
+ // A (possibly faster) way to get the current timestamp as an integer.
833
+ var now = Date.now || function() {
834
+ return new Date().getTime();
835
+ };
836
+
837
+ // Internal helper to generate functions for escaping and unescaping strings
838
+ // to/from HTML interpolation.
839
+ function createEscaper(map) {
840
+ var escaper = function(match) {
841
+ return map[match];
842
+ };
843
+ // Regexes for identifying a key that needs to be escaped.
844
+ var source = '(?:' + keys(map).join('|') + ')';
845
+ var testRegexp = RegExp(source);
846
+ var replaceRegexp = RegExp(source, 'g');
847
+ return function(string) {
848
+ string = string == null ? '' : '' + string;
849
+ return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
850
+ };
851
+ }
852
+
853
+ // Internal list of HTML entities for escaping.
854
+ var escapeMap = {
855
+ '&': '&amp;',
856
+ '<': '&lt;',
857
+ '>': '&gt;',
858
+ '"': '&quot;',
859
+ "'": '&#x27;',
860
+ '`': '&#x60;'
861
+ };
862
+
863
+ // Function for escaping strings to HTML interpolation.
864
+ var escape = createEscaper(escapeMap);
865
+
866
+ // Internal list of HTML entities for unescaping.
867
+ var unescapeMap = invert(escapeMap);
868
+
869
+ // Function for unescaping strings from HTML interpolation.
870
+ var unescape = createEscaper(unescapeMap);
871
+
872
+ // By default, Underscore uses ERB-style template delimiters. Change the
873
+ // following template settings to use alternative delimiters.
874
+ var templateSettings = _$1.templateSettings = {
875
+ evaluate: /<%([\s\S]+?)%>/g,
876
+ interpolate: /<%=([\s\S]+?)%>/g,
877
+ escape: /<%-([\s\S]+?)%>/g
878
+ };
879
+
880
+ // When customizing `_.templateSettings`, if you don't want to define an
881
+ // interpolation, evaluation or escaping regex, we need one that is
882
+ // guaranteed not to match.
883
+ var noMatch = /(.)^/;
884
+
885
+ // Certain characters need to be escaped so that they can be put into a
886
+ // string literal.
887
+ var escapes = {
888
+ "'": "'",
889
+ '\\': '\\',
890
+ '\r': 'r',
891
+ '\n': 'n',
892
+ '\u2028': 'u2028',
893
+ '\u2029': 'u2029'
894
+ };
895
+
896
+ var escapeRegExp = /\\|'|\r|\n|\u2028|\u2029/g;
897
+
898
+ function escapeChar(match) {
899
+ return '\\' + escapes[match];
900
+ }
901
+
902
+ // In order to prevent third-party code injection through
903
+ // `_.templateSettings.variable`, we test it against the following regular
904
+ // expression. It is intentionally a bit more liberal than just matching valid
905
+ // identifiers, but still prevents possible loopholes through defaults or
906
+ // destructuring assignment.
907
+ var bareIdentifier = /^\s*(\w|\$)+\s*$/;
908
+
909
+ // JavaScript micro-templating, similar to John Resig's implementation.
910
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
911
+ // and correctly escapes quotes within interpolated code.
912
+ // NB: `oldSettings` only exists for backwards compatibility.
913
+ function template(text, settings, oldSettings) {
914
+ if (!settings && oldSettings) settings = oldSettings;
915
+ settings = defaults({}, settings, _$1.templateSettings);
916
+
917
+ // Combine delimiters into one regular expression via alternation.
918
+ var matcher = RegExp([
919
+ (settings.escape || noMatch).source,
920
+ (settings.interpolate || noMatch).source,
921
+ (settings.evaluate || noMatch).source
922
+ ].join('|') + '|$', 'g');
923
+
924
+ // Compile the template source, escaping string literals appropriately.
925
+ var index = 0;
926
+ var source = "__p+='";
927
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
928
+ source += text.slice(index, offset).replace(escapeRegExp, escapeChar);
929
+ index = offset + match.length;
930
+
931
+ if (escape) {
932
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
933
+ } else if (interpolate) {
934
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
935
+ } else if (evaluate) {
936
+ source += "';\n" + evaluate + "\n__p+='";
937
+ }
938
+
939
+ // Adobe VMs need the match returned to produce the correct offset.
940
+ return match;
941
+ });
942
+ source += "';\n";
943
+
944
+ var argument = settings.variable;
945
+ if (argument) {
946
+ // Insure against third-party code injection. (CVE-2021-23358)
947
+ if (!bareIdentifier.test(argument)) throw new Error(
948
+ 'variable is not a bare identifier: ' + argument
949
+ );
950
+ } else {
951
+ // If a variable is not specified, place data values in local scope.
952
+ source = 'with(obj||{}){\n' + source + '}\n';
953
+ argument = 'obj';
954
+ }
955
+
956
+ source = "var __t,__p='',__j=Array.prototype.join," +
957
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
958
+ source + 'return __p;\n';
959
+
960
+ var render;
961
+ try {
962
+ render = new Function(argument, '_', source);
963
+ } catch (e) {
964
+ e.source = source;
965
+ throw e;
966
+ }
967
+
968
+ var template = function(data) {
969
+ return render.call(this, data, _$1);
970
+ };
971
+
972
+ // Provide the compiled source as a convenience for precompilation.
973
+ template.source = 'function(' + argument + '){\n' + source + '}';
974
+
975
+ return template;
976
+ }
977
+
978
+ // Traverses the children of `obj` along `path`. If a child is a function, it
979
+ // is invoked with its parent as context. Returns the value of the final
980
+ // child, or `fallback` if any child is undefined.
981
+ function result(obj, path, fallback) {
982
+ path = toPath(path);
983
+ var length = path.length;
984
+ if (!length) {
985
+ return isFunction$1(fallback) ? fallback.call(obj) : fallback;
986
+ }
987
+ for (var i = 0; i < length; i++) {
988
+ var prop = obj == null ? void 0 : obj[path[i]];
989
+ if (prop === void 0) {
990
+ prop = fallback;
991
+ i = length; // Ensure we don't continue iterating.
992
+ }
993
+ obj = isFunction$1(prop) ? prop.call(obj) : prop;
994
+ }
995
+ return obj;
996
+ }
997
+
998
+ // Generate a unique integer id (unique within the entire client session).
999
+ // Useful for temporary DOM ids.
1000
+ var idCounter = 0;
1001
+ function uniqueId(prefix) {
1002
+ var id = ++idCounter + '';
1003
+ return prefix ? prefix + id : id;
1004
+ }
1005
+
1006
+ // Start chaining a wrapped Underscore object.
1007
+ function chain(obj) {
1008
+ var instance = _$1(obj);
1009
+ instance._chain = true;
1010
+ return instance;
1011
+ }
1012
+
1013
+ // Internal function to execute `sourceFunc` bound to `context` with optional
1014
+ // `args`. Determines whether to execute a function as a constructor or as a
1015
+ // normal function.
1016
+ function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
1017
+ if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
1018
+ var self = baseCreate(sourceFunc.prototype);
1019
+ var result = sourceFunc.apply(self, args);
1020
+ if (isObject(result)) return result;
1021
+ return self;
1022
+ }
1023
+
1024
+ // Partially apply a function by creating a version that has had some of its
1025
+ // arguments pre-filled, without changing its dynamic `this` context. `_` acts
1026
+ // as a placeholder by default, allowing any combination of arguments to be
1027
+ // pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
1028
+ var partial = restArguments(function(func, boundArgs) {
1029
+ var placeholder = partial.placeholder;
1030
+ var bound = function() {
1031
+ var position = 0, length = boundArgs.length;
1032
+ var args = Array(length);
1033
+ for (var i = 0; i < length; i++) {
1034
+ args[i] = boundArgs[i] === placeholder ? arguments[position++] : boundArgs[i];
1035
+ }
1036
+ while (position < arguments.length) args.push(arguments[position++]);
1037
+ return executeBound(func, bound, this, this, args);
1038
+ };
1039
+ return bound;
1040
+ });
1041
+
1042
+ partial.placeholder = _$1;
1043
+
1044
+ // Create a function bound to a given object (assigning `this`, and arguments,
1045
+ // optionally).
1046
+ var bind = restArguments(function(func, context, args) {
1047
+ if (!isFunction$1(func)) throw new TypeError('Bind must be called on a function');
1048
+ var bound = restArguments(function(callArgs) {
1049
+ return executeBound(func, bound, context, this, args.concat(callArgs));
1050
+ });
1051
+ return bound;
1052
+ });
1053
+
1054
+ // Internal helper for collection methods to determine whether a collection
1055
+ // should be iterated as an array or as an object.
1056
+ // Related: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
1057
+ // Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
1058
+ var isArrayLike = createSizePropertyCheck(getLength);
1059
+
1060
+ // Internal implementation of a recursive `flatten` function.
1061
+ function flatten$1(input, depth, strict, output) {
1062
+ output = output || [];
1063
+ if (!depth && depth !== 0) {
1064
+ depth = Infinity;
1065
+ } else if (depth <= 0) {
1066
+ return output.concat(input);
1067
+ }
1068
+ var idx = output.length;
1069
+ for (var i = 0, length = getLength(input); i < length; i++) {
1070
+ var value = input[i];
1071
+ if (isArrayLike(value) && (isArray(value) || isArguments$1(value))) {
1072
+ // Flatten current level of array or arguments object.
1073
+ if (depth > 1) {
1074
+ flatten$1(value, depth - 1, strict, output);
1075
+ idx = output.length;
1076
+ } else {
1077
+ var j = 0, len = value.length;
1078
+ while (j < len) output[idx++] = value[j++];
1079
+ }
1080
+ } else if (!strict) {
1081
+ output[idx++] = value;
1082
+ }
1083
+ }
1084
+ return output;
1085
+ }
1086
+
1087
+ // Bind a number of an object's methods to that object. Remaining arguments
1088
+ // are the method names to be bound. Useful for ensuring that all callbacks
1089
+ // defined on an object belong to it.
1090
+ var bindAll = restArguments(function(obj, keys) {
1091
+ keys = flatten$1(keys, false, false);
1092
+ var index = keys.length;
1093
+ if (index < 1) throw new Error('bindAll must be passed function names');
1094
+ while (index--) {
1095
+ var key = keys[index];
1096
+ obj[key] = bind(obj[key], obj);
1097
+ }
1098
+ return obj;
1099
+ });
1100
+
1101
+ // Memoize an expensive function by storing its results.
1102
+ function memoize(func, hasher) {
1103
+ var memoize = function(key) {
1104
+ var cache = memoize.cache;
1105
+ var address = '' + (hasher ? hasher.apply(this, arguments) : key);
1106
+ if (!has$1(cache, address)) cache[address] = func.apply(this, arguments);
1107
+ return cache[address];
1108
+ };
1109
+ memoize.cache = {};
1110
+ return memoize;
1111
+ }
1112
+
1113
+ // Delays a function for the given number of milliseconds, and then calls
1114
+ // it with the arguments supplied.
1115
+ var delay = restArguments(function(func, wait, args) {
1116
+ return setTimeout(function() {
1117
+ return func.apply(null, args);
1118
+ }, wait);
1119
+ });
1120
+
1121
+ // Defers a function, scheduling it to run after the current call stack has
1122
+ // cleared.
1123
+ var defer = partial(delay, _$1, 1);
1124
+
1125
+ // Returns a function, that, when invoked, will only be triggered at most once
1126
+ // during a given window of time. Normally, the throttled function will run
1127
+ // as much as it can, without ever going more than once per `wait` duration;
1128
+ // but if you'd like to disable the execution on the leading edge, pass
1129
+ // `{leading: false}`. To disable execution on the trailing edge, ditto.
1130
+ function throttle(func, wait, options) {
1131
+ var timeout, context, args, result;
1132
+ var previous = 0;
1133
+ if (!options) options = {};
1134
+
1135
+ var later = function() {
1136
+ previous = options.leading === false ? 0 : now();
1137
+ timeout = null;
1138
+ result = func.apply(context, args);
1139
+ if (!timeout) context = args = null;
1140
+ };
1141
+
1142
+ var throttled = function() {
1143
+ var _now = now();
1144
+ if (!previous && options.leading === false) previous = _now;
1145
+ var remaining = wait - (_now - previous);
1146
+ context = this;
1147
+ args = arguments;
1148
+ if (remaining <= 0 || remaining > wait) {
1149
+ if (timeout) {
1150
+ clearTimeout(timeout);
1151
+ timeout = null;
1152
+ }
1153
+ previous = _now;
1154
+ result = func.apply(context, args);
1155
+ if (!timeout) context = args = null;
1156
+ } else if (!timeout && options.trailing !== false) {
1157
+ timeout = setTimeout(later, remaining);
1158
+ }
1159
+ return result;
1160
+ };
1161
+
1162
+ throttled.cancel = function() {
1163
+ clearTimeout(timeout);
1164
+ previous = 0;
1165
+ timeout = context = args = null;
1166
+ };
1167
+
1168
+ return throttled;
1169
+ }
1170
+
1171
+ // When a sequence of calls of the returned function ends, the argument
1172
+ // function is triggered. The end of a sequence is defined by the `wait`
1173
+ // parameter. If `immediate` is passed, the argument function will be
1174
+ // triggered at the beginning of the sequence instead of at the end.
1175
+ function debounce(func, wait, immediate) {
1176
+ var timeout, previous, args, result, context;
1177
+
1178
+ var later = function() {
1179
+ var passed = now() - previous;
1180
+ if (wait > passed) {
1181
+ timeout = setTimeout(later, wait - passed);
1182
+ } else {
1183
+ timeout = null;
1184
+ if (!immediate) result = func.apply(context, args);
1185
+ // This check is needed because `func` can recursively invoke `debounced`.
1186
+ if (!timeout) args = context = null;
1187
+ }
1188
+ };
1189
+
1190
+ var debounced = restArguments(function(_args) {
1191
+ context = this;
1192
+ args = _args;
1193
+ previous = now();
1194
+ if (!timeout) {
1195
+ timeout = setTimeout(later, wait);
1196
+ if (immediate) result = func.apply(context, args);
1197
+ }
1198
+ return result;
1199
+ });
1200
+
1201
+ debounced.cancel = function() {
1202
+ clearTimeout(timeout);
1203
+ timeout = args = context = null;
1204
+ };
1205
+
1206
+ return debounced;
1207
+ }
1208
+
1209
+ // Returns the first function passed as an argument to the second,
1210
+ // allowing you to adjust arguments, run code before and after, and
1211
+ // conditionally execute the original function.
1212
+ function wrap(func, wrapper) {
1213
+ return partial(wrapper, func);
1214
+ }
1215
+
1216
+ // Returns a negated version of the passed-in predicate.
1217
+ function negate(predicate) {
1218
+ return function() {
1219
+ return !predicate.apply(this, arguments);
1220
+ };
1221
+ }
1222
+
1223
+ // Returns a function that is the composition of a list of functions, each
1224
+ // consuming the return value of the function that follows.
1225
+ function compose() {
1226
+ var args = arguments;
1227
+ var start = args.length - 1;
1228
+ return function() {
1229
+ var i = start;
1230
+ var result = args[start].apply(this, arguments);
1231
+ while (i--) result = args[i].call(this, result);
1232
+ return result;
1233
+ };
1234
+ }
1235
+
1236
+ // Returns a function that will only be executed on and after the Nth call.
1237
+ function after(times, func) {
1238
+ return function() {
1239
+ if (--times < 1) {
1240
+ return func.apply(this, arguments);
1241
+ }
1242
+ };
1243
+ }
1244
+
1245
+ // Returns a function that will only be executed up to (but not including) the
1246
+ // Nth call.
1247
+ function before(times, func) {
1248
+ var memo;
1249
+ return function() {
1250
+ if (--times > 0) {
1251
+ memo = func.apply(this, arguments);
1252
+ }
1253
+ if (times <= 1) func = null;
1254
+ return memo;
1255
+ };
1256
+ }
1257
+
1258
+ // Returns a function that will be executed at most one time, no matter how
1259
+ // often you call it. Useful for lazy initialization.
1260
+ var once = partial(before, 2);
1261
+
1262
+ // Returns the first key on an object that passes a truth test.
1263
+ function findKey(obj, predicate, context) {
1264
+ predicate = cb(predicate, context);
1265
+ var _keys = keys(obj), key;
1266
+ for (var i = 0, length = _keys.length; i < length; i++) {
1267
+ key = _keys[i];
1268
+ if (predicate(obj[key], key, obj)) return key;
1269
+ }
1270
+ }
1271
+
1272
+ // Internal function to generate `_.findIndex` and `_.findLastIndex`.
1273
+ function createPredicateIndexFinder(dir) {
1274
+ return function(array, predicate, context) {
1275
+ predicate = cb(predicate, context);
1276
+ var length = getLength(array);
1277
+ var index = dir > 0 ? 0 : length - 1;
1278
+ for (; index >= 0 && index < length; index += dir) {
1279
+ if (predicate(array[index], index, array)) return index;
1280
+ }
1281
+ return -1;
1282
+ };
1283
+ }
1284
+
1285
+ // Returns the first index on an array-like that passes a truth test.
1286
+ var findIndex = createPredicateIndexFinder(1);
1287
+
1288
+ // Returns the last index on an array-like that passes a truth test.
1289
+ var findLastIndex = createPredicateIndexFinder(-1);
1290
+
1291
+ // Use a comparator function to figure out the smallest index at which
1292
+ // an object should be inserted so as to maintain order. Uses binary search.
1293
+ function sortedIndex(array, obj, iteratee, context) {
1294
+ iteratee = cb(iteratee, context, 1);
1295
+ var value = iteratee(obj);
1296
+ var low = 0, high = getLength(array);
1297
+ while (low < high) {
1298
+ var mid = Math.floor((low + high) / 2);
1299
+ if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
1300
+ }
1301
+ return low;
1302
+ }
1303
+
1304
+ // Internal function to generate the `_.indexOf` and `_.lastIndexOf` functions.
1305
+ function createIndexFinder(dir, predicateFind, sortedIndex) {
1306
+ return function(array, item, idx) {
1307
+ var i = 0, length = getLength(array);
1308
+ if (typeof idx == 'number') {
1309
+ if (dir > 0) {
1310
+ i = idx >= 0 ? idx : Math.max(idx + length, i);
1311
+ } else {
1312
+ length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
1313
+ }
1314
+ } else if (sortedIndex && idx && length) {
1315
+ idx = sortedIndex(array, item);
1316
+ return array[idx] === item ? idx : -1;
1317
+ }
1318
+ if (item !== item) {
1319
+ idx = predicateFind(slice.call(array, i, length), isNaN$1);
1320
+ return idx >= 0 ? idx + i : -1;
1321
+ }
1322
+ for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
1323
+ if (array[idx] === item) return idx;
1324
+ }
1325
+ return -1;
1326
+ };
1327
+ }
1328
+
1329
+ // Return the position of the first occurrence of an item in an array,
1330
+ // or -1 if the item is not included in the array.
1331
+ // If the array is large and already in sort order, pass `true`
1332
+ // for **isSorted** to use binary search.
1333
+ var indexOf = createIndexFinder(1, findIndex, sortedIndex);
1334
+
1335
+ // Return the position of the last occurrence of an item in an array,
1336
+ // or -1 if the item is not included in the array.
1337
+ var lastIndexOf = createIndexFinder(-1, findLastIndex);
1338
+
1339
+ // Return the first value which passes a truth test.
1340
+ function find(obj, predicate, context) {
1341
+ var keyFinder = isArrayLike(obj) ? findIndex : findKey;
1342
+ var key = keyFinder(obj, predicate, context);
1343
+ if (key !== void 0 && key !== -1) return obj[key];
1344
+ }
1345
+
1346
+ // Convenience version of a common use case of `_.find`: getting the first
1347
+ // object containing specific `key:value` pairs.
1348
+ function findWhere(obj, attrs) {
1349
+ return find(obj, matcher(attrs));
1350
+ }
1351
+
1352
+ // The cornerstone for collection functions, an `each`
1353
+ // implementation, aka `forEach`.
1354
+ // Handles raw objects in addition to array-likes. Treats all
1355
+ // sparse array-likes as if they were dense.
1356
+ function each(obj, iteratee, context) {
1357
+ iteratee = optimizeCb(iteratee, context);
1358
+ var i, length;
1359
+ if (isArrayLike(obj)) {
1360
+ for (i = 0, length = obj.length; i < length; i++) {
1361
+ iteratee(obj[i], i, obj);
1362
+ }
1363
+ } else {
1364
+ var _keys = keys(obj);
1365
+ for (i = 0, length = _keys.length; i < length; i++) {
1366
+ iteratee(obj[_keys[i]], _keys[i], obj);
1367
+ }
1368
+ }
1369
+ return obj;
1370
+ }
1371
+
1372
+ // Return the results of applying the iteratee to each element.
1373
+ function map(obj, iteratee, context) {
1374
+ iteratee = cb(iteratee, context);
1375
+ var _keys = !isArrayLike(obj) && keys(obj),
1376
+ length = (_keys || obj).length,
1377
+ results = Array(length);
1378
+ for (var index = 0; index < length; index++) {
1379
+ var currentKey = _keys ? _keys[index] : index;
1380
+ results[index] = iteratee(obj[currentKey], currentKey, obj);
1381
+ }
1382
+ return results;
1383
+ }
1384
+
1385
+ // Internal helper to create a reducing function, iterating left or right.
1386
+ function createReduce(dir) {
1387
+ // Wrap code that reassigns argument variables in a separate function than
1388
+ // the one that accesses `arguments.length` to avoid a perf hit. (#1991)
1389
+ var reducer = function(obj, iteratee, memo, initial) {
1390
+ var _keys = !isArrayLike(obj) && keys(obj),
1391
+ length = (_keys || obj).length,
1392
+ index = dir > 0 ? 0 : length - 1;
1393
+ if (!initial) {
1394
+ memo = obj[_keys ? _keys[index] : index];
1395
+ index += dir;
1396
+ }
1397
+ for (; index >= 0 && index < length; index += dir) {
1398
+ var currentKey = _keys ? _keys[index] : index;
1399
+ memo = iteratee(memo, obj[currentKey], currentKey, obj);
1400
+ }
1401
+ return memo;
1402
+ };
1403
+
1404
+ return function(obj, iteratee, memo, context) {
1405
+ var initial = arguments.length >= 3;
1406
+ return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial);
1407
+ };
1408
+ }
1409
+
1410
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
1411
+ // or `foldl`.
1412
+ var reduce = createReduce(1);
1413
+
1414
+ // The right-associative version of reduce, also known as `foldr`.
1415
+ var reduceRight = createReduce(-1);
1416
+
1417
+ // Return all the elements that pass a truth test.
1418
+ function filter(obj, predicate, context) {
1419
+ var results = [];
1420
+ predicate = cb(predicate, context);
1421
+ each(obj, function(value, index, list) {
1422
+ if (predicate(value, index, list)) results.push(value);
1423
+ });
1424
+ return results;
1425
+ }
1426
+
1427
+ // Return all the elements for which a truth test fails.
1428
+ function reject(obj, predicate, context) {
1429
+ return filter(obj, negate(cb(predicate)), context);
1430
+ }
1431
+
1432
+ // Determine whether all of the elements pass a truth test.
1433
+ function every(obj, predicate, context) {
1434
+ predicate = cb(predicate, context);
1435
+ var _keys = !isArrayLike(obj) && keys(obj),
1436
+ length = (_keys || obj).length;
1437
+ for (var index = 0; index < length; index++) {
1438
+ var currentKey = _keys ? _keys[index] : index;
1439
+ if (!predicate(obj[currentKey], currentKey, obj)) return false;
1440
+ }
1441
+ return true;
1442
+ }
1443
+
1444
+ // Determine if at least one element in the object passes a truth test.
1445
+ function some(obj, predicate, context) {
1446
+ predicate = cb(predicate, context);
1447
+ var _keys = !isArrayLike(obj) && keys(obj),
1448
+ length = (_keys || obj).length;
1449
+ for (var index = 0; index < length; index++) {
1450
+ var currentKey = _keys ? _keys[index] : index;
1451
+ if (predicate(obj[currentKey], currentKey, obj)) return true;
1452
+ }
1453
+ return false;
1454
+ }
1455
+
1456
+ // Determine if the array or object contains a given item (using `===`).
1457
+ function contains(obj, item, fromIndex, guard) {
1458
+ if (!isArrayLike(obj)) obj = values(obj);
1459
+ if (typeof fromIndex != 'number' || guard) fromIndex = 0;
1460
+ return indexOf(obj, item, fromIndex) >= 0;
1461
+ }
1462
+
1463
+ // Invoke a method (with arguments) on every item in a collection.
1464
+ var invoke = restArguments(function(obj, path, args) {
1465
+ var contextPath, func;
1466
+ if (isFunction$1(path)) {
1467
+ func = path;
1468
+ } else {
1469
+ path = toPath(path);
1470
+ contextPath = path.slice(0, -1);
1471
+ path = path[path.length - 1];
1472
+ }
1473
+ return map(obj, function(context) {
1474
+ var method = func;
1475
+ if (!method) {
1476
+ if (contextPath && contextPath.length) {
1477
+ context = deepGet(context, contextPath);
1478
+ }
1479
+ if (context == null) return void 0;
1480
+ method = context[path];
1481
+ }
1482
+ return method == null ? method : method.apply(context, args);
1483
+ });
1484
+ });
1485
+
1486
+ // Convenience version of a common use case of `_.map`: fetching a property.
1487
+ function pluck$1(obj, key) {
1488
+ return map(obj, property(key));
1489
+ }
1490
+
1491
+ // Convenience version of a common use case of `_.filter`: selecting only
1492
+ // objects containing specific `key:value` pairs.
1493
+ function where(obj, attrs) {
1494
+ return filter(obj, matcher(attrs));
1495
+ }
1496
+
1497
+ // Return the maximum element (or element-based computation).
1498
+ function max(obj, iteratee, context) {
1499
+ var result = -Infinity, lastComputed = -Infinity,
1500
+ value, computed;
1501
+ if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
1502
+ obj = isArrayLike(obj) ? obj : values(obj);
1503
+ for (var i = 0, length = obj.length; i < length; i++) {
1504
+ value = obj[i];
1505
+ if (value != null && value > result) {
1506
+ result = value;
1507
+ }
1508
+ }
1509
+ } else {
1510
+ iteratee = cb(iteratee, context);
1511
+ each(obj, function(v, index, list) {
1512
+ computed = iteratee(v, index, list);
1513
+ if (computed > lastComputed || (computed === -Infinity && result === -Infinity)) {
1514
+ result = v;
1515
+ lastComputed = computed;
1516
+ }
1517
+ });
1518
+ }
1519
+ return result;
1520
+ }
1521
+
1522
+ // Return the minimum element (or element-based computation).
1523
+ function min(obj, iteratee, context) {
1524
+ var result = Infinity, lastComputed = Infinity,
1525
+ value, computed;
1526
+ if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
1527
+ obj = isArrayLike(obj) ? obj : values(obj);
1528
+ for (var i = 0, length = obj.length; i < length; i++) {
1529
+ value = obj[i];
1530
+ if (value != null && value < result) {
1531
+ result = value;
1532
+ }
1533
+ }
1534
+ } else {
1535
+ iteratee = cb(iteratee, context);
1536
+ each(obj, function(v, index, list) {
1537
+ computed = iteratee(v, index, list);
1538
+ if (computed < lastComputed || (computed === Infinity && result === Infinity)) {
1539
+ result = v;
1540
+ lastComputed = computed;
1541
+ }
1542
+ });
1543
+ }
1544
+ return result;
1545
+ }
1546
+
1547
+ // Safely create a real, live array from anything iterable.
1548
+ var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
1549
+ function toArray(obj) {
1550
+ if (!obj) return [];
1551
+ if (isArray(obj)) return slice.call(obj);
1552
+ if (isString(obj)) {
1553
+ // Keep surrogate pair characters together.
1554
+ return obj.match(reStrSymbol);
1555
+ }
1556
+ if (isArrayLike(obj)) return map(obj, identity);
1557
+ return values(obj);
1558
+ }
1559
+
1560
+ // Sample **n** random values from a collection using the modern version of the
1561
+ // [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
1562
+ // If **n** is not specified, returns a single random element.
1563
+ // The internal `guard` argument allows it to work with `_.map`.
1564
+ function sample(obj, n, guard) {
1565
+ if (n == null || guard) {
1566
+ if (!isArrayLike(obj)) obj = values(obj);
1567
+ return obj[random(obj.length - 1)];
1568
+ }
1569
+ var sample = toArray(obj);
1570
+ var length = getLength(sample);
1571
+ n = Math.max(Math.min(n, length), 0);
1572
+ var last = length - 1;
1573
+ for (var index = 0; index < n; index++) {
1574
+ var rand = random(index, last);
1575
+ var temp = sample[index];
1576
+ sample[index] = sample[rand];
1577
+ sample[rand] = temp;
1578
+ }
1579
+ return sample.slice(0, n);
1580
+ }
1581
+
1582
+ // Shuffle a collection.
1583
+ function shuffle(obj) {
1584
+ return sample(obj, Infinity);
1585
+ }
1586
+
1587
+ // Sort the object's values by a criterion produced by an iteratee.
1588
+ function sortBy(obj, iteratee, context) {
1589
+ var index = 0;
1590
+ iteratee = cb(iteratee, context);
1591
+ return pluck$1(map(obj, function(value, key, list) {
1592
+ return {
1593
+ value: value,
1594
+ index: index++,
1595
+ criteria: iteratee(value, key, list)
1596
+ };
1597
+ }).sort(function(left, right) {
1598
+ var a = left.criteria;
1599
+ var b = right.criteria;
1600
+ if (a !== b) {
1601
+ if (a > b || a === void 0) return 1;
1602
+ if (a < b || b === void 0) return -1;
1603
+ }
1604
+ return left.index - right.index;
1605
+ }), 'value');
1606
+ }
1607
+
1608
+ // An internal function used for aggregate "group by" operations.
1609
+ function group(behavior, partition) {
1610
+ return function(obj, iteratee, context) {
1611
+ var result = partition ? [[], []] : {};
1612
+ iteratee = cb(iteratee, context);
1613
+ each(obj, function(value, index) {
1614
+ var key = iteratee(value, index, obj);
1615
+ behavior(result, value, key);
1616
+ });
1617
+ return result;
1618
+ };
1619
+ }
1620
+
1621
+ // Groups the object's values by a criterion. Pass either a string attribute
1622
+ // to group by, or a function that returns the criterion.
1623
+ var groupBy = group(function(result, value, key) {
1624
+ if (has$1(result, key)) result[key].push(value); else result[key] = [value];
1625
+ });
1626
+
1627
+ // Indexes the object's values by a criterion, similar to `_.groupBy`, but for
1628
+ // when you know that your index values will be unique.
1629
+ var indexBy = group(function(result, value, key) {
1630
+ result[key] = value;
1631
+ });
1632
+
1633
+ // Counts instances of an object that group by a certain criterion. Pass
1634
+ // either a string attribute to count by, or a function that returns the
1635
+ // criterion.
1636
+ var countBy = group(function(result, value, key) {
1637
+ if (has$1(result, key)) result[key]++; else result[key] = 1;
1638
+ });
1639
+
1640
+ // Split a collection into two arrays: one whose elements all pass the given
1641
+ // truth test, and one whose elements all do not pass the truth test.
1642
+ var partition = group(function(result, value, pass) {
1643
+ result[pass ? 0 : 1].push(value);
1644
+ }, true);
1645
+
1646
+ // Return the number of elements in a collection.
1647
+ function size(obj) {
1648
+ if (obj == null) return 0;
1649
+ return isArrayLike(obj) ? obj.length : keys(obj).length;
1650
+ }
1651
+
1652
+ // Internal `_.pick` helper function to determine whether `key` is an enumerable
1653
+ // property name of `obj`.
1654
+ function keyInObj(value, key, obj) {
1655
+ return key in obj;
1656
+ }
1657
+
1658
+ // Return a copy of the object only containing the allowed properties.
1659
+ var pick = restArguments(function(obj, keys) {
1660
+ var result = {}, iteratee = keys[0];
1661
+ if (obj == null) return result;
1662
+ if (isFunction$1(iteratee)) {
1663
+ if (keys.length > 1) iteratee = optimizeCb(iteratee, keys[1]);
1664
+ keys = allKeys(obj);
1665
+ } else {
1666
+ iteratee = keyInObj;
1667
+ keys = flatten$1(keys, false, false);
1668
+ obj = Object(obj);
1669
+ }
1670
+ for (var i = 0, length = keys.length; i < length; i++) {
1671
+ var key = keys[i];
1672
+ var value = obj[key];
1673
+ if (iteratee(value, key, obj)) result[key] = value;
1674
+ }
1675
+ return result;
1676
+ });
1677
+
1678
+ // Return a copy of the object without the disallowed properties.
1679
+ var omit = restArguments(function(obj, keys) {
1680
+ var iteratee = keys[0], context;
1681
+ if (isFunction$1(iteratee)) {
1682
+ iteratee = negate(iteratee);
1683
+ if (keys.length > 1) context = keys[1];
1684
+ } else {
1685
+ keys = map(flatten$1(keys, false, false), String);
1686
+ iteratee = function(value, key) {
1687
+ return !contains(keys, key);
1688
+ };
1689
+ }
1690
+ return pick(obj, iteratee, context);
1691
+ });
1692
+
1693
+ // Returns everything but the last entry of the array. Especially useful on
1694
+ // the arguments object. Passing **n** will return all the values in
1695
+ // the array, excluding the last N.
1696
+ function initial(array, n, guard) {
1697
+ return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
1698
+ }
1699
+
1700
+ // Get the first element of an array. Passing **n** will return the first N
1701
+ // values in the array. The **guard** check allows it to work with `_.map`.
1702
+ function first(array, n, guard) {
1703
+ if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
1704
+ if (n == null || guard) return array[0];
1705
+ return initial(array, array.length - n);
1706
+ }
1707
+
1708
+ // Returns everything but the first entry of the `array`. Especially useful on
1709
+ // the `arguments` object. Passing an **n** will return the rest N values in the
1710
+ // `array`.
1711
+ function rest(array, n, guard) {
1712
+ return slice.call(array, n == null || guard ? 1 : n);
1713
+ }
1714
+
1715
+ // Get the last element of an array. Passing **n** will return the last N
1716
+ // values in the array.
1717
+ function last(array, n, guard) {
1718
+ if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
1719
+ if (n == null || guard) return array[array.length - 1];
1720
+ return rest(array, Math.max(0, array.length - n));
1721
+ }
1722
+
1723
+ // Trim out all falsy values from an array.
1724
+ function compact(array) {
1725
+ return filter(array, Boolean);
1726
+ }
1727
+
1728
+ // Flatten out an array, either recursively (by default), or up to `depth`.
1729
+ // Passing `true` or `false` as `depth` means `1` or `Infinity`, respectively.
1730
+ function flatten(array, depth) {
1731
+ return flatten$1(array, depth, false);
1732
+ }
1733
+
1734
+ // Take the difference between one array and a number of other arrays.
1735
+ // Only the elements present in just the first array will remain.
1736
+ var difference = restArguments(function(array, rest) {
1737
+ rest = flatten$1(rest, true, true);
1738
+ return filter(array, function(value){
1739
+ return !contains(rest, value);
1740
+ });
1741
+ });
1742
+
1743
+ // Return a version of the array that does not contain the specified value(s).
1744
+ var without = restArguments(function(array, otherArrays) {
1745
+ return difference(array, otherArrays);
1746
+ });
1747
+
1748
+ // Produce a duplicate-free version of the array. If the array has already
1749
+ // been sorted, you have the option of using a faster algorithm.
1750
+ // The faster algorithm will not work with an iteratee if the iteratee
1751
+ // is not a one-to-one function, so providing an iteratee will disable
1752
+ // the faster algorithm.
1753
+ function uniq(array, isSorted, iteratee, context) {
1754
+ if (!isBoolean(isSorted)) {
1755
+ context = iteratee;
1756
+ iteratee = isSorted;
1757
+ isSorted = false;
1758
+ }
1759
+ if (iteratee != null) iteratee = cb(iteratee, context);
1760
+ var result = [];
1761
+ var seen = [];
1762
+ for (var i = 0, length = getLength(array); i < length; i++) {
1763
+ var value = array[i],
1764
+ computed = iteratee ? iteratee(value, i, array) : value;
1765
+ if (isSorted && !iteratee) {
1766
+ if (!i || seen !== computed) result.push(value);
1767
+ seen = computed;
1768
+ } else if (iteratee) {
1769
+ if (!contains(seen, computed)) {
1770
+ seen.push(computed);
1771
+ result.push(value);
1772
+ }
1773
+ } else if (!contains(result, value)) {
1774
+ result.push(value);
1775
+ }
1776
+ }
1777
+ return result;
1778
+ }
1779
+
1780
+ // Produce an array that contains the union: each distinct element from all of
1781
+ // the passed-in arrays.
1782
+ var union = restArguments(function(arrays) {
1783
+ return uniq(flatten$1(arrays, true, true));
1784
+ });
1785
+
1786
+ // Produce an array that contains every item shared between all the
1787
+ // passed-in arrays.
1788
+ function intersection(array) {
1789
+ var result = [];
1790
+ var argsLength = arguments.length;
1791
+ for (var i = 0, length = getLength(array); i < length; i++) {
1792
+ var item = array[i];
1793
+ if (contains(result, item)) continue;
1794
+ var j;
1795
+ for (j = 1; j < argsLength; j++) {
1796
+ if (!contains(arguments[j], item)) break;
1797
+ }
1798
+ if (j === argsLength) result.push(item);
1799
+ }
1800
+ return result;
1801
+ }
1802
+
1803
+ // Complement of zip. Unzip accepts an array of arrays and groups
1804
+ // each array's elements on shared indices.
1805
+ function unzip(array) {
1806
+ var length = (array && max(array, getLength).length) || 0;
1807
+ var result = Array(length);
1808
+
1809
+ for (var index = 0; index < length; index++) {
1810
+ result[index] = pluck$1(array, index);
1811
+ }
1812
+ return result;
1813
+ }
1814
+
1815
+ // Zip together multiple lists into a single array -- elements that share
1816
+ // an index go together.
1817
+ var zip = restArguments(unzip);
1818
+
1819
+ // Converts lists into objects. Pass either a single array of `[key, value]`
1820
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
1821
+ // the corresponding values. Passing by pairs is the reverse of `_.pairs`.
1822
+ function object(list, values) {
1823
+ var result = {};
1824
+ for (var i = 0, length = getLength(list); i < length; i++) {
1825
+ if (values) {
1826
+ result[list[i]] = values[i];
1827
+ } else {
1828
+ result[list[i][0]] = list[i][1];
1829
+ }
1830
+ }
1831
+ return result;
1832
+ }
1833
+
1834
+ // Generate an integer Array containing an arithmetic progression. A port of
1835
+ // the native Python `range()` function. See
1836
+ // [the Python documentation](https://docs.python.org/library/functions.html#range).
1837
+ function range(start, stop, step) {
1838
+ if (stop == null) {
1839
+ stop = start || 0;
1840
+ start = 0;
1841
+ }
1842
+ if (!step) {
1843
+ step = stop < start ? -1 : 1;
1844
+ }
1845
+
1846
+ var length = Math.max(Math.ceil((stop - start) / step), 0);
1847
+ var range = Array(length);
1848
+
1849
+ for (var idx = 0; idx < length; idx++, start += step) {
1850
+ range[idx] = start;
1851
+ }
1852
+
1853
+ return range;
1854
+ }
1855
+
1856
+ // Chunk a single array into multiple arrays, each containing `count` or fewer
1857
+ // items.
1858
+ function chunk(array, count) {
1859
+ if (count == null || count < 1) return [];
1860
+ var result = [];
1861
+ var i = 0, length = array.length;
1862
+ while (i < length) {
1863
+ result.push(slice.call(array, i, i += count));
1864
+ }
1865
+ return result;
1866
+ }
1867
+
1868
+ // Helper function to continue chaining intermediate results.
1869
+ function chainResult(instance, obj) {
1870
+ return instance._chain ? _$1(obj).chain() : obj;
1871
+ }
1872
+
1873
+ // Add your own custom functions to the Underscore object.
1874
+ function mixin(obj) {
1875
+ each(functions(obj), function(name) {
1876
+ var func = _$1[name] = obj[name];
1877
+ _$1.prototype[name] = function() {
1878
+ var args = [this._wrapped];
1879
+ push.apply(args, arguments);
1880
+ return chainResult(this, func.apply(_$1, args));
1881
+ };
1882
+ });
1883
+ return _$1;
1884
+ }
1885
+
1886
+ // Add all mutator `Array` functions to the wrapper.
1887
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1888
+ var method = ArrayProto[name];
1889
+ _$1.prototype[name] = function() {
1890
+ var obj = this._wrapped;
1891
+ if (obj != null) {
1892
+ method.apply(obj, arguments);
1893
+ if ((name === 'shift' || name === 'splice') && obj.length === 0) {
1894
+ delete obj[0];
1895
+ }
1896
+ }
1897
+ return chainResult(this, obj);
1898
+ };
1899
+ });
1900
+
1901
+ // Add all accessor `Array` functions to the wrapper.
1902
+ each(['concat', 'join', 'slice'], function(name) {
1903
+ var method = ArrayProto[name];
1904
+ _$1.prototype[name] = function() {
1905
+ var obj = this._wrapped;
1906
+ if (obj != null) obj = method.apply(obj, arguments);
1907
+ return chainResult(this, obj);
1908
+ };
1909
+ });
1910
+
1911
+ // Named Exports
1912
+
1913
+ var allExports = /*#__PURE__*/Object.freeze({
1914
+ __proto__: null,
1915
+ VERSION: VERSION,
1916
+ restArguments: restArguments,
1917
+ isObject: isObject,
1918
+ isNull: isNull,
1919
+ isUndefined: isUndefined,
1920
+ isBoolean: isBoolean,
1921
+ isElement: isElement,
1922
+ isString: isString,
1923
+ isNumber: isNumber,
1924
+ isDate: isDate,
1925
+ isRegExp: isRegExp,
1926
+ isError: isError,
1927
+ isSymbol: isSymbol,
1928
+ isArrayBuffer: isArrayBuffer,
1929
+ isDataView: isDataView$1,
1930
+ isArray: isArray,
1931
+ isFunction: isFunction$1,
1932
+ isArguments: isArguments$1,
1933
+ isFinite: isFinite$1,
1934
+ isNaN: isNaN$1,
1935
+ isTypedArray: isTypedArray$1,
1936
+ isEmpty: isEmpty,
1937
+ isMatch: isMatch,
1938
+ isEqual: isEqual,
1939
+ isMap: isMap,
1940
+ isWeakMap: isWeakMap,
1941
+ isSet: isSet,
1942
+ isWeakSet: isWeakSet,
1943
+ keys: keys,
1944
+ allKeys: allKeys,
1945
+ values: values,
1946
+ pairs: pairs,
1947
+ invert: invert,
1948
+ functions: functions,
1949
+ methods: functions,
1950
+ extend: extend,
1951
+ extendOwn: extendOwn,
1952
+ assign: extendOwn,
1953
+ defaults: defaults,
1954
+ create: create,
1955
+ clone: clone,
1956
+ tap: tap,
1957
+ get: get,
1958
+ has: has,
1959
+ mapObject: mapObject$1,
1960
+ identity: identity,
1961
+ constant: constant,
1962
+ noop: noop,
1963
+ toPath: toPath$1,
1964
+ property: property,
1965
+ propertyOf: propertyOf,
1966
+ matcher: matcher,
1967
+ matches: matcher,
1968
+ times: times,
1969
+ random: random,
1970
+ now: now,
1971
+ escape: escape,
1972
+ unescape: unescape,
1973
+ templateSettings: templateSettings,
1974
+ template: template,
1975
+ result: result,
1976
+ uniqueId: uniqueId,
1977
+ chain: chain,
1978
+ iteratee: iteratee,
1979
+ partial: partial,
1980
+ bind: bind,
1981
+ bindAll: bindAll,
1982
+ memoize: memoize,
1983
+ delay: delay,
1984
+ defer: defer,
1985
+ throttle: throttle,
1986
+ debounce: debounce,
1987
+ wrap: wrap,
1988
+ negate: negate,
1989
+ compose: compose,
1990
+ after: after,
1991
+ before: before,
1992
+ once: once,
1993
+ findKey: findKey,
1994
+ findIndex: findIndex,
1995
+ findLastIndex: findLastIndex,
1996
+ sortedIndex: sortedIndex,
1997
+ indexOf: indexOf,
1998
+ lastIndexOf: lastIndexOf,
1999
+ find: find,
2000
+ detect: find,
2001
+ findWhere: findWhere,
2002
+ each: each,
2003
+ forEach: each,
2004
+ map: map,
2005
+ collect: map,
2006
+ reduce: reduce,
2007
+ foldl: reduce,
2008
+ inject: reduce,
2009
+ reduceRight: reduceRight,
2010
+ foldr: reduceRight,
2011
+ filter: filter,
2012
+ select: filter,
2013
+ reject: reject,
2014
+ every: every,
2015
+ all: every,
2016
+ some: some,
2017
+ any: some,
2018
+ contains: contains,
2019
+ includes: contains,
2020
+ include: contains,
2021
+ invoke: invoke,
2022
+ pluck: pluck$1,
2023
+ where: where,
2024
+ max: max,
2025
+ min: min,
2026
+ shuffle: shuffle,
2027
+ sample: sample,
2028
+ sortBy: sortBy,
2029
+ groupBy: groupBy,
2030
+ indexBy: indexBy,
2031
+ countBy: countBy,
2032
+ partition: partition,
2033
+ toArray: toArray,
2034
+ size: size,
2035
+ pick: pick,
2036
+ omit: omit,
2037
+ first: first,
2038
+ head: first,
2039
+ take: first,
2040
+ initial: initial,
2041
+ last: last,
2042
+ rest: rest,
2043
+ tail: rest,
2044
+ drop: rest,
2045
+ compact: compact,
2046
+ flatten: flatten,
2047
+ without: without,
2048
+ uniq: uniq,
2049
+ unique: uniq,
2050
+ union: union,
2051
+ intersection: intersection,
2052
+ difference: difference,
2053
+ unzip: unzip,
2054
+ transpose: unzip,
2055
+ zip: zip,
2056
+ object: object,
2057
+ range: range,
2058
+ chunk: chunk,
2059
+ mixin: mixin,
2060
+ 'default': _$1
2061
+ });
2062
+
2063
+ // Default Export
2064
+
2065
+ // Add all of the Underscore functions to the wrapper object.
2066
+ var _ = mixin(allExports);
2067
+ // Legacy Node.js API.
2068
+ _._ = _;
2069
+
2070
+ function getMatrixSize(matrix) {
2071
+ const matrixSize = [1, 1];
2072
+
2073
+ // We need to find the widest row and tallest column to get the correct
2074
+ // matrix size.
2075
+ _(matrix).each((matrixRow, row) => {
2076
+ let rowWidth = 0;
2077
+ _(matrixRow).each((matrixCol, col) => {
2078
+ if (matrixCol != null && matrixCol.toString().length) {
2079
+ rowWidth = col + 1;
2080
+ }
2081
+ });
2082
+
2083
+ // Matrix width:
2084
+ matrixSize[1] = Math.max(matrixSize[1], rowWidth);
2085
+
2086
+ // Matrix height:
2087
+ if (rowWidth > 0) {
2088
+ matrixSize[0] = Math.max(matrixSize[0], row + 1);
2089
+ }
2090
+ });
2091
+ return matrixSize;
2092
+ }
2093
+
2094
+ /**
2095
+ * Get the character used for separating decimals.
2096
+ */
2097
+ const getDecimalSeparator = locale => {
2098
+ switch (locale) {
2099
+ // TODO(somewhatabstract): Remove this when Chrome supports the `ka`
2100
+ // locale properly.
2101
+ // https://github.com/formatjs/formatjs/issues/1526#issuecomment-559891201
2102
+ //
2103
+ // Supported locales in Chrome:
2104
+ // https://source.chromium.org/chromium/chromium/src/+/master:third_party/icu/scripts/chrome_ui_languages.list
2105
+ case "ka":
2106
+ return ",";
2107
+ default:
2108
+ const numberWithDecimalSeparator = 1.1;
2109
+ // TODO(FEI-3647): Update to use .formatToParts() once we no longer have to
2110
+ // support Safari 12.
2111
+ const match = new Intl.NumberFormat(locale).format(numberWithDecimalSeparator)
2112
+ // 0x661 is ARABIC-INDIC DIGIT ONE
2113
+ // 0x6F1 is EXTENDED ARABIC-INDIC DIGIT ONE
2114
+ .match(/[^\d\u0661\u06F1]/);
2115
+ return match?.[0] ?? ".";
2116
+ }
2117
+ };
2118
+
2119
+ /**
2120
+ * APPROXIMATE equality on numbers and primitives.
2121
+ */
2122
+ function approximateEqual(x, y) {
2123
+ if (typeof x === "number" && typeof y === "number") {
2124
+ return Math.abs(x - y) < 1e-9;
2125
+ }
2126
+ return x === y;
2127
+ }
2128
+
2129
+ /**
2130
+ * Deep APPROXIMATE equality on primitives, numbers, arrays, and objects.
2131
+ * Recursive.
2132
+ */
2133
+ function approximateDeepEqual(x, y) {
2134
+ if (Array.isArray(x) && Array.isArray(y)) {
2135
+ if (x.length !== y.length) {
2136
+ return false;
2137
+ }
2138
+ for (let i = 0; i < x.length; i++) {
2139
+ if (!approximateDeepEqual(x[i], y[i])) {
2140
+ return false;
2141
+ }
2142
+ }
2143
+ return true;
2144
+ }
2145
+ if (Array.isArray(x) || Array.isArray(y)) {
2146
+ return false;
2147
+ }
2148
+ if (typeof x === "function" && typeof y === "function") {
2149
+ return approximateEqual(x, y);
2150
+ }
2151
+ if (typeof x === "function" || typeof y === "function") {
2152
+ return false;
2153
+ }
2154
+ if (typeof x === "object" && typeof y === "object" && !!x && !!y) {
2155
+ return x === y || _.all(x, function (v, k) {
2156
+ // @ts-expect-error - TS2536 - Type 'CollectionKey<T>' cannot be used to index type 'T'.
2157
+ return approximateDeepEqual(y[k], v);
2158
+ }) && _.all(y, function (v, k) {
2159
+ // @ts-expect-error - TS2536 - Type 'CollectionKey<T>' cannot be used to index type 'T'.
2160
+ return approximateDeepEqual(x[k], v);
2161
+ });
2162
+ }
2163
+ if (typeof x === "object" && !!x || typeof y === "object" && !!y) {
2164
+ return false;
2165
+ }
2166
+ return approximateEqual(x, y);
2167
+ }
2168
+
2169
+ // TODO(benchristel): in the future, we may want to make deepClone work for
2170
+ // Record<string, Cloneable> as well. Currently, it only does arrays.
2171
+
2172
+ function deepClone(obj) {
2173
+ if (Array.isArray(obj)) {
2174
+ return obj.map(deepClone);
2175
+ }
2176
+ return obj;
2177
+ }
2178
+
2179
+ const MOVABLES = {
2180
+ PLOT: "PLOT",
2181
+ PARABOLA: "PARABOLA",
2182
+ SINUSOID: "SINUSOID"
2183
+ };
2184
+
2185
+ // TODO(charlie): These really need to go into a utility file as they're being
2186
+ // used by both interactive-graph and now grapher.
2187
+ function canonicalSineCoefficients(coeffs) {
2188
+ // For a curve of the form f(x) = a * Sin(b * x - c) + d,
2189
+ // this function ensures that a, b > 0, and c is its
2190
+ // smallest possible positive value.
2191
+ let amplitude = coeffs[0];
2192
+ let angularFrequency = coeffs[1];
2193
+ let phase = coeffs[2];
2194
+ const verticalOffset = coeffs[3];
2195
+
2196
+ // Guarantee a > 0
2197
+ if (amplitude < 0) {
2198
+ amplitude *= -1;
2199
+ angularFrequency *= -1;
2200
+ phase *= -1;
2201
+ }
2202
+ const period = 2 * Math.PI;
2203
+ // Guarantee b > 0
2204
+ if (angularFrequency < 0) {
2205
+ angularFrequency *= -1;
2206
+ phase *= -1;
2207
+ phase += period / 2;
2208
+ }
2209
+
2210
+ // Guarantee c is smallest possible positive value
2211
+ while (phase > 0) {
2212
+ phase -= period;
2213
+ }
2214
+ while (phase < 0) {
2215
+ phase += period;
2216
+ }
2217
+ return [amplitude, angularFrequency, phase, verticalOffset];
2218
+ }
2219
+ function canonicalTangentCoefficients(coeffs) {
2220
+ // For a curve of the form f(x) = a * Tan(b * x - c) + d,
2221
+ // this function ensures that a, b > 0, and c is its
2222
+ // smallest possible positive value.
2223
+ let amplitude = coeffs[0];
2224
+ let angularFrequency = coeffs[1];
2225
+ let phase = coeffs[2];
2226
+ const verticalOffset = coeffs[3];
2227
+
2228
+ // Guarantee a > 0
2229
+ if (amplitude < 0) {
2230
+ amplitude *= -1;
2231
+ angularFrequency *= -1;
2232
+ phase *= -1;
2233
+ }
2234
+ const period = Math.PI;
2235
+ // Guarantee b > 0
2236
+ if (angularFrequency < 0) {
2237
+ angularFrequency *= -1;
2238
+ phase *= -1;
2239
+ phase += period / 2;
2240
+ }
2241
+
2242
+ // Guarantee c is smallest possible positive value
2243
+ while (phase > 0) {
2244
+ phase -= period;
2245
+ }
2246
+ while (phase < 0) {
2247
+ phase += period;
2248
+ }
2249
+ return [amplitude, angularFrequency, phase, verticalOffset];
2250
+ }
2251
+ const PlotDefaults = {
2252
+ areEqual: function (coeffs1, coeffs2) {
2253
+ return approximateDeepEqual(coeffs1, coeffs2);
2254
+ },
2255
+ movable: MOVABLES.PLOT,
2256
+ getPropsForCoeffs: function (coeffs) {
2257
+ return {
2258
+ // @ts-expect-error - TS2339 - Property 'getFunctionForCoeffs' does not exist on type '{ readonly areEqual: (coeffs1: any, coeffs2: any) => boolean; readonly Movable: any; readonly getPropsForCoeffs: (coeffs: any) => any; }'.
2259
+ fn: _.partial(this.getFunctionForCoeffs, coeffs)
2260
+ };
2261
+ }
2262
+ };
2263
+ const Linear = _.extend({}, PlotDefaults, {
2264
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/67aaf581e6d9ef9038c10558a1f70ac21c11c9f8.png",
2265
+ defaultCoords: [[0.25, 0.75], [0.75, 0.75]],
2266
+ getCoefficients: function (coords) {
2267
+ const p1 = coords[0];
2268
+ const p2 = coords[1];
2269
+ const denom = p2[0] - p1[0];
2270
+ const num = p2[1] - p1[1];
2271
+ if (denom === 0) {
2272
+ return;
2273
+ }
2274
+ const m = num / denom;
2275
+ const b = p2[1] - m * p2[0];
2276
+ return [m, b];
2277
+ },
2278
+ getFunctionForCoeffs: function (coeffs, x) {
2279
+ const m = coeffs[0];
2280
+ const b = coeffs[1];
2281
+ return m * x + b;
2282
+ },
2283
+ getEquationString: function (coords) {
2284
+ const coeffs = this.getCoefficients(coords);
2285
+ const m = coeffs[0];
2286
+ const b = coeffs[1];
2287
+ return "y = " + m.toFixed(3) + "x + " + b.toFixed(3);
2288
+ }
2289
+ });
2290
+ const Quadratic = _.extend({}, PlotDefaults, {
2291
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/e23d36e6fc29ee37174e92c9daba2a66677128ab.png",
2292
+ defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
2293
+ movable: MOVABLES.PARABOLA,
2294
+ getCoefficients: function (coords) {
2295
+ const p1 = coords[0];
2296
+ const p2 = coords[1];
2297
+
2298
+ // Parabola with vertex (h, k) has form: y = a * (h - k)^2 + k
2299
+ const h = p1[0];
2300
+ const k = p1[1];
2301
+
2302
+ // Use these to calculate familiar a, b, c
2303
+ const a = (p2[1] - k) / ((p2[0] - h) * (p2[0] - h));
2304
+ const b = -2 * h * a;
2305
+ const c = a * h * h + k;
2306
+ return [a, b, c];
2307
+ },
2308
+ getFunctionForCoeffs: function (coeffs, x) {
2309
+ const a = coeffs[0];
2310
+ const b = coeffs[1];
2311
+ const c = coeffs[2];
2312
+ return (a * x + b) * x + c;
2313
+ },
2314
+ getPropsForCoeffs: function (coeffs) {
2315
+ return {
2316
+ a: coeffs[0],
2317
+ b: coeffs[1],
2318
+ c: coeffs[2]
2319
+ };
2320
+ },
2321
+ getEquationString: function (coords) {
2322
+ const coeffs = this.getCoefficients(coords);
2323
+ const a = coeffs[0];
2324
+ const b = coeffs[1];
2325
+ const c = coeffs[2];
2326
+ return "y = " + a.toFixed(3) + "x^2 + " + b.toFixed(3) + "x + " + c.toFixed(3);
2327
+ }
2328
+ });
2329
+ const Sinusoid = _.extend({}, PlotDefaults, {
2330
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/3d68e7718498475f53b206c2ab285626baf8857e.png",
2331
+ defaultCoords: [[0.5, 0.5], [0.6, 0.6]],
2332
+ movable: MOVABLES.SINUSOID,
2333
+ getCoefficients: function (coords) {
2334
+ const p1 = coords[0];
2335
+ const p2 = coords[1];
2336
+ const a = p2[1] - p1[1];
2337
+ const b = Math.PI / (2 * (p2[0] - p1[0]));
2338
+ const c = p1[0] * b;
2339
+ const d = p1[1];
2340
+ return [a, b, c, d];
2341
+ },
2342
+ getFunctionForCoeffs: function (coeffs, x) {
2343
+ const a = coeffs[0];
2344
+ const b = coeffs[1];
2345
+ const c = coeffs[2];
2346
+ const d = coeffs[3];
2347
+ return a * Math.sin(b * x - c) + d;
2348
+ },
2349
+ getPropsForCoeffs: function (coeffs) {
2350
+ return {
2351
+ a: coeffs[0],
2352
+ b: coeffs[1],
2353
+ c: coeffs[2],
2354
+ d: coeffs[3]
2355
+ };
2356
+ },
2357
+ getEquationString: function (coords) {
2358
+ const coeffs = this.getCoefficients(coords);
2359
+ const a = coeffs[0];
2360
+ const b = coeffs[1];
2361
+ const c = coeffs[2];
2362
+ const d = coeffs[3];
2363
+ return "y = " + a.toFixed(3) + " sin(" + b.toFixed(3) + "x - " + c.toFixed(3) + ") + " + d.toFixed(3);
2364
+ },
2365
+ areEqual: function (coeffs1, coeffs2) {
2366
+ return approximateDeepEqual(canonicalSineCoefficients(coeffs1), canonicalSineCoefficients(coeffs2));
2367
+ }
2368
+ });
2369
+ const Tangent = _.extend({}, PlotDefaults, {
2370
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/7db80d23c35214f98659fe1cf0765811c1bbfbba.png",
2371
+ defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
2372
+ getCoefficients: function (coords) {
2373
+ const p1 = coords[0];
2374
+ const p2 = coords[1];
2375
+ const a = p2[1] - p1[1];
2376
+ const b = Math.PI / (4 * (p2[0] - p1[0]));
2377
+ const c = p1[0] * b;
2378
+ const d = p1[1];
2379
+ return [a, b, c, d];
2380
+ },
2381
+ getFunctionForCoeffs: function (coeffs, x) {
2382
+ const a = coeffs[0];
2383
+ const b = coeffs[1];
2384
+ const c = coeffs[2];
2385
+ const d = coeffs[3];
2386
+ return a * Math.tan(b * x - c) + d;
2387
+ },
2388
+ getEquationString: function (coords) {
2389
+ const coeffs = this.getCoefficients(coords);
2390
+ const a = coeffs[0];
2391
+ const b = coeffs[1];
2392
+ const c = coeffs[2];
2393
+ const d = coeffs[3];
2394
+ return "y = " + a.toFixed(3) + " sin(" + b.toFixed(3) + "x - " + c.toFixed(3) + ") + " + d.toFixed(3);
2395
+ },
2396
+ areEqual: function (coeffs1, coeffs2) {
2397
+ return approximateDeepEqual(canonicalTangentCoefficients(coeffs1), canonicalTangentCoefficients(coeffs2));
2398
+ }
2399
+ });
2400
+ const Exponential = _.extend({}, PlotDefaults, {
2401
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/9cbfad55525e3ce755a31a631b074670a5dad611.png",
2402
+ defaultCoords: [[0.5, 0.55], [0.75, 0.75]],
2403
+ defaultAsymptote: [[0, 0.5], [1.0, 0.5]],
2404
+ /**
2405
+ * Add extra constraints for movement of the points or asymptote (below):
2406
+ * newCoord: [x, y]
2407
+ * The end position of the point or asymptote endpoint
2408
+ * oldCoord: [x, y]
2409
+ * The old position of the point or asymptote endpoint
2410
+ * coords:
2411
+ * An array of coordinates representing the proposed end configuration
2412
+ * of the plot coordinates.
2413
+ * asymptote:
2414
+ * An array of coordinates representing the proposed end configuration
2415
+ * of the asymptote.
2416
+ *
2417
+ * Return: either a coordinate (to be used as the resulting coordinate of
2418
+ * the move) or a boolean, where `true` uses newCoord as the resulting
2419
+ * coordinate, and `false` uses oldCoord as the resulting coordinate.
2420
+ */
2421
+ extraCoordConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
2422
+ const y = asymptote[0][1];
2423
+ return _.all(coords, coord => coord[1] !== y);
2424
+ },
2425
+ extraAsymptoteConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
2426
+ const y = newCoord[1];
2427
+ const isValid = _.all(coords, coord => coord[1] > y) || _.all(coords, coord => coord[1] < y);
2428
+ if (isValid) {
2429
+ return [oldCoord[0], y];
2430
+ }
2431
+ // Snap the asymptote as close as possible, i.e., if the user moves
2432
+ // the mouse really quickly into an invalid region
2433
+ const oldY = oldCoord[1];
2434
+ const wasBelow = _.all(coords, coord => coord[1] > oldY);
2435
+ if (wasBelow) {
2436
+ const bottomMost = _.min(_.map(coords, coord => coord[1]));
2437
+ return [oldCoord[0], bottomMost - graph.snapStep[1]];
2438
+ }
2439
+ const topMost = _.max(_.map(coords, coord => coord[1]));
2440
+ return [oldCoord[0], topMost + graph.snapStep[1]];
2441
+ },
2442
+ allowReflectOverAsymptote: true,
2443
+ getCoefficients: function (coords, asymptote) {
2444
+ const p1 = coords[0];
2445
+ const p2 = coords[1];
2446
+ const c = asymptote[0][1];
2447
+ const b = Math.log((p1[1] - c) / (p2[1] - c)) / (p1[0] - p2[0]);
2448
+ const a = (p1[1] - c) / Math.exp(b * p1[0]);
2449
+ return [a, b, c];
2450
+ },
2451
+ getFunctionForCoeffs: function (coeffs, x) {
2452
+ const a = coeffs[0];
2453
+ const b = coeffs[1];
2454
+ const c = coeffs[2];
2455
+ return a * Math.exp(b * x) + c;
2456
+ },
2457
+ getEquationString: function (coords, asymptote) {
2458
+ if (!asymptote) {
2459
+ return null;
2460
+ }
2461
+ const coeffs = this.getCoefficients(coords, asymptote);
2462
+ const a = coeffs[0];
2463
+ const b = coeffs[1];
2464
+ const c = coeffs[2];
2465
+ return "y = " + a.toFixed(3) + "e^(" + b.toFixed(3) + "x) + " + c.toFixed(3);
2466
+ }
2467
+ });
2468
+ const Logarithm = _.extend({}, PlotDefaults, {
2469
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/f6491e99d34af34d924bfe0231728ad912068dc3.png",
2470
+ defaultCoords: [[0.55, 0.5], [0.75, 0.75]],
2471
+ defaultAsymptote: [[0.5, 0], [0.5, 1.0]],
2472
+ extraCoordConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
2473
+ const x = asymptote[0][0];
2474
+ return _.all(coords, coord => coord[0] !== x) && coords[0][1] !== coords[1][1];
2475
+ },
2476
+ extraAsymptoteConstraint: function (newCoord, oldCoord, coords, asymptote, graph) {
2477
+ const x = newCoord[0];
2478
+ const isValid = _.all(coords, coord => coord[0] > x) || _.all(coords, coord => coord[0] < x);
2479
+ if (isValid) {
2480
+ return [x, oldCoord[1]];
2481
+ }
2482
+ // Snap the asymptote as close as possible, i.e., if the user moves
2483
+ // the mouse really quickly into an invalid region
2484
+ const oldX = oldCoord[0];
2485
+ const wasLeft = _.all(coords, coord => coord[0] > oldX);
2486
+ if (wasLeft) {
2487
+ const leftMost = _.min(_.map(coords, coord => coord[0]));
2488
+ return [leftMost - graph.snapStep[0], oldCoord[1]];
2489
+ }
2490
+ const rightMost = _.max(_.map(coords, coord => coord[0]));
2491
+ return [rightMost + graph.snapStep[0], oldCoord[1]];
2492
+ },
2493
+ allowReflectOverAsymptote: true,
2494
+ getCoefficients: function (coords, asymptote) {
2495
+ // It's easiest to calculate the logarithm's coefficients by thinking
2496
+ // about it as the inverse of the exponential, so we flip x and y and
2497
+ // perform some algebra on the coefficients. This also unifies the
2498
+ // logic between the two 'models'.
2499
+ const flip = coord => [coord[1], coord[0]];
2500
+ const inverseCoeffs = Exponential.getCoefficients(_.map(coords, flip), _.map(asymptote, flip));
2501
+ if (inverseCoeffs) {
2502
+ const c = -inverseCoeffs[2] / inverseCoeffs[0];
2503
+ const b = 1 / inverseCoeffs[0];
2504
+ const a = 1 / inverseCoeffs[1];
2505
+ return [a, b, c];
2506
+ }
2507
+ },
2508
+ getFunctionForCoeffs: function (coeffs, x, asymptote) {
2509
+ const a = coeffs[0];
2510
+ const b = coeffs[1];
2511
+ const c = coeffs[2];
2512
+ return a * Math.log(b * x + c);
2513
+ },
2514
+ getEquationString: function (coords, asymptote) {
2515
+ if (!asymptote) {
2516
+ return null;
2517
+ }
2518
+ const coeffs = this.getCoefficients(coords, asymptote);
2519
+ const a = coeffs[0];
2520
+ const b = coeffs[1];
2521
+ const c = coeffs[2];
2522
+ return "y = ln(" + a.toFixed(3) + "x + " + b.toFixed(3) + ") + " + c.toFixed(3);
2523
+ }
2524
+ });
2525
+ const AbsoluteValue = _.extend({}, PlotDefaults, {
2526
+ url: "https://ka-perseus-graphie.s3.amazonaws.com/8256a630175a0cb1d11de223d6de0266daf98721.png",
2527
+ defaultCoords: [[0.5, 0.5], [0.75, 0.75]],
2528
+ getCoefficients: function (coords) {
2529
+ const p1 = coords[0];
2530
+ const p2 = coords[1];
2531
+ const denom = p2[0] - p1[0];
2532
+ const num = p2[1] - p1[1];
2533
+ if (denom === 0) {
2534
+ return;
2535
+ }
2536
+ let m = Math.abs(num / denom);
2537
+ if (p2[1] < p1[1]) {
2538
+ m *= -1;
2539
+ }
2540
+ const horizontalOffset = p1[0];
2541
+ const verticalOffset = p1[1];
2542
+ return [m, horizontalOffset, verticalOffset];
2543
+ },
2544
+ getFunctionForCoeffs: function (coeffs, x) {
2545
+ const m = coeffs[0];
2546
+ const horizontalOffset = coeffs[1];
2547
+ const verticalOffset = coeffs[2];
2548
+ return m * Math.abs(x - horizontalOffset) + verticalOffset;
2549
+ },
2550
+ getEquationString: function (coords) {
2551
+ const coeffs = this.getCoefficients(coords);
2552
+ const m = coeffs[0];
2553
+ const horizontalOffset = coeffs[1];
2554
+ const verticalOffset = coeffs[2];
2555
+ return "y = " + m.toFixed(3) + "| x - " + horizontalOffset.toFixed(3) + "| + " + verticalOffset.toFixed(3);
2556
+ }
2557
+ });
2558
+
2559
+ /* Utility functions for dealing with graphing interfaces. */
2560
+ const functionTypeMapping = {
2561
+ linear: Linear,
2562
+ quadratic: Quadratic,
2563
+ sinusoid: Sinusoid,
2564
+ tangent: Tangent,
2565
+ exponential: Exponential,
2566
+ logarithm: Logarithm,
2567
+ absolute_value: AbsoluteValue
2568
+ };
2569
+ const allTypes = _.keys(functionTypeMapping);
2570
+ function functionForType(type) {
2571
+ // @ts-expect-error: TypeScript doesn't know how to use deal with generics
2572
+ // and conditional types in this way.
2573
+ return functionTypeMapping[type];
2574
+ }
2575
+
2576
+ var grapherUtil = /*#__PURE__*/Object.freeze({
2577
+ __proto__: null,
2578
+ MOVABLES: MOVABLES,
2579
+ allTypes: allTypes,
2580
+ functionForType: functionForType
2581
+ });
2582
+
46
2583
  // This file is processed by a Rollup plugin (replace) to inject the production
47
2584
  const libName = "@khanacademy/perseus-core";
48
- const libVersion = "3.0.5";
2585
+ const libVersion = "3.2.0";
49
2586
  addLibraryVersionToPerseusDebug(libName, libVersion);
50
2587
 
51
2588
  /**
@@ -100,8 +2637,301 @@ class PerseusError extends Error {
100
2637
  }
101
2638
  }
102
2639
 
2640
+ /**
2641
+ * The Perseus "data schema" file.
2642
+ *
2643
+ * This file, and the types in it, represents the "data schema" that Perseus
2644
+ * uses. The @khanacademy/perseus-editor package edits and produces objects
2645
+ * that conform to the types in this file. Similarly, the top-level renderers
2646
+ * in @khanacademy/perseus, consume objects that conform to these types.
2647
+ *
2648
+ * WARNING: This file should not import any types from elsewhere so that it is
2649
+ * easy to reason about changes that alter the Perseus schema. This helps
2650
+ * ensure that it is not changed accidentally when upgrading a dependant
2651
+ * package or other part of Perseus code. Note that TypeScript does type
2652
+ * checking via something called "structural typing". This means that as long
2653
+ * as the shape of a type matches, the name it goes by doesn't matter. As a
2654
+ * result, a `Coord` type that looks like this `[x: number, y: number]` is
2655
+ * _identical_, in TypeScript's eyes, to this `Vector2` type `[x: number, y:
2656
+ * number]`. Also, with tuples, the labels for each entry is ignored, so `[x:
2657
+ * number, y: number]` is compatible with `[min: number, max: number]`. The
2658
+ * labels are for humans, not TypeScript. :)
2659
+ *
2660
+ * If you make changes to types in this file, be very sure that:
2661
+ *
2662
+ * a) the changes are backwards compatible. If they are not, old data from
2663
+ * previous versions of the "schema" could become unrenderable, or worse,
2664
+ * introduce hard-to-diagnose bugs.
2665
+ * b) the parsing code (`util/parse-perseus-json/`) is updated to handle
2666
+ * the new format _as well as_ the old format.
2667
+ */
2668
+
2669
+ // TODO(FEI-4010): Remove `Perseus` prefix for all types here
2670
+
2671
+ // Same name as Mafs
2672
+
2673
+ /**
2674
+ * Our core set of Perseus widgets.
2675
+ *
2676
+ * This interface is the basis for "registering" all Perseus widget types.
2677
+ * There should be one key/value pair for each supported widget. If you create
2678
+ * a new widget, an entry should be added to this interface. Note that this
2679
+ * only registers the widget options type, you'll also need to register the
2680
+ * widget so that it's available at runtime (@see
2681
+ * {@link file://./widgets.ts#registerWidget}).
2682
+ *
2683
+ * Importantly, the key should be the name that is used in widget IDs. For most
2684
+ * widgets that is the same as the widget option's `type` field. In cases where
2685
+ * a widget has been deprecated and replaced with the deprecated-standin
2686
+ * widget, it should be the original widget type!
2687
+ *
2688
+ * If you define the widget outside of this package, you can still add the new
2689
+ * widget to this interface by writing the following in that package that
2690
+ * contains the widget. TypeScript will merge that definition of the
2691
+ * `PerseusWidgets` with the one defined below.
2692
+ *
2693
+ * ```typescript
2694
+ * declare module "@khanacademy/perseus" {
2695
+ * interface PerseusWidgetTypes {
2696
+ * // A new widget
2697
+ * "new-awesomeness": MyAwesomeNewWidget;
2698
+ *
2699
+ * // A deprecated widget
2700
+ * "super-old-widget": DeprecatedStandinWidget;
2701
+ * }
2702
+ * }
2703
+ *
2704
+ * // The new widget's options definition
2705
+ * type MyAwesomeNewWidget = WidgetOptions<'new-awesomeness', MyAwesomeNewWidgetOptions>;
2706
+ *
2707
+ * // The deprecated widget's options definition
2708
+ * type SuperOldWidget = WidgetOptions<'super-old-widget', object>;
2709
+ * ```
2710
+ *
2711
+ * This interface can be extended through the magic of TypeScript "Declaration
2712
+ * merging". Specifically, we augment this module and extend this interface.
2713
+ *
2714
+ * @see {@link https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation}
2715
+ */
2716
+
2717
+ /**
2718
+ * A map of widget IDs to widget options. This is most often used as the type
2719
+ * for a set of widgets defined in a `PerseusItem` but can also be useful to
2720
+ * represent a function parameter where only `widgets` from a `PerseusItem` are
2721
+ * needed. Today Widget IDs are made up of the widget type and an incrementing
2722
+ * integer (eg. `interactive-graph 1` or `radio 3`). It is suggested to avoid
2723
+ * reading/parsing the widget id to derive any information from it, except in
2724
+ * the case of this map.
2725
+ *
2726
+ * @see {@link PerseusWidgetTypes} additional widgets can be added to this map type
2727
+ * by augmenting the PerseusWidgetTypes with new widget types!
2728
+ */
2729
+
2730
+ /**
2731
+ * A "PerseusItem" is a classic Perseus item. It is rendered by the
2732
+ * `ServerItemRenderer` and the layout is pre-set.
2733
+ *
2734
+ * To render more complex Perseus items, see the `Item` type in the multi item
2735
+ * area.
2736
+ */
2737
+
2738
+ /**
2739
+ * A "PerseusArticle" is an item that is meant to be rendered as an article.
2740
+ * This item is never scored and is rendered by the `ArticleRenderer`.
2741
+ */
2742
+
2743
+ const ItemExtras = [
2744
+ // The user might benefit from using a Scientific Calculator. Provided on Khan Academy when true
2745
+ "calculator",
2746
+ // The user might benefit from using a statistics Chi Squared Table like https://people.richland.edu/james/lecture/m170/tbl-chi.html
2747
+ "chi2Table",
2748
+ // The user might benefit from a monthly payments calculator. Provided on Khan Academy when true
2749
+ "financialCalculatorMonthlyPayment",
2750
+ // The user might benefit from a total amount calculator. Provided on Khan Academy when true
2751
+ "financialCalculatorTotalAmount",
2752
+ // The user might benefit from a time to pay off calculator. Provided on Khan Academy when true
2753
+ "financialCalculatorTimeToPayOff",
2754
+ // The user might benefit from using a Periodic Table of Elements. Provided on Khan Academy when true
2755
+ "periodicTable",
2756
+ // The user might benefit from using a Periodic Table of Elements with key. Provided on Khan Academy when true
2757
+ "periodicTableWithKey",
2758
+ // The user might benefit from using a statistics T Table like https://www.statisticshowto.com/tables/t-distribution-table/
2759
+ "tTable",
2760
+ // The user might benefit from using a statistics Z Table like https://www.ztable.net/
2761
+ "zTable"];
2762
+
2763
+ /**
2764
+ * The type representing the common structure of all widget's options. The
2765
+ * `Options` generic type represents the widget-specific option data.
2766
+ */
2767
+
2768
+ // prettier-ignore
2769
+
2770
+ // prettier-ignore
2771
+
2772
+ // prettier-ignore
2773
+
2774
+ // prettier-ignore
2775
+
2776
+ // prettier-ignore
2777
+
2778
+ // prettier-ignore
2779
+
2780
+ // prettier-ignore
2781
+
2782
+ // prettier-ignore
2783
+
2784
+ // prettier-ignore
2785
+
2786
+ // prettier-ignore
2787
+
2788
+ // prettier-ignore
2789
+
2790
+ // prettier-ignore
2791
+
2792
+ // prettier-ignore
2793
+
2794
+ // prettier-ignore
2795
+
2796
+ // prettier-ignore
2797
+
2798
+ // prettier-ignore
2799
+
2800
+ // prettier-ignore
2801
+
2802
+ // prettier-ignore
2803
+
2804
+ // prettier-ignore
2805
+
2806
+ // prettier-ignore
2807
+
2808
+ // prettier-ignore
2809
+
2810
+ // prettier-ignore
2811
+
2812
+ // prettier-ignore
2813
+
2814
+ // prettier-ignore
2815
+
2816
+ // prettier-ignore
2817
+
2818
+ // prettier-ignore
2819
+
2820
+ // prettier-ignore
2821
+
2822
+ // prettier-ignore
2823
+
2824
+ // prettier-ignore
2825
+
2826
+ // prettier-ignore
2827
+
2828
+ // prettier-ignore
2829
+
2830
+ // prettier-ignore
2831
+
2832
+ // prettier-ignore
2833
+
2834
+ // prettier-ignore
2835
+
2836
+ //prettier-ignore
2837
+
2838
+ /**
2839
+ * A background image applied to various widgets.
2840
+ */
2841
+
2842
+ /**
2843
+ * The type of markings to display on the graph.
2844
+ * - axes: shows the axes without the gride lines
2845
+ * - graph: shows the axes and the grid lines
2846
+ * - grid: shows only the grid lines
2847
+ * - none: shows no markings
2848
+ */
2849
+
2850
+ const PerseusExpressionAnswerFormConsidered = ["correct", "wrong", "ungraded"];
2851
+
2852
+ // 2D range: xMin, xMax, yMin, yMax
2853
+
2854
+ const lockedFigureColorNames = ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
2855
+ const lockedFigureColors = {
2856
+ blue: "#3D7586",
2857
+ green: "#447A53",
2858
+ grayH: "#3B3D45",
2859
+ purple: "#594094",
2860
+ pink: "#B25071",
2861
+ red: "#D92916",
2862
+ orange: "#946700"
2863
+ };
2864
+ const lockedFigureFillStyles = {
2865
+ none: 0,
2866
+ white: 1,
2867
+ translucent: 0.4,
2868
+ solid: 1
2869
+ };
2870
+
2871
+ // Not associated with a specific figure
2872
+
2873
+ const plotterPlotTypes = ["bar", "line", "pic", "histogram", "dotplot"];
2874
+
2875
+ /**
2876
+ * _ utilities for objects
2877
+ */
2878
+
2879
+ /**
2880
+ * Does a pluck on keys inside objects in an object
2881
+ *
2882
+ * Ex:
2883
+ * tools = {
2884
+ * translation: {
2885
+ * enabled: true
2886
+ * },
2887
+ * rotation: {
2888
+ * enabled: false
2889
+ * }
2890
+ * };
2891
+ * pluckObject(tools, "enabled") returns {
2892
+ * translation: true
2893
+ * rotation: false
2894
+ * }
2895
+ */
2896
+ const pluck = function (table, subKey) {
2897
+ return _.object(_.map(table, function (value, key) {
2898
+ return [key, value[subKey]];
2899
+ }));
2900
+ };
2901
+
2902
+ /**
2903
+ * Maps an object to an object
2904
+ *
2905
+ * > mapObject({a: '1', b: '2'}, (value, key) => {
2906
+ * return value + 1;
2907
+ * });
2908
+ * {a: 2, b: 3}
2909
+ */
2910
+ const mapObject = function (obj, lambda) {
2911
+ const result = {};
2912
+ Object.keys(obj).forEach(key => {
2913
+ // @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'K'.
2914
+ result[key] = lambda(obj[key], key);
2915
+ });
2916
+ return result;
2917
+ };
2918
+
103
2919
  exports.Errors = Errors;
2920
+ exports.GrapherUtil = grapherUtil;
2921
+ exports.ItemExtras = ItemExtras;
104
2922
  exports.PerseusError = PerseusError;
2923
+ exports.PerseusExpressionAnswerFormConsidered = PerseusExpressionAnswerFormConsidered;
105
2924
  exports.addLibraryVersionToPerseusDebug = addLibraryVersionToPerseusDebug;
2925
+ exports.approximateDeepEqual = approximateDeepEqual;
2926
+ exports.approximateEqual = approximateEqual;
2927
+ exports.deepClone = deepClone;
2928
+ exports.getDecimalSeparator = getDecimalSeparator;
2929
+ exports.getMatrixSize = getMatrixSize;
106
2930
  exports.libVersion = libVersion;
2931
+ exports.lockedFigureColorNames = lockedFigureColorNames;
2932
+ exports.lockedFigureColors = lockedFigureColors;
2933
+ exports.lockedFigureFillStyles = lockedFigureFillStyles;
2934
+ exports.mapObject = mapObject;
2935
+ exports.plotterPlotTypes = plotterPlotTypes;
2936
+ exports.pluck = pluck;
107
2937
  //# sourceMappingURL=index.js.map