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