{"version":3,"file":"PhoneMaskController.CEUdVAbd.mjs","names":["__esmMin","init_npm_react_18_3_1","ce","c","init_jsx_runtime","addPropertyControls","ControlType","init_framer_DcxuU94H","PhoneMaskController","props","countryCodeMatch","phoneMask","countryCodeLength","applyPhoneMask","matrix","i","def","currentValue","event","newValue","a","handleBlur","customEvent","restrictNameInput","phoneFields","nameFields","phoneField","nameField","init_PhoneMaskController"],"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":"A,2KAgBG,SAAwBQ,EAAoB,EAAM,CAAC,GAAK,CAAC,aAAWC,EAAYC,EAAiBC,EAAU,MAAM,UAAU,EAAkEC,GAA9CF,EAAiBA,EAAiB,GAAG,GAAA,CAAuC,OAAu8C,OAAh8CR,MAAc,CAAC,IAAMW,EAAe,GAAO,CAAC,IAAMC,EAAOH,EAAcI,EAAE,EAAQC,EAAIF,EAAO,QAAQ,MAAM,EAAE,EAAMG,EAAaC,EAAM,OAAO,MAAM,QAAQ,MAAM,EAAE,EAAKF,EAAI,QAAQC,EAAa,SAAQ,EAAaD,GAAK,IAAMG,EA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