Skip to content

Commit 4016f4f

Browse files
committed
put homepage demos into the repo
1 parent 8e826e6 commit 4016f4f

File tree

15 files changed

+186
-31
lines changed

15 files changed

+186
-31
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Hello {name}!</h1>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "world"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
let count = 0;
3+
4+
function increment() {
5+
count += 1;
6+
}
7+
</script>
8+
9+
<button on:click={increment}>
10+
clicks: {count}
11+
</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<script>
2+
import Foo from './Foo.html';
3+
</script>
4+
5+
<style>
6+
p {
7+
font-weight: bold;
8+
}
9+
</style>
10+
11+
<p>this &lt;p&gt; is bold but not red</p>
12+
<Foo/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<style>
2+
p {
3+
color: red;
4+
}
5+
</style>
6+
7+
<p>this &lt;p&gt; is red but not bold</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<script>
2+
import { quintOut } from 'svelte/easing';
3+
import { fade, draw, fly } from 'svelte/transition';
4+
import { expand, blur } from './custom-transitions.js';
5+
import { inner, outer } from './shape.js';
6+
7+
let visible = true;
8+
</script>
9+
10+
<style>
11+
svg {
12+
width: 100%;
13+
height: 100%;
14+
}
15+
16+
path {
17+
fill: white;
18+
opacity: 1;
19+
}
20+
21+
label {
22+
position: absolute;
23+
top: 1em;
24+
left: 1em;
25+
}
26+
27+
.centered {
28+
font-size: 20vw;
29+
position: absolute;
30+
left: 50%;
31+
top: 50%;
32+
transform: translate(-50%,-50%);
33+
font-family: 'Overpass';
34+
letter-spacing: 0.12em;
35+
color: #676778;
36+
font-weight: 100;
37+
}
38+
39+
.centered span {
40+
will-change: filter;
41+
}
42+
</style>
43+
44+
{#if visible}
45+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 103 124">
46+
<g out:fade="{{duration: 200}}" opacity=0.2>
47+
<path
48+
in:expand="{{duration: 400, delay: 1000, easing: quintOut}}"
49+
style="stroke: #ff3e00; fill: #ff3e00; stroke-width: 50;"
50+
d={outer}
51+
/>
52+
<path
53+
in:draw="{{duration: 1000}}"
54+
style="stroke:#ff3e00; stroke-width: 1.5"
55+
d={inner}
56+
/>
57+
</g>
58+
</svg>
59+
60+
<div class="centered" out:fly="{{y: -20, duration: 800}}">
61+
{#each 'SVELTE' as char, i}
62+
<span
63+
in:blur="{{delay: 1000 + i * 150, duration: 800}}"
64+
>{char}</span>
65+
{/each}
66+
</div>
67+
{/if}
68+
69+
<label>
70+
<input type="checkbox" bind:checked={visible}>
71+
toggle me
72+
</label>
73+
74+
<link href="https://fonts.googleapis.com/css?family=Overpass:100" rel="stylesheet">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { cubicOut } from 'svelte/easing';
2+
3+
export function expand(node, params) {
4+
const {
5+
delay = 0,
6+
duration = 400,
7+
easing = cubicOut
8+
} = params;
9+
10+
const w = parseFloat(getComputedStyle(node).strokeWidth);
11+
12+
return {
13+
delay,
14+
duration,
15+
easing,
16+
css: t => `opacity: ${t}; stroke-width: ${t * w}`
17+
};
18+
}
19+
20+
export function blur(node, params) {
21+
const {
22+
b = 10,
23+
delay = 0,
24+
duration = 400,
25+
easing = cubicOut
26+
} = params;
27+
28+
return {
29+
delay,
30+
duration,
31+
easing,
32+
css: (t, u) => `opacity: ${t}; filter: blur(${u * b}px);`
33+
};
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

site/content/examples/homepage-demo-transitions/shape.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/routes/api/examples/[slug].js

+11-12
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,21 @@ function createExample(slug) {
5353
export function get(req, res) {
5454
const { slug } = req.params;
5555

56-
if (!slugs.has(slug)) {
56+
try {
57+
if (!lookup.has(slug) || process.env.NODE_ENV !== 'production') {
58+
lookup.set(slug, createExample(slug));
59+
}
60+
61+
res.writeHead(200, {
62+
'Content-Type': 'application/json'
63+
});
64+
65+
res.end(lookup.get(slug));
66+
} catch (err) {
5767
res.writeHead(404, {
5868
'Content-Type': 'application/json'
5969
});
6070

6171
res.end(JSON.stringify({ error: 'not found' }));
62-
return;
6372
}
64-
65-
if (!lookup.has(slug) || process.env.NODE_ENV !== 'production') {
66-
lookup.set(slug, createExample(slug));
67-
}
68-
69-
res.writeHead(200, {
70-
'Content-Type': 'application/json'
71-
});
72-
73-
res.end(lookup.get(slug));
7473
}

site/src/routes/index.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
182182

183183
<iframe
184184
title="Hello world example"
185-
src="/repl/embed?gist=0eb9e3a2d22b981b67924c326ed1293a"
185+
src="/repl/embed?demo=homepage-demo-hello-world"
186186
scrolling="no"
187187
></iframe>
188188
</section>
@@ -193,8 +193,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
193193
</div>
194194

195195
<iframe
196-
title="Scoped styles example"
197-
src="/repl/embed?gist=ea123e7c4e7edc809670eb2dcab25b56"
196+
title="Hello world example"
197+
src="/repl/embed?demo=homepage-demo-scoped-styles"
198198
scrolling="no"
199199
></iframe>
200200
</section>
@@ -205,8 +205,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
205205
</div>
206206

207207
<iframe
208-
title="Reactivity example"
209-
src="/repl/embed?gist=7b7908b677eb0c374e17f1c5b6287e6e"
208+
title="Hello world example"
209+
src="/repl/embed?demo=homepage-demo-reactivity"
210210
scrolling="no"
211211
></iframe>
212212
</section>
@@ -217,8 +217,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
217217
</div>
218218

219219
<iframe
220-
title="Transitions example"
221-
src="/repl/embed?gist=c5336bba9eb1195bb2403aa04ff25186"
220+
title="Hello world example"
221+
src="/repl/embed?demo=homepage-demo-transitions"
222222
scrolling="no"
223223
></iframe>
224224
</section>

site/src/routes/repl/_components/Repl.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
workers.compiler.postMessage({ type: 'init', version });
6969
workers.compiler.onmessage = event => {
7070
js = event.data.js;
71-
css = event.data.css;
71+
css = event.data.css || `/* Add a <style> tag to see compiled CSS */`;
7272
if (event.data.props) props = event.data.props;
7373
};
7474

site/src/routes/repl/embed.html

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
import Repl from './_components/Repl.html';
55

66
export let query;
7-
8-
let version = query.version;
9-
let gist_id = query.gist;
10-
11-
let gist;
7+
let version = query.version || 'alpha';
128

139
let app = {
1410
components: [],
@@ -18,15 +14,14 @@
1814
let name = 'loading...';
1915

2016
onMount(() => {
21-
fetch(`https://unpkg.com/svelte@${version || 'alpha'}/package.json`)
17+
fetch(`https://unpkg.com/svelte@${version}/package.json`)
2218
.then(r => r.json())
2319
.then(pkg => {
2420
version = pkg.version;
2521
});
2622

27-
if (gist_id) {
28-
fetch(`gist/${gist_id}`).then(r => r.json()).then(data => {
29-
gist = data;
23+
if (query.gist) {
24+
fetch(`gist/${query.gist}`).then(r => r.json()).then(data => {
3025
const { id, description, files } = data;
3126

3227
name = description;
@@ -63,8 +58,19 @@
6358

6459
app = { components, values };
6560
});
66-
} else {
67-
// TODO err...
61+
} else if (query.demo) {
62+
const url = `api/examples/${query.demo}`;
63+
64+
fetch(url).then(async response => {
65+
if (response.ok) {
66+
const data = await response.json();
67+
68+
app = {
69+
values: tryParseData(data.json5) || {}, // TODO make this more error-resistant
70+
components: data.components
71+
};
72+
}
73+
});
6874
}
6975
});
7076

0 commit comments

Comments
 (0)