@tsparticles/plugin-emitters-shape-canvas 4.0.0-alpha.8 → 4.0.0-beta.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.
Files changed (51) hide show
  1. package/373.min.js +2 -0
  2. package/browser/EmittersCanvasShape.js +12 -7
  3. package/browser/EmittersCanvasShapeGenerator.js +2 -2
  4. package/browser/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
  5. package/browser/Options/Classes/PixelsOptions.js +1 -0
  6. package/browser/Options/Classes/TextFontOptions.js +5 -0
  7. package/browser/Options/Classes/TextLinesOptions.js +2 -0
  8. package/browser/Options/Classes/TextOptions.js +4 -0
  9. package/browser/index.js +4 -5
  10. package/cjs/EmittersCanvasShape.js +12 -7
  11. package/cjs/EmittersCanvasShapeGenerator.js +2 -2
  12. package/cjs/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
  13. package/cjs/Options/Classes/PixelsOptions.js +1 -0
  14. package/cjs/Options/Classes/TextFontOptions.js +5 -0
  15. package/cjs/Options/Classes/TextLinesOptions.js +2 -0
  16. package/cjs/Options/Classes/TextOptions.js +4 -0
  17. package/cjs/index.js +4 -5
  18. package/dist_browser_EmittersCanvasShapeGenerator_js.js +8 -18
  19. package/esm/EmittersCanvasShape.js +12 -7
  20. package/esm/EmittersCanvasShapeGenerator.js +2 -2
  21. package/esm/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
  22. package/esm/Options/Classes/PixelsOptions.js +1 -0
  23. package/esm/Options/Classes/TextFontOptions.js +5 -0
  24. package/esm/Options/Classes/TextLinesOptions.js +2 -0
  25. package/esm/Options/Classes/TextOptions.js +4 -0
  26. package/esm/index.js +4 -5
  27. package/package.json +4 -3
  28. package/report.html +1 -1
  29. package/tsparticles.plugin.emitters.shape.canvas.js +71 -19
  30. package/tsparticles.plugin.emitters.shape.canvas.min.js +2 -2
  31. package/types/EmittersCanvasShape.d.ts +3 -2
  32. package/types/EmittersCanvasShapeGenerator.d.ts +2 -2
  33. package/types/Options/Interfaces/ITextFontOptions.d.ts +2 -7
  34. package/types/Options/Interfaces/ITextLinesOptions.d.ts +2 -4
  35. package/types/Options/Interfaces/ITextOptions.d.ts +2 -3
  36. package/umd/EmittersCanvasShape.js +14 -9
  37. package/umd/EmittersCanvasShapeGenerator.js +2 -2
  38. package/umd/Options/Classes/EmittersCanvasShapeOptions.js +7 -0
  39. package/umd/Options/Classes/PixelsOptions.js +1 -0
  40. package/umd/Options/Classes/TextFontOptions.js +5 -0
  41. package/umd/Options/Classes/TextLinesOptions.js +2 -0
  42. package/umd/Options/Classes/TextOptions.js +4 -0
  43. package/umd/index.js +5 -6
  44. package/103.min.js +0 -2
  45. package/103.min.js.LICENSE.txt +0 -1
  46. package/browser/utils.js +0 -96
  47. package/cjs/utils.js +0 -96
  48. package/esm/utils.js +0 -96
  49. package/tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt +0 -1
  50. package/types/utils.d.ts +0 -6
  51. package/umd/utils.js +0 -111
@@ -4,7 +4,7 @@
4
4
  * Demo / Generator : https://particles.js.org/
5
5
  * GitHub : https://www.github.com/matteobruni/tsparticles
6
6
  * How to use? : Check the GitHub README
7
- * v4.0.0-alpha.8
7
+ * v4.0.0-beta.0
8
8
  */
9
9
  /*
10
10
  * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
@@ -16,25 +16,25 @@
16
16
  */
