@tsparticles/shape-image 3.0.3 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/21.min.js +2 -0
  2. package/21.min.js.LICENSE.txt +1 -0
  3. package/618.min.js +2 -0
  4. package/618.min.js.LICENSE.txt +1 -0
  5. package/623.min.js +2 -0
  6. package/623.min.js.LICENSE.txt +1 -0
  7. package/browser/GifUtils/ByteStream.js +13 -9
  8. package/browser/GifUtils/Utils.js +113 -10
  9. package/browser/ImageDrawer.js +44 -109
  10. package/browser/ImagePreloader.js +3 -2
  11. package/browser/Utils.js +6 -23
  12. package/browser/index.js +12 -5
  13. package/cjs/GifUtils/ByteStream.js +13 -9
  14. package/cjs/GifUtils/Utils.js +139 -11
  15. package/cjs/ImageDrawer.js +67 -109
  16. package/cjs/ImagePreloader.js +3 -2
  17. package/cjs/Utils.js +7 -25
  18. package/cjs/index.js +36 -6
  19. package/dist_browser_GifUtils_Utils_js.js +50 -0
  20. package/dist_browser_ImageDrawer_js.js +30 -0
  21. package/dist_browser_ImagePreloader_js.js +40 -0
  22. package/esm/GifUtils/ByteStream.js +13 -9
  23. package/esm/GifUtils/Utils.js +113 -10
  24. package/esm/ImageDrawer.js +44 -109
  25. package/esm/ImagePreloader.js +3 -2
  26. package/esm/Utils.js +6 -23
  27. package/esm/index.js +12 -5
  28. package/package.json +2 -2
  29. package/report.html +3 -3
  30. package/tsparticles.shape.image.js +251 -862
  31. package/tsparticles.shape.image.min.js +1 -1
  32. package/tsparticles.shape.image.min.js.LICENSE.txt +1 -1
  33. package/types/GifUtils/Utils.d.ts +4 -0
  34. package/types/ImageDrawer.d.ts +3 -3
  35. package/types/ImagePreloader.d.ts +1 -1
  36. package/types/Utils.d.ts +0 -1
  37. package/umd/GifUtils/ByteStream.js +13 -9
  38. package/umd/GifUtils/Utils.js +140 -11
  39. package/umd/ImageDrawer.js +69 -110
  40. package/umd/ImagePreloader.js +3 -2
  41. package/umd/Utils.js +8 -26
  42. package/umd/index.js +38 -7
@@ -4,7 +4,15 @@
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
- * v3.0.3
7
+ * v3.2.0
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/).
8
16
  */
9
17
  (function webpackUniversalModuleDefinition(root, factory) {
10
18
  if(typeof exports === 'object' && typeof module === 'object')
@@ -15,15 +23,38 @@
15
23
  var a = typeof exports === 'object' ? factory(require("@tsparticles/engine")) : factory(root["window"]);
16
24
  for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
17
25
  }
18
- })(this, (__WEBPACK_EXTERNAL_MODULE__533__) => {
26
+ })(this, (__WEBPACK_EXTERNAL_MODULE__tsparticles_engine__) => {
19
27
  return /******/ (() => { // webpackBootstrap
20
28
  /******/ "use strict";
21
29
  /******/ var __webpack_modules__ = ({
22
30
 
23
- /***/ 533:
31
+ /***/ "./dist/browser/Utils.js":
32
+ /*!*******************************!*\
33
+ !*** ./dist/browser/Utils.js ***!
34
+ \*******************************/
35
+ /***/ ((__unused_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 */ downloadSvgImage: () => (/* binding */ downloadSvgImage),\n/* harmony export */ loadImage: () => (/* binding */ loadImage),\n/* harmony export */ replaceImageColor: () => (/* binding */ replaceImageColor)\n/* harmony export */ });\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\nconst stringStart = 0,\n defaultOpacity = 1;\nconst currentColorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\\((-?\\d+%?[,\\s]+){2,3}\\s*[\\d.]+%?\\))|currentcolor/gi;\nfunction replaceColorSvg(imageShape, color, opacity) {\n const {\n svgData\n } = imageShape;\n if (!svgData) {\n return \"\";\n }\n const colorStyle = (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getStyleFromHsl)(color, opacity);\n if (svgData.includes(\"fill\")) {\n return svgData.replace(currentColorRegex, () => colorStyle);\n }\n const preFillIndex = svgData.indexOf(\">\");\n return `${svgData.substring(stringStart, preFillIndex)} fill=\"${colorStyle}\"${svgData.substring(preFillIndex)}`;\n}\nasync function loadImage(image) {\n return new Promise(resolve => {\n image.loading = true;\n const img = new Image();\n image.element = img;\n img.addEventListener(\"load\", () => {\n image.loading = false;\n resolve();\n });\n img.addEventListener(\"error\", () => {\n image.element = undefined;\n image.error = true;\n image.loading = false;\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLogger)().error(`${_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} loading image: ${image.source}`);\n resolve();\n });\n img.src = image.source;\n });\n}\nasync function downloadSvgImage(image) {\n if (image.type !== \"svg\") {\n await loadImage(image);\n return;\n }\n image.loading = true;\n const response = await fetch(image.source);\n if (!response.ok) {\n (0,_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.getLogger)().error(`${_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} Image not found`);\n image.error = true;\n } else {\n image.svgData = await response.text();\n }\n image.loading = false;\n}\nfunction replaceImageColor(image, imageData, color, particle) {\n const svgColoredData = replaceColorSvg(image, color, particle.opacity?.value ?? defaultOpacity),\n imageRes = {\n color,\n gif: imageData.gif,\n data: {\n ...image,\n svgData: svgColoredData\n },\n loaded: false,\n ratio: imageData.width / imageData.height,\n replaceColor: imageData.replaceColor,\n source: imageData.src\n };\n return new Promise(resolve => {\n const svg = new Blob([svgColoredData], {\n type: \"image/svg+xml\"\n }),\n domUrl = URL || window.URL || window.webkitURL || window,\n url = domUrl.createObjectURL(svg),\n img = new Image();\n img.addEventListener(\"load\", () => {\n imageRes.loaded = true;\n imageRes.element = img;\n resolve(imageRes);\n domUrl.revokeObjectURL(url);\n });\n const errorHandler = async () => {\n domUrl.revokeObjectURL(url);\n const img2 = {\n ...image,\n error: false,\n loading: true\n };\n await loadImage(img2);\n imageRes.loaded = true;\n imageRes.element = img2.element;\n resolve(imageRes);\n };\n img.addEventListener(\"error\", () => void errorHandler());\n img.src = url;\n });\n}\n\n//# sourceURL=webpack://@tsparticles/shape-image/./dist/browser/Utils.js?");
38
+
39
+ /***/ }),
40
+
41
+ /***/ "./dist/browser/index.js":
42
+ /*!*******************************!*\
43
+ !*** ./dist/browser/index.js ***!
44
+ \*******************************/
45
+ /***/ ((__unused_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 */ loadImageShape: () => (/* binding */ loadImageShape)\n/* harmony export */ });\n/* harmony import */ var _Utils_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Utils.js */ \"./dist/browser/Utils.js\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @tsparticles/engine */ \"@tsparticles/engine\");\n/* harmony import */ var _tsparticles_engine__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__);\n\n\nconst extLength = 3;\nfunction addLoadImageToEngine(engine) {\n if (engine.loadImage) {\n return;\n }\n engine.loadImage = async data => {\n if (!data.name && !data.src) {\n throw new Error(`${_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} no image source provided`);\n }\n if (!engine.images) {\n engine.images = [];\n }\n if (engine.images.find(t => t.name === data.name || t.source === data.src)) {\n return;\n }\n try {\n const image = {\n gif: data.gif ?? false,\n name: data.name ?? data.src,\n source: data.src,\n type: data.src.substring(data.src.length - extLength),\n error: false,\n loading: true,\n replaceColor: data.replaceColor,\n ratio: data.width && data.height ? data.width / data.height : undefined\n };\n engine.images.push(image);\n let imageFunc;\n if (data.gif) {\n const {\n loadGifImage\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_GifUtils_Utils_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./GifUtils/Utils.js */ \"./dist/browser/GifUtils/Utils.js\"));\n imageFunc = loadGifImage;\n } else {\n imageFunc = data.replaceColor ? _Utils_js__WEBPACK_IMPORTED_MODULE_1__.downloadSvgImage : _Utils_js__WEBPACK_IMPORTED_MODULE_1__.loadImage;\n }\n await imageFunc(image);\n } catch {\n throw new Error(`${_tsparticles_engine__WEBPACK_IMPORTED_MODULE_0__.errorPrefix} ${data.name ?? data.src} not found`);\n }\n };\n}\nasync function loadImageShape(engine, refresh = true) {\n addLoadImageToEngine(engine);\n const {\n ImagePreloaderPlugin\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ImagePreloader_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ImagePreloader.js */ \"./dist/browser/ImagePreloader.js\")),\n {\n ImageDrawer\n } = await __webpack_require__.e(/*! import() */ \"dist_browser_ImageDrawer_js\").then(__webpack_require__.bind(__webpack_require__, /*! ./ImageDrawer.js */ \"./dist/browser/ImageDrawer.js\"));\n const preloader = new ImagePreloaderPlugin(engine);\n await engine.addPlugin(preloader, refresh);\n await engine.addShape([\"image\", \"images\"], new ImageDrawer(engine), refresh);\n}\n\n//# sourceURL=webpack://@tsparticles/shape-image/./dist/browser/index.js?");
48
+
49
+ /***/ }),
50
+
51
+ /***/ "@tsparticles/engine":
52
+ /*!*********************************************************************************************************************************!*\
53
+ !*** external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"} ***!
54
+ \*********************************************************************************************************************************/
24
55
  /***/ ((module) => {
25
56
 
26
- module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
57
+ module.exports = __WEBPACK_EXTERNAL_MODULE__tsparticles_engine__;
27
58
 
28
59
  /***/ })
29
60
 
@@ -53,7 +84,22 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
53
84
  /******/ return module.exports;
54
85
  /******/ }
