@karta.io/simplebar 0.16.0

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