@tsparticles/react 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,401 @@
1
+ [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
+
3
+ # @tsparticles/react
4
+
5
+ [![npm](https://img.shields.io/npm/v/@tsparticles/react)](https://www.npmjs.com/package/@tsparticles/react) [![npm](https://img.shields.io/npm/dm/@tsparticles/react)](https://www.npmjs.com/package/@tsparticles/react) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
+
7
+ Official [tsParticles](https://github.com/tsparticles/tsparticles) ReactJS 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/react
17
+ ```
18
+
19
+ or
20
+
21
+ ```shell
22
+ yarn add @tsparticles/react
23
+ ```
24
+
25
+ ### TypeScript Installation
26
+
27
+ ```shell
28
+ npm install @tsparticles/react @tsparticles/engine
29
+ ```
30
+
31
+ or
32
+
33
+ ```shell
34
+ yarn add @tsparticles/react @tsparticles/engine
35
+ ```
36
+
37
+ [@tsparticles/engine](https://npmjs.com/package/@tsparticles/engine) is the core package for [tsParticles](https://particles.js.org), it contains useful types like `ISourceOptions`, `Engine` or `Container`.
38
+
39
+ ### create-react-app
40
+
41
+ Starting from version 1.17.0 there are two official `create-react-app` templates:
42
+
43
+ - `cra-template-particles`: Simple ReactJS template with full screen particles, using JavaScript
44
+ - `cra-template-particles-typescript`: Simple ReactJS template with full screen particles, using TypeScript
45
+
46
+ You can simply install them using the `create-react-app` command like this:
47
+
48
+ ```shell
49
+ $ create-react-app your_app --template particles
50
+ ```
51
+
52
+ or
53
+
54
+ ```shell
55
+ $ create-react-app your_app --template particles-typescript
56
+ ```
57
+
58
+ ## How to use
59
+
60
+ ### Code
61
+
62
+ Examples:
63
+
64
+ #### Options object
65
+
66
+ ##### JavaScript support - object
67
+
68
+ ```jsx
69
+ import { useCallback, useEffect, useState } from "react";
70
+ import Particles, { initParticlesEngine } from "@tsparticles/react";
71
+ // import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
72
+ // import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
73
+ import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
74
+ // import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
75
+
76
+ const App = () => {
77
+ const [ init, setInit ] = useState(false);
78
+
79
+ // this should be run only once per application lifetime
80
+ useEffect(() => {
81
+ initParticlesEngine(async (engine) => {
82
+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
83
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
84
+ // starting from v2 you can add only the features you need reducing the bundle size
85
+ //await loadAll(engine);
86
+ //await loadFull(engine);
87
+ await loadSlim(engine);
88
+ //await loadBasic(engine);
89
+ }).then(() => {
90
+ setInit(true);
91
+ });
92
+ }, []);
93
+
94
+ const particlesLoaded = (container) => {
95
+ console.log(container);
96
+ };
97
+
98
+ return (
99
+ { init && <Particles
100
+ id="tsparticles"
101
+ particlesLoaded={particlesLoaded}
102
+ options={{
103
+ background: {
104
+ color: {
105
+ value: "#0d47a1",
106
+ },
107
+ },
108
+ fpsLimit: 120,
109
+ interactivity: {
110
+ events: {
111
+ onClick: {
112
+ enable: true,
113
+ mode: "push",
114
+ },
115
+ onHover: {
116
+ enable: true,
117
+ mode: "repulse",
118
+ },
119
+ resize: true,
120
+ },
121
+ modes: {
122
+ push: {
123
+ quantity: 4,
124
+ },
125
+ repulse: {
126
+ distance: 200,
127
+ duration: 0.4,
128
+ },
129
+ },
130
+ },
131
+ particles: {
132
+ color: {
133
+ value: "#ffffff",
134
+ },
135
+ links: {
136
+ color: "#ffffff",
137
+ distance: 150,
138
+ enable: true,
139
+ opacity: 0.5,
140
+ width: 1,
141
+ },
142
+ move: {
143
+ direction: "none",
144
+ enable: true,
145
+ outModes: {
146
+ default: "bounce",
147
+ },
148
+ random: false,
149
+ speed: 6,
150
+ straight: false,
151
+ },
152
+ number: {
153
+ density: {
154
+ enable: true,
155
+ area: 800,
156
+ },
157
+ value: 80,
158
+ },
159
+ opacity: {
160
+ value: 0.5,
161
+ },
162
+ shape: {
163
+ type: "circle",
164
+ },
165
+ size: {
166
+ value: { min: 1, max: 5 },
167
+ },
168
+ },
169
+ detectRetina: true,
170
+ }}
171
+ />
172
+ }
173
+ )
174
+ ;
175
+ };
176
+ ```
177
+
178
+ ##### TypeScript support - object
179
+
180
+ ```tsx
181
+ import { useCallback, useEffect, useState } from "react";
182
+ import Particles, { initParticlesEngine } from "@tsparticles/react";
183
+ import type { Container, Engine } from "@tsparticles/engine";
184
+ // import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
185
+ // import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
186
+ import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
187
+ // import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
188
+
189
+ const App = () => {
190
+ const [ init, setInit ] = useState(false);
191
+
192
+ // this should be run only once per application lifetime
193
+ useEffect(() => {
194
+ initParticlesEngine(async (engine) => {
195
+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
196
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
197
+ // starting from v2 you can add only the features you need reducing the bundle size
198
+ //await loadAll(engine);
199
+ //await loadFull(engine);
200
+ await loadSlim(engine);
201
+ //await loadBasic(engine);
202
+ }).then(() => {
203
+ setInit(true);
204
+ });
205
+ }, []);
206
+
207
+ const particlesLoaded = (container) => {
208
+ console.log(container);
209
+ };
210
+
211
+ return (
212
+ { init && <Particles
213
+ id="tsparticles"
214
+ particlesLoaded={particlesLoaded}
215
+ options={{
216
+ background: {
217
+ color: {
218
+ value: "#0d47a1",
219
+ },
220
+ },
221
+ fpsLimit: 120,
222
+ interactivity: {
223
+ events: {
224
+ onClick: {
225
+ enable: true,
226
+ mode: "push",
227
+ },
228
+ onHover: {
229
+ enable: true,
230
+ mode: "repulse",
231
+ },
232
+ resize: true,
233
+ },
234
+ modes: {
235
+ push: {
236
+ quantity: 4,
237
+ },
238
+ repulse: {
239
+ distance: 200,
240
+ duration: 0.4,
241
+ },
242
+ },
243
+ },
244
+ particles: {
245
+ color: {
246
+ value: "#ffffff",
247
+ },
248
+ links: {
249
+ color: "#ffffff",
250
+ distance: 150,
251
+ enable: true,
252
+ opacity: 0.5,
253
+ width: 1,
254
+ },
255
+ move: {
256
+ direction: "none",
257
+ enable: true,
258
+ outModes: {
259
+ default: "bounce",
260
+ },
261
+ random: false,
262
+ speed: 6,
263
+ straight: false,
264
+ },
265
+ number: {
266
+ density: {
267
+ enable: true,
268
+ area: 800,
269
+ },
270
+ value: 80,
271
+ },
272
+ opacity: {
273
+ value: 0.5,
274
+ },
275
+ shape: {
276
+ type: "circle",
277
+ },
278
+ size: {
279
+ value: { min: 1, max: 5 },
280
+ },
281
+ },
282
+ detectRetina: true,
283
+ }}
284
+ />
285
+ }
286
+ )
287
+ ;
288
+ };
289
+ ```
290
+
291
+ #### Remote url
292
+
293
+ ##### JavaScript support - url
294
+
295
+ ```jsx
296
+ import { useCallback, useEffect, useState } from "react";
297
+ import Particles, { initParticlesEngine } from "@tsparticles/react";
298
+ // import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
299
+ // import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
300
+ import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
301
+ // import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
302
+
303
+ const App = () => {
304
+ const [ init, setInit ] = useState(false);
305
+
306
+ // this should be run only once per application lifetime
307
+ useEffect(() => {
308
+ initParticlesEngine(async (engine) => {
309
+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
310
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
311
+ // starting from v2 you can add only the features you need reducing the bundle size
312
+ //await loadAll(engine);
313
+ //await loadFull(engine);
314
+ await loadSlim(engine);
315
+ //await loadBasic(engine);
316
+ }).then(() => {
317
+ setInit(true);
318
+ });
319
+ }, []);
320
+
321
+ const particlesLoaded = (container) => {
322
+ console.log(container);
323
+ };
324
+
325
+ return (
326
+ { init && <Particles id="tsparticles" url="http://foo.bar/particles.json" particlesLoaded={particlesLoaded}/>
327
+ }
328
+ )
329
+ ;
330
+ };
331
+ ```
332
+
333
+ ##### TypeScript support - url
334
+
335
+ ```tsx
336
+ import { useCallback, useEffect, useState } from "react";
337
+ import Particles, { initParticlesEngine } from "@tsparticles/react";
338
+ import type { Container, Engine } from "@tsparticles/engine";
339
+ // import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
340
+ // import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
341
+ import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
342
+ // import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
343
+
344
+ const App = () => {
345
+ const [ init, setInit ] = useState(false);
346
+
347
+ // this should be run only once per application lifetime
348
+ useEffect(() => {
349
+ initParticlesEngine(async (engine) => {
350
+ // you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
351
+ // this loads the tsparticles package bundle, it's the easiest method for getting everything ready
352
+ // starting from v2 you can add only the features you need reducing the bundle size
353
+ //await loadAll(engine);
354
+ //await loadFull(engine);
355
+ await loadSlim(engine);
356
+ //await loadBasic(engine);
357
+ }).then(() => {
358
+ setInit(true);
359
+ });
360
+ }, []);
361
+
362
+ const particlesLoaded = (container) => {
363
+ console.log(container);
364
+ };
365
+
366
+ return (
367
+ { init && <Particles id="tsparticles" url="http://foo.bar/particles.json" particlesLoaded={particlesLoaded}/>
368
+ }
369
+ )
370
+ ;
371
+ };
372
+ ```
373
+
374
+ ### Props
375
+
376
+ | Prop | Type | Definition |
377
+ |-----------|--------|------------------------------------------------------|
378
+ | id | string | The id of the element. |
379
+ | width | string | The width of the canvas. |
380
+ | height | string | The height of the canvas. |
381
+ | options | object | The options of the particles instance. |
382
+ | url | string | The remote options url, called using an AJAX request |
383
+ | style | object | The style of the canvas element. |
384
+ | className | string | The class name of the canvas wrapper. |
385
+
386
+ #### particles.json
387
+
388
+ Find all configuration
389
+ options [here](https://particles.js.org/docs/interfaces/tsParticles_Engine.Options_Interfaces_IOptions.IOptions.html).
390
+
391
+ You can find sample configurations [here](https://github.com/tsparticles/tsparticles/tree/main/utils/configs/src) 📖
392
+
393
+ ## Demos
394
+
395
+ Preset demos can be found [here](https://particles.js.org/samples/presets/index.html)
396
+
397
+ There's also a CodePen collection actively maintained and updated [here](https://codepen.io/collection/DPOage)
398
+
399
+ Report bugs and issues [here](https://github.com/tsparticles/tsparticles/issues)
400
+
401
+ [tsParticle Website](https://particles.js.org)
@@ -0,0 +1,10 @@
1
+ import type { Container, ISourceOptions } from "@tsparticles/engine";
2
+ import type { CSSProperties } from "react";
3
+ export interface IParticlesProps {
4
+ id?: string;
5
+ options?: ISourceOptions;
6
+ url?: string;
7
+ style?: CSSProperties;
8
+ className?: string;
9
+ particlesLoaded?: (container?: Container) => Promise<void>;
10
+ }
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,4 @@
1
+ import { FC } from "react";
2
+ import type { IParticlesProps } from "./IParticlesProps";
3
+ declare const Particles: FC<IParticlesProps>;
4
+ export default Particles;
@@ -0,0 +1,18 @@
1
+ import { jsx as d } from "react/jsx-runtime";
2
+ import { useEffect as m } from "react";
3
+ import { tsParticles as s } from "@tsparticles/engine";
4
+ const f = (t) => {
5
+ const i = t.id ?? "tsparticles";
6
+ return m(() => {
7
+ let e;
8
+ return s.load({ id: i, url: t.url, options: t.options }).then((l) => {
9
+ var a;
10
+ e = l, (a = t.particlesLoaded) == null || a.call(t, l);
11
+ }), () => {
12
+ e == null || e.destroy();
13
+ };
14
+ }, [i, t, t.url, t.options]), /* @__PURE__ */ d("div", { id: i, className: t.className });
15
+ };
16
+ export {
17
+ f as default
18
+ };
@@ -0,0 +1,6 @@
1
+ import { Engine } from "@tsparticles/engine";
2
+ import Particles from "./Particles";
3
+ export type { IParticlesProps, } from "./IParticlesProps";
4
+ export declare function initParticlesEngine(cb: (engine: Engine) => Promise<void>): Promise<void>;
5
+ export default Particles;
6
+ export { Particles };
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { tsParticles as i } from "@tsparticles/engine";
2
+ import o from "./Particles.js";
3
+ import "react/jsx-runtime";
4
+ import "react";
5
+ async function n(t) {
6
+ await t(i);
7
+ }
8
+ export {
9
+ o as Particles,
10
+ o as default,
11
+ n as initParticlesEngine
12
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@tsparticles/react",
3
+ "version": "3.0.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "dev": "vite",
9
+ "build": "tsc && vite build",
10
+ "build:ci": "tsc && vite build",
11
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
12
+ "preview": "vite preview",
13
+ "prepublishOnly": "pnpm run build"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "peerDependencies": {
19
+ "@tsparticles/engine": "^3.0.2",
20
+ "react": ">=16.8.0",
21
+ "react-dom": ">=16.8.0"
22
+ },
23
+ "devDependencies": {
24
+ "@tsparticles/engine": "^3.0.2",
25
+ "@types/react": "^18.2.42",
26
+ "@types/react-dom": "^18.2.17",
27
+ "@typescript-eslint/eslint-plugin": "^6.13.2",
28
+ "@typescript-eslint/parser": "^6.13.2",
29
+ "@vitejs/plugin-react": "^4.2.1",
30
+ "eslint": "^8.55.0",
31
+ "eslint-plugin-react-hooks": "^4.6.0",
32
+ "eslint-plugin-react-refresh": "^0.4.5",
33
+ "glob": "^10.3.10",
34
+ "react": "^18.2.0",
35
+ "react-dom": "^18.2.0",
36
+ "typescript": "^5.3.3",
37
+ "vite": "^5.0.6",
38
+ "vite-plugin-dts": "^3.6.4",
39
+ "vite-plugin-lib-inject-css": "^1.3.0"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "gitHead": "06ad7ff6a21833bb7c62c443b2cfb6bbcba58273"
45
+ }