@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.
@@ -0,0 +1,132 @@
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.1
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__ = ({
30
+
31
+ /***/ "@tsparticles/engine"
32
+ /*!*********************************************************************************************************************************!*\
33
+ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
34
+ \*********************************************************************************************************************************/
35
+ (module) {
36
+
37
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
38
+
39
+ /***/ },
40
+
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
+ });
@@ -0,0 +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})());
package/types/Utils.d.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { type CanvasContextType, type ICoordinates, type IDimension } from "@tsparticles/engine";
1
2
  import type { CanvasPixelData, ITextDataOptions } from "./types.js";
2
- import { type IDimension } from "@tsparticles/engine";
3
- export declare function getCanvasImageData(ctx: CanvasRenderingContext2D, size: IDimension, offset: number, clear?: boolean): CanvasPixelData;
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;
4
5
  export declare function getImageData(src: string, offset: number, canvasSettings?: CanvasRenderingContext2DSettings): Promise<CanvasPixelData>;
5
6
  export declare function getTextData(textOptions: ITextDataOptions, offset: number, fill: boolean, canvasSettings?: CanvasRenderingContext2DSettings): CanvasPixelData | undefined;
6
7
  export declare function loadFont(font?: string, weight?: string): Promise<void>;
package/umd/Utils.js CHANGED
@@ -9,12 +9,24 @@
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.drawLine = drawLine;
12
13
  exports.getCanvasImageData = getCanvasImageData;
13
14
  exports.getImageData = getImageData;
14
15
  exports.getTextData = getTextData;
15
16
  exports.loadFont = loadFont;
16
17
  const engine_1 = require("@tsparticles/engine");
17
- const defaultWidth = 0;
18
+ const defaultWidth = 0, indexesOffset = {
19
+ r: 0,
20
+ g: 1,
21
+ b: 2,
22
+ a: 3,
23
+ }, alphaMax = 255, alphaFactor = engine_1.identity / alphaMax;
24
+ function drawLine(context, begin, end) {
25
+ context.beginPath();
26
+ context.moveTo(begin.x, begin.y);
27
+ context.lineTo(end.x, end.y);
28
+ context.closePath();
29
+ }
18
30
  function getCanvasImageData(ctx, size, offset, clear = true) {
19
31
  const imageData = ctx.getImageData(engine_1.originPoint.x, engine_1.originPoint.y, size.width, size.height).data;
20
32
  if (clear) {
@@ -27,12 +39,7 @@
27
39
  y: Math.floor(idx / size.width),
28
40
  };
29
41
  pixels[pos.y] ??= [];
30
- const indexesOffset = {
31
- r: 0,
32
- g: 1,
33
- b: 2,
34
- a: 3,
35
- }, alphaFactor = 255, row = pixels[pos.y];
42
+ const row = pixels[pos.y];
36
43
  if (!row) {
37
44
  continue;
38
45
  }
@@ -40,7 +47,7 @@
40
47
  r: imageData[i + indexesOffset.r] ?? engine_1.defaultRgbMin,
41
48
  g: imageData[i + indexesOffset.g] ?? engine_1.defaultRgbMin,
42
49
  b: imageData[i + indexesOffset.b] ?? engine_1.defaultRgbMin,
43
- a: (imageData[i + indexesOffset.a] ?? engine_1.defaultAlpha) / alphaFactor,
50
+ a: (imageData[i + indexesOffset.a] ?? engine_1.defaultAlpha) * alphaFactor,
44
51
  };
45
52
  }
