Skip to content

Commit 93f37c3

Browse files
authored
Merge pull request sveltejs#1901 from sveltejs/embedded-repl
embedded REPLs
2 parents fab7450 + 4016f4f commit 93f37c3

39 files changed

+593
-200
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/components/TopNav.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
display: flex;
5858
align-items: center;
5959
justify-content: space-between;
60-
width: 100%;
60+
width: 100vw;
6161
height: var(--nav-h);
6262
padding: 0 var(--side-nav);
6363
margin: 0 auto;
@@ -162,7 +162,7 @@
162162
position: fixed;
163163
top: 0;
164164
left: 0;
165-
width: 100%;
165+
width: 100vw;
166166
height: var(--nav-h);
167167
padding: 0 var(--side-nav) 0 var(--side-nav);
168168
display: flex;

site/src/routes/_layout.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import Nav from '../components/TopNav.html';
44

55
export let child;
6+
export let path;
67
</script>
78

89
<InlineSvg />
9-
<Nav segment={child.segment} />
10+
{#if path !== '/repl/embed'}
11+
<Nav segment={child.segment} />
12+
{/if}
13+
1014
<main>
1115
<svelte:component this={child.component} {...child.props} />
1216
</main>
@@ -15,7 +19,7 @@
1519
main {
1620
position: relative;
1721
margin: 0 auto;
18-
padding: var(--nav-h) 0 0 0;
22+
padding: var(--nav-h) var(--side-nav) 0 var(--side-nav);
1923
overflow-x: hidden;
2024
}
2125
</style>

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/blog/index.html

-26
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,6 @@ <h2>{post.metadata.title}</h2>
7777
text-transform: uppercase;
7878
}
7979

80-
/* .post:first-child .byline::after {
81-
content: 'Latest post';
82-
font-weight: 700;
83-
color: var(--second);
84-
text-transform: uppercase;
85-
margin-left: 1em;
86-
} */
87-
88-
8980
.post p {
9081
font-size: var(--h5);
9182
max-width: 30em;
@@ -103,21 +94,4 @@ <h2>{post.metadata.title}</h2>
10394
.posts a:hover > h2 {
10495
color: var(--flash)
10596
}
106-
107-
.byline {
108-
/* width: 100%; */
109-
padding: 1.6rem 0 0 0;
110-
/* border-bottom: 1px solid var(--second); */
111-
font: 300 var(--code-fs)/1.7 var(--font-mono);
112-
}
113-
114-
time {
115-
/* border-bottom: 1px solid var(--second); */
116-
}
117-
118-
.byline a {
119-
color: var(--second);
120-
}
121-
122-
.byline a:hover { color: var(--flash) }
12397
</style>

0 commit comments

Comments
 (0)