@tsparticles/path-svg 3.0.3 → 3.2.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/794.min.js +2 -0
- package/794.min.js.LICENSE.txt +1 -0
- package/browser/SVGPathGenerator.js +36 -37
- package/browser/index.js +1 -1
- package/cjs/SVGPathGenerator.js +35 -36
- package/cjs/index.js +25 -2
- package/dist_browser_SVGPathGenerator_js.js +30 -0
- package/esm/SVGPathGenerator.js +36 -37
- package/esm/index.js +1 -1
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.path.svg.js +241 -178
- package/tsparticles.path.svg.min.js +1 -1
- package/tsparticles.path.svg.min.js.LICENSE.txt +1 -1
- package/types/SVGPathGenerator.d.ts +2 -7
- package/umd/SVGPathGenerator.js +35 -36
- package/umd/index.js +27 -3
package/umd/SVGPathGenerator.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.SVGPathGenerator = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const defaultSpeed = 1, half = 0.5, minStep = 0, minIndex = 0, minWidth = 0, minScale = 1;
|
|
14
15
|
class SVGPathGenerator {
|
|
15
16
|
constructor() {
|
|
16
17
|
this._paths = [];
|
|
@@ -23,21 +24,21 @@
|
|
|
23
24
|
generate(particle, delta) {
|
|
24
25
|
const container = particle.container, pxRatio = container.retina.pixelRatio;
|
|
25
26
|
if (particle.svgDirection === undefined) {
|
|
26
|
-
particle.svgDirection = (0, engine_1.getRandom)() >
|
|
27
|
+
particle.svgDirection = (0, engine_1.getRandom)() > engine_1.halfRandom ? 0 : 1;
|
|
27
28
|
}
|
|
28
29
|
if (particle.svgPathIndex === undefined) {
|
|
29
30
|
particle.svgPathIndex = Math.floor(Math.random() * this._paths.length);
|
|
30
31
|
}
|
|
31
32
|
if (particle.svgSpeed === undefined) {
|
|
32
|
-
particle.svgSpeed = particle.velocity.mult((particle.retina.moveSpeed ??
|
|
33
|
+
particle.svgSpeed = particle.velocity.mult((particle.retina.moveSpeed ?? defaultSpeed) * half).length;
|
|
33
34
|
}
|
|
34
35
|
if (particle.svgStep === undefined) {
|
|
35
36
|
particle.svgStep = (0, engine_1.randomInRange)({ min: 0, max: this._paths[particle.svgPathIndex].length }) * pxRatio;
|
|
36
37
|
}
|
|
37
38
|
if (particle.svgOffset === undefined) {
|
|
38
39
|
particle.svgOffset = {
|
|
39
|
-
width: (0, engine_1.randomInRange)({ min: -this._width
|
|
40
|
-
height: (0, engine_1.randomInRange)({ min: -this._width
|
|
40
|
+
width: (0, engine_1.randomInRange)({ min: -this._width * half, max: this._width * half }) * pxRatio,
|
|
41
|
+
height: (0, engine_1.randomInRange)({ min: -this._width * half, max: this._width * half }) * pxRatio,
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
if (particle.svgInitialPosition === undefined) {
|
|
@@ -53,12 +54,12 @@
|
|
|
53
54
|
}
|
|
54
55
|
let path = this._paths[particle.svgPathIndex];
|
|
55
56
|
if (path) {
|
|
56
|
-
const pathLength = path.length;
|
|
57
|
+
const pathLength = path.length, indexOffset = 1;
|
|
57
58
|
if (particle.svgStep >= pathLength) {
|
|
58
|
-
particle.svgPathIndex = particle.svgPathIndex +
|
|
59
|
+
particle.svgPathIndex = particle.svgPathIndex + indexOffset;
|
|
59
60
|
if (particle.svgPathIndex >= this._paths.length) {
|
|
60
61
|
if (this._reverse) {
|
|
61
|
-
particle.svgPathIndex = this._paths.length -
|
|
62
|
+
particle.svgPathIndex = this._paths.length - indexOffset;
|
|
62
63
|
particle.svgDirection = 1;
|
|
63
64
|
}
|
|
64
65
|
else {
|
|
@@ -67,15 +68,15 @@
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
|
-
else if (particle.svgStep <=
|
|
71
|
-
particle.svgPathIndex = particle.svgPathIndex -
|
|
72
|
-
if (particle.svgPathIndex <
|
|
71
|
+
else if (particle.svgStep <= minStep) {
|
|
72
|
+
particle.svgPathIndex = particle.svgPathIndex - indexOffset;
|
|
73
|
+
if (particle.svgPathIndex < minIndex) {
|
|
73
74
|
if (this._reverse) {
|
|
74
75
|
particle.svgPathIndex = 0;
|
|
75
76
|
particle.svgDirection = 0;
|
|
76
77
|
}
|
|
77
78
|
else {
|
|
78
|
-
particle.svgPathIndex = this._paths.length -
|
|
79
|
+
particle.svgPathIndex = this._paths.length - indexOffset;
|
|
79
80
|
path = this._paths[particle.svgPathIndex];
|
|
80
81
|
particle.svgStep = path.length;
|
|
81
82
|
}
|
|
@@ -86,48 +87,46 @@
|
|
|
86
87
|
if (path) {
|
|
87
88
|
const pathElement = path.element, pos = pathElement.getPointAtLength(particle.svgStep), canvasSize = particle.container.canvas.size, offset = (0, engine_1.getPosition)(this._offset, canvasSize), scale = this._scale * pxRatio;
|
|
88
89
|
particle.position.x =
|
|
89
|
-
(pos.x - this._size.width
|
|
90
|
+
(pos.x - this._size.width * half) * scale +
|
|
90
91
|
particle.svgInitialPosition.x +
|
|
91
92
|
offset.x +
|
|
92
93
|
particle.svgOffset.width;
|
|
93
94
|
particle.position.y =
|
|
94
|
-
(pos.y - this._size.height
|
|
95
|
+
(pos.y - this._size.height * half) * scale +
|
|
95
96
|
particle.svgInitialPosition.y +
|
|
96
97
|
offset.y +
|
|
97
98
|
particle.svgOffset.height;
|
|
98
99
|
}
|
|
99
|
-
return engine_1.Vector.origin;
|
|
100
|
+
return Promise.resolve(engine_1.Vector.origin);
|
|
100
101
|
}
|
|
101
|
-
init(container) {
|
|
102
|
+
async init(container) {
|
|
102
103
|
const options = container.actualOptions.particles.move.path.options, position = options.position ?? this._offset;
|
|
103
104
|
this._reverse = options.reverse ?? this._reverse;
|
|
104
|
-
this._scale = options.scale ??
|
|
105
|
+
this._scale = options.scale ?? minScale;
|
|
105
106
|
this._offset.x = position.x;
|
|
106
107
|
this._offset.y = position.y;
|
|
107
108
|
this._offset.mode = position.mode;
|
|
108
|
-
this._width = options.width ??
|
|
109
|
+
this._width = options.width ?? minWidth;
|
|
109
110
|
if (options.url && !options.path) {
|
|
110
111
|
const url = options.url;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
});
|
|
126
|
-
}
|
|
112
|
+
const response = await fetch(url), data = await response.text();
|
|
113
|
+
const parser = new DOMParser(), doc = parser.parseFromString(data, "image/svg+xml"), firstIndex = 0, svg = doc.getElementsByTagName("svg")[firstIndex];
|
|
114
|
+
let svgPaths = svg.getElementsByTagName("path");
|
|
115
|
+
if (!svgPaths.length) {
|
|
116
|
+
svgPaths = doc.getElementsByTagName("path");
|
|
117
|
+
}
|
|
118
|
+
this._paths = [];
|
|
119
|
+
for (let i = 0; i < svgPaths.length; i++) {
|
|
120
|
+
const path = svgPaths.item(i);
|
|
121
|
+
if (path) {
|
|
122
|
+
this._paths.push({
|
|
123
|
+
element: path,
|
|
124
|
+
length: path.getTotalLength(),
|
|
125
|
+
});
|
|
127
126
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
}
|
|
128
|
+
this._size.height = parseFloat(svg.getAttribute("height") ?? "0");
|
|
129
|
+
this._size.width = parseFloat(svg.getAttribute("width") ?? "0");
|
|
131
130
|
}
|
|
132
131
|
else if (options.path) {
|
|
133
132
|
const path = options.path;
|
package/umd/index.js
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"
|
|
30
|
+
define(["require", "exports"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.loadSVGPath = exports.svgPathName = void 0;
|
|
13
|
-
const SVGPathGenerator_js_1 = require("./SVGPathGenerator.js");
|
|
14
37
|
exports.svgPathName = "svgPathGenerator";
|
|
15
38
|
async function loadSVGPath(engine, refresh = true) {
|
|
16
|
-
await
|
|
39
|
+
const { SVGPathGenerator } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./SVGPathGenerator.js"))) : new Promise((resolve_1, reject_1) => { require(["./SVGPathGenerator.js"], resolve_1, reject_1); }).then(__importStar));
|
|
40
|
+
await engine.addPathGenerator(exports.svgPathName, new SVGPathGenerator(), refresh);
|
|
17
41
|
}
|
|
18
42
|
exports.loadSVGPath = loadSVGPath;
|
|
19
43
|
});
|