UNPKG

5.32 kBMarkdownView Raw
1[![banner](https://particles.js.org/images/banner2.png)](https://particles.js.org)
2
3# tsParticles Full Bundle
4
5[![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles/badge)](https://www.jsdelivr.com/package/npm/tsparticles) [![npmjs](https://badge.fury.io/js/tsparticles.svg)](https://www.npmjs.com/package/tsparticles) [![npmjs](https://img.shields.io/npm/dt/tsparticles)](https://www.npmjs.com/package/tsparticles) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
7[tsParticles](https://github.com/tsparticles/tsparticles) full bundle loads all the v1 features to
8a `@tsparticles/engine` instance.
9
10**Included Packages**
11
12- [@tsparticles/slim (and all its dependencies)](https://github.com/tsparticles/tsparticles/tree/main/bundles/slim)
13- [@tsparticles/interaction-external-trail](https://github.com/tsparticles/tsparticles/tree/main/interactions/external/trail)
14- [@tsparticles/plugin-absorbers](https://github.com/tsparticles/tsparticles/tree/main/plugins/absorbers)
15- [@tsparticles/plugin-emitters](https://github.com/tsparticles/tsparticles/tree/main/plugins/emitters)
16- [@tsparticles/shape-text](https://github.com/tsparticles/tsparticles/tree/main/shapes/text)
17- [@tsparticles/updater-destroy](https://github.com/tsparticles/tsparticles/tree/main/updaters/destroy)
18- [@tsparticles/updater-roll](https://github.com/tsparticles/tsparticles/tree/main/updaters/roll)
19- [@tsparticles/updater-tilt](https://github.com/tsparticles/tsparticles/tree/main/updaters/tilt)
20- [@tsparticles/updater-twinkle](https://github.com/tsparticles/tsparticles/tree/main/updaters/twinkle)
21- [@tsparticles/updater-wobble](https://github.com/tsparticles/tsparticles/tree/main/updaters/wobble)
22
23## How to use it
24
25### CDN / Vanilla JS / jQuery
26
27The CDN/Vanilla version JS has two different files:
28
29- One is a bundle file with all the scripts included in a single file
30- One is a file including just the `loadFull` function to load the tsParticles full preset, all dependencies must be
31 included manually
32
33#### Bundle
34
35Including the `tsparticles.bundle.min.js` file will work exactly like `v1`, you can start using the `tsParticles`
36instance in the same way.
37
38This is the easiest usage, since it's a single file with the same `v1` features.
39
40All new features will be added as external packages, this bundle is recommended for migrating from `v1` easily.
41
42#### Not Bundle
43
44This installation requires more work since all dependencies must be included in the page. Some lines above are all
45specified in the **Included Packages** section.
46
47A note about `@tsparticles/slim` can be made: it's not mandatory to include all of its dependencies, the slim bundle file
48is enough, and if this is done the `@tsparticles/engine` is not needed, since it's already bundled in the slim bundle.
49
50### Usage
51
52Once the scripts are loaded you can set up `tsParticles` like this:
53
54```javascript
55(async () => {
56 await loadFull(tsParticles);
57
58 await tsParticles.load({
59 id: "tsparticles",
60 options: {
61 /* options */
62 },
63 });
64})();
65```
66
67### React.js / Preact / Inferno
68
69_The syntax for `React.js`, `Preact` and `Inferno` is the same_.
70
71This sample uses the class component syntax, but you can use hooks as well (if the library supports it).
72
73_Class Components_
74
75```typescript jsx
76import React from "react";
77import Particles from "react-particles";
78import type { Engine } from "@tsparticles/engine";
79import { loadFull } from "tsparticles";
80
81export class ParticlesContainer extends PureComponent<unknown> {
82 // this customizes the component tsParticles installation
83 async customInit(engine: Engine): Promise<void> {
84 // this adds the bundle to tsParticles
85 await loadFull(engine);
86 }
87
88 render() {
89 const options = {
90 /* custom options */
91 };
92
93 return <Particles options={options} init={this.customInit} />;
94 }
95}
96```
97
98_Hooks / Functional Components_
99
100```typescript jsx
101import React, { useCallback } from "react";
102import Particles from "react-particles";
103import type { Engine } from "@tsparticles/engine";
104import { loadFull } from "tsparticles";
105
106export function ParticlesContainer(props: unknown) {
107 // this customizes the component tsParticles installation
108 const customInit = useCallback(async (engine: Engine) => {
109 // this adds the bundle to tsParticles
110 await loadFull(engine);
111 });
112
113 const options = {
114 /* custom options */
115 };
116
117 return <Particles options={options} init={this.customInit} />;
118}
119```
120
121### Vue (2.x and 3.x)
122
123_The syntax for `Vue.js 2.x` and `3.x` is the same_
124
125```vue
126<Particles id="tsparticles" :particlesInit="particlesInit" :options="options" />
127```
128
129```js
130const options = {
131 /* custom options */
132};
133
134async function particlesInit(engine: Engine): Promise<void> {
135 await loadFull(engine);
136}
137```
138
139### Angular
140
141```html
142<ng-particles [id]="id" [options]="options" [particlesInit]="particlesInit"></ng-particles>
143```
144
145```ts
146const options = {
147 /* custom options */
148};
149
150async function particlesInit(engine: Engine): Promise<void> {
151 await loadFull(engine);
152}
153```
154
155### Svelte
156
157```sveltehtml
158
159<Particles
160 id="tsparticles"
161 options={options}
162 particlesInit={particlesInit}
163/>
164```
165
166```js
167let options = {
168 /* custom options */
169};
170
171let particlesInit = async (engine) => {
172 await loadFull(engine);
173};
174```