| 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 |
import SimpleBarCore from 'simplebar-core'; |
| 11 |
|
| 12 |
/****************************************************************************** |
| 13 |
Copyright (c) Microsoft Corporation. |
| 14 |
|
| 15 |
Permission to use, copy, modify, and/or distribute this software for any |
| 16 |
purpose with or without fee is hereby granted. |
| 17 |
|
| 18 |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH |
| 19 |
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY |
| 20 |
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, |
| 21 |
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
| 22 |
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
| 23 |
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 24 |
PERFORMANCE OF THIS SOFTWARE. |
| 25 |
***************************************************************************** */ |
| 26 |
/* global Reflect, Promise */ |
| 27 |
|
| 28 |
var extendStatics = function(d, b) { |
| 29 |
extendStatics = Object.setPrototypeOf || |
| 30 |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
| 31 |
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
| 32 |
return extendStatics(d, b); |
| 33 |
}; |
| 34 |
|
| 35 |
function __extends(d, b) { |
| 36 |
if (typeof b !== "function" && b !== null) |
| 37 |
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); |
| 38 |
extendStatics(d, b); |
| 39 |
function __() { this.constructor = d; } |
| 40 |
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); |
| 41 |
} |
| 42 |
|
| 43 |
var _a = SimpleBarCore.helpers, getOptions = _a.getOptions, addClasses = _a.addClasses, canUseDOM = _a.canUseDOM; |
| 44 |
var SimpleBar = /** @class */ (function (_super) { |
| 45 |
__extends(SimpleBar, _super); |
| 46 |
function SimpleBar() { |
| 47 |
var args = []; |
| 48 |
for (var _i = 0; _i < arguments.length; _i++) { |
| 49 |
args[_i] = arguments[_i]; |
| 50 |
} |
| 51 |
var _this = _super.apply(this, args) || this; |
| 52 |
// // Save a reference to the instance, so we know this DOM node has already been instancied |
| 53 |
SimpleBar.instances.set(args[0], _this); |
| 54 |
return _this; |
| 55 |
} |
| 56 |
SimpleBar.initDOMLoadedElements = function () { |
| 57 |
document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements); |
| 58 |
window.removeEventListener('load', this.initDOMLoadedElements); |
| 59 |
Array.prototype.forEach.call(document.querySelectorAll('[data-simplebar]'), function (el) { |
| 60 |
if (el.getAttribute('data-simplebar') !== 'init' && |
| 61 |
!SimpleBar.instances.has(el)) |
| 62 |
new SimpleBar(el, getOptions(el.attributes)); |
| 63 |
}); |
| 64 |
}; |
| 65 |
SimpleBar.removeObserver = function () { |
| 66 |
var _a; |
| 67 |
(_a = SimpleBar.globalObserver) === null || _a === void 0 ? void 0 : _a.disconnect(); |
| 68 |
}; |
| 69 |
SimpleBar.prototype.initDOM = function () { |
| 70 |
var _this = this; |
| 71 |
var _a, _b, _c; |
| 72 |
// make sure this element doesn't have the elements yet |
| 73 |
if (!Array.prototype.filter.call(this.el.children, function (child) { |
| 74 |
return child.classList.contains(_this.classNames.wrapper); |
| 75 |
}).length) { |
| 76 |
// Prepare DOM |
| 77 |
this.wrapperEl = document.createElement('div'); |
| 78 |
this.contentWrapperEl = document.createElement('div'); |
| 79 |
this.offsetEl = document.createElement('div'); |
| 80 |
this.maskEl = document.createElement('div'); |
| 81 |
this.contentEl = document.createElement('div'); |
| 82 |
this.placeholderEl = document.createElement('div'); |
| 83 |
this.heightAutoObserverWrapperEl = document.createElement('div'); |
| 84 |
this.heightAutoObserverEl = document.createElement('div'); |
| 85 |
addClasses(this.wrapperEl, this.classNames.wrapper); |
| 86 |
addClasses(this.contentWrapperEl, this.classNames.contentWrapper); |
| 87 |
addClasses(this.offsetEl, this.classNames.offset); |
| 88 |
addClasses(this.maskEl, this.classNames.mask); |
| 89 |
addClasses(this.contentEl, this.classNames.contentEl); |
| 90 |
addClasses(this.placeholderEl, this.classNames.placeholder); |
| 91 |
addClasses(this.heightAutoObserverWrapperEl, this.classNames.heightAutoObserverWrapperEl); |
| 92 |
addClasses(this.heightAutoObserverEl, this.classNames.heightAutoObserverEl); |
| 93 |
while (this.el.firstChild) { |
| 94 |
this.contentEl.appendChild(this.el.firstChild); |
| 95 |
} |
| 96 |
this.contentWrapperEl.appendChild(this.contentEl); |
| 97 |
this.offsetEl.appendChild(this.contentWrapperEl); |
| 98 |
this.maskEl.appendChild(this.offsetEl); |
| 99 |
this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl); |
| 100 |
this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl); |
| 101 |
this.wrapperEl.appendChild(this.maskEl); |
| 102 |
this.wrapperEl.appendChild(this.placeholderEl); |
| 103 |
this.el.appendChild(this.wrapperEl); |
| 104 |
(_a = this.contentWrapperEl) === null || _a === void 0 ? void 0 : _a.setAttribute('tabindex', this.options.tabIndex.toString()); |
| 105 |
(_b = this.contentWrapperEl) === null || _b === void 0 ? void 0 : _b.setAttribute('role', 'region'); |
| 106 |
(_c = this.contentWrapperEl) === null || _c === void 0 ? void 0 : _c.setAttribute('aria-label', this.options.ariaLabel); |
| 107 |
} |
| 108 |
if (!this.axis.x.track.el || !this.axis.y.track.el) { |
| 109 |
var track = document.createElement('div'); |
| 110 |
var scrollbar = document.createElement('div'); |
| 111 |
addClasses(track, this.classNames.track); |
| 112 |
addClasses(scrollbar, this.classNames.scrollbar); |
| 113 |
track.appendChild(scrollbar); |
| 114 |
this.axis.x.track.el = track.cloneNode(true); |
| 115 |
addClasses(this.axis.x.track.el, this.classNames.horizontal); |
| 116 |
this.axis.y.track.el = track.cloneNode(true); |
| 117 |
addClasses(this.axis.y.track.el, this.classNames.vertical); |
| 118 |
this.el.appendChild(this.axis.x.track.el); |
| 119 |
this.el.appendChild(this.axis.y.track.el); |
| 120 |
} |
| 121 |
SimpleBarCore.prototype.initDOM.call(this); |
| 122 |
this.el.setAttribute('data-simplebar', 'init'); |
| 123 |
}; |
| 124 |
SimpleBar.prototype.unMount = function () { |
| 125 |
SimpleBarCore.prototype.unMount.call(this); |
| 126 |
SimpleBar.instances["delete"](this.el); |
| 127 |
}; |
| 128 |
SimpleBar.initHtmlApi = function () { |
| 129 |
this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this); |
| 130 |
// MutationObserver is IE11+ |
| 131 |
if (typeof MutationObserver !== 'undefined') { |
| 132 |
// Mutation observer to observe dynamically added elements |
| 133 |
this.globalObserver = new MutationObserver(SimpleBar.handleMutations); |
| 134 |
this.globalObserver.observe(document, { childList: true, subtree: true }); |
| 135 |
} |
| 136 |
// Taken from jQuery `ready` function |
| 137 |
// Instantiate elements already present on the page |
| 138 |
if (document.readyState === 'complete' || // @ts-ignore: IE specific |
| 139 |
(document.readyState !== 'loading' && !document.documentElement.doScroll)) { |
| 140 |
// Handle it asynchronously to allow scripts the opportunity to delay init |
| 141 |
window.setTimeout(this.initDOMLoadedElements); |
| 142 |
} |
| 143 |
else { |
| 144 |
document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements); |
| 145 |
window.addEventListener('load', this.initDOMLoadedElements); |
| 146 |
} |
| 147 |
}; |
| 148 |
SimpleBar.handleMutations = function (mutations) { |
| 149 |
mutations.forEach(function (mutation) { |
| 150 |
mutation.addedNodes.forEach(function (addedNode) { |
| 151 |
if (addedNode.nodeType === 1) { |
| 152 |
if (addedNode.hasAttribute('data-simplebar')) { |
| 153 |
!SimpleBar.instances.has(addedNode) && |
| 154 |
document.documentElement.contains(addedNode) && |
| 155 |
new SimpleBar(addedNode, getOptions(addedNode.attributes)); |
| 156 |
} |
| 157 |
else { |
| 158 |
addedNode |
| 159 |
.querySelectorAll('[data-simplebar]') |
| 160 |
.forEach(function (el) { |
| 161 |
if (el.getAttribute('data-simplebar') !== 'init' && |
| 162 |
!SimpleBar.instances.has(el) && |
| 163 |
document.documentElement.contains(el)) |
| 164 |
new SimpleBar(el, getOptions(el.attributes)); |
| 165 |
}); |
| 166 |
} |
| 167 |
} |
| 168 |
}); |
| 169 |
mutation.removedNodes.forEach(function (removedNode) { |
| 170 |
var _a; |
| 171 |
if (removedNode.nodeType === 1) { |
| 172 |
if (removedNode.getAttribute('data-simplebar') === 'init') { |
| 173 |
!document.documentElement.contains(removedNode) && |
| 174 |
((_a = SimpleBar.instances.get(removedNode)) === null || _a === void 0 ? void 0 : _a.unMount()); |
| 175 |
} |
| 176 |
else { |
| 177 |
Array.prototype.forEach.call(removedNode.querySelectorAll('[data-simplebar="init"]'), function (el) { |
| 178 |
var _a; |
| 179 |
!document.documentElement.contains(el) && |
| 180 |
((_a = SimpleBar.instances.get(el)) === null || _a === void 0 ? void 0 : _a.unMount()); |
| 181 |
}); |
| 182 |
} |
| 183 |
} |
| 184 |
}); |
| 185 |
}); |
| 186 |
}; |
| 187 |
SimpleBar.instances = new WeakMap(); |
| 188 |
return SimpleBar; |
| 189 |
}(SimpleBarCore)); |
| 190 |
/** |
| 191 |
* HTML API |
| 192 |
* Called only in a browser env. |
| 193 |
*/ |
| 194 |
if (canUseDOM) { |
| 195 |
SimpleBar.initHtmlApi(); |
| 196 |
} |
| 197 |
|
| 198 |
export { SimpleBar as default }; |
| 199 |
//# sourceMappingURL=index.mjs.map |
| 200 |
|