);
}
================================================
FILE: apps/nextjs-beta/app/particles.tsx
================================================
"use client";
import Particles from "@tsparticles/react";
import configs from "@tsparticles/configs";
export default function ParticlesComponent(props: {
id: string;
done: boolean;
}) {
return props.done && ;
}
================================================
FILE: apps/nextjs-beta/next.config.js
================================================
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
}
module.exports = nextConfig
================================================
FILE: apps/nextjs-beta/package.json
================================================
{
"name": "nextjs-beta-demo",
"version": "3.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"build:ci": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@next/font": "^14.0.3",
"@tsparticles/configs": "^3.0.2",
"@tsparticles/engine": "^3.0.2",
"@tsparticles/react": "workspace:^",
"@types/node": "^20.10.4",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"eslint": "^8.55.0",
"eslint-config-next": "^14.0.3",
"next": "^14.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tsparticles": "^3.0.2",
"typescript": "^5.3.3"
}
}
================================================
FILE: apps/nextjs-beta/pages/api/hello.ts
================================================
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from 'next'
type Data = {
name: string
}
export default function handler(
req: NextApiRequest,
res: NextApiResponse
) {
res.status(200).json({ name: 'John Doe' })
}
================================================
FILE: apps/nextjs-beta/tsconfig.json
================================================
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
]
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
================================================
FILE: apps/react/.gitignore
================================================
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
================================================
FILE: apps/react/CHANGELOG.md
================================================
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [3.0.0](https://github.com/tsparticles/react/compare/v2.12.2...v3.0.0) (2023-12-07)
### Bug Fixes
* **deps:** update dependency @testing-library/jest-dom to v6 ([ba7f6c0](https://github.com/tsparticles/react/commit/ba7f6c08f5373eaf83838ba579c4a755353ac6b4))
* fixed component, it was refreshing infinite times for a bug. now it works perfectly ([4ef5e81](https://github.com/tsparticles/react/commit/4ef5e8197f1364e3a62c8262ae04c9272457047a))
### Features
* added particles setup function (name not definitive), updated to v3 ([e164c66](https://github.com/tsparticles/react/commit/e164c669b515d30057059ef8f7a8d35ff562b5e3))
## [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.12.1...v3.0.0-beta.1) (2023-08-11)
**Note:** Version bump only for package react-demo
## [2.12.1](https://github.com/tsparticles/react/compare/v3.0.0-beta.1...v2.12.1) (2023-08-04)
**Note:** Version bump only for package react-demo
# [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.11.0...v3.0.0-beta.1) (2023-08-04)
### Bug Fixes
* **deps:** update dependency @testing-library/react to v14 ([107b5c9](https://github.com/tsparticles/react/commit/107b5c9c76478bb6eb0ae9d1873f62beefc423a9))
* **deps:** update dependency @testing-library/user-event to v14 ([62043e2](https://github.com/tsparticles/react/commit/62043e22da2caefcbccc1dfa563aa01a2f6769b4))
* **deps:** update dependency web-vitals to v3 ([d3b48dc](https://github.com/tsparticles/react/commit/d3b48dcf6927778903314696c3b6b351d4eaed4f))
================================================
FILE: apps/react/README.md
================================================
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
================================================
FILE: apps/react/package.json
================================================
{
"name": "react-demo",
"version": "3.0.0",
"private": true,
"dependencies": {
"@tsparticles/engine": "^3.0.2",
"@tsparticles/react": "workspace:^",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"tsparticles": "^3.0.2",
"web-vitals": "^3.5.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build:ci": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
================================================
FILE: apps/react/public/index.html
================================================
React App
================================================
FILE: apps/react/public/manifest.json
================================================
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
================================================
FILE: apps/react/public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
================================================
FILE: apps/react/src/App.css
================================================
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: red;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.theme-btn {
}
================================================
FILE: apps/react/src/App.js
================================================
import Particles, { initParticlesEngine } from "@tsparticles/react";
import { loadFull } from "tsparticles";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import logo from "./logo.svg";
import "./App.css";
function App() {
const containerRef = useRef(null), [ init, setInit ] = useState(false);
useEffect(() => {
if (init) {
return;
}
initParticlesEngine(async (engine) => {
await loadFull(engine);
}).then(() => {
setInit(true);
});
}, [ init ]);
const particlesLoaded = useCallback(
(container) => {
containerRef.current = container;
window.particlesContainer = container;
},
[ containerRef ]
),
options = useMemo(
() => ({
fullScreen: {
zIndex: -1,
},
particles: {
number: {
value: 100,
},
links: {
enable: true,
},
move: {
enable: true,
},
},
themes: [
{
name: "light",
default: {
value: true,
auto: true,
mode: "light",
},
options: {
background: {
color: "#ffffff",
},
particles: {
color: {
value: "#000000",
},
links: {
color: "#000000",
},
},
},
},
{
name: "dark",
default: {
value: true,
auto: true,
mode: "dark",
},
options: {
background: {
color: "#000000",
},
particles: {
color: {
value: "#ffffff",
},
links: {
color: "#ffffff",
},
},
},
},
],
}),
[]
),
lightTheme = () => {
containerRef.current?.loadTheme("light");
},
darkTheme = () => {
containerRef.current?.loadTheme("dark");
};
return (
);
}
export default App;
================================================
FILE: apps/react/src/App.test.js
================================================
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render();
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
================================================
FILE: apps/react/src/index.css
================================================
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
================================================
FILE: apps/react/src/index.js
================================================
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
);
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
================================================
FILE: apps/react/src/reportWebVitals.js
================================================
const reportWebVitals = onPerfEntry => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
};
export default reportWebVitals;
================================================
FILE: apps/react/src/setupTests.js
================================================
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
================================================
FILE: components/react/.eslintrc.cjs
================================================
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
================================================
FILE: components/react/.gitignore
================================================
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
================================================
FILE: components/react/CHANGELOG.md
================================================
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [3.0.0](https://github.com/tsparticles/react/compare/v2.12.2...v3.0.0) (2023-12-07)
### Bug Fixes
* fixed component, it was refreshing infinite times for a bug. now it works perfectly ([4ef5e81](https://github.com/tsparticles/react/commit/4ef5e8197f1364e3a62c8262ae04c9272457047a))
### Features
* added particles setup function (name not definitive), updated to v3 ([e164c66](https://github.com/tsparticles/react/commit/e164c669b515d30057059ef8f7a8d35ff562b5e3))
* converted component to hooks API, closes [#49](https://github.com/tsparticles/react/issues/49) ([4a9eaa0](https://github.com/tsparticles/react/commit/4a9eaa018052e244ed217446e8b56cb8dfc582ed))
================================================
FILE: components/react/README.md
================================================
[](https://particles.js.org)
# @tsparticles/react
[](https://www.npmjs.com/package/@tsparticles/react) [](https://www.npmjs.com/package/@tsparticles/react) [](https://github.com/sponsors/matteobruni)
Official [tsParticles](https://github.com/tsparticles/tsparticles) ReactJS component
[](https://join.slack.com/t/tsparticles/shared_invite/enQtOTcxNTQxNjQ4NzkxLWE2MTZhZWExMWRmOWI5MTMxNjczOGE1Yjk0MjViYjdkYTUzODM3OTc5MGQ5MjFlODc4MzE0N2Q1OWQxZDc1YzI) [](https://discord.gg/hACwv45Hme) [](https://t.me/tsparticles)
[](https://www.producthunt.com/posts/tsparticles?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-tsparticles")
## Installation
```shell
npm install @tsparticles/react
```
or
```shell
yarn add @tsparticles/react
```
### TypeScript Installation
```shell
npm install @tsparticles/react @tsparticles/engine
```
or
```shell
yarn add @tsparticles/react @tsparticles/engine
```
[@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`.
### create-react-app
Starting from version 1.17.0 there are two official `create-react-app` templates:
- `cra-template-particles`: Simple ReactJS template with full screen particles, using JavaScript
- `cra-template-particles-typescript`: Simple ReactJS template with full screen particles, using TypeScript
You can simply install them using the `create-react-app` command like this:
```shell
$ create-react-app your_app --template particles
```
or
```shell
$ create-react-app your_app --template particles-typescript
```
## How to use
### Code
Examples:
#### Options object
##### JavaScript support - object
```jsx
import { useEffect, useMemo, useState } from "react";
import Particles, { initParticlesEngine } from "@tsparticles/react";
// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
const App = () => {
const [init, setInit] = useState(false);
// this should be run only once per application lifetime
useEffect(() => {
initParticlesEngine(async (engine) => {
// you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
// this loads the tsparticles package bundle, it's the easiest method for getting everything ready
// starting from v2 you can add only the features you need reducing the bundle size
//await loadAll(engine);
//await loadFull(engine);
await loadSlim(engine);
//await loadBasic(engine);
}).then(() => {
setInit(true);
});
}, []);
const particlesLoaded = (container) => {
console.log(container);
};
const options = useMemo(
() => ({
background: {
color: {
value: "#0d47a1",
},
},
fpsLimit: 120,
interactivity: {
events: {
onClick: {
enable: true,
mode: "push",
},
onHover: {
enable: true,
mode: "repulse",
},
},
modes: {
push: {
quantity: 4,
},
repulse: {
distance: 200,
duration: 0.4,
},
},
},
particles: {
color: {
value: "#ffffff",
},
links: {
color: "#ffffff",
distance: 150,
enable: true,
opacity: 0.5,
width: 1,
},
move: {
direction: "none",
enable: true,
outModes: {
default: "bounce",
},
random: false,
speed: 6,
straight: false,
},
number: {
density: {
enable: true,
},
value: 80,
},
opacity: {
value: 0.5,
},
shape: {
type: "circle",
},
size: {
value: { min: 1, max: 5 },
},
},
detectRetina: true,
}),
[],
);
if (init) {
return (
);
}
return <>>;
};
```
##### TypeScript support - object
```tsx
import { useEffect, useMemo, useState } from "react";
import Particles, { initParticlesEngine } from "@tsparticles/react";
import {
type Container,
type ISourceOptions,
MoveDirection,
OutMode,
} from "@tsparticles/engine";
// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
const App = () => {
const [init, setInit] = useState(false);
// this should be run only once per application lifetime
useEffect(() => {
initParticlesEngine(async (engine) => {
// you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
// this loads the tsparticles package bundle, it's the easiest method for getting everything ready
// starting from v2 you can add only the features you need reducing the bundle size
//await loadAll(engine);
//await loadFull(engine);
await loadSlim(engine);
//await loadBasic(engine);
}).then(() => {
setInit(true);
});
}, []);
const particlesLoaded = async (container?: Container): Promise => {
console.log(container);
};
const options: ISourceOptions = useMemo(
() => ({
background: {
color: {
value: "#0d47a1",
},
},
fpsLimit: 120,
interactivity: {
events: {
onClick: {
enable: true,
mode: "push",
},
onHover: {
enable: true,
mode: "repulse",
},
},
modes: {
push: {
quantity: 4,
},
repulse: {
distance: 200,
duration: 0.4,
},
},
},
particles: {
color: {
value: "#ffffff",
},
links: {
color: "#ffffff",
distance: 150,
enable: true,
opacity: 0.5,
width: 1,
},
move: {
direction: MoveDirection.none,
enable: true,
outModes: {
default: OutMode.out,
},
random: false,
speed: 6,
straight: false,
},
number: {
density: {
enable: true,
},
value: 80,
},
opacity: {
value: 0.5,
},
shape: {
type: "circle",
},
size: {
value: { min: 1, max: 5 },
},
},
detectRetina: true,
}),
[],
);
if (init) {
return (
);
}
return <>>;
};
```
#### Remote url
##### JavaScript support - url
```jsx
import { useEffect, useState } from "react";
import Particles, { initParticlesEngine } from "@tsparticles/react";
// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
const App = () => {
const [init, setInit] = useState(false);
// this should be run only once per application lifetime
useEffect(() => {
initParticlesEngine(async (engine) => {
// you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
// this loads the tsparticles package bundle, it's the easiest method for getting everything ready
// starting from v2 you can add only the features you need reducing the bundle size
//await loadAll(engine);
//await loadFull(engine);
await loadSlim(engine);
//await loadBasic(engine);
}).then(() => {
setInit(true);
});
}, []);
const particlesLoaded = (container) => {
console.log(container);
};
if (init) {
return (
);
}
return <>>;
};
```
##### TypeScript support - url
```tsx
import { useEffect, useState } from "react";
import Particles, { initParticlesEngine } from "@tsparticles/react";
import type { Container } from "@tsparticles/engine";
// import { loadAll } from "@/tsparticles/all"; // if you are going to use `loadAll`, install the "@tsparticles/all" package too.
// import { loadFull } from "tsparticles"; // if you are going to use `loadFull`, install the "tsparticles" package too.
import { loadSlim } from "@tsparticles/slim"; // if you are going to use `loadSlim`, install the "@tsparticles/slim" package too.
// import { loadBasic } from "@tsparticles/basic"; // if you are going to use `loadBasic`, install the "@tsparticles/basic" package too.
const App = () => {
const [init, setInit] = useState(false);
// this should be run only once per application lifetime
useEffect(() => {
initParticlesEngine(async (engine) => {
// you can initiate the tsParticles instance (engine) here, adding custom shapes or presets
// this loads the tsparticles package bundle, it's the easiest method for getting everything ready
// starting from v2 you can add only the features you need reducing the bundle size
//await loadAll(engine);
//await loadFull(engine);
await loadSlim(engine);
//await loadBasic(engine);
}).then(() => {
setInit(true);
});
}, []);
const particlesLoaded = (container?: Container) => {
console.log(container);
};
if (init) {
return (
);
}
return <>>;
};
```
### Props
| Prop | Type | Definition |
| --------- | ------ | ---------------------------------------------------- |
| id | string | The id of the element. |
| width | string | The width of the canvas. |
| height | string | The height of the canvas. |
| options | object | The options of the particles instance. |
| url | string | The remote options url, called using an AJAX request |
| style | object | The style of the canvas element. |
| className | string | The class name of the canvas wrapper. |
#### particles.json
Find all configuration
options [here](https://particles.js.org/docs/interfaces/tsParticles_Engine.Options_Interfaces_IOptions.IOptions.html).
You can find sample configurations [here](https://github.com/tsparticles/tsparticles/tree/main/utils/configs/src) 📖
## Demos
Preset demos can be found [here](https://particles.js.org/samples/presets/index.html)
There's also a CodePen collection actively maintained and updated [here](https://codepen.io/collection/DPOage)
Report bugs and issues [here](https://github.com/tsparticles/tsparticles/issues)
[tsParticle Website](https://particles.js.org)
================================================
FILE: components/react/index.html
================================================
Vite + React + TS
================================================
FILE: components/react/lib/IParticlesProps.ts
================================================
import type { Container, ISourceOptions } from "@tsparticles/engine";
import type { CSSProperties } from "react";
export interface IParticlesProps {
id?: string;
options?: ISourceOptions;
url?: string;
style?: CSSProperties;
className?: string;
particlesLoaded?: (container?: Container) => Promise;
}
================================================
FILE: components/react/lib/Particles.tsx
================================================
import { FC, useEffect } from "react";
import type { IParticlesProps } from "./IParticlesProps";
import { tsParticles, type Container } from "@tsparticles/engine";
const Particles: FC = (props) => {
const id = props.id ?? "tsparticles";
useEffect(() => {
let container: Container | undefined;
tsParticles
.load({ id, url: props.url, options: props.options })
.then((c) => {
container = c;
props.particlesLoaded?.(c);
});
return () => {
container?.destroy();
};
}, [id, props, props.url, props.options]);
return ;
};
export default Particles;
================================================
FILE: components/react/lib/index.ts
================================================
import { Engine, tsParticles } from "@tsparticles/engine";
import Particles from "./Particles";
export type { IParticlesProps } from "./IParticlesProps";
export async function initParticlesEngine(
cb: (engine: Engine) => Promise,
): Promise {
await cb(tsParticles);
}
export default Particles;
export { Particles };
================================================
FILE: components/react/package.json
================================================
{
"name": "@tsparticles/react",
"version": "3.0.0",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"dev": "vite",
"build": "prettier --write README.md && pnpm run prettify && tsc && vite build",
"build:ci": "prettier --check README.md && pnpm run prettify:ci && tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"prettify": "prettier --write \"src/**/*.{ts,tsx}\" && prettier --write \"lib/**/*.{ts,tsx}\"",
"prettify:ci": "prettier --check \"src/**/*.{ts,tsx}\" && prettier --check \"lib/**/*.{ts,tsx}\"",
"prepublishOnly": "pnpm run build"
},
"files": [
"dist"
],
"license": "MIT",
"peerDependencies": {
"@tsparticles/engine": "^3.0.2",
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
},
"devDependencies": {
"@tsparticles/engine": "^3.0.2",
"@types/react": "^18.2.45",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"glob": "^10.3.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4",
"vite-plugin-lib-inject-css": "^2.0.0"
},
"publishConfig": {
"access": "public"
}
}
================================================
FILE: components/react/src/App.css
================================================
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
================================================
FILE: components/react/src/App.tsx
================================================
import { useState } from "react";
import reactLogo from "./assets/react.svg";
import viteLogo from "/vite.svg";
import "./App.css";
function App() {
const [count, setCount] = useState(0);
return (
<>
Vite + React
Edit src/App.tsx and save to test HMR
Click on the Vite and React logos to learn more
>
);
}
export default App;
================================================
FILE: components/react/src/index.css
================================================
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
-webkit-text-size-adjust: 100%;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
================================================
FILE: components/react/src/main.tsx
================================================
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App.tsx";
import "./index.css";
ReactDOM.createRoot(document.getElementById("root")!).render(
,
);
================================================
FILE: components/react/src/vite-env.d.ts
================================================
///
================================================
FILE: components/react/tsconfig.json
================================================
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "lib"],
"references": [{ "path": "./tsconfig.node.json" }]
}
================================================
FILE: components/react/tsconfig.node.json
================================================
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
================================================
FILE: components/react/vite.config.ts
================================================
import { defineConfig } from "vite";
import { extname, relative, resolve } from "path";
import { fileURLToPath } from "node:url";
import { glob } from "glob";
import react from "@vitejs/plugin-react";
import dts from "vite-plugin-dts";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), dts({ include: ["lib"] })],
build: {
rollupOptions: {
external: ["react", "react/jsx-runtime", "@tsparticles/engine"],
input: Object.fromEntries(
glob.sync("lib/**/*.{ts,tsx}").map((file) => [
// The name of the entry point
// lib/nested/foo.ts becomes nested/foo
relative("lib", file.slice(0, file.length - extname(file).length)),
// The absolute path to the entry file
// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
fileURLToPath(new URL(file, import.meta.url)),
])
),
output: {
assetFileNames: "assets/[name][extname]",
entryFileNames: "[name].js",
},
},
lib: {
entry: resolve(__dirname, "lib/index.ts"),
formats: ["es"],
},
copyPublicDir: false,
},
});
================================================
FILE: lerna.json
================================================
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"packages": [
"apps/*",
"components/*",
"templates/*"
],
"version": "3.0.0",
"npmClient": "pnpm",
"conventionalCommits": true,
"command": {
"version": {
"message": "chore(release): published new version"
}
}
}
================================================
FILE: package.json
================================================
{
"name": "@tsparticles/react-workspace",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "prettier --write README.md && lerna run build",
"build:ci": "prettier --check README.md && lerna run build:ci"
},
"license": "MIT",
"dependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"husky": "^9.0.0",
"lerna": "^8.0.1",
"prettier": "^3.1.1",
"process": "^0.11.10",
"react-error-overlay": "^6.0.11"
},
"workspaces": [
"apps/*",
"components/*",
"templates/*"
]
}
================================================
FILE: pnpm-workspace.yaml
================================================
packages:
- 'apps/*'
- 'components/*'
- 'templates/*'
================================================
FILE: renovate.json
================================================
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
]
}
================================================
FILE: templates/react/CHANGELOG.md
================================================
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [3.0.0](https://github.com/tsparticles/react/compare/v2.12.2...v3.0.0) (2023-12-07)
### Bug Fixes
* fixed component, it was refreshing infinite times for a bug. now it works perfectly ([4ef5e81](https://github.com/tsparticles/react/commit/4ef5e8197f1364e3a62c8262ae04c9272457047a))
### Features
* added particles setup function (name not definitive), updated to v3 ([e164c66](https://github.com/tsparticles/react/commit/e164c669b515d30057059ef8f7a8d35ff562b5e3))
## [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.12.1...v3.0.0-beta.1) (2023-08-11)
**Note:** Version bump only for package cra-template-particles
## [2.12.1](https://github.com/tsparticles/react/compare/v3.0.0-beta.1...v2.12.1) (2023-08-04)
**Note:** Version bump only for package cra-template-particles
# [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.11.0...v3.0.0-beta.1) (2023-08-04)
**Note:** Version bump only for package cra-template-particles
# [2.11.0](https://github.com/tsparticles/react/compare/v2.10.1...v2.11.0) (2023-07-14)
**Note:** Version bump only for package cra-template-particles
## 2.10.1 (2023-06-04)
### Features
* updated templates to React 18 ([d9ae354](https://github.com/tsparticles/react/commit/d9ae354d71f245e85009c96007bd59df7bd422c8))
## [2.9.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.9.2...cra-template-particles@2.9.3) (2023-02-12)
**Note:** Version bump only for package cra-template-particles
## [2.9.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.9.1...cra-template-particles@2.9.2) (2023-02-12)
**Note:** Version bump only for package cra-template-particles
## [2.9.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.9.0...cra-template-particles@2.9.1) (2023-02-11)
**Note:** Version bump only for package cra-template-particles
# [2.9.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.8.0...cra-template-particles@2.9.0) (2023-02-10)
**Note:** Version bump only for package cra-template-particles
# [2.8.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.7.1...cra-template-particles@2.8.0) (2023-01-18)
**Note:** Version bump only for package cra-template-particles
## [2.7.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.7.0...cra-template-particles@2.7.1) (2022-12-25)
**Note:** Version bump only for package cra-template-particles
# [2.7.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.6.0...cra-template-particles@2.7.0) (2022-12-23)
### Features
- improved density values, now is 1:1 with number on 1080 resolution with pixel ratio of 1 ([3ff8fbf](https://github.com/tsparticles/tsparticles/commit/3ff8fbfefb01f1d6fe8be836c3c2909b74630475))
# [2.6.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.5.3...cra-template-particles@2.6.0) (2022-12-06)
### Bug Fixes
- **deps:** update dependency fs-extra to v11 ([e82352a](https://github.com/tsparticles/tsparticles/commit/e82352a685960603a58fb222f91d157ee65967de))
## [2.5.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.5.2...cra-template-particles@2.5.3) (2022-11-07)
**Note:** Version bump only for package cra-template-particles
## [2.5.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.5.1...cra-template-particles@2.5.2) (2022-11-07)
**Note:** Version bump only for package cra-template-particles
## [2.5.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.5.0...cra-template-particles@2.5.1) (2022-11-03)
**Note:** Version bump only for package cra-template-particles
# [2.5.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.4.0...cra-template-particles@2.5.0) (2022-11-02)
**Note:** Version bump only for package cra-template-particles
# [2.4.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.3.4...cra-template-particles@2.4.0) (2022-10-30)
### Features
- removed all canvas context save/restore calls ([208722f](https://github.com/tsparticles/tsparticles/commit/208722f0a521246165b7cdc529dfbfbd7a3cf7eb))
## [2.3.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.3.3...cra-template-particles@2.3.4) (2022-09-30)
**Note:** Version bump only for package cra-template-particles
## [2.3.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.3.2...cra-template-particles@2.3.3) (2022-09-30)
**Note:** Version bump only for package cra-template-particles
## [2.3.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.3.1...cra-template-particles@2.3.2) (2022-09-21)
**Note:** Version bump only for package cra-template-particles
## [2.3.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.3.0...cra-template-particles@2.3.1) (2022-09-13)
**Note:** Version bump only for package cra-template-particles
# [2.3.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.2.4...cra-template-particles@2.3.0) (2022-09-11)
**Note:** Version bump only for package cra-template-particles
## [2.2.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.2.2...cra-template-particles@2.2.4) (2022-08-26)
**Note:** Version bump only for package cra-template-particles
## [2.2.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.2.2...cra-template-particles@2.2.3) (2022-08-21)
**Note:** Version bump only for package cra-template-particles
## [2.2.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.2.1...cra-template-particles@2.2.2) (2022-08-16)
### Bug Fixes
- fixed double mouse events on mobile using pointer events, closes [#4622](https://github.com/tsparticles/tsparticles/issues/4622) ([1019fa4](https://github.com/tsparticles/tsparticles/commit/1019fa431f8a43cbd45d6adeb5adf94433e6e04b))
## [2.2.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.2.0...cra-template-particles@2.2.1) (2022-08-12)
**Note:** Version bump only for package cra-template-particles
# [2.2.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.1.4...cra-template-particles@2.2.0) (2022-08-11)
**Note:** Version bump only for package cra-template-particles
## [2.1.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.1.3...cra-template-particles@2.1.4) (2022-07-28)
### Features
- preparing @tsparticles/react and switching alternate packages ([49e749e](https://github.com/tsparticles/tsparticles/commit/49e749e90e076f0cb22eefe0f3399102f5b9fb35))
## [2.1.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.1.2...cra-template-particles@2.1.3) (2022-07-01)
**Note:** Version bump only for package cra-template-particles
## [2.1.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.1.1...cra-template-particles@2.1.2) (2022-07-01)
**Note:** Version bump only for package cra-template-particles
## [2.1.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.1.0...cra-template-particles@2.1.1) (2022-07-01)
**Note:** Version bump only for package cra-template-particles
# [2.1.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.6...cra-template-particles@2.1.0) (2022-06-18)
### Bug Fixes
- **deps:** update dependency @capacitor/core to v3.5.0 ([581bb7e](https://github.com/tsparticles/tsparticles/commit/581bb7e2f4f6aceb3535daf9223954a80f2daa81))
## [2.0.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.5...cra-template-particles@2.0.6) (2022-04-16)
**Note:** Version bump only for package cra-template-particles
## [2.0.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.4...cra-template-particles@2.0.5) (2022-04-14)
**Note:** Version bump only for package cra-template-particles
## [2.0.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.43.1...cra-template-particles@2.0.4) (2022-04-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [2.0.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.1...cra-template-particles@2.0.3) (2022-03-11)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [2.0.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.4...cra-template-particles@2.0.2) (2022-02-21)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [1.43.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.43.0...cra-template-particles@1.43.1) (2022-04-06)
**Note:** Version bump only for package cra-template-particles
# [1.43.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.4...cra-template-particles@1.43.0) (2022-04-04)
**Note:** Version bump only for package cra-template-particles
## [1.42.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.3...cra-template-particles@1.42.4) (2022-03-20)
**Note:** Version bump only for package cra-template-particles
## [1.42.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.2...cra-template-particles@1.42.3) (2022-03-18)
**Note:** Version bump only for package cra-template-particles
## [1.42.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.1...cra-template-particles@1.42.2) (2022-03-14)
**Note:** Version bump only for package cra-template-particles
## [1.42.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.42.0...cra-template-particles@1.42.1) (2022-03-09)
**Note:** Version bump only for package cra-template-particles
# [1.42.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.6...cra-template-particles@1.42.0) (2022-03-08)
**Note:** Version bump only for package cra-template-particles
## [2.0.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.0...cra-template-particles@2.0.1) (2022-02-15)
## [1.41.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.5...cra-template-particles@1.41.6) (2022-03-03)
**Note:** Version bump only for package cra-template-particles
## [1.41.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.4...cra-template-particles@1.41.5) (2022-02-24)
**Note:** Version bump only for package cra-template-particles
## [1.41.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.3...cra-template-particles@1.41.4) (2022-02-20)
**Note:** Version bump only for package cra-template-particles
## [1.41.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.2...cra-template-particles@1.41.3) (2022-02-19)
**Note:** Version bump only for package cra-template-particles
## [1.41.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.1...cra-template-particles@1.41.2) (2022-02-16)
**Note:** Version bump only for package cra-template-particles
# [2.0.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.1...cra-template-particles@2.0.0) (2022-02-15)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.22.2...cra-template-particles@2.0.0-beta.5) (2022-01-30)
## [1.41.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.41.0...cra-template-particles@1.41.1) (2022-02-14)
**Note:** Version bump only for package cra-template-particles
# [1.41.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.40.2...cra-template-particles@1.41.0) (2022-02-10)
**Note:** Version bump only for package cra-template-particles
## [1.40.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.40.1...cra-template-particles@1.40.2) (2022-02-07)
**Note:** Version bump only for package cra-template-particles
## [1.40.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.40.0...cra-template-particles@1.40.1) (2022-02-06)
**Note:** Version bump only for package cra-template-particles
# [1.40.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.22.3...cra-template-particles@1.40.0) (2022-02-04)
**Note:** Version bump only for package cra-template-particles
## [1.22.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.22.2...cra-template-particles@1.22.3) (2022-02-02)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
- updated fpsLimit default value to 120 build: updated all presets to have a fpsLimit of 120 ([d1eff05](https://github.com/tsparticles/tsparticles/commit/d1eff050224c4d65727c0abc3f100d70d3807eb8))
# [2.0.0-beta.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.0-beta.3...cra-template-particles@2.0.0-beta.4) (2021-12-07)
## [1.22.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.22.1...cra-template-particles@1.22.2) (2022-01-29)
**Note:** Version bump only for package cra-template-particles
## [1.22.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.22.0...cra-template-particles@1.22.1) (2022-01-26)
**Note:** Version bump only for package cra-template-particles
# [1.22.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.21.0...cra-template-particles@1.22.0) (2022-01-08)
**Note:** Version bump only for package cra-template-particles
# [1.21.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.6...cra-template-particles@1.21.0) (2021-12-29)
**Note:** Version bump only for package cra-template-particles
## [1.20.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.5...cra-template-particles@1.20.6) (2021-12-24)
**Note:** Version bump only for package cra-template-particles
# [2.0.0-beta.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.5...cra-template-particles@2.0.0-beta.3) (2021-12-04)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.4...cra-template-particles@2.0.0-beta.2) (2021-10-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@2.0.0-beta.0...cra-template-particles@2.0.0-beta.1) (2021-10-06)
## [1.20.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.4...cra-template-particles@1.20.5) (2021-11-28)
**Note:** Version bump only for package cra-template-particles
## [1.20.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.3...cra-template-particles@1.20.4) (2021-11-17)
**Note:** Version bump only for package cra-template-particles
## [1.20.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.2...cra-template-particles@1.20.3) (2021-11-05)
**Note:** Version bump only for package cra-template-particles
## [1.20.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.1...cra-template-particles@1.20.2) (2021-10-31)
**Note:** Version bump only for package cra-template-particles
## [1.20.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.20.0...cra-template-particles@1.20.1) (2021-10-30)
**Note:** Version bump only for package cra-template-particles
# [1.20.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.19.0...cra-template-particles@1.20.0) (2021-10-28)
**Note:** Version bump only for package cra-template-particles
# [1.19.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.4...cra-template-particles@1.19.0) (2021-10-14)
**Note:** Version bump only for package cra-template-particles
## [1.18.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.3...cra-template-particles@1.18.4) (2021-10-06)
**Note:** Version bump only for package cra-template-particles
# [2.0.0-beta.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.3...cra-template-particles@2.0.0-beta.0) (2021-10-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [1.18.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.2...cra-template-particles@1.18.3) (2021-10-03)
**Note:** Version bump only for package cra-template-particles
## [1.18.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.1...cra-template-particles@1.18.2) (2021-09-27)
**Note:** Version bump only for package cra-template-particles
## [1.18.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.18.0...cra-template-particles@1.18.1) (2021-09-20)
**Note:** Version bump only for package cra-template-particles
# [1.18.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.17.1...cra-template-particles@1.18.0) (2021-09-18)
**Note:** Version bump only for package cra-template-particles
## [1.17.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.17.0...cra-template-particles@1.17.1) (2021-09-15)
**Note:** Version bump only for package cra-template-particles
# [1.17.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.16.3...cra-template-particles@1.17.0) (2021-08-23)
**Note:** Version bump only for package cra-template-particles
## [1.16.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.16.2...cra-template-particles@1.16.3) (2021-08-10)
**Note:** Version bump only for package cra-template-particles
## [1.16.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.16.1...cra-template-particles@1.16.2) (2021-07-31)
**Note:** Version bump only for package cra-template-particles
## [1.16.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.16.0...cra-template-particles@1.16.1) (2021-07-29)
**Note:** Version bump only for package cra-template-particles
# [1.16.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.15.0...cra-template-particles@1.16.0) (2021-07-29)
**Note:** Version bump only for package cra-template-particles
## [1.1.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0...cra-template-particles@1.1.1) (2020-10-06)
**Note:** Version bump only for package cra-template-particles
# [1.1.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.6...cra-template-particles@1.1.0) (2020-10-05)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.5...cra-template-particles@1.1.0-beta.6) (2020-10-04)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.4...cra-template-particles@1.1.0-beta.5) (2020-10-04)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.3...cra-template-particles@1.1.0-beta.4) (2020-10-03)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.2...cra-template-particles@1.1.0-beta.3) (2020-10-03)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.1...cra-template-particles@1.1.0-beta.2) (2020-10-03)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-beta.0...cra-template-particles@1.1.0-beta.1) (2020-10-02)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-beta.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.0.12...cra-template-particles@1.1.0-beta.0) (2020-10-02)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.14](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.0.9...cra-template-particles@1.1.0-alpha.14) (2020-08-22)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.13](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.12...cra-template-particles@1.1.0-alpha.13) (2020-08-17)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.12](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.0.8...cra-template-particles@1.1.0-alpha.12) (2020-08-16)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.11](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.10...cra-template-particles@1.1.0-alpha.11) (2020-08-13)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.10](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.9...cra-template-particles@1.1.0-alpha.10) (2020-08-13)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.9](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.8...cra-template-particles@1.1.0-alpha.9) (2020-08-13)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.8](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.7...cra-template-particles@1.1.0-alpha.8) (2020-08-13)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.7](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.6...cra-template-particles@1.1.0-alpha.7) (2020-08-12)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.5...cra-template-particles@1.1.0-alpha.6) (2020-08-11)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.4...cra-template-particles@1.1.0-alpha.5) (2020-08-11)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.3...cra-template-particles@1.1.0-alpha.4) (2020-08-11)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.2...cra-template-particles@1.1.0-alpha.3) (2020-08-10)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.1.0-alpha.1...cra-template-particles@1.1.0-alpha.2) (2020-08-09)
**Note:** Version bump only for package cra-template-particles
# [1.1.0-alpha.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles@1.0.7...cra-template-particles@1.1.0-alpha.1) (2020-08-08)
**Note:** Version bump only for package cra-template-particles
================================================
FILE: templates/react/LICENSE
================================================
MIT License
Copyright (c) 2020 Matteo Bruni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: templates/react/README.md
================================================
[](https://particles.js.org)
# cra-template-particles
This is the official template for [React tsParticles](https://github.com/tsparticles/tsparticles) [Create React App](https://github.com/facebook/create-react-app).
If you don't specify a template (for example, `--template particles`), this template will be used by default.
For example:
```sh
npx create-react-app my-app --template particles
# or
yarn create react-app my-app --template particles
```
For more information, please refer to:
- [Getting Started](https://create-react-app.dev/docs/getting-started) – How to create a new app.
- [User Guide](https://create-react-app.dev) – How to develop apps bootstrapped with Create React App.
- [Particles Guide](https://github.com/tsparticles/tsparticles) - How to customize tsParticles options.
- [Particles Demo](https://particles.js.org) - tsParticles demo website.
================================================
FILE: templates/react/package.json
================================================
{
"name": "cra-template-particles",
"version": "3.0.0",
"description": "Official React tsParticles template",
"keywords": [
"front-end",
"frontend",
"tsparticles",
"particles.js",
"particlesjs",
"particles",
"particle",
"canvas",
"jsparticles",
"xparticles",
"particles-js",
"particles-bg",
"particles-bg-vue",
"particles-ts",
"particles.ts",
"react-particles-js",
"react-particles.js",
"react-particles",
"react",
"reactjs",
"vue-particles",
"ngx-particles",
"angular-particles",
"particleground",
"vue",
"vuejs",
"preact",
"preactjs",
"jquery",
"angularjs",
"angular",
"typescript",
"javascript",
"animation",
"web",
"html5",
"web-design",
"webdesign",
"css",
"html",
"css3",
"animated",
"background",
"confetti",
"canvas",
"fireworks",
"fireworks-js",
"confetti-js",
"confettijs",
"fireworksjs",
"canvas-confetti"
],
"author": "Matteo Bruni ",
"homepage": "https://particles.js.org",
"license": "MIT",
"main": "template.json",
"files": [
"template",
"template.json"
],
"repository": {
"type": "git",
"url": "git+https://github.com/tsparticles/react.git",
"directory": "templates/react"
},
"bugs": {
"url": "https://github.com/tsparticles/react/issues"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/matteobruni"
},
{
"type": "github",
"url": "https://github.com/sponsors/tsparticles"
},
{
"type": "buymeacoffee",
"url": "https://www.buymeacoffee.com/matteobruni"
}
],
"dependencies": {
"@tsparticles/engine": "^3.0.2",
"@tsparticles/react": "^3.0.0",
"tslib": "^2.6.2",
"tsparticles": "^3.0.2"
},
"devDependencies": {
"fs-extra": "^11.2.0"
},
"scripts": {
"build": "node scripts/prebuild.js",
"build:ci": "node scripts/prebuild.js",
"version": "pnpm run build && git add ./template.json",
"prepack": "pnpm run build"
}
}
================================================
FILE: templates/react/scripts/prebuild.js
================================================
const fs = require('fs-extra');
const mainPackage = require('../package.json');
const libPackage = './template.json';
fs.readFile(libPackage, function (error, data) {
if (error) {
throw error;
}
const text = data.toString();
const libObj = JSON.parse(text);
console.log(libObj);
libObj.package.dependencies["@tsparticles/react"] = mainPackage.dependencies["@tsparticles/react"].replace("workspace:", "");
libObj.package.dependencies["tsparticles"] = mainPackage.dependencies["tsparticles"].replace("workspace:", "");
libObj.package.dependencies["@tsparticles/engine"] = mainPackage.dependencies["@tsparticles/engine"].replace("workspace:", "");
fs.writeFile(libPackage, JSON.stringify(libObj, undefined, 2), 'utf-8', function () {
console.log(`template.json dependencies updated successfully`);
});
});
================================================
FILE: templates/react/template/README.md
================================================
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
================================================
FILE: templates/react/template/gitignore
================================================
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
================================================
FILE: templates/react/template/public/index.html
================================================
React App
================================================
FILE: templates/react/template/public/manifest.json
================================================
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
================================================
FILE: templates/react/template/public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
================================================
FILE: templates/react/template/src/App.css
================================================
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#tsparticles {
position: fixed;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
left: 0;
top: 0;
z-index: -1;
}
================================================
FILE: templates/react/template/src/App.js
================================================
import React, {useEffect, useState} from "react";
import Particles, {initParticlesEngine} from "@tsparticles/react";
import {loadFull} from "tsparticles";
import logo from "./logo.svg";
import "./App.css";
import particlesOptions from "./particles.json";
function App() {
const [init, setInit] = useState(false);
useEffect(() => {
if (init) {
return;
}
initParticlesEngine(async (engine) => {
await loadFull(engine);
}).then(() => {
setInit(true);
});
}, []);
return (
{init && }
Edit src/App.js and save to reload.
Edit src/particles.json to customize Particles, then save
to reload.
);
}
export default App;
================================================
FILE: templates/react/template/src/App.test.js
================================================
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render();
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
================================================
FILE: templates/react/template/src/index.css
================================================
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
================================================
FILE: templates/react/template/src/index.js
================================================
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
================================================
FILE: templates/react/template/src/particles.json
================================================
{
"background": {
"color": "#282c34"
},
"interactivity": {
"events": {
"onClick": {
"enable": true,
"mode": "push"
},
"onHover": {
"enable": true,
"mode": "repulse"
},
"resize": true
},
"modes": {
"push": {
"quantity": 4
},
"repulse": {
"distance": 200,
"duration": 0.4
}
}
},
"particles": {
"color": {
"value": "#ffffff"
},
"links": {
"color": "#ffffff",
"distance": 150,
"enable": true,
"opacity": 0.5,
"width": 1
},
"collisions": {
"enable": true
},
"move": {
"direction": "none",
"enable": true,
"outModes": {
"default": "bounce"
},
"random": false,
"speed": 6,
"straight": false
},
"number": {
"density": {
"enable": true
},
"value": 80
},
"opacity": {
"value": 0.5
},
"shape": {
"type": "circle"
},
"size": {
"random": true,
"value": 5
}
}
}
================================================
FILE: templates/react/template/src/serviceWorker.js
================================================
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}
================================================
FILE: templates/react/template/src/setupTests.js
================================================
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';
================================================
FILE: templates/react/template.json
================================================
{
"package": {
"dependencies": {
"@tsparticles/react": "^3.0.0",
"@tsparticles/engine": "^3.0.2",
"tsparticles": "^3.0.2",
"tslib": "^2.6.2"
}
}
}
================================================
FILE: templates/react-ts/CHANGELOG.md
================================================
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [3.0.0](https://github.com/tsparticles/react/compare/v2.12.2...v3.0.0) (2023-12-07)
### Bug Fixes
* **deps:** update dependency @testing-library/jest-dom to v6 ([ba7f6c0](https://github.com/tsparticles/react/commit/ba7f6c08f5373eaf83838ba579c4a755353ac6b4))
* fixed component, it was refreshing infinite times for a bug. now it works perfectly ([4ef5e81](https://github.com/tsparticles/react/commit/4ef5e8197f1364e3a62c8262ae04c9272457047a))
### Features
* added particles setup function (name not definitive), updated to v3 ([e164c66](https://github.com/tsparticles/react/commit/e164c669b515d30057059ef8f7a8d35ff562b5e3))
## [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.12.1...v3.0.0-beta.1) (2023-08-11)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.12.1](https://github.com/tsparticles/react/compare/v3.0.0-beta.1...v2.12.1) (2023-08-04)
**Note:** Version bump only for package cra-template-particles-typescript
# [3.0.0-beta.1](https://github.com/tsparticles/react/compare/v2.11.0...v3.0.0-beta.1) (2023-08-04)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.11.0](https://github.com/tsparticles/react/compare/v2.10.1...v2.11.0) (2023-07-14)
**Note:** Version bump only for package cra-template-particles-typescript
## 2.10.1 (2023-06-04)
### Features
* updated templates to React 18 ([d9ae354](https://github.com/tsparticles/react/commit/d9ae354d71f245e85009c96007bd59df7bd422c8))
## [2.9.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.9.2...cra-template-particles-typescript@2.9.3) (2023-02-12)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.9.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.9.1...cra-template-particles-typescript@2.9.2) (2023-02-12)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.9.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.9.0...cra-template-particles-typescript@2.9.1) (2023-02-11)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.9.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.8.0...cra-template-particles-typescript@2.9.0) (2023-02-10)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.8.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.7.1...cra-template-particles-typescript@2.8.0) (2023-01-18)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.7.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.7.0...cra-template-particles-typescript@2.7.1) (2022-12-25)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.7.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.6.0...cra-template-particles-typescript@2.7.0) (2022-12-23)
### Features
- improved density values, now is 1:1 with number on 1080 resolution with pixel ratio of 1 ([3ff8fbf](https://github.com/tsparticles/tsparticles/commit/3ff8fbfefb01f1d6fe8be836c3c2909b74630475))
# [2.6.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.5.3...cra-template-particles-typescript@2.6.0) (2022-12-06)
### Bug Fixes
- **deps:** update dependency fs-extra to v11 ([e82352a](https://github.com/tsparticles/tsparticles/commit/e82352a685960603a58fb222f91d157ee65967de))
## [2.5.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.5.2...cra-template-particles-typescript@2.5.3) (2022-11-07)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.5.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.5.1...cra-template-particles-typescript@2.5.2) (2022-11-07)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.5.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.5.0...cra-template-particles-typescript@2.5.1) (2022-11-03)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.5.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.4.0...cra-template-particles-typescript@2.5.0) (2022-11-02)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.4.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.3.4...cra-template-particles-typescript@2.4.0) (2022-10-30)
### Features
- removed all canvas context save/restore calls ([208722f](https://github.com/tsparticles/tsparticles/commit/208722f0a521246165b7cdc529dfbfbd7a3cf7eb))
## [2.3.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.3.3...cra-template-particles-typescript@2.3.4) (2022-09-30)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.3.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.3.2...cra-template-particles-typescript@2.3.3) (2022-09-30)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.3.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.3.1...cra-template-particles-typescript@2.3.2) (2022-09-21)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.3.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.3.0...cra-template-particles-typescript@2.3.1) (2022-09-13)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.3.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.2.4...cra-template-particles-typescript@2.3.0) (2022-09-11)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.2.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.2.2...cra-template-particles-typescript@2.2.4) (2022-08-26)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.2.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.2.2...cra-template-particles-typescript@2.2.3) (2022-08-21)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.2.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.2.1...cra-template-particles-typescript@2.2.2) (2022-08-16)
### Bug Fixes
- fixed double mouse events on mobile using pointer events, closes [#4622](https://github.com/tsparticles/tsparticles/issues/4622) ([1019fa4](https://github.com/tsparticles/tsparticles/commit/1019fa431f8a43cbd45d6adeb5adf94433e6e04b))
## [2.2.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.2.0...cra-template-particles-typescript@2.2.1) (2022-08-12)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.2.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.1.4...cra-template-particles-typescript@2.2.0) (2022-08-11)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.1.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.1.3...cra-template-particles-typescript@2.1.4) (2022-07-28)
### Features
- preparing @tsparticles/react and switching alternate packages ([49e749e](https://github.com/tsparticles/tsparticles/commit/49e749e90e076f0cb22eefe0f3399102f5b9fb35))
## [2.1.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.1.2...cra-template-particles-typescript@2.1.3) (2022-07-01)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.1.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.1.1...cra-template-particles-typescript@2.1.2) (2022-07-01)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.1.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.1.0...cra-template-particles-typescript@2.1.1) (2022-07-01)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.1.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.6...cra-template-particles-typescript@2.1.0) (2022-06-18)
### Bug Fixes
- **deps:** update dependency @capacitor/core to v3.5.0 ([581bb7e](https://github.com/tsparticles/tsparticles/commit/581bb7e2f4f6aceb3535daf9223954a80f2daa81))
- fixed react-tsparticles typescript template ([04a4d10](https://github.com/tsparticles/tsparticles/commit/04a4d100b97bd5828d7346c7277c5b47bd8f9208))
## [2.0.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.5...cra-template-particles-typescript@2.0.6) (2022-04-16)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.0.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.4...cra-template-particles-typescript@2.0.5) (2022-04-14)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.0.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.43.1...cra-template-particles-typescript@2.0.4) (2022-04-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [2.0.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.1...cra-template-particles-typescript@2.0.3) (2022-03-11)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [2.0.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.4...cra-template-particles-typescript@2.0.2) (2022-02-21)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [1.43.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.43.0...cra-template-particles-typescript@1.43.1) (2022-04-06)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.43.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.4...cra-template-particles-typescript@1.43.0) (2022-04-04)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.42.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.3...cra-template-particles-typescript@1.42.4) (2022-03-20)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.42.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.2...cra-template-particles-typescript@1.42.3) (2022-03-18)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.42.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.1...cra-template-particles-typescript@1.42.2) (2022-03-14)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.42.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.42.0...cra-template-particles-typescript@1.42.1) (2022-03-09)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.42.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.6...cra-template-particles-typescript@1.42.0) (2022-03-08)
**Note:** Version bump only for package cra-template-particles-typescript
## [2.0.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.0...cra-template-particles-typescript@2.0.1) (2022-02-15)
## [1.41.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.5...cra-template-particles-typescript@1.41.6) (2022-03-03)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.41.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.4...cra-template-particles-typescript@1.41.5) (2022-02-24)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.41.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.3...cra-template-particles-typescript@1.41.4) (2022-02-20)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.41.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.2...cra-template-particles-typescript@1.41.3) (2022-02-19)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.41.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.1...cra-template-particles-typescript@1.41.2) (2022-02-16)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.0.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.1...cra-template-particles-typescript@2.0.0) (2022-02-15)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.22.2...cra-template-particles-typescript@2.0.0-beta.5) (2022-01-30)
## [1.41.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.41.0...cra-template-particles-typescript@1.41.1) (2022-02-14)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.41.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.40.2...cra-template-particles-typescript@1.41.0) (2022-02-10)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.40.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.40.1...cra-template-particles-typescript@1.40.2) (2022-02-07)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.40.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.40.0...cra-template-particles-typescript@1.40.1) (2022-02-06)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.40.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.22.3...cra-template-particles-typescript@1.40.0) (2022-02-04)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.22.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.22.2...cra-template-particles-typescript@1.22.3) (2022-02-02)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
- updated fpsLimit default value to 120 build: updated all presets to have a fpsLimit of 120 ([d1eff05](https://github.com/tsparticles/tsparticles/commit/d1eff050224c4d65727c0abc3f100d70d3807eb8))
# [2.0.0-beta.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.0-beta.3...cra-template-particles-typescript@2.0.0-beta.4) (2021-12-07)
## [1.22.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.22.1...cra-template-particles-typescript@1.22.2) (2022-01-29)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.22.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.22.0...cra-template-particles-typescript@1.22.1) (2022-01-26)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.22.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.21.0...cra-template-particles-typescript@1.22.0) (2022-01-08)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.21.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.6...cra-template-particles-typescript@1.21.0) (2021-12-29)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.20.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.5...cra-template-particles-typescript@1.20.6) (2021-12-24)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.0.0-beta.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.5...cra-template-particles-typescript@2.0.0-beta.3) (2021-12-04)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.4...cra-template-particles-typescript@2.0.0-beta.2) (2021-10-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
# [2.0.0-beta.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@2.0.0-beta.0...cra-template-particles-typescript@2.0.0-beta.1) (2021-10-06)
## [1.20.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.4...cra-template-particles-typescript@1.20.5) (2021-11-28)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.20.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.3...cra-template-particles-typescript@1.20.4) (2021-11-17)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.20.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.2...cra-template-particles-typescript@1.20.3) (2021-11-05)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.20.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.1...cra-template-particles-typescript@1.20.2) (2021-10-31)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.20.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.20.0...cra-template-particles-typescript@1.20.1) (2021-10-30)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.20.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.19.0...cra-template-particles-typescript@1.20.0) (2021-10-28)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.19.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.4...cra-template-particles-typescript@1.19.0) (2021-10-14)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.18.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.3...cra-template-particles-typescript@1.18.4) (2021-10-06)
**Note:** Version bump only for package cra-template-particles-typescript
# [2.0.0-beta.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.3...cra-template-particles-typescript@2.0.0-beta.0) (2021-10-06)
### Features
- splitting engine from slim and full bundles (v2) ([268b78c](https://github.com/tsparticles/tsparticles/commit/268b78c12d6c54069893d27643cfe7a30f3be777))
## [1.18.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.2...cra-template-particles-typescript@1.18.3) (2021-10-03)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.18.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.1...cra-template-particles-typescript@1.18.2) (2021-09-27)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.18.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.18.0...cra-template-particles-typescript@1.18.1) (2021-09-20)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.18.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.17.1...cra-template-particles-typescript@1.18.0) (2021-09-18)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.17.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.17.0...cra-template-particles-typescript@1.17.1) (2021-09-15)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.17.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.16.3...cra-template-particles-typescript@1.17.0) (2021-08-23)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.16.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.16.2...cra-template-particles-typescript@1.16.3) (2021-08-10)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.16.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.16.1...cra-template-particles-typescript@1.16.2) (2021-07-31)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.16.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.16.0...cra-template-particles-typescript@1.16.1) (2021-07-29)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.16.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.15.0...cra-template-particles-typescript@1.16.0) (2021-07-29)
**Note:** Version bump only for package cra-template-particles-typescript
## [1.1.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0...cra-template-particles-typescript@1.1.1) (2020-10-06)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.6...cra-template-particles-typescript@1.1.0) (2020-10-05)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.5...cra-template-particles-typescript@1.1.0-beta.6) (2020-10-04)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.4...cra-template-particles-typescript@1.1.0-beta.5) (2020-10-04)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.3...cra-template-particles-typescript@1.1.0-beta.4) (2020-10-03)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.2...cra-template-particles-typescript@1.1.0-beta.3) (2020-10-03)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.1...cra-template-particles-typescript@1.1.0-beta.2) (2020-10-03)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-beta.0...cra-template-particles-typescript@1.1.0-beta.1) (2020-10-02)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-beta.0](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.0.12...cra-template-particles-typescript@1.1.0-beta.0) (2020-10-02)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.14](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.0.9...cra-template-particles-typescript@1.1.0-alpha.14) (2020-08-22)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.13](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.12...cra-template-particles-typescript@1.1.0-alpha.13) (2020-08-17)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.12](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.0.8...cra-template-particles-typescript@1.1.0-alpha.12) (2020-08-16)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.11](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.10...cra-template-particles-typescript@1.1.0-alpha.11) (2020-08-13)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.10](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.9...cra-template-particles-typescript@1.1.0-alpha.10) (2020-08-13)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.9](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.8...cra-template-particles-typescript@1.1.0-alpha.9) (2020-08-13)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.8](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.7...cra-template-particles-typescript@1.1.0-alpha.8) (2020-08-13)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.7](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.6...cra-template-particles-typescript@1.1.0-alpha.7) (2020-08-12)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.6](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.5...cra-template-particles-typescript@1.1.0-alpha.6) (2020-08-11)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.5](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.4...cra-template-particles-typescript@1.1.0-alpha.5) (2020-08-11)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.4](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.3...cra-template-particles-typescript@1.1.0-alpha.4) (2020-08-11)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.3](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.2...cra-template-particles-typescript@1.1.0-alpha.3) (2020-08-10)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.2](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.1.0-alpha.1...cra-template-particles-typescript@1.1.0-alpha.2) (2020-08-09)
**Note:** Version bump only for package cra-template-particles-typescript
# [1.1.0-alpha.1](https://github.com/tsparticles/tsparticles/compare/cra-template-particles-typescript@1.0.7...cra-template-particles-typescript@1.1.0-alpha.1) (2020-08-08)
**Note:** Version bump only for package cra-template-particles-typescript
================================================
FILE: templates/react-ts/LICENSE
================================================
MIT License
Copyright (c) 2020 Matteo Bruni
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: templates/react-ts/README.md
================================================
[](https://particles.js.org)
# cra-template-particles-typescript
This is the official TypeScript template for [React tsParticles](https://github.com/tsparticles/tsparticles) with [Create React App](https://github.com/facebook/create-react-app).
To use this template, add `--template particles-typescript` when creating a new app.
For example:
```sh
npx create-react-app my-app --template particles-typescript
# or
yarn create react-app my-app --template particles-typescript
```
For more information, please refer to:
- [Getting Started](https://create-react-app.dev/docs/getting-started) – How to create a new app.
- [User Guide](https://create-react-app.dev) – How to develop apps bootstrapped with Create React App.
- [Particles Guide](https://github.com/tsparticles/tsparticles) - How to customize tsParticles options.
- [Particles Demo](https://particles.js.org) - tsParticles demo website.
================================================
FILE: templates/react-ts/package.json
================================================
{
"name": "cra-template-particles-typescript",
"version": "3.0.0",
"description": "Official TypeScript React tsParticles template",
"keywords": [
"front-end",
"frontend",
"tsparticles",
"particles.js",
"particlesjs",
"particles",
"particle",
"canvas",
"jsparticles",
"xparticles",
"particles-js",
"particles-bg",
"particles-bg-vue",
"particles-ts",
"particles.ts",
"react-particles-js",
"react-particles.js",
"react-particles",
"react",
"reactjs",
"vue-particles",
"ngx-particles",
"angular-particles",
"particleground",
"vue",
"vuejs",
"preact",
"preactjs",
"jquery",
"angularjs",
"angular",
"typescript",
"javascript",
"animation",
"web",
"html5",
"web-design",
"webdesign",
"css",
"html",
"css3",
"animated",
"background",
"confetti",
"canvas",
"fireworks",
"fireworks-js",
"confetti-js",
"confettijs",
"fireworksjs",
"canvas-confetti"
],
"author": "Matteo Bruni ",
"homepage": "https://particles.js.org",
"license": "MIT",
"main": "template.json",
"files": [
"template",
"template.json"
],
"repository": {
"type": "git",
"url": "git+https://github.com/tsparticles/react.git",
"directory": "templates/react-ts"
},
"bugs": {
"url": "https://github.com/tsparticles/react/issues"
},
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/matteobruni"
},
{
"type": "github",
"url": "https://github.com/sponsors/tsparticles"
},
{
"type": "buymeacoffee",
"url": "https://www.buymeacoffee.com/matteobruni"
}
],
"dependencies": {
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.1",
"@tsparticles/engine": "^3.0.2",
"@tsparticles/react": "^3.0.0",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.3",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"tslib": "^2.6.2",
"tsparticles": "^3.0.2",
"typescript": "^5.3.3",
"web-vitals": "^3.5.0"
},
"devDependencies": {
"fs-extra": "^11.2.0"
},
"scripts": {
"build": "node scripts/prebuild.js",
"build:ci": "node scripts/prebuild.js",
"version": "pnpm run build && git add ./template.json",
"prepack": "pnpm run build"
}
}
================================================
FILE: templates/react-ts/scripts/prebuild.js
================================================
const fs = require('fs-extra');
const mainPackage = require('../package.json');
const libPackage = './template.json';
fs.readFile(libPackage, function (error, data) {
if (error) {
throw error;
}
const text = data.toString();
const libObj = JSON.parse(text);
console.log(libObj);
libObj.package.dependencies["@tsparticles/react"] = mainPackage.dependencies["@tsparticles/react"].replace("workspace:", "");
libObj.package.dependencies["tsparticles"] = mainPackage.dependencies["tsparticles"].replace("workspace:", "");
libObj.package.dependencies["@tsparticles/engine"] = mainPackage.dependencies["@tsparticles/engine"].replace("workspace:", "");
fs.writeFile(libPackage, JSON.stringify(libObj, undefined, 2), 'utf-8', function () {
console.log(`template.json dependencies updated successfully`);
});
});
================================================
FILE: templates/react-ts/template/README.md
================================================
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can’t go back!**
If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
================================================
FILE: templates/react-ts/template/gitignore
================================================
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
================================================
FILE: templates/react-ts/template/public/index.html
================================================
React App
================================================
FILE: templates/react-ts/template/public/manifest.json
================================================
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
================================================
FILE: templates/react-ts/template/public/robots.txt
================================================
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
================================================
FILE: templates/react-ts/template/src/App.css
================================================
.App {
text-align: center;
}
.App-logo {
height: 40vmin;
pointer-events: none;
}
@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}
.App-header {
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
#tsparticles {
position: fixed;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
left: 0;
top: 0;
z-index: -1;
}
================================================
FILE: templates/react-ts/template/src/App.test.tsx
================================================
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render();
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
================================================
FILE: templates/react-ts/template/src/App.tsx
================================================
import React, { useCallback, useEffect, useState } from "react";
import Particles, { initParticlesEngine } from "@tsparticles/react";
import type { Engine } from "@tsparticles/engine";
import { loadFull } from "tsparticles";
import logo from "./logo.svg";
import "./App.css";
import particlesOptions from "./particles.json";
import { ISourceOptions } from "@tsparticles/engine";
function App() {
const [ init, setInit ] = useState(false);
useEffect(() => {
initParticlesEngine(async (engine) => {
await loadFull(engine);
}).then(() => {
setInit(true);
});
}, []);
return (
{init && (
)}
Edit src/App.tsx and save to reload.
Edit src/particles.json to customize Particles, then save
to reload.
);
}
export default App;
================================================
FILE: templates/react-ts/template/src/index.css
================================================
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
================================================
FILE: templates/react-ts/template/src/index.tsx
================================================
import React from "react";
import ReactDOM from "react-dom/client";
import "./index.css";
import App from "./App";
import * as serviceWorker from "./serviceWorker";
import reportWebVitals from "./reportWebVitals";
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://cra.link/PWA
serviceWorker.unregister();
// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
================================================
FILE: templates/react-ts/template/src/particles.json
================================================
{
"background": {
"color": "#282c34"
},
"interactivity": {
"events": {
"onClick": {
"enable": true,
"mode": "push"
},
"onHover": {
"enable": true,
"mode": "repulse"
},
"resize": true
},
"modes": {
"bubble": {
"distance": 400,
"duration": 2,
"opacity": 0.8,
"size": 40
},
"push": {
"quantity": 4
},
"repulse": {
"distance": 200,
"duration": 0.4
}
}
},
"particles": {
"color": {
"value": "#ffffff"
},
"links": {
"color": "#ffffff",
"distance": 150,
"enable": true,
"opacity": 0.5,
"width": 1
},
"collisions": {
"enable": true
},
"move": {
"direction": "none",
"enable": true,
"outMode": "bounce",
"random": false,
"speed": 6,
"straight": false
},
"number": {
"density": {
"enable": true
},
"value": 80
},
"opacity": {
"value": 0.5
},
"shape": {
"type": "circle"
},
"size": {
"random": true,
"value": 5
}
}
}
================================================
FILE: templates/react-ts/template/src/reportWebVitals.ts
================================================
import { ReportHandler } from 'web-vitals';
const reportWebVitals = (onPerfEntry?: ReportHandler) => {
if (onPerfEntry && onPerfEntry instanceof Function) {
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
getCLS(onPerfEntry);
getFID(onPerfEntry);
getFCP(onPerfEntry);
getLCP(onPerfEntry);
getTTFB(onPerfEntry);
});
}
}
export default reportWebVitals;
================================================
FILE: templates/react-ts/template/src/serviceWorker.ts
================================================
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://cra.link/PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
type Config = {
onSuccess?: (registration: ServiceWorkerRegistration) => void;
onUpdate?: (registration: ServiceWorkerRegistration) => void;
};
export function register(config?: Config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(
process.env.PUBLIC_URL,
window.location.href
);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://cra.link/PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl: string, config?: Config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://cra.link/PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl: string, config?: Config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' }
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}
================================================
FILE: templates/react-ts/template/src/setupTests.ts
================================================
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
================================================
FILE: templates/react-ts/template/tsconfig.json
================================================
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"importHelpers": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": false,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}
================================================
FILE: templates/react-ts/template.json
================================================
{
"package": {
"dependencies": {
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.4.3",
"@types/node": "^20.10.3",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"@types/jest": "^29.5.10",
"@tsparticles/react": "^3.0.0",
"@tsparticles/engine": "^3.0.2",
"tslib": "^2.6.2",
"typescript": "^5.3.2",
"web-vitals": "^3.4.0",
"tsparticles": "^3.0.2"
}
}
}