17
17
  (function webpackUniversalModuleDefinition(root, factory) {
18
18
  if(typeof exports === 'object' && typeof module === 'object')
19
- module.exports = factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"));
19
+ module.exports = factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"), require("@tsparticles/canvas-utils"));
20
20
  else if(typeof define === 'function' && define.amd)
21
- define(["@tsparticles/plugin-emitters", "@tsparticles/engine"], factory);
21
+ define(["@tsparticles/plugin-emitters", "@tsparticles/engine", "@tsparticles/canvas-utils"], factory);
22
22
  else {
23
- var a = typeof exports === 'object' ? factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine")) : factory(root["window"], root["window"]);
23
+ var a = typeof exports === 'object' ? factory(require("@tsparticles/plugin-emitters"), require("@tsparticles/engine"), require("@tsparticles/canvas-utils")) : factory(root["window"], root["window"], root["window"]);
24
24
  for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
25
25
  }
26
- })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__, __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
26
+ })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__, __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__, __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__) => {
27
27
  return /******/ (() => { // webpackBootstrap
28
28
  /******/ "use strict";
29
29
  /******/ var __webpack_modules__ = ({
30
30
 
31
- /***/ "./dist/browser/index.js"
32
- /*!*******************************!*\
33
- !*** ./dist/browser/index.js ***!
34
- \*******************************/
35
- (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
31
+ /***/ "@tsparticles/canvas-utils"
32
+ /*!***************************************************************************************************************************************************!*\
33
+ !*** external {"commonjs":"@tsparticles/canvas-utils","commonjs2":"@tsparticles/canvas-utils","amd":"@tsparticles/canvas-utils","root":"window"} ***!
34
+ \***************************************************************************************************************************************************/
35
+ (module) {
36
36
 
37
- eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadEmittersShapeCanvas: () => (/* binding */ loadEmittersShapeCanvas)\n/* harmony export */ });\nasync function loadEmittersShapeCanvas(engine) {\n engine.checkVersion(\"4.0.0-alpha.8\");\n await engine.register(async e => {\n if (!e.addEmitterShapeGenerator) {\n throw new Error(\"tsParticles emitters plugin missing or initialized after shapes\");\n }\n const {\n EmittersCanvasShapeGenerator\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_EmittersCanvasShapeGenerator_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./EmittersCanvasShapeGenerator.js */ \"./dist/browser/EmittersCanvasShapeGenerator.js\"));\n e.addEmitterShapeGenerator(\"canvas\", new EmittersCanvasShapeGenerator());\n });\n}\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-canvas/./dist/browser/index.js?\n}");
37
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_canvas_utils__;
38
38
 
39
39
  /***/ },
40
40
 
@@ -56,6 +56,16 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
56
56
 
57
57
  module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
58
58
 
59
+ /***/ },
60
+
61
+ /***/ "./dist/browser/index.js"
62
+ /*!*******************************!*\
63
+ !*** ./dist/browser/index.js ***!
64
+ \*******************************/
65
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
66
+
67
+ eval("{__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ loadEmittersShapeCanvas: () => (/* binding */ loadEmittersShapeCanvas)\n/* harmony export */ });\nasync function loadEmittersShapeCanvas(engine) {\n engine.checkVersion(\"4.0.0-beta.0\");\n await engine.register(async (e)=>{\n const { ensureEmittersPluginLoaded } = await Promise.resolve(/*! import() */).then(__webpack_require__.t.bind(__webpack_require__, /*! @tsparticles/plugin-emitters */ \"@tsparticles/plugin-emitters\", 19));\n ensureEmittersPluginLoaded(e);\n const { EmittersCanvasShapeGenerator } = await __webpack_require__.e(/*! import() */ \"dist_browser_EmittersCanvasShapeGenerator_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./EmittersCanvasShapeGenerator.js */ \"./dist/browser/EmittersCanvasShapeGenerator.js\"));\n e.addEmitterShapeGenerator?.(\"canvas\", new EmittersCanvasShapeGenerator());\n });\n}\n\n\n//# sourceURL=webpack://@tsparticles/plugin-emitters-shape-canvas/./dist/browser/index.js?\n}");
68
+
59
69
  /***/ }
60
70
 
61
71
  /******/ });
@@ -70,12 +80,6 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
70
80
  /******/ if (cachedModule !== undefined) {
71
81
  /******/ return cachedModule.exports;
72
82
  /******/ }
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
83
  /******/ // Create a new module (and put it into the cache)
80
84
  /******/ var module = __webpack_module_cache__[moduleId] = {
81
85
  /******/ // no module.id needed
@@ -84,6 +88,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
84
88
  /******/ };
85
89
  /******/
86
90
  /******/ // Execute the module function
91
+ /******/ if (!(moduleId in __webpack_modules__)) {
92
+ /******/ delete __webpack_module_cache__[moduleId];
93
+ /******/ var e = new Error("Cannot find module '" + moduleId + "'");
94
+ /******/ e.code = 'MODULE_NOT_FOUND';
95
+ /******/ throw e;
96
+ /******/ }
87
97
  /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
88
98
  /******/
89
99
  /******/ // Return the exports of the module
@@ -94,6 +104,36 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
94
104
  /******/ __webpack_require__.m = __webpack_modules__;
95
105
  /******/
96
106
  /************************************************************************/
107
+ /******/ /* webpack/runtime/create fake namespace object */
108
+ /******/ (() => {
109
+ /******/ var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);
110
+ /******/ var leafPrototypes;
111
+ /******/ // create a fake namespace object
112
+ /******/ // mode & 1: value is a module id, require it
113
+ /******/ // mode & 2: merge all properties of value into the ns
114
+ /******/ // mode & 4: return value when already ns object
115
+ /******/ // mode & 16: return value when it's Promise-like
116
+ /******/ // mode & 8|1: behave like require
117
+ /******/ __webpack_require__.t = function(value, mode) {
118
+ /******/ if(mode & 1) value = this(value);
119
+ /******/ if(mode & 8) return value;
120
+ /******/ if(typeof value === 'object' && value) {
121
+ /******/ if((mode & 4) && value.__esModule) return value;
122
+ /******/ if((mode & 16) && typeof value.then === 'function') return value;
123
+ /******/ }
124
+ /******/ var ns = Object.create(null);
125
+ /******/ __webpack_require__.r(ns);
126
+ /******/ var def = {};
127
+ /******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
128
+ /******/ for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) {
129
+ /******/ Object.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));
130
+ /******/ }
131
+ /******/ def['default'] = () => (value);
132
+ /******/ __webpack_require__.d(ns, def);
133
+ /******/ return ns;
134
+ /******/ };
135
+ /******/ })();
136
+ /******/
97
137
  /******/ /* webpack/runtime/define property getters */
98
138
  /******/ (() => {
99
139
  /******/ // define getter functions for harmony exports
@@ -128,6 +168,18 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
128
168
  /******/ };
129
169
  /******/ })();
130
170
  /******/
171
+ /******/ /* webpack/runtime/global */
172
+ /******/ (() => {
173
+ /******/ __webpack_require__.g = (function() {
174
+ /******/ if (typeof globalThis === 'object') return globalThis;
175
+ /******/ try {
176
+ /******/ return this || new Function('return this')();
177
+ /******/ } catch (e) {
178
+ /******/ if (typeof window === 'object') return window;
179
+ /******/ }
180
+ /******/ })();
181
+ /******/ })();
182
+ /******/
131
183
  /******/ /* webpack/runtime/hasOwnProperty shorthand */
