@tsparticles/shape-rounded-rect 3.0.0-alpha.1 → 3.0.0-beta.1
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/RoundedRectDrawer.js +21 -19
- package/browser/index.js +3 -3
- package/browser/package.json +1 -0
- package/cjs/RoundedRectDrawer.js +21 -19
- package/cjs/index.js +3 -3
- package/cjs/package.json +1 -0
- package/esm/RoundedRectDrawer.js +21 -19
- package/esm/index.js +3 -3
- package/esm/package.json +1 -0
- package/package.json +23 -6
- package/report.html +4 -4
- package/tsparticles.shape.rounded-rect.js +93 -49
- package/tsparticles.shape.rounded-rect.min.js +1 -1
- package/tsparticles.shape.rounded-rect.min.js.LICENSE.txt +1 -8
- package/types/IRoundedRectData.d.ts +2 -2
- package/types/RoundedParticle.d.ts +4 -0
- package/types/RoundedRectDrawer.d.ts +4 -3
- package/types/index.d.ts +1 -1
- package/umd/RoundedRectDrawer.js +22 -20
- package/umd/index.js +4 -4
- package/types/IRoundedParticle.d.ts +0 -4
- /package/browser/{IRoundedParticle.js → RoundedParticle.js} +0 -0
- /package/cjs/{IRoundedParticle.js → RoundedParticle.js} +0 -0
- /package/esm/{IRoundedParticle.js → RoundedParticle.js} +0 -0
- /package/umd/{IRoundedParticle.js → RoundedParticle.js} +0 -0
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
# tsParticles Rounded Rectangle Shape
|
|
4
4
|
|
|
5
|
-
[](https://www.jsdelivr.com/package/npm/@tsparticles/shape-rounded-rect)
|
|
6
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-rounded-rect)
|
|
7
|
+
[](https://www.npmjs.com/package/@tsparticles/shape-rounded-rect) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
9
|
[tsParticles](https://github.com/matteobruni/tsparticles) additional rounded rectangle 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 loadRoundedRectShape();
|
|
29
|
+
await loadRoundedRectShape(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-rounded-rect
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
or
|
|
50
50
|
|
|
51
51
|
```shell
|
|
52
|
-
$ yarn add tsparticles
|
|
52
|
+
$ yarn add @tsparticles/shape-rounded-rect
|
|
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 { loadRoundedRectShape } = require("tsparticles
|
|
58
|
+
const { tsParticles } = require("@tsparticles/engine");
|
|
59
|
+
const { loadRoundedRectShape } = require("@tsparticles/shape-rounded-rect");
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
(async () => {
|
|
62
|
+
await loadRoundedRectShape(tsParticles);
|
|
63
|
+
})();
|
|
62
64
|
```
|
|
63
65
|
|
|
64
66
|
or
|
|
65
67
|
|
|
66
68
|
```javascript
|
|
67
|
-
import { tsParticles } from "tsparticles
|
|
68
|
-
import { loadRoundedRectShape } from "tsparticles
|
|
69
|
+
import { tsParticles } from "@tsparticles/engine";
|
|
70
|
+
import { loadRoundedRectShape } from "@tsparticles/shape-rounded-rect";
|
|
69
71
|
|
|
70
|
-
|
|
72
|
+
(async () => {
|
|
73
|
+
await loadRoundedRectShape(tsParticles);
|
|
74
|
+
})();
|
|
71
75
|
```
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { getRangeValue } from "@tsparticles/engine";
|
|
2
|
+
const fixFactor = Math.sqrt(2), drawRoundedRect = (ctx, info, radius = {
|
|
2
3
|
topRight: 4,
|
|
3
4
|
bottomRight: 4,
|
|
4
5
|
bottomLeft: 4,
|
|
5
6
|
topLeft: 4,
|
|
6
7
|
}) => {
|
|
7
|
-
const { x, y, width, height } = info;
|
|
8
|
-
const r = x + width;
|
|
9
|
-
const b = y + height;
|
|
8
|
+
const { x, y, width, height } = info, r = x + width, b = y + height;
|
|
10
9
|
ctx.moveTo(x + radius.topLeft, y);
|
|
11
10
|
ctx.lineTo(r - radius.topRight, y);
|
|
12
11
|
ctx.quadraticCurveTo(r, y, r, y + radius.topRight);
|
|
@@ -19,23 +18,26 @@ const drawRoundedRect = (ctx, info, radius = {
|
|
|
19
18
|
};
|
|
20
19
|
export class RoundedRectDrawer {
|
|
21
20
|
draw(context, particle, radius) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
const fixedRadius = radius / fixFactor, fixedDiameter = fixedRadius * 2, borderRadius = particle.borderRadius ?? 5;
|
|
22
|
+
if ("roundRect" in context) {
|
|
23
|
+
context.roundRect(-fixedRadius, -fixedRadius, fixedDiameter, fixedDiameter, borderRadius);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
drawRoundedRect(context, {
|
|
27
|
+
x: -fixedRadius,
|
|
28
|
+
y: -fixedRadius,
|
|
29
|
+
height: fixedDiameter,
|
|
30
|
+
width: fixedDiameter,
|
|
31
|
+
}, {
|
|
32
|
+
topLeft: borderRadius,
|
|
33
|
+
topRight: borderRadius,
|
|
34
|
+
bottomLeft: borderRadius,
|
|
35
|
+
bottomRight: borderRadius,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
particleInit(container, particle) {
|
|
36
|
-
var _a;
|
|
37
40
|
const shapeData = particle.shapeData;
|
|
38
|
-
|
|
39
|
-
roundedRect.borderRadius = ((_a = shapeData === null || shapeData === void 0 ? void 0 : shapeData.radius) !== null && _a !== void 0 ? _a : 4) * container.retina.pixelRatio;
|
|
41
|
+
particle.borderRadius = getRangeValue(shapeData?.radius ?? 5) * container.retina.pixelRatio;
|
|
40
42
|
}
|
|
41
43
|
}
|
package/browser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RoundedRectDrawer } from "./RoundedRectDrawer";
|
|
2
|
-
export function loadRoundedRectShape(engine) {
|
|
3
|
-
engine.addShape("rounded-rect", new RoundedRectDrawer());
|
|
1
|
+
import { RoundedRectDrawer } from "./RoundedRectDrawer.js";
|
|
2
|
+
export async function loadRoundedRectShape(engine, refresh = true) {
|
|
3
|
+
await engine.addShape("rounded-rect", new RoundedRectDrawer(), refresh);
|
|
4
4
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/cjs/RoundedRectDrawer.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RoundedRectDrawer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const engine_1 = require("@tsparticles/engine");
|
|
5
|
+
const fixFactor = Math.sqrt(2), drawRoundedRect = (ctx, info, radius = {
|
|
5
6
|
topRight: 4,
|
|
6
7
|
bottomRight: 4,
|
|
7
8
|
bottomLeft: 4,
|
|
8
9
|
topLeft: 4,
|
|
9
10
|
}) => {
|
|
10
|
-
const { x, y, width, height } = info;
|
|
11
|
-
const r = x + width;
|
|
12
|
-
const b = y + height;
|
|
11
|
+
const { x, y, width, height } = info, r = x + width, b = y + height;
|
|
13
12
|
ctx.moveTo(x + radius.topLeft, y);
|
|
14
13
|
ctx.lineTo(r - radius.topRight, y);
|
|
15
14
|
ctx.quadraticCurveTo(r, y, r, y + radius.topRight);
|
|
@@ -22,24 +21,27 @@ const drawRoundedRect = (ctx, info, radius = {
|
|
|
22
21
|
};
|
|
23
22
|
class RoundedRectDrawer {
|
|
24
23
|
draw(context, particle, radius) {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
const fixedRadius = radius / fixFactor, fixedDiameter = fixedRadius * 2, borderRadius = particle.borderRadius ?? 5;
|
|
25
|
+
if ("roundRect" in context) {
|
|
26
|
+
context.roundRect(-fixedRadius, -fixedRadius, fixedDiameter, fixedDiameter, borderRadius);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
drawRoundedRect(context, {
|
|
30
|
+
x: -fixedRadius,
|
|
31
|
+
y: -fixedRadius,
|
|
32
|
+
height: fixedDiameter,
|
|
33
|
+
width: fixedDiameter,
|
|
34
|
+
}, {
|
|
35
|
+
topLeft: borderRadius,
|
|
36
|
+
topRight: borderRadius,
|
|
37
|
+
bottomLeft: borderRadius,
|
|
38
|
+
bottomRight: borderRadius,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
37
41
|
}
|
|
38
42
|
particleInit(container, particle) {
|
|
39
|
-
var _a;
|
|
40
43
|
const shapeData = particle.shapeData;
|
|
41
|
-
|
|
42
|
-
roundedRect.borderRadius = ((_a = shapeData === null || shapeData === void 0 ? void 0 : shapeData.radius) !== null && _a !== void 0 ? _a : 4) * container.retina.pixelRatio;
|
|
44
|
+
particle.borderRadius = (0, engine_1.getRangeValue)(shapeData?.radius ?? 5) * container.retina.pixelRatio;
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
exports.RoundedRectDrawer = RoundedRectDrawer;
|
package/cjs/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadRoundedRectShape = void 0;
|
|
4
|
-
const
|
|
5
|
-
function loadRoundedRectShape(engine) {
|
|
6
|
-
engine.addShape("rounded-rect", new
|
|
4
|
+
const RoundedRectDrawer_js_1 = require("./RoundedRectDrawer.js");
|
|
5
|
+
async function loadRoundedRectShape(engine, refresh = true) {
|
|
6
|
+
await engine.addShape("rounded-rect", new RoundedRectDrawer_js_1.RoundedRectDrawer(), refresh);
|
|
7
7
|
}
|
|
8
8
|
exports.loadRoundedRectShape = loadRoundedRectShape;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
package/esm/RoundedRectDrawer.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { getRangeValue } from "@tsparticles/engine";
|
|
2
|
+
const fixFactor = Math.sqrt(2), drawRoundedRect = (ctx, info, radius = {
|
|
2
3
|
topRight: 4,
|
|
3
4
|
bottomRight: 4,
|
|
4
5
|
bottomLeft: 4,
|
|
5
6
|
topLeft: 4,
|
|
6
7
|
}) => {
|
|
7
|
-
const { x, y, width, height } = info;
|
|
8
|
-
const r = x + width;
|
|
9
|
-
const b = y + height;
|
|
8
|
+
const { x, y, width, height } = info, r = x + width, b = y + height;
|
|
10
9
|
ctx.moveTo(x + radius.topLeft, y);
|
|
11
10
|
ctx.lineTo(r - radius.topRight, y);
|
|
12
11
|
ctx.quadraticCurveTo(r, y, r, y + radius.topRight);
|
|
@@ -19,23 +18,26 @@ const drawRoundedRect = (ctx, info, radius = {
|
|
|
19
18
|
};
|
|
20
19
|
export class RoundedRectDrawer {
|
|
21
20
|
draw(context, particle, radius) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
const fixedRadius = radius / fixFactor, fixedDiameter = fixedRadius * 2, borderRadius = particle.borderRadius ?? 5;
|
|
22
|
+
if ("roundRect" in context) {
|
|
23
|
+
context.roundRect(-fixedRadius, -fixedRadius, fixedDiameter, fixedDiameter, borderRadius);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
drawRoundedRect(context, {
|
|
27
|
+
x: -fixedRadius,
|
|
28
|
+
y: -fixedRadius,
|
|
29
|
+
height: fixedDiameter,
|
|
30
|
+
width: fixedDiameter,
|
|
31
|
+
}, {
|
|
32
|
+
topLeft: borderRadius,
|
|
33
|
+
topRight: borderRadius,
|
|
34
|
+
bottomLeft: borderRadius,
|
|
35
|
+
bottomRight: borderRadius,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
particleInit(container, particle) {
|
|
36
|
-
var _a;
|
|
37
40
|
const shapeData = particle.shapeData;
|
|
38
|
-
|
|
39
|
-
roundedRect.borderRadius = ((_a = shapeData === null || shapeData === void 0 ? void 0 : shapeData.radius) !== null && _a !== void 0 ? _a : 4) * container.retina.pixelRatio;
|
|
41
|
+
particle.borderRadius = getRangeValue(shapeData?.radius ?? 5) * container.retina.pixelRatio;
|
|
40
42
|
}
|
|
41
43
|
}
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RoundedRectDrawer } from "./RoundedRectDrawer";
|
|
2
|
-
export function loadRoundedRectShape(engine) {
|
|
3
|
-
engine.addShape("rounded-rect", new RoundedRectDrawer());
|
|
1
|
+
import { RoundedRectDrawer } from "./RoundedRectDrawer.js";
|
|
2
|
+
export async function loadRoundedRectShape(engine, refresh = true) {
|
|
3
|
+
await engine.addShape("rounded-rect", new RoundedRectDrawer(), refresh);
|
|
4
4
|
}
|
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "module" }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/shape-rounded-rect",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
4
|
"description": "tsParticles rounded rect shape",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
@@ -72,20 +72,37 @@
|
|
|
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"
|
|
78
82
|
}
|
|
79
83
|
],
|
|
80
|
-
"
|
|
84
|
+
"sideEffects": false,
|
|
81
85
|
"jsdelivr": "tsparticles.shape.rounded-rect.min.js",
|
|
82
86
|
"unpkg": "tsparticles.shape.rounded-rect.min.js",
|
|
87
|
+
"browser": "browser/index.js",
|
|
88
|
+
"main": "cjs/index.js",
|
|
83
89
|
"module": "esm/index.js",
|
|
84
90
|
"types": "types/index.d.ts",
|
|
85
|
-
"
|
|
86
|
-
"
|
|
91
|
+
"exports": {
|
|
92
|
+
".": {
|
|
93
|
+
"types": "./types/index.d.ts",
|
|
94
|
+
"browser": "./browser/index.js",
|
|
95
|
+
"import": "./esm/index.js",
|
|
96
|
+
"require": "./cjs/index.js",
|
|
97
|
+
"umd": "./umd/index.js",
|
|
98
|
+
"default": "./cjs/index.js"
|
|
99
|
+
},
|
|
100
|
+
"./package.json": "./package.json"
|
|
87
101
|
},
|
|
88
102
|
"dependencies": {
|
|
89
|
-
"@tsparticles/engine": "^3.0.0-
|
|
103
|
+
"@tsparticles/engine": "^3.0.0-beta.1"
|
|
104
|
+
},
|
|
105
|
+
"publishConfig": {
|
|
106
|
+
"access": "public"
|
|
90
107
|
}
|
|
91
|
-
}
|
|
108
|
+
}
|