{"version":3,"file":"AutoTableOfContents.DyIDVUSi.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/mQDWbrvpXTTU0EXewF9z/4WQgtSNNIlaTGwb6rRzX/AutoTableOfContents.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * On This Page — a table of contents that builds itself.\n *\n * Reads the page's own section anchors and their headings at load time, so\n * renaming a heading, reordering sections, or adding one shows up here with no\n * second edit. Nothing about the list is stored anywhere; the page is the\n * single source of truth. Before this, the eight rows existed three times over\n * (once per breakpoint) and had already drifted from five of the headings they\n * claimed to name.\n *\n * HOW IT FINDS SECTIONS. Framer only emits an `id` attribute for anchors the\n * author sets (Element ID in the editor). A whole published page otherwise\n * carries about seven internal ids, every one of them listed in RESERVED or\n * prefixed `__framer`. So \"every slug-shaped id inside #main that contains a\n * heading\" is exactly the set of real sections — verified against the published\n * /library HTML, which has 7 ids, all internal.\n *\n * DELIBERATE TRADE. This runs in the browser, so the list is absent from the\n * server-rendered HTML. That is the accepted cost of it being automatic. It is\n * a small one: the section headings and their anchors sit in the static HTML\n * either way, and those are what search engines read to build \"jump to\"\n * results. Only this widget is invisible to a crawler, and its links are\n * same-page anchors that carry little weight. Never move page copy that must\n * be indexed inside this component.\n *\n * A section is skipped, rather than mislabelled, when it has no heading — the\n * component can render a short list but never a wrong one.\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight auto\n */// The only `id`s Framer itself puts on a published page.\nconst RESERVED=new Set([\"main\",\"overlay\",\"svg-templates\",\"template-overlay\"]);// Author anchors are slugs: lowercase words joined by single dashes.\nconst SLUG=/^[a-z0-9]+(?:-[a-z0-9]+)*$/;const BORDER=\"1px solid var(--token-6d563747-b62b-410c-9b86-e78d45abd919, rgba(41,37,33,0.12))\";const MUTED=\"var(--token-29aee5a1-f534-46c2-9527-bb91eed0ba37, rgb(96,93,89))\";const INK=\"var(--token-312c9bcb-539b-4978-99ac-bc5eeb4842f5, rgb(41,37,33))\";// Unquoted on purpose: Framer server-renders component CSS through React, which\n// escapes quotes and breaks any quoted font name. Multi-word names are valid\n// CSS unquoted.\nconst SERIF=\"Lora, Georgia, serif\";function readSections(self,headingSelector,exclude){if(typeof document===\"undefined\")return[];const root=document.getElementById(\"main\")??document.body;if(!root)return[];const found=[];const seen=new Set;// querySelectorAll returns document order, which is the reading order we want.\nfor(const el of Array.from(root.querySelectorAll(\"[id]\"))){const id=el.id;if(!id||seen.has(id))continue;if(RESERVED.has(id)||id.indexOf(\"__framer\")===0)continue;if(!SLUG.test(id))continue;if(exclude.has(id))continue;// Never index ourselves.\nif(self&&self.contains(el))continue;// The heading that belongs to THIS section: its nearest id-bearing\n// ancestor must be this element, so nested sections cannot steal it.\nlet heading=null;for(const h of Array.from(el.querySelectorAll(headingSelector))){if(h.closest(\"[id]\")===el){heading=h;break;}}if(!heading)continue;const label=(heading.textContent||\"\").replace(/\\s+/g,\" \").trim();if(!label)continue;seen.add(id);found.push({id,label});}return found;}const SAMPLE=[{id:\"sample-1\",label:\"Section headings appear here\"},{id:\"sample-2\",label:\"Read live from this page\"},{id:\"sample-3\",label:\"Nothing to keep in sync\"}];export default function AutoTableOfContents(props){const{headingSelector=\"h2\",padNumbers=true,excludeIds=\"\",style}=props;const hostRef=useRef(null);// null until the first scan has run, so the very first paint renders\n// nothing rather than flashing sample rows on a live page.\nconst[scan,setScan]=useState(null);const exclude=new Set(excludeIds.split(\",\").map(s=>s.trim().replace(/^#/,\"\")).filter(Boolean));useEffect(()=>{let alive=true;const sync=()=>{if(!alive)return;const next={entries:readSections(hostRef.current,headingSelector,exclude),pageRoot:typeof document!==\"undefined\"&&!!document.getElementById(\"main\")};setScan(prev=>JSON.stringify(prev)===JSON.stringify(next)?prev:next);};sync();// Framer hydrates after mount and images can shift things in; re-read a\n// couple of times rather than trusting the first paint.\nconst timers=[window.setTimeout(sync,250),window.setTimeout(sync,1200)];window.addEventListener(\"load\",sync);return()=>{alive=false;timers.forEach(window.clearTimeout);window.removeEventListener(\"load\",sync);};},[headingSelector,excludeIds]);// Sample rows exist only so the block is visible while designing. They are\n// shown when there is demonstrably no page to read — no #main wrapper, which\n// is what an isolated canvas/export render looks like. On a real page #main\n// is present, so a scan that finds nothing renders NOTHING: an empty list is\n// honest, whereas inventing rows on a published page would be a lie that\n// links nowhere. Keyed on the DOM rather than RenderTarget because the\n// render target of a published page is not a safe thing to assume.\nconst rows=scan===null?RenderTarget.current()===RenderTarget.canvas?SAMPLE:[]:scan.entries.length>0?scan.entries:scan.pageRoot?[]:SAMPLE;const go=(event,id)=>{const target=document.getElementById(id);if(!target)return;// no target: let the browser do whatever it can\nevent.preventDefault();target.scrollIntoView({behavior:\"smooth\",block:\"start\"});if(window.history&&window.history.replaceState){window.history.replaceState(null,\"\",\"#\"+id);}};return /*#__PURE__*/_jsx(\"div\",{ref:hostRef,style:{display:\"flex\",flexDirection:\"column\",gap:0,width:\"100%\",...style},children:rows.map((entry,i)=>/*#__PURE__*/_jsxs(\"a\",{href:\"#\"+entry.id,onClick:e=>go(e,entry.id),style:{display:\"flex\",flexDirection:\"row\",alignItems:\"center\",gap:14,padding:\"15px 0px\",textDecoration:\"none\",borderTop:i===0?BORDER:undefined,borderBottom:BORDER,cursor:\"pointer\"},children:[/*#__PURE__*/_jsx(\"span\",{style:{flex:\"0 0 30px\",width:30,fontFamily:SERIF,fontWeight:500,fontSize:15,lineHeight:\"1.2em\",color:MUTED},children:padNumbers?String(i+1).padStart(2,\"0\"):String(i+1)}),/*#__PURE__*/_jsx(\"span\",{style:{flex:\"1 1 auto\",fontFamily:SERIF,fontWeight:500,fontSize:18,lineHeight:\"140%\",color:INK},children:entry.label})]},entry.id))});}addPropertyControls(AutoTableOfContents,{headingSelector:{type:ControlType.String,title:\"Heading\",defaultValue:\"h2\",description:\"Which heading level names a section. Sections use h2.\"},padNumbers:{type:ControlType.Boolean,title:\"01 style\",defaultValue:true,enabledTitle:\"01\",disabledTitle:\"1\"},excludeIds:{type:ControlType.String,title:\"Skip\",defaultValue:\"\",description:\"Anchor ids to leave out, comma separated.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"AutoTableOfContents\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./AutoTableOfContents.map"],"mappings":"oNAmCmC,SAAS,EAAa,EAAK,EAAgB,EAAQ,CAAC,GAAG,OAAO,SAAW,IAAY,MAAM,CAAC,EAAE,IAAM,EAAK,SAAS,eAAe,MAAM,GAAG,SAAS,KAAK,GAAG,CAAC,EAAK,MAAM,CAAC,EAAE,IAAM,EAAM,CAAC,EAAQ,EAAK,IAAI,IAC3O,IAAI,IAAM,KAAM,MAAM,KAAK,EAAK,iBAAiB,MAAM,CAAC,EAAE,CAAC,IAAM,EAAG,EAAG,GACvE,GAD6E,CAAC,GAAI,EAAK,IAAI,CAAE,GAAc,EAAS,IAAI,CAAE,GAAG,EAAG,QAAQ,UAAU,IAAI,GAAc,CAAC,EAAK,KAAK,CAAE,GAAc,EAAQ,IAAI,CAAE,GAC1M,GAAM,EAAK,SAAS,CAAE,EAAE,SAE3B,IAAI,EAAQ,KAAK,IAAI,IAAM,KAAK,MAAM,KAAK,EAAG,iBAAiB,CAAe,CAAC,EAAG,GAAG,EAAE,QAAQ,MAAM,IAAI,EAAG,CAAC,EAAQ,EAAE,KAAM,CAAE,GAAG,CAAC,EAAQ,SAAS,IAAM,GAAO,EAAQ,aAAa,GAAA,CAAI,QAAQ,OAAO,GAAG,CAAC,CAAC,KAAK,EAAM,IAAe,EAAK,IAAI,CAAE,EAAE,EAAM,KAAK,CAAC,KAAG,OAAK,CAAC,EAAE,CAAC,OAAO,CAAM,CAAsK,SAAwB,EAAoB,EAAM,CAAC,GAAK,CAAC,kBAAgB,KAAK,aAAW,GAAK,aAAW,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