v-money3 3.24.1 → 3.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -62
- package/dist/component.vue.d.ts +12 -3
- package/dist/options.d.ts +2 -0
- package/dist/v-money3.mjs +469 -407
- package/dist/v-money3.umd.js +1 -1
- package/package.json +24 -23
package/README.md
CHANGED
|
@@ -7,64 +7,49 @@
|
|
|
7
7
|
|
|
8
8
|

|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Introduction
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
Since I use it in many projects and part of then will be upgraded to Vue3,
|
|
14
|
-
I needed it to work after the upgrades.
|
|
15
|
-
|
|
16
|
-
Feel free to open an issue or post a pull request!
|
|
12
|
+
Welcome to `v-money3`, a versatile money masking solution designed specifically for `Vue 3` applications. This library serves as a replacement for the now-abandoned [`v-money`](https://github.com/vuejs-tips/v-money) library, ensuring compatibility and functionality for projects transitioning to `Vue 3`.
|
|
17
13
|
|
|
18
14
|
## Features
|
|
19
15
|
|
|
20
|
-
- Arbitrary Precision
|
|
21
|
-
- Lightweight
|
|
22
|
-
- Dependency
|
|
23
|
-
- Mobile
|
|
24
|
-
- Component or Directive
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
it will be interpreted as `'0.55'`.
|
|
38
|
-
To instruct the correct format on setup you need to pass in `'55.00'`
|
|
39
|
-
when using `v-model`. The same is true for `'5.5'`.
|
|
40
|
-
It will be interpreted as `'0.55'`. Another example: `'55.5'` => `'5.55'`.
|
|
41
|
-
Arbitrary precision is supported by using `string` and `BigInt` with `v-model`.
|
|
42
|
-
|
|
43
|
-
For the majority of users, it will make sense to use float numbers and stay within the
|
|
44
|
-
boundaries of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number).
|
|
45
|
-
If you fit this instance, you need to use `v-model`
|
|
46
|
-
with the number modifier, or `v-model.number`. But than,
|
|
47
|
-
you are stuck with numbers smaller than `2^53 - 1` or
|
|
48
|
-
`9007199254740991` or `9,007,199,254,740,991`. - Little more than nine quadrilion...
|
|
49
|
-
See [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER).
|
|
50
|
-
|
|
51
|
-
For those who are using `v-model.number`, integers and floats are completely
|
|
52
|
-
understood.
|
|
53
|
-
Let's follow another train of thought:
|
|
54
|
-
If your precision is set to `2` and you set a default model value of `55`,
|
|
55
|
-
it will be interpreted as `55.00`. The same is true for `5.5`.
|
|
56
|
-
It will be interpreted as `5.50`. Another example: `55.5` => `55.50`.
|
|
16
|
+
- **Arbitrary Precision:** Utilize [`BigInt`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) for precise calculations.
|
|
17
|
+
- **Lightweight:** Less than 4KB when gzipped.
|
|
18
|
+
- **Dependency-free:** No external dependencies for seamless integration.
|
|
19
|
+
- **Mobile Support:** Ensures a consistent experience across devices.
|
|
20
|
+
- **Component or Directive Flavors:** Choose between component-based or directive-based implementation.
|
|
21
|
+
- **Copy/Paste Support:** Easily accept input via copy/paste actions.
|
|
22
|
+
- **Min/Max Limits:** Set minimum and maximum limits for input values.
|
|
23
|
+
|
|
24
|
+
## Arbitrary Precision
|
|
25
|
+
|
|
26
|
+
In this release, some breaking changes have been introduced. Let's delve into the details:
|
|
27
|
+
|
|
28
|
+
`v-money3` supports arbitrary precision through the use of `BigInt`. Arbitrary precision is only supported with `v-model`. When using `v-model`, ensure the input is provided as a string representation of a number (e.g., `'12345.67'`). If your precision is set to `2` and you provide a default `v-model` value of `'55'`, it will be interpreted as `'0.55'`. To maintain the correct format, ensure you pass `'55.00'` when using `v-model`.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
For most users, it's advisable to utilize floating-point numbers and adhere to the boundaries of [`Number`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number). In such cases, employing `v-model` with the number modifier, or `v-model.number`, is recommended. However, this limits you to numbers smaller than `2^53 - 1` or `9007199254740991` (approximately nine quadrillion). Refer to [MAX_SAFE_INTEGER](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) for more information. For users employing `v-model.number`, integers and floats are intuitively understood. If your precision is set to `2` and you input a default `v-model.number` value of `55`, it will be interpreted as `55.00`. The same applies to `5.5`, which will be rendered as `5.50`.
|
|
32
|
+
|
|
57
33
|
|
|
58
34
|
[More Examples](https://github.com/jonathanpmartins/v-money3/issues/38#issuecomment-903214235)
|
|
59
35
|
|
|
60
|
-
##
|
|
36
|
+
## Browser Target
|
|
61
37
|
|
|
62
|
-
|
|
38
|
+
If you encounter the error message: `Big integer literals are not available in the configured target environment`, please ensure your browser targets are updated to include at least the following entries:
|
|
39
|
+
```
|
|
40
|
+
['es2020', 'safari14']
|
|
41
|
+
```
|
|
42
|
+
Can I use `bigInt`? https://caniuse.com/bigint
|
|
43
|
+
|
|
44
|
+
More information: [#66](https://github.com/jonathanpmartins/v-money3/issues/66), [#70](https://github.com/jonathanpmartins/v-money3/issues/70), [#89](https://github.com/jonathanpmartins/v-money3/issues/89)
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
63
47
|
|
|
64
48
|
```bash
|
|
65
49
|
npm i v-money3 --save
|
|
66
50
|
```
|
|
67
51
|
|
|
52
|
+
## Usage
|
|
68
53
|
|
|
69
54
|
### Register Globally ([view codesandbox](https://codesandbox.io/s/v-money3-global-registering-lv1jv?file=/src/main.js))
|
|
70
55
|
|
|
@@ -129,6 +114,7 @@ app.directive('money3', Money3Directive)
|
|
|
129
114
|
min: null,
|
|
130
115
|
max: null,
|
|
131
116
|
allowBlank: false,
|
|
117
|
+
treatZeroAsBlank: true,
|
|
132
118
|
minimumNumberOfCharacters: 0,
|
|
133
119
|
shouldRound: true,
|
|
134
120
|
focusOnRight: false,
|
|
@@ -141,16 +127,12 @@ app.directive('money3', Money3Directive)
|
|
|
141
127
|
|
|
142
128
|
### Component v-model number modifier ([view codesandbox](https://codesandbox.io/s/v-money3-use-as-component-forked-523de?file=/src/App.vue))
|
|
143
129
|
|
|
144
|
-
`v-model
|
|
145
|
-
If the `masked` property is set to true it will be formatted,
|
|
146
|
-
|
|
147
|
-
If you need your model to be a float number use the `number` modifier.
|
|
148
|
-
Ex.: `v-model.number="amount"`
|
|
130
|
+
When using `v-model`, the returned value will always be a `string`.
|
|
131
|
+
If the `masked` property is set to `true`, it will be formatted accordingly; otherwise, it will be a fixed string representation of a floating-point number.
|
|
132
|
+
If you require your model to be a floating-point number, utilize the `number` modifier. For example:
|
|
149
133
|
|
|
150
|
-
- `v-model="amount"` will return a fixed string with typeof `string`.
|
|
151
|
-
|
|
152
|
-
- `v-model.number="amount"` will return a float number with typeof
|
|
153
|
-
`number`. Ex.: 123456.78
|
|
134
|
+
- `v-model="amount"` will return a fixed string with a typeof `string`. For instance: `'123456.78'`
|
|
135
|
+
- `v-model.number="amount"` will return a floating-point number with a typeof `number`. For example: `123456.78`
|
|
154
136
|
|
|
155
137
|
```html
|
|
156
138
|
<template>
|
|
@@ -173,7 +155,7 @@ Ex.: "123456.78"
|
|
|
173
155
|
```
|
|
174
156
|
|
|
175
157
|
### Use as directive ([view codesandbox](https://codesandbox.io/s/v-money3-use-as-directive-e7ror?file=/src/App.vue))
|
|
176
|
-
|
|
158
|
+
To ensure proper functionality, you must use `v-model.lazy` for binding.
|
|
177
159
|
```html
|
|
178
160
|
<template>
|
|
179
161
|
<input v-model.lazy="amount" v-money3="config" />
|
|
@@ -197,6 +179,7 @@ Must use `v-model.lazy` to bind works properly.
|
|
|
197
179
|
min: null,
|
|
198
180
|
max: null,
|
|
199
181
|
allowBlank: false,
|
|
182
|
+
treatZeroAsBlank: true,
|
|
200
183
|
minimumNumberOfCharacters: 0,
|
|
201
184
|
shouldRound: true,
|
|
202
185
|
focusOnRight: false,
|
|
@@ -208,10 +191,8 @@ Must use `v-model.lazy` to bind works properly.
|
|
|
208
191
|
</script>
|
|
209
192
|
```
|
|
210
193
|
|
|
211
|
-
By default, directives
|
|
212
|
-
|
|
213
|
-
to work with floats/integers on directives you need to configure the `number`
|
|
214
|
-
modifier manually.
|
|
194
|
+
By default, directives are only compatible with `v-model`. It's important to note that using `v-model.number` directly on directives is not supported.
|
|
195
|
+
If you need to work with `float` or `integer` on directives, you'll need to manually configure the number modifier.
|
|
215
196
|
|
|
216
197
|
Using config:
|
|
217
198
|
```javascipt
|
|
@@ -219,7 +200,7 @@ modelModifiers: {
|
|
|
219
200
|
number: true,
|
|
220
201
|
}
|
|
221
202
|
```
|
|
222
|
-
If you bind it
|
|
203
|
+
If you directly bind it, you're perfectly fine as well:
|
|
223
204
|
```html
|
|
224
205
|
<input :model-modifiers="{ number: true }" v-model.lazy="amount" v-money3="config" />
|
|
225
206
|
```
|
|
@@ -239,6 +220,7 @@ If you bind it directly you are just fine too:
|
|
|
239
220
|
| min | false | Number | null | The min value allowed |
|
|
240
221
|
| max | false | Number | null | The max value allowed |
|
|
241
222
|
| allow-blank | false | Boolean | false | If the field can start blank and be cleared out by user |
|
|
223
|
+
| treat-zero-as-blank | false | Boolean | true | When `allow-blank` is true, controls whether zero is rendered as blank. Set to `false` to distinguish zero from blank (e.g. show `0.00` and only blank on empty input). Has no effect when `allow-blank` is false |
|
|
242
224
|
| minimum-number-of-characters | false | Number | 0 | The minimum number of characters that the mask should show |
|
|
243
225
|
| should-round | false | Boolean | true | Should default values be rounded or sliced |
|
|
244
226
|
| focus-on-right | false | Boolean | false | When focus, set the cursor to the far right |
|
|
@@ -257,8 +239,7 @@ Numbers `0-9` and the following characters...
|
|
|
257
239
|
- `prefix`
|
|
258
240
|
- `suffix`
|
|
259
241
|
|
|
260
|
-
Restricted inputs will be
|
|
261
|
-
A console warn with more information will be shown!
|
|
242
|
+
Restricted inputs will be filtered out of the final mask, and a console warning with more information will be displayed.
|
|
262
243
|
|
|
263
244
|
|
|
264
245
|
## Don't want to use a package manager?
|
|
@@ -289,6 +270,7 @@ const config = {
|
|
|
289
270
|
min: null,
|
|
290
271
|
max: null,
|
|
291
272
|
allowBlank: false,
|
|
273
|
+
treatZeroAsBlank: true,
|
|
292
274
|
minimumNumberOfCharacters: 0,
|
|
293
275
|
modelModifiers: {
|
|
294
276
|
number: false,
|
|
@@ -314,6 +296,16 @@ console.log(unformatted);
|
|
|
314
296
|
// output float number: 12345.67
|
|
315
297
|
```
|
|
316
298
|
|
|
299
|
+
|
|
300
|
+
### Contribution and Feedback
|
|
301
|
+
Your contributions and feedback are highly valued! If you encounter any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request on GitHub.
|
|
302
|
+
|
|
303
|
+
The previous `v-money` library has been abandoned, prompting the development of v-money3 to accommodate projects migrating to `Vue 3`.
|
|
304
|
+
|
|
305
|
+
Happy coding with v-money3!
|
|
306
|
+
|
|
307
|
+
|
|
317
308
|
### References
|
|
318
309
|
|
|
319
310
|
- https://github.com/vuejs-tips/v-money (based on `v-money`)
|
|
311
|
+
|
package/dist/component.vue.d.ts
CHANGED
|
@@ -68,6 +68,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
68
68
|
type: BooleanConstructor;
|
|
69
69
|
default: () => boolean;
|
|
70
70
|
};
|
|
71
|
+
treatZeroAsBlank: {
|
|
72
|
+
type: BooleanConstructor;
|
|
73
|
+
default: () => boolean;
|
|
74
|
+
};
|
|
71
75
|
minimumNumberOfCharacters: {
|
|
72
76
|
type: NumberConstructor;
|
|
73
77
|
default: () => number;
|
|
@@ -80,9 +84,9 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
80
84
|
type: BooleanConstructor;
|
|
81
85
|
default: () => boolean;
|
|
82
86
|
};
|
|
83
|
-
},
|
|
87
|
+
}, unknown, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
84
88
|
"update:model-value": (value: string | number) => void;
|
|
85
|
-
}, string, import("vue").
|
|
89
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
86
90
|
debug: {
|
|
87
91
|
required: false;
|
|
88
92
|
type: BooleanConstructor;
|
|
@@ -152,6 +156,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
152
156
|
type: BooleanConstructor;
|
|
153
157
|
default: () => boolean;
|
|
154
158
|
};
|
|
159
|
+
treatZeroAsBlank: {
|
|
160
|
+
type: BooleanConstructor;
|
|
161
|
+
default: () => boolean;
|
|
162
|
+
};
|
|
155
163
|
minimumNumberOfCharacters: {
|
|
156
164
|
type: NumberConstructor;
|
|
157
165
|
default: () => number;
|
|
@@ -179,10 +187,11 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
179
187
|
min: string | number;
|
|
180
188
|
max: string | number;
|
|
181
189
|
allowBlank: boolean;
|
|
190
|
+
treatZeroAsBlank: boolean;
|
|
182
191
|
minimumNumberOfCharacters: number;
|
|
183
192
|
modelModifiers: Record<string, any>;
|
|
184
193
|
shouldRound: boolean;
|
|
185
194
|
focusOnRight: boolean;
|
|
186
195
|
id: string | number;
|
|
187
|
-
}>;
|
|
196
|
+
}, {}>;
|
|
188
197
|
export default _default;
|
package/dist/options.d.ts
CHANGED
|
@@ -11,10 +11,12 @@ export interface VMoneyOptions {
|
|
|
11
11
|
min: number | string | null;
|
|
12
12
|
max: number | string | null;
|
|
13
13
|
allowBlank: boolean;
|
|
14
|
+
treatZeroAsBlank: boolean;
|
|
14
15
|
minimumNumberOfCharacters: number;
|
|
15
16
|
modelModifiers: any;
|
|
16
17
|
shouldRound: boolean;
|
|
17
18
|
focusOnRight: boolean;
|
|
19
|
+
lazy: boolean;
|
|
18
20
|
[key: string]: any;
|
|
19
21
|
}
|
|
20
22
|
declare const _default: VMoneyOptions;
|
package/dist/v-money3.mjs
CHANGED
|
@@ -1,429 +1,491 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
import { computed as e, createElementBlock as t, defineComponent as n, getCurrentInstance as r, mergeProps as i, openBlock as a, ref as o, resolveDirective as s, toRefs as c, unref as l, useAttrs as u, watch as d, withDirectives as f } from "vue";
|
|
2
|
+
//#region src/options.ts
|
|
3
|
+
var p = {
|
|
4
|
+
debug: !1,
|
|
5
|
+
masked: !1,
|
|
6
|
+
prefix: "",
|
|
7
|
+
suffix: "",
|
|
8
|
+
thousands: ",",
|
|
9
|
+
decimal: ".",
|
|
10
|
+
precision: 2,
|
|
11
|
+
disableNegative: !1,
|
|
12
|
+
disabled: !1,
|
|
13
|
+
min: null,
|
|
14
|
+
max: null,
|
|
15
|
+
allowBlank: !1,
|
|
16
|
+
treatZeroAsBlank: !0,
|
|
17
|
+
minimumNumberOfCharacters: 0,
|
|
18
|
+
modelModifiers: { number: !1 },
|
|
19
|
+
shouldRound: !0,
|
|
20
|
+
focusOnRight: !1,
|
|
21
|
+
lazy: !0
|
|
22
|
+
}, m = ["+", "-"], h = [
|
|
23
|
+
"decimal",
|
|
24
|
+
"thousands",
|
|
25
|
+
"prefix",
|
|
26
|
+
"suffix"
|
|
27
|
+
];
|
|
28
|
+
function g(e) {
|
|
29
|
+
return Math.max(0, Math.min(e, 1e3));
|
|
27
30
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
31
|
+
function _(e, t) {
|
|
32
|
+
return e = e.padStart(t + 1, "0"), t === 0 ? e : `${e.slice(0, -t)}.${e.slice(-t)}`;
|
|
30
33
|
}
|
|
31
|
-
function
|
|
32
|
-
|
|
34
|
+
function v(e) {
|
|
35
|
+
return e = e ? e.toString() : "", e.replace(/\D+/g, "") || "0";
|
|
33
36
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
37
|
+
function y(e, t) {
|
|
38
|
+
return e.replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${t}`);
|
|
36
39
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
40
|
+
function b(e, t, n) {
|
|
41
|
+
return t ? e + n + t : e;
|
|
39
42
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
43
|
+
function x(e, t) {
|
|
44
|
+
return m.includes(e) ? (console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`), !1) : /\d/g.test(e) ? (console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`), !1) : !0;
|
|
42
45
|
}
|
|
43
|
-
function
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return !1;
|
|
47
|
-
return !0;
|
|
46
|
+
function S(e) {
|
|
47
|
+
for (let t of h) if (!x(e[t], t)) return !1;
|
|
48
|
+
return !0;
|
|
48
49
|
}
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
return t;
|
|
50
|
+
function C(e) {
|
|
51
|
+
for (let t of h) {
|
|
52
|
+
e[t] = e[t].replace(/\d+/g, "");
|
|
53
|
+
for (let n of m) e[t] = e[t].replaceAll(n, "");
|
|
54
|
+
}
|
|
55
|
+
return e;
|
|
56
56
|
}
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
return e - (n + 1);
|
|
57
|
+
function w(e) {
|
|
58
|
+
return e.length - (e.indexOf(".") + 1);
|
|
60
59
|
}
|
|
61
|
-
function
|
|
62
|
-
|
|
60
|
+
function T(e) {
|
|
61
|
+
return e.replace(/^(-?)0+(?!\.)(.+)/, "$1$2");
|
|
63
62
|
}
|
|
64
|
-
function
|
|
65
|
-
|
|
63
|
+
function E(e) {
|
|
64
|
+
return /^-?[\d]+$/g.test(e);
|
|
66
65
|
}
|
|
67
|
-
function D(
|
|
68
|
-
|
|
66
|
+
function D(e) {
|
|
67
|
+
return /^-?[\d]+(\.[\d]+)$/g.test(e);
|
|
69
68
|
}
|
|
70
|
-
function O(
|
|
71
|
-
|
|
69
|
+
function O(e, t, n) {
|
|
70
|
+
return t > e.length - 1 ? e : e.substring(0, t) + n + e.substring(t + 1);
|
|
72
71
|
}
|
|
73
|
-
function
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return `1${i}`;
|
|
90
|
-
}
|
|
91
|
-
return i;
|
|
72
|
+
function k(e, t) {
|
|
73
|
+
let n = t - w(e);
|
|
74
|
+
if (n >= 0) return e;
|
|
75
|
+
let r = e.slice(0, n), i = e.slice(n);
|
|
76
|
+
if (r.charAt(r.length - 1) === "." && (r = r.slice(0, -1)), parseInt(i.charAt(0), 10) >= 5) {
|
|
77
|
+
for (let e = r.length - 1; e >= 0; --e) {
|
|
78
|
+
let t = r.charAt(e);
|
|
79
|
+
if (t !== "." && t !== "-") {
|
|
80
|
+
let n = parseInt(t, 10) + 1;
|
|
81
|
+
if (n < 10) return O(r, e, n);
|
|
82
|
+
r = O(r, e, "0");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return `1${r}`;
|
|
86
|
+
}
|
|
87
|
+
return r;
|
|
92
88
|
}
|
|
93
|
-
function
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
function A(e, t) {
|
|
90
|
+
let n = () => {
|
|
91
|
+
e.setSelectionRange(t, t);
|
|
92
|
+
};
|
|
93
|
+
e === document.activeElement && (n(), setTimeout(n, 1));
|
|
98
94
|
}
|
|
99
|
-
function j(
|
|
100
|
-
|
|
95
|
+
function j(e) {
|
|
96
|
+
return new Event(e, {
|
|
97
|
+
bubbles: !0,
|
|
98
|
+
cancelable: !1
|
|
99
|
+
});
|
|
101
100
|
}
|
|
102
|
-
function
|
|
103
|
-
|
|
101
|
+
function M({ debug: e = !1 }, ...t) {
|
|
102
|
+
e && console.log(...t);
|
|
104
103
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
getDecimalPrecision() {
|
|
115
|
-
return this.decimal;
|
|
116
|
-
}
|
|
117
|
-
setNumber(e) {
|
|
118
|
-
this.decimal = 0, typeof e == "bigint" ? this.number = e : typeof e == "number" ? this.setupString(e.toString()) : this.setupString(e);
|
|
119
|
-
}
|
|
120
|
-
toFixed(e = 0, n = !0) {
|
|
121
|
-
let i = this.toString();
|
|
122
|
-
const a = e - this.getDecimalPrecision();
|
|
123
|
-
return a > 0 ? (i.includes(".") || (i += "."), i.padEnd(i.length + a, "0")) : a < 0 ? n ? P(i, e) : i.slice(0, a) : i;
|
|
124
|
-
}
|
|
125
|
-
toString() {
|
|
126
|
-
let e = this.number.toString();
|
|
127
|
-
if (this.decimal) {
|
|
128
|
-
let n = !1;
|
|
129
|
-
return e.charAt(0) === "-" && (e = e.substring(1), n = !0), e = e.padStart(e.length + this.decimal, "0"), e = `${e.slice(0, -this.decimal)}.${e.slice(-this.decimal)}`, e = C(e), (n ? "-" : "") + e;
|
|
130
|
-
}
|
|
131
|
-
return e;
|
|
132
|
-
}
|
|
133
|
-
lessThan(e) {
|
|
134
|
-
const [n, i] = this.adjustComparisonNumbers(e);
|
|
135
|
-
return n < i;
|
|
136
|
-
}
|
|
137
|
-
biggerThan(e) {
|
|
138
|
-
const [n, i] = this.adjustComparisonNumbers(e);
|
|
139
|
-
return n > i;
|
|
140
|
-
}
|
|
141
|
-
isEqual(e) {
|
|
142
|
-
const [n, i] = this.adjustComparisonNumbers(e);
|
|
143
|
-
return n === i;
|
|
144
|
-
}
|
|
145
|
-
setupString(e) {
|
|
146
|
-
if (e = C(e), A(e))
|
|
147
|
-
this.number = BigInt(e);
|
|
148
|
-
else if (D(e))
|
|
149
|
-
this.decimal = I(e), this.number = BigInt(e.replace(".", ""));
|
|
150
|
-
else
|
|
151
|
-
throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`);
|
|
152
|
-
}
|
|
153
|
-
adjustComparisonNumbers(e) {
|
|
154
|
-
let n;
|
|
155
|
-
e.constructor.name !== "BigNumber" ? n = new p(e) : n = e;
|
|
156
|
-
const i = this.getDecimalPrecision() - n.getDecimalPrecision();
|
|
157
|
-
let a = this.getNumber(), s = n.getNumber();
|
|
158
|
-
return i > 0 ? s = n.getNumber() * 10n ** BigInt(i) : i < 0 && (a = this.getNumber() * 10n ** BigInt(i * -1)), [a, s];
|
|
159
|
-
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/typeof.js
|
|
106
|
+
function N(e) {
|
|
107
|
+
"@babel/helpers - typeof";
|
|
108
|
+
return N = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
109
|
+
return typeof e;
|
|
110
|
+
} : function(e) {
|
|
111
|
+
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
112
|
+
}, N(e);
|
|
160
113
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
let a = t.replace(e.prefix, "").replace(e.suffix, "");
|
|
173
|
-
r(e, "utils format() - filtered", a), !e.precision && e.thousands !== "." && D(a) && (a = P(a, 0), r(e, "utils format() - !opt.precision && isValidFloat()", a));
|
|
174
|
-
const s = F(a);
|
|
175
|
-
r(e, "utils format() - numbers", s), r(e, "utils format() - numbersToCurrency", i + N(s, e.precision));
|
|
176
|
-
const u = new p(i + N(s, e.precision));
|
|
177
|
-
r(e, "utils format() - bigNumber1", u.toString()), e.max && u.biggerThan(e.max) && u.setNumber(e.max), e.min && u.lessThan(e.min) && u.setNumber(e.min);
|
|
178
|
-
const o = u.toFixed(d(e.precision), e.shouldRound);
|
|
179
|
-
if (r(e, "utils format() - bigNumber2", u.toFixed(d(e.precision))), /^0(\.0+)?$/g.test(o) && e.allowBlank)
|
|
180
|
-
return "";
|
|
181
|
-
let [g, f] = o.split(".");
|
|
182
|
-
const h = f !== void 0 ? f.length : 0;
|
|
183
|
-
g = g.padStart(e.minimumNumberOfCharacters - h, "0"), g = se(g, e.thousands);
|
|
184
|
-
const y = e.prefix + ue(g, f, e.decimal) + e.suffix;
|
|
185
|
-
return r(e, "utils format() - output", y), y;
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/toPrimitive.js
|
|
116
|
+
function P(e, t) {
|
|
117
|
+
if (N(e) != "object" || !e) return e;
|
|
118
|
+
var n = e[Symbol.toPrimitive];
|
|
119
|
+
if (n !== void 0) {
|
|
120
|
+
var r = n.call(e, t || "default");
|
|
121
|
+
if (N(r) != "object") return r;
|
|
122
|
+
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
123
|
+
}
|
|
124
|
+
return (t === "string" ? String : Number)(e);
|
|
186
125
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const s = F(a);
|
|
193
|
-
r(e, "utils unformat() - numbers", s);
|
|
194
|
-
const u = new p(i + N(s, e.precision));
|
|
195
|
-
r(e, "utils unformat() - bigNumber1", s.toString()), e.max && u.biggerThan(e.max) && u.setNumber(e.max), e.min && u.lessThan(e.min) && u.setNumber(e.min);
|
|
196
|
-
let o = u.toFixed(d(e.precision), e.shouldRound);
|
|
197
|
-
return e.modelModifiers && e.modelModifiers.number && (o = parseFloat(o)), r(e, "utils unformat() - output", o), o;
|
|
126
|
+
//#endregion
|
|
127
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/toPropertyKey.js
|
|
128
|
+
function F(e) {
|
|
129
|
+
var t = P(e, "string");
|
|
130
|
+
return N(t) == "symbol" ? t : t + "";
|
|
198
131
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
props: {
|
|
260
|
-
debug: {
|
|
261
|
-
required: !1,
|
|
262
|
-
type: Boolean,
|
|
263
|
-
default: !1
|
|
264
|
-
},
|
|
265
|
-
id: {
|
|
266
|
-
required: !1,
|
|
267
|
-
type: [Number, String],
|
|
268
|
-
default: () => {
|
|
269
|
-
const t = G();
|
|
270
|
-
return t ? t.uid : null;
|
|
271
|
-
}
|
|
272
|
-
},
|
|
273
|
-
modelValue: {
|
|
274
|
-
required: !0,
|
|
275
|
-
type: [Number, String]
|
|
276
|
-
},
|
|
277
|
-
modelModifiers: {
|
|
278
|
-
required: !1,
|
|
279
|
-
type: Object,
|
|
280
|
-
default: () => ({ number: !1 })
|
|
281
|
-
},
|
|
282
|
-
masked: {
|
|
283
|
-
type: Boolean,
|
|
284
|
-
default: !1
|
|
285
|
-
},
|
|
286
|
-
precision: {
|
|
287
|
-
type: Number,
|
|
288
|
-
default: () => l.precision
|
|
289
|
-
},
|
|
290
|
-
decimal: {
|
|
291
|
-
type: String,
|
|
292
|
-
default: () => l.decimal,
|
|
293
|
-
validator(t) {
|
|
294
|
-
return b(t, "decimal");
|
|
295
|
-
}
|
|
296
|
-
},
|
|
297
|
-
thousands: {
|
|
298
|
-
type: String,
|
|
299
|
-
default: () => l.thousands,
|
|
300
|
-
validator(t) {
|
|
301
|
-
return b(t, "thousands");
|
|
302
|
-
}
|
|
303
|
-
},
|
|
304
|
-
prefix: {
|
|
305
|
-
type: String,
|
|
306
|
-
default: () => l.prefix,
|
|
307
|
-
validator(t) {
|
|
308
|
-
return b(t, "prefix");
|
|
309
|
-
}
|
|
310
|
-
},
|
|
311
|
-
suffix: {
|
|
312
|
-
type: String,
|
|
313
|
-
default: () => l.suffix,
|
|
314
|
-
validator(t) {
|
|
315
|
-
return b(t, "suffix");
|
|
316
|
-
}
|
|
317
|
-
},
|
|
318
|
-
disableNegative: {
|
|
319
|
-
type: Boolean,
|
|
320
|
-
default: !1
|
|
321
|
-
},
|
|
322
|
-
disabled: {
|
|
323
|
-
type: Boolean,
|
|
324
|
-
default: !1
|
|
325
|
-
},
|
|
326
|
-
max: {
|
|
327
|
-
type: [Number, String],
|
|
328
|
-
default: () => l.max
|
|
329
|
-
},
|
|
330
|
-
min: {
|
|
331
|
-
type: [Number, String],
|
|
332
|
-
default: () => l.min
|
|
333
|
-
},
|
|
334
|
-
allowBlank: {
|
|
335
|
-
type: Boolean,
|
|
336
|
-
default: () => l.allowBlank
|
|
337
|
-
},
|
|
338
|
-
minimumNumberOfCharacters: {
|
|
339
|
-
type: Number,
|
|
340
|
-
default: () => l.minimumNumberOfCharacters
|
|
341
|
-
},
|
|
342
|
-
shouldRound: {
|
|
343
|
-
type: Boolean,
|
|
344
|
-
default: () => l.shouldRound
|
|
345
|
-
},
|
|
346
|
-
focusOnRight: {
|
|
347
|
-
type: Boolean,
|
|
348
|
-
default: () => l.focusOnRight
|
|
349
|
-
}
|
|
350
|
-
},
|
|
351
|
-
emits: ["update:model-value"],
|
|
352
|
-
setup(t, { emit: e }) {
|
|
353
|
-
const n = t, { modelValue: i, modelModifiers: a, masked: s, precision: u, shouldRound: o, focusOnRight: g } = J(n);
|
|
354
|
-
r(n, "component setup()", n);
|
|
355
|
-
let f = i.value;
|
|
356
|
-
(n.disableNegative || f !== "-") && a.value && a.value.number && (o.value ? f = Number(i.value).toFixed(d(u.value)) : f = Number(i.value).toFixed(d(u.value) + 1).slice(0, -1));
|
|
357
|
-
const h = Q(k(f, n, "component setup"));
|
|
358
|
-
r(n, "component setup() - data.formattedValue", h.value), X(i, y);
|
|
359
|
-
function y(m) {
|
|
360
|
-
r(n, "component watch() -> value", m);
|
|
361
|
-
const c = k(
|
|
362
|
-
m,
|
|
363
|
-
x({ ...n }),
|
|
364
|
-
"component watch"
|
|
365
|
-
);
|
|
366
|
-
c !== h.value && (r(n, "component watch() changed -> formatted", c), h.value = c);
|
|
367
|
-
}
|
|
368
|
-
let B = null;
|
|
369
|
-
function U(m) {
|
|
370
|
-
let c = m.target.value;
|
|
371
|
-
r(n, "component change() -> evt.target.value", c), s.value && !a.value.number || (c = S(
|
|
372
|
-
c,
|
|
373
|
-
x({ ...n }),
|
|
374
|
-
"component change"
|
|
375
|
-
)), c !== B && (B = c, r(n, "component change() -> update:model-value", c), e("update:model-value", c));
|
|
376
|
-
}
|
|
377
|
-
const L = Y(), H = ee(() => {
|
|
378
|
-
const m = {
|
|
379
|
-
...L
|
|
380
|
-
};
|
|
381
|
-
return delete m["onUpdate:modelValue"], m;
|
|
382
|
-
});
|
|
383
|
-
return (m, c) => {
|
|
384
|
-
const K = te("money3");
|
|
385
|
-
return ne((ie(), re("input", ae({
|
|
386
|
-
id: `${t.id}`
|
|
387
|
-
}, v(H), {
|
|
388
|
-
type: "tel",
|
|
389
|
-
class: "v-money3",
|
|
390
|
-
value: h.value,
|
|
391
|
-
disabled: n.disabled,
|
|
392
|
-
onChange: U
|
|
393
|
-
}), null, 16, oe)), [
|
|
394
|
-
[K, {
|
|
395
|
-
precision: v(u),
|
|
396
|
-
decimal: n.decimal,
|
|
397
|
-
thousands: n.thousands,
|
|
398
|
-
prefix: n.prefix,
|
|
399
|
-
suffix: n.suffix,
|
|
400
|
-
disableNegative: n.disableNegative,
|
|
401
|
-
min: n.min,
|
|
402
|
-
max: n.max,
|
|
403
|
-
allowBlank: n.allowBlank,
|
|
404
|
-
minimumNumberOfCharacters: n.minimumNumberOfCharacters,
|
|
405
|
-
debug: n.debug,
|
|
406
|
-
modelModifiers: v(a),
|
|
407
|
-
shouldRound: v(o),
|
|
408
|
-
focusOnRight: v(g)
|
|
409
|
-
}]
|
|
410
|
-
]);
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
}), ge = {
|
|
414
|
-
install(t) {
|
|
415
|
-
t.component("money3", de), t.directive("money3", q);
|
|
416
|
-
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/defineProperty.js
|
|
134
|
+
function I(e, t, n) {
|
|
135
|
+
return (t = F(t)) in e ? Object.defineProperty(e, t, {
|
|
136
|
+
value: n,
|
|
137
|
+
enumerable: !0,
|
|
138
|
+
configurable: !0,
|
|
139
|
+
writable: !0
|
|
140
|
+
}) : e[t] = n, e;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/BigNumber.ts
|
|
144
|
+
var L = class e {
|
|
145
|
+
constructor(e) {
|
|
146
|
+
I(this, "number", 0n), I(this, "decimal", 0), this.setNumber(e);
|
|
147
|
+
}
|
|
148
|
+
getNumber() {
|
|
149
|
+
return this.number;
|
|
150
|
+
}
|
|
151
|
+
getDecimalPrecision() {
|
|
152
|
+
return this.decimal;
|
|
153
|
+
}
|
|
154
|
+
setNumber(e) {
|
|
155
|
+
this.decimal = 0, typeof e == "bigint" ? this.number = e : typeof e == "number" ? this.setupString(e.toString()) : this.setupString(e);
|
|
156
|
+
}
|
|
157
|
+
toFixed(e = 0, t = !0) {
|
|
158
|
+
let n = this.toString(), r = e - this.getDecimalPrecision();
|
|
159
|
+
return r > 0 ? (n.includes(".") || (n += "."), n.padEnd(n.length + r, "0")) : r < 0 ? t ? k(n, e) : n.slice(0, r) : n;
|
|
160
|
+
}
|
|
161
|
+
toString() {
|
|
162
|
+
let e = this.number.toString();
|
|
163
|
+
if (this.decimal) {
|
|
164
|
+
let t = !1;
|
|
165
|
+
return e.charAt(0) === "-" && (e = e.substring(1), t = !0), e = e.padStart(e.length + this.decimal, "0"), e = `${e.slice(0, -this.decimal)}.${e.slice(-this.decimal)}`, e = T(e), (t ? "-" : "") + e;
|
|
166
|
+
}
|
|
167
|
+
return e;
|
|
168
|
+
}
|
|
169
|
+
lessThan(e) {
|
|
170
|
+
let [t, n] = this.adjustComparisonNumbers(e);
|
|
171
|
+
return t < n;
|
|
172
|
+
}
|
|
173
|
+
biggerThan(e) {
|
|
174
|
+
let [t, n] = this.adjustComparisonNumbers(e);
|
|
175
|
+
return t > n;
|
|
176
|
+
}
|
|
177
|
+
isEqual(e) {
|
|
178
|
+
let [t, n] = this.adjustComparisonNumbers(e);
|
|
179
|
+
return t === n;
|
|
180
|
+
}
|
|
181
|
+
setupString(e) {
|
|
182
|
+
if (e = T(e), E(e)) this.number = BigInt(e);
|
|
183
|
+
else if (D(e)) this.decimal = w(e), this.number = BigInt(e.replace(".", ""));
|
|
184
|
+
else throw Error(`BigNumber has received and invalid format for the constructor: ${e}`);
|
|
185
|
+
}
|
|
186
|
+
adjustComparisonNumbers(t) {
|
|
187
|
+
let n;
|
|
188
|
+
n = t.constructor.name === "BigNumber" ? t : new e(t);
|
|
189
|
+
let r = this.getDecimalPrecision() - n.getDecimalPrecision(), i = this.getNumber(), a = n.getNumber();
|
|
190
|
+
return r > 0 ? a = n.getNumber() * 10n ** BigInt(r) : r < 0 && (i = this.getNumber() * 10n ** BigInt(r * -1)), [i, a];
|
|
191
|
+
}
|
|
417
192
|
};
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/format.ts
|
|
195
|
+
function R(e, t = p, n = "") {
|
|
196
|
+
if (M(t, "utils format() - caller", n), M(t, "utils format() - input1", e), (e == null || e === "") && t.allowBlank) return "";
|
|
197
|
+
if (e == null) e = "";
|
|
198
|
+
else if (typeof e == "number") e = t.shouldRound ? e.toFixed(g(t.precision)) : e.toFixed(g(t.precision) + 1).slice(0, -1);
|
|
199
|
+
else if (t.modelModifiers && t.modelModifiers.number && E(e)) e = Number(e).toFixed(g(t.precision));
|
|
200
|
+
else if (!t.disableNegative && e === "-") return e;
|
|
201
|
+
M(t, "utils format() - input2", e);
|
|
202
|
+
let r = t.disableNegative ? "" : e.indexOf("-") >= 0 ? "-" : "", i = e.replace(t.prefix, "").replace(t.suffix, "");
|
|
203
|
+
M(t, "utils format() - filtered", i), !t.precision && t.thousands !== "." && D(i) && (i = k(i, 0), M(t, "utils format() - !opt.precision && isValidFloat()", i));
|
|
204
|
+
let a = v(i);
|
|
205
|
+
M(t, "utils format() - numbers", a), M(t, "utils format() - numbersToCurrency", r + _(a, t.precision));
|
|
206
|
+
let o = new L(r + _(a, t.precision));
|
|
207
|
+
M(t, "utils format() - bigNumber1", o.toString()), t.max && o.biggerThan(t.max) && o.setNumber(t.max), t.min && o.lessThan(t.min) && o.setNumber(t.min);
|
|
208
|
+
let s = o.toFixed(g(t.precision), t.shouldRound);
|
|
209
|
+
if (M(t, "utils format() - bigNumber2", o.toFixed(g(t.precision))), /^0(\.0+)?$/g.test(s) && t.allowBlank && t.treatZeroAsBlank) return "";
|
|
210
|
+
let [c, l] = s.split("."), u = l === void 0 ? 0 : l.length;
|
|
211
|
+
c = c.padStart(t.minimumNumberOfCharacters - u, "0"), c = y(c, t.thousands);
|
|
212
|
+
let d = t.prefix + b(c, l, t.decimal) + t.suffix;
|
|
213
|
+
return M(t, "utils format() - output", d), d;
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/unformat.ts
|
|
217
|
+
function z(e, t = p, n = "") {
|
|
218
|
+
if (M(t, "utils unformat() - caller", n), M(t, "utils unformat() - input", e), !t.disableNegative && e === "-") return M(t, "utils unformat() - return netagive symbol", e), e;
|
|
219
|
+
let r = t.disableNegative ? "" : e.indexOf("-") >= 0 ? "-" : "", i = e.replace(t.prefix, "").replace(t.suffix, "");
|
|
220
|
+
M(t, "utils unformat() - filtered", i);
|
|
221
|
+
let a = v(i);
|
|
222
|
+
M(t, "utils unformat() - numbers", a);
|
|
223
|
+
let o = new L(r + _(a, t.precision));
|
|
224
|
+
M(t, "utils unformat() - bigNumber1", a.toString()), t.max && o.biggerThan(t.max) && o.setNumber(t.max), t.min && o.lessThan(t.min) && o.setNumber(t.min);
|
|
225
|
+
let s = o.toFixed(g(t.precision), t.shouldRound);
|
|
226
|
+
return t.modelModifiers && t.modelModifiers.number && (s = parseFloat(s)), M(t, "utils unformat() - output", s), s;
|
|
227
|
+
}
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region src/directive.ts
|
|
230
|
+
var B = [
|
|
231
|
+
"precision",
|
|
232
|
+
"decimal",
|
|
233
|
+
"thousands",
|
|
234
|
+
"prefix",
|
|
235
|
+
"suffix",
|
|
236
|
+
"min",
|
|
237
|
+
"max",
|
|
238
|
+
"allowBlank",
|
|
239
|
+
"treatZeroAsBlank",
|
|
240
|
+
"minimumNumberOfCharacters",
|
|
241
|
+
"shouldRound",
|
|
242
|
+
"modelModifiers"
|
|
243
|
+
], V = (e, t, n) => {
|
|
244
|
+
if (M(t, "directive setValue() - caller", n), !S(t)) {
|
|
245
|
+
M(t, "directive setValue() - validateRestrictedOptions() return false. Stopping here...", e.value);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
let r = e.value.length - (e.selectionEnd || 0), i = R(e.value, t, n);
|
|
249
|
+
i !== e.value && (e.value = i, r = Math.max(r, t.suffix.length), r = e.value.length - r, r = Math.max(r, t.prefix.length), A(e, r), e.dispatchEvent(j("change")));
|
|
250
|
+
}, H = (e, t) => {
|
|
251
|
+
let n = e.currentTarget, r = e.code === "Backspace" || e.code === "Delete", i = n.value.length - (n.selectionEnd || 0) === 0;
|
|
252
|
+
if (M(t, "directive onkeydown() - el.value", n.value), M(t, "directive onkeydown() - backspacePressed", r), M(t, "directive onkeydown() - isAtEndPosition", i), t.allowBlank && t.treatZeroAsBlank && r && i && z(n.value, t, "directive onkeydown allowBlank") === 0 && (M(t, "directive onkeydown() - set el.value = \"\"", n.value), n.value = "", n.dispatchEvent(j("change"))), M(t, "directive onkeydown() - e.key", e.key), e.key === "+") {
|
|
253
|
+
M(t, "directive onkeydown() - unformat el.value", n.value);
|
|
254
|
+
let e = z(n.value, t, "directive onkeydown +");
|
|
255
|
+
typeof e == "string" && (e = parseFloat(e)), e < 0 && (n.value = String(e * -1));
|
|
256
|
+
}
|
|
257
|
+
}, U = (e, t) => {
|
|
258
|
+
let n = e.currentTarget;
|
|
259
|
+
M(t, "directive oninput()", n.value), /^[1-9]$/.test(n.value) && (n.value = _(n.value, g(t.precision)), M(t, "directive oninput() - is 1-9", n.value)), V(n, t, "directive oninput");
|
|
260
|
+
}, W = (e, t) => {
|
|
261
|
+
let n = e.currentTarget;
|
|
262
|
+
M(t, "directive onFocus()", n.value), t.focusOnRight && A(n, n.value.length - t.suffix.length);
|
|
263
|
+
}, G = (e) => {
|
|
264
|
+
if (e.tagName.toLocaleUpperCase() !== "INPUT") {
|
|
265
|
+
let t = e.getElementsByTagName("input");
|
|
266
|
+
if (t.length !== 1) throw Error(`v-money3 requires 1 input, found ${t.length} elements.`);
|
|
267
|
+
return t[0];
|
|
268
|
+
}
|
|
269
|
+
return e;
|
|
270
|
+
}, K = (e, t) => {
|
|
271
|
+
e.onkeydown = (e) => {
|
|
272
|
+
H(e, t);
|
|
273
|
+
}, e.oninput = (e) => {
|
|
274
|
+
U(e, t);
|
|
275
|
+
}, e.onfocus = (e) => {
|
|
276
|
+
W(e, t);
|
|
277
|
+
};
|
|
429
278
|
};
|
|
279
|
+
function q(e, t) {
|
|
280
|
+
return e ? B.some((n) => JSON.stringify(e[n]) !== JSON.stringify(t[n])) : !1;
|
|
281
|
+
}
|
|
282
|
+
var J = {
|
|
283
|
+
mounted(e, t) {
|
|
284
|
+
if (!t.value) return;
|
|
285
|
+
let n = C({
|
|
286
|
+
...p,
|
|
287
|
+
...t.value
|
|
288
|
+
});
|
|
289
|
+
M(n, "directive mounted() - opt", n), e = G(e), K(e, n), M(n, "directive mounted() - el.value", e.value), V(e, n, "directive mounted");
|
|
290
|
+
},
|
|
291
|
+
updated(e, t) {
|
|
292
|
+
if (!t.value) return;
|
|
293
|
+
let n = C({
|
|
294
|
+
...p,
|
|
295
|
+
...t.value
|
|
296
|
+
});
|
|
297
|
+
if (M(n, "directive updated() - opt", n), M(n, "directive updated() - el.value", e.value), e = G(e), R(e.value, n, "directive updated check") !== e.value) {
|
|
298
|
+
if (q(t.oldValue ? C({
|
|
299
|
+
...p,
|
|
300
|
+
...t.oldValue
|
|
301
|
+
}) : null, n) && e.value !== "") {
|
|
302
|
+
console.warn("v-money3: runtime change of format options on the bare directive is unsupported and was skipped to avoid corrupting the value. Re-mount the directive or use the Money3 component instead.");
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
V(e, n, "directive updated");
|
|
306
|
+
}
|
|
307
|
+
},
|
|
308
|
+
beforeUnmount(e) {
|
|
309
|
+
e.onkeydown = null, e.oninput = null, e.onfocus = null;
|
|
310
|
+
}
|
|
311
|
+
}, Y = [
|
|
312
|
+
"id",
|
|
313
|
+
"value",
|
|
314
|
+
"disabled"
|
|
315
|
+
], X = /* @__PURE__ */ n({
|
|
316
|
+
inheritAttrs: !1,
|
|
317
|
+
name: "Money3",
|
|
318
|
+
directives: { money3: J },
|
|
319
|
+
__name: "component",
|
|
320
|
+
props: {
|
|
321
|
+
debug: {
|
|
322
|
+
required: !1,
|
|
323
|
+
type: Boolean,
|
|
324
|
+
default: !1
|
|
325
|
+
},
|
|
326
|
+
id: {
|
|
327
|
+
required: !1,
|
|
328
|
+
type: [Number, String],
|
|
329
|
+
default: () => {
|
|
330
|
+
let e = r();
|
|
331
|
+
return e ? e.uid : null;
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
modelValue: {
|
|
335
|
+
required: !0,
|
|
336
|
+
type: [Number, String]
|
|
337
|
+
},
|
|
338
|
+
modelModifiers: {
|
|
339
|
+
required: !1,
|
|
340
|
+
type: Object,
|
|
341
|
+
default: () => ({ number: !1 })
|
|
342
|
+
},
|
|
343
|
+
masked: {
|
|
344
|
+
type: Boolean,
|
|
345
|
+
default: !1
|
|
346
|
+
},
|
|
347
|
+
precision: {
|
|
348
|
+
type: Number,
|
|
349
|
+
default: () => p.precision
|
|
350
|
+
},
|
|
351
|
+
decimal: {
|
|
352
|
+
type: String,
|
|
353
|
+
default: () => p.decimal,
|
|
354
|
+
validator(e) {
|
|
355
|
+
return x(e, "decimal");
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
thousands: {
|
|
359
|
+
type: String,
|
|
360
|
+
default: () => p.thousands,
|
|
361
|
+
validator(e) {
|
|
362
|
+
return x(e, "thousands");
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
prefix: {
|
|
366
|
+
type: String,
|
|
367
|
+
default: () => p.prefix,
|
|
368
|
+
validator(e) {
|
|
369
|
+
return x(e, "prefix");
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
suffix: {
|
|
373
|
+
type: String,
|
|
374
|
+
default: () => p.suffix,
|
|
375
|
+
validator(e) {
|
|
376
|
+
return x(e, "suffix");
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
disableNegative: {
|
|
380
|
+
type: Boolean,
|
|
381
|
+
default: !1
|
|
382
|
+
},
|
|
383
|
+
disabled: {
|
|
384
|
+
type: Boolean,
|
|
385
|
+
default: !1
|
|
386
|
+
},
|
|
387
|
+
max: {
|
|
388
|
+
type: [Number, String],
|
|
389
|
+
default: () => p.max
|
|
390
|
+
},
|
|
391
|
+
min: {
|
|
392
|
+
type: [Number, String],
|
|
393
|
+
default: () => p.min
|
|
394
|
+
},
|
|
395
|
+
allowBlank: {
|
|
396
|
+
type: Boolean,
|
|
397
|
+
default: () => p.allowBlank
|
|
398
|
+
},
|
|
399
|
+
treatZeroAsBlank: {
|
|
400
|
+
type: Boolean,
|
|
401
|
+
default: () => p.treatZeroAsBlank
|
|
402
|
+
},
|
|
403
|
+
minimumNumberOfCharacters: {
|
|
404
|
+
type: Number,
|
|
405
|
+
default: () => p.minimumNumberOfCharacters
|
|
406
|
+
},
|
|
407
|
+
shouldRound: {
|
|
408
|
+
type: Boolean,
|
|
409
|
+
default: () => p.shouldRound
|
|
410
|
+
},
|
|
411
|
+
focusOnRight: {
|
|
412
|
+
type: Boolean,
|
|
413
|
+
default: () => p.focusOnRight
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
emits: ["update:model-value"],
|
|
417
|
+
setup(n, { emit: r }) {
|
|
418
|
+
let p = n, { modelValue: m, modelModifiers: h, masked: _, precision: v, shouldRound: y, focusOnRight: b } = c(p);
|
|
419
|
+
M(p, "component setup()", p);
|
|
420
|
+
let { value: x } = m;
|
|
421
|
+
(p.disableNegative || x !== "-") && h.value && h.value.number && (x = y.value ? Number(m.value).toFixed(g(v.value)) : Number(m.value).toFixed(g(v.value) + 1).slice(0, -1));
|
|
422
|
+
let S = o(R(x, p, "component setup"));
|
|
423
|
+
M(p, "component setup() - data.formattedValue", S.value);
|
|
424
|
+
function w(e) {
|
|
425
|
+
M(p, "component watch() -> value", e);
|
|
426
|
+
let t = R(e, C({ ...p }), "component watch");
|
|
427
|
+
t !== S.value && (M(p, "component watch() changed -> formatted", t), S.value = t);
|
|
428
|
+
}
|
|
429
|
+
d(m, w);
|
|
430
|
+
let T = null, E = r;
|
|
431
|
+
function D() {
|
|
432
|
+
let e = C({ ...p }), t = m.value;
|
|
433
|
+
if (t === "-") return;
|
|
434
|
+
let n = R(t, e, "component opts watch");
|
|
435
|
+
n !== S.value && (S.value = n);
|
|
436
|
+
let r = z(n, e, "component opts watch reunformat"), i = Number(t), a = Number(r);
|
|
437
|
+
!Number.isNaN(i) && !Number.isNaN(a) && i !== a && a !== T && (T = a, E("update:model-value", r));
|
|
438
|
+
}
|
|
439
|
+
d(() => [
|
|
440
|
+
p.precision,
|
|
441
|
+
p.decimal,
|
|
442
|
+
p.thousands,
|
|
443
|
+
p.prefix,
|
|
444
|
+
p.suffix,
|
|
445
|
+
p.min,
|
|
446
|
+
p.max,
|
|
447
|
+
p.allowBlank,
|
|
448
|
+
p.treatZeroAsBlank,
|
|
449
|
+
p.minimumNumberOfCharacters,
|
|
450
|
+
p.shouldRound
|
|
451
|
+
], D), d(() => p.modelModifiers, D, { deep: !0 });
|
|
452
|
+
function O(e) {
|
|
453
|
+
let t = e.target.value;
|
|
454
|
+
M(p, "component change() -> evt.target.value", t), _.value && !h.value.number || (t = z(t, C({ ...p }), "component change")), t !== T && (T = t, M(p, "component change() -> update:model-value", t), E("update:model-value", t));
|
|
455
|
+
}
|
|
456
|
+
let k = u(), A = e(() => {
|
|
457
|
+
let e = { ...k };
|
|
458
|
+
return delete e["onUpdate:modelValue"], e;
|
|
459
|
+
});
|
|
460
|
+
return (e, r) => {
|
|
461
|
+
let o = s("money3");
|
|
462
|
+
return f((a(), t("input", i({ id: `${n.id}` }, A.value, {
|
|
463
|
+
type: "tel",
|
|
464
|
+
class: "v-money3",
|
|
465
|
+
value: S.value,
|
|
466
|
+
disabled: p.disabled,
|
|
467
|
+
onChange: O
|
|
468
|
+
}), null, 16, Y)), [[o, {
|
|
469
|
+
precision: l(v),
|
|
470
|
+
decimal: p.decimal,
|
|
471
|
+
thousands: p.thousands,
|
|
472
|
+
prefix: p.prefix,
|
|
473
|
+
suffix: p.suffix,
|
|
474
|
+
disableNegative: p.disableNegative,
|
|
475
|
+
min: p.min,
|
|
476
|
+
max: p.max,
|
|
477
|
+
allowBlank: p.allowBlank,
|
|
478
|
+
treatZeroAsBlank: p.treatZeroAsBlank,
|
|
479
|
+
minimumNumberOfCharacters: p.minimumNumberOfCharacters,
|
|
480
|
+
debug: p.debug,
|
|
481
|
+
modelModifiers: l(h),
|
|
482
|
+
shouldRound: l(y),
|
|
483
|
+
focusOnRight: l(b)
|
|
484
|
+
}]]);
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}), Z = { install(e) {
|
|
488
|
+
e.component("money3", X), e.directive("money3", J);
|
|
489
|
+
} };
|
|
490
|
+
//#endregion
|
|
491
|
+
export { L as BigNumber, X as Money, X as Money3, X as Money3Component, J as Money3Directive, J as VMoney, J as VMoney3, Z as default, R as format, z as unformat };
|
package/dist/v-money3.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l["v-money3"]={},l.Vue))})(this,function(l,a){"use strict";var ee=Object.defineProperty;var te=(l,a,o)=>a in l?ee(l,a,{enumerable:!0,configurable:!0,writable:!0,value:o}):l[a]=o;var C=(l,a,o)=>(te(l,typeof a!="symbol"?a+"":a,o),o);const o={debug:!1,masked:!1,prefix:"",suffix:"",thousands:",",decimal:".",precision:2,disableNegative:!1,disabled:!1,min:null,max:null,allowBlank:!1,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0,focusOnRight:!1},M=["+","-"],O=["decimal","thousands","prefix","suffix"];function m(t){return Math.max(0,Math.min(t,1e3))}function p(t,e){return t=t.padStart(e+1,"0"),e===0?t:`${t.slice(0,-e)}.${t.slice(-e)}`}function E(t){return t=t?t.toString():"",t.replace(/\D+/g,"")||"0"}function H(t,e){return t.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${e}`)}function K(t,e,n){return e?t+n+e:t}function y(t,e){return M.includes(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" as a value.`),!1):/\d/g.test(t)?(console.warn(`v-money3 "${e}" property don't accept "${t}" (any number) as a value.`),!1):!0}function W(t){for(const e of O)if(!y(t[e],e))return!1;return!0}function w(t){for(const e of O){t[e]=t[e].replace(/\d+/g,"");for(const n of M)t[e]=t[e].replaceAll(n,"")}return t}function V(t){const e=t.length,n=t.indexOf(".");return e-(n+1)}function $(t){return t.replace(/^(-?)0+(?!\.)(.+)/,"$1$2")}function F(t){return/^-?[\d]+$/g.test(t)}function I(t){return/^-?[\d]+(\.[\d]+)$/g.test(t)}function D(t,e,n){return e>t.length-1?t:t.substring(0,e)+n+t.substring(e+1)}function A(t,e){const n=e-V(t);if(n>=0)return t;let i=t.slice(0,n);const s=t.slice(n);if(i.charAt(i.length-1)==="."&&(i=i.slice(0,-1)),parseInt(s.charAt(0),10)>=5){for(let u=i.length-1;u>=0;u-=1){const c=i.charAt(u);if(c!=="."&&c!=="-"){const d=parseInt(c,10)+1;if(d<10)return D(i,u,d);i=D(i,u,"0")}}return`1${i}`}return i}function P(t,e){const n=()=>{t.setSelectionRange(e,e)};t===document.activeElement&&(n(),setTimeout(n,1))}function _(t){return new Event(t,{bubbles:!0,cancelable:!1})}function r({debug:t=!1},...e){t&&console.log(...e)}class N{constructor(e){C(this,"number",0n);C(this,"decimal",0);this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e=="bigint"?this.number=e:typeof e=="number"?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,n=!0){let i=this.toString();const s=e-this.getDecimalPrecision();return s>0?(i.includes(".")||(i+="."),i.padEnd(i.length+s,"0")):s<0?n?A(i,e):i.slice(0,s):i}toString(){let e=this.number.toString();if(this.decimal){let n=!1;return e.charAt(0)==="-"&&(e=e.substring(1),n=!0),e=e.padStart(e.length+this.decimal,"0"),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=$(e),(n?"-":"")+e}return e}lessThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n<i}biggerThan(e){const[n,i]=this.adjustComparisonNumbers(e);return n>i}isEqual(e){const[n,i]=this.adjustComparisonNumbers(e);return n===i}setupString(e){if(e=$(e),F(e))this.number=BigInt(e);else if(I(e))this.decimal=V(e),this.number=BigInt(e.replace(".",""));else throw new Error(`BigNumber has received and invalid format for the constructor: ${e}`)}adjustComparisonNumbers(e){let n;e.constructor.name!=="BigNumber"?n=new N(e):n=e;const i=this.getDecimalPrecision()-n.getDecimalPrecision();let s=this.getNumber(),u=n.getNumber();return i>0?u=n.getNumber()*10n**BigInt(i):i<0&&(s=this.getNumber()*10n**BigInt(i*-1)),[s,u]}}function S(t,e=o,n=""){if(r(e,"utils format() - caller",n),r(e,"utils format() - input1",t),t==null)t="";else if(typeof t=="number")e.shouldRound?t=t.toFixed(m(e.precision)):t=t.toFixed(m(e.precision)+1).slice(0,-1);else if(e.modelModifiers&&e.modelModifiers.number&&F(t))t=Number(t).toFixed(m(e.precision));else if(!e.disableNegative&&t==="-")return t;r(e,"utils format() - input2",t);const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"";let s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils format() - filtered",s),!e.precision&&e.thousands!=="."&&I(s)&&(s=A(s,0),r(e,"utils format() - !opt.precision && isValidFloat()",s));const u=E(s);r(e,"utils format() - numbers",u),r(e,"utils format() - numbersToCurrency",i+p(u,e.precision));const c=new N(i+p(u,e.precision));r(e,"utils format() - bigNumber1",c.toString()),e.max&&c.biggerThan(e.max)&&c.setNumber(e.max),e.min&&c.lessThan(e.min)&&c.setNumber(e.min);const d=c.toFixed(m(e.precision),e.shouldRound);if(r(e,"utils format() - bigNumber2",c.toFixed(m(e.precision))),/^0(\.0+)?$/g.test(d)&&e.allowBlank)return"";let[v,g]=d.split(".");const b=g!==void 0?g.length:0;v=v.padStart(e.minimumNumberOfCharacters-b,"0"),v=H(v,e.thousands);const B=e.prefix+K(v,g,e.decimal)+e.suffix;return r(e,"utils format() - output",B),B}function k(t,e=o,n=""){if(r(e,"utils unformat() - caller",n),r(e,"utils unformat() - input",t),!e.disableNegative&&t==="-")return r(e,"utils unformat() - return netagive symbol",t),t;const i=e.disableNegative?"":t.indexOf("-")>=0?"-":"",s=t.replace(e.prefix,"").replace(e.suffix,"");r(e,"utils unformat() - filtered",s);const u=E(s);r(e,"utils unformat() - numbers",u);const c=new N(i+p(u,e.precision));r(e,"utils unformat() - bigNumber1",u.toString()),e.max&&c.biggerThan(e.max)&&c.setNumber(e.max),e.min&&c.lessThan(e.min)&&c.setNumber(e.min);let d=c.toFixed(m(e.precision),e.shouldRound);return e.modelModifiers&&e.modelModifiers.number&&(d=parseFloat(d)),r(e,"utils unformat() - output",d),d}const T=(t,e,n)=>{if(r(e,"directive setValue() - caller",n),!W(e)){r(e,"directive setValue() - validateRestrictedOptions() return false. Stopping here...",t.value);return}let i=t.value.length-(t.selectionEnd||0);t.value=S(t.value,e,n),i=Math.max(i,e.suffix.length),i=t.value.length-i,i=Math.max(i,e.prefix.length),P(t,i),t.dispatchEvent(_("change"))},j=(t,e)=>{const n=t.currentTarget,i=t.code==="Backspace"||t.code==="Delete",s=n.value.length-(n.selectionEnd||0)===0;if(r(e,"directive onkeydown() - el.value",n.value),r(e,"directive onkeydown() - backspacePressed",i),r(e,"directive onkeydown() - isAtEndPosition",s),e.allowBlank&&i&&s&&k(n.value,e,"directive onkeydown allowBlank")===0&&(r(e,'directive onkeydown() - set el.value = ""',n.value),n.value="",n.dispatchEvent(_("change"))),r(e,"directive onkeydown() - e.key",t.key),t.key==="+"){r(e,"directive onkeydown() - unformat el.value",n.value);let u=k(n.value,e,"directive onkeydown +");typeof u=="string"&&(u=parseFloat(u)),u<0&&(n.value=String(u*-1))}},q=(t,e)=>{const n=t.currentTarget;r(e,"directive oninput()",n.value),/^[1-9]$/.test(n.value)&&(n.value=p(n.value,m(e.precision)),r(e,"directive oninput() - is 1-9",n.value)),T(n,e,"directive oninput")},U=(t,e)=>{const n=t.currentTarget;r(e,"directive onFocus()",n.value),e.focusOnRight&&P(n,n.value.length-e.suffix.length)},x={mounted(t,e){if(!e.value)return;const n=w({...o,...e.value});if(r(n,"directive mounted() - opt",n),t.tagName.toLocaleUpperCase()!=="INPUT"){const i=t.getElementsByTagName("input");i.length!==1||(t=i[0])}t.onkeydown=i=>{j(i,n)},t.oninput=i=>{q(i,n)},t.onfocus=i=>{U(i,n)},r(n,"directive mounted() - el.value",t.value),T(t,n,"directive mounted")},updated(t,e){if(!e.value)return;const n=w({...o,...e.value});t.onkeydown=i=>{j(i,n)},t.oninput=i=>{q(i,n)},t.onfocus=i=>{U(i,n)},r(n,"directive updated() - el.value",t.value),r(n,"directive updated() - opt",n),T(t,n,"directive updated")},beforeUnmount(t){t.onkeydown=null,t.oninput=null,t.onfocus=null}},Z=["id","value","disabled"],z={inheritAttrs:!1,name:"Money3",directives:{money3:x}},R=a.defineComponent({...z,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{const t=a.getCurrentInstance();return t?t.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>o.precision},decimal:{type:String,default:()=>o.decimal,validator(t){return y(t,"decimal")}},thousands:{type:String,default:()=>o.thousands,validator(t){return y(t,"thousands")}},prefix:{type:String,default:()=>o.prefix,validator(t){return y(t,"prefix")}},suffix:{type:String,default:()=>o.suffix,validator(t){return y(t,"suffix")}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>o.max},min:{type:[Number,String],default:()=>o.min},allowBlank:{type:Boolean,default:()=>o.allowBlank},minimumNumberOfCharacters:{type:Number,default:()=>o.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>o.shouldRound},focusOnRight:{type:Boolean,default:()=>o.focusOnRight}},emits:["update:model-value"],setup(t,{emit:e}){const n=t,{modelValue:i,modelModifiers:s,masked:u,precision:c,shouldRound:d,focusOnRight:v}=a.toRefs(n);r(n,"component setup()",n);let g=i.value;(n.disableNegative||g!=="-")&&s.value&&s.value.number&&(d.value?g=Number(i.value).toFixed(m(c.value)):g=Number(i.value).toFixed(m(c.value)+1).slice(0,-1));const b=a.ref(S(g,n,"component setup"));r(n,"component setup() - data.formattedValue",b.value),a.watch(i,B);function B(h){r(n,"component watch() -> value",h);const f=S(h,w({...n}),"component watch");f!==b.value&&(r(n,"component watch() changed -> formatted",f),b.value=f)}let L=null;function J(h){let f=h.target.value;r(n,"component change() -> evt.target.value",f),u.value&&!s.value.number||(f=k(f,w({...n}),"component change")),f!==L&&(L=f,r(n,"component change() -> update:model-value",f),e("update:model-value",f))}const Q=a.useAttrs(),X=a.computed(()=>{const h={...Q};return delete h["onUpdate:modelValue"],h});return(h,f)=>{const Y=a.resolveDirective("money3");return a.withDirectives((a.openBlock(),a.createElementBlock("input",a.mergeProps({id:`${t.id}`},a.unref(X),{type:"tel",class:"v-money3",value:b.value,disabled:n.disabled,onChange:J}),null,16,Z)),[[Y,{precision:a.unref(c),decimal:n.decimal,thousands:n.thousands,prefix:n.prefix,suffix:n.suffix,disableNegative:n.disableNegative,min:n.min,max:n.max,allowBlank:n.allowBlank,minimumNumberOfCharacters:n.minimumNumberOfCharacters,debug:n.debug,modelModifiers:a.unref(s),shouldRound:a.unref(d),focusOnRight:a.unref(v)}]])}}}),G={install(t){t.component("money3",R),t.directive("money3",x)}};l.BigNumber=N,l.Money=R,l.Money3=R,l.Money3Component=R,l.Money3Directive=x,l.VMoney=x,l.VMoney3=x,l.default=G,l.format=S,l.unformat=k,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`)):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`v-money3`]={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n={debug:!1,masked:!1,prefix:``,suffix:``,thousands:`,`,decimal:`.`,precision:2,disableNegative:!1,disabled:!1,min:null,max:null,allowBlank:!1,treatZeroAsBlank:!0,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0,focusOnRight:!1,lazy:!0},r=[`+`,`-`],i=[`decimal`,`thousands`,`prefix`,`suffix`];function a(e){return Math.max(0,Math.min(e,1e3))}function o(e,t){return e=e.padStart(t+1,`0`),t===0?e:`${e.slice(0,-t)}.${e.slice(-t)}`}function s(e){return e=e?e.toString():``,e.replace(/\D+/g,``)||`0`}function c(e,t){return e.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${t}`)}function l(e,t,n){return t?e+n+t:e}function u(e,t){return r.includes(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`),!1):/\d/g.test(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`),!1):!0}function d(e){for(let t of i)if(!u(e[t],t))return!1;return!0}function f(e){for(let t of i){e[t]=e[t].replace(/\d+/g,``);for(let n of r)e[t]=e[t].replaceAll(n,``)}return e}function p(e){return e.length-(e.indexOf(`.`)+1)}function m(e){return e.replace(/^(-?)0+(?!\.)(.+)/,`$1$2`)}function h(e){return/^-?[\d]+$/g.test(e)}function g(e){return/^-?[\d]+(\.[\d]+)$/g.test(e)}function _(e,t,n){return t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1)}function v(e,t){let n=t-p(e);if(n>=0)return e;let r=e.slice(0,n),i=e.slice(n);if(r.charAt(r.length-1)===`.`&&(r=r.slice(0,-1)),parseInt(i.charAt(0),10)>=5){for(let e=r.length-1;e>=0;--e){let t=r.charAt(e);if(t!==`.`&&t!==`-`){let n=parseInt(t,10)+1;if(n<10)return _(r,e,n);r=_(r,e,`0`)}}return`1${r}`}return r}function y(e,t){let n=()=>{e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}function b(e){return new Event(e,{bubbles:!0,cancelable:!1})}function x({debug:e=!1},...t){e&&console.log(...t)}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function w(e){var t=C(e,`string`);return S(t)==`symbol`?t:t+``}function T(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var E=class e{constructor(e){T(this,`number`,0n),T(this,`decimal`,0),this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e==`bigint`?this.number=e:typeof e==`number`?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,t=!0){let n=this.toString(),r=e-this.getDecimalPrecision();return r>0?(n.includes(`.`)||(n+=`.`),n.padEnd(n.length+r,`0`)):r<0?t?v(n,e):n.slice(0,r):n}toString(){let e=this.number.toString();if(this.decimal){let t=!1;return e.charAt(0)===`-`&&(e=e.substring(1),t=!0),e=e.padStart(e.length+this.decimal,`0`),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=m(e),(t?`-`:``)+e}return e}lessThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t<n}biggerThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t>n}isEqual(e){let[t,n]=this.adjustComparisonNumbers(e);return t===n}setupString(e){if(e=m(e),h(e))this.number=BigInt(e);else if(g(e))this.decimal=p(e),this.number=BigInt(e.replace(`.`,``));else throw Error(`BigNumber has received and invalid format for the constructor: ${e}`)}adjustComparisonNumbers(t){let n;n=t.constructor.name===`BigNumber`?t:new e(t);let r=this.getDecimalPrecision()-n.getDecimalPrecision(),i=this.getNumber(),a=n.getNumber();return r>0?a=n.getNumber()*10n**BigInt(r):r<0&&(i=this.getNumber()*10n**BigInt(r*-1)),[i,a]}};function D(e,t=n,r=``){if(x(t,`utils format() - caller`,r),x(t,`utils format() - input1`,e),(e==null||e===``)&&t.allowBlank)return``;if(e==null)e=``;else if(typeof e==`number`)e=t.shouldRound?e.toFixed(a(t.precision)):e.toFixed(a(t.precision)+1).slice(0,-1);else if(t.modelModifiers&&t.modelModifiers.number&&h(e))e=Number(e).toFixed(a(t.precision));else if(!t.disableNegative&&e===`-`)return e;x(t,`utils format() - input2`,e);let i=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,u=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils format() - filtered`,u),!t.precision&&t.thousands!==`.`&&g(u)&&(u=v(u,0),x(t,`utils format() - !opt.precision && isValidFloat()`,u));let d=s(u);x(t,`utils format() - numbers`,d),x(t,`utils format() - numbersToCurrency`,i+o(d,t.precision));let f=new E(i+o(d,t.precision));x(t,`utils format() - bigNumber1`,f.toString()),t.max&&f.biggerThan(t.max)&&f.setNumber(t.max),t.min&&f.lessThan(t.min)&&f.setNumber(t.min);let p=f.toFixed(a(t.precision),t.shouldRound);if(x(t,`utils format() - bigNumber2`,f.toFixed(a(t.precision))),/^0(\.0+)?$/g.test(p)&&t.allowBlank&&t.treatZeroAsBlank)return``;let[m,_]=p.split(`.`),y=_===void 0?0:_.length;m=m.padStart(t.minimumNumberOfCharacters-y,`0`),m=c(m,t.thousands);let b=t.prefix+l(m,_,t.decimal)+t.suffix;return x(t,`utils format() - output`,b),b}function O(e,t=n,r=``){if(x(t,`utils unformat() - caller`,r),x(t,`utils unformat() - input`,e),!t.disableNegative&&e===`-`)return x(t,`utils unformat() - return netagive symbol`,e),e;let i=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,c=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils unformat() - filtered`,c);let l=s(c);x(t,`utils unformat() - numbers`,l);let u=new E(i+o(l,t.precision));x(t,`utils unformat() - bigNumber1`,l.toString()),t.max&&u.biggerThan(t.max)&&u.setNumber(t.max),t.min&&u.lessThan(t.min)&&u.setNumber(t.min);let d=u.toFixed(a(t.precision),t.shouldRound);return t.modelModifiers&&t.modelModifiers.number&&(d=parseFloat(d)),x(t,`utils unformat() - output`,d),d}var k=[`precision`,`decimal`,`thousands`,`prefix`,`suffix`,`min`,`max`,`allowBlank`,`treatZeroAsBlank`,`minimumNumberOfCharacters`,`shouldRound`,`modelModifiers`],A=(e,t,n)=>{if(x(t,`directive setValue() - caller`,n),!d(t)){x(t,`directive setValue() - validateRestrictedOptions() return false. Stopping here...`,e.value);return}let r=e.value.length-(e.selectionEnd||0),i=D(e.value,t,n);i!==e.value&&(e.value=i,r=Math.max(r,t.suffix.length),r=e.value.length-r,r=Math.max(r,t.prefix.length),y(e,r),e.dispatchEvent(b(`change`)))},j=(e,t)=>{let n=e.currentTarget,r=e.code===`Backspace`||e.code===`Delete`,i=n.value.length-(n.selectionEnd||0)===0;if(x(t,`directive onkeydown() - el.value`,n.value),x(t,`directive onkeydown() - backspacePressed`,r),x(t,`directive onkeydown() - isAtEndPosition`,i),t.allowBlank&&t.treatZeroAsBlank&&r&&i&&O(n.value,t,`directive onkeydown allowBlank`)===0&&(x(t,`directive onkeydown() - set el.value = ""`,n.value),n.value=``,n.dispatchEvent(b(`change`))),x(t,`directive onkeydown() - e.key`,e.key),e.key===`+`){x(t,`directive onkeydown() - unformat el.value`,n.value);let e=O(n.value,t,`directive onkeydown +`);typeof e==`string`&&(e=parseFloat(e)),e<0&&(n.value=String(e*-1))}},M=(e,t)=>{let n=e.currentTarget;x(t,`directive oninput()`,n.value),/^[1-9]$/.test(n.value)&&(n.value=o(n.value,a(t.precision)),x(t,`directive oninput() - is 1-9`,n.value)),A(n,t,`directive oninput`)},N=(e,t)=>{let n=e.currentTarget;x(t,`directive onFocus()`,n.value),t.focusOnRight&&y(n,n.value.length-t.suffix.length)},P=e=>{if(e.tagName.toLocaleUpperCase()!==`INPUT`){let t=e.getElementsByTagName(`input`);if(t.length!==1)throw Error(`v-money3 requires 1 input, found ${t.length} elements.`);return t[0]}return e},F=(e,t)=>{e.onkeydown=e=>{j(e,t)},e.oninput=e=>{M(e,t)},e.onfocus=e=>{N(e,t)}};function I(e,t){return e?k.some(n=>JSON.stringify(e[n])!==JSON.stringify(t[n])):!1}var L={mounted(e,t){if(!t.value)return;let r=f({...n,...t.value});x(r,`directive mounted() - opt`,r),e=P(e),F(e,r),x(r,`directive mounted() - el.value`,e.value),A(e,r,`directive mounted`)},updated(e,t){if(!t.value)return;let r=f({...n,...t.value});if(x(r,`directive updated() - opt`,r),x(r,`directive updated() - el.value`,e.value),e=P(e),D(e.value,r,`directive updated check`)!==e.value){if(I(t.oldValue?f({...n,...t.oldValue}):null,r)&&e.value!==``){console.warn(`v-money3: runtime change of format options on the bare directive is unsupported and was skipped to avoid corrupting the value. Re-mount the directive or use the Money3 component instead.`);return}A(e,r,`directive updated`)}},beforeUnmount(e){e.onkeydown=null,e.oninput=null,e.onfocus=null}},R=[`id`,`value`,`disabled`],z=(0,t.defineComponent)({inheritAttrs:!1,name:`Money3`,directives:{money3:L},__name:`component`,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{let e=(0,t.getCurrentInstance)();return e?e.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>n.precision},decimal:{type:String,default:()=>n.decimal,validator(e){return u(e,`decimal`)}},thousands:{type:String,default:()=>n.thousands,validator(e){return u(e,`thousands`)}},prefix:{type:String,default:()=>n.prefix,validator(e){return u(e,`prefix`)}},suffix:{type:String,default:()=>n.suffix,validator(e){return u(e,`suffix`)}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>n.max},min:{type:[Number,String],default:()=>n.min},allowBlank:{type:Boolean,default:()=>n.allowBlank},treatZeroAsBlank:{type:Boolean,default:()=>n.treatZeroAsBlank},minimumNumberOfCharacters:{type:Number,default:()=>n.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>n.shouldRound},focusOnRight:{type:Boolean,default:()=>n.focusOnRight}},emits:[`update:model-value`],setup(e,{emit:n}){let r=e,{modelValue:i,modelModifiers:o,masked:s,precision:c,shouldRound:l,focusOnRight:u}=(0,t.toRefs)(r);x(r,`component setup()`,r);let{value:d}=i;(r.disableNegative||d!==`-`)&&o.value&&o.value.number&&(d=l.value?Number(i.value).toFixed(a(c.value)):Number(i.value).toFixed(a(c.value)+1).slice(0,-1));let p=(0,t.ref)(D(d,r,`component setup`));x(r,`component setup() - data.formattedValue`,p.value);function m(e){x(r,`component watch() -> value`,e);let t=D(e,f({...r}),`component watch`);t!==p.value&&(x(r,`component watch() changed -> formatted`,t),p.value=t)}(0,t.watch)(i,m);let h=null,g=n;function _(){let e=f({...r}),t=i.value;if(t===`-`)return;let n=D(t,e,`component opts watch`);n!==p.value&&(p.value=n);let a=O(n,e,`component opts watch reunformat`),o=Number(t),s=Number(a);!Number.isNaN(o)&&!Number.isNaN(s)&&o!==s&&s!==h&&(h=s,g(`update:model-value`,a))}(0,t.watch)(()=>[r.precision,r.decimal,r.thousands,r.prefix,r.suffix,r.min,r.max,r.allowBlank,r.treatZeroAsBlank,r.minimumNumberOfCharacters,r.shouldRound],_),(0,t.watch)(()=>r.modelModifiers,_,{deep:!0});function v(e){let t=e.target.value;x(r,`component change() -> evt.target.value`,t),s.value&&!o.value.number||(t=O(t,f({...r}),`component change`)),t!==h&&(h=t,x(r,`component change() -> update:model-value`,t),g(`update:model-value`,t))}let y=(0,t.useAttrs)(),b=(0,t.computed)(()=>{let e={...y};return delete e[`onUpdate:modelValue`],e});return(n,i)=>{let a=(0,t.resolveDirective)(`money3`);return(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`input`,(0,t.mergeProps)({id:`${e.id}`},b.value,{type:`tel`,class:`v-money3`,value:p.value,disabled:r.disabled,onChange:v}),null,16,R)),[[a,{precision:(0,t.unref)(c),decimal:r.decimal,thousands:r.thousands,prefix:r.prefix,suffix:r.suffix,disableNegative:r.disableNegative,min:r.min,max:r.max,allowBlank:r.allowBlank,treatZeroAsBlank:r.treatZeroAsBlank,minimumNumberOfCharacters:r.minimumNumberOfCharacters,debug:r.debug,modelModifiers:(0,t.unref)(o),shouldRound:(0,t.unref)(l),focusOnRight:(0,t.unref)(u)}]])}}});e.BigNumber=E,e.Money=z,e.Money3=z,e.Money3Component=z,e.Money3Directive=L,e.VMoney=L,e.VMoney3=L,e.default={install(e){e.component(`money3`,z),e.directive(`money3`,L)}},e.format=D,e.unformat=O});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "v-money3",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.25.0",
|
|
4
4
|
"description": "Vue3 currency input/directive mask",
|
|
5
5
|
"main": "./dist/v-money3.umd.js",
|
|
6
6
|
"module": "./dist/v-money3.mjs",
|
|
@@ -55,29 +55,30 @@
|
|
|
55
55
|
"vue": ">= 3.2.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@babel/plugin-transform-runtime": "7.
|
|
59
|
-
"@babel/preset-env": "7.
|
|
60
|
-
"@types/jest": "29.5.
|
|
61
|
-
"@types/jest-environment-puppeteer": "5.0.
|
|
58
|
+
"@babel/plugin-transform-runtime": "7.23.9",
|
|
59
|
+
"@babel/preset-env": "7.23.9",
|
|
60
|
+
"@types/jest": "29.5.11",
|
|
61
|
+
"@types/jest-environment-puppeteer": "5.0.6",
|
|
62
62
|
"@types/puppeteer": "5.4.7",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "
|
|
64
|
-
"@typescript-eslint/parser": "
|
|
65
|
-
"@vitejs/plugin-vue": "
|
|
66
|
-
"@vue/compiler-sfc": "3.
|
|
67
|
-
"@vue/test-utils": "2.
|
|
68
|
-
"
|
|
69
|
-
"
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "7.18",
|
|
64
|
+
"@typescript-eslint/parser": "7.18",
|
|
65
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
66
|
+
"@vue/compiler-sfc": "3.4.15",
|
|
67
|
+
"@vue/test-utils": "2.4.4",
|
|
68
|
+
"@vue/vue3-jest": "29.2.6",
|
|
69
|
+
"babel-jest": "29.7.0",
|
|
70
|
+
"eslint": "^8.57.1",
|
|
70
71
|
"eslint-config-airbnb-base": "15.0.0",
|
|
71
|
-
"eslint-config-airbnb-typescript": "
|
|
72
|
-
"eslint-plugin-import": "2.
|
|
73
|
-
"eslint-plugin-vue": "9.
|
|
74
|
-
"jest": "
|
|
75
|
-
"jest-
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"vue
|
|
81
|
-
"vue-tsc": "
|
|
72
|
+
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
73
|
+
"eslint-plugin-import": "2.29.1",
|
|
74
|
+
"eslint-plugin-vue": "9.20.1",
|
|
75
|
+
"jest": "29.7.0",
|
|
76
|
+
"jest-environment-jsdom": "^30.4.1",
|
|
77
|
+
"jest-puppeteer": "^11.0.0",
|
|
78
|
+
"node": "^22.22.3",
|
|
79
|
+
"ts-jest": "29.1.2",
|
|
80
|
+
"vite": "^8.0.13",
|
|
81
|
+
"vue": "3.4.15",
|
|
82
|
+
"vue-tsc": "^3.2.9"
|
|
82
83
|
}
|
|
83
84
|
}
|