{"version":3,"file":"ConvertCalculatorEmbed.D6FFf7Km.mjs","names":["useRef","useState","useCallback"],"sources":["https:/framerusercontent.com/modules/3evIvZD10dsqEGBOYcDa/G0S9FJabwzzU0vfSfg2p/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":"kUAAwJ,SAAwB,EAAU,EAAM,CAAC,GAAK,CAAC,eAAa,aAAW,EAAY,EAAaA,EAAO,KAAK,CAAO,EAAUA,EAAO,KAAK,CAAO,EAAWA,EAAO,QAAQ,EAAa,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,UAAU,EAAE,EAAE,GAAG,CAAM,CAAC,EAAa,GAAiBC,EAAS,GAAM,CAAM,CAAC,EAAO,GAAWA,EAAS,IAAI,CAAO,EAAeD,EAAO,GAAM,CAAO,EAAS,oBAA0B,EAAO,oCAA0C,EAAQ,GAAG,EAAO,mBACxmB,OAAyB,IAAS,SAAgB,EAAO,kBAAkB,IAAA,KAAW,EAAO,gBAAgB,IAAO,AAAwB,EAAO,cAAY,IAAI,IAAK,EAAO,YAAY,IAAI,EAAW,QAAQ,MAAY,CAAI,EAAO,aAAa,EAAO,YAAY,OAAO,EAAW,QAAQ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