{"version":3,"file":"PhoneMaskController.CeDkPyEB.mjs","names":[],"sources":["https:/framerusercontent.com/modules/yizwceTvg0HE8uCw3Xgj/uOlDWpHMgW1rEgncKWSU/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 (sergeichyrkov.com, x.com/sergeichyrkov) at chyrkov.studio\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\":{\"framerContractVersion\":\"1\",\"framerIntrinsicHeight\":\"1\",\"framerIntrinsicWidth\":\"1\",\"framerDisableUnlink\":\"*\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PhoneMaskController.map"],"mappings":"kQAgBG,SAAwB,EAAoB,EAAM,CAAC,GAAK,CAAC,aAAW,EAAY,EAAiB,EAAU,MAAM,WAAW,CAAiE,GAA9C,EAAiB,EAAiB,GAAG,IAAuC,OAAu8C,OAAh8C,MAAc,CAAC,IAAM,EAAe,GAAO,CAAC,IAAM,EAAO,EAAc,EAAE,EAAQ,EAAI,EAAO,QAAQ,MAAM,GAAG,CAAK,EAAa,EAAM,OAAO,MAAM,QAAQ,MAAM,GAAG,CAAI,EAAI,QAAQ,EAAa,SAAQ,EAAa,GAAK,IAAM,EAAS,EAAO,QAAQ,KAAK,SAAS,EAAE,CAAC,MAAM,QAAQ,KAAK,EAAE,EAAE,EAAE,EAAa,OAAO,EAAa,OAAO,IAAI,CAAC,GAAG,EAAa,OAAO,GAAG,GAAI,CAAC,EAAM,OAAO,MAAM,GAAiB,EAAW,GAAO,CAAuF,GAAnE,EAAM,OAAO,MAAoC,QAAQ,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