@tsparticles/path-grid 4.0.0-alpha.14

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.
@@ -0,0 +1,317 @@
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-alpha.14
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__ = ({
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 */ gridPathName: () => (/* binding */ gridPathName),\n/* harmony export */ loadGridPath: () => (/* binding */ loadGridPath)\n/* harmony export */ });\nconst gridPathName = \"gridPathGenerator\";\nasync function loadGridPath(engine) {\n engine.checkVersion(\"4.0.0-alpha.14\");\n await engine.register((e)=>{\n e.addPathGenerator(gridPathName, async (container)=>{\n const { GridPathGenerator } = await __webpack_require__.e(/*! import() */ \"dist_browser_GridPathGenerator_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./GridPathGenerator.js */ \"./dist/browser/GridPathGenerator.js\"));\n return new GridPathGenerator(container);\n });\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/path-grid/./dist/browser/index.js?\n}");
38
+
39
+ /***/ },
40
+
41
+ /***/ "@tsparticles/engine"
42
+ /*!*********************************************************************************************************************************!*\
43
+ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
44
+ \*********************************************************************************************************************************/
45
+ (module) {
46
+
47
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
48
+
49
+ /***/ }
50
+
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
+ /******/ // 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
+ /******/ // Create a new module (and put it into the cache)
70
+ /******/ var module = __webpack_module_cache__[moduleId] = {
71
+ /******/ // no module.id needed
72
+ /******/ // no module.loaded needed
73
+ /******/ exports: {}
74
+ /******/ };
75
+ /******/
76
+ /******/ // Execute the module function
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/path-grid:";
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.path.grid": 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_path_grid"] = this["webpackChunk_tsparticles_path_grid"] || [];
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
+ });
@@ -0,0 +1,2 @@
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 a(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return i[e](r,r.exports,a),r.exports}a.m=i,a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce((t,r)=>(a.f[r](e,t),t),[])),a.u=e=>""+e+".min.js",a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),s={},a.l=(e,t,r,o)=>{if(s[e])return void s[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/path-grid:"+r){i=l;break}}i||(n=!0,(i=document.createElement("script")).charset="utf-8",a.nc&&i.setAttribute("nonce",a.nc),i.setAttribute("data-webpack","@tsparticles/path-grid:"+r),i.src=e),s[e]=[t];var u=(t,r)=>{i.onerror=i.onload=null,clearTimeout(d);var o=s[e];if(delete s[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)},a.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.g.importScripts&&(c=a.g.location+"");var s,c,p=a.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");a.p=c=c.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),t={80:0},a.f.j=(e,r)=>{var o=a.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=a.p+a.u(e),s=Error();a.l(n,r=>{if(a.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;s.message="Loading chunk "+e+` failed.
2
+ (`+i+": "+n+")",s.name="ChunkLoadError",s.type=i,s.request=n,o[1](s)}},"chunk-"+e,e)}},r=(e,r)=>{var o,i,[n,s,c]=r,p=0;if(n.some(e=>0!==t[e])){for(o in s)a.o(s,o)&&(a.m[o]=s[o]);c&&c(a)}for(e&&e(r);p<n.length;p++)i=n[p],a.o(t,i)&&t[i]&&t[i][0](),t[i]=0},(o=this.webpackChunk_tsparticles_path_grid=this.webpackChunk_tsparticles_path_grid||[]).forEach(r.bind(null,0)),o.push=r.bind(null,o.push.bind(o));var d={};a.r(d),a.d(d,{gridPathName:()=>f,loadGridPath:()=>h});let f="gridPathGenerator";async function h(e){e.checkVersion("4.0.0-alpha.14"),await e.register(e=>{e.addPathGenerator(f,async e=>{let{GridPathGenerator:t}=await a.e(915).then(a.bind(a,915));return new t(e)})})}return d})());
@@ -0,0 +1,13 @@
1
+ import { type Container, type IMovePathGenerator, Vector } from "@tsparticles/engine";
2
+ import type { GridPathParticle } from "./GridPathParticle.js";
3
+ import type { IGridPathOptions } from "./IGridPathOptions.js";
4
+ export declare class GridPathGenerator implements IMovePathGenerator {
5
+ readonly options: IGridPathOptions;
6
+ private readonly _container;
7
+ constructor(container: Container);
8
+ generate(p: GridPathParticle): Vector;
9
+ init(): void;
10
+ reset(p: GridPathParticle): void;
11
+ update(): void;
12
+ private _generateMazeGraph;
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { ICoordinates, Particle } from "@tsparticles/engine";
2
+ export type GridPathParticle = Particle & {
3
+ grid?: {
4
+ cellPosition: ICoordinates;
5
+ direction: number;
6
+ speed: number;
7
+ };
8
+ };
@@ -0,0 +1,5 @@
1
+ export interface IGridPathOptions {
2
+ autoMaze?: boolean;
3
+ cellSize: number;
4
+ graph?: Record<string, number[]>;
5
+ }
@@ -0,0 +1,3 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare const gridPathName = "gridPathGenerator";
3
+ export declare function loadGridPath(engine: Engine): Promise<void>;
@@ -0,0 +1,120 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "@tsparticles/engine"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GridPathGenerator = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ const dirs = [
15
+ engine_1.Vector.create(engine_1.identity, engine_1.originPoint.y),
16
+ engine_1.Vector.create(engine_1.originPoint.x, engine_1.identity),
17
+ engine_1.Vector.create(-engine_1.identity, engine_1.originPoint.y),
18
+ engine_1.Vector.create(engine_1.originPoint.x, -engine_1.identity),
19
+ ], opposite = [2, 3, 0, 1], minLength = 0;
20
+ class GridPathGenerator {
21
+ options;
22
+ _container;
23
+ constructor(container) {
24
+ this._container = container;
25
+ this.options = {
26
+ cellSize: 40,
27
+ graph: undefined,
28
+ autoMaze: false,
29
+ };
30
+ }
31
+ generate(p) {
32
+ const size = this.options.cellSize;
33
+ p.grid ??= {
34
+ direction: Math.trunc((0, engine_1.getRandom)() * dirs.length),
35
+ speed: p.velocity.length,
36
+ cellPosition: {
37
+ x: Math.floor(p.position.x / size),
38
+ y: Math.floor(p.position.y / size),
39
+ },
40
+ };
41
+ const grid = p.grid, c = {
42
+ x: Math.floor(p.position.x / size),
43
+ y: Math.floor(p.position.y / size),
44
+ };
45
+ if (c.x !== grid.cellPosition.x || c.y !== grid.cellPosition.y) {
46
+ grid.cellPosition.x = c.x;
47
+ grid.cellPosition.y = c.y;
48
+ const key = `${c.x},${c.y}`, allowed = this.options.graph?.[key];
49
+ if (allowed && allowed.length > minLength) {
50
+ grid.direction = allowed[Math.trunc((0, engine_1.getRandom)() * allowed.length)];
51
+ }
52
+ else if (!this.options.graph) {
53
+ const turn = Math.trunc((0, engine_1.getRandom)() * 3) - 1;
54
+ grid.direction = (grid.direction + turn + 4) % dirs.length;
55
+ }
56
+ }
57
+ p.velocity.x = 0;
58
+ p.velocity.y = 0;
59
+ const d = dirs[grid.direction];
60
+ return engine_1.Vector.create(d.x * grid.speed, d.y * grid.speed);
61
+ }
62
+ init() {
63
+ const source = this._container.actualOptions.particles.move.path.options;
64
+ this.options.cellSize = source["cellSize"] ?? this.options.cellSize;
65
+ this.options.autoMaze = source["autoMaze"] ?? this.options.autoMaze;
66
+ this.options.graph = source["graph"];
67
+ if (this.options.autoMaze) {
68
+ const canvas = this._container.canvas.size, cellSize = this.options.cellSize, size = {
69
+ width: Math.ceil(canvas.width / cellSize),
70
+ height: Math.ceil(canvas.height / cellSize),
71
+ };
72
+ this.options.graph = this._generateMazeGraph(size);
73
+ }
74
+ }
75
+ reset(p) {
76
+ delete p.grid;
77
+ }
78
+ update() {
79
+ }
80
+ _generateMazeGraph({ height, width }) {
81
+ const graph = {}, visited = [];
82
+ for (let y = 0; y < height; y++) {
83
+ visited[y] = [];
84
+ }
85
+ const stack = [{ x: engine_1.originPoint.x, y: engine_1.originPoint.y }];
86
+ while (stack.length > 0) {
87
+ const { x, y } = stack[stack.length - 1];
88
+ if (!visited[y][x]) {
89
+ visited[y][x] = true;
90
+ }
91
+ const dirsOrder = [0, 1, 2, 3].sort(() => (0, engine_1.getRandom)() - 0.5);
92
+ let moved = false;
93
+ for (const d of dirsOrder) {
94
+ const n = {
95
+ x: x + (d === 0 ? 1 : d === 2 ? -1 : 0),
96
+ y: y + (d === 1 ? 1 : d === 3 ? -1 : 0),
97
+ };
98
+ if (n.x < 0 || n.y < 0 || n.x >= width || n.y >= height) {
99
+ continue;
100
+ }
101
+ if (!visited[n.y][n.x]) {
102
+ const key = `${x},${y}`, nKey = `${n.x},${n.y}`;
103
+ graph[key] ??= [];
104
+ graph[nKey] ??= [];
105
+ graph[key].push(d);
106
+ graph[nKey].push(opposite[d]);
107
+ stack.push(n);
108
+ moved = true;
109
+ break;
110
+ }
111
+ }
112
+ if (!moved) {
113
+ stack.pop();
114
+ }
115
+ }
116
+ return graph;
117
+ }
118
+ }
119
+ exports.GridPathGenerator = GridPathGenerator;
120
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
@@ -0,0 +1,12 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ });
package/umd/index.js ADDED
@@ -0,0 +1,58 @@
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
+ })();
34
+ (function (factory) {
35
+ if (typeof module === "object" && typeof module.exports === "object") {
36
+ var v = factory(require, exports);
37
+ if (v !== undefined) module.exports = v;
38
+ }
39
+ else if (typeof define === "function" && define.amd) {
40
+ define(["require", "exports"], factory);
41
+ }
42
+ })(function (require, exports) {
43
+ "use strict";
44
+ var __syncRequire = typeof module === "object" && typeof module.exports === "object";
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.gridPathName = void 0;
47
+ exports.loadGridPath = loadGridPath;
48
+ exports.gridPathName = "gridPathGenerator";
49
+ async function loadGridPath(engine) {
50
+ engine.checkVersion("4.0.0-alpha.14");
51
+ await engine.register(e => {
52
+ e.addPathGenerator(exports.gridPathName, async (container) => {
53
+ const { GridPathGenerator } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./GridPathGenerator.js"))) : new Promise((resolve_1, reject_1) => { require(["./GridPathGenerator.js"], resolve_1, reject_1); }).then(__importStar));
54
+ return new GridPathGenerator(container);
55
+ });
56
+ });
57
+ }
58
+ });