@tsparticles/pjs 3.0.0-alpha.1 → 3.0.0-beta.5
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/README.md +46 -8
- package/browser/VincentGarreau/particles.js +271 -0
- package/browser/bundle.js +2 -2
- package/browser/index.js +7 -20
- package/browser/marcbruederlin/Particles.js +83 -0
- package/browser/package.json +1 -0
- package/cjs/VincentGarreau/particles.js +274 -0
- package/cjs/bundle.js +3 -2
- package/cjs/index.js +7 -20
- package/cjs/marcbruederlin/Particles.js +87 -0
- package/cjs/package.json +1 -0
- package/esm/VincentGarreau/particles.js +271 -0
- package/esm/bundle.js +2 -2
- package/esm/index.js +7 -20
- package/esm/marcbruederlin/Particles.js +83 -0
- package/esm/package.json +1 -0
- package/package.json +36 -13
- package/report.html +5 -5
- package/tsparticles.pjs.bundle.js +2596 -2312
- package/tsparticles.pjs.bundle.min.js +1 -1
- package/tsparticles.pjs.bundle.min.js.LICENSE.txt +1 -8
- package/tsparticles.pjs.js +396 -12
- package/tsparticles.pjs.min.js +1 -1
- package/tsparticles.pjs.min.js.LICENSE.txt +1 -8
- package/types/VincentGarreau/IParticlesJS.d.ts +117 -0
- package/types/VincentGarreau/particles.d.ts +7 -0
- package/types/bundle.d.ts +2 -2
- package/types/index.d.ts +11 -2
- package/types/marcbruederlin/Particles.d.ts +23 -0
- package/umd/VincentGarreau/particles.js +284 -0
- package/umd/bundle.js +3 -2
- package/umd/index.js +8 -21
- package/umd/marcbruederlin/Particles.js +97 -0
- package/types/IParticlesJS.d.ts +0 -6
- /package/browser/{IParticlesJS.js → VincentGarreau/IParticlesJS.js} +0 -0
- /package/cjs/{IParticlesJS.js → VincentGarreau/IParticlesJS.js} +0 -0
- /package/esm/{IParticlesJS.js → VincentGarreau/IParticlesJS.js} +0 -0
- /package/umd/{IParticlesJS.js → VincentGarreau/IParticlesJS.js} +0 -0
package/README.md
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
# tsParticles Particles.js Compatibility Package
|
4
4
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/particles.js) [](https://www.npmjs.com/package/@tsparticles/particles.js) [](https://www.npmjs.com/package/@tsparticles/particles.js) [](https://github.com/sponsors/matteobruni)
|
6
6
|
|
7
|
-
[tsParticles](https://github.com/
|
7
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) particles.js compatibility library.
|
8
8
|
|
9
9
|
## How to use it
|
10
10
|
|
@@ -17,12 +17,8 @@ The CDN/Vanilla version JS has two different files:
|
|
17
17
|
|
18
18
|
#### Bundle
|
19
19
|
|
20
|
-
Including the `tsparticles.pjs.bundle.min.js` file will work exactly like `v1`, you can start using the `tsParticles
|
21
|
-
the `particlesJS` instance in the same way.
|
22
|
-
|
23
|
-
This is the easiest usage, since it's a single file with the some of the `v1` features.
|
24
|
-
|
25
|
-
All new features will be added as external packages, this bundle is recommended for migrating from `v1` easily.
|
20
|
+
Including the `tsparticles.pjs.bundle.min.js` file will work exactly like `v1`, you can start using the `tsParticles`,
|
21
|
+
the `particlesJS` instance, or the `Particles` object in the same way.
|
26
22
|
|
27
23
|
#### Not Bundle
|
28
24
|
|
@@ -49,3 +45,45 @@ tsParticles.load({
|
|
49
45
|
},
|
50
46
|
});
|
51
47
|
```
|
48
|
+
|
49
|
+
#### Options
|
50
|
+
|
51
|
+
Here you can use ParticlesJS or tsParticles options, they will work both fine.
|
52
|
+
|
53
|
+
### Alternative Usage
|
54
|
+
|
55
|
+
```javascript
|
56
|
+
const { Particles } = initPjs(tsParticles); // not needed if using the bundle script, required for any other installation
|
57
|
+
|
58
|
+
Particles.init({
|
59
|
+
/* options */
|
60
|
+
});
|
61
|
+
```
|
62
|
+
|
63
|
+
#### Particles Options (only for Particles.init)
|
64
|
+
|
65
|
+
| Option | Type | Default | Description |
|
66
|
+
| ------------------ | ------------------ | --------- | --------------------------------------------------------------------- |
|
67
|
+
| `selector` | string | - | _Required:_ The CSS selector of your canvas element |
|
68
|
+
| `maxParticles` | integer | `100` | _Optional:_ Maximum amount of particles |
|
69
|
+
| `sizeVariations` | integer | `3` | _Optional:_ Amount of size variations |
|
70
|
+
| `speed` | integer | `0.5` | _Optional:_ Movement speed of the particles |
|
71
|
+
| `color` | string or string[] | `#000000` | _Optional:_ Color(s) of the particles and connecting lines |
|
72
|
+
| `minDistance` | integer | `120` | _Optional:_ Distance in `px` for connecting lines |
|
73
|
+
| `connectParticles` | boolean | `false` | _Optional:_ `true`/`false` if connecting lines should be drawn or not |
|
74
|
+
| `responsive` | array | `null` | _Optional:_ Array of objects containing breakpoints and options |
|
75
|
+
|
76
|
+
##### Responsive Options
|
77
|
+
|
78
|
+
| Option | Type | Default | Description |
|
79
|
+
| ------------ | ------- | ------- | --------------------------------------------------------- |
|
80
|
+
| `breakpoint` | integer | - | _Required:_ Breakpoint in `px` |
|
81
|
+
| `options` | object | - | _Required:_ Options object, that overrides default values |
|
82
|
+
|
83
|
+
#### Methods
|
84
|
+
|
85
|
+
| Method | Description |
|
86
|
+
| ----------------- | ----------------------------------- |
|
87
|
+
| `pauseAnimation` | Pauses/stops the particle animation |
|
88
|
+
| `resumeAnimation` | Continues the particle animation |
|
89
|
+
| `destroy` | Destroys the plugin |
|
@@ -0,0 +1,271 @@
|
|
1
|
+
import { deepExtend } from "@tsparticles/engine";
|
2
|
+
const defaultPjsOptions = {
|
3
|
+
particles: {
|
4
|
+
number: {
|
5
|
+
value: 400,
|
6
|
+
density: {
|
7
|
+
enable: true,
|
8
|
+
value_area: 800,
|
9
|
+
},
|
10
|
+
},
|
11
|
+
color: {
|
12
|
+
value: "#fff",
|
13
|
+
},
|
14
|
+
shape: {
|
15
|
+
type: "circle",
|
16
|
+
stroke: {
|
17
|
+
width: 0,
|
18
|
+
color: "#ff0000",
|
19
|
+
},
|
20
|
+
polygon: {
|
21
|
+
nb_sides: 5,
|
22
|
+
},
|
23
|
+
image: {
|
24
|
+
src: "",
|
25
|
+
width: 100,
|
26
|
+
height: 100,
|
27
|
+
},
|
28
|
+
},
|
29
|
+
opacity: {
|
30
|
+
value: 1,
|
31
|
+
random: false,
|
32
|
+
anim: {
|
33
|
+
enable: false,
|
34
|
+
speed: 2,
|
35
|
+
opacity_min: 0,
|
36
|
+
sync: false,
|
37
|
+
},
|
38
|
+
},
|
39
|
+
size: {
|
40
|
+
value: 20,
|
41
|
+
random: false,
|
42
|
+
anim: {
|
43
|
+
enable: false,
|
44
|
+
speed: 20,
|
45
|
+
size_min: 0,
|
46
|
+
sync: false,
|
47
|
+
},
|
48
|
+
},
|
49
|
+
line_linked: {
|
50
|
+
enable: true,
|
51
|
+
distance: 100,
|
52
|
+
color: "#fff",
|
53
|
+
opacity: 1,
|
54
|
+
width: 1,
|
55
|
+
},
|
56
|
+
move: {
|
57
|
+
enable: true,
|
58
|
+
speed: 2,
|
59
|
+
direction: "none",
|
60
|
+
random: false,
|
61
|
+
straight: false,
|
62
|
+
out_mode: "out",
|
63
|
+
bounce: false,
|
64
|
+
attract: {
|
65
|
+
enable: false,
|
66
|
+
rotateX: 3000,
|
67
|
+
rotateY: 3000,
|
68
|
+
},
|
69
|
+
},
|
70
|
+
},
|
71
|
+
interactivity: {
|
72
|
+
detect_on: "canvas",
|
73
|
+
events: {
|
74
|
+
onhover: {
|
75
|
+
enable: true,
|
76
|
+
mode: "grab",
|
77
|
+
},
|
78
|
+
onclick: {
|
79
|
+
enable: true,
|
80
|
+
mode: "push",
|
81
|
+
},
|
82
|
+
resize: true,
|
83
|
+
},
|
84
|
+
modes: {
|
85
|
+
grab: {
|
86
|
+
distance: 100,
|
87
|
+
line_linked: {
|
88
|
+
opacity: 1,
|
89
|
+
},
|
90
|
+
},
|
91
|
+
bubble: {
|
92
|
+
distance: 200,
|
93
|
+
size: 80,
|
94
|
+
duration: 0.4,
|
95
|
+
opacity: 1,
|
96
|
+
speed: 3,
|
97
|
+
},
|
98
|
+
repulse: {
|
99
|
+
distance: 200,
|
100
|
+
duration: 0.4,
|
101
|
+
},
|
102
|
+
push: {
|
103
|
+
particles_nb: 4,
|
104
|
+
},
|
105
|
+
remove: {
|
106
|
+
particles_nb: 2,
|
107
|
+
},
|
108
|
+
},
|
109
|
+
},
|
110
|
+
retina_detect: false,
|
111
|
+
};
|
112
|
+
const initParticlesJS = (engine) => {
|
113
|
+
const particlesJS = (tagId, options) => {
|
114
|
+
const fixedOptions = deepExtend(defaultPjsOptions, options);
|
115
|
+
return engine.load({
|
116
|
+
id: tagId,
|
117
|
+
options: {
|
118
|
+
fullScreen: {
|
119
|
+
enable: false,
|
120
|
+
},
|
121
|
+
detectRetina: fixedOptions.retina_detect,
|
122
|
+
smooth: true,
|
123
|
+
interactivity: {
|
124
|
+
detectsOn: fixedOptions.interactivity.detect_on,
|
125
|
+
events: {
|
126
|
+
onHover: {
|
127
|
+
enable: fixedOptions.interactivity.events.onhover.enable,
|
128
|
+
mode: fixedOptions.interactivity.events.onhover.mode,
|
129
|
+
},
|
130
|
+
onClick: {
|
131
|
+
enable: fixedOptions.interactivity.events.onclick.enable,
|
132
|
+
mode: fixedOptions.interactivity.events.onclick.mode,
|
133
|
+
},
|
134
|
+
resize: {
|
135
|
+
enable: fixedOptions.interactivity.events.resize,
|
136
|
+
},
|
137
|
+
},
|
138
|
+
modes: {
|
139
|
+
grab: {
|
140
|
+
distance: fixedOptions.interactivity.modes.grab.distance,
|
141
|
+
links: {
|
142
|
+
opacity: fixedOptions.interactivity.modes.grab.line_linked.opacity,
|
143
|
+
},
|
144
|
+
},
|
145
|
+
bubble: {
|
146
|
+
distance: fixedOptions.interactivity.modes.bubble.distance,
|
147
|
+
size: fixedOptions.interactivity.modes.bubble.size,
|
148
|
+
duration: fixedOptions.interactivity.modes.bubble.duration,
|
149
|
+
opacity: fixedOptions.interactivity.modes.bubble.opacity,
|
150
|
+
speed: fixedOptions.interactivity.modes.bubble.speed,
|
151
|
+
},
|
152
|
+
repulse: {
|
153
|
+
distance: fixedOptions.interactivity.modes.repulse.distance,
|
154
|
+
duration: fixedOptions.interactivity.modes.repulse.duration,
|
155
|
+
},
|
156
|
+
push: {
|
157
|
+
quantity: fixedOptions.interactivity.modes.push.particles_nb,
|
158
|
+
},
|
159
|
+
remove: {
|
160
|
+
quantity: fixedOptions.interactivity.modes.remove.particles_nb,
|
161
|
+
},
|
162
|
+
},
|
163
|
+
},
|
164
|
+
particles: {
|
165
|
+
collisions: {
|
166
|
+
enable: fixedOptions.particles.move.bounce,
|
167
|
+
},
|
168
|
+
number: {
|
169
|
+
value: fixedOptions.particles.number.value,
|
170
|
+
density: {
|
171
|
+
enable: fixedOptions.particles.number.density.enable,
|
172
|
+
width: fixedOptions.particles.number.density.value_area,
|
173
|
+
},
|
174
|
+
},
|
175
|
+
color: {
|
176
|
+
value: fixedOptions.particles.color.value,
|
177
|
+
},
|
178
|
+
stroke: {
|
179
|
+
width: fixedOptions.particles.shape.stroke.width,
|
180
|
+
color: {
|
181
|
+
value: fixedOptions.particles.shape.stroke.color,
|
182
|
+
},
|
183
|
+
},
|
184
|
+
shape: {
|
185
|
+
type: fixedOptions.particles.shape.type,
|
186
|
+
options: {
|
187
|
+
polygon: {
|
188
|
+
sides: fixedOptions.particles.shape.polygon.nb_sides,
|
189
|
+
},
|
190
|
+
image: {
|
191
|
+
src: fixedOptions.particles.shape.image.src,
|
192
|
+
width: fixedOptions.particles.shape.image.width,
|
193
|
+
height: fixedOptions.particles.shape.image.height,
|
194
|
+
},
|
195
|
+
},
|
196
|
+
},
|
197
|
+
opacity: {
|
198
|
+
value: fixedOptions.particles.opacity.random
|
199
|
+
? {
|
200
|
+
min: fixedOptions.particles.opacity.anim.enable
|
201
|
+
? fixedOptions.particles.opacity.anim.opacity_min
|
202
|
+
: 0,
|
203
|
+
max: fixedOptions.particles.opacity.value,
|
204
|
+
}
|
205
|
+
: fixedOptions.particles.opacity.value,
|
206
|
+
animation: {
|
207
|
+
enable: fixedOptions.particles.opacity.anim.enable,
|
208
|
+
speed: fixedOptions.particles.opacity.anim.speed,
|
209
|
+
sync: fixedOptions.particles.opacity.anim.sync,
|
210
|
+
},
|
211
|
+
},
|
212
|
+
size: {
|
213
|
+
value: fixedOptions.particles.size.random
|
214
|
+
? {
|
215
|
+
min: fixedOptions.particles.size.anim.enable
|
216
|
+
? fixedOptions.particles.size.anim.size_min
|
217
|
+
: 0,
|
218
|
+
max: fixedOptions.particles.size.value,
|
219
|
+
}
|
220
|
+
: fixedOptions.particles.size.value,
|
221
|
+
animation: {
|
222
|
+
enable: fixedOptions.particles.size.anim.enable,
|
223
|
+
speed: fixedOptions.particles.size.anim.speed,
|
224
|
+
sync: fixedOptions.particles.size.anim.sync,
|
225
|
+
},
|
226
|
+
},
|
227
|
+
links: {
|
228
|
+
enable: fixedOptions.particles.line_linked.enable,
|
229
|
+
distance: fixedOptions.particles.line_linked.distance,
|
230
|
+
color: fixedOptions.particles.line_linked.color,
|
231
|
+
opacity: fixedOptions.particles.line_linked.opacity,
|
232
|
+
width: fixedOptions.particles.line_linked.width,
|
233
|
+
},
|
234
|
+
move: {
|
235
|
+
enable: fixedOptions.particles.move.enable,
|
236
|
+
speed: fixedOptions.particles.move.speed / 3,
|
237
|
+
direction: fixedOptions.particles.move.direction,
|
238
|
+
random: fixedOptions.particles.move.random,
|
239
|
+
straight: fixedOptions.particles.move.straight,
|
240
|
+
outModes: fixedOptions.particles.move.out_mode,
|
241
|
+
attract: {
|
242
|
+
enable: fixedOptions.particles.move.attract.enable,
|
243
|
+
rotate: {
|
244
|
+
x: fixedOptions.particles.move.attract.rotateX,
|
245
|
+
y: fixedOptions.particles.move.attract.rotateY,
|
246
|
+
},
|
247
|
+
},
|
248
|
+
},
|
249
|
+
},
|
250
|
+
},
|
251
|
+
});
|
252
|
+
};
|
253
|
+
particlesJS.load = (tagId, pathConfigJson, callback) => {
|
254
|
+
engine
|
255
|
+
.load({ id: tagId, url: pathConfigJson })
|
256
|
+
.then((container) => {
|
257
|
+
if (container) {
|
258
|
+
callback(container);
|
259
|
+
}
|
260
|
+
})
|
261
|
+
.catch(() => {
|
262
|
+
callback(undefined);
|
263
|
+
});
|
264
|
+
};
|
265
|
+
particlesJS.setOnClickHandler = (callback) => {
|
266
|
+
engine.setOnClickHandler(callback);
|
267
|
+
};
|
268
|
+
const pJSDom = engine.dom();
|
269
|
+
return { particlesJS, pJSDom };
|
270
|
+
};
|
271
|
+
export { initParticlesJS };
|
package/browser/bundle.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { initPjs } from ".";
|
2
2
|
import { tsParticles } from "@tsparticles/engine";
|
3
|
-
const { particlesJS, pJSDom } = initPjs(tsParticles);
|
3
|
+
const { particlesJS, pJSDom, Particles } = initPjs(tsParticles);
|
4
4
|
export * from "@tsparticles/engine";
|
5
|
-
export { particlesJS, pJSDom };
|
5
|
+
export { particlesJS, pJSDom, Particles };
|
package/browser/index.js
CHANGED
@@ -1,23 +1,10 @@
|
|
1
|
+
import { Particles } from "./marcbruederlin/Particles.js";
|
2
|
+
import { initParticlesJS } from "./VincentGarreau/particles.js";
|
1
3
|
const initPjs = (engine) => {
|
2
|
-
const particlesJS = (
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
.load({ id: tagId, url: pathConfigJson })
|
8
|
-
.then((container) => {
|
9
|
-
if (container) {
|
10
|
-
callback(container);
|
11
|
-
}
|
12
|
-
})
|
13
|
-
.catch(() => {
|
14
|
-
callback(undefined);
|
15
|
-
});
|
16
|
-
};
|
17
|
-
particlesJS.setOnClickHandler = (callback) => {
|
18
|
-
engine.setOnClickHandler(callback);
|
19
|
-
};
|
20
|
-
const pJSDom = engine.dom();
|
21
|
-
return { particlesJS, pJSDom };
|
4
|
+
const { particlesJS, pJSDom } = initParticlesJS(engine);
|
5
|
+
window.particlesJS = particlesJS;
|
6
|
+
window.pJSDom = pJSDom;
|
7
|
+
window.Particles = Particles;
|
8
|
+
return { particlesJS, pJSDom, Particles };
|
22
9
|
};
|
23
10
|
export { initPjs };
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { tsParticles } from "@tsparticles/engine";
|
2
|
+
export class Particles {
|
3
|
+
static init(options) {
|
4
|
+
const particles = new Particles(), selector = options.selector;
|
5
|
+
if (!selector) {
|
6
|
+
throw new Error("No selector provided");
|
7
|
+
}
|
8
|
+
const el = document.querySelector(selector);
|
9
|
+
if (!el) {
|
10
|
+
throw new Error("No element found for selector");
|
11
|
+
}
|
12
|
+
tsParticles
|
13
|
+
.load({
|
14
|
+
id: selector.replace(".", "").replace("!", ""),
|
15
|
+
element: el,
|
16
|
+
options: {
|
17
|
+
fullScreen: {
|
18
|
+
enable: false,
|
19
|
+
},
|
20
|
+
particles: {
|
21
|
+
color: {
|
22
|
+
value: options.color ?? "!000000",
|
23
|
+
},
|
24
|
+
links: {
|
25
|
+
color: "random",
|
26
|
+
distance: options.minDistance ?? 120,
|
27
|
+
enable: options.connectParticles ?? false,
|
28
|
+
},
|
29
|
+
move: {
|
30
|
+
enable: true,
|
31
|
+
speed: options.speed ?? 0.5,
|
32
|
+
},
|
33
|
+
number: {
|
34
|
+
value: options.maxParticles ?? 100,
|
35
|
+
},
|
36
|
+
size: {
|
37
|
+
value: { min: 1, max: options.sizeVariations ?? 3 },
|
38
|
+
},
|
39
|
+
},
|
40
|
+
responsive: options.responsive?.map((responsive) => ({
|
41
|
+
maxWidth: responsive.breakpoint,
|
42
|
+
options: {
|
43
|
+
particles: {
|
44
|
+
color: {
|
45
|
+
value: responsive.options?.color,
|
46
|
+
},
|
47
|
+
links: {
|
48
|
+
distance: responsive.options?.minDistance,
|
49
|
+
enable: responsive.options?.connectParticles,
|
50
|
+
},
|
51
|
+
number: {
|
52
|
+
value: options.maxParticles,
|
53
|
+
},
|
54
|
+
move: {
|
55
|
+
enable: true,
|
56
|
+
speed: responsive.options?.speed,
|
57
|
+
},
|
58
|
+
size: {
|
59
|
+
value: responsive.options?.sizeVariations,
|
60
|
+
},
|
61
|
+
},
|
62
|
+
},
|
63
|
+
})),
|
64
|
+
},
|
65
|
+
})
|
66
|
+
.then((container) => {
|
67
|
+
particles._container = container;
|
68
|
+
});
|
69
|
+
return particles;
|
70
|
+
}
|
71
|
+
destroy() {
|
72
|
+
const container = this._container;
|
73
|
+
container && container.destroy();
|
74
|
+
}
|
75
|
+
pauseAnimation() {
|
76
|
+
const container = this._container;
|
77
|
+
container && container.pause();
|
78
|
+
}
|
79
|
+
resumeAnimation() {
|
80
|
+
const container = this._container;
|
81
|
+
container && container.play();
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{ "type": "module" }
|