@tsparticles/plugin-polygon-mask 3.0.0-alpha.1 → 3.0.0-beta.1

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 (52) hide show
  1. package/README.md +15 -11
  2. package/browser/Options/Classes/PolygonMask.js +6 -12
  3. package/browser/Options/Classes/PolygonMaskDraw.js +2 -19
  4. package/browser/Options/Classes/PolygonMaskDrawStroke.js +3 -4
  5. package/browser/PolygonMaskInstance.js +298 -306
  6. package/browser/index.js +13 -14
  7. package/browser/package.json +1 -0
  8. package/browser/pathseg.js +1 -1
  9. package/browser/utils.js +3 -5
  10. package/cjs/Options/Classes/PolygonMask.js +9 -15
  11. package/cjs/Options/Classes/PolygonMaskDraw.js +3 -20
  12. package/cjs/Options/Classes/PolygonMaskDrawStroke.js +2 -3
  13. package/cjs/PolygonMaskInstance.js +311 -334
  14. package/cjs/index.js +15 -27
  15. package/cjs/package.json +1 -0
  16. package/cjs/pathseg.js +1 -1
  17. package/cjs/utils.js +4 -6
  18. package/esm/Options/Classes/PolygonMask.js +6 -12
  19. package/esm/Options/Classes/PolygonMaskDraw.js +2 -19
  20. package/esm/Options/Classes/PolygonMaskDrawStroke.js +3 -4
  21. package/esm/PolygonMaskInstance.js +298 -306
  22. package/esm/index.js +13 -14
  23. package/esm/package.json +1 -0
  24. package/esm/pathseg.js +1 -1
  25. package/esm/utils.js +3 -5
  26. package/package.json +21 -6
  27. package/report.html +4 -4
  28. package/tsparticles.plugin.polygon-mask.js +336 -362
  29. package/tsparticles.plugin.polygon-mask.min.js +1 -1
  30. package/tsparticles.plugin.polygon-mask.min.js.LICENSE.txt +1 -8
  31. package/types/Interfaces/ISvgPath.d.ts +1 -1
  32. package/types/Options/Classes/PolygonMask.d.ts +7 -10
  33. package/types/Options/Classes/PolygonMaskDraw.d.ts +3 -8
  34. package/types/Options/Classes/PolygonMaskDrawStroke.d.ts +2 -3
  35. package/types/Options/Classes/PolygonMaskInline.d.ts +3 -3
  36. package/types/Options/Classes/PolygonMaskLocalSvg.d.ts +1 -1
  37. package/types/Options/Classes/PolygonMaskMove.d.ts +2 -2
  38. package/types/Options/Interfaces/IPolygonMask.d.ts +5 -5
  39. package/types/Options/Interfaces/IPolygonMaskDraw.d.ts +1 -4
  40. package/types/Options/Interfaces/IPolygonMaskInline.d.ts +1 -1
  41. package/types/Options/Interfaces/IPolygonMaskMove.d.ts +1 -1
  42. package/types/PolygonMaskInstance.d.ts +15 -17
  43. package/types/index.d.ts +5 -5
  44. package/types/types.d.ts +3 -3
  45. package/types/utils.d.ts +3 -4
  46. package/umd/Options/Classes/PolygonMask.js +10 -16
  47. package/umd/Options/Classes/PolygonMaskDraw.js +4 -21
  48. package/umd/Options/Classes/PolygonMaskDrawStroke.js +2 -3
  49. package/umd/PolygonMaskInstance.js +300 -308
  50. package/umd/index.js +16 -17
  51. package/umd/pathseg.js +1 -1
  52. package/umd/utils.js +3 -5
