Comparing version 3.0.0 to 3.0.1
@@ -1,2 +0,2 @@ | ||
/*! maska v3.0.0 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u.Maska={}))})(this,function(u){"use strict";var j=Object.defineProperty;var V=(u,p,M)=>p in u?j(u,p,{enumerable:!0,configurable:!0,writable:!0,value:M}):u[p]=M;var v=(u,p,M)=>V(u,typeof p!="symbol"?p+"":p,M);const p={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},M=(a,s,e)=>a.replaceAll(s,"").replace(e,".").replace("..",".").replace(/[^.\d]/g,""),P=(a,s,e)=>{var t;return new Intl.NumberFormat(((t=e.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:a,maximumFractionDigits:s,roundingMode:"trunc"})},L=(a,s=!0,e)=>{var b,N,A,g;const t=((b=e.number)==null?void 0:b.unsigned)==null&&a.startsWith("-")?"-":"",n=((N=e.number)==null?void 0:N.fraction)??0;let o=P(0,n,e);const h=o.formatToParts(1000.12),m=((A=h.find(i=>i.type==="group"))==null?void 0:A.value)??" ",l=((g=h.find(i=>i.type==="decimal"))==null?void 0:g.value)??".",r=M(a,m,l);if(r===""||Number.isNaN(r))return t;const f=r.split(".");if(f[1]!=null&&f[1].length>=1){const i=f[1].length<=n?f[1].length:n;o=P(i,n,e)}let c=o.format(parseFloat(r));return s?n>0&&r.endsWith(".")&&!r.slice(0,-1).includes(".")&&(c+=l):c=M(c,m,l),t+c};class T{constructor(s={}){v(this,"opts",{});v(this,"memo",new Map);const e={...s};if(e.tokens!=null){e.tokens=e.tokensReplace?{...e.tokens}:{...p,...e.tokens};for(const t of Object.values(e.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else e.tokens=p;Array.isArray(e.mask)&&(e.mask.length>1?e.mask=[...e.mask].sort((t,n)=>t.length-n.length):e.mask=e.mask[0]??""),e.mask===""&&(e.mask=null),this.opts=e}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const e=this.findMask(s);if(this.opts.mask==null||e==null)return!1;const t=this.process(s,e).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=e.length}findMask(s){const e=this.opts.mask;if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="function")return e(s);const t=this.process(s,e.slice(-1).pop()??"",!1);return e.find(n=>this.process(s,n,!1).length>=t.length)??""}escapeMask(s){const e=[],t=[];return s.split("").forEach((n,o)=>{n==="!"&&s[o-1]!=="!"?t.push(o-t.length):e.push(n)}),{mask:e.join(""),escaped:t}}process(s,e,t=!0){if(this.opts.number!=null)return L(s,t,this.opts);if(e==null)return s;const n=`v=${s},mr=${e},m=${t?1:0}`;if(this.memo.has(n))return this.memo.get(n);const{mask:o,escaped:h}=this.escapeMask(e),m=[],l=this.opts.tokens!=null?this.opts.tokens:{},r=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",c=this.isReversed()?0:o.length-1,b=this.isReversed()?()=>i>-1&&d>-1:()=>i<o.length&&d<s.length,N=y=>!this.isReversed()&&y<=c||this.isReversed()&&y>=c;let A,g=-1,i=this.isReversed()?o.length-1:0,d=this.isReversed()?s.length-1:0,R=!1;for(;b();){const y=o.charAt(i),k=l[y],w=(k==null?void 0:k.transform)!=null?k.transform(s.charAt(d)):s.charAt(d);if(!h.includes(i)&&k!=null?(w.match(k.pattern)!=null?(m[f](w),k.repeated?(g===-1?g=i:i===c&&i!==g&&(i=g-r),c===g&&(i-=r)):k.multiple&&(R=!0,i-=r),i+=r):k.multiple?R&&(i+=r,d-=r,R=!1):w===A?A=void 0:k.optional&&(i+=r,d-=r),d+=r):(t&&!this.isEager()&&m[f](y),w===y&&!this.isEager()?d+=r:A=y,this.isEager()||(i+=r)),this.isEager())for(;N(i)&&(l[o.charAt(i)]==null||h.includes(i));){if(t){if(m[f](o.charAt(i)),s.charAt(d)===o.charAt(i)){i+=r,d+=r;continue}}else o.charAt(i)===s.charAt(d)&&(d+=r);i+=r}}return this.memo.set(n,m.join("")),this.memo.get(n)}}const C=a=>JSON.parse(a.replaceAll("'",'"')),W=(a,s={})=>{const e={...s};a.dataset.maska!=null&&a.dataset.maska!==""&&(e.mask=x(a.dataset.maska)),a.dataset.maskaEager!=null&&(e.eager=E(a.dataset.maskaEager)),a.dataset.maskaReversed!=null&&(e.reversed=E(a.dataset.maskaReversed)),a.dataset.maskaTokensReplace!=null&&(e.tokensReplace=E(a.dataset.maskaTokensReplace)),a.dataset.maskaTokens!=null&&(e.tokens=O(a.dataset.maskaTokens));const t={};return a.dataset.maskaNumberLocale!=null&&(t.locale=a.dataset.maskaNumberLocale),a.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(a.dataset.maskaNumberFraction)),a.dataset.maskaNumberUnsigned!=null&&(t.unsigned=E(a.dataset.maskaNumberUnsigned)),(a.dataset.maskaNumber!=null||Object.values(t).length>0)&&(e.number=t),e},E=a=>a!==""?!!JSON.parse(a):!0,x=a=>a.startsWith("[")&&a.endsWith("]")?C(a):a,O=a=>{if(a.startsWith("{")&&a.endsWith("}"))return C(a);const s={};return a.split("|").forEach(e=>{const t=e.split(":");s[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),s};class S{constructor(s,e={}){v(this,"items",new Map);v(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input")return;const e=s.target,t=this.items.get(e),n="inputType"in s&&s.inputType.startsWith("delete"),o=t.isEager(),h=n&&o&&t.unmasked(e.value)===""?"":e.value;this.fixCursor(e,n,()=>this.setValue(e,h))});this.options=e,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const e=this.getOptions(this.options);for(const t of s){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const n=new T(W(t,e));this.items.set(t,n),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&n.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:e,preProcess:t,postProcess:n,...o}=s;return o}fixCursor(s,e,t){const n=s.selectionStart,o=s.value;if(t(),n===null||n===o.length&&!e)return;const h=s.value,m=o.slice(0,n),l=h.slice(0,n),r=this.processInput(s,m).unmasked,f=this.processInput(s,l).unmasked;let c=n;m!==l&&(c+=e?h.length-o.length:r.length-f.length),s.setSelectionRange(c,c)}setValue(s,e){const t=this.processInput(s,e);s.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(n=>n(t)):this.options.onMaska(t)),s.dispatchEvent(new CustomEvent("maska",{detail:t})),s.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(s,e){const t=this.items.get(s);let n=e??s.value;this.options.preProcess!=null&&(n=this.options.preProcess(n));let o=t.masked(n);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:t.unmasked(n),completed:t.completed(n)}}}const I=new WeakMap,F=a=>{a.directive("maska",(s,e,t)=>{const n=s instanceof HTMLInputElement?s:s.querySelector("input");if(n==null||(n==null?void 0:n.type)==="file")return;let o={};const h=e.expression!==""?t.evaluateLater(e.expression):()=>{};t.effect(()=>{var m;if(h(l=>{o=typeof l=="string"?{mask:l}:{...l}}),e.value!=null){const l=r=>{const f=e.modifiers.includes("unmasked")?r.unmasked:e.modifiers.includes("completed")?r.completed:r.masked,c=t.Alpine.$data(n);e.value in c&&(c[e.value]=f)};o.onMaska=o.onMaska==null?l:Array.isArray(o.onMaska)?[...o.onMaska,l]:[o.onMaska,l]}I.has(n)?(m=I.get(n))==null||m.update(o):I.set(n,new S(n,o))})}).before("model")};document.addEventListener("alpine:init",()=>{window.Alpine.plugin(F)}),u.Mask=T,u.MaskInput=S,u.tokens=p,u.xMaska=F,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}); | ||
/*! maska v3.0.1 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(u,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(u=typeof globalThis<"u"?globalThis:u||self,p(u.Maska={}))})(this,function(u){"use strict";var j=Object.defineProperty;var V=(u,p,M)=>p in u?j(u,p,{enumerable:!0,configurable:!0,writable:!0,value:M}):u[p]=M;var v=(u,p,M)=>V(u,typeof p!="symbol"?p+"":p,M);const p={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},M=(a,s,e)=>a.replaceAll(s,"").replace(e,".").replace("..",".").replace(/[^.\d]/g,""),T=(a,s,e)=>{var t;return new Intl.NumberFormat(((t=e.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:a,maximumFractionDigits:s,roundingMode:"trunc"})},L=(a,s=!0,e)=>{var b,N,A,g;const t=((b=e.number)==null?void 0:b.unsigned)==null&&a.startsWith("-")?"-":"",n=((N=e.number)==null?void 0:N.fraction)??0;let o=T(0,n,e);const h=o.formatToParts(1000.12),m=((A=h.find(i=>i.type==="group"))==null?void 0:A.value)??" ",l=((g=h.find(i=>i.type==="decimal"))==null?void 0:g.value)??".",r=M(a,m,l);if(r===""||Number.isNaN(r))return t;const f=r.split(".");if(f[1]!=null&&f[1].length>=1){const i=f[1].length<=n?f[1].length:n;o=T(i,n,e)}let c=o.format(parseFloat(r));return s?n>0&&r.endsWith(".")&&!r.slice(0,-1).includes(".")&&(c+=l):c=M(c,m,l),t+c};class P{constructor(s={}){v(this,"opts",{});v(this,"memo",new Map);const e={...s};if(e.tokens!=null){e.tokens=e.tokensReplace?{...e.tokens}:{...p,...e.tokens};for(const t of Object.values(e.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else e.tokens=p;Array.isArray(e.mask)&&(e.mask.length>1?e.mask=[...e.mask].sort((t,n)=>t.length-n.length):e.mask=e.mask[0]??""),e.mask===""&&(e.mask=null),this.opts=e}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const e=this.findMask(s);if(this.opts.mask==null||e==null)return!1;const t=this.process(s,e).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=e.length}findMask(s){const e=this.opts.mask;if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="function")return e(s);const t=this.process(s,e.slice(-1).pop()??"",!1);return e.find(n=>this.process(s,n,!1).length>=t.length)??""}escapeMask(s){const e=[],t=[];return s.split("").forEach((n,o)=>{n==="!"&&s[o-1]!=="!"?t.push(o-t.length):e.push(n)}),{mask:e.join(""),escaped:t}}process(s,e,t=!0){if(this.opts.number!=null)return L(s,t,this.opts);if(e==null)return s;const n=`v=${s},mr=${e},m=${t?1:0}`;if(this.memo.has(n))return this.memo.get(n);const{mask:o,escaped:h}=this.escapeMask(e),m=[],l=this.opts.tokens!=null?this.opts.tokens:{},r=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",c=this.isReversed()?0:o.length-1,b=this.isReversed()?()=>i>-1&&d>-1:()=>i<o.length&&d<s.length,N=y=>!this.isReversed()&&y<=c||this.isReversed()&&y>=c;let A,g=-1,i=this.isReversed()?o.length-1:0,d=this.isReversed()?s.length-1:0,R=!1;for(;b();){const y=o.charAt(i),k=l[y],w=(k==null?void 0:k.transform)!=null?k.transform(s.charAt(d)):s.charAt(d);if(!h.includes(i)&&k!=null?(w.match(k.pattern)!=null?(m[f](w),k.repeated?(g===-1?g=i:i===c&&i!==g&&(i=g-r),c===g&&(i-=r)):k.multiple&&(R=!0,i-=r),i+=r):k.multiple?R&&(i+=r,d-=r,R=!1):w===A?A=void 0:k.optional&&(i+=r,d-=r),d+=r):(t&&!this.isEager()&&m[f](y),w===y&&!this.isEager()?d+=r:A=y,this.isEager()||(i+=r)),this.isEager())for(;N(i)&&(l[o.charAt(i)]==null||h.includes(i));){if(t){if(m[f](o.charAt(i)),s.charAt(d)===o.charAt(i)){i+=r,d+=r;continue}}else o.charAt(i)===s.charAt(d)&&(d+=r);i+=r}}return this.memo.set(n,m.join("")),this.memo.get(n)}}const C=a=>JSON.parse(a.replaceAll("'",'"')),W=(a,s={})=>{const e={...s};a.dataset.maska!=null&&a.dataset.maska!==""&&(e.mask=x(a.dataset.maska)),a.dataset.maskaEager!=null&&(e.eager=E(a.dataset.maskaEager)),a.dataset.maskaReversed!=null&&(e.reversed=E(a.dataset.maskaReversed)),a.dataset.maskaTokensReplace!=null&&(e.tokensReplace=E(a.dataset.maskaTokensReplace)),a.dataset.maskaTokens!=null&&(e.tokens=O(a.dataset.maskaTokens));const t={};return a.dataset.maskaNumberLocale!=null&&(t.locale=a.dataset.maskaNumberLocale),a.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(a.dataset.maskaNumberFraction)),a.dataset.maskaNumberUnsigned!=null&&(t.unsigned=E(a.dataset.maskaNumberUnsigned)),(a.dataset.maskaNumber!=null||Object.values(t).length>0)&&(e.number=t),e},E=a=>a!==""?!!JSON.parse(a):!0,x=a=>a.startsWith("[")&&a.endsWith("]")?C(a):a,O=a=>{if(a.startsWith("{")&&a.endsWith("}"))return C(a);const s={};return a.split("|").forEach(e=>{const t=e.split(":");s[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),s};class S{constructor(s,e={}){v(this,"items",new Map);v(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input"&&!s.isTrusted)return;const e=s.target,t=this.items.get(e),n="inputType"in s&&s.inputType.startsWith("delete"),o=t.isEager(),h=n&&o&&t.unmasked(e.value)===""?"":e.value;this.fixCursor(e,n,()=>this.setValue(e,h))});this.options=e,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const e=this.getOptions(this.options);for(const t of s){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const n=new P(W(t,e));this.items.set(t,n),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&n.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:e,preProcess:t,postProcess:n,...o}=s;return o}fixCursor(s,e,t){const n=s.selectionStart,o=s.value;if(t(),n===null||n===o.length&&!e)return;const h=s.value,m=o.slice(0,n),l=h.slice(0,n),r=this.processInput(s,m).unmasked,f=this.processInput(s,l).unmasked;let c=n;m!==l&&(c+=e?h.length-o.length:r.length-f.length),s.setSelectionRange(c,c)}setValue(s,e){const t=this.processInput(s,e);s.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(n=>n(t)):this.options.onMaska(t)),s.dispatchEvent(new CustomEvent("maska",{detail:t})),s.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(s,e){const t=this.items.get(s);let n=e??s.value;this.options.preProcess!=null&&(n=this.options.preProcess(n));let o=t.masked(n);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:t.unmasked(n),completed:t.completed(n)}}}const I=new WeakMap,F=a=>{a.directive("maska",(s,e,t)=>{const n=s instanceof HTMLInputElement?s:s.querySelector("input");if(n==null||(n==null?void 0:n.type)==="file")return;let o={};const h=e.expression!==""?t.evaluateLater(e.expression):()=>{};t.effect(()=>{var m;if(h(l=>{o=typeof l=="string"?{mask:l}:{...l}}),e.value!=null){const l=r=>{const f=e.modifiers.includes("unmasked")?r.unmasked:e.modifiers.includes("completed")?r.completed:r.masked,c=t.Alpine.$data(n);e.value in c&&(c[e.value]=f)};o.onMaska=o.onMaska==null?l:Array.isArray(o.onMaska)?[...o.onMaska,l]:[o.onMaska,l]}I.has(n)?(m=I.get(n))==null||m.update(o):I.set(n,new S(n,o))})}).before("model")};document.addEventListener("alpine:init",()=>{window.Alpine.plugin(F)}),u.Mask=P,u.MaskInput=S,u.tokens=p,u.xMaska=F,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}); |
@@ -1,2 +0,2 @@ | ||
/*! maska v3.0.0 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(c,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(c=typeof globalThis<"u"?globalThis:c||self,l(c.Maska={}))})(this,function(c){"use strict";var j=Object.defineProperty;var x=(c,l,y)=>l in c?j(c,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[l]=y;var E=(c,l,y)=>x(c,typeof l!="symbol"?l+"":l,y);const l={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},y=(n,s,e)=>n.replaceAll(s,"").replace(e,".").replace("..",".").replace(/[^.\d]/g,""),w=(n,s,e)=>{var t;return new Intl.NumberFormat(((t=e.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:n,maximumFractionDigits:s,roundingMode:"trunc"})},C=(n,s=!0,e)=>{var A,N,v,g;const t=((A=e.number)==null?void 0:A.unsigned)==null&&n.startsWith("-")?"-":"",a=((N=e.number)==null?void 0:N.fraction)??0;let r=w(0,a,e);const p=r.formatToParts(1000.12),m=((v=p.find(o=>o.type==="group"))==null?void 0:v.value)??" ",k=((g=p.find(o=>o.type==="decimal"))==null?void 0:g.value)??".",i=y(n,m,k);if(i===""||Number.isNaN(i))return t;const f=i.split(".");if(f[1]!=null&&f[1].length>=1){const o=f[1].length<=a?f[1].length:a;r=w(o,a,e)}let h=r.format(parseFloat(i));return s?a>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(h+=k):h=y(h,m,k),t+h};class P{constructor(s={}){E(this,"opts",{});E(this,"memo",new Map);const e={...s};if(e.tokens!=null){e.tokens=e.tokensReplace?{...e.tokens}:{...l,...e.tokens};for(const t of Object.values(e.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else e.tokens=l;Array.isArray(e.mask)&&(e.mask.length>1?e.mask=[...e.mask].sort((t,a)=>t.length-a.length):e.mask=e.mask[0]??""),e.mask===""&&(e.mask=null),this.opts=e}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const e=this.findMask(s);if(this.opts.mask==null||e==null)return!1;const t=this.process(s,e).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=e.length}findMask(s){const e=this.opts.mask;if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="function")return e(s);const t=this.process(s,e.slice(-1).pop()??"",!1);return e.find(a=>this.process(s,a,!1).length>=t.length)??""}escapeMask(s){const e=[],t=[];return s.split("").forEach((a,r)=>{a==="!"&&s[r-1]!=="!"?t.push(r-t.length):e.push(a)}),{mask:e.join(""),escaped:t}}process(s,e,t=!0){if(this.opts.number!=null)return C(s,t,this.opts);if(e==null)return s;const a=`v=${s},mr=${e},m=${t?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:r,escaped:p}=this.escapeMask(e),m=[],k=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",h=this.isReversed()?0:r.length-1,A=this.isReversed()?()=>o>-1&&u>-1:()=>o<r.length&&u<s.length,N=M=>!this.isReversed()&&M<=h||this.isReversed()&&M>=h;let v,g=-1,o=this.isReversed()?r.length-1:0,u=this.isReversed()?s.length-1:0,I=!1;for(;A();){const M=r.charAt(o),d=k[M],R=(d==null?void 0:d.transform)!=null?d.transform(s.charAt(u)):s.charAt(u);if(!p.includes(o)&&d!=null?(R.match(d.pattern)!=null?(m[f](R),d.repeated?(g===-1?g=o:o===h&&o!==g&&(o=g-i),h===g&&(o-=i)):d.multiple&&(I=!0,o-=i),o+=i):d.multiple?I&&(o+=i,u-=i,I=!1):R===v?v=void 0:d.optional&&(o+=i,u-=i),u+=i):(t&&!this.isEager()&&m[f](M),R===M&&!this.isEager()?u+=i:v=M,this.isEager()||(o+=i)),this.isEager())for(;N(o)&&(k[r.charAt(o)]==null||p.includes(o));){if(t){if(m[f](r.charAt(o)),s.charAt(u)===r.charAt(o)){o+=i,u+=i;continue}}else r.charAt(o)===s.charAt(u)&&(u+=i);o+=i}}return this.memo.set(a,m.join("")),this.memo.get(a)}}const T=n=>JSON.parse(n.replaceAll("'",'"')),F=(n,s={})=>{const e={...s};n.dataset.maska!=null&&n.dataset.maska!==""&&(e.mask=S(n.dataset.maska)),n.dataset.maskaEager!=null&&(e.eager=b(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(e.reversed=b(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(e.tokensReplace=b(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(e.tokens=O(n.dataset.maskaTokens));const t={};return n.dataset.maskaNumberLocale!=null&&(t.locale=n.dataset.maskaNumberLocale),n.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(n.dataset.maskaNumberFraction)),n.dataset.maskaNumberUnsigned!=null&&(t.unsigned=b(n.dataset.maskaNumberUnsigned)),(n.dataset.maskaNumber!=null||Object.values(t).length>0)&&(e.number=t),e},b=n=>n!==""?!!JSON.parse(n):!0,S=n=>n.startsWith("[")&&n.endsWith("]")?T(n):n,O=n=>{if(n.startsWith("{")&&n.endsWith("}"))return T(n);const s={};return n.split("|").forEach(e=>{const t=e.split(":");s[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),s};class W{constructor(s,e={}){E(this,"items",new Map);E(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input")return;const e=s.target,t=this.items.get(e),a="inputType"in s&&s.inputType.startsWith("delete"),r=t.isEager(),p=a&&r&&t.unmasked(e.value)===""?"":e.value;this.fixCursor(e,a,()=>this.setValue(e,p))});this.options=e,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const e=this.getOptions(this.options);for(const t of s){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const a=new P(F(t,e));this.items.set(t,a),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&a.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:e,preProcess:t,postProcess:a,...r}=s;return r}fixCursor(s,e,t){const a=s.selectionStart,r=s.value;if(t(),a===null||a===r.length&&!e)return;const p=s.value,m=r.slice(0,a),k=p.slice(0,a),i=this.processInput(s,m).unmasked,f=this.processInput(s,k).unmasked;let h=a;m!==k&&(h+=e?p.length-r.length:i.length-f.length),s.setSelectionRange(h,h)}setValue(s,e){const t=this.processInput(s,e);s.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(a=>a(t)):this.options.onMaska(t)),s.dispatchEvent(new CustomEvent("maska",{detail:t})),s.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(s,e){const t=this.items.get(s);let a=e??s.value;this.options.preProcess!=null&&(a=this.options.preProcess(a));let r=t.masked(a);return this.options.postProcess!=null&&(r=this.options.postProcess(r)),{masked:r,unmasked:t.unmasked(a),completed:t.completed(a)}}}c.Mask=P,c.MaskInput=W,c.tokens=l,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}); | ||
/*! maska v3.0.1 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(c,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(c=typeof globalThis<"u"?globalThis:c||self,l(c.Maska={}))})(this,function(c){"use strict";var j=Object.defineProperty;var x=(c,l,y)=>l in c?j(c,l,{enumerable:!0,configurable:!0,writable:!0,value:y}):c[l]=y;var E=(c,l,y)=>x(c,typeof l!="symbol"?l+"":l,y);const l={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},y=(n,s,e)=>n.replaceAll(s,"").replace(e,".").replace("..",".").replace(/[^.\d]/g,""),w=(n,s,e)=>{var t;return new Intl.NumberFormat(((t=e.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:n,maximumFractionDigits:s,roundingMode:"trunc"})},C=(n,s=!0,e)=>{var A,N,v,g;const t=((A=e.number)==null?void 0:A.unsigned)==null&&n.startsWith("-")?"-":"",a=((N=e.number)==null?void 0:N.fraction)??0;let r=w(0,a,e);const p=r.formatToParts(1000.12),m=((v=p.find(o=>o.type==="group"))==null?void 0:v.value)??" ",k=((g=p.find(o=>o.type==="decimal"))==null?void 0:g.value)??".",i=y(n,m,k);if(i===""||Number.isNaN(i))return t;const f=i.split(".");if(f[1]!=null&&f[1].length>=1){const o=f[1].length<=a?f[1].length:a;r=w(o,a,e)}let h=r.format(parseFloat(i));return s?a>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(h+=k):h=y(h,m,k),t+h};class P{constructor(s={}){E(this,"opts",{});E(this,"memo",new Map);const e={...s};if(e.tokens!=null){e.tokens=e.tokensReplace?{...e.tokens}:{...l,...e.tokens};for(const t of Object.values(e.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else e.tokens=l;Array.isArray(e.mask)&&(e.mask.length>1?e.mask=[...e.mask].sort((t,a)=>t.length-a.length):e.mask=e.mask[0]??""),e.mask===""&&(e.mask=null),this.opts=e}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const e=this.findMask(s);if(this.opts.mask==null||e==null)return!1;const t=this.process(s,e).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=e.length}findMask(s){const e=this.opts.mask;if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="function")return e(s);const t=this.process(s,e.slice(-1).pop()??"",!1);return e.find(a=>this.process(s,a,!1).length>=t.length)??""}escapeMask(s){const e=[],t=[];return s.split("").forEach((a,r)=>{a==="!"&&s[r-1]!=="!"?t.push(r-t.length):e.push(a)}),{mask:e.join(""),escaped:t}}process(s,e,t=!0){if(this.opts.number!=null)return C(s,t,this.opts);if(e==null)return s;const a=`v=${s},mr=${e},m=${t?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:r,escaped:p}=this.escapeMask(e),m=[],k=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",h=this.isReversed()?0:r.length-1,A=this.isReversed()?()=>o>-1&&u>-1:()=>o<r.length&&u<s.length,N=M=>!this.isReversed()&&M<=h||this.isReversed()&&M>=h;let v,g=-1,o=this.isReversed()?r.length-1:0,u=this.isReversed()?s.length-1:0,I=!1;for(;A();){const M=r.charAt(o),d=k[M],R=(d==null?void 0:d.transform)!=null?d.transform(s.charAt(u)):s.charAt(u);if(!p.includes(o)&&d!=null?(R.match(d.pattern)!=null?(m[f](R),d.repeated?(g===-1?g=o:o===h&&o!==g&&(o=g-i),h===g&&(o-=i)):d.multiple&&(I=!0,o-=i),o+=i):d.multiple?I&&(o+=i,u-=i,I=!1):R===v?v=void 0:d.optional&&(o+=i,u-=i),u+=i):(t&&!this.isEager()&&m[f](M),R===M&&!this.isEager()?u+=i:v=M,this.isEager()||(o+=i)),this.isEager())for(;N(o)&&(k[r.charAt(o)]==null||p.includes(o));){if(t){if(m[f](r.charAt(o)),s.charAt(u)===r.charAt(o)){o+=i,u+=i;continue}}else r.charAt(o)===s.charAt(u)&&(u+=i);o+=i}}return this.memo.set(a,m.join("")),this.memo.get(a)}}const T=n=>JSON.parse(n.replaceAll("'",'"')),F=(n,s={})=>{const e={...s};n.dataset.maska!=null&&n.dataset.maska!==""&&(e.mask=S(n.dataset.maska)),n.dataset.maskaEager!=null&&(e.eager=b(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(e.reversed=b(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(e.tokensReplace=b(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(e.tokens=O(n.dataset.maskaTokens));const t={};return n.dataset.maskaNumberLocale!=null&&(t.locale=n.dataset.maskaNumberLocale),n.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(n.dataset.maskaNumberFraction)),n.dataset.maskaNumberUnsigned!=null&&(t.unsigned=b(n.dataset.maskaNumberUnsigned)),(n.dataset.maskaNumber!=null||Object.values(t).length>0)&&(e.number=t),e},b=n=>n!==""?!!JSON.parse(n):!0,S=n=>n.startsWith("[")&&n.endsWith("]")?T(n):n,O=n=>{if(n.startsWith("{")&&n.endsWith("}"))return T(n);const s={};return n.split("|").forEach(e=>{const t=e.split(":");s[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),s};class W{constructor(s,e={}){E(this,"items",new Map);E(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input"&&!s.isTrusted)return;const e=s.target,t=this.items.get(e),a="inputType"in s&&s.inputType.startsWith("delete"),r=t.isEager(),p=a&&r&&t.unmasked(e.value)===""?"":e.value;this.fixCursor(e,a,()=>this.setValue(e,p))});this.options=e,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const e=this.getOptions(this.options);for(const t of s){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const a=new P(F(t,e));this.items.set(t,a),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&a.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:e,preProcess:t,postProcess:a,...r}=s;return r}fixCursor(s,e,t){const a=s.selectionStart,r=s.value;if(t(),a===null||a===r.length&&!e)return;const p=s.value,m=r.slice(0,a),k=p.slice(0,a),i=this.processInput(s,m).unmasked,f=this.processInput(s,k).unmasked;let h=a;m!==k&&(h+=e?p.length-r.length:i.length-f.length),s.setSelectionRange(h,h)}setValue(s,e){const t=this.processInput(s,e);s.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(a=>a(t)):this.options.onMaska(t)),s.dispatchEvent(new CustomEvent("maska",{detail:t})),s.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(s,e){const t=this.items.get(s);let a=e??s.value;this.options.preProcess!=null&&(a=this.options.preProcess(a));let r=t.masked(a);return this.options.postProcess!=null&&(r=this.options.postProcess(r)),{masked:r,unmasked:t.unmasked(a),completed:t.completed(a)}}}c.Mask=P,c.MaskInput=W,c.tokens=l,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})}); |
@@ -1,2 +0,2 @@ | ||
/*! maska v3.0.0 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.Maska={}))})(this,function(l){"use strict";var V=Object.defineProperty;var $=(l,c,M)=>c in l?V(l,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):l[c]=M;var A=(l,c,M)=>$(l,typeof c!="symbol"?c+"":c,M);const c={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},M=(a,e,s)=>a.replaceAll(e,"").replace(s,".").replace("..",".").replace(/[^.\d]/g,""),T=(a,e,s)=>{var t;return new Intl.NumberFormat(((t=s.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:a,maximumFractionDigits:e,roundingMode:"trunc"})},W=(a,e=!0,s)=>{var N,w,v,g;const t=((N=s.number)==null?void 0:N.unsigned)==null&&a.startsWith("-")?"-":"",n=((w=s.number)==null?void 0:w.fraction)??0;let o=T(0,n,s);const u=o.formatToParts(1000.12),h=((v=u.find(r=>r.type==="group"))==null?void 0:v.value)??" ",d=((g=u.find(r=>r.type==="decimal"))==null?void 0:g.value)??".",i=M(a,h,d);if(i===""||Number.isNaN(i))return t;const f=i.split(".");if(f[1]!=null&&f[1].length>=1){const r=f[1].length<=n?f[1].length:n;o=T(r,n,s)}let p=o.format(parseFloat(i));return e?n>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(p+=d):p=M(p,h,d),t+p};class C{constructor(e={}){A(this,"opts",{});A(this,"memo",new Map);const s={...e};if(s.tokens!=null){s.tokens=s.tokensReplace?{...s.tokens}:{...c,...s.tokens};for(const t of Object.values(s.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else s.tokens=c;Array.isArray(s.mask)&&(s.mask.length>1?s.mask=[...s.mask].sort((t,n)=>t.length-n.length):s.mask=s.mask[0]??""),s.mask===""&&(s.mask=null),this.opts=s}masked(e){return this.process(e,this.findMask(e))}unmasked(e){return this.process(e,this.findMask(e),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(e){const s=this.findMask(e);if(this.opts.mask==null||s==null)return!1;const t=this.process(e,s).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=s.length}findMask(e){const s=this.opts.mask;if(s==null)return null;if(typeof s=="string")return s;if(typeof s=="function")return s(e);const t=this.process(e,s.slice(-1).pop()??"",!1);return s.find(n=>this.process(e,n,!1).length>=t.length)??""}escapeMask(e){const s=[],t=[];return e.split("").forEach((n,o)=>{n==="!"&&e[o-1]!=="!"?t.push(o-t.length):s.push(n)}),{mask:s.join(""),escaped:t}}process(e,s,t=!0){if(this.opts.number!=null)return W(e,t,this.opts);if(s==null)return e;const n=`v=${e},mr=${s},m=${t?1:0}`;if(this.memo.has(n))return this.memo.get(n);const{mask:o,escaped:u}=this.escapeMask(s),h=[],d=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",p=this.isReversed()?0:o.length-1,N=this.isReversed()?()=>r>-1&&m>-1:()=>r<o.length&&m<e.length,w=y=>!this.isReversed()&&y<=p||this.isReversed()&&y>=p;let v,g=-1,r=this.isReversed()?o.length-1:0,m=this.isReversed()?e.length-1:0,P=!1;for(;N();){const y=o.charAt(r),k=d[y],I=(k==null?void 0:k.transform)!=null?k.transform(e.charAt(m)):e.charAt(m);if(!u.includes(r)&&k!=null?(I.match(k.pattern)!=null?(h[f](I),k.repeated?(g===-1?g=r:r===p&&r!==g&&(r=g-i),p===g&&(r-=i)):k.multiple&&(P=!0,r-=i),r+=i):k.multiple?P&&(r+=i,m-=i,P=!1):I===v?v=void 0:k.optional&&(r+=i,m-=i),m+=i):(t&&!this.isEager()&&h[f](y),I===y&&!this.isEager()?m+=i:v=y,this.isEager()||(r+=i)),this.isEager())for(;w(r)&&(d[o.charAt(r)]==null||u.includes(r));){if(t){if(h[f](o.charAt(r)),e.charAt(m)===o.charAt(r)){r+=i,m+=i;continue}}else o.charAt(r)===e.charAt(m)&&(m+=i);r+=i}}return this.memo.set(n,h.join("")),this.memo.get(n)}}const S=a=>JSON.parse(a.replaceAll("'",'"')),b=(a,e={})=>{const s={...e};a.dataset.maska!=null&&a.dataset.maska!==""&&(s.mask=x(a.dataset.maska)),a.dataset.maskaEager!=null&&(s.eager=E(a.dataset.maskaEager)),a.dataset.maskaReversed!=null&&(s.reversed=E(a.dataset.maskaReversed)),a.dataset.maskaTokensReplace!=null&&(s.tokensReplace=E(a.dataset.maskaTokensReplace)),a.dataset.maskaTokens!=null&&(s.tokens=O(a.dataset.maskaTokens));const t={};return a.dataset.maskaNumberLocale!=null&&(t.locale=a.dataset.maskaNumberLocale),a.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(a.dataset.maskaNumberFraction)),a.dataset.maskaNumberUnsigned!=null&&(t.unsigned=E(a.dataset.maskaNumberUnsigned)),(a.dataset.maskaNumber!=null||Object.values(t).length>0)&&(s.number=t),s},E=a=>a!==""?!!JSON.parse(a):!0,x=a=>a.startsWith("[")&&a.endsWith("]")?S(a):a,O=a=>{if(a.startsWith("{")&&a.endsWith("}"))return S(a);const e={};return a.split("|").forEach(s=>{const t=s.split(":");e[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),e};class F{constructor(e,s={}){A(this,"items",new Map);A(this,"onInput",e=>{if(e instanceof CustomEvent&&e.type==="input")return;const s=e.target,t=this.items.get(s),n="inputType"in e&&e.inputType.startsWith("delete"),o=t.isEager(),u=n&&o&&t.unmasked(s.value)===""?"":s.value;this.fixCursor(s,n,()=>this.setValue(s,u))});this.options=s,this.init(this.getInputs(e))}update(e={}){this.options={...e},this.init(Array.from(this.items.keys()))}updateValue(e){e.value!==""&&e.value!==this.processInput(e).masked&&this.setValue(e,e.value)}destroy(){for(const e of this.items.keys())e.removeEventListener("input",this.onInput);this.items.clear()}init(e){const s=this.getOptions(this.options);for(const t of e){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const n=new C(b(t,s));this.items.set(t,n),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&n.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(e){return typeof e=="string"?Array.from(document.querySelectorAll(e)):"length"in e?Array.from(e):[e]}getOptions(e){const{onMaska:s,preProcess:t,postProcess:n,...o}=e;return o}fixCursor(e,s,t){const n=e.selectionStart,o=e.value;if(t(),n===null||n===o.length&&!s)return;const u=e.value,h=o.slice(0,n),d=u.slice(0,n),i=this.processInput(e,h).unmasked,f=this.processInput(e,d).unmasked;let p=n;h!==d&&(p+=s?u.length-o.length:i.length-f.length),e.setSelectionRange(p,p)}setValue(e,s){const t=this.processInput(e,s);e.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(n=>n(t)):this.options.onMaska(t)),e.dispatchEvent(new CustomEvent("maska",{detail:t})),e.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(e,s){const t=this.items.get(e);let n=s??e.value;this.options.preProcess!=null&&(n=this.options.preProcess(n));let o=t.masked(n);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:t.unmasked(n),completed:t.completed(n)}}}const R=new WeakMap,j=(a,e)=>{if(a.arg==null||a.instance==null)return;const s="setup"in a.instance.$.type;a.arg in a.instance?a.instance[a.arg]=e:s&&console.warn("Maska: please expose `%s` using defineExpose",a.arg)},L=(a,e)=>{var n;const s=a instanceof HTMLInputElement?a:a.querySelector("input");if(s==null||(s==null?void 0:s.type)==="file")return;let t={};if(e.value!=null&&(t=typeof e.value=="string"?{mask:e.value}:{...e.value}),e.arg!=null){const o=u=>{const h=e.modifiers.unmasked?u.unmasked:e.modifiers.completed?u.completed:u.masked;j(e,h)};t.onMaska=t.onMaska==null?o:Array.isArray(t.onMaska)?[...t.onMaska,o]:[t.onMaska,o]}R.has(s)?(n=R.get(s))==null||n.update(t):R.set(s,new F(s,t))};l.Mask=C,l.MaskInput=F,l.tokens=c,l.vMaska=L,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}); | ||
/*! maska v3.0.1 by Alexander Shabunevich | Released under the MIT license */ | ||
(function(l,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(l=typeof globalThis<"u"?globalThis:l||self,c(l.Maska={}))})(this,function(l){"use strict";var V=Object.defineProperty;var $=(l,c,M)=>c in l?V(l,c,{enumerable:!0,configurable:!0,writable:!0,value:M}):l[c]=M;var A=(l,c,M)=>$(l,typeof c!="symbol"?c+"":c,M);const c={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},M=(a,s,e)=>a.replaceAll(s,"").replace(e,".").replace("..",".").replace(/[^.\d]/g,""),P=(a,s,e)=>{var t;return new Intl.NumberFormat(((t=e.number)==null?void 0:t.locale)??"en",{minimumFractionDigits:a,maximumFractionDigits:s,roundingMode:"trunc"})},W=(a,s=!0,e)=>{var N,w,v,g;const t=((N=e.number)==null?void 0:N.unsigned)==null&&a.startsWith("-")?"-":"",n=((w=e.number)==null?void 0:w.fraction)??0;let o=P(0,n,e);const u=o.formatToParts(1000.12),h=((v=u.find(r=>r.type==="group"))==null?void 0:v.value)??" ",d=((g=u.find(r=>r.type==="decimal"))==null?void 0:g.value)??".",i=M(a,h,d);if(i===""||Number.isNaN(i))return t;const f=i.split(".");if(f[1]!=null&&f[1].length>=1){const r=f[1].length<=n?f[1].length:n;o=P(r,n,e)}let p=o.format(parseFloat(i));return s?n>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(p+=d):p=M(p,h,d),t+p};class C{constructor(s={}){A(this,"opts",{});A(this,"memo",new Map);const e={...s};if(e.tokens!=null){e.tokens=e.tokensReplace?{...e.tokens}:{...c,...e.tokens};for(const t of Object.values(e.tokens))typeof t.pattern=="string"&&(t.pattern=new RegExp(t.pattern))}else e.tokens=c;Array.isArray(e.mask)&&(e.mask.length>1?e.mask=[...e.mask].sort((t,n)=>t.length-n.length):e.mask=e.mask[0]??""),e.mask===""&&(e.mask=null),this.opts=e}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const e=this.findMask(s);if(this.opts.mask==null||e==null)return!1;const t=this.process(s,e).length;return typeof this.opts.mask=="string"?t>=this.opts.mask.length:t>=e.length}findMask(s){const e=this.opts.mask;if(e==null)return null;if(typeof e=="string")return e;if(typeof e=="function")return e(s);const t=this.process(s,e.slice(-1).pop()??"",!1);return e.find(n=>this.process(s,n,!1).length>=t.length)??""}escapeMask(s){const e=[],t=[];return s.split("").forEach((n,o)=>{n==="!"&&s[o-1]!=="!"?t.push(o-t.length):e.push(n)}),{mask:e.join(""),escaped:t}}process(s,e,t=!0){if(this.opts.number!=null)return W(s,t,this.opts);if(e==null)return s;const n=`v=${s},mr=${e},m=${t?1:0}`;if(this.memo.has(n))return this.memo.get(n);const{mask:o,escaped:u}=this.escapeMask(e),h=[],d=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,f=this.isReversed()?"unshift":"push",p=this.isReversed()?0:o.length-1,N=this.isReversed()?()=>r>-1&&m>-1:()=>r<o.length&&m<s.length,w=y=>!this.isReversed()&&y<=p||this.isReversed()&&y>=p;let v,g=-1,r=this.isReversed()?o.length-1:0,m=this.isReversed()?s.length-1:0,T=!1;for(;N();){const y=o.charAt(r),k=d[y],I=(k==null?void 0:k.transform)!=null?k.transform(s.charAt(m)):s.charAt(m);if(!u.includes(r)&&k!=null?(I.match(k.pattern)!=null?(h[f](I),k.repeated?(g===-1?g=r:r===p&&r!==g&&(r=g-i),p===g&&(r-=i)):k.multiple&&(T=!0,r-=i),r+=i):k.multiple?T&&(r+=i,m-=i,T=!1):I===v?v=void 0:k.optional&&(r+=i,m-=i),m+=i):(t&&!this.isEager()&&h[f](y),I===y&&!this.isEager()?m+=i:v=y,this.isEager()||(r+=i)),this.isEager())for(;w(r)&&(d[o.charAt(r)]==null||u.includes(r));){if(t){if(h[f](o.charAt(r)),s.charAt(m)===o.charAt(r)){r+=i,m+=i;continue}}else o.charAt(r)===s.charAt(m)&&(m+=i);r+=i}}return this.memo.set(n,h.join("")),this.memo.get(n)}}const S=a=>JSON.parse(a.replaceAll("'",'"')),b=(a,s={})=>{const e={...s};a.dataset.maska!=null&&a.dataset.maska!==""&&(e.mask=x(a.dataset.maska)),a.dataset.maskaEager!=null&&(e.eager=E(a.dataset.maskaEager)),a.dataset.maskaReversed!=null&&(e.reversed=E(a.dataset.maskaReversed)),a.dataset.maskaTokensReplace!=null&&(e.tokensReplace=E(a.dataset.maskaTokensReplace)),a.dataset.maskaTokens!=null&&(e.tokens=O(a.dataset.maskaTokens));const t={};return a.dataset.maskaNumberLocale!=null&&(t.locale=a.dataset.maskaNumberLocale),a.dataset.maskaNumberFraction!=null&&(t.fraction=parseInt(a.dataset.maskaNumberFraction)),a.dataset.maskaNumberUnsigned!=null&&(t.unsigned=E(a.dataset.maskaNumberUnsigned)),(a.dataset.maskaNumber!=null||Object.values(t).length>0)&&(e.number=t),e},E=a=>a!==""?!!JSON.parse(a):!0,x=a=>a.startsWith("[")&&a.endsWith("]")?S(a):a,O=a=>{if(a.startsWith("{")&&a.endsWith("}"))return S(a);const s={};return a.split("|").forEach(e=>{const t=e.split(":");s[t[0]]={pattern:new RegExp(t[1]),optional:t[2]==="optional",multiple:t[2]==="multiple",repeated:t[2]==="repeated"}}),s};class F{constructor(s,e={}){A(this,"items",new Map);A(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input"&&!s.isTrusted)return;const e=s.target,t=this.items.get(e),n="inputType"in s&&s.inputType.startsWith("delete"),o=t.isEager(),u=n&&o&&t.unmasked(e.value)===""?"":e.value;this.fixCursor(e,n,()=>this.setValue(e,u))});this.options=e,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const e=this.getOptions(this.options);for(const t of s){this.items.has(t)||t.addEventListener("input",this.onInput,{capture:!0});const n=new C(b(t,e));this.items.set(t,n),queueMicrotask(()=>this.updateValue(t)),t.selectionStart===null&&n.isEager()&&console.warn("Maska: input of `%s` type is not supported",t.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:e,preProcess:t,postProcess:n,...o}=s;return o}fixCursor(s,e,t){const n=s.selectionStart,o=s.value;if(t(),n===null||n===o.length&&!e)return;const u=s.value,h=o.slice(0,n),d=u.slice(0,n),i=this.processInput(s,h).unmasked,f=this.processInput(s,d).unmasked;let p=n;h!==d&&(p+=e?u.length-o.length:i.length-f.length),s.setSelectionRange(p,p)}setValue(s,e){const t=this.processInput(s,e);s.value=t.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(n=>n(t)):this.options.onMaska(t)),s.dispatchEvent(new CustomEvent("maska",{detail:t})),s.dispatchEvent(new CustomEvent("input",{detail:t.masked}))}processInput(s,e){const t=this.items.get(s);let n=e??s.value;this.options.preProcess!=null&&(n=this.options.preProcess(n));let o=t.masked(n);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:t.unmasked(n),completed:t.completed(n)}}}const R=new WeakMap,j=(a,s)=>{if(a.arg==null||a.instance==null)return;const e="setup"in a.instance.$.type;a.arg in a.instance?a.instance[a.arg]=s:e&&console.warn("Maska: please expose `%s` using defineExpose",a.arg)},L=(a,s)=>{var n;const e=a instanceof HTMLInputElement?a:a.querySelector("input");if(e==null||(e==null?void 0:e.type)==="file")return;let t={};if(s.value!=null&&(t=typeof s.value=="string"?{mask:s.value}:{...s.value}),s.arg!=null){const o=u=>{const h=s.modifiers.unmasked?u.unmasked:s.modifiers.completed?u.completed:u.masked;j(s,h)};t.onMaska=t.onMaska==null?o:Array.isArray(t.onMaska)?[...t.onMaska,o]:[t.onMaska,o]}R.has(e)?(n=R.get(e))==null||n.update(t):R.set(e,new F(e,t))};l.Mask=C,l.MaskInput=F,l.tokens=c,l.vMaska=L,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})}); |
@@ -1,1 +0,1 @@ | ||
"use strict";var C=Object.defineProperty;var T=(n,s,t)=>s in n?C(n,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[s]=t;var y=(n,s,t)=>T(n,typeof s!="symbol"?s+"":s,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},R=(n,s,t)=>n.replaceAll(s,"").replace(t,".").replace("..",".").replace(/[^.\d]/g,""),I=(n,s,t)=>{var e;return new Intl.NumberFormat(((e=t.number)==null?void 0:e.locale)??"en",{minimumFractionDigits:n,maximumFractionDigits:s,roundingMode:"trunc"})},F=(n,s=!0,t)=>{var M,v,g,d;const e=((M=t.number)==null?void 0:M.unsigned)==null&&n.startsWith("-")?"-":"",a=((v=t.number)==null?void 0:v.fraction)??0;let o=I(0,a,t);const h=o.formatToParts(1000.12),u=((g=h.find(r=>r.type==="group"))==null?void 0:g.value)??" ",f=((d=h.find(r=>r.type==="decimal"))==null?void 0:d.value)??".",i=R(n,u,f);if(i===""||Number.isNaN(i))return e;const p=i.split(".");if(p[1]!=null&&p[1].length>=1){const r=p[1].length<=a?p[1].length:a;o=I(r,a,t)}let l=o.format(parseFloat(i));return s?a>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(l+=f):l=R(l,u,f),e+l};class w{constructor(s={}){y(this,"opts",{});y(this,"memo",new Map);const t={...s};if(t.tokens!=null){t.tokens=t.tokensReplace?{...t.tokens}:{...N,...t.tokens};for(const e of Object.values(t.tokens))typeof e.pattern=="string"&&(e.pattern=new RegExp(e.pattern))}else t.tokens=N;Array.isArray(t.mask)&&(t.mask.length>1?t.mask=[...t.mask].sort((e,a)=>e.length-a.length):t.mask=t.mask[0]??""),t.mask===""&&(t.mask=null),this.opts=t}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const t=this.findMask(s);if(this.opts.mask==null||t==null)return!1;const e=this.process(s,t).length;return typeof this.opts.mask=="string"?e>=this.opts.mask.length:e>=t.length}findMask(s){const t=this.opts.mask;if(t==null)return null;if(typeof t=="string")return t;if(typeof t=="function")return t(s);const e=this.process(s,t.slice(-1).pop()??"",!1);return t.find(a=>this.process(s,a,!1).length>=e.length)??""}escapeMask(s){const t=[],e=[];return s.split("").forEach((a,o)=>{a==="!"&&s[o-1]!=="!"?e.push(o-e.length):t.push(a)}),{mask:t.join(""),escaped:e}}process(s,t,e=!0){if(this.opts.number!=null)return F(s,e,this.opts);if(t==null)return s;const a=`v=${s},mr=${t},m=${e?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:o,escaped:h}=this.escapeMask(t),u=[],f=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,p=this.isReversed()?"unshift":"push",l=this.isReversed()?0:o.length-1,M=this.isReversed()?()=>r>-1&&c>-1:()=>r<o.length&&c<s.length,v=k=>!this.isReversed()&&k<=l||this.isReversed()&&k>=l;let g,d=-1,r=this.isReversed()?o.length-1:0,c=this.isReversed()?s.length-1:0,b=!1;for(;M();){const k=o.charAt(r),m=f[k],E=(m==null?void 0:m.transform)!=null?m.transform(s.charAt(c)):s.charAt(c);if(!h.includes(r)&&m!=null?(E.match(m.pattern)!=null?(u[p](E),m.repeated?(d===-1?d=r:r===l&&r!==d&&(r=d-i),l===d&&(r-=i)):m.multiple&&(b=!0,r-=i),r+=i):m.multiple?b&&(r+=i,c-=i,b=!1):E===g?g=void 0:m.optional&&(r+=i,c-=i),c+=i):(e&&!this.isEager()&&u[p](k),E===k&&!this.isEager()?c+=i:g=k,this.isEager()||(r+=i)),this.isEager())for(;v(r)&&(f[o.charAt(r)]==null||h.includes(r));){if(e){if(u[p](o.charAt(r)),s.charAt(c)===o.charAt(r)){r+=i,c+=i;continue}}else o.charAt(r)===s.charAt(c)&&(c+=i);r+=i}}return this.memo.set(a,u.join("")),this.memo.get(a)}}const P=n=>JSON.parse(n.replaceAll("'",'"')),S=(n,s={})=>{const t={...s};n.dataset.maska!=null&&n.dataset.maska!==""&&(t.mask=O(n.dataset.maska)),n.dataset.maskaEager!=null&&(t.eager=A(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(t.reversed=A(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(t.tokensReplace=A(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(t.tokens=W(n.dataset.maskaTokens));const e={};return n.dataset.maskaNumberLocale!=null&&(e.locale=n.dataset.maskaNumberLocale),n.dataset.maskaNumberFraction!=null&&(e.fraction=parseInt(n.dataset.maskaNumberFraction)),n.dataset.maskaNumberUnsigned!=null&&(e.unsigned=A(n.dataset.maskaNumberUnsigned)),(n.dataset.maskaNumber!=null||Object.values(e).length>0)&&(t.number=e),t},A=n=>n!==""?!!JSON.parse(n):!0,O=n=>n.startsWith("[")&&n.endsWith("]")?P(n):n,W=n=>{if(n.startsWith("{")&&n.endsWith("}"))return P(n);const s={};return n.split("|").forEach(t=>{const e=t.split(":");s[e[0]]={pattern:new RegExp(e[1]),optional:e[2]==="optional",multiple:e[2]==="multiple",repeated:e[2]==="repeated"}}),s};class x{constructor(s,t={}){y(this,"items",new Map);y(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input")return;const t=s.target,e=this.items.get(t),a="inputType"in s&&s.inputType.startsWith("delete"),o=e.isEager(),h=a&&o&&e.unmasked(t.value)===""?"":t.value;this.fixCursor(t,a,()=>this.setValue(t,h))});this.options=t,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const t=this.getOptions(this.options);for(const e of s){this.items.has(e)||e.addEventListener("input",this.onInput,{capture:!0});const a=new w(S(e,t));this.items.set(e,a),queueMicrotask(()=>this.updateValue(e)),e.selectionStart===null&&a.isEager()&&console.warn("Maska: input of `%s` type is not supported",e.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:t,preProcess:e,postProcess:a,...o}=s;return o}fixCursor(s,t,e){const a=s.selectionStart,o=s.value;if(e(),a===null||a===o.length&&!t)return;const h=s.value,u=o.slice(0,a),f=h.slice(0,a),i=this.processInput(s,u).unmasked,p=this.processInput(s,f).unmasked;let l=a;u!==f&&(l+=t?h.length-o.length:i.length-p.length),s.setSelectionRange(l,l)}setValue(s,t){const e=this.processInput(s,t);s.value=e.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(a=>a(e)):this.options.onMaska(e)),s.dispatchEvent(new CustomEvent("maska",{detail:e})),s.dispatchEvent(new CustomEvent("input",{detail:e.masked}))}processInput(s,t){const e=this.items.get(s);let a=t??s.value;this.options.preProcess!=null&&(a=this.options.preProcess(a));let o=e.masked(a);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:e.unmasked(a),completed:e.completed(a)}}}exports.Mask=w;exports.MaskInput=x;exports.tokens=N; | ||
"use strict";var C=Object.defineProperty;var T=(n,s,t)=>s in n?C(n,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[s]=t;var y=(n,s,t)=>T(n,typeof s!="symbol"?s+"":s,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N={"#":{pattern:/[0-9]/},"@":{pattern:/[a-zA-Z]/},"*":{pattern:/[a-zA-Z0-9]/}},R=(n,s,t)=>n.replaceAll(s,"").replace(t,".").replace("..",".").replace(/[^.\d]/g,""),I=(n,s,t)=>{var e;return new Intl.NumberFormat(((e=t.number)==null?void 0:e.locale)??"en",{minimumFractionDigits:n,maximumFractionDigits:s,roundingMode:"trunc"})},F=(n,s=!0,t)=>{var M,v,g,d;const e=((M=t.number)==null?void 0:M.unsigned)==null&&n.startsWith("-")?"-":"",a=((v=t.number)==null?void 0:v.fraction)??0;let o=I(0,a,t);const h=o.formatToParts(1000.12),u=((g=h.find(r=>r.type==="group"))==null?void 0:g.value)??" ",f=((d=h.find(r=>r.type==="decimal"))==null?void 0:d.value)??".",i=R(n,u,f);if(i===""||Number.isNaN(i))return e;const p=i.split(".");if(p[1]!=null&&p[1].length>=1){const r=p[1].length<=a?p[1].length:a;o=I(r,a,t)}let l=o.format(parseFloat(i));return s?a>0&&i.endsWith(".")&&!i.slice(0,-1).includes(".")&&(l+=f):l=R(l,u,f),e+l};class w{constructor(s={}){y(this,"opts",{});y(this,"memo",new Map);const t={...s};if(t.tokens!=null){t.tokens=t.tokensReplace?{...t.tokens}:{...N,...t.tokens};for(const e of Object.values(t.tokens))typeof e.pattern=="string"&&(e.pattern=new RegExp(e.pattern))}else t.tokens=N;Array.isArray(t.mask)&&(t.mask.length>1?t.mask=[...t.mask].sort((e,a)=>e.length-a.length):t.mask=t.mask[0]??""),t.mask===""&&(t.mask=null),this.opts=t}masked(s){return this.process(s,this.findMask(s))}unmasked(s){return this.process(s,this.findMask(s),!1)}isEager(){return this.opts.eager===!0}isReversed(){return this.opts.reversed===!0}completed(s){const t=this.findMask(s);if(this.opts.mask==null||t==null)return!1;const e=this.process(s,t).length;return typeof this.opts.mask=="string"?e>=this.opts.mask.length:e>=t.length}findMask(s){const t=this.opts.mask;if(t==null)return null;if(typeof t=="string")return t;if(typeof t=="function")return t(s);const e=this.process(s,t.slice(-1).pop()??"",!1);return t.find(a=>this.process(s,a,!1).length>=e.length)??""}escapeMask(s){const t=[],e=[];return s.split("").forEach((a,o)=>{a==="!"&&s[o-1]!=="!"?e.push(o-e.length):t.push(a)}),{mask:t.join(""),escaped:e}}process(s,t,e=!0){if(this.opts.number!=null)return F(s,e,this.opts);if(t==null)return s;const a=`v=${s},mr=${t},m=${e?1:0}`;if(this.memo.has(a))return this.memo.get(a);const{mask:o,escaped:h}=this.escapeMask(t),u=[],f=this.opts.tokens!=null?this.opts.tokens:{},i=this.isReversed()?-1:1,p=this.isReversed()?"unshift":"push",l=this.isReversed()?0:o.length-1,M=this.isReversed()?()=>r>-1&&c>-1:()=>r<o.length&&c<s.length,v=k=>!this.isReversed()&&k<=l||this.isReversed()&&k>=l;let g,d=-1,r=this.isReversed()?o.length-1:0,c=this.isReversed()?s.length-1:0,b=!1;for(;M();){const k=o.charAt(r),m=f[k],E=(m==null?void 0:m.transform)!=null?m.transform(s.charAt(c)):s.charAt(c);if(!h.includes(r)&&m!=null?(E.match(m.pattern)!=null?(u[p](E),m.repeated?(d===-1?d=r:r===l&&r!==d&&(r=d-i),l===d&&(r-=i)):m.multiple&&(b=!0,r-=i),r+=i):m.multiple?b&&(r+=i,c-=i,b=!1):E===g?g=void 0:m.optional&&(r+=i,c-=i),c+=i):(e&&!this.isEager()&&u[p](k),E===k&&!this.isEager()?c+=i:g=k,this.isEager()||(r+=i)),this.isEager())for(;v(r)&&(f[o.charAt(r)]==null||h.includes(r));){if(e){if(u[p](o.charAt(r)),s.charAt(c)===o.charAt(r)){r+=i,c+=i;continue}}else o.charAt(r)===s.charAt(c)&&(c+=i);r+=i}}return this.memo.set(a,u.join("")),this.memo.get(a)}}const P=n=>JSON.parse(n.replaceAll("'",'"')),S=(n,s={})=>{const t={...s};n.dataset.maska!=null&&n.dataset.maska!==""&&(t.mask=O(n.dataset.maska)),n.dataset.maskaEager!=null&&(t.eager=A(n.dataset.maskaEager)),n.dataset.maskaReversed!=null&&(t.reversed=A(n.dataset.maskaReversed)),n.dataset.maskaTokensReplace!=null&&(t.tokensReplace=A(n.dataset.maskaTokensReplace)),n.dataset.maskaTokens!=null&&(t.tokens=W(n.dataset.maskaTokens));const e={};return n.dataset.maskaNumberLocale!=null&&(e.locale=n.dataset.maskaNumberLocale),n.dataset.maskaNumberFraction!=null&&(e.fraction=parseInt(n.dataset.maskaNumberFraction)),n.dataset.maskaNumberUnsigned!=null&&(e.unsigned=A(n.dataset.maskaNumberUnsigned)),(n.dataset.maskaNumber!=null||Object.values(e).length>0)&&(t.number=e),t},A=n=>n!==""?!!JSON.parse(n):!0,O=n=>n.startsWith("[")&&n.endsWith("]")?P(n):n,W=n=>{if(n.startsWith("{")&&n.endsWith("}"))return P(n);const s={};return n.split("|").forEach(t=>{const e=t.split(":");s[e[0]]={pattern:new RegExp(e[1]),optional:e[2]==="optional",multiple:e[2]==="multiple",repeated:e[2]==="repeated"}}),s};class x{constructor(s,t={}){y(this,"items",new Map);y(this,"onInput",s=>{if(s instanceof CustomEvent&&s.type==="input"&&!s.isTrusted)return;const t=s.target,e=this.items.get(t),a="inputType"in s&&s.inputType.startsWith("delete"),o=e.isEager(),h=a&&o&&e.unmasked(t.value)===""?"":t.value;this.fixCursor(t,a,()=>this.setValue(t,h))});this.options=t,this.init(this.getInputs(s))}update(s={}){this.options={...s},this.init(Array.from(this.items.keys()))}updateValue(s){s.value!==""&&s.value!==this.processInput(s).masked&&this.setValue(s,s.value)}destroy(){for(const s of this.items.keys())s.removeEventListener("input",this.onInput);this.items.clear()}init(s){const t=this.getOptions(this.options);for(const e of s){this.items.has(e)||e.addEventListener("input",this.onInput,{capture:!0});const a=new w(S(e,t));this.items.set(e,a),queueMicrotask(()=>this.updateValue(e)),e.selectionStart===null&&a.isEager()&&console.warn("Maska: input of `%s` type is not supported",e.type)}}getInputs(s){return typeof s=="string"?Array.from(document.querySelectorAll(s)):"length"in s?Array.from(s):[s]}getOptions(s){const{onMaska:t,preProcess:e,postProcess:a,...o}=s;return o}fixCursor(s,t,e){const a=s.selectionStart,o=s.value;if(e(),a===null||a===o.length&&!t)return;const h=s.value,u=o.slice(0,a),f=h.slice(0,a),i=this.processInput(s,u).unmasked,p=this.processInput(s,f).unmasked;let l=a;u!==f&&(l+=t?h.length-o.length:i.length-p.length),s.setSelectionRange(l,l)}setValue(s,t){const e=this.processInput(s,t);s.value=e.masked,this.options.onMaska!=null&&(Array.isArray(this.options.onMaska)?this.options.onMaska.forEach(a=>a(e)):this.options.onMaska(e)),s.dispatchEvent(new CustomEvent("maska",{detail:e})),s.dispatchEvent(new CustomEvent("input",{detail:e.masked}))}processInput(s,t){const e=this.items.get(s);let a=t??s.value;this.options.preProcess!=null&&(a=this.options.preProcess(a));let o=e.masked(a);return this.options.postProcess!=null&&(o=this.options.postProcess(o)),{masked:o,unmasked:e.unmasked(a),completed:e.completed(a)}}}exports.Mask=w;exports.MaskInput=x;exports.tokens=N; |
{ | ||
"name": "maska", | ||
"description": "Simple zero-dependency input mask for Vanilla JS, Vue, Alpine.js and Svelte", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "mask", |
@@ -13,3 +13,2 @@ <p align="center"> | ||
<a href="https://github.com/beholdr/maska/actions/workflows/build.yml"><img src="https://github.com/beholdr/maska/actions/workflows/build.yml/badge.svg"></a> | ||
<a href="https://github.com/beholdr/maska"><img src="https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/beholdr/7f2a04de5e494f9a3820832520ee2562/raw/badge.json"></a> | ||
</p> | ||
@@ -16,0 +15,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
54053
49