{"version":3,"file":"TextPro.D3biHaVL.mjs","names":["useState","useMemo"],"sources":["https:/framerusercontent.com/modules/dqTAkSmLH1iWI2I3ThDP/7teUVMjnzsN47CX4txty/TextPro.js"],"sourcesContent":["// import React, { useState, useEffect, cloneElement, isValidElement } from \"react\"\n// import { addPropertyControls, ControlType, RenderTarget } from \"framer\"\n// import { GlobalFont, GlobalStyles, screenSize } from \"../0_Global/Style.tsx\"\n// import { colorpattle } from \"../0_CSS/Theme.tsx\"\n// // import { GlobalFont, GlobalStyles, screenSize } from \"../0_Global/Style.tsx\"\n// /**\n//  * @framerDisableUnlink\n//  */\n// export default function TextPro(props) {\n//     const {\n//         textitem,\n//         fontsize,\n//         fontweight,\n//         fontColor,\n//         fontSysColor,\n//         SameAlign,\n//         align,\n//         ...elseprops\n//     } = props\n//     const evi =\n//         RenderTarget.current() === RenderTarget.preview ||\n//         RenderTarget.current() === RenderTarget.export ||\n//         RenderTarget.current() === RenderTarget.canvas\n//     const Wsize = screenSize()\n//     //const mode = localStorage.getItem(\"theme\") === \"dark\" ? \"dark\" : \"light\"\n//     const tfontColor =\n//         fontSysColor !== \"none\" ? \"var(\" + fontSysColor + \")\" : fontColor\n//     //fontSysColor !== \"none\" ? colorpattle[fontSysColor][mode] : fontColor\n//     // console.log(\"hi color\")\n//     // console.log(tfontColor, mode)\n//     const element =\n//         Array.isArray(textitem) && textitem.length > 0 ? textitem[0] : textitem\n//     const [textobj, settext] = useState(null)\n//     //console.log(element)\n//     useEffect(() => {\n//         if (Object.keys(element).length !== 0) {\n//             try {\n//                 const FirstStyle = {\n//                     ...element?.props?.children?.props?.children?.props\n//                         ?.children?.props?.style,\n//                     ...GlobalFont.fontsize[fontsize][Wsize],\n//                 }\n//                 const combinedStyle = {\n//                     ...FirstStyle,\n//                     ...GlobalFont.weight[fontweight],\n//                     \"--framer-text-color\": tfontColor,\n//                     ...(!SameAlign && { \"--framer-text-alignment\": align }),\n//                 }\n//                 //console.log(combinedStyle)\n//                 let element2 = cloneElement(element)\n//                 // console.log(element2.props)\n//                 if (evi) {\n//                     let target =\n//                         element2?.props?.children?.props?.children?.props\n//                             ?.children\n//                     if (target) {\n//                         target.type = GlobalFont.fontsize[fontsize][Wsize].type\n//                         target.props.style = combinedStyle\n//                     }\n//                 }\n//                 const cElement = cloneElement(element2, {\n//                     ...element2.props,\n//                     style: {\n//                         ...element2.props.style,\n//                         width: \"100%\",\n//                         // 添加其他的样式属性\n//                     },\n//                 })\n//                 settext(cElement)\n//             } catch (error) {\n//                 console.log(\"文字核心组件错误\", error.message, error, element)\n//                 // console.log(element)\n//             }\n//         }\n//     }, [textitem])\n//     // console.log(\"修改的数值:\")\n//     // console.log(\n//     //     React.isValidElement(clonedElement) ? clonedElement : \"啥也没有\"\n//     // )\n//     // <div className=\"tooltip-container\">\n//     //     Hover over me\n//     //     <GlobalStyles />\n//     //     <span className=\"tooltip-text\">This is the tooltip text!</span>\n//     // </div>\n//     if (isValidElement(textobj)) {\n//         return <div>{textobj}</div>\n//     } else {\n//         //return <h1>Add Textitem first</h1>\n//         return null\n//     }\n// }\n// addPropertyControls(TextPro, {\n//     textitem: {\n//         type: ControlType.ComponentInstance,\n//     },\n//     fontsize: {\n//         type: ControlType.Enum,\n//         // displaySegmentedControl: true,\n//         // segmentedControlDirection: \"vertical\",\n//         options: Object.keys(GlobalFont.fontsize),\n//         optionTitles: Object.keys(GlobalFont.fontsize),\n//     },\n//     fontweight: {\n//         type: ControlType.Enum,\n//         defaultValue: \"regular\",\n//         // displaySegmentedControl: true,\n//         // segmentedControlDirection: \"vertical\",\n//         options: Object.keys(GlobalFont.weight),\n//         optionTitles: Object.keys(GlobalFont.weight),\n//     },\n//     fontSysColor: {\n//         type: ControlType.Enum,\n//         defaultValue: \"none\",\n//         options: [\"none\", ...Object.keys(colorpattle)],\n//     },\n//     fontColor: {\n//         type: ControlType.Color,\n//         defaultValue:\n//             colorpattle[\"--text-p-color\"][\n//                 localStorage.getItem(\"theme\") === \"dark\" ? \"dark\" : \"light\"\n//             ],\n//         hidden(props) {\n//             return props.fontSysColor !== \"none\"\n//         },\n//     },\n//     SameAlign: {\n//         type: ControlType.Boolean,\n//         defaultValue: true,\n//     },\n//     align: {\n//         type: ControlType.Enum,\n//         options: [\"left\", \"center\", \"right\"],\n//         optionIcons: [\n//             \"text-align-left\",\n//             \"text-align-center\",\n//             \"text-align-right\",\n//         ],\n//         displaySegmentedControl: true,\n//         hidden(props) {\n//             return props.SameAlign\n//         },\n//     },\n// })\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useState,useEffect,useLayoutEffect,cloneElement,isValidElement,useMemo}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";import{GlobalFont,screenSize}from\"https://framerusercontent.com/modules/20zhayqm9y3Y0ekkXAdJ/RJxcqD9cS3BOBLZBK92L/Style.js\";import{colorpattle}from\"https://framerusercontent.com/modules/niZ6YpK06zTaQeX49VIS/kyUI2MH03eq9506I17so/Theme.js\";// 在组件外部，只执行一次\nlet styleInjected=false;/**\n * @framerDisableUnlink\n */export default function TextPro(props){const{textitem,fontsize,fontweight,fontColor,fontSysColor,SameAlign,align,autoline,...restProps}=props;// 添加客户端状态检查\nconst[isClient,setIsClient]=useState(false);const[renderedText,setRenderedText]=useState(null);// 客户端挂载检查\nuseLayoutEffect(()=>{setIsClient(true);},[]);// 安全地获取主题\nconst getTheme=()=>{if(typeof window!==\"undefined\"&&window.localStorage){return localStorage.getItem(\"theme\")===\"dark\"?\"dark\":\"light\";}return\"light\"// 服务器端默认\n;};// 安全地检查渲染环境\nconst isRenderEnv=useMemo(()=>{if(typeof window===\"undefined\")return false;try{return[RenderTarget.preview,RenderTarget.export,RenderTarget.canvas].includes(RenderTarget.current());}catch(error){console.warn(\"RenderTarget check failed:\",error);return false;}},[isClient]);// 安全地获取屏幕尺寸\nconst Wsize=useMemo(()=>{if(!isClient)return\"desktop\"// 服务器端默认\n;try{return screenSize();}catch(error){console.warn(\"screenSize check failed:\",error);return\"desktop\";}},[isClient]);// 自动处理系统色 or 自定义色\nconst computedColor=useMemo(()=>{return fontSysColor!==\"none\"?`var(${fontSysColor})`:fontColor;},[fontSysColor,fontColor]);// 提取并缓存 element\nconst element=useMemo(()=>Array.isArray(textitem)?textitem[0]:textitem,[textitem]);// const styleTag = useMemo(\n//     () => (\n//         <style>{`\n//     .textpro-wrapper,\n//     .textpro-wrapper * {\n//         opacity: 1 !important;\n//     }\n// `}</style>\n//     ),\n//     []\n// ) // 空依赖，只创建一次\n// 📌 移到 useEffect 外面，变成独立的 useMemo\nconst computedStyle=useMemo(()=>({...GlobalFont.fontsize[fontsize]?.[Wsize],...GlobalFont.weight[fontweight],\"--framer-text-color\":computedColor,...!SameAlign&&{\"--framer-text-alignment\":align},...autoline>0&&{overflow:\"hidden\",display:\"-webkit-box\",WebkitLineClamp:autoline,WebkitBoxOrient:\"vertical\",textOverflow:\"ellipsis\",whiteSpace:\"normal\",wordBreak:\"break-word\"}}),[fontsize,Wsize,fontweight,computedColor,SameAlign,align,autoline]);useEffect(()=>{// 只在客户端执行\nif(!isClient||!element||!/*#__PURE__*/isValidElement(element)){setRenderedText(null);return;}try{// 找到嵌套的 text 元素\nconst nestedText=element?.props?.children?.props?.children?.props?.children;// ✅ 直接合并，不用重新计算\nconst baseStyle={...nestedText?.props?.style,...computedStyle};// const baseStyle = {\n//     ...nestedText?.props?.style,\n//     ...GlobalFont.fontsize[fontsize]?.[Wsize],\n//     ...GlobalFont.weight[fontweight],\n//     \"--framer-text-color\": computedColor,\n//     ...(!SameAlign && {\n//         \"--framer-text-alignment\": align,\n//     }),\n//     ...(autoline > 0 && {\n//         overflow: \"hidden\",\n//         display: \"-webkit-box\",\n//         WebkitLineClamp: autoline,\n//         WebkitBoxOrient: \"vertical\",\n//         textOverflow: \"ellipsis\",\n//         whiteSpace: \"normal\",\n//         wordBreak: \"break-word\",\n//     }),\n// }\nif(isRenderEnv&&nestedText){nestedText.type=GlobalFont.fontsize[fontsize]?.[Wsize]?.type;nestedText.props.style=baseStyle;}const wrappedElement=/*#__PURE__*/cloneElement(element,{...element.props,style:{...element.props.style,width:\"100%\"}});setRenderedText(wrappedElement);}catch(error){console.error(\"TextPro 错误:\",error.message,error);//setRenderedText(null)\n}},[isClient,element,computedStyle])// ⚠️ 依赖项也要改\n;// [\n//     isClient, // 添加 isClient 依赖\n//     element,\n//     fontsize,\n//     fontweight,\n//     computedColor,\n//     SameAlign,\n//     align,\n//     autoline,\n//     Wsize,\n//     isRenderEnv,\n// ])\n// 服务器端渲染占位符\nif(!isClient){return /*#__PURE__*/_jsx(\"div\",{style:{minHeight:\"40px\",opacity:1,visibility:\"hidden\"},children:\"Loading...\"});}// 客户端渲染,{styletag专门应对属性隐藏}\nreturn /*#__PURE__*/isValidElement(renderedText)?/*#__PURE__*/_jsx(\"div\",{style:{width:\"100%\"},children:renderedText})://     // {styleTag}\n//     {renderedText}\n// </div>\nnull;}// 安全地获取默认颜色值\nconst getDefaultColor=()=>{try{if(typeof window!==\"undefined\"&&window.localStorage){const theme=localStorage.getItem(\"theme\")===\"dark\"?\"dark\":\"light\";return colorpattle[\"--text-p-color\"]?.[theme];}}catch(error){console.warn(\"Failed to get theme from localStorage:\",error);}// 服务器端或出错时的默认值\nreturn colorpattle[\"--text-p-color\"]?.[\"light\"]||\"#000000\";};// 控件属性配置\naddPropertyControls(TextPro,{textitem:{type:ControlType.ComponentInstance},fontsize:{type:ControlType.Enum,options:Object.keys(GlobalFont.fontsize),optionTitles:Object.keys(GlobalFont.fontsize)},fontweight:{type:ControlType.Enum,defaultValue:\"regular\",options:Object.keys(GlobalFont.weight),optionTitles:Object.keys(GlobalFont.weight)},fontSysColor:{type:ControlType.Enum,defaultValue:\"none\",options:[\"none\",...Object.keys(colorpattle)]},fontColor:{type:ControlType.Color,defaultValue:getDefaultColor(),hidden(props){return props.fontSysColor!==\"none\";}},SameAlign:{type:ControlType.Boolean,defaultValue:true},align:{type:ControlType.Enum,options:[\"left\",\"center\",\"right\"],optionIcons:[\"text-align-left\",\"text-align-center\",\"text-align-right\"],displaySegmentedControl:true,hidden(props){return props.SameAlign;}},autoline:{type:ControlType.Number,defaultValue:0}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TextPro\",\"slots\":[],\"annotations\":{\"framerDisableUnlink\":\"\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}"],"mappings":"0UAkJG,SAAwB,EAAQ,EAAM,CAAC,GAAK,CAAC,WAAS,WAAS,aAAW,YAAU,eAAa,YAAU,QAAM,WAAS,GAAG,GAAW,EACtI,CAAC,EAAS,GAAaA,EAAS,EAAK,EAAO,CAAC,EAAa,GAAiBA,EAAS,IAAI,EAC7F,MAAoB,CAAC,EAAY,EAAI,CAAE,EAAE,CAAC,CAAC,EAG3C,IAAM,EAAYC,MAAY,CAAC,GAAU,IAAS,OAAY,MAAO,GAAM,GAAG,CAAC,MAAM,CAAC,EAAa,QAAQ,EAAa,OAAO,EAAa,MAAM,CAAC,CAAC,SAAS,EAAa,QAAQ,CAAC,CAAE,OAAO,EAAM,CAAkD,OAAjD,QAAQ,KAAK,6BAA6B,CAAK,EAAS,EAAM,CAAC,EAAE,CAAC,CAAQ,CAAC,EACxQ,EAAMA,MAAY,CAAC,GAAG,CAAC,EAAS,MAAM,UAC3C,GAAG,CAAC,OAAO,EAAW,CAAE,OAAO,EAAM,CAAgD,OAA/C,QAAQ,KAAK,2BAA2B,CAAK,EAAQ,SAAU,CAAC,EAAE,CAAC,CAAQ,CAAC,EAC7G,EAAcA,MAAoB,IAAe,OAA8B,EAAvB,OAAO,EAAa,GAAe,CAAC,EAAa,CAAS,CAAC,EACnH,EAAQA,MAAY,MAAM,QAAQ,CAAQ,EAAE,EAAS,GAAG,EAAS,CAAC,CAAQ,CAAC,EAY3E,EAAcA,OAAa,CAAC,GAAG,EAAW,SAAS,EAAS,GAAG,GAAO,GAAG,EAAW,OAAO,GAAY,sBAAsB,EAAc,GAAG,CA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