{"version":3,"file":"Embed.C4COvU_F.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/o1PI5S8YtkA5bP5g4dFz/9zLIz4fn80IR9zpOx18Q/Embed.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType}from\"framer\";import{useIsOnCanvas,emptyStateStyle,containerStyles}from\"https://framer.com/m/framer/default-utils.js\";/**\n * @framerIntrinsicWidth 600\n * @framerIntrinsicHeight 400\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n *\n * @framerDisableUnlink\n */ export default function Embed({type,url,html}){if(type===\"url\"&&url){return /*#__PURE__*/ _jsx(EmbedURL,{url:url});}if(type===\"html\"&&html){return /*#__PURE__*/ _jsx(EmbedHTML,{html:html});}return /*#__PURE__*/ _jsx(Instructions,{});};addPropertyControls(Embed,{type:{type:ControlType.Enum,defaultValue:\"url\",displaySegmentedControl:true,options:[\"url\",\"html\"],optionTitles:[\"URL\",\"HTML\"]},url:{title:\"URL\",type:ControlType.String,description:\"Some websites don’t support embedding.\",hidden(props){return props.type!==\"url\";}},html:{title:\"HTML\",displayTextArea:true,type:ControlType.String,hidden(props){return props.type!==\"html\";}}});function Instructions(){return /*#__PURE__*/ _jsx(\"div\",{style:{...emptyStateStyle,overflow:\"hidden\"},children:/*#__PURE__*/ _jsx(\"div\",{style:centerTextStyle,children:\"To embed a website or widget, add it to the properties\\xa0panel.\"})});}function EmbedURL({url}){// Add https:// if the URL does not have a protocol.\nif(!/[a-z]+:\\/\\//.test(url)){url=\"https://\"+url;}const onCanvas=useIsOnCanvas();// We need to check if the url is blocked inside an iframe by the X-Frame-Options\n// or Content-Security-Policy headers on the backend.\nconst[state,setState]=useState(onCanvas?undefined:false);useEffect(()=>{// We only want to check on the canvas.\n// On the website we want to avoid the additional delay.\nif(!onCanvas)return;// TODO: We could also use AbortController here.\nlet isLastEffect=true;setState(undefined);async function load(){const response=await fetch(\"https://api.framer.com/functions/check-iframe-url?url=\"+encodeURIComponent(url));if(response.status==200){const{isBlocked}=await response.json();if(isLastEffect){setState(isBlocked);}}else{const message=await response.text();console.error(message);const error=new Error(\"This site can’t be reached.\");setState(error);}}load().catch(error=>{console.error(error);setState(error);});return()=>{isLastEffect=false;};},[url]);if(!url.startsWith(\"https://\")){return /*#__PURE__*/ _jsx(ErrorMessage,{message:\"Unsupported protocol.\"});}if(state===undefined){return /*#__PURE__*/ _jsx(LoadingIndicator,{});}if(state instanceof Error){return /*#__PURE__*/ _jsx(ErrorMessage,{message:state.message});}if(state===true){const message=`Can't embed ${url} due to its content security policy.`;return /*#__PURE__*/ _jsx(ErrorMessage,{message:message});}return /*#__PURE__*/ _jsx(\"iframe\",{src:url,style:iframeStyle,loading:\"lazy\",// @ts-ignore\nfetchPriority:onCanvas?\"low\":\"auto\",referrerPolicy:\"no-referrer\",sandbox:getSandbox(onCanvas)});}const iframeStyle={width:\"100%\",height:\"100%\",border:\"none\"};function getSandbox(onCanvas){const result=[\"allow-same-origin\",\"allow-scripts\"];if(!onCanvas){result.push(\"allow-downloads\",\"allow-forms\",\"allow-modals\",\"allow-orientation-lock\",\"allow-pointer-lock\",\"allow-popups\",\"allow-popups-to-escape-sandbox\",\"allow-presentation\",\"allow-storage-access-by-user-activation\",\"allow-top-navigation-by-user-activation\");}return result.join(\" \");}function EmbedHTML({html}){const ref=useRef();// If the HTML contains a script tag we can't use\n// dangerouslySetInnerHTML because it doesn't execute\n// scripts on the client. Otherwise, we can benefit\n// from SSG by using dangerouslySetInnerHTML.\nconst hasScript=html.includes(\"</script>\");useEffect(()=>{if(!hasScript)return;const div=ref.current;div.innerHTML=html;executeScripts(div);return()=>{div.innerHTML=\"\";};},[html,hasScript]);return /*#__PURE__*/ _jsx(\"div\",{ref:ref,style:htmlStyle,dangerouslySetInnerHTML:!hasScript?{__html:html}:undefined});}const htmlStyle={width:\"100%\",height:\"100%\",display:\"flex\",flexDirection:\"column\",justifyContent:\"center\",alignItems:\"center\"};// This function replaces scripts with executable ones.\n// https://stackoverflow.com/questions/1197575/can-scripts-be-inserted-with-innerhtml\nfunction executeScripts(node){if(node instanceof Element&&node.tagName===\"SCRIPT\"){const script=document.createElement(\"script\");script.text=node.innerHTML;for(const{name,value}of node.attributes){script.setAttribute(name,value);}node.parentElement.replaceChild(script,node);}else{for(const child of node.childNodes){executeScripts(child);}}}// Generic components\nfunction LoadingIndicator(){return /*#__PURE__*/ _jsx(\"div\",{className:\"framerInternalUI-componentPlaceholder\",style:{...containerStyles,overflow:\"hidden\"},children:/*#__PURE__*/ _jsx(\"div\",{style:centerTextStyle,children:\"Loading…\"})});}function ErrorMessage({message}){return /*#__PURE__*/ _jsx(\"div\",{className:\"framerInternalUI-errorPlaceholder\",style:{...containerStyles,overflow:\"hidden\"},children:/*#__PURE__*/ _jsxs(\"div\",{style:centerTextStyle,children:[\"Error: \",message]})});}const centerTextStyle={textAlign:\"center\",minWidth:140};\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"Embed\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerDisableUnlink\":\"\",\"framerIntrinsicWidth\":\"600\",\"framerIntrinsicHeight\":\"400\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Embed.map"],"mappings":"0eAQI,SAAwB,EAAM,CAAC,OAAK,MAAI,QAAM,CAAgJ,OAA5I,IAAO,OAAO,EAA0B,EAAK,EAAS,CAAK,MAAI,CAAC,CAAK,IAAO,QAAQ,EAA2B,EAAK,EAAU,CAAM,OAAK,CAAC,CAAuB,EAAK,EAAa,EAAE,CAAC,CAAqZ,SAAS,GAAc,CAAC,OAAqB,EAAK,MAAM,CAAC,MAAM,CAAC,GAAG,EAAgB,SAAS,SAAS,CAAC,SAAuB,EAAK,MAAM,CAAC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