@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 CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  # tsParticles Spiral Shape
4
4
 
5
- [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/tsparticles-shape-spiral/badge)](https://www.jsdelivr.com/package/npm/tsparticles-shape-spiral)
6
- [![npmjs](https://badge.fury.io/js/tsparticles-shape-spiral.svg)](https://www.npmjs.com/package/tsparticles-shape-spiral)
7
- [![npmjs](https://img.shields.io/npm/dt/tsparticles-shape-spiral)](https://www.npmjs.com/package/tsparticles-shape-spiral) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
5
+ [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/shape-spiral/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/shape-spiral)
6
+ [![npmjs](https://badge.fury.io/js/@tsparticles/shape-spiral.svg)](https://www.npmjs.com/package/@tsparticles/shape-spiral)
7
+ [![npmjs](https://img.shields.io/npm/dt/@tsparticles/shape-spiral)](https://www.npmjs.com/package/@tsparticles/shape-spiral) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](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-shape-spiral
46
+ $ npm install @tsparticles/shape-spiral
47
47
  ```
48
48
 
49
49
  or
50
50
 
51
51
  ```shell
52
- $ yarn add tsparticles-shape-spiral
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-engine");
59
- const { loadSpiralShape } = require("tsparticles-shape-spiral");
58
+ const { tsParticles } = require("@tsparticles/engine");
59
+ const { loadSpiralShape } = require("@tsparticles/shape-spiral");
60
60
 
61
- loadSpiralShape(tsParticles);
61
+ (async () => {
62
+ await loadSpiralShape(tsParticles);
63
+ })();
62
64
  ```
63
65
 
64
66
  or
65
67
 
66
68
  ```javascript
67
- import { tsParticles } from "tsparticles-engine";
68
- import { loadSpiralShape } from "tsparticles-shape-spiral";
69
+ import { tsParticles } from "@tsparticles/engine";
70
+ import { loadSpiralShape } from "@tsparticles/shape-spiral";
69
71
 
70
- loadSpiralShape(tsParticles);
72
+ (async () => {
73
+ await loadSpiralShape(tsParticles);
74
+ })();
71
75
  ```
@@ -1,15 +1,24 @@
1
+ import { getRangeValue } from "@tsparticles/engine";
1
2
  export class SpiralDrawer {
2
3
  draw(context, particle, radius) {
3
- const spiral = particle, realWidth = (radius - spiral.spiralInnerRadius) / spiral.spiralLineSpacing;
4
- for (let i = 0; i < realWidth * 10; i++) {
5
- const angle = 0.1 * i, positionFactor = spiral.spiralInnerRadius + spiral.spiralLineSpacing * angle, x = positionFactor * Math.cos(angle), y = positionFactor * Math.sin(angle);
6
- context.lineTo(x, y);
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
- var _a, _b;
11
- const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData, spiral = particle;
12
- spiral.spiralInnerRadius = ((_a = shapeData.innerRadius) !== null && _a !== void 0 ? _a : 1) * pixelRatio;
13
- spiral.spiralLineSpacing = ((_b = shapeData.lineSpacing) !== null && _b !== void 0 ? _b : 1) * pixelRatio;
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
  }
@@ -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
- const spiral = particle, realWidth = (radius - spiral.spiralInnerRadius) / spiral.spiralLineSpacing;
7
- for (let i = 0; i < realWidth * 10; i++) {
8
- const angle = 0.1 * i, positionFactor = spiral.spiralInnerRadius + spiral.spiralLineSpacing * angle, x = positionFactor * Math.cos(angle), y = positionFactor * Math.sin(angle);
9
- context.lineTo(x, y);
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
- var _a, _b;
14
- const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData, spiral = particle;
15
- spiral.spiralInnerRadius = ((_a = shapeData.innerRadius) !== null && _a !== void 0 ? _a : 1) * pixelRatio;
16
- spiral.spiralLineSpacing = ((_b = shapeData.lineSpacing) !== null && _b !== void 0 ? _b : 1) * pixelRatio;
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;
@@ -1,15 +1,24 @@
1
+ import { getRangeValue } from "@tsparticles/engine";
1
2
  export class SpiralDrawer {
2
3
  draw(context, particle, radius) {
3
- const spiral = particle, realWidth = (radius - spiral.spiralInnerRadius) / spiral.spiralLineSpacing;
4
- for (let i = 0; i < realWidth * 10; i++) {
5
- const angle = 0.1 * i, positionFactor = spiral.spiralInnerRadius + spiral.spiralLineSpacing * angle, x = positionFactor * Math.cos(angle), y = positionFactor * Math.sin(angle);
6
- context.lineTo(x, y);
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
- var _a, _b;
11
- const pixelRatio = container.retina.pixelRatio, shapeData = particle.shapeData, spiral = particle;
12
- spiral.spiralInnerRadius = ((_a = shapeData.innerRadius) !== null && _a !== void 0 ? _a : 1) * pixelRatio;
13
- spiral.spiralLineSpacing = ((_b = shapeData.lineSpacing) !== null && _b !== void 0 ? _b : 1) * pixelRatio;
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-alpha.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
+ }