@tsparticles/plugin-polygon-mask 3.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +70 -0
  3. package/browser/Enums/PolygonMaskInlineArrangement.js +1 -0
  4. package/browser/Enums/PolygonMaskMoveType.js +1 -0
  5. package/browser/Enums/PolygonMaskType.js +1 -0
  6. package/browser/Interfaces/ISvgPath.js +1 -0
  7. package/browser/Options/Classes/PolygonMask.js +56 -0
  8. package/browser/Options/Classes/PolygonMaskDraw.js +34 -0
  9. package/browser/Options/Classes/PolygonMaskDrawStroke.js +24 -0
  10. package/browser/Options/Classes/PolygonMaskInline.js +13 -0
  11. package/browser/Options/Classes/PolygonMaskLocalSvg.js +25 -0
  12. package/browser/Options/Classes/PolygonMaskMove.js +17 -0
  13. package/browser/Options/Interfaces/IPolygonMask.js +1 -0
  14. package/browser/Options/Interfaces/IPolygonMaskDraw.js +1 -0
  15. package/browser/Options/Interfaces/IPolygonMaskDrawStroke.js +1 -0
  16. package/browser/Options/Interfaces/IPolygonMaskInline.js +1 -0
  17. package/browser/Options/Interfaces/IPolygonMaskLocalSvg.js +1 -0
  18. package/browser/Options/Interfaces/IPolygonMaskMove.js +1 -0
  19. package/browser/PolygonMaskInstance.js +388 -0
  20. package/browser/index.js +33 -0
  21. package/browser/pathseg.js +1496 -0
  22. package/browser/types.js +1 -0
  23. package/browser/utils.js +108 -0
  24. package/cjs/Enums/PolygonMaskInlineArrangement.js +2 -0
  25. package/cjs/Enums/PolygonMaskMoveType.js +2 -0
  26. package/cjs/Enums/PolygonMaskType.js +2 -0
  27. package/cjs/Interfaces/ISvgPath.js +2 -0
  28. package/cjs/Options/Classes/PolygonMask.js +60 -0
  29. package/cjs/Options/Classes/PolygonMaskDraw.js +38 -0
  30. package/cjs/Options/Classes/PolygonMaskDrawStroke.js +28 -0
  31. package/cjs/Options/Classes/PolygonMaskInline.js +17 -0
  32. package/cjs/Options/Classes/PolygonMaskLocalSvg.js +29 -0
  33. package/cjs/Options/Classes/PolygonMaskMove.js +21 -0
  34. package/cjs/Options/Interfaces/IPolygonMask.js +2 -0
  35. package/cjs/Options/Interfaces/IPolygonMaskDraw.js +2 -0
  36. package/cjs/Options/Interfaces/IPolygonMaskDrawStroke.js +2 -0
  37. package/cjs/Options/Interfaces/IPolygonMaskInline.js +2 -0
  38. package/cjs/Options/Interfaces/IPolygonMaskLocalSvg.js +2 -0
  39. package/cjs/Options/Interfaces/IPolygonMaskMove.js +2 -0
  40. package/cjs/PolygonMaskInstance.js +407 -0
  41. package/cjs/index.js +62 -0
  42. package/cjs/pathseg.js +1496 -0
  43. package/cjs/types.js +2 -0
  44. package/cjs/utils.js +116 -0
  45. package/esm/Enums/PolygonMaskInlineArrangement.js +1 -0
  46. package/esm/Enums/PolygonMaskMoveType.js +1 -0
  47. package/esm/Enums/PolygonMaskType.js +1 -0
  48. package/esm/Interfaces/ISvgPath.js +1 -0
  49. package/esm/Options/Classes/PolygonMask.js +56 -0
  50. package/esm/Options/Classes/PolygonMaskDraw.js +34 -0
  51. package/esm/Options/Classes/PolygonMaskDrawStroke.js +24 -0
  52. package/esm/Options/Classes/PolygonMaskInline.js +13 -0
  53. package/esm/Options/Classes/PolygonMaskLocalSvg.js +25 -0
  54. package/esm/Options/Classes/PolygonMaskMove.js +17 -0
  55. package/esm/Options/Interfaces/IPolygonMask.js +1 -0
  56. package/esm/Options/Interfaces/IPolygonMaskDraw.js +1 -0
  57. package/esm/Options/Interfaces/IPolygonMaskDrawStroke.js +1 -0
  58. package/esm/Options/Interfaces/IPolygonMaskInline.js +1 -0
  59. package/esm/Options/Interfaces/IPolygonMaskLocalSvg.js +1 -0
  60. package/esm/Options/Interfaces/IPolygonMaskMove.js +1 -0
  61. package/esm/PolygonMaskInstance.js +388 -0
  62. package/esm/index.js +33 -0
  63. package/esm/pathseg.js +1496 -0
  64. package/esm/types.js +1 -0
  65. package/esm/utils.js +108 -0
  66. package/package.json +81 -0
  67. package/report.html +39 -0
  68. package/tsparticles.plugin.polygon-mask.js +2276 -0
  69. package/tsparticles.plugin.polygon-mask.min.js +2 -0
  70. package/tsparticles.plugin.polygon-mask.min.js.LICENSE.txt +8 -0
  71. package/types/Enums/PolygonMaskInlineArrangement.d.ts +8 -0
  72. package/types/Enums/PolygonMaskMoveType.d.ts +4 -0
  73. package/types/Enums/PolygonMaskType.d.ts +6 -0
  74. package/types/Interfaces/ISvgPath.d.ts +6 -0
  75. package/types/Options/Classes/PolygonMask.d.ts +23 -0
  76. package/types/Options/Classes/PolygonMaskDraw.d.ts +14 -0
  77. package/types/Options/Classes/PolygonMaskDrawStroke.d.ts +10 -0
  78. package/types/Options/Classes/PolygonMaskInline.d.ts +9 -0
  79. package/types/Options/Classes/PolygonMaskLocalSvg.d.ts +8 -0
  80. package/types/Options/Classes/PolygonMaskMove.d.ts +9 -0
  81. package/types/Options/Interfaces/IPolygonMask.d.ts +17 -0
  82. package/types/Options/Interfaces/IPolygonMaskDraw.d.ts +8 -0
  83. package/types/Options/Interfaces/IPolygonMaskDrawStroke.d.ts +6 -0
  84. package/types/Options/Interfaces/IPolygonMaskInline.d.ts +4 -0
  85. package/types/Options/Interfaces/IPolygonMaskLocalSvg.d.ts +5 -0
  86. package/types/Options/Interfaces/IPolygonMaskMove.d.ts +5 -0
  87. package/types/PolygonMaskInstance.d.ts +37 -0
  88. package/types/index.d.ts +6 -0
  89. package/types/pathseg.d.ts +0 -0
  90. package/types/types.d.ts +15 -0
  91. package/types/utils.d.ts +11 -0
  92. package/umd/Enums/PolygonMaskInlineArrangement.js +12 -0
  93. package/umd/Enums/PolygonMaskMoveType.js +12 -0
  94. package/umd/Enums/PolygonMaskType.js +12 -0
  95. package/umd/Interfaces/ISvgPath.js +12 -0
  96. package/umd/Options/Classes/PolygonMask.js +70 -0
  97. package/umd/Options/Classes/PolygonMaskDraw.js +48 -0
  98. package/umd/Options/Classes/PolygonMaskDrawStroke.js +38 -0
  99. package/umd/Options/Classes/PolygonMaskInline.js +27 -0
  100. package/umd/Options/Classes/PolygonMaskLocalSvg.js +39 -0
  101. package/umd/Options/Classes/PolygonMaskMove.js +31 -0
  102. package/umd/Options/Interfaces/IPolygonMask.js +12 -0
  103. package/umd/Options/Interfaces/IPolygonMaskDraw.js +12 -0
  104. package/umd/Options/Interfaces/IPolygonMaskDrawStroke.js +12 -0
  105. package/umd/Options/Interfaces/IPolygonMaskInline.js +12 -0
  106. package/umd/Options/Interfaces/IPolygonMaskLocalSvg.js +12 -0
  107. package/umd/Options/Interfaces/IPolygonMaskMove.js +12 -0
  108. package/umd/PolygonMaskInstance.js +402 -0
  109. package/umd/index.js +61 -0
  110. package/umd/pathseg.js +1496 -0
  111. package/umd/types.js +12 -0
  112. package/umd/utils.js +126 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,108 @@
