@karta.io/simplebar 1.0.0-beta.49 → 1.0.0-beta.5
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/dist/simplebar.cjs +212 -202
- package/dist/simplebar.d.cts +1 -1
- package/dist/simplebar.d.ts +1 -1
- package/dist/simplebar.mjs +212 -202
- package/package.json +4 -4
package/dist/simplebar.cjs
CHANGED
|
@@ -12,6 +12,7 @@ const debounce__default = /*#__PURE__*/_interopDefaultCompat(debounce);
|
|
|
12
12
|
const memoize__default = /*#__PURE__*/_interopDefaultCompat(memoize);
|
|
13
13
|
|
|
14
14
|
const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
15
|
+
const canUseDOM$1 = canUseDOM;
|
|
15
16
|
|
|
16
17
|
function getElementWindow(element) {
|
|
17
18
|
if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
|
|
@@ -28,7 +29,7 @@ function getElementDocument(element) {
|
|
|
28
29
|
|
|
29
30
|
let cachedScrollbarWidth = null;
|
|
30
31
|
let cachedDevicePixelRatio = null;
|
|
31
|
-
if (canUseDOM) {
|
|
32
|
+
if (canUseDOM$1) {
|
|
32
33
|
window.addEventListener("resize", () => {
|
|
33
34
|
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
|
|
34
35
|
cachedDevicePixelRatio = window.devicePixelRatio;
|
|
@@ -54,13 +55,177 @@ function scrollbarWidth(el) {
|
|
|
54
55
|
return cachedScrollbarWidth;
|
|
55
56
|
}
|
|
56
57
|
|
|
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 {
|
|
58
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
|
+
});
|
|
59
224
|
this.el = element;
|
|
60
225
|
this.minScrollbarWidth = 20;
|
|
61
|
-
this.options = { ...
|
|
226
|
+
this.options = { ..._SimpleBar.defaultOptions, ...options };
|
|
62
227
|
this.classNames = {
|
|
63
|
-
...
|
|
228
|
+
..._SimpleBar.defaultOptions.classNames,
|
|
64
229
|
...this.options.classNames
|
|
65
230
|
};
|
|
66
231
|
this.axis = {
|
|
@@ -94,7 +259,7 @@ class SimpleBar {
|
|
|
94
259
|
}
|
|
95
260
|
};
|
|
96
261
|
this.removePreventClickId = null;
|
|
97
|
-
if (
|
|
262
|
+
if (_SimpleBar.instances.has(this.el)) {
|
|
98
263
|
return;
|
|
99
264
|
}
|
|
100
265
|
this.recalculate = throttle__default(this.recalculate.bind(this), 64);
|
|
@@ -106,7 +271,7 @@ class SimpleBar {
|
|
|
106
271
|
this.onWindowResize = debounce__default(this.onWindowResize.bind(this), 64, {
|
|
107
272
|
leading: true
|
|
108
273
|
});
|
|
109
|
-
|
|
274
|
+
_SimpleBar.getRtlHelpers = memoize__default(_SimpleBar.getRtlHelpers);
|
|
110
275
|
this.init();
|
|
111
276
|
}
|
|
112
277
|
/**
|
|
@@ -125,10 +290,10 @@ class SimpleBar {
|
|
|
125
290
|
document.body.appendChild(scrollbarDummyEl);
|
|
126
291
|
const dummyContainerChild = scrollbarDummyEl.firstElementChild;
|
|
127
292
|
scrollbarDummyEl.scrollLeft = 0;
|
|
128
|
-
const dummyContainerOffset =
|
|
129
|
-
const dummyContainerChildOffset =
|
|
293
|
+
const dummyContainerOffset = _SimpleBar.getOffset(scrollbarDummyEl);
|
|
294
|
+
const dummyContainerChildOffset = _SimpleBar.getOffset(dummyContainerChild);
|
|
130
295
|
scrollbarDummyEl.scrollLeft = 999;
|
|
131
|
-
const dummyContainerScrollOffsetAfterScroll =
|
|
296
|
+
const dummyContainerScrollOffsetAfterScroll = _SimpleBar.getOffset(
|
|
132
297
|
dummyContainerChild
|
|
133
298
|
);
|
|
134
299
|
return {
|
|
@@ -138,32 +303,6 @@ class SimpleBar {
|
|
|
138
303
|
isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
|
|
139
304
|
};
|
|
140
305
|
}
|
|
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
306
|
static getOffset(el) {
|
|
168
307
|
const rect = el.getBoundingClientRect();
|
|
169
308
|
const elDocument = getElementDocument(el);
|
|
@@ -173,10 +312,9 @@ class SimpleBar {
|
|
|
173
312
|
left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
|
|
174
313
|
};
|
|
175
314
|
}
|
|
176
|
-
static instances = /* @__PURE__ */ new WeakMap();
|
|
177
315
|
init() {
|
|
178
|
-
|
|
179
|
-
if (canUseDOM) {
|
|
316
|
+
_SimpleBar.instances.set(this.el, this);
|
|
317
|
+
if (canUseDOM$1) {
|
|
180
318
|
this.initDOM();
|
|
181
319
|
this.setAccessibilityAttributes();
|
|
182
320
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
@@ -297,7 +435,8 @@ class SimpleBar {
|
|
|
297
435
|
let resizeObserverStarted = false;
|
|
298
436
|
const resizeObserver$1 = elWindow.ResizeObserver || resizeObserver.ResizeObserver;
|
|
299
437
|
this.resizeObserver = new resizeObserver$1(() => {
|
|
300
|
-
if (!resizeObserverStarted)
|
|
438
|
+
if (!resizeObserverStarted)
|
|
439
|
+
return;
|
|
301
440
|
this.recalculate();
|
|
302
441
|
});
|
|
303
442
|
this.resizeObserver.observe(this.el);
|
|
@@ -379,10 +518,10 @@ class SimpleBar {
|
|
|
379
518
|
const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
|
|
380
519
|
const scrollbar = this.axis[axis].scrollbar;
|
|
381
520
|
let scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
|
|
382
|
-
scrollOffset = axis === "x" && this.isRtl &&
|
|
521
|
+
scrollOffset = axis === "x" && this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
|
|
383
522
|
let scrollPourcent = scrollOffset / (contentSize - hostSize);
|
|
384
523
|
let handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
|
|
385
|
-
handleOffset = axis === "x" && this.isRtl &&
|
|
524
|
+
handleOffset = axis === "x" && this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
|
|
386
525
|
scrollbar.el.style.transform = axis === "x" ? `translate3d(${handleOffset}px, 0, 0)` : `translate3d(0, ${handleOffset}px, 0)`;
|
|
387
526
|
}
|
|
388
527
|
toggleTrackVisibility(axis = "y") {
|
|
@@ -405,48 +544,6 @@ class SimpleBar {
|
|
|
405
544
|
this.offsetEl.style[this.isRtl ? "left" : "right"] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? `-${this.scrollbarWidth}px` : 0;
|
|
406
545
|
this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? `-${this.scrollbarWidth}px` : 0;
|
|
407
546
|
}
|
|
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
547
|
onMouseMoveForAxis(axis = "y") {
|
|
451
548
|
this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
|
|
452
549
|
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
|
|
@@ -465,25 +562,10 @@ class SimpleBar {
|
|
|
465
562
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
466
563
|
}
|
|
467
564
|
}
|
|
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
565
|
onMouseLeaveForAxis(axis = "y") {
|
|
480
566
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
481
567
|
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
|
|
482
568
|
}
|
|
483
|
-
onWindowResize = () => {
|
|
484
|
-
this.scrollbarWidth = this.getScrollbarWidth();
|
|
485
|
-
this.hideNativeScrollbar();
|
|
486
|
-
};
|
|
487
569
|
/**
|
|
488
570
|
* Show scrollbar
|
|
489
571
|
*/
|
|
@@ -497,54 +579,6 @@ class SimpleBar {
|
|
|
497
579
|
this.hideScrollbars();
|
|
498
580
|
}
|
|
499
581
|
}
|
|
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
582
|
/**
|
|
549
583
|
* on scrollbar handle drag movement starts
|
|
550
584
|
*/
|
|
@@ -566,61 +600,9 @@ class SimpleBar {
|
|
|
566
600
|
this.removePreventClickId = null;
|
|
567
601
|
}
|
|
568
602
|
}
|
|
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
603
|
onTrackClick(e, axis = "y") {
|
|
623
|
-
if (!this.options.clickOnTrack)
|
|
604
|
+
if (!this.options.clickOnTrack)
|
|
605
|
+
return;
|
|
624
606
|
const elWindow = getElementWindow(this.el);
|
|
625
607
|
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
|
|
626
608
|
const scrollbar = this.axis[axis].scrollbar;
|
|
@@ -710,7 +692,7 @@ class SimpleBar {
|
|
|
710
692
|
*/
|
|
711
693
|
unMount() {
|
|
712
694
|
this.removeListeners();
|
|
713
|
-
|
|
695
|
+
_SimpleBar.instances.delete(this.el);
|
|
714
696
|
}
|
|
715
697
|
/**
|
|
716
698
|
* Check if mouse is within bounds
|
|
@@ -728,6 +710,34 @@ class SimpleBar {
|
|
|
728
710
|
(child) => matches.call(child, query)
|
|
729
711
|
)[0];
|
|
730
712
|
}
|
|
731
|
-
}
|
|
713
|
+
};
|
|
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;
|
|
732
742
|
|
|
733
743
|
module.exports = SimpleBar;
|
package/dist/simplebar.d.cts
CHANGED
package/dist/simplebar.d.ts
CHANGED
package/dist/simplebar.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import memoize from 'lodash/memoize.js';
|
|
|
4
4
|
import { ResizeObserver } from '@juggle/resize-observer';
|
|
5
5
|
|
|
6
6
|
const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
7
|
+
const canUseDOM$1 = canUseDOM;
|
|
7
8
|
|
|
8
9
|
function getElementWindow(element) {
|
|
9
10
|
if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
|
|
@@ -20,7 +21,7 @@ function getElementDocument(element) {
|
|
|
20
21
|
|
|
21
22
|
let cachedScrollbarWidth = null;
|
|
22
23
|
let cachedDevicePixelRatio = null;
|
|
23
|
-
if (canUseDOM) {
|
|
24
|
+
if (canUseDOM$1) {
|
|
24
25
|
window.addEventListener("resize", () => {
|
|
25
26
|
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
|
|
26
27
|
cachedDevicePixelRatio = window.devicePixelRatio;
|
|
@@ -46,13 +47,177 @@ function scrollbarWidth(el) {
|
|
|
46
47
|
return cachedScrollbarWidth;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
var __defProp = Object.defineProperty;
|
|
51
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
52
|
+
var __publicField = (obj, key, value) => {
|
|
53
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
const _SimpleBar = class _SimpleBar {
|
|
50
57
|
constructor(element, options) {
|
|
58
|
+
/**
|
|
59
|
+
* On scroll event handling
|
|
60
|
+
*/
|
|
61
|
+
__publicField(this, "onScroll", () => {
|
|
62
|
+
const elWindow = getElementWindow(this.el);
|
|
63
|
+
if (!this.scrollXTicking) {
|
|
64
|
+
elWindow.requestAnimationFrame(this.scrollX);
|
|
65
|
+
this.scrollXTicking = true;
|
|
66
|
+
}
|
|
67
|
+
if (!this.scrollYTicking) {
|
|
68
|
+
elWindow.requestAnimationFrame(this.scrollY);
|
|
69
|
+
this.scrollYTicking = true;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
__publicField(this, "scrollX", () => {
|
|
73
|
+
if (this.axis.x.isOverflowing) {
|
|
74
|
+
this.showScrollbar("x");
|
|
75
|
+
this.positionScrollbar("x");
|
|
76
|
+
}
|
|
77
|
+
this.scrollXTicking = false;
|
|
78
|
+
});
|
|
79
|
+
__publicField(this, "scrollY", () => {
|
|
80
|
+
if (this.axis.y.isOverflowing) {
|
|
81
|
+
this.showScrollbar("y");
|
|
82
|
+
this.positionScrollbar("y");
|
|
83
|
+
}
|
|
84
|
+
this.scrollYTicking = false;
|
|
85
|
+
});
|
|
86
|
+
__publicField(this, "onMouseEnter", () => {
|
|
87
|
+
this.showScrollbar("x");
|
|
88
|
+
this.showScrollbar("y");
|
|
89
|
+
});
|
|
90
|
+
__publicField(this, "onMouseMove", (e) => {
|
|
91
|
+
this.mouseX = e.clientX;
|
|
92
|
+
this.mouseY = e.clientY;
|
|
93
|
+
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
94
|
+
this.onMouseMoveForAxis("x");
|
|
95
|
+
}
|
|
96
|
+
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
97
|
+
this.onMouseMoveForAxis("y");
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
__publicField(this, "onMouseLeave", () => {
|
|
101
|
+
this.onMouseMove.cancel();
|
|
102
|
+
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
103
|
+
this.onMouseLeaveForAxis("x");
|
|
104
|
+
}
|
|
105
|
+
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
106
|
+
this.onMouseLeaveForAxis("y");
|
|
107
|
+
}
|
|
108
|
+
this.mouseX = -1;
|
|
109
|
+
this.mouseY = -1;
|
|
110
|
+
});
|
|
111
|
+
__publicField(this, "onWindowResize", () => {
|
|
112
|
+
this.scrollbarWidth = this.getScrollbarWidth();
|
|
113
|
+
this.hideNativeScrollbar();
|
|
114
|
+
});
|
|
115
|
+
/**
|
|
116
|
+
* Hide Scrollbar
|
|
117
|
+
*/
|
|
118
|
+
__publicField(this, "hideScrollbars", () => {
|
|
119
|
+
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
120
|
+
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
121
|
+
if (!this.isWithinBounds(this.axis.y.track.rect)) {
|
|
122
|
+
this.axis.y.scrollbar.el.classList.remove(this.classNames.visible);
|
|
123
|
+
this.axis.y.isVisible = false;
|
|
124
|
+
}
|
|
125
|
+
if (!this.isWithinBounds(this.axis.x.track.rect)) {
|
|
126
|
+
this.axis.x.scrollbar.el.classList.remove(this.classNames.visible);
|
|
127
|
+
this.axis.x.isVisible = false;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
__publicField(this, "onPointerEvent", (e) => {
|
|
131
|
+
let isWithinTrackXBounds, isWithinTrackYBounds;
|
|
132
|
+
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
133
|
+
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
134
|
+
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
135
|
+
isWithinTrackXBounds = this.isWithinBounds(this.axis.x.track.rect);
|
|
136
|
+
}
|
|
137
|
+
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
138
|
+
isWithinTrackYBounds = this.isWithinBounds(this.axis.y.track.rect);
|
|
139
|
+
}
|
|
140
|
+
if (isWithinTrackXBounds || isWithinTrackYBounds) {
|
|
141
|
+
e.preventDefault();
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
if (e.type === "mousedown") {
|
|
144
|
+
if (isWithinTrackXBounds) {
|
|
145
|
+
this.axis.x.scrollbar.rect = this.axis.x.scrollbar.el.getBoundingClientRect();
|
|
146
|
+
if (this.isWithinBounds(this.axis.x.scrollbar.rect)) {
|
|
147
|
+
this.onDragStart(e, "x");
|
|
148
|
+
} else {
|
|
149
|
+
this.onTrackClick(e, "x");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (isWithinTrackYBounds) {
|
|
153
|
+
this.axis.y.scrollbar.rect = this.axis.y.scrollbar.el.getBoundingClientRect();
|
|
154
|
+
if (this.isWithinBounds(this.axis.y.scrollbar.rect)) {
|
|
155
|
+
this.onDragStart(e, "y");
|
|
156
|
+
} else {
|
|
157
|
+
this.onTrackClick(e, "y");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
/**
|
|
164
|
+
* Drag scrollbar handle
|
|
165
|
+
*/
|
|
166
|
+
__publicField(this, "drag", (e) => {
|
|
167
|
+
let eventOffset;
|
|
168
|
+
const track = this.axis[this.draggedAxis].track;
|
|
169
|
+
const trackSize = track.rect[this.axis[this.draggedAxis].sizeAttr];
|
|
170
|
+
const scrollbar = this.axis[this.draggedAxis].scrollbar;
|
|
171
|
+
const contentSize = this.contentWrapperEl[this.axis[this.draggedAxis].scrollSizeAttr];
|
|
172
|
+
const hostSize = parseInt(
|
|
173
|
+
this.elStyles[this.axis[this.draggedAxis].sizeAttr],
|
|
174
|
+
10
|
|
175
|
+
);
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
e.stopPropagation();
|
|
178
|
+
if (this.draggedAxis === "y") {
|
|
179
|
+
eventOffset = e.pageY;
|
|
180
|
+
} else {
|
|
181
|
+
eventOffset = e.pageX;
|
|
182
|
+
}
|
|
183
|
+
let dragPos = eventOffset - track.rect[this.axis[this.draggedAxis].offsetAttr] - this.axis[this.draggedAxis].dragOffset;
|
|
184
|
+
let dragPerc = dragPos / (trackSize - scrollbar.size);
|
|
185
|
+
let scrollPos = dragPerc * (contentSize - hostSize);
|
|
186
|
+
if (this.draggedAxis === "x") {
|
|
187
|
+
scrollPos = this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
|
|
188
|
+
scrollPos = this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
|
|
189
|
+
}
|
|
190
|
+
this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* End scroll handle drag
|
|
194
|
+
*/
|
|
195
|
+
__publicField(this, "onEndDrag", (e) => {
|
|
196
|
+
const elDocument = getElementDocument(this.el);
|
|
197
|
+
const elWindow = getElementWindow(this.el);
|
|
198
|
+
e.preventDefault();
|
|
199
|
+
e.stopPropagation();
|
|
200
|
+
this.el.classList.remove(this.classNames.dragging);
|
|
201
|
+
elDocument.removeEventListener("mousemove", this.drag, true);
|
|
202
|
+
elDocument.removeEventListener("mouseup", this.onEndDrag, true);
|
|
203
|
+
this.removePreventClickId = elWindow.setTimeout(() => {
|
|
204
|
+
elDocument.removeEventListener("click", this.preventClick, true);
|
|
205
|
+
elDocument.removeEventListener("dblclick", this.preventClick, true);
|
|
206
|
+
this.removePreventClickId = null;
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
/**
|
|
210
|
+
* Handler to ignore click events during drag
|
|
211
|
+
*/
|
|
212
|
+
__publicField(this, "preventClick", (e) => {
|
|
213
|
+
e.preventDefault();
|
|
214
|
+
e.stopPropagation();
|
|
215
|
+
});
|
|
51
216
|
this.el = element;
|
|
52
217
|
this.minScrollbarWidth = 20;
|
|
53
|
-
this.options = { ...
|
|
218
|
+
this.options = { ..._SimpleBar.defaultOptions, ...options };
|
|
54
219
|
this.classNames = {
|
|
55
|
-
...
|
|
220
|
+
..._SimpleBar.defaultOptions.classNames,
|
|
56
221
|
...this.options.classNames
|
|
57
222
|
};
|
|
58
223
|
this.axis = {
|
|
@@ -86,7 +251,7 @@ class SimpleBar {
|
|
|
86
251
|
}
|
|
87
252
|
};
|
|
88
253
|
this.removePreventClickId = null;
|
|
89
|
-
if (
|
|
254
|
+
if (_SimpleBar.instances.has(this.el)) {
|
|
90
255
|
return;
|
|
91
256
|
}
|
|
92
257
|
this.recalculate = throttle(this.recalculate.bind(this), 64);
|
|
@@ -98,7 +263,7 @@ class SimpleBar {
|
|
|
98
263
|
this.onWindowResize = debounce(this.onWindowResize.bind(this), 64, {
|
|
99
264
|
leading: true
|
|
100
265
|
});
|
|
101
|
-
|
|
266
|
+
_SimpleBar.getRtlHelpers = memoize(_SimpleBar.getRtlHelpers);
|
|
102
267
|
this.init();
|
|
103
268
|
}
|
|
104
269
|
/**
|
|
@@ -117,10 +282,10 @@ class SimpleBar {
|
|
|
117
282
|
document.body.appendChild(scrollbarDummyEl);
|
|
118
283
|
const dummyContainerChild = scrollbarDummyEl.firstElementChild;
|
|
119
284
|
scrollbarDummyEl.scrollLeft = 0;
|
|
120
|
-
const dummyContainerOffset =
|
|
121
|
-
const dummyContainerChildOffset =
|
|
285
|
+
const dummyContainerOffset = _SimpleBar.getOffset(scrollbarDummyEl);
|
|
286
|
+
const dummyContainerChildOffset = _SimpleBar.getOffset(dummyContainerChild);
|
|
122
287
|
scrollbarDummyEl.scrollLeft = 999;
|
|
123
|
-
const dummyContainerScrollOffsetAfterScroll =
|
|
288
|
+
const dummyContainerScrollOffsetAfterScroll = _SimpleBar.getOffset(
|
|
124
289
|
dummyContainerChild
|
|
125
290
|
);
|
|
126
291
|
return {
|
|
@@ -130,32 +295,6 @@ class SimpleBar {
|
|
|
130
295
|
isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
|
|
131
296
|
};
|
|
132
297
|
}
|
|
133
|
-
static defaultOptions = {
|
|
134
|
-
autoHide: true,
|
|
135
|
-
forceVisible: false,
|
|
136
|
-
clickOnTrack: true,
|
|
137
|
-
clickOnTrackSpeed: 40,
|
|
138
|
-
classNames: {
|
|
139
|
-
contentEl: "simplebar-content",
|
|
140
|
-
contentWrapper: "simplebar-content-wrapper",
|
|
141
|
-
offset: "simplebar-offset",
|
|
142
|
-
mask: "simplebar-mask",
|
|
143
|
-
wrapper: "simplebar-wrapper",
|
|
144
|
-
placeholder: "simplebar-placeholder",
|
|
145
|
-
scrollbar: "simplebar-scrollbar",
|
|
146
|
-
track: "simplebar-track",
|
|
147
|
-
heightAutoObserverWrapperEl: "simplebar-height-auto-observer-wrapper",
|
|
148
|
-
heightAutoObserverEl: "simplebar-height-auto-observer",
|
|
149
|
-
visible: "simplebar-visible",
|
|
150
|
-
horizontal: "simplebar-horizontal",
|
|
151
|
-
vertical: "simplebar-vertical",
|
|
152
|
-
hover: "simplebar-hover",
|
|
153
|
-
dragging: "simplebar-dragging"
|
|
154
|
-
},
|
|
155
|
-
scrollbarMinSize: 25,
|
|
156
|
-
scrollbarMaxSize: 0,
|
|
157
|
-
timeout: 1e3
|
|
158
|
-
};
|
|
159
298
|
static getOffset(el) {
|
|
160
299
|
const rect = el.getBoundingClientRect();
|
|
161
300
|
const elDocument = getElementDocument(el);
|
|
@@ -165,10 +304,9 @@ class SimpleBar {
|
|
|
165
304
|
left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
|
|
166
305
|
};
|
|
167
306
|
}
|
|
168
|
-
static instances = /* @__PURE__ */ new WeakMap();
|
|
169
307
|
init() {
|
|
170
|
-
|
|
171
|
-
if (canUseDOM) {
|
|
308
|
+
_SimpleBar.instances.set(this.el, this);
|
|
309
|
+
if (canUseDOM$1) {
|
|
172
310
|
this.initDOM();
|
|
173
311
|
this.setAccessibilityAttributes();
|
|
174
312
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
@@ -289,7 +427,8 @@ class SimpleBar {
|
|
|
289
427
|
let resizeObserverStarted = false;
|
|
290
428
|
const resizeObserver = elWindow.ResizeObserver || ResizeObserver;
|
|
291
429
|
this.resizeObserver = new resizeObserver(() => {
|
|
292
|
-
if (!resizeObserverStarted)
|
|
430
|
+
if (!resizeObserverStarted)
|
|
431
|
+
return;
|
|
293
432
|
this.recalculate();
|
|
294
433
|
});
|
|
295
434
|
this.resizeObserver.observe(this.el);
|
|
@@ -371,10 +510,10 @@ class SimpleBar {
|
|
|
371
510
|
const hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
|
|
372
511
|
const scrollbar = this.axis[axis].scrollbar;
|
|
373
512
|
let scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
|
|
374
|
-
scrollOffset = axis === "x" && this.isRtl &&
|
|
513
|
+
scrollOffset = axis === "x" && this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
|
|
375
514
|
let scrollPourcent = scrollOffset / (contentSize - hostSize);
|
|
376
515
|
let handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
|
|
377
|
-
handleOffset = axis === "x" && this.isRtl &&
|
|
516
|
+
handleOffset = axis === "x" && this.isRtl && _SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
|
|
378
517
|
scrollbar.el.style.transform = axis === "x" ? `translate3d(${handleOffset}px, 0, 0)` : `translate3d(0, ${handleOffset}px, 0)`;
|
|
379
518
|
}
|
|
380
519
|
toggleTrackVisibility(axis = "y") {
|
|
@@ -397,48 +536,6 @@ class SimpleBar {
|
|
|
397
536
|
this.offsetEl.style[this.isRtl ? "left" : "right"] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? `-${this.scrollbarWidth}px` : 0;
|
|
398
537
|
this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? `-${this.scrollbarWidth}px` : 0;
|
|
399
538
|
}
|
|
400
|
-
/**
|
|
401
|
-
* On scroll event handling
|
|
402
|
-
*/
|
|
403
|
-
onScroll = () => {
|
|
404
|
-
const elWindow = getElementWindow(this.el);
|
|
405
|
-
if (!this.scrollXTicking) {
|
|
406
|
-
elWindow.requestAnimationFrame(this.scrollX);
|
|
407
|
-
this.scrollXTicking = true;
|
|
408
|
-
}
|
|
409
|
-
if (!this.scrollYTicking) {
|
|
410
|
-
elWindow.requestAnimationFrame(this.scrollY);
|
|
411
|
-
this.scrollYTicking = true;
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
scrollX = () => {
|
|
415
|
-
if (this.axis.x.isOverflowing) {
|
|
416
|
-
this.showScrollbar("x");
|
|
417
|
-
this.positionScrollbar("x");
|
|
418
|
-
}
|
|
419
|
-
this.scrollXTicking = false;
|
|
420
|
-
};
|
|
421
|
-
scrollY = () => {
|
|
422
|
-
if (this.axis.y.isOverflowing) {
|
|
423
|
-
this.showScrollbar("y");
|
|
424
|
-
this.positionScrollbar("y");
|
|
425
|
-
}
|
|
426
|
-
this.scrollYTicking = false;
|
|
427
|
-
};
|
|
428
|
-
onMouseEnter = () => {
|
|
429
|
-
this.showScrollbar("x");
|
|
430
|
-
this.showScrollbar("y");
|
|
431
|
-
};
|
|
432
|
-
onMouseMove = (e) => {
|
|
433
|
-
this.mouseX = e.clientX;
|
|
434
|
-
this.mouseY = e.clientY;
|
|
435
|
-
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
436
|
-
this.onMouseMoveForAxis("x");
|
|
437
|
-
}
|
|
438
|
-
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
439
|
-
this.onMouseMoveForAxis("y");
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
539
|
onMouseMoveForAxis(axis = "y") {
|
|
443
540
|
this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
|
|
444
541
|
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
|
|
@@ -457,25 +554,10 @@ class SimpleBar {
|
|
|
457
554
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
458
555
|
}
|
|
459
556
|
}
|
|
460
|
-
onMouseLeave = () => {
|
|
461
|
-
this.onMouseMove.cancel();
|
|
462
|
-
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
463
|
-
this.onMouseLeaveForAxis("x");
|
|
464
|
-
}
|
|
465
|
-
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
466
|
-
this.onMouseLeaveForAxis("y");
|
|
467
|
-
}
|
|
468
|
-
this.mouseX = -1;
|
|
469
|
-
this.mouseY = -1;
|
|
470
|
-
};
|
|
471
557
|
onMouseLeaveForAxis(axis = "y") {
|
|
472
558
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
473
559
|
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
|
|
474
560
|
}
|
|
475
|
-
onWindowResize = () => {
|
|
476
|
-
this.scrollbarWidth = this.getScrollbarWidth();
|
|
477
|
-
this.hideNativeScrollbar();
|
|
478
|
-
};
|
|
479
561
|
/**
|
|
480
562
|
* Show scrollbar
|
|
481
563
|
*/
|
|
@@ -489,54 +571,6 @@ class SimpleBar {
|
|
|
489
571
|
this.hideScrollbars();
|
|
490
572
|
}
|
|
491
573
|
}
|
|
492
|
-
/**
|
|
493
|
-
* Hide Scrollbar
|
|
494
|
-
*/
|
|
495
|
-
hideScrollbars = () => {
|
|
496
|
-
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
497
|
-
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
498
|
-
if (!this.isWithinBounds(this.axis.y.track.rect)) {
|
|
499
|
-
this.axis.y.scrollbar.el.classList.remove(this.classNames.visible);
|
|
500
|
-
this.axis.y.isVisible = false;
|
|
501
|
-
}
|
|
502
|
-
if (!this.isWithinBounds(this.axis.x.track.rect)) {
|
|
503
|
-
this.axis.x.scrollbar.el.classList.remove(this.classNames.visible);
|
|
504
|
-
this.axis.x.isVisible = false;
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
onPointerEvent = (e) => {
|
|
508
|
-
let isWithinTrackXBounds, isWithinTrackYBounds;
|
|
509
|
-
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
510
|
-
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
511
|
-
if (this.axis.x.isOverflowing || this.axis.x.forceVisible) {
|
|
512
|
-
isWithinTrackXBounds = this.isWithinBounds(this.axis.x.track.rect);
|
|
513
|
-
}
|
|
514
|
-
if (this.axis.y.isOverflowing || this.axis.y.forceVisible) {
|
|
515
|
-
isWithinTrackYBounds = this.isWithinBounds(this.axis.y.track.rect);
|
|
516
|
-
}
|
|
517
|
-
if (isWithinTrackXBounds || isWithinTrackYBounds) {
|
|
518
|
-
e.preventDefault();
|
|
519
|
-
e.stopPropagation();
|
|
520
|
-
if (e.type === "mousedown") {
|
|
521
|
-
if (isWithinTrackXBounds) {
|
|
522
|
-
this.axis.x.scrollbar.rect = this.axis.x.scrollbar.el.getBoundingClientRect();
|
|
523
|
-
if (this.isWithinBounds(this.axis.x.scrollbar.rect)) {
|
|
524
|
-
this.onDragStart(e, "x");
|
|
525
|
-
} else {
|
|
526
|
-
this.onTrackClick(e, "x");
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
if (isWithinTrackYBounds) {
|
|
530
|
-
this.axis.y.scrollbar.rect = this.axis.y.scrollbar.el.getBoundingClientRect();
|
|
531
|
-
if (this.isWithinBounds(this.axis.y.scrollbar.rect)) {
|
|
532
|
-
this.onDragStart(e, "y");
|
|
533
|
-
} else {
|
|
534
|
-
this.onTrackClick(e, "y");
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
574
|
/**
|
|
541
575
|
* on scrollbar handle drag movement starts
|
|
542
576
|
*/
|
|
@@ -558,61 +592,9 @@ class SimpleBar {
|
|
|
558
592
|
this.removePreventClickId = null;
|
|
559
593
|
}
|
|
560
594
|
}
|
|
561
|
-
/**
|
|
562
|
-
* Drag scrollbar handle
|
|
563
|
-
*/
|
|
564
|
-
drag = (e) => {
|
|
565
|
-
let eventOffset;
|
|
566
|
-
const track = this.axis[this.draggedAxis].track;
|
|
567
|
-
const trackSize = track.rect[this.axis[this.draggedAxis].sizeAttr];
|
|
568
|
-
const scrollbar = this.axis[this.draggedAxis].scrollbar;
|
|
569
|
-
const contentSize = this.contentWrapperEl[this.axis[this.draggedAxis].scrollSizeAttr];
|
|
570
|
-
const hostSize = parseInt(
|
|
571
|
-
this.elStyles[this.axis[this.draggedAxis].sizeAttr],
|
|
572
|
-
10
|
|
573
|
-
);
|
|
574
|
-
e.preventDefault();
|
|
575
|
-
e.stopPropagation();
|
|
576
|
-
if (this.draggedAxis === "y") {
|
|
577
|
-
eventOffset = e.pageY;
|
|
578
|
-
} else {
|
|
579
|
-
eventOffset = e.pageX;
|
|
580
|
-
}
|
|
581
|
-
let dragPos = eventOffset - track.rect[this.axis[this.draggedAxis].offsetAttr] - this.axis[this.draggedAxis].dragOffset;
|
|
582
|
-
let dragPerc = dragPos / (trackSize - scrollbar.size);
|
|
583
|
-
let scrollPos = dragPerc * (contentSize - hostSize);
|
|
584
|
-
if (this.draggedAxis === "x") {
|
|
585
|
-
scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
|
|
586
|
-
scrollPos = this.isRtl && SimpleBar.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
|
|
587
|
-
}
|
|
588
|
-
this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
|
|
589
|
-
};
|
|
590
|
-
/**
|
|
591
|
-
* End scroll handle drag
|
|
592
|
-
*/
|
|
593
|
-
onEndDrag = (e) => {
|
|
594
|
-
const elDocument = getElementDocument(this.el);
|
|
595
|
-
const elWindow = getElementWindow(this.el);
|
|
596
|
-
e.preventDefault();
|
|
597
|
-
e.stopPropagation();
|
|
598
|
-
this.el.classList.remove(this.classNames.dragging);
|
|
599
|
-
elDocument.removeEventListener("mousemove", this.drag, true);
|
|
600
|
-
elDocument.removeEventListener("mouseup", this.onEndDrag, true);
|
|
601
|
-
this.removePreventClickId = elWindow.setTimeout(() => {
|
|
602
|
-
elDocument.removeEventListener("click", this.preventClick, true);
|
|
603
|
-
elDocument.removeEventListener("dblclick", this.preventClick, true);
|
|
604
|
-
this.removePreventClickId = null;
|
|
605
|
-
});
|
|
606
|
-
};
|
|
607
|
-
/**
|
|
608
|
-
* Handler to ignore click events during drag
|
|
609
|
-
*/
|
|
610
|
-
preventClick = (e) => {
|
|
611
|
-
e.preventDefault();
|
|
612
|
-
e.stopPropagation();
|
|
613
|
-
};
|
|
614
595
|
onTrackClick(e, axis = "y") {
|
|
615
|
-
if (!this.options.clickOnTrack)
|
|
596
|
+
if (!this.options.clickOnTrack)
|
|
597
|
+
return;
|
|
616
598
|
const elWindow = getElementWindow(this.el);
|
|
617
599
|
this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
|
|
618
600
|
const scrollbar = this.axis[axis].scrollbar;
|
|
@@ -702,7 +684,7 @@ class SimpleBar {
|
|
|
702
684
|
*/
|
|
703
685
|
unMount() {
|
|
704
686
|
this.removeListeners();
|
|
705
|
-
|
|
687
|
+
_SimpleBar.instances.delete(this.el);
|
|
706
688
|
}
|
|
707
689
|
/**
|
|
708
690
|
* Check if mouse is within bounds
|
|
@@ -720,6 +702,34 @@ class SimpleBar {
|
|
|
720
702
|
(child) => matches.call(child, query)
|
|
721
703
|
)[0];
|
|
722
704
|
}
|
|
723
|
-
}
|
|
705
|
+
};
|
|
706
|
+
__publicField(_SimpleBar, "defaultOptions", {
|
|
707
|
+
autoHide: true,
|
|
708
|
+
forceVisible: false,
|
|
709
|
+
clickOnTrack: true,
|
|
710
|
+
clickOnTrackSpeed: 40,
|
|
711
|
+
classNames: {
|
|
712
|
+
contentEl: "simplebar-content",
|
|
713
|
+
contentWrapper: "simplebar-content-wrapper",
|
|
714
|
+
offset: "simplebar-offset",
|
|
715
|
+
mask: "simplebar-mask",
|
|
716
|
+
wrapper: "simplebar-wrapper",
|
|
717
|
+
placeholder: "simplebar-placeholder",
|
|
718
|
+
scrollbar: "simplebar-scrollbar",
|
|
719
|
+
track: "simplebar-track",
|
|
720
|
+
heightAutoObserverWrapperEl: "simplebar-height-auto-observer-wrapper",
|
|
721
|
+
heightAutoObserverEl: "simplebar-height-auto-observer",
|
|
722
|
+
visible: "simplebar-visible",
|
|
723
|
+
horizontal: "simplebar-horizontal",
|
|
724
|
+
vertical: "simplebar-vertical",
|
|
725
|
+
hover: "simplebar-hover",
|
|
726
|
+
dragging: "simplebar-dragging"
|
|
727
|
+
},
|
|
728
|
+
scrollbarMinSize: 25,
|
|
729
|
+
scrollbarMaxSize: 0,
|
|
730
|
+
timeout: 1e3
|
|
731
|
+
});
|
|
732
|
+
__publicField(_SimpleBar, "instances", /* @__PURE__ */ new WeakMap());
|
|
733
|
+
let SimpleBar = _SimpleBar;
|
|
724
734
|
|
|
725
735
|
export { SimpleBar as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/simplebar",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.5",
|
|
4
4
|
"description": "Клон core части библиотеки simplebar",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@juggle/resize-observer": "3.4.0",
|
|
24
|
-
"lodash": "4.17.
|
|
24
|
+
"lodash": "4.17.21"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"unbuild": "
|
|
27
|
+
"unbuild": "2.0.0"
|
|
28
28
|
},
|
|
29
29
|
"lint-staged": {
|
|
30
30
|
"*.{js,jsx,json}": [
|
|
@@ -36,6 +36,6 @@
|
|
|
36
36
|
"dev": "rollup -c -w",
|
|
37
37
|
"build": "unbuild",
|
|
38
38
|
"precommit": "lint-staged",
|
|
39
|
-
"pub": "pnpm build && pnpm publish --no-git-checks
|
|
39
|
+
"pub": "pnpm build && pnpm publish --no-git-checks"
|
|
40
40
|
}
|
|
41
41
|
}
|