You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4403 lines
147 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (c) 2017-2019 MuK IT GmbH.
  4. *
  5. * This file is part of MuK Web Utils
  6. * (see https://mukit.at).
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. **********************************************************************************/
  22. (function (global, factory) {
  23. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  24. typeof define === 'function' && define.amd ? define(factory) :
  25. (global = global || self, global.SimpleBar = factory());
  26. }(this, function () { 'use strict';
  27. var _isObject = function (it) {
  28. return typeof it === 'object' ? it !== null : typeof it === 'function';
  29. };
  30. var _anObject = function (it) {
  31. if (!_isObject(it)) throw TypeError(it + ' is not an object!');
  32. return it;
  33. };
  34. // 7.2.1 RequireObjectCoercible(argument)
  35. var _defined = function (it) {
  36. if (it == undefined) throw TypeError("Can't call method on " + it);
  37. return it;
  38. };
  39. // 7.1.13 ToObject(argument)
  40. var _toObject = function (it) {
  41. return Object(_defined(it));
  42. };
  43. // 7.1.4 ToInteger
  44. var ceil = Math.ceil;
  45. var floor = Math.floor;
  46. var _toInteger = function (it) {
  47. return isNaN(it = +it) ? 0 : (it > 0 ? floor : ceil)(it);
  48. };
  49. // 7.1.15 ToLength
  50. var min = Math.min;
  51. var _toLength = function (it) {
  52. return it > 0 ? min(_toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
  53. };
  54. // true -> String#at
  55. // false -> String#codePointAt
  56. var _stringAt = function (TO_STRING) {
  57. return function (that, pos) {
  58. var s = String(_defined(that));
  59. var i = _toInteger(pos);
  60. var l = s.length;
  61. var a, b;
  62. if (i < 0 || i >= l) return TO_STRING ? '' : undefined;
  63. a = s.charCodeAt(i);
  64. return a < 0xd800 || a > 0xdbff || i + 1 === l || (b = s.charCodeAt(i + 1)) < 0xdc00 || b > 0xdfff
  65. ? TO_STRING ? s.charAt(i) : a
  66. : TO_STRING ? s.slice(i, i + 2) : (a - 0xd800 << 10) + (b - 0xdc00) + 0x10000;
  67. };
  68. };
  69. var at = _stringAt(true);
  70. // `AdvanceStringIndex` abstract operation
  71. // https://tc39.github.io/ecma262/#sec-advancestringindex
  72. var _advanceStringIndex = function (S, index, unicode) {
  73. return index + (unicode ? at(S, index).length : 1);
  74. };
  75. var toString = {}.toString;
  76. var _cof = function (it) {
  77. return toString.call(it).slice(8, -1);
  78. };
  79. var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
  80. function createCommonjsModule(fn, module) {
  81. return module = { exports: {} }, fn(module, module.exports), module.exports;
  82. }
  83. var _core = createCommonjsModule(function (module) {
  84. var core = module.exports = { version: '2.6.2' };
  85. if (typeof __e == 'number') __e = core; // eslint-disable-line no-undef
  86. });
  87. var _core_1 = _core.version;
  88. var _global = createCommonjsModule(function (module) {
  89. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  90. var global = module.exports = typeof window != 'undefined' && window.Math == Math
  91. ? window : typeof self != 'undefined' && self.Math == Math ? self
  92. // eslint-disable-next-line no-new-func
  93. : Function('return this')();
  94. if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
  95. });
  96. var _library = false;
  97. var _shared = createCommonjsModule(function (module) {
  98. var SHARED = '__core-js_shared__';
  99. var store = _global[SHARED] || (_global[SHARED] = {});
  100. (module.exports = function (key, value) {
  101. return store[key] || (store[key] = value !== undefined ? value : {});
  102. })('versions', []).push({
  103. version: _core.version,
  104. mode: _library ? 'pure' : 'global',
  105. copyright: '© 2019 Denis Pushkarev (zloirock.ru)'
  106. });
  107. });
  108. var id = 0;
  109. var px = Math.random();
  110. var _uid = function (key) {
  111. return 'Symbol('.concat(key === undefined ? '' : key, ')_', (++id + px).toString(36));
  112. };
  113. var _wks = createCommonjsModule(function (module) {
  114. var store = _shared('wks');
  115. var Symbol = _global.Symbol;
  116. var USE_SYMBOL = typeof Symbol == 'function';
  117. var $exports = module.exports = function (name) {
  118. return store[name] || (store[name] =
  119. USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : _uid)('Symbol.' + name));
  120. };
  121. $exports.store = store;
  122. });
  123. // getting tag from 19.1.3.6 Object.prototype.toString()
  124. var TAG = _wks('toStringTag');
  125. // ES3 wrong here
  126. var ARG = _cof(function () { return arguments; }()) == 'Arguments';
  127. // fallback for IE11 Script Access Denied error
  128. var tryGet = function (it, key) {
  129. try {
  130. return it[key];
  131. } catch (e) { /* empty */ }
  132. };
  133. var _classof = function (it) {
  134. var O, T, B;
  135. return it === undefined ? 'Undefined' : it === null ? 'Null'
  136. // @@toStringTag case
  137. : typeof (T = tryGet(O = Object(it), TAG)) == 'string' ? T
  138. // builtinTag case
  139. : ARG ? _cof(O)
  140. // ES3 arguments fallback
  141. : (B = _cof(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : B;
  142. };
  143. var builtinExec = RegExp.prototype.exec;
  144. // `RegExpExec` abstract operation
  145. // https://tc39.github.io/ecma262/#sec-regexpexec
  146. var _regexpExecAbstract = function (R, S) {
  147. var exec = R.exec;
  148. if (typeof exec === 'function') {
  149. var result = exec.call(R, S);
  150. if (typeof result !== 'object') {
  151. throw new TypeError('RegExp exec method returned something other than an Object or null');
  152. }
  153. return result;
  154. }
  155. if (_classof(R) !== 'RegExp') {
  156. throw new TypeError('RegExp#exec called on incompatible receiver');
  157. }
  158. return builtinExec.call(R, S);
  159. };
  160. // 21.2.5.3 get RegExp.prototype.flags
  161. var _flags = function () {
  162. var that = _anObject(this);
  163. var result = '';
  164. if (that.global) result += 'g';
  165. if (that.ignoreCase) result += 'i';
  166. if (that.multiline) result += 'm';
  167. if (that.unicode) result += 'u';
  168. if (that.sticky) result += 'y';
  169. return result;
  170. };
  171. var nativeExec = RegExp.prototype.exec;
  172. // This always refers to the native implementation, because the
  173. // String#replace polyfill uses ./fix-regexp-well-known-symbol-logic.js,
  174. // which loads this file before patching the method.
  175. var nativeReplace = String.prototype.replace;
  176. var patchedExec = nativeExec;
  177. var LAST_INDEX = 'lastIndex';
  178. var UPDATES_LAST_INDEX_WRONG = (function () {
  179. var re1 = /a/,
  180. re2 = /b*/g;
  181. nativeExec.call(re1, 'a');
  182. nativeExec.call(re2, 'a');
  183. return re1[LAST_INDEX] !== 0 || re2[LAST_INDEX] !== 0;
  184. })();
  185. // nonparticipating capturing group, copied from es5-shim's String#split patch.
  186. var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
  187. var PATCH = UPDATES_LAST_INDEX_WRONG || NPCG_INCLUDED;
  188. if (PATCH) {
  189. patchedExec = function exec(str) {
  190. var re = this;
  191. var lastIndex, reCopy, match, i;
  192. if (NPCG_INCLUDED) {
  193. reCopy = new RegExp('^' + re.source + '$(?!\\s)', _flags.call(re));
  194. }
  195. if (UPDATES_LAST_INDEX_WRONG) lastIndex = re[LAST_INDEX];
  196. match = nativeExec.call(re, str);
  197. if (UPDATES_LAST_INDEX_WRONG && match) {
  198. re[LAST_INDEX] = re.global ? match.index + match[0].length : lastIndex;
  199. }
  200. if (NPCG_INCLUDED && match && match.length > 1) {
  201. // Fix browsers whose `exec` methods don't consistently return `undefined`
  202. // for NPCG, like IE8. NOTE: This doesn' work for /(.?)?/
  203. // eslint-disable-next-line no-loop-func
  204. nativeReplace.call(match[0], reCopy, function () {
  205. for (i = 1; i < arguments.length - 2; i++) {
  206. if (arguments[i] === undefined) match[i] = undefined;
  207. }
  208. });
  209. }
  210. return match;
  211. };
  212. }
  213. var _regexpExec = patchedExec;
  214. var _fails = function (exec) {
  215. try {
  216. return !!exec();
  217. } catch (e) {
  218. return true;
  219. }
  220. };
  221. // Thank's IE8 for his funny defineProperty
  222. var _descriptors = !_fails(function () {
  223. return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
  224. });
  225. var document$1 = _global.document;
  226. // typeof document.createElement is 'object' in old IE
  227. var is = _isObject(document$1) && _isObject(document$1.createElement);
  228. var _domCreate = function (it) {
  229. return is ? document$1.createElement(it) : {};
  230. };
  231. var _ie8DomDefine = !_descriptors && !_fails(function () {
  232. return Object.defineProperty(_domCreate('div'), 'a', { get: function () { return 7; } }).a != 7;
  233. });
  234. // 7.1.1 ToPrimitive(input [, PreferredType])
  235. // instead of the ES6 spec version, we didn't implement @@toPrimitive case
  236. // and the second argument - flag - preferred type is a string
  237. var _toPrimitive = function (it, S) {
  238. if (!_isObject(it)) return it;
  239. var fn, val;
  240. if (S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
  241. if (typeof (fn = it.valueOf) == 'function' && !_isObject(val = fn.call(it))) return val;
  242. if (!S && typeof (fn = it.toString) == 'function' && !_isObject(val = fn.call(it))) return val;
  243. throw TypeError("Can't convert object to primitive value");
  244. };
  245. var dP = Object.defineProperty;
  246. var f = _descriptors ? Object.defineProperty : function defineProperty(O, P, Attributes) {
  247. _anObject(O);
  248. P = _toPrimitive(P, true);
  249. _anObject(Attributes);
  250. if (_ie8DomDefine) try {
  251. return dP(O, P, Attributes);
  252. } catch (e) { /* empty */ }
  253. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
  254. if ('value' in Attributes) O[P] = Attributes.value;
  255. return O;
  256. };
  257. var _objectDp = {
  258. f: f
  259. };
  260. var _propertyDesc = function (bitmap, value) {
  261. return {
  262. enumerable: !(bitmap & 1),
  263. configurable: !(bitmap & 2),
  264. writable: !(bitmap & 4),
  265. value: value
  266. };
  267. };
  268. var _hide = _descriptors ? function (object, key, value) {
  269. return _objectDp.f(object, key, _propertyDesc(1, value));
  270. } : function (object, key, value) {
  271. object[key] = value;
  272. return object;
  273. };
  274. var hasOwnProperty = {}.hasOwnProperty;
  275. var _has = function (it, key) {
  276. return hasOwnProperty.call(it, key);
  277. };
  278. var _redefine = createCommonjsModule(function (module) {
  279. var SRC = _uid('src');
  280. var TO_STRING = 'toString';
  281. var $toString = Function[TO_STRING];
  282. var TPL = ('' + $toString).split(TO_STRING);
  283. _core.inspectSource = function (it) {
  284. return $toString.call(it);
  285. };
  286. (module.exports = function (O, key, val, safe) {
  287. var isFunction = typeof val == 'function';
  288. if (isFunction) _has(val, 'name') || _hide(val, 'name', key);
  289. if (O[key] === val) return;
  290. if (isFunction) _has(val, SRC) || _hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
  291. if (O === _global) {
  292. O[key] = val;
  293. } else if (!safe) {
  294. delete O[key];
  295. _hide(O, key, val);
  296. } else if (O[key]) {
  297. O[key] = val;
  298. } else {
  299. _hide(O, key, val);
  300. }
  301. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  302. })(Function.prototype, TO_STRING, function toString() {
  303. return typeof this == 'function' && this[SRC] || $toString.call(this);
  304. });
  305. });
  306. var _aFunction = function (it) {
  307. if (typeof it != 'function') throw TypeError(it + ' is not a function!');
  308. return it;
  309. };
  310. // optional / simple context binding
  311. var _ctx = function (fn, that, length) {
  312. _aFunction(fn);
  313. if (that === undefined) return fn;
  314. switch (length) {
  315. case 1: return function (a) {
  316. return fn.call(that, a);
  317. };
  318. case 2: return function (a, b) {
  319. return fn.call(that, a, b);
  320. };
  321. case 3: return function (a, b, c) {
  322. return fn.call(that, a, b, c);
  323. };
  324. }
  325. return function (/* ...args */) {
  326. return fn.apply(that, arguments);
  327. };
  328. };
  329. var PROTOTYPE = 'prototype';
  330. var $export = function (type, name, source) {
  331. var IS_FORCED = type & $export.F;
  332. var IS_GLOBAL = type & $export.G;
  333. var IS_STATIC = type & $export.S;
  334. var IS_PROTO = type & $export.P;
  335. var IS_BIND = type & $export.B;
  336. var target = IS_GLOBAL ? _global : IS_STATIC ? _global[name] || (_global[name] = {}) : (_global[name] || {})[PROTOTYPE];
  337. var exports = IS_GLOBAL ? _core : _core[name] || (_core[name] = {});
  338. var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
  339. var key, own, out, exp;
  340. if (IS_GLOBAL) source = name;
  341. for (key in source) {
  342. // contains in native
  343. own = !IS_FORCED && target && target[key] !== undefined;
  344. // export native or passed
  345. out = (own ? target : source)[key];
  346. // bind timers to global for call from export context
  347. exp = IS_BIND && own ? _ctx(out, _global) : IS_PROTO && typeof out == 'function' ? _ctx(Function.call, out) : out;
  348. // extend global
  349. if (target) _redefine(target, key, out, type & $export.U);
  350. // export
  351. if (exports[key] != out) _hide(exports, key, exp);
  352. if (IS_PROTO && expProto[key] != out) expProto[key] = out;
  353. }
  354. };
  355. _global.core = _core;
  356. // type bitmap
  357. $export.F = 1; // forced
  358. $export.G = 2; // global
  359. $export.S = 4; // static
  360. $export.P = 8; // proto
  361. $export.B = 16; // bind
  362. $export.W = 32; // wrap
  363. $export.U = 64; // safe
  364. $export.R = 128; // real proto method for `library`
  365. var _export = $export;
  366. _export({
  367. target: 'RegExp',
  368. proto: true,
  369. forced: _regexpExec !== /./.exec
  370. }, {
  371. exec: _regexpExec
  372. });
  373. var SPECIES = _wks('species');
  374. var REPLACE_SUPPORTS_NAMED_GROUPS = !_fails(function () {
  375. // #replace needs built-in support for named groups.
  376. // #match works fine because it just return the exec results, even if it has
  377. // a "grops" property.
  378. var re = /./;
  379. re.exec = function () {
  380. var result = [];
  381. result.groups = { a: '7' };
  382. return result;
  383. };
  384. return ''.replace(re, '$<a>') !== '7';
  385. });
  386. var SPLIT_WORKS_WITH_OVERWRITTEN_EXEC = (function () {
  387. // Chrome 51 has a buggy "split" implementation when RegExp#exec !== nativeExec
  388. var re = /(?:)/;
  389. var originalExec = re.exec;
  390. re.exec = function () { return originalExec.apply(this, arguments); };
  391. var result = 'ab'.split(re);
  392. return result.length === 2 && result[0] === 'a' && result[1] === 'b';
  393. })();
  394. var _fixReWks = function (KEY, length, exec) {
  395. var SYMBOL = _wks(KEY);
  396. var DELEGATES_TO_SYMBOL = !_fails(function () {
  397. // String methods call symbol-named RegEp methods
  398. var O = {};
  399. O[SYMBOL] = function () { return 7; };
  400. return ''[KEY](O) != 7;
  401. });
  402. var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL ? !_fails(function () {
  403. // Symbol-named RegExp methods call .exec
  404. var execCalled = false;
  405. var re = /a/;
  406. re.exec = function () { execCalled = true; return null; };
  407. if (KEY === 'split') {
  408. // RegExp[@@split] doesn't call the regex's exec method, but first creates
  409. // a new one. We need to return the patched regex when creating the new one.
  410. re.constructor = {};
  411. re.constructor[SPECIES] = function () { return re; };
  412. }
  413. re[SYMBOL]('');
  414. return !execCalled;
  415. }) : undefined;
  416. if (
  417. !DELEGATES_TO_SYMBOL ||
  418. !DELEGATES_TO_EXEC ||
  419. (KEY === 'replace' && !REPLACE_SUPPORTS_NAMED_GROUPS) ||
  420. (KEY === 'split' && !SPLIT_WORKS_WITH_OVERWRITTEN_EXEC)
  421. ) {
  422. var nativeRegExpMethod = /./[SYMBOL];
  423. var fns = exec(
  424. _defined,
  425. SYMBOL,
  426. ''[KEY],
  427. function maybeCallNative(nativeMethod, regexp, str, arg2, forceStringMethod) {
  428. if (regexp.exec === _regexpExec) {
  429. if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
  430. // The native String method already delegates to @@method (this
  431. // polyfilled function), leasing to infinite recursion.
  432. // We avoid it by directly calling the native @@method method.
  433. return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) };
  434. }
  435. return { done: true, value: nativeMethod.call(str, regexp, arg2) };
  436. }
  437. return { done: false };
  438. }
  439. );
  440. var strfn = fns[0];
  441. var rxfn = fns[1];
  442. _redefine(String.prototype, KEY, strfn);
  443. _hide(RegExp.prototype, SYMBOL, length == 2
  444. // 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
  445. // 21.2.5.11 RegExp.prototype[@@split](string, limit)
  446. ? function (string, arg) { return rxfn.call(string, this, arg); }
  447. // 21.2.5.6 RegExp.prototype[@@match](string)
  448. // 21.2.5.9 RegExp.prototype[@@search](string)
  449. : function (string) { return rxfn.call(string, this); }
  450. );
  451. }
  452. };
  453. var max = Math.max;
  454. var min$1 = Math.min;
  455. var floor$1 = Math.floor;
  456. var SUBSTITUTION_SYMBOLS = /\$([$&`']|\d\d?|<[^>]*>)/g;
  457. var SUBSTITUTION_SYMBOLS_NO_NAMED = /\$([$&`']|\d\d?)/g;
  458. var maybeToString = function (it) {
  459. return it === undefined ? it : String(it);
  460. };
  461. // @@replace logic
  462. _fixReWks('replace', 2, function (defined, REPLACE, $replace, maybeCallNative) {
  463. return [
  464. // `String.prototype.replace` method
  465. // https://tc39.github.io/ecma262/#sec-string.prototype.replace
  466. function replace(searchValue, replaceValue) {
  467. var O = defined(this);
  468. var fn = searchValue == undefined ? undefined : searchValue[REPLACE];
  469. return fn !== undefined
  470. ? fn.call(searchValue, O, replaceValue)
  471. : $replace.call(String(O), searchValue, replaceValue);
  472. },
  473. // `RegExp.prototype[@@replace]` method
  474. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@replace
  475. function (regexp, replaceValue) {
  476. var res = maybeCallNative($replace, regexp, this, replaceValue);
  477. if (res.done) return res.value;
  478. var rx = _anObject(regexp);
  479. var S = String(this);
  480. var functionalReplace = typeof replaceValue === 'function';
  481. if (!functionalReplace) replaceValue = String(replaceValue);
  482. var global = rx.global;
  483. if (global) {
  484. var fullUnicode = rx.unicode;
  485. rx.lastIndex = 0;
  486. }
  487. var results = [];
  488. while (true) {
  489. var result = _regexpExecAbstract(rx, S);
  490. if (result === null) break;
  491. results.push(result);
  492. if (!global) break;
  493. var matchStr = String(result[0]);
  494. if (matchStr === '') rx.lastIndex = _advanceStringIndex(S, _toLength(rx.lastIndex), fullUnicode);
  495. }
  496. var accumulatedResult = '';
  497. var nextSourcePosition = 0;
  498. for (var i = 0; i < results.length; i++) {
  499. result = results[i];
  500. var matched = String(result[0]);
  501. var position = max(min$1(_toInteger(result.index), S.length), 0);
  502. var captures = [];
  503. // NOTE: This is equivalent to
  504. // captures = result.slice(1).map(maybeToString)
  505. // but for some reason `nativeSlice.call(result, 1, result.length)` (called in
  506. // the slice polyfill when slicing native arrays) "doesn't work" in safari 9 and
  507. // causes a crash (https://pastebin.com/N21QzeQA) when trying to debug it.
  508. for (var j = 1; j < result.length; j++) captures.push(maybeToString(result[j]));
  509. var namedCaptures = result.groups;
  510. if (functionalReplace) {
  511. var replacerArgs = [matched].concat(captures, position, S);
  512. if (namedCaptures !== undefined) replacerArgs.push(namedCaptures);
  513. var replacement = String(replaceValue.apply(undefined, replacerArgs));
  514. } else {
  515. replacement = getSubstitution(matched, S, position, captures, namedCaptures, replaceValue);
  516. }
  517. if (position >= nextSourcePosition) {
  518. accumulatedResult += S.slice(nextSourcePosition, position) + replacement;
  519. nextSourcePosition = position + matched.length;
  520. }
  521. }
  522. return accumulatedResult + S.slice(nextSourcePosition);
  523. }
  524. ];
  525. // https://tc39.github.io/ecma262/#sec-getsubstitution
  526. function getSubstitution(matched, str, position, captures, namedCaptures, replacement) {
  527. var tailPos = position + matched.length;
  528. var m = captures.length;
  529. var symbols = SUBSTITUTION_SYMBOLS_NO_NAMED;
  530. if (namedCaptures !== undefined) {
  531. namedCaptures = _toObject(namedCaptures);
  532. symbols = SUBSTITUTION_SYMBOLS;
  533. }
  534. return $replace.call(replacement, symbols, function (match, ch) {
  535. var capture;
  536. switch (ch.charAt(0)) {
  537. case '$': return '$';
  538. case '&': return matched;
  539. case '`': return str.slice(0, position);
  540. case "'": return str.slice(tailPos);
  541. case '<':
  542. capture = namedCaptures[ch.slice(1, -1)];
  543. break;
  544. default: // \d\d?
  545. var n = +ch;
  546. if (n === 0) return match;
  547. if (n > m) {
  548. var f = floor$1(n / 10);
  549. if (f === 0) return match;
  550. if (f <= m) return captures[f - 1] === undefined ? ch.charAt(1) : captures[f - 1] + ch.charAt(1);
  551. return match;
  552. }
  553. capture = captures[n - 1];
  554. }
  555. return capture === undefined ? '' : capture;
  556. });
  557. }
  558. });
  559. var dP$1 = _objectDp.f;
  560. var FProto = Function.prototype;
  561. var nameRE = /^\s*function ([^ (]*)/;
  562. var NAME = 'name';
  563. // 19.2.4.2 name
  564. NAME in FProto || _descriptors && dP$1(FProto, NAME, {
  565. configurable: true,
  566. get: function () {
  567. try {
  568. return ('' + this).match(nameRE)[1];
  569. } catch (e) {
  570. return '';
  571. }
  572. }
  573. });
  574. // @@match logic
  575. _fixReWks('match', 1, function (defined, MATCH, $match, maybeCallNative) {
  576. return [
  577. // `String.prototype.match` method
  578. // https://tc39.github.io/ecma262/#sec-string.prototype.match
  579. function match(regexp) {
  580. var O = defined(this);
  581. var fn = regexp == undefined ? undefined : regexp[MATCH];
  582. return fn !== undefined ? fn.call(regexp, O) : new RegExp(regexp)[MATCH](String(O));
  583. },
  584. // `RegExp.prototype[@@match]` method
  585. // https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match
  586. function (regexp) {
  587. var res = maybeCallNative($match, regexp, this);
  588. if (res.done) return res.value;
  589. var rx = _anObject(regexp);
  590. var S = String(this);
  591. if (!rx.global) return _regexpExecAbstract(rx, S);
  592. var fullUnicode = rx.unicode;
  593. rx.lastIndex = 0;
  594. var A = [];
  595. var n = 0;
  596. var result;
  597. while ((result = _regexpExecAbstract(rx, S)) !== null) {
  598. var matchStr = String(result[0]);
  599. A[n] = matchStr;
  600. if (matchStr === '') rx.lastIndex = _advanceStringIndex(S, _toLength(rx.lastIndex), fullUnicode);
  601. n++;
  602. }
  603. return n === 0 ? null : A;
  604. }
  605. ];
  606. });
  607. // 22.1.3.31 Array.prototype[@@unscopables]
  608. var UNSCOPABLES = _wks('unscopables');
  609. var ArrayProto = Array.prototype;
  610. if (ArrayProto[UNSCOPABLES] == undefined) _hide(ArrayProto, UNSCOPABLES, {});
  611. var _addToUnscopables = function (key) {
  612. ArrayProto[UNSCOPABLES][key] = true;
  613. };
  614. var _iterStep = function (done, value) {
  615. return { value: value, done: !!done };
  616. };
  617. var _iterators = {};
  618. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  619. // eslint-disable-next-line no-prototype-builtins
  620. var _iobject = Object('z').propertyIsEnumerable(0) ? Object : function (it) {
  621. return _cof(it) == 'String' ? it.split('') : Object(it);
  622. };
  623. // to indexed object, toObject with fallback for non-array-like ES3 strings
  624. var _toIobject = function (it) {
  625. return _iobject(_defined(it));
  626. };
  627. var max$1 = Math.max;
  628. var min$2 = Math.min;
  629. var _toAbsoluteIndex = function (index, length) {
  630. index = _toInteger(index);
  631. return index < 0 ? max$1(index + length, 0) : min$2(index, length);
  632. };
  633. // false -> Array#indexOf
  634. // true -> Array#includes
  635. var _arrayIncludes = function (IS_INCLUDES) {
  636. return function ($this, el, fromIndex) {
  637. var O = _toIobject($this);
  638. var length = _toLength(O.length);
  639. var index = _toAbsoluteIndex(fromIndex, length);
  640. var value;
  641. // Array#includes uses SameValueZero equality algorithm
  642. // eslint-disable-next-line no-self-compare
  643. if (IS_INCLUDES && el != el) while (length > index) {
  644. value = O[index++];
  645. // eslint-disable-next-line no-self-compare
  646. if (value != value) return true;
  647. // Array#indexOf ignores holes, Array#includes - not
  648. } else for (;length > index; index++) if (IS_INCLUDES || index in O) {
  649. if (O[index] === el) return IS_INCLUDES || index || 0;
  650. } return !IS_INCLUDES && -1;
  651. };
  652. };
  653. var shared = _shared('keys');
  654. var _sharedKey = function (key) {
  655. return shared[key] || (shared[key] = _uid(key));
  656. };
  657. var arrayIndexOf = _arrayIncludes(false);
  658. var IE_PROTO = _sharedKey('IE_PROTO');
  659. var _objectKeysInternal = function (object, names) {
  660. var O = _toIobject(object);
  661. var i = 0;
  662. var result = [];
  663. var key;
  664. for (key in O) if (key != IE_PROTO) _has(O, key) && result.push(key);
  665. // Don't enum bug & hidden keys
  666. while (names.length > i) if (_has(O, key = names[i++])) {
  667. ~arrayIndexOf(result, key) || result.push(key);
  668. }
  669. return result;
  670. };
  671. // IE 8- don't enum bug keys
  672. var _enumBugKeys = (
  673. 'constructor,hasOwnProperty,isPrototypeOf,propertyIsEnumerable,toLocaleString,toString,valueOf'
  674. ).split(',');
  675. // 19.1.2.14 / 15.2.3.14 Object.keys(O)
  676. var _objectKeys = Object.keys || function keys(O) {
  677. return _objectKeysInternal(O, _enumBugKeys);
  678. };
  679. var _objectDps = _descriptors ? Object.defineProperties : function defineProperties(O, Properties) {
  680. _anObject(O);
  681. var keys = _objectKeys(Properties);
  682. var length = keys.length;
  683. var i = 0;
  684. var P;
  685. while (length > i) _objectDp.f(O, P = keys[i++], Properties[P]);
  686. return O;
  687. };
  688. var document$2 = _global.document;
  689. var _html = document$2 && document$2.documentElement;
  690. // 19.1.2.2 / 15.2.3.5 Object.create(O [, Properties])
  691. var IE_PROTO$1 = _sharedKey('IE_PROTO');
  692. var Empty = function () { /* empty */ };
  693. var PROTOTYPE$1 = 'prototype';
  694. // Create object with fake `null` prototype: use iframe Object with cleared prototype
  695. var createDict = function () {
  696. // Thrash, waste and sodomy: IE GC bug
  697. var iframe = _domCreate('iframe');
  698. var i = _enumBugKeys.length;
  699. var lt = '<';
  700. var gt = '>';
  701. var iframeDocument;
  702. iframe.style.display = 'none';
  703. _html.appendChild(iframe);
  704. iframe.src = 'javascript:'; // eslint-disable-line no-script-url
  705. // createDict = iframe.contentWindow.Object;
  706. // html.removeChild(iframe);
  707. iframeDocument = iframe.contentWindow.document;
  708. iframeDocument.open();
  709. iframeDocument.write(lt + 'script' + gt + 'document.F=Object' + lt + '/script' + gt);
  710. iframeDocument.close();
  711. createDict = iframeDocument.F;
  712. while (i--) delete createDict[PROTOTYPE$1][_enumBugKeys[i]];
  713. return createDict();
  714. };
  715. var _objectCreate = Object.create || function create(O, Properties) {
  716. var result;
  717. if (O !== null) {
  718. Empty[PROTOTYPE$1] = _anObject(O);
  719. result = new Empty();
  720. Empty[PROTOTYPE$1] = null;
  721. // add "__proto__" for Object.getPrototypeOf polyfill
  722. result[IE_PROTO$1] = O;
  723. } else result = createDict();
  724. return Properties === undefined ? result : _objectDps(result, Properties);
  725. };
  726. var def = _objectDp.f;
  727. var TAG$1 = _wks('toStringTag');
  728. var _setToStringTag = function (it, tag, stat) {
  729. if (it && !_has(it = stat ? it : it.prototype, TAG$1)) def(it, TAG$1, { configurable: true, value: tag });
  730. };
  731. var IteratorPrototype = {};
  732. // 25.1.2.1.1 %IteratorPrototype%[@@iterator]()
  733. _hide(IteratorPrototype, _wks('iterator'), function () { return this; });
  734. var _iterCreate = function (Constructor, NAME, next) {
  735. Constructor.prototype = _objectCreate(IteratorPrototype, { next: _propertyDesc(1, next) });
  736. _setToStringTag(Constructor, NAME + ' Iterator');
  737. };
  738. // 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
  739. var IE_PROTO$2 = _sharedKey('IE_PROTO');
  740. var ObjectProto = Object.prototype;
  741. var _objectGpo = Object.getPrototypeOf || function (O) {
  742. O = _toObject(O);
  743. if (_has(O, IE_PROTO$2)) return O[IE_PROTO$2];
  744. if (typeof O.constructor == 'function' && O instanceof O.constructor) {
  745. return O.constructor.prototype;
  746. } return O instanceof Object ? ObjectProto : null;
  747. };
  748. var ITERATOR = _wks('iterator');
  749. var BUGGY = !([].keys && 'next' in [].keys()); // Safari has buggy iterators w/o `next`
  750. var FF_ITERATOR = '@@iterator';
  751. var KEYS = 'keys';
  752. var VALUES = 'values';
  753. var returnThis = function () { return this; };
  754. var _iterDefine = function (Base, NAME, Constructor, next, DEFAULT, IS_SET, FORCED) {
  755. _iterCreate(Constructor, NAME, next);
  756. var getMethod = function (kind) {
  757. if (!BUGGY && kind in proto) return proto[kind];
  758. switch (kind) {
  759. case KEYS: return function keys() { return new Constructor(this, kind); };
  760. case VALUES: return function values() { return new Constructor(this, kind); };
  761. } return function entries() { return new Constructor(this, kind); };
  762. };
  763. var TAG = NAME + ' Iterator';
  764. var DEF_VALUES = DEFAULT == VALUES;
  765. var VALUES_BUG = false;
  766. var proto = Base.prototype;
  767. var $native = proto[ITERATOR] || proto[FF_ITERATOR] || DEFAULT && proto[DEFAULT];
  768. var $default = $native || getMethod(DEFAULT);
  769. var $entries = DEFAULT ? !DEF_VALUES ? $default : getMethod('entries') : undefined;
  770. var $anyNative = NAME == 'Array' ? proto.entries || $native : $native;
  771. var methods, key, IteratorPrototype;
  772. // Fix native
  773. if ($anyNative) {
  774. IteratorPrototype = _objectGpo($anyNative.call(new Base()));
  775. if (IteratorPrototype !== Object.prototype && IteratorPrototype.next) {
  776. // Set @@toStringTag to native iterators
  777. _setToStringTag(IteratorPrototype, TAG, true);
  778. // fix for some old engines
  779. if (!_library && typeof IteratorPrototype[ITERATOR] != 'function') _hide(IteratorPrototype, ITERATOR, returnThis);
  780. }
  781. }
  782. // fix Array#{values, @@iterator}.name in V8 / FF
  783. if (DEF_VALUES && $native && $native.name !== VALUES) {
  784. VALUES_BUG = true;
  785. $default = function values() { return $native.call(this); };
  786. }
  787. // Define iterator
  788. if ((!_library || FORCED) && (BUGGY || VALUES_BUG || !proto[ITERATOR])) {
  789. _hide(proto, ITERATOR, $default);
  790. }
  791. // Plug for library
  792. _iterators[NAME] = $default;
  793. _iterators[TAG] = returnThis;
  794. if (DEFAULT) {
  795. methods = {
  796. values: DEF_VALUES ? $default : getMethod(VALUES),
  797. keys: IS_SET ? $default : getMethod(KEYS),
  798. entries: $entries
  799. };
  800. if (FORCED) for (key in methods) {
  801. if (!(key in proto)) _redefine(proto, key, methods[key]);
  802. } else _export(_export.P + _export.F * (BUGGY || VALUES_BUG), NAME, methods);
  803. }
  804. return methods;
  805. };
  806. // 22.1.3.4 Array.prototype.entries()
  807. // 22.1.3.13 Array.prototype.keys()
  808. // 22.1.3.29 Array.prototype.values()
  809. // 22.1.3.30 Array.prototype[@@iterator]()
  810. var es6_array_iterator = _iterDefine(Array, 'Array', function (iterated, kind) {
  811. this._t = _toIobject(iterated); // target
  812. this._i = 0; // next index
  813. this._k = kind; // kind
  814. // 22.1.5.2.1 %ArrayIteratorPrototype%.next()
  815. }, function () {
  816. var O = this._t;
  817. var kind = this._k;
  818. var index = this._i++;
  819. if (!O || index >= O.length) {
  820. this._t = undefined;
  821. return _iterStep(1);
  822. }
  823. if (kind == 'keys') return _iterStep(0, index);
  824. if (kind == 'values') return _iterStep(0, O[index]);
  825. return _iterStep(0, [index, O[index]]);
  826. }, 'values');
  827. // argumentsList[@@iterator] is %ArrayProto_values% (9.4.4.6, 9.4.4.7)
  828. _iterators.Arguments = _iterators.Array;
  829. _addToUnscopables('keys');
  830. _addToUnscopables('values');
  831. _addToUnscopables('entries');
  832. var ITERATOR$1 = _wks('iterator');
  833. var TO_STRING_TAG = _wks('toStringTag');
  834. var ArrayValues = _iterators.Array;
  835. var DOMIterables = {
  836. CSSRuleList: true, // TODO: Not spec compliant, should be false.
  837. CSSStyleDeclaration: false,
  838. CSSValueList: false,
  839. ClientRectList: false,
  840. DOMRectList: false,
  841. DOMStringList: false,
  842. DOMTokenList: true,
  843. DataTransferItemList: false,
  844. FileList: false,
  845. HTMLAllCollection: false,
  846. HTMLCollection: false,
  847. HTMLFormElement: false,
  848. HTMLSelectElement: false,
  849. MediaList: true, // TODO: Not spec compliant, should be false.
  850. MimeTypeArray: false,
  851. NamedNodeMap: false,
  852. NodeList: true,
  853. PaintRequestList: false,
  854. Plugin: false,
  855. PluginArray: false,
  856. SVGLengthList: false,
  857. SVGNumberList: false,
  858. SVGPathSegList: false,
  859. SVGPointList: false,
  860. SVGStringList: false,
  861. SVGTransformList: false,
  862. SourceBufferList: false,
  863. StyleSheetList: true, // TODO: Not spec compliant, should be false.
  864. TextTrackCueList: false,
  865. TextTrackList: false,
  866. TouchList: false
  867. };
  868. for (var collections = _objectKeys(DOMIterables), i = 0; i < collections.length; i++) {
  869. var NAME$1 = collections[i];
  870. var explicit = DOMIterables[NAME$1];
  871. var Collection = _global[NAME$1];
  872. var proto = Collection && Collection.prototype;
  873. var key;
  874. if (proto) {
  875. if (!proto[ITERATOR$1]) _hide(proto, ITERATOR$1, ArrayValues);
  876. if (!proto[TO_STRING_TAG]) _hide(proto, TO_STRING_TAG, NAME$1);
  877. _iterators[NAME$1] = ArrayValues;
  878. if (explicit) for (key in es6_array_iterator) if (!proto[key]) _redefine(proto, key, es6_array_iterator[key], true);
  879. }
  880. }
  881. var $at = _stringAt(true);
  882. // 21.1.3.27 String.prototype[@@iterator]()
  883. _iterDefine(String, 'String', function (iterated) {
  884. this._t = String(iterated); // target
  885. this._i = 0; // next index
  886. // 21.1.5.2.1 %StringIteratorPrototype%.next()
  887. }, function () {
  888. var O = this._t;
  889. var index = this._i;
  890. var point;
  891. if (index >= O.length) return { value: undefined, done: true };
  892. point = $at(O, index);
  893. this._i += point.length;
  894. return { value: point, done: false };
  895. });
  896. // call something on iterator step with safe closing on error
  897. var _iterCall = function (iterator, fn, value, entries) {
  898. try {
  899. return entries ? fn(_anObject(value)[0], value[1]) : fn(value);
  900. // 7.4.6 IteratorClose(iterator, completion)
  901. } catch (e) {
  902. var ret = iterator['return'];
  903. if (ret !== undefined) _anObject(ret.call(iterator));
  904. throw e;
  905. }
  906. };
  907. // check on default Array iterator
  908. var ITERATOR$2 = _wks('iterator');
  909. var ArrayProto$1 = Array.prototype;
  910. var _isArrayIter = function (it) {
  911. return it !== undefined && (_iterators.Array === it || ArrayProto$1[ITERATOR$2] === it);
  912. };
  913. var _createProperty = function (object, index, value) {
  914. if (index in object) _objectDp.f(object, index, _propertyDesc(0, value));
  915. else object[index] = value;
  916. };
  917. var ITERATOR$3 = _wks('iterator');
  918. var core_getIteratorMethod = _core.getIteratorMethod = function (it) {
  919. if (it != undefined) return it[ITERATOR$3]
  920. || it['@@iterator']
  921. || _iterators[_classof(it)];
  922. };
  923. var ITERATOR$4 = _wks('iterator');
  924. var SAFE_CLOSING = false;
  925. try {
  926. var riter = [7][ITERATOR$4]();
  927. riter['return'] = function () { SAFE_CLOSING = true; };
  928. } catch (e) { /* empty */ }
  929. var _iterDetect = function (exec, skipClosing) {
  930. if (!skipClosing && !SAFE_CLOSING) return false;
  931. var safe = false;
  932. try {
  933. var arr = [7];
  934. var iter = arr[ITERATOR$4]();
  935. iter.next = function () { return { done: safe = true }; };
  936. arr[ITERATOR$4] = function () { return iter; };
  937. exec(arr);
  938. } catch (e) { /* empty */ }
  939. return safe;
  940. };
  941. _export(_export.S + _export.F * !_iterDetect(function (iter) { }), 'Array', {
  942. // 22.1.2.1 Array.from(arrayLike, mapfn = undefined, thisArg = undefined)
  943. from: function from(arrayLike /* , mapfn = undefined, thisArg = undefined */) {
  944. var O = _toObject(arrayLike);
  945. var C = typeof this == 'function' ? this : Array;
  946. var aLen = arguments.length;
  947. var mapfn = aLen > 1 ? arguments[1] : undefined;
  948. var mapping = mapfn !== undefined;
  949. var index = 0;
  950. var iterFn = core_getIteratorMethod(O);
  951. var length, result, step, iterator;
  952. if (mapping) mapfn = _ctx(mapfn, aLen > 2 ? arguments[2] : undefined, 2);
  953. // if object isn't iterable or it's array with default iterator - use simple case
  954. if (iterFn != undefined && !(C == Array && _isArrayIter(iterFn))) {
  955. for (iterator = iterFn.call(O), result = new C(); !(step = iterator.next()).done; index++) {
  956. _createProperty(result, index, mapping ? _iterCall(iterator, mapfn, [step.value, index], true) : step.value);
  957. }
  958. } else {
  959. length = _toLength(O.length);
  960. for (result = new C(length); length > index; index++) {
  961. _createProperty(result, index, mapping ? mapfn(O[index], index) : O[index]);
  962. }
  963. }
  964. result.length = index;
  965. return result;
  966. }
  967. });
  968. function _classCallCheck(instance, Constructor) {
  969. if (!(instance instanceof Constructor)) {
  970. throw new TypeError("Cannot call a class as a function");
  971. }
  972. }
  973. function _defineProperties(target, props) {
  974. for (var i = 0; i < props.length; i++) {
  975. var descriptor = props[i];
  976. descriptor.enumerable = descriptor.enumerable || false;
  977. descriptor.configurable = true;
  978. if ("value" in descriptor) descriptor.writable = true;
  979. Object.defineProperty(target, descriptor.key, descriptor);
  980. }
  981. }
  982. function _createClass(Constructor, protoProps, staticProps) {
  983. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  984. if (staticProps) _defineProperties(Constructor, staticProps);
  985. return Constructor;
  986. }
  987. function _defineProperty(obj, key, value) {
  988. if (key in obj) {
  989. Object.defineProperty(obj, key, {
  990. value: value,
  991. enumerable: true,
  992. configurable: true,
  993. writable: true
  994. });
  995. } else {
  996. obj[key] = value;
  997. }
  998. return obj;
  999. }
  1000. function _objectSpread(target) {
  1001. for (var i = 1; i < arguments.length; i++) {
  1002. var source = arguments[i] != null ? arguments[i] : {};
  1003. var ownKeys = Object.keys(source);
  1004. if (typeof Object.getOwnPropertySymbols === 'function') {
  1005. ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
  1006. return Object.getOwnPropertyDescriptor(source, sym).enumerable;
  1007. }));
  1008. }
  1009. ownKeys.forEach(function (key) {
  1010. _defineProperty(target, key, source[key]);
  1011. });
  1012. }
  1013. return target;
  1014. }
  1015. var scrollbarWidth = createCommonjsModule(function (module, exports) {
  1016. /*! scrollbarWidth.js v0.1.3 | felixexter | MIT | https://github.com/felixexter/scrollbarWidth */
  1017. (function (root, factory) {
  1018. {
  1019. module.exports = factory();
  1020. }
  1021. }(commonjsGlobal, function () {
  1022. function scrollbarWidth() {
  1023. if (typeof document === 'undefined') {
  1024. return 0
  1025. }
  1026. var
  1027. body = document.body,
  1028. box = document.createElement('div'),
  1029. boxStyle = box.style,
  1030. width;
  1031. boxStyle.position = 'absolute';
  1032. boxStyle.top = boxStyle.left = '-9999px';
  1033. boxStyle.width = boxStyle.height = '100px';
  1034. boxStyle.overflow = 'scroll';
  1035. body.appendChild(box);
  1036. width = box.offsetWidth - box.clientWidth;
  1037. body.removeChild(box);
  1038. return width;
  1039. }
  1040. return scrollbarWidth;
  1041. }));
  1042. });
  1043. /**
  1044. * lodash (Custom Build) <https://lodash.com/>
  1045. * Build: `lodash modularize exports="npm" -o ./`
  1046. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  1047. * Released under MIT license <https://lodash.com/license>
  1048. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1049. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1050. */
  1051. /** Used as the `TypeError` message for "Functions" methods. */
  1052. var FUNC_ERROR_TEXT = 'Expected a function';
  1053. /** Used as references for various `Number` constants. */
  1054. var NAN = 0 / 0;
  1055. /** `Object#toString` result references. */
  1056. var symbolTag = '[object Symbol]';
  1057. /** Used to match leading and trailing whitespace. */
  1058. var reTrim = /^\s+|\s+$/g;
  1059. /** Used to detect bad signed hexadecimal string values. */
  1060. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  1061. /** Used to detect binary string values. */
  1062. var reIsBinary = /^0b[01]+$/i;
  1063. /** Used to detect octal string values. */
  1064. var reIsOctal = /^0o[0-7]+$/i;
  1065. /** Built-in method references without a dependency on `root`. */
  1066. var freeParseInt = parseInt;
  1067. /** Detect free variable `global` from Node.js. */
  1068. var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  1069. /** Detect free variable `self`. */
  1070. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  1071. /** Used as a reference to the global object. */
  1072. var root = freeGlobal || freeSelf || Function('return this')();
  1073. /** Used for built-in method references. */
  1074. var objectProto = Object.prototype;
  1075. /**
  1076. * Used to resolve the
  1077. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1078. * of values.
  1079. */
  1080. var objectToString = objectProto.toString;
  1081. /* Built-in method references for those with the same name as other `lodash` methods. */
  1082. var nativeMax = Math.max,
  1083. nativeMin = Math.min;
  1084. /**
  1085. * Gets the timestamp of the number of milliseconds that have elapsed since
  1086. * the Unix epoch (1 January 1970 00:00:00 UTC).
  1087. *
  1088. * @static
  1089. * @memberOf _
  1090. * @since 2.4.0
  1091. * @category Date
  1092. * @returns {number} Returns the timestamp.
  1093. * @example
  1094. *
  1095. * _.defer(function(stamp) {
  1096. * console.log(_.now() - stamp);
  1097. * }, _.now());
  1098. * // => Logs the number of milliseconds it took for the deferred invocation.
  1099. */
  1100. var now = function() {
  1101. return root.Date.now();
  1102. };
  1103. /**
  1104. * Creates a debounced function that delays invoking `func` until after `wait`
  1105. * milliseconds have elapsed since the last time the debounced function was
  1106. * invoked. The debounced function comes with a `cancel` method to cancel
  1107. * delayed `func` invocations and a `flush` method to immediately invoke them.
  1108. * Provide `options` to indicate whether `func` should be invoked on the
  1109. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  1110. * with the last arguments provided to the debounced function. Subsequent
  1111. * calls to the debounced function return the result of the last `func`
  1112. * invocation.
  1113. *
  1114. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  1115. * invoked on the trailing edge of the timeout only if the debounced function
  1116. * is invoked more than once during the `wait` timeout.
  1117. *
  1118. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  1119. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  1120. *
  1121. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  1122. * for details over the differences between `_.debounce` and `_.throttle`.
  1123. *
  1124. * @static
  1125. * @memberOf _
  1126. * @since 0.1.0
  1127. * @category Function
  1128. * @param {Function} func The function to debounce.
  1129. * @param {number} [wait=0] The number of milliseconds to delay.
  1130. * @param {Object} [options={}] The options object.
  1131. * @param {boolean} [options.leading=false]
  1132. * Specify invoking on the leading edge of the timeout.
  1133. * @param {number} [options.maxWait]
  1134. * The maximum time `func` is allowed to be delayed before it's invoked.
  1135. * @param {boolean} [options.trailing=true]
  1136. * Specify invoking on the trailing edge of the timeout.
  1137. * @returns {Function} Returns the new debounced function.
  1138. * @example
  1139. *
  1140. * // Avoid costly calculations while the window size is in flux.
  1141. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  1142. *
  1143. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  1144. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  1145. * 'leading': true,
  1146. * 'trailing': false
  1147. * }));
  1148. *
  1149. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  1150. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  1151. * var source = new EventSource('/stream');
  1152. * jQuery(source).on('message', debounced);
  1153. *
  1154. * // Cancel the trailing debounced invocation.
  1155. * jQuery(window).on('popstate', debounced.cancel);
  1156. */
  1157. function debounce(func, wait, options) {
  1158. var lastArgs,
  1159. lastThis,
  1160. maxWait,
  1161. result,
  1162. timerId,
  1163. lastCallTime,
  1164. lastInvokeTime = 0,
  1165. leading = false,
  1166. maxing = false,
  1167. trailing = true;
  1168. if (typeof func != 'function') {
  1169. throw new TypeError(FUNC_ERROR_TEXT);
  1170. }
  1171. wait = toNumber(wait) || 0;
  1172. if (isObject(options)) {
  1173. leading = !!options.leading;
  1174. maxing = 'maxWait' in options;
  1175. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  1176. trailing = 'trailing' in options ? !!options.trailing : trailing;
  1177. }
  1178. function invokeFunc(time) {
  1179. var args = lastArgs,
  1180. thisArg = lastThis;
  1181. lastArgs = lastThis = undefined;
  1182. lastInvokeTime = time;
  1183. result = func.apply(thisArg, args);
  1184. return result;
  1185. }
  1186. function leadingEdge(time) {
  1187. // Reset any `maxWait` timer.
  1188. lastInvokeTime = time;
  1189. // Start the timer for the trailing edge.
  1190. timerId = setTimeout(timerExpired, wait);
  1191. // Invoke the leading edge.
  1192. return leading ? invokeFunc(time) : result;
  1193. }
  1194. function remainingWait(time) {
  1195. var timeSinceLastCall = time - lastCallTime,
  1196. timeSinceLastInvoke = time - lastInvokeTime,
  1197. result = wait - timeSinceLastCall;
  1198. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  1199. }
  1200. function shouldInvoke(time) {
  1201. var timeSinceLastCall = time - lastCallTime,
  1202. timeSinceLastInvoke = time - lastInvokeTime;
  1203. // Either this is the first call, activity has stopped and we're at the
  1204. // trailing edge, the system time has gone backwards and we're treating
  1205. // it as the trailing edge, or we've hit the `maxWait` limit.
  1206. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  1207. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  1208. }
  1209. function timerExpired() {
  1210. var time = now();
  1211. if (shouldInvoke(time)) {
  1212. return trailingEdge(time);
  1213. }
  1214. // Restart the timer.
  1215. timerId = setTimeout(timerExpired, remainingWait(time));
  1216. }
  1217. function trailingEdge(time) {
  1218. timerId = undefined;
  1219. // Only invoke if we have `lastArgs` which means `func` has been
  1220. // debounced at least once.
  1221. if (trailing && lastArgs) {
  1222. return invokeFunc(time);
  1223. }
  1224. lastArgs = lastThis = undefined;
  1225. return result;
  1226. }
  1227. function cancel() {
  1228. if (timerId !== undefined) {
  1229. clearTimeout(timerId);
  1230. }
  1231. lastInvokeTime = 0;
  1232. lastArgs = lastCallTime = lastThis = timerId = undefined;
  1233. }
  1234. function flush() {
  1235. return timerId === undefined ? result : trailingEdge(now());
  1236. }
  1237. function debounced() {
  1238. var time = now(),
  1239. isInvoking = shouldInvoke(time);
  1240. lastArgs = arguments;
  1241. lastThis = this;
  1242. lastCallTime = time;
  1243. if (isInvoking) {
  1244. if (timerId === undefined) {
  1245. return leadingEdge(lastCallTime);
  1246. }
  1247. if (maxing) {
  1248. // Handle invocations in a tight loop.
  1249. timerId = setTimeout(timerExpired, wait);
  1250. return invokeFunc(lastCallTime);
  1251. }
  1252. }
  1253. if (timerId === undefined) {
  1254. timerId = setTimeout(timerExpired, wait);
  1255. }
  1256. return result;
  1257. }
  1258. debounced.cancel = cancel;
  1259. debounced.flush = flush;
  1260. return debounced;
  1261. }
  1262. /**
  1263. * Creates a throttled function that only invokes `func` at most once per
  1264. * every `wait` milliseconds. The throttled function comes with a `cancel`
  1265. * method to cancel delayed `func` invocations and a `flush` method to
  1266. * immediately invoke them. Provide `options` to indicate whether `func`
  1267. * should be invoked on the leading and/or trailing edge of the `wait`
  1268. * timeout. The `func` is invoked with the last arguments provided to the
  1269. * throttled function. Subsequent calls to the throttled function return the
  1270. * result of the last `func` invocation.
  1271. *
  1272. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  1273. * invoked on the trailing edge of the timeout only if the throttled function
  1274. * is invoked more than once during the `wait` timeout.
  1275. *
  1276. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  1277. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  1278. *
  1279. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  1280. * for details over the differences between `_.throttle` and `_.debounce`.
  1281. *
  1282. * @static
  1283. * @memberOf _
  1284. * @since 0.1.0
  1285. * @category Function
  1286. * @param {Function} func The function to throttle.
  1287. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  1288. * @param {Object} [options={}] The options object.
  1289. * @param {boolean} [options.leading=true]
  1290. * Specify invoking on the leading edge of the timeout.
  1291. * @param {boolean} [options.trailing=true]
  1292. * Specify invoking on the trailing edge of the timeout.
  1293. * @returns {Function} Returns the new throttled function.
  1294. * @example
  1295. *
  1296. * // Avoid excessively updating the position while scrolling.
  1297. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  1298. *
  1299. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  1300. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  1301. * jQuery(element).on('click', throttled);
  1302. *
  1303. * // Cancel the trailing throttled invocation.
  1304. * jQuery(window).on('popstate', throttled.cancel);
  1305. */
  1306. function throttle(func, wait, options) {
  1307. var leading = true,
  1308. trailing = true;
  1309. if (typeof func != 'function') {
  1310. throw new TypeError(FUNC_ERROR_TEXT);
  1311. }
  1312. if (isObject(options)) {
  1313. leading = 'leading' in options ? !!options.leading : leading;
  1314. trailing = 'trailing' in options ? !!options.trailing : trailing;
  1315. }
  1316. return debounce(func, wait, {
  1317. 'leading': leading,
  1318. 'maxWait': wait,
  1319. 'trailing': trailing
  1320. });
  1321. }
  1322. /**
  1323. * Checks if `value` is the
  1324. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1325. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1326. *
  1327. * @static
  1328. * @memberOf _
  1329. * @since 0.1.0
  1330. * @category Lang
  1331. * @param {*} value The value to check.
  1332. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1333. * @example
  1334. *
  1335. * _.isObject({});
  1336. * // => true
  1337. *
  1338. * _.isObject([1, 2, 3]);
  1339. * // => true
  1340. *
  1341. * _.isObject(_.noop);
  1342. * // => true
  1343. *
  1344. * _.isObject(null);
  1345. * // => false
  1346. */
  1347. function isObject(value) {
  1348. var type = typeof value;
  1349. return !!value && (type == 'object' || type == 'function');
  1350. }
  1351. /**
  1352. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1353. * and has a `typeof` result of "object".
  1354. *
  1355. * @static
  1356. * @memberOf _
  1357. * @since 4.0.0
  1358. * @category Lang
  1359. * @param {*} value The value to check.
  1360. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1361. * @example
  1362. *
  1363. * _.isObjectLike({});
  1364. * // => true
  1365. *
  1366. * _.isObjectLike([1, 2, 3]);
  1367. * // => true
  1368. *
  1369. * _.isObjectLike(_.noop);
  1370. * // => false
  1371. *
  1372. * _.isObjectLike(null);
  1373. * // => false
  1374. */
  1375. function isObjectLike(value) {
  1376. return !!value && typeof value == 'object';
  1377. }
  1378. /**
  1379. * Checks if `value` is classified as a `Symbol` primitive or object.
  1380. *
  1381. * @static
  1382. * @memberOf _
  1383. * @since 4.0.0
  1384. * @category Lang
  1385. * @param {*} value The value to check.
  1386. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1387. * @example
  1388. *
  1389. * _.isSymbol(Symbol.iterator);
  1390. * // => true
  1391. *
  1392. * _.isSymbol('abc');
  1393. * // => false
  1394. */
  1395. function isSymbol(value) {
  1396. return typeof value == 'symbol' ||
  1397. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  1398. }
  1399. /**
  1400. * Converts `value` to a number.
  1401. *
  1402. * @static
  1403. * @memberOf _
  1404. * @since 4.0.0
  1405. * @category Lang
  1406. * @param {*} value The value to process.
  1407. * @returns {number} Returns the number.
  1408. * @example
  1409. *
  1410. * _.toNumber(3.2);
  1411. * // => 3.2
  1412. *
  1413. * _.toNumber(Number.MIN_VALUE);
  1414. * // => 5e-324
  1415. *
  1416. * _.toNumber(Infinity);
  1417. * // => Infinity
  1418. *
  1419. * _.toNumber('3.2');
  1420. * // => 3.2
  1421. */
  1422. function toNumber(value) {
  1423. if (typeof value == 'number') {
  1424. return value;
  1425. }
  1426. if (isSymbol(value)) {
  1427. return NAN;
  1428. }
  1429. if (isObject(value)) {
  1430. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  1431. value = isObject(other) ? (other + '') : other;
  1432. }
  1433. if (typeof value != 'string') {
  1434. return value === 0 ? value : +value;
  1435. }
  1436. value = value.replace(reTrim, '');
  1437. var isBinary = reIsBinary.test(value);
  1438. return (isBinary || reIsOctal.test(value))
  1439. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  1440. : (reIsBadHex.test(value) ? NAN : +value);
  1441. }
  1442. var lodash_throttle = throttle;
  1443. /**
  1444. * lodash (Custom Build) <https://lodash.com/>
  1445. * Build: `lodash modularize exports="npm" -o ./`
  1446. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  1447. * Released under MIT license <https://lodash.com/license>
  1448. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1449. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1450. */
  1451. /** Used as the `TypeError` message for "Functions" methods. */
  1452. var FUNC_ERROR_TEXT$1 = 'Expected a function';
  1453. /** Used as references for various `Number` constants. */
  1454. var NAN$1 = 0 / 0;
  1455. /** `Object#toString` result references. */
  1456. var symbolTag$1 = '[object Symbol]';
  1457. /** Used to match leading and trailing whitespace. */
  1458. var reTrim$1 = /^\s+|\s+$/g;
  1459. /** Used to detect bad signed hexadecimal string values. */
  1460. var reIsBadHex$1 = /^[-+]0x[0-9a-f]+$/i;
  1461. /** Used to detect binary string values. */
  1462. var reIsBinary$1 = /^0b[01]+$/i;
  1463. /** Used to detect octal string values. */
  1464. var reIsOctal$1 = /^0o[0-7]+$/i;
  1465. /** Built-in method references without a dependency on `root`. */
  1466. var freeParseInt$1 = parseInt;
  1467. /** Detect free variable `global` from Node.js. */
  1468. var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  1469. /** Detect free variable `self`. */
  1470. var freeSelf$1 = typeof self == 'object' && self && self.Object === Object && self;
  1471. /** Used as a reference to the global object. */
  1472. var root$1 = freeGlobal$1 || freeSelf$1 || Function('return this')();
  1473. /** Used for built-in method references. */
  1474. var objectProto$1 = Object.prototype;
  1475. /**
  1476. * Used to resolve the
  1477. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1478. * of values.
  1479. */
  1480. var objectToString$1 = objectProto$1.toString;
  1481. /* Built-in method references for those with the same name as other `lodash` methods. */
  1482. var nativeMax$1 = Math.max,
  1483. nativeMin$1 = Math.min;
  1484. /**
  1485. * Gets the timestamp of the number of milliseconds that have elapsed since
  1486. * the Unix epoch (1 January 1970 00:00:00 UTC).
  1487. *
  1488. * @static
  1489. * @memberOf _
  1490. * @since 2.4.0
  1491. * @category Date
  1492. * @returns {number} Returns the timestamp.
  1493. * @example
  1494. *
  1495. * _.defer(function(stamp) {
  1496. * console.log(_.now() - stamp);
  1497. * }, _.now());
  1498. * // => Logs the number of milliseconds it took for the deferred invocation.
  1499. */
  1500. var now$1 = function() {
  1501. return root$1.Date.now();
  1502. };
  1503. /**
  1504. * Creates a debounced function that delays invoking `func` until after `wait`
  1505. * milliseconds have elapsed since the last time the debounced function was
  1506. * invoked. The debounced function comes with a `cancel` method to cancel
  1507. * delayed `func` invocations and a `flush` method to immediately invoke them.
  1508. * Provide `options` to indicate whether `func` should be invoked on the
  1509. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  1510. * with the last arguments provided to the debounced function. Subsequent
  1511. * calls to the debounced function return the result of the last `func`
  1512. * invocation.
  1513. *
  1514. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  1515. * invoked on the trailing edge of the timeout only if the debounced function
  1516. * is invoked more than once during the `wait` timeout.
  1517. *
  1518. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  1519. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  1520. *
  1521. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  1522. * for details over the differences between `_.debounce` and `_.throttle`.
  1523. *
  1524. * @static
  1525. * @memberOf _
  1526. * @since 0.1.0
  1527. * @category Function
  1528. * @param {Function} func The function to debounce.
  1529. * @param {number} [wait=0] The number of milliseconds to delay.
  1530. * @param {Object} [options={}] The options object.
  1531. * @param {boolean} [options.leading=false]
  1532. * Specify invoking on the leading edge of the timeout.
  1533. * @param {number} [options.maxWait]
  1534. * The maximum time `func` is allowed to be delayed before it's invoked.
  1535. * @param {boolean} [options.trailing=true]
  1536. * Specify invoking on the trailing edge of the timeout.
  1537. * @returns {Function} Returns the new debounced function.
  1538. * @example
  1539. *
  1540. * // Avoid costly calculations while the window size is in flux.
  1541. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  1542. *
  1543. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  1544. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  1545. * 'leading': true,
  1546. * 'trailing': false
  1547. * }));
  1548. *
  1549. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  1550. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  1551. * var source = new EventSource('/stream');
  1552. * jQuery(source).on('message', debounced);
  1553. *
  1554. * // Cancel the trailing debounced invocation.
  1555. * jQuery(window).on('popstate', debounced.cancel);
  1556. */
  1557. function debounce$1(func, wait, options) {
  1558. var lastArgs,
  1559. lastThis,
  1560. maxWait,
  1561. result,
  1562. timerId,
  1563. lastCallTime,
  1564. lastInvokeTime = 0,
  1565. leading = false,
  1566. maxing = false,
  1567. trailing = true;
  1568. if (typeof func != 'function') {
  1569. throw new TypeError(FUNC_ERROR_TEXT$1);
  1570. }
  1571. wait = toNumber$1(wait) || 0;
  1572. if (isObject$1(options)) {
  1573. leading = !!options.leading;
  1574. maxing = 'maxWait' in options;
  1575. maxWait = maxing ? nativeMax$1(toNumber$1(options.maxWait) || 0, wait) : maxWait;
  1576. trailing = 'trailing' in options ? !!options.trailing : trailing;
  1577. }
  1578. function invokeFunc(time) {
  1579. var args = lastArgs,
  1580. thisArg = lastThis;
  1581. lastArgs = lastThis = undefined;
  1582. lastInvokeTime = time;
  1583. result = func.apply(thisArg, args);
  1584. return result;
  1585. }
  1586. function leadingEdge(time) {
  1587. // Reset any `maxWait` timer.
  1588. lastInvokeTime = time;
  1589. // Start the timer for the trailing edge.
  1590. timerId = setTimeout(timerExpired, wait);
  1591. // Invoke the leading edge.
  1592. return leading ? invokeFunc(time) : result;
  1593. }
  1594. function remainingWait(time) {
  1595. var timeSinceLastCall = time - lastCallTime,
  1596. timeSinceLastInvoke = time - lastInvokeTime,
  1597. result = wait - timeSinceLastCall;
  1598. return maxing ? nativeMin$1(result, maxWait - timeSinceLastInvoke) : result;
  1599. }
  1600. function shouldInvoke(time) {
  1601. var timeSinceLastCall = time - lastCallTime,
  1602. timeSinceLastInvoke = time - lastInvokeTime;
  1603. // Either this is the first call, activity has stopped and we're at the
  1604. // trailing edge, the system time has gone backwards and we're treating
  1605. // it as the trailing edge, or we've hit the `maxWait` limit.
  1606. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  1607. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  1608. }
  1609. function timerExpired() {
  1610. var time = now$1();
  1611. if (shouldInvoke(time)) {
  1612. return trailingEdge(time);
  1613. }
  1614. // Restart the timer.
  1615. timerId = setTimeout(timerExpired, remainingWait(time));
  1616. }
  1617. function trailingEdge(time) {
  1618. timerId = undefined;
  1619. // Only invoke if we have `lastArgs` which means `func` has been
  1620. // debounced at least once.
  1621. if (trailing && lastArgs) {
  1622. return invokeFunc(time);
  1623. }
  1624. lastArgs = lastThis = undefined;
  1625. return result;
  1626. }
  1627. function cancel() {
  1628. if (timerId !== undefined) {
  1629. clearTimeout(timerId);
  1630. }
  1631. lastInvokeTime = 0;
  1632. lastArgs = lastCallTime = lastThis = timerId = undefined;
  1633. }
  1634. function flush() {
  1635. return timerId === undefined ? result : trailingEdge(now$1());
  1636. }
  1637. function debounced() {
  1638. var time = now$1(),
  1639. isInvoking = shouldInvoke(time);
  1640. lastArgs = arguments;
  1641. lastThis = this;
  1642. lastCallTime = time;
  1643. if (isInvoking) {
  1644. if (timerId === undefined) {
  1645. return leadingEdge(lastCallTime);
  1646. }
  1647. if (maxing) {
  1648. // Handle invocations in a tight loop.
  1649. timerId = setTimeout(timerExpired, wait);
  1650. return invokeFunc(lastCallTime);
  1651. }
  1652. }
  1653. if (timerId === undefined) {
  1654. timerId = setTimeout(timerExpired, wait);
  1655. }
  1656. return result;
  1657. }
  1658. debounced.cancel = cancel;
  1659. debounced.flush = flush;
  1660. return debounced;
  1661. }
  1662. /**
  1663. * Checks if `value` is the
  1664. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  1665. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  1666. *
  1667. * @static
  1668. * @memberOf _
  1669. * @since 0.1.0
  1670. * @category Lang
  1671. * @param {*} value The value to check.
  1672. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  1673. * @example
  1674. *
  1675. * _.isObject({});
  1676. * // => true
  1677. *
  1678. * _.isObject([1, 2, 3]);
  1679. * // => true
  1680. *
  1681. * _.isObject(_.noop);
  1682. * // => true
  1683. *
  1684. * _.isObject(null);
  1685. * // => false
  1686. */
  1687. function isObject$1(value) {
  1688. var type = typeof value;
  1689. return !!value && (type == 'object' || type == 'function');
  1690. }
  1691. /**
  1692. * Checks if `value` is object-like. A value is object-like if it's not `null`
  1693. * and has a `typeof` result of "object".
  1694. *
  1695. * @static
  1696. * @memberOf _
  1697. * @since 4.0.0
  1698. * @category Lang
  1699. * @param {*} value The value to check.
  1700. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  1701. * @example
  1702. *
  1703. * _.isObjectLike({});
  1704. * // => true
  1705. *
  1706. * _.isObjectLike([1, 2, 3]);
  1707. * // => true
  1708. *
  1709. * _.isObjectLike(_.noop);
  1710. * // => false
  1711. *
  1712. * _.isObjectLike(null);
  1713. * // => false
  1714. */
  1715. function isObjectLike$1(value) {
  1716. return !!value && typeof value == 'object';
  1717. }
  1718. /**
  1719. * Checks if `value` is classified as a `Symbol` primitive or object.
  1720. *
  1721. * @static
  1722. * @memberOf _
  1723. * @since 4.0.0
  1724. * @category Lang
  1725. * @param {*} value The value to check.
  1726. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  1727. * @example
  1728. *
  1729. * _.isSymbol(Symbol.iterator);
  1730. * // => true
  1731. *
  1732. * _.isSymbol('abc');
  1733. * // => false
  1734. */
  1735. function isSymbol$1(value) {
  1736. return typeof value == 'symbol' ||
  1737. (isObjectLike$1(value) && objectToString$1.call(value) == symbolTag$1);
  1738. }
  1739. /**
  1740. * Converts `value` to a number.
  1741. *
  1742. * @static
  1743. * @memberOf _
  1744. * @since 4.0.0
  1745. * @category Lang
  1746. * @param {*} value The value to process.
  1747. * @returns {number} Returns the number.
  1748. * @example
  1749. *
  1750. * _.toNumber(3.2);
  1751. * // => 3.2
  1752. *
  1753. * _.toNumber(Number.MIN_VALUE);
  1754. * // => 5e-324
  1755. *
  1756. * _.toNumber(Infinity);
  1757. * // => Infinity
  1758. *
  1759. * _.toNumber('3.2');
  1760. * // => 3.2
  1761. */
  1762. function toNumber$1(value) {
  1763. if (typeof value == 'number') {
  1764. return value;
  1765. }
  1766. if (isSymbol$1(value)) {
  1767. return NAN$1;
  1768. }
  1769. if (isObject$1(value)) {
  1770. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  1771. value = isObject$1(other) ? (other + '') : other;
  1772. }
  1773. if (typeof value != 'string') {
  1774. return value === 0 ? value : +value;
  1775. }
  1776. value = value.replace(reTrim$1, '');
  1777. var isBinary = reIsBinary$1.test(value);
  1778. return (isBinary || reIsOctal$1.test(value))
  1779. ? freeParseInt$1(value.slice(2), isBinary ? 2 : 8)
  1780. : (reIsBadHex$1.test(value) ? NAN$1 : +value);
  1781. }
  1782. var lodash_debounce = debounce$1;
  1783. /**
  1784. * lodash (Custom Build) <https://lodash.com/>
  1785. * Build: `lodash modularize exports="npm" -o ./`
  1786. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  1787. * Released under MIT license <https://lodash.com/license>
  1788. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  1789. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  1790. */
  1791. /** Used as the `TypeError` message for "Functions" methods. */
  1792. var FUNC_ERROR_TEXT$2 = 'Expected a function';
  1793. /** Used to stand-in for `undefined` hash values. */
  1794. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  1795. /** `Object#toString` result references. */
  1796. var funcTag = '[object Function]',
  1797. genTag = '[object GeneratorFunction]';
  1798. /**
  1799. * Used to match `RegExp`
  1800. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  1801. */
  1802. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  1803. /** Used to detect host constructors (Safari). */
  1804. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  1805. /** Detect free variable `global` from Node.js. */
  1806. var freeGlobal$2 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
  1807. /** Detect free variable `self`. */
  1808. var freeSelf$2 = typeof self == 'object' && self && self.Object === Object && self;
  1809. /** Used as a reference to the global object. */
  1810. var root$2 = freeGlobal$2 || freeSelf$2 || Function('return this')();
  1811. /**
  1812. * Gets the value at `key` of `object`.
  1813. *
  1814. * @private
  1815. * @param {Object} [object] The object to query.
  1816. * @param {string} key The key of the property to get.
  1817. * @returns {*} Returns the property value.
  1818. */
  1819. function getValue(object, key) {
  1820. return object == null ? undefined : object[key];
  1821. }
  1822. /**
  1823. * Checks if `value` is a host object in IE < 9.
  1824. *
  1825. * @private
  1826. * @param {*} value The value to check.
  1827. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  1828. */
  1829. function isHostObject(value) {
  1830. // Many host objects are `Object` objects that can coerce to strings
  1831. // despite having improperly defined `toString` methods.
  1832. var result = false;
  1833. if (value != null && typeof value.toString != 'function') {
  1834. try {
  1835. result = !!(value + '');
  1836. } catch (e) {}
  1837. }
  1838. return result;
  1839. }
  1840. /** Used for built-in method references. */
  1841. var arrayProto = Array.prototype,
  1842. funcProto = Function.prototype,
  1843. objectProto$2 = Object.prototype;
  1844. /** Used to detect overreaching core-js shims. */
  1845. var coreJsData = root$2['__core-js_shared__'];
  1846. /** Used to detect methods masquerading as native. */
  1847. var maskSrcKey = (function() {
  1848. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1849. return uid ? ('Symbol(src)_1.' + uid) : '';
  1850. }());
  1851. /** Used to resolve the decompiled source of functions. */
  1852. var funcToString = funcProto.toString;
  1853. /** Used to check objects for own properties. */
  1854. var hasOwnProperty$1 = objectProto$2.hasOwnProperty;
  1855. /**
  1856. * Used to resolve the
  1857. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1858. * of values.
  1859. */
  1860. var objectToString$2 = objectProto$2.toString;
  1861. /** Used to detect if a method is native. */
  1862. var reIsNative = RegExp('^' +
  1863. funcToString.call(hasOwnProperty$1).replace(reRegExpChar, '\\$&')
  1864. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1865. );
  1866. /** Built-in value references. */
  1867. var splice = arrayProto.splice;
  1868. /* Built-in method references that are verified to be native. */
  1869. var Map$1 = getNative(root$2, 'Map'),
  1870. nativeCreate = getNative(Object, 'create');
  1871. /**
  1872. * Creates a hash object.
  1873. *
  1874. * @private
  1875. * @constructor
  1876. * @param {Array} [entries] The key-value pairs to cache.
  1877. */
  1878. function Hash(entries) {
  1879. var index = -1,
  1880. length = entries ? entries.length : 0;
  1881. this.clear();
  1882. while (++index < length) {
  1883. var entry = entries[index];
  1884. this.set(entry[0], entry[1]);
  1885. }
  1886. }
  1887. /**
  1888. * Removes all key-value entries from the hash.
  1889. *
  1890. * @private
  1891. * @name clear
  1892. * @memberOf Hash
  1893. */
  1894. function hashClear() {
  1895. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1896. }
  1897. /**
  1898. * Removes `key` and its value from the hash.
  1899. *
  1900. * @private
  1901. * @name delete
  1902. * @memberOf Hash
  1903. * @param {Object} hash The hash to modify.
  1904. * @param {string} key The key of the value to remove.
  1905. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1906. */
  1907. function hashDelete(key) {
  1908. return this.has(key) && delete this.__data__[key];
  1909. }
  1910. /**
  1911. * Gets the hash value for `key`.
  1912. *
  1913. * @private
  1914. * @name get
  1915. * @memberOf Hash
  1916. * @param {string} key The key of the value to get.
  1917. * @returns {*} Returns the entry value.
  1918. */
  1919. function hashGet(key) {
  1920. var data = this.__data__;
  1921. if (nativeCreate) {
  1922. var result = data[key];
  1923. return result === HASH_UNDEFINED ? undefined : result;
  1924. }
  1925. return hasOwnProperty$1.call(data, key) ? data[key] : undefined;
  1926. }
  1927. /**
  1928. * Checks if a hash value for `key` exists.
  1929. *
  1930. * @private
  1931. * @name has
  1932. * @memberOf Hash
  1933. * @param {string} key The key of the entry to check.
  1934. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1935. */
  1936. function hashHas(key) {
  1937. var data = this.__data__;
  1938. return nativeCreate ? data[key] !== undefined : hasOwnProperty$1.call(data, key);
  1939. }
  1940. /**
  1941. * Sets the hash `key` to `value`.
  1942. *
  1943. * @private
  1944. * @name set
  1945. * @memberOf Hash
  1946. * @param {string} key The key of the value to set.
  1947. * @param {*} value The value to set.
  1948. * @returns {Object} Returns the hash instance.
  1949. */
  1950. function hashSet(key, value) {
  1951. var data = this.__data__;
  1952. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1953. return this;
  1954. }
  1955. // Add methods to `Hash`.
  1956. Hash.prototype.clear = hashClear;
  1957. Hash.prototype['delete'] = hashDelete;
  1958. Hash.prototype.get = hashGet;
  1959. Hash.prototype.has = hashHas;
  1960. Hash.prototype.set = hashSet;
  1961. /**
  1962. * Creates an list cache object.
  1963. *
  1964. * @private
  1965. * @constructor
  1966. * @param {Array} [entries] The key-value pairs to cache.
  1967. */
  1968. function ListCache(entries) {
  1969. var index = -1,
  1970. length = entries ? entries.length : 0;
  1971. this.clear();
  1972. while (++index < length) {
  1973. var entry = entries[index];
  1974. this.set(entry[0], entry[1]);
  1975. }
  1976. }
  1977. /**
  1978. * Removes all key-value entries from the list cache.
  1979. *
  1980. * @private
  1981. * @name clear
  1982. * @memberOf ListCache
  1983. */
  1984. function listCacheClear() {
  1985. this.__data__ = [];
  1986. }
  1987. /**
  1988. * Removes `key` and its value from the list cache.
  1989. *
  1990. * @private
  1991. * @name delete
  1992. * @memberOf ListCache
  1993. * @param {string} key The key of the value to remove.
  1994. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1995. */
  1996. function listCacheDelete(key) {
  1997. var data = this.__data__,
  1998. index = assocIndexOf(data, key);
  1999. if (index < 0) {
  2000. return false;
  2001. }
  2002. var lastIndex = data.length - 1;
  2003. if (index == lastIndex) {
  2004. data.pop();
  2005. } else {
  2006. splice.call(data, index, 1);
  2007. }
  2008. return true;
  2009. }
  2010. /**
  2011. * Gets the list cache value for `key`.
  2012. *
  2013. * @private
  2014. * @name get
  2015. * @memberOf ListCache
  2016. * @param {string} key The key of the value to get.
  2017. * @returns {*} Returns the entry value.
  2018. */
  2019. function listCacheGet(key) {
  2020. var data = this.__data__,
  2021. index = assocIndexOf(data, key);
  2022. return index < 0 ? undefined : data[index][1];
  2023. }
  2024. /**
  2025. * Checks if a list cache value for `key` exists.
  2026. *
  2027. * @private
  2028. * @name has
  2029. * @memberOf ListCache
  2030. * @param {string} key The key of the entry to check.
  2031. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2032. */
  2033. function listCacheHas(key) {
  2034. return assocIndexOf(this.__data__, key) > -1;
  2035. }
  2036. /**
  2037. * Sets the list cache `key` to `value`.
  2038. *
  2039. * @private
  2040. * @name set
  2041. * @memberOf ListCache
  2042. * @param {string} key The key of the value to set.
  2043. * @param {*} value The value to set.
  2044. * @returns {Object} Returns the list cache instance.
  2045. */
  2046. function listCacheSet(key, value) {
  2047. var data = this.__data__,
  2048. index = assocIndexOf(data, key);
  2049. if (index < 0) {
  2050. data.push([key, value]);
  2051. } else {
  2052. data[index][1] = value;
  2053. }
  2054. return this;
  2055. }
  2056. // Add methods to `ListCache`.
  2057. ListCache.prototype.clear = listCacheClear;
  2058. ListCache.prototype['delete'] = listCacheDelete;
  2059. ListCache.prototype.get = listCacheGet;
  2060. ListCache.prototype.has = listCacheHas;
  2061. ListCache.prototype.set = listCacheSet;
  2062. /**
  2063. * Creates a map cache object to store key-value pairs.
  2064. *
  2065. * @private
  2066. * @constructor
  2067. * @param {Array} [entries] The key-value pairs to cache.
  2068. */
  2069. function MapCache(entries) {
  2070. var index = -1,
  2071. length = entries ? entries.length : 0;
  2072. this.clear();
  2073. while (++index < length) {
  2074. var entry = entries[index];
  2075. this.set(entry[0], entry[1]);
  2076. }
  2077. }
  2078. /**
  2079. * Removes all key-value entries from the map.
  2080. *
  2081. * @private
  2082. * @name clear
  2083. * @memberOf MapCache
  2084. */
  2085. function mapCacheClear() {
  2086. this.__data__ = {
  2087. 'hash': new Hash,
  2088. 'map': new (Map$1 || ListCache),
  2089. 'string': new Hash
  2090. };
  2091. }
  2092. /**
  2093. * Removes `key` and its value from the map.
  2094. *
  2095. * @private
  2096. * @name delete
  2097. * @memberOf MapCache
  2098. * @param {string} key The key of the value to remove.
  2099. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2100. */
  2101. function mapCacheDelete(key) {
  2102. return getMapData(this, key)['delete'](key);
  2103. }
  2104. /**
  2105. * Gets the map value for `key`.
  2106. *
  2107. * @private
  2108. * @name get
  2109. * @memberOf MapCache
  2110. * @param {string} key The key of the value to get.
  2111. * @returns {*} Returns the entry value.
  2112. */
  2113. function mapCacheGet(key) {
  2114. return getMapData(this, key).get(key);
  2115. }
  2116. /**
  2117. * Checks if a map value for `key` exists.
  2118. *
  2119. * @private
  2120. * @name has
  2121. * @memberOf MapCache
  2122. * @param {string} key The key of the entry to check.
  2123. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2124. */
  2125. function mapCacheHas(key) {
  2126. return getMapData(this, key).has(key);
  2127. }
  2128. /**
  2129. * Sets the map `key` to `value`.
  2130. *
  2131. * @private
  2132. * @name set
  2133. * @memberOf MapCache
  2134. * @param {string} key The key of the value to set.
  2135. * @param {*} value The value to set.
  2136. * @returns {Object} Returns the map cache instance.
  2137. */
  2138. function mapCacheSet(key, value) {
  2139. getMapData(this, key).set(key, value);
  2140. return this;
  2141. }
  2142. // Add methods to `MapCache`.
  2143. MapCache.prototype.clear = mapCacheClear;
  2144. MapCache.prototype['delete'] = mapCacheDelete;
  2145. MapCache.prototype.get = mapCacheGet;
  2146. MapCache.prototype.has = mapCacheHas;
  2147. MapCache.prototype.set = mapCacheSet;
  2148. /**
  2149. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2150. *
  2151. * @private
  2152. * @param {Array} array The array to inspect.
  2153. * @param {*} key The key to search for.
  2154. * @returns {number} Returns the index of the matched value, else `-1`.
  2155. */
  2156. function assocIndexOf(array, key) {
  2157. var length = array.length;
  2158. while (length--) {
  2159. if (eq(array[length][0], key)) {
  2160. return length;
  2161. }
  2162. }
  2163. return -1;
  2164. }
  2165. /**
  2166. * The base implementation of `_.isNative` without bad shim checks.
  2167. *
  2168. * @private
  2169. * @param {*} value The value to check.
  2170. * @returns {boolean} Returns `true` if `value` is a native function,
  2171. * else `false`.
  2172. */
  2173. function baseIsNative(value) {
  2174. if (!isObject$2(value) || isMasked(value)) {
  2175. return false;
  2176. }
  2177. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  2178. return pattern.test(toSource(value));
  2179. }
  2180. /**
  2181. * Gets the data for `map`.
  2182. *
  2183. * @private
  2184. * @param {Object} map The map to query.
  2185. * @param {string} key The reference key.
  2186. * @returns {*} Returns the map data.
  2187. */
  2188. function getMapData(map, key) {
  2189. var data = map.__data__;
  2190. return isKeyable(key)
  2191. ? data[typeof key == 'string' ? 'string' : 'hash']
  2192. : data.map;
  2193. }
  2194. /**
  2195. * Gets the native function at `key` of `object`.
  2196. *
  2197. * @private
  2198. * @param {Object} object The object to query.
  2199. * @param {string} key The key of the method to get.
  2200. * @returns {*} Returns the function if it's native, else `undefined`.
  2201. */
  2202. function getNative(object, key) {
  2203. var value = getValue(object, key);
  2204. return baseIsNative(value) ? value : undefined;
  2205. }
  2206. /**
  2207. * Checks if `value` is suitable for use as unique object key.
  2208. *
  2209. * @private
  2210. * @param {*} value The value to check.
  2211. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  2212. */
  2213. function isKeyable(value) {
  2214. var type = typeof value;
  2215. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  2216. ? (value !== '__proto__')
  2217. : (value === null);
  2218. }
  2219. /**
  2220. * Checks if `func` has its source masked.
  2221. *
  2222. * @private
  2223. * @param {Function} func The function to check.
  2224. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  2225. */
  2226. function isMasked(func) {
  2227. return !!maskSrcKey && (maskSrcKey in func);
  2228. }
  2229. /**
  2230. * Converts `func` to its source code.
  2231. *
  2232. * @private
  2233. * @param {Function} func The function to process.
  2234. * @returns {string} Returns the source code.
  2235. */
  2236. function toSource(func) {
  2237. if (func != null) {
  2238. try {
  2239. return funcToString.call(func);
  2240. } catch (e) {}
  2241. try {
  2242. return (func + '');
  2243. } catch (e) {}
  2244. }
  2245. return '';
  2246. }
  2247. /**
  2248. * Creates a function that memoizes the result of `func`. If `resolver` is
  2249. * provided, it determines the cache key for storing the result based on the
  2250. * arguments provided to the memoized function. By default, the first argument
  2251. * provided to the memoized function is used as the map cache key. The `func`
  2252. * is invoked with the `this` binding of the memoized function.
  2253. *
  2254. * **Note:** The cache is exposed as the `cache` property on the memoized
  2255. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  2256. * constructor with one whose instances implement the
  2257. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  2258. * method interface of `delete`, `get`, `has`, and `set`.
  2259. *
  2260. * @static
  2261. * @memberOf _
  2262. * @since 0.1.0
  2263. * @category Function
  2264. * @param {Function} func The function to have its output memoized.
  2265. * @param {Function} [resolver] The function to resolve the cache key.
  2266. * @returns {Function} Returns the new memoized function.
  2267. * @example
  2268. *
  2269. * var object = { 'a': 1, 'b': 2 };
  2270. * var other = { 'c': 3, 'd': 4 };
  2271. *
  2272. * var values = _.memoize(_.values);
  2273. * values(object);
  2274. * // => [1, 2]
  2275. *
  2276. * values(other);
  2277. * // => [3, 4]
  2278. *
  2279. * object.a = 2;
  2280. * values(object);
  2281. * // => [1, 2]
  2282. *
  2283. * // Modify the result cache.
  2284. * values.cache.set(object, ['a', 'b']);
  2285. * values(object);
  2286. * // => ['a', 'b']
  2287. *
  2288. * // Replace `_.memoize.Cache`.
  2289. * _.memoize.Cache = WeakMap;
  2290. */
  2291. function memoize(func, resolver) {
  2292. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  2293. throw new TypeError(FUNC_ERROR_TEXT$2);
  2294. }
  2295. var memoized = function() {
  2296. var args = arguments,
  2297. key = resolver ? resolver.apply(this, args) : args[0],
  2298. cache = memoized.cache;
  2299. if (cache.has(key)) {
  2300. return cache.get(key);
  2301. }
  2302. var result = func.apply(this, args);
  2303. memoized.cache = cache.set(key, result);
  2304. return result;
  2305. };
  2306. memoized.cache = new (memoize.Cache || MapCache);
  2307. return memoized;
  2308. }
  2309. // Assign cache to `_.memoize`.
  2310. memoize.Cache = MapCache;
  2311. /**
  2312. * Performs a
  2313. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2314. * comparison between two values to determine if they are equivalent.
  2315. *
  2316. * @static
  2317. * @memberOf _
  2318. * @since 4.0.0
  2319. * @category Lang
  2320. * @param {*} value The value to compare.
  2321. * @param {*} other The other value to compare.
  2322. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2323. * @example
  2324. *
  2325. * var object = { 'a': 1 };
  2326. * var other = { 'a': 1 };
  2327. *
  2328. * _.eq(object, object);
  2329. * // => true
  2330. *
  2331. * _.eq(object, other);
  2332. * // => false
  2333. *
  2334. * _.eq('a', 'a');
  2335. * // => true
  2336. *
  2337. * _.eq('a', Object('a'));
  2338. * // => false
  2339. *
  2340. * _.eq(NaN, NaN);
  2341. * // => true
  2342. */
  2343. function eq(value, other) {
  2344. return value === other || (value !== value && other !== other);
  2345. }
  2346. /**
  2347. * Checks if `value` is classified as a `Function` object.
  2348. *
  2349. * @static
  2350. * @memberOf _
  2351. * @since 0.1.0
  2352. * @category Lang
  2353. * @param {*} value The value to check.
  2354. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  2355. * @example
  2356. *
  2357. * _.isFunction(_);
  2358. * // => true
  2359. *
  2360. * _.isFunction(/abc/);
  2361. * // => false
  2362. */
  2363. function isFunction(value) {
  2364. // The use of `Object#toString` avoids issues with the `typeof` operator
  2365. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  2366. var tag = isObject$2(value) ? objectToString$2.call(value) : '';
  2367. return tag == funcTag || tag == genTag;
  2368. }
  2369. /**
  2370. * Checks if `value` is the
  2371. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  2372. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  2373. *
  2374. * @static
  2375. * @memberOf _
  2376. * @since 0.1.0
  2377. * @category Lang
  2378. * @param {*} value The value to check.
  2379. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  2380. * @example
  2381. *
  2382. * _.isObject({});
  2383. * // => true
  2384. *
  2385. * _.isObject([1, 2, 3]);
  2386. * // => true
  2387. *
  2388. * _.isObject(_.noop);
  2389. * // => true
  2390. *
  2391. * _.isObject(null);
  2392. * // => false
  2393. */
  2394. function isObject$2(value) {
  2395. var type = typeof value;
  2396. return !!value && (type == 'object' || type == 'function');
  2397. }
  2398. var lodash_memoize = memoize;
  2399. /**
  2400. * A collection of shims that provide minimal functionality of the ES6 collections.
  2401. *
  2402. * These implementations are not meant to be used outside of the ResizeObserver
  2403. * modules as they cover only a limited range of use cases.
  2404. */
  2405. /* eslint-disable require-jsdoc, valid-jsdoc */
  2406. var MapShim = (function () {
  2407. if (typeof Map !== 'undefined') {
  2408. return Map;
  2409. }
  2410. /**
  2411. * Returns index in provided array that matches the specified key.
  2412. *
  2413. * @param {Array<Array>} arr
  2414. * @param {*} key
  2415. * @returns {number}
  2416. */
  2417. function getIndex(arr, key) {
  2418. var result = -1;
  2419. arr.some(function (entry, index) {
  2420. if (entry[0] === key) {
  2421. result = index;
  2422. return true;
  2423. }
  2424. return false;
  2425. });
  2426. return result;
  2427. }
  2428. return /** @class */ (function () {
  2429. function class_1() {
  2430. this.__entries__ = [];
  2431. }
  2432. Object.defineProperty(class_1.prototype, "size", {
  2433. /**
  2434. * @returns {boolean}
  2435. */
  2436. get: function () {
  2437. return this.__entries__.length;
  2438. },
  2439. enumerable: true,
  2440. configurable: true
  2441. });
  2442. /**
  2443. * @param {*} key
  2444. * @returns {*}
  2445. */
  2446. class_1.prototype.get = function (key) {
  2447. var index = getIndex(this.__entries__, key);
  2448. var entry = this.__entries__[index];
  2449. return entry && entry[1];
  2450. };
  2451. /**
  2452. * @param {*} key
  2453. * @param {*} value
  2454. * @returns {void}
  2455. */
  2456. class_1.prototype.set = function (key, value) {
  2457. var index = getIndex(this.__entries__, key);
  2458. if (~index) {
  2459. this.__entries__[index][1] = value;
  2460. }
  2461. else {
  2462. this.__entries__.push([key, value]);
  2463. }
  2464. };
  2465. /**
  2466. * @param {*} key
  2467. * @returns {void}
  2468. */
  2469. class_1.prototype.delete = function (key) {
  2470. var entries = this.__entries__;
  2471. var index = getIndex(entries, key);
  2472. if (~index) {
  2473. entries.splice(index, 1);
  2474. }
  2475. };
  2476. /**
  2477. * @param {*} key
  2478. * @returns {void}
  2479. */
  2480. class_1.prototype.has = function (key) {
  2481. return !!~getIndex(this.__entries__, key);
  2482. };
  2483. /**
  2484. * @returns {void}
  2485. */
  2486. class_1.prototype.clear = function () {
  2487. this.__entries__.splice(0);
  2488. };
  2489. /**
  2490. * @param {Function} callback
  2491. * @param {*} [ctx=null]
  2492. * @returns {void}
  2493. */
  2494. class_1.prototype.forEach = function (callback, ctx) {
  2495. if (ctx === void 0) { ctx = null; }
  2496. for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
  2497. var entry = _a[_i];
  2498. callback.call(ctx, entry[1], entry[0]);
  2499. }
  2500. };
  2501. return class_1;
  2502. }());
  2503. })();
  2504. /**
  2505. * Detects whether window and document objects are available in current environment.
  2506. */
  2507. var isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined' && window.document === document;
  2508. // Returns global object of a current environment.
  2509. var global$1 = (function () {
  2510. if (typeof global !== 'undefined' && global.Math === Math) {
  2511. return global;
  2512. }
  2513. if (typeof self !== 'undefined' && self.Math === Math) {
  2514. return self;
  2515. }
  2516. if (typeof window !== 'undefined' && window.Math === Math) {
  2517. return window;
  2518. }
  2519. // eslint-disable-next-line no-new-func
  2520. return Function('return this')();
  2521. })();
  2522. /**
  2523. * A shim for the requestAnimationFrame which falls back to the setTimeout if
  2524. * first one is not supported.
  2525. *
  2526. * @returns {number} Requests' identifier.
  2527. */
  2528. var requestAnimationFrame$1 = (function () {
  2529. if (typeof requestAnimationFrame === 'function') {
  2530. // It's required to use a bounded function because IE sometimes throws
  2531. // an "Invalid calling object" error if rAF is invoked without the global
  2532. // object on the left hand side.
  2533. return requestAnimationFrame.bind(global$1);
  2534. }
  2535. return function (callback) { return setTimeout(function () { return callback(Date.now()); }, 1000 / 60); };
  2536. })();
  2537. // Defines minimum timeout before adding a trailing call.
  2538. var trailingTimeout = 2;
  2539. /**
  2540. * Creates a wrapper function which ensures that provided callback will be
  2541. * invoked only once during the specified delay period.
  2542. *
  2543. * @param {Function} callback - Function to be invoked after the delay period.
  2544. * @param {number} delay - Delay after which to invoke callback.
  2545. * @returns {Function}
  2546. */
  2547. function throttle$1 (callback, delay) {
  2548. var leadingCall = false, trailingCall = false, lastCallTime = 0;
  2549. /**
  2550. * Invokes the original callback function and schedules new invocation if
  2551. * the "proxy" was called during current request.
  2552. *
  2553. * @returns {void}
  2554. */
  2555. function resolvePending() {
  2556. if (leadingCall) {
  2557. leadingCall = false;
  2558. callback();
  2559. }
  2560. if (trailingCall) {
  2561. proxy();
  2562. }
  2563. }
  2564. /**
  2565. * Callback invoked after the specified delay. It will further postpone
  2566. * invocation of the original function delegating it to the
  2567. * requestAnimationFrame.
  2568. *
  2569. * @returns {void}
  2570. */
  2571. function timeoutCallback() {
  2572. requestAnimationFrame$1(resolvePending);
  2573. }
  2574. /**
  2575. * Schedules invocation of the original function.
  2576. *
  2577. * @returns {void}
  2578. */
  2579. function proxy() {
  2580. var timeStamp = Date.now();
  2581. if (leadingCall) {
  2582. // Reject immediately following calls.
  2583. if (timeStamp - lastCallTime < trailingTimeout) {
  2584. return;
  2585. }
  2586. // Schedule new call to be in invoked when the pending one is resolved.
  2587. // This is important for "transitions" which never actually start
  2588. // immediately so there is a chance that we might miss one if change
  2589. // happens amids the pending invocation.
  2590. trailingCall = true;
  2591. }
  2592. else {
  2593. leadingCall = true;
  2594. trailingCall = false;
  2595. setTimeout(timeoutCallback, delay);
  2596. }
  2597. lastCallTime = timeStamp;
  2598. }
  2599. return proxy;
  2600. }
  2601. // Minimum delay before invoking the update of observers.
  2602. var REFRESH_DELAY = 20;
  2603. // A list of substrings of CSS properties used to find transition events that
  2604. // might affect dimensions of observed elements.
  2605. var transitionKeys = ['top', 'right', 'bottom', 'left', 'width', 'height', 'size', 'weight'];
  2606. // Check if MutationObserver is available.
  2607. var mutationObserverSupported = typeof MutationObserver !== 'undefined';
  2608. /**
  2609. * Singleton controller class which handles updates of ResizeObserver instances.
  2610. */
  2611. var ResizeObserverController = /** @class */ (function () {
  2612. /**
  2613. * Creates a new instance of ResizeObserverController.
  2614. *
  2615. * @private
  2616. */
  2617. function ResizeObserverController() {
  2618. /**
  2619. * Indicates whether DOM listeners have been added.
  2620. *
  2621. * @private {boolean}
  2622. */
  2623. this.connected_ = false;
  2624. /**
  2625. * Tells that controller has subscribed for Mutation Events.
  2626. *
  2627. * @private {boolean}
  2628. */
  2629. this.mutationEventsAdded_ = false;
  2630. /**
  2631. * Keeps reference to the instance of MutationObserver.
  2632. *
  2633. * @private {MutationObserver}
  2634. */
  2635. this.mutationsObserver_ = null;
  2636. /**
  2637. * A list of connected observers.
  2638. *
  2639. * @private {Array<ResizeObserverSPI>}
  2640. */
  2641. this.observers_ = [];
  2642. this.onTransitionEnd_ = this.onTransitionEnd_.bind(this);
  2643. this.refresh = throttle$1(this.refresh.bind(this), REFRESH_DELAY);
  2644. }
  2645. /**
  2646. * Adds observer to observers list.
  2647. *
  2648. * @param {ResizeObserverSPI} observer - Observer to be added.
  2649. * @returns {void}
  2650. */
  2651. ResizeObserverController.prototype.addObserver = function (observer) {
  2652. if (!~this.observers_.indexOf(observer)) {
  2653. this.observers_.push(observer);
  2654. }
  2655. // Add listeners if they haven't been added yet.
  2656. if (!this.connected_) {
  2657. this.connect_();
  2658. }
  2659. };
  2660. /**
  2661. * Removes observer from observers list.
  2662. *
  2663. * @param {ResizeObserverSPI} observer - Observer to be removed.
  2664. * @returns {void}
  2665. */
  2666. ResizeObserverController.prototype.removeObserver = function (observer) {
  2667. var observers = this.observers_;
  2668. var index = observers.indexOf(observer);
  2669. // Remove observer if it's present in registry.
  2670. if (~index) {
  2671. observers.splice(index, 1);
  2672. }
  2673. // Remove listeners if controller has no connected observers.
  2674. if (!observers.length && this.connected_) {
  2675. this.disconnect_();
  2676. }
  2677. };
  2678. /**
  2679. * Invokes the update of observers. It will continue running updates insofar
  2680. * it detects changes.
  2681. *
  2682. * @returns {void}
  2683. */
  2684. ResizeObserverController.prototype.refresh = function () {
  2685. var changesDetected = this.updateObservers_();
  2686. // Continue running updates if changes have been detected as there might
  2687. // be future ones caused by CSS transitions.
  2688. if (changesDetected) {
  2689. this.refresh();
  2690. }
  2691. };
  2692. /**
  2693. * Updates every observer from observers list and notifies them of queued
  2694. * entries.
  2695. *
  2696. * @private
  2697. * @returns {boolean} Returns "true" if any observer has detected changes in
  2698. * dimensions of it's elements.
  2699. */
  2700. ResizeObserverController.prototype.updateObservers_ = function () {
  2701. // Collect observers that have active observations.
  2702. var activeObservers = this.observers_.filter(function (observer) {
  2703. return observer.gatherActive(), observer.hasActive();
  2704. });
  2705. // Deliver notifications in a separate cycle in order to avoid any
  2706. // collisions between observers, e.g. when multiple instances of
  2707. // ResizeObserver are tracking the same element and the callback of one
  2708. // of them changes content dimensions of the observed target. Sometimes
  2709. // this may result in notifications being blocked for the rest of observers.
  2710. activeObservers.forEach(function (observer) { return observer.broadcastActive(); });
  2711. return activeObservers.length > 0;
  2712. };
  2713. /**
  2714. * Initializes DOM listeners.
  2715. *
  2716. * @private
  2717. * @returns {void}
  2718. */
  2719. ResizeObserverController.prototype.connect_ = function () {
  2720. // Do nothing if running in a non-browser environment or if listeners
  2721. // have been already added.
  2722. if (!isBrowser || this.connected_) {
  2723. return;
  2724. }
  2725. // Subscription to the "Transitionend" event is used as a workaround for
  2726. // delayed transitions. This way it's possible to capture at least the
  2727. // final state of an element.
  2728. document.addEventListener('transitionend', this.onTransitionEnd_);
  2729. window.addEventListener('resize', this.refresh);
  2730. if (mutationObserverSupported) {
  2731. this.mutationsObserver_ = new MutationObserver(this.refresh);
  2732. this.mutationsObserver_.observe(document, {
  2733. attributes: true,
  2734. childList: true,
  2735. characterData: true,
  2736. subtree: true
  2737. });
  2738. }
  2739. else {
  2740. document.addEventListener('DOMSubtreeModified', this.refresh);
  2741. this.mutationEventsAdded_ = true;
  2742. }
  2743. this.connected_ = true;
  2744. };
  2745. /**
  2746. * Removes DOM listeners.
  2747. *
  2748. * @private
  2749. * @returns {void}
  2750. */
  2751. ResizeObserverController.prototype.disconnect_ = function () {
  2752. // Do nothing if running in a non-browser environment or if listeners
  2753. // have been already removed.
  2754. if (!isBrowser || !this.connected_) {
  2755. return;
  2756. }
  2757. document.removeEventListener('transitionend', this.onTransitionEnd_);
  2758. window.removeEventListener('resize', this.refresh);
  2759. if (this.mutationsObserver_) {
  2760. this.mutationsObserver_.disconnect();
  2761. }
  2762. if (this.mutationEventsAdded_) {
  2763. document.removeEventListener('DOMSubtreeModified', this.refresh);
  2764. }
  2765. this.mutationsObserver_ = null;
  2766. this.mutationEventsAdded_ = false;
  2767. this.connected_ = false;
  2768. };
  2769. /**
  2770. * "Transitionend" event handler.
  2771. *
  2772. * @private
  2773. * @param {TransitionEvent} event
  2774. * @returns {void}
  2775. */
  2776. ResizeObserverController.prototype.onTransitionEnd_ = function (_a) {
  2777. var _b = _a.propertyName, propertyName = _b === void 0 ? '' : _b;
  2778. // Detect whether transition may affect dimensions of an element.
  2779. var isReflowProperty = transitionKeys.some(function (key) {
  2780. return !!~propertyName.indexOf(key);
  2781. });
  2782. if (isReflowProperty) {
  2783. this.refresh();
  2784. }
  2785. };
  2786. /**
  2787. * Returns instance of the ResizeObserverController.
  2788. *
  2789. * @returns {ResizeObserverController}
  2790. */
  2791. ResizeObserverController.getInstance = function () {
  2792. if (!this.instance_) {
  2793. this.instance_ = new ResizeObserverController();
  2794. }
  2795. return this.instance_;
  2796. };
  2797. /**
  2798. * Holds reference to the controller's instance.
  2799. *
  2800. * @private {ResizeObserverController}
  2801. */
  2802. ResizeObserverController.instance_ = null;
  2803. return ResizeObserverController;
  2804. }());
  2805. /**
  2806. * Defines non-writable/enumerable properties of the provided target object.
  2807. *
  2808. * @param {Object} target - Object for which to define properties.
  2809. * @param {Object} props - Properties to be defined.
  2810. * @returns {Object} Target object.
  2811. */
  2812. var defineConfigurable = (function (target, props) {
  2813. for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
  2814. var key = _a[_i];
  2815. Object.defineProperty(target, key, {
  2816. value: props[key],
  2817. enumerable: false,
  2818. writable: false,
  2819. configurable: true
  2820. });
  2821. }
  2822. return target;
  2823. });
  2824. /**
  2825. * Returns the global object associated with provided element.
  2826. *
  2827. * @param {Object} target
  2828. * @returns {Object}
  2829. */
  2830. var getWindowOf = (function (target) {
  2831. // Assume that the element is an instance of Node, which means that it
  2832. // has the "ownerDocument" property from which we can retrieve a
  2833. // corresponding global object.
  2834. var ownerGlobal = target && target.ownerDocument && target.ownerDocument.defaultView;
  2835. // Return the local global object if it's not possible extract one from
  2836. // provided element.
  2837. return ownerGlobal || global$1;
  2838. });
  2839. // Placeholder of an empty content rectangle.
  2840. var emptyRect = createRectInit(0, 0, 0, 0);
  2841. /**
  2842. * Converts provided string to a number.
  2843. *
  2844. * @param {number|string} value
  2845. * @returns {number}
  2846. */
  2847. function toFloat(value) {
  2848. return parseFloat(value) || 0;
  2849. }
  2850. /**
  2851. * Extracts borders size from provided styles.
  2852. *
  2853. * @param {CSSStyleDeclaration} styles
  2854. * @param {...string} positions - Borders positions (top, right, ...)
  2855. * @returns {number}
  2856. */
  2857. function getBordersSize(styles) {
  2858. var positions = [];
  2859. for (var _i = 1; _i < arguments.length; _i++) {
  2860. positions[_i - 1] = arguments[_i];
  2861. }
  2862. return positions.reduce(function (size, position) {
  2863. var value = styles['border-' + position + '-width'];
  2864. return size + toFloat(value);
  2865. }, 0);
  2866. }
  2867. /**
  2868. * Extracts paddings sizes from provided styles.
  2869. *
  2870. * @param {CSSStyleDeclaration} styles
  2871. * @returns {Object} Paddings box.
  2872. */
  2873. function getPaddings(styles) {
  2874. var positions = ['top', 'right', 'bottom', 'left'];
  2875. var paddings = {};
  2876. for (var _i = 0, positions_1 = positions; _i < positions_1.length; _i++) {
  2877. var position = positions_1[_i];
  2878. var value = styles['padding-' + position];
  2879. paddings[position] = toFloat(value);
  2880. }
  2881. return paddings;
  2882. }
  2883. /**
  2884. * Calculates content rectangle of provided SVG element.
  2885. *
  2886. * @param {SVGGraphicsElement} target - Element content rectangle of which needs
  2887. * to be calculated.
  2888. * @returns {DOMRectInit}
  2889. */
  2890. function getSVGContentRect(target) {
  2891. var bbox = target.getBBox();
  2892. return createRectInit(0, 0, bbox.width, bbox.height);
  2893. }
  2894. /**
  2895. * Calculates content rectangle of provided HTMLElement.
  2896. *
  2897. * @param {HTMLElement} target - Element for which to calculate the content rectangle.
  2898. * @returns {DOMRectInit}
  2899. */
  2900. function getHTMLElementContentRect(target) {
  2901. // Client width & height properties can't be
  2902. // used exclusively as they provide rounded values.
  2903. var clientWidth = target.clientWidth, clientHeight = target.clientHeight;
  2904. // By this condition we can catch all non-replaced inline, hidden and
  2905. // detached elements. Though elements with width & height properties less
  2906. // than 0.5 will be discarded as well.
  2907. //
  2908. // Without it we would need to implement separate methods for each of
  2909. // those cases and it's not possible to perform a precise and performance
  2910. // effective test for hidden elements. E.g. even jQuery's ':visible' filter
  2911. // gives wrong results for elements with width & height less than 0.5.
  2912. if (!clientWidth && !clientHeight) {
  2913. return emptyRect;
  2914. }
  2915. var styles = getWindowOf(target).getComputedStyle(target);
  2916. var paddings = getPaddings(styles);
  2917. var horizPad = paddings.left + paddings.right;
  2918. var vertPad = paddings.top + paddings.bottom;
  2919. // Computed styles of width & height are being used because they are the
  2920. // only dimensions available to JS that contain non-rounded values. It could
  2921. // be possible to utilize the getBoundingClientRect if only it's data wasn't
  2922. // affected by CSS transformations let alone paddings, borders and scroll bars.
  2923. var width = toFloat(styles.width), height = toFloat(styles.height);
  2924. // Width & height include paddings and borders when the 'border-box' box
  2925. // model is applied (except for IE).
  2926. if (styles.boxSizing === 'border-box') {
  2927. // Following conditions are required to handle Internet Explorer which
  2928. // doesn't include paddings and borders to computed CSS dimensions.
  2929. //
  2930. // We can say that if CSS dimensions + paddings are equal to the "client"
  2931. // properties then it's either IE, and thus we don't need to subtract
  2932. // anything, or an element merely doesn't have paddings/borders styles.
  2933. if (Math.round(width + horizPad) !== clientWidth) {
  2934. width -= getBordersSize(styles, 'left', 'right') + horizPad;
  2935. }
  2936. if (Math.round(height + vertPad) !== clientHeight) {
  2937. height -= getBordersSize(styles, 'top', 'bottom') + vertPad;
  2938. }
  2939. }
  2940. // Following steps can't be applied to the document's root element as its
  2941. // client[Width/Height] properties represent viewport area of the window.
  2942. // Besides, it's as well not necessary as the <html> itself neither has
  2943. // rendered scroll bars nor it can be clipped.
  2944. if (!isDocumentElement(target)) {
  2945. // In some browsers (only in Firefox, actually) CSS width & height
  2946. // include scroll bars size which can be removed at this step as scroll
  2947. // bars are the only difference between rounded dimensions + paddings
  2948. // and "client" properties, though that is not always true in Chrome.
  2949. var vertScrollbar = Math.round(width + horizPad) - clientWidth;
  2950. var horizScrollbar = Math.round(height + vertPad) - clientHeight;
  2951. // Chrome has a rather weird rounding of "client" properties.
  2952. // E.g. for an element with content width of 314.2px it sometimes gives
  2953. // the client width of 315px and for the width of 314.7px it may give
  2954. // 314px. And it doesn't happen all the time. So just ignore this delta
  2955. // as a non-relevant.
  2956. if (Math.abs(vertScrollbar) !== 1) {
  2957. width -= vertScrollbar;
  2958. }
  2959. if (Math.abs(horizScrollbar) !== 1) {
  2960. height -= horizScrollbar;
  2961. }
  2962. }
  2963. return createRectInit(paddings.left, paddings.top, width, height);
  2964. }
  2965. /**
  2966. * Checks whether provided element is an instance of the SVGGraphicsElement.
  2967. *
  2968. * @param {Element} target - Element to be checked.
  2969. * @returns {boolean}
  2970. */
  2971. var isSVGGraphicsElement = (function () {
  2972. // Some browsers, namely IE and Edge, don't have the SVGGraphicsElement
  2973. // interface.
  2974. if (typeof SVGGraphicsElement !== 'undefined') {
  2975. return function (target) { return target instanceof getWindowOf(target).SVGGraphicsElement; };
  2976. }
  2977. // If it's so, then check that element is at least an instance of the
  2978. // SVGElement and that it has the "getBBox" method.
  2979. // eslint-disable-next-line no-extra-parens
  2980. return function (target) { return (target instanceof getWindowOf(target).SVGElement &&
  2981. typeof target.getBBox === 'function'); };
  2982. })();
  2983. /**
  2984. * Checks whether provided element is a document element (<html>).
  2985. *
  2986. * @param {Element} target - Element to be checked.
  2987. * @returns {boolean}
  2988. */
  2989. function isDocumentElement(target) {
  2990. return target === getWindowOf(target).document.documentElement;
  2991. }
  2992. /**
  2993. * Calculates an appropriate content rectangle for provided html or svg element.
  2994. *
  2995. * @param {Element} target - Element content rectangle of which needs to be calculated.
  2996. * @returns {DOMRectInit}
  2997. */
  2998. function getContentRect(target) {
  2999. if (!isBrowser) {
  3000. return emptyRect;
  3001. }
  3002. if (isSVGGraphicsElement(target)) {
  3003. return getSVGContentRect(target);
  3004. }
  3005. return getHTMLElementContentRect(target);
  3006. }
  3007. /**
  3008. * Creates rectangle with an interface of the DOMRectReadOnly.
  3009. * Spec: https://drafts.fxtf.org/geometry/#domrectreadonly
  3010. *
  3011. * @param {DOMRectInit} rectInit - Object with rectangle's x/y coordinates and dimensions.
  3012. * @returns {DOMRectReadOnly}
  3013. */
  3014. function createReadOnlyRect(_a) {
  3015. var x = _a.x, y = _a.y, width = _a.width, height = _a.height;
  3016. // If DOMRectReadOnly is available use it as a prototype for the rectangle.
  3017. var Constr = typeof DOMRectReadOnly !== 'undefined' ? DOMRectReadOnly : Object;
  3018. var rect = Object.create(Constr.prototype);
  3019. // Rectangle's properties are not writable and non-enumerable.
  3020. defineConfigurable(rect, {
  3021. x: x, y: y, width: width, height: height,
  3022. top: y,
  3023. right: x + width,
  3024. bottom: height + y,
  3025. left: x
  3026. });
  3027. return rect;
  3028. }
  3029. /**
  3030. * Creates DOMRectInit object based on the provided dimensions and the x/y coordinates.
  3031. * Spec: https://drafts.fxtf.org/geometry/#dictdef-domrectinit
  3032. *
  3033. * @param {number} x - X coordinate.
  3034. * @param {number} y - Y coordinate.
  3035. * @param {number} width - Rectangle's width.
  3036. * @param {number} height - Rectangle's height.
  3037. * @returns {DOMRectInit}
  3038. */
  3039. function createRectInit(x, y, width, height) {
  3040. return { x: x, y: y, width: width, height: height };
  3041. }
  3042. /**
  3043. * Class that is responsible for computations of the content rectangle of
  3044. * provided DOM element and for keeping track of it's changes.
  3045. */
  3046. var ResizeObservation = /** @class */ (function () {
  3047. /**
  3048. * Creates an instance of ResizeObservation.
  3049. *
  3050. * @param {Element} target - Element to be observed.
  3051. */
  3052. function ResizeObservation(target) {
  3053. /**
  3054. * Broadcasted width of content rectangle.
  3055. *
  3056. * @type {number}
  3057. */
  3058. this.broadcastWidth = 0;
  3059. /**
  3060. * Broadcasted height of content rectangle.
  3061. *
  3062. * @type {number}
  3063. */
  3064. this.broadcastHeight = 0;
  3065. /**
  3066. * Reference to the last observed content rectangle.
  3067. *
  3068. * @private {DOMRectInit}
  3069. */
  3070. this.contentRect_ = createRectInit(0, 0, 0, 0);
  3071. this.target = target;
  3072. }
  3073. /**
  3074. * Updates content rectangle and tells whether it's width or height properties
  3075. * have changed since the last broadcast.
  3076. *
  3077. * @returns {boolean}
  3078. */
  3079. ResizeObservation.prototype.isActive = function () {
  3080. var rect = getContentRect(this.target);
  3081. this.contentRect_ = rect;
  3082. return (rect.width !== this.broadcastWidth ||
  3083. rect.height !== this.broadcastHeight);
  3084. };
  3085. /**
  3086. * Updates 'broadcastWidth' and 'broadcastHeight' properties with a data
  3087. * from the corresponding properties of the last observed content rectangle.
  3088. *
  3089. * @returns {DOMRectInit} Last observed content rectangle.
  3090. */
  3091. ResizeObservation.prototype.broadcastRect = function () {
  3092. var rect = this.contentRect_;
  3093. this.broadcastWidth = rect.width;
  3094. this.broadcastHeight = rect.height;
  3095. return rect;
  3096. };
  3097. return ResizeObservation;
  3098. }());
  3099. var ResizeObserverEntry = /** @class */ (function () {
  3100. /**
  3101. * Creates an instance of ResizeObserverEntry.
  3102. *
  3103. * @param {Element} target - Element that is being observed.
  3104. * @param {DOMRectInit} rectInit - Data of the element's content rectangle.
  3105. */
  3106. function ResizeObserverEntry(target, rectInit) {
  3107. var contentRect = createReadOnlyRect(rectInit);
  3108. // According to the specification following properties are not writable
  3109. // and are also not enumerable in the native implementation.
  3110. //
  3111. // Property accessors are not being used as they'd require to define a
  3112. // private WeakMap storage which may cause memory leaks in browsers that
  3113. // don't support this type of collections.
  3114. defineConfigurable(this, { target: target, contentRect: contentRect });
  3115. }
  3116. return ResizeObserverEntry;
  3117. }());
  3118. var ResizeObserverSPI = /** @class */ (function () {
  3119. /**
  3120. * Creates a new instance of ResizeObserver.
  3121. *
  3122. * @param {ResizeObserverCallback} callback - Callback function that is invoked
  3123. * when one of the observed elements changes it's content dimensions.
  3124. * @param {ResizeObserverController} controller - Controller instance which
  3125. * is responsible for the updates of observer.
  3126. * @param {ResizeObserver} callbackCtx - Reference to the public
  3127. * ResizeObserver instance which will be passed to callback function.
  3128. */
  3129. function ResizeObserverSPI(callback, controller, callbackCtx) {
  3130. /**
  3131. * Collection of resize observations that have detected changes in dimensions
  3132. * of elements.
  3133. *
  3134. * @private {Array<ResizeObservation>}
  3135. */
  3136. this.activeObservations_ = [];
  3137. /**
  3138. * Registry of the ResizeObservation instances.
  3139. *
  3140. * @private {Map<Element, ResizeObservation>}
  3141. */
  3142. this.observations_ = new MapShim();
  3143. if (typeof callback !== 'function') {
  3144. throw new TypeError('The callback provided as parameter 1 is not a function.');
  3145. }
  3146. this.callback_ = callback;
  3147. this.controller_ = controller;
  3148. this.callbackCtx_ = callbackCtx;
  3149. }
  3150. /**
  3151. * Starts observing provided element.
  3152. *
  3153. * @param {Element} target - Element to be observed.
  3154. * @returns {void}
  3155. */
  3156. ResizeObserverSPI.prototype.observe = function (target) {
  3157. if (!arguments.length) {
  3158. throw new TypeError('1 argument required, but only 0 present.');
  3159. }
  3160. // Do nothing if current environment doesn't have the Element interface.
  3161. if (typeof Element === 'undefined' || !(Element instanceof Object)) {
  3162. return;
  3163. }
  3164. if (!(target instanceof getWindowOf(target).Element)) {
  3165. throw new TypeError('parameter 1 is not of type "Element".');
  3166. }
  3167. var observations = this.observations_;
  3168. // Do nothing if element is already being observed.
  3169. if (observations.has(target)) {
  3170. return;
  3171. }
  3172. observations.set(target, new ResizeObservation(target));
  3173. this.controller_.addObserver(this);
  3174. // Force the update of observations.
  3175. this.controller_.refresh();
  3176. };
  3177. /**
  3178. * Stops observing provided element.
  3179. *
  3180. * @param {Element} target - Element to stop observing.
  3181. * @returns {void}
  3182. */
  3183. ResizeObserverSPI.prototype.unobserve = function (target) {
  3184. if (!arguments.length) {
  3185. throw new TypeError('1 argument required, but only 0 present.');
  3186. }
  3187. // Do nothing if current environment doesn't have the Element interface.
  3188. if (typeof Element === 'undefined' || !(Element instanceof Object)) {
  3189. return;
  3190. }
  3191. if (!(target instanceof getWindowOf(target).Element)) {
  3192. throw new TypeError('parameter 1 is not of type "Element".');
  3193. }
  3194. var observations = this.observations_;
  3195. // Do nothing if element is not being observed.
  3196. if (!observations.has(target)) {
  3197. return;
  3198. }
  3199. observations.delete(target);
  3200. if (!observations.size) {
  3201. this.controller_.removeObserver(this);
  3202. }
  3203. };
  3204. /**
  3205. * Stops observing all elements.
  3206. *
  3207. * @returns {void}
  3208. */
  3209. ResizeObserverSPI.prototype.disconnect = function () {
  3210. this.clearActive();
  3211. this.observations_.clear();
  3212. this.controller_.removeObserver(this);
  3213. };
  3214. /**
  3215. * Collects observation instances the associated element of which has changed
  3216. * it's content rectangle.
  3217. *
  3218. * @returns {void}
  3219. */
  3220. ResizeObserverSPI.prototype.gatherActive = function () {
  3221. var _this = this;
  3222. this.clearActive();
  3223. this.observations_.forEach(function (observation) {
  3224. if (observation.isActive()) {
  3225. _this.activeObservations_.push(observation);
  3226. }
  3227. });
  3228. };
  3229. /**
  3230. * Invokes initial callback function with a list of ResizeObserverEntry
  3231. * instances collected from active resize observations.
  3232. *
  3233. * @returns {void}
  3234. */
  3235. ResizeObserverSPI.prototype.broadcastActive = function () {
  3236. // Do nothing if observer doesn't have active observations.
  3237. if (!this.hasActive()) {
  3238. return;
  3239. }
  3240. var ctx = this.callbackCtx_;
  3241. // Create ResizeObserverEntry instance for every active observation.
  3242. var entries = this.activeObservations_.map(function (observation) {
  3243. return new ResizeObserverEntry(observation.target, observation.broadcastRect());
  3244. });
  3245. this.callback_.call(ctx, entries, ctx);
  3246. this.clearActive();
  3247. };
  3248. /**
  3249. * Clears the collection of active observations.
  3250. *
  3251. * @returns {void}
  3252. */
  3253. ResizeObserverSPI.prototype.clearActive = function () {
  3254. this.activeObservations_.splice(0);
  3255. };
  3256. /**
  3257. * Tells whether observer has active observations.
  3258. *
  3259. * @returns {boolean}
  3260. */
  3261. ResizeObserverSPI.prototype.hasActive = function () {
  3262. return this.activeObservations_.length > 0;
  3263. };
  3264. return ResizeObserverSPI;
  3265. }());
  3266. // Registry of internal observers. If WeakMap is not available use current shim
  3267. // for the Map collection as it has all required methods and because WeakMap
  3268. // can't be fully polyfilled anyway.
  3269. var observers = typeof WeakMap !== 'undefined' ? new WeakMap() : new MapShim();
  3270. /**
  3271. * ResizeObserver API. Encapsulates the ResizeObserver SPI implementation
  3272. * exposing only those methods and properties that are defined in the spec.
  3273. */
  3274. var ResizeObserver = /** @class */ (function () {
  3275. /**
  3276. * Creates a new instance of ResizeObserver.
  3277. *
  3278. * @param {ResizeObserverCallback} callback - Callback that is invoked when
  3279. * dimensions of the observed elements change.
  3280. */
  3281. function ResizeObserver(callback) {
  3282. if (!(this instanceof ResizeObserver)) {
  3283. throw new TypeError('Cannot call a class as a function.');
  3284. }
  3285. if (!arguments.length) {
  3286. throw new TypeError('1 argument required, but only 0 present.');
  3287. }
  3288. var controller = ResizeObserverController.getInstance();
  3289. var observer = new ResizeObserverSPI(callback, controller, this);
  3290. observers.set(this, observer);
  3291. }
  3292. return ResizeObserver;
  3293. }());
  3294. // Expose public methods of ResizeObserver.
  3295. [
  3296. 'observe',
  3297. 'unobserve',
  3298. 'disconnect'
  3299. ].forEach(function (method) {
  3300. ResizeObserver.prototype[method] = function () {
  3301. var _a;
  3302. return (_a = observers.get(this))[method].apply(_a, arguments);
  3303. };
  3304. });
  3305. var index = (function () {
  3306. // Export existing implementation if available.
  3307. if (typeof global$1.ResizeObserver !== 'undefined') {
  3308. return global$1.ResizeObserver;
  3309. }
  3310. return ResizeObserver;
  3311. })();
  3312. var canUseDOM = !!(
  3313. typeof window !== 'undefined' &&
  3314. window.document &&
  3315. window.document.createElement
  3316. );
  3317. var canUseDom = canUseDOM;
  3318. var SimpleBar =
  3319. /*#__PURE__*/
  3320. function () {
  3321. function SimpleBar(element, options) {
  3322. var _this = this;
  3323. _classCallCheck(this, SimpleBar);
  3324. this.onScroll = function () {
  3325. if (!_this.scrollXTicking) {
  3326. window.requestAnimationFrame(_this.scrollX);
  3327. _this.scrollXTicking = true;
  3328. }
  3329. if (!_this.scrollYTicking) {
  3330. window.requestAnimationFrame(_this.scrollY);
  3331. _this.scrollYTicking = true;
  3332. }
  3333. };
  3334. this.scrollX = function () {
  3335. if (_this.axis.x.isOverflowing) {
  3336. _this.showScrollbar('x');
  3337. _this.positionScrollbar('x');
  3338. }
  3339. _this.scrollXTicking = false;
  3340. };
  3341. this.scrollY = function () {
  3342. if (_this.axis.y.isOverflowing) {
  3343. _this.showScrollbar('y');
  3344. _this.positionScrollbar('y');
  3345. }
  3346. _this.scrollYTicking = false;
  3347. };
  3348. this.onMouseEnter = function () {
  3349. _this.showScrollbar('x');
  3350. _this.showScrollbar('y');
  3351. };
  3352. this.onMouseMove = function (e) {
  3353. _this.mouseX = e.clientX;
  3354. _this.mouseY = e.clientY;
  3355. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  3356. _this.onMouseMoveForAxis('x');
  3357. }
  3358. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  3359. _this.onMouseMoveForAxis('y');
  3360. }
  3361. };
  3362. this.onMouseLeave = function () {
  3363. _this.onMouseMove.cancel();
  3364. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  3365. _this.onMouseLeaveForAxis('x');
  3366. }
  3367. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  3368. _this.onMouseLeaveForAxis('y');
  3369. }
  3370. _this.mouseX = -1;
  3371. _this.mouseY = -1;
  3372. };
  3373. this.onWindowResize = function () {
  3374. // Recalculate scrollbarWidth in case it's a zoom
  3375. _this.scrollbarWidth = scrollbarWidth();
  3376. _this.hideNativeScrollbar();
  3377. };
  3378. this.hideScrollbars = function () {
  3379. _this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
  3380. _this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
  3381. if (!_this.isWithinBounds(_this.axis.y.track.rect)) {
  3382. _this.axis.y.scrollbar.el.classList.remove(_this.classNames.visible);
  3383. _this.axis.y.isVisible = false;
  3384. }
  3385. if (!_this.isWithinBounds(_this.axis.x.track.rect)) {
  3386. _this.axis.x.scrollbar.el.classList.remove(_this.classNames.visible);
  3387. _this.axis.x.isVisible = false;
  3388. }
  3389. };
  3390. this.onPointerEvent = function (e) {
  3391. var isWithinBoundsY, isWithinBoundsX;
  3392. _this.axis.x.scrollbar.rect = _this.axis.x.scrollbar.el.getBoundingClientRect();
  3393. _this.axis.y.scrollbar.rect = _this.axis.y.scrollbar.el.getBoundingClientRect();
  3394. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  3395. isWithinBoundsX = _this.isWithinBounds(_this.axis.x.scrollbar.rect);
  3396. }
  3397. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  3398. isWithinBoundsY = _this.isWithinBounds(_this.axis.y.scrollbar.rect);
  3399. } // If any pointer event is called on the scrollbar
  3400. if (isWithinBoundsY || isWithinBoundsX) {
  3401. // Preventing the event's default action stops text being
  3402. // selectable during the drag.
  3403. e.preventDefault(); // Prevent event leaking
  3404. e.stopPropagation();
  3405. if (e.type === 'mousedown') {
  3406. if (isWithinBoundsY) {
  3407. _this.onDragStart(e, 'y');
  3408. }
  3409. if (isWithinBoundsX) {
  3410. _this.onDragStart(e, 'x');
  3411. }
  3412. }
  3413. }
  3414. };
  3415. this.drag = function (e) {
  3416. var eventOffset;
  3417. var track = _this.axis[_this.draggedAxis].track;
  3418. var trackSize = track.rect[_this.axis[_this.draggedAxis].sizeAttr];
  3419. var scrollbar = _this.axis[_this.draggedAxis].scrollbar;
  3420. e.preventDefault();
  3421. e.stopPropagation();
  3422. if (_this.draggedAxis === 'y') {
  3423. eventOffset = e.pageY;
  3424. } else {
  3425. eventOffset = e.pageX;
  3426. } // Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset).
  3427. var dragPos = eventOffset - track.rect[_this.axis[_this.draggedAxis].offsetAttr] - _this.axis[_this.draggedAxis].dragOffset; // Convert the mouse position into a percentage of the scrollbar height/width.
  3428. var dragPerc = dragPos / track.rect[_this.axis[_this.draggedAxis].sizeAttr]; // Scroll the content by the same percentage.
  3429. var scrollPos = dragPerc * _this.contentEl[_this.axis[_this.draggedAxis].scrollSizeAttr]; // Fix browsers inconsistency on RTL
  3430. if (_this.draggedAxis === 'x') {
  3431. scrollPos = _this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
  3432. scrollPos = _this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
  3433. }
  3434. _this.contentEl[_this.axis[_this.draggedAxis].scrollOffsetAttr] = scrollPos;
  3435. };
  3436. this.onEndDrag = function (e) {
  3437. e.preventDefault();
  3438. e.stopPropagation();
  3439. document.removeEventListener('mousemove', _this.drag);
  3440. document.removeEventListener('mouseup', _this.onEndDrag);
  3441. };
  3442. this.el = element;
  3443. this.flashTimeout;
  3444. this.contentEl;
  3445. this.offsetEl;
  3446. this.maskEl;
  3447. this.globalObserver;
  3448. this.mutationObserver;
  3449. this.resizeObserver;
  3450. this.scrollbarWidth;
  3451. this.minScrollbarWidth = 20;
  3452. this.options = _objectSpread({}, SimpleBar.defaultOptions, options);
  3453. this.classNames = _objectSpread({}, SimpleBar.defaultOptions.classNames, this.options.classNames);
  3454. this.isRtl;
  3455. this.axis = {
  3456. x: {
  3457. scrollOffsetAttr: 'scrollLeft',
  3458. sizeAttr: 'width',
  3459. scrollSizeAttr: 'scrollWidth',
  3460. offsetAttr: 'left',
  3461. overflowAttr: 'overflowX',
  3462. dragOffset: 0,
  3463. isOverflowing: true,
  3464. isVisible: false,
  3465. forceVisible: false,
  3466. track: {},
  3467. scrollbar: {}
  3468. },
  3469. y: {
  3470. scrollOffsetAttr: 'scrollTop',
  3471. sizeAttr: 'height',
  3472. scrollSizeAttr: 'scrollHeight',
  3473. offsetAttr: 'top',
  3474. overflowAttr: 'overflowY',
  3475. dragOffset: 0,
  3476. isOverflowing: true,
  3477. isVisible: false,
  3478. forceVisible: false,
  3479. track: {},
  3480. scrollbar: {}
  3481. }
  3482. };
  3483. this.recalculate = lodash_throttle(this.recalculate.bind(this), 64);
  3484. this.onMouseMove = lodash_throttle(this.onMouseMove.bind(this), 64);
  3485. this.hideScrollbars = lodash_debounce(this.hideScrollbars.bind(this), this.options.timeout);
  3486. this.onWindowResize = lodash_debounce(this.onWindowResize.bind(this), 64, {
  3487. leading: true
  3488. });
  3489. SimpleBar.getRtlHelpers = lodash_memoize(SimpleBar.getRtlHelpers); // getContentElement is deprecated
  3490. this.getContentElement = this.getScrollElement;
  3491. this.init();
  3492. }
  3493. /**
  3494. * Static properties
  3495. */
  3496. /**
  3497. * Helper to fix browsers inconsistency on RTL:
  3498. * - Firefox inverts the scrollbar initial position
  3499. * - IE11 inverts both scrollbar position and scrolling offset
  3500. * Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
  3501. */
  3502. _createClass(SimpleBar, [{
  3503. key: "init",
  3504. value: function init() {
  3505. // Save a reference to the instance, so we know this DOM node has already been instancied
  3506. this.el.SimpleBar = this; // We stop here on server-side
  3507. if (canUseDom) {
  3508. this.initDOM();
  3509. this.scrollbarWidth = scrollbarWidth();
  3510. this.recalculate();
  3511. this.initListeners();
  3512. }
  3513. }
  3514. }, {
  3515. key: "initDOM",
  3516. value: function initDOM() {
  3517. var _this2 = this;
  3518. // make sure this element doesn't have the elements yet
  3519. if (Array.from(this.el.children).filter(function (child) {
  3520. return child.classList.contains(_this2.classNames.wrapper);
  3521. }).length) {
  3522. // assume that element has his DOM already initiated
  3523. this.wrapperEl = this.el.querySelector(".".concat(this.classNames.wrapper));
  3524. this.contentEl = this.el.querySelector(".".concat(this.classNames.content));
  3525. this.offsetEl = this.el.querySelector(".".concat(this.classNames.offset));
  3526. this.maskEl = this.el.querySelector(".".concat(this.classNames.mask));
  3527. this.placeholderEl = this.el.querySelector(".".concat(this.classNames.placeholder));
  3528. this.heightAutoObserverWrapperEl = this.el.querySelector(".".concat(this.classNames.heightAutoObserverWrapperEl));
  3529. this.heightAutoObserverEl = this.el.querySelector(".".concat(this.classNames.heightAutoObserverEl));
  3530. this.axis.x.track.el = this.el.querySelector(".".concat(this.classNames.track, ".").concat(this.classNames.horizontal));
  3531. this.axis.y.track.el = this.el.querySelector(".".concat(this.classNames.track, ".").concat(this.classNames.vertical));
  3532. } else {
  3533. // Prepare DOM
  3534. this.wrapperEl = document.createElement('div');
  3535. this.contentEl = document.createElement('div');
  3536. this.offsetEl = document.createElement('div');
  3537. this.maskEl = document.createElement('div');
  3538. this.placeholderEl = document.createElement('div');
  3539. this.heightAutoObserverWrapperEl = document.createElement('div');
  3540. this.heightAutoObserverEl = document.createElement('div');
  3541. this.wrapperEl.classList.add(this.classNames.wrapper);
  3542. this.contentEl.classList.add(this.classNames.content);
  3543. this.offsetEl.classList.add(this.classNames.offset);
  3544. this.maskEl.classList.add(this.classNames.mask);
  3545. this.placeholderEl.classList.add(this.classNames.placeholder);
  3546. this.heightAutoObserverWrapperEl.classList.add(this.classNames.heightAutoObserverWrapperEl);
  3547. this.heightAutoObserverEl.classList.add(this.classNames.heightAutoObserverEl);
  3548. while (this.el.firstChild) {
  3549. this.contentEl.appendChild(this.el.firstChild);
  3550. }
  3551. this.offsetEl.appendChild(this.contentEl);
  3552. this.maskEl.appendChild(this.offsetEl);
  3553. this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
  3554. this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
  3555. this.wrapperEl.appendChild(this.maskEl);
  3556. this.wrapperEl.appendChild(this.placeholderEl);
  3557. this.el.appendChild(this.wrapperEl);
  3558. }
  3559. if (!this.axis.x.track.el || !this.axis.y.track.el) {
  3560. var track = document.createElement('div');
  3561. var scrollbar = document.createElement('div');
  3562. track.classList.add(this.classNames.track);
  3563. scrollbar.classList.add(this.classNames.scrollbar);
  3564. if (!this.options.autoHide) {
  3565. scrollbar.classList.add(this.classNames.visible);
  3566. }
  3567. track.appendChild(scrollbar);
  3568. this.axis.x.track.el = track.cloneNode(true);
  3569. this.axis.x.track.el.classList.add(this.classNames.horizontal);
  3570. this.axis.y.track.el = track.cloneNode(true);
  3571. this.axis.y.track.el.classList.add(this.classNames.vertical);
  3572. this.el.appendChild(this.axis.x.track.el);
  3573. this.el.appendChild(this.axis.y.track.el);
  3574. }
  3575. this.axis.x.scrollbar.el = this.axis.x.track.el.querySelector(".".concat(this.classNames.scrollbar));
  3576. this.axis.y.scrollbar.el = this.axis.y.track.el.querySelector(".".concat(this.classNames.scrollbar));
  3577. this.el.setAttribute('data-simplebar', 'init');
  3578. }
  3579. }, {
  3580. key: "initListeners",
  3581. value: function initListeners() {
  3582. var _this3 = this;
  3583. // Event listeners
  3584. if (this.options.autoHide) {
  3585. this.el.addEventListener('mouseenter', this.onMouseEnter);
  3586. }
  3587. ['mousedown', 'click', 'dblclick', 'touchstart', 'touchend', 'touchmove'].forEach(function (e) {
  3588. _this3.el.addEventListener(e, _this3.onPointerEvent, true);
  3589. });
  3590. this.el.addEventListener('mousemove', this.onMouseMove);
  3591. this.el.addEventListener('mouseleave', this.onMouseLeave);
  3592. this.contentEl.addEventListener('scroll', this.onScroll); // Browser zoom triggers a window resize
  3593. window.addEventListener('resize', this.onWindowResize); // MutationObserver is IE11+
  3594. if (typeof MutationObserver !== 'undefined') {
  3595. // create an observer instance
  3596. this.mutationObserver = new MutationObserver(function (mutations) {
  3597. mutations.forEach(function (mutation) {
  3598. if (mutation.target === _this3.el || !_this3.isChildNode(mutation.target) || mutation.addedNodes.length || mutation.removedNodes.length) {
  3599. _this3.recalculate();
  3600. }
  3601. });
  3602. }); // pass in the target node, as well as the observer options
  3603. this.mutationObserver.observe(this.el, {
  3604. attributes: true,
  3605. childList: true,
  3606. characterData: true,
  3607. subtree: true
  3608. });
  3609. }
  3610. this.resizeObserver = new index(this.recalculate);
  3611. this.resizeObserver.observe(this.el);
  3612. }
  3613. }, {
  3614. key: "recalculate",
  3615. value: function recalculate() {
  3616. var isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
  3617. this.elStyles = window.getComputedStyle(this.el);
  3618. this.isRtl = this.elStyles.direction === 'rtl';
  3619. this.contentEl.style.padding = "".concat(this.elStyles.paddingTop, " ").concat(this.elStyles.paddingRight, " ").concat(this.elStyles.paddingBottom, " ").concat(this.elStyles.paddingLeft);
  3620. this.contentEl.style.height = isHeightAuto ? 'auto' : '100%';
  3621. this.placeholderEl.style.width = "".concat(this.contentEl.scrollWidth, "px");
  3622. this.placeholderEl.style.height = "".concat(this.contentEl.scrollHeight, "px");
  3623. this.wrapperEl.style.margin = "-".concat(this.elStyles.paddingTop, " -").concat(this.elStyles.paddingRight, " -").concat(this.elStyles.paddingBottom, " -").concat(this.elStyles.paddingLeft);
  3624. this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
  3625. this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect(); // Set isOverflowing to false if scrollbar is not necessary (content is shorter than offset)
  3626. this.axis.x.isOverflowing = (this.scrollbarWidth ? this.contentEl.scrollWidth : this.contentEl.scrollWidth - this.minScrollbarWidth) > Math.ceil(this.axis.x.track.rect.width);
  3627. this.axis.y.isOverflowing = (this.scrollbarWidth ? this.contentEl.scrollHeight : this.contentEl.scrollHeight - this.minScrollbarWidth) > Math.ceil(this.axis.y.track.rect.height); // Set isOverflowing to false if user explicitely set hidden overflow
  3628. this.axis.x.isOverflowing = this.elStyles.overflowX === 'hidden' ? false : this.axis.x.isOverflowing;
  3629. this.axis.y.isOverflowing = this.elStyles.overflowY === 'hidden' ? false : this.axis.y.isOverflowing;
  3630. this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
  3631. this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
  3632. this.axis.x.scrollbar.size = this.getScrollbarSize('x');
  3633. this.axis.y.scrollbar.size = this.getScrollbarSize('y');
  3634. this.axis.x.scrollbar.el.style.width = "".concat(this.axis.x.scrollbar.size, "px");
  3635. this.axis.y.scrollbar.el.style.height = "".concat(this.axis.y.scrollbar.size, "px");
  3636. this.positionScrollbar('x');
  3637. this.positionScrollbar('y');
  3638. this.toggleTrackVisibility('x');
  3639. this.toggleTrackVisibility('y');
  3640. this.hideNativeScrollbar();
  3641. }
  3642. /**
  3643. * Calculate scrollbar size
  3644. */
  3645. }, {
  3646. key: "getScrollbarSize",
  3647. value: function getScrollbarSize() {
  3648. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3649. var contentSize = this.scrollbarWidth ? this.contentEl[this.axis[axis].scrollSizeAttr] : this.contentEl[this.axis[axis].scrollSizeAttr] - this.minScrollbarWidth;
  3650. var trackSize = this.axis[axis].track.rect[this.axis[axis].sizeAttr];
  3651. var scrollbarSize;
  3652. if (!this.axis[axis].isOverflowing) {
  3653. return;
  3654. }
  3655. var scrollbarRatio = trackSize / contentSize; // Calculate new height/position of drag handle.
  3656. scrollbarSize = Math.max(~~(scrollbarRatio * trackSize), this.options.scrollbarMinSize);
  3657. if (this.options.scrollbarMaxSize) {
  3658. scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
  3659. }
  3660. return scrollbarSize;
  3661. }
  3662. }, {
  3663. key: "positionScrollbar",
  3664. value: function positionScrollbar() {
  3665. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3666. var contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
  3667. var trackSize = this.axis[axis].track.rect[this.axis[axis].sizeAttr];
  3668. var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
  3669. var scrollbar = this.axis[axis].scrollbar;
  3670. var scrollOffset = this.contentEl[this.axis[axis].scrollOffsetAttr];
  3671. scrollOffset = axis === 'x' && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
  3672. var scrollPourcent = scrollOffset / (contentSize - hostSize);
  3673. var handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
  3674. handleOffset = axis === 'x' && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
  3675. scrollbar.el.style.transform = axis === 'x' ? "translate3d(".concat(handleOffset, "px, 0, 0)") : "translate3d(0, ".concat(handleOffset, "px, 0)");
  3676. }
  3677. }, {
  3678. key: "toggleTrackVisibility",
  3679. value: function toggleTrackVisibility() {
  3680. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3681. var track = this.axis[axis].track.el;
  3682. var scrollbar = this.axis[axis].scrollbar.el;
  3683. if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
  3684. track.style.visibility = 'visible';
  3685. this.contentEl.style[this.axis[axis].overflowAttr] = 'scroll';
  3686. } else {
  3687. track.style.visibility = 'hidden';
  3688. this.contentEl.style[this.axis[axis].overflowAttr] = 'hidden';
  3689. } // Even if forceVisible is enabled, scrollbar itself should be hidden
  3690. if (this.axis[axis].isOverflowing) {
  3691. scrollbar.style.visibility = 'visible';
  3692. } else {
  3693. scrollbar.style.visibility = 'hidden';
  3694. }
  3695. }
  3696. }, {
  3697. key: "hideNativeScrollbar",
  3698. value: function hideNativeScrollbar() {
  3699. this.offsetEl.style[this.isRtl ? 'left' : 'right'] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? "-".concat(this.scrollbarWidth || this.minScrollbarWidth, "px") : 0;
  3700. this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? "-".concat(this.scrollbarWidth || this.minScrollbarWidth, "px") : 0; // If floating scrollbar
  3701. if (!this.scrollbarWidth) {
  3702. var paddingDirection = [this.isRtl ? 'paddingLeft' : 'paddingRight'];
  3703. this.contentEl.style[paddingDirection] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? "calc(".concat(this.elStyles[paddingDirection], " + ").concat(this.minScrollbarWidth, "px)") : this.elStyles[paddingDirection];
  3704. this.contentEl.style.paddingBottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? "calc(".concat(this.elStyles.paddingBottom, " + ").concat(this.minScrollbarWidth, "px)") : this.elStyles.paddingBottom;
  3705. }
  3706. }
  3707. /**
  3708. * On scroll event handling
  3709. */
  3710. }, {
  3711. key: "onMouseMoveForAxis",
  3712. value: function onMouseMoveForAxis() {
  3713. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3714. this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
  3715. this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
  3716. var isWithinScrollbarBoundsX = this.isWithinBounds(this.axis[axis].scrollbar.rect);
  3717. if (isWithinScrollbarBoundsX) {
  3718. this.axis[axis].scrollbar.el.classList.add(this.classNames.hover);
  3719. } else {
  3720. this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
  3721. }
  3722. if (this.isWithinBounds(this.axis[axis].track.rect)) {
  3723. this.showScrollbar(axis);
  3724. this.axis[axis].track.el.classList.add(this.classNames.hover);
  3725. } else {
  3726. this.axis[axis].track.el.classList.remove(this.classNames.hover);
  3727. }
  3728. }
  3729. }, {
  3730. key: "onMouseLeaveForAxis",
  3731. value: function onMouseLeaveForAxis() {
  3732. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3733. this.axis[axis].track.el.classList.remove(this.classNames.hover);
  3734. this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
  3735. }
  3736. }, {
  3737. key: "showScrollbar",
  3738. /**
  3739. * Show scrollbar
  3740. */
  3741. value: function showScrollbar() {
  3742. var axis = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'y';
  3743. var scrollbar = this.axis[axis].scrollbar.el;
  3744. if (!this.axis[axis].isVisible) {
  3745. scrollbar.classList.add(this.classNames.visible);
  3746. this.axis[axis].isVisible = true;
  3747. }
  3748. if (this.options.autoHide) {
  3749. this.hideScrollbars();
  3750. }
  3751. }
  3752. /**
  3753. * Hide Scrollbar
  3754. */
  3755. }, {
  3756. key: "onDragStart",
  3757. /**
  3758. * on scrollbar handle drag movement starts
  3759. */
  3760. value: function onDragStart(e) {
  3761. var axis = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'y';
  3762. var scrollbar = this.axis[axis].scrollbar.el; // Measure how far the user's mouse is from the top of the scrollbar drag handle.
  3763. var eventOffset = axis === 'y' ? e.pageY : e.pageX;
  3764. this.axis[axis].dragOffset = eventOffset - scrollbar.getBoundingClientRect()[this.axis[axis].offsetAttr];
  3765. this.draggedAxis = axis;
  3766. document.addEventListener('mousemove', this.drag);
  3767. document.addEventListener('mouseup', this.onEndDrag);
  3768. }
  3769. /**
  3770. * Drag scrollbar handle
  3771. */
  3772. }, {
  3773. key: "getScrollElement",
  3774. /**
  3775. * Getter for original scrolling element
  3776. */
  3777. value: function getScrollElement() {
  3778. return this.contentEl;
  3779. }
  3780. }, {
  3781. key: "removeListeners",
  3782. value: function removeListeners() {
  3783. var _this4 = this;
  3784. // Event listeners
  3785. if (this.options.autoHide) {
  3786. this.el.removeEventListener('mouseenter', this.onMouseEnter);
  3787. }
  3788. ['mousedown', 'click', 'dblclick', 'touchstart', 'touchend', 'touchmove'].forEach(function (e) {
  3789. _this4.el.removeEventListener(e, _this4.onPointerEvent);
  3790. });
  3791. this.el.removeEventListener('mousemove', this.onMouseMove);
  3792. this.el.removeEventListener('mouseleave', this.onMouseLeave);
  3793. this.contentEl.removeEventListener('scroll', this.onScroll);
  3794. window.removeEventListener('resize', this.onWindowResize);
  3795. this.mutationObserver && this.mutationObserver.disconnect();
  3796. this.resizeObserver.disconnect(); // Cancel all debounced functions
  3797. this.recalculate.cancel();
  3798. this.onMouseMove.cancel();
  3799. this.hideScrollbars.cancel();
  3800. this.onWindowResize.cancel();
  3801. }
  3802. /**
  3803. * UnMount mutation observer and delete SimpleBar instance from DOM element
  3804. */
  3805. }, {
  3806. key: "unMount",
  3807. value: function unMount() {
  3808. this.removeListeners();
  3809. this.el.SimpleBar = null;
  3810. }
  3811. /**
  3812. * Recursively walks up the parent nodes looking for this.el
  3813. */
  3814. }, {
  3815. key: "isChildNode",
  3816. value: function isChildNode(el) {
  3817. if (el === null) return false;
  3818. if (el === this.el) return true;
  3819. return this.isChildNode(el.parentNode);
  3820. }
  3821. /**
  3822. * Check if mouse is within bounds
  3823. */
  3824. }, {
  3825. key: "isWithinBounds",
  3826. value: function isWithinBounds(bbox) {
  3827. return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
  3828. }
  3829. }], [{
  3830. key: "getRtlHelpers",
  3831. value: function getRtlHelpers() {
  3832. var dummyDiv = document.createElement('div');
  3833. dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
  3834. var scrollbarDummyEl = dummyDiv.firstElementChild;
  3835. document.body.appendChild(scrollbarDummyEl);
  3836. var dummyContainerChild = scrollbarDummyEl.firstElementChild;
  3837. scrollbarDummyEl.scrollLeft = 0;
  3838. var dummyContainerOffset = SimpleBar.getOffset(scrollbarDummyEl);
  3839. var dummyContainerChildOffset = SimpleBar.getOffset(dummyContainerChild);
  3840. scrollbarDummyEl.scrollLeft = 999;
  3841. var dummyContainerScrollOffsetAfterScroll = SimpleBar.getOffset(dummyContainerChild);
  3842. return {
  3843. // determines if the scrolling is responding with negative values
  3844. isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
  3845. // determines if the origin scrollbar position is inverted or not (positioned on left or right)
  3846. isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
  3847. };
  3848. }
  3849. }, {
  3850. key: "initHtmlApi",
  3851. value: function initHtmlApi() {
  3852. this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this); // MutationObserver is IE11+
  3853. if (typeof MutationObserver !== 'undefined') {
  3854. // Mutation observer to observe dynamically added elements
  3855. this.globalObserver = new MutationObserver(function (mutations) {
  3856. mutations.forEach(function (mutation) {
  3857. Array.from(mutation.addedNodes).forEach(function (addedNode) {
  3858. if (addedNode.nodeType === 1) {
  3859. if (addedNode.hasAttribute('data-simplebar')) {
  3860. !addedNode.SimpleBar && new SimpleBar(addedNode, SimpleBar.getElOptions(addedNode));
  3861. } else {
  3862. Array.from(addedNode.querySelectorAll('[data-simplebar]')).forEach(function (el) {
  3863. !el.SimpleBar && new SimpleBar(el, SimpleBar.getElOptions(el));
  3864. });
  3865. }
  3866. }
  3867. });
  3868. Array.from(mutation.removedNodes).forEach(function (removedNode) {
  3869. if (removedNode.nodeType === 1) {
  3870. if (removedNode.hasAttribute('data-simplebar')) {
  3871. removedNode.SimpleBar && removedNode.SimpleBar.unMount();
  3872. } else {
  3873. Array.from(removedNode.querySelectorAll('[data-simplebar]')).forEach(function (el) {
  3874. el.SimpleBar && el.SimpleBar.unMount();
  3875. });
  3876. }
  3877. }
  3878. });
  3879. });
  3880. });
  3881. this.globalObserver.observe(document, {
  3882. childList: true,
  3883. subtree: true
  3884. });
  3885. } // Taken from jQuery `ready` function
  3886. // Instantiate elements already present on the page
  3887. if (document.readyState === 'complete' || document.readyState !== 'loading' && !document.documentElement.doScroll) {
  3888. // Handle it asynchronously to allow scripts the opportunity to delay init
  3889. window.setTimeout(this.initDOMLoadedElements);
  3890. } else {
  3891. document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  3892. window.addEventListener('load', this.initDOMLoadedElements);
  3893. }
  3894. } // Helper function to retrieve options from element attributes
  3895. }, {
  3896. key: "getElOptions",
  3897. value: function getElOptions(el) {
  3898. var options = Array.from(el.attributes).reduce(function (acc, attribute) {
  3899. var option = attribute.name.match(/data-simplebar-(.+)/);
  3900. if (option) {
  3901. var key = option[1].replace(/\W+(.)/g, function (x, chr) {
  3902. return chr.toUpperCase();
  3903. });
  3904. switch (attribute.value) {
  3905. case 'true':
  3906. acc[key] = true;
  3907. break;
  3908. case 'false':
  3909. acc[key] = false;
  3910. break;
  3911. case undefined:
  3912. acc[key] = true;
  3913. break;
  3914. default:
  3915. acc[key] = attribute.value;
  3916. }
  3917. }
  3918. return acc;
  3919. }, {});
  3920. return options;
  3921. }
  3922. }, {
  3923. key: "removeObserver",
  3924. value: function removeObserver() {
  3925. this.globalObserver.disconnect();
  3926. }
  3927. }, {
  3928. key: "initDOMLoadedElements",
  3929. value: function initDOMLoadedElements() {
  3930. document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  3931. window.removeEventListener('load', this.initDOMLoadedElements);
  3932. Array.from(document.querySelectorAll('[data-simplebar]')).forEach(function (el) {
  3933. if (!el.SimpleBar) new SimpleBar(el, SimpleBar.getElOptions(el));
  3934. });
  3935. }
  3936. }, {
  3937. key: "getOffset",
  3938. value: function getOffset(el) {
  3939. var rect = el.getBoundingClientRect();
  3940. return {
  3941. top: rect.top + (window.pageYOffset || document.documentElement.scrollTop),
  3942. left: rect.left + (window.pageXOffset || document.documentElement.scrollLeft)
  3943. };
  3944. }
  3945. }]);
  3946. return SimpleBar;
  3947. }();
  3948. /**
  3949. * HTML API
  3950. * Called only in a browser env.
  3951. */
  3952. SimpleBar.defaultOptions = {
  3953. autoHide: true,
  3954. forceVisible: false,
  3955. classNames: {
  3956. content: 'simplebar-content',
  3957. offset: 'simplebar-offset',
  3958. mask: 'simplebar-mask',
  3959. wrapper: 'simplebar-wrapper',
  3960. placeholder: 'simplebar-placeholder',
  3961. scrollbar: 'simplebar-scrollbar',
  3962. track: 'simplebar-track',
  3963. heightAutoObserverWrapperEl: 'simplebar-height-auto-observer-wrapper',
  3964. heightAutoObserverEl: 'simplebar-height-auto-observer',
  3965. visible: 'simplebar-visible',
  3966. horizontal: 'simplebar-horizontal',
  3967. vertical: 'simplebar-vertical',
  3968. hover: 'simplebar-hover'
  3969. },
  3970. scrollbarMinSize: 25,
  3971. scrollbarMaxSize: 0,
  3972. timeout: 1000
  3973. };
  3974. if (canUseDom) {
  3975. SimpleBar.initHtmlApi();
  3976. }
  3977. return SimpleBar;
  3978. }));