File tree 15 files changed +186
-31
lines changed
homepage-demo-hello-world
homepage-demo-scoped-styles
homepage-demo-transitions
15 files changed +186
-31
lines changed Original file line number Diff line number Diff line change
1
+ < h1 > Hello {name}!</ h1 >
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : "world"
3
+ }
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ { }
Original file line number Diff line number Diff line change
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 <p> is bold but not red</ p >
12
+ < Foo />
Original file line number Diff line number Diff line change
1
+ < style >
2
+ p {
3
+ color : red;
4
+ }
5
+ </ style >
6
+
7
+ < p > this <p> is red but not bold</ p >
Original file line number Diff line number Diff line change
1
+ { }
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ { }
Original file line number Diff line number Diff line change @@ -53,22 +53,21 @@ function createExample(slug) {
53
53
export function get ( req , res ) {
54
54
const { slug } = req . params ;
55
55
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 ) {
57
67
res . writeHead ( 404 , {
58
68
'Content-Type' : 'application/json'
59
69
} ) ;
60
70
61
71
res . end ( JSON . stringify ( { error : 'not found' } ) ) ;
62
- return ;
63
72
}
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 ) ) ;
74
73
}
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
182
182
183
183
< iframe
184
184
title ="Hello world example "
185
- src ="/repl/embed?gist=0eb9e3a2d22b981b67924c326ed1293a "
185
+ src ="/repl/embed?demo=homepage-demo-hello-world "
186
186
scrolling ="no "
187
187
> </ iframe >
188
188
</ section >
@@ -193,8 +193,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
193
193
</ div >
194
194
195
195
< 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 "
198
198
scrolling ="no "
199
199
> </ iframe >
200
200
</ section >
@@ -205,8 +205,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
205
205
</ div >
206
206
207
207
< iframe
208
- title ="Reactivity example "
209
- src ="/repl/embed?gist=7b7908b677eb0c374e17f1c5b6287e6e "
208
+ title ="Hello world example "
209
+ src ="/repl/embed?demo=homepage-demo-reactivity "
210
210
scrolling ="no "
211
211
> </ iframe >
212
212
</ section >
@@ -217,8 +217,8 @@ <h2 style='padding:2.4rem 0 0 0'>Truly reactive</h2>
217
217
</ div >
218
218
219
219
< iframe
220
- title ="Transitions example "
221
- src ="/repl/embed?gist=c5336bba9eb1195bb2403aa04ff25186 "
220
+ title ="Hello world example "
221
+ src ="/repl/embed?demo=homepage-demo-transitions "
222
222
scrolling ="no "
223
223
> </ iframe >
224
224
</ section >
Original file line number Diff line number Diff line change 68
68
workers . compiler . postMessage ( { type : 'init' , version } ) ;
69
69
workers . compiler . onmessage = event => {
70
70
js = event . data . js ;
71
- css = event . data . css ;
71
+ css = event . data . css || `/* Add a <style> tag to see compiled CSS */` ;
72
72
if ( event . data . props ) props = event . data . props ;
73
73
} ;
74
74
Original file line number Diff line number Diff line change 4
4
import Repl from './_components/Repl.html' ;
5
5
6
6
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' ;
12
8
13
9
let app = {
14
10
components : [ ] ,
18
14
let name = 'loading...' ;
19
15
20
16
onMount ( ( ) => {
21
- fetch ( `https://unpkg.com/svelte@${ version || 'alpha' } /package.json` )
17
+ fetch ( `https://unpkg.com/svelte@${ version } /package.json` )
22
18
. then ( r => r . json ( ) )
23
19
. then ( pkg => {
24
20
version = pkg . version ;
25
21
} ) ;
26
22
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 => {
30
25
const { id, description, files } = data ;
31
26
32
27
name = description ;
63
58
64
59
app = { components, values } ;
65
60
} ) ;
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
+ } ) ;
68
74
}
69
75
} ) ;
70
76
You can’t perform that action at this time.
0 commit comments