{"version":3,"file":"NoteContents.BlUuEzan.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/RvEHSm7DvxO0UyLnlfr4/GKI4O0phBhqMcPjPsbA4/NoteContents.js"],"sourcesContent":["// Note Contents: the \"In this note\" list beside an article, built from the article's H2 headings, with the current\n// section highlighted as you read. Why code: Framer can't list the headings inside CMS rich text or track which one\n// is on screen. It reads the headings from the layer named in \"Article Layer\" (keep that layer's name), gives each\n// heading an anchor id, and links to it. Title, offset, fonts and colours are property controls.\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";import{addPropertyControls,ControlType,useIsStaticRenderer}from\"framer\";const slug=s=>s.toLowerCase().replace(/[’']/g,\"\").replace(/[^a-z0-9]+/g,\"-\").replace(/^-|-$/g,\"\");/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight auto\n */export default function NoteContents(props){const{title,articleLayer,offset,titleFont,linkFont,textColor,activeColor,ruleColor,accentColor}=props;const isStatic=useIsStaticRenderer();const[items,setItems]=useState([]);const[active,setActive]=useState(0);useEffect(()=>{if(typeof document===\"undefined\")return;const root=document.querySelector(`[data-framer-name=\"${articleLayer}\"]`);if(!root)return;const heads=Array.from(root.querySelectorAll(\"h2\"));const used={};const list=heads.map(h=>{let id=h.id||slug(h.textContent||\"section\");if(!h.id){used[id]=(used[id]||0)+1;if(used[id]>1)id+=\"-\"+used[id];h.id=id;}return{id,text:h.textContent||\"\"};});setItems(list);if(isStatic)return;const onScroll=()=>{let k=0;heads.forEach((h,i)=>{if(h.getBoundingClientRect().top<offset)k=i;});setActive(k);};onScroll();window.addEventListener(\"scroll\",onScroll,{passive:true});return()=>window.removeEventListener(\"scroll\",onScroll);},[articleLayer,offset,isStatic]);return /*#__PURE__*/_jsxs(\"nav\",{\"aria-label\":title,style:{display:\"grid\",gap:14,width:\"100%\"},children:[/*#__PURE__*/_jsx(\"p\",{style:{margin:0,color:activeColor,...titleFont},children:title}),/*#__PURE__*/_jsx(\"ol\",{style:{listStyle:\"none\",margin:0,padding:0,display:\"grid\"},children:items.map((it,i)=>/*#__PURE__*/_jsx(\"li\",{children:/*#__PURE__*/_jsx(\"a\",{href:\"#\"+it.id,style:{display:\"block\",padding:\"7px 0 7px 16px\",textDecoration:\"none\",borderLeft:`2px solid ${i===active?accentColor:ruleColor}`,color:i===active?activeColor:textColor,transition:isStatic?\"none\":\"color .3s, border-color .4s cubic-bezier(.2,.8,.2,1)\",...linkFont},children:it.text})},it.id))})]});}NoteContents.defaultProps={title:\"In this note\",articleLayer:\"Article Body\",offset:140,textColor:\"#555A66\",activeColor:\"#161A26\",ruleColor:\"rgba(22, 26, 38, 0.12)\",accentColor:\"#F2B134\"};addPropertyControls(NoteContents,{title:{type:ControlType.String,title:\"Title\"},articleLayer:{type:ControlType.String,title:\"Article Layer\",description:\"Name of the rich text layer holding the article\"},offset:{type:ControlType.Number,title:\"Offset\",min:0,max:400,unit:\"px\",description:\"A heading counts as current once it passes this far from the top\"},titleFont:{type:ControlType.Font,title:\"Title Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:14.72,lineHeight:1}},linkFont:{type:ControlType.Font,title:\"Link Font\",controls:\"extended\",defaultFontType:\"sans-serif\",defaultValue:{fontSize:14.72,lineHeight:1.35}},textColor:{type:ControlType.Color,title:\"Text\"},activeColor:{type:ControlType.Color,title:\"Current\"},ruleColor:{type:ControlType.Color,title:\"Rule\"},accentColor:{type:ControlType.Color,title:\"Marker\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"NoteContents\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"auto\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./NoteContents.map"],"mappings":"8MAOG,SAAwB,EAAa,EAAM,CAAC,GAAK,CAAC,QAAM,eAAa,SAAO,Y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