@karta.io/simplebar 1.0.0-beta.50 → 1.0.0-beta.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,733 +1,657 @@
1
- 'use strict';
2
-
3
- const throttle = require('lodash/throttle.js');
4
- const debounce = require('lodash/debounce.js');
5
- const memoize = require('lodash/memoize.js');
6
- const resizeObserver = require('@juggle/resize-observer');
7
-
8
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
-
10
- const throttle__default = /*#__PURE__*/_interopDefaultCompat(throttle);
11
- const debounce__default = /*#__PURE__*/_interopDefaultCompat(debounce);
12
- const memoize__default = /*#__PURE__*/_interopDefaultCompat(memoize);
13
-
14
- const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
15
-
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ let lodash_throttle_js = require("lodash/throttle.js");
24
+ lodash_throttle_js = __toESM(lodash_throttle_js, 1);
25
+ let lodash_debounce_js = require("lodash/debounce.js");
26
+ lodash_debounce_js = __toESM(lodash_debounce_js, 1);
27
+ let lodash_memoize_js = require("lodash/memoize.js");
28
+ lodash_memoize_js = __toESM(lodash_memoize_js, 1);
29
+ let _juggle_resize_observer = require("@juggle/resize-observer");
30
+ //#region src/canUseDOM.js
31
+ var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
32
+ //#endregion
33
+ //#region src/helpers.js
16
34
  function getElementWindow(element) {
17
- if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
18
- return window;
19
- }
20
- return element.ownerDocument.defaultView;
35
+ if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) return window;
36
+ return element.ownerDocument.defaultView;
21
37
  }
22
38
  function getElementDocument(element) {
23
- if (!element || !element.ownerDocument) {
24
- return document;
25
- }
26
- return element.ownerDocument;
27
- }
28
-
29
- let cachedScrollbarWidth = null;
30
- let cachedDevicePixelRatio = null;
31
- if (canUseDOM) {
32
- window.addEventListener("resize", () => {
33
- if (cachedDevicePixelRatio !== window.devicePixelRatio) {
34
- cachedDevicePixelRatio = window.devicePixelRatio;
35
- cachedScrollbarWidth = null;
36
- }
37
- });
39
+ if (!element || !element.ownerDocument) return document;
40
+ return element.ownerDocument;
38
41
  }
