@m4l/components 0.1.6 → 0.1.7

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/simplebar.js DELETED
@@ -1,850 +0,0 @@
1
- import require$$0, { useRef, useEffect } from "react";
2
- import PropTypes from "prop-types";
3
- import "./core-js.js";
4
- import { l as lodash_throttle, a as lodash_debounce, b as lodash_memoize } from "./lodash.js";
5
- import { R as ResizeObserver } from "./juggle.js";
6
- import { c as canUseDom } from "./can-use-dom.js";
7
- import { jsxs, jsx } from "react/jsx-runtime";
8
- function getElementWindow(element) {
9
- if (!element || !element.ownerDocument || !element.ownerDocument.defaultView) {
10
- return window;
11
- }
12
- return element.ownerDocument.defaultView;
13
- }
14
- function getElementDocument(element) {
15
- if (!element || !element.ownerDocument) {
16
- return document;
17
- }
18
- return element.ownerDocument;
19
- }
20
- var cachedScrollbarWidth = null;
21
- var cachedDevicePixelRatio = null;
22
- if (canUseDom) {
23
- window.addEventListener("resize", function() {
24
- if (cachedDevicePixelRatio !== window.devicePixelRatio) {
25
- cachedDevicePixelRatio = window.devicePixelRatio;
26
- cachedScrollbarWidth = null;
27
- }
28
- });
29
- }
30
- function scrollbarWidth(el) {
31
- if (cachedScrollbarWidth === null) {
32
- var document2 = getElementDocument(el);
33
- if (typeof document2 === "undefined") {
34
- cachedScrollbarWidth = 0;
35
- return cachedScrollbarWidth;
36
- }
37
- var body = document2.body;
38
- var box = document2.createElement("div");
39
- box.classList.add("simplebar-hide-scrollbar");
40
- body.appendChild(box);
41
- var width = box.getBoundingClientRect().right;
42
- body.removeChild(box);
43
- cachedScrollbarWidth = width;
44
- }
45
- return cachedScrollbarWidth;
46
- }
47
- var SimpleBar$1 = /* @__PURE__ */ function() {
48
- function SimpleBar2(element, options) {
49
- var _this = this;
50
- this.onScroll = function() {
51
- var elWindow = getElementWindow(_this.el);
52
- if (!_this.scrollXTicking) {
53
- elWindow.requestAnimationFrame(_this.scrollX);
54
- _this.scrollXTicking = true;
55
- }
56
- if (!_this.scrollYTicking) {
57
- elWindow.requestAnimationFrame(_this.scrollY);
58
- _this.scrollYTicking = true;
59
- }
60
- };
61
- this.scrollX = function() {
62
- if (_this.axis.x.isOverflowing) {
63
- _this.showScrollbar("x");
64
- _this.positionScrollbar("x");
65
- }
66
- _this.scrollXTicking = false;
67
- };
68
- this.scrollY = function() {
69
- if (_this.axis.y.isOverflowing) {
70
- _this.showScrollbar("y");
71
- _this.positionScrollbar("y");
72
- }
73
- _this.scrollYTicking = false;
74
- };
75
- this.onMouseEnter = function() {
76
- _this.showScrollbar("x");
77
- _this.showScrollbar("y");
78
- };
79
- this.onMouseMove = function(e) {
80
- _this.mouseX = e.clientX;
81
- _this.mouseY = e.clientY;
82
- if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
83
- _this.onMouseMoveForAxis("x");
84
- }
85
- if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
86
- _this.onMouseMoveForAxis("y");
87
- }
88
- };
89
- this.onMouseLeave = function() {
90
- _this.onMouseMove.cancel();
91
- if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
92
- _this.onMouseLeaveForAxis("x");
93
- }
94
- if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
95
- _this.onMouseLeaveForAxis("y");
96
- }
97
- _this.mouseX = -1;
98
- _this.mouseY = -1;
99
- };
100
- this.onWindowResize = function() {
101
- _this.scrollbarWidth = _this.getScrollbarWidth();
102
- _this.hideNativeScrollbar();
103
- };
104
- this.hideScrollbars = function() {
105
- _this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
106
- _this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
107
- if (!_this.isWithinBounds(_this.axis.y.track.rect)) {
108
- _this.axis.y.scrollbar.el.classList.remove(_this.classNames.visible);
109
- _this.axis.y.isVisible = false;
110
- }
111
- if (!_this.isWithinBounds(_this.axis.x.track.rect)) {
112
- _this.axis.x.scrollbar.el.classList.remove(_this.classNames.visible);
113
- _this.axis.x.isVisible = false;
114
- }
115
- };
116
- this.onPointerEvent = function(e) {
117
- var isWithinTrackXBounds, isWithinTrackYBounds;
118
- _this.axis.x.track.rect = _this.axis.x.track.el.getBoundingClientRect();
119
- _this.axis.y.track.rect = _this.axis.y.track.el.getBoundingClientRect();
120
- if (_this.axis.x.isOverflowing || _this.axis.x.forceVisible) {
121
- isWithinTrackXBounds = _this.isWithinBounds(_this.axis.x.track.rect);
122
- }
123
- if (_this.axis.y.isOverflowing || _this.axis.y.forceVisible) {
124
- isWithinTrackYBounds = _this.isWithinBounds(_this.axis.y.track.rect);
125
- }
126
- if (isWithinTrackXBounds || isWithinTrackYBounds) {
127
- e.preventDefault();
128
- e.stopPropagation();
129
- if (e.type === "mousedown") {
130
- if (isWithinTrackXBounds) {
131
- _this.axis.x.scrollbar.rect = _this.axis.x.scrollbar.el.getBoundingClientRect();
132
- if (_this.isWithinBounds(_this.axis.x.scrollbar.rect)) {
133
- _this.onDragStart(e, "x");
134
- } else {
135
- _this.onTrackClick(e, "x");
136
- }
137
- }
138
- if (isWithinTrackYBounds) {
139
- _this.axis.y.scrollbar.rect = _this.axis.y.scrollbar.el.getBoundingClientRect();
140
- if (_this.isWithinBounds(_this.axis.y.scrollbar.rect)) {
141
- _this.onDragStart(e, "y");
142
- } else {
143
- _this.onTrackClick(e, "y");
144
- }
145
- }
146
- }
147
- }
148
- };
149
- this.drag = function(e) {
150
- var eventOffset;
151
- var track = _this.axis[_this.draggedAxis].track;
152
- var trackSize = track.rect[_this.axis[_this.draggedAxis].sizeAttr];
153
- var scrollbar = _this.axis[_this.draggedAxis].scrollbar;
154
- var contentSize = _this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollSizeAttr];
155
- var hostSize = parseInt(_this.elStyles[_this.axis[_this.draggedAxis].sizeAttr], 10);
156
- e.preventDefault();
157
- e.stopPropagation();
158
- if (_this.draggedAxis === "y") {
159
- eventOffset = e.pageY;
160
- } else {
161
- eventOffset = e.pageX;
162
- }
163
- var dragPos = eventOffset - track.rect[_this.axis[_this.draggedAxis].offsetAttr] - _this.axis[_this.draggedAxis].dragOffset;
164
- var dragPerc = dragPos / (trackSize - scrollbar.size);
165
- var scrollPos = dragPerc * (contentSize - hostSize);
166
- if (_this.draggedAxis === "x") {
167
- scrollPos = _this.isRtl && SimpleBar2.getRtlHelpers().isRtlScrollbarInverted ? scrollPos - (trackSize + scrollbar.size) : scrollPos;
168
- scrollPos = _this.isRtl && SimpleBar2.getRtlHelpers().isRtlScrollingInverted ? -scrollPos : scrollPos;
169
- }
170
- _this.contentWrapperEl[_this.axis[_this.draggedAxis].scrollOffsetAttr] = scrollPos;
171
- };
172
- this.onEndDrag = function(e) {
173
- var elDocument = getElementDocument(_this.el);
174
- var elWindow = getElementWindow(_this.el);
175
- e.preventDefault();
176
- e.stopPropagation();
177
- _this.el.classList.remove(_this.classNames.dragging);
178
- elDocument.removeEventListener("mousemove", _this.drag, true);
179
- elDocument.removeEventListener("mouseup", _this.onEndDrag, true);
180
- _this.removePreventClickId = elWindow.setTimeout(function() {
181
- elDocument.removeEventListener("click", _this.preventClick, true);
182
- elDocument.removeEventListener("dblclick", _this.preventClick, true);
183
- _this.removePreventClickId = null;
184
- });
185
- };
186
- this.preventClick = function(e) {
187
- e.preventDefault();
188
- e.stopPropagation();
189
- };
190
- this.el = element;
191
- this.minScrollbarWidth = 20;
192
- this.options = Object.assign({}, SimpleBar2.defaultOptions, options);
193
- this.classNames = Object.assign({}, SimpleBar2.defaultOptions.classNames, this.options.classNames);
194
- this.axis = {
195
- x: {
196
- scrollOffsetAttr: "scrollLeft",
197
- sizeAttr: "width",
198
- scrollSizeAttr: "scrollWidth",
199
- offsetSizeAttr: "offsetWidth",
200
- offsetAttr: "left",
201
- overflowAttr: "overflowX",
202
- dragOffset: 0,
203
- isOverflowing: true,
204
- isVisible: false,
205
- forceVisible: false,
206
- track: {},
207
- scrollbar: {}
208
- },
209
- y: {
210
- scrollOffsetAttr: "scrollTop",
211
- sizeAttr: "height",
212
- scrollSizeAttr: "scrollHeight",
213
- offsetSizeAttr: "offsetHeight",
214
- offsetAttr: "top",
215
- overflowAttr: "overflowY",
216
- dragOffset: 0,
217
- isOverflowing: true,
218
- isVisible: false,
219
- forceVisible: false,
220
- track: {},
221
- scrollbar: {}
222
- }
223
- };
224
- this.removePreventClickId = null;
225
- if (SimpleBar2.instances.has(this.el)) {
226
- return;
227
- }
228
- this.recalculate = lodash_throttle(this.recalculate.bind(this), 64);
229
- this.onMouseMove = lodash_throttle(this.onMouseMove.bind(this), 64);
230
- this.hideScrollbars = lodash_debounce(this.hideScrollbars.bind(this), this.options.timeout);
231
- this.onWindowResize = lodash_debounce(this.onWindowResize.bind(this), 64, {
232
- leading: true
233
- });
234
- SimpleBar2.getRtlHelpers = lodash_memoize(SimpleBar2.getRtlHelpers);
235
- this.init();
236
- }
237
- SimpleBar2.getRtlHelpers = function getRtlHelpers() {
238
- var dummyDiv = document.createElement("div");
239
- dummyDiv.innerHTML = '<div class="hs-dummy-scrollbar-size"><div style="height: 200%; width: 200%; margin: 10px 0;"></div></div>';
240
- var scrollbarDummyEl = dummyDiv.firstElementChild;
241
- document.body.appendChild(scrollbarDummyEl);
242
- var dummyContainerChild = scrollbarDummyEl.firstElementChild;
243
- scrollbarDummyEl.scrollLeft = 0;
244
- var dummyContainerOffset = SimpleBar2.getOffset(scrollbarDummyEl);
245
- var dummyContainerChildOffset = SimpleBar2.getOffset(dummyContainerChild);
246
- scrollbarDummyEl.scrollLeft = 999;
247
- var dummyContainerScrollOffsetAfterScroll = SimpleBar2.getOffset(dummyContainerChild);
248
- return {
249
- isRtlScrollingInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left && dummyContainerChildOffset.left - dummyContainerScrollOffsetAfterScroll.left !== 0,
250
- isRtlScrollbarInverted: dummyContainerOffset.left !== dummyContainerChildOffset.left
251
- };
252
- };
253
- SimpleBar2.getOffset = function getOffset(el) {
254
- var rect = el.getBoundingClientRect();
255
- var elDocument = getElementDocument(el);
256
- var elWindow = getElementWindow(el);
257
- return {
258
- top: rect.top + (elWindow.pageYOffset || elDocument.documentElement.scrollTop),
259
- left: rect.left + (elWindow.pageXOffset || elDocument.documentElement.scrollLeft)
260
- };
261
- };
262
- var _proto = SimpleBar2.prototype;
263
- _proto.init = function init() {
264
- SimpleBar2.instances.set(this.el, this);
265
- if (canUseDom) {
266
- this.initDOM();
267
- this.setAccessibilityAttributes();
268
- this.scrollbarWidth = this.getScrollbarWidth();
269
- this.recalculate();
270
- this.initListeners();
271
- }
272
- };
273
- _proto.initDOM = function initDOM() {
274
- var _this2 = this;
275
- if (Array.prototype.filter.call(this.el.children, function(child) {
276
- return child.classList.contains(_this2.classNames.wrapper);
277
- }).length) {
278
- this.wrapperEl = this.el.querySelector("." + this.classNames.wrapper);
279
- this.contentWrapperEl = this.options.scrollableNode || this.el.querySelector("." + this.classNames.contentWrapper);
280
- this.contentEl = this.options.contentNode || this.el.querySelector("." + this.classNames.contentEl);
281
- this.offsetEl = this.el.querySelector("." + this.classNames.offset);
282
- this.maskEl = this.el.querySelector("." + this.classNames.mask);
283
- this.placeholderEl = this.findChild(this.wrapperEl, "." + this.classNames.placeholder);
284
- this.heightAutoObserverWrapperEl = this.el.querySelector("." + this.classNames.heightAutoObserverWrapperEl);
285
- this.heightAutoObserverEl = this.el.querySelector("." + this.classNames.heightAutoObserverEl);
286
- this.axis.x.track.el = this.findChild(this.el, "." + this.classNames.track + "." + this.classNames.horizontal);
287
- this.axis.y.track.el = this.findChild(this.el, "." + this.classNames.track + "." + this.classNames.vertical);
288
- } else {
289
- this.wrapperEl = document.createElement("div");
290
- this.contentWrapperEl = document.createElement("div");
291
- this.offsetEl = document.createElement("div");
292
- this.maskEl = document.createElement("div");
293
- this.contentEl = document.createElement("div");
294
- this.placeholderEl = document.createElement("div");
295
- this.heightAutoObserverWrapperEl = document.createElement("div");
296
- this.heightAutoObserverEl = document.createElement("div");
297
- this.wrapperEl.classList.add(this.classNames.wrapper);
298
- this.contentWrapperEl.classList.add(this.classNames.contentWrapper);
299
- this.offsetEl.classList.add(this.classNames.offset);
300
- this.maskEl.classList.add(this.classNames.mask);
301
- this.contentEl.classList.add(this.classNames.contentEl);
302
- this.placeholderEl.classList.add(this.classNames.placeholder);
303
- this.heightAutoObserverWrapperEl.classList.add(this.classNames.heightAutoObserverWrapperEl);
304
- this.heightAutoObserverEl.classList.add(this.classNames.heightAutoObserverEl);
305
- while (this.el.firstChild) {
306
- this.contentEl.appendChild(this.el.firstChild);
307
- }
308
- this.contentWrapperEl.appendChild(this.contentEl);
309
- this.offsetEl.appendChild(this.contentWrapperEl);
310
- this.maskEl.appendChild(this.offsetEl);
311
- this.heightAutoObserverWrapperEl.appendChild(this.heightAutoObserverEl);
312
- this.wrapperEl.appendChild(this.heightAutoObserverWrapperEl);
313
- this.wrapperEl.appendChild(this.maskEl);
314
- this.wrapperEl.appendChild(this.placeholderEl);
315
- this.el.appendChild(this.wrapperEl);
316
- }
317
- if (!this.axis.x.track.el || !this.axis.y.track.el) {
318
- var track = document.createElement("div");
319
- var scrollbar = document.createElement("div");
320
- track.classList.add(this.classNames.track);
321
- scrollbar.classList.add(this.classNames.scrollbar);
322
- track.appendChild(scrollbar);
323
- this.axis.x.track.el = track.cloneNode(true);
324
- this.axis.x.track.el.classList.add(this.classNames.horizontal);
325
- this.axis.y.track.el = track.cloneNode(true);
326
- this.axis.y.track.el.classList.add(this.classNames.vertical);
327
- this.el.appendChild(this.axis.x.track.el);
328
- this.el.appendChild(this.axis.y.track.el);
329
- }
330
- this.axis.x.scrollbar.el = this.axis.x.track.el.querySelector("." + this.classNames.scrollbar);
331
- this.axis.y.scrollbar.el = this.axis.y.track.el.querySelector("." + this.classNames.scrollbar);
332
- if (!this.options.autoHide) {
333
- this.axis.x.scrollbar.el.classList.add(this.classNames.visible);
334
- this.axis.y.scrollbar.el.classList.add(this.classNames.visible);
335
- }
336
- this.el.setAttribute("data-simplebar", "init");
337
- };
338
- _proto.setAccessibilityAttributes = function setAccessibilityAttributes() {
339
- var ariaLabel = this.options.ariaLabel || "scrollable content";
340
- this.contentWrapperEl.setAttribute("tabindex", "0");
341
- this.contentWrapperEl.setAttribute("role", "region");
342
- this.contentWrapperEl.setAttribute("aria-label", ariaLabel);
343
- };
344
- _proto.initListeners = function initListeners() {
345
- var _this3 = this;
346
- var elWindow = getElementWindow(this.el);
347
- if (this.options.autoHide) {
348
- this.el.addEventListener("mouseenter", this.onMouseEnter);
349
- }
350
- ["mousedown", "click", "dblclick"].forEach(function(e) {
351
- _this3.el.addEventListener(e, _this3.onPointerEvent, true);
352
- });
353
- ["touchstart", "touchend", "touchmove"].forEach(function(e) {
354
- _this3.el.addEventListener(e, _this3.onPointerEvent, {
355
- capture: true,
356
- passive: true
357
- });
358
- });
359
- this.el.addEventListener("mousemove", this.onMouseMove);
360
- this.el.addEventListener("mouseleave", this.onMouseLeave);
361
- this.contentWrapperEl.addEventListener("scroll", this.onScroll);
362
- elWindow.addEventListener("resize", this.onWindowResize);
363
- var resizeObserverStarted = false;
364
- var resizeObserver = elWindow.ResizeObserver || ResizeObserver;
365
- this.resizeObserver = new resizeObserver(function() {
366
- if (!resizeObserverStarted)
367
- return;
368
- _this3.recalculate();
369
- });
370
- this.resizeObserver.observe(this.el);
371
- this.resizeObserver.observe(this.contentEl);
372
- elWindow.requestAnimationFrame(function() {
373
- resizeObserverStarted = true;
374
- });
375
- this.mutationObserver = new elWindow.MutationObserver(this.recalculate);
376
- this.mutationObserver.observe(this.contentEl, {
377
- childList: true,
378
- subtree: true,
379
- characterData: true
380
- });
381
- };
382
- _proto.recalculate = function recalculate() {
383
- var elWindow = getElementWindow(this.el);
384
- this.elStyles = elWindow.getComputedStyle(this.el);
385
- this.isRtl = this.elStyles.direction === "rtl";
386
- var isHeightAuto = this.heightAutoObserverEl.offsetHeight <= 1;
387
- var isWidthAuto = this.heightAutoObserverEl.offsetWidth <= 1;
388
- var contentElOffsetWidth = this.contentEl.offsetWidth;
389
- var contentWrapperElOffsetWidth = this.contentWrapperEl.offsetWidth;
390
- var elOverflowX = this.elStyles.overflowX;
391
- var elOverflowY = this.elStyles.overflowY;
392
- this.contentEl.style.padding = this.elStyles.paddingTop + " " + this.elStyles.paddingRight + " " + this.elStyles.paddingBottom + " " + this.elStyles.paddingLeft;
393
- this.wrapperEl.style.margin = "-" + this.elStyles.paddingTop + " -" + this.elStyles.paddingRight + " -" + this.elStyles.paddingBottom + " -" + this.elStyles.paddingLeft;
394
- var contentElScrollHeight = this.contentEl.scrollHeight;
395
- var contentElScrollWidth = this.contentEl.scrollWidth;
396
- this.contentWrapperEl.style.height = isHeightAuto ? "auto" : "100%";
397
- this.placeholderEl.style.width = isWidthAuto ? contentElOffsetWidth + "px" : "auto";
398
- this.placeholderEl.style.height = contentElScrollHeight + "px";
399
- var contentWrapperElOffsetHeight = this.contentWrapperEl.offsetHeight;
400
- this.axis.x.isOverflowing = contentElScrollWidth > contentElOffsetWidth;
401
- this.axis.y.isOverflowing = contentElScrollHeight > contentWrapperElOffsetHeight;
402
- this.axis.x.isOverflowing = elOverflowX === "hidden" ? false : this.axis.x.isOverflowing;
403
- this.axis.y.isOverflowing = elOverflowY === "hidden" ? false : this.axis.y.isOverflowing;
404
- this.axis.x.forceVisible = this.options.forceVisible === "x" || this.options.forceVisible === true;
405
- this.axis.y.forceVisible = this.options.forceVisible === "y" || this.options.forceVisible === true;
406
- this.hideNativeScrollbar();
407
- var offsetForXScrollbar = this.axis.x.isOverflowing ? this.scrollbarWidth : 0;
408
- var offsetForYScrollbar = this.axis.y.isOverflowing ? this.scrollbarWidth : 0;
409
- this.axis.x.isOverflowing = this.axis.x.isOverflowing && contentElScrollWidth > contentWrapperElOffsetWidth - offsetForYScrollbar;
410
- this.axis.y.isOverflowing = this.axis.y.isOverflowing && contentElScrollHeight > contentWrapperElOffsetHeight - offsetForXScrollbar;
411
- this.axis.x.scrollbar.size = this.getScrollbarSize("x");
412
- this.axis.y.scrollbar.size = this.getScrollbarSize("y");
413
- this.axis.x.scrollbar.el.style.width = this.axis.x.scrollbar.size + "px";
414
- this.axis.y.scrollbar.el.style.height = this.axis.y.scrollbar.size + "px";
415
- this.positionScrollbar("x");
416
- this.positionScrollbar("y");
417
- this.toggleTrackVisibility("x");
418
- this.toggleTrackVisibility("y");
419
- };
420
- _proto.getScrollbarSize = function getScrollbarSize(axis) {
421
- if (axis === void 0) {
422
- axis = "y";
423
- }
424
- if (!this.axis[axis].isOverflowing) {
425
- return 0;
426
- }
427
- var contentSize = this.contentEl[this.axis[axis].scrollSizeAttr];
428
- var trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
429
- var scrollbarSize;
430
- var scrollbarRatio = trackSize / contentSize;
431
- scrollbarSize = Math.max(~~(scrollbarRatio * trackSize), this.options.scrollbarMinSize);
432
- if (this.options.scrollbarMaxSize) {
433
- scrollbarSize = Math.min(scrollbarSize, this.options.scrollbarMaxSize);
434
- }
435
- return scrollbarSize;
436
- };
437
- _proto.positionScrollbar = function positionScrollbar(axis) {
438
- if (axis === void 0) {
439
- axis = "y";
440
- }
441
- if (!this.axis[axis].isOverflowing) {
442
- return;
443
- }
444
- var contentSize = this.contentWrapperEl[this.axis[axis].scrollSizeAttr];
445
- var trackSize = this.axis[axis].track.el[this.axis[axis].offsetSizeAttr];
446
- var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
447
- var scrollbar = this.axis[axis].scrollbar;
448
- var scrollOffset = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
449
- scrollOffset = axis === "x" && this.isRtl && SimpleBar2.getRtlHelpers().isRtlScrollingInverted ? -scrollOffset : scrollOffset;
450
- var scrollPourcent = scrollOffset / (contentSize - hostSize);
451
- var handleOffset = ~~((trackSize - scrollbar.size) * scrollPourcent);
452
- handleOffset = axis === "x" && this.isRtl && SimpleBar2.getRtlHelpers().isRtlScrollbarInverted ? handleOffset + (trackSize - scrollbar.size) : handleOffset;
453
- scrollbar.el.style.transform = axis === "x" ? "translate3d(" + handleOffset + "px, 0, 0)" : "translate3d(0, " + handleOffset + "px, 0)";
454
- };
455
- _proto.toggleTrackVisibility = function toggleTrackVisibility(axis) {
456
- if (axis === void 0) {
457
- axis = "y";
458
- }
459
- var track = this.axis[axis].track.el;
460
- var scrollbar = this.axis[axis].scrollbar.el;
461
- if (this.axis[axis].isOverflowing || this.axis[axis].forceVisible) {
462
- track.style.visibility = "visible";
463
- this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "scroll";
464
- } else {
465
- track.style.visibility = "hidden";
466
- this.contentWrapperEl.style[this.axis[axis].overflowAttr] = "hidden";
467
- }
468
- if (this.axis[axis].isOverflowing) {
469
- scrollbar.style.display = "block";
470
- } else {
471
- scrollbar.style.display = "none";
472
- }
473
- };
474
- _proto.hideNativeScrollbar = function hideNativeScrollbar() {
475
- this.offsetEl.style[this.isRtl ? "left" : "right"] = this.axis.y.isOverflowing || this.axis.y.forceVisible ? "-" + this.scrollbarWidth + "px" : 0;
476
- this.offsetEl.style.bottom = this.axis.x.isOverflowing || this.axis.x.forceVisible ? "-" + this.scrollbarWidth + "px" : 0;
477
- };
478
- _proto.onMouseMoveForAxis = function onMouseMoveForAxis(axis) {
479
- if (axis === void 0) {
480
- axis = "y";
481
- }
482
- this.axis[axis].track.rect = this.axis[axis].track.el.getBoundingClientRect();
483
- this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
484
- var isWithinScrollbarBoundsX = this.isWithinBounds(this.axis[axis].scrollbar.rect);
485
- if (isWithinScrollbarBoundsX) {
486
- this.axis[axis].scrollbar.el.classList.add(this.classNames.hover);
487
- } else {
488
- this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
489
- }
490
- if (this.isWithinBounds(this.axis[axis].track.rect)) {
491
- this.showScrollbar(axis);
492
- this.axis[axis].track.el.classList.add(this.classNames.hover);
493
- } else {
494
- this.axis[axis].track.el.classList.remove(this.classNames.hover);
495
- }
496
- };
497
- _proto.onMouseLeaveForAxis = function onMouseLeaveForAxis(axis) {
498
- if (axis === void 0) {
499
- axis = "y";
500
- }
501
- this.axis[axis].track.el.classList.remove(this.classNames.hover);
502
- this.axis[axis].scrollbar.el.classList.remove(this.classNames.hover);
503
- };
504
- _proto.showScrollbar = function showScrollbar(axis) {
505
- if (axis === void 0) {
506
- axis = "y";
507
- }
508
- var scrollbar = this.axis[axis].scrollbar.el;
509
- if (!this.axis[axis].isVisible) {
510
- scrollbar.classList.add(this.classNames.visible);
511
- this.axis[axis].isVisible = true;
512
- }
513
- if (this.options.autoHide) {
514
- this.hideScrollbars();
515
- }
516
- };
517
- _proto.onDragStart = function onDragStart(e, axis) {
518
- if (axis === void 0) {
519
- axis = "y";
520
- }
521
- var elDocument = getElementDocument(this.el);
522
- var elWindow = getElementWindow(this.el);
523
- var scrollbar = this.axis[axis].scrollbar;
524
- var eventOffset = axis === "y" ? e.pageY : e.pageX;
525
- this.axis[axis].dragOffset = eventOffset - scrollbar.rect[this.axis[axis].offsetAttr];
526
- this.draggedAxis = axis;
527
- this.el.classList.add(this.classNames.dragging);
528
- elDocument.addEventListener("mousemove", this.drag, true);
529
- elDocument.addEventListener("mouseup", this.onEndDrag, true);
530
- if (this.removePreventClickId === null) {
531
- elDocument.addEventListener("click", this.preventClick, true);
532
- elDocument.addEventListener("dblclick", this.preventClick, true);
533
- } else {
534
- elWindow.clearTimeout(this.removePreventClickId);
535
- this.removePreventClickId = null;
536
- }
537
- };
538
- _proto.onTrackClick = function onTrackClick(e, axis) {
539
- var _this4 = this;
540
- if (axis === void 0) {
541
- axis = "y";
542
- }
543
- if (!this.options.clickOnTrack)
544
- return;
545
- var elWindow = getElementWindow(this.el);
546
- this.axis[axis].scrollbar.rect = this.axis[axis].scrollbar.el.getBoundingClientRect();
547
- var scrollbar = this.axis[axis].scrollbar;
548
- var scrollbarOffset = scrollbar.rect[this.axis[axis].offsetAttr];
549
- var hostSize = parseInt(this.elStyles[this.axis[axis].sizeAttr], 10);
550
- var scrolled = this.contentWrapperEl[this.axis[axis].scrollOffsetAttr];
551
- var t = axis === "y" ? this.mouseY - scrollbarOffset : this.mouseX - scrollbarOffset;
552
- var dir = t < 0 ? -1 : 1;
553
- var scrollSize = dir === -1 ? scrolled - hostSize : scrolled + hostSize;
554
- var scrollTo = function scrollTo2() {
555
- if (dir === -1) {
556
- if (scrolled > scrollSize) {
557
- var _this4$contentWrapper;
558
- scrolled -= _this4.options.clickOnTrackSpeed;
559
- _this4.contentWrapperEl.scrollTo((_this4$contentWrapper = {}, _this4$contentWrapper[_this4.axis[axis].offsetAttr] = scrolled, _this4$contentWrapper));
560
- elWindow.requestAnimationFrame(scrollTo2);
561
- }
562
- } else {
563
- if (scrolled < scrollSize) {
564
- var _this4$contentWrapper2;
565
- scrolled += _this4.options.clickOnTrackSpeed;
566
- _this4.contentWrapperEl.scrollTo((_this4$contentWrapper2 = {}, _this4$contentWrapper2[_this4.axis[axis].offsetAttr] = scrolled, _this4$contentWrapper2));
567
- elWindow.requestAnimationFrame(scrollTo2);
568
- }
569
- }
570
- };
571
- scrollTo();
572
- };
573
- _proto.getContentElement = function getContentElement() {
574
- return this.contentEl;
575
- };
576
- _proto.getScrollElement = function getScrollElement() {
577
- return this.contentWrapperEl;
578
- };
579
- _proto.getScrollbarWidth = function getScrollbarWidth() {
580
- try {
581
- if (getComputedStyle(this.contentWrapperEl, "::-webkit-scrollbar").display === "none" || "scrollbarWidth" in document.documentElement.style || "-ms-overflow-style" in document.documentElement.style) {
582
- return 0;
583
- } else {
584
- return scrollbarWidth(this.el);
585
- }
586
- } catch (e) {
587
- return scrollbarWidth(this.el);
588
- }
589
- };
590
- _proto.removeListeners = function removeListeners() {
591
- var _this5 = this;
592
- var elWindow = getElementWindow(this.el);
593
- if (this.options.autoHide) {
594
- this.el.removeEventListener("mouseenter", this.onMouseEnter);
595
- }
596
- ["mousedown", "click", "dblclick"].forEach(function(e) {
597
- _this5.el.removeEventListener(e, _this5.onPointerEvent, true);
598
- });
599
- ["touchstart", "touchend", "touchmove"].forEach(function(e) {
600
- _this5.el.removeEventListener(e, _this5.onPointerEvent, {
601
- capture: true,
602
- passive: true
603
- });
604
- });
605
- this.el.removeEventListener("mousemove", this.onMouseMove);
606
- this.el.removeEventListener("mouseleave", this.onMouseLeave);
607
- if (this.contentWrapperEl) {
608
- this.contentWrapperEl.removeEventListener("scroll", this.onScroll);
609
- }
610
- elWindow.removeEventListener("resize", this.onWindowResize);
611
- if (this.mutationObserver) {
612
- this.mutationObserver.disconnect();
613
- }
614
- if (this.resizeObserver) {
615
- this.resizeObserver.disconnect();
616
- }
617
- this.recalculate.cancel();
618
- this.onMouseMove.cancel();
619
- this.hideScrollbars.cancel();
620
- this.onWindowResize.cancel();
621
- };
622
- _proto.unMount = function unMount() {
623
- this.removeListeners();
624
- SimpleBar2.instances.delete(this.el);
625
- };
626
- _proto.isWithinBounds = function isWithinBounds(bbox) {
627
- return this.mouseX >= bbox.left && this.mouseX <= bbox.left + bbox.width && this.mouseY >= bbox.top && this.mouseY <= bbox.top + bbox.height;
628
- };
629
- _proto.findChild = function findChild(el, query) {
630
- var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
631
- return Array.prototype.filter.call(el.children, function(child) {
632
- return matches.call(child, query);
633
- })[0];
634
- };
635
- return SimpleBar2;
636
- }();
637
- SimpleBar$1.defaultOptions = {
638
- autoHide: true,
639
- forceVisible: false,
640
- clickOnTrack: true,
641
- clickOnTrackSpeed: 40,
642
- classNames: {
643
- contentEl: "simplebar-content",
644
- contentWrapper: "simplebar-content-wrapper",
645
- offset: "simplebar-offset",
646
- mask: "simplebar-mask",
647
- wrapper: "simplebar-wrapper",
648
- placeholder: "simplebar-placeholder",
649
- scrollbar: "simplebar-scrollbar",
650
- track: "simplebar-track",
651
- heightAutoObserverWrapperEl: "simplebar-height-auto-observer-wrapper",
652
- heightAutoObserverEl: "simplebar-height-auto-observer",
653
- visible: "simplebar-visible",
654
- horizontal: "simplebar-horizontal",
655
- vertical: "simplebar-vertical",
656
- hover: "simplebar-hover",
657
- dragging: "simplebar-dragging"
658
- },
659
- scrollbarMinSize: 25,
660
- scrollbarMaxSize: 0,
661
- timeout: 1e3
662
- };
663
- SimpleBar$1.instances = /* @__PURE__ */ new WeakMap();
664
- function ownKeys(object, enumerableOnly) {
665
- var keys = Object.keys(object);
666
- if (Object.getOwnPropertySymbols) {
667
- var symbols = Object.getOwnPropertySymbols(object);
668
- enumerableOnly && (symbols = symbols.filter(function(sym) {
669
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
670
- })), keys.push.apply(keys, symbols);
671
- }
672
- return keys;
673
- }
674
- function _objectSpread2(target) {
675
- for (var i = 1; i < arguments.length; i++) {
676
- var source = null != arguments[i] ? arguments[i] : {};
677
- i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
678
- _defineProperty(target, key, source[key]);
679
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
680
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
681
- });
682
- }
683
- return target;
684
- }
685
- function _defineProperty(obj, key, value) {
686
- if (key in obj) {
687
- Object.defineProperty(obj, key, {
688
- value,
689
- enumerable: true,
690
- configurable: true,
691
- writable: true
692
- });
693
- } else {
694
- obj[key] = value;
695
- }
696
- return obj;
697
- }
698
- function _objectWithoutPropertiesLoose(source, excluded) {
699
- if (source == null)
700
- return {};
701
- var target = {};
702
- var sourceKeys = Object.keys(source);
703
- var key, i;
704
- for (i = 0; i < sourceKeys.length; i++) {
705
- key = sourceKeys[i];
706
- if (excluded.indexOf(key) >= 0)
707
- continue;
708
- target[key] = source[key];
709
- }
710
- return target;
711
- }
712
- function _objectWithoutProperties(source, excluded) {
713
- if (source == null)
714
- return {};
715
- var target = _objectWithoutPropertiesLoose(source, excluded);
716
- var key, i;
717
- if (Object.getOwnPropertySymbols) {
718
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
719
- for (i = 0; i < sourceSymbolKeys.length; i++) {
720
- key = sourceSymbolKeys[i];
721
- if (excluded.indexOf(key) >= 0)
722
- continue;
723
- if (!Object.prototype.propertyIsEnumerable.call(source, key))
724
- continue;
725
- target[key] = source[key];
726
- }
727
- }
728
- return target;
729
- }
730
- var _excluded = ["children", "scrollableNodeProps", "tag"];
731
- var getOptions = function getOptions2(obj) {
732
- var options = Array.prototype.reduce.call(obj, function(acc, attribute) {
733
- var option = attribute.name.match(/data-simplebar-(.+)/);
734
- if (option) {
735
- var key = option[1].replace(/\W+(.)/g, function(x, chr) {
736
- return chr.toUpperCase();
737
- });
738
- switch (attribute.value) {
739
- case "true":
740
- acc[key] = true;
741
- break;
742
- case "false":
743
- acc[key] = false;
744
- break;
745
- case void 0:
746
- acc[key] = true;
747
- break;
748
- default:
749
- acc[key] = attribute.value;
750
- }
751
- }
752
- return acc;
753
- }, {});
754
- return options;
755
- };
756
- var SimpleBar = /* @__PURE__ */ require$$0.forwardRef(function(_ref, ref) {
757
- var children = _ref.children, _ref$scrollableNodePr = _ref.scrollableNodeProps, scrollableNodeProps = _ref$scrollableNodePr === void 0 ? {} : _ref$scrollableNodePr, _ref$tag = _ref.tag, tag = _ref$tag === void 0 ? "div" : _ref$tag, otherProps = _objectWithoutProperties(_ref, _excluded);
758
- var RootTag = tag;
759
- var instance;
760
- var scrollableNodeRef = useRef();
761
- var elRef = useRef();
762
- var contentNodeRef = useRef();
763
- var options = {};
764
- var rest = {};
765
- var deprecatedOptions = [];
766
- Object.keys(otherProps).forEach(function(key) {
767
- if (Object.prototype.hasOwnProperty.call(SimpleBar$1.defaultOptions, key)) {
768
- options[key] = otherProps[key];
769
- } else if (key.match(/data-simplebar-(.+)/) && key !== "data-simplebar-direction") {
770
- deprecatedOptions.push({
771
- name: key,
772
- value: otherProps[key]
773
- });
774
- } else {
775
- rest[key] = otherProps[key];
776
- }
777
- });
778
- if (deprecatedOptions.length) {
779
- console.warn(`simplebar-react: this way of passing options is deprecated. Pass it like normal props instead:
780
- 'data-simplebar-auto-hide="false"' \u2014> 'autoHide="false"'
781
- `);
782
- }
783
- useEffect(function() {
784
- scrollableNodeRef = scrollableNodeProps.ref || scrollableNodeRef;
785
- if (elRef.current) {
786
- instance = new SimpleBar$1(elRef.current, _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, getOptions(deprecatedOptions)), options), scrollableNodeRef && {
787
- scrollableNode: scrollableNodeRef.current
788
- }), contentNodeRef.current && {
789
- contentNode: contentNodeRef.current
790
- }));
791
- if (ref) {
792
- ref.current = instance;
793
- }
794
- }
795
- return function() {
796
- instance.unMount();
797
- instance = null;
798
- };
799
- }, []);
800
- return /* @__PURE__ */ jsxs(RootTag, {
801
- ref: elRef,
802
- "data-simplebar": true,
803
- ...rest,
804
- children: [/* @__PURE__ */ jsxs("div", {
805
- className: "simplebar-wrapper",
806
- children: [/* @__PURE__ */ jsx("div", {
807
- className: "simplebar-height-auto-observer-wrapper",
808
- children: /* @__PURE__ */ jsx("div", {
809
- className: "simplebar-height-auto-observer"
810
- })
811
- }), /* @__PURE__ */ jsx("div", {
812
- className: "simplebar-mask",
813
- children: /* @__PURE__ */ jsx("div", {
814
- className: "simplebar-offset",
815
- children: typeof children === "function" ? children({
816
- scrollableNodeRef,
817
- contentNodeRef
818
- }) : /* @__PURE__ */ jsx("div", {
819
- ...scrollableNodeProps,
820
- className: "simplebar-content-wrapper".concat(scrollableNodeProps.className ? " ".concat(scrollableNodeProps.className) : ""),
821
- children: /* @__PURE__ */ jsx("div", {
822
- className: "simplebar-content",
823
- children
824
- })
825
- })
826
- })
827
- }), /* @__PURE__ */ jsx("div", {
828
- className: "simplebar-placeholder"
829
- })]
830
- }), /* @__PURE__ */ jsx("div", {
831
- className: "simplebar-track simplebar-horizontal",
832
- children: /* @__PURE__ */ jsx("div", {
833
- className: "simplebar-scrollbar"
834
- })
835
- }), /* @__PURE__ */ jsx("div", {
836
- className: "simplebar-track simplebar-vertical",
837
- children: /* @__PURE__ */ jsx("div", {
838
- className: "simplebar-scrollbar"
839
- })
840
- })]
841
- });
842
- });
843
- SimpleBar.displayName = "SimpleBar";
844
- SimpleBar.propTypes = {
845
- children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
846
- scrollableNodeProps: PropTypes.object,
847
- tag: PropTypes.string
848
- };
849
- const simplebar_min = "";
850
- export { SimpleBar as S };