55
86
  /******/
87
+ /******/ // expose the modules object (__webpack_modules__)
88
+ /******/ __webpack_require__.m = __webpack_modules__;
89
+ /******/
56
90
  /************************************************************************/
91
+ /******/ /* webpack/runtime/compat get default export */
92
+ /******/ (() => {
93
+ /******/ // getDefaultExport function for compatibility with non-harmony modules
94
+ /******/ __webpack_require__.n = (module) => {
95
+ /******/ var getter = module && module.__esModule ?
96
+ /******/ () => (module['default']) :
97
+ /******/ () => (module);
98
+ /******/ __webpack_require__.d(getter, { a: getter });
99
+ /******/ return getter;
100
+ /******/ };
101
+ /******/ })();
102
+ /******/
57
103
  /******/ /* webpack/runtime/define property getters */
58
104
  /******/ (() => {
59
105
  /******/ // define getter functions for harmony exports
@@ -66,11 +112,91 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
66
112
  /******/ };
67
113
  /******/ })();
68
114
  /******/
115
+ /******/ /* webpack/runtime/ensure chunk */
116
+ /******/ (() => {
117
+ /******/ __webpack_require__.f = {};
118
+ /******/ // This file contains only the entry chunk.
119
+ /******/ // The chunk loading function for additional chunks
120
+ /******/ __webpack_require__.e = (chunkId) => {
121
+ /******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
122
+ /******/ __webpack_require__.f[key](chunkId, promises);
123
+ /******/ return promises;
124
+ /******/ }, []));
125
+ /******/ };
126
+ /******/ })();
127
+ /******/
128
+ /******/ /* webpack/runtime/get javascript chunk filename */
129
+ /******/ (() => {
130
+ /******/ // This function allow to reference async chunks
131
+ /******/ __webpack_require__.u = (chunkId) => {
132
+ /******/ // return url for filenames based on template
133
+ /******/ return "" + chunkId + ".js";
134
+ /******/ };
135
+ /******/ })();
136
+ /******/
137
+ /******/ /* webpack/runtime/global */
138
+ /******/ (() => {
139
+ /******/ __webpack_require__.g = (function() {
140
+ /******/ if (typeof globalThis === 'object') return globalThis;
141
+ /******/ try {
142
+ /******/ return this || new Function('return this')();
143
+ /******/ } catch (e) {
144
+ /******/ if (typeof window === 'object') return window;
145
+ /******/ }
146
+ /******/ })();
147
+ /******/ })();
148
+ /******/
69
149
  /******/ /* webpack/runtime/hasOwnProperty shorthand */
70
150
  /******/ (() => {
71
151
  /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
72
152
  /******/ })();
73
153
  /******/
