@tsparticles/plugin-poisson-disc 4.0.0-alpha.5 → 4.0.0-beta.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 (38) hide show
  1. package/56.min.js +1 -0
  2. package/960.min.js +1 -0
  3. package/964.min.js +1 -0
  4. package/browser/Options/Classes/Poisson.js +5 -0
  5. package/browser/PoissonDisc.js +79 -67
  6. package/browser/PoissonDiscPlugin.js +1 -3
  7. package/browser/PoissonDiscPluginInstance.js +9 -2
  8. package/browser/index.js +1 -1
  9. package/cjs/Options/Classes/Poisson.js +5 -0
  10. package/cjs/PoissonDisc.js +79 -67
  11. package/cjs/PoissonDiscPlugin.js +1 -3
  12. package/cjs/PoissonDiscPluginInstance.js +9 -2
  13. package/cjs/index.js +1 -1
  14. package/dist_browser_PoissonDiscPluginInstance_js.js +2 -12
  15. package/dist_browser_PoissonDiscPlugin_js.js +3 -3
  16. package/dist_browser_PoissonDisc_js.js +30 -0
  17. package/esm/Options/Classes/Poisson.js +5 -0
  18. package/esm/PoissonDisc.js +79 -67
  19. package/esm/PoissonDiscPlugin.js +1 -3
  20. package/esm/PoissonDiscPluginInstance.js +9 -2
  21. package/esm/index.js +1 -1
  22. package/package.json +2 -2
  23. package/report.html +3 -3
  24. package/tsparticles.plugin.poisson.js +31 -19
  25. package/tsparticles.plugin.poisson.min.js +2 -2
  26. package/types/PoissonDisc.d.ts +1 -1
  27. package/types/PoissonDiscPlugin.d.ts +1 -2
  28. package/types/PoissonDiscPluginInstance.d.ts +1 -1
  29. package/umd/Options/Classes/Poisson.js +5 -0
  30. package/umd/PoissonDisc.js +79 -67
  31. package/umd/PoissonDiscPlugin.js +1 -3
  32. package/umd/PoissonDiscPluginInstance.js +45 -4
  33. package/umd/index.js +1 -1
  34. package/336.min.js +0 -2
  35. package/336.min.js.LICENSE.txt +0 -1
  36. package/879.min.js +0 -2
  37. package/879.min.js.LICENSE.txt +0 -1
  38. package/tsparticles.plugin.poisson.min.js.LICENSE.txt +0 -1
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v4.0.0-alpha.5
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -28,16 +28,6 @@ return /******/ (() => { // webpackBootstrap
28
28
  /******/ "use strict";
29
29
  /******/ var __webpack_modules__ = ({
30
30
 
31
- /***/ "./dist/browser/index.js"
32
- /*!*******************************!*\
33
- !*** ./dist/browser/index.js ***!
34
- \*******************************/
35
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
36
-
37
- 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-alpha.5\");\n await engine.register(async e => {\n const {\n PoissonDiscPlugin\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_PoissonDiscPlugin_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./PoissonDiscPlugin.js */ \"./dist/browser/PoissonDiscPlugin.js\"));\n e.addPlugin(new PoissonDiscPlugin());\n });\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/index.js?\n}");
38
-
39
- /***/ },
40
-
41
31
  /***/ "@tsparticles/engine"
42
32
  /*!*********************************************************************************************************************************!*\
43
33
  !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
@@ -46,6 +36,16 @@ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpa
46
36
 
47
37
  module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
48
38
 
39
+ /***/ },
40
+
41
+ /***/ "./dist/browser/index.js"
42
+ /*!*******************************!*\
43
+ !*** ./dist/browser/index.js ***!
44
+ \*******************************/
45
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
46
+
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.0\");\n await engine.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.addPlugin(new PoissonDiscPlugin());\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-poisson-disc/./dist/browser/index.js?\n}");
48
+
49
49
  /***/ }
50
50
 
51
51
  /******/ });
@@ -60,12 +60,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
60
60
  /******/ if (cachedModule !== undefined) {
61
61
  /******/ return cachedModule.exports;
62
62
  /******/ }
63
- /******/ // Check if module exists (development only)
64
- /******/ if (__webpack_modules__[moduleId] === undefined) {
65
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
66
- /******/ e.code = 'MODULE_NOT_FOUND';
67
- /******/ throw e;
68
- /******/ }
69
63
  /******/ // Create a new module (and put it into the cache)
