{"version":3,"file":"TableOFContent.D1WJqEo7.mjs","names":["_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,CAAA,GAAO,CAAC,GAAK,CAAC,EAAM,CAAC,GAAU,CAAM,CAAC,EAAc,EAAiB,CAAC,EAAS,GAAG,CAAM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