@tsparticles/fireworks 4.0.0-beta.8 → 4.0.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 (141) hide show
  1. package/README.md +98 -45
  2. package/browser/browser.js +5 -0
  3. package/browser/bundle.js +4 -0
  4. package/browser/fireworks.js +32 -216
  5. package/browser/fireworks.lazy.js +64 -0
  6. package/browser/index.lazy.js +1 -0
  7. package/browser/types.js +1 -0
  8. package/browser/utils.js +195 -0
  9. package/cjs/browser.js +5 -0
  10. package/cjs/bundle.js +4 -0
  11. package/cjs/fireworks.js +32 -216
  12. package/cjs/fireworks.lazy.js +64 -0
  13. package/cjs/index.lazy.js +1 -0
  14. package/cjs/types.js +1 -0
  15. package/cjs/utils.js +195 -0
  16. package/esm/browser.js +5 -0
  17. package/esm/bundle.js +4 -0
  18. package/esm/fireworks.js +32 -216
  19. package/esm/fireworks.lazy.js +64 -0
  20. package/esm/index.lazy.js +1 -0
  21. package/esm/types.js +1 -0
  22. package/esm/utils.js +195 -0
  23. package/package.json +19 -12
  24. package/report.html +4949 -94
  25. package/tsparticles.fireworks.bundle.js +9132 -977
  26. package/tsparticles.fireworks.bundle.min.js +1 -2
  27. package/tsparticles.fireworks.js +395 -467
  28. package/tsparticles.fireworks.min.js +1 -2
  29. package/types/browser.d.ts +1 -0
  30. package/types/fireworks.d.ts +3 -6
  31. package/types/fireworks.lazy.d.ts +17 -0
  32. package/types/index.lazy.d.ts +4 -0
  33. package/types/types.d.ts +6 -0
  34. package/types/utils.d.ts +6 -0
  35. package/1241.min.js +0 -1
  36. package/1581.min.js +0 -1
  37. package/2049.min.js +0 -1
  38. package/2066.min.js +0 -1
  39. package/2127.min.js +0 -1
  40. package/218.min.js +0 -1
  41. package/2191.min.js +0 -1
  42. package/2270.min.js +0 -1
  43. package/2556.min.js +0 -1
  44. package/2602.min.js +0 -1
  45. package/2760.min.js +0 -1
  46. package/2865.min.js +0 -33
  47. package/3047.min.js +0 -1
  48. package/3073.min.js +0 -1
  49. package/3384.min.js +0 -1
  50. package/3443.min.js +0 -1
  51. package/3583.min.js +0 -1
  52. package/374.min.js +0 -1
  53. package/382.min.js +0 -1
  54. package/4068.min.js +0 -1
  55. package/4186.min.js +0 -1
  56. package/4217.min.js +0 -1
  57. package/4427.min.js +0 -1
  58. package/4519.min.js +0 -1
  59. package/4626.min.js +0 -1
  60. package/5048.min.js +0 -1
  61. package/5218.min.js +0 -1
  62. package/5294.min.js +0 -1
  63. package/5344.min.js +0 -1
  64. package/5445.min.js +0 -1
  65. package/5492.min.js +0 -1
  66. package/5629.min.js +0 -1
  67. package/5675.min.js +0 -1
  68. package/6055.min.js +0 -1
  69. package/6067.min.js +0 -1
  70. package/6099.min.js +0 -1
  71. package/6171.min.js +0 -1
  72. package/648.min.js +0 -1
  73. package/6602.min.js +0 -1
  74. package/6943.min.js +0 -1
  75. package/6996.min.js +0 -1
  76. package/7162.min.js +0 -1
  77. package/7698.min.js +0 -1
  78. package/7711.min.js +0 -1
  79. package/7757.min.js +0 -1
  80. package/7792.min.js +0 -1
  81. package/8272.min.js +0 -1
  82. package/8386.min.js +0 -1
  83. package/8529.min.js +0 -1
  84. package/8607.min.js +0 -1
  85. package/8656.min.js +0 -1
  86. package/8731.min.js +0 -1
  87. package/9407.min.js +0 -1
  88. package/9674.min.js +0 -1
  89. package/basic_dist_browser_index_js.js +0 -30
  90. package/dist_browser_FireworksInstance_js.js +0 -30
  91. package/engine_dist_browser_Core_Container_js.js +0 -100
  92. package/plugins_blend_dist_browser_BlendPluginInstance_js.js +0 -30
  93. package/plugins_blend_dist_browser_BlendPlugin_js.js +0 -40
  94. package/plugins_blend_dist_browser_index_js.js +0 -30
  95. package/plugins_colors_hex_dist_browser_HexColorManager_js.js +0 -30
  96. package/plugins_colors_hex_dist_browser_index_js.js +0 -30
  97. package/plugins_colors_hsl_dist_browser_HslColorManager_js.js +0 -30
  98. package/plugins_colors_hsl_dist_browser_index_js.js +0 -30
  99. package/plugins_colors_rgb_dist_browser_RgbColorManager_js.js +0 -30
  100. package/plugins_colors_rgb_dist_browser_index_js.js +0 -30
  101. package/plugins_emittersShapes_square_dist_browser_EmittersSquareShapeGenerator_js.js +0 -100
  102. package/plugins_emittersShapes_square_dist_browser_index_js.js +0 -30
  103. package/plugins_emitters_dist_browser_EmitterInstance_js.js +0 -30
  104. package/plugins_emitters_dist_browser_EmittersInstancesManager_js.js +0 -100
  105. package/plugins_emitters_dist_browser_EmittersInteractor_js.js +0 -210
  106. package/plugins_emitters_dist_browser_EmittersPluginInstance_js.js +0 -30
  107. package/plugins_emitters_dist_browser_EmittersPlugin_js.js +0 -100
  108. package/plugins_emitters_dist_browser_ShapeManager_js.js +0 -30
  109. package/plugins_emitters_dist_browser_addEmittersShapesManager_js.js +0 -30
  110. package/plugins_emitters_dist_browser_getEmittersInstancesManager_js.js +0 -30
  111. package/plugins_emitters_dist_browser_index_js.js +0 -80
  112. package/plugins_emitters_dist_browser_plugin_js.js +0 -50
  113. package/plugins_interactivity_dist_browser_InteractivityPluginInstance_js.js +0 -50
  114. package/plugins_interactivity_dist_browser_InteractivityPlugin_js.js +0 -70
  115. package/plugins_interactivity_dist_browser_index_js.js +0 -120
  116. package/plugins_move_dist_browser_MovePluginInstance_js.js +0 -40
  117. package/plugins_move_dist_browser_MovePlugin_js.js +0 -30
  118. package/plugins_move_dist_browser_index_js.js +0 -30
  119. package/plugins_sounds_dist_browser_SoundsPluginInstance_js.js +0 -40
  120. package/plugins_sounds_dist_browser_SoundsPlugin_js.js +0 -130
  121. package/plugins_sounds_dist_browser_index_js.js +0 -30
  122. package/shapes_circle_dist_browser_CircleDrawer_js.js +0 -40
  123. package/shapes_circle_dist_browser_index_js.js +0 -30
  124. package/shapes_line_dist_browser_LineDrawer_js.js +0 -40
  125. package/shapes_line_dist_browser_index_js.js +0 -30
  126. package/updaters_destroy_dist_browser_DestroyUpdater_js.js +0 -100
  127. package/updaters_destroy_dist_browser_index_js.js +0 -30
  128. package/updaters_fillColor_dist_browser_FillColorUpdater_js.js +0 -30
  129. package/updaters_fillColor_dist_browser_index_js.js +0 -30
  130. package/updaters_life_dist_browser_LifeUpdater_js.js +0 -70
  131. package/updaters_life_dist_browser_index_js.js +0 -30
  132. package/updaters_opacity_dist_browser_OpacityUpdater_js.js +0 -30
  133. package/updaters_opacity_dist_browser_index_js.js +0 -30
  134. package/updaters_outModes_dist_browser_OutOfCanvasUpdater_js.js +0 -80
  135. package/updaters_outModes_dist_browser_index_js.js +0 -30
  136. package/updaters_rotate_dist_browser_RotateUpdater_js.js +0 -50
  137. package/updaters_rotate_dist_browser_index_js.js +0 -30
  138. package/updaters_size_dist_browser_SizeUpdater_js.js +0 -30
  139. package/updaters_size_dist_browser_index_js.js +0 -30
  140. package/updaters_strokeColor_dist_browser_StrokeColorUpdater_js.js +0 -30
  141. package/updaters_strokeColor_dist_browser_index_js.js +0 -30
