{"version":3,"file":"TextDecrypt_Prod.OlLCMisK.mjs","names":["useRef","useState"],"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,YAAY,EAAa,OAAa,EAAaA,EAAO,MAAY,EAAmBA,EAAO,GAAS,EAAYA,EAAO,GAAS,EAAcA,EAAO,EAAa,IAAa,CAAC,EAAK,EAAQ,CAACC,EAAS,EAAc,SAChT,CAAC,UAAQ,CAAC,EAAU,CAAC,OAAO,EAAa,OAAO,CAAC,YAAY,gBAAgB,CAAC,EACnF,MAAc,CAAC,IAAM,EAAY,EAAQ,GAAG,SAAS,GAAO,CAC5D,GAAG,IAAQ,EAAY,QAAQ,OAAO,EAAY,QAAQ,EAC1D,IAAM,EAAQ,EAAa,QAAQ,GAAG,CAAC,EAAQ,OAAO,IAAM,EAAK,EAAQ,wBAA8B,EAAe,EAAO,YAAkB,EAAW,EAAK,IAAU,EAAiB,EAAW,EACrM,GAAG,GAAkB,GAAG,CAAC,EAAQ,EAAM,MAAM,MAAQ,CAClD,KAAK,IAAI,EAAM,EAAmB,UAAU,KAAI,EAAc,QAAQ,EAAa,GAAO,EAAmB,QAAQ,GAExH,IAAM,EAAqB,GAAS,EAAmB,GAAiE,GAAxC,EAAqB,EAAsB,EAAiB,GAAoB,G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