UNPKG

604 kBJavaScriptView Raw
1/**
2 * vis-graph3d
3 * https://visjs.github.io/vis-graph3d/
4 *
5 * Create interactive, animated 3d graphs. Surfaces, lines, dots and block styling out of the box.
6 *
7 * @version 6.0.2
8 * @date 2021-08-22T15:02:30.974Z
9 *
10 * @copyright (c) 2011-2017 Almende B.V, http://almende.com
11 * @copyright (c) 2017-2019 visjs contributors, https://github.com/visjs
12 *
13 * @license
14 * vis.js is dual licensed under both
15 *
16 * 1. The Apache 2.0 License
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * and
20 *
21 * 2. The MIT License
22 * http://opensource.org/licenses/MIT
23 *
24 * vis.js may be distributed under either license.
25 */
26
27var ceil = Math.ceil;
28var floor$1 = Math.floor; // `ToInteger` abstract operation
29// https://tc39.es/ecma262/#sec-tointeger
30
31var toInteger = function (argument) {
32 return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor$1 : ceil)(argument);
33};
34
35var path = {};
36
37var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
38
39function unwrapExports (x) {
40 return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
41}
42
43function createCommonjsModule(fn, module) {
44 return module = { exports: {} }, fn(module, module.exports), module.exports;
45}
46
47var check = function (it) {
48 return it && it.Math == Math && it;
49}; // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
50
51
52var global_1 = // eslint-disable-next-line es/no-global-this -- safe
53check(typeof globalThis == 'object' && globalThis) || check(typeof window == 'object' && window) || // eslint-disable-next-line no-restricted-globals -- safe
54check(typeof self == 'object' && self) || check(typeof commonjsGlobal == 'object' && commonjsGlobal) || // eslint-disable-next-line no-new-func -- fallback
55function () {
56 return this;
57}() || Function('return this')();
58
59var aFunction$1 = function (variable) {
60 return typeof variable == 'function' ? variable : undefined;
61};
62
63var getBuiltIn = function (namespace, method) {
64 return arguments.length < 2 ? aFunction$1(path[namespace]) || aFunction$1(global_1[namespace]) : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method];
65};
66
67var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
68
69var process = global_1.process;
70var Deno = global_1.Deno;
71var versions = process && process.versions || Deno && Deno.version;
72var v8 = versions && versions.v8;
73var match, version;
74
75if (v8) {
76 match = v8.split('.');
77 version = match[0] < 4 ? 1 : match[0] + match[1];
78} else if (engineUserAgent) {
79 match = engineUserAgent.match(/Edge\/(\d+)/);
80
81 if (!match || match[1] >= 74) {
82 match = engineUserAgent.match(/Chrome\/(\d+)/);
83 if (match) version = match[1];
84 }
85}
86
87var engineV8Version = version && +version;
88
89var fails = function (exec) {
90 try {
91 return !!exec();
92 } catch (error) {
93 return true;
94 }
95};
96
97/* eslint-disable es/no-symbol -- required for testing */
98// eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
99
100var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
101 var symbol = Symbol(); // Chrome 38 Symbol has incorrect toString conversion
102 // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
103
104 return !String(symbol) || !(Object(symbol) instanceof Symbol) || // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
105 !Symbol.sham && engineV8Version && engineV8Version < 41;
106});
107
108/* eslint-disable es/no-symbol -- required for testing */
109
110var useSymbolAsUid = nativeSymbol && !Symbol.sham && typeof Symbol.iterator == 'symbol';
111
112var isSymbol = useSymbolAsUid ? function (it) {
113 return typeof it == 'symbol';
114} : function (it) {
115 var $Symbol = getBuiltIn('Symbol');
116 return typeof $Symbol == 'function' && Object(it) instanceof $Symbol;
117};
118
119var toString_1 = function (argument) {
120 if (isSymbol(argument)) throw TypeError('Cannot convert a Symbol value to a string');
121 return String(argument);
122};
123
124// `RequireObjectCoercible` abstract operation
125// https://tc39.es/ecma262/#sec-requireobjectcoercible
126var requireObjectCoercible = function (it) {
127 if (it == undefined) throw TypeError("Can't call method on " + it);
128 return it;
129};
130
131var createMethod$5 = function (CONVERT_TO_STRING) {
132 return function ($this, pos) {
133 var S = toString_1(requireObjectCoercible($this));
134 var position = toInteger(pos);
135 var size = S.length;
136 var first, second;
137 if (position < 0 || position >= size) return CONVERT_TO_STRING ? '' : undefined;
138 first = S.charCodeAt(position);
139 return first < 0xD800 || first > 0xDBFF || position + 1 === size || (second = S.charCodeAt(position + 1)) < 0xDC00 || second > 0xDFFF ? CONVERT_TO_STRING ? S.charAt(position) : first : CONVERT_TO_STRING ? S.slice(position, position + 2) : (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
140 };
141};
142
143var stringMultibyte = {
144 // `String.prototype.codePointAt` method
145 // https://tc39.es/ecma262/#sec-string.prototype.codepointat
146 codeAt: createMethod$5(false),
147 // `String.prototype.at` method
148 // https://github.com/mathiasbynens/String.prototype.at
149 charAt: createMethod$5(true)
150};
151
152var setGlobal = function (key, value) {
153 try {
154 // eslint-disable-next-line es/no-object-defineproperty -- safe
155 Object.defineProperty(global_1, key, {
156 value: value,
157 configurable: true,
158 writable: true
159 });
160 } catch (error) {
161 global_1[key] = value;
162 }
163
164 return value;
165};
166
167var SHARED = '__core-js_shared__';
168var store$1 = global_1[SHARED] || setGlobal(SHARED, {});
169var sharedStore = store$1;
170
171var functionToString = Function.toString; // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
172
173if (typeof sharedStore.inspectSource != 'function') {
174 sharedStore.inspectSource = function (it) {
175 return functionToString.call(it);
176 };
177}
178
179var inspectSource = sharedStore.inspectSource;
180
181var WeakMap$1 = global_1.WeakMap;
182var nativeWeakMap = typeof WeakMap$1 === 'function' && /native code/.test(inspectSource(WeakMap$1));
183
184var isObject$1 = function (it) {
185 return typeof it === 'object' ? it !== null : typeof it === 'function';
186};
187
188var descriptors = !fails(function () {
189 // eslint-disable-next-line es/no-object-defineproperty -- required for testing
190 return Object.defineProperty({}, 1, {
191 get: function () {
192 return 7;
193 }
194 })[1] != 7;
195});
196
197var document$1 = global_1.document; // typeof document.createElement is 'object' in old IE
198
199var EXISTS = isObject$1(document$1) && isObject$1(document$1.createElement);
200
201var documentCreateElement = function (it) {
202 return EXISTS ? document$1.createElement(it) : {};
203};
204
205var ie8DomDefine = !descriptors && !fails(function () {
206 // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
207 return Object.defineProperty(documentCreateElement('div'), 'a', {
208 get: function () {
209 return 7;
210 }
211 }).a != 7;
212});
213
214var anObject = function (it) {
215 if (!isObject$1(it)) {
216 throw TypeError(String(it) + ' is not an object');
217 }
218
219 return it;
220};
221
222// https://tc39.es/ecma262/#sec-ordinarytoprimitive
223
224var ordinaryToPrimitive = function (input, pref) {
225 var fn, val;
226 if (pref === 'string' && typeof (fn = input.toString) == 'function' && !isObject$1(val = fn.call(input))) return val;
227 if (typeof (fn = input.valueOf) == 'function' && !isObject$1(val = fn.call(input))) return val;
228 if (pref !== 'string' && typeof (fn = input.toString) == 'function' && !isObject$1(val = fn.call(input))) return val;
229 throw TypeError("Can't convert object to primitive value");
230};
231
232var shared = createCommonjsModule(function (module) {
233 (module.exports = function (key, value) {
234 return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
235 })('versions', []).push({
236 version: '3.16.1',
237 mode: 'pure' ,
238 copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
239 });
240});
241
242// https://tc39.es/ecma262/#sec-toobject
243
244var toObject = function (argument) {
245 return Object(requireObjectCoercible(argument));
246};
247
248var hasOwnProperty = {}.hasOwnProperty;
249
250var has$1 = Object.hasOwn || function hasOwn(it, key) {
251 return hasOwnProperty.call(toObject(it), key);
252};
253
254var id = 0;
255var postfix = Math.random();
256
257var uid = function (key) {
258 return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
259};
260
261var WellKnownSymbolsStore$1 = shared('wks');
262var Symbol$1 = global_1.Symbol;
263var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
264
265var wellKnownSymbol = function (name) {
266 if (!has$1(WellKnownSymbolsStore$1, name) || !(nativeSymbol || typeof WellKnownSymbolsStore$1[name] == 'string')) {
267 if (nativeSymbol && has$1(Symbol$1, name)) {
268 WellKnownSymbolsStore$1[name] = Symbol$1[name];
269 } else {
270 WellKnownSymbolsStore$1[name] = createWellKnownSymbol('Symbol.' + name);
271 }
272 }
273
274 return WellKnownSymbolsStore$1[name];
275};
276
277var TO_PRIMITIVE$1 = wellKnownSymbol('toPrimitive'); // `ToPrimitive` abstract operation
278// https://tc39.es/ecma262/#sec-toprimitive
279
280var toPrimitive = function (input, pref) {
281 if (!isObject$1(input) || isSymbol(input)) return input;
282 var exoticToPrim = input[TO_PRIMITIVE$1];
283 var result;
284
285 if (exoticToPrim !== undefined) {
286 if (pref === undefined) pref = 'default';
287 result = exoticToPrim.call(input, pref);
288 if (!isObject$1(result) || isSymbol(result)) return result;
289 throw TypeError("Can't convert object to primitive value");
290 }
291
292 if (pref === undefined) pref = 'number';
293 return ordinaryToPrimitive(input, pref);
294};
295
296// https://tc39.es/ecma262/#sec-topropertykey
297
298var toPropertyKey = function (argument) {
299 var key = toPrimitive(argument, 'string');
300 return isSymbol(key) ? key : String(key);
301};
302
303var $defineProperty$1 = Object.defineProperty; // `Object.defineProperty` method
304// https://tc39.es/ecma262/#sec-object.defineproperty
305
306var f$6 = descriptors ? $defineProperty$1 : function defineProperty(O, P, Attributes) {
307 anObject(O);
308 P = toPropertyKey(P);
309 anObject(Attributes);
310 if (ie8DomDefine) try {
311 return $defineProperty$1(O, P, Attributes);
312 } catch (error) {
313 /* empty */
314 }
315 if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
316 if ('value' in Attributes) O[P] = Attributes.value;
317 return O;
318};
319var objectDefineProperty = {
320 f: f$6
321};
322
323var createPropertyDescriptor = function (bitmap, value) {
324 return {
325 enumerable: !(bitmap & 1),
326 configurable: !(bitmap & 2),
327 writable: !(bitmap & 4),
328 value: value
329 };
330};
331
332var createNonEnumerableProperty = descriptors ? function (object, key, value) {
333 return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
334} : function (object, key, value) {
335 object[key] = value;
336 return object;
337};
338
339var keys$6 = shared('keys');
340
341var sharedKey = function (key) {
342 return keys$6[key] || (keys$6[key] = uid(key));
343};
344
345var hiddenKeys$1 = {};
346
347var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
348var WeakMap = global_1.WeakMap;
349var set$3, get, has;
350
351var enforce = function (it) {
352 return has(it) ? get(it) : set$3(it, {});
353};
354
355var getterFor = function (TYPE) {
356 return function (it) {
357 var state;
358
359 if (!isObject$1(it) || (state = get(it)).type !== TYPE) {
360 throw TypeError('Incompatible receiver, ' + TYPE + ' required');
361 }
362
363 return state;
364 };
365};
366
367if (nativeWeakMap || sharedStore.state) {
368 var store = sharedStore.state || (sharedStore.state = new WeakMap());
369 var wmget = store.get;
370 var wmhas = store.has;
371 var wmset = store.set;
372
373 set$3 = function (it, metadata) {
374 if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
375 metadata.facade = it;
376 wmset.call(store, it, metadata);
377 return metadata;
378 };
379
380 get = function (it) {
381 return wmget.call(store, it) || {};
382 };
383
384 has = function (it) {
385 return wmhas.call(store, it);
386 };
387} else {
388 var STATE = sharedKey('state');
389 hiddenKeys$1[STATE] = true;
390
391 set$3 = function (it, metadata) {
392 if (has$1(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
393 metadata.facade = it;
394 createNonEnumerableProperty(it, STATE, metadata);
395 return metadata;
396 };
397
398 get = function (it) {
399 return has$1(it, STATE) ? it[STATE] : {};
400 };
401
402 has = function (it) {
403 return has$1(it, STATE);
404 };
405}
406
407var internalState = {
408 set: set$3,
409 get: get,
410 has: has,
411 enforce: enforce,
412 getterFor: getterFor
413};
414
415var $propertyIsEnumerable$1 = {}.propertyIsEnumerable; // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
416
417var getOwnPropertyDescriptor$3 = Object.getOwnPropertyDescriptor; // Nashorn ~ JDK8 bug
418
419var NASHORN_BUG = getOwnPropertyDescriptor$3 && !$propertyIsEnumerable$1.call({
420 1: 2
421}, 1); // `Object.prototype.propertyIsEnumerable` method implementation
422// https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
423
424var f$5 = NASHORN_BUG ? function propertyIsEnumerable(V) {
425 var descriptor = getOwnPropertyDescriptor$3(this, V);
426 return !!descriptor && descriptor.enumerable;
427} : $propertyIsEnumerable$1;
428var objectPropertyIsEnumerable = {
429 f: f$5
430};
431
432var toString$1 = {}.toString;
433
434var classofRaw = function (it) {
435 return toString$1.call(it).slice(8, -1);
436};
437
438var split = ''.split; // fallback for non-array-like ES3 and non-enumerable old V8 strings
439
440var indexedObject = fails(function () {
441 // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
442 // eslint-disable-next-line no-prototype-builtins -- safe
443 return !Object('z').propertyIsEnumerable(0);
444}) ? function (it) {
445 return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
446} : Object;
447
448var toIndexedObject = function (it) {
449 return indexedObject(requireObjectCoercible(it));
450};
451
452var $getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor; // `Object.getOwnPropertyDescriptor` method
453// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
454
455var f$4 = descriptors ? $getOwnPropertyDescriptor$1 : function getOwnPropertyDescriptor(O, P) {
456 O = toIndexedObject(O);
457 P = toPropertyKey(P);
458 if (ie8DomDefine) try {
459 return $getOwnPropertyDescriptor$1(O, P);
460 } catch (error) {
461 /* empty */
462 }
463 if (has$1(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
464};
465var objectGetOwnPropertyDescriptor = {
466 f: f$4
467};
468
469var replacement = /#|\.prototype\./;
470
471var isForced = function (feature, detection) {
472 var value = data[normalize(feature)];
473 return value == POLYFILL ? true : value == NATIVE ? false : typeof detection == 'function' ? fails(detection) : !!detection;
474};
475
476var normalize = isForced.normalize = function (string) {
477 return String(string).replace(replacement, '.').toLowerCase();
478};
479
480var data = isForced.data = {};
481var NATIVE = isForced.NATIVE = 'N';
482var POLYFILL = isForced.POLYFILL = 'P';
483var isForced_1 = isForced;
484
485var aFunction = function (it) {
486 if (typeof it != 'function') {
487 throw TypeError(String(it) + ' is not a function');
488 }
489
490 return it;
491};
492
493var functionBindContext = function (fn, that, length) {
494 aFunction(fn);
495 if (that === undefined) return fn;
496
497 switch (length) {
498 case 0:
499 return function () {
500 return fn.call(that);
501 };
502
503 case 1:
504 return function (a) {
505 return fn.call(that, a);
506 };
507
508 case 2:
509 return function (a, b) {
510 return fn.call(that, a, b);
511 };
512
513 case 3:
514 return function (a, b, c) {
515 return fn.call(that, a, b, c);
516 };
517 }
518
519 return function () {
520 return fn.apply(that, arguments);
521 };
522};
523
524var getOwnPropertyDescriptor$2 = objectGetOwnPropertyDescriptor.f;
525
526var wrapConstructor = function (NativeConstructor) {
527 var Wrapper = function (a, b, c) {
528 if (this instanceof NativeConstructor) {
529 switch (arguments.length) {
530 case 0:
531 return new NativeConstructor();
532
533 case 1:
534 return new NativeConstructor(a);
535
536 case 2:
537 return new NativeConstructor(a, b);
538 }
539
540 return new NativeConstructor(a, b, c);
541 }
542
543 return NativeConstructor.apply(this, arguments);
544 };
545
546 Wrapper.prototype = NativeConstructor.prototype;
547 return Wrapper;
548};
549/*
550 options.target - name of the target object
551 options.global - target is the global object
552 options.stat - export as static methods of target
553 options.proto - export as prototype methods of target
554 options.real - real prototype method for the `pure` version
555 options.forced - export even if the native feature is available
556 options.bind - bind methods to the target, required for the `pure` version
557 options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
558 options.unsafe - use the simple assignment of property instead of delete + defineProperty
559 options.sham - add a flag to not completely full polyfills
560 options.enumerable - export as enumerable property
561 options.noTargetGet - prevent calling a getter on target
562*/
563
564
565var _export = function (options, source) {
566 var TARGET = options.target;
567 var GLOBAL = options.global;
568 var STATIC = options.stat;
569 var PROTO = options.proto;
570 var nativeSource = GLOBAL ? global_1 : STATIC ? global_1[TARGET] : (global_1[TARGET] || {}).prototype;
571 var target = GLOBAL ? path : path[TARGET] || (path[TARGET] = {});
572 var targetPrototype = target.prototype;
573 var FORCED, USE_NATIVE, VIRTUAL_PROTOTYPE;
574 var key, sourceProperty, targetProperty, nativeProperty, resultProperty, descriptor;
575
576 for (key in source) {
577 FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced); // contains in native
578
579 USE_NATIVE = !FORCED && nativeSource && has$1(nativeSource, key);
580 targetProperty = target[key];
581 if (USE_NATIVE) if (options.noTargetGet) {
582 descriptor = getOwnPropertyDescriptor$2(nativeSource, key);
583 nativeProperty = descriptor && descriptor.value;
584 } else nativeProperty = nativeSource[key]; // export native or implementation
585
586 sourceProperty = USE_NATIVE && nativeProperty ? nativeProperty : source[key];
587 if (USE_NATIVE && typeof targetProperty === typeof sourceProperty) continue; // bind timers to global for call from export context
588
589 if (options.bind && USE_NATIVE) resultProperty = functionBindContext(sourceProperty, global_1); // wrap global constructors for prevent changs in this version
590 else if (options.wrap && USE_NATIVE) resultProperty = wrapConstructor(sourceProperty); // make static versions for prototype methods
591 else if (PROTO && typeof sourceProperty == 'function') resultProperty = functionBindContext(Function.call, sourceProperty); // default case
592 else resultProperty = sourceProperty; // add a flag to not completely full polyfills
593
594 if (options.sham || sourceProperty && sourceProperty.sham || targetProperty && targetProperty.sham) {
595 createNonEnumerableProperty(resultProperty, 'sham', true);
596 }
597
598 target[key] = resultProperty;
599
600 if (PROTO) {
601 VIRTUAL_PROTOTYPE = TARGET + 'Prototype';
602
603 if (!has$1(path, VIRTUAL_PROTOTYPE)) {
604 createNonEnumerableProperty(path, VIRTUAL_PROTOTYPE, {});
605 } // export virtual prototype methods
606
607
608 path[VIRTUAL_PROTOTYPE][key] = sourceProperty; // export real prototype methods
609
610 if (options.real && targetPrototype && !targetPrototype[key]) {
611 createNonEnumerableProperty(targetPrototype, key, sourceProperty);
612 }
613 }
614 }
615};
616
617var correctPrototypeGetter = !fails(function () {
618 function F() {
619 /* empty */
620 }
621
622 F.prototype.constructor = null; // eslint-disable-next-line es/no-object-getprototypeof -- required for testing
623
624 return Object.getPrototypeOf(new F()) !== F.prototype;
625});
626
627var IE_PROTO$1 = sharedKey('IE_PROTO');
628var ObjectPrototype$1 = Object.prototype; // `Object.getPrototypeOf` method
629// https://tc39.es/ecma262/#sec-object.getprototypeof
630// eslint-disable-next-line es/no-object-getprototypeof -- safe
631
632var objectGetPrototypeOf = correctPrototypeGetter ? Object.getPrototypeOf : function (O) {
633 O = toObject(O);
634 if (has$1(O, IE_PROTO$1)) return O[IE_PROTO$1];
635
636 if (typeof O.constructor == 'function' && O instanceof O.constructor) {
637 return O.constructor.prototype;
638 }
639
640 return O instanceof Object ? ObjectPrototype$1 : null;
641};
642
643var ITERATOR$4 = wellKnownSymbol('iterator');
644var BUGGY_SAFARI_ITERATORS$1 = false;
645
646var returnThis$2 = function () {
647 return this;
648}; // `%IteratorPrototype%` object
649// https://tc39.es/ecma262/#sec-%iteratorprototype%-object
650
651
652var IteratorPrototype$2, PrototypeOfArrayIteratorPrototype, arrayIterator;
653/* eslint-disable es/no-array-prototype-keys -- safe */
654
655if ([].keys) {
656 arrayIterator = [].keys(); // Safari 8 has buggy iterators w/o `next`
657
658 if (!('next' in arrayIterator)) BUGGY_SAFARI_ITERATORS$1 = true;else {
659 PrototypeOfArrayIteratorPrototype = objectGetPrototypeOf(objectGetPrototypeOf(arrayIterator));
660 if (PrototypeOfArrayIteratorPrototype !== Object.prototype) IteratorPrototype$2 = PrototypeOfArrayIteratorPrototype;
661 }
662}
663
664var NEW_ITERATOR_PROTOTYPE = IteratorPrototype$2 == undefined || fails(function () {
665 var test = {}; // FF44- legacy iterators case
666
667 return IteratorPrototype$2[ITERATOR$4].call(test) !== test;
668});
669if (NEW_ITERATOR_PROTOTYPE) IteratorPrototype$2 = {}; // `%IteratorPrototype%[@@iterator]()` method
670// https://tc39.es/ecma262/#sec-%iteratorprototype%-@@iterator
671
672if ((NEW_ITERATOR_PROTOTYPE) && !has$1(IteratorPrototype$2, ITERATOR$4)) {
673 createNonEnumerableProperty(IteratorPrototype$2, ITERATOR$4, returnThis$2);
674}
675
676var iteratorsCore = {
677 IteratorPrototype: IteratorPrototype$2,
678 BUGGY_SAFARI_ITERATORS: BUGGY_SAFARI_ITERATORS$1
679};
680
681var min$2 = Math.min; // `ToLength` abstract operation
682// https://tc39.es/ecma262/#sec-tolength
683
684var toLength = function (argument) {
685 return argument > 0 ? min$2(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
686};
687
688var max$2 = Math.max;
689var min$1 = Math.min; // Helper for a popular repeating case of the spec:
690// Let integer be ? ToInteger(index).
691// If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
692
693var toAbsoluteIndex = function (index, length) {
694 var integer = toInteger(index);
695 return integer < 0 ? max$2(integer + length, 0) : min$1(integer, length);
696};
697
698var createMethod$4 = function (IS_INCLUDES) {
699 return function ($this, el, fromIndex) {
700 var O = toIndexedObject($this);
701 var length = toLength(O.length);
702 var index = toAbsoluteIndex(fromIndex, length);
703 var value; // Array#includes uses SameValueZero equality algorithm
704 // eslint-disable-next-line no-self-compare -- NaN check
705
706 if (IS_INCLUDES && el != el) while (length > index) {
707 value = O[index++]; // eslint-disable-next-line no-self-compare -- NaN check
708
709 if (value != value) return true; // Array#indexOf ignores holes, Array#includes - not
710 } else for (; length > index; index++) {
711 if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
712 }
713 return !IS_INCLUDES && -1;
714 };
715};
716
717var arrayIncludes = {
718 // `Array.prototype.includes` method
719 // https://tc39.es/ecma262/#sec-array.prototype.includes
720 includes: createMethod$4(true),
721 // `Array.prototype.indexOf` method
722 // https://tc39.es/ecma262/#sec-array.prototype.indexof
723 indexOf: createMethod$4(false)
724};
725
726var indexOf$3 = arrayIncludes.indexOf;
727
728var objectKeysInternal = function (object, names) {
729 var O = toIndexedObject(object);
730 var i = 0;
731 var result = [];
732 var key;
733
734 for (key in O) !has$1(hiddenKeys$1, key) && has$1(O, key) && result.push(key); // Don't enum bug & hidden keys
735
736
737 while (names.length > i) if (has$1(O, key = names[i++])) {
738 ~indexOf$3(result, key) || result.push(key);
739 }
740
741 return result;
742};
743
744// IE8- don't enum bug keys
745var enumBugKeys = ['constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf'];
746
747// https://tc39.es/ecma262/#sec-object.keys
748// eslint-disable-next-line es/no-object-keys -- safe
749
750var objectKeys = Object.keys || function keys(O) {
751 return objectKeysInternal(O, enumBugKeys);
752};
753
754// https://tc39.es/ecma262/#sec-object.defineproperties
755// eslint-disable-next-line es/no-object-defineproperties -- safe
756
757var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
758 anObject(O);
759 var keys = objectKeys(Properties);
760 var length = keys.length;
761 var index = 0;
762 var key;
763
764 while (length > index) objectDefineProperty.f(O, key = keys[index++], Properties[key]);
765
766 return O;
767};
768
769var html = getBuiltIn('document', 'documentElement');
770
771/* global ActiveXObject -- old IE, WSH */
772
773var GT = '>';
774var LT = '<';
775var PROTOTYPE$1 = 'prototype';
776var SCRIPT = 'script';
777var IE_PROTO = sharedKey('IE_PROTO');
778
779var EmptyConstructor = function () {
780 /* empty */
781};
782
783var scriptTag = function (content) {
784 return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
785}; // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
786
787
788var NullProtoObjectViaActiveX = function (activeXDocument) {
789 activeXDocument.write(scriptTag(''));
790 activeXDocument.close();
791 var temp = activeXDocument.parentWindow.Object;
792 activeXDocument = null; // avoid memory leak
793
794 return temp;
795}; // Create object with fake `null` prototype: use iframe Object with cleared prototype
796
797
798var NullProtoObjectViaIFrame = function () {
799 // Thrash, waste and sodomy: IE GC bug
800 var iframe = documentCreateElement('iframe');
801 var JS = 'java' + SCRIPT + ':';
802 var iframeDocument;
803
804 if (iframe.style) {
805 iframe.style.display = 'none';
806 html.appendChild(iframe); // https://github.com/zloirock/core-js/issues/475
807
808 iframe.src = String(JS);
809 iframeDocument = iframe.contentWindow.document;
810 iframeDocument.open();
811 iframeDocument.write(scriptTag('document.F=Object'));
812 iframeDocument.close();
813 return iframeDocument.F;
814 }
815}; // Check for document.domain and active x support
816// No need to use active x approach when document.domain is not set
817// see https://github.com/es-shims/es5-shim/issues/150
818// variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
819// avoid IE GC bug
820
821
822var activeXDocument;
823
824var NullProtoObject = function () {
825 try {
826 activeXDocument = new ActiveXObject('htmlfile');
827 } catch (error) {
828 /* ignore */
829 }
830
831 NullProtoObject = document.domain && activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : // old IE
832 NullProtoObjectViaIFrame() || NullProtoObjectViaActiveX(activeXDocument); // WSH
833
834 var length = enumBugKeys.length;
835
836 while (length--) delete NullProtoObject[PROTOTYPE$1][enumBugKeys[length]];
837
838 return NullProtoObject();
839};
840
841hiddenKeys$1[IE_PROTO] = true; // `Object.create` method
842// https://tc39.es/ecma262/#sec-object.create
843
844var objectCreate = Object.create || function create(O, Properties) {
845 var result;
846
847 if (O !== null) {
848 EmptyConstructor[PROTOTYPE$1] = anObject(O);
849 result = new EmptyConstructor();
850 EmptyConstructor[PROTOTYPE$1] = null; // add "__proto__" for Object.getPrototypeOf polyfill
851
852 result[IE_PROTO] = O;
853 } else result = NullProtoObject();
854
855 return Properties === undefined ? result : objectDefineProperties(result, Properties);
856};
857
858var TO_STRING_TAG$3 = wellKnownSymbol('toStringTag');
859var test$2 = {};
860test$2[TO_STRING_TAG$3] = 'z';
861var toStringTagSupport = String(test$2) === '[object z]';
862
863var TO_STRING_TAG$2 = wellKnownSymbol('toStringTag'); // ES3 wrong here
864
865var CORRECT_ARGUMENTS = classofRaw(function () {
866 return arguments;
867}()) == 'Arguments'; // fallback for IE11 Script Access Denied error
868
869var tryGet = function (it, key) {
870 try {
871 return it[key];
872 } catch (error) {
873 /* empty */
874 }
875}; // getting tag from ES6+ `Object.prototype.toString`
876
877
878var classof = toStringTagSupport ? classofRaw : function (it) {
879 var O, tag, result;
880 return it === undefined ? 'Undefined' : it === null ? 'Null' // @@toStringTag case
881 : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG$2)) == 'string' ? tag // builtinTag case
882 : CORRECT_ARGUMENTS ? classofRaw(O) // ES3 arguments fallback
883 : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result;
884};
885
886// https://tc39.es/ecma262/#sec-object.prototype.tostring
887
888
889var objectToString = toStringTagSupport ? {}.toString : function toString() {
890 return '[object ' + classof(this) + ']';
891};
892
893var defineProperty$9 = objectDefineProperty.f;
894var TO_STRING_TAG$1 = wellKnownSymbol('toStringTag');
895
896var setToStringTag = function (it, TAG, STATIC, SET_METHOD) {
897 if (it) {
898 var target = STATIC ? it : it.prototype;
899
900 if (!has$1(target, TO_STRING_TAG$1)) {
901 defineProperty$9(target, TO_STRING_TAG$1, {
902 configurable: true,
903 value: TAG
904 });
905 }
906
907 if (SET_METHOD && !toStringTagSupport) {
908 createNonEnumerableProperty(target, 'toString', objectToString);
909 }
910 }
911};
912
913var iterators = {};
914
915var IteratorPrototype$1 = iteratorsCore.IteratorPrototype;
916
917var returnThis$1 = function () {
918 return this;
919};
920
921var createIteratorConstructor = function (IteratorConstructor, NAME, next) {
922 var TO_STRING_TAG = NAME + ' Iterator';
923 IteratorConstructor.prototype = objectCreate(IteratorPrototype$1, {
924 next: createPropertyDescriptor(1, next)
925 });
926 setToStringTag(IteratorConstructor, TO_STRING_TAG, false, true);
927 iterators[TO_STRING_TAG] = returnThis$1;
928 return IteratorConstructor;
929};
930
931var aPossiblePrototype = function (it) {
932 if (!isObject$1(it) && it !== null) {
933 throw TypeError("Can't set " + String(it) + ' as a prototype');
934 }
935
936 return it;
937};
938
939/* eslint-disable no-proto -- safe */
940// `Object.setPrototypeOf` method
941// https://tc39.es/ecma262/#sec-object.setprototypeof
942// Works with __proto__ only. Old v8 can't work with null proto objects.
943// eslint-disable-next-line es/no-object-setprototypeof -- safe
944
945var objectSetPrototypeOf = Object.setPrototypeOf || ('__proto__' in {} ? function () {
946 var CORRECT_SETTER = false;
947 var test = {};
948 var setter;
949
950 try {
951 // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
952 setter = Object.getOwnPropertyDescriptor(Object.prototype, '__proto__').set;
953 setter.call(test, []);
954 CORRECT_SETTER = test instanceof Array;
955 } catch (error) {
956 /* empty */
957 }
958
959 return function setPrototypeOf(O, proto) {
960 anObject(O);
961 aPossiblePrototype(proto);
962 if (CORRECT_SETTER) setter.call(O, proto);else O.__proto__ = proto;
963 return O;
964 };
965}() : undefined);
966
967var redefine = function (target, key, value, options) {
968 if (options && options.enumerable) target[key] = value;else createNonEnumerableProperty(target, key, value);
969};
970
971var IteratorPrototype = iteratorsCore.IteratorPrototype;
972var BUGGY_SAFARI_ITERATORS = iteratorsCore.BUGGY_SAFARI_ITERATORS;
973var ITERATOR$3 = wellKnownSymbol('iterator');
974var KEYS = 'keys';
975var VALUES = 'values';
976var ENTRIES = 'entries';
977
978var returnThis = function () {
979 return this;
980};
981
982var defineIterator = function (Iterable, NAME, IteratorConstructor, next, DEFAULT, IS_SET, FORCED) {
983 createIteratorConstructor(IteratorConstructor, NAME, next);
984
985 var getIterationMethod = function (KIND) {
986 if (KIND === DEFAULT && defaultIterator) return defaultIterator;
987 if (!BUGGY_SAFARI_ITERATORS && KIND in IterablePrototype) return IterablePrototype[KIND];
988
989 switch (KIND) {
990 case KEYS:
991 return function keys() {
992 return new IteratorConstructor(this, KIND);
993 };
994
995 case VALUES:
996 return function values() {
997 return new IteratorConstructor(this, KIND);
998 };
999
1000 case ENTRIES:
1001 return function entries() {
1002 return new IteratorConstructor(this, KIND);
1003 };
1004 }
1005
1006 return function () {
1007 return new IteratorConstructor(this);
1008 };
1009 };
1010
1011 var TO_STRING_TAG = NAME + ' Iterator';
1012 var INCORRECT_VALUES_NAME = false;
1013 var IterablePrototype = Iterable.prototype;
1014 var nativeIterator = IterablePrototype[ITERATOR$3] || IterablePrototype['@@iterator'] || DEFAULT && IterablePrototype[DEFAULT];
1015 var defaultIterator = !BUGGY_SAFARI_ITERATORS && nativeIterator || getIterationMethod(DEFAULT);
1016 var anyNativeIterator = NAME == 'Array' ? IterablePrototype.entries || nativeIterator : nativeIterator;
1017 var CurrentIteratorPrototype, methods, KEY; // fix native
1018
1019 if (anyNativeIterator) {
1020 CurrentIteratorPrototype = objectGetPrototypeOf(anyNativeIterator.call(new Iterable()));
1021
1022 if (IteratorPrototype !== Object.prototype && CurrentIteratorPrototype.next) {
1023
1024
1025 setToStringTag(CurrentIteratorPrototype, TO_STRING_TAG, true, true);
1026 iterators[TO_STRING_TAG] = returnThis;
1027 }
1028 } // fix Array.prototype.{ values, @@iterator }.name in V8 / FF
1029
1030
1031 if (DEFAULT == VALUES && nativeIterator && nativeIterator.name !== VALUES) {
1032 INCORRECT_VALUES_NAME = true;
1033
1034 defaultIterator = function values() {
1035 return nativeIterator.call(this);
1036 };
1037 } // define iterator
1038
1039
1040 if ((FORCED) && IterablePrototype[ITERATOR$3] !== defaultIterator) {
1041 createNonEnumerableProperty(IterablePrototype, ITERATOR$3, defaultIterator);
1042 }
1043
1044 iterators[NAME] = defaultIterator; // export additional methods
1045
1046 if (DEFAULT) {
1047 methods = {
1048 values: getIterationMethod(VALUES),
1049 keys: IS_SET ? defaultIterator : getIterationMethod(KEYS),
1050 entries: getIterationMethod(ENTRIES)
1051 };
1052 if (FORCED) for (KEY in methods) {
1053 if (BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME || !(KEY in IterablePrototype)) {
1054 redefine(IterablePrototype, KEY, methods[KEY]);
1055 }
1056 } else _export({
1057 target: NAME,
1058 proto: true,
1059 forced: BUGGY_SAFARI_ITERATORS || INCORRECT_VALUES_NAME
1060 }, methods);
1061 }
1062
1063 return methods;
1064};
1065
1066var charAt = stringMultibyte.charAt;
1067var STRING_ITERATOR = 'String Iterator';
1068var setInternalState$4 = internalState.set;
1069var getInternalState$2 = internalState.getterFor(STRING_ITERATOR); // `String.prototype[@@iterator]` method
1070// https://tc39.es/ecma262/#sec-string.prototype-@@iterator
1071
1072defineIterator(String, 'String', function (iterated) {
1073 setInternalState$4(this, {
1074 type: STRING_ITERATOR,
1075 string: toString_1(iterated),
1076 index: 0
1077 }); // `%StringIteratorPrototype%.next` method
1078 // https://tc39.es/ecma262/#sec-%stringiteratorprototype%.next
1079}, function next() {
1080 var state = getInternalState$2(this);
1081 var string = state.string;
1082 var index = state.index;
1083 var point;
1084 if (index >= string.length) return {
1085 value: undefined,
1086 done: true
1087 };
1088 point = charAt(string, index);
1089 state.index += point.length;
1090 return {
1091 value: point,
1092 done: false
1093 };
1094});
1095
1096var iteratorClose = function (iterator) {
1097 var returnMethod = iterator['return'];
1098
1099 if (returnMethod !== undefined) {
1100 return anObject(returnMethod.call(iterator)).value;
1101 }
1102};
1103
1104var callWithSafeIterationClosing = function (iterator, fn, value, ENTRIES) {
1105 try {
1106 return ENTRIES ? fn(anObject(value)[0], value[1]) : fn(value);
1107 } catch (error) {
1108 iteratorClose(iterator);
1109 throw error;
1110 }
1111};
1112
1113var ITERATOR$2 = wellKnownSymbol('iterator');
1114var ArrayPrototype$h = Array.prototype; // check on default Array iterator
1115
1116var isArrayIteratorMethod = function (it) {
1117 return it !== undefined && (iterators.Array === it || ArrayPrototype$h[ITERATOR$2] === it);
1118};
1119
1120var createProperty = function (object, key, value) {
1121 var propertyKey = toPropertyKey(key);
1122 if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));else object[propertyKey] = value;
1123};
1124
1125var ITERATOR$1 = wellKnownSymbol('iterator');
1126
1127var getIteratorMethod$3 = function (it) {
1128 if (it != undefined) return it[ITERATOR$1] || it['@@iterator'] || iterators[classof(it)];
1129};
1130
1131// https://tc39.es/ecma262/#sec-array.from
1132
1133
1134var arrayFrom = function from(arrayLike
1135/* , mapfn = undefined, thisArg = undefined */
1136) {
1137 var O = toObject(arrayLike);
1138 var C = typeof this == 'function' ? this : Array;
1139 var argumentsLength = arguments.length;
1140 var mapfn = argumentsLength > 1 ? arguments[1] : undefined;
1141 var mapping = mapfn !== undefined;
1142 var iteratorMethod = getIteratorMethod$3(O);
1143 var index = 0;
1144 var length, result, step, iterator, next, value;
1145 if (mapping) mapfn = functionBindContext(mapfn, argumentsLength > 2 ? arguments[2] : undefined, 2); // if the target is not iterable or it's an array with the default iterator - use a simple case
1146
1147 if (iteratorMethod != undefined && !(C == Array && isArrayIteratorMethod(iteratorMethod))) {
1148 iterator = iteratorMethod.call(O);
1149 next = iterator.next;
1150 result = new C();
1151
1152 for (; !(step = next.call(iterator)).done; index++) {
1153 value = mapping ? callWithSafeIterationClosing(iterator, mapfn, [step.value, index], true) : step.value;
1154 createProperty(result, index, value);
1155 }
1156 } else {
1157 length = toLength(O.length);
1158 result = new C(length);
1159
1160 for (; length > index; index++) {
1161 value = mapping ? mapfn(O[index], index) : O[index];
1162 createProperty(result, index, value);
1163 }
1164 }
1165
1166 result.length = index;
1167 return result;
1168};
1169
1170var ITERATOR = wellKnownSymbol('iterator');
1171var SAFE_CLOSING = false;
1172
1173try {
1174 var called = 0;
1175 var iteratorWithReturn = {
1176 next: function () {
1177 return {
1178 done: !!called++
1179 };
1180 },
1181 'return': function () {
1182 SAFE_CLOSING = true;
1183 }
1184 };
1185
1186 iteratorWithReturn[ITERATOR] = function () {
1187 return this;
1188 }; // eslint-disable-next-line es/no-array-from, no-throw-literal -- required for testing
1189
1190
1191 Array.from(iteratorWithReturn, function () {
1192 throw 2;
1193 });
1194} catch (error) {
1195 /* empty */
1196}
1197
1198var checkCorrectnessOfIteration = function (exec, SKIP_CLOSING) {
1199 if (!SKIP_CLOSING && !SAFE_CLOSING) return false;
1200 var ITERATION_SUPPORT = false;
1201
1202 try {
1203 var object = {};
1204
1205 object[ITERATOR] = function () {
1206 return {
1207 next: function () {
1208 return {
1209 done: ITERATION_SUPPORT = true
1210 };
1211 }
1212 };
1213 };
1214
1215 exec(object);
1216 } catch (error) {
1217 /* empty */
1218 }
1219
1220 return ITERATION_SUPPORT;
1221};
1222
1223var INCORRECT_ITERATION = !checkCorrectnessOfIteration(function (iterable) {
1224 // eslint-disable-next-line es/no-array-from -- required for testing
1225 Array.from(iterable);
1226}); // `Array.from` method
1227// https://tc39.es/ecma262/#sec-array.from
1228
1229_export({
1230 target: 'Array',
1231 stat: true,
1232 forced: INCORRECT_ITERATION
1233}, {
1234 from: arrayFrom
1235});
1236
1237var from_1$4 = path.Array.from;
1238
1239var from_1$3 = from_1$4;
1240
1241var from_1$2 = from_1$3;
1242
1243var ARRAY_ITERATOR = 'Array Iterator';
1244var setInternalState$3 = internalState.set;
1245var getInternalState$1 = internalState.getterFor(ARRAY_ITERATOR); // `Array.prototype.entries` method
1246// https://tc39.es/ecma262/#sec-array.prototype.entries
1247// `Array.prototype.keys` method
1248// https://tc39.es/ecma262/#sec-array.prototype.keys
1249// `Array.prototype.values` method
1250// https://tc39.es/ecma262/#sec-array.prototype.values
1251// `Array.prototype[@@iterator]` method
1252// https://tc39.es/ecma262/#sec-array.prototype-@@iterator
1253// `CreateArrayIterator` internal method
1254// https://tc39.es/ecma262/#sec-createarrayiterator
1255
1256defineIterator(Array, 'Array', function (iterated, kind) {
1257 setInternalState$3(this, {
1258 type: ARRAY_ITERATOR,
1259 target: toIndexedObject(iterated),
1260 // target
1261 index: 0,
1262 // next index
1263 kind: kind // kind
1264
1265 }); // `%ArrayIteratorPrototype%.next` method
1266 // https://tc39.es/ecma262/#sec-%arrayiteratorprototype%.next
1267}, function () {
1268 var state = getInternalState$1(this);
1269 var target = state.target;
1270 var kind = state.kind;
1271 var index = state.index++;
1272
1273 if (!target || index >= target.length) {
1274 state.target = undefined;
1275 return {
1276 value: undefined,
1277 done: true
1278 };
1279 }
1280
1281 if (kind == 'keys') return {
1282 value: index,
1283 done: false
1284 };
1285 if (kind == 'values') return {
1286 value: target[index],
1287 done: false
1288 };
1289 return {
1290 value: [index, target[index]],
1291 done: false
1292 };
1293}, 'values'); // argumentsList[@@iterator] is %ArrayProto_values%
1294// https://tc39.es/ecma262/#sec-createunmappedargumentsobject
1295// https://tc39.es/ecma262/#sec-createmappedargumentsobject
1296
1297iterators.Arguments = iterators.Array; // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
1298
1299var getIteratorMethod_1 = getIteratorMethod$3;
1300
1301// iterable DOM collections
1302// flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
1303var domIterables = {
1304 CSSRuleList: 0,
1305 CSSStyleDeclaration: 0,
1306 CSSValueList: 0,
1307 ClientRectList: 0,
1308 DOMRectList: 0,
1309 DOMStringList: 0,
1310 DOMTokenList: 1,
1311 DataTransferItemList: 0,
1312 FileList: 0,
1313 HTMLAllCollection: 0,
1314 HTMLCollection: 0,
1315 HTMLFormElement: 0,
1316 HTMLSelectElement: 0,
1317 MediaList: 0,
1318 MimeTypeArray: 0,
1319 NamedNodeMap: 0,
1320 NodeList: 1,
1321 PaintRequestList: 0,
1322 Plugin: 0,
1323 PluginArray: 0,
1324 SVGLengthList: 0,
1325 SVGNumberList: 0,
1326 SVGPathSegList: 0,
1327 SVGPointList: 0,
1328 SVGStringList: 0,
1329 SVGTransformList: 0,
1330 SourceBufferList: 0,
1331 StyleSheetList: 0,
1332 TextTrackCueList: 0,
1333 TextTrackList: 0,
1334 TouchList: 0
1335};
1336
1337var TO_STRING_TAG = wellKnownSymbol('toStringTag');
1338
1339for (var COLLECTION_NAME in domIterables) {
1340 var Collection = global_1[COLLECTION_NAME];
1341 var CollectionPrototype = Collection && Collection.prototype;
1342
1343 if (CollectionPrototype && classof(CollectionPrototype) !== TO_STRING_TAG) {
1344 createNonEnumerableProperty(CollectionPrototype, TO_STRING_TAG, COLLECTION_NAME);
1345 }
1346
1347 iterators[COLLECTION_NAME] = iterators.Array;
1348}
1349
1350var getIteratorMethod$2 = getIteratorMethod_1;
1351
1352var getIteratorMethod$1 = getIteratorMethod$2;
1353
1354var getIteratorMethod = getIteratorMethod$1;
1355
1356// https://tc39.es/ecma262/#sec-isarray
1357// eslint-disable-next-line es/no-array-isarray -- safe
1358
1359var isArray$5 = Array.isArray || function isArray(arg) {
1360 return classofRaw(arg) == 'Array';
1361};
1362
1363var hiddenKeys = enumBugKeys.concat('length', 'prototype'); // `Object.getOwnPropertyNames` method
1364// https://tc39.es/ecma262/#sec-object.getownpropertynames
1365// eslint-disable-next-line es/no-object-getownpropertynames -- safe
1366
1367var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
1368 return objectKeysInternal(O, hiddenKeys);
1369};
1370
1371var objectGetOwnPropertyNames = {
1372 f: f$3
1373};
1374
1375/* eslint-disable es/no-object-getownpropertynames -- safe */
1376
1377var $getOwnPropertyNames$1 = objectGetOwnPropertyNames.f;
1378var toString = {}.toString;
1379var windowNames = typeof window == 'object' && window && Object.getOwnPropertyNames ? Object.getOwnPropertyNames(window) : [];
1380
1381var getWindowNames = function (it) {
1382 try {
1383 return $getOwnPropertyNames$1(it);
1384 } catch (error) {
1385 return windowNames.slice();
1386 }
1387}; // fallback for IE11 buggy Object.getOwnPropertyNames with iframe and window
1388
1389
1390var f$2 = function getOwnPropertyNames(it) {
1391 return windowNames && toString.call(it) == '[object Window]' ? getWindowNames(it) : $getOwnPropertyNames$1(toIndexedObject(it));
1392};
1393
1394var objectGetOwnPropertyNamesExternal = {
1395 f: f$2
1396};
1397
1398// eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
1399var f$1 = Object.getOwnPropertySymbols;
1400var objectGetOwnPropertySymbols = {
1401 f: f$1
1402};
1403
1404var f = wellKnownSymbol;
1405var wellKnownSymbolWrapped = {
1406 f: f
1407};
1408
1409var defineProperty$8 = objectDefineProperty.f;
1410
1411var defineWellKnownSymbol = function (NAME) {
1412 var Symbol = path.Symbol || (path.Symbol = {});
1413 if (!has$1(Symbol, NAME)) defineProperty$8(Symbol, NAME, {
1414 value: wellKnownSymbolWrapped.f(NAME)
1415 });
1416};
1417
1418var SPECIES$3 = wellKnownSymbol('species'); // a part of `ArraySpeciesCreate` abstract operation
1419// https://tc39.es/ecma262/#sec-arrayspeciescreate
1420
1421var arraySpeciesConstructor = function (originalArray) {
1422 var C;
1423
1424 if (isArray$5(originalArray)) {
1425 C = originalArray.constructor; // cross-realm fallback
1426
1427 if (typeof C == 'function' && (C === Array || isArray$5(C.prototype))) C = undefined;else if (isObject$1(C)) {
1428 C = C[SPECIES$3];
1429 if (C === null) C = undefined;
1430 }
1431 }
1432
1433 return C === undefined ? Array : C;
1434};
1435
1436// https://tc39.es/ecma262/#sec-arrayspeciescreate
1437
1438var arraySpeciesCreate = function (originalArray, length) {
1439 return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
1440};
1441
1442var push = [].push; // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex, filterReject }` methods implementation
1443
1444var createMethod$3 = function (TYPE) {
1445 var IS_MAP = TYPE == 1;
1446 var IS_FILTER = TYPE == 2;
1447 var IS_SOME = TYPE == 3;
1448 var IS_EVERY = TYPE == 4;
1449 var IS_FIND_INDEX = TYPE == 6;
1450 var IS_FILTER_REJECT = TYPE == 7;
1451 var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
1452 return function ($this, callbackfn, that, specificCreate) {
1453 var O = toObject($this);
1454 var self = indexedObject(O);
1455 var boundFunction = functionBindContext(callbackfn, that, 3);
1456 var length = toLength(self.length);
1457 var index = 0;
1458 var create = specificCreate || arraySpeciesCreate;
1459 var target = IS_MAP ? create($this, length) : IS_FILTER || IS_FILTER_REJECT ? create($this, 0) : undefined;
1460 var value, result;
1461
1462 for (; length > index; index++) if (NO_HOLES || index in self) {
1463 value = self[index];
1464 result = boundFunction(value, index, O);
1465
1466 if (TYPE) {
1467 if (IS_MAP) target[index] = result; // map
1468 else if (result) switch (TYPE) {
1469 case 3:
1470 return true;
1471 // some
1472
1473 case 5:
1474 return value;
1475 // find
1476
1477 case 6:
1478 return index;
1479 // findIndex
1480
1481 case 2:
1482 push.call(target, value);
1483 // filter
1484 } else switch (TYPE) {
1485 case 4:
1486 return false;
1487 // every
1488
1489 case 7:
1490 push.call(target, value);
1491 // filterReject
1492 }
1493 }
1494 }
1495
1496 return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
1497 };
1498};
1499
1500var arrayIteration = {
1501 // `Array.prototype.forEach` method
1502 // https://tc39.es/ecma262/#sec-array.prototype.foreach
1503 forEach: createMethod$3(0),
1504 // `Array.prototype.map` method
1505 // https://tc39.es/ecma262/#sec-array.prototype.map
1506 map: createMethod$3(1),
1507 // `Array.prototype.filter` method
1508 // https://tc39.es/ecma262/#sec-array.prototype.filter
1509 filter: createMethod$3(2),
1510 // `Array.prototype.some` method
1511 // https://tc39.es/ecma262/#sec-array.prototype.some
1512 some: createMethod$3(3),
1513 // `Array.prototype.every` method
1514 // https://tc39.es/ecma262/#sec-array.prototype.every
1515 every: createMethod$3(4),
1516 // `Array.prototype.find` method
1517 // https://tc39.es/ecma262/#sec-array.prototype.find
1518 find: createMethod$3(5),
1519 // `Array.prototype.findIndex` method
1520 // https://tc39.es/ecma262/#sec-array.prototype.findIndex
1521 findIndex: createMethod$3(6),
1522 // `Array.prototype.filterReject` method
1523 // https://github.com/tc39/proposal-array-filtering
1524 filterReject: createMethod$3(7)
1525};
1526
1527var $forEach$1 = arrayIteration.forEach;
1528var HIDDEN = sharedKey('hidden');
1529var SYMBOL = 'Symbol';
1530var PROTOTYPE = 'prototype';
1531var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
1532var setInternalState$2 = internalState.set;
1533var getInternalState = internalState.getterFor(SYMBOL);
1534var ObjectPrototype = Object[PROTOTYPE];
1535var $Symbol = global_1.Symbol;
1536var $stringify$1 = getBuiltIn('JSON', 'stringify');
1537var nativeGetOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f;
1538var nativeDefineProperty = objectDefineProperty.f;
1539var nativeGetOwnPropertyNames = objectGetOwnPropertyNamesExternal.f;
1540var nativePropertyIsEnumerable = objectPropertyIsEnumerable.f;
1541var AllSymbols = shared('symbols');
1542var ObjectPrototypeSymbols = shared('op-symbols');
1543var StringToSymbolRegistry = shared('string-to-symbol-registry');
1544var SymbolToStringRegistry = shared('symbol-to-string-registry');
1545var WellKnownSymbolsStore = shared('wks');
1546var QObject = global_1.QObject; // Don't use setters in Qt Script, https://github.com/zloirock/core-js/issues/173
1547
1548var USE_SETTER = !QObject || !QObject[PROTOTYPE] || !QObject[PROTOTYPE].findChild; // fallback for old Android, https://code.google.com/p/v8/issues/detail?id=687
1549
1550var setSymbolDescriptor = descriptors && fails(function () {
1551 return objectCreate(nativeDefineProperty({}, 'a', {
1552 get: function () {
1553 return nativeDefineProperty(this, 'a', {
1554 value: 7
1555 }).a;
1556 }
1557 })).a != 7;
1558}) ? function (O, P, Attributes) {
1559 var ObjectPrototypeDescriptor = nativeGetOwnPropertyDescriptor$1(ObjectPrototype, P);
1560 if (ObjectPrototypeDescriptor) delete ObjectPrototype[P];
1561 nativeDefineProperty(O, P, Attributes);
1562
1563 if (ObjectPrototypeDescriptor && O !== ObjectPrototype) {
1564 nativeDefineProperty(ObjectPrototype, P, ObjectPrototypeDescriptor);
1565 }
1566} : nativeDefineProperty;
1567
1568var wrap$1 = function (tag, description) {
1569 var symbol = AllSymbols[tag] = objectCreate($Symbol[PROTOTYPE]);
1570 setInternalState$2(symbol, {
1571 type: SYMBOL,
1572 tag: tag,
1573 description: description
1574 });
1575 if (!descriptors) symbol.description = description;
1576 return symbol;
1577};
1578
1579var $defineProperty = function defineProperty(O, P, Attributes) {
1580 if (O === ObjectPrototype) $defineProperty(ObjectPrototypeSymbols, P, Attributes);
1581 anObject(O);
1582 var key = toPropertyKey(P);
1583 anObject(Attributes);
1584
1585 if (has$1(AllSymbols, key)) {
1586 if (!Attributes.enumerable) {
1587 if (!has$1(O, HIDDEN)) nativeDefineProperty(O, HIDDEN, createPropertyDescriptor(1, {}));
1588 O[HIDDEN][key] = true;
1589 } else {
1590 if (has$1(O, HIDDEN) && O[HIDDEN][key]) O[HIDDEN][key] = false;
1591 Attributes = objectCreate(Attributes, {
1592 enumerable: createPropertyDescriptor(0, false)
1593 });
1594 }
1595
1596 return setSymbolDescriptor(O, key, Attributes);
1597 }
1598
1599 return nativeDefineProperty(O, key, Attributes);
1600};
1601
1602var $defineProperties = function defineProperties(O, Properties) {
1603 anObject(O);
1604 var properties = toIndexedObject(Properties);
1605 var keys = objectKeys(properties).concat($getOwnPropertySymbols(properties));
1606 $forEach$1(keys, function (key) {
1607 if (!descriptors || $propertyIsEnumerable.call(properties, key)) $defineProperty(O, key, properties[key]);
1608 });
1609 return O;
1610};
1611
1612var $create = function create(O, Properties) {
1613 return Properties === undefined ? objectCreate(O) : $defineProperties(objectCreate(O), Properties);
1614};
1615
1616var $propertyIsEnumerable = function propertyIsEnumerable(V) {
1617 var P = toPropertyKey(V);
1618 var enumerable = nativePropertyIsEnumerable.call(this, P);
1619 if (this === ObjectPrototype && has$1(AllSymbols, P) && !has$1(ObjectPrototypeSymbols, P)) return false;
1620 return enumerable || !has$1(this, P) || !has$1(AllSymbols, P) || has$1(this, HIDDEN) && this[HIDDEN][P] ? enumerable : true;
1621};
1622
1623var $getOwnPropertyDescriptor = function getOwnPropertyDescriptor(O, P) {
1624 var it = toIndexedObject(O);
1625 var key = toPropertyKey(P);
1626 if (it === ObjectPrototype && has$1(AllSymbols, key) && !has$1(ObjectPrototypeSymbols, key)) return;
1627 var descriptor = nativeGetOwnPropertyDescriptor$1(it, key);
1628
1629 if (descriptor && has$1(AllSymbols, key) && !(has$1(it, HIDDEN) && it[HIDDEN][key])) {
1630 descriptor.enumerable = true;
1631 }
1632
1633 return descriptor;
1634};
1635
1636var $getOwnPropertyNames = function getOwnPropertyNames(O) {
1637 var names = nativeGetOwnPropertyNames(toIndexedObject(O));
1638 var result = [];
1639 $forEach$1(names, function (key) {
1640 if (!has$1(AllSymbols, key) && !has$1(hiddenKeys$1, key)) result.push(key);
1641 });
1642 return result;
1643};
1644
1645var $getOwnPropertySymbols = function getOwnPropertySymbols(O) {
1646 var IS_OBJECT_PROTOTYPE = O === ObjectPrototype;
1647 var names = nativeGetOwnPropertyNames(IS_OBJECT_PROTOTYPE ? ObjectPrototypeSymbols : toIndexedObject(O));
1648 var result = [];
1649 $forEach$1(names, function (key) {
1650 if (has$1(AllSymbols, key) && (!IS_OBJECT_PROTOTYPE || has$1(ObjectPrototype, key))) {
1651 result.push(AllSymbols[key]);
1652 }
1653 });
1654 return result;
1655}; // `Symbol` constructor
1656// https://tc39.es/ecma262/#sec-symbol-constructor
1657
1658
1659if (!nativeSymbol) {
1660 $Symbol = function Symbol() {
1661 if (this instanceof $Symbol) throw TypeError('Symbol is not a constructor');
1662 var description = !arguments.length || arguments[0] === undefined ? undefined : toString_1(arguments[0]);
1663 var tag = uid(description);
1664
1665 var setter = function (value) {
1666 if (this === ObjectPrototype) setter.call(ObjectPrototypeSymbols, value);
1667 if (has$1(this, HIDDEN) && has$1(this[HIDDEN], tag)) this[HIDDEN][tag] = false;
1668 setSymbolDescriptor(this, tag, createPropertyDescriptor(1, value));
1669 };
1670
1671 if (descriptors && USE_SETTER) setSymbolDescriptor(ObjectPrototype, tag, {
1672 configurable: true,
1673 set: setter
1674 });
1675 return wrap$1(tag, description);
1676 };
1677
1678 redefine($Symbol[PROTOTYPE], 'toString', function toString() {
1679 return getInternalState(this).tag;
1680 });
1681 redefine($Symbol, 'withoutSetter', function (description) {
1682 return wrap$1(uid(description), description);
1683 });
1684 objectPropertyIsEnumerable.f = $propertyIsEnumerable;
1685 objectDefineProperty.f = $defineProperty;
1686 objectGetOwnPropertyDescriptor.f = $getOwnPropertyDescriptor;
1687 objectGetOwnPropertyNames.f = objectGetOwnPropertyNamesExternal.f = $getOwnPropertyNames;
1688 objectGetOwnPropertySymbols.f = $getOwnPropertySymbols;
1689
1690 wellKnownSymbolWrapped.f = function (name) {
1691 return wrap$1(wellKnownSymbol(name), name);
1692 };
1693
1694 if (descriptors) {
1695 // https://github.com/tc39/proposal-Symbol-description
1696 nativeDefineProperty($Symbol[PROTOTYPE], 'description', {
1697 configurable: true,
1698 get: function description() {
1699 return getInternalState(this).description;
1700 }
1701 });
1702 }
1703}
1704
1705_export({
1706 global: true,
1707 wrap: true,
1708 forced: !nativeSymbol,
1709 sham: !nativeSymbol
1710}, {
1711 Symbol: $Symbol
1712});
1713$forEach$1(objectKeys(WellKnownSymbolsStore), function (name) {
1714 defineWellKnownSymbol(name);
1715});
1716_export({
1717 target: SYMBOL,
1718 stat: true,
1719 forced: !nativeSymbol
1720}, {
1721 // `Symbol.for` method
1722 // https://tc39.es/ecma262/#sec-symbol.for
1723 'for': function (key) {
1724 var string = toString_1(key);
1725 if (has$1(StringToSymbolRegistry, string)) return StringToSymbolRegistry[string];
1726 var symbol = $Symbol(string);
1727 StringToSymbolRegistry[string] = symbol;
1728 SymbolToStringRegistry[symbol] = string;
1729 return symbol;
1730 },
1731 // `Symbol.keyFor` method
1732 // https://tc39.es/ecma262/#sec-symbol.keyfor
1733 keyFor: function keyFor(sym) {
1734 if (!isSymbol(sym)) throw TypeError(sym + ' is not a symbol');
1735 if (has$1(SymbolToStringRegistry, sym)) return SymbolToStringRegistry[sym];
1736 },
1737 useSetter: function () {
1738 USE_SETTER = true;
1739 },
1740 useSimple: function () {
1741 USE_SETTER = false;
1742 }
1743});
1744_export({
1745 target: 'Object',
1746 stat: true,
1747 forced: !nativeSymbol,
1748 sham: !descriptors
1749}, {
1750 // `Object.create` method
1751 // https://tc39.es/ecma262/#sec-object.create
1752 create: $create,
1753 // `Object.defineProperty` method
1754 // https://tc39.es/ecma262/#sec-object.defineproperty
1755 defineProperty: $defineProperty,
1756 // `Object.defineProperties` method
1757 // https://tc39.es/ecma262/#sec-object.defineproperties
1758 defineProperties: $defineProperties,
1759 // `Object.getOwnPropertyDescriptor` method
1760 // https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
1761 getOwnPropertyDescriptor: $getOwnPropertyDescriptor
1762});
1763_export({
1764 target: 'Object',
1765 stat: true,
1766 forced: !nativeSymbol
1767}, {
1768 // `Object.getOwnPropertyNames` method
1769 // https://tc39.es/ecma262/#sec-object.getownpropertynames
1770 getOwnPropertyNames: $getOwnPropertyNames,
1771 // `Object.getOwnPropertySymbols` method
1772 // https://tc39.es/ecma262/#sec-object.getownpropertysymbols
1773 getOwnPropertySymbols: $getOwnPropertySymbols
1774}); // Chrome 38 and 39 `Object.getOwnPropertySymbols` fails on primitives
1775// https://bugs.chromium.org/p/v8/issues/detail?id=3443
1776
1777_export({
1778 target: 'Object',
1779 stat: true,
1780 forced: fails(function () {
1781 objectGetOwnPropertySymbols.f(1);
1782 })
1783}, {
1784 getOwnPropertySymbols: function getOwnPropertySymbols(it) {
1785 return objectGetOwnPropertySymbols.f(toObject(it));
1786 }
1787}); // `JSON.stringify` method behavior with symbols
1788// https://tc39.es/ecma262/#sec-json.stringify
1789
1790if ($stringify$1) {
1791 var FORCED_JSON_STRINGIFY = !nativeSymbol || fails(function () {
1792 var symbol = $Symbol(); // MS Edge converts symbol values to JSON as {}
1793
1794 return $stringify$1([symbol]) != '[null]' // WebKit converts symbol values to JSON as null
1795 || $stringify$1({
1796 a: symbol
1797 }) != '{}' // V8 throws on boxed symbols
1798 || $stringify$1(Object(symbol)) != '{}';
1799 });
1800 _export({
1801 target: 'JSON',
1802 stat: true,
1803 forced: FORCED_JSON_STRINGIFY
1804 }, {
1805 // eslint-disable-next-line no-unused-vars -- required for `.length`
1806 stringify: function stringify(it, replacer, space) {
1807 var args = [it];
1808 var index = 1;
1809 var $replacer;
1810
1811 while (arguments.length > index) args.push(arguments[index++]);
1812
1813 $replacer = replacer;
1814 if (!isObject$1(replacer) && it === undefined || isSymbol(it)) return; // IE8 returns string on undefined
1815
1816 if (!isArray$5(replacer)) replacer = function (key, value) {
1817 if (typeof $replacer == 'function') value = $replacer.call(this, key, value);
1818 if (!isSymbol(value)) return value;
1819 };
1820 args[1] = replacer;
1821 return $stringify$1.apply(null, args);
1822 }
1823 });
1824} // `Symbol.prototype[@@toPrimitive]` method
1825// https://tc39.es/ecma262/#sec-symbol.prototype-@@toprimitive
1826
1827
1828if (!$Symbol[PROTOTYPE][TO_PRIMITIVE]) {
1829 createNonEnumerableProperty($Symbol[PROTOTYPE], TO_PRIMITIVE, $Symbol[PROTOTYPE].valueOf);
1830} // `Symbol.prototype[@@toStringTag]` property
1831// https://tc39.es/ecma262/#sec-symbol.prototype-@@tostringtag
1832
1833
1834setToStringTag($Symbol, SYMBOL);
1835hiddenKeys$1[HIDDEN] = true;
1836
1837var getOwnPropertySymbols$2 = path.Object.getOwnPropertySymbols;
1838
1839var getOwnPropertySymbols$1 = getOwnPropertySymbols$2;
1840
1841var getOwnPropertySymbols = getOwnPropertySymbols$1;
1842
1843var nativeGetOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
1844var FAILS_ON_PRIMITIVES$2 = fails(function () {
1845 nativeGetOwnPropertyDescriptor(1);
1846});
1847var FORCED$6 = !descriptors || FAILS_ON_PRIMITIVES$2; // `Object.getOwnPropertyDescriptor` method
1848// https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
1849
1850_export({
1851 target: 'Object',
1852 stat: true,
1853 forced: FORCED$6,
1854 sham: !descriptors
1855}, {
1856 getOwnPropertyDescriptor: function getOwnPropertyDescriptor(it, key) {
1857 return nativeGetOwnPropertyDescriptor(toIndexedObject(it), key);
1858 }
1859});
1860
1861var getOwnPropertyDescriptor_1 = createCommonjsModule(function (module) {
1862 var Object = path.Object;
1863
1864 var getOwnPropertyDescriptor = module.exports = function getOwnPropertyDescriptor(it, key) {
1865 return Object.getOwnPropertyDescriptor(it, key);
1866 };
1867
1868 if (Object.getOwnPropertyDescriptor.sham) getOwnPropertyDescriptor.sham = true;
1869});
1870
1871var getOwnPropertyDescriptor$1 = getOwnPropertyDescriptor_1;
1872
1873var getOwnPropertyDescriptor = getOwnPropertyDescriptor$1;
1874
1875var ownKeys$5 = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
1876 var keys = objectGetOwnPropertyNames.f(anObject(it));
1877 var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
1878 return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
1879};
1880
1881// https://tc39.es/ecma262/#sec-object.getownpropertydescriptors
1882
1883_export({
1884 target: 'Object',
1885 stat: true,
1886 sham: !descriptors
1887}, {
1888 getOwnPropertyDescriptors: function getOwnPropertyDescriptors(object) {
1889 var O = toIndexedObject(object);
1890 var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
1891 var keys = ownKeys$5(O);
1892 var result = {};
1893 var index = 0;
1894 var key, descriptor;
1895
1896 while (keys.length > index) {
1897 descriptor = getOwnPropertyDescriptor(O, key = keys[index++]);
1898 if (descriptor !== undefined) createProperty(result, key, descriptor);
1899 }
1900
1901 return result;
1902 }
1903});
1904
1905var getOwnPropertyDescriptors$2 = path.Object.getOwnPropertyDescriptors;
1906
1907var getOwnPropertyDescriptors$1 = getOwnPropertyDescriptors$2;
1908
1909var getOwnPropertyDescriptors = getOwnPropertyDescriptors$1;
1910
1911// https://tc39.es/ecma262/#sec-object.defineproperties
1912
1913_export({
1914 target: 'Object',
1915 stat: true,
1916 forced: !descriptors,
1917 sham: !descriptors
1918}, {
1919 defineProperties: objectDefineProperties
1920});
1921
1922var defineProperties_1 = createCommonjsModule(function (module) {
1923 var Object = path.Object;
1924
1925 var defineProperties = module.exports = function defineProperties(T, D) {
1926 return Object.defineProperties(T, D);
1927 };
1928
1929 if (Object.defineProperties.sham) defineProperties.sham = true;
1930});
1931
1932var defineProperties$1 = defineProperties_1;
1933
1934var defineProperties = defineProperties$1;
1935
1936// https://tc39.es/ecma262/#sec-object.defineproperty
1937
1938_export({
1939 target: 'Object',
1940 stat: true,
1941 forced: !descriptors,
1942 sham: !descriptors
1943}, {
1944 defineProperty: objectDefineProperty.f
1945});
1946
1947var defineProperty_1 = createCommonjsModule(function (module) {
1948 var Object = path.Object;
1949
1950 var defineProperty = module.exports = function defineProperty(it, key, desc) {
1951 return Object.defineProperty(it, key, desc);
1952 };
1953
1954 if (Object.defineProperty.sham) defineProperty.sham = true;
1955});
1956
1957var defineProperty$7 = defineProperty_1;
1958
1959var defineProperty$6 = defineProperty$7;
1960
1961var classCallCheck = createCommonjsModule(function (module) {
1962 function _classCallCheck(instance, Constructor) {
1963 if (!(instance instanceof Constructor)) {
1964 throw new TypeError("Cannot call a class as a function");
1965 }
1966 }
1967
1968 module.exports = _classCallCheck;
1969 module.exports["default"] = module.exports, module.exports.__esModule = true;
1970});
1971var _classCallCheck = unwrapExports(classCallCheck);
1972
1973var defineProperty$5 = defineProperty$7;
1974
1975var defineProperty$4 = defineProperty$5;
1976
1977var createClass = createCommonjsModule(function (module) {
1978 function _defineProperties(target, props) {
1979 for (var i = 0; i < props.length; i++) {
1980 var descriptor = props[i];
1981 descriptor.enumerable = descriptor.enumerable || false;
1982 descriptor.configurable = true;
1983 if ("value" in descriptor) descriptor.writable = true;
1984
1985 defineProperty$4(target, descriptor.key, descriptor);
1986 }
1987 }
1988
1989 function _createClass(Constructor, protoProps, staticProps) {
1990 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1991 if (staticProps) _defineProperties(Constructor, staticProps);
1992 return Constructor;
1993 }
1994
1995 module.exports = _createClass;
1996 module.exports["default"] = module.exports, module.exports.__esModule = true;
1997});
1998var _createClass = unwrapExports(createClass);
1999
2000var defineProperty$3 = createCommonjsModule(function (module) {
2001 function _defineProperty(obj, key, value) {
2002 if (key in obj) {
2003 defineProperty$4(obj, key, {
2004 value: value,
2005 enumerable: true,
2006 configurable: true,
2007 writable: true
2008 });
2009 } else {
2010 obj[key] = value;
2011 }
2012
2013 return obj;
2014 }
2015
2016 module.exports = _defineProperty;
2017 module.exports["default"] = module.exports, module.exports.__esModule = true;
2018});
2019var _defineProperty = unwrapExports(defineProperty$3);
2020
2021// https://tc39.es/ecma262/#sec-array.isarray
2022
2023_export({
2024 target: 'Array',
2025 stat: true
2026}, {
2027 isArray: isArray$5
2028});
2029
2030var isArray$4 = path.Array.isArray;
2031
2032var isArray$3 = isArray$4;
2033
2034var isArray$2 = isArray$3;
2035
2036var isArray$1 = isArray$2;
2037
2038var arrayWithHoles = createCommonjsModule(function (module) {
2039 function _arrayWithHoles(arr) {
2040 if (isArray$1(arr)) return arr;
2041 }
2042
2043 module.exports = _arrayWithHoles;
2044 module.exports["default"] = module.exports, module.exports.__esModule = true;
2045});
2046unwrapExports(arrayWithHoles);
2047
2048var SPECIES$2 = wellKnownSymbol('species');
2049
2050var arrayMethodHasSpeciesSupport = function (METHOD_NAME) {
2051 // We can't use this feature detection in V8 since it causes
2052 // deoptimization and serious performance degradation
2053 // https://github.com/zloirock/core-js/issues/677
2054 return engineV8Version >= 51 || !fails(function () {
2055 var array = [];
2056 var constructor = array.constructor = {};
2057
2058 constructor[SPECIES$2] = function () {
2059 return {
2060 foo: 1
2061 };
2062 };
2063
2064 return array[METHOD_NAME](Boolean).foo !== 1;
2065 });
2066};
2067
2068var IS_CONCAT_SPREADABLE = wellKnownSymbol('isConcatSpreadable');
2069var MAX_SAFE_INTEGER$1 = 0x1FFFFFFFFFFFFF;
2070var MAXIMUM_ALLOWED_INDEX_EXCEEDED = 'Maximum allowed index exceeded'; // We can't use this feature detection in V8 since it causes
2071// deoptimization and serious performance degradation
2072// https://github.com/zloirock/core-js/issues/679
2073
2074var IS_CONCAT_SPREADABLE_SUPPORT = engineV8Version >= 51 || !fails(function () {
2075 var array = [];
2076 array[IS_CONCAT_SPREADABLE] = false;
2077 return array.concat()[0] !== array;
2078});
2079var SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('concat');
2080
2081var isConcatSpreadable = function (O) {
2082 if (!isObject$1(O)) return false;
2083 var spreadable = O[IS_CONCAT_SPREADABLE];
2084 return spreadable !== undefined ? !!spreadable : isArray$5(O);
2085};
2086
2087var FORCED$5 = !IS_CONCAT_SPREADABLE_SUPPORT || !SPECIES_SUPPORT; // `Array.prototype.concat` method
2088// https://tc39.es/ecma262/#sec-array.prototype.concat
2089// with adding support of @@isConcatSpreadable and @@species
2090
2091_export({
2092 target: 'Array',
2093 proto: true,
2094 forced: FORCED$5
2095}, {
2096 // eslint-disable-next-line no-unused-vars -- required for `.length`
2097 concat: function concat(arg) {
2098 var O = toObject(this);
2099 var A = arraySpeciesCreate(O, 0);
2100 var n = 0;
2101 var i, k, length, len, E;
2102
2103 for (i = -1, length = arguments.length; i < length; i++) {
2104 E = i === -1 ? O : arguments[i];
2105
2106 if (isConcatSpreadable(E)) {
2107 len = toLength(E.length);
2108 if (n + len > MAX_SAFE_INTEGER$1) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
2109
2110 for (k = 0; k < len; k++, n++) if (k in E) createProperty(A, n, E[k]);
2111 } else {
2112 if (n >= MAX_SAFE_INTEGER$1) throw TypeError(MAXIMUM_ALLOWED_INDEX_EXCEEDED);
2113 createProperty(A, n++, E);
2114 }
2115 }
2116
2117 A.length = n;
2118 return A;
2119 }
2120});
2121
2122// https://tc39.es/ecma262/#sec-symbol.asynciterator
2123
2124defineWellKnownSymbol('asyncIterator');
2125
2126// https://tc39.es/ecma262/#sec-symbol.hasinstance
2127
2128defineWellKnownSymbol('hasInstance');
2129
2130// https://tc39.es/ecma262/#sec-symbol.isconcatspreadable
2131
2132defineWellKnownSymbol('isConcatSpreadable');
2133
2134// https://tc39.es/ecma262/#sec-symbol.iterator
2135
2136defineWellKnownSymbol('iterator');
2137
2138// https://tc39.es/ecma262/#sec-symbol.match
2139
2140defineWellKnownSymbol('match');
2141
2142// https://tc39.es/ecma262/#sec-symbol.matchall
2143
2144defineWellKnownSymbol('matchAll');
2145
2146// https://tc39.es/ecma262/#sec-symbol.replace
2147
2148defineWellKnownSymbol('replace');
2149
2150// https://tc39.es/ecma262/#sec-symbol.search
2151
2152defineWellKnownSymbol('search');
2153
2154// https://tc39.es/ecma262/#sec-symbol.species
2155
2156defineWellKnownSymbol('species');
2157
2158// https://tc39.es/ecma262/#sec-symbol.split
2159
2160defineWellKnownSymbol('split');
2161
2162// https://tc39.es/ecma262/#sec-symbol.toprimitive
2163
2164defineWellKnownSymbol('toPrimitive');
2165
2166// https://tc39.es/ecma262/#sec-symbol.tostringtag
2167
2168defineWellKnownSymbol('toStringTag');
2169
2170// https://tc39.es/ecma262/#sec-symbol.unscopables
2171
2172defineWellKnownSymbol('unscopables');
2173
2174// https://tc39.es/ecma262/#sec-json-@@tostringtag
2175
2176setToStringTag(global_1.JSON, 'JSON', true);
2177
2178var symbol$4 = path.Symbol;
2179
2180var symbol$3 = symbol$4;
2181
2182// https://github.com/tc39/proposal-using-statement
2183
2184defineWellKnownSymbol('asyncDispose');
2185
2186// https://github.com/tc39/proposal-using-statement
2187
2188defineWellKnownSymbol('dispose');
2189
2190// https://github.com/tc39/proposal-pattern-matching
2191
2192defineWellKnownSymbol('matcher');
2193
2194// https://github.com/tc39/proposal-decorators
2195
2196defineWellKnownSymbol('metadata');
2197
2198// https://github.com/tc39/proposal-observable
2199
2200defineWellKnownSymbol('observable');
2201
2202// `Symbol.patternMatch` well-known symbol
2203// https://github.com/tc39/proposal-pattern-matching
2204
2205defineWellKnownSymbol('patternMatch');
2206
2207defineWellKnownSymbol('replaceAll');
2208
2209// TODO: Remove from `core-js@4`
2210
2211var symbol$2 = symbol$3;
2212
2213var symbol$1 = symbol$2;
2214
2215var iterableToArrayLimit = createCommonjsModule(function (module) {
2216 function _iterableToArrayLimit(arr, i) {
2217 var _i = arr == null ? null : typeof symbol$1 !== "undefined" && getIteratorMethod(arr) || arr["@@iterator"];
2218
2219 if (_i == null) return;
2220 var _arr = [];
2221 var _n = true;
2222 var _d = false;
2223
2224 var _s, _e;
2225
2226 try {
2227 for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
2228 _arr.push(_s.value);
2229
2230 if (i && _arr.length === i) break;
2231 }
2232 } catch (err) {
2233 _d = true;
2234 _e = err;
2235 } finally {
2236 try {
2237 if (!_n && _i["return"] != null) _i["return"]();
2238 } finally {
2239 if (_d) throw _e;
2240 }
2241 }
2242
2243 return _arr;
2244 }
2245
2246 module.exports = _iterableToArrayLimit;
2247 module.exports["default"] = module.exports, module.exports.__esModule = true;
2248});
2249unwrapExports(iterableToArrayLimit);
2250
2251var HAS_SPECIES_SUPPORT$3 = arrayMethodHasSpeciesSupport('slice');
2252var SPECIES$1 = wellKnownSymbol('species');
2253var nativeSlice = [].slice;
2254var max$1 = Math.max; // `Array.prototype.slice` method
2255// https://tc39.es/ecma262/#sec-array.prototype.slice
2256// fallback for not array-like ES3 strings and DOM objects
2257
2258_export({
2259 target: 'Array',
2260 proto: true,
2261 forced: !HAS_SPECIES_SUPPORT$3
2262}, {
2263 slice: function slice(start, end) {
2264 var O = toIndexedObject(this);
2265 var length = toLength(O.length);
2266 var k = toAbsoluteIndex(start, length);
2267 var fin = toAbsoluteIndex(end === undefined ? length : end, length); // inline `ArraySpeciesCreate` for usage native `Array#slice` where it's possible
2268
2269 var Constructor, result, n;
2270
2271 if (isArray$5(O)) {
2272 Constructor = O.constructor; // cross-realm fallback
2273
2274 if (typeof Constructor == 'function' && (Constructor === Array || isArray$5(Constructor.prototype))) {
2275 Constructor = undefined;
2276 } else if (isObject$1(Constructor)) {
2277 Constructor = Constructor[SPECIES$1];
2278 if (Constructor === null) Constructor = undefined;
2279 }
2280
2281 if (Constructor === Array || Constructor === undefined) {
2282 return nativeSlice.call(O, k, fin);
2283 }
2284 }
2285
2286 result = new (Constructor === undefined ? Array : Constructor)(max$1(fin - k, 0));
2287
2288 for (n = 0; k < fin; k++, n++) if (k in O) createProperty(result, n, O[k]);
2289
2290 result.length = n;
2291 return result;
2292 }
2293});
2294
2295var entryVirtual = function (CONSTRUCTOR) {
2296 return path[CONSTRUCTOR + 'Prototype'];
2297};
2298
2299var slice$6 = entryVirtual('Array').slice;
2300
2301var ArrayPrototype$g = Array.prototype;
2302
2303var slice_1 = function (it) {
2304 var own = it.slice;
2305 return it === ArrayPrototype$g || it instanceof Array && own === ArrayPrototype$g.slice ? slice$6 : own;
2306};
2307
2308var slice$5 = slice_1;
2309
2310var slice$4 = slice$5;
2311
2312var slice$3 = slice$4;
2313
2314var from_1$1 = from_1$3;
2315
2316var from_1 = from_1$1;
2317
2318var arrayLikeToArray = createCommonjsModule(function (module) {
2319 function _arrayLikeToArray(arr, len) {
2320 if (len == null || len > arr.length) len = arr.length;
2321
2322 for (var i = 0, arr2 = new Array(len); i < len; i++) {
2323 arr2[i] = arr[i];
2324 }
2325
2326 return arr2;
2327 }
2328
2329 module.exports = _arrayLikeToArray;
2330 module.exports["default"] = module.exports, module.exports.__esModule = true;
2331});
2332unwrapExports(arrayLikeToArray);
2333
2334var unsupportedIterableToArray = createCommonjsModule(function (module) {
2335 function _unsupportedIterableToArray(o, minLen) {
2336 var _context;
2337
2338 if (!o) return;
2339 if (typeof o === "string") return arrayLikeToArray(o, minLen);
2340
2341 var n = slice$3(_context = Object.prototype.toString.call(o)).call(_context, 8, -1);
2342
2343 if (n === "Object" && o.constructor) n = o.constructor.name;
2344 if (n === "Map" || n === "Set") return from_1(o);
2345 if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
2346 }
2347
2348 module.exports = _unsupportedIterableToArray;
2349 module.exports["default"] = module.exports, module.exports.__esModule = true;
2350});
2351unwrapExports(unsupportedIterableToArray);
2352
2353var nonIterableRest = createCommonjsModule(function (module) {
2354 function _nonIterableRest() {
2355 throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2356 }
2357
2358 module.exports = _nonIterableRest;
2359 module.exports["default"] = module.exports, module.exports.__esModule = true;
2360});
2361unwrapExports(nonIterableRest);
2362
2363var slicedToArray = createCommonjsModule(function (module) {
2364 function _slicedToArray(arr, i) {
2365 return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
2366 }
2367
2368 module.exports = _slicedToArray;
2369 module.exports["default"] = module.exports, module.exports.__esModule = true;
2370});
2371var _slicedToArray = unwrapExports(slicedToArray);
2372
2373var iterator$4 = wellKnownSymbolWrapped.f('iterator');
2374
2375var iterator$3 = iterator$4;
2376
2377var iterator$2 = iterator$3;
2378
2379var iterator$1 = iterator$2;
2380
2381var _typeof_1 = createCommonjsModule(function (module) {
2382 function _typeof(obj) {
2383 "@babel/helpers - typeof";
2384
2385 if (typeof symbol$1 === "function" && typeof iterator$1 === "symbol") {
2386 module.exports = _typeof = function _typeof(obj) {
2387 return typeof obj;
2388 };
2389
2390 module.exports["default"] = module.exports, module.exports.__esModule = true;
2391 } else {
2392 module.exports = _typeof = function _typeof(obj) {
2393 return obj && typeof symbol$1 === "function" && obj.constructor === symbol$1 && obj !== symbol$1.prototype ? "symbol" : typeof obj;
2394 };
2395
2396 module.exports["default"] = module.exports, module.exports.__esModule = true;
2397 }
2398
2399 return _typeof(obj);
2400 }
2401
2402 module.exports = _typeof;
2403 module.exports["default"] = module.exports, module.exports.__esModule = true;
2404});
2405
2406var _typeof = unwrapExports(_typeof_1);
2407
2408var arrayWithoutHoles = createCommonjsModule(function (module) {
2409 function _arrayWithoutHoles(arr) {
2410 if (isArray$1(arr)) return arrayLikeToArray(arr);
2411 }
2412
2413 module.exports = _arrayWithoutHoles;
2414 module.exports["default"] = module.exports, module.exports.__esModule = true;
2415});
2416unwrapExports(arrayWithoutHoles);
2417
2418var iterableToArray = createCommonjsModule(function (module) {
2419 function _iterableToArray(iter) {
2420 if (typeof symbol$1 !== "undefined" && getIteratorMethod(iter) != null || iter["@@iterator"] != null) return from_1(iter);
2421 }
2422
2423 module.exports = _iterableToArray;
2424 module.exports["default"] = module.exports, module.exports.__esModule = true;
2425});
2426unwrapExports(iterableToArray);
2427
2428var nonIterableSpread = createCommonjsModule(function (module) {
2429 function _nonIterableSpread() {
2430 throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
2431 }
2432
2433 module.exports = _nonIterableSpread;
2434 module.exports["default"] = module.exports, module.exports.__esModule = true;
2435});
2436unwrapExports(nonIterableSpread);
2437
2438var toConsumableArray = createCommonjsModule(function (module) {
2439 function _toConsumableArray(arr) {
2440 return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
2441 }
2442
2443 module.exports = _toConsumableArray;
2444 module.exports["default"] = module.exports, module.exports.__esModule = true;
2445});
2446var _toConsumableArray = unwrapExports(toConsumableArray);
2447
2448var symbol = symbol$3;
2449
2450var concat$2 = entryVirtual('Array').concat;
2451
2452var ArrayPrototype$f = Array.prototype;
2453
2454var concat_1 = function (it) {
2455 var own = it.concat;
2456 return it === ArrayPrototype$f || it instanceof Array && own === ArrayPrototype$f.concat ? concat$2 : own;
2457};
2458
2459var concat$1 = concat_1;
2460
2461var concat = concat$1;
2462
2463var slice$2 = slice$5;
2464
2465// https://tc39.es/ecma262/#sec-reflect.ownkeys
2466
2467_export({
2468 target: 'Reflect',
2469 stat: true
2470}, {
2471 ownKeys: ownKeys$5
2472});
2473
2474var ownKeys$4 = path.Reflect.ownKeys;
2475
2476var ownKeys$3 = ownKeys$4;
2477
2478var ownKeys$2 = ownKeys$3;
2479
2480var isArray = isArray$3;
2481
2482var $map = arrayIteration.map;
2483var HAS_SPECIES_SUPPORT$2 = arrayMethodHasSpeciesSupport('map'); // `Array.prototype.map` method
2484// https://tc39.es/ecma262/#sec-array.prototype.map
2485// with adding support of @@species
2486
2487_export({
2488 target: 'Array',
2489 proto: true,
2490 forced: !HAS_SPECIES_SUPPORT$2
2491}, {
2492 map: function map(callbackfn
2493 /* , thisArg */
2494 ) {
2495 return $map(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
2496 }
2497});
2498
2499var map$5 = entryVirtual('Array').map;
2500
2501var ArrayPrototype$e = Array.prototype;
2502
2503var map_1 = function (it) {
2504 var own = it.map;
2505 return it === ArrayPrototype$e || it instanceof Array && own === ArrayPrototype$e.map ? map$5 : own;
2506};
2507
2508var map$4 = map_1;
2509
2510var map$3 = map$4;
2511
2512var FAILS_ON_PRIMITIVES$1 = fails(function () {
2513 objectKeys(1);
2514}); // `Object.keys` method
2515// https://tc39.es/ecma262/#sec-object.keys
2516
2517_export({
2518 target: 'Object',
2519 stat: true,
2520 forced: FAILS_ON_PRIMITIVES$1
2521}, {
2522 keys: function keys(it) {
2523 return objectKeys(toObject(it));
2524 }
2525});
2526
2527var keys$5 = path.Object.keys;
2528
2529var keys$4 = keys$5;
2530
2531var keys$3 = keys$4;
2532
2533// https://tc39.es/ecma262/#sec-date.now
2534
2535_export({
2536 target: 'Date',
2537 stat: true
2538}, {
2539 now: function now() {
2540 return new Date().getTime();
2541 }
2542});
2543
2544var now$3 = path.Date.now;
2545
2546var now$2 = now$3;
2547
2548var now$1 = now$2;
2549
2550var slice$1 = [].slice;
2551var factories = {};
2552
2553var construct$3 = function (C, argsLength, args) {
2554 if (!(argsLength in factories)) {
2555 for (var list = [], i = 0; i < argsLength; i++) list[i] = 'a[' + i + ']'; // eslint-disable-next-line no-new-func -- we have no proper alternatives, IE8- only
2556
2557
2558 factories[argsLength] = Function('C,a', 'return new C(' + list.join(',') + ')');
2559 }
2560
2561 return factories[argsLength](C, args);
2562}; // `Function.prototype.bind` method implementation
2563// https://tc39.es/ecma262/#sec-function.prototype.bind
2564
2565
2566var functionBind = Function.bind || function bind(that
2567/* , ...args */
2568) {
2569 var fn = aFunction(this);
2570 var partArgs = slice$1.call(arguments, 1);
2571
2572 var boundFunction = function bound() {
2573 var args = partArgs.concat(slice$1.call(arguments));
2574 return this instanceof boundFunction ? construct$3(fn, args.length, args) : fn.apply(that, args);
2575 };
2576
2577 if (isObject$1(fn.prototype)) boundFunction.prototype = fn.prototype;
2578 return boundFunction;
2579};
2580
2581// https://tc39.es/ecma262/#sec-function.prototype.bind
2582
2583_export({
2584 target: 'Function',
2585 proto: true
2586}, {
2587 bind: functionBind
2588});
2589
2590var bind$2 = entryVirtual('Function').bind;
2591
2592var FunctionPrototype = Function.prototype;
2593
2594var bind_1 = function (it) {
2595 var own = it.bind;
2596 return it === FunctionPrototype || it instanceof Function && own === FunctionPrototype.bind ? bind$2 : own;
2597};
2598
2599var bind$1 = bind_1;
2600
2601var bind = bind$1;
2602
2603var arrayMethodIsStrict = function (METHOD_NAME, argument) {
2604 var method = [][METHOD_NAME];
2605 return !!method && fails(function () {
2606 // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
2607 method.call(null, argument || function () {
2608 throw 1;
2609 }, 1);
2610 });
2611};
2612
2613var $forEach = arrayIteration.forEach;
2614var STRICT_METHOD$4 = arrayMethodIsStrict('forEach'); // `Array.prototype.forEach` method implementation
2615// https://tc39.es/ecma262/#sec-array.prototype.foreach
2616
2617var arrayForEach = !STRICT_METHOD$4 ? function forEach(callbackfn
2618/* , thisArg */
2619) {
2620 return $forEach(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined); // eslint-disable-next-line es/no-array-prototype-foreach -- safe
2621} : [].forEach;
2622
2623// https://tc39.es/ecma262/#sec-array.prototype.foreach
2624// eslint-disable-next-line es/no-array-prototype-foreach -- safe
2625
2626
2627_export({
2628 target: 'Array',
2629 proto: true,
2630 forced: [].forEach != arrayForEach
2631}, {
2632 forEach: arrayForEach
2633});
2634
2635var forEach$4 = entryVirtual('Array').forEach;
2636
2637var forEach$3 = forEach$4;
2638
2639var ArrayPrototype$d = Array.prototype;
2640var DOMIterables$3 = {
2641 DOMTokenList: true,
2642 NodeList: true
2643};
2644
2645var forEach_1 = function (it) {
2646 var own = it.forEach;
2647 return it === ArrayPrototype$d || it instanceof Array && own === ArrayPrototype$d.forEach // eslint-disable-next-line no-prototype-builtins -- safe
2648 || DOMIterables$3.hasOwnProperty(classof(it)) ? forEach$3 : own;
2649};
2650
2651var forEach$2 = forEach_1;
2652
2653var nativeReverse = [].reverse;
2654var test$1 = [1, 2]; // `Array.prototype.reverse` method
2655// https://tc39.es/ecma262/#sec-array.prototype.reverse
2656// fix for Safari 12.0 bug
2657// https://bugs.webkit.org/show_bug.cgi?id=188794
2658
2659_export({
2660 target: 'Array',
2661 proto: true,
2662 forced: String(test$1) === String(test$1.reverse())
2663}, {
2664 reverse: function reverse() {
2665 // eslint-disable-next-line no-self-assign -- dirty hack
2666 if (isArray$5(this)) this.length = this.length;
2667 return nativeReverse.call(this);
2668 }
2669});
2670
2671var reverse$2 = entryVirtual('Array').reverse;
2672
2673var ArrayPrototype$c = Array.prototype;
2674
2675var reverse_1 = function (it) {
2676 var own = it.reverse;
2677 return it === ArrayPrototype$c || it instanceof Array && own === ArrayPrototype$c.reverse ? reverse$2 : own;
2678};
2679
2680var reverse$1 = reverse_1;
2681
2682var reverse = reverse$1;
2683
2684var HAS_SPECIES_SUPPORT$1 = arrayMethodHasSpeciesSupport('splice');
2685var max = Math.max;
2686var min = Math.min;
2687var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF;
2688var MAXIMUM_ALLOWED_LENGTH_EXCEEDED = 'Maximum allowed length exceeded'; // `Array.prototype.splice` method
2689// https://tc39.es/ecma262/#sec-array.prototype.splice
2690// with adding support of @@species
2691
2692_export({
2693 target: 'Array',
2694 proto: true,
2695 forced: !HAS_SPECIES_SUPPORT$1
2696}, {
2697 splice: function splice(start, deleteCount
2698 /* , ...items */
2699 ) {
2700 var O = toObject(this);
2701 var len = toLength(O.length);
2702 var actualStart = toAbsoluteIndex(start, len);
2703 var argumentsLength = arguments.length;
2704 var insertCount, actualDeleteCount, A, k, from, to;
2705
2706 if (argumentsLength === 0) {
2707 insertCount = actualDeleteCount = 0;
2708 } else if (argumentsLength === 1) {
2709 insertCount = 0;
2710 actualDeleteCount = len - actualStart;
2711 } else {
2712 insertCount = argumentsLength - 2;
2713 actualDeleteCount = min(max(toInteger(deleteCount), 0), len - actualStart);
2714 }
2715
2716 if (len + insertCount - actualDeleteCount > MAX_SAFE_INTEGER) {
2717 throw TypeError(MAXIMUM_ALLOWED_LENGTH_EXCEEDED);
2718 }
2719
2720 A = arraySpeciesCreate(O, actualDeleteCount);
2721
2722 for (k = 0; k < actualDeleteCount; k++) {
2723 from = actualStart + k;
2724 if (from in O) createProperty(A, k, O[from]);
2725 }
2726
2727 A.length = actualDeleteCount;
2728
2729 if (insertCount < actualDeleteCount) {
2730 for (k = actualStart; k < len - actualDeleteCount; k++) {
2731 from = k + actualDeleteCount;
2732 to = k + insertCount;
2733 if (from in O) O[to] = O[from];else delete O[to];
2734 }
2735
2736 for (k = len; k > len - actualDeleteCount + insertCount; k--) delete O[k - 1];
2737 } else if (insertCount > actualDeleteCount) {
2738 for (k = len - actualDeleteCount; k > actualStart; k--) {
2739 from = k + actualDeleteCount - 1;
2740 to = k + insertCount - 1;
2741 if (from in O) O[to] = O[from];else delete O[to];
2742 }
2743 }
2744
2745 for (k = 0; k < insertCount; k++) {
2746 O[k + actualStart] = arguments[k + 2];
2747 }
2748
2749 O.length = len - actualDeleteCount + insertCount;
2750 return A;
2751 }
2752});
2753
2754var splice$2 = entryVirtual('Array').splice;
2755
2756var ArrayPrototype$b = Array.prototype;
2757
2758var splice_1 = function (it) {
2759 var own = it.splice;
2760 return it === ArrayPrototype$b || it instanceof Array && own === ArrayPrototype$b.splice ? splice$2 : own;
2761};
2762
2763var splice$1 = splice_1;
2764
2765var splice = splice$1;
2766
2767var $assign = Object.assign; // eslint-disable-next-line es/no-object-defineproperty -- required for testing
2768
2769var defineProperty$2 = Object.defineProperty; // `Object.assign` method
2770// https://tc39.es/ecma262/#sec-object.assign
2771
2772var objectAssign = !$assign || fails(function () {
2773 // should have correct order of operations (Edge bug)
2774 if (descriptors && $assign({
2775 b: 1
2776 }, $assign(defineProperty$2({}, 'a', {
2777 enumerable: true,
2778 get: function () {
2779 defineProperty$2(this, 'b', {
2780 value: 3,
2781 enumerable: false
2782 });
2783 }
2784 }), {
2785 b: 2
2786 })).b !== 1) return true; // should work with symbols and should have deterministic property order (V8 bug)
2787
2788 var A = {};
2789 var B = {}; // eslint-disable-next-line es/no-symbol -- safe
2790
2791 var symbol = Symbol();
2792 var alphabet = 'abcdefghijklmnopqrst';
2793 A[symbol] = 7;
2794 alphabet.split('').forEach(function (chr) {
2795 B[chr] = chr;
2796 });
2797 return $assign({}, A)[symbol] != 7 || objectKeys($assign({}, B)).join('') != alphabet;
2798}) ? function assign(target, source) {
2799 // eslint-disable-line no-unused-vars -- required for `.length`
2800 var T = toObject(target);
2801 var argumentsLength = arguments.length;
2802 var index = 1;
2803 var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
2804 var propertyIsEnumerable = objectPropertyIsEnumerable.f;
2805
2806 while (argumentsLength > index) {
2807 var S = indexedObject(arguments[index++]);
2808 var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
2809 var length = keys.length;
2810 var j = 0;
2811 var key;
2812
2813 while (length > j) {
2814 key = keys[j++];
2815 if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key];
2816 }
2817 }
2818
2819 return T;
2820} : $assign;
2821
2822// https://tc39.es/ecma262/#sec-object.assign
2823// eslint-disable-next-line es/no-object-assign -- required for testing
2824
2825_export({
2826 target: 'Object',
2827 stat: true,
2828 forced: Object.assign !== objectAssign
2829}, {
2830 assign: objectAssign
2831});
2832
2833var assign$4 = path.Object.assign;
2834
2835var assign$3 = assign$4;
2836
2837var assign$2 = assign$3;
2838
2839var $includes = arrayIncludes.includes; // `Array.prototype.includes` method
2840// https://tc39.es/ecma262/#sec-array.prototype.includes
2841
2842_export({
2843 target: 'Array',
2844 proto: true
2845}, {
2846 includes: function includes(el
2847 /* , fromIndex = 0 */
2848 ) {
2849 return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
2850 }
2851}); // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
2852
2853var includes$4 = entryVirtual('Array').includes;
2854
2855var MATCH$1 = wellKnownSymbol('match'); // `IsRegExp` abstract operation
2856// https://tc39.es/ecma262/#sec-isregexp
2857
2858var isRegexp = function (it) {
2859 var isRegExp;
2860 return isObject$1(it) && ((isRegExp = it[MATCH$1]) !== undefined ? !!isRegExp : classofRaw(it) == 'RegExp');
2861};
2862
2863var notARegexp = function (it) {
2864 if (isRegexp(it)) {
2865 throw TypeError("The method doesn't accept regular expressions");
2866 }
2867
2868 return it;
2869};
2870
2871var MATCH = wellKnownSymbol('match');
2872
2873var correctIsRegexpLogic = function (METHOD_NAME) {
2874 var regexp = /./;
2875
2876 try {
2877 '/./'[METHOD_NAME](regexp);
2878 } catch (error1) {
2879 try {
2880 regexp[MATCH] = false;
2881 return '/./'[METHOD_NAME](regexp);
2882 } catch (error2) {
2883 /* empty */
2884 }
2885 }
2886
2887 return false;
2888};
2889
2890// https://tc39.es/ecma262/#sec-string.prototype.includes
2891
2892
2893_export({
2894 target: 'String',
2895 proto: true,
2896 forced: !correctIsRegexpLogic('includes')
2897}, {
2898 includes: function includes(searchString
2899 /* , position = 0 */
2900 ) {
2901 return !!~toString_1(requireObjectCoercible(this)).indexOf(toString_1(notARegexp(searchString)), arguments.length > 1 ? arguments[1] : undefined);
2902 }
2903});
2904
2905var includes$3 = entryVirtual('String').includes;
2906
2907var ArrayPrototype$a = Array.prototype;
2908var StringPrototype$1 = String.prototype;
2909
2910var includes$2 = function (it) {
2911 var own = it.includes;
2912 if (it === ArrayPrototype$a || it instanceof Array && own === ArrayPrototype$a.includes) return includes$4;
2913
2914 if (typeof it === 'string' || it === StringPrototype$1 || it instanceof String && own === StringPrototype$1.includes) {
2915 return includes$3;
2916 }
2917
2918 return own;
2919};
2920
2921var includes$1 = includes$2;
2922
2923var includes = includes$1;
2924
2925var FAILS_ON_PRIMITIVES = fails(function () {
2926 objectGetPrototypeOf(1);
2927}); // `Object.getPrototypeOf` method
2928// https://tc39.es/ecma262/#sec-object.getprototypeof
2929
2930_export({
2931 target: 'Object',
2932 stat: true,
2933 forced: FAILS_ON_PRIMITIVES,
2934 sham: !correctPrototypeGetter
2935}, {
2936 getPrototypeOf: function getPrototypeOf(it) {
2937 return objectGetPrototypeOf(toObject(it));
2938 }
2939});
2940
2941var getPrototypeOf$5 = path.Object.getPrototypeOf;
2942
2943var getPrototypeOf$4 = getPrototypeOf$5;
2944
2945var getPrototypeOf$3 = getPrototypeOf$4;
2946
2947var $filter = arrayIteration.filter;
2948var HAS_SPECIES_SUPPORT = arrayMethodHasSpeciesSupport('filter'); // `Array.prototype.filter` method
2949// https://tc39.es/ecma262/#sec-array.prototype.filter
2950// with adding support of @@species
2951
2952_export({
2953 target: 'Array',
2954 proto: true,
2955 forced: !HAS_SPECIES_SUPPORT
2956}, {
2957 filter: function filter(callbackfn
2958 /* , thisArg */
2959 ) {
2960 return $filter(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
2961 }
2962});
2963
2964var filter$2 = entryVirtual('Array').filter;
2965
2966var ArrayPrototype$9 = Array.prototype;
2967
2968var filter_1 = function (it) {
2969 var own = it.filter;
2970 return it === ArrayPrototype$9 || it instanceof Array && own === ArrayPrototype$9.filter ? filter$2 : own;
2971};
2972
2973var filter$1 = filter_1;
2974
2975var filter = filter$1;
2976
2977var propertyIsEnumerable = objectPropertyIsEnumerable.f; // `Object.{ entries, values }` methods implementation
2978
2979var createMethod$2 = function (TO_ENTRIES) {
2980 return function (it) {
2981 var O = toIndexedObject(it);
2982 var keys = objectKeys(O);
2983 var length = keys.length;
2984 var i = 0;
2985 var result = [];
2986 var key;
2987
2988 while (length > i) {
2989 key = keys[i++];
2990
2991 if (!descriptors || propertyIsEnumerable.call(O, key)) {
2992 result.push(TO_ENTRIES ? [key, O[key]] : O[key]);
2993 }
2994 }
2995
2996 return result;
2997 };
2998};
2999
3000var objectToArray = {
3001 // `Object.entries` method
3002 // https://tc39.es/ecma262/#sec-object.entries
3003 entries: createMethod$2(true),
3004 // `Object.values` method
3005 // https://tc39.es/ecma262/#sec-object.values
3006 values: createMethod$2(false)
3007};
3008
3009var $values = objectToArray.values; // `Object.values` method
3010// https://tc39.es/ecma262/#sec-object.values
3011
3012_export({
3013 target: 'Object',
3014 stat: true
3015}, {
3016 values: function values(O) {
3017 return $values(O);
3018 }
3019});
3020
3021var values$5 = path.Object.values;
3022
3023var values$4 = values$5;
3024
3025var values$3 = values$4;
3026
3027// a string of all valid unicode whitespaces
3028var whitespaces = '\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002' + '\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF';
3029
3030var whitespace = '[' + whitespaces + ']';
3031var ltrim = RegExp('^' + whitespace + whitespace + '*');
3032var rtrim = RegExp(whitespace + whitespace + '*$'); // `String.prototype.{ trim, trimStart, trimEnd, trimLeft, trimRight }` methods implementation
3033
3034var createMethod$1 = function (TYPE) {
3035 return function ($this) {
3036 var string = toString_1(requireObjectCoercible($this));
3037 if (TYPE & 1) string = string.replace(ltrim, '');
3038 if (TYPE & 2) string = string.replace(rtrim, '');
3039 return string;
3040 };
3041};
3042
3043var stringTrim = {
3044 // `String.prototype.{ trimLeft, trimStart }` methods
3045 // https://tc39.es/ecma262/#sec-string.prototype.trimstart
3046 start: createMethod$1(1),
3047 // `String.prototype.{ trimRight, trimEnd }` methods
3048 // https://tc39.es/ecma262/#sec-string.prototype.trimend
3049 end: createMethod$1(2),
3050 // `String.prototype.trim` method
3051 // https://tc39.es/ecma262/#sec-string.prototype.trim
3052 trim: createMethod$1(3)
3053};
3054
3055var trim$4 = stringTrim.trim;
3056var $parseInt = global_1.parseInt;
3057var hex = /^[+-]?0[Xx]/;
3058var FORCED$4 = $parseInt(whitespaces + '08') !== 8 || $parseInt(whitespaces + '0x16') !== 22; // `parseInt` method
3059// https://tc39.es/ecma262/#sec-parseint-string-radix
3060
3061var numberParseInt = FORCED$4 ? function parseInt(string, radix) {
3062 var S = trim$4(toString_1(string));
3063 return $parseInt(S, radix >>> 0 || (hex.test(S) ? 16 : 10));
3064} : $parseInt;
3065
3066// https://tc39.es/ecma262/#sec-parseint-string-radix
3067
3068_export({
3069 global: true,
3070 forced: parseInt != numberParseInt
3071}, {
3072 parseInt: numberParseInt
3073});
3074
3075var _parseInt$2 = path.parseInt;
3076
3077var _parseInt$1 = _parseInt$2;
3078
3079var _parseInt = _parseInt$1;
3080
3081/* eslint-disable es/no-array-prototype-indexof -- required for testing */
3082
3083
3084var $indexOf = arrayIncludes.indexOf;
3085var nativeIndexOf = [].indexOf;
3086var NEGATIVE_ZERO = !!nativeIndexOf && 1 / [1].indexOf(1, -0) < 0;
3087var STRICT_METHOD$3 = arrayMethodIsStrict('indexOf'); // `Array.prototype.indexOf` method
3088// https://tc39.es/ecma262/#sec-array.prototype.indexof
3089
3090_export({
3091 target: 'Array',
3092 proto: true,
3093 forced: NEGATIVE_ZERO || !STRICT_METHOD$3
3094}, {
3095 indexOf: function indexOf(searchElement
3096 /* , fromIndex = 0 */
3097 ) {
3098 return NEGATIVE_ZERO // convert -0 to +0
3099 ? nativeIndexOf.apply(this, arguments) || 0 : $indexOf(this, searchElement, arguments.length > 1 ? arguments[1] : undefined);
3100 }
3101});
3102
3103var indexOf$2 = entryVirtual('Array').indexOf;
3104
3105var ArrayPrototype$8 = Array.prototype;
3106
3107var indexOf_1 = function (it) {
3108 var own = it.indexOf;
3109 return it === ArrayPrototype$8 || it instanceof Array && own === ArrayPrototype$8.indexOf ? indexOf$2 : own;
3110};
3111
3112var indexOf$1 = indexOf_1;
3113
3114var indexOf = indexOf$1;
3115
3116var non = '\u200B\u0085\u180E'; // check that a method works with the correct list
3117// of whitespaces and has a correct name
3118
3119var stringTrimForced = function (METHOD_NAME) {
3120 return fails(function () {
3121 return !!whitespaces[METHOD_NAME]() || non[METHOD_NAME]() != non || whitespaces[METHOD_NAME].name !== METHOD_NAME;
3122 });
3123};
3124
3125var $trim = stringTrim.trim; // `String.prototype.trim` method
3126// https://tc39.es/ecma262/#sec-string.prototype.trim
3127
3128_export({
3129 target: 'String',
3130 proto: true,
3131 forced: stringTrimForced('trim')
3132}, {
3133 trim: function trim() {
3134 return $trim(this);
3135 }
3136});
3137
3138var trim$3 = entryVirtual('String').trim;
3139
3140var StringPrototype = String.prototype;
3141
3142var trim_1 = function (it) {
3143 var own = it.trim;
3144 return typeof it === 'string' || it === StringPrototype || it instanceof String && own === StringPrototype.trim ? trim$3 : own;
3145};
3146
3147var trim$2 = trim_1;
3148
3149var trim$1 = trim$2;
3150
3151// https://tc39.es/ecma262/#sec-object.create
3152
3153_export({
3154 target: 'Object',
3155 stat: true,
3156 sham: !descriptors
3157}, {
3158 create: objectCreate
3159});
3160
3161var Object$1 = path.Object;
3162
3163var create$4 = function create(P, D) {
3164 return Object$1.create(P, D);
3165};
3166
3167var create$3 = create$4;
3168
3169var create$2 = create$3;
3170
3171var $stringify = getBuiltIn('JSON', 'stringify');
3172var re = /[\uD800-\uDFFF]/g;
3173var low = /^[\uD800-\uDBFF]$/;
3174var hi = /^[\uDC00-\uDFFF]$/;
3175
3176var fix = function (match, offset, string) {
3177 var prev = string.charAt(offset - 1);
3178 var next = string.charAt(offset + 1);
3179
3180 if (low.test(match) && !hi.test(next) || hi.test(match) && !low.test(prev)) {
3181 return '\\u' + match.charCodeAt(0).toString(16);
3182 }
3183
3184 return match;
3185};
3186
3187var FORCED$3 = fails(function () {
3188 return $stringify('\uDF06\uD834') !== '"\\udf06\\ud834"' || $stringify('\uDEAD') !== '"\\udead"';
3189});
3190
3191if ($stringify) {
3192 // `JSON.stringify` method
3193 // https://tc39.es/ecma262/#sec-json.stringify
3194 // https://github.com/tc39/proposal-well-formed-stringify
3195 _export({
3196 target: 'JSON',
3197 stat: true,
3198 forced: FORCED$3
3199 }, {
3200 // eslint-disable-next-line no-unused-vars -- required for `.length`
3201 stringify: function stringify(it, replacer, space) {
3202 var result = $stringify.apply(null, arguments);
3203 return typeof result == 'string' ? result.replace(re, fix) : result;
3204 }
3205 });
3206}
3207
3208if (!path.JSON) path.JSON = {
3209 stringify: JSON.stringify
3210}; // eslint-disable-next-line no-unused-vars -- required for `.length`
3211
3212var stringify$3 = function stringify(it, replacer, space) {
3213 return path.JSON.stringify.apply(null, arguments);
3214};
3215
3216var stringify$2 = stringify$3;
3217
3218var stringify$1 = stringify$2;
3219
3220var slice = [].slice;
3221var MSIE = /MSIE .\./.test(engineUserAgent); // <- dirty ie9- check
3222
3223var wrap = function (scheduler) {
3224 return function (handler, timeout
3225 /* , ...arguments */
3226 ) {
3227 var boundArgs = arguments.length > 2;
3228 var args = boundArgs ? slice.call(arguments, 2) : undefined;
3229 return scheduler(boundArgs ? function () {
3230 // eslint-disable-next-line no-new-func -- spec requirement
3231 (typeof handler == 'function' ? handler : Function(handler)).apply(this, args);
3232 } : handler, timeout);
3233 };
3234}; // ie9- setTimeout & setInterval additional parameters fix
3235// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
3236
3237
3238_export({
3239 global: true,
3240 bind: true,
3241 forced: MSIE
3242}, {
3243 // `setTimeout` method
3244 // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-settimeout
3245 setTimeout: wrap(global_1.setTimeout),
3246 // `setInterval` method
3247 // https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#dom-setinterval
3248 setInterval: wrap(global_1.setInterval)
3249});
3250
3251var setTimeout$2 = path.setTimeout;
3252
3253var setTimeout$1 = setTimeout$2;
3254
3255// https://tc39.es/ecma262/#sec-array.prototype.fill
3256
3257
3258var arrayFill = function fill(value
3259/* , start = 0, end = @length */
3260) {
3261 var O = toObject(this);
3262 var length = toLength(O.length);
3263 var argumentsLength = arguments.length;
3264 var index = toAbsoluteIndex(argumentsLength > 1 ? arguments[1] : undefined, length);
3265 var end = argumentsLength > 2 ? arguments[2] : undefined;
3266 var endPos = end === undefined ? length : toAbsoluteIndex(end, length);
3267
3268 while (endPos > index) O[index++] = value;
3269
3270 return O;
3271};
3272
3273// https://tc39.es/ecma262/#sec-array.prototype.fill
3274
3275_export({
3276 target: 'Array',
3277 proto: true
3278}, {
3279 fill: arrayFill
3280}); // https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
3281
3282var fill$2 = entryVirtual('Array').fill;
3283
3284var ArrayPrototype$7 = Array.prototype;
3285
3286var fill_1 = function (it) {
3287 var own = it.fill;
3288 return it === ArrayPrototype$7 || it instanceof Array && own === ArrayPrototype$7.fill ? fill$2 : own;
3289};
3290
3291var fill$1 = fill_1;
3292
3293var fill = fill$1;
3294
3295var componentEmitter = createCommonjsModule(function (module) {
3296 /**
3297 * Expose `Emitter`.
3298 */
3299 {
3300 module.exports = Emitter;
3301 }
3302 /**
3303 * Initialize a new `Emitter`.
3304 *
3305 * @api public
3306 */
3307
3308
3309 function Emitter(obj) {
3310 if (obj) return mixin(obj);
3311 }
3312 /**
3313 * Mixin the emitter properties.
3314 *
3315 * @param {Object} obj
3316 * @return {Object}
3317 * @api private
3318 */
3319
3320 function mixin(obj) {
3321 for (var key in Emitter.prototype) {
3322 obj[key] = Emitter.prototype[key];
3323 }
3324
3325 return obj;
3326 }
3327 /**
3328 * Listen on the given `event` with `fn`.
3329 *
3330 * @param {String} event
3331 * @param {Function} fn
3332 * @return {Emitter}
3333 * @api public
3334 */
3335
3336
3337 Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
3338 this._callbacks = this._callbacks || {};
3339 (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
3340 return this;
3341 };
3342 /**
3343 * Adds an `event` listener that will be invoked a single
3344 * time then automatically removed.
3345 *
3346 * @param {String} event
3347 * @param {Function} fn
3348 * @return {Emitter}
3349 * @api public
3350 */
3351
3352
3353 Emitter.prototype.once = function (event, fn) {
3354 function on() {
3355 this.off(event, on);
3356 fn.apply(this, arguments);
3357 }
3358
3359 on.fn = fn;
3360 this.on(event, on);
3361 return this;
3362 };
3363 /**
3364 * Remove the given callback for `event` or all
3365 * registered callbacks.
3366 *
3367 * @param {String} event
3368 * @param {Function} fn
3369 * @return {Emitter}
3370 * @api public
3371 */
3372
3373
3374 Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
3375 this._callbacks = this._callbacks || {}; // all
3376
3377 if (0 == arguments.length) {
3378 this._callbacks = {};
3379 return this;
3380 } // specific event
3381
3382
3383 var callbacks = this._callbacks['$' + event];
3384 if (!callbacks) return this; // remove all handlers
3385
3386 if (1 == arguments.length) {
3387 delete this._callbacks['$' + event];
3388 return this;
3389 } // remove specific handler
3390
3391
3392 var cb;
3393
3394 for (var i = 0; i < callbacks.length; i++) {
3395 cb = callbacks[i];
3396
3397 if (cb === fn || cb.fn === fn) {
3398 callbacks.splice(i, 1);
3399 break;
3400 }
3401 } // Remove event specific arrays for event types that no
3402 // one is subscribed for to avoid memory leak.
3403
3404
3405 if (callbacks.length === 0) {
3406 delete this._callbacks['$' + event];
3407 }
3408
3409 return this;
3410 };
3411 /**
3412 * Emit `event` with the given args.
3413 *
3414 * @param {String} event
3415 * @param {Mixed} ...
3416 * @return {Emitter}
3417 */
3418
3419
3420 Emitter.prototype.emit = function (event) {
3421 this._callbacks = this._callbacks || {};
3422 var args = new Array(arguments.length - 1),
3423 callbacks = this._callbacks['$' + event];
3424
3425 for (var i = 1; i < arguments.length; i++) {
3426 args[i - 1] = arguments[i];
3427 }
3428
3429 if (callbacks) {
3430 callbacks = callbacks.slice(0);
3431
3432 for (var i = 0, len = callbacks.length; i < len; ++i) {
3433 callbacks[i].apply(this, args);
3434 }
3435 }
3436
3437 return this;
3438 };
3439 /**
3440 * Return array of callbacks for `event`.
3441 *
3442 * @param {String} event
3443 * @return {Array}
3444 * @api public
3445 */
3446
3447
3448 Emitter.prototype.listeners = function (event) {
3449 this._callbacks = this._callbacks || {};
3450 return this._callbacks['$' + event] || [];
3451 };
3452 /**
3453 * Check if this emitter has `event` handlers.
3454 *
3455 * @param {String} event
3456 * @return {Boolean}
3457 * @api public
3458 */
3459
3460
3461 Emitter.prototype.hasListeners = function (event) {
3462 return !!this.listeners(event).length;
3463 };
3464});
3465
3466/*! Hammer.JS - v2.0.17-rc - 2019-12-16
3467 * http://naver.github.io/egjs
3468 *
3469 * Forked By Naver egjs
3470 * Copyright (c) hammerjs
3471 * Licensed under the MIT license */
3472function _extends() {
3473 _extends = Object.assign || function (target) {
3474 for (var i = 1; i < arguments.length; i++) {
3475 var source = arguments[i];
3476
3477 for (var key in source) {
3478 if (Object.prototype.hasOwnProperty.call(source, key)) {
3479 target[key] = source[key];
3480 }
3481 }
3482 }
3483
3484 return target;
3485 };
3486
3487 return _extends.apply(this, arguments);
3488}
3489
3490function _inheritsLoose(subClass, superClass) {
3491 subClass.prototype = Object.create(superClass.prototype);
3492 subClass.prototype.constructor = subClass;
3493 subClass.__proto__ = superClass;
3494}
3495
3496function _assertThisInitialized$1(self) {
3497 if (self === void 0) {
3498 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
3499 }
3500
3501 return self;
3502}
3503/**
3504 * @private
3505 * extend object.
3506 * means that properties in dest will be overwritten by the ones in src.
3507 * @param {Object} target
3508 * @param {...Object} objects_to_assign
3509 * @returns {Object} target
3510 */
3511
3512
3513var assign;
3514
3515if (typeof Object.assign !== 'function') {
3516 assign = function assign(target) {
3517 if (target === undefined || target === null) {
3518 throw new TypeError('Cannot convert undefined or null to object');
3519 }
3520
3521 var output = Object(target);
3522
3523 for (var index = 1; index < arguments.length; index++) {
3524 var source = arguments[index];
3525
3526 if (source !== undefined && source !== null) {
3527 for (var nextKey in source) {
3528 if (source.hasOwnProperty(nextKey)) {
3529 output[nextKey] = source[nextKey];
3530 }
3531 }
3532 }
3533 }
3534
3535 return output;
3536 };
3537} else {
3538 assign = Object.assign;
3539}
3540
3541var assign$1 = assign;
3542var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
3543var TEST_ELEMENT = typeof document === "undefined" ? {
3544 style: {}
3545} : document.createElement('div');
3546var TYPE_FUNCTION = 'function';
3547var round = Math.round,
3548 abs = Math.abs;
3549var now = Date.now;
3550/**
3551 * @private
3552 * get the prefixed property
3553 * @param {Object} obj
3554 * @param {String} property
3555 * @returns {String|Undefined} prefixed
3556 */
3557
3558function prefixed(obj, property) {
3559 var prefix;
3560 var prop;
3561 var camelProp = property[0].toUpperCase() + property.slice(1);
3562 var i = 0;
3563
3564 while (i < VENDOR_PREFIXES.length) {
3565 prefix = VENDOR_PREFIXES[i];
3566 prop = prefix ? prefix + camelProp : property;
3567
3568 if (prop in obj) {
3569 return prop;
3570 }
3571
3572 i++;
3573 }
3574
3575 return undefined;
3576}
3577/* eslint-disable no-new-func, no-nested-ternary */
3578
3579
3580var win;
3581
3582if (typeof window === "undefined") {
3583 // window is undefined in node.js
3584 win = {};
3585} else {
3586 win = window;
3587}
3588
3589var PREFIXED_TOUCH_ACTION = prefixed(TEST_ELEMENT.style, 'touchAction');
3590var NATIVE_TOUCH_ACTION = PREFIXED_TOUCH_ACTION !== undefined;
3591
3592function getTouchActionProps() {
3593 if (!NATIVE_TOUCH_ACTION) {
3594 return false;
3595 }
3596
3597 var touchMap = {};
3598 var cssSupports = win.CSS && win.CSS.supports;
3599 ['auto', 'manipulation', 'pan-y', 'pan-x', 'pan-x pan-y', 'none'].forEach(function (val) {
3600 // If css.supports is not supported but there is native touch-action assume it supports
3601 // all values. This is the case for IE 10 and 11.
3602 return touchMap[val] = cssSupports ? win.CSS.supports('touch-action', val) : true;
3603 });
3604 return touchMap;
3605}
3606
3607var TOUCH_ACTION_COMPUTE = 'compute';
3608var TOUCH_ACTION_AUTO = 'auto';
3609var TOUCH_ACTION_MANIPULATION = 'manipulation'; // not implemented
3610
3611var TOUCH_ACTION_NONE = 'none';
3612var TOUCH_ACTION_PAN_X = 'pan-x';
3613var TOUCH_ACTION_PAN_Y = 'pan-y';
3614var TOUCH_ACTION_MAP = getTouchActionProps();
3615var MOBILE_REGEX = /mobile|tablet|ip(ad|hone|od)|android/i;
3616var SUPPORT_TOUCH = ('ontouchstart' in win);
3617var SUPPORT_POINTER_EVENTS = prefixed(win, 'PointerEvent') !== undefined;
3618var SUPPORT_ONLY_TOUCH = SUPPORT_TOUCH && MOBILE_REGEX.test(navigator.userAgent);
3619var INPUT_TYPE_TOUCH = 'touch';
3620var INPUT_TYPE_PEN = 'pen';
3621var INPUT_TYPE_MOUSE = 'mouse';
3622var INPUT_TYPE_KINECT = 'kinect';
3623var COMPUTE_INTERVAL = 25;
3624var INPUT_START = 1;
3625var INPUT_MOVE = 2;
3626var INPUT_END = 4;
3627var INPUT_CANCEL = 8;
3628var DIRECTION_NONE = 1;
3629var DIRECTION_LEFT = 2;
3630var DIRECTION_RIGHT = 4;
3631var DIRECTION_UP = 8;
3632var DIRECTION_DOWN = 16;
3633var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
3634var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
3635var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
3636var PROPS_XY = ['x', 'y'];
3637var PROPS_CLIENT_XY = ['clientX', 'clientY'];
3638/**
3639 * @private
3640 * walk objects and arrays
3641 * @param {Object} obj
3642 * @param {Function} iterator
3643 * @param {Object} context
3644 */
3645
3646function each(obj, iterator, context) {
3647 var i;
3648
3649 if (!obj) {
3650 return;
3651 }
3652
3653 if (obj.forEach) {
3654 obj.forEach(iterator, context);
3655 } else if (obj.length !== undefined) {
3656 i = 0;
3657
3658 while (i < obj.length) {
3659 iterator.call(context, obj[i], i, obj);
3660 i++;
3661 }
3662 } else {
3663 for (i in obj) {
3664 obj.hasOwnProperty(i) && iterator.call(context, obj[i], i, obj);
3665 }
3666 }
3667}
3668/**
3669 * @private
3670 * let a boolean value also be a function that must return a boolean
3671 * this first item in args will be used as the context
3672 * @param {Boolean|Function} val
3673 * @param {Array} [args]
3674 * @returns {Boolean}
3675 */
3676
3677
3678function boolOrFn(val, args) {
3679 if (typeof val === TYPE_FUNCTION) {
3680 return val.apply(args ? args[0] || undefined : undefined, args);
3681 }
3682
3683 return val;
3684}
3685/**
3686 * @private
3687 * small indexOf wrapper
3688 * @param {String} str
3689 * @param {String} find
3690 * @returns {Boolean} found
3691 */
3692
3693
3694function inStr(str, find) {
3695 return str.indexOf(find) > -1;
3696}
3697/**
3698 * @private
3699 * when the touchActions are collected they are not a valid value, so we need to clean things up. *
3700 * @param {String} actions
3701 * @returns {*}
3702 */
3703
3704
3705function cleanTouchActions(actions) {
3706 // none
3707 if (inStr(actions, TOUCH_ACTION_NONE)) {
3708 return TOUCH_ACTION_NONE;
3709 }
3710
3711 var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X);
3712 var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y); // if both pan-x and pan-y are set (different recognizers
3713 // for different directions, e.g. horizontal pan but vertical swipe?)
3714 // we need none (as otherwise with pan-x pan-y combined none of these
3715 // recognizers will work, since the browser would handle all panning
3716
3717 if (hasPanX && hasPanY) {
3718 return TOUCH_ACTION_NONE;
3719 } // pan-x OR pan-y
3720
3721
3722 if (hasPanX || hasPanY) {
3723 return hasPanX ? TOUCH_ACTION_PAN_X : TOUCH_ACTION_PAN_Y;
3724 } // manipulation
3725
3726
3727 if (inStr(actions, TOUCH_ACTION_MANIPULATION)) {
3728 return TOUCH_ACTION_MANIPULATION;
3729 }
3730
3731 return TOUCH_ACTION_AUTO;
3732}
3733/**
3734 * @private
3735 * Touch Action
3736 * sets the touchAction property or uses the js alternative
3737 * @param {Manager} manager
3738 * @param {String} value
3739 * @constructor
3740 */
3741
3742
3743var TouchAction = /*#__PURE__*/function () {
3744 function TouchAction(manager, value) {
3745 this.manager = manager;
3746 this.set(value);
3747 }
3748 /**
3749 * @private
3750 * set the touchAction value on the element or enable the polyfill
3751 * @param {String} value
3752 */
3753
3754
3755 var _proto = TouchAction.prototype;
3756
3757 _proto.set = function set(value) {
3758 // find out the touch-action by the event handlers
3759 if (value === TOUCH_ACTION_COMPUTE) {
3760 value = this.compute();
3761 }
3762
3763 if (NATIVE_TOUCH_ACTION && this.manager.element.style && TOUCH_ACTION_MAP[value]) {
3764 this.manager.element.style[PREFIXED_TOUCH_ACTION] = value;
3765 }
3766
3767 this.actions = value.toLowerCase().trim();
3768 };
3769 /**
3770 * @private
3771 * just re-set the touchAction value
3772 */
3773
3774
3775 _proto.update = function update() {
3776 this.set(this.manager.options.touchAction);
3777 };
3778 /**
3779 * @private
3780 * compute the value for the touchAction property based on the recognizer's settings
3781 * @returns {String} value
3782 */
3783
3784
3785 _proto.compute = function compute() {
3786 var actions = [];
3787 each(this.manager.recognizers, function (recognizer) {
3788 if (boolOrFn(recognizer.options.enable, [recognizer])) {
3789 actions = actions.concat(recognizer.getTouchAction());
3790 }
3791 });
3792 return cleanTouchActions(actions.join(' '));
3793 };
3794 /**
3795 * @private
3796 * this method is called on each input cycle and provides the preventing of the browser behavior
3797 * @param {Object} input
3798 */
3799
3800
3801 _proto.preventDefaults = function preventDefaults(input) {
3802 var srcEvent = input.srcEvent;
3803 var direction = input.offsetDirection; // if the touch action did prevented once this session
3804
3805 if (this.manager.session.prevented) {
3806 srcEvent.preventDefault();
3807 return;
3808 }
3809
3810 var actions = this.actions;
3811 var hasNone = inStr(actions, TOUCH_ACTION_NONE) && !TOUCH_ACTION_MAP[TOUCH_ACTION_NONE];
3812 var hasPanY = inStr(actions, TOUCH_ACTION_PAN_Y) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_Y];
3813 var hasPanX = inStr(actions, TOUCH_ACTION_PAN_X) && !TOUCH_ACTION_MAP[TOUCH_ACTION_PAN_X];
3814
3815 if (hasNone) {
3816 // do not prevent defaults if this is a tap gesture
3817 var isTapPointer = input.pointers.length === 1;
3818 var isTapMovement = input.distance < 2;
3819 var isTapTouchTime = input.deltaTime < 250;
3820
3821 if (isTapPointer && isTapMovement && isTapTouchTime) {
3822 return;
3823 }
3824 }
3825
3826 if (hasPanX && hasPanY) {
3827 // `pan-x pan-y` means browser handles all scrolling/panning, do not prevent
3828 return;
3829 }
3830
3831 if (hasNone || hasPanY && direction & DIRECTION_HORIZONTAL || hasPanX && direction & DIRECTION_VERTICAL) {
3832 return this.preventSrc(srcEvent);
3833 }
3834 };
3835 /**
3836 * @private
3837 * call preventDefault to prevent the browser's default behavior (scrolling in most cases)
3838 * @param {Object} srcEvent
3839 */
3840
3841
3842 _proto.preventSrc = function preventSrc(srcEvent) {
3843 this.manager.session.prevented = true;
3844 srcEvent.preventDefault();
3845 };
3846
3847 return TouchAction;
3848}();
3849/**
3850 * @private
3851 * find if a node is in the given parent
3852 * @method hasParent
3853 * @param {HTMLElement} node
3854 * @param {HTMLElement} parent
3855 * @return {Boolean} found
3856 */
3857
3858
3859function hasParent$1(node, parent) {
3860 while (node) {
3861 if (node === parent) {
3862 return true;
3863 }
3864
3865 node = node.parentNode;
3866 }
3867
3868 return false;
3869}
3870/**
3871 * @private
3872 * get the center of all the pointers
3873 * @param {Array} pointers
3874 * @return {Object} center contains `x` and `y` properties
3875 */
3876
3877
3878function getCenter(pointers) {
3879 var pointersLength = pointers.length; // no need to loop when only one touch
3880
3881 if (pointersLength === 1) {
3882 return {
3883 x: round(pointers[0].clientX),
3884 y: round(pointers[0].clientY)
3885 };
3886 }
3887
3888 var x = 0;
3889 var y = 0;
3890 var i = 0;
3891
3892 while (i < pointersLength) {
3893 x += pointers[i].clientX;
3894 y += pointers[i].clientY;
3895 i++;
3896 }
3897
3898 return {
3899 x: round(x / pointersLength),
3900 y: round(y / pointersLength)
3901 };
3902}
3903/**
3904 * @private
3905 * create a simple clone from the input used for storage of firstInput and firstMultiple
3906 * @param {Object} input
3907 * @returns {Object} clonedInputData
3908 */
3909
3910
3911function simpleCloneInputData(input) {
3912 // make a simple copy of the pointers because we will get a reference if we don't
3913 // we only need clientXY for the calculations
3914 var pointers = [];
3915 var i = 0;
3916
3917 while (i < input.pointers.length) {
3918 pointers[i] = {
3919 clientX: round(input.pointers[i].clientX),
3920 clientY: round(input.pointers[i].clientY)
3921 };
3922 i++;
3923 }
3924
3925 return {
3926 timeStamp: now(),
3927 pointers: pointers,
3928 center: getCenter(pointers),
3929 deltaX: input.deltaX,
3930 deltaY: input.deltaY
3931 };
3932}
3933/**
3934 * @private
3935 * calculate the absolute distance between two points
3936 * @param {Object} p1 {x, y}
3937 * @param {Object} p2 {x, y}
3938 * @param {Array} [props] containing x and y keys
3939 * @return {Number} distance
3940 */
3941
3942
3943function getDistance(p1, p2, props) {
3944 if (!props) {
3945 props = PROPS_XY;
3946 }
3947
3948 var x = p2[props[0]] - p1[props[0]];
3949 var y = p2[props[1]] - p1[props[1]];
3950 return Math.sqrt(x * x + y * y);
3951}
3952/**
3953 * @private
3954 * calculate the angle between two coordinates
3955 * @param {Object} p1
3956 * @param {Object} p2
3957 * @param {Array} [props] containing x and y keys
3958 * @return {Number} angle
3959 */
3960
3961
3962function getAngle(p1, p2, props) {
3963 if (!props) {
3964 props = PROPS_XY;
3965 }
3966
3967 var x = p2[props[0]] - p1[props[0]];
3968 var y = p2[props[1]] - p1[props[1]];
3969 return Math.atan2(y, x) * 180 / Math.PI;
3970}
3971/**
3972 * @private
3973 * get the direction between two points
3974 * @param {Number} x
3975 * @param {Number} y
3976 * @return {Number} direction
3977 */
3978
3979
3980function getDirection(x, y) {
3981 if (x === y) {
3982 return DIRECTION_NONE;
3983 }
3984
3985 if (abs(x) >= abs(y)) {
3986 return x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
3987 }
3988
3989 return y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
3990}
3991
3992function computeDeltaXY(session, input) {
3993 var center = input.center; // let { offsetDelta:offset = {}, prevDelta = {}, prevInput = {} } = session;
3994 // jscs throwing error on defalut destructured values and without defaults tests fail
3995
3996 var offset = session.offsetDelta || {};
3997 var prevDelta = session.prevDelta || {};
3998 var prevInput = session.prevInput || {};
3999
4000 if (input.eventType === INPUT_START || prevInput.eventType === INPUT_END) {
4001 prevDelta = session.prevDelta = {
4002 x: prevInput.deltaX || 0,
4003 y: prevInput.deltaY || 0
4004 };
4005 offset = session.offsetDelta = {
4006 x: center.x,
4007 y: center.y
4008 };
4009 }
4010
4011 input.deltaX = prevDelta.x + (center.x - offset.x);
4012 input.deltaY = prevDelta.y + (center.y - offset.y);
4013}
4014/**
4015 * @private
4016 * calculate the velocity between two points. unit is in px per ms.
4017 * @param {Number} deltaTime
4018 * @param {Number} x
4019 * @param {Number} y
4020 * @return {Object} velocity `x` and `y`
4021 */
4022
4023
4024function getVelocity(deltaTime, x, y) {
4025 return {
4026 x: x / deltaTime || 0,
4027 y: y / deltaTime || 0
4028 };
4029}
4030/**
4031 * @private
4032 * calculate the scale factor between two pointersets
4033 * no scale is 1, and goes down to 0 when pinched together, and bigger when pinched out
4034 * @param {Array} start array of pointers
4035 * @param {Array} end array of pointers
4036 * @return {Number} scale
4037 */
4038
4039
4040function getScale(start, end) {
4041 return getDistance(end[0], end[1], PROPS_CLIENT_XY) / getDistance(start[0], start[1], PROPS_CLIENT_XY);
4042}
4043/**
4044 * @private
4045 * calculate the rotation degrees between two pointersets
4046 * @param {Array} start array of pointers
4047 * @param {Array} end array of pointers
4048 * @return {Number} rotation
4049 */
4050
4051
4052function getRotation(start, end) {
4053 return getAngle(end[1], end[0], PROPS_CLIENT_XY) + getAngle(start[1], start[0], PROPS_CLIENT_XY);
4054}
4055/**
4056 * @private
4057 * velocity is calculated every x ms
4058 * @param {Object} session
4059 * @param {Object} input
4060 */
4061
4062
4063function computeIntervalInputData(session, input) {
4064 var last = session.lastInterval || input;
4065 var deltaTime = input.timeStamp - last.timeStamp;
4066 var velocity;
4067 var velocityX;
4068 var velocityY;
4069 var direction;
4070
4071 if (input.eventType !== INPUT_CANCEL && (deltaTime > COMPUTE_INTERVAL || last.velocity === undefined)) {
4072 var deltaX = input.deltaX - last.deltaX;
4073 var deltaY = input.deltaY - last.deltaY;
4074 var v = getVelocity(deltaTime, deltaX, deltaY);
4075 velocityX = v.x;
4076 velocityY = v.y;
4077 velocity = abs(v.x) > abs(v.y) ? v.x : v.y;
4078 direction = getDirection(deltaX, deltaY);
4079 session.lastInterval = input;
4080 } else {
4081 // use latest velocity info if it doesn't overtake a minimum period
4082 velocity = last.velocity;
4083 velocityX = last.velocityX;
4084 velocityY = last.velocityY;
4085 direction = last.direction;
4086 }
4087
4088 input.velocity = velocity;
4089 input.velocityX = velocityX;
4090 input.velocityY = velocityY;
4091 input.direction = direction;
4092}
4093/**
4094* @private
4095 * extend the data with some usable properties like scale, rotate, velocity etc
4096 * @param {Object} manager
4097 * @param {Object} input
4098 */
4099
4100
4101function computeInputData(manager, input) {
4102 var session = manager.session;
4103 var pointers = input.pointers;
4104 var pointersLength = pointers.length; // store the first input to calculate the distance and direction
4105
4106 if (!session.firstInput) {
4107 session.firstInput = simpleCloneInputData(input);
4108 } // to compute scale and rotation we need to store the multiple touches
4109
4110
4111 if (pointersLength > 1 && !session.firstMultiple) {
4112 session.firstMultiple = simpleCloneInputData(input);
4113 } else if (pointersLength === 1) {
4114 session.firstMultiple = false;
4115 }
4116
4117 var firstInput = session.firstInput,
4118 firstMultiple = session.firstMultiple;
4119 var offsetCenter = firstMultiple ? firstMultiple.center : firstInput.center;
4120 var center = input.center = getCenter(pointers);
4121 input.timeStamp = now();
4122 input.deltaTime = input.timeStamp - firstInput.timeStamp;
4123 input.angle = getAngle(offsetCenter, center);
4124 input.distance = getDistance(offsetCenter, center);
4125 computeDeltaXY(session, input);
4126 input.offsetDirection = getDirection(input.deltaX, input.deltaY);
4127 var overallVelocity = getVelocity(input.deltaTime, input.deltaX, input.deltaY);
4128 input.overallVelocityX = overallVelocity.x;
4129 input.overallVelocityY = overallVelocity.y;
4130 input.overallVelocity = abs(overallVelocity.x) > abs(overallVelocity.y) ? overallVelocity.x : overallVelocity.y;
4131 input.scale = firstMultiple ? getScale(firstMultiple.pointers, pointers) : 1;
4132 input.rotation = firstMultiple ? getRotation(firstMultiple.pointers, pointers) : 0;
4133 input.maxPointers = !session.prevInput ? input.pointers.length : input.pointers.length > session.prevInput.maxPointers ? input.pointers.length : session.prevInput.maxPointers;
4134 computeIntervalInputData(session, input); // find the correct target
4135
4136 var target = manager.element;
4137 var srcEvent = input.srcEvent;
4138 var srcEventTarget;
4139
4140 if (srcEvent.composedPath) {
4141 srcEventTarget = srcEvent.composedPath()[0];
4142 } else if (srcEvent.path) {
4143 srcEventTarget = srcEvent.path[0];
4144 } else {
4145 srcEventTarget = srcEvent.target;
4146 }
4147
4148 if (hasParent$1(srcEventTarget, target)) {
4149 target = srcEventTarget;
4150 }
4151
4152 input.target = target;
4153}
4154/**
4155 * @private
4156 * handle input events
4157 * @param {Manager} manager
4158 * @param {String} eventType
4159 * @param {Object} input
4160 */
4161
4162
4163function inputHandler(manager, eventType, input) {
4164 var pointersLen = input.pointers.length;
4165 var changedPointersLen = input.changedPointers.length;
4166 var isFirst = eventType & INPUT_START && pointersLen - changedPointersLen === 0;
4167 var isFinal = eventType & (INPUT_END | INPUT_CANCEL) && pointersLen - changedPointersLen === 0;
4168 input.isFirst = !!isFirst;
4169 input.isFinal = !!isFinal;
4170
4171 if (isFirst) {
4172 manager.session = {};
4173 } // source event is the normalized value of the domEvents
4174 // like 'touchstart, mouseup, pointerdown'
4175
4176
4177 input.eventType = eventType; // compute scale, rotation etc
4178
4179 computeInputData(manager, input); // emit secret event
4180
4181 manager.emit('hammer.input', input);
4182 manager.recognize(input);
4183 manager.session.prevInput = input;
4184}
4185/**
4186 * @private
4187 * split string on whitespace
4188 * @param {String} str
4189 * @returns {Array} words
4190 */
4191
4192
4193function splitStr(str) {
4194 return str.trim().split(/\s+/g);
4195}
4196/**
4197 * @private
4198 * addEventListener with multiple events at once
4199 * @param {EventTarget} target
4200 * @param {String} types
4201 * @param {Function} handler
4202 */
4203
4204
4205function addEventListeners(target, types, handler) {
4206 each(splitStr(types), function (type) {
4207 target.addEventListener(type, handler, false);
4208 });
4209}
4210/**
4211 * @private
4212 * removeEventListener with multiple events at once
4213 * @param {EventTarget} target
4214 * @param {String} types
4215 * @param {Function} handler
4216 */
4217
4218
4219function removeEventListeners(target, types, handler) {
4220 each(splitStr(types), function (type) {
4221 target.removeEventListener(type, handler, false);
4222 });
4223}
4224/**
4225 * @private
4226 * get the window object of an element
4227 * @param {HTMLElement} element
4228 * @returns {DocumentView|Window}
4229 */
4230
4231
4232function getWindowForElement(element) {
4233 var doc = element.ownerDocument || element;
4234 return doc.defaultView || doc.parentWindow || window;
4235}
4236/**
4237 * @private
4238 * create new input type manager
4239 * @param {Manager} manager
4240 * @param {Function} callback
4241 * @returns {Input}
4242 * @constructor
4243 */
4244
4245
4246var Input = /*#__PURE__*/function () {
4247 function Input(manager, callback) {
4248 var self = this;
4249 this.manager = manager;
4250 this.callback = callback;
4251 this.element = manager.element;
4252 this.target = manager.options.inputTarget; // smaller wrapper around the handler, for the scope and the enabled state of the manager,
4253 // so when disabled the input events are completely bypassed.
4254
4255 this.domHandler = function (ev) {
4256 if (boolOrFn(manager.options.enable, [manager])) {
4257 self.handler(ev);
4258 }
4259 };
4260
4261 this.init();
4262 }
4263 /**
4264 * @private
4265 * should handle the inputEvent data and trigger the callback
4266 * @virtual
4267 */
4268
4269
4270 var _proto = Input.prototype;
4271
4272 _proto.handler = function handler() {};
4273 /**
4274 * @private
4275 * bind the events
4276 */
4277
4278
4279 _proto.init = function init() {
4280 this.evEl && addEventListeners(this.element, this.evEl, this.domHandler);
4281 this.evTarget && addEventListeners(this.target, this.evTarget, this.domHandler);
4282 this.evWin && addEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
4283 };
4284 /**
4285 * @private
4286 * unbind the events
4287 */
4288
4289
4290 _proto.destroy = function destroy() {
4291 this.evEl && removeEventListeners(this.element, this.evEl, this.domHandler);
4292 this.evTarget && removeEventListeners(this.target, this.evTarget, this.domHandler);
4293 this.evWin && removeEventListeners(getWindowForElement(this.element), this.evWin, this.domHandler);
4294 };
4295
4296 return Input;
4297}();
4298/**
4299 * @private
4300 * find if a array contains the object using indexOf or a simple polyFill
4301 * @param {Array} src
4302 * @param {String} find
4303 * @param {String} [findByKey]
4304 * @return {Boolean|Number} false when not found, or the index
4305 */
4306
4307
4308function inArray(src, find, findByKey) {
4309 if (src.indexOf && !findByKey) {
4310 return src.indexOf(find);
4311 } else {
4312 var i = 0;
4313
4314 while (i < src.length) {
4315 if (findByKey && src[i][findByKey] == find || !findByKey && src[i] === find) {
4316 // do not use === here, test fails
4317 return i;
4318 }
4319
4320 i++;
4321 }
4322
4323 return -1;
4324 }
4325}
4326
4327var POINTER_INPUT_MAP = {
4328 pointerdown: INPUT_START,
4329 pointermove: INPUT_MOVE,
4330 pointerup: INPUT_END,
4331 pointercancel: INPUT_CANCEL,
4332 pointerout: INPUT_CANCEL
4333}; // in IE10 the pointer types is defined as an enum
4334
4335var IE10_POINTER_TYPE_ENUM = {
4336 2: INPUT_TYPE_TOUCH,
4337 3: INPUT_TYPE_PEN,
4338 4: INPUT_TYPE_MOUSE,
4339 5: INPUT_TYPE_KINECT // see https://twitter.com/jacobrossi/status/480596438489890816
4340
4341};
4342var POINTER_ELEMENT_EVENTS = 'pointerdown';
4343var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel'; // IE10 has prefixed support, and case-sensitive
4344
4345if (win.MSPointerEvent && !win.PointerEvent) {
4346 POINTER_ELEMENT_EVENTS = 'MSPointerDown';
4347 POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
4348}
4349/**
4350 * @private
4351 * Pointer events input
4352 * @constructor
4353 * @extends Input
4354 */
4355
4356
4357var PointerEventInput = /*#__PURE__*/function (_Input) {
4358 _inheritsLoose(PointerEventInput, _Input);
4359
4360 function PointerEventInput() {
4361 var _this;
4362
4363 var proto = PointerEventInput.prototype;
4364 proto.evEl = POINTER_ELEMENT_EVENTS;
4365 proto.evWin = POINTER_WINDOW_EVENTS;
4366 _this = _Input.apply(this, arguments) || this;
4367 _this.store = _this.manager.session.pointerEvents = [];
4368 return _this;
4369 }
4370 /**
4371 * @private
4372 * handle mouse events
4373 * @param {Object} ev
4374 */
4375
4376
4377 var _proto = PointerEventInput.prototype;
4378
4379 _proto.handler = function handler(ev) {
4380 var store = this.store;
4381 var removePointer = false;
4382 var eventTypeNormalized = ev.type.toLowerCase().replace('ms', '');
4383 var eventType = POINTER_INPUT_MAP[eventTypeNormalized];
4384 var pointerType = IE10_POINTER_TYPE_ENUM[ev.pointerType] || ev.pointerType;
4385 var isTouch = pointerType === INPUT_TYPE_TOUCH; // get index of the event in the store
4386
4387 var storeIndex = inArray(store, ev.pointerId, 'pointerId'); // start and mouse must be down
4388
4389 if (eventType & INPUT_START && (ev.button === 0 || isTouch)) {
4390 if (storeIndex < 0) {
4391 store.push(ev);
4392 storeIndex = store.length - 1;
4393 }
4394 } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
4395 removePointer = true;
4396 } // it not found, so the pointer hasn't been down (so it's probably a hover)
4397
4398
4399 if (storeIndex < 0) {
4400 return;
4401 } // update the event in the store
4402
4403
4404 store[storeIndex] = ev;
4405 this.callback(this.manager, eventType, {
4406 pointers: store,
4407 changedPointers: [ev],
4408 pointerType: pointerType,
4409 srcEvent: ev
4410 });
4411
4412 if (removePointer) {
4413 // remove from the store
4414 store.splice(storeIndex, 1);
4415 }
4416 };
4417
4418 return PointerEventInput;
4419}(Input);
4420/**
4421 * @private
4422 * convert array-like objects to real arrays
4423 * @param {Object} obj
4424 * @returns {Array}
4425 */
4426
4427
4428function toArray$1(obj) {
4429 return Array.prototype.slice.call(obj, 0);
4430}
4431/**
4432 * @private
4433 * unique array with objects based on a key (like 'id') or just by the array's value
4434 * @param {Array} src [{id:1},{id:2},{id:1}]
4435 * @param {String} [key]
4436 * @param {Boolean} [sort=False]
4437 * @returns {Array} [{id:1},{id:2}]
4438 */
4439
4440
4441function uniqueArray(src, key, sort) {
4442 var results = [];
4443 var values = [];
4444 var i = 0;
4445
4446 while (i < src.length) {
4447 var val = key ? src[i][key] : src[i];
4448
4449 if (inArray(values, val) < 0) {
4450 results.push(src[i]);
4451 }
4452
4453 values[i] = val;
4454 i++;
4455 }
4456
4457 if (sort) {
4458 if (!key) {
4459 results = results.sort();
4460 } else {
4461 results = results.sort(function (a, b) {
4462 return a[key] > b[key];
4463 });
4464 }
4465 }
4466
4467 return results;
4468}
4469
4470var TOUCH_INPUT_MAP = {
4471 touchstart: INPUT_START,
4472 touchmove: INPUT_MOVE,
4473 touchend: INPUT_END,
4474 touchcancel: INPUT_CANCEL
4475};
4476var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
4477/**
4478 * @private
4479 * Multi-user touch events input
4480 * @constructor
4481 * @extends Input
4482 */
4483
4484var TouchInput = /*#__PURE__*/function (_Input) {
4485 _inheritsLoose(TouchInput, _Input);
4486
4487 function TouchInput() {
4488 var _this;
4489
4490 TouchInput.prototype.evTarget = TOUCH_TARGET_EVENTS;
4491 _this = _Input.apply(this, arguments) || this;
4492 _this.targetIds = {}; // this.evTarget = TOUCH_TARGET_EVENTS;
4493
4494 return _this;
4495 }
4496
4497 var _proto = TouchInput.prototype;
4498
4499 _proto.handler = function handler(ev) {
4500 var type = TOUCH_INPUT_MAP[ev.type];
4501 var touches = getTouches.call(this, ev, type);
4502
4503 if (!touches) {
4504 return;
4505 }
4506
4507 this.callback(this.manager, type, {
4508 pointers: touches[0],
4509 changedPointers: touches[1],
4510 pointerType: INPUT_TYPE_TOUCH,
4511 srcEvent: ev
4512 });
4513 };
4514
4515 return TouchInput;
4516}(Input);
4517
4518function getTouches(ev, type) {
4519 var allTouches = toArray$1(ev.touches);
4520 var targetIds = this.targetIds; // when there is only one touch, the process can be simplified
4521
4522 if (type & (INPUT_START | INPUT_MOVE) && allTouches.length === 1) {
4523 targetIds[allTouches[0].identifier] = true;
4524 return [allTouches, allTouches];
4525 }
4526
4527 var i;
4528 var targetTouches;
4529 var changedTouches = toArray$1(ev.changedTouches);
4530 var changedTargetTouches = [];
4531 var target = this.target; // get target touches from touches
4532
4533 targetTouches = allTouches.filter(function (touch) {
4534 return hasParent$1(touch.target, target);
4535 }); // collect touches
4536
4537 if (type === INPUT_START) {
4538 i = 0;
4539
4540 while (i < targetTouches.length) {
4541 targetIds[targetTouches[i].identifier] = true;
4542 i++;
4543 }
4544 } // filter changed touches to only contain touches that exist in the collected target ids
4545
4546
4547 i = 0;
4548
4549 while (i < changedTouches.length) {
4550 if (targetIds[changedTouches[i].identifier]) {
4551 changedTargetTouches.push(changedTouches[i]);
4552 } // cleanup removed touches
4553
4554
4555 if (type & (INPUT_END | INPUT_CANCEL)) {
4556 delete targetIds[changedTouches[i].identifier];
4557 }
4558
4559 i++;
4560 }
4561
4562 if (!changedTargetTouches.length) {
4563 return;
4564 }
4565
4566 return [// merge targetTouches with changedTargetTouches so it contains ALL touches, including 'end' and 'cancel'
4567 uniqueArray(targetTouches.concat(changedTargetTouches), 'identifier', true), changedTargetTouches];
4568}
4569
4570var MOUSE_INPUT_MAP = {
4571 mousedown: INPUT_START,
4572 mousemove: INPUT_MOVE,
4573 mouseup: INPUT_END
4574};
4575var MOUSE_ELEMENT_EVENTS = 'mousedown';
4576var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
4577/**
4578 * @private
4579 * Mouse events input
4580 * @constructor
4581 * @extends Input
4582 */
4583
4584var MouseInput = /*#__PURE__*/function (_Input) {
4585 _inheritsLoose(MouseInput, _Input);
4586
4587 function MouseInput() {
4588 var _this;
4589
4590 var proto = MouseInput.prototype;
4591 proto.evEl = MOUSE_ELEMENT_EVENTS;
4592 proto.evWin = MOUSE_WINDOW_EVENTS;
4593 _this = _Input.apply(this, arguments) || this;
4594 _this.pressed = false; // mousedown state
4595
4596 return _this;
4597 }
4598 /**
4599 * @private
4600 * handle mouse events
4601 * @param {Object} ev
4602 */
4603
4604
4605 var _proto = MouseInput.prototype;
4606
4607 _proto.handler = function handler(ev) {
4608 var eventType = MOUSE_INPUT_MAP[ev.type]; // on start we want to have the left mouse button down
4609
4610 if (eventType & INPUT_START && ev.button === 0) {
4611 this.pressed = true;
4612 }
4613
4614 if (eventType & INPUT_MOVE && ev.which !== 1) {
4615 eventType = INPUT_END;
4616 } // mouse must be down
4617
4618
4619 if (!this.pressed) {
4620 return;
4621 }
4622
4623 if (eventType & INPUT_END) {
4624 this.pressed = false;
4625 }
4626
4627 this.callback(this.manager, eventType, {
4628 pointers: [ev],
4629 changedPointers: [ev],
4630 pointerType: INPUT_TYPE_MOUSE,
4631 srcEvent: ev
4632 });
4633 };
4634
4635 return MouseInput;
4636}(Input);
4637/**
4638 * @private
4639 * Combined touch and mouse input
4640 *
4641 * Touch has a higher priority then mouse, and while touching no mouse events are allowed.
4642 * This because touch devices also emit mouse events while doing a touch.
4643 *
4644 * @constructor
4645 * @extends Input
4646 */
4647
4648
4649var DEDUP_TIMEOUT = 2500;
4650var DEDUP_DISTANCE = 25;
4651
4652function setLastTouch(eventData) {
4653 var _eventData$changedPoi = eventData.changedPointers,
4654 touch = _eventData$changedPoi[0];
4655
4656 if (touch.identifier === this.primaryTouch) {
4657 var lastTouch = {
4658 x: touch.clientX,
4659 y: touch.clientY
4660 };
4661 var lts = this.lastTouches;
4662 this.lastTouches.push(lastTouch);
4663
4664 var removeLastTouch = function removeLastTouch() {
4665 var i = lts.indexOf(lastTouch);
4666
4667 if (i > -1) {
4668 lts.splice(i, 1);
4669 }
4670 };
4671
4672 setTimeout(removeLastTouch, DEDUP_TIMEOUT);
4673 }
4674}
4675
4676function recordTouches(eventType, eventData) {
4677 if (eventType & INPUT_START) {
4678 this.primaryTouch = eventData.changedPointers[0].identifier;
4679 setLastTouch.call(this, eventData);
4680 } else if (eventType & (INPUT_END | INPUT_CANCEL)) {
4681 setLastTouch.call(this, eventData);
4682 }
4683}
4684
4685function isSyntheticEvent(eventData) {
4686 var x = eventData.srcEvent.clientX;
4687 var y = eventData.srcEvent.clientY;
4688
4689 for (var i = 0; i < this.lastTouches.length; i++) {
4690 var t = this.lastTouches[i];
4691 var dx = Math.abs(x - t.x);
4692 var dy = Math.abs(y - t.y);
4693
4694 if (dx <= DEDUP_DISTANCE && dy <= DEDUP_DISTANCE) {
4695 return true;
4696 }
4697 }
4698
4699 return false;
4700}
4701
4702var TouchMouseInput = /*#__PURE__*/function () {
4703 var TouchMouseInput = /*#__PURE__*/function (_Input) {
4704 _inheritsLoose(TouchMouseInput, _Input);
4705
4706 function TouchMouseInput(_manager, callback) {
4707 var _this;
4708
4709 _this = _Input.call(this, _manager, callback) || this;
4710
4711 _this.handler = function (manager, inputEvent, inputData) {
4712 var isTouch = inputData.pointerType === INPUT_TYPE_TOUCH;
4713 var isMouse = inputData.pointerType === INPUT_TYPE_MOUSE;
4714
4715 if (isMouse && inputData.sourceCapabilities && inputData.sourceCapabilities.firesTouchEvents) {
4716 return;
4717 } // when we're in a touch event, record touches to de-dupe synthetic mouse event
4718
4719
4720 if (isTouch) {
4721 recordTouches.call(_assertThisInitialized$1(_assertThisInitialized$1(_this)), inputEvent, inputData);
4722 } else if (isMouse && isSyntheticEvent.call(_assertThisInitialized$1(_assertThisInitialized$1(_this)), inputData)) {
4723 return;
4724 }
4725
4726 _this.callback(manager, inputEvent, inputData);
4727 };
4728
4729 _this.touch = new TouchInput(_this.manager, _this.handler);
4730 _this.mouse = new MouseInput(_this.manager, _this.handler);
4731 _this.primaryTouch = null;
4732 _this.lastTouches = [];
4733 return _this;
4734 }
4735 /**
4736 * @private
4737 * handle mouse and touch events
4738 * @param {Hammer} manager
4739 * @param {String} inputEvent
4740 * @param {Object} inputData
4741 */
4742
4743
4744 var _proto = TouchMouseInput.prototype;
4745 /**
4746 * @private
4747 * remove the event listeners
4748 */
4749
4750 _proto.destroy = function destroy() {
4751 this.touch.destroy();
4752 this.mouse.destroy();
4753 };
4754
4755 return TouchMouseInput;
4756 }(Input);
4757
4758 return TouchMouseInput;
4759}();
4760/**
4761 * @private
4762 * create new input type manager
4763 * called by the Manager constructor
4764 * @param {Hammer} manager
4765 * @returns {Input}
4766 */
4767
4768
4769function createInputInstance(manager) {
4770 var Type; // let inputClass = manager.options.inputClass;
4771
4772 var inputClass = manager.options.inputClass;
4773
4774 if (inputClass) {
4775 Type = inputClass;
4776 } else if (SUPPORT_POINTER_EVENTS) {
4777 Type = PointerEventInput;
4778 } else if (SUPPORT_ONLY_TOUCH) {
4779 Type = TouchInput;
4780 } else if (!SUPPORT_TOUCH) {
4781 Type = MouseInput;
4782 } else {
4783 Type = TouchMouseInput;
4784 }
4785
4786 return new Type(manager, inputHandler);
4787}
4788/**
4789 * @private
4790 * if the argument is an array, we want to execute the fn on each entry
4791 * if it aint an array we don't want to do a thing.
4792 * this is used by all the methods that accept a single and array argument.
4793 * @param {*|Array} arg
4794 * @param {String} fn
4795 * @param {Object} [context]
4796 * @returns {Boolean}
4797 */
4798
4799
4800function invokeArrayArg(arg, fn, context) {
4801 if (Array.isArray(arg)) {
4802 each(arg, context[fn], context);
4803 return true;
4804 }
4805
4806 return false;
4807}
4808
4809var STATE_POSSIBLE = 1;
4810var STATE_BEGAN = 2;
4811var STATE_CHANGED = 4;
4812var STATE_ENDED = 8;
4813var STATE_RECOGNIZED = STATE_ENDED;
4814var STATE_CANCELLED = 16;
4815var STATE_FAILED = 32;
4816/**
4817 * @private
4818 * get a unique id
4819 * @returns {number} uniqueId
4820 */
4821
4822var _uniqueId = 1;
4823
4824function uniqueId() {
4825 return _uniqueId++;
4826}
4827/**
4828 * @private
4829 * get a recognizer by name if it is bound to a manager
4830 * @param {Recognizer|String} otherRecognizer
4831 * @param {Recognizer} recognizer
4832 * @returns {Recognizer}
4833 */
4834
4835
4836function getRecognizerByNameIfManager(otherRecognizer, recognizer) {
4837 var manager = recognizer.manager;
4838
4839 if (manager) {
4840 return manager.get(otherRecognizer);
4841 }
4842
4843 return otherRecognizer;
4844}
4845/**
4846 * @private
4847 * get a usable string, used as event postfix
4848 * @param {constant} state
4849 * @returns {String} state
4850 */
4851
4852
4853function stateStr(state) {
4854 if (state & STATE_CANCELLED) {
4855 return 'cancel';
4856 } else if (state & STATE_ENDED) {
4857 return 'end';
4858 } else if (state & STATE_CHANGED) {
4859 return 'move';
4860 } else if (state & STATE_BEGAN) {
4861 return 'start';
4862 }
4863
4864 return '';
4865}
4866/**
4867 * @private
4868 * Recognizer flow explained; *
4869 * All recognizers have the initial state of POSSIBLE when a input session starts.
4870 * The definition of a input session is from the first input until the last input, with all it's movement in it. *
4871 * Example session for mouse-input: mousedown -> mousemove -> mouseup
4872 *
4873 * On each recognizing cycle (see Manager.recognize) the .recognize() method is executed
4874 * which determines with state it should be.
4875 *
4876 * If the recognizer has the state FAILED, CANCELLED or RECOGNIZED (equals ENDED), it is reset to
4877 * POSSIBLE to give it another change on the next cycle.
4878 *
4879 * Possible
4880 * |
4881 * +-----+---------------+
4882 * | |
4883 * +-----+-----+ |
4884 * | | |
4885 * Failed Cancelled |
4886 * +-------+------+
4887 * | |
4888 * Recognized Began
4889 * |
4890 * Changed
4891 * |
4892 * Ended/Recognized
4893 */
4894
4895/**
4896 * @private
4897 * Recognizer
4898 * Every recognizer needs to extend from this class.
4899 * @constructor
4900 * @param {Object} options
4901 */
4902
4903
4904var Recognizer = /*#__PURE__*/function () {
4905 function Recognizer(options) {
4906 if (options === void 0) {
4907 options = {};
4908 }
4909
4910 this.options = _extends({
4911 enable: true
4912 }, options);
4913 this.id = uniqueId();
4914 this.manager = null; // default is enable true
4915
4916 this.state = STATE_POSSIBLE;
4917 this.simultaneous = {};
4918 this.requireFail = [];
4919 }
4920 /**
4921 * @private
4922 * set options
4923 * @param {Object} options
4924 * @return {Recognizer}
4925 */
4926
4927
4928 var _proto = Recognizer.prototype;
4929
4930 _proto.set = function set(options) {
4931 assign$1(this.options, options); // also update the touchAction, in case something changed about the directions/enabled state
4932
4933 this.manager && this.manager.touchAction.update();
4934 return this;
4935 };
4936 /**
4937 * @private
4938 * recognize simultaneous with an other recognizer.
4939 * @param {Recognizer} otherRecognizer
4940 * @returns {Recognizer} this
4941 */
4942
4943
4944 _proto.recognizeWith = function recognizeWith(otherRecognizer) {
4945 if (invokeArrayArg(otherRecognizer, 'recognizeWith', this)) {
4946 return this;
4947 }
4948
4949 var simultaneous = this.simultaneous;
4950 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
4951
4952 if (!simultaneous[otherRecognizer.id]) {
4953 simultaneous[otherRecognizer.id] = otherRecognizer;
4954 otherRecognizer.recognizeWith(this);
4955 }
4956
4957 return this;
4958 };
4959 /**
4960 * @private
4961 * drop the simultaneous link. it doesnt remove the link on the other recognizer.
4962 * @param {Recognizer} otherRecognizer
4963 * @returns {Recognizer} this
4964 */
4965
4966
4967 _proto.dropRecognizeWith = function dropRecognizeWith(otherRecognizer) {
4968 if (invokeArrayArg(otherRecognizer, 'dropRecognizeWith', this)) {
4969 return this;
4970 }
4971
4972 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
4973 delete this.simultaneous[otherRecognizer.id];
4974 return this;
4975 };
4976 /**
4977 * @private
4978 * recognizer can only run when an other is failing
4979 * @param {Recognizer} otherRecognizer
4980 * @returns {Recognizer} this
4981 */
4982
4983
4984 _proto.requireFailure = function requireFailure(otherRecognizer) {
4985 if (invokeArrayArg(otherRecognizer, 'requireFailure', this)) {
4986 return this;
4987 }
4988
4989 var requireFail = this.requireFail;
4990 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
4991
4992 if (inArray(requireFail, otherRecognizer) === -1) {
4993 requireFail.push(otherRecognizer);
4994 otherRecognizer.requireFailure(this);
4995 }
4996
4997 return this;
4998 };
4999 /**
5000 * @private
5001 * drop the requireFailure link. it does not remove the link on the other recognizer.
5002 * @param {Recognizer} otherRecognizer
5003 * @returns {Recognizer} this
5004 */
5005
5006
5007 _proto.dropRequireFailure = function dropRequireFailure(otherRecognizer) {
5008 if (invokeArrayArg(otherRecognizer, 'dropRequireFailure', this)) {
5009 return this;
5010 }
5011
5012 otherRecognizer = getRecognizerByNameIfManager(otherRecognizer, this);
5013 var index = inArray(this.requireFail, otherRecognizer);
5014
5015 if (index > -1) {
5016 this.requireFail.splice(index, 1);
5017 }
5018
5019 return this;
5020 };
5021 /**
5022 * @private
5023 * has require failures boolean
5024 * @returns {boolean}
5025 */
5026
5027
5028 _proto.hasRequireFailures = function hasRequireFailures() {
5029 return this.requireFail.length > 0;
5030 };
5031 /**
5032 * @private
5033 * if the recognizer can recognize simultaneous with an other recognizer
5034 * @param {Recognizer} otherRecognizer
5035 * @returns {Boolean}
5036 */
5037
5038
5039 _proto.canRecognizeWith = function canRecognizeWith(otherRecognizer) {
5040 return !!this.simultaneous[otherRecognizer.id];
5041 };
5042 /**
5043 * @private
5044 * You should use `tryEmit` instead of `emit` directly to check
5045 * that all the needed recognizers has failed before emitting.
5046 * @param {Object} input
5047 */
5048
5049
5050 _proto.emit = function emit(input) {
5051 var self = this;
5052 var state = this.state;
5053
5054 function emit(event) {
5055 self.manager.emit(event, input);
5056 } // 'panstart' and 'panmove'
5057
5058
5059 if (state < STATE_ENDED) {
5060 emit(self.options.event + stateStr(state));
5061 }
5062
5063 emit(self.options.event); // simple 'eventName' events
5064
5065 if (input.additionalEvent) {
5066 // additional event(panleft, panright, pinchin, pinchout...)
5067 emit(input.additionalEvent);
5068 } // panend and pancancel
5069
5070
5071 if (state >= STATE_ENDED) {
5072 emit(self.options.event + stateStr(state));
5073 }
5074 };
5075 /**
5076 * @private
5077 * Check that all the require failure recognizers has failed,
5078 * if true, it emits a gesture event,
5079 * otherwise, setup the state to FAILED.
5080 * @param {Object} input
5081 */
5082
5083
5084 _proto.tryEmit = function tryEmit(input) {
5085 if (this.canEmit()) {
5086 return this.emit(input);
5087 } // it's failing anyway
5088
5089
5090 this.state = STATE_FAILED;
5091 };
5092 /**
5093 * @private
5094 * can we emit?
5095 * @returns {boolean}
5096 */
5097
5098
5099 _proto.canEmit = function canEmit() {
5100 var i = 0;
5101
5102 while (i < this.requireFail.length) {
5103 if (!(this.requireFail[i].state & (STATE_FAILED | STATE_POSSIBLE))) {
5104 return false;
5105 }
5106
5107 i++;
5108 }
5109
5110 return true;
5111 };
5112 /**
5113 * @private
5114 * update the recognizer
5115 * @param {Object} inputData
5116 */
5117
5118
5119 _proto.recognize = function recognize(inputData) {
5120 // make a new copy of the inputData
5121 // so we can change the inputData without messing up the other recognizers
5122 var inputDataClone = assign$1({}, inputData); // is is enabled and allow recognizing?
5123
5124 if (!boolOrFn(this.options.enable, [this, inputDataClone])) {
5125 this.reset();
5126 this.state = STATE_FAILED;
5127 return;
5128 } // reset when we've reached the end
5129
5130
5131 if (this.state & (STATE_RECOGNIZED | STATE_CANCELLED | STATE_FAILED)) {
5132 this.state = STATE_POSSIBLE;
5133 }
5134
5135 this.state = this.process(inputDataClone); // the recognizer has recognized a gesture
5136 // so trigger an event
5137
5138 if (this.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED | STATE_CANCELLED)) {
5139 this.tryEmit(inputDataClone);
5140 }
5141 };
5142 /**
5143 * @private
5144 * return the state of the recognizer
5145 * the actual recognizing happens in this method
5146 * @virtual
5147 * @param {Object} inputData
5148 * @returns {constant} STATE
5149 */
5150
5151 /* jshint ignore:start */
5152
5153
5154 _proto.process = function process(inputData) {};
5155 /* jshint ignore:end */
5156
5157 /**
5158 * @private
5159 * return the preferred touch-action
5160 * @virtual
5161 * @returns {Array}
5162 */
5163
5164
5165 _proto.getTouchAction = function getTouchAction() {};
5166 /**
5167 * @private
5168 * called when the gesture isn't allowed to recognize
5169 * like when another is being recognized or it is disabled
5170 * @virtual
5171 */
5172
5173
5174 _proto.reset = function reset() {};
5175
5176 return Recognizer;
5177}();
5178/**
5179 * @private
5180 * A tap is recognized when the pointer is doing a small tap/click. Multiple taps are recognized if they occur
5181 * between the given interval and position. The delay option can be used to recognize multi-taps without firing
5182 * a single tap.
5183 *
5184 * The eventData from the emitted event contains the property `tapCount`, which contains the amount of
5185 * multi-taps being recognized.
5186 * @constructor
5187 * @extends Recognizer
5188 */
5189
5190
5191var TapRecognizer = /*#__PURE__*/function (_Recognizer) {
5192 _inheritsLoose(TapRecognizer, _Recognizer);
5193
5194 function TapRecognizer(options) {
5195 var _this;
5196
5197 if (options === void 0) {
5198 options = {};
5199 }
5200
5201 _this = _Recognizer.call(this, _extends({
5202 event: 'tap',
5203 pointers: 1,
5204 taps: 1,
5205 interval: 300,
5206 // max time between the multi-tap taps
5207 time: 250,
5208 // max time of the pointer to be down (like finger on the screen)
5209 threshold: 9,
5210 // a minimal movement is ok, but keep it low
5211 posThreshold: 10
5212 }, options)) || this; // previous time and center,
5213 // used for tap counting
5214
5215 _this.pTime = false;
5216 _this.pCenter = false;
5217 _this._timer = null;
5218 _this._input = null;
5219 _this.count = 0;
5220 return _this;
5221 }
5222
5223 var _proto = TapRecognizer.prototype;
5224
5225 _proto.getTouchAction = function getTouchAction() {
5226 return [TOUCH_ACTION_MANIPULATION];
5227 };
5228
5229 _proto.process = function process(input) {
5230 var _this2 = this;
5231
5232 var options = this.options;
5233 var validPointers = input.pointers.length === options.pointers;
5234 var validMovement = input.distance < options.threshold;
5235 var validTouchTime = input.deltaTime < options.time;
5236 this.reset();
5237
5238 if (input.eventType & INPUT_START && this.count === 0) {
5239 return this.failTimeout();
5240 } // we only allow little movement
5241 // and we've reached an end event, so a tap is possible
5242
5243
5244 if (validMovement && validTouchTime && validPointers) {
5245 if (input.eventType !== INPUT_END) {
5246 return this.failTimeout();
5247 }
5248
5249 var validInterval = this.pTime ? input.timeStamp - this.pTime < options.interval : true;
5250 var validMultiTap = !this.pCenter || getDistance(this.pCenter, input.center) < options.posThreshold;
5251 this.pTime = input.timeStamp;
5252 this.pCenter = input.center;
5253
5254 if (!validMultiTap || !validInterval) {
5255 this.count = 1;
5256 } else {
5257 this.count += 1;
5258 }
5259
5260 this._input = input; // if tap count matches we have recognized it,
5261 // else it has began recognizing...
5262
5263 var tapCount = this.count % options.taps;
5264
5265 if (tapCount === 0) {
5266 // no failing requirements, immediately trigger the tap event
5267 // or wait as long as the multitap interval to trigger
5268 if (!this.hasRequireFailures()) {
5269 return STATE_RECOGNIZED;
5270 } else {
5271 this._timer = setTimeout(function () {
5272 _this2.state = STATE_RECOGNIZED;
5273
5274 _this2.tryEmit();
5275 }, options.interval);
5276 return STATE_BEGAN;
5277 }
5278 }
5279 }
5280
5281 return STATE_FAILED;
5282 };
5283
5284 _proto.failTimeout = function failTimeout() {
5285 var _this3 = this;
5286
5287 this._timer = setTimeout(function () {
5288 _this3.state = STATE_FAILED;
5289 }, this.options.interval);
5290 return STATE_FAILED;
5291 };
5292
5293 _proto.reset = function reset() {
5294 clearTimeout(this._timer);
5295 };
5296
5297 _proto.emit = function emit() {
5298 if (this.state === STATE_RECOGNIZED) {
5299 this._input.tapCount = this.count;
5300 this.manager.emit(this.options.event, this._input);
5301 }
5302 };
5303
5304 return TapRecognizer;
5305}(Recognizer);
5306/**
5307 * @private
5308 * This recognizer is just used as a base for the simple attribute recognizers.
5309 * @constructor
5310 * @extends Recognizer
5311 */
5312
5313
5314var AttrRecognizer = /*#__PURE__*/function (_Recognizer) {
5315 _inheritsLoose(AttrRecognizer, _Recognizer);
5316
5317 function AttrRecognizer(options) {
5318 if (options === void 0) {
5319 options = {};
5320 }
5321
5322 return _Recognizer.call(this, _extends({
5323 pointers: 1
5324 }, options)) || this;
5325 }
5326 /**
5327 * @private
5328 * Used to check if it the recognizer receives valid input, like input.distance > 10.
5329 * @memberof AttrRecognizer
5330 * @param {Object} input
5331 * @returns {Boolean} recognized
5332 */
5333
5334
5335 var _proto = AttrRecognizer.prototype;
5336
5337 _proto.attrTest = function attrTest(input) {
5338 var optionPointers = this.options.pointers;
5339 return optionPointers === 0 || input.pointers.length === optionPointers;
5340 };
5341 /**
5342 * @private
5343 * Process the input and return the state for the recognizer
5344 * @memberof AttrRecognizer
5345 * @param {Object} input
5346 * @returns {*} State
5347 */
5348
5349
5350 _proto.process = function process(input) {
5351 var state = this.state;
5352 var eventType = input.eventType;
5353 var isRecognized = state & (STATE_BEGAN | STATE_CHANGED);
5354 var isValid = this.attrTest(input); // on cancel input and we've recognized before, return STATE_CANCELLED
5355
5356 if (isRecognized && (eventType & INPUT_CANCEL || !isValid)) {
5357 return state | STATE_CANCELLED;
5358 } else if (isRecognized || isValid) {
5359 if (eventType & INPUT_END) {
5360 return state | STATE_ENDED;
5361 } else if (!(state & STATE_BEGAN)) {
5362 return STATE_BEGAN;
5363 }
5364
5365 return state | STATE_CHANGED;
5366 }
5367
5368 return STATE_FAILED;
5369 };
5370
5371 return AttrRecognizer;
5372}(Recognizer);
5373/**
5374 * @private
5375 * direction cons to string
5376 * @param {constant} direction
5377 * @returns {String}
5378 */
5379
5380
5381function directionStr(direction) {
5382 if (direction === DIRECTION_DOWN) {
5383 return 'down';
5384 } else if (direction === DIRECTION_UP) {
5385 return 'up';
5386 } else if (direction === DIRECTION_LEFT) {
5387 return 'left';
5388 } else if (direction === DIRECTION_RIGHT) {
5389 return 'right';
5390 }
5391
5392 return '';
5393}
5394/**
5395 * @private
5396 * Pan
5397 * Recognized when the pointer is down and moved in the allowed direction.
5398 * @constructor
5399 * @extends AttrRecognizer
5400 */
5401
5402
5403var PanRecognizer = /*#__PURE__*/function (_AttrRecognizer) {
5404 _inheritsLoose(PanRecognizer, _AttrRecognizer);
5405
5406 function PanRecognizer(options) {
5407 var _this;
5408
5409 if (options === void 0) {
5410 options = {};
5411 }
5412
5413 _this = _AttrRecognizer.call(this, _extends({
5414 event: 'pan',
5415 threshold: 10,
5416 pointers: 1,
5417 direction: DIRECTION_ALL
5418 }, options)) || this;
5419 _this.pX = null;
5420 _this.pY = null;
5421 return _this;
5422 }
5423
5424 var _proto = PanRecognizer.prototype;
5425
5426 _proto.getTouchAction = function getTouchAction() {
5427 var direction = this.options.direction;
5428 var actions = [];
5429
5430 if (direction & DIRECTION_HORIZONTAL) {
5431 actions.push(TOUCH_ACTION_PAN_Y);
5432 }
5433
5434 if (direction & DIRECTION_VERTICAL) {
5435 actions.push(TOUCH_ACTION_PAN_X);
5436 }
5437
5438 return actions;
5439 };
5440
5441 _proto.directionTest = function directionTest(input) {
5442 var options = this.options;
5443 var hasMoved = true;
5444 var distance = input.distance;
5445 var direction = input.direction;
5446 var x = input.deltaX;
5447 var y = input.deltaY; // lock to axis?
5448
5449 if (!(direction & options.direction)) {
5450 if (options.direction & DIRECTION_HORIZONTAL) {
5451 direction = x === 0 ? DIRECTION_NONE : x < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT;
5452 hasMoved = x !== this.pX;
5453 distance = Math.abs(input.deltaX);
5454 } else {
5455 direction = y === 0 ? DIRECTION_NONE : y < 0 ? DIRECTION_UP : DIRECTION_DOWN;
5456 hasMoved = y !== this.pY;
5457 distance = Math.abs(input.deltaY);
5458 }
5459 }
5460
5461 input.direction = direction;
5462 return hasMoved && distance > options.threshold && direction & options.direction;
5463 };
5464
5465 _proto.attrTest = function attrTest(input) {
5466 return AttrRecognizer.prototype.attrTest.call(this, input) && ( // replace with a super call
5467 this.state & STATE_BEGAN || !(this.state & STATE_BEGAN) && this.directionTest(input));
5468 };
5469
5470 _proto.emit = function emit(input) {
5471 this.pX = input.deltaX;
5472 this.pY = input.deltaY;
5473 var direction = directionStr(input.direction);
5474
5475 if (direction) {
5476 input.additionalEvent = this.options.event + direction;
5477 }
5478
5479 _AttrRecognizer.prototype.emit.call(this, input);
5480 };
5481
5482 return PanRecognizer;
5483}(AttrRecognizer);
5484/**
5485 * @private
5486 * Swipe
5487 * Recognized when the pointer is moving fast (velocity), with enough distance in the allowed direction.
5488 * @constructor
5489 * @extends AttrRecognizer
5490 */
5491
5492
5493var SwipeRecognizer = /*#__PURE__*/function (_AttrRecognizer) {
5494 _inheritsLoose(SwipeRecognizer, _AttrRecognizer);
5495
5496 function SwipeRecognizer(options) {
5497 if (options === void 0) {
5498 options = {};
5499 }
5500
5501 return _AttrRecognizer.call(this, _extends({
5502 event: 'swipe',
5503 threshold: 10,
5504 velocity: 0.3,
5505 direction: DIRECTION_HORIZONTAL | DIRECTION_VERTICAL,
5506 pointers: 1
5507 }, options)) || this;
5508 }
5509
5510 var _proto = SwipeRecognizer.prototype;
5511
5512 _proto.getTouchAction = function getTouchAction() {
5513 return PanRecognizer.prototype.getTouchAction.call(this);
5514 };
5515
5516 _proto.attrTest = function attrTest(input) {
5517 var direction = this.options.direction;
5518 var velocity;
5519
5520 if (direction & (DIRECTION_HORIZONTAL | DIRECTION_VERTICAL)) {
5521 velocity = input.overallVelocity;
5522 } else if (direction & DIRECTION_HORIZONTAL) {
5523 velocity = input.overallVelocityX;
5524 } else if (direction & DIRECTION_VERTICAL) {
5525 velocity = input.overallVelocityY;
5526 }
5527
5528 return _AttrRecognizer.prototype.attrTest.call(this, input) && direction & input.offsetDirection && input.distance > this.options.threshold && input.maxPointers === this.options.pointers && abs(velocity) > this.options.velocity && input.eventType & INPUT_END;
5529 };
5530
5531 _proto.emit = function emit(input) {
5532 var direction = directionStr(input.offsetDirection);
5533
5534 if (direction) {
5535 this.manager.emit(this.options.event + direction, input);
5536 }
5537
5538 this.manager.emit(this.options.event, input);
5539 };
5540
5541 return SwipeRecognizer;
5542}(AttrRecognizer);
5543/**
5544 * @private
5545 * Pinch
5546 * Recognized when two or more pointers are moving toward (zoom-in) or away from each other (zoom-out).
5547 * @constructor
5548 * @extends AttrRecognizer
5549 */
5550
5551
5552var PinchRecognizer = /*#__PURE__*/function (_AttrRecognizer) {
5553 _inheritsLoose(PinchRecognizer, _AttrRecognizer);
5554
5555 function PinchRecognizer(options) {
5556 if (options === void 0) {
5557 options = {};
5558 }
5559
5560 return _AttrRecognizer.call(this, _extends({
5561 event: 'pinch',
5562 threshold: 0,
5563 pointers: 2
5564 }, options)) || this;
5565 }
5566
5567 var _proto = PinchRecognizer.prototype;
5568
5569 _proto.getTouchAction = function getTouchAction() {
5570 return [TOUCH_ACTION_NONE];
5571 };
5572
5573 _proto.attrTest = function attrTest(input) {
5574 return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.scale - 1) > this.options.threshold || this.state & STATE_BEGAN);
5575 };
5576
5577 _proto.emit = function emit(input) {
5578 if (input.scale !== 1) {
5579 var inOut = input.scale < 1 ? 'in' : 'out';
5580 input.additionalEvent = this.options.event + inOut;
5581 }
5582
5583 _AttrRecognizer.prototype.emit.call(this, input);
5584 };
5585
5586 return PinchRecognizer;
5587}(AttrRecognizer);
5588/**
5589 * @private
5590 * Rotate
5591 * Recognized when two or more pointer are moving in a circular motion.
5592 * @constructor
5593 * @extends AttrRecognizer
5594 */
5595
5596
5597var RotateRecognizer = /*#__PURE__*/function (_AttrRecognizer) {
5598 _inheritsLoose(RotateRecognizer, _AttrRecognizer);
5599
5600 function RotateRecognizer(options) {
5601 if (options === void 0) {
5602 options = {};
5603 }
5604
5605 return _AttrRecognizer.call(this, _extends({
5606 event: 'rotate',
5607 threshold: 0,
5608 pointers: 2
5609 }, options)) || this;
5610 }
5611
5612 var _proto = RotateRecognizer.prototype;
5613
5614 _proto.getTouchAction = function getTouchAction() {
5615 return [TOUCH_ACTION_NONE];
5616 };
5617
5618 _proto.attrTest = function attrTest(input) {
5619 return _AttrRecognizer.prototype.attrTest.call(this, input) && (Math.abs(input.rotation) > this.options.threshold || this.state & STATE_BEGAN);
5620 };
5621
5622 return RotateRecognizer;
5623}(AttrRecognizer);
5624/**
5625 * @private
5626 * Press
5627 * Recognized when the pointer is down for x ms without any movement.
5628 * @constructor
5629 * @extends Recognizer
5630 */
5631
5632
5633var PressRecognizer = /*#__PURE__*/function (_Recognizer) {
5634 _inheritsLoose(PressRecognizer, _Recognizer);
5635
5636 function PressRecognizer(options) {
5637 var _this;
5638
5639 if (options === void 0) {
5640 options = {};
5641 }
5642
5643 _this = _Recognizer.call(this, _extends({
5644 event: 'press',
5645 pointers: 1,
5646 time: 251,
5647 // minimal time of the pointer to be pressed
5648 threshold: 9
5649 }, options)) || this;
5650 _this._timer = null;
5651 _this._input = null;
5652 return _this;
5653 }
5654
5655 var _proto = PressRecognizer.prototype;
5656
5657 _proto.getTouchAction = function getTouchAction() {
5658 return [TOUCH_ACTION_AUTO];
5659 };
5660
5661 _proto.process = function process(input) {
5662 var _this2 = this;
5663
5664 var options = this.options;
5665 var validPointers = input.pointers.length === options.pointers;
5666 var validMovement = input.distance < options.threshold;
5667 var validTime = input.deltaTime > options.time;
5668 this._input = input; // we only allow little movement
5669 // and we've reached an end event, so a tap is possible
5670
5671 if (!validMovement || !validPointers || input.eventType & (INPUT_END | INPUT_CANCEL) && !validTime) {
5672 this.reset();
5673 } else if (input.eventType & INPUT_START) {
5674 this.reset();
5675 this._timer = setTimeout(function () {
5676 _this2.state = STATE_RECOGNIZED;
5677
5678 _this2.tryEmit();
5679 }, options.time);
5680 } else if (input.eventType & INPUT_END) {
5681 return STATE_RECOGNIZED;
5682 }
5683
5684 return STATE_FAILED;
5685 };
5686
5687 _proto.reset = function reset() {
5688 clearTimeout(this._timer);
5689 };
5690
5691 _proto.emit = function emit(input) {
5692 if (this.state !== STATE_RECOGNIZED) {
5693 return;
5694 }
5695
5696 if (input && input.eventType & INPUT_END) {
5697 this.manager.emit(this.options.event + "up", input);
5698 } else {
5699 this._input.timeStamp = now();
5700 this.manager.emit(this.options.event, this._input);
5701 }
5702 };
5703
5704 return PressRecognizer;
5705}(Recognizer);
5706
5707var defaults = {
5708 /**
5709 * @private
5710 * set if DOM events are being triggered.
5711 * But this is slower and unused by simple implementations, so disabled by default.
5712 * @type {Boolean}
5713 * @default false
5714 */
5715 domEvents: false,
5716
5717 /**
5718 * @private
5719 * The value for the touchAction property/fallback.
5720 * When set to `compute` it will magically set the correct value based on the added recognizers.
5721 * @type {String}
5722 * @default compute
5723 */
5724 touchAction: TOUCH_ACTION_COMPUTE,
5725
5726 /**
5727 * @private
5728 * @type {Boolean}
5729 * @default true
5730 */
5731 enable: true,
5732
5733 /**
5734 * @private
5735 * EXPERIMENTAL FEATURE -- can be removed/changed
5736 * Change the parent input target element.
5737 * If Null, then it is being set the to main element.
5738 * @type {Null|EventTarget}
5739 * @default null
5740 */
5741 inputTarget: null,
5742
5743 /**
5744 * @private
5745 * force an input class
5746 * @type {Null|Function}
5747 * @default null
5748 */
5749 inputClass: null,
5750
5751 /**
5752 * @private
5753 * Some CSS properties can be used to improve the working of Hammer.
5754 * Add them to this method and they will be set when creating a new Manager.
5755 * @namespace
5756 */
5757 cssProps: {
5758 /**
5759 * @private
5760 * Disables text selection to improve the dragging gesture. Mainly for desktop browsers.
5761 * @type {String}
5762 * @default 'none'
5763 */
5764 userSelect: "none",
5765
5766 /**
5767 * @private
5768 * Disable the Windows Phone grippers when pressing an element.
5769 * @type {String}
5770 * @default 'none'
5771 */
5772 touchSelect: "none",
5773
5774 /**
5775 * @private
5776 * Disables the default callout shown when you touch and hold a touch target.
5777 * On iOS, when you touch and hold a touch target such as a link, Safari displays
5778 * a callout containing information about the link. This property allows you to disable that callout.
5779 * @type {String}
5780 * @default 'none'
5781 */
5782 touchCallout: "none",
5783
5784 /**
5785 * @private
5786 * Specifies whether zooming is enabled. Used by IE10>
5787 * @type {String}
5788 * @default 'none'
5789 */
5790 contentZooming: "none",
5791
5792 /**
5793 * @private
5794 * Specifies that an entire element should be draggable instead of its contents. Mainly for desktop browsers.
5795 * @type {String}
5796 * @default 'none'
5797 */
5798 userDrag: "none",
5799
5800 /**
5801 * @private
5802 * Overrides the highlight color shown when the user taps a link or a JavaScript
5803 * clickable element in iOS. This property obeys the alpha value, if specified.
5804 * @type {String}
5805 * @default 'rgba(0,0,0,0)'
5806 */
5807 tapHighlightColor: "rgba(0,0,0,0)"
5808 }
5809};
5810/**
5811 * @private
5812 * Default recognizer setup when calling `Hammer()`
5813 * When creating a new Manager these will be skipped.
5814 * This is separated with other defaults because of tree-shaking.
5815 * @type {Array}
5816 */
5817
5818var preset = [[RotateRecognizer, {
5819 enable: false
5820}], [PinchRecognizer, {
5821 enable: false
5822}, ['rotate']], [SwipeRecognizer, {
5823 direction: DIRECTION_HORIZONTAL
5824}], [PanRecognizer, {
5825 direction: DIRECTION_HORIZONTAL
5826}, ['swipe']], [TapRecognizer], [TapRecognizer, {
5827 event: 'doubletap',
5828 taps: 2
5829}, ['tap']], [PressRecognizer]];
5830var STOP = 1;
5831var FORCED_STOP = 2;
5832/**
5833 * @private
5834 * add/remove the css properties as defined in manager.options.cssProps
5835 * @param {Manager} manager
5836 * @param {Boolean} add
5837 */
5838
5839function toggleCssProps(manager, add) {
5840 var element = manager.element;
5841
5842 if (!element.style) {
5843 return;
5844 }
5845
5846 var prop;
5847 each(manager.options.cssProps, function (value, name) {
5848 prop = prefixed(element.style, name);
5849
5850 if (add) {
5851 manager.oldCssProps[prop] = element.style[prop];
5852 element.style[prop] = value;
5853 } else {
5854 element.style[prop] = manager.oldCssProps[prop] || "";
5855 }
5856 });
5857
5858 if (!add) {
5859 manager.oldCssProps = {};
5860 }
5861}
5862/**
5863 * @private
5864 * trigger dom event
5865 * @param {String} event
5866 * @param {Object} data
5867 */
5868
5869
5870function triggerDomEvent(event, data) {
5871 var gestureEvent = document.createEvent("Event");
5872 gestureEvent.initEvent(event, true, true);
5873 gestureEvent.gesture = data;
5874 data.target.dispatchEvent(gestureEvent);
5875}
5876/**
5877* @private
5878 * Manager
5879 * @param {HTMLElement} element
5880 * @param {Object} [options]
5881 * @constructor
5882 */
5883
5884
5885var Manager = /*#__PURE__*/function () {
5886 function Manager(element, options) {
5887 var _this = this;
5888
5889 this.options = assign$1({}, defaults, options || {});
5890 this.options.inputTarget = this.options.inputTarget || element;
5891 this.handlers = {};
5892 this.session = {};
5893 this.recognizers = [];
5894 this.oldCssProps = {};
5895 this.element = element;
5896 this.input = createInputInstance(this);
5897 this.touchAction = new TouchAction(this, this.options.touchAction);
5898 toggleCssProps(this, true);
5899 each(this.options.recognizers, function (item) {
5900 var recognizer = _this.add(new item[0](item[1]));
5901
5902 item[2] && recognizer.recognizeWith(item[2]);
5903 item[3] && recognizer.requireFailure(item[3]);
5904 }, this);
5905 }
5906 /**
5907 * @private
5908 * set options
5909 * @param {Object} options
5910 * @returns {Manager}
5911 */
5912
5913
5914 var _proto = Manager.prototype;
5915
5916 _proto.set = function set(options) {
5917 assign$1(this.options, options); // Options that need a little more setup
5918
5919 if (options.touchAction) {
5920 this.touchAction.update();
5921 }
5922
5923 if (options.inputTarget) {
5924 // Clean up existing event listeners and reinitialize
5925 this.input.destroy();
5926 this.input.target = options.inputTarget;
5927 this.input.init();
5928 }
5929
5930 return this;
5931 };
5932 /**
5933 * @private
5934 * stop recognizing for this session.
5935 * This session will be discarded, when a new [input]start event is fired.
5936 * When forced, the recognizer cycle is stopped immediately.
5937 * @param {Boolean} [force]
5938 */
5939
5940
5941 _proto.stop = function stop(force) {
5942 this.session.stopped = force ? FORCED_STOP : STOP;
5943 };
5944 /**
5945 * @private
5946 * run the recognizers!
5947 * called by the inputHandler function on every movement of the pointers (touches)
5948 * it walks through all the recognizers and tries to detect the gesture that is being made
5949 * @param {Object} inputData
5950 */
5951
5952
5953 _proto.recognize = function recognize(inputData) {
5954 var session = this.session;
5955
5956 if (session.stopped) {
5957 return;
5958 } // run the touch-action polyfill
5959
5960
5961 this.touchAction.preventDefaults(inputData);
5962 var recognizer;
5963 var recognizers = this.recognizers; // this holds the recognizer that is being recognized.
5964 // so the recognizer's state needs to be BEGAN, CHANGED, ENDED or RECOGNIZED
5965 // if no recognizer is detecting a thing, it is set to `null`
5966
5967 var curRecognizer = session.curRecognizer; // reset when the last recognizer is recognized
5968 // or when we're in a new session
5969
5970 if (!curRecognizer || curRecognizer && curRecognizer.state & STATE_RECOGNIZED) {
5971 session.curRecognizer = null;
5972 curRecognizer = null;
5973 }
5974
5975 var i = 0;
5976
5977 while (i < recognizers.length) {
5978 recognizer = recognizers[i]; // find out if we are allowed try to recognize the input for this one.
5979 // 1. allow if the session is NOT forced stopped (see the .stop() method)
5980 // 2. allow if we still haven't recognized a gesture in this session, or the this recognizer is the one
5981 // that is being recognized.
5982 // 3. allow if the recognizer is allowed to run simultaneous with the current recognized recognizer.
5983 // this can be setup with the `recognizeWith()` method on the recognizer.
5984
5985 if (session.stopped !== FORCED_STOP && ( // 1
5986 !curRecognizer || recognizer === curRecognizer || // 2
5987 recognizer.canRecognizeWith(curRecognizer))) {
5988 // 3
5989 recognizer.recognize(inputData);
5990 } else {
5991 recognizer.reset();
5992 } // if the recognizer has been recognizing the input as a valid gesture, we want to store this one as the
5993 // current active recognizer. but only if we don't already have an active recognizer
5994
5995
5996 if (!curRecognizer && recognizer.state & (STATE_BEGAN | STATE_CHANGED | STATE_ENDED)) {
5997 session.curRecognizer = recognizer;
5998 curRecognizer = recognizer;
5999 }
6000
6001 i++;
6002 }
6003 };
6004 /**
6005 * @private
6006 * get a recognizer by its event name.
6007 * @param {Recognizer|String} recognizer
6008 * @returns {Recognizer|Null}
6009 */
6010
6011
6012 _proto.get = function get(recognizer) {
6013 if (recognizer instanceof Recognizer) {
6014 return recognizer;
6015 }
6016
6017 var recognizers = this.recognizers;
6018
6019 for (var i = 0; i < recognizers.length; i++) {
6020 if (recognizers[i].options.event === recognizer) {
6021 return recognizers[i];
6022 }
6023 }
6024
6025 return null;
6026 };
6027 /**
6028 * @private add a recognizer to the manager
6029 * existing recognizers with the same event name will be removed
6030 * @param {Recognizer} recognizer
6031 * @returns {Recognizer|Manager}
6032 */
6033
6034
6035 _proto.add = function add(recognizer) {
6036 if (invokeArrayArg(recognizer, "add", this)) {
6037 return this;
6038 } // remove existing
6039
6040
6041 var existing = this.get(recognizer.options.event);
6042
6043 if (existing) {
6044 this.remove(existing);
6045 }
6046
6047 this.recognizers.push(recognizer);
6048 recognizer.manager = this;
6049 this.touchAction.update();
6050 return recognizer;
6051 };
6052 /**
6053 * @private
6054 * remove a recognizer by name or instance
6055 * @param {Recognizer|String} recognizer
6056 * @returns {Manager}
6057 */
6058
6059
6060 _proto.remove = function remove(recognizer) {
6061 if (invokeArrayArg(recognizer, "remove", this)) {
6062 return this;
6063 }
6064
6065 var targetRecognizer = this.get(recognizer); // let's make sure this recognizer exists
6066
6067 if (recognizer) {
6068 var recognizers = this.recognizers;
6069 var index = inArray(recognizers, targetRecognizer);
6070
6071 if (index !== -1) {
6072 recognizers.splice(index, 1);
6073 this.touchAction.update();
6074 }
6075 }
6076
6077 return this;
6078 };
6079 /**
6080 * @private
6081 * bind event
6082 * @param {String} events
6083 * @param {Function} handler
6084 * @returns {EventEmitter} this
6085 */
6086
6087
6088 _proto.on = function on(events, handler) {
6089 if (events === undefined || handler === undefined) {
6090 return this;
6091 }
6092
6093 var handlers = this.handlers;
6094 each(splitStr(events), function (event) {
6095 handlers[event] = handlers[event] || [];
6096 handlers[event].push(handler);
6097 });
6098 return this;
6099 };
6100 /**
6101 * @private unbind event, leave emit blank to remove all handlers
6102 * @param {String} events
6103 * @param {Function} [handler]
6104 * @returns {EventEmitter} this
6105 */
6106
6107
6108 _proto.off = function off(events, handler) {
6109 if (events === undefined) {
6110 return this;
6111 }
6112
6113 var handlers = this.handlers;
6114 each(splitStr(events), function (event) {
6115 if (!handler) {
6116 delete handlers[event];
6117 } else {
6118 handlers[event] && handlers[event].splice(inArray(handlers[event], handler), 1);
6119 }
6120 });
6121 return this;
6122 };
6123 /**
6124 * @private emit event to the listeners
6125 * @param {String} event
6126 * @param {Object} data
6127 */
6128
6129
6130 _proto.emit = function emit(event, data) {
6131 // we also want to trigger dom events
6132 if (this.options.domEvents) {
6133 triggerDomEvent(event, data);
6134 } // no handlers, so skip it all
6135
6136
6137 var handlers = this.handlers[event] && this.handlers[event].slice();
6138
6139 if (!handlers || !handlers.length) {
6140 return;
6141 }
6142
6143 data.type = event;
6144
6145 data.preventDefault = function () {
6146 data.srcEvent.preventDefault();
6147 };
6148
6149 var i = 0;
6150
6151 while (i < handlers.length) {
6152 handlers[i](data);
6153 i++;
6154 }
6155 };
6156 /**
6157 * @private
6158 * destroy the manager and unbinds all events
6159 * it doesn't unbind dom events, that is the user own responsibility
6160 */
6161
6162
6163 _proto.destroy = function destroy() {
6164 this.element && toggleCssProps(this, false);
6165 this.handlers = {};
6166 this.session = {};
6167 this.input.destroy();
6168 this.element = null;
6169 };
6170
6171 return Manager;
6172}();
6173
6174var SINGLE_TOUCH_INPUT_MAP = {
6175 touchstart: INPUT_START,
6176 touchmove: INPUT_MOVE,
6177 touchend: INPUT_END,
6178 touchcancel: INPUT_CANCEL
6179};
6180var SINGLE_TOUCH_TARGET_EVENTS = 'touchstart';
6181var SINGLE_TOUCH_WINDOW_EVENTS = 'touchstart touchmove touchend touchcancel';
6182/**
6183 * @private
6184 * Touch events input
6185 * @constructor
6186 * @extends Input
6187 */
6188
6189var SingleTouchInput = /*#__PURE__*/function (_Input) {
6190 _inheritsLoose(SingleTouchInput, _Input);
6191
6192 function SingleTouchInput() {
6193 var _this;
6194
6195 var proto = SingleTouchInput.prototype;
6196 proto.evTarget = SINGLE_TOUCH_TARGET_EVENTS;
6197 proto.evWin = SINGLE_TOUCH_WINDOW_EVENTS;
6198 _this = _Input.apply(this, arguments) || this;
6199 _this.started = false;
6200 return _this;
6201 }
6202
6203 var _proto = SingleTouchInput.prototype;
6204
6205 _proto.handler = function handler(ev) {
6206 var type = SINGLE_TOUCH_INPUT_MAP[ev.type]; // should we handle the touch events?
6207
6208 if (type === INPUT_START) {
6209 this.started = true;
6210 }
6211
6212 if (!this.started) {
6213 return;
6214 }
6215
6216 var touches = normalizeSingleTouches.call(this, ev, type); // when done, reset the started state
6217
6218 if (type & (INPUT_END | INPUT_CANCEL) && touches[0].length - touches[1].length === 0) {
6219 this.started = false;
6220 }
6221
6222 this.callback(this.manager, type, {
6223 pointers: touches[0],
6224 changedPointers: touches[1],
6225 pointerType: INPUT_TYPE_TOUCH,
6226 srcEvent: ev
6227 });
6228 };
6229
6230 return SingleTouchInput;
6231}(Input);
6232
6233function normalizeSingleTouches(ev, type) {
6234 var all = toArray$1(ev.touches);
6235 var changed = toArray$1(ev.changedTouches);
6236
6237 if (type & (INPUT_END | INPUT_CANCEL)) {
6238 all = uniqueArray(all.concat(changed), 'identifier', true);
6239 }
6240
6241 return [all, changed];
6242}
6243/**
6244 * @private
6245 * wrap a method with a deprecation warning and stack trace
6246 * @param {Function} method
6247 * @param {String} name
6248 * @param {String} message
6249 * @returns {Function} A new function wrapping the supplied method.
6250 */
6251
6252
6253function deprecate(method, name, message) {
6254 var deprecationMessage = "DEPRECATED METHOD: " + name + "\n" + message + " AT \n";
6255 return function () {
6256 var e = new Error('get-stack-trace');
6257 var stack = e && e.stack ? e.stack.replace(/^[^\(]+?[\n$]/gm, '').replace(/^\s+at\s+/gm, '').replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@') : 'Unknown Stack Trace';
6258 var log = window.console && (window.console.warn || window.console.log);
6259
6260 if (log) {
6261 log.call(window.console, deprecationMessage, stack);
6262 }
6263
6264 return method.apply(this, arguments);
6265 };
6266}
6267/**
6268 * @private
6269 * extend object.
6270 * means that properties in dest will be overwritten by the ones in src.
6271 * @param {Object} dest
6272 * @param {Object} src
6273 * @param {Boolean} [merge=false]
6274 * @returns {Object} dest
6275 */
6276
6277
6278var extend$1 = deprecate(function (dest, src, merge) {
6279 var keys = Object.keys(src);
6280 var i = 0;
6281
6282 while (i < keys.length) {
6283 if (!merge || merge && dest[keys[i]] === undefined) {
6284 dest[keys[i]] = src[keys[i]];
6285 }
6286
6287 i++;
6288 }
6289
6290 return dest;
6291}, 'extend', 'Use `assign`.');
6292/**
6293 * @private
6294 * merge the values from src in the dest.
6295 * means that properties that exist in dest will not be overwritten by src
6296 * @param {Object} dest
6297 * @param {Object} src
6298 * @returns {Object} dest
6299 */
6300
6301var merge$1 = deprecate(function (dest, src) {
6302 return extend$1(dest, src, true);
6303}, 'merge', 'Use `assign`.');
6304/**
6305 * @private
6306 * simple class inheritance
6307 * @param {Function} child
6308 * @param {Function} base
6309 * @param {Object} [properties]
6310 */
6311
6312function inherit(child, base, properties) {
6313 var baseP = base.prototype;
6314 var childP;
6315 childP = child.prototype = Object.create(baseP);
6316 childP.constructor = child;
6317 childP._super = baseP;
6318
6319 if (properties) {
6320 assign$1(childP, properties);
6321 }
6322}
6323/**
6324 * @private
6325 * simple function bind
6326 * @param {Function} fn
6327 * @param {Object} context
6328 * @returns {Function}
6329 */
6330
6331
6332function bindFn(fn, context) {
6333 return function boundFn() {
6334 return fn.apply(context, arguments);
6335 };
6336}
6337/**
6338 * @private
6339 * Simple way to create a manager with a default set of recognizers.
6340 * @param {HTMLElement} element
6341 * @param {Object} [options]
6342 * @constructor
6343 */
6344
6345
6346var Hammer$2 = /*#__PURE__*/function () {
6347 var Hammer =
6348 /**
6349 * @private
6350 * @const {string}
6351 */
6352 function Hammer(element, options) {
6353 if (options === void 0) {
6354 options = {};
6355 }
6356
6357 return new Manager(element, _extends({
6358 recognizers: preset.concat()
6359 }, options));
6360 };
6361
6362 Hammer.VERSION = "2.0.17-rc";
6363 Hammer.DIRECTION_ALL = DIRECTION_ALL;
6364 Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
6365 Hammer.DIRECTION_LEFT = DIRECTION_LEFT;
6366 Hammer.DIRECTION_RIGHT = DIRECTION_RIGHT;
6367 Hammer.DIRECTION_UP = DIRECTION_UP;
6368 Hammer.DIRECTION_HORIZONTAL = DIRECTION_HORIZONTAL;
6369 Hammer.DIRECTION_VERTICAL = DIRECTION_VERTICAL;
6370 Hammer.DIRECTION_NONE = DIRECTION_NONE;
6371 Hammer.DIRECTION_DOWN = DIRECTION_DOWN;
6372 Hammer.INPUT_START = INPUT_START;
6373 Hammer.INPUT_MOVE = INPUT_MOVE;
6374 Hammer.INPUT_END = INPUT_END;
6375 Hammer.INPUT_CANCEL = INPUT_CANCEL;
6376 Hammer.STATE_POSSIBLE = STATE_POSSIBLE;
6377 Hammer.STATE_BEGAN = STATE_BEGAN;
6378 Hammer.STATE_CHANGED = STATE_CHANGED;
6379 Hammer.STATE_ENDED = STATE_ENDED;
6380 Hammer.STATE_RECOGNIZED = STATE_RECOGNIZED;
6381 Hammer.STATE_CANCELLED = STATE_CANCELLED;
6382 Hammer.STATE_FAILED = STATE_FAILED;
6383 Hammer.Manager = Manager;
6384 Hammer.Input = Input;
6385 Hammer.TouchAction = TouchAction;
6386 Hammer.TouchInput = TouchInput;
6387 Hammer.MouseInput = MouseInput;
6388 Hammer.PointerEventInput = PointerEventInput;
6389 Hammer.TouchMouseInput = TouchMouseInput;
6390 Hammer.SingleTouchInput = SingleTouchInput;
6391 Hammer.Recognizer = Recognizer;
6392 Hammer.AttrRecognizer = AttrRecognizer;
6393 Hammer.Tap = TapRecognizer;
6394 Hammer.Pan = PanRecognizer;
6395 Hammer.Swipe = SwipeRecognizer;
6396 Hammer.Pinch = PinchRecognizer;
6397 Hammer.Rotate = RotateRecognizer;
6398 Hammer.Press = PressRecognizer;
6399 Hammer.on = addEventListeners;
6400 Hammer.off = removeEventListeners;
6401 Hammer.each = each;
6402 Hammer.merge = merge$1;
6403 Hammer.extend = extend$1;
6404 Hammer.bindFn = bindFn;
6405 Hammer.assign = assign$1;
6406 Hammer.inherit = inherit;
6407 Hammer.bindFn = bindFn;
6408 Hammer.prefixed = prefixed;
6409 Hammer.toArray = toArray$1;
6410 Hammer.inArray = inArray;
6411 Hammer.uniqueArray = uniqueArray;
6412 Hammer.splitStr = splitStr;
6413 Hammer.boolOrFn = boolOrFn;
6414 Hammer.hasParent = hasParent$1;
6415 Hammer.addEventListeners = addEventListeners;
6416 Hammer.removeEventListeners = removeEventListeners;
6417 Hammer.defaults = assign$1({}, defaults, {
6418 preset: preset
6419 });
6420 return Hammer;
6421}(); // style loader but by script tag, not by the loader.
6422var RealHammer = Hammer$2;
6423
6424function ownKeys$1(object, enumerableOnly) { var keys = keys$3(object); if (getOwnPropertySymbols) { var symbols = getOwnPropertySymbols(object); if (enumerableOnly) { symbols = filter(symbols).call(symbols, function (sym) { return getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
6425
6426function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context22; forEach$2(_context22 = ownKeys$1(Object(source), true)).call(_context22, function (key) { _defineProperty(target, key, source[key]); }); } else if (getOwnPropertyDescriptors) { defineProperties(target, getOwnPropertyDescriptors(source)); } else { var _context23; forEach$2(_context23 = ownKeys$1(Object(source))).call(_context23, function (key) { defineProperty$6(target, key, getOwnPropertyDescriptor(source, key)); }); } } return target; }
6427
6428function _createForOfIteratorHelper$1(o, allowArrayLike) { var it = typeof symbol !== "undefined" && getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
6429
6430function _unsupportedIterableToArray$1(o, minLen) { var _context21; if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = slice$2(_context21 = Object.prototype.toString.call(o)).call(_context21, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return from_1$2(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
6431
6432function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6433/**
6434 * Use this symbol to delete properies in deepObjectAssign.
6435 */
6436
6437var DELETE = symbol("DELETE");
6438/**
6439 * Pure version of deepObjectAssign, it doesn't modify any of it's arguments.
6440 *
6441 * @param base - The base object that fullfils the whole interface T.
6442 * @param updates - Updates that may change or delete props.
6443 *
6444 * @returns A brand new instance with all the supplied objects deeply merged.
6445 */
6446
6447
6448function pureDeepObjectAssign(base) {
6449 var _context;
6450
6451 for (var _len = arguments.length, updates = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6452 updates[_key - 1] = arguments[_key];
6453 }
6454
6455 return deepObjectAssign.apply(void 0, concat(_context = [{}, base]).call(_context, updates));
6456}
6457/**
6458 * Deep version of object assign with additional deleting by the DELETE symbol.
6459 *
6460 * @param values - Objects to be deeply merged.
6461 *
6462 * @returns The first object from values.
6463 */
6464
6465
6466function deepObjectAssign() {
6467 var merged = deepObjectAssignNonentry.apply(void 0, arguments);
6468 stripDelete(merged);
6469 return merged;
6470}
6471/**
6472 * Deep version of object assign with additional deleting by the DELETE symbol.
6473 *
6474 * @remarks
6475 * This doesn't strip the DELETE symbols so they may end up in the final object.
6476 *
6477 * @param values - Objects to be deeply merged.
6478 *
6479 * @returns The first object from values.
6480 */
6481
6482
6483function deepObjectAssignNonentry() {
6484 for (var _len2 = arguments.length, values = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
6485 values[_key2] = arguments[_key2];
6486 }
6487
6488 if (values.length < 2) {
6489 return values[0];
6490 } else if (values.length > 2) {
6491 var _context2;
6492
6493 return deepObjectAssignNonentry.apply(void 0, concat(_context2 = [deepObjectAssign(values[0], values[1])]).call(_context2, _toConsumableArray(slice$2(values).call(values, 2))));
6494 }
6495
6496 var a = values[0];
6497 var b = values[1];
6498
6499 var _iterator = _createForOfIteratorHelper$1(ownKeys$2(b)),
6500 _step;
6501
6502 try {
6503 for (_iterator.s(); !(_step = _iterator.n()).done;) {
6504 var prop = _step.value;
6505 if (!Object.prototype.propertyIsEnumerable.call(b, prop)) ;else if (b[prop] === DELETE) {
6506 delete a[prop];
6507 } else if (a[prop] !== null && b[prop] !== null && _typeof(a[prop]) === "object" && _typeof(b[prop]) === "object" && !isArray(a[prop]) && !isArray(b[prop])) {
6508 a[prop] = deepObjectAssignNonentry(a[prop], b[prop]);
6509 } else {
6510 a[prop] = clone(b[prop]);
6511 }
6512 }
6513 } catch (err) {
6514 _iterator.e(err);
6515 } finally {
6516 _iterator.f();
6517 }
6518
6519 return a;
6520}
6521/**
6522 * Deep clone given object or array. In case of primitive simply return.
6523 *
6524 * @param a - Anything.
6525 *
6526 * @returns Deep cloned object/array or unchanged a.
6527 */
6528
6529
6530function clone(a) {
6531 if (isArray(a)) {
6532 return map$3(a).call(a, function (value) {
6533 return clone(value);
6534 });
6535 } else if (_typeof(a) === "object" && a !== null) {
6536 return deepObjectAssignNonentry({}, a);
6537 } else {
6538 return a;
6539 }
6540}
6541/**
6542 * Strip DELETE from given object.
6543 *
6544 * @param a - Object which may contain DELETE but won't after this is executed.
6545 */
6546
6547
6548function stripDelete(a) {
6549 for (var _i = 0, _Object$keys = keys$3(a); _i < _Object$keys.length; _i++) {
6550 var prop = _Object$keys[_i];
6551
6552 if (a[prop] === DELETE) {
6553 delete a[prop];
6554 } else if (_typeof(a[prop]) === "object" && a[prop] !== null) {
6555 stripDelete(a[prop]);
6556 }
6557 }
6558}
6559/**
6560 * Seedable, fast and reasonably good (not crypto but more than okay for our
6561 * needs) random number generator.
6562 *
6563 * @remarks
6564 * Adapted from {@link https://web.archive.org/web/20110429100736/http://baagoe.com:80/en/RandomMusings/javascript}.
6565 * Original algorithm created by Johannes Baagøe \<baagoe\@baagoe.com\> in 2010.
6566 */
6567
6568/**
6569 * Create a seeded pseudo random generator based on Alea by Johannes Baagøe.
6570 *
6571 * @param seed - All supplied arguments will be used as a seed. In case nothing
6572 * is supplied the current time will be used to seed the generator.
6573 *
6574 * @returns A ready to use seeded generator.
6575 */
6576
6577
6578function Alea() {
6579 for (var _len3 = arguments.length, seed = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
6580 seed[_key3] = arguments[_key3];
6581 }
6582
6583 return AleaImplementation(seed.length ? seed : [now$1()]);
6584}
6585/**
6586 * An implementation of [[Alea]] without user input validation.
6587 *
6588 * @param seed - The data that will be used to seed the generator.
6589 *
6590 * @returns A ready to use seeded generator.
6591 */
6592
6593
6594function AleaImplementation(seed) {
6595 var _mashSeed = mashSeed(seed),
6596 _mashSeed2 = _slicedToArray(_mashSeed, 3),
6597 s0 = _mashSeed2[0],
6598 s1 = _mashSeed2[1],
6599 s2 = _mashSeed2[2];
6600
6601 var c = 1;
6602
6603 var random = function random() {
6604 var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32
6605
6606 s0 = s1;
6607 s1 = s2;
6608 return s2 = t - (c = t | 0);
6609 };
6610
6611 random.uint32 = function () {
6612 return random() * 0x100000000;
6613 }; // 2^32
6614
6615
6616 random.fract53 = function () {
6617 return random() + (random() * 0x200000 | 0) * 1.1102230246251565e-16;
6618 }; // 2^-53
6619
6620
6621 random.algorithm = "Alea";
6622 random.seed = seed;
6623 random.version = "0.9";
6624 return random;
6625}
6626/**
6627 * Turn arbitrary data into values [[AleaImplementation]] can use to generate
6628 * random numbers.
6629 *
6630 * @param seed - Arbitrary data that will be used as the seed.
6631 *
6632 * @returns Three numbers to use as initial values for [[AleaImplementation]].
6633 */
6634
6635
6636function mashSeed() {
6637 var mash = Mash();
6638 var s0 = mash(" ");
6639 var s1 = mash(" ");
6640 var s2 = mash(" ");
6641
6642 for (var i = 0; i < arguments.length; i++) {
6643 s0 -= mash(i < 0 || arguments.length <= i ? undefined : arguments[i]);
6644
6645 if (s0 < 0) {
6646 s0 += 1;
6647 }
6648
6649 s1 -= mash(i < 0 || arguments.length <= i ? undefined : arguments[i]);
6650
6651 if (s1 < 0) {
6652 s1 += 1;
6653 }
6654
6655 s2 -= mash(i < 0 || arguments.length <= i ? undefined : arguments[i]);
6656
6657 if (s2 < 0) {
6658 s2 += 1;
6659 }
6660 }
6661
6662 return [s0, s1, s2];
6663}
6664/**
6665 * Create a new mash function.
6666 *
6667 * @returns A nonpure function that takes arbitrary [[Mashable]] data and turns
6668 * them into numbers.
6669 */
6670
6671
6672function Mash() {
6673 var n = 0xefc8249d;
6674 return function (data) {
6675 var string = data.toString();
6676
6677 for (var i = 0; i < string.length; i++) {
6678 n += string.charCodeAt(i);
6679 var h = 0.02519603282416938 * n;
6680 n = h >>> 0;
6681 h -= n;
6682 h *= n;
6683 n = h >>> 0;
6684 h -= n;
6685 n += h * 0x100000000; // 2^32
6686 }
6687
6688 return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
6689 };
6690}
6691/**
6692 * Setup a mock hammer.js object, for unit testing.
6693 *
6694 * Inspiration: https://github.com/uber/deck.gl/pull/658
6695 *
6696 * @returns {{on: noop, off: noop, destroy: noop, emit: noop, get: get}}
6697 */
6698
6699
6700function hammerMock() {
6701 var noop = function noop() {};
6702
6703 return {
6704 on: noop,
6705 off: noop,
6706 destroy: noop,
6707 emit: noop,
6708 get: function get() {
6709 return {
6710 set: noop
6711 };
6712 }
6713 };
6714}
6715
6716var Hammer$1 = typeof window !== "undefined" ? window.Hammer || RealHammer : function () {
6717 // hammer.js is only available in a browser, not in node.js. Replacing it with a mock object.
6718 return hammerMock();
6719};
6720/**
6721 * Turn an element into an clickToUse element.
6722 * When not active, the element has a transparent overlay. When the overlay is
6723 * clicked, the mode is changed to active.
6724 * When active, the element is displayed with a blue border around it, and
6725 * the interactive contents of the element can be used. When clicked outside
6726 * the element, the elements mode is changed to inactive.
6727 *
6728 * @param {Element} container
6729 * @class Activator
6730 */
6731
6732function Activator(container) {
6733 var _this = this,
6734 _context3;
6735
6736 this._cleanupQueue = [];
6737 this.active = false;
6738 this._dom = {
6739 container: container,
6740 overlay: document.createElement("div")
6741 };
6742
6743 this._dom.overlay.classList.add("vis-overlay");
6744
6745 this._dom.container.appendChild(this._dom.overlay);
6746
6747 this._cleanupQueue.push(function () {
6748 _this._dom.overlay.parentNode.removeChild(_this._dom.overlay);
6749 });
6750
6751 var hammer = Hammer$1(this._dom.overlay);
6752 hammer.on("tap", bind(_context3 = this._onTapOverlay).call(_context3, this));
6753
6754 this._cleanupQueue.push(function () {
6755 hammer.destroy(); // FIXME: cleaning up hammer instances doesn't work (Timeline not removed
6756 // from memory)
6757 }); // block all touch events (except tap)
6758
6759
6760 var events = ["tap", "doubletap", "press", "pinch", "pan", "panstart", "panmove", "panend"];
6761
6762 forEach$2(events).call(events, function (event) {
6763 hammer.on(event, function (event) {
6764 event.srcEvent.stopPropagation();
6765 });
6766 }); // attach a click event to the window, in order to deactivate when clicking outside the timeline
6767
6768
6769 if (document && document.body) {
6770 this._onClick = function (event) {
6771 if (!_hasParent(event.target, container)) {
6772 _this.deactivate();
6773 }
6774 };
6775
6776 document.body.addEventListener("click", this._onClick);
6777
6778 this._cleanupQueue.push(function () {
6779 document.body.removeEventListener("click", _this._onClick);
6780 });
6781 } // prepare escape key listener for deactivating when active
6782
6783
6784 this._escListener = function (event) {
6785 if ("key" in event ? event.key === "Escape" : event.keyCode === 27
6786 /* the keyCode is for IE11 */
6787 ) {
6788 _this.deactivate();
6789 }
6790 };
6791} // turn into an event emitter
6792
6793
6794componentEmitter(Activator.prototype); // The currently active activator
6795
6796Activator.current = null;
6797/**
6798 * Destroy the activator. Cleans up all created DOM and event listeners
6799 */
6800
6801Activator.prototype.destroy = function () {
6802 var _context4, _context5;
6803
6804 this.deactivate();
6805
6806 var _iterator2 = _createForOfIteratorHelper$1(reverse(_context4 = splice(_context5 = this._cleanupQueue).call(_context5, 0)).call(_context4)),
6807 _step2;
6808
6809 try {
6810 for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
6811 var callback = _step2.value;
6812 callback();
6813 }
6814 } catch (err) {
6815 _iterator2.e(err);
6816 } finally {
6817 _iterator2.f();
6818 }
6819};
6820/**
6821 * Activate the element
6822 * Overlay is hidden, element is decorated with a blue shadow border
6823 */
6824
6825
6826Activator.prototype.activate = function () {
6827 // we allow only one active activator at a time
6828 if (Activator.current) {
6829 Activator.current.deactivate();
6830 }
6831
6832 Activator.current = this;
6833 this.active = true;
6834 this._dom.overlay.style.display = "none";
6835
6836 this._dom.container.classList.add("vis-active");
6837
6838 this.emit("change");
6839 this.emit("activate"); // ugly hack: bind ESC after emitting the events, as the Network rebinds all
6840 // keyboard events on a 'change' event
6841
6842 document.body.addEventListener("keydown", this._escListener);
6843};
6844/**
6845 * Deactivate the element
6846 * Overlay is displayed on top of the element
6847 */
6848
6849
6850Activator.prototype.deactivate = function () {
6851 this.active = false;
6852 this._dom.overlay.style.display = "block";
6853
6854 this._dom.container.classList.remove("vis-active");
6855
6856 document.body.removeEventListener("keydown", this._escListener);
6857 this.emit("change");
6858 this.emit("deactivate");
6859};
6860/**
6861 * Handle a tap event: activate the container
6862 *
6863 * @param {Event} event The event
6864 * @private
6865 */
6866
6867
6868Activator.prototype._onTapOverlay = function (event) {
6869 // activate the container
6870 this.activate();
6871 event.srcEvent.stopPropagation();
6872};
6873/**
6874 * Test whether the element has the requested parent element somewhere in
6875 * its chain of parent nodes.
6876 *
6877 * @param {HTMLElement} element
6878 * @param {HTMLElement} parent
6879 * @returns {boolean} Returns true when the parent is found somewhere in the
6880 * chain of parent nodes.
6881 * @private
6882 */
6883
6884
6885function _hasParent(element, parent) {
6886 while (element) {
6887 if (element === parent) {
6888 return true;
6889 }
6890
6891 element = element.parentNode;
6892 }
6893
6894 return false;
6895} // utility functions
6896// parse ASP.Net Date pattern,
6897// for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/'
6898// code from http://momentjs.com/
6899
6900
6901var ASPDateRegex = /^\/?Date\((-?\d+)/i; // Color REs
6902
6903var fullHexRE = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
6904var shortHexRE = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
6905var rgbRE = /^rgb\( *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *\)$/i;
6906var rgbaRE = /^rgba\( *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *(1?\d{1,2}|2[0-4]\d|25[0-5]) *, *([01]|0?\.\d+) *\)$/i;
6907/**
6908 * Test whether given object is a number.
6909 *
6910 * @param value - Input value of unknown type.
6911 *
6912 * @returns True if number, false otherwise.
6913 */
6914
6915function isNumber(value) {
6916 return value instanceof Number || typeof value === "number";
6917}
6918/**
6919 * Remove everything in the DOM object.
6920 *
6921 * @param DOMobject - Node whose child nodes will be recursively deleted.
6922 */
6923
6924
6925function recursiveDOMDelete(DOMobject) {
6926 if (DOMobject) {
6927 while (DOMobject.hasChildNodes() === true) {
6928 var child = DOMobject.firstChild;
6929
6930 if (child) {
6931 recursiveDOMDelete(child);
6932 DOMobject.removeChild(child);
6933 }
6934 }
6935 }
6936}
6937/**
6938 * Test whether given object is a string.
6939 *
6940 * @param value - Input value of unknown type.
6941 *
6942 * @returns True if string, false otherwise.
6943 */
6944
6945
6946function isString(value) {
6947 return value instanceof String || typeof value === "string";
6948}
6949/**
6950 * Test whether given object is a object (not primitive or null).
6951 *
6952 * @param value - Input value of unknown type.
6953 *
6954 * @returns True if not null object, false otherwise.
6955 */
6956
6957
6958function isObject(value) {
6959 return _typeof(value) === "object" && value !== null;
6960}
6961/**
6962 * Test whether given object is a Date, or a String containing a Date.
6963 *
6964 * @param value - Input value of unknown type.
6965 *
6966 * @returns True if Date instance or string date representation, false otherwise.
6967 */
6968
6969
6970function isDate(value) {
6971 if (value instanceof Date) {
6972 return true;
6973 } else if (isString(value)) {
6974 // test whether this string contains a date
6975 var match = ASPDateRegex.exec(value);
6976
6977 if (match) {
6978 return true;
6979 } else if (!isNaN(Date.parse(value))) {
6980 return true;
6981 }
6982 }
6983
6984 return false;
6985}
6986/**
6987 * Copy property from b to a if property present in a.
6988 * If property in b explicitly set to null, delete it if `allowDeletion` set.
6989 *
6990 * Internal helper routine, should not be exported. Not added to `exports` for that reason.
6991 *
6992 * @param a - Target object.
6993 * @param b - Source object.
6994 * @param prop - Name of property to copy from b to a.
6995 * @param allowDeletion - If true, delete property in a if explicitly set to null in b.
6996 */
6997
6998
6999function copyOrDelete(a, b, prop, allowDeletion) {
7000 var doDeletion = false;
7001
7002 if (allowDeletion === true) {
7003 doDeletion = b[prop] === null && a[prop] !== undefined;
7004 }
7005
7006 if (doDeletion) {
7007 delete a[prop];
7008 } else {
7009 a[prop] = b[prop]; // Remember, this is a reference copy!
7010 }
7011}
7012/**
7013 * Fill an object with a possibly partially defined other object.
7014 *
7015 * Only copies values for the properties already present in a.
7016 * That means an object is not created on a property if only the b object has it.
7017 *
7018 * @param a - The object that will have it's properties updated.
7019 * @param b - The object with property updates.
7020 * @param allowDeletion - If true, delete properties in a that are explicitly set to null in b.
7021 */
7022
7023
7024function fillIfDefined(a, b) {
7025 var allowDeletion = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
7026
7027 // NOTE: iteration of properties of a
7028 // NOTE: prototype properties iterated over as well
7029 for (var prop in a) {
7030 if (b[prop] !== undefined) {
7031 if (b[prop] === null || _typeof(b[prop]) !== "object") {
7032 // Note: typeof null === 'object'
7033 copyOrDelete(a, b, prop, allowDeletion);
7034 } else {
7035 var aProp = a[prop];
7036 var bProp = b[prop];
7037
7038 if (isObject(aProp) && isObject(bProp)) {
7039 fillIfDefined(aProp, bProp, allowDeletion);
7040 }
7041 }
7042 }
7043 }
7044}
7045/**
7046 * Copy the values of all of the enumerable own properties from one or more source objects to a
7047 * target object. Returns the target object.
7048 *
7049 * @param target - The target object to copy to.
7050 * @param source - The source object from which to copy properties.
7051 *
7052 * @returns The target object.
7053 */
7054
7055
7056var extend = assign$2;
7057/**
7058 * Extend object a with selected properties of object b or a series of objects.
7059 *
7060 * @remarks
7061 * Only properties with defined values are copied.
7062 *
7063 * @param props - Properties to be copied to a.
7064 * @param a - The target.
7065 * @param others - The sources.
7066 *
7067 * @returns Argument a.
7068 */
7069
7070function selectiveExtend(props, a) {
7071 if (!isArray(props)) {
7072 throw new Error("Array with property names expected as first argument");
7073 }
7074
7075 for (var _len4 = arguments.length, others = new Array(_len4 > 2 ? _len4 - 2 : 0), _key4 = 2; _key4 < _len4; _key4++) {
7076 others[_key4 - 2] = arguments[_key4];
7077 }
7078
7079 for (var _i2 = 0, _others = others; _i2 < _others.length; _i2++) {
7080 var other = _others[_i2];
7081
7082 for (var p = 0; p < props.length; p++) {
7083 var prop = props[p];
7084
7085 if (other && Object.prototype.hasOwnProperty.call(other, prop)) {
7086 a[prop] = other[prop];
7087 }
7088 }
7089 }
7090
7091 return a;
7092}
7093/**
7094 * Extend object a with selected properties of object b.
7095 * Only properties with defined values are copied.
7096 *
7097 * @remarks
7098 * Previous version of this routine implied that multiple source objects could
7099 * be used; however, the implementation was **wrong**. Since multiple (\>1)
7100 * sources weren't used anywhere in the `vis.js` code, this has been removed
7101 *
7102 * @param props - Names of first-level properties to copy over.
7103 * @param a - Target object.
7104 * @param b - Source object.
7105 * @param allowDeletion - If true, delete property in a if explicitly set to null in b.
7106 *
7107 * @returns Argument a.
7108 */
7109
7110
7111function selectiveDeepExtend(props, a, b) {
7112 var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
7113
7114 // TODO: add support for Arrays to deepExtend
7115 if (isArray(b)) {
7116 throw new TypeError("Arrays are not supported by deepExtend");
7117 }
7118
7119 for (var p = 0; p < props.length; p++) {
7120 var prop = props[p];
7121
7122 if (Object.prototype.hasOwnProperty.call(b, prop)) {
7123 if (b[prop] && b[prop].constructor === Object) {
7124 if (a[prop] === undefined) {
7125 a[prop] = {};
7126 }
7127
7128 if (a[prop].constructor === Object) {
7129 deepExtend(a[prop], b[prop], false, allowDeletion);
7130 } else {
7131 copyOrDelete(a, b, prop, allowDeletion);
7132 }
7133 } else if (isArray(b[prop])) {
7134 throw new TypeError("Arrays are not supported by deepExtend");
7135 } else {
7136 copyOrDelete(a, b, prop, allowDeletion);
7137 }
7138 }
7139 }
7140
7141 return a;
7142}
7143/**
7144 * Extend object `a` with properties of object `b`, ignoring properties which
7145 * are explicitly specified to be excluded.
7146 *
7147 * @remarks
7148 * The properties of `b` are considered for copying. Properties which are
7149 * themselves objects are are also extended. Only properties with defined
7150 * values are copied.
7151 *
7152 * @param propsToExclude - Names of properties which should *not* be copied.
7153 * @param a - Object to extend.
7154 * @param b - Object to take properties from for extension.
7155 * @param allowDeletion - If true, delete properties in a that are explicitly
7156 * set to null in b.
7157 *
7158 * @returns Argument a.
7159 */
7160
7161
7162function selectiveNotDeepExtend(propsToExclude, a, b) {
7163 var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
7164
7165 // TODO: add support for Arrays to deepExtend
7166 // NOTE: array properties have an else-below; apparently, there is a problem here.
7167 if (isArray(b)) {
7168 throw new TypeError("Arrays are not supported by deepExtend");
7169 }
7170
7171 for (var prop in b) {
7172 if (!Object.prototype.hasOwnProperty.call(b, prop)) {
7173 continue;
7174 } // Handle local properties only
7175
7176
7177 if (includes(propsToExclude).call(propsToExclude, prop)) {
7178 continue;
7179 } // In exclusion list, skip
7180
7181
7182 if (b[prop] && b[prop].constructor === Object) {
7183 if (a[prop] === undefined) {
7184 a[prop] = {};
7185 }
7186
7187 if (a[prop].constructor === Object) {
7188 deepExtend(a[prop], b[prop]); // NOTE: allowDeletion not propagated!
7189 } else {
7190 copyOrDelete(a, b, prop, allowDeletion);
7191 }
7192 } else if (isArray(b[prop])) {
7193 a[prop] = [];
7194
7195 for (var i = 0; i < b[prop].length; i++) {
7196 a[prop].push(b[prop][i]);
7197 }
7198 } else {
7199 copyOrDelete(a, b, prop, allowDeletion);
7200 }
7201 }
7202
7203 return a;
7204}
7205/**
7206 * Deep extend an object a with the properties of object b.
7207 *
7208 * @param a - Target object.
7209 * @param b - Source object.
7210 * @param protoExtend - If true, the prototype values will also be extended.
7211 * (That is the options objects that inherit from others will also get the
7212 * inherited options).
7213 * @param allowDeletion - If true, the values of fields that are null will be deleted.
7214 *
7215 * @returns Argument a.
7216 */
7217
7218
7219function deepExtend(a, b) {
7220 var protoExtend = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
7221 var allowDeletion = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
7222
7223 for (var prop in b) {
7224 if (Object.prototype.hasOwnProperty.call(b, prop) || protoExtend === true) {
7225 if (_typeof(b[prop]) === "object" && b[prop] !== null && getPrototypeOf$3(b[prop]) === Object.prototype) {
7226 if (a[prop] === undefined) {
7227 a[prop] = deepExtend({}, b[prop], protoExtend); // NOTE: allowDeletion not propagated!
7228 } else if (_typeof(a[prop]) === "object" && a[prop] !== null && getPrototypeOf$3(a[prop]) === Object.prototype) {
7229 deepExtend(a[prop], b[prop], protoExtend); // NOTE: allowDeletion not propagated!
7230 } else {
7231 copyOrDelete(a, b, prop, allowDeletion);
7232 }
7233 } else if (isArray(b[prop])) {
7234 var _context6;
7235
7236 a[prop] = slice$2(_context6 = b[prop]).call(_context6);
7237 } else {
7238 copyOrDelete(a, b, prop, allowDeletion);
7239 }
7240 }
7241 }
7242
7243 return a;
7244}
7245/**
7246 * Test whether all elements in two arrays are equal.
7247 *
7248 * @param a - First array.
7249 * @param b - Second array.
7250 *
7251 * @returns True if both arrays have the same length and same elements (1 = '1').
7252 */
7253
7254
7255function equalArray(a, b) {
7256 if (a.length !== b.length) {
7257 return false;
7258 }
7259
7260 for (var i = 0, len = a.length; i < len; i++) {
7261 if (a[i] != b[i]) {
7262 return false;
7263 }
7264 }
7265
7266 return true;
7267}
7268/**
7269 * Get the type of an object, for example exports.getType([]) returns 'Array'.
7270 *
7271 * @param object - Input value of unknown type.
7272 *
7273 * @returns Detected type.
7274 */
7275
7276
7277function getType(object) {
7278 var type = _typeof(object);
7279
7280 if (type === "object") {
7281 if (object === null) {
7282 return "null";
7283 }
7284
7285 if (object instanceof Boolean) {
7286 return "Boolean";
7287 }
7288
7289 if (object instanceof Number) {
7290 return "Number";
7291 }
7292
7293 if (object instanceof String) {
7294 return "String";
7295 }
7296
7297 if (isArray(object)) {
7298 return "Array";
7299 }
7300
7301 if (object instanceof Date) {
7302 return "Date";
7303 }
7304
7305 return "Object";
7306 }
7307
7308 if (type === "number") {
7309 return "Number";
7310 }
7311
7312 if (type === "boolean") {
7313 return "Boolean";
7314 }
7315
7316 if (type === "string") {
7317 return "String";
7318 }
7319
7320 if (type === undefined) {
7321 return "undefined";
7322 }
7323
7324 return type;
7325}
7326/**
7327 * Used to extend an array and copy it. This is used to propagate paths recursively.
7328 *
7329 * @param arr - First part.
7330 * @param newValue - The value to be aadded into the array.
7331 *
7332 * @returns A new array with all items from arr and newValue (which is last).
7333 */
7334
7335
7336function copyAndExtendArray(arr, newValue) {
7337 var _context7;
7338
7339 return concat(_context7 = []).call(_context7, _toConsumableArray(arr), [newValue]);
7340}
7341/**
7342 * Used to extend an array and copy it. This is used to propagate paths recursively.
7343 *
7344 * @param arr - The array to be copied.
7345 *
7346 * @returns Shallow copy of arr.
7347 */
7348
7349
7350function copyArray(arr) {
7351 return slice$2(arr).call(arr);
7352}
7353/**
7354 * Retrieve the absolute left value of a DOM element.
7355 *
7356 * @param elem - A dom element, for example a div.
7357 *
7358 * @returns The absolute left position of this element in the browser page.
7359 */
7360
7361
7362function getAbsoluteLeft(elem) {
7363 return elem.getBoundingClientRect().left;
7364}
7365/**
7366 * Retrieve the absolute right value of a DOM element.
7367 *
7368 * @param elem - A dom element, for example a div.
7369 *
7370 * @returns The absolute right position of this element in the browser page.
7371 */
7372
7373
7374function getAbsoluteRight(elem) {
7375 return elem.getBoundingClientRect().right;
7376}
7377/**
7378 * Retrieve the absolute top value of a DOM element.
7379 *
7380 * @param elem - A dom element, for example a div.
7381 *
7382 * @returns The absolute top position of this element in the browser page.
7383 */
7384
7385
7386function getAbsoluteTop(elem) {
7387 return elem.getBoundingClientRect().top;
7388}
7389/**
7390 * Add a className to the given elements style.
7391 *
7392 * @param elem - The element to which the classes will be added.
7393 * @param classNames - Space separated list of classes.
7394 */
7395
7396
7397function addClassName(elem, classNames) {
7398 var classes = elem.className.split(" ");
7399 var newClasses = classNames.split(" ");
7400 classes = concat(classes).call(classes, filter(newClasses).call(newClasses, function (className) {
7401 return !includes(classes).call(classes, className);
7402 }));
7403 elem.className = classes.join(" ");
7404}
7405/**
7406 * Remove a className from the given elements style.
7407 *
7408 * @param elem - The element from which the classes will be removed.
7409 * @param classNames - Space separated list of classes.
7410 */
7411
7412
7413function removeClassName(elem, classNames) {
7414 var classes = elem.className.split(" ");
7415 var oldClasses = classNames.split(" ");
7416 classes = filter(classes).call(classes, function (className) {
7417 return !includes(oldClasses).call(oldClasses, className);
7418 });
7419 elem.className = classes.join(" ");
7420}
7421/**
7422 * For each method for both arrays and objects.
7423 * In case of an array, the built-in Array.forEach() is applied (**No, it's not!**).
7424 * In case of an Object, the method loops over all properties of the object.
7425 *
7426 * @param object - An Object or Array to be iterated over.
7427 * @param callback - Array.forEach-like callback.
7428 */
7429
7430
7431function forEach$1(object, callback) {
7432 if (isArray(object)) {
7433 // array
7434 var len = object.length;
7435
7436 for (var i = 0; i < len; i++) {
7437 callback(object[i], i, object);
7438 }
7439 } else {
7440 // object
7441 for (var key in object) {
7442 if (Object.prototype.hasOwnProperty.call(object, key)) {
7443 callback(object[key], key, object);
7444 }
7445 }
7446 }
7447}
7448/**
7449 * Convert an object into an array: all objects properties are put into the array. The resulting array is unordered.
7450 *
7451 * @param o - Object that contains the properties and methods.
7452 *
7453 * @returns An array of unordered values.
7454 */
7455
7456
7457var toArray = values$3;
7458/**
7459 * Update a property in an object.
7460 *
7461 * @param object - The object whose property will be updated.
7462 * @param key - Name of the property to be updated.
7463 * @param value - The new value to be assigned.
7464 *
7465 * @returns Whether the value was updated (true) or already strictly the same in the original object (false).
7466 */
7467
7468function updateProperty(object, key, value) {
7469 if (object[key] !== value) {
7470 object[key] = value;
7471 return true;
7472 } else {
7473 return false;
7474 }
7475}
7476/**
7477 * Throttle the given function to be only executed once per animation frame.
7478 *
7479 * @param fn - The original function.
7480 *
7481 * @returns The throttled function.
7482 */
7483
7484
7485function throttle(fn) {
7486 var scheduled = false;
7487 return function () {
7488 if (!scheduled) {
7489 scheduled = true;
7490 requestAnimationFrame(function () {
7491 scheduled = false;
7492 fn();
7493 });
7494 }
7495 };
7496}
7497/**
7498 * Add and event listener. Works for all browsers.
7499 *
7500 * @param element - The element to bind the event listener to.
7501 * @param action - Same as Element.addEventListener(action, —, —).
7502 * @param listener - Same as Element.addEventListener(—, listener, —).
7503 * @param useCapture - Same as Element.addEventListener(—, —, useCapture).
7504 */
7505
7506
7507function addEventListener(element, action, listener, useCapture) {
7508 if (element.addEventListener) {
7509 var _context8;
7510
7511 if (useCapture === undefined) {
7512 useCapture = false;
7513 }
7514
7515 if (action === "mousewheel" && includes(_context8 = navigator.userAgent).call(_context8, "Firefox")) {
7516 action = "DOMMouseScroll"; // For Firefox
7517 }
7518
7519 element.addEventListener(action, listener, useCapture);
7520 } else {
7521 // @TODO: IE types? Does anyone care?
7522 element.attachEvent("on" + action, listener); // IE browsers
7523 }
7524}
7525/**
7526 * Remove an event listener from an element.
7527 *
7528 * @param element - The element to bind the event listener to.
7529 * @param action - Same as Element.removeEventListener(action, —, —).
7530 * @param listener - Same as Element.removeEventListener(—, listener, —).
7531 * @param useCapture - Same as Element.removeEventListener(—, —, useCapture).
7532 */
7533
7534
7535function removeEventListener(element, action, listener, useCapture) {
7536 if (element.removeEventListener) {
7537 var _context9;
7538
7539 // non-IE browsers
7540 if (useCapture === undefined) {
7541 useCapture = false;
7542 }
7543
7544 if (action === "mousewheel" && includes(_context9 = navigator.userAgent).call(_context9, "Firefox")) {
7545 action = "DOMMouseScroll"; // For Firefox
7546 }
7547
7548 element.removeEventListener(action, listener, useCapture);
7549 } else {
7550 // @TODO: IE types? Does anyone care?
7551 element.detachEvent("on" + action, listener); // IE browsers
7552 }
7553}
7554/**
7555 * Cancels the event's default action if it is cancelable, without stopping further propagation of the event.
7556 *
7557 * @param event - The event whose default action should be prevented.
7558 */
7559
7560
7561function preventDefault(event) {
7562 if (!event) {
7563 event = window.event;
7564 }
7565
7566 if (!event) ;else if (event.preventDefault) {
7567 event.preventDefault(); // non-IE browsers
7568 } else {
7569 // @TODO: IE types? Does anyone care?
7570 event.returnValue = false; // IE browsers
7571 }
7572}
7573/**
7574 * Get HTML element which is the target of the event.
7575 *
7576 * @param event - The event.
7577 *
7578 * @returns The element or null if not obtainable.
7579 */
7580
7581
7582function getTarget() {
7583 var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.event;
7584 // code from http://www.quirksmode.org/js/events_properties.html
7585 // @TODO: EventTarget can be almost anything, is it okay to return only Elements?
7586 var target = null;
7587 if (!event) ;else if (event.target) {
7588 target = event.target;
7589 } else if (event.srcElement) {
7590 target = event.srcElement;
7591 }
7592
7593 if (!(target instanceof Element)) {
7594 return null;
7595 }
7596
7597 if (target.nodeType != null && target.nodeType == 3) {
7598 // defeat Safari bug
7599 target = target.parentNode;
7600
7601 if (!(target instanceof Element)) {
7602 return null;
7603 }
7604 }
7605
7606 return target;
7607}
7608/**
7609 * Check if given element contains given parent somewhere in the DOM tree.
7610 *
7611 * @param element - The element to be tested.
7612 * @param parent - The ancestor (not necessarily parent) of the element.
7613 *
7614 * @returns True if parent is an ancestor of the element, false otherwise.
7615 */
7616
7617
7618function hasParent(element, parent) {
7619 var elem = element;
7620
7621 while (elem) {
7622 if (elem === parent) {
7623 return true;
7624 } else if (elem.parentNode) {
7625 elem = elem.parentNode;
7626 } else {
7627 return false;
7628 }
7629 }
7630
7631 return false;
7632}
7633
7634var option = {
7635 /**
7636 * Convert a value into a boolean.
7637 *
7638 * @param value - Value to be converted intoboolean, a function will be executed as `(() => unknown)`.
7639 * @param defaultValue - If the value or the return value of the function == null then this will be returned.
7640 *
7641 * @returns Corresponding boolean value, if none then the default value, if none then null.
7642 */
7643 asBoolean: function asBoolean(value, defaultValue) {
7644 if (typeof value == "function") {
7645 value = value();
7646 }
7647
7648 if (value != null) {
7649 return value != false;
7650 }
7651
7652 return defaultValue || null;
7653 },
7654
7655 /**
7656 * Convert a value into a number.
7657 *
7658 * @param value - Value to be converted intonumber, a function will be executed as `(() => unknown)`.
7659 * @param defaultValue - If the value or the return value of the function == null then this will be returned.
7660 *
7661 * @returns Corresponding **boxed** number value, if none then the default value, if none then null.
7662 */
7663 asNumber: function asNumber(value, defaultValue) {
7664 if (typeof value == "function") {
7665 value = value();
7666 }
7667
7668 if (value != null) {
7669 return Number(value) || defaultValue || null;
7670 }
7671
7672 return defaultValue || null;
7673 },
7674
7675 /**
7676 * Convert a value into a string.
7677 *
7678 * @param value - Value to be converted intostring, a function will be executed as `(() => unknown)`.
7679 * @param defaultValue - If the value or the return value of the function == null then this will be returned.
7680 *
7681 * @returns Corresponding **boxed** string value, if none then the default value, if none then null.
7682 */
7683 asString: function asString(value, defaultValue) {
7684 if (typeof value == "function") {
7685 value = value();
7686 }
7687
7688 if (value != null) {
7689 return String(value);
7690 }
7691
7692 return defaultValue || null;
7693 },
7694
7695 /**
7696 * Convert a value into a size.
7697 *
7698 * @param value - Value to be converted intosize, a function will be executed as `(() => unknown)`.
7699 * @param defaultValue - If the value or the return value of the function == null then this will be returned.
7700 *
7701 * @returns Corresponding string value (number + 'px'), if none then the default value, if none then null.
7702 */
7703 asSize: function asSize(value, defaultValue) {
7704 if (typeof value == "function") {
7705 value = value();
7706 }
7707
7708 if (isString(value)) {
7709 return value;
7710 } else if (isNumber(value)) {
7711 return value + "px";
7712 } else {
7713 return defaultValue || null;
7714 }
7715 },
7716
7717 /**
7718 * Convert a value into a DOM Element.
7719 *
7720 * @param value - Value to be converted into DOM Element, a function will be executed as `(() => unknown)`.
7721 * @param defaultValue - If the value or the return value of the function == null then this will be returned.
7722 *
7723 * @returns The DOM Element, if none then the default value, if none then null.
7724 */
7725 asElement: function asElement(value, defaultValue) {
7726 if (typeof value == "function") {
7727 value = value();
7728 }
7729
7730 return value || defaultValue || null;
7731 }
7732};
7733/**
7734 * Convert hex color string into RGB color object.
7735 *
7736 * @remarks
7737 * {@link http://stackoverflow.com/questions/5623838/rgb-to-hex-and-hex-to-rgb}
7738 *
7739 * @param hex - Hex color string (3 or 6 digits, with or without #).
7740 *
7741 * @returns RGB color object.
7742 */
7743
7744function hexToRGB(hex) {
7745 var result;
7746
7747 switch (hex.length) {
7748 case 3:
7749 case 4:
7750 result = shortHexRE.exec(hex);
7751 return result ? {
7752 r: _parseInt(result[1] + result[1], 16),
7753 g: _parseInt(result[2] + result[2], 16),
7754 b: _parseInt(result[3] + result[3], 16)
7755 } : null;
7756
7757 case 6:
7758 case 7:
7759 result = fullHexRE.exec(hex);
7760 return result ? {
7761 r: _parseInt(result[1], 16),
7762 g: _parseInt(result[2], 16),
7763 b: _parseInt(result[3], 16)
7764 } : null;
7765
7766 default:
7767 return null;
7768 }
7769}
7770/**
7771 * This function takes string color in hex or RGB format and adds the opacity, RGBA is passed through unchanged.
7772 *
7773 * @param color - The color string (hex, RGB, RGBA).
7774 * @param opacity - The new opacity.
7775 *
7776 * @returns RGBA string, for example 'rgba(255, 0, 127, 0.3)'.
7777 */
7778
7779
7780function overrideOpacity(color, opacity) {
7781 if (includes(color).call(color, "rgba")) {
7782 return color;
7783 } else if (includes(color).call(color, "rgb")) {
7784 var rgb = color.substr(indexOf(color).call(color, "(") + 1).replace(")", "").split(",");
7785 return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + opacity + ")";
7786 } else {
7787 var _rgb = hexToRGB(color);
7788
7789 if (_rgb == null) {
7790 return color;
7791 } else {
7792 return "rgba(" + _rgb.r + "," + _rgb.g + "," + _rgb.b + "," + opacity + ")";
7793 }
7794 }
7795}
7796/**
7797 * Convert RGB \<0, 255\> into hex color string.
7798 *
7799 * @param red - Red channel.
7800 * @param green - Green channel.
7801 * @param blue - Blue channel.
7802 *
7803 * @returns Hex color string (for example: '#0acdc0').
7804 */
7805
7806
7807function RGBToHex(red, green, blue) {
7808 var _context10;
7809
7810 return "#" + slice$2(_context10 = ((1 << 24) + (red << 16) + (green << 8) + blue).toString(16)).call(_context10, 1);
7811}
7812/**
7813 * Parse a color property into an object with border, background, and highlight colors.
7814 *
7815 * @param inputColor - Shorthand color string or input color object.
7816 * @param defaultColor - Full color object to fill in missing values in inputColor.
7817 *
7818 * @returns Color object.
7819 */
7820
7821
7822function parseColor(inputColor, defaultColor) {
7823 if (isString(inputColor)) {
7824 var colorStr = inputColor;
7825
7826 if (isValidRGB(colorStr)) {
7827 var _context11;
7828
7829 var rgb = map$3(_context11 = colorStr.substr(4).substr(0, colorStr.length - 5).split(",")).call(_context11, function (value) {
7830 return _parseInt(value);
7831 });
7832
7833 colorStr = RGBToHex(rgb[0], rgb[1], rgb[2]);
7834 }
7835
7836 if (isValidHex(colorStr) === true) {
7837 var hsv = hexToHSV(colorStr);
7838 var lighterColorHSV = {
7839 h: hsv.h,
7840 s: hsv.s * 0.8,
7841 v: Math.min(1, hsv.v * 1.02)
7842 };
7843 var darkerColorHSV = {
7844 h: hsv.h,
7845 s: Math.min(1, hsv.s * 1.25),
7846 v: hsv.v * 0.8
7847 };
7848 var darkerColorHex = HSVToHex(darkerColorHSV.h, darkerColorHSV.s, darkerColorHSV.v);
7849 var lighterColorHex = HSVToHex(lighterColorHSV.h, lighterColorHSV.s, lighterColorHSV.v);
7850 return {
7851 background: colorStr,
7852 border: darkerColorHex,
7853 highlight: {
7854 background: lighterColorHex,
7855 border: darkerColorHex
7856 },
7857 hover: {
7858 background: lighterColorHex,
7859 border: darkerColorHex
7860 }
7861 };
7862 } else {
7863 return {
7864 background: colorStr,
7865 border: colorStr,
7866 highlight: {
7867 background: colorStr,
7868 border: colorStr
7869 },
7870 hover: {
7871 background: colorStr,
7872 border: colorStr
7873 }
7874 };
7875 }
7876 } else {
7877 if (defaultColor) {
7878 var color = {
7879 background: inputColor.background || defaultColor.background,
7880 border: inputColor.border || defaultColor.border,
7881 highlight: isString(inputColor.highlight) ? {
7882 border: inputColor.highlight,
7883 background: inputColor.highlight
7884 } : {
7885 background: inputColor.highlight && inputColor.highlight.background || defaultColor.highlight.background,
7886 border: inputColor.highlight && inputColor.highlight.border || defaultColor.highlight.border
7887 },
7888 hover: isString(inputColor.hover) ? {
7889 border: inputColor.hover,
7890 background: inputColor.hover
7891 } : {
7892 border: inputColor.hover && inputColor.hover.border || defaultColor.hover.border,
7893 background: inputColor.hover && inputColor.hover.background || defaultColor.hover.background
7894 }
7895 };
7896 return color;
7897 } else {
7898 var _color = {
7899 background: inputColor.background || undefined,
7900 border: inputColor.border || undefined,
7901 highlight: isString(inputColor.highlight) ? {
7902 border: inputColor.highlight,
7903 background: inputColor.highlight
7904 } : {
7905 background: inputColor.highlight && inputColor.highlight.background || undefined,
7906 border: inputColor.highlight && inputColor.highlight.border || undefined
7907 },
7908 hover: isString(inputColor.hover) ? {
7909 border: inputColor.hover,
7910 background: inputColor.hover
7911 } : {
7912 border: inputColor.hover && inputColor.hover.border || undefined,
7913 background: inputColor.hover && inputColor.hover.background || undefined
7914 }
7915 };
7916 return _color;
7917 }
7918 }
7919}
7920/**
7921 * Convert RGB \<0, 255\> into HSV object.
7922 *
7923 * @remarks
7924 * {@link http://www.javascripter.net/faq/rgb2hsv.htm}
7925 *
7926 * @param red - Red channel.
7927 * @param green - Green channel.
7928 * @param blue - Blue channel.
7929 *
7930 * @returns HSV color object.
7931 */
7932
7933
7934function RGBToHSV(red, green, blue) {
7935 red = red / 255;
7936 green = green / 255;
7937 blue = blue / 255;
7938 var minRGB = Math.min(red, Math.min(green, blue));
7939 var maxRGB = Math.max(red, Math.max(green, blue)); // Black-gray-white
7940
7941 if (minRGB === maxRGB) {
7942 return {
7943 h: 0,
7944 s: 0,
7945 v: minRGB
7946 };
7947 } // Colors other than black-gray-white:
7948
7949
7950 var d = red === minRGB ? green - blue : blue === minRGB ? red - green : blue - red;
7951 var h = red === minRGB ? 3 : blue === minRGB ? 1 : 5;
7952 var hue = 60 * (h - d / (maxRGB - minRGB)) / 360;
7953 var saturation = (maxRGB - minRGB) / maxRGB;
7954 var value = maxRGB;
7955 return {
7956 h: hue,
7957 s: saturation,
7958 v: value
7959 };
7960}
7961
7962var cssUtil = {
7963 // split a string with css styles into an object with key/values
7964 split: function split(cssText) {
7965 var _context12;
7966
7967 var styles = {};
7968
7969 forEach$2(_context12 = cssText.split(";")).call(_context12, function (style) {
7970 if (trim$1(style).call(style) != "") {
7971 var _context13, _context14;
7972
7973 var parts = style.split(":");
7974
7975 var key = trim$1(_context13 = parts[0]).call(_context13);
7976
7977 var value = trim$1(_context14 = parts[1]).call(_context14);
7978
7979 styles[key] = value;
7980 }
7981 });
7982
7983 return styles;
7984 },
7985 // build a css text string from an object with key/values
7986 join: function join(styles) {
7987 var _context15;
7988
7989 return map$3(_context15 = keys$3(styles)).call(_context15, function (key) {
7990 return key + ": " + styles[key];
7991 }).join("; ");
7992 }
7993};
7994/**
7995 * Append a string with css styles to an element.
7996 *
7997 * @param element - The element that will receive new styles.
7998 * @param cssText - The styles to be appended.
7999 */
8000
8001function addCssText(element, cssText) {
8002 var currentStyles = cssUtil.split(element.style.cssText);
8003 var newStyles = cssUtil.split(cssText);
8004
8005 var styles = _objectSpread$1(_objectSpread$1({}, currentStyles), newStyles);
8006
8007 element.style.cssText = cssUtil.join(styles);
8008}
8009/**
8010 * Remove a string with css styles from an element.
8011 *
8012 * @param element - The element from which styles should be removed.
8013 * @param cssText - The styles to be removed.
8014 */
8015
8016
8017function removeCssText(element, cssText) {
8018 var styles = cssUtil.split(element.style.cssText);
8019 var removeStyles = cssUtil.split(cssText);
8020
8021 for (var key in removeStyles) {
8022 if (Object.prototype.hasOwnProperty.call(removeStyles, key)) {
8023 delete styles[key];
8024 }
8025 }
8026
8027 element.style.cssText = cssUtil.join(styles);
8028}
8029/**
8030 * Convert HSV \<0, 1\> into RGB color object.
8031 *
8032 * @remarks
8033 * {@link https://gist.github.com/mjijackson/5311256}
8034 *
8035 * @param h - Hue.
8036 * @param s - Saturation.
8037 * @param v - Value.
8038 *
8039 * @returns RGB color object.
8040 */
8041
8042
8043function HSVToRGB(h, s, v) {
8044 var r;
8045 var g;
8046 var b;
8047 var i = Math.floor(h * 6);
8048 var f = h * 6 - i;
8049 var p = v * (1 - s);
8050 var q = v * (1 - f * s);
8051 var t = v * (1 - (1 - f) * s);
8052
8053 switch (i % 6) {
8054 case 0:
8055 r = v, g = t, b = p;
8056 break;
8057
8058 case 1:
8059 r = q, g = v, b = p;
8060 break;
8061
8062 case 2:
8063 r = p, g = v, b = t;
8064 break;
8065
8066 case 3:
8067 r = p, g = q, b = v;
8068 break;
8069
8070 case 4:
8071 r = t, g = p, b = v;
8072 break;
8073
8074 case 5:
8075 r = v, g = p, b = q;
8076 break;
8077 }
8078
8079 return {
8080 r: Math.floor(r * 255),
8081 g: Math.floor(g * 255),
8082 b: Math.floor(b * 255)
8083 };
8084}
8085/**
8086 * Convert HSV \<0, 1\> into hex color string.
8087 *
8088 * @param h - Hue.
8089 * @param s - Saturation.
8090 * @param v - Value.
8091 *
8092 * @returns Hex color string.
8093 */
8094
8095
8096function HSVToHex(h, s, v) {
8097 var rgb = HSVToRGB(h, s, v);
8098 return RGBToHex(rgb.r, rgb.g, rgb.b);
8099}
8100/**
8101 * Convert hex color string into HSV \<0, 1\>.
8102 *
8103 * @param hex - Hex color string.
8104 *
8105 * @returns HSV color object.
8106 */
8107
8108
8109function hexToHSV(hex) {
8110 var rgb = hexToRGB(hex);
8111
8112 if (!rgb) {
8113 throw new TypeError("'".concat(hex, "' is not a valid color."));
8114 }
8115
8116 return RGBToHSV(rgb.r, rgb.g, rgb.b);
8117}
8118/**
8119 * Validate hex color string.
8120 *
8121 * @param hex - Unknown string that may contain a color.
8122 *
8123 * @returns True if the string is valid, false otherwise.
8124 */
8125
8126
8127function isValidHex(hex) {
8128 var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
8129 return isOk;
8130}
8131/**
8132 * Validate RGB color string.
8133 *
8134 * @param rgb - Unknown string that may contain a color.
8135 *
8136 * @returns True if the string is valid, false otherwise.
8137 */
8138
8139
8140function isValidRGB(rgb) {
8141 return rgbRE.test(rgb);
8142}
8143/**
8144 * Validate RGBA color string.
8145 *
8146 * @param rgba - Unknown string that may contain a color.
8147 *
8148 * @returns True if the string is valid, false otherwise.
8149 */
8150
8151
8152function isValidRGBA(rgba) {
8153 return rgbaRE.test(rgba);
8154}
8155/**
8156 * This recursively redirects the prototype of JSON objects to the referenceObject.
8157 * This is used for default options.
8158 *
8159 * @param fields - Names of properties to be bridged.
8160 * @param referenceObject - The original object.
8161 *
8162 * @returns A new object inheriting from the referenceObject.
8163 */
8164
8165
8166function selectiveBridgeObject(fields, referenceObject) {
8167 if (referenceObject !== null && _typeof(referenceObject) === "object") {
8168 // !!! typeof null === 'object'
8169 var objectTo = create$2(referenceObject);
8170
8171 for (var i = 0; i < fields.length; i++) {
8172 if (Object.prototype.hasOwnProperty.call(referenceObject, fields[i])) {
8173 if (_typeof(referenceObject[fields[i]]) == "object") {
8174 objectTo[fields[i]] = bridgeObject(referenceObject[fields[i]]);
8175 }
8176 }
8177 }
8178
8179 return objectTo;
8180 } else {
8181 return null;
8182 }
8183}
8184/**
8185 * This recursively redirects the prototype of JSON objects to the referenceObject.
8186 * This is used for default options.
8187 *
8188 * @param referenceObject - The original object.
8189 *
8190 * @returns The Element if the referenceObject is an Element, or a new object inheriting from the referenceObject.
8191 */
8192
8193
8194function bridgeObject(referenceObject) {
8195 if (referenceObject === null || _typeof(referenceObject) !== "object") {
8196 return null;
8197 }
8198
8199 if (referenceObject instanceof Element) {
8200 // Avoid bridging DOM objects
8201 return referenceObject;
8202 }
8203
8204 var objectTo = create$2(referenceObject);
8205
8206 for (var i in referenceObject) {
8207 if (Object.prototype.hasOwnProperty.call(referenceObject, i)) {
8208 if (_typeof(referenceObject[i]) == "object") {
8209 objectTo[i] = bridgeObject(referenceObject[i]);
8210 }
8211 }
8212 }
8213
8214 return objectTo;
8215}
8216/**
8217 * This method provides a stable sort implementation, very fast for presorted data.
8218 *
8219 * @param a - The array to be sorted (in-place).
8220 * @param compare - An order comparator.
8221 *
8222 * @returns The argument a.
8223 */
8224
8225
8226function insertSort(a, compare) {
8227 for (var i = 0; i < a.length; i++) {
8228 var k = a[i];
8229 var j = void 0;
8230
8231 for (j = i; j > 0 && compare(k, a[j - 1]) < 0; j--) {
8232 a[j] = a[j - 1];
8233 }
8234
8235 a[j] = k;
8236 }
8237
8238 return a;
8239}
8240/**
8241 * This is used to set the options of subobjects in the options object.
8242 *
8243 * A requirement of these subobjects is that they have an 'enabled' element
8244 * which is optional for the user but mandatory for the program.
8245 *
8246 * The added value here of the merge is that option 'enabled' is set as required.
8247 *
8248 * @param mergeTarget - Either this.options or the options used for the groups.
8249 * @param options - Options.
8250 * @param option - Option key in the options argument.
8251 * @param globalOptions - Global options, passed in to determine value of option 'enabled'.
8252 */
8253
8254
8255function mergeOptions(mergeTarget, options, option) {
8256 var globalOptions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
8257
8258 // Local helpers
8259 var isPresent = function isPresent(obj) {
8260 return obj !== null && obj !== undefined;
8261 };
8262
8263 var isObject = function isObject(obj) {
8264 return obj !== null && _typeof(obj) === "object";
8265 }; // https://stackoverflow.com/a/34491287/1223531
8266
8267
8268 var isEmpty = function isEmpty(obj) {
8269 for (var x in obj) {
8270 if (Object.prototype.hasOwnProperty.call(obj, x)) {
8271 return false;
8272 }
8273 }
8274
8275 return true;
8276 }; // Guards
8277
8278
8279 if (!isObject(mergeTarget)) {
8280 throw new Error("Parameter mergeTarget must be an object");
8281 }
8282
8283 if (!isObject(options)) {
8284 throw new Error("Parameter options must be an object");
8285 }
8286
8287 if (!isPresent(option)) {
8288 throw new Error("Parameter option must have a value");
8289 }
8290
8291 if (!isObject(globalOptions)) {
8292 throw new Error("Parameter globalOptions must be an object");
8293 } //
8294 // Actual merge routine, separated from main logic
8295 // Only a single level of options is merged. Deeper levels are ref'd. This may actually be an issue.
8296 //
8297
8298
8299 var doMerge = function doMerge(target, options, option) {
8300 if (!isObject(target[option])) {
8301 target[option] = {};
8302 }
8303
8304 var src = options[option];
8305 var dst = target[option];
8306
8307 for (var prop in src) {
8308 if (Object.prototype.hasOwnProperty.call(src, prop)) {
8309 dst[prop] = src[prop];
8310 }
8311 }
8312 }; // Local initialization
8313
8314
8315 var srcOption = options[option];
8316 var globalPassed = isObject(globalOptions) && !isEmpty(globalOptions);
8317 var globalOption = globalPassed ? globalOptions[option] : undefined;
8318 var globalEnabled = globalOption ? globalOption.enabled : undefined; /////////////////////////////////////////
8319 // Main routine
8320 /////////////////////////////////////////
8321
8322 if (srcOption === undefined) {
8323 return; // Nothing to do
8324 }
8325
8326 if (typeof srcOption === "boolean") {
8327 if (!isObject(mergeTarget[option])) {
8328 mergeTarget[option] = {};
8329 }
8330
8331 mergeTarget[option].enabled = srcOption;
8332 return;
8333 }
8334
8335 if (srcOption === null && !isObject(mergeTarget[option])) {
8336 // If possible, explicit copy from globals
8337 if (isPresent(globalOption)) {
8338 mergeTarget[option] = create$2(globalOption);
8339 } else {
8340 return; // Nothing to do
8341 }
8342 }
8343
8344 if (!isObject(srcOption)) {
8345 return;
8346 } //
8347 // Ensure that 'enabled' is properly set. It is required internally
8348 // Note that the value from options will always overwrite the existing value
8349 //
8350
8351
8352 var enabled = true; // default value
8353
8354 if (srcOption.enabled !== undefined) {
8355 enabled = srcOption.enabled;
8356 } else {
8357 // Take from globals, if present
8358 if (globalEnabled !== undefined) {
8359 enabled = globalOption.enabled;
8360 }
8361 }
8362
8363 doMerge(mergeTarget, options, option);
8364 mergeTarget[option].enabled = enabled;
8365}
8366/**
8367 * This function does a binary search for a visible item in a sorted list. If we find a visible item, the code that uses
8368 * this function will then iterate in both directions over this sorted list to find all visible items.
8369 *
8370 * @param orderedItems - Items ordered by start.
8371 * @param comparator - -1 is lower, 0 is equal, 1 is higher.
8372 * @param field - Property name on an item (That is item[field]).
8373 * @param field2 - Second property name on an item (That is item[field][field2]).
8374 *
8375 * @returns Index of the found item or -1 if nothing was found.
8376 */
8377
8378
8379function binarySearchCustom(orderedItems, comparator, field, field2) {
8380 var maxIterations = 10000;
8381 var iteration = 0;
8382 var low = 0;
8383 var high = orderedItems.length - 1;
8384
8385 while (low <= high && iteration < maxIterations) {
8386 var middle = Math.floor((low + high) / 2);
8387 var item = orderedItems[middle];
8388 var value = field2 === undefined ? item[field] : item[field][field2];
8389 var searchResult = comparator(value);
8390
8391 if (searchResult == 0) {
8392 // jihaa, found a visible item!
8393 return middle;
8394 } else if (searchResult == -1) {
8395 // it is too small --> increase low
8396 low = middle + 1;
8397 } else {
8398 // it is too big --> decrease high
8399 high = middle - 1;
8400 }
8401
8402 iteration++;
8403 }
8404
8405 return -1;
8406}
8407/**
8408 * This function does a binary search for a specific value in a sorted array.
8409 * If it does not exist but is in between of two values, we return either the
8410 * one before or the one after, depending on user input If it is found, we
8411 * return the index, else -1.
8412 *
8413 * @param orderedItems - Sorted array.
8414 * @param target - The searched value.
8415 * @param field - Name of the property in items to be searched.
8416 * @param sidePreference - If the target is between two values, should the index of the before or the after be returned?
8417 * @param comparator - An optional comparator, returning -1, 0, 1 for \<, ===, \>.
8418 *
8419 * @returns The index of found value or -1 if nothing was found.
8420 */
8421
8422
8423function binarySearchValue(orderedItems, target, field, sidePreference, comparator) {
8424 var maxIterations = 10000;
8425 var iteration = 0;
8426 var low = 0;
8427 var high = orderedItems.length - 1;
8428 var prevValue;
8429 var value;
8430 var nextValue;
8431 var middle;
8432 comparator = comparator != undefined ? comparator : function (a, b) {
8433 return a == b ? 0 : a < b ? -1 : 1;
8434 };
8435
8436 while (low <= high && iteration < maxIterations) {
8437 // get a new guess
8438 middle = Math.floor(0.5 * (high + low));
8439 prevValue = orderedItems[Math.max(0, middle - 1)][field];
8440 value = orderedItems[middle][field];
8441 nextValue = orderedItems[Math.min(orderedItems.length - 1, middle + 1)][field];
8442
8443 if (comparator(value, target) == 0) {
8444 // we found the target
8445 return middle;
8446 } else if (comparator(prevValue, target) < 0 && comparator(value, target) > 0) {
8447 // target is in between of the previous and the current
8448 return sidePreference == "before" ? Math.max(0, middle - 1) : middle;
8449 } else if (comparator(value, target) < 0 && comparator(nextValue, target) > 0) {
8450 // target is in between of the current and the next
8451 return sidePreference == "before" ? middle : Math.min(orderedItems.length - 1, middle + 1);
8452 } else {
8453 // didnt find the target, we need to change our boundaries.
8454 if (comparator(value, target) < 0) {
8455 // it is too small --> increase low
8456 low = middle + 1;
8457 } else {
8458 // it is too big --> decrease high
8459 high = middle - 1;
8460 }
8461 }
8462
8463 iteration++;
8464 } // didnt find anything. Return -1.
8465
8466
8467 return -1;
8468}
8469/*
8470 * Easing Functions.
8471 * Only considering the t value for the range [0, 1] => [0, 1].
8472 *
8473 * Inspiration: from http://gizma.com/easing/
8474 * https://gist.github.com/gre/1650294
8475 */
8476
8477
8478var easingFunctions = {
8479 /**
8480 * Provides no easing and no acceleration.
8481 *
8482 * @param t - Time.
8483 *
8484 * @returns Value at time t.
8485 */
8486 linear: function linear(t) {
8487 return t;
8488 },
8489
8490 /**
8491 * Accelerate from zero velocity.
8492 *
8493 * @param t - Time.
8494 *
8495 * @returns Value at time t.
8496 */
8497 easeInQuad: function easeInQuad(t) {
8498 return t * t;
8499 },
8500
8501 /**
8502 * Decelerate to zero velocity.
8503 *
8504 * @param t - Time.
8505 *
8506 * @returns Value at time t.
8507 */
8508 easeOutQuad: function easeOutQuad(t) {
8509 return t * (2 - t);
8510 },
8511
8512 /**
8513 * Accelerate until halfway, then decelerate.
8514 *
8515 * @param t - Time.
8516 *
8517 * @returns Value at time t.
8518 */
8519 easeInOutQuad: function easeInOutQuad(t) {
8520 return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
8521 },
8522
8523 /**
8524 * Accelerate from zero velocity.
8525 *
8526 * @param t - Time.
8527 *
8528 * @returns Value at time t.
8529 */
8530 easeInCubic: function easeInCubic(t) {
8531 return t * t * t;
8532 },
8533
8534 /**
8535 * Decelerate to zero velocity.
8536 *
8537 * @param t - Time.
8538 *
8539 * @returns Value at time t.
8540 */
8541 easeOutCubic: function easeOutCubic(t) {
8542 return --t * t * t + 1;
8543 },
8544
8545 /**
8546 * Accelerate until halfway, then decelerate.
8547 *
8548 * @param t - Time.
8549 *
8550 * @returns Value at time t.
8551 */
8552 easeInOutCubic: function easeInOutCubic(t) {
8553 return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
8554 },
8555
8556 /**
8557 * Accelerate from zero velocity.
8558 *
8559 * @param t - Time.
8560 *
8561 * @returns Value at time t.
8562 */
8563 easeInQuart: function easeInQuart(t) {
8564 return t * t * t * t;
8565 },
8566
8567 /**
8568 * Decelerate to zero velocity.
8569 *
8570 * @param t - Time.
8571 *
8572 * @returns Value at time t.
8573 */
8574 easeOutQuart: function easeOutQuart(t) {
8575 return 1 - --t * t * t * t;
8576 },
8577
8578 /**
8579 * Accelerate until halfway, then decelerate.
8580 *
8581 * @param t - Time.
8582 *
8583 * @returns Value at time t.
8584 */
8585 easeInOutQuart: function easeInOutQuart(t) {
8586 return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * --t * t * t * t;
8587 },
8588
8589 /**
8590 * Accelerate from zero velocity.
8591 *
8592 * @param t - Time.
8593 *
8594 * @returns Value at time t.
8595 */
8596 easeInQuint: function easeInQuint(t) {
8597 return t * t * t * t * t;
8598 },
8599
8600 /**
8601 * Decelerate to zero velocity.
8602 *
8603 * @param t - Time.
8604 *
8605 * @returns Value at time t.
8606 */
8607 easeOutQuint: function easeOutQuint(t) {
8608 return 1 + --t * t * t * t * t;
8609 },
8610
8611 /**
8612 * Accelerate until halfway, then decelerate.
8613 *
8614 * @param t - Time.
8615 *
8616 * @returns Value at time t.
8617 */
8618 easeInOutQuint: function easeInOutQuint(t) {
8619 return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
8620 }
8621};
8622/**
8623 * Experimentaly compute the width of the scrollbar for this browser.
8624 *
8625 * @returns The width in pixels.
8626 */
8627
8628function getScrollBarWidth() {
8629 var inner = document.createElement("p");
8630 inner.style.width = "100%";
8631 inner.style.height = "200px";
8632 var outer = document.createElement("div");
8633 outer.style.position = "absolute";
8634 outer.style.top = "0px";
8635 outer.style.left = "0px";
8636 outer.style.visibility = "hidden";
8637 outer.style.width = "200px";
8638 outer.style.height = "150px";
8639 outer.style.overflow = "hidden";
8640 outer.appendChild(inner);
8641 document.body.appendChild(outer);
8642 var w1 = inner.offsetWidth;
8643 outer.style.overflow = "scroll";
8644 var w2 = inner.offsetWidth;
8645
8646 if (w1 == w2) {
8647 w2 = outer.clientWidth;
8648 }
8649
8650 document.body.removeChild(outer);
8651 return w1 - w2;
8652} // @TODO: This doesn't work properly.
8653// It works only for single property objects,
8654// otherwise it combines all of the types in a union.
8655// export function topMost<K1 extends string, V1> (
8656// pile: Record<K1, undefined | V1>[],
8657// accessors: K1 | [K1]
8658// ): undefined | V1
8659// export function topMost<K1 extends string, K2 extends string, V1, V2> (
8660// pile: Record<K1, undefined | V1 | Record<K2, undefined | V2>>[],
8661// accessors: [K1, K2]
8662// ): undefined | V1 | V2
8663// export function topMost<K1 extends string, K2 extends string, K3 extends string, V1, V2, V3> (
8664// pile: Record<K1, undefined | V1 | Record<K2, undefined | V2 | Record<K3, undefined | V3>>>[],
8665// accessors: [K1, K2, K3]
8666// ): undefined | V1 | V2 | V3
8667
8668/**
8669 * Get the top most property value from a pile of objects.
8670 *
8671 * @param pile - Array of objects, no required format.
8672 * @param accessors - Array of property names.
8673 * For example `object['foo']['bar']` → `['foo', 'bar']`.
8674 *
8675 * @returns Value of the property with given accessors path from the first pile item where it's not undefined.
8676 */
8677
8678
8679function topMost(pile, accessors) {
8680 var candidate;
8681
8682 if (!isArray(accessors)) {
8683 accessors = [accessors];
8684 }
8685
8686 var _iterator3 = _createForOfIteratorHelper$1(pile),
8687 _step3;
8688
8689 try {
8690 for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
8691 var member = _step3.value;
8692
8693 if (member) {
8694 candidate = member[accessors[0]];
8695
8696 for (var i = 1; i < accessors.length; i++) {
8697 if (candidate) {
8698 candidate = candidate[accessors[i]];
8699 }
8700 }
8701
8702 if (typeof candidate !== "undefined") {
8703 break;
8704 }
8705 }
8706 }
8707 } catch (err) {
8708 _iterator3.e(err);
8709 } finally {
8710 _iterator3.f();
8711 }
8712
8713 return candidate;
8714}
8715
8716var htmlColors = {
8717 black: "#000000",
8718 navy: "#000080",
8719 darkblue: "#00008B",
8720 mediumblue: "#0000CD",
8721 blue: "#0000FF",
8722 darkgreen: "#006400",
8723 green: "#008000",
8724 teal: "#008080",
8725 darkcyan: "#008B8B",
8726 deepskyblue: "#00BFFF",
8727 darkturquoise: "#00CED1",
8728 mediumspringgreen: "#00FA9A",
8729 lime: "#00FF00",
8730 springgreen: "#00FF7F",
8731 aqua: "#00FFFF",
8732 cyan: "#00FFFF",
8733 midnightblue: "#191970",
8734 dodgerblue: "#1E90FF",
8735 lightseagreen: "#20B2AA",
8736 forestgreen: "#228B22",
8737 seagreen: "#2E8B57",
8738 darkslategray: "#2F4F4F",
8739 limegreen: "#32CD32",
8740 mediumseagreen: "#3CB371",
8741 turquoise: "#40E0D0",
8742 royalblue: "#4169E1",
8743 steelblue: "#4682B4",
8744 darkslateblue: "#483D8B",
8745 mediumturquoise: "#48D1CC",
8746 indigo: "#4B0082",
8747 darkolivegreen: "#556B2F",
8748 cadetblue: "#5F9EA0",
8749 cornflowerblue: "#6495ED",
8750 mediumaquamarine: "#66CDAA",
8751 dimgray: "#696969",
8752 slateblue: "#6A5ACD",
8753 olivedrab: "#6B8E23",
8754 slategray: "#708090",
8755 lightslategray: "#778899",
8756 mediumslateblue: "#7B68EE",
8757 lawngreen: "#7CFC00",
8758 chartreuse: "#7FFF00",
8759 aquamarine: "#7FFFD4",
8760 maroon: "#800000",
8761 purple: "#800080",
8762 olive: "#808000",
8763 gray: "#808080",
8764 skyblue: "#87CEEB",
8765 lightskyblue: "#87CEFA",
8766 blueviolet: "#8A2BE2",
8767 darkred: "#8B0000",
8768 darkmagenta: "#8B008B",
8769 saddlebrown: "#8B4513",
8770 darkseagreen: "#8FBC8F",
8771 lightgreen: "#90EE90",
8772 mediumpurple: "#9370D8",
8773 darkviolet: "#9400D3",
8774 palegreen: "#98FB98",
8775 darkorchid: "#9932CC",
8776 yellowgreen: "#9ACD32",
8777 sienna: "#A0522D",
8778 brown: "#A52A2A",
8779 darkgray: "#A9A9A9",
8780 lightblue: "#ADD8E6",
8781 greenyellow: "#ADFF2F",
8782 paleturquoise: "#AFEEEE",
8783 lightsteelblue: "#B0C4DE",
8784 powderblue: "#B0E0E6",
8785 firebrick: "#B22222",
8786 darkgoldenrod: "#B8860B",
8787 mediumorchid: "#BA55D3",
8788 rosybrown: "#BC8F8F",
8789 darkkhaki: "#BDB76B",
8790 silver: "#C0C0C0",
8791 mediumvioletred: "#C71585",
8792 indianred: "#CD5C5C",
8793 peru: "#CD853F",
8794 chocolate: "#D2691E",
8795 tan: "#D2B48C",
8796 lightgrey: "#D3D3D3",
8797 palevioletred: "#D87093",
8798 thistle: "#D8BFD8",
8799 orchid: "#DA70D6",
8800 goldenrod: "#DAA520",
8801 crimson: "#DC143C",
8802 gainsboro: "#DCDCDC",
8803 plum: "#DDA0DD",
8804 burlywood: "#DEB887",
8805 lightcyan: "#E0FFFF",
8806 lavender: "#E6E6FA",
8807 darksalmon: "#E9967A",
8808 violet: "#EE82EE",
8809 palegoldenrod: "#EEE8AA",
8810 lightcoral: "#F08080",
8811 khaki: "#F0E68C",
8812 aliceblue: "#F0F8FF",
8813 honeydew: "#F0FFF0",
8814 azure: "#F0FFFF",
8815 sandybrown: "#F4A460",
8816 wheat: "#F5DEB3",
8817 beige: "#F5F5DC",
8818 whitesmoke: "#F5F5F5",
8819 mintcream: "#F5FFFA",
8820 ghostwhite: "#F8F8FF",
8821 salmon: "#FA8072",
8822 antiquewhite: "#FAEBD7",
8823 linen: "#FAF0E6",
8824 lightgoldenrodyellow: "#FAFAD2",
8825 oldlace: "#FDF5E6",
8826 red: "#FF0000",
8827 fuchsia: "#FF00FF",
8828 magenta: "#FF00FF",
8829 deeppink: "#FF1493",
8830 orangered: "#FF4500",
8831 tomato: "#FF6347",
8832 hotpink: "#FF69B4",
8833 coral: "#FF7F50",
8834 darkorange: "#FF8C00",
8835 lightsalmon: "#FFA07A",
8836 orange: "#FFA500",
8837 lightpink: "#FFB6C1",
8838 pink: "#FFC0CB",
8839 gold: "#FFD700",
8840 peachpuff: "#FFDAB9",
8841 navajowhite: "#FFDEAD",
8842 moccasin: "#FFE4B5",
8843 bisque: "#FFE4C4",
8844 mistyrose: "#FFE4E1",
8845 blanchedalmond: "#FFEBCD",
8846 papayawhip: "#FFEFD5",
8847 lavenderblush: "#FFF0F5",
8848 seashell: "#FFF5EE",
8849 cornsilk: "#FFF8DC",
8850 lemonchiffon: "#FFFACD",
8851 floralwhite: "#FFFAF0",
8852 snow: "#FFFAFA",
8853 yellow: "#FFFF00",
8854 lightyellow: "#FFFFE0",
8855 ivory: "#FFFFF0",
8856 white: "#FFFFFF"
8857};
8858/**
8859 * @param {number} [pixelRatio=1]
8860 */
8861
8862var ColorPicker = /*#__PURE__*/function () {
8863 /**
8864 * @param {number} [pixelRatio=1]
8865 */
8866 function ColorPicker() {
8867 var pixelRatio = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
8868
8869 _classCallCheck(this, ColorPicker);
8870
8871 this.pixelRatio = pixelRatio;
8872 this.generated = false;
8873 this.centerCoordinates = {
8874 x: 289 / 2,
8875 y: 289 / 2
8876 };
8877 this.r = 289 * 0.49;
8878 this.color = {
8879 r: 255,
8880 g: 255,
8881 b: 255,
8882 a: 1.0
8883 };
8884 this.hueCircle = undefined;
8885 this.initialColor = {
8886 r: 255,
8887 g: 255,
8888 b: 255,
8889 a: 1.0
8890 };
8891 this.previousColor = undefined;
8892 this.applied = false; // bound by
8893
8894 this.updateCallback = function () {};
8895
8896 this.closeCallback = function () {}; // create all DOM elements
8897
8898
8899 this._create();
8900 }
8901 /**
8902 * this inserts the colorPicker into a div from the DOM
8903 *
8904 * @param {Element} container
8905 */
8906
8907
8908 _createClass(ColorPicker, [{
8909 key: "insertTo",
8910 value: function insertTo(container) {
8911 if (this.hammer !== undefined) {
8912 this.hammer.destroy();
8913 this.hammer = undefined;
8914 }
8915
8916 this.container = container;
8917 this.container.appendChild(this.frame);
8918
8919 this._bindHammer();
8920
8921 this._setSize();
8922 }
8923 /**
8924 * the callback is executed on apply and save. Bind it to the application
8925 *
8926 * @param {Function} callback
8927 */
8928
8929 }, {
8930 key: "setUpdateCallback",
8931 value: function setUpdateCallback(callback) {
8932 if (typeof callback === "function") {
8933 this.updateCallback = callback;
8934 } else {
8935 throw new Error("Function attempted to set as colorPicker update callback is not a function.");
8936 }
8937 }
8938 /**
8939 * the callback is executed on apply and save. Bind it to the application
8940 *
8941 * @param {Function} callback
8942 */
8943
8944 }, {
8945 key: "setCloseCallback",
8946 value: function setCloseCallback(callback) {
8947 if (typeof callback === "function") {
8948 this.closeCallback = callback;
8949 } else {
8950 throw new Error("Function attempted to set as colorPicker closing callback is not a function.");
8951 }
8952 }
8953 /**
8954 *
8955 * @param {string} color
8956 * @returns {string}
8957 * @private
8958 */
8959
8960 }, {
8961 key: "_isColorString",
8962 value: function _isColorString(color) {
8963 if (typeof color === "string") {
8964 return htmlColors[color];
8965 }
8966 }
8967 /**
8968 * Set the color of the colorPicker
8969 * Supported formats:
8970 * 'red' --> HTML color string
8971 * '#ffffff' --> hex string
8972 * 'rgb(255,255,255)' --> rgb string
8973 * 'rgba(255,255,255,1.0)' --> rgba string
8974 * {r:255,g:255,b:255} --> rgb object
8975 * {r:255,g:255,b:255,a:1.0} --> rgba object
8976 *
8977 * @param {string | object} color
8978 * @param {boolean} [setInitial=true]
8979 */
8980
8981 }, {
8982 key: "setColor",
8983 value: function setColor(color) {
8984 var setInitial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
8985
8986 if (color === "none") {
8987 return;
8988 }
8989
8990 var rgba; // if a html color shorthand is used, convert to hex
8991
8992 var htmlColor = this._isColorString(color);
8993
8994 if (htmlColor !== undefined) {
8995 color = htmlColor;
8996 } // check format
8997
8998
8999 if (isString(color) === true) {
9000 if (isValidRGB(color) === true) {
9001 var rgbaArray = color.substr(4).substr(0, color.length - 5).split(",");
9002 rgba = {
9003 r: rgbaArray[0],
9004 g: rgbaArray[1],
9005 b: rgbaArray[2],
9006 a: 1.0
9007 };
9008 } else if (isValidRGBA(color) === true) {
9009 var _rgbaArray = color.substr(5).substr(0, color.length - 6).split(",");
9010
9011 rgba = {
9012 r: _rgbaArray[0],
9013 g: _rgbaArray[1],
9014 b: _rgbaArray[2],
9015 a: _rgbaArray[3]
9016 };
9017 } else if (isValidHex(color) === true) {
9018 var rgbObj = hexToRGB(color);
9019 rgba = {
9020 r: rgbObj.r,
9021 g: rgbObj.g,
9022 b: rgbObj.b,
9023 a: 1.0
9024 };
9025 }
9026 } else {
9027 if (color instanceof Object) {
9028 if (color.r !== undefined && color.g !== undefined && color.b !== undefined) {
9029 var alpha = color.a !== undefined ? color.a : "1.0";
9030 rgba = {
9031 r: color.r,
9032 g: color.g,
9033 b: color.b,
9034 a: alpha
9035 };
9036 }
9037 }
9038 } // set color
9039
9040
9041 if (rgba === undefined) {
9042 throw new Error("Unknown color passed to the colorPicker. Supported are strings: rgb, hex, rgba. Object: rgb ({r:r,g:g,b:b,[a:a]}). Supplied: " + stringify$1(color));
9043 } else {
9044 this._setColor(rgba, setInitial);
9045 }
9046 }
9047 /**
9048 * this shows the color picker.
9049 * The hue circle is constructed once and stored.
9050 */
9051
9052 }, {
9053 key: "show",
9054 value: function show() {
9055 if (this.closeCallback !== undefined) {
9056 this.closeCallback();
9057 this.closeCallback = undefined;
9058 }
9059
9060 this.applied = false;
9061 this.frame.style.display = "block";
9062
9063 this._generateHueCircle();
9064 } // ------------------------------------------ PRIVATE ----------------------------- //
9065
9066 /**
9067 * Hide the picker. Is called by the cancel button.
9068 * Optional boolean to store the previous color for easy access later on.
9069 *
9070 * @param {boolean} [storePrevious=true]
9071 * @private
9072 */
9073
9074 }, {
9075 key: "_hide",
9076 value: function _hide() {
9077 var _this2 = this;
9078
9079 var storePrevious = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
9080
9081 // store the previous color for next time;
9082 if (storePrevious === true) {
9083 this.previousColor = assign$2({}, this.color);
9084 }
9085
9086 if (this.applied === true) {
9087 this.updateCallback(this.initialColor);
9088 }
9089
9090 this.frame.style.display = "none"; // call the closing callback, restoring the onclick method.
9091 // this is in a setTimeout because it will trigger the show again before the click is done.
9092
9093 setTimeout$1(function () {
9094 if (_this2.closeCallback !== undefined) {
9095 _this2.closeCallback();
9096
9097 _this2.closeCallback = undefined;
9098 }
9099 }, 0);
9100 }
9101 /**
9102 * bound to the save button. Saves and hides.
9103 *
9104 * @private
9105 */
9106
9107 }, {
9108 key: "_save",
9109 value: function _save() {
9110 this.updateCallback(this.color);
9111 this.applied = false;
9112
9113 this._hide();
9114 }
9115 /**
9116 * Bound to apply button. Saves but does not close. Is undone by the cancel button.
9117 *
9118 * @private
9119 */
9120
9121 }, {
9122 key: "_apply",
9123 value: function _apply() {
9124 this.applied = true;
9125 this.updateCallback(this.color);
9126
9127 this._updatePicker(this.color);
9128 }
9129 /**
9130 * load the color from the previous session.
9131 *
9132 * @private
9133 */
9134
9135 }, {
9136 key: "_loadLast",
9137 value: function _loadLast() {
9138 if (this.previousColor !== undefined) {
9139 this.setColor(this.previousColor, false);
9140 } else {
9141 alert("There is no last color to load...");
9142 }
9143 }
9144 /**
9145 * set the color, place the picker
9146 *
9147 * @param {object} rgba
9148 * @param {boolean} [setInitial=true]
9149 * @private
9150 */
9151
9152 }, {
9153 key: "_setColor",
9154 value: function _setColor(rgba) {
9155 var setInitial = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
9156
9157 // store the initial color
9158 if (setInitial === true) {
9159 this.initialColor = assign$2({}, rgba);
9160 }
9161
9162 this.color = rgba;
9163 var hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
9164 var angleConvert = 2 * Math.PI;
9165 var radius = this.r * hsv.s;
9166 var x = this.centerCoordinates.x + radius * Math.sin(angleConvert * hsv.h);
9167 var y = this.centerCoordinates.y + radius * Math.cos(angleConvert * hsv.h);
9168 this.colorPickerSelector.style.left = x - 0.5 * this.colorPickerSelector.clientWidth + "px";
9169 this.colorPickerSelector.style.top = y - 0.5 * this.colorPickerSelector.clientHeight + "px";
9170
9171 this._updatePicker(rgba);
9172 }
9173 /**
9174 * bound to opacity control
9175 *
9176 * @param {number} value
9177 * @private
9178 */
9179
9180 }, {
9181 key: "_setOpacity",
9182 value: function _setOpacity(value) {
9183 this.color.a = value / 100;
9184
9185 this._updatePicker(this.color);
9186 }
9187 /**
9188 * bound to brightness control
9189 *
9190 * @param {number} value
9191 * @private
9192 */
9193
9194 }, {
9195 key: "_setBrightness",
9196 value: function _setBrightness(value) {
9197 var hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
9198 hsv.v = value / 100;
9199 var rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
9200 rgba["a"] = this.color.a;
9201 this.color = rgba;
9202
9203 this._updatePicker();
9204 }
9205 /**
9206 * update the color picker. A black circle overlays the hue circle to mimic the brightness decreasing.
9207 *
9208 * @param {object} rgba
9209 * @private
9210 */
9211
9212 }, {
9213 key: "_updatePicker",
9214 value: function _updatePicker() {
9215 var rgba = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.color;
9216 var hsv = RGBToHSV(rgba.r, rgba.g, rgba.b);
9217 var ctx = this.colorPickerCanvas.getContext("2d");
9218
9219 if (this.pixelRation === undefined) {
9220 this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1);
9221 }
9222
9223 ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0); // clear the canvas
9224
9225 var w = this.colorPickerCanvas.clientWidth;
9226 var h = this.colorPickerCanvas.clientHeight;
9227 ctx.clearRect(0, 0, w, h);
9228 ctx.putImageData(this.hueCircle, 0, 0);
9229 ctx.fillStyle = "rgba(0,0,0," + (1 - hsv.v) + ")";
9230 ctx.circle(this.centerCoordinates.x, this.centerCoordinates.y, this.r);
9231
9232 fill(ctx).call(ctx);
9233
9234 this.brightnessRange.value = 100 * hsv.v;
9235 this.opacityRange.value = 100 * rgba.a;
9236 this.initialColorDiv.style.backgroundColor = "rgba(" + this.initialColor.r + "," + this.initialColor.g + "," + this.initialColor.b + "," + this.initialColor.a + ")";
9237 this.newColorDiv.style.backgroundColor = "rgba(" + this.color.r + "," + this.color.g + "," + this.color.b + "," + this.color.a + ")";
9238 }
9239 /**
9240 * used by create to set the size of the canvas.
9241 *
9242 * @private
9243 */
9244
9245 }, {
9246 key: "_setSize",
9247 value: function _setSize() {
9248 this.colorPickerCanvas.style.width = "100%";
9249 this.colorPickerCanvas.style.height = "100%";
9250 this.colorPickerCanvas.width = 289 * this.pixelRatio;
9251 this.colorPickerCanvas.height = 289 * this.pixelRatio;
9252 }
9253 /**
9254 * create all dom elements
9255 * TODO: cleanup, lots of similar dom elements
9256 *
9257 * @private
9258 */
9259
9260 }, {
9261 key: "_create",
9262 value: function _create() {
9263 var _context16, _context17, _context18, _context19;
9264
9265 this.frame = document.createElement("div");
9266 this.frame.className = "vis-color-picker";
9267 this.colorPickerDiv = document.createElement("div");
9268 this.colorPickerSelector = document.createElement("div");
9269 this.colorPickerSelector.className = "vis-selector";
9270 this.colorPickerDiv.appendChild(this.colorPickerSelector);
9271 this.colorPickerCanvas = document.createElement("canvas");
9272 this.colorPickerDiv.appendChild(this.colorPickerCanvas);
9273
9274 if (!this.colorPickerCanvas.getContext) {
9275 var noCanvas = document.createElement("DIV");
9276 noCanvas.style.color = "red";
9277 noCanvas.style.fontWeight = "bold";
9278 noCanvas.style.padding = "10px";
9279 noCanvas.innerText = "Error: your browser does not support HTML canvas";
9280 this.colorPickerCanvas.appendChild(noCanvas);
9281 } else {
9282 var ctx = this.colorPickerCanvas.getContext("2d");
9283 this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1);
9284 this.colorPickerCanvas.getContext("2d").setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0);
9285 }
9286
9287 this.colorPickerDiv.className = "vis-color";
9288 this.opacityDiv = document.createElement("div");
9289 this.opacityDiv.className = "vis-opacity";
9290 this.brightnessDiv = document.createElement("div");
9291 this.brightnessDiv.className = "vis-brightness";
9292 this.arrowDiv = document.createElement("div");
9293 this.arrowDiv.className = "vis-arrow";
9294 this.opacityRange = document.createElement("input");
9295
9296 try {
9297 this.opacityRange.type = "range"; // Not supported on IE9
9298
9299 this.opacityRange.min = "0";
9300 this.opacityRange.max = "100";
9301 } catch (err) {// TODO: Add some error handling.
9302 }
9303
9304 this.opacityRange.value = "100";
9305 this.opacityRange.className = "vis-range";
9306 this.brightnessRange = document.createElement("input");
9307
9308 try {
9309 this.brightnessRange.type = "range"; // Not supported on IE9
9310
9311 this.brightnessRange.min = "0";
9312 this.brightnessRange.max = "100";
9313 } catch (err) {// TODO: Add some error handling.
9314 }
9315
9316 this.brightnessRange.value = "100";
9317 this.brightnessRange.className = "vis-range";
9318 this.opacityDiv.appendChild(this.opacityRange);
9319 this.brightnessDiv.appendChild(this.brightnessRange);
9320 var me = this;
9321
9322 this.opacityRange.onchange = function () {
9323 me._setOpacity(this.value);
9324 };
9325
9326 this.opacityRange.oninput = function () {
9327 me._setOpacity(this.value);
9328 };
9329
9330 this.brightnessRange.onchange = function () {
9331 me._setBrightness(this.value);
9332 };
9333
9334 this.brightnessRange.oninput = function () {
9335 me._setBrightness(this.value);
9336 };
9337
9338 this.brightnessLabel = document.createElement("div");
9339 this.brightnessLabel.className = "vis-label vis-brightness";
9340 this.brightnessLabel.innerText = "brightness:";
9341 this.opacityLabel = document.createElement("div");
9342 this.opacityLabel.className = "vis-label vis-opacity";
9343 this.opacityLabel.innerText = "opacity:";
9344 this.newColorDiv = document.createElement("div");
9345 this.newColorDiv.className = "vis-new-color";
9346 this.newColorDiv.innerText = "new";
9347 this.initialColorDiv = document.createElement("div");
9348 this.initialColorDiv.className = "vis-initial-color";
9349 this.initialColorDiv.innerText = "initial";
9350 this.cancelButton = document.createElement("div");
9351 this.cancelButton.className = "vis-button vis-cancel";
9352 this.cancelButton.innerText = "cancel";
9353 this.cancelButton.onclick = bind(_context16 = this._hide).call(_context16, this, false);
9354 this.applyButton = document.createElement("div");
9355 this.applyButton.className = "vis-button vis-apply";
9356 this.applyButton.innerText = "apply";
9357 this.applyButton.onclick = bind(_context17 = this._apply).call(_context17, this);
9358 this.saveButton = document.createElement("div");
9359 this.saveButton.className = "vis-button vis-save";
9360 this.saveButton.innerText = "save";
9361 this.saveButton.onclick = bind(_context18 = this._save).call(_context18, this);
9362 this.loadButton = document.createElement("div");
9363 this.loadButton.className = "vis-button vis-load";
9364 this.loadButton.innerText = "load last";
9365 this.loadButton.onclick = bind(_context19 = this._loadLast).call(_context19, this);
9366 this.frame.appendChild(this.colorPickerDiv);
9367 this.frame.appendChild(this.arrowDiv);
9368 this.frame.appendChild(this.brightnessLabel);
9369 this.frame.appendChild(this.brightnessDiv);
9370 this.frame.appendChild(this.opacityLabel);
9371 this.frame.appendChild(this.opacityDiv);
9372 this.frame.appendChild(this.newColorDiv);
9373 this.frame.appendChild(this.initialColorDiv);
9374 this.frame.appendChild(this.cancelButton);
9375 this.frame.appendChild(this.applyButton);
9376 this.frame.appendChild(this.saveButton);
9377 this.frame.appendChild(this.loadButton);
9378 }
9379 /**
9380 * bind hammer to the color picker
9381 *
9382 * @private
9383 */
9384
9385 }, {
9386 key: "_bindHammer",
9387 value: function _bindHammer() {
9388 var _this3 = this;
9389
9390 this.drag = {};
9391 this.pinch = {};
9392 this.hammer = new Hammer$1(this.colorPickerCanvas);
9393 this.hammer.get("pinch").set({
9394 enable: true
9395 });
9396 this.hammer.on("hammer.input", function (event) {
9397 if (event.isFirst) {
9398 _this3._moveSelector(event);
9399 }
9400 });
9401 this.hammer.on("tap", function (event) {
9402 _this3._moveSelector(event);
9403 });
9404 this.hammer.on("panstart", function (event) {
9405 _this3._moveSelector(event);
9406 });
9407 this.hammer.on("panmove", function (event) {
9408 _this3._moveSelector(event);
9409 });
9410 this.hammer.on("panend", function (event) {
9411 _this3._moveSelector(event);
9412 });
9413 }
9414 /**
9415 * generate the hue circle. This is relatively heavy (200ms) and is done only once on the first time it is shown.
9416 *
9417 * @private
9418 */
9419
9420 }, {
9421 key: "_generateHueCircle",
9422 value: function _generateHueCircle() {
9423 if (this.generated === false) {
9424 var ctx = this.colorPickerCanvas.getContext("2d");
9425
9426 if (this.pixelRation === undefined) {
9427 this.pixelRatio = (window.devicePixelRatio || 1) / (ctx.webkitBackingStorePixelRatio || ctx.mozBackingStorePixelRatio || ctx.msBackingStorePixelRatio || ctx.oBackingStorePixelRatio || ctx.backingStorePixelRatio || 1);
9428 }
9429
9430 ctx.setTransform(this.pixelRatio, 0, 0, this.pixelRatio, 0, 0); // clear the canvas
9431
9432 var w = this.colorPickerCanvas.clientWidth;
9433 var h = this.colorPickerCanvas.clientHeight;
9434 ctx.clearRect(0, 0, w, h); // draw hue circle
9435
9436 var x, y, hue, sat;
9437 this.centerCoordinates = {
9438 x: w * 0.5,
9439 y: h * 0.5
9440 };
9441 this.r = 0.49 * w;
9442 var angleConvert = 2 * Math.PI / 360;
9443 var hfac = 1 / 360;
9444 var sfac = 1 / this.r;
9445 var rgb;
9446
9447 for (hue = 0; hue < 360; hue++) {
9448 for (sat = 0; sat < this.r; sat++) {
9449 x = this.centerCoordinates.x + sat * Math.sin(angleConvert * hue);
9450 y = this.centerCoordinates.y + sat * Math.cos(angleConvert * hue);
9451 rgb = HSVToRGB(hue * hfac, sat * sfac, 1);
9452 ctx.fillStyle = "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
9453 ctx.fillRect(x - 0.5, y - 0.5, 2, 2);
9454 }
9455 }
9456
9457 ctx.strokeStyle = "rgba(0,0,0,1)";
9458 ctx.circle(this.centerCoordinates.x, this.centerCoordinates.y, this.r);
9459 ctx.stroke();
9460 this.hueCircle = ctx.getImageData(0, 0, w, h);
9461 }
9462
9463 this.generated = true;
9464 }
9465 /**
9466 * move the selector. This is called by hammer functions.
9467 *
9468 * @param {Event} event The event
9469 * @private
9470 */
9471
9472 }, {
9473 key: "_moveSelector",
9474 value: function _moveSelector(event) {
9475 var rect = this.colorPickerDiv.getBoundingClientRect();
9476 var left = event.center.x - rect.left;
9477 var top = event.center.y - rect.top;
9478 var centerY = 0.5 * this.colorPickerDiv.clientHeight;
9479 var centerX = 0.5 * this.colorPickerDiv.clientWidth;
9480 var x = left - centerX;
9481 var y = top - centerY;
9482 var angle = Math.atan2(x, y);
9483 var radius = 0.98 * Math.min(Math.sqrt(x * x + y * y), centerX);
9484 var newTop = Math.cos(angle) * radius + centerY;
9485 var newLeft = Math.sin(angle) * radius + centerX;
9486 this.colorPickerSelector.style.top = newTop - 0.5 * this.colorPickerSelector.clientHeight + "px";
9487 this.colorPickerSelector.style.left = newLeft - 0.5 * this.colorPickerSelector.clientWidth + "px"; // set color
9488
9489 var h = angle / (2 * Math.PI);
9490 h = h < 0 ? h + 1 : h;
9491 var s = radius / this.r;
9492 var hsv = RGBToHSV(this.color.r, this.color.g, this.color.b);
9493 hsv.h = h;
9494 hsv.s = s;
9495 var rgba = HSVToRGB(hsv.h, hsv.s, hsv.v);
9496 rgba["a"] = this.color.a;
9497 this.color = rgba; // update previews
9498
9499 this.initialColorDiv.style.backgroundColor = "rgba(" + this.initialColor.r + "," + this.initialColor.g + "," + this.initialColor.b + "," + this.initialColor.a + ")";
9500 this.newColorDiv.style.backgroundColor = "rgba(" + this.color.r + "," + this.color.g + "," + this.color.b + "," + this.color.a + ")";
9501 }
9502 }]);
9503
9504 return ColorPicker;
9505}();
9506/**
9507 * Wrap given text (last argument) in HTML elements (all preceding arguments).
9508 *
9509 * @param {...any} rest - List of tag names followed by inner text.
9510 *
9511 * @returns An element or a text node.
9512 */
9513
9514
9515function wrapInTag() {
9516 for (var _len5 = arguments.length, rest = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
9517 rest[_key5] = arguments[_key5];
9518 }
9519
9520 if (rest.length < 1) {
9521 throw new TypeError("Invalid arguments.");
9522 } else if (rest.length === 1) {
9523 return document.createTextNode(rest[0]);
9524 } else {
9525 var element = document.createElement(rest[0]);
9526 element.appendChild(wrapInTag.apply(void 0, _toConsumableArray(slice$2(rest).call(rest, 1))));
9527 return element;
9528 }
9529}
9530/**
9531 * The way this works is for all properties of this.possible options, you can supply the property name in any form to list the options.
9532 * Boolean options are recognised as Boolean
9533 * Number options should be written as array: [default value, min value, max value, stepsize]
9534 * Colors should be written as array: ['color', '#ffffff']
9535 * Strings with should be written as array: [option1, option2, option3, ..]
9536 *
9537 * The options are matched with their counterparts in each of the modules and the values used in the configuration are
9538 */
9539
9540
9541var Configurator = /*#__PURE__*/function () {
9542 /**
9543 * @param {object} parentModule | the location where parentModule.setOptions() can be called
9544 * @param {object} defaultContainer | the default container of the module
9545 * @param {object} configureOptions | the fully configured and predefined options set found in allOptions.js
9546 * @param {number} pixelRatio | canvas pixel ratio
9547 * @param {Function} hideOption | custom logic to dynamically hide options
9548 */
9549 function Configurator(parentModule, defaultContainer, configureOptions) {
9550 var pixelRatio = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
9551 var hideOption = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : function () {
9552 return false;
9553 };
9554
9555 _classCallCheck(this, Configurator);
9556
9557 this.parent = parentModule;
9558 this.changedOptions = [];
9559 this.container = defaultContainer;
9560 this.allowCreation = false;
9561 this.hideOption = hideOption;
9562 this.options = {};
9563 this.initialized = false;
9564 this.popupCounter = 0;
9565 this.defaultOptions = {
9566 enabled: false,
9567 filter: true,
9568 container: undefined,
9569 showButton: true
9570 };
9571
9572 assign$2(this.options, this.defaultOptions);
9573
9574 this.configureOptions = configureOptions;
9575 this.moduleOptions = {};
9576 this.domElements = [];
9577 this.popupDiv = {};
9578 this.popupLimit = 5;
9579 this.popupHistory = {};
9580 this.colorPicker = new ColorPicker(pixelRatio);
9581 this.wrapper = undefined;
9582 }
9583 /**
9584 * refresh all options.
9585 * Because all modules parse their options by themselves, we just use their options. We copy them here.
9586 *
9587 * @param {object} options
9588 */
9589
9590
9591 _createClass(Configurator, [{
9592 key: "setOptions",
9593 value: function setOptions(options) {
9594 if (options !== undefined) {
9595 // reset the popup history because the indices may have been changed.
9596 this.popupHistory = {};
9597
9598 this._removePopup();
9599
9600 var enabled = true;
9601
9602 if (typeof options === "string") {
9603 this.options.filter = options;
9604 } else if (isArray(options)) {
9605 this.options.filter = options.join();
9606 } else if (_typeof(options) === "object") {
9607 if (options == null) {
9608 throw new TypeError("options cannot be null");
9609 }
9610
9611 if (options.container !== undefined) {
9612 this.options.container = options.container;
9613 }
9614
9615 if (filter(options) !== undefined) {
9616 this.options.filter = filter(options);
9617 }
9618
9619 if (options.showButton !== undefined) {
9620 this.options.showButton = options.showButton;
9621 }
9622
9623 if (options.enabled !== undefined) {
9624 enabled = options.enabled;
9625 }
9626 } else if (typeof options === "boolean") {
9627 this.options.filter = true;
9628 enabled = options;
9629 } else if (typeof options === "function") {
9630 this.options.filter = options;
9631 enabled = true;
9632 }
9633
9634 if (filter(this.options) === false) {
9635 enabled = false;
9636 }
9637
9638 this.options.enabled = enabled;
9639 }
9640
9641 this._clean();
9642 }
9643 /**
9644 *
9645 * @param {object} moduleOptions
9646 */
9647
9648 }, {
9649 key: "setModuleOptions",
9650 value: function setModuleOptions(moduleOptions) {
9651 this.moduleOptions = moduleOptions;
9652
9653 if (this.options.enabled === true) {
9654 this._clean();
9655
9656 if (this.options.container !== undefined) {
9657 this.container = this.options.container;
9658 }
9659
9660 this._create();
9661 }
9662 }
9663 /**
9664 * Create all DOM elements
9665 *
9666 * @private
9667 */
9668
9669 }, {
9670 key: "_create",
9671 value: function _create() {
9672 this._clean();
9673
9674 this.changedOptions = [];
9675
9676 var filter$1 = filter(this.options);
9677
9678 var counter = 0;
9679 var show = false;
9680
9681 for (var _option in this.configureOptions) {
9682 if (Object.prototype.hasOwnProperty.call(this.configureOptions, _option)) {
9683 this.allowCreation = false;
9684 show = false;
9685
9686 if (typeof filter$1 === "function") {
9687 show = filter$1(_option, []);
9688 show = show || this._handleObject(this.configureOptions[_option], [_option], true);
9689 } else if (filter$1 === true || indexOf(filter$1).call(filter$1, _option) !== -1) {
9690 show = true;
9691 }
9692
9693 if (show !== false) {
9694 this.allowCreation = true; // linebreak between categories
9695
9696 if (counter > 0) {
9697 this._makeItem([]);
9698 } // a header for the category
9699
9700
9701 this._makeHeader(_option); // get the sub options
9702
9703
9704 this._handleObject(this.configureOptions[_option], [_option]);
9705 }
9706
9707 counter++;
9708 }
9709 }
9710
9711 this._makeButton();
9712
9713 this._push(); //~ this.colorPicker.insertTo(this.container);
9714
9715 }
9716 /**
9717 * draw all DOM elements on the screen
9718 *
9719 * @private
9720 */
9721
9722 }, {
9723 key: "_push",
9724 value: function _push() {
9725 this.wrapper = document.createElement("div");
9726 this.wrapper.className = "vis-configuration-wrapper";
9727 this.container.appendChild(this.wrapper);
9728
9729 for (var i = 0; i < this.domElements.length; i++) {
9730 this.wrapper.appendChild(this.domElements[i]);
9731 }
9732
9733 this._showPopupIfNeeded();
9734 }
9735 /**
9736 * delete all DOM elements
9737 *
9738 * @private
9739 */
9740
9741 }, {
9742 key: "_clean",
9743 value: function _clean() {
9744 for (var i = 0; i < this.domElements.length; i++) {
9745 this.wrapper.removeChild(this.domElements[i]);
9746 }
9747
9748 if (this.wrapper !== undefined) {
9749 this.container.removeChild(this.wrapper);
9750 this.wrapper = undefined;
9751 }
9752
9753 this.domElements = [];
9754
9755 this._removePopup();
9756 }
9757 /**
9758 * get the value from the actualOptions if it exists
9759 *
9760 * @param {Array} path | where to look for the actual option
9761 * @returns {*}
9762 * @private
9763 */
9764
9765 }, {
9766 key: "_getValue",
9767 value: function _getValue(path) {
9768 var base = this.moduleOptions;
9769
9770 for (var i = 0; i < path.length; i++) {
9771 if (base[path[i]] !== undefined) {
9772 base = base[path[i]];
9773 } else {
9774 base = undefined;
9775 break;
9776 }
9777 }
9778
9779 return base;
9780 }
9781 /**
9782 * all option elements are wrapped in an item
9783 *
9784 * @param {Array} path | where to look for the actual option
9785 * @param {Array.<Element>} domElements
9786 * @returns {number}
9787 * @private
9788 */
9789
9790 }, {
9791 key: "_makeItem",
9792 value: function _makeItem(path) {
9793 if (this.allowCreation === true) {
9794 var item = document.createElement("div");
9795 item.className = "vis-configuration vis-config-item vis-config-s" + path.length;
9796
9797 for (var _len6 = arguments.length, domElements = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
9798 domElements[_key6 - 1] = arguments[_key6];
9799 }
9800
9801 forEach$2(domElements).call(domElements, function (element) {
9802 item.appendChild(element);
9803 });
9804
9805 this.domElements.push(item);
9806 return this.domElements.length;
9807 }
9808
9809 return 0;
9810 }
9811 /**
9812 * header for major subjects
9813 *
9814 * @param {string} name
9815 * @private
9816 */
9817
9818 }, {
9819 key: "_makeHeader",
9820 value: function _makeHeader(name) {
9821 var div = document.createElement("div");
9822 div.className = "vis-configuration vis-config-header";
9823 div.innerText = name;
9824
9825 this._makeItem([], div);
9826 }
9827 /**
9828 * make a label, if it is an object label, it gets different styling.
9829 *
9830 * @param {string} name
9831 * @param {Array} path | where to look for the actual option
9832 * @param {string} objectLabel
9833 * @returns {HTMLElement}
9834 * @private
9835 */
9836
9837 }, {
9838 key: "_makeLabel",
9839 value: function _makeLabel(name, path) {
9840 var objectLabel = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
9841 var div = document.createElement("div");
9842 div.className = "vis-configuration vis-config-label vis-config-s" + path.length;
9843
9844 if (objectLabel === true) {
9845 while (div.firstChild) {
9846 div.removeChild(div.firstChild);
9847 }
9848
9849 div.appendChild(wrapInTag("i", "b", name));
9850 } else {
9851 div.innerText = name + ":";
9852 }
9853
9854 return div;
9855 }
9856 /**
9857 * make a dropdown list for multiple possible string optoins
9858 *
9859 * @param {Array.<number>} arr
9860 * @param {number} value
9861 * @param {Array} path | where to look for the actual option
9862 * @private
9863 */
9864
9865 }, {
9866 key: "_makeDropdown",
9867 value: function _makeDropdown(arr, value, path) {
9868 var select = document.createElement("select");
9869 select.className = "vis-configuration vis-config-select";
9870 var selectedValue = 0;
9871
9872 if (value !== undefined) {
9873 if (indexOf(arr).call(arr, value) !== -1) {
9874 selectedValue = indexOf(arr).call(arr, value);
9875 }
9876 }
9877
9878 for (var i = 0; i < arr.length; i++) {
9879 var _option2 = document.createElement("option");
9880
9881 _option2.value = arr[i];
9882
9883 if (i === selectedValue) {
9884 _option2.selected = "selected";
9885 }
9886
9887 _option2.innerText = arr[i];
9888 select.appendChild(_option2);
9889 }
9890
9891 var me = this;
9892
9893 select.onchange = function () {
9894 me._update(this.value, path);
9895 };
9896
9897 var label = this._makeLabel(path[path.length - 1], path);
9898
9899 this._makeItem(path, label, select);
9900 }
9901 /**
9902 * make a range object for numeric options
9903 *
9904 * @param {Array.<number>} arr
9905 * @param {number} value
9906 * @param {Array} path | where to look for the actual option
9907 * @private
9908 */
9909
9910 }, {
9911 key: "_makeRange",
9912 value: function _makeRange(arr, value, path) {
9913 var defaultValue = arr[0];
9914 var min = arr[1];
9915 var max = arr[2];
9916 var step = arr[3];
9917 var range = document.createElement("input");
9918 range.className = "vis-configuration vis-config-range";
9919
9920 try {
9921 range.type = "range"; // not supported on IE9
9922
9923 range.min = min;
9924 range.max = max;
9925 } catch (err) {// TODO: Add some error handling.
9926 }
9927
9928 range.step = step; // set up the popup settings in case they are needed.
9929
9930 var popupString = "";
9931 var popupValue = 0;
9932
9933 if (value !== undefined) {
9934 var factor = 1.2;
9935
9936 if (value < 0 && value * factor < min) {
9937 range.min = Math.ceil(value * factor);
9938 popupValue = range.min;
9939 popupString = "range increased";
9940 } else if (value / factor < min) {
9941 range.min = Math.ceil(value / factor);
9942 popupValue = range.min;
9943 popupString = "range increased";
9944 }
9945
9946 if (value * factor > max && max !== 1) {
9947 range.max = Math.ceil(value * factor);
9948 popupValue = range.max;
9949 popupString = "range increased";
9950 }
9951
9952 range.value = value;
9953 } else {
9954 range.value = defaultValue;
9955 }
9956
9957 var input = document.createElement("input");
9958 input.className = "vis-configuration vis-config-rangeinput";
9959 input.value = range.value;
9960 var me = this;
9961
9962 range.onchange = function () {
9963 input.value = this.value;
9964
9965 me._update(Number(this.value), path);
9966 };
9967
9968 range.oninput = function () {
9969 input.value = this.value;
9970 };
9971
9972 var label = this._makeLabel(path[path.length - 1], path);
9973
9974 var itemIndex = this._makeItem(path, label, range, input); // if a popup is needed AND it has not been shown for this value, show it.
9975
9976
9977 if (popupString !== "" && this.popupHistory[itemIndex] !== popupValue) {
9978 this.popupHistory[itemIndex] = popupValue;
9979
9980 this._setupPopup(popupString, itemIndex);
9981 }
9982 }
9983 /**
9984 * make a button object
9985 *
9986 * @private
9987 */
9988
9989 }, {
9990 key: "_makeButton",
9991 value: function _makeButton() {
9992 var _this4 = this;
9993
9994 if (this.options.showButton === true) {
9995 var generateButton = document.createElement("div");
9996 generateButton.className = "vis-configuration vis-config-button";
9997 generateButton.innerText = "generate options";
9998
9999 generateButton.onclick = function () {
10000 _this4._printOptions();
10001 };
10002
10003 generateButton.onmouseover = function () {
10004 generateButton.className = "vis-configuration vis-config-button hover";
10005 };
10006
10007 generateButton.onmouseout = function () {
10008 generateButton.className = "vis-configuration vis-config-button";
10009 };
10010
10011 this.optionsContainer = document.createElement("div");
10012 this.optionsContainer.className = "vis-configuration vis-config-option-container";
10013 this.domElements.push(this.optionsContainer);
10014 this.domElements.push(generateButton);
10015 }
10016 }
10017 /**
10018 * prepare the popup
10019 *
10020 * @param {string} string
10021 * @param {number} index
10022 * @private
10023 */
10024
10025 }, {
10026 key: "_setupPopup",
10027 value: function _setupPopup(string, index) {
10028 var _this5 = this;
10029
10030 if (this.initialized === true && this.allowCreation === true && this.popupCounter < this.popupLimit) {
10031 var div = document.createElement("div");
10032 div.id = "vis-configuration-popup";
10033 div.className = "vis-configuration-popup";
10034 div.innerText = string;
10035
10036 div.onclick = function () {
10037 _this5._removePopup();
10038 };
10039
10040 this.popupCounter += 1;
10041 this.popupDiv = {
10042 html: div,
10043 index: index
10044 };
10045 }
10046 }
10047 /**
10048 * remove the popup from the dom
10049 *
10050 * @private
10051 */
10052
10053 }, {
10054 key: "_removePopup",
10055 value: function _removePopup() {
10056 if (this.popupDiv.html !== undefined) {
10057 this.popupDiv.html.parentNode.removeChild(this.popupDiv.html);
10058 clearTimeout(this.popupDiv.hideTimeout);
10059 clearTimeout(this.popupDiv.deleteTimeout);
10060 this.popupDiv = {};
10061 }
10062 }
10063 /**
10064 * Show the popup if it is needed.
10065 *
10066 * @private
10067 */
10068
10069 }, {
10070 key: "_showPopupIfNeeded",
10071 value: function _showPopupIfNeeded() {
10072 var _this6 = this;
10073
10074 if (this.popupDiv.html !== undefined) {
10075 var correspondingElement = this.domElements[this.popupDiv.index];
10076 var rect = correspondingElement.getBoundingClientRect();
10077 this.popupDiv.html.style.left = rect.left + "px";
10078 this.popupDiv.html.style.top = rect.top - 30 + "px"; // 30 is the height;
10079
10080 document.body.appendChild(this.popupDiv.html);
10081 this.popupDiv.hideTimeout = setTimeout$1(function () {
10082 _this6.popupDiv.html.style.opacity = 0;
10083 }, 1500);
10084 this.popupDiv.deleteTimeout = setTimeout$1(function () {
10085 _this6._removePopup();
10086 }, 1800);
10087 }
10088 }
10089 /**
10090 * make a checkbox for boolean options.
10091 *
10092 * @param {number} defaultValue
10093 * @param {number} value
10094 * @param {Array} path | where to look for the actual option
10095 * @private
10096 */
10097
10098 }, {
10099 key: "_makeCheckbox",
10100 value: function _makeCheckbox(defaultValue, value, path) {
10101 var checkbox = document.createElement("input");
10102 checkbox.type = "checkbox";
10103 checkbox.className = "vis-configuration vis-config-checkbox";
10104 checkbox.checked = defaultValue;
10105
10106 if (value !== undefined) {
10107 checkbox.checked = value;
10108
10109 if (value !== defaultValue) {
10110 if (_typeof(defaultValue) === "object") {
10111 if (value !== defaultValue.enabled) {
10112 this.changedOptions.push({
10113 path: path,
10114 value: value
10115 });
10116 }
10117 } else {
10118 this.changedOptions.push({
10119 path: path,
10120 value: value
10121 });
10122 }
10123 }
10124 }
10125
10126 var me = this;
10127
10128 checkbox.onchange = function () {
10129 me._update(this.checked, path);
10130 };
10131
10132 var label = this._makeLabel(path[path.length - 1], path);
10133
10134 this._makeItem(path, label, checkbox);
10135 }
10136 /**
10137 * make a text input field for string options.
10138 *
10139 * @param {number} defaultValue
10140 * @param {number} value
10141 * @param {Array} path | where to look for the actual option
10142 * @private
10143 */
10144
10145 }, {
10146 key: "_makeTextInput",
10147 value: function _makeTextInput(defaultValue, value, path) {
10148 var checkbox = document.createElement("input");
10149 checkbox.type = "text";
10150 checkbox.className = "vis-configuration vis-config-text";
10151 checkbox.value = value;
10152
10153 if (value !== defaultValue) {
10154 this.changedOptions.push({
10155 path: path,
10156 value: value
10157 });
10158 }
10159
10160 var me = this;
10161
10162 checkbox.onchange = function () {
10163 me._update(this.value, path);
10164 };
10165
10166 var label = this._makeLabel(path[path.length - 1], path);
10167
10168 this._makeItem(path, label, checkbox);
10169 }
10170 /**
10171 * make a color field with a color picker for color fields
10172 *
10173 * @param {Array.<number>} arr
10174 * @param {number} value
10175 * @param {Array} path | where to look for the actual option
10176 * @private
10177 */
10178
10179 }, {
10180 key: "_makeColorField",
10181 value: function _makeColorField(arr, value, path) {
10182 var _this7 = this;
10183
10184 var defaultColor = arr[1];
10185 var div = document.createElement("div");
10186 value = value === undefined ? defaultColor : value;
10187
10188 if (value !== "none") {
10189 div.className = "vis-configuration vis-config-colorBlock";
10190 div.style.backgroundColor = value;
10191 } else {
10192 div.className = "vis-configuration vis-config-colorBlock none";
10193 }
10194
10195 value = value === undefined ? defaultColor : value;
10196
10197 div.onclick = function () {
10198 _this7._showColorPicker(value, div, path);
10199 };
10200
10201 var label = this._makeLabel(path[path.length - 1], path);
10202
10203 this._makeItem(path, label, div);
10204 }
10205 /**
10206 * used by the color buttons to call the color picker.
10207 *
10208 * @param {number} value
10209 * @param {HTMLElement} div
10210 * @param {Array} path | where to look for the actual option
10211 * @private
10212 */
10213
10214 }, {
10215 key: "_showColorPicker",
10216 value: function _showColorPicker(value, div, path) {
10217 var _this8 = this;
10218
10219 // clear the callback from this div
10220 div.onclick = function () {};
10221
10222 this.colorPicker.insertTo(div);
10223 this.colorPicker.show();
10224 this.colorPicker.setColor(value);
10225 this.colorPicker.setUpdateCallback(function (color) {
10226 var colorString = "rgba(" + color.r + "," + color.g + "," + color.b + "," + color.a + ")";
10227 div.style.backgroundColor = colorString;
10228
10229 _this8._update(colorString, path);
10230 }); // on close of the colorpicker, restore the callback.
10231
10232 this.colorPicker.setCloseCallback(function () {
10233 div.onclick = function () {
10234 _this8._showColorPicker(value, div, path);
10235 };
10236 });
10237 }
10238 /**
10239 * parse an object and draw the correct items
10240 *
10241 * @param {object} obj
10242 * @param {Array} [path=[]] | where to look for the actual option
10243 * @param {boolean} [checkOnly=false]
10244 * @returns {boolean}
10245 * @private
10246 */
10247
10248 }, {
10249 key: "_handleObject",
10250 value: function _handleObject(obj) {
10251 var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
10252 var checkOnly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
10253 var show = false;
10254
10255 var filter$1 = filter(this.options);
10256
10257 var visibleInSet = false;
10258
10259 for (var subObj in obj) {
10260 if (Object.prototype.hasOwnProperty.call(obj, subObj)) {
10261 show = true;
10262 var item = obj[subObj];
10263 var newPath = copyAndExtendArray(path, subObj);
10264
10265 if (typeof filter$1 === "function") {
10266 show = filter$1(subObj, path); // if needed we must go deeper into the object.
10267
10268 if (show === false) {
10269 if (!isArray(item) && typeof item !== "string" && typeof item !== "boolean" && item instanceof Object) {
10270 this.allowCreation = false;
10271 show = this._handleObject(item, newPath, true);
10272 this.allowCreation = checkOnly === false;
10273 }
10274 }
10275 }
10276
10277 if (show !== false) {
10278 visibleInSet = true;
10279
10280 var value = this._getValue(newPath);
10281
10282 if (isArray(item)) {
10283 this._handleArray(item, value, newPath);
10284 } else if (typeof item === "string") {
10285 this._makeTextInput(item, value, newPath);
10286 } else if (typeof item === "boolean") {
10287 this._makeCheckbox(item, value, newPath);
10288 } else if (item instanceof Object) {
10289 // skip the options that are not enabled
10290 if (!this.hideOption(path, subObj, this.moduleOptions)) {
10291 // initially collapse options with an disabled enabled option.
10292 if (item.enabled !== undefined) {
10293 var enabledPath = copyAndExtendArray(newPath, "enabled");
10294
10295 var enabledValue = this._getValue(enabledPath);
10296
10297 if (enabledValue === true) {
10298 var label = this._makeLabel(subObj, newPath, true);
10299
10300 this._makeItem(newPath, label);
10301
10302 visibleInSet = this._handleObject(item, newPath) || visibleInSet;
10303 } else {
10304 this._makeCheckbox(item, enabledValue, newPath);
10305 }
10306 } else {
10307 var _label = this._makeLabel(subObj, newPath, true);
10308
10309 this._makeItem(newPath, _label);
10310
10311 visibleInSet = this._handleObject(item, newPath) || visibleInSet;
10312 }
10313 }
10314 } else {
10315 console.error("dont know how to handle", item, subObj, newPath);
10316 }
10317 }
10318 }
10319 }
10320
10321 return visibleInSet;
10322 }
10323 /**
10324 * handle the array type of option
10325 *
10326 * @param {Array.<number>} arr
10327 * @param {number} value
10328 * @param {Array} path | where to look for the actual option
10329 * @private
10330 */
10331
10332 }, {
10333 key: "_handleArray",
10334 value: function _handleArray(arr, value, path) {
10335 if (typeof arr[0] === "string" && arr[0] === "color") {
10336 this._makeColorField(arr, value, path);
10337
10338 if (arr[1] !== value) {
10339 this.changedOptions.push({
10340 path: path,
10341 value: value
10342 });
10343 }
10344 } else if (typeof arr[0] === "string") {
10345 this._makeDropdown(arr, value, path);
10346
10347 if (arr[0] !== value) {
10348 this.changedOptions.push({
10349 path: path,
10350 value: value
10351 });
10352 }
10353 } else if (typeof arr[0] === "number") {
10354 this._makeRange(arr, value, path);
10355
10356 if (arr[0] !== value) {
10357 this.changedOptions.push({
10358 path: path,
10359 value: Number(value)
10360 });
10361 }
10362 }
10363 }
10364 /**
10365 * called to update the network with the new settings.
10366 *
10367 * @param {number} value
10368 * @param {Array} path | where to look for the actual option
10369 * @private
10370 */
10371
10372 }, {
10373 key: "_update",
10374 value: function _update(value, path) {
10375 var options = this._constructOptions(value, path);
10376
10377 if (this.parent.body && this.parent.body.emitter && this.parent.body.emitter.emit) {
10378 this.parent.body.emitter.emit("configChange", options);
10379 }
10380
10381 this.initialized = true;
10382 this.parent.setOptions(options);
10383 }
10384 /**
10385 *
10386 * @param {string | boolean} value
10387 * @param {Array.<string>} path
10388 * @param {{}} optionsObj
10389 * @returns {{}}
10390 * @private
10391 */
10392
10393 }, {
10394 key: "_constructOptions",
10395 value: function _constructOptions(value, path) {
10396 var optionsObj = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
10397 var pointer = optionsObj; // when dropdown boxes can be string or boolean, we typecast it into correct types
10398
10399 value = value === "true" ? true : value;
10400 value = value === "false" ? false : value;
10401
10402 for (var i = 0; i < path.length; i++) {
10403 if (path[i] !== "global") {
10404 if (pointer[path[i]] === undefined) {
10405 pointer[path[i]] = {};
10406 }
10407
10408 if (i !== path.length - 1) {
10409 pointer = pointer[path[i]];
10410 } else {
10411 pointer[path[i]] = value;
10412 }
10413 }
10414 }
10415
10416 return optionsObj;
10417 }
10418 /**
10419 * @private
10420 */
10421
10422 }, {
10423 key: "_printOptions",
10424 value: function _printOptions() {
10425 var options = this.getOptions();
10426
10427 while (this.optionsContainer.firstChild) {
10428 this.optionsContainer.removeChild(this.optionsContainer.firstChild);
10429 }
10430
10431 this.optionsContainer.appendChild(wrapInTag("pre", "const options = " + stringify$1(options, null, 2)));
10432 }
10433 /**
10434 *
10435 * @returns {{}} options
10436 */
10437
10438 }, {
10439 key: "getOptions",
10440 value: function getOptions() {
10441 var options = {};
10442
10443 for (var i = 0; i < this.changedOptions.length; i++) {
10444 this._constructOptions(this.changedOptions[i].value, this.changedOptions[i].path, options);
10445 }
10446
10447 return options;
10448 }
10449 }]);
10450
10451 return Configurator;
10452}();
10453/**
10454 * Popup is a class to create a popup window with some text
10455 */
10456
10457
10458var Popup = /*#__PURE__*/function () {
10459 /**
10460 * @param {Element} container The container object.
10461 * @param {string} overflowMethod How the popup should act to overflowing ('flip' or 'cap')
10462 */
10463 function Popup(container, overflowMethod) {
10464 _classCallCheck(this, Popup);
10465
10466 this.container = container;
10467 this.overflowMethod = overflowMethod || "cap";
10468 this.x = 0;
10469 this.y = 0;
10470 this.padding = 5;
10471 this.hidden = false; // create the frame
10472
10473 this.frame = document.createElement("div");
10474 this.frame.className = "vis-tooltip";
10475 this.container.appendChild(this.frame);
10476 }
10477 /**
10478 * @param {number} x Horizontal position of the popup window
10479 * @param {number} y Vertical position of the popup window
10480 */
10481
10482
10483 _createClass(Popup, [{
10484 key: "setPosition",
10485 value: function setPosition(x, y) {
10486 this.x = _parseInt(x);
10487 this.y = _parseInt(y);
10488 }
10489 /**
10490 * Set the content for the popup window. This can be HTML code or text.
10491 *
10492 * @param {string | Element} content
10493 */
10494
10495 }, {
10496 key: "setText",
10497 value: function setText(content) {
10498 if (content instanceof Element) {
10499 while (this.frame.firstChild) {
10500 this.frame.removeChild(this.frame.firstChild);
10501 }
10502
10503 this.frame.appendChild(content);
10504 } else {
10505 // String containing literal text, element has to be used for HTML due to
10506 // XSS risks associated with innerHTML (i.e. prevent XSS by accident).
10507 this.frame.innerText = content;
10508 }
10509 }
10510 /**
10511 * Show the popup window
10512 *
10513 * @param {boolean} [doShow] Show or hide the window
10514 */
10515
10516 }, {
10517 key: "show",
10518 value: function show(doShow) {
10519 if (doShow === undefined) {
10520 doShow = true;
10521 }
10522
10523 if (doShow === true) {
10524 var height = this.frame.clientHeight;
10525 var width = this.frame.clientWidth;
10526 var maxHeight = this.frame.parentNode.clientHeight;
10527 var maxWidth = this.frame.parentNode.clientWidth;
10528 var left = 0,
10529 top = 0;
10530
10531 if (this.overflowMethod == "flip") {
10532 var isLeft = false,
10533 isTop = true; // Where around the position it's located
10534
10535 if (this.y - height < this.padding) {
10536 isTop = false;
10537 }
10538
10539 if (this.x + width > maxWidth - this.padding) {
10540 isLeft = true;
10541 }
10542
10543 if (isLeft) {
10544 left = this.x - width;
10545 } else {
10546 left = this.x;
10547 }
10548
10549 if (isTop) {
10550 top = this.y - height;
10551 } else {
10552 top = this.y;
10553 }
10554 } else {
10555 top = this.y - height;
10556
10557 if (top + height + this.padding > maxHeight) {
10558 top = maxHeight - height - this.padding;
10559 }
10560
10561 if (top < this.padding) {
10562 top = this.padding;
10563 }
10564
10565 left = this.x;
10566
10567 if (left + width + this.padding > maxWidth) {
10568 left = maxWidth - width - this.padding;
10569 }
10570
10571 if (left < this.padding) {
10572 left = this.padding;
10573 }
10574 }
10575
10576 this.frame.style.left = left + "px";
10577 this.frame.style.top = top + "px";
10578 this.frame.style.visibility = "visible";
10579 this.hidden = false;
10580 } else {
10581 this.hide();
10582 }
10583 }
10584 /**
10585 * Hide the popup window
10586 */
10587
10588 }, {
10589 key: "hide",
10590 value: function hide() {
10591 this.hidden = true;
10592 this.frame.style.left = "0";
10593 this.frame.style.top = "0";
10594 this.frame.style.visibility = "hidden";
10595 }
10596 /**
10597 * Remove the popup window
10598 */
10599
10600 }, {
10601 key: "destroy",
10602 value: function destroy() {
10603 this.frame.parentNode.removeChild(this.frame); // Remove element from DOM
10604 }
10605 }]);
10606
10607 return Popup;
10608}();
10609
10610var errorFound = false;
10611var allOptions$1;
10612var VALIDATOR_PRINT_STYLE = "background: #FFeeee; color: #dd0000";
10613/**
10614 * Used to validate options.
10615 */
10616
10617var Validator = /*#__PURE__*/function () {
10618 function Validator() {
10619 _classCallCheck(this, Validator);
10620 }
10621
10622 _createClass(Validator, null, [{
10623 key: "validate",
10624 value:
10625 /**
10626 * Main function to be called
10627 *
10628 * @param {object} options
10629 * @param {object} referenceOptions
10630 * @param {object} subObject
10631 * @returns {boolean}
10632 * @static
10633 */
10634 function validate(options, referenceOptions, subObject) {
10635 errorFound = false;
10636 allOptions$1 = referenceOptions;
10637 var usedOptions = referenceOptions;
10638
10639 if (subObject !== undefined) {
10640 usedOptions = referenceOptions[subObject];
10641 }
10642
10643 Validator.parse(options, usedOptions, []);
10644 return errorFound;
10645 }
10646 /**
10647 * Will traverse an object recursively and check every value
10648 *
10649 * @param {object} options
10650 * @param {object} referenceOptions
10651 * @param {Array} path | where to look for the actual option
10652 * @static
10653 */
10654
10655 }, {
10656 key: "parse",
10657 value: function parse(options, referenceOptions, path) {
10658 for (var _option3 in options) {
10659 if (Object.prototype.hasOwnProperty.call(options, _option3)) {
10660 Validator.check(_option3, options, referenceOptions, path);
10661 }
10662 }
10663 }
10664 /**
10665 * Check every value. If the value is an object, call the parse function on that object.
10666 *
10667 * @param {string} option
10668 * @param {object} options
10669 * @param {object} referenceOptions
10670 * @param {Array} path | where to look for the actual option
10671 * @static
10672 */
10673
10674 }, {
10675 key: "check",
10676 value: function check(option, options, referenceOptions, path) {
10677 if (referenceOptions[option] === undefined && referenceOptions.__any__ === undefined) {
10678 Validator.getSuggestion(option, referenceOptions, path);
10679 return;
10680 }
10681
10682 var referenceOption = option;
10683 var is_object = true;
10684
10685 if (referenceOptions[option] === undefined && referenceOptions.__any__ !== undefined) {
10686 // NOTE: This only triggers if the __any__ is in the top level of the options object.
10687 // THAT'S A REALLY BAD PLACE TO ALLOW IT!!!!
10688 // TODO: Examine if needed, remove if possible
10689 // __any__ is a wildcard. Any value is accepted and will be further analysed by reference.
10690 referenceOption = "__any__"; // if the any-subgroup is not a predefined object in the configurator,
10691 // we do not look deeper into the object.
10692
10693 is_object = Validator.getType(options[option]) === "object";
10694 }
10695
10696 var refOptionObj = referenceOptions[referenceOption];
10697
10698 if (is_object && refOptionObj.__type__ !== undefined) {
10699 refOptionObj = refOptionObj.__type__;
10700 }
10701
10702 Validator.checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path);
10703 }
10704 /**
10705 *
10706 * @param {string} option | the option property
10707 * @param {object} options | The supplied options object
10708 * @param {object} referenceOptions | The reference options containing all options and their allowed formats
10709 * @param {string} referenceOption | Usually this is the same as option, except when handling an __any__ tag.
10710 * @param {string} refOptionObj | This is the type object from the reference options
10711 * @param {Array} path | where in the object is the option
10712 * @static
10713 */
10714
10715 }, {
10716 key: "checkFields",
10717 value: function checkFields(option, options, referenceOptions, referenceOption, refOptionObj, path) {
10718 var log = function log(message) {
10719 console.error("%c" + message + Validator.printLocation(path, option), VALIDATOR_PRINT_STYLE);
10720 };
10721
10722 var optionType = Validator.getType(options[option]);
10723 var refOptionType = refOptionObj[optionType];
10724
10725 if (refOptionType !== undefined) {
10726 // if the type is correct, we check if it is supposed to be one of a few select values
10727 if (Validator.getType(refOptionType) === "array" && indexOf(refOptionType).call(refOptionType, options[option]) === -1) {
10728 log('Invalid option detected in "' + option + '".' + " Allowed values are:" + Validator.print(refOptionType) + ' not "' + options[option] + '". ');
10729 errorFound = true;
10730 } else if (optionType === "object" && referenceOption !== "__any__") {
10731 path = copyAndExtendArray(path, option);
10732 Validator.parse(options[option], referenceOptions[referenceOption], path);
10733 }
10734 } else if (refOptionObj["any"] === undefined) {
10735 // type of the field is incorrect and the field cannot be any
10736 log('Invalid type received for "' + option + '". Expected: ' + Validator.print(keys$3(refOptionObj)) + ". Received [" + optionType + '] "' + options[option] + '"');
10737 errorFound = true;
10738 }
10739 }
10740 /**
10741 *
10742 * @param {object | boolean | number | string | Array.<number> | Date | Node | Moment | undefined | null} object
10743 * @returns {string}
10744 * @static
10745 */
10746
10747 }, {
10748 key: "getType",
10749 value: function getType(object) {
10750 var type = _typeof(object);
10751
10752 if (type === "object") {
10753 if (object === null) {
10754 return "null";
10755 }
10756
10757 if (object instanceof Boolean) {
10758 return "boolean";
10759 }
10760
10761 if (object instanceof Number) {
10762 return "number";
10763 }
10764
10765 if (object instanceof String) {
10766 return "string";
10767 }
10768
10769 if (isArray(object)) {
10770 return "array";
10771 }
10772
10773 if (object instanceof Date) {
10774 return "date";
10775 }
10776
10777 if (object.nodeType !== undefined) {
10778 return "dom";
10779 }
10780
10781 if (object._isAMomentObject === true) {
10782 return "moment";
10783 }
10784
10785 return "object";
10786 } else if (type === "number") {
10787 return "number";
10788 } else if (type === "boolean") {
10789 return "boolean";
10790 } else if (type === "string") {
10791 return "string";
10792 } else if (type === undefined) {
10793 return "undefined";
10794 }
10795
10796 return type;
10797 }
10798 /**
10799 * @param {string} option
10800 * @param {object} options
10801 * @param {Array.<string>} path
10802 * @static
10803 */
10804
10805 }, {
10806 key: "getSuggestion",
10807 value: function getSuggestion(option, options, path) {
10808 var localSearch = Validator.findInOptions(option, options, path, false);
10809 var globalSearch = Validator.findInOptions(option, allOptions$1, [], true);
10810 var localSearchThreshold = 8;
10811 var globalSearchThreshold = 4;
10812 var msg;
10813
10814 if (localSearch.indexMatch !== undefined) {
10815 msg = " in " + Validator.printLocation(localSearch.path, option, "") + 'Perhaps it was incomplete? Did you mean: "' + localSearch.indexMatch + '"?\n\n';
10816 } else if (globalSearch.distance <= globalSearchThreshold && localSearch.distance > globalSearch.distance) {
10817 msg = " in " + Validator.printLocation(localSearch.path, option, "") + "Perhaps it was misplaced? Matching option found at: " + Validator.printLocation(globalSearch.path, globalSearch.closestMatch, "");
10818 } else if (localSearch.distance <= localSearchThreshold) {
10819 msg = '. Did you mean "' + localSearch.closestMatch + '"?' + Validator.printLocation(localSearch.path, option);
10820 } else {
10821 msg = ". Did you mean one of these: " + Validator.print(keys$3(options)) + Validator.printLocation(path, option);
10822 }
10823
10824 console.error('%cUnknown option detected: "' + option + '"' + msg, VALIDATOR_PRINT_STYLE);
10825 errorFound = true;
10826 }
10827 /**
10828 * traverse the options in search for a match.
10829 *
10830 * @param {string} option
10831 * @param {object} options
10832 * @param {Array} path | where to look for the actual option
10833 * @param {boolean} [recursive=false]
10834 * @returns {{closestMatch: string, path: Array, distance: number}}
10835 * @static
10836 */
10837
10838 }, {
10839 key: "findInOptions",
10840 value: function findInOptions(option, options, path) {
10841 var recursive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
10842 var min = 1e9;
10843 var closestMatch = "";
10844 var closestMatchPath = [];
10845 var lowerCaseOption = option.toLowerCase();
10846 var indexMatch = undefined;
10847
10848 for (var op in options) {
10849 var distance = void 0;
10850
10851 if (options[op].__type__ !== undefined && recursive === true) {
10852 var result = Validator.findInOptions(option, options[op], copyAndExtendArray(path, op));
10853
10854 if (min > result.distance) {
10855 closestMatch = result.closestMatch;
10856 closestMatchPath = result.path;
10857 min = result.distance;
10858 indexMatch = result.indexMatch;
10859 }
10860 } else {
10861 var _context20;
10862
10863 if (indexOf(_context20 = op.toLowerCase()).call(_context20, lowerCaseOption) !== -1) {
10864 indexMatch = op;
10865 }
10866
10867 distance = Validator.levenshteinDistance(option, op);
10868
10869 if (min > distance) {
10870 closestMatch = op;
10871 closestMatchPath = copyArray(path);
10872 min = distance;
10873 }
10874 }
10875 }
10876
10877 return {
10878 closestMatch: closestMatch,
10879 path: closestMatchPath,
10880 distance: min,
10881 indexMatch: indexMatch
10882 };
10883 }
10884 /**
10885 * @param {Array.<string>} path
10886 * @param {object} option
10887 * @param {string} prefix
10888 * @returns {string}
10889 * @static
10890 */
10891
10892 }, {
10893 key: "printLocation",
10894 value: function printLocation(path, option) {
10895 var prefix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "Problem value found at: \n";
10896 var str = "\n\n" + prefix + "options = {\n";
10897
10898 for (var i = 0; i < path.length; i++) {
10899 for (var j = 0; j < i + 1; j++) {
10900 str += " ";
10901 }
10902
10903 str += path[i] + ": {\n";
10904 }
10905
10906 for (var _j = 0; _j < path.length + 1; _j++) {
10907 str += " ";
10908 }
10909
10910 str += option + "\n";
10911
10912 for (var _i3 = 0; _i3 < path.length + 1; _i3++) {
10913 for (var _j2 = 0; _j2 < path.length - _i3; _j2++) {
10914 str += " ";
10915 }
10916
10917 str += "}\n";
10918 }
10919
10920 return str + "\n\n";
10921 }
10922 /**
10923 * @param {object} options
10924 * @returns {string}
10925 * @static
10926 */
10927
10928 }, {
10929 key: "print",
10930 value: function print(options) {
10931 return stringify$1(options).replace(/(")|(\[)|(\])|(,"__type__")/g, "").replace(/(,)/g, ", ");
10932 }
10933 /**
10934 * Compute the edit distance between the two given strings
10935 * http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#JavaScript
10936 *
10937 * Copyright (c) 2011 Andrei Mackenzie
10938 *
10939 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10940 *
10941 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10942 *
10943 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10944 *
10945 * @param {string} a
10946 * @param {string} b
10947 * @returns {Array.<Array.<number>>}}
10948 * @static
10949 */
10950
10951 }, {
10952 key: "levenshteinDistance",
10953 value: function levenshteinDistance(a, b) {
10954 if (a.length === 0) return b.length;
10955 if (b.length === 0) return a.length;
10956 var matrix = []; // increment along the first column of each row
10957
10958 var i;
10959
10960 for (i = 0; i <= b.length; i++) {
10961 matrix[i] = [i];
10962 } // increment each column in the first row
10963
10964
10965 var j;
10966
10967 for (j = 0; j <= a.length; j++) {
10968 matrix[0][j] = j;
10969 } // Fill in the rest of the matrix
10970
10971
10972 for (i = 1; i <= b.length; i++) {
10973 for (j = 1; j <= a.length; j++) {
10974 if (b.charAt(i - 1) == a.charAt(j - 1)) {
10975 matrix[i][j] = matrix[i - 1][j - 1];
10976 } else {
10977 matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, // substitution
10978 Math.min(matrix[i][j - 1] + 1, // insertion
10979 matrix[i - 1][j] + 1)); // deletion
10980 }
10981 }
10982 }
10983
10984 return matrix[b.length][a.length];
10985 }
10986 }]);
10987
10988 return Validator;
10989}();
10990
10991var Activator$1 = Activator;
10992var ColorPicker$1 = ColorPicker;
10993var Configurator$1 = Configurator;
10994var Hammer$1$1 = Hammer$1;
10995var Popup$1 = Popup;
10996var VALIDATOR_PRINT_STYLE$1 = VALIDATOR_PRINT_STYLE;
10997var Validator$1 = Validator;
10998
10999var esnext$1 = /*#__PURE__*/Object.freeze({
11000 __proto__: null,
11001 Activator: Activator$1,
11002 Alea: Alea,
11003 ColorPicker: ColorPicker$1,
11004 Configurator: Configurator$1,
11005 DELETE: DELETE,
11006 HSVToHex: HSVToHex,
11007 HSVToRGB: HSVToRGB,
11008 Hammer: Hammer$1$1,
11009 Popup: Popup$1,
11010 RGBToHSV: RGBToHSV,
11011 RGBToHex: RGBToHex,
11012 VALIDATOR_PRINT_STYLE: VALIDATOR_PRINT_STYLE$1,
11013 Validator: Validator$1,
11014 addClassName: addClassName,
11015 addCssText: addCssText,
11016 addEventListener: addEventListener,
11017 binarySearchCustom: binarySearchCustom,
11018 binarySearchValue: binarySearchValue,
11019 bridgeObject: bridgeObject,
11020 copyAndExtendArray: copyAndExtendArray,
11021 copyArray: copyArray,
11022 deepExtend: deepExtend,
11023 deepObjectAssign: deepObjectAssign,
11024 easingFunctions: easingFunctions,
11025 equalArray: equalArray,
11026 extend: extend,
11027 fillIfDefined: fillIfDefined,
11028 forEach: forEach$1,
11029 getAbsoluteLeft: getAbsoluteLeft,
11030 getAbsoluteRight: getAbsoluteRight,
11031 getAbsoluteTop: getAbsoluteTop,
11032 getScrollBarWidth: getScrollBarWidth,
11033 getTarget: getTarget,
11034 getType: getType,
11035 hasParent: hasParent,
11036 hexToHSV: hexToHSV,
11037 hexToRGB: hexToRGB,
11038 insertSort: insertSort,
11039 isDate: isDate,
11040 isNumber: isNumber,
11041 isObject: isObject,
11042 isString: isString,
11043 isValidHex: isValidHex,
11044 isValidRGB: isValidRGB,
11045 isValidRGBA: isValidRGBA,
11046 mergeOptions: mergeOptions,
11047 option: option,
11048 overrideOpacity: overrideOpacity,
11049 parseColor: parseColor,
11050 preventDefault: preventDefault,
11051 pureDeepObjectAssign: pureDeepObjectAssign,
11052 recursiveDOMDelete: recursiveDOMDelete,
11053 removeClassName: removeClassName,
11054 removeCssText: removeCssText,
11055 removeEventListener: removeEventListener,
11056 selectiveBridgeObject: selectiveBridgeObject,
11057 selectiveDeepExtend: selectiveDeepExtend,
11058 selectiveExtend: selectiveExtend,
11059 selectiveNotDeepExtend: selectiveNotDeepExtend,
11060 throttle: throttle,
11061 toArray: toArray,
11062 topMost: topMost,
11063 updateProperty: updateProperty
11064});
11065
11066var DOMutil$1 = createCommonjsModule(function (module, exports) {
11067 // DOM utility methods
11068
11069 /**
11070 * this prepares the JSON container for allocating SVG elements
11071 * @param {Object} JSONcontainer
11072 * @private
11073 */
11074 exports.prepareElements = function (JSONcontainer) {
11075 // cleanup the redundant svgElements;
11076 for (var elementType in JSONcontainer) {
11077 if (JSONcontainer.hasOwnProperty(elementType)) {
11078 JSONcontainer[elementType].redundant = JSONcontainer[elementType].used;
11079 JSONcontainer[elementType].used = [];
11080 }
11081 }
11082 };
11083 /**
11084 * this cleans up all the unused SVG elements. By asking for the parentNode, we only need to supply the JSON container from
11085 * which to remove the redundant elements.
11086 *
11087 * @param {Object} JSONcontainer
11088 * @private
11089 */
11090
11091
11092 exports.cleanupElements = function (JSONcontainer) {
11093 // cleanup the redundant svgElements;
11094 for (var elementType in JSONcontainer) {
11095 if (JSONcontainer.hasOwnProperty(elementType)) {
11096 if (JSONcontainer[elementType].redundant) {
11097 for (var i = 0; i < JSONcontainer[elementType].redundant.length; i++) {
11098 JSONcontainer[elementType].redundant[i].parentNode.removeChild(JSONcontainer[elementType].redundant[i]);
11099 }
11100
11101 JSONcontainer[elementType].redundant = [];
11102 }
11103 }
11104 }
11105 };
11106 /**
11107 * Ensures that all elements are removed first up so they can be recreated cleanly
11108 * @param {Object} JSONcontainer
11109 */
11110
11111
11112 exports.resetElements = function (JSONcontainer) {
11113 exports.prepareElements(JSONcontainer);
11114 exports.cleanupElements(JSONcontainer);
11115 exports.prepareElements(JSONcontainer);
11116 };
11117 /**
11118 * Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer
11119 * the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this.
11120 *
11121 * @param {string} elementType
11122 * @param {Object} JSONcontainer
11123 * @param {Object} svgContainer
11124 * @returns {Element}
11125 * @private
11126 */
11127
11128
11129 exports.getSVGElement = function (elementType, JSONcontainer, svgContainer) {
11130 var element; // allocate SVG element, if it doesnt yet exist, create one.
11131
11132 if (JSONcontainer.hasOwnProperty(elementType)) {
11133 // this element has been created before
11134 // check if there is an redundant element
11135 if (JSONcontainer[elementType].redundant.length > 0) {
11136 element = JSONcontainer[elementType].redundant[0];
11137 JSONcontainer[elementType].redundant.shift();
11138 } else {
11139 // create a new element and add it to the SVG
11140 element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
11141 svgContainer.appendChild(element);
11142 }
11143 } else {
11144 // create a new element and add it to the SVG, also create a new object in the svgElements to keep track of it.
11145 element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
11146 JSONcontainer[elementType] = {
11147 used: [],
11148 redundant: []
11149 };
11150 svgContainer.appendChild(element);
11151 }
11152
11153 JSONcontainer[elementType].used.push(element);
11154 return element;
11155 };
11156 /**
11157 * Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer
11158 * the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this.
11159 *
11160 * @param {string} elementType
11161 * @param {Object} JSONcontainer
11162 * @param {Element} DOMContainer
11163 * @param {Element} insertBefore
11164 * @returns {*}
11165 */
11166
11167
11168 exports.getDOMElement = function (elementType, JSONcontainer, DOMContainer, insertBefore) {
11169 var element; // allocate DOM element, if it doesnt yet exist, create one.
11170
11171 if (JSONcontainer.hasOwnProperty(elementType)) {
11172 // this element has been created before
11173 // check if there is an redundant element
11174 if (JSONcontainer[elementType].redundant.length > 0) {
11175 element = JSONcontainer[elementType].redundant[0];
11176 JSONcontainer[elementType].redundant.shift();
11177 } else {
11178 // create a new element and add it to the SVG
11179 element = document.createElement(elementType);
11180
11181 if (insertBefore !== undefined) {
11182 DOMContainer.insertBefore(element, insertBefore);
11183 } else {
11184 DOMContainer.appendChild(element);
11185 }
11186 }
11187 } else {
11188 // create a new element and add it to the SVG, also create a new object in the svgElements to keep track of it.
11189 element = document.createElement(elementType);
11190 JSONcontainer[elementType] = {
11191 used: [],
11192 redundant: []
11193 };
11194
11195 if (insertBefore !== undefined) {
11196 DOMContainer.insertBefore(element, insertBefore);
11197 } else {
11198 DOMContainer.appendChild(element);
11199 }
11200 }
11201
11202 JSONcontainer[elementType].used.push(element);
11203 return element;
11204 };
11205 /**
11206 * Draw a point object. This is a separate function because it can also be called by the legend.
11207 * The reason the JSONcontainer and the target SVG svgContainer have to be supplied is so the legend can use these functions
11208 * as well.
11209 *
11210 * @param {number} x
11211 * @param {number} y
11212 * @param {Object} groupTemplate: A template containing the necessary information to draw the datapoint e.g., {style: 'circle', size: 5, className: 'className' }
11213 * @param {Object} JSONcontainer
11214 * @param {Object} svgContainer
11215 * @param {Object} labelObj
11216 * @returns {vis.PointItem}
11217 */
11218
11219
11220 exports.drawPoint = function (x, y, groupTemplate, JSONcontainer, svgContainer, labelObj) {
11221 var point;
11222
11223 if (groupTemplate.style == 'circle') {
11224 point = exports.getSVGElement('circle', JSONcontainer, svgContainer);
11225 point.setAttributeNS(null, "cx", x);
11226 point.setAttributeNS(null, "cy", y);
11227 point.setAttributeNS(null, "r", 0.5 * groupTemplate.size);
11228 } else {
11229 point = exports.getSVGElement('rect', JSONcontainer, svgContainer);
11230 point.setAttributeNS(null, "x", x - 0.5 * groupTemplate.size);
11231 point.setAttributeNS(null, "y", y - 0.5 * groupTemplate.size);
11232 point.setAttributeNS(null, "width", groupTemplate.size);
11233 point.setAttributeNS(null, "height", groupTemplate.size);
11234 }
11235
11236 if (groupTemplate.styles !== undefined) {
11237 point.setAttributeNS(null, "style", groupTemplate.styles);
11238 }
11239
11240 point.setAttributeNS(null, "class", groupTemplate.className + " vis-point"); //handle label
11241
11242 if (labelObj) {
11243 var label = exports.getSVGElement('text', JSONcontainer, svgContainer);
11244
11245 if (labelObj.xOffset) {
11246 x = x + labelObj.xOffset;
11247 }
11248
11249 if (labelObj.yOffset) {
11250 y = y + labelObj.yOffset;
11251 }
11252
11253 if (labelObj.content) {
11254 label.textContent = labelObj.content;
11255 }
11256
11257 if (labelObj.className) {
11258 label.setAttributeNS(null, "class", labelObj.className + " vis-label");
11259 }
11260
11261 label.setAttributeNS(null, "x", x);
11262 label.setAttributeNS(null, "y", y);
11263 }
11264
11265 return point;
11266 };
11267 /**
11268 * draw a bar SVG element centered on the X coordinate
11269 *
11270 * @param {number} x
11271 * @param {number} y
11272 * @param {number} width
11273 * @param {number} height
11274 * @param {string} className
11275 * @param {Object} JSONcontainer
11276 * @param {Object} svgContainer
11277 * @param {string} style
11278 */
11279
11280
11281 exports.drawBar = function (x, y, width, height, className, JSONcontainer, svgContainer, style) {
11282 if (height != 0) {
11283 if (height < 0) {
11284 height *= -1;
11285 y -= height;
11286 }
11287
11288 var rect = exports.getSVGElement('rect', JSONcontainer, svgContainer);
11289 rect.setAttributeNS(null, "x", x - 0.5 * width);
11290 rect.setAttributeNS(null, "y", y);
11291 rect.setAttributeNS(null, "width", width);
11292 rect.setAttributeNS(null, "height", height);
11293 rect.setAttributeNS(null, "class", className);
11294
11295 if (style) {
11296 rect.setAttributeNS(null, "style", style);
11297 }
11298 }
11299 };
11300});
11301DOMutil$1.prepareElements;
11302DOMutil$1.cleanupElements;
11303DOMutil$1.resetElements;
11304DOMutil$1.getSVGElement;
11305DOMutil$1.getDOMElement;
11306DOMutil$1.drawPoint;
11307DOMutil$1.drawBar;
11308
11309var nativeConstruct = getBuiltIn('Reflect', 'construct'); // `Reflect.construct` method
11310// https://tc39.es/ecma262/#sec-reflect.construct
11311// MS Edge supports only 2 arguments and argumentsList argument is optional
11312// FF Nightly sets third argument as `new.target`, but does not create `this` from it
11313
11314var NEW_TARGET_BUG = fails(function () {
11315 function F() {
11316 /* empty */
11317 }
11318
11319 return !(nativeConstruct(function () {
11320 /* empty */
11321 }, [], F) instanceof F);
11322});
11323var ARGS_BUG = !fails(function () {
11324 nativeConstruct(function () {
11325 /* empty */
11326 });
11327});
11328var FORCED$2 = NEW_TARGET_BUG || ARGS_BUG;
11329_export({
11330 target: 'Reflect',
11331 stat: true,
11332 forced: FORCED$2,
11333 sham: FORCED$2
11334}, {
11335 construct: function construct(Target, args
11336 /* , newTarget */
11337 ) {
11338 aFunction(Target);
11339 anObject(args);
11340 var newTarget = arguments.length < 3 ? Target : aFunction(arguments[2]);
11341 if (ARGS_BUG && !NEW_TARGET_BUG) return nativeConstruct(Target, args, newTarget);
11342
11343 if (Target == newTarget) {
11344 // w/o altered newTarget, optimization for 0-4 arguments
11345 switch (args.length) {
11346 case 0:
11347 return new Target();
11348
11349 case 1:
11350 return new Target(args[0]);
11351
11352 case 2:
11353 return new Target(args[0], args[1]);
11354
11355 case 3:
11356 return new Target(args[0], args[1], args[2]);
11357
11358 case 4:
11359 return new Target(args[0], args[1], args[2], args[3]);
11360 } // w/o altered newTarget, lot of arguments case
11361
11362
11363 var $args = [null];
11364 $args.push.apply($args, args);
11365 return new (functionBind.apply(Target, $args))();
11366 } // with altered newTarget, not support built-in constructors
11367
11368
11369 var proto = newTarget.prototype;
11370 var instance = objectCreate(isObject$1(proto) ? proto : Object.prototype);
11371 var result = Function.apply.call(Target, instance, args);
11372 return isObject$1(result) ? result : instance;
11373 }
11374});
11375
11376var construct$2 = path.Reflect.construct;
11377
11378var construct$1 = construct$2;
11379
11380var construct = construct$1;
11381
11382var assertThisInitialized = createCommonjsModule(function (module) {
11383 function _assertThisInitialized(self) {
11384 if (self === void 0) {
11385 throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
11386 }
11387
11388 return self;
11389 }
11390
11391 module.exports = _assertThisInitialized;
11392 module.exports["default"] = module.exports, module.exports.__esModule = true;
11393});
11394var _assertThisInitialized = unwrapExports(assertThisInitialized);
11395
11396var create$1 = create$3;
11397
11398var create = create$1;
11399
11400// https://tc39.es/ecma262/#sec-object.setprototypeof
11401
11402_export({
11403 target: 'Object',
11404 stat: true
11405}, {
11406 setPrototypeOf: objectSetPrototypeOf
11407});
11408
11409var setPrototypeOf$4 = path.Object.setPrototypeOf;
11410
11411var setPrototypeOf$3 = setPrototypeOf$4;
11412
11413var setPrototypeOf$2 = setPrototypeOf$3;
11414
11415var setPrototypeOf$1 = setPrototypeOf$2;
11416
11417var setPrototypeOf = createCommonjsModule(function (module) {
11418 function _setPrototypeOf(o, p) {
11419 module.exports = _setPrototypeOf = setPrototypeOf$1 || function _setPrototypeOf(o, p) {
11420 o.__proto__ = p;
11421 return o;
11422 };
11423
11424 module.exports["default"] = module.exports, module.exports.__esModule = true;
11425 return _setPrototypeOf(o, p);
11426 }
11427
11428 module.exports = _setPrototypeOf;
11429 module.exports["default"] = module.exports, module.exports.__esModule = true;
11430});
11431unwrapExports(setPrototypeOf);
11432
11433var inherits = createCommonjsModule(function (module) {
11434 function _inherits(subClass, superClass) {
11435 if (typeof superClass !== "function" && superClass !== null) {
11436 throw new TypeError("Super expression must either be null or a function");
11437 }
11438
11439 subClass.prototype = create(superClass && superClass.prototype, {
11440 constructor: {
11441 value: subClass,
11442 writable: true,
11443 configurable: true
11444 }
11445 });
11446 if (superClass) setPrototypeOf(subClass, superClass);
11447 }
11448
11449 module.exports = _inherits;
11450 module.exports["default"] = module.exports, module.exports.__esModule = true;
11451});
11452var _inherits = unwrapExports(inherits);
11453
11454var possibleConstructorReturn = createCommonjsModule(function (module) {
11455 var _typeof = _typeof_1["default"];
11456
11457 function _possibleConstructorReturn(self, call) {
11458 if (call && (_typeof(call) === "object" || typeof call === "function")) {
11459 return call;
11460 } else if (call !== void 0) {
11461 throw new TypeError("Derived constructors may only return object or undefined");
11462 }
11463
11464 return assertThisInitialized(self);
11465 }
11466
11467 module.exports = _possibleConstructorReturn;
11468 module.exports["default"] = module.exports, module.exports.__esModule = true;
11469});
11470var _possibleConstructorReturn = unwrapExports(possibleConstructorReturn);
11471
11472var getPrototypeOf$2 = getPrototypeOf$4;
11473
11474var getPrototypeOf$1 = getPrototypeOf$2;
11475
11476var getPrototypeOf = createCommonjsModule(function (module) {
11477 function _getPrototypeOf(o) {
11478 module.exports = _getPrototypeOf = setPrototypeOf$1 ? getPrototypeOf$1 : function _getPrototypeOf(o) {
11479 return o.__proto__ || getPrototypeOf$1(o);
11480 };
11481 module.exports["default"] = module.exports, module.exports.__esModule = true;
11482 return _getPrototypeOf(o);
11483 }
11484
11485 module.exports = _getPrototypeOf;
11486 module.exports["default"] = module.exports, module.exports.__esModule = true;
11487});
11488var _getPrototypeOf = unwrapExports(getPrototypeOf);
11489
11490var runtime_1 = createCommonjsModule(function (module) {
11491 /**
11492 * Copyright (c) 2014-present, Facebook, Inc.
11493 *
11494 * This source code is licensed under the MIT license found in the
11495 * LICENSE file in the root directory of this source tree.
11496 */
11497 var runtime = function (exports) {
11498
11499 var Op = Object.prototype;
11500 var hasOwn = Op.hasOwnProperty;
11501 var undefined$1; // More compressible than void 0.
11502
11503 var $Symbol = typeof Symbol === "function" ? Symbol : {};
11504 var iteratorSymbol = $Symbol.iterator || "@@iterator";
11505 var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
11506 var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
11507
11508 function define(obj, key, value) {
11509 Object.defineProperty(obj, key, {
11510 value: value,
11511 enumerable: true,
11512 configurable: true,
11513 writable: true
11514 });
11515 return obj[key];
11516 }
11517
11518 try {
11519 // IE 8 has a broken Object.defineProperty that only works on DOM objects.
11520 define({}, "");
11521 } catch (err) {
11522 define = function (obj, key, value) {
11523 return obj[key] = value;
11524 };
11525 }
11526
11527 function wrap(innerFn, outerFn, self, tryLocsList) {
11528 // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
11529 var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
11530 var generator = Object.create(protoGenerator.prototype);
11531 var context = new Context(tryLocsList || []); // The ._invoke method unifies the implementations of the .next,
11532 // .throw, and .return methods.
11533
11534 generator._invoke = makeInvokeMethod(innerFn, self, context);
11535 return generator;
11536 }
11537
11538 exports.wrap = wrap; // Try/catch helper to minimize deoptimizations. Returns a completion
11539 // record like context.tryEntries[i].completion. This interface could
11540 // have been (and was previously) designed to take a closure to be
11541 // invoked without arguments, but in all the cases we care about we
11542 // already have an existing method we want to call, so there's no need
11543 // to create a new function object. We can even get away with assuming
11544 // the method takes exactly one argument, since that happens to be true
11545 // in every case, so we don't have to touch the arguments object. The
11546 // only additional allocation required is the completion record, which
11547 // has a stable shape and so hopefully should be cheap to allocate.
11548
11549 function tryCatch(fn, obj, arg) {
11550 try {
11551 return {
11552 type: "normal",
11553 arg: fn.call(obj, arg)
11554 };
11555 } catch (err) {
11556 return {
11557 type: "throw",
11558 arg: err
11559 };
11560 }
11561 }
11562
11563 var GenStateSuspendedStart = "suspendedStart";
11564 var GenStateSuspendedYield = "suspendedYield";
11565 var GenStateExecuting = "executing";
11566 var GenStateCompleted = "completed"; // Returning this object from the innerFn has the same effect as
11567 // breaking out of the dispatch switch statement.
11568
11569 var ContinueSentinel = {}; // Dummy constructor functions that we use as the .constructor and
11570 // .constructor.prototype properties for functions that return Generator
11571 // objects. For full spec compliance, you may wish to configure your
11572 // minifier not to mangle the names of these two functions.
11573
11574 function Generator() {}
11575
11576 function GeneratorFunction() {}
11577
11578 function GeneratorFunctionPrototype() {} // This is a polyfill for %IteratorPrototype% for environments that
11579 // don't natively support it.
11580
11581
11582 var IteratorPrototype = {};
11583
11584 IteratorPrototype[iteratorSymbol] = function () {
11585 return this;
11586 };
11587
11588 var getProto = Object.getPrototypeOf;
11589 var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
11590
11591 if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
11592 // This environment has a native %IteratorPrototype%; use it instead
11593 // of the polyfill.
11594 IteratorPrototype = NativeIteratorPrototype;
11595 }
11596
11597 var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
11598 GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
11599 GeneratorFunctionPrototype.constructor = GeneratorFunction;
11600 GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"); // Helper for defining the .next, .throw, and .return methods of the
11601 // Iterator interface in terms of a single ._invoke method.
11602
11603 function defineIteratorMethods(prototype) {
11604 ["next", "throw", "return"].forEach(function (method) {
11605 define(prototype, method, function (arg) {
11606 return this._invoke(method, arg);
11607 });
11608 });
11609 }
11610
11611 exports.isGeneratorFunction = function (genFun) {
11612 var ctor = typeof genFun === "function" && genFun.constructor;
11613 return ctor ? ctor === GeneratorFunction || // For the native GeneratorFunction constructor, the best we can
11614 // do is to check its .name property.
11615 (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
11616 };
11617
11618 exports.mark = function (genFun) {
11619 if (Object.setPrototypeOf) {
11620 Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
11621 } else {
11622 genFun.__proto__ = GeneratorFunctionPrototype;
11623 define(genFun, toStringTagSymbol, "GeneratorFunction");
11624 }
11625
11626 genFun.prototype = Object.create(Gp);
11627 return genFun;
11628 }; // Within the body of any async function, `await x` is transformed to
11629 // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
11630 // `hasOwn.call(value, "__await")` to determine if the yielded value is
11631 // meant to be awaited.
11632
11633
11634 exports.awrap = function (arg) {
11635 return {
11636 __await: arg
11637 };
11638 };
11639
11640 function AsyncIterator(generator, PromiseImpl) {
11641 function invoke(method, arg, resolve, reject) {
11642 var record = tryCatch(generator[method], generator, arg);
11643
11644 if (record.type === "throw") {
11645 reject(record.arg);
11646 } else {
11647 var result = record.arg;
11648 var value = result.value;
11649
11650 if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
11651 return PromiseImpl.resolve(value.__await).then(function (value) {
11652 invoke("next", value, resolve, reject);
11653 }, function (err) {
11654 invoke("throw", err, resolve, reject);
11655 });
11656 }
11657
11658 return PromiseImpl.resolve(value).then(function (unwrapped) {
11659 // When a yielded Promise is resolved, its final value becomes
11660 // the .value of the Promise<{value,done}> result for the
11661 // current iteration.
11662 result.value = unwrapped;
11663 resolve(result);
11664 }, function (error) {
11665 // If a rejected Promise was yielded, throw the rejection back
11666 // into the async generator function so it can be handled there.
11667 return invoke("throw", error, resolve, reject);
11668 });
11669 }
11670 }
11671
11672 var previousPromise;
11673
11674 function enqueue(method, arg) {
11675 function callInvokeWithMethodAndArg() {
11676 return new PromiseImpl(function (resolve, reject) {
11677 invoke(method, arg, resolve, reject);
11678 });
11679 }
11680
11681 return previousPromise = // If enqueue has been called before, then we want to wait until
11682 // all previous Promises have been resolved before calling invoke,
11683 // so that results are always delivered in the correct order. If
11684 // enqueue has not been called before, then it is important to
11685 // call invoke immediately, without waiting on a callback to fire,
11686 // so that the async generator function has the opportunity to do
11687 // any necessary setup in a predictable way. This predictability
11688 // is why the Promise constructor synchronously invokes its
11689 // executor callback, and why async functions synchronously
11690 // execute code before the first await. Since we implement simple
11691 // async functions in terms of async generators, it is especially
11692 // important to get this right, even though it requires care.
11693 previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, // Avoid propagating failures to Promises returned by later
11694 // invocations of the iterator.
11695 callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
11696 } // Define the unified helper method that is used to implement .next,
11697 // .throw, and .return (see defineIteratorMethods).
11698
11699
11700 this._invoke = enqueue;
11701 }
11702
11703 defineIteratorMethods(AsyncIterator.prototype);
11704
11705 AsyncIterator.prototype[asyncIteratorSymbol] = function () {
11706 return this;
11707 };
11708
11709 exports.AsyncIterator = AsyncIterator; // Note that simple async functions are implemented on top of
11710 // AsyncIterator objects; they just return a Promise for the value of
11711 // the final result produced by the iterator.
11712
11713 exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
11714 if (PromiseImpl === void 0) PromiseImpl = Promise;
11715 var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
11716 return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
11717 : iter.next().then(function (result) {
11718 return result.done ? result.value : iter.next();
11719 });
11720 };
11721
11722 function makeInvokeMethod(innerFn, self, context) {
11723 var state = GenStateSuspendedStart;
11724 return function invoke(method, arg) {
11725 if (state === GenStateExecuting) {
11726 throw new Error("Generator is already running");
11727 }
11728
11729 if (state === GenStateCompleted) {
11730 if (method === "throw") {
11731 throw arg;
11732 } // Be forgiving, per 25.3.3.3.3 of the spec:
11733 // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
11734
11735
11736 return doneResult();
11737 }
11738
11739 context.method = method;
11740 context.arg = arg;
11741
11742 while (true) {
11743 var delegate = context.delegate;
11744
11745 if (delegate) {
11746 var delegateResult = maybeInvokeDelegate(delegate, context);
11747
11748 if (delegateResult) {
11749 if (delegateResult === ContinueSentinel) continue;
11750 return delegateResult;
11751 }
11752 }
11753
11754 if (context.method === "next") {
11755 // Setting context._sent for legacy support of Babel's
11756 // function.sent implementation.
11757 context.sent = context._sent = context.arg;
11758 } else if (context.method === "throw") {
11759 if (state === GenStateSuspendedStart) {
11760 state = GenStateCompleted;
11761 throw context.arg;
11762 }
11763
11764 context.dispatchException(context.arg);
11765 } else if (context.method === "return") {
11766 context.abrupt("return", context.arg);
11767 }
11768
11769 state = GenStateExecuting;
11770 var record = tryCatch(innerFn, self, context);
11771
11772 if (record.type === "normal") {
11773 // If an exception is thrown from innerFn, we leave state ===
11774 // GenStateExecuting and loop back for another invocation.
11775 state = context.done ? GenStateCompleted : GenStateSuspendedYield;
11776
11777 if (record.arg === ContinueSentinel) {
11778 continue;
11779 }
11780
11781 return {
11782 value: record.arg,
11783 done: context.done
11784 };
11785 } else if (record.type === "throw") {
11786 state = GenStateCompleted; // Dispatch the exception by looping back around to the
11787 // context.dispatchException(context.arg) call above.
11788
11789 context.method = "throw";
11790 context.arg = record.arg;
11791 }
11792 }
11793 };
11794 } // Call delegate.iterator[context.method](context.arg) and handle the
11795 // result, either by returning a { value, done } result from the
11796 // delegate iterator, or by modifying context.method and context.arg,
11797 // setting context.delegate to null, and returning the ContinueSentinel.
11798
11799
11800 function maybeInvokeDelegate(delegate, context) {
11801 var method = delegate.iterator[context.method];
11802
11803 if (method === undefined$1) {
11804 // A .throw or .return when the delegate iterator has no .throw
11805 // method always terminates the yield* loop.
11806 context.delegate = null;
11807
11808 if (context.method === "throw") {
11809 // Note: ["return"] must be used for ES3 parsing compatibility.
11810 if (delegate.iterator["return"]) {
11811 // If the delegate iterator has a return method, give it a
11812 // chance to clean up.
11813 context.method = "return";
11814 context.arg = undefined$1;
11815 maybeInvokeDelegate(delegate, context);
11816
11817 if (context.method === "throw") {
11818 // If maybeInvokeDelegate(context) changed context.method from
11819 // "return" to "throw", let that override the TypeError below.
11820 return ContinueSentinel;
11821 }
11822 }
11823
11824 context.method = "throw";
11825 context.arg = new TypeError("The iterator does not provide a 'throw' method");
11826 }
11827
11828 return ContinueSentinel;
11829 }
11830
11831 var record = tryCatch(method, delegate.iterator, context.arg);
11832
11833 if (record.type === "throw") {
11834 context.method = "throw";
11835 context.arg = record.arg;
11836 context.delegate = null;
11837 return ContinueSentinel;
11838 }
11839
11840 var info = record.arg;
11841
11842 if (!info) {
11843 context.method = "throw";
11844 context.arg = new TypeError("iterator result is not an object");
11845 context.delegate = null;
11846 return ContinueSentinel;
11847 }
11848
11849 if (info.done) {
11850 // Assign the result of the finished delegate to the temporary
11851 // variable specified by delegate.resultName (see delegateYield).
11852 context[delegate.resultName] = info.value; // Resume execution at the desired location (see delegateYield).
11853
11854 context.next = delegate.nextLoc; // If context.method was "throw" but the delegate handled the
11855 // exception, let the outer generator proceed normally. If
11856 // context.method was "next", forget context.arg since it has been
11857 // "consumed" by the delegate iterator. If context.method was
11858 // "return", allow the original .return call to continue in the
11859 // outer generator.
11860
11861 if (context.method !== "return") {
11862 context.method = "next";
11863 context.arg = undefined$1;
11864 }
11865 } else {
11866 // Re-yield the result returned by the delegate method.
11867 return info;
11868 } // The delegate iterator is finished, so forget it and continue with
11869 // the outer generator.
11870
11871
11872 context.delegate = null;
11873 return ContinueSentinel;
11874 } // Define Generator.prototype.{next,throw,return} in terms of the
11875 // unified ._invoke helper method.
11876
11877
11878 defineIteratorMethods(Gp);
11879 define(Gp, toStringTagSymbol, "Generator"); // A Generator should always return itself as the iterator object when the
11880 // @@iterator function is called on it. Some browsers' implementations of the
11881 // iterator prototype chain incorrectly implement this, causing the Generator
11882 // object to not be returned from this call. This ensures that doesn't happen.
11883 // See https://github.com/facebook/regenerator/issues/274 for more details.
11884
11885 Gp[iteratorSymbol] = function () {
11886 return this;
11887 };
11888
11889 Gp.toString = function () {
11890 return "[object Generator]";
11891 };
11892
11893 function pushTryEntry(locs) {
11894 var entry = {
11895 tryLoc: locs[0]
11896 };
11897
11898 if (1 in locs) {
11899 entry.catchLoc = locs[1];
11900 }
11901
11902 if (2 in locs) {
11903 entry.finallyLoc = locs[2];
11904 entry.afterLoc = locs[3];
11905 }
11906
11907 this.tryEntries.push(entry);
11908 }
11909
11910 function resetTryEntry(entry) {
11911 var record = entry.completion || {};
11912 record.type = "normal";
11913 delete record.arg;
11914 entry.completion = record;
11915 }
11916
11917 function Context(tryLocsList) {
11918 // The root entry object (effectively a try statement without a catch
11919 // or a finally block) gives us a place to store values thrown from
11920 // locations where there is no enclosing try statement.
11921 this.tryEntries = [{
11922 tryLoc: "root"
11923 }];
11924 tryLocsList.forEach(pushTryEntry, this);
11925 this.reset(true);
11926 }
11927
11928 exports.keys = function (object) {
11929 var keys = [];
11930
11931 for (var key in object) {
11932 keys.push(key);
11933 }
11934
11935 keys.reverse(); // Rather than returning an object with a next method, we keep
11936 // things simple and return the next function itself.
11937
11938 return function next() {
11939 while (keys.length) {
11940 var key = keys.pop();
11941
11942 if (key in object) {
11943 next.value = key;
11944 next.done = false;
11945 return next;
11946 }
11947 } // To avoid creating an additional object, we just hang the .value
11948 // and .done properties off the next function object itself. This
11949 // also ensures that the minifier will not anonymize the function.
11950
11951
11952 next.done = true;
11953 return next;
11954 };
11955 };
11956
11957 function values(iterable) {
11958 if (iterable) {
11959 var iteratorMethod = iterable[iteratorSymbol];
11960
11961 if (iteratorMethod) {
11962 return iteratorMethod.call(iterable);
11963 }
11964
11965 if (typeof iterable.next === "function") {
11966 return iterable;
11967 }
11968
11969 if (!isNaN(iterable.length)) {
11970 var i = -1,
11971 next = function next() {
11972 while (++i < iterable.length) {
11973 if (hasOwn.call(iterable, i)) {
11974 next.value = iterable[i];
11975 next.done = false;
11976 return next;
11977 }
11978 }
11979
11980 next.value = undefined$1;
11981 next.done = true;
11982 return next;
11983 };
11984
11985 return next.next = next;
11986 }
11987 } // Return an iterator with no values.
11988
11989
11990 return {
11991 next: doneResult
11992 };
11993 }
11994
11995 exports.values = values;
11996
11997 function doneResult() {
11998 return {
11999 value: undefined$1,
12000 done: true
12001 };
12002 }
12003
12004 Context.prototype = {
12005 constructor: Context,
12006 reset: function (skipTempReset) {
12007 this.prev = 0;
12008 this.next = 0; // Resetting context._sent for legacy support of Babel's
12009 // function.sent implementation.
12010
12011 this.sent = this._sent = undefined$1;
12012 this.done = false;
12013 this.delegate = null;
12014 this.method = "next";
12015 this.arg = undefined$1;
12016 this.tryEntries.forEach(resetTryEntry);
12017
12018 if (!skipTempReset) {
12019 for (var name in this) {
12020 // Not sure about the optimal order of these conditions:
12021 if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
12022 this[name] = undefined$1;
12023 }
12024 }
12025 }
12026 },
12027 stop: function () {
12028 this.done = true;
12029 var rootEntry = this.tryEntries[0];
12030 var rootRecord = rootEntry.completion;
12031
12032 if (rootRecord.type === "throw") {
12033 throw rootRecord.arg;
12034 }
12035
12036 return this.rval;
12037 },
12038 dispatchException: function (exception) {
12039 if (this.done) {
12040 throw exception;
12041 }
12042
12043 var context = this;
12044
12045 function handle(loc, caught) {
12046 record.type = "throw";
12047 record.arg = exception;
12048 context.next = loc;
12049
12050 if (caught) {
12051 // If the dispatched exception was caught by a catch block,
12052 // then let that catch block handle the exception normally.
12053 context.method = "next";
12054 context.arg = undefined$1;
12055 }
12056
12057 return !!caught;
12058 }
12059
12060 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
12061 var entry = this.tryEntries[i];
12062 var record = entry.completion;
12063
12064 if (entry.tryLoc === "root") {
12065 // Exception thrown outside of any try block that could handle
12066 // it, so set the completion value of the entire function to
12067 // throw the exception.
12068 return handle("end");
12069 }
12070
12071 if (entry.tryLoc <= this.prev) {
12072 var hasCatch = hasOwn.call(entry, "catchLoc");
12073 var hasFinally = hasOwn.call(entry, "finallyLoc");
12074
12075 if (hasCatch && hasFinally) {
12076 if (this.prev < entry.catchLoc) {
12077 return handle(entry.catchLoc, true);
12078 } else if (this.prev < entry.finallyLoc) {
12079 return handle(entry.finallyLoc);
12080 }
12081 } else if (hasCatch) {
12082 if (this.prev < entry.catchLoc) {
12083 return handle(entry.catchLoc, true);
12084 }
12085 } else if (hasFinally) {
12086 if (this.prev < entry.finallyLoc) {
12087 return handle(entry.finallyLoc);
12088 }
12089 } else {
12090 throw new Error("try statement without catch or finally");
12091 }
12092 }
12093 }
12094 },
12095 abrupt: function (type, arg) {
12096 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
12097 var entry = this.tryEntries[i];
12098
12099 if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
12100 var finallyEntry = entry;
12101 break;
12102 }
12103 }
12104
12105 if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
12106 // Ignore the finally entry if control is not jumping to a
12107 // location outside the try/catch block.
12108 finallyEntry = null;
12109 }
12110
12111 var record = finallyEntry ? finallyEntry.completion : {};
12112 record.type = type;
12113 record.arg = arg;
12114
12115 if (finallyEntry) {
12116 this.method = "next";
12117 this.next = finallyEntry.finallyLoc;
12118 return ContinueSentinel;
12119 }
12120
12121 return this.complete(record);
12122 },
12123 complete: function (record, afterLoc) {
12124 if (record.type === "throw") {
12125 throw record.arg;
12126 }
12127
12128 if (record.type === "break" || record.type === "continue") {
12129 this.next = record.arg;
12130 } else if (record.type === "return") {
12131 this.rval = this.arg = record.arg;
12132 this.method = "return";
12133 this.next = "end";
12134 } else if (record.type === "normal" && afterLoc) {
12135 this.next = afterLoc;
12136 }
12137
12138 return ContinueSentinel;
12139 },
12140 finish: function (finallyLoc) {
12141 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
12142 var entry = this.tryEntries[i];
12143
12144 if (entry.finallyLoc === finallyLoc) {
12145 this.complete(entry.completion, entry.afterLoc);
12146 resetTryEntry(entry);
12147 return ContinueSentinel;
12148 }
12149 }
12150 },
12151 "catch": function (tryLoc) {
12152 for (var i = this.tryEntries.length - 1; i >= 0; --i) {
12153 var entry = this.tryEntries[i];
12154
12155 if (entry.tryLoc === tryLoc) {
12156 var record = entry.completion;
12157
12158 if (record.type === "throw") {
12159 var thrown = record.arg;
12160 resetTryEntry(entry);
12161 }
12162
12163 return thrown;
12164 }
12165 } // The context.catch method must only be called with a location
12166 // argument that corresponds to a known catch block.
12167
12168
12169 throw new Error("illegal catch attempt");
12170 },
12171 delegateYield: function (iterable, resultName, nextLoc) {
12172 this.delegate = {
12173 iterator: values(iterable),
12174 resultName: resultName,
12175 nextLoc: nextLoc
12176 };
12177
12178 if (this.method === "next") {
12179 // Deliberately forget the last sent value so that we don't
12180 // accidentally pass it on to the delegate.
12181 this.arg = undefined$1;
12182 }
12183
12184 return ContinueSentinel;
12185 }
12186 }; // Regardless of whether this script is executing as a CommonJS module
12187 // or not, return the runtime object so that we can declare the variable
12188 // regeneratorRuntime in the outer scope, which allows this module to be
12189 // injected easily by `bin/regenerator --include-runtime script.js`.
12190
12191 return exports;
12192 }( // If this script is executing as a CommonJS module, use module.exports
12193 // as the regeneratorRuntime namespace. Otherwise create a new empty
12194 // object. Either way, the resulting object will be used to initialize
12195 // the regeneratorRuntime variable at the top of this file.
12196 module.exports );
12197
12198 try {
12199 regeneratorRuntime = runtime;
12200 } catch (accidentalStrictMode) {
12201 // This module should not be running in strict mode, so the above
12202 // assignment should always work unless something is misconfigured. Just
12203 // in case runtime.js accidentally runs in strict mode, we can escape
12204 // strict mode using a global Function call. This could conceivably fail
12205 // if a Content Security Policy forbids using Function, but in that case
12206 // the proper solution is to fix the accidental strict mode problem. If
12207 // you've misconfigured your bundler to force strict mode and applied a
12208 // CSP to forbid Function, and you're not willing to fix either of those
12209 // problems, please detail your unique predicament in a GitHub issue.
12210 Function("r", "regeneratorRuntime = r")(runtime);
12211 }
12212});
12213
12214var regenerator = runtime_1;
12215
12216var createMethod = function (IS_RIGHT) {
12217 return function (that, callbackfn, argumentsLength, memo) {
12218 aFunction(callbackfn);
12219 var O = toObject(that);
12220 var self = indexedObject(O);
12221 var length = toLength(O.length);
12222 var index = IS_RIGHT ? length - 1 : 0;
12223 var i = IS_RIGHT ? -1 : 1;
12224 if (argumentsLength < 2) while (true) {
12225 if (index in self) {
12226 memo = self[index];
12227 index += i;
12228 break;
12229 }
12230
12231 index += i;
12232
12233 if (IS_RIGHT ? index < 0 : length <= index) {
12234 throw TypeError('Reduce of empty array with no initial value');
12235 }
12236 }
12237
12238 for (; IS_RIGHT ? index >= 0 : length > index; index += i) if (index in self) {
12239 memo = callbackfn(memo, self[index], index, O);
12240 }
12241
12242 return memo;
12243 };
12244};
12245
12246var arrayReduce = {
12247 // `Array.prototype.reduce` method
12248 // https://tc39.es/ecma262/#sec-array.prototype.reduce
12249 left: createMethod(false),
12250 // `Array.prototype.reduceRight` method
12251 // https://tc39.es/ecma262/#sec-array.prototype.reduceright
12252 right: createMethod(true)
12253};
12254
12255var engineIsNode = classofRaw(global_1.process) == 'process';
12256
12257var $reduce = arrayReduce.left;
12258var STRICT_METHOD$2 = arrayMethodIsStrict('reduce'); // Chrome 80-82 has a critical bug
12259// https://bugs.chromium.org/p/chromium/issues/detail?id=1049982
12260
12261var CHROME_BUG = !engineIsNode && engineV8Version > 79 && engineV8Version < 83; // `Array.prototype.reduce` method
12262// https://tc39.es/ecma262/#sec-array.prototype.reduce
12263
12264_export({
12265 target: 'Array',
12266 proto: true,
12267 forced: !STRICT_METHOD$2 || CHROME_BUG
12268}, {
12269 reduce: function reduce(callbackfn
12270 /* , initialValue */
12271 ) {
12272 return $reduce(this, callbackfn, arguments.length, arguments.length > 1 ? arguments[1] : undefined);
12273 }
12274});
12275
12276var reduce$2 = entryVirtual('Array').reduce;
12277
12278var ArrayPrototype$6 = Array.prototype;
12279
12280var reduce_1 = function (it) {
12281 var own = it.reduce;
12282 return it === ArrayPrototype$6 || it instanceof Array && own === ArrayPrototype$6.reduce ? reduce$2 : own;
12283};
12284
12285var reduce$1 = reduce_1;
12286
12287var reduce = reduce$1;
12288
12289// https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
12290
12291
12292var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
12293 var targetIndex = start;
12294 var sourceIndex = 0;
12295 var mapFn = mapper ? functionBindContext(mapper, thisArg, 3) : false;
12296 var element;
12297
12298 while (sourceIndex < sourceLen) {
12299 if (sourceIndex in source) {
12300 element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
12301
12302 if (depth > 0 && isArray$5(element)) {
12303 targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
12304 } else {
12305 if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
12306 target[targetIndex] = element;
12307 }
12308
12309 targetIndex++;
12310 }
12311
12312 sourceIndex++;
12313 }
12314
12315 return targetIndex;
12316};
12317
12318var flattenIntoArray_1 = flattenIntoArray;
12319
12320// https://tc39.es/ecma262/#sec-array.prototype.flatmap
12321
12322
12323_export({
12324 target: 'Array',
12325 proto: true
12326}, {
12327 flatMap: function flatMap(callbackfn
12328 /* , thisArg */
12329 ) {
12330 var O = toObject(this);
12331 var sourceLen = toLength(O.length);
12332 var A;
12333 aFunction(callbackfn);
12334 A = arraySpeciesCreate(O, 0);
12335 A.length = flattenIntoArray_1(A, O, O, sourceLen, 0, 1, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
12336 return A;
12337 }
12338});
12339
12340var flatMap$2 = entryVirtual('Array').flatMap;
12341
12342var ArrayPrototype$5 = Array.prototype;
12343
12344var flatMap_1 = function (it) {
12345 var own = it.flatMap;
12346 return it === ArrayPrototype$5 || it instanceof Array && own === ArrayPrototype$5.flatMap ? flatMap$2 : own;
12347};
12348
12349var flatMap$1 = flatMap_1;
12350
12351var flatMap = flatMap$1;
12352
12353var freezing = !fails(function () {
12354 // eslint-disable-next-line es/no-object-isextensible, es/no-object-preventextensions -- required for testing
12355 return Object.isExtensible(Object.preventExtensions({}));
12356});
12357
12358var internalMetadata = createCommonjsModule(function (module) {
12359 var defineProperty = objectDefineProperty.f;
12360 var REQUIRED = false;
12361 var METADATA = uid('meta');
12362 var id = 0; // eslint-disable-next-line es/no-object-isextensible -- safe
12363
12364 var isExtensible = Object.isExtensible || function () {
12365 return true;
12366 };
12367
12368 var setMetadata = function (it) {
12369 defineProperty(it, METADATA, {
12370 value: {
12371 objectID: 'O' + id++,
12372 // object ID
12373 weakData: {} // weak collections IDs
12374
12375 }
12376 });
12377 };
12378
12379 var fastKey = function (it, create) {
12380 // return a primitive with prefix
12381 if (!isObject$1(it)) return typeof it == 'symbol' ? it : (typeof it == 'string' ? 'S' : 'P') + it;
12382
12383 if (!has$1(it, METADATA)) {
12384 // can't set metadata to uncaught frozen object
12385 if (!isExtensible(it)) return 'F'; // not necessary to add metadata
12386
12387 if (!create) return 'E'; // add missing metadata
12388
12389 setMetadata(it); // return object ID
12390 }
12391
12392 return it[METADATA].objectID;
12393 };
12394
12395 var getWeakData = function (it, create) {
12396 if (!has$1(it, METADATA)) {
12397 // can't set metadata to uncaught frozen object
12398 if (!isExtensible(it)) return true; // not necessary to add metadata
12399
12400 if (!create) return false; // add missing metadata
12401
12402 setMetadata(it); // return the store of weak collections IDs
12403 }
12404
12405 return it[METADATA].weakData;
12406 }; // add metadata on freeze-family methods calling
12407
12408
12409 var onFreeze = function (it) {
12410 if (freezing && REQUIRED && isExtensible(it) && !has$1(it, METADATA)) setMetadata(it);
12411 return it;
12412 };
12413
12414 var enable = function () {
12415 meta.enable = function () {
12416 /* empty */
12417 };
12418
12419 REQUIRED = true;
12420 var getOwnPropertyNames = objectGetOwnPropertyNames.f;
12421 var splice = [].splice;
12422 var test = {};
12423 test[METADATA] = 1; // prevent exposing of metadata key
12424
12425 if (getOwnPropertyNames(test).length) {
12426 objectGetOwnPropertyNames.f = function (it) {
12427 var result = getOwnPropertyNames(it);
12428
12429 for (var i = 0, length = result.length; i < length; i++) {
12430 if (result[i] === METADATA) {
12431 splice.call(result, i, 1);
12432 break;
12433 }
12434 }
12435
12436 return result;
12437 };
12438
12439 _export({
12440 target: 'Object',
12441 stat: true,
12442 forced: true
12443 }, {
12444 getOwnPropertyNames: objectGetOwnPropertyNamesExternal.f
12445 });
12446 }
12447 };
12448
12449 var meta = module.exports = {
12450 enable: enable,
12451 fastKey: fastKey,
12452 getWeakData: getWeakData,
12453 onFreeze: onFreeze
12454 };
12455 hiddenKeys$1[METADATA] = true;
12456});
12457internalMetadata.enable;
12458internalMetadata.fastKey;
12459internalMetadata.getWeakData;
12460internalMetadata.onFreeze;
12461
12462var Result = function (stopped, result) {
12463 this.stopped = stopped;
12464 this.result = result;
12465};
12466
12467var iterate = function (iterable, unboundFunction, options) {
12468 var that = options && options.that;
12469 var AS_ENTRIES = !!(options && options.AS_ENTRIES);
12470 var IS_ITERATOR = !!(options && options.IS_ITERATOR);
12471 var INTERRUPTED = !!(options && options.INTERRUPTED);
12472 var fn = functionBindContext(unboundFunction, that, 1 + AS_ENTRIES + INTERRUPTED);
12473 var iterator, iterFn, index, length, result, next, step;
12474
12475 var stop = function (condition) {
12476 if (iterator) iteratorClose(iterator);
12477 return new Result(true, condition);
12478 };
12479
12480 var callFn = function (value) {
12481 if (AS_ENTRIES) {
12482 anObject(value);
12483 return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
12484 }
12485
12486 return INTERRUPTED ? fn(value, stop) : fn(value);
12487 };
12488
12489 if (IS_ITERATOR) {
12490 iterator = iterable;
12491 } else {
12492 iterFn = getIteratorMethod$3(iterable);
12493 if (typeof iterFn != 'function') throw TypeError('Target is not iterable'); // optimisation for array iterators
12494
12495 if (isArrayIteratorMethod(iterFn)) {
12496 for (index = 0, length = toLength(iterable.length); length > index; index++) {
12497 result = callFn(iterable[index]);
12498 if (result && result instanceof Result) return result;
12499 }
12500
12501 return new Result(false);
12502 }
12503
12504 iterator = iterFn.call(iterable);
12505 }
12506
12507 next = iterator.next;
12508
12509 while (!(step = next.call(iterator)).done) {
12510 try {
12511 result = callFn(step.value);
12512 } catch (error) {
12513 iteratorClose(iterator);
12514 throw error;
12515 }
12516
12517 if (typeof result == 'object' && result && result instanceof Result) return result;
12518 }
12519
12520 return new Result(false);
12521};
12522
12523var anInstance = function (it, Constructor, name) {
12524 if (!(it instanceof Constructor)) {
12525 throw TypeError('Incorrect ' + (name ? name + ' ' : '') + 'invocation');
12526 }
12527
12528 return it;
12529};
12530
12531var defineProperty$1 = objectDefineProperty.f;
12532var forEach = arrayIteration.forEach;
12533var setInternalState$1 = internalState.set;
12534var internalStateGetterFor$1 = internalState.getterFor;
12535
12536var collection = function (CONSTRUCTOR_NAME, wrapper, common) {
12537 var IS_MAP = CONSTRUCTOR_NAME.indexOf('Map') !== -1;
12538 var IS_WEAK = CONSTRUCTOR_NAME.indexOf('Weak') !== -1;
12539 var ADDER = IS_MAP ? 'set' : 'add';
12540 var NativeConstructor = global_1[CONSTRUCTOR_NAME];
12541 var NativePrototype = NativeConstructor && NativeConstructor.prototype;
12542 var exported = {};
12543 var Constructor;
12544
12545 if (!descriptors || typeof NativeConstructor != 'function' || !(IS_WEAK || NativePrototype.forEach && !fails(function () {
12546 new NativeConstructor().entries().next();
12547 }))) {
12548 // create collection constructor
12549 Constructor = common.getConstructor(wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER);
12550 internalMetadata.enable();
12551 } else {
12552 Constructor = wrapper(function (target, iterable) {
12553 setInternalState$1(anInstance(target, Constructor, CONSTRUCTOR_NAME), {
12554 type: CONSTRUCTOR_NAME,
12555 collection: new NativeConstructor()
12556 });
12557 if (iterable != undefined) iterate(iterable, target[ADDER], {
12558 that: target,
12559 AS_ENTRIES: IS_MAP
12560 });
12561 });
12562 var getInternalState = internalStateGetterFor$1(CONSTRUCTOR_NAME);
12563 forEach(['add', 'clear', 'delete', 'forEach', 'get', 'has', 'set', 'keys', 'values', 'entries'], function (KEY) {
12564 var IS_ADDER = KEY == 'add' || KEY == 'set';
12565
12566 if (KEY in NativePrototype && !(IS_WEAK && KEY == 'clear')) {
12567 createNonEnumerableProperty(Constructor.prototype, KEY, function (a, b) {
12568 var collection = getInternalState(this).collection;
12569 if (!IS_ADDER && IS_WEAK && !isObject$1(a)) return KEY == 'get' ? undefined : false;
12570 var result = collection[KEY](a === 0 ? 0 : a, b);
12571 return IS_ADDER ? this : result;
12572 });
12573 }
12574 });
12575 IS_WEAK || defineProperty$1(Constructor.prototype, 'size', {
12576 configurable: true,
12577 get: function () {
12578 return getInternalState(this).collection.size;
12579 }
12580 });
12581 }
12582
12583 setToStringTag(Constructor, CONSTRUCTOR_NAME, false, true);
12584 exported[CONSTRUCTOR_NAME] = Constructor;
12585 _export({
12586 global: true,
12587 forced: true
12588 }, exported);
12589 if (!IS_WEAK) common.setStrong(Constructor, CONSTRUCTOR_NAME, IS_MAP);
12590 return Constructor;
12591};
12592
12593var redefineAll = function (target, src, options) {
12594 for (var key in src) {
12595 if (options && options.unsafe && target[key]) target[key] = src[key];else redefine(target, key, src[key], options);
12596 }
12597
12598 return target;
12599};
12600
12601var SPECIES = wellKnownSymbol('species');
12602
12603var setSpecies = function (CONSTRUCTOR_NAME) {
12604 var Constructor = getBuiltIn(CONSTRUCTOR_NAME);
12605 var defineProperty = objectDefineProperty.f;
12606
12607 if (descriptors && Constructor && !Constructor[SPECIES]) {
12608 defineProperty(Constructor, SPECIES, {
12609 configurable: true,
12610 get: function () {
12611 return this;
12612 }
12613 });
12614 }
12615};
12616
12617var defineProperty = objectDefineProperty.f;
12618var fastKey = internalMetadata.fastKey;
12619var setInternalState = internalState.set;
12620var internalStateGetterFor = internalState.getterFor;
12621var collectionStrong = {
12622 getConstructor: function (wrapper, CONSTRUCTOR_NAME, IS_MAP, ADDER) {
12623 var C = wrapper(function (that, iterable) {
12624 anInstance(that, C, CONSTRUCTOR_NAME);
12625 setInternalState(that, {
12626 type: CONSTRUCTOR_NAME,
12627 index: objectCreate(null),
12628 first: undefined,
12629 last: undefined,
12630 size: 0
12631 });
12632 if (!descriptors) that.size = 0;
12633 if (iterable != undefined) iterate(iterable, that[ADDER], {
12634 that: that,
12635 AS_ENTRIES: IS_MAP
12636 });
12637 });
12638 var getInternalState = internalStateGetterFor(CONSTRUCTOR_NAME);
12639
12640 var define = function (that, key, value) {
12641 var state = getInternalState(that);
12642 var entry = getEntry(that, key);
12643 var previous, index; // change existing entry
12644
12645 if (entry) {
12646 entry.value = value; // create new entry
12647 } else {
12648 state.last = entry = {
12649 index: index = fastKey(key, true),
12650 key: key,
12651 value: value,
12652 previous: previous = state.last,
12653 next: undefined,
12654 removed: false
12655 };
12656 if (!state.first) state.first = entry;
12657 if (previous) previous.next = entry;
12658 if (descriptors) state.size++;else that.size++; // add to index
12659
12660 if (index !== 'F') state.index[index] = entry;
12661 }
12662
12663 return that;
12664 };
12665
12666 var getEntry = function (that, key) {
12667 var state = getInternalState(that); // fast case
12668
12669 var index = fastKey(key);
12670 var entry;
12671 if (index !== 'F') return state.index[index]; // frozen object case
12672
12673 for (entry = state.first; entry; entry = entry.next) {
12674 if (entry.key == key) return entry;
12675 }
12676 };
12677
12678 redefineAll(C.prototype, {
12679 // `{ Map, Set }.prototype.clear()` methods
12680 // https://tc39.es/ecma262/#sec-map.prototype.clear
12681 // https://tc39.es/ecma262/#sec-set.prototype.clear
12682 clear: function clear() {
12683 var that = this;
12684 var state = getInternalState(that);
12685 var data = state.index;
12686 var entry = state.first;
12687
12688 while (entry) {
12689 entry.removed = true;
12690 if (entry.previous) entry.previous = entry.previous.next = undefined;
12691 delete data[entry.index];
12692 entry = entry.next;
12693 }
12694
12695 state.first = state.last = undefined;
12696 if (descriptors) state.size = 0;else that.size = 0;
12697 },
12698 // `{ Map, Set }.prototype.delete(key)` methods
12699 // https://tc39.es/ecma262/#sec-map.prototype.delete
12700 // https://tc39.es/ecma262/#sec-set.prototype.delete
12701 'delete': function (key) {
12702 var that = this;
12703 var state = getInternalState(that);
12704 var entry = getEntry(that, key);
12705
12706 if (entry) {
12707 var next = entry.next;
12708 var prev = entry.previous;
12709 delete state.index[entry.index];
12710 entry.removed = true;
12711 if (prev) prev.next = next;
12712 if (next) next.previous = prev;
12713 if (state.first == entry) state.first = next;
12714 if (state.last == entry) state.last = prev;
12715 if (descriptors) state.size--;else that.size--;
12716 }
12717
12718 return !!entry;
12719 },
12720 // `{ Map, Set }.prototype.forEach(callbackfn, thisArg = undefined)` methods
12721 // https://tc39.es/ecma262/#sec-map.prototype.foreach
12722 // https://tc39.es/ecma262/#sec-set.prototype.foreach
12723 forEach: function forEach(callbackfn
12724 /* , that = undefined */
12725 ) {
12726 var state = getInternalState(this);
12727 var boundFunction = functionBindContext(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3);
12728 var entry;
12729
12730 while (entry = entry ? entry.next : state.first) {
12731 boundFunction(entry.value, entry.key, this); // revert to the last existing entry
12732
12733 while (entry && entry.removed) entry = entry.previous;
12734 }
12735 },
12736 // `{ Map, Set}.prototype.has(key)` methods
12737 // https://tc39.es/ecma262/#sec-map.prototype.has
12738 // https://tc39.es/ecma262/#sec-set.prototype.has
12739 has: function has(key) {
12740 return !!getEntry(this, key);
12741 }
12742 });
12743 redefineAll(C.prototype, IS_MAP ? {
12744 // `Map.prototype.get(key)` method
12745 // https://tc39.es/ecma262/#sec-map.prototype.get
12746 get: function get(key) {
12747 var entry = getEntry(this, key);
12748 return entry && entry.value;
12749 },
12750 // `Map.prototype.set(key, value)` method
12751 // https://tc39.es/ecma262/#sec-map.prototype.set
12752 set: function set(key, value) {
12753 return define(this, key === 0 ? 0 : key, value);
12754 }
12755 } : {
12756 // `Set.prototype.add(value)` method
12757 // https://tc39.es/ecma262/#sec-set.prototype.add
12758 add: function add(value) {
12759 return define(this, value = value === 0 ? 0 : value, value);
12760 }
12761 });
12762 if (descriptors) defineProperty(C.prototype, 'size', {
12763 get: function () {
12764 return getInternalState(this).size;
12765 }
12766 });
12767 return C;
12768 },
12769 setStrong: function (C, CONSTRUCTOR_NAME, IS_MAP) {
12770 var ITERATOR_NAME = CONSTRUCTOR_NAME + ' Iterator';
12771 var getInternalCollectionState = internalStateGetterFor(CONSTRUCTOR_NAME);
12772 var getInternalIteratorState = internalStateGetterFor(ITERATOR_NAME); // `{ Map, Set }.prototype.{ keys, values, entries, @@iterator }()` methods
12773 // https://tc39.es/ecma262/#sec-map.prototype.entries
12774 // https://tc39.es/ecma262/#sec-map.prototype.keys
12775 // https://tc39.es/ecma262/#sec-map.prototype.values
12776 // https://tc39.es/ecma262/#sec-map.prototype-@@iterator
12777 // https://tc39.es/ecma262/#sec-set.prototype.entries
12778 // https://tc39.es/ecma262/#sec-set.prototype.keys
12779 // https://tc39.es/ecma262/#sec-set.prototype.values
12780 // https://tc39.es/ecma262/#sec-set.prototype-@@iterator
12781
12782 defineIterator(C, CONSTRUCTOR_NAME, function (iterated, kind) {
12783 setInternalState(this, {
12784 type: ITERATOR_NAME,
12785 target: iterated,
12786 state: getInternalCollectionState(iterated),
12787 kind: kind,
12788 last: undefined
12789 });
12790 }, function () {
12791 var state = getInternalIteratorState(this);
12792 var kind = state.kind;
12793 var entry = state.last; // revert to the last existing entry
12794
12795 while (entry && entry.removed) entry = entry.previous; // get next entry
12796
12797
12798 if (!state.target || !(state.last = entry = entry ? entry.next : state.state.first)) {
12799 // or finish the iteration
12800 state.target = undefined;
12801 return {
12802 value: undefined,
12803 done: true
12804 };
12805 } // return step by kind
12806
12807
12808 if (kind == 'keys') return {
12809 value: entry.key,
12810 done: false
12811 };
12812 if (kind == 'values') return {
12813 value: entry.value,
12814 done: false
12815 };
12816 return {
12817 value: [entry.key, entry.value],
12818 done: false
12819 };
12820 }, IS_MAP ? 'entries' : 'values', !IS_MAP, true); // `{ Map, Set }.prototype[@@species]` accessors
12821 // https://tc39.es/ecma262/#sec-get-map-@@species
12822 // https://tc39.es/ecma262/#sec-get-set-@@species
12823
12824 setSpecies(CONSTRUCTOR_NAME);
12825 }
12826};
12827collectionStrong.getConstructor;
12828collectionStrong.setStrong;
12829
12830// https://tc39.es/ecma262/#sec-map-objects
12831
12832
12833collection('Map', function (init) {
12834 return function Map() {
12835 return init(this, arguments.length ? arguments[0] : undefined);
12836 };
12837}, collectionStrong);
12838
12839var map$2 = path.Map;
12840
12841var map$1 = map$2;
12842
12843var map = map$1;
12844
12845// https://tc39.es/ecma262/#sec-set-objects
12846
12847
12848collection('Set', function (init) {
12849 return function Set() {
12850 return init(this, arguments.length ? arguments[0] : undefined);
12851 };
12852}, collectionStrong);
12853
12854var set$2 = path.Set;
12855
12856var set$1 = set$2;
12857
12858var set = set$1;
12859
12860var iterator = iterator$3;
12861
12862var getIterator$3 = function (it) {
12863 var iteratorMethod = getIteratorMethod$3(it);
12864
12865 if (typeof iteratorMethod != 'function') {
12866 throw TypeError(String(it) + ' is not iterable');
12867 }
12868
12869 return anObject(iteratorMethod.call(it));
12870};
12871
12872var getIterator_1 = getIterator$3;
12873
12874var getIterator$2 = getIterator_1;
12875
12876var getIterator$1 = getIterator$2;
12877
12878var getIterator = getIterator$1;
12879
12880// TODO: use something more complex like timsort?
12881var floor = Math.floor;
12882
12883var mergeSort = function (array, comparefn) {
12884 var length = array.length;
12885 var middle = floor(length / 2);
12886 return length < 8 ? insertionSort(array, comparefn) : merge(mergeSort(array.slice(0, middle), comparefn), mergeSort(array.slice(middle), comparefn), comparefn);
12887};
12888
12889var insertionSort = function (array, comparefn) {
12890 var length = array.length;
12891 var i = 1;
12892 var element, j;
12893
12894 while (i < length) {
12895 j = i;
12896 element = array[i];
12897
12898 while (j && comparefn(array[j - 1], element) > 0) {
12899 array[j] = array[--j];
12900 }
12901
12902 if (j !== i++) array[j] = element;
12903 }
12904
12905 return array;
12906};
12907
12908var merge = function (left, right, comparefn) {
12909 var llength = left.length;
12910 var rlength = right.length;
12911 var lindex = 0;
12912 var rindex = 0;
12913 var result = [];
12914
12915 while (lindex < llength || rindex < rlength) {
12916 if (lindex < llength && rindex < rlength) {
12917 result.push(comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]);
12918 } else {
12919 result.push(lindex < llength ? left[lindex++] : right[rindex++]);
12920 }
12921 }
12922
12923 return result;
12924};
12925
12926var arraySort = mergeSort;
12927
12928var firefox = engineUserAgent.match(/firefox\/(\d+)/i);
12929var engineFfVersion = !!firefox && +firefox[1];
12930
12931var engineIsIeOrEdge = /MSIE|Trident/.test(engineUserAgent);
12932
12933var webkit = engineUserAgent.match(/AppleWebKit\/(\d+)\./);
12934var engineWebkitVersion = !!webkit && +webkit[1];
12935
12936var test = [];
12937var nativeSort = test.sort; // IE8-
12938
12939var FAILS_ON_UNDEFINED = fails(function () {
12940 test.sort(undefined);
12941}); // V8 bug
12942
12943var FAILS_ON_NULL = fails(function () {
12944 test.sort(null);
12945}); // Old WebKit
12946
12947var STRICT_METHOD$1 = arrayMethodIsStrict('sort');
12948var STABLE_SORT = !fails(function () {
12949 // feature detection can be too slow, so check engines versions
12950 if (engineV8Version) return engineV8Version < 70;
12951 if (engineFfVersion && engineFfVersion > 3) return;
12952 if (engineIsIeOrEdge) return true;
12953 if (engineWebkitVersion) return engineWebkitVersion < 603;
12954 var result = '';
12955 var code, chr, value, index; // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
12956
12957 for (code = 65; code < 76; code++) {
12958 chr = String.fromCharCode(code);
12959
12960 switch (code) {
12961 case 66:
12962 case 69:
12963 case 70:
12964 case 72:
12965 value = 3;
12966 break;
12967
12968 case 68:
12969 case 71:
12970 value = 4;
12971 break;
12972
12973 default:
12974 value = 2;
12975 }
12976
12977 for (index = 0; index < 47; index++) {
12978 test.push({
12979 k: chr + index,
12980 v: value
12981 });
12982 }
12983 }
12984
12985 test.sort(function (a, b) {
12986 return b.v - a.v;
12987 });
12988
12989 for (index = 0; index < test.length; index++) {
12990 chr = test[index].k.charAt(0);
12991 if (result.charAt(result.length - 1) !== chr) result += chr;
12992 }
12993
12994 return result !== 'DGBEFHACIJK';
12995});
12996var FORCED$1 = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD$1 || !STABLE_SORT;
12997
12998var getSortCompare = function (comparefn) {
12999 return function (x, y) {
13000 if (y === undefined) return -1;
13001 if (x === undefined) return 1;
13002 if (comparefn !== undefined) return +comparefn(x, y) || 0;
13003 return toString_1(x) > toString_1(y) ? 1 : -1;
13004 };
13005}; // `Array.prototype.sort` method
13006// https://tc39.es/ecma262/#sec-array.prototype.sort
13007
13008
13009_export({
13010 target: 'Array',
13011 proto: true,
13012 forced: FORCED$1
13013}, {
13014 sort: function sort(comparefn) {
13015 if (comparefn !== undefined) aFunction(comparefn);
13016 var array = toObject(this);
13017 if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
13018 var items = [];
13019 var arrayLength = toLength(array.length);
13020 var itemsLength, index;
13021
13022 for (index = 0; index < arrayLength; index++) {
13023 if (index in array) items.push(array[index]);
13024 }
13025
13026 items = arraySort(items, getSortCompare(comparefn));
13027 itemsLength = items.length;
13028 index = 0;
13029
13030 while (index < itemsLength) array[index] = items[index++];
13031
13032 while (index < arrayLength) delete array[index++];
13033
13034 return array;
13035 }
13036});
13037
13038var sort$2 = entryVirtual('Array').sort;
13039
13040var ArrayPrototype$4 = Array.prototype;
13041
13042var sort_1 = function (it) {
13043 var own = it.sort;
13044 return it === ArrayPrototype$4 || it instanceof Array && own === ArrayPrototype$4.sort ? sort$2 : own;
13045};
13046
13047var sort$1 = sort_1;
13048
13049var sort = sort$1;
13050
13051var $some = arrayIteration.some;
13052var STRICT_METHOD = arrayMethodIsStrict('some'); // `Array.prototype.some` method
13053// https://tc39.es/ecma262/#sec-array.prototype.some
13054
13055_export({
13056 target: 'Array',
13057 proto: true,
13058 forced: !STRICT_METHOD
13059}, {
13060 some: function some(callbackfn
13061 /* , thisArg */
13062 ) {
13063 return $some(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
13064 }
13065});
13066
13067var some$2 = entryVirtual('Array').some;
13068
13069var ArrayPrototype$3 = Array.prototype;
13070
13071var some_1 = function (it) {
13072 var own = it.some;
13073 return it === ArrayPrototype$3 || it instanceof Array && own === ArrayPrototype$3.some ? some$2 : own;
13074};
13075
13076var some$1 = some_1;
13077
13078var some = some$1;
13079
13080var keys$2 = entryVirtual('Array').keys;
13081
13082var keys$1 = keys$2;
13083
13084var ArrayPrototype$2 = Array.prototype;
13085var DOMIterables$2 = {
13086 DOMTokenList: true,
13087 NodeList: true
13088};
13089
13090var keys_1 = function (it) {
13091 var own = it.keys;
13092 return it === ArrayPrototype$2 || it instanceof Array && own === ArrayPrototype$2.keys // eslint-disable-next-line no-prototype-builtins -- safe
13093 || DOMIterables$2.hasOwnProperty(classof(it)) ? keys$1 : own;
13094};
13095
13096var keys = keys_1;
13097
13098var values$2 = entryVirtual('Array').values;
13099
13100var values$1 = values$2;
13101
13102var ArrayPrototype$1 = Array.prototype;
13103var DOMIterables$1 = {
13104 DOMTokenList: true,
13105 NodeList: true
13106};
13107
13108var values_1 = function (it) {
13109 var own = it.values;
13110 return it === ArrayPrototype$1 || it instanceof Array && own === ArrayPrototype$1.values // eslint-disable-next-line no-prototype-builtins -- safe
13111 || DOMIterables$1.hasOwnProperty(classof(it)) ? values$1 : own;
13112};
13113
13114var values = values_1;
13115
13116var entries$2 = entryVirtual('Array').entries;
13117
13118var entries$1 = entries$2;
13119
13120var ArrayPrototype = Array.prototype;
13121var DOMIterables = {
13122 DOMTokenList: true,
13123 NodeList: true
13124};
13125
13126var entries_1 = function (it) {
13127 var own = it.entries;
13128 return it === ArrayPrototype || it instanceof Array && own === ArrayPrototype.entries // eslint-disable-next-line no-prototype-builtins -- safe
13129 || DOMIterables.hasOwnProperty(classof(it)) ? entries$1 : own;
13130};
13131
13132var entries = entries_1;
13133
13134// Unique ID creation requires a high quality random # generator. In the browser we therefore
13135// require the crypto API and do not support built-in fallback to lower quality random number
13136// generators (like Math.random()).
13137var getRandomValues;
13138var rnds8 = new Uint8Array(16);
13139function rng() {
13140 // lazy load so that environments that need to polyfill have a chance to do so
13141 if (!getRandomValues) {
13142 // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
13143 // find the complete implementation of crypto (msCrypto) on IE11.
13144 getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
13145
13146 if (!getRandomValues) {
13147 throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
13148 }
13149 }
13150
13151 return getRandomValues(rnds8);
13152}
13153
13154var REGEX = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
13155
13156function validate(uuid) {
13157 return typeof uuid === 'string' && REGEX.test(uuid);
13158}
13159
13160/**
13161 * Convert array of 16 byte values to UUID string format of the form:
13162 * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
13163 */
13164
13165var byteToHex = [];
13166
13167for (var i = 0; i < 256; ++i) {
13168 byteToHex.push((i + 0x100).toString(16).substr(1));
13169}
13170
13171function stringify(arr) {
13172 var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; // Note: Be careful editing this code! It's been tuned for performance
13173 // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
13174
13175 var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
13176 // of the following:
13177 // - One or more input array values don't map to a hex octet (leading to
13178 // "undefined" in the uuid)
13179 // - Invalid input values for the RFC `version` or `variant` fields
13180
13181 if (!validate(uuid)) {
13182 throw TypeError('Stringified UUID is invalid');
13183 }
13184
13185 return uuid;
13186}
13187
13188function v4(options, buf, offset) {
13189 options = options || {};
13190 var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
13191
13192 rnds[6] = rnds[6] & 0x0f | 0x40;
13193 rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
13194
13195 if (buf) {
13196 offset = offset || 0;
13197
13198 for (var i = 0; i < 16; ++i) {
13199 buf[offset + i] = rnds[i];
13200 }
13201
13202 return buf;
13203 }
13204
13205 return stringify(rnds);
13206}
13207
13208function ownKeys(object, enumerableOnly) { var keys = keys$3(object); if (getOwnPropertySymbols) { var symbols = getOwnPropertySymbols(object); if (enumerableOnly) { symbols = filter(symbols).call(symbols, function (sym) { return getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
13209
13210function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context32; forEach$2(_context32 = ownKeys(Object(source), true)).call(_context32, function (key) { _defineProperty(target, key, source[key]); }); } else if (getOwnPropertyDescriptors) { defineProperties(target, getOwnPropertyDescriptors(source)); } else { var _context33; forEach$2(_context33 = ownKeys(Object(source))).call(_context33, function (key) { defineProperty$6(target, key, getOwnPropertyDescriptor(source, key)); }); } } return target; }
13211
13212function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
13213
13214function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !construct) return false; if (construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13215
13216function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof symbol !== "undefined" && getIteratorMethod(o) || o["@@iterator"]; if (!it) { if (isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
13217
13218function _unsupportedIterableToArray(o, minLen) { var _context31; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = slice$2(_context31 = Object.prototype.toString.call(o)).call(_context31, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return from_1$2(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13219
13220function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
13221/**
13222 * Create new data pipe.
13223 *
13224 * @param from - The source data set or data view.
13225 *
13226 * @remarks
13227 * Example usage:
13228 * ```typescript
13229 * interface AppItem {
13230 * whoami: string;
13231 * appData: unknown;
13232 * visData: VisItem;
13233 * }
13234 * interface VisItem {
13235 * id: number;
13236 * label: string;
13237 * color: string;
13238 * x: number;
13239 * y: number;
13240 * }
13241 *
13242 * const ds1 = new DataSet<AppItem, "whoami">([], { fieldId: "whoami" });
13243 * const ds2 = new DataSet<VisItem, "id">();
13244 *
13245 * const pipe = createNewDataPipeFrom(ds1)
13246 * .filter((item): boolean => item.enabled === true)
13247 * .map<VisItem, "id">((item): VisItem => item.visData)
13248 * .to(ds2);
13249 *
13250 * pipe.start();
13251 * ```
13252 *
13253 * @returns A factory whose methods can be used to configure the pipe.
13254 */
13255
13256function createNewDataPipeFrom(from) {
13257 return new DataPipeUnderConstruction(from);
13258}
13259/**
13260 * Internal implementation of the pipe. This should be accessible only through
13261 * `createNewDataPipeFrom` from the outside.
13262 *
13263 * @typeParam SI - Source item type.
13264 * @typeParam SP - Source item type's id property name.
13265 * @typeParam TI - Target item type.
13266 * @typeParam TP - Target item type's id property name.
13267 */
13268
13269
13270var SimpleDataPipe = /*#__PURE__*/function () {
13271 /**
13272 * Create a new data pipe.
13273 *
13274 * @param _source - The data set or data view that will be observed.
13275 * @param _transformers - An array of transforming functions to be used to
13276 * filter or transform the items in the pipe.
13277 * @param _target - The data set or data view that will receive the items.
13278 */
13279 function SimpleDataPipe(_source, _transformers, _target) {
13280 var _context, _context2, _context3;
13281
13282 _classCallCheck(this, SimpleDataPipe);
13283
13284 this._source = _source;
13285 this._transformers = _transformers;
13286 this._target = _target;
13287 /**
13288 * Bound listeners for use with `DataInterface['on' | 'off']`.
13289 */
13290
13291 this._listeners = {
13292 add: bind(_context = this._add).call(_context, this),
13293 remove: bind(_context2 = this._remove).call(_context2, this),
13294 update: bind(_context3 = this._update).call(_context3, this)
13295 };
13296 }
13297 /** @inheritDoc */
13298
13299
13300 _createClass(SimpleDataPipe, [{
13301 key: "all",
13302 value: function all() {
13303 this._target.update(this._transformItems(this._source.get()));
13304
13305 return this;
13306 }
13307 /** @inheritDoc */
13308
13309 }, {
13310 key: "start",
13311 value: function start() {
13312 this._source.on("add", this._listeners.add);
13313
13314 this._source.on("remove", this._listeners.remove);
13315
13316 this._source.on("update", this._listeners.update);
13317
13318 return this;
13319 }
13320 /** @inheritDoc */
13321
13322 }, {
13323 key: "stop",
13324 value: function stop() {
13325 this._source.off("add", this._listeners.add);
13326
13327 this._source.off("remove", this._listeners.remove);
13328
13329 this._source.off("update", this._listeners.update);
13330
13331 return this;
13332 }
13333 /**
13334 * Apply the transformers to the items.
13335 *
13336 * @param items - The items to be transformed.
13337 *
13338 * @returns The transformed items.
13339 */
13340
13341 }, {
13342 key: "_transformItems",
13343 value: function _transformItems(items) {
13344 var _context4;
13345
13346 return reduce(_context4 = this._transformers).call(_context4, function (items, transform) {
13347 return transform(items);
13348 }, items);
13349 }
13350 /**
13351 * Handle an add event.
13352 *
13353 * @param _name - Ignored.
13354 * @param payload - The payload containing the ids of the added items.
13355 */
13356
13357 }, {
13358 key: "_add",
13359 value: function _add(_name, payload) {
13360 if (payload == null) {
13361 return;
13362 }
13363
13364 this._target.add(this._transformItems(this._source.get(payload.items)));
13365 }
13366 /**
13367 * Handle an update event.
13368 *
13369 * @param _name - Ignored.
13370 * @param payload - The payload containing the ids of the updated items.
13371 */
13372
13373 }, {
13374 key: "_update",
13375 value: function _update(_name, payload) {
13376 if (payload == null) {
13377 return;
13378 }
13379
13380 this._target.update(this._transformItems(this._source.get(payload.items)));
13381 }
13382 /**
13383 * Handle a remove event.
13384 *
13385 * @param _name - Ignored.
13386 * @param payload - The payload containing the data of the removed items.
13387 */
13388
13389 }, {
13390 key: "_remove",
13391 value: function _remove(_name, payload) {
13392 if (payload == null) {
13393 return;
13394 }
13395
13396 this._target.remove(this._transformItems(payload.oldData));
13397 }
13398 }]);
13399
13400 return SimpleDataPipe;
13401}();
13402/**
13403 * Internal implementation of the pipe factory. This should be accessible
13404 * only through `createNewDataPipeFrom` from the outside.
13405 *
13406 * @typeParam TI - Target item type.
13407 * @typeParam TP - Target item type's id property name.
13408 */
13409
13410
13411var DataPipeUnderConstruction = /*#__PURE__*/function () {
13412 /**
13413 * Create a new data pipe factory. This is an internal constructor that
13414 * should never be called from outside of this file.
13415 *
13416 * @param _source - The source data set or data view for this pipe.
13417 */
13418 function DataPipeUnderConstruction(_source) {
13419 _classCallCheck(this, DataPipeUnderConstruction);
13420
13421 this._source = _source;
13422 /**
13423 * Array transformers used to transform items within the pipe. This is typed
13424 * as any for the sake of simplicity.
13425 */
13426
13427 this._transformers = [];
13428 }
13429 /**
13430 * Filter the items.
13431 *
13432 * @param callback - A filtering function that returns true if given item
13433 * should be piped and false if not.
13434 *
13435 * @returns This factory for further configuration.
13436 */
13437
13438
13439 _createClass(DataPipeUnderConstruction, [{
13440 key: "filter",
13441 value: function filter$1(callback) {
13442 this._transformers.push(function (input) {
13443 return filter(input).call(input, callback);
13444 });
13445
13446 return this;
13447 }
13448 /**
13449 * Map each source item to a new type.
13450 *
13451 * @param callback - A mapping function that takes a source item and returns
13452 * corresponding mapped item.
13453 *
13454 * @typeParam TI - Target item type.
13455 * @typeParam TP - Target item type's id property name.
13456 *
13457 * @returns This factory for further configuration.
13458 */
13459
13460 }, {
13461 key: "map",
13462 value: function map(callback) {
13463 this._transformers.push(function (input) {
13464 return map$3(input).call(input, callback);
13465 });
13466
13467 return this;
13468 }
13469 /**
13470 * Map each source item to zero or more items of a new type.
13471 *
13472 * @param callback - A mapping function that takes a source item and returns
13473 * an array of corresponding mapped items.
13474 *
13475 * @typeParam TI - Target item type.
13476 * @typeParam TP - Target item type's id property name.
13477 *
13478 * @returns This factory for further configuration.
13479 */
13480
13481 }, {
13482 key: "flatMap",
13483 value: function flatMap$1(callback) {
13484 this._transformers.push(function (input) {
13485 return flatMap(input).call(input, callback);
13486 });
13487
13488 return this;
13489 }
13490 /**
13491 * Connect this pipe to given data set.
13492 *
13493 * @param target - The data set that will receive the items from this pipe.
13494 *
13495 * @returns The pipe connected between given data sets and performing
13496 * configured transformation on the processed items.
13497 */
13498
13499 }, {
13500 key: "to",
13501 value: function to(target) {
13502 return new SimpleDataPipe(this._source, this._transformers, target);
13503 }
13504 }]);
13505
13506 return DataPipeUnderConstruction;
13507}();
13508/**
13509 * Determine whether a value can be used as an id.
13510 *
13511 * @param value - Input value of unknown type.
13512 *
13513 * @returns True if the value is valid id, false otherwise.
13514 */
13515
13516
13517function isId(value) {
13518 return typeof value === "string" || typeof value === "number";
13519}
13520/**
13521 * A queue.
13522 *
13523 * @typeParam T - The type of method names to be replaced by queued versions.
13524 */
13525
13526
13527var Queue$1 = /*#__PURE__*/function () {
13528 /**
13529 * Construct a new Queue.
13530 *
13531 * @param options - Queue configuration.
13532 */
13533 function Queue(options) {
13534 _classCallCheck(this, Queue);
13535
13536 this._queue = [];
13537 this._timeout = null;
13538 this._extended = null; // options
13539
13540 this.delay = null;
13541 this.max = Infinity;
13542 this.setOptions(options);
13543 }
13544 /**
13545 * Update the configuration of the queue.
13546 *
13547 * @param options - Queue configuration.
13548 */
13549
13550
13551 _createClass(Queue, [{
13552 key: "setOptions",
13553 value: function setOptions(options) {
13554 if (options && typeof options.delay !== "undefined") {
13555 this.delay = options.delay;
13556 }
13557
13558 if (options && typeof options.max !== "undefined") {
13559 this.max = options.max;
13560 }
13561
13562 this._flushIfNeeded();
13563 }
13564 /**
13565 * Extend an object with queuing functionality.
13566 * The object will be extended with a function flush, and the methods provided in options.replace will be replaced with queued ones.
13567 *
13568 * @param object - The object to be extended.
13569 * @param options - Additional options.
13570 *
13571 * @returns The created queue.
13572 */
13573
13574 }, {
13575 key: "destroy",
13576 value:
13577 /**
13578 * Destroy the queue. The queue will first flush all queued actions, and in case it has extended an object, will restore the original object.
13579 */
13580 function destroy() {
13581 this.flush();
13582
13583 if (this._extended) {
13584 var object = this._extended.object;
13585 var methods = this._extended.methods;
13586
13587 for (var i = 0; i < methods.length; i++) {
13588 var method = methods[i];
13589
13590 if (method.original) {
13591 // @TODO: better solution?
13592 object[method.name] = method.original;
13593 } else {
13594 // @TODO: better solution?
13595 delete object[method.name];
13596 }
13597 }
13598
13599 this._extended = null;
13600 }
13601 }
13602 /**
13603 * Replace a method on an object with a queued version.
13604 *
13605 * @param object - Object having the method.
13606 * @param method - The method name.
13607 */
13608
13609 }, {
13610 key: "replace",
13611 value: function replace(object, method) {
13612 /* eslint-disable-next-line @typescript-eslint/no-this-alias -- Function this is necessary in the function bellow, so class this has to be saved into a variable here. */
13613 var me = this;
13614 var original = object[method];
13615
13616 if (!original) {
13617 throw new Error("Method " + method + " undefined");
13618 }
13619
13620 object[method] = function () {
13621 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
13622 args[_key] = arguments[_key];
13623 }
13624
13625 // add this call to the queue
13626 me.queue({
13627 args: args,
13628 fn: original,
13629 context: this
13630 });
13631 };
13632 }
13633 /**
13634 * Queue a call.
13635 *
13636 * @param entry - The function or entry to be queued.
13637 */
13638
13639 }, {
13640 key: "queue",
13641 value: function queue(entry) {
13642 if (typeof entry === "function") {
13643 this._queue.push({
13644 fn: entry
13645 });
13646 } else {
13647 this._queue.push(entry);
13648 }
13649
13650 this._flushIfNeeded();
13651 }
13652 /**
13653 * Check whether the queue needs to be flushed.
13654 */
13655
13656 }, {
13657 key: "_flushIfNeeded",
13658 value: function _flushIfNeeded() {
13659 var _this = this;
13660
13661 // flush when the maximum is exceeded.
13662 if (this._queue.length > this.max) {
13663 this.flush();
13664 } // flush after a period of inactivity when a delay is configured
13665
13666
13667 if (this._timeout != null) {
13668 clearTimeout(this._timeout);
13669 this._timeout = null;
13670 }
13671
13672 if (this.queue.length > 0 && typeof this.delay === "number") {
13673 this._timeout = setTimeout$1(function () {
13674 _this.flush();
13675 }, this.delay);
13676 }
13677 }
13678 /**
13679 * Flush all queued calls
13680 */
13681
13682 }, {
13683 key: "flush",
13684 value: function flush() {
13685 var _context5, _context6;
13686
13687 forEach$2(_context5 = splice(_context6 = this._queue).call(_context6, 0)).call(_context5, function (entry) {
13688 entry.fn.apply(entry.context || entry.fn, entry.args || []);
13689 });
13690 }
13691 }], [{
13692 key: "extend",
13693 value: function extend(object, options) {
13694 var queue = new Queue(options);
13695
13696 if (object.flush !== undefined) {
13697 throw new Error("Target object already has a property flush");
13698 }
13699
13700 object.flush = function () {
13701 queue.flush();
13702 };
13703
13704 var methods = [{
13705 name: "flush",
13706 original: undefined
13707 }];
13708
13709 if (options && options.replace) {
13710 for (var i = 0; i < options.replace.length; i++) {
13711 var name = options.replace[i];
13712 methods.push({
13713 name: name,
13714 // @TODO: better solution?
13715 original: object[name]
13716 }); // @TODO: better solution?
13717
13718 queue.replace(object, name);
13719 }
13720 }
13721
13722 queue._extended = {
13723 object: object,
13724 methods: methods
13725 };
13726 return queue;
13727 }
13728 }]);
13729
13730 return Queue;
13731}();
13732/**
13733 * [[DataSet]] code that can be reused in [[DataView]] or other similar implementations of [[DataInterface]].
13734 *
13735 * @typeParam Item - Item type that may or may not have an id.
13736 * @typeParam IdProp - Name of the property that contains the id.
13737 */
13738
13739
13740var DataSetPart = /*#__PURE__*/function () {
13741 function DataSetPart() {
13742 _classCallCheck(this, DataSetPart);
13743
13744 this._subscribers = {
13745 "*": [],
13746 add: [],
13747 remove: [],
13748 update: []
13749 };
13750 /**
13751 * @deprecated Use on instead (PS: DataView.subscribe === DataView.on).
13752 */
13753
13754 this.subscribe = DataSetPart.prototype.on;
13755 /**
13756 * @deprecated Use off instead (PS: DataView.unsubscribe === DataView.off).
13757 */
13758
13759 this.unsubscribe = DataSetPart.prototype.off;
13760 }
13761 /**
13762 * Trigger an event
13763 *
13764 * @param event - Event name.
13765 * @param payload - Event payload.
13766 * @param senderId - Id of the sender.
13767 */
13768
13769
13770 _createClass(DataSetPart, [{
13771 key: "_trigger",
13772 value: function _trigger(event, payload, senderId) {
13773 var _context7, _context8;
13774
13775 if (event === "*") {
13776 throw new Error("Cannot trigger event *");
13777 }
13778
13779 forEach$2(_context7 = concat(_context8 = []).call(_context8, _toConsumableArray(this._subscribers[event]), _toConsumableArray(this._subscribers["*"]))).call(_context7, function (subscriber) {
13780 subscriber(event, payload, senderId != null ? senderId : null);
13781 });
13782 }
13783 /**
13784 * Subscribe to an event, add an event listener.
13785 *
13786 * @remarks Non-function callbacks are ignored.
13787 *
13788 * @param event - Event name.
13789 * @param callback - Callback method.
13790 */
13791
13792 }, {
13793 key: "on",
13794 value: function on(event, callback) {
13795 if (typeof callback === "function") {
13796 this._subscribers[event].push(callback);
13797 } // @TODO: Maybe throw for invalid callbacks?
13798
13799 }
13800 /**
13801 * Unsubscribe from an event, remove an event listener.
13802 *
13803 * @remarks If the same callback was subscribed more than once **all** occurences will be removed.
13804 *
13805 * @param event - Event name.
13806 * @param callback - Callback method.
13807 */
13808
13809 }, {
13810 key: "off",
13811 value: function off(event, callback) {
13812 var _context9;
13813
13814 this._subscribers[event] = filter(_context9 = this._subscribers[event]).call(_context9, function (subscriber) {
13815 return subscriber !== callback;
13816 });
13817 }
13818 }]);
13819
13820 return DataSetPart;
13821}();
13822/**
13823 * Data stream
13824 *
13825 * @remarks
13826 * [[DataStream]] offers an always up to date stream of items from a [[DataSet]] or [[DataView]].
13827 * That means that the stream is evaluated at the time of iteration, conversion to another data type or when [[cache]] is called, not when the [[DataStream]] was created.
13828 * Multiple invocations of for example [[toItemArray]] may yield different results (if the data source like for example [[DataSet]] gets modified).
13829 *
13830 * @typeParam Item - The item type this stream is going to work with.
13831 */
13832
13833
13834var DataStream = /*#__PURE__*/function (_Symbol$iterator) {
13835 /**
13836 * Create a new data stream.
13837 *
13838 * @param pairs - The id, item pairs.
13839 */
13840 function DataStream(pairs) {
13841 _classCallCheck(this, DataStream);
13842
13843 this._pairs = pairs;
13844 }
13845 /**
13846 * Return an iterable of key, value pairs for every entry in the stream.
13847 */
13848
13849
13850 _createClass(DataStream, [{
13851 key: _Symbol$iterator,
13852 value:
13853 /*#__PURE__*/
13854 regenerator.mark(function value() {
13855 var _iterator, _step, _step$value, id, item;
13856
13857 return regenerator.wrap(function value$(_context10) {
13858 while (1) {
13859 switch (_context10.prev = _context10.next) {
13860 case 0:
13861 _iterator = _createForOfIteratorHelper(this._pairs);
13862 _context10.prev = 1;
13863
13864 _iterator.s();
13865
13866 case 3:
13867 if ((_step = _iterator.n()).done) {
13868 _context10.next = 9;
13869 break;
13870 }
13871
13872 _step$value = _slicedToArray(_step.value, 2), id = _step$value[0], item = _step$value[1];
13873 _context10.next = 7;
13874 return [id, item];
13875
13876 case 7:
13877 _context10.next = 3;
13878 break;
13879
13880 case 9:
13881 _context10.next = 14;
13882 break;
13883
13884 case 11:
13885 _context10.prev = 11;
13886 _context10.t0 = _context10["catch"](1);
13887
13888 _iterator.e(_context10.t0);
13889
13890 case 14:
13891 _context10.prev = 14;
13892
13893 _iterator.f();
13894
13895 return _context10.finish(14);
13896
13897 case 17:
13898 case "end":
13899 return _context10.stop();
13900 }
13901 }
13902 }, value, this, [[1, 11, 14, 17]]);
13903 })
13904 /**
13905 * Return an iterable of key, value pairs for every entry in the stream.
13906 */
13907
13908 }, {
13909 key: "entries",
13910 value:
13911 /*#__PURE__*/
13912 regenerator.mark(function entries() {
13913 var _iterator2, _step2, _step2$value, id, item;
13914
13915 return regenerator.wrap(function entries$(_context11) {
13916 while (1) {
13917 switch (_context11.prev = _context11.next) {
13918 case 0:
13919 _iterator2 = _createForOfIteratorHelper(this._pairs);
13920 _context11.prev = 1;
13921
13922 _iterator2.s();
13923
13924 case 3:
13925 if ((_step2 = _iterator2.n()).done) {
13926 _context11.next = 9;
13927 break;
13928 }
13929
13930 _step2$value = _slicedToArray(_step2.value, 2), id = _step2$value[0], item = _step2$value[1];
13931 _context11.next = 7;
13932 return [id, item];
13933
13934 case 7:
13935 _context11.next = 3;
13936 break;
13937
13938 case 9:
13939 _context11.next = 14;
13940 break;
13941
13942 case 11:
13943 _context11.prev = 11;
13944 _context11.t0 = _context11["catch"](1);
13945
13946 _iterator2.e(_context11.t0);
13947
13948 case 14:
13949 _context11.prev = 14;
13950
13951 _iterator2.f();
13952
13953 return _context11.finish(14);
13954
13955 case 17:
13956 case "end":
13957 return _context11.stop();
13958 }
13959 }
13960 }, entries, this, [[1, 11, 14, 17]]);
13961 })
13962 /**
13963 * Return an iterable of keys in the stream.
13964 */
13965
13966 }, {
13967 key: "keys",
13968 value:
13969 /*#__PURE__*/
13970 regenerator.mark(function keys() {
13971 var _iterator3, _step3, _step3$value, id;
13972
13973 return regenerator.wrap(function keys$(_context12) {
13974 while (1) {
13975 switch (_context12.prev = _context12.next) {
13976 case 0:
13977 _iterator3 = _createForOfIteratorHelper(this._pairs);
13978 _context12.prev = 1;
13979
13980 _iterator3.s();
13981
13982 case 3:
13983 if ((_step3 = _iterator3.n()).done) {
13984 _context12.next = 9;
13985 break;
13986 }
13987
13988 _step3$value = _slicedToArray(_step3.value, 1), id = _step3$value[0];
13989 _context12.next = 7;
13990 return id;
13991
13992 case 7:
13993 _context12.next = 3;
13994 break;
13995
13996 case 9:
13997 _context12.next = 14;
13998 break;
13999
14000 case 11:
14001 _context12.prev = 11;
14002 _context12.t0 = _context12["catch"](1);
14003
14004 _iterator3.e(_context12.t0);
14005
14006 case 14:
14007 _context12.prev = 14;
14008
14009 _iterator3.f();
14010
14011 return _context12.finish(14);
14012
14013 case 17:
14014 case "end":
14015 return _context12.stop();
14016 }
14017 }
14018 }, keys, this, [[1, 11, 14, 17]]);
14019 })
14020 /**
14021 * Return an iterable of values in the stream.
14022 */
14023
14024 }, {
14025 key: "values",
14026 value:
14027 /*#__PURE__*/
14028 regenerator.mark(function values() {
14029 var _iterator4, _step4, _step4$value, item;
14030
14031 return regenerator.wrap(function values$(_context13) {
14032 while (1) {
14033 switch (_context13.prev = _context13.next) {
14034 case 0:
14035 _iterator4 = _createForOfIteratorHelper(this._pairs);
14036 _context13.prev = 1;
14037
14038 _iterator4.s();
14039
14040 case 3:
14041 if ((_step4 = _iterator4.n()).done) {
14042 _context13.next = 9;
14043 break;
14044 }
14045
14046 _step4$value = _slicedToArray(_step4.value, 2), item = _step4$value[1];
14047 _context13.next = 7;
14048 return item;
14049
14050 case 7:
14051 _context13.next = 3;
14052 break;
14053
14054 case 9:
14055 _context13.next = 14;
14056 break;
14057
14058 case 11:
14059 _context13.prev = 11;
14060 _context13.t0 = _context13["catch"](1);
14061
14062 _iterator4.e(_context13.t0);
14063
14064 case 14:
14065 _context13.prev = 14;
14066
14067 _iterator4.f();
14068
14069 return _context13.finish(14);
14070
14071 case 17:
14072 case "end":
14073 return _context13.stop();
14074 }
14075 }
14076 }, values, this, [[1, 11, 14, 17]]);
14077 })
14078 /**
14079 * Return an array containing all the ids in this stream.
14080 *
14081 * @remarks
14082 * The array may contain duplicities.
14083 *
14084 * @returns The array with all ids from this stream.
14085 */
14086
14087 }, {
14088 key: "toIdArray",
14089 value: function toIdArray() {
14090 var _context14;
14091
14092 return map$3(_context14 = _toConsumableArray(this._pairs)).call(_context14, function (pair) {
14093 return pair[0];
14094 });
14095 }
14096 /**
14097 * Return an array containing all the items in this stream.
14098 *
14099 * @remarks
14100 * The array may contain duplicities.
14101 *
14102 * @returns The array with all items from this stream.
14103 */
14104
14105 }, {
14106 key: "toItemArray",
14107 value: function toItemArray() {
14108 var _context15;
14109
14110 return map$3(_context15 = _toConsumableArray(this._pairs)).call(_context15, function (pair) {
14111 return pair[1];
14112 });
14113 }
14114 /**
14115 * Return an array containing all the entries in this stream.
14116 *
14117 * @remarks
14118 * The array may contain duplicities.
14119 *
14120 * @returns The array with all entries from this stream.
14121 */
14122
14123 }, {
14124 key: "toEntryArray",
14125 value: function toEntryArray() {
14126 return _toConsumableArray(this._pairs);
14127 }
14128 /**
14129 * Return an object map containing all the items in this stream accessible by ids.
14130 *
14131 * @remarks
14132 * In case of duplicate ids (coerced to string so `7 == '7'`) the last encoutered appears in the returned object.
14133 *
14134 * @returns The object map of all id → item pairs from this stream.
14135 */
14136
14137 }, {
14138 key: "toObjectMap",
14139 value: function toObjectMap() {
14140 var map = create$2(null);
14141
14142 var _iterator5 = _createForOfIteratorHelper(this._pairs),
14143 _step5;
14144
14145 try {
14146 for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
14147 var _step5$value = _slicedToArray(_step5.value, 2),
14148 id = _step5$value[0],
14149 item = _step5$value[1];
14150
14151 map[id] = item;
14152 }
14153 } catch (err) {
14154 _iterator5.e(err);
14155 } finally {
14156 _iterator5.f();
14157 }
14158
14159 return map;
14160 }
14161 /**
14162 * Return a map containing all the items in this stream accessible by ids.
14163 *
14164 * @returns The map of all id → item pairs from this stream.
14165 */
14166
14167 }, {
14168 key: "toMap",
14169 value: function toMap() {
14170 return new map(this._pairs);
14171 }
14172 /**
14173 * Return a set containing all the (unique) ids in this stream.
14174 *
14175 * @returns The set of all ids from this stream.
14176 */
14177
14178 }, {
14179 key: "toIdSet",
14180 value: function toIdSet() {
14181 return new set(this.toIdArray());
14182 }
14183 /**
14184 * Return a set containing all the (unique) items in this stream.
14185 *
14186 * @returns The set of all items from this stream.
14187 */
14188
14189 }, {
14190 key: "toItemSet",
14191 value: function toItemSet() {
14192 return new set(this.toItemArray());
14193 }
14194 /**
14195 * Cache the items from this stream.
14196 *
14197 * @remarks
14198 * This method allows for items to be fetched immediatelly and used (possibly multiple times) later.
14199 * It can also be used to optimize performance as [[DataStream]] would otherwise reevaluate everything upon each iteration.
14200 *
14201 * ## Example
14202 * ```javascript
14203 * const ds = new DataSet([…])
14204 *
14205 * const cachedStream = ds.stream()
14206 * .filter(…)
14207 * .sort(…)
14208 * .map(…)
14209 * .cached(…) // Data are fetched, processed and cached here.
14210 *
14211 * ds.clear()
14212 * chachedStream // Still has all the items.
14213 * ```
14214 *
14215 * @returns A new [[DataStream]] with cached items (detached from the original [[DataSet]]).
14216 */
14217
14218 }, {
14219 key: "cache",
14220 value: function cache() {
14221 return new DataStream(_toConsumableArray(this._pairs));
14222 }
14223 /**
14224 * Get the distinct values of given property.
14225 *
14226 * @param callback - The function that picks and possibly converts the property.
14227 *
14228 * @typeParam T - The type of the distinct value.
14229 *
14230 * @returns A set of all distinct properties.
14231 */
14232
14233 }, {
14234 key: "distinct",
14235 value: function distinct(callback) {
14236 var set$1 = new set();
14237
14238 var _iterator6 = _createForOfIteratorHelper(this._pairs),
14239 _step6;
14240
14241 try {
14242 for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
14243 var _step6$value = _slicedToArray(_step6.value, 2),
14244 id = _step6$value[0],
14245 item = _step6$value[1];
14246
14247 set$1.add(callback(item, id));
14248 }
14249 } catch (err) {
14250 _iterator6.e(err);
14251 } finally {
14252 _iterator6.f();
14253 }
14254
14255 return set$1;
14256 }
14257 /**
14258 * Filter the items of the stream.
14259 *
14260 * @param callback - The function that decides whether an item will be included.
14261 *
14262 * @returns A new data stream with the filtered items.
14263 */
14264
14265 }, {
14266 key: "filter",
14267 value: function filter(callback) {
14268 var pairs = this._pairs;
14269 return new DataStream(_defineProperty({}, iterator, /*#__PURE__*/regenerator.mark(function _callee() {
14270 var _iterator7, _step7, _step7$value, id, item;
14271
14272 return regenerator.wrap(function _callee$(_context16) {
14273 while (1) {
14274 switch (_context16.prev = _context16.next) {
14275 case 0:
14276 _iterator7 = _createForOfIteratorHelper(pairs);
14277 _context16.prev = 1;
14278
14279 _iterator7.s();
14280
14281 case 3:
14282 if ((_step7 = _iterator7.n()).done) {
14283 _context16.next = 10;
14284 break;
14285 }
14286
14287 _step7$value = _slicedToArray(_step7.value, 2), id = _step7$value[0], item = _step7$value[1];
14288
14289 if (!callback(item, id)) {
14290 _context16.next = 8;
14291 break;
14292 }
14293
14294 _context16.next = 8;
14295 return [id, item];
14296
14297 case 8:
14298 _context16.next = 3;
14299 break;
14300
14301 case 10:
14302 _context16.next = 15;
14303 break;
14304
14305 case 12:
14306 _context16.prev = 12;
14307 _context16.t0 = _context16["catch"](1);
14308
14309 _iterator7.e(_context16.t0);
14310
14311 case 15:
14312 _context16.prev = 15;
14313
14314 _iterator7.f();
14315
14316 return _context16.finish(15);
14317
14318 case 18:
14319 case "end":
14320 return _context16.stop();
14321 }
14322 }
14323 }, _callee, null, [[1, 12, 15, 18]]);
14324 })));
14325 }
14326 /**
14327 * Execute a callback for each item of the stream.
14328 *
14329 * @param callback - The function that will be invoked for each item.
14330 */
14331
14332 }, {
14333 key: "forEach",
14334 value: function forEach(callback) {
14335 var _iterator8 = _createForOfIteratorHelper(this._pairs),
14336 _step8;
14337
14338 try {
14339 for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
14340 var _step8$value = _slicedToArray(_step8.value, 2),
14341 id = _step8$value[0],
14342 item = _step8$value[1];
14343
14344 callback(item, id);
14345 }
14346 } catch (err) {
14347 _iterator8.e(err);
14348 } finally {
14349 _iterator8.f();
14350 }
14351 }
14352 /**
14353 * Map the items into a different type.
14354 *
14355 * @param callback - The function that does the conversion.
14356 *
14357 * @typeParam Mapped - The type of the item after mapping.
14358 *
14359 * @returns A new data stream with the mapped items.
14360 */
14361
14362 }, {
14363 key: "map",
14364 value: function map(callback) {
14365 var pairs = this._pairs;
14366 return new DataStream(_defineProperty({}, iterator, /*#__PURE__*/regenerator.mark(function _callee2() {
14367 var _iterator9, _step9, _step9$value, id, item;
14368
14369 return regenerator.wrap(function _callee2$(_context17) {
14370 while (1) {
14371 switch (_context17.prev = _context17.next) {
14372 case 0:
14373 _iterator9 = _createForOfIteratorHelper(pairs);
14374 _context17.prev = 1;
14375
14376 _iterator9.s();
14377
14378 case 3:
14379 if ((_step9 = _iterator9.n()).done) {
14380 _context17.next = 9;
14381 break;
14382 }
14383
14384 _step9$value = _slicedToArray(_step9.value, 2), id = _step9$value[0], item = _step9$value[1];
14385 _context17.next = 7;
14386 return [id, callback(item, id)];
14387
14388 case 7:
14389 _context17.next = 3;
14390 break;
14391
14392 case 9:
14393 _context17.next = 14;
14394 break;
14395
14396 case 11:
14397 _context17.prev = 11;
14398 _context17.t0 = _context17["catch"](1);
14399
14400 _iterator9.e(_context17.t0);
14401
14402 case 14:
14403 _context17.prev = 14;
14404
14405 _iterator9.f();
14406
14407 return _context17.finish(14);
14408
14409 case 17:
14410 case "end":
14411 return _context17.stop();
14412 }
14413 }
14414 }, _callee2, null, [[1, 11, 14, 17]]);
14415 })));
14416 }
14417 /**
14418 * Get the item with the maximum value of given property.
14419 *
14420 * @param callback - The function that picks and possibly converts the property.
14421 *
14422 * @returns The item with the maximum if found otherwise null.
14423 */
14424
14425 }, {
14426 key: "max",
14427 value: function max(callback) {
14428 var iter = getIterator(this._pairs);
14429
14430 var curr = iter.next();
14431
14432 if (curr.done) {
14433 return null;
14434 }
14435
14436 var maxItem = curr.value[1];
14437 var maxValue = callback(curr.value[1], curr.value[0]);
14438
14439 while (!(curr = iter.next()).done) {
14440 var _curr$value = _slicedToArray(curr.value, 2),
14441 id = _curr$value[0],
14442 item = _curr$value[1];
14443
14444 var _value = callback(item, id);
14445
14446 if (_value > maxValue) {
14447 maxValue = _value;
14448 maxItem = item;
14449 }
14450 }
14451
14452 return maxItem;
14453 }
14454 /**
14455 * Get the item with the minimum value of given property.
14456 *
14457 * @param callback - The function that picks and possibly converts the property.
14458 *
14459 * @returns The item with the minimum if found otherwise null.
14460 */
14461
14462 }, {
14463 key: "min",
14464 value: function min(callback) {
14465 var iter = getIterator(this._pairs);
14466
14467 var curr = iter.next();
14468
14469 if (curr.done) {
14470 return null;
14471 }
14472
14473 var minItem = curr.value[1];
14474 var minValue = callback(curr.value[1], curr.value[0]);
14475
14476 while (!(curr = iter.next()).done) {
14477 var _curr$value2 = _slicedToArray(curr.value, 2),
14478 id = _curr$value2[0],
14479 item = _curr$value2[1];
14480
14481 var _value2 = callback(item, id);
14482
14483 if (_value2 < minValue) {
14484 minValue = _value2;
14485 minItem = item;
14486 }
14487 }
14488
14489 return minItem;
14490 }
14491 /**
14492 * Reduce the items into a single value.
14493 *
14494 * @param callback - The function that does the reduction.
14495 * @param accumulator - The initial value of the accumulator.
14496 *
14497 * @typeParam T - The type of the accumulated value.
14498 *
14499 * @returns The reduced value.
14500 */
14501
14502 }, {
14503 key: "reduce",
14504 value: function reduce(callback, accumulator) {
14505 var _iterator10 = _createForOfIteratorHelper(this._pairs),
14506 _step10;
14507
14508 try {
14509 for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
14510 var _step10$value = _slicedToArray(_step10.value, 2),
14511 id = _step10$value[0],
14512 item = _step10$value[1];
14513
14514 accumulator = callback(accumulator, item, id);
14515 }
14516 } catch (err) {
14517 _iterator10.e(err);
14518 } finally {
14519 _iterator10.f();
14520 }
14521
14522 return accumulator;
14523 }
14524 /**
14525 * Sort the items.
14526 *
14527 * @param callback - Item comparator.
14528 *
14529 * @returns A new stream with sorted items.
14530 */
14531
14532 }, {
14533 key: "sort",
14534 value: function sort$1(callback) {
14535 var _this2 = this;
14536
14537 return new DataStream(_defineProperty({}, iterator, function () {
14538 var _context18;
14539
14540 return getIterator(sort(_context18 = _toConsumableArray(_this2._pairs)).call(_context18, function (_ref, _ref2) {
14541 var _ref3 = _slicedToArray(_ref, 2),
14542 idA = _ref3[0],
14543 itemA = _ref3[1];
14544
14545 var _ref4 = _slicedToArray(_ref2, 2),
14546 idB = _ref4[0],
14547 itemB = _ref4[1];
14548
14549 return callback(itemA, itemB, idA, idB);
14550 }));
14551 }));
14552 }
14553 }]);
14554
14555 return DataStream;
14556}(iterator);
14557/**
14558 * Add an id to given item if it doesn't have one already.
14559 *
14560 * @remarks
14561 * The item will be modified.
14562 *
14563 * @param item - The item that will have an id after a call to this function.
14564 * @param idProp - The key of the id property.
14565 *
14566 * @typeParam Item - Item type that may or may not have an id.
14567 * @typeParam IdProp - Name of the property that contains the id.
14568 *
14569 * @returns true
14570 */
14571
14572
14573function ensureFullItem(item, idProp) {
14574 if (item[idProp] == null) {
14575 // generate an id
14576 item[idProp] = v4();
14577 }
14578
14579 return item;
14580}
14581/**
14582 * # DataSet
14583 *
14584 * Vis.js comes with a flexible DataSet, which can be used to hold and
14585 * manipulate unstructured data and listen for changes in the data. The DataSet
14586 * is key/value based. Data items can be added, updated and removed from the
14587 * DataSet, and one can subscribe to changes in the DataSet. The data in the
14588 * DataSet can be filtered and ordered. Data can be normalized when appending it
14589 * to the DataSet as well.
14590 *
14591 * ## Example
14592 *
14593 * The following example shows how to use a DataSet.
14594 *
14595 * ```javascript
14596 * // create a DataSet
14597 * var options = {};
14598 * var data = new vis.DataSet(options);
14599 *
14600 * // add items
14601 * // note that the data items can contain different properties and data formats
14602 * data.add([
14603 * {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
14604 * {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
14605 * {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
14606 * {id: 4, text: 'item 4'}
14607 * ]);
14608 *
14609 * // subscribe to any change in the DataSet
14610 * data.on('*', function (event, properties, senderId) {
14611 * console.log('event', event, properties);
14612 * });
14613 *
14614 * // update an existing item
14615 * data.update({id: 2, group: 1});
14616 *
14617 * // remove an item
14618 * data.remove(4);
14619 *
14620 * // get all ids
14621 * var ids = data.getIds();
14622 * console.log('ids', ids);
14623 *
14624 * // get a specific item
14625 * var item1 = data.get(1);
14626 * console.log('item1', item1);
14627 *
14628 * // retrieve a filtered subset of the data
14629 * var items = data.get({
14630 * filter: function (item) {
14631 * return item.group == 1;
14632 * }
14633 * });
14634 * console.log('filtered items', items);
14635 * ```
14636 *
14637 * @typeParam Item - Item type that may or may not have an id.
14638 * @typeParam IdProp - Name of the property that contains the id.
14639 */
14640
14641
14642var DataSet$1 = /*#__PURE__*/function (_DataSetPart) {
14643 _inherits(DataSet, _DataSetPart);
14644
14645 var _super = _createSuper(DataSet);
14646
14647 /**
14648 * Construct a new DataSet.
14649 *
14650 * @param data - Initial data or options.
14651 * @param options - Options (type error if data is also options).
14652 */
14653 function DataSet(data, options) {
14654 var _this3;
14655
14656 _classCallCheck(this, DataSet);
14657
14658 _this3 = _super.call(this);
14659 _this3._queue = null; // correctly read optional arguments
14660
14661 if (data && !isArray(data)) {
14662 options = data;
14663 data = [];
14664 }
14665
14666 _this3._options = options || {};
14667 _this3._data = new map(); // map with data indexed by id
14668
14669 _this3.length = 0; // number of items in the DataSet
14670
14671 _this3._idProp = _this3._options.fieldId || "id"; // name of the field containing id
14672 // add initial data when provided
14673
14674 if (data && data.length) {
14675 _this3.add(data);
14676 }
14677
14678 _this3.setOptions(options);
14679
14680 return _this3;
14681 }
14682 /** @inheritDoc */
14683
14684
14685 _createClass(DataSet, [{
14686 key: "idProp",
14687 get: function get() {
14688 return this._idProp;
14689 }
14690 /**
14691 * Set new options.
14692 *
14693 * @param options - The new options.
14694 */
14695
14696 }, {
14697 key: "setOptions",
14698 value: function setOptions(options) {
14699 if (options && options.queue !== undefined) {
14700 if (options.queue === false) {
14701 // delete queue if loaded
14702 if (this._queue) {
14703 this._queue.destroy();
14704
14705 this._queue = null;
14706 }
14707 } else {
14708 // create queue and update its options
14709 if (!this._queue) {
14710 this._queue = Queue$1.extend(this, {
14711 replace: ["add", "update", "remove"]
14712 });
14713 }
14714
14715 if (options.queue && _typeof(options.queue) === "object") {
14716 this._queue.setOptions(options.queue);
14717 }
14718 }
14719 }
14720 }
14721 /**
14722 * Add a data item or an array with items.
14723 *
14724 * After the items are added to the DataSet, the DataSet will trigger an event `add`. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
14725 *
14726 * ## Example
14727 *
14728 * ```javascript
14729 * // create a DataSet
14730 * const data = new vis.DataSet()
14731 *
14732 * // add items
14733 * const ids = data.add([
14734 * { id: 1, text: 'item 1' },
14735 * { id: 2, text: 'item 2' },
14736 * { text: 'item without an id' }
14737 * ])
14738 *
14739 * console.log(ids) // [1, 2, '<UUIDv4>']
14740 * ```
14741 *
14742 * @param data - Items to be added (ids will be generated if missing).
14743 * @param senderId - Sender id.
14744 *
14745 * @returns addedIds - Array with the ids (generated if not present) of the added items.
14746 *
14747 * @throws When an item with the same id as any of the added items already exists.
14748 */
14749
14750 }, {
14751 key: "add",
14752 value: function add(data, senderId) {
14753 var _this4 = this;
14754
14755 var addedIds = [];
14756 var id;
14757
14758 if (isArray(data)) {
14759 // Array
14760 var idsToAdd = map$3(data).call(data, function (d) {
14761 return d[_this4._idProp];
14762 });
14763
14764 if (some(idsToAdd).call(idsToAdd, function (id) {
14765 return _this4._data.has(id);
14766 })) {
14767 throw new Error("A duplicate id was found in the parameter array.");
14768 }
14769
14770 for (var i = 0, len = data.length; i < len; i++) {
14771 id = this._addItem(data[i]);
14772 addedIds.push(id);
14773 }
14774 } else if (data && _typeof(data) === "object") {
14775 // Single item
14776 id = this._addItem(data);
14777 addedIds.push(id);
14778 } else {
14779 throw new Error("Unknown dataType");
14780 }
14781
14782 if (addedIds.length) {
14783 this._trigger("add", {
14784 items: addedIds
14785 }, senderId);
14786 }
14787
14788 return addedIds;
14789 }
14790 /**
14791 * Update existing items. When an item does not exist, it will be created.
14792 *
14793 * @remarks
14794 * The provided properties will be merged in the existing item. When an item does not exist, it will be created.
14795 *
14796 * After the items are updated, the DataSet will trigger an event `add` for the added items, and an event `update`. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
14797 *
14798 * ## Example
14799 *
14800 * ```javascript
14801 * // create a DataSet
14802 * const data = new vis.DataSet([
14803 * { id: 1, text: 'item 1' },
14804 * { id: 2, text: 'item 2' },
14805 * { id: 3, text: 'item 3' }
14806 * ])
14807 *
14808 * // update items
14809 * const ids = data.update([
14810 * { id: 2, text: 'item 2 (updated)' },
14811 * { id: 4, text: 'item 4 (new)' }
14812 * ])
14813 *
14814 * console.log(ids) // [2, 4]
14815 * ```
14816 *
14817 * ## Warning for TypeScript users
14818 * This method may introduce partial items into the data set. Use add or updateOnly instead for better type safety.
14819 *
14820 * @param data - Items to be updated (if the id is already present) or added (if the id is missing).
14821 * @param senderId - Sender id.
14822 *
14823 * @returns updatedIds - The ids of the added (these may be newly generated if there was no id in the item from the data) or updated items.
14824 *
14825 * @throws When the supplied data is neither an item nor an array of items.
14826 */
14827
14828 }, {
14829 key: "update",
14830 value: function update(data, senderId) {
14831 var _this5 = this;
14832
14833 var addedIds = [];
14834 var updatedIds = [];
14835 var oldData = [];
14836 var updatedData = [];
14837 var idProp = this._idProp;
14838
14839 var addOrUpdate = function addOrUpdate(item) {
14840 var origId = item[idProp];
14841
14842 if (origId != null && _this5._data.has(origId)) {
14843 var fullItem = item; // it has an id, therefore it is a fullitem
14844
14845 var oldItem = assign$2({}, _this5._data.get(origId)); // update item
14846
14847
14848 var id = _this5._updateItem(fullItem);
14849
14850 updatedIds.push(id);
14851 updatedData.push(fullItem);
14852 oldData.push(oldItem);
14853 } else {
14854 // add new item
14855 var _id = _this5._addItem(item);
14856
14857 addedIds.push(_id);
14858 }
14859 };
14860
14861 if (isArray(data)) {
14862 // Array
14863 for (var i = 0, len = data.length; i < len; i++) {
14864 if (data[i] && _typeof(data[i]) === "object") {
14865 addOrUpdate(data[i]);
14866 } else {
14867 console.warn("Ignoring input item, which is not an object at index " + i);
14868 }
14869 }
14870 } else if (data && _typeof(data) === "object") {
14871 // Single item
14872 addOrUpdate(data);
14873 } else {
14874 throw new Error("Unknown dataType");
14875 }
14876
14877 if (addedIds.length) {
14878 this._trigger("add", {
14879 items: addedIds
14880 }, senderId);
14881 }
14882
14883 if (updatedIds.length) {
14884 var props = {
14885 items: updatedIds,
14886 oldData: oldData,
14887 data: updatedData
14888 }; // TODO: remove deprecated property 'data' some day
14889 //Object.defineProperty(props, 'data', {
14890 // 'get': (function() {
14891 // console.warn('Property data is deprecated. Use DataSet.get(ids) to retrieve the new data, use the oldData property on this object to get the old data');
14892 // return updatedData;
14893 // }).bind(this)
14894 //});
14895
14896 this._trigger("update", props, senderId);
14897 }
14898
14899 return concat(addedIds).call(addedIds, updatedIds);
14900 }
14901 /**
14902 * Update existing items. When an item does not exist, an error will be thrown.
14903 *
14904 * @remarks
14905 * The provided properties will be deeply merged into the existing item.
14906 * When an item does not exist (id not present in the data set or absent), an error will be thrown and nothing will be changed.
14907 *
14908 * After the items are updated, the DataSet will trigger an event `update`.
14909 * When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
14910 *
14911 * ## Example
14912 *
14913 * ```javascript
14914 * // create a DataSet
14915 * const data = new vis.DataSet([
14916 * { id: 1, text: 'item 1' },
14917 * { id: 2, text: 'item 2' },
14918 * { id: 3, text: 'item 3' },
14919 * ])
14920 *
14921 * // update items
14922 * const ids = data.update([
14923 * { id: 2, text: 'item 2 (updated)' }, // works
14924 * // { id: 4, text: 'item 4 (new)' }, // would throw
14925 * // { text: 'item 4 (new)' }, // would also throw
14926 * ])
14927 *
14928 * console.log(ids) // [2]
14929 * ```
14930 *
14931 * @param data - Updates (the id and optionally other props) to the items in this data set.
14932 * @param senderId - Sender id.
14933 *
14934 * @returns updatedIds - The ids of the updated items.
14935 *
14936 * @throws When the supplied data is neither an item nor an array of items, when the ids are missing.
14937 */
14938
14939 }, {
14940 key: "updateOnly",
14941 value: function updateOnly(data, senderId) {
14942 var _context19,
14943 _this6 = this;
14944
14945 if (!isArray(data)) {
14946 data = [data];
14947 }
14948
14949 var updateEventData = map$3(_context19 = map$3(data).call(data, function (update) {
14950 var oldData = _this6._data.get(update[_this6._idProp]);
14951
14952 if (oldData == null) {
14953 throw new Error("Updating non-existent items is not allowed.");
14954 }
14955
14956 return {
14957 oldData: oldData,
14958 update: update
14959 };
14960 })).call(_context19, function (_ref5) {
14961 var oldData = _ref5.oldData,
14962 update = _ref5.update;
14963 var id = oldData[_this6._idProp];
14964 var updatedData = pureDeepObjectAssign(oldData, update);
14965
14966 _this6._data.set(id, updatedData);
14967
14968 return {
14969 id: id,
14970 oldData: oldData,
14971 updatedData: updatedData
14972 };
14973 });
14974
14975 if (updateEventData.length) {
14976 var props = {
14977 items: map$3(updateEventData).call(updateEventData, function (value) {
14978 return value.id;
14979 }),
14980 oldData: map$3(updateEventData).call(updateEventData, function (value) {
14981 return value.oldData;
14982 }),
14983 data: map$3(updateEventData).call(updateEventData, function (value) {
14984 return value.updatedData;
14985 })
14986 }; // TODO: remove deprecated property 'data' some day
14987 //Object.defineProperty(props, 'data', {
14988 // 'get': (function() {
14989 // console.warn('Property data is deprecated. Use DataSet.get(ids) to retrieve the new data, use the oldData property on this object to get the old data');
14990 // return updatedData;
14991 // }).bind(this)
14992 //});
14993
14994 this._trigger("update", props, senderId);
14995
14996 return props.items;
14997 } else {
14998 return [];
14999 }
15000 }
15001 /** @inheritDoc */
15002
15003 }, {
15004 key: "get",
15005 value: function get(first, second) {
15006 // @TODO: Woudn't it be better to split this into multiple methods?
15007 // parse the arguments
15008 var id = undefined;
15009 var ids = undefined;
15010 var options = undefined;
15011
15012 if (isId(first)) {
15013 // get(id [, options])
15014 id = first;
15015 options = second;
15016 } else if (isArray(first)) {
15017 // get(ids [, options])
15018 ids = first;
15019 options = second;
15020 } else {
15021 // get([, options])
15022 options = first;
15023 } // determine the return type
15024
15025
15026 var returnType = options && options.returnType === "Object" ? "Object" : "Array"; // @TODO: WTF is this? Or am I missing something?
15027 // var returnType
15028 // if (options && options.returnType) {
15029 // var allowedValues = ['Array', 'Object']
15030 // returnType =
15031 // allowedValues.indexOf(options.returnType) == -1
15032 // ? 'Array'
15033 // : options.returnType
15034 // } else {
15035 // returnType = 'Array'
15036 // }
15037 // build options
15038
15039 var filter$1 = options && filter(options);
15040
15041 var items = [];
15042 var item = undefined;
15043 var itemIds = undefined;
15044 var itemId = undefined; // convert items
15045
15046 if (id != null) {
15047 // return a single item
15048 item = this._data.get(id);
15049
15050 if (item && filter$1 && !filter$1(item)) {
15051 item = undefined;
15052 }
15053 } else if (ids != null) {
15054 // return a subset of items
15055 for (var i = 0, len = ids.length; i < len; i++) {
15056 item = this._data.get(ids[i]);
15057
15058 if (item != null && (!filter$1 || filter$1(item))) {
15059 items.push(item);
15060 }
15061 }
15062 } else {
15063 var _context20;
15064
15065 // return all items
15066 itemIds = _toConsumableArray(keys(_context20 = this._data).call(_context20));
15067
15068 for (var _i = 0, _len2 = itemIds.length; _i < _len2; _i++) {
15069 itemId = itemIds[_i];
15070 item = this._data.get(itemId);
15071
15072 if (item != null && (!filter$1 || filter$1(item))) {
15073 items.push(item);
15074 }
15075 }
15076 } // order the results
15077
15078
15079 if (options && options.order && id == undefined) {
15080 this._sort(items, options.order);
15081 } // filter fields of the items
15082
15083
15084 if (options && options.fields) {
15085 var fields = options.fields;
15086
15087 if (id != undefined && item != null) {
15088 item = this._filterFields(item, fields);
15089 } else {
15090 for (var _i2 = 0, _len3 = items.length; _i2 < _len3; _i2++) {
15091 items[_i2] = this._filterFields(items[_i2], fields);
15092 }
15093 }
15094 } // return the results
15095
15096
15097 if (returnType == "Object") {
15098 var result = {};
15099
15100 for (var _i3 = 0, _len4 = items.length; _i3 < _len4; _i3++) {
15101 var resultant = items[_i3]; // @TODO: Shoudn't this be this._fieldId?
15102 // result[resultant.id] = resultant
15103
15104 var _id2 = resultant[this._idProp];
15105 result[_id2] = resultant;
15106 }
15107
15108 return result;
15109 } else {
15110 if (id != null) {
15111 var _item;
15112
15113 // a single item
15114 return (_item = item) !== null && _item !== void 0 ? _item : null;
15115 } else {
15116 // just return our array
15117 return items;
15118 }
15119 }
15120 }
15121 /** @inheritDoc */
15122
15123 }, {
15124 key: "getIds",
15125 value: function getIds(options) {
15126 var data = this._data;
15127
15128 var filter$1 = options && filter(options);
15129
15130 var order = options && options.order;
15131
15132 var itemIds = _toConsumableArray(keys(data).call(data));
15133
15134 var ids = [];
15135
15136 if (filter$1) {
15137 // get filtered items
15138 if (order) {
15139 // create ordered list
15140 var items = [];
15141
15142 for (var i = 0, len = itemIds.length; i < len; i++) {
15143 var id = itemIds[i];
15144
15145 var item = this._data.get(id);
15146
15147 if (item != null && filter$1(item)) {
15148 items.push(item);
15149 }
15150 }
15151
15152 this._sort(items, order);
15153
15154 for (var _i4 = 0, _len5 = items.length; _i4 < _len5; _i4++) {
15155 ids.push(items[_i4][this._idProp]);
15156 }
15157 } else {
15158 // create unordered list
15159 for (var _i5 = 0, _len6 = itemIds.length; _i5 < _len6; _i5++) {
15160 var _id3 = itemIds[_i5];
15161
15162 var _item2 = this._data.get(_id3);
15163
15164 if (_item2 != null && filter$1(_item2)) {
15165 ids.push(_item2[this._idProp]);
15166 }
15167 }
15168 }
15169 } else {
15170 // get all items
15171 if (order) {
15172 // create an ordered list
15173 var _items = [];
15174
15175 for (var _i6 = 0, _len7 = itemIds.length; _i6 < _len7; _i6++) {
15176 var _id4 = itemIds[_i6];
15177
15178 _items.push(data.get(_id4));
15179 }
15180
15181 this._sort(_items, order);
15182
15183 for (var _i7 = 0, _len8 = _items.length; _i7 < _len8; _i7++) {
15184 ids.push(_items[_i7][this._idProp]);
15185 }
15186 } else {
15187 // create unordered list
15188 for (var _i8 = 0, _len9 = itemIds.length; _i8 < _len9; _i8++) {
15189 var _id5 = itemIds[_i8];
15190
15191 var _item3 = data.get(_id5);
15192
15193 if (_item3 != null) {
15194 ids.push(_item3[this._idProp]);
15195 }
15196 }
15197 }
15198 }
15199
15200 return ids;
15201 }
15202 /** @inheritDoc */
15203
15204 }, {
15205 key: "getDataSet",
15206 value: function getDataSet() {
15207 return this;
15208 }
15209 /** @inheritDoc */
15210
15211 }, {
15212 key: "forEach",
15213 value: function forEach(callback, options) {
15214 var filter$1 = options && filter(options);
15215
15216 var data = this._data;
15217
15218 var itemIds = _toConsumableArray(keys(data).call(data));
15219
15220 if (options && options.order) {
15221 // execute forEach on ordered list
15222 var items = this.get(options);
15223
15224 for (var i = 0, len = items.length; i < len; i++) {
15225 var item = items[i];
15226 var id = item[this._idProp];
15227 callback(item, id);
15228 }
15229 } else {
15230 // unordered
15231 for (var _i9 = 0, _len10 = itemIds.length; _i9 < _len10; _i9++) {
15232 var _id6 = itemIds[_i9];
15233
15234 var _item4 = this._data.get(_id6);
15235
15236 if (_item4 != null && (!filter$1 || filter$1(_item4))) {
15237 callback(_item4, _id6);
15238 }
15239 }
15240 }
15241 }
15242 /** @inheritDoc */
15243
15244 }, {
15245 key: "map",
15246 value: function map(callback, options) {
15247 var filter$1 = options && filter(options);
15248
15249 var mappedItems = [];
15250 var data = this._data;
15251
15252 var itemIds = _toConsumableArray(keys(data).call(data)); // convert and filter items
15253
15254
15255 for (var i = 0, len = itemIds.length; i < len; i++) {
15256 var id = itemIds[i];
15257
15258 var item = this._data.get(id);
15259
15260 if (item != null && (!filter$1 || filter$1(item))) {
15261 mappedItems.push(callback(item, id));
15262 }
15263 } // order items
15264
15265
15266 if (options && options.order) {
15267 this._sort(mappedItems, options.order);
15268 }
15269
15270 return mappedItems;
15271 }
15272 /**
15273 * Filter the fields of an item.
15274 *
15275 * @param item - The item whose fields should be filtered.
15276 * @param fields - The names of the fields that will be kept.
15277 *
15278 * @typeParam K - Field name type.
15279 *
15280 * @returns The item without any additional fields.
15281 */
15282
15283 }, {
15284 key: "_filterFields",
15285 value: function _filterFields(item, fields) {
15286 var _context21;
15287
15288 if (!item) {
15289 // item is null
15290 return item;
15291 }
15292
15293 return reduce(_context21 = isArray(fields) ? // Use the supplied array
15294 fields : // Use the keys of the supplied object
15295 keys$3(fields)).call(_context21, function (filteredItem, field) {
15296 filteredItem[field] = item[field];
15297 return filteredItem;
15298 }, {});
15299 }
15300 /**
15301 * Sort the provided array with items.
15302 *
15303 * @param items - Items to be sorted in place.
15304 * @param order - A field name or custom sort function.
15305 *
15306 * @typeParam T - The type of the items in the items array.
15307 */
15308
15309 }, {
15310 key: "_sort",
15311 value: function _sort(items, order) {
15312 if (typeof order === "string") {
15313 // order by provided field name
15314 var name = order; // field name
15315
15316 sort(items).call(items, function (a, b) {
15317 // @TODO: How to treat missing properties?
15318 var av = a[name];
15319 var bv = b[name];
15320 return av > bv ? 1 : av < bv ? -1 : 0;
15321 });
15322 } else if (typeof order === "function") {
15323 // order by sort function
15324 sort(items).call(items, order);
15325 } else {
15326 // TODO: extend order by an Object {field:string, direction:string}
15327 // where direction can be 'asc' or 'desc'
15328 throw new TypeError("Order must be a function or a string");
15329 }
15330 }
15331 /**
15332 * Remove an item or multiple items by “reference” (only the id is used) or by id.
15333 *
15334 * The method ignores removal of non-existing items, and returns an array containing the ids of the items which are actually removed from the DataSet.
15335 *
15336 * After the items are removed, the DataSet will trigger an event `remove` for the removed items. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
15337 *
15338 * ## Example
15339 * ```javascript
15340 * // create a DataSet
15341 * const data = new vis.DataSet([
15342 * { id: 1, text: 'item 1' },
15343 * { id: 2, text: 'item 2' },
15344 * { id: 3, text: 'item 3' }
15345 * ])
15346 *
15347 * // remove items
15348 * const ids = data.remove([2, { id: 3 }, 4])
15349 *
15350 * console.log(ids) // [2, 3]
15351 * ```
15352 *
15353 * @param id - One or more items or ids of items to be removed.
15354 * @param senderId - Sender id.
15355 *
15356 * @returns The ids of the removed items.
15357 */
15358
15359 }, {
15360 key: "remove",
15361 value: function remove(id, senderId) {
15362 var removedIds = [];
15363 var removedItems = []; // force everything to be an array for simplicity
15364
15365 var ids = isArray(id) ? id : [id];
15366
15367 for (var i = 0, len = ids.length; i < len; i++) {
15368 var item = this._remove(ids[i]);
15369
15370 if (item) {
15371 var itemId = item[this._idProp];
15372
15373 if (itemId != null) {
15374 removedIds.push(itemId);
15375 removedItems.push(item);
15376 }
15377 }
15378 }
15379
15380 if (removedIds.length) {
15381 this._trigger("remove", {
15382 items: removedIds,
15383 oldData: removedItems
15384 }, senderId);
15385 }
15386
15387 return removedIds;
15388 }
15389 /**
15390 * Remove an item by its id or reference.
15391 *
15392 * @param id - Id of an item or the item itself.
15393 *
15394 * @returns The removed item if removed, null otherwise.
15395 */
15396
15397 }, {
15398 key: "_remove",
15399 value: function _remove(id) {
15400 // @TODO: It origianlly returned the item although the docs say id.
15401 // The code expects the item, so probably an error in the docs.
15402 var ident; // confirm the id to use based on the args type
15403
15404 if (isId(id)) {
15405 ident = id;
15406 } else if (id && _typeof(id) === "object") {
15407 ident = id[this._idProp]; // look for the identifier field using ._idProp
15408 } // do the removing if the item is found
15409
15410
15411 if (ident != null && this._data.has(ident)) {
15412 var item = this._data.get(ident) || null;
15413
15414 this._data.delete(ident);
15415
15416 --this.length;
15417 return item;
15418 }
15419
15420 return null;
15421 }
15422 /**
15423 * Clear the entire data set.
15424 *
15425 * After the items are removed, the [[DataSet]] will trigger an event `remove` for all removed items. When a `senderId` is provided, this id will be passed with the triggered event to all subscribers.
15426 *
15427 * @param senderId - Sender id.
15428 *
15429 * @returns removedIds - The ids of all removed items.
15430 */
15431
15432 }, {
15433 key: "clear",
15434 value: function clear(senderId) {
15435 var _context22;
15436
15437 var ids = _toConsumableArray(keys(_context22 = this._data).call(_context22));
15438
15439 var items = [];
15440
15441 for (var i = 0, len = ids.length; i < len; i++) {
15442 items.push(this._data.get(ids[i]));
15443 }
15444
15445 this._data.clear();
15446
15447 this.length = 0;
15448
15449 this._trigger("remove", {
15450 items: ids,
15451 oldData: items
15452 }, senderId);
15453
15454 return ids;
15455 }
15456 /**
15457 * Find the item with maximum value of a specified field.
15458 *
15459 * @param field - Name of the property that should be searched for max value.
15460 *
15461 * @returns Item containing max value, or null if no items.
15462 */
15463
15464 }, {
15465 key: "max",
15466 value: function max(field) {
15467 var _context23;
15468
15469 var max = null;
15470 var maxField = null;
15471
15472 var _iterator11 = _createForOfIteratorHelper(values(_context23 = this._data).call(_context23)),
15473 _step11;
15474
15475 try {
15476 for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
15477 var item = _step11.value;
15478 var itemField = item[field];
15479
15480 if (typeof itemField === "number" && (maxField == null || itemField > maxField)) {
15481 max = item;
15482 maxField = itemField;
15483 }
15484 }
15485 } catch (err) {
15486 _iterator11.e(err);
15487 } finally {
15488 _iterator11.f();
15489 }
15490
15491 return max || null;
15492 }
15493 /**
15494 * Find the item with minimum value of a specified field.
15495 *
15496 * @param field - Name of the property that should be searched for min value.
15497 *
15498 * @returns Item containing min value, or null if no items.
15499 */
15500
15501 }, {
15502 key: "min",
15503 value: function min(field) {
15504 var _context24;
15505
15506 var min = null;
15507 var minField = null;
15508
15509 var _iterator12 = _createForOfIteratorHelper(values(_context24 = this._data).call(_context24)),
15510 _step12;
15511
15512 try {
15513 for (_iterator12.s(); !(_step12 = _iterator12.n()).done;) {
15514 var item = _step12.value;
15515 var itemField = item[field];
15516
15517 if (typeof itemField === "number" && (minField == null || itemField < minField)) {
15518 min = item;
15519 minField = itemField;
15520 }
15521 }
15522 } catch (err) {
15523 _iterator12.e(err);
15524 } finally {
15525 _iterator12.f();
15526 }
15527
15528 return min || null;
15529 }
15530 /**
15531 * Find all distinct values of a specified field
15532 *
15533 * @param prop - The property name whose distinct values should be returned.
15534 *
15535 * @returns Unordered array containing all distinct values. Items without specified property are ignored.
15536 */
15537
15538 }, {
15539 key: "distinct",
15540 value: function distinct(prop) {
15541 var data = this._data;
15542
15543 var itemIds = _toConsumableArray(keys(data).call(data));
15544
15545 var values = [];
15546 var count = 0;
15547
15548 for (var i = 0, len = itemIds.length; i < len; i++) {
15549 var id = itemIds[i];
15550 var item = data.get(id);
15551 var _value3 = item[prop];
15552 var exists = false;
15553
15554 for (var j = 0; j < count; j++) {
15555 if (values[j] == _value3) {
15556 exists = true;
15557 break;
15558 }
15559 }
15560
15561 if (!exists && _value3 !== undefined) {
15562 values[count] = _value3;
15563 count++;
15564 }
15565 }
15566
15567 return values;
15568 }
15569 /**
15570 * Add a single item. Will fail when an item with the same id already exists.
15571 *
15572 * @param item - A new item to be added.
15573 *
15574 * @returns Added item's id. An id is generated when it is not present in the item.
15575 */
15576
15577 }, {
15578 key: "_addItem",
15579 value: function _addItem(item) {
15580 var fullItem = ensureFullItem(item, this._idProp);
15581 var id = fullItem[this._idProp]; // check whether this id is already taken
15582
15583 if (this._data.has(id)) {
15584 // item already exists
15585 throw new Error("Cannot add item: item with id " + id + " already exists");
15586 }
15587
15588 this._data.set(id, fullItem);
15589
15590 ++this.length;
15591 return id;
15592 }
15593 /**
15594 * Update a single item: merge with existing item.
15595 * Will fail when the item has no id, or when there does not exist an item with the same id.
15596 *
15597 * @param update - The new item
15598 *
15599 * @returns The id of the updated item.
15600 */
15601
15602 }, {
15603 key: "_updateItem",
15604 value: function _updateItem(update) {
15605 var id = update[this._idProp];
15606
15607 if (id == null) {
15608 throw new Error("Cannot update item: item has no id (item: " + stringify$1(update) + ")");
15609 }
15610
15611 var item = this._data.get(id);
15612
15613 if (!item) {
15614 // item doesn't exist
15615 throw new Error("Cannot update item: no item with id " + id + " found");
15616 }
15617
15618 this._data.set(id, _objectSpread(_objectSpread({}, item), update));
15619
15620 return id;
15621 }
15622 /** @inheritDoc */
15623
15624 }, {
15625 key: "stream",
15626 value: function stream(ids) {
15627 if (ids) {
15628 var data = this._data;
15629 return new DataStream(_defineProperty({}, iterator, /*#__PURE__*/regenerator.mark(function _callee3() {
15630 var _iterator13, _step13, id, item;
15631
15632 return regenerator.wrap(function _callee3$(_context25) {
15633 while (1) {
15634 switch (_context25.prev = _context25.next) {
15635 case 0:
15636 _iterator13 = _createForOfIteratorHelper(ids);
15637 _context25.prev = 1;
15638
15639 _iterator13.s();
15640
15641 case 3:
15642 if ((_step13 = _iterator13.n()).done) {
15643 _context25.next = 11;
15644 break;
15645 }
15646
15647 id = _step13.value;
15648 item = data.get(id);
15649
15650 if (!(item != null)) {
15651 _context25.next = 9;
15652 break;
15653 }
15654
15655 _context25.next = 9;
15656 return [id, item];
15657
15658 case 9:
15659 _context25.next = 3;
15660 break;
15661
15662 case 11:
15663 _context25.next = 16;
15664 break;
15665
15666 case 13:
15667 _context25.prev = 13;
15668 _context25.t0 = _context25["catch"](1);
15669
15670 _iterator13.e(_context25.t0);
15671
15672 case 16:
15673 _context25.prev = 16;
15674
15675 _iterator13.f();
15676
15677 return _context25.finish(16);
15678
15679 case 19:
15680 case "end":
15681 return _context25.stop();
15682 }
15683 }
15684 }, _callee3, null, [[1, 13, 16, 19]]);
15685 })));
15686 } else {
15687 var _context26;
15688
15689 return new DataStream(_defineProperty({}, iterator, bind(_context26 = entries(this._data)).call(_context26, this._data)));
15690 }
15691 }
15692 }]);
15693
15694 return DataSet;
15695}(DataSetPart);
15696/**
15697 * DataView
15698 *
15699 * A DataView offers a filtered and/or formatted view on a DataSet. One can subscribe to changes in a DataView, and easily get filtered or formatted data without having to specify filters and field types all the time.
15700 *
15701 * ## Example
15702 * ```javascript
15703 * // create a DataSet
15704 * var data = new vis.DataSet();
15705 * data.add([
15706 * {id: 1, text: 'item 1', date: new Date(2013, 6, 20), group: 1, first: true},
15707 * {id: 2, text: 'item 2', date: '2013-06-23', group: 2},
15708 * {id: 3, text: 'item 3', date: '2013-06-25', group: 2},
15709 * {id: 4, text: 'item 4'}
15710 * ]);
15711 *
15712 * // create a DataView
15713 * // the view will only contain items having a property group with value 1,
15714 * // and will only output fields id, text, and date.
15715 * var view = new vis.DataView(data, {
15716 * filter: function (item) {
15717 * return (item.group == 1);
15718 * },
15719 * fields: ['id', 'text', 'date']
15720 * });
15721 *
15722 * // subscribe to any change in the DataView
15723 * view.on('*', function (event, properties, senderId) {
15724 * console.log('event', event, properties);
15725 * });
15726 *
15727 * // update an item in the data set
15728 * data.update({id: 2, group: 1});
15729 *
15730 * // get all ids in the view
15731 * var ids = view.getIds();
15732 * console.log('ids', ids); // will output [1, 2]
15733 *
15734 * // get all items in the view
15735 * var items = view.get();
15736 * ```
15737 *
15738 * @typeParam Item - Item type that may or may not have an id.
15739 * @typeParam IdProp - Name of the property that contains the id.
15740 */
15741
15742
15743var DataView$1 = /*#__PURE__*/function (_DataSetPart2) {
15744 _inherits(DataView, _DataSetPart2);
15745
15746 var _super2 = _createSuper(DataView);
15747
15748 /**
15749 * Create a DataView.
15750 *
15751 * @param data - The instance containing data (directly or indirectly).
15752 * @param options - Options to configure this data view.
15753 */
15754 function DataView(data, options) {
15755 var _context27;
15756
15757 var _this7;
15758
15759 _classCallCheck(this, DataView);
15760
15761 _this7 = _super2.call(this);
15762 /** @inheritDoc */
15763
15764 _this7.length = 0;
15765 _this7._ids = new set(); // ids of the items currently in memory (just contains a boolean true)
15766
15767 _this7._options = options || {};
15768 _this7._listener = bind(_context27 = _this7._onEvent).call(_context27, _assertThisInitialized(_this7));
15769
15770 _this7.setData(data);
15771
15772 return _this7;
15773 }
15774 /** @inheritDoc */
15775
15776
15777 _createClass(DataView, [{
15778 key: "idProp",
15779 get: function get() {
15780 return this.getDataSet().idProp;
15781 } // TODO: implement a function .config() to dynamically update things like configured filter
15782 // and trigger changes accordingly
15783
15784 /**
15785 * Set a data source for the view.
15786 *
15787 * @param data - The instance containing data (directly or indirectly).
15788 *
15789 * @remarks
15790 * Note that when the data view is bound to a data set it won't be garbage
15791 * collected unless the data set is too. Use `dataView.setData(null)` or
15792 * `dataView.dispose()` to enable garbage collection before you lose the last
15793 * reference.
15794 */
15795
15796 }, {
15797 key: "setData",
15798 value: function setData(data) {
15799 if (this._data) {
15800 // unsubscribe from current dataset
15801 if (this._data.off) {
15802 this._data.off("*", this._listener);
15803 } // trigger a remove of all items in memory
15804
15805
15806 var ids = this._data.getIds({
15807 filter: filter(this._options)
15808 });
15809
15810 var items = this._data.get(ids);
15811
15812 this._ids.clear();
15813
15814 this.length = 0;
15815
15816 this._trigger("remove", {
15817 items: ids,
15818 oldData: items
15819 });
15820 }
15821
15822 if (data != null) {
15823 this._data = data; // trigger an add of all added items
15824
15825 var _ids = this._data.getIds({
15826 filter: filter(this._options)
15827 });
15828
15829 for (var i = 0, len = _ids.length; i < len; i++) {
15830 var id = _ids[i];
15831
15832 this._ids.add(id);
15833 }
15834
15835 this.length = _ids.length;
15836
15837 this._trigger("add", {
15838 items: _ids
15839 });
15840 } else {
15841 this._data = new DataSet$1();
15842 } // subscribe to new dataset
15843
15844
15845 if (this._data.on) {
15846 this._data.on("*", this._listener);
15847 }
15848 }
15849 /**
15850 * Refresh the DataView.
15851 * Useful when the DataView has a filter function containing a variable parameter.
15852 */
15853
15854 }, {
15855 key: "refresh",
15856 value: function refresh() {
15857 var ids = this._data.getIds({
15858 filter: filter(this._options)
15859 });
15860
15861 var oldIds = _toConsumableArray(this._ids);
15862
15863 var newIds = {};
15864 var addedIds = [];
15865 var removedIds = [];
15866 var removedItems = []; // check for additions
15867
15868 for (var i = 0, len = ids.length; i < len; i++) {
15869 var id = ids[i];
15870 newIds[id] = true;
15871
15872 if (!this._ids.has(id)) {
15873 addedIds.push(id);
15874
15875 this._ids.add(id);
15876 }
15877 } // check for removals
15878
15879
15880 for (var _i10 = 0, _len11 = oldIds.length; _i10 < _len11; _i10++) {
15881 var _id7 = oldIds[_i10];
15882
15883 var item = this._data.get(_id7);
15884
15885 if (item == null) {
15886 // @TODO: Investigate.
15887 // Doesn't happen during tests or examples.
15888 // Is it really impossible or could it eventually happen?
15889 // How to handle it if it does? The types guarantee non-nullable items.
15890 console.error("If you see this, report it please.");
15891 } else if (!newIds[_id7]) {
15892 removedIds.push(_id7);
15893 removedItems.push(item);
15894
15895 this._ids.delete(_id7);
15896 }
15897 }
15898
15899 this.length += addedIds.length - removedIds.length; // trigger events
15900
15901 if (addedIds.length) {
15902 this._trigger("add", {
15903 items: addedIds
15904 });
15905 }
15906
15907 if (removedIds.length) {
15908 this._trigger("remove", {
15909 items: removedIds,
15910 oldData: removedItems
15911 });
15912 }
15913 }
15914 /** @inheritDoc */
15915
15916 }, {
15917 key: "get",
15918 value: function get(first, second) {
15919 if (this._data == null) {
15920 return null;
15921 } // parse the arguments
15922
15923
15924 var ids = null;
15925 var options;
15926
15927 if (isId(first) || isArray(first)) {
15928 ids = first;
15929 options = second;
15930 } else {
15931 options = first;
15932 } // extend the options with the default options and provided options
15933
15934
15935 var viewOptions = assign$2({}, this._options, options); // create a combined filter method when needed
15936
15937
15938 var thisFilter = filter(this._options);
15939
15940 var optionsFilter = options && filter(options);
15941
15942 if (thisFilter && optionsFilter) {
15943 viewOptions.filter = function (item) {
15944 return thisFilter(item) && optionsFilter(item);
15945 };
15946 }
15947
15948 if (ids == null) {
15949 return this._data.get(viewOptions);
15950 } else {
15951 return this._data.get(ids, viewOptions);
15952 }
15953 }
15954 /** @inheritDoc */
15955
15956 }, {
15957 key: "getIds",
15958 value: function getIds(options) {
15959 if (this._data.length) {
15960 var defaultFilter = filter(this._options);
15961
15962 var optionsFilter = options != null ? filter(options) : null;
15963 var filter$1;
15964
15965 if (optionsFilter) {
15966 if (defaultFilter) {
15967 filter$1 = function filter(item) {
15968 return defaultFilter(item) && optionsFilter(item);
15969 };
15970 } else {
15971 filter$1 = optionsFilter;
15972 }
15973 } else {
15974 filter$1 = defaultFilter;
15975 }
15976
15977 return this._data.getIds({
15978 filter: filter$1,
15979 order: options && options.order
15980 });
15981 } else {
15982 return [];
15983 }
15984 }
15985 /** @inheritDoc */
15986
15987 }, {
15988 key: "forEach",
15989 value: function forEach(callback, options) {
15990 if (this._data) {
15991 var _context28;
15992
15993 var defaultFilter = filter(this._options);
15994
15995 var optionsFilter = options && filter(options);
15996
15997 var filter$1;
15998
15999 if (optionsFilter) {
16000 if (defaultFilter) {
16001 filter$1 = function filter(item) {
16002 return defaultFilter(item) && optionsFilter(item);
16003 };
16004 } else {
16005 filter$1 = optionsFilter;
16006 }
16007 } else {
16008 filter$1 = defaultFilter;
16009 }
16010
16011 forEach$2(_context28 = this._data).call(_context28, callback, {
16012 filter: filter$1,
16013 order: options && options.order
16014 });
16015 }
16016 }
16017 /** @inheritDoc */
16018
16019 }, {
16020 key: "map",
16021 value: function map(callback, options) {
16022 if (this._data) {
16023 var _context29;
16024
16025 var defaultFilter = filter(this._options);
16026
16027 var optionsFilter = options && filter(options);
16028
16029 var filter$1;
16030
16031 if (optionsFilter) {
16032 if (defaultFilter) {
16033 filter$1 = function filter(item) {
16034 return defaultFilter(item) && optionsFilter(item);
16035 };
16036 } else {
16037 filter$1 = optionsFilter;
16038 }
16039 } else {
16040 filter$1 = defaultFilter;
16041 }
16042
16043 return map$3(_context29 = this._data).call(_context29, callback, {
16044 filter: filter$1,
16045 order: options && options.order
16046 });
16047 } else {
16048 return [];
16049 }
16050 }
16051 /** @inheritDoc */
16052
16053 }, {
16054 key: "getDataSet",
16055 value: function getDataSet() {
16056 return this._data.getDataSet();
16057 }
16058 /** @inheritDoc */
16059
16060 }, {
16061 key: "stream",
16062 value: function stream(ids) {
16063 var _context30;
16064
16065 return this._data.stream(ids || _defineProperty({}, iterator, bind(_context30 = keys(this._ids)).call(_context30, this._ids)));
16066 }
16067 /**
16068 * Render the instance unusable prior to garbage collection.
16069 *
16070 * @remarks
16071 * The intention of this method is to help discover scenarios where the data
16072 * view is being used when the programmer thinks it has been garbage collected
16073 * already. It's stricter version of `dataView.setData(null)`.
16074 */
16075
16076 }, {
16077 key: "dispose",
16078 value: function dispose() {
16079 var _this$_data;
16080
16081 if ((_this$_data = this._data) !== null && _this$_data !== void 0 && _this$_data.off) {
16082 this._data.off("*", this._listener);
16083 }
16084
16085 var message = "This data view has already been disposed of.";
16086 var replacement = {
16087 get: function get() {
16088 throw new Error(message);
16089 },
16090 set: function set() {
16091 throw new Error(message);
16092 },
16093 configurable: false
16094 };
16095
16096 var _iterator14 = _createForOfIteratorHelper(ownKeys$2(DataView.prototype)),
16097 _step14;
16098
16099 try {
16100 for (_iterator14.s(); !(_step14 = _iterator14.n()).done;) {
16101 var key = _step14.value;
16102
16103 defineProperty$6(this, key, replacement);
16104 }
16105 } catch (err) {
16106 _iterator14.e(err);
16107 } finally {
16108 _iterator14.f();
16109 }
16110 }
16111 /**
16112 * Event listener. Will propagate all events from the connected data set to the subscribers of the DataView, but will filter the items and only trigger when there are changes in the filtered data set.
16113 *
16114 * @param event - The name of the event.
16115 * @param params - Parameters of the event.
16116 * @param senderId - Id supplied by the sender.
16117 */
16118
16119 }, {
16120 key: "_onEvent",
16121 value: function _onEvent(event, params, senderId) {
16122 if (!params || !params.items || !this._data) {
16123 return;
16124 }
16125
16126 var ids = params.items;
16127 var addedIds = [];
16128 var updatedIds = [];
16129 var removedIds = [];
16130 var oldItems = [];
16131 var updatedItems = [];
16132 var removedItems = [];
16133
16134 switch (event) {
16135 case "add":
16136 // filter the ids of the added items
16137 for (var i = 0, len = ids.length; i < len; i++) {
16138 var id = ids[i];
16139 var item = this.get(id);
16140
16141 if (item) {
16142 this._ids.add(id);
16143
16144 addedIds.push(id);
16145 }
16146 }
16147
16148 break;
16149
16150 case "update":
16151 // determine the event from the views viewpoint: an updated
16152 // item can be added, updated, or removed from this view.
16153 for (var _i11 = 0, _len12 = ids.length; _i11 < _len12; _i11++) {
16154 var _id8 = ids[_i11];
16155
16156 var _item5 = this.get(_id8);
16157
16158 if (_item5) {
16159 if (this._ids.has(_id8)) {
16160 updatedIds.push(_id8);
16161 updatedItems.push(params.data[_i11]);
16162 oldItems.push(params.oldData[_i11]);
16163 } else {
16164 this._ids.add(_id8);
16165
16166 addedIds.push(_id8);
16167 }
16168 } else {
16169 if (this._ids.has(_id8)) {
16170 this._ids.delete(_id8);
16171
16172 removedIds.push(_id8);
16173 removedItems.push(params.oldData[_i11]);
16174 }
16175 }
16176 }
16177
16178 break;
16179
16180 case "remove":
16181 // filter the ids of the removed items
16182 for (var _i12 = 0, _len13 = ids.length; _i12 < _len13; _i12++) {
16183 var _id9 = ids[_i12];
16184
16185 if (this._ids.has(_id9)) {
16186 this._ids.delete(_id9);
16187
16188 removedIds.push(_id9);
16189 removedItems.push(params.oldData[_i12]);
16190 }
16191 }
16192
16193 break;
16194 }
16195
16196 this.length += addedIds.length - removedIds.length;
16197
16198 if (addedIds.length) {
16199 this._trigger("add", {
16200 items: addedIds
16201 }, senderId);
16202 }
16203
16204 if (updatedIds.length) {
16205 this._trigger("update", {
16206 items: updatedIds,
16207 oldData: oldItems,
16208 data: updatedItems
16209 }, senderId);
16210 }
16211
16212 if (removedIds.length) {
16213 this._trigger("remove", {
16214 items: removedIds,
16215 oldData: removedItems
16216 }, senderId);
16217 }
16218 }
16219 }]);
16220
16221 return DataView;
16222}(DataSetPart);
16223/**
16224 * Check that given value is compatible with Vis Data Set interface.
16225 *
16226 * @param idProp - The expected property to contain item id.
16227 * @param v - The value to be tested.
16228 *
16229 * @returns True if all expected values and methods match, false otherwise.
16230 */
16231
16232
16233function isDataSetLike(idProp, v) {
16234 return _typeof(v) === "object" && v !== null && idProp === v.idProp && typeof v.add === "function" && typeof v.clear === "function" && typeof v.distinct === "function" && typeof forEach$2(v) === "function" && typeof v.get === "function" && typeof v.getDataSet === "function" && typeof v.getIds === "function" && typeof v.length === "number" && typeof map$3(v) === "function" && typeof v.max === "function" && typeof v.min === "function" && typeof v.off === "function" && typeof v.on === "function" && typeof v.remove === "function" && typeof v.setOptions === "function" && typeof v.stream === "function" && typeof v.update === "function" && typeof v.updateOnly === "function";
16235}
16236/**
16237 * Check that given value is compatible with Vis Data View interface.
16238 *
16239 * @param idProp - The expected property to contain item id.
16240 * @param v - The value to be tested.
16241 *
16242 * @returns True if all expected values and methods match, false otherwise.
16243 */
16244
16245
16246function isDataViewLike(idProp, v) {
16247 return _typeof(v) === "object" && v !== null && idProp === v.idProp && typeof forEach$2(v) === "function" && typeof v.get === "function" && typeof v.getDataSet === "function" && typeof v.getIds === "function" && typeof v.length === "number" && typeof map$3(v) === "function" && typeof v.off === "function" && typeof v.on === "function" && typeof v.stream === "function" && isDataSetLike(idProp, v.getDataSet());
16248}
16249
16250var esnext = /*#__PURE__*/Object.freeze({
16251 __proto__: null,
16252 DELETE: DELETE,
16253 DataSet: DataSet$1,
16254 DataStream: DataStream,
16255 DataView: DataView$1,
16256 Queue: Queue$1,
16257 createNewDataPipeFrom: createNewDataPipeFrom,
16258 isDataSetLike: isDataSetLike,
16259 isDataViewLike: isDataViewLike
16260});
16261
16262var trim = stringTrim.trim;
16263var $parseFloat = global_1.parseFloat;
16264var FORCED = 1 / $parseFloat(whitespaces + '-0') !== -Infinity; // `parseFloat` method
16265// https://tc39.es/ecma262/#sec-parsefloat-string
16266
16267var numberParseFloat = FORCED ? function parseFloat(string) {
16268 var trimmedString = trim(toString_1(string));
16269 var result = $parseFloat(trimmedString);
16270 return result === 0 && trimmedString.charAt(0) == '-' ? -0 : result;
16271} : $parseFloat;
16272
16273// https://tc39.es/ecma262/#sec-parsefloat-string
16274
16275_export({
16276 global: true,
16277 forced: parseFloat != numberParseFloat
16278}, {
16279 parseFloat: numberParseFloat
16280});
16281
16282var _parseFloat$2 = path.parseFloat;
16283
16284var _parseFloat$1 = _parseFloat$2;
16285
16286var _parseFloat = _parseFloat$1;
16287
16288// https://tc39.es/ecma262/#sec-number.isnan
16289
16290_export({
16291 target: 'Number',
16292 stat: true
16293}, {
16294 isNaN: function isNaN(number) {
16295 // eslint-disable-next-line no-self-compare -- NaN check
16296 return number != number;
16297 }
16298});
16299
16300var isNan$2 = path.Number.isNaN;
16301
16302var isNan$1 = isNan$2;
16303
16304var isNan = isNan$1;
16305
16306/**
16307 * @prototype Point3d
16308 * @param {number} [x]
16309 * @param {number} [y]
16310 * @param {number} [z]
16311 */
16312function Point3d(x, y, z) {
16313 this.x = x !== undefined ? x : 0;
16314 this.y = y !== undefined ? y : 0;
16315 this.z = z !== undefined ? z : 0;
16316}
16317/**
16318 * Subtract the two provided points, returns a-b
16319 * @param {Point3d} a
16320 * @param {Point3d} b
16321 * @return {Point3d} a-b
16322 */
16323
16324
16325Point3d.subtract = function (a, b) {
16326 var sub = new Point3d();
16327 sub.x = a.x - b.x;
16328 sub.y = a.y - b.y;
16329 sub.z = a.z - b.z;
16330 return sub;
16331};
16332/**
16333 * Add the two provided points, returns a+b
16334 * @param {Point3d} a
16335 * @param {Point3d} b
16336 * @return {Point3d} a+b
16337 */
16338
16339
16340Point3d.add = function (a, b) {
16341 var sum = new Point3d();
16342 sum.x = a.x + b.x;
16343 sum.y = a.y + b.y;
16344 sum.z = a.z + b.z;
16345 return sum;
16346};
16347/**
16348 * Calculate the average of two 3d points
16349 * @param {Point3d} a
16350 * @param {Point3d} b
16351 * @return {Point3d} The average, (a+b)/2
16352 */
16353
16354
16355Point3d.avg = function (a, b) {
16356 return new Point3d((a.x + b.x) / 2, (a.y + b.y) / 2, (a.z + b.z) / 2);
16357};
16358/**
16359 * Scale the provided point by a scalar, returns p*c
16360 * @param {Point3d} p
16361 * @param {number} c
16362 * @return {Point3d} p*c
16363 */
16364
16365
16366Point3d.scalarProduct = function (p, c) {
16367 return new Point3d(p.x * c, p.y * c, p.z * c);
16368};
16369/**
16370 * Calculate the dot product of the two provided points, returns a.b
16371 * Documentation: http://en.wikipedia.org/wiki/Dot_product
16372 * @param {Point3d} a
16373 * @param {Point3d} b
16374 * @return {Point3d} dot product a.b
16375 */
16376
16377
16378Point3d.dotProduct = function (a, b) {
16379 return a.x * b.x + a.y * b.y + a.z * b.z;
16380};
16381/**
16382 * Calculate the cross product of the two provided points, returns axb
16383 * Documentation: http://en.wikipedia.org/wiki/Cross_product
16384 * @param {Point3d} a
16385 * @param {Point3d} b
16386 * @return {Point3d} cross product axb
16387 */
16388
16389
16390Point3d.crossProduct = function (a, b) {
16391 var crossproduct = new Point3d();
16392 crossproduct.x = a.y * b.z - a.z * b.y;
16393 crossproduct.y = a.z * b.x - a.x * b.z;
16394 crossproduct.z = a.x * b.y - a.y * b.x;
16395 return crossproduct;
16396};
16397/**
16398 * Retrieve the length of the vector (or the distance from this point to the origin
16399 * @return {number} length
16400 */
16401
16402
16403Point3d.prototype.length = function () {
16404 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
16405};
16406/**
16407 * Return a normalized vector pointing in the same direction.
16408 * @return {Point3d} normalized
16409 */
16410
16411
16412Point3d.prototype.normalize = function () {
16413 return Point3d.scalarProduct(this, 1 / this.length());
16414};
16415
16416var Point3d_1 = Point3d;
16417
16418/**
16419 * @prototype Point2d
16420 * @param {number} [x]
16421 * @param {number} [y]
16422 */
16423function Point2d(x, y) {
16424 this.x = x !== undefined ? x : 0;
16425 this.y = y !== undefined ? y : 0;
16426}
16427
16428var Point2d_1 = Point2d;
16429
16430/**
16431 * An html slider control with start/stop/prev/next buttons
16432 *
16433 * @constructor Slider
16434 * @param {Element} container The element where the slider will be created
16435 * @param {Object} options Available options:
16436 * {boolean} visible If true (default) the
16437 * slider is visible.
16438 */
16439
16440function Slider(container, options) {
16441 if (container === undefined) {
16442 throw new Error('No container element defined');
16443 }
16444
16445 this.container = container;
16446 this.visible = options && options.visible != undefined ? options.visible : true;
16447
16448 if (this.visible) {
16449 this.frame = document.createElement('DIV'); //this.frame.style.backgroundColor = '#E5E5E5';
16450
16451 this.frame.style.width = '100%';
16452 this.frame.style.position = 'relative';
16453 this.container.appendChild(this.frame);
16454 this.frame.prev = document.createElement('INPUT');
16455 this.frame.prev.type = 'BUTTON';
16456 this.frame.prev.value = 'Prev';
16457 this.frame.appendChild(this.frame.prev);
16458 this.frame.play = document.createElement('INPUT');
16459 this.frame.play.type = 'BUTTON';
16460 this.frame.play.value = 'Play';
16461 this.frame.appendChild(this.frame.play);
16462 this.frame.next = document.createElement('INPUT');
16463 this.frame.next.type = 'BUTTON';
16464 this.frame.next.value = 'Next';
16465 this.frame.appendChild(this.frame.next);
16466 this.frame.bar = document.createElement('INPUT');
16467 this.frame.bar.type = 'BUTTON';
16468 this.frame.bar.style.position = 'absolute';
16469 this.frame.bar.style.border = '1px solid red';
16470 this.frame.bar.style.width = '100px';
16471 this.frame.bar.style.height = '6px';
16472 this.frame.bar.style.borderRadius = '2px';
16473 this.frame.bar.style.MozBorderRadius = '2px';
16474 this.frame.bar.style.border = '1px solid #7F7F7F';
16475 this.frame.bar.style.backgroundColor = '#E5E5E5';
16476 this.frame.appendChild(this.frame.bar);
16477 this.frame.slide = document.createElement('INPUT');
16478 this.frame.slide.type = 'BUTTON';
16479 this.frame.slide.style.margin = '0px';
16480 this.frame.slide.value = ' ';
16481 this.frame.slide.style.position = 'relative';
16482 this.frame.slide.style.left = '-100px';
16483 this.frame.appendChild(this.frame.slide); // create events
16484
16485 var me = this;
16486
16487 this.frame.slide.onmousedown = function (event) {
16488 me._onMouseDown(event);
16489 };
16490
16491 this.frame.prev.onclick = function (event) {
16492 me.prev(event);
16493 };
16494
16495 this.frame.play.onclick = function (event) {
16496 me.togglePlay(event);
16497 };
16498
16499 this.frame.next.onclick = function (event) {
16500 me.next(event);
16501 };
16502 }
16503
16504 this.onChangeCallback = undefined;
16505 this.values = [];
16506 this.index = undefined;
16507 this.playTimeout = undefined;
16508 this.playInterval = 1000; // milliseconds
16509
16510 this.playLoop = true;
16511}
16512/**
16513 * Select the previous index
16514 */
16515
16516
16517Slider.prototype.prev = function () {
16518 var index = this.getIndex();
16519
16520 if (index > 0) {
16521 index--;
16522 this.setIndex(index);
16523 }
16524};
16525/**
16526 * Select the next index
16527 */
16528
16529
16530Slider.prototype.next = function () {
16531 var index = this.getIndex();
16532
16533 if (index < values(this).length - 1) {
16534 index++;
16535 this.setIndex(index);
16536 }
16537};
16538/**
16539 * Select the next index
16540 */
16541
16542
16543Slider.prototype.playNext = function () {
16544 var start = new Date();
16545 var index = this.getIndex();
16546
16547 if (index < values(this).length - 1) {
16548 index++;
16549 this.setIndex(index);
16550 } else if (this.playLoop) {
16551 // jump to the start
16552 index = 0;
16553 this.setIndex(index);
16554 }
16555
16556 var end = new Date();
16557 var diff = end - start; // calculate how much time it to to set the index and to execute the callback
16558 // function.
16559
16560 var interval = Math.max(this.playInterval - diff, 0); // document.title = diff // TODO: cleanup
16561
16562 var me = this;
16563 this.playTimeout = setTimeout$1(function () {
16564 me.playNext();
16565 }, interval);
16566};
16567/**
16568 * Toggle start or stop playing
16569 */
16570
16571
16572Slider.prototype.togglePlay = function () {
16573 if (this.playTimeout === undefined) {
16574 this.play();
16575 } else {
16576 this.stop();
16577 }
16578};
16579/**
16580 * Start playing
16581 */
16582
16583
16584Slider.prototype.play = function () {
16585 // Test whether already playing
16586 if (this.playTimeout) return;
16587 this.playNext();
16588
16589 if (this.frame) {
16590 this.frame.play.value = 'Stop';
16591 }
16592};
16593/**
16594 * Stop playing
16595 */
16596
16597
16598Slider.prototype.stop = function () {
16599 clearInterval(this.playTimeout);
16600 this.playTimeout = undefined;
16601
16602 if (this.frame) {
16603 this.frame.play.value = 'Play';
16604 }
16605};
16606/**
16607 * Set a callback function which will be triggered when the value of the
16608 * slider bar has changed.
16609 *
16610 * @param {function} callback
16611 */
16612
16613
16614Slider.prototype.setOnChangeCallback = function (callback) {
16615 this.onChangeCallback = callback;
16616};
16617/**
16618 * Set the interval for playing the list
16619 * @param {number} interval The interval in milliseconds
16620 */
16621
16622
16623Slider.prototype.setPlayInterval = function (interval) {
16624 this.playInterval = interval;
16625};
16626/**
16627 * Retrieve the current play interval
16628 * @return {number} interval The interval in milliseconds
16629 */
16630
16631
16632Slider.prototype.getPlayInterval = function () {
16633 return this.playInterval;
16634};
16635/**
16636 * Set looping on or off
16637 * @param {boolean} doLoop If true, the slider will jump to the start when
16638 * the end is passed, and will jump to the end
16639 * when the start is passed.
16640 *
16641 */
16642
16643
16644Slider.prototype.setPlayLoop = function (doLoop) {
16645 this.playLoop = doLoop;
16646};
16647/**
16648 * Execute the onchange callback function
16649 */
16650
16651
16652Slider.prototype.onChange = function () {
16653 if (this.onChangeCallback !== undefined) {
16654 this.onChangeCallback();
16655 }
16656};
16657/**
16658 * redraw the slider on the correct place
16659 */
16660
16661
16662Slider.prototype.redraw = function () {
16663 if (this.frame) {
16664 // resize the bar
16665 this.frame.bar.style.top = this.frame.clientHeight / 2 - this.frame.bar.offsetHeight / 2 + 'px';
16666 this.frame.bar.style.width = this.frame.clientWidth - this.frame.prev.clientWidth - this.frame.play.clientWidth - this.frame.next.clientWidth - 30 + 'px'; // position the slider button
16667
16668 var left = this.indexToLeft(this.index);
16669 this.frame.slide.style.left = left + 'px';
16670 }
16671};
16672/**
16673 * Set the list with values for the slider
16674 * @param {Array} values A javascript array with values (any type)
16675 */
16676
16677
16678Slider.prototype.setValues = function (values$1) {
16679 this.values = values$1;
16680 if (values(this).length > 0) this.setIndex(0);else this.index = undefined;
16681};
16682/**
16683 * Select a value by its index
16684 * @param {number} index
16685 */
16686
16687
16688Slider.prototype.setIndex = function (index) {
16689 if (index < values(this).length) {
16690 this.index = index;
16691 this.redraw();
16692 this.onChange();
16693 } else {
16694 throw new Error('Index out of range');
16695 }
16696};
16697/**
16698 * retrieve the index of the currently selected vaue
16699 * @return {number} index
16700 */
16701
16702
16703Slider.prototype.getIndex = function () {
16704 return this.index;
16705};
16706/**
16707 * retrieve the currently selected value
16708 * @return {*} value
16709 */
16710
16711
16712Slider.prototype.get = function () {
16713 return values(this)[this.index];
16714};
16715
16716Slider.prototype._onMouseDown = function (event) {
16717 // only react on left mouse button down
16718 var leftButtonDown = event.which ? event.which === 1 : event.button === 1;
16719 if (!leftButtonDown) return;
16720 this.startClientX = event.clientX;
16721 this.startSlideX = _parseFloat(this.frame.slide.style.left);
16722 this.frame.style.cursor = 'move'; // add event listeners to handle moving the contents
16723 // we store the function onmousemove and onmouseup in the graph, so we can
16724 // remove the eventlisteners lateron in the function mouseUp()
16725
16726 var me = this;
16727
16728 this.onmousemove = function (event) {
16729 me._onMouseMove(event);
16730 };
16731
16732 this.onmouseup = function (event) {
16733 me._onMouseUp(event);
16734 };
16735
16736 addEventListener(document, 'mousemove', this.onmousemove);
16737 addEventListener(document, 'mouseup', this.onmouseup);
16738 preventDefault(event);
16739};
16740
16741Slider.prototype.leftToIndex = function (left) {
16742 var width = _parseFloat(this.frame.bar.style.width) - this.frame.slide.clientWidth - 10;
16743 var x = left - 3;
16744 var index = Math.round(x / width * (values(this).length - 1));
16745 if (index < 0) index = 0;
16746 if (index > values(this).length - 1) index = values(this).length - 1;
16747 return index;
16748};
16749
16750Slider.prototype.indexToLeft = function (index) {
16751 var width = _parseFloat(this.frame.bar.style.width) - this.frame.slide.clientWidth - 10;
16752 var x = index / (values(this).length - 1) * width;
16753 var left = x + 3;
16754 return left;
16755};
16756
16757Slider.prototype._onMouseMove = function (event) {
16758 var diff = event.clientX - this.startClientX;
16759 var x = this.startSlideX + diff;
16760 var index = this.leftToIndex(x);
16761 this.setIndex(index);
16762 preventDefault();
16763};
16764
16765Slider.prototype._onMouseUp = function (event) {
16766 // eslint-disable-line no-unused-vars
16767 this.frame.style.cursor = 'auto'; // remove event listeners
16768
16769 removeEventListener(document, 'mousemove', this.onmousemove);
16770 removeEventListener(document, 'mouseup', this.onmouseup);
16771 preventDefault();
16772};
16773
16774/**
16775 * @prototype StepNumber
16776 * The class StepNumber is an iterator for Numbers. You provide a start and end
16777 * value, and a best step size. StepNumber itself rounds to fixed values and
16778 * a finds the step that best fits the provided step.
16779 *
16780 * If prettyStep is true, the step size is chosen as close as possible to the
16781 * provided step, but being a round value like 1, 2, 5, 10, 20, 50, ....
16782 *
16783 * Example usage:
16784 * var step = new StepNumber(0, 10, 2.5, true);
16785 * step.start();
16786 * while (!step.end()) {
16787 * alert(step.getCurrent());
16788 * step.next();
16789 * }
16790 *
16791 * Version: 1.0
16792 *
16793 * @param {number} start The start value
16794 * @param {number} end The end value
16795 * @param {number} step Optional. Step size. Must be a positive value.
16796 * @param {boolean} prettyStep Optional. If true, the step size is rounded
16797 * To a pretty step size (like 1, 2, 5, 10, 20, 50, ...)
16798 */
16799function StepNumber(start, end, step, prettyStep) {
16800 // set default values
16801 this._start = 0;
16802 this._end = 0;
16803 this._step = 1;
16804 this.prettyStep = true;
16805 this.precision = 5;
16806 this._current = 0;
16807 this.setRange(start, end, step, prettyStep);
16808}
16809/**
16810 * Check for input values, to prevent disasters from happening
16811 *
16812 * Source: http://stackoverflow.com/a/1830844
16813 *
16814 * @param {string} n
16815 * @returns {boolean}
16816 */
16817
16818
16819StepNumber.prototype.isNumeric = function (n) {
16820 return !isNaN(_parseFloat(n)) && isFinite(n);
16821};
16822/**
16823 * Set a new range: start, end and step.
16824 *
16825 * @param {number} start The start value
16826 * @param {number} end The end value
16827 * @param {number} step Optional. Step size. Must be a positive value.
16828 * @param {boolean} prettyStep Optional. If true, the step size is rounded
16829 * To a pretty step size (like 1, 2, 5, 10, 20, 50, ...)
16830 */
16831
16832
16833StepNumber.prototype.setRange = function (start, end, step, prettyStep) {
16834 if (!this.isNumeric(start)) {
16835 throw new Error('Parameter \'start\' is not numeric; value: ' + start);
16836 }
16837
16838 if (!this.isNumeric(end)) {
16839 throw new Error('Parameter \'end\' is not numeric; value: ' + start);
16840 }
16841
16842 if (!this.isNumeric(step)) {
16843 throw new Error('Parameter \'step\' is not numeric; value: ' + start);
16844 }
16845
16846 this._start = start ? start : 0;
16847 this._end = end ? end : 0;
16848 this.setStep(step, prettyStep);
16849};
16850/**
16851 * Set a new step size
16852 * @param {number} step New step size. Must be a positive value
16853 * @param {boolean} prettyStep Optional. If true, the provided step is rounded
16854 * to a pretty step size (like 1, 2, 5, 10, 20, 50, ...)
16855 */
16856
16857
16858StepNumber.prototype.setStep = function (step, prettyStep) {
16859 if (step === undefined || step <= 0) return;
16860 if (prettyStep !== undefined) this.prettyStep = prettyStep;
16861 if (this.prettyStep === true) this._step = StepNumber.calculatePrettyStep(step);else this._step = step;
16862};
16863/**
16864 * Calculate a nice step size, closest to the desired step size.
16865 * Returns a value in one of the ranges 1*10^n, 2*10^n, or 5*10^n, where n is an
16866 * integer Number. For example 1, 2, 5, 10, 20, 50, etc...
16867 * @param {number} step Desired step size
16868 * @return {number} Nice step size
16869 */
16870
16871
16872StepNumber.calculatePrettyStep = function (step) {
16873 var log10 = function log10(x) {
16874 return Math.log(x) / Math.LN10;
16875 }; // try three steps (multiple of 1, 2, or 5
16876
16877
16878 var step1 = Math.pow(10, Math.round(log10(step))),
16879 step2 = 2 * Math.pow(10, Math.round(log10(step / 2))),
16880 step5 = 5 * Math.pow(10, Math.round(log10(step / 5))); // choose the best step (closest to minimum step)
16881
16882 var prettyStep = step1;
16883 if (Math.abs(step2 - step) <= Math.abs(prettyStep - step)) prettyStep = step2;
16884 if (Math.abs(step5 - step) <= Math.abs(prettyStep - step)) prettyStep = step5; // for safety
16885
16886 if (prettyStep <= 0) {
16887 prettyStep = 1;
16888 }
16889
16890 return prettyStep;
16891};
16892/**
16893 * returns the current value of the step
16894 * @return {number} current value
16895 */
16896
16897
16898StepNumber.prototype.getCurrent = function () {
16899 return _parseFloat(this._current.toPrecision(this.precision));
16900};
16901/**
16902 * returns the current step size
16903 * @return {number} current step size
16904 */
16905
16906
16907StepNumber.prototype.getStep = function () {
16908 return this._step;
16909};
16910/**
16911 * Set the current to its starting value.
16912 *
16913 * By default, this will be the largest value smaller than start, which
16914 * is a multiple of the step size.
16915 *
16916 * Parameters checkFirst is optional, default false.
16917 * If set to true, move the current value one step if smaller than start.
16918 *
16919 * @param {boolean} [checkFirst=false]
16920 */
16921
16922
16923StepNumber.prototype.start = function (checkFirst) {
16924 if (checkFirst === undefined) {
16925 checkFirst = false;
16926 }
16927
16928 this._current = this._start - this._start % this._step;
16929
16930 if (checkFirst) {
16931 if (this.getCurrent() < this._start) {
16932 this.next();
16933 }
16934 }
16935};
16936/**
16937 * Do a step, add the step size to the current value
16938 */
16939
16940
16941StepNumber.prototype.next = function () {
16942 this._current += this._step;
16943};
16944/**
16945 * Returns true whether the end is reached
16946 * @return {boolean} True if the current value has passed the end value.
16947 */
16948
16949
16950StepNumber.prototype.end = function () {
16951 return this._current > this._end;
16952};
16953
16954var StepNumber_1 = StepNumber;
16955
16956// `Math.sign` method implementation
16957// https://tc39.es/ecma262/#sec-math.sign
16958// eslint-disable-next-line es/no-math-sign -- safe
16959var mathSign = Math.sign || function sign(x) {
16960 // eslint-disable-next-line no-self-compare -- NaN check
16961 return (x = +x) == 0 || x != x ? x : x < 0 ? -1 : 1;
16962};
16963
16964// https://tc39.es/ecma262/#sec-math.sign
16965
16966_export({
16967 target: 'Math',
16968 stat: true
16969}, {
16970 sign: mathSign
16971});
16972
16973var sign$2 = path.Math.sign;
16974
16975var sign$1 = sign$2;
16976
16977var sign = sign$1;
16978
16979/**
16980 * The camera is mounted on a (virtual) camera arm. The camera arm can rotate
16981 * The camera is always looking in the direction of the origin of the arm.
16982 * This way, the camera always rotates around one fixed point, the location
16983 * of the camera arm.
16984 *
16985 * Documentation:
16986 * http://en.wikipedia.org/wiki/3D_projection
16987 * @class Camera
16988 */
16989
16990function Camera() {
16991 this.armLocation = new Point3d_1();
16992 this.armRotation = {};
16993 this.armRotation.horizontal = 0;
16994 this.armRotation.vertical = 0;
16995 this.armLength = 1.7;
16996 this.cameraOffset = new Point3d_1();
16997 this.offsetMultiplier = 0.6;
16998 this.cameraLocation = new Point3d_1();
16999 this.cameraRotation = new Point3d_1(0.5 * Math.PI, 0, 0);
17000 this.calculateCameraOrientation();
17001}
17002/**
17003 * Set offset camera in camera coordinates
17004 * @param {number} x offset by camera horisontal
17005 * @param {number} y offset by camera vertical
17006 */
17007
17008
17009Camera.prototype.setOffset = function (x, y) {
17010 var abs = Math.abs,
17011 sign$1 = sign,
17012 mul = this.offsetMultiplier,
17013 border = this.armLength * mul;
17014
17015 if (abs(x) > border) {
17016 x = sign$1(x) * border;
17017 }
17018
17019 if (abs(y) > border) {
17020 y = sign$1(y) * border;
17021 }
17022
17023 this.cameraOffset.x = x;
17024 this.cameraOffset.y = y;
17025 this.calculateCameraOrientation();
17026};
17027/**
17028 * Get camera offset by horizontal and vertical
17029 * @returns {number}
17030 */
17031
17032
17033Camera.prototype.getOffset = function () {
17034 return this.cameraOffset;
17035};
17036/**
17037 * Set the location (origin) of the arm
17038 * @param {number} x Normalized value of x
17039 * @param {number} y Normalized value of y
17040 * @param {number} z Normalized value of z
17041 */
17042
17043
17044Camera.prototype.setArmLocation = function (x, y, z) {
17045 this.armLocation.x = x;
17046 this.armLocation.y = y;
17047 this.armLocation.z = z;
17048 this.calculateCameraOrientation();
17049};
17050/**
17051 * Set the rotation of the camera arm
17052 * @param {number} horizontal The horizontal rotation, between 0 and 2*PI.
17053 * Optional, can be left undefined.
17054 * @param {number} vertical The vertical rotation, between 0 and 0.5*PI
17055 * if vertical=0.5*PI, the graph is shown from the
17056 * top. Optional, can be left undefined.
17057 */
17058
17059
17060Camera.prototype.setArmRotation = function (horizontal, vertical) {
17061 if (horizontal !== undefined) {
17062 this.armRotation.horizontal = horizontal;
17063 }
17064
17065 if (vertical !== undefined) {
17066 this.armRotation.vertical = vertical;
17067 if (this.armRotation.vertical < 0) this.armRotation.vertical = 0;
17068 if (this.armRotation.vertical > 0.5 * Math.PI) this.armRotation.vertical = 0.5 * Math.PI;
17069 }
17070
17071 if (horizontal !== undefined || vertical !== undefined) {
17072 this.calculateCameraOrientation();
17073 }
17074};
17075/**
17076 * Retrieve the current arm rotation
17077 * @return {object} An object with parameters horizontal and vertical
17078 */
17079
17080
17081Camera.prototype.getArmRotation = function () {
17082 var rot = {};
17083 rot.horizontal = this.armRotation.horizontal;
17084 rot.vertical = this.armRotation.vertical;
17085 return rot;
17086};
17087/**
17088 * Set the (normalized) length of the camera arm.
17089 * @param {number} length A length between 0.71 and 5.0
17090 */
17091
17092
17093Camera.prototype.setArmLength = function (length) {
17094 if (length === undefined) return;
17095 this.armLength = length; // Radius must be larger than the corner of the graph,
17096 // which has a distance of sqrt(0.5^2+0.5^2) = 0.71 from the center of the
17097 // graph
17098
17099 if (this.armLength < 0.71) this.armLength = 0.71;
17100 if (this.armLength > 5.0) this.armLength = 5.0;
17101 this.setOffset(this.cameraOffset.x, this.cameraOffset.y);
17102 this.calculateCameraOrientation();
17103};
17104/**
17105 * Retrieve the arm length
17106 * @return {number} length
17107 */
17108
17109
17110Camera.prototype.getArmLength = function () {
17111 return this.armLength;
17112};
17113/**
17114 * Retrieve the camera location
17115 * @return {Point3d} cameraLocation
17116 */
17117
17118
17119Camera.prototype.getCameraLocation = function () {
17120 return this.cameraLocation;
17121};
17122/**
17123 * Retrieve the camera rotation
17124 * @return {Point3d} cameraRotation
17125 */
17126
17127
17128Camera.prototype.getCameraRotation = function () {
17129 return this.cameraRotation;
17130};
17131/**
17132 * Calculate the location and rotation of the camera based on the
17133 * position and orientation of the camera arm
17134 */
17135
17136
17137Camera.prototype.calculateCameraOrientation = function () {
17138 // calculate location of the camera
17139 this.cameraLocation.x = this.armLocation.x - this.armLength * Math.sin(this.armRotation.horizontal) * Math.cos(this.armRotation.vertical);
17140 this.cameraLocation.y = this.armLocation.y - this.armLength * Math.cos(this.armRotation.horizontal) * Math.cos(this.armRotation.vertical);
17141 this.cameraLocation.z = this.armLocation.z + this.armLength * Math.sin(this.armRotation.vertical); // calculate rotation of the camera
17142
17143 this.cameraRotation.x = Math.PI / 2 - this.armRotation.vertical;
17144 this.cameraRotation.y = 0;
17145 this.cameraRotation.z = -this.armRotation.horizontal;
17146 var xa = this.cameraRotation.x;
17147 var za = this.cameraRotation.z;
17148 var dx = this.cameraOffset.x;
17149 var dy = this.cameraOffset.y;
17150 var sin = Math.sin,
17151 cos = Math.cos;
17152 this.cameraLocation.x = this.cameraLocation.x + dx * cos(za) + dy * -sin(za) * cos(xa);
17153 this.cameraLocation.y = this.cameraLocation.y + dx * sin(za) + dy * cos(za) * cos(xa);
17154 this.cameraLocation.z = this.cameraLocation.z + dy * sin(xa);
17155};
17156
17157var STYLE = {
17158 BAR: 0,
17159 BARCOLOR: 1,
17160 BARSIZE: 2,
17161 DOT: 3,
17162 DOTLINE: 4,
17163 DOTCOLOR: 5,
17164 DOTSIZE: 6,
17165 GRID: 7,
17166 LINE: 8,
17167 SURFACE: 9
17168}; // The string representations of the styles
17169
17170var STYLENAME = {
17171 'dot': STYLE.DOT,
17172 'dot-line': STYLE.DOTLINE,
17173 'dot-color': STYLE.DOTCOLOR,
17174 'dot-size': STYLE.DOTSIZE,
17175 'line': STYLE.LINE,
17176 'grid': STYLE.GRID,
17177 'surface': STYLE.SURFACE,
17178 'bar': STYLE.BAR,
17179 'bar-color': STYLE.BARCOLOR,
17180 'bar-size': STYLE.BARSIZE
17181};
17182/**
17183 * Field names in the options hash which are of relevance to the user.
17184 *
17185 * Specifically, these are the fields which require no special handling,
17186 * and can be directly copied over.
17187 */
17188
17189var OPTIONKEYS = ['width', 'height', 'filterLabel', 'legendLabel', 'xLabel', 'yLabel', 'zLabel', 'xValueLabel', 'yValueLabel', 'zValueLabel', 'showXAxis', 'showYAxis', 'showZAxis', 'showGrayBottom', 'showGrid', 'showPerspective', 'showShadow', 'showSurfaceGrid', 'keepAspectRatio', 'rotateAxisLabels', 'verticalRatio', 'dotSizeRatio', 'dotSizeMinFraction', 'dotSizeMaxFraction', 'showAnimationControls', 'animationInterval', 'animationPreload', 'animationAutoStart', 'axisColor', 'axisFontSize', 'axisFontType', 'gridColor', 'xCenter', 'yCenter', 'zoomable', 'tooltipDelay', 'ctrlToZoom'];
17190/**
17191 * Field names in the options hash which are of relevance to the user.
17192 *
17193 * Same as OPTIONKEYS, but internally these fields are stored with
17194 * prefix 'default' in the name.
17195 */
17196
17197var PREFIXEDOPTIONKEYS = ['xBarWidth', 'yBarWidth', 'valueMin', 'valueMax', 'xMin', 'xMax', 'xStep', 'yMin', 'yMax', 'yStep', 'zMin', 'zMax', 'zStep']; // Placeholder for DEFAULTS reference
17198
17199var DEFAULTS = undefined;
17200/**
17201 * Check if given hash is empty.
17202 *
17203 * Source: http://stackoverflow.com/a/679937
17204 *
17205 * @param {object} obj
17206 * @returns {boolean}
17207 */
17208
17209function isEmpty(obj) {
17210 for (var prop in obj) {
17211 if (obj.hasOwnProperty(prop)) return false;
17212 }
17213
17214 return true;
17215}
17216/**
17217 * Make first letter of parameter upper case.
17218 *
17219 * Source: http://stackoverflow.com/a/1026087
17220 *
17221 * @param {string} str
17222 * @returns {string}
17223 */
17224
17225
17226function capitalize(str) {
17227 if (str === undefined || str === "" || typeof str != "string") {
17228 return str;
17229 }
17230
17231 return str.charAt(0).toUpperCase() + slice$2(str).call(str, 1);
17232}
17233/**
17234 * Add a prefix to a field name, taking style guide into account
17235 *
17236 * @param {string} prefix
17237 * @param {string} fieldName
17238 * @returns {string}
17239 */
17240
17241
17242function prefixFieldName(prefix, fieldName) {
17243 if (prefix === undefined || prefix === "") {
17244 return fieldName;
17245 }
17246
17247 return prefix + capitalize(fieldName);
17248}
17249/**
17250 * Forcibly copy fields from src to dst in a controlled manner.
17251 *
17252 * A given field in dst will always be overwitten. If this field
17253 * is undefined or not present in src, the field in dst will
17254 * be explicitly set to undefined.
17255 *
17256 * The intention here is to be able to reset all option fields.
17257 *
17258 * Only the fields mentioned in array 'fields' will be handled.
17259 *
17260 * @param {object} src
17261 * @param {object} dst
17262 * @param {array<string>} fields array with names of fields to copy
17263 * @param {string} [prefix] prefix to use for the target fields.
17264 */
17265
17266
17267function forceCopy(src, dst, fields, prefix) {
17268 var srcKey;
17269 var dstKey;
17270
17271 for (var i = 0; i < fields.length; ++i) {
17272 srcKey = fields[i];
17273 dstKey = prefixFieldName(prefix, srcKey);
17274 dst[dstKey] = src[srcKey];
17275 }
17276}
17277/**
17278 * Copy fields from src to dst in a safe and controlled manner.
17279 *
17280 * Only the fields mentioned in array 'fields' will be copied over,
17281 * and only if these are actually defined.
17282 *
17283 * @param {object} src
17284 * @param {object} dst
17285 * @param {array<string>} fields array with names of fields to copy
17286 * @param {string} [prefix] prefix to use for the target fields.
17287 */
17288
17289
17290function safeCopy(src, dst, fields, prefix) {
17291 var srcKey;
17292 var dstKey;
17293
17294 for (var i = 0; i < fields.length; ++i) {
17295 srcKey = fields[i];
17296 if (src[srcKey] === undefined) continue;
17297 dstKey = prefixFieldName(prefix, srcKey);
17298 dst[dstKey] = src[srcKey];
17299 }
17300}
17301/**
17302 * Initialize dst with the values in src.
17303 *
17304 * src is the hash with the default values.
17305 * A reference DEFAULTS to this hash is stored locally for
17306 * further handling.
17307 *
17308 * For now, dst is assumed to be a Graph3d instance.
17309 * @param {object} src
17310 * @param {object} dst
17311 */
17312
17313
17314function setDefaults(src, dst) {
17315 if (src === undefined || isEmpty(src)) {
17316 throw new Error('No DEFAULTS passed');
17317 }
17318
17319 if (dst === undefined) {
17320 throw new Error('No dst passed');
17321 } // Remember defaults for future reference
17322
17323
17324 DEFAULTS = src; // Handle the defaults which can be simply copied over
17325
17326 forceCopy(src, dst, OPTIONKEYS);
17327 forceCopy(src, dst, PREFIXEDOPTIONKEYS, 'default'); // Handle the more complex ('special') fields
17328
17329 setSpecialSettings(src, dst); // Following are internal fields, not part of the user settings
17330
17331 dst.margin = 10; // px
17332
17333 dst.showTooltip = false;
17334 dst.onclick_callback = null;
17335 dst.eye = new Point3d_1(0, 0, -1); // TODO: set eye.z about 3/4 of the width of the window?
17336}
17337/**
17338 *
17339 * @param {object} options
17340 * @param {object} dst
17341 */
17342
17343
17344function setOptions(options, dst) {
17345 if (options === undefined) {
17346 return;
17347 }
17348
17349 if (dst === undefined) {
17350 throw new Error('No dst passed');
17351 }
17352
17353 if (DEFAULTS === undefined || isEmpty(DEFAULTS)) {
17354 throw new Error('DEFAULTS not set for module Settings');
17355 } // Handle the parameters which can be simply copied over
17356
17357
17358 safeCopy(options, dst, OPTIONKEYS);
17359 safeCopy(options, dst, PREFIXEDOPTIONKEYS, 'default'); // Handle the more complex ('special') fields
17360
17361 setSpecialSettings(options, dst);
17362}
17363/**
17364 * Special handling for certain parameters
17365 *
17366 * 'Special' here means: setting requires more than a simple copy
17367 *
17368 * @param {object} src
17369 * @param {object} dst
17370 */
17371
17372
17373function setSpecialSettings(src, dst) {
17374 if (src.backgroundColor !== undefined) {
17375 setBackgroundColor(src.backgroundColor, dst);
17376 }
17377
17378 setDataColor(src.dataColor, dst);
17379 setStyle(src.style, dst);
17380
17381 if (src.surfaceColors !== undefined) {
17382 console.warn('`options.surfaceColors` is deprecated and may be removed in a future ' + 'version. Please use `options.colormap` instead. Note that the `colormap` ' + 'option uses the inverse array ordering (running from vMin to vMax).');
17383
17384 if (src.colormap !== undefined) {
17385 throw new Error('The `colormap` and `surfaceColors` options are mutually exclusive.');
17386 }
17387
17388 if (dst.style !== 'surface') {
17389 console.warn('Ignoring `surfaceColors` in graph style `' + dst.style + '` for ' + 'backward compatibility (only effective in `surface` plots).');
17390 } else {
17391 setSurfaceColor(src.surfaceColors, dst);
17392 }
17393 } else {
17394 setColormap(src.colormap, dst);
17395 }
17396
17397 setShowLegend(src.showLegend, dst);
17398 setCameraPosition(src.cameraPosition, dst); // As special fields go, this is an easy one; just a translation of the name.
17399 // Can't use this.tooltip directly, because that field exists internally
17400
17401 if (src.tooltip !== undefined) {
17402 dst.showTooltip = src.tooltip;
17403 }
17404
17405 if (src.onclick != undefined) {
17406 dst.onclick_callback = src.onclick;
17407 console.warn("`options.onclick` is deprecated and may be removed in a future version." + " Please use `Graph3d.on('click', handler)` instead.");
17408 }
17409
17410 if (src.tooltipStyle !== undefined) {
17411 selectiveDeepExtend(['tooltipStyle'], dst, src);
17412 }
17413}
17414/**
17415 * Set the value of setting 'showLegend'
17416 *
17417 * This depends on the value of the style fields, so it must be called
17418 * after the style field has been initialized.
17419 *
17420 * @param {boolean} showLegend
17421 * @param {object} dst
17422 */
17423
17424
17425function setShowLegend(showLegend, dst) {
17426 if (showLegend === undefined) {
17427 // If the default was auto, make a choice for this field
17428 var isAutoByDefault = DEFAULTS.showLegend === undefined;
17429
17430 if (isAutoByDefault) {
17431 // these styles default to having legends
17432 var isLegendGraphStyle = dst.style === STYLE.DOTCOLOR || dst.style === STYLE.DOTSIZE;
17433 dst.showLegend = isLegendGraphStyle;
17434 }
17435 } else {
17436 dst.showLegend = showLegend;
17437 }
17438}
17439/**
17440 * Retrieve the style index from given styleName
17441 * @param {string} styleName Style name such as 'dot', 'grid', 'dot-line'
17442 * @return {number} styleNumber Enumeration value representing the style, or -1
17443 * when not found
17444 */
17445
17446
17447function getStyleNumberByName(styleName) {
17448 var number = STYLENAME[styleName];
17449
17450 if (number === undefined) {
17451 return -1;
17452 }
17453
17454 return number;
17455}
17456/**
17457 * Check if given number is a valid style number.
17458 *
17459 * @param {string | number} style
17460 * @return {boolean} true if valid, false otherwise
17461 */
17462
17463
17464function checkStyleNumber(style) {
17465 var valid = false;
17466
17467 for (var n in STYLE) {
17468 if (STYLE[n] === style) {
17469 valid = true;
17470 break;
17471 }
17472 }
17473
17474 return valid;
17475}
17476/**
17477 *
17478 * @param {string | number} style
17479 * @param {Object} dst
17480 */
17481
17482
17483function setStyle(style, dst) {
17484 if (style === undefined) {
17485 return; // Nothing to do
17486 }
17487
17488 var styleNumber;
17489
17490 if (typeof style === 'string') {
17491 styleNumber = getStyleNumberByName(style);
17492
17493 if (styleNumber === -1) {
17494 throw new Error('Style \'' + style + '\' is invalid');
17495 }
17496 } else {
17497 // Do a pedantic check on style number value
17498 if (!checkStyleNumber(style)) {
17499 throw new Error('Style \'' + style + '\' is invalid');
17500 }
17501
17502 styleNumber = style;
17503 }
17504
17505 dst.style = styleNumber;
17506}
17507/**
17508 * Set the background styling for the graph
17509 * @param {string | {fill: string, stroke: string, strokeWidth: string}} backgroundColor
17510 * @param {Object} dst
17511 */
17512
17513
17514function setBackgroundColor(backgroundColor, dst) {
17515 var fill$1 = 'white';
17516 var stroke = 'gray';
17517 var strokeWidth = 1;
17518
17519 if (typeof backgroundColor === 'string') {
17520 fill$1 = backgroundColor;
17521 stroke = 'none';
17522 strokeWidth = 0;
17523 } else if (_typeof(backgroundColor) === 'object') {
17524 if (fill(backgroundColor) !== undefined) fill$1 = fill(backgroundColor);
17525 if (backgroundColor.stroke !== undefined) stroke = backgroundColor.stroke;
17526 if (backgroundColor.strokeWidth !== undefined) strokeWidth = backgroundColor.strokeWidth;
17527 } else {
17528 throw new Error('Unsupported type of backgroundColor');
17529 }
17530
17531 dst.frame.style.backgroundColor = fill$1;
17532 dst.frame.style.borderColor = stroke;
17533 dst.frame.style.borderWidth = strokeWidth + 'px';
17534 dst.frame.style.borderStyle = 'solid';
17535}
17536/**
17537 *
17538 * @param {string | Object} dataColor
17539 * @param {Object} dst
17540 */
17541
17542
17543function setDataColor(dataColor, dst) {
17544 if (dataColor === undefined) {
17545 return; // Nothing to do
17546 }
17547
17548 if (dst.dataColor === undefined) {
17549 dst.dataColor = {};
17550 }
17551
17552 if (typeof dataColor === 'string') {
17553 dst.dataColor.fill = dataColor;
17554 dst.dataColor.stroke = dataColor;
17555 } else {
17556 if (fill(dataColor)) {
17557 dst.dataColor.fill = fill(dataColor);
17558 }
17559
17560 if (dataColor.stroke) {
17561 dst.dataColor.stroke = dataColor.stroke;
17562 }
17563
17564 if (dataColor.strokeWidth !== undefined) {
17565 dst.dataColor.strokeWidth = dataColor.strokeWidth;
17566 }
17567 }
17568}
17569/**
17570 *
17571 * @param {Object | Array<string>} surfaceColors Either an object that describes the HUE, or an array of HTML hex color codes
17572 * @param {Object} dst
17573 */
17574
17575
17576function setSurfaceColor(surfaceColors, dst) {
17577 if (surfaceColors === undefined || surfaceColors === true) {
17578 return; // Nothing to do
17579 }
17580
17581 if (surfaceColors === false) {
17582 dst.surfaceColors = undefined;
17583 return;
17584 }
17585
17586 if (dst.surfaceColors === undefined) {
17587 dst.surfaceColors = {};
17588 }
17589
17590 var rgbColors;
17591
17592 if (isArray(surfaceColors)) {
17593 rgbColors = parseColorArray(surfaceColors);
17594 } else if (_typeof(surfaceColors) === 'object') {
17595 rgbColors = parseColorObject(surfaceColors.hue);
17596 } else {
17597 throw new Error('Unsupported type of surfaceColors');
17598 } // for some reason surfaceColors goes from vMax to vMin:
17599
17600
17601 reverse(rgbColors).call(rgbColors);
17602
17603 dst.colormap = rgbColors;
17604}
17605/**
17606 *
17607 * @param {Object | Array<string>} colormap Either an object that describes the HUE, or an array of HTML hex color codes
17608 * @param {Object} dst
17609 */
17610
17611
17612function setColormap(colormap, dst) {
17613 if (colormap === undefined) {
17614 return;
17615 }
17616
17617 var rgbColors;
17618
17619 if (isArray(colormap)) {
17620 rgbColors = parseColorArray(colormap);
17621 } else if (_typeof(colormap) === 'object') {
17622 rgbColors = parseColorObject(colormap.hue);
17623 } else if (typeof colormap === 'function') {
17624 rgbColors = colormap;
17625 } else {
17626 throw new Error('Unsupported type of colormap');
17627 }
17628
17629 dst.colormap = rgbColors;
17630}
17631/**
17632 *
17633 * @param {Array} colormap
17634 */
17635
17636
17637function parseColorArray(colormap) {
17638 if (colormap.length < 2) {
17639 throw new Error('Colormap array length must be 2 or above.');
17640 }
17641
17642 return map$3(colormap).call(colormap, function (colorCode) {
17643 if (!isValidHex(colorCode)) {
17644 throw new Error("Invalid hex color code supplied to colormap.");
17645 }
17646
17647 return hexToRGB(colorCode);
17648 });
17649}
17650/**
17651 * Converts an object to a certain amount of hex color stops. At which point:
17652 * the HTML hex color codes is converted into an RGB color object.
17653 *
17654 * @param {Object} hues
17655 */
17656
17657
17658function parseColorObject(hues) {
17659 if (hues === undefined) {
17660 throw new Error('Unsupported type of colormap');
17661 }
17662
17663 if (!(hues.saturation >= 0 && hues.saturation <= 100)) {
17664 throw new Error('Saturation is out of bounds. Expected range is 0-100.');
17665 }
17666
17667 if (!(hues.brightness >= 0 && hues.brightness <= 100)) {
17668 throw new Error('Brightness is out of bounds. Expected range is 0-100.');
17669 }
17670
17671 if (!(hues.colorStops >= 2)) {
17672 throw new Error('colorStops is out of bounds. Expected 2 or above.');
17673 }
17674
17675 var hueStep = (hues.end - hues.start) / (hues.colorStops - 1);
17676 var rgbColors = [];
17677
17678 for (var i = 0; i < hues.colorStops; ++i) {
17679 var hue = (hues.start + hueStep * i) % 360 / 360;
17680 rgbColors.push(HSVToRGB(hue < 0 ? hue + 1 : hue, hues.saturation / 100, hues.brightness / 100));
17681 }
17682
17683 return rgbColors;
17684}
17685/**
17686 *
17687 * @param {Object} cameraPosition
17688 * @param {Object} dst
17689 */
17690
17691
17692function setCameraPosition(cameraPosition, dst) {
17693 var camPos = cameraPosition;
17694
17695 if (camPos === undefined) {
17696 return;
17697 }
17698
17699 if (dst.camera === undefined) {
17700 dst.camera = new Camera();
17701 }
17702
17703 dst.camera.setArmRotation(camPos.horizontal, camPos.vertical);
17704 dst.camera.setArmLength(camPos.distance);
17705}
17706
17707/**
17708 * This object contains all possible options. It will check if the types are correct, if required if the option is one
17709 * of the allowed values.
17710 *
17711 * __any__ means that the name of the property does not matter.
17712 * __type__ is a required field for all objects and contains the allowed types of all objects
17713 */
17714var string = 'string';
17715var bool = 'boolean';
17716var number = 'number';
17717var object = 'object'; // should only be in a __type__ property
17718
17719var array = 'array'; // Following not used here, but useful for reference
17720//let dom = 'dom';
17721//let any = 'any';
17722
17723var colorOptions = {
17724 fill: {
17725 string: string
17726 },
17727 stroke: {
17728 string: string
17729 },
17730 strokeWidth: {
17731 number: number
17732 },
17733 __type__: {
17734 string: string,
17735 object: object,
17736 'undefined': 'undefined'
17737 }
17738};
17739var surfaceColorsOptions = {
17740 hue: {
17741 start: {
17742 number: number
17743 },
17744 end: {
17745 number: number
17746 },
17747 saturation: {
17748 number: number
17749 },
17750 brightness: {
17751 number: number
17752 },
17753 colorStops: {
17754 number: number
17755 },
17756 __type__: {
17757 object: object
17758 }
17759 },
17760 __type__: {
17761 boolean: bool,
17762 array: array,
17763 object: object,
17764 'undefined': 'undefined'
17765 }
17766};
17767var colormapOptions = {
17768 hue: {
17769 start: {
17770 number: number
17771 },
17772 end: {
17773 number: number
17774 },
17775 saturation: {
17776 number: number
17777 },
17778 brightness: {
17779 number: number
17780 },
17781 colorStops: {
17782 number: number
17783 },
17784 __type__: {
17785 object: object
17786 }
17787 },
17788 __type__: {
17789 array: array,
17790 object: object,
17791 'function': 'function',
17792 'undefined': 'undefined'
17793 }
17794};
17795/**
17796 * Order attempted to be alphabetical.
17797 * - x/y/z-prefixes ignored in sorting
17798 * - __type__ always at end
17799 * - globals at end
17800 */
17801
17802var allOptions = {
17803 animationAutoStart: {
17804 boolean: bool,
17805 'undefined': 'undefined'
17806 },
17807 animationInterval: {
17808 number: number
17809 },
17810 animationPreload: {
17811 boolean: bool
17812 },
17813 axisColor: {
17814 string: string
17815 },
17816 axisFontSize: {
17817 number: number
17818 },
17819 axisFontType: {
17820 string: string
17821 },
17822 backgroundColor: colorOptions,
17823 xBarWidth: {
17824 number: number,
17825 'undefined': 'undefined'
17826 },
17827 yBarWidth: {
17828 number: number,
17829 'undefined': 'undefined'
17830 },
17831 cameraPosition: {
17832 distance: {
17833 number: number
17834 },
17835 horizontal: {
17836 number: number
17837 },
17838 vertical: {
17839 number: number
17840 },
17841 __type__: {
17842 object: object
17843 }
17844 },
17845 zoomable: {
17846 boolean: bool
17847 },
17848 ctrlToZoom: {
17849 boolean: bool
17850 },
17851 xCenter: {
17852 string: string
17853 },
17854 yCenter: {
17855 string: string
17856 },
17857 colormap: colormapOptions,
17858 dataColor: colorOptions,
17859 dotSizeMinFraction: {
17860 number: number
17861 },
17862 dotSizeMaxFraction: {
17863 number: number
17864 },
17865 dotSizeRatio: {
17866 number: number
17867 },
17868 filterLabel: {
17869 string: string
17870 },
17871 gridColor: {
17872 string: string
17873 },
17874 onclick: {
17875 'function': 'function'
17876 },
17877 keepAspectRatio: {
17878 boolean: bool
17879 },
17880 xLabel: {
17881 string: string
17882 },
17883 yLabel: {
17884 string: string
17885 },
17886 zLabel: {
17887 string: string
17888 },
17889 legendLabel: {
17890 string: string
17891 },
17892 xMin: {
17893 number: number,
17894 'undefined': 'undefined'
17895 },
17896 yMin: {
17897 number: number,
17898 'undefined': 'undefined'
17899 },
17900 zMin: {
17901 number: number,
17902 'undefined': 'undefined'
17903 },
17904 xMax: {
17905 number: number,
17906 'undefined': 'undefined'
17907 },
17908 yMax: {
17909 number: number,
17910 'undefined': 'undefined'
17911 },
17912 zMax: {
17913 number: number,
17914 'undefined': 'undefined'
17915 },
17916 showAnimationControls: {
17917 boolean: bool,
17918 'undefined': 'undefined'
17919 },
17920 showGrayBottom: {
17921 boolean: bool
17922 },
17923 showGrid: {
17924 boolean: bool
17925 },
17926 showLegend: {
17927 boolean: bool,
17928 'undefined': 'undefined'
17929 },
17930 showPerspective: {
17931 boolean: bool
17932 },
17933 showShadow: {
17934 boolean: bool
17935 },
17936 showSurfaceGrid: {
17937 boolean: bool
17938 },
17939 showXAxis: {
17940 boolean: bool
17941 },
17942 showYAxis: {
17943 boolean: bool
17944 },
17945 showZAxis: {
17946 boolean: bool
17947 },
17948 rotateAxisLabels: {
17949 boolean: bool
17950 },
17951 surfaceColors: surfaceColorsOptions,
17952 xStep: {
17953 number: number,
17954 'undefined': 'undefined'
17955 },
17956 yStep: {
17957 number: number,
17958 'undefined': 'undefined'
17959 },
17960 zStep: {
17961 number: number,
17962 'undefined': 'undefined'
17963 },
17964 style: {
17965 number: number,
17966 // TODO: either Graph3d.DEFAULT has string, or number allowed in documentation
17967 string: ['bar', 'bar-color', 'bar-size', 'dot', 'dot-line', 'dot-color', 'dot-size', 'line', 'grid', 'surface']
17968 },
17969 tooltip: {
17970 boolean: bool,
17971 'function': 'function'
17972 },
17973 tooltipDelay: {
17974 number: number
17975 },
17976 tooltipStyle: {
17977 content: {
17978 color: {
17979 string: string
17980 },
17981 background: {
17982 string: string
17983 },
17984 border: {
17985 string: string
17986 },
17987 borderRadius: {
17988 string: string
17989 },
17990 boxShadow: {
17991 string: string
17992 },
17993 padding: {
17994 string: string
17995 },
17996 __type__: {
17997 object: object
17998 }
17999 },
18000 line: {
18001 borderLeft: {
18002 string: string
18003 },
18004 height: {
18005 string: string
18006 },
18007 width: {
18008 string: string
18009 },
18010 pointerEvents: {
18011 string: string
18012 },
18013 __type__: {
18014 object: object
18015 }
18016 },
18017 dot: {
18018 border: {
18019 string: string
18020 },
18021 borderRadius: {
18022 string: string
18023 },
18024 height: {
18025 string: string
18026 },
18027 width: {
18028 string: string
18029 },
18030 pointerEvents: {
18031 string: string
18032 },
18033 __type__: {
18034 object: object
18035 }
18036 },
18037 __type__: {
18038 object: object
18039 }
18040 },
18041 xValueLabel: {
18042 'function': 'function'
18043 },
18044 yValueLabel: {
18045 'function': 'function'
18046 },
18047 zValueLabel: {
18048 'function': 'function'
18049 },
18050 valueMax: {
18051 number: number,
18052 'undefined': 'undefined'
18053 },
18054 valueMin: {
18055 number: number,
18056 'undefined': 'undefined'
18057 },
18058 verticalRatio: {
18059 number: number
18060 },
18061 //globals :
18062 height: {
18063 string: string
18064 },
18065 width: {
18066 string: string
18067 },
18068 __type__: {
18069 object: object
18070 }
18071};
18072
18073/**
18074 * @prototype Range
18075 *
18076 * Helper class to make working with related min and max values easier.
18077 *
18078 * The range is inclusive; a given value is considered part of the range if:
18079 *
18080 * this.min <= value <= this.max
18081 */
18082function Range() {
18083 this.min = undefined;
18084 this.max = undefined;
18085}
18086/**
18087 * Adjust the range so that the passed value fits in it.
18088 *
18089 * If the value is outside of the current extremes, adjust
18090 * the min or max so that the value is within the range.
18091 *
18092 * @param {number} value Numeric value to fit in range
18093 */
18094
18095
18096Range.prototype.adjust = function (value) {
18097 if (value === undefined) return;
18098
18099 if (this.min === undefined || this.min > value) {
18100 this.min = value;
18101 }
18102
18103 if (this.max === undefined || this.max < value) {
18104 this.max = value;
18105 }
18106};
18107/**
18108 * Adjust the current range so that the passed range fits in it.
18109 *
18110 * @param {Range} range Range instance to fit in current instance
18111 */
18112
18113
18114Range.prototype.combine = function (range) {
18115 this.add(range.min);
18116 this.add(range.max);
18117};
18118/**
18119 * Expand the range by the given value
18120 *
18121 * min will be lowered by given value;
18122 * max will be raised by given value
18123 *
18124 * Shrinking by passing a negative value is allowed.
18125 *
18126 * @param {number} val Amount by which to expand or shrink current range with
18127 */
18128
18129
18130Range.prototype.expand = function (val) {
18131 if (val === undefined) {
18132 return;
18133 }
18134
18135 var newMin = this.min - val;
18136 var newMax = this.max + val; // Note that following allows newMin === newMax.
18137 // This should be OK, since method expand() allows this also.
18138
18139 if (newMin > newMax) {
18140 throw new Error('Passed expansion value makes range invalid');
18141 }
18142
18143 this.min = newMin;
18144 this.max = newMax;
18145};
18146/**
18147 * Determine the full range width of current instance.
18148 *
18149 * @returns {num} The calculated width of this range
18150 */
18151
18152
18153Range.prototype.range = function () {
18154 return this.max - this.min;
18155};
18156/**
18157 * Determine the central point of current instance.
18158 *
18159 * @returns {number} the value in the middle of min and max
18160 */
18161
18162
18163Range.prototype.center = function () {
18164 return (this.min + this.max) / 2;
18165};
18166
18167var Range_1 = Range;
18168
18169/**
18170 * @class Filter
18171 *
18172 * @param {DataGroup} dataGroup the data group
18173 * @param {number} column The index of the column to be filtered
18174 * @param {Graph3d} graph The graph
18175 */
18176
18177function Filter(dataGroup, column, graph) {
18178 this.dataGroup = dataGroup;
18179 this.column = column;
18180 this.graph = graph; // the parent graph
18181
18182 this.index = undefined;
18183 this.value = undefined; // read all distinct values and select the first one
18184
18185 this.values = dataGroup.getDistinctValues(this.column);
18186
18187 if (values(this).length > 0) {
18188 this.selectValue(0);
18189 } // create an array with the filtered datapoints. this will be loaded afterwards
18190
18191
18192 this.dataPoints = [];
18193 this.loaded = false;
18194 this.onLoadCallback = undefined;
18195
18196 if (graph.animationPreload) {
18197 this.loaded = false;
18198 this.loadInBackground();
18199 } else {
18200 this.loaded = true;
18201 }
18202}
18203/**
18204 * Return the label
18205 * @return {string} label
18206 */
18207
18208
18209Filter.prototype.isLoaded = function () {
18210 return this.loaded;
18211};
18212/**
18213 * Return the loaded progress
18214 * @return {number} percentage between 0 and 100
18215 */
18216
18217
18218Filter.prototype.getLoadedProgress = function () {
18219 var len = values(this).length;
18220
18221 var i = 0;
18222
18223 while (this.dataPoints[i]) {
18224 i++;
18225 }
18226
18227 return Math.round(i / len * 100);
18228};
18229/**
18230 * Return the label
18231 * @return {string} label
18232 */
18233
18234
18235Filter.prototype.getLabel = function () {
18236 return this.graph.filterLabel;
18237};
18238/**
18239 * Return the columnIndex of the filter
18240 * @return {number} columnIndex
18241 */
18242
18243
18244Filter.prototype.getColumn = function () {
18245 return this.column;
18246};
18247/**
18248 * Return the currently selected value. Returns undefined if there is no selection
18249 * @return {*} value
18250 */
18251
18252
18253Filter.prototype.getSelectedValue = function () {
18254 if (this.index === undefined) return undefined;
18255 return values(this)[this.index];
18256};
18257/**
18258 * Retrieve all values of the filter
18259 * @return {Array} values
18260 */
18261
18262
18263Filter.prototype.getValues = function () {
18264 return values(this);
18265};
18266/**
18267 * Retrieve one value of the filter
18268 * @param {number} index
18269 * @return {*} value
18270 */
18271
18272
18273Filter.prototype.getValue = function (index) {
18274 if (index >= values(this).length) throw new Error('Index out of range');
18275 return values(this)[index];
18276};
18277/**
18278 * Retrieve the (filtered) dataPoints for the currently selected filter index
18279 * @param {number} [index] (optional)
18280 * @return {Array} dataPoints
18281 */
18282
18283
18284Filter.prototype._getDataPoints = function (index) {
18285 if (index === undefined) index = this.index;
18286 if (index === undefined) return [];
18287 var dataPoints;
18288
18289 if (this.dataPoints[index]) {
18290 dataPoints = this.dataPoints[index];
18291 } else {
18292 var f = {};
18293 f.column = this.column;
18294 f.value = values(this)[index];
18295 var dataView = new DataView$1(this.dataGroup.getDataSet(), {
18296 filter: function filter(item) {
18297 return item[f.column] == f.value;
18298 }
18299 }).get();
18300 dataPoints = this.dataGroup._getDataPoints(dataView);
18301 this.dataPoints[index] = dataPoints;
18302 }
18303
18304 return dataPoints;
18305};
18306/**
18307 * Set a callback function when the filter is fully loaded.
18308 *
18309 * @param {function} callback
18310 */
18311
18312
18313Filter.prototype.setOnLoadCallback = function (callback) {
18314 this.onLoadCallback = callback;
18315};
18316/**
18317 * Add a value to the list with available values for this filter
18318 * No double entries will be created.
18319 * @param {number} index
18320 */
18321
18322
18323Filter.prototype.selectValue = function (index) {
18324 if (index >= values(this).length) throw new Error('Index out of range');
18325 this.index = index;
18326 this.value = values(this)[index];
18327};
18328/**
18329 * Load all filtered rows in the background one by one
18330 * Start this method without providing an index!
18331 *
18332 * @param {number} [index=0]
18333 */
18334
18335
18336Filter.prototype.loadInBackground = function (index) {
18337 if (index === undefined) index = 0;
18338 var frame = this.graph.frame;
18339
18340 if (index < values(this).length) {
18341 // create a progress box
18342 if (frame.progress === undefined) {
18343 frame.progress = document.createElement('DIV');
18344 frame.progress.style.position = 'absolute';
18345 frame.progress.style.color = 'gray';
18346 frame.appendChild(frame.progress);
18347 }
18348
18349 var progress = this.getLoadedProgress();
18350 frame.progress.innerHTML = 'Loading animation... ' + progress + '%'; // TODO: this is no nice solution...
18351
18352 frame.progress.style.bottom = 60 + 'px'; // TODO: use height of slider
18353
18354 frame.progress.style.left = 10 + 'px';
18355 var me = this;
18356
18357 setTimeout$1(function () {
18358 me.loadInBackground(index + 1);
18359 }, 10);
18360
18361 this.loaded = false;
18362 } else {
18363 this.loaded = true; // remove the progress box
18364
18365 if (frame.progress !== undefined) {
18366 frame.removeChild(frame.progress);
18367 frame.progress = undefined;
18368 }
18369
18370 if (this.onLoadCallback) this.onLoadCallback();
18371 }
18372};
18373
18374/**
18375 * Creates a container for all data of one specific 3D-graph.
18376 *
18377 * On construction, the container is totally empty; the data
18378 * needs to be initialized with method initializeData().
18379 * Failure to do so will result in the following exception begin thrown
18380 * on instantiation of Graph3D:
18381 *
18382 * Error: Array, DataSet, or DataView expected
18383 *
18384 * @constructor DataGroup
18385 */
18386
18387function DataGroup() {
18388 this.dataTable = null; // The original data table
18389}
18390/**
18391 * Initializes the instance from the passed data.
18392 *
18393 * Calculates minimum and maximum values and column index values.
18394 *
18395 * The graph3d instance is used internally to access the settings for
18396 * the given instance.
18397 * TODO: Pass settings only instead.
18398 *
18399 * @param {vis.Graph3d} graph3d Reference to the calling Graph3D instance.
18400 * @param {Array | DataSet | DataView} rawData The data containing the items for
18401 * the Graph.
18402 * @param {number} style Style Number
18403 * @returns {Array.<Object>}
18404 */
18405
18406
18407DataGroup.prototype.initializeData = function (graph3d, rawData, style) {
18408 if (rawData === undefined) return;
18409
18410 if (isArray(rawData)) {
18411 rawData = new DataSet$1(rawData);
18412 }
18413
18414 var data;
18415
18416 if (rawData instanceof DataSet$1 || rawData instanceof DataView$1) {
18417 data = rawData.get();
18418 } else {
18419 throw new Error('Array, DataSet, or DataView expected');
18420 }
18421
18422 if (data.length == 0) return;
18423 this.style = style; // unsubscribe from the dataTable
18424
18425 if (this.dataSet) {
18426 this.dataSet.off('*', this._onChange);
18427 }
18428
18429 this.dataSet = rawData;
18430 this.dataTable = data; // subscribe to changes in the dataset
18431
18432 var me = this;
18433
18434 this._onChange = function () {
18435 graph3d.setData(me.dataSet);
18436 };
18437
18438 this.dataSet.on('*', this._onChange); // determine the location of x,y,z,value,filter columns
18439
18440 this.colX = 'x';
18441 this.colY = 'y';
18442 this.colZ = 'z';
18443 var withBars = graph3d.hasBars(style); // determine barWidth from data
18444
18445 if (withBars) {
18446 if (graph3d.defaultXBarWidth !== undefined) {
18447 this.xBarWidth = graph3d.defaultXBarWidth;
18448 } else {
18449 this.xBarWidth = this.getSmallestDifference(data, this.colX) || 1;
18450 }
18451
18452 if (graph3d.defaultYBarWidth !== undefined) {
18453 this.yBarWidth = graph3d.defaultYBarWidth;
18454 } else {
18455 this.yBarWidth = this.getSmallestDifference(data, this.colY) || 1;
18456 }
18457 } // calculate minima and maxima
18458
18459
18460 this._initializeRange(data, this.colX, graph3d, withBars);
18461
18462 this._initializeRange(data, this.colY, graph3d, withBars);
18463
18464 this._initializeRange(data, this.colZ, graph3d, false);
18465
18466 if (data[0].hasOwnProperty('style')) {
18467 this.colValue = 'style';
18468 var valueRange = this.getColumnRange(data, this.colValue);
18469
18470 this._setRangeDefaults(valueRange, graph3d.defaultValueMin, graph3d.defaultValueMax);
18471
18472 this.valueRange = valueRange;
18473 } else {
18474 this.colValue = 'z';
18475 this.valueRange = this.zRange;
18476 } // Initialize data filter if a filter column is provided
18477
18478
18479 var table = this.getDataTable();
18480
18481 if (table[0].hasOwnProperty('filter')) {
18482 if (this.dataFilter === undefined) {
18483 this.dataFilter = new Filter(this, 'filter', graph3d);
18484 this.dataFilter.setOnLoadCallback(function () {
18485 graph3d.redraw();
18486 });
18487 }
18488 }
18489
18490 var dataPoints;
18491
18492 if (this.dataFilter) {
18493 // apply filtering
18494 dataPoints = this.dataFilter._getDataPoints();
18495 } else {
18496 // no filtering. load all data
18497 dataPoints = this._getDataPoints(this.getDataTable());
18498 }
18499
18500 return dataPoints;
18501};
18502/**
18503 * Collect the range settings for the given data column.
18504 *
18505 * This internal method is intended to make the range
18506 * initalization more generic.
18507 *
18508 * TODO: if/when combined settings per axis defined, get rid of this.
18509 *
18510 * @private
18511 *
18512 * @param {'x'|'y'|'z'} column The data column to process
18513 * @param {vis.Graph3d} graph3d Reference to the calling Graph3D instance;
18514 * required for access to settings
18515 * @returns {Object}
18516 */
18517
18518
18519DataGroup.prototype._collectRangeSettings = function (column, graph3d) {
18520 var _context;
18521
18522 var index = indexOf(_context = ['x', 'y', 'z']).call(_context, column);
18523
18524 if (index == -1) {
18525 throw new Error('Column \'' + column + '\' invalid');
18526 }
18527
18528 var upper = column.toUpperCase();
18529 return {
18530 barWidth: this[column + 'BarWidth'],
18531 min: graph3d['default' + upper + 'Min'],
18532 max: graph3d['default' + upper + 'Max'],
18533 step: graph3d['default' + upper + 'Step'],
18534 range_label: column + 'Range',
18535 // Name of instance field to write to
18536 step_label: column + 'Step' // Name of instance field to write to
18537
18538 };
18539};
18540/**
18541 * Initializes the settings per given column.
18542 *
18543 * TODO: if/when combined settings per axis defined, rewrite this.
18544 *
18545 * @private
18546 *
18547 * @param {DataSet | DataView} data The data containing the items for the Graph
18548 * @param {'x'|'y'|'z'} column The data column to process
18549 * @param {vis.Graph3d} graph3d Reference to the calling Graph3D instance;
18550 * required for access to settings
18551 * @param {boolean} withBars True if initializing for bar graph
18552 */
18553
18554
18555DataGroup.prototype._initializeRange = function (data, column, graph3d, withBars) {
18556 var NUMSTEPS = 5;
18557
18558 var settings = this._collectRangeSettings(column, graph3d);
18559
18560 var range = this.getColumnRange(data, column);
18561
18562 if (withBars && column != 'z') {
18563 // Safeguard for 'z'; it doesn't have a bar width
18564 range.expand(settings.barWidth / 2);
18565 }
18566
18567 this._setRangeDefaults(range, settings.min, settings.max);
18568
18569 this[settings.range_label] = range;
18570 this[settings.step_label] = settings.step !== undefined ? settings.step : range.range() / NUMSTEPS;
18571};
18572/**
18573 * Creates a list with all the different values in the data for the given column.
18574 *
18575 * If no data passed, use the internal data of this instance.
18576 *
18577 * @param {'x'|'y'|'z'} column The data column to process
18578 * @param {DataSet|DataView|undefined} data The data containing the items for the Graph
18579 *
18580 * @returns {Array} All distinct values in the given column data, sorted ascending.
18581 */
18582
18583
18584DataGroup.prototype.getDistinctValues = function (column, data) {
18585 if (data === undefined) {
18586 data = this.dataTable;
18587 }
18588
18589 var values = [];
18590
18591 for (var i = 0; i < data.length; i++) {
18592 var value = data[i][column] || 0;
18593
18594 if (indexOf(values).call(values, value) === -1) {
18595 values.push(value);
18596 }
18597 }
18598
18599 return sort(values).call(values, function (a, b) {
18600 return a - b;
18601 });
18602};
18603/**
18604 * Determine the smallest difference between the values for given
18605 * column in the passed data set.
18606 *
18607 * @param {DataSet|DataView|undefined} data The data containing the items for the Graph
18608 * @param {'x'|'y'|'z'} column The data column to process
18609 *
18610 * @returns {number|null} Smallest difference value or
18611 * null, if it can't be determined.
18612 */
18613
18614
18615DataGroup.prototype.getSmallestDifference = function (data, column) {
18616 var values = this.getDistinctValues(data, column); // Get all the distinct diffs
18617 // Array values is assumed to be sorted here
18618
18619 var smallest_diff = null;
18620
18621 for (var i = 1; i < values.length; i++) {
18622 var diff = values[i] - values[i - 1];
18623
18624 if (smallest_diff == null || smallest_diff > diff) {
18625 smallest_diff = diff;
18626 }
18627 }
18628
18629 return smallest_diff;
18630};
18631/**
18632 * Get the absolute min/max values for the passed data column.
18633 *
18634 * @param {DataSet|DataView|undefined} data The data containing the items for the Graph
18635 * @param {'x'|'y'|'z'} column The data column to process
18636 *
18637 * @returns {Range} A Range instance with min/max members properly set.
18638 */
18639
18640
18641DataGroup.prototype.getColumnRange = function (data, column) {
18642 var range = new Range_1(); // Adjust the range so that it covers all values in the passed data elements.
18643
18644 for (var i = 0; i < data.length; i++) {
18645 var item = data[i][column];
18646 range.adjust(item);
18647 }
18648
18649 return range;
18650};
18651/**
18652 * Determines the number of rows in the current data.
18653 *
18654 * @returns {number}
18655 */
18656
18657
18658DataGroup.prototype.getNumberOfRows = function () {
18659 return this.dataTable.length;
18660};
18661/**
18662 * Set default values for range
18663 *
18664 * The default values override the range values, if defined.
18665 *
18666 * Because it's possible that only defaultMin or defaultMax is set, it's better
18667 * to pass in a range already set with the min/max set from the data. Otherwise,
18668 * it's quite hard to process the min/max properly.
18669 *
18670 * @param {vis.Range} range
18671 * @param {number} [defaultMin=range.min]
18672 * @param {number} [defaultMax=range.max]
18673 * @private
18674 */
18675
18676
18677DataGroup.prototype._setRangeDefaults = function (range, defaultMin, defaultMax) {
18678 if (defaultMin !== undefined) {
18679 range.min = defaultMin;
18680 }
18681
18682 if (defaultMax !== undefined) {
18683 range.max = defaultMax;
18684 } // This is the original way that the default min/max values were adjusted.
18685 // TODO: Perhaps it's better if an error is thrown if the values do not agree.
18686 // But this will change the behaviour.
18687
18688
18689 if (range.max <= range.min) range.max = range.min + 1;
18690};
18691
18692DataGroup.prototype.getDataTable = function () {
18693 return this.dataTable;
18694};
18695
18696DataGroup.prototype.getDataSet = function () {
18697 return this.dataSet;
18698};
18699/**
18700 * Return all data values as a list of Point3d objects
18701 * @param {Array.<Object>} data
18702 * @returns {Array.<Object>}
18703 */
18704
18705
18706DataGroup.prototype.getDataPoints = function (data) {
18707 var dataPoints = [];
18708
18709 for (var i = 0; i < data.length; i++) {
18710 var point = new Point3d_1();
18711 point.x = data[i][this.colX] || 0;
18712 point.y = data[i][this.colY] || 0;
18713 point.z = data[i][this.colZ] || 0;
18714 point.data = data[i];
18715 point.value = data[i][this.colValue] || 0;
18716 var obj = {};
18717 obj.point = point;
18718 obj.bottom = new Point3d_1(point.x, point.y, this.zRange.min);
18719 obj.trans = undefined;
18720 obj.screen = undefined;
18721 dataPoints.push(obj);
18722 }
18723
18724 return dataPoints;
18725};
18726/**
18727 * Copy all values from the data table to a matrix.
18728 *
18729 * The provided values are supposed to form a grid of (x,y) positions.
18730 * @param {Array.<Object>} data
18731 * @returns {Array.<Object>}
18732 * @private
18733 */
18734
18735
18736DataGroup.prototype.initDataAsMatrix = function (data) {
18737 // TODO: store the created matrix dataPoints in the filters instead of
18738 // reloading each time.
18739 var x, y, i, obj; // create two lists with all present x and y values
18740
18741 var dataX = this.getDistinctValues(this.colX, data);
18742 var dataY = this.getDistinctValues(this.colY, data);
18743 var dataPoints = this.getDataPoints(data); // create a grid, a 2d matrix, with all values.
18744
18745 var dataMatrix = []; // temporary data matrix
18746
18747 for (i = 0; i < dataPoints.length; i++) {
18748 obj = dataPoints[i]; // TODO: implement Array().indexOf() for Internet Explorer
18749
18750 var xIndex = indexOf(dataX).call(dataX, obj.point.x);
18751
18752 var yIndex = indexOf(dataY).call(dataY, obj.point.y);
18753
18754 if (dataMatrix[xIndex] === undefined) {
18755 dataMatrix[xIndex] = [];
18756 }
18757
18758 dataMatrix[xIndex][yIndex] = obj;
18759 } // fill in the pointers to the neighbors.
18760
18761
18762 for (x = 0; x < dataMatrix.length; x++) {
18763 for (y = 0; y < dataMatrix[x].length; y++) {
18764 if (dataMatrix[x][y]) {
18765 dataMatrix[x][y].pointRight = x < dataMatrix.length - 1 ? dataMatrix[x + 1][y] : undefined;
18766 dataMatrix[x][y].pointTop = y < dataMatrix[x].length - 1 ? dataMatrix[x][y + 1] : undefined;
18767 dataMatrix[x][y].pointCross = x < dataMatrix.length - 1 && y < dataMatrix[x].length - 1 ? dataMatrix[x + 1][y + 1] : undefined;
18768 }
18769 }
18770 }
18771
18772 return dataPoints;
18773};
18774/**
18775 * Return common information, if present
18776 *
18777 * @returns {string}
18778 */
18779
18780
18781DataGroup.prototype.getInfo = function () {
18782 var dataFilter = this.dataFilter;
18783 if (!dataFilter) return undefined;
18784 return dataFilter.getLabel() + ': ' + dataFilter.getSelectedValue();
18785};
18786/**
18787 * Reload the data
18788 */
18789
18790
18791DataGroup.prototype.reload = function () {
18792 if (this.dataTable) {
18793 this.setData(this.dataTable);
18794 }
18795};
18796/**
18797 * Filter the data based on the current filter
18798 *
18799 * @param {Array} data
18800 * @returns {Array} dataPoints Array with point objects which can be drawn on
18801 * screen
18802 */
18803
18804
18805DataGroup.prototype._getDataPoints = function (data) {
18806 var dataPoints = [];
18807
18808 if (this.style === STYLE.GRID || this.style === STYLE.SURFACE) {
18809 dataPoints = this.initDataAsMatrix(data);
18810 } else {
18811 // 'dot', 'dot-line', etc.
18812 dataPoints = this.getDataPoints(data);
18813
18814 if (this.style === STYLE.LINE) {
18815 // Add next member points for line drawing
18816 for (var i = 0; i < dataPoints.length; i++) {
18817 if (i > 0) {
18818 dataPoints[i - 1].pointNext = dataPoints[i];
18819 }
18820 }
18821 }
18822 }
18823
18824 return dataPoints;
18825};
18826
18827Graph3d$1.STYLE = STYLE;
18828/**
18829 * Following label is used in the settings to describe values which should be
18830 * determined by the code while running, from the current data and graph style.
18831 *
18832 * Using 'undefined' directly achieves the same thing, but this is more
18833 * descriptive by describing the intent.
18834 */
18835
18836var autoByDefault = undefined;
18837/**
18838 * Default values for option settings.
18839 *
18840 * These are the values used when a Graph3d instance is initialized without
18841 * custom settings.
18842 *
18843 * If a field is not in this list, a default value of 'autoByDefault' is assumed,
18844 * which is just an alias for 'undefined'.
18845 */
18846
18847Graph3d$1.DEFAULTS = {
18848 width: '400px',
18849 height: '400px',
18850 filterLabel: 'time',
18851 legendLabel: 'value',
18852 xLabel: 'x',
18853 yLabel: 'y',
18854 zLabel: 'z',
18855 xValueLabel: function xValueLabel(v) {
18856 return v;
18857 },
18858 yValueLabel: function yValueLabel(v) {
18859 return v;
18860 },
18861 zValueLabel: function zValueLabel(v) {
18862 return v;
18863 },
18864 showXAxis: true,
18865 showYAxis: true,
18866 showZAxis: true,
18867 showGrayBottom: false,
18868 showGrid: true,
18869 showPerspective: true,
18870 showShadow: false,
18871 showSurfaceGrid: true,
18872 keepAspectRatio: true,
18873 rotateAxisLabels: true,
18874 verticalRatio: 0.5,
18875 // 0.1 to 1.0, where 1.0 results in a 'cube'
18876 dotSizeRatio: 0.02,
18877 // size of the dots as a fraction of the graph width
18878 dotSizeMinFraction: 0.5,
18879 // size of min-value dot as a fraction of dotSizeRatio
18880 dotSizeMaxFraction: 2.5,
18881 // size of max-value dot as a fraction of dotSizeRatio
18882 showAnimationControls: autoByDefault,
18883 animationInterval: 1000,
18884 // milliseconds
18885 animationPreload: false,
18886 animationAutoStart: autoByDefault,
18887 axisFontSize: 14,
18888 axisFontType: 'arial',
18889 axisColor: '#4D4D4D',
18890 gridColor: '#D3D3D3',
18891 xCenter: '55%',
18892 yCenter: '50%',
18893 style: Graph3d$1.STYLE.DOT,
18894 tooltip: false,
18895 tooltipDelay: 300,
18896 // milliseconds
18897 tooltipStyle: {
18898 content: {
18899 padding: '10px',
18900 border: '1px solid #4d4d4d',
18901 color: '#1a1a1a',
18902 background: 'rgba(255,255,255,0.7)',
18903 borderRadius: '2px',
18904 boxShadow: '5px 5px 10px rgba(128,128,128,0.5)'
18905 },
18906 line: {
18907 height: '40px',
18908 width: '0',
18909 borderLeft: '1px solid #4d4d4d',
18910 pointerEvents: 'none'
18911 },
18912 dot: {
18913 height: '0',
18914 width: '0',
18915 border: '5px solid #4d4d4d',
18916 borderRadius: '5px',
18917 pointerEvents: 'none'
18918 }
18919 },
18920 dataColor: {
18921 fill: '#7DC1FF',
18922 stroke: '#3267D2',
18923 strokeWidth: 1 // px
18924
18925 },
18926 surfaceColors: autoByDefault,
18927 colormap: autoByDefault,
18928 cameraPosition: {
18929 horizontal: 1.0,
18930 vertical: 0.5,
18931 distance: 1.7
18932 },
18933 zoomable: true,
18934 ctrlToZoom: false,
18935
18936 /*
18937 The following fields are 'auto by default', see above.
18938 */
18939 showLegend: autoByDefault,
18940 // determined by graph style
18941 backgroundColor: autoByDefault,
18942 xBarWidth: autoByDefault,
18943 yBarWidth: autoByDefault,
18944 valueMin: autoByDefault,
18945 valueMax: autoByDefault,
18946 xMin: autoByDefault,
18947 xMax: autoByDefault,
18948 xStep: autoByDefault,
18949 yMin: autoByDefault,
18950 yMax: autoByDefault,
18951 yStep: autoByDefault,
18952 zMin: autoByDefault,
18953 zMax: autoByDefault,
18954 zStep: autoByDefault
18955}; // -----------------------------------------------------------------------------
18956// Class Graph3d
18957// -----------------------------------------------------------------------------
18958
18959/**
18960 * Graph3d displays data in 3d.
18961 *
18962 * Graph3d is developed in javascript as a Google Visualization Chart.
18963 *
18964 * @constructor Graph3d
18965 * @param {Element} container The DOM element in which the Graph3d will
18966 * be created. Normally a div element.
18967 * @param {DataSet | DataView | Array} [data]
18968 * @param {Object} [options]
18969 */
18970
18971function Graph3d$1(container, data, options) {
18972 if (!(this instanceof Graph3d$1)) {
18973 throw new SyntaxError('Constructor must be called with the new operator');
18974 } // create variables and set default values
18975
18976
18977 this.containerElement = container;
18978 this.dataGroup = new DataGroup();
18979 this.dataPoints = null; // The table with point objects
18980 // create a frame and canvas
18981
18982 this.create();
18983 setDefaults(Graph3d$1.DEFAULTS, this); // the column indexes
18984
18985 this.colX = undefined;
18986 this.colY = undefined;
18987 this.colZ = undefined;
18988 this.colValue = undefined; // TODO: customize axis range
18989 // apply options (also when undefined)
18990
18991 this.setOptions(options); // apply data
18992
18993 this.setData(data);
18994} // Extend Graph3d with an Emitter mixin
18995
18996
18997componentEmitter(Graph3d$1.prototype);
18998/**
18999 * Calculate the scaling values, dependent on the range in x, y, and z direction
19000 */
19001
19002Graph3d$1.prototype._setScale = function () {
19003 this.scale = new Point3d_1(1 / this.xRange.range(), 1 / this.yRange.range(), 1 / this.zRange.range()); // keep aspect ration between x and y scale if desired
19004
19005 if (this.keepAspectRatio) {
19006 if (this.scale.x < this.scale.y) {
19007 //noinspection JSSuspiciousNameCombination
19008 this.scale.y = this.scale.x;
19009 } else {
19010 //noinspection JSSuspiciousNameCombination
19011 this.scale.x = this.scale.y;
19012 }
19013 } // scale the vertical axis
19014
19015
19016 this.scale.z *= this.verticalRatio; // TODO: can this be automated? verticalRatio?
19017 // determine scale for (optional) value
19018
19019 if (this.valueRange !== undefined) {
19020 this.scale.value = 1 / this.valueRange.range();
19021 } // position the camera arm
19022
19023
19024 var xCenter = this.xRange.center() * this.scale.x;
19025 var yCenter = this.yRange.center() * this.scale.y;
19026 var zCenter = this.zRange.center() * this.scale.z;
19027 this.camera.setArmLocation(xCenter, yCenter, zCenter);
19028};
19029/**
19030 * Convert a 3D location to a 2D location on screen
19031 * Source: ttp://en.wikipedia.org/wiki/3D_projection
19032 *
19033 * @param {Point3d} point3d A 3D point with parameters x, y, z
19034 * @returns {Point2d} point2d A 2D point with parameters x, y
19035 */
19036
19037
19038Graph3d$1.prototype._convert3Dto2D = function (point3d) {
19039 var translation = this._convertPointToTranslation(point3d);
19040
19041 return this._convertTranslationToScreen(translation);
19042};
19043/**
19044 * Convert a 3D location its translation seen from the camera
19045 * Source: http://en.wikipedia.org/wiki/3D_projection
19046 *
19047 * @param {Point3d} point3d A 3D point with parameters x, y, z
19048 * @returns {Point3d} translation A 3D point with parameters x, y, z This is
19049 * the translation of the point, seen from the
19050 * camera.
19051 */
19052
19053
19054Graph3d$1.prototype._convertPointToTranslation = function (point3d) {
19055 var cameraLocation = this.camera.getCameraLocation(),
19056 cameraRotation = this.camera.getCameraRotation(),
19057 ax = point3d.x * this.scale.x,
19058 ay = point3d.y * this.scale.y,
19059 az = point3d.z * this.scale.z,
19060 cx = cameraLocation.x,
19061 cy = cameraLocation.y,
19062 cz = cameraLocation.z,
19063 // calculate angles
19064 sinTx = Math.sin(cameraRotation.x),
19065 cosTx = Math.cos(cameraRotation.x),
19066 sinTy = Math.sin(cameraRotation.y),
19067 cosTy = Math.cos(cameraRotation.y),
19068 sinTz = Math.sin(cameraRotation.z),
19069 cosTz = Math.cos(cameraRotation.z),
19070 // calculate translation
19071 dx = cosTy * (sinTz * (ay - cy) + cosTz * (ax - cx)) - sinTy * (az - cz),
19072 dy = sinTx * (cosTy * (az - cz) + sinTy * (sinTz * (ay - cy) + cosTz * (ax - cx))) + cosTx * (cosTz * (ay - cy) - sinTz * (ax - cx)),
19073 dz = cosTx * (cosTy * (az - cz) + sinTy * (sinTz * (ay - cy) + cosTz * (ax - cx))) - sinTx * (cosTz * (ay - cy) - sinTz * (ax - cx));
19074 return new Point3d_1(dx, dy, dz);
19075};
19076/**
19077 * Convert a translation point to a point on the screen
19078 *
19079 * @param {Point3d} translation A 3D point with parameters x, y, z This is
19080 * the translation of the point, seen from the
19081 * camera.
19082 * @returns {Point2d} point2d A 2D point with parameters x, y
19083 */
19084
19085
19086Graph3d$1.prototype._convertTranslationToScreen = function (translation) {
19087 var ex = this.eye.x,
19088 ey = this.eye.y,
19089 ez = this.eye.z,
19090 dx = translation.x,
19091 dy = translation.y,
19092 dz = translation.z; // calculate position on screen from translation
19093
19094 var bx;
19095 var by;
19096
19097 if (this.showPerspective) {
19098 bx = (dx - ex) * (ez / dz);
19099 by = (dy - ey) * (ez / dz);
19100 } else {
19101 bx = dx * -(ez / this.camera.getArmLength());
19102 by = dy * -(ez / this.camera.getArmLength());
19103 } // shift and scale the point to the center of the screen
19104 // use the width of the graph to scale both horizontally and vertically.
19105
19106
19107 return new Point2d_1(this.currentXCenter + bx * this.frame.canvas.clientWidth, this.currentYCenter - by * this.frame.canvas.clientWidth);
19108};
19109/**
19110 * Calculate the translations and screen positions of all points
19111 *
19112 * @param {Array.<Point3d>} points
19113 * @private
19114 */
19115
19116
19117Graph3d$1.prototype._calcTranslations = function (points) {
19118 for (var i = 0; i < points.length; i++) {
19119 var point = points[i];
19120 point.trans = this._convertPointToTranslation(point.point);
19121 point.screen = this._convertTranslationToScreen(point.trans); // calculate the translation of the point at the bottom (needed for sorting)
19122
19123 var transBottom = this._convertPointToTranslation(point.bottom);
19124
19125 point.dist = this.showPerspective ? transBottom.length() : -transBottom.z;
19126 } // sort the points on depth of their (x,y) position (not on z)
19127
19128
19129 var sortDepth = function sortDepth(a, b) {
19130 return b.dist - a.dist;
19131 };
19132
19133 sort(points).call(points, sortDepth);
19134};
19135/**
19136 * Transfer min/max values to the Graph3d instance.
19137 */
19138
19139
19140Graph3d$1.prototype._initializeRanges = function () {
19141 // TODO: later on, all min/maxes of all datagroups will be combined here
19142 var dg = this.dataGroup;
19143 this.xRange = dg.xRange;
19144 this.yRange = dg.yRange;
19145 this.zRange = dg.zRange;
19146 this.valueRange = dg.valueRange; // Values currently needed but which need to be sorted out for
19147 // the multiple graph case.
19148
19149 this.xStep = dg.xStep;
19150 this.yStep = dg.yStep;
19151 this.zStep = dg.zStep;
19152 this.xBarWidth = dg.xBarWidth;
19153 this.yBarWidth = dg.yBarWidth;
19154 this.colX = dg.colX;
19155 this.colY = dg.colY;
19156 this.colZ = dg.colZ;
19157 this.colValue = dg.colValue; // set the scale dependent on the ranges.
19158
19159 this._setScale();
19160};
19161/**
19162 * Return all data values as a list of Point3d objects
19163 *
19164 * @param {vis.DataSet} data
19165 * @returns {Array.<Object>}
19166 */
19167
19168
19169Graph3d$1.prototype.getDataPoints = function (data) {
19170 var dataPoints = [];
19171
19172 for (var i = 0; i < data.length; i++) {
19173 var point = new Point3d_1();
19174 point.x = data[i][this.colX] || 0;
19175 point.y = data[i][this.colY] || 0;
19176 point.z = data[i][this.colZ] || 0;
19177 point.data = data[i];
19178 point.value = data[i][this.colValue] || 0;
19179 var obj = {};
19180 obj.point = point;
19181 obj.bottom = new Point3d_1(point.x, point.y, this.zRange.min);
19182 obj.trans = undefined;
19183 obj.screen = undefined;
19184 dataPoints.push(obj);
19185 }
19186
19187 return dataPoints;
19188};
19189/**
19190 * Filter the data based on the current filter
19191 *
19192 * @param {Array} data
19193 * @returns {Array} dataPoints Array with point objects which can be drawn on
19194 * screen
19195 */
19196
19197
19198Graph3d$1.prototype._getDataPoints = function (data) {
19199 // TODO: store the created matrix dataPoints in the filters instead of
19200 // reloading each time.
19201 var x, y, i, obj;
19202 var dataPoints = [];
19203
19204 if (this.style === Graph3d$1.STYLE.GRID || this.style === Graph3d$1.STYLE.SURFACE) {
19205 // copy all values from the data table to a matrix
19206 // the provided values are supposed to form a grid of (x,y) positions
19207 // create two lists with all present x and y values
19208 var dataX = this.dataGroup.getDistinctValues(this.colX, data);
19209 var dataY = this.dataGroup.getDistinctValues(this.colY, data);
19210 dataPoints = this.getDataPoints(data); // create a grid, a 2d matrix, with all values.
19211
19212 var dataMatrix = []; // temporary data matrix
19213
19214 for (i = 0; i < dataPoints.length; i++) {
19215 obj = dataPoints[i]; // TODO: implement Array().indexOf() for Internet Explorer
19216
19217 var xIndex = indexOf(dataX).call(dataX, obj.point.x);
19218
19219 var yIndex = indexOf(dataY).call(dataY, obj.point.y);
19220
19221 if (dataMatrix[xIndex] === undefined) {
19222 dataMatrix[xIndex] = [];
19223 }
19224
19225 dataMatrix[xIndex][yIndex] = obj;
19226 } // fill in the pointers to the neighbors.
19227
19228
19229 for (x = 0; x < dataMatrix.length; x++) {
19230 for (y = 0; y < dataMatrix[x].length; y++) {
19231 if (dataMatrix[x][y]) {
19232 dataMatrix[x][y].pointRight = x < dataMatrix.length - 1 ? dataMatrix[x + 1][y] : undefined;
19233 dataMatrix[x][y].pointTop = y < dataMatrix[x].length - 1 ? dataMatrix[x][y + 1] : undefined;
19234 dataMatrix[x][y].pointCross = x < dataMatrix.length - 1 && y < dataMatrix[x].length - 1 ? dataMatrix[x + 1][y + 1] : undefined;
19235 }
19236 }
19237 }
19238 } else {
19239 // 'dot', 'dot-line', etc.
19240 dataPoints = this.getDataPoints(data);
19241
19242 if (this.style === Graph3d$1.STYLE.LINE) {
19243 // Add next member points for line drawing
19244 for (i = 0; i < dataPoints.length; i++) {
19245 if (i > 0) {
19246 dataPoints[i - 1].pointNext = dataPoints[i];
19247 }
19248 }
19249 }
19250 }
19251
19252 return dataPoints;
19253};
19254/**
19255 * Create the main frame for the Graph3d.
19256 *
19257 * This function is executed once when a Graph3d object is created. The frame
19258 * contains a canvas, and this canvas contains all objects like the axis and
19259 * nodes.
19260 */
19261
19262
19263Graph3d$1.prototype.create = function () {
19264 // remove all elements from the container element.
19265 while (this.containerElement.hasChildNodes()) {
19266 this.containerElement.removeChild(this.containerElement.firstChild);
19267 }
19268
19269 this.frame = document.createElement('div');
19270 this.frame.style.position = 'relative';
19271 this.frame.style.overflow = 'hidden'; // create the graph canvas (HTML canvas element)
19272
19273 this.frame.canvas = document.createElement('canvas');
19274 this.frame.canvas.style.position = 'relative';
19275 this.frame.appendChild(this.frame.canvas); //if (!this.frame.canvas.getContext) {
19276
19277 {
19278 var noCanvas = document.createElement('DIV');
19279 noCanvas.style.color = 'red';
19280 noCanvas.style.fontWeight = 'bold';
19281 noCanvas.style.padding = '10px';
19282 noCanvas.innerHTML = 'Error: your browser does not support HTML canvas';
19283 this.frame.canvas.appendChild(noCanvas);
19284 }
19285 this.frame.filter = document.createElement('div');
19286 filter(this.frame).style.position = 'absolute';
19287 filter(this.frame).style.bottom = '0px';
19288 filter(this.frame).style.left = '0px';
19289 filter(this.frame).style.width = '100%';
19290 this.frame.appendChild(filter(this.frame)); // add event listeners to handle moving and zooming the contents
19291
19292 var me = this;
19293
19294 var onmousedown = function onmousedown(event) {
19295 me._onMouseDown(event);
19296 };
19297
19298 var ontouchstart = function ontouchstart(event) {
19299 me._onTouchStart(event);
19300 };
19301
19302 var onmousewheel = function onmousewheel(event) {
19303 me._onWheel(event);
19304 };
19305
19306 var ontooltip = function ontooltip(event) {
19307 me._onTooltip(event);
19308 };
19309
19310 var onclick = function onclick(event) {
19311 me._onClick(event);
19312 }; // TODO: these events are never cleaned up... can give a 'memory leakage'
19313
19314
19315 addEventListener(this.frame.canvas, 'mousedown', onmousedown);
19316 addEventListener(this.frame.canvas, 'touchstart', ontouchstart);
19317 addEventListener(this.frame.canvas, 'mousewheel', onmousewheel);
19318 addEventListener(this.frame.canvas, 'mousemove', ontooltip);
19319 addEventListener(this.frame.canvas, 'click', onclick); // add the new graph to the container element
19320
19321 this.containerElement.appendChild(this.frame);
19322};
19323/**
19324 * Set a new size for the graph
19325 *
19326 * @param {number} width
19327 * @param {number} height
19328 * @private
19329 */
19330
19331
19332Graph3d$1.prototype._setSize = function (width, height) {
19333 this.frame.style.width = width;
19334 this.frame.style.height = height;
19335
19336 this._resizeCanvas();
19337};
19338/**
19339 * Resize the canvas to the current size of the frame
19340 */
19341
19342
19343Graph3d$1.prototype._resizeCanvas = function () {
19344 this.frame.canvas.style.width = '100%';
19345 this.frame.canvas.style.height = '100%';
19346 this.frame.canvas.width = this.frame.canvas.clientWidth;
19347 this.frame.canvas.height = this.frame.canvas.clientHeight; // adjust with for margin
19348
19349 filter(this.frame).style.width = this.frame.canvas.clientWidth - 2 * 10 + 'px';
19350};
19351/**
19352 * Start playing the animation, if requested and filter present. Only applicable
19353 * when animation data is available.
19354 */
19355
19356
19357Graph3d$1.prototype.animationStart = function () {
19358 // start animation when option is true
19359 if (!this.animationAutoStart || !this.dataGroup.dataFilter) return;
19360 if (!filter(this.frame) || !filter(this.frame).slider) throw new Error('No animation available');
19361
19362 filter(this.frame).slider.play();
19363};
19364/**
19365 * Stop animation
19366 */
19367
19368
19369Graph3d$1.prototype.animationStop = function () {
19370 if (!filter(this.frame) || !filter(this.frame).slider) return;
19371
19372 filter(this.frame).slider.stop();
19373};
19374/**
19375 * Resize the center position based on the current values in this.xCenter
19376 * and this.yCenter (which are strings with a percentage or a value
19377 * in pixels). The center positions are the variables this.currentXCenter
19378 * and this.currentYCenter
19379 */
19380
19381
19382Graph3d$1.prototype._resizeCenter = function () {
19383 // calculate the horizontal center position
19384 if (this.xCenter.charAt(this.xCenter.length - 1) === '%') {
19385 this.currentXCenter = _parseFloat(this.xCenter) / 100 * this.frame.canvas.clientWidth;
19386 } else {
19387 this.currentXCenter = _parseFloat(this.xCenter); // supposed to be in px
19388 } // calculate the vertical center position
19389
19390
19391 if (this.yCenter.charAt(this.yCenter.length - 1) === '%') {
19392 this.currentYCenter = _parseFloat(this.yCenter) / 100 * (this.frame.canvas.clientHeight - filter(this.frame).clientHeight);
19393 } else {
19394 this.currentYCenter = _parseFloat(this.yCenter); // supposed to be in px
19395 }
19396};
19397/**
19398 * Retrieve the current camera rotation
19399 *
19400 * @returns {object} An object with parameters horizontal, vertical, and
19401 * distance
19402 */
19403
19404
19405Graph3d$1.prototype.getCameraPosition = function () {
19406 var pos = this.camera.getArmRotation();
19407 pos.distance = this.camera.getArmLength();
19408 return pos;
19409};
19410/**
19411 * Load data into the 3D Graph
19412 *
19413 * @param {vis.DataSet} data
19414 * @private
19415 */
19416
19417
19418Graph3d$1.prototype._readData = function (data) {
19419 // read the data
19420 this.dataPoints = this.dataGroup.initializeData(this, data, this.style);
19421
19422 this._initializeRanges();
19423
19424 this._redrawFilter();
19425};
19426/**
19427 * Replace the dataset of the Graph3d
19428 *
19429 * @param {Array | DataSet | DataView} data
19430 */
19431
19432
19433Graph3d$1.prototype.setData = function (data) {
19434 if (data === undefined || data === null) return;
19435
19436 this._readData(data);
19437
19438 this.redraw();
19439 this.animationStart();
19440};
19441/**
19442 * Update the options. Options will be merged with current options
19443 *
19444 * @param {Object} options
19445 */
19446
19447
19448Graph3d$1.prototype.setOptions = function (options) {
19449 if (options === undefined) return;
19450 var errorFound = Validator$1.validate(options, allOptions);
19451
19452 if (errorFound === true) {
19453 console.log("%cErrors have been found in the supplied options object.", VALIDATOR_PRINT_STYLE$1);
19454 }
19455
19456 this.animationStop();
19457 setOptions(options, this);
19458 this.setPointDrawingMethod();
19459
19460 this._setSize(this.width, this.height);
19461
19462 this.setAxisLabelMethod();
19463 this.setData(this.dataGroup.getDataTable());
19464 this.animationStart();
19465};
19466/**
19467 * Determine which point drawing method to use for the current graph style.
19468 */
19469
19470
19471Graph3d$1.prototype.setPointDrawingMethod = function () {
19472 var method = undefined;
19473
19474 switch (this.style) {
19475 case Graph3d$1.STYLE.BAR:
19476 method = this._redrawBarGraphPoint;
19477 break;
19478
19479 case Graph3d$1.STYLE.BARCOLOR:
19480 method = this._redrawBarColorGraphPoint;
19481 break;
19482
19483 case Graph3d$1.STYLE.BARSIZE:
19484 method = this._redrawBarSizeGraphPoint;
19485 break;
19486
19487 case Graph3d$1.STYLE.DOT:
19488 method = this._redrawDotGraphPoint;
19489 break;
19490
19491 case Graph3d$1.STYLE.DOTLINE:
19492 method = this._redrawDotLineGraphPoint;
19493 break;
19494
19495 case Graph3d$1.STYLE.DOTCOLOR:
19496 method = this._redrawDotColorGraphPoint;
19497 break;
19498
19499 case Graph3d$1.STYLE.DOTSIZE:
19500 method = this._redrawDotSizeGraphPoint;
19501 break;
19502
19503 case Graph3d$1.STYLE.SURFACE:
19504 method = this._redrawSurfaceGraphPoint;
19505 break;
19506
19507 case Graph3d$1.STYLE.GRID:
19508 method = this._redrawGridGraphPoint;
19509 break;
19510
19511 case Graph3d$1.STYLE.LINE:
19512 method = this._redrawLineGraphPoint;
19513 break;
19514
19515 default:
19516 throw new Error('Can not determine point drawing method ' + 'for graph style \'' + this.style + '\'');
19517 }
19518
19519 this._pointDrawingMethod = method;
19520};
19521/**
19522 * Determine which functions to use to draw axis labels.
19523 */
19524
19525
19526Graph3d$1.prototype.setAxisLabelMethod = function () {
19527 if (this.rotateAxisLabels) {
19528 this._drawAxisLabelX = this.drawAxisLabelXRotate;
19529 this._drawAxisLabelY = this.drawAxisLabelYRotate;
19530 this._drawAxisLabelZ = this.drawAxisLabelZRotate;
19531 } else {
19532 this._drawAxisLabelX = this.drawAxisLabelX;
19533 this._drawAxisLabelY = this.drawAxisLabelY;
19534 this._drawAxisLabelZ = this.drawAxisLabelZ;
19535 }
19536};
19537/**
19538 * Redraw the Graph.
19539 */
19540
19541
19542Graph3d$1.prototype.redraw = function () {
19543 if (this.dataPoints === undefined) {
19544 throw new Error('Graph data not initialized');
19545 }
19546
19547 this._resizeCanvas();
19548
19549 this._resizeCenter();
19550
19551 this._redrawSlider();
19552
19553 this._redrawClear();
19554
19555 this._redrawAxis();
19556
19557 this._redrawDataGraph();
19558
19559 this._redrawInfo();
19560
19561 this._redrawLegend();
19562};
19563/**
19564 * Get drawing context without exposing canvas
19565 *
19566 * @returns {CanvasRenderingContext2D}
19567 * @private
19568 */
19569
19570
19571Graph3d$1.prototype._getContext = function () {
19572 var canvas = this.frame.canvas;
19573 var ctx = canvas.getContext('2d');
19574 ctx.lineJoin = 'round';
19575 ctx.lineCap = 'round';
19576 return ctx;
19577};
19578/**
19579 * Clear the canvas before redrawing
19580 */
19581
19582
19583Graph3d$1.prototype._redrawClear = function () {
19584 var canvas = this.frame.canvas;
19585 var ctx = canvas.getContext('2d');
19586 ctx.clearRect(0, 0, canvas.width, canvas.height);
19587};
19588
19589Graph3d$1.prototype._dotSize = function () {
19590 return this.frame.clientWidth * this.dotSizeRatio;
19591};
19592/**
19593 * Get legend width
19594 *
19595 * @returns {*}
19596 * @private
19597 */
19598
19599
19600Graph3d$1.prototype._getLegendWidth = function () {
19601 var width;
19602
19603 if (this.style === Graph3d$1.STYLE.DOTSIZE) {
19604 var dotSize = this._dotSize(); //width = dotSize / 2 + dotSize * 2;
19605
19606
19607 width = dotSize * this.dotSizeMaxFraction;
19608 } else if (this.style === Graph3d$1.STYLE.BARSIZE) {
19609 width = this.xBarWidth;
19610 } else {
19611 width = 20;
19612 }
19613
19614 return width;
19615};
19616/**
19617 * Redraw the legend based on size, dot color, or surface height
19618 */
19619
19620
19621Graph3d$1.prototype._redrawLegend = function () {
19622 //Return without drawing anything, if no legend is specified
19623 if (this.showLegend !== true) {
19624 return;
19625 } // Do not draw legend when graph style does not support
19626
19627
19628 if (this.style === Graph3d$1.STYLE.LINE || this.style === Graph3d$1.STYLE.BARSIZE //TODO add legend support for BARSIZE
19629 ) {
19630 return;
19631 } // Legend types - size and color. Determine if size legend.
19632
19633
19634 var isSizeLegend = this.style === Graph3d$1.STYLE.BARSIZE || this.style === Graph3d$1.STYLE.DOTSIZE; // Legend is either tracking z values or style values. This flag if false means use z values.
19635
19636 var isValueLegend = this.style === Graph3d$1.STYLE.DOTSIZE || this.style === Graph3d$1.STYLE.DOTCOLOR || this.style === Graph3d$1.STYLE.SURFACE || this.style === Graph3d$1.STYLE.BARCOLOR;
19637 var height = Math.max(this.frame.clientHeight * 0.25, 100);
19638 var top = this.margin;
19639
19640 var width = this._getLegendWidth(); // px - overwritten by size legend
19641
19642
19643 var right = this.frame.clientWidth - this.margin;
19644 var left = right - width;
19645 var bottom = top + height;
19646
19647 var ctx = this._getContext();
19648
19649 ctx.lineWidth = 1;
19650 ctx.font = '14px arial'; // TODO: put in options
19651
19652 if (isSizeLegend === false) {
19653 // draw the color bar
19654 var ymin = 0;
19655 var ymax = height; // Todo: make height customizable
19656
19657 var y;
19658
19659 for (y = ymin; y < ymax; y++) {
19660 // Need (1 - x) because y runs from top to bottom:
19661 var f = 1 - (y - ymin) / (ymax - ymin);
19662
19663 var color = this._colormap(f, 1);
19664
19665 ctx.strokeStyle = color;
19666 ctx.beginPath();
19667 ctx.moveTo(left, top + y);
19668 ctx.lineTo(right, top + y);
19669 ctx.stroke();
19670 }
19671
19672 ctx.strokeStyle = this.axisColor;
19673 ctx.strokeRect(left, top, width, height);
19674 } else {
19675 // draw the size legend box
19676 var widthMin;
19677
19678 if (this.style === Graph3d$1.STYLE.DOTSIZE) {
19679 // Get the proportion to max and min right
19680 widthMin = width * (this.dotSizeMinFraction / this.dotSizeMaxFraction);
19681 } else if (this.style === Graph3d$1.STYLE.BARSIZE) ;
19682
19683 ctx.strokeStyle = this.axisColor;
19684 ctx.fillStyle = fill(this.dataColor);
19685 ctx.beginPath();
19686 ctx.moveTo(left, top);
19687 ctx.lineTo(right, top);
19688 ctx.lineTo(left + widthMin, bottom);
19689 ctx.lineTo(left, bottom);
19690 ctx.closePath();
19691
19692 fill(ctx).call(ctx);
19693
19694 ctx.stroke();
19695 } // print value text along the legend edge
19696
19697
19698 var gridLineLen = 5; // px
19699
19700 var legendMin = isValueLegend ? this.valueRange.min : this.zRange.min;
19701 var legendMax = isValueLegend ? this.valueRange.max : this.zRange.max;
19702 var step = new StepNumber_1(legendMin, legendMax, (legendMax - legendMin) / 5, true);
19703 step.start(true);
19704 var from;
19705 var to;
19706
19707 while (!step.end()) {
19708 y = bottom - (step.getCurrent() - legendMin) / (legendMax - legendMin) * height;
19709 from = new Point2d_1(left - gridLineLen, y);
19710 to = new Point2d_1(left, y);
19711
19712 this._line(ctx, from, to);
19713
19714 ctx.textAlign = 'right';
19715 ctx.textBaseline = 'middle';
19716 ctx.fillStyle = this.axisColor;
19717 ctx.fillText(step.getCurrent(), left - 2 * gridLineLen, y);
19718 step.next();
19719 }
19720
19721 ctx.textAlign = 'right';
19722 ctx.textBaseline = 'top';
19723 var label = this.legendLabel;
19724 ctx.fillText(label, right, bottom + this.margin);
19725};
19726/**
19727 * Redraw the filter
19728 */
19729
19730
19731Graph3d$1.prototype._redrawFilter = function () {
19732 var dataFilter = this.dataGroup.dataFilter;
19733
19734 var filter$1 = filter(this.frame);
19735
19736 filter$1.innerHTML = '';
19737
19738 if (!dataFilter) {
19739 filter$1.slider = undefined;
19740 return;
19741 }
19742
19743 var options = {
19744 'visible': this.showAnimationControls
19745 };
19746 var slider = new Slider(filter$1, options);
19747 filter$1.slider = slider; // TODO: css here is not nice here...
19748
19749 filter$1.style.padding = '10px'; //this.frame.filter.style.backgroundColor = '#EFEFEF';
19750
19751 slider.setValues(values(dataFilter));
19752 slider.setPlayInterval(this.animationInterval); // create an event handler
19753
19754 var me = this;
19755
19756 var onchange = function onchange() {
19757 var dataFilter = me.dataGroup.dataFilter;
19758 var index = slider.getIndex();
19759 dataFilter.selectValue(index);
19760 me.dataPoints = dataFilter._getDataPoints();
19761 me.redraw();
19762 };
19763
19764 slider.setOnChangeCallback(onchange);
19765};
19766/**
19767 * Redraw the slider
19768 */
19769
19770
19771Graph3d$1.prototype._redrawSlider = function () {
19772 if (filter(this.frame).slider !== undefined) {
19773 filter(this.frame).slider.redraw();
19774 }
19775};
19776/**
19777 * Redraw common information
19778 */
19779
19780
19781Graph3d$1.prototype._redrawInfo = function () {
19782 var info = this.dataGroup.getInfo();
19783 if (info === undefined) return;
19784
19785 var ctx = this._getContext();
19786
19787 ctx.font = '14px arial'; // TODO: put in options
19788
19789 ctx.lineStyle = 'gray';
19790 ctx.fillStyle = 'gray';
19791 ctx.textAlign = 'left';
19792 ctx.textBaseline = 'top';
19793 var x = this.margin;
19794 var y = this.margin;
19795 ctx.fillText(info, x, y);
19796};
19797/**
19798 * Draw a line between 2d points 'from' and 'to'.
19799 *
19800 * If stroke style specified, set that as well.
19801 *
19802 * @param {CanvasRenderingContext2D} ctx
19803 * @param {vis.Point2d} from
19804 * @param {vis.Point2d} to
19805 * @param {string} [strokeStyle]
19806 * @private
19807 */
19808
19809
19810Graph3d$1.prototype._line = function (ctx, from, to, strokeStyle) {
19811 if (strokeStyle !== undefined) {
19812 ctx.strokeStyle = strokeStyle;
19813 }
19814
19815 ctx.beginPath();
19816 ctx.moveTo(from.x, from.y);
19817 ctx.lineTo(to.x, to.y);
19818 ctx.stroke();
19819};
19820/**
19821 *
19822 * @param {CanvasRenderingContext2D} ctx
19823 * @param {vis.Point3d} point3d
19824 * @param {string} text
19825 * @param {number} armAngle
19826 * @param {number} [yMargin=0]
19827 */
19828
19829
19830Graph3d$1.prototype.drawAxisLabelX = function (ctx, point3d, text, armAngle, yMargin) {
19831 if (yMargin === undefined) {
19832 yMargin = 0;
19833 }
19834
19835 var point2d = this._convert3Dto2D(point3d);
19836
19837 if (Math.cos(armAngle * 2) > 0) {
19838 ctx.textAlign = 'center';
19839 ctx.textBaseline = 'top';
19840 point2d.y += yMargin;
19841 } else if (Math.sin(armAngle * 2) < 0) {
19842 ctx.textAlign = 'right';
19843 ctx.textBaseline = 'middle';
19844 } else {
19845 ctx.textAlign = 'left';
19846 ctx.textBaseline = 'middle';
19847 }
19848
19849 ctx.fillStyle = this.axisColor;
19850 ctx.fillText(text, point2d.x, point2d.y);
19851};
19852/**
19853 *
19854 * @param {CanvasRenderingContext2D} ctx
19855 * @param {vis.Point3d} point3d
19856 * @param {string} text
19857 * @param {number} armAngle
19858 * @param {number} [yMargin=0]
19859 */
19860
19861
19862Graph3d$1.prototype.drawAxisLabelY = function (ctx, point3d, text, armAngle, yMargin) {
19863 if (yMargin === undefined) {
19864 yMargin = 0;
19865 }
19866
19867 var point2d = this._convert3Dto2D(point3d);
19868
19869 if (Math.cos(armAngle * 2) < 0) {
19870 ctx.textAlign = 'center';
19871 ctx.textBaseline = 'top';
19872 point2d.y += yMargin;
19873 } else if (Math.sin(armAngle * 2) > 0) {
19874 ctx.textAlign = 'right';
19875 ctx.textBaseline = 'middle';
19876 } else {
19877 ctx.textAlign = 'left';
19878 ctx.textBaseline = 'middle';
19879 }
19880
19881 ctx.fillStyle = this.axisColor;
19882 ctx.fillText(text, point2d.x, point2d.y);
19883};
19884/**
19885 *
19886 * @param {CanvasRenderingContext2D} ctx
19887 * @param {vis.Point3d} point3d
19888 * @param {string} text
19889 * @param {number} [offset=0]
19890 */
19891
19892
19893Graph3d$1.prototype.drawAxisLabelZ = function (ctx, point3d, text, offset) {
19894 if (offset === undefined) {
19895 offset = 0;
19896 }
19897
19898 var point2d = this._convert3Dto2D(point3d);
19899
19900 ctx.textAlign = 'right';
19901 ctx.textBaseline = 'middle';
19902 ctx.fillStyle = this.axisColor;
19903 ctx.fillText(text, point2d.x - offset, point2d.y);
19904};
19905/**
19906 *
19907 * @param {CanvasRenderingContext2D} ctx
19908 * @param {vis.Point3d} point3d
19909 * @param {string} text
19910 * @param {number} armAngle
19911 * @param {number} [yMargin=0]
19912 */
19913
19914
19915Graph3d$1.prototype.drawAxisLabelXRotate = function (ctx, point3d, text, armAngle, yMargin) {
19916
19917 var point2d = this._convert3Dto2D(point3d);
19918
19919 if (Math.cos(armAngle * 2) > 0) {
19920 ctx.save();
19921 ctx.translate(point2d.x, point2d.y);
19922 ctx.rotate(-Math.PI / 2);
19923 ctx.textAlign = 'right';
19924 ctx.textBaseline = 'middle';
19925 ctx.fillStyle = this.axisColor;
19926 ctx.fillText(text, 0, 0);
19927 ctx.restore();
19928 } else if (Math.sin(armAngle * 2) < 0) {
19929 ctx.textAlign = 'right';
19930 ctx.textBaseline = 'middle';
19931 ctx.fillStyle = this.axisColor;
19932 ctx.fillText(text, point2d.x, point2d.y);
19933 } else {
19934 ctx.textAlign = 'left';
19935 ctx.textBaseline = 'middle';
19936 ctx.fillStyle = this.axisColor;
19937 ctx.fillText(text, point2d.x, point2d.y);
19938 }
19939};
19940/**
19941 *
19942 * @param {CanvasRenderingContext2D} ctx
19943 * @param {vis.Point3d} point3d
19944 * @param {string} text
19945 * @param {number} armAngle
19946 * @param {number} [yMargin=0]
19947 */
19948
19949
19950Graph3d$1.prototype.drawAxisLabelYRotate = function (ctx, point3d, text, armAngle, yMargin) {
19951
19952 var point2d = this._convert3Dto2D(point3d);
19953
19954 if (Math.cos(armAngle * 2) < 0) {
19955 ctx.save();
19956 ctx.translate(point2d.x, point2d.y);
19957 ctx.rotate(-Math.PI / 2);
19958 ctx.textAlign = 'right';
19959 ctx.textBaseline = 'middle';
19960 ctx.fillStyle = this.axisColor;
19961 ctx.fillText(text, 0, 0);
19962 ctx.restore();
19963 } else if (Math.sin(armAngle * 2) > 0) {
19964 ctx.textAlign = 'right';
19965 ctx.textBaseline = 'middle';
19966 ctx.fillStyle = this.axisColor;
19967 ctx.fillText(text, point2d.x, point2d.y);
19968 } else {
19969 ctx.textAlign = 'left';
19970 ctx.textBaseline = 'middle';
19971 ctx.fillStyle = this.axisColor;
19972 ctx.fillText(text, point2d.x, point2d.y);
19973 }
19974};
19975/**
19976 *
19977 * @param {CanvasRenderingContext2D} ctx
19978 * @param {vis.Point3d} point3d
19979 * @param {string} text
19980 * @param {number} [offset=0]
19981 */
19982
19983
19984Graph3d$1.prototype.drawAxisLabelZRotate = function (ctx, point3d, text, offset) {
19985 if (offset === undefined) {
19986 offset = 0;
19987 }
19988
19989 var point2d = this._convert3Dto2D(point3d);
19990
19991 ctx.textAlign = 'right';
19992 ctx.textBaseline = 'middle';
19993 ctx.fillStyle = this.axisColor;
19994 ctx.fillText(text, point2d.x - offset, point2d.y);
19995};
19996/**
19997
19998
19999/**
20000 * Draw a line between 2d points 'from' and 'to'.
20001 *
20002 * If stroke style specified, set that as well.
20003 *
20004 * @param {CanvasRenderingContext2D} ctx
20005 * @param {vis.Point2d} from
20006 * @param {vis.Point2d} to
20007 * @param {string} [strokeStyle]
20008 * @private
20009 */
20010
20011
20012Graph3d$1.prototype._line3d = function (ctx, from, to, strokeStyle) {
20013 var from2d = this._convert3Dto2D(from);
20014
20015 var to2d = this._convert3Dto2D(to);
20016
20017 this._line(ctx, from2d, to2d, strokeStyle);
20018};
20019/**
20020 * Redraw the axis
20021 */
20022
20023
20024Graph3d$1.prototype._redrawAxis = function () {
20025 var ctx = this._getContext(),
20026 from,
20027 to,
20028 step,
20029 prettyStep,
20030 text,
20031 xText,
20032 yText,
20033 zText,
20034 offset,
20035 xOffset,
20036 yOffset; // TODO: get the actual rendered style of the containerElement
20037 //ctx.font = this.containerElement.style.font;
20038 //ctx.font = 24 / this.camera.getArmLength() + 'px arial';
20039
20040
20041 ctx.font = this.axisFontSize / this.camera.getArmLength() + 'px ' + this.axisFontType; // calculate the length for the short grid lines
20042
20043 var gridLenX = 0.025 / this.scale.x;
20044 var gridLenY = 0.025 / this.scale.y;
20045 var textMargin = 5 / this.camera.getArmLength(); // px
20046
20047 var armAngle = this.camera.getArmRotation().horizontal;
20048 var armVector = new Point2d_1(Math.cos(armAngle), Math.sin(armAngle));
20049 var xRange = this.xRange;
20050 var yRange = this.yRange;
20051 var zRange = this.zRange;
20052 var point3d; // draw x-grid lines
20053
20054 ctx.lineWidth = 1;
20055 prettyStep = this.defaultXStep === undefined;
20056 step = new StepNumber_1(xRange.min, xRange.max, this.xStep, prettyStep);
20057 step.start(true);
20058
20059 while (!step.end()) {
20060 var x = step.getCurrent();
20061
20062 if (this.showGrid) {
20063 from = new Point3d_1(x, yRange.min, zRange.min);
20064 to = new Point3d_1(x, yRange.max, zRange.min);
20065
20066 this._line3d(ctx, from, to, this.gridColor);
20067 } else if (this.showXAxis) {
20068 from = new Point3d_1(x, yRange.min, zRange.min);
20069 to = new Point3d_1(x, yRange.min + gridLenX, zRange.min);
20070
20071 this._line3d(ctx, from, to, this.axisColor);
20072
20073 from = new Point3d_1(x, yRange.max, zRange.min);
20074 to = new Point3d_1(x, yRange.max - gridLenX, zRange.min);
20075
20076 this._line3d(ctx, from, to, this.axisColor);
20077 }
20078
20079 if (this.showXAxis) {
20080 yText = armVector.x > 0 ? yRange.min : yRange.max;
20081 point3d = new Point3d_1(x, yText, zRange.min);
20082 var msg = ' ' + this.xValueLabel(x) + ' ';
20083
20084 this._drawAxisLabelX.call(this, ctx, point3d, msg, armAngle, textMargin);
20085 }
20086
20087 step.next();
20088 } // draw y-grid lines
20089
20090
20091 ctx.lineWidth = 1;
20092 prettyStep = this.defaultYStep === undefined;
20093 step = new StepNumber_1(yRange.min, yRange.max, this.yStep, prettyStep);
20094 step.start(true);
20095
20096 while (!step.end()) {
20097 var y = step.getCurrent();
20098
20099 if (this.showGrid) {
20100 from = new Point3d_1(xRange.min, y, zRange.min);
20101 to = new Point3d_1(xRange.max, y, zRange.min);
20102
20103 this._line3d(ctx, from, to, this.gridColor);
20104 } else if (this.showYAxis) {
20105 from = new Point3d_1(xRange.min, y, zRange.min);
20106 to = new Point3d_1(xRange.min + gridLenY, y, zRange.min);
20107
20108 this._line3d(ctx, from, to, this.axisColor);
20109
20110 from = new Point3d_1(xRange.max, y, zRange.min);
20111 to = new Point3d_1(xRange.max - gridLenY, y, zRange.min);
20112
20113 this._line3d(ctx, from, to, this.axisColor);
20114 }
20115
20116 if (this.showYAxis) {
20117 xText = armVector.y > 0 ? xRange.min : xRange.max;
20118 point3d = new Point3d_1(xText, y, zRange.min);
20119
20120 var _msg = ' ' + this.yValueLabel(y) + ' ';
20121
20122 this._drawAxisLabelY.call(this, ctx, point3d, _msg, armAngle, textMargin);
20123 }
20124
20125 step.next();
20126 } // draw z-grid lines and axis
20127
20128
20129 if (this.showZAxis) {
20130 ctx.lineWidth = 1;
20131 prettyStep = this.defaultZStep === undefined;
20132 step = new StepNumber_1(zRange.min, zRange.max, this.zStep, prettyStep);
20133 step.start(true);
20134 xText = armVector.x > 0 ? xRange.min : xRange.max;
20135 yText = armVector.y < 0 ? yRange.min : yRange.max;
20136
20137 while (!step.end()) {
20138 var z = step.getCurrent(); // TODO: make z-grid lines really 3d?
20139
20140 var from3d = new Point3d_1(xText, yText, z);
20141
20142 var from2d = this._convert3Dto2D(from3d);
20143
20144 to = new Point2d_1(from2d.x - textMargin, from2d.y);
20145
20146 this._line(ctx, from2d, to, this.axisColor);
20147
20148 var _msg2 = this.zValueLabel(z) + ' ';
20149
20150 this._drawAxisLabelZ.call(this, ctx, from3d, _msg2, 5);
20151
20152 step.next();
20153 }
20154
20155 ctx.lineWidth = 1;
20156 from = new Point3d_1(xText, yText, zRange.min);
20157 to = new Point3d_1(xText, yText, zRange.max);
20158
20159 this._line3d(ctx, from, to, this.axisColor);
20160 } // draw x-axis
20161
20162
20163 if (this.showXAxis) {
20164 var xMin2d;
20165 var xMax2d;
20166 ctx.lineWidth = 1; // line at yMin
20167
20168 xMin2d = new Point3d_1(xRange.min, yRange.min, zRange.min);
20169 xMax2d = new Point3d_1(xRange.max, yRange.min, zRange.min);
20170
20171 this._line3d(ctx, xMin2d, xMax2d, this.axisColor); // line at ymax
20172
20173
20174 xMin2d = new Point3d_1(xRange.min, yRange.max, zRange.min);
20175 xMax2d = new Point3d_1(xRange.max, yRange.max, zRange.min);
20176
20177 this._line3d(ctx, xMin2d, xMax2d, this.axisColor);
20178 } // draw y-axis
20179
20180
20181 if (this.showYAxis) {
20182 ctx.lineWidth = 1; // line at xMin
20183
20184 from = new Point3d_1(xRange.min, yRange.min, zRange.min);
20185 to = new Point3d_1(xRange.min, yRange.max, zRange.min);
20186
20187 this._line3d(ctx, from, to, this.axisColor); // line at xMax
20188
20189
20190 from = new Point3d_1(xRange.max, yRange.min, zRange.min);
20191 to = new Point3d_1(xRange.max, yRange.max, zRange.min);
20192
20193 this._line3d(ctx, from, to, this.axisColor);
20194 } // draw x-label
20195
20196
20197 var xLabel = this.xLabel;
20198
20199 if (xLabel.length > 0 && this.showXAxis) {
20200 yOffset = 0.1 / this.scale.y;
20201 xText = (xRange.max + 3 * xRange.min) / 4;
20202 yText = armVector.x > 0 ? yRange.min - yOffset : yRange.max + yOffset;
20203 text = new Point3d_1(xText, yText, zRange.min);
20204 this.drawAxisLabelX(ctx, text, xLabel, armAngle);
20205 } // draw y-label
20206
20207
20208 var yLabel = this.yLabel;
20209
20210 if (yLabel.length > 0 && this.showYAxis) {
20211 xOffset = 0.1 / this.scale.x;
20212 xText = armVector.y > 0 ? xRange.min - xOffset : xRange.max + xOffset;
20213 yText = (yRange.max + 3 * yRange.min) / 4;
20214 text = new Point3d_1(xText, yText, zRange.min);
20215 this.drawAxisLabelY(ctx, text, yLabel, armAngle);
20216 } // draw z-label
20217
20218
20219 var zLabel = this.zLabel;
20220
20221 if (zLabel.length > 0 && this.showZAxis) {
20222 offset = 30; // pixels. // TODO: relate to the max width of the values on the z axis?
20223
20224 xText = armVector.x > 0 ? xRange.min : xRange.max;
20225 yText = armVector.y < 0 ? yRange.min : yRange.max;
20226 zText = (zRange.max + 3 * zRange.min) / 4;
20227 text = new Point3d_1(xText, yText, zText);
20228 this.drawAxisLabelZ(ctx, text, zLabel, offset);
20229 }
20230};
20231/**
20232 *
20233 * @param {vis.Point3d} point
20234 * @returns {*}
20235 * @private
20236 */
20237
20238
20239Graph3d$1.prototype._getStrokeWidth = function (point) {
20240 if (point !== undefined) {
20241 if (this.showPerspective) {
20242 return 1 / -point.trans.z * this.dataColor.strokeWidth;
20243 } else {
20244 return -(this.eye.z / this.camera.getArmLength()) * this.dataColor.strokeWidth;
20245 }
20246 }
20247
20248 return this.dataColor.strokeWidth;
20249}; // -----------------------------------------------------------------------------
20250// Drawing primitives for the graphs
20251// -----------------------------------------------------------------------------
20252
20253/**
20254 * Draw a bar element in the view with the given properties.
20255 *
20256 * @param {CanvasRenderingContext2D} ctx
20257 * @param {Object} point
20258 * @param {number} xWidth
20259 * @param {number} yWidth
20260 * @param {string} color
20261 * @param {string} borderColor
20262 * @private
20263 */
20264
20265
20266Graph3d$1.prototype._redrawBar = function (ctx, point, xWidth, yWidth, color, borderColor) {
20267 var surface; // calculate all corner points
20268
20269 var me = this;
20270 var point3d = point.point;
20271 var zMin = this.zRange.min;
20272 var top = [{
20273 point: new Point3d_1(point3d.x - xWidth, point3d.y - yWidth, point3d.z)
20274 }, {
20275 point: new Point3d_1(point3d.x + xWidth, point3d.y - yWidth, point3d.z)
20276 }, {
20277 point: new Point3d_1(point3d.x + xWidth, point3d.y + yWidth, point3d.z)
20278 }, {
20279 point: new Point3d_1(point3d.x - xWidth, point3d.y + yWidth, point3d.z)
20280 }];
20281 var bottom = [{
20282 point: new Point3d_1(point3d.x - xWidth, point3d.y - yWidth, zMin)
20283 }, {
20284 point: new Point3d_1(point3d.x + xWidth, point3d.y - yWidth, zMin)
20285 }, {
20286 point: new Point3d_1(point3d.x + xWidth, point3d.y + yWidth, zMin)
20287 }, {
20288 point: new Point3d_1(point3d.x - xWidth, point3d.y + yWidth, zMin)
20289 }]; // calculate screen location of the points
20290
20291 forEach$2(top).call(top, function (obj) {
20292 obj.screen = me._convert3Dto2D(obj.point);
20293 });
20294
20295 forEach$2(bottom).call(bottom, function (obj) {
20296 obj.screen = me._convert3Dto2D(obj.point);
20297 }); // create five sides, calculate both corner points and center points
20298
20299
20300 var surfaces = [{
20301 corners: top,
20302 center: Point3d_1.avg(bottom[0].point, bottom[2].point)
20303 }, {
20304 corners: [top[0], top[1], bottom[1], bottom[0]],
20305 center: Point3d_1.avg(bottom[1].point, bottom[0].point)
20306 }, {
20307 corners: [top[1], top[2], bottom[2], bottom[1]],
20308 center: Point3d_1.avg(bottom[2].point, bottom[1].point)
20309 }, {
20310 corners: [top[2], top[3], bottom[3], bottom[2]],
20311 center: Point3d_1.avg(bottom[3].point, bottom[2].point)
20312 }, {
20313 corners: [top[3], top[0], bottom[0], bottom[3]],
20314 center: Point3d_1.avg(bottom[0].point, bottom[3].point)
20315 }];
20316 point.surfaces = surfaces; // calculate the distance of each of the surface centers to the camera
20317
20318 for (var j = 0; j < surfaces.length; j++) {
20319 surface = surfaces[j];
20320
20321 var transCenter = this._convertPointToTranslation(surface.center);
20322
20323 surface.dist = this.showPerspective ? transCenter.length() : -transCenter.z; // TODO: this dept calculation doesn't work 100% of the cases due to perspective,
20324 // but the current solution is fast/simple and works in 99.9% of all cases
20325 // the issue is visible in example 14, with graph.setCameraPosition({horizontal: 2.97, vertical: 0.5, distance: 0.9})
20326 } // order the surfaces by their (translated) depth
20327
20328
20329 sort(surfaces).call(surfaces, function (a, b) {
20330 var diff = b.dist - a.dist;
20331 if (diff) return diff; // if equal depth, sort the top surface last
20332
20333 if (a.corners === top) return 1;
20334 if (b.corners === top) return -1; // both are equal
20335
20336 return 0;
20337 }); // draw the ordered surfaces
20338
20339
20340 ctx.lineWidth = this._getStrokeWidth(point);
20341 ctx.strokeStyle = borderColor;
20342 ctx.fillStyle = color; // NOTE: we start at j=2 instead of j=0 as we don't need to draw the two surfaces at the backside
20343
20344 for (var _j = 2; _j < surfaces.length; _j++) {
20345 surface = surfaces[_j];
20346
20347 this._polygon(ctx, surface.corners);
20348 }
20349};
20350/**
20351 * Draw a polygon using the passed points and fill it with the passed style and stroke.
20352 *
20353 * @param {CanvasRenderingContext2D} ctx
20354 * @param {Array.<vis.Point3d>} points an array of points.
20355 * @param {string} [fillStyle] the fill style to set
20356 * @param {string} [strokeStyle] the stroke style to set
20357 */
20358
20359
20360Graph3d$1.prototype._polygon = function (ctx, points, fillStyle, strokeStyle) {
20361 if (points.length < 2) {
20362 return;
20363 }
20364
20365 if (fillStyle !== undefined) {
20366 ctx.fillStyle = fillStyle;
20367 }
20368
20369 if (strokeStyle !== undefined) {
20370 ctx.strokeStyle = strokeStyle;
20371 }
20372
20373 ctx.beginPath();
20374 ctx.moveTo(points[0].screen.x, points[0].screen.y);
20375
20376 for (var i = 1; i < points.length; ++i) {
20377 var point = points[i];
20378 ctx.lineTo(point.screen.x, point.screen.y);
20379 }
20380
20381 ctx.closePath();
20382
20383 fill(ctx).call(ctx);
20384
20385 ctx.stroke(); // TODO: only draw stroke when strokeWidth > 0
20386};
20387/**
20388 * @param {CanvasRenderingContext2D} ctx
20389 * @param {object} point
20390 * @param {string} color
20391 * @param {string} borderColor
20392 * @param {number} [size=this._dotSize()]
20393 * @private
20394 */
20395
20396
20397Graph3d$1.prototype._drawCircle = function (ctx, point, color, borderColor, size) {
20398 var radius = this._calcRadius(point, size);
20399
20400 ctx.lineWidth = this._getStrokeWidth(point);
20401 ctx.strokeStyle = borderColor;
20402 ctx.fillStyle = color;
20403 ctx.beginPath();
20404 ctx.arc(point.screen.x, point.screen.y, radius, 0, Math.PI * 2, true);
20405
20406 fill(ctx).call(ctx);
20407
20408 ctx.stroke();
20409};
20410/**
20411 * Determine the colors for the 'regular' graph styles.
20412 *
20413 * @param {object} point
20414 * @returns {{fill, border}}
20415 * @private
20416 */
20417
20418
20419Graph3d$1.prototype._getColorsRegular = function (point) {
20420 var f = (point.point.value - this.valueRange.min) * this.scale.value;
20421
20422 var color = this._colormap(f, 1);
20423
20424 var borderColor = this._colormap(f, 0.8);
20425
20426 return {
20427 fill: color,
20428 border: borderColor
20429 };
20430};
20431/**
20432 * Get the colors for the 'color' graph styles.
20433 * These styles are currently: 'bar-color' and 'dot-color'
20434 * Color may be set as a string representation of HTML color, like #ff00ff,
20435 * or calculated from a number, for example, distance from this point
20436 * The first option is useful when we have some pre-given legend, to which we have to adjust ourselves
20437 * The second option is useful when we are interested in automatically setting the color, from some value,
20438 * using some color scale
20439 * @param {object} point
20440 * @returns {{fill: *, border: *}}
20441 * @private
20442 */
20443
20444
20445Graph3d$1.prototype._getColorsColor = function (point) {
20446 // calculate the color based on the value
20447 var color, borderColor, pointStyle;
20448
20449 if (point && point.point && point.point.data && point.point.data.style) {
20450 pointStyle = point.point.data.style;
20451 }
20452
20453 if (pointStyle && _typeof(pointStyle) === 'object' && fill(pointStyle) && pointStyle.stroke) {
20454 return {
20455 fill: fill(pointStyle),
20456 border: pointStyle.stroke
20457 };
20458 }
20459
20460 if (typeof point.point.value === "string") {
20461 color = point.point.value;
20462 borderColor = point.point.value;
20463 } else {
20464 var f = (point.point.value - this.valueRange.min) * this.scale.value;
20465 color = this._colormap(f, 1);
20466 borderColor = this._colormap(f, 0.8);
20467 }
20468
20469 return {
20470 fill: color,
20471 border: borderColor
20472 };
20473};
20474/**
20475 * Get the colors for the 'size' graph styles.
20476 * These styles are currently: 'bar-size' and 'dot-size'
20477 *
20478 * @returns {{fill: *, border: (string|colorOptions.stroke|{string, undefined}|string|colorOptions.stroke|{string}|*)}}
20479 * @private
20480 */
20481
20482
20483Graph3d$1.prototype._getColorsSize = function () {
20484 return {
20485 fill: fill(this.dataColor),
20486 border: this.dataColor.stroke
20487 };
20488};
20489/**
20490 * Determine the color corresponding to a given value on the color scale.
20491 *
20492 * @param {number} [x] the data value to be mapped running from 0 to 1
20493 * @param {number} [v] scale factor between 0 and 1 for the color brightness
20494 * @returns {string}
20495 * @private
20496 */
20497
20498
20499Graph3d$1.prototype._colormap = function (x) {
20500 var v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
20501 var r, g, b, a;
20502 var colormap = this.colormap;
20503
20504 if (isArray(colormap)) {
20505 var maxIndex = colormap.length - 1;
20506 var startIndex = Math.max(Math.floor(x * maxIndex), 0);
20507 var endIndex = Math.min(startIndex + 1, maxIndex);
20508 var innerRatio = x * maxIndex - startIndex;
20509 var min = colormap[startIndex];
20510 var max = colormap[endIndex];
20511 r = min.r + innerRatio * (max.r - min.r);
20512 g = min.g + innerRatio * (max.g - min.g);
20513 b = min.b + innerRatio * (max.b - min.b);
20514 } else if (typeof colormap === 'function') {
20515 var _colormap = colormap(x);
20516
20517 r = _colormap.r;
20518 g = _colormap.g;
20519 b = _colormap.b;
20520 a = _colormap.a;
20521 } else {
20522 var hue = (1 - x) * 240;
20523
20524 var _util$HSVToRGB = HSVToRGB(hue / 360, 1, 1);
20525
20526 r = _util$HSVToRGB.r;
20527 g = _util$HSVToRGB.g;
20528 b = _util$HSVToRGB.b;
20529 }
20530
20531 if (typeof a === 'number' && !isNan(a)) {
20532 var _context, _context2, _context3;
20533
20534 return concat(_context = concat(_context2 = concat(_context3 = "RGBA(".concat(Math.round(r * v), ", ")).call(_context3, Math.round(g * v), ", ")).call(_context2, Math.round(b * v), ", ")).call(_context, a, ")");
20535 } else {
20536 var _context4, _context5;
20537
20538 return concat(_context4 = concat(_context5 = "RGB(".concat(Math.round(r * v), ", ")).call(_context5, Math.round(g * v), ", ")).call(_context4, Math.round(b * v), ")");
20539 }
20540};
20541/**
20542 * Determine the size of a point on-screen, as determined by the
20543 * distance to the camera.
20544 *
20545 * @param {Object} point
20546 * @param {number} [size=this._dotSize()] the size that needs to be translated to screen coordinates.
20547 * optional; if not passed, use the default point size.
20548 * @returns {number}
20549 * @private
20550 */
20551
20552
20553Graph3d$1.prototype._calcRadius = function (point, size) {
20554 if (size === undefined) {
20555 size = this._dotSize();
20556 }
20557
20558 var radius;
20559
20560 if (this.showPerspective) {
20561 radius = size / -point.trans.z;
20562 } else {
20563 radius = size * -(this.eye.z / this.camera.getArmLength());
20564 }
20565
20566 if (radius < 0) {
20567 radius = 0;
20568 }
20569
20570 return radius;
20571}; // -----------------------------------------------------------------------------
20572// Methods for drawing points per graph style.
20573// -----------------------------------------------------------------------------
20574
20575/**
20576 * Draw single datapoint for graph style 'bar'.
20577 *
20578 * @param {CanvasRenderingContext2D} ctx
20579 * @param {Object} point
20580 * @private
20581 */
20582
20583
20584Graph3d$1.prototype._redrawBarGraphPoint = function (ctx, point) {
20585 var xWidth = this.xBarWidth / 2;
20586 var yWidth = this.yBarWidth / 2;
20587
20588 var colors = this._getColorsRegular(point);
20589
20590 this._redrawBar(ctx, point, xWidth, yWidth, fill(colors), colors.border);
20591};
20592/**
20593 * Draw single datapoint for graph style 'bar-color'.
20594 *
20595 * @param {CanvasRenderingContext2D} ctx
20596 * @param {Object} point
20597 * @private
20598 */
20599
20600
20601Graph3d$1.prototype._redrawBarColorGraphPoint = function (ctx, point) {
20602 var xWidth = this.xBarWidth / 2;
20603 var yWidth = this.yBarWidth / 2;
20604
20605 var colors = this._getColorsColor(point);
20606
20607 this._redrawBar(ctx, point, xWidth, yWidth, fill(colors), colors.border);
20608};
20609/**
20610 * Draw single datapoint for graph style 'bar-size'.
20611 *
20612 * @param {CanvasRenderingContext2D} ctx
20613 * @param {Object} point
20614 * @private
20615 */
20616
20617
20618Graph3d$1.prototype._redrawBarSizeGraphPoint = function (ctx, point) {
20619 // calculate size for the bar
20620 var fraction = (point.point.value - this.valueRange.min) / this.valueRange.range();
20621 var xWidth = this.xBarWidth / 2 * (fraction * 0.8 + 0.2);
20622 var yWidth = this.yBarWidth / 2 * (fraction * 0.8 + 0.2);
20623
20624 var colors = this._getColorsSize();
20625
20626 this._redrawBar(ctx, point, xWidth, yWidth, fill(colors), colors.border);
20627};
20628/**
20629 * Draw single datapoint for graph style 'dot'.
20630 *
20631 * @param {CanvasRenderingContext2D} ctx
20632 * @param {Object} point
20633 * @private
20634 */
20635
20636
20637Graph3d$1.prototype._redrawDotGraphPoint = function (ctx, point) {
20638 var colors = this._getColorsRegular(point);
20639
20640 this._drawCircle(ctx, point, fill(colors), colors.border);
20641};
20642/**
20643 * Draw single datapoint for graph style 'dot-line'.
20644 *
20645 * @param {CanvasRenderingContext2D} ctx
20646 * @param {Object} point
20647 * @private
20648 */
20649
20650
20651Graph3d$1.prototype._redrawDotLineGraphPoint = function (ctx, point) {
20652 // draw a vertical line from the XY-plane to the graph value
20653 var from = this._convert3Dto2D(point.bottom);
20654
20655 ctx.lineWidth = 1;
20656
20657 this._line(ctx, from, point.screen, this.gridColor);
20658
20659 this._redrawDotGraphPoint(ctx, point);
20660};
20661/**
20662 * Draw single datapoint for graph style 'dot-color'.
20663 *
20664 * @param {CanvasRenderingContext2D} ctx
20665 * @param {Object} point
20666 * @private
20667 */
20668
20669
20670Graph3d$1.prototype._redrawDotColorGraphPoint = function (ctx, point) {
20671 var colors = this._getColorsColor(point);
20672
20673 this._drawCircle(ctx, point, fill(colors), colors.border);
20674};
20675/**
20676 * Draw single datapoint for graph style 'dot-size'.
20677 *
20678 * @param {CanvasRenderingContext2D} ctx
20679 * @param {Object} point
20680 * @private
20681 */
20682
20683
20684Graph3d$1.prototype._redrawDotSizeGraphPoint = function (ctx, point) {
20685 var dotSize = this._dotSize();
20686
20687 var fraction = (point.point.value - this.valueRange.min) / this.valueRange.range();
20688 var sizeMin = dotSize * this.dotSizeMinFraction;
20689 var sizeRange = dotSize * this.dotSizeMaxFraction - sizeMin;
20690 var size = sizeMin + sizeRange * fraction;
20691
20692 var colors = this._getColorsSize();
20693
20694 this._drawCircle(ctx, point, fill(colors), colors.border, size);
20695};
20696/**
20697 * Draw single datapoint for graph style 'surface'.
20698 *
20699 * @param {CanvasRenderingContext2D} ctx
20700 * @param {Object} point
20701 * @private
20702 */
20703
20704
20705Graph3d$1.prototype._redrawSurfaceGraphPoint = function (ctx, point) {
20706 var right = point.pointRight;
20707 var top = point.pointTop;
20708 var cross = point.pointCross;
20709
20710 if (point === undefined || right === undefined || top === undefined || cross === undefined) {
20711 return;
20712 }
20713
20714 var topSideVisible = true;
20715 var fillStyle;
20716 var strokeStyle;
20717 var cosViewAngle;
20718
20719 if (this.showGrayBottom || this.showShadow) {
20720 // calculate the cross product of the two vectors from center
20721 // to left and right, in order to know whether we are looking at the
20722 // bottom or at the top side. We can also use the cross product
20723 // for calculating light intensity
20724 var aDiff = Point3d_1.subtract(cross.trans, point.trans);
20725 var bDiff = Point3d_1.subtract(top.trans, right.trans);
20726 var surfaceNormal = Point3d_1.crossProduct(aDiff, bDiff);
20727
20728 if (this.showPerspective) {
20729 var surfacePosition = Point3d_1.avg(Point3d_1.avg(point.trans, cross.trans), Point3d_1.avg(right.trans, top.trans)); // This corresponds to diffuse lighting with light source at (0, 0, 0).
20730 // More generally, we would need `surfacePosition - lightPosition`:
20731
20732 cosViewAngle = -Point3d_1.dotProduct(surfaceNormal.normalize(), surfacePosition.normalize());
20733 } else {
20734 cosViewAngle = surfaceNormal.z / surfaceNormal.length();
20735 }
20736
20737 topSideVisible = cosViewAngle > 0;
20738 }
20739
20740 if (topSideVisible || !this.showGrayBottom) {
20741 var vAvg = (point.point.value + right.point.value + top.point.value + cross.point.value) / 4;
20742 var ratio = (vAvg - this.valueRange.min) * this.scale.value; // lighting factor. TODO: let user specify lighting model as function(?)
20743
20744 var v = this.showShadow ? (1 + cosViewAngle) / 2 : 1;
20745 fillStyle = this._colormap(ratio, v);
20746 } else {
20747 fillStyle = 'gray';
20748 }
20749
20750 if (this.showSurfaceGrid) {
20751 strokeStyle = this.axisColor; // TODO: should be customizable
20752 } else {
20753 strokeStyle = fillStyle;
20754 }
20755
20756 ctx.lineWidth = this._getStrokeWidth(point); // TODO: only draw stroke when strokeWidth > 0
20757
20758 var points = [point, right, cross, top];
20759
20760 this._polygon(ctx, points, fillStyle, strokeStyle);
20761};
20762/**
20763 * Helper method for _redrawGridGraphPoint()
20764 *
20765 * @param {CanvasRenderingContext2D} ctx
20766 * @param {Object} from
20767 * @param {Object} to
20768 * @private
20769 */
20770
20771
20772Graph3d$1.prototype._drawGridLine = function (ctx, from, to) {
20773 if (from === undefined || to === undefined) {
20774 return;
20775 }
20776
20777 var vAvg = (from.point.value + to.point.value) / 2;
20778 var f = (vAvg - this.valueRange.min) * this.scale.value;
20779 ctx.lineWidth = this._getStrokeWidth(from) * 2;
20780 ctx.strokeStyle = this._colormap(f, 1);
20781
20782 this._line(ctx, from.screen, to.screen);
20783};
20784/**
20785 * Draw single datapoint for graph style 'Grid'.
20786 *
20787 * @param {CanvasRenderingContext2D} ctx
20788 * @param {Object} point
20789 * @private
20790 */
20791
20792
20793Graph3d$1.prototype._redrawGridGraphPoint = function (ctx, point) {
20794 this._drawGridLine(ctx, point, point.pointRight);
20795
20796 this._drawGridLine(ctx, point, point.pointTop);
20797};
20798/**
20799 * Draw single datapoint for graph style 'line'.
20800 *
20801 * @param {CanvasRenderingContext2D} ctx
20802 * @param {Object} point
20803 * @private
20804 */
20805
20806
20807Graph3d$1.prototype._redrawLineGraphPoint = function (ctx, point) {
20808 if (point.pointNext === undefined) {
20809 return;
20810 }
20811
20812 ctx.lineWidth = this._getStrokeWidth(point);
20813 ctx.strokeStyle = this.dataColor.stroke;
20814
20815 this._line(ctx, point.screen, point.pointNext.screen);
20816};
20817/**
20818 * Draw all datapoints for currently selected graph style.
20819 *
20820 */
20821
20822
20823Graph3d$1.prototype._redrawDataGraph = function () {
20824 var ctx = this._getContext();
20825
20826 var i;
20827 if (this.dataPoints === undefined || this.dataPoints.length <= 0) return; // TODO: throw exception?
20828
20829 this._calcTranslations(this.dataPoints);
20830
20831 for (i = 0; i < this.dataPoints.length; i++) {
20832 var point = this.dataPoints[i]; // Using call() ensures that the correct context is used
20833
20834 this._pointDrawingMethod.call(this, ctx, point);
20835 }
20836}; // -----------------------------------------------------------------------------
20837// End methods for drawing points per graph style.
20838// -----------------------------------------------------------------------------
20839
20840/**
20841 * Store startX, startY and startOffset for mouse operations
20842 *
20843 * @param {Event} event The event that occurred
20844 */
20845
20846
20847Graph3d$1.prototype._storeMousePosition = function (event) {
20848 // get mouse position (different code for IE and all other browsers)
20849 this.startMouseX = getMouseX(event);
20850 this.startMouseY = getMouseY(event);
20851 this._startCameraOffset = this.camera.getOffset();
20852};
20853/**
20854 * Start a moving operation inside the provided parent element
20855 * @param {Event} event The event that occurred (required for
20856 * retrieving the mouse position)
20857 */
20858
20859
20860Graph3d$1.prototype._onMouseDown = function (event) {
20861 event = event || window.event; // check if mouse is still down (may be up when focus is lost for example
20862 // in an iframe)
20863
20864 if (this.leftButtonDown) {
20865 this._onMouseUp(event);
20866 } // only react on left mouse button down
20867
20868
20869 this.leftButtonDown = event.which ? event.which === 1 : event.button === 1;
20870 if (!this.leftButtonDown && !this.touchDown) return;
20871
20872 this._storeMousePosition(event);
20873
20874 this.startStart = new Date(this.start);
20875 this.startEnd = new Date(this.end);
20876 this.startArmRotation = this.camera.getArmRotation();
20877 this.frame.style.cursor = 'move'; // add event listeners to handle moving the contents
20878 // we store the function onmousemove and onmouseup in the graph, so we can
20879 // remove the eventlisteners lateron in the function mouseUp()
20880
20881 var me = this;
20882
20883 this.onmousemove = function (event) {
20884 me._onMouseMove(event);
20885 };
20886
20887 this.onmouseup = function (event) {
20888 me._onMouseUp(event);
20889 };
20890
20891 addEventListener(document, 'mousemove', me.onmousemove);
20892 addEventListener(document, 'mouseup', me.onmouseup);
20893 preventDefault(event);
20894};
20895/**
20896 * Perform moving operating.
20897 * This function activated from within the funcion Graph.mouseDown().
20898 * @param {Event} event Well, eehh, the event
20899 */
20900
20901
20902Graph3d$1.prototype._onMouseMove = function (event) {
20903 this.moving = true;
20904 event = event || window.event; // calculate change in mouse position
20905
20906 var diffX = _parseFloat(getMouseX(event)) - this.startMouseX;
20907 var diffY = _parseFloat(getMouseY(event)) - this.startMouseY; // move with ctrl or rotate by other
20908
20909 if (event && event.ctrlKey === true) {
20910 // calculate change in mouse position
20911 var scaleX = this.frame.clientWidth * 0.5;
20912 var scaleY = this.frame.clientHeight * 0.5;
20913 var offXNew = (this._startCameraOffset.x || 0) - diffX / scaleX * this.camera.armLength * 0.8;
20914 var offYNew = (this._startCameraOffset.y || 0) + diffY / scaleY * this.camera.armLength * 0.8;
20915 this.camera.setOffset(offXNew, offYNew);
20916
20917 this._storeMousePosition(event);
20918 } else {
20919 var horizontalNew = this.startArmRotation.horizontal + diffX / 200;
20920 var verticalNew = this.startArmRotation.vertical + diffY / 200;
20921 var snapAngle = 4; // degrees
20922
20923 var snapValue = Math.sin(snapAngle / 360 * 2 * Math.PI); // snap horizontally to nice angles at 0pi, 0.5pi, 1pi, 1.5pi, etc...
20924 // the -0.001 is to take care that the vertical axis is always drawn at the left front corner
20925
20926 if (Math.abs(Math.sin(horizontalNew)) < snapValue) {
20927 horizontalNew = Math.round(horizontalNew / Math.PI) * Math.PI - 0.001;
20928 }
20929
20930 if (Math.abs(Math.cos(horizontalNew)) < snapValue) {
20931 horizontalNew = (Math.round(horizontalNew / Math.PI - 0.5) + 0.5) * Math.PI - 0.001;
20932 } // snap vertically to nice angles
20933
20934
20935 if (Math.abs(Math.sin(verticalNew)) < snapValue) {
20936 verticalNew = Math.round(verticalNew / Math.PI) * Math.PI;
20937 }
20938
20939 if (Math.abs(Math.cos(verticalNew)) < snapValue) {
20940 verticalNew = (Math.round(verticalNew / Math.PI - 0.5) + 0.5) * Math.PI;
20941 }
20942
20943 this.camera.setArmRotation(horizontalNew, verticalNew);
20944 }
20945
20946 this.redraw(); // fire a cameraPositionChange event
20947
20948 var parameters = this.getCameraPosition();
20949 this.emit('cameraPositionChange', parameters);
20950 preventDefault(event);
20951};
20952/**
20953 * Stop moving operating.
20954 * This function activated from within the funcion Graph.mouseDown().
20955 * @param {Event} event The event
20956 */
20957
20958
20959Graph3d$1.prototype._onMouseUp = function (event) {
20960 this.frame.style.cursor = 'auto';
20961 this.leftButtonDown = false; // remove event listeners here
20962
20963 removeEventListener(document, 'mousemove', this.onmousemove);
20964 removeEventListener(document, 'mouseup', this.onmouseup);
20965 preventDefault(event);
20966};
20967/**
20968 * @param {Event} event The event
20969 */
20970
20971
20972Graph3d$1.prototype._onClick = function (event) {
20973 // NOTE: onclick_callback is deprecated and may be removed in a future version.
20974 if (!this.onclick_callback && !this.hasListeners('click')) return;
20975
20976 if (!this.moving) {
20977 var boundingRect = this.frame.getBoundingClientRect();
20978 var mouseX = getMouseX(event) - boundingRect.left;
20979 var mouseY = getMouseY(event) - boundingRect.top;
20980
20981 var dataPoint = this._dataPointFromXY(mouseX, mouseY);
20982
20983 if (dataPoint) {
20984 if (this.onclick_callback) this.onclick_callback(dataPoint.point.data);
20985 this.emit('click', dataPoint.point.data);
20986 }
20987 } else {
20988 // disable onclick callback, if it came immediately after rotate/pan
20989 this.moving = false;
20990 }
20991
20992 preventDefault(event);
20993};
20994/**
20995 * After having moved the mouse, a tooltip should pop up when the mouse is resting on a data point
20996 * @param {Event} event A mouse move event
20997 */
20998
20999
21000Graph3d$1.prototype._onTooltip = function (event) {
21001 var delay = this.tooltipDelay; // ms
21002
21003 var boundingRect = this.frame.getBoundingClientRect();
21004 var mouseX = getMouseX(event) - boundingRect.left;
21005 var mouseY = getMouseY(event) - boundingRect.top;
21006
21007 if (!this.showTooltip) {
21008 return;
21009 }
21010
21011 if (this.tooltipTimeout) {
21012 clearTimeout(this.tooltipTimeout);
21013 } // (delayed) display of a tooltip only if no mouse button is down
21014
21015
21016 if (this.leftButtonDown) {
21017 this._hideTooltip();
21018
21019 return;
21020 }
21021
21022 if (this.tooltip && this.tooltip.dataPoint) {
21023 // tooltip is currently visible
21024 var dataPoint = this._dataPointFromXY(mouseX, mouseY);
21025
21026 if (dataPoint !== this.tooltip.dataPoint) {
21027 // datapoint changed
21028 if (dataPoint) {
21029 this._showTooltip(dataPoint);
21030 } else {
21031 this._hideTooltip();
21032 }
21033 }
21034 } else {
21035 // tooltip is currently not visible
21036 var me = this;
21037 this.tooltipTimeout = setTimeout$1(function () {
21038 me.tooltipTimeout = null; // show a tooltip if we have a data point
21039
21040 var dataPoint = me._dataPointFromXY(mouseX, mouseY);
21041
21042 if (dataPoint) {
21043 me._showTooltip(dataPoint);
21044 }
21045 }, delay);
21046 }
21047};
21048/**
21049 * Event handler for touchstart event on mobile devices
21050 * @param {Event} event The event
21051 */
21052
21053
21054Graph3d$1.prototype._onTouchStart = function (event) {
21055 this.touchDown = true;
21056 var me = this;
21057
21058 this.ontouchmove = function (event) {
21059 me._onTouchMove(event);
21060 };
21061
21062 this.ontouchend = function (event) {
21063 me._onTouchEnd(event);
21064 };
21065
21066 addEventListener(document, 'touchmove', me.ontouchmove);
21067 addEventListener(document, 'touchend', me.ontouchend);
21068
21069 this._onMouseDown(event);
21070};
21071/**
21072 * Event handler for touchmove event on mobile devices
21073 * @param {Event} event The event
21074 */
21075
21076
21077Graph3d$1.prototype._onTouchMove = function (event) {
21078 this._onMouseMove(event);
21079};
21080/**
21081 * Event handler for touchend event on mobile devices
21082 * @param {Event} event The event
21083 */
21084
21085
21086Graph3d$1.prototype._onTouchEnd = function (event) {
21087 this.touchDown = false;
21088 removeEventListener(document, 'touchmove', this.ontouchmove);
21089 removeEventListener(document, 'touchend', this.ontouchend);
21090
21091 this._onMouseUp(event);
21092};
21093/**
21094 * Event handler for mouse wheel event, used to zoom the graph
21095 * Code from http://adomas.org/javascript-mouse-wheel/
21096 * @param {Event} event The event
21097 */
21098
21099
21100Graph3d$1.prototype._onWheel = function (event) {
21101 if (!event)
21102 /* For IE. */
21103 event = window.event;
21104
21105 if (this.zoomable && (!this.ctrlToZoom || event.ctrlKey)) {
21106 // retrieve delta
21107 var delta = 0;
21108
21109 if (event.wheelDelta) {
21110 /* IE/Opera. */
21111 delta = event.wheelDelta / 120;
21112 } else if (event.detail) {
21113 /* Mozilla case. */
21114 // In Mozilla, sign of delta is different than in IE.
21115 // Also, delta is multiple of 3.
21116 delta = -event.detail / 3;
21117 } // If delta is nonzero, handle it.
21118 // Basically, delta is now positive if wheel was scrolled up,
21119 // and negative, if wheel was scrolled down.
21120
21121
21122 if (delta) {
21123 var oldLength = this.camera.getArmLength();
21124 var newLength = oldLength * (1 - delta / 10);
21125 this.camera.setArmLength(newLength);
21126 this.redraw();
21127
21128 this._hideTooltip();
21129 } // fire a cameraPositionChange event
21130
21131
21132 var parameters = this.getCameraPosition();
21133 this.emit('cameraPositionChange', parameters); // Prevent default actions caused by mouse wheel.
21134 // That might be ugly, but we handle scrolls somehow
21135 // anyway, so don't bother here..
21136
21137 preventDefault(event);
21138 }
21139};
21140/**
21141 * Test whether a point lies inside given 2D triangle
21142 *
21143 * @param {vis.Point2d} point
21144 * @param {vis.Point2d[]} triangle
21145 * @returns {boolean} true if given point lies inside or on the edge of the
21146 * triangle, false otherwise
21147 * @private
21148 */
21149
21150
21151Graph3d$1.prototype._insideTriangle = function (point, triangle) {
21152 var a = triangle[0],
21153 b = triangle[1],
21154 c = triangle[2];
21155 /**
21156 *
21157 * @param {number} x
21158 * @returns {number}
21159 */
21160
21161 function sign(x) {
21162 return x > 0 ? 1 : x < 0 ? -1 : 0;
21163 }
21164
21165 var as = sign((b.x - a.x) * (point.y - a.y) - (b.y - a.y) * (point.x - a.x));
21166 var bs = sign((c.x - b.x) * (point.y - b.y) - (c.y - b.y) * (point.x - b.x));
21167 var cs = sign((a.x - c.x) * (point.y - c.y) - (a.y - c.y) * (point.x - c.x)); // each of the three signs must be either equal to each other or zero
21168
21169 return (as == 0 || bs == 0 || as == bs) && (bs == 0 || cs == 0 || bs == cs) && (as == 0 || cs == 0 || as == cs);
21170};
21171/**
21172 * Find a data point close to given screen position (x, y)
21173 *
21174 * @param {number} x
21175 * @param {number} y
21176 * @returns {Object | null} The closest data point or null if not close to any
21177 * data point
21178 * @private
21179 */
21180
21181
21182Graph3d$1.prototype._dataPointFromXY = function (x, y) {
21183 var i,
21184 distMax = 100,
21185 // px
21186 dataPoint = null,
21187 closestDataPoint = null,
21188 closestDist = null,
21189 center = new Point2d_1(x, y);
21190
21191 if (this.style === Graph3d$1.STYLE.BAR || this.style === Graph3d$1.STYLE.BARCOLOR || this.style === Graph3d$1.STYLE.BARSIZE) {
21192 // the data points are ordered from far away to closest
21193 for (i = this.dataPoints.length - 1; i >= 0; i--) {
21194 dataPoint = this.dataPoints[i];
21195 var surfaces = dataPoint.surfaces;
21196
21197 if (surfaces) {
21198 for (var s = surfaces.length - 1; s >= 0; s--) {
21199 // split each surface in two triangles, and see if the center point is inside one of these
21200 var surface = surfaces[s];
21201 var corners = surface.corners;
21202 var triangle1 = [corners[0].screen, corners[1].screen, corners[2].screen];
21203 var triangle2 = [corners[2].screen, corners[3].screen, corners[0].screen];
21204
21205 if (this._insideTriangle(center, triangle1) || this._insideTriangle(center, triangle2)) {
21206 // return immediately at the first hit
21207 return dataPoint;
21208 }
21209 }
21210 }
21211 }
21212 } else {
21213 // find the closest data point, using distance to the center of the point on 2d screen
21214 for (i = 0; i < this.dataPoints.length; i++) {
21215 dataPoint = this.dataPoints[i];
21216 var point = dataPoint.screen;
21217
21218 if (point) {
21219 var distX = Math.abs(x - point.x);
21220 var distY = Math.abs(y - point.y);
21221 var dist = Math.sqrt(distX * distX + distY * distY);
21222
21223 if ((closestDist === null || dist < closestDist) && dist < distMax) {
21224 closestDist = dist;
21225 closestDataPoint = dataPoint;
21226 }
21227 }
21228 }
21229 }
21230
21231 return closestDataPoint;
21232};
21233/**
21234 * Determine if the given style has bars
21235 *
21236 * @param {number} style the style to check
21237 * @returns {boolean} true if bar style, false otherwise
21238 */
21239
21240
21241Graph3d$1.prototype.hasBars = function (style) {
21242 return style == Graph3d$1.STYLE.BAR || style == Graph3d$1.STYLE.BARCOLOR || style == Graph3d$1.STYLE.BARSIZE;
21243};
21244/**
21245 * Display a tooltip for given data point
21246 * @param {Object} dataPoint
21247 * @private
21248 */
21249
21250
21251Graph3d$1.prototype._showTooltip = function (dataPoint) {
21252 var content, line, dot;
21253
21254 if (!this.tooltip) {
21255 content = document.createElement('div');
21256
21257 assign$2(content.style, {}, this.tooltipStyle.content);
21258
21259 content.style.position = 'absolute';
21260 line = document.createElement('div');
21261
21262 assign$2(line.style, {}, this.tooltipStyle.line);
21263
21264 line.style.position = 'absolute';
21265 dot = document.createElement('div');
21266
21267 assign$2(dot.style, {}, this.tooltipStyle.dot);
21268
21269 dot.style.position = 'absolute';
21270 this.tooltip = {
21271 dataPoint: null,
21272 dom: {
21273 content: content,
21274 line: line,
21275 dot: dot
21276 }
21277 };
21278 } else {
21279 content = this.tooltip.dom.content;
21280 line = this.tooltip.dom.line;
21281 dot = this.tooltip.dom.dot;
21282 }
21283
21284 this._hideTooltip();
21285
21286 this.tooltip.dataPoint = dataPoint;
21287
21288 if (typeof this.showTooltip === 'function') {
21289 content.innerHTML = this.showTooltip(dataPoint.point);
21290 } else {
21291 content.innerHTML = '<table>' + '<tr><td>' + this.xLabel + ':</td><td>' + dataPoint.point.x + '</td></tr>' + '<tr><td>' + this.yLabel + ':</td><td>' + dataPoint.point.y + '</td></tr>' + '<tr><td>' + this.zLabel + ':</td><td>' + dataPoint.point.z + '</td></tr>' + '</table>';
21292 }
21293
21294 content.style.left = '0';
21295 content.style.top = '0';
21296 this.frame.appendChild(content);
21297 this.frame.appendChild(line);
21298 this.frame.appendChild(dot); // calculate sizes
21299
21300 var contentWidth = content.offsetWidth;
21301 var contentHeight = content.offsetHeight;
21302 var lineHeight = line.offsetHeight;
21303 var dotWidth = dot.offsetWidth;
21304 var dotHeight = dot.offsetHeight;
21305 var left = dataPoint.screen.x - contentWidth / 2;
21306 left = Math.min(Math.max(left, 10), this.frame.clientWidth - 10 - contentWidth);
21307 line.style.left = dataPoint.screen.x + 'px';
21308 line.style.top = dataPoint.screen.y - lineHeight + 'px';
21309 content.style.left = left + 'px';
21310 content.style.top = dataPoint.screen.y - lineHeight - contentHeight + 'px';
21311 dot.style.left = dataPoint.screen.x - dotWidth / 2 + 'px';
21312 dot.style.top = dataPoint.screen.y - dotHeight / 2 + 'px';
21313};
21314/**
21315 * Hide the tooltip when displayed
21316 * @private
21317 */
21318
21319
21320Graph3d$1.prototype._hideTooltip = function () {
21321 if (this.tooltip) {
21322 this.tooltip.dataPoint = null;
21323
21324 for (var prop in this.tooltip.dom) {
21325 if (this.tooltip.dom.hasOwnProperty(prop)) {
21326 var elem = this.tooltip.dom[prop];
21327
21328 if (elem && elem.parentNode) {
21329 elem.parentNode.removeChild(elem);
21330 }
21331 }
21332 }
21333 }
21334};
21335/**--------------------------------------------------------------------------**/
21336
21337/**
21338 * Get the horizontal mouse position from a mouse event
21339 *
21340 * @param {Event} event
21341 * @returns {number} mouse x
21342 */
21343
21344
21345function getMouseX(event) {
21346 if ('clientX' in event) return event.clientX;
21347 return event.targetTouches[0] && event.targetTouches[0].clientX || 0;
21348}
21349/**
21350 * Get the vertical mouse position from a mouse event
21351 *
21352 * @param {Event} event
21353 * @returns {number} mouse y
21354 */
21355
21356
21357function getMouseY(event) {
21358 if ('clientY' in event) return event.clientY;
21359 return event.targetTouches[0] && event.targetTouches[0].clientY || 0;
21360} // -----------------------------------------------------------------------------
21361// Public methods for specific settings
21362// -----------------------------------------------------------------------------
21363
21364/**
21365 * Set the rotation and distance of the camera
21366 *
21367 * @param {Object} pos An object with the camera position
21368 * @param {number} [pos.horizontal] The horizontal rotation, between 0 and 2*PI.
21369 * Optional, can be left undefined.
21370 * @param {number} [pos.vertical] The vertical rotation, between 0 and 0.5*PI.
21371 * if vertical=0.5*PI, the graph is shown from
21372 * the top. Optional, can be left undefined.
21373 * @param {number} [pos.distance] The (normalized) distance of the camera to the
21374 * center of the graph, a value between 0.71 and
21375 * 5.0. Optional, can be left undefined.
21376 */
21377
21378
21379Graph3d$1.prototype.setCameraPosition = function (pos) {
21380 setCameraPosition(pos, this);
21381 this.redraw();
21382};
21383/**
21384 * Set a new size for the graph
21385 *
21386 * @param {string} width Width in pixels or percentage (for example '800px'
21387 * or '50%')
21388 * @param {string} height Height in pixels or percentage (for example '400px'
21389 * or '30%')
21390 */
21391
21392
21393Graph3d$1.prototype.setSize = function (width, height) {
21394 this._setSize(width, height);
21395
21396 this.redraw();
21397}; // -----------------------------------------------------------------------------
21398
21399/**
21400 * Created by Alex on 11/6/2014.
21401 */
21402function keycharm$1(options) {
21403 var preventDefault = options && options.preventDefault || false;
21404 var container = options && options.container || window;
21405 var _exportFunctions = {};
21406 var _bound = {
21407 keydown: {},
21408 keyup: {}
21409 };
21410 var _keys = {};
21411 var i; // a - z
21412
21413 for (i = 97; i <= 122; i++) {
21414 _keys[String.fromCharCode(i)] = {
21415 code: 65 + (i - 97),
21416 shift: false
21417 };
21418 } // A - Z
21419
21420
21421 for (i = 65; i <= 90; i++) {
21422 _keys[String.fromCharCode(i)] = {
21423 code: i,
21424 shift: true
21425 };
21426 } // 0 - 9
21427
21428
21429 for (i = 0; i <= 9; i++) {
21430 _keys['' + i] = {
21431 code: 48 + i,
21432 shift: false
21433 };
21434 } // F1 - F12
21435
21436
21437 for (i = 1; i <= 12; i++) {
21438 _keys['F' + i] = {
21439 code: 111 + i,
21440 shift: false
21441 };
21442 } // num0 - num9
21443
21444
21445 for (i = 0; i <= 9; i++) {
21446 _keys['num' + i] = {
21447 code: 96 + i,
21448 shift: false
21449 };
21450 } // numpad misc
21451
21452
21453 _keys['num*'] = {
21454 code: 106,
21455 shift: false
21456 };
21457 _keys['num+'] = {
21458 code: 107,
21459 shift: false
21460 };
21461 _keys['num-'] = {
21462 code: 109,
21463 shift: false
21464 };
21465 _keys['num/'] = {
21466 code: 111,
21467 shift: false
21468 };
21469 _keys['num.'] = {
21470 code: 110,
21471 shift: false
21472 }; // arrows
21473
21474 _keys['left'] = {
21475 code: 37,
21476 shift: false
21477 };
21478 _keys['up'] = {
21479 code: 38,
21480 shift: false
21481 };
21482 _keys['right'] = {
21483 code: 39,
21484 shift: false
21485 };
21486 _keys['down'] = {
21487 code: 40,
21488 shift: false
21489 }; // extra keys
21490
21491 _keys['space'] = {
21492 code: 32,
21493 shift: false
21494 };
21495 _keys['enter'] = {
21496 code: 13,
21497 shift: false
21498 };
21499 _keys['shift'] = {
21500 code: 16,
21501 shift: undefined
21502 };
21503 _keys['esc'] = {
21504 code: 27,
21505 shift: false
21506 };
21507 _keys['backspace'] = {
21508 code: 8,
21509 shift: false
21510 };
21511 _keys['tab'] = {
21512 code: 9,
21513 shift: false
21514 };
21515 _keys['ctrl'] = {
21516 code: 17,
21517 shift: false
21518 };
21519 _keys['alt'] = {
21520 code: 18,
21521 shift: false
21522 };
21523 _keys['delete'] = {
21524 code: 46,
21525 shift: false
21526 };
21527 _keys['pageup'] = {
21528 code: 33,
21529 shift: false
21530 };
21531 _keys['pagedown'] = {
21532 code: 34,
21533 shift: false
21534 }; // symbols
21535
21536 _keys['='] = {
21537 code: 187,
21538 shift: false
21539 };
21540 _keys['-'] = {
21541 code: 189,
21542 shift: false
21543 };
21544 _keys[']'] = {
21545 code: 221,
21546 shift: false
21547 };
21548 _keys['['] = {
21549 code: 219,
21550 shift: false
21551 };
21552
21553 var down = function (event) {
21554 handleEvent(event, 'keydown');
21555 };
21556
21557 var up = function (event) {
21558 handleEvent(event, 'keyup');
21559 }; // handle the actualy bound key with the event
21560
21561
21562 var handleEvent = function (event, type) {
21563 if (_bound[type][event.keyCode] !== undefined) {
21564 var bound = _bound[type][event.keyCode];
21565
21566 for (var i = 0; i < bound.length; i++) {
21567 if (bound[i].shift === undefined) {
21568 bound[i].fn(event);
21569 } else if (bound[i].shift == true && event.shiftKey == true) {
21570 bound[i].fn(event);
21571 } else if (bound[i].shift == false && event.shiftKey == false) {
21572 bound[i].fn(event);
21573 }
21574 }
21575
21576 if (preventDefault == true) {
21577 event.preventDefault();
21578 }
21579 }
21580 }; // bind a key to a callback
21581
21582
21583 _exportFunctions.bind = function (key, callback, type) {
21584 if (type === undefined) {
21585 type = 'keydown';
21586 }
21587
21588 if (_keys[key] === undefined) {
21589 throw new Error("unsupported key: " + key);
21590 }
21591
21592 if (_bound[type][_keys[key].code] === undefined) {
21593 _bound[type][_keys[key].code] = [];
21594 }
21595
21596 _bound[type][_keys[key].code].push({
21597 fn: callback,
21598 shift: _keys[key].shift
21599 });
21600 }; // bind all keys to a call back (demo purposes)
21601
21602
21603 _exportFunctions.bindAll = function (callback, type) {
21604 if (type === undefined) {
21605 type = 'keydown';
21606 }
21607
21608 for (var key in _keys) {
21609 if (_keys.hasOwnProperty(key)) {
21610 _exportFunctions.bind(key, callback, type);
21611 }
21612 }
21613 }; // get the key label from an event
21614
21615
21616 _exportFunctions.getKey = function (event) {
21617 for (var key in _keys) {
21618 if (_keys.hasOwnProperty(key)) {
21619 if (event.shiftKey == true && _keys[key].shift == true && event.keyCode == _keys[key].code) {
21620 return key;
21621 } else if (event.shiftKey == false && _keys[key].shift == false && event.keyCode == _keys[key].code) {
21622 return key;
21623 } else if (event.keyCode == _keys[key].code && key == 'shift') {
21624 return key;
21625 }
21626 }
21627 }
21628
21629 return "unknown key, currently not supported";
21630 }; // unbind either a specific callback from a key or all of them (by leaving callback undefined)
21631
21632
21633 _exportFunctions.unbind = function (key, callback, type) {
21634 if (type === undefined) {
21635 type = 'keydown';
21636 }
21637
21638 if (_keys[key] === undefined) {
21639 throw new Error("unsupported key: " + key);
21640 }
21641
21642 if (callback !== undefined) {
21643 var newBindings = [];
21644 var bound = _bound[type][_keys[key].code];
21645
21646 if (bound !== undefined) {
21647 for (var i = 0; i < bound.length; i++) {
21648 if (!(bound[i].fn == callback && bound[i].shift == _keys[key].shift)) {
21649 newBindings.push(_bound[type][_keys[key].code][i]);
21650 }
21651 }
21652 }
21653
21654 _bound[type][_keys[key].code] = newBindings;
21655 } else {
21656 _bound[type][_keys[key].code] = [];
21657 }
21658 }; // reset all bound variables.
21659
21660
21661 _exportFunctions.reset = function () {
21662 _bound = {
21663 keydown: {},
21664 keyup: {}
21665 };
21666 }; // unbind all listeners and reset all variables.
21667
21668
21669 _exportFunctions.destroy = function () {
21670 _bound = {
21671 keydown: {},
21672 keyup: {}
21673 };
21674 container.removeEventListener('keydown', down, true);
21675 container.removeEventListener('keyup', up, true);
21676 }; // create listeners.
21677
21678
21679 container.addEventListener('keydown', down, true);
21680 container.addEventListener('keyup', up, true); // return the public functions.
21681
21682 return _exportFunctions;
21683}
21684
21685var util_1 = esnext$1;
21686var DOMutil = DOMutil$1; // data
21687
21688var DataSet = esnext.DataSet,
21689 DataView = esnext.DataView,
21690 Queue = esnext.Queue;
21691var DataSet_1 = DataSet;
21692var DataView_1 = DataView;
21693var Queue_1 = Queue; // Graph3d
21694
21695var Graph3d = Graph3d$1;
21696var graph3d = {
21697 Camera: Camera,
21698 Filter: Filter,
21699 Point2d: Point2d_1,
21700 Point3d: Point3d_1,
21701 Slider: Slider,
21702 StepNumber: StepNumber_1
21703}; // bundled external libraries
21704
21705var Hammer = esnext$1.Hammer;
21706var keycharm = keycharm$1;
21707var repo = {
21708 util: util_1,
21709 DOMutil: DOMutil,
21710 DataSet: DataSet_1,
21711 DataView: DataView_1,
21712 Queue: Queue_1,
21713 Graph3d: Graph3d,
21714 graph3d: graph3d,
21715 Hammer: Hammer,
21716 keycharm: keycharm
21717};
21718
21719export { DOMutil, DataSet_1 as DataSet, DataView_1 as DataView, Graph3d, Hammer, Queue_1 as Queue, repo as default, graph3d, keycharm, util_1 as util };
21720//# sourceMappingURL=esm.js.map