@tsparticles/plugin-emitters 3.0.0-alpha.1 → 3.0.0-beta.1

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 (47) hide show
  1. package/README.md +15 -11
  2. package/browser/EmitterInstance.js +101 -113
  3. package/browser/Emitters.js +31 -27
  4. package/browser/Options/Classes/Emitter.js +6 -6
  5. package/browser/Options/Classes/EmitterLife.js +4 -3
  6. package/browser/index.js +23 -26
  7. package/browser/package.json +1 -0
  8. package/cjs/EmitterInstance.js +102 -114
  9. package/cjs/Emitters.js +41 -48
  10. package/cjs/Options/Classes/Emitter.js +8 -8
  11. package/cjs/Options/Classes/EmitterLife.js +4 -3
  12. package/cjs/Shapes/Circle/CircleShape.js +1 -1
  13. package/cjs/index.js +38 -52
  14. package/cjs/package.json +1 -0
  15. package/esm/EmitterInstance.js +101 -113
  16. package/esm/Emitters.js +31 -27
  17. package/esm/Options/Classes/Emitter.js +6 -6
  18. package/esm/Options/Classes/EmitterLife.js +4 -3
  19. package/esm/index.js +23 -26
  20. package/esm/package.json +1 -0
  21. package/package.json +19 -6
  22. package/report.html +4 -4
  23. package/tsparticles.plugin.emitters.js +137 -145
  24. package/tsparticles.plugin.emitters.min.js +1 -1
  25. package/tsparticles.plugin.emitters.min.js.LICENSE.txt +1 -8
  26. package/types/EmitterContainer.d.ts +3 -3
  27. package/types/EmitterInstance.d.ts +12 -12
  28. package/types/Emitters.d.ts +7 -7
  29. package/types/EmittersEngine.d.ts +2 -2
  30. package/types/Enums/EmitterShapeType.d.ts +3 -1
  31. package/types/Options/Classes/Emitter.d.ts +6 -7
  32. package/types/Options/Classes/EmitterLife.d.ts +4 -4
  33. package/types/Options/Classes/EmitterRate.d.ts +2 -2
  34. package/types/Options/Classes/EmitterSize.d.ts +3 -4
  35. package/types/Options/Interfaces/IEmitter.d.ts +4 -4
  36. package/types/Options/Interfaces/IEmitterLife.d.ts +3 -2
  37. package/types/Options/Interfaces/IEmitterSize.d.ts +2 -2
  38. package/types/ShapeManager.d.ts +1 -1
  39. package/types/Shapes/Circle/CircleShape.d.ts +2 -2
  40. package/types/Shapes/Square/SquareShape.d.ts +2 -2
  41. package/types/index.d.ts +6 -6
  42. package/types/types.d.ts +2 -2
  43. package/umd/EmitterInstance.js +103 -115
  44. package/umd/Emitters.js +33 -29
  45. package/umd/Options/Classes/Emitter.js +9 -9
  46. package/umd/Options/Classes/EmitterLife.js +5 -4
  47. package/umd/index.js +32 -35
