mother-mask 3.11.0 → 3.13.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 +253 -21
- package/dist/mother-mask.cjs +1 -1
- package/dist/mother-mask.cjs.map +1 -1
- package/dist/mother-mask.d.cts +36 -13
- package/dist/mother-mask.d.mts +36 -13
- package/dist/mother-mask.mjs +1 -1
- package/dist/mother-mask.mjs.map +1 -1
- package/dist/mother-mask.umd.js +1 -1
- package/dist/mother-mask.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Lightweight input masks for browser forms. Zero runtime dependencies, written in TypeScript, and published with ESM, CJS, and UMD builds.
|
|
4
4
|
|
|
5
|
-
[npm](https://www.npmjs.com/package/mother-mask) | [
|
|
5
|
+
[npm](https://www.npmjs.com/package/mother-mask) | [Documentation and live examples](https://dan2dev.github.io/mother-mask/)
|
|
6
|
+
|
|
7
|
+
Format phone numbers, dates, identifiers, and decimal inputs with static patterns,
|
|
8
|
+
custom tokens, or a mask chosen from the value. Formatting does **not** validate
|
|
9
|
+
dates, checksums, card networks, or whether an identifier exists; validate those
|
|
10
|
+
separately in your application.
|
|
11
|
+
|
|
12
|
+
[Basic usage](#basic-usage) · [Decimals](#decimal-inputs) ·
|
|
13
|
+
[Patterns](#pattern-syntax) · [Custom tokens](#custom-tokens-and-transforms) ·
|
|
14
|
+
[Dynamic masks](#content-dependent-masks) · [Editing](#segmented-editing) · [API](#api)
|
|
6
15
|
|
|
7
16
|
## Install
|
|
8
17
|
|
|
@@ -16,6 +25,12 @@ pnpm add mother-mask
|
|
|
16
25
|
|
|
17
26
|
## Basic Usage
|
|
18
27
|
|
|
28
|
+
Use a text input with an appropriate keyboard hint:
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<input id="phone" type="text" inputmode="tel" aria-label="Phone number" />
|
|
32
|
+
```
|
|
33
|
+
|
|
19
34
|
```ts
|
|
20
35
|
import { bind } from 'mother-mask'
|
|
21
36
|
|
|
@@ -27,12 +42,16 @@ const dispose = bind(input, '(99) 99999-9999')
|
|
|
27
42
|
dispose()
|
|
28
43
|
```
|
|
29
44
|
|
|
30
|
-
Use an ordered mask array for values with more than one length
|
|
45
|
+
Use an ordered mask array for values with more than one length. Order by data
|
|
46
|
+
capacity, shortest first; selection uses the number of accepted characters, not
|
|
47
|
+
their content:
|
|
31
48
|
|
|
32
49
|
```ts
|
|
33
50
|
bind(input, ['(99) 9999-9999', '(99) 99999-9999'])
|
|
34
51
|
```
|
|
35
52
|
|
|
53
|
+
Use [`resolveMask`](#content-dependent-masks) when a prefix determines the layout.
|
|
54
|
+
|
|
36
55
|
Listen for changes with either a callback or an options object:
|
|
37
56
|
|
|
38
57
|
```ts
|
|
@@ -47,6 +66,17 @@ bind(input, '999.999.999-99', {
|
|
|
47
66
|
})
|
|
48
67
|
```
|
|
49
68
|
|
|
69
|
+
Bind each input once. Calling `bind` or `bindDecimal` on an already-bound input
|
|
70
|
+
does nothing; dispose the existing binding before changing its options. In a UI
|
|
71
|
+
framework, bind after the input mounts and call the disposer during cleanup.
|
|
72
|
+
Disposal removes listeners, pending frames, and attributes added by the library;
|
|
73
|
+
attributes that were already present are preserved.
|
|
74
|
+
|
|
75
|
+
Binding does not format the initial value or fire an initial callback. Use the
|
|
76
|
+
[pure helpers](#formatting-without-an-input) to prepare values before binding.
|
|
77
|
+
Assignments to `input.value` do not dispatch an input event, so format programmatic
|
|
78
|
+
updates yourself as well.
|
|
79
|
+
|
|
50
80
|
## Decimal Inputs
|
|
51
81
|
|
|
52
82
|
Use `bindDecimal` for numbers, currency fields, and values where the integer part should grow freely.
|
|
@@ -71,12 +101,33 @@ For Brazilian-style formatting:
|
|
|
71
101
|
|
|
72
102
|
```ts
|
|
73
103
|
bindDecimal(input, {
|
|
104
|
+
decimalPlaces: 2,
|
|
74
105
|
separator: '.',
|
|
75
106
|
decimalSeparator: ',',
|
|
76
107
|
})
|
|
77
108
|
```
|
|
78
109
|
|
|
79
|
-
|
|
110
|
+
Without `decimalPlaces`, the fraction is optional and has no length limit. Set it
|
|
111
|
+
to `2` for two fixed, zero-padded places, or `0` for integers only. `numberPlaces`
|
|
112
|
+
optionally pads and caps the integer part; it is unlimited by default.
|
|
113
|
+
|
|
114
|
+
| Option | Default | Behavior |
|
|
115
|
+
| --- | --- | --- |
|
|
116
|
+
| `decimalPlaces` | Unset | Optional, unlimited fraction; set a width to pad and cap it |
|
|
117
|
+
| `numberPlaces` | Unset | Unlimited integer part; set a width to pad and cap it |
|
|
118
|
+
| `segmented` | `true` | Group the integer part into thousands |
|
|
119
|
+
| `separator` | `','` | Thousands separator |
|
|
120
|
+
| `decimalSeparator` | `'.'` | Separator before the fraction |
|
|
121
|
+
| `prefix`, `suffix` | `''` | Fixed display text, excluded from numeric parsing |
|
|
122
|
+
| `allowNegative` | `false` | Allow negative numbers |
|
|
123
|
+
| `onChange` | Unset | Binding callback receiving the formatted string and JS number |
|
|
124
|
+
|
|
125
|
+
For decimal masks, `segmented` controls thousands grouping. It is separate from
|
|
126
|
+
the independent-field behavior of pattern masks. Use `type="text"` and
|
|
127
|
+
`inputmode="decimal"` for formatted decimal fields.
|
|
128
|
+
|
|
129
|
+
`prefix` and `suffix` are fixed display text. Typing inside the prefix inserts at
|
|
130
|
+
the start of the number; typing inside the suffix inserts at the end:
|
|
80
131
|
|
|
81
132
|
```ts
|
|
82
133
|
bindDecimal(input, { prefix: '$', decimalPlaces: 2 })
|
|
@@ -88,16 +139,19 @@ Their text is never read back as part of the number either, so an affix carrying
|
|
|
88
139
|
|
|
89
140
|
```ts
|
|
90
141
|
bindDecimal(input, { prefix: 'Q1 ', decimalPlaces: 2 })
|
|
91
|
-
// typing 1234 → "Q1 1,234.00"
|
|
142
|
+
// typing 1234 → "Q1 1,234.00"
|
|
143
|
+
// unmaskDecimal('Q1 1,234.00', { prefix: 'Q1 ' }) → 1234
|
|
92
144
|
```
|
|
93
145
|
|
|
94
146
|
## Pattern Syntax
|
|
95
147
|
|
|
96
148
|
| Character | Matches |
|
|
97
149
|
| --- | --- |
|
|
98
|
-
| `9` |
|
|
99
|
-
| `Z` |
|
|
100
|
-
| `A` |
|
|
150
|
+
| `9` | ASCII digit (`0`–`9`) |
|
|
151
|
+
| `Z` | ASCII letter |
|
|
152
|
+
| `A` | ASCII letter or digit |
|
|
153
|
+
| Custom token | Matches its local definition (see below) |
|
|
154
|
+
| `\` | Escapes a token or another backslash (see [escaping](#escaped-literals)) |
|
|
101
155
|
| Anything else | Literal separator |
|
|
102
156
|
|
|
103
157
|
Examples:
|
|
@@ -108,6 +162,108 @@ bind(input, '99/99/9999')
|
|
|
108
162
|
bind(input, 'AA.AAA.AAA/AAAA-99')
|
|
109
163
|
```
|
|
110
164
|
|
|
165
|
+
## Custom Tokens and Transforms
|
|
166
|
+
|
|
167
|
+
Tokens are local to an operation or binding. A definition is a `RegExp`, a
|
|
168
|
+
`(char: string) => boolean` matcher, or `{ match, transform? }`:
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
bind(input, 'HH-HH', { tokens: { H: /[0-9A-Fa-f]/ } })
|
|
172
|
+
// "a1b2" → "a1-b2"; "g" is rejected
|
|
173
|
+
|
|
174
|
+
bind(input, 'UUU-999', {
|
|
175
|
+
tokens: {
|
|
176
|
+
U: { match: /[a-z]/i, transform: char => char.toUpperCase() },
|
|
177
|
+
},
|
|
178
|
+
})
|
|
179
|
+
// "abc123" → "ABC-123"
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Keys are single Unicode code points; `\` is reserved. Custom definitions may
|
|
183
|
+
override `9`, `Z`, or `A` for that binding only. Definitions are snapshotted on
|
|
184
|
+
bind; dispose and rebind to change them. Matchers should be pure. RegExp `g`/`y`
|
|
185
|
+
flags are ignored on a private copy; the caller's `lastIndex` is never changed.
|
|
186
|
+
|
|
187
|
+
A transform **must return exactly one Unicode code point**, otherwise a
|
|
188
|
+
`RangeError` is thrown (for example, uppercasing `ß` to `SS` is not supported).
|
|
189
|
+
Use an idempotent transform whose output still matches the token. UTF-16 width
|
|
190
|
+
may change: the caret follows the source character, not the output's case or width.
|
|
191
|
+
|
|
192
|
+
Custom tokens work with ordered arrays, segmented editing, eager literals,
|
|
193
|
+
and all four APIs: `applyMask`, `process`, `buildMask`, and `bind`.
|
|
194
|
+
|
|
195
|
+
Use token transforms to normalize case while preserving the caret, rather than
|
|
196
|
+
rewriting `input.value` inside an `onChange` callback.
|
|
197
|
+
|
|
198
|
+
## Content-dependent Masks
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
bind(input, '9999 9999 9999 9999', {
|
|
202
|
+
resolveMask(value) {
|
|
203
|
+
return value.startsWith('34') || value.startsWith('37')
|
|
204
|
+
? '9999 999999 99999'
|
|
205
|
+
: '9999 9999 9999 9999'
|
|
206
|
+
},
|
|
207
|
+
})
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
`resolveMask` is called **once per masking application**, before transforms,
|
|
211
|
+
with candidate data: code points accepted by the slots of the supplied fallback
|
|
212
|
+
pattern (or any fallback array member). Complete fallback literal runs at their
|
|
213
|
+
slot boundaries (escaped runs also after a segment shrinks) and nonmatching characters are removed. Thus raw and formatted
|
|
214
|
+
card numbers give the same digit stream, and invalid letters cannot change the
|
|
215
|
+
prefix. Make the fallback alphabet cover every format your resolver can return.
|
|
216
|
+
The callback can return a string or an ordered array; arrays retain capacity-based
|
|
217
|
+
selection. No recursive resolution or caching of input values occurs.
|
|
218
|
+
|
|
219
|
+
Resolver masks describe **one continuous identifier**: old separators are removed
|
|
220
|
+
before rendering the selected layout, even with `segmented: true`. This prevents
|
|
221
|
+
stale boundaries when equal-capacity layouts switch. For independently editable
|
|
222
|
+
fields, use a static pattern/array and segmented mode instead. Eager mode still
|
|
223
|
+
applies; the caret tracks logical characters and already-crossed literal boundaries.
|
|
224
|
+
|
|
225
|
+
`bind` does not add `maxlength` for resolvers (the maximum is unknowable) or
|
|
226
|
+
custom tokens (IME drafts can exceed the final capacity). The engine still caps
|
|
227
|
+
slots. Author-supplied `maxlength` is preserved. Disposal removes attributes added
|
|
228
|
+
by the binding, so rebinding cannot inherit a library-created stale limit.
|
|
229
|
+
|
|
230
|
+
## Escaped Literals
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
bind(input, '\\A-999999') // "123456" → "A-123456"
|
|
234
|
+
bind(input, '\\9-99') // "12" → "9-12"
|
|
235
|
+
bind(input, '\\Z-99') // "12" → "Z-12"
|
|
236
|
+
bind(input, '\\\\99') // a literal backslash, then two digits
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
In the pattern, backslash escapes a built-in/custom token or another backslash.
|
|
240
|
+
Before any other character it remains literal; a trailing backslash also remains
|
|
241
|
+
literal. Existing masks that used a backslash immediately before a token or
|
|
242
|
+
backslash must double it to keep that backslash in the output.
|
|
243
|
+
|
|
244
|
+
Complete literal runs are treated as formatting at their boundary; escaped runs
|
|
245
|
+
remain formatting after a segment shrinks, rather than becoming slot data. If literal text also matches the data alphabet, raw
|
|
246
|
+
and already-formatted input can be ambiguous: use a distinct separator (such as
|
|
247
|
+
`'\\9-99'`) to distinguish the literal from user data. Resolver formats should
|
|
248
|
+
likewise avoid introducing data-looking literals absent from the fallback pattern.
|
|
249
|
+
|
|
250
|
+
## Unicode and Composition
|
|
251
|
+
|
|
252
|
+
```ts
|
|
253
|
+
bind(input, 'LLLL', { tokens: { L: /\p{L}/u } })
|
|
254
|
+
// accepts Á, Ç, É, ñ, ü, ø, Ж, λ, and supplementary letters such as 𐐀
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Matching is by **Unicode code point**, not UTF-16 code unit or grapheme cluster.
|
|
258
|
+
Combining marks and joined emoji sequences therefore occupy separate slots if
|
|
259
|
+
accepted; no normalization or grapheme segmentation is performed. Caret offsets
|
|
260
|
+
remain DOM-compatible UTF-16 positions. Built-in `Z` and `A` remain ASCII-only.
|
|
261
|
+
|
|
262
|
+
With custom tokens, provisional IME text and selection are left untouched until
|
|
263
|
+
composition commits. This includes custom ASCII matchers: an arbitrary predicate's
|
|
264
|
+
alphabet cannot be safely inferred. Built-in-only masks keep live formatting during
|
|
265
|
+
Android autocorrect composition. No timeout or delayed commit is used.
|
|
266
|
+
|
|
111
267
|
## Segmented Editing
|
|
112
268
|
|
|
113
269
|
Masks are segmented by default. Separators behave like boundaries, which keeps fields such as dates from bleeding into each other while editing:
|
|
@@ -116,6 +272,16 @@ Masks are segmented by default. Separators behave like boundaries, which keeps f
|
|
|
116
272
|
bind(input, '99/99/9999')
|
|
117
273
|
```
|
|
118
274
|
|
|
275
|
+
Deleting all the data in an internal segment preserves its existing dividers
|
|
276
|
+
while later segments still contain data. For example, three Backspaces over
|
|
277
|
+
`222` in `(111) 222-3333` leave `(111) |-3333` (`|` marks the caret), ready to
|
|
278
|
+
type a replacement. This also works with `eager: false`. Trailing separators
|
|
279
|
+
still follow eager mode, and selecting everything and deleting clears the input.
|
|
280
|
+
|
|
281
|
+
If another Backspace removes part of a divider, the caret follows any collapsed
|
|
282
|
+
text to the left: `(111|-3333`, never `(111-|3333`. Backward word/line deletion
|
|
283
|
+
uses the same caret rule; movement through a divider that stays visible is preserved.
|
|
284
|
+
|
|
119
285
|
Separators left in the value also anchor the characters around them, so an edit that replaces whole fields leaves the rest where it was:
|
|
120
286
|
|
|
121
287
|
```ts
|
|
@@ -124,7 +290,7 @@ bind(input, '999.999.999-99')
|
|
|
124
290
|
// → "015.|-39" the "-" keeps "39" in the last field
|
|
125
291
|
```
|
|
126
292
|
|
|
127
|
-
Anchoring is only as precise as the separators allow. A mask whose separators are all the same character can produce
|
|
293
|
+
Anchoring is only as precise as the separators allow. A mask whose separators are all the same character can produce an ambiguous value — with `'99/99/9999'`, `"1/2025"` reads equally well as `1 / 20 / 25` — and resolves it to the earliest field that fits. Masks with distinct separators (CPF, CNPJ, phone numbers) have no such gap.
|
|
128
294
|
|
|
129
295
|
For classic reflow behavior, pass `segmented: false`:
|
|
130
296
|
|
|
@@ -132,6 +298,51 @@ For classic reflow behavior, pass `segmented: false`:
|
|
|
132
298
|
bind(input, '999.999.999-99', { segmented: false })
|
|
133
299
|
```
|
|
134
300
|
|
|
301
|
+
## Eager Mode
|
|
302
|
+
|
|
303
|
+
On by default: the next literal separator is revealed as soon as the segment before it is completely filled, instead of waiting for the first character of the next segment:
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
bind(input, '99/99/9999')
|
|
307
|
+
// typing "25" shows "25/" right away
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Pass `eager: false` to wait for the next real character instead:
|
|
311
|
+
|
|
312
|
+
```ts
|
|
313
|
+
bind(input, '99/99/9999', { eager: false })
|
|
314
|
+
// typing "25" shows "25" until the next digit arrives
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
`bind` does not reinsert an eager separator immediately after Backspace/Delete
|
|
318
|
+
removes it: deleting the `"."` off `"012."` leaves `"012"`. This is binding behavior;
|
|
319
|
+
the pure helpers have no edit history and apply the configured `eager` option on
|
|
320
|
+
every call. Arrow keys, Home/End, and selection shortcuts retain native behavior.
|
|
321
|
+
|
|
322
|
+
## Formatting Without an Input
|
|
323
|
+
|
|
324
|
+
The pure helpers return strings or a formatted value with a caret position:
|
|
325
|
+
|
|
326
|
+
```ts
|
|
327
|
+
import { applyMask, process, processDecimal, formatDecimalValue, unmaskDecimal } from 'mother-mask'
|
|
328
|
+
|
|
329
|
+
process('12345678901', '999.999.999-99') // '123.456.789-01'
|
|
330
|
+
applyMask('25122025', '99/99/9999', 8) // { value: '25/12/2025', caret: 10 }
|
|
331
|
+
|
|
332
|
+
processDecimal('1234.567') // '1,234.567' — optional, unlimited fraction
|
|
333
|
+
processDecimal('1234.5', { decimalPlaces: 2, prefix: '$' }) // '$1,234.50'
|
|
334
|
+
processDecimal('7.3', { numberPlaces: 2, decimalPlaces: 2 }) // '07.30'
|
|
335
|
+
|
|
336
|
+
const euro = { decimalPlaces: 2, separator: '.', decimalSeparator: ',', suffix: ' €' }
|
|
337
|
+
formatDecimalValue(1234.5, euro) // '1.234,50 €'
|
|
338
|
+
unmaskDecimal('1.234,50 €', euro) // 1234.5
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
Pass the same locale and affix options when formatting and parsing.
|
|
342
|
+
`formatDecimalValue` accepts a JS number; the other decimal helpers accept strings
|
|
343
|
+
in the configured format. `unmaskDecimal` returns `0` for empty or digitless input.
|
|
344
|
+
All caret arguments and results are UTF-16 offsets, matching DOM selections.
|
|
345
|
+
|
|
135
346
|
## CDN
|
|
136
347
|
|
|
137
348
|
```html
|
|
@@ -145,29 +356,50 @@ The global name is `MotherMask`.
|
|
|
145
356
|
|
|
146
357
|
## API
|
|
147
358
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
359
|
+
| Export | Returns / purpose |
|
|
360
|
+
| --- | --- |
|
|
361
|
+
| `bind(input, mask, options?)` | Disposer; bind a static pattern, ordered array, or resolver via options |
|
|
362
|
+
| `bindDecimal(input, options?)` | Disposer; bind a decimal input |
|
|
363
|
+
| `applyMask(value, mask, inputCaret?, options?)` | `MaskResult`: `{ value, caret }` |
|
|
364
|
+
| `process(value, mask, options?)` | Formatted string |
|
|
365
|
+
| `buildMask(value, mask, caret?, options?)` | `Mask` instance; call `.process()` and read `.caret` afterward |
|
|
366
|
+
| `new Mask(value, mask, caret?, options?)` | Low-level processor with the same options |
|
|
367
|
+
| `getMaxLength(mask, options?)` | Formatted UTF-16 upper bound; `Infinity` with a resolver |
|
|
368
|
+
| `applyDecimalMask(value, inputCaret?, options?)` | `MaskResult`: `{ value, caret }` |
|
|
369
|
+
| `processDecimal(value, options?)` | Formatted decimal string |
|
|
370
|
+
| `unmaskDecimal(value, options?)` | Parsed JS number |
|
|
371
|
+
| `formatDecimalValue(value, options?)` | Display string from a JS number |
|
|
372
|
+
|
|
373
|
+
Pattern options (`ApplyMaskOptions`) are `segmented` (default `true`), `eager`
|
|
374
|
+
(default `true`), `tokens`, and `resolveMask`. `BindOptions` adds `onChange`.
|
|
375
|
+
`bind` also accepts a `(value) => void` callback as its third argument;
|
|
376
|
+
`bindDecimal` accepts `(value, numericValue) => void` as its second argument.
|
|
377
|
+
|
|
378
|
+
Optional caret arguments default to `0`. `getMaxLength` counts literals and
|
|
379
|
+
reserves up to two UTF-16 units per custom-token slot; it is not a count of data
|
|
380
|
+
characters. See [dynamic masks](#content-dependent-masks) for `maxlength` handling.
|
|
161
381
|
|
|
162
382
|
Exported types:
|
|
163
383
|
|
|
164
384
|
- `MaskPattern`
|
|
385
|
+
- `TokenMatcher`
|
|
386
|
+
- `MaskTokenDefinition`
|
|
387
|
+
- `MaskTokens`
|
|
388
|
+
- `MaskResolver`
|
|
165
389
|
- `MaskResult`
|
|
166
390
|
- `ApplyMaskOptions`
|
|
167
391
|
- `BindOptions`
|
|
168
392
|
- `DecimalMaskOptions`
|
|
169
393
|
- `BindDecimalOptions`
|
|
170
394
|
|
|
395
|
+
## Development
|
|
396
|
+
|
|
397
|
+
See the [repository guide](https://github.com/dan2dev/mother-mask/blob/main/REPOSITORY.md)
|
|
398
|
+
for builds, tests, and release commands, and the
|
|
399
|
+
[docs guide](https://github.com/dan2dev/mother-mask/blob/main/docs/README.md) for
|
|
400
|
+
running the documentation website. Keep this README and the published package
|
|
401
|
+
README in sync.
|
|
402
|
+
|
|
171
403
|
## License
|
|
172
404
|
|
|
173
405
|
MIT - [Danilo Celestino de Castro](https://github.com/dan2dev)
|
package/dist/mother-mask.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return e>=`0`&&e<=`9`}function t(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function n(e){return e===`9`||e===`Z`||e===`A`}function r(n,r){return r===`9`?e(n):r===`Z`?t(n):e(n)||t(n)}function i(e,t,n,i){let a=``,o=``,s=0,c=0,l=!1;for(let i=0;i<t.length;i++){let u=t[i];if(u!==`9`&&u!==`Z`&&u!==`A`){o+=u;continue}let d=!1;for(;s<e.length;){let t=e[s++];if(r(t,u)){a+=o+t,o=``,d=!0,l||(s<=n?c=a.length:l=!0);break}}if(!d)break}if(l||(c=a.length),i&&o){let e=c===a.length;a+=o,e&&(c=a.length)}return{value:a,caret:c}}const a=new Map;function o(e,t){if(a.size>=64){let e=a.keys().next();e.done||a.delete(e.value)}a.set(e,t)}function s(e){let t=a.get(e);if(t)return t;let r=[],i=[],s=[],c=[],l=0;for(;l<e.length;){let t=l,a=n(e[l]);for(;l<e.length&&n(e[l])===a;)l++;let o=e.slice(t,l);a?(i.push(s.length),c.push(r.length),s.push(o),r.push({kind:`slots`,chars:o})):(i.push(-1),r.push({kind:`literal`,text:o}))}let u=s.length,d=Array(u),f=Array(u),p=Array(u+1),m=Array(r.length).fill(-1),h=Array(r.length).fill(-1),g=0;for(let e=0;e<u;e++)d[e]=g,g+=s[e].length,f[e]=c[e]>0?c[e]-1:-1;p[u]=0;for(let e=u-1;e>=0;e--)p[e]=p[e+1]+s[e].length;for(let e=0;e<r.length;e++)r[e].kind===`literal`&&(m[e]=e>0?i[e-1]:-1,h[e]=e+1<r.length?i[e+1]:-1);let _={tokens:r,runChars:s,runOffset:d,literalBeforeRun:f,capacityFromRun:p,runOfToken:i,runBeforeLiteral:m,runAfterLiteral:h,totalSlots:g};return o(e,_),_}function c(e,t){return e.tokens[e.literalBeforeRun[t]].text}function l(n,r){let i=0;for(let a=r;a<n.length;a++){let r=n[a];(e(r)||t(r))&&i++}return i}function u(e,t,n,r){let i=l(e,t);for(let a=r+1;a<n.runChars.length;a++)if(e.startsWith(c(n,a),t))return i<=n.capacityFromRun[a]?a:-1;return-1}function d(e,t){let n=t.runChars.length,i=Array(t.totalSlots).fill(``),a=Array(t.totalSlots).fill(-1),o=Array(n).fill(0),s=Array(t.tokens.length).fill(-1),l=0,d=0,f=0;for(;f<e.length&&l<n;){let p=t.runChars[l],m=e[f];if(r(m,p[d])){let r=t.runOffset[l]+d;if(i[r]=m,a[r]=f,o[l]=d+1,f++,d++,d===p.length&&(l++,d=0,l<n)){let n=c(t,l);e.startsWith(n,f)&&(s[t.literalBeforeRun[l]]=f,f+=n.length)}continue}let h=u(e,f,t,l);if(h>=0){s[t.literalBeforeRun[h]]=f,f+=c(t,h).length,l=h,d=0;continue}f++}return{slotChar:i,slotSource:a,runFilled:o,literalSource:s}}function f(e,t,n){let{tokens:r,runBeforeLiteral:i,runAfterLiteral:a,literalBeforeRun:o,runChars:s}=e,{runFilled:c}=t,l=Array(r.length).fill(!1);for(let e=0;e<r.length;e++){if(r[e].kind!==`literal`)continue;let t=a[e],o=i[e];l[e]=t>=0&&c[t]>0||n&&(o<0||c[o]===s[o].length)}let u=-1;for(let e=0;e<s.length;e++){if(c[e]===0)continue;let t=o[e];if(t>=0){let n=r[t].text;for(let t=u+1;t<e;t++){let e=o[t];e<0||r[e].text===n&&(l[e]=!0)}}u=e}return l}function p(e,t,n,r,i){let{tokens:a,runChars:o,runOffset:s,runBeforeLiteral:c,runAfterLiteral:l,runOfToken:u}=e,{slotChar:d,slotSource:f,runFilled:p}=t,m=``,h=0,g=!1;for(let e=0;e<a.length;e++){let _=a[e];if(_.kind===`literal`){if(!n[e])continue;let a=c[e],s=l[e],u=s<0||p[s]===0,d=i&&(a<0||p[a]===o[a].length),f=t.literalSource[e],v=!g&&h===m.length;m+=_.text,v&&(d&&u||f>=0&&f<r)&&(h=m.length);continue}let v=u[e],y=s[v];for(let e=0;e<p[v];e++)m+=d[y+e],!g&&(f[y+e]<r?h=m.length:g=!0)}return{value:m,caret:h}}function m(e,t,n,r){let i=s(t),a=d(e,i);return p(i,a,f(i,a,r),n,r)}function h(e,t,n=0,r){if(!e)return{value:``,caret:0};let a=r?.eager!==!1;return r?.segmented===!1?i(e,t,n,a):m(e,t,n,a)}function g(e){let t=0;for(let n of e)(n>=`0`&&n<=`9`||n>=`a`&&n<=`z`||n>=`A`&&n<=`Z`)&&t++;return t}function _(e){let t=0;for(let n of e)(n===`9`||n===`Z`||n===`A`)&&t++;return t}function v(e,t){if(!Array.isArray(t))return t;let n=g(e),r=0;for(;r<t.length-1&&n>_(t[r]);)r++;return t[r]}function y(e){return Array.isArray(e)?e.length>0?Math.max(...e.map(e=>e.length)):0:e.length}var b=class{caret;_value;_mask;_options;constructor(e,t,n=0,r){this._value=e,this._mask=t,this.caret=n,this._options=r}process(){let e=h(this._value,this._mask,this.caret,this._options);return this.caret=e.caret,e.value}};function x(e,t,n=0,r){return new b(e,v(e,t),n,r)}function S(e,t,n){return x(e,t,0,n).process()}let C;function w(){return C===void 0&&(C=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),C}const T=`data-masked`;function E(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function D(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function O(e,t){try{e.setSelectionRange(t,t)}catch{}}function k(e){return e===`deleteContentBackward`?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function A(e,t){return!t&&e}function j(e,t,n){if(e.getAttribute(T)!==null)return()=>{};let{onChange:r,segmented:i,eager:a}=E(n),o=[],s=(t,n)=>{e.hasAttribute(t)||(e.setAttribute(t,n),o.push(t))},c=y(t);e.setAttribute(T,Array.isArray(t)?t.join(`|`):t),s(`autocomplete`,`off`),s(`autocorrect`,`off`),s(`autocapitalize`,`off`),s(`spellcheck`,`false`),s(`maxlength`,String(c));let l=!1,u=!1,d=!1,f=e.value??``,p=w()?`keyup`:`keydown`,m=new Set,h=e=>{let t=requestAnimationFrame(()=>{m.delete(t),e()});m.add(t)},g=()=>{for(let e of m)cancelAnimationFrame(e);m.clear()},_=e=>{let n=e.target;h(()=>{let e=x(n.value,t,0,{segmented:i,eager:a});n.value=e.process(),r?.(n.value)})},v=e=>{let n=e,o=e.target;g(),l=!1,d=!0;let s=D(o),c=f.length,u=k(n.inputType),p=x(o.value,t,s,{segmented:i,eager:A(a,u===`backspace`||u===`delete`)});o.value=p.process(),u===`unidentified`?O(o,o.value.length>c?p.caret:s):u===`delete`?O(o,c===o.value.length?s+1:s):u===`backspace`?O(o,s):O(o,p.caret),f=o.value,r?.(o.value)},b=()=>{u=!0,g(),l=!1},S=e=>{u=!1,d=!0;let n=e.target,o=D(n),s=x(n.value,t,o,{segmented:i,eager:a});n.value=s.process(),O(n,s.caret),f=n.value,r?.(n.value)},C=e=>{let n=e,o=n.target,s=o.value;if(u)return;if(p===`keyup`&&d){d=!1;return}if(!n.key){l=!0,h(()=>{if(o.value===s&&o.selectionStart!==o.selectionEnd){l=!1;return}let e=o.selectionStart??999,n=o.value.length<s.length,r=x(o.value,t,e,{segmented:i,eager:A(a,n)});o.value=r.process(),o.setSelectionRange(r.caret,r.caret),h(()=>{l=!1})});return}if(n.key===`Meta`)return;let f=n.key===`Backspace`,m=n.key===`Delete`,g=n.key.length===1&&!n.ctrlKey&&!n.altKey&&!n.metaKey,_=n.key===`Unidentified`;if(g&&o.selectionStart===o.selectionEnd&&s.length>=c&&!w()){n.preventDefault();return}if(l){n.preventDefault();return}!f&&!m&&!g&&!_||h(()=>{if(o.value===s&&o.selectionStart!==o.selectionEnd)return;let e=o.selectionStart??999,n=x(o.value,t,e,{segmented:i,eager:A(a,f||m)});if(o.value=n.process(),_){let t=o.value.length>s.length?n.caret:e;o.setSelectionRange(t,t)}else if(m){let t=s.length===o.value.length?e+1:e;o.setSelectionRange(t,t)}else f?o.setSelectionRange(e,e):g&&o.setSelectionRange(n.caret,n.caret);r?.(o.value)})};return e.addEventListener(`paste`,_),e.addEventListener(`input`,v),e.addEventListener(`compositionstart`,b),e.addEventListener(`compositionend`,S),e.addEventListener(p,C),()=>{e.removeEventListener(`paste`,_),e.removeEventListener(`input`,v),e.removeEventListener(`compositionstart`,b),e.removeEventListener(`compositionend`,S),e.removeEventListener(p,C),e.removeAttribute(T);for(let t of o)e.removeAttribute(t);g()}}function M(e){return e>=`0`&&e<=`9`}function N(e){let t=e?.decimalPlaces,n=t!=null&&Number.isFinite(t)?Math.max(0,Math.floor(t)):void 0,r=e?.numberPlaces;return{decimalPlaces:n,numberPlaces:r!=null&&Number.isFinite(r)?Math.max(1,Math.floor(r)):void 0,segmented:e?.segmented??!0,separator:e?.separator??`,`,decimalSeparator:e?.decimalSeparator??`.`,prefix:e?.prefix??``,suffix:e?.suffix??``,allowNegative:e?.allowNegative??!1}}function P(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function F(e,t){if(!t||e.length<=3)return e;let n=[],r=e.length;for(;r>3;)n.unshift(e.slice(r-3,r)),r-=3;return n.unshift(e.slice(0,r)),n.join(t)}function I(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(M(e[r])&&(n++,n===t))return r+1;return e.length}function L(e,t){let n=0,r=``;t.prefix&&e.startsWith(t.prefix)?n=t.prefix.length:(t.allowNegative&&e[0]===`-`&&(r=`-`,n=1),t.prefix&&e.startsWith(t.prefix,n)&&(n+=t.prefix.length));let i=e.length;return t.suffix&&e.endsWith(t.suffix)&&i-t.suffix.length>=n&&(i-=t.suffix.length),{sign:r,body:e.slice(n,i),bodyStart:n}}function R(e,t){let n=L(e,t),r=``,i=``,a=n.sign===`-`,o=!1,s=t.decimalPlaces!==0;for(let e of n.body){if(M(e)){o?(t.decimalPlaces==null||i.length<t.decimalPlaces)&&(i+=e):(t.numberPlaces==null||r.length<t.numberPlaces)&&(r+=e);continue}if(s&&!o&&e===t.decimalSeparator){o=!0;continue}e===`-`&&t.allowNegative&&(a=!0)}return{isNegative:a,intDigits:r,fracDigits:i,hasSeparator:o}}function z(e,t,n){let r=n.decimalPlaces!==0,i=!1,a=0;for(let o=0;o<t;o++){let t=e[o];if(M(t)){i?(n.decimalPlaces==null||a<n.decimalPlaces)&&a++:(n.numberPlaces==null||a<n.numberPlaces)&&a++;continue}r&&!i&&t===n.decimalSeparator&&(i=!0,a=0)}return{inFraction:i,digitsBefore:a}}function B(e,t=0,n){let r=N(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=R(e,r);if(a===``&&o===``&&!s)return{value:``,caret:0};let c=P(a||`0`),l=r.numberPlaces==null?c:c.padStart(r.numberPlaces,`0`),u=r.segmented?F(l,r.separator):l,d=r.decimalPlaces!=null&&r.decimalPlaces>0?o.padEnd(r.decimalPlaces,`0`):o,f=u+(r.decimalPlaces!==0&&(r.decimalPlaces!=null||s)?r.decimalSeparator+d:``),p=i?`-`:``,m=p+r.prefix+f+r.suffix,h=L(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=z(h.body,g,r),y=p.length+r.prefix.length,b=l.length-c.length;return{value:m,caret:_?y+u.length+r.decimalSeparator.length+v:y+I(u,v+b)}}function V(e,t){return B(e,e.length,t).value}function H(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=R(e,N(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n?-a:a}function U(e,t){let n=N(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=R(e,n);if(a||i.length<n.decimalPlaces+1)return null;let o=i.length-n.decimalPlaces,s=i.slice(o),c=i.slice(0,o-1),l=r?`-`:``;return B(l+c+n.decimalSeparator+s,l.length+c.length,n)}function W(e,t,n,r){if(n<=0)return null;let i=t-n;if(i<0||t>e.length)return null;let a=e.slice(0,i)+e.slice(t),{bodyStart:o,body:s}=L(a,N(r)),c=o+s.length,l=i<o?o:i>c?c:-1;if(l<0)return null;let u=e.slice(i,t);return{value:a.slice(0,l)+u+a.slice(l),caret:l+n}}function G(e,t,n,r){let i=N(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=R(e.slice(0,a)+e.slice(t),i),u=P(s||`0`),d=u!==`0`,f=d&&i.numberPlaces!=null&&u.length<i.numberPlaces;if(d&&!f)return null;let p=+!!o+i.prefix.length;if(a<p||a>p+s.length)return null;let m=o?`-`:``,h=(d?u:``)+n;return B(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function K(e,t){let n=N(t);if(!Number.isFinite(e))return``;let r=n.allowNegative&&e<0,i=Math.abs(e),a=n.decimalPlaces==null?String(i):i.toFixed(n.decimalPlaces),o=a.indexOf(`.`),s=o===-1?a:a.slice(0,o),c=o===-1?``:a.slice(o+1),l=P(s||`0`),u=n.numberPlaces==null?l:l.padStart(n.numberPlaces,`0`),d=(n.segmented?F(u,n.separator):u)+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+d+n.suffix}const q=`data-masked`;function J(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function Y(e){return e.length===1&&e>=`0`&&e<=`9`}function X(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function Z(e,t){try{e.setSelectionRange(t,t)}catch{}}function Q(e,t){if(e.getAttribute(q)!==null)return()=>{};let{onChange:n,...r}=J(t),i=r,{decimalSeparator:a,decimalPlaces:o}=N(i),s=[],c=(t,n)=>{e.hasAttribute(t)||(e.setAttribute(t,n),s.push(t))};e.setAttribute(q,`decimal`),c(`autocomplete`,`off`),c(`autocorrect`,`off`),c(`autocapitalize`,`off`),c(`spellcheck`,`false`);let l=!1,u=!1,d=!1,f=null,p=w()?`keyup`:`keydown`,m=new Set,h=e=>{let t=requestAnimationFrame(()=>{m.delete(t),e()});m.add(t)},g=()=>{for(let e of m)cancelAnimationFrame(e);m.clear()},_=(e,t)=>{e.value=t.value,Z(e,t.caret),n?.(t.value,H(t.value,i))},v=(e,t={})=>{let n=X(e),r=(t,r)=>{if(o===0||t.length!==1||t!==`.`&&t!==`,`||t===a)return!1;for(let i of r)if(i!=null&&i>=0&&e.value.slice(i,i+t.length)===t)return e.value=e.value.slice(0,i)+a+e.value.slice(i+t.length),n=i+t.length<=n?n+a.length-t.length:n,Z(e,n),!0;return!1};if(f){let{text:e,starts:t}=f;f=null,r(e,t)}if(t.inputType===`deleteContentBackward`){let t=U(e.value,i);if(t){_(e,t);return}}let s=t.insertedText;if(s!=null&&r(s,[t.insertedAt,n-s.length]),s!=null&&s.length>0){let t=W(e.value,n,s.length,i);t&&(e.value=t.value,n=t.caret)}let c=s!=null&&s.length===1&&Y(s)?s:void 0,l=c?G(e.value,n,c,i):null;_(e,l??B(e.value,n,i))},y=e=>{let t=e.target;h(()=>{v(t)})},b=e=>{let t=e,n=e.target;g(),l=!1,f=null,d=!0,v(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},x=()=>{u=!0,g(),l=!1,f=null},S=e=>{u=!1,d=!0,v(e.target)},C=e=>{let t=e,n=t.target,r=X(n),i=n.value;if(u)return;if(p===`keyup`&&d){d=!1;return}if(!t.key){l=!0,h(()=>{if(n.value===i&&n.selectionStart!==n.selectionEnd){l=!1;return}v(n),h(()=>{l=!1})});return}if(t.key===`Meta`)return;if(l){t.preventDefault();return}let s=t.key===`Backspace`,c=t.key===`Delete`,m=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,g=t.key===`Unidentified`;m&&o!==0&&(t.key===`.`||t.key===`,`)&&t.key!==a&&(f={text:t.key,starts:[r,r-t.key.length]}),!(!s&&!c&&!m&&!g)&&h(()=>{(n.value!==i||n.selectionStart===n.selectionEnd)&&v(n,{insertedText:m?t.key:null,insertedAt:m?r:void 0,inputType:s?`deleteContentBackward`:c?`deleteContentForward`:void 0})})};return e.addEventListener(`paste`,y),e.addEventListener(`input`,b),e.addEventListener(`compositionstart`,x),e.addEventListener(`compositionend`,S),e.addEventListener(p,C),()=>{e.removeEventListener(`paste`,y),e.removeEventListener(`input`,b),e.removeEventListener(`compositionstart`,x),e.removeEventListener(`compositionend`,S),e.removeEventListener(p,C),e.removeAttribute(q);for(let t of s)e.removeAttribute(t);g()}}exports.Mask=b,exports.applyDecimalMask=B,exports.applyMask=h,exports.bind=j,exports.bindDecimal=Q,exports.buildMask=x,exports.formatDecimalValue=K,exports.getMaxLength=y,exports.process=S,exports.processDecimal=V,exports.unmaskDecimal=H;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return e>=`0`&&e<=`9`}function t(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function n(n){return e(n)||t(n)}const r=[[`9`,{match:e,maxLength:1}],[`Z`,{match:t,maxLength:1}],[`A`,{match:n,maxLength:1}]];function i(e){if(typeof e==`function`)return e;let t=new RegExp(e.source,e.flags.replace(/[gy]/g,``));return e=>t.test(e)}function a(e,t){if(!t.transform)return e;let n=t.transform(e);if(typeof n!=`string`||Array.from(n).length!==1)throw RangeError(`A mask token transform must return exactly one Unicode code point`);return n}function o(e,t){let n=[],r=[],i=[],a=[],o=Array.from(e),s=0,c=!1;for(let e=0;e<o.length;e++){let l=o[e],u=!1;l===`\\`&&(o[e+1]===`\\`||t.has(o[e+1]))&&(l=o[++e],u=!0,c=!0);let d=u?void 0:t.get(l),f=n[n.length-1];if(d){if(s+=d.maxLength,f?.kind===`slots`)f.chars.push(d);else{let e=[d];r.push(i.length),a.push(n.length),i.push(e),n.push({kind:`slots`,chars:e})}}else s+=l.length,f?.kind===`literal`?f.text+=l:(r.push(-1),n.push({kind:`literal`,text:l}))}let l=i.length,u=Array(l),d=Array(l),f=Array(l+1),p=Array(n.length).fill(-1),m=Array(n.length).fill(-1),h=0;for(let e=0;e<l;e++)u[e]=h,h+=i[e].length,d[e]=a[e]>0?a[e]-1:-1;f[l]=0;for(let e=l-1;e>=0;e--)f[e]=f[e+1]+i[e].length;for(let e=0;e<n.length;e++)n[e].kind===`literal`&&(p[e]=e>0?r[e-1]:-1,m[e]=e+1<n.length?r[e+1]:-1);let g=[],_=[],v=new Set;for(let e=0;e<n.length;e++){let t=n[e];if(t.kind===`literal`)g.push(t),_.push({text:t.text,offset:m[e]<0?h:u[m[e]]});else for(let e of t.chars)g.push(e),v.add(e)}return{maxLength:s,hasEscapes:c,dataSlots:[...v],literals:_,parts:g,tokens:n,runChars:i,runOffset:u,literalBeforeRun:d,capacityFromRun:f,runOfToken:r,runBeforeLiteral:p,runAfterLiteral:m,totalSlots:h}}var s=class{definitions=new Map(r);cache=new Map;custom;constructor(e){this.custom=!!e&&Object.keys(e).length>0;for(let t of Object.keys(e??{})){let n=e[t];if(t===`\\`||Array.from(t).length!==1)throw RangeError(`Mask token keys must be one Unicode code point other than backslash`);let r=typeof n==`object`&&`match`in n?n:{match:n};this.definitions.set(t,{match:i(r.match),transform:r.transform,maxLength:2})}}compile(e){let t=this.cache.get(e);if(t)return t;let n=o(e,this.definitions);return this.cache.size===64&&this.cache.delete(this.cache.keys().next().value),this.cache.set(e,n),n}isData(e,t){if(t&&(this.custom||t.hasEscapes))return t.dataSlots.some(t=>t.match(e));for(let t of this.definitions.values())if(t.match(e))return!0;return!1}data(e,t,n,r=!0){let i=``,a=0,o=0,s=0,c=-1,l=!1,u,d=[];if(n){let e=new Set;for(let t of n){for(let n of t.dataSlots)e.add(n);if(r)for(let e of t.literals)d.push(e)}u=[...e]}let f=n?.some(e=>e.hasEscapes);for(;a<e.length;){let n=c!==s&&d?.find(t=>(t.offset===s||f)&&e.startsWith(t.text,a));if(n){a<t&&(l=!0),a+=n.text.length,c=s;continue}let r=String.fromCodePoint(e.codePointAt(a)),p=a;if(a+=r.length,!(u?u.some(e=>e.match(r)):this.isData(r))){p<t&&d?.some(t=>e.startsWith(t.text,p))&&(l=!0);continue}i+=r,s++,a<=t&&(o=i.length,l=!1)}return{value:i,caret:o,afterLiteral:l}}resolve(e,t,n=!0){if(!Array.isArray(t))return this.compile(t);let r=t.map(e=>this.compile(e)),i=Array.from(this.data(e,0,this.custom||r.some(e=>e.hasEscapes)?r:void 0,n).value).length,a=0;for(;a<r.length-1&&i>r[a].totalSlots;)a++;return r[a]??this.compile(``)}};const c=new s;function l(e,t){if(t?.resolveMask)return 1/0;let n=t?.tokens?new s(t.tokens):c,r=Array.isArray(e)?e:[e],i=0;for(let e of r)i=Math.max(i,n.compile(e).maxLength);return i}function u(e,t,n,r,i,o){let s=``,c=``,l=0,u=0,d=!1,f=t.tokens[0],p=!1;for(let r of t.parts){if(`kind`in r){c+=r.text,i&&e.startsWith(r.text,l)&&(l+=r.text.length,r===f&&(p=!0));continue}let m=!1;for(;l<e.length;){let h=i&&t.hasEscapes&&t.literals.find(t=>e.startsWith(t.text,l));if(h){l+=h.text.length;continue}if(i&&!p&&f?.kind===`literal`&&e.startsWith(f.text,l)){l+=f.text.length,p=!0;continue}let g=String.fromCodePoint(e.codePointAt(l));if(l+=g.length,r.match(g)){o&&!d&&l>n&&(u=s.length+c.length),s+=c+a(g,r),c=``,m=!0,d||(l<=n?u=s.length:d=!0);break}}if(!m)break}if(d||(u=s.length),r&&c){let e=u===s.length;s+=c,e&&(u=s.length)}return{value:s,caret:u}}function d(e,t){return e.tokens[e.literalBeforeRun[t]].text}function f(e,t,n,r){let i=0;for(let a=t;a<e.length;){let t=String.fromCodePoint(e.codePointAt(a));a+=t.length,n.isData(t,r)&&i++}return i}function p(e,t,n,r,i){for(let a=r+1;a<n.runChars.length;a++){let r=d(n,a);if(e.startsWith(r,t))return f(e,t+r.length,i,n)<=n.capacityFromRun[a]?a:-1}return-1}function m(e,t,n,r){let i=t.runChars.length,o=Array(t.totalSlots).fill(``),s=Array(t.totalSlots).fill(-1),c=Array(i).fill(0),l=Array(t.tokens.length).fill(-1),u=0,f=0,m=0,h=t.tokens[0];for(r&&h?.kind===`literal`&&e.startsWith(h.text)&&(l[0]=0,m=h.text.length);m<e.length&&u<i;){if(r&&l[0]<0&&h?.kind===`literal`&&e.startsWith(h.text,m)){l[0]=m,m+=h.text.length;continue}let g=t.runChars[u],_=String.fromCodePoint(e.codePointAt(m)),v=g[f].match(_),y=r&&(!v||t.hasEscapes)?p(e,m,t,u,n):-1;if(y>=0){l[t.literalBeforeRun[y]]=m,m+=d(t,y).length,u=y,f=0;continue}if(v){let n=t.runOffset[u]+f;if(o[n]=a(_,g[f]),s[n]=m+_.length,c[u]=f+1,m+=_.length,f++,f===g.length&&(u++,f=0,r&&u<i)){let n=d(t,u);e.startsWith(n,m)&&(l[t.literalBeforeRun[u]]=m,m+=n.length)}continue}m+=_.length}return{slotChar:o,slotSource:s,runFilled:c,literalSource:l}}function h(e,t,n){let{tokens:r,runBeforeLiteral:i,runAfterLiteral:a,literalBeforeRun:o,runChars:s}=e,{runFilled:c,literalSource:l}=t,u=Array(r.length).fill(!1),d=c.length-1;for(;d>=0&&c[d]===0;)d--;for(let e=0;e<r.length;e++){if(r[e].kind!==`literal`)continue;let t=a[e],o=i[e];u[e]=t>=0&&(c[t]>0||l[e]>=0&&t<d)||n&&(o<0||c[o]===s[o].length)}let f=-1;for(let e=0;e<s.length;e++){if(c[e]===0)continue;let t=o[e];if(t>=0){let n=r[t].text;for(let t=f+1;t<e;t++){let e=o[t];e<0||r[e].text===n&&(u[e]=!0)}}f=e}return u}function g(e,t,n,r,i,a){let{tokens:o,runChars:s,runOffset:c,runBeforeLiteral:l,runAfterLiteral:u,runOfToken:d}=e,{slotChar:f,slotSource:p,runFilled:m}=t,h=``,g=0,_=!1;for(let e=0;e<o.length;e++){let v=o[e];if(v.kind===`literal`){if(!n[e])continue;let o=l[e],c=u[e],d=c<0||m[c]===0,f=i&&(o<0||m[o]===s[o].length),p=t.literalSource[e],y=!_&&g===h.length;h+=v.text,y&&(a||f&&d||p>=0&&p<r)&&(g=h.length);continue}let y=d[e],b=c[y];for(let e=0;e<m[y];e++)h+=f[b+e],!_&&(p[b+e]<=r?g=h.length:_=!0)}return{value:h,caret:g}}function _(e,t,n,r,i,a,o){let s=m(e,t,i,a);return g(t,s,h(t,s,r),n,r,o)}function v(e,t,n,r,i){let a,o=!1;if(r?.resolveMask){let s=Array.isArray(t)?t:[t],c=i.data(e,n,s.map(e=>i.compile(e)));a=i.resolve(c.value,r.resolveMask(c.value),!1),e=c.value,n=c.caret,o=c.afterLiteral}else a=i.resolve(e,t);if(!e)return{value:``,caret:0};let s=r?.eager!==!1;return r?.segmented===!1?u(e,a,n,s,!r.resolveMask,o):_(e,a,n,s,i,!r?.resolveMask,o)}function y(e,t,n=0,r){return v(e,t,n,r,r?.tokens?new s(r.tokens):c)}let b;function x(){return b===void 0&&(b=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),b}const S=`data-masked`;function C(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function w(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function T(e,t){try{t>0&&t<e.value.length&&e.value.charCodeAt(t)>=56320&&e.value.charCodeAt(t)<=57343&&e.value.charCodeAt(t-1)>=55296&&e.value.charCodeAt(t-1)<=56319&&t--,e.setSelectionRange(t,t)}catch{}}function E(e){return()=>{let t=e;e=void 0,t?.()}}function D(e,t,n){if(n.value.startsWith(e.slice(0,t)))return t;let r=n.value.length,i=e.length;for(;i>t&&r>0&&e[i-1]===n.value[r-1];)i--,r--;return Math.min(t,n.caret,r)}function O(e){return e?.startsWith(`delete`)&&e.endsWith(`Backward`)?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function k(e,t){return!t&&e}function A(e,t,n){if(e.getAttribute(S)!==null)return()=>{};let{onChange:r,segmented:i,eager:a,tokens:o,resolveMask:c}=C(n),u=new s(o),d=(e,n,r=a)=>v(e,t,n,{tokens:o,resolveMask:c,segmented:i,eager:r},u),f=!!o&&Object.keys(o).length>0,p=[],m=(t,n)=>{e.hasAttribute(t)||(e.setAttribute(t,n),p.push(t))},h=c||f?1/0:l(t);e.setAttribute(S,Array.isArray(t)?t.join(`|`):t),m(`autocomplete`,`off`),m(`autocorrect`,`off`),m(`autocapitalize`,`off`),m(`spellcheck`,`false`),Number.isFinite(h)&&m(`maxlength`,String(h));let g=!1,_=!1,y=!1,b=e.value??``,A=x()?`keyup`:`keydown`,j=new Set,M=e=>{let t=requestAnimationFrame(()=>{j.delete(t),e()});j.add(t)},N=()=>{for(let e of j)cancelAnimationFrame(e);j.clear()},P=e=>{let t=e.target,n=t.value;M(()=>{if(f&&_||t.value===n&&t.selectionStart!==t.selectionEnd)return;let e=d(t.value,w(t));t.value=e.value,T(t,e.caret),b=t.value,r?.(t.value)})},F=e=>{let t=e,n=e.target;if(N(),g=!1,y=!0,f&&(_||t.isComposing)||n.value===b&&n.selectionStart!==n.selectionEnd)return;let i=w(n),o=b.length,s=O(t.inputType),l=n.value,u=d(l,i,k(a,s===`backspace`||s===`delete`));n.value=u.value,c&&u.value!==l&&u.value!==b?T(n,u.caret):s===`unidentified`?T(n,n.value.length>o?u.caret:i):s===`delete`?T(n,o===n.value.length?i+1:i):s===`backspace`?T(n,D(l,i,u)):T(n,u.caret),b=n.value,r?.(n.value)},I=()=>{_=!0,N(),g=!1},L=e=>{_=!1,y=!0;let t=e.target,n=w(t),i=d(t.value,n);t.value=i.value,T(t,i.caret),b=t.value,r?.(t.value)},R=e=>{let t=e,n=t.target,i=n.value;if(_)return;if(A===`keyup`&&y){y=!1;return}if(!t.key){g=!0,M(()=>{if(n.value===i&&n.selectionStart!==n.selectionEnd){g=!1;return}let e=n.selectionStart??999,t=n.value.length<i.length,r=d(n.value,e,k(a,t));n.value=r.value,T(n,r.caret),b=n.value,M(()=>{g=!1})});return}if(t.key===`Meta`)return;let o=t.key===`Backspace`,s=t.key===`Delete`,l=Array.from(t.key).length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,u=t.key===`Unidentified`;if(l&&n.selectionStart===n.selectionEnd&&i.length>=h&&!x()){t.preventDefault();return}if(g){t.preventDefault();return}!o&&!s&&!l&&!u||M(()=>{if(n.value===i&&n.selectionStart!==n.selectionEnd)return;let e=n.selectionStart??999,t=n.value,f=d(t,e,k(a,o||s));if(n.value=f.value,c&&f.value!==t&&f.value!==i)T(n,f.caret);else if(u){let t=n.value.length>i.length?f.caret:e;T(n,t)}else if(s){let t=i.length===n.value.length?e+1:e;T(n,t)}else o?T(n,D(t,e,f)):l&&T(n,f.caret);b=n.value,r?.(n.value)})};return e.addEventListener(`paste`,P),e.addEventListener(`input`,F),e.addEventListener(`compositionstart`,I),e.addEventListener(`compositionend`,L),e.addEventListener(A,R),E(()=>{e.removeEventListener(`paste`,P),e.removeEventListener(`input`,F),e.removeEventListener(`compositionstart`,I),e.removeEventListener(`compositionend`,L),e.removeEventListener(A,R),e.removeAttribute(S);for(let t of p)e.removeAttribute(t);N()})}function j(e){return e>=`0`&&e<=`9`}function M(e){let t=e?.decimalPlaces,n=t!=null&&Number.isFinite(t)?Math.max(0,Math.floor(t)):void 0,r=e?.numberPlaces;return{decimalPlaces:n,numberPlaces:r!=null&&Number.isFinite(r)?Math.max(1,Math.floor(r)):void 0,segmented:e?.segmented??!0,separator:e?.separator??`,`,decimalSeparator:e?.decimalSeparator??`.`,prefix:e?.prefix??``,suffix:e?.suffix??``,allowNegative:e?.allowNegative??!1}}function N(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function P(e,t){if(!t||e.length<=3)return e;let n=[],r=e.length;for(;r>3;)n.unshift(e.slice(r-3,r)),r-=3;return n.unshift(e.slice(0,r)),n.join(t)}function F(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(j(e[r])&&(n++,n===t))return r+1;return e.length}function I(e,t){let n=0,r=``;t.prefix&&e.startsWith(t.prefix)?n=t.prefix.length:(t.allowNegative&&e[0]===`-`&&(r=`-`,n=1),t.prefix&&e.startsWith(t.prefix,n)&&(n+=t.prefix.length));let i=e.length;return t.suffix&&e.endsWith(t.suffix)&&i-t.suffix.length>=n&&(i-=t.suffix.length),{sign:r,body:e.slice(n,i),bodyStart:n}}function L(e,t){let n=I(e,t),r=``,i=``,a=n.sign===`-`,o=!1,s=t.decimalPlaces!==0;for(let e of n.body){if(j(e)){o?(t.decimalPlaces==null||i.length<t.decimalPlaces)&&(i+=e):(t.numberPlaces==null||r.length<t.numberPlaces)&&(r+=e);continue}if(s&&!o&&e===t.decimalSeparator){o=!0;continue}e===`-`&&t.allowNegative&&(a=!0)}return{isNegative:a,intDigits:r,fracDigits:i,hasSeparator:o}}function R(e,t,n){let r=n.decimalPlaces!==0,i=!1,a=0;for(let o=0;o<t;o++){let t=e[o];if(j(t)){i?(n.decimalPlaces==null||a<n.decimalPlaces)&&a++:(n.numberPlaces==null||a<n.numberPlaces)&&a++;continue}r&&!i&&t===n.decimalSeparator&&(i=!0,a=0)}return{inFraction:i,digitsBefore:a}}function z(e,t=0,n){let r=M(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=L(e,r);if(a===``&&o===``&&!s)return{value:``,caret:0};let c=N(a||`0`),l=r.numberPlaces==null?c:c.padStart(r.numberPlaces,`0`),u=r.segmented?P(l,r.separator):l,d=r.decimalPlaces!=null&&r.decimalPlaces>0?o.padEnd(r.decimalPlaces,`0`):o,f=u+(r.decimalPlaces!==0&&(r.decimalPlaces!=null||s)?r.decimalSeparator+d:``),p=i?`-`:``,m=p+r.prefix+f+r.suffix,h=I(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=R(h.body,g,r),y=p.length+r.prefix.length,b=l.length-c.length;return{value:m,caret:_?y+u.length+r.decimalSeparator.length+v:y+F(u,v+b)}}function B(e,t){return z(e,e.length,t).value}function V(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=L(e,M(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n?-a:a}function H(e,t){let n=M(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=L(e,n);if(a||i.length<n.decimalPlaces+1)return null;let o=i.length-n.decimalPlaces,s=i.slice(o),c=i.slice(0,o-1),l=r?`-`:``;return z(l+c+n.decimalSeparator+s,l.length+c.length,n)}function U(e,t,n,r){if(n<=0)return null;let i=t-n;if(i<0||t>e.length)return null;let a=e.slice(0,i)+e.slice(t),{bodyStart:o,body:s}=I(a,M(r)),c=o+s.length,l=i<o?o:i>c?c:-1;if(l<0)return null;let u=e.slice(i,t);return{value:a.slice(0,l)+u+a.slice(l),caret:l+n}}function W(e,t,n,r){let i=M(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=L(e.slice(0,a)+e.slice(t),i),u=N(s||`0`),d=u!==`0`,f=d&&i.numberPlaces!=null&&u.length<i.numberPlaces;if(d&&!f)return null;let p=+!!o+i.prefix.length;if(a<p||a>p+s.length)return null;let m=o?`-`:``,h=(d?u:``)+n;return z(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function G(e,t){let n=M(t);if(!Number.isFinite(e))return``;let r=n.allowNegative&&e<0,i=Math.abs(e),a=n.decimalPlaces==null?String(i):i.toFixed(n.decimalPlaces),o=a.indexOf(`.`),s=o===-1?a:a.slice(0,o),c=o===-1?``:a.slice(o+1),l=N(s||`0`),u=n.numberPlaces==null?l:l.padStart(n.numberPlaces,`0`),d=(n.segmented?P(u,n.separator):u)+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+d+n.suffix}const K=`data-masked`;function q(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function J(e){return e.length===1&&e>=`0`&&e<=`9`}function Y(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function X(e,t){try{e.setSelectionRange(t,t)}catch{}}function Z(e,t){if(e.getAttribute(K)!==null)return()=>{};let{onChange:n,...r}=q(t),i=r,{decimalSeparator:a,decimalPlaces:o}=M(i),s=[],c=(t,n)=>{e.hasAttribute(t)||(e.setAttribute(t,n),s.push(t))};e.setAttribute(K,`decimal`),c(`autocomplete`,`off`),c(`autocorrect`,`off`),c(`autocapitalize`,`off`),c(`spellcheck`,`false`);let l=!1,u=!1,d=!1,f=null,p=x()?`keyup`:`keydown`,m=new Set,h=e=>{let t=requestAnimationFrame(()=>{m.delete(t),e()});m.add(t)},g=()=>{for(let e of m)cancelAnimationFrame(e);m.clear()},_=(e,t)=>{e.value=t.value,X(e,t.caret),n?.(t.value,V(t.value,i))},v=(e,t={})=>{let n=Y(e),r=(t,r)=>{if(o===0||t.length!==1||t!==`.`&&t!==`,`||t===a)return!1;for(let i of r)if(i!=null&&i>=0&&e.value.slice(i,i+t.length)===t)return e.value=e.value.slice(0,i)+a+e.value.slice(i+t.length),n=i+t.length<=n?n+a.length-t.length:n,X(e,n),!0;return!1};if(f){let{text:e,starts:t}=f;f=null,r(e,t)}if(t.inputType===`deleteContentBackward`){let t=H(e.value,i);if(t){_(e,t);return}}let s=t.insertedText;if(s!=null&&r(s,[t.insertedAt,n-s.length]),s!=null&&s.length>0){let t=U(e.value,n,s.length,i);t&&(e.value=t.value,n=t.caret)}let c=s!=null&&s.length===1&&J(s)?s:void 0,l=c?W(e.value,n,c,i):null;_(e,l??z(e.value,n,i))},y=e=>{let t=e.target;h(()=>{v(t)})},b=e=>{let t=e,n=e.target;g(),l=!1,f=null,d=!0,v(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},S=()=>{u=!0,g(),l=!1,f=null},C=e=>{u=!1,d=!0,v(e.target)},w=e=>{let t=e,n=t.target,r=Y(n),i=n.value;if(u)return;if(p===`keyup`&&d){d=!1;return}if(!t.key){l=!0,h(()=>{if(n.value===i&&n.selectionStart!==n.selectionEnd){l=!1;return}v(n),h(()=>{l=!1})});return}if(t.key===`Meta`)return;if(l){t.preventDefault();return}let s=t.key===`Backspace`,c=t.key===`Delete`,m=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,g=t.key===`Unidentified`;m&&o!==0&&(t.key===`.`||t.key===`,`)&&t.key!==a&&(f={text:t.key,starts:[r,r-t.key.length]}),!(!s&&!c&&!m&&!g)&&h(()=>{(n.value!==i||n.selectionStart===n.selectionEnd)&&v(n,{insertedText:m?t.key:null,insertedAt:m?r:void 0,inputType:s?`deleteContentBackward`:c?`deleteContentForward`:void 0})})};return e.addEventListener(`paste`,y),e.addEventListener(`input`,b),e.addEventListener(`compositionstart`,S),e.addEventListener(`compositionend`,C),e.addEventListener(p,w),()=>{e.removeEventListener(`paste`,y),e.removeEventListener(`input`,b),e.removeEventListener(`compositionstart`,S),e.removeEventListener(`compositionend`,C),e.removeEventListener(p,w),e.removeAttribute(K);for(let t of s)e.removeAttribute(t);g()}}var Q=class{caret;_value;_mask;_options;constructor(e,t,n=0,r){this._value=e,this._mask=t,this.caret=n,this._options=r}process(){let e=y(this._value,this._mask,this.caret,this._options);return this.caret=e.caret,e.value}};function $(e,t,n=0,r){return new Q(e,t,n,r)}function ee(e,t,n){return $(e,t,0,n).process()}exports.Mask=Q,exports.applyDecimalMask=z,exports.applyMask=y,exports.bind=A,exports.bindDecimal=Z,exports.buildMask=$,exports.formatDecimalValue=G,exports.getMaxLength=l,exports.process=ee,exports.processDecimal=B,exports.unmaskDecimal=V;
|
|
2
2
|
//# sourceMappingURL=mother-mask.cjs.map
|