bj-web-components 0.2.28 → 0.2.30

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,9 +1,8 @@
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(
1
+ import { jsxs as d, jsx as e, Fragment as h } from "react/jsx-runtime";
2
+ import { useRef as _, useEffect as j } from "react";
3
+ const f = 600, w = 200;
4
+ function m({ className: t }) {
5
+ return /* @__PURE__ */ e("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: t, children: /* @__PURE__ */ e(
7
6
  "path",
8
7
  {
9
8
  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",
@@ -11,60 +10,55 @@ function SpinnerIcon({ className }) {
11
10
  }
12
11
  ) });
13
12
  }
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);
13
+ function C({ icon: t, upDisabled: o, downDisabled: l, onStep: i }) {
14
+ const u = _(void 0), a = _(i);
15
+ a.current = i;
16
+ const r = () => clearTimeout(u.current), s = (n, c) => {
17
+ n.preventDefault(), r(), a.current(c);
18
+ function p() {
19
+ a.current(c), u.current = setTimeout(p, w);
26
20
  }
27
- stepTimeoutRef.current = setTimeout(loopStep, STEP_DELAY);
21
+ u.current = setTimeout(p, f);
28
22
  };
29
- useEffect(() => onStopStep, []);
30
- const sharedProps = {
23
+ j(() => r, []);
24
+ const b = {
31
25
  unselectable: "on",
32
26
  role: "button",
33
- onMouseUp: onStopStep,
34
- onMouseLeave: onStopStep
27
+ onMouseUp: r,
28
+ onMouseLeave: r
35
29
  };
36
30
  return (
37
31
  // Click zones come before the icon(s) in DOM order so the icon halves
38
32
  // can be dimmed via a `:hover ~`/`:active ~` sibling selector in CSS —
39
33
  // the icon itself stays `pointer-events: none` and purely visual.
40
- /* @__PURE__ */ jsxs("div", { className: "bj-input-number__handler-wrap", children: [
41
- /* @__PURE__ */ jsx(
34
+ /* @__PURE__ */ d("div", { className: "bj-input-number__handler-wrap", children: [
35
+ /* @__PURE__ */ e(
42
36
  "span",
43
37
  {
44
- ...sharedProps,
38
+ ...b,
45
39
  "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)
40
+ "aria-disabled": o,
41
+ className: o ? "bj-input-number__handler bj-input-number__handler--up bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--up",
42
+ onMouseDown: (n) => s(n, !0)
49
43
  }
50
44
  ),
51
- /* @__PURE__ */ jsx(
45
+ /* @__PURE__ */ e(
52
46
  "span",
53
47
  {
54
- ...sharedProps,
48
+ ...b,
55
49
  "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)
50
+ "aria-disabled": l,
51
+ className: l ? "bj-input-number__handler bj-input-number__handler--down bj-input-number__handler--disabled" : "bj-input-number__handler bj-input-number__handler--down",
52
+ onMouseDown: (n) => s(n, !1)
59
53
  }
60
54
  ),
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" })
55
+ t || /* @__PURE__ */ d(h, { children: [
56
+ /* @__PURE__ */ e(m, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--up" }),
57
+ /* @__PURE__ */ e(m, { className: "bj-input-number__handler-icon bj-input-number__handler-icon--down" })
64
58
  ] })
65
59
  ] })
66
60
  );
67
61
  }
68
62
  export {
69
- StepHandler as default
63
+ C as default
70
64
  };
@@ -1,40 +1 @@
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;
1
+ "use strict";const h=require("react");function d(s,a){const c=h.useRef(null);function f(){if(s)try{const{selectionStart:t,selectionEnd:e,value:r}=s;c.current={start:t??0,end:e??0,value:r,beforeTxt:r.substring(0,t??0),afterTxt:r.substring(e??0)}}catch{}}function i(){if(!(!s||!c.current||!a))try{const{value:t}=s,{beforeTxt:e,afterTxt:r,start:o}=c.current;let n=t.length;if(t.startsWith(e))n=e.length;else if(t.endsWith(r))n=t.length-r.length;else{const l=e[o-1],u=t.indexOf(l,o-1);u!==-1&&(n=u+1)}s.setSelectionRange(n,n)}catch{}}return[f,i]}module.exports=d;
@@ -1,41 +1,39 @@
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
- }
1
+ import { useRef as h } from "react";
2
+ function g(n, a) {
3
+ const o = h(null);
4
+ function l() {
5
+ if (n)
6
+ try {
7
+ const { selectionStart: t, selectionEnd: e, value: r } = n;
8
+ o.current = {
9
+ start: t ?? 0,
10
+ end: e ?? 0,
11
+ value: r,
12
+ beforeTxt: r.substring(0, t ?? 0),
13
+ afterTxt: r.substring(e ?? 0)
14
+ };
15
+ } catch {
16
+ }
17
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;
18
+ function u() {
19
+ if (!(!n || !o.current || !a))
20
+ try {
21
+ const { value: t } = n, { beforeTxt: e, afterTxt: r, start: c } = o.current;
22
+ let s = t.length;
23
+ if (t.startsWith(e))
24
+ s = e.length;
25
+ else if (t.endsWith(r))
26
+ s = t.length - r.length;
27
+ else {
28
+ const i = e[c - 1], f = t.indexOf(i, c - 1);
29
+ f !== -1 && (s = f + 1);
30
+ }
31
+ n.setSelectionRange(s, s);
32
+ } catch {
32
33
  }
33
- input.setSelectionRange(startPos, startPos);
34
- } catch {
35
- }
36
34
  }
37
- return [recordCursor, restoreCursor];
35
+ return [l, u];
38
36
  }
39
37
  export {
40
- useCursor as default
38
+ g as default
41
39
  };
@@ -1,12 +1 @@
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;
1
+ "use strict";const t=require("react");function c(){const e=t.useRef(0),r=()=>cancelAnimationFrame(e.current);return t.useEffect(()=>r,[]),n=>{r(),e.current=requestAnimationFrame(n)}}module.exports=c;
@@ -1,13 +1,10 @@
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);
1
+ import { useRef as t, useEffect as a } from "react";
2
+ function u() {
3
+ const e = t(0), n = () => cancelAnimationFrame(e.current);
4
+ return a(() => n, []), (r) => {
5
+ n(), e.current = requestAnimationFrame(r);
9
6
  };
10
7
  }
11
8
  export {
12
- useFrame as default
9
+ u as default
13
10
  };
@@ -1,147 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function d(r){return!r&&r!==0&&!Number.isNaN(r)||!String(r).trim()}function N(r){let t=r.trim(),e=t.startsWith("-");e&&(t=t.slice(1)),t=t.replace(/(\.\d*[^0])0*$/,"$1").replace(/\.0*$/,"").replace(/^0+/,""),t.startsWith(".")&&(t=`0${t}`);const i=t||"0",u=i.split("."),m=u[0]||"0",s=u[1]||"0";m==="0"&&s==="0"&&(e=!1);const o=e?"-":"";return{negative:e,negativeStr:o,trimStr:i,integerStr:m,decimalStr:s,fullStr:`${o}${i}`}}function S(r){const t=String(r);return!Number.isNaN(Number(t))&&t.includes("e")}function a(r){const t=String(r);if(S(r)){const[,e="0"]=t.toLowerCase().split("e");return Math.max(0,-Number(e))}return t.includes(".")&&b(t)?t.length-t.indexOf(".")-1:0}function f(r){const t=String(r);return S(r)?r>Number.MAX_SAFE_INTEGER?String(Number.MAX_SAFE_INTEGER):r<Number.MIN_SAFE_INTEGER?String(Number.MIN_SAFE_INTEGER):N(r.toFixed(a(r))).fullStr:N(t).fullStr}function b(r){if(typeof r=="number")return!Number.isNaN(r);if(!r)return!1;const t=String(r);return/^\s*-?\d+(\.\d+)?\s*$/.test(t)||/^\s*-?\d+\.\s*$/.test(t)||/^\s*-?\.\d+\s*$/.test(t)}class n{constructor(t){if(this.origin="",d(t)){this.empty=!0;return}this.origin=String(t),this.number=Number(t)}negate(){return new n(-this.toNumber())}add(t){if(this.isInvalidate())return new n(t);const e=Number(t);if(Number.isNaN(e))return this;const i=this.number+e;if(i>Number.MAX_SAFE_INTEGER)return new n(Number.MAX_SAFE_INTEGER);if(i<Number.MIN_SAFE_INTEGER)return new n(Number.MIN_SAFE_INTEGER);const u=Math.max(a(this.number),a(e));return new n(i.toFixed(u))}isEmpty(){return!!this.empty}isNaN(){return Number.isNaN(this.number)}isInvalidate(){return this.isEmpty()||this.isNaN()}equals(t){return this.toNumber()===(t==null?void 0:t.toNumber())}lessEquals(t){return this.add(t.negate().toString()).toNumber()<=0}toNumber(){return this.number}toString(t=!0){return t?this.isInvalidate()?"":f(this.number):this.origin}}function E(r){return new n(r)}function g(r,t,e,i=!1){if(r==="")return"";const{negativeStr:u,integerStr:m,decimalStr:s}=N(r),o=`${t}${s}`,c=`${u}${m}`;if(e!==void 0&&e>=0){const l=Number(s[e]);if(l>=5&&!i){const h=E(r).add(`${u}0.${"0".repeat(e)}${10-l}`);return g(h.toString(),t,e,i)}return e===0?c:`${c}${t}${s.padEnd(e,"0").slice(0,e)}`}return o===".0"?c:`${c}${o}`}function $(r){const t=typeof r=="number"?f(r):N(String(r)).fullStr;return t.includes(".")?N(t.replace(/(\d)\.(\d)/g,"$1$2.")).fullStr:`${r}0`}exports.Decimal=n;exports.getDecimal=E;exports.getDecupleSteps=$;exports.getNumberPrecision=a;exports.isEmptyValue=d;exports.num2str=f;exports.toFixed=g;exports.trimNumber=N;exports.validateNumber=b;
@@ -1,86 +1,66 @@
1
- function isEmptyValue(value) {
2
- return !value && value !== 0 && !Number.isNaN(value) || !String(value).trim();
1
+ function b(r) {
2
+ return !r && r !== 0 && !Number.isNaN(r) || !String(r).trim();
3
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 ? "-" : "";
4
+ function o(r) {
5
+ let t = r.trim(), e = t.startsWith("-");
6
+ e && (t = t.slice(1)), t = t.replace(/(\.\d*[^0])0*$/, "$1").replace(/\.0*$/, "").replace(/^0+/, ""), t.startsWith(".") && (t = `0${t}`);
7
+ const n = t || "0", i = n.split("."), m = i[0] || "0", s = i[1] || "0";
8
+ m === "0" && s === "0" && (e = !1);
9
+ const N = e ? "-" : "";
22
10
  return {
23
- negative,
24
- negativeStr,
25
- trimStr,
26
- integerStr,
27
- decimalStr,
28
- fullStr: `${negativeStr}${trimStr}`
11
+ negative: e,
12
+ negativeStr: N,
13
+ trimStr: n,
14
+ integerStr: m,
15
+ decimalStr: s,
16
+ fullStr: `${N}${n}`
29
17
  };
30
18
  }
31
- function isScientificNotation(number) {
32
- const str = String(number);
33
- return !Number.isNaN(Number(str)) && str.includes("e");
19
+ function S(r) {
20
+ const t = String(r);
21
+ return !Number.isNaN(Number(t)) && t.includes("e");
34
22
  }
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));
23
+ function f(r) {
24
+ const t = String(r);
25
+ if (S(r)) {
26
+ const [, e = "0"] = t.toLowerCase().split("e");
27
+ return Math.max(0, -Number(e));
40
28
  }
41
- return numStr.includes(".") && validateNumber(numStr) ? numStr.length - numStr.indexOf(".") - 1 : 0;
29
+ return t.includes(".") && E(t) ? t.length - t.indexOf(".") - 1 : 0;
42
30
  }
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;
31
+ function d(r) {
32
+ const t = String(r);
33
+ return S(r) ? r > Number.MAX_SAFE_INTEGER ? String(Number.MAX_SAFE_INTEGER) : r < Number.MIN_SAFE_INTEGER ? String(Number.MIN_SAFE_INTEGER) : o(r.toFixed(f(r))).fullStr : o(t).fullStr;
51
34
  }
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);
35
+ function E(r) {
36
+ if (typeof r == "number")
37
+ return !Number.isNaN(r);
38
+ if (!r) return !1;
39
+ const t = String(r);
40
+ return /^\s*-?\d+(\.\d+)?\s*$/.test(t) || // 11.28
41
+ /^\s*-?\d+\.\s*$/.test(t) || // 1.
42
+ /^\s*-?\.\d+\s*$/.test(t);
61
43
  }
62
- class Decimal {
63
- constructor(value) {
64
- this.origin = "";
65
- if (isEmptyValue(value)) {
66
- this.empty = true;
44
+ class u {
45
+ constructor(t) {
46
+ if (this.origin = "", b(t)) {
47
+ this.empty = !0;
67
48
  return;
68
49
  }
69
- this.origin = String(value);
70
- this.number = Number(value);
50
+ this.origin = String(t), this.number = Number(t);
71
51
  }
72
52
  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));
53
+ return new u(-this.toNumber());
54
+ }
55
+ add(t) {
56
+ if (this.isInvalidate()) return new u(t);
57
+ const e = Number(t);
58
+ if (Number.isNaN(e)) return this;
59
+ const n = this.number + e;
60
+ if (n > Number.MAX_SAFE_INTEGER) return new u(Number.MAX_SAFE_INTEGER);
61
+ if (n < Number.MIN_SAFE_INTEGER) return new u(Number.MIN_SAFE_INTEGER);
62
+ const i = Math.max(f(this.number), f(e));
63
+ return new u(n.toFixed(i));
84
64
  }
85
65
  isEmpty() {
86
66
  return !!this.empty;
@@ -91,57 +71,49 @@ class Decimal {
91
71
  isInvalidate() {
92
72
  return this.isEmpty() || this.isNaN();
93
73
  }
94
- equals(target) {
95
- return this.toNumber() === (target == null ? void 0 : target.toNumber());
74
+ equals(t) {
75
+ return this.toNumber() === (t == null ? void 0 : t.toNumber());
96
76
  }
97
- lessEquals(target) {
98
- return this.add(target.negate().toString()).toNumber() <= 0;
77
+ lessEquals(t) {
78
+ return this.add(t.negate().toString()).toNumber() <= 0;
99
79
  }
100
80
  toNumber() {
101
81
  return this.number;
102
82
  }
103
- toString(safe = true) {
104
- if (!safe) return this.origin;
105
- if (this.isInvalidate()) return "";
106
- return num2str(this.number);
83
+ toString(t = !0) {
84
+ return t ? this.isInvalidate() ? "" : d(this.number) : this.origin;
107
85
  }
108
86
  }
109
- function getDecimal(value) {
110
- return new Decimal(value);
87
+ function h(r) {
88
+ return new u(r);
111
89
  }
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}`
90
+ function g(r, t, e, n = !1) {
91
+ if (r === "") return "";
92
+ const { negativeStr: i, integerStr: m, decimalStr: s } = o(r), N = `${t}${s}`, c = `${i}${m}`;
93
+ if (e !== void 0 && e >= 0) {
94
+ const a = Number(s[e]);
95
+ if (a >= 5 && !n) {
96
+ const l = h(r).add(
97
+ `${i}0.${"0".repeat(e)}${10 - a}`
122
98
  );
123
- return toFixed(advancedDecimal.toString(), separatorStr, precision, cutOnly);
99
+ return g(l.toString(), t, e, n);
124
100
  }
125
- if (precision === 0) return numberWithoutDecimal;
126
- return `${numberWithoutDecimal}${separatorStr}${decimalStr.padEnd(precision, "0").slice(0, precision)}`;
101
+ return e === 0 ? c : `${c}${t}${s.padEnd(e, "0").slice(0, e)}`;
127
102
  }
128
- if (precisionDecimalStr === ".0") return numberWithoutDecimal;
129
- return `${numberWithoutDecimal}${precisionDecimalStr}`;
103
+ return N === ".0" ? c : `${c}${N}`;
130
104
  }
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;
105
+ function $(r) {
106
+ const t = typeof r == "number" ? d(r) : o(String(r)).fullStr;
107
+ return t.includes(".") ? o(t.replace(/(\d)\.(\d)/g, "$1$2.")).fullStr : `${r}0`;
136
108
  }
137
109
  export {
138
- Decimal,
139
- getDecimal,
140
- getDecupleSteps,
141
- getNumberPrecision,
142
- isEmptyValue,
143
- num2str,
144
- toFixed,
145
- trimNumber,
146
- validateNumber
110
+ u as Decimal,
111
+ h as getDecimal,
112
+ $ as getDecupleSteps,
113
+ f as getNumberPrecision,
114
+ b as isEmptyValue,
115
+ d as num2str,
116
+ g as toFixed,
117
+ o as trimNumber,
118
+ E as validateNumber
147
119
  };