@khanacademy/perseus-core 3.6.0 → 4.0.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/LICENSE +18 -0
- package/dist/data-schema.d.ts +25 -7
- package/dist/es/index.js +262 -2140
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +293 -2147
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/perseus-parsers/interactive-graph-widget.d.ts +1 -0
- package/dist/parse-perseus-json/perseus-parsers/perseus-answer-area.d.ts +2 -0
- package/dist/utils/random-util.d.ts +5 -0
- package/dist/widgets/dropdown/dropdown-util.d.ts +1 -1
- package/dist/widgets/group/index.d.ts +1 -1
- package/dist/widgets/interactive-graph/interactive-graph-util.d.ts +1 -2
- package/dist/widgets/logic-export.types.d.ts +2 -1
- package/dist/widgets/matcher/matcher-util.d.ts +28 -0
- package/dist/widgets/numeric-input/numeric-input-util.d.ts +3 -2
- package/dist/widgets/sorter/sorter-util.d.ts +1 -0
- package/package.json +33 -32
- /package/dist/{utils → shared-utils}/add-library-version-to-perseus-debug.d.ts +0 -0
package/dist/es/index.js
CHANGED
|
@@ -1,2068 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* This allows each library to provide runtime version information to assist in
|
|
7
|
-
* debugging in production environments.
|
|
8
|
-
*/
|
|
9
|
-
const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
|
|
10
|
-
// If the library version is the default value, then we don't want to
|
|
11
|
-
// prefix it with a "v" to indicate that it is a version number.
|
|
12
|
-
let prefix = "v";
|
|
13
|
-
if (libraryVersion === "__lib_version__") {
|
|
14
|
-
prefix = "";
|
|
15
|
-
}
|
|
16
|
-
const formattedVersion = `${prefix}${libraryVersion}`;
|
|
17
|
-
if (typeof globalThis !== "undefined") {
|
|
18
|
-
var _globalThis$__perseus;
|
|
19
|
-
globalThis.__perseus_debug__ = (_globalThis$__perseus = globalThis.__perseus_debug__) != null ? _globalThis$__perseus : {};
|
|
20
|
-
const existingVersionEntry = globalThis.__perseus_debug__[libraryName];
|
|
21
|
-
if (existingVersionEntry) {
|
|
22
|
-
// If we already have an entry and it doesn't match the registered
|
|
23
|
-
// version, we morph the entry into an array and log a warning.
|
|
24
|
-
if (existingVersionEntry !== formattedVersion) {
|
|
25
|
-
// Existing entry might be an array already (oops, at least 2
|
|
26
|
-
// versions of the library already loaded!).
|
|
27
|
-
const allVersions = Array.isArray(existingVersionEntry) ? existingVersionEntry : [existingVersionEntry];
|
|
28
|
-
allVersions.push(formattedVersion);
|
|
29
|
-
globalThis.__perseus_debug__[libraryName] = allVersions;
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line no-console
|
|
32
|
-
console.warn(`Multiple versions of ${libraryName} loaded on this page: ${allVersions.sort().join(", ")}`);
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
globalThis.__perseus_debug__[libraryName] = formattedVersion;
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
// eslint-disable-next-line no-console
|
|
39
|
-
console.warn(`globalThis not found found (${formattedVersion})`);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// Current version.
|
|
44
|
-
var VERSION = '1.13.3';
|
|
45
|
-
|
|
46
|
-
// Establish the root object, `window` (`self`) in the browser, `global`
|
|
47
|
-
// on the server, or `this` in some virtual machines. We use `self`
|
|
48
|
-
// instead of `window` for `WebWorker` support.
|
|
49
|
-
var root = (typeof self == 'object' && self.self === self && self) ||
|
|
50
|
-
(typeof global == 'object' && global.global === global && global) ||
|
|
51
|
-
Function('return this')() ||
|
|
52
|
-
{};
|
|
53
|
-
|
|
54
|
-
// Save bytes in the minified (but not gzipped) version:
|
|
55
|
-
var ArrayProto = Array.prototype, ObjProto = Object.prototype;
|
|
56
|
-
var SymbolProto = typeof Symbol !== 'undefined' ? Symbol.prototype : null;
|
|
57
|
-
|
|
58
|
-
// Create quick reference variables for speed access to core prototypes.
|
|
59
|
-
var push = ArrayProto.push,
|
|
60
|
-
slice = ArrayProto.slice,
|
|
61
|
-
toString = ObjProto.toString,
|
|
62
|
-
hasOwnProperty = ObjProto.hasOwnProperty;
|
|
63
|
-
|
|
64
|
-
// Modern feature detection.
|
|
65
|
-
var supportsArrayBuffer = typeof ArrayBuffer !== 'undefined',
|
|
66
|
-
supportsDataView = typeof DataView !== 'undefined';
|
|
67
|
-
|
|
68
|
-
// All **ECMAScript 5+** native function implementations that we hope to use
|
|
69
|
-
// are declared here.
|
|
70
|
-
var nativeIsArray = Array.isArray,
|
|
71
|
-
nativeKeys = Object.keys,
|
|
72
|
-
nativeCreate = Object.create,
|
|
73
|
-
nativeIsView = supportsArrayBuffer && ArrayBuffer.isView;
|
|
74
|
-
|
|
75
|
-
// Create references to these builtin functions because we override them.
|
|
76
|
-
var _isNaN = isNaN,
|
|
77
|
-
_isFinite = isFinite;
|
|
78
|
-
|
|
79
|
-
// Keys in IE < 9 that won't be iterated by `for key in ...` and thus missed.
|
|
80
|
-
var hasEnumBug = !{toString: null}.propertyIsEnumerable('toString');
|
|
81
|
-
var nonEnumerableProps = ['valueOf', 'isPrototypeOf', 'toString',
|
|
82
|
-
'propertyIsEnumerable', 'hasOwnProperty', 'toLocaleString'];
|
|
83
|
-
|
|
84
|
-
// The largest integer that can be represented exactly.
|
|
85
|
-
var MAX_ARRAY_INDEX = Math.pow(2, 53) - 1;
|
|
86
|
-
|
|
87
|
-
// Some functions take a variable number of arguments, or a few expected
|
|
88
|
-
// arguments at the beginning and then a variable number of values to operate
|
|
89
|
-
// on. This helper accumulates all remaining arguments past the function’s
|
|
90
|
-
// argument length (or an explicit `startIndex`), into an array that becomes
|
|
91
|
-
// the last argument. Similar to ES6’s "rest parameter".
|
|
92
|
-
function restArguments(func, startIndex) {
|
|
93
|
-
startIndex = startIndex == null ? func.length - 1 : +startIndex;
|
|
94
|
-
return function() {
|
|
95
|
-
var length = Math.max(arguments.length - startIndex, 0),
|
|
96
|
-
rest = Array(length),
|
|
97
|
-
index = 0;
|
|
98
|
-
for (; index < length; index++) {
|
|
99
|
-
rest[index] = arguments[index + startIndex];
|
|
100
|
-
}
|
|
101
|
-
switch (startIndex) {
|
|
102
|
-
case 0: return func.call(this, rest);
|
|
103
|
-
case 1: return func.call(this, arguments[0], rest);
|
|
104
|
-
case 2: return func.call(this, arguments[0], arguments[1], rest);
|
|
105
|
-
}
|
|
106
|
-
var args = Array(startIndex + 1);
|
|
107
|
-
for (index = 0; index < startIndex; index++) {
|
|
108
|
-
args[index] = arguments[index];
|
|
109
|
-
}
|
|
110
|
-
args[startIndex] = rest;
|
|
111
|
-
return func.apply(this, args);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Is a given variable an object?
|
|
116
|
-
function isObject$1(obj) {
|
|
117
|
-
var type = typeof obj;
|
|
118
|
-
return type === 'function' || (type === 'object' && !!obj);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// Is a given value equal to null?
|
|
122
|
-
function isNull(obj) {
|
|
123
|
-
return obj === null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
// Is a given variable undefined?
|
|
127
|
-
function isUndefined(obj) {
|
|
128
|
-
return obj === void 0;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Is a given value a boolean?
|
|
132
|
-
function isBoolean(obj) {
|
|
133
|
-
return obj === true || obj === false || toString.call(obj) === '[object Boolean]';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Is a given value a DOM element?
|
|
137
|
-
function isElement(obj) {
|
|
138
|
-
return !!(obj && obj.nodeType === 1);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Internal function for creating a `toString`-based type tester.
|
|
142
|
-
function tagTester(name) {
|
|
143
|
-
var tag = '[object ' + name + ']';
|
|
144
|
-
return function(obj) {
|
|
145
|
-
return toString.call(obj) === tag;
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
var isString = tagTester('String');
|
|
150
|
-
|
|
151
|
-
var isNumber = tagTester('Number');
|
|
152
|
-
|
|
153
|
-
var isDate = tagTester('Date');
|
|
154
|
-
|
|
155
|
-
var isRegExp = tagTester('RegExp');
|
|
156
|
-
|
|
157
|
-
var isError = tagTester('Error');
|
|
158
|
-
|
|
159
|
-
var isSymbol = tagTester('Symbol');
|
|
160
|
-
|
|
161
|
-
var isArrayBuffer = tagTester('ArrayBuffer');
|
|
162
|
-
|
|
163
|
-
var isFunction = tagTester('Function');
|
|
164
|
-
|
|
165
|
-
// Optimize `isFunction` if appropriate. Work around some `typeof` bugs in old
|
|
166
|
-
// v8, IE 11 (#1621), Safari 8 (#1929), and PhantomJS (#2236).
|
|
167
|
-
var nodelist = root.document && root.document.childNodes;
|
|
168
|
-
if (typeof /./ != 'function' && typeof Int8Array != 'object' && typeof nodelist != 'function') {
|
|
169
|
-
isFunction = function(obj) {
|
|
170
|
-
return typeof obj == 'function' || false;
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
var isFunction$1 = isFunction;
|
|
175
|
-
|
|
176
|
-
var hasObjectTag = tagTester('Object');
|
|
177
|
-
|
|
178
|
-
// In IE 10 - Edge 13, `DataView` has string tag `'[object Object]'`.
|
|
179
|
-
// In IE 11, the most common among them, this problem also applies to
|
|
180
|
-
// `Map`, `WeakMap` and `Set`.
|
|
181
|
-
var hasStringTagBug = (
|
|
182
|
-
supportsDataView && hasObjectTag(new DataView(new ArrayBuffer(8)))
|
|
183
|
-
),
|
|
184
|
-
isIE11 = (typeof Map !== 'undefined' && hasObjectTag(new Map));
|
|
185
|
-
|
|
186
|
-
var isDataView = tagTester('DataView');
|
|
187
|
-
|
|
188
|
-
// In IE 10 - Edge 13, we need a different heuristic
|
|
189
|
-
// to determine whether an object is a `DataView`.
|
|
190
|
-
function ie10IsDataView(obj) {
|
|
191
|
-
return obj != null && isFunction$1(obj.getInt8) && isArrayBuffer(obj.buffer);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
var isDataView$1 = (hasStringTagBug ? ie10IsDataView : isDataView);
|
|
195
|
-
|
|
196
|
-
// Is a given value an array?
|
|
197
|
-
// Delegates to ECMA5's native `Array.isArray`.
|
|
198
|
-
var isArray = nativeIsArray || tagTester('Array');
|
|
199
|
-
|
|
200
|
-
// Internal function to check whether `key` is an own property name of `obj`.
|
|
201
|
-
function has$1(obj, key) {
|
|
202
|
-
return obj != null && hasOwnProperty.call(obj, key);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
var isArguments = tagTester('Arguments');
|
|
206
|
-
|
|
207
|
-
// Define a fallback version of the method in browsers (ahem, IE < 9), where
|
|
208
|
-
// there isn't any inspectable "Arguments" type.
|
|
209
|
-
(function() {
|
|
210
|
-
if (!isArguments(arguments)) {
|
|
211
|
-
isArguments = function(obj) {
|
|
212
|
-
return has$1(obj, 'callee');
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
}());
|
|
216
|
-
|
|
217
|
-
var isArguments$1 = isArguments;
|
|
218
|
-
|
|
219
|
-
// Is a given object a finite number?
|
|
220
|
-
function isFinite$1(obj) {
|
|
221
|
-
return !isSymbol(obj) && _isFinite(obj) && !isNaN(parseFloat(obj));
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Is the given value `NaN`?
|
|
225
|
-
function isNaN$1(obj) {
|
|
226
|
-
return isNumber(obj) && _isNaN(obj);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// Predicate-generating function. Often useful outside of Underscore.
|
|
230
|
-
function constant$1(value) {
|
|
231
|
-
return function() {
|
|
232
|
-
return value;
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Common internal logic for `isArrayLike` and `isBufferLike`.
|
|
237
|
-
function createSizePropertyCheck(getSizeProperty) {
|
|
238
|
-
return function(collection) {
|
|
239
|
-
var sizeProperty = getSizeProperty(collection);
|
|
240
|
-
return typeof sizeProperty == 'number' && sizeProperty >= 0 && sizeProperty <= MAX_ARRAY_INDEX;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Internal helper to generate a function to obtain property `key` from `obj`.
|
|
245
|
-
function shallowProperty(key) {
|
|
246
|
-
return function(obj) {
|
|
247
|
-
return obj == null ? void 0 : obj[key];
|
|
248
|
-
};
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// Internal helper to obtain the `byteLength` property of an object.
|
|
252
|
-
var getByteLength = shallowProperty('byteLength');
|
|
253
|
-
|
|
254
|
-
// Internal helper to determine whether we should spend extensive checks against
|
|
255
|
-
// `ArrayBuffer` et al.
|
|
256
|
-
var isBufferLike = createSizePropertyCheck(getByteLength);
|
|
257
|
-
|
|
258
|
-
// Is a given value a typed array?
|
|
259
|
-
var typedArrayPattern = /\[object ((I|Ui)nt(8|16|32)|Float(32|64)|Uint8Clamped|Big(I|Ui)nt64)Array\]/;
|
|
260
|
-
function isTypedArray(obj) {
|
|
261
|
-
// `ArrayBuffer.isView` is the most future-proof, so use it when available.
|
|
262
|
-
// Otherwise, fall back on the above regular expression.
|
|
263
|
-
return nativeIsView ? (nativeIsView(obj) && !isDataView$1(obj)) :
|
|
264
|
-
isBufferLike(obj) && typedArrayPattern.test(toString.call(obj));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
var isTypedArray$1 = supportsArrayBuffer ? isTypedArray : constant$1(false);
|
|
268
|
-
|
|
269
|
-
// Internal helper to obtain the `length` property of an object.
|
|
270
|
-
var getLength = shallowProperty('length');
|
|
271
|
-
|
|
272
|
-
// Internal helper to create a simple lookup structure.
|
|
273
|
-
// `collectNonEnumProps` used to depend on `_.contains`, but this led to
|
|
274
|
-
// circular imports. `emulatedSet` is a one-off solution that only works for
|
|
275
|
-
// arrays of strings.
|
|
276
|
-
function emulatedSet(keys) {
|
|
277
|
-
var hash = {};
|
|
278
|
-
for (var l = keys.length, i = 0; i < l; ++i) hash[keys[i]] = true;
|
|
279
|
-
return {
|
|
280
|
-
contains: function(key) { return hash[key] === true; },
|
|
281
|
-
push: function(key) {
|
|
282
|
-
hash[key] = true;
|
|
283
|
-
return keys.push(key);
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Internal helper. Checks `keys` for the presence of keys in IE < 9 that won't
|
|
289
|
-
// be iterated by `for key in ...` and thus missed. Extends `keys` in place if
|
|
290
|
-
// needed.
|
|
291
|
-
function collectNonEnumProps(obj, keys) {
|
|
292
|
-
keys = emulatedSet(keys);
|
|
293
|
-
var nonEnumIdx = nonEnumerableProps.length;
|
|
294
|
-
var constructor = obj.constructor;
|
|
295
|
-
var proto = (isFunction$1(constructor) && constructor.prototype) || ObjProto;
|
|
296
|
-
|
|
297
|
-
// Constructor is a special case.
|
|
298
|
-
var prop = 'constructor';
|
|
299
|
-
if (has$1(obj, prop) && !keys.contains(prop)) keys.push(prop);
|
|
300
|
-
|
|
301
|
-
while (nonEnumIdx--) {
|
|
302
|
-
prop = nonEnumerableProps[nonEnumIdx];
|
|
303
|
-
if (prop in obj && obj[prop] !== proto[prop] && !keys.contains(prop)) {
|
|
304
|
-
keys.push(prop);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Retrieve the names of an object's own properties.
|
|
310
|
-
// Delegates to **ECMAScript 5**'s native `Object.keys`.
|
|
311
|
-
function keys(obj) {
|
|
312
|
-
if (!isObject$1(obj)) return [];
|
|
313
|
-
if (nativeKeys) return nativeKeys(obj);
|
|
314
|
-
var keys = [];
|
|
315
|
-
for (var key in obj) if (has$1(obj, key)) keys.push(key);
|
|
316
|
-
// Ahem, IE < 9.
|
|
317
|
-
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
|
318
|
-
return keys;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Is a given array, string, or object empty?
|
|
322
|
-
// An "empty" object has no enumerable own-properties.
|
|
323
|
-
function isEmpty(obj) {
|
|
324
|
-
if (obj == null) return true;
|
|
325
|
-
// Skip the more expensive `toString`-based type checks if `obj` has no
|
|
326
|
-
// `.length`.
|
|
327
|
-
var length = getLength(obj);
|
|
328
|
-
if (typeof length == 'number' && (
|
|
329
|
-
isArray(obj) || isString(obj) || isArguments$1(obj)
|
|
330
|
-
)) return length === 0;
|
|
331
|
-
return getLength(keys(obj)) === 0;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
// Returns whether an object has a given set of `key:value` pairs.
|
|
335
|
-
function isMatch(object, attrs) {
|
|
336
|
-
var _keys = keys(attrs), length = _keys.length;
|
|
337
|
-
if (object == null) return !length;
|
|
338
|
-
var obj = Object(object);
|
|
339
|
-
for (var i = 0; i < length; i++) {
|
|
340
|
-
var key = _keys[i];
|
|
341
|
-
if (attrs[key] !== obj[key] || !(key in obj)) return false;
|
|
342
|
-
}
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
// If Underscore is called as a function, it returns a wrapped object that can
|
|
347
|
-
// be used OO-style. This wrapper holds altered versions of all functions added
|
|
348
|
-
// through `_.mixin`. Wrapped objects may be chained.
|
|
349
|
-
function _$1(obj) {
|
|
350
|
-
if (obj instanceof _$1) return obj;
|
|
351
|
-
if (!(this instanceof _$1)) return new _$1(obj);
|
|
352
|
-
this._wrapped = obj;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
_$1.VERSION = VERSION;
|
|
356
|
-
|
|
357
|
-
// Extracts the result from a wrapped and chained object.
|
|
358
|
-
_$1.prototype.value = function() {
|
|
359
|
-
return this._wrapped;
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
// Provide unwrapping proxies for some methods used in engine operations
|
|
363
|
-
// such as arithmetic and JSON stringification.
|
|
364
|
-
_$1.prototype.valueOf = _$1.prototype.toJSON = _$1.prototype.value;
|
|
365
|
-
|
|
366
|
-
_$1.prototype.toString = function() {
|
|
367
|
-
return String(this._wrapped);
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
// Internal function to wrap or shallow-copy an ArrayBuffer,
|
|
371
|
-
// typed array or DataView to a new view, reusing the buffer.
|
|
372
|
-
function toBufferView(bufferSource) {
|
|
373
|
-
return new Uint8Array(
|
|
374
|
-
bufferSource.buffer || bufferSource,
|
|
375
|
-
bufferSource.byteOffset || 0,
|
|
376
|
-
getByteLength(bufferSource)
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// We use this string twice, so give it a name for minification.
|
|
381
|
-
var tagDataView = '[object DataView]';
|
|
382
|
-
|
|
383
|
-
// Internal recursive comparison function for `_.isEqual`.
|
|
384
|
-
function eq(a, b, aStack, bStack) {
|
|
385
|
-
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
|
386
|
-
// See the [Harmony `egal` proposal](https://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
|
387
|
-
if (a === b) return a !== 0 || 1 / a === 1 / b;
|
|
388
|
-
// `null` or `undefined` only equal to itself (strict comparison).
|
|
389
|
-
if (a == null || b == null) return false;
|
|
390
|
-
// `NaN`s are equivalent, but non-reflexive.
|
|
391
|
-
if (a !== a) return b !== b;
|
|
392
|
-
// Exhaust primitive checks
|
|
393
|
-
var type = typeof a;
|
|
394
|
-
if (type !== 'function' && type !== 'object' && typeof b != 'object') return false;
|
|
395
|
-
return deepEq(a, b, aStack, bStack);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// Internal recursive comparison function for `_.isEqual`.
|
|
399
|
-
function deepEq(a, b, aStack, bStack) {
|
|
400
|
-
// Unwrap any wrapped objects.
|
|
401
|
-
if (a instanceof _$1) a = a._wrapped;
|
|
402
|
-
if (b instanceof _$1) b = b._wrapped;
|
|
403
|
-
// Compare `[[Class]]` names.
|
|
404
|
-
var className = toString.call(a);
|
|
405
|
-
if (className !== toString.call(b)) return false;
|
|
406
|
-
// Work around a bug in IE 10 - Edge 13.
|
|
407
|
-
if (hasStringTagBug && className == '[object Object]' && isDataView$1(a)) {
|
|
408
|
-
if (!isDataView$1(b)) return false;
|
|
409
|
-
className = tagDataView;
|
|
410
|
-
}
|
|
411
|
-
switch (className) {
|
|
412
|
-
// These types are compared by value.
|
|
413
|
-
case '[object RegExp]':
|
|
414
|
-
// RegExps are coerced to strings for comparison (Note: '' + /a/i === '/a/i')
|
|
415
|
-
case '[object String]':
|
|
416
|
-
// Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
|
|
417
|
-
// equivalent to `new String("5")`.
|
|
418
|
-
return '' + a === '' + b;
|
|
419
|
-
case '[object Number]':
|
|
420
|
-
// `NaN`s are equivalent, but non-reflexive.
|
|
421
|
-
// Object(NaN) is equivalent to NaN.
|
|
422
|
-
if (+a !== +a) return +b !== +b;
|
|
423
|
-
// An `egal` comparison is performed for other numeric values.
|
|
424
|
-
return +a === 0 ? 1 / +a === 1 / b : +a === +b;
|
|
425
|
-
case '[object Date]':
|
|
426
|
-
case '[object Boolean]':
|
|
427
|
-
// Coerce dates and booleans to numeric primitive values. Dates are compared by their
|
|
428
|
-
// millisecond representations. Note that invalid dates with millisecond representations
|
|
429
|
-
// of `NaN` are not equivalent.
|
|
430
|
-
return +a === +b;
|
|
431
|
-
case '[object Symbol]':
|
|
432
|
-
return SymbolProto.valueOf.call(a) === SymbolProto.valueOf.call(b);
|
|
433
|
-
case '[object ArrayBuffer]':
|
|
434
|
-
case tagDataView:
|
|
435
|
-
// Coerce to typed array so we can fall through.
|
|
436
|
-
return deepEq(toBufferView(a), toBufferView(b), aStack, bStack);
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
var areArrays = className === '[object Array]';
|
|
440
|
-
if (!areArrays && isTypedArray$1(a)) {
|
|
441
|
-
var byteLength = getByteLength(a);
|
|
442
|
-
if (byteLength !== getByteLength(b)) return false;
|
|
443
|
-
if (a.buffer === b.buffer && a.byteOffset === b.byteOffset) return true;
|
|
444
|
-
areArrays = true;
|
|
445
|
-
}
|
|
446
|
-
if (!areArrays) {
|
|
447
|
-
if (typeof a != 'object' || typeof b != 'object') return false;
|
|
448
|
-
|
|
449
|
-
// Objects with different constructors are not equivalent, but `Object`s or `Array`s
|
|
450
|
-
// from different frames are.
|
|
451
|
-
var aCtor = a.constructor, bCtor = b.constructor;
|
|
452
|
-
if (aCtor !== bCtor && !(isFunction$1(aCtor) && aCtor instanceof aCtor &&
|
|
453
|
-
isFunction$1(bCtor) && bCtor instanceof bCtor)
|
|
454
|
-
&& ('constructor' in a && 'constructor' in b)) {
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
// Assume equality for cyclic structures. The algorithm for detecting cyclic
|
|
459
|
-
// structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
|
|
460
|
-
|
|
461
|
-
// Initializing stack of traversed objects.
|
|
462
|
-
// It's done here since we only need them for objects and arrays comparison.
|
|
463
|
-
aStack = aStack || [];
|
|
464
|
-
bStack = bStack || [];
|
|
465
|
-
var length = aStack.length;
|
|
466
|
-
while (length--) {
|
|
467
|
-
// Linear search. Performance is inversely proportional to the number of
|
|
468
|
-
// unique nested structures.
|
|
469
|
-
if (aStack[length] === a) return bStack[length] === b;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// Add the first object to the stack of traversed objects.
|
|
473
|
-
aStack.push(a);
|
|
474
|
-
bStack.push(b);
|
|
475
|
-
|
|
476
|
-
// Recursively compare objects and arrays.
|
|
477
|
-
if (areArrays) {
|
|
478
|
-
// Compare array lengths to determine if a deep comparison is necessary.
|
|
479
|
-
length = a.length;
|
|
480
|
-
if (length !== b.length) return false;
|
|
481
|
-
// Deep compare the contents, ignoring non-numeric properties.
|
|
482
|
-
while (length--) {
|
|
483
|
-
if (!eq(a[length], b[length], aStack, bStack)) return false;
|
|
484
|
-
}
|
|
485
|
-
} else {
|
|
486
|
-
// Deep compare objects.
|
|
487
|
-
var _keys = keys(a), key;
|
|
488
|
-
length = _keys.length;
|
|
489
|
-
// Ensure that both objects contain the same number of properties before comparing deep equality.
|
|
490
|
-
if (keys(b).length !== length) return false;
|
|
491
|
-
while (length--) {
|
|
492
|
-
// Deep compare each member
|
|
493
|
-
key = _keys[length];
|
|
494
|
-
if (!(has$1(b, key) && eq(a[key], b[key], aStack, bStack))) return false;
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
// Remove the first object from the stack of traversed objects.
|
|
498
|
-
aStack.pop();
|
|
499
|
-
bStack.pop();
|
|
500
|
-
return true;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
// Perform a deep comparison to check if two objects are equal.
|
|
504
|
-
function isEqual(a, b) {
|
|
505
|
-
return eq(a, b);
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Retrieve all the enumerable property names of an object.
|
|
509
|
-
function allKeys(obj) {
|
|
510
|
-
if (!isObject$1(obj)) return [];
|
|
511
|
-
var keys = [];
|
|
512
|
-
for (var key in obj) keys.push(key);
|
|
513
|
-
// Ahem, IE < 9.
|
|
514
|
-
if (hasEnumBug) collectNonEnumProps(obj, keys);
|
|
515
|
-
return keys;
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
// Since the regular `Object.prototype.toString` type tests don't work for
|
|
519
|
-
// some types in IE 11, we use a fingerprinting heuristic instead, based
|
|
520
|
-
// on the methods. It's not great, but it's the best we got.
|
|
521
|
-
// The fingerprint method lists are defined below.
|
|
522
|
-
function ie11fingerprint(methods) {
|
|
523
|
-
var length = getLength(methods);
|
|
524
|
-
return function(obj) {
|
|
525
|
-
if (obj == null) return false;
|
|
526
|
-
// `Map`, `WeakMap` and `Set` have no enumerable keys.
|
|
527
|
-
var keys = allKeys(obj);
|
|
528
|
-
if (getLength(keys)) return false;
|
|
529
|
-
for (var i = 0; i < length; i++) {
|
|
530
|
-
if (!isFunction$1(obj[methods[i]])) return false;
|
|
531
|
-
}
|
|
532
|
-
// If we are testing against `WeakMap`, we need to ensure that
|
|
533
|
-
// `obj` doesn't have a `forEach` method in order to distinguish
|
|
534
|
-
// it from a regular `Map`.
|
|
535
|
-
return methods !== weakMapMethods || !isFunction$1(obj[forEachName]);
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// In the interest of compact minification, we write
|
|
540
|
-
// each string in the fingerprints only once.
|
|
541
|
-
var forEachName = 'forEach',
|
|
542
|
-
hasName = 'has',
|
|
543
|
-
commonInit = ['clear', 'delete'],
|
|
544
|
-
mapTail = ['get', hasName, 'set'];
|
|
545
|
-
|
|
546
|
-
// `Map`, `WeakMap` and `Set` each have slightly different
|
|
547
|
-
// combinations of the above sublists.
|
|
548
|
-
var mapMethods = commonInit.concat(forEachName, mapTail),
|
|
549
|
-
weakMapMethods = commonInit.concat(mapTail),
|
|
550
|
-
setMethods = ['add'].concat(commonInit, forEachName, hasName);
|
|
551
|
-
|
|
552
|
-
var isMap = isIE11 ? ie11fingerprint(mapMethods) : tagTester('Map');
|
|
553
|
-
|
|
554
|
-
var isWeakMap = isIE11 ? ie11fingerprint(weakMapMethods) : tagTester('WeakMap');
|
|
555
|
-
|
|
556
|
-
var isSet = isIE11 ? ie11fingerprint(setMethods) : tagTester('Set');
|
|
557
|
-
|
|
558
|
-
var isWeakSet = tagTester('WeakSet');
|
|
559
|
-
|
|
560
|
-
// Retrieve the values of an object's properties.
|
|
561
|
-
function values(obj) {
|
|
562
|
-
var _keys = keys(obj);
|
|
563
|
-
var length = _keys.length;
|
|
564
|
-
var values = Array(length);
|
|
565
|
-
for (var i = 0; i < length; i++) {
|
|
566
|
-
values[i] = obj[_keys[i]];
|
|
567
|
-
}
|
|
568
|
-
return values;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
// Convert an object into a list of `[key, value]` pairs.
|
|
572
|
-
// The opposite of `_.object` with one argument.
|
|
573
|
-
function pairs(obj) {
|
|
574
|
-
var _keys = keys(obj);
|
|
575
|
-
var length = _keys.length;
|
|
576
|
-
var pairs = Array(length);
|
|
577
|
-
for (var i = 0; i < length; i++) {
|
|
578
|
-
pairs[i] = [_keys[i], obj[_keys[i]]];
|
|
579
|
-
}
|
|
580
|
-
return pairs;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// Invert the keys and values of an object. The values must be serializable.
|
|
584
|
-
function invert(obj) {
|
|
585
|
-
var result = {};
|
|
586
|
-
var _keys = keys(obj);
|
|
587
|
-
for (var i = 0, length = _keys.length; i < length; i++) {
|
|
588
|
-
result[obj[_keys[i]]] = _keys[i];
|
|
589
|
-
}
|
|
590
|
-
return result;
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
// Return a sorted list of the function names available on the object.
|
|
594
|
-
function functions(obj) {
|
|
595
|
-
var names = [];
|
|
596
|
-
for (var key in obj) {
|
|
597
|
-
if (isFunction$1(obj[key])) names.push(key);
|
|
598
|
-
}
|
|
599
|
-
return names.sort();
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
// An internal function for creating assigner functions.
|
|
603
|
-
function createAssigner(keysFunc, defaults) {
|
|
604
|
-
return function(obj) {
|
|
605
|
-
var length = arguments.length;
|
|
606
|
-
if (defaults) obj = Object(obj);
|
|
607
|
-
if (length < 2 || obj == null) return obj;
|
|
608
|
-
for (var index = 1; index < length; index++) {
|
|
609
|
-
var source = arguments[index],
|
|
610
|
-
keys = keysFunc(source),
|
|
611
|
-
l = keys.length;
|
|
612
|
-
for (var i = 0; i < l; i++) {
|
|
613
|
-
var key = keys[i];
|
|
614
|
-
if (!defaults || obj[key] === void 0) obj[key] = source[key];
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
return obj;
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// Extend a given object with all the properties in passed-in object(s).
|
|
622
|
-
var extend = createAssigner(allKeys);
|
|
623
|
-
|
|
624
|
-
// Assigns a given object with all the own properties in the passed-in
|
|
625
|
-
// object(s).
|
|
626
|
-
// (https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object/assign)
|
|
627
|
-
var extendOwn = createAssigner(keys);
|
|
628
|
-
|
|
629
|
-
// Fill in a given object with default properties.
|
|
630
|
-
var defaults = createAssigner(allKeys, true);
|
|
631
|
-
|
|
632
|
-
// Create a naked function reference for surrogate-prototype-swapping.
|
|
633
|
-
function ctor() {
|
|
634
|
-
return function(){};
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// An internal function for creating a new object that inherits from another.
|
|
638
|
-
function baseCreate(prototype) {
|
|
639
|
-
if (!isObject$1(prototype)) return {};
|
|
640
|
-
if (nativeCreate) return nativeCreate(prototype);
|
|
641
|
-
var Ctor = ctor();
|
|
642
|
-
Ctor.prototype = prototype;
|
|
643
|
-
var result = new Ctor;
|
|
644
|
-
Ctor.prototype = null;
|
|
645
|
-
return result;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
// Creates an object that inherits from the given prototype object.
|
|
649
|
-
// If additional properties are provided then they will be added to the
|
|
650
|
-
// created object.
|
|
651
|
-
function create(prototype, props) {
|
|
652
|
-
var result = baseCreate(prototype);
|
|
653
|
-
if (props) extendOwn(result, props);
|
|
654
|
-
return result;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// Create a (shallow-cloned) duplicate of an object.
|
|
658
|
-
function clone(obj) {
|
|
659
|
-
if (!isObject$1(obj)) return obj;
|
|
660
|
-
return isArray(obj) ? obj.slice() : extend({}, obj);
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// Invokes `interceptor` with the `obj` and then returns `obj`.
|
|
664
|
-
// The primary purpose of this method is to "tap into" a method chain, in
|
|
665
|
-
// order to perform operations on intermediate results within the chain.
|
|
666
|
-
function tap(obj, interceptor) {
|
|
667
|
-
interceptor(obj);
|
|
668
|
-
return obj;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
// Normalize a (deep) property `path` to array.
|
|
672
|
-
// Like `_.iteratee`, this function can be customized.
|
|
673
|
-
function toPath$1(path) {
|
|
674
|
-
return isArray(path) ? path : [path];
|
|
675
|
-
}
|
|
676
|
-
_$1.toPath = toPath$1;
|
|
677
|
-
|
|
678
|
-
// Internal wrapper for `_.toPath` to enable minification.
|
|
679
|
-
// Similar to `cb` for `_.iteratee`.
|
|
680
|
-
function toPath(path) {
|
|
681
|
-
return _$1.toPath(path);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
// Internal function to obtain a nested property in `obj` along `path`.
|
|
685
|
-
function deepGet(obj, path) {
|
|
686
|
-
var length = path.length;
|
|
687
|
-
for (var i = 0; i < length; i++) {
|
|
688
|
-
if (obj == null) return void 0;
|
|
689
|
-
obj = obj[path[i]];
|
|
690
|
-
}
|
|
691
|
-
return length ? obj : void 0;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
// Get the value of the (deep) property on `path` from `object`.
|
|
695
|
-
// If any property in `path` does not exist or if the value is
|
|
696
|
-
// `undefined`, return `defaultValue` instead.
|
|
697
|
-
// The `path` is normalized through `_.toPath`.
|
|
698
|
-
function get(object, path, defaultValue) {
|
|
699
|
-
var value = deepGet(object, toPath(path));
|
|
700
|
-
return isUndefined(value) ? defaultValue : value;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Shortcut function for checking if an object has a given property directly on
|
|
704
|
-
// itself (in other words, not on a prototype). Unlike the internal `has`
|
|
705
|
-
// function, this public version can also traverse nested properties.
|
|
706
|
-
function has(obj, path) {
|
|
707
|
-
path = toPath(path);
|
|
708
|
-
var length = path.length;
|
|
709
|
-
for (var i = 0; i < length; i++) {
|
|
710
|
-
var key = path[i];
|
|
711
|
-
if (!has$1(obj, key)) return false;
|
|
712
|
-
obj = obj[key];
|
|
713
|
-
}
|
|
714
|
-
return !!length;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// Keep the identity function around for default iteratees.
|
|
718
|
-
function identity(value) {
|
|
719
|
-
return value;
|
|
720
|
-
}
|
|
721
|
-
|
|
722
|
-
// Returns a predicate for checking whether an object has a given set of
|
|
723
|
-
// `key:value` pairs.
|
|
724
|
-
function matcher(attrs) {
|
|
725
|
-
attrs = extendOwn({}, attrs);
|
|
726
|
-
return function(obj) {
|
|
727
|
-
return isMatch(obj, attrs);
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// Creates a function that, when passed an object, will traverse that object’s
|
|
732
|
-
// properties down the given `path`, specified as an array of keys or indices.
|
|
733
|
-
function property(path) {
|
|
734
|
-
path = toPath(path);
|
|
735
|
-
return function(obj) {
|
|
736
|
-
return deepGet(obj, path);
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
// Internal function that returns an efficient (for current engines) version
|
|
741
|
-
// of the passed-in callback, to be repeatedly applied in other Underscore
|
|
742
|
-
// functions.
|
|
743
|
-
function optimizeCb(func, context, argCount) {
|
|
744
|
-
if (context === void 0) return func;
|
|
745
|
-
switch (argCount == null ? 3 : argCount) {
|
|
746
|
-
case 1: return function(value) {
|
|
747
|
-
return func.call(context, value);
|
|
748
|
-
};
|
|
749
|
-
// The 2-argument case is omitted because we’re not using it.
|
|
750
|
-
case 3: return function(value, index, collection) {
|
|
751
|
-
return func.call(context, value, index, collection);
|
|
752
|
-
};
|
|
753
|
-
case 4: return function(accumulator, value, index, collection) {
|
|
754
|
-
return func.call(context, accumulator, value, index, collection);
|
|
755
|
-
};
|
|
756
|
-
}
|
|
757
|
-
return function() {
|
|
758
|
-
return func.apply(context, arguments);
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
// An internal function to generate callbacks that can be applied to each
|
|
763
|
-
// element in a collection, returning the desired result — either `_.identity`,
|
|
764
|
-
// an arbitrary callback, a property matcher, or a property accessor.
|
|
765
|
-
function baseIteratee(value, context, argCount) {
|
|
766
|
-
if (value == null) return identity;
|
|
767
|
-
if (isFunction$1(value)) return optimizeCb(value, context, argCount);
|
|
768
|
-
if (isObject$1(value) && !isArray(value)) return matcher(value);
|
|
769
|
-
return property(value);
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
// External wrapper for our callback generator. Users may customize
|
|
773
|
-
// `_.iteratee` if they want additional predicate/iteratee shorthand styles.
|
|
774
|
-
// This abstraction hides the internal-only `argCount` argument.
|
|
775
|
-
function iteratee(value, context) {
|
|
776
|
-
return baseIteratee(value, context, Infinity);
|
|
777
|
-
}
|
|
778
|
-
_$1.iteratee = iteratee;
|
|
779
|
-
|
|
780
|
-
// The function we call internally to generate a callback. It invokes
|
|
781
|
-
// `_.iteratee` if overridden, otherwise `baseIteratee`.
|
|
782
|
-
function cb(value, context, argCount) {
|
|
783
|
-
if (_$1.iteratee !== iteratee) return _$1.iteratee(value, context);
|
|
784
|
-
return baseIteratee(value, context, argCount);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
// Returns the results of applying the `iteratee` to each element of `obj`.
|
|
788
|
-
// In contrast to `_.map` it returns an object.
|
|
789
|
-
function mapObject$1(obj, iteratee, context) {
|
|
790
|
-
iteratee = cb(iteratee, context);
|
|
791
|
-
var _keys = keys(obj),
|
|
792
|
-
length = _keys.length,
|
|
793
|
-
results = {};
|
|
794
|
-
for (var index = 0; index < length; index++) {
|
|
795
|
-
var currentKey = _keys[index];
|
|
796
|
-
results[currentKey] = iteratee(obj[currentKey], currentKey, obj);
|
|
797
|
-
}
|
|
798
|
-
return results;
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// Predicate-generating function. Often useful outside of Underscore.
|
|
802
|
-
function noop(){}
|
|
803
|
-
|
|
804
|
-
// Generates a function for a given object that returns a given property.
|
|
805
|
-
function propertyOf(obj) {
|
|
806
|
-
if (obj == null) return noop;
|
|
807
|
-
return function(path) {
|
|
808
|
-
return get(obj, path);
|
|
809
|
-
};
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
// Run a function **n** times.
|
|
813
|
-
function times(n, iteratee, context) {
|
|
814
|
-
var accum = Array(Math.max(0, n));
|
|
815
|
-
iteratee = optimizeCb(iteratee, context, 1);
|
|
816
|
-
for (var i = 0; i < n; i++) accum[i] = iteratee(i);
|
|
817
|
-
return accum;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
// Return a random integer between `min` and `max` (inclusive).
|
|
821
|
-
function random(min, max) {
|
|
822
|
-
if (max == null) {
|
|
823
|
-
max = min;
|
|
824
|
-
min = 0;
|
|
825
|
-
}
|
|
826
|
-
return min + Math.floor(Math.random() * (max - min + 1));
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
// A (possibly faster) way to get the current timestamp as an integer.
|
|
830
|
-
var now = Date.now || function() {
|
|
831
|
-
return new Date().getTime();
|
|
832
|
-
};
|
|
833
|
-
|
|
834
|
-
// Internal helper to generate functions for escaping and unescaping strings
|
|
835
|
-
// to/from HTML interpolation.
|
|
836
|
-
function createEscaper(map) {
|
|
837
|
-
var escaper = function(match) {
|
|
838
|
-
return map[match];
|
|
839
|
-
};
|
|
840
|
-
// Regexes for identifying a key that needs to be escaped.
|
|
841
|
-
var source = '(?:' + keys(map).join('|') + ')';
|
|
842
|
-
var testRegexp = RegExp(source);
|
|
843
|
-
var replaceRegexp = RegExp(source, 'g');
|
|
844
|
-
return function(string) {
|
|
845
|
-
string = string == null ? '' : '' + string;
|
|
846
|
-
return testRegexp.test(string) ? string.replace(replaceRegexp, escaper) : string;
|
|
847
|
-
};
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
// Internal list of HTML entities for escaping.
|
|
851
|
-
var escapeMap = {
|
|
852
|
-
'&': '&',
|
|
853
|
-
'<': '<',
|
|
854
|
-
'>': '>',
|
|
855
|
-
'"': '"',
|
|
856
|
-
"'": ''',
|
|
857
|
-
'`': '`'
|
|
858
|
-
};
|
|
859
|
-
|
|
860
|
-
// Function for escaping strings to HTML interpolation.
|
|
861
|
-
var escape = createEscaper(escapeMap);
|
|
862
|
-
|
|
863
|
-
// Internal list of HTML entities for unescaping.
|
|
864
|
-
var unescapeMap = invert(escapeMap);
|
|
865
|
-
|
|
866
|
-
// Function for unescaping strings from HTML interpolation.
|
|
867
|
-
var unescape = createEscaper(unescapeMap);
|
|
868
|
-
|
|
869
|
-
// By default, Underscore uses ERB-style template delimiters. Change the
|
|
870
|
-
// following template settings to use alternative delimiters.
|
|
871
|
-
var templateSettings = _$1.templateSettings = {
|
|
872
|
-
evaluate: /<%([\s\S]+?)%>/g,
|
|
873
|
-
interpolate: /<%=([\s\S]+?)%>/g,
|
|
874
|
-
escape: /<%-([\s\S]+?)%>/g
|
|
875
|
-
};
|
|
876
|
-
|
|
877
|
-
// When customizing `_.templateSettings`, if you don't want to define an
|
|
878
|
-
// interpolation, evaluation or escaping regex, we need one that is
|
|
879
|
-
// guaranteed not to match.
|
|
880
|
-
var noMatch = /(.)^/;
|
|
881
|
-
|
|
882
|
-
// Certain characters need to be escaped so that they can be put into a
|
|
883
|
-
// string literal.
|
|
884
|
-
var escapes = {
|
|
885
|
-
"'": "'",
|
|
886
|
-
'\\': '\\',
|
|
887
|
-
'\r': 'r',
|
|
888
|
-
'\n': 'n',
|
|
889
|
-
'\u2028': 'u2028',
|
|
890
|
-
'\u2029': 'u2029'
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
var escapeRegExp = /\\|'|\r|\n|\u2028|\u2029/g;
|
|
894
|
-
|
|
895
|
-
function escapeChar(match) {
|
|
896
|
-
return '\\' + escapes[match];
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
// In order to prevent third-party code injection through
|
|
900
|
-
// `_.templateSettings.variable`, we test it against the following regular
|
|
901
|
-
// expression. It is intentionally a bit more liberal than just matching valid
|
|
902
|
-
// identifiers, but still prevents possible loopholes through defaults or
|
|
903
|
-
// destructuring assignment.
|
|
904
|
-
var bareIdentifier = /^\s*(\w|\$)+\s*$/;
|
|
905
|
-
|
|
906
|
-
// JavaScript micro-templating, similar to John Resig's implementation.
|
|
907
|
-
// Underscore templating handles arbitrary delimiters, preserves whitespace,
|
|
908
|
-
// and correctly escapes quotes within interpolated code.
|
|
909
|
-
// NB: `oldSettings` only exists for backwards compatibility.
|
|
910
|
-
function template(text, settings, oldSettings) {
|
|
911
|
-
if (!settings && oldSettings) settings = oldSettings;
|
|
912
|
-
settings = defaults({}, settings, _$1.templateSettings);
|
|
913
|
-
|
|
914
|
-
// Combine delimiters into one regular expression via alternation.
|
|
915
|
-
var matcher = RegExp([
|
|
916
|
-
(settings.escape || noMatch).source,
|
|
917
|
-
(settings.interpolate || noMatch).source,
|
|
918
|
-
(settings.evaluate || noMatch).source
|
|
919
|
-
].join('|') + '|$', 'g');
|
|
920
|
-
|
|
921
|
-
// Compile the template source, escaping string literals appropriately.
|
|
922
|
-
var index = 0;
|
|
923
|
-
var source = "__p+='";
|
|
924
|
-
text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
|
|
925
|
-
source += text.slice(index, offset).replace(escapeRegExp, escapeChar);
|
|
926
|
-
index = offset + match.length;
|
|
927
|
-
|
|
928
|
-
if (escape) {
|
|
929
|
-
source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
|
|
930
|
-
} else if (interpolate) {
|
|
931
|
-
source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
|
|
932
|
-
} else if (evaluate) {
|
|
933
|
-
source += "';\n" + evaluate + "\n__p+='";
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
// Adobe VMs need the match returned to produce the correct offset.
|
|
937
|
-
return match;
|
|
938
|
-
});
|
|
939
|
-
source += "';\n";
|
|
940
|
-
|
|
941
|
-
var argument = settings.variable;
|
|
942
|
-
if (argument) {
|
|
943
|
-
// Insure against third-party code injection. (CVE-2021-23358)
|
|
944
|
-
if (!bareIdentifier.test(argument)) throw new Error(
|
|
945
|
-
'variable is not a bare identifier: ' + argument
|
|
946
|
-
);
|
|
947
|
-
} else {
|
|
948
|
-
// If a variable is not specified, place data values in local scope.
|
|
949
|
-
source = 'with(obj||{}){\n' + source + '}\n';
|
|
950
|
-
argument = 'obj';
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
source = "var __t,__p='',__j=Array.prototype.join," +
|
|
954
|
-
"print=function(){__p+=__j.call(arguments,'');};\n" +
|
|
955
|
-
source + 'return __p;\n';
|
|
956
|
-
|
|
957
|
-
var render;
|
|
958
|
-
try {
|
|
959
|
-
render = new Function(argument, '_', source);
|
|
960
|
-
} catch (e) {
|
|
961
|
-
e.source = source;
|
|
962
|
-
throw e;
|
|
963
|
-
}
|
|
964
|
-
|
|
965
|
-
var template = function(data) {
|
|
966
|
-
return render.call(this, data, _$1);
|
|
967
|
-
};
|
|
968
|
-
|
|
969
|
-
// Provide the compiled source as a convenience for precompilation.
|
|
970
|
-
template.source = 'function(' + argument + '){\n' + source + '}';
|
|
971
|
-
|
|
972
|
-
return template;
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// Traverses the children of `obj` along `path`. If a child is a function, it
|
|
976
|
-
// is invoked with its parent as context. Returns the value of the final
|
|
977
|
-
// child, or `fallback` if any child is undefined.
|
|
978
|
-
function result(obj, path, fallback) {
|
|
979
|
-
path = toPath(path);
|
|
980
|
-
var length = path.length;
|
|
981
|
-
if (!length) {
|
|
982
|
-
return isFunction$1(fallback) ? fallback.call(obj) : fallback;
|
|
983
|
-
}
|
|
984
|
-
for (var i = 0; i < length; i++) {
|
|
985
|
-
var prop = obj == null ? void 0 : obj[path[i]];
|
|
986
|
-
if (prop === void 0) {
|
|
987
|
-
prop = fallback;
|
|
988
|
-
i = length; // Ensure we don't continue iterating.
|
|
989
|
-
}
|
|
990
|
-
obj = isFunction$1(prop) ? prop.call(obj) : prop;
|
|
991
|
-
}
|
|
992
|
-
return obj;
|
|
993
|
-
}
|
|
994
|
-
|
|
995
|
-
// Generate a unique integer id (unique within the entire client session).
|
|
996
|
-
// Useful for temporary DOM ids.
|
|
997
|
-
var idCounter = 0;
|
|
998
|
-
function uniqueId(prefix) {
|
|
999
|
-
var id = ++idCounter + '';
|
|
1000
|
-
return prefix ? prefix + id : id;
|
|
1001
|
-
}
|
|
1002
|
-
|
|
1003
|
-
// Start chaining a wrapped Underscore object.
|
|
1004
|
-
function chain(obj) {
|
|
1005
|
-
var instance = _$1(obj);
|
|
1006
|
-
instance._chain = true;
|
|
1007
|
-
return instance;
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
// Internal function to execute `sourceFunc` bound to `context` with optional
|
|
1011
|
-
// `args`. Determines whether to execute a function as a constructor or as a
|
|
1012
|
-
// normal function.
|
|
1013
|
-
function executeBound(sourceFunc, boundFunc, context, callingContext, args) {
|
|
1014
|
-
if (!(callingContext instanceof boundFunc)) return sourceFunc.apply(context, args);
|
|
1015
|
-
var self = baseCreate(sourceFunc.prototype);
|
|
1016
|
-
var result = sourceFunc.apply(self, args);
|
|
1017
|
-
if (isObject$1(result)) return result;
|
|
1018
|
-
return self;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
// Partially apply a function by creating a version that has had some of its
|
|
1022
|
-
// arguments pre-filled, without changing its dynamic `this` context. `_` acts
|
|
1023
|
-
// as a placeholder by default, allowing any combination of arguments to be
|
|
1024
|
-
// pre-filled. Set `_.partial.placeholder` for a custom placeholder argument.
|
|
1025
|
-
var partial = restArguments(function(func, boundArgs) {
|
|
1026
|
-
var placeholder = partial.placeholder;
|
|
1027
|
-
var bound = function() {
|
|
1028
|
-
var position = 0, length = boundArgs.length;
|
|
1029
|
-
var args = Array(length);
|
|
1030
|
-
for (var i = 0; i < length; i++) {
|
|
1031
|
-
args[i] = boundArgs[i] === placeholder ? arguments[position++] : boundArgs[i];
|
|
1032
|
-
}
|
|
1033
|
-
while (position < arguments.length) args.push(arguments[position++]);
|
|
1034
|
-
return executeBound(func, bound, this, this, args);
|
|
1035
|
-
};
|
|
1036
|
-
return bound;
|
|
1037
|
-
});
|
|
1038
|
-
|
|
1039
|
-
partial.placeholder = _$1;
|
|
1040
|
-
|
|
1041
|
-
// Create a function bound to a given object (assigning `this`, and arguments,
|
|
1042
|
-
// optionally).
|
|
1043
|
-
var bind = restArguments(function(func, context, args) {
|
|
1044
|
-
if (!isFunction$1(func)) throw new TypeError('Bind must be called on a function');
|
|
1045
|
-
var bound = restArguments(function(callArgs) {
|
|
1046
|
-
return executeBound(func, bound, context, this, args.concat(callArgs));
|
|
1047
|
-
});
|
|
1048
|
-
return bound;
|
|
1049
|
-
});
|
|
1050
|
-
|
|
1051
|
-
// Internal helper for collection methods to determine whether a collection
|
|
1052
|
-
// should be iterated as an array or as an object.
|
|
1053
|
-
// Related: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength
|
|
1054
|
-
// Avoids a very nasty iOS 8 JIT bug on ARM-64. #2094
|
|
1055
|
-
var isArrayLike = createSizePropertyCheck(getLength);
|
|
1056
|
-
|
|
1057
|
-
// Internal implementation of a recursive `flatten` function.
|
|
1058
|
-
function flatten$1(input, depth, strict, output) {
|
|
1059
|
-
output = output || [];
|
|
1060
|
-
if (!depth && depth !== 0) {
|
|
1061
|
-
depth = Infinity;
|
|
1062
|
-
} else if (depth <= 0) {
|
|
1063
|
-
return output.concat(input);
|
|
1064
|
-
}
|
|
1065
|
-
var idx = output.length;
|
|
1066
|
-
for (var i = 0, length = getLength(input); i < length; i++) {
|
|
1067
|
-
var value = input[i];
|
|
1068
|
-
if (isArrayLike(value) && (isArray(value) || isArguments$1(value))) {
|
|
1069
|
-
// Flatten current level of array or arguments object.
|
|
1070
|
-
if (depth > 1) {
|
|
1071
|
-
flatten$1(value, depth - 1, strict, output);
|
|
1072
|
-
idx = output.length;
|
|
1073
|
-
} else {
|
|
1074
|
-
var j = 0, len = value.length;
|
|
1075
|
-
while (j < len) output[idx++] = value[j++];
|
|
1076
|
-
}
|
|
1077
|
-
} else if (!strict) {
|
|
1078
|
-
output[idx++] = value;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
return output;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
// Bind a number of an object's methods to that object. Remaining arguments
|
|
1085
|
-
// are the method names to be bound. Useful for ensuring that all callbacks
|
|
1086
|
-
// defined on an object belong to it.
|
|
1087
|
-
var bindAll = restArguments(function(obj, keys) {
|
|
1088
|
-
keys = flatten$1(keys, false, false);
|
|
1089
|
-
var index = keys.length;
|
|
1090
|
-
if (index < 1) throw new Error('bindAll must be passed function names');
|
|
1091
|
-
while (index--) {
|
|
1092
|
-
var key = keys[index];
|
|
1093
|
-
obj[key] = bind(obj[key], obj);
|
|
1094
|
-
}
|
|
1095
|
-
return obj;
|
|
1096
|
-
});
|
|
1097
|
-
|
|
1098
|
-
// Memoize an expensive function by storing its results.
|
|
1099
|
-
function memoize(func, hasher) {
|
|
1100
|
-
var memoize = function(key) {
|
|
1101
|
-
var cache = memoize.cache;
|
|
1102
|
-
var address = '' + (hasher ? hasher.apply(this, arguments) : key);
|
|
1103
|
-
if (!has$1(cache, address)) cache[address] = func.apply(this, arguments);
|
|
1104
|
-
return cache[address];
|
|
1105
|
-
};
|
|
1106
|
-
memoize.cache = {};
|
|
1107
|
-
return memoize;
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
// Delays a function for the given number of milliseconds, and then calls
|
|
1111
|
-
// it with the arguments supplied.
|
|
1112
|
-
var delay = restArguments(function(func, wait, args) {
|
|
1113
|
-
return setTimeout(function() {
|
|
1114
|
-
return func.apply(null, args);
|
|
1115
|
-
}, wait);
|
|
1116
|
-
});
|
|
1117
|
-
|
|
1118
|
-
// Defers a function, scheduling it to run after the current call stack has
|
|
1119
|
-
// cleared.
|
|
1120
|
-
var defer = partial(delay, _$1, 1);
|
|
1121
|
-
|
|
1122
|
-
// Returns a function, that, when invoked, will only be triggered at most once
|
|
1123
|
-
// during a given window of time. Normally, the throttled function will run
|
|
1124
|
-
// as much as it can, without ever going more than once per `wait` duration;
|
|
1125
|
-
// but if you'd like to disable the execution on the leading edge, pass
|
|
1126
|
-
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
|
1127
|
-
function throttle(func, wait, options) {
|
|
1128
|
-
var timeout, context, args, result;
|
|
1129
|
-
var previous = 0;
|
|
1130
|
-
if (!options) options = {};
|
|
1131
|
-
|
|
1132
|
-
var later = function() {
|
|
1133
|
-
previous = options.leading === false ? 0 : now();
|
|
1134
|
-
timeout = null;
|
|
1135
|
-
result = func.apply(context, args);
|
|
1136
|
-
if (!timeout) context = args = null;
|
|
1137
|
-
};
|
|
1138
|
-
|
|
1139
|
-
var throttled = function() {
|
|
1140
|
-
var _now = now();
|
|
1141
|
-
if (!previous && options.leading === false) previous = _now;
|
|
1142
|
-
var remaining = wait - (_now - previous);
|
|
1143
|
-
context = this;
|
|
1144
|
-
args = arguments;
|
|
1145
|
-
if (remaining <= 0 || remaining > wait) {
|
|
1146
|
-
if (timeout) {
|
|
1147
|
-
clearTimeout(timeout);
|
|
1148
|
-
timeout = null;
|
|
1149
|
-
}
|
|
1150
|
-
previous = _now;
|
|
1151
|
-
result = func.apply(context, args);
|
|
1152
|
-
if (!timeout) context = args = null;
|
|
1153
|
-
} else if (!timeout && options.trailing !== false) {
|
|
1154
|
-
timeout = setTimeout(later, remaining);
|
|
1155
|
-
}
|
|
1156
|
-
return result;
|
|
1157
|
-
};
|
|
1158
|
-
|
|
1159
|
-
throttled.cancel = function() {
|
|
1160
|
-
clearTimeout(timeout);
|
|
1161
|
-
previous = 0;
|
|
1162
|
-
timeout = context = args = null;
|
|
1163
|
-
};
|
|
1164
|
-
|
|
1165
|
-
return throttled;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
// When a sequence of calls of the returned function ends, the argument
|
|
1169
|
-
// function is triggered. The end of a sequence is defined by the `wait`
|
|
1170
|
-
// parameter. If `immediate` is passed, the argument function will be
|
|
1171
|
-
// triggered at the beginning of the sequence instead of at the end.
|
|
1172
|
-
function debounce(func, wait, immediate) {
|
|
1173
|
-
var timeout, previous, args, result, context;
|
|
1174
|
-
|
|
1175
|
-
var later = function() {
|
|
1176
|
-
var passed = now() - previous;
|
|
1177
|
-
if (wait > passed) {
|
|
1178
|
-
timeout = setTimeout(later, wait - passed);
|
|
1179
|
-
} else {
|
|
1180
|
-
timeout = null;
|
|
1181
|
-
if (!immediate) result = func.apply(context, args);
|
|
1182
|
-
// This check is needed because `func` can recursively invoke `debounced`.
|
|
1183
|
-
if (!timeout) args = context = null;
|
|
1184
|
-
}
|
|
1185
|
-
};
|
|
1186
|
-
|
|
1187
|
-
var debounced = restArguments(function(_args) {
|
|
1188
|
-
context = this;
|
|
1189
|
-
args = _args;
|
|
1190
|
-
previous = now();
|
|
1191
|
-
if (!timeout) {
|
|
1192
|
-
timeout = setTimeout(later, wait);
|
|
1193
|
-
if (immediate) result = func.apply(context, args);
|
|
1194
|
-
}
|
|
1195
|
-
return result;
|
|
1196
|
-
});
|
|
1197
|
-
|
|
1198
|
-
debounced.cancel = function() {
|
|
1199
|
-
clearTimeout(timeout);
|
|
1200
|
-
timeout = args = context = null;
|
|
1201
|
-
};
|
|
1202
|
-
|
|
1203
|
-
return debounced;
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
// Returns the first function passed as an argument to the second,
|
|
1207
|
-
// allowing you to adjust arguments, run code before and after, and
|
|
1208
|
-
// conditionally execute the original function.
|
|
1209
|
-
function wrap(func, wrapper) {
|
|
1210
|
-
return partial(wrapper, func);
|
|
1211
|
-
}
|
|
1212
|
-
|
|
1213
|
-
// Returns a negated version of the passed-in predicate.
|
|
1214
|
-
function negate(predicate) {
|
|
1215
|
-
return function() {
|
|
1216
|
-
return !predicate.apply(this, arguments);
|
|
1217
|
-
};
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
// Returns a function that is the composition of a list of functions, each
|
|
1221
|
-
// consuming the return value of the function that follows.
|
|
1222
|
-
function compose() {
|
|
1223
|
-
var args = arguments;
|
|
1224
|
-
var start = args.length - 1;
|
|
1225
|
-
return function() {
|
|
1226
|
-
var i = start;
|
|
1227
|
-
var result = args[start].apply(this, arguments);
|
|
1228
|
-
while (i--) result = args[i].call(this, result);
|
|
1229
|
-
return result;
|
|
1230
|
-
};
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
// Returns a function that will only be executed on and after the Nth call.
|
|
1234
|
-
function after(times, func) {
|
|
1235
|
-
return function() {
|
|
1236
|
-
if (--times < 1) {
|
|
1237
|
-
return func.apply(this, arguments);
|
|
1238
|
-
}
|
|
1239
|
-
};
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
// Returns a function that will only be executed up to (but not including) the
|
|
1243
|
-
// Nth call.
|
|
1244
|
-
function before(times, func) {
|
|
1245
|
-
var memo;
|
|
1246
|
-
return function() {
|
|
1247
|
-
if (--times > 0) {
|
|
1248
|
-
memo = func.apply(this, arguments);
|
|
1249
|
-
}
|
|
1250
|
-
if (times <= 1) func = null;
|
|
1251
|
-
return memo;
|
|
1252
|
-
};
|
|
1253
|
-
}
|
|
1254
|
-
|
|
1255
|
-
// Returns a function that will be executed at most one time, no matter how
|
|
1256
|
-
// often you call it. Useful for lazy initialization.
|
|
1257
|
-
var once = partial(before, 2);
|
|
1258
|
-
|
|
1259
|
-
// Returns the first key on an object that passes a truth test.
|
|
1260
|
-
function findKey(obj, predicate, context) {
|
|
1261
|
-
predicate = cb(predicate, context);
|
|
1262
|
-
var _keys = keys(obj), key;
|
|
1263
|
-
for (var i = 0, length = _keys.length; i < length; i++) {
|
|
1264
|
-
key = _keys[i];
|
|
1265
|
-
if (predicate(obj[key], key, obj)) return key;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// Internal function to generate `_.findIndex` and `_.findLastIndex`.
|
|
1270
|
-
function createPredicateIndexFinder(dir) {
|
|
1271
|
-
return function(array, predicate, context) {
|
|
1272
|
-
predicate = cb(predicate, context);
|
|
1273
|
-
var length = getLength(array);
|
|
1274
|
-
var index = dir > 0 ? 0 : length - 1;
|
|
1275
|
-
for (; index >= 0 && index < length; index += dir) {
|
|
1276
|
-
if (predicate(array[index], index, array)) return index;
|
|
1277
|
-
}
|
|
1278
|
-
return -1;
|
|
1279
|
-
};
|
|
1280
|
-
}
|
|
1281
|
-
|
|
1282
|
-
// Returns the first index on an array-like that passes a truth test.
|
|
1283
|
-
var findIndex = createPredicateIndexFinder(1);
|
|
1284
|
-
|
|
1285
|
-
// Returns the last index on an array-like that passes a truth test.
|
|
1286
|
-
var findLastIndex = createPredicateIndexFinder(-1);
|
|
1287
|
-
|
|
1288
|
-
// Use a comparator function to figure out the smallest index at which
|
|
1289
|
-
// an object should be inserted so as to maintain order. Uses binary search.
|
|
1290
|
-
function sortedIndex(array, obj, iteratee, context) {
|
|
1291
|
-
iteratee = cb(iteratee, context, 1);
|
|
1292
|
-
var value = iteratee(obj);
|
|
1293
|
-
var low = 0, high = getLength(array);
|
|
1294
|
-
while (low < high) {
|
|
1295
|
-
var mid = Math.floor((low + high) / 2);
|
|
1296
|
-
if (iteratee(array[mid]) < value) low = mid + 1; else high = mid;
|
|
1297
|
-
}
|
|
1298
|
-
return low;
|
|
1299
|
-
}
|
|
1300
|
-
|
|
1301
|
-
// Internal function to generate the `_.indexOf` and `_.lastIndexOf` functions.
|
|
1302
|
-
function createIndexFinder(dir, predicateFind, sortedIndex) {
|
|
1303
|
-
return function(array, item, idx) {
|
|
1304
|
-
var i = 0, length = getLength(array);
|
|
1305
|
-
if (typeof idx == 'number') {
|
|
1306
|
-
if (dir > 0) {
|
|
1307
|
-
i = idx >= 0 ? idx : Math.max(idx + length, i);
|
|
1308
|
-
} else {
|
|
1309
|
-
length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
|
|
1310
|
-
}
|
|
1311
|
-
} else if (sortedIndex && idx && length) {
|
|
1312
|
-
idx = sortedIndex(array, item);
|
|
1313
|
-
return array[idx] === item ? idx : -1;
|
|
1314
|
-
}
|
|
1315
|
-
if (item !== item) {
|
|
1316
|
-
idx = predicateFind(slice.call(array, i, length), isNaN$1);
|
|
1317
|
-
return idx >= 0 ? idx + i : -1;
|
|
1318
|
-
}
|
|
1319
|
-
for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
|
|
1320
|
-
if (array[idx] === item) return idx;
|
|
1321
|
-
}
|
|
1322
|
-
return -1;
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
// Return the position of the first occurrence of an item in an array,
|
|
1327
|
-
// or -1 if the item is not included in the array.
|
|
1328
|
-
// If the array is large and already in sort order, pass `true`
|
|
1329
|
-
// for **isSorted** to use binary search.
|
|
1330
|
-
var indexOf = createIndexFinder(1, findIndex, sortedIndex);
|
|
1331
|
-
|
|
1332
|
-
// Return the position of the last occurrence of an item in an array,
|
|
1333
|
-
// or -1 if the item is not included in the array.
|
|
1334
|
-
var lastIndexOf = createIndexFinder(-1, findLastIndex);
|
|
1335
|
-
|
|
1336
|
-
// Return the first value which passes a truth test.
|
|
1337
|
-
function find(obj, predicate, context) {
|
|
1338
|
-
var keyFinder = isArrayLike(obj) ? findIndex : findKey;
|
|
1339
|
-
var key = keyFinder(obj, predicate, context);
|
|
1340
|
-
if (key !== void 0 && key !== -1) return obj[key];
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1343
|
-
// Convenience version of a common use case of `_.find`: getting the first
|
|
1344
|
-
// object containing specific `key:value` pairs.
|
|
1345
|
-
function findWhere(obj, attrs) {
|
|
1346
|
-
return find(obj, matcher(attrs));
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
// The cornerstone for collection functions, an `each`
|
|
1350
|
-
// implementation, aka `forEach`.
|
|
1351
|
-
// Handles raw objects in addition to array-likes. Treats all
|
|
1352
|
-
// sparse array-likes as if they were dense.
|
|
1353
|
-
function each(obj, iteratee, context) {
|
|
1354
|
-
iteratee = optimizeCb(iteratee, context);
|
|
1355
|
-
var i, length;
|
|
1356
|
-
if (isArrayLike(obj)) {
|
|
1357
|
-
for (i = 0, length = obj.length; i < length; i++) {
|
|
1358
|
-
iteratee(obj[i], i, obj);
|
|
1359
|
-
}
|
|
1360
|
-
} else {
|
|
1361
|
-
var _keys = keys(obj);
|
|
1362
|
-
for (i = 0, length = _keys.length; i < length; i++) {
|
|
1363
|
-
iteratee(obj[_keys[i]], _keys[i], obj);
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
return obj;
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
// Return the results of applying the iteratee to each element.
|
|
1370
|
-
function map(obj, iteratee, context) {
|
|
1371
|
-
iteratee = cb(iteratee, context);
|
|
1372
|
-
var _keys = !isArrayLike(obj) && keys(obj),
|
|
1373
|
-
length = (_keys || obj).length,
|
|
1374
|
-
results = Array(length);
|
|
1375
|
-
for (var index = 0; index < length; index++) {
|
|
1376
|
-
var currentKey = _keys ? _keys[index] : index;
|
|
1377
|
-
results[index] = iteratee(obj[currentKey], currentKey, obj);
|
|
1378
|
-
}
|
|
1379
|
-
return results;
|
|
1380
|
-
}
|
|
1381
|
-
|
|
1382
|
-
// Internal helper to create a reducing function, iterating left or right.
|
|
1383
|
-
function createReduce(dir) {
|
|
1384
|
-
// Wrap code that reassigns argument variables in a separate function than
|
|
1385
|
-
// the one that accesses `arguments.length` to avoid a perf hit. (#1991)
|
|
1386
|
-
var reducer = function(obj, iteratee, memo, initial) {
|
|
1387
|
-
var _keys = !isArrayLike(obj) && keys(obj),
|
|
1388
|
-
length = (_keys || obj).length,
|
|
1389
|
-
index = dir > 0 ? 0 : length - 1;
|
|
1390
|
-
if (!initial) {
|
|
1391
|
-
memo = obj[_keys ? _keys[index] : index];
|
|
1392
|
-
index += dir;
|
|
1393
|
-
}
|
|
1394
|
-
for (; index >= 0 && index < length; index += dir) {
|
|
1395
|
-
var currentKey = _keys ? _keys[index] : index;
|
|
1396
|
-
memo = iteratee(memo, obj[currentKey], currentKey, obj);
|
|
1397
|
-
}
|
|
1398
|
-
return memo;
|
|
1399
|
-
};
|
|
1400
|
-
|
|
1401
|
-
return function(obj, iteratee, memo, context) {
|
|
1402
|
-
var initial = arguments.length >= 3;
|
|
1403
|
-
return reducer(obj, optimizeCb(iteratee, context, 4), memo, initial);
|
|
1404
|
-
};
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
// **Reduce** builds up a single result from a list of values, aka `inject`,
|
|
1408
|
-
// or `foldl`.
|
|
1409
|
-
var reduce = createReduce(1);
|
|
1410
|
-
|
|
1411
|
-
// The right-associative version of reduce, also known as `foldr`.
|
|
1412
|
-
var reduceRight = createReduce(-1);
|
|
1413
|
-
|
|
1414
|
-
// Return all the elements that pass a truth test.
|
|
1415
|
-
function filter(obj, predicate, context) {
|
|
1416
|
-
var results = [];
|
|
1417
|
-
predicate = cb(predicate, context);
|
|
1418
|
-
each(obj, function(value, index, list) {
|
|
1419
|
-
if (predicate(value, index, list)) results.push(value);
|
|
1420
|
-
});
|
|
1421
|
-
return results;
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
// Return all the elements for which a truth test fails.
|
|
1425
|
-
function reject(obj, predicate, context) {
|
|
1426
|
-
return filter(obj, negate(cb(predicate)), context);
|
|
1427
|
-
}
|
|
1428
|
-
|
|
1429
|
-
// Determine whether all of the elements pass a truth test.
|
|
1430
|
-
function every(obj, predicate, context) {
|
|
1431
|
-
predicate = cb(predicate, context);
|
|
1432
|
-
var _keys = !isArrayLike(obj) && keys(obj),
|
|
1433
|
-
length = (_keys || obj).length;
|
|
1434
|
-
for (var index = 0; index < length; index++) {
|
|
1435
|
-
var currentKey = _keys ? _keys[index] : index;
|
|
1436
|
-
if (!predicate(obj[currentKey], currentKey, obj)) return false;
|
|
1437
|
-
}
|
|
1438
|
-
return true;
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
// Determine if at least one element in the object passes a truth test.
|
|
1442
|
-
function some(obj, predicate, context) {
|
|
1443
|
-
predicate = cb(predicate, context);
|
|
1444
|
-
var _keys = !isArrayLike(obj) && keys(obj),
|
|
1445
|
-
length = (_keys || obj).length;
|
|
1446
|
-
for (var index = 0; index < length; index++) {
|
|
1447
|
-
var currentKey = _keys ? _keys[index] : index;
|
|
1448
|
-
if (predicate(obj[currentKey], currentKey, obj)) return true;
|
|
1449
|
-
}
|
|
1450
|
-
return false;
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
// Determine if the array or object contains a given item (using `===`).
|
|
1454
|
-
function contains(obj, item, fromIndex, guard) {
|
|
1455
|
-
if (!isArrayLike(obj)) obj = values(obj);
|
|
1456
|
-
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
|
|
1457
|
-
return indexOf(obj, item, fromIndex) >= 0;
|
|
1458
|
-
}
|
|
1459
|
-
|
|
1460
|
-
// Invoke a method (with arguments) on every item in a collection.
|
|
1461
|
-
var invoke = restArguments(function(obj, path, args) {
|
|
1462
|
-
var contextPath, func;
|
|
1463
|
-
if (isFunction$1(path)) {
|
|
1464
|
-
func = path;
|
|
1465
|
-
} else {
|
|
1466
|
-
path = toPath(path);
|
|
1467
|
-
contextPath = path.slice(0, -1);
|
|
1468
|
-
path = path[path.length - 1];
|
|
1469
|
-
}
|
|
1470
|
-
return map(obj, function(context) {
|
|
1471
|
-
var method = func;
|
|
1472
|
-
if (!method) {
|
|
1473
|
-
if (contextPath && contextPath.length) {
|
|
1474
|
-
context = deepGet(context, contextPath);
|
|
1475
|
-
}
|
|
1476
|
-
if (context == null) return void 0;
|
|
1477
|
-
method = context[path];
|
|
1478
|
-
}
|
|
1479
|
-
return method == null ? method : method.apply(context, args);
|
|
1480
|
-
});
|
|
1481
|
-
});
|
|
1482
|
-
|
|
1483
|
-
// Convenience version of a common use case of `_.map`: fetching a property.
|
|
1484
|
-
function pluck$1(obj, key) {
|
|
1485
|
-
return map(obj, property(key));
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
// Convenience version of a common use case of `_.filter`: selecting only
|
|
1489
|
-
// objects containing specific `key:value` pairs.
|
|
1490
|
-
function where(obj, attrs) {
|
|
1491
|
-
return filter(obj, matcher(attrs));
|
|
1492
|
-
}
|
|
1493
|
-
|
|
1494
|
-
// Return the maximum element (or element-based computation).
|
|
1495
|
-
function max(obj, iteratee, context) {
|
|
1496
|
-
var result = -Infinity, lastComputed = -Infinity,
|
|
1497
|
-
value, computed;
|
|
1498
|
-
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
|
|
1499
|
-
obj = isArrayLike(obj) ? obj : values(obj);
|
|
1500
|
-
for (var i = 0, length = obj.length; i < length; i++) {
|
|
1501
|
-
value = obj[i];
|
|
1502
|
-
if (value != null && value > result) {
|
|
1503
|
-
result = value;
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
} else {
|
|
1507
|
-
iteratee = cb(iteratee, context);
|
|
1508
|
-
each(obj, function(v, index, list) {
|
|
1509
|
-
computed = iteratee(v, index, list);
|
|
1510
|
-
if (computed > lastComputed || (computed === -Infinity && result === -Infinity)) {
|
|
1511
|
-
result = v;
|
|
1512
|
-
lastComputed = computed;
|
|
1513
|
-
}
|
|
1514
|
-
});
|
|
1515
|
-
}
|
|
1516
|
-
return result;
|
|
1517
|
-
}
|
|
1518
|
-
|
|
1519
|
-
// Return the minimum element (or element-based computation).
|
|
1520
|
-
function min(obj, iteratee, context) {
|
|
1521
|
-
var result = Infinity, lastComputed = Infinity,
|
|
1522
|
-
value, computed;
|
|
1523
|
-
if (iteratee == null || (typeof iteratee == 'number' && typeof obj[0] != 'object' && obj != null)) {
|
|
1524
|
-
obj = isArrayLike(obj) ? obj : values(obj);
|
|
1525
|
-
for (var i = 0, length = obj.length; i < length; i++) {
|
|
1526
|
-
value = obj[i];
|
|
1527
|
-
if (value != null && value < result) {
|
|
1528
|
-
result = value;
|
|
1529
|
-
}
|
|
1530
|
-
}
|
|
1531
|
-
} else {
|
|
1532
|
-
iteratee = cb(iteratee, context);
|
|
1533
|
-
each(obj, function(v, index, list) {
|
|
1534
|
-
computed = iteratee(v, index, list);
|
|
1535
|
-
if (computed < lastComputed || (computed === Infinity && result === Infinity)) {
|
|
1536
|
-
result = v;
|
|
1537
|
-
lastComputed = computed;
|
|
1538
|
-
}
|
|
1539
|
-
});
|
|
1540
|
-
}
|
|
1541
|
-
return result;
|
|
1542
|
-
}
|
|
1543
|
-
|
|
1544
|
-
// Safely create a real, live array from anything iterable.
|
|
1545
|
-
var reStrSymbol = /[^\ud800-\udfff]|[\ud800-\udbff][\udc00-\udfff]|[\ud800-\udfff]/g;
|
|
1546
|
-
function toArray(obj) {
|
|
1547
|
-
if (!obj) return [];
|
|
1548
|
-
if (isArray(obj)) return slice.call(obj);
|
|
1549
|
-
if (isString(obj)) {
|
|
1550
|
-
// Keep surrogate pair characters together.
|
|
1551
|
-
return obj.match(reStrSymbol);
|
|
1552
|
-
}
|
|
1553
|
-
if (isArrayLike(obj)) return map(obj, identity);
|
|
1554
|
-
return values(obj);
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
// Sample **n** random values from a collection using the modern version of the
|
|
1558
|
-
// [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
|
1559
|
-
// If **n** is not specified, returns a single random element.
|
|
1560
|
-
// The internal `guard` argument allows it to work with `_.map`.
|
|
1561
|
-
function sample(obj, n, guard) {
|
|
1562
|
-
if (n == null || guard) {
|
|
1563
|
-
if (!isArrayLike(obj)) obj = values(obj);
|
|
1564
|
-
return obj[random(obj.length - 1)];
|
|
1565
|
-
}
|
|
1566
|
-
var sample = toArray(obj);
|
|
1567
|
-
var length = getLength(sample);
|
|
1568
|
-
n = Math.max(Math.min(n, length), 0);
|
|
1569
|
-
var last = length - 1;
|
|
1570
|
-
for (var index = 0; index < n; index++) {
|
|
1571
|
-
var rand = random(index, last);
|
|
1572
|
-
var temp = sample[index];
|
|
1573
|
-
sample[index] = sample[rand];
|
|
1574
|
-
sample[rand] = temp;
|
|
1575
|
-
}
|
|
1576
|
-
return sample.slice(0, n);
|
|
1577
|
-
}
|
|
1578
|
-
|
|
1579
|
-
// Shuffle a collection.
|
|
1580
|
-
function shuffle(obj) {
|
|
1581
|
-
return sample(obj, Infinity);
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
// Sort the object's values by a criterion produced by an iteratee.
|
|
1585
|
-
function sortBy(obj, iteratee, context) {
|
|
1586
|
-
var index = 0;
|
|
1587
|
-
iteratee = cb(iteratee, context);
|
|
1588
|
-
return pluck$1(map(obj, function(value, key, list) {
|
|
1589
|
-
return {
|
|
1590
|
-
value: value,
|
|
1591
|
-
index: index++,
|
|
1592
|
-
criteria: iteratee(value, key, list)
|
|
1593
|
-
};
|
|
1594
|
-
}).sort(function(left, right) {
|
|
1595
|
-
var a = left.criteria;
|
|
1596
|
-
var b = right.criteria;
|
|
1597
|
-
if (a !== b) {
|
|
1598
|
-
if (a > b || a === void 0) return 1;
|
|
1599
|
-
if (a < b || b === void 0) return -1;
|
|
1600
|
-
}
|
|
1601
|
-
return left.index - right.index;
|
|
1602
|
-
}), 'value');
|
|
1603
|
-
}
|
|
1604
|
-
|
|
1605
|
-
// An internal function used for aggregate "group by" operations.
|
|
1606
|
-
function group(behavior, partition) {
|
|
1607
|
-
return function(obj, iteratee, context) {
|
|
1608
|
-
var result = partition ? [[], []] : {};
|
|
1609
|
-
iteratee = cb(iteratee, context);
|
|
1610
|
-
each(obj, function(value, index) {
|
|
1611
|
-
var key = iteratee(value, index, obj);
|
|
1612
|
-
behavior(result, value, key);
|
|
1613
|
-
});
|
|
1614
|
-
return result;
|
|
1615
|
-
};
|
|
1616
|
-
}
|
|
1617
|
-
|
|
1618
|
-
// Groups the object's values by a criterion. Pass either a string attribute
|
|
1619
|
-
// to group by, or a function that returns the criterion.
|
|
1620
|
-
var groupBy = group(function(result, value, key) {
|
|
1621
|
-
if (has$1(result, key)) result[key].push(value); else result[key] = [value];
|
|
1622
|
-
});
|
|
1623
|
-
|
|
1624
|
-
// Indexes the object's values by a criterion, similar to `_.groupBy`, but for
|
|
1625
|
-
// when you know that your index values will be unique.
|
|
1626
|
-
var indexBy = group(function(result, value, key) {
|
|
1627
|
-
result[key] = value;
|
|
1628
|
-
});
|
|
1629
|
-
|
|
1630
|
-
// Counts instances of an object that group by a certain criterion. Pass
|
|
1631
|
-
// either a string attribute to count by, or a function that returns the
|
|
1632
|
-
// criterion.
|
|
1633
|
-
var countBy = group(function(result, value, key) {
|
|
1634
|
-
if (has$1(result, key)) result[key]++; else result[key] = 1;
|
|
1635
|
-
});
|
|
1636
|
-
|
|
1637
|
-
// Split a collection into two arrays: one whose elements all pass the given
|
|
1638
|
-
// truth test, and one whose elements all do not pass the truth test.
|
|
1639
|
-
var partition = group(function(result, value, pass) {
|
|
1640
|
-
result[pass ? 0 : 1].push(value);
|
|
1641
|
-
}, true);
|
|
1642
|
-
|
|
1643
|
-
// Return the number of elements in a collection.
|
|
1644
|
-
function size(obj) {
|
|
1645
|
-
if (obj == null) return 0;
|
|
1646
|
-
return isArrayLike(obj) ? obj.length : keys(obj).length;
|
|
1647
|
-
}
|
|
1648
|
-
|
|
1649
|
-
// Internal `_.pick` helper function to determine whether `key` is an enumerable
|
|
1650
|
-
// property name of `obj`.
|
|
1651
|
-
function keyInObj(value, key, obj) {
|
|
1652
|
-
return key in obj;
|
|
1653
|
-
}
|
|
1654
|
-
|
|
1655
|
-
// Return a copy of the object only containing the allowed properties.
|
|
1656
|
-
var pick = restArguments(function(obj, keys) {
|
|
1657
|
-
var result = {}, iteratee = keys[0];
|
|
1658
|
-
if (obj == null) return result;
|
|
1659
|
-
if (isFunction$1(iteratee)) {
|
|
1660
|
-
if (keys.length > 1) iteratee = optimizeCb(iteratee, keys[1]);
|
|
1661
|
-
keys = allKeys(obj);
|
|
1662
|
-
} else {
|
|
1663
|
-
iteratee = keyInObj;
|
|
1664
|
-
keys = flatten$1(keys, false, false);
|
|
1665
|
-
obj = Object(obj);
|
|
1666
|
-
}
|
|
1667
|
-
for (var i = 0, length = keys.length; i < length; i++) {
|
|
1668
|
-
var key = keys[i];
|
|
1669
|
-
var value = obj[key];
|
|
1670
|
-
if (iteratee(value, key, obj)) result[key] = value;
|
|
1671
|
-
}
|
|
1672
|
-
return result;
|
|
1673
|
-
});
|
|
1674
|
-
|
|
1675
|
-
// Return a copy of the object without the disallowed properties.
|
|
1676
|
-
var omit = restArguments(function(obj, keys) {
|
|
1677
|
-
var iteratee = keys[0], context;
|
|
1678
|
-
if (isFunction$1(iteratee)) {
|
|
1679
|
-
iteratee = negate(iteratee);
|
|
1680
|
-
if (keys.length > 1) context = keys[1];
|
|
1681
|
-
} else {
|
|
1682
|
-
keys = map(flatten$1(keys, false, false), String);
|
|
1683
|
-
iteratee = function(value, key) {
|
|
1684
|
-
return !contains(keys, key);
|
|
1685
|
-
};
|
|
1686
|
-
}
|
|
1687
|
-
return pick(obj, iteratee, context);
|
|
1688
|
-
});
|
|
1689
|
-
|
|
1690
|
-
// Returns everything but the last entry of the array. Especially useful on
|
|
1691
|
-
// the arguments object. Passing **n** will return all the values in
|
|
1692
|
-
// the array, excluding the last N.
|
|
1693
|
-
function initial(array, n, guard) {
|
|
1694
|
-
return slice.call(array, 0, Math.max(0, array.length - (n == null || guard ? 1 : n)));
|
|
1695
|
-
}
|
|
1696
|
-
|
|
1697
|
-
// Get the first element of an array. Passing **n** will return the first N
|
|
1698
|
-
// values in the array. The **guard** check allows it to work with `_.map`.
|
|
1699
|
-
function first(array, n, guard) {
|
|
1700
|
-
if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
|
|
1701
|
-
if (n == null || guard) return array[0];
|
|
1702
|
-
return initial(array, array.length - n);
|
|
1703
|
-
}
|
|
1704
|
-
|
|
1705
|
-
// Returns everything but the first entry of the `array`. Especially useful on
|
|
1706
|
-
// the `arguments` object. Passing an **n** will return the rest N values in the
|
|
1707
|
-
// `array`.
|
|
1708
|
-
function rest(array, n, guard) {
|
|
1709
|
-
return slice.call(array, n == null || guard ? 1 : n);
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
// Get the last element of an array. Passing **n** will return the last N
|
|
1713
|
-
// values in the array.
|
|
1714
|
-
function last(array, n, guard) {
|
|
1715
|
-
if (array == null || array.length < 1) return n == null || guard ? void 0 : [];
|
|
1716
|
-
if (n == null || guard) return array[array.length - 1];
|
|
1717
|
-
return rest(array, Math.max(0, array.length - n));
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
// Trim out all falsy values from an array.
|
|
1721
|
-
function compact(array) {
|
|
1722
|
-
return filter(array, Boolean);
|
|
1723
|
-
}
|
|
1724
|
-
|
|
1725
|
-
// Flatten out an array, either recursively (by default), or up to `depth`.
|
|
1726
|
-
// Passing `true` or `false` as `depth` means `1` or `Infinity`, respectively.
|
|
1727
|
-
function flatten(array, depth) {
|
|
1728
|
-
return flatten$1(array, depth, false);
|
|
1729
|
-
}
|
|
1730
|
-
|
|
1731
|
-
// Take the difference between one array and a number of other arrays.
|
|
1732
|
-
// Only the elements present in just the first array will remain.
|
|
1733
|
-
var difference = restArguments(function(array, rest) {
|
|
1734
|
-
rest = flatten$1(rest, true, true);
|
|
1735
|
-
return filter(array, function(value){
|
|
1736
|
-
return !contains(rest, value);
|
|
1737
|
-
});
|
|
1738
|
-
});
|
|
1739
|
-
|
|
1740
|
-
// Return a version of the array that does not contain the specified value(s).
|
|
1741
|
-
var without = restArguments(function(array, otherArrays) {
|
|
1742
|
-
return difference(array, otherArrays);
|
|
1743
|
-
});
|
|
1744
|
-
|
|
1745
|
-
// Produce a duplicate-free version of the array. If the array has already
|
|
1746
|
-
// been sorted, you have the option of using a faster algorithm.
|
|
1747
|
-
// The faster algorithm will not work with an iteratee if the iteratee
|
|
1748
|
-
// is not a one-to-one function, so providing an iteratee will disable
|
|
1749
|
-
// the faster algorithm.
|
|
1750
|
-
function uniq(array, isSorted, iteratee, context) {
|
|
1751
|
-
if (!isBoolean(isSorted)) {
|
|
1752
|
-
context = iteratee;
|
|
1753
|
-
iteratee = isSorted;
|
|
1754
|
-
isSorted = false;
|
|
1755
|
-
}
|
|
1756
|
-
if (iteratee != null) iteratee = cb(iteratee, context);
|
|
1757
|
-
var result = [];
|
|
1758
|
-
var seen = [];
|
|
1759
|
-
for (var i = 0, length = getLength(array); i < length; i++) {
|
|
1760
|
-
var value = array[i],
|
|
1761
|
-
computed = iteratee ? iteratee(value, i, array) : value;
|
|
1762
|
-
if (isSorted && !iteratee) {
|
|
1763
|
-
if (!i || seen !== computed) result.push(value);
|
|
1764
|
-
seen = computed;
|
|
1765
|
-
} else if (iteratee) {
|
|
1766
|
-
if (!contains(seen, computed)) {
|
|
1767
|
-
seen.push(computed);
|
|
1768
|
-
result.push(value);
|
|
1769
|
-
}
|
|
1770
|
-
} else if (!contains(result, value)) {
|
|
1771
|
-
result.push(value);
|
|
1772
|
-
}
|
|
1773
|
-
}
|
|
1774
|
-
return result;
|
|
1775
|
-
}
|
|
1776
|
-
|
|
1777
|
-
// Produce an array that contains the union: each distinct element from all of
|
|
1778
|
-
// the passed-in arrays.
|
|
1779
|
-
var union$1 = restArguments(function(arrays) {
|
|
1780
|
-
return uniq(flatten$1(arrays, true, true));
|
|
1781
|
-
});
|
|
1782
|
-
|
|
1783
|
-
// Produce an array that contains every item shared between all the
|
|
1784
|
-
// passed-in arrays.
|
|
1785
|
-
function intersection(array) {
|
|
1786
|
-
var result = [];
|
|
1787
|
-
var argsLength = arguments.length;
|
|
1788
|
-
for (var i = 0, length = getLength(array); i < length; i++) {
|
|
1789
|
-
var item = array[i];
|
|
1790
|
-
if (contains(result, item)) continue;
|
|
1791
|
-
var j;
|
|
1792
|
-
for (j = 1; j < argsLength; j++) {
|
|
1793
|
-
if (!contains(arguments[j], item)) break;
|
|
1794
|
-
}
|
|
1795
|
-
if (j === argsLength) result.push(item);
|
|
1796
|
-
}
|
|
1797
|
-
return result;
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
// Complement of zip. Unzip accepts an array of arrays and groups
|
|
1801
|
-
// each array's elements on shared indices.
|
|
1802
|
-
function unzip(array) {
|
|
1803
|
-
var length = (array && max(array, getLength).length) || 0;
|
|
1804
|
-
var result = Array(length);
|
|
1805
|
-
|
|
1806
|
-
for (var index = 0; index < length; index++) {
|
|
1807
|
-
result[index] = pluck$1(array, index);
|
|
1808
|
-
}
|
|
1809
|
-
return result;
|
|
1810
|
-
}
|
|
1811
|
-
|
|
1812
|
-
// Zip together multiple lists into a single array -- elements that share
|
|
1813
|
-
// an index go together.
|
|
1814
|
-
var zip = restArguments(unzip);
|
|
1815
|
-
|
|
1816
|
-
// Converts lists into objects. Pass either a single array of `[key, value]`
|
|
1817
|
-
// pairs, or two parallel arrays of the same length -- one of keys, and one of
|
|
1818
|
-
// the corresponding values. Passing by pairs is the reverse of `_.pairs`.
|
|
1819
|
-
function object$1(list, values) {
|
|
1820
|
-
var result = {};
|
|
1821
|
-
for (var i = 0, length = getLength(list); i < length; i++) {
|
|
1822
|
-
if (values) {
|
|
1823
|
-
result[list[i]] = values[i];
|
|
1824
|
-
} else {
|
|
1825
|
-
result[list[i][0]] = list[i][1];
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1828
|
-
return result;
|
|
1829
|
-
}
|
|
1830
|
-
|
|
1831
|
-
// Generate an integer Array containing an arithmetic progression. A port of
|
|
1832
|
-
// the native Python `range()` function. See
|
|
1833
|
-
// [the Python documentation](https://docs.python.org/library/functions.html#range).
|
|
1834
|
-
function range(start, stop, step) {
|
|
1835
|
-
if (stop == null) {
|
|
1836
|
-
stop = start || 0;
|
|
1837
|
-
start = 0;
|
|
1838
|
-
}
|
|
1839
|
-
if (!step) {
|
|
1840
|
-
step = stop < start ? -1 : 1;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
var length = Math.max(Math.ceil((stop - start) / step), 0);
|
|
1844
|
-
var range = Array(length);
|
|
1845
|
-
|
|
1846
|
-
for (var idx = 0; idx < length; idx++, start += step) {
|
|
1847
|
-
range[idx] = start;
|
|
1848
|
-
}
|
|
1849
|
-
|
|
1850
|
-
return range;
|
|
1851
|
-
}
|
|
1852
|
-
|
|
1853
|
-
// Chunk a single array into multiple arrays, each containing `count` or fewer
|
|
1854
|
-
// items.
|
|
1855
|
-
function chunk(array, count) {
|
|
1856
|
-
if (count == null || count < 1) return [];
|
|
1857
|
-
var result = [];
|
|
1858
|
-
var i = 0, length = array.length;
|
|
1859
|
-
while (i < length) {
|
|
1860
|
-
result.push(slice.call(array, i, i += count));
|
|
1861
|
-
}
|
|
1862
|
-
return result;
|
|
1863
|
-
}
|
|
1864
|
-
|
|
1865
|
-
// Helper function to continue chaining intermediate results.
|
|
1866
|
-
function chainResult(instance, obj) {
|
|
1867
|
-
return instance._chain ? _$1(obj).chain() : obj;
|
|
1868
|
-
}
|
|
1869
|
-
|
|
1870
|
-
// Add your own custom functions to the Underscore object.
|
|
1871
|
-
function mixin(obj) {
|
|
1872
|
-
each(functions(obj), function(name) {
|
|
1873
|
-
var func = _$1[name] = obj[name];
|
|
1874
|
-
_$1.prototype[name] = function() {
|
|
1875
|
-
var args = [this._wrapped];
|
|
1876
|
-
push.apply(args, arguments);
|
|
1877
|
-
return chainResult(this, func.apply(_$1, args));
|
|
1878
|
-
};
|
|
1879
|
-
});
|
|
1880
|
-
return _$1;
|
|
1881
|
-
}
|
|
1882
|
-
|
|
1883
|
-
// Add all mutator `Array` functions to the wrapper.
|
|
1884
|
-
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
|
1885
|
-
var method = ArrayProto[name];
|
|
1886
|
-
_$1.prototype[name] = function() {
|
|
1887
|
-
var obj = this._wrapped;
|
|
1888
|
-
if (obj != null) {
|
|
1889
|
-
method.apply(obj, arguments);
|
|
1890
|
-
if ((name === 'shift' || name === 'splice') && obj.length === 0) {
|
|
1891
|
-
delete obj[0];
|
|
1892
|
-
}
|
|
1893
|
-
}
|
|
1894
|
-
return chainResult(this, obj);
|
|
1895
|
-
};
|
|
1896
|
-
});
|
|
1897
|
-
|
|
1898
|
-
// Add all accessor `Array` functions to the wrapper.
|
|
1899
|
-
each(['concat', 'join', 'slice'], function(name) {
|
|
1900
|
-
var method = ArrayProto[name];
|
|
1901
|
-
_$1.prototype[name] = function() {
|
|
1902
|
-
var obj = this._wrapped;
|
|
1903
|
-
if (obj != null) obj = method.apply(obj, arguments);
|
|
1904
|
-
return chainResult(this, obj);
|
|
1905
|
-
};
|
|
1906
|
-
});
|
|
1907
|
-
|
|
1908
|
-
// Named Exports
|
|
1909
|
-
|
|
1910
|
-
var allExports = /*#__PURE__*/Object.freeze({
|
|
1911
|
-
__proto__: null,
|
|
1912
|
-
VERSION: VERSION,
|
|
1913
|
-
restArguments: restArguments,
|
|
1914
|
-
isObject: isObject$1,
|
|
1915
|
-
isNull: isNull,
|
|
1916
|
-
isUndefined: isUndefined,
|
|
1917
|
-
isBoolean: isBoolean,
|
|
1918
|
-
isElement: isElement,
|
|
1919
|
-
isString: isString,
|
|
1920
|
-
isNumber: isNumber,
|
|
1921
|
-
isDate: isDate,
|
|
1922
|
-
isRegExp: isRegExp,
|
|
1923
|
-
isError: isError,
|
|
1924
|
-
isSymbol: isSymbol,
|
|
1925
|
-
isArrayBuffer: isArrayBuffer,
|
|
1926
|
-
isDataView: isDataView$1,
|
|
1927
|
-
isArray: isArray,
|
|
1928
|
-
isFunction: isFunction$1,
|
|
1929
|
-
isArguments: isArguments$1,
|
|
1930
|
-
isFinite: isFinite$1,
|
|
1931
|
-
isNaN: isNaN$1,
|
|
1932
|
-
isTypedArray: isTypedArray$1,
|
|
1933
|
-
isEmpty: isEmpty,
|
|
1934
|
-
isMatch: isMatch,
|
|
1935
|
-
isEqual: isEqual,
|
|
1936
|
-
isMap: isMap,
|
|
1937
|
-
isWeakMap: isWeakMap,
|
|
1938
|
-
isSet: isSet,
|
|
1939
|
-
isWeakSet: isWeakSet,
|
|
1940
|
-
keys: keys,
|
|
1941
|
-
allKeys: allKeys,
|
|
1942
|
-
values: values,
|
|
1943
|
-
pairs: pairs,
|
|
1944
|
-
invert: invert,
|
|
1945
|
-
functions: functions,
|
|
1946
|
-
methods: functions,
|
|
1947
|
-
extend: extend,
|
|
1948
|
-
extendOwn: extendOwn,
|
|
1949
|
-
assign: extendOwn,
|
|
1950
|
-
defaults: defaults,
|
|
1951
|
-
create: create,
|
|
1952
|
-
clone: clone,
|
|
1953
|
-
tap: tap,
|
|
1954
|
-
get: get,
|
|
1955
|
-
has: has,
|
|
1956
|
-
mapObject: mapObject$1,
|
|
1957
|
-
identity: identity,
|
|
1958
|
-
constant: constant$1,
|
|
1959
|
-
noop: noop,
|
|
1960
|
-
toPath: toPath$1,
|
|
1961
|
-
property: property,
|
|
1962
|
-
propertyOf: propertyOf,
|
|
1963
|
-
matcher: matcher,
|
|
1964
|
-
matches: matcher,
|
|
1965
|
-
times: times,
|
|
1966
|
-
random: random,
|
|
1967
|
-
now: now,
|
|
1968
|
-
escape: escape,
|
|
1969
|
-
unescape: unescape,
|
|
1970
|
-
templateSettings: templateSettings,
|
|
1971
|
-
template: template,
|
|
1972
|
-
result: result,
|
|
1973
|
-
uniqueId: uniqueId,
|
|
1974
|
-
chain: chain,
|
|
1975
|
-
iteratee: iteratee,
|
|
1976
|
-
partial: partial,
|
|
1977
|
-
bind: bind,
|
|
1978
|
-
bindAll: bindAll,
|
|
1979
|
-
memoize: memoize,
|
|
1980
|
-
delay: delay,
|
|
1981
|
-
defer: defer,
|
|
1982
|
-
throttle: throttle,
|
|
1983
|
-
debounce: debounce,
|
|
1984
|
-
wrap: wrap,
|
|
1985
|
-
negate: negate,
|
|
1986
|
-
compose: compose,
|
|
1987
|
-
after: after,
|
|
1988
|
-
before: before,
|
|
1989
|
-
once: once,
|
|
1990
|
-
findKey: findKey,
|
|
1991
|
-
findIndex: findIndex,
|
|
1992
|
-
findLastIndex: findLastIndex,
|
|
1993
|
-
sortedIndex: sortedIndex,
|
|
1994
|
-
indexOf: indexOf,
|
|
1995
|
-
lastIndexOf: lastIndexOf,
|
|
1996
|
-
find: find,
|
|
1997
|
-
detect: find,
|
|
1998
|
-
findWhere: findWhere,
|
|
1999
|
-
each: each,
|
|
2000
|
-
forEach: each,
|
|
2001
|
-
map: map,
|
|
2002
|
-
collect: map,
|
|
2003
|
-
reduce: reduce,
|
|
2004
|
-
foldl: reduce,
|
|
2005
|
-
inject: reduce,
|
|
2006
|
-
reduceRight: reduceRight,
|
|
2007
|
-
foldr: reduceRight,
|
|
2008
|
-
filter: filter,
|
|
2009
|
-
select: filter,
|
|
2010
|
-
reject: reject,
|
|
2011
|
-
every: every,
|
|
2012
|
-
all: every,
|
|
2013
|
-
some: some,
|
|
2014
|
-
any: some,
|
|
2015
|
-
contains: contains,
|
|
2016
|
-
includes: contains,
|
|
2017
|
-
include: contains,
|
|
2018
|
-
invoke: invoke,
|
|
2019
|
-
pluck: pluck$1,
|
|
2020
|
-
where: where,
|
|
2021
|
-
max: max,
|
|
2022
|
-
min: min,
|
|
2023
|
-
shuffle: shuffle,
|
|
2024
|
-
sample: sample,
|
|
2025
|
-
sortBy: sortBy,
|
|
2026
|
-
groupBy: groupBy,
|
|
2027
|
-
indexBy: indexBy,
|
|
2028
|
-
countBy: countBy,
|
|
2029
|
-
partition: partition,
|
|
2030
|
-
toArray: toArray,
|
|
2031
|
-
size: size,
|
|
2032
|
-
pick: pick,
|
|
2033
|
-
omit: omit,
|
|
2034
|
-
first: first,
|
|
2035
|
-
head: first,
|
|
2036
|
-
take: first,
|
|
2037
|
-
initial: initial,
|
|
2038
|
-
last: last,
|
|
2039
|
-
rest: rest,
|
|
2040
|
-
tail: rest,
|
|
2041
|
-
drop: rest,
|
|
2042
|
-
compact: compact,
|
|
2043
|
-
flatten: flatten,
|
|
2044
|
-
without: without,
|
|
2045
|
-
uniq: uniq,
|
|
2046
|
-
unique: uniq,
|
|
2047
|
-
union: union$1,
|
|
2048
|
-
intersection: intersection,
|
|
2049
|
-
difference: difference,
|
|
2050
|
-
unzip: unzip,
|
|
2051
|
-
transpose: unzip,
|
|
2052
|
-
zip: zip,
|
|
2053
|
-
object: object$1,
|
|
2054
|
-
range: range,
|
|
2055
|
-
chunk: chunk,
|
|
2056
|
-
mixin: mixin,
|
|
2057
|
-
'default': _$1
|
|
2058
|
-
});
|
|
2059
|
-
|
|
2060
|
-
// Default Export
|
|
2061
|
-
|
|
2062
|
-
// Add all of the Underscore functions to the wrapper object.
|
|
2063
|
-
var _ = mixin(allExports);
|
|
2064
|
-
// Legacy Node.js API.
|
|
2065
|
-
_._ = _;
|
|
1
|
+
import _ from 'underscore';
|
|
2
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
3
|
+
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
4
|
+
import { seededRNG as seededRNG$1, shuffle as shuffle$1 } from '@khanacademy/perseus-core';
|
|
2066
5
|
|
|
2067
6
|
function getMatrixSize(matrix) {
|
|
2068
7
|
const matrixSize = [1, 1];
|
|
@@ -2109,7 +48,9 @@ const getDecimalSeparator = locale => {
|
|
|
2109
48
|
const match = new Intl.NumberFormat(locale).format(numberWithDecimalSeparator)
|
|
2110
49
|
// 0x661 is ARABIC-INDIC DIGIT ONE
|
|
2111
50
|
// 0x6F1 is EXTENDED ARABIC-INDIC DIGIT ONE
|
|
2112
|
-
|
|
51
|
+
// 0x967 is DEVANAGARI DIGIT ONE
|
|
52
|
+
// 0x9e7 is BENGALI/BANGLA DIGIT ONE
|
|
53
|
+
.match(/[^\d\u0661\u06F1\u0967\u09e7]/);
|
|
2113
54
|
return (_match$ = match == null ? void 0 : match[0]) != null ? _match$ : ".";
|
|
2114
55
|
}
|
|
2115
56
|
};
|
|
@@ -2890,16 +831,6 @@ const number = (rawValue, ctx) => {
|
|
|
2890
831
|
return ctx.failure("number", rawValue);
|
|
2891
832
|
};
|
|
2892
833
|
|
|
2893
|
-
function _extends() {
|
|
2894
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
2895
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
2896
|
-
var t = arguments[e];
|
|
2897
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
2898
|
-
}
|
|
2899
|
-
return n;
|
|
2900
|
-
}, _extends.apply(null, arguments);
|
|
2901
|
-
}
|
|
2902
|
-
|
|
2903
834
|
function object(schema) {
|
|
2904
835
|
return (rawValue, ctx) => {
|
|
2905
836
|
if (!isObject(rawValue)) {
|
|
@@ -3076,7 +1007,7 @@ function parseWidget(parseType, parseOptions) {
|
|
|
3076
1007
|
graded: optional(boolean),
|
|
3077
1008
|
alignment: optional(string),
|
|
3078
1009
|
options: parseOptions,
|
|
3079
|
-
key: optional(number),
|
|
1010
|
+
key: optional(nullable(number)),
|
|
3080
1011
|
version: optional(object({
|
|
3081
1012
|
major: number,
|
|
3082
1013
|
minor: number
|
|
@@ -3462,14 +1393,15 @@ const imageDimensionToNumber = pipeParsers(union(number).or(string).parser)
|
|
|
3462
1393
|
// string parses to either NaN (using parseInt) or 0 (using unary +) and
|
|
3463
1394
|
// CSS will treat NaN as invalid and default to 0 instead.
|
|
3464
1395
|
.then(convert(emptyToZero)).then(stringToNumber).parser;
|
|
1396
|
+
const dimensionOrUndefined = defaulted(imageDimensionToNumber, () => undefined);
|
|
3465
1397
|
const parsePerseusImageBackground = object({
|
|
3466
1398
|
url: optional(nullable(string)),
|
|
3467
|
-
width:
|
|
3468
|
-
height:
|
|
3469
|
-
top:
|
|
3470
|
-
left:
|
|
3471
|
-
bottom:
|
|
3472
|
-
scale:
|
|
1399
|
+
width: dimensionOrUndefined,
|
|
1400
|
+
height: dimensionOrUndefined,
|
|
1401
|
+
top: dimensionOrUndefined,
|
|
1402
|
+
left: dimensionOrUndefined,
|
|
1403
|
+
bottom: dimensionOrUndefined,
|
|
1404
|
+
scale: dimensionOrUndefined
|
|
3473
1405
|
});
|
|
3474
1406
|
|
|
3475
1407
|
const pairOfNumbers$2 = pair(number, number);
|
|
@@ -4076,13 +2008,16 @@ const parseLockedPolygonType = object({
|
|
|
4076
2008
|
labels: optional(array(parseLockedLabelType)),
|
|
4077
2009
|
ariaLabel: optional(string)
|
|
4078
2010
|
});
|
|
2011
|
+
|
|
2012
|
+
// Exported for testing.
|
|
2013
|
+
const parseLockedFunctionDomain = defaulted(pair(defaulted(number, () => -Infinity), defaulted(number, () => Infinity)), () => [-Infinity, Infinity]);
|
|
4079
2014
|
const parseLockedFunctionType = object({
|
|
4080
2015
|
type: constant("function"),
|
|
4081
2016
|
color: parseLockedFigureColor,
|
|
4082
2017
|
strokeStyle: parseLockedLineStyle,
|
|
4083
2018
|
equation: string,
|
|
4084
2019
|
directionalAxis: enumeration("x", "y"),
|
|
4085
|
-
domain:
|
|
2020
|
+
domain: parseLockedFunctionDomain,
|
|
4086
2021
|
// TODO(benchristel): default labels to empty array?
|
|
4087
2022
|
labels: optional(array(parseLockedLabelType)),
|
|
4088
2023
|
ariaLabel: optional(string)
|
|
@@ -4202,6 +2137,7 @@ const parseNumberLineWidget = parseWidget(constant("number-line"), object({
|
|
|
4202
2137
|
}));
|
|
4203
2138
|
|
|
4204
2139
|
const parseMathFormat = enumeration("integer", "mixed", "improper", "proper", "decimal", "percent", "pi");
|
|
2140
|
+
const parseSimplify = enumeration("required", "correct", "enforced", "optional");
|
|
4205
2141
|
const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
|
|
4206
2142
|
answers: array(object({
|
|
4207
2143
|
message: string,
|
|
@@ -4210,13 +2146,18 @@ const parseNumericInputWidget = parseWidget(constant("numeric-input"), object({
|
|
|
4210
2146
|
// the data, simplify this.
|
|
4211
2147
|
value: optional(nullable(number)),
|
|
4212
2148
|
status: string,
|
|
4213
|
-
answerForms:
|
|
2149
|
+
answerForms: defaulted(array(parseMathFormat), () => undefined),
|
|
4214
2150
|
strict: boolean,
|
|
4215
2151
|
maxError: optional(nullable(number)),
|
|
4216
2152
|
// TODO(benchristel): simplify should never be a boolean, but we
|
|
4217
2153
|
// have some content where it is anyway. If we ever backfill
|
|
4218
2154
|
// the data, we should simplify `simplify`.
|
|
4219
|
-
simplify: optional(nullable(union(
|
|
2155
|
+
simplify: optional(nullable(union(parseSimplify).or(pipeParsers(boolean).then(convert(value => {
|
|
2156
|
+
if (typeof value === "boolean") {
|
|
2157
|
+
return value ? "required" : "optional";
|
|
2158
|
+
}
|
|
2159
|
+
return value;
|
|
2160
|
+
})).parser).parser))
|
|
4220
2161
|
})),
|
|
4221
2162
|
labelText: optional(string),
|
|
4222
2163
|
size: string,
|
|
@@ -4308,7 +2249,7 @@ const parseRadioWidget = parseWidget(constant("radio"), object({
|
|
|
4308
2249
|
// There is an import cycle between radio-widget.ts and
|
|
4309
2250
|
// widgets-map.ts. The anonymous function below ensures that we
|
|
4310
2251
|
// don't refer to parseWidgetsMap before it's defined.
|
|
4311
|
-
widgets:
|
|
2252
|
+
widgets: defaulted((rawVal, ctx) => parseWidgetsMap(rawVal, ctx), () => undefined)
|
|
4312
2253
|
})),
|
|
4313
2254
|
hasNoneOfTheAbove: optional(boolean),
|
|
4314
2255
|
countChoices: optional(boolean),
|
|
@@ -4461,13 +2402,17 @@ const parseDeprecatedWidget = parseWidget(
|
|
|
4461
2402
|
(_, ctx) => ctx.success("deprecated-standin"),
|
|
4462
2403
|
// Allow any widget options
|
|
4463
2404
|
object({}));
|
|
4464
|
-
const
|
|
4465
|
-
|
|
4466
|
-
|
|
2405
|
+
const parseStringToNonNegativeInt = (rawValue, ctx) => {
|
|
2406
|
+
// The article renderer seems to allow the numeric part of a widget ID to
|
|
2407
|
+
// be 0, at least for image widgets. However, if widget IDs in an exercise
|
|
2408
|
+
// contain 0, the exercise renderer will blow up. We allow 0 here for
|
|
2409
|
+
// compatibility with articles.
|
|
2410
|
+
if (typeof rawValue !== "string" || !/^(0|[1-9][0-9]*)$/.test(rawValue)) {
|
|
2411
|
+
return ctx.failure("a string representing a non-negative integer", rawValue);
|
|
4467
2412
|
}
|
|
4468
2413
|
return ctx.success(+rawValue);
|
|
4469
2414
|
};
|
|
4470
|
-
const parseWidgetIdComponents = pair(string,
|
|
2415
|
+
const parseWidgetIdComponents = pair(string, parseStringToNonNegativeInt);
|
|
4471
2416
|
|
|
4472
2417
|
const parsePerseusRenderer = defaulted(object({
|
|
4473
2418
|
// TODO(benchristel): content is also defaulted to empty string in
|
|
@@ -4478,8 +2423,9 @@ const parsePerseusRenderer = defaulted(object({
|
|
|
4478
2423
|
// The anonymous function below ensures that we don't try to access
|
|
4479
2424
|
// parseWidgetsMap before it's defined.
|
|
4480
2425
|
widgets: defaulted((rawVal, ctx) => parseWidgetsMap(rawVal, ctx), () => ({})),
|
|
4481
|
-
|
|
4482
|
-
|
|
2426
|
+
images: parseImages,
|
|
2427
|
+
// deprecated
|
|
2428
|
+
metadata: any
|
|
4483
2429
|
}),
|
|
4484
2430
|
// Default value
|
|
4485
2431
|
() => ({
|
|
@@ -4490,29 +2436,48 @@ const parsePerseusRenderer = defaulted(object({
|
|
|
4490
2436
|
|
|
4491
2437
|
const parsePerseusArticle = union(parsePerseusRenderer).or(array(parsePerseusRenderer)).parser;
|
|
4492
2438
|
|
|
4493
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
4494
|
-
if (null == r) return {};
|
|
4495
|
-
var t = {};
|
|
4496
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
4497
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
4498
|
-
t[n] = r[n];
|
|
4499
|
-
}
|
|
4500
|
-
return t;
|
|
4501
|
-
}
|
|
4502
|
-
|
|
4503
2439
|
const parseHint = object({
|
|
4504
|
-
replace:
|
|
2440
|
+
replace: defaulted(boolean, () => undefined),
|
|
4505
2441
|
content: string,
|
|
4506
2442
|
widgets: defaulted(parseWidgetsMap, () => ({})),
|
|
4507
|
-
|
|
4508
|
-
|
|
2443
|
+
images: parseImages,
|
|
2444
|
+
// deprecated
|
|
2445
|
+
metadata: any
|
|
4509
2446
|
});
|
|
4510
2447
|
|
|
4511
|
-
const
|
|
2448
|
+
const parsePerseusAnswerArea = pipeParsers(defaulted(object({}), () => ({}))).then(convert(toAnswerArea)).parser;
|
|
2449
|
+
|
|
2450
|
+
// Some answerAreas have extra, bogus fields, like:
|
|
2451
|
+
//
|
|
2452
|
+
// "answerArea": {
|
|
2453
|
+
// "type": "multiple",
|
|
2454
|
+
// "options": {},
|
|
2455
|
+
// "version": null,
|
|
2456
|
+
// "static": false,
|
|
2457
|
+
// "graded": false,
|
|
2458
|
+
// "alignment": "",
|
|
2459
|
+
// }
|
|
2460
|
+
//
|
|
2461
|
+
// This function filters the fields of an answerArea object, keeping only the
|
|
2462
|
+
// known ones, and converts `undefined` and `null` values to `false`.
|
|
2463
|
+
function toAnswerArea(raw) {
|
|
2464
|
+
return {
|
|
2465
|
+
zTable: !!raw.zTable,
|
|
2466
|
+
calculator: !!raw.calculator,
|
|
2467
|
+
chi2Table: !!raw.chi2Table,
|
|
2468
|
+
financialCalculatorMonthlyPayment: !!raw.financialCalculatorMonthlyPayment,
|
|
2469
|
+
financialCalculatorTotalAmount: !!raw.financialCalculatorTotalAmount,
|
|
2470
|
+
financialCalculatorTimeToPayOff: !!raw.financialCalculatorTimeToPayOff,
|
|
2471
|
+
periodicTable: !!raw.periodicTable,
|
|
2472
|
+
periodicTableWithKey: !!raw.periodicTableWithKey,
|
|
2473
|
+
tTable: !!raw.tTable
|
|
2474
|
+
};
|
|
2475
|
+
}
|
|
2476
|
+
|
|
4512
2477
|
const parsePerseusItem$1 = object({
|
|
4513
2478
|
question: parsePerseusRenderer,
|
|
4514
2479
|
hints: defaulted(array(parseHint), () => []),
|
|
4515
|
-
answerArea:
|
|
2480
|
+
answerArea: parsePerseusAnswerArea,
|
|
4516
2481
|
itemDataVersion: optional(object({
|
|
4517
2482
|
major: number,
|
|
4518
2483
|
minor: number
|
|
@@ -4521,24 +2486,6 @@ const parsePerseusItem$1 = object({
|
|
|
4521
2486
|
answer: any
|
|
4522
2487
|
});
|
|
4523
2488
|
|
|
4524
|
-
// Some answerAreas have extra fields, like:
|
|
4525
|
-
//
|
|
4526
|
-
// "answerArea": {
|
|
4527
|
-
// "type": "multiple",
|
|
4528
|
-
// "options": {
|
|
4529
|
-
// "content": "",
|
|
4530
|
-
// "images": {},
|
|
4531
|
-
// "widgets": {}
|
|
4532
|
-
// }
|
|
4533
|
-
// }
|
|
4534
|
-
//
|
|
4535
|
-
// The "type" and "options" fields don't seem to be used anywhere. This
|
|
4536
|
-
// migration function removes them.
|
|
4537
|
-
function migrateAnswerArea(rawValue, ctx) {
|
|
4538
|
-
const rest = _objectWithoutPropertiesLoose(rawValue, _excluded$a);
|
|
4539
|
-
return ctx.success(rest);
|
|
4540
|
-
}
|
|
4541
|
-
|
|
4542
2489
|
/**
|
|
4543
2490
|
* Helper to parse PerseusItem JSON
|
|
4544
2491
|
* Why not just use JSON.parse? We want:
|
|
@@ -4611,9 +2558,51 @@ function throwErrorIfCheatingDetected() {
|
|
|
4611
2558
|
}
|
|
4612
2559
|
}
|
|
4613
2560
|
|
|
2561
|
+
/**
|
|
2562
|
+
* Adds the given perseus library version information to the __perseus_debug__
|
|
2563
|
+
* object and ensures that the object is attached to `globalThis` (`window` in
|
|
2564
|
+
* browser environments).
|
|
2565
|
+
*
|
|
2566
|
+
* This allows each library to provide runtime version information to assist in
|
|
2567
|
+
* debugging in production environments.
|
|
2568
|
+
*/
|
|
2569
|
+
const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
|
|
2570
|
+
// If the library version is the default value, then we don't want to
|
|
2571
|
+
// prefix it with a "v" to indicate that it is a version number.
|
|
2572
|
+
let prefix = "v";
|
|
2573
|
+
if (libraryVersion === "__lib_version__") {
|
|
2574
|
+
prefix = "";
|
|
2575
|
+
}
|
|
2576
|
+
const formattedVersion = `${prefix}${libraryVersion}`;
|
|
2577
|
+
if (typeof globalThis !== "undefined") {
|
|
2578
|
+
var _globalThis$__perseus;
|
|
2579
|
+
globalThis.__perseus_debug__ = (_globalThis$__perseus = globalThis.__perseus_debug__) != null ? _globalThis$__perseus : {};
|
|
2580
|
+
const existingVersionEntry = globalThis.__perseus_debug__[libraryName];
|
|
2581
|
+
if (existingVersionEntry) {
|
|
2582
|
+
// If we already have an entry and it doesn't match the registered
|
|
2583
|
+
// version, we morph the entry into an array and log a warning.
|
|
2584
|
+
if (existingVersionEntry !== formattedVersion) {
|
|
2585
|
+
// Existing entry might be an array already (oops, at least 2
|
|
2586
|
+
// versions of the library already loaded!).
|
|
2587
|
+
const allVersions = Array.isArray(existingVersionEntry) ? existingVersionEntry : [existingVersionEntry];
|
|
2588
|
+
allVersions.push(formattedVersion);
|
|
2589
|
+
globalThis.__perseus_debug__[libraryName] = allVersions;
|
|
2590
|
+
|
|
2591
|
+
// eslint-disable-next-line no-console
|
|
2592
|
+
console.warn(`Multiple versions of ${libraryName} loaded on this page: ${allVersions.sort().join(", ")}`);
|
|
2593
|
+
}
|
|
2594
|
+
} else {
|
|
2595
|
+
globalThis.__perseus_debug__[libraryName] = formattedVersion;
|
|
2596
|
+
}
|
|
2597
|
+
} else {
|
|
2598
|
+
// eslint-disable-next-line no-console
|
|
2599
|
+
console.warn(`globalThis not found found (${formattedVersion})`);
|
|
2600
|
+
}
|
|
2601
|
+
};
|
|
2602
|
+
|
|
4614
2603
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
4615
2604
|
const libName = "@khanacademy/perseus-core";
|
|
4616
|
-
const libVersion = "
|
|
2605
|
+
const libVersion = "4.0.0";
|
|
4617
2606
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
4618
2607
|
|
|
4619
2608
|
/**
|
|
@@ -4933,10 +2922,7 @@ const grapherWidgetLogic = {
|
|
|
4933
2922
|
const defaultWidgetOptions$m = {
|
|
4934
2923
|
content: "",
|
|
4935
2924
|
widgets: {},
|
|
4936
|
-
images: {}
|
|
4937
|
-
// `undefined` instead of `null` so that getDefaultProps works for
|
|
4938
|
-
// `the GroupMetadataEditor`
|
|
4939
|
-
metadata: undefined
|
|
2925
|
+
images: {}
|
|
4940
2926
|
};
|
|
4941
2927
|
const groupWidgetLogic = {
|
|
4942
2928
|
name: "group",
|
|
@@ -5077,6 +3063,63 @@ const labelImageWidgetLogic = {
|
|
|
5077
3063
|
getPublicWidgetOptions: getLabelImagePublicWidgetOptions
|
|
5078
3064
|
};
|
|
5079
3065
|
|
|
3066
|
+
// TODO(LEMS-2841): Should be able to remove once getPublicWidgetOptions is hooked up
|
|
3067
|
+
|
|
3068
|
+
// TODO(LEMS-2841): Should be able to remove once getPublicWidgetOptions is hooked up
|
|
3069
|
+
const shuffleMatcher = props => {
|
|
3070
|
+
// Use the same random() function to shuffle both columns sequentially
|
|
3071
|
+
const rng = seededRNG$1(props.problemNum);
|
|
3072
|
+
let left;
|
|
3073
|
+
if (!props.orderMatters) {
|
|
3074
|
+
// If the order doesn't matter, don't shuffle the left column
|
|
3075
|
+
left = props.left;
|
|
3076
|
+
} else {
|
|
3077
|
+
left = shuffle$1(props.left, rng, /* ensurePermuted */true);
|
|
3078
|
+
}
|
|
3079
|
+
const right = shuffle$1(props.right, rng, /* ensurePermuted */true);
|
|
3080
|
+
return {
|
|
3081
|
+
left,
|
|
3082
|
+
right
|
|
3083
|
+
};
|
|
3084
|
+
};
|
|
3085
|
+
|
|
3086
|
+
// TODO(LEMS-2841): Can shorten to shuffleMatcher after above function removed
|
|
3087
|
+
function shuffleMatcherWithRandom(data) {
|
|
3088
|
+
// Use the same random() function to shuffle both columns sequentially
|
|
3089
|
+
let left;
|
|
3090
|
+
if (!data.orderMatters) {
|
|
3091
|
+
// If the order doesn't matter, don't shuffle the left column
|
|
3092
|
+
left = data.left;
|
|
3093
|
+
} else {
|
|
3094
|
+
left = shuffle$1(data.left, Math.random, /* ensurePermuted */true);
|
|
3095
|
+
}
|
|
3096
|
+
const right = shuffle$1(data.right, Math.random, /* ensurePermuted */true);
|
|
3097
|
+
return {
|
|
3098
|
+
left,
|
|
3099
|
+
right
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
/**
|
|
3104
|
+
* For details on the individual options, see the
|
|
3105
|
+
* PerseusMatcherWidgetOptions type
|
|
3106
|
+
*/
|
|
3107
|
+
|
|
3108
|
+
/**
|
|
3109
|
+
* Given a PerseusMatcherWidgetOptions object, return a new object with only
|
|
3110
|
+
* the public options that should be exposed to the client.
|
|
3111
|
+
*/
|
|
3112
|
+
function getMatcherPublicWidgetOptions(options) {
|
|
3113
|
+
const {
|
|
3114
|
+
left,
|
|
3115
|
+
right
|
|
3116
|
+
} = shuffleMatcherWithRandom(options);
|
|
3117
|
+
return _extends({}, options, {
|
|
3118
|
+
left: left,
|
|
3119
|
+
right: right
|
|
3120
|
+
});
|
|
3121
|
+
}
|
|
3122
|
+
|
|
5080
3123
|
const defaultWidgetOptions$f = {
|
|
5081
3124
|
left: ["$x$", "$y$", "$z$"],
|
|
5082
3125
|
right: ["$1$", "$2$", "$3$"],
|
|
@@ -5086,7 +3129,8 @@ const defaultWidgetOptions$f = {
|
|
|
5086
3129
|
};
|
|
5087
3130
|
const matcherWidgetLogic = {
|
|
5088
3131
|
name: "matcher",
|
|
5089
|
-
defaultWidgetOptions: defaultWidgetOptions$f
|
|
3132
|
+
defaultWidgetOptions: defaultWidgetOptions$f,
|
|
3133
|
+
getPublicWidgetOptions: getMatcherPublicWidgetOptions
|
|
5090
3134
|
};
|
|
5091
3135
|
|
|
5092
3136
|
const _excluded$6 = ["answers"];
|
|
@@ -5180,13 +3224,35 @@ const _excluded$3 = ["answers"];
|
|
|
5180
3224
|
* PerseusNumericInputWidgetOptions type
|
|
5181
3225
|
*/
|
|
5182
3226
|
|
|
3227
|
+
/**
|
|
3228
|
+
* This data from `answers` is used pre-scoring to give hints
|
|
3229
|
+
* to the learner regarding the format of accepted answers
|
|
3230
|
+
*/
|
|
3231
|
+
function getNumericInputAnswerPublicData(answer) {
|
|
3232
|
+
const {
|
|
3233
|
+
answerForms,
|
|
3234
|
+
simplify,
|
|
3235
|
+
status
|
|
3236
|
+
} = answer;
|
|
3237
|
+
return {
|
|
3238
|
+
answerForms,
|
|
3239
|
+
simplify,
|
|
3240
|
+
status
|
|
3241
|
+
};
|
|
3242
|
+
}
|
|
3243
|
+
|
|
5183
3244
|
/**
|
|
5184
3245
|
* Given a PerseusNumericInputWidgetOptions object, return a new object with only
|
|
5185
3246
|
* the public options that should be exposed to the client.
|
|
5186
3247
|
*/
|
|
5187
3248
|
function getNumericInputPublicWidgetOptions(options) {
|
|
5188
|
-
const
|
|
5189
|
-
|
|
3249
|
+
const {
|
|
3250
|
+
answers
|
|
3251
|
+
} = options,
|
|
3252
|
+
publicWidgetOptions = _objectWithoutPropertiesLoose(options, _excluded$3);
|
|
3253
|
+
return _extends({}, publicWidgetOptions, {
|
|
3254
|
+
answers: answers.map(getNumericInputAnswerPublicData)
|
|
3255
|
+
});
|
|
5190
3256
|
}
|
|
5191
3257
|
|
|
5192
3258
|
const defaultWidgetOptions$b = {
|
|
@@ -5418,14 +3484,17 @@ const radioWidgetLogic = {
|
|
|
5418
3484
|
* the public options that should be exposed to the client.
|
|
5419
3485
|
*/
|
|
5420
3486
|
function getSorterPublicWidgetOptions(options) {
|
|
5421
|
-
|
|
3487
|
+
const shuffledCorrect = shuffle$1(options.correct, Math.random, /* ensurePermuted */true);
|
|
3488
|
+
return _extends({}, options, {
|
|
5422
3489
|
// Note(Tamara): This does not provide correct answer information any longer.
|
|
5423
3490
|
// To maintain compatibility with the original widget options, we are
|
|
5424
3491
|
// keeping the key the same. Represents initial state of the cards here.
|
|
5425
|
-
correct:
|
|
5426
|
-
|
|
5427
|
-
|
|
5428
|
-
|
|
3492
|
+
correct: shuffledCorrect,
|
|
3493
|
+
// Note(Tamara): This new key is only added here with "true". There isn't
|
|
3494
|
+
// a place where it is set to false. It indicates that the correct field
|
|
3495
|
+
// has been shuffled and no longer contains correct answer info.
|
|
3496
|
+
isCorrectShuffled: true
|
|
3497
|
+
});
|
|
5429
3498
|
}
|
|
5430
3499
|
|
|
5431
3500
|
const defaultWidgetOptions$2 = {
|
|
@@ -5724,5 +3793,58 @@ function splitPerseusItem(originalItem) {
|
|
|
5724
3793
|
});
|
|
5725
3794
|
}
|
|
5726
3795
|
|
|
5727
|
-
|
|
3796
|
+
/* Note(tamara): Brought over from the perseus package packages/perseus/src/util.ts file.
|
|
3797
|
+
May be useful to bring other perseus package utilities here. Contains utility functions
|
|
3798
|
+
and types used across multiple widgets for randomization and shuffling. */
|
|
3799
|
+
const seededRNG = function seededRNG(seed) {
|
|
3800
|
+
let randomSeed = seed;
|
|
3801
|
+
return function () {
|
|
3802
|
+
// Robert Jenkins' 32 bit integer hash function.
|
|
3803
|
+
let seed = randomSeed;
|
|
3804
|
+
seed = seed + 0x7ed55d16 + (seed << 12) & 0xffffffff;
|
|
3805
|
+
seed = (seed ^ 0xc761c23c ^ seed >>> 19) & 0xffffffff;
|
|
3806
|
+
seed = seed + 0x165667b1 + (seed << 5) & 0xffffffff;
|
|
3807
|
+
seed = (seed + 0xd3a2646c ^ seed << 9) & 0xffffffff;
|
|
3808
|
+
seed = seed + 0xfd7046c5 + (seed << 3) & 0xffffffff;
|
|
3809
|
+
seed = (seed ^ 0xb55a4f09 ^ seed >>> 16) & 0xffffffff;
|
|
3810
|
+
return (randomSeed = seed & 0xfffffff) / 0x10000000;
|
|
3811
|
+
};
|
|
3812
|
+
};
|
|
3813
|
+
|
|
3814
|
+
// Shuffle an array using a given random seed or function.
|
|
3815
|
+
// If `ensurePermuted` is true, the input and output are guaranteed to be
|
|
3816
|
+
// distinct permutations.
|
|
3817
|
+
function shuffle(array, randomSeed, ensurePermuted = false) {
|
|
3818
|
+
// Always return a copy of the input array
|
|
3819
|
+
const shuffled = _.clone(array);
|
|
3820
|
+
|
|
3821
|
+
// Handle edge cases (input array is empty or uniform)
|
|
3822
|
+
if (!shuffled.length || _.all(shuffled, function (value) {
|
|
3823
|
+
return _.isEqual(value, shuffled[0]);
|
|
3824
|
+
})) {
|
|
3825
|
+
return shuffled;
|
|
3826
|
+
}
|
|
3827
|
+
let random;
|
|
3828
|
+
if (typeof randomSeed === "function") {
|
|
3829
|
+
random = randomSeed;
|
|
3830
|
+
} else {
|
|
3831
|
+
random = seededRNG(randomSeed);
|
|
3832
|
+
}
|
|
3833
|
+
do {
|
|
3834
|
+
// Fischer-Yates shuffle
|
|
3835
|
+
for (let top = shuffled.length; top > 0; top--) {
|
|
3836
|
+
const newEnd = Math.floor(random() * top);
|
|
3837
|
+
const temp = shuffled[newEnd];
|
|
3838
|
+
|
|
3839
|
+
// @ts-expect-error - TS2542 - Index signature in type 'readonly T[]' only permits reading.
|
|
3840
|
+
shuffled[newEnd] = shuffled[top - 1];
|
|
3841
|
+
// @ts-expect-error - TS2542 - Index signature in type 'readonly T[]' only permits reading.
|
|
3842
|
+
shuffled[top - 1] = temp;
|
|
3843
|
+
}
|
|
3844
|
+
} while (ensurePermuted && _.isEqual(array, shuffled));
|
|
3845
|
+
return shuffled;
|
|
3846
|
+
}
|
|
3847
|
+
const random = seededRNG(new Date().getTime() & 0xffffffff);
|
|
3848
|
+
|
|
3849
|
+
export { coreWidgetRegistry as CoreWidgetRegistry, Errors, grapherUtil as GrapherUtil, ItemExtras, PerseusError, PerseusExpressionAnswerFormConsidered, addWidget, approximateDeepEqual, approximateEqual, categorizerWidgetLogic as categorizerLogic, csProgramWidgetLogic as csProgramLogic, deepClone, definitionWidgetLogic as definitionLogic, dropdownWidgetLogic as dropdownLogic, explanationWidgetLogic as explanationLogic, expressionWidgetLogic as expressionLogic, getCSProgramPublicWidgetOptions, getCategorizerPublicWidgetOptions, getDecimalSeparator, getDropdownPublicWidgetOptions, getExpressionPublicWidgetOptions, getGrapherPublicWidgetOptions, getIFramePublicWidgetOptions, getInteractiveGraphPublicWidgetOptions, getLabelImagePublicWidgetOptions, getMatcherPublicWidgetOptions, getMatrixPublicWidgetOptions, getMatrixSize, getNumberLinePublicWidgetOptions, getNumericInputPublicWidgetOptions, getOrdererPublicWidgetOptions, getPlotterPublicWidgetOptions, getRadioPublicWidgetOptions, getSorterPublicWidgetOptions, getTablePublicWidgetOptions, getUpgradedWidgetOptions, getWidgetIdsFromContent, getWidgetIdsFromContentByType, gradedGroupWidgetLogic as gradedGroupLogic, gradedGroupSetWidgetLogic as gradedGroupSetLogic, grapherWidgetLogic as grapherLogic, groupWidgetLogic as groupLogic, iframeWidgetLogic as iframeLogic, imageWidgetLogic as imageLogic, inputNumberWidgetLogic as inputNumberLogic, interactionWidgetLogic as interactionLogic, interactiveGraphWidgetLogic as interactiveGraphLogic, isFailure, isSuccess, labelImageWidgetLogic as labelImageLogic, libVersion, lockedFigureColorNames, lockedFigureColors, lockedFigureFillStyles, mapObject, matcherWidgetLogic as matcherLogic, matrixWidgetLogic as matrixLogic, measurerWidgetLogic as measurerLogic, numberLineWidgetLogic as numberLineLogic, numericInputWidgetLogic as numericInputLogic, ordererWidgetLogic as ordererLogic, parseAndMigratePerseusArticle, parseAndMigratePerseusItem, parsePerseusItem, passageWidgetLogic as passageLogic, passageRefWidgetLogic as passageRefLogic, passageRefTargetWidgetLogic as passageRefTargetLogic, phetSimulationWidgetLogic as phetSimulationLogic, plotterWidgetLogic as plotterLogic, plotterPlotTypes, pluck, pythonProgramWidgetLogic as pythonProgramLogic, radioWidgetLogic as radioLogic, random, seededRNG, shuffle, shuffleMatcher, sorterWidgetLogic as sorterLogic, splitPerseusItem, tableWidgetLogic as tableLogic, upgradeWidgetInfoToLatestVersion, videoWidgetLogic as videoLogic };
|
|
5728
3850
|
//# sourceMappingURL=index.js.map
|