{"version":3,"file":"MathBlock.BQQffibP.mjs","names":["useState","useRef","useMemo","katex"],"sources":["https:/framerusercontent.com/modules/e5HuGfdKbvjGn6yMzQEJ/RAzrJ2768DMCy306Dyvb/MathBlock.js"],"sourcesContent":["// User request: Create a new KaTeX math component for Framer CMS rich text embeds with reliable stylesheet loading across all render targets, currentColor-based theme inheritance for light/dark mode, SSR-safe rendering, graceful TeX fallback, and a small purposeful control surface.\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useMemo,useRef,useState,startTransition}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";// @ts-ignore - Framer runtime supports URL imports; local type-checker has no declaration for this module specifier.\nimport katex from\"https://esm.sh/katex@0.16.22\";const KATEX_CSS_HREF=\"https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/katex.min.css\";// The project's Primary Background in light and dark.\nconst LIGHT_BACKDROP=\"rgb(252, 252, 252)\";const DARK_BACKDROP=\"rgb(13, 13, 13)\";function ensureKatexStylesheet(href){if(typeof document===\"undefined\")return;const existing=document.querySelector(`link[rel=\"stylesheet\"][href=\"${href}\"]`);if(existing)return;const link=document.createElement(\"link\");link.rel=\"stylesheet\";link.href=href;document.head.appendChild(link);}function inFramerApp(){if(RenderTarget.current()!==RenderTarget.preview)return true;return typeof window!==\"undefined\"&&/(^|\\.)framer\\.com$/i.test(window.location.hostname);}function parseColor(value){const parts=value.match(/[\\d.]+/g)?.map(Number);if(!parts||parts.length<3)return null;const scale=value.startsWith(\"color(\")?255:1;return[parts[0]*scale,parts[1]*scale,parts[2]*scale,parts[3]??1];}function relativeLuminance([r,g,b]){const linear=channel=>{const c=channel/255;return c<=.03928?c/12.92:((c+.055)/1.055)**2.4;};return .2126*linear(r)+.7152*linear(g)+.0722*linear(b);}// Framer's editor can preview components in the opposite theme to the panel around them, which\n// makes token colours read inverted. If the text would clash with what is behind it, sit on a\n// backdrop in the project's background colour for the text's theme. On the site nothing changes.\nfunction useReadableBackdrop(anchor,color){const[backdrop,setBackdrop]=useState(undefined);useEffect(()=>{const el=anchor.current;if(!el)return;const text=parseColor(window.getComputedStyle(el).color);if(!text)return;let surface=null;for(let node=el.parentElement;node&&!surface;node=node.parentElement){const background=parseColor(window.getComputedStyle(node).backgroundColor);if(background&&background[3]>.5)surface=background;}const textLuminance=relativeLuminance(text);let clashes=inFramerApp();if(surface){const surfaceLuminance=relativeLuminance(surface);const contrast=(Math.max(textLuminance,surfaceLuminance)+.05)/(Math.min(textLuminance,surfaceLuminance)+.05);clashes=contrast<3;}const next=clashes?textLuminance>.18?DARK_BACKDROP:LIGHT_BACKDROP:undefined;startTransition(()=>setBackdrop(next));},[color]);return backdrop;}/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n * @framerDisableUnlink\n */export default function MathBlock(props){const{tex=\"P(\\\\theta) \\\\propto \\\\sin\\\\theta\\\\,\\\\left|P_l^{|m|}(\\\\cos\\\\theta)\\\\right|^2\",display=true,color,fontSize=20,align=\"center\"}=props;const rootRef=useRef(null);const backdrop=useReadableBackdrop(rootRef,color??\"\");useEffect(()=>{ensureKatexStylesheet(KATEX_CSS_HREF);},[]);const html=useMemo(()=>{try{return katex.renderToString(tex,{displayMode:display,throwOnError:false,output:\"htmlAndMathml\"});}catch{return\"\";}},[tex,display]);const hasKatexHtml=html.length>0;const effectiveColor=color??\"currentColor\";const wrapperStyle=useMemo(()=>({position:\"relative\",width:display?\"100%\":\"auto\",maxWidth:\"100%\",display:display?\"block\":\"inline-block\",color:effectiveColor,fontSize:`${fontSize}px`,textAlign:align,overflowX:\"auto\",overflowY:\"visible\",WebkitOverflowScrolling:\"touch\",...backdrop?{background:backdrop,padding:\"8px 12px\",borderRadius:8}:null}),[display,effectiveColor,fontSize,align,backdrop]);return /*#__PURE__*/_jsxs(\"div\",{ref:rootRef,style:wrapperStyle,children:[typeof document===\"undefined\"&&/*#__PURE__*/_jsx(\"link\",{rel:\"stylesheet\",href:KATEX_CSS_HREF}),hasKatexHtml?/*#__PURE__*/_jsx(\"div\",{style:{color:\"inherit\"},dangerouslySetInnerHTML:{__html:html}}):/*#__PURE__*/_jsx(\"code\",{style:{fontFamily:'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace',opacity:.75,whiteSpace:display?\"pre-wrap\":\"normal\",color:\"inherit\"},children:tex}),/*#__PURE__*/_jsx(\"style\",{children:`.katex, .katex * { color: inherit !important; }`})]});}MathBlock.displayName=\"Math\";addPropertyControls(MathBlock,{tex:{type:ControlType.String,title:\"TeX\",displayTextArea:true,defaultValue:\"P(\\\\theta) \\\\propto \\\\sin\\\\theta\\\\,\\\\left|P_l^{|m|}(\\\\cos\\\\theta)\\\\right|^2\"},display:{type:ControlType.Boolean,title:\"Display\",defaultValue:true},color:{type:ControlType.Color,title:\"Color\",optional:true},fontSize:{type:ControlType.Number,title:\"Font Size\",min:8,max:96,defaultValue:20,unit:\"px\"},align:{type:ControlType.Enum,title:\"Align\",options:[\"left\",\"center\",\"right\"],optionTitles:[\"Left\",\"Center\",\"Right\"],defaultValue:\"center\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"MathBlock\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\",\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerDisableUnlink\":\"\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./MathBlock.map"],"mappings":"kRAGgF,SAAS,EAAsB,EAAK,CAAyH,GAArH,OAAO,SAAW,KAAkC,SAAS,cAAc,gCAAgC,EAAK,GAAe,EAAE,OAAO,IAAM,EAAK,SAAS,cAAc,MAAM,EAAE,EAAK,IAAI,aAAa,EAAK,KAAK,EAAK,SAAS,KAAK,YAAY,CAAI,CAAE,CAAC,SAAS,GAAa,CAA8D,OAA1D,EAAa,QAAQ,IAAI,EAAa,SAAk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