bj-web-components 0.2.26 → 0.2.28

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.
Files changed (109) hide show
  1. package/dist/favicon.ico +0 -0
  2. package/dist/file.svg +1 -0
  3. package/dist/globe.svg +1 -0
  4. package/dist/index.d.ts +1141 -0
  5. package/dist/index.js +51 -0
  6. package/dist/index.mjs +51 -0
  7. package/dist/miniapp.d.ts +1 -0
  8. package/dist/miniapp.js +1 -0
  9. package/dist/miniapp.mjs +1 -0
  10. package/dist/mobile.d.ts +1 -0
  11. package/dist/mobile.js +1 -0
  12. package/dist/mobile.mjs +1 -0
  13. package/dist/next.svg +1 -0
  14. package/dist/react.d.ts +1 -0
  15. package/dist/react.js +1 -0
  16. package/dist/react.mjs +1 -0
  17. package/dist/shared.d.ts +1 -0
  18. package/dist/shared.js +1 -0
  19. package/dist/shared.mjs +1 -0
  20. package/dist/style.css +3744 -0
  21. package/dist/vercel.svg +1 -0
  22. package/dist/web/BasicInput/BInput.js +208 -0
  23. package/dist/web/BasicInput/BInput.mjs +209 -0
  24. package/dist/web/BasicInput/utils.js +47 -0
  25. package/dist/web/BasicInput/utils.mjs +47 -0
  26. package/dist/web/CategoryDropdown/CategoryDropdown.js +307 -0
  27. package/dist/web/CategoryDropdown/CategoryDropdown.mjs +308 -0
  28. package/dist/web/CheckBox/BCheckBox.js +116 -0
  29. package/dist/web/CheckBox/BCheckBox.mjs +117 -0
  30. package/dist/web/CheckBox/Group.js +73 -0
  31. package/dist/web/CheckBox/Group.mjs +74 -0
  32. package/dist/web/CheckBox/context.js +5 -0
  33. package/dist/web/CheckBox/context.mjs +5 -0
  34. package/dist/web/CheckBox/index.js +8 -0
  35. package/dist/web/CheckBox/index.mjs +8 -0
  36. package/dist/web/Dropdown/BDropdown.js +186 -0
  37. package/dist/web/Dropdown/BDropdown.mjs +186 -0
  38. package/dist/web/EmptyInputBox/EmptyInputBox.js +77 -0
  39. package/dist/web/EmptyInputBox/EmptyInputBox.mjs +78 -0
  40. package/dist/web/FileCard/FileCard.js +157 -0
  41. package/dist/web/FileCard/FileCard.mjs +158 -0
  42. package/dist/web/Icon/Icon.js +9 -0
  43. package/dist/web/Icon/Icon.mjs +10 -0
  44. package/dist/web/Input/Input.js +181 -0
  45. package/dist/web/Input/Input.mjs +182 -0
  46. package/dist/web/InputNumber/BInputNumber.js +311 -0
  47. package/dist/web/InputNumber/BInputNumber.mjs +312 -0
  48. package/dist/web/InputNumber/StepHandler.js +69 -0
  49. package/dist/web/InputNumber/StepHandler.mjs +70 -0
  50. package/dist/web/InputNumber/hooks/useCursor.js +40 -0
  51. package/dist/web/InputNumber/hooks/useCursor.mjs +41 -0
  52. package/dist/web/InputNumber/hooks/useFrame.js +12 -0
  53. package/dist/web/InputNumber/hooks/useFrame.mjs +13 -0
  54. package/dist/web/InputNumber/utils/decimal.js +147 -0
  55. package/dist/web/InputNumber/utils/decimal.mjs +147 -0
  56. package/dist/web/Modal/Modal.js +84 -0
  57. package/dist/web/Modal/Modal.mjs +85 -0
  58. package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +232 -0
  59. package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +233 -0
  60. package/dist/web/Pagination/Pagination.js +328 -0
  61. package/dist/web/Pagination/Pagination.mjs +329 -0
  62. package/dist/web/ProductField/ProductField.js +272 -0
  63. package/dist/web/ProductField/ProductField.mjs +273 -0
  64. package/dist/web/ProductField/arrow-up.svg.js +3 -0
  65. package/dist/web/ProductField/arrow-up.svg.mjs +4 -0
  66. package/dist/web/ProductField/checkbox-no.svg.js +3 -0
  67. package/dist/web/ProductField/checkbox-no.svg.mjs +4 -0
  68. package/dist/web/ProductField/checkbox-ok.svg.js +3 -0
  69. package/dist/web/ProductField/checkbox-ok.svg.mjs +4 -0
  70. package/dist/web/ProductField/no_data_light.svg.js +3 -0
  71. package/dist/web/ProductField/no_data_light.svg.mjs +4 -0
  72. package/dist/web/ProductField/search.svg.js +3 -0
  73. package/dist/web/ProductField/search.svg.mjs +4 -0
  74. package/dist/web/ProductField/sort.svg.js +3 -0
  75. package/dist/web/ProductField/sort.svg.mjs +4 -0
  76. package/dist/web/SkuInputCard/SkuInputCard.js +276 -0
  77. package/dist/web/SkuInputCard/SkuInputCard.mjs +277 -0
  78. package/dist/web/SkuInputCard/spin_loading_red.gif.js +3 -0
  79. package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +4 -0
  80. package/dist/web/Switch/Switch.js +70 -0
  81. package/dist/web/Switch/Switch.mjs +71 -0
  82. package/dist/web/Table/BTable.js +950 -0
  83. package/dist/web/Table/BTable.mjs +950 -0
  84. package/dist/web/Table/Column.js +5 -0
  85. package/dist/web/Table/Column.mjs +6 -0
  86. package/dist/web/Table/ColumnGroup.js +5 -0
  87. package/dist/web/Table/ColumnGroup.mjs +6 -0
  88. package/dist/web/Table/utils/columns.js +48 -0
  89. package/dist/web/Table/utils/columns.mjs +48 -0
  90. package/dist/web/Table/utils/sortFilter.js +84 -0
  91. package/dist/web/Table/utils/sortFilter.mjs +84 -0
  92. package/dist/web/Tabs/BTabs.js +150 -0
  93. package/dist/web/Tabs/BTabs.mjs +150 -0
  94. package/dist/web/Tabs/TabPane.js +8 -0
  95. package/dist/web/Tabs/TabPane.mjs +8 -0
  96. package/dist/web/Tooltip/ConfirmTooltip.js +26 -0
  97. package/dist/web/Tooltip/ConfirmTooltip.mjs +27 -0
  98. package/dist/web/Tooltip/ContentTooltip.js +94 -0
  99. package/dist/web/Tooltip/ContentTooltip.mjs +95 -0
  100. package/dist/web/Tooltip/ProgressTooltip.js +36 -0
  101. package/dist/web/Tooltip/ProgressTooltip.mjs +37 -0
  102. package/dist/web/Tooltip/TooltipWrapper.js +12 -0
  103. package/dist/web/Tooltip/TooltipWrapper.mjs +13 -0
  104. package/dist/web/Tooltip/useAutoPlacement.js +41 -0
  105. package/dist/web/Tooltip/useAutoPlacement.mjs +41 -0
  106. package/dist/web.d.ts +1141 -0
  107. package/dist/web.js +51 -0
  108. package/dist/web.mjs +51 -0
  109. package/package.json +1 -1
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ const jsxRuntime = require("react/jsx-runtime");
3
+ const react = require("react");
4
+ ;/* empty css */
5
+ const MIN_THUMB_SIZE = 24;
6
+ const HIDE_DELAY = 800;
7
+ const EMPTY_THUMB = { visible: false, offset: 0, length: 0, cross: 0 };
8
+ function BOverlayScrollbar({
9
+ containerRef,
10
+ targetRef,
11
+ selector,
12
+ direction = "vertical",
13
+ size = 4,
14
+ gap = 0,
15
+ background,
16
+ showOnHover = true,
17
+ showOnScroll = true,
18
+ hoverSelector,
19
+ horizontalInsetStart = 0,
20
+ horizontalInsetEnd = 0,
21
+ horizontalThumbLength,
22
+ className = ""
23
+ }) {
24
+ const showVertical = direction === "vertical" || direction === "both";
25
+ const showHorizontal = direction === "horizontal" || direction === "both";
26
+ const scrollElementRef = react.useRef(null);
27
+ const dragRef = react.useRef(null);
28
+ const hideTimerRef = react.useRef(null);
29
+ const hoverTargetRef = react.useRef(false);
30
+ const thumbHoverRef = react.useRef(false);
31
+ const [verticalThumb, setVerticalThumb] = react.useState(EMPTY_THUMB);
32
+ const [horizontalThumb, setHorizontalThumb] = react.useState(EMPTY_THUMB);
33
+ const [active, setActive] = react.useState(!showOnHover);
34
+ react.useEffect(() => {
35
+ if (!showOnHover) setActive(true);
36
+ }, [showOnHover]);
37
+ const sync = react.useCallback(() => {
38
+ const element = scrollElementRef.current;
39
+ const container = containerRef.current;
40
+ if (!element || !container) return;
41
+ const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = element;
42
+ const elementRect = element.getBoundingClientRect();
43
+ const containerRect = container.getBoundingClientRect();
44
+ const offsetTop = elementRect.top - containerRect.top;
45
+ const offsetLeft = elementRect.left - containerRect.left;
46
+ if (showVertical) {
47
+ const maxScroll = scrollHeight - clientHeight;
48
+ if (maxScroll <= 1) {
49
+ setVerticalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
50
+ } else {
51
+ const length = Math.max(clientHeight / scrollHeight * clientHeight, MIN_THUMB_SIZE);
52
+ setVerticalThumb({
53
+ visible: true,
54
+ offset: offsetTop + scrollTop / maxScroll * (clientHeight - length),
55
+ length,
56
+ cross: offsetLeft + clientWidth - size - gap
57
+ });
58
+ }
59
+ }
60
+ if (showHorizontal) {
61
+ const maxScroll = scrollWidth - clientWidth;
62
+ const trackLength = Math.max(clientWidth - horizontalInsetStart - horizontalInsetEnd, 0);
63
+ if (maxScroll <= 1 || trackLength <= 0) {
64
+ setHorizontalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
65
+ } else {
66
+ const proportionalLength = clientWidth / scrollWidth * trackLength;
67
+ const length = Math.min(trackLength, Math.max(horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
68
+ setHorizontalThumb({
69
+ visible: true,
70
+ offset: offsetLeft + horizontalInsetStart + scrollLeft / maxScroll * (trackLength - length),
71
+ length,
72
+ cross: offsetTop + clientHeight - size - gap
73
+ });
74
+ }
75
+ }
76
+ }, [containerRef, gap, horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength, showHorizontal, showVertical, size]);
77
+ const wakeUp = react.useCallback(() => {
78
+ if (!showOnHover) return;
79
+ const interacting = hoverTargetRef.current || thumbHoverRef.current || dragRef.current;
80
+ if (!showOnScroll && !interacting) {
81
+ setActive(false);
82
+ return;
83
+ }
84
+ setActive(true);
85
+ if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
86
+ hideTimerRef.current = setTimeout(() => {
87
+ if (!dragRef.current && !hoverTargetRef.current && !thumbHoverRef.current) setActive(false);
88
+ }, HIDE_DELAY);
89
+ }, [showOnHover, showOnScroll]);
90
+ const onScroll = react.useCallback(() => {
91
+ sync();
92
+ wakeUp();
93
+ }, [sync, wakeUp]);
94
+ react.useEffect(() => {
95
+ const container = containerRef.current;
96
+ if (!container) return;
97
+ if (window.getComputedStyle(container).position === "static") container.style.position = "relative";
98
+ let detach;
99
+ let hoverElement = null;
100
+ const attach = () => {
101
+ const element = (targetRef == null ? void 0 : targetRef.current) ?? (selector ? container.querySelector(selector) : container.firstElementChild);
102
+ if (!element || element === scrollElementRef.current) return;
103
+ detach == null ? void 0 : detach();
104
+ scrollElementRef.current = element;
105
+ element.addEventListener("scroll", onScroll, { passive: true });
106
+ const observer = new ResizeObserver(sync);
107
+ observer.observe(element);
108
+ if (element.firstElementChild) observer.observe(element.firstElementChild);
109
+ detach = () => {
110
+ element.removeEventListener("scroll", onScroll);
111
+ observer.disconnect();
112
+ };
113
+ sync();
114
+ };
115
+ const onEnter = () => {
116
+ hoverTargetRef.current = true;
117
+ if (showOnHover) setActive(true);
118
+ };
119
+ const onLeave = () => {
120
+ hoverTargetRef.current = false;
121
+ if (showOnHover && !thumbHoverRef.current && !dragRef.current) setActive(false);
122
+ };
123
+ const detachHover = () => {
124
+ hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseenter", onEnter);
125
+ hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseleave", onLeave);
126
+ hoverElement = null;
127
+ hoverTargetRef.current = false;
128
+ };
129
+ const attachHover = () => {
130
+ const next = hoverSelector ? container.querySelector(hoverSelector) : container;
131
+ if (!next || next === hoverElement) return;
132
+ detachHover();
133
+ hoverElement = next;
134
+ hoverElement.addEventListener("mouseenter", onEnter);
135
+ hoverElement.addEventListener("mouseleave", onLeave);
136
+ };
137
+ attach();
138
+ attachHover();
139
+ const mutation = new MutationObserver(() => {
140
+ if (!scrollElementRef.current || !container.contains(scrollElementRef.current)) attach();
141
+ if (hoverElement && !container.contains(hoverElement)) detachHover();
142
+ if (!hoverElement) attachHover();
143
+ sync();
144
+ });
145
+ mutation.observe(container, { childList: true, subtree: true });
146
+ return () => {
147
+ mutation.disconnect();
148
+ detach == null ? void 0 : detach();
149
+ detachHover();
150
+ scrollElementRef.current = null;
151
+ if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
152
+ };
153
+ }, [containerRef, hoverSelector, onScroll, selector, showOnHover, sync, targetRef]);
154
+ const onDragMove = react.useCallback((event) => {
155
+ const element = scrollElementRef.current;
156
+ const start = dragRef.current;
157
+ if (!element || !start) return;
158
+ const vertical = start.axis === "vertical";
159
+ const clientSize = vertical ? element.clientHeight : element.clientWidth;
160
+ const scrollSize = vertical ? element.scrollHeight : element.scrollWidth;
161
+ const trackLength = vertical ? clientSize : Math.max(clientSize - horizontalInsetStart - horizontalInsetEnd, 0);
162
+ const proportionalLength = clientSize / scrollSize * trackLength;
163
+ const thumbLength = Math.min(trackLength, Math.max(vertical ? proportionalLength : horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
164
+ const trackRange = trackLength - thumbLength;
165
+ if (trackRange <= 0) return;
166
+ const delta = (vertical ? event.clientY : event.clientX) - start.client;
167
+ const moved = start.scroll + delta * ((scrollSize - clientSize) / trackRange);
168
+ if (vertical) element.scrollTop = moved;
169
+ else element.scrollLeft = moved;
170
+ }, [horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength]);
171
+ const onDragEnd = react.useCallback(() => {
172
+ const wasDragging = Boolean(dragRef.current);
173
+ dragRef.current = null;
174
+ document.body.style.userSelect = "";
175
+ document.removeEventListener("mousemove", onDragMove);
176
+ document.removeEventListener("mouseup", onDragEnd);
177
+ if (wasDragging) wakeUp();
178
+ }, [onDragMove, wakeUp]);
179
+ const startDrag = (axis) => (event) => {
180
+ const element = scrollElementRef.current;
181
+ if (!element) return;
182
+ event.preventDefault();
183
+ event.stopPropagation();
184
+ dragRef.current = {
185
+ axis,
186
+ client: axis === "vertical" ? event.clientY : event.clientX,
187
+ scroll: axis === "vertical" ? element.scrollTop : element.scrollLeft
188
+ };
189
+ document.body.style.userSelect = "none";
190
+ document.addEventListener("mousemove", onDragMove);
191
+ document.addEventListener("mouseup", onDragEnd);
192
+ };
193
+ react.useEffect(() => () => {
194
+ dragRef.current = null;
195
+ document.body.style.userSelect = "";
196
+ document.removeEventListener("mousemove", onDragMove);
197
+ document.removeEventListener("mouseup", onDragEnd);
198
+ }, [onDragEnd, onDragMove]);
199
+ const thumbClassName = ["bj-overlay-scrollbar__thumb", active && "bj-overlay-scrollbar__thumb--active", className].filter(Boolean).join(" ");
200
+ const colorStyle = background ? { "--bj-overlay-scrollbar-bg": background } : void 0;
201
+ const onThumbEnter = () => {
202
+ thumbHoverRef.current = true;
203
+ if (showOnHover) setActive(true);
204
+ };
205
+ const onThumbLeave = () => {
206
+ thumbHoverRef.current = false;
207
+ if (showOnHover && !hoverTargetRef.current && !dragRef.current) setActive(false);
208
+ };
209
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
210
+ showVertical && verticalThumb.visible && /* @__PURE__ */ jsxRuntime.jsx(
211
+ "div",
212
+ {
213
+ className: `${thumbClassName} bj-overlay-scrollbar__thumb--vertical`,
214
+ onMouseDown: startDrag("vertical"),
215
+ onMouseEnter: onThumbEnter,
216
+ onMouseLeave: onThumbLeave,
217
+ style: { ...colorStyle, top: verticalThumb.offset, left: verticalThumb.cross, height: verticalThumb.length, width: size }
218
+ }
219
+ ),
220
+ showHorizontal && horizontalThumb.visible && /* @__PURE__ */ jsxRuntime.jsx(
221
+ "div",
222
+ {
223
+ className: `${thumbClassName} bj-overlay-scrollbar__thumb--horizontal`,
224
+ onMouseDown: startDrag("horizontal"),
225
+ onMouseEnter: onThumbEnter,
226
+ onMouseLeave: onThumbLeave,
227
+ style: { ...colorStyle, left: horizontalThumb.offset, top: horizontalThumb.cross, width: horizontalThumb.length, height: size }
228
+ }
229
+ )
230
+ ] });
231
+ }
232
+ module.exports = BOverlayScrollbar;
@@ -0,0 +1,233 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import { useRef, useState, useEffect, useCallback } from "react";
3
+ /* empty css */
4
+ const MIN_THUMB_SIZE = 24;
5
+ const HIDE_DELAY = 800;
6
+ const EMPTY_THUMB = { visible: false, offset: 0, length: 0, cross: 0 };
7
+ function BOverlayScrollbar({
8
+ containerRef,
9
+ targetRef,
10
+ selector,
11
+ direction = "vertical",
12
+ size = 4,
13
+ gap = 0,
14
+ background,
15
+ showOnHover = true,
16
+ showOnScroll = true,
17
+ hoverSelector,
18
+ horizontalInsetStart = 0,
19
+ horizontalInsetEnd = 0,
20
+ horizontalThumbLength,
21
+ className = ""
22
+ }) {
23
+ const showVertical = direction === "vertical" || direction === "both";
24
+ const showHorizontal = direction === "horizontal" || direction === "both";
25
+ const scrollElementRef = useRef(null);
26
+ const dragRef = useRef(null);
27
+ const hideTimerRef = useRef(null);
28
+ const hoverTargetRef = useRef(false);
29
+ const thumbHoverRef = useRef(false);
30
+ const [verticalThumb, setVerticalThumb] = useState(EMPTY_THUMB);
31
+ const [horizontalThumb, setHorizontalThumb] = useState(EMPTY_THUMB);
32
+ const [active, setActive] = useState(!showOnHover);
33
+ useEffect(() => {
34
+ if (!showOnHover) setActive(true);
35
+ }, [showOnHover]);
36
+ const sync = useCallback(() => {
37
+ const element = scrollElementRef.current;
38
+ const container = containerRef.current;
39
+ if (!element || !container) return;
40
+ const { scrollTop, scrollHeight, clientHeight, scrollLeft, scrollWidth, clientWidth } = element;
41
+ const elementRect = element.getBoundingClientRect();
42
+ const containerRect = container.getBoundingClientRect();
43
+ const offsetTop = elementRect.top - containerRect.top;
44
+ const offsetLeft = elementRect.left - containerRect.left;
45
+ if (showVertical) {
46
+ const maxScroll = scrollHeight - clientHeight;
47
+ if (maxScroll <= 1) {
48
+ setVerticalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
49
+ } else {
50
+ const length = Math.max(clientHeight / scrollHeight * clientHeight, MIN_THUMB_SIZE);
51
+ setVerticalThumb({
52
+ visible: true,
53
+ offset: offsetTop + scrollTop / maxScroll * (clientHeight - length),
54
+ length,
55
+ cross: offsetLeft + clientWidth - size - gap
56
+ });
57
+ }
58
+ }
59
+ if (showHorizontal) {
60
+ const maxScroll = scrollWidth - clientWidth;
61
+ const trackLength = Math.max(clientWidth - horizontalInsetStart - horizontalInsetEnd, 0);
62
+ if (maxScroll <= 1 || trackLength <= 0) {
63
+ setHorizontalThumb((previous) => previous.visible ? EMPTY_THUMB : previous);
64
+ } else {
65
+ const proportionalLength = clientWidth / scrollWidth * trackLength;
66
+ const length = Math.min(trackLength, Math.max(horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
67
+ setHorizontalThumb({
68
+ visible: true,
69
+ offset: offsetLeft + horizontalInsetStart + scrollLeft / maxScroll * (trackLength - length),
70
+ length,
71
+ cross: offsetTop + clientHeight - size - gap
72
+ });
73
+ }
74
+ }
75
+ }, [containerRef, gap, horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength, showHorizontal, showVertical, size]);
76
+ const wakeUp = useCallback(() => {
77
+ if (!showOnHover) return;
78
+ const interacting = hoverTargetRef.current || thumbHoverRef.current || dragRef.current;
79
+ if (!showOnScroll && !interacting) {
80
+ setActive(false);
81
+ return;
82
+ }
83
+ setActive(true);
84
+ if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
85
+ hideTimerRef.current = setTimeout(() => {
86
+ if (!dragRef.current && !hoverTargetRef.current && !thumbHoverRef.current) setActive(false);
87
+ }, HIDE_DELAY);
88
+ }, [showOnHover, showOnScroll]);
89
+ const onScroll = useCallback(() => {
90
+ sync();
91
+ wakeUp();
92
+ }, [sync, wakeUp]);
93
+ useEffect(() => {
94
+ const container = containerRef.current;
95
+ if (!container) return;
96
+ if (window.getComputedStyle(container).position === "static") container.style.position = "relative";
97
+ let detach;
98
+ let hoverElement = null;
99
+ const attach = () => {
100
+ const element = (targetRef == null ? void 0 : targetRef.current) ?? (selector ? container.querySelector(selector) : container.firstElementChild);
101
+ if (!element || element === scrollElementRef.current) return;
102
+ detach == null ? void 0 : detach();
103
+ scrollElementRef.current = element;
104
+ element.addEventListener("scroll", onScroll, { passive: true });
105
+ const observer = new ResizeObserver(sync);
106
+ observer.observe(element);
107
+ if (element.firstElementChild) observer.observe(element.firstElementChild);
108
+ detach = () => {
109
+ element.removeEventListener("scroll", onScroll);
110
+ observer.disconnect();
111
+ };
112
+ sync();
113
+ };
114
+ const onEnter = () => {
115
+ hoverTargetRef.current = true;
116
+ if (showOnHover) setActive(true);
117
+ };
118
+ const onLeave = () => {
119
+ hoverTargetRef.current = false;
120
+ if (showOnHover && !thumbHoverRef.current && !dragRef.current) setActive(false);
121
+ };
122
+ const detachHover = () => {
123
+ hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseenter", onEnter);
124
+ hoverElement == null ? void 0 : hoverElement.removeEventListener("mouseleave", onLeave);
125
+ hoverElement = null;
126
+ hoverTargetRef.current = false;
127
+ };
128
+ const attachHover = () => {
129
+ const next = hoverSelector ? container.querySelector(hoverSelector) : container;
130
+ if (!next || next === hoverElement) return;
131
+ detachHover();
132
+ hoverElement = next;
133
+ hoverElement.addEventListener("mouseenter", onEnter);
134
+ hoverElement.addEventListener("mouseleave", onLeave);
135
+ };
136
+ attach();
137
+ attachHover();
138
+ const mutation = new MutationObserver(() => {
139
+ if (!scrollElementRef.current || !container.contains(scrollElementRef.current)) attach();
140
+ if (hoverElement && !container.contains(hoverElement)) detachHover();
141
+ if (!hoverElement) attachHover();
142
+ sync();
143
+ });
144
+ mutation.observe(container, { childList: true, subtree: true });
145
+ return () => {
146
+ mutation.disconnect();
147
+ detach == null ? void 0 : detach();
148
+ detachHover();
149
+ scrollElementRef.current = null;
150
+ if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
151
+ };
152
+ }, [containerRef, hoverSelector, onScroll, selector, showOnHover, sync, targetRef]);
153
+ const onDragMove = useCallback((event) => {
154
+ const element = scrollElementRef.current;
155
+ const start = dragRef.current;
156
+ if (!element || !start) return;
157
+ const vertical = start.axis === "vertical";
158
+ const clientSize = vertical ? element.clientHeight : element.clientWidth;
159
+ const scrollSize = vertical ? element.scrollHeight : element.scrollWidth;
160
+ const trackLength = vertical ? clientSize : Math.max(clientSize - horizontalInsetStart - horizontalInsetEnd, 0);
161
+ const proportionalLength = clientSize / scrollSize * trackLength;
162
+ const thumbLength = Math.min(trackLength, Math.max(vertical ? proportionalLength : horizontalThumbLength ?? proportionalLength, MIN_THUMB_SIZE));
163
+ const trackRange = trackLength - thumbLength;
164
+ if (trackRange <= 0) return;
165
+ const delta = (vertical ? event.clientY : event.clientX) - start.client;
166
+ const moved = start.scroll + delta * ((scrollSize - clientSize) / trackRange);
167
+ if (vertical) element.scrollTop = moved;
168
+ else element.scrollLeft = moved;
169
+ }, [horizontalInsetEnd, horizontalInsetStart, horizontalThumbLength]);
170
+ const onDragEnd = useCallback(() => {
171
+ const wasDragging = Boolean(dragRef.current);
172
+ dragRef.current = null;
173
+ document.body.style.userSelect = "";
174
+ document.removeEventListener("mousemove", onDragMove);
175
+ document.removeEventListener("mouseup", onDragEnd);
176
+ if (wasDragging) wakeUp();
177
+ }, [onDragMove, wakeUp]);
178
+ const startDrag = (axis) => (event) => {
179
+ const element = scrollElementRef.current;
180
+ if (!element) return;
181
+ event.preventDefault();
182
+ event.stopPropagation();
183
+ dragRef.current = {
184
+ axis,
185
+ client: axis === "vertical" ? event.clientY : event.clientX,
186
+ scroll: axis === "vertical" ? element.scrollTop : element.scrollLeft
187
+ };
188
+ document.body.style.userSelect = "none";
189
+ document.addEventListener("mousemove", onDragMove);
190
+ document.addEventListener("mouseup", onDragEnd);
191
+ };
192
+ useEffect(() => () => {
193
+ dragRef.current = null;
194
+ document.body.style.userSelect = "";
195
+ document.removeEventListener("mousemove", onDragMove);
196
+ document.removeEventListener("mouseup", onDragEnd);
197
+ }, [onDragEnd, onDragMove]);
198
+ const thumbClassName = ["bj-overlay-scrollbar__thumb", active && "bj-overlay-scrollbar__thumb--active", className].filter(Boolean).join(" ");
199
+ const colorStyle = background ? { "--bj-overlay-scrollbar-bg": background } : void 0;
200
+ const onThumbEnter = () => {
201
+ thumbHoverRef.current = true;
202
+ if (showOnHover) setActive(true);
203
+ };
204
+ const onThumbLeave = () => {
205
+ thumbHoverRef.current = false;
206
+ if (showOnHover && !hoverTargetRef.current && !dragRef.current) setActive(false);
207
+ };
208
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
209
+ showVertical && verticalThumb.visible && /* @__PURE__ */ jsx(
210
+ "div",
211
+ {
212
+ className: `${thumbClassName} bj-overlay-scrollbar__thumb--vertical`,
213
+ onMouseDown: startDrag("vertical"),
214
+ onMouseEnter: onThumbEnter,
215
+ onMouseLeave: onThumbLeave,
216
+ style: { ...colorStyle, top: verticalThumb.offset, left: verticalThumb.cross, height: verticalThumb.length, width: size }
217
+ }
218
+ ),
219
+ showHorizontal && horizontalThumb.visible && /* @__PURE__ */ jsx(
220
+ "div",
221
+ {
222
+ className: `${thumbClassName} bj-overlay-scrollbar__thumb--horizontal`,
223
+ onMouseDown: startDrag("horizontal"),
224
+ onMouseEnter: onThumbEnter,
225
+ onMouseLeave: onThumbLeave,
226
+ style: { ...colorStyle, left: horizontalThumb.offset, top: horizontalThumb.cross, width: horizontalThumb.length, height: size }
227
+ }
228
+ )
229
+ ] });
230
+ }
231
+ export {
232
+ BOverlayScrollbar as default
233
+ };