{"version":3,"file":"PhoneMaskController.C_KGyq4D.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,YAAU,CAAC,EAAY,EAAiB,EAAU,MAAM,YAAkB,EAAY,EAAiB,EAAiB,GAAG,GAAS,EAAkB,EAAY,OAAu8C,OAAh8C,MAAc,CAAC,IAAM,EAAe,GAAO,CAAC,IAAM,EAAO,EAAc,EAAE,EAAQ,EAAI,EAAO,QAAQ,MAAM,IAAQ,EAAa,EAAM,OAAO,MAAM,QAAQ,MAAM,IAAO,EAAI,QAAQ,EAAa,SAAQ,EAAa,GAAK,IAAM,EAAS,EAAO,QAAQ,KAAK,SAAS,EAAE,CAAC,MAAM,QAAQ,KAAK,IAAI,EAAE,EAAa,OAAO,EAAa,OAAO,KAAK,GAAG,EAAa,OAAO,GAAG,CAAG,GAAE,EAAM,OAAO,MAAM,CAAU,EAAO,EAAW,GAAO,CAAC,IAAM,EAAa,EAAM,OAAO,MAAY,EAAW,EAAa,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