{"version":3,"file":"ScrollColorText.BnM5iDA_.mjs","names":["useRef","useState","useMemo","endPos"],"sources":["https:/framerusercontent.com/modules/tQQwqhgiIruc1X8WqdBl/P6Si4PR1lD5OUulinIHf/ScrollColorText.js"],"sourcesContent":["// Text color animation on scroll - changes each character's color individually\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,useMemo,startTransition}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";import{useScroll,useTransform,motion}from\"framer-motion\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function ScrollTextColor(props){const{content=\"Hello World\",colorStart=\"#CCCCCC\",colorEnd=\"#000000\",trigger=\"layer-in-view\",animationStart=\"bottom\",animationEnd=\"center\",startOffset=0,replay=true,font}=props;const containerRef=useRef(null);const isStatic=useIsStaticRenderer();const[elementTop,setElementTop]=useState(0);const[elementHeight,setElementHeight]=useState(0);const{scrollY}=useScroll();// Calculate element position\nuseEffect(()=>{if(isStatic||!containerRef.current)return;const updatePosition=()=>{if(containerRef.current){const rect=containerRef.current.getBoundingClientRect();const scrollTop=window.pageYOffset||document.documentElement.scrollTop;startTransition(()=>{setElementTop(rect.top+scrollTop);setElementHeight(rect.height);});}};updatePosition();window.addEventListener(\"resize\",updatePosition);return()=>window.removeEventListener(\"resize\",updatePosition);},[isStatic,content]);// Split content into characters\nconst characters=useMemo(()=>{// Split by words, preserve spaces (line breaks will be preserved by whiteSpace: pre-wrap)\nconst words=content.split(/(\\s+)/);// Support *word* or _word_ to mark a single word as italic\n// now also when punctuation immediately follows (.,!?;: etc.)\nreturn words.map((word,index)=>{// Match *content*<trailing>  (trailing may be punctuation)\nconst matchAsterisk=word.match(/^\\*([^*]+)\\*(.*)$/);const matchUnderscore=word.match(/^_([^_]+)_(.*)$/);let italicWord=null;if(matchAsterisk){// keep trailing characters (e.g., \".\")\nitalicWord=matchAsterisk[1]+(matchAsterisk[2]||\"\");}else if(matchUnderscore){italicWord=matchUnderscore[1]+(matchUnderscore[2]||\"\");}return{word:italicWord??word,italic:Boolean(italicWord),index};});},[content]);// Calculate animation range based on trigger and positions\nconst getAnimationRange=()=>{const windowHeight=typeof window!==\"undefined\"?window.innerHeight:800;if(trigger===\"scroll-position\"){const startPos=0;const endPos=windowHeight;return[startPos,endPos];}else{const getPositionOffset=position=>{switch(position){case\"top\":return windowHeight;case\"center\":return windowHeight/2;case\"bottom\":return 0;default:return 0;}};const startPos=elementTop-getPositionOffset(animationStart);const endPos=elementTop-getPositionOffset(animationEnd);return[startPos,endPos];}};const isFixedWidth=props?.style&&props.style.width===\"100%\";if(isStatic){return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...props.style,color:colorStart,wordWrap:\"break-word\",overflowWrap:\"break-word\",// ✅ Preserve Shift+Enter line breaks\nwhiteSpace:\"pre-wrap\",...font},children:characters.map((item,i)=>/*#__PURE__*/_jsx(\"span\",{style:{color:colorStart,fontStyle:item.italic?\"italic\":undefined,display:\"inline\"},children:item.word},i))});}const[animationStartPos,animationEndPos]=getAnimationRange();const animationDistance=animationEndPos-animationStartPos;return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,style:{...props.style,wordWrap:\"break-word\",overflowWrap:\"break-word\",// ✅ Preserve Shift+Enter line breaks\nwhiteSpace:\"pre-wrap\",...font},children:characters.map((item,index)=>{const wordStartPos=animationStartPos+index/characters.length*animationDistance+startOffset;const wordEndPos=animationStartPos+(index+1)/characters.length*animationDistance+startOffset;const wordProgress=useTransform(scrollY,[wordStartPos,wordEndPos],[0,1],{clamp:!replay});return /*#__PURE__*/_jsx(motion.span,{style:{color:useTransform(wordProgress,[0,1],[colorStart,colorEnd]),fontStyle:item.italic?\"italic\":undefined,display:\"inline\"},children:item.word},index);})});}// Helper to map Framer font variant to font weight\nconst variantNameToFontWeight={Regular:400,Thin:100,\"Extra Light\":200,Light:300,Medium:500,Semibold:600,Bold:700,\"Extra Bold\":800,Black:900,\"Thin Italic\":100,\"Extra Light Italic\":200,\"Light Italic\":300,Italic:400,\"Medium Italic\":500,\"Semibold Italic\":600,\"Bold Italic\":700,\"Extra Bold Italic\":800,\"Black Italic\":900,\"Regular Italic\":400,Variable:400,\"Variable Italic\":400};function variantToFontWeight(variant){return variantNameToFontWeight[variant]||400;}addPropertyControls(ScrollTextColor,{font:{type:ControlType.Font,title:\"Font\",defaultValue:{variant:\"Semibold\"},controls:\"extended\",defaultFontType:\"sans-serif\"},content:{type:ControlType.String,title:\"Content\",defaultValue:\"Hello World\",displayTextArea:true},colorStart:{type:ControlType.Color,title:\"Start Color\",defaultValue:\"#CCCCCC\"},colorEnd:{type:ControlType.Color,title:\"End Color\",defaultValue:\"#000000\"},trigger:{type:ControlType.Enum,title:\"Trigger\",options:[\"layer-in-view\",\"scroll-position\"],optionTitles:[\"Layer in View\",\"Scroll Position\"],defaultValue:\"layer-in-view\"},animationStart:{type:ControlType.Enum,title:\"Start\",options:[\"top\",\"center\",\"bottom\"],optionTitles:[\"Top\",\"Center\",\"Bottom\"],defaultValue:\"bottom\",hidden:({trigger})=>trigger===\"scroll-position\"},animationEnd:{type:ControlType.Enum,title:\"End\",options:[\"top\",\"center\",\"bottom\"],optionTitles:[\"Top\",\"Center\",\"Bottom\"],defaultValue:\"center\",hidden:({trigger})=>trigger===\"scroll-position\"},startOffset:{type:ControlType.Number,title:\"Start Offset\",defaultValue:0,min:-1e3,max:1e3,step:10,unit:\"px\"},replay:{type:ControlType.Boolean,title:\"Replay\",defaultValue:true,enabledTitle:\"Yes\",disabledTitle:\"No\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ScrollTextColor\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\",\"framerSupportedLayoutWidth\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ScrollColorText.map"],"mappings":"2RAIG,SAAwB,EAAgB,EAAM,CAAC,GAA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