{"version":3,"file":"PhoneMaskController.CSbC4e-N.mjs","names":[],"sources":["https:/framerusercontent.com/modules/yizwceTvg0HE8uCw3Xgj/TOAPG8DhHbMYannuhKNS/PhoneMaskController.js"],"sourcesContent":["/**\n * v2.0\n * Name and Phone Mask Validation for Framer\n * You may use this asset for personal and commercial use.\n * Created by Sergei Chyrkov (x.com/sergeichyrkov) at sergeichyrkov.com\n *\n * Redistribution of this work is NOT permitted, re-sharing or altering it\n * in a way that misrepresents authorship is not allowed. Proper attribution is required.\n *\n * Hope you enjoy using it!\n *\n */import{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 1\n * @framerIntrinsicHeight 1\n */export default function PhoneMaskController(props){const{phoneMask}=props;const countryCodeMatch=phoneMask.match(/^\\+(\\d+)/);const countryCode=countryCodeMatch?countryCodeMatch[1]:\"\";const countryCodeLength=countryCode.length;useEffect(()=>{const applyPhoneMask=event=>{const matrix=phoneMask;let i=0;const def=matrix.replace(/\\D/g,\"\");let currentValue=event.target.value.replace(/\\D/g,\"\");if(def.length>=currentValue.length){currentValue=def;}const newValue=matrix.replace(/./g,function(a){return/[_\\d]/.test(a)&&i<currentValue.length?currentValue.charAt(i++):i>=currentValue.length?\"\":a;});event.target.value=newValue;};const handleBlur=event=>{const currentValue=event.target.value;const digitsOnly=currentValue.replace(/\\D/g,\"\");if(digitsOnly.length<=countryCodeLength){event.target.value=\"\";const customEvent=new Event(\"change\");event.target.dispatchEvent(customEvent);}};const restrictNameInput=event=>{const regex=/^[a-zA-Z\\u0400-\\u04FF\\s]*$/;if(!regex.test(event.target.value)){event.target.value=event.target.value.replace(/[^a-zA-Z\\u0400-\\u04FF\\s]/g,\"\");}};const phoneFields=document.querySelectorAll('input[type=\"tel\"]');const nameFields=document.querySelectorAll('input[name=\"name\"]');phoneFields.forEach(phoneField=>{phoneField.addEventListener(\"input\",applyPhoneMask);phoneField.addEventListener(\"blur\",handleBlur);});nameFields.forEach(nameField=>{nameField.addEventListener(\"input\",restrictNameInput);});return()=>{phoneFields.forEach(phoneField=>{phoneField.removeEventListener(\"input\",applyPhoneMask);phoneField.removeEventListener(\"blur\",handleBlur);});nameFields.forEach(nameField=>{nameField.removeEventListener(\"input\",restrictNameInput);});};},[phoneMask,countryCodeLength]);return /*#__PURE__*/_jsx(\"div\",{style:{width:0,height:0,position:\"absolute\",opacity:0,pointerEvents:\"none\"}});}addPropertyControls(PhoneMaskController,{phoneMask:{type:ControlType.String,title:\"Phone Mask\",defaultValue:\"+1 (___) ___-__-__\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"PhoneMaskController\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"1\",\"framerDisableUnlink\":\"*\",\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PhoneMaskController.map"],"mappings":"2KAgBG,SAAwB,EAAoB,EAAM,CAAC,GAAK,CAAC,aAAW,EAAY,EAAiB,EAAU,MAAM,UAAU,EAAkE,GAA9C,EAAiB,EAAiB,GAAG,GAAA,CAAuC,OAAu8C,OAAh8C,MAAc,CAAC,IAAM,EAAe,GAAO,CAAC,IAAM,EAAO,EAAc,EAAE,EAAQ,EAAI,EAAO,QAAQ,MAAM,EAAE,EAAM,EAAa,EAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,EAAK,EAAI,QAAQ,EAAa,SAAQ,EAAa,GAAK,IAAM,EAAS,EAAO,QAAQ,KAAK,SAAS,EAAE,CAAC,MAAM,QAAQ,KAAK,CAAC,GAAG,EAAE,EAAa,OAAO,EAAa,OAAO,GAAG,EAAE,GAAG,EAAa,OAAO,GAAG,CAAE,CAAC,EAAE,EAAM,OAAO,MAAM,CAAS,EAAQ,EAAW,GAAO,CAAuF,GAAnE,EAAM,OAAO,MAAoC,Q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