|
1 |
| -<script> |
2 |
| - import Counter from './Counter.svelte'; |
3 |
| - import welcome from '$lib/images/svelte-welcome.webp'; |
4 |
| - import welcome_fallback from '$lib/images/svelte-welcome.png'; |
5 |
| - import Particles from "@tsparticles/svelte"; |
6 |
| - import { loadFull } from "tsparticles"; |
| 1 | +<script lang="ts"> |
| 2 | + import Counter from './Counter.svelte'; |
| 3 | + import welcome from '$lib/images/svelte-welcome.webp'; |
| 4 | + import welcome_fallback from '$lib/images/svelte-welcome.png'; |
| 5 | + import { particlesInit } from "@tsparticles/svelte"; |
| 6 | + import { loadFull } from "tsparticles"; |
| 7 | + import { type Engine } from "@tsparticles/engine"; |
| 8 | + import { browser } from '$app/environment'; |
7 | 9 |
|
8 |
| - let particlesConfig = { |
9 |
| - particles: { |
10 |
| - color: { |
11 |
| - value: "#000", |
12 |
| - }, |
13 |
| - links: { |
14 |
| - enable: true, |
15 |
| - color: "#000", |
16 |
| - }, |
17 |
| - number: { |
18 |
| - value: 80 |
19 |
| - }, |
20 |
| - move: { |
21 |
| - enable: true, |
22 |
| - }, |
23 |
| - }, |
24 |
| - }; |
| 10 | + let particlesConfig = { |
| 11 | + particles: { |
| 12 | + color: { |
| 13 | + value: "#000", |
| 14 | + }, |
| 15 | + links: { |
| 16 | + enable: true, |
| 17 | + color: "#000", |
| 18 | + }, |
| 19 | + number: { |
| 20 | + value: 80 |
| 21 | + }, |
| 22 | + move: { |
| 23 | + enable: true, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }; |
25 | 27 |
|
26 |
| - let particlesInit = async engine => { |
27 |
| - // you can use main to customize the tsParticles instance adding presets or custom shapes |
28 |
| - // this loads the tsparticles package bundle, it's the easiest method for getting everything ready |
29 |
| - // starting from v2 you can add only the features you need reducing the bundle size |
30 |
| - await loadFull(engine); |
31 |
| - }; |
| 28 | + void particlesInit(async (engine: Engine) => { |
| 29 | + await loadFull(engine); |
| 30 | + }); |
| 31 | +
|
| 32 | + const ParticlesConstructor = browser ? |
| 33 | + import('@tsparticles/svelte').then((module) => module.default) : |
| 34 | + new Promise(() => { |
| 35 | + }); |
32 | 36 | </script>
|
33 | 37 |
|
34 | 38 | <svelte:head>
|
35 |
| - <title>Home</title> |
36 |
| - <meta name="description" content="Svelte demo app" /> |
| 39 | + <title>Home</title> |
| 40 | + <meta name="description" content="Svelte demo app"/> |
37 | 41 | </svelte:head>
|
38 | 42 |
|
39 | 43 | <section>
|
40 |
| - <h1> |
| 44 | + <h1> |
41 | 45 | <span class="welcome">
|
42 | 46 | <picture>
|
43 |
| - <source srcset={welcome} type="image/webp" /> |
44 |
| - <img src={welcome_fallback} alt="Welcome" /> |
| 47 | + <source srcset={welcome} type="image/webp"/> |
| 48 | + <img src={welcome_fallback} alt="Welcome"/> |
45 | 49 | </picture>
|
46 | 50 | </span>
|
47 | 51 |
|
48 |
| - to your new<br />SvelteKit app |
49 |
| - </h1> |
| 52 | + to your new<br/>SvelteKit app |
| 53 | + </h1> |
50 | 54 |
|
51 |
| - <h2> |
52 |
| - try editing <strong>src/routes/+page.svelte</strong> |
53 |
| - </h2> |
| 55 | + <h2> |
| 56 | + try editing <strong>src/routes/+page.svelte</strong> |
| 57 | + </h2> |
54 | 58 |
|
55 |
| - <Counter /> |
| 59 | + <Counter/> |
56 | 60 |
|
57 |
| - <Particles |
58 |
| - id="tsparticles" |
59 |
| - class="foo bar" |
60 |
| - style="" |
61 |
| - options="{particlesConfig}" |
62 |
| - particlesInit="{particlesInit}" |
63 |
| - /> |
| 61 | + {#await ParticlesConstructor} |
| 62 | + <p>Loading...</p> |
| 63 | + {:then component} |
| 64 | + <svelte:component this={component} id="tsparticles" |
| 65 | + options="{particlesConfig}"/> |
| 66 | + {:catch error} |
| 67 | + <p>Something went wrong: {error.message}</p> |
| 68 | + {/await} |
64 | 69 | </section>
|
65 | 70 |
|
66 | 71 | <style>
|
67 |
| - section { |
68 |
| - display: flex; |
69 |
| - flex-direction: column; |
70 |
| - justify-content: center; |
71 |
| - align-items: center; |
72 |
| - flex: 0.6; |
73 |
| - } |
| 72 | + section { |
| 73 | + display: flex; |
| 74 | + flex-direction: column; |
| 75 | + justify-content: center; |
| 76 | + align-items: center; |
| 77 | + flex: 0.6; |
| 78 | + } |
74 | 79 |
|
75 |
| - h1 { |
76 |
| - width: 100%; |
77 |
| - } |
| 80 | + h1 { |
| 81 | + width: 100%; |
| 82 | + } |
78 | 83 |
|
79 |
| - .welcome { |
80 |
| - display: block; |
81 |
| - position: relative; |
82 |
| - width: 100%; |
83 |
| - height: 0; |
84 |
| - padding: 0 0 calc(100% * 495 / 2048) 0; |
85 |
| - } |
| 84 | + .welcome { |
| 85 | + display: block; |
| 86 | + position: relative; |
| 87 | + width: 100%; |
| 88 | + height: 0; |
| 89 | + padding: 0 0 calc(100% * 495 / 2048) 0; |
| 90 | + } |
86 | 91 |
|
87 |
| - .welcome img { |
88 |
| - position: absolute; |
89 |
| - width: 100%; |
90 |
| - height: 100%; |
91 |
| - top: 0; |
92 |
| - display: block; |
93 |
| - } |
| 92 | + .welcome img { |
| 93 | + position: absolute; |
| 94 | + width: 100%; |
| 95 | + height: 100%; |
| 96 | + top: 0; |
| 97 | + display: block; |
| 98 | + } |
94 | 99 | </style>
|
0 commit comments