bj-web-components 0.2.28 → 0.2.29

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 (90) hide show
  1. package/dist/index.js +1 -51
  2. package/dist/index.mjs +49 -49
  3. package/dist/style.css +1 -3744
  4. package/dist/web/BasicInput/BInput.js +1 -208
  5. package/dist/web/BasicInput/BInput.mjs +132 -164
  6. package/dist/web/BasicInput/utils.js +1 -47
  7. package/dist/web/BasicInput/utils.mjs +28 -38
  8. package/dist/web/CategoryDropdown/CategoryDropdown.js +1 -307
  9. package/dist/web/CategoryDropdown/CategoryDropdown.mjs +170 -218
  10. package/dist/web/CheckBox/BCheckBox.js +1 -116
  11. package/dist/web/CheckBox/BCheckBox.mjs +70 -86
  12. package/dist/web/CheckBox/Group.js +1 -73
  13. package/dist/web/CheckBox/Group.mjs +56 -63
  14. package/dist/web/CheckBox/context.js +1 -5
  15. package/dist/web/CheckBox/context.mjs +3 -3
  16. package/dist/web/CheckBox/index.js +1 -8
  17. package/dist/web/CheckBox/index.mjs +6 -6
  18. package/dist/web/Dropdown/BDropdown.js +1 -186
  19. package/dist/web/Dropdown/BDropdown.mjs +106 -132
  20. package/dist/web/EmptyInputBox/EmptyInputBox.js +1 -77
  21. package/dist/web/EmptyInputBox/EmptyInputBox.mjs +48 -52
  22. package/dist/web/FileCard/FileCard.js +1 -157
  23. package/dist/web/FileCard/FileCard.mjs +82 -112
  24. package/dist/web/Icon/Icon.js +1 -9
  25. package/dist/web/Icon/Icon.mjs +6 -6
  26. package/dist/web/Input/Input.js +1 -181
  27. package/dist/web/Input/Input.mjs +113 -122
  28. package/dist/web/InputNumber/BInputNumber.js +1 -311
  29. package/dist/web/InputNumber/BInputNumber.mjs +167 -275
  30. package/dist/web/InputNumber/StepHandler.js +1 -69
  31. package/dist/web/InputNumber/StepHandler.mjs +32 -38
  32. package/dist/web/InputNumber/hooks/useCursor.js +1 -40
  33. package/dist/web/InputNumber/hooks/useCursor.mjs +33 -35
  34. package/dist/web/InputNumber/hooks/useFrame.js +1 -12
  35. package/dist/web/InputNumber/hooks/useFrame.mjs +6 -9
  36. package/dist/web/InputNumber/utils/decimal.js +1 -147
  37. package/dist/web/InputNumber/utils/decimal.mjs +81 -109
  38. package/dist/web/Modal/Modal.js +1 -84
  39. package/dist/web/Modal/Modal.mjs +49 -52
  40. package/dist/web/OverlayScrollbar/BOverlayScrollbar.js +1 -232
  41. package/dist/web/OverlayScrollbar/BOverlayScrollbar.mjs +125 -206
  42. package/dist/web/Pagination/Pagination.js +1 -328
  43. package/dist/web/Pagination/Pagination.mjs +178 -254
  44. package/dist/web/ProductField/ProductField.js +1 -272
  45. package/dist/web/ProductField/ProductField.mjs +143 -190
  46. package/dist/web/ProductField/arrow-up.svg.js +1 -3
  47. package/dist/web/ProductField/arrow-up.svg.mjs +2 -2
  48. package/dist/web/ProductField/checkbox-no.svg.js +1 -3
  49. package/dist/web/ProductField/checkbox-no.svg.mjs +2 -2
  50. package/dist/web/ProductField/checkbox-ok.svg.js +1 -3
  51. package/dist/web/ProductField/checkbox-ok.svg.mjs +2 -2
  52. package/dist/web/ProductField/no_data_light.svg.js +1 -3
  53. package/dist/web/ProductField/no_data_light.svg.mjs +2 -2
  54. package/dist/web/ProductField/search.svg.js +1 -3
  55. package/dist/web/ProductField/search.svg.mjs +2 -2
  56. package/dist/web/ProductField/sort.svg.js +1 -3
  57. package/dist/web/ProductField/sort.svg.mjs +2 -2
  58. package/dist/web/SkuInputCard/SkuInputCard.js +1 -276
  59. package/dist/web/SkuInputCard/SkuInputCard.mjs +149 -188
  60. package/dist/web/SkuInputCard/spin_loading_red.gif.js +1 -3
  61. package/dist/web/SkuInputCard/spin_loading_red.gif.mjs +2 -2
  62. package/dist/web/Switch/Switch.js +1 -70
  63. package/dist/web/Switch/Switch.mjs +37 -47
  64. package/dist/web/Table/BTable.js +1 -950
  65. package/dist/web/Table/BTable.mjs +521 -767
  66. package/dist/web/Table/Column.js +1 -5
  67. package/dist/web/Table/Column.mjs +2 -2
  68. package/dist/web/Table/ColumnGroup.js +1 -5
  69. package/dist/web/Table/ColumnGroup.mjs +2 -2
  70. package/dist/web/Table/utils/columns.js +1 -48
  71. package/dist/web/Table/utils/columns.mjs +30 -35
  72. package/dist/web/Table/utils/sortFilter.js +1 -84
  73. package/dist/web/Table/utils/sortFilter.mjs +52 -73
  74. package/dist/web/Tabs/BTabs.js +1 -150
  75. package/dist/web/Tabs/BTabs.mjs +98 -118
  76. package/dist/web/Tabs/TabPane.js +1 -8
  77. package/dist/web/Tabs/TabPane.mjs +4 -4
  78. package/dist/web/Tooltip/ConfirmTooltip.js +1 -26
  79. package/dist/web/Tooltip/ConfirmTooltip.mjs +19 -20
  80. package/dist/web/Tooltip/ContentTooltip.js +1 -94
  81. package/dist/web/Tooltip/ContentTooltip.mjs +62 -72
  82. package/dist/web/Tooltip/ProgressTooltip.js +1 -36
  83. package/dist/web/Tooltip/ProgressTooltip.mjs +20 -22
  84. package/dist/web/Tooltip/TooltipWrapper.js +1 -12
  85. package/dist/web/Tooltip/TooltipWrapper.mjs +8 -8
  86. package/dist/web/Tooltip/useAutoPlacement.js +1 -41
  87. package/dist/web/Tooltip/useAutoPlacement.mjs +25 -34
  88. package/dist/web.js +1 -51
  89. package/dist/web.mjs +49 -49
  90. package/package.json +1 -1