132
184
  /******/ (() => {
133
185
  /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
@@ -192,8 +244,8 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_plugin_emitters__;
192
244
  /******/ /* webpack/runtime/publicPath */
193
245
  /******/ (() => {
194
246
  /******/ var scriptUrl;
195
- /******/ if (globalThis.importScripts) scriptUrl = globalThis.location + "";
196
- /******/ var document = globalThis.document;
247
+ /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
248
+ /******/ var document = __webpack_require__.g.document;
197
249
  /******/ if (!scriptUrl && document) {
198
250
  /******/ if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
199
251
  /******/ scriptUrl = document.currentScript.src;
@@ -1,2 +1,2 @@
1
- /*! For license information please see tsparticles.plugin.emitters.shape.canvas.min.js.LICENSE.txt */
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,a={303(e){e.exports=t},526(t){t.exports=e}},n={};function o(e){var t=n[e];if(void 0!==t)return t.exports;var r=n[e]={exports:{}};return a[e](r,r.exports,o),r.exports}o.m=a,o.d=(e,t)=>{for(var r in t)o.o(t,r)&&!o.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce(((t,r)=>(o.f[r](e,t),t)),[])),o.u=e=>e+".min.js",o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r={},i="@tsparticles/plugin-emitters-shape-canvas:",o.l=(e,t,a,n)=>{if(r[e])r[e].push(t);else{var s,p;if(void 0!==a)for(var l=document.getElementsByTagName("script"),c=0;c<l.length;c++){var u=l[c];if(u.getAttribute("src")==e||u.getAttribute("data-webpack")==i+a){s=u;break}}s||(p=!0,(s=document.createElement("script")).charset="utf-8",o.nc&&s.setAttribute("nonce",o.nc),s.setAttribute("data-webpack",i+a),s.src=e),r[e]=[t];var d=(t,i)=>{s.onerror=s.onload=null,clearTimeout(f);var a=r[e];if(delete r[e],s.parentNode&&s.parentNode.removeChild(s),a&&a.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)}},o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},(()=>{var e;globalThis.importScripts&&(e=globalThis.location+"");var t=globalThis.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var r=t.getElementsByTagName("script");if(r.length)for(var i=r.length-1;i>-1&&(!e||!/^http(s?):/.test(e));)e=r[i--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),o.p=e})(),(()=>{var e={346:0};o.f.j=(t,r)=>{var i=o.o(e,t)?e[t]:void 0;if(0!==i)if(i)r.push(i[2]);else{var a=new Promise(((r,a)=>i=e[t]=[r,a]));r.push(i[2]=a);var n=o.p+o.u(t),s=new Error;o.l(n,(r=>{if(o.o(e,t)&&(0!==(i=e[t])&&(e[t]=void 0),i)){var a=r&&("load"===r.type?"missing":r.type),n=r&&r.target&&r.target.src;s.message="Loading chunk "+t+" failed.\n("+a+": "+n+")",s.name="ChunkLoadError",s.type=a,s.request=n,i[1](s)}}),"chunk-"+t,t)}};var t=(t,r)=>{var i,a,[n,s,p]=r,l=0;if(n.some((t=>0!==e[t]))){for(i in s)o.o(s,i)&&(o.m[i]=s[i]);if(p)p(o)}for(t&&t(r);l<n.length;l++)a=n[l],o.o(e,a)&&e[a]&&e[a][0](),e[a]=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={};async function p(e){e.checkVersion("4.0.0-alpha.8"),await e.register((async e=>{if(!e.addEmitterShapeGenerator)throw new Error("tsParticles emitters plugin missing or initialized after shapes");const{EmittersCanvasShapeGenerator:t}=await o.e(103).then(o.bind(o,103));e.addEmitterShapeGenerator("canvas",new t)}))}return o.r(s),o.d(s,{loadEmittersShapeCanvas:()=>p}),s})()));
1
+ !function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"),require("@tsparticles/canvas-utils"));else if("function"==typeof define&&define.amd)define(["@tsparticles/plugin-emitters","@tsparticles/engine","@tsparticles/canvas-utils"],t);else{var r="object"==typeof exports?t(require("@tsparticles/plugin-emitters"),require("@tsparticles/engine"),require("@tsparticles/canvas-utils")):t(e.window,e.window,e.window);for(var i in r)("object"==typeof exports?exports:e)[i]=r[i]}}(this,(e,t,r)=>(()=>{"use strict";var i,o,n,a={425(e){e.exports=r},303(e){e.exports=t},526(t){t.exports=e}},s={};function c(e){var t=s[e];if(void 0!==t)return t.exports;var r=s[e]={exports:{}};return a[e](r,r.exports,c),r.exports}c.m=a,l=Object.getPrototypeOf?e=>Object.getPrototypeOf(e):e=>e.__proto__,c.t=function(e,t){if(1&t&&(e=this(e)),8&t||"object"==typeof e&&e&&(4&t&&e.__esModule||16&t&&"function"==typeof e.then))return e;var r=Object.create(null);c.r(r);var i={};p=p||[null,l({}),l([]),l(l)];for(var o=2&t&&e;("object"==typeof o||"function"==typeof o)&&!~p.indexOf(o);o=l(o))Object.getOwnPropertyNames(o).forEach(t=>i[t]=()=>e[t]);return i.default=()=>e,c.d(r,i),r},c.d=(e,t)=>{for(var r in t)c.o(t,r)&&!c.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},c.f={},c.e=e=>Promise.all(Object.keys(c.f).reduce((t,r)=>(c.f[r](e,t),t),[])),c.u=e=>""+e+".min.js",c.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||Function("return this")()}catch(e){if("object"==typeof window)return window}}(),c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),u={},c.l=(e,t,r,i)=>{if(u[e])return void u[e].push(t);if(void 0!==r)for(var o,n,a=document.getElementsByTagName("script"),s=0;s<a.length;s++){var p=a[s];if(p.getAttribute("src")==e||p.getAttribute("data-webpack")=="@tsparticles/plugin-emitters-shape-canvas:"+r){o=p;break}}o||(n=!0,(o=document.createElement("script")).charset="utf-8",c.nc&&o.setAttribute("nonce",c.nc),o.setAttribute("data-webpack","@tsparticles/plugin-emitters-shape-canvas:"+r),o.src=e),u[e]=[t];var l=(t,r)=>{o.onerror=o.onload=null,clearTimeout(f);var i=u[e];if(delete u[e],o.parentNode&&o.parentNode.removeChild(o),i&&i.forEach(e=>e(r)),t)return t(r)},f=setTimeout(l.bind(null,void 0,{type:"timeout",target:o}),12e4);o.onerror=l.bind(null,o.onerror),o.onload=l.bind(null,o.onload),n&&document.head.appendChild(o)},c.r=e=>{"u">typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},c.g.importScripts&&(f=c.g.location+"");var p,l,u,f,d=c.g.document;if(!f&&d&&(d.currentScript&&"SCRIPT"===d.currentScript.tagName.toUpperCase()&&(f=d.currentScript.src),!f)){var b=d.getElementsByTagName("script");if(b.length)for(var h=b.length-1;h>-1&&(!f||!/^http(s?):/.test(f));)f=b[h--].src}if(!f)throw Error("Automatic publicPath is not supported in this browser");c.p=f=f.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),i={346:0},c.f.j=(e,t)=>{var r=c.o(i,e)?i[e]:void 0;if(0!==r)if(r)t.push(r[2]);else{var o=new Promise((t,o)=>r=i[e]=[t,o]);t.push(r[2]=o);var n=c.p+c.u(e),a=Error();c.l(n,t=>{if(c.o(i,e)&&(0!==(r=i[e])&&(i[e]=void 0),r)){var o=t&&("load"===t.type?"missing":t.type),n=t&&t.target&&t.target.src;a.message="Loading chunk "+e+` failed.
2
+ (`+o+": "+n+")",a.name="ChunkLoadError",a.type=o,a.request=n,r[1](a)}},"chunk-"+e,e)}},o=(e,t)=>{var r,o,[n,a,s]=t,p=0;if(n.some(e=>0!==i[e])){for(r in a)c.o(a,r)&&(c.m[r]=a[r]);s&&s(c)}for(e&&e(t);p<n.length;p++)o=n[p],c.o(i,o)&&i[o]&&i[o][0](),i[o]=0},(n=this.webpackChunk_tsparticles_plugin_emitters_shape_canvas=this.webpackChunk_tsparticles_plugin_emitters_shape_canvas||[]).forEach(o.bind(null,0)),n.push=o.bind(null,n.push.bind(n));var m={};async function g(e){e.checkVersion("4.0.0-beta.0"),await e.register(async e=>{let{ensureEmittersPluginLoaded:t}=await Promise.resolve().then(c.t.bind(c,526,19));t(e);let{EmittersCanvasShapeGenerator:r}=await c.e(373).then(c.bind(c,373));e.addEmitterShapeGenerator?.("canvas",new r)})}return c.r(m),c.d(m,{loadEmittersShapeCanvas:()=>g}),m})());
@@ -1,12 +1,13 @@
1
+ import { type Container, type ICoordinates, type IDimension, type IRgba } from "@tsparticles/engine";
1
2
  import { EmitterShapeBase, type IRandomPositionData } from "@tsparticles/plugin-emitters";
2
- import { type ICoordinates, type IDimension, type IRgba } from "@tsparticles/engine";
3
3
  import type { CanvasPixelData } from "./types.js";
4
4
  import type { EmittersCanvasShapeOptions } from "./Options/Classes/EmittersCanvasShapeOptions.js";
5
5
  export declare class EmittersCanvasShape extends EmitterShapeBase<EmittersCanvasShapeOptions> {
6
6
  filter: (pixel: IRgba) => boolean;
7
7
  pixelData: CanvasPixelData;
8
8
  scale: number;
9
- constructor(position: ICoordinates, size: IDimension, fill: boolean, options: EmittersCanvasShapeOptions);
9
+ private readonly _container;
10
+ constructor(container: Container, position: ICoordinates, size: IDimension, fill: boolean, options: EmittersCanvasShapeOptions);
10
11
  init(): Promise<void>;
11
12
  randomPosition(): IRandomPositionData | null;
12
13
  resize(position: ICoordinates, size: IDimension): void;
@@ -1,6 +1,6 @@
1
- import { type ICoordinates, type IDimension } from "@tsparticles/engine";
1
+ import { type Container, type ICoordinates, type IDimension } from "@tsparticles/engine";
2
2
  import type { IEmitterShape, IEmitterShapeGenerator } from "@tsparticles/plugin-emitters";
3
3
  import type { IEmittersCanvasShapeOptions } from "./Options/Interfaces/IEmittersCanvasShapeOptions.js";
4
4
  export declare class EmittersCanvasShapeGenerator implements IEmitterShapeGenerator<IEmittersCanvasShapeOptions> {
5
- generate(position: ICoordinates, size: IDimension, fill: boolean, options: IEmittersCanvasShapeOptions): IEmitterShape;
5
+ generate(container: Container, position: ICoordinates, size: IDimension, fill: boolean, options: IEmittersCanvasShapeOptions): IEmitterShape;
6
6
  }
@@ -1,7 +1,2 @@
1
- export interface ITextFontOptions {
2
- family: string;
3
- size: string | number;
4
- style: string;
5
- variant: string;
6
- weight: string;
7
- }
1
+ import type { ITextDataFontOptions } from "@tsparticles/canvas-utils";
2
+ export type ITextFontOptions = ITextDataFontOptions;
@@ -1,4 +1,2 @@
1
- export interface ITextLinesOptions {
2
- separator: string;
3
- spacing: number;
4
- }
1
+ import type { ITextDataLinesOptions } from "@tsparticles/canvas-utils";
2
+ export type ITextLinesOptions = ITextDataLinesOptions;
@@ -1,8 +1,7 @@
1
+ import type { ITextDataOptions } from "@tsparticles/canvas-utils";
1
2
  import type { ITextFontOptions } from "./ITextFontOptions.js";
2
3
  import type { ITextLinesOptions } from "./ITextLinesOptions.js";
3
- export interface ITextOptions {
4
- color: string;
4
+ export interface ITextOptions extends ITextDataOptions {
5
5
  font: ITextFontOptions;
6
6
  lines: ITextLinesOptions;
7
- text: string;
8
7
  }
@@ -4,23 +4,28 @@
4
4
  if (v !== undefined) module.exports = v;
5
5
  }
6
6
  else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "@tsparticles/plugin-emitters", "@tsparticles/engine", "./utils.js"], factory);
7
+ define(["require", "exports", "@tsparticles/engine", "@tsparticles/plugin-emitters", "@tsparticles/canvas-utils"], factory);
8
8
  }
9
9
  })(function (require, exports) {
10
10
  "use strict";
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EmittersCanvasShape = void 0;
13
- const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
14
13
  const engine_1 = require("@tsparticles/engine");
15
- const utils_js_1 = require("./utils.js");
14
+ const plugin_emitters_1 = require("@tsparticles/plugin-emitters");
15
+ const canvas_utils_1 = require("@tsparticles/canvas-utils");
16
16
  const maxRetries = 100;
17
17
  class EmittersCanvasShape extends plugin_emitters_1.EmitterShapeBase {
18
- constructor(position, size, fill, options) {
18
+ filter;
19
+ pixelData;
20
+ scale;
21
+ _container;
22
+ constructor(container, position, size, fill, options) {
19
23
  super(position, size, fill, options);
24
+ this._container = container;
20
25
  const filter = options.filter, minAlpha = 0;
21
26
  let filterFunc = (pixel) => pixel.a > minAlpha;
22
27
  if ((0, engine_1.isString)(filter)) {
23
- if (Object.hasOwn(globalThis, filter)) {
28
+ if (filter in globalThis) {
24
29
  const wndFilter = globalThis[filter];
25
30
  if ((0, engine_1.isFunction)(wndFilter)) {
26
31
  filterFunc = wndFilter;
@@ -46,21 +51,21 @@
46
51
  if (!url) {
47
52
  return;
48
53
  }
49
- pixelData = await (0, utils_js_1.getImageData)(url, offset);
54
+ pixelData = await (0, canvas_utils_1.getImageData)(url, offset, this._container.canvas.settings);
50
55
  }
51
56
  else if (element ?? selector) {
52
57
  const canvas = element ?? (selector && (0, engine_1.safeDocument)().querySelector(selector));
53
58
  if (!canvas) {
54
59
  return;
55
60
  }
56
- const context = canvas.getContext("2d");
61
+ const context = canvas.getContext("2d", this._container.canvas.settings);
57
62
  if (!context) {
58
63
  return;
59
64
  }
60
- pixelData = (0, utils_js_1.getCanvasImageData)(context, canvas, offset);
65
+ pixelData = (0, canvas_utils_1.getCanvasImageData)(context, canvas, offset);
61
66
  }
62
67
  else {
63
- const data = (0, utils_js_1.getTextData)(text, offset, this.fill);
68
+ const data = (0, canvas_utils_1.getTextData)(text, offset, this.fill, this._container.canvas.settings);
64
69
  if ((0, engine_1.isNull)(data)) {
65
70
  return;
66
71
  }
@@ -13,10 +13,10 @@
13
13
  const EmittersCanvasShape_js_1 = require("./EmittersCanvasShape.js");
14
14
  const EmittersCanvasShapeOptions_js_1 = require("./Options/Classes/EmittersCanvasShapeOptions.js");
15
15
  class EmittersCanvasShapeGenerator {
16
- generate(position, size, fill, options) {
16
+ generate(container, position, size, fill, options) {
17
17
  const shapeOptions = new EmittersCanvasShapeOptions_js_1.EmittersCanvasShapeOptions();
18
18
  shapeOptions.load(options);
19
- return new EmittersCanvasShape_js_1.EmittersCanvasShape(position, size, fill, shapeOptions);
19
+ return new EmittersCanvasShape_js_1.EmittersCanvasShape(container, position, size, fill, shapeOptions);
20
20
  }
21
21
  }
22
22
  exports.EmittersCanvasShapeGenerator = EmittersCanvasShapeGenerator;
@@ -15,6 +15,13 @@
15
15
  const TextOptions_js_1 = require("./TextOptions.js");
16
16
  const minAlpha = 0;
17
17
  class EmittersCanvasShapeOptions {
18
+ element;
19
+ filter;
20
+ image;
21
+ pixels;
22
+ scale;
23
+ selector;
24
+ text;
18
25
  constructor() {
19
26
  this.filter = (pixel) => pixel.a > minAlpha;
20
27
  this.pixels = new PixelsOptions_js_1.PixelsOptions();
@@ -12,6 +12,7 @@
12
12
  exports.PixelsOptions = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  class PixelsOptions {
15
+ offset;
15
16
  constructor() {
16
17
  this.offset = 4;
17
18
  }
@@ -12,6 +12,11 @@
12
12
  exports.TextFontOptions = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  class TextFontOptions {
15
+ family;
16
+ size;
17
+ style;
18
+ variant;
19
+ weight;
15
20
  constructor() {
16
21
  this.family = "Verdana";
17
22
  this.size = 32;
@@ -12,6 +12,8 @@
12
12
  exports.TextLinesOptions = void 0;
13
13
  const engine_1 = require("@tsparticles/engine");
14
14
  class TextLinesOptions {
15
+ separator;
16
+ spacing;
15
17
  constructor() {
16
18
  this.separator = "\n";
17
19
  this.spacing = 0;
@@ -14,6 +14,10 @@
14
14
  const TextFontOptions_js_1 = require("./TextFontOptions.js");
15
15
  const TextLinesOptions_js_1 = require("./TextLinesOptions.js");
16
16
  class TextOptions {
17
+ color;
18
+ font;
19
+ lines;
20
+ text;
17
21
  constructor() {
18
22
  this.color = "#000000";
19
23
  this.font = new TextFontOptions_js_1.TextFontOptions();
package/umd/index.js CHANGED
@@ -45,13 +45,12 @@ var __importStar = (this && this.__importStar) || (function () {
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.loadEmittersShapeCanvas = loadEmittersShapeCanvas;
47
47
  async function loadEmittersShapeCanvas(engine) {
48
- engine.checkVersion("4.0.0-alpha.8");
48
+ engine.checkVersion("4.0.0-beta.0");
49
49
  await engine.register(async (e) => {
50
- if (!e.addEmitterShapeGenerator) {
51
- throw new Error("tsParticles emitters plugin missing or initialized after shapes");
52
- }
53
- const { 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));
54
- e.addEmitterShapeGenerator("canvas", new EmittersCanvasShapeGenerator());
50
+ const { ensureEmittersPluginLoaded } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("@tsparticles/plugin-emitters"))) : new Promise((resolve_1, reject_1) => { require(["@tsparticles/plugin-emitters"], resolve_1, reject_1); }).then(__importStar));
51
+ ensureEmittersPluginLoaded(e);
52
+ const { EmittersCanvasShapeGenerator } = await (__syncRequire ? Promise.resolve().then(() => __importStar(require("./EmittersCanvasShapeGenerator.js"))) : new Promise((resolve_2, reject_2) => { require(["./EmittersCanvasShapeGenerator.js"], resolve_2, reject_2); }).then(__importStar));
53
+ e.addEmitterShapeGenerator?.("canvas", new EmittersCanvasShapeGenerator());
55
54
  });
56
55
  }
57
56
  });
package/103.min.js DELETED
@@ -1,2 +0,0 @@
1
- /*! For license information please see 103.min.js.LICENSE.txt */
2
- (this.webpackChunk_tsparticles_plugin_emitters_shape_canvas=this.webpackChunk_tsparticles_plugin_emitters_shape_canvas||[]).push([[103],{103(t,e,i){i.d(e,{EmittersCanvasShapeGenerator:()=>g});var s=i(526),o=i(303);const a=0,n=0;function l(t,e,i,s=!0){const o=t.getImageData(a,n,e.width,e.height).data;s&&t.clearRect(a,n,e.width,e.height);const l=[];for(let t=0;t<o.length;t+=i){const s=t/i,a={x:s%e.width,y:Math.floor(s/e.width)};l[a.y]??=[];const n={r:0,g:1,b:2,a:3},r=255,h=l[a.y];h&&(h[a.x]={r:o[t+n.r]??0,g:o[t+n.g]??0,b:o[t+n.b]??0,a:(o[t+n.a]??1)/r})}return{pixels:l,width:Math.min(...l.map((t=>t.length))),height:l.length}}class r extends s.EmitterShapeBase{constructor(t,e,i,s){super(t,e,i,s);const a=s.filter;let n=t=>t.a>0;if((0,o.isString)(a)){if(Object.hasOwn(globalThis,a)){const t=globalThis[a];(0,o.isFunction)(t)&&(n=t)}}else n=a;this.filter=n,this.scale=s.scale,this.pixelData={pixels:[],height:0,width:0}}async init(){let t;const e=this.options,i=e.selector,s=e.pixels,r=e.image,h=e.element,c=e.text,f=s.offset;if(r){const e=r.src;if(!e)return;t=await function(t,e){const i=new Image;i.crossOrigin="Anonymous";const s=new Promise(((t,s)=>{i.onerror=s,i.onload=()=>{const r=(0,o.safeDocument)().createElement("canvas");r.width=i.width,r.height=i.height;const h=r.getContext("2d");h?(h.drawImage(i,a,n,i.width,i.height,a,n,r.width,r.height),t(l(h,r,e))):s(new Error("Could not get canvas context"))}}));return i.src=t,s}(e,f)}else if(h??i){const e=h??(i&&(0,o.safeDocument)().querySelector(i));if(!e)return;const s=e.getContext("2d");if(!s)return;t=l(s,e,f)}else{const e=function(t,e,i){const s=(0,o.safeDocument)().createElement("canvas"),n=s.getContext("2d"),{font:r,text:h,lines:c,color:f}=t;if(!h||!n)return;const u=h.split(c.separator),d=(0,o.isNumber)(r.size)?`${r.size.toString()}px`:r.size,g=[];let x=0,p=0;for(const t of u){n.font=`${r.style||""} ${r.variant||""} ${r.weight||""} ${d} ${r.family}`;const e=n.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+c.spacing,g.push(i)}s.width=x,s.height=p;let m=0;for(const t of g)n.font=`${r.style||""} ${r.variant||""} ${r.weight||""} ${d} ${r.family}`,i?(n.fillStyle=f,n.fillText(t.text,a,m+t.measure.actualBoundingBoxAscent)):(n.strokeStyle=f,n.strokeText(t.text,a,m+t.measure.actualBoundingBoxAscent)),m+=t.height+c.spacing;return l(n,s,e)}(c,f,this.fill);if((0,o.isNull)(e))return;t=e}this.pixelData=t}randomPosition(){const{height:t,width:e}=this.pixelData,i=this.pixelData,s=this.position,a=this.scale,n=s.x-e*a*o.half,l=s.y-t*a*o.half;for(let s=0;s<100;s++){const s=Math.floor((0,o.getRandom)()*e*t),r={x:s%e,y:Math.floor(s/e)},h=i.pixels[r.y];if(!h)continue;const c=h[r.x];if(!c)continue;if(this.filter(c))return{position:{x:r.x*a+n,y:r.y*a+l},color:{...c},opacity:c.a}}return null}resize(t,e){super.resize(t,e)}}class h{constructor(){this.offset=4}load(t){(0,o.isNull)(t)||void 0!==t.offset&&(this.offset=t.offset)}}class c{constructor(){this.family="Verdana",this.size=32,this.style="",this.variant="",this.weight=""}load(t){(0,o.isNull)(t)||(void 0!==t.family&&(this.family=t.family),void 0!==t.size&&(this.size=t.size),void 0!==t.style&&(this.style=t.style),void 0!==t.variant&&(this.variant=t.variant),void 0!==t.weight&&(this.weight=t.weight))}}class f{constructor(){this.separator="\n",this.spacing=0}load(t){(0,o.isNull)(t)||(void 0!==t.separator&&(this.separator=t.separator),void 0!==t.spacing&&(this.spacing=t.spacing))}}class u{constructor(){this.color="#000000",this.font=new c,this.lines=new f,this.text=""}load(t){(0,o.isNull)(t)||(void 0!==t.color&&(this.color=t.color),this.font.load(t.font),this.lines.load(t.lines),void 0!==t.text&&(this.text=t.text))}}class d{constructor(){this.filter=t=>t.a>0,this.pixels=new h,this.scale=1,this.selector="",this.text=new u}load(t){(0,o.isNull)(t)||(void 0!==t.element&&(this.element=t.element),void 0!==t.filter&&(this.filter=t.filter),this.pixels.load(t.pixels),void 0!==t.scale&&(this.scale=t.scale),void 0!==t.selector&&(this.selector=t.selector),void 0!==t.image&&(this.image=t.image),this.text.load(t.text))}}class g{generate(t,e,i,s){const o=new d;return o.load(s),new r(t,e,i,o)}}}}]);
@@ -1 +0,0 @@
1
- /*! tsParticles Emitters Shape Canvas Plugin v4.0.0-alpha.8 by Matteo Bruni */
package/browser/utils.js DELETED
@@ -1,96 +0,0 @@
1
- import { isNumber, safeDocument } from "@tsparticles/engine";
2
- const origin = {
3
- x: 0,
4
- y: 0,
5
- }, minWidth = 0, defaultRgbValue = 0, defaultAlphaValue = 1;
6
- export function getCanvasImageData(ctx, size, offset, clear = true) {
7
- const imageData = ctx.getImageData(origin.x, origin.y, size.width, size.height).data;
8
- if (clear) {
9
- ctx.clearRect(origin.x, origin.y, size.width, size.height);
10
- }
11
- const pixels = [];
12
- for (let i = 0; i < imageData.length; i += offset) {
13
- const idx = i / offset, pos = {
14
- x: idx % size.width,
15
- y: Math.floor(idx / size.width),
16
- };
17
- pixels[pos.y] ??= [];
18
- const indexesOffset = {
19
- r: 0,
20
- g: 1,
21
- b: 2,
22
- a: 3,
23
- }, alphaFactor = 255, row = pixels[pos.y];
24
- if (!row) {
25
- continue;
26
- }
27
- row[pos.x] = {
28
- r: imageData[i + indexesOffset.r] ?? defaultRgbValue,
29
- g: imageData[i + indexesOffset.g] ?? defaultRgbValue,
30
- b: imageData[i + indexesOffset.b] ?? defaultRgbValue,
31
- a: (imageData[i + indexesOffset.a] ?? defaultAlphaValue) / alphaFactor,
32
- };
33
- }
34
- return {
35
- pixels,
36
- width: Math.min(...pixels.map(row => row.length)),
37
- height: pixels.length,
38
- };
39
- }
40
- export function getImageData(src, offset) {
41
- const image = new Image();
42
- image.crossOrigin = "Anonymous";
43
- const p = new Promise((resolve, reject) => {
44
- image.onerror = reject;
45
- image.onload = () => {
46
- const canvas = safeDocument().createElement("canvas");
47
- canvas.width = image.width;
48
- canvas.height = image.height;
49
- const context = canvas.getContext("2d");
50
- if (!context) {
51
- reject(new Error("Could not get canvas context"));
52
- return;
53
- }
54
- context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
55
- resolve(getCanvasImageData(context, canvas, offset));
56
- };
57
- });
58
- image.src = src;
59
- return p;
60
- }
61
- export function getTextData(textOptions, offset, fill) {
62
- const canvas = safeDocument().createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
63
- if (!text || !context) {
64
- return;
65
- }
66
- const lines = text.split(linesOptions.separator), fontSize = isNumber(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
67
- let maxWidth = 0, totalHeight = 0;
68
- for (const line of lines) {
69
- context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
70
- const measure = context.measureText(line), lineData = {
71
- measure,
72
- text: line,
73
- height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
74
- width: measure.width,
75
- };
76
- maxWidth = Math.max(maxWidth || minWidth, lineData.width);
77
- totalHeight += lineData.height + linesOptions.spacing;
78
- linesData.push(lineData);
79
- }
80
- canvas.width = maxWidth;
81
- canvas.height = totalHeight;
82
- let currentHeight = 0;
83
- for (const line of linesData) {
84
- context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
85
- if (fill) {
86
- context.fillStyle = color;
87
- context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
88
- }
89
- else {
90
- context.strokeStyle = color;
91
- context.strokeText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
92
- }
93
- currentHeight += line.height + linesOptions.spacing;
94
- }
95
- return getCanvasImageData(context, canvas, offset);
96
- }
package/cjs/utils.js DELETED
@@ -1,96 +0,0 @@
1
- import { isNumber, safeDocument } from "@tsparticles/engine";
2
- const origin = {
3
- x: 0,
4
- y: 0,
5
- }, minWidth = 0, defaultRgbValue = 0, defaultAlphaValue = 1;
6
- export function getCanvasImageData(ctx, size, offset, clear = true) {
7
- const imageData = ctx.getImageData(origin.x, origin.y, size.width, size.height).data;
8
- if (clear) {
9
- ctx.clearRect(origin.x, origin.y, size.width, size.height);
10
- }
11
- const pixels = [];
12
- for (let i = 0; i < imageData.length; i += offset) {
13
- const idx = i / offset, pos = {
14
- x: idx % size.width,
15
- y: Math.floor(idx / size.width),
16
- };
17
- pixels[pos.y] ??= [];
18
- const indexesOffset = {
19
- r: 0,
20
- g: 1,
21
- b: 2,
22
- a: 3,
23
- }, alphaFactor = 255, row = pixels[pos.y];
24
- if (!row) {
25
- continue;
26
- }
27
- row[pos.x] = {
28
- r: imageData[i + indexesOffset.r] ?? defaultRgbValue,
29
- g: imageData[i + indexesOffset.g] ?? defaultRgbValue,
30
- b: imageData[i + indexesOffset.b] ?? defaultRgbValue,
31
- a: (imageData[i + indexesOffset.a] ?? defaultAlphaValue) / alphaFactor,
32
- };
33
- }
34
- return {
35
- pixels,
36
- width: Math.min(...pixels.map(row => row.length)),
37
- height: pixels.length,
38
- };
39
- }
40
- export function getImageData(src, offset) {
41
- const image = new Image();
42
- image.crossOrigin = "Anonymous";
43
- const p = new Promise((resolve, reject) => {
44
- image.onerror = reject;
45
- image.onload = () => {
46
- const canvas = safeDocument().createElement("canvas");
47
- canvas.width = image.width;
48
- canvas.height = image.height;
49
- const context = canvas.getContext("2d");
50
- if (!context) {
51
- reject(new Error("Could not get canvas context"));
52
- return;
53
- }
54
- context.drawImage(image, origin.x, origin.y, image.width, image.height, origin.x, origin.y, canvas.width, canvas.height);
55
- resolve(getCanvasImageData(context, canvas, offset));
56
- };
57
- });
58
- image.src = src;
59
- return p;
60
- }
61
- export function getTextData(textOptions, offset, fill) {
62
- const canvas = safeDocument().createElement("canvas"), context = canvas.getContext("2d"), { font, text, lines: linesOptions, color } = textOptions;
63
- if (!text || !context) {
64
- return;
65
- }
66
- const lines = text.split(linesOptions.separator), fontSize = isNumber(font.size) ? `${font.size.toString()}px` : font.size, linesData = [];
67
- let maxWidth = 0, totalHeight = 0;
68
- for (const line of lines) {
69
- context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
70
- const measure = context.measureText(line), lineData = {
71
- measure,
72
- text: line,
73
- height: measure.actualBoundingBoxAscent + measure.actualBoundingBoxDescent,
74
- width: measure.width,
75
- };
76
- maxWidth = Math.max(maxWidth || minWidth, lineData.width);
77
- totalHeight += lineData.height + linesOptions.spacing;
78
- linesData.push(lineData);
79
- }
80
- canvas.width = maxWidth;
81
- canvas.height = totalHeight;
82
- let currentHeight = 0;
83
- for (const line of linesData) {
84
- context.font = `${font.style || ""} ${font.variant || ""} ${font.weight || ""} ${fontSize} ${font.family}`;
85
- if (fill) {
86
- context.fillStyle = color;
87
- context.fillText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
88
- }
89
- else {
90
- context.strokeStyle = color;
91
- context.strokeText(line.text, origin.x, currentHeight + line.measure.actualBoundingBoxAscent);
92
- }
93
- currentHeight += line.height + linesOptions.spacing;
94
- }
95
- return getCanvasImageData(context, canvas, offset);
96
- }