package/README.md CHANGED
@@ -4,8 +4,7 @@
4
4
 
5
5
  [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/fireworks/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/fireworks) [![npmjs](https://badge.fury.io/js/@tsparticles/fireworks.svg)](https://www.npmjs.com/package/@tsparticles/fireworks) [![npmjs](https://img.shields.io/npm/dt/@tsparticles/fireworks)](https://www.npmjs.com/package/@tsparticles/fireworks) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
6
 
7
- [tsParticles](https://github.com/tsparticles/tsparticles) fireworks bundle loads all the features necessary to create
8
- beautiful fireworks effects with ease.
7
+ [tsParticles](https://github.com/tsparticles/tsparticles) fireworks bundle to create fireworks effects with a focused API.
9
8
 
10
9
  **Included Packages**
11
10
 
@@ -13,10 +12,12 @@ beautiful fireworks effects with ease.
13
12
  - [@tsparticles/engine](https://github.com/tsparticles/tsparticles/tree/main/engine)
14
13
  - [@tsparticles/plugin-blend](https://github.com/tsparticles/tsparticles/tree/main/plugins/blend)
15
14
  - [@tsparticles/plugin-emitters](https://github.com/tsparticles/tsparticles/tree/main/plugins/emitters)
16
- - [@tsparticles/plugin-emitters-shape-square](https://github.com/tsparticles/tsparticles/tree/main/plugins/emitters/shape/square)
15
+ - [@tsparticles/plugin-emitters-shape-square](https://github.com/tsparticles/tsparticles/tree/main/plugins/emittersShapes/square)
17
16
  - [@tsparticles/plugin-sounds](https://github.com/tsparticles/tsparticles/tree/main/plugins/sounds)
17
+ - [@tsparticles/shape-line](https://github.com/tsparticles/tsparticles/tree/main/shapes/line)
18
18
  - [@tsparticles/updater-destroy](https://github.com/tsparticles/tsparticles/tree/main/updaters/destroy)
19
19
  - [@tsparticles/updater-life](https://github.com/tsparticles/tsparticles/tree/main/updaters/life)
20
+ - [@tsparticles/updater-paint](https://github.com/tsparticles/tsparticles/tree/main/updaters/paint)
20
21
  - [@tsparticles/updater-rotate](https://github.com/tsparticles/tsparticles/tree/main/updaters/rotate)
21
22
 
22
23
  ## Dependency Graph
@@ -43,40 +44,98 @@ end
43
44
  subgraph u [Updaters]
44
45
  ud[tsparticles/updater-destroy]
45
46
  ul[tsparticles/updater-life]
47
+ up[tsparticles/updater-paint]
46
48
  ur[tsparticles/updater-rotate]
47
49
  end
48
50
 
51
+ subgraph s [Shapes]
52
+ sl[tsparticles/shape-line]
53
+ end
54
+
49
55
  bf --> bb
50
56
  bf --> ce
51
- bf --> e
52
57
  bf --> p
58
+ bf --> s
53
59
  bf --> u
54
60
  ```
55
61
 
56
- ## Quick checklist
62
+ ## Exposed API
63
+
64
+ The package API is centered on `fireworks`.
65
+
66
+ ```ts
67
+ import { fireworks } from "@tsparticles/fireworks";
57
68
 
58
- 1. Install `@tsparticles/engine` (or use the CDN bundle below)
59
- 2. Call the package loader function(s) before `tsParticles.load(...)`
60
- 3. Apply the package options in your `tsParticles.load(...)` config
69
+ // Main API
70
+ const instance = await fireworks();
71
+ const byId = await fireworks("canvas-id", options);
72
+ const byOptions = await fireworks(options);
73
+
74
+ // Extra helpers
75
+ await fireworks.init();
76
+ const custom = await fireworks.create(canvas, options);
77
+
78
+ console.log(fireworks.version);
79
+ ```
80
+
81
+ `@tsparticles/fireworks` does not expose `tsParticles` from its main entrypoint.
82
+ If you need direct engine APIs, import them from `@tsparticles/engine`.
83
+
84
+ ## Installation
85
+
86
+ ```bash
87
+ pnpm add @tsparticles/fireworks
88
+ ```
61
89
 
62
90
  ## How to use it
63
91
 
92
+ ### ESM / TypeScript
93
+
94
+ ```ts
95
+ import { fireworks } from "@tsparticles/fireworks";
96
+
97
+ const instance = await fireworks({
98
+ colors: ["#ffffff", "#ff0000"],
99
+ sounds: false,
100
+ });
101
+
102
+ instance?.pause();
103
+ instance?.play();
104
+ instance?.stop();
105
+ ```
106
+
107
+ With explicit canvas id:
108
+
109
+ ```ts
110
+ import { fireworks } from "@tsparticles/fireworks";
111
+
112
+ await fireworks("tsparticles", {
113
+ rate: 3,
114
+ speed: { min: 10, max: 25 },
115
+ });
116
+ ```
117
+
118
+ ### Custom canvas via `fireworks.create`
119
+
120
+ ```ts
121
+ import { fireworks } from "@tsparticles/fireworks";
122
+
123
+ const canvas = document.getElementById("my-canvas") as HTMLCanvasElement;
124
+ await fireworks.create(canvas, { sounds: true });
125
+ ```
126
+
64
127
  ### CDN / Vanilla JS / jQuery
65
128
 
66
- The CDN/Vanilla version JS has two different files:
129
+ The CDN/Vanilla JS version has two files:
67
130
 
68
131
  - One is a bundle file with all the scripts included in a single file
69
- - One is a file including just the `fireworks` function to load the tsParticles fireworks bunddle, all dependencies must
70
- be
71
- included manually
72
-
73
- #### Bundle
132
+ - One includes only the `fireworks` API, where dependencies must be loaded manually
74
133
 
75
- Including the `tsparticles.fireworks.bundle.min.js` file will out of the box.
134
+ After loading the bundle, `fireworks` is available on `globalThis`.
76
135
 
77
- This is the easiest usage, since it's a single file with all the features loaded.
136
+ #### Bundle
78
137
 
79
- You can still add additional packages, loading them like all the other packages.
138
+ Use the bundle when you want a single script with all required dependencies.
80
139
 
81
140
  #### Not Bundle
82
141
 
@@ -85,47 +144,33 @@ specified in the **Included Packages** section.
85
144
 
86
145
  ### Usage
87
146
 
88
- Once the scripts are loaded you can set up `tsParticles` like the following examples:
89
-
90
- ** Easiest Way **
91
-
92
147
  ```javascript
93
148
  fireworks();
94
149
  ```
95
150
 
96
- ** Async Way, best practice **
97
-
98
151
  ```javascript
99
152
  (async () => {
100
- await fireworks();
153
+ const instance = await fireworks();
154
+
155
+ instance?.pause();
156
+ instance?.play();
157
+ instance?.stop();
101
158
  })();
102
159
  ```
103
160
 
104
- ** Custom Canvas **
105
-
106
161
  ```javascript
107
162
  fireworks.create(document.getElementById("custom-id"));
108
163
  ```
109
164
 
110
- ** Fireworks Options **
111
-
112
- ```javascript
113
- fireworks({
114
- colors: ["#ffffff", "#ff0000"],
115
- });
116
- ```
117
-
118
- ** Custom Canvas with Options **
165
+ #### Options
119
166
 
120
- ```javascript
121
- fireworks.create(document.getElementById("custom-id"), {
122
- colors: ["#ffffff", "#ff0000"],
123
- });
124
- ```
167
+ `fireworks` supports these call signatures:
125
168
 
126
- #### Options
169
+ - `fireworks()`
170
+ - `fireworks(options)`
171
+ - `fireworks(id, options)`
127
172
 
128
- The `fireworks` has only a single `options` object parameter, with the following properties:
173
+ Main options:
129
174
 
130
175
  - `background` String: The background color of the canvas, it can be any valid CSS color, can be transparent as well.
131
176
  - `brightness` Number or { min: number; max: number; }: The brightness offset applied to the particles color, from -100
@@ -141,11 +186,19 @@ The `fireworks` has only a single `options` object parameter, with the following
141
186
  - `speed` Number or { min: number; max: number; }: The speed of the fireworks particles.
142
187
  - `splitCount` Number or { min: number; max: number; }: The number of particles to split the emitter in.
143
188
 
189
+ ### Returned instance methods
190
+
191
+ The resolved `FireworksInstance` exposes:
192
+
193
+ - `pause()`
194
+ - `play()`
195
+ - `stop()`
196
+
144
197
  ## Common pitfalls
145
198
 
146
- - Calling `tsParticles.load(...)` before `package loader(...)`
147
- - Verify required peer packages before enabling advanced options
148
- - Change one option group at a time to isolate regressions quickly
199
+ - Calling `fireworks` before scripts are loaded in CDN usage
200
+ - Assuming `tsParticles` is exported by `@tsparticles/fireworks` main entrypoint
201
+ - Reusing the same `id` unintentionally (the package caches instances by id)
149
202
 
150
203
  ## Related docs
151
204
 
@@ -0,0 +1,5 @@
1
+ import { fireworks } from "./index.js";
2
+ const globalObject = globalThis;
3
+ globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
4
+ globalObject.fireworks = fireworks;
5
+ export * from "./index.js";
package/browser/bundle.js CHANGED
@@ -1,2 +1,6 @@
1
+ import { fireworks } from "./index.js";
1
2
  export * from "./index.js";
2
3
  export * from "@tsparticles/engine";
4
+ const globalObject = globalThis;
5
+ globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
6
+ globalObject.fireworks = fireworks;
@@ -1,230 +1,45 @@
1
- import { DestroyType, EventType, MoveDirection, OutMode, StartValueType, getRangeMax, getRangeMin, isNumber, isString, setRangeValue, tsParticles, } from "@tsparticles/engine";
2
- import { FireworkOptions } from "./FireworkOptions.js";
3
- let initialized = false, initializing = false;
4
- const explodeSoundCheck = (args) => {
5
- const data = args.data;
6
- return data?.particle?.options.move.gravity.enable ?? false;
7
- };
8
- async function initPlugins(engine) {
9
- if (initialized) {
10
- return;
11
- }
12
- if (initializing) {
13
- return new Promise(resolve => {
14
- const timeout = 100, interval = setInterval(() => {
15
- if (!initialized) {
16
- return;
17
- }
18
- clearInterval(interval);
19
- resolve();
20
- }, timeout);
21
- });
22
- }
23
- initializing = true;
24
- engine.checkVersion("4.0.0-beta.8");
1
+ import { isString, tsParticles } from "@tsparticles/engine";
2
+ import { getFireworksInstance } from "./utils.js";
3
+ import { loadBasic } from "@tsparticles/basic";
4
+ import { loadBlendPlugin } from "@tsparticles/plugin-blend";
5
+ import { loadDestroyUpdater } from "@tsparticles/updater-destroy";
6
+ import { loadEmittersPluginSimple } from "@tsparticles/plugin-emitters/plugin";
7
+ import { loadEmittersShapeSquare } from "@tsparticles/plugin-emitters-shape-square";
8
+ import { loadLifeUpdater } from "@tsparticles/updater-life";
9
+ import { loadLineShape } from "@tsparticles/shape-line";
10
+ import { loadPaintUpdater } from "@tsparticles/updater-paint";
11
+ import { loadRotateUpdater } from "@tsparticles/updater-rotate";
12
+ import { loadSoundsPlugin } from "@tsparticles/plugin-sounds";
13
+ let initPromise = null;
14
+ async function doInitPlugins(engine) {
15
+ engine.checkVersion("4.0.0");
25
16
  await engine.pluginManager.register(async (e) => {
26
- const [{ loadBasic }, { loadLineShape }, { loadBlendPlugin }, { loadEmittersPluginSimple }, { loadEmittersShapeSquare }, { loadSoundsPlugin }, { loadRotateUpdater }, { loadDestroyUpdater }, { loadLifeUpdater }, { loadStrokeColorUpdater },] = await Promise.all([
27
- import("@tsparticles/basic"),
28
- import("@tsparticles/shape-line"),
29
- import("@tsparticles/plugin-blend"),
30
- import("@tsparticles/plugin-emitters/plugin"),
31
- import("@tsparticles/plugin-emitters-shape-square"),
32
- import("@tsparticles/plugin-sounds"),
33
- import("@tsparticles/updater-rotate"),
34
- import("@tsparticles/updater-destroy"),
35
- import("@tsparticles/updater-life"),
36
- import("@tsparticles/updater-stroke-color"),
37
- ]);
17
+ const loadEmittersForFireworks = async (e) => {
18
+ await loadEmittersPluginSimple(e);
19
+ await loadEmittersShapeSquare(e);
20
+ };
38
21
  await Promise.all([
39
22
  loadBasic(e),
40
23
  loadLineShape(e),
41
24
  loadBlendPlugin(e),
42
- (async () => {
43
- await loadEmittersPluginSimple(e);
44
- await loadEmittersShapeSquare(e);
45
- })(),
25
+ loadEmittersForFireworks(e),
46
26
  loadSoundsPlugin(e),
47
27
  loadRotateUpdater(e),
48
28
  loadDestroyUpdater(e),
49
29
  loadLifeUpdater(e),
50
- loadStrokeColorUpdater(e),
30
+ loadPaintUpdater(e),
51
31
  ]);
52
32
  });
53
- initializing = false;
54
- initialized = true;
55
33
  }
56
- function getOptions(options, canvas) {
57
- const identity = 1;
58
- return {
59
- detectRetina: true,
60
- background: {
61
- color: options.background,
62
- },
63
- blend: {
64
- enable: true,
65
- mode: "lighter",
66
- },
67
- fullScreen: {
68
- enable: !canvas,
69
- },
70
- fpsLimit: 60,
71
- emitters: {
72
- direction: MoveDirection.top,
73
- life: {
74
- count: 0,
75
- duration: 0.1,
76
- delay: 0.1,
77
- },
78
- rate: {
79
- delay: isNumber(options.rate)
80
- ? identity / options.rate
81
- : { min: identity / getRangeMin(options.rate), max: identity / getRangeMax(options.rate) },
82
- quantity: 1,
83
- },
84
- size: {
85
- width: 100,
86
- height: 0,
87
- },
88
- position: {
89
- y: 100,
90
- x: 50,
91
- },
92
- },
93
- particles: {
94
- number: {
95
- value: 0,
96
- },
97
- stroke: {
98
- color: {
99
- value: options.colors,
100
- },
101
- width: 2,
102
- },
103
- destroy: {
104
- mode: "split",
105
- bounds: {
106
- top: setRangeValue(options.minHeight),
107
- },
108
- split: {
109
- count: 1,
110
- factor: {
111
- value: 0.333333,
112
- },
113
- rate: {
114
- value: options.splitCount,
115
- },
116
- strokeColorOffset: {
117
- s: options.saturation,
118
- l: options.brightness,
119
- },
120
- particles: {
121
- group: "split",
122
- number: {
123
- value: 0,
124
- },
125
- opacity: {
126
- value: {
127
- min: 0.1,
128
- max: 1,
129
- },
130
- animation: {
131
- enable: true,
132
- speed: { min: 2, max: 4 },
133
- sync: true,
134
- startValue: StartValueType.max,
135
- destroy: DestroyType.min,
136
- count: 1,
137
- },
138
- },
139
- size: {
140
- value: { min: 5, max: 10 },
141
- },
142
- life: {
143
- count: 1,
144
- duration: {
145
- value: {
146
- min: 0.5,
147
- max: 1,
148
- },
149
- },
150
- },
151
- move: {
152
- decay: 0.05,
153
- enable: true,
154
- gravity: {
155
- enable: false,
156
- },
157
- speed: {
158
- min: 10,
159
- max: 25,
160
- },
161
- direction: "outside",
162
- outModes: OutMode.destroy,
163
- },
164
- },
165
- },
166
- },
167
- life: {
168
- count: 1,
169
- },
170
- shape: {
171
- type: "line",
172
- options: {
173
- line: {
174
- cap: "round",
175
- },
176
- },
177
- },
178
- size: {
179
- value: { min: 10, max: 20 },
180
- },
181
- rotate: {
182
- path: true,
183
- },
184
- move: {
185
- enable: true,
186
- gravity: {
187
- acceleration: setRangeValue(options.gravity),
188
- enable: true,
189
- inverse: true,
190
- maxSpeed: 150,
191
- },
192
- speed: setRangeValue(options.speed),
193
- outModes: {
194
- default: OutMode.destroy,
195
- top: OutMode.none,
196
- },
197
- },
198
- },
199
- sounds: {
200
- enable: options.sounds,
201
- events: [
202
- {
203
- event: EventType.particleRemoved,
204
- filter: explodeSoundCheck,
205
- audio: [
206
- "https://particles.js.org/audio/explosion0.mp3",
207
- "https://particles.js.org/audio/explosion1.mp3",
208
- "https://particles.js.org/audio/explosion2.mp3",
209
- ],
210
- },
211
- ],
212
- volume: 50,
213
- },
214
- };
215
- }
216
- async function getFireworksInstance(id, sourceOptions, canvas) {
217
- await initPlugins(tsParticles);
218
- const options = new FireworkOptions();
219
- options.load(sourceOptions);
220
- const particlesOptions = getOptions(options, canvas), container = await tsParticles.load({ id, element: canvas, options: particlesOptions });
221
- if (!container) {
222
- return;
34
+ async function initPlugins(engine) {
35
+ if (initPromise) {
36
+ return initPromise;
223
37
  }
224
- const { FireworksInstance } = await import("./FireworksInstance.js");
225
- return new FireworksInstance(container);
38
+ initPromise = doInitPlugins(engine);
39
+ return initPromise;
226
40
  }
227
41
  export async function fireworks(idOrOptions, sourceOptions) {
42
+ await initPlugins(tsParticles);
228
43
  let id, options;
229
44
  if (isString(idOrOptions)) {
230
45
  id = idOrOptions;
@@ -234,14 +49,15 @@ export async function fireworks(idOrOptions, sourceOptions) {
234
49
  id = "fireworks";
235
50
  options = idOrOptions ?? {};
236
51
  }
237
- return getFireworksInstance(id, options);
52
+ return getFireworksInstance(tsParticles, id, options);
238
53
  }
239
54
  fireworks.create = async (canvas, options) => {
240
- const id = canvas.id || "fireworks";
241
- return getFireworksInstance(id, options ?? {}, canvas);
55
+ await initPlugins(tsParticles);
56
+ const id = canvas?.id ?? "fireworks";
57
+ return getFireworksInstance(tsParticles, id, options ?? {}, canvas ?? undefined);
242
58
  };
243
59
  fireworks.init = async () => {
244
60
  await initPlugins(tsParticles);
245
61
  };
246
- fireworks.version = "4.0.0-beta.8";
62
+ fireworks.version = "4.0.0";
247
63
  globalThis.fireworks = fireworks;
@@ -0,0 +1,64 @@
1
+ import { isString, tsParticles } from "@tsparticles/engine/lazy";
2
+ import { getFireworksInstance } from "./utils.js";
3
+ let initPromise = null;
4
+ async function doInitPlugins(engine) {
5
+ engine.checkVersion("4.0.0");
6
+ await engine.pluginManager.register(async (e) => {
7
+ const [{ loadBasic }, { loadLineShape }, { loadBlendPlugin }, { loadEmittersPluginSimple }, { loadEmittersShapeSquare }, { loadSoundsPlugin }, { loadRotateUpdater }, { loadDestroyUpdater }, { loadLifeUpdater }, { loadPaintUpdater },] = await Promise.all([
8
+ import("@tsparticles/basic/lazy"),
9
+ import("@tsparticles/shape-line"),
10
+ import("@tsparticles/plugin-blend"),
11
+ import("@tsparticles/plugin-emitters/plugin"),
12
+ import("@tsparticles/plugin-emitters-shape-square"),
13
+ import("@tsparticles/plugin-sounds"),
14
+ import("@tsparticles/updater-rotate/lazy"),
15
+ import("@tsparticles/updater-destroy/lazy"),
16
+ import("@tsparticles/updater-life/lazy"),
17
+ import("@tsparticles/updater-paint/lazy"),
18
+ ]), loadEmittersForFireworks = async (e) => {
19
+ await loadEmittersPluginSimple(e);
20
+ await loadEmittersShapeSquare(e);
21
+ };
22
+ await Promise.all([
23
+ loadBasic(e),
24
+ loadLineShape(e),
25
+ loadBlendPlugin(e),
26
+ loadEmittersForFireworks(e),
27
+ loadSoundsPlugin(e),
28
+ loadRotateUpdater(e),
29
+ loadDestroyUpdater(e),
30
+ loadLifeUpdater(e),
31
+ loadPaintUpdater(e),
32
+ ]);
33
+ });
34
+ }
35
+ async function initPlugins(engine) {
36
+ if (initPromise) {
37
+ return initPromise;
38
+ }
39
+ initPromise = doInitPlugins(engine);
40
+ return initPromise;
41
+ }
42
+ export async function fireworks(idOrOptions, sourceOptions) {
43
+ await initPlugins(tsParticles);
44
+ let id, options;
45
+ if (isString(idOrOptions)) {
46
+ id = idOrOptions;
47
+ options = sourceOptions ?? {};
48
+ }
49
+ else {
50
+ id = "fireworks";
51
+ options = idOrOptions ?? {};
52
+ }
53
+ return getFireworksInstance(tsParticles, id, options);
54
+ }
55
+ fireworks.create = async (canvas, options) => {
56
+ await initPlugins(tsParticles);
57
+ const id = canvas?.id ?? "fireworks";
58
+ return getFireworksInstance(tsParticles, id, options ?? {}, canvas ?? undefined);
59
+ };
60
+ fireworks.init = async () => {
61
+ await initPlugins(tsParticles);
62
+ };
63
+ fireworks.version = "4.0.0";
64
+ globalThis.fireworks = fireworks;
@@ -0,0 +1 @@
1
+ export * from "./fireworks.lazy.js";
@@ -0,0 +1 @@
1
+ export {};