@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.
- package/21.min.js +2 -0
- package/21.min.js.LICENSE.txt +1 -0
- package/618.min.js +2 -0
- package/618.min.js.LICENSE.txt +1 -0
- package/623.min.js +2 -0
- package/623.min.js.LICENSE.txt +1 -0
- package/browser/GifUtils/ByteStream.js +13 -9
- package/browser/GifUtils/Utils.js +113 -10
- package/browser/ImageDrawer.js +44 -109
- package/browser/ImagePreloader.js +3 -2
- package/browser/Utils.js +6 -23
- package/browser/index.js +12 -5
- package/cjs/GifUtils/ByteStream.js +13 -9
- package/cjs/GifUtils/Utils.js +139 -11
- package/cjs/ImageDrawer.js +67 -109
- package/cjs/ImagePreloader.js +3 -2
- package/cjs/Utils.js +7 -25
- package/cjs/index.js +36 -6
- package/dist_browser_GifUtils_Utils_js.js +50 -0
- package/dist_browser_ImageDrawer_js.js +30 -0
- package/dist_browser_ImagePreloader_js.js +40 -0
- package/esm/GifUtils/ByteStream.js +13 -9
- package/esm/GifUtils/Utils.js +113 -10
- package/esm/ImageDrawer.js +44 -109
- package/esm/ImagePreloader.js +3 -2
- package/esm/Utils.js +6 -23
- package/esm/index.js +12 -5
- package/package.json +2 -2
- package/report.html +3 -3
- package/tsparticles.shape.image.js +251 -862
- package/tsparticles.shape.image.min.js +1 -1
- package/tsparticles.shape.image.min.js.LICENSE.txt +1 -1
- package/types/GifUtils/Utils.d.ts +4 -0
- package/types/ImageDrawer.d.ts +3 -3
- package/types/ImagePreloader.d.ts +1 -1
- package/types/Utils.d.ts +0 -1
- package/umd/GifUtils/ByteStream.js +13 -9
- package/umd/GifUtils/Utils.js +140 -11
- package/umd/ImageDrawer.js +69 -110
- package/umd/ImagePreloader.js +3 -2
- package/umd/Utils.js +8 -26
- package/umd/index.js +38 -7
package/cjs/GifUtils/Utils.js
CHANGED
|
@@ -1,8 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decodeGIF = exports.getGIFLoopAmount = void 0;
|
|
26
|
+
exports.loadGifImage = exports.drawGif = exports.decodeGIF = exports.getGIFLoopAmount = void 0;
|
|
4
27
|
const Constants_js_1 = require("./Constants.js");
|
|
5
28
|
const ByteStream_js_1 = require("./ByteStream.js");
|
|
29
|
+
const origin = {
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0,
|
|
32
|
+
}, defaultFrame = 0, half = 0.5, initialTime = 0, firstIndex = 0, defaultLoopCount = 0;
|
|
6
33
|
function parseColorTable(byteStream, count) {
|
|
7
34
|
const colors = [];
|
|
8
35
|
for (let i = 0; i < count; i++) {
|
|
@@ -15,7 +42,7 @@ function parseColorTable(byteStream, count) {
|
|
|
15
42
|
}
|
|
16
43
|
return colors;
|
|
17
44
|
}
|
|
18
|
-
|
|
45
|
+
function parseExtensionBlock(byteStream, gif, getFrameIndex, getTransparencyIndex) {
|
|
19
46
|
switch (byteStream.nextByte()) {
|
|
20
47
|
case 249: {
|
|
21
48
|
const frame = gif.frames[getFrameIndex(false)];
|
|
@@ -87,7 +114,10 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
87
114
|
}
|
|
88
115
|
const getColor = (index) => {
|
|
89
116
|
const { r, g, b } = (localColorTableFlag ? frame.localColorTable : gif.globalColorTable)[index];
|
|
90
|
-
|
|
117
|
+
if (index !== getTransparencyIndex(null)) {
|
|
118
|
+
return { r, g, b, a: 255 };
|
|
119
|
+
}
|
|
120
|
+
return { r, g, b, a: avgAlpha ? ~~((r + g + b) / 3) : 0 };
|
|
91
121
|
};
|
|
92
122
|
const image = (() => {
|
|
93
123
|
try {
|
|
@@ -113,7 +143,8 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
113
143
|
if (interlacedFlag) {
|
|
114
144
|
for (let code = 0, size = minCodeSize + 1, pos = 0, dic = [[0]], pass = 0; pass < 4; pass++) {
|
|
115
145
|
if (Constants_js_1.InterlaceOffsets[pass] < frame.height) {
|
|
116
|
-
|
|
146
|
+
let pixelPos = 0, lineIndex = 0, exit = false;
|
|
147
|
+
while (!exit) {
|
|
117
148
|
const last = code;
|
|
118
149
|
code = readBits(pos, size);
|
|
119
150
|
pos += size + 1;
|
|
@@ -131,8 +162,8 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
131
162
|
else if (last !== clearCode) {
|
|
132
163
|
dic.push(dic[last].concat(dic[code][0]));
|
|
133
164
|
}
|
|
134
|
-
for (
|
|
135
|
-
const { r, g, b, a } = getColor(
|
|
165
|
+
for (const item of dic[code]) {
|
|
166
|
+
const { r, g, b, a } = getColor(item);
|
|
136
167
|
image.data.set([r, g, b, a], Constants_js_1.InterlaceOffsets[pass] * frame.width +
|
|
137
168
|
Constants_js_1.InterlaceSteps[pass] * lineIndex +
|
|
138
169
|
(pixelPos % (frame.width * 4)));
|
|
@@ -145,7 +176,7 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
145
176
|
if (pixelPos === frame.width * 4 * (lineIndex + 1)) {
|
|
146
177
|
lineIndex++;
|
|
147
178
|
if (Constants_js_1.InterlaceOffsets[pass] + Constants_js_1.InterlaceSteps[pass] * lineIndex >= frame.height) {
|
|
148
|
-
|
|
179
|
+
exit = true;
|
|
149
180
|
}
|
|
150
181
|
}
|
|
151
182
|
}
|
|
@@ -156,7 +187,9 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
156
187
|
frame.bitmap = await createImageBitmap(image);
|
|
157
188
|
}
|
|
158
189
|
else {
|
|
159
|
-
|
|
190
|
+
let code = 0, size = minCodeSize + 1, pos = 0, pixelPos = -4, exit = false;
|
|
191
|
+
const dic = [[0]];
|
|
192
|
+
while (!exit) {
|
|
160
193
|
const last = code;
|
|
161
194
|
code = readBits(pos, size);
|
|
162
195
|
pos += size;
|
|
@@ -169,6 +202,7 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
169
202
|
}
|
|
170
203
|
else {
|
|
171
204
|
if (code === clearCode + 1) {
|
|
205
|
+
exit = true;
|
|
172
206
|
break;
|
|
173
207
|
}
|
|
174
208
|
if (code >= dic.length) {
|
|
@@ -177,8 +211,8 @@ async function parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTran
|
|
|
177
211
|
else if (last !== clearCode) {
|
|
178
212
|
dic.push(dic[last].concat(dic[code][0]));
|
|
179
213
|
}
|
|
180
|
-
for (
|
|
181
|
-
const { r, g, b, a } = getColor(
|
|
214
|
+
for (const item of dic[code]) {
|
|
215
|
+
const { r, g, b, a } = getColor(item);
|
|
182
216
|
image.data.set([r, g, b, a], (pixelPos += 4));
|
|
183
217
|
}
|
|
184
218
|
if (dic.length >= 1 << size && size < 0xc) {
|
|
@@ -199,7 +233,7 @@ async function parseBlock(byteStream, gif, avgAlpha, getFrameIndex, getTranspare
|
|
|
199
233
|
await parseImageBlock(byteStream, gif, avgAlpha, getFrameIndex, getTransparencyIndex, progressCallback);
|
|
200
234
|
break;
|
|
201
235
|
case 33:
|
|
202
|
-
|
|
236
|
+
parseExtensionBlock(byteStream, gif, getFrameIndex, getTransparencyIndex);
|
|
203
237
|
break;
|
|
204
238
|
default:
|
|
205
239
|
throw new EvalError("undefined block found");
|
|
@@ -327,3 +361,97 @@ async function decodeGIF(gifURL, progressCallback, avgAlpha) {
|
|
|
327
361
|
}
|
|
328
362
|
}
|
|
329
363
|
exports.decodeGIF = decodeGIF;
|
|
364
|
+
function drawGif(data) {
|
|
365
|
+
const { context, radius, particle, delta } = data, image = particle.image;
|
|
366
|
+
if (!image?.gifData || !image.gif) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const offscreenCanvas = new OffscreenCanvas(image.gifData.width, image.gifData.height), offscreenContext = offscreenCanvas.getContext("2d");
|
|
370
|
+
if (!offscreenContext) {
|
|
371
|
+
throw new Error("could not create offscreen canvas context");
|
|
372
|
+
}
|
|
373
|
+
offscreenContext.imageSmoothingQuality = "low";
|
|
374
|
+
offscreenContext.imageSmoothingEnabled = false;
|
|
375
|
+
offscreenContext.clearRect(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
376
|
+
if (particle.gifLoopCount === undefined) {
|
|
377
|
+
particle.gifLoopCount = image.gifLoopCount ?? defaultLoopCount;
|
|
378
|
+
}
|
|
379
|
+
let frameIndex = particle.gifFrame ?? defaultFrame;
|
|
380
|
+
const pos = { x: -image.gifData.width * half, y: -image.gifData.height * half }, frame = image.gifData.frames[frameIndex];
|
|
381
|
+
if (particle.gifTime === undefined) {
|
|
382
|
+
particle.gifTime = initialTime;
|
|
383
|
+
}
|
|
384
|
+
if (!frame.bitmap) {
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
context.scale(radius / image.gifData.width, radius / image.gifData.height);
|
|
388
|
+
switch (frame.disposalMethod) {
|
|
389
|
+
case 4:
|
|
390
|
+
case 5:
|
|
391
|
+
case 6:
|
|
392
|
+
case 7:
|
|
393
|
+
case 0:
|
|
394
|
+
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
395
|
+
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
396
|
+
offscreenContext.clearRect(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
397
|
+
break;
|
|
398
|
+
case 1:
|
|
399
|
+
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
400
|
+
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
401
|
+
break;
|
|
402
|
+
case 2:
|
|
403
|
+
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
404
|
+
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
405
|
+
offscreenContext.clearRect(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
406
|
+
if (!image.gifData.globalColorTable.length) {
|
|
407
|
+
offscreenContext.putImageData(image.gifData.frames[firstIndex].image, pos.x + frame.left, pos.y + frame.top);
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
offscreenContext.putImageData(image.gifData.backgroundImage, pos.x, pos.y);
|
|
411
|
+
}
|
|
412
|
+
break;
|
|
413
|
+
case 3:
|
|
414
|
+
{
|
|
415
|
+
const previousImageData = offscreenContext.getImageData(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
416
|
+
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
417
|
+
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
418
|
+
offscreenContext.clearRect(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
419
|
+
offscreenContext.putImageData(previousImageData, origin.x, origin.y);
|
|
420
|
+
}
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
particle.gifTime += delta.value;
|
|
424
|
+
if (particle.gifTime > frame.delayTime) {
|
|
425
|
+
particle.gifTime -= frame.delayTime;
|
|
426
|
+
if (++frameIndex >= image.gifData.frames.length) {
|
|
427
|
+
if (--particle.gifLoopCount <= defaultLoopCount) {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
frameIndex = firstIndex;
|
|
431
|
+
offscreenContext.clearRect(origin.x, origin.y, offscreenCanvas.width, offscreenCanvas.height);
|
|
432
|
+
}
|
|
433
|
+
particle.gifFrame = frameIndex;
|
|
434
|
+
}
|
|
435
|
+
context.scale(image.gifData.width / radius, image.gifData.height / radius);
|
|
436
|
+
}
|
|
437
|
+
exports.drawGif = drawGif;
|
|
438
|
+
async function loadGifImage(image) {
|
|
439
|
+
if (image.type !== "gif") {
|
|
440
|
+
const { loadImage } = await Promise.resolve().then(() => __importStar(require("../Utils.js")));
|
|
441
|
+
await loadImage(image);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
image.loading = true;
|
|
445
|
+
try {
|
|
446
|
+
image.gifData = await decodeGIF(image.source);
|
|
447
|
+
image.gifLoopCount = getGIFLoopAmount(image.gifData) ?? defaultLoopCount;
|
|
448
|
+
if (!image.gifLoopCount) {
|
|
449
|
+
image.gifLoopCount = Infinity;
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
catch {
|
|
453
|
+
image.error = true;
|
|
454
|
+
}
|
|
455
|
+
image.loading = false;
|
|
456
|
+
}
|
|
457
|
+
exports.loadGifImage = loadGifImage;
|
package/cjs/ImageDrawer.js
CHANGED
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.ImageDrawer = void 0;
|
|
4
27
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const
|
|
28
|
+
const double = 2, defaultAlpha = 1, sides = 12, defaultRatio = 1;
|
|
6
29
|
class ImageDrawer {
|
|
7
30
|
constructor(engine) {
|
|
8
31
|
this.loadImageShape = async (imageShape) => {
|
|
@@ -24,92 +47,27 @@ class ImageDrawer {
|
|
|
24
47
|
}
|
|
25
48
|
this._engine.images.push(image);
|
|
26
49
|
}
|
|
27
|
-
draw(data) {
|
|
28
|
-
const { context, radius, particle, opacity
|
|
50
|
+
async draw(data) {
|
|
51
|
+
const { context, radius, particle, opacity } = data, image = particle.image, element = image?.element;
|
|
29
52
|
if (!image) {
|
|
30
53
|
return;
|
|
31
54
|
}
|
|
32
55
|
context.globalAlpha = opacity;
|
|
33
56
|
if (image.gif && image.gifData) {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
throw new Error("could not create offscreen canvas context");
|
|
37
|
-
}
|
|
38
|
-
offscreenContext.imageSmoothingQuality = "low";
|
|
39
|
-
offscreenContext.imageSmoothingEnabled = false;
|
|
40
|
-
offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
41
|
-
if (particle.gifLoopCount === undefined) {
|
|
42
|
-
particle.gifLoopCount = image.gifLoopCount ?? 0;
|
|
43
|
-
}
|
|
44
|
-
let frameIndex = particle.gifFrame ?? 0;
|
|
45
|
-
const pos = { x: -image.gifData.width * 0.5, y: -image.gifData.height * 0.5 }, frame = image.gifData.frames[frameIndex];
|
|
46
|
-
if (particle.gifTime === undefined) {
|
|
47
|
-
particle.gifTime = 0;
|
|
48
|
-
}
|
|
49
|
-
if (!frame.bitmap) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
context.scale(radius / image.gifData.width, radius / image.gifData.height);
|
|
53
|
-
switch (frame.disposalMethod) {
|
|
54
|
-
case 4:
|
|
55
|
-
case 5:
|
|
56
|
-
case 6:
|
|
57
|
-
case 7:
|
|
58
|
-
case 0:
|
|
59
|
-
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
60
|
-
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
61
|
-
offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
62
|
-
break;
|
|
63
|
-
case 1:
|
|
64
|
-
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
65
|
-
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
66
|
-
break;
|
|
67
|
-
case 2:
|
|
68
|
-
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
69
|
-
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
70
|
-
offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
71
|
-
if (image.gifData.globalColorTable.length === 0) {
|
|
72
|
-
offscreenContext.putImageData(image.gifData.frames[0].image, pos.x + frame.left, pos.y + frame.top);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
offscreenContext.putImageData(image.gifData.backgroundImage, pos.x, pos.y);
|
|
76
|
-
}
|
|
77
|
-
break;
|
|
78
|
-
case 3:
|
|
79
|
-
{
|
|
80
|
-
const previousImageData = offscreenContext.getImageData(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
81
|
-
offscreenContext.drawImage(frame.bitmap, frame.left, frame.top);
|
|
82
|
-
context.drawImage(offscreenCanvas, pos.x, pos.y);
|
|
83
|
-
offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
84
|
-
offscreenContext.putImageData(previousImageData, 0, 0);
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
particle.gifTime += delta.value;
|
|
89
|
-
if (particle.gifTime > frame.delayTime) {
|
|
90
|
-
particle.gifTime -= frame.delayTime;
|
|
91
|
-
if (++frameIndex >= image.gifData.frames.length) {
|
|
92
|
-
if (--particle.gifLoopCount <= 0) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
frameIndex = 0;
|
|
96
|
-
offscreenContext.clearRect(0, 0, offscreenCanvas.width, offscreenCanvas.height);
|
|
97
|
-
}
|
|
98
|
-
particle.gifFrame = frameIndex;
|
|
99
|
-
}
|
|
100
|
-
context.scale(image.gifData.width / radius, image.gifData.height / radius);
|
|
57
|
+
const { drawGif } = await Promise.resolve().then(() => __importStar(require("./GifUtils/Utils.js")));
|
|
58
|
+
drawGif(data);
|
|
101
59
|
}
|
|
102
60
|
else if (element) {
|
|
103
61
|
const ratio = image.ratio, pos = {
|
|
104
62
|
x: -radius,
|
|
105
63
|
y: -radius,
|
|
106
|
-
}, diameter = radius *
|
|
64
|
+
}, diameter = radius * double;
|
|
107
65
|
context.drawImage(element, pos.x, pos.y, diameter, diameter / ratio);
|
|
108
66
|
}
|
|
109
|
-
context.globalAlpha =
|
|
67
|
+
context.globalAlpha = defaultAlpha;
|
|
110
68
|
}
|
|
111
69
|
getSidesCount() {
|
|
112
|
-
return
|
|
70
|
+
return sides;
|
|
113
71
|
}
|
|
114
72
|
async init(container) {
|
|
115
73
|
const options = container.actualOptions;
|
|
@@ -120,7 +78,7 @@ class ImageDrawer {
|
|
|
120
78
|
await this._engine.loadImage(imageData);
|
|
121
79
|
}
|
|
122
80
|
}
|
|
123
|
-
loadShape(particle) {
|
|
81
|
+
async loadShape(particle) {
|
|
124
82
|
if (particle.shape !== "image" && particle.shape !== "images") {
|
|
125
83
|
return;
|
|
126
84
|
}
|
|
@@ -133,12 +91,11 @@ class ImageDrawer {
|
|
|
133
91
|
}
|
|
134
92
|
const image = this._engine.images.find((t) => t.name === imageData.name || t.source === imageData.src);
|
|
135
93
|
if (!image) {
|
|
136
|
-
this.loadImageShape(imageData)
|
|
137
|
-
|
|
138
|
-
});
|
|
94
|
+
await this.loadImageShape(imageData);
|
|
95
|
+
await this.loadShape(particle);
|
|
139
96
|
}
|
|
140
97
|
}
|
|
141
|
-
particleInit(container, particle) {
|
|
98
|
+
async particleInit(container, particle) {
|
|
142
99
|
if (particle.shape !== "image" && particle.shape !== "images") {
|
|
143
100
|
return;
|
|
144
101
|
}
|
|
@@ -156,41 +113,42 @@ class ImageDrawer {
|
|
|
156
113
|
const replaceColor = imageData.replaceColor ?? image.replaceColor;
|
|
157
114
|
if (image.loading) {
|
|
158
115
|
setTimeout(() => {
|
|
159
|
-
this.particleInit(container, particle);
|
|
116
|
+
void this.particleInit(container, particle);
|
|
160
117
|
});
|
|
161
118
|
return;
|
|
162
119
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!imageRes.ratio) {
|
|
183
|
-
imageRes.ratio = 1;
|
|
184
|
-
}
|
|
185
|
-
const fill = imageData.fill ?? particle.shapeFill, close = imageData.close ?? particle.shapeClose, imageShape = {
|
|
186
|
-
image: imageRes,
|
|
187
|
-
fill,
|
|
188
|
-
close,
|
|
120
|
+
let imageRes;
|
|
121
|
+
if (image.svgData && color) {
|
|
122
|
+
const { replaceImageColor } = await Promise.resolve().then(() => __importStar(require("./Utils.js")));
|
|
123
|
+
imageRes = await replaceImageColor(image, imageData, color, particle);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
imageRes = {
|
|
127
|
+
color,
|
|
128
|
+
data: image,
|
|
129
|
+
element: image.element,
|
|
130
|
+
gif: image.gif,
|
|
131
|
+
gifData: image.gifData,
|
|
132
|
+
gifLoopCount: image.gifLoopCount,
|
|
133
|
+
loaded: true,
|
|
134
|
+
ratio: imageData.width && imageData.height
|
|
135
|
+
? imageData.width / imageData.height
|
|
136
|
+
: image.ratio ?? defaultRatio,
|
|
137
|
+
replaceColor: replaceColor,
|
|
138
|
+
source: imageData.src,
|
|
189
139
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
140
|
+
}
|
|
141
|
+
if (!imageRes.ratio) {
|
|
142
|
+
imageRes.ratio = 1;
|
|
143
|
+
}
|
|
144
|
+
const fill = imageData.fill ?? particle.shapeFill, close = imageData.close ?? particle.shapeClose, imageShape = {
|
|
145
|
+
image: imageRes,
|
|
146
|
+
fill,
|
|
147
|
+
close,
|
|
148
|
+
};
|
|
149
|
+
particle.image = imageShape.image;
|
|
150
|
+
particle.shapeFill = imageShape.fill;
|
|
151
|
+
particle.shapeClose = imageShape.close;
|
|
194
152
|
}
|
|
195
153
|
}
|
|
196
154
|
exports.ImageDrawer = ImageDrawer;
|
package/cjs/ImagePreloader.js
CHANGED
|
@@ -7,11 +7,12 @@ class ImagePreloaderPlugin {
|
|
|
7
7
|
this.id = "imagePreloader";
|
|
8
8
|
this._engine = engine;
|
|
9
9
|
}
|
|
10
|
-
getPlugin() {
|
|
10
|
+
async getPlugin() {
|
|
11
|
+
await Promise.resolve();
|
|
11
12
|
return {};
|
|
12
13
|
}
|
|
13
14
|
loadOptions(options, source) {
|
|
14
|
-
if (!source
|
|
15
|
+
if (!source?.preload) {
|
|
15
16
|
return;
|
|
16
17
|
}
|
|
17
18
|
if (!options.preload) {
|
package/cjs/Utils.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceImageColor = exports.downloadSvgImage = exports.
|
|
3
|
+
exports.replaceImageColor = exports.downloadSvgImage = exports.loadImage = void 0;
|
|
4
4
|
const engine_1 = require("@tsparticles/engine");
|
|
5
|
-
const
|
|
5
|
+
const stringStart = 0, defaultOpacity = 1;
|
|
6
6
|
const currentColorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d.]+%?\))|currentcolor/gi;
|
|
7
7
|
function replaceColorSvg(imageShape, color, opacity) {
|
|
8
8
|
const { svgData } = imageShape;
|
|
@@ -14,7 +14,7 @@ function replaceColorSvg(imageShape, color, opacity) {
|
|
|
14
14
|
return svgData.replace(currentColorRegex, () => colorStyle);
|
|
15
15
|
}
|
|
16
16
|
const preFillIndex = svgData.indexOf(">");
|
|
17
|
-
return `${svgData.substring(
|
|
17
|
+
return `${svgData.substring(stringStart, preFillIndex)} fill="${colorStyle}"${svgData.substring(preFillIndex)}`;
|
|
18
18
|
}
|
|
19
19
|
async function loadImage(image) {
|
|
20
20
|
return new Promise((resolve) => {
|
|
@@ -36,25 +36,6 @@ async function loadImage(image) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
exports.loadImage = loadImage;
|
|
39
|
-
async function loadGifImage(image) {
|
|
40
|
-
if (image.type !== "gif") {
|
|
41
|
-
await loadImage(image);
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
image.loading = true;
|
|
45
|
-
try {
|
|
46
|
-
image.gifData = await (0, Utils_js_1.decodeGIF)(image.source);
|
|
47
|
-
image.gifLoopCount = (0, Utils_js_1.getGIFLoopAmount)(image.gifData) ?? 0;
|
|
48
|
-
if (image.gifLoopCount === 0) {
|
|
49
|
-
image.gifLoopCount = Infinity;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
image.error = true;
|
|
54
|
-
}
|
|
55
|
-
image.loading = false;
|
|
56
|
-
}
|
|
57
|
-
exports.loadGifImage = loadGifImage;
|
|
58
39
|
async function downloadSvgImage(image) {
|
|
59
40
|
if (image.type !== "svg") {
|
|
60
41
|
await loadImage(image);
|
|
@@ -73,7 +54,7 @@ async function downloadSvgImage(image) {
|
|
|
73
54
|
}
|
|
74
55
|
exports.downloadSvgImage = downloadSvgImage;
|
|
75
56
|
function replaceImageColor(image, imageData, color, particle) {
|
|
76
|
-
const svgColoredData = replaceColorSvg(image, color, particle.opacity?.value ??
|
|
57
|
+
const svgColoredData = replaceColorSvg(image, color, particle.opacity?.value ?? defaultOpacity), imageRes = {
|
|
77
58
|
color,
|
|
78
59
|
gif: imageData.gif,
|
|
79
60
|
data: {
|
|
@@ -93,7 +74,7 @@ function replaceImageColor(image, imageData, color, particle) {
|
|
|
93
74
|
resolve(imageRes);
|
|
94
75
|
domUrl.revokeObjectURL(url);
|
|
95
76
|
});
|
|
96
|
-
|
|
77
|
+
const errorHandler = async () => {
|
|
97
78
|
domUrl.revokeObjectURL(url);
|
|
98
79
|
const img2 = {
|
|
99
80
|
...image,
|
|
@@ -104,7 +85,8 @@ function replaceImageColor(image, imageData, color, particle) {
|
|
|
104
85
|
imageRes.loaded = true;
|
|
105
86
|
imageRes.element = img2.element;
|
|
106
87
|
resolve(imageRes);
|
|
107
|
-
}
|
|
88
|
+
};
|
|
89
|
+
img.addEventListener("error", () => void errorHandler());
|
|
108
90
|
img.src = url;
|
|
109
91
|
});
|
|
110
92
|
}
|
package/cjs/index.js
CHANGED
|
@@ -1,10 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.loadImageShape = void 0;
|
|
4
27
|
const Utils_js_1 = require("./Utils.js");
|
|
5
|
-
const ImageDrawer_js_1 = require("./ImageDrawer.js");
|
|
6
|
-
const ImagePreloader_js_1 = require("./ImagePreloader.js");
|
|
7
28
|
const engine_1 = require("@tsparticles/engine");
|
|
29
|
+
const extLength = 3;
|
|
8
30
|
function addLoadImageToEngine(engine) {
|
|
9
31
|
if (engine.loadImage) {
|
|
10
32
|
return;
|
|
@@ -24,14 +46,21 @@ function addLoadImageToEngine(engine) {
|
|
|
24
46
|
gif: data.gif ?? false,
|
|
25
47
|
name: data.name ?? data.src,
|
|
26
48
|
source: data.src,
|
|
27
|
-
type: data.src.substring(data.src.length -
|
|
49
|
+
type: data.src.substring(data.src.length - extLength),
|
|
28
50
|
error: false,
|
|
29
51
|
loading: true,
|
|
30
52
|
replaceColor: data.replaceColor,
|
|
31
53
|
ratio: data.width && data.height ? data.width / data.height : undefined,
|
|
32
54
|
};
|
|
33
55
|
engine.images.push(image);
|
|
34
|
-
|
|
56
|
+
let imageFunc;
|
|
57
|
+
if (data.gif) {
|
|
58
|
+
const { loadGifImage } = await Promise.resolve().then(() => __importStar(require("./GifUtils/Utils.js")));
|
|
59
|
+
imageFunc = loadGifImage;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
imageFunc = data.replaceColor ? Utils_js_1.downloadSvgImage : Utils_js_1.loadImage;
|
|
63
|
+
}
|
|
35
64
|
await imageFunc(image);
|
|
36
65
|
}
|
|
37
66
|
catch {
|
|
@@ -41,8 +70,9 @@ function addLoadImageToEngine(engine) {
|
|
|
41
70
|
}
|
|
42
71
|
async function loadImageShape(engine, refresh = true) {
|
|
43
72
|
addLoadImageToEngine(engine);
|
|
44
|
-
const
|
|
73
|
+
const { ImagePreloaderPlugin } = await Promise.resolve().then(() => __importStar(require("./ImagePreloader.js"))), { ImageDrawer } = await Promise.resolve().then(() => __importStar(require("./ImageDrawer.js")));
|
|
74
|
+
const preloader = new ImagePreloaderPlugin(engine);
|
|
45
75
|
await engine.addPlugin(preloader, refresh);
|
|
46
|
-
await engine.addShape(["image", "images"], new
|
|
76
|
+
await engine.addShape(["image", "images"], new ImageDrawer(engine), refresh);
|
|
47
77
|
}
|
|
48
78
|
exports.loadImageShape = loadImageShape;
|