1
+ import { Vector, getDistances, getStyleFromRgb, rangeColorToRgb } from "@tsparticles/engine";
2
+ export function drawPolygonMask(context, rawData, stroke) {
3
+ const color = rangeColorToRgb(stroke.color);
4
+ if (!color) {
5
+ return;
6
+ }
7
+ context.beginPath();
8
+ context.moveTo(rawData[0].x, rawData[0].y);
9
+ for (const item of rawData) {
10
+ context.lineTo(item.x, item.y);
11
+ }
12
+ context.closePath();
13
+ context.strokeStyle = getStyleFromRgb(color);
14
+ context.lineWidth = stroke.width;
15
+ context.stroke();
16
+ }
17
+ export function drawPolygonMaskPath(context, path, stroke, position) {
18
+ context.setTransform(1, 0, 0, 1, position.x, position.y);
19
+ const color = rangeColorToRgb(stroke.color);
20
+ if (!color) {
21
+ return;
22
+ }
23
+ context.strokeStyle = getStyleFromRgb(color, stroke.opacity);
24
+ context.lineWidth = stroke.width;
25
+ context.stroke(path);
26
+ context.setTransform(1, 0, 0, 1, 0, 0);
27
+ }
28
+ export function parsePaths(paths, scale, offset) {
29
+ var _a;
30
+ const res = [];
31
+ 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 = {
33
+ x: 0,
34
+ y: 0,
35
+ };
36
+ 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) {
40
+ case svgPathSeg.PATHSEG_MOVETO_ABS:
41
+ case svgPathSeg.PATHSEG_LINETO_ABS:
42
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
43
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
44
+ case svgPathSeg.PATHSEG_ARC_ABS:
45
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
46
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: {
47
+ const absSeg = segment;
48
+ p.x = absSeg.x;
49
+ p.y = absSeg.y;
50
+ break;
51
+ }
52
+ case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
53
+ p.x = segment.x;
54
+ break;
55
+ case svgPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
56
+ p.y = segment.y;
57
+ break;
58
+ case svgPathSeg.PATHSEG_LINETO_REL:
59
+ case svgPathSeg.PATHSEG_MOVETO_REL:
60
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_REL:
61
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
62
+ case svgPathSeg.PATHSEG_ARC_REL:
63
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
64
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: {
65
+ const relSeg = segment;
66
+ p.x += relSeg.x;
67
+ p.y += relSeg.y;
68
+ break;
69
+ }
70
+ case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
71
+ p.x += segment.x;
72
+ break;
73
+ case svgPathSeg.PATHSEG_LINETO_VERTICAL_REL:
74
+ p.y += segment.y;
75
+ break;
76
+ case svgPathSeg.PATHSEG_UNKNOWN:
77
+ case svgPathSeg.PATHSEG_CLOSEPATH:
78
+ continue;
79
+ }
80
+ res.push({
81
+ x: p.x * scale + offset.x,
82
+ y: p.y * scale + offset.y,
83
+ });
84
+ }
85
+ }
86
+ return res;
87
+ }
88
+ export function calcClosestPtOnSegment(s1, s2, pos) {
89
+ const { dx: dx1, dy: dy1 } = getDistances(pos, s1), { dx: dx2, dy: dy2 } = getDistances(s2, s1), t = (dx1 * dx2 + dy1 * dy2) / (dx2 ** 2 + dy2 ** 2), res = {
90
+ x: s1.x + dx2 * t,
91
+ y: s1.y + dy2 * t,
92
+ isOnSegment: t >= 0 && t <= 1,
93
+ };
94
+ if (t < 0) {
95
+ res.x = s1.x;
96
+ res.y = s1.y;
97
+ }
98
+ else if (t > 1) {
99
+ res.x = s2.x;
100
+ res.y = s2.y;
101
+ }
102
+ return res;
103
+ }
104
+ export function segmentBounce(start, stop, velocity) {
105
+ const { dx, dy } = getDistances(start, stop), wallAngle = Math.atan2(dy, dx), wallNormal = Vector.create(Math.sin(wallAngle), -Math.cos(wallAngle)), d = 2 * (velocity.x * wallNormal.x + velocity.y * wallNormal.y);
106
+ wallNormal.multTo(d);
107
+ velocity.subFrom(wallNormal);
108
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
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
+ const engine_1 = require("@tsparticles/engine");
9
+ class PolygonMask {
10
+ constructor() {
11
+ this.draw = new PolygonMaskDraw_1.PolygonMaskDraw();
12
+ this.enable = false;
13
+ this.inline = new PolygonMaskInline_1.PolygonMaskInline();
14
+ this.move = new PolygonMaskMove_1.PolygonMaskMove();
15
+ this.scale = 1;
16
+ this.type = "none";
17
+ }
18
+ get inlineArrangement() {
19
+ return this.inline.arrangement;
20
+ }
21
+ set inlineArrangement(value) {
22
+ this.inline.arrangement = value;
23
+ }
24
+ load(data) {
25
+ if (!data) {
26
+ return;
27
+ }
28
+ this.draw.load(data.draw);
29
+ this.inline.load(data.inline);
30
+ this.move.load(data.move);
31
+ if (data.scale !== undefined) {
32
+ this.scale = data.scale;
33
+ }
34
+ if (data.type !== undefined) {
35
+ this.type = data.type;
36
+ }
37
+ if (data.enable !== undefined) {
38
+ this.enable = data.enable;
39
+ }
40
+ else {
41
+ this.enable = this.type !== "none";
42
+ }
43
+ if (data.url !== undefined) {
44
+ this.url = data.url;
45
+ }
46
+ if (data.data !== undefined) {
47
+ if (typeof data.data === "string") {
48
+ this.data = data.data;
49
+ }
50
+ else {
51
+ this.data = new PolygonMaskLocalSvg_1.PolygonMaskLocalSvg();
52
+ this.data.load(data.data);
53
+ }
54
+ }
55
+ if (data.position !== undefined) {
56
+ this.position = (0, engine_1.deepExtend)({}, data.position);
57
+ }
58
+ }
59
+ }
60
+ exports.PolygonMask = PolygonMask;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonMaskDraw = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ const PolygonMaskDrawStroke_1 = require("./PolygonMaskDrawStroke");
6
+ class PolygonMaskDraw {
7
+ constructor() {
8
+ 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;
22
+ }
23
+ load(data) {
24
+ var _a;
25
+ if (!data) {
26
+ return;
27
+ }
28
+ if (data.enable !== undefined) {
29
+ this.enable = data.enable;
30
+ }
31
+ const stroke = (_a = data.stroke) !== null && _a !== void 0 ? _a : {
32
+ color: data.lineColor,
33
+ width: data.lineWidth,
34
+ };
35
+ this.stroke.load(stroke);
36
+ }
37
+ }
38
+ exports.PolygonMaskDraw = PolygonMaskDraw;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonMaskDrawStroke = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ class PolygonMaskDrawStroke {
6
+ constructor() {
7
+ this.color = new engine_1.OptionsColor();
8
+ this.width = 0.5;
9
+ this.opacity = 1;
10
+ }
11
+ load(data) {
12
+ var _a;
13
+ if (!data) {
14
+ return;
15
+ }
16
+ 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;
19
+ }
20
+ if (data.opacity !== undefined) {
21
+ this.opacity = data.opacity;
22
+ }
23
+ if (data.width !== undefined) {
24
+ this.width = data.width;
25
+ }
26
+ }
27
+ }
28
+ exports.PolygonMaskDrawStroke = PolygonMaskDrawStroke;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonMaskInline = void 0;
4
+ class PolygonMaskInline {
5
+ constructor() {
6
+ this.arrangement = "one-per-point";
7
+ }
8
+ load(data) {
9
+ if (!data) {
10
+ return;
11
+ }
12
+ if (data.arrangement !== undefined) {
13
+ this.arrangement = data.arrangement;
14
+ }
15
+ }
16
+ }
17
+ exports.PolygonMaskInline = PolygonMaskInline;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonMaskLocalSvg = void 0;
4
+ class PolygonMaskLocalSvg {
5
+ constructor() {
6
+ this.path = [];
7
+ this.size = {
8
+ height: 0,
9
+ width: 0,
10
+ };
11
+ }
12
+ load(data) {
13
+ if (!data) {
14
+ return;
15
+ }
16
+ if (data.path !== undefined) {
17
+ this.path = data.path;
18
+ }
19
+ if (data.size !== undefined) {
20
+ if (data.size.width !== undefined) {
21
+ this.size.width = data.size.width;
22
+ }
23
+ if (data.size.height !== undefined) {
24
+ this.size.height = data.size.height;
25
+ }
26
+ }
27
+ }
28
+ }
29
+ exports.PolygonMaskLocalSvg = PolygonMaskLocalSvg;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PolygonMaskMove = void 0;
4
+ class PolygonMaskMove {
5
+ constructor() {
6
+ this.radius = 10;
7
+ this.type = "path";
8
+ }
9
+ load(data) {
10
+ if (!data) {
11
+ return;
12
+ }
13
+ if (data.radius !== undefined) {
14
+ this.radius = data.radius;
15
+ }
16
+ if (data.type !== undefined) {
17
+ this.type = data.type;
18
+ }
19
+ }
20
+ }
21
+ exports.PolygonMaskMove = PolygonMaskMove;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });