mother-mask 3.16.0 → 3.18.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 +24 -0
- package/dist/mother-mask.cjs +1 -1
- package/dist/mother-mask.cjs.map +1 -1
- package/dist/mother-mask.d.cts +10 -0
- package/dist/mother-mask.d.mts +10 -0
- package/dist/mother-mask.mjs +1 -1
- package/dist/mother-mask.mjs.map +1 -1
- package/dist/mother-mask.umd.js +1 -1
- package/dist/mother-mask.umd.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -292,6 +292,30 @@ bind(input, '999.999.999-99')
|
|
|
292
292
|
|
|
293
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.
|
|
294
294
|
|
|
295
|
+
Deleting a selection can take a whole field *and* the separator introducing
|
|
296
|
+
the next one with it — selecting `"(11) "` out of `"(11) 98765-4321"` and
|
|
297
|
+
pressing Backspace/Delete/Cut removes the area code, its closing paren, and
|
|
298
|
+
the space in one stroke. `bind()` restores that separator before masking, so
|
|
299
|
+
the untouched `"98765-4321"` stays exactly where it was instead of sliding
|
|
300
|
+
into the emptied field:
|
|
301
|
+
|
|
302
|
+
```ts
|
|
303
|
+
bind(input, '(99) 99999-9999')
|
|
304
|
+
// "(11) 98765-4321" — select "(11) ", press Backspace
|
|
305
|
+
// → "(|) 98765-4321" "98765" and "4321" never moved
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
This is bind-only, like eager's Backspace/Delete handling above: pure
|
|
309
|
+
`applyMask`/`buildMask`/`process` see only the resulting `(value, caret)` and
|
|
310
|
+
can't tell a deletion from fresh input, so `applyMask("98765-4321", mask, 0)`
|
|
311
|
+
still packs from the left. A selection confined to separator text (no field
|
|
312
|
+
data in it) is left alone, however wide — that is ordinary divider erosion,
|
|
313
|
+
not a swallow, and keeps working exactly as above. Word/line deletes
|
|
314
|
+
(`Cmd+Backspace`/`Cmd+Delete` and friends) are a deliberate bulk clear and are
|
|
315
|
+
never rescued, and neither are ordered mask arrays or `resolveMask`, since
|
|
316
|
+
which pattern or layout applies can itself change once the deletion shrinks
|
|
317
|
+
the data.
|
|
318
|
+
|
|
295
319
|
For classic reflow behavior, pass `segmented: false`:
|
|
296
320
|
|
|
297
321
|
```ts
|
package/dist/mother-mask.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e){return e>=`0`&&e<=`9`}function t(e){return e>=`a`&&e<=`z`||e>=`A`&&e<=`Z`}function n(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,n]of Object.entries(e??{})){if(t===`\\`||Array.from(t).length!==1)throw RangeError(`Mask token keys must be one Unicode code point other than backslash`);let e=typeof n==`object`&&`match`in n?n:{match:n};this.definitions.set(t,{match:i(e.match),transform:e.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){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 m(e,t,n){return e.startsWith(n,t)?n.length:p(e,t,n)}function h(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=d(n,s),a=o===0?e.startsWith(r,t)?r.length:0:p(e,t,r);if(a)return f(e,t+a,i,n)<=n.capacityFromRun[s]?s:-1}return-1}function g(e,t,n,r,i){let o=t.runChars.length,s=Array(t.totalSlots).fill(``),c=Array(t.totalSlots).fill(-1),l=Array(o).fill(0),u=Array(t.tokens.length).fill(-1),p=0,g=0,_=0,v=!1,y=t.tokens[0];for(r&&y?.kind===`literal`&&e.startsWith(y.text)&&(u[0]=0,_=y.text.length);_<e.length&&p<o;){if(r&&u[0]<0&&y?.kind===`literal`&&e.startsWith(y.text,_)){u[0]=_,_+=y.text.length;continue}let b=t.runChars[p],x=String.fromCodePoint(e.codePointAt(_)),S=b[g].match(x),C=r&&(!S||t.hasEscapes)?h(e,_,t,p,n):-1;if(C>=0){u[t.literalBeforeRun[C]]=_,_+=m(e,_,d(t,C)),p=C,g=0;continue}if(!v&&g>0&&_===i&&p+1<o&&e.indexOf(d(t,p+1),_)<0&&f(e,_,n,t)===t.capacityFromRun[p+1]){v=!0,p++,g=0;continue}if(S){let n=t.runOffset[p]+g;if(s[n]=a(x,b[g]),c[n]=_+x.length,l[p]=g+1,_+=x.length,g++,g===b.length&&(p++,g=0,r&&p<o)){let n=d(t,p);e.startsWith(n,_)&&(u[t.literalBeforeRun[p]]=_,_+=n.length)}continue}_+=x.length}return{slotChar:s,slotSource:c,runFilled:l,literalSource:u}}function _(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 v(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 y(e,t,n,r,i,a,o){let s=g(e,t,i,a,n);return v(t,s,_(t,s,r),n,r,o)}function b(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):y(e,a,n,s,i,!r?.resolveMask,o)}function x(e,t,n=0,r){return b(e,t,n,r,r?.tokens?new s(r.tokens):c)}const S=`data-masked`;function C(e){return e.getAttribute(S)!==null}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){let t=e;return()=>{let e=t;t=void 0,e?.()}}function D(e,t){return e.value===t&&e.selectionStart!==e.selectionEnd}function O(){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 k(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)}}}let A;function j(){return A===void 0&&(A=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),A}function M(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function N(e,t,n){return e===0&&t.value!==n?t.caret:e}function P(e,t,n,r){if(n.value.startsWith(e.slice(0,t)))return N(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 F(e){return e?.startsWith(`delete`)&&e.endsWith(`Backward`)?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function I(e,t){return!t&&e}function L(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:N(n,i,o):e===`delete`?r===i.value.length?n+1:N(n,i,o):e===`backspace`?P(t,n,i,o):i.caret}function R(e,t,n){if(C(e))return()=>{};let{onChange:r,segmented:i,eager:a,tokens:o,resolveMask:c}=M(n),u=new s(o),d=(e,n,r=a)=>b(e,t,n,{tokens:o,resolveMask:c,segmented:i,eager:r},u),f=!!o&&Object.keys(o).length>0,{setIfMissing:p,removeTracked:m}=k(e),h=c||f?1/0:l(t);e.setAttribute(S,Array.isArray(t)?t.join(`|`):t),p(`autocomplete`,`off`),p(`autocorrect`,`off`),p(`autocapitalize`,`off`),p(`spellcheck`,`false`),Number.isFinite(h)&&p(`maxlength`,String(h));let g=!1,_=!1,v=!1,y=e.value??``,x=j()?`keyup`:`keydown`,{scheduleFrame:A,cancelPendingFrames:N}=O(),P=e=>{let t=e.target,n=t.value;A(()=>{if(f&&_||D(t,n))return;let e=d(t.value,w(t));t.value=e.value,T(t,e.caret),y=t.value,r?.(t.value)})},R=e=>{let t=e,n=e.target;if(N(),g=!1,v=!0,f&&(_||t.isComposing)||D(n,y))return;let i=w(n),o=y.length,s=F(t.inputType),l=n.value,u=d(l,i,I(a,s===`backspace`||s===`delete`));n.value=u.value,T(n,L(s,l,i,o,u,c,y)),y=n.value,r?.(n.value)},z=()=>{_=!0,N(),g=!1},B=e=>{_=!1,v=!0;let t=e.target,n=w(t),i=d(t.value,n);t.value=i.value,T(t,i.caret),y=t.value,r?.(t.value)},V=e=>{let t=e,n=t.target,i=n.value;if(_)return;if(x===`keyup`&&v){v=!1;return}if(!t.key){g=!0,A(()=>{if(D(n,i)){g=!1;return}let e=n.selectionStart??999,t=n.value.length<i.length,r=d(n.value,e,I(a,t));n.value=r.value,T(n,r.caret),y=n.value,A(()=>{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&&!j()){t.preventDefault();return}if(g){t.preventDefault();return}if(!o&&!s&&!l&&!u)return;let f=o?`backspace`:s?`delete`:u?`unidentified`:`insert`;A(()=>{if(D(n,i))return;let e=n.selectionStart??999,t=n.value,l=d(t,e,I(a,o||s));n.value=l.value,T(n,L(f,t,e,i.length,l,c,i)),y=n.value,r?.(n.value)})};return e.addEventListener(`paste`,P),e.addEventListener(`input`,R),e.addEventListener(`compositionstart`,z),e.addEventListener(`compositionend`,B),e.addEventListener(x,V),E(()=>{e.removeEventListener(`paste`,P),e.removeEventListener(`input`,R),e.removeEventListener(`compositionstart`,z),e.removeEventListener(`compositionend`,B),e.removeEventListener(x,V),e.removeAttribute(S),m(),N()})}function z(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 B(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function V(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 H(e,t){let n=B(e||`0`),r=t.numberPlaces==null?n:n.padStart(t.numberPlaces,`0`);return{intPart:n,paddedInt:r,groupedInt:t.segmented?V(r,t.separator):r}}function U(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 W(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 G(t,n){let r=W(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)}return{isNegative:o,intDigits:i,fracDigits:a,hasSeparator:s}}function K(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 q(e,t=0,n){let r=z(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=G(e,r);if(a===``&&o===``&&!s)return{value:``,caret:0};let{intPart:c,paddedInt:l,groupedInt:u}=H(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=W(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=K(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+U(u,v+b)}}function J(e,t){return q(e,e.length,t).value}function Y(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=G(e,z(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n?-a:a}function X(e,t){let n=z(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=G(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 q(l+c+n.decimalSeparator+s,l.length+c.length,n)}function Z(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}=W(a,z(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 ee(e,t,n,r){let i=z(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=G(e.slice(0,a)+e.slice(t),i),u=B(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 q(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function te(e,t){let n=z(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),{groupedInt:l}=H(s,n),u=l+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+u+n.suffix}function ne(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function re(e){return e.length===1&&e>=`0`&&e<=`9`}function ie(e,t){if(C(e))return()=>{};let{onChange:n,...r}=ne(t),i=r,{decimalSeparator:a,decimalPlaces:o}=z(i),{setIfMissing:s,removeTracked:c}=k(e);e.setAttribute(S,`decimal`),s(`autocomplete`,`off`),s(`autocorrect`,`off`),s(`autocapitalize`,`off`),s(`spellcheck`,`false`);let l=!1,u=!1,d=!1,f=null,p=j()?`keyup`:`keydown`,{scheduleFrame:m,cancelPendingFrames:h}=O(),g=(e,t)=>{e.value=t.value,T(e,t.caret),n?.(t.value,Y(t.value,i))},_=(e,t={})=>{let n=w(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,T(e,n),!0;return!1};if(f){let{text:e,starts:t}=f;f=null,r(e,t)}if(t.inputType===`deleteContentBackward`){let t=X(e.value,i);if(t){g(e,t);return}}let s=t.insertedText;if(s!=null&&r(s,[t.insertedAt,n-s.length]),s!=null&&s.length>0){let t=Z(e.value,n,s.length,i);t&&(e.value=t.value,n=t.caret)}let c=s!=null&&s.length===1&&re(s)?s:void 0,l=c?ee(e.value,n,c,i):null;g(e,l??q(e.value,n,i))},v=e=>{let t=e.target;m(()=>{_(t)})},y=e=>{let t=e,n=e.target;h(),l=!1,f=null,d=!0,_(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},b=()=>{u=!0,h(),l=!1,f=null},x=e=>{u=!1,d=!0,_(e.target)},A=e=>{let t=e,n=t.target,r=w(n),i=n.value;if(u)return;if(p===`keyup`&&d){d=!1;return}if(!t.key){l=!0,m(()=>{if(D(n,i)){l=!1;return}_(n),m(()=>{l=!1})});return}if(t.key===`Meta`)return;if(l){t.preventDefault();return}let s=t.key===`Backspace`,c=t.key===`Delete`,h=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,g=t.key===`Unidentified`;h&&o!==0&&(t.key===`.`||t.key===`,`)&&t.key!==a&&(f={text:t.key,starts:[r,r-t.key.length]}),!(!s&&!c&&!h&&!g)&&m(()=>{D(n,i)||_(n,{insertedText:h?t.key:null,insertedAt:h?r:void 0,inputType:s?`deleteContentBackward`:c?`deleteContentForward`:void 0})})};return e.addEventListener(`paste`,v),e.addEventListener(`input`,y),e.addEventListener(`compositionstart`,b),e.addEventListener(`compositionend`,x),e.addEventListener(p,A),E(()=>{e.removeEventListener(`paste`,v),e.removeEventListener(`input`,y),e.removeEventListener(`compositionstart`,b),e.removeEventListener(`compositionend`,x),e.removeEventListener(p,A),e.removeAttribute(S),c(),h()})}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=x(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 ae(e,t,n){return $(e,t,0,n).process()}exports.Mask=Q,exports.applyDecimalMask=q,exports.applyMask=x,exports.bind=R,exports.bindDecimal=ie,exports.buildMask=$,exports.formatDecimalValue=te,exports.getMaxLength=l,exports.process=ae,exports.processDecimal=J,exports.unmaskDecimal=Y;
|
|
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,n]of Object.entries(e??{})){if(t===`\\`||Array.from(t).length!==1)throw RangeError(`Mask token keys must be one Unicode code point other than backslash`);let e=typeof n==`object`&&`match`in n?n:{match:n};this.definitions.set(t,{match:i(e.match),transform:e.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){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 m(e,t,n){return e.startsWith(n,t)?n.length:p(e,t,n)}function h(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=d(n,s),a=o===0?e.startsWith(r,t)?r.length:0:p(e,t,r);if(a)return f(e,t+a,i,n)<=n.capacityFromRun[s]?s:-1}return-1}function g(e,t,n,r,i){let o=t.runChars.length,s=Array(t.totalSlots).fill(``),c=Array(t.totalSlots).fill(-1),l=Array(o).fill(0),u=Array(t.tokens.length).fill(-1),p=0,g=0,_=0,v=!1,y=t.tokens[0];for(r&&y?.kind===`literal`&&e.startsWith(y.text)&&(u[0]=0,_=y.text.length);_<e.length&&p<o;){if(r&&u[0]<0&&y?.kind===`literal`&&e.startsWith(y.text,_)){u[0]=_,_+=y.text.length;continue}let b=t.runChars[p],x=String.fromCodePoint(e.codePointAt(_)),S=b[g].match(x),C=r&&(!S||t.hasEscapes)?h(e,_,t,p,n):-1;if(C>=0){u[t.literalBeforeRun[C]]=_,_+=m(e,_,d(t,C)),p=C,g=0;continue}if(!v&&g>0&&_===i&&p+1<o&&e.indexOf(d(t,p+1),_)<0&&f(e,_,n,t)===t.capacityFromRun[p+1]){v=!0,p++,g=0;continue}if(S){let n=t.runOffset[p]+g;if(s[n]=a(x,b[g]),c[n]=_+x.length,l[p]=g+1,_+=x.length,g++,g===b.length&&(p++,g=0,r&&p<o)){let n=d(t,p);e.startsWith(n,_)&&(u[t.literalBeforeRun[p]]=_,_+=n.length)}continue}_+=x.length}return{slotChar:s,slotSource:c,runFilled:l,literalSource:u}}function _(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 v(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 y(e,t,n,r,i,a,o){let s=g(e,t,i,a,n);return v(t,s,_(t,s,r),n,r,o)}function b(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):y(e,a,n,s,i,!r?.resolveMask,o)}function x(e,t,n=0,r){return b(e,t,n,r,r?.tokens?new s(r.tokens):c)}const S=`data-masked`;function C(e){return e.getAttribute(S)!==null}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){let t=e;return()=>{let e=t;t=void 0,e?.()}}function D(e,t){return e.value===t&&e.selectionStart!==e.selectionEnd}function O(){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 k(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 A(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)}}}let j;function M(){return j===void 0&&(j=typeof navigator<`u`&&/iPad|iPhone|iPod/i.test(navigator.userAgent)),j}function N(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function P(e,t,n){return e===0&&t.value!==n?t.caret:e}function F(e,t,n,r){if(n.value.startsWith(e.slice(0,t)))return P(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 I(e){return e?.startsWith(`delete`)&&e.endsWith(`Backward`)?`backspace`:e===`deleteContentForward`?`delete`:e&&e.startsWith(`insert`)?`insert`:`unidentified`}function L(e,t){return!t&&e}function R(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:P(n,i,o):e===`delete`?r===i.value.length?n+1:P(n,i,o):e===`backspace`?F(t,n,i,o):i.caret}function z(e,t,n){if(C(e))return()=>{};let{onChange:r,segmented:i,eager:a,tokens:o,resolveMask:c}=N(n),u=new s(o),d=(e,n,r=a)=>b(e,t,n,{tokens:o,resolveMask:c,segmented:i,eager:r},u),f=e=>u.isData(e),p=!!o&&Object.keys(o).length>0,{setIfMissing:m,removeTracked:h}=A(e),g=c||p?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(g)&&m(`maxlength`,String(g));let _=!1,v=!1,y=!1,x=e.value??``,j=M()?`keyup`:`keydown`,{scheduleFrame:P,cancelPendingFrames:F}=O(),z=e=>{let t=e.target,n=t.value;P(()=>{if(p&&v||D(t,n))return;let e=d(t.value,w(t));t.value=e.value,T(t,e.caret),x=t.value,r?.(t.value)})},B=e=>{let n=e,i=e.target;if(F(),_=!1,y=!0,p&&(v||n.isComposing)||D(i,x))return;let o=w(i),s=x.length,l=I(n.inputType),u=i.value,m=l===`backspace`||l===`delete`,h=!Array.isArray(t)&&!c&&(n.inputType===`deleteContentBackward`||n.inputType===`deleteContentForward`||n.inputType===`deleteByCut`)?k(u,o,s-u.length,x,f):u,g=d(h,o,L(a,m));i.value=g.value,T(i,R(l,u,o,s,g,c,x)),x=i.value,r?.(i.value)},V=()=>{v=!0,F(),_=!1},H=e=>{v=!1,y=!0;let t=e.target,n=w(t),i=d(t.value,n);t.value=i.value,T(t,i.caret),x=t.value,r?.(t.value)},U=e=>{let t=e,n=t.target,i=n.value;if(v)return;if(j===`keyup`&&y){y=!1;return}if(!t.key){_=!0,P(()=>{if(D(n,i)){_=!1;return}let e=n.selectionStart??999,t=n.value.length<i.length,r=d(n.value,e,L(a,t));n.value=r.value,T(n,r.caret),x=n.value,P(()=>{_=!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>=g&&!M()){t.preventDefault();return}if(_){t.preventDefault();return}if(!o&&!s&&!l&&!u)return;let f=o?`backspace`:s?`delete`:u?`unidentified`:`insert`;P(()=>{if(D(n,i))return;let e=n.selectionStart??999,t=n.value,l=d(t,e,L(a,o||s));n.value=l.value,T(n,R(f,t,e,i.length,l,c,i)),x=n.value,r?.(n.value)})};return e.addEventListener(`paste`,z),e.addEventListener(`input`,B),e.addEventListener(`compositionstart`,V),e.addEventListener(`compositionend`,H),e.addEventListener(j,U),E(()=>{e.removeEventListener(`paste`,z),e.removeEventListener(`input`,B),e.removeEventListener(`compositionstart`,V),e.removeEventListener(`compositionend`,H),e.removeEventListener(j,U),e.removeAttribute(S),h(),F()})}function B(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 V(e){let t=0;for(;t<e.length-1&&e[t]===`0`;)t++;return e.slice(t)}function H(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 U(e,t){let n=V(e||`0`),r=t.numberPlaces==null?n:n.padStart(t.numberPlaces,`0`);return{intPart:n,paddedInt:r,groupedInt:t.segmented?H(r,t.separator):r}}function W(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 G(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 K(t,n){let r=G(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)}return{isNegative:o,intDigits:i,fracDigits:a,hasSeparator:s}}function q(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 J(e,t=0,n){let r=B(n);if(!e)return{value:``,caret:0};let{isNegative:i,intDigits:a,fracDigits:o,hasSeparator:s}=K(e,r);if(a===``&&o===``&&!s)return{value:``,caret:0};let{intPart:c,paddedInt:l,groupedInt:u}=U(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=G(e,r),g=Math.max(0,Math.min(t-h.bodyStart,h.body.length)),{inFraction:_,digitsBefore:v}=q(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+W(u,v+b)}}function Y(e,t){return J(e,e.length,t).value}function X(e,t){let{isNegative:n,intDigits:r,fracDigits:i}=K(e,B(t)),a=Number(i?`${r||`0`}.${i}`:r||`0`);return n?-a:a}function Z(e,t){let n=B(t);if(n.decimalPlaces==null||n.decimalPlaces<=0)return null;let{isNegative:r,intDigits:i,hasSeparator:a}=K(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 J(l+c+n.decimalSeparator+s,l.length+c.length,n)}function ee(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}=G(a,B(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 te(e,t,n,r){let i=B(r),a=t-1;if(a<0||e[a]!==n)return null;let{isNegative:o,intDigits:s,fracDigits:c,hasSeparator:l}=K(e.slice(0,a)+e.slice(t),i),u=V(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 J(m+h+(l?i.decimalSeparator+c:``),m.length+h.length,i)}function ne(e,t){let n=B(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),{groupedInt:l}=U(s,n),u=l+(n.decimalPlaces!==0&&c!==``?n.decimalSeparator+c:``);return(r?`-`:``)+n.prefix+u+n.suffix}function re(e){return e==null?{}:typeof e==`function`?{onChange:e}:e}function ie(e){return e.length===1&&e>=`0`&&e<=`9`}function ae(e,t){if(C(e))return()=>{};let{onChange:n,...r}=re(t),i=r,{decimalSeparator:a,decimalPlaces:o}=B(i),{setIfMissing:s,removeTracked:c}=A(e);e.setAttribute(S,`decimal`),s(`autocomplete`,`off`),s(`autocorrect`,`off`),s(`autocapitalize`,`off`),s(`spellcheck`,`false`);let l=!1,u=!1,d=!1,f=null,p=M()?`keyup`:`keydown`,{scheduleFrame:m,cancelPendingFrames:h}=O(),g=(e,t)=>{e.value=t.value,T(e,t.caret),n?.(t.value,X(t.value,i))},_=(e,t={})=>{let n=w(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,T(e,n),!0;return!1};if(f){let{text:e,starts:t}=f;f=null,r(e,t)}if(t.inputType===`deleteContentBackward`){let t=Z(e.value,i);if(t){g(e,t);return}}let s=t.insertedText;if(s!=null&&r(s,[t.insertedAt,n-s.length]),s!=null&&s.length>0){let t=ee(e.value,n,s.length,i);t&&(e.value=t.value,n=t.caret)}let c=s!=null&&s.length===1&&ie(s)?s:void 0,l=c?te(e.value,n,c,i):null;g(e,l??J(e.value,n,i))},v=e=>{let t=e.target;m(()=>{_(t)})},y=e=>{let t=e,n=e.target;h(),l=!1,f=null,d=!0,_(n,{insertedText:typeof t.data==`string`?t.data:null,inputType:t.inputType})},b=()=>{u=!0,h(),l=!1,f=null},x=e=>{u=!1,d=!0,_(e.target)},k=e=>{let t=e,n=t.target,r=w(n),i=n.value;if(u)return;if(p===`keyup`&&d){d=!1;return}if(!t.key){l=!0,m(()=>{if(D(n,i)){l=!1;return}_(n),m(()=>{l=!1})});return}if(t.key===`Meta`)return;if(l){t.preventDefault();return}let s=t.key===`Backspace`,c=t.key===`Delete`,h=t.key.length===1&&!t.ctrlKey&&!t.altKey&&!t.metaKey,g=t.key===`Unidentified`;h&&o!==0&&(t.key===`.`||t.key===`,`)&&t.key!==a&&(f={text:t.key,starts:[r,r-t.key.length]}),!(!s&&!c&&!h&&!g)&&m(()=>{D(n,i)||_(n,{insertedText:h?t.key:null,insertedAt:h?r:void 0,inputType:s?`deleteContentBackward`:c?`deleteContentForward`:void 0})})};return e.addEventListener(`paste`,v),e.addEventListener(`input`,y),e.addEventListener(`compositionstart`,b),e.addEventListener(`compositionend`,x),e.addEventListener(p,k),E(()=>{e.removeEventListener(`paste`,v),e.removeEventListener(`input`,y),e.removeEventListener(`compositionstart`,b),e.removeEventListener(`compositionend`,x),e.removeEventListener(p,k),e.removeAttribute(S),c(),h()})}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=x(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 oe(e,t,n){return $(e,t,0,n).process()}exports.Mask=Q,exports.applyDecimalMask=J,exports.applyMask=x,exports.bind=z,exports.bindDecimal=ae,exports.buildMask=$,exports.formatDecimalValue=ne,exports.getMaxLength=l,exports.process=oe,exports.processDecimal=Y,exports.unmaskDecimal=X;
|
|
2
2
|
//# sourceMappingURL=mother-mask.cjs.map
|