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