@tsparticles/svelte 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Matteo Bruni
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,210 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # @tsparticles/svelte
4
+
5
+ [![npm](https://img.shields.io/npm/v/@tsparticles/svelte)](https://www.npmjs.com/package/@tsparticles/svelte) [![npm downloads](https://img.shields.io/npm/dm/@tsparticles/svelte)](https://www.npmjs.com/package/@tsparticles/svelte) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
+
7
+ Official [tsParticles](https://github.com/matteobruni/tsparticles) SvelteJS component
8
+
9
+ [![Slack](https://particles.js.org/images/slack.png)](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI) [![Discord](https://particles.js.org/images/discord.png)](https://discord.gg/hACwv45Hme) [![Telegram](https://particles.js.org/images/telegram.png)](https://t.me/tsparticles)
10
+
11
+ [![tsParticles Product Hunt](https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=186113&theme=light)](https://www.producthunt.com/posts/tsparticles?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-tsparticles") <a href="https://www.buymeacoffee.com/matteobruni"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a beer&emoji=🍺&slug=matteobruni&button_colour=5F7FFF&font_colour=ffffff&font_family=Arial&outline_colour=000000&coffee_colour=FFDD00"></a>
12
+
13
+ ## Installation
14
+
15
+ ```shell
16
+ npm install @tsparticles/svelte
17
+ ```
18
+
19
+ or
20
+
21
+ ```shell
22
+ yarn add @tsparticles/svelte
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```html
28
+ <script>
29
+ import Particles, { particlesInit } from '@tsparticles/svelte';
30
+ //import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
31
+ import { loadSlim } from '@tsparticles/slim'; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
32
+
33
+ let particlesUrl = 'http://foo.bar/particles.json'; // placeholder, replace it with a real url
34
+
35
+ let particlesConfig = {
36
+ particles: {
37
+ color: {
38
+ value: '#000'
39
+ },
40
+ links: {
41
+ enable: true,
42
+ color: '#000'
43
+ },
44
+ move: {
45
+ enable: true
46
+ },
47
+ number: {
48
+ value: 100
49
+ }
50
+ }
51
+ };
52
+
53
+ let onParticlesLoaded = (event) => {
54
+ const particlesContainer = event.detail.particles;
55
+
56
+ // you can use particlesContainer to call all the Container class
57
+ // (from the core library) methods like play, pause, refresh, start, stop
58
+ };
59
+
60
+ void particlesInit(async (engine) => {
61
+ // call this once per app
62
+ // you can use main to customize the tsParticles instance adding presets or custom shapes
63
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
64
+ // starting from v2 you can add only the features you need reducing the bundle size
65
+ //await loadFull(engine);
66
+ await loadSlim(engine);
67
+ });
68
+ </script>
69
+
70
+ <Particles
71
+ id="tsparticles"
72
+ class="put your classes here"
73
+ style=""
74
+ options="{particlesConfig}"
75
+ on:particlesLoaded="{onParticlesLoaded}"
76
+ particlesInit="{particlesInit}"
77
+ />
78
+
79
+ <!-- or -->
80
+
81
+ <Particles
82
+ id="tsparticles"
83
+ class="put your classes here"
84
+ style=""
85
+ url="{particlesUrl}"
86
+ on:particlesLoaded="{onParticlesLoaded}"
87
+ particlesInit="{particlesInit}"
88
+ />
89
+ ```
90
+
91
+ ### SSR
92
+
93
+ The particles component isn't built for SSR, so you have to force the component to be called client side
94
+ with `async import`.
95
+
96
+ You can see a sample below:
97
+
98
+ ```html
99
+ <script>
100
+ import { particlesInit } from '@tsparticles/svelte';
101
+ import { onMount } from 'svelte';
102
+ //import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
103
+ import { loadSlim } from '@tsparticles/slim'; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
104
+
105
+ let ParticlesComponent;
106
+
107
+ onMount(async () => {
108
+ const module = await import('@tsparticles/svelte');
109
+
110
+ ParticlesComponent = module.default;
111
+ });
112
+
113
+ let particlesUrl = 'http://foo.bar/particles.json'; // placeholder, replace it with a real url
114
+
115
+ let particlesConfig = {
116
+ particles: {
117
+ color: {
118
+ value: '#000'
119
+ },
120
+ links: {
121
+ enable: true,
122
+ color: '#000'
123
+ },
124
+ move: {
125
+ enable: true
126
+ },
127
+ number: {
128
+ value: 100
129
+ }
130
+ }
131
+ };
132
+
133
+ let onParticlesLoaded = (event) => {
134
+ const particlesContainer = event.detail.particles;
135
+
136
+ // you can use particlesContainer to call all the Container class
137
+ // (from the core library) methods like play, pause, refresh, start, stop
138
+ };
139
+
140
+ void particlesInit(async (engine) => {
141
+ // call this once per app
142
+ // you can use main to customize the tsParticles instance adding presets or custom shapes
143
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
144
+ // starting from v2 you can add only the features you need reducing the bundle size
145
+ //await loadFull(main);
146
+ await loadSlim(engine);
147
+ });
148
+ </script>
149
+
150
+ <svelte:component
151
+ this="{ParticlesComponent}"
152
+ id="tsparticles"
153
+ class="put your classes here"
154
+ style=""
155
+ options="{particlesConfig}"
156
+ on:particlesLoaded="{onParticlesLoaded}"
157
+ particlesInit="{particlesInit}"
158
+ />
159
+
160
+ <!-- or -->
161
+
162
+ <svelte:component
163
+ this="{ParticlesComponent}"
164
+ id="tsparticles"
165
+ class="put your classes here"
166
+ style=""
167
+ url="{particlesUrl}"
168
+ on:particlesLoaded="{onParticlesLoaded}"
169
+ particlesInit="{particlesInit}"
170
+ />
171
+ ```
172
+
173
+ ### TypeScript errors
174
+
175
+ A user reported me a TypeScript error (#3963), and that's because this Svelte component is built using TypeScript.
176
+
177
+ If someone is experiencing the same error, please follow these steps:
178
+
179
+ - install these packages: `typescript`, `svelte-preprocess`.
180
+ - 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>)
181
+ - 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>)
182
+ - 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>)
183
+
184
+ After that, everything should work as expected.
185
+
186
+ ### SvelteKit
187
+
188
+ If you have issues with SvelteKit, like you _Cannot use import statement outside a module_, change your `vite.config.ts` file like this:
189
+
190
+ ```ts
191
+ import { sveltekit } from '@sveltejs/kit/vite';
192
+ import { defineConfig } from 'vite';
193
+
194
+ export default defineConfig({
195
+ plugins: [sveltekit()],
196
+ ssr: {
197
+ noExternal: ['tsparticles', '@tsparticles/slim', '@tsparticles/engine', '@tsparticles/svelte'] // add all tsparticles libraries here, they're not made for SSR, they're client only
198
+ }
199
+ });
200
+ ```
201
+
202
+ ## Demos
203
+
204
+ The demo website is [here](https://particles.js.org)
205
+
206
+ <https://particles.js.org>
207
+
208
+ There's also a CodePen collection actively maintained and updated [here](https://codepen.io/collection/DPOage)
209
+
210
+ <https://codepen.io/collection/DPOage>
@@ -0,0 +1,64 @@
1
+ <svelte:options accessors={true} />
2
+
3
+ <script>import { afterUpdate, createEventDispatcher, onDestroy, onMount } from "svelte";
4
+ import { tsParticles } from "@tsparticles/engine";
5
+ import { initialized } from "./utils.js";
6
+ let cssClass = "";
7
+ export { cssClass as class };
8
+ let canStart = false;
9
+ let style = "";
10
+ export { style };
11
+ export let options = {};
12
+ export let url = "";
13
+ export let id = "tsparticles";
14
+ const dispatch = createEventDispatcher(), particlesLoadedEvent = "particlesLoaded";
15
+ let oldId = id;
16
+ function destroyOldContainer() {
17
+ if (oldId) {
18
+ const oldContainer = tsParticles.dom().find((c) => c.id.toString() === oldId);
19
+ if (oldContainer) {
20
+ oldContainer.destroy();
21
+ }
22
+ }
23
+ }
24
+ const unsub = initialized.subscribe((value) => {
25
+ canStart = value;
26
+ loadParticles();
27
+ });
28
+ onDestroy(() => {
29
+ unsub();
30
+ destroyOldContainer();
31
+ });
32
+ onMount(() => {
33
+ void loadParticles();
34
+ });
35
+ async function loadParticles() {
36
+ destroyOldContainer();
37
+ if (!canStart) {
38
+ return;
39
+ }
40
+ if (id) {
41
+ const cb = (container2) => {
42
+ dispatch(particlesLoadedEvent, {
43
+ particles: container2
44
+ });
45
+ oldId = id;
46
+ };
47
+ const container = await tsParticles.load({
48
+ id,
49
+ options,
50
+ url
51
+ });
52
+ cb(container);
53
+ } else {
54
+ dispatch(particlesLoadedEvent, {
55
+ particles: void 0
56
+ });
57
+ }
58
+ }
59
+ afterUpdate(async () => {
60
+ await loadParticles();
61
+ });
62
+ </script>
63
+
64
+ <div {id} class={cssClass} {style} />
@@ -0,0 +1,37 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ class?: string | undefined;
5
+ style?: string | undefined;
6
+ options?: import("@tsparticles/engine").RecursivePartial<import("@tsparticles/engine").IOptions> | undefined;
7
+ url?: string | undefined;
8
+ id?: string | undefined;
9
+ };
10
+ events: {
11
+ particlesLoaded: CustomEvent<any>;
12
+ } & {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {};
16
+ };
17
+ export type ParticlesProps = typeof __propDef.props;
18
+ export type ParticlesEvents = typeof __propDef.events;
19
+ export type ParticlesSlots = typeof __propDef.slots;
20
+ export default class Particles extends SvelteComponent<ParticlesProps, ParticlesEvents, ParticlesSlots> {
21
+ get class(): string | undefined;
22
+ /**accessor*/
23
+ set class(_: string | undefined);
24
+ get undefined(): any;
25
+ /**accessor*/
26
+ set undefined(_: any);
27
+ get options(): import("@tsparticles/engine").RecursivePartial<import("@tsparticles/engine").IOptions> | undefined;
28
+ /**accessor*/
29
+ set options(_: import("@tsparticles/engine").RecursivePartial<import("@tsparticles/engine").IOptions> | undefined);
30
+ get url(): string | undefined;
31
+ /**accessor*/
32
+ set url(_: string | undefined);
33
+ get id(): string | undefined;
34
+ /**accessor*/
35
+ set id(_: string | undefined);
36
+ }
37
+ export {};
@@ -0,0 +1,4 @@
1
+ import { type Engine } from '@tsparticles/engine';
2
+ import Particles from './Particles.svelte';
3
+ declare function particlesInit(init: (engine: Engine) => Promise<void>): Promise<void>;
4
+ export { Particles as default, particlesInit };
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import { tsParticles } from '@tsparticles/engine';
2
+ import Particles from './Particles.svelte';
3
+ import { initialized } from './utils.js';
4
+ async function particlesInit(init) {
5
+ tsParticles.init();
6
+ await init(tsParticles);
7
+ initialized.set(true);
8
+ }
9
+ export { Particles as default, particlesInit };
@@ -0,0 +1,3 @@
1
+ /// <reference types="svelte" />
2
+ declare const initialized: import("svelte/store").Writable<boolean>;
3
+ export { initialized };
package/dist/utils.js ADDED
@@ -0,0 +1,3 @@
1
+ import { writable } from 'svelte/store';
2
+ const initialized = writable(false);
3
+ export { initialized };
package/package.json ADDED
@@ -0,0 +1,120 @@
1
+ {
2
+ "name": "@tsparticles/svelte",
3
+ "version": "3.0.0",
4
+ "description": "Official tsParticles Svelte Component - Easily create highly customizable particle, confetti and fireworks animations and use them as animated backgrounds for your website. Ready to use components available also for Web Components, React, Vue.js (2.x and 3.x), Angular, jQuery, Preact, Riot.js, Solid.js, Inferno.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/tsparticles/svelte.git",
8
+ "directory": "components/svelte"
9
+ },
10
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
11
+ "license": "MIT",
12
+ "keywords": [
13
+ "front-end",
14
+ "frontend",
15
+ "tsparticles",
16
+ "particles.js",
17
+ "particlesjs",
18
+ "particles",
19
+ "particle",
20
+ "canvas",
21
+ "jsparticles",
22
+ "xparticles",
23
+ "particles-js",
24
+ "particles-bg",
25
+ "particles-bg-vue",
26
+ "particles-ts",
27
+ "particles.ts",
28
+ "react-particles-js",
29
+ "react-particles.js",
30
+ "react-particles",
31
+ "react",
32
+ "reactjs",
33
+ "vue-particles",
34
+ "ngx-particles",
35
+ "angular-particles",
36
+ "particleground",
37
+ "vue",
38
+ "vuejs",
39
+ "preact",
40
+ "preactjs",
41
+ "jquery",
42
+ "angularjs",
43
+ "angular",
44
+ "typescript",
45
+ "javascript",
46
+ "animation",
47
+ "web",
48
+ "html5",
49
+ "web-design",
50
+ "webdesign",
51
+ "css",
52
+ "html",
53
+ "css3",
54
+ "animated",
55
+ "background",
56
+ "confetti",
57
+ "canvas",
58
+ "fireworks",
59
+ "fireworks-js",
60
+ "confetti-js",
61
+ "confettijs",
62
+ "fireworksjs",
63
+ "canvas-confetti"
64
+ ],
65
+ "scripts": {
66
+ "dev": "vite dev",
67
+ "build": "pnpm run format && vite build && npm run package",
68
+ "preview": "vite preview",
69
+ "package": "svelte-kit sync && svelte-package && publint",
70
+ "prepublishOnly": "npm run package",
71
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
72
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
73
+ "lint": "prettier --check . && eslint .",
74
+ "format": "prettier --write ."
75
+ },
76
+ "exports": {
77
+ ".": {
78
+ "types": "./dist/index.d.ts",
79
+ "svelte": "./dist/index.js"
80
+ }
81
+ },
82
+ "files": [
83
+ "dist",
84
+ "!dist/**/*.test.*",
85
+ "!dist/**/*.spec.*"
86
+ ],
87
+ "publishConfig": {
88
+ "access": "public"
89
+ },
90
+ "peerDependencies": {
91
+ "svelte": "^4.0.0"
92
+ },
93
+ "dependencies": {
94
+ "@tsparticles/engine": "^3.0.2"
95
+ },
96
+ "devDependencies": {
97
+ "@sveltejs/adapter-auto": "^3.0.1",
98
+ "@sveltejs/kit": "^2.0.6",
99
+ "@sveltejs/package": "^2.2.4",
100
+ "@sveltejs/vite-plugin-svelte": "^3.0.1",
101
+ "@types/eslint": "^8.56.0",
102
+ "@typescript-eslint/eslint-plugin": "^6.15.0",
103
+ "@typescript-eslint/parser": "^6.15.0",
104
+ "eslint": "^8.56.0",
105
+ "eslint-config-prettier": "^9.1.0",
106
+ "eslint-plugin-svelte": "^2.35.1",
107
+ "prettier": "^3.1.1",
108
+ "prettier-plugin-svelte": "^3.1.2",
109
+ "publint": "^0.2.7",
110
+ "svelte": "^4.2.8",
111
+ "svelte-check": "^3.6.2",
112
+ "tslib": "^2.6.2",
113
+ "typescript": "^5.3.3",
114
+ "vite": "^5.0.10"
115
+ },
116
+ "svelte": "./dist/index.js",
117
+ "types": "./dist/index.d.ts",
118
+ "type": "module",
119
+ "gitHead": "8d902bd74e28a7f9f63e841000995774586560d6"
120
+ }