154
+ /******/ /* webpack/runtime/load script */
155
+ /******/ (() => {
156
+ /******/ var inProgress = {};
157
+ /******/ var dataWebpackPrefix = "@tsparticles/shape-image:";
158
+ /******/ // loadScript function to load a script via script tag
159
+ /******/ __webpack_require__.l = (url, done, key, chunkId) => {
160
+ /******/ if(inProgress[url]) { inProgress[url].push(done); return; }
161
+ /******/ var script, needAttach;
162
+ /******/ if(key !== undefined) {
163
+ /******/ var scripts = document.getElementsByTagName("script");
164
+ /******/ for(var i = 0; i < scripts.length; i++) {
165
+ /******/ var s = scripts[i];
166
+ /******/ if(s.getAttribute("src") == url || s.getAttribute("data-webpack") == dataWebpackPrefix + key) { script = s; break; }
167
+ /******/ }
168
+ /******/ }
169
+ /******/ if(!script) {
170
+ /******/ needAttach = true;
171
+ /******/ script = document.createElement('script');
172
+ /******/
173
+ /******/ script.charset = 'utf-8';
174
+ /******/ script.timeout = 120;
175
+ /******/ if (__webpack_require__.nc) {
176
+ /******/ script.setAttribute("nonce", __webpack_require__.nc);
177
+ /******/ }
178
+ /******/ script.setAttribute("data-webpack", dataWebpackPrefix + key);
179
+ /******/
180
+ /******/ script.src = url;
181
+ /******/ }
182
+ /******/ inProgress[url] = [done];
183
+ /******/ var onScriptComplete = (prev, event) => {
184
+ /******/ // avoid mem leaks in IE.
185
+ /******/ script.onerror = script.onload = null;
186
+ /******/ clearTimeout(timeout);
187
+ /******/ var doneFns = inProgress[url];
188
+ /******/ delete inProgress[url];
189
+ /******/ script.parentNode && script.parentNode.removeChild(script);
190
+ /******/ doneFns && doneFns.forEach((fn) => (fn(event)));
191
+ /******/ if(prev) return prev(event);
192
+ /******/ }
193
+ /******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
194
+ /******/ script.onerror = onScriptComplete.bind(null, script.onerror);
195
+ /******/ script.onload = onScriptComplete.bind(null, script.onload);
196
+ /******/ needAttach && document.head.appendChild(script);
197
+ /******/ };
198
+ /******/ })();
199
+ /******/
74
200
  /******/ /* webpack/runtime/make namespace object */
75
201
  /******/ (() => {
76
202
  /******/ // define __esModule on exports
@@ -82,865 +208,128 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__533__;
82
208
  /******/ };
83
209
  /******/ })();
84
210
  /******/
211
+ /******/ /* webpack/runtime/publicPath */
212
+ /******/ (() => {
213
+ /******/ var scriptUrl;
214
+ /******/ if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
215
+ /******/ var document = __webpack_require__.g.document;
216
+ /******/ if (!scriptUrl && document) {
217
+ /******/ if (document.currentScript)
218
+ /******/ scriptUrl = document.currentScript.src;
219
+ /******/ if (!scriptUrl) {
220
+ /******/ var scripts = document.getElementsByTagName("script");
221
+ /******/ if(scripts.length) {
222
+ /******/ var i = scripts.length - 1;
223
+ /******/ while (i > -1 && !scriptUrl) scriptUrl = scripts[i--].src;
224
+ /******/ }
225
+ /******/ }
226
+ /******/ }
227
+ /******/ // When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration
228
+ /******/ // or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.
229
+ /******/ if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
230
+ /******/ scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
231
+ /******/ __webpack_require__.p = scriptUrl;
232
+ /******/ })();
233
+ /******/
234
+ /******/ /* webpack/runtime/jsonp chunk loading */
235
+ /******/ (() => {
236
+ /******/ // no baseURI
237
+ /******/
238
+ /******/ // object to store loaded and loading chunks
239
+ /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
240
+ /******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
241
+ /******/ var installedChunks = {
242
+ /******/ "tsparticles.shape.image": 0
243
+ /******/ };
244
+ /******/
245
+ /******/ __webpack_require__.f.j = (chunkId, promises) => {
246
+ /******/ // JSONP chunk loading for javascript
247
+ /******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
248
+ /******/ if(installedChunkData !== 0) { // 0 means "already installed".
249
+ /******/
250
+ /******/ // a Promise means "currently loading".
251
+ /******/ if(installedChunkData) {
252
+ /******/ promises.push(installedChunkData[2]);
253
+ /******/ } else {
254
+ /******/ if(true) { // all chunks have JS
255
+ /******/ // setup Promise in chunk cache
256
+ /******/ var promise = new Promise((resolve, reject) => (installedChunkData = installedChunks[chunkId] = [resolve, reject]));
257
+ /******/ promises.push(installedChunkData[2] = promise);
258
+ /******/
259
+ /******/ // start chunk loading
260
+ /******/ var url = __webpack_require__.p + __webpack_require__.u(chunkId);
261
+ /******/ // create error before stack unwound to get useful stacktrace later
262
+ /******/ var error = new Error();
263
+ /******/ var loadingEnded = (event) => {
264
+ /******/ if(__webpack_require__.o(installedChunks, chunkId)) {
265
+ /******/ installedChunkData = installedChunks[chunkId];
266
+ /******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
267
+ /******/ if(installedChunkData) {
268
+ /******/ var errorType = event && (event.type === 'load' ? 'missing' : event.type);
269
+ /******/ var realSrc = event && event.target && event.target.src;
270
+ /******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
271
+ /******/ error.name = 'ChunkLoadError';
272
+ /******/ error.type = errorType;
273
+ /******/ error.request = realSrc;
274
+ /******/ installedChunkData[1](error);
275
+ /******/ }
276
+ /******/ }
277
+ /******/ };
278
+ /******/ __webpack_require__.l(url, loadingEnded, "chunk-" + chunkId, chunkId);
279
+ /******/ }
280
+ /******/ }
281
+ /******/ }
282
+ /******/ };
283
+ /******/
284
+ /******/ // no prefetching
285
+ /******/
286
+ /******/ // no preloaded
287
+ /******/
288
+ /******/ // no HMR
289
+ /******/
290
+ /******/ // no HMR manifest
291
+ /******/
292
+ /******/ // no on chunks loaded
293
+ /******/
294
+ /******/ // install a JSONP callback for chunk loading
295
+ /******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
296
+ /******/ var chunkIds = data[0];
297
+ /******/ var moreModules = data[1];
298
+ /******/ var runtime = data[2];
299
+ /******/ // add "moreModules" to the modules object,
300
+ /******/ // then flag all "chunkIds" as loaded and fire callback
301
+ /******/ var moduleId, chunkId, i = 0;
302
+ /******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
303
+ /******/ for(moduleId in moreModules) {
304
+ /******/ if(__webpack_require__.o(moreModules, moduleId)) {
305
+ /******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
306
+ /******/ }
307
+ /******/ }
308
+ /******/ if(runtime) var result = runtime(__webpack_require__);
309
+ /******/ }
310
+ /******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
311
+ /******/ for(;i < chunkIds.length; i++) {
312
+ /******/ chunkId = chunkIds[i];
313
+ /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
314
+ /******/ installedChunks[chunkId][0]();
315
+ /******/ }
316
+ /******/ installedChunks[chunkId] = 0;
317
+ /******/ }
318
+ /******/
319
+ /******/ }
320
+ /******/
321
+ /******/ var chunkLoadingGlobal = this["webpackChunk_tsparticles_shape_image"] = this["webpackChunk_tsparticles_shape_image"] || [];
322
+ /******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
323
+ /******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
324
+ /******/ })();
325
+ /******/
85
326
  /************************************************************************/
