mother-mask 3.24.0 → 3.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -164,6 +164,7 @@ bindDecimal(input, { prefix: 'Q1 ', decimalPlaces: 2 })
164
164
  | `Z` | ASCII letter |
165
165
  | `A` | ASCII letter or digit |
166
166
  | Custom token | Matches its local definition (see below) |
167
+ | `{n}` / `{min,max}` | Repeats the token before it (see [quantifiers](#bounded-quantifiers)) |
167
168
  | `\` | Escapes a token or another backslash (see [escaping](#escaped-literals)) |
168
169
  | Anything else | Literal separator |
169
170
 
@@ -175,6 +176,63 @@ bind(input, '99/99/9999')
175
176
  bind(input, 'AA.AAA.AAA/AAAA-99')
176
177
  ```
177
178
 
179
+ ## Bounded Quantifiers
180
+
181
+ A slot token can be followed by a bounded repeat count. `{n}` is exactly `n`
182
+ occurrences; `{min,max}` is anywhere from `min` to `max`:
183
+
184
+ ```text
185
+ 9{4} exactly four digits
186
+ 9{1,2} one or two digits
187
+ Z{2,4} two to four letters
188
+ A{1,8} one to eight alphanumeric characters
189
+ ```
190
+
191
+ `{n}` is just shorthand — `9{4}` and `9999` compile to the same mask.
192
+ `{min,max}` is the new capability: a **variable-width segment**.
193
+
194
+ ```ts
195
+ bind(date, '9{1,2}/9{1,2}/9{4}')
196
+ // 3/4/1986 3/12/1986 12/4/1986 12/12/1986
197
+ ```
198
+
199
+ The user decides how wide a ranged segment is, using the separator:
200
+
201
+ - **Typing `"3/"` commits the one-digit first segment.** Once a ranged segment
202
+ has reached its `min`, typing the literal that follows it ends that segment
203
+ for good, and the separator stays visible — it is input, not decoration, so
204
+ this holds with `eager: false` too.
205
+ - **Typing `"12"` reaches `max` and may reveal `"/"` eagerly**, exactly as a
206
+ fixed `99` segment does. With `eager: false` it waits for the next character.
207
+
208
+ Reaching `min` alone never inserts anything: after `"3"` the value is `"3"`,
209
+ because the next keystroke could still be a second digit.
210
+
211
+ Closing a segment early retires the slots it did not use, so a finished value
212
+ can be shorter than the pattern's maximum: `"3/4/1986"` is complete at eight
213
+ characters even though `getMaxLength` reports `10`. Anything typed past that
214
+ point is dropped rather than repacked — the boundaries the user set hold, and
215
+ the character that no longer fits falls off the end, exactly as an extra digit
216
+ does on a full fixed mask. So `maxlength` alone is not a completeness check for
217
+ a ranged mask; inspect the value if you need one.
218
+
219
+ Mother Mask **does not validate dates** — or anything else semantic. It never
220
+ inspects a value to decide that `"34"` cannot be a day and must mean `3/4`.
221
+ A quantifier is a width rule; explicit separators are how a user says a
222
+ segment is shorter than its maximum.
223
+
224
+ Only bounded forms are syntax. `*`, `+`, `?`, `{n,}`, `{,n}`, `{0}` and
225
+ `{2,1}` are not, and neither is a repeat count above 1000; those brace
226
+ sequences stay literal text, exactly as they did before quantifiers existed.
227
+ A quantifier is only read directly after an unescaped token, so the pattern
228
+ `'\\9{1,2}'` is the literal text `9{1,2}`.
229
+
230
+ `getMaxLength` and the `maxlength` `bind` sets use the compiled maximum
231
+ (`10` for `'9{1,2}/9{1,2}/9{4}'`), never the length of the pattern source.
232
+ Ordered mask arrays likewise select by compiled slot capacity. In flat mode
233
+ (`segmented: false`) there are no segment boundaries to commit, so a ranged
234
+ run simply behaves as its maximum width.
235
+
178
236
  ## Custom Tokens and Transforms
179
237
 
180
238
  Tokens are local to an operation or binding. A definition is a `RegExp`, a
@@ -203,7 +261,15 @@ Use an idempotent transform whose output still matches the token. UTF-16 width
203
261
  may change: the caret follows the source character, not the output's case or width.
204
262
 
205
263
  Custom tokens work with ordered arrays, segmented editing, eager literals,
206
- and all four APIs: `applyMask`, `process`, `buildMask`, and `bind`.
264
+ [bounded quantifiers](#bounded-quantifiers), and all four APIs: `applyMask`,
265
+ `process`, `buildMask`, and `bind`. A quantified run reuses the same matcher
266
+ and transform, and a transform still runs exactly once per accepted character:
267
+
268
+ ```ts
269
+ process('ab-123', 'U{1,2}-9{1,3}', {
270
+ tokens: { U: { match: /[a-z]/i, transform: char => char.toUpperCase() } },
271
+ }) // 'AB-123'
272
+ ```
207
273
 
208
274
  Use token transforms to normalize case while preserving the caret, rather than
209
275
  rewriting `input.value` inside an `onChange` callback.
@@ -251,7 +317,9 @@ bind(input, '\\\\99') // a literal backslash, then two digits
251
317
 
252
318
  In the pattern, backslash escapes a built-in/custom token or another backslash.
253
319
  Before any other character it remains literal; a trailing backslash also remains
254
- literal. Existing masks that used a backslash immediately before a token or
320
+ literal. An escaped token cannot take a
321
+ [quantifier](#bounded-quantifiers) either — `'\\9{1,2}'` is the literal text
322
+ `9{1,2}`. Existing masks that used a backslash immediately before a token or
255
323
  backslash must double it to keep that backslash in the output.
256
324
 
257
325
  Complete literal runs are treated as formatting at their boundary; escaped runs
@@ -318,6 +386,26 @@ bind(input, '(99) 99999-9999')
318
386
  // → "(|) 98765-4321" "98765" and "4321" never moved
319
387
  ```
320
388
 
389
+ Typing a character straight over a selection destroys the same dividers the
390
+ equivalent Delete would, so it gets the same rescue — but only when it has to.
391
+ Selecting the `"3/12"` of `"3/12/1986"` on `'9{1,2}/9{1,2}/9{4}'` and typing
392
+ `"4"` leaves `"4/1986"`, where the lone surviving `"/"` reads equally well as
393
+ the day's; without the rescue the untouched year breaks apart into
394
+ `"4/19/86"`. Restoring the divider gives `"4|//1986"` instead, with the year
395
+ untouched. The caret stays in the day: it is only one of the two digits that
396
+ field accepts, so the next keystroke widens it to `"42"` rather than starting
397
+ the month — the mask has no way to know the day was finished, and eager hands
398
+ the caret across on its own once it is. Where the tail was never in danger —
399
+ retyping a CPF over `"012.153.441"`, whose `"-"` is distinct — nothing is
400
+ restored and the digits keep filling from the left exactly as before.
401
+
402
+ A divider whose removal would re-segment untouched text is not erodible:
403
+ Backspacing the second `"/"` out of `"13//1986"` would leave `"13/1986"`,
404
+ which re-reads as `13 / 19 / 86`, so it is put back and the keystroke erodes
405
+ the day instead. Where dropping a divider costs nothing — a CPF's `"-"` still
406
+ pins its last field however much of `"."` survives — Backspace peels it away
407
+ exactly as documented above.
408
+
321
409
  This is bind-only, like eager's Backspace/Delete handling above: pure
322
410
  `applyMask`/`buildMask`/`process` see only the resulting `(value, caret)` and
323
411
  can't tell a deletion from fresh input, so `applyMask("98765-4321", mask, 0)`
@@ -351,6 +439,10 @@ bind(input, '99/99/9999', { eager: false })
351
439
  // typing "25" shows "25" until the next digit arrives
352
440
  ```
353
441
 
442
+ A [ranged segment](#bounded-quantifiers) reveals its separator only at its
443
+ maximum, never at its minimum. A separator the user types themselves is
444
+ their input rather than a reveal, so it survives `eager: false`.
445
+
354
446
  `bind` does not reinsert an eager separator immediately after Backspace/Delete
355
447
  removes it: deleting the `"."` off `"012."` leaves `"012"`. This is binding behavior;
356
448
  the pure helpers have no edit history and apply the configured `eager` option on
@@ -415,9 +507,10 @@ attribute options.
415
507
  `bind` also accepts a `(value) => void` callback as its third argument;
416
508
  `bindDecimal` accepts `(value, numericValue) => void` as its second argument.
417
509
 
418
- Optional caret arguments default to `0`. `getMaxLength` counts literals and
419
- reserves up to two UTF-16 units per custom-token slot; it is not a count of data
420
- characters. See [dynamic masks](#content-dependent-masks) for `maxlength` handling.
510
+ Optional caret arguments default to `0`. `getMaxLength` counts literals,
511
+ counts a [quantified](#bounded-quantifiers) run at its maximum, and reserves up
512
+ to two UTF-16 units per custom-token slot; it is not a count of data characters
513
+ and never the length of the pattern source. See [dynamic masks](#content-dependent-masks) for `maxlength` handling.
421
514
 
422
515
  Exported types:
423
516
 
@@ -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)}const a=[`中`,`あ`,`ア`,`가`];function o(e){let t=i(e);return a.some(e=>{try{return t(e)}catch{return!0}})}function s(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 c(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 l=class{definitions=new Map(r);cache=new Map;custom;hasComposingRisk;constructor(e){this.custom=!!e&&Object.keys(e).length>0;let t=!1;for(let[n,r]of Object.entries(e??{})){if(n===`\\`||Array.from(n).length!==1)throw RangeError(`Mask token keys must be one Unicode code point other than backslash`);let e=typeof r==`object`&&`match`in r?r:{match:r};o(e.match)&&(t=!0),this.definitions.set(n,{match:i(e.match),transform:e.transform,maxLength:2})}this.hasComposingRisk=t}compile(e){let t=this.cache.get(e);if(t)return t;let n=c(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 u=new l;function d(e,t){let n=Array.isArray(e)?e:[e],r=0;for(let e of n)r=Math.max(r,t.compile(e).maxLength);return r}function f(e,t){return t?.resolveMask?1/0:d(e,t?.tokens?new l(t.tokens):u)}function p(e,t,n,r,i,a){let o=``,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)){a&&!d&&l>n&&(u=o.length+c.length),o+=c+s(g,r),c=``,m=!0,d||(l<=n?u=o.length:d=!0);break}}if(!m)break}if(d||(u=o.length),r&&c){let e=u===o.length;o+=c,e&&(u=o.length)}return{value:o,caret:u}}function m(e,t){return e.tokens[e.literalBeforeRun[t]].text}function h(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 g(e,t,n){for(let r=0;r<n.length;)if(r+=String.fromCodePoint(n.codePointAt(r)).length,r<n.length&&e.startsWith(n.slice(r),t))return n.length-r;return 0}function _(e,t,n){return e.startsWith(n,t)?n.length:g(e,t,n)}function v(e,t,n,r,i){let a=n.runChars.length;for(let o=0;o<2;o++)for(let s=r+1;s<a;s++){let r=m(n,s),a=o===0?e.startsWith(r,t)?r.length:0:g(e,t,r);if(a)return h(e,t+a,i,n)<=n.capacityFromRun[s]?s:-1}return-1}function y(e,t,n,r,i){let a=t.runChars.length,o=Array(t.totalSlots).fill(``),c=Array(t.totalSlots).fill(-1),l=Array(a).fill(0),u=Array(t.tokens.length).fill(-1),d=0,f=0,p=0,g=!1,y=t.tokens[0];for(r&&y?.kind===`literal`&&e.startsWith(y.text)&&(u[0]=0,p=y.text.length);p<e.length&&d<a;){if(r&&u[0]<0&&y?.kind===`literal`&&e.startsWith(y.text,p)){u[0]=p,p+=y.text.length;continue}let b=t.runChars[d],x=String.fromCodePoint(e.codePointAt(p)),S=b[f].match(x),C=r&&(!S||t.hasEscapes)?v(e,p,t,d,n):-1;if(C>=0){u[t.literalBeforeRun[C]]=p,p+=_(e,p,m(t,C)),d=C,f=0;continue}if(!g&&f>0&&p===i&&d+1<a&&e.indexOf(m(t,d+1),p)<0&&h(e,p,n,t)===t.capacityFromRun[d+1]){g=!0,d++,f=0;continue}if(S){let n=t.runOffset[d]+f;if(o[n]=s(x,b[f]),c[n]=p+x.length,l[d]=f+1,p+=x.length,f++,f===b.length&&(d++,f=0,r&&d<a)){let n=m(t,d);e.startsWith(n,p)&&(u[t.literalBeforeRun[d]]=p,p+=n.length)}continue}p+=x.length}return{slotChar:o,slotSource:c,runFilled:l,literalSource:u}}function b(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],f=o<0&&d>=0&&(l[e+2]>=0||c[t+1]>0);u[e]=t>=0&&(c[t]>0||l[e]>=0&&t<d)||f||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 x(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=o<0||i&&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 S(e,t,n,r,i,a,o){let s=y(e,t,i,a,n);return x(t,s,b(t,s,r),n,r,o)}function C(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?p(e,a,n,s,!r.resolveMask,o):S(e,a,n,s,i,!r?.resolveMask,o)}function w(e,t,n=0,r){return C(e,t,n,r,r?.tokens?new l(r.tokens):u)}let T;function E(){return T===void 0&&(T=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),T}const D=`data-masked`;function O(e,t){e(`autocomplete`,t.autocomplete??`off`),e(`autocorrect`,t.autocorrect??`off`),e(`autocapitalize`,t.autocapitalize??`off`),e(`spellcheck`,String(t.spellcheck??!1))}function k(e){return e.getAttribute(D)!==null}function A(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function j(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 M(e){let t=e;return()=>{let e=t;t=void 0,e?.()}}function N(e,t){return e.value===t&&e.selectionStart!==e.selectionEnd}function P(){let e=new Set;return{scheduleFrame:t=>{let n=requestAnimationFrame(()=>{e.delete(n),t()});e.add(n)},cancelPendingFrames:()=>{for(let t of e)cancelAnimationFrame(t);e.clear()}}}function ee(e,t,n,r,i){if(n<=0)return e;let a=t+n;if(a>r.length||r.slice(0,t)!==e.slice(0,t)||r.slice(a)!==e.slice(t))return e;let o=r.slice(a);if(!Array.from(o).some(i))return e;let s=r.slice(t,a);if(!Array.from(s).some(i))return e;let c=``;for(let e of s)i(e)||(c+=e);return c?e.slice(0,t)+c+e.slice(t):e}function te(e){let t=[];return{setIfMissing:(n,r)=>{e.hasAttribute(n)||(e.setAttribute(n,r),t.push(n))},removeTracked:()=>{for(let n of t)e.removeAttribute(n)}}}function F(e,t,n,r,i,a){let{setIfMissing:o,removeTracked:s}=te(e);e.setAttribute(D,t),O(o,n),Number.isFinite(r)&&o(`maxlength`,String(r));let c=[`paste`,`input`,`compositionstart`,`compositionend`,E()?`keyup`:`keydown`];for(let t=0;t<c.length;t++)e.addEventListener(c[t],i[t]);return M(()=>{for(let t=0;t<c.length;t++)e.removeEventListener(c[t],i[t]);e.removeAttribute(D),s(),a()})}function I(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function L(e,t,n){return e===0&&t.value!==n?t.caret:e}function R(e,t,n,r){if(n.value.startsWith(e.slice(0,t)))return L(t,n,r);let i=n.value.length,a=e.length;for(;a>t&&i>0&&e[a-1]===n.value[i-1];)a--,i--;return Math.min(t,n.caret,i)}function z(e){return e?.startsWith(`delete`)&&e.endsWith(`Backward`)?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function B(e,t){return!t&&e}function V(e,t,n,r,i,a,o){return a&&i.value!==t&&i.value!==o?i.caret:e===`unidentified`?i.value.length>r?i.caret:L(n,i,o):e===`delete`?r===i.value.length?n+1:L(n,i,o):e===`backspace`?R(t,n,i,o):i.caret}function H(e,t,n){if(k(e))return()=>{};let{onChange:r,segmented:i,eager:a,tokens:o,resolveMask:s,autocomplete:c,autocorrect:u,autocapitalize:f,spellcheck:p}=I(n),m=new l(o),h=(e,n,r=a)=>C(e,t,n,{tokens:o,resolveMask:s,segmented:i,eager:r},m),g=e=>m.isData(e),_=m.hasComposingRisk,v=s||_?1/0:d(t,m),y=!1,b=!1,x=!1,S=e.value??``,{scheduleFrame:w,cancelPendingFrames:T}=P();return F(e,Array.isArray(t)?t.join(`|`):t,{autocomplete:c,autocorrect:u,autocapitalize:f,spellcheck:p},v,[e=>{let t=e.target,n=t.value;w(()=>{if(_&&b||N(t,n))return;let e=h(t.value,A(t));t.value=e.value,j(t,e.caret),S=t.value,r?.(t.value)})},e=>{let n=e,i=e.target;if(T(),y=!1,x=!0,_&&(b||n.isComposing)||N(i,S))return;let o=A(i),c=S.length,l=z(n.inputType),u=i.value,d=l===`backspace`||l===`delete`,f=!Array.isArray(t)&&!s&&(n.inputType===`deleteContentBackward`||n.inputType===`deleteContentForward`||n.inputType===`deleteByCut`)?ee(u,o,c-u.length,S,g):u,p=h(f,o,B(a,d));i.value=p.value,j(i,V(l,u,o,c,p,s,S)),S=i.value,r?.(i.value)},()=>{b=!0,T(),y=!1},e=>{b=!1,x=!0;let t=e.target,n=A(t),i=h(t.value,n);t.value=i.value,j(t,i.caret),S=t.value,r?.(t.value)},e=>{let t=e,n=t.target,i=n.value;if(b)return;if(E()&&x){x=!1;return}if(!t.key){y=!0,w(()=>{if(N(n,i)){y=!1;return}let e=n.selectionStart??999,t=n.value.length<i.length,r=h(n.value,e,B(a,t));n.value=r.value,j(n,r.caret),S=n.value,w(()=>{y=!1})});return}if(t.key===`Meta`)return;let o=t.key===`Backspace`,c=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>=v&&!E()){t.preventDefault();return}if(y){t.preventDefault();return}if(!o&&!c&&!l&&!u)return;let d=o?`backspace`:c?`delete`:u?`unidentified`:`insert`;w(()=>{if(N(n,i))return;let e=n.selectionStart??999,t=n.value,l=h(t,e,B(a,o||c));n.value=l.value,j(n,V(d,t,e,i.length,l,s,i)),S=n.value,r?.(n.value)})}],T)}function U(e){let t=e?.decimalPlaces,n=t!=null&&Number.isFinite(t)?Math.min(100,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 W(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function G(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 K(e,t){let n=W(e||`0`),r=t.numberPlaces==null?n:n.padStart(t.numberPlaces,`0`);return{intPart:n,paddedInt:r,groupedInt:t.segmented?G(r,t.separator):r}}function q(e){let t=e.indexOf(`e`);if(t<0)return e;let n=Number(e.slice(t+1)),r=e.slice(0,t),i=r.indexOf(`.`),a=i<0?r:r.slice(0,i)+r.slice(i+1),o=(i<0?r.length:i)+n;return o<=0?`0.`+`0`.repeat(-o)+a:o>=a.length?a+`0`.repeat(o-a.length):a.slice(0,o)+`.`+a.slice(o)}function ne(t,n){if(n<=0)return 0;let r=0;for(let i=0;i<t.length;i++)if(e(t[i])&&(r++,r===n))return i+1;return t.length}function J(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 Y(t,n){let r=J(t,n),i=``,a=``,o=r.sign===`-`,s=!1,c=n.decimalPlaces!==0;for(let t of r.body){if(e(t)){s?(n.decimalPlaces==null||a.length<n.decimalPlaces)&&(a+=t):(n.numberPlaces==null||i.length<n.numberPlaces)&&(i+=t);continue}if(c&&!s&&t===n.decimalSeparator){s=!0;continue}t===`-`&&n.allowNegative?o=!0:t===`+`&&n.allowNegative&&(o=!1)}return{isNegative:o,intDigits:i,fracDigits:a,hasSeparator:s}}function re(t,n,r){let i=r.decimalPlaces!==0,a=!1,o=0;for(let s=0;s<n;s++){let n=t[s];if(e(n)){a?(r.decimalPlaces==null||o<r.decimalPlaces)&&o++:(r.numberPlaces==null||o<r.numberPlaces)&&o++;continue}i&&!a&&n===r.decimalSeparator&&(a=!0,o=0)}return{inFraction:a,digitsBefore:o}}function X(e,t=0,n){let r=U(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=Y(e,r);if(a===``&&o===``&&!s){if(i){let e=`-`+r.prefix;return{value:e,caret:e.length}}return{value:``,caret:0}}let{intPart:c,paddedInt:l,groupedInt:u}=K(a,r),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=J(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=re(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+ne(u,v+b)}}function ie(e,t){return X(e,e.length,t).value}function Z(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=Y(e,U(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n&&a!==0?-a:a}function ae(e,t){let n=U(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=Y(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 X(l+c+n.decimalSeparator+s,l.length+c.length,n)}function oe(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}=J(a,U(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 se(e,t,n,r){let i=U(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=Y(e.slice(0,a)+e.slice(t),i),u=W(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 X(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function ce(e,t){let n=U(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);a.indexOf(`e`)>=0&&(a=q(String(i))+(n.decimalPlaces?`.`+`0`.repeat(n.decimalPlaces):``));let o=a.indexOf(`.`),s=o===-1?a:a.slice(0,o),c=o===-1?``:a.slice(o+1),{groupedInt:l}=K(s,n),u=l+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+u+n.suffix}function le(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function ue(t,n){if(k(t))return()=>{};let{onChange:r,autocomplete:i,autocorrect:a,autocapitalize:o,spellcheck:s,...c}=le(n),l=c,{decimalSeparator:u,decimalPlaces:d}=U(l),f=!1,p=!1,m=!1,h=null,{scheduleFrame:g,cancelPendingFrames:_}=P(),v=(e,t)=>{e.value=t.value,j(e,t.caret),r?.(t.value,Z(t.value,l))},y=(t,n={})=>{let r=A(t),i=(e,n)=>{if(d===0||e.length!==1||e!==`.`&&e!==`,`||e===u)return!1;for(let i of n)if(i!=null&&i>=0&&t.value.slice(i,i+e.length)===e)return t.value=t.value.slice(0,i)+u+t.value.slice(i+e.length),r=i+e.length<=r?r+u.length-e.length:r,j(t,r),!0;return!1};if(h){let{text:e,starts:t}=h;h=null,i(e,t)}if(n.inputType===`deleteContentBackward`){let e=ae(t.value,l);if(e){v(t,e);return}}let a=n.insertedText;if(a!=null&&i(a,[n.insertedAt,r-a.length]),a!=null&&a.length>0){let e=oe(t.value,r,a.length,l);e&&(t.value=e.value,r=e.caret)}let o=a!=null&&a.length===1&&e(a)?a:void 0,s=o?se(t.value,r,o,l):null;v(t,s??X(t.value,r,l))};return F(t,`decimal`,{autocomplete:i,autocorrect:a,autocapitalize:o,spellcheck:s},1/0,[e=>{let t=e.target;g(()=>{y(t)})},e=>{let t=e,n=e.target;_(),f=!1,h=null,m=!0,y(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},()=>{p=!0,_(),f=!1,h=null},e=>{p=!1,m=!0,y(e.target)},e=>{let t=e,n=t.target,r=A(n),i=n.value;if(p)return;if(E()&&m){m=!1;return}if(!t.key){f=!0,g(()=>{if(N(n,i)){f=!1;return}y(n),g(()=>{f=!1})});return}if(t.key===`Meta`)return;if(f){t.preventDefault();return}let a=t.key===`Backspace`,o=t.key===`Delete`,s=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,c=t.key===`Unidentified`;s&&d!==0&&(t.key===`.`||t.key===`,`)&&t.key!==u&&(h={text:t.key,starts:[r,r-t.key.length]}),!(!a&&!o&&!s&&!c)&&g(()=>{N(n,i)||y(n,{insertedText:s?t.key:null,insertedAt:s?r:void 0,inputType:a?`deleteContentBackward`:o?`deleteContentForward`:void 0})})}],_)}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=w(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 de(e,t,n){return $(e,t,0,n).process()}exports.Mask=Q,exports.applyDecimalMask=X,exports.applyMask=w,exports.bind=H,exports.bindDecimal=ue,exports.buildMask=$,exports.formatDecimalValue=ce,exports.getMaxLength=f,exports.process=de,exports.processDecimal=ie,exports.unmaskDecimal=Z;
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)}const a=[`中`,`あ`,`ア`,`가`];function o(e){let t=i(e);return a.some(e=>{try{return t(e)}catch{return!0}})}function s(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 c(e,t){if(e[t]!==`{`)return;let n=t+1,r=()=>{let t=-1;for(;n<e.length&&e[n]>=`0`&&e[n]<=`9`;)if(t=(t<0?0:t)*10+(e[n].charCodeAt(0)-48),n++,t>1e3)return-1;return t},i=r();if(i<1)return;let a=i;if(!(e[n]===`,`&&(n++,a=r(),a<i))&&e[n]===`}`)return{min:i,max:a,end:n}}function l(e,t){let n=[],r=[],i=[],a=[],o=[],s=Array.from(e),l=0,u=!1;for(let e=0;e<s.length;e++){let d=s[e],f=!1;d===`\\`&&(s[e+1]===`\\`||t.has(s[e+1]))&&(d=s[++e],f=!0,u=!0);let p=f?void 0:t.get(d),m=n[n.length-1];if(p){let t=c(s,e+1),u=t?t.min:1,d=t?t.max:1;if(t&&(e=t.end),l+=p.maxLength*d,m?.kind===`slots`){for(let e=0;e<d;e++)m.chars.push(p);a[a.length-1]+=u}else{let e=[];for(let t=0;t<d;t++)e.push(p);r.push(i.length),o.push(n.length),i.push(e),a.push(u),n.push({kind:`slots`,chars:e})}}else l+=d.length,m?.kind===`literal`?m.text+=d:(r.push(-1),n.push({kind:`literal`,text:d}))}let d=i.length,f=Array(d),p=Array(d),m=Array(d+1),h=Array(n.length).fill(-1),g=Array(n.length).fill(-1),_=0;for(let e=0;e<d;e++)f[e]=_,_+=i[e].length,p[e]=o[e]>0?o[e]-1:-1;m[d]=0;for(let e=d-1;e>=0;e--)m[e]=m[e+1]+i[e].length;for(let e=0;e<n.length;e++)n[e].kind===`literal`&&(h[e]=e>0?r[e-1]:-1,g[e]=e+1<n.length?r[e+1]:-1);let v=[],y=[],b=new Set;for(let e=0;e<n.length;e++){let t=n[e];if(t.kind===`literal`)v.push(t),y.push({text:t.text,offset:g[e]<0?_:f[g[e]]});else for(let e of t.chars)v.push(e),b.add(e)}return{maxLength:l,hasEscapes:u,dataSlots:[...b],literals:y,parts:v,tokens:n,runChars:i,runMin:a,runOffset:f,literalBeforeRun:p,capacityFromRun:m,runOfToken:r,runBeforeLiteral:h,runAfterLiteral:g,totalSlots:_}}var u=class{definitions=new Map(r);cache=new Map;custom;hasComposingRisk;constructor(e){this.custom=!!e&&Object.keys(e).length>0;let t=!1;for(let[n,r]of Object.entries(e??{})){if(n===`\\`||Array.from(n).length!==1)throw RangeError(`Mask token keys must be one Unicode code point other than backslash`);let e=typeof r==`object`&&`match`in r?r:{match:r};o(e.match)&&(t=!0),this.definitions.set(n,{match:i(e.match),transform:e.transform,maxLength:2})}this.hasComposingRisk=t}compile(e){let t=this.cache.get(e);if(t)return t;let n=l(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 d=new u;function f(e,t){let n=Array.isArray(e)?e:[e],r=0;for(let e of n)r=Math.max(r,t.compile(e).maxLength);return r}function p(e,t){return t?.resolveMask?1/0:f(e,t?.tokens?new u(t.tokens):d)}function m(e,t,n,r,i,a){let o=``,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)){a&&!d&&l>n&&(u=o.length+c.length),o+=c+s(g,r),c=``,m=!0,d||(l<=n?u=o.length:d=!0);break}}if(!m)break}if(d||(u=o.length),r&&c){let e=u===o.length;o+=c,e&&(u=o.length)}return{value:o,caret:u}}function h(e,t){return e.tokens[e.literalBeforeRun[t]].text}function g(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 _(e,t,n){for(let r=0;r<n.length;)if(r+=String.fromCodePoint(n.codePointAt(r)).length,r<n.length&&e.startsWith(n.slice(r),t))return n.length-r;return 0}function v(e,t,n){return e.startsWith(n,t)?n.length:_(e,t,n)}function y(e,t,n,r,i,a){let o=n.runChars.length;for(let s=0;s<2;s++)for(let c=r+1;c<o;c++){let o=h(n,c),l=s===0?e.startsWith(o,t)?o.length:0:_(e,t,o);if(l)return a&&c===r+1||g(e,t+l,i,n)<=n.capacityFromRun[c]?c:-1}return-1}function b(e,t,n,r,i){let a=t.runChars.length,o=Array(t.totalSlots).fill(``),c=Array(t.totalSlots).fill(-1),l=Array(a).fill(0),u=Array(a).fill(!1),d=Array(t.tokens.length).fill(-1),f=0,p=0,m=0,_=!1,b=t.tokens[0];for(r&&b?.kind===`literal`&&e.startsWith(b.text)&&(d[0]=0,m=b.text.length);m<e.length&&f<a;){if(r&&d[0]<0&&b?.kind===`literal`&&e.startsWith(b.text,m)){d[0]=m,m+=b.text.length;continue}let x=t.runChars[f],S=String.fromCodePoint(e.codePointAt(m)),C=x[p].match(S),w=l[f]>=t.runMin[f]&&l[f]<x.length,T=r&&(!C||t.hasEscapes)?y(e,m,t,f,n,w):-1;if(T>=0){w&&T===f+1&&(u[f]=!0),d[t.literalBeforeRun[T]]=m,m+=v(e,m,h(t,T)),f=T,p=0;continue}if(!_&&p>0&&m===i&&f+1<a&&(!C||t.runChars[f+1][0].match(S))&&e.indexOf(h(t,f+1),m)<0&&g(e,m,n,t)===t.capacityFromRun[f+1]){_=!0,f++,p=0;continue}if(C){let n=t.runOffset[f]+p;if(o[n]=s(S,x[p]),c[n]=m+S.length,l[f]=p+1,m+=S.length,p++,p===x.length&&(f++,p=0,r&&f<a)){let n=h(t,f);e.startsWith(n,m)&&(d[t.literalBeforeRun[f]]=m,m+=n.length)}continue}m+=S.length}return{slotChar:o,slotSource:c,runFilled:l,runCommitted:u,literalSource:d}}function x(e,t,n){let{tokens:r,runBeforeLiteral:i,runAfterLiteral:a,literalBeforeRun:o,runChars:s}=e,{runFilled:c,runCommitted:l,literalSource:u}=t,d=Array(r.length).fill(!1),f=c.length-1;for(;f>=0&&c[f]===0;)f--;for(let e=0;e<r.length;e++){if(r[e].kind!==`literal`)continue;let t=a[e],o=i[e],p=o<0&&f>=0&&(u[e+2]>=0||c[t+1]>0);d[e]=t>=0&&(c[t]>0||u[e]>=0&&t<f)||p||o>=0&&l[o]||n&&(o<0||c[o]===s[o].length)}let p=-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=p+1;t<e;t++){let e=o[t];e<0||r[e].text===n&&(d[e]=!0)}}p=e}return d}function S(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=o<0||i&&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 C(e,t,n,r,i,a,o){let s=b(e,t,i,a,n);return S(t,s,x(t,s,r),n,r,o)}function w(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?m(e,a,n,s,!r.resolveMask,o):C(e,a,n,s,i,!r?.resolveMask,o)}function T(e,t,n=0,r){return w(e,t,n,r,r?.tokens?new u(r.tokens):d)}let E;function D(){return E===void 0&&(E=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),E}const O=`data-masked`;function ee(e,t){e(`autocomplete`,t.autocomplete??`off`),e(`autocorrect`,t.autocorrect??`off`),e(`autocapitalize`,t.autocapitalize??`off`),e(`spellcheck`,String(t.spellcheck??!1))}function k(e){return e.getAttribute(O)!==null}function A(e){try{return e.selectionStart??e.value.length}catch{return e.value.length}}function j(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 M(e){let t=e;return()=>{let e=t;t=void 0,e?.()}}function N(e,t){return e.value===t&&e.selectionStart!==e.selectionEnd}function P(){let e=new Set;return{scheduleFrame:t=>{let n=requestAnimationFrame(()=>{e.delete(n),t()});e.add(n)},cancelPendingFrames:()=>{for(let t of e)cancelAnimationFrame(t);e.clear()}}}function te(e,t,n,r,i,a=0,o=!1){if(n<=0||a<0||a>t)return e;let s=t-a,c=s+n;if(c>r.length||r.slice(0,s)!==e.slice(0,s)||r.slice(c)!==e.slice(t))return e;let l=r.slice(c);if(!Array.from(l).some(i))return e;let u=r.slice(s,c);if(!o&&!Array.from(u).some(i))return e;let d=``;for(let e of u)i(e)||(d+=e);return d?e.slice(0,t)+d+e.slice(t):e}function ne(e){let t=[];return{setIfMissing:(n,r)=>{e.hasAttribute(n)||(e.setAttribute(n,r),t.push(n))},removeTracked:()=>{for(let n of t)e.removeAttribute(n)}}}function F(e,t,n,r,i,a){let{setIfMissing:o,removeTracked:s}=ne(e);e.setAttribute(O,t),ee(o,n),Number.isFinite(r)&&o(`maxlength`,String(r));let c=[`paste`,`input`,`compositionstart`,`compositionend`,D()?`keyup`:`keydown`];for(let t=0;t<c.length;t++)e.addEventListener(c[t],i[t]);return M(()=>{for(let t=0;t<c.length;t++)e.removeEventListener(c[t],i[t]);e.removeAttribute(O),s(),a()})}function re(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function I(e,t,n){return e===0&&t.value!==n?t.caret:e}function L(e,t,n,r){if(n.value.startsWith(e.slice(0,t)))return I(t,n,r);let i=n.value.length,a=e.length;for(;a>t&&i>0&&e[a-1]===n.value[i-1];)a--,i--;return Math.min(t,n.caret,i)}function R(e){return e?.startsWith(`delete`)&&e.endsWith(`Backward`)?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function z(e,t){return!t&&e}function B(e,t,n,r,i,a,o){return a&&i.value!==t&&i.value!==o?i.caret:e===`unidentified`?i.value.length>r?i.caret:I(n,i,o):e===`delete`?r===i.value.length?n+1:I(n,i,o):e===`backspace`?L(t,n,i,o):i.caret}function ie(e,t,n){if(k(e))return()=>{};let{onChange:r,segmented:i,eager:a,tokens:o,resolveMask:s,autocomplete:c,autocorrect:l,autocapitalize:d,spellcheck:p}=re(n),m=new u(o),h=(e,n,r=a)=>w(e,t,n,{tokens:o,resolveMask:s,segmented:i,eager:r},m),g=e=>m.isData(e),_=m.hasComposingRisk,v=s||_?1/0:f(t,m),y=!1,b=!1,x=!1,S=e.value??``,{scheduleFrame:C,cancelPendingFrames:T}=P();return F(e,Array.isArray(t)?t.join(`|`):t,{autocomplete:c,autocorrect:l,autocapitalize:d,spellcheck:p},v,[e=>{let t=e.target,n=t.value;C(()=>{if(_&&b||N(t,n))return;let e=h(t.value,A(t));t.value=e.value,j(t,e.caret),S=t.value,r?.(t.value)})},e=>{let n=e,i=e.target;if(T(),y=!1,x=!0,_&&(b||n.isComposing)||N(i,S))return;let o=A(i),c=S.length,l=R(n.inputType),u=i.value,d=l===`backspace`||l===`delete`,f=!Array.isArray(t)&&!s,p=f&&(n.inputType===`deleteContentBackward`||n.inputType===`deleteContentForward`||n.inputType===`deleteByCut`),m=f&&n.inputType===`insertText`&&typeof n.data==`string`?n.data:``,v=z(a,d),C=o-m.length,w=c-u.length+m.length,E=u;if(p||m){let e=te(u,o,w,S,g,m.length,!0);if(e!==u){let t=p&&Array.from(S.slice(C,C+w)).some(g),n=S.slice(C+w),r=0;for(;r<n.length;){let e=String.fromCodePoint(n.codePointAt(r));if(g(e))break;r+=e.length}let i=n.slice(r);(t||!h(u,o,v).value.endsWith(i))&&(E=e)}}let D=h(E,o,v);i.value=D.value,j(i,B(l,u,o,c,D,s,S)),S=i.value,r?.(i.value)},()=>{b=!0,T(),y=!1},e=>{b=!1,x=!0;let t=e.target,n=A(t),i=h(t.value,n);t.value=i.value,j(t,i.caret),S=t.value,r?.(t.value)},e=>{let t=e,n=t.target,i=n.value;if(b)return;if(D()&&x){x=!1;return}if(!t.key){y=!0,C(()=>{if(N(n,i)){y=!1;return}let e=n.selectionStart??999,t=n.value.length<i.length,r=h(n.value,e,z(a,t));n.value=r.value,j(n,r.caret),S=n.value,C(()=>{y=!1})});return}if(t.key===`Meta`)return;let o=t.key===`Backspace`,c=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>=v&&!D()){t.preventDefault();return}if(y){t.preventDefault();return}if(!o&&!c&&!l&&!u)return;let d=o?`backspace`:c?`delete`:u?`unidentified`:`insert`;C(()=>{if(N(n,i))return;let e=n.selectionStart??999,t=n.value,l=h(t,e,z(a,o||c));n.value=l.value,j(n,B(d,t,e,i.length,l,s,i)),S=n.value,r?.(n.value)})}],T)}function V(e){let t=e?.decimalPlaces,n=t!=null&&Number.isFinite(t)?Math.min(100,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 H(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function U(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 W(e,t){let n=H(e||`0`),r=t.numberPlaces==null?n:n.padStart(t.numberPlaces,`0`);return{intPart:n,paddedInt:r,groupedInt:t.segmented?U(r,t.separator):r}}function G(e){let t=e.indexOf(`e`);if(t<0)return e;let n=Number(e.slice(t+1)),r=e.slice(0,t),i=r.indexOf(`.`),a=i<0?r:r.slice(0,i)+r.slice(i+1),o=(i<0?r.length:i)+n;return o<=0?`0.`+`0`.repeat(-o)+a:o>=a.length?a+`0`.repeat(o-a.length):a.slice(0,o)+`.`+a.slice(o)}function K(t,n){if(n<=0)return 0;let r=0;for(let i=0;i<t.length;i++)if(e(t[i])&&(r++,r===n))return i+1;return t.length}function q(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 J(t,n){let r=q(t,n),i=``,a=``,o=r.sign===`-`,s=!1,c=n.decimalPlaces!==0;for(let t of r.body){if(e(t)){s?(n.decimalPlaces==null||a.length<n.decimalPlaces)&&(a+=t):(n.numberPlaces==null||i.length<n.numberPlaces)&&(i+=t);continue}if(c&&!s&&t===n.decimalSeparator){s=!0;continue}t===`-`&&n.allowNegative?o=!0:t===`+`&&n.allowNegative&&(o=!1)}return{isNegative:o,intDigits:i,fracDigits:a,hasSeparator:s}}function ae(t,n,r){let i=r.decimalPlaces!==0,a=!1,o=0;for(let s=0;s<n;s++){let n=t[s];if(e(n)){a?(r.decimalPlaces==null||o<r.decimalPlaces)&&o++:(r.numberPlaces==null||o<r.numberPlaces)&&o++;continue}i&&!a&&n===r.decimalSeparator&&(a=!0,o=0)}return{inFraction:a,digitsBefore:o}}function Y(e,t=0,n){let r=V(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=J(e,r);if(a===``&&o===``&&!s){if(i){let e=`-`+r.prefix;return{value:e,caret:e.length}}return{value:``,caret:0}}let{intPart:c,paddedInt:l,groupedInt:u}=W(a,r),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=q(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=ae(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+K(u,v+b)}}function oe(e,t){return Y(e,e.length,t).value}function X(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=J(e,V(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n&&a!==0?-a:a}function se(e,t){let n=V(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=J(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 Y(l+c+n.decimalSeparator+s,l.length+c.length,n)}function ce(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}=q(a,V(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 Z(e,t,n,r){let i=V(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=J(e.slice(0,a)+e.slice(t),i),u=H(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 Y(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function le(e,t){let n=V(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);a.indexOf(`e`)>=0&&(a=G(String(i))+(n.decimalPlaces?`.`+`0`.repeat(n.decimalPlaces):``));let o=a.indexOf(`.`),s=o===-1?a:a.slice(0,o),c=o===-1?``:a.slice(o+1),{groupedInt:l}=W(s,n),u=l+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+u+n.suffix}function ue(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function de(t,n){if(k(t))return()=>{};let{onChange:r,autocomplete:i,autocorrect:a,autocapitalize:o,spellcheck:s,...c}=ue(n),l=c,{decimalSeparator:u,decimalPlaces:d}=V(l),f=!1,p=!1,m=!1,h=null,{scheduleFrame:g,cancelPendingFrames:_}=P(),v=(e,t)=>{e.value=t.value,j(e,t.caret),r?.(t.value,X(t.value,l))},y=(t,n={})=>{let r=A(t),i=(e,n)=>{if(d===0||e.length!==1||e!==`.`&&e!==`,`||e===u)return!1;for(let i of n)if(i!=null&&i>=0&&t.value.slice(i,i+e.length)===e)return t.value=t.value.slice(0,i)+u+t.value.slice(i+e.length),r=i+e.length<=r?r+u.length-e.length:r,j(t,r),!0;return!1};if(h){let{text:e,starts:t}=h;h=null,i(e,t)}if(n.inputType===`deleteContentBackward`){let e=se(t.value,l);if(e){v(t,e);return}}let a=n.insertedText;if(a!=null&&i(a,[n.insertedAt,r-a.length]),a!=null&&a.length>0){let e=ce(t.value,r,a.length,l);e&&(t.value=e.value,r=e.caret)}let o=a!=null&&a.length===1&&e(a)?a:void 0,s=o?Z(t.value,r,o,l):null;v(t,s??Y(t.value,r,l))};return F(t,`decimal`,{autocomplete:i,autocorrect:a,autocapitalize:o,spellcheck:s},1/0,[e=>{let t=e.target;g(()=>{y(t)})},e=>{let t=e,n=e.target;_(),f=!1,h=null,m=!0,y(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},()=>{p=!0,_(),f=!1,h=null},e=>{p=!1,m=!0,y(e.target)},e=>{let t=e,n=t.target,r=A(n),i=n.value;if(p)return;if(D()&&m){m=!1;return}if(!t.key){f=!0,g(()=>{if(N(n,i)){f=!1;return}y(n),g(()=>{f=!1})});return}if(t.key===`Meta`)return;if(f){t.preventDefault();return}let a=t.key===`Backspace`,o=t.key===`Delete`,s=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,c=t.key===`Unidentified`;s&&d!==0&&(t.key===`.`||t.key===`,`)&&t.key!==u&&(h={text:t.key,starts:[r,r-t.key.length]}),!(!a&&!o&&!s&&!c)&&g(()=>{N(n,i)||y(n,{insertedText:s?t.key:null,insertedAt:s?r:void 0,inputType:a?`deleteContentBackward`:o?`deleteContentForward`:void 0})})}],_)}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=T(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 fe(e,t,n){return $(e,t,0,n).process()}exports.Mask=Q,exports.applyDecimalMask=Y,exports.applyMask=T,exports.bind=ie,exports.bindDecimal=de,exports.buildMask=$,exports.formatDecimalValue=le,exports.getMaxLength=p,exports.process=fe,exports.processDecimal=oe,exports.unmaskDecimal=X;
2
2
  //# sourceMappingURL=mother-mask.cjs.map