UNPKG

59.8 kBJavaScriptView Raw
1/*
2 d3plus-common v0.6.61
3 Common functions and methods used across D3plus modules.
4 Copyright (c) 2020 D3plus - https://d3plus.org
5 @license MIT
6*/
7
8(function (factory) {
9 typeof define === 'function' && define.amd ? define(factory) :
10 factory();
11}((function () { 'use strict';
12
13 var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
14
15 function createCommonjsModule(fn, module) {
16 return module = { exports: {} }, fn(module, module.exports), module.exports;
17 }
18
19 var check = function (it) {
20 return it && it.Math == Math && it;
21 };
22
23 // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
24 var global_1 =
25 // eslint-disable-next-line no-undef
26 check(typeof globalThis == 'object' && globalThis) ||
27 check(typeof window == 'object' && window) ||
28 check(typeof self == 'object' && self) ||
29 check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
30 // eslint-disable-next-line no-new-func
31 Function('return this')();
32
33 var fails = function (exec) {
34 try {
35 return !!exec();
36 } catch (error) {
37 return true;
38 }
39 };
40
41 // Thank's IE8 for his funny defineProperty
42 var descriptors = !fails(function () {
43 return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
44 });
45
46 var nativePropertyIsEnumerable = {}.propertyIsEnumerable;
47 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
48
49 // Nashorn ~ JDK8 bug
50 var NASHORN_BUG = getOwnPropertyDescriptor && !nativePropertyIsEnumerable.call({ 1: 2 }, 1);
51
52 // `Object.prototype.propertyIsEnumerable` method implementation
53 // https://tc39.github.io/ecma262/#sec-object.prototype.propertyisenumerable
54 var f = NASHORN_BUG ? function propertyIsEnumerable(V) {
55 var descriptor = getOwnPropertyDescriptor(this, V);
56 return !!descriptor && descriptor.enumerable;
57 } : nativePropertyIsEnumerable;
58
59 var objectPropertyIsEnumerable = {
60 f: f
61 };
62
63 var createPropertyDescriptor = function (bitmap, value) {
64 return {
65 enumerable: !(bitmap & 1),
66 configurable: !(bitmap & 2),
67 writable: !(bitmap & 4),
68 value: value
69 };
70 };
71
72 var toString = {}.toString;
73
74 var classofRaw = function (it) {
75 return toString.call(it).slice(8, -1);
76 };
77
78 var split = ''.split;
79
80 // fallback for non-array-like ES3 and non-enumerable old V8 strings
81 var indexedObject = fails(function () {
82 // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
83 // eslint-disable-next-line no-prototype-builtins
84 return !Object('z').propertyIsEnumerable(0);
85 }) ? function (it) {
86 return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
87 } : Object;
88
89 // `RequireObjectCoercible` abstract operation
90 // https://tc39.github.io/ecma262/#sec-requireobjectcoercible
91 var requireObjectCoercible = function (it) {
92 if (it == undefined) throw TypeError("Can't call method on " + it);
93 return it;
94 };
95
96 // toObject with fallback for non-array-like ES3 strings
97
98
99
100 var toIndexedObject = function (it) {
101 return indexedObject(requireObjectCoercible(it));
102 };
103
104 var isObject = function (it) {
105 return typeof it === 'object' ? it !== null : typeof it === 'function';
106 };
107
108 // `ToPrimitive` abstract operation
109 // https://tc39.github.io/ecma262/#sec-toprimitive
110 // instead of the ES6 spec version, we didn't implement @@toPrimitive case
111 // and the second argument - flag - preferred type is a string
112 var toPrimitive = function (input, PREFERRED_STRING) {
113 if (!isObject(input)) return input;
114 var fn, val;
115 if (PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
116 if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
117 if (!PREFERRED_STRING && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
118 throw TypeError("Can't convert object to primitive value");
119 };
120
121 var hasOwnProperty = {}.hasOwnProperty;
122
123 var has = function (it, key) {
124 return hasOwnProperty.call(it, key);
125 };
126
127 var document$1 = global_1.document;
128 // typeof document.createElement is 'object' in old IE
129 var EXISTS = isObject(document$1) && isObject(document$1.createElement);
130
131 var documentCreateElement = function (it) {
132 return EXISTS ? document$1.createElement(it) : {};
133 };
134
135 // Thank's IE8 for his funny defineProperty
136 var ie8DomDefine = !descriptors && !fails(function () {
137 return Object.defineProperty(documentCreateElement('div'), 'a', {
138 get: function () { return 7; }
139 }).a != 7;
140 });
141
142 var nativeGetOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
143
144 // `Object.getOwnPropertyDescriptor` method
145 // https://tc39.github.io/ecma262/#sec-object.getownpropertydescriptor
146 var f$1 = descriptors ? nativeGetOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
147 O = toIndexedObject(O);
148 P = toPrimitive(P, true);
149 if (ie8DomDefine) try {
150 return nativeGetOwnPropertyDescriptor(O, P);
151 } catch (error) { /* empty */ }
152 if (has(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
153 };
154
155 var objectGetOwnPropertyDescriptor = {
156 f: f$1
157 };
158
159 var anObject = function (it) {
160 if (!isObject(it)) {
161 throw TypeError(String(it) + ' is not an object');
162 } return it;
163 };
164
165 var nativeDefineProperty = Object.defineProperty;
166
167 // `Object.defineProperty` method
168 // https://tc39.github.io/ecma262/#sec-object.defineproperty
169 var f$2 = descriptors ? nativeDefineProperty : function defineProperty(O, P, Attributes) {
170 anObject(O);
171 P = toPrimitive(P, true);
172 anObject(Attributes);
173 if (ie8DomDefine) try {
174 return nativeDefineProperty(O, P, Attributes);
175 } catch (error) { /* empty */ }
176 if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
177 if ('value' in Attributes) O[P] = Attributes.value;
178 return O;
179 };
180
181 var objectDefineProperty = {
182 f: f$2
183 };
184
185 var createNonEnumerableProperty = descriptors ? function (object, key, value) {
186 return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
187 } : function (object, key, value) {
188 object[key] = value;
189 return object;
190 };
191
192 var setGlobal = function (key, value) {
193 try {
194 createNonEnumerableProperty(global_1, key, value);
195 } catch (error) {
196 global_1[key] = value;
197 } return value;
198 };
199
200 var SHARED = '__core-js_shared__';
201 var store = global_1[SHARED] || setGlobal(SHARED, {});
202
203 var sharedStore = store;
204
205 var functionToString = Function.toString;
206
207 // this helper broken in `3.4.1-3.4.4`, so we can't use `shared` helper
208 if (typeof sharedStore.inspectSource != 'function') {
209 sharedStore.inspectSource = function (it) {
210 return functionToString.call(it);
211 };
212 }
213
214 var inspectSource = sharedStore.inspectSource;
215
216 var WeakMap = global_1.WeakMap;
217
218 var nativeWeakMap = typeof WeakMap === 'function' && /native code/.test(inspectSource(WeakMap));
219
220 var shared = createCommonjsModule(function (module) {
221 (module.exports = function (key, value) {
222 return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
223 })('versions', []).push({
224 version: '3.6.5',
225 mode: 'global',
226 copyright: '© 2020 Denis Pushkarev (zloirock.ru)'
227 });
228 });
229
230 var id = 0;
231 var postfix = Math.random();
232
233 var uid = function (key) {
234 return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
235 };
236
237 var keys = shared('keys');
238
239 var sharedKey = function (key) {
240 return keys[key] || (keys[key] = uid(key));
241 };
242
243 var hiddenKeys = {};
244
245 var WeakMap$1 = global_1.WeakMap;
246 var set, get, has$1;
247
248 var enforce = function (it) {
249 return has$1(it) ? get(it) : set(it, {});
250 };
251
252 var getterFor = function (TYPE) {
253 return function (it) {
254 var state;
255 if (!isObject(it) || (state = get(it)).type !== TYPE) {
256 throw TypeError('Incompatible receiver, ' + TYPE + ' required');
257 } return state;
258 };
259 };
260
261 if (nativeWeakMap) {
262 var store$1 = new WeakMap$1();
263 var wmget = store$1.get;
264 var wmhas = store$1.has;
265 var wmset = store$1.set;
266 set = function (it, metadata) {
267 wmset.call(store$1, it, metadata);
268 return metadata;
269 };
270 get = function (it) {
271 return wmget.call(store$1, it) || {};
272 };
273 has$1 = function (it) {
274 return wmhas.call(store$1, it);
275 };
276 } else {
277 var STATE = sharedKey('state');
278 hiddenKeys[STATE] = true;
279 set = function (it, metadata) {
280 createNonEnumerableProperty(it, STATE, metadata);
281 return metadata;
282 };
283 get = function (it) {
284 return has(it, STATE) ? it[STATE] : {};
285 };
286 has$1 = function (it) {
287 return has(it, STATE);
288 };
289 }
290
291 var internalState = {
292 set: set,
293 get: get,
294 has: has$1,
295 enforce: enforce,
296 getterFor: getterFor
297 };
298
299 var redefine = createCommonjsModule(function (module) {
300 var getInternalState = internalState.get;
301 var enforceInternalState = internalState.enforce;
302 var TEMPLATE = String(String).split('String');
303
304 (module.exports = function (O, key, value, options) {
305 var unsafe = options ? !!options.unsafe : false;
306 var simple = options ? !!options.enumerable : false;
307 var noTargetGet = options ? !!options.noTargetGet : false;
308 if (typeof value == 'function') {
309 if (typeof key == 'string' && !has(value, 'name')) createNonEnumerableProperty(value, 'name', key);
310 enforceInternalState(value).source = TEMPLATE.join(typeof key == 'string' ? key : '');
311 }
312 if (O === global_1) {
313 if (simple) O[key] = value;
314 else setGlobal(key, value);
315 return;
316 } else if (!unsafe) {
317 delete O[key];
318 } else if (!noTargetGet && O[key]) {
319 simple = true;
320 }
321 if (simple) O[key] = value;
322 else createNonEnumerableProperty(O, key, value);
323 // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
324 })(Function.prototype, 'toString', function toString() {
325 return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
326 });
327 });
328
329 var path = global_1;
330
331 var aFunction = function (variable) {
332 return typeof variable == 'function' ? variable : undefined;
333 };
334
335 var getBuiltIn = function (namespace, method) {
336 return arguments.length < 2 ? aFunction(path[namespace]) || aFunction(global_1[namespace])
337 : path[namespace] && path[namespace][method] || global_1[namespace] && global_1[namespace][method];
338 };
339
340 var ceil = Math.ceil;
341 var floor = Math.floor;
342
343 // `ToInteger` abstract operation
344 // https://tc39.github.io/ecma262/#sec-tointeger
345 var toInteger = function (argument) {
346 return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor : ceil)(argument);
347 };
348
349 var min = Math.min;
350
351 // `ToLength` abstract operation
352 // https://tc39.github.io/ecma262/#sec-tolength
353 var toLength = function (argument) {
354 return argument > 0 ? min(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
355 };
356
357 var max = Math.max;
358 var min$1 = Math.min;
359
360 // Helper for a popular repeating case of the spec:
361 // Let integer be ? ToInteger(index).
362 // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
363 var toAbsoluteIndex = function (index, length) {
364 var integer = toInteger(index);
365 return integer < 0 ? max(integer + length, 0) : min$1(integer, length);
366 };
367
368 // `Array.prototype.{ indexOf, includes }` methods implementation
369 var createMethod = function (IS_INCLUDES) {
370 return function ($this, el, fromIndex) {
371 var O = toIndexedObject($this);
372 var length = toLength(O.length);
373 var index = toAbsoluteIndex(fromIndex, length);
374 var value;
375 // Array#includes uses SameValueZero equality algorithm
376 // eslint-disable-next-line no-self-compare
377 if (IS_INCLUDES && el != el) while (length > index) {
378 value = O[index++];
379 // eslint-disable-next-line no-self-compare
380 if (value != value) return true;
381 // Array#indexOf ignores holes, Array#includes - not
382 } else for (;length > index; index++) {
383 if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
384 } return !IS_INCLUDES && -1;
385 };
386 };
387
388 var arrayIncludes = {
389 // `Array.prototype.includes` method
390 // https://tc39.github.io/ecma262/#sec-array.prototype.includes
391 includes: createMethod(true),
392 // `Array.prototype.indexOf` method
393 // https://tc39.github.io/ecma262/#sec-array.prototype.indexof
394 indexOf: createMethod(false)
395 };
396
397 var indexOf = arrayIncludes.indexOf;
398
399
400 var objectKeysInternal = function (object, names) {
401 var O = toIndexedObject(object);
402 var i = 0;
403 var result = [];
404 var key;
405 for (key in O) !has(hiddenKeys, key) && has(O, key) && result.push(key);
406 // Don't enum bug & hidden keys
407 while (names.length > i) if (has(O, key = names[i++])) {
408 ~indexOf(result, key) || result.push(key);
409 }
410 return result;
411 };
412
413 // IE8- don't enum bug keys
414 var enumBugKeys = [
415 'constructor',
416 'hasOwnProperty',
417 'isPrototypeOf',
418 'propertyIsEnumerable',
419 'toLocaleString',
420 'toString',
421 'valueOf'
422 ];
423
424 var hiddenKeys$1 = enumBugKeys.concat('length', 'prototype');
425
426 // `Object.getOwnPropertyNames` method
427 // https://tc39.github.io/ecma262/#sec-object.getownpropertynames
428 var f$3 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
429 return objectKeysInternal(O, hiddenKeys$1);
430 };
431
432 var objectGetOwnPropertyNames = {
433 f: f$3
434 };
435
436 var f$4 = Object.getOwnPropertySymbols;
437
438 var objectGetOwnPropertySymbols = {
439 f: f$4
440 };
441
442 // all object keys, includes non-enumerable and symbols
443 var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
444 var keys = objectGetOwnPropertyNames.f(anObject(it));
445 var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
446 return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
447 };
448
449 var copyConstructorProperties = function (target, source) {
450 var keys = ownKeys(source);
451 var defineProperty = objectDefineProperty.f;
452 var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
453 for (var i = 0; i < keys.length; i++) {
454 var key = keys[i];
455 if (!has(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
456 }
457 };
458
459 var replacement = /#|\.prototype\./;
460
461 var isForced = function (feature, detection) {
462 var value = data[normalize(feature)];
463 return value == POLYFILL ? true
464 : value == NATIVE ? false
465 : typeof detection == 'function' ? fails(detection)
466 : !!detection;
467 };
468
469 var normalize = isForced.normalize = function (string) {
470 return String(string).replace(replacement, '.').toLowerCase();
471 };
472
473 var data = isForced.data = {};
474 var NATIVE = isForced.NATIVE = 'N';
475 var POLYFILL = isForced.POLYFILL = 'P';
476
477 var isForced_1 = isForced;
478
479 var getOwnPropertyDescriptor$1 = objectGetOwnPropertyDescriptor.f;
480
481
482
483
484
485
486 /*
487 options.target - name of the target object
488 options.global - target is the global object
489 options.stat - export as static methods of target
490 options.proto - export as prototype methods of target
491 options.real - real prototype method for the `pure` version
492 options.forced - export even if the native feature is available
493 options.bind - bind methods to the target, required for the `pure` version
494 options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
495 options.unsafe - use the simple assignment of property instead of delete + defineProperty
496 options.sham - add a flag to not completely full polyfills
497 options.enumerable - export as enumerable property
498 options.noTargetGet - prevent calling a getter on target
499 */
500 var _export = function (options, source) {
501 var TARGET = options.target;
502 var GLOBAL = options.global;
503 var STATIC = options.stat;
504 var FORCED, target, key, targetProperty, sourceProperty, descriptor;
505 if (GLOBAL) {
506 target = global_1;
507 } else if (STATIC) {
508 target = global_1[TARGET] || setGlobal(TARGET, {});
509 } else {
510 target = (global_1[TARGET] || {}).prototype;
511 }
512 if (target) for (key in source) {
513 sourceProperty = source[key];
514 if (options.noTargetGet) {
515 descriptor = getOwnPropertyDescriptor$1(target, key);
516 targetProperty = descriptor && descriptor.value;
517 } else targetProperty = target[key];
518 FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
519 // contained in target
520 if (!FORCED && targetProperty !== undefined) {
521 if (typeof sourceProperty === typeof targetProperty) continue;
522 copyConstructorProperties(sourceProperty, targetProperty);
523 }
524 // add a flag to not completely full polyfills
525 if (options.sham || (targetProperty && targetProperty.sham)) {
526 createNonEnumerableProperty(sourceProperty, 'sham', true);
527 }
528 // extend global
529 redefine(target, key, sourceProperty, options);
530 }
531 };
532
533 var aFunction$1 = function (it) {
534 if (typeof it != 'function') {
535 throw TypeError(String(it) + ' is not a function');
536 } return it;
537 };
538
539 // optional / simple context binding
540 var functionBindContext = function (fn, that, length) {
541 aFunction$1(fn);
542 if (that === undefined) return fn;
543 switch (length) {
544 case 0: return function () {
545 return fn.call(that);
546 };
547 case 1: return function (a) {
548 return fn.call(that, a);
549 };
550 case 2: return function (a, b) {
551 return fn.call(that, a, b);
552 };
553 case 3: return function (a, b, c) {
554 return fn.call(that, a, b, c);
555 };
556 }
557 return function (/* ...args */) {
558 return fn.apply(that, arguments);
559 };
560 };
561
562 // `ToObject` abstract operation
563 // https://tc39.github.io/ecma262/#sec-toobject
564 var toObject = function (argument) {
565 return Object(requireObjectCoercible(argument));
566 };
567
568 // `IsArray` abstract operation
569 // https://tc39.github.io/ecma262/#sec-isarray
570 var isArray = Array.isArray || function isArray(arg) {
571 return classofRaw(arg) == 'Array';
572 };
573
574 var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
575 // Chrome 38 Symbol has incorrect toString conversion
576 // eslint-disable-next-line no-undef
577 return !String(Symbol());
578 });
579
580 var useSymbolAsUid = nativeSymbol
581 // eslint-disable-next-line no-undef
582 && !Symbol.sham
583 // eslint-disable-next-line no-undef
584 && typeof Symbol.iterator == 'symbol';
585
586 var WellKnownSymbolsStore = shared('wks');
587 var Symbol$1 = global_1.Symbol;
588 var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
589
590 var wellKnownSymbol = function (name) {
591 if (!has(WellKnownSymbolsStore, name)) {
592 if (nativeSymbol && has(Symbol$1, name)) WellKnownSymbolsStore[name] = Symbol$1[name];
593 else WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
594 } return WellKnownSymbolsStore[name];
595 };
596
597 var SPECIES = wellKnownSymbol('species');
598
599 // `ArraySpeciesCreate` abstract operation
600 // https://tc39.github.io/ecma262/#sec-arrayspeciescreate
601 var arraySpeciesCreate = function (originalArray, length) {
602 var C;
603 if (isArray(originalArray)) {
604 C = originalArray.constructor;
605 // cross-realm fallback
606 if (typeof C == 'function' && (C === Array || isArray(C.prototype))) C = undefined;
607 else if (isObject(C)) {
608 C = C[SPECIES];
609 if (C === null) C = undefined;
610 }
611 } return new (C === undefined ? Array : C)(length === 0 ? 0 : length);
612 };
613
614 var push = [].push;
615
616 // `Array.prototype.{ forEach, map, filter, some, every, find, findIndex }` methods implementation
617 var createMethod$1 = function (TYPE) {
618 var IS_MAP = TYPE == 1;
619 var IS_FILTER = TYPE == 2;
620 var IS_SOME = TYPE == 3;
621 var IS_EVERY = TYPE == 4;
622 var IS_FIND_INDEX = TYPE == 6;
623 var NO_HOLES = TYPE == 5 || IS_FIND_INDEX;
624 return function ($this, callbackfn, that, specificCreate) {
625 var O = toObject($this);
626 var self = indexedObject(O);
627 var boundFunction = functionBindContext(callbackfn, that, 3);
628 var length = toLength(self.length);
629 var index = 0;
630 var create = specificCreate || arraySpeciesCreate;
631 var target = IS_MAP ? create($this, length) : IS_FILTER ? create($this, 0) : undefined;
632 var value, result;
633 for (;length > index; index++) if (NO_HOLES || index in self) {
634 value = self[index];
635 result = boundFunction(value, index, O);
636 if (TYPE) {
637 if (IS_MAP) target[index] = result; // map
638 else if (result) switch (TYPE) {
639 case 3: return true; // some
640 case 5: return value; // find
641 case 6: return index; // findIndex
642 case 2: push.call(target, value); // filter
643 } else if (IS_EVERY) return false; // every
644 }
645 }
646 return IS_FIND_INDEX ? -1 : IS_SOME || IS_EVERY ? IS_EVERY : target;
647 };
648 };
649
650 var arrayIteration = {
651 // `Array.prototype.forEach` method
652 // https://tc39.github.io/ecma262/#sec-array.prototype.foreach
653 forEach: createMethod$1(0),
654 // `Array.prototype.map` method
655 // https://tc39.github.io/ecma262/#sec-array.prototype.map
656 map: createMethod$1(1),
657 // `Array.prototype.filter` method
658 // https://tc39.github.io/ecma262/#sec-array.prototype.filter
659 filter: createMethod$1(2),
660 // `Array.prototype.some` method
661 // https://tc39.github.io/ecma262/#sec-array.prototype.some
662 some: createMethod$1(3),
663 // `Array.prototype.every` method
664 // https://tc39.github.io/ecma262/#sec-array.prototype.every
665 every: createMethod$1(4),
666 // `Array.prototype.find` method
667 // https://tc39.github.io/ecma262/#sec-array.prototype.find
668 find: createMethod$1(5),
669 // `Array.prototype.findIndex` method
670 // https://tc39.github.io/ecma262/#sec-array.prototype.findIndex
671 findIndex: createMethod$1(6)
672 };
673
674 // `Object.keys` method
675 // https://tc39.github.io/ecma262/#sec-object.keys
676 var objectKeys = Object.keys || function keys(O) {
677 return objectKeysInternal(O, enumBugKeys);
678 };
679
680 // `Object.defineProperties` method
681 // https://tc39.github.io/ecma262/#sec-object.defineproperties
682 var objectDefineProperties = descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
683 anObject(O);
684 var keys = objectKeys(Properties);
685 var length = keys.length;
686 var index = 0;
687 var key;
688 while (length > index) objectDefineProperty.f(O, key = keys[index++], Properties[key]);
689 return O;
690 };
691
692 var html = getBuiltIn('document', 'documentElement');
693
694 var GT = '>';
695 var LT = '<';
696 var PROTOTYPE = 'prototype';
697 var SCRIPT = 'script';
698 var IE_PROTO = sharedKey('IE_PROTO');
699
700 var EmptyConstructor = function () { /* empty */ };
701
702 var scriptTag = function (content) {
703 return LT + SCRIPT + GT + content + LT + '/' + SCRIPT + GT;
704 };
705
706 // Create object with fake `null` prototype: use ActiveX Object with cleared prototype
707 var NullProtoObjectViaActiveX = function (activeXDocument) {
708 activeXDocument.write(scriptTag(''));
709 activeXDocument.close();
710 var temp = activeXDocument.parentWindow.Object;
711 activeXDocument = null; // avoid memory leak
712 return temp;
713 };
714
715 // Create object with fake `null` prototype: use iframe Object with cleared prototype
716 var NullProtoObjectViaIFrame = function () {
717 // Thrash, waste and sodomy: IE GC bug
718 var iframe = documentCreateElement('iframe');
719 var JS = 'java' + SCRIPT + ':';
720 var iframeDocument;
721 iframe.style.display = 'none';
722 html.appendChild(iframe);
723 // https://github.com/zloirock/core-js/issues/475
724 iframe.src = String(JS);
725 iframeDocument = iframe.contentWindow.document;
726 iframeDocument.open();
727 iframeDocument.write(scriptTag('document.F=Object'));
728 iframeDocument.close();
729 return iframeDocument.F;
730 };
731
732 // Check for document.domain and active x support
733 // No need to use active x approach when document.domain is not set
734 // see https://github.com/es-shims/es5-shim/issues/150
735 // variation of https://github.com/kitcambridge/es5-shim/commit/4f738ac066346
736 // avoid IE GC bug
737 var activeXDocument;
738 var NullProtoObject = function () {
739 try {
740 /* global ActiveXObject */
741 activeXDocument = document.domain && new ActiveXObject('htmlfile');
742 } catch (error) { /* ignore */ }
743 NullProtoObject = activeXDocument ? NullProtoObjectViaActiveX(activeXDocument) : NullProtoObjectViaIFrame();
744 var length = enumBugKeys.length;
745 while (length--) delete NullProtoObject[PROTOTYPE][enumBugKeys[length]];
746 return NullProtoObject();
747 };
748
749 hiddenKeys[IE_PROTO] = true;
750
751 // `Object.create` method
752 // https://tc39.github.io/ecma262/#sec-object.create
753 var objectCreate = Object.create || function create(O, Properties) {
754 var result;
755 if (O !== null) {
756 EmptyConstructor[PROTOTYPE] = anObject(O);
757 result = new EmptyConstructor();
758 EmptyConstructor[PROTOTYPE] = null;
759 // add "__proto__" for Object.getPrototypeOf polyfill
760 result[IE_PROTO] = O;
761 } else result = NullProtoObject();
762 return Properties === undefined ? result : objectDefineProperties(result, Properties);
763 };
764
765 var UNSCOPABLES = wellKnownSymbol('unscopables');
766 var ArrayPrototype = Array.prototype;
767
768 // Array.prototype[@@unscopables]
769 // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
770 if (ArrayPrototype[UNSCOPABLES] == undefined) {
771 objectDefineProperty.f(ArrayPrototype, UNSCOPABLES, {
772 configurable: true,
773 value: objectCreate(null)
774 });
775 }
776
777 // add a key to Array.prototype[@@unscopables]
778 var addToUnscopables = function (key) {
779 ArrayPrototype[UNSCOPABLES][key] = true;
780 };
781
782 var defineProperty = Object.defineProperty;
783 var cache = {};
784
785 var thrower = function (it) { throw it; };
786
787 var arrayMethodUsesToLength = function (METHOD_NAME, options) {
788 if (has(cache, METHOD_NAME)) return cache[METHOD_NAME];
789 if (!options) options = {};
790 var method = [][METHOD_NAME];
791 var ACCESSORS = has(options, 'ACCESSORS') ? options.ACCESSORS : false;
792 var argument0 = has(options, 0) ? options[0] : thrower;
793 var argument1 = has(options, 1) ? options[1] : undefined;
794
795 return cache[METHOD_NAME] = !!method && !fails(function () {
796 if (ACCESSORS && !descriptors) return true;
797 var O = { length: -1 };
798
799 if (ACCESSORS) defineProperty(O, 1, { enumerable: true, get: thrower });
800 else O[1] = 1;
801
802 method.call(O, argument0, argument1);
803 });
804 };
805
806 var $find = arrayIteration.find;
807
808
809
810 var FIND = 'find';
811 var SKIPS_HOLES = true;
812
813 var USES_TO_LENGTH = arrayMethodUsesToLength(FIND);
814
815 // Shouldn't skip holes
816 if (FIND in []) Array(1)[FIND](function () { SKIPS_HOLES = false; });
817
818 // `Array.prototype.find` method
819 // https://tc39.github.io/ecma262/#sec-array.prototype.find
820 _export({ target: 'Array', proto: true, forced: SKIPS_HOLES || !USES_TO_LENGTH }, {
821 find: function find(callbackfn /* , that = undefined */) {
822 return $find(this, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
823 }
824 });
825
826 // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
827 addToUnscopables(FIND);
828
829 var $includes = arrayIncludes.includes;
830
831
832
833 var USES_TO_LENGTH$1 = arrayMethodUsesToLength('indexOf', { ACCESSORS: true, 1: 0 });
834
835 // `Array.prototype.includes` method
836 // https://tc39.github.io/ecma262/#sec-array.prototype.includes
837 _export({ target: 'Array', proto: true, forced: !USES_TO_LENGTH$1 }, {
838 includes: function includes(el /* , fromIndex = 0 */) {
839 return $includes(this, el, arguments.length > 1 ? arguments[1] : undefined);
840 }
841 });
842
843 // https://tc39.github.io/ecma262/#sec-array.prototype-@@unscopables
844 addToUnscopables('includes');
845
846 var nativeAssign = Object.assign;
847 var defineProperty$1 = Object.defineProperty;
848
849 // `Object.assign` method
850 // https://tc39.github.io/ecma262/#sec-object.assign
851 var objectAssign = !nativeAssign || fails(function () {
852 // should have correct order of operations (Edge bug)
853 if (descriptors && nativeAssign({ b: 1 }, nativeAssign(defineProperty$1({}, 'a', {
854 enumerable: true,
855 get: function () {
856 defineProperty$1(this, 'b', {
857 value: 3,
858 enumerable: false
859 });
860 }
861 }), { b: 2 })).b !== 1) return true;
862 // should work with symbols and should have deterministic property order (V8 bug)
863 var A = {};
864 var B = {};
865 // eslint-disable-next-line no-undef
866 var symbol = Symbol();
867 var alphabet = 'abcdefghijklmnopqrst';
868 A[symbol] = 7;
869 alphabet.split('').forEach(function (chr) { B[chr] = chr; });
870 return nativeAssign({}, A)[symbol] != 7 || objectKeys(nativeAssign({}, B)).join('') != alphabet;
871 }) ? function assign(target, source) { // eslint-disable-line no-unused-vars
872 var T = toObject(target);
873 var argumentsLength = arguments.length;
874 var index = 1;
875 var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
876 var propertyIsEnumerable = objectPropertyIsEnumerable.f;
877 while (argumentsLength > index) {
878 var S = indexedObject(arguments[index++]);
879 var keys = getOwnPropertySymbols ? objectKeys(S).concat(getOwnPropertySymbols(S)) : objectKeys(S);
880 var length = keys.length;
881 var j = 0;
882 var key;
883 while (length > j) {
884 key = keys[j++];
885 if (!descriptors || propertyIsEnumerable.call(S, key)) T[key] = S[key];
886 }
887 } return T;
888 } : nativeAssign;
889
890 // `Object.assign` method
891 // https://tc39.github.io/ecma262/#sec-object.assign
892 _export({ target: 'Object', stat: true, forced: Object.assign !== objectAssign }, {
893 assign: objectAssign
894 });
895
896 var MATCH = wellKnownSymbol('match');
897
898 // `IsRegExp` abstract operation
899 // https://tc39.github.io/ecma262/#sec-isregexp
900 var isRegexp = function (it) {
901 var isRegExp;
902 return isObject(it) && ((isRegExp = it[MATCH]) !== undefined ? !!isRegExp : classofRaw(it) == 'RegExp');
903 };
904
905 var notARegexp = function (it) {
906 if (isRegexp(it)) {
907 throw TypeError("The method doesn't accept regular expressions");
908 } return it;
909 };
910
911 var MATCH$1 = wellKnownSymbol('match');
912
913 var correctIsRegexpLogic = function (METHOD_NAME) {
914 var regexp = /./;
915 try {
916 '/./'[METHOD_NAME](regexp);
917 } catch (e) {
918 try {
919 regexp[MATCH$1] = false;
920 return '/./'[METHOD_NAME](regexp);
921 } catch (f) { /* empty */ }
922 } return false;
923 };
924
925 // `String.prototype.includes` method
926 // https://tc39.github.io/ecma262/#sec-string.prototype.includes
927 _export({ target: 'String', proto: true, forced: !correctIsRegexpLogic('includes') }, {
928 includes: function includes(searchString /* , position = 0 */) {
929 return !!~String(requireObjectCoercible(this))
930 .indexOf(notARegexp(searchString), arguments.length > 1 ? arguments[1] : undefined);
931 }
932 });
933
934 var getOwnPropertyDescriptor$2 = objectGetOwnPropertyDescriptor.f;
935
936
937
938
939
940
941 var nativeStartsWith = ''.startsWith;
942 var min$2 = Math.min;
943
944 var CORRECT_IS_REGEXP_LOGIC = correctIsRegexpLogic('startsWith');
945 // https://github.com/zloirock/core-js/pull/702
946 var MDN_POLYFILL_BUG = !CORRECT_IS_REGEXP_LOGIC && !!function () {
947 var descriptor = getOwnPropertyDescriptor$2(String.prototype, 'startsWith');
948 return descriptor && !descriptor.writable;
949 }();
950
951 // `String.prototype.startsWith` method
952 // https://tc39.github.io/ecma262/#sec-string.prototype.startswith
953 _export({ target: 'String', proto: true, forced: !MDN_POLYFILL_BUG && !CORRECT_IS_REGEXP_LOGIC }, {
954 startsWith: function startsWith(searchString /* , position = 0 */) {
955 var that = String(requireObjectCoercible(this));
956 notARegexp(searchString);
957 var index = toLength(min$2(arguments.length > 1 ? arguments[1] : undefined, that.length));
958 var search = String(searchString);
959 return nativeStartsWith
960 ? nativeStartsWith.call(that, search, index)
961 : that.slice(index, index + search.length) === search;
962 }
963 });
964
965 if (typeof window !== "undefined") {
966 (function () {
967 var serializeXML = function (node, output) {
968 var nodeType = node.nodeType;
969 if (nodeType === 3) {
970 output.push(node.textContent.replace(/&/, '&amp;').replace(/</, '&lt;').replace('>', '&gt;'));
971 } else if (nodeType === 1) {
972 output.push('<', node.tagName);
973 if (node.hasAttributes()) {
974 [].forEach.call(node.attributes, function(attrNode){
975 output.push(' ', attrNode.item.name, '=\'', attrNode.item.value, '\'');
976 });
977 }
978 if (node.hasChildNodes()) {
979 output.push('>');
980 [].forEach.call(node.childNodes, function(childNode){
981 serializeXML(childNode, output);
982 });
983 output.push('</', node.tagName, '>');
984 } else {
985 output.push('/>');
986 }
987 } else if (nodeType == 8) {
988 output.push('<!--', node.nodeValue, '-->');
989 }
990 };
991
992 Object.defineProperty(SVGElement.prototype, 'innerHTML', {
993 get: function () {
994 var output = [];
995 var childNode = this.firstChild;
996 while (childNode) {
997 serializeXML(childNode, output);
998 childNode = childNode.nextSibling;
999 }
1000 return output.join('');
1001 },
1002 set: function (markupText) {
1003 while (this.firstChild) {
1004 this.removeChild(this.firstChild);
1005 }
1006
1007 try {
1008 var dXML = new DOMParser();
1009 dXML.async = false;
1010
1011 var sXML = '<svg xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'>' + markupText + '</svg>';
1012 var svgDocElement = dXML.parseFromString(sXML, 'text/xml').documentElement;
1013
1014 var childNode = svgDocElement.firstChild;
1015 while (childNode) {
1016 this.appendChild(this.ownerDocument.importNode(childNode, true));
1017 childNode = childNode.nextSibling;
1018 }
1019 } catch (e) {} }
1020 });
1021
1022 Object.defineProperty(SVGElement.prototype, 'innerSVG', {
1023 get: function () {
1024 return this.innerHTML;
1025 },
1026 set: function (markup) {
1027 this.innerHTML = markup;
1028 }
1029 });
1030
1031 })();
1032 }
1033
1034})));
1035
1036(function (global, factory) {
1037 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('windows-locale'), require('iso639-codes'), require('d3-selection'), require('d3-transition'), require('d3-array'), require('d3-collection')) :
1038 typeof define === 'function' && define.amd ? define('d3plus-common', ['exports', 'windows-locale', 'iso639-codes', 'd3-selection', 'd3-transition', 'd3-array', 'd3-collection'], factory) :
1039 (global = global || self, factory(global.d3plus = {}, global.lcid, global.iso, global.d3Selection, global.d3Transition, global.d3Array, global.d3Collection));
1040}(this, (function (exports, lcid, iso, d3Selection, d3Transition, d3Array, d3Collection) { 'use strict';
1041
1042 lcid = lcid && Object.prototype.hasOwnProperty.call(lcid, 'default') ? lcid['default'] : lcid;
1043 iso = iso && Object.prototype.hasOwnProperty.call(iso, 'default') ? iso['default'] : iso;
1044
1045 /**
1046 @function accessor
1047 @desc Wraps an object key in a simple accessor function.
1048 @param {String} key The key to be returned from each Object passed to the function.
1049 @param {*} [def] A default value to be returned if the key is not present.
1050 @example <caption>this</caption>
1051 accessor("id");
1052 @example <caption>returns this</caption>
1053 function(d) {
1054 return d["id"];
1055 }
1056 */
1057 function accessor (key, def) {
1058 if (def === void 0) return function (d) {
1059 return d[key];
1060 };
1061 return function (d) {
1062 return d[key] === void 0 ? def : d[key];
1063 };
1064 }
1065
1066 function _typeof(obj) {
1067 "@babel/helpers - typeof";
1068
1069 if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1070 _typeof = function (obj) {
1071 return typeof obj;
1072 };
1073 } else {
1074 _typeof = function (obj) {
1075 return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
1076 };
1077 }
1078
1079 return _typeof(obj);
1080 }
1081
1082 function _classCallCheck(instance, Constructor) {
1083 if (!(instance instanceof Constructor)) {
1084 throw new TypeError("Cannot call a class as a function");
1085 }
1086 }
1087
1088 function _defineProperties(target, props) {
1089 for (var i = 0; i < props.length; i++) {
1090 var descriptor = props[i];
1091 descriptor.enumerable = descriptor.enumerable || false;
1092 descriptor.configurable = true;
1093 if ("value" in descriptor) descriptor.writable = true;
1094 Object.defineProperty(target, descriptor.key, descriptor);
1095 }
1096 }
1097
1098 function _createClass(Constructor, protoProps, staticProps) {
1099 if (protoProps) _defineProperties(Constructor.prototype, protoProps);
1100 if (staticProps) _defineProperties(Constructor, staticProps);
1101 return Constructor;
1102 }
1103
1104 function _defineProperty(obj, key, value) {
1105 if (key in obj) {
1106 Object.defineProperty(obj, key, {
1107 value: value,
1108 enumerable: true,
1109 configurable: true,
1110 writable: true
1111 });
1112 } else {
1113 obj[key] = value;
1114 }
1115
1116 return obj;
1117 }
1118
1119 /**
1120 @function isObject
1121 @desc Detects if a variable is a javascript Object.
1122 @param {*} item
1123 */
1124 function isObject (item) {
1125 return item && _typeof(item) === "object" && (typeof window === "undefined" || item !== window && item !== window.document && !(item instanceof Element)) && !Array.isArray(item) ? true : false;
1126 }
1127
1128 /**
1129 @function validObject
1130 @desc Determines if the object passed is the document or window.
1131 @param {Object} obj
1132 @private
1133 */
1134
1135 function validObject(obj) {
1136 if (typeof window === "undefined") return true;else return obj !== window && obj !== document;
1137 }
1138 /**
1139 @function assign
1140 @desc A deeply recursive version of `Object.assign`.
1141 @param {...Object} objects
1142 @example <caption>this</caption>
1143 assign({id: "foo", deep: {group: "A"}}, {id: "bar", deep: {value: 20}}));
1144 @example <caption>returns this</caption>
1145 {id: "bar", deep: {group: "A", value: 20}}
1146 */
1147
1148
1149 function assign() {
1150 var _arguments = arguments;
1151 var target = arguments.length <= 0 ? undefined : arguments[0];
1152
1153 var _loop = function _loop(i) {
1154 var source = i < 0 || _arguments.length <= i ? undefined : _arguments[i];
1155 Object.keys(source).forEach(function (prop) {
1156 var value = source[prop];
1157
1158 if (isObject(value) && validObject(value)) {
1159 if (target.hasOwnProperty(prop) && isObject(target[prop])) target[prop] = assign({}, target[prop], value);else target[prop] = assign({}, value);
1160 } else if (Array.isArray(value)) target[prop] = value.slice();else target[prop] = value;
1161 });
1162 };
1163
1164 for (var i = 1; i < arguments.length; i++) {
1165 _loop(i);
1166 }
1167
1168 return target;
1169 }
1170
1171 /**
1172 @function attrize
1173 @desc Applies each key/value in an object as an attr.
1174 @param {D3selection} elem The D3 element to apply the styles to.
1175 @param {Object} attrs An object of key/value attr pairs.
1176 */
1177 function attrize (e) {
1178 var a = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1179
1180 for (var k in a) {
1181 if ({}.hasOwnProperty.call(a, k)) e.attr(k, a[k]);
1182 }
1183 }
1184
1185 var locales = [];
1186 var isoKeys = Object.keys(iso);
1187 Object.keys(lcid).map(function (id) {
1188 var locale = lcid[id];
1189 var isoLanguage = isoKeys.find(function (name) {
1190 return name.toLowerCase() === locale.language.toLowerCase();
1191 });
1192
1193 if (locale.location && isoLanguage) {
1194 var _locales$push;
1195
1196 locales.push((_locales$push = {}, _defineProperty(_locales$push, "name", locale.language), _defineProperty(_locales$push, "location", locale.location), _defineProperty(_locales$push, "tag", locale.tag), _defineProperty(_locales$push, "lcid", locale.id), _defineProperty(_locales$push, "iso639-2", iso[isoLanguage]["iso639-2"]), _defineProperty(_locales$push, "iso639-1", iso[isoLanguage]["iso639-1"]), _locales$push));
1197 }
1198 });
1199 var defaultLocales = {
1200 ar: "ar-SA",
1201 ca: "ca-ES",
1202 da: "da-DK",
1203 en: "en-US",
1204 ko: "ko-KR",
1205 pa: "pa-IN",
1206 pt: "pt-BR",
1207 sv: "sv-SE"
1208 };
1209 /**
1210 * Converts a 2-digit language into a full language-LOCATION locale.
1211 * @param {String} locale
1212 */
1213
1214 function findLocale (locale) {
1215 if (typeof locale !== "string" || locale.length === 5) return locale;
1216 if (defaultLocales[locale]) return defaultLocales[locale];
1217 var list = locales.filter(function (d) {
1218 return d["iso639-1"] === locale;
1219 });
1220 if (!list.length) return locale;else if (list.length === 1) return list[0].tag;else if (list.find(function (d) {
1221 return d.tag === "".concat(locale, "-").concat(locale.toUpperCase());
1222 })) return "".concat(locale, "-").concat(locale.toUpperCase());else return list[0].tag;
1223 }
1224
1225 /**
1226 @function s
1227 @desc Returns 4 random characters, used for constructing unique identifiers.
1228 @private
1229 */
1230 function s() {
1231 return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
1232 }
1233 /**
1234 @function uuid
1235 @summary Returns a unique identifier.
1236 */
1237
1238
1239 function uuid () {
1240 return "".concat(s()).concat(s(), "-").concat(s(), "-").concat(s(), "-").concat(s(), "-").concat(s()).concat(s()).concat(s());
1241 }
1242
1243 /**
1244 @constant RESET
1245 @desc String constant used to reset an individual config property.
1246 */
1247 var RESET = "D3PLUS-COMMON-RESET";
1248
1249 var esES = {
1250 "and": "y",
1251 "Back": "Atrás",
1252 "Click to Expand": "Clic para Ampliar",
1253 "Click to Hide": "Clic para Ocultar",
1254 "Click to Highlight": "Clic para Resaltar",
1255 "Click to Reset": "Clic para Restablecer",
1256 "Download": "Descargar",
1257 "Loading Visualization": "Cargando Visualización",
1258 "No Data Available": "Datos No Disponibles",
1259 "Powered by D3plus": "Funciona con D3plus",
1260 "Share": "Porcentaje",
1261 "Shift+Click to Hide": "Mayús+Clic para Ocultar",
1262 "Total": "Total",
1263 "Values": "Valores"
1264 };
1265
1266 var dictionaries = {
1267 "es-ES": esES
1268 };
1269
1270 /**
1271 @desc Recursive function that resets nested Object configs.
1272 @param {Object} obj
1273 @param {Object} defaults
1274 @private
1275 */
1276
1277 function nestedReset(obj, defaults) {
1278 if (isObject(obj)) {
1279 for (var nestedKey in obj) {
1280 if ({}.hasOwnProperty.call(obj, nestedKey) && !nestedKey.startsWith("_")) {
1281 var defaultValue = defaults && isObject(defaults) ? defaults[nestedKey] : undefined;
1282
1283 if (obj[nestedKey] === RESET) {
1284 if (defaultValue) obj[nestedKey] = defaultValue;else delete obj[nestedKey];
1285 } else if (isObject(obj[nestedKey])) {
1286 nestedReset(obj[nestedKey], defaultValue);
1287 }
1288 }
1289 }
1290 }
1291 }
1292 /**
1293 * @desc finds all prototype methods of a class and it's parent classes
1294 * @param {*} obj
1295 * @private
1296 */
1297
1298
1299 function getAllMethods(obj) {
1300 var props = [];
1301
1302 do {
1303 props = props.concat(Object.getOwnPropertyNames(obj));
1304 obj = Object.getPrototypeOf(obj);
1305 } while (obj && obj !== Object.prototype);
1306
1307 return props.filter(function (e) {
1308 return e.indexOf("_") !== 0 && !["config", "constructor", "parent", "render"].includes(e);
1309 });
1310 }
1311 /**
1312 @class BaseClass
1313 @summary An abstract class that contains some global methods and functionality.
1314 */
1315
1316
1317 var BaseClass = /*#__PURE__*/function () {
1318 /**
1319 @memberof BaseClass
1320 @desc Invoked when creating a new class instance, and sets any default parameters.
1321 @private
1322 */
1323 function BaseClass() {
1324 var _this = this;
1325
1326 _classCallCheck(this, BaseClass);
1327
1328 this._locale = "en-US";
1329 this._on = {};
1330 this._parent = {};
1331
1332 this._translate = function (d) {
1333 var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _this._locale;
1334 var dictionary = dictionaries[locale];
1335 return dictionary && dictionary[d] ? dictionary[d] : d;
1336 };
1337
1338 this._uuid = uuid();
1339 }
1340 /**
1341 @memberof BaseClass
1342 @desc If *value* is specified, sets the methods that correspond to the key/value pairs and returns this class. If *value* is not specified, returns the current configuration.
1343 @param {Object} [*value*]
1344 @chainable
1345 */
1346
1347
1348 _createClass(BaseClass, [{
1349 key: "config",
1350 value: function config(_) {
1351 var _this2 = this;
1352
1353 if (!this._configDefault) {
1354 var config = {};
1355 getAllMethods(this.__proto__).forEach(function (k) {
1356 var v = _this2[k]();
1357
1358 if (v !== _this2) config[k] = isObject(v) ? assign({}, v) : v;
1359 });
1360 this._configDefault = config;
1361 }
1362
1363 if (arguments.length) {
1364 for (var k in _) {
1365 if ({}.hasOwnProperty.call(_, k) && k in this) {
1366 var v = _[k];
1367
1368 if (v === RESET) {
1369 if (k === "on") this._on = this._configDefault[k];else this[k](this._configDefault[k]);
1370 } else {
1371 nestedReset(v, this._configDefault[k]);
1372 this[k](v);
1373 }
1374 }
1375 }
1376
1377 return this;
1378 } else {
1379 var _config = {};
1380 getAllMethods(this.__proto__).forEach(function (k) {
1381 _config[k] = _this2[k]();
1382 });
1383 return _config;
1384 }
1385 }
1386 /**
1387 @memberof BaseClass
1388 @desc Sets the locale used for all text and number formatting. This method supports the locales defined in [d3plus-format](https://github.com/d3plus/d3plus-format/blob/master/src/locale.js). The locale can be defined as a complex Object (like in d3plus-format), a locale code (like "en-US"), or a 2-digit language code (like "en"). If a 2-digit code is provided, the "findLocale" function is used to identify the most approximate locale from d3plus-format.
1389 @param {Object|String} [*value* = "en-US"]
1390 @chainable
1391 @example
1392 {
1393 separator: "",
1394 suffixes: ["y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "B", "t", "q", "Q", "Z", "Y"],
1395 grouping: [3],
1396 delimiters: {
1397 thousands: ",",
1398 decimal: "."
1399 },
1400 currency: ["$", ""]
1401 }
1402 */
1403
1404 }, {
1405 key: "locale",
1406 value: function locale(_) {
1407 return arguments.length ? (this._locale = findLocale(_), this) : this._locale;
1408 }
1409 /**
1410 @memberof BaseClass
1411 @desc Adds or removes a *listener* to each object for the specified event *typenames*. If a *listener* is not specified, returns the currently assigned listener for the specified event *typename*. Mirrors the core [d3-selection](https://github.com/d3/d3-selection#selection_on) behavior.
1412 @param {String} [*typenames*]
1413 @param {Function} [*listener*]
1414 @chainable
1415 @example <caption>By default, listeners apply globally to all objects, however, passing a namespace with the class name gives control over specific elements:</caption>
1416 new Plot
1417 .on("click.Shape", function(d) {
1418 console.log("data for shape clicked:", d);
1419 })
1420 .on("click.Legend", function(d) {
1421 console.log("data for legend clicked:", d);
1422 })
1423 */
1424
1425 }, {
1426 key: "on",
1427 value: function on(_, f) {
1428 return arguments.length === 2 ? (this._on[_] = f, this) : arguments.length ? typeof _ === "string" ? this._on[_] : (this._on = Object.assign({}, this._on, _), this) : this._on;
1429 }
1430 /**
1431 @memberof Viz
1432 @desc If *value* is specified, sets the parent config used by the wrapper and returns the current class instance.
1433 @param {Object} [*value*]
1434 @chainable
1435 */
1436
1437 }, {
1438 key: "parent",
1439 value: function parent(_) {
1440 return arguments.length ? (this._parent = _, this) : this._parent;
1441 }
1442 /**
1443 @memberof BaseClass
1444 @desc Defines how informational text strings should be displayed. By default, this function will try to find the string in question (which is the first argument provided to this function) inside of an internally managed translation Object. If you'd like to override to use custom text, simply pass this method your own custom formatting function.
1445 @param {Function} [*value*]
1446 @chainable
1447 @example <caption>For example, if we wanted to only change the string "Back" and allow all other string to return in English:</caption>
1448 .translate(function(d) {
1449 return d === "Back" ? "Get outta here" : d;
1450 })
1451 */
1452
1453 }, {
1454 key: "translate",
1455 value: function translate(_) {
1456 return arguments.length ? (this._translate = _, this) : this._translate;
1457 }
1458 /**
1459 @memberof Viz
1460 @desc If *value* is specified, sets the config method for each shape and returns the current class instance.
1461 @param {Object} [*value*]
1462 @chainable
1463 */
1464
1465 }, {
1466 key: "shapeConfig",
1467 value: function shapeConfig(_) {
1468 return arguments.length ? (this._shapeConfig = assign(this._shapeConfig, _), this) : this._shapeConfig;
1469 }
1470 }]);
1471
1472 return BaseClass;
1473 }();
1474
1475 /**
1476 @function closest
1477 @desc Finds the closest numeric value in an array.
1478 @param {Number} n The number value to use when searching the array.
1479 @param {Array} arr The array of values to test against.
1480 */
1481 function closest (n) {
1482 var arr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
1483 if (!arr || !(arr instanceof Array) || !arr.length) return undefined;
1484 return arr.reduce(function (prev, curr) {
1485 return Math.abs(curr - n) < Math.abs(prev - n) ? curr : prev;
1486 });
1487 }
1488
1489 /**
1490 @function configPrep
1491 @desc Preps a config object for d3plus data, and optionally bubbles up a specific nested type. When using this function, you must bind a d3plus class' `this` context.
1492 @param {Object} [config = this._shapeConfig] The configuration object to parse.
1493 @param {String} [type = "shape"] The event classifier to user for "on" events. For example, the default event type of "shape" will apply all events in the "on" config object with that key, like "click.shape" and "mouseleave.shape", in addition to any gloval events like "click" and "mouseleave".
1494 @param {String} [nest] An optional nested key to bubble up to the parent config level.
1495 */
1496 function configPrep() {
1497 var _this = this;
1498
1499 var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this._shapeConfig;
1500 var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "shape";
1501 var nest = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1502 var newConfig = {
1503 duration: this._duration,
1504 on: {}
1505 };
1506
1507 var wrapFunction = function wrapFunction(func) {
1508 return function (d, i, s) {
1509 var parent;
1510
1511 while (d.__d3plus__) {
1512 if (parent) d.__d3plusParent__ = parent;
1513 parent = d;
1514 i = d.i;
1515 d = d.data || d.feature;
1516 }
1517
1518 return func.bind(_this)(d, i, s || parent);
1519 };
1520 };
1521
1522 var parseEvents = function parseEvents(newObj, on) {
1523 for (var event in on) {
1524 if ({}.hasOwnProperty.call(on, event) && !event.includes(".") || event.includes(".".concat(type))) {
1525 newObj.on[event] = wrapFunction(on[event]);
1526 }
1527 }
1528 };
1529
1530 var arrayEval = function arrayEval(arr) {
1531 return arr.map(function (d) {
1532 if (d instanceof Array) return arrayEval(d);else if (_typeof(d) === "object") return keyEval({}, d);else if (typeof d === "function") return wrapFunction(d);else return d;
1533 });
1534 };
1535
1536 var keyEval = function keyEval(newObj, obj) {
1537 for (var key in obj) {
1538 if ({}.hasOwnProperty.call(obj, key)) {
1539 if (key === "on") parseEvents(newObj, obj[key]);else if (typeof obj[key] === "function") {
1540 newObj[key] = wrapFunction(obj[key]);
1541 } else if (obj[key] instanceof Array) {
1542 newObj[key] = arrayEval(obj[key]);
1543 } else if (_typeof(obj[key]) === "object") {
1544 newObj[key] = {
1545 on: {}
1546 };
1547 keyEval(newObj[key], obj[key]);
1548 } else newObj[key] = obj[key];
1549 }
1550 }
1551 };
1552
1553 keyEval(newConfig, config);
1554 if (this._on) parseEvents(newConfig, this._on);
1555
1556 if (nest && config[nest]) {
1557 keyEval(newConfig, config[nest]);
1558 if (config[nest].on) parseEvents(newConfig, config[nest].on);
1559 }
1560
1561 return newConfig;
1562 }
1563
1564 /**
1565 @function constant
1566 @desc Wraps non-function variables in a simple return function.
1567 @param {Array|Number|Object|String} value The value to be returned from the function.
1568 @example <caption>this</caption>
1569 constant(42);
1570 @example <caption>returns this</caption>
1571 function() {
1572 return 42;
1573 }
1574 */
1575 function constant (value) {
1576 return function constant() {
1577 return value;
1578 };
1579 }
1580
1581 /**
1582 @function elem
1583 @desc Manages the enter/update/exit pattern for a single DOM element.
1584 @param {String} selector A D3 selector, which must include the tagname and a class and/or ID.
1585 @param {Object} params Additional parameters.
1586 @param {Boolean} [params.condition = true] Whether or not the element should be rendered (or removed).
1587 @param {Object} [params.enter = {}] A collection of key/value pairs that map to attributes to be given on enter.
1588 @param {Object} [params.exit = {}] A collection of key/value pairs that map to attributes to be given on exit.
1589 @param {D3Selection} [params.parent = d3.select("body")] The parent element for this new element to be appended to.
1590 @param {D3Transition} [params.transition = d3.transition().duration(0)] The transition to use when animated the different life cycle stages.
1591 @param {Object} [params.update = {}] A collection of key/value pairs that map to attributes to be given on update.
1592 */
1593
1594 function elem (selector, p) {
1595 // overrides default params
1596 p = Object.assign({}, {
1597 condition: true,
1598 enter: {},
1599 exit: {},
1600 parent: d3Selection.select("body"),
1601 transition: d3Transition.transition().duration(0),
1602 update: {}
1603 }, p);
1604 var className = /\.([^#]+)/g.exec(selector),
1605 id = /#([^\.]+)/g.exec(selector),
1606 tag = /^([^.^#]+)/g.exec(selector)[1];
1607 var elem = p.parent.selectAll(selector.includes(":") ? selector.split(":")[1] : selector).data(p.condition ? [null] : []);
1608 var enter = elem.enter().append(tag).call(attrize, p.enter);
1609 if (id) enter.attr("id", id[1]);
1610 if (className) enter.attr("class", className[1]);
1611 elem.exit().transition(p.transition).call(attrize, p.exit).remove();
1612 var update = enter.merge(elem);
1613 update.transition(p.transition).call(attrize, p.update);
1614 return update;
1615 }
1616
1617 /**
1618 @function unique
1619 @desc ES5 implementation to reduce an Array of values to unique instances.
1620 @param {Array} objects The Array of objects to be filtered.
1621 @example <caption>this</caption>
1622 unique(["apple", "banana", "apple"]);
1623 @example <caption>returns this</caption>
1624 ["apple", "banana"]
1625 */
1626 function unique (arr) {
1627 return arr.filter(function (k, i, a) {
1628 return a.indexOf(k) === i;
1629 });
1630 }
1631
1632 /**
1633 @function merge
1634 @desc Combines an Array of Objects together and returns a new Object.
1635 @param {Array} objects The Array of objects to be merged together.
1636 @param {Object} aggs An object containing specific aggregation methods (functions) for each key type. By default, numbers are summed and strings are returned as an array of unique values.
1637 @example <caption>this</caption>
1638 merge([
1639 {id: "foo", group: "A", value: 10, links: [1, 2]},
1640 {id: "bar", group: "A", value: 20, links: [1, 3]}
1641 ]);
1642 @example <caption>returns this</caption>
1643 {id: ["bar", "foo"], group: "A", value: 30, links: [1, 2, 3]}
1644 */
1645
1646 function objectMerge(objects) {
1647 var aggs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1648 var availableKeys = unique(d3Array.merge(objects.map(function (o) {
1649 return d3Collection.keys(o);
1650 }))),
1651 newObject = {};
1652 availableKeys.forEach(function (k) {
1653 var values = objects.map(function (o) {
1654 return o[k];
1655 });
1656 var value;
1657 if (aggs[k]) value = aggs[k](values);else {
1658 var types = values.map(function (v) {
1659 return v || v === false ? v.constructor : v;
1660 }).filter(function (v) {
1661 return v !== void 0;
1662 });
1663 if (!types.length) value = undefined;else if (types.indexOf(Array) >= 0) {
1664 value = d3Array.merge(values.map(function (v) {
1665 return v instanceof Array ? v : [v];
1666 }));
1667 value = unique(value);
1668 if (value.length === 1) value = value[0];
1669 } else if (types.indexOf(String) >= 0) {
1670 value = unique(values);
1671 if (value.length === 1) value = value[0];
1672 } else if (types.indexOf(Number) >= 0) value = d3Array.sum(values);else if (types.indexOf(Object) >= 0) {
1673 value = unique(values.filter(function (v) {
1674 return v;
1675 }));
1676 if (value.length === 1) value = value[0];else value = objectMerge(value);
1677 } else {
1678 value = unique(values.filter(function (v) {
1679 return v !== void 0;
1680 }));
1681 if (value.length === 1) value = value[0];
1682 }
1683 }
1684 newObject[k] = value;
1685 });
1686 return newObject;
1687 }
1688
1689 /**
1690 @function parseSides
1691 @desc Converts a string of directional CSS shorthand values into an object with the values expanded.
1692 @param {String|Number} sides The CSS shorthand string to expand.
1693 */
1694 function parseSides (sides) {
1695 var values;
1696 if (typeof sides === "number") values = [sides];else values = sides.split(/\s+/);
1697 if (values.length === 1) values = [values[0], values[0], values[0], values[0]];else if (values.length === 2) values = values.concat(values);else if (values.length === 3) values.push(values[1]);
1698 return ["top", "right", "bottom", "left"].reduce(function (acc, direction, i) {
1699 var value = parseFloat(values[i]);
1700 acc[direction] = value || 0;
1701 return acc;
1702 }, {});
1703 }
1704
1705 /**
1706 @function prefix
1707 @desc Returns the appropriate CSS vendor prefix, given the current browser.
1708 */
1709 function prefix () {
1710 if ("-webkit-transform" in document.body.style) return "-webkit-";else if ("-moz-transform" in document.body.style) return "-moz-";else if ("-ms-transform" in document.body.style) return "-ms-";else if ("-o-transform" in document.body.style) return "-o-";else return "";
1711 }
1712
1713 /**
1714 @function stylize
1715 @desc Applies each key/value in an object as a style.
1716 @param {D3selection} elem The D3 element to apply the styles to.
1717 @param {Object} styles An object of key/value style pairs.
1718 */
1719 function stylize (e) {
1720 var s = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1721
1722 for (var k in s) {
1723 if ({}.hasOwnProperty.call(s, k)) e.style(k, s[k]);
1724 }
1725 }
1726
1727 exports.BaseClass = BaseClass;
1728 exports.RESET = RESET;
1729 exports.accessor = accessor;
1730 exports.assign = assign;
1731 exports.attrize = attrize;
1732 exports.closest = closest;
1733 exports.configPrep = configPrep;
1734 exports.constant = constant;
1735 exports.elem = elem;
1736 exports.findLocale = findLocale;
1737 exports.isObject = isObject;
1738 exports.merge = objectMerge;
1739 exports.parseSides = parseSides;
1740 exports.prefix = prefix;
1741 exports.stylize = stylize;
1742 exports.unique = unique;
1743 exports.uuid = uuid;
1744
1745 Object.defineProperty(exports, '__esModule', { value: true });
1746
1747})));
1748//# sourceMappingURL=d3plus-common.js.map