@tsparticles/canvas-utils 4.0.0-alpha.8 → 4.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 +4 -4
- package/browser/Utils.js +15 -9
- package/cjs/Utils.js +15 -9
- package/esm/Utils.js +15 -9
- package/package.json +5 -5
- package/report.html +84 -29
- package/tsparticles.canvas.utils.js +132 -0
- package/tsparticles.canvas.utils.min.js +1 -0
- package/types/Utils.d.ts +3 -2
- package/umd/Utils.js +15 -8
- package/tsparticles.path.utils.js +0 -132
- package/tsparticles.path.utils.min.js +0 -2
- package/tsparticles.path.utils.min.js.LICENSE.txt +0 -1
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[](https://particles.js.org)
|
|
2
2
|
|
|
3
|
-
# tsParticles
|
|
3
|
+
# tsParticles Canvas Utils Library
|
|
4
4
|
|
|
5
5
|
[](https://www.jsdelivr.com/package/npm/@tsparticles/canvas-utils)
|
|
6
6
|
[](https://www.npmjs.com/package/@tsparticles/canvas-utils)
|
|
7
7
|
[](https://www.npmjs.com/package/@tsparticles/canvas-utils) [](https://github.com/sponsors/matteobruni)
|
|
8
8
|
|
|
9
|
-
[tsParticles](https://github.com/tsparticles/tsparticles)
|
|
9
|
+
[tsParticles](https://github.com/tsparticles/tsparticles) canvas utils.
|
|
10
10
|
|
|
11
11
|
## How to use it
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
The CDN/Vanilla version JS has one required file in vanilla configuration:
|
|
16
16
|
|
|
17
|
-
Including the `tsparticles.
|
|
17
|
+
Including the `tsparticles.canvas.utils.min.js` file will export the function to load the canvas utils:
|
|
18
18
|
|
|
19
19
|
```text
|
|
20
20
|
loadCanvasUtilsPath
|
|
@@ -22,7 +22,7 @@ loadCanvasUtilsPath
|
|
|
22
22
|
|
|
23
23
|
### Usage
|
|
24
24
|
|
|
25
|
-
Once the scripts are loaded you can set up `tsParticles` and the
|
|
25
|
+
Once the scripts are loaded you can set up `tsParticles` and the canvas utils like this:
|
|
26
26
|
|
|
27
27
|
```javascript
|
|
28
28
|
(async () => {
|
package/browser/Utils.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { defaultAlpha, defaultRgbMin, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
-
const defaultWidth = 0
|
|
1
|
+
import { defaultAlpha, defaultRgbMin, identity, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
const defaultWidth = 0, indexesOffset = {
|
|
3
|
+
r: 0,
|
|
4
|
+
g: 1,
|
|
5
|
+
b: 2,
|
|
6
|
+
a: 3,
|
|
7
|
+
}, alphaMax = 255, alphaFactor = identity / alphaMax;
|
|
8
|
+
export function drawLine(context, begin, end) {
|
|
9
|
+
context.beginPath();
|
|
10
|
+
context.moveTo(begin.x, begin.y);
|
|
11
|
+
context.lineTo(end.x, end.y);
|
|
12
|
+
context.closePath();
|
|
13
|
+
}
|
|
3
14
|
export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
4
15
|
const imageData = ctx.getImageData(originPoint.x, originPoint.y, size.width, size.height).data;
|
|
5
16
|
if (clear) {
|
|
@@ -12,12 +23,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
12
23
|
y: Math.floor(idx / size.width),
|
|
13
24
|
};
|
|
14
25
|
pixels[pos.y] ??= [];
|
|
15
|
-
const
|
|
16
|
-
r: 0,
|
|
17
|
-
g: 1,
|
|
18
|
-
b: 2,
|
|
19
|
-
a: 3,
|
|
20
|
-
}, alphaFactor = 255, row = pixels[pos.y];
|
|
26
|
+
const row = pixels[pos.y];
|
|
21
27
|
if (!row) {
|
|
22
28
|
continue;
|
|
23
29
|
}
|
|
@@ -25,7 +31,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
25
31
|
r: imageData[i + indexesOffset.r] ?? defaultRgbMin,
|
|
26
32
|
g: imageData[i + indexesOffset.g] ?? defaultRgbMin,
|
|
27
33
|
b: imageData[i + indexesOffset.b] ?? defaultRgbMin,
|
|
28
|
-
a: (imageData[i + indexesOffset.a] ?? defaultAlpha)
|
|
34
|
+
a: (imageData[i + indexesOffset.a] ?? defaultAlpha) * alphaFactor,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
return {
|
package/cjs/Utils.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { defaultAlpha, defaultRgbMin, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
-
const defaultWidth = 0
|
|
1
|
+
import { defaultAlpha, defaultRgbMin, identity, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
const defaultWidth = 0, indexesOffset = {
|
|
3
|
+
r: 0,
|
|
4
|
+
g: 1,
|
|
5
|
+
b: 2,
|
|
6
|
+
a: 3,
|
|
7
|
+
}, alphaMax = 255, alphaFactor = identity / alphaMax;
|
|
8
|
+
export function drawLine(context, begin, end) {
|
|
9
|
+
context.beginPath();
|
|
10
|
+
context.moveTo(begin.x, begin.y);
|
|
11
|
+
context.lineTo(end.x, end.y);
|
|
12
|
+
context.closePath();
|
|
13
|
+
}
|
|
3
14
|
export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
4
15
|
const imageData = ctx.getImageData(originPoint.x, originPoint.y, size.width, size.height).data;
|
|
5
16
|
if (clear) {
|
|
@@ -12,12 +23,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
12
23
|
y: Math.floor(idx / size.width),
|
|
13
24
|
};
|
|
14
25
|
pixels[pos.y] ??= [];
|
|
15
|
-
const
|
|
16
|
-
r: 0,
|
|
17
|
-
g: 1,
|
|
18
|
-
b: 2,
|
|
19
|
-
a: 3,
|
|
20
|
-
}, alphaFactor = 255, row = pixels[pos.y];
|
|
26
|
+
const row = pixels[pos.y];
|
|
21
27
|
if (!row) {
|
|
22
28
|
continue;
|
|
23
29
|
}
|
|
@@ -25,7 +31,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
25
31
|
r: imageData[i + indexesOffset.r] ?? defaultRgbMin,
|
|
26
32
|
g: imageData[i + indexesOffset.g] ?? defaultRgbMin,
|
|
27
33
|
b: imageData[i + indexesOffset.b] ?? defaultRgbMin,
|
|
28
|
-
a: (imageData[i + indexesOffset.a] ?? defaultAlpha)
|
|
34
|
+
a: (imageData[i + indexesOffset.a] ?? defaultAlpha) * alphaFactor,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
return {
|
package/esm/Utils.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import { defaultAlpha, defaultRgbMin, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
-
const defaultWidth = 0
|
|
1
|
+
import { defaultAlpha, defaultRgbMin, identity, isNumber, originPoint, safeDocument, } from "@tsparticles/engine";
|
|
2
|
+
const defaultWidth = 0, indexesOffset = {
|
|
3
|
+
r: 0,
|
|
4
|
+
g: 1,
|
|
5
|
+
b: 2,
|
|
6
|
+
a: 3,
|
|
7
|
+
}, alphaMax = 255, alphaFactor = identity / alphaMax;
|
|
8
|
+
export function drawLine(context, begin, end) {
|
|
9
|
+
context.beginPath();
|
|
10
|
+
context.moveTo(begin.x, begin.y);
|
|
11
|
+
context.lineTo(end.x, end.y);
|
|
12
|
+
context.closePath();
|
|
13
|
+
}
|
|
3
14
|
export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
4
15
|
const imageData = ctx.getImageData(originPoint.x, originPoint.y, size.width, size.height).data;
|
|
5
16
|
if (clear) {
|
|
@@ -12,12 +23,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
12
23
|
y: Math.floor(idx / size.width),
|
|
13
24
|
};
|
|
14
25
|
pixels[pos.y] ??= [];
|
|
15
|
-
const
|
|
16
|
-
r: 0,
|
|
17
|
-
g: 1,
|
|
18
|
-
b: 2,
|
|
19
|
-
a: 3,
|
|
20
|
-
}, alphaFactor = 255, row = pixels[pos.y];
|
|
26
|
+
const row = pixels[pos.y];
|
|
21
27
|
if (!row) {
|
|
22
28
|
continue;
|
|
23
29
|
}
|
|
@@ -25,7 +31,7 @@ export function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
|
25
31
|
r: imageData[i + indexesOffset.r] ?? defaultRgbMin,
|
|
26
32
|
g: imageData[i + indexesOffset.g] ?? defaultRgbMin,
|
|
27
33
|
b: imageData[i + indexesOffset.b] ?? defaultRgbMin,
|
|
28
|
-
a: (imageData[i + indexesOffset.a] ?? defaultAlpha)
|
|
34
|
+
a: (imageData[i + indexesOffset.a] ?? defaultAlpha) * alphaFactor,
|
|
29
35
|
};
|
|
30
36
|
}
|
|
31
37
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsparticles/canvas-utils",
|
|
3
|
-
"version": "4.0.0-
|
|
4
|
-
"description": "tsParticles
|
|
3
|
+
"version": "4.0.0-beta.1",
|
|
4
|
+
"description": "tsParticles canvas utils library",
|
|
5
5
|
"homepage": "https://particles.js.org",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -85,8 +85,8 @@
|
|
|
85
85
|
}
|
|
86
86
|
],
|
|
87
87
|
"sideEffects": false,
|
|
88
|
-
"jsdelivr": "tsparticles.
|
|
89
|
-
"unpkg": "tsparticles.
|
|
88
|
+
"jsdelivr": "tsparticles.canvas.utils.min.js",
|
|
89
|
+
"unpkg": "tsparticles.canvas.utils.min.js",
|
|
90
90
|
"browser": "browser/index.js",
|
|
91
91
|
"main": "cjs/index.js",
|
|
92
92
|
"module": "esm/index.js",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"./package.json": "./package.json"
|
|
104
104
|
},
|
|
105
105
|
"dependencies": {
|
|
106
|
-
"@tsparticles/engine": "4.0.0-
|
|
106
|
+
"@tsparticles/engine": "4.0.0-beta.1"
|
|
107
107
|
},
|
|
108
108
|
"type": "module"
|
|
109
109
|
}
|