(()=>{function b(i){i.directive("mask",(t,{value:e,expression:o},{effect:s,evaluateLater:f})=>{let n=()=>o,u="";if(["function","dynamic"].includes(e)){let r=f(o);s(()=>{n=c=>{let p;return i.dontAutoEvaluateFunctions(()=>{r(a=>{p=typeof a=="function"?a(c):a},{scope:{$input:c,$money:k.bind({el:t})}})}),p},l(t)})}else l(t);t.addEventListener("input",()=>l(t)),t.addEventListener("blur",()=>l(t,!1));function l(r,c=!0){let p=r.value,a=n(p);if(!a||a==="false")return!1;if(u.length-r.value.length==1)return u=r.value;let g=()=>{u=r.value=d(p,a)};c?I(r,a,()=>{g()}):g()}function d(r,c){if(r==="")return"";let p=h(c,r);return v(c,p)}})}function I(i,t,e){let o=i.selectionStart,s=i.value;e();let f=s.slice(0,o),n=v(t,h(t,f)).length;i.setSelectionRange(n,n)}function h(i,t){let e=t,o="",s={"9":/[0-9]/,a:/[a-zA-Z]/,"*":/[a-zA-Z0-9]/},f="";for(let n=0;n<i.length;n++){if(["9","a","*"].includes(i[n])){f+=i[n];continue}for(let u=0;u<e.length;u++)if(e[u]===i[n]){e=e.slice(0,u)+e.slice(u+1);break}}for(let n=0;n<f.length;n++){let u=!1;for(let l=0;l<e.length;l++)if(s[f[n]].test(e[l])){o+=e[l],e=e.slice(0,l)+e.slice(l+1),u=!0;break}if(!u)break}return o}function v(i,t){let e=Array.from(t),o="";for(let s=0;s<i.length;s++){if(!["9","a","*"].includes(i[s])){o+=i[s];continue}if(e.length===0)break;o+=e.shift()}return o}function k(i,t=".",e){e=t===","&&e===void 0?".":",";let o=(n,u)=>{let l="",d=0;for(let r=n.length-1;r>=0;r--)n[r]!==u&&(d===3?(l=n[r]+u+l,d=0):l=n[r]+l,d++);return l},s=i.replaceAll(new RegExp(`[^0-9\\${t}]`,"g"),""),f=Array.from({length:s.split(t)[0].length}).fill("9").join("");return f=o(f,e),i.includes(t)&&(f+=`${t}99`),queueMicrotask(()=>{this.el.value.endsWith(t)||this.el.value[this.el.selectionStart-1]===t&&this.el.setSelectionRange(this.el.selectionStart-1,this.el.selectionStart-1)}),f}document.addEventListener("alpine:init",()=>{window.Alpine.plugin(b)});})();