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