@tsparticles/plugin-emitters-shape-path 3.0.0-beta.4

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 (40) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -0
  3. package/browser/EmittersPathShape.js +73 -0
  4. package/browser/EmittersPathShapeGenerator.js +9 -0
  5. package/browser/Options/Classes/EmittersPathShapeOptions.js +13 -0
  6. package/browser/Options/Interfaces/IEmittersPathShapeOptions.js +1 -0
  7. package/browser/index.js +7 -0
  8. package/browser/package.json +1 -0
  9. package/browser/utils.js +29 -0
  10. package/cjs/EmittersPathShape.js +77 -0
  11. package/cjs/EmittersPathShapeGenerator.js +13 -0
  12. package/cjs/Options/Classes/EmittersPathShapeOptions.js +17 -0
  13. package/cjs/Options/Interfaces/IEmittersPathShapeOptions.js +2 -0
  14. package/cjs/index.js +11 -0
  15. package/cjs/package.json +1 -0
  16. package/cjs/utils.js +34 -0
  17. package/esm/EmittersPathShape.js +73 -0
  18. package/esm/EmittersPathShapeGenerator.js +9 -0
  19. package/esm/Options/Classes/EmittersPathShapeOptions.js +13 -0
  20. package/esm/Options/Interfaces/IEmittersPathShapeOptions.js +1 -0
  21. package/esm/index.js +7 -0
  22. package/esm/package.json +1 -0
  23. package/esm/utils.js +29 -0
  24. package/package.json +109 -0
  25. package/report.html +39 -0
  26. package/tsparticles.plugin.emitters.shape.path.js +257 -0
  27. package/tsparticles.plugin.emitters.shape.path.min.js +2 -0
  28. package/tsparticles.plugin.emitters.shape.path.min.js.LICENSE.txt +1 -0
  29. package/types/EmittersPathShape.d.ts +12 -0
  30. package/types/EmittersPathShapeGenerator.d.ts +6 -0
  31. package/types/Options/Classes/EmittersPathShapeOptions.d.ts +7 -0
  32. package/types/Options/Interfaces/IEmittersPathShapeOptions.d.ts +4 -0
  33. package/types/index.d.ts +2 -0
  34. package/types/utils.d.ts +3 -0
  35. package/umd/EmittersPathShape.js +87 -0
  36. package/umd/EmittersPathShapeGenerator.js +23 -0
  37. package/umd/Options/Classes/EmittersPathShapeOptions.js +27 -0
  38. package/umd/Options/Interfaces/IEmittersPathShapeOptions.js +12 -0
  39. package/umd/index.js +21 -0
  40. package/umd/utils.js +44 -0
