{"version":3,"file":"TableOfContent.CNeuvVoF.mjs","names":["useState","useMemo","_Fragment"],"sources":["https:/framerusercontent.com/modules/II4Pq1Y6Jk6VBS6fyP1N/Ou4ZVEwNu2W4Q296Hw6H/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,useLayoutEffect,useMemo}from\"react\";const HEADING_TO_DISPLAY=[\"h2\",\"h3\"];const SCROLL_MARGIN_TOP=80;/**\n * ### Global store structure\n * {\n *   sections: {\n *     0: Heading[], // section‑0 headings\n *     1: Heading[], // section‑1 headings\n *     ...\n *   }\n * }\n */const useStore=createStore({sections:{}});// ────────────────────────────────────────────────────────────────────────────────\n//  HOC: Table of Content renderer\n// ────────────────────────────────────────────────────────────────────────────────\nexport function withTableOfContent(Component){return props=>{const[store]=useStore();const[activeSection,setActiveSection]=useState(\"\");/**\n         *  Flatten all sections → single ordered list\n         *  The order is sectionIndex ASC, then originalIndex ASC.\n         */const allHeadings=useMemo(()=>{return Object.keys(store.sections).sort((a,b)=>Number(a)-Number(b)).flatMap(k=>store.sections[k]??[]);},[store.sections]);const scrollToId=id=>{const el=document.getElementById(id);if(el)el.scrollIntoView({behavior:\"smooth\"});};// Highlight current section while scrolling\nuseEffect(()=>{if(allHeadings.length===0)return;const handleScroll=()=>{const headingEls=allHeadings.map(h=>document.getElementById(h.id)).filter(Boolean);const y=window.scrollY-160;for(let i=headingEls.length-1;i>=0;i--){if(headingEls[i]&&headingEls[i].offsetTop<=y){setActiveSection(allHeadings[i].id);return;}}// default to first\nsetActiveSection(allHeadings[0].id);};setTimeout(handleScroll,100)// run once on mount\n;window.addEventListener(\"scroll\",handleScroll);return()=>window.removeEventListener(\"scroll\",handleScroll);},[allHeadings]);const getHeadingStyle=type=>{const base={marginBottom:\"10px\",textDecoration:\"underline\",textDecorationColor:\"#5b69fc\",textDecorationThickness:\"1px\",textUnderlineOffset:\"2px\"};return type===\"h3\"?{...base,marginLeft:\"20px\",fontSize:\"0.9em\"}:base;};// Nothing to render yet – return wrapped component directly\nif(allHeadings.length===0){return /*#__PURE__*/_jsx(Component,{...props});}const visibleHeadings=allHeadings.filter(h=>HEADING_TO_DISPLAY.includes(h.type)).sort((a,b)=>a.globalIndex-b.globalIndex);return /*#__PURE__*/_jsx(_Fragment,{children:visibleHeadings.map(({id,heading,type})=>/*#__PURE__*/_jsx(\"div\",{style:getHeadingStyle(type),children:/*#__PURE__*/_jsx(Component,{...props,variant:activeSection===id?`${type}-active`:type,title:heading,onClick:()=>scrollToId(id)})},id))});};}// ────────────────────────────────────────────────────────────────────────────────\n//  HOC: Content parser – registers headings per section\n// ────────────────────────────────────────────────────────────────────────────────\nfunction withContent(Component,sectionIndex=0){return props=>{const[,setStore]=useStore();const[newProps,setNewProps]=useState(props);// 1️⃣  Register / update headings of THIS section\nuseLayoutEffect(()=>{const newHeadings=formatTableOfContent(newProps.children.props.children,sectionIndex);setStore(prev=>({sections:{...prev.sections,[sectionIndex]:newHeadings}}));},[newProps,sectionIndex]);// 2️⃣  Inject IDs into actual DOM nodes so scrolling works\nuseEffect(()=>{const formatHeadingsInJSX=()=>{if(!props.children?.props?.children||!Array.isArray(props.children.props.children))return props;const newChildren=props.children.props.children.map((item,index)=>{if(!item||!item.props)return item;if([\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"].includes(item.type)){const{formattedId}=formatHeading(item.props.children,index,sectionIndex);return{...item,props:{...item.props,id:formattedId}};}return item;});return{...props,children:{...props.children,props:{...props.children.props,children:newChildren}}};};setNewProps(formatHeadingsInJSX());},[props,sectionIndex]);return /*#__PURE__*/_jsxs(_Fragment,{children:[/*#__PURE__*/_jsx(\"style\",{children:`.framer-text { scroll-margin-top: ${SCROLL_MARGIN_TOP}px; }`}),/*#__PURE__*/_jsx(Component,{...newProps})]});};}// Public wrappers ↓\nexport function withContent1(Component){return withContent(Component,0);}export function withContent2(Component){return withContent(Component,1);}// ────────────────────────────────────────────────────────────────────────────────\n//  Utilities – heading extraction & formatting\n// ────────────────────────────────────────────────────────────────────────────────\nconst formatTableOfContent=(children,sectionIndex=0)=>{const result=[];if(!children||!children.length)return result;children.filter(item=>item&&item.type&&[\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"].includes(item.type)).forEach((item,idx)=>{if(!item.props||!item.props.children)return;const{formattedId,formattedHeading}=formatHeading(item.props.children,idx,sectionIndex);result.push({id:formattedId,heading:formattedHeading,type:item.type,originalIndex:idx,sectionIndex,globalIndex:sectionIndex*1e3+idx});});return result;};const formatHeading=(children,index,sectionIndex=0)=>{let formattedHeading=\"\";if(typeof children===\"string\"){formattedHeading=children;}else if(Array.isArray(children)){formattedHeading=children.map(c=>{if(typeof c===\"string\")return c.trim();if(!c)return\"\";if(c.type===\"br\")return\"\";if(c.props&&typeof c.props.children===\"string\")return c.props.children.trim();return\"\";}).join(\" \");}else if(typeof children===\"object\"&&children&&typeof children.props?.children===\"string\"){formattedHeading=children.props.children;}else{formattedHeading=index.toString();}const formattedId=`section-${sectionIndex}-`+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\"}},\"withContent1\":{\"type\":\"reactHoc\",\"name\":\"withContent1\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withContent2\":{\"type\":\"reactHoc\",\"name\":\"withContent2\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TableOfContent.map"],"mappings":"4TAYA,SAAgB,EAAmB,EAAU,CAAC,MAAO,IAAO,CAAC,GAAK,CAAC,GAAO,GAAU,CAAM,CAAC,EAAc,GAAkBA,EAAS,GAAG,CA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