{"version":3,"file":"TableOfContents.C_gp4P9A.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/nVgbVOsi248FKSYhkBJu/W1bfFP1qw3ANJavIWKrR/TableOfContents.js"],"sourcesContent":["// Sidebar Table of Contents for Blog\n// Shows H2 and H3 headings, clickable, highlights current section\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{useEffect,useState,useRef,startTransition}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * Blog Sidebar Table of Contents\n *\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight any-prefer-fixed\n */export default function TableOfContents(props){const{textColor,hoverColor,font,style,customOffset=100}=props;const[headings,setHeadings]=useState([]);const[activeId,setActiveId]=useState(\"\");const[hoveredId,setHoveredId]=useState(\"\");const observerRef=useRef(null);// Find H2 headings in the DOM\nuseEffect(()=>{if(typeof window===\"undefined\"||RenderTarget.current()!==RenderTarget.preview)return;// Only select H2 headings inside maincontent section\nconst mainContent=document.querySelector(\"#maincontent\");if(!mainContent)return;const h2s=Array.from(mainContent.querySelectorAll(\"h2\"));const items=h2s.map(el=>{let id=el.id;if(!id){id=el.textContent?.toLowerCase().replace(/[^a-z0-9]+/g,\"-\")||\"heading\";el.id=id;}return{id,text:el.textContent||\"\",level:2};});startTransition(()=>setHeadings(items));},[]);// Highlight current section (sync with click and scroll, custom offset)\nuseEffect(()=>{if(typeof window===\"undefined\"||RenderTarget.current()!==RenderTarget.preview)return;if(!headings.length)return;if(observerRef.current)observerRef.current.disconnect();const offsetPx=typeof customOffset===\"number\"?customOffset:50;const callback=()=>{// Find the heading closest to the top (with offset)\nlet minDist=Infinity;let currentId=\"\";headings.forEach(h=>{const el=document.getElementById(h.id);if(el){const rect=el.getBoundingClientRect();const dist=Math.abs(rect.top-offsetPx);if(rect.top-offsetPx<=1&&dist<minDist){minDist=dist;currentId=h.id;}}});if(currentId)startTransition(()=>setActiveId(currentId));};window.addEventListener(\"scroll\",callback,{passive:true});// Initial call\ncallback();return()=>window.removeEventListener(\"scroll\",callback);},[headings,customOffset]);// Scroll to heading (with offset)\nfunction handleClick(id){if(typeof window===\"undefined\")return;const el=document.getElementById(id);if(el){const y=el.getBoundingClientRect().top+window.scrollY-(typeof customOffset===\"number\"?customOffset:50);window.scrollTo({top:y,behavior:\"smooth\"});startTransition(()=>setActiveId(id));}}return /*#__PURE__*/_jsx(\"nav\",{\"aria-label\":\"Table of contents\",style:{...style,color:textColor,padding:0,minWidth:220,maxWidth:320,minHeight:5,fontFamily:font.fontFamily,fontSize:font.fontSize,fontWeight:font.fontWeight,lineHeight:font.lineHeight,letterSpacing:font.letterSpacing,boxShadow:\"none\",position:\"relative\",overflow:\"auto\"},children:/*#__PURE__*/_jsx(\"ul\",{style:{listStyle:\"none\",margin:0,padding:0},children:headings.map(h=>/*#__PURE__*/_jsx(\"li\",{style:{marginLeft:h.level===3?24:0,marginBottom:8},children:/*#__PURE__*/_jsx(\"button\",{onClick:()=>handleClick(h.id),style:{background:\"transparent\",color:h.id===activeId||h.id===hoveredId?hoverColor:textColor,border:\"none\",borderRadius:0,padding:\"2px 0 2px 0\",width:\"100%\",textAlign:\"left\",cursor:\"pointer\",fontFamily:font.fontFamily,fontSize:font.fontSize,fontWeight:font.fontWeight,lineHeight:font.lineHeight,letterSpacing:font.letterSpacing,transition:\"color 0.15s\",outline:\"none\",boxShadow:\"none\"},\"aria-current\":h.id===activeId?\"true\":undefined,onMouseOver:()=>setHoveredId(h.id),onMouseOut:()=>setHoveredId(\"\"),children:h.text})},h.id))})});}addPropertyControls(TableOfContents,{textColor:{type:ControlType.Color,title:\"Text Color\",defaultValue:\"#888888\"},hoverColor:{type:ControlType.Color,title:\"Hover Color\",defaultValue:\"#000000\"},font:{type:ControlType.Font,title:\"Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:\"15px\",variant:\"Medium\",letterSpacing:\"-0.01em\",lineHeight:\"1.3em\"},displayFontSize:true,displayTextAlignment:true},customOffset:{type:ControlType.Number,title:\"Scroll Offset\",defaultValue:100,min:0,max:200,step:1,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TableOfContents\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"any-prefer-fixed\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TableOfContents.map"],"mappings":"qNAOG,SAAwB,EAAgB,EAAM,CAAC,GAAK,CAAC,YAAU,aAAW,OAAK,QAAM,eAAa,KAAK,EAAW,CAAC,EAAS,GAAaA,EAAS,EAAE,CAAC,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAG,CAAM,CAAC,EAAU,GAAcA,EAAS,GAAG,CAAO,EAAYC,EAAO,KAAK,CAC3Q,MAAc,CAAC,GAAU,IAAS,QAAa,EAAa,SAAS,GAAG,EAAa,QAAQ,OAC7F,IAAM,EAAY,SAAS,cAAc,eAAe,CAAC,GAAG,CAAC,EAAY,OAAgE,IAAM,EAArD,MAAM,KAAK,EAAY,iBAAiB,KAAK,CAAC,CAAiB,IAAI,GAAI,CAAC,IAAI,EAAG,EAAG,GAA4F,OAArF,IAAI,EAAG,EAAG,aAAa,aAAa,CAAC,QAAQ,cAAc,IAAI,EAAE,UAAU,EAAG,GAAG,GAAU,CAAC,KAAG,KAAK,EAAG,aAAa,GAAG,MAAM,EAAE,EAAG,CAAC,MAAoB,EAAY,EAAM,CAAC,EAAG,EAAE,CAAC,CACnW,MAAc,CAAsF,GAA3E,IAAS,QAAa,EAAa,SAAS,GAAG,EAAa,SAAkB,CAAC,EAAS,OAAO,OAAU,EAAY,SAAQ,EAAY,QAAQ,YAAY,CAAC,IAAM,EAAS,OAAO,GAAe,SAAS,EAAa,GAAS,MAAa,CACxQ,IAAI,EAAQ,IAAa,EAAU,GAAG,EAAS,QAAQ,GAAG,CAAC,IAAM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