@tsparticles/plugin-emitters-shape-canvas 3.0.3 → 3.2.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/720.min.js +2 -0
- package/720.min.js.LICENSE.txt +1 -0
- package/browser/EmittersCanvasShape.js +12 -12
- package/browser/Options/Classes/EmittersCanvasShapeOptions.js +2 -1
- package/browser/index.js +2 -4
- package/browser/utils.js +20 -10
- package/cjs/EmittersCanvasShape.js +12 -12
- package/cjs/Options/Classes/EmittersCanvasShapeOptions.js +2 -1
- package/cjs/index.js +25 -4
- package/cjs/utils.js +20 -10
- package/dist_browser_EmittersCanvasShapeGenerator_js.js +100 -0
- package/esm/EmittersCanvasShape.js +12 -12
- package/esm/Options/Classes/EmittersCanvasShapeOptions.js +2 -1
- package/esm/index.js +2 -4
- package/esm/utils.js +20 -10
- package/package.json +3 -3
- package/report.html +3 -3
- package/tsparticles.plugin.emitters.shape.canvas.js +246 -362
- package/tsparticles.plugin.emitters.shape.canvas.min.js +1 -1
- package/tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt +1 -1
- package/types/types.d.ts +4 -4
- package/types/utils.d.ts +1 -1
- package/umd/EmittersCanvasShape.js +12 -12
- package/umd/Options/Classes/EmittersCanvasShapeOptions.js +2 -1
- package/umd/index.js +27 -5
- package/umd/utils.js +20 -10
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt */
|
|
2
|
-
!function(t
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine")):t(e.window,e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,((e,t)=>(()=>{var r,i,n={533:e=>{e.exports=t},68:t=>{t.exports=e}},o={};function a(e){var t=o[e];if(void 0!==t)return t.exports;var r=o[e]={exports:{}};return n[e](r,r.exports,a),r.exports}a.m=n,a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.f={},a.e=e=>Promise.all(Object.keys(a.f).reduce(((t,r)=>(a.f[r](e,t),t)),[])),a.u=e=>e+".min.js",a.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r={},i="@tsparticles/plugin-emitters-shape-canvas:",a.l=(e,t,n,o)=>{if(r[e])r[e].push(t);else{var s,p;if(void 0!==n)for(var c=document.getElementsByTagName("script"),l=0;l<c.length;l++){var u=c[l];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==i+n){s=u;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",s.timeout=120,a.nc&&s.setAttribute("nonce",a.nc),s.setAttribute("data-webpack",i+n),s.src=e),r[e]=[t];var d=(t,i)=>{s.onerror=s.onload=null,clearTimeout(f);var n=r[e];if(delete r[e],s.parentNode&&s.parentNode.removeChild(s),n&&n.forEach((e=>e(i))),t)return t(i)},f=setTimeout(d.bind(null,void 0,{type:"timeout",target:s}),12e4);s.onerror=d.bind(null,s.onerror),s.onload=d.bind(null,s.onload),p&&document.head.appendChild(s)}},a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;a.g.importScripts&&(e=a.g.location+"");var t=a.g.document;if(!e&&t&&(t.currentScript&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&!e;)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),a.p=e})(),(()=>{var e={926:0};a.f.j=(t,r)=>{var i=a.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var n=new Promise(((r,n)=>i=e[t]=[r,n]));r.push(i[2]=n);var o=a.p+a.u(t),s=new Error;a.l(o,(r=>{if(a.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var n=r&&("load"===r.type?"missing":r.type),o=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+n+": "+o+")",s.name="ChunkLoadError",s.type=n,s.request=o,i[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,n,o=r[0],s=r[1],p=r[2],c=0;if(o.some((t=>0!==e[t]))){for(i in s)a.o(s,i)&&(a.m[i]=s[i]);if(p)p(a)}for(t&&t(r);c<o.length;c++)n=o[c],a.o(e,n)&&e[n]&&e[n][0](),e[n]=0},r=this.webpackChunk_tsparticles_plugin_emitters_shape_canvas=this.webpackChunk_tsparticles_plugin_emitters_shape_canvas||[];r.forEach(t.bind(null,0)),r.push=t.bind(null,r.push.bind(r))})();var s={};return(()=>{async function e(e,t=!0){const r=e,{EmittersCanvasShapeGenerator:i}=await a.e(720).then(a.bind(a,720));r.addEmitterShapeGenerator?.("canvas",new i),await r.refresh(t)}a.r(s),a.d(s,{loadEmittersShapeCanvas:()=>e})})(),s})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! tsParticles Emitters Shape Canvas Plugin v3.0
|
|
1
|
+
/*! tsParticles Emitters Shape Canvas Plugin v3.2.0 by Matteo Bruni */
|
package/types/types.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { IRgba } from "@tsparticles/engine";
|
|
2
|
-
export
|
|
2
|
+
export interface CanvasPixelData {
|
|
3
3
|
height: number;
|
|
4
4
|
pixels: IRgba[][];
|
|
5
5
|
width: number;
|
|
6
|
-
}
|
|
7
|
-
export
|
|
6
|
+
}
|
|
7
|
+
export interface TextLineData {
|
|
8
8
|
height: number;
|
|
9
9
|
measure: TextMetrics;
|
|
10
10
|
text: string;
|
|
11
11
|
width: number;
|
|
12
|
-
}
|
|
12
|
+
}
|
package/types/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CanvasPixelData } from "./types.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type IDimension } from "@tsparticles/engine";
|
|
3
3
|
import type { TextOptions } from "./Options/Classes/TextOptions.js";
|
|
4
4
|
export declare function getCanvasImageData(ctx: CanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
|
|
5
5
|
export declare function getImageData(src: string, offset: number): Promise<CanvasPixelData>;
|
|
@@ -13,11 +13,12 @@
|
|
|
13
13
|
const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
|
|
14
14
|
const engine_1 = require("@tsparticles/engine");
|
|
15
15
|
const utils_js_1 = require("./utils.js");
|
|
16
|
+
const maxRetries = 100, half = 0.5;
|
|
16
17
|
class EmittersCanvasShape extends plugin_emitters_1.EmitterShapeBase {
|
|
17
18
|
constructor(position, size, fill, options) {
|
|
18
19
|
super(position, size, fill, options);
|
|
19
|
-
const filter = options.filter;
|
|
20
|
-
let filterFunc = (pixel) => pixel.a >
|
|
20
|
+
const filter = options.filter, minAlpha = 0;
|
|
21
|
+
let filterFunc = (pixel) => pixel.a > minAlpha;
|
|
21
22
|
if (filter !== undefined) {
|
|
22
23
|
if ((0, engine_1.isString)(filter)) {
|
|
23
24
|
if (Object.hasOwn(window, filter)) {
|
|
@@ -56,8 +57,8 @@
|
|
|
56
57
|
}
|
|
57
58
|
pixelData = data;
|
|
58
59
|
}
|
|
59
|
-
else if (element
|
|
60
|
-
const canvas = element
|
|
60
|
+
else if (element ?? selector) {
|
|
61
|
+
const canvas = element ?? (selector && document.querySelector(selector));
|
|
61
62
|
if (!canvas) {
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
@@ -73,12 +74,11 @@
|
|
|
73
74
|
this.pixelData = pixelData;
|
|
74
75
|
}
|
|
75
76
|
async randomPosition() {
|
|
76
|
-
const { height, width } = this.pixelData, data = this.pixelData, position = this.position, scale = this.scale
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
y: position.y - (height * scale) / 2,
|
|
77
|
+
const { height, width } = this.pixelData, data = this.pixelData, position = this.position, scale = this.scale, positionOffset = {
|
|
78
|
+
x: position.x - width * scale * half,
|
|
79
|
+
y: position.y - height * scale * half,
|
|
80
80
|
};
|
|
81
|
-
for (let i = 0; i <
|
|
81
|
+
for (let i = 0; i < maxRetries; i++) {
|
|
82
82
|
const nextIndex = Math.floor((0, engine_1.getRandom)() * width * height), pixelPos = {
|
|
83
83
|
x: nextIndex % width,
|
|
84
84
|
y: Math.floor(nextIndex / width),
|
|
@@ -86,16 +86,16 @@
|
|
|
86
86
|
if (!shouldCreateParticle) {
|
|
87
87
|
continue;
|
|
88
88
|
}
|
|
89
|
-
return {
|
|
89
|
+
return Promise.resolve({
|
|
90
90
|
position: {
|
|
91
91
|
x: pixelPos.x * scale + positionOffset.x,
|
|
92
92
|
y: pixelPos.y * scale + positionOffset.y,
|
|
93
93
|
},
|
|
94
94
|
color: { ...pixel },
|
|
95
95
|
opacity: pixel.a,
|
|
96
|
-
};
|
|
96
|
+
});
|
|
97
97
|
}
|
|
98
|
-
return null;
|
|
98
|
+
return Promise.resolve(null);
|
|
99
99
|
}
|
|
100
100
|
resize(position, size) {
|
|
101
101
|
super.resize(position, size);
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
exports.EmittersCanvasShapeOptions = void 0;
|
|
13
13
|
const PixelsOptions_js_1 = require("./PixelsOptions.js");
|
|
14
14
|
const TextOptions_js_1 = require("./TextOptions.js");
|
|
15
|
+
const minAlpha = 0;
|
|
15
16
|
class EmittersCanvasShapeOptions {
|
|
16
17
|
constructor() {
|
|
17
|
-
this.filter = (pixel) => pixel.a >
|
|
18
|
+
this.filter = (pixel) => pixel.a > minAlpha;
|
|
18
19
|
this.pixels = new PixelsOptions_js_1.PixelsOptions();
|
|
19
20
|
this.scale = 1;
|
|
20
21
|
this.selector = "";
|
package/umd/index.js
CHANGED
|
@@ -1,20 +1,42 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
+
}) : function(o, v) {
|
|
15
|
+
o["default"] = v;
|
|
16
|
+
});
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
1
24
|
(function (factory) {
|
|
2
25
|
if (typeof module === "object" && typeof module.exports === "object") {
|
|
3
26
|
var v = factory(require, exports);
|
|
4
27
|
if (v !== undefined) module.exports = v;
|
|
5
28
|
}
|
|
6
29
|
else if (typeof define === "function" && define.amd) {
|
|
7
|
-
define(["require", "exports"
|
|
30
|
+
define(["require", "exports"], factory);
|
|
8
31
|
}
|
|
9
32
|
})(function (require, exports) {
|
|
10
33
|
"use strict";
|
|
34
|
+
var __syncRequire = typeof module === "object" && typeof module.exports === "object";
|
|
11
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
36
|
exports.loadEmittersShapeCanvas = void 0;
|
|
13
|
-
const EmittersCanvasShapeGenerator_js_1 = require("./EmittersCanvasShapeGenerator.js");
|
|
14
37
|
async function loadEmittersShapeCanvas(engine, refresh = true) {
|
|
15
|
-
const emittersEngine = engine;
|
|
16
|
-
emittersEngine.addEmitterShapeGenerator
|
|
17
|
-
emittersEngine.addEmitterShapeGenerator("canvas", new EmittersCanvasShapeGenerator_js_1.EmittersCanvasShapeGenerator());
|
|
38
|
+
const emittersEngine = engine, { EmittersCanvasShapeGenerator } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmittersCanvasShapeGenerator.js"))) : new Promise((resolve_1, reject_1) => { require(["./EmittersCanvasShapeGenerator.js"], resolve_1, reject_1); }).then(__importStar));
|
|
39
|
+
emittersEngine.addEmitterShapeGenerator?.("canvas", new EmittersCanvasShapeGenerator());
|
|
18
40
|
await emittersEngine.refresh(refresh);
|
|
19
41
|
}
|
|
20
42
|
exports.loadEmittersShapeCanvas = loadEmittersShapeCanvas;
|
package/umd/utils.js
CHANGED
|
@@ -11,10 +11,14 @@
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getTextData = exports.getImageData = exports.getCanvasImageData = void 0;
|
|
13
13
|
const engine_1 = require("@tsparticles/engine");
|
|
14
|
+
const origin = {
|
|
15
|
+
x: 0,
|
|
16
|
+
y: 0,
|
|
17
|
+
}, minWidth = 0;
|
|
14
18
|
function getCanvasImageData(ctx, size, offset, clear = true) {
|
|
15
|
-
const imageData = ctx.getImageData(
|
|
19
|
+
const imageData = ctx.getImageData(origin.x, origin.y, size.width, size.height).data;
|
|
16
20
|
if (clear) {
|
|
17
|
-
ctx.clearRect(
|
|
21
|
+
ctx.clearRect(origin.x, origin.y, size.width, size.height);
|
|
18
22
|
}
|
|
19
23
|
const pixels = [];
|
|
20
24
|
for (let i = 0; i < imageData.length; i += offset) {
|
|
@@ -25,11 +29,17 @@
|
|
|
25
29
|
if (!pixels[pos.y]) {
|
|
26
30
|
pixels[pos.y] = [];
|
|
27
31
|
}
|
|
32
|
+
const indexesOffset = {
|
|
33
|
+
r: 0,
|
|
34
|
+
g: 1,
|
|
35
|
+
b: 2,
|
|
36
|
+
a: 3,
|
|
37
|
+
}, alphaFactor = 255;
|
|
28
38
|
pixels[pos.y][pos.x] = {
|
|
29
|
-
r: imageData[i],
|
|
30
|
-
g: imageData[i +
|
|
31
|
-
b: imageData[i +
|
|
32
|
-
a: imageData[i +
|
|
39
|
+
r: imageData[i + indexesOffset.r],
|
|
40
|
+
g: imageData[i + indexesOffset.g],
|
|
41
|
+
b: imageData[i + indexesOffset.b],
|
|
42
|
+
a: imageData[i + indexesOffset.a] / alphaFactor,
|
|
33
43
|
};
|
|
34
44
|
}
|
|
35
45
|
return {
|
|
@@ -52,7 +62,7 @@
|
|
|
52
62
|
if (!context) {
|
|
53
63
|
return reject(new Error(`${engine_1.errorPrefix} Could not get canvas context`));
|
|
54
64
|
}
|
|
55
|
-
context.drawImage(image,
|
|
65
|
+
context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
|
|
56
66
|
resolve(getCanvasImageData(context, canvas, offset));
|
|
57
67
|
};
|
|
58
68
|
});
|
|
@@ -75,7 +85,7 @@
|
|
|
75
85
|
height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
|
|
76
86
|
width: measure.width,
|
|
77
87
|
};
|
|
78
|
-
maxWidth = Math.max(maxWidth ||
|
|
88
|
+
maxWidth = Math.max(maxWidth || minWidth, lineData.width);
|
|
79
89
|
totalHeight += lineData.height + linesOptions.spacing;
|
|
80
90
|
linesData.push(lineData);
|
|
81
91
|
}
|
|
@@ -86,11 +96,11 @@
|
|
|
86
96
|
context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
|
|
87
97
|
if (fill) {
|
|
88
98
|
context.fillStyle = color;
|
|
89
|
-
context.fillText(line.text,
|
|
99
|
+
context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
90
100
|
}
|
|
91
101
|
else {
|
|
92
102
|
context.strokeStyle = color;
|
|
93
|
-
context.strokeText(line.text,
|
|
103
|
+
context.strokeText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
|
|
94
104
|
}
|
|
95
105
|
currentHeight += line.height + linesOptions.spacing;
|
|
96
106
|
}
|