{"version":3,"file":"GradientWordsText.CMLdMRJO.mjs","names":["useState","useMemo","i","p"],"sources":["https:/framerusercontent.com/modules/lDA6XX4WMWcrSyrOOjO5/LRhk4dW8MehMwkGF1vrg/GradientWordsText.js"],"sourcesContent":["// Instructions: Create a Framer component that follows the Framer component rules and achieves the user's goal.\n// User goal: Apply a gradient to specific words within a longer text.\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useMemo,useState,useEffect}from\"react\";import{addPropertyControls,ControlType}from\"framer\";function escapeRegExp(input){return input.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\");}function isWordChar(ch){return/[A-Za-z0-9_]/.test(ch);}function boundaryOk(text,start,end){const before=start-1>=0?text[start-1]:\"\";const after=end<text.length?text[end]:\"\";const beforeOk=!before||!isWordChar(before);const afterOk=!after||!isWordChar(after);return beforeOk&&afterOk;}/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function GradientWordsText(props){const{text=\"Apply gradient to specific words within a longer text.\",highlights=[{word:\"gradient\",from:\"#8855FF\",to:\"#0099FF\",angle:90},{word:\"words\",from:\"#FF5588\",to:\"#FFBB00\",angle:90}],caseSensitive=false,matchWholeWord=true,baseTextColor=\"#000000\",fallbackHighlightColor=\"#000000\",font,highlightFont,variant=\"static\",animationDuration=3,style}=props;// STATO: Assumiamo true di default per il Server-Side Rendering\nconst[supportsGradientText,setSupportsGradientText]=useState(true);// EFFETTO: Controlliamo il reale supporto solo sul browser a componente montato\nuseEffect(()=>{const isSupported=typeof window!==\"undefined\"&&typeof CSS!==\"undefined\"&&// @ts-ignore\n(CSS.supports?.(\"-webkit-background-clip\",\"text\")||CSS.supports?.(\"background-clip\",\"text\"));if(!isSupported){setSupportsGradientText(false);}},[]);const isFixedWidth=!!style&&style.width===\"100%\";const isFixedHeight=!!style&&style.height===\"100%\";const parts=useMemo(()=>{const clean=(highlights||[]).map((h,i)=>({...h,_i:i,word:(h?.word??\"\").toString()})).filter(h=>h.word.trim().length>0);if(!text||clean.length===0)return[{type:\"text\",value:text??\"\"}];const haystack=caseSensitive?text:text.toLowerCase();const needles=clean.map(h=>({...h,needle:caseSensitive?h.word:h.word.toLowerCase()})).sort((a,b)=>b.needle.length-a.needle.length);const out=[];let i=0;let buffer=\"\";while(i<text.length){let best=null;for(const h of needles){const needle=h.needle;if(!needle)continue;if(i+needle.length>haystack.length)continue;if(haystack.startsWith(needle,i)){const start=i;const end=i+needle.length;if(matchWholeWord&&!boundaryOk(text,start,end))continue;best={start,end,meta:h};break;}}if(!best){buffer+=text[i];i+=1;continue;}if(buffer){out.push({type:\"text\",value:buffer});buffer=\"\";}const value=text.slice(best.start,best.end);out.push({type:\"highlight\",value,meta:{word:best.meta.word,from:best.meta.from,to:best.meta.to,angle:best.meta.angle,_i:best.meta._i}});i=best.end;}if(buffer)out.push({type:\"text\",value:buffer});return out;},[text,highlights,caseSensitive,matchWholeWord]);const baseFontStyle=font??{};const effectiveHighlightFontStyle={...baseFontStyle,...highlightFont??{}};const containerStyle={position:\"relative\",width:\"100%\",...isFixedHeight?{height:\"100%\"}:{},display:\"block\",color:baseTextColor,...baseFontStyle,...style};const textStyle={whiteSpace:\"pre-wrap\",wordBreak:\"break-word\",overflowWrap:\"anywhere\",...baseFontStyle,...isFixedWidth?{}:{minWidth:\"max-content\"}};const animationKeyframes=useMemo(()=>{if(variant!==\"animated\")return null;return`\n            @keyframes gradientShift {\n                0%, 100% {\n                    background-position: 0% 50%;\n                }\n                50% {\n                    background-position: 100% 50%;\n                }\n            }\n        `;},[variant]);return /*#__PURE__*/_jsxs(\"div\",{style:containerStyle,children:[animationKeyframes&&/*#__PURE__*/_jsx(\"style\",{children:animationKeyframes}),/*#__PURE__*/_jsx(\"span\",{style:textStyle,children:parts.map((p,idx)=>{if(p.type===\"text\"){return /*#__PURE__*/_jsx(\"span\",{children:p.value},`t-${idx}`);}const from=p.meta.from||\"#8855FF\";const to=p.meta.to||\"#0099FF\";const angle=Number.isFinite(p.meta.angle)?p.meta.angle:90;const gradientStyle={...effectiveHighlightFontStyle,backgroundImage:variant===\"animated\"?`linear-gradient(${angle}deg, ${from}, ${to}, ${from}, ${to})`:`linear-gradient(${angle}deg, ${from}, ${to})`,WebkitBackgroundClip:\"text\",backgroundClip:\"text\",color:\"transparent\",WebkitTextFillColor:\"transparent\",display:\"inline\",...variant===\"animated\"?{backgroundSize:\"200% 200%\",animation:`gradientShift ${animationDuration}s ease infinite`}:{}};const fallbackStyle={...effectiveHighlightFontStyle,color:fallbackHighlightColor};return /*#__PURE__*/_jsx(\"span\",{style:supportsGradientText?gradientStyle:fallbackStyle,children:p.value},`h-${p.meta._i}-${idx}`);})})]});}addPropertyControls(GradientWordsText,{text:{type:ControlType.String,title:\"Text\",defaultValue:\"Apply gradient to specific words within a longer text.\",displayTextArea:true},variant:{type:ControlType.Enum,title:\"Variant\",options:[\"static\",\"animated\"],optionTitles:[\"Static\",\"Animated\"],defaultValue:\"static\",displaySegmentedControl:true},animationDuration:{type:ControlType.Number,title:\"Duration\",defaultValue:3,min:.5,max:10,step:.5,unit:\"s\",hidden:({variant})=>variant!==\"animated\"},highlights:{type:ControlType.Array,title:\"Highlights\",defaultValue:[{word:\"gradient\",from:\"#8855FF\",to:\"#0099FF\",angle:90},{word:\"words\",from:\"#FF5588\",to:\"#FFBB00\",angle:90}],control:{type:ControlType.Object,controls:{word:{type:ControlType.String,title:\"Word\",defaultValue:\"gradient\"},from:{type:ControlType.Color,title:\"From\",defaultValue:\"#8855FF\"},to:{type:ControlType.Color,title:\"To\",defaultValue:\"#0099FF\"},angle:{type:ControlType.Number,title:\"Angle\",defaultValue:90,min:0,max:360,step:1,unit:\"deg\"}}},maxCount:20},caseSensitive:{type:ControlType.Boolean,title:\"Case Sensitive\",defaultValue:false,enabledTitle:\"On\",disabledTitle:\"Off\"},matchWholeWord:{type:ControlType.Boolean,title:\"Whole Word\",defaultValue:true,enabledTitle:\"On\",disabledTitle:\"Off\"},baseTextColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#000000\"},fallbackHighlightColor:{type:ControlType.Color,title:\"Fallback Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"22px\",variant:\"Semibold\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}},highlightFont:{type:ControlType.Font,title:\"Highlight Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"22px\",variant:\"Bold\",letterSpacing:\"-0.01em\",lineHeight:\"1.2em\"}}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"GradientWordsText\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GradientWordsText.map"],"mappings":"6MAE4O,SAAS,EAAW,EAAG,CAAC,MAAM,eAAe,KAAK,EAAG,CAAE,SAAS,EAAW,EAAK,EAAM,EAAI,CAAC,IAAM,EAAO,EAAM,GAAG,EAAE,EAAK,EAAM,GAAG,GAAS,EAAM,EAAI,EAAK,OAAO,EAAK,GAAK,GAAS,EAAS,CAAC,GAAQ,CAAC,EAAW,EAAO,CAAO,EAAQ,CAAC,GAAO,CAAC,EAAW,EAAM,CAAC,OAAO,GAAU,EAG5f,SAAwB,EAAkB,EAAM,CAAC,GAAK,CAAC,OAAK,yDAAyD,aAAW,CAAC,CAAC,KAAK,WAAW,KAAK,UAAU,GAAG,UAAU,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,KAAK,UAAU,GAAG,UAAU,MAAM,GAAG,CAAC,CAAC,gBAAc,GAAM,iBAAe,GAAK,gBAAc,UAAU,yBAAuB,UAAU,OAAK,gBAAc,UAAQ,SAAS,oBAAkB,EAAE,SAAO,EAC3Y,CAAC,EAAq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