1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | (function webpackUniversalModuleDefinition(root, factory) {
|
10 | if(typeof exports === 'object' && typeof module === 'object')
|
11 | module.exports = factory();
|
12 | else if(typeof define === 'function' && define.amd)
|
13 | define([], factory);
|
14 | else {
|
15 | var a = factory();
|
16 | for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
|
17 | }
|
18 | })(this, () => {
|
19 | return (() => {
|
20 | "use strict";
|
21 |
|
22 | var __webpack_require__ = {};
|
23 |
|
24 |
|
25 |
|
26 | (() => {
|
27 |
|
28 | __webpack_require__.d = (exports, definition) => {
|
29 | for(var key in definition) {
|
30 | if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
31 | Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
32 | }
|
33 | }
|
34 | };
|
35 | })();
|
36 |
|
37 |
|
38 | (() => {
|
39 | __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
40 | })();
|
41 |
|
42 |
|
43 | (() => {
|
44 |
|
45 | __webpack_require__.r = (exports) => {
|
46 | if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
47 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
48 | }
|
49 | Object.defineProperty(exports, '__esModule', { value: true });
|
50 | };
|
51 | })();
|
52 |
|
53 |
|
54 | var __webpack_exports__ = {};
|
55 |
|
56 | __webpack_require__.r(__webpack_exports__);
|
57 |
|
58 |
|
59 | __webpack_require__.d(__webpack_exports__, {
|
60 | "AnimatableColor": () => ( AnimatableColor),
|
61 | "AnimationOptions": () => ( AnimationOptions),
|
62 | "Background": () => ( Background),
|
63 | "BackgroundMask": () => ( BackgroundMask),
|
64 | "BackgroundMaskCover": () => ( BackgroundMaskCover),
|
65 | "Circle": () => ( Circle),
|
66 | "ClickEvent": () => ( ClickEvent),
|
67 | "Collisions": () => ( Collisions),
|
68 | "CollisionsAbsorb": () => ( CollisionsAbsorb),
|
69 | "CollisionsOverlap": () => ( CollisionsOverlap),
|
70 | "ColorAnimation": () => ( ColorAnimation),
|
71 | "DivEvent": () => ( DivEvent),
|
72 | "Events": () => ( Events),
|
73 | "ExternalInteractorBase": () => ( ExternalInteractorBase),
|
74 | "FullScreen": () => ( FullScreen),
|
75 | "HoverEvent": () => ( HoverEvent),
|
76 | "HslAnimation": () => ( HslAnimation),
|
77 | "HslColorManager": () => ( HslColorManager),
|
78 | "Interactivity": () => ( Interactivity),
|
79 | "ManualParticle": () => ( ManualParticle),
|
80 | "Modes": () => ( Modes),
|
81 | "Move": () => ( Move),
|
82 | "MoveAngle": () => ( MoveAngle),
|
83 | "MoveAttract": () => ( MoveAttract),
|
84 | "MoveCenter": () => ( MoveCenter),
|
85 | "MoveGravity": () => ( MoveGravity),
|
86 | "MovePath": () => ( MovePath),
|
87 | "MoveTrail": () => ( MoveTrail),
|
88 | "Opacity": () => ( Opacity),
|
89 | "OpacityAnimation": () => ( OpacityAnimation),
|
90 | "Options": () => ( Options),
|
91 | "OptionsColor": () => ( OptionsColor),
|
92 | "OutModes": () => ( OutModes),
|
93 | "Parallax": () => ( Parallax),
|
94 | "ParticlesBounce": () => ( ParticlesBounce),
|
95 | "ParticlesBounceFactor": () => ( ParticlesBounceFactor),
|
96 | "ParticlesDensity": () => ( ParticlesDensity),
|
97 | "ParticlesInteractorBase": () => ( ParticlesInteractorBase),
|
98 | "ParticlesNumber": () => ( ParticlesNumber),
|
99 | "ParticlesOptions": () => ( ParticlesOptions),
|
100 | "Point": () => ( Point),
|
101 | "Range": () => ( Range),
|
102 | "Rectangle": () => ( Rectangle),
|
103 | "ResizeEvent": () => ( ResizeEvent),
|
104 | "Responsive": () => ( Responsive),
|
105 | "RgbColorManager": () => ( RgbColorManager),
|
106 | "Shadow": () => ( Shadow),
|
107 | "Shape": () => ( Shape),
|
108 | "Size": () => ( Size),
|
109 | "SizeAnimation": () => ( SizeAnimation),
|
110 | "Spin": () => ( Spin),
|
111 | "Stroke": () => ( Stroke),
|
112 | "Theme": () => ( Theme),
|
113 | "ThemeDefault": () => ( ThemeDefault),
|
114 | "ValueWithRandom": () => ( ValueWithRandom),
|
115 | "Vector": () => ( Vector),
|
116 | "Vector3d": () => ( Vector3d),
|
117 | "ZIndex": () => ( ZIndex),
|
118 | "addColorManager": () => ( addColorManager),
|
119 | "addEasing": () => ( addEasing),
|
120 | "alterHsl": () => ( alterHsl),
|
121 | "animate": () => ( animate),
|
122 | "areBoundsInside": () => ( areBoundsInside),
|
123 | "arrayRandomIndex": () => ( arrayRandomIndex),
|
124 | "calcExactPositionOrRandomFromSize": () => ( calcExactPositionOrRandomFromSize),
|
125 | "calcExactPositionOrRandomFromSizeRanged": () => ( calcExactPositionOrRandomFromSizeRanged),
|
126 | "calcPositionFromSize": () => ( calcPositionFromSize),
|
127 | "calcPositionOrRandomFromSize": () => ( calcPositionOrRandomFromSize),
|
128 | "calcPositionOrRandomFromSizeRanged": () => ( calcPositionOrRandomFromSizeRanged),
|
129 | "calculateBounds": () => ( calculateBounds),
|
130 | "cancelAnimation": () => ( cancelAnimation),
|
131 | "circleBounce": () => ( circleBounce),
|
132 | "circleBounceDataFromParticle": () => ( circleBounceDataFromParticle),
|
133 | "clamp": () => ( clamp),
|
134 | "clear": () => ( clear),
|
135 | "collisionVelocity": () => ( collisionVelocity),
|
136 | "colorMix": () => ( colorMix),
|
137 | "colorToHsl": () => ( colorToHsl),
|
138 | "colorToRgb": () => ( colorToRgb),
|
139 | "deepExtend": () => ( deepExtend),
|
140 | "divMode": () => ( divMode),
|
141 | "divModeExecute": () => ( divModeExecute),
|
142 | "drawLine": () => ( drawLine),
|
143 | "drawParticle": () => ( drawParticle),
|
144 | "drawParticlePlugin": () => ( drawParticlePlugin),
|
145 | "drawPlugin": () => ( drawPlugin),
|
146 | "drawShape": () => ( drawShape),
|
147 | "drawShapeAfterEffect": () => ( drawShapeAfterEffect),
|
148 | "drawTriangle": () => ( drawTriangle),
|
149 | "executeOnSingleOrMultiple": () => ( executeOnSingleOrMultiple),
|
150 | "findItemFromSingleOrMultiple": () => ( findItemFromSingleOrMultiple),
|
151 | "generatedAttribute": () => ( generatedAttribute),
|
152 | "getDistance": () => ( getDistance),
|
153 | "getDistances": () => ( getDistances),
|
154 | "getEasing": () => ( getEasing),
|
155 | "getHslAnimationFromHsl": () => ( getHslAnimationFromHsl),
|
156 | "getHslFromAnimation": () => ( getHslFromAnimation),
|
157 | "getLinkColor": () => ( getLinkColor),
|
158 | "getLinkRandomColor": () => ( getLinkRandomColor),
|
159 | "getParticleBaseVelocity": () => ( getParticleBaseVelocity),
|
160 | "getParticleDirectionAngle": () => ( getParticleDirectionAngle),
|
161 | "getRandom": () => ( getRandom),
|
162 | "getRandomRgbColor": () => ( getRandomRgbColor),
|
163 | "getRangeMax": () => ( getRangeMax),
|
164 | "getRangeMin": () => ( getRangeMin),
|
165 | "getRangeValue": () => ( getRangeValue),
|
166 | "getStyleFromHsl": () => ( getStyleFromHsl),
|
167 | "getStyleFromRgb": () => ( getStyleFromRgb),
|
168 | "getValue": () => ( getValue),
|
169 | "hasMatchMedia": () => ( hasMatchMedia),
|
170 | "hslToRgb": () => ( hslToRgb),
|
171 | "hslaToRgba": () => ( hslaToRgba),
|
172 | "isDivModeEnabled": () => ( isDivModeEnabled),
|
173 | "isInArray": () => ( isInArray),
|
174 | "isPointInside": () => ( isPointInside),
|
175 | "isSsr": () => ( isSsr),
|
176 | "itemFromArray": () => ( itemFromArray),
|
177 | "itemFromSingleOrMultiple": () => ( itemFromSingleOrMultiple),
|
178 | "loadFont": () => ( loadFont),
|
179 | "loadOptions": () => ( loadOptions),
|
180 | "loadParticlesOptions": () => ( loadParticlesOptions),
|
181 | "loadSlim": () => ( loadSlim),
|
182 | "mix": () => ( mix),
|
183 | "mouseDownEvent": () => ( mouseDownEvent),
|
184 | "mouseLeaveEvent": () => ( mouseLeaveEvent),
|
185 | "mouseMoveEvent": () => ( mouseMoveEvent),
|
186 | "mouseOutEvent": () => ( mouseOutEvent),
|
187 | "mouseUpEvent": () => ( mouseUpEvent),
|
188 | "paintBase": () => ( paintBase),
|
189 | "paintImage": () => ( paintImage),
|
190 | "parseAlpha": () => ( parseAlpha),
|
191 | "randomInRange": () => ( randomInRange),
|
192 | "rangeColorToHsl": () => ( rangeColorToHsl),
|
193 | "rangeColorToRgb": () => ( rangeColorToRgb),
|
194 | "rectBounce": () => ( rectBounce),
|
195 | "resizeEvent": () => ( resizeEvent),
|
196 | "rgbToHsl": () => ( rgbToHsl),
|
197 | "safeMatchMedia": () => ( safeMatchMedia),
|
198 | "setRandom": () => ( setRandom),
|
199 | "setRangeValue": () => ( setRangeValue),
|
200 | "singleDivModeExecute": () => ( singleDivModeExecute),
|
201 | "stringToAlpha": () => ( stringToAlpha),
|
202 | "stringToRgb": () => ( stringToRgb),
|
203 | "touchCancelEvent": () => ( touchCancelEvent),
|
204 | "touchEndEvent": () => ( touchEndEvent),
|
205 | "touchMoveEvent": () => ( touchMoveEvent),
|
206 | "touchStartEvent": () => ( touchStartEvent),
|
207 | "tsParticles": () => ( tsParticles),
|
208 | "visibilityChangeEvent": () => ( visibilityChangeEvent)
|
209 | });
|
210 |
|
211 | ;
|
212 | const initPjs = engine => {
|
213 | const particlesJS = (tagId, options) => {
|
214 | return engine.load(tagId, options);
|
215 | };
|
216 | particlesJS.load = (tagId, pathConfigJson, callback) => {
|
217 | engine.loadJSON(tagId, pathConfigJson).then(container => {
|
218 | if (container) {
|
219 | callback(container);
|
220 | }
|
221 | }).catch(() => {
|
222 | callback(undefined);
|
223 | });
|
224 | };
|
225 | particlesJS.setOnClickHandler = callback => {
|
226 | engine.setOnClickHandler(callback);
|
227 | };
|
228 | const pJSDom = engine.dom();
|
229 | return {
|
230 | particlesJS,
|
231 | pJSDom
|
232 | };
|
233 | };
|
234 |
|
235 | ;
|
236 | class EventDispatcher {
|
237 | constructor() {
|
238 | this._listeners = new Map();
|
239 | }
|
240 | addEventListener(type, listener) {
|
241 | var _a;
|
242 | this.removeEventListener(type, listener);
|
243 | if (!this._listeners.get(type)) {
|
244 | this._listeners.set(type, []);
|
245 | }
|
246 | (_a = this._listeners.get(type)) === null || _a === void 0 ? void 0 : _a.push(listener);
|
247 | }
|
248 | dispatchEvent(type, args) {
|
249 | var _a;
|
250 | (_a = this._listeners.get(type)) === null || _a === void 0 ? void 0 : _a.forEach(handler => handler(args));
|
251 | }
|
252 | hasEventListener(type) {
|
253 | return !!this._listeners.get(type);
|
254 | }
|
255 | removeAllEventListeners(type) {
|
256 | if (!type) {
|
257 | this._listeners = new Map();
|
258 | } else {
|
259 | this._listeners.delete(type);
|
260 | }
|
261 | }
|
262 | removeEventListener(type, listener) {
|
263 | const arr = this._listeners.get(type);
|
264 | if (!arr) {
|
265 | return;
|
266 | }
|
267 | const length = arr.length,
|
268 | idx = arr.indexOf(listener);
|
269 | if (idx < 0) {
|
270 | return;
|
271 | }
|
272 | if (length === 1) {
|
273 | this._listeners.delete(type);
|
274 | } else {
|
275 | arr.splice(idx, 1);
|
276 | }
|
277 | }
|
278 | }
|
279 | ;
|
280 | class Vector3d {
|
281 | constructor(xOrCoords, y, z) {
|
282 | if (typeof xOrCoords !== "number" && xOrCoords) {
|
283 | this.x = xOrCoords.x;
|
284 | this.y = xOrCoords.y;
|
285 | const coords3d = xOrCoords;
|
286 | this.z = coords3d.z ? coords3d.z : 0;
|
287 | } else if (xOrCoords !== undefined && y !== undefined) {
|
288 | this.x = xOrCoords;
|
289 | this.y = y;
|
290 | this.z = z !== null && z !== void 0 ? z : 0;
|
291 | } else {
|
292 | throw new Error("tsParticles - Vector3d not initialized correctly");
|
293 | }
|
294 | }
|
295 | static get origin() {
|
296 | return Vector3d.create(0, 0, 0);
|
297 | }
|
298 | get angle() {
|
299 | return Math.atan2(this.y, this.x);
|
300 | }
|
301 | set angle(angle) {
|
302 | this.updateFromAngle(angle, this.length);
|
303 | }
|
304 | get length() {
|
305 | return Math.sqrt(this.getLengthSq());
|
306 | }
|
307 | set length(length) {
|
308 | this.updateFromAngle(this.angle, length);
|
309 | }
|
310 | static clone(source) {
|
311 | return Vector3d.create(source.x, source.y, source.z);
|
312 | }
|
313 | static create(x, y, z) {
|
314 | return new Vector3d(x, y, z);
|
315 | }
|
316 | add(v) {
|
317 | return Vector3d.create(this.x + v.x, this.y + v.y, this.z + v.z);
|
318 | }
|
319 | addTo(v) {
|
320 | this.x += v.x;
|
321 | this.y += v.y;
|
322 | this.z += v.z;
|
323 | }
|
324 | copy() {
|
325 | return Vector3d.clone(this);
|
326 | }
|
327 | distanceTo(v) {
|
328 | return this.sub(v).length;
|
329 | }
|
330 | distanceToSq(v) {
|
331 | return this.sub(v).getLengthSq();
|
332 | }
|
333 | div(n) {
|
334 | return Vector3d.create(this.x / n, this.y / n, this.z / n);
|
335 | }
|
336 | divTo(n) {
|
337 | this.x /= n;
|
338 | this.y /= n;
|
339 | this.z /= n;
|
340 | }
|
341 | getLengthSq() {
|
342 | return this.x ** 2 + this.y ** 2;
|
343 | }
|
344 | mult(n) {
|
345 | return Vector3d.create(this.x * n, this.y * n, this.z * n);
|
346 | }
|
347 | multTo(n) {
|
348 | this.x *= n;
|
349 | this.y *= n;
|
350 | this.z *= n;
|
351 | }
|
352 | rotate(angle) {
|
353 | return Vector3d.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle), 0);
|
354 | }
|
355 | setTo(c) {
|
356 | this.x = c.x;
|
357 | this.y = c.y;
|
358 | const v3d = c;
|
359 | this.z = v3d.z ? v3d.z : 0;
|
360 | }
|
361 | sub(v) {
|
362 | return Vector3d.create(this.x - v.x, this.y - v.y, this.z - v.z);
|
363 | }
|
364 | subFrom(v) {
|
365 | this.x -= v.x;
|
366 | this.y -= v.y;
|
367 | this.z -= v.z;
|
368 | }
|
369 | updateFromAngle(angle, length) {
|
370 | this.x = Math.cos(angle) * length;
|
371 | this.y = Math.sin(angle) * length;
|
372 | }
|
373 | }
|
374 | ;
|
375 |
|
376 | class Vector extends Vector3d {
|
377 | constructor(xOrCoords, y) {
|
378 | super(xOrCoords, y, 0);
|
379 | }
|
380 | static get origin() {
|
381 | return Vector.create(0, 0);
|
382 | }
|
383 | static clone(source) {
|
384 | return Vector.create(source.x, source.y);
|
385 | }
|
386 | static create(x, y) {
|
387 | return new Vector(x, y);
|
388 | }
|
389 | }
|
390 | ;
|
391 |
|
392 | let _random = Math.random;
|
393 | const easings = new Map();
|
394 | function addEasing(name, easing) {
|
395 | if (!easings.get(name)) {
|
396 | easings.set(name, easing);
|
397 | }
|
398 | }
|
399 | function getEasing(name) {
|
400 | return easings.get(name) || (value => value);
|
401 | }
|
402 | function setRandom(rnd = Math.random) {
|
403 | _random = rnd;
|
404 | }
|
405 | function getRandom() {
|
406 | return clamp(_random(), 0, 1 - 1e-16);
|
407 | }
|
408 | function clamp(num, min, max) {
|
409 | return Math.min(Math.max(num, min), max);
|
410 | }
|
411 | function mix(comp1, comp2, weight1, weight2) {
|
412 | return Math.floor((comp1 * weight1 + comp2 * weight2) / (weight1 + weight2));
|
413 | }
|
414 | function randomInRange(r) {
|
415 | const max = getRangeMax(r);
|
416 | let min = getRangeMin(r);
|
417 | if (max === min) {
|
418 | min = 0;
|
419 | }
|
420 | return getRandom() * (max - min) + min;
|
421 | }
|
422 | function getRangeValue(value) {
|
423 | return typeof value === "number" ? value : randomInRange(value);
|
424 | }
|
425 | function getRangeMin(value) {
|
426 | return typeof value === "number" ? value : value.min;
|
427 | }
|
428 | function getRangeMax(value) {
|
429 | return typeof value === "number" ? value : value.max;
|
430 | }
|
431 | function setRangeValue(source, value) {
|
432 | if (source === value || value === undefined && typeof source === "number") {
|
433 | return source;
|
434 | }
|
435 | const min = getRangeMin(source),
|
436 | max = getRangeMax(source);
|
437 | return value !== undefined ? {
|
438 | min: Math.min(min, value),
|
439 | max: Math.max(max, value)
|
440 | } : setRangeValue(min, max);
|
441 | }
|
442 | function getValue(options) {
|
443 | const random = options.random,
|
444 | {
|
445 | enable,
|
446 | minimumValue
|
447 | } = typeof random === "boolean" ? {
|
448 | enable: random,
|
449 | minimumValue: 0
|
450 | } : random;
|
451 | return enable ? getRangeValue(setRangeValue(options.value, minimumValue)) : getRangeValue(options.value);
|
452 | }
|
453 | function getDistances(pointA, pointB) {
|
454 | const dx = pointA.x - pointB.x,
|
455 | dy = pointA.y - pointB.y;
|
456 | return {
|
457 | dx: dx,
|
458 | dy: dy,
|
459 | distance: Math.sqrt(dx ** 2 + dy ** 2)
|
460 | };
|
461 | }
|
462 | function getDistance(pointA, pointB) {
|
463 | return getDistances(pointA, pointB).distance;
|
464 | }
|
465 | function getParticleDirectionAngle(direction, position, center) {
|
466 | if (typeof direction === "number") {
|
467 | return direction * Math.PI / 180;
|
468 | } else {
|
469 | switch (direction) {
|
470 | case "top":
|
471 | return -Math.PI / 2;
|
472 | case "top-right":
|
473 | return -Math.PI / 4;
|
474 | case "right":
|
475 | return 0;
|
476 | case "bottom-right":
|
477 | return Math.PI / 4;
|
478 | case "bottom":
|
479 | return Math.PI / 2;
|
480 | case "bottom-left":
|
481 | return 3 * Math.PI / 4;
|
482 | case "left":
|
483 | return Math.PI;
|
484 | case "top-left":
|
485 | return -3 * Math.PI / 4;
|
486 | case "inside":
|
487 | return Math.atan2(center.y - position.y, center.x - position.x);
|
488 | case "outside":
|
489 | return Math.atan2(position.y - center.y, position.x - center.x);
|
490 | default:
|
491 | return getRandom() * Math.PI * 2;
|
492 | }
|
493 | }
|
494 | }
|
495 | function getParticleBaseVelocity(direction) {
|
496 | const baseVelocity = Vector.origin;
|
497 | baseVelocity.length = 1;
|
498 | baseVelocity.angle = direction;
|
499 | return baseVelocity;
|
500 | }
|
501 | function collisionVelocity(v1, v2, m1, m2) {
|
502 | return Vector.create(v1.x * (m1 - m2) / (m1 + m2) + v2.x * 2 * m2 / (m1 + m2), v1.y);
|
503 | }
|
504 | function calcPositionFromSize(data) {
|
505 | return data.position && data.position.x !== undefined && data.position.y !== undefined ? {
|
506 | x: data.position.x * data.size.width / 100,
|
507 | y: data.position.y * data.size.height / 100
|
508 | } : undefined;
|
509 | }
|
510 | function calcPositionOrRandomFromSize(data) {
|
511 | var _a, _b, _c, _d;
|
512 | return {
|
513 | x: ((_b = (_a = data.position) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : getRandom() * 100) * data.size.width / 100,
|
514 | y: ((_d = (_c = data.position) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : getRandom() * 100) * data.size.height / 100
|
515 | };
|
516 | }
|
517 | function calcPositionOrRandomFromSizeRanged(data) {
|
518 | var _a, _b;
|
519 | const position = {
|
520 | x: ((_a = data.position) === null || _a === void 0 ? void 0 : _a.x) !== undefined ? getRangeValue(data.position.x) : undefined,
|
521 | y: ((_b = data.position) === null || _b === void 0 ? void 0 : _b.y) !== undefined ? getRangeValue(data.position.y) : undefined
|
522 | };
|
523 | return calcPositionOrRandomFromSize({
|
524 | size: data.size,
|
525 | position
|
526 | });
|
527 | }
|
528 | function calcExactPositionOrRandomFromSize(data) {
|
529 | var _a, _b, _c, _d;
|
530 | return {
|
531 | x: (_b = (_a = data.position) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : getRandom() * data.size.width,
|
532 | y: (_d = (_c = data.position) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : getRandom() * data.size.height
|
533 | };
|
534 | }
|
535 | function calcExactPositionOrRandomFromSizeRanged(data) {
|
536 | var _a, _b;
|
537 | const position = {
|
538 | x: ((_a = data.position) === null || _a === void 0 ? void 0 : _a.x) !== undefined ? getRangeValue(data.position.x) : undefined,
|
539 | y: ((_b = data.position) === null || _b === void 0 ? void 0 : _b.y) !== undefined ? getRangeValue(data.position.y) : undefined
|
540 | };
|
541 | return calcExactPositionOrRandomFromSize({
|
542 | size: data.size,
|
543 | position
|
544 | });
|
545 | }
|
546 | function parseAlpha(input) {
|
547 | return input ? input.endsWith("%") ? parseFloat(input) / 100 : parseFloat(input) : 1;
|
548 | }
|
549 | ;
|
550 |
|
551 |
|
552 | function rectSideBounce(pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor) {
|
553 | const res = {
|
554 | bounced: false
|
555 | };
|
556 | if (pOtherSide.min < rectOtherSide.min || pOtherSide.min > rectOtherSide.max || pOtherSide.max < rectOtherSide.min || pOtherSide.max > rectOtherSide.max) {
|
557 | return res;
|
558 | }
|
559 | if (pSide.max >= rectSide.min && pSide.max <= (rectSide.max + rectSide.min) / 2 && velocity > 0 || pSide.min <= rectSide.max && pSide.min > (rectSide.max + rectSide.min) / 2 && velocity < 0) {
|
560 | res.velocity = velocity * -factor;
|
561 | res.bounced = true;
|
562 | }
|
563 | return res;
|
564 | }
|
565 | function checkSelector(element, selectors) {
|
566 | const res = executeOnSingleOrMultiple(selectors, selector => {
|
567 | return element.matches(selector);
|
568 | });
|
569 | return res instanceof Array ? res.some(t => t) : res;
|
570 | }
|
571 | function isSsr() {
|
572 | return typeof window === "undefined" || !window || typeof window.document === "undefined" || !window.document;
|
573 | }
|
574 | function hasMatchMedia() {
|
575 | return !isSsr() && typeof matchMedia !== "undefined";
|
576 | }
|
577 | function safeMatchMedia(query) {
|
578 | if (!hasMatchMedia()) {
|
579 | return;
|
580 | }
|
581 | return matchMedia(query);
|
582 | }
|
583 | function animate() {
|
584 | return isSsr() ? callback => setTimeout(callback) : callback => (requestAnimationFrame || setTimeout)(callback);
|
585 | }
|
586 | function cancelAnimation() {
|
587 | return isSsr() ? handle => clearTimeout(handle) : handle => (cancelAnimationFrame || clearTimeout)(handle);
|
588 | }
|
589 | function isInArray(value, array) {
|
590 | return value === array || array instanceof Array && array.indexOf(value) > -1;
|
591 | }
|
592 | async function loadFont(font, weight) {
|
593 | try {
|
594 | await document.fonts.load(`${weight !== null && weight !== void 0 ? weight : "400"} 36px '${font !== null && font !== void 0 ? font : "Verdana"}'`);
|
595 | } catch (_a) {}
|
596 | }
|
597 | function arrayRandomIndex(array) {
|
598 | return Math.floor(getRandom() * array.length);
|
599 | }
|
600 | function itemFromArray(array, index, useIndex = true) {
|
601 | return array[index !== undefined && useIndex ? index % array.length : arrayRandomIndex(array)];
|
602 | }
|
603 | function isPointInside(point, size, offset, radius, direction) {
|
604 | return areBoundsInside(calculateBounds(point, radius !== null && radius !== void 0 ? radius : 0), size, offset, direction);
|
605 | }
|
606 | function areBoundsInside(bounds, size, offset, direction) {
|
607 | let inside = true;
|
608 | if (!direction || direction === "bottom") {
|
609 | inside = bounds.top < size.height + offset.x;
|
610 | }
|
611 | if (inside && (!direction || direction === "left")) {
|
612 | inside = bounds.right > offset.x;
|
613 | }
|
614 | if (inside && (!direction || direction === "right")) {
|
615 | inside = bounds.left < size.width + offset.y;
|
616 | }
|
617 | if (inside && (!direction || direction === "top")) {
|
618 | inside = bounds.bottom > offset.y;
|
619 | }
|
620 | return inside;
|
621 | }
|
622 | function calculateBounds(point, radius) {
|
623 | return {
|
624 | bottom: point.y + radius,
|
625 | left: point.x - radius,
|
626 | right: point.x + radius,
|
627 | top: point.y - radius
|
628 | };
|
629 | }
|
630 | function deepExtend(destination, ...sources) {
|
631 | for (const source of sources) {
|
632 | if (source === undefined || source === null) {
|
633 | continue;
|
634 | }
|
635 | if (typeof source !== "object") {
|
636 | destination = source;
|
637 | continue;
|
638 | }
|
639 | const sourceIsArray = Array.isArray(source);
|
640 | if (sourceIsArray && (typeof destination !== "object" || !destination || !Array.isArray(destination))) {
|
641 | destination = [];
|
642 | } else if (!sourceIsArray && (typeof destination !== "object" || !destination || Array.isArray(destination))) {
|
643 | destination = {};
|
644 | }
|
645 | for (const key in source) {
|
646 | if (key === "__proto__") {
|
647 | continue;
|
648 | }
|
649 | const sourceDict = source,
|
650 | value = sourceDict[key],
|
651 | isObject = typeof value === "object",
|
652 | destDict = destination;
|
653 | destDict[key] = isObject && Array.isArray(value) ? value.map(v => deepExtend(destDict[key], v)) : deepExtend(destDict[key], value);
|
654 | }
|
655 | }
|
656 | return destination;
|
657 | }
|
658 | function isDivModeEnabled(mode, divs) {
|
659 | return !!findItemFromSingleOrMultiple(divs, t => t.enable && isInArray(mode, t.mode));
|
660 | }
|
661 | function divModeExecute(mode, divs, callback) {
|
662 | executeOnSingleOrMultiple(divs, div => {
|
663 | const divMode = div.mode,
|
664 | divEnabled = div.enable;
|
665 | if (divEnabled && isInArray(mode, divMode)) {
|
666 | singleDivModeExecute(div, callback);
|
667 | }
|
668 | });
|
669 | }
|
670 | function singleDivModeExecute(div, callback) {
|
671 | const selectors = div.selectors;
|
672 | executeOnSingleOrMultiple(selectors, selector => {
|
673 | callback(selector, div);
|
674 | });
|
675 | }
|
676 | function divMode(divs, element) {
|
677 | if (!element || !divs) {
|
678 | return;
|
679 | }
|
680 | return findItemFromSingleOrMultiple(divs, div => {
|
681 | return checkSelector(element, div.selectors);
|
682 | });
|
683 | }
|
684 | function circleBounceDataFromParticle(p) {
|
685 | return {
|
686 | position: p.getPosition(),
|
687 | radius: p.getRadius(),
|
688 | mass: p.getMass(),
|
689 | velocity: p.velocity,
|
690 | factor: Vector.create(getValue(p.options.bounce.horizontal), getValue(p.options.bounce.vertical))
|
691 | };
|
692 | }
|
693 | function circleBounce(p1, p2) {
|
694 | const {
|
695 | x: xVelocityDiff,
|
696 | y: yVelocityDiff
|
697 | } = p1.velocity.sub(p2.velocity),
|
698 | [pos1, pos2] = [p1.position, p2.position],
|
699 | {
|
700 | dx: xDist,
|
701 | dy: yDist
|
702 | } = getDistances(pos2, pos1);
|
703 | if (xVelocityDiff * xDist + yVelocityDiff * yDist < 0) {
|
704 | return;
|
705 | }
|
706 | const angle = -Math.atan2(yDist, xDist),
|
707 | m1 = p1.mass,
|
708 | m2 = p2.mass,
|
709 | u1 = p1.velocity.rotate(angle),
|
710 | u2 = p2.velocity.rotate(angle),
|
711 | v1 = collisionVelocity(u1, u2, m1, m2),
|
712 | v2 = collisionVelocity(u2, u1, m1, m2),
|
713 | vFinal1 = v1.rotate(-angle),
|
714 | vFinal2 = v2.rotate(-angle);
|
715 | p1.velocity.x = vFinal1.x * p1.factor.x;
|
716 | p1.velocity.y = vFinal1.y * p1.factor.y;
|
717 | p2.velocity.x = vFinal2.x * p2.factor.x;
|
718 | p2.velocity.y = vFinal2.y * p2.factor.y;
|
719 | }
|
720 | function rectBounce(particle, divBounds) {
|
721 | const pPos = particle.getPosition(),
|
722 | size = particle.getRadius(),
|
723 | bounds = calculateBounds(pPos, size),
|
724 | resH = rectSideBounce({
|
725 | min: bounds.left,
|
726 | max: bounds.right
|
727 | }, {
|
728 | min: bounds.top,
|
729 | max: bounds.bottom
|
730 | }, {
|
731 | min: divBounds.left,
|
732 | max: divBounds.right
|
733 | }, {
|
734 | min: divBounds.top,
|
735 | max: divBounds.bottom
|
736 | }, particle.velocity.x, getValue(particle.options.bounce.horizontal));
|
737 | if (resH.bounced) {
|
738 | if (resH.velocity !== undefined) {
|
739 | particle.velocity.x = resH.velocity;
|
740 | }
|
741 | if (resH.position !== undefined) {
|
742 | particle.position.x = resH.position;
|
743 | }
|
744 | }
|
745 | const resV = rectSideBounce({
|
746 | min: bounds.top,
|
747 | max: bounds.bottom
|
748 | }, {
|
749 | min: bounds.left,
|
750 | max: bounds.right
|
751 | }, {
|
752 | min: divBounds.top,
|
753 | max: divBounds.bottom
|
754 | }, {
|
755 | min: divBounds.left,
|
756 | max: divBounds.right
|
757 | }, particle.velocity.y, getValue(particle.options.bounce.vertical));
|
758 | if (resV.bounced) {
|
759 | if (resV.velocity !== undefined) {
|
760 | particle.velocity.y = resV.velocity;
|
761 | }
|
762 | if (resV.position !== undefined) {
|
763 | particle.position.y = resV.position;
|
764 | }
|
765 | }
|
766 | }
|
767 | function executeOnSingleOrMultiple(obj, callback) {
|
768 | return obj instanceof Array ? obj.map((item, index) => callback(item, index)) : callback(obj, 0);
|
769 | }
|
770 | function itemFromSingleOrMultiple(obj, index, useIndex) {
|
771 | return obj instanceof Array ? itemFromArray(obj, index, useIndex) : obj;
|
772 | }
|
773 | function findItemFromSingleOrMultiple(obj, callback) {
|
774 | return obj instanceof Array ? obj.find((t, index) => callback(t, index)) : callback(obj, 0) ? obj : undefined;
|
775 | }
|
776 | ;
|
777 |
|
778 |
|
779 | const randomColorValue = "random",
|
780 | midColorValue = "mid",
|
781 | colorManagers = new Map();
|
782 | function addColorManager(manager) {
|
783 | colorManagers.set(manager.key, manager);
|
784 | }
|
785 | function hue2rgb(p, q, t) {
|
786 | if (t < 0) {
|
787 | t += 1;
|
788 | }
|
789 | if (t > 1) {
|
790 | t -= 1;
|
791 | }
|
792 | if (t < 1 / 6) {
|
793 | return p + (q - p) * 6 * t;
|
794 | }
|
795 | if (t < 1 / 2) {
|
796 | return q;
|
797 | }
|
798 | if (t < 2 / 3) {
|
799 | return p + (q - p) * (2 / 3 - t) * 6;
|
800 | }
|
801 | return p;
|
802 | }
|
803 | function stringToRgba(input) {
|
804 | for (const [, manager] of colorManagers) {
|
805 | if (input.startsWith(manager.stringPrefix)) {
|
806 | return manager.parseString(input);
|
807 | }
|
808 | }
|
809 | const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i,
|
810 | hexFixed = input.replace(shorthandRegex, (_, r, g, b, a) => {
|
811 | return r + r + g + g + b + b + (a !== undefined ? a + a : "");
|
812 | }),
|
813 | regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i,
|
814 | result = regex.exec(hexFixed);
|
815 | return result ? {
|
816 | a: result[4] !== undefined ? parseInt(result[4], 16) / 0xff : 1,
|
817 | b: parseInt(result[3], 16),
|
818 | g: parseInt(result[2], 16),
|
819 | r: parseInt(result[1], 16)
|
820 | } : undefined;
|
821 | }
|
822 | function rangeColorToRgb(input, index, useIndex = true) {
|
823 | if (!input) {
|
824 | return;
|
825 | }
|
826 | const color = typeof input === "string" ? {
|
827 | value: input
|
828 | } : input;
|
829 | if (typeof color.value === "string") {
|
830 | return colorToRgb(color.value, index, useIndex);
|
831 | }
|
832 | if (color.value instanceof Array) {
|
833 | return rangeColorToRgb({
|
834 | value: itemFromArray(color.value, index, useIndex)
|
835 | });
|
836 | }
|
837 | for (const [, manager] of colorManagers) {
|
838 | const res = manager.handleRangeColor(color);
|
839 | if (res) {
|
840 | return res;
|
841 | }
|
842 | }
|
843 | }
|
844 | function colorToRgb(input, index, useIndex = true) {
|
845 | if (!input) {
|
846 | return;
|
847 | }
|
848 | const color = typeof input === "string" ? {
|
849 | value: input
|
850 | } : input;
|
851 | if (typeof color.value === "string") {
|
852 | return color.value === randomColorValue ? getRandomRgbColor() : stringToRgb(color.value);
|
853 | }
|
854 | if (color.value instanceof Array) {
|
855 | return colorToRgb({
|
856 | value: itemFromArray(color.value, index, useIndex)
|
857 | });
|
858 | }
|
859 | for (const [, manager] of colorManagers) {
|
860 | const res = manager.handleColor(color);
|
861 | if (res) {
|
862 | return res;
|
863 | }
|
864 | }
|
865 | }
|
866 | function colorToHsl(color, index, useIndex = true) {
|
867 | const rgb = colorToRgb(color, index, useIndex);
|
868 | return rgb ? rgbToHsl(rgb) : undefined;
|
869 | }
|
870 | function rangeColorToHsl(color, index, useIndex = true) {
|
871 | const rgb = rangeColorToRgb(color, index, useIndex);
|
872 | return rgb ? rgbToHsl(rgb) : undefined;
|
873 | }
|
874 | function rgbToHsl(color) {
|
875 | const r1 = color.r / 255,
|
876 | g1 = color.g / 255,
|
877 | b1 = color.b / 255,
|
878 | max = Math.max(r1, g1, b1),
|
879 | min = Math.min(r1, g1, b1),
|
880 | res = {
|
881 | h: 0,
|
882 | l: (max + min) / 2,
|
883 | s: 0
|
884 | };
|
885 | if (max !== min) {
|
886 | res.s = res.l < 0.5 ? (max - min) / (max + min) : (max - min) / (2.0 - max - min);
|
887 | res.h = r1 === max ? (g1 - b1) / (max - min) : res.h = g1 === max ? 2.0 + (b1 - r1) / (max - min) : 4.0 + (r1 - g1) / (max - min);
|
888 | }
|
889 | res.l *= 100;
|
890 | res.s *= 100;
|
891 | res.h *= 60;
|
892 | if (res.h < 0) {
|
893 | res.h += 360;
|
894 | }
|
895 | if (res.h >= 360) {
|
896 | res.h -= 360;
|
897 | }
|
898 | return res;
|
899 | }
|
900 | function stringToAlpha(input) {
|
901 | var _a;
|
902 | return (_a = stringToRgba(input)) === null || _a === void 0 ? void 0 : _a.a;
|
903 | }
|
904 | function stringToRgb(input) {
|
905 | return stringToRgba(input);
|
906 | }
|
907 | function hslToRgb(hsl) {
|
908 | const result = {
|
909 | b: 0,
|
910 | g: 0,
|
911 | r: 0
|
912 | },
|
913 | hslPercent = {
|
914 | h: hsl.h / 360,
|
915 | l: hsl.l / 100,
|
916 | s: hsl.s / 100
|
917 | };
|
918 | if (!hslPercent.s) {
|
919 | result.b = hslPercent.l;
|
920 | result.g = hslPercent.l;
|
921 | result.r = hslPercent.l;
|
922 | } else {
|
923 | const q = hslPercent.l < 0.5 ? hslPercent.l * (1 + hslPercent.s) : hslPercent.l + hslPercent.s - hslPercent.l * hslPercent.s,
|
924 | p = 2 * hslPercent.l - q;
|
925 | result.r = hue2rgb(p, q, hslPercent.h + 1 / 3);
|
926 | result.g = hue2rgb(p, q, hslPercent.h);
|
927 | result.b = hue2rgb(p, q, hslPercent.h - 1 / 3);
|
928 | }
|
929 | result.r = Math.floor(result.r * 255);
|
930 | result.g = Math.floor(result.g * 255);
|
931 | result.b = Math.floor(result.b * 255);
|
932 | return result;
|
933 | }
|
934 | function hslaToRgba(hsla) {
|
935 | const rgbResult = hslToRgb(hsla);
|
936 | return {
|
937 | a: hsla.a,
|
938 | b: rgbResult.b,
|
939 | g: rgbResult.g,
|
940 | r: rgbResult.r
|
941 | };
|
942 | }
|
943 | function getRandomRgbColor(min) {
|
944 | const fixedMin = min !== null && min !== void 0 ? min : 0;
|
945 | return {
|
946 | b: Math.floor(randomInRange(setRangeValue(fixedMin, 256))),
|
947 | g: Math.floor(randomInRange(setRangeValue(fixedMin, 256))),
|
948 | r: Math.floor(randomInRange(setRangeValue(fixedMin, 256)))
|
949 | };
|
950 | }
|
951 | function getStyleFromRgb(color, opacity) {
|
952 | return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
|
953 | }
|
954 | function getStyleFromHsl(color, opacity) {
|
955 | return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
|
956 | }
|
957 | function colorMix(color1, color2, size1, size2) {
|
958 | let rgb1 = color1,
|
959 | rgb2 = color2;
|
960 | if (rgb1.r === undefined) {
|
961 | rgb1 = hslToRgb(color1);
|
962 | }
|
963 | if (rgb2.r === undefined) {
|
964 | rgb2 = hslToRgb(color2);
|
965 | }
|
966 | return {
|
967 | b: mix(rgb1.b, rgb2.b, size1, size2),
|
968 | g: mix(rgb1.g, rgb2.g, size1, size2),
|
969 | r: mix(rgb1.r, rgb2.r, size1, size2)
|
970 | };
|
971 | }
|
972 | function getLinkColor(p1, p2, linkColor) {
|
973 | var _a, _b;
|
974 | if (linkColor === randomColorValue) {
|
975 | return getRandomRgbColor();
|
976 | } else if (linkColor === midColorValue) {
|
977 | const sourceColor = (_a = p1.getFillColor()) !== null && _a !== void 0 ? _a : p1.getStrokeColor(),
|
978 | destColor = (_b = p2 === null || p2 === void 0 ? void 0 : p2.getFillColor()) !== null && _b !== void 0 ? _b : p2 === null || p2 === void 0 ? void 0 : p2.getStrokeColor();
|
979 | if (sourceColor && destColor && p2) {
|
980 | return colorMix(sourceColor, destColor, p1.getRadius(), p2.getRadius());
|
981 | } else {
|
982 | const hslColor = sourceColor !== null && sourceColor !== void 0 ? sourceColor : destColor;
|
983 | if (hslColor) {
|
984 | return hslToRgb(hslColor);
|
985 | }
|
986 | }
|
987 | } else {
|
988 | return linkColor;
|
989 | }
|
990 | }
|
991 | function getLinkRandomColor(optColor, blink, consent) {
|
992 | const color = typeof optColor === "string" ? optColor : optColor.value;
|
993 | if (color === randomColorValue) {
|
994 | if (consent) {
|
995 | return rangeColorToRgb({
|
996 | value: color
|
997 | });
|
998 | }
|
999 | if (blink) {
|
1000 | return randomColorValue;
|
1001 | }
|
1002 | return midColorValue;
|
1003 | } else if (color === midColorValue) {
|
1004 | return midColorValue;
|
1005 | } else {
|
1006 | return rangeColorToRgb({
|
1007 | value: color
|
1008 | });
|
1009 | }
|
1010 | }
|
1011 | function getHslFromAnimation(animation) {
|
1012 | return animation !== undefined ? {
|
1013 | h: animation.h.value,
|
1014 | s: animation.s.value,
|
1015 | l: animation.l.value
|
1016 | } : undefined;
|
1017 | }
|
1018 | function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
|
1019 | const resColor = {
|
1020 | h: {
|
1021 | enable: false,
|
1022 | value: hsl.h
|
1023 | },
|
1024 | s: {
|
1025 | enable: false,
|
1026 | value: hsl.s
|
1027 | },
|
1028 | l: {
|
1029 | enable: false,
|
1030 | value: hsl.l
|
1031 | }
|
1032 | };
|
1033 | if (animationOptions) {
|
1034 | setColorAnimation(resColor.h, animationOptions.h, reduceFactor);
|
1035 | setColorAnimation(resColor.s, animationOptions.s, reduceFactor);
|
1036 | setColorAnimation(resColor.l, animationOptions.l, reduceFactor);
|
1037 | }
|
1038 | return resColor;
|
1039 | }
|
1040 | function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
|
1041 | colorValue.enable = colorAnimation.enable;
|
1042 | if (colorValue.enable) {
|
1043 | colorValue.velocity = getRangeValue(colorAnimation.speed) / 100 * reduceFactor;
|
1044 | colorValue.decay = 1 - getRangeValue(colorAnimation.decay);
|
1045 | colorValue.status = "increasing";
|
1046 | colorValue.loops = 0;
|
1047 | colorValue.maxLoops = getRangeValue(colorAnimation.count);
|
1048 | if (!colorAnimation.sync) {
|
1049 | colorValue.velocity *= getRandom();
|
1050 | colorValue.value *= getRandom();
|
1051 | }
|
1052 | colorValue.initialValue = colorValue.value;
|
1053 | } else {
|
1054 | colorValue.velocity = 0;
|
1055 | }
|
1056 | }
|
1057 | ;
|
1058 |
|
1059 | function drawLine(context, begin, end) {
|
1060 | context.beginPath();
|
1061 | context.moveTo(begin.x, begin.y);
|
1062 | context.lineTo(end.x, end.y);
|
1063 | context.closePath();
|
1064 | }
|
1065 | function drawTriangle(context, p1, p2, p3) {
|
1066 | context.beginPath();
|
1067 | context.moveTo(p1.x, p1.y);
|
1068 | context.lineTo(p2.x, p2.y);
|
1069 | context.lineTo(p3.x, p3.y);
|
1070 | context.closePath();
|
1071 | }
|
1072 | function paintBase(context, dimension, baseColor) {
|
1073 | context.fillStyle = baseColor !== null && baseColor !== void 0 ? baseColor : "rgba(0,0,0,0)";
|
1074 | context.fillRect(0, 0, dimension.width, dimension.height);
|
1075 | }
|
1076 | function paintImage(context, dimension, image, opacity) {
|
1077 | if (!image) {
|
1078 | return;
|
1079 | }
|
1080 | context.globalAlpha = opacity;
|
1081 | context.drawImage(image, 0, 0, dimension.width, dimension.height);
|
1082 | context.globalAlpha = 1;
|
1083 | }
|
1084 | function clear(context, dimension) {
|
1085 | context.clearRect(0, 0, dimension.width, dimension.height);
|
1086 | }
|
1087 | function drawParticle(data) {
|
1088 | var _a, _b, _c, _d, _e;
|
1089 | const {
|
1090 | container,
|
1091 | context,
|
1092 | particle,
|
1093 | delta,
|
1094 | colorStyles,
|
1095 | backgroundMask,
|
1096 | composite,
|
1097 | radius,
|
1098 | opacity,
|
1099 | shadow,
|
1100 | transform
|
1101 | } = data;
|
1102 | const pos = particle.getPosition(),
|
1103 | angle = particle.rotation + (particle.pathRotation ? particle.velocity.angle : 0),
|
1104 | rotateData = {
|
1105 | sin: Math.sin(angle),
|
1106 | cos: Math.cos(angle)
|
1107 | },
|
1108 | transformData = {
|
1109 | a: rotateData.cos * ((_a = transform.a) !== null && _a !== void 0 ? _a : 1),
|
1110 | b: rotateData.sin * ((_b = transform.b) !== null && _b !== void 0 ? _b : 1),
|
1111 | c: -rotateData.sin * ((_c = transform.c) !== null && _c !== void 0 ? _c : 1),
|
1112 | d: rotateData.cos * ((_d = transform.d) !== null && _d !== void 0 ? _d : 1)
|
1113 | };
|
1114 | context.setTransform(transformData.a, transformData.b, transformData.c, transformData.d, pos.x, pos.y);
|
1115 | context.beginPath();
|
1116 | if (backgroundMask) {
|
1117 | context.globalCompositeOperation = composite;
|
1118 | }
|
1119 | const shadowColor = particle.shadowColor;
|
1120 | if (shadow.enable && shadowColor) {
|
1121 | context.shadowBlur = shadow.blur;
|
1122 | context.shadowColor = getStyleFromRgb(shadowColor);
|
1123 | context.shadowOffsetX = shadow.offset.x;
|
1124 | context.shadowOffsetY = shadow.offset.y;
|
1125 | }
|
1126 | if (colorStyles.fill) {
|
1127 | context.fillStyle = colorStyles.fill;
|
1128 | }
|
1129 | const strokeWidth = (_e = particle.strokeWidth) !== null && _e !== void 0 ? _e : 0;
|
1130 | context.lineWidth = strokeWidth;
|
1131 | if (colorStyles.stroke) {
|
1132 | context.strokeStyle = colorStyles.stroke;
|
1133 | }
|
1134 | drawShape(container, context, particle, radius, opacity, delta);
|
1135 | if (strokeWidth > 0) {
|
1136 | context.stroke();
|
1137 | }
|
1138 | if (particle.close) {
|
1139 | context.closePath();
|
1140 | }
|
1141 | if (particle.fill) {
|
1142 | context.fill();
|
1143 | }
|
1144 | drawShapeAfterEffect(container, context, particle, radius, opacity, delta);
|
1145 | context.globalCompositeOperation = "source-over";
|
1146 | context.setTransform(1, 0, 0, 1, 0, 0);
|
1147 | }
|
1148 | function drawShape(container, context, particle, radius, opacity, delta) {
|
1149 | if (!particle.shape) {
|
1150 | return;
|
1151 | }
|
1152 | const drawer = container.drawers.get(particle.shape);
|
1153 | if (!drawer) {
|
1154 | return;
|
1155 | }
|
1156 | drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
1157 | }
|
1158 | function drawShapeAfterEffect(container, context, particle, radius, opacity, delta) {
|
1159 | if (!particle.shape) {
|
1160 | return;
|
1161 | }
|
1162 | const drawer = container.drawers.get(particle.shape);
|
1163 | if (!(drawer === null || drawer === void 0 ? void 0 : drawer.afterEffect)) {
|
1164 | return;
|
1165 | }
|
1166 | drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
1167 | }
|
1168 | function drawPlugin(context, plugin, delta) {
|
1169 | if (!plugin.draw) {
|
1170 | return;
|
1171 | }
|
1172 | plugin.draw(context, delta);
|
1173 | }
|
1174 | function drawParticlePlugin(context, plugin, particle, delta) {
|
1175 | if (!plugin.drawParticle) {
|
1176 | return;
|
1177 | }
|
1178 | plugin.drawParticle(context, particle, delta);
|
1179 | }
|
1180 | function alterHsl(color, type, value) {
|
1181 | return {
|
1182 | h: color.h,
|
1183 | s: color.s,
|
1184 | l: color.l + (type === "darken" ? -1 : 1) * value
|
1185 | };
|
1186 | }
|
1187 | ;
|
1188 | const generatedAttribute = "generated";
|
1189 | const touchEndEvent = "touchend";
|
1190 | const mouseDownEvent = "pointerdown";
|
1191 | const mouseUpEvent = "pointerup";
|
1192 | const mouseMoveEvent = "pointermove";
|
1193 | const touchStartEvent = "touchstart";
|
1194 | const touchMoveEvent = "touchmove";
|
1195 | const mouseLeaveEvent = "pointerleave";
|
1196 | const mouseOutEvent = "pointerout";
|
1197 | const touchCancelEvent = "touchcancel";
|
1198 | const resizeEvent = "resize";
|
1199 | const visibilityChangeEvent = "visibilitychange";
|
1200 | ;
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 | function setTransformValue(factor, newFactor, key) {
|
1206 | var _a;
|
1207 | const newValue = newFactor[key];
|
1208 | if (newValue !== undefined) {
|
1209 | factor[key] = ((_a = factor[key]) !== null && _a !== void 0 ? _a : 1) * newValue;
|
1210 | }
|
1211 | }
|
1212 | class Canvas {
|
1213 | constructor(container) {
|
1214 | this.container = container;
|
1215 | this.size = {
|
1216 | height: 0,
|
1217 | width: 0
|
1218 | };
|
1219 | this._context = null;
|
1220 | this._generated = false;
|
1221 | this._preDrawUpdaters = [];
|
1222 | this._postDrawUpdaters = [];
|
1223 | this._resizePlugins = [];
|
1224 | this._colorPlugins = [];
|
1225 | this._mutationObserver = !isSsr() && typeof MutationObserver !== "undefined" ? new MutationObserver(records => {
|
1226 | for (const record of records) {
|
1227 | if (record.type === "attributes" && record.attributeName === "style") {
|
1228 | this._repairStyle();
|
1229 | }
|
1230 | }
|
1231 | }) : undefined;
|
1232 | }
|
1233 | get _fullScreen() {
|
1234 | return this.container.actualOptions.fullScreen.enable;
|
1235 | }
|
1236 | clear() {
|
1237 | const options = this.container.actualOptions,
|
1238 | trail = options.particles.move.trail,
|
1239 | trailFill = this._trailFill;
|
1240 | if (options.backgroundMask.enable) {
|
1241 | this.paint();
|
1242 | } else if (trail.enable && trail.length > 0 && trailFill) {
|
1243 | if (trailFill.color) {
|
1244 | this._paintBase(getStyleFromRgb(trailFill.color, trailFill.opacity));
|
1245 | } else if (trailFill.image) {
|
1246 | this._paintImage(trailFill.image, trailFill.opacity);
|
1247 | }
|
1248 | } else {
|
1249 | this.draw(ctx => {
|
1250 | clear(ctx, this.size);
|
1251 | });
|
1252 | }
|
1253 | }
|
1254 | destroy() {
|
1255 | var _a, _b;
|
1256 | (_a = this._mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
1257 | if (this._generated) {
|
1258 | (_b = this.element) === null || _b === void 0 ? void 0 : _b.remove();
|
1259 | } else {
|
1260 | this._resetOriginalStyle();
|
1261 | }
|
1262 | this.draw(ctx => {
|
1263 | clear(ctx, this.size);
|
1264 | });
|
1265 | this._preDrawUpdaters = [];
|
1266 | this._postDrawUpdaters = [];
|
1267 | this._resizePlugins = [];
|
1268 | this._colorPlugins = [];
|
1269 | }
|
1270 | draw(cb) {
|
1271 | if (!this._context) {
|
1272 | return;
|
1273 | }
|
1274 | return cb(this._context);
|
1275 | }
|
1276 | drawParticle(particle, delta) {
|
1277 | var _a;
|
1278 | if (particle.spawning || particle.destroyed) {
|
1279 | return;
|
1280 | }
|
1281 | const radius = particle.getRadius();
|
1282 | if (radius <= 0) {
|
1283 | return;
|
1284 | }
|
1285 | const pfColor = particle.getFillColor(),
|
1286 | psColor = (_a = particle.getStrokeColor()) !== null && _a !== void 0 ? _a : pfColor;
|
1287 | let [fColor, sColor] = this._getPluginParticleColors(particle);
|
1288 | if (!fColor) {
|
1289 | fColor = pfColor;
|
1290 | }
|
1291 | if (!sColor) {
|
1292 | sColor = psColor;
|
1293 | }
|
1294 | if (!fColor && !sColor) {
|
1295 | return;
|
1296 | }
|
1297 | this.draw(ctx => {
|
1298 | var _a, _b, _c, _d;
|
1299 | const options = this.container.actualOptions,
|
1300 | zIndexOptions = particle.options.zIndex,
|
1301 | zOpacityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.opacityRate,
|
1302 | opacity = (_c = (_a = particle.bubble.opacity) !== null && _a !== void 0 ? _a : (_b = particle.opacity) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : 1,
|
1303 | strokeOpacity = (_d = particle.strokeOpacity) !== null && _d !== void 0 ? _d : opacity,
|
1304 | zOpacity = opacity * zOpacityFactor,
|
1305 | zStrokeOpacity = strokeOpacity * zOpacityFactor,
|
1306 | transform = {},
|
1307 | colorStyles = {
|
1308 | fill: fColor ? getStyleFromHsl(fColor, zOpacity) : undefined
|
1309 | };
|
1310 | colorStyles.stroke = sColor ? getStyleFromHsl(sColor, zStrokeOpacity) : colorStyles.fill;
|
1311 | this._applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform);
|
1312 | drawParticle({
|
1313 | container: this.container,
|
1314 | context: ctx,
|
1315 | particle,
|
1316 | delta,
|
1317 | colorStyles,
|
1318 | backgroundMask: options.backgroundMask.enable,
|
1319 | composite: options.backgroundMask.composite,
|
1320 | radius: radius * (1 - particle.zIndexFactor) ** zIndexOptions.sizeRate,
|
1321 | opacity: zOpacity,
|
1322 | shadow: particle.options.shadow,
|
1323 | transform
|
1324 | });
|
1325 | this._applyPostDrawUpdaters(particle);
|
1326 | });
|
1327 | }
|
1328 | drawParticlePlugin(plugin, particle, delta) {
|
1329 | this.draw(ctx => {
|
1330 | drawParticlePlugin(ctx, plugin, particle, delta);
|
1331 | });
|
1332 | }
|
1333 | drawPlugin(plugin, delta) {
|
1334 | this.draw(ctx => {
|
1335 | drawPlugin(ctx, plugin, delta);
|
1336 | });
|
1337 | }
|
1338 | async init() {
|
1339 | var _a;
|
1340 | this.resize();
|
1341 | this._initStyle();
|
1342 | this._initCover();
|
1343 | try {
|
1344 | await this._initTrail();
|
1345 | } catch (e) {
|
1346 | console.error(e);
|
1347 | }
|
1348 | this.initBackground();
|
1349 | if (this.element) {
|
1350 | (_a = this._mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.element, {
|
1351 | attributes: true
|
1352 | });
|
1353 | }
|
1354 | this.initUpdaters();
|
1355 | this.initPlugins();
|
1356 | this.paint();
|
1357 | }
|
1358 | initBackground() {
|
1359 | const options = this.container.actualOptions,
|
1360 | background = options.background,
|
1361 | element = this.element,
|
1362 | elementStyle = element === null || element === void 0 ? void 0 : element.style;
|
1363 | if (!elementStyle) {
|
1364 | return;
|
1365 | }
|
1366 | if (background.color) {
|
1367 | const color = rangeColorToRgb(background.color);
|
1368 | elementStyle.backgroundColor = color ? getStyleFromRgb(color, background.opacity) : "";
|
1369 | } else {
|
1370 | elementStyle.backgroundColor = "";
|
1371 | }
|
1372 | elementStyle.backgroundImage = background.image || "";
|
1373 | elementStyle.backgroundPosition = background.position || "";
|
1374 | elementStyle.backgroundRepeat = background.repeat || "";
|
1375 | elementStyle.backgroundSize = background.size || "";
|
1376 | }
|
1377 | initPlugins() {
|
1378 | this._resizePlugins = [];
|
1379 | for (const [, plugin] of this.container.plugins) {
|
1380 | if (plugin.resize) {
|
1381 | this._resizePlugins.push(plugin);
|
1382 | }
|
1383 | if (plugin.particleFillColor || plugin.particleStrokeColor) {
|
1384 | this._colorPlugins.push(plugin);
|
1385 | }
|
1386 | }
|
1387 | }
|
1388 | initUpdaters() {
|
1389 | this._preDrawUpdaters = [];
|
1390 | this._postDrawUpdaters = [];
|
1391 | for (const updater of this.container.particles.updaters) {
|
1392 | if (updater.afterDraw) {
|
1393 | this._postDrawUpdaters.push(updater);
|
1394 | }
|
1395 | if (updater.getColorStyles || updater.getTransformValues || updater.beforeDraw) {
|
1396 | this._preDrawUpdaters.push(updater);
|
1397 | }
|
1398 | }
|
1399 | }
|
1400 | loadCanvas(canvas) {
|
1401 | var _a, _b;
|
1402 | if (this._generated) {
|
1403 | (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
|
1404 | }
|
1405 | this._generated = canvas.dataset && generatedAttribute in canvas.dataset ? canvas.dataset[generatedAttribute] === "true" : this._generated;
|
1406 | this.element = canvas;
|
1407 | this.element.ariaHidden = "true";
|
1408 | this._originalStyle = deepExtend({}, this.element.style);
|
1409 | this.size.height = canvas.offsetHeight;
|
1410 | this.size.width = canvas.offsetWidth;
|
1411 | this._context = this.element.getContext("2d");
|
1412 | (_b = this._mutationObserver) === null || _b === void 0 ? void 0 : _b.observe(this.element, {
|
1413 | attributes: true
|
1414 | });
|
1415 | this.container.retina.init();
|
1416 | this.initBackground();
|
1417 | }
|
1418 | paint() {
|
1419 | const options = this.container.actualOptions;
|
1420 | this.draw(ctx => {
|
1421 | if (options.backgroundMask.enable && options.backgroundMask.cover) {
|
1422 | clear(ctx, this.size);
|
1423 | this._paintBase(this._coverColorStyle);
|
1424 | } else {
|
1425 | this._paintBase();
|
1426 | }
|
1427 | });
|
1428 | }
|
1429 | resize() {
|
1430 | if (!this.element) {
|
1431 | return;
|
1432 | }
|
1433 | const container = this.container,
|
1434 | pxRatio = container.retina.pixelRatio,
|
1435 | size = container.canvas.size,
|
1436 | newSize = {
|
1437 | width: this.element.offsetWidth * pxRatio,
|
1438 | height: this.element.offsetHeight * pxRatio
|
1439 | };
|
1440 | if (newSize.height === size.height && newSize.width === size.width && newSize.height === this.element.height && newSize.width === this.element.width) {
|
1441 | return;
|
1442 | }
|
1443 | const oldSize = Object.assign({}, size);
|
1444 | this.element.width = size.width = this.element.offsetWidth * pxRatio;
|
1445 | this.element.height = size.height = this.element.offsetHeight * pxRatio;
|
1446 | if (this.container.started) {
|
1447 | this.resizeFactor = {
|
1448 | width: size.width / oldSize.width,
|
1449 | height: size.height / oldSize.height
|
1450 | };
|
1451 | }
|
1452 | }
|
1453 | async windowResize() {
|
1454 | if (!this.element) {
|
1455 | return;
|
1456 | }
|
1457 | this.resize();
|
1458 | const container = this.container,
|
1459 | needsRefresh = container.updateActualOptions();
|
1460 | container.particles.setDensity();
|
1461 | this._applyResizePlugins();
|
1462 | if (needsRefresh) {
|
1463 | await container.refresh();
|
1464 | }
|
1465 | }
|
1466 | _applyPostDrawUpdaters(particle) {
|
1467 | var _a;
|
1468 | for (const updater of this._postDrawUpdaters) {
|
1469 | (_a = updater.afterDraw) === null || _a === void 0 ? void 0 : _a.call(updater, particle);
|
1470 | }
|
1471 | }
|
1472 | _applyPreDrawUpdaters(ctx, particle, radius, zOpacity, colorStyles, transform) {
|
1473 | var _a;
|
1474 | for (const updater of this._preDrawUpdaters) {
|
1475 | if (updater.getColorStyles) {
|
1476 | const {
|
1477 | fill,
|
1478 | stroke
|
1479 | } = updater.getColorStyles(particle, ctx, radius, zOpacity);
|
1480 | if (fill) {
|
1481 | colorStyles.fill = fill;
|
1482 | }
|
1483 | if (stroke) {
|
1484 | colorStyles.stroke = stroke;
|
1485 | }
|
1486 | }
|
1487 | if (updater.getTransformValues) {
|
1488 | const updaterTransform = updater.getTransformValues(particle);
|
1489 | for (const key in updaterTransform) {
|
1490 | setTransformValue(transform, updaterTransform, key);
|
1491 | }
|
1492 | }
|
1493 | (_a = updater.beforeDraw) === null || _a === void 0 ? void 0 : _a.call(updater, particle);
|
1494 | }
|
1495 | }
|
1496 | _applyResizePlugins() {
|
1497 | for (const plugin of this._resizePlugins) {
|
1498 | if (plugin.resize) {
|
1499 | plugin.resize();
|
1500 | }
|
1501 | }
|
1502 | }
|
1503 | _getPluginParticleColors(particle) {
|
1504 | let fColor, sColor;
|
1505 | for (const plugin of this._colorPlugins) {
|
1506 | if (!fColor && plugin.particleFillColor) {
|
1507 | fColor = rangeColorToHsl(plugin.particleFillColor(particle));
|
1508 | }
|
1509 | if (!sColor && plugin.particleStrokeColor) {
|
1510 | sColor = rangeColorToHsl(plugin.particleStrokeColor(particle));
|
1511 | }
|
1512 | if (fColor && sColor) {
|
1513 | break;
|
1514 | }
|
1515 | }
|
1516 | return [fColor, sColor];
|
1517 | }
|
1518 | _initCover() {
|
1519 | const options = this.container.actualOptions,
|
1520 | cover = options.backgroundMask.cover,
|
1521 | color = cover.color,
|
1522 | coverRgb = rangeColorToRgb(color);
|
1523 | if (coverRgb) {
|
1524 | const coverColor = {
|
1525 | r: coverRgb.r,
|
1526 | g: coverRgb.g,
|
1527 | b: coverRgb.b,
|
1528 | a: cover.opacity
|
1529 | };
|
1530 | this._coverColorStyle = getStyleFromRgb(coverColor, coverColor.a);
|
1531 | }
|
1532 | }
|
1533 | _initStyle() {
|
1534 | const element = this.element,
|
1535 | options = this.container.actualOptions;
|
1536 | if (!element) {
|
1537 | return;
|
1538 | }
|
1539 | if (this._fullScreen) {
|
1540 | this._originalStyle = deepExtend({}, element.style);
|
1541 | this._setFullScreenStyle();
|
1542 | } else {
|
1543 | this._resetOriginalStyle();
|
1544 | }
|
1545 | for (const key in options.style) {
|
1546 | if (!key || !options.style) {
|
1547 | continue;
|
1548 | }
|
1549 | const value = options.style[key];
|
1550 | if (!value) {
|
1551 | continue;
|
1552 | }
|
1553 | element.style.setProperty(key, value, "important");
|
1554 | }
|
1555 | }
|
1556 | async _initTrail() {
|
1557 | const options = this.container.actualOptions,
|
1558 | trail = options.particles.move.trail,
|
1559 | trailFill = trail.fill;
|
1560 | if (!trail.enable) {
|
1561 | return;
|
1562 | }
|
1563 | if (trailFill.color) {
|
1564 | const fillColor = rangeColorToRgb(trailFill.color);
|
1565 | if (!fillColor) {
|
1566 | return;
|
1567 | }
|
1568 | const trail = options.particles.move.trail;
|
1569 | this._trailFill = {
|
1570 | color: Object.assign({}, fillColor),
|
1571 | opacity: 1 / trail.length
|
1572 | };
|
1573 | } else {
|
1574 | await new Promise((resolve, reject) => {
|
1575 | if (!trailFill.image) {
|
1576 | return;
|
1577 | }
|
1578 | const img = document.createElement("img");
|
1579 | img.addEventListener("load", () => {
|
1580 | this._trailFill = {
|
1581 | image: img,
|
1582 | opacity: 1 / trail.length
|
1583 | };
|
1584 | resolve();
|
1585 | });
|
1586 | img.addEventListener("error", evt => {
|
1587 | reject(evt.error);
|
1588 | });
|
1589 | img.src = trailFill.image;
|
1590 | });
|
1591 | }
|
1592 | }
|
1593 | _paintBase(baseColor) {
|
1594 | this.draw(ctx => {
|
1595 | paintBase(ctx, this.size, baseColor);
|
1596 | });
|
1597 | }
|
1598 | _paintImage(image, opacity) {
|
1599 | this.draw(ctx => {
|
1600 | paintImage(ctx, this.size, image, opacity);
|
1601 | });
|
1602 | }
|
1603 | _repairStyle() {
|
1604 | var _a, _b;
|
1605 | const element = this.element;
|
1606 | if (!element) {
|
1607 | return;
|
1608 | }
|
1609 | (_a = this._mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
|
1610 | this._initStyle();
|
1611 | this.initBackground();
|
1612 | (_b = this._mutationObserver) === null || _b === void 0 ? void 0 : _b.observe(element, {
|
1613 | attributes: true
|
1614 | });
|
1615 | }
|
1616 | _resetOriginalStyle() {
|
1617 | const element = this.element,
|
1618 | originalStyle = this._originalStyle;
|
1619 | if (!(element && originalStyle)) {
|
1620 | return;
|
1621 | }
|
1622 | element.style.position = originalStyle.position;
|
1623 | element.style.zIndex = originalStyle.zIndex;
|
1624 | element.style.top = originalStyle.top;
|
1625 | element.style.left = originalStyle.left;
|
1626 | element.style.width = originalStyle.width;
|
1627 | element.style.height = originalStyle.height;
|
1628 | }
|
1629 | _setFullScreenStyle() {
|
1630 | const element = this.element;
|
1631 | if (!element) {
|
1632 | return;
|
1633 | }
|
1634 | const priority = "important";
|
1635 | element.style.setProperty("position", "fixed", priority);
|
1636 | element.style.setProperty("z-index", this.container.actualOptions.fullScreen.zIndex.toString(10), priority);
|
1637 | element.style.setProperty("top", "0", priority);
|
1638 | element.style.setProperty("left", "0", priority);
|
1639 | element.style.setProperty("width", "100%", priority);
|
1640 | element.style.setProperty("height", "100%", priority);
|
1641 | }
|
1642 | }
|
1643 | ;
|
1644 |
|
1645 |
|
1646 | function manageListener(element, event, handler, add, options) {
|
1647 | if (add) {
|
1648 | let addOptions = {
|
1649 | passive: true
|
1650 | };
|
1651 | if (typeof options === "boolean") {
|
1652 | addOptions.capture = options;
|
1653 | } else if (options !== undefined) {
|
1654 | addOptions = options;
|
1655 | }
|
1656 | element.addEventListener(event, handler, addOptions);
|
1657 | } else {
|
1658 | const removeOptions = options;
|
1659 | element.removeEventListener(event, handler, removeOptions);
|
1660 | }
|
1661 | }
|
1662 | class EventListeners {
|
1663 | constructor(container) {
|
1664 | this.container = container;
|
1665 | this.canPush = true;
|
1666 | this.handlers = {
|
1667 | mouseMove: e => this.mouseTouchMove(e),
|
1668 | touchStart: e => this.mouseTouchMove(e),
|
1669 | touchMove: e => this.mouseTouchMove(e),
|
1670 | touchEnd: () => this.mouseTouchFinish(),
|
1671 | mouseLeave: () => this.mouseTouchFinish(),
|
1672 | touchCancel: () => this.mouseTouchFinish(),
|
1673 | touchEndClick: e => this.mouseTouchClick(e),
|
1674 | mouseUp: e => this.mouseTouchClick(e),
|
1675 | mouseDown: () => this.mouseDown(),
|
1676 | visibilityChange: () => this.handleVisibilityChange(),
|
1677 | themeChange: e => this.handleThemeChange(e),
|
1678 | oldThemeChange: e => this.handleThemeChange(e),
|
1679 | resize: () => this.handleWindowResize()
|
1680 | };
|
1681 | }
|
1682 | addListeners() {
|
1683 | this.manageListeners(true);
|
1684 | }
|
1685 | removeListeners() {
|
1686 | this.manageListeners(false);
|
1687 | }
|
1688 | doMouseTouchClick(e) {
|
1689 | const container = this.container,
|
1690 | options = container.actualOptions;
|
1691 | if (this.canPush) {
|
1692 | const mouseInteractivity = container.interactivity.mouse,
|
1693 | mousePos = mouseInteractivity.position;
|
1694 | if (!mousePos) {
|
1695 | return;
|
1696 | }
|
1697 | mouseInteractivity.clickPosition = Object.assign({}, mousePos);
|
1698 | mouseInteractivity.clickTime = new Date().getTime();
|
1699 | const onClick = options.interactivity.events.onClick;
|
1700 | executeOnSingleOrMultiple(onClick.mode, mode => this.handleClickMode(mode));
|
1701 | }
|
1702 | if (e.type === "touchend") {
|
1703 | setTimeout(() => this.mouseTouchFinish(), 500);
|
1704 | }
|
1705 | }
|
1706 | handleClickMode(mode) {
|
1707 | this.container.handleClickMode(mode);
|
1708 | }
|
1709 | handleThemeChange(e) {
|
1710 | const mediaEvent = e,
|
1711 | container = this.container,
|
1712 | options = container.options,
|
1713 | defaultThemes = options.defaultThemes,
|
1714 | themeName = mediaEvent.matches ? defaultThemes.dark : defaultThemes.light,
|
1715 | theme = options.themes.find(theme => theme.name === themeName);
|
1716 | if (theme && theme.default.auto) {
|
1717 | container.loadTheme(themeName);
|
1718 | }
|
1719 | }
|
1720 | handleVisibilityChange() {
|
1721 | const container = this.container,
|
1722 | options = container.actualOptions;
|
1723 | this.mouseTouchFinish();
|
1724 | if (!options.pauseOnBlur) {
|
1725 | return;
|
1726 | }
|
1727 | if (document === null || document === void 0 ? void 0 : document.hidden) {
|
1728 | container.pageHidden = true;
|
1729 | container.pause();
|
1730 | } else {
|
1731 | container.pageHidden = false;
|
1732 | if (container.getAnimationStatus()) {
|
1733 | container.play(true);
|
1734 | } else {
|
1735 | container.draw(true);
|
1736 | }
|
1737 | }
|
1738 | }
|
1739 | handleWindowResize() {
|
1740 | if (this.resizeTimeout) {
|
1741 | clearTimeout(this.resizeTimeout);
|
1742 | delete this.resizeTimeout;
|
1743 | }
|
1744 | this.resizeTimeout = setTimeout(async () => {
|
1745 | var _a;
|
1746 | return (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize();
|
1747 | }, this.container.actualOptions.interactivity.events.resize.delay * 1000);
|
1748 | }
|
1749 | manageListeners(add) {
|
1750 | var _a;
|
1751 | const handlers = this.handlers,
|
1752 | container = this.container,
|
1753 | options = container.actualOptions,
|
1754 | detectType = options.interactivity.detectsOn;
|
1755 | let mouseLeaveTmpEvent = mouseLeaveEvent;
|
1756 | if (detectType === "window") {
|
1757 | container.interactivity.element = window;
|
1758 | mouseLeaveTmpEvent = mouseOutEvent;
|
1759 | } else if (detectType === "parent" && container.canvas.element) {
|
1760 | const canvasEl = container.canvas.element;
|
1761 | container.interactivity.element = (_a = canvasEl.parentElement) !== null && _a !== void 0 ? _a : canvasEl.parentNode;
|
1762 | } else {
|
1763 | container.interactivity.element = container.canvas.element;
|
1764 | }
|
1765 | const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)");
|
1766 | if (mediaMatch) {
|
1767 | if (mediaMatch.addEventListener !== undefined) {
|
1768 | manageListener(mediaMatch, "change", handlers.themeChange, add);
|
1769 | } else if (mediaMatch.addListener !== undefined) {
|
1770 | if (add) {
|
1771 | mediaMatch.addListener(handlers.oldThemeChange);
|
1772 | } else {
|
1773 | mediaMatch.removeListener(handlers.oldThemeChange);
|
1774 | }
|
1775 | }
|
1776 | }
|
1777 | const interactivityEl = container.interactivity.element;
|
1778 | if (!interactivityEl) {
|
1779 | return;
|
1780 | }
|
1781 | const html = interactivityEl;
|
1782 | if (options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable) {
|
1783 | manageListener(interactivityEl, mouseMoveEvent, handlers.mouseMove, add);
|
1784 | manageListener(interactivityEl, touchStartEvent, handlers.touchStart, add);
|
1785 | manageListener(interactivityEl, touchMoveEvent, handlers.touchMove, add);
|
1786 | if (!options.interactivity.events.onClick.enable) {
|
1787 | manageListener(interactivityEl, touchEndEvent, handlers.touchEnd, add);
|
1788 | } else {
|
1789 | manageListener(interactivityEl, touchEndEvent, handlers.touchEndClick, add);
|
1790 | manageListener(interactivityEl, mouseUpEvent, handlers.mouseUp, add);
|
1791 | manageListener(interactivityEl, mouseDownEvent, handlers.mouseDown, add);
|
1792 | }
|
1793 | manageListener(interactivityEl, mouseLeaveTmpEvent, handlers.mouseLeave, add);
|
1794 | manageListener(interactivityEl, touchCancelEvent, handlers.touchCancel, add);
|
1795 | }
|
1796 | if (container.canvas.element) {
|
1797 | container.canvas.element.style.pointerEvents = html === container.canvas.element ? "initial" : "none";
|
1798 | }
|
1799 | if (options.interactivity.events.resize) {
|
1800 | if (typeof ResizeObserver !== "undefined") {
|
1801 | if (this.resizeObserver && !add) {
|
1802 | if (container.canvas.element) {
|
1803 | this.resizeObserver.unobserve(container.canvas.element);
|
1804 | }
|
1805 | this.resizeObserver.disconnect();
|
1806 | delete this.resizeObserver;
|
1807 | } else if (!this.resizeObserver && add && container.canvas.element) {
|
1808 | this.resizeObserver = new ResizeObserver(entries => {
|
1809 | const entry = entries.find(e => e.target === container.canvas.element);
|
1810 | if (!entry) {
|
1811 | return;
|
1812 | }
|
1813 | this.handleWindowResize();
|
1814 | });
|
1815 | this.resizeObserver.observe(container.canvas.element);
|
1816 | }
|
1817 | } else {
|
1818 | manageListener(window, resizeEvent, handlers.resize, add);
|
1819 | }
|
1820 | }
|
1821 | if (document) {
|
1822 | manageListener(document, visibilityChangeEvent, handlers.visibilityChange, add, false);
|
1823 | }
|
1824 | }
|
1825 | mouseDown() {
|
1826 | const interactivity = this.container.interactivity;
|
1827 | if (interactivity) {
|
1828 | const mouse = interactivity.mouse;
|
1829 | mouse.clicking = true;
|
1830 | mouse.downPosition = mouse.position;
|
1831 | }
|
1832 | }
|
1833 | mouseTouchClick(e) {
|
1834 | const container = this.container,
|
1835 | options = container.actualOptions,
|
1836 | mouse = container.interactivity.mouse;
|
1837 | mouse.inside = true;
|
1838 | let handled = false;
|
1839 | const mousePosition = mouse.position;
|
1840 | if (!mousePosition || !options.interactivity.events.onClick.enable) {
|
1841 | return;
|
1842 | }
|
1843 | for (const [, plugin] of container.plugins) {
|
1844 | if (!plugin.clickPositionValid) {
|
1845 | continue;
|
1846 | }
|
1847 | handled = plugin.clickPositionValid(mousePosition);
|
1848 | if (handled) {
|
1849 | break;
|
1850 | }
|
1851 | }
|
1852 | if (!handled) {
|
1853 | this.doMouseTouchClick(e);
|
1854 | }
|
1855 | mouse.clicking = false;
|
1856 | }
|
1857 | mouseTouchFinish() {
|
1858 | const interactivity = this.container.interactivity;
|
1859 | if (!interactivity) {
|
1860 | return;
|
1861 | }
|
1862 | const mouse = interactivity.mouse;
|
1863 | delete mouse.position;
|
1864 | delete mouse.clickPosition;
|
1865 | delete mouse.downPosition;
|
1866 | interactivity.status = mouseLeaveEvent;
|
1867 | mouse.inside = false;
|
1868 | mouse.clicking = false;
|
1869 | }
|
1870 | mouseTouchMove(e) {
|
1871 | var _a, _b, _c, _d, _e, _f, _g;
|
1872 | const container = this.container,
|
1873 | options = container.actualOptions;
|
1874 | if (!((_a = container.interactivity) === null || _a === void 0 ? void 0 : _a.element)) {
|
1875 | return;
|
1876 | }
|
1877 | container.interactivity.mouse.inside = true;
|
1878 | let pos;
|
1879 | const canvas = container.canvas.element;
|
1880 | if (e.type.startsWith("pointer")) {
|
1881 | this.canPush = true;
|
1882 | const mouseEvent = e;
|
1883 | if (container.interactivity.element === window) {
|
1884 | if (canvas) {
|
1885 | const clientRect = canvas.getBoundingClientRect();
|
1886 | pos = {
|
1887 | x: mouseEvent.clientX - clientRect.left,
|
1888 | y: mouseEvent.clientY - clientRect.top
|
1889 | };
|
1890 | }
|
1891 | } else if (options.interactivity.detectsOn === "parent") {
|
1892 | const source = mouseEvent.target,
|
1893 | target = mouseEvent.currentTarget,
|
1894 | canvasEl = container.canvas.element;
|
1895 | if (source && target && canvasEl) {
|
1896 | const sourceRect = source.getBoundingClientRect(),
|
1897 | targetRect = target.getBoundingClientRect(),
|
1898 | canvasRect = canvasEl.getBoundingClientRect();
|
1899 | pos = {
|
1900 | x: mouseEvent.offsetX + 2 * sourceRect.left - (targetRect.left + canvasRect.left),
|
1901 | y: mouseEvent.offsetY + 2 * sourceRect.top - (targetRect.top + canvasRect.top)
|
1902 | };
|
1903 | } else {
|
1904 | pos = {
|
1905 | x: (_b = mouseEvent.offsetX) !== null && _b !== void 0 ? _b : mouseEvent.clientX,
|
1906 | y: (_c = mouseEvent.offsetY) !== null && _c !== void 0 ? _c : mouseEvent.clientY
|
1907 | };
|
1908 | }
|
1909 | } else if (mouseEvent.target === container.canvas.element) {
|
1910 | pos = {
|
1911 | x: (_d = mouseEvent.offsetX) !== null && _d !== void 0 ? _d : mouseEvent.clientX,
|
1912 | y: (_e = mouseEvent.offsetY) !== null && _e !== void 0 ? _e : mouseEvent.clientY
|
1913 | };
|
1914 | }
|
1915 | } else {
|
1916 | this.canPush = e.type !== "touchmove";
|
1917 | const touchEvent = e,
|
1918 | lastTouch = touchEvent.touches[touchEvent.touches.length - 1],
|
1919 | canvasRect = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect();
|
1920 | pos = {
|
1921 | x: lastTouch.clientX - ((_f = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) !== null && _f !== void 0 ? _f : 0),
|
1922 | y: lastTouch.clientY - ((_g = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) !== null && _g !== void 0 ? _g : 0)
|
1923 | };
|
1924 | }
|
1925 | const pxRatio = container.retina.pixelRatio;
|
1926 | if (pos) {
|
1927 | pos.x *= pxRatio;
|
1928 | pos.y *= pxRatio;
|
1929 | }
|
1930 | container.interactivity.mouse.position = pos;
|
1931 | container.interactivity.status = mouseMoveEvent;
|
1932 | }
|
1933 | }
|
1934 | ;
|
1935 | function initDelta(value, fpsLimit = 60, smooth = false) {
|
1936 | return {
|
1937 | value,
|
1938 | factor: smooth ? 60 / fpsLimit : 60 * value / 1000
|
1939 | };
|
1940 | }
|
1941 | class FrameManager {
|
1942 | constructor(container) {
|
1943 | this.container = container;
|
1944 | }
|
1945 | async nextFrame(timestamp) {
|
1946 | var _a;
|
1947 | try {
|
1948 | const container = this.container;
|
1949 | if (!container.smooth && container.lastFrameTime !== undefined && timestamp < container.lastFrameTime + 1000 / container.fpsLimit) {
|
1950 | container.draw(false);
|
1951 | return;
|
1952 | }
|
1953 | (_a = container.lastFrameTime) !== null && _a !== void 0 ? _a : container.lastFrameTime = timestamp;
|
1954 | const delta = initDelta(timestamp - container.lastFrameTime, container.fpsLimit, container.smooth);
|
1955 | container.lifeTime += delta.value;
|
1956 | container.lastFrameTime = timestamp;
|
1957 | if (delta.value > 1000) {
|
1958 | container.draw(false);
|
1959 | return;
|
1960 | }
|
1961 | await container.particles.draw(delta);
|
1962 | if (container.duration > 0 && container.lifeTime > container.duration) {
|
1963 | container.destroy();
|
1964 | return;
|
1965 | }
|
1966 | if (container.getAnimationStatus()) {
|
1967 | container.draw(false);
|
1968 | }
|
1969 | } catch (e) {
|
1970 | console.error("tsParticles error in animation loop", e);
|
1971 | }
|
1972 | }
|
1973 | }
|
1974 | ;
|
1975 | class OptionsColor {
|
1976 | constructor() {
|
1977 | this.value = "";
|
1978 | }
|
1979 | static create(source, data) {
|
1980 | const color = new OptionsColor();
|
1981 | color.load(source);
|
1982 | if (data !== undefined) {
|
1983 | if (typeof data === "string" || data instanceof Array) {
|
1984 | color.load({
|
1985 | value: data
|
1986 | });
|
1987 | } else {
|
1988 | color.load(data);
|
1989 | }
|
1990 | }
|
1991 | return color;
|
1992 | }
|
1993 | load(data) {
|
1994 | if ((data === null || data === void 0 ? void 0 : data.value) === undefined) {
|
1995 | return;
|
1996 | }
|
1997 | this.value = data.value;
|
1998 | }
|
1999 | }
|
2000 | ;
|
2001 |
|
2002 | class Background {
|
2003 | constructor() {
|
2004 | this.color = new OptionsColor();
|
2005 | this.color.value = "";
|
2006 | this.image = "";
|
2007 | this.position = "";
|
2008 | this.repeat = "";
|
2009 | this.size = "";
|
2010 | this.opacity = 1;
|
2011 | }
|
2012 | load(data) {
|
2013 | if (!data) {
|
2014 | return;
|
2015 | }
|
2016 | if (data.color !== undefined) {
|
2017 | this.color = OptionsColor.create(this.color, data.color);
|
2018 | }
|
2019 | if (data.image !== undefined) {
|
2020 | this.image = data.image;
|
2021 | }
|
2022 | if (data.position !== undefined) {
|
2023 | this.position = data.position;
|
2024 | }
|
2025 | if (data.repeat !== undefined) {
|
2026 | this.repeat = data.repeat;
|
2027 | }
|
2028 | if (data.size !== undefined) {
|
2029 | this.size = data.size;
|
2030 | }
|
2031 | if (data.opacity !== undefined) {
|
2032 | this.opacity = data.opacity;
|
2033 | }
|
2034 | }
|
2035 | }
|
2036 | ;
|
2037 |
|
2038 | class BackgroundMaskCover {
|
2039 | constructor() {
|
2040 | this.color = new OptionsColor();
|
2041 | this.color.value = "#fff";
|
2042 | this.opacity = 1;
|
2043 | }
|
2044 | load(data) {
|
2045 | if (!data) {
|
2046 | return;
|
2047 | }
|
2048 | if (data.color !== undefined) {
|
2049 | this.color = OptionsColor.create(this.color, data.color);
|
2050 | }
|
2051 | if (data.opacity !== undefined) {
|
2052 | this.opacity = data.opacity;
|
2053 | }
|
2054 | }
|
2055 | }
|
2056 | ;
|
2057 |
|
2058 | class BackgroundMask {
|
2059 | constructor() {
|
2060 | this.composite = "destination-out";
|
2061 | this.cover = new BackgroundMaskCover();
|
2062 | this.enable = false;
|
2063 | }
|
2064 | load(data) {
|
2065 | if (!data) {
|
2066 | return;
|
2067 | }
|
2068 | if (data.composite !== undefined) {
|
2069 | this.composite = data.composite;
|
2070 | }
|
2071 | if (data.cover !== undefined) {
|
2072 | const cover = data.cover;
|
2073 | const color = typeof data.cover === "string" ? {
|
2074 | color: data.cover
|
2075 | } : data.cover;
|
2076 | this.cover.load(cover.color !== undefined ? cover : {
|
2077 | color: color
|
2078 | });
|
2079 | }
|
2080 | if (data.enable !== undefined) {
|
2081 | this.enable = data.enable;
|
2082 | }
|
2083 | }
|
2084 | }
|
2085 | ;
|
2086 | class FullScreen {
|
2087 | constructor() {
|
2088 | this.enable = true;
|
2089 | this.zIndex = 0;
|
2090 | }
|
2091 | load(data) {
|
2092 | if (!data) {
|
2093 | return;
|
2094 | }
|
2095 | if (data.enable !== undefined) {
|
2096 | this.enable = data.enable;
|
2097 | }
|
2098 | if (data.zIndex !== undefined) {
|
2099 | this.zIndex = data.zIndex;
|
2100 | }
|
2101 | }
|
2102 | }
|
2103 | ;
|
2104 | class ClickEvent {
|
2105 | constructor() {
|
2106 | this.enable = false;
|
2107 | this.mode = [];
|
2108 | }
|
2109 | load(data) {
|
2110 | if (!data) {
|
2111 | return;
|
2112 | }
|
2113 | if (data.enable !== undefined) {
|
2114 | this.enable = data.enable;
|
2115 | }
|
2116 | if (data.mode !== undefined) {
|
2117 | this.mode = data.mode;
|
2118 | }
|
2119 | }
|
2120 | }
|
2121 | ;
|
2122 |
|
2123 | class DivEvent {
|
2124 | constructor() {
|
2125 | this.selectors = [];
|
2126 | this.enable = false;
|
2127 | this.mode = [];
|
2128 | this.type = "circle";
|
2129 | }
|
2130 | get el() {
|
2131 | return this.elementId;
|
2132 | }
|
2133 | set el(value) {
|
2134 | this.elementId = value;
|
2135 | }
|
2136 | get elementId() {
|
2137 | return this.ids;
|
2138 | }
|
2139 | set elementId(value) {
|
2140 | this.ids = value;
|
2141 | }
|
2142 | get ids() {
|
2143 | return executeOnSingleOrMultiple(this.selectors, t => t.replace("#", ""));
|
2144 | }
|
2145 | set ids(value) {
|
2146 | this.selectors = executeOnSingleOrMultiple(value, t => `#${t}`);
|
2147 | }
|
2148 | load(data) {
|
2149 | var _a, _b;
|
2150 | if (!data) {
|
2151 | return;
|
2152 | }
|
2153 | const ids = (_b = (_a = data.ids) !== null && _a !== void 0 ? _a : data.elementId) !== null && _b !== void 0 ? _b : data.el;
|
2154 | if (ids !== undefined) {
|
2155 | this.ids = ids;
|
2156 | }
|
2157 | if (data.selectors !== undefined) {
|
2158 | this.selectors = data.selectors;
|
2159 | }
|
2160 | if (data.enable !== undefined) {
|
2161 | this.enable = data.enable;
|
2162 | }
|
2163 | if (data.mode !== undefined) {
|
2164 | this.mode = data.mode;
|
2165 | }
|
2166 | if (data.type !== undefined) {
|
2167 | this.type = data.type;
|
2168 | }
|
2169 | }
|
2170 | }
|
2171 | ;
|
2172 | class Parallax {
|
2173 | constructor() {
|
2174 | this.enable = false;
|
2175 | this.force = 2;
|
2176 | this.smooth = 10;
|
2177 | }
|
2178 | load(data) {
|
2179 | if (!data) {
|
2180 | return;
|
2181 | }
|
2182 | if (data.enable !== undefined) {
|
2183 | this.enable = data.enable;
|
2184 | }
|
2185 | if (data.force !== undefined) {
|
2186 | this.force = data.force;
|
2187 | }
|
2188 | if (data.smooth !== undefined) {
|
2189 | this.smooth = data.smooth;
|
2190 | }
|
2191 | }
|
2192 | }
|
2193 | ;
|
2194 |
|
2195 | class HoverEvent {
|
2196 | constructor() {
|
2197 | this.enable = false;
|
2198 | this.mode = [];
|
2199 | this.parallax = new Parallax();
|
2200 | }
|
2201 | load(data) {
|
2202 | if (!data) {
|
2203 | return;
|
2204 | }
|
2205 | if (data.enable !== undefined) {
|
2206 | this.enable = data.enable;
|
2207 | }
|
2208 | if (data.mode !== undefined) {
|
2209 | this.mode = data.mode;
|
2210 | }
|
2211 | this.parallax.load(data.parallax);
|
2212 | }
|
2213 | }
|
2214 | ;
|
2215 | class ResizeEvent {
|
2216 | constructor() {
|
2217 | this.delay = 0.5;
|
2218 | this.enable = true;
|
2219 | }
|
2220 | load(data) {
|
2221 | if (data === undefined) {
|
2222 | return;
|
2223 | }
|
2224 | if (data.delay !== undefined) {
|
2225 | this.delay = data.delay;
|
2226 | }
|
2227 | if (data.enable !== undefined) {
|
2228 | this.enable = data.enable;
|
2229 | }
|
2230 | }
|
2231 | }
|
2232 | ;
|
2233 |
|
2234 |
|
2235 |
|
2236 |
|
2237 |
|
2238 | class Events {
|
2239 | constructor() {
|
2240 | this.onClick = new ClickEvent();
|
2241 | this.onDiv = new DivEvent();
|
2242 | this.onHover = new HoverEvent();
|
2243 | this.resize = new ResizeEvent();
|
2244 | }
|
2245 | get onclick() {
|
2246 | return this.onClick;
|
2247 | }
|
2248 | set onclick(value) {
|
2249 | this.onClick = value;
|
2250 | }
|
2251 | get ondiv() {
|
2252 | return this.onDiv;
|
2253 | }
|
2254 | set ondiv(value) {
|
2255 | this.onDiv = value;
|
2256 | }
|
2257 | get onhover() {
|
2258 | return this.onHover;
|
2259 | }
|
2260 | set onhover(value) {
|
2261 | this.onHover = value;
|
2262 | }
|
2263 | load(data) {
|
2264 | var _a, _b, _c;
|
2265 | if (!data) {
|
2266 | return;
|
2267 | }
|
2268 | this.onClick.load((_a = data.onClick) !== null && _a !== void 0 ? _a : data.onclick);
|
2269 | const onDiv = (_b = data.onDiv) !== null && _b !== void 0 ? _b : data.ondiv;
|
2270 | if (onDiv !== undefined) {
|
2271 | this.onDiv = executeOnSingleOrMultiple(onDiv, t => {
|
2272 | const tmp = new DivEvent();
|
2273 | tmp.load(t);
|
2274 | return tmp;
|
2275 | });
|
2276 | }
|
2277 | this.onHover.load((_c = data.onHover) !== null && _c !== void 0 ? _c : data.onhover);
|
2278 | if (typeof data.resize === "boolean") {
|
2279 | this.resize.enable = data.resize;
|
2280 | } else {
|
2281 | this.resize.load(data.resize);
|
2282 | }
|
2283 | }
|
2284 | }
|
2285 | ;
|
2286 | class Modes {
|
2287 | constructor(engine, container) {
|
2288 | this._engine = engine;
|
2289 | this._container = container;
|
2290 | }
|
2291 | load(data) {
|
2292 | if (!data) {
|
2293 | return;
|
2294 | }
|
2295 | if (this._container) {
|
2296 | const interactors = this._engine.plugins.interactors.get(this._container);
|
2297 | if (interactors) {
|
2298 | for (const interactor of interactors) {
|
2299 | if (interactor.loadModeOptions) {
|
2300 | interactor.loadModeOptions(this, data);
|
2301 | }
|
2302 | }
|
2303 | }
|
2304 | }
|
2305 | }
|
2306 | }
|
2307 | ;
|
2308 |
|
2309 |
|
2310 | class Interactivity {
|
2311 | constructor(engine, container) {
|
2312 | this.detectsOn = "window";
|
2313 | this.events = new Events();
|
2314 | this.modes = new Modes(engine, container);
|
2315 | }
|
2316 | get detect_on() {
|
2317 | return this.detectsOn;
|
2318 | }
|
2319 | set detect_on(value) {
|
2320 | this.detectsOn = value;
|
2321 | }
|
2322 | load(data) {
|
2323 | var _a;
|
2324 | if (!data) {
|
2325 | return;
|
2326 | }
|
2327 | const detectsOn = (_a = data.detectsOn) !== null && _a !== void 0 ? _a : data.detect_on;
|
2328 | if (detectsOn !== undefined) {
|
2329 | this.detectsOn = detectsOn;
|
2330 | }
|
2331 | this.events.load(data.events);
|
2332 | this.modes.load(data.modes);
|
2333 | }
|
2334 | }
|
2335 | ;
|
2336 |
|
2337 | class ManualParticle {
|
2338 | load(data) {
|
2339 | var _a, _b;
|
2340 | if (!data) {
|
2341 | return;
|
2342 | }
|
2343 | if (data.position !== undefined) {
|
2344 | this.position = {
|
2345 | x: (_a = data.position.x) !== null && _a !== void 0 ? _a : 50,
|
2346 | y: (_b = data.position.y) !== null && _b !== void 0 ? _b : 50
|
2347 | };
|
2348 | }
|
2349 | if (data.options !== undefined) {
|
2350 | this.options = deepExtend({}, data.options);
|
2351 | }
|
2352 | }
|
2353 | }
|
2354 | ;
|
2355 |
|
2356 | class Responsive {
|
2357 | constructor() {
|
2358 | this.maxWidth = Infinity;
|
2359 | this.options = {};
|
2360 | this.mode = "canvas";
|
2361 | }
|
2362 | load(data) {
|
2363 | if (!data) {
|
2364 | return;
|
2365 | }
|
2366 | if (data.maxWidth !== undefined) {
|
2367 | this.maxWidth = data.maxWidth;
|
2368 | }
|
2369 | if (data.mode !== undefined) {
|
2370 | if (data.mode === "screen") {
|
2371 | this.mode = "screen";
|
2372 | } else {
|
2373 | this.mode = "canvas";
|
2374 | }
|
2375 | }
|
2376 | if (data.options !== undefined) {
|
2377 | this.options = deepExtend({}, data.options);
|
2378 | }
|
2379 | }
|
2380 | }
|
2381 | ;
|
2382 | class ThemeDefault {
|
2383 | constructor() {
|
2384 | this.auto = false;
|
2385 | this.mode = "any";
|
2386 | this.value = false;
|
2387 | }
|
2388 | load(data) {
|
2389 | if (!data) {
|
2390 | return;
|
2391 | }
|
2392 | if (data.auto !== undefined) {
|
2393 | this.auto = data.auto;
|
2394 | }
|
2395 | if (data.mode !== undefined) {
|
2396 | this.mode = data.mode;
|
2397 | }
|
2398 | if (data.value !== undefined) {
|
2399 | this.value = data.value;
|
2400 | }
|
2401 | }
|
2402 | }
|
2403 | ;
|
2404 |
|
2405 |
|
2406 | class Theme {
|
2407 | constructor() {
|
2408 | this.name = "";
|
2409 | this.default = new ThemeDefault();
|
2410 | }
|
2411 | load(data) {
|
2412 | if (!data) {
|
2413 | return;
|
2414 | }
|
2415 | if (data.name !== undefined) {
|
2416 | this.name = data.name;
|
2417 | }
|
2418 | this.default.load(data.default);
|
2419 | if (data.options !== undefined) {
|
2420 | this.options = deepExtend({}, data.options);
|
2421 | }
|
2422 | }
|
2423 | }
|
2424 | ;
|
2425 |
|
2426 | class ColorAnimation {
|
2427 | constructor() {
|
2428 | this.count = 0;
|
2429 | this.enable = false;
|
2430 | this.offset = 0;
|
2431 | this.speed = 1;
|
2432 | this.decay = 0;
|
2433 | this.sync = true;
|
2434 | }
|
2435 | load(data) {
|
2436 | if (!data) {
|
2437 | return;
|
2438 | }
|
2439 | if (data.count !== undefined) {
|
2440 | this.count = setRangeValue(data.count);
|
2441 | }
|
2442 | if (data.enable !== undefined) {
|
2443 | this.enable = data.enable;
|
2444 | }
|
2445 | if (data.offset !== undefined) {
|
2446 | this.offset = setRangeValue(data.offset);
|
2447 | }
|
2448 | if (data.speed !== undefined) {
|
2449 | this.speed = setRangeValue(data.speed);
|
2450 | }
|
2451 | if (data.decay !== undefined) {
|
2452 | this.decay = setRangeValue(data.decay);
|
2453 | }
|
2454 | if (data.sync !== undefined) {
|
2455 | this.sync = data.sync;
|
2456 | }
|
2457 | }
|
2458 | }
|
2459 | ;
|
2460 |
|
2461 | class HslAnimation {
|
2462 | constructor() {
|
2463 | this.h = new ColorAnimation();
|
2464 | this.s = new ColorAnimation();
|
2465 | this.l = new ColorAnimation();
|
2466 | }
|
2467 | load(data) {
|
2468 | if (!data) {
|
2469 | return;
|
2470 | }
|
2471 | this.h.load(data.h);
|
2472 | this.s.load(data.s);
|
2473 | this.l.load(data.l);
|
2474 | }
|
2475 | }
|
2476 | ;
|
2477 |
|
2478 |
|
2479 | class AnimatableColor extends OptionsColor {
|
2480 | constructor() {
|
2481 | super();
|
2482 | this.animation = new HslAnimation();
|
2483 | }
|
2484 | static create(source, data) {
|
2485 | const color = new AnimatableColor();
|
2486 | color.load(source);
|
2487 | if (data !== undefined) {
|
2488 | if (typeof data === "string" || data instanceof Array) {
|
2489 | color.load({
|
2490 | value: data
|
2491 | });
|
2492 | } else {
|
2493 | color.load(data);
|
2494 | }
|
2495 | }
|
2496 | return color;
|
2497 | }
|
2498 | load(data) {
|
2499 | super.load(data);
|
2500 | if (!data) {
|
2501 | return;
|
2502 | }
|
2503 | const colorAnimation = data.animation;
|
2504 | if (colorAnimation !== undefined) {
|
2505 | if (colorAnimation.enable !== undefined) {
|
2506 | this.animation.h.load(colorAnimation);
|
2507 | } else {
|
2508 | this.animation.load(data.animation);
|
2509 | }
|
2510 | }
|
2511 | }
|
2512 | }
|
2513 | ;
|
2514 | class CollisionsAbsorb {
|
2515 | constructor() {
|
2516 | this.speed = 2;
|
2517 | }
|
2518 | load(data) {
|
2519 | if (!data) {
|
2520 | return;
|
2521 | }
|
2522 | if (data.speed !== undefined) {
|
2523 | this.speed = data.speed;
|
2524 | }
|
2525 | }
|
2526 | }
|
2527 | ;
|
2528 | class CollisionsOverlap {
|
2529 | constructor() {
|
2530 | this.enable = true;
|
2531 | this.retries = 0;
|
2532 | }
|
2533 | load(data) {
|
2534 | if (!data) {
|
2535 | return;
|
2536 | }
|
2537 | if (data.enable !== undefined) {
|
2538 | this.enable = data.enable;
|
2539 | }
|
2540 | if (data.retries !== undefined) {
|
2541 | this.retries = data.retries;
|
2542 | }
|
2543 | }
|
2544 | }
|
2545 | ;
|
2546 | class Random {
|
2547 | constructor() {
|
2548 | this.enable = false;
|
2549 | this.minimumValue = 0;
|
2550 | }
|
2551 | load(data) {
|
2552 | if (!data) {
|
2553 | return;
|
2554 | }
|
2555 | if (data.enable !== undefined) {
|
2556 | this.enable = data.enable;
|
2557 | }
|
2558 | if (data.minimumValue !== undefined) {
|
2559 | this.minimumValue = data.minimumValue;
|
2560 | }
|
2561 | }
|
2562 | }
|
2563 | ;
|
2564 |
|
2565 |
|
2566 | class ValueWithRandom {
|
2567 | constructor() {
|
2568 | this.random = new Random();
|
2569 | this.value = 0;
|
2570 | }
|
2571 | load(data) {
|
2572 | if (!data) {
|
2573 | return;
|
2574 | }
|
2575 | if (typeof data.random === "boolean") {
|
2576 | this.random.enable = data.random;
|
2577 | } else {
|
2578 | this.random.load(data.random);
|
2579 | }
|
2580 | if (data.value !== undefined) {
|
2581 | this.value = setRangeValue(data.value, this.random.enable ? this.random.minimumValue : undefined);
|
2582 | }
|
2583 | }
|
2584 | }
|
2585 | ;
|
2586 |
|
2587 | class ParticlesBounceFactor extends ValueWithRandom {
|
2588 | constructor() {
|
2589 | super();
|
2590 | this.random.minimumValue = 0.1;
|
2591 | this.value = 1;
|
2592 | }
|
2593 | }
|
2594 | ;
|
2595 |
|
2596 | class ParticlesBounce {
|
2597 | constructor() {
|
2598 | this.horizontal = new ParticlesBounceFactor();
|
2599 | this.vertical = new ParticlesBounceFactor();
|
2600 | }
|
2601 | load(data) {
|
2602 | if (!data) {
|
2603 | return;
|
2604 | }
|
2605 | this.horizontal.load(data.horizontal);
|
2606 | this.vertical.load(data.vertical);
|
2607 | }
|
2608 | }
|
2609 | ;
|
2610 |
|
2611 |
|
2612 |
|
2613 | class Collisions {
|
2614 | constructor() {
|
2615 | this.absorb = new CollisionsAbsorb();
|
2616 | this.bounce = new ParticlesBounce();
|
2617 | this.enable = false;
|
2618 | this.mode = "bounce";
|
2619 | this.overlap = new CollisionsOverlap();
|
2620 | }
|
2621 | load(data) {
|
2622 | if (!data) {
|
2623 | return;
|
2624 | }
|
2625 | this.absorb.load(data.absorb);
|
2626 | this.bounce.load(data.bounce);
|
2627 | if (data.enable !== undefined) {
|
2628 | this.enable = data.enable;
|
2629 | }
|
2630 | if (data.mode !== undefined) {
|
2631 | this.mode = data.mode;
|
2632 | }
|
2633 | this.overlap.load(data.overlap);
|
2634 | }
|
2635 | }
|
2636 | ;
|
2637 |
|
2638 | class MoveAngle {
|
2639 | constructor() {
|
2640 | this.offset = 0;
|
2641 | this.value = 90;
|
2642 | }
|
2643 | load(data) {
|
2644 | if (!data) {
|
2645 | return;
|
2646 | }
|
2647 | if (data.offset !== undefined) {
|
2648 | this.offset = setRangeValue(data.offset);
|
2649 | }
|
2650 | if (data.value !== undefined) {
|
2651 | this.value = setRangeValue(data.value);
|
2652 | }
|
2653 | }
|
2654 | }
|
2655 | ;
|
2656 |
|
2657 | class MoveAttract {
|
2658 | constructor() {
|
2659 | this.distance = 200;
|
2660 | this.enable = false;
|
2661 | this.rotate = {
|
2662 | x: 3000,
|
2663 | y: 3000
|
2664 | };
|
2665 | }
|
2666 | get rotateX() {
|
2667 | return this.rotate.x;
|
2668 | }
|
2669 | set rotateX(value) {
|
2670 | this.rotate.x = value;
|
2671 | }
|
2672 | get rotateY() {
|
2673 | return this.rotate.y;
|
2674 | }
|
2675 | set rotateY(value) {
|
2676 | this.rotate.y = value;
|
2677 | }
|
2678 | load(data) {
|
2679 | var _a, _b, _c, _d;
|
2680 | if (!data) {
|
2681 | return;
|
2682 | }
|
2683 | if (data.distance !== undefined) {
|
2684 | this.distance = setRangeValue(data.distance);
|
2685 | }
|
2686 | if (data.enable !== undefined) {
|
2687 | this.enable = data.enable;
|
2688 | }
|
2689 | const rotateX = (_b = (_a = data.rotate) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : data.rotateX;
|
2690 | if (rotateX !== undefined) {
|
2691 | this.rotate.x = rotateX;
|
2692 | }
|
2693 | const rotateY = (_d = (_c = data.rotate) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : data.rotateY;
|
2694 | if (rotateY !== undefined) {
|
2695 | this.rotate.y = rotateY;
|
2696 | }
|
2697 | }
|
2698 | }
|
2699 | ;
|
2700 | class MoveCenter {
|
2701 | constructor() {
|
2702 | this.x = 50;
|
2703 | this.y = 50;
|
2704 | this.mode = "percent";
|
2705 | this.radius = 0;
|
2706 | }
|
2707 | load(data) {
|
2708 | if (!data) {
|
2709 | return;
|
2710 | }
|
2711 | if (data.x !== undefined) {
|
2712 | this.x = data.x;
|
2713 | }
|
2714 | if (data.y !== undefined) {
|
2715 | this.y = data.y;
|
2716 | }
|
2717 | if (data.mode !== undefined) {
|
2718 | this.mode = data.mode;
|
2719 | }
|
2720 | if (data.radius !== undefined) {
|
2721 | this.radius = data.radius;
|
2722 | }
|
2723 | }
|
2724 | }
|
2725 | ;
|
2726 |
|
2727 | class MoveGravity {
|
2728 | constructor() {
|
2729 | this.acceleration = 9.81;
|
2730 | this.enable = false;
|
2731 | this.inverse = false;
|
2732 | this.maxSpeed = 50;
|
2733 | }
|
2734 | load(data) {
|
2735 | if (!data) {
|
2736 | return;
|
2737 | }
|
2738 | if (data.acceleration !== undefined) {
|
2739 | this.acceleration = setRangeValue(data.acceleration);
|
2740 | }
|
2741 | if (data.enable !== undefined) {
|
2742 | this.enable = data.enable;
|
2743 | }
|
2744 | if (data.inverse !== undefined) {
|
2745 | this.inverse = data.inverse;
|
2746 | }
|
2747 | if (data.maxSpeed !== undefined) {
|
2748 | this.maxSpeed = setRangeValue(data.maxSpeed);
|
2749 | }
|
2750 | }
|
2751 | }
|
2752 | ;
|
2753 |
|
2754 |
|
2755 | class MovePath {
|
2756 | constructor() {
|
2757 | this.clamp = true;
|
2758 | this.delay = new ValueWithRandom();
|
2759 | this.enable = false;
|
2760 | this.options = {};
|
2761 | }
|
2762 | load(data) {
|
2763 | if (!data) {
|
2764 | return;
|
2765 | }
|
2766 | if (data.clamp !== undefined) {
|
2767 | this.clamp = data.clamp;
|
2768 | }
|
2769 | this.delay.load(data.delay);
|
2770 | if (data.enable !== undefined) {
|
2771 | this.enable = data.enable;
|
2772 | }
|
2773 | this.generator = data.generator;
|
2774 | if (data.options) {
|
2775 | this.options = deepExtend(this.options, data.options);
|
2776 | }
|
2777 | }
|
2778 | }
|
2779 | ;
|
2780 |
|
2781 | class MoveTrailFill {
|
2782 | load(data) {
|
2783 | if (!data) {
|
2784 | return;
|
2785 | }
|
2786 | if (data.color !== undefined) {
|
2787 | this.color = OptionsColor.create(this.color, data.color);
|
2788 | }
|
2789 | if (data.image !== undefined) {
|
2790 | this.image = data.image;
|
2791 | }
|
2792 | }
|
2793 | }
|
2794 | ;
|
2795 |
|
2796 | class MoveTrail {
|
2797 | constructor() {
|
2798 | this.enable = false;
|
2799 | this.length = 10;
|
2800 | this.fill = new MoveTrailFill();
|
2801 | }
|
2802 | get fillColor() {
|
2803 | return this.fill.color;
|
2804 | }
|
2805 | set fillColor(value) {
|
2806 | this.fill.load({
|
2807 | color: value
|
2808 | });
|
2809 | }
|
2810 | load(data) {
|
2811 | if (!data) {
|
2812 | return;
|
2813 | }
|
2814 | if (data.enable !== undefined) {
|
2815 | this.enable = data.enable;
|
2816 | }
|
2817 | if (data.fill !== undefined || data.fillColor !== undefined) {
|
2818 | this.fill.load(data.fill || {
|
2819 | color: data.fillColor
|
2820 | });
|
2821 | }
|
2822 | if (data.length !== undefined) {
|
2823 | this.length = data.length;
|
2824 | }
|
2825 | }
|
2826 | }
|
2827 | ;
|
2828 | class OutModes {
|
2829 | constructor() {
|
2830 | this.default = "out";
|
2831 | }
|
2832 | load(data) {
|
2833 | var _a, _b, _c, _d;
|
2834 | if (!data) {
|
2835 | return;
|
2836 | }
|
2837 | if (data.default !== undefined) {
|
2838 | this.default = data.default;
|
2839 | }
|
2840 | this.bottom = (_a = data.bottom) !== null && _a !== void 0 ? _a : data.default;
|
2841 | this.left = (_b = data.left) !== null && _b !== void 0 ? _b : data.default;
|
2842 | this.right = (_c = data.right) !== null && _c !== void 0 ? _c : data.default;
|
2843 | this.top = (_d = data.top) !== null && _d !== void 0 ? _d : data.default;
|
2844 | }
|
2845 | }
|
2846 | ;
|
2847 |
|
2848 |
|
2849 | class Spin {
|
2850 | constructor() {
|
2851 | this.acceleration = 0;
|
2852 | this.enable = false;
|
2853 | }
|
2854 | load(data) {
|
2855 | if (!data) {
|
2856 | return;
|
2857 | }
|
2858 | if (data.acceleration !== undefined) {
|
2859 | this.acceleration = setRangeValue(data.acceleration);
|
2860 | }
|
2861 | if (data.enable !== undefined) {
|
2862 | this.enable = data.enable;
|
2863 | }
|
2864 | this.position = data.position ? deepExtend({}, data.position) : undefined;
|
2865 | }
|
2866 | }
|
2867 | ;
|
2868 |
|
2869 |
|
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 | class Move {
|
2878 | constructor() {
|
2879 | this.angle = new MoveAngle();
|
2880 | this.attract = new MoveAttract();
|
2881 | this.center = new MoveCenter();
|
2882 | this.decay = 0;
|
2883 | this.distance = {};
|
2884 | this.direction = "none";
|
2885 | this.drift = 0;
|
2886 | this.enable = false;
|
2887 | this.gravity = new MoveGravity();
|
2888 | this.path = new MovePath();
|
2889 | this.outModes = new OutModes();
|
2890 | this.random = false;
|
2891 | this.size = false;
|
2892 | this.speed = 2;
|
2893 | this.spin = new Spin();
|
2894 | this.straight = false;
|
2895 | this.trail = new MoveTrail();
|
2896 | this.vibrate = false;
|
2897 | this.warp = false;
|
2898 | }
|
2899 | get bounce() {
|
2900 | return this.collisions;
|
2901 | }
|
2902 | set bounce(value) {
|
2903 | this.collisions = value;
|
2904 | }
|
2905 | get collisions() {
|
2906 | return false;
|
2907 | }
|
2908 | set collisions(_) {}
|
2909 | get noise() {
|
2910 | return this.path;
|
2911 | }
|
2912 | set noise(value) {
|
2913 | this.path = value;
|
2914 | }
|
2915 | get outMode() {
|
2916 | return this.outModes.default;
|
2917 | }
|
2918 | set outMode(value) {
|
2919 | this.outModes.default = value;
|
2920 | }
|
2921 | get out_mode() {
|
2922 | return this.outMode;
|
2923 | }
|
2924 | set out_mode(value) {
|
2925 | this.outMode = value;
|
2926 | }
|
2927 | load(data) {
|
2928 | var _a, _b, _c;
|
2929 | if (!data) {
|
2930 | return;
|
2931 | }
|
2932 | this.angle.load(typeof data.angle === "number" ? {
|
2933 | value: data.angle
|
2934 | } : data.angle);
|
2935 | this.attract.load(data.attract);
|
2936 | this.center.load(data.center);
|
2937 | if (data.decay !== undefined) {
|
2938 | this.decay = setRangeValue(data.decay);
|
2939 | }
|
2940 | if (data.direction !== undefined) {
|
2941 | this.direction = data.direction;
|
2942 | }
|
2943 | if (data.distance !== undefined) {
|
2944 | this.distance = typeof data.distance === "number" ? {
|
2945 | horizontal: data.distance,
|
2946 | vertical: data.distance
|
2947 | } : Object.assign({}, data.distance);
|
2948 | }
|
2949 | if (data.drift !== undefined) {
|
2950 | this.drift = setRangeValue(data.drift);
|
2951 | }
|
2952 | if (data.enable !== undefined) {
|
2953 | this.enable = data.enable;
|
2954 | }
|
2955 | this.gravity.load(data.gravity);
|
2956 | const outModes = (_b = (_a = data.outModes) !== null && _a !== void 0 ? _a : data.outMode) !== null && _b !== void 0 ? _b : data.out_mode;
|
2957 | if (outModes !== undefined) {
|
2958 | if (typeof outModes === "object") {
|
2959 | this.outModes.load(outModes);
|
2960 | } else {
|
2961 | this.outModes.load({
|
2962 | default: outModes
|
2963 | });
|
2964 | }
|
2965 | }
|
2966 | this.path.load((_c = data.path) !== null && _c !== void 0 ? _c : data.noise);
|
2967 | if (data.random !== undefined) {
|
2968 | this.random = data.random;
|
2969 | }
|
2970 | if (data.size !== undefined) {
|
2971 | this.size = data.size;
|
2972 | }
|
2973 | if (data.speed !== undefined) {
|
2974 | this.speed = setRangeValue(data.speed);
|
2975 | }
|
2976 | this.spin.load(data.spin);
|
2977 | if (data.straight !== undefined) {
|
2978 | this.straight = data.straight;
|
2979 | }
|
2980 | this.trail.load(data.trail);
|
2981 | if (data.vibrate !== undefined) {
|
2982 | this.vibrate = data.vibrate;
|
2983 | }
|
2984 | if (data.warp !== undefined) {
|
2985 | this.warp = data.warp;
|
2986 | }
|
2987 | }
|
2988 | }
|
2989 | ;
|
2990 |
|
2991 | class AnimationOptions {
|
2992 | constructor() {
|
2993 | this.count = 0;
|
2994 | this.enable = false;
|
2995 | this.speed = 1;
|
2996 | this.decay = 0;
|
2997 | this.sync = false;
|
2998 | }
|
2999 | load(data) {
|
3000 | if (!data) {
|
3001 | return;
|
3002 | }
|
3003 | if (data.count !== undefined) {
|
3004 | this.count = setRangeValue(data.count);
|
3005 | }
|
3006 | if (data.enable !== undefined) {
|
3007 | this.enable = data.enable;
|
3008 | }
|
3009 | if (data.speed !== undefined) {
|
3010 | this.speed = setRangeValue(data.speed);
|
3011 | }
|
3012 | if (data.decay !== undefined) {
|
3013 | this.decay = setRangeValue(data.decay);
|
3014 | }
|
3015 | if (data.sync !== undefined) {
|
3016 | this.sync = data.sync;
|
3017 | }
|
3018 | }
|
3019 | }
|
3020 | ;
|
3021 |
|
3022 | class OpacityAnimation extends AnimationOptions {
|
3023 | constructor() {
|
3024 | super();
|
3025 | this.destroy = "none";
|
3026 | this.enable = false;
|
3027 | this.speed = 2;
|
3028 | this.startValue = "random";
|
3029 | this.sync = false;
|
3030 | }
|
3031 | get opacity_min() {
|
3032 | return this.minimumValue;
|
3033 | }
|
3034 | set opacity_min(value) {
|
3035 | this.minimumValue = value;
|
3036 | }
|
3037 | load(data) {
|
3038 | var _a;
|
3039 | if (!data) {
|
3040 | return;
|
3041 | }
|
3042 | super.load(data);
|
3043 | if (data.destroy !== undefined) {
|
3044 | this.destroy = data.destroy;
|
3045 | }
|
3046 | if (data.enable !== undefined) {
|
3047 | this.enable = data.enable;
|
3048 | }
|
3049 | this.minimumValue = (_a = data.minimumValue) !== null && _a !== void 0 ? _a : data.opacity_min;
|
3050 | if (data.speed !== undefined) {
|
3051 | this.speed = data.speed;
|
3052 | }
|
3053 | if (data.startValue !== undefined) {
|
3054 | this.startValue = data.startValue;
|
3055 | }
|
3056 | if (data.sync !== undefined) {
|
3057 | this.sync = data.sync;
|
3058 | }
|
3059 | }
|
3060 | }
|
3061 | ;
|
3062 |
|
3063 |
|
3064 |
|
3065 | class Opacity extends ValueWithRandom {
|
3066 | constructor() {
|
3067 | super();
|
3068 | this.animation = new OpacityAnimation();
|
3069 | this.random.minimumValue = 0.1;
|
3070 | this.value = 1;
|
3071 | }
|
3072 | get anim() {
|
3073 | return this.animation;
|
3074 | }
|
3075 | set anim(value) {
|
3076 | this.animation = value;
|
3077 | }
|
3078 | load(data) {
|
3079 | var _a;
|
3080 | if (!data) {
|
3081 | return;
|
3082 | }
|
3083 | super.load(data);
|
3084 | const animation = (_a = data.animation) !== null && _a !== void 0 ? _a : data.anim;
|
3085 | if (animation !== undefined) {
|
3086 | this.animation.load(animation);
|
3087 | this.value = setRangeValue(this.value, this.animation.enable ? this.animation.minimumValue : undefined);
|
3088 | }
|
3089 | }
|
3090 | }
|
3091 | ;
|
3092 | class ParticlesDensity {
|
3093 | constructor() {
|
3094 | this.enable = false;
|
3095 | this.width = 1920;
|
3096 | this.height = 1080;
|
3097 | }
|
3098 | get area() {
|
3099 | return this.width;
|
3100 | }
|
3101 | set area(value) {
|
3102 | this.width = value;
|
3103 | }
|
3104 | get factor() {
|
3105 | return this.height;
|
3106 | }
|
3107 | set factor(value) {
|
3108 | this.height = value;
|
3109 | }
|
3110 | get value_area() {
|
3111 | return this.area;
|
3112 | }
|
3113 | set value_area(value) {
|
3114 | this.area = value;
|
3115 | }
|
3116 | load(data) {
|
3117 | var _a, _b, _c;
|
3118 | if (!data) {
|
3119 | return;
|
3120 | }
|
3121 | if (data.enable !== undefined) {
|
3122 | this.enable = data.enable;
|
3123 | }
|
3124 | const width = (_b = (_a = data.width) !== null && _a !== void 0 ? _a : data.area) !== null && _b !== void 0 ? _b : data.value_area;
|
3125 | if (width !== undefined) {
|
3126 | this.width = width;
|
3127 | }
|
3128 | const height = (_c = data.height) !== null && _c !== void 0 ? _c : data.factor;
|
3129 | if (height !== undefined) {
|
3130 | this.height = height;
|
3131 | }
|
3132 | }
|
3133 | }
|
3134 | ;
|
3135 |
|
3136 | class ParticlesNumber {
|
3137 | constructor() {
|
3138 | this.density = new ParticlesDensity();
|
3139 | this.limit = 0;
|
3140 | this.value = 100;
|
3141 | }
|
3142 | get max() {
|
3143 | return this.limit;
|
3144 | }
|
3145 | set max(value) {
|
3146 | this.limit = value;
|
3147 | }
|
3148 | load(data) {
|
3149 | var _a;
|
3150 | if (!data) {
|
3151 | return;
|
3152 | }
|
3153 | this.density.load(data.density);
|
3154 | const limit = (_a = data.limit) !== null && _a !== void 0 ? _a : data.max;
|
3155 | if (limit !== undefined) {
|
3156 | this.limit = limit;
|
3157 | }
|
3158 | if (data.value !== undefined) {
|
3159 | this.value = data.value;
|
3160 | }
|
3161 | }
|
3162 | }
|
3163 | ;
|
3164 |
|
3165 | class Shadow {
|
3166 | constructor() {
|
3167 | this.blur = 0;
|
3168 | this.color = new OptionsColor();
|
3169 | this.enable = false;
|
3170 | this.offset = {
|
3171 | x: 0,
|
3172 | y: 0
|
3173 | };
|
3174 | this.color.value = "#000";
|
3175 | }
|
3176 | load(data) {
|
3177 | if (!data) {
|
3178 | return;
|
3179 | }
|
3180 | if (data.blur !== undefined) {
|
3181 | this.blur = data.blur;
|
3182 | }
|
3183 | this.color = OptionsColor.create(this.color, data.color);
|
3184 | if (data.enable !== undefined) {
|
3185 | this.enable = data.enable;
|
3186 | }
|
3187 | if (data.offset === undefined) {
|
3188 | return;
|
3189 | }
|
3190 | if (data.offset.x !== undefined) {
|
3191 | this.offset.x = data.offset.x;
|
3192 | }
|
3193 | if (data.offset.y !== undefined) {
|
3194 | this.offset.y = data.offset.y;
|
3195 | }
|
3196 | }
|
3197 | }
|
3198 | ;
|
3199 |
|
3200 | const charKey = "character",
|
3201 | charAltKey = "char",
|
3202 | imageKey = "image",
|
3203 | imageAltKey = "images",
|
3204 | polygonKey = "polygon",
|
3205 | polygonAltKey = "star";
|
3206 | class Shape {
|
3207 | constructor() {
|
3208 | this.options = {};
|
3209 | this.type = "circle";
|
3210 | }
|
3211 | get character() {
|
3212 | var _a;
|
3213 | return (_a = this.options[charKey]) !== null && _a !== void 0 ? _a : this.options[charAltKey];
|
3214 | }
|
3215 | set character(value) {
|
3216 | this.options[charAltKey] = this.options[charKey] = value;
|
3217 | }
|
3218 | get custom() {
|
3219 | return this.options;
|
3220 | }
|
3221 | set custom(value) {
|
3222 | this.options = value;
|
3223 | }
|
3224 | get image() {
|
3225 | var _a;
|
3226 | return (_a = this.options[imageKey]) !== null && _a !== void 0 ? _a : this.options[imageAltKey];
|
3227 | }
|
3228 | set image(value) {
|
3229 | this.options[imageAltKey] = this.options[imageKey] = value;
|
3230 | }
|
3231 | get images() {
|
3232 | return this.image;
|
3233 | }
|
3234 | set images(value) {
|
3235 | this.image = value;
|
3236 | }
|
3237 | get polygon() {
|
3238 | var _a;
|
3239 | return (_a = this.options[polygonKey]) !== null && _a !== void 0 ? _a : this.options[polygonAltKey];
|
3240 | }
|
3241 | set polygon(value) {
|
3242 | this.options[polygonAltKey] = this.options[polygonKey] = value;
|
3243 | }
|
3244 | get stroke() {
|
3245 | return [];
|
3246 | }
|
3247 | set stroke(_value) {}
|
3248 | load(data) {
|
3249 | var _a, _b, _c;
|
3250 | if (!data) {
|
3251 | return;
|
3252 | }
|
3253 | const options = (_a = data.options) !== null && _a !== void 0 ? _a : data.custom;
|
3254 | if (options !== undefined) {
|
3255 | for (const shape in options) {
|
3256 | const item = options[shape];
|
3257 | if (item) {
|
3258 | this.options[shape] = deepExtend((_b = this.options[shape]) !== null && _b !== void 0 ? _b : {}, item);
|
3259 | }
|
3260 | }
|
3261 | }
|
3262 | this.loadShape(data.character, charKey, charAltKey, true);
|
3263 | this.loadShape(data.polygon, polygonKey, polygonAltKey, false);
|
3264 | this.loadShape((_c = data.image) !== null && _c !== void 0 ? _c : data.images, imageKey, imageAltKey, true);
|
3265 | if (data.type !== undefined) {
|
3266 | this.type = data.type;
|
3267 | }
|
3268 | }
|
3269 | loadShape(item, mainKey, altKey, altOverride) {
|
3270 | var _a, _b;
|
3271 | if (!item) {
|
3272 | return;
|
3273 | }
|
3274 | const isArray = item instanceof Array;
|
3275 | const emptyValue = isArray ? [] : {},
|
3276 | mainDifferentValues = isArray !== this.options[mainKey] instanceof Array,
|
3277 | altDifferentValues = isArray !== this.options[altKey] instanceof Array;
|
3278 | if (mainDifferentValues) {
|
3279 | this.options[mainKey] = emptyValue;
|
3280 | }
|
3281 | if (altDifferentValues && altOverride) {
|
3282 | this.options[altKey] = emptyValue;
|
3283 | }
|
3284 | this.options[mainKey] = deepExtend((_a = this.options[mainKey]) !== null && _a !== void 0 ? _a : emptyValue, item);
|
3285 | if (!this.options[altKey] || altOverride) {
|
3286 | this.options[altKey] = deepExtend((_b = this.options[altKey]) !== null && _b !== void 0 ? _b : emptyValue, item);
|
3287 | }
|
3288 | }
|
3289 | }
|
3290 | ;
|
3291 |
|
3292 | class SizeAnimation extends AnimationOptions {
|
3293 | constructor() {
|
3294 | super();
|
3295 | this.destroy = "none";
|
3296 | this.enable = false;
|
3297 | this.speed = 5;
|
3298 | this.startValue = "random";
|
3299 | this.sync = false;
|
3300 | }
|
3301 | get size_min() {
|
3302 | return this.minimumValue;
|
3303 | }
|
3304 | set size_min(value) {
|
3305 | this.minimumValue = value;
|
3306 | }
|
3307 | load(data) {
|
3308 | var _a;
|
3309 | super.load(data);
|
3310 | if (!data) {
|
3311 | return;
|
3312 | }
|
3313 | if (data.destroy !== undefined) {
|
3314 | this.destroy = data.destroy;
|
3315 | }
|
3316 | if (data.enable !== undefined) {
|
3317 | this.enable = data.enable;
|
3318 | }
|
3319 | this.minimumValue = (_a = data.minimumValue) !== null && _a !== void 0 ? _a : data.size_min;
|
3320 | if (data.speed !== undefined) {
|
3321 | this.speed = data.speed;
|
3322 | }
|
3323 | if (data.startValue !== undefined) {
|
3324 | this.startValue = data.startValue;
|
3325 | }
|
3326 | if (data.sync !== undefined) {
|
3327 | this.sync = data.sync;
|
3328 | }
|
3329 | }
|
3330 | }
|
3331 | ;
|
3332 |
|
3333 |
|
3334 |
|
3335 | class Size extends ValueWithRandom {
|
3336 | constructor() {
|
3337 | super();
|
3338 | this.animation = new SizeAnimation();
|
3339 | this.random.minimumValue = 1;
|
3340 | this.value = 3;
|
3341 | }
|
3342 | get anim() {
|
3343 | return this.animation;
|
3344 | }
|
3345 | set anim(value) {
|
3346 | this.animation = value;
|
3347 | }
|
3348 | load(data) {
|
3349 | var _a;
|
3350 | super.load(data);
|
3351 | if (!data) {
|
3352 | return;
|
3353 | }
|
3354 | const animation = (_a = data.animation) !== null && _a !== void 0 ? _a : data.anim;
|
3355 | if (animation !== undefined) {
|
3356 | this.animation.load(animation);
|
3357 | this.value = setRangeValue(this.value, this.animation.enable ? this.animation.minimumValue : undefined);
|
3358 | }
|
3359 | }
|
3360 | }
|
3361 | ;
|
3362 |
|
3363 |
|
3364 | class Stroke {
|
3365 | constructor() {
|
3366 | this.width = 0;
|
3367 | }
|
3368 | load(data) {
|
3369 | if (!data) {
|
3370 | return;
|
3371 | }
|
3372 | if (data.color !== undefined) {
|
3373 | this.color = AnimatableColor.create(this.color, data.color);
|
3374 | }
|
3375 | if (data.width !== undefined) {
|
3376 | this.width = setRangeValue(data.width);
|
3377 | }
|
3378 | if (data.opacity !== undefined) {
|
3379 | this.opacity = setRangeValue(data.opacity);
|
3380 | }
|
3381 | }
|
3382 | }
|
3383 | ;
|
3384 |
|
3385 | class ZIndex extends ValueWithRandom {
|
3386 | constructor() {
|
3387 | super();
|
3388 | this.opacityRate = 1;
|
3389 | this.sizeRate = 1;
|
3390 | this.velocityRate = 1;
|
3391 | }
|
3392 | load(data) {
|
3393 | super.load(data);
|
3394 | if (!data) {
|
3395 | return;
|
3396 | }
|
3397 | if (data.opacityRate !== undefined) {
|
3398 | this.opacityRate = data.opacityRate;
|
3399 | }
|
3400 | if (data.sizeRate !== undefined) {
|
3401 | this.sizeRate = data.sizeRate;
|
3402 | }
|
3403 | if (data.velocityRate !== undefined) {
|
3404 | this.velocityRate = data.velocityRate;
|
3405 | }
|
3406 | }
|
3407 | }
|
3408 | ;
|
3409 |
|
3410 |
|
3411 |
|
3412 |
|
3413 |
|
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 | class ParticlesOptions {
|
3422 | constructor(engine, container) {
|
3423 | this._engine = engine;
|
3424 | this._container = container;
|
3425 | this.bounce = new ParticlesBounce();
|
3426 | this.collisions = new Collisions();
|
3427 | this.color = new AnimatableColor();
|
3428 | this.color.value = "#fff";
|
3429 | this.groups = {};
|
3430 | this.move = new Move();
|
3431 | this.number = new ParticlesNumber();
|
3432 | this.opacity = new Opacity();
|
3433 | this.reduceDuplicates = false;
|
3434 | this.shadow = new Shadow();
|
3435 | this.shape = new Shape();
|
3436 | this.size = new Size();
|
3437 | this.stroke = new Stroke();
|
3438 | this.zIndex = new ZIndex();
|
3439 | }
|
3440 | load(data) {
|
3441 | var _a, _b, _c, _d, _e, _f;
|
3442 | if (!data) {
|
3443 | return;
|
3444 | }
|
3445 | this.bounce.load(data.bounce);
|
3446 | this.color.load(AnimatableColor.create(this.color, data.color));
|
3447 | if (data.groups !== undefined) {
|
3448 | for (const group in data.groups) {
|
3449 | const item = data.groups[group];
|
3450 | if (item !== undefined) {
|
3451 | this.groups[group] = deepExtend((_a = this.groups[group]) !== null && _a !== void 0 ? _a : {}, item);
|
3452 | }
|
3453 | }
|
3454 | }
|
3455 | this.move.load(data.move);
|
3456 | this.number.load(data.number);
|
3457 | this.opacity.load(data.opacity);
|
3458 | if (data.reduceDuplicates !== undefined) {
|
3459 | this.reduceDuplicates = data.reduceDuplicates;
|
3460 | }
|
3461 | this.shape.load(data.shape);
|
3462 | this.size.load(data.size);
|
3463 | this.shadow.load(data.shadow);
|
3464 | this.zIndex.load(data.zIndex);
|
3465 | const collisions = (_c = (_b = data.move) === null || _b === void 0 ? void 0 : _b.collisions) !== null && _c !== void 0 ? _c : (_d = data.move) === null || _d === void 0 ? void 0 : _d.bounce;
|
3466 | if (collisions !== undefined) {
|
3467 | this.collisions.enable = collisions;
|
3468 | }
|
3469 | this.collisions.load(data.collisions);
|
3470 | if (data.interactivity !== undefined) {
|
3471 | this.interactivity = deepExtend({}, data.interactivity);
|
3472 | }
|
3473 | const strokeToLoad = (_e = data.stroke) !== null && _e !== void 0 ? _e : (_f = data.shape) === null || _f === void 0 ? void 0 : _f.stroke;
|
3474 | if (strokeToLoad) {
|
3475 | this.stroke = executeOnSingleOrMultiple(strokeToLoad, t => {
|
3476 | const tmp = new Stroke();
|
3477 | tmp.load(t);
|
3478 | return tmp;
|
3479 | });
|
3480 | }
|
3481 | if (this._container) {
|
3482 | const updaters = this._engine.plugins.updaters.get(this._container);
|
3483 | if (updaters) {
|
3484 | for (const updater of updaters) {
|
3485 | if (updater.loadOptions) {
|
3486 | updater.loadOptions(this, data);
|
3487 | }
|
3488 | }
|
3489 | }
|
3490 | const interactors = this._engine.plugins.interactors.get(this._container);
|
3491 | if (interactors) {
|
3492 | for (const interactor of interactors) {
|
3493 | if (interactor.loadParticlesOptions) {
|
3494 | interactor.loadParticlesOptions(this, data);
|
3495 | }
|
3496 | }
|
3497 | }
|
3498 | }
|
3499 | }
|
3500 | }
|
3501 | ;
|
3502 |
|
3503 | function loadOptions(options, ...sourceOptionsArr) {
|
3504 | for (const sourceOptions of sourceOptionsArr) {
|
3505 | options.load(sourceOptions);
|
3506 | }
|
3507 | }
|
3508 | function loadParticlesOptions(engine, container, ...sourceOptionsArr) {
|
3509 | const options = new ParticlesOptions(engine, container);
|
3510 | loadOptions(options, ...sourceOptionsArr);
|
3511 | return options;
|
3512 | }
|
3513 | ;
|
3514 |
|
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 | class Options {
|
3525 | constructor(engine, container) {
|
3526 | this._engine = engine;
|
3527 | this._container = container;
|
3528 | this.autoPlay = true;
|
3529 | this.background = new Background();
|
3530 | this.backgroundMask = new BackgroundMask();
|
3531 | this.defaultThemes = {};
|
3532 | this.delay = 0;
|
3533 | this.fullScreen = new FullScreen();
|
3534 | this.detectRetina = true;
|
3535 | this.duration = 0;
|
3536 | this.fpsLimit = 120;
|
3537 | this.interactivity = new Interactivity(engine, container);
|
3538 | this.manualParticles = [];
|
3539 | this.particles = loadParticlesOptions(this._engine, this._container);
|
3540 | this.pauseOnBlur = true;
|
3541 | this.pauseOnOutsideViewport = true;
|
3542 | this.responsive = [];
|
3543 | this.smooth = false;
|
3544 | this.style = {};
|
3545 | this.themes = [];
|
3546 | this.zLayers = 100;
|
3547 | }
|
3548 | get backgroundMode() {
|
3549 | return this.fullScreen;
|
3550 | }
|
3551 | set backgroundMode(value) {
|
3552 | this.fullScreen.load(value);
|
3553 | }
|
3554 | get fps_limit() {
|
3555 | return this.fpsLimit;
|
3556 | }
|
3557 | set fps_limit(value) {
|
3558 | this.fpsLimit = value;
|
3559 | }
|
3560 | get retina_detect() {
|
3561 | return this.detectRetina;
|
3562 | }
|
3563 | set retina_detect(value) {
|
3564 | this.detectRetina = value;
|
3565 | }
|
3566 | load(data) {
|
3567 | var _a, _b, _c, _d, _e;
|
3568 | if (!data) {
|
3569 | return;
|
3570 | }
|
3571 | if (data.preset !== undefined) {
|
3572 | executeOnSingleOrMultiple(data.preset, preset => this._importPreset(preset));
|
3573 | }
|
3574 | if (data.autoPlay !== undefined) {
|
3575 | this.autoPlay = data.autoPlay;
|
3576 | }
|
3577 | if (data.delay !== undefined) {
|
3578 | this.delay = setRangeValue(data.delay);
|
3579 | }
|
3580 | const detectRetina = (_a = data.detectRetina) !== null && _a !== void 0 ? _a : data.retina_detect;
|
3581 | if (detectRetina !== undefined) {
|
3582 | this.detectRetina = detectRetina;
|
3583 | }
|
3584 | if (data.duration !== undefined) {
|
3585 | this.duration = setRangeValue(data.duration);
|
3586 | }
|
3587 | const fpsLimit = (_b = data.fpsLimit) !== null && _b !== void 0 ? _b : data.fps_limit;
|
3588 | if (fpsLimit !== undefined) {
|
3589 | this.fpsLimit = fpsLimit;
|
3590 | }
|
3591 | if (data.pauseOnBlur !== undefined) {
|
3592 | this.pauseOnBlur = data.pauseOnBlur;
|
3593 | }
|
3594 | if (data.pauseOnOutsideViewport !== undefined) {
|
3595 | this.pauseOnOutsideViewport = data.pauseOnOutsideViewport;
|
3596 | }
|
3597 | if (data.zLayers !== undefined) {
|
3598 | this.zLayers = data.zLayers;
|
3599 | }
|
3600 | this.background.load(data.background);
|
3601 | const fullScreen = (_c = data.fullScreen) !== null && _c !== void 0 ? _c : data.backgroundMode;
|
3602 | if (typeof fullScreen === "boolean") {
|
3603 | this.fullScreen.enable = fullScreen;
|
3604 | } else {
|
3605 | this.fullScreen.load(fullScreen);
|
3606 | }
|
3607 | this.backgroundMask.load(data.backgroundMask);
|
3608 | this.interactivity.load(data.interactivity);
|
3609 | if (data.manualParticles !== undefined) {
|
3610 | this.manualParticles = data.manualParticles.map(t => {
|
3611 | const tmp = new ManualParticle();
|
3612 | tmp.load(t);
|
3613 | return tmp;
|
3614 | });
|
3615 | }
|
3616 | this.particles.load(data.particles);
|
3617 | this.style = deepExtend(this.style, data.style);
|
3618 | this._engine.plugins.loadOptions(this, data);
|
3619 | if (data.smooth !== undefined) {
|
3620 | this.smooth = data.smooth;
|
3621 | }
|
3622 | const interactors = this._engine.plugins.interactors.get(this._container);
|
3623 | if (interactors) {
|
3624 | for (const interactor of interactors) {
|
3625 | if (interactor.loadOptions) {
|
3626 | interactor.loadOptions(this, data);
|
3627 | }
|
3628 | }
|
3629 | }
|
3630 | if (data.responsive !== undefined) {
|
3631 | for (const responsive of data.responsive) {
|
3632 | const optResponsive = new Responsive();
|
3633 | optResponsive.load(responsive);
|
3634 | this.responsive.push(optResponsive);
|
3635 | }
|
3636 | }
|
3637 | this.responsive.sort((a, b) => a.maxWidth - b.maxWidth);
|
3638 | if (data.themes !== undefined) {
|
3639 | for (const theme of data.themes) {
|
3640 | const existingTheme = this.themes.find(t => t.name === theme.name);
|
3641 | if (!existingTheme) {
|
3642 | const optTheme = new Theme();
|
3643 | optTheme.load(theme);
|
3644 | this.themes.push(optTheme);
|
3645 | } else {
|
3646 | existingTheme.load(theme);
|
3647 | }
|
3648 | }
|
3649 | }
|
3650 | this.defaultThemes.dark = (_d = this._findDefaultTheme("dark")) === null || _d === void 0 ? void 0 : _d.name;
|
3651 | this.defaultThemes.light = (_e = this._findDefaultTheme("light")) === null || _e === void 0 ? void 0 : _e.name;
|
3652 | }
|
3653 | setResponsive(width, pxRatio, defaultOptions) {
|
3654 | this.load(defaultOptions);
|
3655 | const responsiveOptions = this.responsive.find(t => t.mode === "screen" && screen ? t.maxWidth > screen.availWidth : t.maxWidth * pxRatio > width);
|
3656 | this.load(responsiveOptions === null || responsiveOptions === void 0 ? void 0 : responsiveOptions.options);
|
3657 | return responsiveOptions === null || responsiveOptions === void 0 ? void 0 : responsiveOptions.maxWidth;
|
3658 | }
|
3659 | setTheme(name) {
|
3660 | if (name) {
|
3661 | const chosenTheme = this.themes.find(theme => theme.name === name);
|
3662 | if (chosenTheme) {
|
3663 | this.load(chosenTheme.options);
|
3664 | }
|
3665 | } else {
|
3666 | const mediaMatch = safeMatchMedia("(prefers-color-scheme: dark)"),
|
3667 | clientDarkMode = mediaMatch && mediaMatch.matches,
|
3668 | defaultTheme = this._findDefaultTheme(clientDarkMode ? "dark" : "light");
|
3669 | if (defaultTheme) {
|
3670 | this.load(defaultTheme.options);
|
3671 | }
|
3672 | }
|
3673 | }
|
3674 | _findDefaultTheme(mode) {
|
3675 | var _a;
|
3676 | return (_a = this.themes.find(theme => theme.default.value && theme.default.mode === mode)) !== null && _a !== void 0 ? _a : this.themes.find(theme => theme.default.value && theme.default.mode === "any");
|
3677 | }
|
3678 | _importPreset(preset) {
|
3679 | this.load(this._engine.plugins.getPreset(preset));
|
3680 | }
|
3681 | }
|
3682 | ;
|
3683 | class InteractionManager {
|
3684 | constructor(engine, container) {
|
3685 | this.container = container;
|
3686 | this._engine = engine;
|
3687 | this._interactors = this._engine.plugins.getInteractors(this.container, true);
|
3688 | this._externalInteractors = [];
|
3689 | this._particleInteractors = [];
|
3690 | }
|
3691 | async externalInteract(delta) {
|
3692 | for (const interactor of this._externalInteractors) {
|
3693 | if (interactor.isEnabled()) {
|
3694 | await interactor.interact(delta);
|
3695 | }
|
3696 | }
|
3697 | }
|
3698 | handleClickMode(mode) {
|
3699 | for (const interactor of this._externalInteractors) {
|
3700 | if (interactor.handleClickMode) {
|
3701 | interactor.handleClickMode(mode);
|
3702 | }
|
3703 | }
|
3704 | }
|
3705 | init() {
|
3706 | this._externalInteractors = [];
|
3707 | this._particleInteractors = [];
|
3708 | for (const interactor of this._interactors) {
|
3709 | switch (interactor.type) {
|
3710 | case "external":
|
3711 | this._externalInteractors.push(interactor);
|
3712 | break;
|
3713 | case "particles":
|
3714 | this._particleInteractors.push(interactor);
|
3715 | break;
|
3716 | }
|
3717 | interactor.init();
|
3718 | }
|
3719 | }
|
3720 | async particlesInteract(particle, delta) {
|
3721 | for (const interactor of this._externalInteractors) {
|
3722 | interactor.clear(particle, delta);
|
3723 | }
|
3724 | for (const interactor of this._particleInteractors) {
|
3725 | if (interactor.isEnabled(particle)) {
|
3726 | await interactor.interact(particle, delta);
|
3727 | }
|
3728 | }
|
3729 | }
|
3730 | async reset(particle) {
|
3731 | for (const interactor of this._externalInteractors) {
|
3732 | if (interactor.isEnabled()) {
|
3733 | await interactor.reset(particle);
|
3734 | }
|
3735 | }
|
3736 | for (const interactor of this._particleInteractors) {
|
3737 | if (interactor.isEnabled(particle)) {
|
3738 | await interactor.reset(particle);
|
3739 | }
|
3740 | }
|
3741 | }
|
3742 | }
|
3743 | ;
|
3744 |
|
3745 |
|
3746 |
|
3747 |
|
3748 |
|
3749 |
|
3750 |
|
3751 |
|
3752 | const fixOutMode = data => {
|
3753 | if (!isInArray(data.outMode, data.checkModes)) {
|
3754 | return;
|
3755 | }
|
3756 | if (data.coord > data.maxCoord - data.radius * 2) {
|
3757 | data.setCb(-data.radius);
|
3758 | } else if (data.coord < data.radius * 2) {
|
3759 | data.setCb(data.radius);
|
3760 | }
|
3761 | };
|
3762 | class Particle {
|
3763 | constructor(engine, id, container, position, overrideOptions, group) {
|
3764 | this.container = container;
|
3765 | this._engine = engine;
|
3766 | this.init(id, position, overrideOptions, group);
|
3767 | }
|
3768 | destroy(override) {
|
3769 | var _a;
|
3770 | if (this.unbreakable || this.destroyed) {
|
3771 | return;
|
3772 | }
|
3773 | this.destroyed = true;
|
3774 | this.bubble.inRange = false;
|
3775 | this.slow.inRange = false;
|
3776 | for (const [, plugin] of this.container.plugins) {
|
3777 | if (plugin.particleDestroyed) {
|
3778 | plugin.particleDestroyed(this, override);
|
3779 | }
|
3780 | }
|
3781 | for (const updater of this.container.particles.updaters) {
|
3782 | if (updater.particleDestroyed) {
|
3783 | updater.particleDestroyed(this, override);
|
3784 | }
|
3785 | }
|
3786 | (_a = this.pathGenerator) === null || _a === void 0 ? void 0 : _a.reset(this);
|
3787 | }
|
3788 | draw(delta) {
|
3789 | const container = this.container;
|
3790 | for (const [, plugin] of container.plugins) {
|
3791 | container.canvas.drawParticlePlugin(plugin, this, delta);
|
3792 | }
|
3793 | container.canvas.drawParticle(this, delta);
|
3794 | }
|
3795 | getFillColor() {
|
3796 | var _a;
|
3797 | return this._getRollColor((_a = this.bubble.color) !== null && _a !== void 0 ? _a : getHslFromAnimation(this.color));
|
3798 | }
|
3799 | getMass() {
|
3800 | return this.getRadius() ** 2 * Math.PI / 2;
|
3801 | }
|
3802 | getPosition() {
|
3803 | return {
|
3804 | x: this.position.x + this.offset.x,
|
3805 | y: this.position.y + this.offset.y,
|
3806 | z: this.position.z
|
3807 | };
|
3808 | }
|
3809 | getRadius() {
|
3810 | var _a;
|
3811 | return (_a = this.bubble.radius) !== null && _a !== void 0 ? _a : this.size.value;
|
3812 | }
|
3813 | getStrokeColor() {
|
3814 | var _a;
|
3815 | return this._getRollColor((_a = this.bubble.color) !== null && _a !== void 0 ? _a : getHslFromAnimation(this.strokeColor));
|
3816 | }
|
3817 | init(id, position, overrideOptions, group) {
|
3818 | var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
3819 | const container = this.container,
|
3820 | engine = this._engine;
|
3821 | this.id = id;
|
3822 | this.group = group;
|
3823 | this.fill = true;
|
3824 | this.pathRotation = false;
|
3825 | this.close = true;
|
3826 | this.lastPathTime = 0;
|
3827 | this.destroyed = false;
|
3828 | this.unbreakable = false;
|
3829 | this.rotation = 0;
|
3830 | this.misplaced = false;
|
3831 | this.retina = {
|
3832 | maxDistance: {}
|
3833 | };
|
3834 | this.outType = "normal";
|
3835 | this.ignoresResizeRatio = true;
|
3836 | const pxRatio = container.retina.pixelRatio,
|
3837 | mainOptions = container.actualOptions,
|
3838 | particlesOptions = loadParticlesOptions(this._engine, container, mainOptions.particles),
|
3839 | shapeType = particlesOptions.shape.type,
|
3840 | {
|
3841 | reduceDuplicates
|
3842 | } = particlesOptions;
|
3843 | this.shape = itemFromSingleOrMultiple(shapeType, this.id, reduceDuplicates);
|
3844 | const shapeOptions = particlesOptions.shape;
|
3845 | if (overrideOptions && overrideOptions.shape && overrideOptions.shape.type) {
|
3846 | const overrideShapeType = overrideOptions.shape.type,
|
3847 | shape = itemFromSingleOrMultiple(overrideShapeType, this.id, reduceDuplicates);
|
3848 | if (shape) {
|
3849 | this.shape = shape;
|
3850 | shapeOptions.load(overrideOptions.shape);
|
3851 | }
|
3852 | }
|
3853 | this.shapeData = this._loadShapeData(shapeOptions, reduceDuplicates);
|
3854 | particlesOptions.load(overrideOptions);
|
3855 | particlesOptions.load((_a = this.shapeData) === null || _a === void 0 ? void 0 : _a.particles);
|
3856 | this.interactivity = new Interactivity(engine, container);
|
3857 | this.interactivity.load(container.actualOptions.interactivity);
|
3858 | this.interactivity.load(particlesOptions.interactivity);
|
3859 | this.fill = (_c = (_b = this.shapeData) === null || _b === void 0 ? void 0 : _b.fill) !== null && _c !== void 0 ? _c : this.fill;
|
3860 | this.close = (_e = (_d = this.shapeData) === null || _d === void 0 ? void 0 : _d.close) !== null && _e !== void 0 ? _e : this.close;
|
3861 | this.options = particlesOptions;
|
3862 | const pathOptions = this.options.move.path;
|
3863 | this.pathDelay = getValue(pathOptions.delay) * 1000;
|
3864 | if (pathOptions.generator) {
|
3865 | this.pathGenerator = this._engine.plugins.getPathGenerator(pathOptions.generator);
|
3866 | if (this.pathGenerator && container.addPath(pathOptions.generator, this.pathGenerator)) {
|
3867 | this.pathGenerator.init(container);
|
3868 | }
|
3869 | }
|
3870 | const zIndexValue = getRangeValue(this.options.zIndex.value);
|
3871 | container.retina.initParticle(this);
|
3872 | const sizeOptions = this.options.size,
|
3873 | sizeRange = sizeOptions.value,
|
3874 | sizeAnimation = sizeOptions.animation;
|
3875 | this.size = {
|
3876 | enable: sizeOptions.animation.enable,
|
3877 | value: getRangeValue(sizeOptions.value) * container.retina.pixelRatio,
|
3878 | max: getRangeMax(sizeRange) * pxRatio,
|
3879 | min: getRangeMin(sizeRange) * pxRatio,
|
3880 | loops: 0,
|
3881 | maxLoops: getRangeValue(sizeOptions.animation.count)
|
3882 | };
|
3883 | if (sizeAnimation.enable) {
|
3884 | this.size.status = "increasing";
|
3885 | this.size.decay = 1 - getRangeValue(sizeAnimation.decay);
|
3886 | switch (sizeAnimation.startValue) {
|
3887 | case "min":
|
3888 | this.size.value = this.size.min;
|
3889 | this.size.status = "increasing";
|
3890 | break;
|
3891 | case "random":
|
3892 | this.size.value = randomInRange(this.size);
|
3893 | this.size.status = getRandom() >= 0.5 ? "increasing" : "decreasing";
|
3894 | break;
|
3895 | case "max":
|
3896 | default:
|
3897 | this.size.value = this.size.max;
|
3898 | this.size.status = "decreasing";
|
3899 | break;
|
3900 | }
|
3901 | }
|
3902 | this.size.initialValue = this.size.value;
|
3903 | this.bubble = {
|
3904 | inRange: false
|
3905 | };
|
3906 | this.slow = {
|
3907 | inRange: false,
|
3908 | factor: 1
|
3909 | };
|
3910 | this.position = this._calcPosition(container, position, clamp(zIndexValue, 0, container.zLayers));
|
3911 | this.initialPosition = this.position.copy();
|
3912 | const canvasSize = container.canvas.size,
|
3913 | moveCenter = Object.assign({}, this.options.move.center),
|
3914 | isCenterPercent = moveCenter.mode === "percent";
|
3915 | this.moveCenter = {
|
3916 | x: moveCenter.x * (isCenterPercent ? canvasSize.width / 100 : 1),
|
3917 | y: moveCenter.y * (isCenterPercent ? canvasSize.height / 100 : 1),
|
3918 | radius: (_f = this.options.move.center.radius) !== null && _f !== void 0 ? _f : 0,
|
3919 | mode: (_g = this.options.move.center.mode) !== null && _g !== void 0 ? _g : "percent"
|
3920 | };
|
3921 | this.direction = getParticleDirectionAngle(this.options.move.direction, this.position, this.moveCenter);
|
3922 | switch (this.options.move.direction) {
|
3923 | case "inside":
|
3924 | this.outType = "inside";
|
3925 | break;
|
3926 | case "outside":
|
3927 | this.outType = "outside";
|
3928 | break;
|
3929 | }
|
3930 | this.initialVelocity = this._calculateVelocity();
|
3931 | this.velocity = this.initialVelocity.copy();
|
3932 | this.moveDecay = 1 - getRangeValue(this.options.move.decay);
|
3933 | this.offset = Vector.origin;
|
3934 | const particles = container.particles;
|
3935 | particles.needsSort = particles.needsSort || particles.lastZIndex < this.position.z;
|
3936 | particles.lastZIndex = this.position.z;
|
3937 | this.zIndexFactor = this.position.z / container.zLayers;
|
3938 | this.sides = 24;
|
3939 | let drawer = container.drawers.get(this.shape);
|
3940 | if (!drawer) {
|
3941 | drawer = this._engine.plugins.getShapeDrawer(this.shape);
|
3942 | if (drawer) {
|
3943 | container.drawers.set(this.shape, drawer);
|
3944 | }
|
3945 | }
|
3946 | if (drawer === null || drawer === void 0 ? void 0 : drawer.loadShape) {
|
3947 | drawer === null || drawer === void 0 ? void 0 : drawer.loadShape(this);
|
3948 | }
|
3949 | const sideCountFunc = drawer === null || drawer === void 0 ? void 0 : drawer.getSidesCount;
|
3950 | if (sideCountFunc) {
|
3951 | this.sides = sideCountFunc(this);
|
3952 | }
|
3953 | this.spawning = false;
|
3954 | this.shadowColor = rangeColorToRgb(this.options.shadow.color);
|
3955 | for (const updater of container.particles.updaters) {
|
3956 | updater.init(this);
|
3957 | }
|
3958 | for (const mover of container.particles.movers) {
|
3959 | (_h = mover.init) === null || _h === void 0 ? void 0 : _h.call(mover, this);
|
3960 | }
|
3961 | if (drawer === null || drawer === void 0 ? void 0 : drawer.particleInit) {
|
3962 | drawer.particleInit(container, this);
|
3963 | }
|
3964 | for (const [, plugin] of container.plugins) {
|
3965 | (_j = plugin.particleCreated) === null || _j === void 0 ? void 0 : _j.call(plugin, this);
|
3966 | }
|
3967 | }
|
3968 | isInsideCanvas() {
|
3969 | const radius = this.getRadius(),
|
3970 | canvasSize = this.container.canvas.size;
|
3971 | return this.position.x >= -radius && this.position.y >= -radius && this.position.y <= canvasSize.height + radius && this.position.x <= canvasSize.width + radius;
|
3972 | }
|
3973 | isVisible() {
|
3974 | return !this.destroyed && !this.spawning && this.isInsideCanvas();
|
3975 | }
|
3976 | reset() {
|
3977 | var _a;
|
3978 | for (const updater of this.container.particles.updaters) {
|
3979 | (_a = updater.reset) === null || _a === void 0 ? void 0 : _a.call(updater, this);
|
3980 | }
|
3981 | }
|
3982 | _calcPosition(container, position, zIndex, tryCount = 0) {
|
3983 | var _a, _b, _c, _d;
|
3984 | for (const [, plugin] of container.plugins) {
|
3985 | const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
3986 | if (pluginPos !== undefined) {
|
3987 | return Vector3d.create(pluginPos.x, pluginPos.y, zIndex);
|
3988 | }
|
3989 | }
|
3990 | const canvasSize = container.canvas.size,
|
3991 | exactPosition = calcExactPositionOrRandomFromSize({
|
3992 | size: canvasSize,
|
3993 | position: position
|
3994 | }),
|
3995 | pos = Vector3d.create(exactPosition.x, exactPosition.y, zIndex),
|
3996 | radius = this.getRadius(),
|
3997 | outModes = this.options.move.outModes,
|
3998 | fixHorizontal = outMode => {
|
3999 | fixOutMode({
|
4000 | outMode,
|
4001 | checkModes: ["bounce", "bounce-horizontal"],
|
4002 | coord: pos.x,
|
4003 | maxCoord: container.canvas.size.width,
|
4004 | setCb: value => pos.x += value,
|
4005 | radius
|
4006 | });
|
4007 | },
|
4008 | fixVertical = outMode => {
|
4009 | fixOutMode({
|
4010 | outMode,
|
4011 | checkModes: ["bounce", "bounce-vertical"],
|
4012 | coord: pos.y,
|
4013 | maxCoord: container.canvas.size.height,
|
4014 | setCb: value => pos.y += value,
|
4015 | radius
|
4016 | });
|
4017 | };
|
4018 | fixHorizontal((_a = outModes.left) !== null && _a !== void 0 ? _a : outModes.default);
|
4019 | fixHorizontal((_b = outModes.right) !== null && _b !== void 0 ? _b : outModes.default);
|
4020 | fixVertical((_c = outModes.top) !== null && _c !== void 0 ? _c : outModes.default);
|
4021 | fixVertical((_d = outModes.bottom) !== null && _d !== void 0 ? _d : outModes.default);
|
4022 | if (this._checkOverlap(pos, tryCount)) {
|
4023 | return this._calcPosition(container, undefined, zIndex, tryCount + 1);
|
4024 | }
|
4025 | return pos;
|
4026 | }
|
4027 | _calculateVelocity() {
|
4028 | const baseVelocity = getParticleBaseVelocity(this.direction),
|
4029 | res = baseVelocity.copy(),
|
4030 | moveOptions = this.options.move;
|
4031 | if (moveOptions.direction === "inside" || moveOptions.direction === "outside") {
|
4032 | return res;
|
4033 | }
|
4034 | const rad = Math.PI / 180 * getRangeValue(moveOptions.angle.value),
|
4035 | radOffset = Math.PI / 180 * getRangeValue(moveOptions.angle.offset),
|
4036 | range = {
|
4037 | left: radOffset - rad / 2,
|
4038 | right: radOffset + rad / 2
|
4039 | };
|
4040 | if (!moveOptions.straight) {
|
4041 | res.angle += randomInRange(setRangeValue(range.left, range.right));
|
4042 | }
|
4043 | if (moveOptions.random && typeof moveOptions.speed === "number") {
|
4044 | res.length *= getRandom();
|
4045 | }
|
4046 | return res;
|
4047 | }
|
4048 | _checkOverlap(pos, tryCount = 0) {
|
4049 | const collisionsOptions = this.options.collisions,
|
4050 | radius = this.getRadius();
|
4051 | if (!collisionsOptions.enable) {
|
4052 | return false;
|
4053 | }
|
4054 | const overlapOptions = collisionsOptions.overlap;
|
4055 | if (overlapOptions.enable) {
|
4056 | return false;
|
4057 | }
|
4058 | const retries = overlapOptions.retries;
|
4059 | if (retries >= 0 && tryCount > retries) {
|
4060 | throw new Error("Particle is overlapping and can't be placed");
|
4061 | }
|
4062 | let overlaps = false;
|
4063 | for (const particle of this.container.particles.array) {
|
4064 | if (getDistance(pos, particle.position) < radius + particle.getRadius()) {
|
4065 | overlaps = true;
|
4066 | break;
|
4067 | }
|
4068 | }
|
4069 | return overlaps;
|
4070 | }
|
4071 | _getRollColor(color) {
|
4072 | var _a;
|
4073 | if (!color || !this.roll || !this.backColor && !this.roll.alter) {
|
4074 | return color;
|
4075 | }
|
4076 | const backFactor = this.roll.horizontal && this.roll.vertical ? 2 : 1,
|
4077 | backSum = this.roll.horizontal ? Math.PI / 2 : 0,
|
4078 | rolled = Math.floor((((_a = this.roll.angle) !== null && _a !== void 0 ? _a : 0) + backSum) / (Math.PI / backFactor)) % 2;
|
4079 | if (!rolled) {
|
4080 | return color;
|
4081 | }
|
4082 | if (this.backColor) {
|
4083 | return this.backColor;
|
4084 | }
|
4085 | if (this.roll.alter) {
|
4086 | return alterHsl(color, this.roll.alter.type, this.roll.alter.value);
|
4087 | }
|
4088 | return color;
|
4089 | }
|
4090 | _loadShapeData(shapeOptions, reduceDuplicates) {
|
4091 | const shapeData = shapeOptions.options[this.shape];
|
4092 | if (shapeData) {
|
4093 | return deepExtend({}, itemFromSingleOrMultiple(shapeData, this.id, reduceDuplicates));
|
4094 | }
|
4095 | }
|
4096 | }
|
4097 | ;
|
4098 | class Point {
|
4099 | constructor(position, particle) {
|
4100 | this.position = position;
|
4101 | this.particle = particle;
|
4102 | }
|
4103 | }
|
4104 | ;
|
4105 | class Range {
|
4106 | constructor(x, y) {
|
4107 | this.position = {
|
4108 | x: x,
|
4109 | y: y
|
4110 | };
|
4111 | }
|
4112 | }
|
4113 | ;
|
4114 |
|
4115 |
|
4116 | class Circle extends Range {
|
4117 | constructor(x, y, radius) {
|
4118 | super(x, y);
|
4119 | this.radius = radius;
|
4120 | }
|
4121 | contains(point) {
|
4122 | return getDistance(point, this.position) <= this.radius;
|
4123 | }
|
4124 | intersects(range) {
|
4125 | const rect = range,
|
4126 | circle = range,
|
4127 | pos1 = this.position,
|
4128 | pos2 = range.position,
|
4129 | distPos = {
|
4130 | x: Math.abs(pos2.x - pos1.x),
|
4131 | y: Math.abs(pos2.y - pos1.y)
|
4132 | },
|
4133 | r = this.radius;
|
4134 | if (circle.radius !== undefined) {
|
4135 | const rSum = r + circle.radius,
|
4136 | dist = Math.sqrt(distPos.x ** 2 + distPos.y ** 2);
|
4137 | return rSum > dist;
|
4138 | } else if (rect.size !== undefined) {
|
4139 | const w = rect.size.width,
|
4140 | h = rect.size.height,
|
4141 | edges = Math.pow(distPos.x - w, 2) + Math.pow(distPos.y - h, 2);
|
4142 | return edges <= r ** 2 || distPos.x <= r + w && distPos.y <= r + h || distPos.x <= w || distPos.y <= h;
|
4143 | }
|
4144 | return false;
|
4145 | }
|
4146 | }
|
4147 | ;
|
4148 |
|
4149 |
|
4150 | class Rectangle extends Range {
|
4151 | constructor(x, y, width, height) {
|
4152 | super(x, y);
|
4153 | this.size = {
|
4154 | height: height,
|
4155 | width: width
|
4156 | };
|
4157 | }
|
4158 | contains(point) {
|
4159 | const w = this.size.width,
|
4160 | h = this.size.height,
|
4161 | pos = this.position;
|
4162 | return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h;
|
4163 | }
|
4164 | intersects(range) {
|
4165 | if (range instanceof Circle) {
|
4166 | range.intersects(this);
|
4167 | }
|
4168 | const w = this.size.width,
|
4169 | h = this.size.height,
|
4170 | pos1 = this.position,
|
4171 | pos2 = range.position,
|
4172 | size2 = range instanceof Rectangle ? range.size : {
|
4173 | width: 0,
|
4174 | height: 0
|
4175 | },
|
4176 | w2 = size2.width,
|
4177 | h2 = size2.height;
|
4178 | return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y;
|
4179 | }
|
4180 | }
|
4181 | ;
|
4182 |
|
4183 |
|
4184 |
|
4185 | class QuadTree {
|
4186 | constructor(rectangle, capacity) {
|
4187 | this.rectangle = rectangle;
|
4188 | this.capacity = capacity;
|
4189 | this._points = [];
|
4190 | this._divided = false;
|
4191 | }
|
4192 | insert(point) {
|
4193 | var _a, _b, _c, _d, _e;
|
4194 | if (!this.rectangle.contains(point.position)) {
|
4195 | return false;
|
4196 | }
|
4197 | if (this._points.length < this.capacity) {
|
4198 | this._points.push(point);
|
4199 | return true;
|
4200 | }
|
4201 | if (!this._divided) {
|
4202 | this.subdivide();
|
4203 | }
|
4204 | return (_e = ((_a = this._NE) === null || _a === void 0 ? void 0 : _a.insert(point)) || ((_b = this._NW) === null || _b === void 0 ? void 0 : _b.insert(point)) || ((_c = this._SE) === null || _c === void 0 ? void 0 : _c.insert(point)) || ((_d = this._SW) === null || _d === void 0 ? void 0 : _d.insert(point))) !== null && _e !== void 0 ? _e : false;
|
4205 | }
|
4206 | query(range, check, found) {
|
4207 | var _a, _b, _c, _d;
|
4208 | const res = found !== null && found !== void 0 ? found : [];
|
4209 | if (!range.intersects(this.rectangle)) {
|
4210 | return [];
|
4211 | }
|
4212 | for (const p of this._points) {
|
4213 | if (!range.contains(p.position) && getDistance(range.position, p.position) > p.particle.getRadius() && (!check || check(p.particle))) {
|
4214 | continue;
|
4215 | }
|
4216 | res.push(p.particle);
|
4217 | }
|
4218 | if (this._divided) {
|
4219 | (_a = this._NE) === null || _a === void 0 ? void 0 : _a.query(range, check, res);
|
4220 | (_b = this._NW) === null || _b === void 0 ? void 0 : _b.query(range, check, res);
|
4221 | (_c = this._SE) === null || _c === void 0 ? void 0 : _c.query(range, check, res);
|
4222 | (_d = this._SW) === null || _d === void 0 ? void 0 : _d.query(range, check, res);
|
4223 | }
|
4224 | return res;
|
4225 | }
|
4226 | queryCircle(position, radius, check) {
|
4227 | return this.query(new Circle(position.x, position.y, radius), check);
|
4228 | }
|
4229 | queryRectangle(position, size, check) {
|
4230 | return this.query(new Rectangle(position.x, position.y, size.width, size.height), check);
|
4231 | }
|
4232 | subdivide() {
|
4233 | const x = this.rectangle.position.x,
|
4234 | y = this.rectangle.position.y,
|
4235 | w = this.rectangle.size.width,
|
4236 | h = this.rectangle.size.height,
|
4237 | capacity = this.capacity;
|
4238 | this._NE = new QuadTree(new Rectangle(x, y, w / 2, h / 2), capacity);
|
4239 | this._NW = new QuadTree(new Rectangle(x + w / 2, y, w / 2, h / 2), capacity);
|
4240 | this._SE = new QuadTree(new Rectangle(x, y + h / 2, w / 2, h / 2), capacity);
|
4241 | this._SW = new QuadTree(new Rectangle(x + w / 2, y + h / 2, w / 2, h / 2), capacity);
|
4242 | this._divided = true;
|
4243 | }
|
4244 | }
|
4245 | ;
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 | class Particles {
|
4253 | constructor(engine, container) {
|
4254 | this.container = container;
|
4255 | this._engine = engine;
|
4256 | this.nextId = 0;
|
4257 | this.array = [];
|
4258 | this.zArray = [];
|
4259 | this.pool = [];
|
4260 | this.limit = 0;
|
4261 | this.needsSort = false;
|
4262 | this.lastZIndex = 0;
|
4263 | this.interactionManager = new InteractionManager(this._engine, container);
|
4264 | const canvasSize = this.container.canvas.size;
|
4265 | this.quadTree = new QuadTree(new Rectangle(-canvasSize.width / 4, -canvasSize.height / 4, canvasSize.width * 3 / 2, canvasSize.height * 3 / 2), 4);
|
4266 | this.movers = this._engine.plugins.getMovers(container, true);
|
4267 | this.updaters = this._engine.plugins.getUpdaters(container, true);
|
4268 | }
|
4269 | get count() {
|
4270 | return this.array.length;
|
4271 | }
|
4272 | addManualParticles() {
|
4273 | const container = this.container,
|
4274 | options = container.actualOptions;
|
4275 | for (const particle of options.manualParticles) {
|
4276 | this.addParticle(calcPositionFromSize({
|
4277 | size: container.canvas.size,
|
4278 | position: particle.position
|
4279 | }), particle.options);
|
4280 | }
|
4281 | }
|
4282 | addParticle(position, overrideOptions, group, initializer) {
|
4283 | const container = this.container,
|
4284 | options = container.actualOptions,
|
4285 | limit = options.particles.number.limit;
|
4286 | if (limit > 0) {
|
4287 | const countToRemove = this.count + 1 - limit;
|
4288 | if (countToRemove > 0) {
|
4289 | this.removeQuantity(countToRemove);
|
4290 | }
|
4291 | }
|
4292 | return this._pushParticle(position, overrideOptions, group, initializer);
|
4293 | }
|
4294 | clear() {
|
4295 | this.array = [];
|
4296 | this.zArray = [];
|
4297 | }
|
4298 | destroy() {
|
4299 | this.array = [];
|
4300 | this.zArray = [];
|
4301 | this.movers = [];
|
4302 | this.updaters = [];
|
4303 | }
|
4304 | async draw(delta) {
|
4305 | const container = this.container,
|
4306 | canvasSize = this.container.canvas.size;
|
4307 | this.quadTree = new QuadTree(new Rectangle(-canvasSize.width / 4, -canvasSize.height / 4, canvasSize.width * 3 / 2, canvasSize.height * 3 / 2), 4);
|
4308 | container.canvas.clear();
|
4309 | await this.update(delta);
|
4310 | if (this.needsSort) {
|
4311 | this.zArray.sort((a, b) => b.position.z - a.position.z || a.id - b.id);
|
4312 | this.lastZIndex = this.zArray[this.zArray.length - 1].position.z;
|
4313 | this.needsSort = false;
|
4314 | }
|
4315 | for (const [, plugin] of container.plugins) {
|
4316 | container.canvas.drawPlugin(plugin, delta);
|
4317 | }
|
4318 | for (const p of this.zArray) {
|
4319 | p.draw(delta);
|
4320 | }
|
4321 | }
|
4322 | handleClickMode(mode) {
|
4323 | this.interactionManager.handleClickMode(mode);
|
4324 | }
|
4325 | init() {
|
4326 | var _a;
|
4327 | const container = this.container,
|
4328 | options = container.actualOptions;
|
4329 | this.lastZIndex = 0;
|
4330 | this.needsSort = false;
|
4331 | let handled = false;
|
4332 | this.updaters = this._engine.plugins.getUpdaters(container, true);
|
4333 | this.interactionManager.init();
|
4334 | for (const [, plugin] of container.plugins) {
|
4335 | if (plugin.particlesInitialization !== undefined) {
|
4336 | handled = plugin.particlesInitialization();
|
4337 | }
|
4338 | if (handled) {
|
4339 | break;
|
4340 | }
|
4341 | }
|
4342 | this.interactionManager.init();
|
4343 | for (const [, pathGenerator] of container.pathGenerators) {
|
4344 | pathGenerator.init(container);
|
4345 | }
|
4346 | this.addManualParticles();
|
4347 | if (!handled) {
|
4348 | for (const group in options.particles.groups) {
|
4349 | const groupOptions = options.particles.groups[group];
|
4350 | for (let i = this.count, j = 0; j < ((_a = groupOptions.number) === null || _a === void 0 ? void 0 : _a.value) && i < options.particles.number.value; i++, j++) {
|
4351 | this.addParticle(undefined, groupOptions, group);
|
4352 | }
|
4353 | }
|
4354 | for (let i = this.count; i < options.particles.number.value; i++) {
|
4355 | this.addParticle();
|
4356 | }
|
4357 | }
|
4358 | }
|
4359 | push(nb, mouse, overrideOptions, group) {
|
4360 | this.pushing = true;
|
4361 | for (let i = 0; i < nb; i++) {
|
4362 | this.addParticle(mouse === null || mouse === void 0 ? void 0 : mouse.position, overrideOptions, group);
|
4363 | }
|
4364 | this.pushing = false;
|
4365 | }
|
4366 | async redraw() {
|
4367 | this.clear();
|
4368 | this.init();
|
4369 | await this.draw({
|
4370 | value: 0,
|
4371 | factor: 0
|
4372 | });
|
4373 | }
|
4374 | remove(particle, group, override) {
|
4375 | this.removeAt(this.array.indexOf(particle), undefined, group, override);
|
4376 | }
|
4377 | removeAt(index, quantity = 1, group, override) {
|
4378 | if (index < 0 || index > this.count) {
|
4379 | return;
|
4380 | }
|
4381 | let deleted = 0;
|
4382 | for (let i = index; deleted < quantity && i < this.count; i++) {
|
4383 | const particle = this.array[i];
|
4384 | if (!particle || particle.group !== group) {
|
4385 | continue;
|
4386 | }
|
4387 | particle.destroy(override);
|
4388 | this.array.splice(i--, 1);
|
4389 | const zIdx = this.zArray.indexOf(particle);
|
4390 | this.zArray.splice(zIdx, 1);
|
4391 | this.pool.push(particle);
|
4392 | deleted++;
|
4393 | this._engine.dispatchEvent("particleRemoved", {
|
4394 | container: this.container,
|
4395 | data: {
|
4396 | particle
|
4397 | }
|
4398 | });
|
4399 | }
|
4400 | }
|
4401 | removeQuantity(quantity, group) {
|
4402 | this.removeAt(0, quantity, group);
|
4403 | }
|
4404 | setDensity() {
|
4405 | const options = this.container.actualOptions;
|
4406 | for (const group in options.particles.groups) {
|
4407 | this._applyDensity(options.particles.groups[group], 0, group);
|
4408 | }
|
4409 | this._applyDensity(options.particles, options.manualParticles.length);
|
4410 | }
|
4411 | async update(delta) {
|
4412 | var _a, _b;
|
4413 | const container = this.container,
|
4414 | particlesToDelete = [];
|
4415 | for (const [, pathGenerator] of container.pathGenerators) {
|
4416 | pathGenerator.update();
|
4417 | }
|
4418 | for (const [, plugin] of container.plugins) {
|
4419 | (_a = plugin.update) === null || _a === void 0 ? void 0 : _a.call(plugin, delta);
|
4420 | }
|
4421 | for (const particle of this.array) {
|
4422 | const resizeFactor = container.canvas.resizeFactor;
|
4423 | if (resizeFactor && !particle.ignoresResizeRatio) {
|
4424 | particle.position.x *= resizeFactor.width;
|
4425 | particle.position.y *= resizeFactor.height;
|
4426 | particle.initialPosition.x *= resizeFactor.width;
|
4427 | particle.initialPosition.y *= resizeFactor.height;
|
4428 | }
|
4429 | particle.ignoresResizeRatio = false;
|
4430 | await this.interactionManager.reset(particle);
|
4431 | for (const [, plugin] of this.container.plugins) {
|
4432 | if (particle.destroyed) {
|
4433 | break;
|
4434 | }
|
4435 | (_b = plugin.particleUpdate) === null || _b === void 0 ? void 0 : _b.call(plugin, particle, delta);
|
4436 | }
|
4437 | for (const mover of this.movers) {
|
4438 | if (mover.isEnabled(particle)) {
|
4439 | mover.move(particle, delta);
|
4440 | }
|
4441 | }
|
4442 | if (particle.destroyed) {
|
4443 | particlesToDelete.push(particle);
|
4444 | continue;
|
4445 | }
|
4446 | this.quadTree.insert(new Point(particle.getPosition(), particle));
|
4447 | }
|
4448 | for (const particle of particlesToDelete) {
|
4449 | this.remove(particle);
|
4450 | }
|
4451 | await this.interactionManager.externalInteract(delta);
|
4452 | for (const particle of this.array) {
|
4453 | for (const updater of this.updaters) {
|
4454 | updater.update(particle, delta);
|
4455 | }
|
4456 | if (!particle.destroyed && !particle.spawning) {
|
4457 | await this.interactionManager.particlesInteract(particle, delta);
|
4458 | }
|
4459 | }
|
4460 | delete container.canvas.resizeFactor;
|
4461 | }
|
4462 | _applyDensity(options, manualCount, group) {
|
4463 | var _a;
|
4464 | if (!((_a = options.number.density) === null || _a === void 0 ? void 0 : _a.enable)) {
|
4465 | return;
|
4466 | }
|
4467 | const numberOptions = options.number,
|
4468 | densityFactor = this._initDensityFactor(numberOptions.density),
|
4469 | optParticlesNumber = numberOptions.value,
|
4470 | optParticlesLimit = numberOptions.limit > 0 ? numberOptions.limit : optParticlesNumber,
|
4471 | particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor + manualCount,
|
4472 | particlesCount = Math.min(this.count, this.array.filter(t => t.group === group).length);
|
4473 | this.limit = numberOptions.limit * densityFactor;
|
4474 | if (particlesCount < particlesNumber) {
|
4475 | this.push(Math.abs(particlesNumber - particlesCount), undefined, options, group);
|
4476 | } else if (particlesCount > particlesNumber) {
|
4477 | this.removeQuantity(particlesCount - particlesNumber, group);
|
4478 | }
|
4479 | }
|
4480 | _initDensityFactor(densityOptions) {
|
4481 | const container = this.container;
|
4482 | if (!container.canvas.element || !densityOptions.enable) {
|
4483 | return 1;
|
4484 | }
|
4485 | const canvas = container.canvas.element,
|
4486 | pxRatio = container.retina.pixelRatio;
|
4487 | return canvas.width * canvas.height / (densityOptions.factor * pxRatio ** 2 * densityOptions.area);
|
4488 | }
|
4489 | _pushParticle(position, overrideOptions, group, initializer) {
|
4490 | try {
|
4491 | let particle = this.pool.pop();
|
4492 | if (particle) {
|
4493 | particle.init(this.nextId, position, overrideOptions, group);
|
4494 | } else {
|
4495 | particle = new Particle(this._engine, this.nextId, this.container, position, overrideOptions, group);
|
4496 | }
|
4497 | let canAdd = true;
|
4498 | if (initializer) {
|
4499 | canAdd = initializer(particle);
|
4500 | }
|
4501 | if (!canAdd) {
|
4502 | return;
|
4503 | }
|
4504 | this.array.push(particle);
|
4505 | this.zArray.push(particle);
|
4506 | this.nextId++;
|
4507 | this._engine.dispatchEvent("particleAdded", {
|
4508 | container: this.container,
|
4509 | data: {
|
4510 | particle
|
4511 | }
|
4512 | });
|
4513 | return particle;
|
4514 | } catch (e) {
|
4515 | console.warn(`error adding particle: ${e}`);
|
4516 | return;
|
4517 | }
|
4518 | }
|
4519 | }
|
4520 | ;
|
4521 |
|
4522 |
|
4523 | class Retina {
|
4524 | constructor(container) {
|
4525 | this.container = container;
|
4526 | }
|
4527 | init() {
|
4528 | const container = this.container,
|
4529 | options = container.actualOptions;
|
4530 | this.pixelRatio = !options.detectRetina || isSsr() ? 1 : window.devicePixelRatio;
|
4531 | this.reduceFactor = 1;
|
4532 | const ratio = this.pixelRatio;
|
4533 | if (container.canvas.element) {
|
4534 | const element = container.canvas.element;
|
4535 | container.canvas.size.width = element.offsetWidth * ratio;
|
4536 | container.canvas.size.height = element.offsetHeight * ratio;
|
4537 | }
|
4538 | const particles = options.particles;
|
4539 | this.attractDistance = getRangeValue(particles.move.attract.distance) * ratio;
|
4540 | this.sizeAnimationSpeed = getRangeValue(particles.size.animation.speed) * ratio;
|
4541 | this.maxSpeed = getRangeValue(particles.move.gravity.maxSpeed) * ratio;
|
4542 | }
|
4543 | initParticle(particle) {
|
4544 | const options = particle.options,
|
4545 | ratio = this.pixelRatio,
|
4546 | moveDistance = options.move.distance,
|
4547 | props = particle.retina;
|
4548 | props.attractDistance = getRangeValue(options.move.attract.distance) * ratio;
|
4549 | props.moveDrift = getRangeValue(options.move.drift) * ratio;
|
4550 | props.moveSpeed = getRangeValue(options.move.speed) * ratio;
|
4551 | props.sizeAnimationSpeed = getRangeValue(options.size.animation.speed) * ratio;
|
4552 | const maxDistance = props.maxDistance;
|
4553 | maxDistance.horizontal = moveDistance.horizontal !== undefined ? moveDistance.horizontal * ratio : undefined;
|
4554 | maxDistance.vertical = moveDistance.vertical !== undefined ? moveDistance.vertical * ratio : undefined;
|
4555 | props.maxSpeed = getRangeValue(options.move.gravity.maxSpeed) * ratio;
|
4556 | }
|
4557 | }
|
4558 | ;
|
4559 |
|
4560 |
|
4561 |
|
4562 |
|
4563 |
|
4564 |
|
4565 |
|
4566 |
|
4567 |
|
4568 | function guardCheck(container) {
|
4569 | return container && !container.destroyed;
|
4570 | }
|
4571 | function loadContainerOptions(engine, container, ...sourceOptionsArr) {
|
4572 | const options = new Options(engine, container);
|
4573 | loadOptions(options, ...sourceOptionsArr);
|
4574 | return options;
|
4575 | }
|
4576 | const defaultPathGeneratorKey = "default",
|
4577 | defaultPathGenerator = {
|
4578 | generate: p => {
|
4579 | const v = p.velocity.copy();
|
4580 | v.angle += v.length * Math.PI / 180;
|
4581 | return v;
|
4582 | },
|
4583 | init: () => {},
|
4584 | update: () => {},
|
4585 | reset: () => {}
|
4586 | };
|
4587 | class Container {
|
4588 | constructor(engine, id, sourceOptions) {
|
4589 | this.id = id;
|
4590 | this._engine = engine;
|
4591 | this.fpsLimit = 120;
|
4592 | this.smooth = false;
|
4593 | this._delay = 0;
|
4594 | this.duration = 0;
|
4595 | this.lifeTime = 0;
|
4596 | this._firstStart = true;
|
4597 | this.started = false;
|
4598 | this.destroyed = false;
|
4599 | this._paused = true;
|
4600 | this.lastFrameTime = 0;
|
4601 | this.zLayers = 100;
|
4602 | this.pageHidden = false;
|
4603 | this._sourceOptions = sourceOptions;
|
4604 | this._initialSourceOptions = sourceOptions;
|
4605 | this.retina = new Retina(this);
|
4606 | this.canvas = new Canvas(this);
|
4607 | this.particles = new Particles(this._engine, this);
|
4608 | this.frameManager = new FrameManager(this);
|
4609 | this.pathGenerators = new Map();
|
4610 | this.interactivity = {
|
4611 | mouse: {
|
4612 | clicking: false,
|
4613 | inside: false
|
4614 | }
|
4615 | };
|
4616 | this.plugins = new Map();
|
4617 | this.drawers = new Map();
|
4618 | this._options = loadContainerOptions(this._engine, this);
|
4619 | this.actualOptions = loadContainerOptions(this._engine, this);
|
4620 | this._eventListeners = new EventListeners(this);
|
4621 | if (typeof IntersectionObserver !== "undefined" && IntersectionObserver) {
|
4622 | this._intersectionObserver = new IntersectionObserver(entries => this._intersectionManager(entries));
|
4623 | }
|
4624 | this._engine.dispatchEvent("containerBuilt", {
|
4625 | container: this
|
4626 | });
|
4627 | }
|
4628 | get options() {
|
4629 | return this._options;
|
4630 | }
|
4631 | get sourceOptions() {
|
4632 | return this._sourceOptions;
|
4633 | }
|
4634 | addClickHandler(callback) {
|
4635 | if (!guardCheck(this)) {
|
4636 | return;
|
4637 | }
|
4638 | const el = this.interactivity.element;
|
4639 | if (!el) {
|
4640 | return;
|
4641 | }
|
4642 | const clickOrTouchHandler = (e, pos, radius) => {
|
4643 | if (!guardCheck(this)) {
|
4644 | return;
|
4645 | }
|
4646 | const pxRatio = this.retina.pixelRatio,
|
4647 | posRetina = {
|
4648 | x: pos.x * pxRatio,
|
4649 | y: pos.y * pxRatio
|
4650 | },
|
4651 | particles = this.particles.quadTree.queryCircle(posRetina, radius * pxRatio);
|
4652 | callback(e, particles);
|
4653 | };
|
4654 | const clickHandler = e => {
|
4655 | if (!guardCheck(this)) {
|
4656 | return;
|
4657 | }
|
4658 | const mouseEvent = e,
|
4659 | pos = {
|
4660 | x: mouseEvent.offsetX || mouseEvent.clientX,
|
4661 | y: mouseEvent.offsetY || mouseEvent.clientY
|
4662 | };
|
4663 | clickOrTouchHandler(e, pos, 1);
|
4664 | };
|
4665 | const touchStartHandler = () => {
|
4666 | if (!guardCheck(this)) {
|
4667 | return;
|
4668 | }
|
4669 | touched = true;
|
4670 | touchMoved = false;
|
4671 | };
|
4672 | const touchMoveHandler = () => {
|
4673 | if (!guardCheck(this)) {
|
4674 | return;
|
4675 | }
|
4676 | touchMoved = true;
|
4677 | };
|
4678 | const touchEndHandler = e => {
|
4679 | if (!guardCheck(this)) {
|
4680 | return;
|
4681 | }
|
4682 | if (touched && !touchMoved) {
|
4683 | const touchEvent = e;
|
4684 | let lastTouch = touchEvent.touches[touchEvent.touches.length - 1];
|
4685 | if (!lastTouch) {
|
4686 | lastTouch = touchEvent.changedTouches[touchEvent.changedTouches.length - 1];
|
4687 | if (!lastTouch) {
|
4688 | return;
|
4689 | }
|
4690 | }
|
4691 | const element = this.canvas.element,
|
4692 | canvasRect = element ? element.getBoundingClientRect() : undefined,
|
4693 | pos = {
|
4694 | x: lastTouch.clientX - (canvasRect ? canvasRect.left : 0),
|
4695 | y: lastTouch.clientY - (canvasRect ? canvasRect.top : 0)
|
4696 | };
|
4697 | clickOrTouchHandler(e, pos, Math.max(lastTouch.radiusX, lastTouch.radiusY));
|
4698 | }
|
4699 | touched = false;
|
4700 | touchMoved = false;
|
4701 | };
|
4702 | const touchCancelHandler = () => {
|
4703 | if (!guardCheck(this)) {
|
4704 | return;
|
4705 | }
|
4706 | touched = false;
|
4707 | touchMoved = false;
|
4708 | };
|
4709 | let touched = false,
|
4710 | touchMoved = false;
|
4711 | el.addEventListener("click", clickHandler);
|
4712 | el.addEventListener("touchstart", touchStartHandler);
|
4713 | el.addEventListener("touchmove", touchMoveHandler);
|
4714 | el.addEventListener("touchend", touchEndHandler);
|
4715 | el.addEventListener("touchcancel", touchCancelHandler);
|
4716 | }
|
4717 | addPath(key, generator, override = false) {
|
4718 | if (!guardCheck(this) || !override && this.pathGenerators.has(key)) {
|
4719 | return false;
|
4720 | }
|
4721 | this.pathGenerators.set(key, generator !== null && generator !== void 0 ? generator : defaultPathGenerator);
|
4722 | return true;
|
4723 | }
|
4724 | destroy() {
|
4725 | if (!guardCheck(this)) {
|
4726 | return;
|
4727 | }
|
4728 | this.stop();
|
4729 | this.particles.destroy();
|
4730 | this.canvas.destroy();
|
4731 | for (const [, drawer] of this.drawers) {
|
4732 | if (drawer.destroy) {
|
4733 | drawer.destroy(this);
|
4734 | }
|
4735 | }
|
4736 | for (const key of this.drawers.keys()) {
|
4737 | this.drawers.delete(key);
|
4738 | }
|
4739 | this._engine.plugins.destroy(this);
|
4740 | this.destroyed = true;
|
4741 | const mainArr = this._engine.dom(),
|
4742 | idx = mainArr.findIndex(t => t === this);
|
4743 | if (idx >= 0) {
|
4744 | mainArr.splice(idx, 1);
|
4745 | }
|
4746 | this._engine.dispatchEvent("containerDestroyed", {
|
4747 | container: this
|
4748 | });
|
4749 | }
|
4750 | draw(force) {
|
4751 | if (!guardCheck(this)) {
|
4752 | return;
|
4753 | }
|
4754 | let refreshTime = force;
|
4755 | this._drawAnimationFrame = animate()(async timestamp => {
|
4756 | if (refreshTime) {
|
4757 | this.lastFrameTime = undefined;
|
4758 | refreshTime = false;
|
4759 | }
|
4760 | await this.frameManager.nextFrame(timestamp);
|
4761 | });
|
4762 | }
|
4763 | exportConfiguration() {
|
4764 | return JSON.stringify(this.actualOptions, (key, value) => {
|
4765 | if (key === "_engine" || key === "_container") {
|
4766 | return;
|
4767 | }
|
4768 | return value;
|
4769 | }, 2);
|
4770 | }
|
4771 | exportImage(callback, type, quality) {
|
4772 | const element = this.canvas.element;
|
4773 | if (element) {
|
4774 | element.toBlob(callback, type !== null && type !== void 0 ? type : "image/png", quality);
|
4775 | }
|
4776 | }
|
4777 | exportImg(callback) {
|
4778 | this.exportImage(callback);
|
4779 | }
|
4780 | getAnimationStatus() {
|
4781 | return !this._paused && !this.pageHidden && guardCheck(this);
|
4782 | }
|
4783 | handleClickMode(mode) {
|
4784 | if (!guardCheck(this)) {
|
4785 | return;
|
4786 | }
|
4787 | this.particles.handleClickMode(mode);
|
4788 | for (const [, plugin] of this.plugins) {
|
4789 | if (plugin.handleClickMode) {
|
4790 | plugin.handleClickMode(mode);
|
4791 | }
|
4792 | }
|
4793 | }
|
4794 | async init() {
|
4795 | if (!guardCheck(this)) {
|
4796 | return;
|
4797 | }
|
4798 | const shapes = this._engine.plugins.getSupportedShapes();
|
4799 | for (const type of shapes) {
|
4800 | const drawer = this._engine.plugins.getShapeDrawer(type);
|
4801 | if (drawer) {
|
4802 | this.drawers.set(type, drawer);
|
4803 | }
|
4804 | }
|
4805 | this._options = loadContainerOptions(this._engine, this, this._initialSourceOptions, this.sourceOptions);
|
4806 | this.actualOptions = loadContainerOptions(this._engine, this, this._options);
|
4807 | const availablePlugins = this._engine.plugins.getAvailablePlugins(this);
|
4808 | for (const [id, plugin] of availablePlugins) {
|
4809 | this.plugins.set(id, plugin);
|
4810 | }
|
4811 | this.retina.init();
|
4812 | await this.canvas.init();
|
4813 | this.updateActualOptions();
|
4814 | this.canvas.initBackground();
|
4815 | this.canvas.resize();
|
4816 | this.zLayers = this.actualOptions.zLayers;
|
4817 | this.duration = getRangeValue(this.actualOptions.duration) * 1000;
|
4818 | this._delay = getRangeValue(this.actualOptions.delay) * 1000;
|
4819 | this.lifeTime = 0;
|
4820 | this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 120;
|
4821 | this.smooth = this.actualOptions.smooth;
|
4822 | for (const [, drawer] of this.drawers) {
|
4823 | if (drawer.init) {
|
4824 | await drawer.init(this);
|
4825 | }
|
4826 | }
|
4827 | for (const [, plugin] of this.plugins) {
|
4828 | if (plugin.init) {
|
4829 | await plugin.init();
|
4830 | }
|
4831 | }
|
4832 | this._engine.dispatchEvent("containerInit", {
|
4833 | container: this
|
4834 | });
|
4835 | this.particles.init();
|
4836 | this.particles.setDensity();
|
4837 | for (const [, plugin] of this.plugins) {
|
4838 | if (plugin.particlesSetup) {
|
4839 | plugin.particlesSetup();
|
4840 | }
|
4841 | }
|
4842 | this._engine.dispatchEvent("particlesSetup", {
|
4843 | container: this
|
4844 | });
|
4845 | }
|
4846 | async loadTheme(name) {
|
4847 | if (!guardCheck(this)) {
|
4848 | return;
|
4849 | }
|
4850 | this._currentTheme = name;
|
4851 | await this.refresh();
|
4852 | }
|
4853 | pause() {
|
4854 | if (!guardCheck(this)) {
|
4855 | return;
|
4856 | }
|
4857 | if (this._drawAnimationFrame !== undefined) {
|
4858 | cancelAnimation()(this._drawAnimationFrame);
|
4859 | delete this._drawAnimationFrame;
|
4860 | }
|
4861 | if (this._paused) {
|
4862 | return;
|
4863 | }
|
4864 | for (const [, plugin] of this.plugins) {
|
4865 | if (plugin.pause) {
|
4866 | plugin.pause();
|
4867 | }
|
4868 | }
|
4869 | if (!this.pageHidden) {
|
4870 | this._paused = true;
|
4871 | }
|
4872 | this._engine.dispatchEvent("containerPaused", {
|
4873 | container: this
|
4874 | });
|
4875 | }
|
4876 | play(force) {
|
4877 | if (!guardCheck(this)) {
|
4878 | return;
|
4879 | }
|
4880 | const needsUpdate = this._paused || force;
|
4881 | if (this._firstStart && !this.actualOptions.autoPlay) {
|
4882 | this._firstStart = false;
|
4883 | return;
|
4884 | }
|
4885 | if (this._paused) {
|
4886 | this._paused = false;
|
4887 | }
|
4888 | if (needsUpdate) {
|
4889 | for (const [, plugin] of this.plugins) {
|
4890 | if (plugin.play) {
|
4891 | plugin.play();
|
4892 | }
|
4893 | }
|
4894 | }
|
4895 | this._engine.dispatchEvent("containerPlay", {
|
4896 | container: this
|
4897 | });
|
4898 | this.draw(needsUpdate || false);
|
4899 | }
|
4900 | async refresh() {
|
4901 | if (!guardCheck(this)) {
|
4902 | return;
|
4903 | }
|
4904 | this.stop();
|
4905 | return this.start();
|
4906 | }
|
4907 | async reset() {
|
4908 | if (!guardCheck(this)) {
|
4909 | return;
|
4910 | }
|
4911 | this._options = loadContainerOptions(this._engine, this);
|
4912 | return this.refresh();
|
4913 | }
|
4914 | setNoise(noiseOrGenerator, init, update) {
|
4915 | if (!guardCheck(this)) {
|
4916 | return;
|
4917 | }
|
4918 | this.setPath(noiseOrGenerator, init, update);
|
4919 | }
|
4920 | setPath(pathOrGenerator, init, update) {
|
4921 | if (!pathOrGenerator || !guardCheck(this)) {
|
4922 | return;
|
4923 | }
|
4924 | const pathGenerator = Object.assign({}, defaultPathGenerator);
|
4925 | if (typeof pathOrGenerator === "function") {
|
4926 | pathGenerator.generate = pathOrGenerator;
|
4927 | if (init) {
|
4928 | pathGenerator.init = init;
|
4929 | }
|
4930 | if (update) {
|
4931 | pathGenerator.update = update;
|
4932 | }
|
4933 | } else {
|
4934 | const oldGenerator = pathGenerator;
|
4935 | pathGenerator.generate = pathOrGenerator.generate || oldGenerator.generate;
|
4936 | pathGenerator.init = pathOrGenerator.init || oldGenerator.init;
|
4937 | pathGenerator.update = pathOrGenerator.update || oldGenerator.update;
|
4938 | }
|
4939 | this.addPath(defaultPathGeneratorKey, pathGenerator, true);
|
4940 | }
|
4941 | async start() {
|
4942 | if (!guardCheck(this) || this.started) {
|
4943 | return;
|
4944 | }
|
4945 | await this.init();
|
4946 | this.started = true;
|
4947 | await new Promise(resolve => {
|
4948 | this._delayTimeout = setTimeout(async () => {
|
4949 | this._eventListeners.addListeners();
|
4950 | if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
4951 | this._intersectionObserver.observe(this.interactivity.element);
|
4952 | }
|
4953 | for (const [, plugin] of this.plugins) {
|
4954 | if (plugin.start) {
|
4955 | await plugin.start();
|
4956 | }
|
4957 | }
|
4958 | this._engine.dispatchEvent("containerStarted", {
|
4959 | container: this
|
4960 | });
|
4961 | this.play();
|
4962 | resolve();
|
4963 | }, this._delay);
|
4964 | });
|
4965 | }
|
4966 | stop() {
|
4967 | if (!guardCheck(this) || !this.started) {
|
4968 | return;
|
4969 | }
|
4970 | if (this._delayTimeout) {
|
4971 | clearTimeout(this._delayTimeout);
|
4972 | delete this._delayTimeout;
|
4973 | }
|
4974 | this._firstStart = true;
|
4975 | this.started = false;
|
4976 | this._eventListeners.removeListeners();
|
4977 | this.pause();
|
4978 | this.particles.clear();
|
4979 | this.canvas.clear();
|
4980 | if (this.interactivity.element instanceof HTMLElement && this._intersectionObserver) {
|
4981 | this._intersectionObserver.unobserve(this.interactivity.element);
|
4982 | }
|
4983 | for (const [, plugin] of this.plugins) {
|
4984 | if (plugin.stop) {
|
4985 | plugin.stop();
|
4986 | }
|
4987 | }
|
4988 | for (const key of this.plugins.keys()) {
|
4989 | this.plugins.delete(key);
|
4990 | }
|
4991 | this._sourceOptions = this._options;
|
4992 | this._engine.dispatchEvent("containerStopped", {
|
4993 | container: this
|
4994 | });
|
4995 | }
|
4996 | updateActualOptions() {
|
4997 | this.actualOptions.responsive = [];
|
4998 | const newMaxWidth = this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
|
4999 | this.actualOptions.setTheme(this._currentTheme);
|
5000 | if (this.responsiveMaxWidth === newMaxWidth) {
|
5001 | return false;
|
5002 | }
|
5003 | this.responsiveMaxWidth = newMaxWidth;
|
5004 | return true;
|
5005 | }
|
5006 | _intersectionManager(entries) {
|
5007 | if (!guardCheck(this) || !this.actualOptions.pauseOnOutsideViewport) {
|
5008 | return;
|
5009 | }
|
5010 | for (const entry of entries) {
|
5011 | if (entry.target !== this.interactivity.element) {
|
5012 | continue;
|
5013 | }
|
5014 | (entry.isIntersecting ? this.play : this.pause)();
|
5015 | }
|
5016 | }
|
5017 | }
|
5018 | ;
|
5019 |
|
5020 |
|
5021 |
|
5022 |
|
5023 | async function getDataFromUrl(jsonUrl, index) {
|
5024 | const url = itemFromSingleOrMultiple(jsonUrl, index);
|
5025 | if (!url) {
|
5026 | return;
|
5027 | }
|
5028 | const response = await fetch(url);
|
5029 | if (response.ok) {
|
5030 | return response.json();
|
5031 | }
|
5032 | console.error(`tsParticles - Error ${response.status} while retrieving config file`);
|
5033 | }
|
5034 | class Loader {
|
5035 | constructor(engine) {
|
5036 | this._engine = engine;
|
5037 | }
|
5038 | load(tagId, options, index) {
|
5039 | const params = {
|
5040 | index,
|
5041 | remote: false
|
5042 | };
|
5043 | if (typeof tagId === "string") {
|
5044 | params.tagId = tagId;
|
5045 | } else {
|
5046 | params.options = tagId;
|
5047 | }
|
5048 | if (typeof options === "number") {
|
5049 | params.index = options;
|
5050 | } else {
|
5051 | params.options = options !== null && options !== void 0 ? options : params.options;
|
5052 | }
|
5053 | return this.loadOptions(params);
|
5054 | }
|
5055 | async loadJSON(tagId, jsonUrl, index) {
|
5056 | let url, id;
|
5057 | if (typeof jsonUrl === "number" || jsonUrl === undefined) {
|
5058 | url = tagId;
|
5059 | } else {
|
5060 | id = tagId;
|
5061 | url = jsonUrl;
|
5062 | }
|
5063 | return this.loadRemoteOptions({
|
5064 | tagId: id,
|
5065 | url,
|
5066 | index,
|
5067 | remote: true
|
5068 | });
|
5069 | }
|
5070 | async loadOptions(params) {
|
5071 | var _a, _b, _c;
|
5072 | const tagId = (_a = params.tagId) !== null && _a !== void 0 ? _a : `tsparticles${Math.floor(getRandom() * 10000)}`,
|
5073 | {
|
5074 | index,
|
5075 | url: jsonUrl,
|
5076 | remote
|
5077 | } = params,
|
5078 | options = remote ? await getDataFromUrl(jsonUrl, index) : params.options;
|
5079 | let domContainer = (_b = params.element) !== null && _b !== void 0 ? _b : document.getElementById(tagId);
|
5080 | if (!domContainer) {
|
5081 | domContainer = document.createElement("div");
|
5082 | domContainer.id = tagId;
|
5083 | (_c = document.querySelector("body")) === null || _c === void 0 ? void 0 : _c.append(domContainer);
|
5084 | }
|
5085 | const currentOptions = itemFromSingleOrMultiple(options, index),
|
5086 | dom = this._engine.dom(),
|
5087 | oldIndex = dom.findIndex(v => v.id === tagId);
|
5088 | if (oldIndex >= 0) {
|
5089 | const old = this._engine.domItem(oldIndex);
|
5090 | if (old && !old.destroyed) {
|
5091 | old.destroy();
|
5092 | dom.splice(oldIndex, 1);
|
5093 | }
|
5094 | }
|
5095 | let canvasEl;
|
5096 | if (domContainer.tagName.toLowerCase() === "canvas") {
|
5097 | canvasEl = domContainer;
|
5098 | canvasEl.dataset[generatedAttribute] = "false";
|
5099 | } else {
|
5100 | const existingCanvases = domContainer.getElementsByTagName("canvas");
|
5101 | if (existingCanvases.length) {
|
5102 | canvasEl = existingCanvases[0];
|
5103 | canvasEl.dataset[generatedAttribute] = "false";
|
5104 | } else {
|
5105 | canvasEl = document.createElement("canvas");
|
5106 | canvasEl.dataset[generatedAttribute] = "true";
|
5107 | domContainer.appendChild(canvasEl);
|
5108 | }
|
5109 | }
|
5110 | if (!canvasEl.style.width) {
|
5111 | canvasEl.style.width = "100%";
|
5112 | }
|
5113 | if (!canvasEl.style.height) {
|
5114 | canvasEl.style.height = "100%";
|
5115 | }
|
5116 | const newItem = new Container(this._engine, tagId, currentOptions);
|
5117 | if (oldIndex >= 0) {
|
5118 | dom.splice(oldIndex, 0, newItem);
|
5119 | } else {
|
5120 | dom.push(newItem);
|
5121 | }
|
5122 | newItem.canvas.loadCanvas(canvasEl);
|
5123 | await newItem.start();
|
5124 | return newItem;
|
5125 | }
|
5126 | async loadRemoteOptions(params) {
|
5127 | return this.loadOptions(params);
|
5128 | }
|
5129 | async set(id, domContainer, options, index) {
|
5130 | const params = {
|
5131 | index,
|
5132 | remote: false
|
5133 | };
|
5134 | if (typeof id === "string") {
|
5135 | params.tagId = id;
|
5136 | } else {
|
5137 | params.element = id;
|
5138 | }
|
5139 | if (domContainer instanceof HTMLElement) {
|
5140 | params.element = domContainer;
|
5141 | } else {
|
5142 | params.options = domContainer;
|
5143 | }
|
5144 | if (typeof options === "number") {
|
5145 | params.index = options;
|
5146 | } else {
|
5147 | params.options = options !== null && options !== void 0 ? options : params.options;
|
5148 | }
|
5149 | return this.loadOptions(params);
|
5150 | }
|
5151 | async setJSON(id, domContainer, jsonUrl, index) {
|
5152 | let url, newId, newIndex, element;
|
5153 | if (id instanceof HTMLElement) {
|
5154 | element = id;
|
5155 | url = domContainer;
|
5156 | newIndex = jsonUrl;
|
5157 | } else {
|
5158 | newId = id;
|
5159 | element = domContainer;
|
5160 | url = jsonUrl;
|
5161 | newIndex = index;
|
5162 | }
|
5163 | return this.loadRemoteOptions({
|
5164 | tagId: newId,
|
5165 | url,
|
5166 | index: newIndex,
|
5167 | element,
|
5168 | remote: true
|
5169 | });
|
5170 | }
|
5171 | }
|
5172 | ;
|
5173 |
|
5174 | function getItemsFromInitializer(container, map, initializers, force = false) {
|
5175 | let res = map.get(container);
|
5176 | if (!res || force) {
|
5177 | res = [...initializers.values()].map(t => t(container));
|
5178 | map.set(container, res);
|
5179 | }
|
5180 | return res;
|
5181 | }
|
5182 | class Plugins {
|
5183 | constructor(engine) {
|
5184 | this._engine = engine;
|
5185 | this.plugins = [];
|
5186 | this._initializers = {
|
5187 | interactors: new Map(),
|
5188 | movers: new Map(),
|
5189 | updaters: new Map()
|
5190 | };
|
5191 | this.interactors = new Map();
|
5192 | this.movers = new Map();
|
5193 | this.updaters = new Map();
|
5194 | this.presets = new Map();
|
5195 | this.drawers = new Map();
|
5196 | this.pathGenerators = new Map();
|
5197 | }
|
5198 | addInteractor(name, initInteractor) {
|
5199 | this._initializers.interactors.set(name, initInteractor);
|
5200 | }
|
5201 | addParticleMover(name, initMover) {
|
5202 | this._initializers.movers.set(name, initMover);
|
5203 | }
|
5204 | addParticleUpdater(name, initUpdater) {
|
5205 | this._initializers.updaters.set(name, initUpdater);
|
5206 | }
|
5207 | addPathGenerator(type, pathGenerator) {
|
5208 | if (!this.getPathGenerator(type)) {
|
5209 | this.pathGenerators.set(type, pathGenerator);
|
5210 | }
|
5211 | }
|
5212 | addPlugin(plugin) {
|
5213 | if (!this.getPlugin(plugin.id)) {
|
5214 | this.plugins.push(plugin);
|
5215 | }
|
5216 | }
|
5217 | addPreset(presetKey, options, override = false) {
|
5218 | if (override || !this.getPreset(presetKey)) {
|
5219 | this.presets.set(presetKey, options);
|
5220 | }
|
5221 | }
|
5222 | addShapeDrawer(types, drawer) {
|
5223 | executeOnSingleOrMultiple(types, type => {
|
5224 | if (!this.getShapeDrawer(type)) {
|
5225 | this.drawers.set(type, drawer);
|
5226 | }
|
5227 | });
|
5228 | }
|
5229 | destroy(container) {
|
5230 | this.updaters.delete(container);
|
5231 | this.movers.delete(container);
|
5232 | this.interactors.delete(container);
|
5233 | }
|
5234 | getAvailablePlugins(container) {
|
5235 | const res = new Map();
|
5236 | for (const plugin of this.plugins) {
|
5237 | if (!plugin.needsPlugin(container.actualOptions)) {
|
5238 | continue;
|
5239 | }
|
5240 | res.set(plugin.id, plugin.getPlugin(container));
|
5241 | }
|
5242 | return res;
|
5243 | }
|
5244 | getInteractors(container, force = false) {
|
5245 | return getItemsFromInitializer(container, this.interactors, this._initializers.interactors, force);
|
5246 | }
|
5247 | getMovers(container, force = false) {
|
5248 | return getItemsFromInitializer(container, this.movers, this._initializers.movers, force);
|
5249 | }
|
5250 | getPathGenerator(type) {
|
5251 | return this.pathGenerators.get(type);
|
5252 | }
|
5253 | getPlugin(plugin) {
|
5254 | return this.plugins.find(t => t.id === plugin);
|
5255 | }
|
5256 | getPreset(preset) {
|
5257 | return this.presets.get(preset);
|
5258 | }
|
5259 | getShapeDrawer(type) {
|
5260 | return this.drawers.get(type);
|
5261 | }
|
5262 | getSupportedShapes() {
|
5263 | return this.drawers.keys();
|
5264 | }
|
5265 | getUpdaters(container, force = false) {
|
5266 | return getItemsFromInitializer(container, this.updaters, this._initializers.updaters, force);
|
5267 | }
|
5268 | loadOptions(options, sourceOptions) {
|
5269 | for (const plugin of this.plugins) {
|
5270 | plugin.loadOptions(options, sourceOptions);
|
5271 | }
|
5272 | }
|
5273 | loadParticlesOptions(container, options, ...sourceOptions) {
|
5274 | const updaters = this.updaters.get(container);
|
5275 | if (!updaters) {
|
5276 | return;
|
5277 | }
|
5278 | for (const updater of updaters) {
|
5279 | if (updater.loadOptions) {
|
5280 | updater.loadOptions(options, ...sourceOptions);
|
5281 | }
|
5282 | }
|
5283 | }
|
5284 | }
|
5285 | ;
|
5286 |
|
5287 |
|
5288 |
|
5289 | class Engine {
|
5290 | constructor() {
|
5291 | this._domArray = [];
|
5292 | this._eventDispatcher = new EventDispatcher();
|
5293 | this._initialized = false;
|
5294 | this._loader = new Loader(this);
|
5295 | this.plugins = new Plugins(this);
|
5296 | }
|
5297 | addEventListener(type, listener) {
|
5298 | this._eventDispatcher.addEventListener(type, listener);
|
5299 | }
|
5300 | async addInteractor(name, interactorInitializer) {
|
5301 | this.plugins.addInteractor(name, interactorInitializer);
|
5302 | await this.refresh();
|
5303 | }
|
5304 | async addMover(name, moverInitializer) {
|
5305 | this.plugins.addParticleMover(name, moverInitializer);
|
5306 | await this.refresh();
|
5307 | }
|
5308 | async addParticleUpdater(name, updaterInitializer) {
|
5309 | this.plugins.addParticleUpdater(name, updaterInitializer);
|
5310 | await this.refresh();
|
5311 | }
|
5312 | async addPathGenerator(name, generator) {
|
5313 | this.plugins.addPathGenerator(name, generator);
|
5314 | await this.refresh();
|
5315 | }
|
5316 | async addPlugin(plugin) {
|
5317 | this.plugins.addPlugin(plugin);
|
5318 | await this.refresh();
|
5319 | }
|
5320 | async addPreset(preset, options, override = false) {
|
5321 | this.plugins.addPreset(preset, options, override);
|
5322 | await this.refresh();
|
5323 | }
|
5324 | async addShape(shape, drawer, init, afterEffect, destroy) {
|
5325 | let customDrawer;
|
5326 | if (typeof drawer === "function") {
|
5327 | customDrawer = {
|
5328 | afterEffect: afterEffect,
|
5329 | destroy: destroy,
|
5330 | draw: drawer,
|
5331 | init: init
|
5332 | };
|
5333 | } else {
|
5334 | customDrawer = drawer;
|
5335 | }
|
5336 | this.plugins.addShapeDrawer(shape, customDrawer);
|
5337 | await this.refresh();
|
5338 | }
|
5339 | dispatchEvent(type, args) {
|
5340 | this._eventDispatcher.dispatchEvent(type, args);
|
5341 | }
|
5342 | dom() {
|
5343 | return this._domArray;
|
5344 | }
|
5345 | domItem(index) {
|
5346 | const dom = this.dom(),
|
5347 | item = dom[index];
|
5348 | if (item && !item.destroyed) {
|
5349 | return item;
|
5350 | }
|
5351 | dom.splice(index, 1);
|
5352 | }
|
5353 | init() {
|
5354 | if (!this._initialized) {
|
5355 | this._initialized = true;
|
5356 | }
|
5357 | }
|
5358 | async load(tagId, options) {
|
5359 | return this._loader.load(tagId, options);
|
5360 | }
|
5361 | async loadFromArray(tagId, options, index) {
|
5362 | return this._loader.load(tagId, options, index);
|
5363 | }
|
5364 | async loadJSON(tagId, pathConfigJson, index) {
|
5365 | return this._loader.loadJSON(tagId, pathConfigJson, index);
|
5366 | }
|
5367 | async refresh() {
|
5368 | for (const instance of this.dom()) {
|
5369 | await instance.refresh();
|
5370 | }
|
5371 | }
|
5372 | removeEventListener(type, listener) {
|
5373 | this._eventDispatcher.removeEventListener(type, listener);
|
5374 | }
|
5375 | async set(id, element, options) {
|
5376 | return this._loader.set(id, element, options);
|
5377 | }
|
5378 | async setJSON(id, element, pathConfigJson, index) {
|
5379 | return this._loader.setJSON(id, element, pathConfigJson, index);
|
5380 | }
|
5381 | setOnClickHandler(callback) {
|
5382 | const dom = this.dom();
|
5383 | if (!dom.length) {
|
5384 | throw new Error("Can only set click handlers after calling tsParticles.load() or tsParticles.loadJSON()");
|
5385 | }
|
5386 | for (const domItem of dom) {
|
5387 | domItem.addClickHandler(callback);
|
5388 | }
|
5389 | }
|
5390 | }
|
5391 | ;
|
5392 |
|
5393 |
|
5394 | class HslColorManager {
|
5395 | constructor() {
|
5396 | this.key = "hsl";
|
5397 | this.stringPrefix = "hsl";
|
5398 | }
|
5399 | handleColor(color) {
|
5400 | var _a;
|
5401 | const colorValue = color.value,
|
5402 | hslColor = (_a = colorValue.hsl) !== null && _a !== void 0 ? _a : color.value;
|
5403 | if (hslColor.h !== undefined && hslColor.s !== undefined && hslColor.l !== undefined) {
|
5404 | return hslToRgb(hslColor);
|
5405 | }
|
5406 | }
|
5407 | handleRangeColor(color) {
|
5408 | var _a;
|
5409 | const colorValue = color.value,
|
5410 | hslColor = (_a = colorValue.hsl) !== null && _a !== void 0 ? _a : color.value;
|
5411 | if (hslColor.h !== undefined && hslColor.l !== undefined) {
|
5412 | return hslToRgb({
|
5413 | h: getRangeValue(hslColor.h),
|
5414 | l: getRangeValue(hslColor.l),
|
5415 | s: getRangeValue(hslColor.s)
|
5416 | });
|
5417 | }
|
5418 | }
|
5419 | parseString(input) {
|
5420 | if (!input.startsWith("hsl")) {
|
5421 | return;
|
5422 | }
|
5423 | const regex = /hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.%]+)\s*)?\)/i,
|
5424 | result = regex.exec(input);
|
5425 | return result ? hslaToRgba({
|
5426 | a: result.length > 4 ? parseAlpha(result[5]) : 1,
|
5427 | h: parseInt(result[1], 10),
|
5428 | l: parseInt(result[3], 10),
|
5429 | s: parseInt(result[2], 10)
|
5430 | }) : undefined;
|
5431 | }
|
5432 | }
|
5433 | ;
|
5434 |
|
5435 | class RgbColorManager {
|
5436 | constructor() {
|
5437 | this.key = "rgb";
|
5438 | this.stringPrefix = "rgb";
|
5439 | }
|
5440 | handleColor(color) {
|
5441 | var _a;
|
5442 | const colorValue = color.value,
|
5443 | rgbColor = (_a = colorValue.rgb) !== null && _a !== void 0 ? _a : color.value;
|
5444 | if (rgbColor.r !== undefined) {
|
5445 | return rgbColor;
|
5446 | }
|
5447 | }
|
5448 | handleRangeColor(color) {
|
5449 | var _a;
|
5450 | const colorValue = color.value,
|
5451 | rgbColor = (_a = colorValue.rgb) !== null && _a !== void 0 ? _a : color.value;
|
5452 | if (rgbColor.r !== undefined) {
|
5453 | return {
|
5454 | r: getRangeValue(rgbColor.r),
|
5455 | g: getRangeValue(rgbColor.g),
|
5456 | b: getRangeValue(rgbColor.b)
|
5457 | };
|
5458 | }
|
5459 | }
|
5460 | parseString(input) {
|
5461 | if (!input.startsWith(this.stringPrefix)) {
|
5462 | return;
|
5463 | }
|
5464 | const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.%]+)\s*)?\)/i,
|
5465 | result = regex.exec(input);
|
5466 | return result ? {
|
5467 | a: result.length > 4 ? parseAlpha(result[5]) : 1,
|
5468 | b: parseInt(result[3], 10),
|
5469 | g: parseInt(result[2], 10),
|
5470 | r: parseInt(result[1], 10)
|
5471 | } : undefined;
|
5472 | }
|
5473 | }
|
5474 | ;
|
5475 | class ExternalInteractorBase {
|
5476 | constructor(container) {
|
5477 | this.container = container;
|
5478 | this.type = "external";
|
5479 | }
|
5480 | }
|
5481 | ;
|
5482 | class ParticlesInteractorBase {
|
5483 | constructor(container) {
|
5484 | this.container = container;
|
5485 | this.type = "particles";
|
5486 | }
|
5487 | }
|
5488 | ;
|
5489 |
|
5490 |
|
5491 |
|
5492 |
|
5493 | const rgbColorManager = new RgbColorManager(),
|
5494 | hslColorManager = new HslColorManager();
|
5495 | addColorManager(rgbColorManager);
|
5496 | addColorManager(hslColorManager);
|
5497 | const tsParticles = new Engine();
|
5498 | tsParticles.init();
|
5499 |
|
5500 |
|
5501 |
|
5502 |
|
5503 |
|
5504 |
|
5505 |
|
5506 |
|
5507 |
|
5508 |
|
5509 |
|
5510 |
|
5511 |
|
5512 |
|
5513 |
|
5514 |
|
5515 |
|
5516 |
|
5517 |
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 |
|
5524 |
|
5525 |
|
5526 |
|
5527 |
|
5528 |
|
5529 |
|
5530 |
|
5531 |
|
5532 |
|
5533 |
|
5534 |
|
5535 |
|
5536 |
|
5537 |
|
5538 |
|
5539 |
|
5540 |
|
5541 |
|
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 |
|
5550 |
|
5551 |
|
5552 |
|
5553 |
|
5554 |
|
5555 |
|
5556 |
|
5557 |
|
5558 |
|
5559 |
|
5560 |
|
5561 |
|
5562 |
|
5563 |
|
5564 |
|
5565 |
|
5566 |
|
5567 |
|
5568 |
|
5569 |
|
5570 |
|
5571 |
|
5572 |
|
5573 |
|
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 |
|
5583 |
|
5584 |
|
5585 |
|
5586 |
|
5587 |
|
5588 |
|
5589 |
|
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 |
|
5596 |
|
5597 |
|
5598 |
|
5599 |
|
5600 |
|
5601 |
|
5602 |
|
5603 |
|
5604 |
|
5605 |
|
5606 |
|
5607 |
|
5608 |
|
5609 |
|
5610 |
|
5611 |
|
5612 |
|
5613 |
|
5614 |
|
5615 |
|
5616 |
|
5617 |
|
5618 |
|
5619 |
|
5620 |
|
5621 |
|
5622 |
|
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 |
|
5628 |
|
5629 |
|
5630 |
|
5631 |
|
5632 |
|
5633 |
|
5634 |
|
5635 |
|
5636 |
|
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 |
|
5645 |
|
5646 |
|
5647 |
|
5648 |
|
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 |
|
5654 |
|
5655 |
|
5656 |
|
5657 |
|
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 |
|
5666 |
|
5667 |
|
5668 |
|
5669 |
|
5670 |
|
5671 |
|
5672 |
|
5673 |
|
5674 |
|
5675 |
|
5676 |
|
5677 |
|
5678 |
|
5679 |
|
5680 |
|
5681 |
|
5682 | ;
|
5683 |
|
5684 | class RotateAnimation {
|
5685 | constructor() {
|
5686 | this.enable = false;
|
5687 | this.speed = 0;
|
5688 | this.decay = 0;
|
5689 | this.sync = false;
|
5690 | }
|
5691 | load(data) {
|
5692 | if (!data) {
|
5693 | return;
|
5694 | }
|
5695 | if (data.enable !== undefined) {
|
5696 | this.enable = data.enable;
|
5697 | }
|
5698 | if (data.speed !== undefined) {
|
5699 | this.speed = setRangeValue(data.speed);
|
5700 | }
|
5701 | if (data.decay !== undefined) {
|
5702 | this.decay = setRangeValue(data.decay);
|
5703 | }
|
5704 | if (data.sync !== undefined) {
|
5705 | this.sync = data.sync;
|
5706 | }
|
5707 | }
|
5708 | }
|
5709 | ;
|
5710 |
|
5711 |
|
5712 | class Rotate extends ValueWithRandom {
|
5713 | constructor() {
|
5714 | super();
|
5715 | this.animation = new RotateAnimation();
|
5716 | this.direction = "clockwise";
|
5717 | this.path = false;
|
5718 | this.value = 0;
|
5719 | }
|
5720 | load(data) {
|
5721 | if (!data) {
|
5722 | return;
|
5723 | }
|
5724 | super.load(data);
|
5725 | if (data.direction !== undefined) {
|
5726 | this.direction = data.direction;
|
5727 | }
|
5728 | this.animation.load(data.animation);
|
5729 | if (data.path !== undefined) {
|
5730 | this.path = data.path;
|
5731 | }
|
5732 | }
|
5733 | }
|
5734 | ;
|
5735 |
|
5736 |
|
5737 | function updateAngle(particle, delta) {
|
5738 | var _a, _b;
|
5739 | const rotate = particle.rotate,
|
5740 | rotateOptions = particle.options.rotate;
|
5741 | if (!rotate || !rotateOptions) {
|
5742 | return;
|
5743 | }
|
5744 | const rotateAnimation = rotateOptions.animation,
|
5745 | speed = ((_a = rotate.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
|
5746 | max = 2 * Math.PI,
|
5747 | decay = (_b = rotate.decay) !== null && _b !== void 0 ? _b : 1;
|
5748 | if (!rotateAnimation.enable) {
|
5749 | return;
|
5750 | }
|
5751 | switch (rotate.status) {
|
5752 | case "increasing":
|
5753 | rotate.value += speed;
|
5754 | if (rotate.value > max) {
|
5755 | rotate.value -= max;
|
5756 | }
|
5757 | break;
|
5758 | case "decreasing":
|
5759 | default:
|
5760 | rotate.value -= speed;
|
5761 | if (rotate.value < 0) {
|
5762 | rotate.value += max;
|
5763 | }
|
5764 | break;
|
5765 | }
|
5766 | if (rotate.velocity && decay !== 1) {
|
5767 | rotate.velocity *= decay;
|
5768 | }
|
5769 | }
|
5770 | class RotateUpdater {
|
5771 | constructor(container) {
|
5772 | this.container = container;
|
5773 | }
|
5774 | init(particle) {
|
5775 | const rotateOptions = particle.options.rotate;
|
5776 | if (!rotateOptions) {
|
5777 | return;
|
5778 | }
|
5779 | particle.rotate = {
|
5780 | enable: rotateOptions.animation.enable,
|
5781 | value: getRangeValue(rotateOptions.value) * Math.PI / 180
|
5782 | };
|
5783 | particle.pathRotation = rotateOptions.path;
|
5784 | let rotateDirection = rotateOptions.direction;
|
5785 | if (rotateDirection === "random") {
|
5786 | const index = Math.floor(getRandom() * 2);
|
5787 | rotateDirection = index > 0 ? "counter-clockwise" : "clockwise";
|
5788 | }
|
5789 | switch (rotateDirection) {
|
5790 | case "counter-clockwise":
|
5791 | case "counterClockwise":
|
5792 | particle.rotate.status = "decreasing";
|
5793 | break;
|
5794 | case "clockwise":
|
5795 | particle.rotate.status = "increasing";
|
5796 | break;
|
5797 | }
|
5798 | const rotateAnimation = rotateOptions.animation;
|
5799 | if (rotateAnimation.enable) {
|
5800 | particle.rotate.decay = 1 - getRangeValue(rotateAnimation.decay);
|
5801 | particle.rotate.velocity = getRangeValue(rotateAnimation.speed) / 360 * this.container.retina.reduceFactor;
|
5802 | if (!rotateAnimation.sync) {
|
5803 | particle.rotate.velocity *= getRandom();
|
5804 | }
|
5805 | }
|
5806 | particle.rotation = particle.rotate.value;
|
5807 | }
|
5808 | isEnabled(particle) {
|
5809 | const rotate = particle.options.rotate;
|
5810 | if (!rotate) {
|
5811 | return false;
|
5812 | }
|
5813 | return !particle.destroyed && !particle.spawning && rotate.animation.enable && !rotate.path;
|
5814 | }
|
5815 | loadOptions(options, ...sources) {
|
5816 | if (!options.rotate) {
|
5817 | options.rotate = new Rotate();
|
5818 | }
|
5819 | for (const source of sources) {
|
5820 | options.rotate.load(source === null || source === void 0 ? void 0 : source.rotate);
|
5821 | }
|
5822 | }
|
5823 | update(particle, delta) {
|
5824 | var _a, _b;
|
5825 | if (!this.isEnabled(particle)) {
|
5826 | return;
|
5827 | }
|
5828 | updateAngle(particle, delta);
|
5829 | particle.rotation = (_b = (_a = particle.rotate) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 0;
|
5830 | }
|
5831 | }
|
5832 | ;
|
5833 |
|
5834 | async function loadAngleUpdater(engine) {
|
5835 | await engine.addParticleUpdater("rotate", container => new RotateUpdater(container));
|
5836 | }
|
5837 | ;
|
5838 |
|
5839 | function applyDistance(particle) {
|
5840 | const initialPosition = particle.initialPosition,
|
5841 | {
|
5842 | dx,
|
5843 | dy
|
5844 | } = getDistances(initialPosition, particle.position),
|
5845 | dxFixed = Math.abs(dx),
|
5846 | dyFixed = Math.abs(dy),
|
5847 | hDistance = particle.retina.maxDistance.horizontal,
|
5848 | vDistance = particle.retina.maxDistance.vertical;
|
5849 | if (!hDistance && !vDistance) {
|
5850 | return;
|
5851 | }
|
5852 | if ((hDistance && dxFixed >= hDistance || vDistance && dyFixed >= vDistance) && !particle.misplaced) {
|
5853 | particle.misplaced = !!hDistance && dxFixed > hDistance || !!vDistance && dyFixed > vDistance;
|
5854 | if (hDistance) {
|
5855 | particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
5856 | }
|
5857 | if (vDistance) {
|
5858 | particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
5859 | }
|
5860 | } else if ((!hDistance || dxFixed < hDistance) && (!vDistance || dyFixed < vDistance) && particle.misplaced) {
|
5861 | particle.misplaced = false;
|
5862 | } else if (particle.misplaced) {
|
5863 | const pos = particle.position,
|
5864 | vel = particle.velocity;
|
5865 | if (hDistance && (pos.x < initialPosition.x && vel.x < 0 || pos.x > initialPosition.x && vel.x > 0)) {
|
5866 | vel.x *= -getRandom();
|
5867 | }
|
5868 | if (vDistance && (pos.y < initialPosition.y && vel.y < 0 || pos.y > initialPosition.y && vel.y > 0)) {
|
5869 | vel.y *= -getRandom();
|
5870 | }
|
5871 | }
|
5872 | }
|
5873 | function spin(particle, moveSpeed) {
|
5874 | const container = particle.container;
|
5875 | if (!particle.spin) {
|
5876 | return;
|
5877 | }
|
5878 | const updateFunc = {
|
5879 | x: particle.spin.direction === "clockwise" ? Math.cos : Math.sin,
|
5880 | y: particle.spin.direction === "clockwise" ? Math.sin : Math.cos
|
5881 | };
|
5882 | particle.position.x = particle.spin.center.x + particle.spin.radius * updateFunc.x(particle.spin.angle);
|
5883 | particle.position.y = particle.spin.center.y + particle.spin.radius * updateFunc.y(particle.spin.angle);
|
5884 | particle.spin.radius += particle.spin.acceleration;
|
5885 | const maxCanvasSize = Math.max(container.canvas.size.width, container.canvas.size.height);
|
5886 | if (particle.spin.radius > maxCanvasSize / 2) {
|
5887 | particle.spin.radius = maxCanvasSize / 2;
|
5888 | particle.spin.acceleration *= -1;
|
5889 | } else if (particle.spin.radius < 0) {
|
5890 | particle.spin.radius = 0;
|
5891 | particle.spin.acceleration *= -1;
|
5892 | }
|
5893 | particle.spin.angle += moveSpeed / 100 * (1 - particle.spin.radius / maxCanvasSize);
|
5894 | }
|
5895 | function applyPath(particle, delta) {
|
5896 | var _a;
|
5897 | const particlesOptions = particle.options,
|
5898 | pathOptions = particlesOptions.move.path,
|
5899 | pathEnabled = pathOptions.enable;
|
5900 | if (!pathEnabled) {
|
5901 | return;
|
5902 | }
|
5903 | if (particle.lastPathTime <= particle.pathDelay) {
|
5904 | particle.lastPathTime += delta.value;
|
5905 | return;
|
5906 | }
|
5907 | const path = (_a = particle.pathGenerator) === null || _a === void 0 ? void 0 : _a.generate(particle);
|
5908 | if (path) {
|
5909 | particle.velocity.addTo(path);
|
5910 | }
|
5911 | if (pathOptions.clamp) {
|
5912 | particle.velocity.x = clamp(particle.velocity.x, -1, 1);
|
5913 | particle.velocity.y = clamp(particle.velocity.y, -1, 1);
|
5914 | }
|
5915 | particle.lastPathTime -= particle.pathDelay;
|
5916 | }
|
5917 | function getProximitySpeedFactor(particle) {
|
5918 | return particle.slow.inRange ? particle.slow.factor : 1;
|
5919 | }
|
5920 | ;
|
5921 |
|
5922 |
|
5923 | class BaseMover {
|
5924 | init(particle) {
|
5925 | var _a;
|
5926 | const container = particle.container,
|
5927 | options = particle.options,
|
5928 | gravityOptions = options.move.gravity,
|
5929 | spinOptions = options.move.spin;
|
5930 | particle.gravity = {
|
5931 | enable: gravityOptions.enable,
|
5932 | acceleration: getRangeValue(gravityOptions.acceleration),
|
5933 | inverse: gravityOptions.inverse
|
5934 | };
|
5935 | if (spinOptions.enable) {
|
5936 | const spinPos = (_a = spinOptions.position) !== null && _a !== void 0 ? _a : {
|
5937 | x: 50,
|
5938 | y: 50
|
5939 | },
|
5940 | spinCenter = {
|
5941 | x: spinPos.x / 100 * container.canvas.size.width,
|
5942 | y: spinPos.y / 100 * container.canvas.size.height
|
5943 | },
|
5944 | pos = particle.getPosition(),
|
5945 | distance = getDistance(pos, spinCenter),
|
5946 | spinAcceleration = getRangeValue(spinOptions.acceleration);
|
5947 | particle.retina.spinAcceleration = spinAcceleration * container.retina.pixelRatio;
|
5948 | particle.spin = {
|
5949 | center: spinCenter,
|
5950 | direction: particle.velocity.x >= 0 ? "clockwise" : "counter-clockwise",
|
5951 | angle: particle.velocity.angle,
|
5952 | radius: distance,
|
5953 | acceleration: particle.retina.spinAcceleration
|
5954 | };
|
5955 | }
|
5956 | }
|
5957 | isEnabled(particle) {
|
5958 | return !particle.destroyed && particle.options.move.enable;
|
5959 | }
|
5960 | move(particle, delta) {
|
5961 | var _a, _b, _c;
|
5962 | var _d, _e;
|
5963 | const particleOptions = particle.options,
|
5964 | moveOptions = particleOptions.move;
|
5965 | if (!moveOptions.enable) {
|
5966 | return;
|
5967 | }
|
5968 | const container = particle.container,
|
5969 | slowFactor = getProximitySpeedFactor(particle),
|
5970 | baseSpeed = ((_a = (_d = particle.retina).moveSpeed) !== null && _a !== void 0 ? _a : _d.moveSpeed = getRangeValue(moveOptions.speed) * container.retina.pixelRatio) * container.retina.reduceFactor,
|
5971 | moveDrift = (_b = (_e = particle.retina).moveDrift) !== null && _b !== void 0 ? _b : _e.moveDrift = getRangeValue(particle.options.move.drift) * container.retina.pixelRatio,
|
5972 | maxSize = getRangeMax(particleOptions.size.value) * container.retina.pixelRatio,
|
5973 | sizeFactor = moveOptions.size ? particle.getRadius() / maxSize : 1,
|
5974 | speedFactor = sizeFactor * slowFactor * (delta.factor || 1),
|
5975 | diffFactor = 2,
|
5976 | moveSpeed = baseSpeed * speedFactor / diffFactor;
|
5977 | if (moveOptions.spin.enable) {
|
5978 | spin(particle, moveSpeed);
|
5979 | } else {
|
5980 | applyPath(particle, delta);
|
5981 | const gravityOptions = particle.gravity,
|
5982 | gravityFactor = (gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && gravityOptions.inverse ? -1 : 1;
|
5983 | if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && moveSpeed) {
|
5984 | particle.velocity.y += gravityFactor * (gravityOptions.acceleration * delta.factor) / (60 * moveSpeed);
|
5985 | }
|
5986 | if (moveDrift && moveSpeed) {
|
5987 | particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed);
|
5988 | }
|
5989 | const decay = particle.moveDecay;
|
5990 | if (decay != 1) {
|
5991 | particle.velocity.multTo(decay);
|
5992 | }
|
5993 | const velocity = particle.velocity.mult(moveSpeed),
|
5994 | maxSpeed = (_c = particle.retina.maxSpeed) !== null && _c !== void 0 ? _c : container.retina.maxSpeed;
|
5995 | if ((gravityOptions === null || gravityOptions === void 0 ? void 0 : gravityOptions.enable) && maxSpeed > 0 && (!gravityOptions.inverse && velocity.y >= 0 && velocity.y >= maxSpeed || gravityOptions.inverse && velocity.y <= 0 && velocity.y <= -maxSpeed)) {
|
5996 | velocity.y = gravityFactor * maxSpeed;
|
5997 | if (moveSpeed) {
|
5998 | particle.velocity.y = velocity.y / moveSpeed;
|
5999 | }
|
6000 | }
|
6001 | const zIndexOptions = particle.options.zIndex,
|
6002 | zVelocityFactor = (1 - particle.zIndexFactor) ** zIndexOptions.velocityRate;
|
6003 | if (zVelocityFactor != 1) {
|
6004 | velocity.multTo(zVelocityFactor);
|
6005 | }
|
6006 | particle.position.addTo(velocity);
|
6007 | if (moveOptions.vibrate) {
|
6008 | particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
6009 | particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
6010 | }
|
6011 | }
|
6012 | applyDistance(particle);
|
6013 | }
|
6014 | }
|
6015 | ;
|
6016 |
|
6017 | async function loadBaseMover(engine) {
|
6018 | engine.addMover("base", () => new BaseMover());
|
6019 | }
|
6020 | ;
|
6021 | class CircleDrawer {
|
6022 | draw(context, particle, radius) {
|
6023 | if (!particle.circleRange) {
|
6024 | particle.circleRange = {
|
6025 | min: 0,
|
6026 | max: Math.PI * 2
|
6027 | };
|
6028 | }
|
6029 | const circleRange = particle.circleRange;
|
6030 | context.arc(0, 0, radius, circleRange.min, circleRange.max, false);
|
6031 | }
|
6032 | getSidesCount() {
|
6033 | return 12;
|
6034 | }
|
6035 | particleInit(container, particle) {
|
6036 | var _a;
|
6037 | const shapeData = particle.shapeData,
|
6038 | angle = (_a = shapeData === null || shapeData === void 0 ? void 0 : shapeData.angle) !== null && _a !== void 0 ? _a : {
|
6039 | max: 360,
|
6040 | min: 0
|
6041 | };
|
6042 | particle.circleRange = typeof angle !== "object" ? {
|
6043 | min: 0,
|
6044 | max: angle * Math.PI / 180
|
6045 | } : {
|
6046 | min: angle.min * Math.PI / 180,
|
6047 | max: angle.max * Math.PI / 180
|
6048 | };
|
6049 | }
|
6050 | }
|
6051 | ;
|
6052 |
|
6053 | async function loadCircleShape(engine) {
|
6054 | await engine.addShape("circle", new CircleDrawer());
|
6055 | }
|
6056 | ;
|
6057 |
|
6058 | function updateColorValue(delta, value, valueAnimation, max, decrease) {
|
6059 | var _a, _b;
|
6060 | const colorValue = value;
|
6061 | if (!colorValue || !valueAnimation.enable || colorValue.loops !== undefined && colorValue.maxLoops !== undefined && colorValue.maxLoops > 0 && colorValue.loops >= colorValue.maxLoops) {
|
6062 | return;
|
6063 | }
|
6064 | const offset = randomInRange(valueAnimation.offset),
|
6065 | velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6,
|
6066 | decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
6067 | if (!decrease || colorValue.status === "increasing") {
|
6068 | colorValue.value += velocity;
|
6069 | if (colorValue.value > max) {
|
6070 | if (!colorValue.loops) {
|
6071 | colorValue.loops = 0;
|
6072 | }
|
6073 | colorValue.loops++;
|
6074 | if (decrease) {
|
6075 | colorValue.status = "decreasing";
|
6076 | colorValue.value -= colorValue.value % max;
|
6077 | }
|
6078 | }
|
6079 | } else {
|
6080 | colorValue.value -= velocity;
|
6081 | if (colorValue.value < 0) {
|
6082 | if (!colorValue.loops) {
|
6083 | colorValue.loops = 0;
|
6084 | }
|
6085 | colorValue.loops++;
|
6086 | colorValue.status = "increasing";
|
6087 | colorValue.value += colorValue.value;
|
6088 | }
|
6089 | }
|
6090 | if (colorValue.velocity && decay !== 1) {
|
6091 | colorValue.velocity *= decay;
|
6092 | }
|
6093 | if (colorValue.value > max) {
|
6094 | colorValue.value %= max;
|
6095 | }
|
6096 | }
|
6097 | function updateColor(particle, delta) {
|
6098 | var _a, _b, _c;
|
6099 | const animationOptions = particle.options.color.animation;
|
6100 | const h = (_a = particle.color) === null || _a === void 0 ? void 0 : _a.h,
|
6101 | s = (_b = particle.color) === null || _b === void 0 ? void 0 : _b.s,
|
6102 | l = (_c = particle.color) === null || _c === void 0 ? void 0 : _c.l;
|
6103 | if (h) {
|
6104 | updateColorValue(delta, h, animationOptions.h, 360, false);
|
6105 | }
|
6106 | if (s) {
|
6107 | updateColorValue(delta, s, animationOptions.s, 100, true);
|
6108 | }
|
6109 | if (l) {
|
6110 | updateColorValue(delta, l, animationOptions.l, 100, true);
|
6111 | }
|
6112 | }
|
6113 | class ColorUpdater {
|
6114 | constructor(container) {
|
6115 | this.container = container;
|
6116 | }
|
6117 | init(particle) {
|
6118 | const hslColor = rangeColorToHsl(particle.options.color, particle.id, particle.options.reduceDuplicates);
|
6119 | if (hslColor) {
|
6120 | particle.color = getHslAnimationFromHsl(hslColor, particle.options.color.animation, this.container.retina.reduceFactor);
|
6121 | }
|
6122 | }
|
6123 | isEnabled(particle) {
|
6124 | var _a, _b, _c;
|
6125 | const animationOptions = particle.options.color.animation;
|
6126 | return !particle.destroyed && !particle.spawning && (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h.value) !== undefined && animationOptions.h.enable || ((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s.value) !== undefined && animationOptions.s.enable || ((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l.value) !== undefined && animationOptions.l.enable);
|
6127 | }
|
6128 | update(particle, delta) {
|
6129 | updateColor(particle, delta);
|
6130 | }
|
6131 | }
|
6132 | ;
|
6133 |
|
6134 | async function loadColorUpdater(engine) {
|
6135 | await engine.addParticleUpdater("color", container => new ColorUpdater(container));
|
6136 | }
|
6137 | ;
|
6138 | class Attract {
|
6139 | constructor() {
|
6140 | this.distance = 200;
|
6141 | this.duration = 0.4;
|
6142 | this.easing = "ease-out-quad";
|
6143 | this.factor = 1;
|
6144 | this.maxSpeed = 50;
|
6145 | this.speed = 1;
|
6146 | }
|
6147 | load(data) {
|
6148 | if (!data) {
|
6149 | return;
|
6150 | }
|
6151 | if (data.distance !== undefined) {
|
6152 | this.distance = data.distance;
|
6153 | }
|
6154 | if (data.duration !== undefined) {
|
6155 | this.duration = data.duration;
|
6156 | }
|
6157 | if (data.easing !== undefined) {
|
6158 | this.easing = data.easing;
|
6159 | }
|
6160 | if (data.factor !== undefined) {
|
6161 | this.factor = data.factor;
|
6162 | }
|
6163 | if (data.maxSpeed !== undefined) {
|
6164 | this.maxSpeed = data.maxSpeed;
|
6165 | }
|
6166 | if (data.speed !== undefined) {
|
6167 | this.speed = data.speed;
|
6168 | }
|
6169 | }
|
6170 | }
|
6171 | ;
|
6172 |
|
6173 |
|
6174 | class Attractor extends ExternalInteractorBase {
|
6175 | constructor(engine, container) {
|
6176 | super(container);
|
6177 | this._engine = engine;
|
6178 | if (!container.attract) {
|
6179 | container.attract = {
|
6180 | particles: []
|
6181 | };
|
6182 | }
|
6183 | this.handleClickMode = mode => {
|
6184 | const options = this.container.actualOptions,
|
6185 | attract = options.interactivity.modes.attract;
|
6186 | if (!attract || mode !== "attract") {
|
6187 | return;
|
6188 | }
|
6189 | if (!container.attract) {
|
6190 | container.attract = {
|
6191 | particles: []
|
6192 | };
|
6193 | }
|
6194 | container.attract.clicking = true;
|
6195 | container.attract.count = 0;
|
6196 | for (const particle of container.attract.particles) {
|
6197 | if (!this.isEnabled(particle)) {
|
6198 | continue;
|
6199 | }
|
6200 | particle.velocity.setTo(particle.initialVelocity);
|
6201 | }
|
6202 | container.attract.particles = [];
|
6203 | container.attract.finish = false;
|
6204 | setTimeout(() => {
|
6205 | if (!container.destroyed) {
|
6206 | if (!container.attract) {
|
6207 | container.attract = {
|
6208 | particles: []
|
6209 | };
|
6210 | }
|
6211 | container.attract.clicking = false;
|
6212 | }
|
6213 | }, attract.duration * 1000);
|
6214 | };
|
6215 | }
|
6216 | clear() {}
|
6217 | init() {
|
6218 | const container = this.container,
|
6219 | attract = container.actualOptions.interactivity.modes.attract;
|
6220 | if (!attract) {
|
6221 | return;
|
6222 | }
|
6223 | container.retina.attractModeDistance = attract.distance * container.retina.pixelRatio;
|
6224 | }
|
6225 | async interact() {
|
6226 | const container = this.container,
|
6227 | options = container.actualOptions,
|
6228 | mouseMoveStatus = container.interactivity.status === mouseMoveEvent,
|
6229 | events = options.interactivity.events,
|
6230 | hoverEnabled = events.onHover.enable,
|
6231 | hoverMode = events.onHover.mode,
|
6232 | clickEnabled = events.onClick.enable,
|
6233 | clickMode = events.onClick.mode;
|
6234 | if (mouseMoveStatus && hoverEnabled && isInArray("attract", hoverMode)) {
|
6235 | this.hoverAttract();
|
6236 | } else if (clickEnabled && isInArray("attract", clickMode)) {
|
6237 | this.clickAttract();
|
6238 | }
|
6239 | }
|
6240 | isEnabled(particle) {
|
6241 | var _a;
|
6242 | const container = this.container,
|
6243 | options = container.actualOptions,
|
6244 | mouse = container.interactivity.mouse,
|
6245 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events;
|
6246 | if ((!mouse.position || !events.onHover.enable) && (!mouse.clickPosition || !events.onClick.enable)) {
|
6247 | return false;
|
6248 | }
|
6249 | const hoverMode = events.onHover.mode,
|
6250 | clickMode = events.onClick.mode;
|
6251 | return isInArray("attract", hoverMode) || isInArray("attract", clickMode);
|
6252 | }
|
6253 | loadModeOptions(options, ...sources) {
|
6254 | if (!options.attract) {
|
6255 | options.attract = new Attract();
|
6256 | }
|
6257 | for (const source of sources) {
|
6258 | options.attract.load(source === null || source === void 0 ? void 0 : source.attract);
|
6259 | }
|
6260 | }
|
6261 | reset() {}
|
6262 | clickAttract() {
|
6263 | const container = this.container;
|
6264 | if (!container.attract) {
|
6265 | container.attract = {
|
6266 | particles: []
|
6267 | };
|
6268 | }
|
6269 | if (!container.attract.finish) {
|
6270 | if (!container.attract.count) {
|
6271 | container.attract.count = 0;
|
6272 | }
|
6273 | container.attract.count++;
|
6274 | if (container.attract.count === container.particles.count) {
|
6275 | container.attract.finish = true;
|
6276 | }
|
6277 | }
|
6278 | if (container.attract.clicking) {
|
6279 | const mousePos = container.interactivity.mouse.clickPosition,
|
6280 | attractRadius = container.retina.attractModeDistance;
|
6281 | if (!attractRadius || attractRadius < 0 || !mousePos) {
|
6282 | return;
|
6283 | }
|
6284 | this.processAttract(mousePos, attractRadius, new Circle(mousePos.x, mousePos.y, attractRadius));
|
6285 | } else if (container.attract.clicking === false) {
|
6286 | container.attract.particles = [];
|
6287 | }
|
6288 | return;
|
6289 | }
|
6290 | hoverAttract() {
|
6291 | const container = this.container,
|
6292 | mousePos = container.interactivity.mouse.position,
|
6293 | attractRadius = container.retina.attractModeDistance;
|
6294 | if (!attractRadius || attractRadius < 0 || !mousePos) {
|
6295 | return;
|
6296 | }
|
6297 | this.processAttract(mousePos, attractRadius, new Circle(mousePos.x, mousePos.y, attractRadius));
|
6298 | }
|
6299 | processAttract(position, attractRadius, area) {
|
6300 | const container = this.container,
|
6301 | attractOptions = container.actualOptions.interactivity.modes.attract;
|
6302 | if (!attractOptions) {
|
6303 | return;
|
6304 | }
|
6305 | const query = container.particles.quadTree.query(area, p => this.isEnabled(p));
|
6306 | for (const particle of query) {
|
6307 | const {
|
6308 | dx,
|
6309 | dy,
|
6310 | distance
|
6311 | } = getDistances(particle.position, position);
|
6312 | const velocity = attractOptions.speed * attractOptions.factor;
|
6313 | const attractFactor = clamp(getEasing(attractOptions.easing)(1 - distance / attractRadius) * velocity, 0, attractOptions.maxSpeed);
|
6314 | const normVec = Vector.create(distance === 0 ? velocity : dx / distance * attractFactor, distance === 0 ? velocity : dy / distance * attractFactor);
|
6315 | particle.position.subFrom(normVec);
|
6316 | }
|
6317 | }
|
6318 | }
|
6319 | ;
|
6320 |
|
6321 | async function loadExternalAttractInteraction(engine) {
|
6322 | await engine.addInteractor("externalAttract", container => new Attractor(engine, container));
|
6323 | }
|
6324 |
|
6325 |
|
6326 | ;
|
6327 | class Bounce {
|
6328 | constructor() {
|
6329 | this.distance = 200;
|
6330 | }
|
6331 | load(data) {
|
6332 | if (!data) {
|
6333 | return;
|
6334 | }
|
6335 | if (data.distance !== undefined) {
|
6336 | this.distance = data.distance;
|
6337 | }
|
6338 | }
|
6339 | }
|
6340 | ;
|
6341 |
|
6342 |
|
6343 | class Bouncer extends ExternalInteractorBase {
|
6344 | constructor(container) {
|
6345 | super(container);
|
6346 | }
|
6347 | clear() {}
|
6348 | init() {
|
6349 | const container = this.container,
|
6350 | bounce = container.actualOptions.interactivity.modes.bounce;
|
6351 | if (!bounce) {
|
6352 | return;
|
6353 | }
|
6354 | container.retina.bounceModeDistance = bounce.distance * container.retina.pixelRatio;
|
6355 | }
|
6356 | async interact() {
|
6357 | const container = this.container,
|
6358 | options = container.actualOptions,
|
6359 | events = options.interactivity.events,
|
6360 | mouseMoveStatus = container.interactivity.status === mouseMoveEvent,
|
6361 | hoverEnabled = events.onHover.enable,
|
6362 | hoverMode = events.onHover.mode,
|
6363 | divs = events.onDiv;
|
6364 | if (mouseMoveStatus && hoverEnabled && isInArray("bounce", hoverMode)) {
|
6365 | this.processMouseBounce();
|
6366 | } else {
|
6367 | divModeExecute("bounce", divs, (selector, div) => this.singleSelectorBounce(selector, div));
|
6368 | }
|
6369 | }
|
6370 | isEnabled(particle) {
|
6371 | var _a;
|
6372 | const container = this.container,
|
6373 | options = container.actualOptions,
|
6374 | mouse = container.interactivity.mouse,
|
6375 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events,
|
6376 | divs = events.onDiv;
|
6377 | return mouse.position && events.onHover.enable && isInArray("bounce", events.onHover.mode) || isDivModeEnabled("bounce", divs);
|
6378 | }
|
6379 | loadModeOptions(options, ...sources) {
|
6380 | if (!options.bounce) {
|
6381 | options.bounce = new Bounce();
|
6382 | }
|
6383 | for (const source of sources) {
|
6384 | options.bounce.load(source === null || source === void 0 ? void 0 : source.bounce);
|
6385 | }
|
6386 | }
|
6387 | reset() {}
|
6388 | processBounce(position, radius, area) {
|
6389 | const query = this.container.particles.quadTree.query(area, p => this.isEnabled(p));
|
6390 | for (const particle of query) {
|
6391 | if (area instanceof Circle) {
|
6392 | circleBounce(circleBounceDataFromParticle(particle), {
|
6393 | position,
|
6394 | radius,
|
6395 | mass: radius ** 2 * Math.PI / 2,
|
6396 | velocity: Vector.origin,
|
6397 | factor: Vector.origin
|
6398 | });
|
6399 | } else if (area instanceof Rectangle) {
|
6400 | rectBounce(particle, calculateBounds(position, radius));
|
6401 | }
|
6402 | }
|
6403 | }
|
6404 | processMouseBounce() {
|
6405 | const container = this.container,
|
6406 | pxRatio = container.retina.pixelRatio,
|
6407 | tolerance = 10 * pxRatio,
|
6408 | mousePos = container.interactivity.mouse.position,
|
6409 | radius = container.retina.bounceModeDistance;
|
6410 | if (!radius || radius < 0 || !mousePos) {
|
6411 | return;
|
6412 | }
|
6413 | this.processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance));
|
6414 | }
|
6415 | singleSelectorBounce(selector, div) {
|
6416 | const container = this.container,
|
6417 | query = document.querySelectorAll(selector);
|
6418 | if (!query.length) {
|
6419 | return;
|
6420 | }
|
6421 | query.forEach(item => {
|
6422 | const elem = item,
|
6423 | pxRatio = container.retina.pixelRatio,
|
6424 | pos = {
|
6425 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
6426 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
6427 | },
|
6428 | radius = elem.offsetWidth / 2 * pxRatio,
|
6429 | tolerance = 10 * pxRatio,
|
6430 | area = div.type === "circle" ? new Circle(pos.x, pos.y, radius + tolerance) : new Rectangle(elem.offsetLeft * pxRatio - tolerance, elem.offsetTop * pxRatio - tolerance, elem.offsetWidth * pxRatio + tolerance * 2, elem.offsetHeight * pxRatio + tolerance * 2);
|
6431 | this.processBounce(pos, radius, area);
|
6432 | });
|
6433 | }
|
6434 | }
|
6435 | ;
|
6436 |
|
6437 | async function loadExternalBounceInteraction(engine) {
|
6438 | await engine.addInteractor("externalBounce", container => new Bouncer(container));
|
6439 | }
|
6440 |
|
6441 |
|
6442 | ;
|
6443 |
|
6444 | class BubbleBase {
|
6445 | constructor() {
|
6446 | this.distance = 200;
|
6447 | this.duration = 0.4;
|
6448 | this.mix = false;
|
6449 | }
|
6450 | load(data) {
|
6451 | if (!data) {
|
6452 | return;
|
6453 | }
|
6454 | if (data.distance !== undefined) {
|
6455 | this.distance = data.distance;
|
6456 | }
|
6457 | if (data.duration !== undefined) {
|
6458 | this.duration = data.duration;
|
6459 | }
|
6460 | if (data.mix !== undefined) {
|
6461 | this.mix = data.mix;
|
6462 | }
|
6463 | if (data.opacity !== undefined) {
|
6464 | this.opacity = data.opacity;
|
6465 | }
|
6466 | if (data.color !== undefined) {
|
6467 | const sourceColor = this.color instanceof Array ? undefined : this.color;
|
6468 | this.color = executeOnSingleOrMultiple(data.color, color => {
|
6469 | return OptionsColor.create(sourceColor, color);
|
6470 | });
|
6471 | }
|
6472 | if (data.size !== undefined) {
|
6473 | this.size = data.size;
|
6474 | }
|
6475 | }
|
6476 | }
|
6477 | ;
|
6478 |
|
6479 |
|
6480 | class BubbleDiv extends BubbleBase {
|
6481 | constructor() {
|
6482 | super();
|
6483 | this.selectors = [];
|
6484 | }
|
6485 | get ids() {
|
6486 | return executeOnSingleOrMultiple(this.selectors, t => t.replace("#", ""));
|
6487 | }
|
6488 | set ids(value) {
|
6489 | this.selectors = executeOnSingleOrMultiple(value, t => `#${t}`);
|
6490 | }
|
6491 | load(data) {
|
6492 | super.load(data);
|
6493 | if (!data) {
|
6494 | return;
|
6495 | }
|
6496 | if (data.ids !== undefined) {
|
6497 | this.ids = data.ids;
|
6498 | }
|
6499 | if (data.selectors !== undefined) {
|
6500 | this.selectors = data.selectors;
|
6501 | }
|
6502 | }
|
6503 | }
|
6504 | ;
|
6505 |
|
6506 |
|
6507 |
|
6508 | class Bubble extends BubbleBase {
|
6509 | load(data) {
|
6510 | super.load(data);
|
6511 | if (!data) {
|
6512 | return;
|
6513 | }
|
6514 | this.divs = executeOnSingleOrMultiple(data.divs, div => {
|
6515 | const tmp = new BubbleDiv();
|
6516 | tmp.load(div);
|
6517 | return tmp;
|
6518 | });
|
6519 | }
|
6520 | }
|
6521 | ;
|
6522 |
|
6523 |
|
6524 | function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
|
6525 | if (modeValue >= optionsValue) {
|
6526 | const value = particleValue + (modeValue - optionsValue) * ratio;
|
6527 | return clamp(value, particleValue, modeValue);
|
6528 | } else if (modeValue < optionsValue) {
|
6529 | const value = particleValue - (optionsValue - modeValue) * ratio;
|
6530 | return clamp(value, modeValue, particleValue);
|
6531 | }
|
6532 | }
|
6533 | class Bubbler extends ExternalInteractorBase {
|
6534 | constructor(container) {
|
6535 | super(container);
|
6536 | if (!container.bubble) {
|
6537 | container.bubble = {};
|
6538 | }
|
6539 | this.handleClickMode = mode => {
|
6540 | if (mode !== "bubble") {
|
6541 | return;
|
6542 | }
|
6543 | if (!container.bubble) {
|
6544 | container.bubble = {};
|
6545 | }
|
6546 | container.bubble.clicking = true;
|
6547 | };
|
6548 | }
|
6549 | clear(particle, delta, force) {
|
6550 | if (particle.bubble.inRange && !force) {
|
6551 | return;
|
6552 | }
|
6553 | delete particle.bubble.div;
|
6554 | delete particle.bubble.opacity;
|
6555 | delete particle.bubble.radius;
|
6556 | delete particle.bubble.color;
|
6557 | }
|
6558 | init() {
|
6559 | const container = this.container,
|
6560 | bubble = container.actualOptions.interactivity.modes.bubble;
|
6561 | if (!bubble) {
|
6562 | return;
|
6563 | }
|
6564 | container.retina.bubbleModeDistance = bubble.distance * container.retina.pixelRatio;
|
6565 | if (bubble.size !== undefined) {
|
6566 | container.retina.bubbleModeSize = bubble.size * container.retina.pixelRatio;
|
6567 | }
|
6568 | }
|
6569 | async interact(delta) {
|
6570 | const options = this.container.actualOptions,
|
6571 | events = options.interactivity.events,
|
6572 | onHover = events.onHover,
|
6573 | onClick = events.onClick,
|
6574 | hoverEnabled = onHover.enable,
|
6575 | hoverMode = onHover.mode,
|
6576 | clickEnabled = onClick.enable,
|
6577 | clickMode = onClick.mode,
|
6578 | divs = events.onDiv;
|
6579 | if (hoverEnabled && isInArray("bubble", hoverMode)) {
|
6580 | this.hoverBubble(delta);
|
6581 | } else if (clickEnabled && isInArray("bubble", clickMode)) {
|
6582 | this.clickBubble(delta);
|
6583 | } else {
|
6584 | divModeExecute("bubble", divs, (selector, div) => this.singleSelectorHover(delta, selector, div));
|
6585 | }
|
6586 | }
|
6587 | isEnabled(particle) {
|
6588 | var _a;
|
6589 | const container = this.container,
|
6590 | options = container.actualOptions,
|
6591 | mouse = container.interactivity.mouse,
|
6592 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events,
|
6593 | divs = events.onDiv,
|
6594 | divBubble = isDivModeEnabled("bubble", divs);
|
6595 | if (!(divBubble || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
|
6596 | return false;
|
6597 | }
|
6598 | const hoverMode = events.onHover.mode;
|
6599 | const clickMode = events.onClick.mode;
|
6600 | return isInArray("bubble", hoverMode) || isInArray("bubble", clickMode) || divBubble;
|
6601 | }
|
6602 | loadModeOptions(options, ...sources) {
|
6603 | if (!options.bubble) {
|
6604 | options.bubble = new Bubble();
|
6605 | }
|
6606 | for (const source of sources) {
|
6607 | options.bubble.load(source === null || source === void 0 ? void 0 : source.bubble);
|
6608 | }
|
6609 | }
|
6610 | reset(particle) {
|
6611 | particle.bubble.inRange = false;
|
6612 | }
|
6613 | clickBubble(delta) {
|
6614 | var _a, _b;
|
6615 | const container = this.container,
|
6616 | options = container.actualOptions,
|
6617 | mouseClickPos = container.interactivity.mouse.clickPosition,
|
6618 | bubble = options.interactivity.modes.bubble;
|
6619 | if (!bubble || !mouseClickPos) {
|
6620 | return;
|
6621 | }
|
6622 | if (!container.bubble) {
|
6623 | container.bubble = {};
|
6624 | }
|
6625 | const distance = container.retina.bubbleModeDistance;
|
6626 | if (!distance || distance < 0) {
|
6627 | return;
|
6628 | }
|
6629 | const query = container.particles.quadTree.queryCircle(mouseClickPos, distance, p => this.isEnabled(p));
|
6630 | for (const particle of query) {
|
6631 | if (!container.bubble.clicking) {
|
6632 | continue;
|
6633 | }
|
6634 | particle.bubble.inRange = !container.bubble.durationEnd;
|
6635 | const pos = particle.getPosition(),
|
6636 | distMouse = getDistance(pos, mouseClickPos),
|
6637 | timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
|
6638 | if (timeSpent > bubble.duration) {
|
6639 | container.bubble.durationEnd = true;
|
6640 | }
|
6641 | if (timeSpent > bubble.duration * 2) {
|
6642 | container.bubble.clicking = false;
|
6643 | container.bubble.durationEnd = false;
|
6644 | }
|
6645 | const sizeData = {
|
6646 | bubbleObj: {
|
6647 | optValue: container.retina.bubbleModeSize,
|
6648 | value: particle.bubble.radius
|
6649 | },
|
6650 | particlesObj: {
|
6651 | optValue: getRangeMax(particle.options.size.value) * container.retina.pixelRatio,
|
6652 | value: particle.size.value
|
6653 | },
|
6654 | type: "size"
|
6655 | };
|
6656 | this.process(particle, distMouse, timeSpent, sizeData);
|
6657 | const opacityData = {
|
6658 | bubbleObj: {
|
6659 | optValue: bubble.opacity,
|
6660 | value: particle.bubble.opacity
|
6661 | },
|
6662 | particlesObj: {
|
6663 | optValue: getRangeMax(particle.options.opacity.value),
|
6664 | value: (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1
|
6665 | },
|
6666 | type: "opacity"
|
6667 | };
|
6668 | this.process(particle, distMouse, timeSpent, opacityData);
|
6669 | if (!container.bubble.durationEnd) {
|
6670 | if (distMouse <= distance) {
|
6671 | this.hoverBubbleColor(particle, distMouse);
|
6672 | } else {
|
6673 | delete particle.bubble.color;
|
6674 | }
|
6675 | } else {
|
6676 | delete particle.bubble.color;
|
6677 | }
|
6678 | }
|
6679 | }
|
6680 | hoverBubble(delta) {
|
6681 | const container = this.container,
|
6682 | mousePos = container.interactivity.mouse.position,
|
6683 | distance = container.retina.bubbleModeDistance;
|
6684 | if (!distance || distance < 0 || mousePos === undefined) {
|
6685 | return;
|
6686 | }
|
6687 | const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
|
6688 | for (const particle of query) {
|
6689 | particle.bubble.inRange = true;
|
6690 | const pos = particle.getPosition(),
|
6691 | pointDistance = getDistance(pos, mousePos),
|
6692 | ratio = 1 - pointDistance / distance;
|
6693 | if (pointDistance <= distance) {
|
6694 | if (ratio >= 0 && container.interactivity.status === mouseMoveEvent) {
|
6695 | this.hoverBubbleSize(particle, ratio);
|
6696 | this.hoverBubbleOpacity(particle, ratio);
|
6697 | this.hoverBubbleColor(particle, ratio);
|
6698 | }
|
6699 | } else {
|
6700 | this.reset(particle);
|
6701 | }
|
6702 | if (container.interactivity.status === mouseLeaveEvent) {
|
6703 | this.reset(particle);
|
6704 | }
|
6705 | }
|
6706 | }
|
6707 | hoverBubbleColor(particle, ratio, divBubble) {
|
6708 | const options = this.container.actualOptions;
|
6709 | const bubbleOptions = divBubble !== null && divBubble !== void 0 ? divBubble : options.interactivity.modes.bubble;
|
6710 | if (!bubbleOptions) {
|
6711 | return;
|
6712 | }
|
6713 | if (!particle.bubble.finalColor) {
|
6714 | const modeColor = bubbleOptions.color;
|
6715 | if (!modeColor) {
|
6716 | return;
|
6717 | }
|
6718 | const bubbleColor = itemFromSingleOrMultiple(modeColor);
|
6719 | particle.bubble.finalColor = rangeColorToHsl(bubbleColor);
|
6720 | }
|
6721 | if (!particle.bubble.finalColor) {
|
6722 | return;
|
6723 | }
|
6724 | if (bubbleOptions.mix) {
|
6725 | particle.bubble.color = undefined;
|
6726 | const pColor = particle.getFillColor();
|
6727 | particle.bubble.color = pColor ? rgbToHsl(colorMix(pColor, particle.bubble.finalColor, 1 - ratio, ratio)) : particle.bubble.finalColor;
|
6728 | } else {
|
6729 | particle.bubble.color = particle.bubble.finalColor;
|
6730 | }
|
6731 | }
|
6732 | hoverBubbleOpacity(particle, ratio, divBubble) {
|
6733 | var _a, _b, _c, _d;
|
6734 | const container = this.container,
|
6735 | options = container.actualOptions,
|
6736 | modeOpacity = (_a = divBubble === null || divBubble === void 0 ? void 0 : divBubble.opacity) !== null && _a !== void 0 ? _a : (_b = options.interactivity.modes.bubble) === null || _b === void 0 ? void 0 : _b.opacity;
|
6737 | if (!modeOpacity) {
|
6738 | return;
|
6739 | }
|
6740 | const optOpacity = particle.options.opacity.value;
|
6741 | const pOpacity = (_d = (_c = particle.opacity) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 1;
|
6742 | const opacity = calculateBubbleValue(pOpacity, modeOpacity, getRangeMax(optOpacity), ratio);
|
6743 | if (opacity !== undefined) {
|
6744 | particle.bubble.opacity = opacity;
|
6745 | }
|
6746 | }
|
6747 | hoverBubbleSize(particle, ratio, divBubble) {
|
6748 | const container = this.container,
|
6749 | modeSize = (divBubble === null || divBubble === void 0 ? void 0 : divBubble.size) ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
|
6750 | if (modeSize === undefined) {
|
6751 | return;
|
6752 | }
|
6753 | const optSize = getRangeMax(particle.options.size.value) * container.retina.pixelRatio;
|
6754 | const pSize = particle.size.value;
|
6755 | const size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
|
6756 | if (size !== undefined) {
|
6757 | particle.bubble.radius = size;
|
6758 | }
|
6759 | }
|
6760 | process(particle, distMouse, timeSpent, data) {
|
6761 | const container = this.container,
|
6762 | bubbleParam = data.bubbleObj.optValue,
|
6763 | options = container.actualOptions,
|
6764 | bubble = options.interactivity.modes.bubble;
|
6765 | if (!bubble || bubbleParam === undefined) {
|
6766 | return;
|
6767 | }
|
6768 | const bubbleDuration = bubble.duration,
|
6769 | bubbleDistance = container.retina.bubbleModeDistance,
|
6770 | particlesParam = data.particlesObj.optValue,
|
6771 | pObjBubble = data.bubbleObj.value,
|
6772 | pObj = data.particlesObj.value || 0,
|
6773 | type = data.type;
|
6774 | if (!bubbleDistance || bubbleDistance < 0 || bubbleParam === particlesParam) {
|
6775 | return;
|
6776 | }
|
6777 | if (!container.bubble) {
|
6778 | container.bubble = {};
|
6779 | }
|
6780 | if (!container.bubble.durationEnd) {
|
6781 | if (distMouse <= bubbleDistance) {
|
6782 | const obj = pObjBubble !== null && pObjBubble !== void 0 ? pObjBubble : pObj;
|
6783 | if (obj !== bubbleParam) {
|
6784 | const value = pObj - timeSpent * (pObj - bubbleParam) / bubbleDuration;
|
6785 | if (type === "size") {
|
6786 | particle.bubble.radius = value;
|
6787 | }
|
6788 | if (type === "opacity") {
|
6789 | particle.bubble.opacity = value;
|
6790 | }
|
6791 | }
|
6792 | } else {
|
6793 | if (type === "size") {
|
6794 | delete particle.bubble.radius;
|
6795 | }
|
6796 | if (type === "opacity") {
|
6797 | delete particle.bubble.opacity;
|
6798 | }
|
6799 | }
|
6800 | } else if (pObjBubble) {
|
6801 | if (type === "size") {
|
6802 | delete particle.bubble.radius;
|
6803 | }
|
6804 | if (type === "opacity") {
|
6805 | delete particle.bubble.opacity;
|
6806 | }
|
6807 | }
|
6808 | }
|
6809 | singleSelectorHover(delta, selector, div) {
|
6810 | const container = this.container,
|
6811 | selectors = document.querySelectorAll(selector),
|
6812 | bubble = container.actualOptions.interactivity.modes.bubble;
|
6813 | if (!bubble || !selectors.length) {
|
6814 | return;
|
6815 | }
|
6816 | selectors.forEach(item => {
|
6817 | const elem = item,
|
6818 | pxRatio = container.retina.pixelRatio,
|
6819 | pos = {
|
6820 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
6821 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
6822 | },
|
6823 | repulseRadius = elem.offsetWidth / 2 * pxRatio,
|
6824 | area = div.type === "circle" ? new Circle(pos.x, pos.y, repulseRadius) : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio),
|
6825 | query = container.particles.quadTree.query(area, p => this.isEnabled(p));
|
6826 | for (const particle of query) {
|
6827 | if (!area.contains(particle.getPosition())) {
|
6828 | continue;
|
6829 | }
|
6830 | particle.bubble.inRange = true;
|
6831 | const divs = bubble.divs;
|
6832 | const divBubble = divMode(divs, elem);
|
6833 | if (!particle.bubble.div || particle.bubble.div !== elem) {
|
6834 | this.clear(particle, delta, true);
|
6835 | particle.bubble.div = elem;
|
6836 | }
|
6837 | this.hoverBubbleSize(particle, 1, divBubble);
|
6838 | this.hoverBubbleOpacity(particle, 1, divBubble);
|
6839 | this.hoverBubbleColor(particle, 1, divBubble);
|
6840 | }
|
6841 | });
|
6842 | }
|
6843 | }
|
6844 | ;
|
6845 |
|
6846 | async function loadExternalBubbleInteraction(engine) {
|
6847 | await engine.addInteractor("externalBubble", container => new Bubbler(container));
|
6848 | }
|
6849 |
|
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 | ;
|
6856 | class ConnectLinks {
|
6857 | constructor() {
|
6858 | this.opacity = 0.5;
|
6859 | }
|
6860 | load(data) {
|
6861 | if (!data) {
|
6862 | return;
|
6863 | }
|
6864 | if (data.opacity !== undefined) {
|
6865 | this.opacity = data.opacity;
|
6866 | }
|
6867 | }
|
6868 | }
|
6869 | ;
|
6870 |
|
6871 | class Connect {
|
6872 | constructor() {
|
6873 | this.distance = 80;
|
6874 | this.links = new ConnectLinks();
|
6875 | this.radius = 60;
|
6876 | }
|
6877 | get lineLinked() {
|
6878 | return this.links;
|
6879 | }
|
6880 | set lineLinked(value) {
|
6881 | this.links = value;
|
6882 | }
|
6883 | get line_linked() {
|
6884 | return this.links;
|
6885 | }
|
6886 | set line_linked(value) {
|
6887 | this.links = value;
|
6888 | }
|
6889 | load(data) {
|
6890 | var _a, _b;
|
6891 | if (!data) {
|
6892 | return;
|
6893 | }
|
6894 | if (data.distance !== undefined) {
|
6895 | this.distance = data.distance;
|
6896 | }
|
6897 | this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
|
6898 | if (data.radius !== undefined) {
|
6899 | this.radius = data.radius;
|
6900 | }
|
6901 | }
|
6902 | }
|
6903 | ;
|
6904 |
|
6905 |
|
6906 | function gradient(context, p1, p2, opacity) {
|
6907 | const gradStop = Math.floor(p2.getRadius() / p1.getRadius()),
|
6908 | color1 = p1.getFillColor(),
|
6909 | color2 = p2.getFillColor();
|
6910 | if (!color1 || !color2) {
|
6911 | return;
|
6912 | }
|
6913 | const sourcePos = p1.getPosition(),
|
6914 | destPos = p2.getPosition(),
|
6915 | midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius()),
|
6916 | grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
6917 | grad.addColorStop(0, getStyleFromHsl(color1, opacity));
|
6918 | grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
|
6919 | grad.addColorStop(1, getStyleFromHsl(color2, opacity));
|
6920 | return grad;
|
6921 | }
|
6922 | function drawConnectLine(context, width, lineStyle, begin, end) {
|
6923 | drawLine(context, begin, end);
|
6924 | context.lineWidth = width;
|
6925 | context.strokeStyle = lineStyle;
|
6926 | context.stroke();
|
6927 | }
|
6928 | function lineStyle(container, ctx, p1, p2) {
|
6929 | const options = container.actualOptions,
|
6930 | connectOptions = options.interactivity.modes.connect;
|
6931 | if (!connectOptions) {
|
6932 | return;
|
6933 | }
|
6934 | return gradient(ctx, p1, p2, connectOptions.links.opacity);
|
6935 | }
|
6936 | function drawConnection(container, p1, p2) {
|
6937 | container.canvas.draw(ctx => {
|
6938 | var _a;
|
6939 | const ls = lineStyle(container, ctx, p1, p2);
|
6940 | if (!ls) {
|
6941 | return;
|
6942 | }
|
6943 | const pos1 = p1.getPosition(),
|
6944 | pos2 = p2.getPosition();
|
6945 | drawConnectLine(ctx, (_a = p1.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, ls, pos1, pos2);
|
6946 | });
|
6947 | }
|
6948 | class Connector extends ExternalInteractorBase {
|
6949 | constructor(container) {
|
6950 | super(container);
|
6951 | }
|
6952 | clear() {}
|
6953 | init() {
|
6954 | const container = this.container,
|
6955 | connect = container.actualOptions.interactivity.modes.connect;
|
6956 | if (!connect) {
|
6957 | return;
|
6958 | }
|
6959 | container.retina.connectModeDistance = connect.distance * container.retina.pixelRatio;
|
6960 | container.retina.connectModeRadius = connect.radius * container.retina.pixelRatio;
|
6961 | }
|
6962 | async interact() {
|
6963 | const container = this.container,
|
6964 | options = container.actualOptions;
|
6965 | if (options.interactivity.events.onHover.enable && container.interactivity.status === "pointermove") {
|
6966 | const mousePos = container.interactivity.mouse.position;
|
6967 | if (!container.retina.connectModeDistance || container.retina.connectModeDistance < 0 || !container.retina.connectModeRadius || container.retina.connectModeRadius < 0 || !mousePos) {
|
6968 | return;
|
6969 | }
|
6970 | const distance = Math.abs(container.retina.connectModeRadius),
|
6971 | query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
|
6972 | let i = 0;
|
6973 | for (const p1 of query) {
|
6974 | const pos1 = p1.getPosition();
|
6975 | for (const p2 of query.slice(i + 1)) {
|
6976 | const pos2 = p2.getPosition(),
|
6977 | distMax = Math.abs(container.retina.connectModeDistance),
|
6978 | xDiff = Math.abs(pos1.x - pos2.x),
|
6979 | yDiff = Math.abs(pos1.y - pos2.y);
|
6980 | if (xDiff < distMax && yDiff < distMax) {
|
6981 | drawConnection(container, p1, p2);
|
6982 | }
|
6983 | }
|
6984 | ++i;
|
6985 | }
|
6986 | }
|
6987 | }
|
6988 | isEnabled(particle) {
|
6989 | var _a;
|
6990 | const container = this.container,
|
6991 | mouse = container.interactivity.mouse,
|
6992 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
6993 | if (!(events.onHover.enable && mouse.position)) {
|
6994 | return false;
|
6995 | }
|
6996 | return isInArray("connect", events.onHover.mode);
|
6997 | }
|
6998 | loadModeOptions(options, ...sources) {
|
6999 | if (!options.connect) {
|
7000 | options.connect = new Connect();
|
7001 | }
|
7002 | for (const source of sources) {
|
7003 | options.connect.load(source === null || source === void 0 ? void 0 : source.connect);
|
7004 | }
|
7005 | }
|
7006 | reset() {}
|
7007 | }
|
7008 | ;
|
7009 |
|
7010 | async function loadExternalConnectInteraction(engine) {
|
7011 | await engine.addInteractor("externalConnect", container => new Connector(container));
|
7012 | }
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 | ;
|
7018 |
|
7019 | class GrabLinks {
|
7020 | constructor() {
|
7021 | this.blink = false;
|
7022 | this.consent = false;
|
7023 | this.opacity = 1;
|
7024 | }
|
7025 | load(data) {
|
7026 | if (!data) {
|
7027 | return;
|
7028 | }
|
7029 | if (data.blink !== undefined) {
|
7030 | this.blink = data.blink;
|
7031 | }
|
7032 | if (data.color !== undefined) {
|
7033 | this.color = OptionsColor.create(this.color, data.color);
|
7034 | }
|
7035 | if (data.consent !== undefined) {
|
7036 | this.consent = data.consent;
|
7037 | }
|
7038 | if (data.opacity !== undefined) {
|
7039 | this.opacity = data.opacity;
|
7040 | }
|
7041 | }
|
7042 | }
|
7043 | ;
|
7044 |
|
7045 | class Grab {
|
7046 | constructor() {
|
7047 | this.distance = 100;
|
7048 | this.links = new GrabLinks();
|
7049 | }
|
7050 | get lineLinked() {
|
7051 | return this.links;
|
7052 | }
|
7053 | set lineLinked(value) {
|
7054 | this.links = value;
|
7055 | }
|
7056 | get line_linked() {
|
7057 | return this.links;
|
7058 | }
|
7059 | set line_linked(value) {
|
7060 | this.links = value;
|
7061 | }
|
7062 | load(data) {
|
7063 | var _a, _b;
|
7064 | if (!data) {
|
7065 | return;
|
7066 | }
|
7067 | if (data.distance !== undefined) {
|
7068 | this.distance = data.distance;
|
7069 | }
|
7070 | this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
|
7071 | }
|
7072 | }
|
7073 | ;
|
7074 |
|
7075 |
|
7076 | function drawGrabLine(context, width, begin, end, colorLine, opacity) {
|
7077 | drawLine(context, begin, end);
|
7078 | context.strokeStyle = getStyleFromRgb(colorLine, opacity);
|
7079 | context.lineWidth = width;
|
7080 | context.stroke();
|
7081 | }
|
7082 | function drawGrab(container, particle, lineColor, opacity, mousePos) {
|
7083 | container.canvas.draw(ctx => {
|
7084 | var _a;
|
7085 | const beginPos = particle.getPosition();
|
7086 | drawGrabLine(ctx, (_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0, beginPos, mousePos, lineColor, opacity);
|
7087 | });
|
7088 | }
|
7089 | class Grabber extends ExternalInteractorBase {
|
7090 | constructor(container) {
|
7091 | super(container);
|
7092 | }
|
7093 | clear() {}
|
7094 | init() {
|
7095 | const container = this.container,
|
7096 | grab = container.actualOptions.interactivity.modes.grab;
|
7097 | if (!grab) {
|
7098 | return;
|
7099 | }
|
7100 | container.retina.grabModeDistance = grab.distance * container.retina.pixelRatio;
|
7101 | }
|
7102 | async interact() {
|
7103 | var _a, _b;
|
7104 | const container = this.container,
|
7105 | options = container.actualOptions,
|
7106 | interactivity = options.interactivity;
|
7107 | if (!interactivity.modes.grab || !interactivity.events.onHover.enable || container.interactivity.status !== mouseMoveEvent) {
|
7108 | return;
|
7109 | }
|
7110 | const mousePos = container.interactivity.mouse.position;
|
7111 | if (!mousePos) {
|
7112 | return;
|
7113 | }
|
7114 | const distance = container.retina.grabModeDistance;
|
7115 | if (!distance || distance < 0) {
|
7116 | return;
|
7117 | }
|
7118 | const query = container.particles.quadTree.queryCircle(mousePos, distance, p => this.isEnabled(p));
|
7119 | for (const particle of query) {
|
7120 | const pos = particle.getPosition(),
|
7121 | pointDistance = getDistance(pos, mousePos);
|
7122 | if (pointDistance > distance) {
|
7123 | continue;
|
7124 | }
|
7125 | const grabLineOptions = interactivity.modes.grab.links,
|
7126 | lineOpacity = grabLineOptions.opacity,
|
7127 | opacityLine = lineOpacity - pointDistance * lineOpacity / distance;
|
7128 | if (opacityLine <= 0) {
|
7129 | continue;
|
7130 | }
|
7131 | const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : (_b = particle.options.links) === null || _b === void 0 ? void 0 : _b.color;
|
7132 | if (!container.particles.grabLineColor && optColor) {
|
7133 | const linksOptions = interactivity.modes.grab.links;
|
7134 | container.particles.grabLineColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
|
7135 | }
|
7136 | const colorLine = getLinkColor(particle, undefined, container.particles.grabLineColor);
|
7137 | if (!colorLine) {
|
7138 | return;
|
7139 | }
|
7140 | drawGrab(container, particle, colorLine, opacityLine, mousePos);
|
7141 | }
|
7142 | }
|
7143 | isEnabled(particle) {
|
7144 | var _a;
|
7145 | const container = this.container,
|
7146 | mouse = container.interactivity.mouse,
|
7147 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
7148 | return events.onHover.enable && !!mouse.position && isInArray("grab", events.onHover.mode);
|
7149 | }
|
7150 | loadModeOptions(options, ...sources) {
|
7151 | if (!options.grab) {
|
7152 | options.grab = new Grab();
|
7153 | }
|
7154 | for (const source of sources) {
|
7155 | options.grab.load(source === null || source === void 0 ? void 0 : source.grab);
|
7156 | }
|
7157 | }
|
7158 | reset() {}
|
7159 | }
|
7160 | ;
|
7161 |
|
7162 | async function loadExternalGrabInteraction(engine) {
|
7163 | await engine.addInteractor("externalGrab", container => new Grabber(container));
|
7164 | }
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 | ;
|
7170 |
|
7171 | class Pauser extends ExternalInteractorBase {
|
7172 | constructor(container) {
|
7173 | super(container);
|
7174 | this.handleClickMode = mode => {
|
7175 | if (mode !== "pause") {
|
7176 | return;
|
7177 | }
|
7178 | const container = this.container;
|
7179 | if (container.getAnimationStatus()) {
|
7180 | container.pause();
|
7181 | } else {
|
7182 | container.play();
|
7183 | }
|
7184 | };
|
7185 | }
|
7186 | clear() {}
|
7187 | init() {}
|
7188 | async interact() {}
|
7189 | isEnabled() {
|
7190 | return true;
|
7191 | }
|
7192 | reset() {}
|
7193 | }
|
7194 | ;
|
7195 |
|
7196 | function loadExternalPauseInteraction(engine) {
|
7197 | engine.addInteractor("externalPause", container => new Pauser(container));
|
7198 | }
|
7199 | ;
|
7200 | class Push {
|
7201 | constructor() {
|
7202 | this.default = true;
|
7203 | this.groups = [];
|
7204 | this.quantity = 4;
|
7205 | }
|
7206 | get particles_nb() {
|
7207 | return this.quantity;
|
7208 | }
|
7209 | set particles_nb(value) {
|
7210 | this.quantity = value;
|
7211 | }
|
7212 | load(data) {
|
7213 | var _a;
|
7214 | if (!data) {
|
7215 | return;
|
7216 | }
|
7217 | if (data.default !== undefined) {
|
7218 | this.default = data.default;
|
7219 | }
|
7220 | if (data.groups !== undefined) {
|
7221 | this.groups = data.groups.map(t => t);
|
7222 | }
|
7223 | if (!this.groups.length) {
|
7224 | this.default = true;
|
7225 | }
|
7226 | const quantity = (_a = data.quantity) !== null && _a !== void 0 ? _a : data.particles_nb;
|
7227 | if (quantity !== undefined) {
|
7228 | this.quantity = quantity;
|
7229 | }
|
7230 | }
|
7231 | }
|
7232 | ;
|
7233 |
|
7234 |
|
7235 |
|
7236 | class Pusher extends ExternalInteractorBase {
|
7237 | constructor(container) {
|
7238 | super(container);
|
7239 | this.handleClickMode = mode => {
|
7240 | if (mode !== "push") {
|
7241 | return;
|
7242 | }
|
7243 | const container = this.container,
|
7244 | options = container.actualOptions,
|
7245 | pushOptions = options.interactivity.modes.push;
|
7246 | if (!pushOptions) {
|
7247 | return;
|
7248 | }
|
7249 | const pushNb = pushOptions.quantity;
|
7250 | if (pushNb <= 0) {
|
7251 | return;
|
7252 | }
|
7253 | const group = itemFromArray([undefined, ...pushOptions.groups]),
|
7254 | groupOptions = group !== undefined ? container.actualOptions.particles.groups[group] : undefined;
|
7255 | container.particles.push(pushNb, container.interactivity.mouse, groupOptions, group);
|
7256 | };
|
7257 | }
|
7258 | clear() {}
|
7259 | init() {}
|
7260 | async interact() {}
|
7261 | isEnabled() {
|
7262 | return true;
|
7263 | }
|
7264 | loadModeOptions(options, ...sources) {
|
7265 | if (!options.push) {
|
7266 | options.push = new Push();
|
7267 | }
|
7268 | for (const source of sources) {
|
7269 | options.push.load(source === null || source === void 0 ? void 0 : source.push);
|
7270 | }
|
7271 | }
|
7272 | reset() {}
|
7273 | }
|
7274 | ;
|
7275 |
|
7276 | async function loadExternalPushInteraction(engine) {
|
7277 | await engine.addInteractor("externalPush", container => new Pusher(container));
|
7278 | }
|
7279 |
|
7280 |
|
7281 | ;
|
7282 | class Remove {
|
7283 | constructor() {
|
7284 | this.quantity = 2;
|
7285 | }
|
7286 | get particles_nb() {
|
7287 | return this.quantity;
|
7288 | }
|
7289 | set particles_nb(value) {
|
7290 | this.quantity = value;
|
7291 | }
|
7292 | load(data) {
|
7293 | var _a;
|
7294 | if (!data) {
|
7295 | return;
|
7296 | }
|
7297 | const quantity = (_a = data.quantity) !== null && _a !== void 0 ? _a : data.particles_nb;
|
7298 | if (quantity !== undefined) {
|
7299 | this.quantity = quantity;
|
7300 | }
|
7301 | }
|
7302 | }
|
7303 | ;
|
7304 |
|
7305 |
|
7306 | class Remover extends ExternalInteractorBase {
|
7307 | constructor(container) {
|
7308 | super(container);
|
7309 | this.handleClickMode = mode => {
|
7310 | const container = this.container,
|
7311 | options = container.actualOptions;
|
7312 | if (!options.interactivity.modes.remove || mode !== "remove") {
|
7313 | return;
|
7314 | }
|
7315 | const removeNb = options.interactivity.modes.remove.quantity;
|
7316 | container.particles.removeQuantity(removeNb);
|
7317 | };
|
7318 | }
|
7319 | clear() {}
|
7320 | init() {}
|
7321 | async interact() {}
|
7322 | isEnabled() {
|
7323 | return true;
|
7324 | }
|
7325 | loadModeOptions(options, ...sources) {
|
7326 | if (!options.remove) {
|
7327 | options.remove = new Remove();
|
7328 | }
|
7329 | for (const source of sources) {
|
7330 | options.remove.load(source === null || source === void 0 ? void 0 : source.remove);
|
7331 | }
|
7332 | }
|
7333 | reset() {}
|
7334 | }
|
7335 | ;
|
7336 |
|
7337 | function loadExternalRemoveInteraction(engine) {
|
7338 | engine.addInteractor("externalRemove", container => new Remover(container));
|
7339 | }
|
7340 |
|
7341 |
|
7342 | ;
|
7343 | class RepulseBase {
|
7344 | constructor() {
|
7345 | this.distance = 200;
|
7346 | this.duration = 0.4;
|
7347 | this.factor = 100;
|
7348 | this.speed = 1;
|
7349 | this.maxSpeed = 50;
|
7350 | this.easing = "ease-out-quad";
|
7351 | }
|
7352 | load(data) {
|
7353 | if (!data) {
|
7354 | return;
|
7355 | }
|
7356 | if (data.distance !== undefined) {
|
7357 | this.distance = data.distance;
|
7358 | }
|
7359 | if (data.duration !== undefined) {
|
7360 | this.duration = data.duration;
|
7361 | }
|
7362 | if (data.easing !== undefined) {
|
7363 | this.easing = data.easing;
|
7364 | }
|
7365 | if (data.factor !== undefined) {
|
7366 | this.factor = data.factor;
|
7367 | }
|
7368 | if (data.speed !== undefined) {
|
7369 | this.speed = data.speed;
|
7370 | }
|
7371 | if (data.maxSpeed !== undefined) {
|
7372 | this.maxSpeed = data.maxSpeed;
|
7373 | }
|
7374 | }
|
7375 | }
|
7376 | ;
|
7377 |
|
7378 |
|
7379 | class RepulseDiv extends RepulseBase {
|
7380 | constructor() {
|
7381 | super();
|
7382 | this.selectors = [];
|
7383 | }
|
7384 | get ids() {
|
7385 | return executeOnSingleOrMultiple(this.selectors, t => t.replace("#", ""));
|
7386 | }
|
7387 | set ids(value) {
|
7388 | this.selectors = executeOnSingleOrMultiple(value, t => `#${t}`);
|
7389 | }
|
7390 | load(data) {
|
7391 | super.load(data);
|
7392 | if (!data) {
|
7393 | return;
|
7394 | }
|
7395 | if (data.ids !== undefined) {
|
7396 | this.ids = data.ids;
|
7397 | }
|
7398 | if (data.selectors !== undefined) {
|
7399 | this.selectors = data.selectors;
|
7400 | }
|
7401 | }
|
7402 | }
|
7403 | ;
|
7404 |
|
7405 |
|
7406 |
|
7407 | class Repulse extends RepulseBase {
|
7408 | load(data) {
|
7409 | super.load(data);
|
7410 | if (!data) {
|
7411 | return;
|
7412 | }
|
7413 | this.divs = executeOnSingleOrMultiple(data.divs, div => {
|
7414 | const tmp = new RepulseDiv();
|
7415 | tmp.load(div);
|
7416 | return tmp;
|
7417 | });
|
7418 | }
|
7419 | }
|
7420 | ;
|
7421 |
|
7422 |
|
7423 | class Repulser extends ExternalInteractorBase {
|
7424 | constructor(engine, container) {
|
7425 | super(container);
|
7426 | this._engine = engine;
|
7427 | if (!container.repulse) {
|
7428 | container.repulse = {
|
7429 | particles: []
|
7430 | };
|
7431 | }
|
7432 | this.handleClickMode = mode => {
|
7433 | const options = this.container.actualOptions,
|
7434 | repulse = options.interactivity.modes.repulse;
|
7435 | if (!repulse || mode !== "repulse") {
|
7436 | return;
|
7437 | }
|
7438 | if (!container.repulse) {
|
7439 | container.repulse = {
|
7440 | particles: []
|
7441 | };
|
7442 | }
|
7443 | container.repulse.clicking = true;
|
7444 | container.repulse.count = 0;
|
7445 | for (const particle of container.repulse.particles) {
|
7446 | if (!this.isEnabled(particle)) {
|
7447 | continue;
|
7448 | }
|
7449 | particle.velocity.setTo(particle.initialVelocity);
|
7450 | }
|
7451 | container.repulse.particles = [];
|
7452 | container.repulse.finish = false;
|
7453 | setTimeout(() => {
|
7454 | if (!container.destroyed) {
|
7455 | if (!container.repulse) {
|
7456 | container.repulse = {
|
7457 | particles: []
|
7458 | };
|
7459 | }
|
7460 | container.repulse.clicking = false;
|
7461 | }
|
7462 | }, repulse.duration * 1000);
|
7463 | };
|
7464 | }
|
7465 | clear() {}
|
7466 | init() {
|
7467 | const container = this.container,
|
7468 | repulse = container.actualOptions.interactivity.modes.repulse;
|
7469 | if (!repulse) {
|
7470 | return;
|
7471 | }
|
7472 | container.retina.repulseModeDistance = repulse.distance * container.retina.pixelRatio;
|
7473 | }
|
7474 | async interact() {
|
7475 | const container = this.container,
|
7476 | options = container.actualOptions,
|
7477 | mouseMoveStatus = container.interactivity.status === mouseMoveEvent,
|
7478 | events = options.interactivity.events,
|
7479 | hoverEnabled = events.onHover.enable,
|
7480 | hoverMode = events.onHover.mode,
|
7481 | clickEnabled = events.onClick.enable,
|
7482 | clickMode = events.onClick.mode,
|
7483 | divs = events.onDiv;
|
7484 | if (mouseMoveStatus && hoverEnabled && isInArray("repulse", hoverMode)) {
|
7485 | this.hoverRepulse();
|
7486 | } else if (clickEnabled && isInArray("repulse", clickMode)) {
|
7487 | this.clickRepulse();
|
7488 | } else {
|
7489 | divModeExecute("repulse", divs, (selector, div) => this.singleSelectorRepulse(selector, div));
|
7490 | }
|
7491 | }
|
7492 | isEnabled(particle) {
|
7493 | var _a;
|
7494 | const container = this.container,
|
7495 | options = container.actualOptions,
|
7496 | mouse = container.interactivity.mouse,
|
7497 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : options.interactivity).events,
|
7498 | divs = events.onDiv,
|
7499 | divRepulse = isDivModeEnabled("repulse", divs);
|
7500 | if (!(divRepulse || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
|
7501 | return false;
|
7502 | }
|
7503 | const hoverMode = events.onHover.mode,
|
7504 | clickMode = events.onClick.mode;
|
7505 | return isInArray("repulse", hoverMode) || isInArray("repulse", clickMode) || divRepulse;
|
7506 | }
|
7507 | loadModeOptions(options, ...sources) {
|
7508 | if (!options.repulse) {
|
7509 | options.repulse = new Repulse();
|
7510 | }
|
7511 | for (const source of sources) {
|
7512 | options.repulse.load(source === null || source === void 0 ? void 0 : source.repulse);
|
7513 | }
|
7514 | }
|
7515 | reset() {}
|
7516 | clickRepulse() {
|
7517 | const container = this.container,
|
7518 | repulse = container.actualOptions.interactivity.modes.repulse;
|
7519 | if (!repulse) {
|
7520 | return;
|
7521 | }
|
7522 | if (!container.repulse) {
|
7523 | container.repulse = {
|
7524 | particles: []
|
7525 | };
|
7526 | }
|
7527 | if (!container.repulse.finish) {
|
7528 | if (!container.repulse.count) {
|
7529 | container.repulse.count = 0;
|
7530 | }
|
7531 | container.repulse.count++;
|
7532 | if (container.repulse.count === container.particles.count) {
|
7533 | container.repulse.finish = true;
|
7534 | }
|
7535 | }
|
7536 | if (container.repulse.clicking) {
|
7537 | const repulseDistance = container.retina.repulseModeDistance;
|
7538 | if (!repulseDistance || repulseDistance < 0) {
|
7539 | return;
|
7540 | }
|
7541 | const repulseRadius = Math.pow(repulseDistance / 6, 3),
|
7542 | mouseClickPos = container.interactivity.mouse.clickPosition;
|
7543 | if (mouseClickPos === undefined) {
|
7544 | return;
|
7545 | }
|
7546 | const range = new Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius),
|
7547 | query = container.particles.quadTree.query(range, p => this.isEnabled(p));
|
7548 | for (const particle of query) {
|
7549 | const {
|
7550 | dx,
|
7551 | dy,
|
7552 | distance
|
7553 | } = getDistances(mouseClickPos, particle.position),
|
7554 | d = distance ** 2,
|
7555 | velocity = repulse.speed,
|
7556 | force = -repulseRadius * velocity / d;
|
7557 | if (d <= repulseRadius) {
|
7558 | container.repulse.particles.push(particle);
|
7559 | const vect = Vector.create(dx, dy);
|
7560 | vect.length = force;
|
7561 | particle.velocity.setTo(vect);
|
7562 | }
|
7563 | }
|
7564 | } else if (container.repulse.clicking === false) {
|
7565 | for (const particle of container.repulse.particles) {
|
7566 | particle.velocity.setTo(particle.initialVelocity);
|
7567 | }
|
7568 | container.repulse.particles = [];
|
7569 | }
|
7570 | }
|
7571 | hoverRepulse() {
|
7572 | const container = this.container,
|
7573 | mousePos = container.interactivity.mouse.position,
|
7574 | repulseRadius = container.retina.repulseModeDistance;
|
7575 | if (!repulseRadius || repulseRadius < 0 || !mousePos) {
|
7576 | return;
|
7577 | }
|
7578 | this.processRepulse(mousePos, repulseRadius, new Circle(mousePos.x, mousePos.y, repulseRadius));
|
7579 | }
|
7580 | processRepulse(position, repulseRadius, area, divRepulse) {
|
7581 | var _a;
|
7582 | const container = this.container,
|
7583 | query = container.particles.quadTree.query(area, p => this.isEnabled(p)),
|
7584 | repulseOptions = container.actualOptions.interactivity.modes.repulse;
|
7585 | if (!repulseOptions) {
|
7586 | return;
|
7587 | }
|
7588 | for (const particle of query) {
|
7589 | const {
|
7590 | dx,
|
7591 | dy,
|
7592 | distance
|
7593 | } = getDistances(particle.position, position),
|
7594 | velocity = ((_a = divRepulse === null || divRepulse === void 0 ? void 0 : divRepulse.speed) !== null && _a !== void 0 ? _a : repulseOptions.speed) * repulseOptions.factor,
|
7595 | repulseFactor = clamp(getEasing(repulseOptions.easing)(1 - distance / repulseRadius) * velocity, 0, repulseOptions.maxSpeed),
|
7596 | normVec = Vector.create(distance === 0 ? velocity : dx / distance * repulseFactor, distance === 0 ? velocity : dy / distance * repulseFactor);
|
7597 | particle.position.addTo(normVec);
|
7598 | }
|
7599 | }
|
7600 | singleSelectorRepulse(selector, div) {
|
7601 | const container = this.container,
|
7602 | repulse = container.actualOptions.interactivity.modes.repulse;
|
7603 | if (!repulse) {
|
7604 | return;
|
7605 | }
|
7606 | const query = document.querySelectorAll(selector);
|
7607 | if (!query.length) {
|
7608 | return;
|
7609 | }
|
7610 | query.forEach(item => {
|
7611 | const elem = item,
|
7612 | pxRatio = container.retina.pixelRatio,
|
7613 | pos = {
|
7614 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
7615 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
7616 | },
|
7617 | repulseRadius = elem.offsetWidth / 2 * pxRatio,
|
7618 | area = div.type === "circle" ? new Circle(pos.x, pos.y, repulseRadius) : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio),
|
7619 | divs = repulse.divs,
|
7620 | divRepulse = divMode(divs, elem);
|
7621 | this.processRepulse(pos, repulseRadius, area, divRepulse);
|
7622 | });
|
7623 | }
|
7624 | }
|
7625 | ;
|
7626 |
|
7627 | async function loadExternalRepulseInteraction(engine) {
|
7628 | await engine.addInteractor("externalRepulse", container => new Repulser(engine, container));
|
7629 | }
|
7630 |
|
7631 |
|
7632 |
|
7633 |
|
7634 |
|
7635 |
|
7636 | ;
|
7637 | class Slow {
|
7638 | constructor() {
|
7639 | this.factor = 3;
|
7640 | this.radius = 200;
|
7641 | }
|
7642 | load(data) {
|
7643 | if (!data) {
|
7644 | return;
|
7645 | }
|
7646 | if (data.factor !== undefined) {
|
7647 | this.factor = data.factor;
|
7648 | }
|
7649 | if (data.radius !== undefined) {
|
7650 | this.radius = data.radius;
|
7651 | }
|
7652 | }
|
7653 | }
|
7654 | ;
|
7655 |
|
7656 |
|
7657 | class Slower extends ExternalInteractorBase {
|
7658 | constructor(container) {
|
7659 | super(container);
|
7660 | }
|
7661 | clear(particle, delta, force) {
|
7662 | if (particle.slow.inRange && !force) {
|
7663 | return;
|
7664 | }
|
7665 | particle.slow.factor = 1;
|
7666 | }
|
7667 | init() {
|
7668 | const container = this.container,
|
7669 | slow = container.actualOptions.interactivity.modes.slow;
|
7670 | if (!slow) {
|
7671 | return;
|
7672 | }
|
7673 | container.retina.slowModeRadius = slow.radius * container.retina.pixelRatio;
|
7674 | }
|
7675 | async interact() {}
|
7676 | isEnabled(particle) {
|
7677 | var _a;
|
7678 | const container = this.container,
|
7679 | mouse = container.interactivity.mouse,
|
7680 | events = ((_a = particle === null || particle === void 0 ? void 0 : particle.interactivity) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity).events;
|
7681 | return events.onHover.enable && !!mouse.position && isInArray("slow", events.onHover.mode);
|
7682 | }
|
7683 | loadModeOptions(options, ...sources) {
|
7684 | if (!options.slow) {
|
7685 | options.slow = new Slow();
|
7686 | }
|
7687 | for (const source of sources) {
|
7688 | options.slow.load(source === null || source === void 0 ? void 0 : source.slow);
|
7689 | }
|
7690 | }
|
7691 | reset(particle) {
|
7692 | particle.slow.inRange = false;
|
7693 | const container = this.container,
|
7694 | options = container.actualOptions,
|
7695 | mousePos = container.interactivity.mouse.position,
|
7696 | radius = container.retina.slowModeRadius,
|
7697 | slow = options.interactivity.modes.slow;
|
7698 | if (!slow || !radius || radius < 0 || !mousePos) {
|
7699 | return;
|
7700 | }
|
7701 | const particlePos = particle.getPosition(),
|
7702 | dist = getDistance(mousePos, particlePos),
|
7703 | proximityFactor = dist / radius,
|
7704 | slowFactor = slow.factor;
|
7705 | if (dist <= radius) {
|
7706 | particle.slow.inRange = true;
|
7707 | particle.slow.factor = proximityFactor / slowFactor;
|
7708 | }
|
7709 | }
|
7710 | }
|
7711 | ;
|
7712 |
|
7713 | async function loadExternalSlowInteraction(engine) {
|
7714 | await engine.addInteractor("externalSlow", container => new Slower(container));
|
7715 | }
|
7716 |
|
7717 |
|
7718 | ;
|
7719 |
|
7720 | const currentColorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d.]+%?\))|currentcolor/gi;
|
7721 | function replaceColorSvg(imageShape, color, opacity) {
|
7722 | const {
|
7723 | svgData
|
7724 | } = imageShape;
|
7725 | if (!svgData) {
|
7726 | return "";
|
7727 | }
|
7728 | const colorStyle = getStyleFromHsl(color, opacity);
|
7729 | if (svgData.includes("fill")) {
|
7730 | return svgData.replace(currentColorRegex, () => colorStyle);
|
7731 | }
|
7732 | const preFillIndex = svgData.indexOf(">");
|
7733 | return `${svgData.substring(0, preFillIndex)} fill="${colorStyle}"${svgData.substring(preFillIndex)}`;
|
7734 | }
|
7735 | async function loadImage(image) {
|
7736 | return new Promise(resolve => {
|
7737 | image.loading = true;
|
7738 | const img = new Image();
|
7739 | image.element = img;
|
7740 | img.addEventListener("load", () => {
|
7741 | image.loading = false;
|
7742 | resolve();
|
7743 | });
|
7744 | img.addEventListener("error", () => {
|
7745 | image.element = undefined;
|
7746 | image.error = true;
|
7747 | image.loading = false;
|
7748 | console.error(`Error tsParticles - loading image: ${image.source}`);
|
7749 | resolve();
|
7750 | });
|
7751 | img.src = image.source;
|
7752 | });
|
7753 | }
|
7754 | async function downloadSvgImage(image) {
|
7755 | if (image.type !== "svg") {
|
7756 | await loadImage(image);
|
7757 | return;
|
7758 | }
|
7759 | image.loading = true;
|
7760 | const response = await fetch(image.source);
|
7761 | if (!response.ok) {
|
7762 | console.error("Error tsParticles - Image not found");
|
7763 | image.error = true;
|
7764 | }
|
7765 | if (!image.error) {
|
7766 | image.svgData = await response.text();
|
7767 | }
|
7768 | image.loading = false;
|
7769 | }
|
7770 | function replaceImageColor(image, imageData, color, particle) {
|
7771 | var _a, _b, _c;
|
7772 | const svgColoredData = replaceColorSvg(image, color, (_b = (_a = particle.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : 1),
|
7773 | imageRes = {
|
7774 | color,
|
7775 | data: Object.assign(Object.assign({}, image), {
|
7776 | svgData: svgColoredData
|
7777 | }),
|
7778 | loaded: false,
|
7779 | ratio: imageData.width / imageData.height,
|
7780 | replaceColor: (_c = imageData.replaceColor) !== null && _c !== void 0 ? _c : imageData.replace_color,
|
7781 | source: imageData.src
|
7782 | };
|
7783 | return new Promise(resolve => {
|
7784 | const svg = new Blob([svgColoredData], {
|
7785 | type: "image/svg+xml"
|
7786 | }),
|
7787 | domUrl = URL || window.URL || window.webkitURL || window,
|
7788 | url = domUrl.createObjectURL(svg),
|
7789 | img = new Image();
|
7790 | img.addEventListener("load", () => {
|
7791 | imageRes.loaded = true;
|
7792 | imageRes.element = img;
|
7793 | resolve(imageRes);
|
7794 | domUrl.revokeObjectURL(url);
|
7795 | });
|
7796 | img.addEventListener("error", async () => {
|
7797 | domUrl.revokeObjectURL(url);
|
7798 | const img2 = Object.assign(Object.assign({}, image), {
|
7799 | error: false,
|
7800 | loading: true
|
7801 | });
|
7802 | await loadImage(img2);
|
7803 | imageRes.loaded = true;
|
7804 | imageRes.element = img2.element;
|
7805 | resolve(imageRes);
|
7806 | });
|
7807 | img.src = url;
|
7808 | });
|
7809 | }
|
7810 | ;
|
7811 |
|
7812 | class ImageDrawer {
|
7813 | constructor() {
|
7814 | this._images = [];
|
7815 | }
|
7816 | addImage(container, image) {
|
7817 | const containerImages = this.getImages(container);
|
7818 | containerImages === null || containerImages === void 0 ? void 0 : containerImages.images.push(image);
|
7819 | }
|
7820 | destroy() {
|
7821 | this._images = [];
|
7822 | }
|
7823 | draw(context, particle, radius, opacity) {
|
7824 | var _a;
|
7825 | const image = particle.image,
|
7826 | element = image === null || image === void 0 ? void 0 : image.element;
|
7827 | if (!element) {
|
7828 | return;
|
7829 | }
|
7830 | const ratio = (_a = image === null || image === void 0 ? void 0 : image.ratio) !== null && _a !== void 0 ? _a : 1,
|
7831 | pos = {
|
7832 | x: -radius,
|
7833 | y: -radius
|
7834 | };
|
7835 | context.globalAlpha = opacity;
|
7836 | context.drawImage(element, pos.x, pos.y, radius * 2, radius * 2 / ratio);
|
7837 | context.globalAlpha = 1;
|
7838 | }
|
7839 | getImages(container) {
|
7840 | const containerImages = this._images.find(t => t.id === container.id);
|
7841 | if (!containerImages) {
|
7842 | this._images.push({
|
7843 | id: container.id,
|
7844 | images: []
|
7845 | });
|
7846 | return this.getImages(container);
|
7847 | } else {
|
7848 | return containerImages;
|
7849 | }
|
7850 | }
|
7851 | getSidesCount() {
|
7852 | return 12;
|
7853 | }
|
7854 | loadShape(particle) {
|
7855 | if (particle.shape !== "image" && particle.shape !== "images") {
|
7856 | return;
|
7857 | }
|
7858 | const container = particle.container,
|
7859 | images = this.getImages(container).images,
|
7860 | imageData = particle.shapeData,
|
7861 | image = images.find(t => t.source === imageData.src);
|
7862 | if (!image) {
|
7863 | this.loadImageShape(container, imageData).then(() => {
|
7864 | this.loadShape(particle);
|
7865 | });
|
7866 | }
|
7867 | }
|
7868 | particleInit(container, particle) {
|
7869 | var _a;
|
7870 | if (particle.shape !== "image" && particle.shape !== "images") {
|
7871 | return;
|
7872 | }
|
7873 | const images = this.getImages(container).images,
|
7874 | imageData = particle.shapeData,
|
7875 | color = particle.getFillColor(),
|
7876 | replaceColor = (_a = imageData.replaceColor) !== null && _a !== void 0 ? _a : imageData.replace_color,
|
7877 | image = images.find(t => t.source === imageData.src);
|
7878 | if (!image) {
|
7879 | return;
|
7880 | }
|
7881 | if (image.loading) {
|
7882 | setTimeout(() => {
|
7883 | this.particleInit(container, particle);
|
7884 | });
|
7885 | return;
|
7886 | }
|
7887 | (async () => {
|
7888 | var _a, _b;
|
7889 | let imageRes;
|
7890 | if (image.svgData && color) {
|
7891 | imageRes = await replaceImageColor(image, imageData, color, particle);
|
7892 | } else {
|
7893 | imageRes = {
|
7894 | color,
|
7895 | data: image,
|
7896 | element: image.element,
|
7897 | loaded: true,
|
7898 | ratio: imageData.width / imageData.height,
|
7899 | replaceColor: replaceColor,
|
7900 | source: imageData.src
|
7901 | };
|
7902 | }
|
7903 | if (!imageRes.ratio) {
|
7904 | imageRes.ratio = 1;
|
7905 | }
|
7906 | const fill = (_a = imageData.fill) !== null && _a !== void 0 ? _a : particle.fill,
|
7907 | close = (_b = imageData.close) !== null && _b !== void 0 ? _b : particle.close,
|
7908 | imageShape = {
|
7909 | image: imageRes,
|
7910 | fill,
|
7911 | close
|
7912 | };
|
7913 | particle.image = imageShape.image;
|
7914 | particle.fill = imageShape.fill;
|
7915 | particle.close = imageShape.close;
|
7916 | })();
|
7917 | }
|
7918 | async loadImageShape(container, imageShape) {
|
7919 | var _a;
|
7920 | const source = imageShape.src;
|
7921 | if (!source) {
|
7922 | throw new Error("Error tsParticles - No image.src");
|
7923 | }
|
7924 | try {
|
7925 | const image = {
|
7926 | source: source,
|
7927 | type: source.substring(source.length - 3),
|
7928 | error: false,
|
7929 | loading: true
|
7930 | };
|
7931 | this.addImage(container, image);
|
7932 | const imageFunc = ((_a = imageShape.replaceColor) !== null && _a !== void 0 ? _a : imageShape.replace_color) ? downloadSvgImage : loadImage;
|
7933 | await imageFunc(image);
|
7934 | } catch (_b) {
|
7935 | throw new Error(`tsParticles error - ${imageShape.src} not found`);
|
7936 | }
|
7937 | }
|
7938 | }
|
7939 | ;
|
7940 |
|
7941 | async function loadImageShape(engine) {
|
7942 | await engine.addShape(["image", "images"], new ImageDrawer());
|
7943 | }
|
7944 | ;
|
7945 |
|
7946 | class LifeDelay extends ValueWithRandom {
|
7947 | constructor() {
|
7948 | super();
|
7949 | this.sync = false;
|
7950 | }
|
7951 | load(data) {
|
7952 | if (!data) {
|
7953 | return;
|
7954 | }
|
7955 | super.load(data);
|
7956 | if (data.sync !== undefined) {
|
7957 | this.sync = data.sync;
|
7958 | }
|
7959 | }
|
7960 | }
|
7961 | ;
|
7962 |
|
7963 | class LifeDuration extends ValueWithRandom {
|
7964 | constructor() {
|
7965 | super();
|
7966 | this.random.minimumValue = 0.0001;
|
7967 | this.sync = false;
|
7968 | }
|
7969 | load(data) {
|
7970 | if (!data) {
|
7971 | return;
|
7972 | }
|
7973 | super.load(data);
|
7974 | if (data.sync !== undefined) {
|
7975 | this.sync = data.sync;
|
7976 | }
|
7977 | }
|
7978 | }
|
7979 | ;
|
7980 |
|
7981 |
|
7982 | class Life {
|
7983 | constructor() {
|
7984 | this.count = 0;
|
7985 | this.delay = new LifeDelay();
|
7986 | this.duration = new LifeDuration();
|
7987 | }
|
7988 | load(data) {
|
7989 | if (!data) {
|
7990 | return;
|
7991 | }
|
7992 | if (data.count !== undefined) {
|
7993 | this.count = data.count;
|
7994 | }
|
7995 | this.delay.load(data.delay);
|
7996 | this.duration.load(data.duration);
|
7997 | }
|
7998 | }
|
7999 | ;
|
8000 |
|
8001 |
|
8002 | class LifeUpdater {
|
8003 | constructor(container) {
|
8004 | this.container = container;
|
8005 | }
|
8006 | init(particle) {
|
8007 | const container = this.container,
|
8008 | particlesOptions = particle.options,
|
8009 | lifeOptions = particlesOptions.life;
|
8010 | if (!lifeOptions) {
|
8011 | return;
|
8012 | }
|
8013 | particle.life = {
|
8014 | delay: container.retina.reduceFactor ? getRangeValue(lifeOptions.delay.value) * (lifeOptions.delay.sync ? 1 : getRandom()) / container.retina.reduceFactor * 1000 : 0,
|
8015 | delayTime: 0,
|
8016 | duration: container.retina.reduceFactor ? getRangeValue(lifeOptions.duration.value) * (lifeOptions.duration.sync ? 1 : getRandom()) / container.retina.reduceFactor * 1000 : 0,
|
8017 | time: 0,
|
8018 | count: lifeOptions.count
|
8019 | };
|
8020 | if (particle.life.duration <= 0) {
|
8021 | particle.life.duration = -1;
|
8022 | }
|
8023 | if (particle.life.count <= 0) {
|
8024 | particle.life.count = -1;
|
8025 | }
|
8026 | if (particle.life) {
|
8027 | particle.spawning = particle.life.delay > 0;
|
8028 | }
|
8029 | }
|
8030 | isEnabled(particle) {
|
8031 | return !particle.destroyed;
|
8032 | }
|
8033 | loadOptions(options, ...sources) {
|
8034 | if (!options.life) {
|
8035 | options.life = new Life();
|
8036 | }
|
8037 | for (const source of sources) {
|
8038 | options.life.load(source === null || source === void 0 ? void 0 : source.life);
|
8039 | }
|
8040 | }
|
8041 | update(particle, delta) {
|
8042 | if (!this.isEnabled(particle) || !particle.life) {
|
8043 | return;
|
8044 | }
|
8045 | const life = particle.life;
|
8046 | let justSpawned = false;
|
8047 | if (particle.spawning) {
|
8048 | life.delayTime += delta.value;
|
8049 | if (life.delayTime >= particle.life.delay) {
|
8050 | justSpawned = true;
|
8051 | particle.spawning = false;
|
8052 | life.delayTime = 0;
|
8053 | life.time = 0;
|
8054 | } else {
|
8055 | return;
|
8056 | }
|
8057 | }
|
8058 | if (life.duration === -1) {
|
8059 | return;
|
8060 | }
|
8061 | if (particle.spawning) {
|
8062 | return;
|
8063 | }
|
8064 | if (justSpawned) {
|
8065 | life.time = 0;
|
8066 | } else {
|
8067 | life.time += delta.value;
|
8068 | }
|
8069 | if (life.time < life.duration) {
|
8070 | return;
|
8071 | }
|
8072 | life.time = 0;
|
8073 | if (particle.life.count > 0) {
|
8074 | particle.life.count--;
|
8075 | }
|
8076 | if (particle.life.count === 0) {
|
8077 | particle.destroy();
|
8078 | return;
|
8079 | }
|
8080 | const canvasSize = this.container.canvas.size,
|
8081 | widthRange = setRangeValue(0, canvasSize.width),
|
8082 | heightRange = setRangeValue(0, canvasSize.width);
|
8083 | particle.position.x = randomInRange(widthRange);
|
8084 | particle.position.y = randomInRange(heightRange);
|
8085 | particle.spawning = true;
|
8086 | life.delayTime = 0;
|
8087 | life.time = 0;
|
8088 | particle.reset();
|
8089 | const lifeOptions = particle.options.life;
|
8090 | if (lifeOptions) {
|
8091 | life.delay = getRangeValue(lifeOptions.delay.value) * 1000;
|
8092 | life.duration = getRangeValue(lifeOptions.duration.value) * 1000;
|
8093 | }
|
8094 | }
|
8095 | }
|
8096 | ;
|
8097 |
|
8098 | async function loadLifeUpdater(engine) {
|
8099 | await engine.addParticleUpdater("life", container => new LifeUpdater(container));
|
8100 | }
|
8101 | ;
|
8102 | class LineDrawer {
|
8103 | draw(context, particle, radius) {
|
8104 | context.moveTo(-radius / 2, 0);
|
8105 | context.lineTo(radius / 2, 0);
|
8106 | }
|
8107 | getSidesCount() {
|
8108 | return 1;
|
8109 | }
|
8110 | }
|
8111 | ;
|
8112 |
|
8113 | async function loadLineShape(engine) {
|
8114 | await engine.addShape("line", new LineDrawer());
|
8115 | }
|
8116 | ;
|
8117 |
|
8118 | function checkDestroy(particle, value, minValue, maxValue) {
|
8119 | switch (particle.options.opacity.animation.destroy) {
|
8120 | case "max":
|
8121 | if (value >= maxValue) {
|
8122 | particle.destroy();
|
8123 | }
|
8124 | break;
|
8125 | case "min":
|
8126 | if (value <= minValue) {
|
8127 | particle.destroy();
|
8128 | }
|
8129 | break;
|
8130 | }
|
8131 | }
|
8132 | function updateOpacity(particle, delta) {
|
8133 | var _a, _b, _c, _d, _e, _f;
|
8134 | if (!particle.opacity) {
|
8135 | return;
|
8136 | }
|
8137 | const minValue = particle.opacity.min,
|
8138 | maxValue = particle.opacity.max,
|
8139 | decay = (_a = particle.opacity.decay) !== null && _a !== void 0 ? _a : 1;
|
8140 | if (particle.destroyed || !particle.opacity.enable || ((_b = particle.opacity.maxLoops) !== null && _b !== void 0 ? _b : 0) > 0 && ((_c = particle.opacity.loops) !== null && _c !== void 0 ? _c : 0) > ((_d = particle.opacity.maxLoops) !== null && _d !== void 0 ? _d : 0)) {
|
8141 | return;
|
8142 | }
|
8143 | switch (particle.opacity.status) {
|
8144 | case "increasing":
|
8145 | if (particle.opacity.value >= maxValue) {
|
8146 | particle.opacity.status = "decreasing";
|
8147 | if (!particle.opacity.loops) {
|
8148 | particle.opacity.loops = 0;
|
8149 | }
|
8150 | particle.opacity.loops++;
|
8151 | } else {
|
8152 | particle.opacity.value += ((_e = particle.opacity.velocity) !== null && _e !== void 0 ? _e : 0) * delta.factor;
|
8153 | }
|
8154 | break;
|
8155 | case "decreasing":
|
8156 | if (particle.opacity.value <= minValue) {
|
8157 | particle.opacity.status = "increasing";
|
8158 | if (!particle.opacity.loops) {
|
8159 | particle.opacity.loops = 0;
|
8160 | }
|
8161 | particle.opacity.loops++;
|
8162 | } else {
|
8163 | particle.opacity.value -= ((_f = particle.opacity.velocity) !== null && _f !== void 0 ? _f : 0) * delta.factor;
|
8164 | }
|
8165 | break;
|
8166 | }
|
8167 | if (particle.opacity.velocity && particle.opacity.decay !== 1) {
|
8168 | particle.opacity.velocity *= decay;
|
8169 | }
|
8170 | checkDestroy(particle, particle.opacity.value, minValue, maxValue);
|
8171 | if (!particle.destroyed) {
|
8172 | particle.opacity.value = clamp(particle.opacity.value, minValue, maxValue);
|
8173 | }
|
8174 | }
|
8175 | class OpacityUpdater {
|
8176 | constructor(container) {
|
8177 | this.container = container;
|
8178 | }
|
8179 | init(particle) {
|
8180 | const opacityOptions = particle.options.opacity;
|
8181 | particle.opacity = {
|
8182 | enable: opacityOptions.animation.enable,
|
8183 | max: getRangeMax(opacityOptions.value),
|
8184 | min: getRangeMin(opacityOptions.value),
|
8185 | value: getRangeValue(opacityOptions.value),
|
8186 | loops: 0,
|
8187 | maxLoops: getRangeValue(opacityOptions.animation.count)
|
8188 | };
|
8189 | const opacityAnimation = opacityOptions.animation;
|
8190 | if (opacityAnimation.enable) {
|
8191 | particle.opacity.decay = 1 - getRangeValue(opacityAnimation.decay);
|
8192 | particle.opacity.status = "increasing";
|
8193 | const opacityRange = opacityOptions.value;
|
8194 | particle.opacity.min = getRangeMin(opacityRange);
|
8195 | particle.opacity.max = getRangeMax(opacityRange);
|
8196 | switch (opacityAnimation.startValue) {
|
8197 | case "min":
|
8198 | particle.opacity.value = particle.opacity.min;
|
8199 | particle.opacity.status = "increasing";
|
8200 | break;
|
8201 | case "random":
|
8202 | particle.opacity.value = randomInRange(particle.opacity);
|
8203 | particle.opacity.status = getRandom() >= 0.5 ? "increasing" : "decreasing";
|
8204 | break;
|
8205 | case "max":
|
8206 | default:
|
8207 | particle.opacity.value = particle.opacity.max;
|
8208 | particle.opacity.status = "decreasing";
|
8209 | break;
|
8210 | }
|
8211 | particle.opacity.velocity = getRangeValue(opacityAnimation.speed) / 100 * this.container.retina.reduceFactor;
|
8212 | if (!opacityAnimation.sync) {
|
8213 | particle.opacity.velocity *= getRandom();
|
8214 | }
|
8215 | }
|
8216 | particle.opacity.initialValue = particle.opacity.value;
|
8217 | }
|
8218 | isEnabled(particle) {
|
8219 | var _a, _b, _c, _d;
|
8220 | return !particle.destroyed && !particle.spawning && !!particle.opacity && particle.opacity.enable && (((_a = particle.opacity.maxLoops) !== null && _a !== void 0 ? _a : 0) <= 0 || ((_b = particle.opacity.maxLoops) !== null && _b !== void 0 ? _b : 0) > 0 && ((_c = particle.opacity.loops) !== null && _c !== void 0 ? _c : 0) < ((_d = particle.opacity.maxLoops) !== null && _d !== void 0 ? _d : 0));
|
8221 | }
|
8222 | reset(particle) {
|
8223 | if (particle.opacity) {
|
8224 | particle.opacity.loops = 0;
|
8225 | }
|
8226 | }
|
8227 | update(particle, delta) {
|
8228 | if (!this.isEnabled(particle)) {
|
8229 | return;
|
8230 | }
|
8231 | updateOpacity(particle, delta);
|
8232 | }
|
8233 | }
|
8234 | ;
|
8235 |
|
8236 | async function loadOpacityUpdater(engine) {
|
8237 | await engine.addParticleUpdater("opacity", container => new OpacityUpdater(container));
|
8238 | }
|
8239 | ;
|
8240 |
|
8241 | function bounceHorizontal(data) {
|
8242 | if (data.outMode !== "bounce" && data.outMode !== "bounce-horizontal" && data.outMode !== "bounceHorizontal" && data.outMode !== "split") {
|
8243 | return;
|
8244 | }
|
8245 | if (data.bounds.right < 0) {
|
8246 | data.particle.position.x = data.size + data.offset.x;
|
8247 | } else if (data.bounds.left > data.canvasSize.width) {
|
8248 | data.particle.position.x = data.canvasSize.width - data.size - data.offset.x;
|
8249 | }
|
8250 | const velocity = data.particle.velocity.x;
|
8251 | let bounced = false;
|
8252 | if (data.direction === "right" && data.bounds.right >= data.canvasSize.width && velocity > 0 || data.direction === "left" && data.bounds.left <= 0 && velocity < 0) {
|
8253 | const newVelocity = getValue(data.particle.options.bounce.horizontal);
|
8254 | data.particle.velocity.x *= -newVelocity;
|
8255 | bounced = true;
|
8256 | }
|
8257 | if (!bounced) {
|
8258 | return;
|
8259 | }
|
8260 | const minPos = data.offset.x + data.size;
|
8261 | if (data.bounds.right >= data.canvasSize.width) {
|
8262 | data.particle.position.x = data.canvasSize.width - minPos;
|
8263 | } else if (data.bounds.left <= 0) {
|
8264 | data.particle.position.x = minPos;
|
8265 | }
|
8266 | if (data.outMode === "split") {
|
8267 | data.particle.destroy();
|
8268 | }
|
8269 | }
|
8270 | function bounceVertical(data) {
|
8271 | if (data.outMode !== "bounce" && data.outMode !== "bounce-vertical" && data.outMode !== "bounceVertical" && data.outMode !== "split") {
|
8272 | return;
|
8273 | }
|
8274 | if (data.bounds.bottom < 0) {
|
8275 | data.particle.position.y = data.size + data.offset.y;
|
8276 | } else if (data.bounds.top > data.canvasSize.height) {
|
8277 | data.particle.position.y = data.canvasSize.height - data.size - data.offset.y;
|
8278 | }
|
8279 | const velocity = data.particle.velocity.y;
|
8280 | let bounced = false;
|
8281 | if (data.direction === "bottom" && data.bounds.bottom >= data.canvasSize.height && velocity > 0 || data.direction === "top" && data.bounds.top <= 0 && velocity < 0) {
|
8282 | const newVelocity = getValue(data.particle.options.bounce.vertical);
|
8283 | data.particle.velocity.y *= -newVelocity;
|
8284 | bounced = true;
|
8285 | }
|
8286 | if (!bounced) {
|
8287 | return;
|
8288 | }
|
8289 | const minPos = data.offset.y + data.size;
|
8290 | if (data.bounds.bottom >= data.canvasSize.height) {
|
8291 | data.particle.position.y = data.canvasSize.height - minPos;
|
8292 | } else if (data.bounds.top <= 0) {
|
8293 | data.particle.position.y = minPos;
|
8294 | }
|
8295 | if (data.outMode === "split") {
|
8296 | data.particle.destroy();
|
8297 | }
|
8298 | }
|
8299 | ;
|
8300 |
|
8301 |
|
8302 | class BounceOutMode {
|
8303 | constructor(container) {
|
8304 | this.container = container;
|
8305 | this.modes = ["bounce", "bounce-vertical", "bounce-horizontal", "bounceVertical", "bounceHorizontal", "split"];
|
8306 | }
|
8307 | update(particle, direction, delta, outMode) {
|
8308 | if (!this.modes.includes(outMode)) {
|
8309 | return;
|
8310 | }
|
8311 | const container = this.container;
|
8312 | let handled = false;
|
8313 | for (const [, plugin] of container.plugins) {
|
8314 | if (plugin.particleBounce !== undefined) {
|
8315 | handled = plugin.particleBounce(particle, delta, direction);
|
8316 | }
|
8317 | if (handled) {
|
8318 | break;
|
8319 | }
|
8320 | }
|
8321 | if (handled) {
|
8322 | return;
|
8323 | }
|
8324 | const pos = particle.getPosition(),
|
8325 | offset = particle.offset,
|
8326 | size = particle.getRadius(),
|
8327 | bounds = calculateBounds(pos, size),
|
8328 | canvasSize = container.canvas.size;
|
8329 | bounceHorizontal({
|
8330 | particle,
|
8331 | outMode,
|
8332 | direction,
|
8333 | bounds,
|
8334 | canvasSize,
|
8335 | offset,
|
8336 | size
|
8337 | });
|
8338 | bounceVertical({
|
8339 | particle,
|
8340 | outMode,
|
8341 | direction,
|
8342 | bounds,
|
8343 | canvasSize,
|
8344 | offset,
|
8345 | size
|
8346 | });
|
8347 | }
|
8348 | }
|
8349 | ;
|
8350 |
|
8351 | class DestroyOutMode {
|
8352 | constructor(container) {
|
8353 | this.container = container;
|
8354 | this.modes = ["destroy"];
|
8355 | }
|
8356 | update(particle, direction, delta, outMode) {
|
8357 | if (!this.modes.includes(outMode)) {
|
8358 | return;
|
8359 | }
|
8360 | const container = this.container;
|
8361 | switch (particle.outType) {
|
8362 | case "normal":
|
8363 | case "outside":
|
8364 | if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
|
8365 | return;
|
8366 | }
|
8367 | break;
|
8368 | case "inside":
|
8369 | {
|
8370 | const {
|
8371 | dx,
|
8372 | dy
|
8373 | } = getDistances(particle.position, particle.moveCenter);
|
8374 | const {
|
8375 | x: vx,
|
8376 | y: vy
|
8377 | } = particle.velocity;
|
8378 | if (vx < 0 && dx > particle.moveCenter.radius || vy < 0 && dy > particle.moveCenter.radius || vx >= 0 && dx < -particle.moveCenter.radius || vy >= 0 && dy < -particle.moveCenter.radius) {
|
8379 | return;
|
8380 | }
|
8381 | break;
|
8382 | }
|
8383 | }
|
8384 | container.particles.remove(particle, undefined, true);
|
8385 | }
|
8386 | }
|
8387 | ;
|
8388 |
|
8389 | class NoneOutMode {
|
8390 | constructor(container) {
|
8391 | this.container = container;
|
8392 | this.modes = ["none"];
|
8393 | }
|
8394 | update(particle, direction, delta, outMode) {
|
8395 | if (!this.modes.includes(outMode)) {
|
8396 | return;
|
8397 | }
|
8398 | if (particle.options.move.distance.horizontal && (direction === "left" || direction === "right") || particle.options.move.distance.vertical && (direction === "top" || direction === "bottom")) {
|
8399 | return;
|
8400 | }
|
8401 | const gravityOptions = particle.options.move.gravity,
|
8402 | container = this.container;
|
8403 | const canvasSize = container.canvas.size;
|
8404 | const pRadius = particle.getRadius();
|
8405 | if (!gravityOptions.enable) {
|
8406 | if (particle.velocity.y > 0 && particle.position.y <= canvasSize.height + pRadius || particle.velocity.y < 0 && particle.position.y >= -pRadius || particle.velocity.x > 0 && particle.position.x <= canvasSize.width + pRadius || particle.velocity.x < 0 && particle.position.x >= -pRadius) {
|
8407 | return;
|
8408 | }
|
8409 | if (!isPointInside(particle.position, container.canvas.size, Vector.origin, pRadius, direction)) {
|
8410 | container.particles.remove(particle);
|
8411 | }
|
8412 | } else {
|
8413 | const position = particle.position;
|
8414 | if (!gravityOptions.inverse && position.y > canvasSize.height + pRadius && direction === "bottom" || gravityOptions.inverse && position.y < -pRadius && direction === "top") {
|
8415 | container.particles.remove(particle);
|
8416 | }
|
8417 | }
|
8418 | }
|
8419 | }
|
8420 | ;
|
8421 |
|
8422 | class OutOutMode {
|
8423 | constructor(container) {
|
8424 | this.container = container;
|
8425 | this.modes = ["out"];
|
8426 | }
|
8427 | update(particle, direction, delta, outMode) {
|
8428 | if (!this.modes.includes(outMode)) {
|
8429 | return;
|
8430 | }
|
8431 | const container = this.container;
|
8432 | switch (particle.outType) {
|
8433 | case "inside":
|
8434 | {
|
8435 | const {
|
8436 | x: vx,
|
8437 | y: vy
|
8438 | } = particle.velocity;
|
8439 | const circVec = Vector.origin;
|
8440 | circVec.length = particle.moveCenter.radius;
|
8441 | circVec.angle = particle.velocity.angle + Math.PI;
|
8442 | circVec.addTo(Vector.create(particle.moveCenter));
|
8443 | const {
|
8444 | dx,
|
8445 | dy
|
8446 | } = getDistances(particle.position, circVec);
|
8447 | if (vx <= 0 && dx >= 0 || vy <= 0 && dy >= 0 || vx >= 0 && dx <= 0 || vy >= 0 && dy <= 0) {
|
8448 | return;
|
8449 | }
|
8450 | particle.position.x = Math.floor(randomInRange({
|
8451 | min: 0,
|
8452 | max: container.canvas.size.width
|
8453 | }));
|
8454 | particle.position.y = Math.floor(randomInRange({
|
8455 | min: 0,
|
8456 | max: container.canvas.size.height
|
8457 | }));
|
8458 | const {
|
8459 | dx: newDx,
|
8460 | dy: newDy
|
8461 | } = getDistances(particle.position, particle.moveCenter);
|
8462 | particle.direction = Math.atan2(-newDy, -newDx);
|
8463 | particle.velocity.angle = particle.direction;
|
8464 | break;
|
8465 | }
|
8466 | default:
|
8467 | {
|
8468 | if (isPointInside(particle.position, container.canvas.size, Vector.origin, particle.getRadius(), direction)) {
|
8469 | return;
|
8470 | }
|
8471 | switch (particle.outType) {
|
8472 | case "outside":
|
8473 | {
|
8474 | particle.position.x = Math.floor(randomInRange({
|
8475 | min: -particle.moveCenter.radius,
|
8476 | max: particle.moveCenter.radius
|
8477 | })) + particle.moveCenter.x;
|
8478 | particle.position.y = Math.floor(randomInRange({
|
8479 | min: -particle.moveCenter.radius,
|
8480 | max: particle.moveCenter.radius
|
8481 | })) + particle.moveCenter.y;
|
8482 | const {
|
8483 | dx,
|
8484 | dy
|
8485 | } = getDistances(particle.position, particle.moveCenter);
|
8486 | if (particle.moveCenter.radius) {
|
8487 | particle.direction = Math.atan2(dy, dx);
|
8488 | particle.velocity.angle = particle.direction;
|
8489 | }
|
8490 | break;
|
8491 | }
|
8492 | case "normal":
|
8493 | {
|
8494 | const wrap = particle.options.move.warp,
|
8495 | canvasSize = container.canvas.size,
|
8496 | newPos = {
|
8497 | bottom: canvasSize.height + particle.getRadius() + particle.offset.y,
|
8498 | left: -particle.getRadius() - particle.offset.x,
|
8499 | right: canvasSize.width + particle.getRadius() + particle.offset.x,
|
8500 | top: -particle.getRadius() - particle.offset.y
|
8501 | },
|
8502 | sizeValue = particle.getRadius(),
|
8503 | nextBounds = calculateBounds(particle.position, sizeValue);
|
8504 | if (direction === "right" && nextBounds.left > canvasSize.width + particle.offset.x) {
|
8505 | particle.position.x = newPos.left;
|
8506 | particle.initialPosition.x = particle.position.x;
|
8507 | if (!wrap) {
|
8508 | particle.position.y = getRandom() * canvasSize.height;
|
8509 | particle.initialPosition.y = particle.position.y;
|
8510 | }
|
8511 | } else if (direction === "left" && nextBounds.right < -particle.offset.x) {
|
8512 | particle.position.x = newPos.right;
|
8513 | particle.initialPosition.x = particle.position.x;
|
8514 | if (!wrap) {
|
8515 | particle.position.y = getRandom() * canvasSize.height;
|
8516 | particle.initialPosition.y = particle.position.y;
|
8517 | }
|
8518 | }
|
8519 | if (direction === "bottom" && nextBounds.top > canvasSize.height + particle.offset.y) {
|
8520 | if (!wrap) {
|
8521 | particle.position.x = getRandom() * canvasSize.width;
|
8522 | particle.initialPosition.x = particle.position.x;
|
8523 | }
|
8524 | particle.position.y = newPos.top;
|
8525 | particle.initialPosition.y = particle.position.y;
|
8526 | } else if (direction === "top" && nextBounds.bottom < -particle.offset.y) {
|
8527 | if (!wrap) {
|
8528 | particle.position.x = getRandom() * canvasSize.width;
|
8529 | particle.initialPosition.x = particle.position.x;
|
8530 | }
|
8531 | particle.position.y = newPos.bottom;
|
8532 | particle.initialPosition.y = particle.position.y;
|
8533 | }
|
8534 | break;
|
8535 | }
|
8536 | }
|
8537 | break;
|
8538 | }
|
8539 | }
|
8540 | }
|
8541 | }
|
8542 | ;
|
8543 |
|
8544 |
|
8545 |
|
8546 |
|
8547 | class OutOfCanvasUpdater {
|
8548 | constructor(container) {
|
8549 | this.container = container;
|
8550 | this.updaters = [new BounceOutMode(container), new DestroyOutMode(container), new OutOutMode(container), new NoneOutMode(container)];
|
8551 | }
|
8552 | init() {}
|
8553 | isEnabled(particle) {
|
8554 | return !particle.destroyed && !particle.spawning;
|
8555 | }
|
8556 | update(particle, delta) {
|
8557 | var _a, _b, _c, _d;
|
8558 | const outModes = particle.options.move.outModes;
|
8559 | this.updateOutMode(particle, delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, "bottom");
|
8560 | this.updateOutMode(particle, delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, "left");
|
8561 | this.updateOutMode(particle, delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, "right");
|
8562 | this.updateOutMode(particle, delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, "top");
|
8563 | }
|
8564 | updateOutMode(particle, delta, outMode, direction) {
|
8565 | for (const updater of this.updaters) {
|
8566 | updater.update(particle, direction, delta, outMode);
|
8567 | }
|
8568 | }
|
8569 | }
|
8570 | ;
|
8571 |
|
8572 | async function loadOutModesUpdater(engine) {
|
8573 | await engine.addParticleUpdater("outModes", container => new OutOfCanvasUpdater(container));
|
8574 | }
|
8575 | ;
|
8576 |
|
8577 | class ParallaxMover {
|
8578 | init() {}
|
8579 | isEnabled(particle) {
|
8580 | return !isSsr() && !particle.destroyed && particle.container.actualOptions.interactivity.events.onHover.parallax.enable;
|
8581 | }
|
8582 | move(particle) {
|
8583 | const container = particle.container,
|
8584 | options = container.actualOptions;
|
8585 | if (isSsr() || !options.interactivity.events.onHover.parallax.enable) {
|
8586 | return;
|
8587 | }
|
8588 | const parallaxForce = options.interactivity.events.onHover.parallax.force,
|
8589 | mousePos = container.interactivity.mouse.position;
|
8590 | if (!mousePos) {
|
8591 | return;
|
8592 | }
|
8593 | const canvasCenter = {
|
8594 | x: container.canvas.size.width / 2,
|
8595 | y: container.canvas.size.height / 2
|
8596 | },
|
8597 | parallaxSmooth = options.interactivity.events.onHover.parallax.smooth,
|
8598 | factor = particle.getRadius() / parallaxForce,
|
8599 | centerDistance = {
|
8600 | x: (mousePos.x - canvasCenter.x) * factor,
|
8601 | y: (mousePos.y - canvasCenter.y) * factor
|
8602 | };
|
8603 | particle.offset.x += (centerDistance.x - particle.offset.x) / parallaxSmooth;
|
8604 | particle.offset.y += (centerDistance.y - particle.offset.y) / parallaxSmooth;
|
8605 | }
|
8606 | }
|
8607 | ;
|
8608 |
|
8609 | async function loadParallaxMover(engine) {
|
8610 | engine.addMover("parallax", () => new ParallaxMover());
|
8611 | }
|
8612 | ;
|
8613 |
|
8614 | class Attractor_Attractor extends ParticlesInteractorBase {
|
8615 | constructor(container) {
|
8616 | super(container);
|
8617 | }
|
8618 | clear() {}
|
8619 | init() {}
|
8620 | async interact(p1) {
|
8621 | var _a;
|
8622 | const container = this.container,
|
8623 | distance = (_a = p1.retina.attractDistance) !== null && _a !== void 0 ? _a : container.retina.attractDistance,
|
8624 | pos1 = p1.getPosition(),
|
8625 | query = container.particles.quadTree.queryCircle(pos1, distance);
|
8626 | for (const p2 of query) {
|
8627 | if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
|
8628 | continue;
|
8629 | }
|
8630 | const pos2 = p2.getPosition(),
|
8631 | {
|
8632 | dx,
|
8633 | dy
|
8634 | } = getDistances(pos1, pos2),
|
8635 | rotate = p1.options.move.attract.rotate,
|
8636 | ax = dx / (rotate.x * 1000),
|
8637 | ay = dy / (rotate.y * 1000),
|
8638 | p1Factor = p2.size.value / p1.size.value,
|
8639 | p2Factor = 1 / p1Factor;
|
8640 | p1.velocity.x -= ax * p1Factor;
|
8641 | p1.velocity.y -= ay * p1Factor;
|
8642 | p2.velocity.x += ax * p2Factor;
|
8643 | p2.velocity.y += ay * p2Factor;
|
8644 | }
|
8645 | }
|
8646 | isEnabled(particle) {
|
8647 | return particle.options.move.attract.enable;
|
8648 | }
|
8649 | reset() {}
|
8650 | }
|
8651 | ;
|
8652 |
|
8653 | async function loadParticlesAttractInteraction(engine) {
|
8654 | await engine.addInteractor("particlesAttract", container => new Attractor_Attractor(container));
|
8655 | }
|
8656 | ;
|
8657 |
|
8658 | function updateAbsorb(p1, r1, p2, r2, delta, pixelRatio) {
|
8659 | const factor = clamp(p1.options.collisions.absorb.speed * delta.factor / 10, 0, r2);
|
8660 | p1.size.value += factor / 2;
|
8661 | p2.size.value -= factor;
|
8662 | if (r2 <= pixelRatio) {
|
8663 | p2.size.value = 0;
|
8664 | p2.destroy();
|
8665 | }
|
8666 | }
|
8667 | function absorb(p1, p2, delta, pixelRatio) {
|
8668 | const r1 = p1.getRadius(),
|
8669 | r2 = p2.getRadius();
|
8670 | if (r1 === undefined && r2 !== undefined) {
|
8671 | p1.destroy();
|
8672 | } else if (r1 !== undefined && r2 === undefined) {
|
8673 | p2.destroy();
|
8674 | } else if (r1 !== undefined && r2 !== undefined) {
|
8675 | if (r1 >= r2) {
|
8676 | updateAbsorb(p1, r1, p2, r2, delta, pixelRatio);
|
8677 | } else {
|
8678 | updateAbsorb(p2, r2, p1, r1, delta, pixelRatio);
|
8679 | }
|
8680 | }
|
8681 | }
|
8682 | ;
|
8683 |
|
8684 | function bounce(p1, p2) {
|
8685 | circleBounce(circleBounceDataFromParticle(p1), circleBounceDataFromParticle(p2));
|
8686 | }
|
8687 | ;
|
8688 |
|
8689 | function destroy(p1, p2) {
|
8690 | if (!p1.unbreakable && !p2.unbreakable) {
|
8691 | bounce(p1, p2);
|
8692 | }
|
8693 | if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
|
8694 | p1.destroy();
|
8695 | } else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
|
8696 | p2.destroy();
|
8697 | } else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
|
8698 | const deleteP = p1.getRadius() >= p2.getRadius() ? p1 : p2;
|
8699 | deleteP.destroy();
|
8700 | }
|
8701 | }
|
8702 | ;
|
8703 |
|
8704 |
|
8705 |
|
8706 | function resolveCollision(p1, p2, delta, pixelRatio) {
|
8707 | switch (p1.options.collisions.mode) {
|
8708 | case "absorb":
|
8709 | {
|
8710 | absorb(p1, p2, delta, pixelRatio);
|
8711 | break;
|
8712 | }
|
8713 | case "bounce":
|
8714 | {
|
8715 | bounce(p1, p2);
|
8716 | break;
|
8717 | }
|
8718 | case "destroy":
|
8719 | {
|
8720 | destroy(p1, p2);
|
8721 | break;
|
8722 | }
|
8723 | }
|
8724 | }
|
8725 | ;
|
8726 |
|
8727 |
|
8728 | class Collider extends ParticlesInteractorBase {
|
8729 | constructor(container) {
|
8730 | super(container);
|
8731 | }
|
8732 | clear() {}
|
8733 | init() {}
|
8734 | async interact(p1, delta) {
|
8735 | const container = this.container,
|
8736 | pos1 = p1.getPosition(),
|
8737 | radius1 = p1.getRadius(),
|
8738 | query = container.particles.quadTree.queryCircle(pos1, radius1 * 2);
|
8739 | for (const p2 of query) {
|
8740 | if (p1 === p2 || !p2.options.collisions.enable || p1.options.collisions.mode !== p2.options.collisions.mode || p2.destroyed || p2.spawning) {
|
8741 | continue;
|
8742 | }
|
8743 | const pos2 = p2.getPosition(),
|
8744 | radius2 = p2.getRadius();
|
8745 | if (Math.abs(Math.round(pos1.z) - Math.round(pos2.z)) > radius1 + radius2) {
|
8746 | continue;
|
8747 | }
|
8748 | const dist = getDistance(pos1, pos2),
|
8749 | distP = radius1 + radius2;
|
8750 | if (dist > distP) {
|
8751 | continue;
|
8752 | }
|
8753 | resolveCollision(p1, p2, delta, container.retina.pixelRatio);
|
8754 | }
|
8755 | }
|
8756 | isEnabled(particle) {
|
8757 | return particle.options.collisions.enable;
|
8758 | }
|
8759 | reset() {}
|
8760 | }
|
8761 | ;
|
8762 |
|
8763 | async function loadParticlesCollisionsInteraction(engine) {
|
8764 | await engine.addInteractor("particlesCollisions", container => new Collider(container));
|
8765 | }
|
8766 | ;
|
8767 |
|
8768 | class CircleWarp extends Circle {
|
8769 | constructor(x, y, radius, canvasSize) {
|
8770 | super(x, y, radius);
|
8771 | this.canvasSize = canvasSize;
|
8772 | this.canvasSize = Object.assign({}, canvasSize);
|
8773 | }
|
8774 | contains(point) {
|
8775 | if (super.contains(point)) {
|
8776 | return true;
|
8777 | }
|
8778 | const posNE = {
|
8779 | x: point.x - this.canvasSize.width,
|
8780 | y: point.y
|
8781 | };
|
8782 | if (super.contains(posNE)) {
|
8783 | return true;
|
8784 | }
|
8785 | const posSE = {
|
8786 | x: point.x - this.canvasSize.width,
|
8787 | y: point.y - this.canvasSize.height
|
8788 | };
|
8789 | if (super.contains(posSE)) {
|
8790 | return true;
|
8791 | }
|
8792 | const posSW = {
|
8793 | x: point.x,
|
8794 | y: point.y - this.canvasSize.height
|
8795 | };
|
8796 | return super.contains(posSW);
|
8797 | }
|
8798 | intersects(range) {
|
8799 | if (super.intersects(range)) {
|
8800 | return true;
|
8801 | }
|
8802 | const rect = range,
|
8803 | circle = range,
|
8804 | newPos = {
|
8805 | x: range.position.x - this.canvasSize.width,
|
8806 | y: range.position.y - this.canvasSize.height
|
8807 | };
|
8808 | if (circle.radius !== undefined) {
|
8809 | const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * 2);
|
8810 | return super.intersects(biggerCircle);
|
8811 | } else if (rect.size !== undefined) {
|
8812 | const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
|
8813 | return super.intersects(rectSW);
|
8814 | }
|
8815 | return false;
|
8816 | }
|
8817 | }
|
8818 | ;
|
8819 |
|
8820 | class LinksShadow {
|
8821 | constructor() {
|
8822 | this.blur = 5;
|
8823 | this.color = new OptionsColor();
|
8824 | this.color.value = "#000";
|
8825 | this.enable = false;
|
8826 | }
|
8827 | load(data) {
|
8828 | if (!data) {
|
8829 | return;
|
8830 | }
|
8831 | if (data.blur !== undefined) {
|
8832 | this.blur = data.blur;
|
8833 | }
|
8834 | this.color = OptionsColor.create(this.color, data.color);
|
8835 | if (data.enable !== undefined) {
|
8836 | this.enable = data.enable;
|
8837 | }
|
8838 | }
|
8839 | }
|
8840 | ;
|
8841 |
|
8842 | class LinksTriangle {
|
8843 | constructor() {
|
8844 | this.enable = false;
|
8845 | this.frequency = 1;
|
8846 | }
|
8847 | load(data) {
|
8848 | if (!data) {
|
8849 | return;
|
8850 | }
|
8851 | if (data.color !== undefined) {
|
8852 | this.color = OptionsColor.create(this.color, data.color);
|
8853 | }
|
8854 | if (data.enable !== undefined) {
|
8855 | this.enable = data.enable;
|
8856 | }
|
8857 | if (data.frequency !== undefined) {
|
8858 | this.frequency = data.frequency;
|
8859 | }
|
8860 | if (data.opacity !== undefined) {
|
8861 | this.opacity = data.opacity;
|
8862 | }
|
8863 | }
|
8864 | }
|
8865 | ;
|
8866 |
|
8867 |
|
8868 |
|
8869 | class Links {
|
8870 | constructor() {
|
8871 | this.blink = false;
|
8872 | this.color = new OptionsColor();
|
8873 | this.color.value = "#fff";
|
8874 | this.consent = false;
|
8875 | this.distance = 100;
|
8876 | this.enable = false;
|
8877 | this.frequency = 1;
|
8878 | this.opacity = 1;
|
8879 | this.shadow = new LinksShadow();
|
8880 | this.triangles = new LinksTriangle();
|
8881 | this.width = 1;
|
8882 | this.warp = false;
|
8883 | }
|
8884 | load(data) {
|
8885 | if (!data) {
|
8886 | return;
|
8887 | }
|
8888 | if (data.id !== undefined) {
|
8889 | this.id = data.id;
|
8890 | }
|
8891 | if (data.blink !== undefined) {
|
8892 | this.blink = data.blink;
|
8893 | }
|
8894 | this.color = OptionsColor.create(this.color, data.color);
|
8895 | if (data.consent !== undefined) {
|
8896 | this.consent = data.consent;
|
8897 | }
|
8898 | if (data.distance !== undefined) {
|
8899 | this.distance = data.distance;
|
8900 | }
|
8901 | if (data.enable !== undefined) {
|
8902 | this.enable = data.enable;
|
8903 | }
|
8904 | if (data.frequency !== undefined) {
|
8905 | this.frequency = data.frequency;
|
8906 | }
|
8907 | if (data.opacity !== undefined) {
|
8908 | this.opacity = data.opacity;
|
8909 | }
|
8910 | this.shadow.load(data.shadow);
|
8911 | this.triangles.load(data.triangles);
|
8912 | if (data.width !== undefined) {
|
8913 | this.width = data.width;
|
8914 | }
|
8915 | if (data.warp !== undefined) {
|
8916 | this.warp = data.warp;
|
8917 | }
|
8918 | }
|
8919 | }
|
8920 | ;
|
8921 |
|
8922 |
|
8923 |
|
8924 | function getLinkDistance(pos1, pos2, optDistance, canvasSize, warp) {
|
8925 | let distance = getDistance(pos1, pos2);
|
8926 | if (!warp || distance <= optDistance) {
|
8927 | return distance;
|
8928 | }
|
8929 | const pos2NE = {
|
8930 | x: pos2.x - canvasSize.width,
|
8931 | y: pos2.y
|
8932 | };
|
8933 | distance = getDistance(pos1, pos2NE);
|
8934 | if (distance <= optDistance) {
|
8935 | return distance;
|
8936 | }
|
8937 | const pos2SE = {
|
8938 | x: pos2.x - canvasSize.width,
|
8939 | y: pos2.y - canvasSize.height
|
8940 | };
|
8941 | distance = getDistance(pos1, pos2SE);
|
8942 | if (distance <= optDistance) {
|
8943 | return distance;
|
8944 | }
|
8945 | const pos2SW = {
|
8946 | x: pos2.x,
|
8947 | y: pos2.y - canvasSize.height
|
8948 | };
|
8949 | distance = getDistance(pos1, pos2SW);
|
8950 | return distance;
|
8951 | }
|
8952 | class Linker extends ParticlesInteractorBase {
|
8953 | constructor(container) {
|
8954 | super(container);
|
8955 | this.linkContainer = container;
|
8956 | }
|
8957 | clear() {}
|
8958 | init() {
|
8959 | this.linkContainer.particles.linksColor = undefined;
|
8960 | this.linkContainer.particles.linksColors = new Map();
|
8961 | }
|
8962 | async interact(p1) {
|
8963 | var _a;
|
8964 | if (!p1.options.links) {
|
8965 | return;
|
8966 | }
|
8967 | p1.links = [];
|
8968 | const pos1 = p1.getPosition(),
|
8969 | container = this.container,
|
8970 | canvasSize = container.canvas.size;
|
8971 | if (pos1.x < 0 || pos1.y < 0 || pos1.x > canvasSize.width || pos1.y > canvasSize.height) {
|
8972 | return;
|
8973 | }
|
8974 | const linkOpt1 = p1.options.links,
|
8975 | optOpacity = linkOpt1.opacity,
|
8976 | optDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0,
|
8977 | warp = linkOpt1.warp,
|
8978 | range = warp ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new Circle(pos1.x, pos1.y, optDistance),
|
8979 | query = container.particles.quadTree.query(range);
|
8980 | for (const p2 of query) {
|
8981 | const linkOpt2 = p2.options.links;
|
8982 | if (p1 === p2 || !(linkOpt2 === null || linkOpt2 === void 0 ? void 0 : linkOpt2.enable) || linkOpt1.id !== linkOpt2.id || p2.spawning || p2.destroyed || !p2.links || p1.links.map(t => t.destination).indexOf(p2) !== -1 || p2.links.map(t => t.destination).indexOf(p1) !== -1) {
|
8983 | continue;
|
8984 | }
|
8985 | const pos2 = p2.getPosition();
|
8986 | if (pos2.x < 0 || pos2.y < 0 || pos2.x > canvasSize.width || pos2.y > canvasSize.height) {
|
8987 | continue;
|
8988 | }
|
8989 | const distance = getLinkDistance(pos1, pos2, optDistance, canvasSize, warp && linkOpt2.warp);
|
8990 | if (distance > optDistance) {
|
8991 | return;
|
8992 | }
|
8993 | const opacityLine = (1 - distance / optDistance) * optOpacity;
|
8994 | this.setColor(p1);
|
8995 | p1.links.push({
|
8996 | destination: p2,
|
8997 | opacity: opacityLine
|
8998 | });
|
8999 | }
|
9000 | }
|
9001 | isEnabled(particle) {
|
9002 | var _a;
|
9003 | return !!((_a = particle.options.links) === null || _a === void 0 ? void 0 : _a.enable);
|
9004 | }
|
9005 | loadParticlesOptions(options, ...sources) {
|
9006 | var _a, _b;
|
9007 | if (!options.links) {
|
9008 | options.links = new Links();
|
9009 | }
|
9010 | for (const source of sources) {
|
9011 | options.links.load((_b = (_a = source === null || source === void 0 ? void 0 : source.links) !== null && _a !== void 0 ? _a : source === null || source === void 0 ? void 0 : source.lineLinked) !== null && _b !== void 0 ? _b : source === null || source === void 0 ? void 0 : source.line_linked);
|
9012 | }
|
9013 | }
|
9014 | reset() {}
|
9015 | setColor(p1) {
|
9016 | if (!p1.options.links) {
|
9017 | return;
|
9018 | }
|
9019 | const container = this.linkContainer,
|
9020 | linksOptions = p1.options.links;
|
9021 | let linkColor = linksOptions.id === undefined ? container.particles.linksColor : container.particles.linksColors.get(linksOptions.id);
|
9022 | if (linkColor) {
|
9023 | return;
|
9024 | }
|
9025 | const optColor = linksOptions.color;
|
9026 | linkColor = getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
|
9027 | if (linksOptions.id === undefined) {
|
9028 | container.particles.linksColor = linkColor;
|
9029 | } else {
|
9030 | container.particles.linksColors.set(linksOptions.id, linkColor);
|
9031 | }
|
9032 | }
|
9033 | }
|
9034 | ;
|
9035 |
|
9036 | async function loadInteraction(engine) {
|
9037 | await engine.addInteractor("particlesLinks", container => new Linker(container));
|
9038 | }
|
9039 | ;
|
9040 |
|
9041 | function drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) {
|
9042 | let drawn = false;
|
9043 | if (getDistance(begin, end) <= maxDistance) {
|
9044 | drawLine(context, begin, end);
|
9045 | drawn = true;
|
9046 | } else if (warp) {
|
9047 | let pi1;
|
9048 | let pi2;
|
9049 | const endNE = {
|
9050 | x: end.x - canvasSize.width,
|
9051 | y: end.y
|
9052 | };
|
9053 | const d1 = getDistances(begin, endNE);
|
9054 | if (d1.distance <= maxDistance) {
|
9055 | const yi = begin.y - d1.dy / d1.dx * begin.x;
|
9056 | pi1 = {
|
9057 | x: 0,
|
9058 | y: yi
|
9059 | };
|
9060 | pi2 = {
|
9061 | x: canvasSize.width,
|
9062 | y: yi
|
9063 | };
|
9064 | } else {
|
9065 | const endSW = {
|
9066 | x: end.x,
|
9067 | y: end.y - canvasSize.height
|
9068 | };
|
9069 | const d2 = getDistances(begin, endSW);
|
9070 | if (d2.distance <= maxDistance) {
|
9071 | const yi = begin.y - d2.dy / d2.dx * begin.x;
|
9072 | const xi = -yi / (d2.dy / d2.dx);
|
9073 | pi1 = {
|
9074 | x: xi,
|
9075 | y: 0
|
9076 | };
|
9077 | pi2 = {
|
9078 | x: xi,
|
9079 | y: canvasSize.height
|
9080 | };
|
9081 | } else {
|
9082 | const endSE = {
|
9083 | x: end.x - canvasSize.width,
|
9084 | y: end.y - canvasSize.height
|
9085 | };
|
9086 | const d3 = getDistances(begin, endSE);
|
9087 | if (d3.distance <= maxDistance) {
|
9088 | const yi = begin.y - d3.dy / d3.dx * begin.x;
|
9089 | const xi = -yi / (d3.dy / d3.dx);
|
9090 | pi1 = {
|
9091 | x: xi,
|
9092 | y: yi
|
9093 | };
|
9094 | pi2 = {
|
9095 | x: pi1.x + canvasSize.width,
|
9096 | y: pi1.y + canvasSize.height
|
9097 | };
|
9098 | }
|
9099 | }
|
9100 | }
|
9101 | if (pi1 && pi2) {
|
9102 | drawLine(context, begin, pi1);
|
9103 | drawLine(context, end, pi2);
|
9104 | drawn = true;
|
9105 | }
|
9106 | }
|
9107 | if (!drawn) {
|
9108 | return;
|
9109 | }
|
9110 | context.lineWidth = width;
|
9111 | if (backgroundMask) {
|
9112 | context.globalCompositeOperation = composite;
|
9113 | }
|
9114 | context.strokeStyle = getStyleFromRgb(colorLine, opacity);
|
9115 | if (shadow.enable) {
|
9116 | const shadowColor = rangeColorToRgb(shadow.color);
|
9117 | if (shadowColor) {
|
9118 | context.shadowBlur = shadow.blur;
|
9119 | context.shadowColor = getStyleFromRgb(shadowColor);
|
9120 | }
|
9121 | }
|
9122 | context.stroke();
|
9123 | }
|
9124 | function drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) {
|
9125 | drawTriangle(context, pos1, pos2, pos3);
|
9126 | if (backgroundMask) {
|
9127 | context.globalCompositeOperation = composite;
|
9128 | }
|
9129 | context.fillStyle = getStyleFromRgb(colorTriangle, opacityTriangle);
|
9130 | context.fill();
|
9131 | }
|
9132 | ;
|
9133 |
|
9134 |
|
9135 | function getLinkKey(ids) {
|
9136 | ids.sort((a, b) => a - b);
|
9137 | return ids.join("_");
|
9138 | }
|
9139 | function setLinkFrequency(particles, dictionary) {
|
9140 | const key = getLinkKey(particles.map(t => t.id));
|
9141 | let res = dictionary.get(key);
|
9142 | if (res === undefined) {
|
9143 | res = getRandom();
|
9144 | dictionary.set(key, res);
|
9145 | }
|
9146 | return res;
|
9147 | }
|
9148 | class LinkInstance {
|
9149 | constructor(container) {
|
9150 | this.container = container;
|
9151 | this._freqs = {
|
9152 | links: new Map(),
|
9153 | triangles: new Map()
|
9154 | };
|
9155 | }
|
9156 | drawParticle(context, particle) {
|
9157 | var _a;
|
9158 | const pOptions = particle.options;
|
9159 | if (!particle.links || particle.links.length <= 0) {
|
9160 | return;
|
9161 | }
|
9162 | const p1Links = particle.links.filter(l => pOptions.links && this.getLinkFrequency(particle, l.destination) <= pOptions.links.frequency);
|
9163 | for (const link of p1Links) {
|
9164 | this.drawTriangles(pOptions, particle, link, p1Links);
|
9165 | if (link.opacity > 0 && ((_a = particle.retina.linksWidth) !== null && _a !== void 0 ? _a : 0) > 0) {
|
9166 | this.drawLinkLine(particle, link);
|
9167 | }
|
9168 | }
|
9169 | }
|
9170 | async init() {
|
9171 | this._freqs.links = new Map();
|
9172 | this._freqs.triangles = new Map();
|
9173 | }
|
9174 | particleCreated(particle) {
|
9175 | particle.links = [];
|
9176 | if (!particle.options.links) {
|
9177 | return;
|
9178 | }
|
9179 | const ratio = this.container.retina.pixelRatio;
|
9180 | particle.retina.linksDistance = particle.options.links.distance * ratio;
|
9181 | particle.retina.linksWidth = particle.options.links.width * ratio;
|
9182 | }
|
9183 | particleDestroyed(particle) {
|
9184 | particle.links = [];
|
9185 | }
|
9186 | drawLinkLine(p1, link) {
|
9187 | const container = this.container,
|
9188 | options = container.actualOptions,
|
9189 | p2 = link.destination,
|
9190 | pos1 = p1.getPosition(),
|
9191 | pos2 = p2.getPosition();
|
9192 | let opacity = link.opacity;
|
9193 | container.canvas.draw(ctx => {
|
9194 | var _a, _b, _c;
|
9195 | if (!p1.options.links) {
|
9196 | return;
|
9197 | }
|
9198 | let colorLine;
|
9199 | const twinkle = (_a = p1.options.twinkle) === null || _a === void 0 ? void 0 : _a.lines;
|
9200 | if (twinkle === null || twinkle === void 0 ? void 0 : twinkle.enable) {
|
9201 | const twinkleFreq = twinkle.frequency,
|
9202 | twinkleRgb = rangeColorToRgb(twinkle.color),
|
9203 | twinkling = getRandom() < twinkleFreq;
|
9204 | if (twinkling && twinkleRgb) {
|
9205 | colorLine = twinkleRgb;
|
9206 | opacity = getRangeValue(twinkle.opacity);
|
9207 | }
|
9208 | }
|
9209 | if (!colorLine) {
|
9210 | const linksOptions = p1.options.links,
|
9211 | linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;
|
9212 | colorLine = getLinkColor(p1, p2, linkColor);
|
9213 | }
|
9214 | if (!colorLine) {
|
9215 | return;
|
9216 | }
|
9217 | const width = (_b = p1.retina.linksWidth) !== null && _b !== void 0 ? _b : 0,
|
9218 | maxDistance = (_c = p1.retina.linksDistance) !== null && _c !== void 0 ? _c : 0;
|
9219 | drawLinkLine(ctx, width, pos1, pos2, maxDistance, container.canvas.size, p1.options.links.warp, options.backgroundMask.enable, options.backgroundMask.composite, colorLine, opacity, p1.options.links.shadow);
|
9220 | });
|
9221 | }
|
9222 | drawLinkTriangle(p1, link1, link2) {
|
9223 | var _a;
|
9224 | if (!p1.options.links) {
|
9225 | return;
|
9226 | }
|
9227 | const container = this.container,
|
9228 | options = container.actualOptions,
|
9229 | p2 = link1.destination,
|
9230 | p3 = link2.destination,
|
9231 | triangleOptions = p1.options.links.triangles,
|
9232 | opacityTriangle = (_a = triangleOptions.opacity) !== null && _a !== void 0 ? _a : (link1.opacity + link2.opacity) / 2;
|
9233 | if (opacityTriangle <= 0) {
|
9234 | return;
|
9235 | }
|
9236 | container.canvas.draw(ctx => {
|
9237 | var _a;
|
9238 | const pos1 = p1.getPosition(),
|
9239 | pos2 = p2.getPosition(),
|
9240 | pos3 = p3.getPosition(),
|
9241 | linksDistance = (_a = p1.retina.linksDistance) !== null && _a !== void 0 ? _a : 0;
|
9242 | if (getDistance(pos1, pos2) > linksDistance || getDistance(pos3, pos2) > linksDistance || getDistance(pos3, pos1) > linksDistance) {
|
9243 | return;
|
9244 | }
|
9245 | let colorTriangle = rangeColorToRgb(triangleOptions.color);
|
9246 | if (!colorTriangle) {
|
9247 | const linksOptions = p1.options.links,
|
9248 | linkColor = (linksOptions === null || linksOptions === void 0 ? void 0 : linksOptions.id) !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;
|
9249 | colorTriangle = getLinkColor(p1, p2, linkColor);
|
9250 | }
|
9251 | if (!colorTriangle) {
|
9252 | return;
|
9253 | }
|
9254 | drawLinkTriangle(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
|
9255 | });
|
9256 | }
|
9257 | drawTriangles(options, p1, link, p1Links) {
|
9258 | var _a, _b, _c;
|
9259 | const p2 = link.destination;
|
9260 | if (!(((_a = options.links) === null || _a === void 0 ? void 0 : _a.triangles.enable) && ((_b = p2.options.links) === null || _b === void 0 ? void 0 : _b.triangles.enable))) {
|
9261 | return;
|
9262 | }
|
9263 | const vertices = (_c = p2.links) === null || _c === void 0 ? void 0 : _c.filter(t => {
|
9264 | const linkFreq = this.getLinkFrequency(p2, t.destination);
|
9265 | return p2.options.links && linkFreq <= p2.options.links.frequency && p1Links.findIndex(l => l.destination === t.destination) >= 0;
|
9266 | });
|
9267 | if (!(vertices === null || vertices === void 0 ? void 0 : vertices.length)) {
|
9268 | return;
|
9269 | }
|
9270 | for (const vertex of vertices) {
|
9271 | const p3 = vertex.destination,
|
9272 | triangleFreq = this.getTriangleFrequency(p1, p2, p3);
|
9273 | if (triangleFreq > options.links.triangles.frequency) {
|
9274 | continue;
|
9275 | }
|
9276 | this.drawLinkTriangle(p1, link, vertex);
|
9277 | }
|
9278 | }
|
9279 | getLinkFrequency(p1, p2) {
|
9280 | return setLinkFrequency([p1, p2], this._freqs.links);
|
9281 | }
|
9282 | getTriangleFrequency(p1, p2, p3) {
|
9283 | return setLinkFrequency([p1, p2, p3], this._freqs.triangles);
|
9284 | }
|
9285 | }
|
9286 | ;
|
9287 |
|
9288 | class LinksPlugin {
|
9289 | constructor() {
|
9290 | this.id = "links";
|
9291 | }
|
9292 | getPlugin(container) {
|
9293 | return new LinkInstance(container);
|
9294 | }
|
9295 | loadOptions() {}
|
9296 | needsPlugin() {
|
9297 | return true;
|
9298 | }
|
9299 | }
|
9300 | async function loadPlugin(engine) {
|
9301 | const plugin = new LinksPlugin();
|
9302 | await engine.addPlugin(plugin);
|
9303 | }
|
9304 | ;
|
9305 |
|
9306 |
|
9307 | async function loadParticlesLinksInteraction(engine) {
|
9308 | await loadInteraction(engine);
|
9309 | await loadPlugin(engine);
|
9310 | }
|
9311 |
|
9312 |
|
9313 |
|
9314 |
|
9315 |
|
9316 |
|
9317 | ;
|
9318 |
|
9319 | class PolygonDrawerBase {
|
9320 | draw(context, particle, radius) {
|
9321 | const start = this.getCenter(particle, radius),
|
9322 | side = this.getSidesData(particle, radius),
|
9323 | sideCount = side.count.numerator * side.count.denominator,
|
9324 | decimalSides = side.count.numerator / side.count.denominator,
|
9325 | interiorAngleDegrees = 180 * (decimalSides - 2) / decimalSides,
|
9326 | interiorAngle = Math.PI - Math.PI * interiorAngleDegrees / 180;
|
9327 | if (!context) {
|
9328 | return;
|
9329 | }
|
9330 | context.beginPath();
|
9331 | context.translate(start.x, start.y);
|
9332 | context.moveTo(0, 0);
|
9333 | for (let i = 0; i < sideCount; i++) {
|
9334 | context.lineTo(side.length, 0);
|
9335 | context.translate(side.length, 0);
|
9336 | context.rotate(interiorAngle);
|
9337 | }
|
9338 | }
|
9339 | getSidesCount(particle) {
|
9340 | var _a, _b;
|
9341 | const polygon = particle.shapeData,
|
9342 | sides = Math.round(getRangeValue((_b = (_a = polygon === null || polygon === void 0 ? void 0 : polygon.sides) !== null && _a !== void 0 ? _a : polygon === null || polygon === void 0 ? void 0 : polygon.nb_sides) !== null && _b !== void 0 ? _b : 5));
|
9343 | return sides;
|
9344 | }
|
9345 | }
|
9346 | ;
|
9347 |
|
9348 | class PolygonDrawer extends PolygonDrawerBase {
|
9349 | getCenter(particle, radius) {
|
9350 | return {
|
9351 | x: -radius / (particle.sides / 3.5),
|
9352 | y: -radius / (2.66 / 3.5)
|
9353 | };
|
9354 | }
|
9355 | getSidesData(particle, radius) {
|
9356 | const sides = particle.sides;
|
9357 | return {
|
9358 | count: {
|
9359 | denominator: 1,
|
9360 | numerator: sides
|
9361 | },
|
9362 | length: radius * 2.66 / (sides / 3)
|
9363 | };
|
9364 | }
|
9365 | }
|
9366 | ;
|
9367 |
|
9368 | class TriangleDrawer extends PolygonDrawerBase {
|
9369 | getCenter(particle, radius) {
|
9370 | return {
|
9371 | x: -radius,
|
9372 | y: radius / 1.66
|
9373 | };
|
9374 | }
|
9375 | getSidesCount() {
|
9376 | return 3;
|
9377 | }
|
9378 | getSidesData(particle, radius) {
|
9379 | return {
|
9380 | count: {
|
9381 | denominator: 2,
|
9382 | numerator: 3
|
9383 | },
|
9384 | length: radius * 2
|
9385 | };
|
9386 | }
|
9387 | }
|
9388 | ;
|
9389 |
|
9390 |
|
9391 | async function loadGenericPolygonShape(engine) {
|
9392 | await engine.addShape("polygon", new PolygonDrawer());
|
9393 | }
|
9394 | async function loadTriangleShape(engine) {
|
9395 | await engine.addShape("triangle", new TriangleDrawer());
|
9396 | }
|
9397 | async function loadPolygonShape(engine) {
|
9398 | await loadGenericPolygonShape(engine);
|
9399 | await loadTriangleShape(engine);
|
9400 | }
|
9401 | ;
|
9402 |
|
9403 | function SizeUpdater_checkDestroy(particle, value, minValue, maxValue) {
|
9404 | switch (particle.options.size.animation.destroy) {
|
9405 | case "max":
|
9406 | if (value >= maxValue) {
|
9407 | particle.destroy();
|
9408 | }
|
9409 | break;
|
9410 | case "min":
|
9411 | if (value <= minValue) {
|
9412 | particle.destroy();
|
9413 | }
|
9414 | break;
|
9415 | }
|
9416 | }
|
9417 | function updateSize(particle, delta) {
|
9418 | var _a, _b, _c, _d, _e;
|
9419 | const sizeVelocity = ((_a = particle.size.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor,
|
9420 | minValue = particle.size.min,
|
9421 | maxValue = particle.size.max,
|
9422 | decay = (_b = particle.size.decay) !== null && _b !== void 0 ? _b : 1;
|
9423 | if (particle.destroyed || !particle.size.enable || ((_c = particle.size.maxLoops) !== null && _c !== void 0 ? _c : 0) > 0 && ((_d = particle.size.loops) !== null && _d !== void 0 ? _d : 0) > ((_e = particle.size.maxLoops) !== null && _e !== void 0 ? _e : 0)) {
|
9424 | return;
|
9425 | }
|
9426 | switch (particle.size.status) {
|
9427 | case "increasing":
|
9428 | if (particle.size.value >= maxValue) {
|
9429 | particle.size.status = "decreasing";
|
9430 | if (!particle.size.loops) {
|
9431 | particle.size.loops = 0;
|
9432 | }
|
9433 | particle.size.loops++;
|
9434 | } else {
|
9435 | particle.size.value += sizeVelocity;
|
9436 | }
|
9437 | break;
|
9438 | case "decreasing":
|
9439 | if (particle.size.value <= minValue) {
|
9440 | particle.size.status = "increasing";
|
9441 | if (!particle.size.loops) {
|
9442 | particle.size.loops = 0;
|
9443 | }
|
9444 | particle.size.loops++;
|
9445 | } else {
|
9446 | particle.size.value -= sizeVelocity;
|
9447 | }
|
9448 | }
|
9449 | if (particle.size.velocity && decay !== 1) {
|
9450 | particle.size.velocity *= decay;
|
9451 | }
|
9452 | SizeUpdater_checkDestroy(particle, particle.size.value, minValue, maxValue);
|
9453 | if (!particle.destroyed) {
|
9454 | particle.size.value = clamp(particle.size.value, minValue, maxValue);
|
9455 | }
|
9456 | }
|
9457 | class SizeUpdater {
|
9458 | init(particle) {
|
9459 | var _a;
|
9460 | const container = particle.container,
|
9461 | sizeOptions = particle.options.size,
|
9462 | sizeAnimation = sizeOptions.animation;
|
9463 | if (sizeAnimation.enable) {
|
9464 | particle.size.velocity = ((_a = particle.retina.sizeAnimationSpeed) !== null && _a !== void 0 ? _a : container.retina.sizeAnimationSpeed) / 100 * container.retina.reduceFactor;
|
9465 | if (!sizeAnimation.sync) {
|
9466 | particle.size.velocity *= getRandom();
|
9467 | }
|
9468 | }
|
9469 | }
|
9470 | isEnabled(particle) {
|
9471 | var _a, _b, _c, _d;
|
9472 | return !particle.destroyed && !particle.spawning && particle.size.enable && (((_a = particle.size.maxLoops) !== null && _a !== void 0 ? _a : 0) <= 0 || ((_b = particle.size.maxLoops) !== null && _b !== void 0 ? _b : 0) > 0 && ((_c = particle.size.loops) !== null && _c !== void 0 ? _c : 0) < ((_d = particle.size.maxLoops) !== null && _d !== void 0 ? _d : 0));
|
9473 | }
|
9474 | reset(particle) {
|
9475 | particle.size.loops = 0;
|
9476 | }
|
9477 | update(particle, delta) {
|
9478 | if (!this.isEnabled(particle)) {
|
9479 | return;
|
9480 | }
|
9481 | updateSize(particle, delta);
|
9482 | }
|
9483 | }
|
9484 | ;
|
9485 |
|
9486 | async function loadSizeUpdater(engine) {
|
9487 | await engine.addParticleUpdater("size", () => new SizeUpdater());
|
9488 | }
|
9489 | ;
|
9490 | const fixFactor = Math.sqrt(2);
|
9491 | class SquareDrawer {
|
9492 | draw(context, particle, radius) {
|
9493 | context.rect(-radius / fixFactor, -radius / fixFactor, radius * 2 / fixFactor, radius * 2 / fixFactor);
|
9494 | }
|
9495 | getSidesCount() {
|
9496 | return 4;
|
9497 | }
|
9498 | }
|
9499 | ;
|
9500 |
|
9501 | async function loadSquareShape(engine) {
|
9502 | const drawer = new SquareDrawer();
|
9503 | await engine.addShape(["edge", "square"], drawer);
|
9504 | }
|
9505 | ;
|
9506 |
|
9507 | class StarDrawer {
|
9508 | draw(context, particle, radius) {
|
9509 | var _a;
|
9510 | const sides = particle.sides,
|
9511 | inset = (_a = particle.starInset) !== null && _a !== void 0 ? _a : 2;
|
9512 | context.moveTo(0, 0 - radius);
|
9513 | for (let i = 0; i < sides; i++) {
|
9514 | context.rotate(Math.PI / sides);
|
9515 | context.lineTo(0, 0 - radius * inset);
|
9516 | context.rotate(Math.PI / sides);
|
9517 | context.lineTo(0, 0 - radius);
|
9518 | }
|
9519 | }
|
9520 | getSidesCount(particle) {
|
9521 | var _a, _b;
|
9522 | const star = particle.shapeData;
|
9523 | return Math.round(getRangeValue((_b = (_a = star === null || star === void 0 ? void 0 : star.sides) !== null && _a !== void 0 ? _a : star === null || star === void 0 ? void 0 : star.nb_sides) !== null && _b !== void 0 ? _b : 5));
|
9524 | }
|
9525 | particleInit(container, particle) {
|
9526 | var _a;
|
9527 | const star = particle.shapeData,
|
9528 | inset = getRangeValue((_a = star === null || star === void 0 ? void 0 : star.inset) !== null && _a !== void 0 ? _a : 2);
|
9529 | particle.starInset = inset;
|
9530 | }
|
9531 | }
|
9532 | ;
|
9533 |
|
9534 | async function loadStarShape(engine) {
|
9535 | await engine.addShape("star", new StarDrawer());
|
9536 | }
|
9537 | ;
|
9538 |
|
9539 | function StrokeColorUpdater_updateColorValue(delta, value, valueAnimation, max, decrease) {
|
9540 | var _a, _b;
|
9541 | const colorValue = value;
|
9542 | if (!colorValue || !colorValue.enable || colorValue.loops !== undefined && colorValue.maxLoops !== undefined && colorValue.maxLoops > 0 && colorValue.loops >= colorValue.maxLoops) {
|
9543 | return;
|
9544 | }
|
9545 | const offset = randomInRange(valueAnimation.offset),
|
9546 | velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6,
|
9547 | decay = (_b = value.decay) !== null && _b !== void 0 ? _b : 1;
|
9548 | if (!decrease || colorValue.status === "increasing") {
|
9549 | colorValue.value += velocity;
|
9550 | if (colorValue.value > max) {
|
9551 | if (!colorValue.loops) {
|
9552 | colorValue.loops = 0;
|
9553 | }
|
9554 | colorValue.loops++;
|
9555 | if (decrease) {
|
9556 | colorValue.status = "decreasing";
|
9557 | colorValue.value -= colorValue.value % max;
|
9558 | }
|
9559 | }
|
9560 | } else {
|
9561 | colorValue.value -= velocity;
|
9562 | if (colorValue.value < 0) {
|
9563 | if (!colorValue.loops) {
|
9564 | colorValue.loops = 0;
|
9565 | }
|
9566 | colorValue.loops++;
|
9567 | colorValue.status = "increasing";
|
9568 | colorValue.value += colorValue.value;
|
9569 | }
|
9570 | }
|
9571 | if (colorValue.velocity && decay !== 1) {
|
9572 | colorValue.velocity *= decay;
|
9573 | }
|
9574 | if (colorValue.value > max) {
|
9575 | colorValue.value %= max;
|
9576 | }
|
9577 | }
|
9578 | function updateStrokeColor(particle, delta) {
|
9579 | if (!particle.strokeColor || !particle.strokeAnimation) {
|
9580 | return;
|
9581 | }
|
9582 | const h = particle.strokeColor.h;
|
9583 | if (h) {
|
9584 | StrokeColorUpdater_updateColorValue(delta, h, particle.strokeAnimation.h, 360, false);
|
9585 | }
|
9586 | const s = particle.strokeColor.s;
|
9587 | if (s) {
|
9588 | StrokeColorUpdater_updateColorValue(delta, s, particle.strokeAnimation.s, 100, true);
|
9589 | }
|
9590 | const l = particle.strokeColor.l;
|
9591 | if (l) {
|
9592 | StrokeColorUpdater_updateColorValue(delta, l, particle.strokeAnimation.l, 100, true);
|
9593 | }
|
9594 | }
|
9595 | class StrokeColorUpdater {
|
9596 | constructor(container) {
|
9597 | this.container = container;
|
9598 | }
|
9599 | init(particle) {
|
9600 | var _a, _b, _c;
|
9601 | const container = this.container;
|
9602 | const stroke = itemFromSingleOrMultiple(particle.options.stroke, particle.id, particle.options.reduceDuplicates);
|
9603 | particle.strokeWidth = getRangeValue(stroke.width) * container.retina.pixelRatio;
|
9604 | particle.strokeOpacity = getRangeValue((_a = stroke.opacity) !== null && _a !== void 0 ? _a : 1);
|
9605 | particle.strokeAnimation = (_b = stroke.color) === null || _b === void 0 ? void 0 : _b.animation;
|
9606 | const strokeHslColor = (_c = rangeColorToHsl(stroke.color)) !== null && _c !== void 0 ? _c : particle.getFillColor();
|
9607 | if (strokeHslColor) {
|
9608 | particle.strokeColor = getHslAnimationFromHsl(strokeHslColor, particle.strokeAnimation, container.retina.reduceFactor);
|
9609 | }
|
9610 | }
|
9611 | isEnabled(particle) {
|
9612 | var _a, _b, _c;
|
9613 | const color = particle.strokeAnimation;
|
9614 | return !particle.destroyed && !particle.spawning && !!color && (((_a = particle.strokeColor) === null || _a === void 0 ? void 0 : _a.h.value) !== undefined && particle.strokeColor.h.enable || ((_b = particle.strokeColor) === null || _b === void 0 ? void 0 : _b.s.value) !== undefined && particle.strokeColor.s.enable || ((_c = particle.strokeColor) === null || _c === void 0 ? void 0 : _c.l.value) !== undefined && particle.strokeColor.l.enable);
|
9615 | }
|
9616 | update(particle, delta) {
|
9617 | if (!this.isEnabled(particle)) {
|
9618 | return;
|
9619 | }
|
9620 | updateStrokeColor(particle, delta);
|
9621 | }
|
9622 | }
|
9623 | ;
|
9624 |
|
9625 | async function loadStrokeColorUpdater(engine) {
|
9626 | await engine.addParticleUpdater("strokeColor", container => new StrokeColorUpdater(container));
|
9627 | }
|
9628 | ;
|
9629 |
|
9630 | const validTypes = ["text", "character", "char"];
|
9631 | class TextDrawer {
|
9632 | draw(context, particle, radius, opacity) {
|
9633 | var _a, _b, _c;
|
9634 | const character = particle.shapeData;
|
9635 | if (character === undefined) {
|
9636 | return;
|
9637 | }
|
9638 | const textData = character.value;
|
9639 | if (textData === undefined) {
|
9640 | return;
|
9641 | }
|
9642 | const textParticle = particle;
|
9643 | if (textParticle.text === undefined) {
|
9644 | textParticle.text = itemFromSingleOrMultiple(textData, particle.randomIndexData);
|
9645 | }
|
9646 | const text = textParticle.text,
|
9647 | style = (_a = character.style) !== null && _a !== void 0 ? _a : "",
|
9648 | weight = (_b = character.weight) !== null && _b !== void 0 ? _b : "400",
|
9649 | size = Math.round(radius) * 2,
|
9650 | font = (_c = character.font) !== null && _c !== void 0 ? _c : "Verdana",
|
9651 | fill = particle.fill,
|
9652 | offsetX = text.length * radius / 2;
|
9653 | context.font = `${style} ${weight} ${size}px "${font}"`;
|
9654 | const pos = {
|
9655 | x: -offsetX,
|
9656 | y: radius / 2
|
9657 | };
|
9658 | context.globalAlpha = opacity;
|
9659 | if (fill) {
|
9660 | context.fillText(text, pos.x, pos.y);
|
9661 | } else {
|
9662 | context.strokeText(text, pos.x, pos.y);
|
9663 | }
|
9664 | context.globalAlpha = 1;
|
9665 | }
|
9666 | getSidesCount() {
|
9667 | return 12;
|
9668 | }
|
9669 | async init(container) {
|
9670 | const options = container.actualOptions;
|
9671 | if (validTypes.find(t => isInArray(t, options.particles.shape.type))) {
|
9672 | const shapeOptions = validTypes.map(t => options.particles.shape.options[t]).find(t => !!t),
|
9673 | promises = [];
|
9674 | executeOnSingleOrMultiple(shapeOptions, shape => {
|
9675 | promises.push(loadFont(shape.font, shape.weight));
|
9676 | });
|
9677 | await Promise.all(promises);
|
9678 | }
|
9679 | }
|
9680 | }
|
9681 | ;
|
9682 |
|
9683 | async function loadTextShape(engine) {
|
9684 | await engine.addShape(validTypes, new TextDrawer());
|
9685 | }
|
9686 | ;
|
9687 |
|
9688 |
|
9689 |
|
9690 |
|
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 |
|
9696 |
|
9697 |
|
9698 |
|
9699 |
|
9700 |
|
9701 |
|
9702 |
|
9703 |
|
9704 |
|
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 |
|
9710 |
|
9711 |
|
9712 |
|
9713 |
|
9714 |
|
9715 |
|
9716 |
|
9717 | async function loadSlim(engine) {
|
9718 | await loadBaseMover(engine);
|
9719 | await loadParallaxMover(engine);
|
9720 | await loadExternalAttractInteraction(engine);
|
9721 | await loadExternalBounceInteraction(engine);
|
9722 | await loadExternalBubbleInteraction(engine);
|
9723 | await loadExternalConnectInteraction(engine);
|
9724 | await loadExternalGrabInteraction(engine);
|
9725 | await loadExternalPauseInteraction(engine);
|
9726 | await loadExternalPushInteraction(engine);
|
9727 | await loadExternalRemoveInteraction(engine);
|
9728 | await loadExternalRepulseInteraction(engine);
|
9729 | await loadExternalSlowInteraction(engine);
|
9730 | await loadParticlesAttractInteraction(engine);
|
9731 | await loadParticlesCollisionsInteraction(engine);
|
9732 | await loadParticlesLinksInteraction(engine);
|
9733 | await loadCircleShape(engine);
|
9734 | await loadImageShape(engine);
|
9735 | await loadLineShape(engine);
|
9736 | await loadPolygonShape(engine);
|
9737 | await loadSquareShape(engine);
|
9738 | await loadStarShape(engine);
|
9739 | await loadTextShape(engine);
|
9740 | await loadLifeUpdater(engine);
|
9741 | await loadOpacityUpdater(engine);
|
9742 | await loadSizeUpdater(engine);
|
9743 | await loadAngleUpdater(engine);
|
9744 | await loadColorUpdater(engine);
|
9745 | await loadStrokeColorUpdater(engine);
|
9746 | await loadOutModesUpdater(engine);
|
9747 | await initPjs(engine);
|
9748 | }
|
9749 | ;
|
9750 |
|
9751 |
|
9752 | loadSlim(tsParticles);
|
9753 |
|
9754 |
|
9755 | return __webpack_exports__;
|
9756 | })()
|
9757 | ;
|
9758 | }); |
\ | No newline at end of file |