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
// This approach uses vanilla JavaScript to create a sparkline SVG and includes a small animated cat GIF that moves around the screen.
// We'll use the `@stevekrouse/sparklineSVG` to create the sparkline and animate the cat using CSS and a bit of JavaScript.
import { sparklineSVG } from "https://esm.town/v/stevekrouse/sparklineSVG";
export default async function(req: Request): Promise<Response> {
const data = [5, 10, 5, 20, 8, 15]; // Example data for the sparkline
const svg = sparklineSVG(data, { width: 100, height: 20 });
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Sparkline SVG with Animated Cat</title>
<style>
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
text-align: center;
}
.cat {
position: absolute;
width: 50px;
height: 50px;
background: url('https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif') no-repeat center center;
background-size: cover;
animation: moveCat 5s infinite alternate;
}
@keyframes moveCat {
from {
top: 0;
left: 0;
}
to {
top: 80%;
left: 80%;
}
}
</style>
</head>
<body>
<div class="container">
<h1>Sparkline SVG with Animated Cat</h1>
<div>${svg}</div>
<div class="cat"></div>
</div>
</body>
</html>
`;
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}