@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 CHANGED
@@ -1,12 +1,12 @@
1
1
  [![banner](https://particles.js.org/images/banner3.png)](https://particles.js.org)
2
2
 
3
- # tsParticles Path Utils Library
3
+ # tsParticles Canvas Utils Library
4
4
 
5
5
  [![jsDelivr](https://data.jsdelivr.com/v1/package/npm/@tsparticles/canvas-utils/badge)](https://www.jsdelivr.com/package/npm/@tsparticles/canvas-utils)
6
6
  [![npmjs](https://badge.fury.io/js/@tsparticles/canvas-utils.svg)](https://www.npmjs.com/package/@tsparticles/canvas-utils)
7
7
  [![npmjs](https://img.shields.io/npm/dt/@tsparticles/canvas-utils)](https://www.npmjs.com/package/@tsparticles/canvas-utils) [![GitHub Sponsors](https://img.shields.io/github/sponsors/matteobruni)](https://github.com/sponsors/matteobruni)
8
8
 
9
- [tsParticles](https://github.com/tsparticles/tsparticles) path plugin for path utils movement.
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.path.utils.min.js` file will export the function to load the path plugin:
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 path plugin like this:
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 indexesOffset = {
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) / alphaFactor,
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 indexesOffset = {
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) / alphaFactor,
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 indexesOffset = {
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) / alphaFactor,
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-alpha.8",
4
- "description": "tsParticles path utils library",
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.path.utils.min.js",
89
- "unpkg": "tsparticles.path.utils.min.js",
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-alpha.8"
106
+ "@tsparticles/engine": "4.0.0-beta.1"
107
107
  },
108
108
  "type": "module"
109
109
  }