@tsparticles/engine 3.0.3 → 3.2.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/373.min.js +2 -0
- package/373.min.js.LICENSE.txt +1 -0
- package/438.min.js +2 -0
- package/438.min.js.LICENSE.txt +1 -0
- package/README.md +337 -216
- package/browser/Core/Canvas.js +102 -49
- package/browser/Core/Container.js +53 -41
- package/browser/Core/Engine.js +47 -32
- package/browser/Core/Particle.js +46 -48
- package/browser/Core/Particles.js +70 -57
- package/browser/Core/Retina.js +5 -4
- package/browser/Core/Utils/Circle.js +4 -3
- package/browser/Core/Utils/Constants.js +3 -0
- package/browser/Core/Utils/EventListeners.js +19 -16
- package/browser/Core/Utils/ExternalInteractorBase.js +1 -1
- package/browser/Core/Utils/InteractionManager.js +17 -8
- package/browser/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/browser/Core/Utils/QuadTree.js +5 -3
- package/browser/Core/Utils/Vector.js +7 -2
- package/browser/Core/Utils/Vector3d.js +14 -9
- package/browser/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/browser/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/browser/Options/Classes/ManualParticle.js +3 -2
- package/browser/Options/Classes/Options.js +3 -0
- package/browser/Utils/CanvasUtils.js +50 -40
- package/browser/Utils/ColorUtils.js +124 -45
- package/browser/Utils/EventDispatcher.js +6 -5
- package/browser/Utils/HslColorManager.js +5 -5
- package/browser/Utils/NumberUtils.js +35 -23
- package/browser/Utils/RgbColorManager.js +5 -5
- package/browser/Utils/Utils.js +102 -19
- package/cjs/Core/Canvas.js +102 -49
- package/cjs/Core/Container.js +53 -41
- package/cjs/Core/Engine.js +70 -32
- package/cjs/Core/Particle.js +45 -47
- package/cjs/Core/Particles.js +93 -57
- package/cjs/Core/Retina.js +5 -4
- package/cjs/Core/Utils/Circle.js +4 -3
- package/cjs/Core/Utils/Constants.js +4 -1
- package/cjs/Core/Utils/EventListeners.js +18 -15
- package/cjs/Core/Utils/ExternalInteractorBase.js +1 -1
- package/cjs/Core/Utils/InteractionManager.js +17 -8
- package/cjs/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/cjs/Core/Utils/QuadTree.js +5 -3
- package/cjs/Core/Utils/Vector.js +7 -2
- package/cjs/Core/Utils/Vector3d.js +14 -9
- package/cjs/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/cjs/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/cjs/Options/Classes/ManualParticle.js +3 -2
- package/cjs/Options/Classes/Options.js +3 -0
- package/cjs/Utils/CanvasUtils.js +50 -40
- package/cjs/Utils/ColorUtils.js +126 -45
- package/cjs/Utils/EventDispatcher.js +6 -5
- package/cjs/Utils/HslColorManager.js +5 -5
- package/cjs/Utils/NumberUtils.js +37 -24
- package/cjs/Utils/RgbColorManager.js +5 -5
- package/cjs/Utils/Utils.js +103 -19
- package/dist_browser_Core_Container_js.js +92 -0
- package/dist_browser_Core_Particle_js.js +32 -0
- package/esm/Core/Canvas.js +102 -49
- package/esm/Core/Container.js +53 -41
- package/esm/Core/Engine.js +47 -32
- package/esm/Core/Particle.js +46 -48
- package/esm/Core/Particles.js +70 -57
- package/esm/Core/Retina.js +5 -4
- package/esm/Core/Utils/Circle.js +4 -3
- package/esm/Core/Utils/Constants.js +3 -0
- package/esm/Core/Utils/EventListeners.js +19 -16
- package/esm/Core/Utils/ExternalInteractorBase.js +1 -1
- package/esm/Core/Utils/InteractionManager.js +17 -8
- package/esm/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/esm/Core/Utils/QuadTree.js +5 -3
- package/esm/Core/Utils/Vector.js +7 -2
- package/esm/Core/Utils/Vector3d.js +14 -9
- package/esm/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/esm/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/esm/Options/Classes/ManualParticle.js +3 -2
- package/esm/Options/Classes/Options.js +3 -0
- package/esm/Utils/CanvasUtils.js +50 -40
- package/esm/Utils/ColorUtils.js +124 -45
- package/esm/Utils/EventDispatcher.js +6 -5
- package/esm/Utils/HslColorManager.js +5 -5
- package/esm/Utils/NumberUtils.js +35 -23
- package/esm/Utils/RgbColorManager.js +5 -5
- package/esm/Utils/Utils.js +102 -19
- package/package.json +1 -1
- package/report.html +3 -3
- package/tsparticles.engine.js +894 -5461
- package/tsparticles.engine.min.js +1 -1
- package/tsparticles.engine.min.js.LICENSE.txt +1 -1
- package/types/Core/Canvas.d.ts +5 -3
- package/types/Core/Container.d.ts +1 -1
- package/types/Core/Engine.d.ts +13 -8
- package/types/Core/Interfaces/IContainerPlugin.d.ts +3 -3
- package/types/Core/Interfaces/IEffectDrawer.d.ts +3 -3
- package/types/Core/Interfaces/IMovePathGenerator.d.ts +2 -2
- package/types/Core/Interfaces/IParticleHslAnimation.d.ts +4 -4
- package/types/Core/Interfaces/IParticleMover.d.ts +2 -2
- package/types/Core/Interfaces/IParticleUpdater.d.ts +2 -2
- package/types/Core/Interfaces/IParticleValueAnimation.d.ts +4 -0
- package/types/Core/Interfaces/IPlugin.d.ts +1 -1
- package/types/Core/Interfaces/IShapeDrawData.d.ts +2 -2
- package/types/Core/Interfaces/IShapeDrawer.d.ts +4 -4
- package/types/Core/Particle.d.ts +3 -3
- package/types/Core/Particles.d.ts +12 -8
- package/types/Core/Utils/Constants.d.ts +3 -0
- package/types/Core/Utils/ExternalInteractorBase.d.ts +1 -1
- package/types/Core/Utils/InteractionManager.d.ts +3 -3
- package/types/Core/Utils/ParticlesInteractorBase.d.ts +1 -1
- package/types/Core/Utils/Point.d.ts +1 -1
- package/types/Enums/Modes/OutMode.d.ts +0 -3
- package/types/Options/Classes/BackgroundMask/BackgroundMaskCover.d.ts +2 -1
- package/types/Options/Classes/Options.d.ts +1 -0
- package/types/Options/Classes/Particles/Move/Move.d.ts +1 -2
- package/types/Options/Classes/Particles/Move/OutModes.d.ts +5 -6
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMask.d.ts +2 -1
- package/types/Options/Interfaces/BackgroundMask/IBackgroundMaskCover.d.ts +2 -1
- package/types/Options/Interfaces/IOptions.d.ts +1 -0
- package/types/Options/Interfaces/Interactivity/Modes/IModes.d.ts +1 -3
- package/types/Options/Interfaces/Particles/Move/IMove.d.ts +2 -2
- package/types/Options/Interfaces/Particles/Move/IOutModes.d.ts +6 -6
- package/types/Types/CustomEventArgs.d.ts +2 -2
- package/types/Types/ExportResult.d.ts +2 -2
- package/types/Types/ParticlesGroups.d.ts +1 -3
- package/types/Types/PathOptions.d.ts +1 -3
- package/types/Types/ShapeData.d.ts +1 -3
- package/types/Utils/CanvasUtils.d.ts +9 -8
- package/types/Utils/ColorUtils.d.ts +5 -0
- package/types/Utils/NumberUtils.d.ts +2 -2
- package/types/Utils/Utils.d.ts +9 -6
- package/umd/Core/Canvas.js +102 -49
- package/umd/Core/Container.js +54 -42
- package/umd/Core/Engine.js +72 -33
- package/umd/Core/Particle.js +46 -48
- package/umd/Core/Particles.js +95 -58
- package/umd/Core/Retina.js +5 -4
- package/umd/Core/Utils/Circle.js +4 -3
- package/umd/Core/Utils/Constants.js +4 -1
- package/umd/Core/Utils/EventListeners.js +18 -15
- package/umd/Core/Utils/ExternalInteractorBase.js +1 -1
- package/umd/Core/Utils/InteractionManager.js +17 -8
- package/umd/Core/Utils/ParticlesInteractorBase.js +1 -1
- package/umd/Core/Utils/QuadTree.js +5 -3
- package/umd/Core/Utils/Vector.js +7 -2
- package/umd/Core/Utils/Vector3d.js +14 -9
- package/umd/Options/Classes/BackgroundMask/BackgroundMask.js +1 -1
- package/umd/Options/Classes/BackgroundMask/BackgroundMaskCover.js +3 -2
- package/umd/Options/Classes/ManualParticle.js +3 -2
- package/umd/Options/Classes/Options.js +3 -0
- package/umd/Utils/CanvasUtils.js +50 -40
- package/umd/Utils/ColorUtils.js +127 -46
- package/umd/Utils/EventDispatcher.js +6 -5
- package/umd/Utils/HslColorManager.js +5 -5
- package/umd/Utils/NumberUtils.js +38 -25
- package/umd/Utils/RgbColorManager.js +5 -5
- package/umd/Utils/Utils.js +104 -20
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
|
|
3
|
+
exports.millisecondsToSeconds = exports.halfRandom = exports.percentDenominator = exports.errorPrefix = exports.visibilityChangeEvent = exports.resizeEvent = exports.touchCancelEvent = exports.touchMoveEvent = exports.touchEndEvent = exports.touchStartEvent = exports.mouseMoveEvent = exports.mouseOutEvent = exports.mouseLeaveEvent = exports.mouseUpEvent = exports.mouseDownEvent = exports.generatedAttribute = void 0;
|
|
4
4
|
exports.generatedAttribute = "generated";
|
|
5
5
|
exports.mouseDownEvent = "pointerdown";
|
|
6
6
|
exports.mouseUpEvent = "pointerup";
|
|
@@ -14,3 +14,6 @@ exports.touchCancelEvent = "touchcancel";
|
|
|
14
14
|
exports.resizeEvent = "resize";
|
|
15
15
|
exports.visibilityChangeEvent = "visibilitychange";
|
|
16
16
|
exports.errorPrefix = "tsParticles - Error";
|
|
17
|
+
exports.percentDenominator = 100;
|
|
18
|
+
exports.halfRandom = 0.5;
|
|
19
|
+
exports.millisecondsToSeconds = 1000;
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.EventListeners = void 0;
|
|
4
4
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
5
5
|
const Constants_js_1 = require("./Constants.js");
|
|
6
|
+
const double = 2;
|
|
6
7
|
function manageListener(element, event, handler, add, options) {
|
|
7
8
|
if (add) {
|
|
8
9
|
let addOptions = { passive: true };
|
|
@@ -35,13 +36,14 @@ class EventListeners {
|
|
|
35
36
|
(0, Utils_js_1.executeOnSingleOrMultiple)(onClick.mode, (mode) => this.container.handleClickMode(mode));
|
|
36
37
|
}
|
|
37
38
|
if (e.type === "touchend") {
|
|
38
|
-
|
|
39
|
+
const touchDelay = 500;
|
|
40
|
+
setTimeout(() => this._mouseTouchFinish(), touchDelay);
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
43
|
this._handleThemeChange = (e) => {
|
|
42
44
|
const mediaEvent = e, container = this.container, options = container.options, defaultThemes = options.defaultThemes, themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light, theme = options.themes.find((theme) => theme.name === themeName);
|
|
43
45
|
if (theme && theme.default.auto) {
|
|
44
|
-
container.loadTheme(themeName);
|
|
46
|
+
void container.loadTheme(themeName);
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
this._handleVisibilityChange = () => {
|
|
@@ -56,7 +58,7 @@ class EventListeners {
|
|
|
56
58
|
}
|
|
57
59
|
else {
|
|
58
60
|
container.pageHidden = false;
|
|
59
|
-
if (container.
|
|
61
|
+
if (container.animationStatus) {
|
|
60
62
|
container.play(true);
|
|
61
63
|
}
|
|
62
64
|
else {
|
|
@@ -64,15 +66,16 @@ class EventListeners {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
};
|
|
67
|
-
this._handleWindowResize =
|
|
69
|
+
this._handleWindowResize = () => {
|
|
68
70
|
if (this._resizeTimeout) {
|
|
69
71
|
clearTimeout(this._resizeTimeout);
|
|
70
72
|
delete this._resizeTimeout;
|
|
71
73
|
}
|
|
72
|
-
|
|
74
|
+
const handleResize = async () => {
|
|
73
75
|
const canvas = this.container.canvas;
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
+
await canvas?.windowResize();
|
|
77
|
+
};
|
|
78
|
+
this._resizeTimeout = setTimeout(() => void handleResize(), this.container.actualOptions.interactivity.events.resize.delay * Constants_js_1.millisecondsToSeconds);
|
|
76
79
|
};
|
|
77
80
|
this._manageInteractivityListeners = (mouseLeaveTmpEvent, add) => {
|
|
78
81
|
const handlers = this._handlers, container = this.container, options = container.actualOptions;
|
|
@@ -158,12 +161,12 @@ class EventListeners {
|
|
|
158
161
|
delete this._resizeObserver;
|
|
159
162
|
}
|
|
160
163
|
else if (!this._resizeObserver && add && canvasEl) {
|
|
161
|
-
this._resizeObserver = new ResizeObserver(
|
|
164
|
+
this._resizeObserver = new ResizeObserver((entries) => {
|
|
162
165
|
const entry = entries.find((e) => e.target === canvasEl);
|
|
163
166
|
if (!entry) {
|
|
164
167
|
return;
|
|
165
168
|
}
|
|
166
|
-
|
|
169
|
+
this._handleWindowResize();
|
|
167
170
|
});
|
|
168
171
|
this._resizeObserver.observe(canvasEl);
|
|
169
172
|
}
|
|
@@ -214,7 +217,7 @@ class EventListeners {
|
|
|
214
217
|
};
|
|
215
218
|
this._mouseTouchMove = (e) => {
|
|
216
219
|
const container = this.container, options = container.actualOptions, interactivity = container.interactivity, canvasEl = container.canvas.element;
|
|
217
|
-
if (!interactivity
|
|
220
|
+
if (!interactivity?.element) {
|
|
218
221
|
return;
|
|
219
222
|
}
|
|
220
223
|
interactivity.mouse.inside = true;
|
|
@@ -236,8 +239,8 @@ class EventListeners {
|
|
|
236
239
|
if (source && target && canvasEl) {
|
|
237
240
|
const sourceRect = source.getBoundingClientRect(), targetRect = target.getBoundingClientRect(), canvasRect = canvasEl.getBoundingClientRect();
|
|
238
241
|
pos = {
|
|
239
|
-
x: mouseEvent.offsetX +
|
|
240
|
-
y: mouseEvent.offsetY +
|
|
242
|
+
x: mouseEvent.offsetX + double * sourceRect.left - (targetRect.left + canvasRect.left),
|
|
243
|
+
y: mouseEvent.offsetY + double * sourceRect.top - (targetRect.top + canvasRect.top),
|
|
241
244
|
};
|
|
242
245
|
}
|
|
243
246
|
else {
|
|
@@ -257,10 +260,10 @@ class EventListeners {
|
|
|
257
260
|
else {
|
|
258
261
|
this._canPush = e.type !== "touchmove";
|
|
259
262
|
if (canvasEl) {
|
|
260
|
-
const touchEvent = e, lastTouch = touchEvent.touches[touchEvent.touches.length -
|
|
263
|
+
const touchEvent = e, lengthOffset = 1, lastTouch = touchEvent.touches[touchEvent.touches.length - lengthOffset], canvasRect = canvasEl.getBoundingClientRect(), defaultCoordinate = 0;
|
|
261
264
|
pos = {
|
|
262
|
-
x: lastTouch.clientX - (canvasRect.left ??
|
|
263
|
-
y: lastTouch.clientY - (canvasRect.top ??
|
|
265
|
+
x: lastTouch.clientX - (canvasRect.left ?? defaultCoordinate),
|
|
266
|
+
y: lastTouch.clientY - (canvasRect.top ?? defaultCoordinate),
|
|
264
267
|
};
|
|
265
268
|
}
|
|
266
269
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ExternalInteractorBase = void 0;
|
|
4
4
|
class ExternalInteractorBase {
|
|
5
5
|
constructor(container) {
|
|
6
|
-
this.container = container;
|
|
7
6
|
this.type = "external";
|
|
7
|
+
this.container = container;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.ExternalInteractorBase = ExternalInteractorBase;
|
|
@@ -5,21 +5,24 @@ class InteractionManager {
|
|
|
5
5
|
constructor(engine, container) {
|
|
6
6
|
this.container = container;
|
|
7
7
|
this._engine = engine;
|
|
8
|
-
this._interactors =
|
|
8
|
+
this._interactors = [];
|
|
9
9
|
this._externalInteractors = [];
|
|
10
10
|
this._particleInteractors = [];
|
|
11
11
|
}
|
|
12
12
|
async externalInteract(delta) {
|
|
13
13
|
for (const interactor of this._externalInteractors) {
|
|
14
|
-
|
|
14
|
+
if (interactor.isEnabled()) {
|
|
15
|
+
await interactor.interact(delta);
|
|
16
|
+
}
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
handleClickMode(mode) {
|
|
18
20
|
for (const interactor of this._externalInteractors) {
|
|
19
|
-
interactor.handleClickMode
|
|
21
|
+
interactor.handleClickMode?.(mode);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
|
-
init() {
|
|
24
|
+
async init() {
|
|
25
|
+
this._interactors = await this._engine.getInteractors(this.container, true);
|
|
23
26
|
this._externalInteractors = [];
|
|
24
27
|
this._particleInteractors = [];
|
|
25
28
|
for (const interactor of this._interactors) {
|
|
@@ -39,15 +42,21 @@ class InteractionManager {
|
|
|
39
42
|
interactor.clear(particle, delta);
|
|
40
43
|
}
|
|
41
44
|
for (const interactor of this._particleInteractors) {
|
|
42
|
-
|
|
45
|
+
if (interactor.isEnabled(particle)) {
|
|
46
|
+
await interactor.interact(particle, delta);
|
|
47
|
+
}
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
|
-
|
|
50
|
+
reset(particle) {
|
|
46
51
|
for (const interactor of this._externalInteractors) {
|
|
47
|
-
interactor.isEnabled()
|
|
52
|
+
if (interactor.isEnabled()) {
|
|
53
|
+
interactor.reset(particle);
|
|
54
|
+
}
|
|
48
55
|
}
|
|
49
56
|
for (const interactor of this._particleInteractors) {
|
|
50
|
-
interactor.isEnabled(particle)
|
|
57
|
+
if (interactor.isEnabled(particle)) {
|
|
58
|
+
interactor.reset(particle);
|
|
59
|
+
}
|
|
51
60
|
}
|
|
52
61
|
}
|
|
53
62
|
}
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ParticlesInteractorBase = void 0;
|
|
4
4
|
class ParticlesInteractorBase {
|
|
5
5
|
constructor(container) {
|
|
6
|
-
this.container = container;
|
|
7
6
|
this.type = "particles";
|
|
7
|
+
this.container = container;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.ParticlesInteractorBase = ParticlesInteractorBase;
|
|
@@ -4,14 +4,16 @@ exports.QuadTree = void 0;
|
|
|
4
4
|
const Circle_js_1 = require("./Circle.js");
|
|
5
5
|
const Rectangle_js_1 = require("./Rectangle.js");
|
|
6
6
|
const NumberUtils_js_1 = require("../../Utils/NumberUtils.js");
|
|
7
|
+
const half = 0.5, double = 2, subdivideCount = 4;
|
|
7
8
|
class QuadTree {
|
|
8
9
|
constructor(rectangle, capacity) {
|
|
9
10
|
this.rectangle = rectangle;
|
|
10
11
|
this.capacity = capacity;
|
|
11
12
|
this._subdivide = () => {
|
|
12
13
|
const { x, y } = this.rectangle.position, { width, height } = this.rectangle.size, { capacity } = this;
|
|
13
|
-
for (let i = 0; i <
|
|
14
|
-
|
|
14
|
+
for (let i = 0; i < subdivideCount; i++) {
|
|
15
|
+
const fixedIndex = i % double;
|
|
16
|
+
this._subs.push(new QuadTree(new Rectangle_js_1.Rectangle(x + width * half * fixedIndex, y + height * half * (Math.round(i * half) - fixedIndex), width * half, height * half), capacity));
|
|
15
17
|
}
|
|
16
18
|
this._divided = true;
|
|
17
19
|
};
|
|
@@ -33,7 +35,7 @@ class QuadTree {
|
|
|
33
35
|
return this._subs.some((sub) => sub.insert(point));
|
|
34
36
|
}
|
|
35
37
|
query(range, check, found) {
|
|
36
|
-
const res = found
|
|
38
|
+
const res = found ?? [];
|
|
37
39
|
if (!range.intersects(this.rectangle)) {
|
|
38
40
|
return [];
|
|
39
41
|
}
|
package/cjs/Core/Utils/Vector.js
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Vector = void 0;
|
|
4
4
|
const Vector3d_js_1 = require("./Vector3d.js");
|
|
5
|
+
const origin = {
|
|
6
|
+
x: 0,
|
|
7
|
+
y: 0,
|
|
8
|
+
z: 0,
|
|
9
|
+
};
|
|
5
10
|
class Vector extends Vector3d_js_1.Vector3d {
|
|
6
11
|
constructor(xOrCoords, y) {
|
|
7
|
-
super(xOrCoords, y,
|
|
12
|
+
super(xOrCoords, y, origin.z);
|
|
8
13
|
}
|
|
9
14
|
static get origin() {
|
|
10
|
-
return Vector.create(
|
|
15
|
+
return Vector.create(origin.x, origin.y);
|
|
11
16
|
}
|
|
12
17
|
static clone(source) {
|
|
13
18
|
return Vector.create(source.x, source.y);
|
|
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Vector3d = void 0;
|
|
4
4
|
const Constants_js_1 = require("./Constants.js");
|
|
5
5
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
6
|
+
const origin = {
|
|
7
|
+
x: 0,
|
|
8
|
+
y: 0,
|
|
9
|
+
z: 0,
|
|
10
|
+
}, squareExp = 2, inverseFactorNumerator = 1.0;
|
|
6
11
|
class Vector3d {
|
|
7
12
|
constructor(xOrCoords, y, z) {
|
|
8
13
|
this._updateFromAngle = (angle, length) => {
|
|
@@ -13,19 +18,19 @@ class Vector3d {
|
|
|
13
18
|
this.x = xOrCoords.x;
|
|
14
19
|
this.y = xOrCoords.y;
|
|
15
20
|
const coords3d = xOrCoords;
|
|
16
|
-
this.z = coords3d.z ? coords3d.z :
|
|
21
|
+
this.z = coords3d.z ? coords3d.z : origin.z;
|
|
17
22
|
}
|
|
18
23
|
else if (xOrCoords !== undefined && y !== undefined) {
|
|
19
24
|
this.x = xOrCoords;
|
|
20
25
|
this.y = y;
|
|
21
|
-
this.z = z ??
|
|
26
|
+
this.z = z ?? origin.z;
|
|
22
27
|
}
|
|
23
28
|
else {
|
|
24
29
|
throw new Error(`${Constants_js_1.errorPrefix} Vector3d not initialized correctly`);
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
32
|
static get origin() {
|
|
28
|
-
return Vector3d.create(
|
|
33
|
+
return Vector3d.create(origin.x, origin.y, origin.z);
|
|
29
34
|
}
|
|
30
35
|
get angle() {
|
|
31
36
|
return Math.atan2(this.y, this.x);
|
|
@@ -71,7 +76,7 @@ class Vector3d {
|
|
|
71
76
|
this.z /= n;
|
|
72
77
|
}
|
|
73
78
|
getLengthSq() {
|
|
74
|
-
return this.x **
|
|
79
|
+
return this.x ** squareExp + this.y ** squareExp;
|
|
75
80
|
}
|
|
76
81
|
mult(n) {
|
|
77
82
|
return Vector3d.create(this.x * n, this.y * n, this.z * n);
|
|
@@ -82,19 +87,19 @@ class Vector3d {
|
|
|
82
87
|
this.z *= n;
|
|
83
88
|
}
|
|
84
89
|
normalize() {
|
|
85
|
-
const length = this.length;
|
|
86
|
-
if (length !=
|
|
87
|
-
this.multTo(
|
|
90
|
+
const length = this.length, noLength = 0;
|
|
91
|
+
if (length != noLength) {
|
|
92
|
+
this.multTo(inverseFactorNumerator / length);
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
rotate(angle) {
|
|
91
|
-
return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle),
|
|
96
|
+
return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle), origin.z);
|
|
92
97
|
}
|
|
93
98
|
setTo(c) {
|
|
94
99
|
this.x = c.x;
|
|
95
100
|
this.y = c.y;
|
|
96
101
|
const v3d = c;
|
|
97
|
-
this.z = v3d.z ? v3d.z :
|
|
102
|
+
this.z = v3d.z ? v3d.z : origin.z;
|
|
98
103
|
}
|
|
99
104
|
sub(v) {
|
|
100
105
|
return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v.z);
|
|
@@ -18,7 +18,7 @@ class BackgroundMask {
|
|
|
18
18
|
}
|
|
19
19
|
if (data.cover !== undefined) {
|
|
20
20
|
const cover = data.cover, color = ((0, Utils_js_1.isString)(data.cover) ? { color: data.cover } : data.cover);
|
|
21
|
-
this.cover.load(cover.color !== undefined ? cover : { color: color });
|
|
21
|
+
this.cover.load(cover.color !== undefined || cover.image !== undefined ? cover : { color: color });
|
|
22
22
|
}
|
|
23
23
|
if (data.enable !== undefined) {
|
|
24
24
|
this.enable = data.enable;
|
|
@@ -4,8 +4,6 @@ exports.BackgroundMaskCover = void 0;
|
|
|
4
4
|
const OptionsColor_js_1 = require("../OptionsColor.js");
|
|
5
5
|
class BackgroundMaskCover {
|
|
6
6
|
constructor() {
|
|
7
|
-
this.color = new OptionsColor_js_1.OptionsColor();
|
|
8
|
-
this.color.value = "#fff";
|
|
9
7
|
this.opacity = 1;
|
|
10
8
|
}
|
|
11
9
|
load(data) {
|
|
@@ -15,6 +13,9 @@ class BackgroundMaskCover {
|
|
|
15
13
|
if (data.color !== undefined) {
|
|
16
14
|
this.color = OptionsColor_js_1.OptionsColor.create(this.color, data.color);
|
|
17
15
|
}
|
|
16
|
+
if (data.image !== undefined) {
|
|
17
|
+
this.image = data.image;
|
|
18
|
+
}
|
|
18
19
|
if (data.opacity !== undefined) {
|
|
19
20
|
this.opacity = data.opacity;
|
|
20
21
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ManualParticle = void 0;
|
|
4
4
|
const Utils_js_1 = require("../../Utils/Utils.js");
|
|
5
|
+
const defaultPosition = 50;
|
|
5
6
|
class ManualParticle {
|
|
6
7
|
load(data) {
|
|
7
8
|
if (!data) {
|
|
@@ -9,8 +10,8 @@ class ManualParticle {
|
|
|
9
10
|
}
|
|
10
11
|
if (data.position) {
|
|
11
12
|
this.position = {
|
|
12
|
-
x: data.position.x ??
|
|
13
|
-
y: data.position.y ??
|
|
13
|
+
x: data.position.x ?? defaultPosition,
|
|
14
|
+
y: data.position.y ?? defaultPosition,
|
|
14
15
|
mode: data.position.mode ?? "percent",
|
|
15
16
|
};
|
|
16
17
|
}
|
package/cjs/Utils/CanvasUtils.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.alterHsl = exports.drawParticlePlugin = exports.drawPlugin = exports.drawShapeAfterDraw = exports.drawShape = exports.drawEffect = exports.drawParticle = exports.clear = exports.paintImage = exports.paintBase = exports.drawLine = void 0;
|
|
4
4
|
const ColorUtils_js_1 = require("./ColorUtils.js");
|
|
5
|
+
const origin = { x: 0, y: 0 };
|
|
5
6
|
function drawLine(context, begin, end) {
|
|
6
7
|
context.beginPath();
|
|
7
8
|
context.moveTo(begin.x, begin.y);
|
|
@@ -11,7 +12,7 @@ function drawLine(context, begin, end) {
|
|
|
11
12
|
exports.drawLine = drawLine;
|
|
12
13
|
function paintBase(context, dimension, baseColor) {
|
|
13
14
|
context.fillStyle = baseColor ?? "rgba(0,0,0,0)";
|
|
14
|
-
context.fillRect(
|
|
15
|
+
context.fillRect(origin.x, origin.y, dimension.width, dimension.height);
|
|
15
16
|
}
|
|
16
17
|
exports.paintBase = paintBase;
|
|
17
18
|
function paintImage(context, dimension, image, opacity) {
|
|
@@ -19,24 +20,23 @@ function paintImage(context, dimension, image, opacity) {
|
|
|
19
20
|
return;
|
|
20
21
|
}
|
|
21
22
|
context.globalAlpha = opacity;
|
|
22
|
-
context.drawImage(image,
|
|
23
|
+
context.drawImage(image, origin.x, origin.y, dimension.width, dimension.height);
|
|
23
24
|
context.globalAlpha = 1;
|
|
24
25
|
}
|
|
25
26
|
exports.paintImage = paintImage;
|
|
26
27
|
function clear(context, dimension) {
|
|
27
|
-
context.clearRect(
|
|
28
|
+
context.clearRect(origin.x, origin.y, dimension.width, dimension.height);
|
|
28
29
|
}
|
|
29
30
|
exports.clear = clear;
|
|
30
|
-
function drawParticle(data) {
|
|
31
|
-
const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data
|
|
32
|
-
const pos = particle.getPosition(), angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : 0), rotateData = {
|
|
31
|
+
async function drawParticle(data) {
|
|
32
|
+
const { container, context, particle, delta, colorStyles, backgroundMask, composite, radius, opacity, shadow, transform, } = data, pos = particle.getPosition(), defaultAngle = 0, angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : defaultAngle), rotateData = {
|
|
33
33
|
sin: Math.sin(angle),
|
|
34
34
|
cos: Math.cos(angle),
|
|
35
|
-
}, transformData = {
|
|
36
|
-
a: rotateData.cos * (transform.a ??
|
|
37
|
-
b: rotateData.sin * (transform.b ??
|
|
38
|
-
c: -rotateData.sin * (transform.c ??
|
|
39
|
-
d: rotateData.cos * (transform.d ??
|
|
35
|
+
}, defaultTransformFactor = 1, transformData = {
|
|
36
|
+
a: rotateData.cos * (transform.a ?? defaultTransformFactor),
|
|
37
|
+
b: rotateData.sin * (transform.b ?? defaultTransformFactor),
|
|
38
|
+
c: -rotateData.sin * (transform.c ?? defaultTransformFactor),
|
|
39
|
+
d: rotateData.cos * (transform.d ?? defaultTransformFactor),
|
|
40
40
|
};
|
|
41
41
|
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
|
42
42
|
if (backgroundMask) {
|
|
@@ -52,30 +52,29 @@ function drawParticle(data) {
|
|
|
52
52
|
if (colorStyles.fill) {
|
|
53
53
|
context.fillStyle = colorStyles.fill;
|
|
54
54
|
}
|
|
55
|
-
const strokeWidth = particle.strokeWidth ??
|
|
55
|
+
const minStrokeWidth = 0, strokeWidth = particle.strokeWidth ?? minStrokeWidth;
|
|
56
56
|
context.lineWidth = strokeWidth;
|
|
57
57
|
if (colorStyles.stroke) {
|
|
58
58
|
context.strokeStyle = colorStyles.stroke;
|
|
59
59
|
}
|
|
60
|
-
const drawData = {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
drawEffect(drawData);
|
|
60
|
+
const drawData = {
|
|
61
|
+
container,
|
|
62
|
+
context,
|
|
63
|
+
particle,
|
|
64
|
+
radius,
|
|
65
|
+
opacity,
|
|
66
|
+
delta,
|
|
67
|
+
transformData,
|
|
68
|
+
strokeWidth,
|
|
69
|
+
};
|
|
70
|
+
await drawShape(drawData);
|
|
71
|
+
await drawShapeAfterDraw(drawData);
|
|
72
|
+
await drawEffect(drawData);
|
|
74
73
|
context.globalCompositeOperation = "source-over";
|
|
75
|
-
context.
|
|
74
|
+
context.resetTransform();
|
|
76
75
|
}
|
|
77
76
|
exports.drawParticle = drawParticle;
|
|
78
|
-
function drawEffect(data) {
|
|
77
|
+
async function drawEffect(data) {
|
|
79
78
|
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
80
79
|
if (!particle.effect) {
|
|
81
80
|
return;
|
|
@@ -84,7 +83,7 @@ function drawEffect(data) {
|
|
|
84
83
|
if (!drawer) {
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
|
-
drawer.draw({
|
|
86
|
+
await drawer.draw({
|
|
88
87
|
context,
|
|
89
88
|
particle,
|
|
90
89
|
radius,
|
|
@@ -95,8 +94,8 @@ function drawEffect(data) {
|
|
|
95
94
|
});
|
|
96
95
|
}
|
|
97
96
|
exports.drawEffect = drawEffect;
|
|
98
|
-
function drawShape(data) {
|
|
99
|
-
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
97
|
+
async function drawShape(data) {
|
|
98
|
+
const { container, context, particle, radius, opacity, delta, strokeWidth, transformData } = data, minStrokeWidth = 0;
|
|
100
99
|
if (!particle.shape) {
|
|
101
100
|
return;
|
|
102
101
|
}
|
|
@@ -104,7 +103,8 @@ function drawShape(data) {
|
|
|
104
103
|
if (!drawer) {
|
|
105
104
|
return;
|
|
106
105
|
}
|
|
107
|
-
|
|
106
|
+
context.beginPath();
|
|
107
|
+
await drawer.draw({
|
|
108
108
|
context,
|
|
109
109
|
particle,
|
|
110
110
|
radius,
|
|
@@ -113,18 +113,27 @@ function drawShape(data) {
|
|
|
113
113
|
pixelRatio: container.retina.pixelRatio,
|
|
114
114
|
transformData: { ...transformData },
|
|
115
115
|
});
|
|
116
|
+
if (particle.shapeClose) {
|
|
117
|
+
context.closePath();
|
|
118
|
+
}
|
|
119
|
+
if (strokeWidth > minStrokeWidth) {
|
|
120
|
+
context.stroke();
|
|
121
|
+
}
|
|
122
|
+
if (particle.shapeFill) {
|
|
123
|
+
context.fill();
|
|
124
|
+
}
|
|
116
125
|
}
|
|
117
126
|
exports.drawShape = drawShape;
|
|
118
|
-
function drawShapeAfterDraw(data) {
|
|
127
|
+
async function drawShapeAfterDraw(data) {
|
|
119
128
|
const { container, context, particle, radius, opacity, delta, transformData } = data;
|
|
120
129
|
if (!particle.shape) {
|
|
121
130
|
return;
|
|
122
131
|
}
|
|
123
132
|
const drawer = container.shapeDrawers.get(particle.shape);
|
|
124
|
-
if (!drawer
|
|
133
|
+
if (!drawer?.afterDraw) {
|
|
125
134
|
return;
|
|
126
135
|
}
|
|
127
|
-
drawer.afterDraw({
|
|
136
|
+
await drawer.afterDraw({
|
|
128
137
|
context,
|
|
129
138
|
particle,
|
|
130
139
|
radius,
|
|
@@ -135,25 +144,26 @@ function drawShapeAfterDraw(data) {
|
|
|
135
144
|
});
|
|
136
145
|
}
|
|
137
146
|
exports.drawShapeAfterDraw = drawShapeAfterDraw;
|
|
138
|
-
function drawPlugin(context, plugin, delta) {
|
|
147
|
+
async function drawPlugin(context, plugin, delta) {
|
|
139
148
|
if (!plugin.draw) {
|
|
140
149
|
return;
|
|
141
150
|
}
|
|
142
|
-
plugin.draw(context, delta);
|
|
151
|
+
await plugin.draw(context, delta);
|
|
143
152
|
}
|
|
144
153
|
exports.drawPlugin = drawPlugin;
|
|
145
|
-
function drawParticlePlugin(context, plugin, particle, delta) {
|
|
154
|
+
async function drawParticlePlugin(context, plugin, particle, delta) {
|
|
146
155
|
if (!plugin.drawParticle) {
|
|
147
156
|
return;
|
|
148
157
|
}
|
|
149
|
-
plugin.drawParticle(context, particle, delta);
|
|
158
|
+
await plugin.drawParticle(context, particle, delta);
|
|
150
159
|
}
|
|
151
160
|
exports.drawParticlePlugin = drawParticlePlugin;
|
|
152
161
|
function alterHsl(color, type, value) {
|
|
162
|
+
const lFactor = 1;
|
|
153
163
|
return {
|
|
154
164
|
h: color.h,
|
|
155
165
|
s: color.s,
|
|
156
|
-
l: color.l + (type === "darken" ? -
|
|
166
|
+
l: color.l + (type === "darken" ? -lFactor : lFactor) * value,
|
|
157
167
|
};
|
|
158
168
|
}
|
|
159
169
|
exports.alterHsl = alterHsl;
|