@tsparticles/plugin-emitters 3.0.0-beta.3 → 3.0.0-beta.5

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 (80) hide show
  1. package/browser/EmitterInstance.js +133 -80
  2. package/browser/EmitterShapeBase.js +12 -0
  3. package/browser/Emitters.js +7 -6
  4. package/browser/Options/Classes/Emitter.js +3 -4
  5. package/browser/Options/Classes/EmitterShape.js +21 -0
  6. package/browser/Options/Classes/EmitterShapeReplace.js +17 -0
  7. package/browser/Options/Interfaces/IEmitterShape.js +1 -0
  8. package/browser/Options/Interfaces/IEmitterShapeReplace.js +1 -0
  9. package/browser/ShapeManager.js +8 -8
  10. package/browser/index.js +7 -8
  11. package/cjs/EmitterInstance.js +133 -80
  12. package/cjs/EmitterShapeBase.js +16 -0
  13. package/cjs/Emitters.js +7 -6
  14. package/cjs/IRandomPositionData.js +2 -0
  15. package/cjs/Options/Classes/Emitter.js +3 -4
  16. package/cjs/Options/Classes/EmitterShape.js +25 -0
  17. package/cjs/Options/Classes/EmitterShapeReplace.js +21 -0
  18. package/cjs/Options/Interfaces/IEmitterShape.js +2 -0
  19. package/cjs/Options/Interfaces/IEmitterShapeReplace.js +2 -0
  20. package/cjs/ShapeManager.js +8 -8
  21. package/cjs/index.js +7 -8
  22. package/esm/EmitterInstance.js +133 -80
  23. package/esm/EmitterShapeBase.js +12 -0
  24. package/esm/Emitters.js +7 -6
  25. package/esm/IEmitterShapeGenerator.js +1 -0
  26. package/esm/IRandomPositionData.js +1 -0
  27. package/esm/Options/Classes/Emitter.js +3 -4
  28. package/esm/Options/Classes/EmitterShape.js +21 -0
  29. package/esm/Options/Classes/EmitterShapeReplace.js +17 -0
  30. package/esm/Options/Interfaces/IEmitterShape.js +1 -0
  31. package/esm/Options/Interfaces/IEmitterShapeReplace.js +1 -0
  32. package/esm/ShapeManager.js +8 -8
  33. package/esm/index.js +7 -8
  34. package/package.json +3 -3
  35. package/report.html +4 -22
  36. package/tsparticles.plugin.emitters.js +208 -176
  37. package/tsparticles.plugin.emitters.min.js +1 -1
  38. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -1
  39. package/types/EmitterContainer.d.ts +1 -1
  40. package/types/EmitterInstance.d.ts +11 -9
  41. package/types/EmitterShapeBase.d.ts +13 -0
  42. package/types/Emitters.d.ts +2 -2
  43. package/types/EmittersEngine.d.ts +2 -2
  44. package/types/IEmitterShape.d.ts +4 -1
  45. package/types/IEmitterShapeGenerator.d.ts +5 -0
  46. package/types/IRandomPositionData.d.ts +6 -0
  47. package/types/Options/Classes/Emitter.d.ts +2 -2
  48. package/types/Options/Classes/EmitterShape.d.ts +10 -0
  49. package/types/Options/Classes/EmitterShapeReplace.d.ts +8 -0
  50. package/types/Options/Interfaces/IEmitter.d.ts +2 -2
  51. package/types/Options/Interfaces/IEmitterShape.d.ts +6 -0
  52. package/types/Options/Interfaces/IEmitterShapeReplace.d.ts +4 -0
  53. package/types/ShapeManager.d.ts +4 -4
  54. package/types/index.d.ts +4 -1
  55. package/umd/EmitterInstance.js +133 -80
  56. package/umd/EmitterShapeBase.js +26 -0
  57. package/umd/Emitters.js +7 -6
  58. package/umd/IRandomPositionData.js +12 -0
  59. package/umd/Options/Classes/Emitter.js +4 -5
  60. package/umd/Options/Classes/EmitterShape.js +35 -0
  61. package/umd/Options/Classes/EmitterShapeReplace.js +31 -0
  62. package/umd/Options/Interfaces/IEmitterShape.js +12 -0
  63. package/umd/Options/Interfaces/IEmitterShapeReplace.js +12 -0
  64. package/umd/ShapeManager.js +8 -8
  65. package/umd/index.js +8 -9
  66. package/browser/Shapes/Circle/CircleShape.js +0 -24
  67. package/browser/Shapes/Square/SquareShape.js +0 -40
  68. package/cjs/Shapes/Circle/CircleShape.js +0 -28
  69. package/cjs/Shapes/Square/SquareShape.js +0 -44
  70. package/esm/Shapes/Circle/CircleShape.js +0 -24
  71. package/esm/Shapes/Square/SquareShape.js +0 -40
  72. package/types/Enums/EmitterShapeType.d.ts +0 -6
  73. package/types/Shapes/Circle/CircleShape.d.ts +0 -5
  74. package/types/Shapes/Square/SquareShape.d.ts +0 -5
  75. package/umd/Shapes/Circle/CircleShape.js +0 -38
  76. package/umd/Shapes/Square/SquareShape.js +0 -54
  77. /package/browser/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
  78. /package/{esm/Enums/EmitterShapeType.js → browser/IRandomPositionData.js} +0 -0
  79. /package/cjs/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
  80. /package/umd/{Enums/EmitterShapeType.js → IEmitterShapeGenerator.js} +0 -0
