{"version":3,"file":"Recoloring_text.BCpHiQJ8.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/ZDJtWYJtXV2s8ptmN7MQ/HpjDsNoQ0ZhVtz5HotRk/Recoloring_text.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{motion,useScroll,useTransform}from\"framer-motion\";import{addPropertyControls,ControlType}from\"framer\";import{useRef,useEffect,useState}from\"react\";export default function ScrollColorTextComponent({text,font,fontSize,letterSpacing,lineHeight,alignment,startColor,endColor,scrollStartPx,scrollEndPx}){const ref=useRef(null);const[viewportHeight,setViewportHeight]=useState(0);useEffect(()=>{if(typeof window!==\"undefined\"){setViewportHeight(window.innerHeight);}},[]);const offsetStartPx=viewportHeight+scrollStartPx*-1;const{scrollYProgress}=useScroll({target:ref,offset:[`start ${offsetStartPx}px`,`end ${scrollEndPx}px`]});const allLetters=text?.replace(/\\s+/g,\"\").split(\"\")||[];const totalLetters=allLetters.length||1;const words=text?.split(\" \")||[];let globalLetterIndex=0;return /*#__PURE__*/_jsx(\"div\",{ref:ref,style:{textAlign:alignment,whiteSpace:\"normal\",wordWrap:\"break-word\",lineHeight:`${lineHeight}em`,fontFamily:font?.fontFamily||\"sans-serif\",fontWeight:font?.fontWeight||400,fontSize:`${fontSize}px`},children:words.map((word,wordIndex)=>/*#__PURE__*/_jsxs(\"span\",{style:{display:\"inline-block\",whiteSpace:\"nowrap\"},children:[word.split(\"\").map((letter,letterIndex)=>{const start=globalLetterIndex/totalLetters;const end=(globalLetterIndex+1)/totalLetters;globalLetterIndex++;const color=useTransform(scrollYProgress,[start,end],[startColor,endColor]);return /*#__PURE__*/_jsx(motion.span,{style:{color,display:\"inline-block\",whiteSpace:\"pre\",marginRight:letterIndex<word.length-1?`${letterSpacing}em`:undefined},children:letter===\" \"?\"\\xa0\":letter},`${wordIndex}-${letterIndex}`);}),/*#__PURE__*/_jsx(\"span\",{children:\"\\xa0\"})]},wordIndex))});}addPropertyControls(ScrollColorTextComponent,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Скролль, чтобы окрасить каждую букву.\"},font:{type:ControlType.Font,title:\"Font\",defaultFontType:\"sans-serif\",defaultValue:{fontFamily:\"Inter\",fontWeight:400}},fontSize:{type:ControlType.Number,title:\"Font Size\",defaultValue:48,min:10,max:200,unit:\"px\"},letterSpacing:{type:ControlType.Number,title:\"Letter Spacing (em)\",defaultValue:0,min:-.2,max:1,step:.01,unit:\"em\"},lineHeight:{type:ControlType.Number,title:\"Line Height (em)\",defaultValue:1.4,min:.5,max:3,step:.1,unit:\"em\"},alignment:{type:ControlType.Enum,title:\"Text Align\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\"},startColor:{type:ControlType.Color,title:\"Start Color\",defaultValue:\"#000000\"},endColor:{type:ControlType.Color,title:\"End Color\",defaultValue:\"#0070f3\"},scrollStartPx:{type:ControlType.Number,title:\"Scroll Start Offset (px)\",defaultValue:100,min:-500,max:1e3,unit:\"px\"},scrollEndPx:{type:ControlType.Number,title:\"Scroll End Offset (px)\",defaultValue:100,min:-500,max:1e3,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollColorTextComponent\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Recoloring_text.map"],"mappings":"4QAAmN,SAAwB,EAAyB,CAAC,OAAK,OAAK,WAAS,gBAAc,aAAW,YAAU,aAAW,WAAS,gBAAc,eAAa,CAAC,IAAM,EAAIA,EAAO,KAAK,CAAM,CAAC,EAAe,GAAmBC,EAAS,EAAE,CAAC,MAAc,CAAW,IAAS,QAAa,EAAkB,EAAO,YAAY,EAAI,EAAE,CAAC,CAAqD,GAAK,CAAC,mBAAiB,EAAU,CAAC,OAAO,EAAI,OAAO,CAAC,SAArF,EAAe,EAAc,GAA+E,IAA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