@tsparticles/canvas-utils 4.0.0-beta.9 → 4.0.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.
@@ -1,132 +1,126 @@
1
- /*!
2
- * Author : Matteo Bruni
3
- * MIT license: https://opensource.org/licenses/MIT
4
- * Demo / Generator : https://particles.js.org/
5
- * GitHub : https://www.github.com/matteobruni/tsparticles
6
- * How to use? : Check the GitHub README
7
- * v4.0.0-beta.9
8
- */
9
- /*
10
- * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
11
- * This devtool is neither made for production nor for readable output files.
12
- * It uses "eval()" calls to create a separate source file in the browser devtools.
13
- * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
14
- * or disable the default devtool with "devtool: false".
15
- * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
16
- */
17
- (function webpackUniversalModuleDefinition(root, factory) {
18
- if(typeof exports === 'object' && typeof module === 'object')
19
- module.exports = factory(require("@tsparticles/engine"));
20
- else if(typeof define === 'function' && define.amd)
21
- define(["@tsparticles/engine"], factory);
22
- else {
23
- var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
24
- for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
25
- }
26
- })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
27
- return /******/ (() => { // webpackBootstrap
28
- /******/ "use strict";
29
- /******/ var __webpack_modules__ = ({
1
+ (function(g){g.__tsParticlesInternals=g.__tsParticlesInternals||{};g.__tsParticlesInternals.bundles=g.__tsParticlesInternals.bundles||{};g.__tsParticlesInternals.effects=g.__tsParticlesInternals.effects||{};g.__tsParticlesInternals.engine=g.__tsParticlesInternals.engine||{};g.__tsParticlesInternals.interactions=g.__tsParticlesInternals.interactions||{};g.__tsParticlesInternals.palettes=g.__tsParticlesInternals.palettes||{};g.__tsParticlesInternals.paths=g.__tsParticlesInternals.paths||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins=g.__tsParticlesInternals.plugins||{};g.__tsParticlesInternals.plugins.emittersShapes=g.__tsParticlesInternals.plugins.emittersShapes||{};g.__tsParticlesInternals.presets=g.__tsParticlesInternals.presets||{};g.__tsParticlesInternals.shapes=g.__tsParticlesInternals.shapes||{};g.__tsParticlesInternals.updaters=g.__tsParticlesInternals.updaters||{};g.__tsParticlesInternals.utils=g.__tsParticlesInternals.utils||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas=g.__tsParticlesInternals.canvas||{};g.__tsParticlesInternals.canvas.utils=g.__tsParticlesInternals.canvas.utils||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path=g.__tsParticlesInternals.path||{};g.__tsParticlesInternals.path.utils=g.__tsParticlesInternals.path.utils||{};var __tsProxyFactory=typeof Proxy!=="undefined"?function(obj){return new Proxy(obj,{get:function(target,key){if(!(key in target)){target[key]={};}return target[key];}});}:function(obj){return obj;};g.__tsParticlesInternals.bundles=__tsProxyFactory(g.__tsParticlesInternals.bundles);g.__tsParticlesInternals.effects=__tsProxyFactory(g.__tsParticlesInternals.effects);g.__tsParticlesInternals.interactions=__tsProxyFactory(g.__tsParticlesInternals.interactions);g.__tsParticlesInternals.palettes=__tsProxyFactory(g.__tsParticlesInternals.palettes);g.__tsParticlesInternals.paths=__tsProxyFactory(g.__tsParticlesInternals.paths);g.__tsParticlesInternals.plugins=__tsProxyFactory(g.__tsParticlesInternals.plugins);g.__tsParticlesInternals.plugins.emittersShapes=__tsProxyFactory(g.__tsParticlesInternals.plugins.emittersShapes);g.__tsParticlesInternals.presets=__tsProxyFactory(g.__tsParticlesInternals.presets);g.__tsParticlesInternals.shapes=__tsProxyFactory(g.__tsParticlesInternals.shapes);g.__tsParticlesInternals.updaters=__tsProxyFactory(g.__tsParticlesInternals.updaters);g.__tsParticlesInternals.utils=__tsProxyFactory(g.__tsParticlesInternals.utils);g.__tsParticlesInternals.canvas=__tsProxyFactory(g.__tsParticlesInternals.canvas);g.__tsParticlesInternals.path=__tsProxyFactory(g.__tsParticlesInternals.path);g.tsparticlesInternalExports=g.tsparticlesInternalExports||{};})(typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:this);
2
+ /* Utility v4.0.0 */
3
+ (function (global, factory) {
4
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tsparticles/engine')) :
5
+ typeof define === 'function' && define.amd ? define(['exports', '@tsparticles/engine'], factory) :
6
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.__tsParticlesInternals = global.__tsParticlesInternals || {}, global.__tsParticlesInternals.canvas = global.__tsParticlesInternals.canvas || {}, global.__tsParticlesInternals.canvas.utils = global.__tsParticlesInternals.canvas.utils || {}), global.__tsParticlesInternals.engine));
7
+ })(this, (function (exports, engine) { 'use strict';
30
8
 
31
- /***/ "@tsparticles/engine"
32
- /*!*********************************************************************************************************************************!*\
33
- !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
34
- \*********************************************************************************************************************************/
35
- (module) {
9
+ const defaultWidth = 0, indexesOffset = {
10
+ r: 0,
11
+ g: 1,
12
+ b: 2,
13
+ a: 3,
14
+ }, alphaMax = 255, alphaFactor = engine.identity / alphaMax;
15
+ function drawLine(context, begin, end) {
16
+ context.beginPath();
17
+ context.moveTo(begin.x, begin.y);
18
+ context.lineTo(end.x, end.y);
19
+ context.closePath();
20
+ }
21
+ function getCanvasImageData(ctx, size, offset, clear = true) {
22
+ const imageData = ctx.getImageData(engine.originPoint.x, engine.originPoint.y, size.width, size.height).data;
23
+ if (clear) {
24
+ ctx.clearRect(engine.originPoint.x, engine.originPoint.y, size.width, size.height);
25
+ }
26
+ const pixels = [];
27
+ for (let i = 0; i < imageData.length; i += offset) {
28
+ const idx = i / offset, pos = {
29
+ x: idx % size.width,
30
+ y: Math.floor(idx / size.width),
31
+ };
32
+ pixels[pos.y] ??= [];
33
+ const row = pixels[pos.y];
34
+ if (!row) {
35
+ continue;
36
+ }
37
+ row[pos.x] = {
38
+ r: imageData[i + indexesOffset.r] ?? engine.defaultRgbMin,
39
+ g: imageData[i + indexesOffset.g] ?? engine.defaultRgbMin,
40
+ b: imageData[i + indexesOffset.b] ?? engine.defaultRgbMin,
41
+ a: (imageData[i + indexesOffset.a] ?? engine.defaultAlpha) * alphaFactor,
42
+ };
43
+ }
44
+ return {
45
+ pixels,
46
+ width: Math.min(...pixels.map(row => row.length)),
47
+ height: pixels.length,
48
+ };
49
+ }
50
+ function getImageData(src, offset, canvasSettings) {
51
+ const image = new Image();
52
+ image.crossOrigin = "Anonymous";
53
+ const p = new Promise((resolve, reject) => {
54
+ image.onerror = reject;
55
+ image.onload = () => {
56
+ const canvas = engine.safeDocument().createElement("canvas");
57
+ canvas.width = image.width;
58
+ canvas.height = image.height;
59
+ const context = canvas.getContext("2d", canvasSettings);
60
+ if (!context) {
61
+ reject(new Error("Could not get canvas context"));
62
+ return;
63
+ }
64
+ context.drawImage(image, engine.originPoint.x, engine.originPoint.y, image.width, image.height, engine.originPoint.x, engine.originPoint.y, canvas.width, canvas.height);
65
+ resolve(getCanvasImageData(context, canvas, offset));
66
+ };
67
+ });
68
+ image.src = src;
69
+ return p;
70
+ }
71
+ function getTextData(textOptions, offset, fill, canvasSettings) {
72
+ const canvas = engine.safeDocument().createElement("canvas"), context = canvas.getContext("2d", canvasSettings), { font, text, lines: linesOptions, color } = textOptions;
73
+ if (!text || !context) {
74
+ return;
75
+ }
76
+ const lines = text.split(linesOptions.separator), fontSize = engine.isNumber(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
77
+ let maxWidth = 0, totalHeight = 0;
78
+ for (const line of lines) {
79
+ context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
80
+ const measure = context.measureText(line), lineData = {
81
+ measure,
82
+ text: line,
83
+ height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
84
+ width: measure.width,
85
+ };
86
+ maxWidth = Math.max(maxWidth || defaultWidth, lineData.width);
87
+ totalHeight += lineData.height + linesOptions.spacing;
88
+ linesData.push(lineData);
89
+ }
90
+ canvas.width = maxWidth;
91
+ canvas.height = totalHeight;
92
+ let currentHeight = 0;
93
+ for (const line of linesData) {
94
+ context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
95
+ if (fill) {
96
+ context.fillStyle = color;
97
+ context.fillText(line.text, engine.originPoint.x, currentHeight + line.measure.actualBoundingBoxAscent);
98
+ }
99
+ else {
100
+ context.strokeStyle = color;
101
+ context.strokeText(line.text, engine.originPoint.x, currentHeight + line.measure.actualBoundingBoxAscent);
102
+ }
103
+ currentHeight += line.height + linesOptions.spacing;
104
+ }
105
+ return getCanvasImageData(context, canvas, offset);
106
+ }
107
+ async function loadFont(font, weight) {
108
+ try {
109
+ await engine.safeDocument().fonts.load(`${weight ?? "400"} 36px '${font ?? "Verdana"}'`);
110
+ }
111
+ catch {
112
+ }
113
+ }
36
114
 
37
- module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
115
+ const globalObject = globalThis;
116
+ globalObject.__tsParticlesInternals = globalObject.__tsParticlesInternals ?? {};
38
117
 
39
- /***/ },
118
+ exports.drawLine = drawLine;
119
+ exports.getCanvasImageData = getCanvasImageData;
120
+ exports.getImageData = getImageData;
121
+ exports.getTextData = getTextData;
122
+ exports.loadFont = loadFont;
40
123
 
41
- /***/ "./dist/browser/Utils.js"
42
- /*!*******************************!*\
43
- !*** ./dist/browser/Utils.js ***!
44
- \*******************************/
45
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
46
-
47
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawLine: () => (/* binding */ drawLine),\n/* harmony export */ getCanvasImageData: () => (/* binding */ getCanvasImageData),\n/* harmony export */ getImageData: () => (/* binding */ getImageData),\n/* harmony export */ getTextData: () => (/* binding */ getTextData),\n/* harmony export */ loadFont: () => (/* binding */ loadFont)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n\nconst defaultWidth = 0, indexesOffset = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n}, alphaMax = 255, alphaFactor = _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.identity / alphaMax;\nfunction drawLine(context, begin, end) {\n context.beginPath();\n context.moveTo(begin.x, begin.y);\n context.lineTo(end.x, end.y);\n context.closePath();\n}\nfunction getCanvasImageData(ctx, size, offset, clear = true) {\n const imageData = ctx.getImageData(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y, size.width, size.height).data;\n if (clear) {\n ctx.clearRect(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y, size.width, size.height);\n }\n const pixels = [];\n for(let i = 0; i < imageData.length; i += offset){\n const idx = i / offset, pos = {\n x: idx % size.width,\n y: Math.floor(idx / size.width)\n };\n pixels[pos.y] ??= [];\n const row = pixels[pos.y];\n if (!row) {\n continue;\n }\n row[pos.x] = {\n r: imageData[i + indexesOffset.r] ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.defaultRgbMin,\n g: imageData[i + indexesOffset.g] ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.defaultRgbMin,\n b: imageData[i + indexesOffset.b] ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.defaultRgbMin,\n a: (imageData[i + indexesOffset.a] ?? _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.defaultAlpha) * alphaFactor\n };\n }\n return {\n pixels,\n width: Math.min(...pixels.map((row)=>row.length)),\n height: pixels.length\n };\n}\nfunction getImageData(src, offset, canvasSettings) {\n const image = new Image();\n image.crossOrigin = \"Anonymous\";\n const p = new Promise((resolve, reject)=>{\n image.onerror = reject;\n image.onload = ()=>{\n const canvas = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"canvas\");\n canvas.width = image.width;\n canvas.height = image.height;\n const context = canvas.getContext(\"2d\", canvasSettings);\n if (!context) {\n reject(new Error(\"Could not get canvas context\"));\n return;\n }\n context.drawImage(image, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y, image.width, image.height, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.y, canvas.width, canvas.height);\n resolve(getCanvasImageData(context, canvas, offset));\n };\n });\n image.src = src;\n return p;\n}\nfunction getTextData(textOptions, offset, fill, canvasSettings) {\n const canvas = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().createElement(\"canvas\"), context = canvas.getContext(\"2d\", canvasSettings), { font, text, lines: linesOptions, color } = textOptions;\n if (!text || !context) {\n return;\n }\n const lines = text.split(linesOptions.separator), fontSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNumber)(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];\n let maxWidth = 0, totalHeight = 0;\n for (const line of lines){\n context.font = `${font.style || \"\"} ${font.variant || \"\"} ${font.weight || \"\"} ${fontSize} ${font.family}`;\n const measure = context.measureText(line), lineData = {\n measure,\n text: line,\n height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,\n width: measure.width\n };\n maxWidth = Math.max(maxWidth || defaultWidth, lineData.width);\n totalHeight += lineData.height + linesOptions.spacing;\n linesData.push(lineData);\n }\n canvas.width = maxWidth;\n canvas.height = totalHeight;\n let currentHeight = 0;\n for (const line of linesData){\n context.font = `${font.style || \"\"} ${font.variant || \"\"} ${font.weight || \"\"} ${fontSize} ${font.family}`;\n if (fill) {\n context.fillStyle = color;\n context.fillText(line.text, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, currentHeight + line.measure.actualBoundingBoxAscent);\n } else {\n context.strokeStyle = color;\n context.strokeText(line.text, _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.originPoint.x, currentHeight + line.measure.actualBoundingBoxAscent);\n }\n currentHeight += line.height + linesOptions.spacing;\n }\n return getCanvasImageData(context, canvas, offset);\n}\nasync function loadFont(font, weight) {\n try {\n await (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.safeDocument)().fonts.load(`${weight ?? \"400\"} 36px '${font ?? \"Verdana\"}'`);\n } catch {}\n}\n\n\n//# sourceURL=webpack://@tsparticles/canvas-utils/./dist/browser/Utils.js?\n}");
48
-
49
- /***/ },
50
-
51
- /***/ "./dist/browser/index.js"
52
- /*!*******************************!*\
53
- !*** ./dist/browser/index.js ***!
54
- \*******************************/
55
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
56
-
57
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ drawLine: () => (/* reexport safe */ _Utils_js__WEBPACK_IMPORTED_MODULE_0__.drawLine),\n/* harmony export */ getCanvasImageData: () => (/* reexport safe */ _Utils_js__WEBPACK_IMPORTED_MODULE_0__.getCanvasImageData),\n/* harmony export */ getImageData: () => (/* reexport safe */ _Utils_js__WEBPACK_IMPORTED_MODULE_0__.getImageData),\n/* harmony export */ getTextData: () => (/* reexport safe */ _Utils_js__WEBPACK_IMPORTED_MODULE_0__.getTextData),\n/* harmony export */ loadFont: () => (/* reexport safe */ _Utils_js__WEBPACK_IMPORTED_MODULE_0__.loadFont)\n/* harmony export */ });\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n\n\n\n//# sourceURL=webpack://@tsparticles/canvas-utils/./dist/browser/index.js?\n}");
58
-
59
- /***/ }
60
-
61
- /******/ });
62
- /************************************************************************/
63
- /******/ // The module cache
64
- /******/ var __webpack_module_cache__ = {};
65
- /******/
66
- /******/ // The require function
67
- /******/ function __webpack_require__(moduleId) {
68
- /******/ // Check if module is in cache
69
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
70
- /******/ if (cachedModule !== undefined) {
71
- /******/ return cachedModule.exports;
72
- /******/ }
73
- /******/ // Create a new module (and put it into the cache)
74
- /******/ var module = __webpack_module_cache__[moduleId] = {
75
- /******/ // no module.id needed
76
- /******/ // no module.loaded needed
77
- /******/ exports: {}
78
- /******/ };
79
- /******/
80
- /******/ // Execute the module function
81
- /******/ if (!(moduleId in __webpack_modules__)) {
82
- /******/ delete __webpack_module_cache__[moduleId];
83
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
84
- /******/ e.code = 'MODULE_NOT_FOUND';
85
- /******/ throw e;
86
- /******/ }
87
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
88
- /******/
89
- /******/ // Return the exports of the module
90
- /******/ return module.exports;
91
- /******/ }
92
- /******/
93
- /************************************************************************/
94
- /******/ /* webpack/runtime/define property getters */
95
- /******/ (() => {
96
- /******/ // define getter functions for harmony exports
97
- /******/ __webpack_require__.d = (exports, definition) => {
98
- /******/ for(var key in definition) {
99
- /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
100
- /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
101
- /******/ }
102
- /******/ }
103
- /******/ };
104
- /******/ })();
105
- /******/
106
- /******/ /* webpack/runtime/hasOwnProperty shorthand */
107
- /******/ (() => {
108
- /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
109
- /******/ })();
110
- /******/
111
- /******/ /* webpack/runtime/make namespace object */
112
- /******/ (() => {
113
- /******/ // define __esModule on exports
114
- /******/ __webpack_require__.r = (exports) => {
115
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
116
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
117
- /******/ }
118
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
119
- /******/ };
120
- /******/ })();
121
- /******/
122
- /************************************************************************/
123
- /******/
124
- /******/ // startup
125
- /******/ // Load entry module and return exports
126
- /******/ // This entry module can't be inlined because the eval devtool is used.
127
- /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js");
128
- /******/
129
- /******/ return __webpack_exports__;
130
- /******/ })()
131
- ;
132
- });
124
+ }));
125
+ Object.assign(globalThis.window || globalThis, { loadFont: (globalThis.__tsParticlesInternals.canvas.utils || {}).loadFont });
126
+ delete (globalThis.window || globalThis).tsparticlesInternalExports;
@@ -1 +1 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e(require("@tsparticles/engine"));else if("function"==typeof define&&define.amd)define(["@tsparticles/engine"],e);else{var i="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var n in i)("object"==typeof exports?exports:t)[n]=i[n]}}(this,t=>(()=>{"use strict";var e={303(e){e.exports=t}},i={};function n(t){var o=i[t];if(void 0!==o)return o.exports;var r=i[t]={exports:{}};return e[t](r,r.exports,n),r.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var o={};n.r(o),n.d(o,{drawLine:()=>l,getCanvasImageData:()=>g,getImageData:()=>s,getTextData:()=>h,loadFont:()=>c});var r=n(303);let a=r.identity/255;function l(t,e,i){t.beginPath(),t.moveTo(e.x,e.y),t.lineTo(i.x,i.y),t.closePath()}function g(t,e,i,n=!0){let o=t.getImageData(r.originPoint.x,r.originPoint.y,e.width,e.height).data;n&&t.clearRect(r.originPoint.x,r.originPoint.y,e.width,e.height);let l=[];for(let t=0;t<o.length;t+=i){let n=t/i,g={x:n%e.width,y:Math.floor(n/e.width)};l[g.y]??=[];let s=l[g.y];s&&(s[g.x]={r:o[t+0]??r.defaultRgbMin,g:o[t+1]??r.defaultRgbMin,b:o[t+2]??r.defaultRgbMin,a:(o[t+3]??r.defaultAlpha)*a})}return{pixels:l,width:Math.min(...l.map(t=>t.length)),height:l.length}}function s(t,e,i){let n=new Image;n.crossOrigin="Anonymous";let o=new Promise((t,o)=>{n.onerror=o,n.onload=()=>{let a=(0,r.safeDocument)().createElement("canvas");a.width=n.width,a.height=n.height;let l=a.getContext("2d",i);l?(l.drawImage(n,r.originPoint.x,r.originPoint.y,n.width,n.height,r.originPoint.x,r.originPoint.y,a.width,a.height),t(g(l,a,e))):o(Error("Could not get canvas context"))}});return n.src=t,o}function h(t,e,i,n){let o=(0,r.safeDocument)().createElement("canvas"),a=o.getContext("2d",n),{font:l,text:s,lines:h,color:c}=t;if(!s||!a)return;let u=s.split(h.separator),d=(0,r.isNumber)(l.size)?`${l.size.toString()}px`:l.size,f=[],x=0,p=0;for(let t of u){a.font=`${l.style||""} ${l.variant||""} ${l.weight||""} ${d} ${l.family}`;let e=a.measureText(t),i={measure:e,text:t,height:e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,width:e.width};x=Math.max(x||0,i.width),p+=i.height+h.spacing,f.push(i)}o.width=x,o.height=p;let y=0;for(let t of f)a.font=`${l.style||""} ${l.variant||""} ${l.weight||""} ${d} ${l.family}`,i?(a.fillStyle=c,a.fillText(t.text,r.originPoint.x,y+t.measure.actualBoundingBoxAscent)):(a.strokeStyle=c,a.strokeText(t.text,r.originPoint.x,y+t.measure.actualBoundingBoxAscent)),y+=t.height+h.spacing;return g(a,o,e)}async function c(t,e){try{await (0,r.safeDocument)().fonts.load(`${e??"400"} 36px '${t??"Verdana"}'`)}catch{}}return o})());
1
+ !function(t){t.__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.bundles=t.__tsParticlesInternals.bundles||{},t.__tsParticlesInternals.effects=t.__tsParticlesInternals.effects||{},t.__tsParticlesInternals.engine=t.__tsParticlesInternals.engine||{},t.__tsParticlesInternals.interactions=t.__tsParticlesInternals.interactions||{},t.__tsParticlesInternals.palettes=t.__tsParticlesInternals.palettes||{},t.__tsParticlesInternals.paths=t.__tsParticlesInternals.paths||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins=t.__tsParticlesInternals.plugins||{},t.__tsParticlesInternals.plugins.emittersShapes=t.__tsParticlesInternals.plugins.emittersShapes||{},t.__tsParticlesInternals.presets=t.__tsParticlesInternals.presets||{},t.__tsParticlesInternals.shapes=t.__tsParticlesInternals.shapes||{},t.__tsParticlesInternals.updaters=t.__tsParticlesInternals.updaters||{},t.__tsParticlesInternals.utils=t.__tsParticlesInternals.utils||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path=t.__tsParticlesInternals.path||{},t.__tsParticlesInternals.path.utils=t.__tsParticlesInternals.path.utils||{};var s="undefined"!=typeof Proxy?function(t){return new Proxy(t,{get:function(t,s){return s in t||(t[s]={}),t[s]}})}:function(t){return t};t.__tsParticlesInternals.bundles=s(t.__tsParticlesInternals.bundles),t.__tsParticlesInternals.effects=s(t.__tsParticlesInternals.effects),t.__tsParticlesInternals.interactions=s(t.__tsParticlesInternals.interactions),t.__tsParticlesInternals.palettes=s(t.__tsParticlesInternals.palettes),t.__tsParticlesInternals.paths=s(t.__tsParticlesInternals.paths),t.__tsParticlesInternals.plugins=s(t.__tsParticlesInternals.plugins),t.__tsParticlesInternals.plugins.emittersShapes=s(t.__tsParticlesInternals.plugins.emittersShapes),t.__tsParticlesInternals.presets=s(t.__tsParticlesInternals.presets),t.__tsParticlesInternals.shapes=s(t.__tsParticlesInternals.shapes),t.__tsParticlesInternals.updaters=s(t.__tsParticlesInternals.updaters),t.__tsParticlesInternals.utils=s(t.__tsParticlesInternals.utils),t.__tsParticlesInternals.canvas=s(t.__tsParticlesInternals.canvas),t.__tsParticlesInternals.path=s(t.__tsParticlesInternals.path),t.tsparticlesInternalExports=t.tsparticlesInternalExports||{}}("undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:this),function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("@tsparticles/engine")):"function"==typeof define&&define.amd?define(["exports","@tsparticles/engine"],s):s(((t="undefined"!=typeof globalThis?globalThis:t||self).__tsParticlesInternals=t.__tsParticlesInternals||{},t.__tsParticlesInternals.canvas=t.__tsParticlesInternals.canvas||{},t.__tsParticlesInternals.canvas.utils=t.__tsParticlesInternals.canvas.utils||{}),t.__tsParticlesInternals.engine)}(this,function(t,s){"use strict";const e=0,n=1,a=2,l=3,i=s.identity/255;function r(t,r,c,_=!0){const o=t.getImageData(s.originPoint.x,s.originPoint.y,r.width,r.height).data;_&&t.clearRect(s.originPoint.x,s.originPoint.y,r.width,r.height);const P=[];for(let t=0;t<o.length;t+=c){const _=t/c,I={x:_%r.width,y:Math.floor(_/r.width)};P[I.y]??=[];const h=P[I.y];h&&(h[I.x]={r:o[t+e]??s.defaultRgbMin,g:o[t+n]??s.defaultRgbMin,b:o[t+a]??s.defaultRgbMin,a:(o[t+l]??s.defaultAlpha)*i})}return{pixels:P,width:Math.min(...P.map(t=>t.length)),height:P.length}}const c=globalThis;c.__tsParticlesInternals=c.__tsParticlesInternals??{},t.drawLine=function(t,s,e){t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(e.x,e.y),t.closePath()},t.getCanvasImageData=r,t.getImageData=function(t,e,n){const a=new Image;a.crossOrigin="Anonymous";const l=new Promise((t,l)=>{a.onerror=l,a.onload=()=>{const i=s.safeDocument().createElement("canvas");i.width=a.width,i.height=a.height;const c=i.getContext("2d",n);c?(c.drawImage(a,s.originPoint.x,s.originPoint.y,a.width,a.height,s.originPoint.x,s.originPoint.y,i.width,i.height),t(r(c,i,e))):l(new Error("Could not get canvas context"))}});return a.src=t,l},t.getTextData=function(t,e,n,a){const l=s.safeDocument().createElement("canvas"),i=l.getContext("2d",a),{font:c,text:_,lines:o,color:P}=t;if(!_||!i)return;const I=_.split(o.separator),h=s.isNumber(c.size)?`${c.size.toString()}px`:c.size,u=[];let g=0,p=0;for(const t of I){i.font=`${c.style||""} ${c.variant||""} ${c.weight||""} ${h} ${c.family}`;const s=i.measureText(t),e={measure:s,text:t,height:s.actualBoundingBoxAscent+s.actualBoundingBoxDescent,width:s.width};g=Math.max(g||0,e.width),p+=e.height+o.spacing,u.push(e)}l.width=g,l.height=p;let d=0;for(const t of u)i.font=`${c.style||""} ${c.variant||""} ${c.weight||""} ${h} ${c.family}`,n?(i.fillStyle=P,i.fillText(t.text,s.originPoint.x,d+t.measure.actualBoundingBoxAscent)):(i.strokeStyle=P,i.strokeText(t.text,s.originPoint.x,d+t.measure.actualBoundingBoxAscent)),d+=t.height+o.spacing;return r(i,l,e)},t.loadFont=async function(t,e){try{await s.safeDocument().fonts.load(`${e??"400"} 36px '${t??"Verdana"}'`)}catch{}}}),Object.assign(globalThis.window||globalThis,{loadFont:(globalThis.__tsParticlesInternals.canvas.utils||{}).loadFont}),delete(globalThis.window||globalThis).tsparticlesInternalExports;
package/types/Utils.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { type CanvasContextType, type ICoordinates, type IDimension } from "@tsparticles/engine";
2
1
  import type { CanvasPixelData, ITextDataOptions } from "./types.js";
3
- export declare function drawLine(context: CanvasContextType, begin: ICoordinates, end: ICoordinates): void;
4
- export declare function getCanvasImageData(ctx: CanvasContextType, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
2
+ import { type ICoordinates, type IDimension } from "@tsparticles/engine";
3
+ export declare function drawLine(context: OffscreenCanvasRenderingContext2D, begin: ICoordinates, end: ICoordinates): void;
4
+ export declare function getCanvasImageData(ctx: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
5
5
  export declare function getImageData(src: string, offset: number, canvasSettings?: CanvasRenderingContext2DSettings): Promise<CanvasPixelData>;
6
6
  export declare function getTextData(textOptions: ITextDataOptions, offset: number, fill: boolean, canvasSettings?: CanvasRenderingContext2DSettings): CanvasPixelData | undefined;
7
7
  export declare function loadFont(font?: string, weight?: string): Promise<void>;
@@ -0,0 +1 @@
1
+ export * from "./index.js";
@@ -0,0 +1,2 @@
1
+ export type * from "./types.js";
2
+ export * from "./Utils.js";