46
53
  return {
@@ -1,132 +0,0 @@
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-alpha.8
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__ = ({
30
-
31
- /***/ "./dist/browser/Utils.js"
32
- /*!*******************************!*\
33
- !*** ./dist/browser/Utils.js ***!
34
- \*******************************/
35
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
36
-
37
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\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;\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,\n pos = {\n x: idx % size.width,\n y: Math.floor(idx / size.width)\n };\n pixels[pos.y] ??= [];\n const indexesOffset = {\n r: 0,\n g: 1,\n b: 2,\n a: 3\n },\n alphaFactor = 255,\n 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\"),\n context = canvas.getContext(\"2d\", canvasSettings),\n {\n font,\n text,\n lines: linesOptions,\n color\n } = textOptions;\n if (!text || !context) {\n return;\n }\n const lines = text.split(linesOptions.separator),\n fontSize = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.isNumber)(font.size) ? `${font.size.toString()}px` : font.size,\n linesData = [];\n let maxWidth = 0,\n 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),\n 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//# sourceURL=webpack://@tsparticles/canvas-utils/./dist/browser/Utils.js?\n}");
38
-
39
- /***/ },
40
-
41
- /***/ "./dist/browser/index.js"
42
- /*!*******************************!*\
43
- !*** ./dist/browser/index.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 */ 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//# sourceURL=webpack://@tsparticles/canvas-utils/./dist/browser/index.js?\n}");
48
-
49
- /***/ },
50
-
51
- /***/ "@tsparticles/engine"
52
- /*!*********************************************************************************************************************************!*\
53
- !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
54
- \*********************************************************************************************************************************/
55
- (module) {
56
-
57
- module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
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
- /******/ // Check if module exists (development only)
74
- /******/ if (__webpack_modules__[moduleId] === undefined) {
75
- /******/ var e = new Error("Cannot find module '" + moduleId + "'");
76
- /******/ e.code = 'MODULE_NOT_FOUND';
77
- /******/ throw e;
78
- /******/ }
79
- /******/ // Create a new module (and put it into the cache)
80
- /******/ var module = __webpack_module_cache__[moduleId] = {
81
- /******/ // no module.id needed
82
- /******/ // no module.loaded needed
83
- /******/ exports: {}
84
- /******/ };
85
- /******/
86
- /******/ // Execute the module function
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
- });
@@ -1,2 +0,0 @@
1
- /*! For license information please see tsparticles.path.utils.min.js.LICENSE.txt */
2
- !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 n="object"==typeof exports?e(require("@tsparticles/engine")):e(t.window);for(var o in n)("object"==typeof exports?exports:t)[o]=n[o]}}(this,(t=>(()=>{var e={303(e){e.exports=t}},n={};function o(t){var i=n[t];if(void 0!==i)return i.exports;var r=n[t]={exports:{}};return e[t](r,r.exports,o),r.exports}o.d=(t,e)=>{for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),o.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};o.r(i),o.d(i,{getCanvasImageData:()=>s,getImageData:()=>c,getTextData:()=>g,loadFont:()=>l});var r=o(303);const a=0;function s(t,e,n,o=!0){const i=t.getImageData(r.originPoint.x,r.originPoint.y,e.width,e.height).data;o&&t.clearRect(r.originPoint.x,r.originPoint.y,e.width,e.height);const a=[];for(let t=0;t<i.length;t+=n){const o=t/n,s={x:o%e.width,y:Math.floor(o/e.width)};a[s.y]??=[];const c={r:0,g:1,b:2,a:3},g=255,l=a[s.y];l&&(l[s.x]={r:i[t+c.r]??r.defaultRgbMin,g:i[t+c.g]??r.defaultRgbMin,b:i[t+c.b]??r.defaultRgbMin,a:(i[t+c.a]??r.defaultAlpha)/g})}return{pixels:a,width:Math.min(...a.map((t=>t.length))),height:a.length}}function c(t,e,n){const o=new Image;o.crossOrigin="Anonymous";const i=new Promise(((t,i)=>{o.onerror=i,o.onload=()=>{const a=(0,r.safeDocument)().createElement("canvas");a.width=o.width,a.height=o.height;const c=a.getContext("2d",n);c?(c.drawImage(o,r.originPoint.x,r.originPoint.y,o.width,o.height,r.originPoint.x,r.originPoint.y,a.width,a.height),t(s(c,a,e))):i(new Error("Could not get canvas context"))}}));return o.src=t,i}function g(t,e,n,o){const i=(0,r.safeDocument)().createElement("canvas"),c=i.getContext("2d",o),{font:g,text:l,lines:h,color:d}=t;if(!l||!c)return;const f=l.split(h.separator),u=(0,r.isNumber)(g.size)?`${g.size.toString()}px`:g.size,x=[];let p=0,y=0;for(const t of f){c.font=`${g.style||""} ${g.variant||""} ${g.weight||""} ${u} ${g.family}`;const e=c.measureText(t),n={measure:e,text:t,height:e.actualBoundingBoxAscent+e.actualBoundingBoxDescent,width:e.width};p=Math.max(p||a,n.width),y+=n.height+h.spacing,x.push(n)}i.width=p,i.height=y;let m=0;for(const t of x)c.font=`${g.style||""} ${g.variant||""} ${g.weight||""} ${u} ${g.family}`,n?(c.fillStyle=d,c.fillText(t.text,r.originPoint.x,m+t.measure.actualBoundingBoxAscent)):(c.strokeStyle=d,c.strokeText(t.text,r.originPoint.x,m+t.measure.actualBoundingBoxAscent)),m+=t.height+h.spacing;return s(c,i,e)}async function l(t,e){try{await(0,r.safeDocument)().fonts.load(`${e??"400"} 36px '${t??"Verdana"}'`)}catch{}}return i})()));
@@ -1 +0,0 @@
1
- /*! tsParticles Path Utils v4.0.0-alpha.8 by Matteo Bruni */