{"version":3,"file":"ConvertCalculatorEmbed.CVeDobwb.mjs","names":["useRef","useState","useCallback","__esmMin","ne","init_npm_react_18_3_1","window","ce","init_jsx_runtime","c","_e","de","init_ssg_sandbox_shims","init_framer_DcGZRLrs","addPropertyControls","ControlType","CalcEmbed","props","containerRef","iframeRef","instanceId","calculatorId","scriptLoaded","setScriptLoaded","height","setHeight","initializedRef","scriptId","ORIGIN","SRC_URL","createInitialIframe","iframe","timestamp","timeStamp","currentUrl","script","preventReinitialization","srcUrl","handleMessage","event","newHeight","init_ConvertCalculatorEmbed"],"sources":["https:/framerusercontent.com/modules/eqov2BnLaOBpsopgJEGi/gLsv0IWQSidxGHrTRa6h/ConvertCalculatorEmbed.js"],"sourcesContent":["import{jsx as _jsx}from\"react/jsx-runtime\";import{ControlType,addPropertyControls}from\"framer\";import{useEffect,useRef,useState,useCallback}from\"react\";export default function CalcEmbed(props){const{calculatorId,timeStamp}=props;const containerRef=useRef(null);const iframeRef=useRef(null);const instanceId=useRef(`calc-${calculatorId}-${Math.random().toString(36).substring(2,9)}`);const[scriptLoaded,setScriptLoaded]=useState(false);const[height,setHeight]=useState(400);const initializedRef=useRef(false);const scriptId=\"calc-embed-script\";const ORIGIN=\"https://www.convertcalculator.com\";const SRC_URL=`${ORIGIN}/scripts/embed.js`;// Set up a global initialization guard\nuseEffect(()=>{if(typeof window!==\"undefined\"){if(window.ccPreventReinit===undefined){window.ccPreventReinit=false;}if(!window.ccInstances){window.ccInstances=new Set;}window.ccInstances.add(instanceId.current);}return()=>{if(window.ccInstances){window.ccInstances.delete(instanceId.current);}};},[]);// Create initial iframe that will be managed by the script\nconst createInitialIframe=useCallback(()=>{if(!containerRef.current||initializedRef.current)return;initializedRef.current=true;const iframe=document.createElement(\"iframe\");iframe.className=\"calculator-frame\";iframe.id=`calculator-frame-${calculatorId}`;iframe.sandbox=\"allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox\";iframe.title=\"Calculator Frame\";iframe.style.border=\"none\";iframe.style.width=\"100%\";iframe.style.height=\"100%\";iframe.style.display=\"block\";iframe.allow=\"fullscreen\";const timestamp=timeStamp||Date.now();const currentUrl=encodeURIComponent(window.location.href||\"framer\");iframe.src=`${ORIGIN}/embed/${calculatorId}?framed=1&url=${currentUrl}&t=${timestamp}`;// Clear container\nwhile(containerRef.current.firstChild){containerRef.current.removeChild(containerRef.current.firstChild);}containerRef.current.appendChild(iframe);iframeRef.current=iframe;containerRef.current.setAttribute(\"data-calc-id\",calculatorId);containerRef.current.setAttribute(\"data-type\",\"framed\");containerRef.current.setAttribute(\"data-loaded\",\"true\");},[calculatorId,timeStamp]);// Load embed.js script\nuseEffect(()=>{if(document.getElementById(scriptId)){setScriptLoaded(true);return;}const script=document.createElement(\"script\");script.src=`${SRC_URL}?t=${Date.now()}`;script.id=scriptId;script.async=true;// Inject loop prevention code before script loads\nconst preventReinitialization=document.createElement(\"script\");preventReinitialization.textContent=`\n      (function() {\n        // Store number of initialization attempts\n        window._ccInitAttempts = 0;\n        \n        // Store original setInterval function\n        const originalSetInterval = window.setInterval;\n        \n        // Override setInterval to prevent infinite loops\n        window.setInterval = function(callback, delay, ...args) {\n          // If we detect many rapid initialization attempts, limit them\n          if (delay < 500 && window._ccInitAttempts > 5) {\n            console.log('Preventing potential initialization loop');\n            return null;\n          }\n          \n          // Call original function\n          return originalSetInterval(callback, delay, ...args);\n        };\n      })();\n    `;document.head.appendChild(preventReinitialization);// Now load the actual script\nscript.onload=()=>{setScriptLoaded(true);};document.body.appendChild(script);},[]);// Create initial iframe and integrate with the script\nuseEffect(()=>{createInitialIframe();},[createInitialIframe]);// Handle calculator ID changes\nuseEffect(()=>{if(scriptLoaded&&containerRef.current&&window.cc?.reload){containerRef.current.setAttribute(\"data-calc-id\",calculatorId);if(iframeRef.current){const timestamp=timeStamp||Date.now();const currentUrl=encodeURIComponent(window.location.href||\"framer\");const srcUrl=`${ORIGIN}/embed/${calculatorId}?framed=1&url=${currentUrl}&t=${timestamp}`;iframeRef.current.src=srcUrl;}// Use the script's reload function to update\nsetTimeout(()=>{if(window.cc?.reload){window.ccPreventReinit=true;window.cc.reload();setTimeout(()=>{window.ccPreventReinit=false;},500);}},100);}},[calculatorId,timeStamp,scriptLoaded]);// Handle height adjustments via postMessage\nuseEffect(()=>{const handleMessage=event=>{if(event.origin!==ORIGIN||!event.data||typeof event.data!==\"object\")return;if(event.data.calculatorId===calculatorId&&event.data.type===\"resize\"&&event.data.payload?.height){const newHeight=event.data.payload.height;setHeight(newHeight);if(iframeRef.current){iframeRef.current.style.height=`${newHeight}px`;}}};window.addEventListener(\"message\",handleMessage);return()=>window.removeEventListener(\"message\",handleMessage);},[calculatorId]);return /*#__PURE__*/_jsx(\"div\",{ref:containerRef,className:\"calculator\",\"data-calc-id\":calculatorId,\"data-type\":\"framed\",\"data-instance-id\":instanceId.current,\"data-loaded\":\"true\",style:{width:\"100%\",height:\"100%\",overflow:\"hidden\"}});}addPropertyControls(CalcEmbed,{calculatorId:{type:ControlType.String,title:\"Calculator ID\",defaultValue:\"LBkGt4HRfSXZFzRcS\"},workspaceId:{type:ControlType.String,title:\"Workspace ID\",defaultValue:\"\"},timeStamp:{type:ControlType.String,title:\"Timestamp\",defaultValue:\"\",hidden:()=>true}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"CalcEmbed\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./ConvertCalculatorEmbed.map"],"mappings":"A,6MAAwJ,SAAwBgB,EAAU,EAAM,CAAC,GAAK,CAAC,eAAa,aAAWC,EAAYC,EAAalB,EAAO,IAAI,EAAQmB,EAAUnB,EAAO,IAAI,EAAQoB,EAAWpB,EAAO,QAAQqB,EAAa,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,GAAG,EAAO,CAACC,EAAaC,GAAiBtB,EAA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