| 1 |
/** |
| 2 |
* simplebar - v6.3.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 |
/** |
| 45 |
* Checks if `value` is the |
| 46 |
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) |
| 47 |
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) |
| 48 |
* |
| 49 |
* @static |
| 50 |
* @memberOf _ |
| 51 |
* @since 0.1.0 |
| 52 |
* @category Lang |
| 53 |
* @param {*} value The value to check. |
| 54 |
* @returns {boolean} Returns `true` if `value` is an object, else `false`. |
| 55 |
* @example |
| 56 |
* |
| 57 |
* _.isObject({}); |
| 58 |
* // => true |
| 59 |
* |
| 60 |
* _.isObject([1, 2, 3]); |
| 61 |
* // => true |
| 62 |
* |
| 63 |
* _.isObject(_.noop); |
| 64 |
* // => true |
| 65 |
* |
| 66 |
* _.isObject(null); |
| 67 |
* // => false |
| 68 |
*/ |
| 69 |
function isObject(value) { |
| 70 |
var type = typeof value; |
| 71 |
return value != null && (type == 'object' || type == 'function'); |
| 72 |
} |
| 73 |
|
| 74 |
/** Detect free variable `global` from Node.js. */ |
| 75 |
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global; |
| 76 |
|
| 77 |
var freeGlobal$1 = freeGlobal; |
| 78 |
|
| 79 |
/** Detect free variable `self`. */ |
| 80 |
var freeSelf = typeof self == 'object' && self && self.Object === Object && self; |
| 81 |
|
| 82 |
/** Used as a reference to the global object. */ |
| 83 |
var root = freeGlobal$1 || freeSelf || Function('return this')(); |
| 84 |
|
| 85 |
var root$1 = root; |
| 86 |
|
| 87 |
/** |
| 88 |
* Gets the timestamp of the number of milliseconds that have elapsed since |
| 89 |
* the Unix epoch (1 January 1970 00:00:00 UTC). |
| 90 |
* |
| 91 |
* @static |
| 92 |
* @memberOf _ |
| 93 |
* @since 2.4.0 |
| 94 |
* @category Date |
| 95 |
* @returns {number} Returns the timestamp. |
| 96 |
* @example |
| 97 |
* |
| 98 |
* _.defer(function(stamp) { |
| 99 |
* console.log(_.now() - stamp); |
| 100 |
* }, _.now()); |
| 101 |
* // => Logs the number of milliseconds it took for the deferred invocation. |
| 102 |
*/ |
| 103 |
var now = function() { |
| 104 |
return root$1.Date.now(); |
| 105 |
}; |
| 106 |
|
| 107 |
var now$1 = now; |
| 108 |
|
| 109 |
/** Used to match a single whitespace character. */ |
| 110 |
var reWhitespace = /\s/; |
| 111 |
|
| 112 |
/** |
| 113 |
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace |
| 114 |
* character of `string`. |
| 115 |
* |
| 116 |
* @private |
| 117 |
* @param {string} string The string to inspect. |
| 118 |
* @returns {number} Returns the index of the last non-whitespace character. |
| 119 |
*/ |
| 120 |
function trimmedEndIndex(string) { |
| 121 |
var index = string.length; |
| 122 |
|
| 123 |
while (index-- && reWhitespace.test(string.charAt(index))) {} |
| 124 |
return index; |
| 125 |
} |
| 126 |
|
| 127 |
/** Used to match leading whitespace. */ |
| 128 |
var reTrimStart = /^\s+/; |
| 129 |
|
| 130 |
/** |
| 131 |
* The base implementation of `_.trim`. |
| 132 |
* |
| 133 |
* @private |
| 134 |
* @param {string} string The string to trim. |
| 135 |
* @returns {string} Returns the trimmed string. |
| 136 |
*/ |
| 137 |
function baseTrim(string) { |
| 138 |
return string |
| 139 |
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '') |
| 140 |
: string; |
| 141 |
} |
| 142 |
|
| 143 |
/** Built-in value references. */ |
| 144 |
var Symbol = root$1.Symbol; |
| 145 |
|
| 146 |
var Symbol$1 = Symbol; |
| 147 |
|
| 148 |
/** Used for built-in method references. */ |
| 149 |
var objectProto$1 = Object.prototype; |
| 150 |
|
| 151 |
/** Used to check objects for own properties. */ |
| 152 |
var hasOwnProperty = objectProto$1.hasOwnProperty; |
| 153 |
|
| 154 |
/** |
| 155 |
* Used to resolve the |
| 156 |
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) |
| 157 |
* of values. |
| 158 |
*/ |
| 159 |
var nativeObjectToString$1 = objectProto$1.toString; |
| 160 |
|
| 161 |
/** Built-in value references. */ |
| 162 |
var symToStringTag$1 = Symbol$1 ? Symbol$1.toStringTag : undefined; |
| 163 |
|
| 164 |
/** |
| 165 |
* A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. |
| 166 |
* |
| 167 |
* @private |
| 168 |
* @param {*} value The value to query. |
| 169 |
* @returns {string} Returns the raw `toStringTag`. |
| 170 |
*/ |
| 171 |
function getRawTag(value) { |
| 172 |
var isOwn = hasOwnProperty.call(value, symToStringTag$1), |
| 173 |
tag = value[symToStringTag$1]; |
| 174 |
|
| 175 |
try { |
| 176 |
value[symToStringTag$1] = undefined; |
| 177 |
var unmasked = true; |
| 178 |
} catch (e) {} |
| 179 |
|
| 180 |
var result = nativeObjectToString$1.call(value); |
| 181 |
if (unmasked) { |
| 182 |
if (isOwn) { |
| 183 |
value[symToStringTag$1] = tag; |
| 184 |
} else { |
| 185 |
delete value[symToStringTag$1]; |
| 186 |
} |
| 187 |
} |
| 188 |
return result; |
| 189 |
} |
| 190 |
|
| 191 |
/** Used for built-in method references. */ |
| 192 |
var objectProto = Object.prototype; |
| 193 |
|
| 194 |
/** |
| 195 |
* Used to resolve the |
| 196 |
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) |
| 197 |
* of values. |
| 198 |
*/ |
| 199 |
var nativeObjectToString = objectProto.toString; |
| 200 |
|
| 201 |
/** |
| 202 |
* Converts `value` to a string using `Object.prototype.toString`. |
| 203 |
* |
| 204 |
* @private |
| 205 |
* @param {*} value The value to convert. |
| 206 |
* @returns {string} Returns the converted string. |
| 207 |
*/ |
| 208 |
function objectToString(value) { |
| 209 |
return nativeObjectToString.call(value); |
| 210 |
} |
| 211 |
|
| 212 |
/** `Object#toString` result references. */ |
| 213 |
var nullTag = '[object Null]', |
| 214 |
undefinedTag = '[object Undefined]'; |
| 215 |
|
| 216 |
/** Built-in value references. */ |
| 217 |
var symToStringTag = Symbol$1 ? Symbol$1.toStringTag : undefined; |
| 218 |
|
| 219 |
/** |
| 220 |
* The base implementation of `getTag` without fallbacks for buggy environments. |
| 221 |
* |
| 222 |
* @private |
| 223 |
* @param {*} value The value to query. |
| 224 |
* @returns {string} Returns the `toStringTag`. |
| 225 |
*/ |
| 226 |
function baseGetTag(value) { |
| 227 |
if (value == null) { |
| 228 |
return value === undefined ? undefinedTag : nullTag; |
| 229 |
} |
| 230 |
return (symToStringTag && symToStringTag in Object(value)) |
| 231 |
? getRawTag(value) |
| 232 |
: objectToString(value); |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* Checks if `value` is object-like. A value is object-like if it's not `null` |
| 237 |
* and has a `typeof` result of "object". |
| 238 |
* |
| 239 |
* @static |
| 240 |
* @memberOf _ |
| 241 |
* @since 4.0.0 |
| 242 |
* @category Lang |
| 243 |
* @param {*} value The value to check. |
| 244 |
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. |
| 245 |
* @example |
| 246 |
* |
| 247 |
* _.isObjectLike({}); |
| 248 |
* // => true |
| 249 |
* |
| 250 |
* _.isObjectLike([1, 2, 3]); |
| 251 |
* // => true |
| 252 |
* |
| 253 |
* _.isObjectLike(_.noop); |
| 254 |
* // => false |
| 255 |
* |
| 256 |
* _.isObjectLike(null); |
| 257 |
* // => false |
| 258 |
*/ |
| 259 |
function isObjectLike(value) { |
| 260 |
return value != null && typeof value == 'object'; |
| 261 |
} |
| 262 |
|
| 263 |
/** `Object#toString` result references. */ |
| 264 |
var symbolTag = '[object Symbol]'; |
| 265 |
|
| 266 |
/** |
| 267 |
* Checks if `value` is classified as a `Symbol` primitive or object. |
| 268 |
* |
| 269 |
* @static |
| 270 |
* @memberOf _ |
| 271 |
* @since 4.0.0 |
| 272 |
* @category Lang |
| 273 |
* @param {*} value The value to check. |
| 274 |
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`. |
| 275 |
* @example |
| 276 |
* |
| 277 |
* _.isSymbol(Symbol.iterator); |
| 278 |
* // => true |
| 279 |
* |
| 280 |
* _.isSymbol('abc'); |
| 281 |
* // => false |
| 282 |
*/ |
| 283 |
function isSymbol(value) { |
| 284 |
return typeof value == 'symbol' || |
| 285 |
(isObjectLike(value) && baseGetTag(value) == symbolTag); |
| 286 |
} |
| 287 |
|
| 288 |
/** Used as references for various `Number` constants. */ |
| 289 |
var NAN = 0 / 0; |
| 290 |
|
| 291 |
/** Used to detect bad signed hexadecimal string values. */ |
| 292 |
var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; |
| 293 |
|
| 294 |
/** Used to detect binary string values. */ |
| 295 |
var reIsBinary = /^0b[01]+$/i; |
| 296 |
|
| 297 |
/** Used to detect octal string values. */ |
| 298 |
var reIsOctal = /^0o[0-7]+$/i; |
| 299 |
|
| 300 |
/** Built-in method references without a dependency on `root`. */ |
| 301 |
var freeParseInt = parseInt; |
| 302 |
|
| 303 |
/** |
| 304 |
* Converts `value` to a number. |
| 305 |
* |
| 306 |
* @static |
| 307 |
* @memberOf _ |
| 308 |
* @since 4.0.0 |
| 309 |
* @category Lang |
| 310 |
* @param {*} value The value to process. |
| 311 |
* @returns {number} Returns the number. |
| 312 |
* @example |
| 313 |
* |
| 314 |
* _.toNumber(3.2); |
| 315 |
* // => 3.2 |
| 316 |
* |
| 317 |
* _.toNumber(Number.MIN_VALUE); |
| 318 |
* // => 5e-324 |
| 319 |
* |
| 320 |
* _.toNumber(Infinity); |
| 321 |
* // => Infinity |
| 322 |
* |
| 323 |
* _.toNumber('3.2'); |
| 324 |
* // => 3.2 |
| 325 |
*/ |
| 326 |
function toNumber(value) { |
| 327 |
if (typeof value == 'number') { |
| 328 |
return value; |
| 329 |
} |
| 330 |
if (isSymbol(value)) { |
| 331 |
return NAN; |
| 332 |
} |
| 333 |
if (isObject(value)) { |
| 334 |
var other = typeof value.valueOf == 'function' ? value.valueOf() : value; |
| 335 |
value = isObject(other) ? (other + '') : other; |
| 336 |
} |
| 337 |
if (typeof value != 'string') { |
| 338 |
return value === 0 ? value : +value; |
| 339 |
} |
| 340 |
value = baseTrim(value); |
| 341 |
var isBinary = reIsBinary.test(value); |
| 342 |
return (isBinary || reIsOctal.test(value)) |
| 343 |
? freeParseInt(value.slice(2), isBinary ? 2 : 8) |
| 344 |
: (reIsBadHex.test(value) ? NAN : +value); |
| 345 |
} |
| 346 |
|
| 347 |
/** Error message constants. */ |
| 348 |
var FUNC_ERROR_TEXT$1 = 'Expected a function'; |
| 349 |
|
| 350 |
/* Built-in method references for those with the same name as other `lodash` methods. */ |
| 351 |
var nativeMax = Math.max, |
| 352 |
nativeMin = Math.min; |
| 353 |
|
| 354 |
/** |
| 355 |
* Creates a debounced function that delays invoking `func` until after `wait` |
| 356 |
* milliseconds have elapsed since the last time the debounced function was |
| 357 |
* invoked. The debounced function comes with a `cancel` method to cancel |
| 358 |
* delayed `func` invocations and a `flush` method to immediately invoke them. |
| 359 |
* Provide `options` to indicate whether `func` should be invoked on the |
| 360 |
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked |
| 361 |
* with the last arguments provided to the debounced function. Subsequent |
| 362 |
* calls to the debounced function return the result of the last `func` |
| 363 |
* invocation. |
| 364 |
* |
| 365 |
* **Note:** If `leading` and `trailing` options are `true`, `func` is |
| 366 |
* invoked on the trailing edge of the timeout only if the debounced function |
| 367 |
* is invoked more than once during the `wait` timeout. |
| 368 |
* |
| 369 |
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred |
| 370 |
* until to the next tick, similar to `setTimeout` with a timeout of `0`. |
| 371 |
* |
| 372 |
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) |
| 373 |
* for details over the differences between `_.debounce` and `_.throttle`. |
| 374 |
* |
| 375 |
* @static |
| 376 |
* @memberOf _ |
| 377 |
* @since 0.1.0 |
| 378 |
* @category Function |
| 379 |
* @param {Function} func The function to debounce. |
| 380 |
* @param {number} [wait=0] The number of milliseconds to delay. |
| 381 |
* @param {Object} [options={}] The options object. |
| 382 |
* @param {boolean} [options.leading=false] |
| 383 |
* Specify invoking on the leading edge of the timeout. |
| 384 |
* @param {number} [options.maxWait] |
| 385 |
* The maximum time `func` is allowed to be delayed before it's invoked. |
| 386 |
* @param {boolean} [options.trailing=true] |
| 387 |
* Specify invoking on the trailing edge of the timeout. |
| 388 |
* @returns {Function} Returns the new debounced function. |
| 389 |
* @example |
| 390 |
* |
| 391 |
* // Avoid costly calculations while the window size is in flux. |
| 392 |
* jQuery(window).on('resize', _.debounce(calculateLayout, 150)); |
| 393 |
* |
| 394 |
* // Invoke `sendMail` when clicked, debouncing subsequent calls. |
| 395 |
* jQuery(element).on('click', _.debounce(sendMail, 300, { |
| 396 |
* 'leading': true, |
| 397 |
* 'trailing': false |
| 398 |
* })); |
| 399 |
* |
| 400 |
* // Ensure `batchLog` is invoked once after 1 second of debounced calls. |
| 401 |
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); |
| 402 |
* var source = new EventSource('/stream'); |
| 403 |
* jQuery(source).on('message', debounced); |
| 404 |
* |
| 405 |
* // Cancel the trailing debounced invocation. |
| 406 |
* jQuery(window).on('popstate', debounced.cancel); |
| 407 |
*/ |
| 408 |
function debounce(func, wait, options) { |
| 409 |
var lastArgs, |
| 410 |
lastThis, |
| 411 |
maxWait, |
| 412 |
result, |
| 413 |
timerId, |
| 414 |
lastCallTime, |
| 415 |
lastInvokeTime = 0, |
| 416 |
leading = false, |
| 417 |
maxing = false, |
| 418 |
trailing = true; |
| 419 |
|
| 420 |
if (typeof func != 'function') { |
| 421 |
throw new TypeError(FUNC_ERROR_TEXT$1); |
| 422 |
} |
| 423 |
wait = toNumber(wait) || 0; |
| 424 |
if (isObject(options)) { |
| 425 |
leading = !!options.leading; |
| 426 |
maxing = 'maxWait' in options; |
| 427 |
maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; |
| 428 |
trailing = 'trailing' in options ? !!options.trailing : trailing; |
| 429 |
} |
| 430 |
|
| 431 |
function invokeFunc(time) { |
| 432 |
var args = lastArgs, |
| 433 |
thisArg = lastThis; |
| 434 |
|
| 435 |
lastArgs = lastThis = undefined; |
| 436 |
lastInvokeTime = time; |
| 437 |
result = func.apply(thisArg, args); |
| 438 |
return result; |
| 439 |
} |
| 440 |
|
| 441 |
function leadingEdge(time) { |
| 442 |
// Reset any `maxWait` timer. |
| 443 |
lastInvokeTime = time; |
| 444 |
// Start the timer for the trailing edge. |
| 445 |
timerId = setTimeout(timerExpired, wait); |
| 446 |
// Invoke the leading edge. |
| 447 |
return leading ? invokeFunc(time) : result; |
| 448 |
} |
| 449 |
|
| 450 |
function remainingWait(time) { |
| 451 |
var timeSinceLastCall = time - lastCallTime, |
| 452 |
timeSinceLastInvoke = time - lastInvokeTime, |
| 453 |
timeWaiting = wait - timeSinceLastCall; |
| 454 |
|
| 455 |
return maxing |
| 456 |
? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) |
| 457 |
: timeWaiting; |
| 458 |
} |
| 459 |
|
| 460 |
function shouldInvoke(time) { |
| 461 |
var timeSinceLastCall = time - lastCallTime, |
| 462 |
timeSinceLastInvoke = time - lastInvokeTime; |
| 463 |
|
| 464 |
// Either this is the first call, activity has stopped and we're at the |
| 465 |
// trailing edge, the system time has gone backwards and we're treating |
| 466 |
// it as the trailing edge, or we've hit the `maxWait` limit. |
| 467 |
return (lastCallTime === undefined || (timeSinceLastCall >= wait) || |
| 468 |
(timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); |
| 469 |
} |
| 470 |
|
| 471 |
function timerExpired() { |
| 472 |
var time = now$1(); |
| 473 |
if (shouldInvoke(time)) { |
| 474 |
return trailingEdge(time); |
| 475 |
} |
| 476 |
// Restart the timer. |
| 477 |
timerId = setTimeout(timerExpired, remainingWait(time)); |
| 478 |
} |
| 479 |
|
| 480 |
function trailingEdge(time) { |
| 481 |
timerId = undefined; |
| 482 |
|
| 483 |
// Only invoke if we have `lastArgs` which means `func` has been |
| 484 |
// debounced at least once. |
| 485 |
if (trailing && lastArgs) { |
| 486 |
return invokeFunc(time); |
| 487 |
} |
| 488 |
lastArgs = lastThis = undefined; |
| 489 |
return result; |
| 490 |
} |
| 491 |
|
| 492 |
function cancel() { |
| 493 |
if (timerId !== undefined) { |
| 494 |
clearTimeout(timerId); |
| 495 |
} |
| 496 |
lastInvokeTime = 0; |
| 497 |
lastArgs = lastCallTime = lastThis = timerId = undefined; |
| 498 |
} |
| 499 |
|
| 500 |
function flush() { |
| 501 |
return timerId === undefined ? result : trailingEdge(now$1()); |
| 502 |
} |
| 503 |
|
| 504 |
function debounced() { |
| 505 |
var time = now$1(), |
| 506 |
isInvoking = shouldInvoke(time); |
| 507 |
|
| 508 |
lastArgs = arguments; |
| 509 |
lastThis = this; |
| 510 |
lastCallTime = time; |
| 511 |
|
| 512 |
if (isInvoking) { |
| 513 |
if (timerId === undefined) { |
| 514 |
return leadingEdge(lastCallTime); |
| 515 |
} |
| 516 |
if (maxing) { |
| 517 |
// Handle invocations in a tight loop. |
| 518 |
clearTimeout(timerId); |
| 519 |
timerId = setTimeout(timerExpired, wait); |
| 520 |
return invokeFunc(lastCallTime); |
| 521 |
} |
| 522 |
} |
| 523 |
if (timerId === undefined) { |
| 524 |
timerId = setTimeout(timerExpired, wait); |
| 525 |
} |
| 526 |
return result; |
| 527 |
} |
| 528 |
debounced.cancel = cancel; |
| 529 |
debounced.flush = flush; |
| 530 |
return debounced; |
| 531 |
} |
| 532 |
|
| 533 |
/** Error message constants. */ |
| 534 |
var FUNC_ERROR_TEXT = 'Expected a function'; |
| 535 |
|
| 536 |
/** |
| 537 |
* Creates a throttled function that only invokes `func` at most once per |
| 538 |
* every `wait` milliseconds. The throttled function comes with a `cancel` |
| 539 |
* method to cancel delayed `func` invocations and a `flush` method to |
| 540 |
* immediately invoke them. Provide `options` to indicate whether `func` |
| 541 |
* should be invoked on the leading and/or trailing edge of the `wait` |
| 542 |
* timeout. The `func` is invoked with the last arguments provided to the |
| 543 |
* throttled function. Subsequent calls to the throttled function return the |
| 544 |
* result of the last `func` invocation. |
| 545 |
* |
| 546 |
* **Note:** If `leading` and `trailing` options are `true`, `func` is |
| 547 |
* invoked on the trailing edge of the timeout only if the throttled function |
| 548 |
* is invoked more than once during the `wait` timeout. |
| 549 |
* |
| 550 |
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred |
| 551 |
* until to the next tick, similar to `setTimeout` with a timeout of `0`. |
| 552 |
* |
| 553 |
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) |
| 554 |
* for details over the differences between `_.throttle` and `_.debounce`. |
| 555 |
* |
| 556 |
* @static |
| 557 |
* @memberOf _ |
| 558 |
* @since 0.1.0 |
| 559 |
* @category Function |
| 560 |
* @param {Function} func The function to throttle. |
| 561 |
* @param {number} [wait=0] The number of milliseconds to throttle invocations to. |
| 562 |
* @param {Object} [options={}] The options object. |
| 563 |
* @param {boolean} [options.leading=true] |
| 564 |
* Specify invoking on the leading edge of the timeout. |
| 565 |
* @param {boolean} [options.trailing=true] |
| 566 |
* Specify invoking on the trailing edge of the timeout. |
| 567 |
* @returns {Function} Returns the new throttled function. |
| 568 |
* @example |
| 569 |
* |
| 570 |
* // Avoid excessively updating the position while scrolling. |
| 571 |
* jQuery(window).on('scroll', _.throttle(updatePosition, 100)); |
| 572 |
* |
| 573 |
* // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. |
| 574 |
* var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); |
| 575 |
* jQuery(element).on('click', throttled); |
| 576 |
* |
| 577 |
* // Cancel the trailing throttled invocation. |
| 578 |
* jQuery(window).on('popstate', throttled.cancel); |
| 579 |
*/ |
| 580 |
function throttle(func, wait, options) { |
| 581 |
var leading = true, |
| 582 |
trailing = true; |
| 583 |
|
| 584 |
if (typeof func != 'function') { |
| 585 |
throw new TypeError(FUNC_ERROR_TEXT); |
| 586 |
} |
| 587 |
if (isObject(options)) { |
| 588 |
leading = 'leading' in options ? !!options.leading : leading; |
| 589 |
trailing = 'trailing' in options ? !!options.trailing : trailing; |
| 590 |
} |
| 591 |
return debounce(func, wait, { |
| 592 |
'leading': leading, |
| 593 |
'maxWait': wait, |
| 594 |
'trailing': trailing |
| 595 |
}); |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* simplebar-core - v1.3.1 |
| 600 |
* Scrollbars, simpler. |
| 601 |
* https://grsmto.github.io/simplebar/ |
| 602 |
* |
| 603 |
* Made by Adrien Denat from a fork by Jonathan Nicol |
| 604 |
* Under MIT License |
| 605 |
*/ |
| 606 |
|
| 607 |
/****************************************************************************** |
| 608 |
Copyright (c) Microsoft Corporation. |
| 609 |
|
| 610 |
Permission to use, copy, modify, and/or distribute this software for any |
| 611 |
purpose with or without fee is hereby granted. |
| 612 |
|
| 613 |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 614 |
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 615 |
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 616 |
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 617 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 618 |
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 619 |
PERFORMANCE OF THIS SOFTWARE. |
| 620 |
***************************************************************************** */ |
| 621 |
|
| 622 |
var __assign = function() { |
| 623 |
__assign = Object.assign || function __assign(t) { |
| 624 |
for (var s, i = 1, n = arguments.length; i < n; i++) { |
| 625 |
s = arguments[i]; |
| 626 |
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; |
| 627 |
} |
| 628 |
return t; |
| 629 |
}; |
| 630 |
return __assign.apply(this, arguments); |
| 631 |
}; |
| 632 |
|
| 633 |
function getElementWindow$1(element) { |
| 634 |
if (!element || |
| 635 |
!element.ownerDocument || |
| 636 |
!element.ownerDocument.defaultView) { |
| 637 |
return window; |
| 638 |
} |
| 639 |
return element.ownerDocument.defaultView; |
| 640 |
} |
| 641 |
function getElementDocument$1(element) { |
| 642 |
if (!element || !element.ownerDocument) { |
| 643 |
return document; |
| 644 |
} |
| 645 |
return element.ownerDocument; |
| 646 |
} |
| 647 |
// Helper function to retrieve options from element attributes |
| 648 |
var getOptions$1 = function (obj) { |
| 649 |
var initialObj = {}; |
| 650 |
var options = Array.prototype.reduce.call(obj, function (acc, attribute) { |
| 651 |
var option = attribute.name.match(/data-simplebar-(.+)/); |
| 652 |
if (option) { |
| 653 |
var key = option[1].replace(/\W+(.)/g, function (_, chr) { return chr.toUpperCase(); }); |
| 654 |
switch (attribute.value) { |
| 655 |
case 'true': |
| 656 |
acc[key] = true; |
| 657 |
break; |
| 658 |
case 'false': |
| 659 |
acc[key] = false; |
| 660 |
break; |
| 661 |
case undefined: |
| 662 |
acc[key] = true; |
| 663 |
break; |
| 664 |
default: |
| 665 |
acc[key] = attribute.value; |
| 666 |
} |
| 667 |
} |
| 668 |
return acc; |
| 669 |
}, initialObj); |
| 670 |
return options; |
| 671 |
}; |
| 672 |
function addClasses$1(el, classes) { |
| 673 |
var _a; |
| 674 |
if (!el) |
| 675 |
return; |
| 676 |
(_a = el.classList).add.apply(_a, classes.split(' ')); |
| 677 |
} |
| 678 |
function removeClasses$1(el, classes) { |
| 679 |
if (!el) |
| 680 |
return; |
| 681 |
classes.split(' ').forEach(function (className) { |
| 682 |
el.classList.remove(className); |
| 683 |
}); |
| 684 |
} |
| 685 |
function classNamesToQuery$1(classNames) { |
| 686 |
return ".".concat(classNames.split(' ').join('.')); |
| 687 |
} |
| 688 |
var canUseDOM$1 = !!(typeof window !== 'undefined' && |
| 689 |
window.document && |
| 690 |
window.document.createElement); |
| 691 |
|
| 692 |
var helpers = /*#__PURE__*/Object.freeze({ |
| 693 |
__proto__: null, |
| 694 |
addClasses: addClasses$1, |
| 695 |
canUseDOM: canUseDOM$1, |
| 696 |
classNamesToQuery: classNamesToQuery$1, |
| 697 |
getElementDocument: getElementDocument$1, |
| 698 |
getElementWindow: getElementWindow$1, |
| 699 |
getOptions: getOptions$1, |
| 700 |
removeClasses: removeClasses$1 |
| 701 |
}); |
| 702 |
|
| 703 |
var cachedScrollbarWidth = null; |
| 704 |
var cachedDevicePixelRatio = null; |
| 705 |
if (canUseDOM$1) { |
| 706 |
window.addEventListener('resize', function () { |
| 707 |
if (cachedDevicePixelRatio !== window.devicePixelRatio) { |
| 708 |
cachedDevicePixelRatio = window.devicePixelRatio; |
| 709 |
cachedScrollbarWidth = null; |
| 710 |
} |
| 711 |
}); |
| 712 |
} |
| 713 |
function scrollbarWidth() { |
| 714 |
if (cachedScrollbarWidth === null) { |
| 715 |
if (typeof document === 'undefined') { |
| 716 |
cachedScrollbarWidth = 0; |
| 717 |
return cachedScrollbarWidth; |
| 718 |
} |
| 719 |
var body = document.body; |
| 720 |
var box = document.createElement('div'); |
| 721 |
box.classList.add('simplebar-hide-scrollbar'); |
| 722 |
body.appendChild(box); |
| 723 |
var width = box.getBoundingClientRect().right; |
| 724 |
body.removeChild(box); |
| 725 |
cachedScrollbarWidth = width; |
| 726 |
} |
| 727 |
return cachedScrollbarWidth; |
| 728 |
} |
| 729 |
|
| 730 |
var getElementWindow = getElementWindow$1, getElementDocument = getElementDocument$1, getOptions$2 = getOptions$1, addClasses$2 = addClasses$1, removeClasses = removeClasses$1, classNamesToQuery = classNamesToQuery$1; |
| 731 |
var SimpleBarCore = /** @class */ (function () { |
| 732 |
function SimpleBarCore(element, options) { |
| 733 |
if (options === void 0) { options = {}; } |
| 734 |
var _this = this; |
| 735 |
this.removePreventClickId = null; |
| 736 |
this.minScrollbarWidth = 20; |
| 737 |
this.stopScrollDelay = 175; |
| 738 |
this.isScrolling = false; |
| 739 |
this.isMouseEntering = false; |
| 740 |
this.isDragging = false; |
| 741 |
this.scrollXTicking = false; |
| 742 |
this.scrollYTicking = false; |
| 743 |
this.wrapperEl = null; |
| 744 |
this.contentWrapperEl = null; |
| 745 |
this.contentEl = null; |
| 746 |
this.offsetEl = null; |
| 747 |
this.maskEl = null; |
| 748 |
this.placeholderEl = null; |
| 749 |
this.heightAutoObserverWrapperEl = null; |
| 750 |
this.heightAutoObserverEl = null; |
| 751 |
this.rtlHelpers = null; |
| 752 |
this.scrollbarWidth = 0; |
| 753 |
this.resizeObserver = null; |
| 754 |
this.mutationObserver = null; |
| 755 |
this.elStyles = null; |
| 756 |
this.isRtl = null; |
| 757 |
this.mouseX = 0; |
| 758 |
this.mouseY = 0; |
| 759 |
this.onMouseMove = function () { }; |
| 760 |
this.onWindowResize = function () { }; |
| 761 |
this.onStopScrolling = function () { }; |
| 762 |
this.onMouseEntered = function () { }; |
| 763 |
/** |
| 764 |
* On scroll event handling |
| 765 |
*/ |
| 766 |
this.onScroll = function () { |
| 767 |
var elWindow = getElementWindow(_this.el); |
| 768 |
if (!_this.scrollXTicking) { |
| 769 |
elWindow.requestAnimationFrame(_this.scrollX); |
| 770 |
_this.scrollXTicking = true; |
| 771 |
} |
| 772 |
if (!_this.scrollYTicking) { |
| 773 |
elWindow.requestAnimationFrame(_this.scrollY); |
| 774 |
_this.scrollYTicking = true; |
| 775 |
} |
| 776 |
if (!_this.isScrolling) { |
| 777 |
_this.isScrolling = true; |
| 778 |
addClasses$2(_this.el, _this.classNames.scrolling); |
| 779 |
} |
| 780 |
_this.showScrollbar('x'); |
| 781 |
_this.showScrollbar('y'); |
| 782 |
_this.onStopScrolling(); |
| 783 |
}; |
| 784 |
this.scrollX = function () { |
| 785 |
if (_this.axis.x.isOverflowing) { |
| 786 |
_this.positionScrollbar('x'); |
| 787 |
} |
| 788 |
_this.scrollXTicking = false; |
| 789 |
}; |
| 790 |
this.scrollY = function () { |
| 791 |
if (_this.axis.y.isOverflowing) { |
| 792 |
_this.positionScrollbar('y'); |
| 793 |
} |
| 794 |
_this.scrollYTicking = false; |
| 795 |
}; |
| 796 |
this._onStopScrolling = function () { |
| 797 |
removeClasses(_this.el, _this.classNames.scrolling); |
| 798 |
if (_this.options.autoHide) { |
| 799 |
_this.hideScrollbar('x'); |
| 800 |
_this.hideScrollbar('y'); |
| 801 |
} |
| 802 |
_this.isScrolling = false; |
| 803 |
}; |
| 804 |
this.onMouseEnter = function () { |
| 805 |
if (!_this.isMouseEntering) { |
| 806 |
addClasses$2(_this.el, _this.classNames.mouseEntered); |
| 807 |
_this.showScrollbar('x'); |
| 808 |
_this.showScrollbar('y'); |
| 809 |
_this.isMouseEntering = true; |
| 810 |
} |
| 811 |
_this.onMouseEntered(); |
| 812 |
}; |
| 813 |
this._onMouseEntered = function () { |
| 814 |
removeClasses(_this.el, _this.classNames.mouseEntered); |
| 815 |
if (_this.options.autoHide) { |
| 816 |
_this.hideScrollbar('x'); |
| 817 |
_this.hideScrollbar('y'); |
| 818 |
} |
| 819 |
_this.isMouseEntering = false; |
| 820 |
}; |
| 821 |
this._onMouseMove = function (e) { |
| 822 |
_this.mouseX = e.clientX; |
| 823 |
_this.mouseY = e.clientY; |
| 824 |
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) { |
| 825 |
_this.onMouseMoveForAxis('x'); |
| 826 |
} |
| 827 |
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) { |
| 828 |
_this.onMouseMoveForAxis('y'); |
| 829 |
} |
| 830 |
}; |
| 831 |
this.onMouseLeave = function () { |
| 832 |
_this.onMouseMove.cancel(); |
| 833 |
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) { |
| 834 |
_this.onMouseLeaveForAxis('x'); |
| 835 |
} |
| 836 |
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) { |
| 837 |
_this.onMouseLeaveForAxis('y'); |
| 838 |
} |
| 839 |
_this.mouseX = -1; |
| 840 |
_this.mouseY = -1; |
| 841 |
}; |
| 842 |
this._onWindowResize = function () { |
| 843 |
// Recalculate scrollbarWidth in case it's a zoom |
| 844 |
_this.scrollbarWidth = _this.getScrollbarWidth(); |
| 845 |
_this.hideNativeScrollbar(); |
| 846 |
}; |
| 847 |
this.onPointerEvent = function (e) { |
| 848 |
if (!_this.axis.x.track.el || |
| 849 |
!_this.axis.y.track.el || |
| 850 |
!_this.axis.x.scrollbar.el || |
| 851 |
!_this.axis.y.scrollbar.el) |
| 852 |
return; |
| 853 |
var isWithinTrackXBounds, isWithinTrackYBounds; |
| 854 |
_this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect(); |
| 855 |
_this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect(); |
| 856 |
if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) { |
| 857 |
isWithinTrackXBounds = _this.isWithinBounds(_this.axis.x.track.rect); |
| 858 |
} |
| 859 |
if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) { |
| 860 |
isWithinTrackYBounds = _this.isWithinBounds(_this.axis.y.track.rect); |
| 861 |
} |
| 862 |
// If any pointer event is called on the scrollbar |
| 863 |
if (isWithinTrackXBounds || isWithinTrackYBounds) { |
| 864 |
// Prevent event leaking |
| 865 |
e.stopPropagation(); |
| 866 |
if (e.type === 'pointerdown' && e.pointerType !== 'touch') { |
| 867 |
if (isWithinTrackXBounds) { |
| 868 |
_this.axis.x.scrollbar.rect = |
| 869 |
_this.axis.x.scrollbar.el.getBoundingClientRect(); |
| 870 |
if (_this.isWithinBounds(_this.axis.x.scrollbar.rect)) { |
| 871 |
_this.onDragStart(e, 'x'); |
| 872 |
} |
| 873 |
else { |
| 874 |
_this.onTrackClick(e, 'x'); |
| 875 |
} |
| 876 |
} |
| 877 |
if (isWithinTrackYBounds) { |
| 878 |
_this.axis.y.scrollbar.rect = |
| 879 |
_this.axis.y.scrollbar.el.getBoundingClientRect(); |
| 880 |
if (_this.isWithinBounds(_this.axis.y.scrollbar.rect)) { |
| 881 |
_this.onDragStart(e, 'y'); |
| 882 |
} |
| 883 |
else { |
| 884 |
_this.onTrackClick(e, 'y'); |
| 885 |
} |
| 886 |
} |
| 887 |
} |
| 888 |
} |
| 889 |
}; |
| 890 |
/** |
| 891 |
* Drag scrollbar handle |
| 892 |
*/ |
| 893 |
this.drag = function (e) { |
| 894 |
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; |
| 895 |
if (!_this.draggedAxis || !_this.contentWrapperEl) |
| 896 |
return; |
| 897 |
var eventOffset; |
| 898 |
var track = _this.axis[_this.draggedAxis].track; |
| 899 |
var trackSize = (_b = (_a = track.rect) === null || _a === void 0 ? void 0 : _a[_this.axis[_this.draggedAxis].sizeAttr]) !== null && _b !== void 0 ? _b : 0; |
| 900 |
var scrollbar = _this.axis[_this.draggedAxis].scrollbar; |
| 901 |
var contentSize = (_d = (_c = _this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c[_this.axis[_this.draggedAxis].scrollSizeAttr]) !== null && _d !== void 0 ? _d : 0; |
| 902 |
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); |
| 903 |
e.preventDefault(); |
| 904 |
e.stopPropagation(); |
| 905 |
if (_this.draggedAxis === 'y') { |
| 906 |
eventOffset = e.pageY; |
| 907 |
} |
| 908 |
else { |
| 909 |
eventOffset = e.pageX; |
| 910 |
} |
| 911 |
// Calculate how far the user's mouse is from the top/left of the scrollbar (minus the dragOffset). |
| 912 |
var dragPos = eventOffset - |
| 913 |
((_h = (_g = track.rect) === null || _g === void 0 ? void 0 : _g[_this.axis[_this.draggedAxis].offsetAttr]) !== null && _h !== void 0 ? _h : 0) - |
| 914 |
_this.axis[_this.draggedAxis].dragOffset; |
| 915 |
dragPos = |
| 916 |
_this.draggedAxis === 'x' && _this.isRtl |
| 917 |
? ((_k = (_j = track.rect) === null || _j === void 0 ? void 0 : _j[_this.axis[_this.draggedAxis].sizeAttr]) !== null && _k !== void 0 ? _k : 0) - |
| 918 |
scrollbar.size - |
| 919 |
dragPos |
| 920 |
: dragPos; |
| 921 |
// Convert the mouse position into a percentage of the scrollbar height/width. |
| 922 |
var dragPerc = dragPos / (trackSize - scrollbar.size); |
| 923 |
// Scroll the content by the same percentage. |
| 924 |
var scrollPos = dragPerc * (contentSize - hostSize); |
| 925 |
// Fix browsers inconsistency on RTL |
| 926 |
if (_this.draggedAxis === 'x' && _this.isRtl) { |
| 927 |
scrollPos = ((_l = SimpleBarCore.getRtlHelpers()) === null || _l === void 0 ? void 0 : _l.isScrollingToNegative) |
| 928 |
? -scrollPos |
| 929 |
: scrollPos; |
| 930 |
} |
| 931 |
_this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollOffsetAttr] = |
| 932 |
scrollPos; |
| 933 |
}; |
| 934 |
/** |
| 935 |
* End scroll handle drag |
| 936 |
*/ |
| 937 |
this.onEndDrag = function (e) { |
| 938 |
_this.isDragging = false; |
| 939 |
var elDocument = getElementDocument(_this.el); |
| 940 |
var elWindow = getElementWindow(_this.el); |
| 941 |
e.preventDefault(); |
| 942 |
e.stopPropagation(); |
| 943 |
removeClasses(_this.el, _this.classNames.dragging); |
| 944 |
_this.onStopScrolling(); |
| 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$1) { |
| 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.isDragging) |
| 1299 |
return; |
| 1300 |
if (this.axis[axis].isOverflowing && this.axis[axis].scrollbar.isVisible) { |
| 1301 |
removeClasses(this.axis[axis].scrollbar.el, this.classNames.visible); |
| 1302 |
this.axis[axis].scrollbar.isVisible = false; |
| 1303 |
} |
| 1304 |
}; |
| 1305 |
SimpleBarCore.prototype.hideNativeScrollbar = function () { |
| 1306 |
if (!this.offsetEl) |
| 1307 |
return; |
| 1308 |
this.offsetEl.style[this.isRtl ? 'left' : 'right'] = |
| 1309 |
this.axis.y.isOverflowing || this.axis.y.forceVisible |
| 1310 |
? "-".concat(this.scrollbarWidth, "px") |
| 1311 |
: '0px'; |
| 1312 |
this.offsetEl.style.bottom = |
| 1313 |
this.axis.x.isOverflowing || this.axis.x.forceVisible |
| 1314 |
? "-".concat(this.scrollbarWidth, "px") |
| 1315 |
: '0px'; |
| 1316 |
}; |
| 1317 |
SimpleBarCore.prototype.onMouseMoveForAxis = function (axis) { |
| 1318 |
if (axis === void 0) { axis = 'y'; } |
| 1319 |
var currentAxis = this.axis[axis]; |
| 1320 |
if (!currentAxis.track.el || !currentAxis.scrollbar.el) |
| 1321 |
return; |
| 1322 |
currentAxis.track.rect = currentAxis.track.el.getBoundingClientRect(); |
| 1323 |
currentAxis.scrollbar.rect = |
| 1324 |
currentAxis.scrollbar.el.getBoundingClientRect(); |
| 1325 |
if (this.isWithinBounds(currentAxis.track.rect)) { |
| 1326 |
this.showScrollbar(axis); |
| 1327 |
addClasses$2(currentAxis.track.el, this.classNames.hover); |
| 1328 |
if (this.isWithinBounds(currentAxis.scrollbar.rect)) { |
| 1329 |
addClasses$2(currentAxis.scrollbar.el, this.classNames.hover); |
| 1330 |
} |
| 1331 |
else { |
| 1332 |
removeClasses(currentAxis.scrollbar.el, this.classNames.hover); |
| 1333 |
} |
| 1334 |
} |
| 1335 |
else { |
| 1336 |
removeClasses(currentAxis.track.el, this.classNames.hover); |
| 1337 |
if (this.options.autoHide) { |
| 1338 |
this.hideScrollbar(axis); |
| 1339 |
} |
| 1340 |
} |
| 1341 |
}; |
| 1342 |
SimpleBarCore.prototype.onMouseLeaveForAxis = function (axis) { |
| 1343 |
if (axis === void 0) { axis = 'y'; } |
| 1344 |
removeClasses(this.axis[axis].track.el, this.classNames.hover); |
| 1345 |
removeClasses(this.axis[axis].scrollbar.el, this.classNames.hover); |
| 1346 |
if (this.options.autoHide) { |
| 1347 |
this.hideScrollbar(axis); |
| 1348 |
} |
| 1349 |
}; |
| 1350 |
/** |
| 1351 |
* on scrollbar handle drag movement starts |
| 1352 |
*/ |
| 1353 |
SimpleBarCore.prototype.onDragStart = function (e, axis) { |
| 1354 |
var _a; |
| 1355 |
if (axis === void 0) { axis = 'y'; } |
| 1356 |
this.isDragging = true; |
| 1357 |
var elDocument = getElementDocument(this.el); |
| 1358 |
var elWindow = getElementWindow(this.el); |
| 1359 |
var scrollbar = this.axis[axis].scrollbar; |
| 1360 |
// Measure how far the user's mouse is from the top of the scrollbar drag handle. |
| 1361 |
var eventOffset = axis === 'y' ? e.pageY : e.pageX; |
| 1362 |
this.axis[axis].dragOffset = |
| 1363 |
eventOffset - (((_a = scrollbar.rect) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetAttr]) || 0); |
| 1364 |
this.draggedAxis = axis; |
| 1365 |
addClasses$2(this.el, this.classNames.dragging); |
| 1366 |
elDocument.addEventListener('mousemove', this.drag, true); |
| 1367 |
elDocument.addEventListener('mouseup', this.onEndDrag, true); |
| 1368 |
if (this.removePreventClickId === null) { |
| 1369 |
elDocument.addEventListener('click', this.preventClick, true); |
| 1370 |
elDocument.addEventListener('dblclick', this.preventClick, true); |
| 1371 |
} |
| 1372 |
else { |
| 1373 |
elWindow.clearTimeout(this.removePreventClickId); |
| 1374 |
this.removePreventClickId = null; |
| 1375 |
} |
| 1376 |
}; |
| 1377 |
SimpleBarCore.prototype.onTrackClick = function (e, axis) { |
| 1378 |
var _this = this; |
| 1379 |
var _a, _b, _c, _d; |
| 1380 |
if (axis === void 0) { axis = 'y'; } |
| 1381 |
var currentAxis = this.axis[axis]; |
| 1382 |
if (!this.options.clickOnTrack || |
| 1383 |
!currentAxis.scrollbar.el || |
| 1384 |
!this.contentWrapperEl) |
| 1385 |
return; |
| 1386 |
// Preventing the event's default to trigger click underneath |
| 1387 |
e.preventDefault(); |
| 1388 |
var elWindow = getElementWindow(this.el); |
| 1389 |
this.axis[axis].scrollbar.rect = |
| 1390 |
currentAxis.scrollbar.el.getBoundingClientRect(); |
| 1391 |
var scrollbar = this.axis[axis].scrollbar; |
| 1392 |
var scrollbarOffset = (_b = (_a = scrollbar.rect) === null || _a === void 0 ? void 0 : _a[this.axis[axis].offsetAttr]) !== null && _b !== void 0 ? _b : 0; |
| 1393 |
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); |
| 1394 |
var scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr]; |
| 1395 |
var t = axis === 'y' |
| 1396 |
? this.mouseY - scrollbarOffset |
| 1397 |
: this.mouseX - scrollbarOffset; |
| 1398 |
var dir = t < 0 ? -1 : 1; |
| 1399 |
var scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize; |
| 1400 |
var speed = 40; |
| 1401 |
var scrollTo = function () { |
| 1402 |
if (!_this.contentWrapperEl) |
| 1403 |
return; |
| 1404 |
if (dir === -1) { |
| 1405 |
if (scrolled > scrollSize) { |
| 1406 |
scrolled -= speed; |
| 1407 |
_this.contentWrapperEl[_this.axis[axis].scrollOffsetAttr] = scrolled; |
| 1408 |
elWindow.requestAnimationFrame(scrollTo); |
| 1409 |
} |
| 1410 |
} |
| 1411 |
else { |
| 1412 |
if (scrolled < scrollSize) { |
| 1413 |
scrolled += speed; |
| 1414 |
_this.contentWrapperEl[_this.axis[axis].scrollOffsetAttr] = scrolled; |
| 1415 |
elWindow.requestAnimationFrame(scrollTo); |
| 1416 |
} |
| 1417 |
} |
| 1418 |
}; |
| 1419 |
scrollTo(); |
| 1420 |
}; |
| 1421 |
/** |
| 1422 |
* Getter for content element |
| 1423 |
*/ |
| 1424 |
SimpleBarCore.prototype.getContentElement = function () { |
| 1425 |
return this.contentEl; |
| 1426 |
}; |
| 1427 |
/** |
| 1428 |
* Getter for original scrolling element |
| 1429 |
*/ |
| 1430 |
SimpleBarCore.prototype.getScrollElement = function () { |
| 1431 |
return this.contentWrapperEl; |
| 1432 |
}; |
| 1433 |
SimpleBarCore.prototype.removeListeners = function () { |
| 1434 |
var elWindow = getElementWindow(this.el); |
| 1435 |
// Event listeners |
| 1436 |
this.el.removeEventListener('mouseenter', this.onMouseEnter); |
| 1437 |
this.el.removeEventListener('pointerdown', this.onPointerEvent, true); |
| 1438 |
this.el.removeEventListener('mousemove', this.onMouseMove); |
| 1439 |
this.el.removeEventListener('mouseleave', this.onMouseLeave); |
| 1440 |
if (this.contentWrapperEl) { |
| 1441 |
this.contentWrapperEl.removeEventListener('scroll', this.onScroll); |
| 1442 |
} |
| 1443 |
elWindow.removeEventListener('resize', this.onWindowResize); |
| 1444 |
if (this.mutationObserver) { |
| 1445 |
this.mutationObserver.disconnect(); |
| 1446 |
} |
| 1447 |
if (this.resizeObserver) { |
| 1448 |
this.resizeObserver.disconnect(); |
| 1449 |
} |
| 1450 |
// Cancel all debounced functions |
| 1451 |
this.onMouseMove.cancel(); |
| 1452 |
this.onWindowResize.cancel(); |
| 1453 |
this.onStopScrolling.cancel(); |
| 1454 |
this.onMouseEntered.cancel(); |
| 1455 |
}; |
| 1456 |
/** |
| 1457 |
* Remove all listeners from DOM nodes |
| 1458 |
*/ |
| 1459 |
SimpleBarCore.prototype.unMount = function () { |
| 1460 |
this.removeListeners(); |
| 1461 |
}; |
| 1462 |
/** |
| 1463 |
* Check if mouse is within bounds |
| 1464 |
*/ |
| 1465 |
SimpleBarCore.prototype.isWithinBounds = function (bbox) { |
| 1466 |
return (this.mouseX >= bbox.left && |
| 1467 |
this.mouseX <= bbox.left + bbox.width && |
| 1468 |
this.mouseY >= bbox.top && |
| 1469 |
this.mouseY <= bbox.top + bbox.height); |
| 1470 |
}; |
| 1471 |
/** |
| 1472 |
* Find element children matches query |
| 1473 |
*/ |
| 1474 |
SimpleBarCore.prototype.findChild = function (el, query) { |
| 1475 |
var matches = el.matches || |
| 1476 |
el.webkitMatchesSelector || |
| 1477 |
el.mozMatchesSelector || |
| 1478 |
el.msMatchesSelector; |
| 1479 |
return Array.prototype.filter.call(el.children, function (child) { |
| 1480 |
return matches.call(child, query); |
| 1481 |
})[0]; |
| 1482 |
}; |
| 1483 |
SimpleBarCore.rtlHelpers = null; |
| 1484 |
SimpleBarCore.defaultOptions = { |
| 1485 |
forceVisible: false, |
| 1486 |
clickOnTrack: true, |
| 1487 |
scrollbarMinSize: 25, |
| 1488 |
scrollbarMaxSize: 0, |
| 1489 |
ariaLabel: 'scrollable content', |
| 1490 |
tabIndex: 0, |
| 1491 |
classNames: { |
| 1492 |
contentEl: 'simplebar-content', |
| 1493 |
contentWrapper: 'simplebar-content-wrapper', |
| 1494 |
offset: 'simplebar-offset', |
| 1495 |
mask: 'simplebar-mask', |
| 1496 |
wrapper: 'simplebar-wrapper', |
| 1497 |
placeholder: 'simplebar-placeholder', |
| 1498 |
scrollbar: 'simplebar-scrollbar', |
| 1499 |
track: 'simplebar-track', |
| 1500 |
heightAutoObserverWrapperEl: 'simplebar-height-auto-observer-wrapper', |
| 1501 |
heightAutoObserverEl: 'simplebar-height-auto-observer', |
| 1502 |
visible: 'simplebar-visible', |
| 1503 |
horizontal: 'simplebar-horizontal', |
| 1504 |
vertical: 'simplebar-vertical', |
| 1505 |
hover: 'simplebar-hover', |
| 1506 |
dragging: 'simplebar-dragging', |
| 1507 |
scrolling: 'simplebar-scrolling', |
| 1508 |
scrollable: 'simplebar-scrollable', |
| 1509 |
mouseEntered: 'simplebar-mouse-entered' |
| 1510 |
}, |
| 1511 |
scrollableNode: null, |
| 1512 |
contentNode: null, |
| 1513 |
autoHide: true |
| 1514 |
}; |
| 1515 |
/** |
| 1516 |
* Static functions |
| 1517 |
*/ |
| 1518 |
SimpleBarCore.getOptions = getOptions$2; |
| 1519 |
SimpleBarCore.helpers = helpers; |
| 1520 |
return SimpleBarCore; |
| 1521 |
}()); |
| 1522 |
|
| 1523 |
var _a = SimpleBarCore.helpers, getOptions = _a.getOptions, addClasses = _a.addClasses, canUseDOM = _a.canUseDOM; |
| 1524 |
var SimpleBar = /** @class */ (function (_super) { |
| 1525 |
__extends(SimpleBar, _super); |
| 1526 |
function SimpleBar() { |
| 1527 |
var args = []; |
| 1528 |
for (var _i = 0; _i < arguments.length; _i++) { |
| 1529 |
args[_i] = arguments[_i]; |
| 1530 |
} |
| 1531 |
var _this = _super.apply(this, args) || this; |
| 1532 |
// // Save a reference to the instance, so we know this DOM node has already been instancied |
| 1533 |
SimpleBar.instances.set(args[0], _this); |
| 1534 |
return _this; |
| 1535 |
} |
| 1536 |
SimpleBar.initDOMLoadedElements = function () { |
| 1537 |
document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements); |
| 1538 |
window.removeEventListener('load', this.initDOMLoadedElements); |
| 1539 |
Array.prototype.forEach.call(document.querySelectorAll('[data-simplebar]'), function (el) { |
| 1540 |
if (el.getAttribute('data-simplebar') !== 'init' && |
| 1541 |
!SimpleBar.instances.has(el)) |
| 1542 |
new SimpleBar(el, getOptions(el.attributes)); |
| 1543 |
}); |
| 1544 |
}; |
| 1545 |
SimpleBar.removeObserver = function () { |
| 1546 |
var _a; |
| 1547 |
(_a = SimpleBar.globalObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); |
| 1548 |
}; |
| 1549 |
SimpleBar.prototype.initDOM = function () { |
| 1550 |
var _this = this; |
| 1551 |
var _a, _b, _c; |
| 1552 |
// make sure this element doesn't have the elements yet |
| 1553 |
if (!Array.prototype.filter.call(this.el.children, function (child) { |
| 1554 |
return child.classList.contains(_this.classNames.wrapper); |
| 1555 |
}).length) { |
| 1556 |
// Prepare DOM |
| 1557 |
this.wrapperEl = document.createElement('div'); |
| 1558 |
this.contentWrapperEl = document.createElement('div'); |
| 1559 |
this.offsetEl = document.createElement('div'); |
| 1560 |
this.maskEl = document.createElement('div'); |
| 1561 |
this.contentEl = document.createElement('div'); |
| 1562 |
this.placeholderEl = document.createElement('div'); |
| 1563 |
this.heightAutoObserverWrapperEl = document.createElement('div'); |
| 1564 |
this.heightAutoObserverEl = document.createElement('div'); |
| 1565 |
addClasses(this.wrapperEl, this.classNames.wrapper); |
| 1566 |
addClasses(this.contentWrapperEl, this.classNames.contentWrapper); |
| 1567 |
addClasses(this.offsetEl, this.classNames.offset); |
| 1568 |
addClasses(this.maskEl, this.classNames.mask); |
| 1569 |
addClasses(this.contentEl, this.classNames.contentEl); |
| 1570 |
addClasses(this.placeholderEl, this.classNames.placeholder); |
| 1571 |
addClasses(this.heightAutoObserverWrapperEl, this.classNames.heightAutoObserverWrapperEl); |
| 1572 |
addClasses(this.heightAutoObserverEl, this.classNames.heightAutoObserverEl); |
| 1573 |
while (this.el.firstChild) { |
| 1574 |
this.contentEl.appendChild(this.el.firstChild); |
| 1575 |
} |
| 1576 |
this.contentWrapperEl.appendChild(this.contentEl); |
| 1577 |
this.offsetEl.appendChild(this.contentWrapperEl); |
| 1578 |
this.maskEl.appendChild(this.offsetEl); |
| 1579 |
this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl); |
| 1580 |
this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl); |
| 1581 |
this.wrapperEl.appendChild(this.maskEl); |
| 1582 |
this.wrapperEl.appendChild(this.placeholderEl); |
| 1583 |
this.el.appendChild(this.wrapperEl); |
| 1584 |
(_a = this.contentWrapperEl) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', this.options.tabIndex.toString()); |
| 1585 |
(_b = this.contentWrapperEl) === null || _b === void 0 ? void 0 : _b.setAttribute('role', 'region'); |
| 1586 |
(_c = this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-label', this.options.ariaLabel); |
| 1587 |
} |
| 1588 |
if (!this.axis.x.track.el || !this.axis.y.track.el) { |
| 1589 |
var track = document.createElement('div'); |
| 1590 |
var scrollbar = document.createElement('div'); |
| 1591 |
addClasses(track, this.classNames.track); |
| 1592 |
addClasses(scrollbar, this.classNames.scrollbar); |
| 1593 |
track.appendChild(scrollbar); |
| 1594 |
this.axis.x.track.el = track.cloneNode(true); |
| 1595 |
addClasses(this.axis.x.track.el, this.classNames.horizontal); |
| 1596 |
this.axis.y.track.el = track.cloneNode(true); |
| 1597 |
addClasses(this.axis.y.track.el, this.classNames.vertical); |
| 1598 |
this.el.appendChild(this.axis.x.track.el); |
| 1599 |
this.el.appendChild(this.axis.y.track.el); |
| 1600 |
} |
| 1601 |
SimpleBarCore.prototype.initDOM.call(this); |
| 1602 |
this.el.setAttribute('data-simplebar', 'init'); |
| 1603 |
}; |
| 1604 |
SimpleBar.prototype.unMount = function () { |
| 1605 |
SimpleBarCore.prototype.unMount.call(this); |
| 1606 |
SimpleBar.instances["delete"](this.el); |
| 1607 |
}; |
| 1608 |
SimpleBar.initHtmlApi = function () { |
| 1609 |
this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this); |
| 1610 |
// MutationObserver is IE11+ |
| 1611 |
if (typeof MutationObserver !== 'undefined') { |
| 1612 |
// Mutation observer to observe dynamically added elements |
| 1613 |
this.globalObserver = new MutationObserver(SimpleBar.handleMutations); |
| 1614 |
this.globalObserver.observe(document, { childList: true, subtree: true }); |
| 1615 |
} |
| 1616 |
// Taken from jQuery `ready` function |
| 1617 |
// Instantiate elements already present on the page |
| 1618 |
if (document.readyState === 'complete' || // @ts-ignore: IE specific |
| 1619 |
(document.readyState !== 'loading' && !document.documentElement.doScroll)) { |
| 1620 |
// Handle it asynchronously to allow scripts the opportunity to delay init |
| 1621 |
window.setTimeout(this.initDOMLoadedElements); |
| 1622 |
} |
| 1623 |
else { |
| 1624 |
document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements); |
| 1625 |
window.addEventListener('load', this.initDOMLoadedElements); |
| 1626 |
} |
| 1627 |
}; |
| 1628 |
SimpleBar.handleMutations = function (mutations) { |
| 1629 |
mutations.forEach(function (mutation) { |
| 1630 |
mutation.addedNodes.forEach(function (addedNode) { |
| 1631 |
if (addedNode.nodeType === 1) { |
| 1632 |
if (addedNode.hasAttribute('data-simplebar')) { |
| 1633 |
!SimpleBar.instances.has(addedNode) && |
| 1634 |
document.documentElement.contains(addedNode) && |
| 1635 |
new SimpleBar(addedNode, getOptions(addedNode.attributes)); |
| 1636 |
} |
| 1637 |
else { |
| 1638 |
addedNode |
| 1639 |
.querySelectorAll('[data-simplebar]') |
| 1640 |
.forEach(function (el) { |
| 1641 |
if (el.getAttribute('data-simplebar') !== 'init' && |
| 1642 |
!SimpleBar.instances.has(el) && |
| 1643 |
document.documentElement.contains(el)) |
| 1644 |
new SimpleBar(el, getOptions(el.attributes)); |
| 1645 |
}); |
| 1646 |
} |
| 1647 |
} |
| 1648 |
}); |
| 1649 |
mutation.removedNodes.forEach(function (removedNode) { |
| 1650 |
var _a; |
| 1651 |
if (removedNode.nodeType === 1) { |
| 1652 |
if (removedNode.getAttribute('data-simplebar') === 'init') { |
| 1653 |
!document.documentElement.contains(removedNode) && |
| 1654 |
((_a = SimpleBar.instances.get(removedNode)) === null || _a === void 0 ? void 0 : _a.unMount()); |
| 1655 |
} |
| 1656 |
else { |
| 1657 |
Array.prototype.forEach.call(removedNode.querySelectorAll('[data-simplebar="init"]'), function (el) { |
| 1658 |
var _a; |
| 1659 |
!document.documentElement.contains(el) && |
| 1660 |
((_a = SimpleBar.instances.get(el)) === null || _a === void 0 ? void 0 : _a.unMount()); |
| 1661 |
}); |
| 1662 |
} |
| 1663 |
} |
| 1664 |
}); |
| 1665 |
}); |
| 1666 |
}; |
| 1667 |
SimpleBar.instances = new WeakMap(); |
| 1668 |
return SimpleBar; |
| 1669 |
}(SimpleBarCore)); |
| 1670 |
/** |
| 1671 |
* HTML API |
| 1672 |
* Called only in a browser env. |
| 1673 |
*/ |
| 1674 |
if (canUseDOM) { |
| 1675 |
SimpleBar.initHtmlApi(); |
| 1676 |
} |
| 1677 |
|
| 1678 |
return SimpleBar; |
| 1679 |
|
| 1680 |
})(); |
| 1681 |
|