package/esm/index.js CHANGED
@@ -1,9 +1,9 @@
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";
1
+ import { executeOnSingleOrMultiple, isArray, isInArray, } from "@tsparticles/engine";
2
+ import { CircleShape } from "./Shapes/Circle/CircleShape.js";
3
+ import { Emitter } from "./Options/Classes/Emitter.js";
4
+ import { Emitters } from "./Emitters.js";
5
+ import { ShapeManager } from "./ShapeManager.js";
6
+ import { SquareShape } from "./Shapes/Square/SquareShape.js";
7
7
  class EmittersPlugin {
8
8
  constructor(engine) {
9
9
  this._engine = engine;
@@ -13,20 +13,19 @@ class EmittersPlugin {
13
13
  return new Emitters(this._engine, container);
14
14
  }
15
15
  loadOptions(options, source) {
16
- var _a, _b, _c, _d, _e, _f;
17
16
  if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
18
17
  return;
19
18
  }
20
- if (source === null || source === void 0 ? void 0 : source.emitters) {
19
+ if (source?.emitters) {
21
20
  options.emitters = executeOnSingleOrMultiple(source.emitters, (emitter) => {
22
21
  const tmp = new Emitter();
23
22
  tmp.load(emitter);
24
23
  return tmp;
25
24
  });
26
25
  }
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;
26
+ const interactivityEmitters = source?.interactivity?.modes?.emitters;
28
27
  if (interactivityEmitters) {
29
- if (interactivityEmitters instanceof Array) {
28
+ if (isArray(interactivityEmitters)) {
30
29
  options.interactivity.modes.emitters = {
31
30
  random: {
32
31
  count: 1,
@@ -42,11 +41,11 @@ class EmittersPlugin {
42
41
  else {
43
42
  const emitterMode = interactivityEmitters;
44
43
  if (emitterMode.value !== undefined) {
45
- if (emitterMode.value instanceof Array) {
44
+ if (isArray(emitterMode.value)) {
46
45
  options.interactivity.modes.emitters = {
47
46
  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,
47
+ count: emitterMode.random.count ?? 1,
48
+ enable: emitterMode.random.enable ?? false,
50
49
  },
51
50
  value: emitterMode.value.map((s) => {
52
51
  const tmp = new Emitter();
@@ -60,8 +59,8 @@ class EmittersPlugin {
60
59
  tmp.load(emitterMode.value);
61
60
  options.interactivity.modes.emitters = {
62
61
  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,
62
+ count: emitterMode.random.count ?? 1,
63
+ enable: emitterMode.random.enable ?? false,
65
64
  },
66
65
  value: tmp,
67
66
  };
@@ -81,33 +80,31 @@ class EmittersPlugin {
81
80
  }
82
81
  }
83
82
  needsPlugin(options) {
84
- var _a, _b, _c;
85
83
  if (!options) {
86
84
  return false;
87
85
  }
88
86
  const emitters = options.emitters;
89
- return ((emitters instanceof Array && !!emitters.length) ||
87
+ return ((isArray(emitters) && !!emitters.length) ||
90
88
  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) &&
89
+ (!!options.interactivity?.events?.onClick?.mode &&
92
90
  isInArray("emitter", options.interactivity.events.onClick.mode)));
93
91
  }
94
92
  }
95
- export async function loadEmittersPlugin(engine) {
93
+ export async function loadEmittersPlugin(engine, refresh = true) {
96
94
  if (!engine.emitterShapeManager) {
97
95
  engine.emitterShapeManager = new ShapeManager(engine);
98
96
  }
99
97
  if (!engine.addEmitterShape) {
100
98
  engine.addEmitterShape = (name, shape) => {
101
- var _a;
102
- (_a = engine.emitterShapeManager) === null || _a === void 0 ? void 0 : _a.addShape(name, shape);
99
+ engine.emitterShapeManager?.addShape(name, shape);
103
100
  };
104
101
  }
105
102
  const plugin = new EmittersPlugin(engine);
106
- await engine.addPlugin(plugin);
103
+ await engine.addPlugin(plugin, refresh);
107
104
  engine.addEmitterShape("circle", new CircleShape());
108
105
  engine.addEmitterShape("square", new SquareShape());
109
106
  }
110
- export * from "./EmitterContainer";
111
- export * from "./EmittersEngine";
112
- export * from "./Enums/EmitterClickMode";
113
- export * from "./Enums/EmitterShapeType";
107
+ export * from "./EmitterContainer.js";
108
+ export * from "./EmittersEngine.js";
109
+ export * from "./Enums/EmitterClickMode.js";
110
+ export * from "./Enums/EmitterShapeType.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsparticles/plugin-emitters",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "tsParticles emitters plugin",
5
5
  "homepage": "https://particles.js.org",
6
6
  "repository": {
@@ -67,15 +67,28 @@
67
67
  "bugs": {
68
68
  "url": "https://github.com/matteobruni/tsparticles/issues"
69
69
  },
70
- "main": "cjs/index.js",
70
+ "sideEffects": false,
71
71
  "jsdelivr": "tsparticles.plugin.emitters.min.js",
72
72
  "unpkg": "tsparticles.plugin.emitters.min.js",
73
+ "browser": "browser/index.js",
74
+ "main": "cjs/index.js",
73
75
  "module": "esm/index.js",
74
76
  "types": "types/index.d.ts",
75
- "publishConfig": {
76
- "access": "public"
77
+ "exports": {
78
+ ".": {
79
+ "types": "./types/index.d.ts",
80
+ "browser": "./browser/index.js",
81
+ "import": "./esm/index.js",
82
+ "require": "./cjs/index.js",
83
+ "umd": "./umd/index.js",
84
+ "default": "./cjs/index.js"
85
+ },
86
+ "./package.json": "./package.json"
77
87
  },
78
88
  "dependencies": {
79
- "@tsparticles/engine": "^3.0.0-alpha.1"
89
+ "@tsparticles/engine": "^3.0.0-beta.1"
90
+ },
91
+ "publishConfig": {
92
+ "access": "public"
80
93
  }
81
- }
94
+ }