@@ -0,0 +1,257 @@
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
+ * v3.0.0-beta.4
8
+ */
9
+ (function webpackUniversalModuleDefinition(root, factory) {
10
+ if(typeof exports === 'object' && typeof module === 'object')
11
+ module.exports = factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"));
12
+ else if(typeof define === 'function' && define.amd)
13
+ define(["@tsparticles/plugin-emitters", "@tsparticles/engine"], factory);
14
+ else {
15
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine")) : factory(root["window"], root["window"]);
16
+ for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
+ }
18
+ })(this, (__WEBPACK_EXTERNAL_MODULE__68__, __WEBPACK_EXTERNAL_MODULE__533__) => {
19
+ return /******/ (() => { // webpackBootstrap
20
+ /******/ "use strict";
21
+ /******/ var __webpack_modules__ = ({
22
+
23
+ /***/ 533:
24
+ /***/ ((module) => {
25
+
26
+ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
27
+
28
+ /***/ }),
29
+
30
+ /***/ 68:
31
+ /***/ ((module) => {
32
+
33
+ module.exports = __WEBPACK_EXTERNAL_MODULE__68__;
34
+
35
+ /***/ })
36
+
37
+ /******/ });
38
+ /************************************************************************/
39
+ /******/ // The module cache
40
+ /******/ var __webpack_module_cache__ = {};
41
+ /******/
42
+ /******/ // The require function
43
+ /******/ function __webpack_require__(moduleId) {
44
+ /******/ // Check if module is in cache
45
+ /******/ var cachedModule = __webpack_module_cache__[moduleId];
46
+ /******/ if (cachedModule !== undefined) {
47
+ /******/ return cachedModule.exports;
48
+ /******/ }
49
+ /******/ // Create a new module (and put it into the cache)
50
+ /******/ var module = __webpack_module_cache__[moduleId] = {
51
+ /******/ // no module.id needed
52
+ /******/ // no module.loaded needed
53
+ /******/ exports: {}
54
+ /******/ };
55
+ /******/
56
+ /******/ // Execute the module function
57
+ /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
58
+ /******/
59
+ /******/ // Return the exports of the module
60
+ /******/ return module.exports;
61
+ /******/ }
62
+ /******/
63
+ /************************************************************************/
64
+ /******/ /* webpack/runtime/define property getters */
65
+ /******/ (() => {
66
+ /******/ // define getter functions for harmony exports
67
+ /******/ __webpack_require__.d = (exports, definition) => {
68
+ /******/ for(var key in definition) {
69
+ /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
70
+ /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
71
+ /******/ }
72
+ /******/ }
73
+ /******/ };
74
+ /******/ })();
75
+ /******/
76
+ /******/ /* webpack/runtime/hasOwnProperty shorthand */
77
+ /******/ (() => {
78
+ /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
79
+ /******/ })();
80
+ /******/
81
+ /******/ /* webpack/runtime/make namespace object */
82
+ /******/ (() => {
83
+ /******/ // define __esModule on exports
84
+ /******/ __webpack_require__.r = (exports) => {
85
+ /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
86
+ /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
87
+ /******/ }
88
+ /******/ Object.defineProperty(exports, '__esModule', { value: true });
89
+ /******/ };
90
+ /******/ })();
91
+ /******/
92
+ /************************************************************************/
93
+ var __webpack_exports__ = {};
94
+ // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
95
+ (() => {
96
+ // ESM COMPAT FLAG
97
+ __webpack_require__.r(__webpack_exports__);
98
+
99
+ // EXPORTS
100
+ __webpack_require__.d(__webpack_exports__, {
101
+ loadEmittersShapePath: () => (/* binding */ loadEmittersShapePath)
102
+ });
103
+
104
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/plugin-emitters","commonjs2":"@tsparticles/plugin-emitters","amd":"@tsparticles/plugin-emitters","root":"window"}
105
+ var plugin_emitters_root_window_ = __webpack_require__(68);
106
+ // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
107
+ var engine_root_window_ = __webpack_require__(533);
108
+ ;// CONCATENATED MODULE: ./dist/browser/utils.js
109
+
110
+ function generateRandomPointWithinPath(ctx, path, center, size) {
111
+ let randomPoint = null;
112
+ for (let attempts = 0; attempts < 100; attempts++) {
113
+ const tmpPoint = {
114
+ x: center.x + (0,engine_root_window_.getRandom)() * size.width - size.width / 2,
115
+ y: center.y + (0,engine_root_window_.getRandom)() * size.height - size.height / 2
116
+ };
117
+ if (ctx.isPointInPath(path, tmpPoint.x, tmpPoint.y)) {
118
+ randomPoint = tmpPoint;
119
+ break;
120
+ }
121
+ }
122
+ return randomPoint;
123
+ }
124
+ function generateRandomPointOnPathPerimeter(ctx, path, center, size) {
125
+ let randomPoint = null;
126
+ for (let attempts = 0; attempts < 100; attempts++) {
127
+ const tmpPoint = {
128
+ x: center.x + (0,engine_root_window_.getRandom)() * size.width - size.width / 2,
129
+ y: center.y + (0,engine_root_window_.getRandom)() * size.height - size.height / 2
130
+ };
131
+ if (ctx.isPointInStroke(path, tmpPoint.x, tmpPoint.y)) {
132
+ randomPoint = tmpPoint;
133
+ break;
134
+ }
135
+ }
136
+ return randomPoint;
137
+ }
138
+ ;// CONCATENATED MODULE: ./dist/browser/EmittersPathShape.js
139
+
140
+
141
+
142
+ class EmittersPathShape extends plugin_emitters_root_window_.EmitterShapeBase {
143
+ constructor(position, size, fill, options) {
144
+ super(position, size, fill, options);
145
+ const ctx = document.createElement("canvas").getContext("2d");
146
+ if (!ctx) {
147
+ throw new Error(`${engine_root_window_.errorPrefix} No 2d context available`);
148
+ }
149
+ this.checkContext = ctx;
150
+ this.points = options.points;
151
+ const pathData = this.points,
152
+ path = new Path2D(),
153
+ offset = {
154
+ x: position.x - size.width / 2,
155
+ y: position.y - size.height / 2
156
+ };
157
+ for (const [index, point] of pathData.entries()) {
158
+ const coords = {
159
+ x: offset.x + point.x * size.width / 100,
160
+ y: offset.y + point.y * size.height / 100
161
+ };
162
+ if (index === 0) {
163
+ path.moveTo(coords.x, coords.y);
164
+ } else {
165
+ path.lineTo(coords.x, coords.y);
166
+ }
167
+ }
168
+ if (pathData[0]) {
169
+ const coords = {
170
+ x: offset.x + pathData[0].x * size.width / 100,
171
+ y: offset.y + pathData[0].y * size.height / 100
172
+ };
173
+ path.lineTo(coords.x, coords.y);
174
+ }
175
+ this.path = path;
176
+ }
177
+ async init() {}
178
+ async randomPosition() {
179
+ const ctx = this.checkContext,
180
+ position = this.position,
181
+ size = this.size,
182
+ fill = this.fill,
183
+ path = this.path,
184
+ res = fill ? generateRandomPointWithinPath(ctx, path, position, size) : generateRandomPointOnPathPerimeter(ctx, path, position, size);
185
+ return res ? {
186
+ position: res
187
+ } : null;
188
+ }
189
+ resize(position, size) {
190
+ super.resize(position, size);
191
+ const pathData = this.points,
192
+ path = new Path2D(),
193
+ offset = {
194
+ x: position.x - size.width / 2,
195
+ y: position.y - size.height / 2
196
+ };
197
+ for (const [index, point] of pathData.entries()) {
198
+ const coords = {
199
+ x: offset.x + point.x * size.width / 100,
200
+ y: offset.y + point.y * size.height / 100
201
+ };
202
+ if (index === 0) {
203
+ path.moveTo(coords.x, coords.y);
204
+ } else {
205
+ path.lineTo(coords.x, coords.y);
206
+ }
207
+ }
208
+ if (pathData[0]) {
209
+ const coords = {
210
+ x: offset.x + pathData[0].x * size.width / 100,
211
+ y: offset.y + pathData[0].y * size.height / 100
212
+ };
213
+ path.lineTo(coords.x, coords.y);
214
+ }
215
+ this.path = path;
216
+ }
217
+ }
218
+ ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/EmittersPathShapeOptions.js
219
+ class EmittersPathShapeOptions {
220
+ constructor() {
221
+ this.points = [];
222
+ }
223
+ load(data) {
224
+ if (!data) {
225
+ return;
226
+ }
227
+ if (data.points !== undefined) {
228
+ this.points = data.points.map(t => ({
229
+ x: t.x ?? 50,
230
+ y: t.y ?? 50
231
+ }));
232
+ }
233
+ }
234
+ }
235
+ ;// CONCATENATED MODULE: ./dist/browser/EmittersPathShapeGenerator.js
236
+
237
+
238
+ class EmittersPathShapeGenerator {
239
+ generate(position, size, fill, options) {
240
+ const shapeOptions = new EmittersPathShapeOptions();
241
+ shapeOptions.load(options);
242
+ return new EmittersPathShape(position, size, fill, shapeOptions);
243
+ }
244
+ }
245
+ ;// CONCATENATED MODULE: ./dist/browser/index.js
246
+
247
+ async function loadEmittersShapePath(engine, refresh = true) {
248
+ const emittersEngine = engine;
249
+ emittersEngine.addEmitterShapeGenerator && emittersEngine.addEmitterShapeGenerator("path", new EmittersPathShapeGenerator());
250
+ await emittersEngine.refresh(refresh);
251
+ }
252
+ })();
253
+
254
+ /******/ return __webpack_exports__;
255
+ /******/ })()
256
+ ;
257
+ });
@@ -0,0 +1,2 @@
1
+ /*! For license information please see tsparticles.plugin.emitters.shape.path.min.js.LICENSE.txt */
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):e(t.window,t.window);for(var o in i)("object"==typeof exports?exports:t)[o]=i[o]}}(this,((t,e)=>(()=>{"use strict";var i={533:t=>{t.exports=e},68:e=>{e.exports=t}},o={};function n(t){var e=o[t];if(void 0!==e)return e.exports;var r=o[t]={exports:{}};return i[t](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{loadEmittersShapePath:()=>a});var t=n(68),e=n(533);class i extends t.EmitterShapeBase{constructor(t,i,o,n){super(t,i,o,n);const r=document.createElement("canvas").getContext("2d");if(!r)throw new Error(`${e.errorPrefix} No 2d context available`);this.checkContext=r,this.points=n.points;const s=this.points,a=new Path2D,h=t.x-i.width/2,c=t.y-i.height/2;for(const[t,e]of s.entries()){const o={x:h+e.x*i.width/100,y:c+e.y*i.height/100};0===t?a.moveTo(o.x,o.y):a.lineTo(o.x,o.y)}if(s[0]){const t={x:h+s[0].x*i.width/100,y:c+s[0].y*i.height/100};a.lineTo(t.x,t.y)}this.path=a}async init(){}async randomPosition(){const t=this.checkContext,i=this.position,o=this.size,n=this.fill,r=this.path,s=n?function(t,i,o,n){let r=null;for(let s=0;s<100;s++){const s={x:o.x+(0,e.getRandom)()*n.width-n.width/2,y:o.y+(0,e.getRandom)()*n.height-n.height/2};if(t.isPointInPath(i,s.x,s.y)){r=s;break}}return r}(t,r,i,o):function(t,i,o,n){let r=null;for(let s=0;s<100;s++){const s={x:o.x+(0,e.getRandom)()*n.width-n.width/2,y:o.y+(0,e.getRandom)()*n.height-n.height/2};if(t.isPointInStroke(i,s.x,s.y)){r=s;break}}return r}(t,r,i,o);return s?{position:s}:null}resize(t,e){super.resize(t,e);const i=this.points,o=new Path2D,n=t.x-e.width/2,r=t.y-e.height/2;for(const[t,s]of i.entries()){const i={x:n+s.x*e.width/100,y:r+s.y*e.height/100};0===t?o.moveTo(i.x,i.y):o.lineTo(i.x,i.y)}if(i[0]){const t={x:n+i[0].x*e.width/100,y:r+i[0].y*e.height/100};o.lineTo(t.x,t.y)}this.path=o}}class o{constructor(){this.points=[]}load(t){t&&void 0!==t.points&&(this.points=t.points.map((t=>({x:t.x??50,y:t.y??50}))))}}class s{generate(t,e,n,r){const s=new o;return s.load(r),new i(t,e,n,s)}}async function a(t,e=!0){const i=t;i.addEmitterShapeGenerator&&i.addEmitterShapeGenerator("path",new s),await i.refresh(e)}})(),r})()));
@@ -0,0 +1 @@
1
+ /*! tsParticles Emitters Shape Path Plugin v3.0.0-beta.4 by Matteo Bruni */
@@ -0,0 +1,12 @@
1
+ import { EmitterShapeBase, type IRandomPositionData } from "@tsparticles/plugin-emitters";
2
+ import { type ICoordinates, type IDimension } from "@tsparticles/engine";
3
+ import type { EmittersPathShapeOptions } from "./Options/Classes/EmittersPathShapeOptions.js";
4
+ export declare class EmittersPathShape extends EmitterShapeBase<EmittersPathShapeOptions> {
5
+ checkContext: CanvasRenderingContext2D;
6
+ path: Path2D;
7
+ points: ICoordinates[];
8
+ constructor(position: ICoordinates, size: IDimension, fill: boolean, options: EmittersPathShapeOptions);
9
+ init(): Promise<void>;
10
+ randomPosition(): Promise<IRandomPositionData | null>;
11
+ resize(position: ICoordinates, size: IDimension): void;
12
+ }
@@ -0,0 +1,6 @@
1
+ import type { ICoordinates, IDimension } from "@tsparticles/engine";
2
+ import type { IEmitterShape, IEmitterShapeGenerator } from "@tsparticles/plugin-emitters";
3
+ import type { IEmittersPathShapeOptions } from "./Options/Interfaces/IEmittersPathShapeOptions.js";
4
+ export declare class EmittersPathShapeGenerator implements IEmitterShapeGenerator<IEmittersPathShapeOptions> {
5
+ generate(position: ICoordinates, size: IDimension, fill: boolean, options: IEmittersPathShapeOptions): IEmitterShape;
6
+ }
@@ -0,0 +1,7 @@
1
+ import type { ICoordinates, IOptionLoader, RecursivePartial } from "@tsparticles/engine";
2
+ import type { IEmittersPathShapeOptions } from "../Interfaces/IEmittersPathShapeOptions.js";
3
+ export declare class EmittersPathShapeOptions implements IEmittersPathShapeOptions, IOptionLoader<IEmittersPathShapeOptions> {
4
+ points: ICoordinates[];
5
+ constructor();
6
+ load(data?: RecursivePartial<IEmittersPathShapeOptions> | undefined): void;
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { ICoordinates } from "@tsparticles/engine";
2
+ export interface IEmittersPathShapeOptions {
3
+ points: ICoordinates[];
4
+ }
@@ -0,0 +1,2 @@
1
+ import type { Engine } from "@tsparticles/engine";
2
+ export declare function loadEmittersShapePath(engine: Engine, refresh?: boolean): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { type ICoordinates, type IDimension } from "@tsparticles/engine";
2
+ export declare function generateRandomPointWithinPath(ctx: CanvasRenderingContext2D, path: Path2D, center: ICoordinates, size: IDimension): ICoordinates | null;
3
+ export declare function generateRandomPointOnPathPerimeter(ctx: CanvasRenderingContext2D, path: Path2D, center: ICoordinates, size: IDimension): ICoordinates | null;
@@ -0,0 +1,87 @@
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/plugin-emitters", "@tsparticles/engine", "./utils.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EmittersPathShape = void 0;
13
+ const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
14
+ const engine_1 = require("@tsparticles/engine");
15
+ const utils_js_1 = require("./utils.js");
16
+ class EmittersPathShape extends plugin_emitters_1.EmitterShapeBase {
17
+ constructor(position, size, fill, options) {
18
+ super(position, size, fill, options);
19
+ const ctx = document.createElement("canvas").getContext("2d");
20
+ if (!ctx) {
21
+ throw new Error(`${engine_1.errorPrefix} No 2d context available`);
22
+ }
23
+ this.checkContext = ctx;
24
+ this.points = options.points;
25
+ const pathData = this.points, path = new Path2D(), offset = {
26
+ x: position.x - size.width / 2,
27
+ y: position.y - size.height / 2,
28
+ };
29
+ for (const [index, point] of pathData.entries()) {
30
+ const coords = {
31
+ x: offset.x + (point.x * size.width) / 100,
32
+ y: offset.y + (point.y * size.height) / 100,
33
+ };
34
+ if (index === 0) {
35
+ path.moveTo(coords.x, coords.y);
36
+ }
37
+ else {
38
+ path.lineTo(coords.x, coords.y);
39
+ }
40
+ }
41
+ if (pathData[0]) {
42
+ const coords = {
43
+ x: offset.x + (pathData[0].x * size.width) / 100,
44
+ y: offset.y + (pathData[0].y * size.height) / 100,
45
+ };
46
+ path.lineTo(coords.x, coords.y);
47
+ }
48
+ this.path = path;
49
+ }
50
+ async init() {
51
+ }
52
+ async randomPosition() {
53
+ const ctx = this.checkContext, position = this.position, size = this.size, fill = this.fill, path = this.path, res = fill
54
+ ? (0, utils_js_1.generateRandomPointWithinPath)(ctx, path, position, size)
55
+ : (0, utils_js_1.generateRandomPointOnPathPerimeter)(ctx, path, position, size);
56
+ return res ? { position: res } : null;
57
+ }
58
+ resize(position, size) {
59
+ super.resize(position, size);
60
+ const pathData = this.points, path = new Path2D(), offset = {
61
+ x: position.x - size.width / 2,
62
+ y: position.y - size.height / 2,
63
+ };
64
+ for (const [index, point] of pathData.entries()) {
65
+ const coords = {
66
+ x: offset.x + (point.x * size.width) / 100,
67
+ y: offset.y + (point.y * size.height) / 100,
68
+ };
69
+ if (index === 0) {
70
+ path.moveTo(coords.x, coords.y);
71
+ }
72
+ else {
73
+ path.lineTo(coords.x, coords.y);
74
+ }
75
+ }
76
+ if (pathData[0]) {
77
+ const coords = {
78
+ x: offset.x + (pathData[0].x * size.width) / 100,
79
+ y: offset.y + (pathData[0].y * size.height) / 100,
80
+ };
81
+ path.lineTo(coords.x, coords.y);
82
+ }
83
+ this.path = path;
84
+ }
85
+ }
86
+ exports.EmittersPathShape = EmittersPathShape;
87
+ });
@@ -0,0 +1,23 @@
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", "./EmittersPathShape.js", "./Options/Classes/EmittersPathShapeOptions.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.EmittersPathShapeGenerator = void 0;
13
+ const EmittersPathShape_js_1 = require("./EmittersPathShape.js");
14
+ const EmittersPathShapeOptions_js_1 = require("./Options/Classes/EmittersPathShapeOptions.js");
15
+ class EmittersPathShapeGenerator {
16
+ generate(position, size, fill, options) {
17
+ const shapeOptions = new EmittersPathShapeOptions_js_1.EmittersPathShapeOptions();
18
+ shapeOptions.load(options);
19
+ return new EmittersPathShape_js_1.EmittersPathShape(position, size, fill, shapeOptions);
20
+ }
21
+ }
22
+ exports.EmittersPathShapeGenerator = EmittersPathShapeGenerator;
23
+ });
@@ -0,0 +1,27 @@
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
+ exports.EmittersPathShapeOptions = void 0;
13
+ class EmittersPathShapeOptions {
14
+ constructor() {
15
+ this.points = [];
16
+ }
17
+ load(data) {
18
+ if (!data) {
19
+ return;
20
+ }
21
+ if (data.points !== undefined) {
22
+ this.points = data.points.map((t) => ({ x: t.x ?? 50, y: t.y ?? 50 }));
23
+ }
24
+ }
25
+ }
26
+ exports.EmittersPathShapeOptions = EmittersPathShapeOptions;
27
+ });
@@ -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,21 @@
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", "./EmittersPathShapeGenerator.js"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.loadEmittersShapePath = void 0;
13
+ const EmittersPathShapeGenerator_js_1 = require("./EmittersPathShapeGenerator.js");
14
+ async function loadEmittersShapePath(engine, refresh = true) {
15
+ const emittersEngine = engine;
16
+ emittersEngine.addEmitterShapeGenerator &&
17
+ emittersEngine.addEmitterShapeGenerator("path", new EmittersPathShapeGenerator_js_1.EmittersPathShapeGenerator());
18
+ await emittersEngine.refresh(refresh);
19
+ }
20
+ exports.loadEmittersShapePath = loadEmittersShapePath;
21
+ });
package/umd/utils.js ADDED
@@ -0,0 +1,44 @@
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.generateRandomPointOnPathPerimeter = exports.generateRandomPointWithinPath = void 0;
13
+ const engine_1 = require("@tsparticles/engine");
14
+ function generateRandomPointWithinPath(ctx, path, center, size) {
15
+ let randomPoint = null;
16
+ for (let attempts = 0; attempts < 100; attempts++) {
17
+ const tmpPoint = {
18
+ x: center.x + (0, engine_1.getRandom)() * size.width - size.width / 2,
19
+ y: center.y + (0, engine_1.getRandom)() * size.height - size.height / 2,
20
+ };
21
+ if (ctx.isPointInPath(path, tmpPoint.x, tmpPoint.y)) {
22
+ randomPoint = tmpPoint;
23
+ break;
24
+ }
25
+ }
26
+ return randomPoint;
27
+ }
28
+ exports.generateRandomPointWithinPath = generateRandomPointWithinPath;
29
+ function generateRandomPointOnPathPerimeter(ctx, path, center, size) {
30
+ let randomPoint = null;
31
+ for (let attempts = 0; attempts < 100; attempts++) {
32
+ const tmpPoint = {
33
+ x: center.x + (0, engine_1.getRandom)() * size.width - size.width / 2,
34
+ y: center.y + (0, engine_1.getRandom)() * size.height - size.height / 2,
35
+ };
36
+ if (ctx.isPointInStroke(path, tmpPoint.x, tmpPoint.y)) {
37
+ randomPoint = tmpPoint;
38
+ break;
39
+ }
40
+ }
41
+ return randomPoint;
42
+ }
43
+ exports.generateRandomPointOnPathPerimeter = generateRandomPointOnPathPerimeter;
44
+ });