42
+ //#endregion
43
+ //#region src/scrollbar-width.js
44
+ var cachedScrollbarWidth = null;
45
+ var cachedDevicePixelRatio = null;
46
+ if (canUseDOM) window.addEventListener("resize", () => {
47
+ if (cachedDevicePixelRatio !== window.devicePixelRatio) {
48
+ cachedDevicePixelRatio = window.devicePixelRatio;
49
+ cachedScrollbarWidth = null;
50
+ }
51
+ });
39
52
  function scrollbarWidth(el) {
40
- if (cachedScrollbarWidth === null) {
41
- const document = getElementDocument(el);
42
- if (typeof document === "undefined") {
43
- cachedScrollbarWidth = 0;
44
- return cachedScrollbarWidth;
45
- }
46
- const body = document.body;
47
- const box = document.createElement("div");
48
- box.classList.add("simplebar-hide-scrollbar");
49
- body.appendChild(box);
50
- const width = box.getBoundingClientRect().right;
51
- body.removeChild(box);
52
- cachedScrollbarWidth = width;
53
- }
54
- return cachedScrollbarWidth;
55
- }
56
-
57
- class SimpleBar {
58
- constructor(element, options) {
59
- this.el = element;
60
- this.minScrollbarWidth = 20;
61
- this.options = { ...SimpleBar.defaultOptions, ...options };
62
- this.classNames = {
63
- ...SimpleBar.defaultOptions.classNames,
64
- ...this.options.classNames
65
- };
66
- this.axis = {
67
- x: {
68
- scrollOffsetAttr: "scrollLeft",
69
- sizeAttr: "width",
70
- scrollSizeAttr: "scrollWidth",
71
- offsetSizeAttr: "offsetWidth",
72
- offsetAttr: "left",
73
- overflowAttr: "overflowX",
74
- dragOffset: 0,
75
- isOverflowing: true,
76
- isVisible: false,
77
- forceVisible: false,
78
- track: {},
79
- scrollbar: {}
80
- },
81
- y: {
82
- scrollOffsetAttr: "scrollTop",
83
- sizeAttr: "height",
84
- scrollSizeAttr: "scrollHeight",
85
- offsetSizeAttr: "offsetHeight",
86
- offsetAttr: "top",
87
- overflowAttr: "overflowY",
88
- dragOffset: 0,
89
- isOverflowing: true,
90
- isVisible: false,
91
- forceVisible: false,
92
- track: {},
93
- scrollbar: {}
94
- }
95
- };
96
- this.removePreventClickId = null;
97
- if (SimpleBar.instances.has(this.el)) {
98
- return;
99
- }
100
- this.recalculate = throttle__default(this.recalculate.bind(this), 64);
101
- this.onMouseMove = throttle__default(this.onMouseMove.bind(this), 64);
102
- this.hideScrollbars = debounce__default(
103
- this.hideScrollbars.bind(this),
104
- this.options.timeout
105
- );
106
- this.onWindowResize = debounce__default(this.onWindowResize.bind(this), 64, {
107
- leading: true
108
- });
109
- SimpleBar.getRtlHelpers = memoize__default(SimpleBar.getRtlHelpers);
110
- this.init();
111
- }
112
- /**
113
- * Static properties
114
- */
115
- /**
116
- * Helper to fix browsers inconsistency on RTL:
117
- * - Firefox inverts the scrollbar initial position
118
- * - IE11 inverts both scrollbar position and scrolling offset
119
- * Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
120
- */
121
- static getRtlHelpers() {
122
- const dummyDiv = document.createElement("div");
123
- dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
124
- const scrollbarDummyEl = dummyDiv.firstElementChild;
125
- document.body.appendChild(scrollbarDummyEl);
126
- const dummyContainerChild = scrollbarDummyEl.firstElementChild;
127
- scrollbarDummyEl.scrollLeft = 0;
128
- const dummyContainerOffset = SimpleBar.getOffset(scrollbarDummyEl);
129
- const dummyContainerChildOffset = SimpleBar.getOffset(dummyContainerChild);
130
- scrollbarDummyEl.scrollLeft = 999;
131
- const dummyContainerScrollOffsetAfterScroll = SimpleBar.getOffset(
132
- dummyContainerChild
133
- );
134
- return {
135
- // determines if the scrolling is responding with negative values
136
- isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
137
- // determines if the origin scrollbar position is inverted or not (positioned on left or right)
138
- isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
139
- };
140
- }
141
- static defaultOptions = {
142
- autoHide: true,
143
- forceVisible: false,
144
- clickOnTrack: true,
145
- clickOnTrackSpeed: 40,
146
- classNames: {
147
- contentEl: "simplebar-content",
148
- contentWrapper: "simplebar-content-wrapper",
149
- offset: "simplebar-offset",
150
- mask: "simplebar-mask",
151
- wrapper: "simplebar-wrapper",
152
- placeholder: "simplebar-placeholder",
153
- scrollbar: "simplebar-scrollbar",
154
- track: "simplebar-track",
155
- heightAutoObserverWrapperEl: "simplebar-height-auto-observer-wrapper",
156
- heightAutoObserverEl: "simplebar-height-auto-observer",
157
- visible: "simplebar-visible",
158
- horizontal: "simplebar-horizontal",
159
- vertical: "simplebar-vertical",
160
- hover: "simplebar-hover",
161
- dragging: "simplebar-dragging"
162
- },
163
- scrollbarMinSize: 25,
164
- scrollbarMaxSize: 0,
165
- timeout: 1e3
166
- };
167
- static getOffset(el) {
168
- const rect = el.getBoundingClientRect();
169
- const elDocument = getElementDocument(el);
170
- const elWindow = getElementWindow(el);
171
- return {
172
- top: rect.top + (elWindow.pageYOffset || elDocument.documentElement.scrollTop),
173
- left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
174
- };
175
- }
176
- static instances = /* @__PURE__ */ new WeakMap();
177
- init() {
178
- SimpleBar.instances.set(this.el, this);
179
- if (canUseDOM) {
180
- this.initDOM();
181
- this.setAccessibilityAttributes();
182
- this.scrollbarWidth = this.getScrollbarWidth();
183
- this.recalculate();
184
- this.initListeners();
185
- }
186
- }
187
- initDOM() {
188
- if (Array.prototype.filter.call(
189
- this.el.children,
190
- (child) => child.classList.contains(this.classNames.wrapper)
191
- ).length) {
192
- this.wrapperEl = this.el.querySelector(`.${this.classNames.wrapper}`);
193
- this.contentWrapperEl = this.options.scrollableNode || this.el.querySelector(`.${this.classNames.contentWrapper}`);
194
- this.contentEl = this.options.contentNode || this.el.querySelector(`.${this.classNames.contentEl}`);
195
- this.offsetEl = this.el.querySelector(`.${this.classNames.offset}`);
196
- this.maskEl = this.el.querySelector(`.${this.classNames.mask}`);
197
- this.placeholderEl = this.findChild(
198
- this.wrapperEl,
199
- `.${this.classNames.placeholder}`
200
- );
201
- this.heightAutoObserverWrapperEl = this.el.querySelector(
202
- `.${this.classNames.heightAutoObserverWrapperEl}`
203
- );
204
- this.heightAutoObserverEl = this.el.querySelector(
205
- `.${this.classNames.heightAutoObserverEl}`
206
- );
207
- this.axis.x.track.el = this.findChild(
208
- this.el,
209
- `.${this.classNames.track}.${this.classNames.horizontal}`
210
- );
211
- this.axis.y.track.el = this.findChild(
212
- this.el,
213
- `.${this.classNames.track}.${this.classNames.vertical}`
214
- );
215
- } else {
216
- this.wrapperEl = document.createElement("div");
217
- this.contentWrapperEl = document.createElement("div");
218
- this.offsetEl = document.createElement("div");
219
- this.maskEl = document.createElement("div");
220
- this.contentEl = document.createElement("div");
221
- this.placeholderEl = document.createElement("div");
222
- this.heightAutoObserverWrapperEl = document.createElement("div");
223
- this.heightAutoObserverEl = document.createElement("div");
224
- this.wrapperEl.classList.add(this.classNames.wrapper);
225
- this.contentWrapperEl.classList.add(this.classNames.contentWrapper);
226
- this.offsetEl.classList.add(this.classNames.offset);
227
- this.maskEl.classList.add(this.classNames.mask);
228
- this.contentEl.classList.add(this.classNames.contentEl);
229
- this.placeholderEl.classList.add(this.classNames.placeholder);
230
- this.heightAutoObserverWrapperEl.classList.add(
231
- this.classNames.heightAutoObserverWrapperEl
232
- );
233
- this.heightAutoObserverEl.classList.add(
234
- this.classNames.heightAutoObserverEl
235
- );
236
- while (this.el.firstChild) {
237
- this.contentEl.appendChild(this.el.firstChild);
238
- }
239
- this.contentWrapperEl.appendChild(this.contentEl);
240
- this.offsetEl.appendChild(this.contentWrapperEl);
241
- this.maskEl.appendChild(this.offsetEl);
242
- this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
243
- this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
244
- this.wrapperEl.appendChild(this.maskEl);
245
- this.wrapperEl.appendChild(this.placeholderEl);
246
- this.el.appendChild(this.wrapperEl);
247
- }
248
- if (!this.axis.x.track.el || !this.axis.y.track.el) {
249
- const track = document.createElement("div");
250
- const scrollbar = document.createElement("div");
251
- track.classList.add(this.classNames.track);
252
- scrollbar.classList.add(this.classNames.scrollbar);
253
- track.appendChild(scrollbar);
254
- this.axis.x.track.el = track.cloneNode(true);
255
- this.axis.x.track.el.classList.add(this.classNames.horizontal);
256
- this.axis.y.track.el = track.cloneNode(true);
257
- this.axis.y.track.el.classList.add(this.classNames.vertical);
258
- this.el.appendChild(this.axis.x.track.el);
259
- this.el.appendChild(this.axis.y.track.el);
260
- }
261
- this.axis.x.scrollbar.el = this.axis.x.track.el.querySelector(
262
- `.${this.classNames.scrollbar}`
263
- );
264
- this.axis.y.scrollbar.el = this.axis.y.track.el.querySelector(
265
- `.${this.classNames.scrollbar}`
266
- );
267
- if (!this.options.autoHide) {
268
- this.axis.x.scrollbar.el.classList.add(this.classNames.visible);
269
- this.axis.y.scrollbar.el.classList.add(this.classNames.visible);
270
- }
271
- this.el.setAttribute("data-simplebar", "init");
272
- }
273
- setAccessibilityAttributes() {
274
- const ariaLabel = this.options.ariaLabel || "scrollable content";
275
- this.contentWrapperEl.setAttribute("tabindex", "0");
276
- this.contentWrapperEl.setAttribute("role", "region");
277
- this.contentWrapperEl.setAttribute("aria-label", ariaLabel);
278
- }
279
- initListeners() {
280
- const elWindow = getElementWindow(this.el);
281
- if (this.options.autoHide) {
282
- this.el.addEventListener("mouseenter", this.onMouseEnter);
283
- }
284
- ["mousedown", "click", "dblclick"].forEach((e) => {
285
- this.el.addEventListener(e, this.onPointerEvent, true);
286
- });
287
- ["touchstart", "touchend", "touchmove"].forEach((e) => {
288
- this.el.addEventListener(e, this.onPointerEvent, {
289
- capture: true,
290
- passive: true
291
- });
292
- });
293
- this.el.addEventListener("mousemove", this.onMouseMove);
294
- this.el.addEventListener("mouseleave", this.onMouseLeave);
295
- this.contentWrapperEl.addEventListener("scroll", this.onScroll);
296
- elWindow.addEventListener("resize", this.onWindowResize);
297
- let resizeObserverStarted = false;
298
- const resizeObserver$1 = elWindow.ResizeObserver || resizeObserver.ResizeObserver;
299
- this.resizeObserver = new resizeObserver$1(() => {
300
- if (!resizeObserverStarted) return;
301
- this.recalculate();
302
- });
303
- this.resizeObserver.observe(this.el);
304
- this.resizeObserver.observe(this.contentEl);
305
- elWindow.requestAnimationFrame(() => {
306
- resizeObserverStarted = true;
307
- });
308
- this.mutationObserver = new elWindow.MutationObserver(this.recalculate);
309
- this.mutationObserver.observe(this.contentEl, {
310
- childList: true,
311
- subtree: true,
312
- characterData: true
313
- });
314
- }
315
- recalculate() {
316
- const elWindow = getElementWindow(this.el);
317
- this.elStyles = elWindow.getComputedStyle(this.el);
318
- this.isRtl = this.elStyles.direction === "rtl";
319
- const isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
320
- const isWidthAuto = this.heightAutoObserverEl.offsetWidth <= 1;
321
- const contentElOffsetWidth = this.contentEl.offsetWidth;
322
- const contentWrapperElOffsetWidth = this.contentWrapperEl.offsetWidth;
323
- const elOverflowX = this.elStyles.overflowX;
324
- const elOverflowY = this.elStyles.overflowY;
325
- this.contentEl.style.padding = `${this.elStyles.paddingTop} ${this.elStyles.paddingRight} ${this.elStyles.paddingBottom} ${this.elStyles.paddingLeft}`;
326
- this.wrapperEl.style.margin = `-${this.elStyles.paddingTop} -${this.elStyles.paddingRight} -${this.elStyles.paddingBottom} -${this.elStyles.paddingLeft}`;
327
- const contentElScrollHeight = this.contentEl.scrollHeight;
328
- const contentElScrollWidth = this.contentEl.scrollWidth;
329
- this.contentWrapperEl.style.height = isHeightAuto ? "auto" : "100%";
330
- this.placeholderEl.style.width = isWidthAuto ? `${contentElOffsetWidth}px` : "auto";
331
- this.placeholderEl.style.height = `${contentElScrollHeight}px`;
332
- const contentWrapperElOffsetHeight = this.contentWrapperEl.offsetHeight;
333
- this.axis.x.isOverflowing = contentElScrollWidth > contentElOffsetWidth;
334
- this.axis.y.isOverflowing = contentElScrollHeight > contentWrapperElOffsetHeight;
335
- this.axis.x.isOverflowing = elOverflowX === "hidden" ? false : this.axis.x.isOverflowing;
336
- this.axis.y.isOverflowing = elOverflowY === "hidden" ? false : this.axis.y.isOverflowing;
337
- this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
338
- this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
339
- this.hideNativeScrollbar();
340
- let offsetForXScrollbar = this.axis.x.isOverflowing ? this.scrollbarWidth : 0;
341
- let offsetForYScrollbar = this.axis.y.isOverflowing ? this.scrollbarWidth : 0;
342
- this.axis.x.isOverflowing = this.axis.x.isOverflowing && contentElScrollWidth > contentWrapperElOffsetWidth - offsetForYScrollbar;
343
- this.axis.y.isOverflowing = this.axis.y.isOverflowing && contentElScrollHeight > contentWrapperElOffsetHeight - offsetForXScrollbar;
344
- this.axis.x.scrollbar.size = this.getScrollbarSize("x");
345
- this.axis.y.scrollbar.size = this.getScrollbarSize("y");
346
- this.axis.x.scrollbar.el.style.width = `${this.axis.x.scrollbar.size}px`;
347
- this.axis.y.scrollbar.el.style.height = `${this.axis.y.scrollbar.size}px`;
348
- this.positionScrollbar("x");
349
- this.positionScrollbar("y");
350
- this.toggleTrackVisibility("x");
351
- this.toggleTrackVisibility("y");
352
- }
353
- /**
354
- * Calculate scrollbar size
355
- */
356
- getScrollbarSize(axis = "y") {
357
- if (!this.axis[axis].isOverflowing) {
358
- return 0;
359
- }
360
- const contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
361
- const trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
362
- let scrollbarSize;
363
- let scrollbarRatio = trackSize / contentSize;
364
- scrollbarSize = Math.max(
365
- ~~(scrollbarRatio * trackSize),
366
- this.options.scrollbarMinSize
367
- );
368
- if (this.options.scrollbarMaxSize) {
369
- scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
370
- }
371
- return scrollbarSize;
372
- }
373
- positionScrollbar(axis = "y") {
374
- if (!this.axis[axis].isOverflowing) {
375
- return;
376
- }
377
- const contentSize = this.contentWrapperEl[this.axis[axis].scrollSizeAttr];
378
- const trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
379
- const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
380
- const scrollbar = this.axis[axis].scrollbar;
381
- let scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
382
- scrollOffset = axis === "x" && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
383
- let scrollPourcent = scrollOffset / (contentSize - hostSize);
384
- let handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
385
- handleOffset = axis === "x" && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
386
- scrollbar.el.style.transform = axis === "x" ? `translate3d(${handleOffset}px, 0, 0)` : `translate3d(0, ${handleOffset}px, 0)`;
387
- }
388
- toggleTrackVisibility(axis = "y") {
389
- const track = this.axis[axis].track.el;
390
- const scrollbar = this.axis[axis].scrollbar.el;
391
- if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
392
- track.style.visibility = "visible";
393
- this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "scroll";
394
- } else {
395
- track.style.visibility = "hidden";
396
- this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "hidden";
397
- }
398
- if (this.axis[axis].isOverflowing) {
399
- scrollbar.style.display = "block";
400
- } else {
401
- scrollbar.style.display = "none";
402
- }
403
- }
404
- hideNativeScrollbar() {
405
- this.offsetEl.style[this.isRtl ? "left" : "right"] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? `-${this.scrollbarWidth}px` : 0;
406
- this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? `-${this.scrollbarWidth}px` : 0;
407
- }
408
- /**
409
- * On scroll event handling
410
- */
411
- onScroll = () => {
412
- const elWindow = getElementWindow(this.el);
413
- if (!this.scrollXTicking) {
414
- elWindow.requestAnimationFrame(this.scrollX);
415
- this.scrollXTicking = true;
416
- }
417
- if (!this.scrollYTicking) {
418
- elWindow.requestAnimationFrame(this.scrollY);
419
- this.scrollYTicking = true;
420
- }
421
- };
422
- scrollX = () => {
423
- if (this.axis.x.isOverflowing) {
424
- this.showScrollbar("x");
425
- this.positionScrollbar("x");
426
- }
427
- this.scrollXTicking = false;
428
- };
429
- scrollY = () => {
430
- if (this.axis.y.isOverflowing) {
431
- this.showScrollbar("y");
432
- this.positionScrollbar("y");
433
- }
434
- this.scrollYTicking = false;
435
- };
436
- onMouseEnter = () => {
437
- this.showScrollbar("x");
438
- this.showScrollbar("y");
439
- };
440
- onMouseMove = (e) => {
441
- this.mouseX = e.clientX;
442
- this.mouseY = e.clientY;
443
- if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
444
- this.onMouseMoveForAxis("x");
445
- }
446
- if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
447
- this.onMouseMoveForAxis("y");
448
- }
449
- };
450
- onMouseMoveForAxis(axis = "y") {
451
- this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
452
- this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
453
- const isWithinScrollbarBoundsX = this.isWithinBounds(
454
- this.axis[axis].scrollbar.rect
455
- );
456
- if (isWithinScrollbarBoundsX) {
457
- this.axis[axis].scrollbar.el.classList.add(this.classNames.hover);
458
- } else {
459
- this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
460
- }
461
- if (this.isWithinBounds(this.axis[axis].track.rect)) {
462
- this.showScrollbar(axis);
463
- this.axis[axis].track.el.classList.add(this.classNames.hover);
464
- } else {
465
- this.axis[axis].track.el.classList.remove(this.classNames.hover);
466
- }
467
- }
468
- onMouseLeave = () => {
469
- this.onMouseMove.cancel();
470
- if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
471
- this.onMouseLeaveForAxis("x");
472
- }
473
- if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
474
- this.onMouseLeaveForAxis("y");
475
- }
476
- this.mouseX = -1;
477
- this.mouseY = -1;
478
- };
479
- onMouseLeaveForAxis(axis = "y") {
480
- this.axis[axis].track.el.classList.remove(this.classNames.hover);
481
- this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
482
- }
483
- onWindowResize = () => {
484
- this.scrollbarWidth = this.getScrollbarWidth();
485
- this.hideNativeScrollbar();
486
- };
487
- /**
488
- * Show scrollbar
489
- */
490
- showScrollbar(axis = "y") {
491
- let scrollbar = this.axis[axis].scrollbar.el;
492
- if (!this.axis[axis].isVisible) {
493
- scrollbar.classList.add(this.classNames.visible);
494
- this.axis[axis].isVisible = true;
495
- }
496
- if (this.options.autoHide) {
497
- this.hideScrollbars();
498
- }
499
- }
500
- /**
501
- * Hide Scrollbar
502
- */
503
- hideScrollbars = () => {
504
- this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
505
- this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
506
- if (!this.isWithinBounds(this.axis.y.track.rect)) {
507
- this.axis.y.scrollbar.el.classList.remove(this.classNames.visible);
508
- this.axis.y.isVisible = false;
509
- }
510
- if (!this.isWithinBounds(this.axis.x.track.rect)) {
511
- this.axis.x.scrollbar.el.classList.remove(this.classNames.visible);
512
- this.axis.x.isVisible = false;
513
- }
514
- };
515
- onPointerEvent = (e) => {
516
- let isWithinTrackXBounds, isWithinTrackYBounds;
517
- this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
518
- this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
519
- if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
520
- isWithinTrackXBounds = this.isWithinBounds(this.axis.x.track.rect);
521
- }
522
- if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
523
- isWithinTrackYBounds = this.isWithinBounds(this.axis.y.track.rect);
524
- }
525
- if (isWithinTrackXBounds || isWithinTrackYBounds) {
526
- e.preventDefault();
527
- e.stopPropagation();
528
- if (e.type === "mousedown") {
529
- if (isWithinTrackXBounds) {
530
- this.axis.x.scrollbar.rect = this.axis.x.scrollbar.el.getBoundingClientRect();
531
- if (this.isWithinBounds(this.axis.x.scrollbar.rect)) {
532
- this.onDragStart(e, "x");
533
- } else {
534
- this.onTrackClick(e, "x");
535
- }
536
- }
537
- if (isWithinTrackYBounds) {
538
- this.axis.y.scrollbar.rect = this.axis.y.scrollbar.el.getBoundingClientRect();
539
- if (this.isWithinBounds(this.axis.y.scrollbar.rect)) {
540
- this.onDragStart(e, "y");
541
- } else {
542
- this.onTrackClick(e, "y");
543
- }
544
- }
545
- }
546
- }
547
- };
548
- /**
549
- * on scrollbar handle drag movement starts
550
- */
551
- onDragStart(e, axis = "y") {
552
- const elDocument = getElementDocument(this.el);
553
- const elWindow = getElementWindow(this.el);
554
- const scrollbar = this.axis[axis].scrollbar;
555
- const eventOffset = axis === "y" ? e.pageY : e.pageX;
556
- this.axis[axis].dragOffset = eventOffset - scrollbar.rect[this.axis[axis].offsetAttr];
557
- this.draggedAxis = axis;
558
- this.el.classList.add(this.classNames.dragging);
559
- elDocument.addEventListener("mousemove", this.drag, true);
560
- elDocument.addEventListener("mouseup", this.onEndDrag, true);
561
- if (this.removePreventClickId === null) {
562
- elDocument.addEventListener("click", this.preventClick, true);
563
- elDocument.addEventListener("dblclick", this.preventClick, true);
564
- } else {
565
- elWindow.clearTimeout(this.removePreventClickId);
566
- this.removePreventClickId = null;
567
- }
568
- }
569
- /**
570
- * Drag scrollbar handle
571
- */
572
- drag = (e) => {
573
- let eventOffset;
574
- const track = this.axis[this.draggedAxis].track;
575
- const trackSize = track.rect[this.axis[this.draggedAxis].sizeAttr];
576
- const scrollbar = this.axis[this.draggedAxis].scrollbar;
577
- const contentSize = this.contentWrapperEl[this.axis[this.draggedAxis].scrollSizeAttr];
578
- const hostSize = parseInt(
579
- this.elStyles[this.axis[this.draggedAxis].sizeAttr],
580
- 10
581
- );
582
- e.preventDefault();
583
- e.stopPropagation();
584
- if (this.draggedAxis === "y") {
585
- eventOffset = e.pageY;
586
- } else {
587
- eventOffset = e.pageX;
588
- }
589
- let dragPos = eventOffset - track.rect[this.axis[this.draggedAxis].offsetAttr] - this.axis[this.draggedAxis].dragOffset;
590
- let dragPerc = dragPos / (trackSize - scrollbar.size);
591
- let scrollPos = dragPerc * (contentSize - hostSize);
592
- if (this.draggedAxis === "x") {
593
- scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
594
- scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
595
- }
596
- this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
597
- };
598
- /**
599
- * End scroll handle drag
600
- */
601
- onEndDrag = (e) => {
602
- const elDocument = getElementDocument(this.el);
603
- const elWindow = getElementWindow(this.el);
604
- e.preventDefault();
605
- e.stopPropagation();
606
- this.el.classList.remove(this.classNames.dragging);
607
- elDocument.removeEventListener("mousemove", this.drag, true);
608
- elDocument.removeEventListener("mouseup", this.onEndDrag, true);
609
- this.removePreventClickId = elWindow.setTimeout(() => {
610
- elDocument.removeEventListener("click", this.preventClick, true);
611
- elDocument.removeEventListener("dblclick", this.preventClick, true);
612
- this.removePreventClickId = null;
613
- });
614
- };
615
- /**
616
- * Handler to ignore click events during drag
617
- */
618
- preventClick = (e) => {
619
- e.preventDefault();
620
- e.stopPropagation();
621
- };
622
- onTrackClick(e, axis = "y") {
623
- if (!this.options.clickOnTrack) return;
624
- const elWindow = getElementWindow(this.el);
625
- this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
626
- const scrollbar = this.axis[axis].scrollbar;
627
- const scrollbarOffset = scrollbar.rect[this.axis[axis].offsetAttr];
628
- const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
629
- let scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
630
- const t = axis === "y" ? this.mouseY - scrollbarOffset : this.mouseX - scrollbarOffset;
631
- const dir = t < 0 ? -1 : 1;
632
- const scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize;
633
- const scrollTo = () => {
634
- if (dir === -1) {
635
- if (scrolled > scrollSize) {
636
- scrolled -= this.options.clickOnTrackSpeed;
637
- this.contentWrapperEl.scrollTo({
638
- [this.axis[axis].offsetAttr]: scrolled
639
- });
640
- elWindow.requestAnimationFrame(scrollTo);
641
- }
642
- } else {
643
- if (scrolled < scrollSize) {
644
- scrolled += this.options.clickOnTrackSpeed;
645
- this.contentWrapperEl.scrollTo({
646
- [this.axis[axis].offsetAttr]: scrolled
647
- });
648
- elWindow.requestAnimationFrame(scrollTo);
649
- }
650
- }
651
- };
652
- scrollTo();
653
- }
654
- /**
655
- * Getter for content element
656
- */
657
- getContentElement() {
658
- return this.contentEl;
659
- }
660
- /**
661
- * Getter for original scrolling element
662
- */
663
- getScrollElement() {
664
- return this.contentWrapperEl;
665
- }
666
- getScrollbarWidth() {
667
- try {
668
- if (getComputedStyle(this.contentWrapperEl, "::-webkit-scrollbar").display === "none" || "scrollbarWidth" in document.documentElement.style || "-ms-overflow-style" in document.documentElement.style) {
669
- return 0;
670
- } else {
671
- return scrollbarWidth(this.el);
672
- }
673
- } catch (e) {
674
- return scrollbarWidth(this.el);
675
- }
676
- }
677
- removeListeners() {
678
- const elWindow = getElementWindow(this.el);
679
- if (this.options.autoHide) {
680
- this.el.removeEventListener("mouseenter", this.onMouseEnter);
681
- }
682
- ["mousedown", "click", "dblclick"].forEach((e) => {
683
- this.el.removeEventListener(e, this.onPointerEvent, true);
684
- });
685
- ["touchstart", "touchend", "touchmove"].forEach((e) => {
686
- this.el.removeEventListener(e, this.onPointerEvent, {
687
- capture: true,
688
- passive: true
689
- });
690
- });
691
- this.el.removeEventListener("mousemove", this.onMouseMove);
692
- this.el.removeEventListener("mouseleave", this.onMouseLeave);
693
- if (this.contentWrapperEl) {
694
- this.contentWrapperEl.removeEventListener("scroll", this.onScroll);
695
- }
696
- elWindow.removeEventListener("resize", this.onWindowResize);
697
- if (this.mutationObserver) {
698
- this.mutationObserver.disconnect();
699
- }
700
- if (this.resizeObserver) {
701
- this.resizeObserver.disconnect();
702
- }
703
- this.recalculate.cancel();
704
- this.onMouseMove.cancel();
705
- this.hideScrollbars.cancel();
706
- this.onWindowResize.cancel();
707
- }
708
- /**
709
- * UnMount mutation observer and delete SimpleBar instance from DOM element
710
- */
711
- unMount() {
712
- this.removeListeners();
713
- SimpleBar.instances.delete(this.el);
714
- }
715
- /**
716
- * Check if mouse is within bounds
717
- */
718
- isWithinBounds(bbox) {
719
- return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
720
- }
721
- /**
722
- * Find element children matches query
723
- */
724
- findChild(el, query) {
725
- const matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
726
- return Array.prototype.filter.call(
727
- el.children,
728
- (child) => matches.call(child, query)
729
- )[0];
730
- }
53
+ if (cachedScrollbarWidth === null) {
54
+ const document = getElementDocument(el);
55
+ if (typeof document === "undefined") {
56
+ cachedScrollbarWidth = 0;
57
+ return cachedScrollbarWidth;
58
+ }
59
+ const body = document.body;
60
+ const box = document.createElement("div");
61
+ box.classList.add("simplebar-hide-scrollbar");
62
+ body.appendChild(box);
63
+ const width = box.getBoundingClientRect().right;
64
+ body.removeChild(box);
65
+ cachedScrollbarWidth = width;
66
+ }
67
+ return cachedScrollbarWidth;
731
68
  }
