@tsparticles/all 3.0.0-beta.5 → 3.0.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.
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Demo / Generator : https://particles.js.org/
|
|
5
5
|
* GitHub : https://www.github.com/matteobruni/tsparticles
|
|
6
6
|
* How to use? : Check the GitHub README
|
|
7
|
-
* v3.0.0
|
|
7
|
+
* v3.0.0
|
|
8
8
|
*/
|
|
9
9
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
10
10
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
@@ -1227,7 +1227,8 @@ function drawParticle(data) {
|
|
|
1227
1227
|
particle,
|
|
1228
1228
|
radius,
|
|
1229
1229
|
opacity,
|
|
1230
|
-
delta
|
|
1230
|
+
delta,
|
|
1231
|
+
transformData
|
|
1231
1232
|
};
|
|
1232
1233
|
context.beginPath();
|
|
1233
1234
|
drawShape(drawData);
|
|
@@ -1252,7 +1253,8 @@ function drawEffect(data) {
|
|
|
1252
1253
|
particle,
|
|
1253
1254
|
radius,
|
|
1254
1255
|
opacity,
|
|
1255
|
-
delta
|
|
1256
|
+
delta,
|
|
1257
|
+
transformData
|
|
1256
1258
|
} = data;
|
|
1257
1259
|
if (!particle.effect) {
|
|
1258
1260
|
return;
|
|
@@ -1267,7 +1269,10 @@ function drawEffect(data) {
|
|
|
1267
1269
|
radius,
|
|
1268
1270
|
opacity,
|
|
1269
1271
|
delta,
|
|
1270
|
-
pixelRatio: container.retina.pixelRatio
|
|
1272
|
+
pixelRatio: container.retina.pixelRatio,
|
|
1273
|
+
transformData: {
|
|
1274
|
+
...transformData
|
|
1275
|
+
}
|
|
1271
1276
|
});
|
|
1272
1277
|
}
|
|
1273
1278
|
function drawShape(data) {
|
|
@@ -1277,7 +1282,8 @@ function drawShape(data) {
|
|
|
1277
1282
|
particle,
|
|
1278
1283
|
radius,
|
|
1279
1284
|
opacity,
|
|
1280
|
-
delta
|
|
1285
|
+
delta,
|
|
1286
|
+
transformData
|
|
1281
1287
|
} = data;
|
|
1282
1288
|
if (!particle.shape) {
|
|
1283
1289
|
return;
|
|
@@ -1292,7 +1298,10 @@ function drawShape(data) {
|
|
|
1292
1298
|
radius,
|
|
1293
1299
|
opacity,
|
|
1294
1300
|
delta,
|
|
1295
|
-
pixelRatio: container.retina.pixelRatio
|
|
1301
|
+
pixelRatio: container.retina.pixelRatio,
|
|
1302
|
+
transformData: {
|
|
1303
|
+
...transformData
|
|
1304
|
+
}
|
|
1296
1305
|
});
|
|
1297
1306
|
}
|
|
1298
1307
|
function drawShapeAfterDraw(data) {
|
|
@@ -1302,7 +1311,8 @@ function drawShapeAfterDraw(data) {
|
|
|
1302
1311
|
particle,
|
|
1303
1312
|
radius,
|
|
1304
1313
|
opacity,
|
|
1305
|
-
delta
|
|
1314
|
+
delta,
|
|
1315
|
+
transformData
|
|
1306
1316
|
} = data;
|
|
1307
1317
|
if (!particle.shape) {
|
|
1308
1318
|
return;
|
|
@@ -1317,7 +1327,10 @@ function drawShapeAfterDraw(data) {
|
|
|
1317
1327
|
radius,
|
|
1318
1328
|
opacity,
|
|
1319
1329
|
delta,
|
|
1320
|
-
pixelRatio: container.retina.pixelRatio
|
|
1330
|
+
pixelRatio: container.retina.pixelRatio,
|
|
1331
|
+
transformData: {
|
|
1332
|
+
...transformData
|
|
1333
|
+
}
|
|
1321
1334
|
});
|
|
1322
1335
|
}
|
|
1323
1336
|
function drawPlugin(context, plugin, delta) {
|
|
@@ -1554,7 +1567,7 @@ class Canvas {
|
|
|
1554
1567
|
} else if (trailFill.image) {
|
|
1555
1568
|
this._paintImage(trailFill.image, trailFill.opacity);
|
|
1556
1569
|
}
|
|
1557
|
-
} else {
|
|
1570
|
+
} else if (options.clear) {
|
|
1558
1571
|
this.draw(ctx => {
|
|
1559
1572
|
clear(ctx, this.size);
|
|
1560
1573
|
});
|
|
@@ -3518,6 +3531,7 @@ class Options {
|
|
|
3518
3531
|
this.autoPlay = true;
|
|
3519
3532
|
this.background = new Background();
|
|
3520
3533
|
this.backgroundMask = new BackgroundMask();
|
|
3534
|
+
this.clear = true;
|
|
3521
3535
|
this.defaultThemes = {};
|
|
3522
3536
|
this.delay = 0;
|
|
3523
3537
|
this.fullScreen = new FullScreen();
|
|
@@ -3545,6 +3559,12 @@ class Options {
|
|
|
3545
3559
|
if (data.autoPlay !== undefined) {
|
|
3546
3560
|
this.autoPlay = data.autoPlay;
|
|
3547
3561
|
}
|
|
3562
|
+
if (data.clear !== undefined) {
|
|
3563
|
+
this.clear = data.clear;
|
|
3564
|
+
}
|
|
3565
|
+
if (data.name !== undefined) {
|
|
3566
|
+
this.name = data.name;
|
|
3567
|
+
}
|
|
3548
3568
|
if (data.delay !== undefined) {
|
|
3549
3569
|
this.delay = setRangeValue(data.delay);
|
|
3550
3570
|
}
|
|
@@ -5126,7 +5146,7 @@ class Engine {
|
|
|
5126
5146
|
return res;
|
|
5127
5147
|
}
|
|
5128
5148
|
get version() {
|
|
5129
|
-
return "3.0.0
|
|
5149
|
+
return "3.0.0";
|
|
5130
5150
|
}
|
|
5131
5151
|
addConfig(config) {
|
|
5132
5152
|
const name = config.name ?? "default";
|
|
@@ -10550,7 +10570,7 @@ class OutOutMode {
|
|
|
10550
10570
|
}
|
|
10551
10571
|
case "normal":
|
|
10552
10572
|
{
|
|
10553
|
-
const
|
|
10573
|
+
const warp = particle.options.move.warp,
|
|
10554
10574
|
canvasSize = container.canvas.size,
|
|
10555
10575
|
newPos = {
|
|
10556
10576
|
bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
|
|
@@ -10563,27 +10583,27 @@ class OutOutMode {
|
|
|
10563
10583
|
if (direction === "right" && nextBounds.left > canvasSize.width + particle.offset.x) {
|
|
10564
10584
|
particle.position.x = newPos.left;
|
|
10565
10585
|
particle.initialPosition.x = particle.position.x;
|
|
10566
|
-
if (!
|
|
10586
|
+
if (!warp) {
|
|
10567
10587
|
particle.position.y = getRandom() * canvasSize.height;
|
|
10568
10588
|
particle.initialPosition.y = particle.position.y;
|
|
10569
10589
|
}
|
|
10570
10590
|
} else if (direction === "left" && nextBounds.right < -particle.offset.x) {
|
|
10571
10591
|
particle.position.x = newPos.right;
|
|
10572
10592
|
particle.initialPosition.x = particle.position.x;
|
|
10573
|
-
if (!
|
|
10593
|
+
if (!warp) {
|
|
10574
10594
|
particle.position.y = getRandom() * canvasSize.height;
|
|
10575
10595
|
particle.initialPosition.y = particle.position.y;
|
|
10576
10596
|
}
|
|
10577
10597
|
}
|
|
10578
10598
|
if (direction === "bottom" && nextBounds.top > canvasSize.height + particle.offset.y) {
|
|
10579
|
-
if (!
|
|
10599
|
+
if (!warp) {
|
|
10580
10600
|
particle.position.x = getRandom() * canvasSize.width;
|
|
10581
10601
|
particle.initialPosition.x = particle.position.x;
|
|
10582
10602
|
}
|
|
10583
10603
|
particle.position.y = newPos.top;
|
|
10584
10604
|
particle.initialPosition.y = particle.position.y;
|
|
10585
10605
|
} else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
|
|
10586
|
-
if (!
|
|
10606
|
+
if (!warp) {
|
|
10587
10607
|
particle.position.x = getRandom() * canvasSize.width;
|
|
10588
10608
|
particle.initialPosition.x = particle.position.x;
|
|
10589
10609
|
}
|
|
@@ -10761,7 +10781,7 @@ class EmojiDrawer {
|
|
|
10761
10781
|
}
|
|
10762
10782
|
destroy() {
|
|
10763
10783
|
for (const [, emojiData] of this._emojiShapeDict) {
|
|
10764
|
-
emojiData?.close();
|
|
10784
|
+
emojiData instanceof ImageBitmap && emojiData?.close();
|
|
10765
10785
|
}
|
|
10766
10786
|
}
|
|
10767
10787
|
draw(data) {
|
|
@@ -10812,17 +10832,33 @@ class EmojiDrawer {
|
|
|
10812
10832
|
particle.emojiData = existingData;
|
|
10813
10833
|
return;
|
|
10814
10834
|
}
|
|
10815
|
-
const canvasSize = getRangeMax(particle.size.value) * 2
|
|
10816
|
-
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10835
|
+
const canvasSize = getRangeMax(particle.size.value) * 2;
|
|
10836
|
+
let emojiData;
|
|
10837
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
10838
|
+
const canvas = new OffscreenCanvas(canvasSize, canvasSize),
|
|
10839
|
+
context = canvas.getContext("2d");
|
|
10840
|
+
if (!context) {
|
|
10841
|
+
return;
|
|
10842
|
+
}
|
|
10843
|
+
context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
|
|
10844
|
+
context.textBaseline = "middle";
|
|
10845
|
+
context.textAlign = "center";
|
|
10846
|
+
context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
|
|
10847
|
+
emojiData = canvas.transferToImageBitmap();
|
|
10848
|
+
} else {
|
|
10849
|
+
const canvas = document.createElement("canvas");
|
|
10850
|
+
canvas.width = canvasSize;
|
|
10851
|
+
canvas.height = canvasSize;
|
|
10852
|
+
const context = canvas.getContext("2d");
|
|
10853
|
+
if (!context) {
|
|
10854
|
+
return;
|
|
10855
|
+
}
|
|
10856
|
+
context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
|
|
10857
|
+
context.textBaseline = "middle";
|
|
10858
|
+
context.textAlign = "center";
|
|
10859
|
+
context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
|
|
10860
|
+
emojiData = canvas;
|
|
10820
10861
|
}
|
|
10821
|
-
context.font = `400 ${getRangeMax(particle.size.value) * 2}px ${font}`;
|
|
10822
|
-
context.textBaseline = "middle";
|
|
10823
|
-
context.textAlign = "center";
|
|
10824
|
-
context.fillText(emoji, getRangeMax(particle.size.value), getRangeMax(particle.size.value));
|
|
10825
|
-
const emojiData = canvas.transferToImageBitmap();
|
|
10826
10862
|
this._emojiShapeDict.set(key, emojiData);
|
|
10827
10863
|
particle.emojiData = emojiData;
|
|
10828
10864
|
}
|
|
@@ -20314,34 +20350,52 @@ class TrailDrawer {
|
|
|
20314
20350
|
if (particle.trail.length < 2) {
|
|
20315
20351
|
return;
|
|
20316
20352
|
}
|
|
20317
|
-
|
|
20353
|
+
while (particle.trail.length > pathLength) {
|
|
20318
20354
|
particle.trail.shift();
|
|
20319
20355
|
}
|
|
20320
20356
|
const trailLength = Math.min(particle.trail.length, pathLength),
|
|
20321
20357
|
offsetPos = {
|
|
20322
20358
|
x: currentPos.x,
|
|
20323
20359
|
y: currentPos.y
|
|
20360
|
+
},
|
|
20361
|
+
canvasSize = {
|
|
20362
|
+
width: particle.container.canvas.size.width + diameter,
|
|
20363
|
+
height: particle.container.canvas.size.height + diameter
|
|
20324
20364
|
};
|
|
20325
20365
|
let lastPos = particle.trail[trailLength - 1].position;
|
|
20366
|
+
context.setTransform(1, 0, 0, 1, currentPos.x, currentPos.y);
|
|
20326
20367
|
for (let i = trailLength; i > 0; i--) {
|
|
20327
20368
|
const step = particle.trail[i - 1],
|
|
20328
20369
|
position = step.position;
|
|
20329
|
-
if (getDistance(lastPos, position) > diameter) {
|
|
20330
|
-
continue;
|
|
20331
|
-
}
|
|
20332
20370
|
context.beginPath();
|
|
20333
20371
|
context.moveTo(lastPos.x - offsetPos.x, lastPos.y - offsetPos.y);
|
|
20334
|
-
|
|
20372
|
+
const warp = {
|
|
20373
|
+
x: (lastPos.x + canvasSize.width) % canvasSize.width,
|
|
20374
|
+
y: (lastPos.y + canvasSize.height) % canvasSize.height
|
|
20375
|
+
};
|
|
20376
|
+
if (Math.abs(lastPos.x - position.x) > canvasSize.width / 2 || Math.abs(lastPos.y - position.y) > canvasSize.height / 2) {
|
|
20377
|
+
lastPos = position;
|
|
20378
|
+
continue;
|
|
20379
|
+
}
|
|
20380
|
+
context.lineTo((Math.abs(lastPos.x - position.x) > canvasSize.width / 2 ? warp.x : position.x) - offsetPos.x, (Math.abs(lastPos.y - position.y) > canvasSize.height / 2 ? warp.y : position.y) - offsetPos.y);
|
|
20335
20381
|
const width = Math.max(i / trailLength * diameter, pxRatio, particle.trailMinWidth ?? -1);
|
|
20382
|
+
const oldAlpha = context.globalAlpha;
|
|
20383
|
+
context.globalAlpha = particle.trailFade ? i / trailLength : 1;
|
|
20336
20384
|
context.lineWidth = particle.trailMaxWidth ? Math.min(width, particle.trailMaxWidth) : width;
|
|
20337
20385
|
context.strokeStyle = step.color;
|
|
20338
20386
|
context.stroke();
|
|
20387
|
+
context.globalAlpha = oldAlpha;
|
|
20339
20388
|
lastPos = position;
|
|
20340
20389
|
}
|
|
20390
|
+
const {
|
|
20391
|
+
transformData
|
|
20392
|
+
} = data;
|
|
20393
|
+
context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, currentPos.x, currentPos.y);
|
|
20341
20394
|
}
|
|
20342
20395
|
particleInit(container, particle) {
|
|
20343
20396
|
particle.trail = [];
|
|
20344
20397
|
const effectData = particle.effectData;
|
|
20398
|
+
particle.trailFade = effectData?.fade ?? true;
|
|
20345
20399
|
particle.trailLength = getRangeValue(effectData?.length ?? 10) * container.retina.pixelRatio;
|
|
20346
20400
|
particle.trailMaxWidth = effectData?.maxWidth ? getRangeValue(effectData.maxWidth) * container.retina.pixelRatio : undefined;
|
|
20347
20401
|
particle.trailMinWidth = effectData?.minWidth ? getRangeValue(effectData.minWidth) * container.retina.pixelRatio : undefined;
|