@karta.io/simplebar 0.34.0-alpha.1 → 0.34.0-alpha.3
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 +69 -11
- package/dist/simplebar.mjs +58 -6
- package/package.json +6 -7
- package/src/helpers.js +0 -46
- package/src/index.js +0 -109
- package/src/scrollbar-width.js +0 -40
- package/src/simplebar.d.ts +0 -51
- package/src/simplebar.js +0 -949
package/dist/simplebar.cjs
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const throttle = require('lodash
|
|
4
|
-
const debounce = require('lodash
|
|
5
|
-
const memoize = require('lodash
|
|
3
|
+
const throttle = require('lodash/throttle');
|
|
4
|
+
const debounce = require('lodash/debounce');
|
|
5
|
+
const memoize = require('lodash/memoize');
|
|
6
6
|
const resizeObserver = require('@juggle/resize-observer');
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
+
|
|
10
|
+
const throttle__default = /*#__PURE__*/_interopDefaultCompat(throttle);
|
|
11
|
+
const debounce__default = /*#__PURE__*/_interopDefaultCompat(debounce);
|
|
12
|
+
const memoize__default = /*#__PURE__*/_interopDefaultCompat(memoize);
|
|
13
|
+
|
|
14
|
+
const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
15
|
+
const canUseDOM$1 = canUseDOM;
|
|
8
16
|
|
|
9
17
|
function getElementWindow(element) {
|
|
10
18
|
if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
|
|
@@ -21,7 +29,7 @@ function getElementDocument(element) {
|
|
|
21
29
|
|
|
22
30
|
let cachedScrollbarWidth = null;
|
|
23
31
|
let cachedDevicePixelRatio = null;
|
|
24
|
-
if (canUseDOM) {
|
|
32
|
+
if (canUseDOM$1) {
|
|
25
33
|
window.addEventListener("resize", () => {
|
|
26
34
|
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
|
|
27
35
|
cachedDevicePixelRatio = window.devicePixelRatio;
|
|
@@ -55,6 +63,9 @@ var __publicField = (obj, key, value) => {
|
|
|
55
63
|
};
|
|
56
64
|
const _SimpleBar = class {
|
|
57
65
|
constructor(element, options) {
|
|
66
|
+
/**
|
|
67
|
+
* On scroll event handling
|
|
68
|
+
*/
|
|
58
69
|
__publicField(this, "onScroll", () => {
|
|
59
70
|
const elWindow = getElementWindow(this.el);
|
|
60
71
|
if (!this.scrollXTicking) {
|
|
@@ -109,6 +120,9 @@ const _SimpleBar = class {
|
|
|
109
120
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
110
121
|
this.hideNativeScrollbar();
|
|
111
122
|
});
|
|
123
|
+
/**
|
|
124
|
+
* Hide Scrollbar
|
|
125
|
+
*/
|
|
112
126
|
__publicField(this, "hideScrollbars", () => {
|
|
113
127
|
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
114
128
|
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
@@ -154,6 +168,9 @@ const _SimpleBar = class {
|
|
|
154
168
|
}
|
|
155
169
|
}
|
|
156
170
|
});
|
|
171
|
+
/**
|
|
172
|
+
* Drag scrollbar handle
|
|
173
|
+
*/
|
|
157
174
|
__publicField(this, "drag", (e) => {
|
|
158
175
|
let eventOffset;
|
|
159
176
|
const track = this.axis[this.draggedAxis].track;
|
|
@@ -180,6 +197,9 @@ const _SimpleBar = class {
|
|
|
180
197
|
}
|
|
181
198
|
this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
|
|
182
199
|
});
|
|
200
|
+
/**
|
|
201
|
+
* End scroll handle drag
|
|
202
|
+
*/
|
|
183
203
|
__publicField(this, "onEndDrag", (e) => {
|
|
184
204
|
const elDocument = getElementDocument(this.el);
|
|
185
205
|
const elWindow = getElementWindow(this.el);
|
|
@@ -194,6 +214,9 @@ const _SimpleBar = class {
|
|
|
194
214
|
this.removePreventClickId = null;
|
|
195
215
|
});
|
|
196
216
|
});
|
|
217
|
+
/**
|
|
218
|
+
* Handler to ignore click events during drag
|
|
219
|
+
*/
|
|
197
220
|
__publicField(this, "preventClick", (e) => {
|
|
198
221
|
e.preventDefault();
|
|
199
222
|
e.stopPropagation();
|
|
@@ -239,18 +262,27 @@ const _SimpleBar = class {
|
|
|
239
262
|
if (_SimpleBar.instances.has(this.el)) {
|
|
240
263
|
return;
|
|
241
264
|
}
|
|
242
|
-
this.recalculate =
|
|
243
|
-
this.onMouseMove =
|
|
244
|
-
this.hideScrollbars =
|
|
265
|
+
this.recalculate = throttle__default(this.recalculate.bind(this), 64);
|
|
266
|
+
this.onMouseMove = throttle__default(this.onMouseMove.bind(this), 64);
|
|
267
|
+
this.hideScrollbars = debounce__default(
|
|
245
268
|
this.hideScrollbars.bind(this),
|
|
246
269
|
this.options.timeout
|
|
247
270
|
);
|
|
248
|
-
this.onWindowResize =
|
|
271
|
+
this.onWindowResize = debounce__default(this.onWindowResize.bind(this), 64, {
|
|
249
272
|
leading: true
|
|
250
273
|
});
|
|
251
|
-
_SimpleBar.getRtlHelpers =
|
|
274
|
+
_SimpleBar.getRtlHelpers = memoize__default(_SimpleBar.getRtlHelpers);
|
|
252
275
|
this.init();
|
|
253
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Static properties
|
|
279
|
+
*/
|
|
280
|
+
/**
|
|
281
|
+
* Helper to fix browsers inconsistency on RTL:
|
|
282
|
+
* - Firefox inverts the scrollbar initial position
|
|
283
|
+
* - IE11 inverts both scrollbar position and scrolling offset
|
|
284
|
+
* Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
|
|
285
|
+
*/
|
|
254
286
|
static getRtlHelpers() {
|
|
255
287
|
const dummyDiv = document.createElement("div");
|
|
256
288
|
dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
|
|
@@ -265,7 +297,9 @@ const _SimpleBar = class {
|
|
|
265
297
|
dummyContainerChild
|
|
266
298
|
);
|
|
267
299
|
return {
|
|
300
|
+
// determines if the scrolling is responding with negative values
|
|
268
301
|
isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
|
|
302
|
+
// determines if the origin scrollbar position is inverted or not (positioned on left or right)
|
|
269
303
|
isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
|
|
270
304
|
};
|
|
271
305
|
}
|
|
@@ -280,7 +314,7 @@ const _SimpleBar = class {
|
|
|
280
314
|
}
|
|
281
315
|
init() {
|
|
282
316
|
_SimpleBar.instances.set(this.el, this);
|
|
283
|
-
if (canUseDOM) {
|
|
317
|
+
if (canUseDOM$1) {
|
|
284
318
|
this.initDOM();
|
|
285
319
|
this.setAccessibilityAttributes();
|
|
286
320
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
@@ -455,6 +489,9 @@ const _SimpleBar = class {
|
|
|
455
489
|
this.toggleTrackVisibility("x");
|
|
456
490
|
this.toggleTrackVisibility("y");
|
|
457
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Calculate scrollbar size
|
|
494
|
+
*/
|
|
458
495
|
getScrollbarSize(axis = "y") {
|
|
459
496
|
if (!this.axis[axis].isOverflowing) {
|
|
460
497
|
return 0;
|
|
@@ -529,6 +566,9 @@ const _SimpleBar = class {
|
|
|
529
566
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
530
567
|
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
|
|
531
568
|
}
|
|
569
|
+
/**
|
|
570
|
+
* Show scrollbar
|
|
571
|
+
*/
|
|
532
572
|
showScrollbar(axis = "y") {
|
|
533
573
|
let scrollbar = this.axis[axis].scrollbar.el;
|
|
534
574
|
if (!this.axis[axis].isVisible) {
|
|
@@ -539,6 +579,9 @@ const _SimpleBar = class {
|
|
|
539
579
|
this.hideScrollbars();
|
|
540
580
|
}
|
|
541
581
|
}
|
|
582
|
+
/**
|
|
583
|
+
* on scrollbar handle drag movement starts
|
|
584
|
+
*/
|
|
542
585
|
onDragStart(e, axis = "y") {
|
|
543
586
|
const elDocument = getElementDocument(this.el);
|
|
544
587
|
const elWindow = getElementWindow(this.el);
|
|
@@ -590,9 +633,15 @@ const _SimpleBar = class {
|
|
|
590
633
|
};
|
|
591
634
|
scrollTo();
|
|
592
635
|
}
|
|
636
|
+
/**
|
|
637
|
+
* Getter for content element
|
|
638
|
+
*/
|
|
593
639
|
getContentElement() {
|
|
594
640
|
return this.contentEl;
|
|
595
641
|
}
|
|
642
|
+
/**
|
|
643
|
+
* Getter for original scrolling element
|
|
644
|
+
*/
|
|
596
645
|
getScrollElement() {
|
|
597
646
|
return this.contentWrapperEl;
|
|
598
647
|
}
|
|
@@ -638,13 +687,22 @@ const _SimpleBar = class {
|
|
|
638
687
|
this.hideScrollbars.cancel();
|
|
639
688
|
this.onWindowResize.cancel();
|
|
640
689
|
}
|
|
690
|
+
/**
|
|
691
|
+
* UnMount mutation observer and delete SimpleBar instance from DOM element
|
|
692
|
+
*/
|
|
641
693
|
unMount() {
|
|
642
694
|
this.removeListeners();
|
|
643
695
|
_SimpleBar.instances.delete(this.el);
|
|
644
696
|
}
|
|
697
|
+
/**
|
|
698
|
+
* Check if mouse is within bounds
|
|
699
|
+
*/
|
|
645
700
|
isWithinBounds(bbox) {
|
|
646
701
|
return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
|
|
647
702
|
}
|
|
703
|
+
/**
|
|
704
|
+
* Find element children matches query
|
|
705
|
+
*/
|
|
648
706
|
findChild(el, query) {
|
|
649
707
|
const matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
|
|
650
708
|
return Array.prototype.filter.call(
|
package/dist/simplebar.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import throttle from 'lodash
|
|
2
|
-
import debounce from 'lodash
|
|
3
|
-
import memoize from 'lodash
|
|
1
|
+
import throttle from 'lodash/throttle';
|
|
2
|
+
import debounce from 'lodash/debounce';
|
|
3
|
+
import memoize from 'lodash/memoize';
|
|
4
4
|
import { ResizeObserver } from '@juggle/resize-observer';
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
const canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
7
|
+
const canUseDOM$1 = canUseDOM;
|
|
6
8
|
|
|
7
9
|
function getElementWindow(element) {
|
|
8
10
|
if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
|
|
@@ -19,7 +21,7 @@ function getElementDocument(element) {
|
|
|
19
21
|
|
|
20
22
|
let cachedScrollbarWidth = null;
|
|
21
23
|
let cachedDevicePixelRatio = null;
|
|
22
|
-
if (canUseDOM) {
|
|
24
|
+
if (canUseDOM$1) {
|
|
23
25
|
window.addEventListener("resize", () => {
|
|
24
26
|
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
|
|
25
27
|
cachedDevicePixelRatio = window.devicePixelRatio;
|
|
@@ -53,6 +55,9 @@ var __publicField = (obj, key, value) => {
|
|
|
53
55
|
};
|
|
54
56
|
const _SimpleBar = class {
|
|
55
57
|
constructor(element, options) {
|
|
58
|
+
/**
|
|
59
|
+
* On scroll event handling
|
|
60
|
+
*/
|
|
56
61
|
__publicField(this, "onScroll", () => {
|
|
57
62
|
const elWindow = getElementWindow(this.el);
|
|
58
63
|
if (!this.scrollXTicking) {
|
|
@@ -107,6 +112,9 @@ const _SimpleBar = class {
|
|
|
107
112
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
108
113
|
this.hideNativeScrollbar();
|
|
109
114
|
});
|
|
115
|
+
/**
|
|
116
|
+
* Hide Scrollbar
|
|
117
|
+
*/
|
|
110
118
|
__publicField(this, "hideScrollbars", () => {
|
|
111
119
|
this.axis.x.track.rect = this.axis.x.track.el.getBoundingClientRect();
|
|
112
120
|
this.axis.y.track.rect = this.axis.y.track.el.getBoundingClientRect();
|
|
@@ -152,6 +160,9 @@ const _SimpleBar = class {
|
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
});
|
|
163
|
+
/**
|
|
164
|
+
* Drag scrollbar handle
|
|
165
|
+
*/
|
|
155
166
|
__publicField(this, "drag", (e) => {
|
|
156
167
|
let eventOffset;
|
|
157
168
|
const track = this.axis[this.draggedAxis].track;
|
|
@@ -178,6 +189,9 @@ const _SimpleBar = class {
|
|
|
178
189
|
}
|
|
179
190
|
this.contentWrapperEl[this.axis[this.draggedAxis].scrollOffsetAttr] = scrollPos;
|
|
180
191
|
});
|
|
192
|
+
/**
|
|
193
|
+
* End scroll handle drag
|
|
194
|
+
*/
|
|
181
195
|
__publicField(this, "onEndDrag", (e) => {
|
|
182
196
|
const elDocument = getElementDocument(this.el);
|
|
183
197
|
const elWindow = getElementWindow(this.el);
|
|
@@ -192,6 +206,9 @@ const _SimpleBar = class {
|
|
|
192
206
|
this.removePreventClickId = null;
|
|
193
207
|
});
|
|
194
208
|
});
|
|
209
|
+
/**
|
|
210
|
+
* Handler to ignore click events during drag
|
|
211
|
+
*/
|
|
195
212
|
__publicField(this, "preventClick", (e) => {
|
|
196
213
|
e.preventDefault();
|
|
197
214
|
e.stopPropagation();
|
|
@@ -249,6 +266,15 @@ const _SimpleBar = class {
|
|
|
249
266
|
_SimpleBar.getRtlHelpers = memoize(_SimpleBar.getRtlHelpers);
|
|
250
267
|
this.init();
|
|
251
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Static properties
|
|
271
|
+
*/
|
|
272
|
+
/**
|
|
273
|
+
* Helper to fix browsers inconsistency on RTL:
|
|
274
|
+
* - Firefox inverts the scrollbar initial position
|
|
275
|
+
* - IE11 inverts both scrollbar position and scrolling offset
|
|
276
|
+
* Directly inspired by @KingSora's OverlayScrollbars https://github.com/KingSora/OverlayScrollbars/blob/master/js/OverlayScrollbars.js#L1634
|
|
277
|
+
*/
|
|
252
278
|
static getRtlHelpers() {
|
|
253
279
|
const dummyDiv = document.createElement("div");
|
|
254
280
|
dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
|
|
@@ -263,7 +289,9 @@ const _SimpleBar = class {
|
|
|
263
289
|
dummyContainerChild
|
|
264
290
|
);
|
|
265
291
|
return {
|
|
292
|
+
// determines if the scrolling is responding with negative values
|
|
266
293
|
isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
|
|
294
|
+
// determines if the origin scrollbar position is inverted or not (positioned on left or right)
|
|
267
295
|
isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
|
|
268
296
|
};
|
|
269
297
|
}
|
|
@@ -278,7 +306,7 @@ const _SimpleBar = class {
|
|
|
278
306
|
}
|
|
279
307
|
init() {
|
|
280
308
|
_SimpleBar.instances.set(this.el, this);
|
|
281
|
-
if (canUseDOM) {
|
|
309
|
+
if (canUseDOM$1) {
|
|
282
310
|
this.initDOM();
|
|
283
311
|
this.setAccessibilityAttributes();
|
|
284
312
|
this.scrollbarWidth = this.getScrollbarWidth();
|
|
@@ -453,6 +481,9 @@ const _SimpleBar = class {
|
|
|
453
481
|
this.toggleTrackVisibility("x");
|
|
454
482
|
this.toggleTrackVisibility("y");
|
|
455
483
|
}
|
|
484
|
+
/**
|
|
485
|
+
* Calculate scrollbar size
|
|
486
|
+
*/
|
|
456
487
|
getScrollbarSize(axis = "y") {
|
|
457
488
|
if (!this.axis[axis].isOverflowing) {
|
|
458
489
|
return 0;
|
|
@@ -527,6 +558,9 @@ const _SimpleBar = class {
|
|
|
527
558
|
this.axis[axis].track.el.classList.remove(this.classNames.hover);
|
|
528
559
|
this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
|
|
529
560
|
}
|
|
561
|
+
/**
|
|
562
|
+
* Show scrollbar
|
|
563
|
+
*/
|
|
530
564
|
showScrollbar(axis = "y") {
|
|
531
565
|
let scrollbar = this.axis[axis].scrollbar.el;
|
|
532
566
|
if (!this.axis[axis].isVisible) {
|
|
@@ -537,6 +571,9 @@ const _SimpleBar = class {
|
|
|
537
571
|
this.hideScrollbars();
|
|
538
572
|
}
|
|
539
573
|
}
|
|
574
|
+
/**
|
|
575
|
+
* on scrollbar handle drag movement starts
|
|
576
|
+
*/
|
|
540
577
|
onDragStart(e, axis = "y") {
|
|
541
578
|
const elDocument = getElementDocument(this.el);
|
|
542
579
|
const elWindow = getElementWindow(this.el);
|
|
@@ -588,9 +625,15 @@ const _SimpleBar = class {
|
|
|
588
625
|
};
|
|
589
626
|
scrollTo();
|
|
590
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Getter for content element
|
|
630
|
+
*/
|
|
591
631
|
getContentElement() {
|
|
592
632
|
return this.contentEl;
|
|
593
633
|
}
|
|
634
|
+
/**
|
|
635
|
+
* Getter for original scrolling element
|
|
636
|
+
*/
|
|
594
637
|
getScrollElement() {
|
|
595
638
|
return this.contentWrapperEl;
|
|
596
639
|
}
|
|
@@ -636,13 +679,22 @@ const _SimpleBar = class {
|
|
|
636
679
|
this.hideScrollbars.cancel();
|
|
637
680
|
this.onWindowResize.cancel();
|
|
638
681
|
}
|
|
682
|
+
/**
|
|
683
|
+
* UnMount mutation observer and delete SimpleBar instance from DOM element
|
|
684
|
+
*/
|
|
639
685
|
unMount() {
|
|
640
686
|
this.removeListeners();
|
|
641
687
|
_SimpleBar.instances.delete(this.el);
|
|
642
688
|
}
|
|
689
|
+
/**
|
|
690
|
+
* Check if mouse is within bounds
|
|
691
|
+
*/
|
|
643
692
|
isWithinBounds(bbox) {
|
|
644
693
|
return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
|
|
645
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Find element children matches query
|
|
697
|
+
*/
|
|
646
698
|
findChild(el, query) {
|
|
647
699
|
const matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
|
|
648
700
|
return Array.prototype.filter.call(
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@karta.io/simplebar",
|
|
3
|
-
"version": "0.34.0-alpha.
|
|
3
|
+
"version": "0.34.0-alpha.3",
|
|
4
4
|
"description": "Клон core части библиотеки simplebar",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
5
7
|
"files": [
|
|
6
|
-
"dist"
|
|
7
|
-
"src",
|
|
8
|
-
"README.md"
|
|
8
|
+
"dist"
|
|
9
9
|
],
|
|
10
10
|
"author": "Vitaly Blokhin <karambafe@gmail.com>",
|
|
11
11
|
"exports": {
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@juggle/resize-observer": "3.3.1",
|
|
24
|
-
"
|
|
25
|
-
"lodash-es": "4.17.21"
|
|
24
|
+
"lodash": "4.17.21"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"unbuild": "1.
|
|
27
|
+
"unbuild": "1.2.1"
|
|
29
28
|
},
|
|
30
29
|
"lint-staged": {
|
|
31
30
|
"*.{js,jsx,json}": [
|
package/src/helpers.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Helper function to retrieve options from element attributes
|
|
2
|
-
export const getOptions = function(obj) {
|
|
3
|
-
const options = Array.prototype.reduce.call(
|
|
4
|
-
obj,
|
|
5
|
-
(acc, attribute) => {
|
|
6
|
-
const option = attribute.name.match(/data-simplebar-(.+)/);
|
|
7
|
-
if (option) {
|
|
8
|
-
const key = option[1].replace(/\W+(.)/g, (x, chr) => chr.toUpperCase());
|
|
9
|
-
switch (attribute.value) {
|
|
10
|
-
case 'true':
|
|
11
|
-
acc[key] = true;
|
|
12
|
-
break;
|
|
13
|
-
case 'false':
|
|
14
|
-
acc[key] = false;
|
|
15
|
-
break;
|
|
16
|
-
case undefined:
|
|
17
|
-
acc[key] = true;
|
|
18
|
-
break;
|
|
19
|
-
default:
|
|
20
|
-
acc[key] = attribute.value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
},
|
|
25
|
-
{}
|
|
26
|
-
);
|
|
27
|
-
return options;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function getElementWindow(element) {
|
|
31
|
-
if (
|
|
32
|
-
!element ||
|
|
33
|
-
!element.ownerDocument ||
|
|
34
|
-
!element.ownerDocument.defaultView
|
|
35
|
-
) {
|
|
36
|
-
return window;
|
|
37
|
-
}
|
|
38
|
-
return element.ownerDocument.defaultView;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getElementDocument(element) {
|
|
42
|
-
if (!element || !element.ownerDocument) {
|
|
43
|
-
return document;
|
|
44
|
-
}
|
|
45
|
-
return element.ownerDocument;
|
|
46
|
-
}
|
package/src/index.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import canUseDOM from 'can-use-dom';
|
|
2
|
-
|
|
3
|
-
import SimpleBar from './simplebar';
|
|
4
|
-
import { getOptions } from './helpers';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @todo переписать на typescript
|
|
8
|
-
*/
|
|
9
|
-
SimpleBar.initDOMLoadedElements = function() {
|
|
10
|
-
document.removeEventListener('DOMContentLoaded', this.initDOMLoadedElements);
|
|
11
|
-
window.removeEventListener('load', this.initDOMLoadedElements);
|
|
12
|
-
|
|
13
|
-
Array.prototype.forEach.call(
|
|
14
|
-
document.querySelectorAll('[data-simplebar]'),
|
|
15
|
-
el => {
|
|
16
|
-
if (
|
|
17
|
-
el.getAttribute('data-simplebar') !== 'init' &&
|
|
18
|
-
!SimpleBar.instances.has(el)
|
|
19
|
-
)
|
|
20
|
-
new SimpleBar(el, getOptions(el.attributes));
|
|
21
|
-
}
|
|
22
|
-
);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
SimpleBar.removeObserver = function() {
|
|
26
|
-
this.globalObserver.disconnect();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
SimpleBar.initHtmlApi = function() {
|
|
30
|
-
this.initDOMLoadedElements = this.initDOMLoadedElements.bind(this);
|
|
31
|
-
|
|
32
|
-
// MutationObserver is IE11+
|
|
33
|
-
if (typeof MutationObserver !== 'undefined') {
|
|
34
|
-
// Mutation observer to observe dynamically added elements
|
|
35
|
-
this.globalObserver = new MutationObserver(SimpleBar.handleMutations);
|
|
36
|
-
|
|
37
|
-
this.globalObserver.observe(document, { childList: true, subtree: true });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Taken from jQuery `ready` function
|
|
41
|
-
// Instantiate elements already present on the page
|
|
42
|
-
if (
|
|
43
|
-
document.readyState === 'complete' ||
|
|
44
|
-
(document.readyState !== 'loading' && !document.documentElement.doScroll)
|
|
45
|
-
) {
|
|
46
|
-
// Handle it asynchronously to allow scripts the opportunity to delay init
|
|
47
|
-
window.setTimeout(this.initDOMLoadedElements);
|
|
48
|
-
} else {
|
|
49
|
-
document.addEventListener('DOMContentLoaded', this.initDOMLoadedElements);
|
|
50
|
-
window.addEventListener('load', this.initDOMLoadedElements);
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
SimpleBar.handleMutations = mutations => {
|
|
55
|
-
mutations.forEach(mutation => {
|
|
56
|
-
Array.prototype.forEach.call(mutation.addedNodes, addedNode => {
|
|
57
|
-
if (addedNode.nodeType === 1) {
|
|
58
|
-
if (addedNode.hasAttribute('data-simplebar')) {
|
|
59
|
-
!SimpleBar.instances.has(addedNode) &&
|
|
60
|
-
document.documentElement.contains(addedNode) &&
|
|
61
|
-
new SimpleBar(addedNode, getOptions(addedNode.attributes));
|
|
62
|
-
} else {
|
|
63
|
-
Array.prototype.forEach.call(
|
|
64
|
-
addedNode.querySelectorAll('[data-simplebar]'),
|
|
65
|
-
function(el) {
|
|
66
|
-
if (
|
|
67
|
-
el.getAttribute('data-simplebar') !== 'init' &&
|
|
68
|
-
!SimpleBar.instances.has(el) &&
|
|
69
|
-
document.documentElement.contains(el)
|
|
70
|
-
)
|
|
71
|
-
new SimpleBar(el, getOptions(el.attributes));
|
|
72
|
-
}
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
Array.prototype.forEach.call(mutation.removedNodes, removedNode => {
|
|
79
|
-
if (removedNode.nodeType === 1) {
|
|
80
|
-
if (removedNode.getAttribute('data-simplebar') === 'init') {
|
|
81
|
-
SimpleBar.instances.has(removedNode) &&
|
|
82
|
-
!document.documentElement.contains(removedNode) &&
|
|
83
|
-
SimpleBar.instances.get(removedNode).unMount();
|
|
84
|
-
} else {
|
|
85
|
-
Array.prototype.forEach.call(
|
|
86
|
-
removedNode.querySelectorAll('[data-simplebar="init"]'),
|
|
87
|
-
el => {
|
|
88
|
-
SimpleBar.instances.has(el) &&
|
|
89
|
-
!document.documentElement.contains(el) &&
|
|
90
|
-
SimpleBar.instances.get(el).unMount();
|
|
91
|
-
}
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
SimpleBar.getOptions = getOptions;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* HTML API
|
|
103
|
-
* Called only in a browser env.
|
|
104
|
-
*/
|
|
105
|
-
if (canUseDOM) {
|
|
106
|
-
SimpleBar.initHtmlApi();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export default SimpleBar;
|
package/src/scrollbar-width.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import canUseDOM from 'can-use-dom';
|
|
2
|
-
import { getElementDocument } from "./helpers";
|
|
3
|
-
|
|
4
|
-
let cachedScrollbarWidth = null;
|
|
5
|
-
let cachedDevicePixelRatio = null;
|
|
6
|
-
|
|
7
|
-
if (canUseDOM) {
|
|
8
|
-
window.addEventListener('resize', () => {
|
|
9
|
-
if (cachedDevicePixelRatio !== window.devicePixelRatio) {
|
|
10
|
-
cachedDevicePixelRatio = window.devicePixelRatio;
|
|
11
|
-
cachedScrollbarWidth = null;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default function scrollbarWidth(el) {
|
|
17
|
-
if (cachedScrollbarWidth === null) {
|
|
18
|
-
|
|
19
|
-
const document = getElementDocument(el);
|
|
20
|
-
|
|
21
|
-
if (typeof document === 'undefined') {
|
|
22
|
-
cachedScrollbarWidth = 0;
|
|
23
|
-
return cachedScrollbarWidth;
|
|
24
|
-
}
|
|
25
|
-
const body = document.body;
|
|
26
|
-
const box = document.createElement('div');
|
|
27
|
-
|
|
28
|
-
box.classList.add('simplebar-hide-scrollbar');
|
|
29
|
-
|
|
30
|
-
body.appendChild(box);
|
|
31
|
-
|
|
32
|
-
const width = box.getBoundingClientRect().right;
|
|
33
|
-
|
|
34
|
-
body.removeChild(box);
|
|
35
|
-
|
|
36
|
-
cachedScrollbarWidth = width;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return cachedScrollbarWidth;
|
|
40
|
-
}
|
package/src/simplebar.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export as namespace SimpleBar;
|
|
2
|
-
export = SimpleBar;
|
|
3
|
-
|
|
4
|
-
declare namespace SimpleBar {
|
|
5
|
-
interface KnownClassNamesOptions {
|
|
6
|
-
contentEl?: string;
|
|
7
|
-
contentWrapper?: string;
|
|
8
|
-
offset?: string;
|
|
9
|
-
mask?: string;
|
|
10
|
-
wrapper?: string;
|
|
11
|
-
placeholder?: string;
|
|
12
|
-
scrollbar?: string;
|
|
13
|
-
track?: string;
|
|
14
|
-
heightAutoObserverWrapperEl?: string;
|
|
15
|
-
heightAutoObserverEl?: string;
|
|
16
|
-
visible?: string;
|
|
17
|
-
horizontal?: string;
|
|
18
|
-
vertical?: string;
|
|
19
|
-
hover?: string;
|
|
20
|
-
dragging?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type ClassNamesOptions = KnownClassNamesOptions & {
|
|
24
|
-
[className: string]: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
interface Options {
|
|
28
|
-
autoHide?: boolean;
|
|
29
|
-
classNames?: ClassNamesOptions;
|
|
30
|
-
forceVisible?: boolean | 'x' | 'y';
|
|
31
|
-
direction?: 'rtl' | 'ltr';
|
|
32
|
-
timeout?: number;
|
|
33
|
-
clickOnTrack?: boolean;
|
|
34
|
-
scrollbarMinSize?: number;
|
|
35
|
-
scrollbarMaxSize?: number;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
declare class SimpleBar {
|
|
40
|
-
static removeObserver(): void;
|
|
41
|
-
static instances: Pick<WeakMap<HTMLElement, SimpleBar>, 'get' | 'has'>;
|
|
42
|
-
|
|
43
|
-
constructor(element: HTMLElement, options?: SimpleBar.Options);
|
|
44
|
-
|
|
45
|
-
recalculate(): void;
|
|
46
|
-
getScrollElement(): HTMLElement;
|
|
47
|
-
getContentElement(): HTMLElement;
|
|
48
|
-
unMount(): void;
|
|
49
|
-
|
|
50
|
-
el: HTMLElement;
|
|
51
|
-
}
|