@tsparticles/shape-spiral 3.0.0-alpha.0 → 3.0.0-beta.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/README.md +16 -12
- package/browser/SpiralDrawer.js +17 -8
- package/browser/index.js +2 -2
- package/cjs/SpiralDrawer.js +17 -8
- package/cjs/index.js +2 -2
- package/esm/SpiralDrawer.js +17 -8
- package/esm/index.js +2 -2
- package/package.json +10 -5
- package/report.html +4 -4
- package/tsparticles.shape.spiral.js +66 -23
- package/tsparticles.shape.spiral.min.js +1 -1
- package/tsparticles.shape.spiral.min.js.LICENSE.txt +1 -8
- package/types/ISpiralData.d.ts +4 -3
- package/types/SpiralDrawer.d.ts +4 -3
- package/types/SpiralParticle.d.ts +6 -0
- package/types/index.d.ts +1 -1
- package/umd/SpiralDrawer.js +18 -9
- package/umd/index.js +2 -2
- package/types/ISpiralParticle.d.ts +0 -5
- /package/browser/{ISpiralParticle.js → SpiralParticle.js} +0 -0
- /package/cjs/{ISpiralParticle.js → SpiralParticle.js} +0 -0
- /package/esm/{ISpiralParticle.js → SpiralParticle.js} +0 -0
- /package/umd/{ISpiralParticle.js → SpiralParticle.js} +0 -0
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Spiral Shape
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/shape-spiral)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-spiral)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-spiral) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) additional spiral shape.
|
|
10
10
|
|
|
@@ -26,7 +26,7 @@ Once the scripts are loaded you can set up `tsParticles` and the shape like this
|
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
(async () => {
|
|
29
|
-
await loadSpiralShape();
|
|
29
|
+
await loadSpiralShape(tsParticles);
|
|
30
30
|
|
|
31
31
|
await tsParticles.load({
|
|
32
32
|
id: "tsparticles",
|
|
@@ -43,29 +43,33 @@ Once the scripts are loaded you can set up `tsParticles` and the shape like this
|
|
|
43
43
|
This package is compatible also with ES or CommonJS modules, firstly this needs to be installed, like this:
|
|
44
44
|
|
|
45
45
|
```shell
|
|
46
|
-
$ npm install tsparticles
|
|
46
|
+
$ npm install @tsparticles/shape-spiral
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
or
|
|
50
50
|
|
|
51
51
|
```shell
|
|
52
|
-
$ yarn add tsparticles
|
|
52
|
+
$ yarn add @tsparticles/shape-spiral
|
|
53
53
|
```
|
|
54
54
|
|
|
55
55
|
Then you need to import it in the app, like this:
|
|
56
56
|
|
|
57
57
|
```javascript
|
|
58
|
-
const { tsParticles } = require("tsparticles
|
|
59
|
-
const { loadSpiralShape } = require("tsparticles
|
|
58
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
59
|
+
const { loadSpiralShape } = require("@tsparticles/shape-spiral");
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
(async () => {
|
|
62
|
+
await loadSpiralShape(tsParticles);
|
|
63
|
+
})();
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
or
|
|
65
67
|
|
|
66
68
|
```javascript
|
|
67
|
-
import { tsParticles } from "tsparticles
|
|
68
|
-
import { loadSpiralShape } from "tsparticles
|
|
69
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
70
|
+
import { loadSpiralShape } from "@tsparticles/shape-spiral";
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
(async () => {
|
|
73
|
+
await loadSpiralShape(tsParticles);
|
|
74
|
+
})();
|
|
71
75
|
```
|
package/browser/SpiralDrawer.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
import { getRangeValue } from "@tsparticles/engine";
|
|
1
2
|
export class SpiralDrawer {
|
|
2
3
|
draw(context, particle, radius) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (particle.spiralInnerRadius === undefined ||
|
|
5
|
+
particle.spiralLineSpacing === undefined ||
|
|
6
|
+
particle.spiralWidthFactor === undefined) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const realWidth = (radius - particle.spiralInnerRadius) / particle.spiralLineSpacing, widthFactor = 10;
|
|
10
|
+
for (let i = 0; i < realWidth * widthFactor; i++) {
|
|
11
|
+
const angle = i / widthFactor, factor = particle.spiralInnerRadius + particle.spiralLineSpacing * angle, pos = {
|
|
12
|
+
x: factor * Math.cos(angle),
|
|
13
|
+
y: factor * Math.sin(angle),
|
|
14
|
+
};
|
|
15
|
+
context.lineTo(pos.x, pos.y);
|
|
7
16
|
}
|
|
8
17
|
}
|
|
9
18
|
particleInit(container, particle) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData;
|
|
20
|
+
particle.spiralInnerRadius = getRangeValue(shapeData.innerRadius ?? 1) * pixelRatio;
|
|
21
|
+
particle.spiralLineSpacing = getRangeValue(shapeData.lineSpacing ?? 1) * pixelRatio;
|
|
22
|
+
particle.spiralWidthFactor = getRangeValue(shapeData.widthFactor ?? 10);
|
|
14
23
|
}
|
|
15
24
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SpiralDrawer } from "./SpiralDrawer";
|
|
2
|
-
export function loadSpiralShape(engine) {
|
|
3
|
-
engine.addShape("spiral", new SpiralDrawer());
|
|
2
|
+
export async function loadSpiralShape(engine, refresh = true) {
|
|
3
|
+
await engine.addShape("spiral", new SpiralDrawer(), refresh);
|
|
4
4
|
}
|
package/cjs/SpiralDrawer.js
CHANGED
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SpiralDrawer = void 0;
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
4
5
|
class SpiralDrawer {
|
|
5
6
|
draw(context, particle, radius) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
if (particle.spiralInnerRadius === undefined ||
|
|
8
|
+
particle.spiralLineSpacing === undefined ||
|
|
9
|
+
particle.spiralWidthFactor === undefined) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const realWidth = (radius - particle.spiralInnerRadius) / particle.spiralLineSpacing, widthFactor = 10;
|
|
13
|
+
for (let i = 0; i < realWidth * widthFactor; i++) {
|
|
14
|
+
const angle = i / widthFactor, factor = particle.spiralInnerRadius + particle.spiralLineSpacing * angle, pos = {
|
|
15
|
+
x: factor * Math.cos(angle),
|
|
16
|
+
y: factor * Math.sin(angle),
|
|
17
|
+
};
|
|
18
|
+
context.lineTo(pos.x, pos.y);
|
|
10
19
|
}
|
|
11
20
|
}
|
|
12
21
|
particleInit(container, particle) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
22
|
+
const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData;
|
|
23
|
+
particle.spiralInnerRadius = (0, engine_1.getRangeValue)(shapeData.innerRadius ?? 1) * pixelRatio;
|
|
24
|
+
particle.spiralLineSpacing = (0, engine_1.getRangeValue)(shapeData.lineSpacing ?? 1) * pixelRatio;
|
|
25
|
+
particle.spiralWidthFactor = (0, engine_1.getRangeValue)(shapeData.widthFactor ?? 10);
|
|
17
26
|
}
|
|
18
27
|
}
|
|
19
28
|
exports.SpiralDrawer = SpiralDrawer;
|
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadSpiralShape = void 0;
|
|
4
4
|
const SpiralDrawer_1 = require("./SpiralDrawer");
|
|
5
|
-
function loadSpiralShape(engine) {
|
|
6
|
-
engine.addShape("spiral", new SpiralDrawer_1.SpiralDrawer());
|
|
5
|
+
async function loadSpiralShape(engine, refresh = true) {
|
|
6
|
+
await engine.addShape("spiral", new SpiralDrawer_1.SpiralDrawer(), refresh);
|
|
7
7
|
}
|
|
8
8
|
exports.loadSpiralShape = loadSpiralShape;
|
package/esm/SpiralDrawer.js
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
|
+
import { getRangeValue } from "@tsparticles/engine";
|
|
1
2
|
export class SpiralDrawer {
|
|
2
3
|
draw(context, particle, radius) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (particle.spiralInnerRadius === undefined ||
|
|
5
|
+
particle.spiralLineSpacing === undefined ||
|
|
6
|
+
particle.spiralWidthFactor === undefined) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const realWidth = (radius - particle.spiralInnerRadius) / particle.spiralLineSpacing, widthFactor = 10;
|
|
10
|
+
for (let i = 0; i < realWidth * widthFactor; i++) {
|
|
11
|
+
const angle = i / widthFactor, factor = particle.spiralInnerRadius + particle.spiralLineSpacing * angle, pos = {
|
|
12
|
+
x: factor * Math.cos(angle),
|
|
13
|
+
y: factor * Math.sin(angle),
|
|
14
|
+
};
|
|
15
|
+
context.lineTo(pos.x, pos.y);
|
|
7
16
|
}
|
|
8
17
|
}
|
|
9
18
|
particleInit(container, particle) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
19
|
+
const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData;
|
|
20
|
+
particle.spiralInnerRadius = getRangeValue(shapeData.innerRadius ?? 1) * pixelRatio;
|
|
21
|
+
particle.spiralLineSpacing = getRangeValue(shapeData.lineSpacing ?? 1) * pixelRatio;
|
|
22
|
+
particle.spiralWidthFactor = getRangeValue(shapeData.widthFactor ?? 10);
|
|
14
23
|
}
|
|
15
24
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { SpiralDrawer } from "./SpiralDrawer";
|
|
2
|
-
export function loadSpiralShape(engine) {
|
|
3
|
-
engine.addShape("spiral", new SpiralDrawer());
|
|
2
|
+
export async function loadSpiralShape(engine, refresh = true) {
|
|
3
|
+
await engine.addShape("spiral", new SpiralDrawer(), refresh);
|
|
4
4
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-spiral",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.0",
|
|
4
4
|
"description": "tsParticles spiral shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -72,6 +72,10 @@
|
|
|
72
72
|
"type": "github",
|
|
73
73
|
"url": "https://github.com/sponsors/matteobruni"
|
|
74
74
|
},
|
|
75
|
+
{
|
|
76
|
+
"type": "github",
|
|
77
|
+
"url": "https://github.com/sponsors/tsparticles"
|
|
78
|
+
},
|
|
75
79
|
{
|
|
76
80
|
"type": "buymeacoffee",
|
|
77
81
|
"url": "https://www.buymeacoffee.com/matteobruni"
|
|
@@ -82,10 +86,11 @@
|
|
|
82
86
|
"unpkg": "tsparticles.shape.spiral.min.js",
|
|
83
87
|
"module": "esm/index.js",
|
|
84
88
|
"types": "types/index.d.ts",
|
|
89
|
+
"sideEffects": false,
|
|
90
|
+
"dependencies": {
|
|
91
|
+
"@tsparticles/engine": "^3.0.0-beta.0"
|
|
92
|
+
},
|
|
85
93
|
"publishConfig": {
|
|
86
94
|
"access": "public"
|
|
87
|
-
},
|
|
88
|
-
"dependencies": {
|
|
89
|
-
"@tsparticles/engine": "^3.0.0-alpha.0"
|
|
90
95
|
}
|
|
91
|
-
}
|
|
96
|
+
}
|