@@ -1,84 +1 @@
1
- "use strict";
2
- const jsxRuntime = require("react/jsx-runtime");
3
- ;/* empty css */
4
- function BuModal({
5
- open = false,
6
- title = "标题",
7
- mode = "standard",
8
- children,
9
- okText = "确认",
10
- cancelText = "取消",
11
- onOk,
12
- onCancel,
13
- onClose,
14
- activeLang = "zh",
15
- onLangChange,
16
- labels,
17
- hint,
18
- confirmLoading = false,
19
- width,
20
- className,
21
- style
22
- }) {
23
- const zhLabel = (labels == null ? void 0 : labels.zh) ?? "中文";
24
- const enLabel = (labels == null ? void 0 : labels.en) ?? "EN";
25
- if (!open) return null;
26
- const isBilingual = mode === "bilingual";
27
- const isSingle = mode === "single";
28
- const containerStyle = width != null ? { width, ...style } : style;
29
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: ["bu-modal__overlay", className].filter(Boolean).join(" "), onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsxs(
30
- "div",
31
- {
32
- className: "bu-modal__container",
33
- style: containerStyle,
34
- onClick: (e) => e.stopPropagation(),
35
- children: [
36
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__header", children: [
37
- /* @__PURE__ */ jsxRuntime.jsx("p", { className: "bu-modal__title", children: title }),
38
- isBilingual && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__lang-toggle", children: [
39
- /* @__PURE__ */ jsxRuntime.jsx(
40
- "button",
41
- {
42
- type: "button",
43
- className: `bu-modal__lang-btn${activeLang === "zh" ? " bu-modal__lang-btn--active" : ""}`,
44
- onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
45
- children: zhLabel
46
- }
47
- ),
48
- /* @__PURE__ */ jsxRuntime.jsx(
49
- "button",
50
- {
51
- type: "button",
52
- className: `bu-modal__lang-btn${activeLang === "en" ? " bu-modal__lang-btn--active" : ""}`,
53
- onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
54
- children: enLabel
55
- }
56
- )
57
- ] }),
58
- /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-modal__close", onClick: onClose, children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) }) })
59
- ] }),
60
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "bu-modal__body", children }),
61
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__footer", children: [
62
- hint && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "bu-modal__hint", children: hint }),
63
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bu-modal__btn-row", children: [
64
- !isSingle && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "bu-modal__btn-cancel", onClick: onCancel ?? onClose, children: cancelText }),
65
- /* @__PURE__ */ jsxRuntime.jsxs(
66
- "button",
67
- {
68
- type: "button",
69
- className: ["bu-modal__btn-ok", confirmLoading ? "bu-modal__btn-ok--loading" : ""].filter(Boolean).join(" "),
70
- disabled: confirmLoading,
71
- onClick: confirmLoading ? void 0 : onOk,
72
- children: [
73
- confirmLoading && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "bu-modal__btn-ok-spinner" }),
74
- okText
75
- ]
76
- }
77
- )
78
- ] })
79
- ] })
80
- ]
81
- }
82
- ) });
83
- }
84
- module.exports = BuModal;
1
+ "use strict";const l=require("react/jsx-runtime");;/* empty css */function w({open:u=!1,title:r="标题",mode:o="standard",children:_,okText:b="确认",cancelText:m="取消",onOk:x,onCancel:j,onClose:i,activeLang:n="zh",onLangChange:s,labels:t,hint:c,confirmLoading:e=!1,width:a,className:N,style:d}){const h=(t==null?void 0:t.zh)??"中文",p=(t==null?void 0:t.en)??"EN";if(!u)return null;const v=o==="bilingual",k=o==="single",y=a!=null?{width:a,...d}:d;return l.jsx("div",{className:["bu-modal__overlay",N].filter(Boolean).join(" "),onClick:i,children:l.jsxs("div",{className:"bu-modal__container",style:y,onClick:f=>f.stopPropagation(),children:[l.jsxs("div",{className:"bu-modal__header",children:[l.jsx("p",{className:"bu-modal__title",children:r}),v&&l.jsxs("div",{className:"bu-modal__lang-toggle",children:[l.jsx("button",{type:"button",className:`bu-modal__lang-btn${n==="zh"?" bu-modal__lang-btn--active":""}`,onClick:()=>s==null?void 0:s("zh"),children:h}),l.jsx("button",{type:"button",className:`bu-modal__lang-btn${n==="en"?" bu-modal__lang-btn--active":""}`,onClick:()=>s==null?void 0:s("en"),children:p})]}),l.jsx("button",{type:"button",className:"bu-modal__close",onClick:i,children:l.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:l.jsx("path",{d:"M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z",fill:"currentColor"})})})]}),l.jsx("div",{className:"bu-modal__body",children:_}),l.jsxs("div",{className:"bu-modal__footer",children:[c&&l.jsx("p",{className:"bu-modal__hint",children:c}),l.jsxs("div",{className:"bu-modal__btn-row",children:[!k&&l.jsx("button",{type:"button",className:"bu-modal__btn-cancel",onClick:j??i,children:m}),l.jsxs("button",{type:"button",className:["bu-modal__btn-ok",e?"bu-modal__btn-ok--loading":""].filter(Boolean).join(" "),disabled:e,onClick:e?void 0:x,children:[e&&l.jsx("span",{className:"bu-modal__btn-ok-spinner"}),b]})]})]})]})})}module.exports=w;
@@ -1,76 +1,73 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx as l, jsxs as i } from "react/jsx-runtime";
2
2
  /* empty css */
