@tsparticles/react 3.0.0 → 4.0.0-beta.16
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 +214 -267
- package/dist/IParticlesProps.js +0 -1
- package/dist/Particles.js +32 -17
- package/dist/ParticlesProvider.js +35 -0
- package/dist/index.js +6 -12
- package/dist/lib/IParticlesProps.d.ts +10 -0
- package/dist/lib/Particles.d.ts +4 -0
- package/dist/lib/ParticlesProvider.d.ts +12 -0
- package/dist/lib/index.d.ts +5 -0
- package/package.json +37 -23
- package/dist/IParticlesProps.d.ts +0 -10
- package/dist/Particles.d.ts +0 -4
- package/dist/index.d.ts +0 -6
package/README.md
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
Official [tsParticles](https://github.com/tsparticles/tsparticles) ReactJS component
|
|
8
8
|
|
|
9
|
+
If you are using Next.js, prefer [@tsparticles/nextjs](https://www.npmjs.com/package/@tsparticles/nextjs) for a Next-first integration layer.
|
|
10
|
+
|
|
9
11
|
[](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI) [](https://discord.gg/hACwv45Hme) [](https://t.me/tsparticles)
|
|
10
12
|
|
|
11
13
|
[](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>
|
|
@@ -36,14 +38,14 @@ yarn add @tsparticles/react @tsparticles/engine
|
|
|
36
38
|
|
|
37
39
|
[@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
40
|
|
|
39
|
-
###
|
|
41
|
+
### React templates
|
|
40
42
|
|
|
41
|
-
Starting from version 1.17.0 there are two official
|
|
43
|
+
Starting from version 1.17.0 there are two official React templates:
|
|
42
44
|
|
|
43
45
|
- `cra-template-particles`: Simple ReactJS template with full screen particles, using JavaScript
|
|
44
46
|
- `cra-template-particles-typescript`: Simple ReactJS template with full screen particles, using TypeScript
|
|
45
47
|
|
|
46
|
-
You can
|
|
48
|
+
You can install them using `create-react-app` like this:
|
|
47
49
|
|
|
48
50
|
```shell
|
|
49
51
|
$ create-react-app your_app --template particles
|
|
@@ -59,6 +61,9 @@ $ create-react-app your_app --template particles-typescript
|
|
|
59
61
|
|
|
60
62
|
### Code
|
|
61
63
|
|
|
64
|
+
`ParticlesProvider` is required and receives one async `init` callback.
|
|
65
|
+
That callback is executed only once for the app lifecycle.
|
|
66
|
+
|
|
62
67
|
Examples:
|
|
63
68
|
|
|
64
69
|
#### Options object
|
|
@@ -66,225 +71,197 @@ Examples:
|
|
|
66
71
|
##### JavaScript support - object
|
|
67
72
|
|
|
68
73
|
```jsx
|
|
69
|
-
import {
|
|
70
|
-
import Particles, {
|
|
71
|
-
// import { loadAll } from "
|
|
74
|
+
import { useMemo } from "react";
|
|
75
|
+
import Particles, { ParticlesProvider } from "@tsparticles/react";
|
|
76
|
+
// import { loadAll } from "@tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
|
|
72
77
|
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
|
|
73
78
|
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
|
|
74
79
|
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
|
|
75
80
|
|
|
81
|
+
const particlesInit = async engine => {
|
|
82
|
+
await loadSlim(engine);
|
|
83
|
+
};
|
|
84
|
+
|
|
76
85
|
const App = () => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
;
|
|
86
|
+
const particlesLoaded = container => {
|
|
87
|
+
console.log(container);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const options = useMemo(
|
|
91
|
+
() => ({
|
|
92
|
+
background: {
|
|
93
|
+
color: {
|
|
94
|
+
value: "#0d47a1",
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
fpsLimit: 120,
|
|
98
|
+
interactivity: {
|
|
99
|
+
events: {
|
|
100
|
+
onClick: {
|
|
101
|
+
enable: true,
|
|
102
|
+
mode: "push",
|
|
103
|
+
},
|
|
104
|
+
onHover: {
|
|
105
|
+
enable: true,
|
|
106
|
+
mode: "repulse",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
modes: {
|
|
110
|
+
push: {
|
|
111
|
+
quantity: 4,
|
|
112
|
+
},
|
|
113
|
+
repulse: {
|
|
114
|
+
distance: 200,
|
|
115
|
+
duration: 0.4,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
particles: {
|
|
120
|
+
color: {
|
|
121
|
+
value: "#ffffff",
|
|
122
|
+
},
|
|
123
|
+
links: {
|
|
124
|
+
color: "#ffffff",
|
|
125
|
+
distance: 150,
|
|
126
|
+
enable: true,
|
|
127
|
+
opacity: 0.5,
|
|
128
|
+
width: 1,
|
|
129
|
+
},
|
|
130
|
+
move: {
|
|
131
|
+
direction: "none",
|
|
132
|
+
enable: true,
|
|
133
|
+
outModes: {
|
|
134
|
+
default: "bounce",
|
|
135
|
+
},
|
|
136
|
+
random: false,
|
|
137
|
+
speed: 6,
|
|
138
|
+
straight: false,
|
|
139
|
+
},
|
|
140
|
+
number: {
|
|
141
|
+
density: {
|
|
142
|
+
enable: true,
|
|
143
|
+
},
|
|
144
|
+
value: 80,
|
|
145
|
+
},
|
|
146
|
+
opacity: {
|
|
147
|
+
value: 0.5,
|
|
148
|
+
},
|
|
149
|
+
shape: {
|
|
150
|
+
type: "circle",
|
|
151
|
+
},
|
|
152
|
+
size: {
|
|
153
|
+
value: { min: 1, max: 5 },
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
detectRetina: true,
|
|
157
|
+
}),
|
|
158
|
+
[],
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return (
|
|
162
|
+
<ParticlesProvider init={particlesInit}>
|
|
163
|
+
<Particles id="tsparticles" particlesLoaded={particlesLoaded} options={options} />
|
|
164
|
+
</ParticlesProvider>
|
|
165
|
+
);
|
|
175
166
|
};
|
|
176
167
|
```
|
|
177
168
|
|
|
178
169
|
##### TypeScript support - object
|
|
179
170
|
|
|
180
171
|
```tsx
|
|
181
|
-
import {
|
|
182
|
-
import Particles, {
|
|
183
|
-
import type
|
|
184
|
-
// import { loadAll } from "
|
|
172
|
+
import { useMemo } from "react";
|
|
173
|
+
import Particles, { ParticlesProvider } from "@tsparticles/react";
|
|
174
|
+
import { type Container, type Engine, type ISourceOptions, MoveDirection, OutMode } from "@tsparticles/engine";
|
|
175
|
+
// import { loadAll } from "@tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
|
|
185
176
|
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
|
|
186
177
|
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
|
|
187
178
|
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
|
|
188
179
|
|
|
180
|
+
const particlesInit = async (engine: Engine): Promise<void> => {
|
|
181
|
+
await loadSlim(engine);
|
|
182
|
+
};
|
|
183
|
+
|
|
189
184
|
const App = () => {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
;
|
|
185
|
+
const particlesLoaded = async (container?: Container): Promise<void> => {
|
|
186
|
+
console.log(container);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const options: ISourceOptions = useMemo(
|
|
190
|
+
() => ({
|
|
191
|
+
background: {
|
|
192
|
+
color: {
|
|
193
|
+
value: "#0d47a1",
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
fpsLimit: 120,
|
|
197
|
+
interactivity: {
|
|
198
|
+
events: {
|
|
199
|
+
onClick: {
|
|
200
|
+
enable: true,
|
|
201
|
+
mode: "push",
|
|
202
|
+
},
|
|
203
|
+
onHover: {
|
|
204
|
+
enable: true,
|
|
205
|
+
mode: "repulse",
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
modes: {
|
|
209
|
+
push: {
|
|
210
|
+
quantity: 4,
|
|
211
|
+
},
|
|
212
|
+
repulse: {
|
|
213
|
+
distance: 200,
|
|
214
|
+
duration: 0.4,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
particles: {
|
|
219
|
+
color: {
|
|
220
|
+
value: "#ffffff",
|
|
221
|
+
},
|
|
222
|
+
links: {
|
|
223
|
+
color: "#ffffff",
|
|
224
|
+
distance: 150,
|
|
225
|
+
enable: true,
|
|
226
|
+
opacity: 0.5,
|
|
227
|
+
width: 1,
|
|
228
|
+
},
|
|
229
|
+
move: {
|
|
230
|
+
direction: MoveDirection.none,
|
|
231
|
+
enable: true,
|
|
232
|
+
outModes: {
|
|
233
|
+
default: OutMode.out,
|
|
234
|
+
},
|
|
235
|
+
random: false,
|
|
236
|
+
speed: 6,
|
|
237
|
+
straight: false,
|
|
238
|
+
},
|
|
239
|
+
number: {
|
|
240
|
+
density: {
|
|
241
|
+
enable: true,
|
|
242
|
+
},
|
|
243
|
+
value: 80,
|
|
244
|
+
},
|
|
245
|
+
opacity: {
|
|
246
|
+
value: 0.5,
|
|
247
|
+
},
|
|
248
|
+
shape: {
|
|
249
|
+
type: "circle",
|
|
250
|
+
},
|
|
251
|
+
size: {
|
|
252
|
+
value: { min: 1, max: 5 },
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
detectRetina: true,
|
|
256
|
+
}),
|
|
257
|
+
[],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<ParticlesProvider init={particlesInit}>
|
|
262
|
+
<Particles id="tsparticles" particlesLoaded={particlesLoaded} options={options} />
|
|
263
|
+
</ParticlesProvider>
|
|
264
|
+
);
|
|
288
265
|
};
|
|
289
266
|
```
|
|
290
267
|
|
|
@@ -293,91 +270,61 @@ const App = () => {
|
|
|
293
270
|
##### JavaScript support - url
|
|
294
271
|
|
|
295
272
|
```jsx
|
|
296
|
-
import
|
|
297
|
-
import
|
|
298
|
-
// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
|
|
273
|
+
import Particles, { ParticlesProvider } from "@tsparticles/react";
|
|
274
|
+
// import { loadAll } from "@tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
|
|
299
275
|
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
|
|
300
276
|
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
|
|
301
277
|
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
|
|
302
278
|
|
|
279
|
+
const particlesInit = async engine => {
|
|
280
|
+
await loadSlim(engine);
|
|
281
|
+
};
|
|
282
|
+
|
|
303
283
|
const App = () => {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
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
|
-
;
|
|
284
|
+
const particlesLoaded = container => {
|
|
285
|
+
console.log(container);
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
return (
|
|
289
|
+
<ParticlesProvider init={particlesInit}>
|
|
290
|
+
<Particles id="tsparticles" url="http://foo.bar/particles.json" particlesLoaded={particlesLoaded} />
|
|
291
|
+
</ParticlesProvider>
|
|
292
|
+
);
|
|
330
293
|
};
|
|
331
294
|
```
|
|
332
295
|
|
|
333
296
|
##### TypeScript support - url
|
|
334
297
|
|
|
335
298
|
```tsx
|
|
336
|
-
import
|
|
337
|
-
import Particles, { initParticlesEngine } from "@tsparticles/react";
|
|
299
|
+
import Particles, { ParticlesProvider } from "@tsparticles/react";
|
|
338
300
|
import type { Container, Engine } from "@tsparticles/engine";
|
|
339
|
-
// import { loadAll } from "
|
|
301
|
+
// import { loadAll } from "@tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
|
|
340
302
|
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
|
|
341
303
|
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
|
|
342
304
|
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
|
|
343
305
|
|
|
306
|
+
const particlesInit = async (engine: Engine): Promise<void> => {
|
|
307
|
+
await loadSlim(engine);
|
|
308
|
+
};
|
|
309
|
+
|
|
344
310
|
const App = () => {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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
|
-
;
|
|
311
|
+
const particlesLoaded = (container?: Container) => {
|
|
312
|
+
console.log(container);
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
return (
|
|
316
|
+
<ParticlesProvider init={particlesInit}>
|
|
317
|
+
<Particles id="tsparticles" url="http://foo.bar/particles.json" particlesLoaded={particlesLoaded} />
|
|
318
|
+
</ParticlesProvider>
|
|
319
|
+
);
|
|
371
320
|
};
|
|
372
321
|
```
|
|
373
322
|
|
|
374
323
|
### Props
|
|
375
324
|
|
|
376
325
|
| Prop | Type | Definition |
|
|
377
|
-
|
|
326
|
+
| --------- | ------ | ---------------------------------------------------- |
|
|
378
327
|
| id | string | The id of the element. |
|
|
379
|
-
| width | string | The width of the canvas. |
|
|
380
|
-
| height | string | The height of the canvas. |
|
|
381
328
|
| options | object | The options of the particles instance. |
|
|
382
329
|
| url | string | The remote options url, called using an AJAX request |
|
|
383
330
|
| style | object | The style of the canvas element. |
|
package/dist/IParticlesProps.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/Particles.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useEffect as
|
|
3
|
-
import { tsParticles as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { useParticlesProvider as e } from "./ParticlesProvider.js";
|
|
2
|
+
import { useEffect as t } from "react";
|
|
3
|
+
import { tsParticles as n } from "@tsparticles/engine";
|
|
4
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
5
|
+
//#region lib/Particles.tsx
|
|
6
|
+
var i = (i) => {
|
|
7
|
+
let { className: a, id: o, options: s, particlesLoaded: c, style: l, url: u } = i, { loaded: d } = e();
|
|
8
|
+
return t(() => {
|
|
9
|
+
if (!d) return;
|
|
10
|
+
let e;
|
|
11
|
+
return n.load({
|
|
12
|
+
id: o ?? "tsparticles",
|
|
13
|
+
url: u,
|
|
14
|
+
options: s
|
|
15
|
+
}).then((t) => {
|
|
16
|
+
e = t, c?.(t);
|
|
17
|
+
}), () => {
|
|
18
|
+
e?.destroy();
|
|
19
|
+
};
|
|
20
|
+
}, [
|
|
21
|
+
o,
|
|
22
|
+
d,
|
|
23
|
+
s,
|
|
24
|
+
c,
|
|
25
|
+
u
|
|
26
|
+
]), /* @__PURE__ */ r("div", {
|
|
27
|
+
id: o ?? "tsparticles",
|
|
28
|
+
className: a,
|
|
29
|
+
style: l
|
|
30
|
+
});
|
|
18
31
|
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { i as default };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createContext as e, useContext as t, useEffect as n, useMemo as r, useState as i } from "react";
|
|
2
|
+
import { tsParticles as a } from "@tsparticles/engine";
|
|
3
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
4
|
+
//#region lib/ParticlesProvider.tsx
|
|
5
|
+
var s = !1, c, l, u = e({ loaded: !1 }), d = ({ children: e, init: t }) => {
|
|
6
|
+
let [d, f] = i(s);
|
|
7
|
+
n(() => {
|
|
8
|
+
let e = !1;
|
|
9
|
+
if (!s) {
|
|
10
|
+
if (!c) l = t, c = (async () => {
|
|
11
|
+
await t(a), s = !0;
|
|
12
|
+
})().catch((e) => {
|
|
13
|
+
throw c = void 0, l = void 0, e;
|
|
14
|
+
});
|
|
15
|
+
else if (l && l !== t) throw Error("ParticlesProvider init callback must be stable across the app lifecycle.");
|
|
16
|
+
return c.then(() => {
|
|
17
|
+
e || f(!0);
|
|
18
|
+
}).catch(() => {
|
|
19
|
+
e || f(!1);
|
|
20
|
+
}), () => {
|
|
21
|
+
e = !0;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}, [t]);
|
|
25
|
+
let p = r(() => ({ loaded: d }), [d]);
|
|
26
|
+
return /* @__PURE__ */ o(u.Provider, {
|
|
27
|
+
value: p,
|
|
28
|
+
children: d ? e : null
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
function f() {
|
|
32
|
+
return t(u);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { d as ParticlesProvider, f as useParticlesProvider };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export {
|
|
9
|
-
o as Particles,
|
|
10
|
-
o as default,
|
|
11
|
-
n as initParticlesEngine
|
|
12
|
-
};
|
|
1
|
+
import { ParticlesProvider as e, useParticlesProvider as t } from "./ParticlesProvider.js";
|
|
2
|
+
import n from "./Particles.js";
|
|
3
|
+
//#region lib/index.ts
|
|
4
|
+
var r = n;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { n as Particles, e as ParticlesProvider, r as default, t as useParticlesProvider };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Container, ISourceOptions } from '@tsparticles/engine';
|
|
2
|
+
import { 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> | void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Engine } from '@tsparticles/engine';
|
|
2
|
+
import { FC, PropsWithChildren } from 'react';
|
|
3
|
+
export type ParticlesPluginRegistrar = (engine: Engine) => Promise<void>;
|
|
4
|
+
export interface IParticlesProviderProps extends PropsWithChildren {
|
|
5
|
+
init: ParticlesPluginRegistrar;
|
|
6
|
+
}
|
|
7
|
+
interface IParticlesProviderContext {
|
|
8
|
+
loaded: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const ParticlesProvider: FC<IParticlesProviderProps>;
|
|
11
|
+
export declare function useParticlesProvider(): IParticlesProviderContext;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { default as Particles } from './Particles.js';
|
|
2
|
+
export type { IParticlesProps } from './IParticlesProps.js';
|
|
3
|
+
export default Particles;
|
|
4
|
+
export { Particles };
|
|
5
|
+
export { type IParticlesProviderProps, type ParticlesPluginRegistrar, ParticlesProvider, useParticlesProvider, } from './ParticlesProvider.js';
|
package/package.json
CHANGED
|
@@ -1,45 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.16",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/tsparticles/tsparticles.git",
|
|
8
|
+
"directory": "wrappers/react"
|
|
9
|
+
},
|
|
5
10
|
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
11
|
+
"types": "dist/lib/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/lib/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
7
18
|
"scripts": {
|
|
8
19
|
"dev": "vite",
|
|
9
|
-
"build": "tsc && vite build",
|
|
10
|
-
"build:ci": "tsc && vite build",
|
|
11
|
-
"lint": "eslint . --
|
|
20
|
+
"build": "prettier --write README.md && pnpm run prettify && tsc && vite build",
|
|
21
|
+
"build:ci": "prettier --check README.md && pnpm run prettify:ci && tsc && vite build",
|
|
22
|
+
"lint": "eslint . --max-warnings 0",
|
|
12
23
|
"preview": "vite preview",
|
|
24
|
+
"prettify": "prettier --write \"src/**/*.{ts,tsx}\" && prettier --write \"lib/**/*.{ts,tsx}\"",
|
|
25
|
+
"prettify:ci": "prettier --check \"src/**/*.{ts,tsx}\" && prettier --check \"lib/**/*.{ts,tsx}\"",
|
|
13
26
|
"prepublishOnly": "pnpm run build"
|
|
14
27
|
},
|
|
15
28
|
"files": [
|
|
16
29
|
"dist"
|
|
17
30
|
],
|
|
31
|
+
"license": "MIT",
|
|
18
32
|
"peerDependencies": {
|
|
19
|
-
"@tsparticles/engine": "
|
|
33
|
+
"@tsparticles/engine": "workspace:^",
|
|
20
34
|
"react": ">=16.8.0",
|
|
21
35
|
"react-dom": ">=16.8.0"
|
|
22
36
|
},
|
|
23
37
|
"devDependencies": {
|
|
24
|
-
"@tsparticles/engine": "
|
|
25
|
-
"@types/react": "^
|
|
26
|
-
"@types/react-dom": "^
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
28
|
-
"@typescript-eslint/parser": "^
|
|
29
|
-
"@vitejs/plugin-react": "^
|
|
30
|
-
"eslint": "^
|
|
31
|
-
"eslint-plugin-react-hooks": "^
|
|
32
|
-
"eslint-plugin-react-refresh": "^0.
|
|
33
|
-
"glob": "^
|
|
34
|
-
"react": "^
|
|
35
|
-
"react-dom": "^
|
|
36
|
-
"typescript": "^
|
|
37
|
-
"vite": "^
|
|
38
|
-
"vite-plugin-dts": "^
|
|
39
|
-
"vite-plugin-lib-inject-css": "^
|
|
38
|
+
"@tsparticles/engine": "4.0.0-beta.16",
|
|
39
|
+
"@types/react": "^19.2.14",
|
|
40
|
+
"@types/react-dom": "^19.2.3",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^8.58.1",
|
|
42
|
+
"@typescript-eslint/parser": "^8.58.1",
|
|
43
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
44
|
+
"eslint": "^10.2.0",
|
|
45
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
46
|
+
"eslint-plugin-react-refresh": "^0.5.2",
|
|
47
|
+
"glob": "^13.0.6",
|
|
48
|
+
"react": "^19.2.5",
|
|
49
|
+
"react-dom": "^19.2.5",
|
|
50
|
+
"typescript": "^6.0.2",
|
|
51
|
+
"vite": "^8.0.8",
|
|
52
|
+
"vite-plugin-dts": "^4.5.4",
|
|
53
|
+
"vite-plugin-lib-inject-css": "^2.2.2"
|
|
40
54
|
},
|
|
41
55
|
"publishConfig": {
|
|
42
56
|
"access": "public"
|
|
43
57
|
},
|
|
44
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "8ac678c4da53ea2b6a9a33aaa40f5141e2a7d513"
|
|
45
59
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/Particles.d.ts
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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 };
|