{"version":3,"file":"Footnote_code.WAVfTP-o.mjs","names":["useRef","RichText"],"sources":["https:/framerusercontent.com/modules/wpUdpYQvrTqFKqJwHzHe/w5LdxogndqyyfOklMyZh/Footnote_code.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef}from\"react\";import{addPropertyControls,ControlType,RichText}from\"framer\";/**\n * Renders an essay's Body field via Framer's RichText, then finds every\n * inline `(n)` footnote marker parse.js produces (footnote refs come\n * through as inline code — `` `(1)` `` in markdown, `<code>(1)</code>`\n * once rendered) and turns it into a tap-to-expand note sourced from\n * the Footnotes CMS field, opening in place instead of jumping to the\n * bottom of the page. Bind `body` -> Body, `footnotes` -> Footnotes on\n * the Essay collection page template.\n *\n * Verified against real CMS data 2026-08-13 (`this-place-will-become-\n * your-tomb-probably`, synced live for this test). The `<code>(n)</code>`\n * marker assumption held. The footnotes-parsing assumption did NOT: a\n * synced Footnotes field renders as an actual `<ol><li>...</li></ol>`,\n * not the plain \"1. text\\n2. text\" lines this originally looked for --\n * as first written, every footnote would have silently failed to match\n * once wired to real data. Fixed to read list-item position instead of\n * a literal digit prefix, with the original line-based parsing kept as\n * a fallback for a hand-typed property-panel test. Footnote text can\n * carry real inline formatting (bold/italic) from Amanda's prose, so\n * the note now renders via innerHTML, not textContent.\n *\n * Fixed 2026-08-14: swapping the native Body text layer for this Code\n * Component broke the Archive's fonts site-wide. The Style panel's\n * \"Text Styles\" binding (the thing that maps H3/H4/H5/H6 to the\n * Madwoman/Scholar/Witness/Archivist voice fonts, and Paragraph to\n * the Archive's default serif) only exists for native Text/RichText\n * layers -- a Code Component wrapping <RichText> has no such control,\n * so it silently fell back to browser defaults. Confirmed live: the\n * component instance's Style panel has no Font/Text section at all.\n * Fix: hardcode the same font mappings the project's real Style Kit\n * defines (read directly from each style's Edit panel, not guessed),\n * scoped to this component's own container so nothing else is touched.\n *\n * Fixed 2026-09-22 (a): the fix above returned this CSS as an inline\n * `<style>{VOICE_FONT_CSS}</style>` element in the component's own\n * JSX. That caused a site-wide, every-load React hydration mismatch\n * (React errors #418/#422/#425, \"server/client mismatch\"). Rendering a\n * `<style>` tag inline via JSX is a known SSR/hydration foot-gun --\n * the server-rendered and client-rendered text content of a `<style>`\n * element don't reliably match byte-for-byte once a browser's own HTML\n * parser gets to it. Fix: stop returning `<style>` in JSX entirely.\n * Inject the same CSS once via a dedicated `useEffect` that appends a\n * single real `<style id=\"essay-body-with-footnotes-fonts\">` element\n * to `document.head`, guarded by a `getElementById` check so\n * remounting this component (page navigation) or multiple instances on\n * one page never inject it twice. Confirmed live: the #418/#422/#425\n * errors naming this file are gone after this fix.\n *\n * Fixed 2026-09-22 (b): the hydration fix above did NOT fix the actual\n * click-dead footnotes -- confirmed by inspecting the live React fiber\n * tree on production. Both `body` and `footnotes` arrive at runtime as\n * real React element objects (`{$$typeof, type, props, ...}`), NOT\n * plain HTML strings, despite this component's own TypeScript prop\n * signature saying `string`. `body` happened to work anyway because it\n * goes straight into `<RichText>{body}</RichText>`, which accepts an\n * element tree fine. `footnotes` did NOT go through RichText -- it was\n * manually parsed with `String(footnotes || \"\")` then\n * `.innerHTML = ...`. `String()` on a JS object produces the literal\n * text \"[object Object]\", not real HTML, so `querySelectorAll(\"li\")`\n * on it always found zero elements, `noteMap` stayed permanently\n * empty, and every `(n)` marker's lookup was always undefined --\n * `wireFootnotes()` silently `return`ed for every marker, every time,\n * so nothing ever got a click handler. Fix: render `footnotes` through\n * a hidden `<RichText>{footnotes}</RichText>` (same renderer `body`\n * already uses successfully) into an off-screen container, then read\n * the real rendered `<li>` elements from that container's actual DOM\n * instead of trying to parse the raw prop as an HTML string. A second\n * MutationObserver (mirroring the existing one-beat-later handling\n * already in place for the body's own markers) re-checks the hidden\n * footnotes container until RichText actually commits its output,\n * since Framer's RichText doesn't guarantee synchronous rendering on\n * first effect run. The old string-parsing fallback is kept, guarded\n * by `typeof footnotes === \"string\"`, for the one path (a hand-typed\n * literal value in Framer's property panel) that can still arrive as\n * a real string rather than an element object.\n *\n * Fixed 2026-09-22 (c): the 2026-08-14 hardcoded font mapping above was\n * itself wrong, not just missing -- Amanda asked for this component's\n * text to match the old book/essay template's real fonts, and checking\n * the project's actual named Text Styles (via the live project's\n * TextStyles list, not re-guessed) against what this file had hardcoded\n * showed real mismatches on 3 of 4 heading levels:\n * h3 was rendering in \"Just Me Again Down Here\" (the Madwoman cursive\n * voice font) at 23px -- the real bound style is Default H3, which is\n * the plain Archive serif (Noto Serif Dives Akuru) at 26px, not a voice\n * font at all. h4's family/size (Instrument Serif, 22px) were already\n * right, but its weight/style (bold italic) was wrong -- the real style\n * (Scholar/Heading 4) is regular weight, not bold or italic. h5's font\n * family (Just Another Hand) was right but its size was rendering at\n * 18px against a real 27px (Witness/Heading 5), a visibly-too-small\n * mismatch. h6 was wrong on every axis -- rendering \"Zen Loop\" (the\n * Archivist voice font) bold-italic at 16px, when the real bound style\n * (Default H6) is the plain Archive serif at 35px, centered, regular\n * weight. `p` (Default Body) was already correct; letter-spacing added\n * for completeness. Corrected all four below to the real values.\n * NOT fixed here, flagged as still open: this component still has no\n * rule at all for `blockquote` or `code` (the footnote markers\n * themselves render via inline styles set directly in `wireFootnotes`\n * below, so this gap only affects a *non-footnote* inline code span or\n * a blockquote, if an essay body ever uses either) -- the project's\n * Text Styles list doesn't cleanly identify which named style Amanda's\n * Blockquote/Code panel rows are actually bound to (multiple\n * same-family candidates exist, e.g. \"Madwoman Body\" vs \"Madwoman Body\n * 2\"), so rather than guess, this is left for a direct check against\n * the live Style panel next time it comes up.\n */const VOICE_FONT_CSS=`\n  .essay-body-with-footnotes p {\n    font-family: \"Noto Serif Dives Akuru\", serif;\n    font-weight: 400;\n    font-size: 13px;\n    line-height: 1.3;\n    letter-spacing: -0.02em;\n  }\n  .essay-body-with-footnotes h3 {\n    font-family: \"Noto Serif Dives Akuru\", serif;\n    font-weight: 400;\n    font-style: normal;\n    font-size: 26px;\n    line-height: 1.4;\n    letter-spacing: -0.04em;\n  }\n  .essay-body-with-footnotes h4 {\n    font-family: \"Instrument Serif\", serif;\n    font-weight: 400;\n    font-style: normal;\n    font-size: 22px;\n    line-height: 1.4;\n    letter-spacing: -0.04em;\n  }\n  .essay-body-with-footnotes h5 {\n    font-family: \"Just Another Hand\", cursive;\n    font-weight: 400;\n    font-style: normal;\n    font-size: 27px;\n    line-height: 1.2;\n    letter-spacing: 0.01em;\n  }\n  .essay-body-with-footnotes h6 {\n    font-family: \"Noto Serif Dives Akuru\", serif;\n    font-weight: 400;\n    font-style: normal;\n    font-size: 35px;\n    line-height: 0.9;\n    letter-spacing: -0.02em;\n    text-align: center;\n  }\n`;export default function EssayBodyWithFootnotes(props){const{body,footnotes,markerColor,noteColor}=props;const containerRef=useRef(null);// Hidden container that renders `footnotes` through Framer's own\n// RichText, purely so its real <li> DOM can be read below -- see the\n// 2026-09-22 (b) fix note above. Never shown to visitors.\nconst footnotesRef=useRef(null);// Injects the voice-font CSS exactly once via a real document.head\n// <style> element instead of returning <style> inline in this\n// component's own JSX -- see the 2026-09-22 (a) fix note above for\n// why the inline-JSX version caused a site-wide hydration mismatch.\n// Guarded by getElementById so this never double-injects on remount\n// or when multiple instances of this component are on the same page.\nuseEffect(()=>{const STYLE_ID=\"essay-body-with-footnotes-fonts\";const existing=document.getElementById(STYLE_ID);if(existing){existing.textContent=VOICE_FONT_CSS;return;}const styleEl=document.createElement(\"style\");styleEl.id=STYLE_ID;styleEl.textContent=VOICE_FONT_CSS;document.head.appendChild(styleEl);},[]);useEffect(()=>{const container=containerRef.current;const footnotesContainer=footnotesRef.current;if(!container||!footnotesContainer)return;const prefersReducedMotion=window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;const cleanupFns=[];// Builds footnote-number -> HTML-text from the hidden RichText\n// container's real rendered DOM. A synced Footnotes field arrives\n// as a real ordered list -- <ol><li><p>text</p></li>...</ol> --\n// with no literal digit in the markup; position in the list IS\n// the footnote number. Read each <li>'s innerHTML (not\n// textContent) so bold/italic survives.\nconst buildNoteMap=()=>{const noteMap={};const listItems=Array.from(footnotesContainer.querySelectorAll(\"li\"));if(listItems.length>0){listItems.forEach((li,i)=>{noteMap[String(i+1)]=li.innerHTML.trim();});}else if(typeof footnotes===\"string\"){// Fallback: a hand-typed property-panel test value can\n// still arrive as a plain string rather than a rendered\n// element tree -- accept plain \"1. text\" lines too.\nfootnotes.split(\"\\n\").forEach(line=>{const m=line.match(/^\\s*(\\d+)\\.\\s+(.*)$/);if(m)noteMap[m[1]]=m[2];});}return noteMap;};// Wires any not-yet-wired `(n)` <code> markers currently in the\n// DOM (excluding the hidden footnotes-source container itself,\n// in case footnote text ever contains its own inline code).\n// Framer's RichText doesn't guarantee its HTML is committed in\n// the same tick this effect first runs (e.g. it can render one\n// beat after mount) -- a one-shot querySelectorAll here would\n// silently find zero markers/list items and never look again,\n// leaving every footnote dead with no click handler. The\n// MutationObservers below call this again whenever either the\n// body container or the hidden footnotes container actually\n// changes.\nconst wireFootnotes=()=>{const noteMap=buildNoteMap();const codeEls=Array.from(container.querySelectorAll(\"code\")).filter(el=>!footnotesContainer.contains(el));codeEls.forEach(el=>{const match=el.textContent?.trim().match(/^\\((\\d+)\\)$/);if(!match)return;const noteText=noteMap[match[1]];if(!noteText)return;if(el.dataset.footnoteWired)return;el.dataset.footnoteWired=\"true\";el.setAttribute(\"role\",\"button\");el.setAttribute(\"tabindex\",\"0\");el.setAttribute(\"aria-expanded\",\"false\");el.style.cursor=\"pointer\";el.style.userSelect=\"none\";const wrap=document.createElement(\"div\");wrap.style.display=\"grid\";wrap.style.gridTemplateRows=\"0fr\";if(!prefersReducedMotion){wrap.style.transition=\"grid-template-rows 0.28s ease\";}wrap.style.margin=\"0.3em 0 0.6em\";const inner=document.createElement(\"div\");inner.style.overflow=\"hidden\";const card=document.createElement(\"div\");card.style.borderLeft=`2px solid ${markerColor}`;card.style.background=noteColor;card.style.padding=\"0.6em 0.9em\";card.style.borderRadius=\"0 4px 4px 0\";card.style.fontStyle=\"italic\";card.style.fontSize=\"0.92em\";card.style.lineHeight=\"1.55\";card.innerHTML=noteText;inner.appendChild(card);wrap.appendChild(inner);const hostBlock=el.closest(\"p\")||el.parentElement;hostBlock?.insertAdjacentElement(\"afterend\",wrap);const toggle=()=>{const open=el.getAttribute(\"aria-expanded\")===\"true\";el.setAttribute(\"aria-expanded\",String(!open));el.style.background=!open?markerColor:\"\";el.style.color=!open?\"#fff\":\"\";wrap.style.gridTemplateRows=!open?\"1fr\":\"0fr\";};const onKey=e=>{if(e.key===\"Enter\"||e.key===\" \"){e.preventDefault();toggle();}};el.addEventListener(\"click\",toggle);el.addEventListener(\"keydown\",onKey);cleanupFns.push(()=>{el.removeEventListener(\"click\",toggle);el.removeEventListener(\"keydown\",onKey);wrap.remove();});});};wireFootnotes();const bodyObserver=new MutationObserver(()=>wireFootnotes());bodyObserver.observe(container,{childList:true,subtree:true});cleanupFns.push(()=>bodyObserver.disconnect());const footnotesObserver=new MutationObserver(()=>wireFootnotes());footnotesObserver.observe(footnotesContainer,{childList:true,subtree:true});cleanupFns.push(()=>footnotesObserver.disconnect());return()=>cleanupFns.forEach(fn=>fn());},[body,footnotes,markerColor,noteColor]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,className:\"essay-body-with-footnotes\",children:[/*#__PURE__*/_jsx(RichText,{children:body}),/*#__PURE__*/_jsx(\"div\",{ref:footnotesRef,\"aria-hidden\":\"true\",style:{display:\"none\"},children:/*#__PURE__*/_jsx(RichText,{children:footnotes})})]});}addPropertyControls(EssayBodyWithFootnotes,{body:{type:ControlType.RichText,title:\"Body\"},footnotes:{type:ControlType.RichText,title:\"Footnotes\"},markerColor:{type:ControlType.Color,title:\"Marker Color\",defaultValue:\"#7a2331\"},noteColor:{type:ControlType.Color,title:\"Note Background\",defaultValue:\"#7a23310d\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"EssayBodyWithFootnotes\",\"slots\":[],\"annotations\":{\"framerContractVers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