3
- function BuModal({
4
- open = false,
5
- title = "标题",
6
- mode = "standard",
7
- children,
8
- okText = "确认",
9
- cancelText = "取消",
10
- onOk,
11
- onCancel,
12
- onClose,
13
- activeLang = "zh",
14
- onLangChange,
15
- labels,
16
- hint,
17
- confirmLoading = false,
18
- width,
19
- className,
20
- style
3
+ function j({
4
+ open: _ = !1,
5
+ title: r = "标题",
6
+ mode: n = "standard",
7
+ children: b,
8
+ okText: m = "确认",
9
+ cancelText: p = "取消",
10
+ onOk: N,
11
+ onCancel: h,
12
+ onClose: a,
13
+ activeLang: c = "zh",
14
+ onLangChange: t,
15
+ labels: o,
16
+ hint: d,
17
+ confirmLoading: e = !1,
18
+ width: s,
19
+ className: v,
20
+ style: u
21
21
  }) {
22
- const zhLabel = (labels == null ? void 0 : labels.zh) ?? "中文";
23
- const enLabel = (labels == null ? void 0 : labels.en) ?? "EN";
24
- if (!open) return null;
25
- const isBilingual = mode === "bilingual";
26
- const isSingle = mode === "single";
27
- const containerStyle = width != null ? { width, ...style } : style;
28
- return /* @__PURE__ */ jsx("div", { className: ["bu-modal__overlay", className].filter(Boolean).join(" "), onClick: onClose, children: /* @__PURE__ */ jsxs(
22
+ const k = (o == null ? void 0 : o.zh) ?? "中文", f = (o == null ? void 0 : o.en) ?? "EN";
23
+ if (!_) return null;
24
+ const y = n === "bilingual", w = n === "single", x = s != null ? { width: s, ...u } : u;
25
+ return /* @__PURE__ */ l("div", { className: ["bu-modal__overlay", v].filter(Boolean).join(" "), onClick: a, children: /* @__PURE__ */ i(
29
26
  "div",
30
27
  {
31
28
  className: "bu-modal__container",
32
- style: containerStyle,
33
- onClick: (e) => e.stopPropagation(),
29
+ style: x,
30
+ onClick: (z) => z.stopPropagation(),
34
31
  children: [
35
- /* @__PURE__ */ jsxs("div", { className: "bu-modal__header", children: [
36
- /* @__PURE__ */ jsx("p", { className: "bu-modal__title", children: title }),
37
- isBilingual && /* @__PURE__ */ jsxs("div", { className: "bu-modal__lang-toggle", children: [
38
- /* @__PURE__ */ jsx(
32
+ /* @__PURE__ */ i("div", { className: "bu-modal__header", children: [
33
+ /* @__PURE__ */ l("p", { className: "bu-modal__title", children: r }),
34
+ y && /* @__PURE__ */ i("div", { className: "bu-modal__lang-toggle", children: [
35
+ /* @__PURE__ */ l(
39
36
  "button",
40
37
  {
41
38
  type: "button",
42
- className: `bu-modal__lang-btn${activeLang === "zh" ? " bu-modal__lang-btn--active" : ""}`,
43
- onClick: () => onLangChange == null ? void 0 : onLangChange("zh"),
44
- children: zhLabel
39
+ className: `bu-modal__lang-btn${c === "zh" ? " bu-modal__lang-btn--active" : ""}`,
40
+ onClick: () => t == null ? void 0 : t("zh"),
41
+ children: k
45
42
  }
46
43
  ),
47
- /* @__PURE__ */ jsx(
44
+ /* @__PURE__ */ l(
48
45
  "button",
49
46
  {
50
47
  type: "button",
51
- className: `bu-modal__lang-btn${activeLang === "en" ? " bu-modal__lang-btn--active" : ""}`,
52
- onClick: () => onLangChange == null ? void 0 : onLangChange("en"),
53
- children: enLabel
48
+ className: `bu-modal__lang-btn${c === "en" ? " bu-modal__lang-btn--active" : ""}`,
49
+ onClick: () => t == null ? void 0 : t("en"),
50
+ children: f
54
51
  }
55
52
  )
56
53
  ] }),
57
- /* @__PURE__ */ jsx("button", { type: "button", className: "bu-modal__close", onClick: onClose, children: /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsx("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) }) })
54
+ /* @__PURE__ */ l("button", { type: "button", className: "bu-modal__close", onClick: a, children: /* @__PURE__ */ l("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ l("path", { d: "M16.5613 6.73027C16.7558 6.53571 17.0723 6.53442 17.2684 6.72736C17.4644 6.92032 17.4657 7.23444 17.2713 7.42901L12.7036 12.0002L17.2713 16.5714C17.4657 16.766 17.4644 17.0801 17.2684 17.273C17.0723 17.4659 16.7558 17.4646 16.5613 17.2701L11.9996 12.7047L7.43794 17.2701C7.24352 17.4647 6.92699 17.4659 6.73091 17.273C6.53485 17.0801 6.53355 16.7659 6.72798 16.5714L11.2955 12.0002L6.72798 7.42901C6.53355 7.23442 6.53485 6.92032 6.73091 6.72736C6.92698 6.53442 7.2435 6.53571 7.43794 6.73027L11.9996 11.2955L16.5613 6.73027Z", fill: "currentColor" }) }) })
58
55
  ] }),
59
- /* @__PURE__ */ jsx("div", { className: "bu-modal__body", children }),
60
- /* @__PURE__ */ jsxs("div", { className: "bu-modal__footer", children: [
61
- hint && /* @__PURE__ */ jsx("p", { className: "bu-modal__hint", children: hint }),
62
- /* @__PURE__ */ jsxs("div", { className: "bu-modal__btn-row", children: [
63
- !isSingle && /* @__PURE__ */ jsx("button", { type: "button", className: "bu-modal__btn-cancel", onClick: onCancel ?? onClose, children: cancelText }),
64
- /* @__PURE__ */ jsxs(
56
+ /* @__PURE__ */ l("div", { className: "bu-modal__body", children: b }),
57
+ /* @__PURE__ */ i("div", { className: "bu-modal__footer", children: [
58
+ d && /* @__PURE__ */ l("p", { className: "bu-modal__hint", children: d }),
59
+ /* @__PURE__ */ i("div", { className: "bu-modal__btn-row", children: [
60
+ !w && /* @__PURE__ */ l("button", { type: "button", className: "bu-modal__btn-cancel", onClick: h ?? a, children: p }),
61
+ /* @__PURE__ */ i(
65
62
  "button",
66
63
  {
67
64
  type: "button",
68
- className: ["bu-modal__btn-ok", confirmLoading ? "bu-modal__btn-ok--loading" : ""].filter(Boolean).join(" "),
69
- disabled: confirmLoading,
70
- onClick: confirmLoading ? void 0 : onOk,
65
+ className: ["bu-modal__btn-ok", e ? "bu-modal__btn-ok--loading" : ""].filter(Boolean).join(" "),
66
+ disabled: e,
67
+ onClick: e ? void 0 : N,
71
68
  children: [
72
- confirmLoading && /* @__PURE__ */ jsx("span", { className: "bu-modal__btn-ok-spinner" }),
73
- okText
69
+ e && /* @__PURE__ */ l("span", { className: "bu-modal__btn-ok-spinner" }),
70
+ m
74
71
  ]
75
72
  }
76
73
  )
@@ -81,5 +78,5 @@ function BuModal({
81
78
  ) });
82
79
  }
83
80
  export {
84
- BuModal as default
81
+ j as default
85
82
  };
@@ -1,232 +1 @@
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;
1
+ "use strict";const Y=require("react/jsx-runtime"),s=require("react");;/* empty css */const $=24,re=800,H={visible:!1,offset:0,length:0,cross:0};function se({containerRef:_,targetRef:j,selector:U,direction:S="vertical",size:E=4,gap:w=0,background:F,showOnHover:l=!0,showOnScroll:Z=!0,hoverSelector:A,horizontalInsetStart:p=0,horizontalInsetEnd:D=0,horizontalThumbLength:R,className:te=""}){const P=S==="vertical"||S==="both",V=S==="horizontal"||S==="both",m=s.useRef(null),f=s.useRef(null),y=s.useRef(null),L=s.useRef(!1),M=s.useRef(!1),[k,G]=s.useState(H),[B,J]=s.useState(H),[ne,v]=s.useState(!l);s.useEffect(()=>{l||v(!0)},[l]);const g=s.useCallback(()=>{const e=m.current,n=_.current;if(!e||!n)return;const{scrollTop:t,scrollHeight:o,clientHeight:c,scrollLeft:d,scrollWidth:u,clientWidth:i}=e,h=e.getBoundingClientRect(),r=n.getBoundingClientRect(),b=h.top-r.top,x=h.left-r.left;if(P){const C=o-c;if(C<=1)G(a=>a.visible?H:a);else{const a=Math.max(c/o*c,$);G({visible:!0,offset:b+t/C*(c-a),length:a,cross:x+i-E-w})}}if(V){const C=u-i,a=Math.max(i-p-D,0);if(C<=1||a<=0)J(W=>W.visible?H:W);else{const W=i/u*a,ee=Math.min(a,Math.max(R??W,$));J({visible:!0,offset:x+p+d/C*(a-ee),length:ee,cross:b+c-E-w})}}},[_,w,D,p,R,V,P,E]),q=s.useCallback(()=>{if(!l)return;const e=L.current||M.current||f.current;if(!Z&&!e){v(!1);return}v(!0),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{!f.current&&!L.current&&!M.current&&v(!1)},re)},[l,Z]),X=s.useCallback(()=>{g(),q()},[g,q]);s.useEffect(()=>{const e=_.current;if(!e)return;window.getComputedStyle(e).position==="static"&&(e.style.position="relative");let n,t=null;const o=()=>{const r=(j==null?void 0:j.current)??(U?e.querySelector(U):e.firstElementChild);if(!r||r===m.current)return;n==null||n(),m.current=r,r.addEventListener("scroll",X,{passive:!0});const b=new ResizeObserver(g);b.observe(r),r.firstElementChild&&b.observe(r.firstElementChild),n=()=>{r.removeEventListener("scroll",X),b.disconnect()},g()},c=()=>{L.current=!0,l&&v(!0)},d=()=>{L.current=!1,l&&!M.current&&!f.current&&v(!1)},u=()=>{t==null||t.removeEventListener("mouseenter",c),t==null||t.removeEventListener("mouseleave",d),t=null,L.current=!1},i=()=>{const r=A?e.querySelector(A):e;!r||r===t||(u(),t=r,t.addEventListener("mouseenter",c),t.addEventListener("mouseleave",d))};o(),i();const h=new MutationObserver(()=>{(!m.current||!e.contains(m.current))&&o(),t&&!e.contains(t)&&u(),t||i(),g()});return h.observe(e,{childList:!0,subtree:!0}),()=>{h.disconnect(),n==null||n(),u(),m.current=null,y.current&&clearTimeout(y.current)}},[_,A,X,U,l,g,j]);const T=s.useCallback(e=>{const n=m.current,t=f.current;if(!n||!t)return;const o=t.axis==="vertical",c=o?n.clientHeight:n.clientWidth,d=o?n.scrollHeight:n.scrollWidth,u=o?c:Math.max(c-p-D,0),i=c/d*u,h=Math.min(u,Math.max(o?i:R??i,$)),r=u-h;if(r<=0)return;const b=(o?e.clientY:e.clientX)-t.client,x=t.scroll+b*((d-c)/r);o?n.scrollTop=x:n.scrollLeft=x},[D,p,R]),N=s.useCallback(()=>{const e=!!f.current;f.current=null,document.body.style.userSelect="",document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",N),e&&q()},[T,q]),K=e=>n=>{const t=m.current;t&&(n.preventDefault(),n.stopPropagation(),f.current={axis:e,client:e==="vertical"?n.clientY:n.clientX,scroll:e==="vertical"?t.scrollTop:t.scrollLeft},document.body.style.userSelect="none",document.addEventListener("mousemove",T),document.addEventListener("mouseup",N))};s.useEffect(()=>()=>{f.current=null,document.body.style.userSelect="",document.removeEventListener("mousemove",T),document.removeEventListener("mouseup",N)},[N,T]);const Q=["bj-overlay-scrollbar__thumb",ne&&"bj-overlay-scrollbar__thumb--active",te].filter(Boolean).join(" "),I=F?{"--bj-overlay-scrollbar-bg":F}:void 0,z=()=>{M.current=!0,l&&v(!0)},O=()=>{M.current=!1,l&&!L.current&&!f.current&&v(!1)};return Y.jsxs(Y.Fragment,{children:[P&&k.visible&&Y.jsx("div",{className:`${Q} bj-overlay-scrollbar__thumb--vertical`,onMouseDown:K("vertical"),onMouseEnter:z,onMouseLeave:O,style:{...I,top:k.offset,left:k.cross,height:k.length,width:E}}),V&&B.visible&&Y.jsx("div",{className:`${Q} bj-overlay-scrollbar__thumb--horizontal`,onMouseDown:K("horizontal"),onMouseEnter:z,onMouseLeave:O,style:{...I,left:B.offset,top:B.cross,width:B.length,height:E}})]})}module.exports=se;