{"version":3,"file":"UnicornStudioEmbed.DdrbAsNe.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/vbaJXlyVEeIvuEevvudG/95qQooHOlOw0nbDpgnZQ/UnicornStudioEmbed.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n * @framerIntrinsicHeight 400\n * @framerIntrinsicWidth 800\n */export default function UnicornStudioEmbed(props){const{sdkVersion=\"1.4.34\"}=props;const elementRef=useRef(null);const sceneRef=useRef(null);const scriptId=useRef(`unicorn-project-${Math.random().toString(36).substr(2,9)}`);const[versionError,setVersionError]=useState(null);// simple semver check: 1.2.3\nconst isValidVersion=v=>/^\\d+\\.\\d+\\.\\d+(-beta)?$/.test(v.trim());useEffect(()=>{const isEditingOrPreviewing=[\"CANVAS\",\"PREVIEW\"].includes(RenderTarget.current());// validate version first\nif(!isValidVersion(sdkVersion)){console.error(`[UnicornStudioEmbed] Invalid SDK version \"${sdkVersion}\". Expected format: x.y.z (e.g. 1.4.34)`);setVersionError(`Invalid SDK version \"${sdkVersion}\". Use x.y.z (e.g. 1.4.34).`);return;}else{setVersionError(null);}if(RenderTarget.current()===\"CANVAS\"){return;}const initializeScript=callback=>{const cdnPrefix=\"https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js\";const scriptSrc=`${cdnPrefix}@v${sdkVersion}/dist/unicornStudio.umd.js`;// check if any unicornstudio.js script is already on the page\nconst existingScript=document.querySelector('script[src^=\"https://cdn.jsdelivr.net/gh/hiunicornstudio/unicornstudio.js\"]');// IMPORTANT:\n// If there is already a script but it's for a different version,\n// we might want to load the desired one anyway. For now, if it's\n// present AND window.UnicornStudio exists, we just use it.\nif(!existingScript){const script=document.createElement(\"script\");script.src=scriptSrc;script.onload=callback;script.onerror=()=>console.error(\"Failed to load UnicornStudio script at \"+scriptSrc);document.body.appendChild(script);}else{if(window.UnicornStudio){callback();}else{const waitForLoad=setInterval(()=>{if(window.UnicornStudio){clearInterval(waitForLoad);callback();}},100);}}};const initializeUnicornStudio=()=>{if(props.projectJSON){try{// Create script element for JSON data\nconst dataScript=document.createElement(\"script\");dataScript.id=scriptId.current;dataScript.type=\"application/json\";dataScript.textContent=props.projectJSON;document.body.appendChild(dataScript);elementRef.current?.setAttribute(\"data-us-project-src\",`${scriptId.current}`);}catch(e){console.error(\"Failed to parse project JSON:\",e);return;}}else if(props.projectId){const query=props.projectId.split(\"?\");const projectId=query[0];const production=query[1]&&query[1].includes(\"production\");const cacheBuster=isEditingOrPreviewing?\"?update=\"+Math.random():\"\";elementRef.current?.setAttribute(\"data-us-project\",projectId+cacheBuster);if(production){elementRef.current?.setAttribute(\"data-us-production\",\"1\");}}const US=window.UnicornStudio;if(!US||!elementRef.current)return;// 1) Clean up only our previous scene\nUS.scenes?.find(s=>s.element===elementRef.current)?.destroy();// 2) Prepare args\nconst args={element:elementRef.current,dpi:props.dpi,scale:props.scale,fps:props.fps,lazyLoad:!!props.lazyLoad,altText:props.altText,ariaLabel:props.ariaLabel};// If you passed JSON via a <script type=\"application/json\" id=...>\nif(props.projectJSON){// ensure script tag exists (your current code already does this)\nargs.filePath=scriptId.current;}else{args.projectId=props.projectId// your parsed id\n;}// 3) Create only this scene\nUS.addScene(args).then(scene=>{sceneRef.current=scene;});};if(props.projectId||props.projectJSON){if(window.UnicornStudio){initializeUnicornStudio();}else{initializeScript(initializeUnicornStudio);}}return()=>{if(sceneRef.current){sceneRef.current.destroy();sceneRef.current=null;}// Clean up JSON script if it exists\nconst dataScript=document.getElementById(scriptId.current);if(dataScript){dataScript.remove();}};},[props.projectId,props.projectJSON,sdkVersion]);// CANVAS mode stays the same\nif(RenderTarget.current()===\"CANVAS\"){return /*#__PURE__*/_jsxs(\"div\",{style:{display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",width:\"100%\",height:\"100%\",backgroundColor:\"rgba(0, 0, 0, 0.15)\",color:\"#4B5563\",fontWeight:500,textAlign:\"center\",padding:\"16px\"},children:[/*#__PURE__*/_jsx(\"p\",{style:{fontSize:\"1.25rem\",marginBottom:\"12px\"},children:\"Scene will render in Preview and on your published site.\"}),!props.projectId&&!props.projectJSON?/*#__PURE__*/_jsx(\"p\",{style:{fontSize:\"1rem\",color:\"#EF4444\"},children:\"No project ID, please export your scene and add its project ID in the detail panel.\"}):\" \"]});}// runtime render\nreturn /*#__PURE__*/_jsxs(\"div\",{style:{width:\"100%\",height:\"100%\",position:\"relative\"},children:[/*#__PURE__*/_jsx(\"div\",{ref:elementRef,\"data-us-dpi\":props.dpi,\"data-us-scale\":props.scale,\"data-us-fps\":props.fps,\"data-us-altText\":props.altText,\"data-us-ariaLabel\":props.ariaLabel,...props.lazyLoad?{\"data-us-lazyload\":\"true\"}:{},style:{width:\"100%\",height:\"100%\",...props.style},children:props.header&&/*#__PURE__*/_jsx(\"h1\",{style:{width:\"1px\",height:\"1px\",margin:\"-1px\",padding:\"0\",overflow:\"hidden\",clip:\"rect(0, 0, 0, 0)\",border:\"0\"},children:props.header})}),versionError?/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",inset:8,background:\"rgba(239, 68, 68, 0.12)\",border:\"1px solid rgba(239, 68, 68, 0.5)\",borderRadius:6,padding:\"8px 10px\",fontSize:12,color:\"#991B1B\",pointerEvents:\"none\"},children:versionError}):null]});}UnicornStudioEmbed.displayName=\"Unicorn Studio Embed\";addPropertyControls(UnicornStudioEmbed,{projectId:{type:ControlType.String,title:\"Project ID\"},projectJSON:{type:ControlType.String,title:\"Project JSON\"},sdkVersion:{type:ControlType.String,title:\"SDK version\",defaultValue:\"1.4.34\",placeholder:\"1.4.34\"},scale:{type:ControlType.Number,title:\"Scale\",defaultValue:1,min:.25,max:1,step:.01},dpi:{type:ControlType.Number,title:\"DPI\",defaultValue:1.5,min:.5,max:2,step:.1},fps:{type:ControlType.Number,title:\"FPS\",defaultValue:60,min:10,max:120,step:5},header:{type:ControlType.String,title:\"H1 text\"},altText:{type:ControlType.String,title:\"Alt text\"},ariaLabel:{type:ControlType.String,title:\"Aria label\"},lazyLoad:{type:ControlType.Boolean,title:\"Lazy Load\",defaultValue:false}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"UnicornStudioEmbed\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerSupportedLayoutWidth\":\"fixed\",\"framerIntrinsicHeight\":\"400\",\"framerIntrinsicWidth\":\"800\",\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./UnicornStudioEmbed.map"],"mappings":"oNAKG,SAAwB,EAAmB,EAAM,CAAC,GAAK,CAAC,aAAW,UAAU,EAAY,EAAWA,EAAO,KAAK,CAAO,EAASA,EAAO,KAAK,CAAO,EAASA,EAAO,mBAAmB,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,OAAO,EAAE,EAAE,GAAG,CAAM,CAAC,EAAa,GAAiBC,EAAS,KAAK,CAC/Q,EAAe,GAAG,0BAA0B,KAAK,EAAE,MAAM,CAAC,CAgBhE,OAhBiE,MAAc,CAAC,IAAM,EAAsB,CAAC,SAAS,UAAU,CAAC,SAAS,EAAa,SAAS,CAAC,CACjK,GAAI,EAAe,EAAW,CAAgN,EAAgB,KAAK,KAApO,CAAC,QAAQ,MAAM,6CAA6C,EAAW,yCAAyC,CAAC,EAAgB,wBAAwB,EAAW,6BAA6B,CAAC,OAAoC,GAAG,EAAa,SAAS,GAAG,SAAU,OAAQ,IAAM,EAAiB,GAAU,CAAgF,IAAM,EAAU,iEAAiB,EAAW,4BAKhd,GAJqB,SAAS,cAAc,8EAA8E,IAIqH,EAAO,cAAe,GAAU,KAAM,CAAC,IAAM,EAAY,gBAAgB,CAAI,EAAO,gBAAe,cAAc,EAAY,CAAC,GAA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