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
/** @jsxImportSource npm:react **/
import { renderToString } from "npm:react-dom@18/server";
export default (req: Request) => {
const styles = `
@keyframes rainbow-text {
0% { color: red; }
15% { color: orange; }
30% { color: yellow; }
45% { color: green; }
60% { color: blue; }
75% { color: indigo; }
90% { color: violet; }
100% { color: red; }
}
.rainbow-letter {
display: inline-block;
animation: rainbow-text 10s linear infinite;
}
.rainbow-text-container {
white-space: pre; /* This preserves whitespace, including spaces */
}
`;
const text = "It me, Karlstens - In Val Town!";
const rainbowText = text.split("").map((letter, index) => (
<span
className="rainbow-letter"
style={{ animationDelay: `${-index * 0.75}s` }}
>
{letter}
</span>
));
return new Response(
renderToString(
<html>
<style>{styles}</style>
<link rel="stylesheet" href="https://unpkg.com/missing.css@1.1.1" />
<main>
<h1 className="rainbow-text-container">{rainbowText}</h1>
<p>Behold, the power of rainbows. 🌈</p>
</main>
</html>,
),
{ headers: { "Content-Type": "text/html" } },
);
};