{"version":3,"file":"PhoneMaskController.BYYNakMI.mjs","names":[],"sources":["https:/framerusercontent.com/modules/yizwceTvg0HE8uCw3Xgj/Nc2NnDkVjQgpNKEwDnY9/PhoneMaskController.js"],"sourcesContent":["/**\n * v3.4\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 setReactInputValue=(input,value)=>{const nativeSetter=Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,\"value\")?.set;if(nativeSetter){nativeSetter.call(input,value);}else{input.value=value;}input.dispatchEvent(new Event(\"input\",{bubbles:true}));};let isApplyingMask=false;const applyPhoneMask=event=>{if(isApplyingMask)return;isApplyingMask=true;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;});setReactInputValue(event.target,newValue);isApplyingMask=false;};const handleBlur=event=>{const currentValue=event.target.value;const digitsOnly=currentValue.replace(/\\D/g,\"\");if(digitsOnly.length<=countryCodeLength){isApplyingMask=true;setReactInputValue(event.target,\"\");isApplyingMask=false;}};const restrictNameInput=event=>{const regex=/^[a-zA-Z\\u0400-\\u04FF\\s]*$/;if(!regex.test(event.target.value)){setReactInputValue(event.target,event.target.value.replace(/[^a-zA-Z\\u0400-\\u04FF\\s]/g,\"\"));}};const phoneFields=document.querySelectorAll('input[type=\"tel\" i]');const nameFields=document.querySelectorAll('input[name=\"name\" i], input[name=\"last-name\" i]');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\":{\"framerIntrinsicHeight\":\"1\",\"framerDisableUnlink\":\"*\",\"framerIntrinsicWidth\":\"1\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./PhoneMaskController.map"],"mappings":"mLAgBG,SAAwB,EAAoB,EAAM,CAAC,GAAK,CAAC,aAAW,EAAY,EAAiB,EAAU,MAAM,UAAU,EAAkE,GAA9C,EAAiB,EAAiB,GAAG,GAAA,CAAuC,OAAo1D,OAA70D,MAAc,CAAC,IAAM,GAAoB,EAAM,IAAQ,CAAC,IAAM,EAAa,OAAO,yBAAyB,EAAO,iBAAiB,UAAU,OAAO,CAAC,EAAE,IAAO,EAAc,EAAa,KAAK,EAAM,CAAK,EAAQ,EAAM,MAAM,EAAO,EAAM,cAAc,IAAI,MAA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