732
-
69
+ //#endregion
70
+ //#region src/simplebar.js
71
+ var SimpleBar = class SimpleBar {
72
+ constructor(element, options) {
73
+ this.el = element;
74
+ this.minScrollbarWidth = 20;
75
+ this.options = {
76
+ ...SimpleBar.defaultOptions,
77
+ ...options
78
+ };
79
+ this.classNames = {
80
+ ...SimpleBar.defaultOptions.classNames,
81
+ ...this.options.classNames
82
+ };
83
+ this.axis = {
84
+ x: {
85
+ scrollOffsetAttr: "scrollLeft",
86
+ sizeAttr: "width",
87
+ scrollSizeAttr: "scrollWidth",
88
+ offsetSizeAttr: "offsetWidth",
89
+ offsetAttr: "left",
90
+ overflowAttr: "overflowX",
91
+ dragOffset: 0,
92
+ isOverflowing: true,
93
+ isVisible: false,
94
+ forceVisible: false,
95
+ track: {},
96
+ scrollbar: {}
97
+ },
98
+ y: {
99
+ scrollOffsetAttr: "scrollTop",
100
+ sizeAttr: "height",
101
+ scrollSizeAttr: "scrollHeight",
102
+ offsetSizeAttr: "offsetHeight",
103
+ offsetAttr: "top",
104
+ overflowAttr: "overflowY",
105
+ dragOffset: 0,
106
+ isOverflowing: true,
107
+ isVisible: false,
108
+ forceVisible: false,
109
+ track: {},
110
+ scrollbar: {}
111
+ }
112
+ };
113
+ this.removePreventClickId = null;
114
+ if (SimpleBar.instances.has(this.el)) return;
115
+ this.recalculate = (0, lodash_throttle_js.default)(this.recalculate.bind(this), 64);
116
+ this.onMouseMove = (0, lodash_throttle_js.default)(this.onMouseMove.bind(this), 64);
117
+ this.hideScrollbars = (0, lodash_debounce_js.default)(this.hideScrollbars.bind(this), this.options.timeout);
118
+ this.onWindowResize = (0, lodash_debounce_js.default)(this.onWindowResize.bind(this), 64, { leading: true });
119
+ SimpleBar.getRtlHelpers = (0, lodash_memoize_js.default)(SimpleBar.getRtlHelpers);
120
+ this.init();
121
+ }
122
+ /**
123
+ * Static properties
124
+ */
125
+ /**
126
+ * Helper to fix browsers inconsistency on RTL:
127
+ * - Firefox inverts the scrollbar initial position
128
+ * - IE11 inverts both scrollbar position and scrolling offset
129
+ * Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
130
+ */
131
+ static getRtlHelpers() {
132
+ const dummyDiv = document.createElement("div");
133
+ dummyDiv.innerHTML = "<div class=\"hs-dummy-scrollbar-size\"><div style=\"height: 200%; width: 200%; margin: 10px 0;\"></div></div>";
134
+ const scrollbarDummyEl = dummyDiv.firstElementChild;
135
+ document.body.appendChild(scrollbarDummyEl);
136
+ const dummyContainerChild = scrollbarDummyEl.firstElementChild;
137
+ scrollbarDummyEl.scrollLeft = 0;
138
+ const dummyContainerOffset = SimpleBar.getOffset(scrollbarDummyEl);
139
+ const dummyContainerChildOffset = SimpleBar.getOffset(dummyContainerChild);
140
+ scrollbarDummyEl.scrollLeft = 999;
141
+ const dummyContainerScrollOffsetAfterScroll = SimpleBar.getOffset(dummyContainerChild);
142
+ return {
143
+ isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
144
+ isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
145
+ };
146
+ }
147
+ static defaultOptions = {
148
+ autoHide: true,
149
+ forceVisible: false,
150
+ clickOnTrack: true,
151
+ clickOnTrackSpeed: 40,
152
+ classNames: {
153
+ contentEl: "simplebar-content",
154
+ contentWrapper: "simplebar-content-wrapper",
155
+ offset: "simplebar-offset",
156
+ mask: "simplebar-mask",
157
+ wrapper: "simplebar-wrapper",
158
+ placeholder: "simplebar-placeholder",
159
+ scrollbar: "simplebar-scrollbar",
160
+ track: "simplebar-track",
161
+ heightAutoObserverWrapperEl: "simplebar-height-auto-observer-wrapper",
162
+ heightAutoObserverEl: "simplebar-height-auto-observer",
163
+ visible: "simplebar-visible",
164
+ horizontal: "simplebar-horizontal",
165
+ vertical: "simplebar-vertical",
166
+ hover: "simplebar-hover",
167
+ dragging: "simplebar-dragging"
168
+ },
169
+ scrollbarMinSize: 25,
170
+ scrollbarMaxSize: 0,
171
+ timeout: 1e3
172
+ };
173
+ static getOffset(el) {
174
+ const rect = el.getBoundingClientRect();
175
+ const elDocument = getElementDocument(el);
176
+ const elWindow = getElementWindow(el);
177
+ return {
178
+ top: rect.top + (elWindow.pageYOffset || elDocument.documentElement.scrollTop),
179
+ left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
180
+ };
181
+ }
182
+ static instances = /* @__PURE__ */ new WeakMap();
183
+ init() {
184
+ SimpleBar.instances.set(this.el, this);
185
+ if (canUseDOM) {
186
+ this.initDOM();
187
+ this.setAccessibilityAttributes();
188
+ this.scrollbarWidth = this.getScrollbarWidth();
189
+ this.recalculate();
190
+ this.initListeners();
191
+ }
192
+ }
193
+ initDOM() {
194
+ if (Array.prototype.filter.call(this.el.children, (child) => child.classList.contains(this.classNames.wrapper)).length) {
195
+ this.wrapperEl = this.el.querySelector(`.${this.classNames.wrapper}`);
196
+ this.contentWrapperEl = this.options.scrollableNode || this.el.querySelector(`.${this.classNames.contentWrapper}`);
197
+ this.contentEl = this.options.contentNode || this.el.querySelector(`.${this.classNames.contentEl}`);
198
+ this.offsetEl = this.el.querySelector(`.${this.classNames.offset}`);
199
+ this.maskEl = this.el.querySelector(`.${this.classNames.mask}`);
200
+ this.placeholderEl = this.findChild(this.wrapperEl, `.${this.classNames.placeholder}`);
201
+ this.heightAutoObserverWrapperEl = this.el.querySelector(`.${this.classNames.heightAutoObserverWrapperEl}`);
202
+ this.heightAutoObserverEl = this.el.querySelector(`.${this.classNames.heightAutoObserverEl}`);
203
+ this.axis.x.track.el = this.findChild(this.el, `.${this.classNames.track}.${this.classNames.horizontal}`);
204
+ this.axis.y.track.el = this.findChild(this.el, `.${this.classNames.track}.${this.classNames.vertical}`);
205
+ } else {
206
+ this.wrapperEl = document.createElement("div");
207
+ this.contentWrapperEl = document.createElement("div");
208
+ this.offsetEl = document.createElement("div");
209
+ this.maskEl = document.createElement("div");
210
+ this.contentEl = document.createElement("div");
211
+ this.placeholderEl = document.createElement("div");
212
+ this.heightAutoObserverWrapperEl = document.createElement("div");
213
+ this.heightAutoObserverEl = document.createElement("div");
214
+ this.wrapperEl.classList.add(this.classNames.wrapper);
215
+ this.contentWrapperEl.classList.add(this.classNames.contentWrapper);
216
+ this.offsetEl.classList.add(this.classNames.offset);
217
+ this.maskEl.classList.add(this.classNames.mask);
218
+ this.contentEl.classList.add(this.classNames.contentEl);
219
+ this.placeholderEl.classList.add(this.classNames.placeholder);
220
+ this.heightAutoObserverWrapperEl.classList.add(this.classNames.heightAutoObserverWrapperEl);
221
+ this.heightAutoObserverEl.classList.add(this.classNames.heightAutoObserverEl);
222
+ while (this.el.firstChild) this.contentEl.appendChild(this.el.firstChild);
223
+ this.contentWrapperEl.appendChild(this.contentEl);
224
+ this.offsetEl.appendChild(this.contentWrapperEl);
225
+ this.maskEl.appendChild(this.offsetEl);
226
+ this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
227
+ this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
228
+ this.wrapperEl.appendChild(this.maskEl);
229
+ this.wrapperEl.appendChild(this.placeholderEl);
230
+ this.el.appendChild(this.wrapperEl);
231
+ }
232
+ if (!this.axis.x.track.el || !this.axis.y.track.el) {
233
+ const track = document.createElement("div");
234
+ const scrollbar = document.createElement("div");
235
+ track.classList.add(this.classNames.track);
236
+ scrollbar.classList.add(this.classNames.scrollbar);
237
+ track.appendChild(scrollbar);
238
+ this.axis.x.track.el = track.cloneNode(true);
239
+ this.axis.x.track.el.classList.add(this.classNames.horizontal);
240
+ this.axis.y.track.el = track.cloneNode(true);
241
+ this.axis.y.track.el.classList.add(this.classNames.vertical);
242
+ this.el.appendChild(this.axis.x.track.el);
243
+ this.el.appendChild(this.axis.y.track.el);
244
+ }
245
+ this.axis.x.scrollbar.el = this.axis.x.track.el.querySelector(`.${this.classNames.scrollbar}`);
246
+ this.axis.y.scrollbar.el = this.axis.y.track.el.querySelector(`.${this.classNames.scrollbar}`);
247
+ if (!this.options.autoHide) {
248
+ this.axis.x.scrollbar.el.classList.add(this.classNames.visible);
249
+ this.axis.y.scrollbar.el.classList.add(this.classNames.visible);
250
+ }
251
+ this.el.setAttribute("data-simplebar", "init");
252
+ }
253
+ setAccessibilityAttributes() {
254
+ const ariaLabel = this.options.ariaLabel || "scrollable content";
255
+ this.contentWrapperEl.setAttribute("tabindex", "0");
256
+ this.contentWrapperEl.setAttribute("role", "region");
257
+ this.contentWrapperEl.setAttribute("aria-label", ariaLabel);
258
+ }
259
+ initListeners() {
260
+ const elWindow = getElementWindow(this.el);
261
+ if (this.options.autoHide) this.el.addEventListener("mouseenter", this.onMouseEnter);
262
+ [
263
+ "mousedown",
264
+ "click",
265
+ "dblclick"
266
+ ].forEach((e) => {
267
+ this.el.addEventListener(e, this.onPointerEvent, true);
268
+ });
269
+ [
270
+ "touchstart",
271
+ "touchend",
272
+ "touchmove"
273
+ ].forEach((e) => {
274
+ this.el.addEventListener(e, this.onPointerEvent, {
275
+ capture: true,
276
+ passive: true
277
+ });
278
+ });
279
+ this.el.addEventListener("mousemove", this.onMouseMove);
280
+ this.el.addEventListener("mouseleave", this.onMouseLeave);
281
+ this.contentWrapperEl.addEventListener("scroll", this.onScroll);
282
+ elWindow.addEventListener("resize", this.onWindowResize);
283
+ let resizeObserverStarted = false;
284
+ const resizeObserver = elWindow.ResizeObserver || _juggle_resize_observer.ResizeObserver;
285
+ this.resizeObserver = new resizeObserver(() => {
286
+ if (!resizeObserverStarted) return;
287
+ this.recalculate();
288
+ });
289
+ this.resizeObserver.observe(this.el);
290
+ this.resizeObserver.observe(this.contentEl);
291
+ elWindow.requestAnimationFrame(() => {
292
+ resizeObserverStarted = true;
293
+ });
294
+ this.mutationObserver = new elWindow.MutationObserver(this.recalculate);
295
+ this.mutationObserver.observe(this.contentEl, {
296
+ childList: true,
297
+ subtree: true,
298
+ characterData: true
299
+ });
300
+ }
301
+ recalculate() {
302
+ const elWindow = getElementWindow(this.el);
303
+ this.elStyles = elWindow.getComputedStyle(this.el);
304
+ this.isRtl = this.elStyles.direction === "rtl";
305
+ const isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
306
+ const isWidthAuto = this.heightAutoObserverEl.offsetWidth <= 1;
307
+ const contentElOffsetWidth = this.contentEl.offsetWidth;
308
+ const contentWrapperElOffsetWidth = this.contentWrapperEl.offsetWidth;
309
+ const elOverflowX = this.elStyles.overflowX;
310
+ const elOverflowY = this.elStyles.overflowY;
311
+ this.contentEl.style.padding = `${this.elStyles.paddingTop} ${this.elStyles.paddingRight} ${this.elStyles.paddingBottom} ${this.elStyles.paddingLeft}`;
312
+ this.wrapperEl.style.margin = `-${this.elStyles.paddingTop} -${this.elStyles.paddingRight} -${this.elStyles.paddingBottom} -${this.elStyles.paddingLeft}`;
313
+ const contentElScrollHeight = this.contentEl.scrollHeight;
314
+ const contentElScrollWidth = this.contentEl.scrollWidth;
315
+ this.contentWrapperEl.style.height = isHeightAuto ? "auto" : "100%";
316
+ this.placeholderEl.style.width = isWidthAuto ? `${contentElOffsetWidth}px` : "auto";
317
+ this.placeholderEl.style.height = `${contentElScrollHeight}px`;
318
+ const contentWrapperElOffsetHeight = this.contentWrapperEl.offsetHeight;
319
+ this.axis.x.isOverflowing = contentElScrollWidth > contentElOffsetWidth;
320
+ this.axis.y.isOverflowing = contentElScrollHeight > contentWrapperElOffsetHeight;
321
+ this.axis.x.isOverflowing = elOverflowX === "hidden" ? false : this.axis.x.isOverflowing;
322
+ this.axis.y.isOverflowing = elOverflowY === "hidden" ? false : this.axis.y.isOverflowing;
323
+ this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
324
+ this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
325
+ this.hideNativeScrollbar();
326
+ let offsetForXScrollbar = this.axis.x.isOverflowing ? this.scrollbarWidth : 0;
327
+ let offsetForYScrollbar = this.axis.y.isOverflowing ? this.scrollbarWidth : 0;
328
+ this.axis.x.isOverflowing = this.axis.x.isOverflowing && contentElScrollWidth > contentWrapperElOffsetWidth - offsetForYScrollbar;
329
+ this.axis.y.isOverflowing = this.axis.y.isOverflowing && contentElScrollHeight > contentWrapperElOffsetHeight - offsetForXScrollbar;
330
+ this.axis.x.scrollbar.size = this.getScrollbarSize("x");
331
+ this.axis.y.scrollbar.size = this.getScrollbarSize("y");
332
+ this.axis.x.scrollbar.el.style.width = `${this.axis.x.scrollbar.size}px`;
333
+ this.axis.y.scrollbar.el.style.height = `${this.axis.y.scrollbar.size}px`;
334
+ this.positionScrollbar("x");
335
+ this.positionScrollbar("y");
336
+ this.toggleTrackVisibility("x");
337
+ this.toggleTrackVisibility("y");
338
+ }
339
+ /**
340
+ * Calculate scrollbar size
341
+ */
342
+ getScrollbarSize(axis = "y") {
343
+ if (!this.axis[axis].isOverflowing) return 0;
344
+ const contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
345
+ const trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
346
+ let scrollbarSize;
347
+ let scrollbarRatio = trackSize / contentSize;
348
+ scrollbarSize = Math.max(~~(scrollbarRatio * trackSize), this.options.scrollbarMinSize);
349
+ if (this.options.scrollbarMaxSize) scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
350
+ return scrollbarSize;
351
+ }
352
+ positionScrollbar(axis = "y") {
353
+ if (!this.axis[axis].isOverflowing) return;
354
+ const contentSize = this.contentWrapperEl[this.axis[axis].scrollSizeAttr];
355
+ const trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
356
+ const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
357
+ const scrollbar = this.axis[axis].scrollbar;
358
+ let scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
359
+ scrollOffset = axis === "x" && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
360
+ let scrollPourcent = scrollOffset / (contentSize - hostSize);
361
+ let handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
362
+ handleOffset = axis === "x" && this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
363
+ scrollbar.el.style.transform = axis === "x" ? `translate3d(${handleOffset}px, 0, 0)` : `translate3d(0, ${handleOffset}px, 0)`;
364
+ }
365
+ toggleTrackVisibility(axis = "y") {
366
+ const track = this.axis[axis].track.el;
367
+ const scrollbar = this.axis[axis].scrollbar.el;
368
+ if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
369
+ track.style.visibility = "visible";
370
+ this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "scroll";
371
+ } else {
372
+ track.style.visibility = "hidden";
373
+ this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "hidden";
374
+ }
375
+ if (this.axis[axis].isOverflowing) scrollbar.style.display = "block";
376
+ else scrollbar.style.display = "none";
377
+ }
378
+ hideNativeScrollbar() {
379
+ this.offsetEl.style[this.isRtl ? "left" : "right"] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? `-${this.scrollbarWidth}px` : 0;
380
+ this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? `-${this.scrollbarWidth}px` : 0;
381
+ }
382
+ /**
383
+ * On scroll event handling
384
+ */
385
+ onScroll = () => {
386
+ const elWindow = getElementWindow(this.el);
387
+ if (!this.scrollXTicking) {
388
+ elWindow.requestAnimationFrame(this.scrollX);
389
+ this.scrollXTicking = true;
390
+ }
391
+ if (!this.scrollYTicking) {
392
+ elWindow.requestAnimationFrame(this.scrollY);
393
+ this.scrollYTicking = true;
394
+ }
395
+ };
396
+ scrollX = () => {
397
+ if (this.axis.x.isOverflowing) {
398
+ this.showScrollbar("x");
399
+ this.positionScrollbar("x");
400
+ }
401
+ this.scrollXTicking = false;
402
+ };
403
+ scrollY = () => {
404
+ if (this.axis.y.isOverflowing) {
405
+ this.showScrollbar("y");
406
+ this.positionScrollbar("y");
407
+ }
408
+ this.scrollYTicking = false;
409
+ };
410
+ onMouseEnter = () => {
411
+ this.showScrollbar("x");
412
+ this.showScrollbar("y");
413
+ };
414
+ onMouseMove = (e) => {
415
+ this.mouseX = e.clientX;
416
+ this.mouseY = e.clientY;
417
+ if (this.axis.x.isOverflowing || this.axis.x.forceVisible) this.onMouseMoveForAxis("x");
418
+ if (this.axis.y.isOverflowing || this.axis.y.forceVisible) this.onMouseMoveForAxis("y");
419
+ };
420
+ onMouseMoveForAxis(axis = "y") {
421
+ this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
422
+ this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
423
+ if (this.isWithinBounds(this.axis[axis].scrollbar.rect)) this.axis[axis].scrollbar.el.classList.add(this.classNames.hover);
424
+ else this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
425
+ if (this.isWithinBounds(this.axis[axis].track.rect)) {
426
+ this.showScrollbar(axis);
427
+ this.axis[axis].track.el.classList.add(this.classNames.hover);
428
+ } else this.axis[axis].track.el.classList.remove(this.classNames.hover);
429
+ }
430
+ onMouseLeave = () => {
431
+ this.onMouseMove.cancel();
432
+ if (this.axis.x.isOverflowing || this.axis.x.forceVisible) this.onMouseLeaveForAxis("x");
433
+ if (this.axis.y.isOverflowing || this.axis.y.forceVisible) this.onMouseLeaveForAxis("y");
434
+ this.mouseX = -1;
435
+ this.mouseY = -1;
436
+ };
437
+ onMouseLeaveForAxis(axis = "y") {
438
+ this.axis[axis].track.el.classList.remove(this.classNames.hover);
439
+ this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
440
+ }
441
+ onWindowResize = () => {
442
+ this.scrollbarWidth = this.getScrollbarWidth();
443
+ this.hideNativeScrollbar();
444
+ };
445
+ /**
446
+ * Show scrollbar
447
+ */
448
+ showScrollbar(axis = "y") {
449
+ let scrollbar = this.axis[axis].scrollbar.el;
450
+ if (!this.axis[axis].isVisible) {
451
+ scrollbar.classList.add(this.classNames.visible);
452
+ this.axis[axis].isVisible = true;
453
+ }
454
+ if (this.options.autoHide) this.hideScrollbars();
455
+ }
456
+ /**
457
+ * Hide Scrollbar
458
+ */
459
+ hideScrollbars = () => {
460
+ this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
461
+ this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
462
+ if (!this.isWithinBounds(this.axis.y.track.rect)) {
463
+ this.axis.y.scrollbar.el.classList.remove(this.classNames.visible);
464
+ this.axis.y.isVisible = false;
465
+ }
466
+ if (!this.isWithinBounds(this.axis.x.track.rect)) {
467
+ this.axis.x.scrollbar.el.classList.remove(this.classNames.visible);
468
+ this.axis.x.isVisible = false;
469
+ }
470
+ };
471
+ onPointerEvent = (e) => {
472
+ let isWithinTrackXBounds, isWithinTrackYBounds;
473
+ this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
474
+ this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
475
+ if (this.axis.x.isOverflowing || this.axis.x.forceVisible) isWithinTrackXBounds = this.isWithinBounds(this.axis.x.track.rect);
476
+ if (this.axis.y.isOverflowing || this.axis.y.forceVisible) isWithinTrackYBounds = this.isWithinBounds(this.axis.y.track.rect);
477
+ if (isWithinTrackXBounds || isWithinTrackYBounds) {
478
+ e.preventDefault();
479
+ e.stopPropagation();
480
+ if (e.type === "mousedown") {
481
+ if (isWithinTrackXBounds) {
482
+ this.axis.x.scrollbar.rect = this.axis.x.scrollbar.el.getBoundingClientRect();
483
+ if (this.isWithinBounds(this.axis.x.scrollbar.rect)) this.onDragStart(e, "x");
484
+ else this.onTrackClick(e, "x");
485
+ }
486
+ if (isWithinTrackYBounds) {
487
+ this.axis.y.scrollbar.rect = this.axis.y.scrollbar.el.getBoundingClientRect();
488
+ if (this.isWithinBounds(this.axis.y.scrollbar.rect)) this.onDragStart(e, "y");
489
+ else this.onTrackClick(e, "y");
490
+ }
491
+ }
492
+ }
493
+ };
494
+ /**
495
+ * on scrollbar handle drag movement starts
496
+ */
497
+ onDragStart(e, axis = "y") {
498
+ const elDocument = getElementDocument(this.el);
499
+ const elWindow = getElementWindow(this.el);
500
+ const scrollbar = this.axis[axis].scrollbar;
501
+ const eventOffset = axis === "y" ? e.pageY : e.pageX;
502
+ this.axis[axis].dragOffset = eventOffset - scrollbar.rect[this.axis[axis].offsetAttr];
503
+ this.draggedAxis = axis;
504
+ this.el.classList.add(this.classNames.dragging);
505
+ elDocument.addEventListener("mousemove", this.drag, true);
506
+ elDocument.addEventListener("mouseup", this.onEndDrag, true);
507
+ if (this.removePreventClickId === null) {
508
+ elDocument.addEventListener("click", this.preventClick, true);
509
+ elDocument.addEventListener("dblclick", this.preventClick, true);
510
+ } else {
511
+ elWindow.clearTimeout(this.removePreventClickId);
512
+ this.removePreventClickId = null;
513
+ }
514
+ }
515
+ /**
516
+ * Drag scrollbar handle
517
+ */
518
+ drag = (e) => {
519
+ let eventOffset;
520
+ const track = this.axis[this.draggedAxis].track;
521
+ const trackSize = track.rect[this.axis[this.draggedAxis].sizeAttr];
522
+ const scrollbar = this.axis[this.draggedAxis].scrollbar;
523
+ const contentSize = this.contentWrapperEl[this.axis[this.draggedAxis].scrollSizeAttr];
524
+ const hostSize = parseInt(this.elStyles[this.axis[this.draggedAxis].sizeAttr], 10);
525
+ e.preventDefault();
526
+ e.stopPropagation();
527
+ if (this.draggedAxis === "y") eventOffset = e.pageY;
528
+ else eventOffset = e.pageX;
529
+ let scrollPos = (eventOffset - track.rect[this.axis[this.draggedAxis].offsetAttr] - this.axis[this.draggedAxis].dragOffset) / (trackSize - scrollbar.size) * (contentSize - hostSize);
530
+ if (this.draggedAxis === "x") {
531
+ scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
532
+ scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
533
+ }
534
+ this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
535
+ };
536
+ /**
537
+ * End scroll handle drag
538
+ */
539
+ onEndDrag = (e) => {
540
+ const elDocument = getElementDocument(this.el);
541
+ const elWindow = getElementWindow(this.el);
542
+ e.preventDefault();
543
+ e.stopPropagation();
544
+ this.el.classList.remove(this.classNames.dragging);
545
+ elDocument.removeEventListener("mousemove", this.drag, true);
546
+ elDocument.removeEventListener("mouseup", this.onEndDrag, true);
547
+ this.removePreventClickId = elWindow.setTimeout(() => {
548
+ elDocument.removeEventListener("click", this.preventClick, true);
549
+ elDocument.removeEventListener("dblclick", this.preventClick, true);
550
+ this.removePreventClickId = null;
551
+ });
552
+ };
553
+ /**
554
+ * Handler to ignore click events during drag
555
+ */
556
+ preventClick = (e) => {
557
+ e.preventDefault();
558
+ e.stopPropagation();
559
+ };
560
+ onTrackClick(e, axis = "y") {
561
+ if (!this.options.clickOnTrack) return;
562
+ const elWindow = getElementWindow(this.el);
563
+ this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
564
+ const scrollbarOffset = this.axis[axis].scrollbar.rect[this.axis[axis].offsetAttr];
565
+ const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
566
+ let scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
567
+ const dir = (axis === "y" ? this.mouseY - scrollbarOffset : this.mouseX - scrollbarOffset) < 0 ? -1 : 1;
568
+ const scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize;
569
+ const scrollTo = () => {
570
+ if (dir === -1) {
571
+ if (scrolled > scrollSize) {
572
+ scrolled -= this.options.clickOnTrackSpeed;
573
+ this.contentWrapperEl.scrollTo({ [this.axis[axis].offsetAttr]: scrolled });
574
+ elWindow.requestAnimationFrame(scrollTo);
575
+ }
576
+ } else if (scrolled < scrollSize) {
577
+ scrolled += this.options.clickOnTrackSpeed;
578
+ this.contentWrapperEl.scrollTo({ [this.axis[axis].offsetAttr]: scrolled });
579
+ elWindow.requestAnimationFrame(scrollTo);
580
+ }
581
+ };
582
+ scrollTo();
583
+ }
584
+ /**
585
+ * Getter for content element
586
+ */
587
+ getContentElement() {
588
+ return this.contentEl;
589
+ }
590
+ /**
591
+ * Getter for original scrolling element
592
+ */
593
+ getScrollElement() {
594
+ return this.contentWrapperEl;
595
+ }
596
+ getScrollbarWidth() {
597
+ try {
598
+ if (getComputedStyle(this.contentWrapperEl, "::-webkit-scrollbar").display === "none" || "scrollbarWidth" in document.documentElement.style || "-ms-overflow-style" in document.documentElement.style) return 0;
599
+ else return scrollbarWidth(this.el);
600
+ } catch (e) {
601
+ return scrollbarWidth(this.el);
602
+ }
603
+ }
604
+ removeListeners() {
605
+ const elWindow = getElementWindow(this.el);
606
+ if (this.options.autoHide) this.el.removeEventListener("mouseenter", this.onMouseEnter);
607
+ [
608
+ "mousedown",
609
+ "click",
610
+ "dblclick"
611
+ ].forEach((e) => {
612
+ this.el.removeEventListener(e, this.onPointerEvent, true);
613
+ });
614
+ [
615
+ "touchstart",
616
+ "touchend",
617
+ "touchmove"
618
+ ].forEach((e) => {
619
+ this.el.removeEventListener(e, this.onPointerEvent, {
620
+ capture: true,
621
+ passive: true
622
+ });
623
+ });
624
+ this.el.removeEventListener("mousemove", this.onMouseMove);
625
+ this.el.removeEventListener("mouseleave", this.onMouseLeave);
626
+ if (this.contentWrapperEl) this.contentWrapperEl.removeEventListener("scroll", this.onScroll);
627
+ elWindow.removeEventListener("resize", this.onWindowResize);
628
+ if (this.mutationObserver) this.mutationObserver.disconnect();
629
+ if (this.resizeObserver) this.resizeObserver.disconnect();
630
+ this.recalculate.cancel();
631
+ this.onMouseMove.cancel();
632
+ this.hideScrollbars.cancel();
633
+ this.onWindowResize.cancel();
634
+ }
635
+ /**
636
+ * UnMount mutation observer and delete SimpleBar instance from DOM element
637
+ */
638
+ unMount() {
639
+ this.removeListeners();
640
+ SimpleBar.instances.delete(this.el);
641
+ }
642
+ /**
643
+ * Check if mouse is within bounds
644
+ */
645
+ isWithinBounds(bbox) {
646
+ return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
647
+ }
648
+ /**
649
+ * Find element children matches query
650
+ */
651
+ findChild(el, query) {
652
+ const matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
653
+ return Array.prototype.filter.call(el.children, (child) => matches.call(child, query))[0];
654
+ }
655
+ };
656
+ //#endregion
733
657
  module.exports = SimpleBar;