70
64
  /******/ var module = __webpack_module_cache__[moduleId] = {
71
65
  /******/ // no module.id needed
@@ -74,6 +68,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
74
68
  /******/ };
75
69
  /******/
76
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
77
  /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
78
78
  /******/
79
79
  /******/ // Return the exports of the module
@@ -118,6 +118,18 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
118
118
  /******/ };
119
119
  /******/ })();
120
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
+ /******/
121
133
  /******/ /* webpack/runtime/hasOwnProperty shorthand */
122
134
  /******/ (() => {
123
135
  /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
@@ -182,8 +194,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
182
194
  /******/ /* webpack/runtime/publicPath */
183
195
  /******/ (() => {
184
196
  /******/ var scriptUrl;
185
- /******/ if (globalThis.importScripts) scriptUrl = globalThis.location + "";
186
- /******/ var document = globalThis.document;
197
+ /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
198
+ /******/ var document = __webpack_require__.g.document;
187
199
  /******/ if (!scriptUrl && document) {
188
200
  /******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
189
201
  /******/ scriptUrl = document.currentScript.src;
@@ -1,2 +1,2 @@
1
- /*! For license information please see tsparticles.plugin.poisson.min.js.LICENSE.txt */
2
- !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,(e=>(()=>{var t,r,o={303(t){t.exports=e}},i={};function n(e){var t=i[e];if(void 0!==t)return t.exports;var r=i[e]={exports:{}};return o[e](r,r.exports,n),r.exports}n.m=o,n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,r)=>(n.f[r](e,t),t)),[])),n.u=e=>e+".min.js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),t={},r="@tsparticles/plugin-poisson-disc:",n.l=(e,o,i,a)=>{if(t[e])t[e].push(o);else{var s,l;if(void 0!==i)for(var p=document.getElementsByTagName("script"),c=0;c<p.length;c++){var u=p[c];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==r+i){s=u;break}}s||(l=!0,(s=document.createElement("script")).charset="utf-8",n.nc&&s.setAttribute("nonce",n.nc),s.setAttribute("data-webpack",r+i),s.src=e),t[e]=[o];var d=(r,o)=>{s.onerror=s.onload=null,clearTimeout(f);var i=t[e];if(delete t[e],s.parentNode&&s.parentNode.removeChild(s),i&&i.forEach((e=>e(o))),r)return r(o)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),l&&document.head.appendChild(s)}},n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var o=r.length-1;o>-1&&(!e||!/^http(s?):/.test(e));)e=r[o--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),n.p=e})(),(()=>{var e={189:0};n.f.j=(t,r)=>{var o=n.o(e,t)?e[t]:void 0;if(0!==o)if(o)r.push(o[2]);else{var i=new Promise(((r,i)=>o=e[t]=[r,i]));r.push(o[2]=i);var a=n.p+n.u(t),s=new Error;n.l(a,(r=>{if(n.o(e,t)&&(0!==(o=e[t])&&(e[t]=void 0),o)){var i=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+i+": "+a+")",s.name="ChunkLoadError",s.type=i,s.request=a,o[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var o,i,[a,s,l]=r,p=0;if(a.some((t=>0!==e[t]))){for(o in s)n.o(s,o)&&(n.m[o]=s[o]);if(l)l(n)}for(t&&t(r);p<a.length;p++)i=a[p],n.o(e,i)&&e[i]&&e[i][0](),e[i]=0},r=this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var a={};async function s(e){e.checkVersion("4.0.0-alpha.5"),await e.register((async e=>{const{PoissonDiscPlugin:t}=await n.e(879).then(n.bind(n,879));e.addPlugin(new t)}))}return n.r(a),n.d(a,{loadPoissonDiscPlugin:()=>s}),a})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/engine")):t(e.window);for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(this,e=>(()=>{"use strict";var t,r,o,i={303(t){t.exports=e}},n={};function s(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return i[e](r,r.exports,s),r.exports}s.m=i,s.d=(e,t)=>{for(var r in t)s.o(t,r)&&!s.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce((t,r)=>(s.f[r](e,t),t),[])),s.u=e=>""+e+".min.js",s.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a={},s.l=(e,t,r,o)=>{if(a[e])return void a[e].push(t);if(void 0!==r)for(var i,n,c=document.getElementsByTagName("script"),p=0;p<c.length;p++){var l=c[p];if(l.getAttribute("src")==e||l.getAttribute("data-webpack")=="@tsparticles/plugin-poisson-disc:"+r){i=l;break}}i||(n=!0,(i=document.createElement("script")).charset="utf-8",s.nc&&i.setAttribute("nonce",s.nc),i.setAttribute("data-webpack","@tsparticles/plugin-poisson-disc:"+r),i.src=e),a[e]=[t];var u=(t,r)=>{i.onerror=i.onload=null,clearTimeout(d);var o=a[e];if(delete a[e],i.parentNode&&i.parentNode.removeChild(i),o&&o.forEach(e=>e(r)),t)return t(r)},d=setTimeout(u.bind(null,void 0,{type:"timeout",target:i}),12e4);i.onerror=u.bind(null,i.onerror),i.onload=u.bind(null,i.onload),n&&document.head.appendChild(i)},s.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},s.g.importScripts&&(c=s.g.location+"");var a,c,p=s.g.document;if(!c&&p&&(p.currentScript&&"SCRIPT"===p.currentScript.tagName.toUpperCase()&&(c=p.currentScript.src),!c)){var l=p.getElementsByTagName("script");if(l.length)for(var u=l.length-1;u>-1&&(!c||!/^http(s?):/.test(c));)c=l[u--].src}if(!c)throw Error("Automatic publicPath is not supported in this browser");s.p=c=c.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),t={189:0},s.f.j=(e,r)=>{var o=s.o(t,e)?t[e]:void 0;if(0!==o)if(o)r.push(o[2]);else{var i=new Promise((r,i)=>o=t[e]=[r,i]);r.push(o[2]=i);var n=s.p+s.u(e),a=Error();s.l(n,r=>{if(s.o(t,e)&&(0!==(o=t[e])&&(t[e]=void 0),o)){var i=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;a.message="Loading chunk "+e+` failed.
2
+ (`+i+": "+n+")",a.name="ChunkLoadError",a.type=i,a.request=n,o[1](a)}},"chunk-"+e,e)}},r=(e,r)=>{var o,i,[n,a,c]=r,p=0;if(n.some(e=>0!==t[e])){for(o in a)s.o(a,o)&&(s.m[o]=a[o]);c&&c(s)}for(e&&e(r);p<n.length;p++)i=n[p],s.o(t,i)&&t[i]&&t[i][0](),t[i]=0},(o=this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).forEach(r.bind(null,0)),o.push=r.bind(null,o.push.bind(o));var d={};async function f(e){e.checkVersion("4.0.0-beta.0"),await e.register(async e=>{let{PoissonDiscPlugin:t}=await s.e(964).then(s.bind(s,964));e.addPlugin(new t)})}return s.r(d),s.d(d,{loadPoissonDiscPlugin:()=>f}),d})());
@@ -21,7 +21,7 @@ export declare class PoissonDisc {
21
21
  initialiseGrid(): void;
22
22
  reset(): void;
23
23
  run(): Promise<void>;
24
- steps(steps: number): Promise<void>;
24
+ steps(steps: number): void;
25
25
  private _getNewPoint;
26
26
  private _step;
27
27
  }