@@ -10,21 +10,21 @@
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ShapeManager = void 0;
13
- const shapes = new Map();
13
+ const shapeGeneratorss = new Map();
14
14
  class ShapeManager {
15
15
  constructor(engine) {
16
16
  this._engine = engine;
17
17
  }
18
- addShape(name, drawer) {
19
- if (!this.getShape(name)) {
20
- shapes.set(name, drawer);
18
+ addShapeGenerator(name, generator) {
19
+ if (!this.getShapeGenerator(name)) {
20
+ shapeGeneratorss.set(name, generator);
21
21
  }
22
22
  }
23
- getShape(name) {
24
- return shapes.get(name);
23
+ getShapeGenerator(name) {
24
+ return shapeGeneratorss.get(name);
25
25
  }
26
- getSupportedShapes() {
27
- return shapes.keys();
26
+ getSupportedShapeGenerators() {
27
+ return shapeGeneratorss.keys();
28
28
  }
29
29
  }
30
30
  exports.ShapeManager = ShapeManager;
package/umd/index.js CHANGED
@@ -18,18 +18,16 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
18
18
  if (v !== undefined) module.exports = v;
19
19
  }
20
20
  else if (typeof define === "function" && define.amd) {
21
- define(["require", "exports", "@tsparticles/engine", "./Shapes/Circle/CircleShape.js", "./Options/Classes/Emitter.js", "./Emitters.js", "./ShapeManager.js", "./Shapes/Square/SquareShape.js", "./EmitterContainer.js", "./EmittersEngine.js", "./Enums/EmitterClickMode.js", "./Enums/EmitterShapeType.js"], factory);
21
+ define(["require", "exports", "@tsparticles/engine", "./Options/Classes/Emitter.js", "./Emitters.js", "./ShapeManager.js", "./EmitterContainer.js", "./EmitterShapeBase.js", "./EmittersEngine.js", "./IEmitterShape.js", "./IEmitterShapeGenerator.js", "./Enums/EmitterClickMode.js", "./IRandomPositionData.js"], factory);
22
22
  }
23
23
  })(function (require, exports) {
24
24
  "use strict";
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.loadEmittersPlugin = void 0;
27
27
  const engine_1 = require("@tsparticles/engine");
28
- const CircleShape_js_1 = require("./Shapes/Circle/CircleShape.js");
29
28
  const Emitter_js_1 = require("./Options/Classes/Emitter.js");
30
29
  const Emitters_js_1 = require("./Emitters.js");
31
30
  const ShapeManager_js_1 = require("./ShapeManager.js");
32
- const SquareShape_js_1 = require("./Shapes/Square/SquareShape.js");
33
31
  class EmittersPlugin {
34
32
  constructor(engine) {
35
33
  this._engine = engine;
@@ -120,19 +118,20 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
120
118
  if (!engine.emitterShapeManager) {
121
119
  engine.emitterShapeManager = new ShapeManager_js_1.ShapeManager(engine);
122
120
  }
123
- if (!engine.addEmitterShape) {
124
- engine.addEmitterShape = (name, shape) => {
125
- engine.emitterShapeManager?.addShape(name, shape);
121
+ if (!engine.addEmitterShapeGenerator) {
122
+ engine.addEmitterShapeGenerator = (name, generator) => {
123
+ engine.emitterShapeManager?.addShapeGenerator(name, generator);
126
124
  };
127
125
  }
128
126
  const plugin = new EmittersPlugin(engine);
129
127
  await engine.addPlugin(plugin, refresh);
130
- engine.addEmitterShape("circle", new CircleShape_js_1.CircleShape());
131
- engine.addEmitterShape("square", new SquareShape_js_1.SquareShape());
132
128
  }
133
129
  exports.loadEmittersPlugin = loadEmittersPlugin;
134
130
  __exportStar(require("./EmitterContainer.js"), exports);
131
+ __exportStar(require("./EmitterShapeBase.js"), exports);
135
132
  __exportStar(require("./EmittersEngine.js"), exports);
133
+ __exportStar(require("./IEmitterShape.js"), exports);
134
+ __exportStar(require("./IEmitterShapeGenerator.js"), exports);
136
135
  __exportStar(require("./Enums/EmitterClickMode.js"), exports);
137
- __exportStar(require("./Enums/EmitterShapeType.js"), exports);
136
+ __exportStar(require("./IRandomPositionData.js"), exports);
138
137
  });
@@ -1,24 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CircleShape = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- class CircleShape {
6
- randomPosition(position, size, fill) {
7
- const generateTheta = (x, y) => {
8
- const u = (0, engine_1.getRandom)() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = (0, engine_1.getRandom)();
9
- if (v < 0.25) {
10
- return theta;
11
- }
12
- else if (v < 0.5) {
13
- return Math.PI - theta;
14
- }
15
- else if (v < 0.75) {
16
- return Math.PI + theta;
17
- }
18
- else {
19
- return -theta;
20
- }
21
- }, 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((0, engine_1.getRandom)()) : maxRadius;
22
- return {
23
- x: position.x + randomRadius * Math.cos(randomTheta),
24
- y: position.y + randomRadius * Math.sin(randomTheta),
25
- };
26
- }
27
- }
28
- exports.CircleShape = CircleShape;
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SquareShape = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- function randomSquareCoordinate(position, offset) {
6
- return position + offset * ((0, engine_1.getRandom)() - 0.5);
7
- }
8
- class SquareShape {
9
- randomPosition(position, size, fill) {
10
- if (fill) {
11
- return {
12
- x: randomSquareCoordinate(position.x, size.width),
13
- y: randomSquareCoordinate(position.y, size.height),
14
- };
15
- }
16
- else {
17
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor((0, engine_1.getRandom)() * 4), v = ((0, engine_1.getRandom)() - 0.5) * 2;
18
- switch (side) {
19
- case 0:
20
- return {
21
- x: position.x + v * halfW,
22
- y: position.y - halfH,
23
- };
24
- case 1:
25
- return {
26
- x: position.x - halfW,
27
- y: position.y + v * halfH,
28
- };
29
- case 2:
30
- return {
31
- x: position.x + v * halfW,
32
- y: position.y + halfH,
33
- };
34
- case 3:
35
- default:
36
- return {
37
- x: position.x + halfW,
38
- y: position.y + v * halfH,
39
- };
40
- }
41
- }
42
- }
43
- }
44
- exports.SquareShape = SquareShape;
@@ -1,24 +0,0 @@
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
- }
@@ -1,40 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
1
- export declare const enum EmitterShapeType {
2
- circle = "circle",
3
- polygon = "polygon",
4
- square = "square",
5
- star = "star"
6
- }
@@ -1,5 +0,0 @@
1
- import { type ICoordinates, type IDimension } from "@tsparticles/engine";
2
- import type { IEmitterShape } from "../../IEmitterShape.js";
3
- export declare class CircleShape implements IEmitterShape {
4
- randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
5
- }
@@ -1,5 +0,0 @@
1
- import { type ICoordinates, type IDimension } from "@tsparticles/engine";
2
- import type { IEmitterShape } from "../../IEmitterShape.js";
3
- export declare class SquareShape implements IEmitterShape {
4
- randomPosition(position: ICoordinates, size: IDimension, fill: boolean): ICoordinates;
5
- }
@@ -1,38 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.CircleShape = void 0;
13
- const engine_1 = require("@tsparticles/engine");
14
- class CircleShape {
15
- randomPosition(position, size, fill) {
16
- const generateTheta = (x, y) => {
17
- const u = (0, engine_1.getRandom)() / 4.0, theta = Math.atan((y / x) * Math.tan(2 * Math.PI * u)), v = (0, engine_1.getRandom)();
18
- if (v < 0.25) {
19
- return theta;
20
- }
21
- else if (v < 0.5) {
22
- return Math.PI - theta;
23
- }
24
- else if (v < 0.75) {
25
- return Math.PI + theta;
26
- }
27
- else {
28
- return -theta;
29
- }
30
- }, 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((0, engine_1.getRandom)()) : maxRadius;
31
- return {
32
- x: position.x + randomRadius * Math.cos(randomTheta),
33
- y: position.y + randomRadius * Math.sin(randomTheta),
34
- };
35
- }
36
- }
37
- exports.CircleShape = CircleShape;
38
- });
@@ -1,54 +0,0 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SquareShape = void 0;
13
- const engine_1 = require("@tsparticles/engine");
14
- function randomSquareCoordinate(position, offset) {
15
- return position + offset * ((0, engine_1.getRandom)() - 0.5);
16
- }
17
- class SquareShape {
18
- randomPosition(position, size, fill) {
19
- if (fill) {
20
- return {
21
- x: randomSquareCoordinate(position.x, size.width),
22
- y: randomSquareCoordinate(position.y, size.height),
23
- };
24
- }
25
- else {
26
- const halfW = size.width / 2, halfH = size.height / 2, side = Math.floor((0, engine_1.getRandom)() * 4), v = ((0, engine_1.getRandom)() - 0.5) * 2;
27
- switch (side) {
28
- case 0:
29
- return {
30
- x: position.x + v * halfW,
31
- y: position.y - halfH,
32
- };
33
- case 1:
34
- return {
35
- x: position.x - halfW,
36
- y: position.y + v * halfH,
37
- };
38
- case 2:
39
- return {
40
- x: position.x + v * halfW,
41
- y: position.y + halfH,
42
- };
43
- case 3:
44
- default:
45
- return {
46
- x: position.x + halfW,
47
- y: position.y + v * halfH,
48
- };
49
- }
50
- }
51
- }
52
- }
53
- exports.SquareShape = SquareShape;
54
- });