mother-mask 3.12.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 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) | [Live demo](https://dan2dev.github.io/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
- `prefix` and `suffix` are chrome, not content. Typing with the caret parked inside them lands the character at the nearest edge of the number, so every spot that looks like the start of the number behaves like it:
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", and unmaskDecimal() reports 1234
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` | Digit |
150
+ | `9` | ASCII digit (`0`–`9`) |
99
151
  | `Z` | ASCII letter |
100
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:
@@ -138,6 +192,9 @@ may change: the caret follows the source character, not the output's case or wid
138
192
  Custom tokens work with ordered arrays, segmented editing, eager literals,
139
193
  and all four APIs: `applyMask`, `process`, `buildMask`, and `bind`.
140
194
 
195
+ Use token transforms to normalize case while preserving the caret, rather than
196
+ rewriting `input.value` inside an `onChange` callback.
197
+
141
198
  ## Content-dependent Masks
142
199
 
143
200
  ```ts
@@ -221,6 +278,10 @@ while later segments still contain data. For example, three Backspaces over
221
278
  type a replacement. This also works with `eager: false`. Trailing separators
222
279
  still follow eager mode, and selecting everything and deleting clears the input.
223
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
+
224
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:
225
286
 
226
287
  ```ts
@@ -229,7 +290,7 @@ bind(input, '999.999.999-99')
229
290
  // → "015.|-39" the "-" keeps "39" in the last field
230
291
  ```
231
292
 
232
- Anchoring is only as precise as the separators allow. A mask whose separators are all the same character can produce a genuinely 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.
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.
233
294
 
234
295
  For classic reflow behavior, pass `segmented: false`:
235
296
 
@@ -237,6 +298,51 @@ For classic reflow behavior, pass `segmented: false`:
237
298
  bind(input, '999.999.999-99', { segmented: false })
238
299
  ```
239
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
+
240
346
  ## CDN
241
347
 
242
348
  ```html
@@ -250,19 +356,28 @@ The global name is `MotherMask`.
250
356
 
251
357
  ## API
252
358
 
253
- Main exports:
254
-
255
- - `bind(input, mask, options?)`
256
- - `bindDecimal(input, options?)`
257
- - `applyMask(value, mask, inputCaret?, options?)`
258
- - `process(value, mask, options?)`
259
- - `buildMask(value, mask, caret?, options?)`
260
- - `getMaxLength(mask, options?)` (formatted UTF-16 upper bound; `Infinity` with a resolver)
261
- - `applyDecimalMask(value, inputCaret?, options?)`
262
- - `processDecimal(value, options?)`
263
- - `unmaskDecimal(value, options?)`
264
- - `formatDecimalValue(value, options?)`
265
- - `Mask`
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.
266
381
 
267
382
  Exported types:
268
383
 
@@ -277,6 +392,14 @@ Exported types:
277
392
  - `DecimalMaskOptions`
278
393
  - `BindDecimalOptions`
279
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
+
280
403
  ## License
281
404
 
282
405
  MIT - [Danilo Celestino de Castro](https://github.com/dan2dev)
@@ -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(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){return e===`deleteContentBackward`?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function O(e,t){return!t&&e}function k(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??``,k=x()?`keyup`:`keydown`,A=new Set,j=e=>{let t=requestAnimationFrame(()=>{A.delete(t),e()});A.add(t)},M=()=>{for(let e of A)cancelAnimationFrame(e);A.clear()},N=e=>{let t=e.target,n=t.value;j(()=>{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)})},P=e=>{let t=e,n=e.target;if(M(),g=!1,y=!0,f&&(_||t.isComposing)||n.value===b&&n.selectionStart!==n.selectionEnd)return;let i=w(n),o=b.length,s=D(t.inputType),l=n.value,u=d(l,i,O(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,i):T(n,u.caret),b=n.value,r?.(n.value)},F=()=>{_=!0,M(),g=!1},I=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)},L=e=>{let t=e,n=t.target,i=n.value;if(_)return;if(k===`keyup`&&y){y=!1;return}if(!t.key){g=!0,j(()=>{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,O(a,t));n.value=r.value,T(n,r.caret),b=n.value,j(()=>{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||j(()=>{if(n.value===i&&n.selectionStart!==n.selectionEnd)return;let e=n.selectionStart??999,t=n.value,f=d(t,e,O(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,e):l&&T(n,f.caret);b=n.value,r?.(n.value)})};return e.addEventListener(`paste`,N),e.addEventListener(`input`,P),e.addEventListener(`compositionstart`,F),e.addEventListener(`compositionend`,I),e.addEventListener(k,L),E(()=>{e.removeEventListener(`paste`,N),e.removeEventListener(`input`,P),e.removeEventListener(`compositionstart`,F),e.removeEventListener(`compositionend`,I),e.removeEventListener(k,L),e.removeAttribute(S);for(let t of p)e.removeAttribute(t);M()})}function A(e){return e>=`0`&&e<=`9`}function j(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 M(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function N(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 P(e,t){if(t<=0)return 0;let n=0;for(let r=0;r<e.length;r++)if(A(e[r])&&(n++,n===t))return r+1;return e.length}function F(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 I(e,t){let n=F(e,t),r=``,i=``,a=n.sign===`-`,o=!1,s=t.decimalPlaces!==0;for(let e of n.body){if(A(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 L(e,t,n){let r=n.decimalPlaces!==0,i=!1,a=0;for(let o=0;o<t;o++){let t=e[o];if(A(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 R(e,t=0,n){let r=j(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=I(e,r);if(a===``&&o===``&&!s)return{value:``,caret:0};let c=M(a||`0`),l=r.numberPlaces==null?c:c.padStart(r.numberPlaces,`0`),u=r.segmented?N(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=F(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=L(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+P(u,v+b)}}function z(e,t){return R(e,e.length,t).value}function B(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=I(e,j(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n?-a:a}function V(e,t){let n=j(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=I(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 R(l+c+n.decimalSeparator+s,l.length+c.length,n)}function H(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}=F(a,j(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 U(e,t,n,r){let i=j(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=I(e.slice(0,a)+e.slice(t),i),u=M(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 R(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function W(e,t){let n=j(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=M(s||`0`),u=n.numberPlaces==null?l:l.padStart(n.numberPlaces,`0`),d=(n.segmented?N(u,n.separator):u)+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+d+n.suffix}const G=`data-masked`;function K(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function q(e){return e.length===1&&e>=`0`&&e<=`9`}function J(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function Y(e,t){try{e.setSelectionRange(t,t)}catch{}}function X(e,t){if(e.getAttribute(G)!==null)return()=>{};let{onChange:n,...r}=K(t),i=r,{decimalSeparator:a,decimalPlaces:o}=j(i),s=[],c=(t,n)=>{e.hasAttribute(t)||(e.setAttribute(t,n),s.push(t))};e.setAttribute(G,`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,Y(e,t.caret),n?.(t.value,B(t.value,i))},v=(e,t={})=>{let n=J(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,Y(e,n),!0;return!1};if(f){let{text:e,starts:t}=f;f=null,r(e,t)}if(t.inputType===`deleteContentBackward`){let t=V(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=H(e.value,n,s.length,i);t&&(e.value=t.value,n=t.caret)}let c=s!=null&&s.length===1&&q(s)?s:void 0,l=c?U(e.value,n,c,i):null;_(e,l??R(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=J(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(G);for(let t of s)e.removeAttribute(t);g()}}var Z=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 Q(e,t,n=0,r){return new Z(e,t,n,r)}function $(e,t,n){return Q(e,t,0,n).process()}exports.Mask=Z,exports.applyDecimalMask=R,exports.applyMask=y,exports.bind=k,exports.bindDecimal=X,exports.buildMask=Q,exports.formatDecimalValue=W,exports.getMaxLength=l,exports.process=$,exports.processDecimal=z,exports.unmaskDecimal=B;
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