package/browser/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import "./pathseg";
2
- import { PolygonMask } from "./Options/Classes/PolygonMask";
3
- import { PolygonMaskInstance } from "./PolygonMaskInstance";
1
+ import "./pathseg.js";
2
+ import { PolygonMask } from "./Options/Classes/PolygonMask.js";
3
+ import { PolygonMaskInstance } from "./PolygonMaskInstance.js";
4
4
  class PolygonMaskPlugin {
5
5
  constructor(engine) {
6
6
  this.id = "polygonMask";
@@ -10,24 +10,23 @@ class PolygonMaskPlugin {
10
10
  return new PolygonMaskInstance(container, this._engine);
11
11
  }
12
12
  loadOptions(options, source) {
13
- if (!this.needsPlugin(source)) {
13
+ if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
14
14
  return;
15
15
  }
16
16
  let polygonOptions = options.polygon;
17
- if ((polygonOptions === null || polygonOptions === void 0 ? void 0 : polygonOptions.load) === undefined) {
17
+ if (polygonOptions?.load === undefined) {
18
18
  options.polygon = polygonOptions = new PolygonMask();
19
19
  }
20
- polygonOptions.load(source === null || source === void 0 ? void 0 : source.polygon);
20
+ polygonOptions.load(source?.polygon);
21
21
  }
22
22
  needsPlugin(options) {
23
- var _a, _b, _c;
24
- return ((_b = (_a = options === null || options === void 0 ? void 0 : options.polygon) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : (((_c = options === null || options === void 0 ? void 0 : options.polygon) === null || _c === void 0 ? void 0 : _c.type) !== undefined && options.polygon.type !== "none"));
23
+ return (options?.polygon?.enable ??
24
+ (options?.polygon?.type !== undefined && options.polygon.type !== "none"));
25
25
  }
26
26
  }
27
- export async function loadPolygonMaskPlugin(engine) {
28
- const plugin = new PolygonMaskPlugin(engine);
29
- await engine.addPlugin(plugin);
27
+ export async function loadPolygonMaskPlugin(engine, refresh = true) {
28
+ await engine.addPlugin(new PolygonMaskPlugin(engine), refresh);
30
29
  }
31
- export * from "./Enums/PolygonMaskInlineArrangement";
32
- export * from "./Enums/PolygonMaskMoveType";
33
- export * from "./Enums/PolygonMaskType";
30
+ export * from "./Enums/PolygonMaskInlineArrangement.js";
31
+ export * from "./Enums/PolygonMaskMoveType.js";
32
+ export * from "./Enums/PolygonMaskType.js";
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -1064,7 +1064,7 @@
1064
1064
  this._pathElement.setAttribute("d", window.SVGPathSegList._pathSegArrayAsString(this._list));
1065
1065
  this._pathElementMutationObserver.observe(this._pathElement, this._mutationObserverConfig);
1066
1066
  };
1067
- window.SVGPathSegList.prototype.segmentChanged = function (pathSeg) {
1067
+ window.SVGPathSegList.prototype.segmentChanged = function () {
1068
1068
  this._writeListToPath();
1069
1069
  };
1070
1070
  window.SVGPathSegList.prototype.clear = function () {
package/browser/utils.js CHANGED
@@ -26,17 +26,15 @@ export function drawPolygonMaskPath(context, path, stroke, position) {
26
26
  context.setTransform(1, 0, 0, 1, 0, 0);
27
27
  }
28
28
  export function parsePaths(paths, scale, offset) {
29
- var _a;
30
29
  const res = [];
31
30
  for (const path of paths) {
32
- const segments = path.element.pathSegList, len = (_a = segments === null || segments === void 0 ? void 0 : segments.numberOfItems) !== null && _a !== void 0 ? _a : 0, p = {
31
+ const segments = path.element.pathSegList, len = segments?.numberOfItems ?? 0, p = {
33
32
  x: 0,
34
33
  y: 0,
35
34
  };
36
35
  for (let i = 0; i < len; i++) {
37
- const segment = segments === null || segments === void 0 ? void 0 : segments.getItem(i);
38
- const svgPathSeg = window.SVGPathSeg;
39
- switch (segment === null || segment === void 0 ? void 0 : segment.pathSegType) {
36
+ const segment = segments?.getItem(i), svgPathSeg = window.SVGPathSeg;
37
+ switch (segment?.pathSegType) {
40
38
  case svgPathSeg.PATHSEG_MOVETO_ABS:
41
39
  case svgPathSeg.PATHSEG_LINETO_ABS:
42
40
  case svgPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
@@ -1,26 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PolygonMask = void 0;
4
- const PolygonMaskDraw_1 = require("./PolygonMaskDraw");
5
- const PolygonMaskInline_1 = require("./PolygonMaskInline");
6
- const PolygonMaskLocalSvg_1 = require("./PolygonMaskLocalSvg");
7
- const PolygonMaskMove_1 = require("./PolygonMaskMove");
8
4
  const engine_1 = require("@tsparticles/engine");
5
+ const PolygonMaskDraw_js_1 = require("./PolygonMaskDraw.js");
6
+ const PolygonMaskInline_js_1 = require("./PolygonMaskInline.js");
7
+ const PolygonMaskLocalSvg_js_1 = require("./PolygonMaskLocalSvg.js");
8
+ const PolygonMaskMove_js_1 = require("./PolygonMaskMove.js");
9
9
  class PolygonMask {
10
10
  constructor() {
11
- this.draw = new PolygonMaskDraw_1.PolygonMaskDraw();
11
+ this.draw = new PolygonMaskDraw_js_1.PolygonMaskDraw();
12
12
  this.enable = false;
13
- this.inline = new PolygonMaskInline_1.PolygonMaskInline();
14
- this.move = new PolygonMaskMove_1.PolygonMaskMove();
13
+ this.inline = new PolygonMaskInline_js_1.PolygonMaskInline();
14
+ this.move = new PolygonMaskMove_js_1.PolygonMaskMove();
15
15
  this.scale = 1;
16
16
  this.type = "none";
17
17
  }
18
- get inlineArrangement() {
19
- return this.inline.arrangement;
20
- }
21
- set inlineArrangement(value) {
22
- this.inline.arrangement = value;
23
- }
24
18
  load(data) {
25
19
  if (!data) {
26
20
  return;
@@ -44,11 +38,11 @@ class PolygonMask {
44
38
  this.url = data.url;
45
39
  }
46
40
  if (data.data !== undefined) {
47
- if (typeof data.data === "string") {
41
+ if ((0, engine_1.isString)(data.data)) {
48
42
  this.data = data.data;
49
43
  }
50
44
  else {
51
- this.data = new PolygonMaskLocalSvg_1.PolygonMaskLocalSvg();
45
+ this.data = new PolygonMaskLocalSvg_js_1.PolygonMaskLocalSvg();
52
46
  this.data.load(data.data);
53
47
  }
54
48
  }
@@ -1,37 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PolygonMaskDraw = void 0;
4
- const engine_1 = require("@tsparticles/engine");
5
- const PolygonMaskDrawStroke_1 = require("./PolygonMaskDrawStroke");
4
+ const PolygonMaskDrawStroke_js_1 = require("./PolygonMaskDrawStroke.js");
6
5
  class PolygonMaskDraw {
7
6
  constructor() {
8
7
  this.enable = false;
9
- this.stroke = new PolygonMaskDrawStroke_1.PolygonMaskDrawStroke();
10
- }
11
- get lineColor() {
12
- return this.stroke.color;
13
- }
14
- set lineColor(value) {
15
- this.stroke.color = engine_1.OptionsColor.create(this.stroke.color, value);
16
- }
17
- get lineWidth() {
18
- return this.stroke.width;
19
- }
20
- set lineWidth(value) {
21
- this.stroke.width = value;
8
+ this.stroke = new PolygonMaskDrawStroke_js_1.PolygonMaskDrawStroke();
22
9
  }
23
10
  load(data) {
24
- var _a;
25
11
  if (!data) {
26
12
  return;
27
13
  }
28
14
  if (data.enable !== undefined) {
29
15
  this.enable = data.enable;
30
16
  }
31
- const stroke = (_a = data.stroke) !== null && _a !== void 0 ? _a : {
32
- color: data.lineColor,
33
- width: data.lineWidth,
34
- };
17
+ const stroke = data.stroke;
35
18
  this.stroke.load(stroke);
36
19
  }
37
20
  }
@@ -9,13 +9,12 @@ class PolygonMaskDrawStroke {
9
9
  this.opacity = 1;
10
10
  }
11
11
  load(data) {
12
- var _a;
13
12
  if (!data) {
14
13
  return;
15
14
  }
16
15
  this.color = engine_1.OptionsColor.create(this.color, data.color);
17
- if (typeof this.color.value === "string") {
18
- this.opacity = (_a = (0, engine_1.stringToAlpha)(this.color.value)) !== null && _a !== void 0 ? _a : this.opacity;
16
+ if ((0, engine_1.isString)(this.color.value)) {
17
+ this.opacity = (0, engine_1.stringToAlpha)(this.color.value) ?? this.opacity;
19
18
  }
20
19
  if (data.opacity !== undefined) {
21
20
  this.opacity = data.opacity;