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

200 lines
9.5 KiB

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