{"version":3,"file":"SplineWithImageFallback.Cwx8jy9Y.mjs","names":["useRef","useState"],"sources":["https:/framerusercontent.com/modules/g9Lq1AZIyz12iDQF5fjm/iYcCvIwC6HHKvFh575bY/SplineWithImageFallback.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useEffect,useRef}from\"react\";import{addPropertyControls,ControlType,RenderTarget}from\"framer\";const SPLINE_VIEWER_SRC=\"https://unpkg.com/@splinetool/viewer@1.12.98/build/spline-viewer.js\";let splineScriptPromise=null;function loadSplineViewerScript(){if(typeof window===\"undefined\")return Promise.resolve();if(window.customElements?.get(\"spline-viewer\"))return Promise.resolve();if(splineScriptPromise)return splineScriptPromise;splineScriptPromise=new Promise((resolve,reject)=>{const existing=document.querySelector(`script[src=\"${SPLINE_VIEWER_SRC}\"]`);if(existing){existing.addEventListener(\"load\",()=>resolve());existing.addEventListener(\"error\",()=>reject());return;}const script=document.createElement(\"script\");script.type=\"module\";script.src=SPLINE_VIEWER_SRC;script.addEventListener(\"load\",()=>resolve());script.addEventListener(\"error\",()=>reject());document.head.appendChild(script);});return splineScriptPromise;}/**\n * SplineWithImageFallback\n *\n * Embeds a live Spline scene via <spline-viewer>. The fallback image\n * doubles as a poster: it's shown immediately and stays up for the\n * entire time the scene is loading, then swaps to the real embed the\n * moment it confirms it's actually rendering. This avoids a flash of\n * blank/white space while the scene downloads and WebGL spins up,\n * which can visibly take a second or more. If the scene hasn't\n * actually finished loading within `timeout` ms of becoming visible —\n * slow connection, blocked script, WebGL unavailable, low power mode,\n * etc. — it just stays on the poster indefinitely instead of ever\n * revealing a broken/empty embed.\n *\n * spline-viewer doesn't stretch to fill an arbitrary container — it\n * renders at the scene's actual designed canvas size and sits inside\n * whatever box it's given. Set Scene Width/Height to match your\n * scene's real size in Spline; the embed is sized to exactly that and\n * centered with flexbox, so Embed Scale always zooms from the true\n * center instead of drifting toward a corner.\n *\n * By default, outside of actual Preview mode (i.e. in the Canvas\n * editor, during export, or in the component thumbnail) the\n * spline-viewer script is never even loaded and the scene is never\n * mounted — only the static fallback image is shown, to keep the\n * Framer editor light on GPU/CPU. Turn the \"Live in Editor\" toggle ON\n * to override this and have the real embed play freely right in the\n * Canvas too — useful while you're sizing/positioning it. Just turn\n * it back off afterward so the editor stays light again.\n *\n * The fallback image shows for one of these concrete reasons: (1) the\n * scene hasn't confirmed it's loaded yet (the normal, brief, expected\n * case on every page load), (2) Live in Editor is off and you're in\n * the Canvas, (3) the Preview Fallback toggle is on AND you're\n * actually inside Framer's own Preview mode (this toggle is\n * automatically ignored on the published site, so leaving it on by\n * mistake can never affect real visitors), (4) the spline-viewer\n * script itself failed to load, or (5) the scene didn't finish loading\n * within the Timeout. If it's stuck on the fallback well past when the\n * scene should be ready, open the browser console — reasons (4) and\n * (5) both log a `[SplineWithImageFallback]` message telling you which\n * one happened.\n *\n * @framerSupportedLayoutWidth any\n * @framerSupportedLayoutHeight any\n */export default function SplineWithImageFallback(props){const{url,fallbackSrc,radius,fit,scale,fallbackScale,sceneWidth,sceneHeight,timeout,forcePreview,liveInCanvas}=props;const containerRef=useRef(null);const viewerRef=useRef(null);const renderTarget=RenderTarget.current();// suppressLive is the one flag everything below checks. It's true\n// only when we're in the Canvas/export/thumbnail AND the \"Live in\n// Editor\" toggle is off. If the toggle is on, the real embed plays\n// everywhere, full stop — no further guard logic to think about.\nconst suppressLive=liveInCanvas?false:renderTarget!==RenderTarget.preview;// Framer's RenderTarget reports the exact same \"preview\" value for\n// both the designer's in-app Preview AND the actual published site\n// — there's no built-in way to tell them apart. That matters\n// because Preview Fallback is meant to be a temporary way to check\n// the fallback image while designing, not something that should\n// ever be able to break the real site if left on by mistake. The\n// reliable distinguishing signal is the hostname: Framer's own\n// Preview runs on a framercanvas.com domain, the published site\n// never does. \"Live\" is the fallback if that check can't confirm\n// we're on Framer's preview host — so even if Framer ever changes\n// that hostname, or the check fails for any reason, Preview\n// Fallback just quietly stops doing anything rather than risking\n// getting stuck showing only the fallback image to real visitors.\nconst isFramerPreviewHost=typeof window!==\"undefined\"&&window.location.host.includes(\"framercanvas.com\");const effectiveForcePreview=forcePreview&&renderTarget===RenderTarget.preview&&isFramerPreviewHost;// If the runtime script itself fails to load (network block, etc.)\n// there's no recovering — go straight to the fallback.\nconst[scriptFailed,setScriptFailed]=useState(false);// True once the scene has actually confirmed it's rendering. Starts\n// false on purpose — a 3D scene can visibly take a second or more to\n// download and spin up WebGL, and an empty <spline-viewer> box during\n// that window just shows the page background through it (a flash of\n// white/blank). Treating \"not loaded yet\" as its own fallback reason,\n// same as a real failure, means the fallback image acts as a poster\n// for that entire window instead of leaving a blank gap.\nconst[hasLoaded,setHasLoaded]=useState(false);const[showFallback,setShowFallback]=useState(false);const displayFallback=!hasLoaded||suppressLive||effectiveForcePreview||showFallback||scriptFailed||!url;useEffect(()=>{// Never run any of this while the real embed is suppressed — no\n// script load, no IntersectionObserver, no grace timer. The\n// component just renders the static fallback image instead.\nif(suppressLive)return;if(!url)return;const container=containerRef.current;if(!container)return;// Reset for this url — if we're re-running because the scene\n// changed, the new one hasn't loaded yet, so go back to showing\n// the poster until it confirms it's ready.\nsetHasLoaded(false);let hasLoadedOnce=false;let isVisible=false;let graceTimer=null;let cancelled=false;const clearGraceTimer=()=>{if(graceTimer){clearTimeout(graceTimer);graceTimer=null;}};const scheduleGraceCheck=()=>{clearGraceTimer();graceTimer=setTimeout(()=>{if(!hasLoadedOnce&&isVisible){console.warn(`[SplineWithImageFallback] Scene didn't fire \"load\" within ${timeout}ms — showing fallback. URL: ${url}`);setShowFallback(true);}},timeout);};const onLoad=()=>{hasLoadedOnce=true;clearGraceTimer();setShowFallback(false);setHasLoaded(true);};const onError=e=>{console.warn(`[SplineWithImageFallback] spline-viewer fired an error event — showing fallback. URL: ${url}`,e);setShowFallback(true);};const observer=new IntersectionObserver(([entry])=>{const wasVisible=isVisible;isVisible=entry.isIntersecting;if(isVisible&&!wasVisible&&!hasLoadedOnce){scheduleGraceCheck();}},{threshold:.1});observer.observe(container);const CHECK_MS=200;const readinessPoll=setInterval(()=>{if(hasLoadedOnce){clearInterval(readinessPoll);return;}const viewer=viewerRef.current;if(viewer?.shadowRoot?.querySelector(\"canvas\")){console.info(`[SplineWithImageFallback] Detected a rendering canvas before \"load\" fired — treating as loaded. URL: ${url}`);onLoad();}},CHECK_MS);loadSplineViewerScript().then(()=>{if(cancelled)return;const viewer=viewerRef.current;if(!viewer)return;viewer.addEventListener(\"load\",onLoad);viewer.addEventListener(\"error\",onError);}).catch(err=>{if(!cancelled){console.warn(\"[SplineWithImageFallback] spline-viewer runtime script failed to load — showing fallback.\",err);setScriptFailed(true);}});return()=>{cancelled=true;clearGraceTimer();clearInterval(readinessPoll);observer.disconnect();const viewer=viewerRef.current;if(viewer){viewer.removeEventListener(\"load\",onLoad);viewer.removeEventListener(\"error\",onError);}};},[url,timeout,suppressLive]);return /*#__PURE__*/_jsxs(\"div\",{ref:containerRef,style:{position:\"relative\",width:\"100%\",height:\"100%\",borderRadius:radius,overflow:\"hidden\"},children:[!suppressLive&&url&&!scriptFailed&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",inset:0,overflow:\"hidden\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",opacity:displayFallback?0:1,pointerEvents:displayFallback?\"none\":\"auto\",transition:\"opacity 0.15s ease-out\"},children:/*#__PURE__*/_jsx(\"spline-viewer\",{ref:viewerRef,url:url,style:{display:\"block\",flexShrink:0,width:`${sceneWidth}px`,height:`${sceneHeight}px`,...scale!==1&&{transform:`scale(${scale})`}}})}),fallbackSrc&&/*#__PURE__*/_jsx(\"img\",{src:fallbackSrc.src??fallbackSrc,alt:\"\",style:{position:\"absolute\",inset:0,width:\"100%\",height:\"100%\",objectFit:fit,...fallbackScale!==1&&{transform:`scale(${fallbackScale})`},opacity:displayFallback?1:0,pointerEvents:displayFallback?\"auto\":\"none\",...!suppressLive&&{transition:\"opacity 0.15s ease-out\"},zIndex:1}})]});}addPropertyControls(SplineWithImageFallback,{url:{type:ControlType.String,title:\"Scene URL\",defaultValue:\"\",placeholder:\"https://prod.spline.design/xxx/scene.splinecode\"},fallbackSrc:{type:ControlType.ResponsiveImage,title:\"Fallback\"},fallbackScale:{type:ControlType.Number,title:\"Fallback Scale\",defaultValue:1,min:.1,max:3,step:.05,description:\"Zoom the fallback image in or out from its own center — independent of Embed Scale, so sizing the image never affects the live embed.\"},radius:{type:ControlType.Number,title:\"Radius\",defaultValue:0,min:0},fit:{type:ControlType.Enum,title:\"Fit\",options:[\"cover\",\"contain\",\"fill\"],optionTitles:[\"Cover\",\"Contain\",\"Fill\"],defaultValue:\"cover\"},sceneWidth:{type:ControlType.Number,title:\"Scene Width\",defaultValue:300,min:1,description:\"The actual pixel width your scene was designed at in Spline — check your project's canvas/artboard size. This is how the embed knows how to center itself correctly.\"},sceneHeight:{type:ControlType.Number,title:\"Scene Height\",defaultValue:350,min:1,description:\"The actual pixel height your scene was designed at in Spline. Must match Scene Width for correct centering.\"},scale:{type:ControlType.Number,title:\"Embed Scale\",defaultValue:1,min:.1,max:3,step:.05,description:\"Zoom the live embed in or out from its own center — below 1 shrinks, above 1 zooms in (may clip at the edges of the component).\"},timeout:{type:ControlType.Number,title:\"Timeout (ms)\",defaultValue:6e3,min:300,max:15e3,step:100,description:\"Spline scenes take longer to initialize than video, especially on a cold CDN cache — give this generous headroom. If it's falling back unexpectedly, check the browser console for the actual reason before just raising this.\"},forcePreview:{type:ControlType.Boolean,title:\"Preview Fallback\",defaultValue:false,description:\"Toggle on to see the fallback image while testing in Framer's own Preview mode. Safe to forget: this only ever has an effect inside Framer's Preview — it's automatically ignored on the actual published site, so it can't accidentally break the live embed for real visitors.\"},liveInCanvas:{type:ControlType.Boolean,title:\"Live in Editor\",defaultValue:false,description:\"ON = the real embed plays freely right here in the Canvas, so you can size and position it visually. OFF = the Canvas shows the static fallback instead, to keep the editor light on GPU. Turn this back off once you're done sizing.\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SplineWithImageFallback\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"any\",\"framerSupportedLayoutWidth\":\"any\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./SplineWithImageFallback.map"],"mappings":"oNAAkS,SAAS,GAAwB,CAAwoB,OAA7nB,IAAS,QAAwC,EAAO,gBAAgB,IAAI,eAAe,EAAS,QAAQ,QAAQ,EAAK,IAA+C,EAAoB,IAAI,SAAS,EAAQ,IAAS,CAAC,IAAM,EAAS,SAAS,cAAc,eAAe,EAAkB,GAAG,EAAE,GAAG,EAAS,CAAC,EAAS,iBAAiB,WAAW,EAAQ,CAAC,EAAE,EAAS,iBAAiB,YAAY,EAAO,CAAC,EAAE,MAAO,CAAC,IAAM,EAAO,SAAS,cAAc,QAAQ,EAAE,EAAO,KAAK,SAAS,EAAO,IAAI,EAAkB,EAAO,iBAAiB,WAAW,EAAQ,CAAC,EAAE,EAAO,iBAAiB,YAAY,EAAO,CAAC,EAAE,SAAS,KAAK,YAAY,CAAM,CAAE,CAAC,EAAS,EAAoB,CA6Cn+B,SAAwB,EAAwB,EAAM,CAAC,GAAK,CAAC,MAAI,cAAY,SAAO,MAAI,QAAM,gBAAc,aAAW,cAAY,UAAQ,eAAa,gBAAc,EAAY,EAAaA,EAAO,IAAI,EAAQ,EAAUA,EAAO,IAAI,EAAQ,EAAa,EAAa,QAAQ,EAI9Q,EAAa,IAAmB,IAAe,EAAa,QAa5D,EAA2B,IAAS,QAAa,EAAO,SAAS,KAAK,SAAS,kBAAkB,EAAQ,EAAsB,GAAc,IAAe,EAAa,SAAS,EAEnL,CAAC,EAAa,GAAiBC,EAAS,EAAK,EAO7C,CAAC,EAAU,GAAcA,EAAS,EAAK,EAAO,CAAC,EAAa,GAAiBA,EAAS,EAAK,EAAQ,EAAgB,CAAC,GAAW,GAAc,GAAuB,GAAc,GAAc,CAAC,EAMmoD,OAN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