@tsparticles/confetti 4.0.0-beta.9 → 4.0.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 (166) hide show
  1. package/README.md +106 -107
  2. package/browser/ConfettiParams.js +1 -0
  3. package/browser/browser.js +5 -0
  4. package/browser/bundle.js +4 -0
  5. package/browser/confetti.js +37 -302
  6. package/browser/confetti.lazy.js +96 -0
  7. package/browser/index.lazy.js +1 -0
  8. package/browser/types.js +1 -0
  9. package/browser/utils.js +279 -0
  10. package/cjs/ConfettiParams.js +1 -0
  11. package/cjs/browser.js +5 -0
  12. package/cjs/bundle.js +4 -0
  13. package/cjs/confetti.js +37 -302
  14. package/cjs/confetti.lazy.js +96 -0
  15. package/cjs/index.lazy.js +1 -0
  16. package/cjs/types.js +1 -0
  17. package/cjs/utils.js +279 -0
  18. package/esm/ConfettiParams.js +1 -0
  19. package/esm/browser.js +5 -0
  20. package/esm/bundle.js +4 -0
  21. package/esm/confetti.js +37 -302
  22. package/esm/confetti.lazy.js +96 -0
  23. package/esm/index.lazy.js +1 -0
  24. package/esm/types.js +1 -0
  25. package/esm/utils.js +279 -0
  26. package/package.json +24 -17
  27. package/report.html +4949 -94
  28. package/tsparticles.confetti.bundle.js +9847 -977
  29. package/tsparticles.confetti.bundle.min.js +1 -2
  30. package/tsparticles.confetti.js +512 -322
  31. package/tsparticles.confetti.min.js +1 -1
  32. package/types/ConfettiParams.d.ts +7 -0
  33. package/types/browser.d.ts +1 -0
  34. package/types/confetti.d.ts +3 -10
  35. package/types/confetti.lazy.d.ts +16 -0
  36. package/types/index.d.ts +1 -0
  37. package/types/index.lazy.d.ts +5 -0
  38. package/types/types.d.ts +4 -0
  39. package/types/utils.d.ts +7 -0
  40. package/1080.min.js +0 -1
  41. package/1241.min.js +0 -1
  42. package/1336.min.js +0 -1
  43. package/1581.min.js +0 -1
  44. package/1583.min.js +0 -1
  45. package/1712.min.js +0 -1
  46. package/1723.min.js +0 -1
  47. package/189.min.js +0 -1
  48. package/2066.min.js +0 -1
  49. package/2127.min.js +0 -1
  50. package/2182.min.js +0 -1
  51. package/2270.min.js +0 -1
  52. package/2528.min.js +0 -1
  53. package/2602.min.js +0 -1
  54. package/2760.min.js +0 -1
  55. package/3047.min.js +0 -1
  56. package/3073.min.js +0 -1
  57. package/3443.min.js +0 -1
  58. package/3583.min.js +0 -1
  59. package/374.min.js +0 -1
  60. package/382.min.js +0 -1
  61. package/404.min.js +0 -1
  62. package/4067.min.js +0 -1
  63. package/4068.min.js +0 -1
  64. package/4077.min.js +0 -1
  65. package/4086.min.js +0 -1
  66. package/4186.min.js +0 -1
  67. package/4217.min.js +0 -1
  68. package/4427.min.js +0 -1
  69. package/4519.min.js +0 -1
  70. package/4626.min.js +0 -1
  71. package/4657.min.js +0 -1
  72. package/5048.min.js +0 -1
  73. package/5294.min.js +0 -1
  74. package/5344.min.js +0 -1
  75. package/5601.min.js +0 -1
  76. package/6055.min.js +0 -1
  77. package/6171.min.js +0 -1
  78. package/6192.min.js +0 -1
  79. package/6265.min.js +0 -1
  80. package/6466.min.js +0 -1
  81. package/648.min.js +0 -1
  82. package/6943.min.js +0 -1
  83. package/6957.min.js +0 -1
  84. package/6972.min.js +0 -1
  85. package/6996.min.js +0 -1
  86. package/7162.min.js +0 -1
  87. package/7175.min.js +0 -1
  88. package/7213.min.js +0 -1
  89. package/7259.min.js +0 -1
  90. package/7316.min.js +0 -1
  91. package/7711.min.js +0 -1
  92. package/7757.min.js +0 -1
  93. package/7775.min.js +0 -1
  94. package/8204.min.js +0 -1
  95. package/8630.min.js +0 -1
  96. package/8731.min.js +0 -1
  97. package/8855.min.js +0 -1
  98. package/9674.min.js +0 -1
  99. package/9726.min.js +0 -1
  100. package/980.min.js +0 -1
  101. package/9835.min.js +0 -1
  102. package/9907.min.js +0 -1
  103. package/basic_dist_browser_index_js.js +0 -30
  104. package/engine_dist_browser_Core_Container_js.js +0 -100
  105. package/plugins_colors_hex_dist_browser_HexColorManager_js.js +0 -30
  106. package/plugins_colors_hex_dist_browser_index_js.js +0 -30
  107. package/plugins_colors_hsl_dist_browser_HslColorManager_js.js +0 -30
  108. package/plugins_colors_hsl_dist_browser_index_js.js +0 -30
  109. package/plugins_colors_rgb_dist_browser_RgbColorManager_js.js +0 -30
  110. package/plugins_colors_rgb_dist_browser_index_js.js +0 -30
  111. package/plugins_emitters_dist_browser_EmitterInstance_js.js +0 -30
  112. package/plugins_emitters_dist_browser_EmittersInstancesManager_js.js +0 -100
  113. package/plugins_emitters_dist_browser_EmittersPluginInstance_js.js +0 -30
  114. package/plugins_emitters_dist_browser_EmittersPlugin_js.js +0 -100
  115. package/plugins_emitters_dist_browser_ShapeManager_js.js +0 -30
  116. package/plugins_emitters_dist_browser_addEmittersShapesManager_js.js +0 -30
  117. package/plugins_emitters_dist_browser_getEmittersInstancesManager_js.js +0 -30
  118. package/plugins_emitters_dist_browser_plugin_js.js +0 -50
  119. package/plugins_motion_dist_browser_MotionPluginInstance_js.js +0 -30
  120. package/plugins_motion_dist_browser_MotionPlugin_js.js +0 -50
  121. package/plugins_motion_dist_browser_index_js.js +0 -30
  122. package/plugins_move_dist_browser_MovePluginInstance_js.js +0 -40
  123. package/plugins_move_dist_browser_MovePlugin_js.js +0 -30
  124. package/plugins_move_dist_browser_index_js.js +0 -30
  125. package/shapes_cards_dist_browser_clubs_ClubDrawer_js.js +0 -30
  126. package/shapes_cards_dist_browser_diamonds_DiamondDrawer_js.js +0 -30
  127. package/shapes_cards_dist_browser_hearts_HeartDrawer_js.js +0 -30
  128. package/shapes_cards_dist_browser_paths_js.js +0 -70
  129. package/shapes_cards_dist_browser_spades_SpadeDrawer_js.js +0 -30
  130. package/shapes_cards_dist_browser_suits_js.js +0 -70
  131. package/shapes_circle_dist_browser_CircleDrawer_js.js +0 -40
  132. package/shapes_circle_dist_browser_index_js.js +0 -30
  133. package/shapes_emoji_dist_browser_EmojiDrawer_js.js +0 -50
  134. package/shapes_emoji_dist_browser_index_js.js +0 -40
  135. package/shapes_heart_dist_browser_HeartDrawer_js.js +0 -40
  136. package/shapes_heart_dist_browser_index_js.js +0 -30
  137. package/shapes_image_dist_browser_GifUtils_Utils_js.js +0 -70
  138. package/shapes_image_dist_browser_ImageDrawer_js.js +0 -30
  139. package/shapes_image_dist_browser_ImagePreloaderInstance_js.js +0 -30
  140. package/shapes_image_dist_browser_ImagePreloader_js.js +0 -40
  141. package/shapes_image_dist_browser_index_js.js +0 -40
  142. package/shapes_polygon_dist_browser_PolygonDrawer_js.js +0 -50
  143. package/shapes_polygon_dist_browser_TriangleDrawer_js.js +0 -50
  144. package/shapes_polygon_dist_browser_index_js.js +0 -30
  145. package/shapes_square_dist_browser_SquareDrawer_js.js +0 -40
  146. package/shapes_square_dist_browser_index_js.js +0 -30
  147. package/shapes_star_dist_browser_StarDrawer_js.js +0 -40
  148. package/shapes_star_dist_browser_index_js.js +0 -30
  149. package/updaters_fillColor_dist_browser_FillColorUpdater_js.js +0 -30
  150. package/updaters_fillColor_dist_browser_index_js.js +0 -30
  151. package/updaters_life_dist_browser_LifeUpdater_js.js +0 -70
  152. package/updaters_life_dist_browser_index_js.js +0 -30
  153. package/updaters_opacity_dist_browser_OpacityUpdater_js.js +0 -30
  154. package/updaters_opacity_dist_browser_index_js.js +0 -30
  155. package/updaters_outModes_dist_browser_OutOfCanvasUpdater_js.js +0 -80
  156. package/updaters_outModes_dist_browser_index_js.js +0 -30
  157. package/updaters_roll_dist_browser_RollUpdater_js.js +0 -70
  158. package/updaters_roll_dist_browser_index_js.js +0 -30
  159. package/updaters_rotate_dist_browser_RotateUpdater_js.js +0 -50
  160. package/updaters_rotate_dist_browser_index_js.js +0 -30
  161. package/updaters_size_dist_browser_SizeUpdater_js.js +0 -30
  162. package/updaters_size_dist_browser_index_js.js +0 -30
  163. package/updaters_tilt_dist_browser_TiltUpdater_js.js +0 -60
  164. package/updaters_tilt_dist_browser_index_js.js +0 -30
  165. package/updaters_wobble_dist_browser_WobbleUpdater_js.js +0 -60
  166. package/updaters_wobble_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/confetti/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/confetti) [![npmjs](https://badge.fury.io/js/@tsparticles/confetti.svg)](https://www.npmjs.com/package/@tsparticles/confetti) [![npmjs](https://img.shields.io/npm/dt/@tsparticles/confetti)](https://www.npmjs.com/package/@tsparticles/confetti) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
6
6
 
7
- [tsParticles](https://github.com/tsparticles/tsparticles) confetti bundle loads all the features necessary to create
8
- beautiful confetti effects with ease.
7
+ [tsParticles](https://github.com/tsparticles/tsparticles) confetti bundle to create confetti effects with a single API.
9
8
 
10
9
  **Included Packages**
11
10
 
@@ -70,30 +69,84 @@ bc --> s
70
69
  bc --> u
71
70
  ```
72
71
 
73
- ## Quick checklist
72
+ ## Exposed API
74
73
 
75
- 1. Install `@tsparticles/engine` (or use the CDN bundle below)
76
- 2. Call the package loader function(s) before `tsParticles.load(...)`
77
- 3. Apply the package options in your `tsParticles.load(...)` config
74
+ The package API is centered on `confetti`.
75
+
76
+ ```ts
77
+ import { confetti } from "@tsparticles/confetti";
78
+
79
+ // Main API
80
+ await confetti(options);
81
+ await confetti("canvas-id", options);
82
+
83
+ // Extra helpers
84
+ await confetti.init();
85
+ const fireOnCanvas = await confetti.create(canvas, defaultOptions);
86
+ await fireOnCanvas(options);
87
+
88
+ console.log(confetti.version);
89
+ ```
90
+
91
+ `@tsparticles/confetti` does not expose `tsParticles` from its main entrypoint.
92
+ If you need direct engine APIs, import them from `@tsparticles/engine`.
93
+
94
+ ## Installation
95
+
96
+ ```bash
97
+ pnpm add @tsparticles/confetti
98
+ ```
78
99
 
79
100
  ## How to use it
80
101
 
102
+ ### ESM / TypeScript
103
+
104
+ ```ts
105
+ import { confetti } from "@tsparticles/confetti";
106
+
107
+ await confetti({
108
+ count: 80,
109
+ spread: 60,
110
+ position: { x: 50, y: 50 },
111
+ colors: ["#ffffff", "#ff0000"],
112
+ });
113
+ ```
114
+
115
+ With explicit canvas id:
116
+
117
+ ```ts
118
+ import { confetti } from "@tsparticles/confetti";
119
+
120
+ await confetti("tsparticles", {
121
+ count: 50,
122
+ angle: 90,
123
+ spread: 45,
124
+ });
125
+ ```
126
+
127
+ ### Custom canvas via `confetti.create`
128
+
129
+ ```ts
130
+ import { confetti } from "@tsparticles/confetti";
131
+
132
+ const canvas = document.getElementById("my-canvas") as HTMLCanvasElement;
133
+ const localConfetti = await confetti.create(canvas, { count: 30 });
134
+
135
+ await localConfetti({ spread: 70 });
136
+ ```
137
+
81
138
  ### CDN / Vanilla JS / jQuery
82
139
 
83
- The CDN/Vanilla version JS has two different files:
140
+ The CDN/Vanilla JS version has two files:
84
141
 
85
142
  - One is a bundle file with all the scripts included in a single file
86
- - One is a file including just the `confetti` function to load the tsParticles confetti bunddle, all dependencies must
87
- be
88
- included manually
143
+ - One includes only the `confetti` API, where dependencies must be loaded manually
89
144
 
90
- #### Bundle
145
+ After loading the bundle, `confetti` is available on `globalThis`.
91
146
 
92
- Including the `tsparticles.confetti.bundle.min.js` file will out of the box.
93
-
94
- This is the easiest usage, since it's a single file with all the features loaded.
147
+ #### Bundle
95
148
 
96
- You can still add additional packages, loading them like all the other packages.
149
+ Use the bundle when you want a single script with all required dependencies.
97
150
 
98
151
  #### Not Bundle
99
152
 
@@ -102,116 +155,62 @@ specified in the **Included Packages** section.
102
155
 
103
156
  ### Usage
104
157
 
105
- Once the scripts are loaded you can set up `tsParticles` like the following examples:
106
-
107
- ** Easiest Way **
108
-
109
- ```javascript
110
- confetti();
158
+ ```js
159
+ confetti({ count: 60 });
111
160
  ```
112
161
 
113
- ** Async Way, best practice **
114
-
115
- ```javascript
162
+ ```js
116
163
  (async () => {
117
- await confetti();
164
+ await confetti({ count: 60, spread: 55 });
118
165
  })();
119
166
  ```
120
167
 
121
- ** Confetti Options **
122
-
123
- ```javascript
168
+ ```js
124
169
  confetti("tsparticles", {
125
- /**
126
- * @deprecated use count property instead
127
- */
128
- particleCount: 50,
129
- /**
130
- * @deprecated use position property instead
131
- */
132
- origin: {
133
- x: 0.5,
134
- y: 0.5,
135
- },
136
- //------------------------------------------
137
- angle: 90,
138
170
  count: 50,
139
171
  position: {
140
172
  x: 50,
141
173
  y: 50,
142
174
  },
143
- spread: 45,
144
- startVelocity: 45,
145
- decay: 0.9,
146
- gravity: 1,
147
- drift: 0,
148
- ticks: 200,
149
- colors: ["#ffffff", "#ff0000"],
150
- shapes: ["square", "circle"],
151
- scalar: 1,
152
- zIndex: 100,
153
- disableForReducedMotion: true,
154
175
  });
155
176
  ```
156
177
 
157
- #### Options
158
-
159
- The `confetti` first parameter can be an id and the second parameter a single `options` object, or just the single
160
- options object without the id, which will be `confetti` by default. The `options` object has the following properties:
161
-
162
- - `count` _Integer (default: 50)_: The number of confetti to launch. More is always fun... but be cool, there's a lot of
163
- math involved. (`particleCount` can be used too, but it's deprecated)
164
- - `angle` _Number (default: 90)_: The angle in which to launch the confetti, in degrees: 90 is straight up.
165
- - `spread` _Number (default: 45)_: How far off center the confetti can go, in degrees. 45 means the confetti will launch
166
- at the defined `angle` plus or minus 22.5 degrees.
167
- - `startVelocity` _Number (default: 45)_: How fast the confetti will start going, in pixels.
168
- - `decay` _Number (default: 0.9)_: How quickly the confetti will lose speed. Keep this number between 0 and 1, otherwise
169
- the confetti will gain speed. Better yet, just never change it.
170
- - `flat` _Boolean (default: false)_: Optionally turns off the tilt and wobble that three dimensional confetti would have
171
- in the real world. Yeah, they look a little sad, but y'all asked for them, so don't blame me.
172
- - `gravity` _Number (default: 1)_: How quickly the particles are pulled down: 1 is full gravity, 0.5 is half gravity,
173
- etc., but there are no limits. You can even make particles go up if you'd like.
174
- - `drift` _Number (default: 0)_: How much to the side the confetti will drift. The default is 0, meaning that they will
175
- fall straight down. Use a negative number for left and positive number for right.
176
- - `ticks` _Number (default: 200)_: How many times the confetti will move. This is abstract... but play with it if the
177
- confetti disappear too quickly for you.
178
- - `position` _Object_: Where to start firing confetti from. Feel free to launch off-screen if you'd like. (`origin` can
179
- be used too, but it's deprecated)
180
- - `position.x` _Number (default: 50)_: The `x` position on the page, with `0` being the left edge and `100` being
181
- the
182
- right edge.
183
- - `position.y` _Number (default: 50)_: The `y` position on the page, with `0` being the top edge and `100` being the
184
- bottom edge.
185
- - `colors` _Array<String>_: An array of color strings, in the HEX format... you know, like `#bada55`.
186
- - `shapes` _Array<String>_: An array of shapes for the confetti. The possible values are:
187
- - `circle`
188
- - `square`
189
- - `star`
190
- - `polygon`
191
- - `image`
192
- - `heart`
193
- - `hearts`
194
- - `spades`
195
- - `clubs`
196
- - `diamonds`
197
- - `text`
198
- The default is to use both shapes in an even mix. You can even change the mix by providing a value such
199
- as `['circle', 'circle', 'square']` to use two third circles and one third squares.
200
- - `scalar` _Number (default: 1)_: Scale factor for each confetti particle. Use decimals to make the confetti smaller. Go
201
- on, try teeny tiny confetti, they are adorable!
202
- - `zIndex` _Integer (default: 100)_: The confetti should be on top, after all. But if you have a crazy high page, you
203
- can set it even higher.
204
- - `disableForReducedMotion` _Boolean (default: true)_: Disables confetti entirely for users
205
- that [prefer reduced motion](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
206
-
207
- And for those asking, yes you can paste your canvas-confetti code and migrate to tsParticles Confetti without changing a
208
- thing
178
+ ### Options
179
+
180
+ The `confetti` API accepts:
181
+
182
+ - `confetti(options)`
183
+ - `confetti(id, options)`
184
+
185
+ Main options:
186
+
187
+ - `count` _Integer (default: 50)_
188
+ - `angle` _Number (default: 90)_
189
+ - `spread` _Number (default: 45)_
190
+ - `startVelocity` _Number (default: 45)_
191
+ - `decay` _Number (default: 0.9)_
192
+ - `flat` _Boolean (default: false)_
193
+ - `gravity` _Number (default: 1)_
194
+ - `drift` _Number (default: 0)_
195
+ - `ticks` _Number (default: 200)_
196
+ - `position` _Object_ (`x`/`y`, default 50/50)
197
+ - `colors` _Array<String>_
198
+ - `shapes` _Array<String>_
199
+ - `shapeOptions` _Record<string, unknown>_
200
+ - `scalar` _Number (default: 1)_
201
+ - `zIndex` _Integer (default: 100)_
202
+ - `disableForReducedMotion` _Boolean (default: true)_
203
+
204
+ Deprecated aliases still accepted:
205
+
206
+ - `particleCount` (use `count`)
207
+ - `origin` (use `position`)
209
208
 
210
209
  ## Common pitfalls
211
210
 
212
- - Calling `tsParticles.load(...)` before `package loader(...)`
213
- - Verify required peer packages before enabling advanced options
214
- - Change one option group at a time to isolate regressions quickly
211
+ - Calling `confetti` before scripts are loaded in CDN usage
212
+ - Assuming `tsParticles` is exported by `@tsparticles/confetti` main entrypoint
213
+ - Passing no first argument in TypeScript (use `confetti(options)` or `confetti(id, options)`)
215
214
 
216
215
  ## Related docs
217
216
 
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { confetti } from "./index.js";
2
+ const globalObject = globalThis;
3
+ globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
4
+ globalObject.confetti = confetti;
5
+ export * from "./index.js";
package/browser/bundle.js CHANGED
@@ -1,2 +1,6 @@
1
+ import { confetti } 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.confetti = confetti;
@@ -1,42 +1,24 @@
1
- import { isString, millisecondsToSeconds, tsParticles, } from "@tsparticles/engine";
2
- import { ConfettiOptions } from "./ConfettiOptions.js";
3
- let initialized = false, initializing = false;
4
- const ids = new Map(), defaultGravity = 9.81, sizeFactor = 5, speedFactor = 3, decayOffset = 1, disableRotate = 0, disableTilt = 0;
5
- async function initPlugins(engine) {
6
- if (initialized) {
7
- return;
8
- }
9
- if (initializing) {
10
- return new Promise(resolve => {
11
- const timeout = 100, interval = setInterval(() => {
12
- if (!initialized) {
13
- return;
14
- }
15
- clearInterval(interval);
16
- resolve();
17
- }, timeout);
18
- });
19
- }
20
- initializing = true;
21
- engine.checkVersion("4.0.0-beta.9");
1
+ import { isString, tsParticles } from "@tsparticles/engine";
2
+ import { loadBasic } from "@tsparticles/basic";
3
+ import { loadCardSuitsShape } from "@tsparticles/shape-cards/suits";
4
+ import { loadEmittersPluginSimple } from "@tsparticles/plugin-emitters/plugin";
5
+ import { loadEmojiShape } from "@tsparticles/shape-emoji";
6
+ import { loadHeartShape } from "@tsparticles/shape-heart";
7
+ import { loadImageShape } from "@tsparticles/shape-image";
8
+ import { loadLifeUpdater } from "@tsparticles/updater-life";
9
+ import { loadMotionPlugin } from "@tsparticles/plugin-motion";
10
+ import { loadPolygonShape } from "@tsparticles/shape-polygon";
11
+ import { loadRollUpdater } from "@tsparticles/updater-roll";
12
+ import { loadRotateUpdater } from "@tsparticles/updater-rotate";
13
+ import { loadSquareShape } from "@tsparticles/shape-square";
14
+ import { loadStarShape } from "@tsparticles/shape-star";
15
+ import { loadTiltUpdater } from "@tsparticles/updater-tilt";
16
+ import { loadWobbleUpdater } from "@tsparticles/updater-wobble";
17
+ import { setConfetti } from "./utils.js";
18
+ let initPromise = null;
19
+ async function doInitPlugins(engine) {
20
+ engine.checkVersion("4.0.1");
22
21
  await engine.pluginManager.register(async (e) => {
23
- const [{ loadBasic }, { loadEmittersPluginSimple }, { loadMotionPlugin }, { loadCardSuitsShape }, { loadHeartShape }, { loadImageShape }, { loadPolygonShape }, { loadSquareShape }, { loadStarShape }, { loadEmojiShape }, { loadRotateUpdater }, { loadLifeUpdater }, { loadRollUpdater }, { loadTiltUpdater }, { loadWobbleUpdater },] = await Promise.all([
24
- import("@tsparticles/basic"),
25
- import("@tsparticles/plugin-emitters/plugin"),
26
- import("@tsparticles/plugin-motion"),
27
- import("@tsparticles/shape-cards/suits"),
28
- import("@tsparticles/shape-heart"),
29
- import("@tsparticles/shape-image"),
30
- import("@tsparticles/shape-polygon"),
31
- import("@tsparticles/shape-square"),
32
- import("@tsparticles/shape-star"),
33
- import("@tsparticles/shape-emoji"),
34
- import("@tsparticles/updater-rotate"),
35
- import("@tsparticles/updater-life"),
36
- import("@tsparticles/updater-roll"),
37
- import("@tsparticles/updater-tilt"),
38
- import("@tsparticles/updater-wobble"),
39
- ]);
40
22
  await Promise.all([
41
23
  loadBasic(e),
42
24
  loadMotionPlugin(e),
@@ -55,265 +37,13 @@ async function initPlugins(engine) {
55
37
  loadWobbleUpdater(e),
56
38
  ]);
57
39
  });
58
- initializing = false;
59
- initialized = true;
60
40
  }
61
- async function setConfetti(params) {
62
- const actualOptions = new ConfettiOptions();
63
- actualOptions.load(params.options);
64
- let container;
65
- const fpsLimit = 120, fpsLimitFactor = 3.6, opacitySpeed = (actualOptions.ticks * millisecondsToSeconds) / (fpsLimitFactor * millisecondsToSeconds * fpsLimit);
66
- if (ids.has(params.id)) {
67
- container = ids.get(params.id);
68
- if (container && !container.destroyed) {
69
- const alias = container;
70
- if ("addEmitter" in alias) {
71
- await alias.addEmitter?.({
72
- startCount: actualOptions.count,
73
- position: actualOptions.position,
74
- size: {
75
- width: 0,
76
- height: 0,
77
- },
78
- rate: {
79
- delay: 0,
80
- quantity: 0,
81
- },
82
- life: {
83
- duration: 0.1,
84
- count: 1,
85
- },
86
- particles: {
87
- fill: {
88
- color: {
89
- value: actualOptions.colors,
90
- },
91
- enable: true,
92
- },
93
- shape: {
94
- type: actualOptions.shapes,
95
- options: actualOptions.shapeOptions,
96
- },
97
- life: {
98
- count: 1,
99
- },
100
- opacity: {
101
- value: { min: 0, max: 1 },
102
- animation: {
103
- enable: true,
104
- sync: true,
105
- speed: opacitySpeed,
106
- startValue: "max",
107
- destroy: "min",
108
- count: 1,
109
- },
110
- },
111
- size: {
112
- value: sizeFactor * actualOptions.scalar,
113
- },
114
- move: {
115
- angle: {
116
- value: actualOptions.spread,
117
- offset: 0,
118
- },
119
- drift: {
120
- min: -actualOptions.drift,
121
- max: actualOptions.drift,
122
- },
123
- gravity: {
124
- acceleration: actualOptions.gravity * defaultGravity,
125
- },
126
- speed: actualOptions.startVelocity * speedFactor,
127
- decay: decayOffset - actualOptions.decay,
128
- direction: -actualOptions.angle,
129
- },
130
- rotate: {
131
- value: actualOptions.flat
132
- ? disableRotate
133
- : {
134
- min: 0,
135
- max: 360,
136
- },
137
- direction: "random",
138
- animation: {
139
- enable: !actualOptions.flat,
140
- speed: 60,
141
- },
142
- },
143
- tilt: {
144
- direction: "random",
145
- enable: !actualOptions.flat,
146
- value: actualOptions.flat
147
- ? disableTilt
148
- : {
149
- min: 0,
150
- max: 360,
151
- },
152
- animation: {
153
- enable: true,
154
- speed: 60,
155
- },
156
- },
157
- roll: {
158
- darken: {
159
- enable: true,
160
- value: 25,
161
- },
162
- enable: !actualOptions.flat,
163
- speed: {
164
- min: 15,
165
- max: 25,
166
- },
167
- },
168
- wobble: {
169
- distance: 30,
170
- enable: !actualOptions.flat,
171
- speed: {
172
- min: -15,
173
- max: 15,
174
- },
175
- },
176
- },
177
- });
178
- return;
179
- }
180
- }
41
+ async function initPlugins(engine) {
42
+ if (initPromise) {
43
+ return initPromise;
181
44
  }
182
- const particlesOptions = {
183
- fullScreen: {
184
- enable: !params.canvas,
185
- zIndex: actualOptions.zIndex,
186
- },
187
- fpsLimit: 120,
188
- particles: {
189
- number: {
190
- value: 0,
191
- },
192
- fill: {
193
- color: {
194
- value: actualOptions.colors,
195
- },
196
- enable: true,
197
- },
198
- shape: {
199
- type: actualOptions.shapes,
200
- options: actualOptions.shapeOptions,
201
- },
202
- opacity: {
203
- value: { min: 0, max: 1 },
204
- animation: {
205
- enable: true,
206
- sync: true,
207
- speed: opacitySpeed,
208
- startValue: "max",
209
- destroy: "min",
210
- count: 1,
211
- },
212
- },
213
- size: {
214
- value: sizeFactor * actualOptions.scalar,
215
- },
216
- links: {
217
- enable: false,
218
- },
219
- life: {
220
- count: 1,
221
- },
222
- move: {
223
- angle: {
224
- value: actualOptions.spread,
225
- offset: 0,
226
- },
227
- drift: {
228
- min: -actualOptions.drift,
229
- max: actualOptions.drift,
230
- },
231
- enable: true,
232
- gravity: {
233
- enable: true,
234
- acceleration: actualOptions.gravity * defaultGravity,
235
- },
236
- speed: actualOptions.startVelocity * speedFactor,
237
- decay: decayOffset - actualOptions.decay,
238
- direction: -actualOptions.angle,
239
- random: true,
240
- straight: false,
241
- outModes: {
242
- default: "none",
243
- bottom: "destroy",
244
- },
245
- },
246
- rotate: {
247
- value: actualOptions.flat
248
- ? disableRotate
249
- : {
250
- min: 0,
251
- max: 360,
252
- },
253
- direction: "random",
254
- animation: {
255
- enable: !actualOptions.flat,
256
- speed: 60,
257
- },
258
- },
259
- tilt: {
260
- direction: "random",
261
- enable: !actualOptions.flat,
262
- value: actualOptions.flat
263
- ? disableTilt
264
- : {
265
- min: 0,
266
- max: 360,
267
- },
268
- animation: {
269
- enable: true,
270
- speed: 60,
271
- },
272
- },
273
- roll: {
274
- darken: {
275
- enable: true,
276
- value: 25,
277
- },
278
- enable: !actualOptions.flat,
279
- speed: {
280
- min: 15,
281
- max: 25,
282
- },
283
- },
284
- wobble: {
285
- distance: 30,
286
- enable: !actualOptions.flat,
287
- speed: {
288
- min: -15,
289
- max: 15,
290
- },
291
- },
292
- },
293
- motion: {
294
- disable: actualOptions.disableForReducedMotion,
295
- },
296
- emitters: {
297
- name: "confetti",
298
- startCount: actualOptions.count,
299
- position: actualOptions.position,
300
- size: {
301
- width: 0,
302
- height: 0,
303
- },
304
- rate: {
305
- delay: 0,
306
- quantity: 0,
307
- },
308
- life: {
309
- duration: 0.1,
310
- count: 1,
311
- },
312
- },
313
- };
314
- container = await tsParticles.load({ id: params.id, element: params.canvas, options: particlesOptions });
315
- ids.set(params.id, container);
316
- return container;
45
+ initPromise = doInitPlugins(engine);
46
+ return initPromise;
317
47
  }
318
48
  export async function confetti(idOrOptions, confettiOptions) {
319
49
  await initPlugins(tsParticles);
@@ -326,15 +56,20 @@ export async function confetti(idOrOptions, confettiOptions) {
326
56
  id = "confetti";
327
57
  options = idOrOptions;
328
58
  }
329
- return setConfetti({
59
+ return setConfetti(tsParticles, {
330
60
  id,
331
61
  options,
332
62
  });
333
63
  }
334
- confetti.create = async (canvas, options) => {
64
+ confetti.create = async (canvas, options = {}) => {
335
65
  await initPlugins(tsParticles);
336
- const id = canvas.getAttribute("id") ?? "confetti";
337
- canvas.setAttribute("id", id);
66
+ const id = canvas?.getAttribute("id") ?? "confetti";
67
+ canvas?.setAttribute("id", id);
68
+ await setConfetti(tsParticles, {
69
+ id,
70
+ canvas: canvas ?? undefined,
71
+ options,
72
+ });
338
73
  return async (idOrOptions, confettiOptions) => {
339
74
  let subOptions, subId;
340
75
  if (isString(idOrOptions)) {
@@ -345,9 +80,9 @@ confetti.create = async (canvas, options) => {
345
80
  subId = id;
346
81
  subOptions = idOrOptions;
347
82
  }
348
- return setConfetti({
83
+ return setConfetti(tsParticles, {
349
84
  id: subId,
350
- canvas,
85
+ canvas: canvas ?? undefined,
351
86
  options: subOptions,
352
87
  });
353
88
  };
@@ -355,5 +90,5 @@ confetti.create = async (canvas, options) => {
355
90
  confetti.init = async () => {
356
91
  await initPlugins(tsParticles);
357
92
  };
358
- confetti.version = "4.0.0-beta.9";
93
+ confetti.version = "4.0.1";
359
94
  globalThis.confetti = confetti;