@tsparticles/plugin-poisson-disc 4.0.0-beta.12 → 4.0.0-beta.15

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.
@@ -1,317 +1,324 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v4.0.0-beta.12
8
- */
9
- /*
10
- * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
11
- * This devtool is neither made for production nor for readable output files.
12
- * It uses "eval()" calls to create a separate source file in the browser devtools.
13
- * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
14
- * or disable the default devtool with "devtool: false".
15
- * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
16
- */
17
- (function webpackUniversalModuleDefinition(root, factory) {
18
- if(typeof exports === 'object' && typeof module === 'object')
19
- module.exports = factory(require("@tsparticles/engine"));
20
- else if(typeof define === 'function' && define.amd)
21
- define(["@tsparticles/engine"], factory);
22
- else {
23
- var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
24
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
25
- }
26
- })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
27
- return /******/ (() => { // webpackBootstrap
28
- /******/ "use strict";
29
- /******/ var __webpack_modules__ = ({
1
+ (function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
2
+ /* Plugin v4.0.0-beta.15 */
3
+ (function (global, factory) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/engine')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/engine'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.plugins = global.__tsParticlesInternals.plugins || {}, global.__tsParticlesInternals.plugins.poisson = global.__tsParticlesInternals.plugins.poisson || {}), global.__tsParticlesInternals.engine));
7
+ })(this, (function (exports, engine) { 'use strict';
30
8
 
31
- /***/ "@tsparticles/engine"
32
- /*!*********************************************************************************************************************************!*\
33
- !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
34
- \*********************************************************************************************************************************/
35
- (module) {
9
+ class Poisson {
10
+ dimensions;
11
+ enable;
12
+ radius;
13
+ retries;
14
+ steps;
15
+ constructor() {
16
+ this.enable = false;
17
+ this.dimensions = 2;
18
+ this.radius = 0;
19
+ this.retries = 30;
20
+ this.steps = 0;
21
+ }
22
+ load(data) {
23
+ if (engine.isNull(data)) {
24
+ return;
25
+ }
26
+ if (data.enable !== undefined) {
27
+ this.enable = data.enable;
28
+ }
29
+ if (data.dimensions !== undefined) {
30
+ this.dimensions = data.dimensions;
31
+ }
32
+ if (data.radius !== undefined) {
33
+ this.radius = data.radius;
34
+ }
35
+ if (data.retries !== undefined) {
36
+ this.retries = data.retries;
37
+ }
38
+ }
39
+ }
36
40
 
37
- module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
41
+ class PoissonDiscPlugin {
42
+ id = "poisson";
43
+ async getPlugin(container) {
44
+ const { PoissonDiscPluginInstance } = await Promise.resolve().then(function () { return PoissonDiscPluginInstance$1; });
45
+ return new PoissonDiscPluginInstance(container);
46
+ }
47
+ loadOptions(_container, options, source) {
48
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
49
+ return;
50
+ }
51
+ let poissonOptions = options.poisson;
52
+ if (poissonOptions?.load === undefined) {
53
+ options.poisson = poissonOptions = new Poisson();
54
+ }
55
+ poissonOptions.load(source?.poisson);
56
+ }
57
+ needsPlugin(options) {
58
+ return options?.poisson?.enable ?? false;
59
+ }
60
+ }
38
61
 
39
- /***/ },
62
+ async function loadPoissonDiscPlugin(engine) {
63
+ engine.checkVersion("4.0.0-beta.15");
64
+ await engine.pluginManager.register(e => {
65
+ e.pluginManager.addPlugin(new PoissonDiscPlugin());
66
+ });
67
+ }
40
68
 
41
- /***/ "./dist/browser/index.js"
42
- /*!*******************************!*\
43
- !*** ./dist/browser/index.js ***!
44
- \*******************************/
45
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
69
+ const globalObject = globalThis;
70
+ globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
71
+ globalObject.loadPoissonDiscPlugin = loadPoissonDiscPlugin;
46
72
 
47
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadPoissonDiscPlugin: () => (/* binding */ loadPoissonDiscPlugin)\n/* harmony export */ });\nasync function loadPoissonDiscPlugin(engine) {\n engine.checkVersion(\"4.0.0-beta.12\");\n await engine.pluginManager.register(async (e)=>{\n const { PoissonDiscPlugin } = await __webpack_require__.e(/*! import() */ \"dist_browser_PoissonDiscPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./PoissonDiscPlugin.js */ \"./dist/browser/PoissonDiscPlugin.js\"));\n e.pluginManager.addPlugin(new PoissonDiscPlugin());\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/index.js?\n}");
73
+ class PoissonDiscPluginInstance {
74
+ poissonDisc;
75
+ redrawTimeout;
76
+ _container;
77
+ _currentIndex;
78
+ constructor(container) {
79
+ this._container = container;
80
+ this._currentIndex = 0;
81
+ }
82
+ async init() {
83
+ await this._initData();
84
+ }
85
+ particlePosition(position) {
86
+ const container = this._container, options = container.actualOptions.poisson;
87
+ if (!this.poissonDisc || !(options?.enable ?? false) || this._currentIndex >= this.poissonDisc.points.length) {
88
+ return;
89
+ }
90
+ return position ?? this.poissonDisc.points[this._currentIndex++]?.position;
91
+ }
92
+ resize() {
93
+ const container = this._container, options = container.actualOptions.poisson;
94
+ if (!(options?.enable ?? false)) {
95
+ return;
96
+ }
97
+ if (this.redrawTimeout) {
98
+ clearTimeout(this.redrawTimeout);
99
+ }
100
+ const timeout = 250;
101
+ this.redrawTimeout = setTimeout(() => {
102
+ void (async () => {
103
+ if (this._container.destroyed) {
104
+ return;
105
+ }
106
+ await this._initData();
107
+ await container.particles.redraw();
108
+ })();
109
+ }, timeout);
110
+ }
111
+ stop() {
112
+ delete this.poissonDisc;
113
+ }
114
+ async _initData() {
115
+ const container = this._container, poissonOptions = container.actualOptions.poisson, particlesOptions = container.actualOptions.particles, canvasSize = container.canvas.size, pixelRatio = container.retina.pixelRatio;
116
+ if (!poissonOptions?.enable) {
117
+ return;
118
+ }
119
+ this._currentIndex = 0;
120
+ const { PoissonDisc } = await Promise.resolve().then(function () { return PoissonDisc$1; });
121
+ this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
122
+ ? poissonOptions.radius * pixelRatio
123
+ : Math.max(engine.getRangeMax(particlesOptions.size.value) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
124
+ const noSteps = 0;
125
+ if (poissonOptions.steps > noSteps) {
126
+ this.poissonDisc.steps(poissonOptions.steps);
127
+ }
128
+ else {
129
+ await this.poissonDisc.run();
130
+ }
131
+ }
132
+ }
48
133
 
49
- /***/ }
134
+ var PoissonDiscPluginInstance$1 = /*#__PURE__*/Object.freeze({
135
+ __proto__: null,
136
+ PoissonDiscPluginInstance: PoissonDiscPluginInstance
137
+ });
50
138
 
51
- /******/ });
52
- /************************************************************************/
53
- /******/ // The module cache
54
- /******/ var __webpack_module_cache__ = {};
55
- /******/
56
- /******/ // The require function
57
- /******/ function __webpack_require__(moduleId) {
58
- /******/ // Check if module is in cache
59
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
60
- /******/ if (cachedModule !== undefined) {
61
- /******/ return cachedModule.exports;
62
- /******/ }
63
- /******/ // Create a new module (and put it into the cache)
64
- /******/ var module = __webpack_module_cache__[moduleId] = {
65
- /******/ // no module.id needed
66
- /******/ // no module.loaded needed
67
- /******/ exports: {}
68
- /******/ };
69
- /******/
70
- /******/ // Execute the module function
71
- /******/ if (!(moduleId in __webpack_modules__)) {
72
- /******/ delete __webpack_module_cache__[moduleId];
73
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
74
- /******/ e.code = 'MODULE_NOT_FOUND';
75
- /******/ throw e;
76
- /******/ }
77
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
78
- /******/
79
- /******/ // Return the exports of the module
80
- /******/ return module.exports;
81
- /******/ }
82
- /******/
83
- /******/ // expose the modules object (__webpack_modules__)
84
- /******/ __webpack_require__.m = __webpack_modules__;
85
- /******/
86
- /************************************************************************/
87
- /******/ /* webpack/runtime/define property getters */
88
- /******/ (() => {
89
- /******/ // define getter functions for harmony exports
90
- /******/ __webpack_require__.d = (exports, definition) => {
91
- /******/ for(var key in definition) {
92
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
93
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
94
- /******/ }
95
- /******/ }
96
- /******/ };
97
- /******/ })();
98
- /******/
99
- /******/ /* webpack/runtime/ensure chunk */
100
- /******/ (() => {
101
- /******/ __webpack_require__.f = {};
102
- /******/ // This file contains only the entry chunk.
103
- /******/ // The chunk loading function for additional chunks
104
- /******/ __webpack_require__.e = (chunkId) => {
105
- /******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
106
- /******/ __webpack_require__.f[key](chunkId, promises);
107
- /******/ return promises;
108
- /******/ }, []));
109
- /******/ };
110
- /******/ })();
111
- /******/
112
- /******/ /* webpack/runtime/get javascript chunk filename */
113
- /******/ (() => {
114
- /******/ // This function allow to reference async chunks
115
- /******/ __webpack_require__.u = (chunkId) => {
116
- /******/ // return url for filenames based on template
117
- /******/ return "" + chunkId + ".js";
118
- /******/ };
119
- /******/ })();
120
- /******/
121
- /******/ /* webpack/runtime/global */
122
- /******/ (() => {
123
- /******/ __webpack_require__.g = (function() {
124
- /******/ if (typeof globalThis === 'object') return globalThis;
125
- /******/ try {
126
- /******/ return this || new Function('return this')();
127
- /******/ } catch (e) {
128
- /******/ if (typeof window === 'object') return window;
129
- /******/ }
130
- /******/ })();
131
- /******/ })();
132
- /******/
133
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
134
- /******/ (() => {
135
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
136
- /******/ })();
137
- /******/
138
- /******/ /* webpack/runtime/load script */
139
- /******/ (() => {
140
- /******/ var inProgress = {};
141
- /******/ var dataWebpackPrefix = "@tsparticles/plugin-poisson-disc:";
142
- /******/ // loadScript function to load a script via script tag
143
- /******/ __webpack_require__.l = (url, done, key, chunkId) => {
144
- /******/ if(inProgress[url]) { inProgress[url].push(done); return; }
145
- /******/ var script, needAttach;
146
- /******/ if(key !== undefined) {
147
- /******/ var scripts = document.getElementsByTagName("script");
148
- /******/ for(var i = 0; i < scripts.length; i++) {
149
- /******/ var s = scripts[i];
150
- /******/ if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; }
151
- /******/ }
152
- /******/ }
153
- /******/ if(!script) {
154
- /******/ needAttach = true;
155
- /******/ script = document.createElement('script');
156
- /******/
157
- /******/ script.charset = 'utf-8';
158
- /******/ if (__webpack_require__.nc) {
159
- /******/ script.setAttribute("nonce", __webpack_require__.nc);
160
- /******/ }
161
- /******/ script.setAttribute("data-webpack", dataWebpackPrefix + key);
162
- /******/
163
- /******/ script.src = url;
164
- /******/ }
165
- /******/ inProgress[url] = [done];
166
- /******/ var onScriptComplete = (prev, event) => {
167
- /******/ // avoid mem leaks in IE.
168
- /******/ script.onerror = script.onload = null;
169
- /******/ clearTimeout(timeout);
170
- /******/ var doneFns = inProgress[url];
171
- /******/ delete inProgress[url];
172
- /******/ script.parentNode && script.parentNode.removeChild(script);
173
- /******/ doneFns && doneFns.forEach((fn) => (fn(event)));
174
- /******/ if(prev) return prev(event);
175
- /******/ }
176
- /******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
177
- /******/ script.onerror = onScriptComplete.bind(null, script.onerror);
178
- /******/ script.onload = onScriptComplete.bind(null, script.onload);
179
- /******/ needAttach && document.head.appendChild(script);
180
- /******/ };
181
- /******/ })();
182
- /******/
183
- /******/ /* webpack/runtime/make namespace object */
184
- /******/ (() => {
185
- /******/ // define __esModule on exports
186
- /******/ __webpack_require__.r = (exports) => {
187
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
188
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
189
- /******/ }
190
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
191
- /******/ };
192
- /******/ })();
193
- /******/
194
- /******/ /* webpack/runtime/publicPath */
195
- /******/ (() => {
196
- /******/ var scriptUrl;
197
- /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
198
- /******/ var document = __webpack_require__.g.document;
199
- /******/ if (!scriptUrl && document) {
200
- /******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
201
- /******/ scriptUrl = document.currentScript.src;
202
- /******/ if (!scriptUrl) {
203
- /******/ var scripts = document.getElementsByTagName("script");
204
- /******/ if(scripts.length) {
205
- /******/ var i = scripts.length - 1;
206
- /******/ while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;
207
- /******/ }
208
- /******/ }
209
- /******/ }
210
- /******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
211
- /******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
212
- /******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
213
- /******/ scriptUrl = scriptUrl.replace(/^blob:/, "").replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
214
- /******/ __webpack_require__.p = scriptUrl;
215
- /******/ })();
216
- /******/
217
- /******/ /* webpack/runtime/jsonp chunk loading */
218
- /******/ (() => {
219
- /******/ // no baseURI
220
- /******/
221
- /******/ // object to store loaded and loading chunks
222
- /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
223
- /******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
224
- /******/ var installedChunks = {
225
- /******/ "tsparticles.plugin.poisson": 0
226
- /******/ };
227
- /******/
228
- /******/ __webpack_require__.f.j = (chunkId, promises) => {
229
- /******/ // JSONP chunk loading for javascript
230
- /******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
231
- /******/ if(installedChunkData !== 0) { // 0 means "already installed".
232
- /******/
233
- /******/ // a Promise means "currently loading".
234
- /******/ if(installedChunkData) {
235
- /******/ promises.push(installedChunkData[2]);
236
- /******/ } else {
237
- /******/ if(true) { // all chunks have JS
238
- /******/ // setup Promise in chunk cache
239
- /******/ var promise = new Promise((resolve, reject) => (installedChunkData = installedChunks[chunkId] = [resolve, reject]));
240
- /******/ promises.push(installedChunkData[2] = promise);
241
- /******/
242
- /******/ // start chunk loading
243
- /******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
244
- /******/ // create error before stack unwound to get useful stacktrace later
245
- /******/ var error = new Error();
246
- /******/ var loadingEnded = (event) => {
247
- /******/ if(__webpack_require__.o(installedChunks, chunkId)) {
248
- /******/ installedChunkData = installedChunks[chunkId];
249
- /******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
250
- /******/ if(installedChunkData) {
251
- /******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
252
- /******/ var realSrc = event && event.target && event.target.src;
253
- /******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
254
- /******/ error.name = 'ChunkLoadError';
255
- /******/ error.type = errorType;
256
- /******/ error.request = realSrc;
257
- /******/ installedChunkData[1](error);
258
- /******/ }
259
- /******/ }
260
- /******/ };
261
- /******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
262
- /******/ }
263
- /******/ }
264
- /******/ }
265
- /******/ };
266
- /******/
267
- /******/ // no prefetching
268
- /******/
269
- /******/ // no preloaded
270
- /******/
271
- /******/ // no HMR
272
- /******/
273
- /******/ // no HMR manifest
274
- /******/
275
- /******/ // no on chunks loaded
276
- /******/
277
- /******/ // install a JSONP callback for chunk loading
278
- /******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
279
- /******/ var [chunkIds, moreModules, runtime] = data;
280
- /******/ // add "moreModules" to the modules object,
281
- /******/ // then flag all "chunkIds" as loaded and fire callback
282
- /******/ var moduleId, chunkId, i = 0;
283
- /******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
284
- /******/ for(moduleId in moreModules) {
285
- /******/ if(__webpack_require__.o(moreModules, moduleId)) {
286
- /******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
287
- /******/ }
288
- /******/ }
289
- /******/ if(runtime) var result = runtime(__webpack_require__);
290
- /******/ }
291
- /******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
292
- /******/ for(;i < chunkIds.length; i++) {
293
- /******/ chunkId = chunkIds[i];
294
- /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
295
- /******/ installedChunks[chunkId][0]();
296
- /******/ }
297
- /******/ installedChunks[chunkId] = 0;
298
- /******/ }
299
- /******/
300
- /******/ }
301
- /******/
302
- /******/ var chunkLoadingGlobal = this["webpackChunk_tsparticles_plugin_poisson_disc"] = this["webpackChunk_tsparticles_plugin_poisson_disc"] || [];
303
- /******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
304
- /******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
305
- /******/ })();
306
- /******/
307
- /************************************************************************/
308
- /******/
309
- /******/ // startup
310
- /******/ // Load entry module and return exports
311
- /******/ // This entry module can't be inlined because the eval devtool is used.
312
- /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js");
313
- /******/
314
- /******/ return __webpack_exports__;
315
- /******/ })()
316
- ;
317
- });
139
+ class PoissonDisc {
140
+ active;
141
+ cellSize;
142
+ cols;
143
+ dimensions;
144
+ firstPoint;
145
+ grid;
146
+ points;
147
+ radius;
148
+ retries;
149
+ rows;
150
+ size;
151
+ constructor(size, radius, retries, dimensions, firstPoint) {
152
+ this.size = { ...size };
153
+ this.radius = radius;
154
+ this.retries = retries;
155
+ this.dimensions = dimensions;
156
+ this.cellSize = Math.floor(this.radius / Math.sqrt(this.dimensions));
157
+ this.cols = Math.floor(this.size.width / this.cellSize);
158
+ this.rows = Math.floor(this.size.height / this.cellSize);
159
+ this.points = [];
160
+ this.active = [];
161
+ this.grid = [];
162
+ this.firstPoint = firstPoint ? { ...firstPoint } : undefined;
163
+ this.reset();
164
+ }
165
+ addPoint(inputPoint) {
166
+ const point = {
167
+ position: { ...inputPoint },
168
+ gridPosition: {
169
+ x: Math.floor(inputPoint.x / this.cellSize),
170
+ y: Math.floor(inputPoint.y / this.cellSize),
171
+ },
172
+ }, pointIndex = this.points.length, row = this.grid[point.gridPosition.y];
173
+ if (!row) {
174
+ return;
175
+ }
176
+ this.points.push(point);
177
+ row[point.gridPosition.x] = pointIndex;
178
+ this.active.push(pointIndex);
179
+ }
180
+ getRandom(min, max) {
181
+ return Math.floor(engine.getRandom() * (max - min)) + min;
182
+ }
183
+ initialiseGrid() {
184
+ for (let y = 0; y <= this.rows; y++) {
185
+ this.grid[y] = [];
186
+ const row = this.grid[y];
187
+ if (!row) {
188
+ continue;
189
+ }
190
+ for (let x = 0; x <= this.cols; x++) {
191
+ row[x] = -1;
192
+ }
193
+ }
194
+ }
195
+ reset() {
196
+ this.points = [];
197
+ this.active = [];
198
+ this.grid = [];
199
+ this.initialiseGrid();
200
+ if (this.firstPoint) {
201
+ this.addPoint(this.firstPoint);
202
+ }
203
+ else {
204
+ const minCoordinate = 0;
205
+ this.addPoint({
206
+ x: this.getRandom(minCoordinate, this.size.width),
207
+ y: this.getRandom(minCoordinate, this.size.height),
208
+ });
209
+ }
210
+ }
211
+ async run() {
212
+ this.reset();
213
+ const minCount = 0, step = 1, yieldEvery = 100, yieldStepModule = 0;
214
+ let iterations = 0;
215
+ while (this.active.length > minCount) {
216
+ this.steps(step);
217
+ if (++iterations % yieldEvery === yieldStepModule) {
218
+ await new Promise(resolve => setTimeout(resolve));
219
+ }
220
+ }
221
+ }
222
+ steps(steps) {
223
+ const minCount = 0;
224
+ for (let i = 0; i < steps; i++) {
225
+ if (this.active.length <= minCount) {
226
+ continue;
227
+ }
228
+ this._step();
229
+ }
230
+ }
231
+ _getNewPoint(currentPoint, tries) {
232
+ const minCoordinate = 0, gridMinValue = 0, maxNeighbourIndex = 1, newAngle = tries * (engine.doublePI / this.retries), newDist = this.getRandom(this.radius, this.radius * engine.double), offset = {
233
+ x: Math.cos(newAngle) * newDist,
234
+ y: Math.sin(newAngle) * newDist,
235
+ }, newPoint = {
236
+ x: Math.floor(currentPoint.position.x + offset.x),
237
+ y: Math.floor(currentPoint.position.y + offset.y),
238
+ }, newGridCoords = {
239
+ x: Math.floor(newPoint.x / this.cellSize),
240
+ y: Math.floor(newPoint.y / this.cellSize),
241
+ };
242
+ if (newPoint.x <= minCoordinate ||
243
+ newPoint.x >= this.size.width ||
244
+ newPoint.y <= minCoordinate ||
245
+ newPoint.y >= this.size.height) {
246
+ return;
247
+ }
248
+ const row = this.grid[newGridCoords.y];
249
+ if (!row) {
250
+ return;
251
+ }
252
+ const cellValue = row[newGridCoords.x];
253
+ if (cellValue === undefined) {
254
+ return;
255
+ }
256
+ if (cellValue >= gridMinValue) {
257
+ return;
258
+ }
259
+ for (let i = -1; i <= maxNeighbourIndex; i++) {
260
+ for (let j = -1; j <= maxNeighbourIndex; j++) {
261
+ if (!i && !j) {
262
+ continue;
263
+ }
264
+ const neighbourGrid = {
265
+ x: newGridCoords.x + j,
266
+ y: newGridCoords.y + i,
267
+ };
268
+ if (neighbourGrid.x < minCoordinate ||
269
+ neighbourGrid.y < minCoordinate ||
270
+ neighbourGrid.x >= this.cols ||
271
+ neighbourGrid.y >= this.rows) {
272
+ continue;
273
+ }
274
+ const neighbourCellValue = this.grid[neighbourGrid.y]?.[neighbourGrid.x];
275
+ if (neighbourCellValue === undefined || neighbourCellValue < gridMinValue) {
276
+ continue;
277
+ }
278
+ const neighbour = this.points[neighbourCellValue];
279
+ if (!neighbour) {
280
+ continue;
281
+ }
282
+ if (engine.getDistance(newPoint, neighbour.position) < this.radius) {
283
+ return;
284
+ }
285
+ }
286
+ }
287
+ return newPoint;
288
+ }
289
+ _step() {
290
+ const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
291
+ let foundNewPoint = false;
292
+ for (let tries = 0; tries < this.retries; tries++) {
293
+ const randomActivePointIndex = this.active[randomActive];
294
+ if (randomActivePointIndex === undefined) {
295
+ continue;
296
+ }
297
+ const point = this.points[randomActivePointIndex];
298
+ if (!point) {
299
+ continue;
300
+ }
301
+ const newPoint = this._getNewPoint(point, tries);
302
+ if (newPoint) {
303
+ foundNewPoint = true;
304
+ this.addPoint(newPoint);
305
+ break;
306
+ }
307
+ }
308
+ if (!foundNewPoint) {
309
+ const deleteCount = 1;
310
+ this.active.splice(randomActive, deleteCount);
311
+ }
312
+ }
313
+ }
314
+
315
+ var PoissonDisc$1 = /*#__PURE__*/Object.freeze({
316
+ __proto__: null,
317
+ PoissonDisc: PoissonDisc
318
+ });
319
+
320
+ exports.loadPoissonDiscPlugin = loadPoissonDiscPlugin;
321
+
322
+ }));
323
+ Object.assign(globalThis.window || globalThis, { loadPoissonDiscPlugin: (globalThis.__tsParticlesInternals.plugins.poisson || {}).loadPoissonDiscPlugin });
324
+ delete (globalThis.window || globalThis).tsparticlesInternalExports;