@@ -1,8 +1,7 @@
1
1
  import { type Container, type IContainerPlugin, type IPlugin, type RecursivePartial } from "@tsparticles/engine";
2
2
  import type { IPoissonOptions, PoissonOptions } from "./types.js";
3
3
  export declare class PoissonDiscPlugin implements IPlugin {
4
- readonly id: string;
5
- constructor();
4
+ readonly id = "poisson";
6
5
  getPlugin(container: Container): Promise<IContainerPlugin>;
7
6
  loadOptions(_container: Container, options: PoissonOptions, source?: RecursivePartial<IPoissonOptions>): void;
8
7
  needsPlugin(options?: RecursivePartial<IPoissonOptions>): boolean;
@@ -1,6 +1,6 @@
1
1
  import { type IContainerPlugin, type ICoordinates } from "@tsparticles/engine";
2
2
  import type { PoissonContainer } from "./types.js";
3
- import { PoissonDisc } from "./PoissonDisc.js";
3
+ import type { PoissonDisc } from "./PoissonDisc.js";
4
4
  export declare class PoissonDiscPluginInstance implements IContainerPlugin {
5
5
  poissonDisc?: PoissonDisc;
6
6
  redrawTimeout?: number | NodeJS.Timeout;
@@ -12,6 +12,11 @@
12
12
  exports.Poisson = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  class Poisson {
15
+ dimensions;
16
+ enable;
17
+ radius;
18
+ retries;
19
+ steps;
15
20
  constructor() {
16
21
  this.enable = false;
17
22
  this.dimensions = 2;
@@ -12,6 +12,17 @@
12
12
  exports.PoissonDisc = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  class PoissonDisc {
15
+ active;
16
+ cellSize;
17
+ cols;
18
+ dimensions;
19
+ firstPoint;
20
+ grid;
21
+ points;
22
+ radius;
23
+ retries;
24
+ rows;
25
+ size;
15
26
  constructor(size, radius, retries, dimensions, firstPoint) {
16
27
  this.size = { ...size };
17
28
  this.radius = radius;
@@ -74,18 +85,22 @@
74
85
  }
75
86
  async run() {
76
87
  this.reset();
77
- const minCount = 0, step = 1;
88
+ const minCount = 0, step = 1, yieldEvery = 100, yieldStepModule = 0;
89
+ let iterations = 0;
78
90
  while (this.active.length > minCount) {
79
- await this.steps(step);
91
+ this.steps(step);
92
+ if (++iterations % yieldEvery === yieldStepModule) {
93
+ await new Promise(resolve => setTimeout(resolve));
94
+ }
80
95
  }
81
96
  }
82
- async steps(steps) {
97
+ steps(steps) {
83
98
  const minCount = 0;
84
99
  for (let i = 0; i < steps; i++) {
85
100
  if (this.active.length <= minCount) {
86
101
  continue;
87
102
  }
88
- await this._step();
103
+ this._step();
89
104
  }
90
105
  }
91
106
  _getNewPoint(currentPoint, tries) {
@@ -99,79 +114,76 @@
99
114
  x: Math.floor(newPoint.x / this.cellSize),
100
115
  y: Math.floor(newPoint.y / this.cellSize),
101
116
  };
102
- if (newPoint.x > minCoordinate &&
103
- newPoint.x < this.size.width &&
104
- newPoint.y > minCoordinate &&
105
- newPoint.y < this.size.height) {
106
- const row = this.grid[newGridCoords.y];
107
- if (!row) {
108
- return;
109
- }
110
- const point = row[newGridCoords.x];
111
- if (point === undefined) {
112
- return;
113
- }
114
- if (point < gridMinValue) {
115
- for (let i = -1; i <= maxNeighbourIndex; i++) {
116
- for (let j = -1; j <= maxNeighbourIndex; j++) {
117
- const neighbourGrid = {
118
- x: newGridCoords.x + j,
119
- y: newGridCoords.y + i,
120
- };
121
- if (neighbourGrid.x >= minCoordinate &&
122
- neighbourGrid.y >= minCoordinate &&
123
- neighbourGrid.x < this.cols &&
124
- neighbourGrid.y < this.rows &&
125
- (neighbourGrid.x !== newGridCoords.x || neighbourGrid.y !== newGridCoords.y)) {
126
- if (point >= gridMinValue) {
127
- const neighbourIndex = point, neighbour = this.points[neighbourIndex];
128
- if (!neighbour) {
129
- continue;
130
- }
131
- const dist = (0, engine_1.getDistance)(newPoint, neighbour.position);
132
- if (dist < this.radius) {
133
- return;
134
- }
135
- }
136
- }
137
- }
138
- }
139
- }
140
- else {
141
- return;
142
- }
117
+ if (newPoint.x <= minCoordinate ||
118
+ newPoint.x >= this.size.width ||
119
+ newPoint.y <= minCoordinate ||
120
+ newPoint.y >= this.size.height) {
121
+ return;
143
122
  }
144
- else {
123
+ const row = this.grid[newGridCoords.y];
124
+ if (!row) {
145
125
  return;
146
126
  }
147
- return newPoint;
148
- }
149
- async _step() {
150
- const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
151
- return new Promise(resolve => {
152
- let foundNewPoint = false;
153
- for (let tries = 0; tries < this.retries; tries++) {
154
- const randomActivePointIndex = this.active[randomActive];
155
- if (randomActivePointIndex === undefined) {
127
+ const cellValue = row[newGridCoords.x];
128
+ if (cellValue === undefined) {
129
+ return;
130
+ }
131
+ if (cellValue >= gridMinValue) {
132
+ return;
133
+ }
134
+ for (let i = -1; i <= maxNeighbourIndex; i++) {
135
+ for (let j = -1; j <= maxNeighbourIndex; j++) {
136
+ if (!i && !j) {
137
+ continue;
138
+ }
139
+ const neighbourGrid = {
140
+ x: newGridCoords.x + j,
141
+ y: newGridCoords.y + i,
142
+ };
143
+ if (neighbourGrid.x < minCoordinate ||
144
+ neighbourGrid.y < minCoordinate ||
145
+ neighbourGrid.x >= this.cols ||
146
+ neighbourGrid.y >= this.rows) {
147
+ continue;
148
+ }
149
+ const neighbourCellValue = this.grid[neighbourGrid.y]?.[neighbourGrid.x];
150
+ if (neighbourCellValue === undefined || neighbourCellValue < gridMinValue) {
156
151
  continue;
157
152
  }
158
- const point = this.points[randomActivePointIndex];
159
- if (!point) {
153
+ const neighbour = this.points[neighbourCellValue];
154
+ if (!neighbour) {
160
155
  continue;
161
156
  }
162
- const newPoint = this._getNewPoint(point, tries);
163
- if (newPoint) {
164
- foundNewPoint = true;
165
- this.addPoint(newPoint);
166
- break;
157
+ if ((0, engine_1.getDistance)(newPoint, neighbour.position) < this.radius) {
158
+ return;
167
159
  }
168
160
  }
169
- if (!foundNewPoint) {
170
- const deleteCount = 1;
171
- this.active.splice(randomActive, deleteCount);
161
+ }
162
+ return newPoint;
163
+ }
164
+ _step() {
165
+ const minCount = 0, randomActive = this.getRandom(minCount, this.active.length);
166
+ let foundNewPoint = false;
167
+ for (let tries = 0; tries < this.retries; tries++) {
168
+ const randomActivePointIndex = this.active[randomActive];
169
+ if (randomActivePointIndex === undefined) {
170
+ continue;
171
+ }
172
+ const point = this.points[randomActivePointIndex];
173
+ if (!point) {
174
+ continue;
172
175
  }
173
- resolve();
174
- });
176
+ const newPoint = this._getNewPoint(point, tries);
177
+ if (newPoint) {
178
+ foundNewPoint = true;
179
+ this.addPoint(newPoint);
180
+ break;
181
+ }
182
+ }
183
+ if (!foundNewPoint) {
184
+ const deleteCount = 1;
185
+ this.active.splice(randomActive, deleteCount);
186
+ }
175
187
  }
176
188
  }
177
189
  exports.PoissonDisc = PoissonDisc;
@@ -46,9 +46,7 @@ var __importStar = (this && this.__importStar) || (function () {
46
46
  exports.PoissonDiscPlugin = void 0;
47
47
  const Poisson_js_1 = require("./Options/Classes/Poisson.js");
48
48
  class PoissonDiscPlugin {
49
- constructor() {
50
- this.id = "poisson";
51
- }
49
+ id = "poisson";
52
50
  async getPlugin(container) {
53
51
  const { PoissonDiscPluginInstance } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDiscPluginInstance.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDiscPluginInstance.js"], resolve_1, reject_1); }).then(__importStar));
54
52
  return new PoissonDiscPluginInstance(container);
@@ -1,18 +1,55 @@
1
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2
+ if (k2 === undefined) k2 = k;
3
+ var desc = Object.getOwnPropertyDescriptor(m, k);
4
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
5
+ desc = { enumerable: true, get: function() { return m[k]; } };
6
+ }
7
+ Object.defineProperty(o, k2, desc);
8
+ }) : (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ o[k2] = m[k];
11
+ }));
12
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
13
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
14
+ }) : function(o, v) {
15
+ o["default"] = v;
16
+ });
17
+ var __importStar = (this && this.__importStar) || (function () {
18
+ var ownKeys = function(o) {
19
+ ownKeys = Object.getOwnPropertyNames || function (o) {
20
+ var ar = [];
21
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
22
+ return ar;
23
+ };
24
+ return ownKeys(o);
25
+ };
26
+ return function (mod) {
27
+ if (mod && mod.__esModule) return mod;
28
+ var result = {};
29
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
30
+ __setModuleDefault(result, mod);
31
+ return result;
32
+ };
33
+ })();
1
34
  (function (factory) {
2
35
  if (typeof module === "object" && typeof module.exports === "object") {
3
36
  var v = factory(require, exports);
4
37
  if (v !== undefined) module.exports = v;
5
38
  }
6
39
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/engine", "./PoissonDisc.js"], factory);
40
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
41
  }
9
42
  })(function (require, exports) {
10
43
  "use strict";
44
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
11
45
  Object.defineProperty(exports, "__esModule", { value: true });
12
46
  exports.PoissonDiscPluginInstance = void 0;
13
47
  const engine_1 = require("@tsparticles/engine");
14
- const PoissonDisc_js_1 = require("./PoissonDisc.js");
15
48
  class PoissonDiscPluginInstance {
49
+ poissonDisc;
50
+ redrawTimeout;
51
+ _container;
52
+ _currentIndex;
16
53
  constructor(container) {
17
54
  this._container = container;
18
55
  this._currentIndex = 0;
@@ -38,6 +75,9 @@
38
75
  const timeout = 250;
39
76
  this.redrawTimeout = setTimeout(() => {
40
77
  void (async () => {
78
+ if (this._container.destroyed) {
79
+ return;
80
+ }
41
81
  await this._initData();
42
82
  await container.particles.redraw();
43
83
  })();
@@ -52,12 +92,13 @@
52
92
  return;
53
93
  }
54
94
  this._currentIndex = 0;
55
- this.poissonDisc = new PoissonDisc_js_1.PoissonDisc(canvasSize, poissonOptions.radius
95
+ const { PoissonDisc } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDisc.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDisc.js"], resolve_1, reject_1); }).then(__importStar));
96
+ this.poissonDisc = new PoissonDisc(canvasSize, poissonOptions.radius
56
97
  ? poissonOptions.radius * pixelRatio
57
98
  : Math.max((0, engine_1.getRangeMax)(particlesOptions.size.value) * pixelRatio, Math.sqrt((canvasSize.width * canvasSize.height) / particlesOptions.number.value)), poissonOptions.retries, poissonOptions.dimensions);
58
99
  const noSteps = 0;
59
100
  if (poissonOptions.steps > noSteps) {
60
- await this.poissonDisc.steps(poissonOptions.steps);
101
+ this.poissonDisc.steps(poissonOptions.steps);
61
102
  }
62
103
  else {
63
104
  await this.poissonDisc.run();
package/umd/index.js CHANGED
@@ -45,7 +45,7 @@ var __importStar = (this && this.__importStar) || (function () {
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.loadPoissonDiscPlugin = loadPoissonDiscPlugin;
47
47
  async function loadPoissonDiscPlugin(engine) {
48
- engine.checkVersion("4.0.0-alpha.5");
48
+ engine.checkVersion("4.0.0-beta.0");
49
49
  await engine.register(async (e) => {
50
50
  const { PoissonDiscPlugin } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./PoissonDiscPlugin.js"))) : new Promise((resolve_1, reject_1) => { require(["./PoissonDiscPlugin.js"], resolve_1, reject_1); }).then(__importStar));
51
51
  e.addPlugin(new PoissonDiscPlugin());
package/336.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see 336.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[336],{336(i,t,s){s.d(t,{PoissonDiscPluginInstance:()=>n});var e=s(303);class o{constructor(i,t,s,e,o){this.size={...i},this.radius=t,this.retries=s,this.dimensions=e,this.cellSize=Math.floor(this.radius/Math.sqrt(this.dimensions)),this.cols=Math.floor(this.size.width/this.cellSize),this.rows=Math.floor(this.size.height/this.cellSize),this.points=[],this.active=[],this.grid=[],this.firstPoint=o?{...o}:void 0,this.reset()}addPoint(i){const t={position:{...i},gridPosition:{x:Math.floor(i.x/this.cellSize),y:Math.floor(i.y/this.cellSize)}},s=this.points.length,e=this.grid[t.gridPosition.y];e&&(this.points.push(t),e[t.gridPosition.x]=s,this.active.push(s))}getRandom(i,t){return Math.floor((0,e.getRandom)()*(t-i))+i}initialiseGrid(){for(let i=0;i<=this.rows;i++){this.grid[i]=[];const t=this.grid[i];if(t)for(let i=0;i<=this.cols;i++)t[i]=-1}}reset(){if(this.points=[],this.active=[],this.grid=[],this.initialiseGrid(),this.firstPoint)this.addPoint(this.firstPoint);else{const i=0;this.addPoint({x:this.getRandom(i,this.size.width),y:this.getRandom(i,this.size.height)})}}async run(){this.reset();for(;this.active.length>0;)await this.steps(1)}async steps(i){for(let t=0;t<i;t++)this.active.length<=0||await this._step()}_getNewPoint(i,t){const s=t*(e.doublePI/this.retries),o=this.getRandom(this.radius,this.radius*e.double),n=Math.cos(s)*o,h=Math.sin(s)*o,r={x:Math.floor(i.position.x+n),y:Math.floor(i.position.y+h)},a=Math.floor(r.x/this.cellSize),c=Math.floor(r.y/this.cellSize);if(r.x>0&&r.x<this.size.width&&r.y>0&&r.y<this.size.height){{const i=this.grid[c];if(!i)return;const t=i[a];if(void 0===t)return;if(!(t<0))return;for(let i=-1;i<=1;i++)for(let s=-1;s<=1;s++){const o={x:a+s,y:c+i};if(o.x>=0&&o.y>=0&&o.x<this.cols&&o.y<this.rows&&(o.x!==a||o.y!==c)&&t>=0){const i=t,s=this.points[i];if(!s)continue;if((0,e.getDistance)(r,s.position)<this.radius)return}}}return r}}async _step(){const i=this.getRandom(0,this.active.length);return new Promise((t=>{let s=!1;for(let t=0;t<this.retries;t++){const e=this.active[i];if(void 0===e)continue;const o=this.points[e];if(!o)continue;const n=this._getNewPoint(o,t);if(n){s=!0,this.addPoint(n);break}}if(!s){const t=1;this.active.splice(i,t)}t()}))}}class n{constructor(i){this._container=i,this._currentIndex=0}async init(){await this._initData()}particlePosition(i){const t=this._container.actualOptions.poisson;if(this.poissonDisc&&t?.enable&&!(this._currentIndex>=this.poissonDisc.points.length))return i??this.poissonDisc.points[this._currentIndex++]?.position}resize(){const i=this._container,t=i.actualOptions.poisson;if(!t?.enable)return;this.redrawTimeout&&clearTimeout(this.redrawTimeout);this.redrawTimeout=setTimeout((()=>{(async()=>{await this._initData(),await i.particles.redraw()})()}),250)}stop(){delete this.poissonDisc}async _initData(){const i=this._container,t=i.actualOptions.poisson,s=i.actualOptions.particles,n=i.canvas.size,h=i.retina.pixelRatio;if(!t?.enable)return;this._currentIndex=0,this.poissonDisc=new o(n,t.radius?t.radius*h:Math.max((0,e.getRangeMax)(s.size.value)*h,Math.sqrt(n.width*n.height/s.number.value)),t.retries,t.dimensions);t.steps>0?await this.poissonDisc.steps(t.steps):await this.poissonDisc.run()}}}}]);
@@ -1 +0,0 @@
1
- /*! tsParticles Poisson Disc Plugin v4.0.0-alpha.5 by Matteo Bruni */
package/879.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see 879.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_plugin_poisson_disc=this.webpackChunk_tsparticles_plugin_poisson_disc||[]).push([[879],{879(s,i,n){n.d(i,{PoissonDiscPlugin:()=>t});var e=n(303);class o{constructor(){this.enable=!1,this.dimensions=2,this.radius=0,this.retries=30,this.steps=0}load(s){(0,e.isNull)(s)||(void 0!==s.enable&&(this.enable=s.enable),void 0!==s.dimensions&&(this.dimensions=s.dimensions),void 0!==s.radius&&(this.radius=s.radius),void 0!==s.retries&&(this.retries=s.retries))}}class t{constructor(){this.id="poisson"}async getPlugin(s){const{PoissonDiscPluginInstance:i}=await n.e(336).then(n.bind(n,336));return new i(s)}loadOptions(s,i,n){if(!this.needsPlugin(i)&&!this.needsPlugin(n))return;let e=i.poisson;void 0===e?.load&&(i.poisson=e=new o),e.load(n?.poisson)}needsPlugin(s){return s?.poisson?.enable??!1}}}}]);
@@ -1 +0,0 @@
1
- /*! tsParticles Poisson Disc Plugin v4.0.0-alpha.5 by Matteo Bruni */
@@ -1 +0,0 @@
1
- /*! tsParticles Poisson Disc Plugin v4.0.0-alpha.5 by Matteo Bruni */