{"version":3,"file":"TextMagnifier_Prod.CSc_RM3c.mjs","names":["useRef","useMemo","_Fragment","useId"],"sources":["https:/framerusercontent.com/modules/pYGJbktLS5nZG5gcVsy0/rrCcSnsX0Ghwk1FVmlDD/TextMagnifier_Prod.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{useSpring,useMotionValue,useMotionValueEvent}from\"framer-motion\";import{useRef,useId,useMemo,useEffect}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n *\n * @framerDisableUnlink\n *\n * @framerIntrinsicWidth 400\n * @framerIntrinsicHeight 200\n */export default function MagneticText({text,color,font,transform,balance,userSelect,tag,style,range,smoothing,boldness}){const id=useInstanceId();const isCanvas=RenderTarget.current()===RenderTarget.canvas;const spanClassName=`${id}-span`;const Tag=tag;const textAlign=font?.textAlign||\"center\";const springTransition={damping:100,stiffness:mapRange(smoothing,0,100,2e3,50)};const hasSpring=smoothing!==0;const mouseX=useMotionValue(0);const mouseY=useMotionValue(0);const mouseXSpring=useSpring(mouseX,springTransition);const mouseYSpring=useSpring(mouseY,springTransition);const elementsRef=useRef([]);const initializedRef=useRef(false);const spanWidthsRef=useRef([]);useEffect(()=>{const handleMouseMove=e=>{mouseX.set(e.clientX);mouseY.set(e.clientY);if(!initializedRef.current){mouseXSpring.jump(e.clientX);mouseYSpring.jump(e.clientY);initializedRef.current=true;}};window.addEventListener(\"mousemove\",handleMouseMove);return()=>window.removeEventListener(\"mousemove\",handleMouseMove);},[]);const lines=useMemo(()=>{const textLines=text.split(\"\\n\");const lines=[];for(let i=0;i<textLines.length;i++){const line=textLines[i].split(/[ \\t]+/);lines.push(line);}return lines;},[text]);let index=0;const createLineChildren=(lineIndex,lineWords)=>{return lineWords.map((word,wordIndex)=>/*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"span\",{className:`${id}-word-wrapper`,children:word.split(\"\").map((char,charIndex)=>{const savedIndex=index;index++;return /*#__PURE__*/_jsx(\"span\",{ref:el=>{if(el)elementsRef.current[savedIndex]=el;},className:spanClassName,children:char},`${lineIndex}-${wordIndex}-${charIndex}`);})},`${lineIndex}-${wordIndex}`),wordIndex<lineWords.length-1&&\" \"]}));};const updateScale=(mx,my)=>{let cumulativeOffset=0;let elementOffset=[];let prevYPosition=0;const elementLineMap=new Map;const elementScaleMap=new Map;const lineOffsets=[];let lineIndex=-1;for(let i=0;i<elementsRef.current.length;i++){const element=elementsRef.current[i];if(!element)continue;const rect=element.getBoundingClientRect();const characterCenterX=rect.left+rect.width/2;const characterCenterY=rect.top+rect.height/2;const distance=Math.sqrt(Math.pow(characterCenterX-mx,2)+Math.pow(characterCenterY-my,2));const d=clamp01(mapRange(distance,range/2,0,0,1));const yPosition=rect.y+rect.height/2;if(Math.abs(yPosition-prevYPosition)>2){lineIndex++;if(lineIndex>0){lineOffsets[lineIndex-1]=cumulativeOffset;}cumulativeOffset=0;}prevYPosition=yPosition;elementLineMap.set(element,lineIndex);if(d<=0){element.style[\"-webkit-text-stroke-width\"]=\"\";elementOffset[i]=cumulativeOffset;}else{const scaleX=mapRange(d,0,1,1,mapRange(boldness,0,1,1,1.285))// 1.2\n;const scaleY=mapRange(d,0,1,1,mapRange(boldness,0,1,1,.928))// 0.95\n;const w=mapRange(d,0,1,0,boldness/10);const halfOffset=spanWidthsRef.current[i]*(scaleX-1)/2;elementScaleMap.set(element,[scaleX,scaleY]);cumulativeOffset+=halfOffset;elementOffset[i]=cumulativeOffset;cumulativeOffset+=halfOffset;element.style[\"-webkit-text-stroke-width\"]=`${w}em`;}if(i===elementsRef.current.length-1){lineOffsets[lineIndex]=cumulativeOffset;}}for(let i=0;i<elementsRef.current.length;i++){const element=elementsRef.current[i];if(!element)continue;const scaleValue=elementScaleMap.get(element);const scale=scaleValue?`scale(${scaleValue[0]}, ${scaleValue[1]})`:\"\";const offset=elementOffset[i];const lineIndex=elementLineMap.get(element)||0;const lineOffset=lineOffsets[lineIndex];let offsetValue=offset;switch(textAlign){case\"center\":offsetValue-=lineOffset/2;break;case\"right\":offsetValue-=lineOffset;break;}const translate=Math.abs(offsetValue)>.1?`translateX(${offsetValue}px)`:\"\";element.style.transform=translate&&scale?`${translate} ${scale}`:translate||scale;}};useMotionValueEvent(hasSpring?mouseXSpring:mouseX,\"change\",mx=>{if(mouseY){updateScale(mx,hasSpring?mouseYSpring.get():mouseY.get());}});useMotionValueEvent(hasSpring?mouseYSpring:mouseY,\"change\",my=>{if(mouseX){updateScale(hasSpring?mouseXSpring.get():mouseX.get(),my);}});useEffect(()=>{if(!isCanvas){elementsRef.current.forEach((el,i)=>{if(el){spanWidthsRef.current[i]=el.getBoundingClientRect().width;}});}},[isCanvas,text,font]);return /*#__PURE__*/_jsxs(Tag,{style:{position:\"relative\",cursor:\"default\",margin:0,whiteSpace:style?.width?\"pre\":\"nowrap\",fontWeight:400,textAlign,userSelect:userSelect?\"auto\":\"none\",textWrap:balance?\"balance\":undefined,textTransform:transform,color,...font,...style},children:[/*#__PURE__*/_jsx(\"style\",{children:`\n\t.${id}-line {\n\t\twidth: 100%;\n\t\tdisplay: block;\n\t\ttransform-style: preserve-3d;\n\t}\n\t.${id}-word-wrapper {\n\t\tdisplay: inline-block;\n\t\ttransform-style: preserve-3d;\n\t\twhite-space: pre;\n\t}\n\t.${id}-span {\n\t\tdisplay: inline-block;\n\t\ttransform-style: preserve-3d;\n\t\twhite-space: pre;\n\t\twill-change: transform, -webkit-text-stroke-width, padding-inline;\n\t\ttransform-origin: 50% 50%};\n\t\t-webkit-text-stroke-color: currentColor;\n\t}\n`}),lines.length===1?createLineChildren(0,lines[0]):lines.map((lineWords,lineIndex)=>/*#__PURE__*/_jsx(\"span\",{className:`${id}-line`,children:createLineChildren(lineIndex,lineWords)},lineIndex))]});}MagneticText.displayName=\"Text Magnifier\";addPropertyControls(MagneticText,{text:{type:ControlType.String,defaultValue:\"Learn Framer With Framer University\",displayTextArea:true},range:{type:ControlType.Number,defaultValue:200},smoothing:{type:ControlType.Number,defaultValue:50,min:0,max:100,step:1},boldness:{type:ControlType.Number,defaultValue:.7,min:0,max:1,step:.1},font:{type:\"font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:32,lineHeight:1.2}},color:{type:ControlType.Color,defaultValue:\"#999999\"},transform:{type:ControlType.Enum,defaultValue:\"none\",options:[\"none\",\"uppercase\",\"lowercase\"],optionTitles:[\"None\",\"Uppercase\",\"Lowercase\"]},balance:{type:ControlType.Boolean,defaultValue:false},userSelect:{type:ControlType.Boolean,defaultValue:false},tag:{type:ControlType.Enum,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 useInstanceId=()=>{const id=useId();const cleanId=id.replace(/:/g,\"\");const instanceId=`frameruni-${cleanId}`;return instanceId;};function mapRange(value,fromLow,fromHigh,toLow,toHigh){if(fromLow===fromHigh){return toLow;}const percentage=(value-fromLow)/(fromHigh-fromLow);return toLow+percentage*(toHigh-toLow);}function clamp01(value){return Math.max(0,Math.min(value,1));}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MagneticText\",\"slots\":[],\"annotations\":{\"framerIntrinsicWidth\":\"400\",\"framerContractVersion\":\"1\",\"framerDisableUnlink\":\"*\",\"framerIntrinsicHeight\":\"200\",\"framerSupportedLayoutWidth\":\"any\",\"framerSupportedLayoutHeight\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TextMagnifier_Prod.map"],"mappings":"4RAQG,SAAwB,EAAa,CAAC,OAAK,QAAM,OAAK,YAAU,UAAQ,aAAW,MAAI,QAAM,QAAM,YAAU,YAAU,CAAC,IAAM,EAAG,EAAc,EAAQ,EAAS,EAAa,QAAQ,IAAI,EAAa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