tsparticles 1.37.3 → 1.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Core/Canvas.d.ts +2 -2
- package/Core/Canvas.js +17 -7
- package/Core/Loader.js +4 -9
- package/Options/Classes/Options.d.ts +1 -0
- package/Options/Classes/Options.js +2 -0
- package/Options/Interfaces/IOptions.d.ts +1 -0
- package/README.md +68 -0
- package/Utils/Constants.d.ts +1 -1
- package/Utils/Constants.js +1 -1
- package/Utils/EventListeners.d.ts +1 -0
- package/Utils/EventListeners.js +14 -3
- package/Utils/Utils.js +4 -7
- package/browser/Core/Canvas.d.ts +2 -2
- package/browser/Core/Canvas.js +17 -7
- package/browser/Core/Loader.js +4 -9
- package/browser/Options/Classes/Options.d.ts +1 -0
- package/browser/Options/Classes/Options.js +3 -1
- package/browser/Options/Interfaces/IOptions.d.ts +1 -0
- package/browser/Utils/Constants.d.ts +1 -4
- package/browser/Utils/Constants.js +1 -4
- package/browser/Utils/EventListeners.d.ts +1 -0
- package/browser/Utils/EventListeners.js +15 -4
- package/browser/Utils/Utils.js +5 -8
- package/esm/Core/Canvas.d.ts +2 -2
- package/esm/Core/Canvas.js +17 -7
- package/esm/Core/Loader.js +4 -9
- package/esm/Options/Classes/Options.d.ts +1 -0
- package/esm/Options/Classes/Options.js +3 -1
- package/esm/Options/Interfaces/IOptions.d.ts +1 -0
- package/esm/Utils/Constants.d.ts +1 -1
- package/esm/Utils/Constants.js +1 -1
- package/esm/Utils/EventListeners.d.ts +1 -0
- package/esm/Utils/EventListeners.js +15 -4
- package/esm/Utils/Utils.js +5 -8
- package/package.json +1 -1
- package/report.html +2 -2
- package/report.slim.html +2 -2
- package/scripts/install.js +14 -3
- package/tsparticles.js +38 -28
- package/tsparticles.min.js +2 -2
- package/tsparticles.slim.js +38 -28
- package/tsparticles.slim.min.js +2 -2
package/esm/Core/Loader.js
CHANGED
|
@@ -38,24 +38,19 @@ export class Loader {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
let canvasEl;
|
|
41
|
-
let generatedCanvas;
|
|
42
41
|
if (domContainer.tagName.toLowerCase() === "canvas") {
|
|
43
42
|
canvasEl = domContainer;
|
|
44
|
-
|
|
43
|
+
canvasEl.dataset[Constants.generatedAttribute] = "false";
|
|
45
44
|
}
|
|
46
45
|
else {
|
|
47
46
|
const existingCanvases = domContainer.getElementsByTagName("canvas");
|
|
48
47
|
if (existingCanvases.length) {
|
|
49
48
|
canvasEl = existingCanvases[0];
|
|
50
|
-
|
|
51
|
-
canvasEl.className = Constants.canvasClass;
|
|
52
|
-
}
|
|
53
|
-
generatedCanvas = false;
|
|
49
|
+
canvasEl.dataset[Constants.generatedAttribute] = "false";
|
|
54
50
|
}
|
|
55
51
|
else {
|
|
56
|
-
generatedCanvas = true;
|
|
57
52
|
canvasEl = document.createElement("canvas");
|
|
58
|
-
canvasEl.
|
|
53
|
+
canvasEl.dataset[Constants.generatedAttribute] = "true";
|
|
59
54
|
canvasEl.style.width = "100%";
|
|
60
55
|
canvasEl.style.height = "100%";
|
|
61
56
|
domContainer.appendChild(canvasEl);
|
|
@@ -68,7 +63,7 @@ export class Loader {
|
|
|
68
63
|
else {
|
|
69
64
|
dom.push(newItem);
|
|
70
65
|
}
|
|
71
|
-
newItem.canvas.loadCanvas(canvasEl
|
|
66
|
+
newItem.canvas.loadCanvas(canvasEl);
|
|
72
67
|
await newItem.start();
|
|
73
68
|
return newItem;
|
|
74
69
|
}
|
|
@@ -32,6 +32,7 @@ export declare class Options implements IOptions, IOptionLoader<IOptions> {
|
|
|
32
32
|
pauseOnBlur: boolean;
|
|
33
33
|
pauseOnOutsideViewport: boolean;
|
|
34
34
|
preset?: string | string[];
|
|
35
|
+
style: RecursivePartial<CSSStyleDeclaration>;
|
|
35
36
|
responsive: Responsive[];
|
|
36
37
|
themes: Theme[];
|
|
37
38
|
zLayers: number;
|
|
@@ -8,7 +8,7 @@ import { Interactivity } from "./Interactivity/Interactivity";
|
|
|
8
8
|
import { ParticlesOptions } from "./Particles/ParticlesOptions";
|
|
9
9
|
import { BackgroundMask } from "./BackgroundMask/BackgroundMask";
|
|
10
10
|
import { Background } from "./Background/Background";
|
|
11
|
-
import { Plugins } from "../../Utils";
|
|
11
|
+
import { deepExtend, Plugins } from "../../Utils";
|
|
12
12
|
import { Theme } from "./Theme/Theme";
|
|
13
13
|
import { ResponsiveMode, ThemeMode } from "../../Enums";
|
|
14
14
|
import { FullScreen } from "./FullScreen/FullScreen";
|
|
@@ -32,6 +32,7 @@ export class Options {
|
|
|
32
32
|
this.pauseOnBlur = true;
|
|
33
33
|
this.pauseOnOutsideViewport = true;
|
|
34
34
|
this.responsive = [];
|
|
35
|
+
this.style = {};
|
|
35
36
|
this.themes = [];
|
|
36
37
|
this.zLayers = 100;
|
|
37
38
|
}
|
|
@@ -110,6 +111,7 @@ export class Options {
|
|
|
110
111
|
}
|
|
111
112
|
this.motion.load(data.motion);
|
|
112
113
|
this.particles.load(data.particles);
|
|
114
|
+
this.style = deepExtend(this.style, data.style);
|
|
113
115
|
Plugins.loadOptions(this, data);
|
|
114
116
|
if (data.responsive !== undefined) {
|
|
115
117
|
for (const responsive of data.responsive) {
|
package/esm/Utils/Constants.d.ts
CHANGED
package/esm/Utils/Constants.js
CHANGED
|
@@ -12,6 +12,7 @@ export declare class EventListeners {
|
|
|
12
12
|
private readonly mouseUpHandler;
|
|
13
13
|
private readonly visibilityChangeHandler;
|
|
14
14
|
private readonly themeChangeHandler;
|
|
15
|
+
private readonly oldThemeChangeHandler;
|
|
15
16
|
private readonly resizeHandler;
|
|
16
17
|
private canPush;
|
|
17
18
|
private resizeTimeout?;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClickMode, InteractivityDetect } from "../Enums";
|
|
2
2
|
import { Constants } from "./Constants";
|
|
3
|
-
import { itemFromArray } from "./Utils";
|
|
3
|
+
import { isSsr, itemFromArray } from "./Utils";
|
|
4
4
|
function manageListener(element, event, handler, add, options) {
|
|
5
5
|
if (add) {
|
|
6
6
|
let addOptions = { passive: true };
|
|
@@ -32,6 +32,7 @@ export class EventListeners {
|
|
|
32
32
|
this.mouseDownHandler = () => this.mouseDown();
|
|
33
33
|
this.visibilityChangeHandler = () => this.handleVisibilityChange();
|
|
34
34
|
this.themeChangeHandler = (e) => this.handleThemeChange(e);
|
|
35
|
+
this.oldThemeChangeHandler = (e) => this.handleThemeChange(e);
|
|
35
36
|
this.resizeHandler = () => this.handleWindowResize();
|
|
36
37
|
}
|
|
37
38
|
addListeners() {
|
|
@@ -57,9 +58,19 @@ export class EventListeners {
|
|
|
57
58
|
else {
|
|
58
59
|
container.interactivity.element = container.canvas.element;
|
|
59
60
|
}
|
|
60
|
-
const mediaMatch = typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
|
|
61
|
+
const mediaMatch = !isSsr() && typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)");
|
|
61
62
|
if (mediaMatch) {
|
|
62
|
-
|
|
63
|
+
if (mediaMatch.addEventListener !== undefined) {
|
|
64
|
+
manageListener(mediaMatch, "change", this.themeChangeHandler, add);
|
|
65
|
+
}
|
|
66
|
+
else if (mediaMatch.addListener !== undefined) {
|
|
67
|
+
if (add) {
|
|
68
|
+
mediaMatch.addListener(this.oldThemeChangeHandler);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
mediaMatch.removeListener(this.oldThemeChangeHandler);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
63
74
|
}
|
|
64
75
|
const interactivityEl = container.interactivity.element;
|
|
65
76
|
if (!interactivityEl) {
|
|
@@ -117,7 +128,7 @@ export class EventListeners {
|
|
|
117
128
|
clearTimeout(this.resizeTimeout);
|
|
118
129
|
delete this.resizeTimeout;
|
|
119
130
|
}
|
|
120
|
-
this.resizeTimeout = setTimeout(() => { var _a; return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize(); }, 500);
|
|
131
|
+
this.resizeTimeout = setTimeout(async () => { var _a; return await ((_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize()); }, 500);
|
|
121
132
|
}
|
|
122
133
|
handleVisibilityChange() {
|
|
123
134
|
const container = this.container;
|
package/esm/Utils/Utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OutModeDirection } from "../Enums";
|
|
2
|
-
import { collisionVelocity, getValue } from "./NumberUtils";
|
|
2
|
+
import { collisionVelocity, getValue, getDistances } from "./NumberUtils";
|
|
3
3
|
import { Vector } from "../Core/Particle/Vector";
|
|
4
4
|
function rectSideBounce(pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor) {
|
|
5
5
|
const res = { bounced: false };
|
|
@@ -181,14 +181,11 @@ export function circleBounceDataFromParticle(p) {
|
|
|
181
181
|
};
|
|
182
182
|
}
|
|
183
183
|
export function circleBounce(p1, p2) {
|
|
184
|
-
const xVelocityDiff = p1.velocity.
|
|
185
|
-
const
|
|
186
|
-
const
|
|
187
|
-
const pos2 = p2.position;
|
|
188
|
-
const xDist = pos2.x - pos1.x;
|
|
189
|
-
const yDist = pos2.y - pos1.y;
|
|
184
|
+
const { x: xVelocityDiff, y: yVelocityDiff } = p1.velocity.sub(p2.velocity);
|
|
185
|
+
const [pos1, pos2] = [p1.position, p2.position];
|
|
186
|
+
const { dx: xDist, dy: yDist } = getDistances(pos2, pos1);
|
|
190
187
|
if (xVelocityDiff * xDist + yVelocityDiff * yDist >= 0) {
|
|
191
|
-
const angle = -Math.atan2(
|
|
188
|
+
const angle = -Math.atan2(yDist, xDist);
|
|
192
189
|
const m1 = p1.mass;
|
|
193
190
|
const m2 = p2.mass;
|
|
194
191
|
const u1 = p1.velocity.rotate(angle);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsparticles",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.",
|
|
5
5
|
"homepage": "https://particles.js.org/",
|
|
6
6
|
"scripts": {
|