{"version":3,"file":"WithTOCAndReadTime.CFcxVNpF.mjs","names":["useStore","useState"],"sources":["https:/framerusercontent.com/modules/vj7bFUjvEQFgEzNBkdoG/vf3CKm378wlVcBk7IhSU/createStore.js","https:/framer.com/m/framer/store.js@^1.0.0","https:/framerusercontent.com/modules/zI8V6l5BJZvXCgO30wDW/pr9uVsvMifPy53m9iWV1/WithTOCAndReadTime.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{useEffect,useState}from\"react\";import{createStore}from\"https://framer.com/m/framer/store.js@^1.0.0\";const HEADING_TO_DISPLAY=[\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\"];const SCROLL_MARGIN_TOP=80;// Store partagé\nconst useStore=createStore({headings:[],content:\"\",numberOfWords:0});// Utilitaire pour s'assurer que les enfants sont toujours un tableau\nconst normalizeChildren=children=>{if(!children)return[];if(Array.isArray(children))return children;return[children];};// **1. Override pour le contenu**\nexport function withContent(Component){return props=>{const[store,setStore]=useStore();useEffect(()=>{var _props_children_props,_props_children;const children=normalizeChildren((_props_children=props.children)===null||_props_children===void 0?void 0:(_props_children_props=_props_children.props)===null||_props_children_props===void 0?void 0:_props_children_props.children);const headings=children.filter(child=>HEADING_TO_DISPLAY.includes(child===null||child===void 0?void 0:child.type)).map((item,index)=>({id:`${item.props.children}-${index}`,heading:item.props.children,type:item.type}));setStore({headings});},[props.children]);return /*#__PURE__*/_jsx(Component,{...props});};}// **2. Override pour la Table of Content**\nexport function withTableOfContent(Component){return props=>{const[store]=useStore();const[activeSection,setActiveSection]=useState(\"\");const scrollToId=id=>{const element=document.getElementById(id);if(element)element.scrollIntoView({behavior:\"smooth\"});};useEffect(()=>{const handleScroll=()=>{const sections=store.headings.map(heading=>document.getElementById(heading.id));const scrollPosition=window.scrollY-SCROLL_MARGIN_TOP;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]);return /*#__PURE__*/_jsxs(_Fragment,{children:[store.headings.length>0&&/*#__PURE__*/_jsxs(\"div\",{children:[/*#__PURE__*/_jsx(\"h2\",{children:\"Table of Contents\"}),/*#__PURE__*/_jsx(\"ul\",{children:store.headings.map(({id,heading,type})=>/*#__PURE__*/_jsx(\"li\",{style:{fontWeight:activeSection===id?\"bold\":\"normal\"},onClick:()=>scrollToId(id),children:heading},id))})]}),/*#__PURE__*/_jsx(Component,{...props})]});};}// **3. Override pour la durée de lecture**\nexport function withReadTime(Component){return props=>{const[store,setStore]=useStore();useEffect(()=>{var _props_children_props,_props_children;const children=normalizeChildren((_props_children=props.children)===null||_props_children===void 0?void 0:(_props_children_props=_props_children.props)===null||_props_children_props===void 0?void 0:_props_children_props.children);const textContent=children.filter(child=>(child===null||child===void 0?void 0:child.type)===\"p\").map(child=>child.props.children).join(\" \");const wordCount=textContent.split(/\\s+/).length;setStore({content:textContent,numberOfWords:wordCount});},[props.children]);return /*#__PURE__*/_jsx(Component,{...props,readTime:`${Math.ceil(store.numberOfWords/200)} min read`});};}\nexport const __FramerMetadata__ = {\"exports\":{\"withContent\":{\"type\":\"reactHoc\",\"name\":\"withContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withTableOfContent\":{\"type\":\"reactHoc\",\"name\":\"withTableOfContent\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"withReadTime\":{\"type\":\"reactHoc\",\"name\":\"withReadTime\",\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./WithTOCAndReadTime.map"],"mappings":"yLAA8E,SAAgB,EAAY,EAAO,CACjH,IAAM,EAAU,EAAK,CAAC,MAAM,OAAO,OAAO,CAAC,GAAG,EAAO,CAAC,CAAC,CAAC,CAClD,EAAa,GAAU,CAC1B,OAAO,GAAW,aAAY,EAAS,EAAS,EAAU,MAAM,EAAE,EAAU,MAAM,OAAO,OAAO,CAAC,GAAG,EAAU,MAAM,GAAG,EAAS,CAAC,EAChI,EAAW,OAAO,GAAS,SAAS,OAAO,OAAO,CAAC,GAAG,EAAO,CAA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