1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource https://esm.sh/react */
import React, { useEffect, useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
const [SplineComponent, setSplineComponent] = useState(null);
const [error, setError] = useState(null);
const [isDarkBackground, setIsDarkBackground] = useState(false);
useEffect(() => {
// Load the Spline component dynamically
import("https://esm.sh/@splinetool/react-spline@2.2.6")
.then((module) => {
setSplineComponent(() => module.default);
})
.catch((err) => {
console.error("Failed to load Spline:", err);
setError("Failed to load Spline component");
});
// Define a consistent 4-second cycle for background transitions
const cycleDuration = 7000;
const timer = setInterval(() => {
setIsDarkBackground((prev) => !prev);
}, cycleDuration);
return () => clearInterval(timer);
}, []);
if (error) {
return <div>Error: {error}</div>;
}
if (!SplineComponent) {
return <div>Loading Spline...</div>;
}
return (
<div className={isDarkBackground ? "dark-bg" : "light-bg"}>
<SplineComponent
scene="https://prod.spline.design/e7g-Cvy1HubTS0Lg/scene.splinecode"
onError={(err) => {
console.error("Spline error:", err);
setError("Error rendering Spline scene");
}}
/>
</div>
);
}
function client() {
createRoot(document.getElementById("root")).render(<App />);
}
if (typeof document !== "undefined") { client(); }
async function server(request: Request): Promise<Response> {
return new Response(
`
<html>
<head>
<title>Spline Scene</title>
<style>${css}</style>
</head>
<body>
<div id="root"></div>
<script src="https://esm.town/v/std/catch"></script>
<script type="module" src="${import.meta.url}"></script>
</body>
</html>
`,
{
headers: {
"content-type": "text/html",
},
},
);
}
const css = `
body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
overflow: hidden;
}
#root, #root > div {
width: 100%;
height: 100%;
}
.light-bg {
background: linear-gradient(135deg, #e0f7fa 0%, #80deea 100%);
transition: background 4s ease;
}
.dark-bg {