@tsparticles/plugin-polygon-mask 3.3.0 → 3.4.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.
- package/browser/Enums/PolygonMaskInlineArrangement.js +8 -1
- package/browser/Enums/PolygonMaskMoveType.js +5 -1
- package/browser/Enums/PolygonMaskType.js +7 -1
- package/browser/Options/Classes/PolygonMask.js +3 -2
- package/browser/Options/Classes/PolygonMaskInline.js +2 -1
- package/browser/Options/Classes/PolygonMaskMove.js +2 -1
- package/browser/PolygonMaskInstance.js +28 -27
- package/browser/PolygonMaskPlugin.js +5 -4
- package/browser/index.js +1 -1
- package/cjs/Enums/PolygonMaskInlineArrangement.js +9 -0
- package/cjs/Enums/PolygonMaskMoveType.js +6 -0
- package/cjs/Enums/PolygonMaskType.js +8 -0
- package/cjs/Options/Classes/PolygonMask.js +3 -2
- package/cjs/Options/Classes/PolygonMaskInline.js +2 -1
- package/cjs/Options/Classes/PolygonMaskMove.js +2 -1
- package/cjs/PolygonMaskInstance.js +27 -26
- package/cjs/PolygonMaskPlugin.js +5 -4
- package/cjs/index.js +2 -2
- package/esm/Enums/PolygonMaskInlineArrangement.js +8 -1
- package/esm/Enums/PolygonMaskMoveType.js +5 -1
- package/esm/Enums/PolygonMaskType.js +7 -1
- package/esm/Options/Classes/PolygonMask.js +3 -2
- package/esm/Options/Classes/PolygonMaskInline.js +2 -1
- package/esm/Options/Classes/PolygonMaskMove.js +2 -1
- package/esm/PolygonMaskInstance.js +28 -27
- package/esm/PolygonMaskPlugin.js +5 -4
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/report.html +1 -1
- package/tsparticles.plugin.polygon-mask.js +122 -200
- package/tsparticles.plugin.polygon-mask.min.js +1 -1
- package/tsparticles.plugin.polygon-mask.min.js.LICENSE.txt +1 -1
- package/types/Enums/PolygonMaskInlineArrangement.d.ts +1 -1
- package/types/Enums/PolygonMaskMoveType.d.ts +1 -1
- package/types/Enums/PolygonMaskType.d.ts +1 -1
- package/types/PolygonMaskPlugin.d.ts +1 -1
- package/umd/Enums/PolygonMaskInlineArrangement.js +9 -0
- package/umd/Enums/PolygonMaskMoveType.js +6 -0
- package/umd/Enums/PolygonMaskType.js +8 -0
- package/umd/Options/Classes/PolygonMask.js +4 -3
- package/umd/Options/Classes/PolygonMaskInline.js +3 -2
- package/umd/Options/Classes/PolygonMaskMove.js +3 -2
- package/umd/PolygonMaskInstance.js +28 -51
- package/umd/PolygonMaskPlugin.js +6 -29
- package/umd/index.js +3 -16
- package/350.min.js +0 -2
- package/350.min.js.LICENSE.txt +0 -1
- package/556.min.js +0 -2
- package/556.min.js.LICENSE.txt +0 -1
- package/dist_browser_PolygonMaskInstance_js.js +0 -40
- package/dist_browser_PolygonMaskPlugin_js.js +0 -90
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PolygonMaskInlineArrangement;
|
|
2
|
+
(function (PolygonMaskInlineArrangement) {
|
|
3
|
+
PolygonMaskInlineArrangement["equidistant"] = "equidistant";
|
|
4
|
+
PolygonMaskInlineArrangement["onePerPoint"] = "one-per-point";
|
|
5
|
+
PolygonMaskInlineArrangement["perPoint"] = "per-point";
|
|
6
|
+
PolygonMaskInlineArrangement["randomLength"] = "random-length";
|
|
7
|
+
PolygonMaskInlineArrangement["randomPoint"] = "random-point";
|
|
8
|
+
})(PolygonMaskInlineArrangement || (PolygonMaskInlineArrangement = {}));
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PolygonMaskType;
|
|
2
|
+
(function (PolygonMaskType) {
|
|
3
|
+
PolygonMaskType["inline"] = "inline";
|
|
4
|
+
PolygonMaskType["inside"] = "inside";
|
|
5
|
+
PolygonMaskType["outside"] = "outside";
|
|
6
|
+
PolygonMaskType["none"] = "none";
|
|
7
|
+
})(PolygonMaskType || (PolygonMaskType = {}));
|
|
@@ -3,6 +3,7 @@ import { PolygonMaskDraw } from "./PolygonMaskDraw.js";
|
|
|
3
3
|
import { PolygonMaskInline } from "./PolygonMaskInline.js";
|
|
4
4
|
import { PolygonMaskLocalSvg } from "./PolygonMaskLocalSvg.js";
|
|
5
5
|
import { PolygonMaskMove } from "./PolygonMaskMove.js";
|
|
6
|
+
import { PolygonMaskType } from "../../Enums/PolygonMaskType.js";
|
|
6
7
|
export class PolygonMask {
|
|
7
8
|
constructor() {
|
|
8
9
|
this.draw = new PolygonMaskDraw();
|
|
@@ -10,7 +11,7 @@ export class PolygonMask {
|
|
|
10
11
|
this.inline = new PolygonMaskInline();
|
|
11
12
|
this.move = new PolygonMaskMove();
|
|
12
13
|
this.scale = 1;
|
|
13
|
-
this.type =
|
|
14
|
+
this.type = PolygonMaskType.none;
|
|
14
15
|
}
|
|
15
16
|
load(data) {
|
|
16
17
|
if (!data) {
|
|
@@ -29,7 +30,7 @@ export class PolygonMask {
|
|
|
29
30
|
this.enable = data.enable;
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
|
-
this.enable = this.type !==
|
|
33
|
+
this.enable = this.type !== PolygonMaskType.none;
|
|
33
34
|
}
|
|
34
35
|
if (data.url !== undefined) {
|
|
35
36
|
this.url = data.url;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { PolygonMaskInlineArrangement, } from "../../Enums/PolygonMaskInlineArrangement.js";
|
|
1
2
|
export class PolygonMaskInline {
|
|
2
3
|
constructor() {
|
|
3
|
-
this.arrangement =
|
|
4
|
+
this.arrangement = PolygonMaskInlineArrangement.onePerPoint;
|
|
4
5
|
}
|
|
5
6
|
load(data) {
|
|
6
7
|
if (!data) {
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { deepExtend, errorPrefix, getDistance, getDistances, getRandom, isArray, isString, itemFromArray, percentDenominator, } from "@tsparticles/engine";
|
|
2
|
-
import { calcClosestPointOnSegment, drawPolygonMask, drawPolygonMaskPath, segmentBounce } from "./utils.js";
|
|
1
|
+
import { OutModeDirection, deepExtend, errorPrefix, getDistance, getDistances, getRandom, isArray, isString, itemFromArray, percentDenominator, } from "@tsparticles/engine";
|
|
2
|
+
import { calcClosestPointOnSegment, drawPolygonMask, drawPolygonMaskPath, parsePaths, segmentBounce } from "./utils.js";
|
|
3
|
+
import { PolygonMaskInlineArrangement } from "./Enums/PolygonMaskInlineArrangement.js";
|
|
4
|
+
import { PolygonMaskType } from "./Enums/PolygonMaskType.js";
|
|
3
5
|
const noPolygonDataLoaded = `${errorPrefix} No polygon data loaded.`, noPolygonFound = `${errorPrefix} No polygon found, you need to specify SVG url in config.`, origin = {
|
|
4
6
|
x: 0,
|
|
5
7
|
y: 0,
|
|
6
8
|
}, half = 0.5, double = 2;
|
|
7
9
|
export class PolygonMaskInstance {
|
|
8
10
|
constructor(container, engine) {
|
|
9
|
-
this._checkInsidePolygon =
|
|
11
|
+
this._checkInsidePolygon = position => {
|
|
10
12
|
const container = this._container, options = container.actualOptions.polygon;
|
|
11
|
-
if (!options?.enable || options.type ===
|
|
13
|
+
if (!options?.enable || options.type === PolygonMaskType.none || options.type === PolygonMaskType.inline) {
|
|
12
14
|
return true;
|
|
13
15
|
}
|
|
14
16
|
if (!this.raw) {
|
|
@@ -22,11 +24,11 @@ export class PolygonMaskInstance {
|
|
|
22
24
|
inside = !inside;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
if (options.type ===
|
|
27
|
+
if (options.type === PolygonMaskType.inside) {
|
|
26
28
|
return inside;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
return options.type ===
|
|
31
|
+
return options.type === PolygonMaskType.outside ? !inside : false;
|
|
30
32
|
}
|
|
31
33
|
};
|
|
32
34
|
this._createPath2D = () => {
|
|
@@ -76,7 +78,7 @@ export class PolygonMaskInstance {
|
|
|
76
78
|
if (!req.ok) {
|
|
77
79
|
throw new Error(`${errorPrefix} occurred during polygon mask download`);
|
|
78
80
|
}
|
|
79
|
-
return
|
|
81
|
+
return this._parseSvgPath(await req.text(), force);
|
|
80
82
|
};
|
|
81
83
|
this._drawPoints = () => {
|
|
82
84
|
if (!this.raw) {
|
|
@@ -89,7 +91,7 @@ export class PolygonMaskInstance {
|
|
|
89
91
|
});
|
|
90
92
|
}
|
|
91
93
|
};
|
|
92
|
-
this._getEquidistantPointByIndex =
|
|
94
|
+
this._getEquidistantPointByIndex = index => {
|
|
93
95
|
const container = this._container, options = container.actualOptions, polygonMaskOptions = options.polygon;
|
|
94
96
|
if (!polygonMaskOptions) {
|
|
95
97
|
return;
|
|
@@ -115,7 +117,7 @@ export class PolygonMaskInstance {
|
|
|
115
117
|
y: (point?.y ?? origin.y) * scale + (this.offset?.y ?? origin.y),
|
|
116
118
|
};
|
|
117
119
|
};
|
|
118
|
-
this._getPointByIndex =
|
|
120
|
+
this._getPointByIndex = index => {
|
|
119
121
|
if (!this.raw?.length) {
|
|
120
122
|
throw new Error(noPolygonDataLoaded);
|
|
121
123
|
}
|
|
@@ -168,14 +170,14 @@ export class PolygonMaskInstance {
|
|
|
168
170
|
const namespaces = 'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"';
|
|
169
171
|
svg = `<svg ${namespaces} width="${data.size.width}" height="${data.size.height}">${path}</svg>`;
|
|
170
172
|
}
|
|
171
|
-
this.raw =
|
|
173
|
+
this.raw = this._parseSvgPath(svg, force);
|
|
172
174
|
}
|
|
173
175
|
this._createPath2D();
|
|
174
176
|
this._engine.dispatchEvent("polygonMaskLoaded", {
|
|
175
177
|
container: this._container,
|
|
176
178
|
});
|
|
177
179
|
};
|
|
178
|
-
this._parseSvgPath =
|
|
180
|
+
this._parseSvgPath = (xml, force) => {
|
|
179
181
|
const forceDownload = force ?? false;
|
|
180
182
|
if (this.paths !== undefined && !forceDownload) {
|
|
181
183
|
return this.raw;
|
|
@@ -210,15 +212,14 @@ export class PolygonMaskInstance {
|
|
|
210
212
|
x: (canvasSize.width * position.x) / percentDenominator - this.dimension.width * half,
|
|
211
213
|
y: (canvasSize.height * position.y) / percentDenominator - this.dimension.height * half,
|
|
212
214
|
};
|
|
213
|
-
const { parsePaths } = await import("./utils.js");
|
|
214
215
|
return parsePaths(this.paths, scale, this.offset);
|
|
215
216
|
};
|
|
216
217
|
this._polygonBounce = (particle, delta, direction) => {
|
|
217
218
|
const options = this._container.actualOptions.polygon;
|
|
218
|
-
if (!this.raw || !options?.enable || direction !==
|
|
219
|
+
if (!this.raw || !options?.enable || direction !== OutModeDirection.top) {
|
|
219
220
|
return false;
|
|
220
221
|
}
|
|
221
|
-
if (options.type ===
|
|
222
|
+
if (options.type === PolygonMaskType.inside || options.type === PolygonMaskType.outside) {
|
|
222
223
|
let closest, dx, dy;
|
|
223
224
|
const pos = particle.getPosition(), radius = particle.getRadius(), offset = 1;
|
|
224
225
|
for (let i = 0, j = this.raw.length - offset; i < this.raw.length; j = i++) {
|
|
@@ -245,7 +246,7 @@ export class PolygonMaskInstance {
|
|
|
245
246
|
return true;
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
|
-
else if (options.type ===
|
|
249
|
+
else if (options.type === PolygonMaskType.inline && particle.initialPosition) {
|
|
249
250
|
const dist = getDistance(particle.initialPosition, particle.getPosition()), { velocity } = particle;
|
|
250
251
|
if (dist > this._moveRadius) {
|
|
251
252
|
velocity.x = velocity.y * half - velocity.x;
|
|
@@ -261,19 +262,19 @@ export class PolygonMaskInstance {
|
|
|
261
262
|
return;
|
|
262
263
|
}
|
|
263
264
|
let position;
|
|
264
|
-
if (options.type ===
|
|
265
|
+
if (options.type === PolygonMaskType.inline) {
|
|
265
266
|
switch (options.inline.arrangement) {
|
|
266
|
-
case
|
|
267
|
+
case PolygonMaskInlineArrangement.randomPoint:
|
|
267
268
|
position = this._getRandomPoint();
|
|
268
269
|
break;
|
|
269
|
-
case
|
|
270
|
+
case PolygonMaskInlineArrangement.randomLength:
|
|
270
271
|
position = this._getRandomPointByLength();
|
|
271
272
|
break;
|
|
272
|
-
case
|
|
273
|
+
case PolygonMaskInlineArrangement.equidistant:
|
|
273
274
|
position = this._getEquidistantPointByIndex(container.particles.count);
|
|
274
275
|
break;
|
|
275
|
-
case
|
|
276
|
-
case
|
|
276
|
+
case PolygonMaskInlineArrangement.onePerPoint:
|
|
277
|
+
case PolygonMaskInlineArrangement.perPoint:
|
|
277
278
|
default:
|
|
278
279
|
position = this._getPointByIndex(container.particles.count);
|
|
279
280
|
}
|
|
@@ -304,8 +305,8 @@ export class PolygonMaskInstance {
|
|
|
304
305
|
clickPositionValid(position) {
|
|
305
306
|
const options = this._container.actualOptions.polygon;
|
|
306
307
|
return (!!options?.enable &&
|
|
307
|
-
options.type !==
|
|
308
|
-
options.type !==
|
|
308
|
+
options.type !== PolygonMaskType.none &&
|
|
309
|
+
options.type !== PolygonMaskType.inline &&
|
|
309
310
|
this._checkInsidePolygon(position));
|
|
310
311
|
}
|
|
311
312
|
draw(context) {
|
|
@@ -358,9 +359,9 @@ export class PolygonMaskInstance {
|
|
|
358
359
|
particlesInitialization() {
|
|
359
360
|
const options = this._container.actualOptions.polygon;
|
|
360
361
|
if (options?.enable &&
|
|
361
|
-
options.type ===
|
|
362
|
-
(options.inline.arrangement ===
|
|
363
|
-
options.inline.arrangement ===
|
|
362
|
+
options.type === PolygonMaskType.inline &&
|
|
363
|
+
(options.inline.arrangement === PolygonMaskInlineArrangement.onePerPoint ||
|
|
364
|
+
options.inline.arrangement === PolygonMaskInlineArrangement.perPoint)) {
|
|
364
365
|
this._drawPoints();
|
|
365
366
|
return true;
|
|
366
367
|
}
|
|
@@ -368,7 +369,7 @@ export class PolygonMaskInstance {
|
|
|
368
369
|
}
|
|
369
370
|
resize() {
|
|
370
371
|
const container = this._container, options = container.actualOptions.polygon;
|
|
371
|
-
if (!(options?.enable && options.type !==
|
|
372
|
+
if (!(options?.enable && options.type !== PolygonMaskType.none)) {
|
|
372
373
|
return;
|
|
373
374
|
}
|
|
374
375
|
if (this.redrawTimeout) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { PolygonMask } from "./Options/Classes/PolygonMask.js";
|
|
2
|
+
import { PolygonMaskInstance } from "./PolygonMaskInstance.js";
|
|
3
|
+
import { PolygonMaskType } from "./Enums/PolygonMaskType.js";
|
|
2
4
|
export class PolygonMaskPlugin {
|
|
3
5
|
constructor(engine) {
|
|
4
6
|
this.id = "polygonMask";
|
|
5
7
|
this._engine = engine;
|
|
6
8
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return new PolygonMaskInstance(container, this._engine);
|
|
9
|
+
getPlugin(container) {
|
|
10
|
+
return Promise.resolve(new PolygonMaskInstance(container, this._engine));
|
|
10
11
|
}
|
|
11
12
|
loadOptions(options, source) {
|
|
12
13
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -20,6 +21,6 @@ export class PolygonMaskPlugin {
|
|
|
20
21
|
}
|
|
21
22
|
needsPlugin(options) {
|
|
22
23
|
return (options?.polygon?.enable ??
|
|
23
|
-
(options?.polygon?.type !== undefined && options.polygon.type !==
|
|
24
|
+
(options?.polygon?.type !== undefined && options.polygon.type !== PolygonMaskType.none));
|
|
24
25
|
}
|
|
25
26
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./pathseg.js";
|
|
2
|
+
import { PolygonMaskPlugin } from "./PolygonMaskPlugin.js";
|
|
2
3
|
export async function loadPolygonMaskPlugin(engine, refresh = true) {
|
|
3
|
-
const { PolygonMaskPlugin } = await import("./PolygonMaskPlugin.js");
|
|
4
4
|
await engine.addPlugin(new PolygonMaskPlugin(engine), refresh);
|
|
5
5
|
}
|
|
6
6
|
export * from "./Enums/PolygonMaskInlineArrangement.js";
|
|
@@ -1,2 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolygonMaskInlineArrangement = void 0;
|
|
4
|
+
var PolygonMaskInlineArrangement;
|
|
5
|
+
(function (PolygonMaskInlineArrangement) {
|
|
6
|
+
PolygonMaskInlineArrangement["equidistant"] = "equidistant";
|
|
7
|
+
PolygonMaskInlineArrangement["onePerPoint"] = "one-per-point";
|
|
8
|
+
PolygonMaskInlineArrangement["perPoint"] = "per-point";
|
|
9
|
+
PolygonMaskInlineArrangement["randomLength"] = "random-length";
|
|
10
|
+
PolygonMaskInlineArrangement["randomPoint"] = "random-point";
|
|
11
|
+
})(PolygonMaskInlineArrangement || (exports.PolygonMaskInlineArrangement = PolygonMaskInlineArrangement = {}));
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolygonMaskMoveType = void 0;
|
|
4
|
+
var PolygonMaskMoveType;
|
|
5
|
+
(function (PolygonMaskMoveType) {
|
|
6
|
+
PolygonMaskMoveType["path"] = "path";
|
|
7
|
+
PolygonMaskMoveType["radius"] = "radius";
|
|
8
|
+
})(PolygonMaskMoveType || (exports.PolygonMaskMoveType = PolygonMaskMoveType = {}));
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolygonMaskType = void 0;
|
|
4
|
+
var PolygonMaskType;
|
|
5
|
+
(function (PolygonMaskType) {
|
|
6
|
+
PolygonMaskType["inline"] = "inline";
|
|
7
|
+
PolygonMaskType["inside"] = "inside";
|
|
8
|
+
PolygonMaskType["outside"] = "outside";
|
|
9
|
+
PolygonMaskType["none"] = "none";
|
|
10
|
+
})(PolygonMaskType || (exports.PolygonMaskType = PolygonMaskType = {}));
|
|
@@ -6,6 +6,7 @@ const PolygonMaskDraw_js_1 = require("./PolygonMaskDraw.js");
|
|
|
6
6
|
const PolygonMaskInline_js_1 = require("./PolygonMaskInline.js");
|
|
7
7
|
const PolygonMaskLocalSvg_js_1 = require("./PolygonMaskLocalSvg.js");
|
|
8
8
|
const PolygonMaskMove_js_1 = require("./PolygonMaskMove.js");
|
|
9
|
+
const PolygonMaskType_js_1 = require("../../Enums/PolygonMaskType.js");
|
|
9
10
|
class PolygonMask {
|
|
10
11
|
constructor() {
|
|
11
12
|
this.draw = new PolygonMaskDraw_js_1.PolygonMaskDraw();
|
|
@@ -13,7 +14,7 @@ class PolygonMask {
|
|
|
13
14
|
this.inline = new PolygonMaskInline_js_1.PolygonMaskInline();
|
|
14
15
|
this.move = new PolygonMaskMove_js_1.PolygonMaskMove();
|
|
15
16
|
this.scale = 1;
|
|
16
|
-
this.type =
|
|
17
|
+
this.type = PolygonMaskType_js_1.PolygonMaskType.none;
|
|
17
18
|
}
|
|
18
19
|
load(data) {
|
|
19
20
|
if (!data) {
|
|
@@ -32,7 +33,7 @@ class PolygonMask {
|
|
|
32
33
|
this.enable = data.enable;
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
|
-
this.enable = this.type !==
|
|
36
|
+
this.enable = this.type !== PolygonMaskType_js_1.PolygonMaskType.none;
|
|
36
37
|
}
|
|
37
38
|
if (data.url !== undefined) {
|
|
38
39
|
this.url = data.url;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PolygonMaskInline = void 0;
|
|
4
|
+
const PolygonMaskInlineArrangement_js_1 = require("../../Enums/PolygonMaskInlineArrangement.js");
|
|
4
5
|
class PolygonMaskInline {
|
|
5
6
|
constructor() {
|
|
6
|
-
this.arrangement =
|
|
7
|
+
this.arrangement = PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.onePerPoint;
|
|
7
8
|
}
|
|
8
9
|
load(data) {
|
|
9
10
|
if (!data) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PolygonMaskMove = void 0;
|
|
4
|
+
const PolygonMaskMoveType_js_1 = require("../../Enums/PolygonMaskMoveType.js");
|
|
4
5
|
class PolygonMaskMove {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.radius = 10;
|
|
7
|
-
this.type =
|
|
8
|
+
this.type = PolygonMaskMoveType_js_1.PolygonMaskMoveType.path;
|
|
8
9
|
}
|
|
9
10
|
load(data) {
|
|
10
11
|
if (!data) {
|
|
@@ -3,15 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PolygonMaskInstance = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const PolygonMaskInlineArrangement_js_1 = require("./Enums/PolygonMaskInlineArrangement.js");
|
|
7
|
+
const PolygonMaskType_js_1 = require("./Enums/PolygonMaskType.js");
|
|
6
8
|
const noPolygonDataLoaded = `${engine_1.errorPrefix} No polygon data loaded.`, noPolygonFound = `${engine_1.errorPrefix} No polygon found, you need to specify SVG url in config.`, origin = {
|
|
7
9
|
x: 0,
|
|
8
10
|
y: 0,
|
|
9
11
|
}, half = 0.5, double = 2;
|
|
10
12
|
class PolygonMaskInstance {
|
|
11
13
|
constructor(container, engine) {
|
|
12
|
-
this._checkInsidePolygon =
|
|
14
|
+
this._checkInsidePolygon = position => {
|
|
13
15
|
const container = this._container, options = container.actualOptions.polygon;
|
|
14
|
-
if (!options?.enable || options.type ===
|
|
16
|
+
if (!options?.enable || options.type === PolygonMaskType_js_1.PolygonMaskType.none || options.type === PolygonMaskType_js_1.PolygonMaskType.inline) {
|
|
15
17
|
return true;
|
|
16
18
|
}
|
|
17
19
|
if (!this.raw) {
|
|
@@ -25,11 +27,11 @@ class PolygonMaskInstance {
|
|
|
25
27
|
inside = !inside;
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
if (options.type ===
|
|
30
|
+
if (options.type === PolygonMaskType_js_1.PolygonMaskType.inside) {
|
|
29
31
|
return inside;
|
|
30
32
|
}
|
|
31
33
|
else {
|
|
32
|
-
return options.type ===
|
|
34
|
+
return options.type === PolygonMaskType_js_1.PolygonMaskType.outside ? !inside : false;
|
|
33
35
|
}
|
|
34
36
|
};
|
|
35
37
|
this._createPath2D = () => {
|
|
@@ -79,7 +81,7 @@ class PolygonMaskInstance {
|
|
|
79
81
|
if (!req.ok) {
|
|
80
82
|
throw new Error(`${engine_1.errorPrefix} occurred during polygon mask download`);
|
|
81
83
|
}
|
|
82
|
-
return
|
|
84
|
+
return this._parseSvgPath(await req.text(), force);
|
|
83
85
|
};
|
|
84
86
|
this._drawPoints = () => {
|
|
85
87
|
if (!this.raw) {
|
|
@@ -92,7 +94,7 @@ class PolygonMaskInstance {
|
|
|
92
94
|
});
|
|
93
95
|
}
|
|
94
96
|
};
|
|
95
|
-
this._getEquidistantPointByIndex =
|
|
97
|
+
this._getEquidistantPointByIndex = index => {
|
|
96
98
|
const container = this._container, options = container.actualOptions, polygonMaskOptions = options.polygon;
|
|
97
99
|
if (!polygonMaskOptions) {
|
|
98
100
|
return;
|
|
@@ -118,7 +120,7 @@ class PolygonMaskInstance {
|
|
|
118
120
|
y: (point?.y ?? origin.y) * scale + (this.offset?.y ?? origin.y),
|
|
119
121
|
};
|
|
120
122
|
};
|
|
121
|
-
this._getPointByIndex =
|
|
123
|
+
this._getPointByIndex = index => {
|
|
122
124
|
if (!this.raw?.length) {
|
|
123
125
|
throw new Error(noPolygonDataLoaded);
|
|
124
126
|
}
|
|
@@ -171,14 +173,14 @@ class PolygonMaskInstance {
|
|
|
171
173
|
const namespaces = 'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"';
|
|
172
174
|
svg = `<svg ${namespaces} width="${data.size.width}" height="${data.size.height}">${path}</svg>`;
|
|
173
175
|
}
|
|
174
|
-
this.raw =
|
|
176
|
+
this.raw = this._parseSvgPath(svg, force);
|
|
175
177
|
}
|
|
176
178
|
this._createPath2D();
|
|
177
179
|
this._engine.dispatchEvent("polygonMaskLoaded", {
|
|
178
180
|
container: this._container,
|
|
179
181
|
});
|
|
180
182
|
};
|
|
181
|
-
this._parseSvgPath =
|
|
183
|
+
this._parseSvgPath = (xml, force) => {
|
|
182
184
|
const forceDownload = force ?? false;
|
|
183
185
|
if (this.paths !== undefined && !forceDownload) {
|
|
184
186
|
return this.raw;
|
|
@@ -213,15 +215,14 @@ class PolygonMaskInstance {
|
|
|
213
215
|
x: (canvasSize.width * position.x) / engine_1.percentDenominator - this.dimension.width * half,
|
|
214
216
|
y: (canvasSize.height * position.y) / engine_1.percentDenominator - this.dimension.height * half,
|
|
215
217
|
};
|
|
216
|
-
|
|
217
|
-
return parsePaths(this.paths, scale, this.offset);
|
|
218
|
+
return (0, utils_js_1.parsePaths)(this.paths, scale, this.offset);
|
|
218
219
|
};
|
|
219
220
|
this._polygonBounce = (particle, delta, direction) => {
|
|
220
221
|
const options = this._container.actualOptions.polygon;
|
|
221
|
-
if (!this.raw || !options?.enable || direction !==
|
|
222
|
+
if (!this.raw || !options?.enable || direction !== engine_1.OutModeDirection.top) {
|
|
222
223
|
return false;
|
|
223
224
|
}
|
|
224
|
-
if (options.type ===
|
|
225
|
+
if (options.type === PolygonMaskType_js_1.PolygonMaskType.inside || options.type === PolygonMaskType_js_1.PolygonMaskType.outside) {
|
|
225
226
|
let closest, dx, dy;
|
|
226
227
|
const pos = particle.getPosition(), radius = particle.getRadius(), offset = 1;
|
|
227
228
|
for (let i = 0, j = this.raw.length - offset; i < this.raw.length; j = i++) {
|
|
@@ -248,7 +249,7 @@ class PolygonMaskInstance {
|
|
|
248
249
|
return true;
|
|
249
250
|
}
|
|
250
251
|
}
|
|
251
|
-
else if (options.type ===
|
|
252
|
+
else if (options.type === PolygonMaskType_js_1.PolygonMaskType.inline && particle.initialPosition) {
|
|
252
253
|
const dist = (0, engine_1.getDistance)(particle.initialPosition, particle.getPosition()), { velocity } = particle;
|
|
253
254
|
if (dist > this._moveRadius) {
|
|
254
255
|
velocity.x = velocity.y * half - velocity.x;
|
|
@@ -264,19 +265,19 @@ class PolygonMaskInstance {
|
|
|
264
265
|
return;
|
|
265
266
|
}
|
|
266
267
|
let position;
|
|
267
|
-
if (options.type ===
|
|
268
|
+
if (options.type === PolygonMaskType_js_1.PolygonMaskType.inline) {
|
|
268
269
|
switch (options.inline.arrangement) {
|
|
269
|
-
case
|
|
270
|
+
case PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.randomPoint:
|
|
270
271
|
position = this._getRandomPoint();
|
|
271
272
|
break;
|
|
272
|
-
case
|
|
273
|
+
case PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.randomLength:
|
|
273
274
|
position = this._getRandomPointByLength();
|
|
274
275
|
break;
|
|
275
|
-
case
|
|
276
|
+
case PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.equidistant:
|
|
276
277
|
position = this._getEquidistantPointByIndex(container.particles.count);
|
|
277
278
|
break;
|
|
278
|
-
case
|
|
279
|
-
case
|
|
279
|
+
case PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.onePerPoint:
|
|
280
|
+
case PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.perPoint:
|
|
280
281
|
default:
|
|
281
282
|
position = this._getPointByIndex(container.particles.count);
|
|
282
283
|
}
|
|
@@ -307,8 +308,8 @@ class PolygonMaskInstance {
|
|
|
307
308
|
clickPositionValid(position) {
|
|
308
309
|
const options = this._container.actualOptions.polygon;
|
|
309
310
|
return (!!options?.enable &&
|
|
310
|
-
options.type !==
|
|
311
|
-
options.type !==
|
|
311
|
+
options.type !== PolygonMaskType_js_1.PolygonMaskType.none &&
|
|
312
|
+
options.type !== PolygonMaskType_js_1.PolygonMaskType.inline &&
|
|
312
313
|
this._checkInsidePolygon(position));
|
|
313
314
|
}
|
|
314
315
|
draw(context) {
|
|
@@ -361,9 +362,9 @@ class PolygonMaskInstance {
|
|
|
361
362
|
particlesInitialization() {
|
|
362
363
|
const options = this._container.actualOptions.polygon;
|
|
363
364
|
if (options?.enable &&
|
|
364
|
-
options.type ===
|
|
365
|
-
(options.inline.arrangement ===
|
|
366
|
-
options.inline.arrangement ===
|
|
365
|
+
options.type === PolygonMaskType_js_1.PolygonMaskType.inline &&
|
|
366
|
+
(options.inline.arrangement === PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.onePerPoint ||
|
|
367
|
+
options.inline.arrangement === PolygonMaskInlineArrangement_js_1.PolygonMaskInlineArrangement.perPoint)) {
|
|
367
368
|
this._drawPoints();
|
|
368
369
|
return true;
|
|
369
370
|
}
|
|
@@ -371,7 +372,7 @@ class PolygonMaskInstance {
|
|
|
371
372
|
}
|
|
372
373
|
resize() {
|
|
373
374
|
const container = this._container, options = container.actualOptions.polygon;
|
|
374
|
-
if (!(options?.enable && options.type !==
|
|
375
|
+
if (!(options?.enable && options.type !== PolygonMaskType_js_1.PolygonMaskType.none)) {
|
|
375
376
|
return;
|
|
376
377
|
}
|
|
377
378
|
if (this.redrawTimeout) {
|
package/cjs/PolygonMaskPlugin.js
CHANGED
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PolygonMaskPlugin = void 0;
|
|
4
4
|
const PolygonMask_js_1 = require("./Options/Classes/PolygonMask.js");
|
|
5
|
+
const PolygonMaskInstance_js_1 = require("./PolygonMaskInstance.js");
|
|
6
|
+
const PolygonMaskType_js_1 = require("./Enums/PolygonMaskType.js");
|
|
5
7
|
class PolygonMaskPlugin {
|
|
6
8
|
constructor(engine) {
|
|
7
9
|
this.id = "polygonMask";
|
|
8
10
|
this._engine = engine;
|
|
9
11
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return new PolygonMaskInstance(container, this._engine);
|
|
12
|
+
getPlugin(container) {
|
|
13
|
+
return Promise.resolve(new PolygonMaskInstance_js_1.PolygonMaskInstance(container, this._engine));
|
|
13
14
|
}
|
|
14
15
|
loadOptions(options, source) {
|
|
15
16
|
if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
|
@@ -23,7 +24,7 @@ class PolygonMaskPlugin {
|
|
|
23
24
|
}
|
|
24
25
|
needsPlugin(options) {
|
|
25
26
|
return (options?.polygon?.enable ??
|
|
26
|
-
(options?.polygon?.type !== undefined && options.polygon.type !==
|
|
27
|
+
(options?.polygon?.type !== undefined && options.polygon.type !== PolygonMaskType_js_1.PolygonMaskType.none));
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
30
|
exports.PolygonMaskPlugin = PolygonMaskPlugin;
|
package/cjs/index.js
CHANGED
|
@@ -16,9 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.loadPolygonMaskPlugin = void 0;
|
|
18
18
|
require("./pathseg.js");
|
|
19
|
+
const PolygonMaskPlugin_js_1 = require("./PolygonMaskPlugin.js");
|
|
19
20
|
async function loadPolygonMaskPlugin(engine, refresh = true) {
|
|
20
|
-
|
|
21
|
-
await engine.addPlugin(new PolygonMaskPlugin(engine), refresh);
|
|
21
|
+
await engine.addPlugin(new PolygonMaskPlugin_js_1.PolygonMaskPlugin(engine), refresh);
|
|
22
22
|
}
|
|
23
23
|
exports.loadPolygonMaskPlugin = loadPolygonMaskPlugin;
|
|
24
24
|
__exportStar(require("./Enums/PolygonMaskInlineArrangement.js"), exports);
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PolygonMaskInlineArrangement;
|
|
2
|
+
(function (PolygonMaskInlineArrangement) {
|
|
3
|
+
PolygonMaskInlineArrangement["equidistant"] = "equidistant";
|
|
4
|
+
PolygonMaskInlineArrangement["onePerPoint"] = "one-per-point";
|
|
5
|
+
PolygonMaskInlineArrangement["perPoint"] = "per-point";
|
|
6
|
+
PolygonMaskInlineArrangement["randomLength"] = "random-length";
|
|
7
|
+
PolygonMaskInlineArrangement["randomPoint"] = "random-point";
|
|
8
|
+
})(PolygonMaskInlineArrangement || (PolygonMaskInlineArrangement = {}));
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var PolygonMaskType;
|
|
2
|
+
(function (PolygonMaskType) {
|
|
3
|
+
PolygonMaskType["inline"] = "inline";
|
|
4
|
+
PolygonMaskType["inside"] = "inside";
|
|
5
|
+
PolygonMaskType["outside"] = "outside";
|
|
6
|
+
PolygonMaskType["none"] = "none";
|
|
7
|
+
})(PolygonMaskType || (PolygonMaskType = {}));
|
|
@@ -3,6 +3,7 @@ import { PolygonMaskDraw } from "./PolygonMaskDraw.js";
|
|
|
3
3
|
import { PolygonMaskInline } from "./PolygonMaskInline.js";
|
|
4
4
|
import { PolygonMaskLocalSvg } from "./PolygonMaskLocalSvg.js";
|
|
5
5
|
import { PolygonMaskMove } from "./PolygonMaskMove.js";
|
|
6
|
+
import { PolygonMaskType } from "../../Enums/PolygonMaskType.js";
|
|
6
7
|
export class PolygonMask {
|
|
7
8
|
constructor() {
|
|
8
9
|
this.draw = new PolygonMaskDraw();
|
|
@@ -10,7 +11,7 @@ export class PolygonMask {
|
|
|
10
11
|
this.inline = new PolygonMaskInline();
|
|
11
12
|
this.move = new PolygonMaskMove();
|
|
12
13
|
this.scale = 1;
|
|
13
|
-
this.type =
|
|
14
|
+
this.type = PolygonMaskType.none;
|
|
14
15
|
}
|
|
15
16
|
load(data) {
|
|
16
17
|
if (!data) {
|
|
@@ -29,7 +30,7 @@ export class PolygonMask {
|
|
|
29
30
|
this.enable = data.enable;
|
|
30
31
|
}
|
|
31
32
|
else {
|
|
32
|
-
this.enable = this.type !==
|
|
33
|
+
this.enable = this.type !== PolygonMaskType.none;
|
|
33
34
|
}
|
|
34
35
|
if (data.url !== undefined) {
|
|
35
36
|
this.url = data.url;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { PolygonMaskInlineArrangement, } from "../../Enums/PolygonMaskInlineArrangement.js";
|
|
1
2
|
export class PolygonMaskInline {
|
|
2
3
|
constructor() {
|
|
3
|
-
this.arrangement =
|
|
4
|
+
this.arrangement = PolygonMaskInlineArrangement.onePerPoint;
|
|
4
5
|
}
|
|
5
6
|
load(data) {
|
|
6
7
|
if (!data) {
|