{"version":3,"file":"TextDecrypt_Prod.YTt2lDnl.mjs","names":[],"sources":["https:/framerusercontent.com/modules/hB0d6gqmsNIfIUrXpK5G/IbIxHgMmMV0zmVfjwCxS/TextDecrypt_Prod.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{useEffect,useState,useRef}from\"react\";import{useScroll}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n *\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 200\n */export default function TextDecrypt(props){var _props_style;const isCanvas=RenderTarget.current()===RenderTarget.canvas;const componentRef=useRef(null);const lastUpdatePosition=useRef(0);const lastScrollY=useRef(0);const encryptedText=useRef(randomString(props));const[text,setText]=useState(encryptedText.current);// Setup scroll tracking with raw values instead of progress\nconst{scrollY}=useScroll({target:componentRef,offset:[\"start end\",\"center center\"]});// Update text on scroll\nuseEffect(()=>{const unsubscribe=scrollY.on(\"change\",value=>{// Skip if we haven't actually scrolled\nif(value===lastScrollY.current)return;lastScrollY.current=value;// Get component's position relative to viewport\nconst element=componentRef.current;if(!element)return;const rect=element.getBoundingClientRect();const viewportHeight=window.innerHeight;const elementTop=rect.top;const relativePosition=elementTop/viewportHeight;// If element is above the 0.5 threshold, keep it fully decrypted\nif(relativePosition<=.5){setText(props.text);return;}// Update random characters every 10px\nif(Math.abs(value-lastUpdatePosition.current)>=10){encryptedText.current=randomString(props);lastUpdatePosition.current=value;}// Calculate encryption percentage based on position\n// 0.8 = 100% encrypted, 0.5 = 0% encrypted\nconst encryptionRangeStart=.8;const encryptionRangeEnd=.5;const encryptionRange=encryptionRangeStart-encryptionRangeEnd;if(relativePosition>encryptionRangeEnd&&relativePosition<=encryptionRangeStart){const percentage=(relativePosition-encryptionRangeEnd)/encryptionRange;const numberOfEncryptedCharacters=Math.floor((props.text.length-1)*percentage)+1;if(numberOfEncryptedCharacters===0){setText(props.text);}else{setText(props.text.slice(0,-numberOfEncryptedCharacters)+encryptedText.current.slice(-numberOfEncryptedCharacters));}}else if(relativePosition>encryptionRangeStart){// Ensure it stays fully encrypted above the 0.8 threshold\nsetText(encryptedText.current);}});return()=>unsubscribe();},[props.text,props.characters,props.options.matchCase,props.options.keepSpaces,scrollY]);const Tag=props.tag;return /*#__PURE__*/_jsx(Tag,{ref:componentRef,style:{color:props.color,userSelect:props.userSelect?\"auto\":\"none\",margin:0,whiteSpace:((_props_style=props.style)===null||_props_style===void 0?void 0:_props_style.width)?undefined:\"nowrap\",...props.font,...props.style},children:isCanvas?randomString(props):text});}TextDecrypt.displayName=\"Scroll Decrypt\";addPropertyControls(TextDecrypt,{text:{type:ControlType.String,defaultValue:\"Text Decrypt\",displayTextArea:true},characters:{type:ControlType.String,defaultValue:\"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+[]{}|;:,.<>?~\",displayTextArea:true},options:{type:ControlType.Object,buttonTitle:\"Options\",controls:{matchCase:{type:ControlType.Boolean,defaultValue:true},keepSpaces:{type:ControlType.Boolean,defaultValue:false}}},font:{type:\"font\",controls:\"extended\",defaultFontType:\"monospace\",defaultValue:{fontSize:24,lineHeight:1.4}},color:{type:ControlType.Color,defaultValue:\"#000\"},userSelect:{type:ControlType.Boolean,defaultValue:true},tag:{type:ControlType.Enum,title:\"Tag\",defaultValue:\"p\",displaySegmentedControl:true,options:[\"h1\",\"h2\",\"h3\",\"p\"],optionTitles:[\"H1\",\"H2\",\"H3\",\"P\"],description:\"More components at [Framer University](https://frameruni.link/cc).\"}});const randomString=props=>{const length=props.text.length;const characters=props.characters;const originalText=props.text;const matchCase=props.options.matchCase;const keepSpaces=props.options.keepSpaces;if(length<=0){return\"\";}let result=\"\";let lastChar=\"\";for(let i=0;i<length;i++){const originalChar=originalText[i];// Preserve spaces and tabs if keepSpaces is true\nif(keepSpaces&&(originalChar===\" \"||originalChar===\"\t\")){result+=originalChar;continue;}let newChar;do{newChar=characters[Math.floor(Math.random()*characters.length)];// Match case if matchCase is true\nif(matchCase&&originalChar){newChar=originalChar===originalChar.toUpperCase()?newChar.toUpperCase():newChar.toLowerCase();}}while(newChar===lastChar&&characters.length>=8)result+=newChar;lastChar=newChar;}return result;};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextDecrypt\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any\",\"framerDisableUnlink\":\"*\",\"framerContractVersion\":\"1\",\"framerIntrinsicWidth\":\"400\",\"framerSupportedLayoutHeight\":\"any\",\"framerIntrinsicHeight\":\"200\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextDecrypt_Prod.map"],"mappings":"+ZAQG,SAAwB,EAAY,EAAM,CAAC,IAAI,EAAa,IAAM,EAAS,EAAa,SAAS,GAAG,EAAa,OAAa,EAAa,EAAO,KAAK,CAAO,EAAmB,EAAO,EAAE,CAAO,EAAY,EAAO,EAAE,CAAO,EAAc,EAAO,EAAa,EAAM,CAAC,CAAM,CAAC,EAAK,EAAQ,CAAC,EAAS,EAAc,QAAQ,CACxT,CAAC,UAAQ,CAAC,EAAU,CAAC,OAAO,EAAa,OAAO,CAAC,YAAY,eAAgB,CAAC,EAAC,CACpF,EAAU,IAAI,CAAC,IAAM,EAAY,EAAQ,GAAG,SAAS,GAAO,CAC5D,GAAG,IAAQ,EAAY,QAAQ,OAAO,EAAY,QAAQ,EAC1D,IAAM,EAAQ,EAAa,QAAQ,IAAI,EAAQ,OAAO,IAAM,EAAK,EAAQ,uBAAuB,CAAO,EAAe,EAAO,YAAkB,EAAW,EAAK,IAAU,EAAiB,EAAW,EACrM,GAAG,GAAkB,GAAG,CAAC,EAAQ,EAAM,KAAK,CAAC,MAAQ,CACrD,AAAG,KAAK,IAAI,EAAM,EAAmB,QAAQ,EAAE,KAAI,EAAc,QAAQ,EAAa,EAAM,CAAC,EAAmB,QAAQ,GAExH,IAA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