@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
package/cjs/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/utils.js ADDED
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.segmentBounce = exports.calcClosestPtOnSegment = exports.parsePaths = exports.drawPolygonMaskPath = exports.drawPolygonMask = void 0;
4
+ const engine_1 = require("@tsparticles/engine");
5
+ function drawPolygonMask(context, rawData, stroke) {
6
+ const color = (0, engine_1.rangeColorToRgb)(stroke.color);
7
+ if (!color) {
8
+ return;
9
+ }
10
+ context.beginPath();
11
+ context.moveTo(rawData[0].x, rawData[0].y);
12
+ for (const item of rawData) {
13
+ context.lineTo(item.x, item.y);
14
+ }
15
+ context.closePath();
16
+ context.strokeStyle = (0, engine_1.getStyleFromRgb)(color);
17
+ context.lineWidth = stroke.width;
18
+ context.stroke();
19
+ }
20
+ exports.drawPolygonMask = drawPolygonMask;
21
+ function drawPolygonMaskPath(context, path, stroke, position) {
22
+ context.setTransform(1, 0, 0, 1, position.x, position.y);
23
+ const color = (0, engine_1.rangeColorToRgb)(stroke.color);
24
+ if (!color) {
25
+ return;
26
+ }
27
+ context.strokeStyle = (0, engine_1.getStyleFromRgb)(color, stroke.opacity);
28
+ context.lineWidth = stroke.width;
29
+ context.stroke(path);
30
+ context.setTransform(1, 0, 0, 1, 0, 0);
31
+ }
32
+ exports.drawPolygonMaskPath = drawPolygonMaskPath;
33
+ function parsePaths(paths, scale, offset) {
34
+ var _a;
35
+ const res = [];
36
+ for (const path of paths) {
37
+ const segments = path.element.pathSegList, len = (_a = segments === null || segments === void 0 ? void 0 : segments.numberOfItems) !== null && _a !== void 0 ? _a : 0, p = {
38
+ x: 0,
39
+ y: 0,
40
+ };
41
+ for (let i = 0; i < len; i++) {
42
+ const segment = segments === null || segments === void 0 ? void 0 : segments.getItem(i);
43
+ const svgPathSeg = window.SVGPathSeg;
44
+ switch (segment === null || segment === void 0 ? void 0 : segment.pathSegType) {
45
+ case svgPathSeg.PATHSEG_MOVETO_ABS:
46
+ case svgPathSeg.PATHSEG_LINETO_ABS:
47
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
48
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
49
+ case svgPathSeg.PATHSEG_ARC_ABS:
50
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
51
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS: {
52
+ const absSeg = segment;
53
+ p.x = absSeg.x;
54
+ p.y = absSeg.y;
55
+ break;
56
+ }
57
+ case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
58
+ p.x = segment.x;
59
+ break;
60
+ case svgPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
61
+ p.y = segment.y;
62
+ break;
63
+ case svgPathSeg.PATHSEG_LINETO_REL:
64
+ case svgPathSeg.PATHSEG_MOVETO_REL:
65
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_REL:
66
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
67
+ case svgPathSeg.PATHSEG_ARC_REL:
68
+ case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
69
+ case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL: {
70
+ const relSeg = segment;
71
+ p.x += relSeg.x;
72
+ p.y += relSeg.y;
73
+ break;
74
+ }
75
+ case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
76
+ p.x += segment.x;
77
+ break;
78
+ case svgPathSeg.PATHSEG_LINETO_VERTICAL_REL:
79
+ p.y += segment.y;
80
+ break;
81
+ case svgPathSeg.PATHSEG_UNKNOWN:
82
+ case svgPathSeg.PATHSEG_CLOSEPATH:
83
+ continue;
84
+ }
85
+ res.push({
86
+ x: p.x * scale + offset.x,
87
+ y: p.y * scale + offset.y,
88
+ });
89
+ }
90
+ }
91
+ return res;
92
+ }
93
+ exports.parsePaths = parsePaths;
94
+ function calcClosestPtOnSegment(s1, s2, pos) {
95
+ const { dx: dx1, dy: dy1 } = (0, engine_1.getDistances)(pos, s1), { dx: dx2, dy: dy2 } = (0, engine_1.getDistances)(s2, s1), t = (dx1 * dx2 + dy1 * dy2) / (Math.pow(dx2, 2) + Math.pow(dy2, 2)), res = {
96
+ x: s1.x + dx2 * t,
97
+ y: s1.y + dy2 * t,
98
+ isOnSegment: t >= 0 && t <= 1,
99
+ };
100
+ if (t < 0) {
101
+ res.x = s1.x;
102
+ res.y = s1.y;
103
+ }
104
+ else if (t > 1) {
105
+ res.x = s2.x;
106
+ res.y = s2.y;
107
+ }
108
+ return res;
109
+ }
110
+ exports.calcClosestPtOnSegment = calcClosestPtOnSegment;
111
+ function segmentBounce(start, stop, velocity) {
112
+ const { dx, dy } = (0, engine_1.getDistances)(start, stop), wallAngle = Math.atan2(dy, dx), wallNormal = engine_1.Vector.create(Math.sin(wallAngle), -Math.cos(wallAngle)), d = 2 * (velocity.x * wallNormal.x + velocity.y * wallNormal.y);
113
+ wallNormal.multTo(d);
114
+ velocity.subFrom(wallNormal);
115
+ }
116
+ exports.segmentBounce = segmentBounce;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,56 @@
1
+ import { PolygonMaskDraw } from "./PolygonMaskDraw";
2
+ import { PolygonMaskInline } from "./PolygonMaskInline";
3
+ import { PolygonMaskLocalSvg } from "./PolygonMaskLocalSvg";
4
+ import { PolygonMaskMove } from "./PolygonMaskMove";
5
+ import { deepExtend } from "@tsparticles/engine";
6
+ export class PolygonMask {
7
+ constructor() {
8
+ this.draw = new PolygonMaskDraw();
9
+ this.enable = false;
10
+ this.inline = new PolygonMaskInline();
11
+ this.move = new PolygonMaskMove();
12
+ this.scale = 1;
13
+ this.type = "none";
14
+ }
15
+ get inlineArrangement() {
16
+ return this.inline.arrangement;
17
+ }
18
+ set inlineArrangement(value) {
19
+ this.inline.arrangement = value;
20
+ }
21
+ load(data) {
22
+ if (!data) {
23
+ return;
24
+ }
25
+ this.draw.load(data.draw);
26
+ this.inline.load(data.inline);
27
+ this.move.load(data.move);
28
+ if (data.scale !== undefined) {
29
+ this.scale = data.scale;
30
+ }
31
+ if (data.type !== undefined) {
32
+ this.type = data.type;
33
+ }
34
+ if (data.enable !== undefined) {
35
+ this.enable = data.enable;
36
+ }
37
+ else {
38
+ this.enable = this.type !== "none";
39
+ }
40
+ if (data.url !== undefined) {
41
+ this.url = data.url;
42
+ }
43
+ if (data.data !== undefined) {
44
+ if (typeof data.data === "string") {
45
+ this.data = data.data;
46
+ }
47
+ else {
48
+ this.data = new PolygonMaskLocalSvg();
49
+ this.data.load(data.data);
50
+ }
51
+ }
52
+ if (data.position !== undefined) {
53
+ this.position = deepExtend({}, data.position);
54
+ }
55
+ }
56
+ }
@@ -0,0 +1,34 @@
1
+ import { OptionsColor } from "@tsparticles/engine";
2
+ import { PolygonMaskDrawStroke } from "./PolygonMaskDrawStroke";
3
+ export class PolygonMaskDraw {
4
+ constructor() {
5
+ this.enable = false;
6
+ this.stroke = new PolygonMaskDrawStroke();
7
+ }
8
+ get lineColor() {
9
+ return this.stroke.color;
10
+ }
11
+ set lineColor(value) {
12
+ this.stroke.color = OptionsColor.create(this.stroke.color, value);
13
+ }
14
+ get lineWidth() {
15
+ return this.stroke.width;
16
+ }
17
+ set lineWidth(value) {
18
+ this.stroke.width = value;
19
+ }
20
+ load(data) {
21
+ var _a;
22
+ if (!data) {
23
+ return;
24
+ }
25
+ if (data.enable !== undefined) {
26
+ this.enable = data.enable;
27
+ }
28
+ const stroke = (_a = data.stroke) !== null && _a !== void 0 ? _a : {
29
+ color: data.lineColor,
30
+ width: data.lineWidth,
31
+ };
32
+ this.stroke.load(stroke);
33
+ }
34
+ }
@@ -0,0 +1,24 @@
1
+ import { OptionsColor, stringToAlpha } from "@tsparticles/engine";
2
+ export class PolygonMaskDrawStroke {
3
+ constructor() {
4
+ this.color = new OptionsColor();
5
+ this.width = 0.5;
6
+ this.opacity = 1;
7
+ }
8
+ load(data) {
9
+ var _a;
10
+ if (!data) {
11
+ return;
12
+ }
13
+ this.color = OptionsColor.create(this.color, data.color);
14
+ if (typeof this.color.value === "string") {
15
+ this.opacity = (_a = stringToAlpha(this.color.value)) !== null && _a !== void 0 ? _a : this.opacity;
16
+ }
17
+ if (data.opacity !== undefined) {
18
+ this.opacity = data.opacity;
19
+ }
20
+ if (data.width !== undefined) {
21
+ this.width = data.width;
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,13 @@
1
+ export class PolygonMaskInline {
2
+ constructor() {
3
+ this.arrangement = "one-per-point";
4
+ }
5
+ load(data) {
6
+ if (!data) {
7
+ return;
8
+ }
9
+ if (data.arrangement !== undefined) {
10
+ this.arrangement = data.arrangement;
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ export class PolygonMaskLocalSvg {
2
+ constructor() {
3
+ this.path = [];
4
+ this.size = {
5
+ height: 0,
6
+ width: 0,
7
+ };
8
+ }
9
+ load(data) {
10
+ if (!data) {
11
+ return;
12
+ }
13
+ if (data.path !== undefined) {
14
+ this.path = data.path;
15
+ }
16
+ if (data.size !== undefined) {
17
+ if (data.size.width !== undefined) {
18
+ this.size.width = data.size.width;
19
+ }
20
+ if (data.size.height !== undefined) {
21
+ this.size.height = data.size.height;
22
+ }
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,17 @@
1
+ export class PolygonMaskMove {
2
+ constructor() {
3
+ this.radius = 10;
4
+ this.type = "path";
5
+ }
6
+ load(data) {
7
+ if (!data) {
8
+ return;
9
+ }
10
+ if (data.radius !== undefined) {
11
+ this.radius = data.radius;
12
+ }
13
+ if (data.type !== undefined) {
14
+ this.type = data.type;
15
+ }
16
+ }
17
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};