{"version":3,"file":"TableOfContents.Bj6pcgkK.mjs","names":["useState","useState","_Fragment","__esmMin","init_ssg_sandbox_shims","init_npm_react_18_3_1","_e","init_jsx_runtime","c","p","ce","useObserveData","Data","init_framer_DS5RHCUB","createStore","dataStore","state1","setDataStore","newState","storeState","storeSetters","setStoreState","setter","useStore","state","setState","init_createStore","init_store_js__1_0","withContent","store","setStore","newProps","setNewProps","props","formatTableOfContent","newChildren","children","item","formatHeading","index","newItem","formattedId","l","SCROLL_MARGIN_TOP","Component","init_TableOfContents","result","type","formattedHeading"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/KZcMf6a12Mwlb8NiOf0t/A1vksTCIwL5B8lJxjLgs/TableOfContents.js"],"sourcesContent":["import{useState,useEffect}from\"react\";import{Data,useObserveData}from\"framer\";export function createStore(state1){// Use Data so that a Preview reload resets the state\nconst dataStore=Data({state:Object.freeze({...state1})});// Create a set function that updates the state\nconst setDataStore=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(dataStore.state);}dataStore.state=Object.freeze({...dataStore.state,...newState});};// Store the initial state, copy the object if it's an object\nlet storeState=typeof state1===\"object\"?Object.freeze({...state1}):state1;// Keep a list of all the listeners, in the form of React hook setters\nconst storeSetters=new Set();// Create a set function that updates all the listeners / setters\nconst setStoreState=newState=>{// If the state is an object, make sure we copy it\nif(typeof newState===\"function\"){newState=newState(storeState);}storeState=typeof newState===\"object\"?Object.freeze({...storeState,...newState}):newState;// Update all the listeners / setters with the new value\nstoreSetters.forEach(setter=>setter(storeState));};// Create the actual hook based on everything above\nfunction useStore(){// Create the hook we are going to use as a listener\nconst[state,setState]=useState(storeState);// If we unmount the component using this hook, we need to remove the listener\n// @ts-ignore\nuseEffect(()=>{// But right now, we need to add the listener\nstoreSetters.add(setState);return()=>storeSetters.delete(setState);},[]);// If Data context exists, use Data, otherwise use vanilla React state\nif(useObserveData()===true){useObserveData();return[dataStore.state,setDataStore];}else{// Return the state and a function to update the central store\nreturn[state,setStoreState];}}return useStore;}\nexport const __FramerMetadata__ = {\"exports\":{\"createStore\":{\"type\":\"function\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./createStore.map","/*\n * createStore (framer/store@1.0.1)\n *\n * Learn More: https://www.framer.com/asset-urls\n */\n\nexport * from \"https://framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js\"\n","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\";// Made with love by Clément. https://lionneclement.com/\n// Full tutorial: https://lionneclement.com/tutorial/how-to-create-table-of-contents-cms-collections-framer\nconst HEADING_TO_DISPLAY=[\"h2\",\"h3\"];const SCROLL_MARGIN_TOP=160;const useStore=createStore({headings:[]});export function withTableOfContent(Component){return props=>{const[store]=useStore();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:type,title:heading,link:`${window.location.pathname}#${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.forEach((item,index)=>{const children=item.props.children;if([\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"].includes(item.type)){const{formattedId}=formatHeading(children,index);// Create a new object for the modified item\nconst newItem={...item,props:{...item.props,id:formattedId}};newChildren.push(newItem);}else{newChildren.push(item);}});// Return a new props object with the modified children\nreturn{...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=[];children.filter(({type})=>[\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"].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();return item.props.children.trim();}).join(\" \");}else if(typeof children===\"object\"){if(typeof children.props.children===\"string\"){formattedHeading=children.props.children;}else{formattedHeading=children.type;}}else{formattedHeading=index.toString();}formattedId=formattedHeading.toLowerCase().replace(/[^a-z]+/g,\"-\").replace(/^-+|-+$/g,\"\").trim();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=./TableOfContents.map"],"mappings":"A,wMAA8E,SAAgBc,EAAY,EAAO,CACjH,IAAMC,EAAUH,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAGI,CAAM,CAAC,CAAC,CAAC,EACjDC,EAAa,GAAU,CAC1B,OAAOC,GAAW,aAAY,EAASA,EAASH,EAAU,KAAK,GAAG,EAAU,MAAM,OA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