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,70 @@
1
+ import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
+ import { useRef, useEffect } from "react";
3
+ const STEP_DELAY = 600;
4
+ const STEP_INTERVAL = 200;
5
+ function SpinnerIcon({ className }) {
6
+ return /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className, children: /* @__PURE__ */ jsx(
7
+ "path",
8
+ {
9
+ d: "M15.4573 13.6501C15.9047 13.6504 16.129 14.192 15.8128 14.5085L12.3352 17.9851C12.139 18.1811 11.8214 18.1811 11.6253 17.9851L8.14772 14.5085C7.83144 14.192 8.0558 13.6504 8.50319 13.6501H15.4573ZM11.6643 5.98311C11.8606 5.78688 12.179 5.78688 12.3753 5.98311L15.8518 9.45967C16.1683 9.77623 15.944 10.3171 15.4964 10.3171H8.54323C8.09567 10.3171 7.87154 9.77625 8.18776 9.45967L11.6643 5.98311Z",
10
+ fill: "currentColor"
11
+ }
12
+ ) });
13
+ }
14
+ function StepHandler({ icon, upDisabled, downDisabled, onStep }) {
15
+ const stepTimeoutRef = useRef(void 0);
16
+ const onStepRef = useRef(onStep);
17
+ onStepRef.current = onStep;
18
+ const onStopStep = () => clearTimeout(stepTimeoutRef.current);
19
+ const onStepMouseDown = (e, up) => {
20
+ e.preventDefault();
21
+ onStopStep();
22
+ onStepRef.current(up);
23
+ function loopStep() {
24
+ onStepRef.current(up);
25
+ stepTimeoutRef.current = setTimeout(loopStep, STEP_INTERVAL);
26
+ }
27
+ stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY);
28
+ };
29
+ useEffect(() => onStopStep, []);
30
+ const sharedProps = {
31
+ unselectable: "on",
32
+ role: "button",
33
+ onMouseUp: onStopStep,
34
+ onMouseLeave: onStopStep
35
+ };
36
+ return (
37
+ // Click zones come before the icon(s) in DOM order so the icon halves
38
+ // can be dimmed via a `:hover ~`/`:active ~` sibling selector in CSS —
39
+ // the icon itself stays `pointer-events: none` and purely visual.
40
+ /* @__PURE__ */ jsxs("div", { className: "bj-input-number__handler-wrap", children: [
41
+ /* @__PURE__ */ jsx(
42
+ "span",
43
+ {
44
+ ...sharedProps,
45
+ "aria-label": "Increase Value",
46
+ "aria-disabled": upDisabled,
47
+ className: upDisabled ? "bj-input-number__handler bj-input-number__handler--up bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--up",
48
+ onMouseDown: (e) => onStepMouseDown(e, true)
49
+ }
50
+ ),
51
+ /* @__PURE__ */ jsx(
52
+ "span",
53
+ {
54
+ ...sharedProps,
55
+ "aria-label": "Decrease Value",
56
+ "aria-disabled": downDisabled,
57
+ className: downDisabled ? "bj-input-number__handler bj-input-number__handler--down bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--down",
58
+ onMouseDown: (e) => onStepMouseDown(e, false)
59
+ }
60
+ ),
61
+ icon || /* @__PURE__ */ jsxs(Fragment, { children: [
62
+ /* @__PURE__ */ jsx(SpinnerIcon, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--up" }),
63
+ /* @__PURE__ */ jsx(SpinnerIcon, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--down" })
64
+ ] })
65
+ ] })
66
+ );
67
+ }
68
+ export {
69
+ StepHandler as default
70
+ };
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ const react = require("react");
3
+ function useCursor(input, focused) {
4
+ const selectionRef = react.useRef(null);
5
+ function recordCursor() {
6
+ if (!input) return;
7
+ try {
8
+ const { selectionStart: start, selectionEnd: end, value } = input;
9
+ selectionRef.current = {
10
+ start: start ?? 0,
11
+ end: end ?? 0,
12
+ value,
13
+ beforeTxt: value.substring(0, start ?? 0),
14
+ afterTxt: value.substring(end ?? 0)
15
+ };
16
+ } catch {
17
+ }
18
+ }
19
+ function restoreCursor() {
20
+ if (!input || !selectionRef.current || !focused) return;
21
+ try {
22
+ const { value } = input;
23
+ const { beforeTxt, afterTxt, start } = selectionRef.current;
24
+ let startPos = value.length;
25
+ if (value.startsWith(beforeTxt)) {
26
+ startPos = beforeTxt.length;
27
+ } else if (value.endsWith(afterTxt)) {
28
+ startPos = value.length - afterTxt.length;
29
+ } else {
30
+ const beforeLastChar = beforeTxt[start - 1];
31
+ const newIndex = value.indexOf(beforeLastChar, start - 1);
32
+ if (newIndex !== -1) startPos = newIndex + 1;
33
+ }
34
+ input.setSelectionRange(startPos, startPos);
35
+ } catch {
36
+ }
37
+ }
38
+ return [recordCursor, restoreCursor];
39
+ }
40
+ module.exports = useCursor;
@@ -0,0 +1,41 @@
1
+ import { useRef } from "react";
2
+ function useCursor(input, focused) {
3
+ const selectionRef = useRef(null);
4
+ function recordCursor() {
5
+ if (!input) return;
6
+ try {
7
+ const { selectionStart: start, selectionEnd: end, value } = input;
8
+ selectionRef.current = {
9
+ start: start ?? 0,
10
+ end: end ?? 0,
11
+ value,
12
+ beforeTxt: value.substring(0, start ?? 0),
13
+ afterTxt: value.substring(end ?? 0)
14
+ };
15
+ } catch {
16
+ }
17
+ }
18
+ function restoreCursor() {
19
+ if (!input || !selectionRef.current || !focused) return;
20
+ try {
21
+ const { value } = input;
22
+ const { beforeTxt, afterTxt, start } = selectionRef.current;
23
+ let startPos = value.length;
24
+ if (value.startsWith(beforeTxt)) {
25
+ startPos = beforeTxt.length;
26
+ } else if (value.endsWith(afterTxt)) {
27
+ startPos = value.length - afterTxt.length;
28
+ } else {
29
+ const beforeLastChar = beforeTxt[start - 1];
30
+ const newIndex = value.indexOf(beforeLastChar, start - 1);
31
+ if (newIndex !== -1) startPos = newIndex + 1;
32
+ }
33
+ input.setSelectionRange(startPos, startPos);
34
+ } catch {
35
+ }
36
+ }
37
+ return [recordCursor, restoreCursor];
38
+ }
39
+ export {
40
+ useCursor as default
41
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ const react = require("react");
3
+ function useFrame() {
4
+ const idRef = react.useRef(0);
5
+ const cleanUp = () => cancelAnimationFrame(idRef.current);
6
+ react.useEffect(() => cleanUp, []);
7
+ return (callback) => {
8
+ cleanUp();
9
+ idRef.current = requestAnimationFrame(callback);
10
+ };
11
+ }
12
+ module.exports = useFrame;
@@ -0,0 +1,13 @@
1
+ import { useRef, useEffect } from "react";
2
+ function useFrame() {
3
+ const idRef = useRef(0);
4
+ const cleanUp = () => cancelAnimationFrame(idRef.current);
5
+ useEffect(() => cleanUp, []);
6
+ return (callback) => {
7
+ cleanUp();
8
+ idRef.current = requestAnimationFrame(callback);
9
+ };
10
+ }
11
+ export {
12
+ useFrame as default
13
+ };
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function isEmptyValue(value) {
4
+ return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();
5
+ }
6
+ function trimNumber(numStr) {
7
+ let str = numStr.trim();
8
+ let negative = str.startsWith("-");
9
+ if (negative) {
10
+ str = str.slice(1);
11
+ }
12
+ str = str.replace(/(\.\d*[^0])0*$/, "$1").replace(/\.0*$/, "").replace(/^0+/, "");
13
+ if (str.startsWith(".")) {
14
+ str = `0${str}`;
15
+ }
16
+ const trimStr = str || "0";
17
+ const splitNumber = trimStr.split(".");
18
+ const integerStr = splitNumber[0] || "0";
19
+ const decimalStr = splitNumber[1] || "0";
20
+ if (integerStr === "0" && decimalStr === "0") {
21
+ negative = false;
22
+ }
23
+ const negativeStr = negative ? "-" : "";
24
+ return {
25
+ negative,
26
+ negativeStr,
27
+ trimStr,
28
+ integerStr,
29
+ decimalStr,
30
+ fullStr: `${negativeStr}${trimStr}`
31
+ };
32
+ }
33
+ function isScientificNotation(number) {
34
+ const str = String(number);
35
+ return !Number.isNaN(Number(str)) && str.includes("e");
36
+ }
37
+ function getNumberPrecision(number) {
38
+ const numStr = String(number);
39
+ if (isScientificNotation(number)) {
40
+ const [, exp = "0"] = numStr.toLowerCase().split("e");
41
+ return Math.max(0, -Number(exp));
42
+ }
43
+ return numStr.includes(".") && validateNumber(numStr) ? numStr.length - numStr.indexOf(".") - 1 : 0;
44
+ }
45
+ function num2str(number) {
46
+ const numStr = String(number);
47
+ if (isScientificNotation(number)) {
48
+ if (number > Number.MAX_SAFE_INTEGER) return String(Number.MAX_SAFE_INTEGER);
49
+ if (number < Number.MIN_SAFE_INTEGER) return String(Number.MIN_SAFE_INTEGER);
50
+ return trimNumber(number.toFixed(getNumberPrecision(number))).fullStr;
51
+ }
52
+ return trimNumber(numStr).fullStr;
53
+ }
54
+ function validateNumber(num) {
55
+ if (typeof num === "number") {
56
+ return !Number.isNaN(num);
57
+ }
58
+ if (!num) return false;
59
+ const str = String(num);
60
+ return /^\s*-?\d+(\.\d+)?\s*$/.test(str) || // 11.28
61
+ /^\s*-?\d+\.\s*$/.test(str) || // 1.
62
+ /^\s*-?\.\d+\s*$/.test(str);
63
+ }
64
+ class Decimal {
65
+ constructor(value) {
66
+ this.origin = "";
67
+ if (isEmptyValue(value)) {
68
+ this.empty = true;
69
+ return;
70
+ }
71
+ this.origin = String(value);
72
+ this.number = Number(value);
73
+ }
74
+ negate() {
75
+ return new Decimal(-this.toNumber());
76
+ }
77
+ add(value) {
78
+ if (this.isInvalidate()) return new Decimal(value);
79
+ const target = Number(value);
80
+ if (Number.isNaN(target)) return this;
81
+ const number = this.number + target;
82
+ if (number > Number.MAX_SAFE_INTEGER) return new Decimal(Number.MAX_SAFE_INTEGER);
83
+ if (number < Number.MIN_SAFE_INTEGER) return new Decimal(Number.MIN_SAFE_INTEGER);
84
+ const maxPrecision = Math.max(getNumberPrecision(this.number), getNumberPrecision(target));
85
+ return new Decimal(number.toFixed(maxPrecision));
86
+ }
87
+ isEmpty() {
88
+ return !!this.empty;
89
+ }
90
+ isNaN() {
91
+ return Number.isNaN(this.number);
92
+ }
93
+ isInvalidate() {
94
+ return this.isEmpty() || this.isNaN();
95
+ }
96
+ equals(target) {
97
+ return this.toNumber() === (target == null ? void 0 : target.toNumber());
98
+ }
99
+ lessEquals(target) {
100
+ return this.add(target.negate().toString()).toNumber() <= 0;
101
+ }
102
+ toNumber() {
103
+ return this.number;
104
+ }
105
+ toString(safe = true) {
106
+ if (!safe) return this.origin;
107
+ if (this.isInvalidate()) return "";
108
+ return num2str(this.number);
109
+ }
110
+ }
111
+ function getDecimal(value) {
112
+ return new Decimal(value);
113
+ }
114
+ function toFixed(numStr, separatorStr, precision, cutOnly = false) {
115
+ if (numStr === "") return "";
116
+ const { negativeStr, integerStr, decimalStr } = trimNumber(numStr);
117
+ const precisionDecimalStr = `${separatorStr}${decimalStr}`;
118
+ const numberWithoutDecimal = `${negativeStr}${integerStr}`;
119
+ if (precision !== void 0 && precision >= 0) {
120
+ const advancedNum = Number(decimalStr[precision]);
121
+ if (advancedNum >= 5 && !cutOnly) {
122
+ const advancedDecimal = getDecimal(numStr).add(
123
+ `${negativeStr}0.${"0".repeat(precision)}${10 - advancedNum}`
124
+ );
125
+ return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
126
+ }
127
+ if (precision === 0) return numberWithoutDecimal;
128
+ return `${numberWithoutDecimal}${separatorStr}${decimalStr.padEnd(precision, "0").slice(0, precision)}`;
129
+ }
130
+ if (precisionDecimalStr === ".0") return numberWithoutDecimal;
131
+ return `${numberWithoutDecimal}${precisionDecimalStr}`;
132
+ }
133
+ function getDecupleSteps(step) {
134
+ const stepStr = typeof step === "number" ? num2str(step) : trimNumber(String(step)).fullStr;
135
+ const hasPoint = stepStr.includes(".");
136
+ if (!hasPoint) return `${step}0`;
137
+ return trimNumber(stepStr.replace(/(\d)\.(\d)/g, "$1$2.")).fullStr;
138
+ }
139
+ exports.Decimal = Decimal;
140
+ exports.getDecimal = getDecimal;
141
+ exports.getDecupleSteps = getDecupleSteps;
142
+ exports.getNumberPrecision = getNumberPrecision;
143
+ exports.isEmptyValue = isEmptyValue;
144
+ exports.num2str = num2str;
145
+ exports.toFixed = toFixed;
146
+ exports.trimNumber = trimNumber;
147
+ exports.validateNumber = validateNumber;
@@ -0,0 +1,147 @@
1
+ function isEmptyValue(value) {
2
+ return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();
3
+ }
4
+ function trimNumber(numStr) {
5
+ let str = numStr.trim();
6
+ let negative = str.startsWith("-");
7
+ if (negative) {
8
+ str = str.slice(1);
9
+ }
10
+ str = str.replace(/(\.\d*[^0])0*$/, "$1").replace(/\.0*$/, "").replace(/^0+/, "");
11
+ if (str.startsWith(".")) {
12
+ str = `0${str}`;
13
+ }
14
+ const trimStr = str || "0";
15
+ const splitNumber = trimStr.split(".");
16
+ const integerStr = splitNumber[0] || "0";
17
+ const decimalStr = splitNumber[1] || "0";
18
+ if (integerStr === "0" && decimalStr === "0") {
19
+ negative = false;
20
+ }
21
+ const negativeStr = negative ? "-" : "";
22
+ return {
23
+ negative,
24
+ negativeStr,
25
+ trimStr,
26
+ integerStr,
27
+ decimalStr,
28
+ fullStr: `${negativeStr}${trimStr}`
29
+ };
30
+ }
31
+ function isScientificNotation(number) {
32
+ const str = String(number);
33
+ return !Number.isNaN(Number(str)) && str.includes("e");
34
+ }
35
+ function getNumberPrecision(number) {
36
+ const numStr = String(number);
37
+ if (isScientificNotation(number)) {
38
+ const [, exp = "0"] = numStr.toLowerCase().split("e");
39
+ return Math.max(0, -Number(exp));
40
+ }
41
+ return numStr.includes(".") && validateNumber(numStr) ? numStr.length - numStr.indexOf(".") - 1 : 0;
42
+ }
43
+ function num2str(number) {
44
+ const numStr = String(number);
45
+ if (isScientificNotation(number)) {
46
+ if (number > Number.MAX_SAFE_INTEGER) return String(Number.MAX_SAFE_INTEGER);
47
+ if (number < Number.MIN_SAFE_INTEGER) return String(Number.MIN_SAFE_INTEGER);
48
+ return trimNumber(number.toFixed(getNumberPrecision(number))).fullStr;
49
+ }
50
+ return trimNumber(numStr).fullStr;
51
+ }
52
+ function validateNumber(num) {
53
+ if (typeof num === "number") {
54
+ return !Number.isNaN(num);
55
+ }
56
+ if (!num) return false;
57
+ const str = String(num);
58
+ return /^\s*-?\d+(\.\d+)?\s*$/.test(str) || // 11.28
59
+ /^\s*-?\d+\.\s*$/.test(str) || // 1.
60
+ /^\s*-?\.\d+\s*$/.test(str);
61
+ }
62
+ class Decimal {
63
+ constructor(value) {
64
+ this.origin = "";
65
+ if (isEmptyValue(value)) {
66
+ this.empty = true;
67
+ return;
68
+ }
69
+ this.origin = String(value);
70
+ this.number = Number(value);
71
+ }
72
+ negate() {
73
+ return new Decimal(-this.toNumber());
74
+ }
75
+ add(value) {
76
+ if (this.isInvalidate()) return new Decimal(value);
77
+ const target = Number(value);
78
+ if (Number.isNaN(target)) return this;
79
+ const number = this.number + target;
80
+ if (number > Number.MAX_SAFE_INTEGER) return new Decimal(Number.MAX_SAFE_INTEGER);
81
+ if (number < Number.MIN_SAFE_INTEGER) return new Decimal(Number.MIN_SAFE_INTEGER);
82
+ const maxPrecision = Math.max(getNumberPrecision(this.number), getNumberPrecision(target));
83
+ return new Decimal(number.toFixed(maxPrecision));
84
+ }
85
+ isEmpty() {
86
+ return !!this.empty;
87
+ }
88
+ isNaN() {
89
+ return Number.isNaN(this.number);
90
+ }
91
+ isInvalidate() {
92
+ return this.isEmpty() || this.isNaN();
93
+ }
94
+ equals(target) {
95
+ return this.toNumber() === (target == null ? void 0 : target.toNumber());
96
+ }
97
+ lessEquals(target) {
98
+ return this.add(target.negate().toString()).toNumber() <= 0;
99
+ }
100
+ toNumber() {
101
+ return this.number;
102
+ }
103
+ toString(safe = true) {
104
+ if (!safe) return this.origin;
105
+ if (this.isInvalidate()) return "";
106
+ return num2str(this.number);
107
+ }
108
+ }
109
+ function getDecimal(value) {
110
+ return new Decimal(value);
111
+ }
112
+ function toFixed(numStr, separatorStr, precision, cutOnly = false) {
113
+ if (numStr === "") return "";
114
+ const { negativeStr, integerStr, decimalStr } = trimNumber(numStr);
115
+ const precisionDecimalStr = `${separatorStr}${decimalStr}`;
116
+ const numberWithoutDecimal = `${negativeStr}${integerStr}`;
117
+ if (precision !== void 0 && precision >= 0) {
118
+ const advancedNum = Number(decimalStr[precision]);
119
+ if (advancedNum >= 5 && !cutOnly) {
120
+ const advancedDecimal = getDecimal(numStr).add(
121
+ `${negativeStr}0.${"0".repeat(precision)}${10 - advancedNum}`
122
+ );
123
+ return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
124
+ }
125
+ if (precision === 0) return numberWithoutDecimal;
126
+ return `${numberWithoutDecimal}${separatorStr}${decimalStr.padEnd(precision, "0").slice(0, precision)}`;
127
+ }
128
+ if (precisionDecimalStr === ".0") return numberWithoutDecimal;
129
+ return `${numberWithoutDecimal}${precisionDecimalStr}`;
130
+ }
131
+ function getDecupleSteps(step) {
132
+ const stepStr = typeof step === "number" ? num2str(step) : trimNumber(String(step)).fullStr;
133
+ const hasPoint = stepStr.includes(".");
134
+ if (!hasPoint) return `${step}0`;
135
+ return trimNumber(stepStr.replace(/(\d)\.(\d)/g, "$1$2.")).fullStr;
136
+ }
137
+ export {
138
+ Decimal,
139
+ getDecimal,
140
+ getDecupleSteps,
141
+ getNumberPrecision,
142
+ isEmptyValue,
143
+ num2str,
144
+ toFixed,
145
+ trimNumber,
146
+ validateNumber
147
+ };
@@ -0,0 +1,84 @@
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;
@@ -0,0 +1,85 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
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
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(
29
+ "div",
30
+ {
31
+ className: "bu-modal__container",
32
+ style: containerStyle,
33
+ onClick: (e) => e.stopPropagation(),
34
+ 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(
39
+ "button",
40
+ {
41
+ 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
45
+ }
46
+ ),
47
+ /* @__PURE__ */ jsx(
48
+ "button",
49
+ {
50
+ 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
54
+ }
55
+ )
56
+ ] }),
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" }) }) })
58
+ ] }),
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(
65
+ "button",
66
+ {
67
+ 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,
71
+ children: [
72
+ confirmLoading && /* @__PURE__ */ jsx("span", { className: "bu-modal__btn-ok-spinner" }),
73
+ okText
74
+ ]
75
+ }
76
+ )
77
+ ] })
78
+ ] })
79
+ ]
80
+ }
81
+ ) });
82
+ }
83
+ export {
84
+ BuModal as default
85
+ };