@tsparticles/plugin-emitters 3.0.0-alpha.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.
Files changed (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/EmitterContainer.js +1 -0
  4. package/browser/EmitterInstance.js +257 -0
  5. package/browser/Emitters.js +119 -0
  6. package/browser/EmittersEngine.js +1 -0
  7. package/browser/Enums/EmitterClickMode.js +1 -0
  8. package/browser/Enums/EmitterShapeType.js +1 -0
  9. package/browser/IEmitterShape.js +1 -0
  10. package/browser/Options/Classes/Emitter.js +62 -0
  11. package/browser/Options/Classes/EmitterLife.js +22 -0
  12. package/browser/Options/Classes/EmitterRate.js +18 -0
  13. package/browser/Options/Classes/EmitterSize.js +21 -0
  14. package/browser/Options/Interfaces/IEmitter.js +1 -0
  15. package/browser/Options/Interfaces/IEmitterLife.js +1 -0
  16. package/browser/Options/Interfaces/IEmitterRate.js +1 -0
  17. package/browser/Options/Interfaces/IEmitterSize.js +1 -0
  18. package/browser/ShapeManager.js +17 -0
  19. package/browser/Shapes/Circle/CircleShape.js +24 -0
  20. package/browser/Shapes/Square/SquareShape.js +40 -0
  21. package/browser/index.js +113 -0
  22. package/browser/types.js +1 -0
  23. package/cjs/EmitterContainer.js +2 -0
  24. package/cjs/EmitterInstance.js +261 -0
  25. package/cjs/Emitters.js +134 -0
  26. package/cjs/EmittersEngine.js +2 -0
  27. package/cjs/Enums/EmitterClickMode.js +2 -0
  28. package/cjs/Enums/EmitterShapeType.js +2 -0
  29. package/cjs/IEmitterShape.js +2 -0
  30. package/cjs/Options/Classes/Emitter.js +66 -0
  31. package/cjs/Options/Classes/EmitterLife.js +26 -0
  32. package/cjs/Options/Classes/EmitterRate.js +22 -0
  33. package/cjs/Options/Classes/EmitterSize.js +25 -0
  34. package/cjs/Options/Interfaces/IEmitter.js +2 -0
  35. package/cjs/Options/Interfaces/IEmitterLife.js +2 -0
  36. package/cjs/Options/Interfaces/IEmitterRate.js +2 -0
  37. package/cjs/Options/Interfaces/IEmitterSize.js +2 -0
  38. package/cjs/ShapeManager.js +21 -0
  39. package/cjs/Shapes/Circle/CircleShape.js +28 -0
  40. package/cjs/Shapes/Square/SquareShape.js +44 -0
  41. package/cjs/index.js +142 -0
  42. package/cjs/types.js +2 -0
  43. package/esm/EmitterContainer.js +1 -0
  44. package/esm/EmitterInstance.js +257 -0
  45. package/esm/Emitters.js +119 -0
  46. package/esm/EmittersEngine.js +1 -0
  47. package/esm/Enums/EmitterClickMode.js +1 -0
  48. package/esm/Enums/EmitterShapeType.js +1 -0
  49. package/esm/IEmitterShape.js +1 -0
  50. package/esm/Options/Classes/Emitter.js +62 -0
  51. package/esm/Options/Classes/EmitterLife.js +22 -0
  52. package/esm/Options/Classes/EmitterRate.js +18 -0
  53. package/esm/Options/Classes/EmitterSize.js +21 -0
  54. package/esm/Options/Interfaces/IEmitter.js +1 -0
  55. package/esm/Options/Interfaces/IEmitterLife.js +1 -0
  56. package/esm/Options/Interfaces/IEmitterRate.js +1 -0
  57. package/esm/Options/Interfaces/IEmitterSize.js +1 -0
  58. package/esm/ShapeManager.js +17 -0
  59. package/esm/Shapes/Circle/CircleShape.js +24 -0
  60. package/esm/Shapes/Square/SquareShape.js +40 -0
  61. package/esm/index.js +113 -0
  62. package/esm/types.js +1 -0
  63. package/package.json +81 -0
  64. package/report.html +39 -0
  65. package/tsparticles.plugin.emitters.js +794 -0
  66. package/tsparticles.plugin.emitters.min.js +2 -0
  67. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +8 -0
  68. package/types/EmitterContainer.d.ts +12 -0
  69. package/types/EmitterInstance.d.ts +46 -0
  70. package/types/Emitters.d.ts +24 -0
  71. package/types/EmittersEngine.d.ts +7 -0
  72. package/types/Enums/EmitterClickMode.d.ts +3 -0
  73. package/types/Enums/EmitterShapeType.d.ts +4 -0
  74. package/types/IEmitterShape.d.ts +4 -0
  75. package/types/Options/Classes/Emitter.d.ts +24 -0
  76. package/types/Options/Classes/EmitterLife.d.ts +10 -0
  77. package/types/Options/Classes/EmitterRate.d.ts +8 -0
  78. package/types/Options/Classes/EmitterSize.d.ts +10 -0
  79. package/types/Options/Interfaces/IEmitter.d.ts +20 -0
  80. package/types/Options/Interfaces/IEmitterLife.d.ts +6 -0
  81. package/types/Options/Interfaces/IEmitterRate.d.ts +5 -0
  82. package/types/Options/Interfaces/IEmitterSize.d.ts +4 -0
  83. package/types/ShapeManager.d.ts +9 -0
  84. package/types/Shapes/Circle/CircleShape.d.ts +5 -0
  85. package/types/Shapes/Square/SquareShape.d.ts +5 -0
  86. package/types/index.d.ts +6 -0
  87. package/types/types.d.ts +31 -0
  88. package/umd/EmitterContainer.js +12 -0
  89. package/umd/EmitterInstance.js +271 -0
  90. package/umd/Emitters.js +133 -0
  91. package/umd/EmittersEngine.js +12 -0
  92. package/umd/Enums/EmitterClickMode.js +12 -0
  93. package/umd/Enums/EmitterShapeType.js +12 -0
  94. package/umd/IEmitterShape.js +12 -0
  95. package/umd/Options/Classes/Emitter.js +76 -0
  96. package/umd/Options/Classes/EmitterLife.js +36 -0
  97. package/umd/Options/Classes/EmitterRate.js +32 -0
  98. package/umd/Options/Classes/EmitterSize.js +35 -0
  99. package/umd/Options/Interfaces/IEmitter.js +12 -0
  100. package/umd/Options/Interfaces/IEmitterLife.js +12 -0
  101. package/umd/Options/Interfaces/IEmitterRate.js +12 -0
  102. package/umd/Options/Interfaces/IEmitterSize.js +12 -0
  103. package/umd/ShapeManager.js +31 -0
  104. package/umd/Shapes/Circle/CircleShape.js +38 -0
  105. package/umd/Shapes/Square/SquareShape.js +54 -0
  106. package/umd/index.js +141 -0
  107. package/umd/types.js +12 -0
@@ -0,0 +1,62 @@
1
+ import { AnimatableColor, deepExtend, executeOnSingleOrMultiple, setRangeValue } from "@tsparticles/engine";
2
+ import { EmitterLife } from "./EmitterLife";
3
+ import { EmitterRate } from "./EmitterRate";
4
+ import { EmitterSize } from "./EmitterSize";
5
+ export class Emitter {
6
+ constructor() {
7
+ this.autoPlay = true;
8
+ this.fill = true;
9
+ this.life = new EmitterLife();
10
+ this.rate = new EmitterRate();
11
+ this.shape = "square";
12
+ this.startCount = 0;
13
+ }
14
+ load(data) {
15
+ if (data === undefined) {
16
+ return;
17
+ }
18
+ if (data.autoPlay !== undefined) {
19
+ this.autoPlay = data.autoPlay;
20
+ }
21
+ if (data.size !== undefined) {
22
+ if (this.size === undefined) {
23
+ this.size = new EmitterSize();
24
+ }
25
+ this.size.load(data.size);
26
+ }
27
+ if (data.direction !== undefined) {
28
+ this.direction = data.direction;
29
+ }
30
+ this.domId = data.domId;
31
+ if (data.fill !== undefined) {
32
+ this.fill = data.fill;
33
+ }
34
+ this.life.load(data.life);
35
+ this.name = data.name;
36
+ this.particles = executeOnSingleOrMultiple(data.particles, (particles) => {
37
+ return deepExtend({}, particles);
38
+ });
39
+ this.rate.load(data.rate);
40
+ if (data.shape !== undefined) {
41
+ this.shape = data.shape;
42
+ }
43
+ if (data.position !== undefined) {
44
+ this.position = {};
45
+ if (data.position.x !== undefined) {
46
+ this.position.x = setRangeValue(data.position.x);
47
+ }
48
+ if (data.position.y !== undefined) {
49
+ this.position.y = setRangeValue(data.position.y);
50
+ }
51
+ }
52
+ if (data.spawnColor !== undefined) {
53
+ if (this.spawnColor === undefined) {
54
+ this.spawnColor = new AnimatableColor();
55
+ }
56
+ this.spawnColor.load(data.spawnColor);
57
+ }
58
+ if (data.startCount !== undefined) {
59
+ this.startCount = data.startCount;
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,22 @@
1
+ export class EmitterLife {
2
+ constructor() {
3
+ this.wait = false;
4
+ }
5
+ load(data) {
6
+ if (data === undefined) {
7
+ return;
8
+ }
9
+ if (data.count !== undefined) {
10
+ this.count = data.count;
11
+ }
12
+ if (data.delay !== undefined) {
13
+ this.delay = data.delay;
14
+ }
15
+ if (data.duration !== undefined) {
16
+ this.duration = data.duration;
17
+ }
18
+ if (data.wait !== undefined) {
19
+ this.wait = data.wait;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,18 @@
1
+ import { setRangeValue } from "@tsparticles/engine";
2
+ export class EmitterRate {
3
+ constructor() {
4
+ this.quantity = 1;
5
+ this.delay = 0.1;
6
+ }
7
+ load(data) {
8
+ if (data === undefined) {
9
+ return;
10
+ }
11
+ if (data.quantity !== undefined) {
12
+ this.quantity = setRangeValue(data.quantity);
13
+ }
14
+ if (data.delay !== undefined) {
15
+ this.delay = setRangeValue(data.delay);
16
+ }
17
+ }
18
+ }
@@ -0,0 +1,21 @@
1
+ export class EmitterSize {
2
+ constructor() {
3
+ this.mode = "percent";
4
+ this.height = 0;
5
+ this.width = 0;
6
+ }
7
+ load(data) {
8
+ if (data === undefined) {
9
+ return;
10
+ }
11
+ if (data.mode !== undefined) {
12
+ this.mode = data.mode;
13
+ }
14
+ if (data.height !== undefined) {
15
+ this.height = data.height;
16
+ }
17
+ if (data.width !== undefined) {
18
+ this.width = data.width;
19
+ }
20
+ }
21
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ const shapes = new Map();
2
+ export class ShapeManager {
3
+ constructor(engine) {
4
+ this._engine = engine;
5
+ }
6
+ addShape(name, drawer) {
7
+ if (!this.getShape(name)) {
8
+ shapes.set(name, drawer);
9
+ }
10
+ }
11
+ getShape(name) {
12
+ return shapes.get(name);
13
+ }
14
+ getSupportedShapes() {
15
+ return shapes.keys();
16
+ }
17
+ }
@@ -0,0 +1,24 @@
1
+ import { getRandom } from "@tsparticles/engine";
2
+ export class CircleShape {
3
+ randomPosition(position, size, fill) {
4
+ const generateTheta = (x, y) => {
5
+ const u = getRandom() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = getRandom();
6
+ if (v < 0.25) {
7
+ return theta;
8
+ }
9
+ else if (v < 0.5) {
10
+ return Math.PI - theta;
11
+ }
12
+ else if (v < 0.75) {
13
+ return Math.PI + theta;
14
+ }
15
+ else {
16
+ return -theta;
17
+ }
18
+ }, radius = (x, y, theta) => (x * y) / Math.sqrt((y * Math.cos(theta)) ** 2 + (x * Math.sin(theta)) ** 2), [a, b] = [size.width / 2, size.height / 2], randomTheta = generateTheta(a, b), maxRadius = radius(a, b, randomTheta), randomRadius = fill ? maxRadius * Math.sqrt(getRandom()) : maxRadius;
19
+ return {
20
+ x: position.x + randomRadius * Math.cos(randomTheta),
21
+ y: position.y + randomRadius * Math.sin(randomTheta),
22
+ };
23
+ }
24
+ }
@@ -0,0 +1,40 @@
1
+ import { getRandom } from "@tsparticles/engine";
2
+ function randomSquareCoordinate(position, offset) {
3
+ return position + offset * (getRandom() - 0.5);
4
+ }
5
+ export class SquareShape {
6
+ randomPosition(position, size, fill) {
7
+ if (fill) {
8
+ return {
9
+ x: randomSquareCoordinate(position.x, size.width),
10
+ y: randomSquareCoordinate(position.y, size.height),
11
+ };
12
+ }
13
+ else {
14
+ const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor(getRandom() * 4), v = (getRandom() - 0.5) * 2;
15
+ switch (side) {
16
+ case 0:
17
+ return {
18
+ x: position.x + v * halfW,
19
+ y: position.y - halfH,
20
+ };
21
+ case 1:
22
+ return {
23
+ x: position.x - halfW,
24
+ y: position.y + v * halfH,
25
+ };
26
+ case 2:
27
+ return {
28
+ x: position.x + v * halfW,
29
+ y: position.y + halfH,
30
+ };
31
+ case 3:
32
+ default:
33
+ return {
34
+ x: position.x + halfW,
35
+ y: position.y + v * halfH,
36
+ };
37
+ }
38
+ }
39
+ }
40
+ }
package/esm/index.js ADDED
@@ -0,0 +1,113 @@
1
+ import { executeOnSingleOrMultiple, isInArray } from "@tsparticles/engine";
2
+ import { CircleShape } from "./Shapes/Circle/CircleShape";
3
+ import { Emitter } from "./Options/Classes/Emitter";
4
+ import { Emitters } from "./Emitters";
5
+ import { ShapeManager } from "./ShapeManager";
6
+ import { SquareShape } from "./Shapes/Square/SquareShape";
7
+ class EmittersPlugin {
8
+ constructor(engine) {
9
+ this._engine = engine;
10
+ this.id = "emitters";
11
+ }
12
+ getPlugin(container) {
13
+ return new Emitters(this._engine, container);
14
+ }
15
+ loadOptions(options, source) {
16
+ var _a, _b, _c, _d, _e, _f;
17
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
18
+ return;
19
+ }
20
+ if (source === null || source === void 0 ? void 0 : source.emitters) {
21
+ options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {
22
+ const tmp = new Emitter();
23
+ tmp.load(emitter);
24
+ return tmp;
25
+ });
26
+ }
27
+ const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
28
+ if (interactivityEmitters) {
29
+ if (interactivityEmitters instanceof Array) {
30
+ options.interactivity.modes.emitters = {
31
+ random: {
32
+ count: 1,
33
+ enable: true,
34
+ },
35
+ value: interactivityEmitters.map((s) => {
36
+ const tmp = new Emitter();
37
+ tmp.load(s);
38
+ return tmp;
39
+ }),
40
+ };
41
+ }
42
+ else {
43
+ const emitterMode = interactivityEmitters;
44
+ if (emitterMode.value !== undefined) {
45
+ if (emitterMode.value instanceof Array) {
46
+ options.interactivity.modes.emitters = {
47
+ random: {
48
+ count: (_c = emitterMode.random.count) !== null && _c !== void 0 ? _c : 1,
49
+ enable: (_d = emitterMode.random.enable) !== null && _d !== void 0 ? _d : false,
50
+ },
51
+ value: emitterMode.value.map((s) => {
52
+ const tmp = new Emitter();
53
+ tmp.load(s);
54
+ return tmp;
55
+ }),
56
+ };
57
+ }
58
+ else {
59
+ const tmp = new Emitter();
60
+ tmp.load(emitterMode.value);
61
+ options.interactivity.modes.emitters = {
62
+ random: {
63
+ count: (_e = emitterMode.random.count) !== null && _e !== void 0 ? _e : 1,
64
+ enable: (_f = emitterMode.random.enable) !== null && _f !== void 0 ? _f : false,
65
+ },
66
+ value: tmp,
67
+ };
68
+ }
69
+ }
70
+ else {
71
+ const emitterOptions = (options.interactivity.modes.emitters = {
72
+ random: {
73
+ count: 1,
74
+ enable: false,
75
+ },
76
+ value: new Emitter(),
77
+ });
78
+ emitterOptions.value.load(interactivityEmitters);
79
+ }
80
+ }
81
+ }
82
+ }
83
+ needsPlugin(options) {
84
+ var _a, _b, _c;
85
+ if (!options) {
86
+ return false;
87
+ }
88
+ const emitters = options.emitters;
89
+ return ((emitters instanceof Array && !!emitters.length) ||
90
+ emitters !== undefined ||
91
+ (!!((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) &&
92
+ isInArray("emitter", options.interactivity.events.onClick.mode)));
93
+ }
94
+ }
95
+ export async function loadEmittersPlugin(engine) {
96
+ if (!engine.emitterShapeManager) {
97
+ engine.emitterShapeManager = new ShapeManager(engine);
98
+ }
99
+ if (!engine.addEmitterShape) {
100
+ engine.addEmitterShape = (name, shape) => {
101
+ var _a;
102
+ (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
103
+ };
104
+ }
105
+ const plugin = new EmittersPlugin(engine);
106
+ await engine.addPlugin(plugin);
107
+ engine.addEmitterShape("circle", new CircleShape());
108
+ engine.addEmitterShape("square", new SquareShape());
109
+ }
110
+ export * from "./EmitterContainer";
111
+ export * from "./EmittersEngine";
112
+ export * from "./Enums/EmitterClickMode";
113
+ export * from "./Enums/EmitterShapeType";
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@tsparticles/plugin-emitters",
3
+ "version": "3.0.0-alpha.0",
4
+ "description": "tsParticles emitters plugin",
5
+ "homepage": "https://particles.js.org",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/matteobruni/tsparticles.git",
9
+ "directory": "plugins/emitters"
10
+ },
11
+ "keywords": [
12
+ "front-end",
13
+ "frontend",
14
+ "tsparticles",
15
+ "particles.js",
16
+ "particlesjs",
17
+ "particles",
18
+ "particle",
19
+ "canvas",
20
+ "jsparticles",
21
+ "xparticles",
22
+ "particles-js",
23
+ "particles-bg",
24
+ "particles-bg-vue",
25
+ "particles-ts",
26
+ "particles.ts",
27
+ "react-particles-js",
28
+ "react-particles.js",
29
+ "react-particles",
30
+ "react",
31
+ "reactjs",
32
+ "vue-particles",
33
+ "ngx-particles",
34
+ "angular-particles",
35
+ "particleground",
36
+ "vue",
37
+ "vuejs",
38
+ "preact",
39
+ "preactjs",
40
+ "jquery",
41
+ "angularjs",
42
+ "angular",
43
+ "typescript",
44
+ "javascript",
45
+ "animation",
46
+ "web",
47
+ "html5",
48
+ "web-design",
49
+ "webdesign",
50
+ "css",
51
+ "html",
52
+ "css3",
53
+ "animated",
54
+ "background",
55
+ "confetti",
56
+ "canvas",
57
+ "fireworks",
58
+ "fireworks-js",
59
+ "confetti-js",
60
+ "confettijs",
61
+ "fireworksjs",
62
+ "canvas-confetti",
63
+ "@tsparticles/plugin"
64
+ ],
65
+ "author": "Matteo Bruni <matteo.bruni@me.com>",
66
+ "license": "MIT",
67
+ "bugs": {
68
+ "url": "https://github.com/matteobruni/tsparticles/issues"
69
+ },
70
+ "main": "cjs/index.js",
71
+ "jsdelivr": "tsparticles.plugin.emitters.min.js",
72
+ "unpkg": "tsparticles.plugin.emitters.min.js",
73
+ "module": "esm/index.js",
74
+ "types": "types/index.d.ts",
75
+ "publishConfig": {
76
+ "access": "public"
77
+ },
78
+ "dependencies": {
79
+ "@tsparticles/engine": "^3.0.0-alpha.0"
80
+ }
81
+ }