86
- var __webpack_exports__ = {};
87
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
88
- (() => {
89
- // ESM COMPAT FLAG
90
- __webpack_require__.r(__webpack_exports__);
91
-
92
- // EXPORTS
93
- __webpack_require__.d(__webpack_exports__, {
94
- loadImageShape: () => (/* binding */ loadImageShape)
95
- });
96
-
97
- // EXTERNAL MODULE: external {"commonjs":"@tsparticles/engine","commonjs2":"@tsparticles/engine","amd":"@tsparticles/engine","root":"window"}
98
- var engine_root_window_ = __webpack_require__(533);
99
- ;// CONCATENATED MODULE: ./dist/browser/GifUtils/Constants.js
100
- const InterlaceOffsets = [0, 4, 2, 1];
101
- const InterlaceSteps = [8, 8, 4, 2];
102
- ;// CONCATENATED MODULE: ./dist/browser/GifUtils/ByteStream.js
103
- class ByteStream {
104
- constructor(bytes) {
105
- this.pos = 0;
106
- this.data = new Uint8ClampedArray(bytes);
107
- }
108
- getString(count) {
109
- const slice = this.data.slice(this.pos, this.pos + count);
110
- this.pos += slice.length;
111
- return slice.reduce((acc, curr) => acc + String.fromCharCode(curr), "");
112
- }
113
- nextByte() {
114
- return this.data[this.pos++];
115
- }
116
- nextTwoBytes() {
117
- this.pos += 2;
118
- return this.data[this.pos - 2] + (this.data[this.pos - 1] << 8);
119
- }
120
- readSubBlocks() {
121
- let blockString = "",
122
- size = 0;
123
- do {
124
- size = this.data[this.pos++];
125
- for (let count = size; --count >= 0; blockString += String.fromCharCode(this.data[this.pos++])) {}
126
- } while (size !== 0);
127
- return blockString;
128
- }
129
- readSubBlocksBin() {
130
- let size = 0,
131
- len = 0;
132
- for (let offset = 0; (size = this.data[this.pos + offset]) !== 0; offset += size + 1) {
133
- len += size;
134
- }
135
- const blockData = new Uint8Array(len);
136
- for (let i = 0; (size = this.data[this.pos++]) !== 0;) {
137
- for (let count = size; --count >= 0; blockData[i++] = this.data[this.pos++]) {}
138
- }
139
- return blockData;
140
- }
141
- skipSubBlocks() {
142
- for (; this.data[this.pos] !== 0; this.pos += this.data[this.pos] + 1) {}
143
- this.pos++;
144
- }
145
- }
146
- ;// CONCATENATED MODULE: ./dist/browser/GifUtils/Utils.js
147
-
148
-
149
- function parseColorTable(byteStream, count) {
150
- const colors = [];
151
- for (let i = 0; i < count; i++) {
152
- colors.push({
153
- r: byteStream.data[byteStream.pos],
154
- g: byteStream.data[byteStream.pos + 1],
155
- b: byteStream.data[byteStream.pos + 2]
156
- });
157
- byteStream.pos += 3;
158
- }
159
- return colors;
160
- }
161
- async function parseExtensionBlock(byteStream, gif, getFrameIndex, getTransparencyIndex) {
162
- switch (byteStream.nextByte()) {
163
- case 249:
164
- {
165
- const frame = gif.frames[getFrameIndex(false)];
166
- byteStream.pos++;
167
- const packedByte = byteStream.nextByte();
168
- frame.GCreserved = (packedByte & 0xe0) >>> 5;
169
- frame.disposalMethod = (packedByte & 0x1c) >>> 2;
170
- frame.userInputDelayFlag = (packedByte & 2) === 2;
171
- const transparencyFlag = (packedByte & 1) === 1;
172
- frame.delayTime = byteStream.nextTwoBytes() * 0xa;
173
- const transparencyIndex = byteStream.nextByte();
174
- if (transparencyFlag) {
175
- getTransparencyIndex(transparencyIndex);
176
- }
177
- byteStream.pos++;
178
- break;
179
- }
180
- case 255:
181
- {
182
- byteStream.pos++;
183
- const applicationExtension = {
184
- identifier: byteStream.getString(8),
185
- authenticationCode: byteStream.getString(3),
186
- data: byteStream.readSubBlocksBin()
187
- };
188
- gif.applicationExtensions.push(applicationExtension);
189
- break;
190
- }
191
- case 254:
192
- {
193
- gif.comments.push([getFrameIndex(false), byteStream.readSubBlocks()]);
194
- break;
195
- }
196
- case 1:
197
- {
198
- if (gif.globalColorTable.length === 0) {
199
- throw new EvalError("plain text extension without global color table");
200
- }
201
- byteStream.pos++;
202
- gif.frames[getFrameIndex(false)].plainTextData = {
203
- left: byteStream.nextTwoBytes(),
204
- top: byteStream.nextTwoBytes(),
205
- width: byteStream.nextTwoBytes(),
206
- height: byteStream.nextTwoBytes(),
207
- charSize: {
208
- width: byteStream.nextTwoBytes(),
209
- height: byteStream.nextTwoBytes()
210
- },
211
- foregroundColor: byteStream.nextByte(),
212
- backgroundColor: byteStream.nextByte(),
213
- text: byteStream.readSubBlocks()
214
- };
215
- break;
216
- }
217
- default:
218
- byteStream.skipSubBlocks();
219
- break;
220
- }
221
- }
222
- async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTransparencyIndex, progressCallback) {
223
- const frame = gif.frames[getFrameIndex(true)];
224
- frame.left = byteStream.nextTwoBytes();
225
- frame.top = byteStream.nextTwoBytes();
226
- frame.width = byteStream.nextTwoBytes();
227
- frame.height = byteStream.nextTwoBytes();
228
- const packedByte = byteStream.nextByte(),
229
- localColorTableFlag = (packedByte & 0x80) === 0x80,
230
- interlacedFlag = (packedByte & 0x40) === 0x40;
231
- frame.sortFlag = (packedByte & 0x20) === 0x20;
232
- frame.reserved = (packedByte & 0x18) >>> 3;
233
- const localColorCount = 1 << (packedByte & 7) + 1;
234
- if (localColorTableFlag) {
235
- frame.localColorTable = parseColorTable(byteStream, localColorCount);
236
- }
237
- const getColor = index => {
238
- const {
239
- r,
240
- g,
241
- b
242
- } = (localColorTableFlag ? frame.localColorTable : gif.globalColorTable)[index];
243
- return {
244
- r,
245
- g,
246
- b,
247
- a: index === getTransparencyIndex(null) ? avgAlpha ? ~~((r + g + b) / 3) : 0 : 255
248
- };
249
- };
250
- const image = (() => {
251
- try {
252
- return new ImageData(frame.width, frame.height, {
253
- colorSpace: "srgb"
254
- });
255
- } catch (error) {
256
- if (error instanceof DOMException && error.name === "IndexSizeError") {
257
- return null;
258
- }
259
- throw error;
260
- }
261
- })();
262
- if (image == null) {
263
- throw new EvalError("GIF frame size is to large");
264
- }
265
- const minCodeSize = byteStream.nextByte(),
266
- imageData = byteStream.readSubBlocksBin(),
267
- clearCode = 1 << minCodeSize;
268
- const readBits = (pos, len) => {
269
- const bytePos = pos >>> 3,
270
- bitPos = pos & 7;
271
- return (imageData[bytePos] + (imageData[bytePos + 1] << 8) + (imageData[bytePos + 2] << 16) & (1 << len) - 1 << bitPos) >>> bitPos;
272
- };
273
- if (interlacedFlag) {
274
- for (let code = 0, size = minCodeSize + 1, pos = 0, dic = [[0]], pass = 0; pass < 4; pass++) {
275
- if (InterlaceOffsets[pass] < frame.height) {
276
- for (let pixelPos = 0, lineIndex = 0;;) {
277
- const last = code;
278
- code = readBits(pos, size);
279
- pos += size + 1;
280
- if (code === clearCode) {
281
- size = minCodeSize + 1;
282
- dic.length = clearCode + 2;
283
- for (let i = 0; i < dic.length; i++) {
284
- dic[i] = i < clearCode ? [i] : [];
285
- }
286
- } else {
287
- if (code >= dic.length) {
288
- dic.push(dic[last].concat(dic[last][0]));
289
- } else if (last !== clearCode) {
290
- dic.push(dic[last].concat(dic[code][0]));
291
- }
292
- for (let i = 0; i < dic[code].length; i++) {
293
- const {
294
- r,
295
- g,
296
- b,
297
- a
298
- } = getColor(dic[code][i]);
299
- image.data.set([r, g, b, a], InterlaceOffsets[pass] * frame.width + InterlaceSteps[pass] * lineIndex + pixelPos % (frame.width * 4));
300
- pixelPos += 4;
301
- }
302
- if (dic.length === 1 << size && size < 0xc) {
303
- size++;
304
- }
305
- }
306
- if (pixelPos === frame.width * 4 * (lineIndex + 1)) {
307
- lineIndex++;
308
- if (InterlaceOffsets[pass] + InterlaceSteps[pass] * lineIndex >= frame.height) {
309
- break;
310
- }
311
- }
312
- }
313
- }
314
- progressCallback?.(byteStream.pos / (byteStream.data.length - 1), getFrameIndex(false) + 1, image, {
315
- x: frame.left,
316
- y: frame.top
317
- }, {
318
- width: gif.width,
319
- height: gif.height
320
- });
321
- }
322
- frame.image = image;
323
- frame.bitmap = await createImageBitmap(image);
324
- } else {
325
- for (let code = 0, size = minCodeSize + 1, pos = 0, dic = [[0]], pixelPos = -4;;) {
326
- const last = code;
327
- code = readBits(pos, size);
328
- pos += size;
329
- if (code === clearCode) {
330
- size = minCodeSize + 1;
331
- dic.length = clearCode + 2;
332
- for (let i = 0; i < dic.length; i++) {
333
- dic[i] = i < clearCode ? [i] : [];
334
- }
335
- } else {
336
- if (code === clearCode + 1) {
337
- break;
338
- }
339
- if (code >= dic.length) {
340
- dic.push(dic[last].concat(dic[last][0]));
341
- } else if (last !== clearCode) {
342
- dic.push(dic[last].concat(dic[code][0]));
343
- }
344
- for (let i = 0; i < dic[code].length; i++) {
345
- const {
346
- r,
347
- g,
348
- b,
349
- a
350
- } = getColor(dic[code][i]);
351
- image.data.set([r, g, b, a], pixelPos += 4);
352
- }
353
- if (dic.length >= 1 << size && size < 0xc) {
354
- size++;
355
- }
356
- }
357
- }
358
- frame.image = image;
359
- frame.bitmap = await createImageBitmap(image);
360
- progressCallback?.((byteStream.pos + 1) / byteStream.data.length, getFrameIndex(false) + 1, frame.image, {
361
- x: frame.left,
362
- y: frame.top
363
- }, {
364
- width: gif.width,
365
- height: gif.height
366
- });
367
- }
368
- }
369
- async function parseBlock(byteStream, gif, avgAlpha, getFrameIndex, getTransparencyIndex, progressCallback) {
370
- switch (byteStream.nextByte()) {
371
- case 59:
372
- return true;
373
- case 44:
374
- await parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTransparencyIndex, progressCallback);
375
- break;
376
- case 33:
377
- await parseExtensionBlock(byteStream, gif, getFrameIndex, getTransparencyIndex);
378
- break;
379
- default:
380
- throw new EvalError("undefined block found");
381
- }
382
- return false;
383
- }
384
- function getGIFLoopAmount(gif) {
385
- for (const extension of gif.applicationExtensions) {
386
- if (extension.identifier + extension.authenticationCode !== "NETSCAPE2.0") {
387
- continue;
388
- }
389
- return extension.data[1] + (extension.data[2] << 8);
390
- }
391
- return NaN;
392
- }
393
- async function decodeGIF(gifURL, progressCallback, avgAlpha) {
394
- if (!avgAlpha) avgAlpha = false;
395
- const res = await fetch(gifURL);
396
- if (!res.ok && res.status === 404) {
397
- throw new EvalError("file not found");
398
- }
399
- const buffer = await res.arrayBuffer();
400
- const gif = {
401
- width: 0,
402
- height: 0,
403
- totalTime: 0,
404
- colorRes: 0,
405
- pixelAspectRatio: 0,
406
- frames: [],
407
- sortFlag: false,
408
- globalColorTable: [],
409
- backgroundImage: new ImageData(1, 1, {
410
- colorSpace: "srgb"
411
- }),
412
- comments: [],
413
- applicationExtensions: []
414
- },
415
- byteStream = new ByteStream(new Uint8ClampedArray(buffer));
416
- if (byteStream.getString(6) !== "GIF89a") {
417
- throw new Error("not a supported GIF file");
418
- }
419
- gif.width = byteStream.nextTwoBytes();
420
- gif.height = byteStream.nextTwoBytes();
421
- const packedByte = byteStream.nextByte(),
422
- globalColorTableFlag = (packedByte & 0x80) === 0x80;
423
- gif.colorRes = (packedByte & 0x70) >>> 4;
424
- gif.sortFlag = (packedByte & 8) === 8;
425
- const globalColorCount = 1 << (packedByte & 7) + 1,
426
- backgroundColorIndex = byteStream.nextByte();
427
- gif.pixelAspectRatio = byteStream.nextByte();
428
- if (gif.pixelAspectRatio !== 0) {
429
- gif.pixelAspectRatio = (gif.pixelAspectRatio + 0xf) / 0x40;
430
- }
431
- if (globalColorTableFlag) {
432
- gif.globalColorTable = parseColorTable(byteStream, globalColorCount);
433
- }
434
- const backgroundImage = (() => {
435
- try {
436
- return new ImageData(gif.width, gif.height, {
437
- colorSpace: "srgb"
438
- });
439
- } catch (error) {
440
- if (error instanceof DOMException && error.name === "IndexSizeError") {
441
- return null;
442
- }
443
- throw error;
444
- }
445
- })();
446
- if (backgroundImage == null) {
447
- throw new Error("GIF frame size is to large");
448
- }
449
- const {
450
- r,
451
- g,
452
- b
453
- } = gif.globalColorTable[backgroundColorIndex];
454
- backgroundImage.data.set(globalColorTableFlag ? [r, g, b, 255] : [0, 0, 0, 0]);
455
- for (let i = 4; i < backgroundImage.data.length; i *= 2) {
456
- backgroundImage.data.copyWithin(i, 0, i);
457
- }
458
- gif.backgroundImage = backgroundImage;
459
- let frameIndex = -1,
460
- incrementFrameIndex = true,
461
- transparencyIndex = -1;
462
- const getframeIndex = increment => {
463
- if (increment) {
464
- incrementFrameIndex = true;
465
- }
466
- return frameIndex;
467
- };
468
- const getTransparencyIndex = newValue => {
469
- if (newValue != null) {
470
- transparencyIndex = newValue;
471
- }
472
- return transparencyIndex;
473
- };
474
- try {
475
- do {
476
- if (incrementFrameIndex) {
477
- gif.frames.push({
478
- left: 0,
479
- top: 0,
480
- width: 0,
481
- height: 0,
482
- disposalMethod: 0,
483
- image: new ImageData(1, 1, {
484
- colorSpace: "srgb"
485
- }),
486
- plainTextData: null,
487
- userInputDelayFlag: false,
488
- delayTime: 0,
489
- sortFlag: false,
490
- localColorTable: [],
491
- reserved: 0,
492
- GCreserved: 0
493
- });
494
- frameIndex++;
495
- transparencyIndex = -1;
496
- incrementFrameIndex = false;
497
- }
498
- } while (!(await parseBlock(byteStream, gif, avgAlpha, getframeIndex, getTransparencyIndex, progressCallback)));
499
- gif.frames.length--;
500
- for (const frame of gif.frames) {
501
- if (frame.userInputDelayFlag && frame.delayTime === 0) {
502
- gif.totalTime = Infinity;
503
- break;
504
- }
505
- gif.totalTime += frame.delayTime;
506
- }
507
- return gif;
508
- } catch (error) {
509
- if (error instanceof EvalError) {
510
- throw new Error(`error while parsing frame ${frameIndex} "${error.message}"`);
511
- }
512
- throw error;
513
- }
514
- }
515
- ;// CONCATENATED MODULE: ./dist/browser/Utils.js
516
-
517
-
518
- const currentColorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d.]+%?\))|currentcolor/gi;
519
- function replaceColorSvg(imageShape, color, opacity) {
520
- const {
521
- svgData
522
- } = imageShape;
523
- if (!svgData) {
524
- return "";
525
- }
526
- const colorStyle = (0,engine_root_window_.getStyleFromHsl)(color, opacity);
527
- if (svgData.includes("fill")) {
528
- return svgData.replace(currentColorRegex, () => colorStyle);
529
- }
530
- const preFillIndex = svgData.indexOf(">");
531
- return `${svgData.substring(0, preFillIndex)} fill="${colorStyle}"${svgData.substring(preFillIndex)}`;
532
- }
533
- async function loadImage(image) {
534
- return new Promise(resolve => {
535
- image.loading = true;
536
- const img = new Image();
537
- image.element = img;
538
- img.addEventListener("load", () => {
539
- image.loading = false;
540
- resolve();
541
- });
542
- img.addEventListener("error", () => {
543
- image.element = undefined;
544
- image.error = true;
545
- image.loading = false;
546
- (0,engine_root_window_.getLogger)().error(`${engine_root_window_.errorPrefix} loading image: ${image.source}`);
547
- resolve();
548
- });
549
- img.src = image.source;
550
- });
551
- }
552
- async function loadGifImage(image) {
553
- if (image.type !== "gif") {
554
- await loadImage(image);
555
- return;
556
- }
557
- image.loading = true;
558
- try {
559
- image.gifData = await decodeGIF(image.source);
560
- image.gifLoopCount = getGIFLoopAmount(image.gifData) ?? 0;
561
- if (image.gifLoopCount === 0) {
562
- image.gifLoopCount = Infinity;
563
- }
564
- } catch {
565
- image.error = true;
566
- }
567
- image.loading = false;
568
- }
569
- async function downloadSvgImage(image) {
570
- if (image.type !== "svg") {
571
- await loadImage(image);
572
- return;
573
- }
574
- image.loading = true;
575
- const response = await fetch(image.source);
576
- if (!response.ok) {
577
- (0,engine_root_window_.getLogger)().error(`${engine_root_window_.errorPrefix} Image not found`);
578
- image.error = true;
579
- } else {
580
- image.svgData = await response.text();
581
- }
582
- image.loading = false;
583
- }
584
- function replaceImageColor(image, imageData, color, particle) {
585
- const svgColoredData = replaceColorSvg(image, color, particle.opacity?.value ?? 1),
586
- imageRes = {
587
- color,
588
- gif: imageData.gif,
589
- data: {
590
- ...image,
591
- svgData: svgColoredData
592
- },
593
- loaded: false,
594
- ratio: imageData.width / imageData.height,
595
- replaceColor: imageData.replaceColor,
596
- source: imageData.src
597
- };
598
- return new Promise(resolve => {
599
- const svg = new Blob([svgColoredData], {
600
- type: "image/svg+xml"
601
- }),
602
- domUrl = URL || window.URL || window.webkitURL || window,
603
- url = domUrl.createObjectURL(svg),
604
- img = new Image();
605
- img.addEventListener("load", () => {
606
- imageRes.loaded = true;
607
- imageRes.element = img;
608
- resolve(imageRes);
609
- domUrl.revokeObjectURL(url);
610
- });
611
- img.addEventListener("error", async () => {
612
- domUrl.revokeObjectURL(url);
613
- const img2 = {
614
- ...image,
615
- error: false,
616
- loading: true
617
- };
618
- await loadImage(img2);
619
- imageRes.loaded = true;
620
- imageRes.element = img2.element;
621
- resolve(imageRes);
622
- });
623
- img.src = url;
624
- });
625
- }
626
- ;// CONCATENATED MODULE: ./dist/browser/ImageDrawer.js
627
-
628
-
629
- class ImageDrawer {
630
- constructor(engine) {
631
- this.loadImageShape = async imageShape => {
632
- if (!this._engine.loadImage) {
633
- throw new Error(`${engine_root_window_.errorPrefix} image shape not initialized`);
634
- }
635
- await this._engine.loadImage({
636
- gif: imageShape.gif,
637
- name: imageShape.name,
638
- replaceColor: imageShape.replaceColor ?? false,
639
- src: imageShape.src
640
- });
641
- };
642
- this._engine = engine;
643
- }
644
- addImage(image) {
645
- if (!this._engine.images) {
646
- this._engine.images = [];
647
- }
648
- this._engine.images.push(image);
649
- }
650
- draw(data) {
651
- const {
652
- context,
653
- radius,
654
- particle,
655
- opacity,
656
- delta
657
- } = data,
658
- image = particle.image,
659
- element = image?.element;
660
- if (!image) {
661
- return;
662
- }
663
- context.globalAlpha = opacity;
664
- if (image.gif && image.gifData) {
665
- const offscreenCanvas = new OffscreenCanvas(image.gifData.width, image.gifData.height),
666
- offscreenContext = offscreenCanvas.getContext("2d");
667
- if (!offscreenContext) {
668
- throw new Error("could not create offscreen canvas context");
669
- }
670
- offscreenContext.imageSmoothingQuality = "low";
671
- offscreenContext.imageSmoothingEnabled = false;
672
- offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
673
- if (particle.gifLoopCount === undefined) {
674
- particle.gifLoopCount = image.gifLoopCount ?? 0;
675
- }
676
- let frameIndex = particle.gifFrame ?? 0;
677
- const pos = {
678
- x: -image.gifData.width * 0.5,
679
- y: -image.gifData.height * 0.5
680
- },
681
- frame = image.gifData.frames[frameIndex];
682
- if (particle.gifTime === undefined) {
683
- particle.gifTime = 0;
684
- }
685
- if (!frame.bitmap) {
686
- return;
687
- }
688
- context.scale(radius / image.gifData.width, radius / image.gifData.height);
689
- switch (frame.disposalMethod) {
690
- case 4:
691
- case 5:
692
- case 6:
693
- case 7:
694
- case 0:
695
- offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
696
- context.drawImage(offscreenCanvas, pos.x, pos.y);
697
- offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
698
- break;
699
- case 1:
700
- offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
701
- context.drawImage(offscreenCanvas, pos.x, pos.y);
702
- break;
703
- case 2:
704
- offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
705
- context.drawImage(offscreenCanvas, pos.x, pos.y);
706
- offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
707
- if (image.gifData.globalColorTable.length === 0) {
708
- offscreenContext.putImageData(image.gifData.frames[0].image, pos.x + frame.left, pos.y + frame.top);
709
- } else {
710
- offscreenContext.putImageData(image.gifData.backgroundImage, pos.x, pos.y);
711
- }
712
- break;
713
- case 3:
714
- {
715
- const previousImageData = offscreenContext.getImageData(0, 0, offscreenCanvas.width, offscreenCanvas.height);
716
- offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
717
- context.drawImage(offscreenCanvas, pos.x, pos.y);
718
- offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
719
- offscreenContext.putImageData(previousImageData, 0, 0);
720
- }
721
- break;
722
- }
723
- particle.gifTime += delta.value;
724
- if (particle.gifTime > frame.delayTime) {
725
- particle.gifTime -= frame.delayTime;
726
- if (++frameIndex >= image.gifData.frames.length) {
727
- if (--particle.gifLoopCount <= 0) {
728
- return;
729
- }
730
- frameIndex = 0;
731
- offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
732
- }
733
- particle.gifFrame = frameIndex;
734
- }
735
- context.scale(image.gifData.width / radius, image.gifData.height / radius);
736
- } else if (element) {
737
- const ratio = image.ratio,
738
- pos = {
739
- x: -radius,
740
- y: -radius
741
- },
742
- diameter = radius * 2;
743
- context.drawImage(element, pos.x, pos.y, diameter, diameter / ratio);
744
- }
745
- context.globalAlpha = 1;
746
- }
747
- getSidesCount() {
748
- return 12;
749
- }
750
- async init(container) {
751
- const options = container.actualOptions;
752
- if (!options.preload || !this._engine.loadImage) {
753
- return;
754
- }
755
- for (const imageData of options.preload) {
756
- await this._engine.loadImage(imageData);
757
- }
758
- }
759
- loadShape(particle) {
760
- if (particle.shape !== "image" && particle.shape !== "images") {
761
- return;
762
- }
763
- if (!this._engine.images) {
764
- this._engine.images = [];
765
- }
766
- const imageData = particle.shapeData;
767
- if (!imageData) {
768
- return;
769
- }
770
- const image = this._engine.images.find(t => t.name === imageData.name || t.source === imageData.src);
771
- if (!image) {
772
- this.loadImageShape(imageData).then(() => {
773
- this.loadShape(particle);
774
- });
775
- }
776
- }
777
- particleInit(container, particle) {
778
- if (particle.shape !== "image" && particle.shape !== "images") {
779
- return;
780
- }
781
- if (!this._engine.images) {
782
- this._engine.images = [];
783
- }
784
- const images = this._engine.images,
785
- imageData = particle.shapeData;
786
- if (!imageData) {
787
- return;
788
- }
789
- const color = particle.getFillColor(),
790
- image = images.find(t => t.name === imageData.name || t.source === imageData.src);
791
- if (!image) {
792
- return;
793
- }
794
- const replaceColor = imageData.replaceColor ?? image.replaceColor;
795
- if (image.loading) {
796
- setTimeout(() => {
797
- this.particleInit(container, particle);
798
- });
799
- return;
800
- }
801
- (async () => {
802
- let imageRes;
803
- if (image.svgData && color) {
804
- imageRes = await replaceImageColor(image, imageData, color, particle);
805
- } else {
806
- imageRes = {
807
- color,
808
- data: image,
809
- element: image.element,
810
- gif: image.gif,
811
- gifData: image.gifData,
812
- gifLoopCount: image.gifLoopCount,
813
- loaded: true,
814
- ratio: imageData.width && imageData.height ? imageData.width / imageData.height : image.ratio ?? 1,
815
- replaceColor: replaceColor,
816
- source: imageData.src
817
- };
818
- }
819
- if (!imageRes.ratio) {
820
- imageRes.ratio = 1;
821
- }
822
- const fill = imageData.fill ?? particle.shapeFill,
823
- close = imageData.close ?? particle.shapeClose,
824
- imageShape = {
825
- image: imageRes,
826
- fill,
827
- close
828
- };
829
- particle.image = imageShape.image;
830
- particle.shapeFill = imageShape.fill;
831
- particle.shapeClose = imageShape.close;
832
- })();
833
- }
834
- }
835
- ;// CONCATENATED MODULE: ./dist/browser/Options/Classes/Preload.js
836
- class Preload {
837
- constructor() {
838
- this.src = "";
839
- this.gif = false;
840
- }
841
- load(data) {
842
- if (!data) {
843
- return;
844
- }
845
- if (data.gif !== undefined) {
846
- this.gif = data.gif;
847
- }
848
- if (data.height !== undefined) {
849
- this.height = data.height;
850
- }
851
- if (data.name !== undefined) {
852
- this.name = data.name;
853
- }
854
- if (data.replaceColor !== undefined) {
855
- this.replaceColor = data.replaceColor;
856
- }
857
- if (data.src !== undefined) {
858
- this.src = data.src;
859
- }
860
- if (data.width !== undefined) {
861
- this.width = data.width;
862
- }
863
- }
864
- }
865
- ;// CONCATENATED MODULE: ./dist/browser/ImagePreloader.js
866
-
867
- class ImagePreloaderPlugin {
868
- constructor(engine) {
869
- this.id = "imagePreloader";
870
- this._engine = engine;
871
- }
872
- getPlugin() {
873
- return {};
874
- }
875
- loadOptions(options, source) {
876
- if (!source || !source.preload) {
877
- return;
878
- }
879
- if (!options.preload) {
880
- options.preload = [];
881
- }
882
- const preloadOptions = options.preload;
883
- for (const item of source.preload) {
884
- const existing = preloadOptions.find(t => t.name === item.name || t.src === item.src);
885
- if (existing) {
886
- existing.load(item);
887
- } else {
888
- const preload = new Preload();
889
- preload.load(item);
890
- preloadOptions.push(preload);
891
- }
892
- }
893
- }
894
- needsPlugin() {
895
- return true;
896
- }
897
- }
898
- ;// CONCATENATED MODULE: ./dist/browser/index.js
899
-
900
-
901
-
902
-
903
- function addLoadImageToEngine(engine) {
904
- if (engine.loadImage) {
905
- return;
906
- }
907
- engine.loadImage = async data => {
908
- if (!data.name && !data.src) {
909
- throw new Error(`${engine_root_window_.errorPrefix} no image source provided`);
910
- }
911
- if (!engine.images) {
912
- engine.images = [];
913
- }
914
- if (engine.images.find(t => t.name === data.name || t.source === data.src)) {
915
- return;
916
- }
917
- try {
918
- const image = {
919
- gif: data.gif ?? false,
920
- name: data.name ?? data.src,
921
- source: data.src,
922
- type: data.src.substring(data.src.length - 3),
923
- error: false,
924
- loading: true,
925
- replaceColor: data.replaceColor,
926
- ratio: data.width && data.height ? data.width / data.height : undefined
927
- };
928
- engine.images.push(image);
929
- const imageFunc = data.gif ? loadGifImage : data.replaceColor ? downloadSvgImage : loadImage;
930
- await imageFunc(image);
931
- } catch {
932
- throw new Error(`${engine_root_window_.errorPrefix} ${data.name ?? data.src} not found`);
933
- }
934
- };
935
- }
936
- async function loadImageShape(engine, refresh = true) {
937
- addLoadImageToEngine(engine);
938
- const preloader = new ImagePreloaderPlugin(engine);
939
- await engine.addPlugin(preloader, refresh);
940
- await engine.addShape(["image", "images"], new ImageDrawer(engine), refresh);
941
- }
942
- })();
943
-
327
+ /******/
328
+ /******/ // startup
329
+ /******/ // Load entry module and return exports
330
+ /******/ // This entry module can't be inlined because the eval devtool is used.
331
+ /******/ var __webpack_exports__ = __webpack_require__("./dist/browser/index.js");
332
+ /******/
944
333
  /******/ return __webpack_exports__;
945
334
  /******/ })()
946
335
  ;