@karta.io/simplebar 1.0.0-beta.5 → 1.0.0-beta.51

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