(function(c,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],i):(c=typeof globalThis<"u"?globalThis:c||self,i(c["React input mask"]={},c.React))})(this,function(c,i){"use strict";const U=typeof window<"u"?i.useLayoutEffect:i.useEffect,_=()=>{const t=i.useRef();return U(()=>{t.current&&(t.current(),t.current=void 0)}),n=>{t.current=n}},I=(t,e=T)=>e.test(t),A=(t,e=y)=>e.test(t),h=t=>t==="*",M=t=>t==="A"||t==="9"||t==="*",j=(t,e)=>{let n=0;return t.split("").map(r=>{if(!M(r))return r;const u=e[n];return u&&(r==="*"||r==="A"&&I(e[n])||r==="9"&&A(e[n]))?(n+=1,u):r}).join("")},R=(t,e,n=0)=>t.slice(0,n)+t.slice(n,t.length).replaceAll("*",e).replaceAll("A",e).replaceAll("9",e),O=(t,e)=>{let n=0;return t.split("").filter(s=>n>=e?!1:M(s)?(n+=1,!1):!0).length},D=(t,e,n)=>{const s=j(e,t),r=O(e,t.length);return R(s,n,t.length+r)},L=({filteredMask:t,value:e,rawValue:n,currentMaskChar:s,charRegex:r,numRegex:u})=>e.length>1||t.length===n.length?!1:G(e,s,r,u),G=(t,e,n,s)=>!!(I(t,n)&&I(e,n)||A(t,s)&&A(e,s)||h(e)),W=(t,e)=>t.selectionStart===0&&t.selectionEnd===e.length,X=(t,e)=>{if(t.value=e,typeof document>"u")return;const n=document.createEvent("HTMLEvents");n.initEvent("change",!0,!1),t.dispatchEvent(n)},b=(t="",e="",n,s,r)=>{const u={maskValue:R(t,r),rawValue:""};if(!t||!e)return u;const f=t.replace(/[^A9*]+/g,"");return e.split("").every((a,p)=>L({value:a,currentMaskChar:f[p],charRegex:n,numRegex:s,filteredMask:f,rawValue:e.slice(0,p)}))?{maskValue:D(e,t,r),rawValue:e}:u},v=(t,e,n,s,r)=>{const u={maskValue:R(t,r),rawValue:""};if(e.length!=t.length)return u;const f=t.split("");if(f.every((l,a)=>M(l)?G(e[a],l,n,s):l===e[a])){const l=f.map((a,p)=>M(a)?e[p]:"").join("");return{maskValue:e,rawValue:l}}return u},K=(t="",e="",n,s,r,u)=>n==="mask"?v(t,e,s,r,u):b(t,e,s,r,u),T=/^[a-zA-Z]*$/,y=/^[0-9]*$/;function $({mask:t="",placeholderChar:e="_",type:n="raw",value:s,charRegex:r=T,numRegex:u=y}){const f=/[^A9*]+/g,w=t==null?void 0:t.replace(f,""),l=_(),{maskValue:a,rawValue:p}=i.useMemo(()=>K(t,s,n,r,u,e),[t,s,n,r,u,e]),[g,q]=i.useState(p),[z,B]=i.useState(a),P=(o,d,V)=>{q(o);const E=D(o,t,e);B(E);const k=n==="raw"?o:E;X(V.target,k),l(()=>{const S=E.indexOf(e);d.setSelectionRange(S,S)})},F=o=>{const d=o.key,V=o.target,E=g.length,k=w[E];if(o.ctrlKey&&o.key.toLowerCase()==="a"){o.preventDefault(),V.setSelectionRange(0,t.length);return}if(d==="Tab"||d==="Enter")return;if(o.preventDefault(),d==="Backspace"&&g.length>0){const N=W(V,t)?"":g.slice(0,-1);return P(N,V,o)}if(!L({value:d,currentMaskChar:k,charRegex:r,numRegex:u,filteredMask:w,rawValue:g}))return;const H=g+d;P(H,V,o)};return{getInputProps:()=>t?{value:z,onKeyDown:F}:{}}}c.DIGIT_REGEX=y,c.LETTER_REGEX=T,c.useInputMask=$,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});