{"version":3,"file":"TableOFContent.XiI3RfIA.mjs","names":["useState","_Fragment"],"sources":["https:/framerusercontent.com/modules/PF1dXvUypVpfq84CrORY/UWGmykIPpDvi5bEigsL2/TableOFContent.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{useEffect,useState}from\"react\";const HEADING_TO_DISPLAY=[\"h2\",\"h4\"];const SCROLL_MARGIN_TOP=110;const useStore=createStore({headings:[]});export function withTableOfContent(Component){return props=>{const[store]=useStore();const[activeSection,setActiveSection]=useState(\"\");const[isClickActive,setIsClickActive]=useState(false);const scrollToId=id=>{const element=document.getElementById(id);if(element){element.scrollIntoView({behavior:\"smooth\"});setActiveSection(id);setIsClickActive(true);setTimeout(()=>{setIsClickActive(false);},500);}};useEffect(()=>{const handleScroll=()=>{if(isClickActive)return;const sections=store.headings.map(heading=>document.getElementById(heading.id));const scrollPosition=window.scrollY-60;for(let i=sections.length-1;i>=0;i--){if(sections[i]&&sections[i].offsetTop<=scrollPosition){setActiveSection(store.headings[i].id);break;}}};window.addEventListener(\"scroll\",handleScroll);return()=>{window.removeEventListener(\"scroll\",handleScroll);};},[store.headings,isClickActive]);return /*#__PURE__*/_jsx(_Fragment,{children:store.headings.length>0&&window?store.headings.sort((a,b)=>a.originalIndex-b.originalIndex).filter(({type})=>HEADING_TO_DISPLAY.includes(type)).map(({id,heading,type},index)=>/*#__PURE__*/_jsx(Component,{...props,variant:activeSection===id?`${type}-active`:type,title:heading,onClick:()=>scrollToId(id)})):/*#__PURE__*/_jsx(Component,{...props})});};}export function withContent(Component){return props=>{const[store,setStore]=useStore();const[newProps,setNewProps]=useState(props);useEffect(()=>{setStore({headings:formatTableOfContent(newProps.children?.props?.children||[])});},[newProps]);useEffect(()=>{const formatHeadings=()=>{const newChildren=[];const children=Array.isArray(props.children?.props?.children)?props.children.props.children:[props.children?.props?.children].filter(Boolean);children.forEach((item,index)=>{if(item&&[\"h2\",\"h4\"].includes(item.type)){const{formattedId}=formatHeading(item.props.children,index);const newItem={...item,props:{...item.props,id:formattedId}};newChildren.push(newItem);}else{newChildren.push(item);}});return{...props,children:{...props.children,props:{...props.children.props,children:newChildren}}};};setNewProps(formatHeadings());},[props]);return /*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"style\",{children:`.framer-text {\n                    scroll-margin-top: ${SCROLL_MARGIN_TOP}px;\n                }`}),/*#__PURE__*/_jsx(Component,{...newProps})]});};}const formatTableOfContent=children=>{const result=[];(Array.isArray(children)?children:[children]).filter(Boolean).filter(({type})=>[\"h2\",\"h4\"].includes(type)).forEach((item,index)=>{const{formattedId,formattedHeading}=formatHeading(item.props.children,index);result.push({id:formattedId,heading:formattedHeading,type:item.type,originalIndex:index});});return result;};const formatHeading=(children,index)=>{let formattedHeading=\"\";let formattedId=\"\";if(typeof children===\"string\"){formattedHeading=children.trim();}else if(Array.isArray(children)){formattedHeading=children.map(item=>{if(typeof item===\"string\")return item.trim();if(item.type===\"br\")return\"\";return item.props.children?.trim()||\"\";}).join(\" \");}else if(children?.props?.children){formattedHeading=children.props.children.trim();}else{formattedHeading=`heading-${index}`;}formattedId=formattedHeading.toLowerCase().replace(/[^a-z0-9]+/g,\"-\").replace(/^-+|-+$/g,\"\");return{formattedId,formattedHeading};};\nexport const __FramerMetadata__ = {\"exports\":{\"withContent\":{\"type\":\"reactHoc\",\"name\":\"withContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTableOfContent\":{\"type\":\"reactHoc\",\"name\":\"withTableOfContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TableOFContent.map"],"mappings":"4SAAqS,SAAgB,EAAmB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,EAAM,CAAC,IAAgB,CAAC,EAAc,EAAiB,CAACA,EAAS,IAAS,CAAC,EAAc,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