simplebar.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680
  1. /**
  2. * simplebar - v6.3.2
  3. * Scrollbars, simpler.
  4. * https://grsmto.github.io/simplebar/
  5. *
  6. * Made by Adrien Denat from a fork by Jonathan Nicol
  7. * Under MIT License
  8. */
  9. var SimpleBar = (function () {
  10. 'use strict';
  11. /******************************************************************************
  12. Copyright (c) Microsoft Corporation.
  13. Permission to use, copy, modify, and/or distribute this software for any
  14. purpose with or without fee is hereby granted.
  15. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  16. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  17. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  18. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  19. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  20. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  21. PERFORMANCE OF THIS SOFTWARE.
  22. ***************************************************************************** */
  23. /* global Reflect, Promise */
  24. var extendStatics = function(d, b) {
  25. extendStatics = Object.setPrototypeOf ||
  26. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  27. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  28. return extendStatics(d, b);
  29. };
  30. function __extends(d, b) {
  31. if (typeof b !== "function" && b !== null)
  32. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  33. extendStatics(d, b);
  34. function __() { this.constructor = d; }
  35. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  36. }
  37. /**
  38. * Checks if `value` is the
  39. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  40. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  41. *
  42. * @static
  43. * @memberOf _
  44. * @since 0.1.0
  45. * @category Lang
  46. * @param {*} value The value to check.
  47. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  48. * @example
  49. *
  50. * _.isObject({});
  51. * // => true
  52. *
  53. * _.isObject([1, 2, 3]);
  54. * // => true
  55. *
  56. * _.isObject(_.noop);
  57. * // => true
  58. *
  59. * _.isObject(null);
  60. * // => false
  61. */
  62. function isObject(value) {
  63. var type = typeof value;
  64. return value != null && (type == 'object' || type == 'function');
  65. }
  66. /** Detect free variable `global` from Node.js. */
  67. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  68. var freeGlobal$1 = freeGlobal;
  69. /** Detect free variable `self`. */
  70. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  71. /** Used as a reference to the global object. */
  72. var root = freeGlobal$1 || freeSelf || Function('return this')();
  73. var root$1 = root;
  74. /**
  75. * Gets the timestamp of the number of milliseconds that have elapsed since
  76. * the Unix epoch (1 January 1970 00:00:00 UTC).
  77. *
  78. * @static
  79. * @memberOf _
  80. * @since 2.4.0
  81. * @category Date
  82. * @returns {number} Returns the timestamp.
  83. * @example
  84. *
  85. * _.defer(function(stamp) {
  86. * console.log(_.now() - stamp);
  87. * }, _.now());
  88. * // => Logs the number of milliseconds it took for the deferred invocation.
  89. */
  90. var now = function() {
  91. return root$1.Date.now();
  92. };
  93. var now$1 = now;
  94. /** Used to match a single whitespace character. */
  95. var reWhitespace = /\s/;
  96. /**
  97. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  98. * character of `string`.
  99. *
  100. * @private
  101. * @param {string} string The string to inspect.
  102. * @returns {number} Returns the index of the last non-whitespace character.
  103. */
  104. function trimmedEndIndex(string) {
  105. var index = string.length;
  106. while (index-- && reWhitespace.test(string.charAt(index))) {}
  107. return index;
  108. }
  109. /** Used to match leading whitespace. */
  110. var reTrimStart = /^\s+/;
  111. /**
  112. * The base implementation of `_.trim`.
  113. *
  114. * @private
  115. * @param {string} string The string to trim.
  116. * @returns {string} Returns the trimmed string.
  117. */
  118. function baseTrim(string) {
  119. return string
  120. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  121. : string;
  122. }
  123. /** Built-in value references. */
  124. var Symbol = root$1.Symbol;
  125. var Symbol$1 = Symbol;
  126. /** Used for built-in method references. */
  127. var objectProto$1 = Object.prototype;
  128. /** Used to check objects for own properties. */
  129. var hasOwnProperty = objectProto$1.hasOwnProperty;
  130. /**
  131. * Used to resolve the
  132. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  133. * of values.
  134. */
  135. var nativeObjectToString$1 = objectProto$1.toString;
  136. /** Built-in value references. */
  137. var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined;
  138. /**
  139. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  140. *
  141. * @private
  142. * @param {*} value The value to query.
  143. * @returns {string} Returns the raw `toStringTag`.
  144. */
  145. function getRawTag(value) {
  146. var isOwn = hasOwnProperty.call(value, symToStringTag$1),
  147. tag = value[symToStringTag$1];
  148. try {
  149. value[symToStringTag$1] = undefined;
  150. var unmasked = true;
  151. } catch (e) {}
  152. var result = nativeObjectToString$1.call(value);
  153. if (unmasked) {
  154. if (isOwn) {
  155. value[symToStringTag$1] = tag;
  156. } else {
  157. delete value[symToStringTag$1];
  158. }
  159. }
  160. return result;
  161. }
  162. /** Used for built-in method references. */
  163. var objectProto = Object.prototype;
  164. /**
  165. * Used to resolve the
  166. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  167. * of values.
  168. */
  169. var nativeObjectToString = objectProto.toString;
  170. /**
  171. * Converts `value` to a string using `Object.prototype.toString`.
  172. *
  173. * @private
  174. * @param {*} value The value to convert.
  175. * @returns {string} Returns the converted string.
  176. */
  177. function objectToString(value) {
  178. return nativeObjectToString.call(value);
  179. }
  180. /** `Object#toString` result references. */
  181. var nullTag = '[object Null]',
  182. undefinedTag = '[object Undefined]';
  183. /** Built-in value references. */
  184. var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined;
  185. /**
  186. * The base implementation of `getTag` without fallbacks for buggy environments.
  187. *
  188. * @private
  189. * @param {*} value The value to query.
  190. * @returns {string} Returns the `toStringTag`.
  191. */
  192. function baseGetTag(value) {
  193. if (value == null) {
  194. return value === undefined ? undefinedTag : nullTag;
  195. }
  196. return (symToStringTag && symToStringTag in Object(value))
  197. ? getRawTag(value)
  198. : objectToString(value);
  199. }
  200. /**
  201. * Checks if `value` is object-like. A value is object-like if it's not `null`
  202. * and has a `typeof` result of "object".
  203. *
  204. * @static
  205. * @memberOf _
  206. * @since 4.0.0
  207. * @category Lang
  208. * @param {*} value The value to check.
  209. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  210. * @example
  211. *
  212. * _.isObjectLike({});
  213. * // => true
  214. *
  215. * _.isObjectLike([1, 2, 3]);
  216. * // => true
  217. *
  218. * _.isObjectLike(_.noop);
  219. * // => false
  220. *
  221. * _.isObjectLike(null);
  222. * // => false
  223. */
  224. function isObjectLike(value) {
  225. return value != null && typeof value == 'object';
  226. }
  227. /** `Object#toString` result references. */
  228. var symbolTag = '[object Symbol]';
  229. /**
  230. * Checks if `value` is classified as a `Symbol` primitive or object.
  231. *
  232. * @static
  233. * @memberOf _
  234. * @since 4.0.0
  235. * @category Lang
  236. * @param {*} value The value to check.
  237. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  238. * @example
  239. *
  240. * _.isSymbol(Symbol.iterator);
  241. * // => true
  242. *
  243. * _.isSymbol('abc');
  244. * // => false
  245. */
  246. function isSymbol(value) {
  247. return typeof value == 'symbol' ||
  248. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  249. }
  250. /** Used as references for various `Number` constants. */
  251. var NAN = 0 / 0;
  252. /** Used to detect bad signed hexadecimal string values. */
  253. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  254. /** Used to detect binary string values. */
  255. var reIsBinary = /^0b[01]+$/i;
  256. /** Used to detect octal string values. */
  257. var reIsOctal = /^0o[0-7]+$/i;
  258. /** Built-in method references without a dependency on `root`. */
  259. var freeParseInt = parseInt;
  260. /**
  261. * Converts `value` to a number.
  262. *
  263. * @static
  264. * @memberOf _
  265. * @since 4.0.0
  266. * @category Lang
  267. * @param {*} value The value to process.
  268. * @returns {number} Returns the number.
  269. * @example
  270. *
  271. * _.toNumber(3.2);
  272. * // => 3.2
  273. *
  274. * _.toNumber(Number.MIN_VALUE);
  275. * // => 5e-324
  276. *
  277. * _.toNumber(Infinity);
  278. * // => Infinity
  279. *
  280. * _.toNumber('3.2');
  281. * // => 3.2
  282. */
  283. function toNumber(value) {
  284. if (typeof value == 'number') {
  285. return value;
  286. }
  287. if (isSymbol(value)) {
  288. return NAN;
  289. }
  290. if (isObject(value)) {
  291. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  292. value = isObject(other) ? (other + '') : other;
  293. }
  294. if (typeof value != 'string') {
  295. return value === 0 ? value : +value;
  296. }
  297. value = baseTrim(value);
  298. var isBinary = reIsBinary.test(value);
  299. return (isBinary || reIsOctal.test(value))
  300. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  301. : (reIsBadHex.test(value) ? NAN : +value);
  302. }
  303. /** Error message constants. */
  304. var FUNC_ERROR_TEXT$1 = 'Expected a function';
  305. /* Built-in method references for those with the same name as other `lodash` methods. */
  306. var nativeMax = Math.max,
  307. nativeMin = Math.min;
  308. /**
  309. * Creates a debounced function that delays invoking `func` until after `wait`
  310. * milliseconds have elapsed since the last time the debounced function was
  311. * invoked. The debounced function comes with a `cancel` method to cancel
  312. * delayed `func` invocations and a `flush` method to immediately invoke them.
  313. * Provide `options` to indicate whether `func` should be invoked on the
  314. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  315. * with the last arguments provided to the debounced function. Subsequent
  316. * calls to the debounced function return the result of the last `func`
  317. * invocation.
  318. *
  319. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  320. * invoked on the trailing edge of the timeout only if the debounced function
  321. * is invoked more than once during the `wait` timeout.
  322. *
  323. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  324. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  325. *
  326. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  327. * for details over the differences between `_.debounce` and `_.throttle`.
  328. *
  329. * @static
  330. * @memberOf _
  331. * @since 0.1.0
  332. * @category Function
  333. * @param {Function} func The function to debounce.
  334. * @param {number} [wait=0] The number of milliseconds to delay.
  335. * @param {Object} [options={}] The options object.
  336. * @param {boolean} [options.leading=false]
  337. * Specify invoking on the leading edge of the timeout.
  338. * @param {number} [options.maxWait]
  339. * The maximum time `func` is allowed to be delayed before it's invoked.
  340. * @param {boolean} [options.trailing=true]
  341. * Specify invoking on the trailing edge of the timeout.
  342. * @returns {Function} Returns the new debounced function.
  343. * @example
  344. *
  345. * // Avoid costly calculations while the window size is in flux.
  346. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  347. *
  348. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  349. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  350. * 'leading': true,
  351. * 'trailing': false
  352. * }));
  353. *
  354. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  355. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  356. * var source = new EventSource('/stream');
  357. * jQuery(source).on('message', debounced);
  358. *
  359. * // Cancel the trailing debounced invocation.
  360. * jQuery(window).on('popstate', debounced.cancel);
  361. */
  362. function debounce(func, wait, options) {
  363. var lastArgs,
  364. lastThis,
  365. maxWait,
  366. result,
  367. timerId,
  368. lastCallTime,
  369. lastInvokeTime = 0,
  370. leading = false,
  371. maxing = false,
  372. trailing = true;
  373. if (typeof func != 'function') {
  374. throw new TypeError(FUNC_ERROR_TEXT$1);
  375. }
  376. wait = toNumber(wait) || 0;
  377. if (isObject(options)) {
  378. leading = !!options.leading;
  379. maxing = 'maxWait' in options;
  380. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  381. trailing = 'trailing' in options ? !!options.trailing : trailing;
  382. }
  383. function invokeFunc(time) {
  384. var args = lastArgs,
  385. thisArg = lastThis;
  386. lastArgs = lastThis = undefined;
  387. lastInvokeTime = time;
  388. result = func.apply(thisArg, args);
  389. return result;
  390. }
  391. function leadingEdge(time) {
  392. // Reset any `maxWait` timer.
  393. lastInvokeTime = time;
  394. // Start the timer for the trailing edge.
  395. timerId = setTimeout(timerExpired, wait);
  396. // Invoke the leading edge.
  397. return leading ? invokeFunc(time) : result;
  398. }
  399. function remainingWait(time) {
  400. var timeSinceLastCall = time - lastCallTime,
  401. timeSinceLastInvoke = time - lastInvokeTime,
  402. timeWaiting = wait - timeSinceLastCall;
  403. return maxing
  404. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  405. : timeWaiting;
  406. }
  407. function shouldInvoke(time) {
  408. var timeSinceLastCall = time - lastCallTime,
  409. timeSinceLastInvoke = time - lastInvokeTime;
  410. // Either this is the first call, activity has stopped and we're at the
  411. // trailing edge, the system time has gone backwards and we're treating
  412. // it as the trailing edge, or we've hit the `maxWait` limit.
  413. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  414. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  415. }
  416. function timerExpired() {
  417. var time = now$1();
  418. if (shouldInvoke(time)) {
  419. return trailingEdge(time);
  420. }
  421. // Restart the timer.
  422. timerId = setTimeout(timerExpired, remainingWait(time));
  423. }
  424. function trailingEdge(time) {
  425. timerId = undefined;
  426. // Only invoke if we have `lastArgs` which means `func` has been
  427. // debounced at least once.
  428. if (trailing && lastArgs) {
  429. return invokeFunc(time);
  430. }
  431. lastArgs = lastThis = undefined;
  432. return result;
  433. }
  434. function cancel() {
  435. if (timerId !== undefined) {
  436. clearTimeout(timerId);
  437. }
  438. lastInvokeTime = 0;
  439. lastArgs = lastCallTime = lastThis = timerId = undefined;
  440. }
  441. function flush() {
  442. return timerId === undefined ? result : trailingEdge(now$1());
  443. }
  444. function debounced() {
  445. var time = now$1(),
  446. isInvoking = shouldInvoke(time);
  447. lastArgs = arguments;
  448. lastThis = this;
  449. lastCallTime = time;
  450. if (isInvoking) {
  451. if (timerId === undefined) {
  452. return leadingEdge(lastCallTime);
  453. }
  454. if (maxing) {
  455. // Handle invocations in a tight loop.
  456. clearTimeout(timerId);
  457. timerId = setTimeout(timerExpired, wait);
  458. return invokeFunc(lastCallTime);
  459. }
  460. }
  461. if (timerId === undefined) {
  462. timerId = setTimeout(timerExpired, wait);
  463. }
  464. return result;
  465. }
  466. debounced.cancel = cancel;
  467. debounced.flush = flush;
  468. return debounced;
  469. }
  470. /** Error message constants. */
  471. var FUNC_ERROR_TEXT = 'Expected a function';
  472. /**
  473. * Creates a throttled function that only invokes `func` at most once per
  474. * every `wait` milliseconds. The throttled function comes with a `cancel`
  475. * method to cancel delayed `func` invocations and a `flush` method to
  476. * immediately invoke them. Provide `options` to indicate whether `func`
  477. * should be invoked on the leading and/or trailing edge of the `wait`
  478. * timeout. The `func` is invoked with the last arguments provided to the
  479. * throttled function. Subsequent calls to the throttled function return the
  480. * result of the last `func` invocation.
  481. *
  482. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  483. * invoked on the trailing edge of the timeout only if the throttled function
  484. * is invoked more than once during the `wait` timeout.
  485. *
  486. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  487. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  488. *
  489. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  490. * for details over the differences between `_.throttle` and `_.debounce`.
  491. *
  492. * @static
  493. * @memberOf _
  494. * @since 0.1.0
  495. * @category Function
  496. * @param {Function} func The function to throttle.
  497. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  498. * @param {Object} [options={}] The options object.
  499. * @param {boolean} [options.leading=true]
  500. * Specify invoking on the leading edge of the timeout.
  501. * @param {boolean} [options.trailing=true]
  502. * Specify invoking on the trailing edge of the timeout.
  503. * @returns {Function} Returns the new throttled function.
  504. * @example
  505. *
  506. * // Avoid excessively updating the position while scrolling.
  507. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  508. *
  509. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  510. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  511. * jQuery(element).on('click', throttled);
  512. *
  513. * // Cancel the trailing throttled invocation.
  514. * jQuery(window).on('popstate', throttled.cancel);
  515. */
  516. function throttle(func, wait, options) {
  517. var leading = true,
  518. trailing = true;
  519. if (typeof func != 'function') {
  520. throw new TypeError(FUNC_ERROR_TEXT);
  521. }
  522. if (isObject(options)) {
  523. leading = 'leading' in options ? !!options.leading : leading;
  524. trailing = 'trailing' in options ? !!options.trailing : trailing;
  525. }
  526. return debounce(func, wait, {
  527. 'leading': leading,
  528. 'maxWait': wait,
  529. 'trailing': trailing
  530. });
  531. }
  532. /**
  533. * simplebar-core - v1.3.2
  534. * Scrollbars, simpler.
  535. * https://grsmto.github.io/simplebar/
  536. *
  537. * Made by Adrien Denat from a fork by Jonathan Nicol
  538. * Under MIT License
  539. */
  540. /******************************************************************************
  541. Copyright (c) Microsoft Corporation.
  542. Permission to use, copy, modify, and/or distribute this software for any
  543. purpose with or without fee is hereby granted.
  544. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  545. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  546. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  547. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  548. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  549. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  550. PERFORMANCE OF THIS SOFTWARE.
  551. ***************************************************************************** */
  552. var __assign = function() {
  553. __assign = Object.assign || function __assign(t) {
  554. for (var s, i = 1, n = arguments.length; i < n; i++) {
  555. s = arguments[i];
  556. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  557. }
  558. return t;
  559. };
  560. return __assign.apply(this, arguments);
  561. };
  562. function getElementWindow$1(element) {
  563. if (!element ||
  564. !element.ownerDocument ||
  565. !element.ownerDocument.defaultView) {
  566. return window;
  567. }
  568. return element.ownerDocument.defaultView;
  569. }
  570. function getElementDocument$1(element) {
  571. if (!element || !element.ownerDocument) {
  572. return document;
  573. }
  574. return element.ownerDocument;
  575. }
  576. // Helper function to retrieve options from element attributes
  577. var getOptions$1 = function (obj) {
  578. var initialObj = {};
  579. var options = Array.prototype.reduce.call(obj, function (acc, attribute) {
  580. var option = attribute.name.match(/data-simplebar-(.+)/);
  581. if (option) {
  582. var key = option[1].replace(/\W+(.)/g, function (_, chr) { return chr.toUpperCase(); });
  583. switch (attribute.value) {
  584. case 'true':
  585. acc[key] = true;
  586. break;
  587. case 'false':
  588. acc[key] = false;
  589. break;
  590. case undefined:
  591. acc[key] = true;
  592. break;
  593. default:
  594. acc[key] = attribute.value;
  595. }
  596. }
  597. return acc;
  598. }, initialObj);
  599. return options;
  600. };
  601. function addClasses$1(el, classes) {
  602. var _a;
  603. if (!el)
  604. return;
  605. (_a = el.classList).add.apply(_a, classes.split(' '));
  606. }
  607. function removeClasses$1(el, classes) {
  608. if (!el)
  609. return;
  610. classes.split(' ').forEach(function (className) {
  611. el.classList.remove(className);
  612. });
  613. }
  614. function classNamesToQuery$1(classNames) {
  615. return ".".concat(classNames.split(' ').join('.'));
  616. }
  617. var canUseDOM$1 = !!(typeof window !== 'undefined' &&
  618. window.document &&
  619. window.document.createElement);
  620. var helpers = /*#__PURE__*/Object.freeze({
  621. __proto__: null,
  622. addClasses: addClasses$1,
  623. canUseDOM: canUseDOM$1,
  624. classNamesToQuery: classNamesToQuery$1,
  625. getElementDocument: getElementDocument$1,
  626. getElementWindow: getElementWindow$1,
  627. getOptions: getOptions$1,
  628. removeClasses: removeClasses$1
  629. });
  630. var cachedScrollbarWidth = null;
  631. var cachedDevicePixelRatio = null;
  632. if (canUseDOM$1) {
  633. window.addEventListener('resize', function () {
  634. if (cachedDevicePixelRatio !== window.devicePixelRatio) {
  635. cachedDevicePixelRatio = window.devicePixelRatio;
  636. cachedScrollbarWidth = null;
  637. }
  638. });
  639. }
  640. function scrollbarWidth() {
  641. if (cachedScrollbarWidth === null) {
  642. if (typeof document === 'undefined') {
  643. cachedScrollbarWidth = 0;
  644. return cachedScrollbarWidth;
  645. }
  646. var body = document.body;
  647. var box = document.createElement('div');
  648. box.classList.add('simplebar-hide-scrollbar');
  649. body.appendChild(box);
  650. var width = box.getBoundingClientRect().right;
  651. body.removeChild(box);
  652. cachedScrollbarWidth = width;
  653. }
  654. return cachedScrollbarWidth;
  655. }
  656. var getElementWindow = getElementWindow$1, getElementDocument = getElementDocument$1, getOptions$2 = getOptions$1, addClasses$2 = addClasses$1, removeClasses = removeClasses$1, classNamesToQuery = classNamesToQuery$1;
  657. var SimpleBarCore = /** @class */ (function () {
  658. function SimpleBarCore(element, options) {
  659. if (options === void 0) { options = {}; }
  660. var _this = this;
  661. this.removePreventClickId = null;
  662. this.minScrollbarWidth = 20;
  663. this.stopScrollDelay = 175;
  664. this.isScrolling = false;
  665. this.isMouseEntering = false;
  666. this.isDragging = false;
  667. this.scrollXTicking = false;
  668. this.scrollYTicking = false;
  669. this.wrapperEl = null;
  670. this.contentWrapperEl = null;
  671. this.contentEl = null;
  672. this.offsetEl = null;
  673. this.maskEl = null;
  674. this.placeholderEl = null;
  675. this.heightAutoObserverWrapperEl = null;
  676. this.heightAutoObserverEl = null;
  677. this.rtlHelpers = null;
  678. this.scrollbarWidth = 0;
  679. this.resizeObserver = null;
  680. this.mutationObserver = null;
  681. this.elStyles = null;
  682. this.isRtl = null;
  683. this.mouseX = 0;
  684. this.mouseY = 0;
  685. this.onMouseMove = function () { };
  686. this.onWindowResize = function () { };
  687. this.onStopScrolling = function () { };
  688. this.onMouseEntered = function () { };
  689. /**
  690. * On scroll event handling
  691. */
  692. this.onScroll = function () {
  693. var elWindow = getElementWindow(_this.el);
  694. if (!_this.scrollXTicking) {
  695. elWindow.requestAnimationFrame(_this.scrollX);
  696. _this.scrollXTicking = true;
  697. }
  698. if (!_this.scrollYTicking) {
  699. elWindow.requestAnimationFrame(_this.scrollY);
  700. _this.scrollYTicking = true;
  701. }
  702. if (!_this.isScrolling) {
  703. _this.isScrolling = true;
  704. addClasses$2(_this.el, _this.classNames.scrolling);
  705. }
  706. _this.showScrollbar('x');
  707. _this.showScrollbar('y');
  708. _this.onStopScrolling();
  709. };
  710. this.scrollX = function () {
  711. if (_this.axis.x.isOverflowing) {
  712. _this.positionScrollbar('x');
  713. }
  714. _this.scrollXTicking = false;
  715. };
  716. this.scrollY = function () {
  717. if (_this.axis.y.isOverflowing) {
  718. _this.positionScrollbar('y');
  719. }
  720. _this.scrollYTicking = false;
  721. };
  722. this._onStopScrolling = function () {
  723. removeClasses(_this.el, _this.classNames.scrolling);
  724. if (_this.options.autoHide) {
  725. _this.hideScrollbar('x');
  726. _this.hideScrollbar('y');
  727. }
  728. _this.isScrolling = false;
  729. };
  730. this.onMouseEnter = function () {
  731. if (!_this.isMouseEntering) {
  732. addClasses$2(_this.el, _this.classNames.mouseEntered);
  733. _this.showScrollbar('x');
  734. _this.showScrollbar('y');
  735. _this.isMouseEntering = true;
  736. }
  737. _this.onMouseEntered();
  738. };
  739. this._onMouseEntered = function () {
  740. removeClasses(_this.el, _this.classNames.mouseEntered);
  741. if (_this.options.autoHide) {
  742. _this.hideScrollbar('x');
  743. _this.hideScrollbar('y');
  744. }
  745. _this.isMouseEntering = false;
  746. };
  747. this._onMouseMove = function (e) {
  748. _this.mouseX = e.clientX;
  749. _this.mouseY = e.clientY;
  750. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  751. _this.onMouseMoveForAxis('x');
  752. }
  753. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  754. _this.onMouseMoveForAxis('y');
  755. }
  756. };
  757. this.onMouseLeave = function () {
  758. _this.onMouseMove.cancel();
  759. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  760. _this.onMouseLeaveForAxis('x');
  761. }
  762. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  763. _this.onMouseLeaveForAxis('y');
  764. }
  765. _this.mouseX = -1;
  766. _this.mouseY = -1;
  767. };
  768. this._onWindowResize = function () {
  769. // Recalculate scrollbarWidth in case it's a zoom
  770. _this.scrollbarWidth = _this.getScrollbarWidth();
  771. _this.hideNativeScrollbar();
  772. };
  773. this.onPointerEvent = function (e) {
  774. if (!_this.axis.x.track.el ||
  775. !_this.axis.y.track.el ||
  776. !_this.axis.x.scrollbar.el ||
  777. !_this.axis.y.scrollbar.el)
  778. return;
  779. var isWithinTrackXBounds, isWithinTrackYBounds;
  780. _this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
  781. _this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
  782. if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
  783. isWithinTrackXBounds = _this.isWithinBounds(_this.axis.x.track.rect);
  784. }
  785. if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
  786. isWithinTrackYBounds = _this.isWithinBounds(_this.axis.y.track.rect);
  787. }
  788. // If any pointer event is called on the scrollbar
  789. if (isWithinTrackXBounds || isWithinTrackYBounds) {
  790. // Prevent event leaking
  791. e.stopPropagation();
  792. if (e.type === 'pointerdown' && e.pointerType !== 'touch') {
  793. if (isWithinTrackXBounds) {
  794. _this.axis.x.scrollbar.rect =
  795. _this.axis.x.scrollbar.el.getBoundingClientRect();
  796. if (_this.isWithinBounds(_this.axis.x.scrollbar.rect)) {
  797. _this.onDragStart(e, 'x');
  798. }
  799. else {
  800. _this.onTrackClick(e, 'x');
  801. }
  802. }
  803. if (isWithinTrackYBounds) {
  804. _this.axis.y.scrollbar.rect =
  805. _this.axis.y.scrollbar.el.getBoundingClientRect();
  806. if (_this.isWithinBounds(_this.axis.y.scrollbar.rect)) {
  807. _this.onDragStart(e, 'y');
  808. }
  809. else {
  810. _this.onTrackClick(e, 'y');
  811. }
  812. }
  813. }
  814. }
  815. };
  816. /**
  817. * Drag scrollbar handle
  818. */
  819. this.drag = function (e) {
  820. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
  821. if (!_this.draggedAxis || !_this.contentWrapperEl)
  822. return;
  823. var eventOffset;
  824. var track = _this.axis[_this.draggedAxis].track;
  825. var trackSize = (_b = (_a = track.rect) === null || _a === void 0 ? void 0 : _a[_this.axis[_this.draggedAxis].sizeAttr]) !== null && _b !== void 0 ? _b : 0;
  826. var scrollbar = _this.axis[_this.draggedAxis].scrollbar;
  827. var contentSize = (_d = (_c = _this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c[_this.axis[_this.draggedAxis].scrollSizeAttr]) !== null && _d !== void 0 ? _d : 0;
  828. var hostSize = parseInt((_f = (_e = _this.elStyles) === null || _e === void 0 ? void 0 : _e[_this.axis[_this.draggedAxis].sizeAttr]) !== null && _f !== void 0 ? _f : '0px', 10);
  829. e.preventDefault();
  830. e.stopPropagation();
  831. if (_this.draggedAxis === 'y') {
  832. eventOffset = e.pageY;
  833. }
  834. else {
  835. eventOffset = e.pageX;
  836. }
  837. // Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset).
  838. var dragPos = eventOffset -
  839. ((_h = (_g = track.rect) === null || _g === void 0 ? void 0 : _g[_this.axis[_this.draggedAxis].offsetAttr]) !== null && _h !== void 0 ? _h : 0) -
  840. _this.axis[_this.draggedAxis].dragOffset;
  841. dragPos =
  842. _this.draggedAxis === 'x' && _this.isRtl
  843. ? ((_k = (_j = track.rect) === null || _j === void 0 ? void 0 : _j[_this.axis[_this.draggedAxis].sizeAttr]) !== null && _k !== void 0 ? _k : 0) -
  844. scrollbar.size -
  845. dragPos
  846. : dragPos;
  847. // Convert the mouse position into a percentage of the scrollbar height/width.
  848. var dragPerc = dragPos / (trackSize - scrollbar.size);
  849. // Scroll the content by the same percentage.
  850. var scrollPos = dragPerc * (contentSize - hostSize);
  851. // Fix browsers inconsistency on RTL
  852. if (_this.draggedAxis === 'x' && _this.isRtl) {
  853. scrollPos = ((_l = SimpleBarCore.getRtlHelpers()) === null || _l === void 0 ? void 0 : _l.isScrollingToNegative)
  854. ? -scrollPos
  855. : scrollPos;
  856. }
  857. _this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollOffsetAttr] =
  858. scrollPos;
  859. };
  860. /**
  861. * End scroll handle drag
  862. */
  863. this.onEndDrag = function (e) {
  864. _this.isDragging = false;
  865. var elDocument = getElementDocument(_this.el);
  866. var elWindow = getElementWindow(_this.el);
  867. e.preventDefault();
  868. e.stopPropagation();
  869. removeClasses(_this.el, _this.classNames.dragging);
  870. _this.onStopScrolling();
  871. elDocument.removeEventListener('mousemove', _this.drag, true);
  872. elDocument.removeEventListener('mouseup', _this.onEndDrag, true);
  873. _this.removePreventClickId = elWindow.setTimeout(function () {
  874. // Remove these asynchronously so we still suppress click events
  875. // generated simultaneously with mouseup.
  876. elDocument.removeEventListener('click', _this.preventClick, true);
  877. elDocument.removeEventListener('dblclick', _this.preventClick, true);
  878. _this.removePreventClickId = null;
  879. });
  880. };
  881. /**
  882. * Handler to ignore click events during drag
  883. */
  884. this.preventClick = function (e) {
  885. e.preventDefault();
  886. e.stopPropagation();
  887. };
  888. this.el = element;
  889. this.options = __assign(__assign({}, SimpleBarCore.defaultOptions), options);
  890. this.classNames = __assign(__assign({}, SimpleBarCore.defaultOptions.classNames), options.classNames);
  891. this.axis = {
  892. x: {
  893. scrollOffsetAttr: 'scrollLeft',
  894. sizeAttr: 'width',
  895. scrollSizeAttr: 'scrollWidth',
  896. offsetSizeAttr: 'offsetWidth',
  897. offsetAttr: 'left',
  898. overflowAttr: 'overflowX',
  899. dragOffset: 0,
  900. isOverflowing: true,
  901. forceVisible: false,
  902. track: { size: null, el: null, rect: null, isVisible: false },
  903. scrollbar: { size: null, el: null, rect: null, isVisible: false }
  904. },
  905. y: {
  906. scrollOffsetAttr: 'scrollTop',
  907. sizeAttr: 'height',
  908. scrollSizeAttr: 'scrollHeight',
  909. offsetSizeAttr: 'offsetHeight',
  910. offsetAttr: 'top',
  911. overflowAttr: 'overflowY',
  912. dragOffset: 0,
  913. isOverflowing: true,
  914. forceVisible: false,
  915. track: { size: null, el: null, rect: null, isVisible: false },
  916. scrollbar: { size: null, el: null, rect: null, isVisible: false }
  917. }
  918. };
  919. if (typeof this.el !== 'object' || !this.el.nodeName) {
  920. throw new Error("Argument passed to SimpleBar must be an HTML element instead of ".concat(this.el));
  921. }
  922. this.onMouseMove = throttle(this._onMouseMove, 64);
  923. this.onWindowResize = debounce(this._onWindowResize, 64, { leading: true });
  924. this.onStopScrolling = debounce(this._onStopScrolling, this.stopScrollDelay);
  925. this.onMouseEntered = debounce(this._onMouseEntered, this.stopScrollDelay);
  926. this.init();
  927. }
  928. /**
  929. * Helper to fix browsers inconsistency on RTL:
  930. * - Firefox inverts the scrollbar initial position
  931. * - IE11 inverts both scrollbar position and scrolling offset
  932. * Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
  933. */
  934. SimpleBarCore.getRtlHelpers = function () {
  935. if (SimpleBarCore.rtlHelpers) {
  936. return SimpleBarCore.rtlHelpers;
  937. }
  938. var dummyDiv = document.createElement('div');
  939. dummyDiv.innerHTML =
  940. '<div class="simplebar-dummy-scrollbar-size"><div></div></div>';
  941. var scrollbarDummyEl = dummyDiv.firstElementChild;
  942. var dummyChild = scrollbarDummyEl === null || scrollbarDummyEl === void 0 ? void 0 : scrollbarDummyEl.firstElementChild;
  943. if (!dummyChild)
  944. return null;
  945. document.body.appendChild(scrollbarDummyEl);
  946. scrollbarDummyEl.scrollLeft = 0;
  947. var dummyContainerOffset = SimpleBarCore.getOffset(scrollbarDummyEl);
  948. var dummyChildOffset = SimpleBarCore.getOffset(dummyChild);
  949. scrollbarDummyEl.scrollLeft = -999;
  950. var dummyChildOffsetAfterScroll = SimpleBarCore.getOffset(dummyChild);
  951. document.body.removeChild(scrollbarDummyEl);
  952. SimpleBarCore.rtlHelpers = {
  953. // determines if the scrolling is responding with negative values
  954. isScrollOriginAtZero: dummyContainerOffset.left !== dummyChildOffset.left,
  955. // determines if the origin scrollbar position is inverted or not (positioned on left or right)
  956. isScrollingToNegative: dummyChildOffset.left !== dummyChildOffsetAfterScroll.left
  957. };
  958. return SimpleBarCore.rtlHelpers;
  959. };
  960. SimpleBarCore.prototype.getScrollbarWidth = function () {
  961. // Try/catch for FF 56 throwing on undefined computedStyles
  962. try {
  963. // Detect browsers supporting CSS scrollbar styling and do not calculate
  964. if ((this.contentWrapperEl &&
  965. getComputedStyle(this.contentWrapperEl, '::-webkit-scrollbar')
  966. .display === 'none') ||
  967. 'scrollbarWidth' in document.documentElement.style ||
  968. '-ms-overflow-style' in document.documentElement.style) {
  969. return 0;
  970. }
  971. else {
  972. return scrollbarWidth();
  973. }
  974. }
  975. catch (e) {
  976. return scrollbarWidth();
  977. }
  978. };
  979. SimpleBarCore.getOffset = function (el) {
  980. var rect = el.getBoundingClientRect();
  981. var elDocument = getElementDocument(el);
  982. var elWindow = getElementWindow(el);
  983. return {
  984. top: rect.top +
  985. (elWindow.pageYOffset || elDocument.documentElement.scrollTop),
  986. left: rect.left +
  987. (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
  988. };
  989. };
  990. SimpleBarCore.prototype.init = function () {
  991. // We stop here on server-side
  992. if (canUseDOM$1) {
  993. this.initDOM();
  994. this.rtlHelpers = SimpleBarCore.getRtlHelpers();
  995. this.scrollbarWidth = this.getScrollbarWidth();
  996. this.recalculate();
  997. this.initListeners();
  998. }
  999. };
  1000. SimpleBarCore.prototype.initDOM = function () {
  1001. var _a, _b;
  1002. // assume that element has his DOM already initiated
  1003. this.wrapperEl = this.el.querySelector(classNamesToQuery(this.classNames.wrapper));
  1004. this.contentWrapperEl =
  1005. this.options.scrollableNode ||
  1006. this.el.querySelector(classNamesToQuery(this.classNames.contentWrapper));
  1007. this.contentEl =
  1008. this.options.contentNode ||
  1009. this.el.querySelector(classNamesToQuery(this.classNames.contentEl));
  1010. this.offsetEl = this.el.querySelector(classNamesToQuery(this.classNames.offset));
  1011. this.maskEl = this.el.querySelector(classNamesToQuery(this.classNames.mask));
  1012. this.placeholderEl = this.findChild(this.wrapperEl, classNamesToQuery(this.classNames.placeholder));
  1013. this.heightAutoObserverWrapperEl = this.el.querySelector(classNamesToQuery(this.classNames.heightAutoObserverWrapperEl));
  1014. this.heightAutoObserverEl = this.el.querySelector(classNamesToQuery(this.classNames.heightAutoObserverEl));
  1015. this.axis.x.track.el = this.findChild(this.el, "".concat(classNamesToQuery(this.classNames.track)).concat(classNamesToQuery(this.classNames.horizontal)));
  1016. this.axis.y.track.el = this.findChild(this.el, "".concat(classNamesToQuery(this.classNames.track)).concat(classNamesToQuery(this.classNames.vertical)));
  1017. this.axis.x.scrollbar.el =
  1018. ((_a = this.axis.x.track.el) === null || _a === void 0 ? void 0 : _a.querySelector(classNamesToQuery(this.classNames.scrollbar))) || null;
  1019. this.axis.y.scrollbar.el =
  1020. ((_b = this.axis.y.track.el) === null || _b === void 0 ? void 0 : _b.querySelector(classNamesToQuery(this.classNames.scrollbar))) || null;
  1021. if (!this.options.autoHide) {
  1022. addClasses$2(this.axis.x.scrollbar.el, this.classNames.visible);
  1023. addClasses$2(this.axis.y.scrollbar.el, this.classNames.visible);
  1024. }
  1025. };
  1026. SimpleBarCore.prototype.initListeners = function () {
  1027. var _this = this;
  1028. var _a;
  1029. var elWindow = getElementWindow(this.el);
  1030. // Event listeners
  1031. this.el.addEventListener('mouseenter', this.onMouseEnter);
  1032. this.el.addEventListener('pointerdown', this.onPointerEvent, true);
  1033. this.el.addEventListener('mousemove', this.onMouseMove);
  1034. this.el.addEventListener('mouseleave', this.onMouseLeave);
  1035. (_a = this.contentWrapperEl) === null || _a === void 0 ? void 0 : _a.addEventListener('scroll', this.onScroll);
  1036. // Browser zoom triggers a window resize
  1037. elWindow.addEventListener('resize', this.onWindowResize);
  1038. if (!this.contentEl)
  1039. return;
  1040. if (window.ResizeObserver) {
  1041. // Hack for https://github.com/WICG/ResizeObserver/issues/38
  1042. var resizeObserverStarted_1 = false;
  1043. var resizeObserver = elWindow.ResizeObserver || ResizeObserver;
  1044. this.resizeObserver = new resizeObserver(function () {
  1045. if (!resizeObserverStarted_1)
  1046. return;
  1047. elWindow.requestAnimationFrame(function () {
  1048. _this.recalculate();
  1049. });
  1050. });
  1051. this.resizeObserver.observe(this.el);
  1052. this.resizeObserver.observe(this.contentEl);
  1053. elWindow.requestAnimationFrame(function () {
  1054. resizeObserverStarted_1 = true;
  1055. });
  1056. }
  1057. // This is required to detect horizontal scroll. Vertical scroll only needs the resizeObserver.
  1058. this.mutationObserver = new elWindow.MutationObserver(function () {
  1059. elWindow.requestAnimationFrame(function () {
  1060. _this.recalculate();
  1061. });
  1062. });
  1063. this.mutationObserver.observe(this.contentEl, {
  1064. childList: true,
  1065. subtree: true,
  1066. characterData: true
  1067. });
  1068. };
  1069. SimpleBarCore.prototype.recalculate = function () {
  1070. if (!this.heightAutoObserverEl ||
  1071. !this.contentEl ||
  1072. !this.contentWrapperEl ||
  1073. !this.wrapperEl ||
  1074. !this.placeholderEl)
  1075. return;
  1076. var elWindow = getElementWindow(this.el);
  1077. this.elStyles = elWindow.getComputedStyle(this.el);
  1078. this.isRtl = this.elStyles.direction === 'rtl';
  1079. var contentElOffsetWidth = this.contentEl.offsetWidth;
  1080. var isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
  1081. var isWidthAuto = this.heightAutoObserverEl.offsetWidth <= 1 || contentElOffsetWidth > 0;
  1082. var contentWrapperElOffsetWidth = this.contentWrapperEl.offsetWidth;
  1083. var elOverflowX = this.elStyles.overflowX;
  1084. var elOverflowY = this.elStyles.overflowY;
  1085. this.contentEl.style.padding = "".concat(this.elStyles.paddingTop, " ").concat(this.elStyles.paddingRight, " ").concat(this.elStyles.paddingBottom, " ").concat(this.elStyles.paddingLeft);
  1086. this.wrapperEl.style.margin = "-".concat(this.elStyles.paddingTop, " -").concat(this.elStyles.paddingRight, " -").concat(this.elStyles.paddingBottom, " -").concat(this.elStyles.paddingLeft);
  1087. var contentElScrollHeight = this.contentEl.scrollHeight;
  1088. var contentElScrollWidth = this.contentEl.scrollWidth;
  1089. this.contentWrapperEl.style.height = isHeightAuto ? 'auto' : '100%';
  1090. // Determine placeholder size
  1091. this.placeholderEl.style.width = isWidthAuto
  1092. ? "".concat(contentElOffsetWidth || contentElScrollWidth, "px")
  1093. : 'auto';
  1094. this.placeholderEl.style.height = "".concat(contentElScrollHeight, "px");
  1095. var contentWrapperElOffsetHeight = this.contentWrapperEl.offsetHeight;
  1096. this.axis.x.isOverflowing =
  1097. contentElOffsetWidth !== 0 && contentElScrollWidth > contentElOffsetWidth;
  1098. this.axis.y.isOverflowing =
  1099. contentElScrollHeight > contentWrapperElOffsetHeight;
  1100. // Set isOverflowing to false if user explicitely set hidden overflow
  1101. this.axis.x.isOverflowing =
  1102. elOverflowX === 'hidden' ? false : this.axis.x.isOverflowing;
  1103. this.axis.y.isOverflowing =
  1104. elOverflowY === 'hidden' ? false : this.axis.y.isOverflowing;
  1105. this.axis.x.forceVisible =
  1106. this.options.forceVisible === 'x' || this.options.forceVisible === true;
  1107. this.axis.y.forceVisible =
  1108. this.options.forceVisible === 'y' || this.options.forceVisible === true;
  1109. this.hideNativeScrollbar();
  1110. // Set isOverflowing to false if scrollbar is not necessary (content is shorter than offset)
  1111. var offsetForXScrollbar = this.axis.x.isOverflowing
  1112. ? this.scrollbarWidth
  1113. : 0;
  1114. var offsetForYScrollbar = this.axis.y.isOverflowing
  1115. ? this.scrollbarWidth
  1116. : 0;
  1117. this.axis.x.isOverflowing =
  1118. this.axis.x.isOverflowing &&
  1119. contentElScrollWidth > contentWrapperElOffsetWidth - offsetForYScrollbar;
  1120. this.axis.y.isOverflowing =
  1121. this.axis.y.isOverflowing &&
  1122. contentElScrollHeight >
  1123. contentWrapperElOffsetHeight - offsetForXScrollbar;
  1124. this.axis.x.scrollbar.size = this.getScrollbarSize('x');
  1125. this.axis.y.scrollbar.size = this.getScrollbarSize('y');
  1126. if (this.axis.x.scrollbar.el)
  1127. this.axis.x.scrollbar.el.style.width = "".concat(this.axis.x.scrollbar.size, "px");
  1128. if (this.axis.y.scrollbar.el)
  1129. this.axis.y.scrollbar.el.style.height = "".concat(this.axis.y.scrollbar.size, "px");
  1130. this.positionScrollbar('x');
  1131. this.positionScrollbar('y');
  1132. this.toggleTrackVisibility('x');
  1133. this.toggleTrackVisibility('y');
  1134. };
  1135. /**
  1136. * Calculate scrollbar size
  1137. */
  1138. SimpleBarCore.prototype.getScrollbarSize = function (axis) {
  1139. var _a, _b;
  1140. if (axis === void 0) { axis = 'y'; }
  1141. if (!this.axis[axis].isOverflowing || !this.contentEl) {
  1142. return 0;
  1143. }
  1144. var contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
  1145. var trackSize = (_b = (_a = this.axis[axis].track.el) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetSizeAttr]) !== null && _b !== void 0 ? _b : 0;
  1146. var scrollbarRatio = trackSize / contentSize;
  1147. var scrollbarSize;
  1148. // Calculate new height/position of drag handle.
  1149. scrollbarSize = Math.max(~~(scrollbarRatio * trackSize), this.options.scrollbarMinSize);
  1150. if (this.options.scrollbarMaxSize) {
  1151. scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
  1152. }
  1153. return scrollbarSize;
  1154. };
  1155. SimpleBarCore.prototype.positionScrollbar = function (axis) {
  1156. var _a, _b, _c;
  1157. if (axis === void 0) { axis = 'y'; }
  1158. var scrollbar = this.axis[axis].scrollbar;
  1159. if (!this.axis[axis].isOverflowing ||
  1160. !this.contentWrapperEl ||
  1161. !scrollbar.el ||
  1162. !this.elStyles) {
  1163. return;
  1164. }
  1165. var contentSize = this.contentWrapperEl[this.axis[axis].scrollSizeAttr];
  1166. var trackSize = ((_a = this.axis[axis].track.el) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetSizeAttr]) || 0;
  1167. var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
  1168. var scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
  1169. scrollOffset =
  1170. axis === 'x' &&
  1171. this.isRtl &&
  1172. ((_b = SimpleBarCore.getRtlHelpers()) === null || _b === void 0 ? void 0 : _b.isScrollOriginAtZero)
  1173. ? -scrollOffset
  1174. : scrollOffset;
  1175. if (axis === 'x' && this.isRtl) {
  1176. scrollOffset = ((_c = SimpleBarCore.getRtlHelpers()) === null || _c === void 0 ? void 0 : _c.isScrollingToNegative)
  1177. ? scrollOffset
  1178. : -scrollOffset;
  1179. }
  1180. var scrollPourcent = scrollOffset / (contentSize - hostSize);
  1181. var handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
  1182. handleOffset =
  1183. axis === 'x' && this.isRtl
  1184. ? -handleOffset + (trackSize - scrollbar.size)
  1185. : handleOffset;
  1186. scrollbar.el.style.transform =
  1187. axis === 'x'
  1188. ? "translate3d(".concat(handleOffset, "px, 0, 0)")
  1189. : "translate3d(0, ".concat(handleOffset, "px, 0)");
  1190. };
  1191. SimpleBarCore.prototype.toggleTrackVisibility = function (axis) {
  1192. if (axis === void 0) { axis = 'y'; }
  1193. var track = this.axis[axis].track.el;
  1194. var scrollbar = this.axis[axis].scrollbar.el;
  1195. if (!track || !scrollbar || !this.contentWrapperEl)
  1196. return;
  1197. if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
  1198. track.style.visibility = 'visible';
  1199. this.contentWrapperEl.style[this.axis[axis].overflowAttr] = 'scroll';
  1200. this.el.classList.add("".concat(this.classNames.scrollable, "-").concat(axis));
  1201. }
  1202. else {
  1203. track.style.visibility = 'hidden';
  1204. this.contentWrapperEl.style[this.axis[axis].overflowAttr] = 'hidden';
  1205. this.el.classList.remove("".concat(this.classNames.scrollable, "-").concat(axis));
  1206. }
  1207. // Even if forceVisible is enabled, scrollbar itself should be hidden
  1208. if (this.axis[axis].isOverflowing) {
  1209. scrollbar.style.display = 'block';
  1210. }
  1211. else {
  1212. scrollbar.style.display = 'none';
  1213. }
  1214. };
  1215. SimpleBarCore.prototype.showScrollbar = function (axis) {
  1216. if (axis === void 0) { axis = 'y'; }
  1217. if (this.axis[axis].isOverflowing && !this.axis[axis].scrollbar.isVisible) {
  1218. addClasses$2(this.axis[axis].scrollbar.el, this.classNames.visible);
  1219. this.axis[axis].scrollbar.isVisible = true;
  1220. }
  1221. };
  1222. SimpleBarCore.prototype.hideScrollbar = function (axis) {
  1223. if (axis === void 0) { axis = 'y'; }
  1224. if (this.isDragging)
  1225. return;
  1226. if (this.axis[axis].isOverflowing && this.axis[axis].scrollbar.isVisible) {
  1227. removeClasses(this.axis[axis].scrollbar.el, this.classNames.visible);
  1228. this.axis[axis].scrollbar.isVisible = false;
  1229. }
  1230. };
  1231. SimpleBarCore.prototype.hideNativeScrollbar = function () {
  1232. if (!this.offsetEl)
  1233. return;
  1234. this.offsetEl.style[this.isRtl ? 'left' : 'right'] =
  1235. this.axis.y.isOverflowing || this.axis.y.forceVisible
  1236. ? "-".concat(this.scrollbarWidth, "px")
  1237. : '0px';
  1238. this.offsetEl.style.bottom =
  1239. this.axis.x.isOverflowing || this.axis.x.forceVisible
  1240. ? "-".concat(this.scrollbarWidth, "px")
  1241. : '0px';
  1242. };
  1243. SimpleBarCore.prototype.onMouseMoveForAxis = function (axis) {
  1244. if (axis === void 0) { axis = 'y'; }
  1245. var currentAxis = this.axis[axis];
  1246. if (!currentAxis.track.el || !currentAxis.scrollbar.el)
  1247. return;
  1248. currentAxis.track.rect = currentAxis.track.el.getBoundingClientRect();
  1249. currentAxis.scrollbar.rect =
  1250. currentAxis.scrollbar.el.getBoundingClientRect();
  1251. if (this.isWithinBounds(currentAxis.track.rect)) {
  1252. this.showScrollbar(axis);
  1253. addClasses$2(currentAxis.track.el, this.classNames.hover);
  1254. if (this.isWithinBounds(currentAxis.scrollbar.rect)) {
  1255. addClasses$2(currentAxis.scrollbar.el, this.classNames.hover);
  1256. }
  1257. else {
  1258. removeClasses(currentAxis.scrollbar.el, this.classNames.hover);
  1259. }
  1260. }
  1261. else {
  1262. removeClasses(currentAxis.track.el, this.classNames.hover);
  1263. if (this.options.autoHide) {
  1264. this.hideScrollbar(axis);
  1265. }
  1266. }
  1267. };
  1268. SimpleBarCore.prototype.onMouseLeaveForAxis = function (axis) {
  1269. if (axis === void 0) { axis = 'y'; }
  1270. removeClasses(this.axis[axis].track.el, this.classNames.hover);
  1271. removeClasses(this.axis[axis].scrollbar.el, this.classNames.hover);
  1272. if (this.options.autoHide) {
  1273. this.hideScrollbar(axis);
  1274. }
  1275. };
  1276. /**
  1277. * on scrollbar handle drag movement starts
  1278. */
  1279. SimpleBarCore.prototype.onDragStart = function (e, axis) {
  1280. var _a;
  1281. if (axis === void 0) { axis = 'y'; }
  1282. this.isDragging = true;
  1283. var elDocument = getElementDocument(this.el);
  1284. var elWindow = getElementWindow(this.el);
  1285. var scrollbar = this.axis[axis].scrollbar;
  1286. // Measure how far the user's mouse is from the top of the scrollbar drag handle.
  1287. var eventOffset = axis === 'y' ? e.pageY : e.pageX;
  1288. this.axis[axis].dragOffset =
  1289. eventOffset - (((_a = scrollbar.rect) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetAttr]) || 0);
  1290. this.draggedAxis = axis;
  1291. addClasses$2(this.el, this.classNames.dragging);
  1292. elDocument.addEventListener('mousemove', this.drag, true);
  1293. elDocument.addEventListener('mouseup', this.onEndDrag, true);
  1294. if (this.removePreventClickId === null) {
  1295. elDocument.addEventListener('click', this.preventClick, true);
  1296. elDocument.addEventListener('dblclick', this.preventClick, true);
  1297. }
  1298. else {
  1299. elWindow.clearTimeout(this.removePreventClickId);
  1300. this.removePreventClickId = null;
  1301. }
  1302. };
  1303. SimpleBarCore.prototype.onTrackClick = function (e, axis) {
  1304. var _this = this;
  1305. var _a, _b, _c, _d;
  1306. if (axis === void 0) { axis = 'y'; }
  1307. var currentAxis = this.axis[axis];
  1308. if (!this.options.clickOnTrack ||
  1309. !currentAxis.scrollbar.el ||
  1310. !this.contentWrapperEl)
  1311. return;
  1312. // Preventing the event's default to trigger click underneath
  1313. e.preventDefault();
  1314. var elWindow = getElementWindow(this.el);
  1315. this.axis[axis].scrollbar.rect =
  1316. currentAxis.scrollbar.el.getBoundingClientRect();
  1317. var scrollbar = this.axis[axis].scrollbar;
  1318. var scrollbarOffset = (_b = (_a = scrollbar.rect) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetAttr]) !== null && _b !== void 0 ? _b : 0;
  1319. var hostSize = parseInt((_d = (_c = this.elStyles) === null || _c === void 0 ? void 0 : _c[this.axis[axis].sizeAttr]) !== null && _d !== void 0 ? _d : '0px', 10);
  1320. var scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
  1321. var t = axis === 'y'
  1322. ? this.mouseY - scrollbarOffset
  1323. : this.mouseX - scrollbarOffset;
  1324. var dir = t < 0 ? -1 : 1;
  1325. var scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize;
  1326. var speed = 40;
  1327. var scrollTo = function () {
  1328. if (!_this.contentWrapperEl)
  1329. return;
  1330. if (dir === -1) {
  1331. if (scrolled > scrollSize) {
  1332. scrolled -= speed;
  1333. _this.contentWrapperEl[_this.axis[axis].scrollOffsetAttr] = scrolled;
  1334. elWindow.requestAnimationFrame(scrollTo);
  1335. }
  1336. }
  1337. else {
  1338. if (scrolled < scrollSize) {
  1339. scrolled += speed;
  1340. _this.contentWrapperEl[_this.axis[axis].scrollOffsetAttr] = scrolled;
  1341. elWindow.requestAnimationFrame(scrollTo);
  1342. }
  1343. }
  1344. };
  1345. scrollTo();
  1346. };
  1347. /**
  1348. * Getter for content element
  1349. */
  1350. SimpleBarCore.prototype.getContentElement = function () {
  1351. return this.contentEl;
  1352. };
  1353. /**
  1354. * Getter for original scrolling element
  1355. */
  1356. SimpleBarCore.prototype.getScrollElement = function () {
  1357. return this.contentWrapperEl;
  1358. };
  1359. SimpleBarCore.prototype.removeListeners = function () {
  1360. var elWindow = getElementWindow(this.el);
  1361. // Event listeners
  1362. this.el.removeEventListener('mouseenter', this.onMouseEnter);
  1363. this.el.removeEventListener('pointerdown', this.onPointerEvent, true);
  1364. this.el.removeEventListener('mousemove', this.onMouseMove);
  1365. this.el.removeEventListener('mouseleave', this.onMouseLeave);
  1366. if (this.contentWrapperEl) {
  1367. this.contentWrapperEl.removeEventListener('scroll', this.onScroll);
  1368. }
  1369. elWindow.removeEventListener('resize', this.onWindowResize);
  1370. if (this.mutationObserver) {
  1371. this.mutationObserver.disconnect();
  1372. }
  1373. if (this.resizeObserver) {
  1374. this.resizeObserver.disconnect();
  1375. }
  1376. // Cancel all debounced functions
  1377. this.onMouseMove.cancel();
  1378. this.onWindowResize.cancel();
  1379. this.onStopScrolling.cancel();
  1380. this.onMouseEntered.cancel();
  1381. };
  1382. /**
  1383. * Remove all listeners from DOM nodes
  1384. */
  1385. SimpleBarCore.prototype.unMount = function () {
  1386. this.removeListeners();
  1387. };
  1388. /**
  1389. * Check if mouse is within bounds
  1390. */
  1391. SimpleBarCore.prototype.isWithinBounds = function (bbox) {
  1392. return (this.mouseX >= bbox.left &&
  1393. this.mouseX <= bbox.left + bbox.width &&
  1394. this.mouseY >= bbox.top &&
  1395. this.mouseY <= bbox.top + bbox.height);
  1396. };
  1397. /**
  1398. * Find element children matches query
  1399. */
  1400. SimpleBarCore.prototype.findChild = function (el, query) {
  1401. var matches = el.matches ||
  1402. el.webkitMatchesSelector ||
  1403. el.mozMatchesSelector ||
  1404. el.msMatchesSelector;
  1405. return Array.prototype.filter.call(el.children, function (child) {
  1406. return matches.call(child, query);
  1407. })[0];
  1408. };
  1409. SimpleBarCore.rtlHelpers = null;
  1410. SimpleBarCore.defaultOptions = {
  1411. forceVisible: false,
  1412. clickOnTrack: true,
  1413. scrollbarMinSize: 25,
  1414. scrollbarMaxSize: 0,
  1415. ariaLabel: 'scrollable content',
  1416. tabIndex: 0,
  1417. classNames: {
  1418. contentEl: 'simplebar-content',
  1419. contentWrapper: 'simplebar-content-wrapper',
  1420. offset: 'simplebar-offset',
  1421. mask: 'simplebar-mask',
  1422. wrapper: 'simplebar-wrapper',
  1423. placeholder: 'simplebar-placeholder',
  1424. scrollbar: 'simplebar-scrollbar',
  1425. track: 'simplebar-track',
  1426. heightAutoObserverWrapperEl: 'simplebar-height-auto-observer-wrapper',
  1427. heightAutoObserverEl: 'simplebar-height-auto-observer',
  1428. visible: 'simplebar-visible',
  1429. horizontal: 'simplebar-horizontal',
  1430. vertical: 'simplebar-vertical',
  1431. hover: 'simplebar-hover',
  1432. dragging: 'simplebar-dragging',
  1433. scrolling: 'simplebar-scrolling',
  1434. scrollable: 'simplebar-scrollable',
  1435. mouseEntered: 'simplebar-mouse-entered'
  1436. },
  1437. scrollableNode: null,
  1438. contentNode: null,
  1439. autoHide: true
  1440. };
  1441. /**
  1442. * Static functions
  1443. */
  1444. SimpleBarCore.getOptions = getOptions$2;
  1445. SimpleBarCore.helpers = helpers;
  1446. return SimpleBarCore;
  1447. }());
  1448. var _a = SimpleBarCore.helpers, getOptions = _a.getOptions, addClasses = _a.addClasses, canUseDOM = _a.canUseDOM;
  1449. var SimpleBar = /** @class */ (function (_super) {
  1450. __extends(SimpleBar, _super);
  1451. function SimpleBar() {
  1452. var args = [];
  1453. for (var _i = 0; _i < arguments.length; _i++) {
  1454. args[_i] = arguments[_i];
  1455. }
  1456. var _this = _super.apply(this, args) || this;
  1457. // // Save a reference to the instance, so we know this DOM node has already been instancied
  1458. SimpleBar.instances.set(args[0], _this);
  1459. return _this;
  1460. }
  1461. SimpleBar.initDOMLoadedElements = function () {
  1462. document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  1463. window.removeEventListener('load', this.initDOMLoadedElements);
  1464. Array.prototype.forEach.call(document.querySelectorAll('[data-simplebar]'), function (el) {
  1465. if (el.getAttribute('data-simplebar') !== 'init' &&
  1466. !SimpleBar.instances.has(el))
  1467. new SimpleBar(el, getOptions(el.attributes));
  1468. });
  1469. };
  1470. SimpleBar.removeObserver = function () {
  1471. var _a;
  1472. (_a = SimpleBar.globalObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
  1473. };
  1474. SimpleBar.prototype.initDOM = function () {
  1475. var _this = this;
  1476. var _a, _b, _c;
  1477. // make sure this element doesn't have the elements yet
  1478. if (!Array.prototype.filter.call(this.el.children, function (child) {
  1479. return child.classList.contains(_this.classNames.wrapper);
  1480. }).length) {
  1481. // Prepare DOM
  1482. this.wrapperEl = document.createElement('div');
  1483. this.contentWrapperEl = document.createElement('div');
  1484. this.offsetEl = document.createElement('div');
  1485. this.maskEl = document.createElement('div');
  1486. this.contentEl = document.createElement('div');
  1487. this.placeholderEl = document.createElement('div');
  1488. this.heightAutoObserverWrapperEl = document.createElement('div');
  1489. this.heightAutoObserverEl = document.createElement('div');
  1490. addClasses(this.wrapperEl, this.classNames.wrapper);
  1491. addClasses(this.contentWrapperEl, this.classNames.contentWrapper);
  1492. addClasses(this.offsetEl, this.classNames.offset);
  1493. addClasses(this.maskEl, this.classNames.mask);
  1494. addClasses(this.contentEl, this.classNames.contentEl);
  1495. addClasses(this.placeholderEl, this.classNames.placeholder);
  1496. addClasses(this.heightAutoObserverWrapperEl, this.classNames.heightAutoObserverWrapperEl);
  1497. addClasses(this.heightAutoObserverEl, this.classNames.heightAutoObserverEl);
  1498. while (this.el.firstChild) {
  1499. this.contentEl.appendChild(this.el.firstChild);
  1500. }
  1501. this.contentWrapperEl.appendChild(this.contentEl);
  1502. this.offsetEl.appendChild(this.contentWrapperEl);
  1503. this.maskEl.appendChild(this.offsetEl);
  1504. this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
  1505. this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
  1506. this.wrapperEl.appendChild(this.maskEl);
  1507. this.wrapperEl.appendChild(this.placeholderEl);
  1508. this.el.appendChild(this.wrapperEl);
  1509. (_a = this.contentWrapperEl) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', this.options.tabIndex.toString());
  1510. (_b = this.contentWrapperEl) === null || _b === void 0 ? void 0 : _b.setAttribute('role', 'region');
  1511. (_c = this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-label', this.options.ariaLabel);
  1512. }
  1513. if (!this.axis.x.track.el || !this.axis.y.track.el) {
  1514. var track = document.createElement('div');
  1515. var scrollbar = document.createElement('div');
  1516. addClasses(track, this.classNames.track);
  1517. addClasses(scrollbar, this.classNames.scrollbar);
  1518. track.appendChild(scrollbar);
  1519. this.axis.x.track.el = track.cloneNode(true);
  1520. addClasses(this.axis.x.track.el, this.classNames.horizontal);
  1521. this.axis.y.track.el = track.cloneNode(true);
  1522. addClasses(this.axis.y.track.el, this.classNames.vertical);
  1523. this.el.appendChild(this.axis.x.track.el);
  1524. this.el.appendChild(this.axis.y.track.el);
  1525. }
  1526. SimpleBarCore.prototype.initDOM.call(this);
  1527. this.el.setAttribute('data-simplebar', 'init');
  1528. };
  1529. SimpleBar.prototype.unMount = function () {
  1530. SimpleBarCore.prototype.unMount.call(this);
  1531. SimpleBar.instances["delete"](this.el);
  1532. };
  1533. SimpleBar.initHtmlApi = function () {
  1534. this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this);
  1535. // MutationObserver is IE11+
  1536. if (typeof MutationObserver !== 'undefined') {
  1537. // Mutation observer to observe dynamically added elements
  1538. this.globalObserver = new MutationObserver(SimpleBar.handleMutations);
  1539. this.globalObserver.observe(document, { childList: true, subtree: true });
  1540. }
  1541. // Taken from jQuery `ready` function
  1542. // Instantiate elements already present on the page
  1543. if (document.readyState === 'complete' || // @ts-ignore: IE specific
  1544. (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
  1545. // Handle it asynchronously to allow scripts the opportunity to delay init
  1546. window.setTimeout(this.initDOMLoadedElements);
  1547. }
  1548. else {
  1549. document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements);
  1550. window.addEventListener('load', this.initDOMLoadedElements);
  1551. }
  1552. };
  1553. SimpleBar.handleMutations = function (mutations) {
  1554. mutations.forEach(function (mutation) {
  1555. mutation.addedNodes.forEach(function (addedNode) {
  1556. if (addedNode.nodeType === 1) {
  1557. if (addedNode.hasAttribute('data-simplebar')) {
  1558. !SimpleBar.instances.has(addedNode) &&
  1559. document.documentElement.contains(addedNode) &&
  1560. new SimpleBar(addedNode, getOptions(addedNode.attributes));
  1561. }
  1562. else {
  1563. addedNode
  1564. .querySelectorAll('[data-simplebar]')
  1565. .forEach(function (el) {
  1566. if (el.getAttribute('data-simplebar') !== 'init' &&
  1567. !SimpleBar.instances.has(el) &&
  1568. document.documentElement.contains(el))
  1569. new SimpleBar(el, getOptions(el.attributes));
  1570. });
  1571. }
  1572. }
  1573. });
  1574. mutation.removedNodes.forEach(function (removedNode) {
  1575. var _a;
  1576. if (removedNode.nodeType === 1) {
  1577. if (removedNode.getAttribute('data-simplebar') === 'init') {
  1578. !document.documentElement.contains(removedNode) &&
  1579. ((_a = SimpleBar.instances.get(removedNode)) === null || _a === void 0 ? void 0 : _a.unMount());
  1580. }
  1581. else {
  1582. Array.prototype.forEach.call(removedNode.querySelectorAll('[data-simplebar="init"]'), function (el) {
  1583. var _a;
  1584. !document.documentElement.contains(el) &&
  1585. ((_a = SimpleBar.instances.get(el)) === null || _a === void 0 ? void 0 : _a.unMount());
  1586. });
  1587. }
  1588. }
  1589. });
  1590. });
  1591. };
  1592. SimpleBar.instances = new WeakMap();
  1593. return SimpleBar;
  1594. }(SimpleBarCore));
  1595. /**
  1596. * HTML API
  1597. * Called only in a browser env.
  1598. */
  1599. if (canUseDOM) {
  1600. SimpleBar.initHtmlApi();
  1601. }
  1602. return SimpleBar;
  1603. })();