You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
101
+
import { loadSlim } from'@tsparticles/slim'; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
102
+
103
+
let ParticlesComponent;
104
+
105
+
onMount(async () => {
106
+
constmodule=awaitimport('@tsparticles/svelte');
107
+
108
+
ParticlesComponent =module.default;
109
+
});
110
+
111
+
let particlesUrl ='http://foo.bar/particles.json'; // placeholder, replace it with a real url
112
+
113
+
let particlesConfig = {
114
+
particles: {
115
+
color: {
116
+
value:'#000'
117
+
},
118
+
links: {
119
+
enable:true,
120
+
color:'#000'
121
+
},
122
+
move: {
123
+
enable:true
124
+
},
125
+
number: {
126
+
value:100
127
+
}
128
+
}
129
+
};
130
+
131
+
letonParticlesLoaded= (event) => {
132
+
constparticlesContainer=event.detail.particles;
133
+
134
+
// you can use particlesContainer to call all the Container class
135
+
// (from the core library) methods like play, pause, refresh, start, stop
136
+
};
137
+
138
+
voidparticlesInit(async (engine) => {
139
+
// call this once per app
140
+
// you can use main to customize the tsParticles instance adding presets or custom shapes
141
+
// this loads the tsparticles package bundle, it's the easiest method for getting everything ready
142
+
// starting from v2 you can add only the features you need reducing the bundle size
143
+
//await loadFull(main);
144
+
awaitloadSlim(engine);
145
+
});
145
146
</script>
146
147
147
148
<svelte:component
148
-
this="{ParticlesComponent}"
149
-
id="tsparticles"
150
-
class="foo bar"
151
-
style=""
152
-
options="{particlesConfig}"
153
-
on:particlesLoaded="{onParticlesLoaded}"
154
-
particlesInit="{particlesInit}"
149
+
this="{ParticlesComponent}"
150
+
id="tsparticles"
151
+
class="put your classes here"
152
+
style=""
153
+
options="{particlesConfig}"
154
+
on:particlesLoaded="{onParticlesLoaded}"
155
155
/>
156
156
157
157
<!-- or -->
158
158
159
159
<svelte:component
160
-
this="{ParticlesComponent}"
161
-
id="tsparticles"
162
-
class="foo bar"
163
-
style=""
164
-
url="{particlesUrl}"
165
-
on:particlesLoaded="{onParticlesLoaded}"
166
-
particlesInit="{particlesInit}"
160
+
this="{ParticlesComponent}"
161
+
id="tsparticles"
162
+
class="put your classes here"
163
+
style=""
164
+
url="{particlesUrl}"
165
+
on:particlesLoaded="{onParticlesLoaded}"
167
166
/>
168
167
```
169
168
@@ -173,10 +172,10 @@ A user reported me a TypeScript error (#3963), and that's because this Svelte co
173
172
174
173
If someone is experiencing the same error, please follow these steps:
175
174
176
-
-install these packages: `typescript`, `svelte-preprocess`.
177
-
-add a `tsconfig.json` file to your project, following this sample: <https://github.com/ivanhofer/sveltekit-typescript-showcase#configure-typescript> (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/main/tsconfig.json>)
178
-
-import `svelte-preprocess` in your svelte configuration file, like this: `import preprocess from 'svelte-preprocess'` (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/c824e45338ffc1a9c907c63d00a6a0af4884a0e9/svelte.config.js#L2>)
179
-
-use the `preprocess` function in your svelte configuration file, like this: `preprocess: preprocess(),` (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/c824e45338ffc1a9c907c63d00a6a0af4884a0e9/svelte.config.js#L9>)
175
+
- install these packages: `typescript`, `svelte-preprocess`.
176
+
- add a `tsconfig.json` file to your project, following this sample: <https://github.com/ivanhofer/sveltekit-typescript-showcase#configure-typescript> (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/main/tsconfig.json>)
177
+
- import `svelte-preprocess` in your svelte configuration file, like this: `import preprocess from 'svelte-preprocess'` (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/c824e45338ffc1a9c907c63d00a6a0af4884a0e9/svelte.config.js#L2>)
178
+
- use the `preprocess` function in your svelte configuration file, like this: `preprocess: preprocess(),` (see this for example: <https://github.com/ivanhofer/sveltekit-typescript-showcase/blob/c824e45338ffc1a9c907c63d00a6a0af4884a0e9/svelte.config.js#L9>)
180
179
181
180
After that, everything should work as expected.
182
181
@@ -185,14 +184,14 @@ After that, everything should work as expected.
185
184
If you have issues with SvelteKit, like you _Cannot use import statement outside a module_, change your `vite.config.ts` file like this:
186
185
187
186
```ts
188
-
import { sveltekit } from"@sveltejs/kit/vite";
189
-
import { defineConfig } from"vite";
187
+
import { sveltekit } from'@sveltejs/kit/vite';
188
+
import { defineConfig } from'vite';
190
189
191
190
exportdefaultdefineConfig({
192
191
plugins: [sveltekit()],
193
192
ssr: {
194
-
noExternal: ["tsparticles", "@tsparticles/slim", "@tsparticles/engine", "@tsparticles/svelte"],// add all tsparticles libraries here, they're not made for SSR, they're client only
195
-
},
193
+
noExternal: ['tsparticles', '@tsparticles/slim', '@tsparticles/engine', '@tsparticles/svelte']// add all tsparticles libraries here, they're not made for SSR, they're client only
* migrated to v3, used new init structure ([bee139b](https://github.com/tsparticles/svelte/commit/bee139bd3466725681212a5d662060cd2f1b3dc2))
12
-
* updated to v3, needs new initialization function to replace particlesInit ([404d847](https://github.com/tsparticles/svelte/commit/404d847673d7d6d830b8ecf9433e4bd468a475fd))
10
+
- migrated to v3, used new init structure ([bee139b](https://github.com/tsparticles/svelte/commit/bee139bd3466725681212a5d662060cd2f1b3dc2))
11
+
- updated to v3, needs new initialization function to replace particlesInit ([404d847](https://github.com/tsparticles/svelte/commit/404d847673d7d6d830b8ecf9433e4bd468a475fd))
0 commit comments