Skip to content

Commit 32c8885

Browse files
committed
[feat] better loading experience
also use Kit's env feature
1 parent c6439ae commit 32c8885

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

src/routes/tutorial/[slug]/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import Chrome from './Chrome.svelte';
1212
import { Icon } from '@sveltejs/site-kit';
1313
import Loading from './Loading.svelte';
14+
import { PUBLIC_USE_FILESYSTEM } from '$env/static/public';
1415
1516
/** @type {import('./$types').PageData} */
1617
export let data;
@@ -132,7 +133,7 @@
132133
await adapter.reset(stubs);
133134
return adapter;
134135
} else {
135-
const module = import.meta.env.VITE_USE_FILESYSTEM
136+
const module = PUBLIC_USE_FILESYSTEM
136137
? await import('$lib/client/adapters/filesystem/index.js')
137138
: await import('$lib/client/adapters/webcontainer/index.js');
138139

src/routes/tutorial/[slug]/Loading.svelte

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<script>
22
import { createEventDispatcher } from 'svelte';
3+
import { tweened } from 'svelte/motion';
4+
import { quadInOut } from 'svelte/easing';
5+
import { PUBLIC_USE_FILESYSTEM } from '$env/static/public';
36
47
/** @type {boolean} */
58
export let initial;
@@ -21,6 +24,20 @@
2124
}
2225
2326
const dispatch = createEventDispatcher();
27+
28+
const grayscale = tweened(1, {
29+
delay: initial ? 1000 : 0,
30+
duration: initial ? 10000 : 2000,
31+
easing: quadInOut
32+
});
33+
grayscale.set(0);
34+
35+
const opacity = tweened(0.1, {
36+
delay: initial ? 5000 : 500,
37+
duration: initial ? 18000 : 2000,
38+
easing: quadInOut
39+
});
40+
opacity.set(1);
2441
</script>
2542

2643
<div class="loading" class:error>
@@ -32,16 +49,34 @@
3249
<p>initializing... this may take a few seconds</p>
3350
{/if}
3451

35-
<svg width="107" height="128" viewBox="0 0 107 128">
36-
<path
37-
d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157"
38-
style="fill: #ff3e00"
39-
/>
40-
<path
41-
d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287"
42-
style="fill: #fff"
43-
/>
44-
</svg>
52+
<div style="display: flex; align-items: center;">
53+
{#if !PUBLIC_USE_FILESYSTEM && initial}
54+
<ul>
55+
<li>Booting WebContainer</li>
56+
{#if $grayscale < 0.65}
57+
<li>Unpacking modules</li>
58+
{/if}
59+
{#if $grayscale < 0.15}
60+
<li>Starting dev server</li>
61+
{/if}
62+
</ul>
63+
{/if}
64+
<svg
65+
width="107"
66+
height="128"
67+
viewBox="0 0 107 128"
68+
style="filter: grayscale({$grayscale}) opacity({$opacity})"
69+
>
70+
<path
71+
d="M94.1566,22.8189c-10.4-14.8851-30.94-19.2971-45.7914-9.8348L22.2825,29.6078A29.9234,29.9234,0,0,0,8.7639,49.6506a31.5136,31.5136,0,0,0,3.1076,20.2318A30.0061,30.0061,0,0,0,7.3953,81.0653a31.8886,31.8886,0,0,0,5.4473,24.1157c10.4022,14.8865,30.9423,19.2966,45.7914,9.8348L84.7167,98.3921A29.9177,29.9177,0,0,0,98.2353,78.3493,31.5263,31.5263,0,0,0,95.13,58.117a30,30,0,0,0,4.4743-11.1824,31.88,31.88,0,0,0-5.4473-24.1157"
72+
style="fill: #ff3e00"
73+
/>
74+
<path
75+
d="M45.8171,106.5815A20.7182,20.7182,0,0,1,23.58,98.3389a19.1739,19.1739,0,0,1-3.2766-14.5025,18.1886,18.1886,0,0,1,.6233-2.4357l.4912-1.4978,1.3363.9815a33.6443,33.6443,0,0,0,10.203,5.0978l.9694.2941-.0893.9675a5.8474,5.8474,0,0,0,1.052,3.8781,6.2389,6.2389,0,0,0,6.6952,2.485,5.7449,5.7449,0,0,0,1.6021-.7041L69.27,76.281a5.4306,5.4306,0,0,0,2.4506-3.631,5.7948,5.7948,0,0,0-.9875-4.3712,6.2436,6.2436,0,0,0-6.6978-2.4864,5.7427,5.7427,0,0,0-1.6.7036l-9.9532,6.3449a19.0329,19.0329,0,0,1-5.2965,2.3259,20.7181,20.7181,0,0,1-22.2368-8.2427,19.1725,19.1725,0,0,1-3.2766-14.5024,17.9885,17.9885,0,0,1,8.13-12.0513L55.8833,23.7472a19.0038,19.0038,0,0,1,5.3-2.3287A20.7182,20.7182,0,0,1,83.42,29.6611a19.1739,19.1739,0,0,1,3.2766,14.5025,18.4,18.4,0,0,1-.6233,2.4357l-.4912,1.4978-1.3356-.98a33.6175,33.6175,0,0,0-10.2037-5.1l-.9694-.2942.0893-.9675a5.8588,5.8588,0,0,0-1.052-3.878,6.2389,6.2389,0,0,0-6.6952-2.485,5.7449,5.7449,0,0,0-1.6021.7041L37.73,51.719a5.4218,5.4218,0,0,0-2.4487,3.63,5.7862,5.7862,0,0,0,.9856,4.3717,6.2437,6.2437,0,0,0,6.6978,2.4864,5.7652,5.7652,0,0,0,1.602-.7041l9.9519-6.3425a18.978,18.978,0,0,1,5.2959-2.3278,20.7181,20.7181,0,0,1,22.2368,8.2427,19.1725,19.1725,0,0,1,3.2766,14.5024,17.9977,17.9977,0,0,1-8.13,12.0532L51.1167,104.2528a19.0038,19.0038,0,0,1-5.3,2.3287"
76+
style="fill: #fff"
77+
/>
78+
</svg>
79+
</div>
4580
{/if}
4681
</div>
4782

@@ -65,6 +100,11 @@
65100
color: #999;
66101
}
67102
103+
ul {
104+
height: 80px;
105+
margin: 0;
106+
}
107+
68108
.error {
69109
align-items: start;
70110
justify-content: start;
@@ -77,6 +117,5 @@
77117
svg {
78118
width: 100px;
79119
height: 100px;
80-
filter: grayscale(1) opacity(0.1);
81120
}
82121
</style>

0 commit comments

Comments
 (0)