{"version":3,"file":"TableOfContent.DRguXbGu.mjs","names":["useState","_Fragment","children"],"sources":["https:/framerusercontent.com/modules/FAUfGnBRUGlmE1tGBVC6/ivj5Ps6fjBFtTZNT4EVY/TableOfContent.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from\"react/jsx-runtime\";import{createElement as _createElement}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";import{useEffect,useState}from\"react\";const HEADING_TO_DISPLAY=[\"h2\"];const SCROLL_MARGIN_TOP=80;const useStore=createStore({headings:[]});export function withTableOfContent(Component){return props=>{const[store]=useStore();const[activeSection,setActiveSection]=useState(\"\");const[clickedSection,setClickedSection]=useState(\"\");const scrollToId=id=>{const element=document.getElementById(id);if(element){setClickedSection(id);setActiveSection(id);element.scrollIntoView({behavior:\"smooth\",block:\"start\"});setTimeout(()=>{setClickedSection(\"\");},800);}};useEffect(()=>{const handleScroll=()=>{if(clickedSection)return;const sections=store.headings.map(heading=>document.getElementById(heading.id)).filter(Boolean);let current=\"\";for(let i=0;i<sections.length;i++){const rect=sections[i].getBoundingClientRect();if(rect.top<=120&&rect.bottom>=120){current=store.headings[i].id;break;}}if(current){setActiveSection(current);}};window.addEventListener(\"scroll\",handleScroll);return()=>{window.removeEventListener(\"scroll\",handleScroll);};},[store.headings,clickedSection]);return /*#__PURE__*/_jsx(_Fragment,{children:store.headings.length>0?store.headings.sort((a,b)=>a.originalIndex-b.originalIndex).filter(({type})=>HEADING_TO_DISPLAY.includes(type)).map(({id,heading,type})=>/*#__PURE__*/_createElement(Component,{...props,key:id,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=[];props.children.props.children.length>0&&props.children.props.children.forEach((item,index)=>{const children=item.props.children;if([\"h2\"].includes(item.type)){const{formattedId}=formatHeading(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:`\n                    .framer-text {\n                        scroll-margin-top: ${SCROLL_MARGIN_TOP}px;\n                    }\n                `}),/*#__PURE__*/_jsx(Component,{...newProps})]});};}const formatTableOfContent=children=>{const result=[];children.length>0&&children.filter(({type})=>[\"h2\"].includes(type)).map((item,index)=>{const children=item.props.children;const{formattedId,formattedHeading}=formatHeading(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;}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(typeof children===\"object\"){if(typeof children.props.children===\"string\"){formattedHeading=children.props.children;}}else{formattedHeading=index.toString();}formattedId=formattedHeading.trim().toLowerCase().replace(/[^a-z0-9]+/g,\"-\").replace(/^-+|-+$/g,\"\");return{formattedId,formattedHeading};};\nexport const __FramerMetadata__ = {\"exports\":{\"withTableOfContent\":{\"type\":\"reactHoc\",\"name\":\"withTableOfContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withContent\":{\"type\":\"reactHoc\",\"name\":\"withContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TableOfContent.map"],"mappings":"+MAAkV,SAAgB,EAAmB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,GAAO,GAAU,CAAM,CAAC,EAAc,GAAkBA,EAAS,GAAG,CAAM,CAAC,EAAe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