{"version":3,"file":"ArticleAutoHeightHtmlEmbed.HezMd2cM.mjs","names":["useRef","useState","useMemo","useCallback"],"sources":["https:/framerusercontent.com/modules/abGFOIaqVyqH6kbJpAFG/pLVmLpdOlOd8TlvakjYA/ArticleAutoHeightHtmlEmbed.js"],"sourcesContent":["// Requested: Create a new code component named ArticleAutoHeightHtmlEmbed for use only inside one CMS article’s rich-text embeds. It must preserve editable HTML input via a multiline string property control named HTML and an optional numeric Min Height control. Render arbitrary supplied HTML safely via srcDoc in an iframe that grows to the content’s actual height, including after fonts/load, responsive reflows, and window resizes. Use ResizeObserver within the iframe document and clean it up safely. The iframe must have no fixed cap, no inner scrolling, width 100%, block display, transparent background, and a sensible 300px initial minimum to avoid flicker. Do not modify any existing files or components; create a new dedicated file/component only.\nimport{jsx as _jsx}from\"react/jsx-runtime\";import{startTransition,useCallback,useEffect,useMemo,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth any-prefer-fixed\n * @framerSupportedLayoutHeight auto\n */export default function ArticleAutoHeightHtmlEmbed(props){const{html,minHeight}=props;const iframeRef=useRef(null);const cleanupRef=useRef(null);const[measuredHeight,setMeasuredHeight]=useState(300);const safeMinHeight=useMemo(()=>Math.max(0,minHeight||0),[minHeight]);const htmlAwareBaselineMinHeight=useMemo(()=>{const htmlValue=(html||\"\").toLowerCase();if(htmlValue.includes(\"bloom-tbl-scroll\"))return 580;if(htmlValue.includes(\"bloom-stats-hl-grid\"))return 360;return 0;},[html]);const processedHtml=useMemo(()=>{const source=html||\"\";const htmlValue=source.toLowerCase();if(!htmlValue.includes(\"bloom-stats-hl-grid\"))return source;const overrideStyle=\"<style> .bloom-stats-hl { margin-top: 0 !important; margin-bottom: 0 !important; } </style>\";if(/<\\/head>/i.test(source)){return source.replace(/<\\/head>/i,`${overrideStyle}</head>`);}if(/<body[^>]*>/i.test(source)){return source.replace(/<body([^>]*)>/i,`<body$1>${overrideStyle}`);}return`${overrideStyle}${source}`;},[html]);const effectiveMinHeight=useMemo(()=>Math.max(safeMinHeight,htmlAwareBaselineMinHeight),[safeMinHeight,htmlAwareBaselineMinHeight]);const measureHeight=useCallback(()=>{const iframe=iframeRef.current;if(!iframe)return;try{const doc=iframe.contentDocument;if(!doc)return;const root=doc.documentElement;const body=doc.body;if(!root)return;const contentHeight=Math.max(root.scrollHeight||0,root.offsetHeight||0,root.clientHeight||0,body?.scrollHeight||0,body?.offsetHeight||0,body?.clientHeight||0);const nextHeight=Math.max(contentHeight,effectiveMinHeight);startTransition(()=>setMeasuredHeight(previous=>previous===nextHeight?previous:nextHeight));}catch(_error){startTransition(()=>setMeasuredHeight(previous=>Math.max(previous,effectiveMinHeight)));}},[effectiveMinHeight]);const attachObservers=useCallback(()=>{if(cleanupRef.current){cleanupRef.current();cleanupRef.current=null;}const iframe=iframeRef.current;if(!iframe)return;try{const doc=iframe.contentDocument;const frameWindow=iframe.contentWindow;if(!doc||!frameWindow||!doc.documentElement)return;const cleanups=[];const ResizeObserverCtor=frameWindow.ResizeObserver||(typeof window!==\"undefined\"?window.ResizeObserver:undefined);if(ResizeObserverCtor){const observer=new ResizeObserverCtor(()=>{measureHeight();});observer.observe(doc.documentElement);if(doc.body)observer.observe(doc.body);cleanups.push(()=>observer.disconnect());}if(doc.fonts&&typeof doc.fonts.ready?.then===\"function\"){doc.fonts.ready.then(()=>{measureHeight();});}frameWindow.addEventListener(\"load\",measureHeight);cleanups.push(()=>frameWindow.removeEventListener(\"load\",measureHeight));if(typeof window!==\"undefined\"){window.addEventListener(\"resize\",measureHeight);cleanups.push(()=>window.removeEventListener(\"resize\",measureHeight));}cleanupRef.current=()=>{cleanups.forEach(cleanup=>cleanup());};}catch(_error){cleanupRef.current=null;}},[measureHeight]);useEffect(()=>{attachObservers();measureHeight();return()=>{if(cleanupRef.current){cleanupRef.current();cleanupRef.current=null;}};},[html,effectiveMinHeight,attachObservers,measureHeight]);const iframeHeight=useMemo(()=>Math.max(measuredHeight,effectiveMinHeight),[measuredHeight,effectiveMinHeight]);return /*#__PURE__*/_jsx(\"iframe\",{ref:iframeRef,srcDoc:processedHtml,onLoad:()=>{attachObservers();measureHeight();},sandbox:\"allow-same-origin\",scrolling:\"no\",style:{position:\"relative\",width:\"100%\",height:iframeHeight,border:\"none\",display:\"block\",background:\"transparent\",overflow:\"hidden\"}});}addPropertyControls(ArticleAutoHeightHtmlEmbed,{html:{type:ControlType.String,title:\"HTML\",defaultValue:\"<p>Embed content</p>\",displayTextArea:true},minHeight:{type:ControlType.Number,title:\"Min Height\",defaultValue:0,min:0,step:1,unit:\"px\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"ArticleAutoHeightHtmlEmbed\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutWidth\":\"any-prefer-fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"auto\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ArticleAutoHeightHtmlEmbed.map"],"mappings":"2NAIG,SAAwB,EAA2B,EAAM,CAAC,GAAK,CAAC,OAAK,aAAW,EAAY,EAAUA,EAAO,IAAI,EAAQ,EAAWA,EAAO,IAAI,EAAO,CAAC,EAAe,GAAmBC,EAAS,GAAG,EAAQ,EAAcC,MAAY,KAAK,IAAI,EAAE,GAAW,CAAC,EAAE,CAAC,CAAS,CAAC,EAAQ,EAA2BA,MAAY,CAAC,IAAM,GAAW,GAAM,GAAA,CAAI,YAAY,EAA+G,OAA1G,EAAU,SAAS,kBAAkB,EAAS,IAAO,EAAU,SAAS,qBAAqB,EAAS,IAAW,CAAE,EAAE,CAAC,CAAI,CAAC,EAAQ,EAAcA,MAAY,CAAC,IAAM,EAAO,GAAM,GAAwC,GAAG,CAAxB,EAAO,YAA0B,CAAC,CAAC,SAAS,qBAAqB,EAAE,OAAO,EAAO,IAAM,EAAc,8FAA6R,MAA5L,YAAY,KAAK,CAAM,EAAU,EAAO,QAAQ,YAA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