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, function() {
|
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 | "AbsorberClickMode": () => ( AbsorberClickMode),
|
61 | "AnimationStatus": () => ( AnimationStatus),
|
62 | "CanvasUtils": () => ( CanvasUtils),
|
63 | "ClickMode": () => ( ClickMode),
|
64 | "CollisionMode": () => ( CollisionMode),
|
65 | "ColorUtils": () => ( ColorUtils),
|
66 | "Constants": () => ( Constants),
|
67 | "Container": () => ( Container),
|
68 | "DestroyMode": () => ( DestroyMode),
|
69 | "DestroyType": () => ( DestroyType),
|
70 | "DivMode": () => ( DivMode),
|
71 | "DivType": () => ( DivType),
|
72 | "EmitterClickMode": () => ( EmitterClickMode),
|
73 | "HoverMode": () => ( HoverMode),
|
74 | "InlineArrangement": () => ( InlineArrangement),
|
75 | "InteractivityDetect": () => ( InteractivityDetect),
|
76 | "Main": () => ( Main),
|
77 | "MoveDirection": () => ( MoveDirection),
|
78 | "MoveType": () => ( MoveType),
|
79 | "OutMode": () => ( OutMode),
|
80 | "ProcessBubbleType": () => ( ProcessBubbleType),
|
81 | "RotateDirection": () => ( RotateDirection),
|
82 | "ShapeType": () => ( ShapeType),
|
83 | "SizeMode": () => ( SizeMode),
|
84 | "StartValueType": () => ( StartValueType),
|
85 | "ThemeMode": () => ( ThemeMode),
|
86 | "Type": () => ( Type),
|
87 | "Utils": () => ( Utils),
|
88 | "Vector": () => ( Vector),
|
89 | "pJSDom": () => ( pJSDom),
|
90 | "particlesJS": () => ( particlesJS),
|
91 | "tsParticles": () => ( tsParticles)
|
92 | });
|
93 |
|
94 | ;
|
95 | const initPjs = main => {
|
96 | const particlesJS = (tagId, options) => {
|
97 | return main.load(tagId, options);
|
98 | };
|
99 |
|
100 | particlesJS.load = (tagId, pathConfigJson, callback) => {
|
101 | main.loadJSON(tagId, pathConfigJson).then(container => {
|
102 | if (container) {
|
103 | callback(container);
|
104 | }
|
105 | });
|
106 | };
|
107 |
|
108 | particlesJS.setOnClickHandler = callback => {
|
109 | main.setOnClickHandler(callback);
|
110 | };
|
111 |
|
112 | const pJSDom = main.dom();
|
113 | return {
|
114 | particlesJS,
|
115 | pJSDom
|
116 | };
|
117 | };
|
118 |
|
119 |
|
120 | ;
|
121 | class SquareDrawer {
|
122 | getSidesCount() {
|
123 | return 4;
|
124 | }
|
125 |
|
126 | draw(context, particle, radius) {
|
127 | context.rect(-radius, -radius, radius * 2, radius * 2);
|
128 | }
|
129 |
|
130 | }
|
131 | ;
|
132 | var OutModeDirection;
|
133 |
|
134 | (function (OutModeDirection) {
|
135 | OutModeDirection["bottom"] = "bottom";
|
136 | OutModeDirection["left"] = "left";
|
137 | OutModeDirection["right"] = "right";
|
138 | OutModeDirection["top"] = "top";
|
139 | })(OutModeDirection || (OutModeDirection = {}));
|
140 | ;
|
141 | var MoveDirection;
|
142 |
|
143 | (function (MoveDirection) {
|
144 | MoveDirection["bottom"] = "bottom";
|
145 | MoveDirection["bottomLeft"] = "bottom-left";
|
146 | MoveDirection["bottomRight"] = "bottom-right";
|
147 | MoveDirection["left"] = "left";
|
148 | MoveDirection["none"] = "none";
|
149 | MoveDirection["right"] = "right";
|
150 | MoveDirection["top"] = "top";
|
151 | MoveDirection["topLeft"] = "top-left";
|
152 | MoveDirection["topRight"] = "top-right";
|
153 | })(MoveDirection || (MoveDirection = {}));
|
154 | ;
|
155 | var RotateDirection;
|
156 |
|
157 | (function (RotateDirection) {
|
158 | RotateDirection["clockwise"] = "clockwise";
|
159 | RotateDirection["counterClockwise"] = "counter-clockwise";
|
160 | RotateDirection["random"] = "random";
|
161 | })(RotateDirection || (RotateDirection = {}));
|
162 | ;
|
163 |
|
164 |
|
165 | ;
|
166 | class Vector {
|
167 | constructor(x, y) {
|
168 | let defX, defY;
|
169 |
|
170 | if (y === undefined) {
|
171 | if (typeof x === "number") {
|
172 | throw new Error("tsParticles - Vector not initialized correctly");
|
173 | }
|
174 |
|
175 | const coords = x;
|
176 | [defX, defY] = [coords.x, coords.y];
|
177 | } else {
|
178 | [defX, defY] = [x, y];
|
179 | }
|
180 |
|
181 | this.x = defX;
|
182 | this.y = defY;
|
183 | }
|
184 |
|
185 | static clone(source) {
|
186 | return Vector.create(source.x, source.y);
|
187 | }
|
188 |
|
189 | static create(x, y) {
|
190 | return new Vector(x, y);
|
191 | }
|
192 |
|
193 | get angle() {
|
194 | return Math.atan2(this.y, this.x);
|
195 | }
|
196 |
|
197 | set angle(angle) {
|
198 | this.updateFromAngle(angle, this.length);
|
199 | }
|
200 |
|
201 | get length() {
|
202 | return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
|
203 | }
|
204 |
|
205 | set length(length) {
|
206 | this.updateFromAngle(this.angle, length);
|
207 | }
|
208 |
|
209 | add(v) {
|
210 | return Vector.create(this.x + v.x, this.y + v.y);
|
211 | }
|
212 |
|
213 | addTo(v) {
|
214 | this.x += v.x;
|
215 | this.y += v.y;
|
216 | }
|
217 |
|
218 | sub(v) {
|
219 | return Vector.create(this.x - v.x, this.y - v.y);
|
220 | }
|
221 |
|
222 | subFrom(v) {
|
223 | this.x -= v.x;
|
224 | this.y -= v.y;
|
225 | }
|
226 |
|
227 | mult(n) {
|
228 | return Vector.create(this.x * n, this.y * n);
|
229 | }
|
230 |
|
231 | multTo(n) {
|
232 | this.x *= n;
|
233 | this.y *= n;
|
234 | }
|
235 |
|
236 | div(n) {
|
237 | return Vector.create(this.x / n, this.y / n);
|
238 | }
|
239 |
|
240 | divTo(n) {
|
241 | this.x /= n;
|
242 | this.y /= n;
|
243 | }
|
244 |
|
245 | distanceTo(v) {
|
246 | return this.sub(v).length;
|
247 | }
|
248 |
|
249 | getLengthSq() {
|
250 | return Math.pow(this.x, 2) + Math.pow(this.y, 2);
|
251 | }
|
252 |
|
253 | distanceToSq(v) {
|
254 | return this.sub(v).getLengthSq();
|
255 | }
|
256 |
|
257 | manhattanDistanceTo(v) {
|
258 | return Math.abs(v.x - this.x) + Math.abs(v.y - this.y);
|
259 | }
|
260 |
|
261 | copy() {
|
262 | return Vector.clone(this);
|
263 | }
|
264 |
|
265 | setTo(velocity) {
|
266 | this.x = velocity.x;
|
267 | this.y = velocity.y;
|
268 | }
|
269 |
|
270 | rotate(angle) {
|
271 | return Vector.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle));
|
272 | }
|
273 |
|
274 | updateFromAngle(angle, length) {
|
275 | this.x = Math.cos(angle) * length;
|
276 | this.y = Math.sin(angle) * length;
|
277 | }
|
278 |
|
279 | }
|
280 | Vector.origin = Vector.create(0, 0);
|
281 | ;
|
282 |
|
283 |
|
284 | class NumberUtils {
|
285 | static clamp(num, min, max) {
|
286 | return Math.min(Math.max(num, min), max);
|
287 | }
|
288 |
|
289 | static mix(comp1, comp2, weight1, weight2) {
|
290 | return Math.floor((comp1 * weight1 + comp2 * weight2) / (weight1 + weight2));
|
291 | }
|
292 |
|
293 | static randomInRange(r) {
|
294 | const max = NumberUtils.getRangeMax(r);
|
295 | let min = NumberUtils.getRangeMin(r);
|
296 |
|
297 | if (max === min) {
|
298 | min = 0;
|
299 | }
|
300 |
|
301 | return Math.random() * (max - min) + min;
|
302 | }
|
303 |
|
304 | static getRangeValue(value) {
|
305 | return typeof value === "number" ? value : NumberUtils.randomInRange(value);
|
306 | }
|
307 |
|
308 | static getRangeMin(value) {
|
309 | return typeof value === "number" ? value : value.min;
|
310 | }
|
311 |
|
312 | static getRangeMax(value) {
|
313 | return typeof value === "number" ? value : value.max;
|
314 | }
|
315 |
|
316 | static setRangeValue(source, value) {
|
317 | if (source === value || value === undefined && typeof source === "number") {
|
318 | return source;
|
319 | }
|
320 |
|
321 | const min = NumberUtils.getRangeMin(source),
|
322 | max = NumberUtils.getRangeMax(source);
|
323 | return value !== undefined ? {
|
324 | min: Math.min(min, value),
|
325 | max: Math.max(max, value)
|
326 | } : NumberUtils.setRangeValue(min, max);
|
327 | }
|
328 |
|
329 | static getValue(options) {
|
330 | const random = options.random;
|
331 | const {
|
332 | enable,
|
333 | minimumValue
|
334 | } = typeof random === "boolean" ? {
|
335 | enable: random,
|
336 | minimumValue: 0
|
337 | } : random;
|
338 | return enable ? NumberUtils.getRangeValue(NumberUtils.setRangeValue(options.value, minimumValue)) : NumberUtils.getRangeValue(options.value);
|
339 | }
|
340 |
|
341 | static getDistances(pointA, pointB) {
|
342 | const dx = pointA.x - pointB.x;
|
343 | const dy = pointA.y - pointB.y;
|
344 | return {
|
345 | dx: dx,
|
346 | dy: dy,
|
347 | distance: Math.sqrt(dx * dx + dy * dy)
|
348 | };
|
349 | }
|
350 |
|
351 | static getDistance(pointA, pointB) {
|
352 | return NumberUtils.getDistances(pointA, pointB).distance;
|
353 | }
|
354 |
|
355 | static getParticleBaseVelocity(direction) {
|
356 | const baseVelocity = Vector.origin;
|
357 | baseVelocity.length = 1;
|
358 |
|
359 | switch (direction) {
|
360 | case MoveDirection.top:
|
361 | baseVelocity.angle = -Math.PI / 2;
|
362 | break;
|
363 |
|
364 | case MoveDirection.topRight:
|
365 | baseVelocity.angle = -Math.PI / 4;
|
366 | break;
|
367 |
|
368 | case MoveDirection.right:
|
369 | baseVelocity.angle = 0;
|
370 | break;
|
371 |
|
372 | case MoveDirection.bottomRight:
|
373 | baseVelocity.angle = Math.PI / 4;
|
374 | break;
|
375 |
|
376 | case MoveDirection.bottom:
|
377 | baseVelocity.angle = Math.PI / 2;
|
378 | break;
|
379 |
|
380 | case MoveDirection.bottomLeft:
|
381 | baseVelocity.angle = 3 * Math.PI / 4;
|
382 | break;
|
383 |
|
384 | case MoveDirection.left:
|
385 | baseVelocity.angle = Math.PI;
|
386 | break;
|
387 |
|
388 | case MoveDirection.topLeft:
|
389 | baseVelocity.angle = -3 * Math.PI / 4;
|
390 | break;
|
391 |
|
392 | case MoveDirection.none:
|
393 | default:
|
394 | baseVelocity.angle = Math.random() * Math.PI * 2;
|
395 | break;
|
396 | }
|
397 |
|
398 | return baseVelocity;
|
399 | }
|
400 |
|
401 | static rotateVelocity(velocity, angle) {
|
402 | return {
|
403 | horizontal: velocity.horizontal * Math.cos(angle) - velocity.vertical * Math.sin(angle),
|
404 | vertical: velocity.horizontal * Math.sin(angle) + velocity.vertical * Math.cos(angle)
|
405 | };
|
406 | }
|
407 |
|
408 | static collisionVelocity(v1, v2, m1, m2) {
|
409 | return Vector.create(v1.x * (m1 - m2) / (m1 + m2) + v2.x * 2 * m2 / (m1 + m2), v1.y);
|
410 | }
|
411 |
|
412 | }
|
413 | ;
|
414 | var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
415 | function adopt(value) {
|
416 | return value instanceof P ? value : new P(function (resolve) {
|
417 | resolve(value);
|
418 | });
|
419 | }
|
420 |
|
421 | return new (P || (P = Promise))(function (resolve, reject) {
|
422 | function fulfilled(value) {
|
423 | try {
|
424 | step(generator.next(value));
|
425 | } catch (e) {
|
426 | reject(e);
|
427 | }
|
428 | }
|
429 |
|
430 | function rejected(value) {
|
431 | try {
|
432 | step(generator["throw"](value));
|
433 | } catch (e) {
|
434 | reject(e);
|
435 | }
|
436 | }
|
437 |
|
438 | function step(result) {
|
439 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
440 | }
|
441 |
|
442 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
443 | });
|
444 | };
|
445 |
|
446 |
|
447 |
|
448 |
|
449 | function rectSideBounce(pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor) {
|
450 | const res = {
|
451 | bounced: false
|
452 | };
|
453 |
|
454 | if (pOtherSide.min >= rectOtherSide.min && pOtherSide.min <= rectOtherSide.max && pOtherSide.max >= rectOtherSide.min && pOtherSide.max <= rectOtherSide.max) {
|
455 | 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) {
|
456 | res.velocity = velocity * -factor;
|
457 | res.bounced = true;
|
458 | }
|
459 | }
|
460 |
|
461 | return res;
|
462 | }
|
463 |
|
464 | function checkSelector(element, selectors) {
|
465 | if (selectors instanceof Array) {
|
466 | for (const selector of selectors) {
|
467 | if (element.matches(selector)) {
|
468 | return true;
|
469 | }
|
470 | }
|
471 |
|
472 | return false;
|
473 | } else {
|
474 | return element.matches(selectors);
|
475 | }
|
476 | }
|
477 |
|
478 | class Utils {
|
479 | static isSsr() {
|
480 | return typeof window === "undefined" || !window;
|
481 | }
|
482 |
|
483 | static get animate() {
|
484 | return Utils.isSsr() ? callback => setTimeout(callback) : callback => (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout)(callback);
|
485 | }
|
486 |
|
487 | static get cancelAnimation() {
|
488 | return Utils.isSsr() ? handle => clearTimeout(handle) : handle => (window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.mozCancelRequestAnimationFrame || window.oCancelRequestAnimationFrame || window.msCancelRequestAnimationFrame || window.clearTimeout)(handle);
|
489 | }
|
490 |
|
491 | static isInArray(value, array) {
|
492 | return value === array || array instanceof Array && array.indexOf(value) > -1;
|
493 | }
|
494 |
|
495 | static loadFont(character) {
|
496 | return __awaiter(this, void 0, void 0, function* () {
|
497 | try {
|
498 | yield document.fonts.load(`${character.weight} 36px '${character.font}'`);
|
499 | } catch (_a) {}
|
500 | });
|
501 | }
|
502 |
|
503 | static arrayRandomIndex(array) {
|
504 | return Math.floor(Math.random() * array.length);
|
505 | }
|
506 |
|
507 | static itemFromArray(array, index, useIndex = true) {
|
508 | const fixedIndex = index !== undefined && useIndex ? index % array.length : Utils.arrayRandomIndex(array);
|
509 | return array[fixedIndex];
|
510 | }
|
511 |
|
512 | static isPointInside(point, size, radius, direction) {
|
513 | return Utils.areBoundsInside(Utils.calculateBounds(point, radius !== null && radius !== void 0 ? radius : 0), size, direction);
|
514 | }
|
515 |
|
516 | static areBoundsInside(bounds, size, direction) {
|
517 | let inside = true;
|
518 |
|
519 | if (!direction || direction === OutModeDirection.bottom) {
|
520 | inside = bounds.top < size.height;
|
521 | }
|
522 |
|
523 | if (inside && (!direction || direction === OutModeDirection.left)) {
|
524 | inside = bounds.right > 0;
|
525 | }
|
526 |
|
527 | if (inside && (!direction || direction === OutModeDirection.right)) {
|
528 | inside = bounds.left < size.width;
|
529 | }
|
530 |
|
531 | if (inside && (!direction || direction === OutModeDirection.top)) {
|
532 | inside = bounds.bottom > 0;
|
533 | }
|
534 |
|
535 | return inside;
|
536 | }
|
537 |
|
538 | static calculateBounds(point, radius) {
|
539 | return {
|
540 | bottom: point.y + radius,
|
541 | left: point.x - radius,
|
542 | right: point.x + radius,
|
543 | top: point.y - radius
|
544 | };
|
545 | }
|
546 |
|
547 | static loadImage(source) {
|
548 | return new Promise((resolve, reject) => {
|
549 | if (!source) {
|
550 | reject("Error tsParticles - No image.src");
|
551 | return;
|
552 | }
|
553 |
|
554 | const image = {
|
555 | source: source,
|
556 | type: source.substr(source.length - 3)
|
557 | };
|
558 | const img = new Image();
|
559 | img.addEventListener("load", () => {
|
560 | image.element = img;
|
561 | resolve(image);
|
562 | });
|
563 | img.addEventListener("error", () => {
|
564 | reject(`Error tsParticles - loading image: ${source}`);
|
565 | });
|
566 | img.src = source;
|
567 | });
|
568 | }
|
569 |
|
570 | static downloadSvgImage(source) {
|
571 | return __awaiter(this, void 0, void 0, function* () {
|
572 | if (!source) {
|
573 | throw new Error("Error tsParticles - No image.src");
|
574 | }
|
575 |
|
576 | const image = {
|
577 | source: source,
|
578 | type: source.substr(source.length - 3)
|
579 | };
|
580 |
|
581 | if (image.type !== "svg") {
|
582 | return Utils.loadImage(source);
|
583 | }
|
584 |
|
585 | const response = yield fetch(image.source);
|
586 |
|
587 | if (!response.ok) {
|
588 | throw new Error("Error tsParticles - Image not found");
|
589 | }
|
590 |
|
591 | image.svgData = yield response.text();
|
592 | return image;
|
593 | });
|
594 | }
|
595 |
|
596 | static deepExtend(destination, ...sources) {
|
597 | for (const source of sources) {
|
598 | if (source === undefined || source === null) {
|
599 | continue;
|
600 | }
|
601 |
|
602 | if (typeof source !== "object") {
|
603 | destination = source;
|
604 | continue;
|
605 | }
|
606 |
|
607 | const sourceIsArray = Array.isArray(source);
|
608 |
|
609 | if (sourceIsArray && (typeof destination !== "object" || !destination || !Array.isArray(destination))) {
|
610 | destination = [];
|
611 | } else if (!sourceIsArray && (typeof destination !== "object" || !destination || Array.isArray(destination))) {
|
612 | destination = {};
|
613 | }
|
614 |
|
615 | for (const key in source) {
|
616 | if (key === "__proto__") {
|
617 | continue;
|
618 | }
|
619 |
|
620 | const sourceDict = source;
|
621 | const value = sourceDict[key];
|
622 | const isObject = typeof value === "object";
|
623 | const destDict = destination;
|
624 | destDict[key] = isObject && Array.isArray(value) ? value.map(v => Utils.deepExtend(destDict[key], v)) : Utils.deepExtend(destDict[key], value);
|
625 | }
|
626 | }
|
627 |
|
628 | return destination;
|
629 | }
|
630 |
|
631 | static isDivModeEnabled(mode, divs) {
|
632 | return divs instanceof Array ? !!divs.find(t => t.enable && Utils.isInArray(mode, t.mode)) : Utils.isInArray(mode, divs.mode);
|
633 | }
|
634 |
|
635 | static divModeExecute(mode, divs, callback) {
|
636 | if (divs instanceof Array) {
|
637 | for (const div of divs) {
|
638 | const divMode = div.mode;
|
639 | const divEnabled = div.enable;
|
640 |
|
641 | if (divEnabled && Utils.isInArray(mode, divMode)) {
|
642 | Utils.singleDivModeExecute(div, callback);
|
643 | }
|
644 | }
|
645 | } else {
|
646 | const divMode = divs.mode;
|
647 | const divEnabled = divs.enable;
|
648 |
|
649 | if (divEnabled && Utils.isInArray(mode, divMode)) {
|
650 | Utils.singleDivModeExecute(divs, callback);
|
651 | }
|
652 | }
|
653 | }
|
654 |
|
655 | static singleDivModeExecute(div, callback) {
|
656 | const selectors = div.selectors;
|
657 |
|
658 | if (selectors instanceof Array) {
|
659 | for (const selector of selectors) {
|
660 | callback(selector, div);
|
661 | }
|
662 | } else {
|
663 | callback(selectors, div);
|
664 | }
|
665 | }
|
666 |
|
667 | static divMode(divs, element) {
|
668 | if (!element || !divs) {
|
669 | return;
|
670 | }
|
671 |
|
672 | if (divs instanceof Array) {
|
673 | return divs.find(d => checkSelector(element, d.selectors));
|
674 | } else if (checkSelector(element, divs.selectors)) {
|
675 | return divs;
|
676 | }
|
677 | }
|
678 |
|
679 | static circleBounceDataFromParticle(p) {
|
680 | return {
|
681 | position: p.getPosition(),
|
682 | radius: p.getRadius(),
|
683 | mass: p.getMass(),
|
684 | velocity: p.velocity,
|
685 | factor: {
|
686 | horizontal: NumberUtils.getValue(p.options.bounce.horizontal),
|
687 | vertical: NumberUtils.getValue(p.options.bounce.vertical)
|
688 | }
|
689 | };
|
690 | }
|
691 |
|
692 | static circleBounce(p1, p2) {
|
693 | const xVelocityDiff = p1.velocity.x;
|
694 | const yVelocityDiff = p1.velocity.y;
|
695 | const pos1 = p1.position;
|
696 | const pos2 = p2.position;
|
697 | const xDist = pos2.x - pos1.x;
|
698 | const yDist = pos2.y - pos1.y;
|
699 |
|
700 | if (xVelocityDiff * xDist + yVelocityDiff * yDist >= 0) {
|
701 | const angle = -Math.atan2(pos2.y - pos1.y, pos2.x - pos1.x);
|
702 | const m1 = p1.mass;
|
703 | const m2 = p2.mass;
|
704 | const u1 = p1.velocity.rotate(angle);
|
705 | const u2 = p2.velocity.rotate(angle);
|
706 | const v1 = NumberUtils.collisionVelocity(u1, u2, m1, m2);
|
707 | const v2 = NumberUtils.collisionVelocity(u2, u1, m1, m2);
|
708 | const vFinal1 = v1.rotate(-angle);
|
709 | const vFinal2 = v2.rotate(-angle);
|
710 | p1.velocity.x = vFinal1.x * p1.factor.horizontal;
|
711 | p1.velocity.y = vFinal1.y * p1.factor.vertical;
|
712 | p2.velocity.x = vFinal2.x * p2.factor.horizontal;
|
713 | p2.velocity.y = vFinal2.y * p2.factor.vertical;
|
714 | }
|
715 | }
|
716 |
|
717 | static rectBounce(particle, divBounds) {
|
718 | const pPos = particle.getPosition();
|
719 | const size = particle.getRadius();
|
720 | const bounds = Utils.calculateBounds(pPos, size);
|
721 | const resH = rectSideBounce({
|
722 | min: bounds.left,
|
723 | max: bounds.right
|
724 | }, {
|
725 | min: bounds.top,
|
726 | max: bounds.bottom
|
727 | }, {
|
728 | min: divBounds.left,
|
729 | max: divBounds.right
|
730 | }, {
|
731 | min: divBounds.top,
|
732 | max: divBounds.bottom
|
733 | }, particle.velocity.x, NumberUtils.getValue(particle.options.bounce.horizontal));
|
734 |
|
735 | if (resH.bounced) {
|
736 | if (resH.velocity !== undefined) {
|
737 | particle.velocity.x = resH.velocity;
|
738 | }
|
739 |
|
740 | if (resH.position !== undefined) {
|
741 | particle.position.x = resH.position;
|
742 | }
|
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, NumberUtils.getValue(particle.options.bounce.vertical));
|
758 |
|
759 | if (resV.bounced) {
|
760 | if (resV.velocity !== undefined) {
|
761 | particle.velocity.y = resV.velocity;
|
762 | }
|
763 |
|
764 | if (resV.position !== undefined) {
|
765 | particle.position.y = resV.position;
|
766 | }
|
767 | }
|
768 | }
|
769 |
|
770 | }
|
771 | ;
|
772 | class Constants {}
|
773 | Constants.canvasClass = "tsparticles-canvas-el";
|
774 | Constants.randomColorValue = "random";
|
775 | Constants.midColorValue = "mid";
|
776 | Constants.touchEndEvent = "touchend";
|
777 | Constants.mouseDownEvent = "mousedown";
|
778 | Constants.mouseUpEvent = "mouseup";
|
779 | Constants.mouseMoveEvent = "mousemove";
|
780 | Constants.touchStartEvent = "touchstart";
|
781 | Constants.touchMoveEvent = "touchmove";
|
782 | Constants.mouseLeaveEvent = "mouseleave";
|
783 | Constants.mouseOutEvent = "mouseout";
|
784 | Constants.touchCancelEvent = "touchcancel";
|
785 | Constants.resizeEvent = "resize";
|
786 | Constants.visibilityChangeEvent = "visibilitychange";
|
787 | Constants.noPolygonDataLoaded = "No polygon data loaded.";
|
788 | Constants.noPolygonFound = "No polygon found, you need to specify SVG url in config.";
|
789 | ;
|
790 |
|
791 |
|
792 |
|
793 |
|
794 | function hue2rgb(p, q, t) {
|
795 | let tCalc = t;
|
796 |
|
797 | if (tCalc < 0) {
|
798 | tCalc += 1;
|
799 | }
|
800 |
|
801 | if (tCalc > 1) {
|
802 | tCalc -= 1;
|
803 | }
|
804 |
|
805 | if (tCalc < 1 / 6) {
|
806 | return p + (q - p) * 6 * tCalc;
|
807 | }
|
808 |
|
809 | if (tCalc < 1 / 2) {
|
810 | return q;
|
811 | }
|
812 |
|
813 | if (tCalc < 2 / 3) {
|
814 | return p + (q - p) * (2 / 3 - tCalc) * 6;
|
815 | }
|
816 |
|
817 | return p;
|
818 | }
|
819 |
|
820 | function stringToRgba(input) {
|
821 | if (input.startsWith("rgb")) {
|
822 | const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.]+)\s*)?\)/i;
|
823 | const result = regex.exec(input);
|
824 | return result ? {
|
825 | a: result.length > 4 ? parseFloat(result[5]) : 1,
|
826 | b: parseInt(result[3], 10),
|
827 | g: parseInt(result[2], 10),
|
828 | r: parseInt(result[1], 10)
|
829 | } : undefined;
|
830 | } else if (input.startsWith("hsl")) {
|
831 | const regex = /hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i;
|
832 | const result = regex.exec(input);
|
833 | return result ? ColorUtils.hslaToRgba({
|
834 | a: result.length > 4 ? parseFloat(result[5]) : 1,
|
835 | h: parseInt(result[1], 10),
|
836 | l: parseInt(result[3], 10),
|
837 | s: parseInt(result[2], 10)
|
838 | }) : undefined;
|
839 | } else if (input.startsWith("hsv")) {
|
840 | const regex = /hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i;
|
841 | const result = regex.exec(input);
|
842 | return result ? ColorUtils.hsvaToRgba({
|
843 | a: result.length > 4 ? parseFloat(result[5]) : 1,
|
844 | h: parseInt(result[1], 10),
|
845 | s: parseInt(result[2], 10),
|
846 | v: parseInt(result[3], 10)
|
847 | }) : undefined;
|
848 | } else {
|
849 | const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i;
|
850 | const hexFixed = input.replace(shorthandRegex, (_m, r, g, b, a) => {
|
851 | return r + r + g + g + b + b + (a !== undefined ? a + a : "");
|
852 | });
|
853 | const regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
|
854 | const result = regex.exec(hexFixed);
|
855 | return result ? {
|
856 | a: result[4] !== undefined ? parseInt(result[4], 16) / 0xff : 1,
|
857 | b: parseInt(result[3], 16),
|
858 | g: parseInt(result[2], 16),
|
859 | r: parseInt(result[1], 16)
|
860 | } : undefined;
|
861 | }
|
862 | }
|
863 |
|
864 | class ColorUtils {
|
865 | static colorToRgb(input, index, useIndex = true) {
|
866 | var _a, _b, _c;
|
867 |
|
868 | if (input === undefined) {
|
869 | return;
|
870 | }
|
871 |
|
872 | const color = typeof input === "string" ? {
|
873 | value: input
|
874 | } : input;
|
875 | let res;
|
876 |
|
877 | if (typeof color.value === "string") {
|
878 | if (color.value === Constants.randomColorValue) {
|
879 | res = ColorUtils.getRandomRgbColor();
|
880 | } else {
|
881 | res = ColorUtils.stringToRgb(color.value);
|
882 | }
|
883 | } else {
|
884 | if (color.value instanceof Array) {
|
885 | const colorSelected = Utils.itemFromArray(color.value, index, useIndex);
|
886 | res = ColorUtils.colorToRgb({
|
887 | value: colorSelected
|
888 | });
|
889 | } else {
|
890 | const colorValue = color.value;
|
891 | const rgbColor = (_a = colorValue.rgb) !== null && _a !== void 0 ? _a : color.value;
|
892 |
|
893 | if (rgbColor.r !== undefined) {
|
894 | res = rgbColor;
|
895 | } else {
|
896 | const hslColor = (_b = colorValue.hsl) !== null && _b !== void 0 ? _b : color.value;
|
897 |
|
898 | if (hslColor.h !== undefined && hslColor.l !== undefined) {
|
899 | res = ColorUtils.hslToRgb(hslColor);
|
900 | } else {
|
901 | const hsvColor = (_c = colorValue.hsv) !== null && _c !== void 0 ? _c : color.value;
|
902 |
|
903 | if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
|
904 | res = ColorUtils.hsvToRgb(hsvColor);
|
905 | }
|
906 | }
|
907 | }
|
908 | }
|
909 | }
|
910 |
|
911 | return res;
|
912 | }
|
913 |
|
914 | static colorToHsl(color, index, useIndex = true) {
|
915 | const rgb = ColorUtils.colorToRgb(color, index, useIndex);
|
916 | return rgb !== undefined ? ColorUtils.rgbToHsl(rgb) : undefined;
|
917 | }
|
918 |
|
919 | static rgbToHsl(color) {
|
920 | const r1 = color.r / 255;
|
921 | const g1 = color.g / 255;
|
922 | const b1 = color.b / 255;
|
923 | const max = Math.max(r1, g1, b1);
|
924 | const min = Math.min(r1, g1, b1);
|
925 | const res = {
|
926 | h: 0,
|
927 | l: (max + min) / 2,
|
928 | s: 0
|
929 | };
|
930 |
|
931 | if (max != min) {
|
932 | res.s = res.l < 0.5 ? (max - min) / (max + min) : (max - min) / (2.0 - max - min);
|
933 | res.h = r1 === max ? (g1 - b1) / (max - min) : res.h = g1 === max ? 2.0 + (b1 - r1) / (max - min) : 4.0 + (r1 - g1) / (max - min);
|
934 | }
|
935 |
|
936 | res.l *= 100;
|
937 | res.s *= 100;
|
938 | res.h *= 60;
|
939 |
|
940 | if (res.h < 0) {
|
941 | res.h += 360;
|
942 | }
|
943 |
|
944 | return res;
|
945 | }
|
946 |
|
947 | static stringToAlpha(input) {
|
948 | var _a;
|
949 |
|
950 | return (_a = stringToRgba(input)) === null || _a === void 0 ? void 0 : _a.a;
|
951 | }
|
952 |
|
953 | static stringToRgb(input) {
|
954 | return stringToRgba(input);
|
955 | }
|
956 |
|
957 | static hslToRgb(hsl) {
|
958 | const result = {
|
959 | b: 0,
|
960 | g: 0,
|
961 | r: 0
|
962 | };
|
963 | const hslPercent = {
|
964 | h: hsl.h / 360,
|
965 | l: hsl.l / 100,
|
966 | s: hsl.s / 100
|
967 | };
|
968 |
|
969 | if (hslPercent.s === 0) {
|
970 | result.b = hslPercent.l;
|
971 | result.g = hslPercent.l;
|
972 | result.r = hslPercent.l;
|
973 | } else {
|
974 | const q = hslPercent.l < 0.5 ? hslPercent.l * (1 + hslPercent.s) : hslPercent.l + hslPercent.s - hslPercent.l * hslPercent.s;
|
975 | const p = 2 * hslPercent.l - q;
|
976 | result.r = hue2rgb(p, q, hslPercent.h + 1 / 3);
|
977 | result.g = hue2rgb(p, q, hslPercent.h);
|
978 | result.b = hue2rgb(p, q, hslPercent.h - 1 / 3);
|
979 | }
|
980 |
|
981 | result.r = Math.floor(result.r * 255);
|
982 | result.g = Math.floor(result.g * 255);
|
983 | result.b = Math.floor(result.b * 255);
|
984 | return result;
|
985 | }
|
986 |
|
987 | static hslaToRgba(hsla) {
|
988 | const rgbResult = ColorUtils.hslToRgb(hsla);
|
989 | return {
|
990 | a: hsla.a,
|
991 | b: rgbResult.b,
|
992 | g: rgbResult.g,
|
993 | r: rgbResult.r
|
994 | };
|
995 | }
|
996 |
|
997 | static hslToHsv(hsl) {
|
998 | const l = hsl.l / 100,
|
999 | sl = hsl.s / 100;
|
1000 | const v = l + sl * Math.min(l, 1 - l),
|
1001 | sv = !v ? 0 : 2 * (1 - l / v);
|
1002 | return {
|
1003 | h: hsl.h,
|
1004 | s: sv * 100,
|
1005 | v: v * 100
|
1006 | };
|
1007 | }
|
1008 |
|
1009 | static hslaToHsva(hsla) {
|
1010 | const hsvResult = ColorUtils.hslToHsv(hsla);
|
1011 | return {
|
1012 | a: hsla.a,
|
1013 | h: hsvResult.h,
|
1014 | s: hsvResult.s,
|
1015 | v: hsvResult.v
|
1016 | };
|
1017 | }
|
1018 |
|
1019 | static hsvToHsl(hsv) {
|
1020 | const v = hsv.v / 100,
|
1021 | sv = hsv.s / 100;
|
1022 | const l = v * (1 - sv / 2),
|
1023 | sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l);
|
1024 | return {
|
1025 | h: hsv.h,
|
1026 | l: l * 100,
|
1027 | s: sl * 100
|
1028 | };
|
1029 | }
|
1030 |
|
1031 | static hsvaToHsla(hsva) {
|
1032 | const hslResult = ColorUtils.hsvToHsl(hsva);
|
1033 | return {
|
1034 | a: hsva.a,
|
1035 | h: hslResult.h,
|
1036 | l: hslResult.l,
|
1037 | s: hslResult.s
|
1038 | };
|
1039 | }
|
1040 |
|
1041 | static hsvToRgb(hsv) {
|
1042 | const result = {
|
1043 | b: 0,
|
1044 | g: 0,
|
1045 | r: 0
|
1046 | };
|
1047 | const hsvPercent = {
|
1048 | h: hsv.h / 60,
|
1049 | s: hsv.s / 100,
|
1050 | v: hsv.v / 100
|
1051 | };
|
1052 | const c = hsvPercent.v * hsvPercent.s,
|
1053 | x = c * (1 - Math.abs(hsvPercent.h % 2 - 1));
|
1054 | let tempRgb;
|
1055 |
|
1056 | if (hsvPercent.h >= 0 && hsvPercent.h <= 1) {
|
1057 | tempRgb = {
|
1058 | r: c,
|
1059 | g: x,
|
1060 | b: 0
|
1061 | };
|
1062 | } else if (hsvPercent.h > 1 && hsvPercent.h <= 2) {
|
1063 | tempRgb = {
|
1064 | r: x,
|
1065 | g: c,
|
1066 | b: 0
|
1067 | };
|
1068 | } else if (hsvPercent.h > 2 && hsvPercent.h <= 3) {
|
1069 | tempRgb = {
|
1070 | r: 0,
|
1071 | g: c,
|
1072 | b: x
|
1073 | };
|
1074 | } else if (hsvPercent.h > 3 && hsvPercent.h <= 4) {
|
1075 | tempRgb = {
|
1076 | r: 0,
|
1077 | g: x,
|
1078 | b: c
|
1079 | };
|
1080 | } else if (hsvPercent.h > 4 && hsvPercent.h <= 5) {
|
1081 | tempRgb = {
|
1082 | r: x,
|
1083 | g: 0,
|
1084 | b: c
|
1085 | };
|
1086 | } else if (hsvPercent.h > 5 && hsvPercent.h <= 6) {
|
1087 | tempRgb = {
|
1088 | r: c,
|
1089 | g: 0,
|
1090 | b: x
|
1091 | };
|
1092 | }
|
1093 |
|
1094 | if (tempRgb) {
|
1095 | const m = hsvPercent.v - c;
|
1096 | result.r = Math.floor((tempRgb.r + m) * 255);
|
1097 | result.g = Math.floor((tempRgb.g + m) * 255);
|
1098 | result.b = Math.floor((tempRgb.b + m) * 255);
|
1099 | }
|
1100 |
|
1101 | return result;
|
1102 | }
|
1103 |
|
1104 | static hsvaToRgba(hsva) {
|
1105 | const rgbResult = ColorUtils.hsvToRgb(hsva);
|
1106 | return {
|
1107 | a: hsva.a,
|
1108 | b: rgbResult.b,
|
1109 | g: rgbResult.g,
|
1110 | r: rgbResult.r
|
1111 | };
|
1112 | }
|
1113 |
|
1114 | static rgbToHsv(rgb) {
|
1115 | const rgbPercent = {
|
1116 | r: rgb.r / 255,
|
1117 | g: rgb.g / 255,
|
1118 | b: rgb.b / 255
|
1119 | },
|
1120 | xMax = Math.max(rgbPercent.r, rgbPercent.g, rgbPercent.b),
|
1121 | xMin = Math.min(rgbPercent.r, rgbPercent.g, rgbPercent.b),
|
1122 | v = xMax,
|
1123 | c = xMax - xMin;
|
1124 | let h = 0;
|
1125 |
|
1126 | if (v === rgbPercent.r) {
|
1127 | h = 60 * ((rgbPercent.g - rgbPercent.b) / c);
|
1128 | } else if (v === rgbPercent.g) {
|
1129 | h = 60 * (2 + (rgbPercent.b - rgbPercent.r) / c);
|
1130 | } else if (v === rgbPercent.b) {
|
1131 | h = 60 * (4 + (rgbPercent.r - rgbPercent.g) / c);
|
1132 | }
|
1133 |
|
1134 | const s = !v ? 0 : c / v;
|
1135 | return {
|
1136 | h,
|
1137 | s: s * 100,
|
1138 | v: v * 100
|
1139 | };
|
1140 | }
|
1141 |
|
1142 | static rgbaToHsva(rgba) {
|
1143 | const hsvResult = ColorUtils.rgbToHsv(rgba);
|
1144 | return {
|
1145 | a: rgba.a,
|
1146 | h: hsvResult.h,
|
1147 | s: hsvResult.s,
|
1148 | v: hsvResult.v
|
1149 | };
|
1150 | }
|
1151 |
|
1152 | static getRandomRgbColor(min) {
|
1153 | const fixedMin = min !== null && min !== void 0 ? min : 0;
|
1154 | return {
|
1155 | b: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256))),
|
1156 | g: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256))),
|
1157 | r: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256)))
|
1158 | };
|
1159 | }
|
1160 |
|
1161 | static getStyleFromRgb(color, opacity) {
|
1162 | return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
|
1163 | }
|
1164 |
|
1165 | static getStyleFromHsl(color, opacity) {
|
1166 | return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
|
1167 | }
|
1168 |
|
1169 | static getStyleFromHsv(color, opacity) {
|
1170 | return ColorUtils.getStyleFromHsl(ColorUtils.hsvToHsl(color), opacity);
|
1171 | }
|
1172 |
|
1173 | static mix(color1, color2, size1, size2) {
|
1174 | let rgb1 = color1;
|
1175 | let rgb2 = color2;
|
1176 |
|
1177 | if (rgb1.r === undefined) {
|
1178 | rgb1 = ColorUtils.hslToRgb(color1);
|
1179 | }
|
1180 |
|
1181 | if (rgb2.r === undefined) {
|
1182 | rgb2 = ColorUtils.hslToRgb(color2);
|
1183 | }
|
1184 |
|
1185 | return {
|
1186 | b: NumberUtils.mix(rgb1.b, rgb2.b, size1, size2),
|
1187 | g: NumberUtils.mix(rgb1.g, rgb2.g, size1, size2),
|
1188 | r: NumberUtils.mix(rgb1.r, rgb2.r, size1, size2)
|
1189 | };
|
1190 | }
|
1191 |
|
1192 | static replaceColorSvg(image, color, opacity) {
|
1193 | if (!image.svgData) {
|
1194 | return "";
|
1195 | }
|
1196 |
|
1197 | const svgXml = image.svgData;
|
1198 | const rgbHex = /#([0-9A-F]{3,6})/gi;
|
1199 | return svgXml.replace(rgbHex, () => ColorUtils.getStyleFromHsl(color, opacity));
|
1200 | }
|
1201 |
|
1202 | static getLinkColor(p1, p2, linkColor) {
|
1203 | var _a, _b;
|
1204 |
|
1205 | if (linkColor === Constants.randomColorValue) {
|
1206 | return ColorUtils.getRandomRgbColor();
|
1207 | } else if (linkColor === "mid") {
|
1208 | const sourceColor = (_a = p1.getFillColor()) !== null && _a !== void 0 ? _a : p1.getStrokeColor();
|
1209 | const 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();
|
1210 |
|
1211 | if (sourceColor && destColor && p2) {
|
1212 | return ColorUtils.mix(sourceColor, destColor, p1.getRadius(), p2.getRadius());
|
1213 | } else {
|
1214 | const hslColor = sourceColor !== null && sourceColor !== void 0 ? sourceColor : destColor;
|
1215 |
|
1216 | if (hslColor) {
|
1217 | return ColorUtils.hslToRgb(hslColor);
|
1218 | }
|
1219 | }
|
1220 | } else {
|
1221 | return linkColor;
|
1222 | }
|
1223 | }
|
1224 |
|
1225 | static getLinkRandomColor(optColor, blink, consent) {
|
1226 | const color = typeof optColor === "string" ? optColor : optColor.value;
|
1227 |
|
1228 | if (color === Constants.randomColorValue) {
|
1229 | if (consent) {
|
1230 | return ColorUtils.colorToRgb({
|
1231 | value: color
|
1232 | });
|
1233 | } else if (blink) {
|
1234 | return Constants.randomColorValue;
|
1235 | } else {
|
1236 | return Constants.midColorValue;
|
1237 | }
|
1238 | } else {
|
1239 | return ColorUtils.colorToRgb({
|
1240 | value: color
|
1241 | });
|
1242 | }
|
1243 | }
|
1244 |
|
1245 | static getHslFromAnimation(animation) {
|
1246 | return animation !== undefined ? {
|
1247 | h: animation.h.value,
|
1248 | s: animation.s.value,
|
1249 | l: animation.l.value
|
1250 | } : undefined;
|
1251 | }
|
1252 |
|
1253 | }
|
1254 | ;
|
1255 |
|
1256 |
|
1257 |
|
1258 | function drawLine(context, begin, end) {
|
1259 | context.beginPath();
|
1260 | context.moveTo(begin.x, begin.y);
|
1261 | context.lineTo(end.x, end.y);
|
1262 | context.closePath();
|
1263 | }
|
1264 |
|
1265 | function drawTriangle(context, p1, p2, p3) {
|
1266 | context.beginPath();
|
1267 | context.moveTo(p1.x, p1.y);
|
1268 | context.lineTo(p2.x, p2.y);
|
1269 | context.lineTo(p3.x, p3.y);
|
1270 | context.closePath();
|
1271 | }
|
1272 |
|
1273 | class CanvasUtils {
|
1274 | static paintBase(context, dimension, baseColor) {
|
1275 | context.save();
|
1276 | context.fillStyle = baseColor !== null && baseColor !== void 0 ? baseColor : "rgba(0,0,0,0)";
|
1277 | context.fillRect(0, 0, dimension.width, dimension.height);
|
1278 | context.restore();
|
1279 | }
|
1280 |
|
1281 | static clear(context, dimension) {
|
1282 | context.clearRect(0, 0, dimension.width, dimension.height);
|
1283 | }
|
1284 |
|
1285 | static drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) {
|
1286 | let drawn = false;
|
1287 |
|
1288 | if (NumberUtils.getDistance(begin, end) <= maxDistance) {
|
1289 | drawLine(context, begin, end);
|
1290 | drawn = true;
|
1291 | } else if (warp) {
|
1292 | let pi1;
|
1293 | let pi2;
|
1294 | const endNE = {
|
1295 | x: end.x - canvasSize.width,
|
1296 | y: end.y
|
1297 | };
|
1298 | const d1 = NumberUtils.getDistances(begin, endNE);
|
1299 |
|
1300 | if (d1.distance <= maxDistance) {
|
1301 | const yi = begin.y - d1.dy / d1.dx * begin.x;
|
1302 | pi1 = {
|
1303 | x: 0,
|
1304 | y: yi
|
1305 | };
|
1306 | pi2 = {
|
1307 | x: canvasSize.width,
|
1308 | y: yi
|
1309 | };
|
1310 | } else {
|
1311 | const endSW = {
|
1312 | x: end.x,
|
1313 | y: end.y - canvasSize.height
|
1314 | };
|
1315 | const d2 = NumberUtils.getDistances(begin, endSW);
|
1316 |
|
1317 | if (d2.distance <= maxDistance) {
|
1318 | const yi = begin.y - d2.dy / d2.dx * begin.x;
|
1319 | const xi = -yi / (d2.dy / d2.dx);
|
1320 | pi1 = {
|
1321 | x: xi,
|
1322 | y: 0
|
1323 | };
|
1324 | pi2 = {
|
1325 | x: xi,
|
1326 | y: canvasSize.height
|
1327 | };
|
1328 | } else {
|
1329 | const endSE = {
|
1330 | x: end.x - canvasSize.width,
|
1331 | y: end.y - canvasSize.height
|
1332 | };
|
1333 | const d3 = NumberUtils.getDistances(begin, endSE);
|
1334 |
|
1335 | if (d3.distance <= maxDistance) {
|
1336 | const yi = begin.y - d3.dy / d3.dx * begin.x;
|
1337 | const xi = -yi / (d3.dy / d3.dx);
|
1338 | pi1 = {
|
1339 | x: xi,
|
1340 | y: yi
|
1341 | };
|
1342 | pi2 = {
|
1343 | x: pi1.x + canvasSize.width,
|
1344 | y: pi1.y + canvasSize.height
|
1345 | };
|
1346 | }
|
1347 | }
|
1348 | }
|
1349 |
|
1350 | if (pi1 && pi2) {
|
1351 | drawLine(context, begin, pi1);
|
1352 | drawLine(context, end, pi2);
|
1353 | drawn = true;
|
1354 | }
|
1355 | }
|
1356 |
|
1357 | if (!drawn) {
|
1358 | return;
|
1359 | }
|
1360 |
|
1361 | context.lineWidth = width;
|
1362 |
|
1363 | if (backgroundMask) {
|
1364 | context.globalCompositeOperation = composite;
|
1365 | }
|
1366 |
|
1367 | context.strokeStyle = ColorUtils.getStyleFromRgb(colorLine, opacity);
|
1368 |
|
1369 | if (shadow.enable) {
|
1370 | const shadowColor = ColorUtils.colorToRgb(shadow.color);
|
1371 |
|
1372 | if (shadowColor) {
|
1373 | context.shadowBlur = shadow.blur;
|
1374 | context.shadowColor = ColorUtils.getStyleFromRgb(shadowColor);
|
1375 | }
|
1376 | }
|
1377 |
|
1378 | context.stroke();
|
1379 | }
|
1380 |
|
1381 | static drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) {
|
1382 | drawTriangle(context, pos1, pos2, pos3);
|
1383 |
|
1384 | if (backgroundMask) {
|
1385 | context.globalCompositeOperation = composite;
|
1386 | }
|
1387 |
|
1388 | context.fillStyle = ColorUtils.getStyleFromRgb(colorTriangle, opacityTriangle);
|
1389 | context.fill();
|
1390 | }
|
1391 |
|
1392 | static drawConnectLine(context, width, lineStyle, begin, end) {
|
1393 | context.save();
|
1394 | drawLine(context, begin, end);
|
1395 | context.lineWidth = width;
|
1396 | context.strokeStyle = lineStyle;
|
1397 | context.stroke();
|
1398 | context.restore();
|
1399 | }
|
1400 |
|
1401 | static gradient(context, p1, p2, opacity) {
|
1402 | const gradStop = Math.floor(p2.getRadius() / p1.getRadius());
|
1403 | const color1 = p1.getFillColor();
|
1404 | const color2 = p2.getFillColor();
|
1405 |
|
1406 | if (!color1 || !color2) {
|
1407 | return;
|
1408 | }
|
1409 |
|
1410 | const sourcePos = p1.getPosition();
|
1411 | const destPos = p2.getPosition();
|
1412 | const midRgb = ColorUtils.mix(color1, color2, p1.getRadius(), p2.getRadius());
|
1413 | const grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
|
1414 | grad.addColorStop(0, ColorUtils.getStyleFromHsl(color1, opacity));
|
1415 | grad.addColorStop(gradStop > 1 ? 1 : gradStop, ColorUtils.getStyleFromRgb(midRgb, opacity));
|
1416 | grad.addColorStop(1, ColorUtils.getStyleFromHsl(color2, opacity));
|
1417 | return grad;
|
1418 | }
|
1419 |
|
1420 | static drawGrabLine(context, width, begin, end, colorLine, opacity) {
|
1421 | context.save();
|
1422 | drawLine(context, begin, end);
|
1423 | context.strokeStyle = ColorUtils.getStyleFromRgb(colorLine, opacity);
|
1424 | context.lineWidth = width;
|
1425 | context.stroke();
|
1426 | context.restore();
|
1427 | }
|
1428 |
|
1429 | static drawLight(container, context, mousePos) {
|
1430 | const lightOptions = container.actualOptions.interactivity.modes.light.area;
|
1431 | context.beginPath();
|
1432 | context.arc(mousePos.x, mousePos.y, lightOptions.radius, 0, 2 * Math.PI);
|
1433 | const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, 0, mousePos.x, mousePos.y, lightOptions.radius);
|
1434 | const gradient = lightOptions.gradient;
|
1435 | const gradientRgb = {
|
1436 | start: ColorUtils.colorToRgb(gradient.start),
|
1437 | stop: ColorUtils.colorToRgb(gradient.stop)
|
1438 | };
|
1439 |
|
1440 | if (!gradientRgb.start || !gradientRgb.stop) {
|
1441 | return;
|
1442 | }
|
1443 |
|
1444 | gradientAmbientLight.addColorStop(0, ColorUtils.getStyleFromRgb(gradientRgb.start));
|
1445 | gradientAmbientLight.addColorStop(1, ColorUtils.getStyleFromRgb(gradientRgb.stop));
|
1446 | context.fillStyle = gradientAmbientLight;
|
1447 | context.fill();
|
1448 | }
|
1449 |
|
1450 | static drawParticleShadow(container, context, particle, mousePos) {
|
1451 | const pos = particle.getPosition();
|
1452 | const shadowOptions = container.actualOptions.interactivity.modes.light.shadow;
|
1453 | context.save();
|
1454 | const radius = particle.getRadius();
|
1455 | const sides = particle.sides;
|
1456 | const full = Math.PI * 2 / sides;
|
1457 | const angle = -particle.rotate.value + Math.PI / 4;
|
1458 | const factor = 1;
|
1459 | const dots = [];
|
1460 |
|
1461 | for (let i = 0; i < sides; i++) {
|
1462 | dots.push({
|
1463 | x: pos.x + radius * Math.sin(angle + full * i) * factor,
|
1464 | y: pos.y + radius * Math.cos(angle + full * i) * factor
|
1465 | });
|
1466 | }
|
1467 |
|
1468 | const points = [];
|
1469 | const shadowLength = shadowOptions.length;
|
1470 |
|
1471 | for (const dot of dots) {
|
1472 | const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x);
|
1473 | const endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2);
|
1474 | const endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2);
|
1475 | points.push({
|
1476 | endX: endX,
|
1477 | endY: endY,
|
1478 | startX: dot.x,
|
1479 | startY: dot.y
|
1480 | });
|
1481 | }
|
1482 |
|
1483 | const shadowRgb = ColorUtils.colorToRgb(shadowOptions.color);
|
1484 |
|
1485 | if (!shadowRgb) {
|
1486 | return;
|
1487 | }
|
1488 |
|
1489 | const shadowColor = ColorUtils.getStyleFromRgb(shadowRgb);
|
1490 |
|
1491 | for (let i = points.length - 1; i >= 0; i--) {
|
1492 | const n = i == points.length - 1 ? 0 : i + 1;
|
1493 | context.beginPath();
|
1494 | context.moveTo(points[i].startX, points[i].startY);
|
1495 | context.lineTo(points[n].startX, points[n].startY);
|
1496 | context.lineTo(points[n].endX, points[n].endY);
|
1497 | context.lineTo(points[i].endX, points[i].endY);
|
1498 | context.fillStyle = shadowColor;
|
1499 | context.fill();
|
1500 | }
|
1501 |
|
1502 | context.restore();
|
1503 | }
|
1504 |
|
1505 | static drawParticle(container, context, particle, delta, fillColorValue, strokeColorValue, backgroundMask, composite, radius, opacity, shadow) {
|
1506 | const pos = particle.getPosition();
|
1507 | context.save();
|
1508 | context.translate(pos.x, pos.y);
|
1509 | context.beginPath();
|
1510 | const angle = particle.rotate.value + (particle.options.rotate.path ? particle.velocity.angle : 0);
|
1511 |
|
1512 | if (angle !== 0) {
|
1513 | context.rotate(angle);
|
1514 | }
|
1515 |
|
1516 | if (backgroundMask) {
|
1517 | context.globalCompositeOperation = composite;
|
1518 | }
|
1519 |
|
1520 | const shadowColor = particle.shadowColor;
|
1521 |
|
1522 | if (shadow.enable && shadowColor) {
|
1523 | context.shadowBlur = shadow.blur;
|
1524 | context.shadowColor = ColorUtils.getStyleFromRgb(shadowColor);
|
1525 | context.shadowOffsetX = shadow.offset.x;
|
1526 | context.shadowOffsetY = shadow.offset.y;
|
1527 | }
|
1528 |
|
1529 | if (fillColorValue) {
|
1530 | context.fillStyle = fillColorValue;
|
1531 | }
|
1532 |
|
1533 | const stroke = particle.stroke;
|
1534 | context.lineWidth = particle.strokeWidth;
|
1535 |
|
1536 | if (strokeColorValue) {
|
1537 | context.strokeStyle = strokeColorValue;
|
1538 | }
|
1539 |
|
1540 | CanvasUtils.drawShape(container, context, particle, radius, opacity, delta);
|
1541 |
|
1542 | if (stroke.width > 0) {
|
1543 | context.stroke();
|
1544 | }
|
1545 |
|
1546 | if (particle.close) {
|
1547 | context.closePath();
|
1548 | }
|
1549 |
|
1550 | if (particle.fill) {
|
1551 | context.fill();
|
1552 | }
|
1553 |
|
1554 | context.restore();
|
1555 | context.save();
|
1556 | context.translate(pos.x, pos.y);
|
1557 |
|
1558 | if (angle !== 0) {
|
1559 | context.rotate(angle);
|
1560 | }
|
1561 |
|
1562 | if (backgroundMask) {
|
1563 | context.globalCompositeOperation = composite;
|
1564 | }
|
1565 |
|
1566 | CanvasUtils.drawShapeAfterEffect(container, context, particle, radius, opacity, delta);
|
1567 | context.restore();
|
1568 | }
|
1569 |
|
1570 | static drawShape(container, context, particle, radius, opacity, delta) {
|
1571 | if (!particle.shape) {
|
1572 | return;
|
1573 | }
|
1574 |
|
1575 | const drawer = container.drawers.get(particle.shape);
|
1576 |
|
1577 | if (!drawer) {
|
1578 | return;
|
1579 | }
|
1580 |
|
1581 | drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
1582 | }
|
1583 |
|
1584 | static drawShapeAfterEffect(container, context, particle, radius, opacity, delta) {
|
1585 | if (!particle.shape) {
|
1586 | return;
|
1587 | }
|
1588 |
|
1589 | const drawer = container.drawers.get(particle.shape);
|
1590 |
|
1591 | if (!(drawer === null || drawer === void 0 ? void 0 : drawer.afterEffect)) {
|
1592 | return;
|
1593 | }
|
1594 |
|
1595 | drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio);
|
1596 | }
|
1597 |
|
1598 | static drawPlugin(context, plugin, delta) {
|
1599 | if (plugin.draw !== undefined) {
|
1600 | context.save();
|
1601 | plugin.draw(context, delta);
|
1602 | context.restore();
|
1603 | }
|
1604 | }
|
1605 |
|
1606 | }
|
1607 | ;
|
1608 | class Range {
|
1609 | constructor(x, y) {
|
1610 | this.position = {
|
1611 | x: x,
|
1612 | y: y
|
1613 | };
|
1614 | }
|
1615 |
|
1616 | }
|
1617 | ;
|
1618 |
|
1619 | class Circle extends Range {
|
1620 | constructor(x, y, radius) {
|
1621 | super(x, y);
|
1622 | this.radius = radius;
|
1623 | }
|
1624 |
|
1625 | contains(point) {
|
1626 | const d = Math.pow(point.x - this.position.x, 2) + Math.pow(point.y - this.position.y, 2);
|
1627 | return d <= this.radius * this.radius;
|
1628 | }
|
1629 |
|
1630 | intersects(range) {
|
1631 | const rect = range;
|
1632 | const circle = range;
|
1633 | const pos1 = this.position;
|
1634 | const pos2 = range.position;
|
1635 | const xDist = Math.abs(pos2.x - pos1.x);
|
1636 | const yDist = Math.abs(pos2.y - pos1.y);
|
1637 | const r = this.radius;
|
1638 |
|
1639 | if (circle.radius !== undefined) {
|
1640 | const rSum = r + circle.radius;
|
1641 | const dist = Math.sqrt(xDist * xDist + yDist + yDist);
|
1642 | return rSum > dist;
|
1643 | } else if (rect.size !== undefined) {
|
1644 | const w = rect.size.width;
|
1645 | const h = rect.size.height;
|
1646 | const edges = Math.pow(xDist - w, 2) + Math.pow(yDist - h, 2);
|
1647 |
|
1648 | if (xDist > r + w || yDist > r + h) {
|
1649 | return false;
|
1650 | }
|
1651 |
|
1652 | if (xDist <= w || yDist <= h) {
|
1653 | return true;
|
1654 | }
|
1655 |
|
1656 | return edges <= r * r;
|
1657 | }
|
1658 |
|
1659 | return false;
|
1660 | }
|
1661 |
|
1662 | }
|
1663 | ;
|
1664 |
|
1665 | class Rectangle extends Range {
|
1666 | constructor(x, y, width, height) {
|
1667 | super(x, y);
|
1668 | this.size = {
|
1669 | height: height,
|
1670 | width: width
|
1671 | };
|
1672 | }
|
1673 |
|
1674 | contains(point) {
|
1675 | const w = this.size.width;
|
1676 | const h = this.size.height;
|
1677 | const pos = this.position;
|
1678 | return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h;
|
1679 | }
|
1680 |
|
1681 | intersects(range) {
|
1682 | const rect = range;
|
1683 | const circle = range;
|
1684 | const w = this.size.width;
|
1685 | const h = this.size.height;
|
1686 | const pos1 = this.position;
|
1687 | const pos2 = range.position;
|
1688 |
|
1689 | if (circle.radius !== undefined) {
|
1690 | return circle.intersects(this);
|
1691 | } else if (rect.size !== undefined) {
|
1692 | const size2 = rect.size;
|
1693 | const w2 = size2.width;
|
1694 | const h2 = size2.height;
|
1695 | return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y;
|
1696 | }
|
1697 |
|
1698 | return false;
|
1699 | }
|
1700 |
|
1701 | }
|
1702 | ;
|
1703 |
|
1704 |
|
1705 | class CircleWarp extends Circle {
|
1706 | constructor(x, y, radius, canvasSize) {
|
1707 | super(x, y, radius);
|
1708 | this.canvasSize = canvasSize;
|
1709 | this.canvasSize = {
|
1710 | height: canvasSize.height,
|
1711 | width: canvasSize.width
|
1712 | };
|
1713 | }
|
1714 |
|
1715 | contains(point) {
|
1716 | if (super.contains(point)) {
|
1717 | return true;
|
1718 | }
|
1719 |
|
1720 | const posNE = {
|
1721 | x: point.x - this.canvasSize.width,
|
1722 | y: point.y
|
1723 | };
|
1724 |
|
1725 | if (super.contains(posNE)) {
|
1726 | return true;
|
1727 | }
|
1728 |
|
1729 | const posSE = {
|
1730 | x: point.x - this.canvasSize.width,
|
1731 | y: point.y - this.canvasSize.height
|
1732 | };
|
1733 |
|
1734 | if (super.contains(posSE)) {
|
1735 | return true;
|
1736 | }
|
1737 |
|
1738 | const posSW = {
|
1739 | x: point.x,
|
1740 | y: point.y - this.canvasSize.height
|
1741 | };
|
1742 | return super.contains(posSW);
|
1743 | }
|
1744 |
|
1745 | intersects(range) {
|
1746 | if (super.intersects(range)) {
|
1747 | return true;
|
1748 | }
|
1749 |
|
1750 | const rect = range;
|
1751 | const circle = range;
|
1752 | const newPos = {
|
1753 | x: range.position.x - this.canvasSize.width,
|
1754 | y: range.position.y - this.canvasSize.height
|
1755 | };
|
1756 |
|
1757 | if (circle.radius !== undefined) {
|
1758 | const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * 2);
|
1759 | return super.intersects(biggerCircle);
|
1760 | } else if (rect.size !== undefined) {
|
1761 | const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2);
|
1762 | return super.intersects(rectSW);
|
1763 | }
|
1764 |
|
1765 | return false;
|
1766 | }
|
1767 |
|
1768 | }
|
1769 | ;
|
1770 | var ClickMode;
|
1771 |
|
1772 | (function (ClickMode) {
|
1773 | ClickMode["attract"] = "attract";
|
1774 | ClickMode["bubble"] = "bubble";
|
1775 | ClickMode["push"] = "push";
|
1776 | ClickMode["remove"] = "remove";
|
1777 | ClickMode["repulse"] = "repulse";
|
1778 | ClickMode["pause"] = "pause";
|
1779 | ClickMode["trail"] = "trail";
|
1780 | })(ClickMode || (ClickMode = {}));
|
1781 | ;
|
1782 | var DestroyMode;
|
1783 |
|
1784 | (function (DestroyMode) {
|
1785 | DestroyMode["none"] = "none";
|
1786 | DestroyMode["split"] = "split";
|
1787 | })(DestroyMode || (DestroyMode = {}));
|
1788 | ;
|
1789 | var DivMode;
|
1790 |
|
1791 | (function (DivMode) {
|
1792 | DivMode["bounce"] = "bounce";
|
1793 | DivMode["bubble"] = "bubble";
|
1794 | DivMode["repulse"] = "repulse";
|
1795 | })(DivMode || (DivMode = {}));
|
1796 | ;
|
1797 | var HoverMode;
|
1798 |
|
1799 | (function (HoverMode) {
|
1800 | HoverMode["attract"] = "attract";
|
1801 | HoverMode["bounce"] = "bounce";
|
1802 | HoverMode["bubble"] = "bubble";
|
1803 | HoverMode["connect"] = "connect";
|
1804 | HoverMode["grab"] = "grab";
|
1805 | HoverMode["light"] = "light";
|
1806 | HoverMode["repulse"] = "repulse";
|
1807 | HoverMode["slow"] = "slow";
|
1808 | HoverMode["trail"] = "trail";
|
1809 | })(HoverMode || (HoverMode = {}));
|
1810 | ;
|
1811 | var CollisionMode;
|
1812 |
|
1813 | (function (CollisionMode) {
|
1814 | CollisionMode["absorb"] = "absorb";
|
1815 | CollisionMode["bounce"] = "bounce";
|
1816 | CollisionMode["destroy"] = "destroy";
|
1817 | })(CollisionMode || (CollisionMode = {}));
|
1818 | ;
|
1819 | var OutMode;
|
1820 |
|
1821 | (function (OutMode) {
|
1822 | OutMode["bounce"] = "bounce";
|
1823 | OutMode["bounceHorizontal"] = "bounce-horizontal";
|
1824 | OutMode["bounceVertical"] = "bounce-vertical";
|
1825 | OutMode["none"] = "none";
|
1826 | OutMode["out"] = "out";
|
1827 | OutMode["destroy"] = "destroy";
|
1828 | OutMode["split"] = "split";
|
1829 | })(OutMode || (OutMode = {}));
|
1830 | ;
|
1831 | var SizeMode;
|
1832 |
|
1833 | (function (SizeMode) {
|
1834 | SizeMode["precise"] = "precise";
|
1835 | SizeMode["percent"] = "percent";
|
1836 | })(SizeMode || (SizeMode = {}));
|
1837 | ;
|
1838 | var ThemeMode;
|
1839 |
|
1840 | (function (ThemeMode) {
|
1841 | ThemeMode["any"] = "any";
|
1842 | ThemeMode["dark"] = "dark";
|
1843 | ThemeMode["light"] = "light";
|
1844 | })(ThemeMode || (ThemeMode = {}));
|
1845 | ;
|
1846 |
|
1847 |
|
1848 |
|
1849 |
|
1850 |
|
1851 |
|
1852 |
|
1853 |
|
1854 | ;
|
1855 | var AnimationStatus;
|
1856 |
|
1857 | (function (AnimationStatus) {
|
1858 | AnimationStatus[AnimationStatus["increasing"] = 0] = "increasing";
|
1859 | AnimationStatus[AnimationStatus["decreasing"] = 1] = "decreasing";
|
1860 | })(AnimationStatus || (AnimationStatus = {}));
|
1861 | ;
|
1862 | var DestroyType;
|
1863 |
|
1864 | (function (DestroyType) {
|
1865 | DestroyType["none"] = "none";
|
1866 | DestroyType["max"] = "max";
|
1867 | DestroyType["min"] = "min";
|
1868 | })(DestroyType || (DestroyType = {}));
|
1869 | ;
|
1870 | var ProcessBubbleType;
|
1871 |
|
1872 | (function (ProcessBubbleType) {
|
1873 | ProcessBubbleType["color"] = "color";
|
1874 | ProcessBubbleType["opacity"] = "opacity";
|
1875 | ProcessBubbleType["size"] = "size";
|
1876 | })(ProcessBubbleType || (ProcessBubbleType = {}));
|
1877 | ;
|
1878 | var ShapeType;
|
1879 |
|
1880 | (function (ShapeType) {
|
1881 | ShapeType["char"] = "char";
|
1882 | ShapeType["character"] = "character";
|
1883 | ShapeType["circle"] = "circle";
|
1884 | ShapeType["edge"] = "edge";
|
1885 | ShapeType["image"] = "image";
|
1886 | ShapeType["images"] = "images";
|
1887 | ShapeType["line"] = "line";
|
1888 | ShapeType["polygon"] = "polygon";
|
1889 | ShapeType["square"] = "square";
|
1890 | ShapeType["star"] = "star";
|
1891 | ShapeType["triangle"] = "triangle";
|
1892 | })(ShapeType || (ShapeType = {}));
|
1893 | ;
|
1894 | var StartValueType;
|
1895 |
|
1896 | (function (StartValueType) {
|
1897 | StartValueType["max"] = "max";
|
1898 | StartValueType["min"] = "min";
|
1899 | StartValueType["random"] = "random";
|
1900 | })(StartValueType || (StartValueType = {}));
|
1901 | ;
|
1902 | var DivType;
|
1903 |
|
1904 | (function (DivType) {
|
1905 | DivType["circle"] = "circle";
|
1906 | DivType["rectangle"] = "rectangle";
|
1907 | })(DivType || (DivType = {}));
|
1908 | ;
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 | ;
|
1915 | var InteractivityDetect;
|
1916 |
|
1917 | (function (InteractivityDetect) {
|
1918 | InteractivityDetect["canvas"] = "canvas";
|
1919 | InteractivityDetect["parent"] = "parent";
|
1920 | InteractivityDetect["window"] = "window";
|
1921 | })(InteractivityDetect || (InteractivityDetect = {}));
|
1922 | ;
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 | ;
|
1929 |
|
1930 |
|
1931 |
|
1932 | function manageListener(element, event, handler, add, options) {
|
1933 | if (add) {
|
1934 | let addOptions = {
|
1935 | passive: true
|
1936 | };
|
1937 |
|
1938 | if (typeof options === "boolean") {
|
1939 | addOptions.capture = options;
|
1940 | } else if (options !== undefined) {
|
1941 | addOptions = options;
|
1942 | }
|
1943 |
|
1944 | element.addEventListener(event, handler, addOptions);
|
1945 | } else {
|
1946 | const removeOptions = options;
|
1947 | element.removeEventListener(event, handler, removeOptions);
|
1948 | }
|
1949 | }
|
1950 |
|
1951 | class EventListeners {
|
1952 | constructor(container) {
|
1953 | this.container = container;
|
1954 | this.canPush = true;
|
1955 |
|
1956 | this.mouseMoveHandler = e => this.mouseTouchMove(e);
|
1957 |
|
1958 | this.touchStartHandler = e => this.mouseTouchMove(e);
|
1959 |
|
1960 | this.touchMoveHandler = e => this.mouseTouchMove(e);
|
1961 |
|
1962 | this.touchEndHandler = () => this.mouseTouchFinish();
|
1963 |
|
1964 | this.mouseLeaveHandler = () => this.mouseTouchFinish();
|
1965 |
|
1966 | this.touchCancelHandler = () => this.mouseTouchFinish();
|
1967 |
|
1968 | this.touchEndClickHandler = e => this.mouseTouchClick(e);
|
1969 |
|
1970 | this.mouseUpHandler = e => this.mouseTouchClick(e);
|
1971 |
|
1972 | this.mouseDownHandler = () => this.mouseDown();
|
1973 |
|
1974 | this.visibilityChangeHandler = () => this.handleVisibilityChange();
|
1975 |
|
1976 | this.resizeHandler = () => this.handleWindowResize();
|
1977 | }
|
1978 |
|
1979 | addListeners() {
|
1980 | this.manageListeners(true);
|
1981 | }
|
1982 |
|
1983 | removeListeners() {
|
1984 | this.manageListeners(false);
|
1985 | }
|
1986 |
|
1987 | manageListeners(add) {
|
1988 | var _a;
|
1989 |
|
1990 | const container = this.container;
|
1991 | const options = container.actualOptions;
|
1992 | const detectType = options.interactivity.detectsOn;
|
1993 | let mouseLeaveEvent = Constants.mouseLeaveEvent;
|
1994 |
|
1995 | if (detectType === InteractivityDetect.window) {
|
1996 | container.interactivity.element = window;
|
1997 | mouseLeaveEvent = Constants.mouseOutEvent;
|
1998 | } else if (detectType === InteractivityDetect.parent && container.canvas.element) {
|
1999 | const canvasEl = container.canvas.element;
|
2000 | container.interactivity.element = (_a = canvasEl.parentElement) !== null && _a !== void 0 ? _a : canvasEl.parentNode;
|
2001 | } else {
|
2002 | container.interactivity.element = container.canvas.element;
|
2003 | }
|
2004 |
|
2005 | const interactivityEl = container.interactivity.element;
|
2006 |
|
2007 | if (!interactivityEl) {
|
2008 | return;
|
2009 | }
|
2010 |
|
2011 | const html = interactivityEl;
|
2012 |
|
2013 | if (options.interactivity.events.onHover.enable || options.interactivity.events.onClick.enable) {
|
2014 | manageListener(interactivityEl, Constants.mouseMoveEvent, this.mouseMoveHandler, add);
|
2015 | manageListener(interactivityEl, Constants.touchStartEvent, this.touchStartHandler, add);
|
2016 | manageListener(interactivityEl, Constants.touchMoveEvent, this.touchMoveHandler, add);
|
2017 |
|
2018 | if (!options.interactivity.events.onClick.enable) {
|
2019 | manageListener(interactivityEl, Constants.touchEndEvent, this.touchEndHandler, add);
|
2020 | } else {
|
2021 | manageListener(interactivityEl, Constants.touchEndEvent, this.touchEndClickHandler, add);
|
2022 | manageListener(interactivityEl, Constants.mouseUpEvent, this.mouseUpHandler, add);
|
2023 | manageListener(interactivityEl, Constants.mouseDownEvent, this.mouseDownHandler, add);
|
2024 | }
|
2025 |
|
2026 | manageListener(interactivityEl, mouseLeaveEvent, this.mouseLeaveHandler, add);
|
2027 | manageListener(interactivityEl, Constants.touchCancelEvent, this.touchCancelHandler, add);
|
2028 | }
|
2029 |
|
2030 | if (container.canvas.element) {
|
2031 | container.canvas.element.style.pointerEvents = html === container.canvas.element ? "initial" : "none";
|
2032 | }
|
2033 |
|
2034 | if (options.interactivity.events.resize) {
|
2035 | manageListener(window, Constants.resizeEvent, this.resizeHandler, add);
|
2036 | }
|
2037 |
|
2038 | if (document) {
|
2039 | manageListener(document, Constants.visibilityChangeEvent, this.visibilityChangeHandler, add, false);
|
2040 | }
|
2041 | }
|
2042 |
|
2043 | handleWindowResize() {
|
2044 | var _a;
|
2045 |
|
2046 | (_a = this.container.canvas) === null || _a === void 0 ? void 0 : _a.windowResize();
|
2047 | }
|
2048 |
|
2049 | handleVisibilityChange() {
|
2050 | const container = this.container;
|
2051 | const options = container.actualOptions;
|
2052 | this.mouseTouchFinish();
|
2053 |
|
2054 | if (!options.pauseOnBlur) {
|
2055 | return;
|
2056 | }
|
2057 |
|
2058 | if (document === null || document === void 0 ? void 0 : document.hidden) {
|
2059 | container.pageHidden = true;
|
2060 | container.pause();
|
2061 | } else {
|
2062 | container.pageHidden = false;
|
2063 |
|
2064 | if (container.getAnimationStatus()) {
|
2065 | container.play(true);
|
2066 | } else {
|
2067 | container.draw();
|
2068 | }
|
2069 | }
|
2070 | }
|
2071 |
|
2072 | mouseDown() {
|
2073 | const interactivity = this.container.interactivity;
|
2074 |
|
2075 | if (interactivity) {
|
2076 | const mouse = interactivity.mouse;
|
2077 | mouse.clicking = true;
|
2078 | mouse.downPosition = mouse.position;
|
2079 | }
|
2080 | }
|
2081 |
|
2082 | mouseTouchMove(e) {
|
2083 | var _a, _b, _c, _d, _e, _f, _g;
|
2084 |
|
2085 | const container = this.container;
|
2086 | const options = container.actualOptions;
|
2087 |
|
2088 | if (((_a = container.interactivity) === null || _a === void 0 ? void 0 : _a.element) === undefined) {
|
2089 | return;
|
2090 | }
|
2091 |
|
2092 | container.interactivity.mouse.inside = true;
|
2093 | let pos;
|
2094 | const canvas = container.canvas.element;
|
2095 |
|
2096 | if (e.type.startsWith("mouse")) {
|
2097 | this.canPush = true;
|
2098 | const mouseEvent = e;
|
2099 |
|
2100 | if (container.interactivity.element === window) {
|
2101 | if (canvas) {
|
2102 | const clientRect = canvas.getBoundingClientRect();
|
2103 | pos = {
|
2104 | x: mouseEvent.clientX - clientRect.left,
|
2105 | y: mouseEvent.clientY - clientRect.top
|
2106 | };
|
2107 | }
|
2108 | } else if (options.interactivity.detectsOn === InteractivityDetect.parent) {
|
2109 | const source = mouseEvent.target;
|
2110 | const target = mouseEvent.currentTarget;
|
2111 | const canvasEl = container.canvas.element;
|
2112 |
|
2113 | if (source && target && canvasEl) {
|
2114 | const sourceRect = source.getBoundingClientRect();
|
2115 | const targetRect = target.getBoundingClientRect();
|
2116 | const canvasRect = canvasEl.getBoundingClientRect();
|
2117 | pos = {
|
2118 | x: mouseEvent.offsetX + 2 * sourceRect.left - (targetRect.left + canvasRect.left),
|
2119 | y: mouseEvent.offsetY + 2 * sourceRect.top - (targetRect.top + canvasRect.top)
|
2120 | };
|
2121 | } else {
|
2122 | pos = {
|
2123 | x: (_b = mouseEvent.offsetX) !== null && _b !== void 0 ? _b : mouseEvent.clientX,
|
2124 | y: (_c = mouseEvent.offsetY) !== null && _c !== void 0 ? _c : mouseEvent.clientY
|
2125 | };
|
2126 | }
|
2127 | } else {
|
2128 | if (mouseEvent.target === container.canvas.element) {
|
2129 | pos = {
|
2130 | x: (_d = mouseEvent.offsetX) !== null && _d !== void 0 ? _d : mouseEvent.clientX,
|
2131 | y: (_e = mouseEvent.offsetY) !== null && _e !== void 0 ? _e : mouseEvent.clientY
|
2132 | };
|
2133 | }
|
2134 | }
|
2135 | } else {
|
2136 | this.canPush = e.type !== "touchmove";
|
2137 | const touchEvent = e;
|
2138 | const lastTouch = touchEvent.touches[touchEvent.touches.length - 1];
|
2139 | const canvasRect = canvas === null || canvas === void 0 ? void 0 : canvas.getBoundingClientRect();
|
2140 | pos = {
|
2141 | x: lastTouch.clientX - ((_f = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) !== null && _f !== void 0 ? _f : 0),
|
2142 | y: lastTouch.clientY - ((_g = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) !== null && _g !== void 0 ? _g : 0)
|
2143 | };
|
2144 | }
|
2145 |
|
2146 | const pxRatio = container.retina.pixelRatio;
|
2147 |
|
2148 | if (pos) {
|
2149 | pos.x *= pxRatio;
|
2150 | pos.y *= pxRatio;
|
2151 | }
|
2152 |
|
2153 | container.interactivity.mouse.position = pos;
|
2154 | container.interactivity.status = Constants.mouseMoveEvent;
|
2155 | }
|
2156 |
|
2157 | mouseTouchFinish() {
|
2158 | const interactivity = this.container.interactivity;
|
2159 |
|
2160 | if (interactivity === undefined) {
|
2161 | return;
|
2162 | }
|
2163 |
|
2164 | const mouse = interactivity.mouse;
|
2165 | delete mouse.position;
|
2166 | delete mouse.clickPosition;
|
2167 | delete mouse.downPosition;
|
2168 | interactivity.status = Constants.mouseLeaveEvent;
|
2169 | mouse.inside = false;
|
2170 | mouse.clicking = false;
|
2171 | }
|
2172 |
|
2173 | mouseTouchClick(e) {
|
2174 | const container = this.container;
|
2175 | const options = container.actualOptions;
|
2176 | const mouse = container.interactivity.mouse;
|
2177 | mouse.inside = true;
|
2178 | let handled = false;
|
2179 | const mousePosition = mouse.position;
|
2180 |
|
2181 | if (mousePosition === undefined || !options.interactivity.events.onClick.enable) {
|
2182 | return;
|
2183 | }
|
2184 |
|
2185 | for (const [, plugin] of container.plugins) {
|
2186 | if (plugin.clickPositionValid !== undefined) {
|
2187 | handled = plugin.clickPositionValid(mousePosition);
|
2188 |
|
2189 | if (handled) {
|
2190 | break;
|
2191 | }
|
2192 | }
|
2193 | }
|
2194 |
|
2195 | if (!handled) {
|
2196 | this.doMouseTouchClick(e);
|
2197 | }
|
2198 |
|
2199 | mouse.clicking = false;
|
2200 | }
|
2201 |
|
2202 | doMouseTouchClick(e) {
|
2203 | const container = this.container;
|
2204 | const options = container.actualOptions;
|
2205 |
|
2206 | if (this.canPush) {
|
2207 | const mousePos = container.interactivity.mouse.position;
|
2208 |
|
2209 | if (mousePos) {
|
2210 | container.interactivity.mouse.clickPosition = {
|
2211 | x: mousePos.x,
|
2212 | y: mousePos.y
|
2213 | };
|
2214 | } else {
|
2215 | return;
|
2216 | }
|
2217 |
|
2218 | container.interactivity.mouse.clickTime = new Date().getTime();
|
2219 | const onClick = options.interactivity.events.onClick;
|
2220 |
|
2221 | if (onClick.mode instanceof Array) {
|
2222 | for (const mode of onClick.mode) {
|
2223 | this.handleClickMode(mode);
|
2224 | }
|
2225 | } else {
|
2226 | this.handleClickMode(onClick.mode);
|
2227 | }
|
2228 | }
|
2229 |
|
2230 | if (e.type === "touchend") {
|
2231 | setTimeout(() => this.mouseTouchFinish(), 500);
|
2232 | }
|
2233 | }
|
2234 |
|
2235 | handleClickMode(mode) {
|
2236 | const container = this.container;
|
2237 | const options = container.actualOptions;
|
2238 | const pushNb = options.interactivity.modes.push.quantity;
|
2239 | const removeNb = options.interactivity.modes.remove.quantity;
|
2240 |
|
2241 | switch (mode) {
|
2242 | case ClickMode.push:
|
2243 | {
|
2244 | if (pushNb > 0) {
|
2245 | container.particles.push(pushNb, container.interactivity.mouse);
|
2246 | }
|
2247 |
|
2248 | break;
|
2249 | }
|
2250 |
|
2251 | case ClickMode.remove:
|
2252 | container.particles.removeQuantity(removeNb);
|
2253 | break;
|
2254 |
|
2255 | case ClickMode.bubble:
|
2256 | container.bubble.clicking = true;
|
2257 | break;
|
2258 |
|
2259 | case ClickMode.repulse:
|
2260 | container.repulse.clicking = true;
|
2261 | container.repulse.count = 0;
|
2262 |
|
2263 | for (const particle of container.repulse.particles) {
|
2264 | particle.velocity.setTo(particle.initialVelocity);
|
2265 | }
|
2266 |
|
2267 | container.repulse.particles = [];
|
2268 | container.repulse.finish = false;
|
2269 | setTimeout(() => {
|
2270 | if (!container.destroyed) {
|
2271 | container.repulse.clicking = false;
|
2272 | }
|
2273 | }, options.interactivity.modes.repulse.duration * 1000);
|
2274 | break;
|
2275 |
|
2276 | case ClickMode.attract:
|
2277 | container.attract.clicking = true;
|
2278 | container.attract.count = 0;
|
2279 |
|
2280 | for (const particle of container.attract.particles) {
|
2281 | particle.velocity.setTo(particle.initialVelocity);
|
2282 | }
|
2283 |
|
2284 | container.attract.particles = [];
|
2285 | container.attract.finish = false;
|
2286 | setTimeout(() => {
|
2287 | if (!container.destroyed) {
|
2288 | container.attract.clicking = false;
|
2289 | }
|
2290 | }, options.interactivity.modes.attract.duration * 1000);
|
2291 | break;
|
2292 |
|
2293 | case ClickMode.pause:
|
2294 | if (container.getAnimationStatus()) {
|
2295 | container.pause();
|
2296 | } else {
|
2297 | container.play();
|
2298 | }
|
2299 |
|
2300 | break;
|
2301 | }
|
2302 |
|
2303 | for (const [, plugin] of container.plugins) {
|
2304 | if (plugin.handleClickMode) {
|
2305 | plugin.handleClickMode(mode);
|
2306 | }
|
2307 | }
|
2308 | }
|
2309 |
|
2310 | }
|
2311 | ;
|
2312 | const plugins = [];
|
2313 | const presets = new Map();
|
2314 | const drawers = new Map();
|
2315 | const pathGenerators = new Map();
|
2316 | class Plugins {
|
2317 | static getPlugin(plugin) {
|
2318 | return plugins.find(t => t.id === plugin);
|
2319 | }
|
2320 |
|
2321 | static addPlugin(plugin) {
|
2322 | if (!Plugins.getPlugin(plugin.id)) {
|
2323 | plugins.push(plugin);
|
2324 | }
|
2325 | }
|
2326 |
|
2327 | static getAvailablePlugins(container) {
|
2328 | const res = new Map();
|
2329 |
|
2330 | for (const plugin of plugins) {
|
2331 | if (!plugin.needsPlugin(container.actualOptions)) {
|
2332 | continue;
|
2333 | }
|
2334 |
|
2335 | res.set(plugin.id, plugin.getPlugin(container));
|
2336 | }
|
2337 |
|
2338 | return res;
|
2339 | }
|
2340 |
|
2341 | static loadOptions(options, sourceOptions) {
|
2342 | for (const plugin of plugins) {
|
2343 | plugin.loadOptions(options, sourceOptions);
|
2344 | }
|
2345 | }
|
2346 |
|
2347 | static getPreset(preset) {
|
2348 | return presets.get(preset);
|
2349 | }
|
2350 |
|
2351 | static addPreset(presetKey, options) {
|
2352 | if (!Plugins.getPreset(presetKey)) {
|
2353 | presets.set(presetKey, options);
|
2354 | }
|
2355 | }
|
2356 |
|
2357 | static addShapeDrawer(type, drawer) {
|
2358 | if (!Plugins.getShapeDrawer(type)) {
|
2359 | drawers.set(type, drawer);
|
2360 | }
|
2361 | }
|
2362 |
|
2363 | static getShapeDrawer(type) {
|
2364 | return drawers.get(type);
|
2365 | }
|
2366 |
|
2367 | static getSupportedShapes() {
|
2368 | return drawers.keys();
|
2369 | }
|
2370 |
|
2371 | static getPathGenerator(type) {
|
2372 | return pathGenerators.get(type);
|
2373 | }
|
2374 |
|
2375 | static addPathGenerator(type, pathGenerator) {
|
2376 | if (!Plugins.getPathGenerator(type)) {
|
2377 | pathGenerators.set(type, pathGenerator);
|
2378 | }
|
2379 | }
|
2380 |
|
2381 | }
|
2382 | ;
|
2383 | class Point {
|
2384 | constructor(position, particle) {
|
2385 | this.position = position;
|
2386 | this.particle = particle;
|
2387 | }
|
2388 |
|
2389 | }
|
2390 | ;
|
2391 |
|
2392 |
|
2393 |
|
2394 | class QuadTree {
|
2395 | constructor(rectangle, capacity) {
|
2396 | this.rectangle = rectangle;
|
2397 | this.capacity = capacity;
|
2398 | this.points = [];
|
2399 | this.divided = false;
|
2400 | }
|
2401 |
|
2402 | subdivide() {
|
2403 | const x = this.rectangle.position.x;
|
2404 | const y = this.rectangle.position.y;
|
2405 | const w = this.rectangle.size.width;
|
2406 | const h = this.rectangle.size.height;
|
2407 | const capacity = this.capacity;
|
2408 | this.northEast = new QuadTree(new Rectangle(x, y, w / 2, h / 2), capacity);
|
2409 | this.northWest = new QuadTree(new Rectangle(x + w / 2, y, w / 2, h / 2), capacity);
|
2410 | this.southEast = new QuadTree(new Rectangle(x, y + h / 2, w / 2, h / 2), capacity);
|
2411 | this.southWest = new QuadTree(new Rectangle(x + w / 2, y + h / 2, w / 2, h / 2), capacity);
|
2412 | this.divided = true;
|
2413 | }
|
2414 |
|
2415 | insert(point) {
|
2416 | var _a, _b, _c, _d, _e;
|
2417 |
|
2418 | if (!this.rectangle.contains(point.position)) {
|
2419 | return false;
|
2420 | }
|
2421 |
|
2422 | if (this.points.length < this.capacity) {
|
2423 | this.points.push(point);
|
2424 | return true;
|
2425 | }
|
2426 |
|
2427 | if (!this.divided) {
|
2428 | this.subdivide();
|
2429 | }
|
2430 |
|
2431 | return (_e = ((_a = this.northEast) === null || _a === void 0 ? void 0 : _a.insert(point)) || ((_b = this.northWest) === null || _b === void 0 ? void 0 : _b.insert(point)) || ((_c = this.southEast) === null || _c === void 0 ? void 0 : _c.insert(point)) || ((_d = this.southWest) === null || _d === void 0 ? void 0 : _d.insert(point))) !== null && _e !== void 0 ? _e : false;
|
2432 | }
|
2433 |
|
2434 | queryCircle(position, radius) {
|
2435 | return this.query(new Circle(position.x, position.y, radius));
|
2436 | }
|
2437 |
|
2438 | queryCircleWarp(position, radius, containerOrSize) {
|
2439 | const container = containerOrSize;
|
2440 | const size = containerOrSize;
|
2441 | return this.query(new CircleWarp(position.x, position.y, radius, container.canvas !== undefined ? container.canvas.size : size));
|
2442 | }
|
2443 |
|
2444 | queryRectangle(position, size) {
|
2445 | return this.query(new Rectangle(position.x, position.y, size.width, size.height));
|
2446 | }
|
2447 |
|
2448 | query(range, found) {
|
2449 | var _a, _b, _c, _d;
|
2450 |
|
2451 | const res = found !== null && found !== void 0 ? found : [];
|
2452 |
|
2453 | if (!range.intersects(this.rectangle)) {
|
2454 | return [];
|
2455 | } else {
|
2456 | for (const p of this.points) {
|
2457 | if (!range.contains(p.position)) {
|
2458 | continue;
|
2459 | }
|
2460 |
|
2461 | res.push(p.particle);
|
2462 | }
|
2463 |
|
2464 | if (this.divided) {
|
2465 | (_a = this.northEast) === null || _a === void 0 ? void 0 : _a.query(range, res);
|
2466 | (_b = this.northWest) === null || _b === void 0 ? void 0 : _b.query(range, res);
|
2467 | (_c = this.southEast) === null || _c === void 0 ? void 0 : _c.query(range, res);
|
2468 | (_d = this.southWest) === null || _d === void 0 ? void 0 : _d.query(range, res);
|
2469 | }
|
2470 | }
|
2471 |
|
2472 | return res;
|
2473 | }
|
2474 |
|
2475 | }
|
2476 | ;
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 |
|
2485 |
|
2486 |
|
2487 |
|
2488 |
|
2489 |
|
2490 | ;
|
2491 | var TextDrawer_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
2492 | function adopt(value) {
|
2493 | return value instanceof P ? value : new P(function (resolve) {
|
2494 | resolve(value);
|
2495 | });
|
2496 | }
|
2497 |
|
2498 | return new (P || (P = Promise))(function (resolve, reject) {
|
2499 | function fulfilled(value) {
|
2500 | try {
|
2501 | step(generator.next(value));
|
2502 | } catch (e) {
|
2503 | reject(e);
|
2504 | }
|
2505 | }
|
2506 |
|
2507 | function rejected(value) {
|
2508 | try {
|
2509 | step(generator["throw"](value));
|
2510 | } catch (e) {
|
2511 | reject(e);
|
2512 | }
|
2513 | }
|
2514 |
|
2515 | function step(result) {
|
2516 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
2517 | }
|
2518 |
|
2519 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
2520 | });
|
2521 | };
|
2522 |
|
2523 |
|
2524 |
|
2525 | class TextDrawer {
|
2526 | getSidesCount() {
|
2527 | return 12;
|
2528 | }
|
2529 |
|
2530 | init(container) {
|
2531 | var _a;
|
2532 |
|
2533 | return TextDrawer_awaiter(this, void 0, void 0, function* () {
|
2534 | const options = container.actualOptions;
|
2535 |
|
2536 | if (Utils.isInArray(ShapeType.char, options.particles.shape.type) || Utils.isInArray(ShapeType.character, options.particles.shape.type)) {
|
2537 | const shapeOptions = (_a = options.particles.shape.options[ShapeType.character]) !== null && _a !== void 0 ? _a : options.particles.shape.options[ShapeType.char];
|
2538 |
|
2539 | if (shapeOptions instanceof Array) {
|
2540 | for (const character of shapeOptions) {
|
2541 | yield Utils.loadFont(character);
|
2542 | }
|
2543 | } else {
|
2544 | if (shapeOptions !== undefined) {
|
2545 | yield Utils.loadFont(shapeOptions);
|
2546 | }
|
2547 | }
|
2548 | }
|
2549 | });
|
2550 | }
|
2551 |
|
2552 | draw(context, particle, radius) {
|
2553 | const character = particle.shapeData;
|
2554 |
|
2555 | if (character === undefined) {
|
2556 | return;
|
2557 | }
|
2558 |
|
2559 | const textData = character.value;
|
2560 |
|
2561 | if (textData === undefined) {
|
2562 | return;
|
2563 | }
|
2564 |
|
2565 | const textParticle = particle;
|
2566 |
|
2567 | if (textParticle.text === undefined) {
|
2568 | textParticle.text = textData instanceof Array ? Utils.itemFromArray(textData, particle.randomIndexData) : textData;
|
2569 | }
|
2570 |
|
2571 | const text = textParticle.text;
|
2572 | const style = character.style;
|
2573 | const weight = character.weight;
|
2574 | const size = Math.round(radius) * 2;
|
2575 | const font = character.font;
|
2576 | const fill = particle.fill;
|
2577 | const offsetX = text.length * radius / 2;
|
2578 | context.font = `${style} ${weight} ${size}px "${font}"`;
|
2579 | const pos = {
|
2580 | x: -offsetX,
|
2581 | y: radius / 2
|
2582 | };
|
2583 |
|
2584 | if (fill) {
|
2585 | context.fillText(text, pos.x, pos.y);
|
2586 | } else {
|
2587 | context.strokeText(text, pos.x, pos.y);
|
2588 | }
|
2589 | }
|
2590 |
|
2591 | }
|
2592 | ;
|
2593 | var ImageDrawer_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
2594 | function adopt(value) {
|
2595 | return value instanceof P ? value : new P(function (resolve) {
|
2596 | resolve(value);
|
2597 | });
|
2598 | }
|
2599 |
|
2600 | return new (P || (P = Promise))(function (resolve, reject) {
|
2601 | function fulfilled(value) {
|
2602 | try {
|
2603 | step(generator.next(value));
|
2604 | } catch (e) {
|
2605 | reject(e);
|
2606 | }
|
2607 | }
|
2608 |
|
2609 | function rejected(value) {
|
2610 | try {
|
2611 | step(generator["throw"](value));
|
2612 | } catch (e) {
|
2613 | reject(e);
|
2614 | }
|
2615 | }
|
2616 |
|
2617 | function step(result) {
|
2618 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
2619 | }
|
2620 |
|
2621 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
2622 | });
|
2623 | };
|
2624 |
|
2625 |
|
2626 |
|
2627 | class ImageDrawer {
|
2628 | constructor() {
|
2629 | this.images = [];
|
2630 | }
|
2631 |
|
2632 | getSidesCount() {
|
2633 | return 12;
|
2634 | }
|
2635 |
|
2636 | getImages(container) {
|
2637 | const containerImages = this.images.filter(t => t.id === container.id);
|
2638 |
|
2639 | if (!containerImages.length) {
|
2640 | this.images.push({
|
2641 | id: container.id,
|
2642 | images: []
|
2643 | });
|
2644 | return this.getImages(container);
|
2645 | }
|
2646 |
|
2647 | return containerImages[0];
|
2648 | }
|
2649 |
|
2650 | addImage(container, image) {
|
2651 | const containerImages = this.getImages(container);
|
2652 | containerImages === null || containerImages === void 0 ? void 0 : containerImages.images.push(image);
|
2653 | }
|
2654 |
|
2655 | init(container) {
|
2656 | var _a;
|
2657 |
|
2658 | return ImageDrawer_awaiter(this, void 0, void 0, function* () {
|
2659 | const options = container.actualOptions;
|
2660 | const shapeOptions = options.particles.shape;
|
2661 |
|
2662 | if (!Utils.isInArray(ShapeType.image, shapeOptions.type) && !Utils.isInArray(ShapeType.images, shapeOptions.type)) {
|
2663 | return;
|
2664 | }
|
2665 |
|
2666 | const imageOptions = (_a = shapeOptions.options[ShapeType.images]) !== null && _a !== void 0 ? _a : shapeOptions.options[ShapeType.image];
|
2667 |
|
2668 | if (imageOptions instanceof Array) {
|
2669 | for (const optionsImage of imageOptions) {
|
2670 | yield this.loadImageShape(container, optionsImage);
|
2671 | }
|
2672 | } else {
|
2673 | yield this.loadImageShape(container, imageOptions);
|
2674 | }
|
2675 | });
|
2676 | }
|
2677 |
|
2678 | destroy() {
|
2679 | this.images = [];
|
2680 | }
|
2681 |
|
2682 | loadImageShape(container, imageShape) {
|
2683 | return ImageDrawer_awaiter(this, void 0, void 0, function* () {
|
2684 | try {
|
2685 | const image = imageShape.replaceColor ? yield Utils.downloadSvgImage(imageShape.src) : yield Utils.loadImage(imageShape.src);
|
2686 |
|
2687 | if (image) {
|
2688 | this.addImage(container, image);
|
2689 | }
|
2690 | } catch (_a) {
|
2691 | console.warn(`tsParticles error - ${imageShape.src} not found`);
|
2692 | }
|
2693 | });
|
2694 | }
|
2695 |
|
2696 | draw(context, particle, radius, opacity) {
|
2697 | var _a, _b;
|
2698 |
|
2699 | if (!context) {
|
2700 | return;
|
2701 | }
|
2702 |
|
2703 | const image = particle.image;
|
2704 | const element = (_a = image === null || image === void 0 ? void 0 : image.data) === null || _a === void 0 ? void 0 : _a.element;
|
2705 |
|
2706 | if (!element) {
|
2707 | return;
|
2708 | }
|
2709 |
|
2710 | const ratio = (_b = image === null || image === void 0 ? void 0 : image.ratio) !== null && _b !== void 0 ? _b : 1;
|
2711 | const pos = {
|
2712 | x: -radius,
|
2713 | y: -radius
|
2714 | };
|
2715 |
|
2716 | if (!(image === null || image === void 0 ? void 0 : image.data.svgData) || !(image === null || image === void 0 ? void 0 : image.replaceColor)) {
|
2717 | context.globalAlpha = opacity;
|
2718 | }
|
2719 |
|
2720 | context.drawImage(element, pos.x, pos.y, radius * 2, radius * 2 / ratio);
|
2721 |
|
2722 | if (!(image === null || image === void 0 ? void 0 : image.data.svgData) || !(image === null || image === void 0 ? void 0 : image.replaceColor)) {
|
2723 | context.globalAlpha = 1;
|
2724 | }
|
2725 | }
|
2726 |
|
2727 | }
|
2728 | ;
|
2729 | class LineDrawer {
|
2730 | getSidesCount() {
|
2731 | return 1;
|
2732 | }
|
2733 |
|
2734 | draw(context, particle, radius) {
|
2735 | context.moveTo(0, -radius / 2);
|
2736 | context.lineTo(0, radius / 2);
|
2737 | }
|
2738 |
|
2739 | }
|
2740 | ;
|
2741 | class CircleDrawer {
|
2742 | getSidesCount() {
|
2743 | return 12;
|
2744 | }
|
2745 |
|
2746 | draw(context, particle, radius) {
|
2747 | context.arc(0, 0, radius, 0, Math.PI * 2, false);
|
2748 | }
|
2749 |
|
2750 | }
|
2751 | ;
|
2752 | class PolygonDrawerBase {
|
2753 | getSidesCount(particle) {
|
2754 | var _a, _b;
|
2755 |
|
2756 | const polygon = particle.shapeData;
|
2757 | return (_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;
|
2758 | }
|
2759 |
|
2760 | draw(context, particle, radius) {
|
2761 | const start = this.getCenter(particle, radius);
|
2762 | const side = this.getSidesData(particle, radius);
|
2763 | const sideCount = side.count.numerator * side.count.denominator;
|
2764 | const decimalSides = side.count.numerator / side.count.denominator;
|
2765 | const interiorAngleDegrees = 180 * (decimalSides - 2) / decimalSides;
|
2766 | const interiorAngle = Math.PI - Math.PI * interiorAngleDegrees / 180;
|
2767 |
|
2768 | if (!context) {
|
2769 | return;
|
2770 | }
|
2771 |
|
2772 | context.beginPath();
|
2773 | context.translate(start.x, start.y);
|
2774 | context.moveTo(0, 0);
|
2775 |
|
2776 | for (let i = 0; i < sideCount; i++) {
|
2777 | context.lineTo(side.length, 0);
|
2778 | context.translate(side.length, 0);
|
2779 | context.rotate(interiorAngle);
|
2780 | }
|
2781 | }
|
2782 |
|
2783 | }
|
2784 | ;
|
2785 |
|
2786 | class TriangleDrawer extends PolygonDrawerBase {
|
2787 | getSidesCount() {
|
2788 | return 3;
|
2789 | }
|
2790 |
|
2791 | getSidesData(particle, radius) {
|
2792 | return {
|
2793 | count: {
|
2794 | denominator: 2,
|
2795 | numerator: 3
|
2796 | },
|
2797 | length: radius * 2
|
2798 | };
|
2799 | }
|
2800 |
|
2801 | getCenter(particle, radius) {
|
2802 | return {
|
2803 | x: -radius,
|
2804 | y: radius / 1.66
|
2805 | };
|
2806 | }
|
2807 |
|
2808 | }
|
2809 | ;
|
2810 | class StarDrawer {
|
2811 | getSidesCount(particle) {
|
2812 | var _a, _b;
|
2813 |
|
2814 | const star = particle.shapeData;
|
2815 | return (_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;
|
2816 | }
|
2817 |
|
2818 | draw(context, particle, radius) {
|
2819 | var _a;
|
2820 |
|
2821 | const star = particle.shapeData;
|
2822 | const sides = this.getSidesCount(particle);
|
2823 | const inset = (_a = star === null || star === void 0 ? void 0 : star.inset) !== null && _a !== void 0 ? _a : 2;
|
2824 | context.moveTo(0, 0 - radius);
|
2825 |
|
2826 | for (let i = 0; i < sides; i++) {
|
2827 | context.rotate(Math.PI / sides);
|
2828 | context.lineTo(0, 0 - radius * inset);
|
2829 | context.rotate(Math.PI / sides);
|
2830 | context.lineTo(0, 0 - radius);
|
2831 | }
|
2832 | }
|
2833 |
|
2834 | }
|
2835 | ;
|
2836 |
|
2837 | class PolygonDrawer extends PolygonDrawerBase {
|
2838 | getSidesData(particle, radius) {
|
2839 | var _a, _b;
|
2840 |
|
2841 | const polygon = particle.shapeData;
|
2842 | const sides = (_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;
|
2843 | return {
|
2844 | count: {
|
2845 | denominator: 1,
|
2846 | numerator: sides
|
2847 | },
|
2848 | length: radius * 2.66 / (sides / 3)
|
2849 | };
|
2850 | }
|
2851 |
|
2852 | getCenter(particle, radius) {
|
2853 | const sides = this.getSidesCount(particle);
|
2854 | return {
|
2855 | x: -radius / (sides / 3.5),
|
2856 | y: -radius / (2.66 / 3.5)
|
2857 | };
|
2858 | }
|
2859 |
|
2860 | }
|
2861 | ;
|
2862 |
|
2863 | class Canvas {
|
2864 | constructor(container) {
|
2865 | this.container = container;
|
2866 | this.size = {
|
2867 | height: 0,
|
2868 | width: 0
|
2869 | };
|
2870 | this.context = null;
|
2871 | this.generatedCanvas = false;
|
2872 | }
|
2873 |
|
2874 | init() {
|
2875 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
2876 |
|
2877 | this.resize();
|
2878 | const options = this.container.actualOptions;
|
2879 | const element = this.element;
|
2880 |
|
2881 | if (element) {
|
2882 | if (options.fullScreen.enable) {
|
2883 | this.originalStyle = Utils.deepExtend({}, element.style);
|
2884 | element.style.position = "fixed";
|
2885 | element.style.zIndex = options.fullScreen.zIndex.toString(10);
|
2886 | element.style.top = "0";
|
2887 | element.style.left = "0";
|
2888 | element.style.width = "100%";
|
2889 | element.style.height = "100%";
|
2890 | } else {
|
2891 | element.style.position = (_b = (_a = this.originalStyle) === null || _a === void 0 ? void 0 : _a.position) !== null && _b !== void 0 ? _b : "";
|
2892 | element.style.zIndex = (_d = (_c = this.originalStyle) === null || _c === void 0 ? void 0 : _c.zIndex) !== null && _d !== void 0 ? _d : "";
|
2893 | element.style.top = (_f = (_e = this.originalStyle) === null || _e === void 0 ? void 0 : _e.top) !== null && _f !== void 0 ? _f : "";
|
2894 | element.style.left = (_h = (_g = this.originalStyle) === null || _g === void 0 ? void 0 : _g.left) !== null && _h !== void 0 ? _h : "";
|
2895 | element.style.width = (_k = (_j = this.originalStyle) === null || _j === void 0 ? void 0 : _j.width) !== null && _k !== void 0 ? _k : "";
|
2896 | element.style.height = (_m = (_l = this.originalStyle) === null || _l === void 0 ? void 0 : _l.height) !== null && _m !== void 0 ? _m : "";
|
2897 | }
|
2898 | }
|
2899 |
|
2900 | const cover = options.backgroundMask.cover;
|
2901 | const color = cover.color;
|
2902 | const trail = options.particles.move.trail;
|
2903 | const coverRgb = ColorUtils.colorToRgb(color);
|
2904 | this.coverColor = coverRgb !== undefined ? {
|
2905 | r: coverRgb.r,
|
2906 | g: coverRgb.g,
|
2907 | b: coverRgb.b,
|
2908 | a: cover.opacity
|
2909 | } : undefined;
|
2910 | this.trailFillColor = ColorUtils.colorToRgb(trail.fillColor);
|
2911 | this.initBackground();
|
2912 | this.paint();
|
2913 | }
|
2914 |
|
2915 | loadCanvas(canvas, generatedCanvas) {
|
2916 | var _a;
|
2917 |
|
2918 | if (!canvas.className) {
|
2919 | canvas.className = Constants.canvasClass;
|
2920 | }
|
2921 |
|
2922 | if (this.generatedCanvas) {
|
2923 | (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
|
2924 | }
|
2925 |
|
2926 | this.generatedCanvas = generatedCanvas !== null && generatedCanvas !== void 0 ? generatedCanvas : this.generatedCanvas;
|
2927 | this.element = canvas;
|
2928 | this.originalStyle = Utils.deepExtend({}, this.element.style);
|
2929 | this.size.height = canvas.offsetHeight;
|
2930 | this.size.width = canvas.offsetWidth;
|
2931 | this.context = this.element.getContext("2d");
|
2932 | this.container.retina.init();
|
2933 | this.initBackground();
|
2934 | }
|
2935 |
|
2936 | destroy() {
|
2937 | var _a;
|
2938 |
|
2939 | if (this.generatedCanvas) {
|
2940 | (_a = this.element) === null || _a === void 0 ? void 0 : _a.remove();
|
2941 | }
|
2942 |
|
2943 | if (this.context) {
|
2944 | CanvasUtils.clear(this.context, this.size);
|
2945 | }
|
2946 | }
|
2947 |
|
2948 | paint() {
|
2949 | const options = this.container.actualOptions;
|
2950 |
|
2951 | if (!this.context) {
|
2952 | return;
|
2953 | }
|
2954 |
|
2955 | if (options.backgroundMask.enable && options.backgroundMask.cover && this.coverColor) {
|
2956 | CanvasUtils.clear(this.context, this.size);
|
2957 | this.paintBase(ColorUtils.getStyleFromRgb(this.coverColor, this.coverColor.a));
|
2958 | } else {
|
2959 | this.paintBase();
|
2960 | }
|
2961 | }
|
2962 |
|
2963 | clear() {
|
2964 | const options = this.container.actualOptions;
|
2965 | const trail = options.particles.move.trail;
|
2966 |
|
2967 | if (options.backgroundMask.enable) {
|
2968 | this.paint();
|
2969 | } else if (trail.enable && trail.length > 0 && this.trailFillColor) {
|
2970 | this.paintBase(ColorUtils.getStyleFromRgb(this.trailFillColor, 1 / trail.length));
|
2971 | } else if (this.context) {
|
2972 | CanvasUtils.clear(this.context, this.size);
|
2973 | }
|
2974 | }
|
2975 |
|
2976 | windowResize() {
|
2977 | if (!this.element) {
|
2978 | return;
|
2979 | }
|
2980 |
|
2981 | const container = this.container;
|
2982 | this.resize();
|
2983 | container.actualOptions.setResponsive(this.size.width, container.retina.pixelRatio, container.options);
|
2984 | container.particles.setDensity();
|
2985 |
|
2986 | for (const [, plugin] of container.plugins) {
|
2987 | if (plugin.resize !== undefined) {
|
2988 | plugin.resize();
|
2989 | }
|
2990 | }
|
2991 | }
|
2992 |
|
2993 | resize() {
|
2994 | if (!this.element) {
|
2995 | return;
|
2996 | }
|
2997 |
|
2998 | const container = this.container;
|
2999 | const pxRatio = container.retina.pixelRatio;
|
3000 | const size = container.canvas.size;
|
3001 | const oldSize = {
|
3002 | width: size.width,
|
3003 | height: size.height
|
3004 | };
|
3005 | size.width = this.element.offsetWidth * pxRatio;
|
3006 | size.height = this.element.offsetHeight * pxRatio;
|
3007 | this.element.width = size.width;
|
3008 | this.element.height = size.height;
|
3009 |
|
3010 | if (this.container.started) {
|
3011 | this.resizeFactor = {
|
3012 | width: size.width / oldSize.width,
|
3013 | height: size.height / oldSize.height
|
3014 | };
|
3015 | }
|
3016 | }
|
3017 |
|
3018 | drawConnectLine(p1, p2) {
|
3019 | var _a;
|
3020 |
|
3021 | const ctx = this.context;
|
3022 |
|
3023 | if (!ctx) {
|
3024 | return;
|
3025 | }
|
3026 |
|
3027 | const lineStyle = this.lineStyle(p1, p2);
|
3028 |
|
3029 | if (!lineStyle) {
|
3030 | return;
|
3031 | }
|
3032 |
|
3033 | const pos1 = p1.getPosition();
|
3034 | const pos2 = p2.getPosition();
|
3035 | CanvasUtils.drawConnectLine(ctx, (_a = p1.linksWidth) !== null && _a !== void 0 ? _a : this.container.retina.linksWidth, lineStyle, pos1, pos2);
|
3036 | }
|
3037 |
|
3038 | drawGrabLine(particle, lineColor, opacity, mousePos) {
|
3039 | var _a;
|
3040 |
|
3041 | const container = this.container;
|
3042 | const ctx = container.canvas.context;
|
3043 |
|
3044 | if (!ctx) {
|
3045 | return;
|
3046 | }
|
3047 |
|
3048 | const beginPos = particle.getPosition();
|
3049 | CanvasUtils.drawGrabLine(ctx, (_a = particle.linksWidth) !== null && _a !== void 0 ? _a : container.retina.linksWidth, beginPos, mousePos, lineColor, opacity);
|
3050 | }
|
3051 |
|
3052 | drawParticleShadow(particle, mousePos) {
|
3053 | if (!this.context) {
|
3054 | return;
|
3055 | }
|
3056 |
|
3057 | CanvasUtils.drawParticleShadow(this.container, this.context, particle, mousePos);
|
3058 | }
|
3059 |
|
3060 | drawLinkTriangle(p1, link1, link2) {
|
3061 | var _a;
|
3062 |
|
3063 | const container = this.container;
|
3064 | const options = container.actualOptions;
|
3065 | const p2 = link1.destination;
|
3066 | const p3 = link2.destination;
|
3067 | const triangleOptions = p1.options.links.triangles;
|
3068 | const opacityTriangle = (_a = triangleOptions.opacity) !== null && _a !== void 0 ? _a : (link1.opacity + link2.opacity) / 2;
|
3069 |
|
3070 | if (opacityTriangle <= 0) {
|
3071 | return;
|
3072 | }
|
3073 |
|
3074 | const pos1 = p1.getPosition();
|
3075 | const pos2 = p2.getPosition();
|
3076 | const pos3 = p3.getPosition();
|
3077 | const ctx = this.context;
|
3078 |
|
3079 | if (!ctx) {
|
3080 | return;
|
3081 | }
|
3082 |
|
3083 | if (NumberUtils.getDistance(pos1, pos2) > container.retina.linksDistance || NumberUtils.getDistance(pos3, pos2) > container.retina.linksDistance || NumberUtils.getDistance(pos3, pos1) > container.retina.linksDistance) {
|
3084 | return;
|
3085 | }
|
3086 |
|
3087 | let colorTriangle = ColorUtils.colorToRgb(triangleOptions.color);
|
3088 |
|
3089 | if (!colorTriangle) {
|
3090 | const linksOptions = p1.options.links;
|
3091 | const linkColor = linksOptions.id !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;
|
3092 | colorTriangle = ColorUtils.getLinkColor(p1, p2, linkColor);
|
3093 | }
|
3094 |
|
3095 | if (!colorTriangle) {
|
3096 | return;
|
3097 | }
|
3098 |
|
3099 | CanvasUtils.drawLinkTriangle(ctx, pos1, pos2, pos3, options.backgroundMask.enable, options.backgroundMask.composite, colorTriangle, opacityTriangle);
|
3100 | }
|
3101 |
|
3102 | drawLinkLine(p1, link) {
|
3103 | var _a, _b;
|
3104 |
|
3105 | const container = this.container;
|
3106 | const options = container.actualOptions;
|
3107 | const p2 = link.destination;
|
3108 | let opacity = link.opacity;
|
3109 | const pos1 = p1.getPosition();
|
3110 | const pos2 = p2.getPosition();
|
3111 | const ctx = this.context;
|
3112 |
|
3113 | if (!ctx) {
|
3114 | return;
|
3115 | }
|
3116 |
|
3117 | let colorLine;
|
3118 | const twinkle = p1.options.twinkle.lines;
|
3119 |
|
3120 | if (twinkle.enable) {
|
3121 | const twinkleFreq = twinkle.frequency;
|
3122 | const twinkleRgb = ColorUtils.colorToRgb(twinkle.color);
|
3123 | const twinkling = Math.random() < twinkleFreq;
|
3124 |
|
3125 | if (twinkling && twinkleRgb !== undefined) {
|
3126 | colorLine = twinkleRgb;
|
3127 | opacity = twinkle.opacity;
|
3128 | }
|
3129 | }
|
3130 |
|
3131 | if (!colorLine) {
|
3132 | const linksOptions = p1.options.links;
|
3133 | const linkColor = linksOptions.id !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;
|
3134 | colorLine = ColorUtils.getLinkColor(p1, p2, linkColor);
|
3135 | }
|
3136 |
|
3137 | if (!colorLine) {
|
3138 | return;
|
3139 | }
|
3140 |
|
3141 | const width = (_a = p1.linksWidth) !== null && _a !== void 0 ? _a : container.retina.linksWidth;
|
3142 | const maxDistance = (_b = p1.linksDistance) !== null && _b !== void 0 ? _b : container.retina.linksDistance;
|
3143 | CanvasUtils.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);
|
3144 | }
|
3145 |
|
3146 | drawParticle(particle, delta) {
|
3147 | var _a, _b, _c, _d;
|
3148 |
|
3149 | if (((_a = particle.image) === null || _a === void 0 ? void 0 : _a.loaded) === false || particle.spawning || particle.destroyed) {
|
3150 | return;
|
3151 | }
|
3152 |
|
3153 | const pfColor = particle.getFillColor();
|
3154 | const psColor = (_b = particle.getStrokeColor()) !== null && _b !== void 0 ? _b : pfColor;
|
3155 |
|
3156 | if (!pfColor && !psColor) {
|
3157 | return;
|
3158 | }
|
3159 |
|
3160 | const options = this.container.actualOptions;
|
3161 | const pOptions = particle.options;
|
3162 | const twinkle = pOptions.twinkle.particles;
|
3163 | const twinkleFreq = twinkle.frequency;
|
3164 | const twinkleRgb = ColorUtils.colorToRgb(twinkle.color);
|
3165 | const twinkling = twinkle.enable && Math.random() < twinkleFreq;
|
3166 | const radius = particle.getRadius();
|
3167 | const opacity = twinkling ? twinkle.opacity : (_c = particle.bubble.opacity) !== null && _c !== void 0 ? _c : particle.opacity.value;
|
3168 | const infectionStage = particle.infecter.infectionStage;
|
3169 | const infection = options.infection;
|
3170 | const infectionStages = infection.stages;
|
3171 | const infectionColor = infectionStage !== undefined ? infectionStages[infectionStage].color : undefined;
|
3172 | const infectionRgb = ColorUtils.colorToRgb(infectionColor);
|
3173 | const fColor = twinkling && twinkleRgb !== undefined ? twinkleRgb : infectionRgb !== null && infectionRgb !== void 0 ? infectionRgb : pfColor ? ColorUtils.hslToRgb(pfColor) : undefined;
|
3174 | const sColor = twinkling && twinkleRgb !== undefined ? twinkleRgb : infectionRgb !== null && infectionRgb !== void 0 ? infectionRgb : psColor ? ColorUtils.hslToRgb(psColor) : undefined;
|
3175 | const fillColorValue = fColor !== undefined ? ColorUtils.getStyleFromRgb(fColor, opacity) : undefined;
|
3176 |
|
3177 | if (!this.context || !fillColorValue && !sColor) {
|
3178 | return;
|
3179 | }
|
3180 |
|
3181 | const strokeColorValue = sColor !== undefined ? ColorUtils.getStyleFromRgb(sColor, (_d = particle.stroke.opacity) !== null && _d !== void 0 ? _d : opacity) : fillColorValue;
|
3182 | this.drawParticleLinks(particle);
|
3183 |
|
3184 | if (radius > 0) {
|
3185 | CanvasUtils.drawParticle(this.container, this.context, particle, delta, fillColorValue, strokeColorValue, options.backgroundMask.enable, options.backgroundMask.composite, radius, opacity, particle.options.shadow);
|
3186 | }
|
3187 | }
|
3188 |
|
3189 | drawParticleLinks(particle) {
|
3190 | if (!this.context) {
|
3191 | return;
|
3192 | }
|
3193 |
|
3194 | const container = this.container;
|
3195 | const particles = container.particles;
|
3196 | const pOptions = particle.options;
|
3197 |
|
3198 | if (particle.links.length > 0) {
|
3199 | this.context.save();
|
3200 | const p1Links = particle.links.filter(l => {
|
3201 | const linkFreq = container.particles.getLinkFrequency(particle, l.destination);
|
3202 | return linkFreq <= pOptions.links.frequency;
|
3203 | });
|
3204 |
|
3205 | for (const link of p1Links) {
|
3206 | const p2 = link.destination;
|
3207 |
|
3208 | if (pOptions.links.triangles.enable) {
|
3209 | const links = p1Links.map(l => l.destination);
|
3210 | const vertices = p2.links.filter(t => {
|
3211 | const linkFreq = container.particles.getLinkFrequency(p2, t.destination);
|
3212 | return linkFreq <= p2.options.links.frequency && links.indexOf(t.destination) >= 0;
|
3213 | });
|
3214 |
|
3215 | if (vertices.length) {
|
3216 | for (const vertex of vertices) {
|
3217 | const p3 = vertex.destination;
|
3218 | const triangleFreq = particles.getTriangleFrequency(particle, p2, p3);
|
3219 |
|
3220 | if (triangleFreq > pOptions.links.triangles.frequency) {
|
3221 | continue;
|
3222 | }
|
3223 |
|
3224 | this.drawLinkTriangle(particle, link, vertex);
|
3225 | }
|
3226 | }
|
3227 | }
|
3228 |
|
3229 | if (link.opacity > 0 && container.retina.linksWidth > 0) {
|
3230 | this.drawLinkLine(particle, link);
|
3231 | }
|
3232 | }
|
3233 |
|
3234 | this.context.restore();
|
3235 | }
|
3236 | }
|
3237 |
|
3238 | drawPlugin(plugin, delta) {
|
3239 | if (!this.context) {
|
3240 | return;
|
3241 | }
|
3242 |
|
3243 | CanvasUtils.drawPlugin(this.context, plugin, delta);
|
3244 | }
|
3245 |
|
3246 | drawLight(mousePos) {
|
3247 | if (!this.context) {
|
3248 | return;
|
3249 | }
|
3250 |
|
3251 | CanvasUtils.drawLight(this.container, this.context, mousePos);
|
3252 | }
|
3253 |
|
3254 | paintBase(baseColor) {
|
3255 | if (!this.context) {
|
3256 | return;
|
3257 | }
|
3258 |
|
3259 | CanvasUtils.paintBase(this.context, this.size, baseColor);
|
3260 | }
|
3261 |
|
3262 | lineStyle(p1, p2) {
|
3263 | if (!this.context) {
|
3264 | return;
|
3265 | }
|
3266 |
|
3267 | const options = this.container.actualOptions;
|
3268 | const connectOptions = options.interactivity.modes.connect;
|
3269 | return CanvasUtils.gradient(this.context, p1, p2, connectOptions.links.opacity);
|
3270 | }
|
3271 |
|
3272 | initBackground() {
|
3273 | const options = this.container.actualOptions;
|
3274 | const background = options.background;
|
3275 | const element = this.element;
|
3276 | const elementStyle = element === null || element === void 0 ? void 0 : element.style;
|
3277 |
|
3278 | if (!elementStyle) {
|
3279 | return;
|
3280 | }
|
3281 |
|
3282 | if (background.color) {
|
3283 | const color = ColorUtils.colorToRgb(background.color);
|
3284 | elementStyle.backgroundColor = color ? ColorUtils.getStyleFromRgb(color, background.opacity) : "";
|
3285 | } else {
|
3286 | elementStyle.backgroundColor = "";
|
3287 | }
|
3288 |
|
3289 | elementStyle.backgroundImage = background.image || "";
|
3290 | elementStyle.backgroundPosition = background.position || "";
|
3291 | elementStyle.backgroundRepeat = background.repeat || "";
|
3292 | elementStyle.backgroundSize = background.size || "";
|
3293 | }
|
3294 |
|
3295 | }
|
3296 | ;
|
3297 |
|
3298 |
|
3299 |
|
3300 |
|
3301 | function bounceHorizontal(data) {
|
3302 | if (data.outMode === OutMode.bounce || data.outMode === OutMode.bounceHorizontal || data.outMode === "bounceHorizontal" || data.outMode === OutMode.split) {
|
3303 | const velocity = data.particle.velocity.x;
|
3304 | let bounced = false;
|
3305 |
|
3306 | if (data.direction === OutModeDirection.right && data.bounds.right >= data.canvasSize.width && velocity > 0 || data.direction === OutModeDirection.left && data.bounds.left <= 0 && velocity < 0) {
|
3307 | const newVelocity = NumberUtils.getValue(data.particle.options.bounce.horizontal);
|
3308 | data.particle.velocity.x *= -newVelocity;
|
3309 | bounced = true;
|
3310 | }
|
3311 |
|
3312 | if (!bounced) {
|
3313 | return;
|
3314 | }
|
3315 |
|
3316 | const minPos = data.offset.x + data.size;
|
3317 |
|
3318 | if (data.bounds.right >= data.canvasSize.width) {
|
3319 | data.particle.position.x = data.canvasSize.width - minPos;
|
3320 | } else if (data.bounds.left <= 0) {
|
3321 | data.particle.position.x = minPos;
|
3322 | }
|
3323 |
|
3324 | if (data.outMode === OutMode.split) {
|
3325 | data.particle.destroy();
|
3326 | }
|
3327 | }
|
3328 | }
|
3329 |
|
3330 | function bounceVertical(data) {
|
3331 | if (data.outMode === OutMode.bounce || data.outMode === OutMode.bounceVertical || data.outMode === "bounceVertical" || data.outMode === OutMode.split) {
|
3332 | const velocity = data.particle.velocity.y;
|
3333 | let bounced = false;
|
3334 |
|
3335 | if (data.direction === OutModeDirection.bottom && data.bounds.bottom >= data.canvasSize.height && velocity > 0 || data.direction === OutModeDirection.top && data.bounds.top <= 0 && velocity < 0) {
|
3336 | const newVelocity = NumberUtils.getValue(data.particle.options.bounce.vertical);
|
3337 | data.particle.velocity.y *= -newVelocity;
|
3338 | bounced = true;
|
3339 | }
|
3340 |
|
3341 | if (!bounced) {
|
3342 | return;
|
3343 | }
|
3344 |
|
3345 | const minPos = data.offset.y + data.size;
|
3346 |
|
3347 | if (data.bounds.bottom >= data.canvasSize.height) {
|
3348 | data.particle.position.y = data.canvasSize.height - minPos;
|
3349 | } else if (data.bounds.top <= 0) {
|
3350 | data.particle.position.y = minPos;
|
3351 | }
|
3352 |
|
3353 | if (data.outMode === OutMode.split) {
|
3354 | data.particle.destroy();
|
3355 | }
|
3356 | }
|
3357 | }
|
3358 |
|
3359 | function checkDestroy(particle, destroy, value, minValue, maxValue) {
|
3360 | switch (destroy) {
|
3361 | case DestroyType.max:
|
3362 | if (value >= maxValue) {
|
3363 | particle.destroy();
|
3364 | }
|
3365 |
|
3366 | break;
|
3367 |
|
3368 | case DestroyType.min:
|
3369 | if (value <= minValue) {
|
3370 | particle.destroy();
|
3371 | }
|
3372 |
|
3373 | break;
|
3374 | }
|
3375 | }
|
3376 |
|
3377 | class Updater {
|
3378 | constructor(container, particle) {
|
3379 | this.container = container;
|
3380 | this.particle = particle;
|
3381 | }
|
3382 |
|
3383 | update(delta) {
|
3384 | if (this.particle.destroyed) {
|
3385 | return;
|
3386 | }
|
3387 |
|
3388 | this.updateLife(delta);
|
3389 |
|
3390 | if (this.particle.destroyed || this.particle.spawning) {
|
3391 | return;
|
3392 | }
|
3393 |
|
3394 | this.updateOpacity(delta);
|
3395 | this.updateSize(delta);
|
3396 | this.updateAngle(delta);
|
3397 | this.updateColor(delta);
|
3398 | this.updateStrokeColor(delta);
|
3399 | this.updateOutModes(delta);
|
3400 | }
|
3401 |
|
3402 | updateLife(delta) {
|
3403 | const particle = this.particle;
|
3404 | let justSpawned = false;
|
3405 |
|
3406 | if (particle.spawning) {
|
3407 | particle.lifeDelayTime += delta.value;
|
3408 |
|
3409 | if (particle.lifeDelayTime >= particle.lifeDelay) {
|
3410 | justSpawned = true;
|
3411 | particle.spawning = false;
|
3412 | particle.lifeDelayTime = 0;
|
3413 | particle.lifeTime = 0;
|
3414 | }
|
3415 | }
|
3416 |
|
3417 | if (particle.lifeDuration === -1) {
|
3418 | return;
|
3419 | }
|
3420 |
|
3421 | if (!particle.spawning) {
|
3422 | if (justSpawned) {
|
3423 | particle.lifeTime = 0;
|
3424 | } else {
|
3425 | particle.lifeTime += delta.value;
|
3426 | }
|
3427 |
|
3428 | if (particle.lifeTime >= particle.lifeDuration) {
|
3429 | particle.lifeTime = 0;
|
3430 |
|
3431 | if (particle.livesRemaining > 0) {
|
3432 | particle.livesRemaining--;
|
3433 | }
|
3434 |
|
3435 | if (particle.livesRemaining === 0) {
|
3436 | particle.destroy();
|
3437 | return;
|
3438 | }
|
3439 |
|
3440 | const canvasSize = this.container.canvas.size;
|
3441 | particle.position.x = NumberUtils.randomInRange(NumberUtils.setRangeValue(0, canvasSize.width));
|
3442 | particle.position.y = NumberUtils.randomInRange(NumberUtils.setRangeValue(0, canvasSize.height));
|
3443 | particle.spawning = true;
|
3444 | particle.lifeDelayTime = 0;
|
3445 | particle.lifeTime = 0;
|
3446 | particle.reset();
|
3447 | const lifeOptions = particle.options.life;
|
3448 | particle.lifeDelay = NumberUtils.getValue(lifeOptions.delay) * 1000;
|
3449 | particle.lifeDuration = NumberUtils.getValue(lifeOptions.duration) * 1000;
|
3450 | }
|
3451 | }
|
3452 | }
|
3453 |
|
3454 | updateOpacity(delta) {
|
3455 | var _a, _b;
|
3456 |
|
3457 | const particle = this.particle;
|
3458 | const opacityOpt = particle.options.opacity;
|
3459 | const opacityAnim = opacityOpt.animation;
|
3460 | const minValue = NumberUtils.getRangeMin(opacityOpt.value);
|
3461 | const maxValue = NumberUtils.getRangeMax(opacityOpt.value);
|
3462 |
|
3463 | if (!particle.destroyed && opacityAnim.enable && (opacityAnim.count <= 0 || particle.loops.size < opacityAnim.count)) {
|
3464 | switch (particle.opacity.status) {
|
3465 | case AnimationStatus.increasing:
|
3466 | if (particle.opacity.value >= maxValue) {
|
3467 | particle.opacity.status = AnimationStatus.decreasing;
|
3468 | particle.loops.opacity++;
|
3469 | } else {
|
3470 | particle.opacity.value += ((_a = particle.opacity.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor;
|
3471 | }
|
3472 |
|
3473 | break;
|
3474 |
|
3475 | case AnimationStatus.decreasing:
|
3476 | if (particle.opacity.value <= minValue) {
|
3477 | particle.opacity.status = AnimationStatus.increasing;
|
3478 | particle.loops.opacity++;
|
3479 | } else {
|
3480 | particle.opacity.value -= ((_b = particle.opacity.velocity) !== null && _b !== void 0 ? _b : 0) * delta.factor;
|
3481 | }
|
3482 |
|
3483 | break;
|
3484 | }
|
3485 |
|
3486 | checkDestroy(particle, opacityAnim.destroy, particle.opacity.value, minValue, maxValue);
|
3487 |
|
3488 | if (!particle.destroyed) {
|
3489 | particle.opacity.value = NumberUtils.clamp(particle.opacity.value, minValue, maxValue);
|
3490 | }
|
3491 | }
|
3492 | }
|
3493 |
|
3494 | updateSize(delta) {
|
3495 | var _a;
|
3496 |
|
3497 | const container = this.container;
|
3498 | const particle = this.particle;
|
3499 | const sizeOpt = particle.options.size;
|
3500 | const sizeAnim = sizeOpt.animation;
|
3501 | const sizeVelocity = ((_a = particle.size.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor;
|
3502 | const minValue = NumberUtils.getRangeMin(sizeOpt.value) * container.retina.pixelRatio;
|
3503 | const maxValue = NumberUtils.getRangeMax(sizeOpt.value) * container.retina.pixelRatio;
|
3504 |
|
3505 | if (!particle.destroyed && sizeAnim.enable && (sizeAnim.count <= 0 || particle.loops.size < sizeAnim.count)) {
|
3506 | switch (particle.size.status) {
|
3507 | case AnimationStatus.increasing:
|
3508 | if (particle.size.value >= maxValue) {
|
3509 | particle.size.status = AnimationStatus.decreasing;
|
3510 | particle.loops.size++;
|
3511 | } else {
|
3512 | particle.size.value += sizeVelocity;
|
3513 | }
|
3514 |
|
3515 | break;
|
3516 |
|
3517 | case AnimationStatus.decreasing:
|
3518 | if (particle.size.value <= minValue) {
|
3519 | particle.size.status = AnimationStatus.increasing;
|
3520 | particle.loops.size++;
|
3521 | } else {
|
3522 | particle.size.value -= sizeVelocity;
|
3523 | }
|
3524 |
|
3525 | }
|
3526 |
|
3527 | checkDestroy(particle, sizeAnim.destroy, particle.size.value, minValue, maxValue);
|
3528 |
|
3529 | if (!particle.destroyed) {
|
3530 | particle.size.value = NumberUtils.clamp(particle.size.value, minValue, maxValue);
|
3531 | }
|
3532 | }
|
3533 | }
|
3534 |
|
3535 | updateAngle(delta) {
|
3536 | var _a;
|
3537 |
|
3538 | const particle = this.particle;
|
3539 | const rotate = particle.options.rotate;
|
3540 | const rotateAnimation = rotate.animation;
|
3541 | const speed = ((_a = particle.rotate.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor;
|
3542 | const max = 2 * Math.PI;
|
3543 |
|
3544 | if (rotateAnimation.enable) {
|
3545 | switch (particle.rotate.status) {
|
3546 | case AnimationStatus.increasing:
|
3547 | particle.rotate.value += speed;
|
3548 |
|
3549 | if (particle.rotate.value > max) {
|
3550 | particle.rotate.value -= max;
|
3551 | }
|
3552 |
|
3553 | break;
|
3554 |
|
3555 | case AnimationStatus.decreasing:
|
3556 | default:
|
3557 | particle.rotate.value -= speed;
|
3558 |
|
3559 | if (particle.rotate.value < 0) {
|
3560 | particle.rotate.value += max;
|
3561 | }
|
3562 |
|
3563 | break;
|
3564 | }
|
3565 | }
|
3566 | }
|
3567 |
|
3568 | updateColor(delta) {
|
3569 | var _a, _b, _c;
|
3570 |
|
3571 | const particle = this.particle;
|
3572 | const animationOptions = particle.options.color.animation;
|
3573 |
|
3574 | if (((_a = particle.color) === null || _a === void 0 ? void 0 : _a.h) !== undefined) {
|
3575 | this.updateColorValue(particle, delta, particle.color.h, animationOptions.h, 360, false);
|
3576 | }
|
3577 |
|
3578 | if (((_b = particle.color) === null || _b === void 0 ? void 0 : _b.s) !== undefined) {
|
3579 | this.updateColorValue(particle, delta, particle.color.s, animationOptions.s, 100, true);
|
3580 | }
|
3581 |
|
3582 | if (((_c = particle.color) === null || _c === void 0 ? void 0 : _c.l) !== undefined) {
|
3583 | this.updateColorValue(particle, delta, particle.color.l, animationOptions.l, 100, true);
|
3584 | }
|
3585 | }
|
3586 |
|
3587 | updateStrokeColor(delta) {
|
3588 | var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
3589 |
|
3590 | const particle = this.particle;
|
3591 |
|
3592 | if (!particle.stroke.color) {
|
3593 | return;
|
3594 | }
|
3595 |
|
3596 | const animationOptions = particle.stroke.color.animation;
|
3597 | const valueAnimations = animationOptions;
|
3598 |
|
3599 | if (valueAnimations.enable !== undefined) {
|
3600 | const hue = (_b = (_a = particle.strokeColor) === null || _a === void 0 ? void 0 : _a.h) !== null && _b !== void 0 ? _b : (_c = particle.color) === null || _c === void 0 ? void 0 : _c.h;
|
3601 |
|
3602 | if (hue) {
|
3603 | this.updateColorValue(particle, delta, hue, valueAnimations, 360, false);
|
3604 | }
|
3605 | } else {
|
3606 | const hslAnimations = animationOptions;
|
3607 | const h = (_e = (_d = particle.strokeColor) === null || _d === void 0 ? void 0 : _d.h) !== null && _e !== void 0 ? _e : (_f = particle.color) === null || _f === void 0 ? void 0 : _f.h;
|
3608 |
|
3609 | if (h) {
|
3610 | this.updateColorValue(particle, delta, h, hslAnimations.h, 360, false);
|
3611 | }
|
3612 |
|
3613 | const s = (_h = (_g = particle.strokeColor) === null || _g === void 0 ? void 0 : _g.s) !== null && _h !== void 0 ? _h : (_j = particle.color) === null || _j === void 0 ? void 0 : _j.s;
|
3614 |
|
3615 | if (s) {
|
3616 | this.updateColorValue(particle, delta, s, hslAnimations.s, 100, true);
|
3617 | }
|
3618 |
|
3619 | const l = (_l = (_k = particle.strokeColor) === null || _k === void 0 ? void 0 : _k.l) !== null && _l !== void 0 ? _l : (_m = particle.color) === null || _m === void 0 ? void 0 : _m.l;
|
3620 |
|
3621 | if (l) {
|
3622 | this.updateColorValue(particle, delta, l, hslAnimations.l, 100, true);
|
3623 | }
|
3624 | }
|
3625 | }
|
3626 |
|
3627 | updateColorValue(particle, delta, value, valueAnimation, max, decrease) {
|
3628 | var _a;
|
3629 |
|
3630 | const colorValue = value;
|
3631 |
|
3632 | if (!colorValue || !valueAnimation.enable) {
|
3633 | return;
|
3634 | }
|
3635 |
|
3636 | const offset = NumberUtils.randomInRange(valueAnimation.offset);
|
3637 | const velocity = ((_a = value.velocity) !== null && _a !== void 0 ? _a : 0) * delta.factor + offset * 3.6;
|
3638 |
|
3639 | if (!decrease || colorValue.status === AnimationStatus.increasing) {
|
3640 | colorValue.value += velocity;
|
3641 |
|
3642 | if (decrease && colorValue.value > max) {
|
3643 | colorValue.status = AnimationStatus.decreasing;
|
3644 | colorValue.value -= colorValue.value % max;
|
3645 | }
|
3646 | } else {
|
3647 | colorValue.value -= velocity;
|
3648 |
|
3649 | if (colorValue.value < 0) {
|
3650 | colorValue.status = AnimationStatus.increasing;
|
3651 | colorValue.value += colorValue.value;
|
3652 | }
|
3653 | }
|
3654 |
|
3655 | if (colorValue.value > max) {
|
3656 | colorValue.value %= max;
|
3657 | }
|
3658 | }
|
3659 |
|
3660 | updateOutModes(delta) {
|
3661 | var _a, _b, _c, _d;
|
3662 |
|
3663 | const outModes = this.particle.options.move.outModes;
|
3664 | this.updateOutMode(delta, (_a = outModes.bottom) !== null && _a !== void 0 ? _a : outModes.default, OutModeDirection.bottom);
|
3665 | this.updateOutMode(delta, (_b = outModes.left) !== null && _b !== void 0 ? _b : outModes.default, OutModeDirection.left);
|
3666 | this.updateOutMode(delta, (_c = outModes.right) !== null && _c !== void 0 ? _c : outModes.default, OutModeDirection.right);
|
3667 | this.updateOutMode(delta, (_d = outModes.top) !== null && _d !== void 0 ? _d : outModes.default, OutModeDirection.top);
|
3668 | }
|
3669 |
|
3670 | updateOutMode(delta, outMode, direction) {
|
3671 | const container = this.container;
|
3672 | const particle = this.particle;
|
3673 |
|
3674 | switch (outMode) {
|
3675 | case OutMode.bounce:
|
3676 | case OutMode.bounceVertical:
|
3677 | case OutMode.bounceHorizontal:
|
3678 | case "bounceVertical":
|
3679 | case "bounceHorizontal":
|
3680 | case OutMode.split:
|
3681 | this.updateBounce(delta, direction, outMode);
|
3682 | break;
|
3683 |
|
3684 | case OutMode.destroy:
|
3685 | if (!Utils.isPointInside(particle.position, container.canvas.size, particle.getRadius(), direction)) {
|
3686 | container.particles.remove(particle, true);
|
3687 | }
|
3688 |
|
3689 | break;
|
3690 |
|
3691 | case OutMode.out:
|
3692 | if (!Utils.isPointInside(particle.position, container.canvas.size, particle.getRadius(), direction)) {
|
3693 | this.fixOutOfCanvasPosition(direction);
|
3694 | }
|
3695 |
|
3696 | break;
|
3697 |
|
3698 | case OutMode.none:
|
3699 | this.bounceNone(direction);
|
3700 | break;
|
3701 | }
|
3702 | }
|
3703 |
|
3704 | fixOutOfCanvasPosition(direction) {
|
3705 | const container = this.container;
|
3706 | const particle = this.particle;
|
3707 | const wrap = particle.options.move.warp;
|
3708 | const canvasSize = container.canvas.size;
|
3709 | const newPos = {
|
3710 | bottom: canvasSize.height + particle.getRadius() - particle.offset.y,
|
3711 | left: -particle.getRadius() - particle.offset.x,
|
3712 | right: canvasSize.width + particle.getRadius() + particle.offset.x,
|
3713 | top: -particle.getRadius() - particle.offset.y
|
3714 | };
|
3715 | const sizeValue = particle.getRadius();
|
3716 | const nextBounds = Utils.calculateBounds(particle.position, sizeValue);
|
3717 |
|
3718 | if (direction === OutModeDirection.right && nextBounds.left > canvasSize.width - particle.offset.x) {
|
3719 | particle.position.x = newPos.left;
|
3720 |
|
3721 | if (!wrap) {
|
3722 | particle.position.y = Math.random() * canvasSize.height;
|
3723 | }
|
3724 | } else if (direction === OutModeDirection.left && nextBounds.right < -particle.offset.x) {
|
3725 | particle.position.x = newPos.right;
|
3726 |
|
3727 | if (!wrap) {
|
3728 | particle.position.y = Math.random() * canvasSize.height;
|
3729 | }
|
3730 | }
|
3731 |
|
3732 | if (direction === OutModeDirection.bottom && nextBounds.top > canvasSize.height - particle.offset.y) {
|
3733 | if (!wrap) {
|
3734 | particle.position.x = Math.random() * canvasSize.width;
|
3735 | }
|
3736 |
|
3737 | particle.position.y = newPos.top;
|
3738 | } else if (direction === OutModeDirection.top && nextBounds.bottom < -particle.offset.y) {
|
3739 | if (!wrap) {
|
3740 | particle.position.x = Math.random() * canvasSize.width;
|
3741 | }
|
3742 |
|
3743 | particle.position.y = newPos.bottom;
|
3744 | }
|
3745 | }
|
3746 |
|
3747 | updateBounce(delta, direction, outMode) {
|
3748 | const container = this.container;
|
3749 | const particle = this.particle;
|
3750 | let handled = false;
|
3751 |
|
3752 | for (const [, plugin] of container.plugins) {
|
3753 | if (plugin.particleBounce !== undefined) {
|
3754 | handled = plugin.particleBounce(particle, delta, direction);
|
3755 | }
|
3756 |
|
3757 | if (handled) {
|
3758 | break;
|
3759 | }
|
3760 | }
|
3761 |
|
3762 | if (handled) {
|
3763 | return;
|
3764 | }
|
3765 |
|
3766 | const pos = particle.getPosition(),
|
3767 | offset = particle.offset,
|
3768 | size = particle.getRadius(),
|
3769 | bounds = Utils.calculateBounds(pos, size),
|
3770 | canvasSize = container.canvas.size;
|
3771 | bounceHorizontal({
|
3772 | particle,
|
3773 | outMode,
|
3774 | direction,
|
3775 | bounds,
|
3776 | canvasSize,
|
3777 | offset,
|
3778 | size
|
3779 | });
|
3780 | bounceVertical({
|
3781 | particle,
|
3782 | outMode,
|
3783 | direction,
|
3784 | bounds,
|
3785 | canvasSize,
|
3786 | offset,
|
3787 | size
|
3788 | });
|
3789 | }
|
3790 |
|
3791 | bounceNone(direction) {
|
3792 | const particle = this.particle;
|
3793 |
|
3794 | if (particle.options.move.distance) {
|
3795 | return;
|
3796 | }
|
3797 |
|
3798 | const gravityOptions = particle.options.move.gravity;
|
3799 | const container = this.container;
|
3800 |
|
3801 | if (!gravityOptions.enable) {
|
3802 | if (!Utils.isPointInside(particle.position, container.canvas.size, particle.getRadius(), direction)) {
|
3803 | container.particles.remove(particle);
|
3804 | }
|
3805 | } else {
|
3806 | const position = particle.position;
|
3807 |
|
3808 | if (gravityOptions.acceleration >= 0 && position.y > container.canvas.size.height && direction === OutModeDirection.bottom || gravityOptions.acceleration < 0 && position.y < 0 && direction === OutModeDirection.top) {
|
3809 | container.particles.remove(particle);
|
3810 | }
|
3811 | }
|
3812 | }
|
3813 |
|
3814 | }
|
3815 | ;
|
3816 | class OptionsColor {
|
3817 | constructor() {
|
3818 | this.value = "#fff";
|
3819 | }
|
3820 |
|
3821 | static create(source, data) {
|
3822 | const color = source !== null && source !== void 0 ? source : new OptionsColor();
|
3823 |
|
3824 | if (data !== undefined) {
|
3825 | color.load(typeof data === "string" ? {
|
3826 | value: data
|
3827 | } : data);
|
3828 | }
|
3829 |
|
3830 | return color;
|
3831 | }
|
3832 |
|
3833 | load(data) {
|
3834 | if ((data === null || data === void 0 ? void 0 : data.value) === undefined) {
|
3835 | return;
|
3836 | }
|
3837 |
|
3838 | this.value = data.value;
|
3839 | }
|
3840 |
|
3841 | }
|
3842 | ;
|
3843 |
|
3844 | class LinksShadow {
|
3845 | constructor() {
|
3846 | this.blur = 5;
|
3847 | this.color = new OptionsColor();
|
3848 | this.enable = false;
|
3849 | this.color.value = "#00ff00";
|
3850 | }
|
3851 |
|
3852 | load(data) {
|
3853 | if (data === undefined) {
|
3854 | return;
|
3855 | }
|
3856 |
|
3857 | if (data.blur !== undefined) {
|
3858 | this.blur = data.blur;
|
3859 | }
|
3860 |
|
3861 | this.color = OptionsColor.create(this.color, data.color);
|
3862 |
|
3863 | if (data.enable !== undefined) {
|
3864 | this.enable = data.enable;
|
3865 | }
|
3866 | }
|
3867 |
|
3868 | }
|
3869 | ;
|
3870 |
|
3871 | class LinksTriangle {
|
3872 | constructor() {
|
3873 | this.enable = false;
|
3874 | this.frequency = 1;
|
3875 | }
|
3876 |
|
3877 | load(data) {
|
3878 | if (data === undefined) {
|
3879 | return;
|
3880 | }
|
3881 |
|
3882 | if (data.color !== undefined) {
|
3883 | this.color = OptionsColor.create(this.color, data.color);
|
3884 | }
|
3885 |
|
3886 | if (data.enable !== undefined) {
|
3887 | this.enable = data.enable;
|
3888 | }
|
3889 |
|
3890 | if (data.frequency !== undefined) {
|
3891 | this.frequency = data.frequency;
|
3892 | }
|
3893 |
|
3894 | if (data.opacity !== undefined) {
|
3895 | this.opacity = data.opacity;
|
3896 | }
|
3897 | }
|
3898 |
|
3899 | }
|
3900 | ;
|
3901 |
|
3902 |
|
3903 |
|
3904 | class Links {
|
3905 | constructor() {
|
3906 | this.blink = false;
|
3907 | this.color = new OptionsColor();
|
3908 | this.consent = false;
|
3909 | this.distance = 100;
|
3910 | this.enable = false;
|
3911 | this.frequency = 1;
|
3912 | this.opacity = 1;
|
3913 | this.shadow = new LinksShadow();
|
3914 | this.triangles = new LinksTriangle();
|
3915 | this.width = 1;
|
3916 | this.warp = false;
|
3917 | }
|
3918 |
|
3919 | load(data) {
|
3920 | if (data === undefined) {
|
3921 | return;
|
3922 | }
|
3923 |
|
3924 | if (data.id !== undefined) {
|
3925 | this.id = data.id;
|
3926 | }
|
3927 |
|
3928 | if (data.blink !== undefined) {
|
3929 | this.blink = data.blink;
|
3930 | }
|
3931 |
|
3932 | this.color = OptionsColor.create(this.color, data.color);
|
3933 |
|
3934 | if (data.consent !== undefined) {
|
3935 | this.consent = data.consent;
|
3936 | }
|
3937 |
|
3938 | if (data.distance !== undefined) {
|
3939 | this.distance = data.distance;
|
3940 | }
|
3941 |
|
3942 | if (data.enable !== undefined) {
|
3943 | this.enable = data.enable;
|
3944 | }
|
3945 |
|
3946 | if (data.frequency !== undefined) {
|
3947 | this.frequency = data.frequency;
|
3948 | }
|
3949 |
|
3950 | if (data.opacity !== undefined) {
|
3951 | this.opacity = data.opacity;
|
3952 | }
|
3953 |
|
3954 | this.shadow.load(data.shadow);
|
3955 | this.triangles.load(data.triangles);
|
3956 |
|
3957 | if (data.width !== undefined) {
|
3958 | this.width = data.width;
|
3959 | }
|
3960 |
|
3961 | if (data.warp !== undefined) {
|
3962 | this.warp = data.warp;
|
3963 | }
|
3964 | }
|
3965 |
|
3966 | }
|
3967 | ;
|
3968 | class Attract {
|
3969 | constructor() {
|
3970 | this.enable = false;
|
3971 | this.rotate = {
|
3972 | x: 3000,
|
3973 | y: 3000
|
3974 | };
|
3975 | }
|
3976 |
|
3977 | get rotateX() {
|
3978 | return this.rotate.x;
|
3979 | }
|
3980 |
|
3981 | set rotateX(value) {
|
3982 | this.rotate.x = value;
|
3983 | }
|
3984 |
|
3985 | get rotateY() {
|
3986 | return this.rotate.y;
|
3987 | }
|
3988 |
|
3989 | set rotateY(value) {
|
3990 | this.rotate.y = value;
|
3991 | }
|
3992 |
|
3993 | load(data) {
|
3994 | var _a, _b, _c, _d;
|
3995 |
|
3996 | if (data === undefined) {
|
3997 | return;
|
3998 | }
|
3999 |
|
4000 | if (data.enable !== undefined) {
|
4001 | this.enable = data.enable;
|
4002 | }
|
4003 |
|
4004 | const rotateX = (_b = (_a = data.rotate) === null || _a === void 0 ? void 0 : _a.x) !== null && _b !== void 0 ? _b : data.rotateX;
|
4005 |
|
4006 | if (rotateX !== undefined) {
|
4007 | this.rotate.x = rotateX;
|
4008 | }
|
4009 |
|
4010 | const rotateY = (_d = (_c = data.rotate) === null || _c === void 0 ? void 0 : _c.y) !== null && _d !== void 0 ? _d : data.rotateY;
|
4011 |
|
4012 | if (rotateY !== undefined) {
|
4013 | this.rotate.y = rotateY;
|
4014 | }
|
4015 | }
|
4016 |
|
4017 | }
|
4018 | ;
|
4019 |
|
4020 | class Trail {
|
4021 | constructor() {
|
4022 | this.enable = false;
|
4023 | this.length = 10;
|
4024 | this.fillColor = new OptionsColor();
|
4025 | this.fillColor.value = "#000000";
|
4026 | }
|
4027 |
|
4028 | load(data) {
|
4029 | if (data === undefined) {
|
4030 | return;
|
4031 | }
|
4032 |
|
4033 | if (data.enable !== undefined) {
|
4034 | this.enable = data.enable;
|
4035 | }
|
4036 |
|
4037 | this.fillColor = OptionsColor.create(this.fillColor, data.fillColor);
|
4038 |
|
4039 | if (data.length !== undefined) {
|
4040 | this.length = data.length;
|
4041 | }
|
4042 | }
|
4043 |
|
4044 | }
|
4045 | ;
|
4046 | class Random {
|
4047 | constructor() {
|
4048 | this.enable = false;
|
4049 | this.minimumValue = 0;
|
4050 | }
|
4051 |
|
4052 | load(data) {
|
4053 | if (!data) {
|
4054 | return;
|
4055 | }
|
4056 |
|
4057 | if (data.enable !== undefined) {
|
4058 | this.enable = data.enable;
|
4059 | }
|
4060 |
|
4061 | if (data.minimumValue !== undefined) {
|
4062 | this.minimumValue = data.minimumValue;
|
4063 | }
|
4064 | }
|
4065 |
|
4066 | }
|
4067 | ;
|
4068 |
|
4069 |
|
4070 | class ValueWithRandom {
|
4071 | constructor() {
|
4072 | this.random = new Random();
|
4073 | this.value = 0;
|
4074 | }
|
4075 |
|
4076 | load(data) {
|
4077 | if (!data) {
|
4078 | return;
|
4079 | }
|
4080 |
|
4081 | if (typeof data.random === "boolean") {
|
4082 | this.random.enable = data.random;
|
4083 | } else {
|
4084 | this.random.load(data.random);
|
4085 | }
|
4086 |
|
4087 | if (data.value !== undefined) {
|
4088 | this.value = NumberUtils.setRangeValue(data.value, this.random.enable ? this.random.minimumValue : undefined);
|
4089 | }
|
4090 | }
|
4091 |
|
4092 | }
|
4093 | ;
|
4094 |
|
4095 | class PathDelay extends ValueWithRandom {
|
4096 | constructor() {
|
4097 | super();
|
4098 | }
|
4099 |
|
4100 | }
|
4101 | ;
|
4102 |
|
4103 | class Path {
|
4104 | constructor() {
|
4105 | this.clamp = true;
|
4106 | this.delay = new PathDelay();
|
4107 | this.enable = false;
|
4108 | }
|
4109 |
|
4110 | load(data) {
|
4111 | if (data === undefined) {
|
4112 | return;
|
4113 | }
|
4114 |
|
4115 | if (data.clamp !== undefined) {
|
4116 | this.clamp = data.clamp;
|
4117 | }
|
4118 |
|
4119 | this.delay.load(data.delay);
|
4120 |
|
4121 | if (data.enable !== undefined) {
|
4122 | this.enable = data.enable;
|
4123 | }
|
4124 |
|
4125 | this.generator = data.generator;
|
4126 | }
|
4127 |
|
4128 | }
|
4129 | ;
|
4130 | class MoveAngle {
|
4131 | constructor() {
|
4132 | this.offset = 45;
|
4133 | this.value = 90;
|
4134 | }
|
4135 |
|
4136 | load(data) {
|
4137 | if (data === undefined) {
|
4138 | return;
|
4139 | }
|
4140 |
|
4141 | if (data.offset !== undefined) {
|
4142 | this.offset = data.offset;
|
4143 | }
|
4144 |
|
4145 | if (data.value !== undefined) {
|
4146 | this.value = data.value;
|
4147 | }
|
4148 | }
|
4149 |
|
4150 | }
|
4151 | ;
|
4152 | class MoveGravity {
|
4153 | constructor() {
|
4154 | this.acceleration = 9.81;
|
4155 | this.enable = false;
|
4156 | this.maxSpeed = 50;
|
4157 | }
|
4158 |
|
4159 | load(data) {
|
4160 | if (!data) {
|
4161 | return;
|
4162 | }
|
4163 |
|
4164 | if (data.acceleration !== undefined) {
|
4165 | this.acceleration = data.acceleration;
|
4166 | }
|
4167 |
|
4168 | if (data.enable !== undefined) {
|
4169 | this.enable = data.enable;
|
4170 | }
|
4171 |
|
4172 | if (data.maxSpeed !== undefined) {
|
4173 | this.maxSpeed = data.maxSpeed;
|
4174 | }
|
4175 | }
|
4176 |
|
4177 | }
|
4178 | ;
|
4179 |
|
4180 | class OutModes {
|
4181 | constructor() {
|
4182 | this.default = OutMode.out;
|
4183 | }
|
4184 |
|
4185 | load(data) {
|
4186 | var _a, _b, _c, _d;
|
4187 |
|
4188 | if (!data) {
|
4189 | return;
|
4190 | }
|
4191 |
|
4192 | if (data.default !== undefined) {
|
4193 | this.default = data.default;
|
4194 | }
|
4195 |
|
4196 | this.bottom = (_a = data.bottom) !== null && _a !== void 0 ? _a : data.default;
|
4197 | this.left = (_b = data.left) !== null && _b !== void 0 ? _b : data.default;
|
4198 | this.right = (_c = data.right) !== null && _c !== void 0 ? _c : data.default;
|
4199 | this.top = (_d = data.top) !== null && _d !== void 0 ? _d : data.default;
|
4200 | }
|
4201 |
|
4202 | }
|
4203 | ;
|
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 |
|
4210 |
|
4211 |
|
4212 | class Move {
|
4213 | constructor() {
|
4214 | this.angle = new MoveAngle();
|
4215 | this.attract = new Attract();
|
4216 | this.decay = 0;
|
4217 | this.distance = 0;
|
4218 | this.direction = MoveDirection.none;
|
4219 | this.drift = 0;
|
4220 | this.enable = false;
|
4221 | this.gravity = new MoveGravity();
|
4222 | this.path = new Path();
|
4223 | this.outModes = new OutModes();
|
4224 | this.random = false;
|
4225 | this.size = false;
|
4226 | this.speed = 2;
|
4227 | this.straight = false;
|
4228 | this.trail = new Trail();
|
4229 | this.vibrate = false;
|
4230 | this.warp = false;
|
4231 | }
|
4232 |
|
4233 | get collisions() {
|
4234 | return false;
|
4235 | }
|
4236 |
|
4237 | set collisions(value) {}
|
4238 |
|
4239 | get bounce() {
|
4240 | return this.collisions;
|
4241 | }
|
4242 |
|
4243 | set bounce(value) {
|
4244 | this.collisions = value;
|
4245 | }
|
4246 |
|
4247 | get out_mode() {
|
4248 | return this.outMode;
|
4249 | }
|
4250 |
|
4251 | set out_mode(value) {
|
4252 | this.outMode = value;
|
4253 | }
|
4254 |
|
4255 | get outMode() {
|
4256 | return this.outModes.default;
|
4257 | }
|
4258 |
|
4259 | set outMode(value) {
|
4260 | this.outModes.default = value;
|
4261 | }
|
4262 |
|
4263 | get noise() {
|
4264 | return this.path;
|
4265 | }
|
4266 |
|
4267 | set noise(value) {
|
4268 | this.path = value;
|
4269 | }
|
4270 |
|
4271 | load(data) {
|
4272 | var _a, _b, _c;
|
4273 |
|
4274 | if (data === undefined) {
|
4275 | return;
|
4276 | }
|
4277 |
|
4278 | if (data.angle !== undefined) {
|
4279 | if (typeof data.angle === "number") {
|
4280 | this.angle.value = data.angle;
|
4281 | } else {
|
4282 | this.angle.load(data.angle);
|
4283 | }
|
4284 | }
|
4285 |
|
4286 | this.attract.load(data.attract);
|
4287 |
|
4288 | if (data.decay !== undefined) {
|
4289 | this.decay = data.decay;
|
4290 | }
|
4291 |
|
4292 | if (data.direction !== undefined) {
|
4293 | this.direction = data.direction;
|
4294 | }
|
4295 |
|
4296 | if (data.distance !== undefined) {
|
4297 | this.distance = data.distance;
|
4298 | }
|
4299 |
|
4300 | if (data.drift !== undefined) {
|
4301 | this.drift = NumberUtils.setRangeValue(data.drift);
|
4302 | }
|
4303 |
|
4304 | if (data.enable !== undefined) {
|
4305 | this.enable = data.enable;
|
4306 | }
|
4307 |
|
4308 | this.gravity.load(data.gravity);
|
4309 | const outMode = (_a = data.outMode) !== null && _a !== void 0 ? _a : data.out_mode;
|
4310 |
|
4311 | if (data.outModes !== undefined || outMode !== undefined) {
|
4312 | if (typeof data.outModes === "string" || data.outModes === undefined && outMode !== undefined) {
|
4313 | this.outModes.load({
|
4314 | default: (_b = data.outModes) !== null && _b !== void 0 ? _b : outMode
|
4315 | });
|
4316 | } else {
|
4317 | this.outModes.load(data.outModes);
|
4318 | }
|
4319 | }
|
4320 |
|
4321 | this.path.load((_c = data.path) !== null && _c !== void 0 ? _c : data.noise);
|
4322 |
|
4323 | if (data.random !== undefined) {
|
4324 | this.random = data.random;
|
4325 | }
|
4326 |
|
4327 | if (data.size !== undefined) {
|
4328 | this.size = data.size;
|
4329 | }
|
4330 |
|
4331 | if (data.speed !== undefined) {
|
4332 | this.speed = NumberUtils.setRangeValue(data.speed);
|
4333 | }
|
4334 |
|
4335 | if (data.straight !== undefined) {
|
4336 | this.straight = data.straight;
|
4337 | }
|
4338 |
|
4339 | this.trail.load(data.trail);
|
4340 |
|
4341 | if (data.vibrate !== undefined) {
|
4342 | this.vibrate = data.vibrate;
|
4343 | }
|
4344 |
|
4345 | if (data.warp !== undefined) {
|
4346 | this.warp = data.warp;
|
4347 | }
|
4348 | }
|
4349 |
|
4350 | }
|
4351 | ;
|
4352 | class Density {
|
4353 | constructor() {
|
4354 | this.enable = false;
|
4355 | this.area = 800;
|
4356 | this.factor = 1000;
|
4357 | }
|
4358 |
|
4359 | get value_area() {
|
4360 | return this.area;
|
4361 | }
|
4362 |
|
4363 | set value_area(value) {
|
4364 | this.area = value;
|
4365 | }
|
4366 |
|
4367 | load(data) {
|
4368 | var _a;
|
4369 |
|
4370 | if (data === undefined) {
|
4371 | return;
|
4372 | }
|
4373 |
|
4374 | if (data.enable !== undefined) {
|
4375 | this.enable = data.enable;
|
4376 | }
|
4377 |
|
4378 | const area = (_a = data.area) !== null && _a !== void 0 ? _a : data.value_area;
|
4379 |
|
4380 | if (area !== undefined) {
|
4381 | this.area = area;
|
4382 | }
|
4383 |
|
4384 | if (data.factor !== undefined) {
|
4385 | this.factor = data.factor;
|
4386 | }
|
4387 | }
|
4388 |
|
4389 | }
|
4390 | ;
|
4391 |
|
4392 | class ParticlesNumber {
|
4393 | constructor() {
|
4394 | this.density = new Density();
|
4395 | this.limit = 0;
|
4396 | this.value = 100;
|
4397 | }
|
4398 |
|
4399 | get max() {
|
4400 | return this.limit;
|
4401 | }
|
4402 |
|
4403 | set max(value) {
|
4404 | this.limit = value;
|
4405 | }
|
4406 |
|
4407 | load(data) {
|
4408 | var _a;
|
4409 |
|
4410 | if (data === undefined) {
|
4411 | return;
|
4412 | }
|
4413 |
|
4414 | this.density.load(data.density);
|
4415 | const limit = (_a = data.limit) !== null && _a !== void 0 ? _a : data.max;
|
4416 |
|
4417 | if (limit !== undefined) {
|
4418 | this.limit = limit;
|
4419 | }
|
4420 |
|
4421 | if (data.value !== undefined) {
|
4422 | this.value = data.value;
|
4423 | }
|
4424 | }
|
4425 |
|
4426 | }
|
4427 | ;
|
4428 | class AnimationOptions {
|
4429 | constructor() {
|
4430 | this.count = 0;
|
4431 | this.enable = false;
|
4432 | this.speed = 1;
|
4433 | this.sync = false;
|
4434 | }
|
4435 |
|
4436 | load(data) {
|
4437 | if (!data) {
|
4438 | return;
|
4439 | }
|
4440 |
|
4441 | if (data.count !== undefined) {
|
4442 | this.count = data.count;
|
4443 | }
|
4444 |
|
4445 | if (data.enable !== undefined) {
|
4446 | this.enable = data.enable;
|
4447 | }
|
4448 |
|
4449 | if (data.speed !== undefined) {
|
4450 | this.speed = data.speed;
|
4451 | }
|
4452 |
|
4453 | if (data.sync !== undefined) {
|
4454 | this.sync = data.sync;
|
4455 | }
|
4456 | }
|
4457 |
|
4458 | }
|
4459 | ;
|
4460 |
|
4461 |
|
4462 | class OpacityAnimation extends AnimationOptions {
|
4463 | constructor() {
|
4464 | super();
|
4465 | this.destroy = DestroyType.none;
|
4466 | this.enable = false;
|
4467 | this.minimumValue = 0;
|
4468 | this.speed = 2;
|
4469 | this.startValue = StartValueType.random;
|
4470 | this.sync = false;
|
4471 | }
|
4472 |
|
4473 | get opacity_min() {
|
4474 | return this.minimumValue;
|
4475 | }
|
4476 |
|
4477 | set opacity_min(value) {
|
4478 | this.minimumValue = value;
|
4479 | }
|
4480 |
|
4481 | load(data) {
|
4482 | var _a;
|
4483 |
|
4484 | if (data === undefined) {
|
4485 | return;
|
4486 | }
|
4487 |
|
4488 | super.load(data);
|
4489 |
|
4490 | if (data.destroy !== undefined) {
|
4491 | this.destroy = data.destroy;
|
4492 | }
|
4493 |
|
4494 | if (data.enable !== undefined) {
|
4495 | this.enable = data.enable;
|
4496 | }
|
4497 |
|
4498 | const minimumValue = (_a = data.minimumValue) !== null && _a !== void 0 ? _a : data.opacity_min;
|
4499 |
|
4500 | if (minimumValue !== undefined) {
|
4501 | this.minimumValue = minimumValue;
|
4502 | }
|
4503 |
|
4504 | if (data.speed !== undefined) {
|
4505 | this.speed = data.speed;
|
4506 | }
|
4507 |
|
4508 | if (data.startValue !== undefined) {
|
4509 | this.startValue = data.startValue;
|
4510 | }
|
4511 |
|
4512 | if (data.sync !== undefined) {
|
4513 | this.sync = data.sync;
|
4514 | }
|
4515 | }
|
4516 |
|
4517 | }
|
4518 | ;
|
4519 |
|
4520 |
|
4521 |
|
4522 | class Opacity extends ValueWithRandom {
|
4523 | constructor() {
|
4524 | super();
|
4525 | this.animation = new OpacityAnimation();
|
4526 | this.random.minimumValue = 0.1;
|
4527 | this.value = 1;
|
4528 | }
|
4529 |
|
4530 | get anim() {
|
4531 | return this.animation;
|
4532 | }
|
4533 |
|
4534 | set anim(value) {
|
4535 | this.animation = value;
|
4536 | }
|
4537 |
|
4538 | load(data) {
|
4539 | var _a;
|
4540 |
|
4541 | if (!data) {
|
4542 | return;
|
4543 | }
|
4544 |
|
4545 | super.load(data);
|
4546 | const animation = (_a = data.animation) !== null && _a !== void 0 ? _a : data.anim;
|
4547 |
|
4548 | if (animation !== undefined) {
|
4549 | this.animation.load(animation);
|
4550 | this.value = NumberUtils.setRangeValue(this.value, this.animation.enable ? this.animation.minimumValue : undefined);
|
4551 | }
|
4552 | }
|
4553 |
|
4554 | }
|
4555 | ;
|
4556 |
|
4557 |
|
4558 | class Shape {
|
4559 | constructor() {
|
4560 | this.options = {};
|
4561 | this.type = ShapeType.circle;
|
4562 | }
|
4563 |
|
4564 | get image() {
|
4565 | var _a;
|
4566 |
|
4567 | return (_a = this.options[ShapeType.image]) !== null && _a !== void 0 ? _a : this.options[ShapeType.images];
|
4568 | }
|
4569 |
|
4570 | set image(value) {
|
4571 | this.options[ShapeType.image] = value;
|
4572 | this.options[ShapeType.images] = value;
|
4573 | }
|
4574 |
|
4575 | get custom() {
|
4576 | return this.options;
|
4577 | }
|
4578 |
|
4579 | set custom(value) {
|
4580 | this.options = value;
|
4581 | }
|
4582 |
|
4583 | get images() {
|
4584 | return this.image instanceof Array ? this.image : [this.image];
|
4585 | }
|
4586 |
|
4587 | set images(value) {
|
4588 | this.image = value;
|
4589 | }
|
4590 |
|
4591 | get stroke() {
|
4592 | return [];
|
4593 | }
|
4594 |
|
4595 | set stroke(_value) {}
|
4596 |
|
4597 | get character() {
|
4598 | var _a;
|
4599 |
|
4600 | return (_a = this.options[ShapeType.character]) !== null && _a !== void 0 ? _a : this.options[ShapeType.char];
|
4601 | }
|
4602 |
|
4603 | set character(value) {
|
4604 | this.options[ShapeType.character] = value;
|
4605 | this.options[ShapeType.char] = value;
|
4606 | }
|
4607 |
|
4608 | get polygon() {
|
4609 | var _a;
|
4610 |
|
4611 | return (_a = this.options[ShapeType.polygon]) !== null && _a !== void 0 ? _a : this.options[ShapeType.star];
|
4612 | }
|
4613 |
|
4614 | set polygon(value) {
|
4615 | this.options[ShapeType.polygon] = value;
|
4616 | this.options[ShapeType.star] = value;
|
4617 | }
|
4618 |
|
4619 | load(data) {
|
4620 | var _a, _b, _c;
|
4621 |
|
4622 | if (data === undefined) {
|
4623 | return;
|
4624 | }
|
4625 |
|
4626 | const options = (_a = data.options) !== null && _a !== void 0 ? _a : data.custom;
|
4627 |
|
4628 | if (options !== undefined) {
|
4629 | for (const shape in options) {
|
4630 | const item = options[shape];
|
4631 |
|
4632 | if (item !== undefined) {
|
4633 | this.options[shape] = Utils.deepExtend((_b = this.options[shape]) !== null && _b !== void 0 ? _b : {}, item);
|
4634 | }
|
4635 | }
|
4636 | }
|
4637 |
|
4638 | this.loadShape(data.character, ShapeType.character, ShapeType.char, true);
|
4639 | this.loadShape(data.polygon, ShapeType.polygon, ShapeType.star, false);
|
4640 | this.loadShape((_c = data.image) !== null && _c !== void 0 ? _c : data.images, ShapeType.image, ShapeType.images, true);
|
4641 |
|
4642 | if (data.type !== undefined) {
|
4643 | this.type = data.type;
|
4644 | }
|
4645 | }
|
4646 |
|
4647 | loadShape(item, mainKey, altKey, altOverride) {
|
4648 | var _a, _b, _c, _d;
|
4649 |
|
4650 | if (item === undefined) {
|
4651 | return;
|
4652 | }
|
4653 |
|
4654 | if (item instanceof Array) {
|
4655 | if (!(this.options[mainKey] instanceof Array)) {
|
4656 | this.options[mainKey] = [];
|
4657 |
|
4658 | if (!this.options[altKey] || altOverride) {
|
4659 | this.options[altKey] = [];
|
4660 | }
|
4661 | }
|
4662 |
|
4663 | this.options[mainKey] = Utils.deepExtend((_a = this.options[mainKey]) !== null && _a !== void 0 ? _a : [], item);
|
4664 |
|
4665 | if (!this.options[altKey] || altOverride) {
|
4666 | this.options[altKey] = Utils.deepExtend((_b = this.options[altKey]) !== null && _b !== void 0 ? _b : [], item);
|
4667 | }
|
4668 | } else {
|
4669 | if (this.options[mainKey] instanceof Array) {
|
4670 | this.options[mainKey] = {};
|
4671 |
|
4672 | if (!this.options[altKey] || altOverride) {
|
4673 | this.options[altKey] = {};
|
4674 | }
|
4675 | }
|
4676 |
|
4677 | this.options[mainKey] = Utils.deepExtend((_c = this.options[mainKey]) !== null && _c !== void 0 ? _c : {}, item);
|
4678 |
|
4679 | if (!this.options[altKey] || altOverride) {
|
4680 | this.options[altKey] = Utils.deepExtend((_d = this.options[altKey]) !== null && _d !== void 0 ? _d : {}, item);
|
4681 | }
|
4682 | }
|
4683 | }
|
4684 |
|
4685 | }
|
4686 | ;
|
4687 |
|
4688 |
|
4689 | class SizeAnimation extends AnimationOptions {
|
4690 | constructor() {
|
4691 | super();
|
4692 | this.destroy = DestroyType.none;
|
4693 | this.enable = false;
|
4694 | this.minimumValue = 0;
|
4695 | this.speed = 5;
|
4696 | this.startValue = StartValueType.random;
|
4697 | this.sync = false;
|
4698 | }
|
4699 |
|
4700 | get size_min() {
|
4701 | return this.minimumValue;
|
4702 | }
|
4703 |
|
4704 | set size_min(value) {
|
4705 | this.minimumValue = value;
|
4706 | }
|
4707 |
|
4708 | load(data) {
|
4709 | var _a;
|
4710 |
|
4711 | if (data === undefined) {
|
4712 | return;
|
4713 | }
|
4714 |
|
4715 | super.load(data);
|
4716 |
|
4717 | if (data.destroy !== undefined) {
|
4718 | this.destroy = data.destroy;
|
4719 | }
|
4720 |
|
4721 | if (data.enable !== undefined) {
|
4722 | this.enable = data.enable;
|
4723 | }
|
4724 |
|
4725 | const minimumValue = (_a = data.minimumValue) !== null && _a !== void 0 ? _a : data.size_min;
|
4726 |
|
4727 | if (minimumValue !== undefined) {
|
4728 | this.minimumValue = minimumValue;
|
4729 | }
|
4730 |
|
4731 | if (data.speed !== undefined) {
|
4732 | this.speed = data.speed;
|
4733 | }
|
4734 |
|
4735 | if (data.startValue !== undefined) {
|
4736 | this.startValue = data.startValue;
|
4737 | }
|
4738 |
|
4739 | if (data.sync !== undefined) {
|
4740 | this.sync = data.sync;
|
4741 | }
|
4742 | }
|
4743 |
|
4744 | }
|
4745 | ;
|
4746 |
|
4747 |
|
4748 |
|
4749 | class Size extends ValueWithRandom {
|
4750 | constructor() {
|
4751 | super();
|
4752 | this.animation = new SizeAnimation();
|
4753 | this.random.minimumValue = 1;
|
4754 | this.value = 3;
|
4755 | }
|
4756 |
|
4757 | get anim() {
|
4758 | return this.animation;
|
4759 | }
|
4760 |
|
4761 | set anim(value) {
|
4762 | this.animation = value;
|
4763 | }
|
4764 |
|
4765 | load(data) {
|
4766 | var _a;
|
4767 |
|
4768 | if (!data) {
|
4769 | return;
|
4770 | }
|
4771 |
|
4772 | super.load(data);
|
4773 | const animation = (_a = data.animation) !== null && _a !== void 0 ? _a : data.anim;
|
4774 |
|
4775 | if (animation !== undefined) {
|
4776 | this.animation.load(animation);
|
4777 | this.value = NumberUtils.setRangeValue(this.value, this.animation.enable ? this.animation.minimumValue : undefined);
|
4778 | }
|
4779 | }
|
4780 |
|
4781 | }
|
4782 | ;
|
4783 | class RotateAnimation {
|
4784 | constructor() {
|
4785 | this.enable = false;
|
4786 | this.speed = 0;
|
4787 | this.sync = false;
|
4788 | }
|
4789 |
|
4790 | load(data) {
|
4791 | if (data === undefined) {
|
4792 | return;
|
4793 | }
|
4794 |
|
4795 | if (data.enable !== undefined) {
|
4796 | this.enable = data.enable;
|
4797 | }
|
4798 |
|
4799 | if (data.speed !== undefined) {
|
4800 | this.speed = data.speed;
|
4801 | }
|
4802 |
|
4803 | if (data.sync !== undefined) {
|
4804 | this.sync = data.sync;
|
4805 | }
|
4806 | }
|
4807 |
|
4808 | }
|
4809 | ;
|
4810 |
|
4811 |
|
4812 |
|
4813 | class Rotate extends ValueWithRandom {
|
4814 | constructor() {
|
4815 | super();
|
4816 | this.animation = new RotateAnimation();
|
4817 | this.direction = RotateDirection.clockwise;
|
4818 | this.path = false;
|
4819 | this.value = 0;
|
4820 | }
|
4821 |
|
4822 | load(data) {
|
4823 | if (!data) {
|
4824 | return;
|
4825 | }
|
4826 |
|
4827 | super.load(data);
|
4828 |
|
4829 | if (data.direction !== undefined) {
|
4830 | this.direction = data.direction;
|
4831 | }
|
4832 |
|
4833 | this.animation.load(data.animation);
|
4834 |
|
4835 | if (data.path !== undefined) {
|
4836 | this.path = data.path;
|
4837 | }
|
4838 | }
|
4839 |
|
4840 | }
|
4841 | ;
|
4842 |
|
4843 | class Shadow {
|
4844 | constructor() {
|
4845 | this.blur = 0;
|
4846 | this.color = new OptionsColor();
|
4847 | this.enable = false;
|
4848 | this.offset = {
|
4849 | x: 0,
|
4850 | y: 0
|
4851 | };
|
4852 | this.color.value = "#000000";
|
4853 | }
|
4854 |
|
4855 | load(data) {
|
4856 | if (data === undefined) {
|
4857 | return;
|
4858 | }
|
4859 |
|
4860 | if (data.blur !== undefined) {
|
4861 | this.blur = data.blur;
|
4862 | }
|
4863 |
|
4864 | this.color = OptionsColor.create(this.color, data.color);
|
4865 |
|
4866 | if (data.enable !== undefined) {
|
4867 | this.enable = data.enable;
|
4868 | }
|
4869 |
|
4870 | if (data.offset === undefined) {
|
4871 | return;
|
4872 | }
|
4873 |
|
4874 | if (data.offset.x !== undefined) {
|
4875 | this.offset.x = data.offset.x;
|
4876 | }
|
4877 |
|
4878 | if (data.offset.y !== undefined) {
|
4879 | this.offset.y = data.offset.y;
|
4880 | }
|
4881 | }
|
4882 |
|
4883 | }
|
4884 | ;
|
4885 |
|
4886 | class ColorAnimation {
|
4887 | constructor() {
|
4888 | this.count = 0;
|
4889 | this.enable = false;
|
4890 | this.offset = 0;
|
4891 | this.speed = 1;
|
4892 | this.sync = true;
|
4893 | }
|
4894 |
|
4895 | load(data) {
|
4896 | if (data === undefined) {
|
4897 | return;
|
4898 | }
|
4899 |
|
4900 | if (data.count !== undefined) {
|
4901 | this.count = data.count;
|
4902 | }
|
4903 |
|
4904 | if (data.enable !== undefined) {
|
4905 | this.enable = data.enable;
|
4906 | }
|
4907 |
|
4908 | if (data.offset !== undefined) {
|
4909 | this.offset = NumberUtils.setRangeValue(data.offset);
|
4910 | }
|
4911 |
|
4912 | if (data.speed !== undefined) {
|
4913 | this.speed = data.speed;
|
4914 | }
|
4915 |
|
4916 | if (data.sync !== undefined) {
|
4917 | this.sync = data.sync;
|
4918 | }
|
4919 | }
|
4920 |
|
4921 | }
|
4922 | ;
|
4923 |
|
4924 | class HslAnimation {
|
4925 | constructor() {
|
4926 | this.h = new ColorAnimation();
|
4927 | this.s = new ColorAnimation();
|
4928 | this.l = new ColorAnimation();
|
4929 | }
|
4930 |
|
4931 | load(data) {
|
4932 | if (!data) {
|
4933 | return;
|
4934 | }
|
4935 |
|
4936 | this.h.load(data.h);
|
4937 | this.s.load(data.s);
|
4938 | this.l.load(data.l);
|
4939 | }
|
4940 |
|
4941 | }
|
4942 | ;
|
4943 |
|
4944 |
|
4945 | class AnimatableColor extends OptionsColor {
|
4946 | constructor() {
|
4947 | super();
|
4948 | this.animation = new HslAnimation();
|
4949 | }
|
4950 |
|
4951 | static create(source, data) {
|
4952 | const color = source !== null && source !== void 0 ? source : new AnimatableColor();
|
4953 |
|
4954 | if (data !== undefined) {
|
4955 | color.load(typeof data === "string" ? {
|
4956 | value: data
|
4957 | } : data);
|
4958 | }
|
4959 |
|
4960 | return color;
|
4961 | }
|
4962 |
|
4963 | load(data) {
|
4964 | super.load(data);
|
4965 |
|
4966 | if (!data) {
|
4967 | return;
|
4968 | }
|
4969 |
|
4970 | const colorAnimation = data.animation;
|
4971 |
|
4972 | if (colorAnimation !== undefined) {
|
4973 | if (colorAnimation.enable !== undefined) {
|
4974 | this.animation.h.load(colorAnimation);
|
4975 | } else {
|
4976 | this.animation.load(data.animation);
|
4977 | }
|
4978 | }
|
4979 | }
|
4980 |
|
4981 | }
|
4982 | ;
|
4983 |
|
4984 | class Stroke {
|
4985 | constructor() {
|
4986 | this.width = 0;
|
4987 | }
|
4988 |
|
4989 | load(data) {
|
4990 | if (data === undefined) {
|
4991 | return;
|
4992 | }
|
4993 |
|
4994 | if (data.color !== undefined) {
|
4995 | this.color = AnimatableColor.create(this.color, data.color);
|
4996 | }
|
4997 |
|
4998 | if (data.width !== undefined) {
|
4999 | this.width = data.width;
|
5000 | }
|
5001 |
|
5002 | if (data.opacity !== undefined) {
|
5003 | this.opacity = data.opacity;
|
5004 | }
|
5005 | }
|
5006 |
|
5007 | }
|
5008 | ;
|
5009 |
|
5010 | class BounceFactor extends ValueWithRandom {
|
5011 | constructor() {
|
5012 | super();
|
5013 | this.random.minimumValue = 0.1;
|
5014 | this.value = 1;
|
5015 | }
|
5016 |
|
5017 | }
|
5018 | ;
|
5019 |
|
5020 | class Bounce {
|
5021 | constructor() {
|
5022 | this.horizontal = new BounceFactor();
|
5023 | this.vertical = new BounceFactor();
|
5024 | }
|
5025 |
|
5026 | load(data) {
|
5027 | if (!data) {
|
5028 | return;
|
5029 | }
|
5030 |
|
5031 | this.horizontal.load(data.horizontal);
|
5032 | this.vertical.load(data.vertical);
|
5033 | }
|
5034 |
|
5035 | }
|
5036 | ;
|
5037 | class CollisionsOverlap {
|
5038 | constructor() {
|
5039 | this.enable = true;
|
5040 | this.retries = 0;
|
5041 | }
|
5042 |
|
5043 | load(data) {
|
5044 | if (!data) {
|
5045 | return;
|
5046 | }
|
5047 |
|
5048 | if (data.enable !== undefined) {
|
5049 | this.enable = data.enable;
|
5050 | }
|
5051 |
|
5052 | if (data.retries !== undefined) {
|
5053 | this.retries = data.retries;
|
5054 | }
|
5055 | }
|
5056 |
|
5057 | }
|
5058 | ;
|
5059 |
|
5060 |
|
5061 |
|
5062 | class Collisions {
|
5063 | constructor() {
|
5064 | this.bounce = new Bounce();
|
5065 | this.enable = false;
|
5066 | this.mode = CollisionMode.bounce;
|
5067 | this.overlap = new CollisionsOverlap();
|
5068 | }
|
5069 |
|
5070 | load(data) {
|
5071 | if (data === undefined) {
|
5072 | return;
|
5073 | }
|
5074 |
|
5075 | this.bounce.load(data.bounce);
|
5076 |
|
5077 | if (data.enable !== undefined) {
|
5078 | this.enable = data.enable;
|
5079 | }
|
5080 |
|
5081 | if (data.mode !== undefined) {
|
5082 | this.mode = data.mode;
|
5083 | }
|
5084 |
|
5085 | this.overlap.load(data.overlap);
|
5086 | }
|
5087 |
|
5088 | }
|
5089 | ;
|
5090 |
|
5091 | class TwinkleValues {
|
5092 | constructor() {
|
5093 | this.enable = false;
|
5094 | this.frequency = 0.05;
|
5095 | this.opacity = 1;
|
5096 | }
|
5097 |
|
5098 | load(data) {
|
5099 | if (data === undefined) {
|
5100 | return;
|
5101 | }
|
5102 |
|
5103 | if (data.color !== undefined) {
|
5104 | this.color = OptionsColor.create(this.color, data.color);
|
5105 | }
|
5106 |
|
5107 | if (data.enable !== undefined) {
|
5108 | this.enable = data.enable;
|
5109 | }
|
5110 |
|
5111 | if (data.frequency !== undefined) {
|
5112 | this.frequency = data.frequency;
|
5113 | }
|
5114 |
|
5115 | if (data.opacity !== undefined) {
|
5116 | this.opacity = data.opacity;
|
5117 | }
|
5118 | }
|
5119 |
|
5120 | }
|
5121 | ;
|
5122 |
|
5123 | class Twinkle {
|
5124 | constructor() {
|
5125 | this.lines = new TwinkleValues();
|
5126 | this.particles = new TwinkleValues();
|
5127 | }
|
5128 |
|
5129 | load(data) {
|
5130 | if (data === undefined) {
|
5131 | return;
|
5132 | }
|
5133 |
|
5134 | this.lines.load(data.lines);
|
5135 | this.particles.load(data.particles);
|
5136 | }
|
5137 |
|
5138 | }
|
5139 | ;
|
5140 |
|
5141 | class LifeDelay extends ValueWithRandom {
|
5142 | constructor() {
|
5143 | super();
|
5144 | this.sync = false;
|
5145 | }
|
5146 |
|
5147 | load(data) {
|
5148 | if (!data) {
|
5149 | return;
|
5150 | }
|
5151 |
|
5152 | super.load(data);
|
5153 |
|
5154 | if (data.sync !== undefined) {
|
5155 | this.sync = data.sync;
|
5156 | }
|
5157 | }
|
5158 |
|
5159 | }
|
5160 | ;
|
5161 |
|
5162 | class LifeDuration extends ValueWithRandom {
|
5163 | constructor() {
|
5164 | super();
|
5165 | this.random.minimumValue = 0.0001;
|
5166 | this.sync = false;
|
5167 | }
|
5168 |
|
5169 | load(data) {
|
5170 | if (data === undefined) {
|
5171 | return;
|
5172 | }
|
5173 |
|
5174 | super.load(data);
|
5175 |
|
5176 | if (data.sync !== undefined) {
|
5177 | this.sync = data.sync;
|
5178 | }
|
5179 | }
|
5180 |
|
5181 | }
|
5182 | ;
|
5183 |
|
5184 |
|
5185 | class Life {
|
5186 | constructor() {
|
5187 | this.count = 0;
|
5188 | this.delay = new LifeDelay();
|
5189 | this.duration = new LifeDuration();
|
5190 | }
|
5191 |
|
5192 | load(data) {
|
5193 | if (data === undefined) {
|
5194 | return;
|
5195 | }
|
5196 |
|
5197 | if (data.count !== undefined) {
|
5198 | this.count = data.count;
|
5199 | }
|
5200 |
|
5201 | this.delay.load(data.delay);
|
5202 | this.duration.load(data.duration);
|
5203 | }
|
5204 |
|
5205 | }
|
5206 | ;
|
5207 |
|
5208 | class SplitFactor extends ValueWithRandom {
|
5209 | constructor() {
|
5210 | super();
|
5211 | this.value = 3;
|
5212 | }
|
5213 |
|
5214 | }
|
5215 | ;
|
5216 |
|
5217 | class SplitRate extends ValueWithRandom {
|
5218 | constructor() {
|
5219 | super();
|
5220 | this.value = {
|
5221 | min: 4,
|
5222 | max: 9
|
5223 | };
|
5224 | }
|
5225 |
|
5226 | }
|
5227 | ;
|
5228 |
|
5229 |
|
5230 |
|
5231 | class Split {
|
5232 | constructor() {
|
5233 | this.count = 1;
|
5234 | this.factor = new SplitFactor();
|
5235 | this.rate = new SplitRate();
|
5236 | }
|
5237 |
|
5238 | load(data) {
|
5239 | if (!data) {
|
5240 | return;
|
5241 | }
|
5242 |
|
5243 | if (data.count !== undefined) {
|
5244 | this.count = data.count;
|
5245 | }
|
5246 |
|
5247 | this.factor.load(data.factor);
|
5248 | this.rate.load(data.rate);
|
5249 |
|
5250 | if (data.particles !== undefined) {
|
5251 | this.particles = Utils.deepExtend({}, data.particles);
|
5252 | }
|
5253 | }
|
5254 |
|
5255 | }
|
5256 | ;
|
5257 |
|
5258 |
|
5259 | class Destroy {
|
5260 | constructor() {
|
5261 | this.mode = DestroyMode.none;
|
5262 | this.split = new Split();
|
5263 | }
|
5264 |
|
5265 | load(data) {
|
5266 | if (!data) {
|
5267 | return;
|
5268 | }
|
5269 |
|
5270 | if (data.mode !== undefined) {
|
5271 | this.mode = data.mode;
|
5272 | }
|
5273 |
|
5274 | this.split.load(data.split);
|
5275 | }
|
5276 |
|
5277 | }
|
5278 | ;
|
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 |
|
5288 |
|
5289 |
|
5290 |
|
5291 |
|
5292 |
|
5293 |
|
5294 | class ParticlesOptions {
|
5295 | constructor() {
|
5296 | this.bounce = new Bounce();
|
5297 | this.collisions = new Collisions();
|
5298 | this.color = new AnimatableColor();
|
5299 | this.destroy = new Destroy();
|
5300 | this.life = new Life();
|
5301 | this.links = new Links();
|
5302 | this.move = new Move();
|
5303 | this.number = new ParticlesNumber();
|
5304 | this.opacity = new Opacity();
|
5305 | this.reduceDuplicates = false;
|
5306 | this.rotate = new Rotate();
|
5307 | this.shadow = new Shadow();
|
5308 | this.shape = new Shape();
|
5309 | this.size = new Size();
|
5310 | this.stroke = new Stroke();
|
5311 | this.twinkle = new Twinkle();
|
5312 | }
|
5313 |
|
5314 | get line_linked() {
|
5315 | return this.links;
|
5316 | }
|
5317 |
|
5318 | set line_linked(value) {
|
5319 | this.links = value;
|
5320 | }
|
5321 |
|
5322 | get lineLinked() {
|
5323 | return this.links;
|
5324 | }
|
5325 |
|
5326 | set lineLinked(value) {
|
5327 | this.links = value;
|
5328 | }
|
5329 |
|
5330 | load(data) {
|
5331 | var _a, _b, _c, _d, _e, _f, _g;
|
5332 |
|
5333 | if (data === undefined) {
|
5334 | return;
|
5335 | }
|
5336 |
|
5337 | this.bounce.load(data.bounce);
|
5338 | this.color = AnimatableColor.create(this.color, data.color);
|
5339 | this.destroy.load(data.destroy);
|
5340 | this.life.load(data.life);
|
5341 | const links = (_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked;
|
5342 |
|
5343 | if (links !== undefined) {
|
5344 | this.links.load(links);
|
5345 | }
|
5346 |
|
5347 | this.move.load(data.move);
|
5348 | this.number.load(data.number);
|
5349 | this.opacity.load(data.opacity);
|
5350 |
|
5351 | if (data.reduceDuplicates !== undefined) {
|
5352 | this.reduceDuplicates = data.reduceDuplicates;
|
5353 | }
|
5354 |
|
5355 | this.rotate.load(data.rotate);
|
5356 | this.shape.load(data.shape);
|
5357 | this.size.load(data.size);
|
5358 | this.shadow.load(data.shadow);
|
5359 | this.twinkle.load(data.twinkle);
|
5360 | const collisions = (_d = (_c = data.move) === null || _c === void 0 ? void 0 : _c.collisions) !== null && _d !== void 0 ? _d : (_e = data.move) === null || _e === void 0 ? void 0 : _e.bounce;
|
5361 |
|
5362 | if (collisions !== undefined) {
|
5363 | this.collisions.enable = collisions;
|
5364 | }
|
5365 |
|
5366 | this.collisions.load(data.collisions);
|
5367 | const strokeToLoad = (_f = data.stroke) !== null && _f !== void 0 ? _f : (_g = data.shape) === null || _g === void 0 ? void 0 : _g.stroke;
|
5368 |
|
5369 | if (strokeToLoad === undefined) {
|
5370 | return;
|
5371 | }
|
5372 |
|
5373 | if (strokeToLoad instanceof Array) {
|
5374 | this.stroke = strokeToLoad.map(s => {
|
5375 | const tmp = new Stroke();
|
5376 | tmp.load(s);
|
5377 | return tmp;
|
5378 | });
|
5379 | } else {
|
5380 | if (this.stroke instanceof Array) {
|
5381 | this.stroke = new Stroke();
|
5382 | }
|
5383 |
|
5384 | this.stroke.load(strokeToLoad);
|
5385 | }
|
5386 | }
|
5387 |
|
5388 | }
|
5389 | ;
|
5390 | class Infecter {
|
5391 | constructor(container) {
|
5392 | this.container = container;
|
5393 | }
|
5394 |
|
5395 | startInfection(stage) {
|
5396 | const options = this.container.actualOptions;
|
5397 | const stages = options.infection.stages;
|
5398 | const stagesCount = stages.length;
|
5399 |
|
5400 | if (stage > stagesCount || stage < 0) {
|
5401 | return;
|
5402 | }
|
5403 |
|
5404 | this.infectionDelay = 0;
|
5405 | this.infectionDelayStage = stage;
|
5406 | }
|
5407 |
|
5408 | updateInfectionStage(stage) {
|
5409 | const options = this.container.actualOptions;
|
5410 | const stagesCount = options.infection.stages.length;
|
5411 |
|
5412 | if (stage > stagesCount || stage < 0 || this.infectionStage !== undefined && this.infectionStage > stage) {
|
5413 | return;
|
5414 | }
|
5415 |
|
5416 | this.infectionStage = stage;
|
5417 | this.infectionTime = 0;
|
5418 | }
|
5419 |
|
5420 | updateInfection(delta) {
|
5421 | const options = this.container.actualOptions;
|
5422 | const infection = options.infection;
|
5423 | const stages = options.infection.stages;
|
5424 | const stagesCount = stages.length;
|
5425 |
|
5426 | if (this.infectionDelay !== undefined && this.infectionDelayStage !== undefined) {
|
5427 | const stage = this.infectionDelayStage;
|
5428 |
|
5429 | if (stage > stagesCount || stage < 0) {
|
5430 | return;
|
5431 | }
|
5432 |
|
5433 | if (this.infectionDelay > infection.delay * 1000) {
|
5434 | this.infectionStage = stage;
|
5435 | this.infectionTime = 0;
|
5436 | delete this.infectionDelay;
|
5437 | delete this.infectionDelayStage;
|
5438 | } else {
|
5439 | this.infectionDelay += delta;
|
5440 | }
|
5441 | } else {
|
5442 | delete this.infectionDelay;
|
5443 | delete this.infectionDelayStage;
|
5444 | }
|
5445 |
|
5446 | if (this.infectionStage !== undefined && this.infectionTime !== undefined) {
|
5447 | const infectionStage = stages[this.infectionStage];
|
5448 |
|
5449 | if (infectionStage.duration !== undefined && infectionStage.duration >= 0) {
|
5450 | if (this.infectionTime > infectionStage.duration * 1000) {
|
5451 | this.nextInfectionStage();
|
5452 | } else {
|
5453 | this.infectionTime += delta;
|
5454 | }
|
5455 | } else {
|
5456 | this.infectionTime += delta;
|
5457 | }
|
5458 | } else {
|
5459 | delete this.infectionStage;
|
5460 | delete this.infectionTime;
|
5461 | }
|
5462 | }
|
5463 |
|
5464 | nextInfectionStage() {
|
5465 | const options = this.container.actualOptions;
|
5466 | const stagesCount = options.infection.stages.length;
|
5467 |
|
5468 | if (stagesCount <= 0 || this.infectionStage === undefined) {
|
5469 | return;
|
5470 | }
|
5471 |
|
5472 | this.infectionTime = 0;
|
5473 |
|
5474 | if (stagesCount <= ++this.infectionStage) {
|
5475 | if (options.infection.cure) {
|
5476 | delete this.infectionStage;
|
5477 | delete this.infectionTime;
|
5478 | return;
|
5479 | } else {
|
5480 | this.infectionStage = 0;
|
5481 | this.infectionTime = 0;
|
5482 | }
|
5483 | }
|
5484 | }
|
5485 |
|
5486 | }
|
5487 | ;
|
5488 |
|
5489 |
|
5490 | class Mover {
|
5491 | constructor(container, particle) {
|
5492 | this.container = container;
|
5493 | this.particle = particle;
|
5494 | }
|
5495 |
|
5496 | move(delta) {
|
5497 | const particle = this.particle;
|
5498 | particle.bubble.inRange = false;
|
5499 | particle.links = [];
|
5500 |
|
5501 | for (const [, plugin] of this.container.plugins) {
|
5502 | if (particle.destroyed) {
|
5503 | break;
|
5504 | }
|
5505 |
|
5506 | if (plugin.particleUpdate) {
|
5507 | plugin.particleUpdate(particle, delta);
|
5508 | }
|
5509 | }
|
5510 |
|
5511 | if (particle.destroyed) {
|
5512 | return;
|
5513 | }
|
5514 |
|
5515 | this.moveParticle(delta);
|
5516 | this.moveParallax();
|
5517 | }
|
5518 |
|
5519 | moveParticle(delta) {
|
5520 | var _a, _b;
|
5521 |
|
5522 | const particle = this.particle;
|
5523 | const particlesOptions = particle.options;
|
5524 |
|
5525 | if (!particlesOptions.move.enable) {
|
5526 | return;
|
5527 | }
|
5528 |
|
5529 | const container = this.container;
|
5530 | const slowFactor = this.getProximitySpeedFactor();
|
5531 | const baseSpeed = ((_a = particle.moveSpeed) !== null && _a !== void 0 ? _a : NumberUtils.getRangeValue(particle.options.move.speed) * container.retina.pixelRatio) * container.retina.reduceFactor;
|
5532 | const maxSize = NumberUtils.getRangeMax(particle.options.size.value) * container.retina.pixelRatio;
|
5533 | const sizeFactor = particlesOptions.move.size ? particle.getRadius() / maxSize : 1;
|
5534 | const moveSpeed = baseSpeed / 2 * sizeFactor * slowFactor * delta.factor;
|
5535 | const moveDrift = (_b = particle.moveDrift) !== null && _b !== void 0 ? _b : NumberUtils.getRangeValue(particle.options.move.drift) * container.retina.pixelRatio;
|
5536 | this.applyPath(delta);
|
5537 | const gravityOptions = particlesOptions.move.gravity;
|
5538 |
|
5539 | if (gravityOptions.enable) {
|
5540 | particle.velocity.y += gravityOptions.acceleration * delta.factor / (60 * moveSpeed);
|
5541 | }
|
5542 |
|
5543 | particle.velocity.x += moveDrift * delta.factor / (60 * moveSpeed);
|
5544 | const decay = 1 - particle.options.move.decay;
|
5545 | particle.velocity.multTo(decay);
|
5546 | const velocity = particle.velocity.mult(moveSpeed);
|
5547 |
|
5548 | if (gravityOptions.enable && velocity.y >= gravityOptions.maxSpeed && gravityOptions.maxSpeed > 0) {
|
5549 | velocity.y = gravityOptions.maxSpeed;
|
5550 | particle.velocity.y = velocity.y / moveSpeed;
|
5551 | }
|
5552 |
|
5553 | particle.position.addTo(velocity);
|
5554 |
|
5555 | if (particlesOptions.move.vibrate) {
|
5556 | particle.position.x += Math.sin(particle.position.x * Math.cos(particle.position.y));
|
5557 | particle.position.y += Math.cos(particle.position.y * Math.sin(particle.position.x));
|
5558 | }
|
5559 |
|
5560 | const initialPosition = particle.initialPosition;
|
5561 | const initialDistance = NumberUtils.getDistance(initialPosition, particle.position);
|
5562 |
|
5563 | if (particle.maxDistance) {
|
5564 | if (initialDistance >= particle.maxDistance && !particle.misplaced) {
|
5565 | particle.misplaced = initialDistance > particle.maxDistance;
|
5566 | particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
5567 | particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
5568 | } else if (initialDistance < particle.maxDistance && particle.misplaced) {
|
5569 | particle.misplaced = false;
|
5570 | } else if (particle.misplaced) {
|
5571 | if (particle.position.x < initialPosition.x && particle.velocity.x < 0 || particle.position.x > initialPosition.x && particle.velocity.x > 0) {
|
5572 | particle.velocity.x *= -Math.random();
|
5573 | }
|
5574 |
|
5575 | if (particle.position.y < initialPosition.y && particle.velocity.y < 0 || particle.position.y > initialPosition.y && particle.velocity.y > 0) {
|
5576 | particle.velocity.y *= -Math.random();
|
5577 | }
|
5578 | }
|
5579 | }
|
5580 | }
|
5581 |
|
5582 | applyPath(delta) {
|
5583 | const particle = this.particle;
|
5584 | const particlesOptions = particle.options;
|
5585 | const pathOptions = particlesOptions.move.path;
|
5586 | const pathEnabled = pathOptions.enable;
|
5587 |
|
5588 | if (!pathEnabled) {
|
5589 | return;
|
5590 | }
|
5591 |
|
5592 | const container = this.container;
|
5593 |
|
5594 | if (particle.lastPathTime <= particle.pathDelay) {
|
5595 | particle.lastPathTime += delta.value;
|
5596 | return;
|
5597 | }
|
5598 |
|
5599 | let generator = container.pathGenerator;
|
5600 |
|
5601 | if (pathOptions.generator) {
|
5602 | const customGenerator = Plugins.getPathGenerator(pathOptions.generator);
|
5603 |
|
5604 | if (customGenerator) {
|
5605 | generator = customGenerator;
|
5606 | }
|
5607 | }
|
5608 |
|
5609 | const path = generator.generate(particle);
|
5610 | particle.velocity.addTo(path);
|
5611 |
|
5612 | if (pathOptions.clamp) {
|
5613 | particle.velocity.x = NumberUtils.clamp(particle.velocity.x, -1, 1);
|
5614 | particle.velocity.y = NumberUtils.clamp(particle.velocity.y, -1, 1);
|
5615 | }
|
5616 |
|
5617 | particle.lastPathTime -= particle.pathDelay;
|
5618 | }
|
5619 |
|
5620 | moveParallax() {
|
5621 | const container = this.container;
|
5622 | const options = container.actualOptions;
|
5623 |
|
5624 | if (Utils.isSsr() || !options.interactivity.events.onHover.parallax.enable) {
|
5625 | return;
|
5626 | }
|
5627 |
|
5628 | const particle = this.particle;
|
5629 | const parallaxForce = options.interactivity.events.onHover.parallax.force;
|
5630 | const mousePos = container.interactivity.mouse.position;
|
5631 |
|
5632 | if (!mousePos) {
|
5633 | return;
|
5634 | }
|
5635 |
|
5636 | const canvasCenter = {
|
5637 | x: container.canvas.size.width / 2,
|
5638 | y: container.canvas.size.height / 2
|
5639 | };
|
5640 | const parallaxSmooth = options.interactivity.events.onHover.parallax.smooth;
|
5641 | const factor = particle.getRadius() / parallaxForce;
|
5642 | const tmp = {
|
5643 | x: (mousePos.x - canvasCenter.x) * factor,
|
5644 | y: (mousePos.y - canvasCenter.y) * factor
|
5645 | };
|
5646 | particle.offset.x += (tmp.x - particle.offset.x) / parallaxSmooth;
|
5647 | particle.offset.y += (tmp.y - particle.offset.y) / parallaxSmooth;
|
5648 | }
|
5649 |
|
5650 | getProximitySpeedFactor() {
|
5651 | const container = this.container;
|
5652 | const options = container.actualOptions;
|
5653 | const active = Utils.isInArray(HoverMode.slow, options.interactivity.events.onHover.mode);
|
5654 |
|
5655 | if (!active) {
|
5656 | return 1;
|
5657 | }
|
5658 |
|
5659 | const mousePos = this.container.interactivity.mouse.position;
|
5660 |
|
5661 | if (!mousePos) {
|
5662 | return 1;
|
5663 | }
|
5664 |
|
5665 | const particlePos = this.particle.getPosition();
|
5666 | const dist = NumberUtils.getDistance(mousePos, particlePos);
|
5667 | const radius = container.retina.slowModeRadius;
|
5668 |
|
5669 | if (dist > radius) {
|
5670 | return 1;
|
5671 | }
|
5672 |
|
5673 | const proximityFactor = dist / radius || 0;
|
5674 | const slowFactor = options.interactivity.modes.slow.factor;
|
5675 | return proximityFactor / slowFactor;
|
5676 | }
|
5677 |
|
5678 | }
|
5679 | ;
|
5680 |
|
5681 |
|
5682 |
|
5683 |
|
5684 |
|
5685 |
|
5686 |
|
5687 |
|
5688 | class Particle {
|
5689 | constructor(id, container, position, overrideOptions) {
|
5690 | var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
5691 |
|
5692 | this.id = id;
|
5693 | this.container = container;
|
5694 | this.links = [];
|
5695 | this.fill = true;
|
5696 | this.close = true;
|
5697 | this.lastPathTime = 0;
|
5698 | this.destroyed = false;
|
5699 | this.unbreakable = false;
|
5700 | this.splitCount = 0;
|
5701 | this.misplaced = false;
|
5702 | this.loops = {
|
5703 | opacity: 0,
|
5704 | size: 0
|
5705 | };
|
5706 | const pxRatio = container.retina.pixelRatio;
|
5707 | const options = container.actualOptions;
|
5708 | const particlesOptions = new ParticlesOptions();
|
5709 | particlesOptions.load(options.particles);
|
5710 | const shapeType = particlesOptions.shape.type;
|
5711 | const reduceDuplicates = particlesOptions.reduceDuplicates;
|
5712 | this.shape = shapeType instanceof Array ? Utils.itemFromArray(shapeType, this.id, reduceDuplicates) : shapeType;
|
5713 |
|
5714 | if (overrideOptions === null || overrideOptions === void 0 ? void 0 : overrideOptions.shape) {
|
5715 | if (overrideOptions.shape.type) {
|
5716 | const overrideShapeType = overrideOptions.shape.type;
|
5717 | this.shape = overrideShapeType instanceof Array ? Utils.itemFromArray(overrideShapeType, this.id, reduceDuplicates) : overrideShapeType;
|
5718 | }
|
5719 |
|
5720 | const shapeOptions = new Shape();
|
5721 | shapeOptions.load(overrideOptions.shape);
|
5722 |
|
5723 | if (this.shape) {
|
5724 | const shapeData = shapeOptions.options[this.shape];
|
5725 |
|
5726 | if (shapeData) {
|
5727 | this.shapeData = Utils.deepExtend({}, shapeData instanceof Array ? Utils.itemFromArray(shapeData, this.id, reduceDuplicates) : shapeData);
|
5728 | }
|
5729 | }
|
5730 | } else {
|
5731 | const shapeData = particlesOptions.shape.options[this.shape];
|
5732 |
|
5733 | if (shapeData) {
|
5734 | this.shapeData = Utils.deepExtend({}, shapeData instanceof Array ? Utils.itemFromArray(shapeData, this.id, reduceDuplicates) : shapeData);
|
5735 | }
|
5736 | }
|
5737 |
|
5738 | if (overrideOptions !== undefined) {
|
5739 | particlesOptions.load(overrideOptions);
|
5740 | }
|
5741 |
|
5742 | if (((_a = this.shapeData) === null || _a === void 0 ? void 0 : _a.particles) !== undefined) {
|
5743 | particlesOptions.load((_b = this.shapeData) === null || _b === void 0 ? void 0 : _b.particles);
|
5744 | }
|
5745 |
|
5746 | this.fill = (_d = (_c = this.shapeData) === null || _c === void 0 ? void 0 : _c.fill) !== null && _d !== void 0 ? _d : this.fill;
|
5747 | this.close = (_f = (_e = this.shapeData) === null || _e === void 0 ? void 0 : _e.close) !== null && _f !== void 0 ? _f : this.close;
|
5748 | this.options = particlesOptions;
|
5749 | this.pathDelay = NumberUtils.getValue(this.options.move.path.delay) * 1000;
|
5750 | container.retina.initParticle(this);
|
5751 | const color = this.options.color;
|
5752 | const sizeOptions = this.options.size;
|
5753 | const sizeValue = NumberUtils.getValue(sizeOptions) * container.retina.pixelRatio;
|
5754 | const randomSize = typeof sizeOptions.random === "boolean" ? sizeOptions.random : sizeOptions.random.enable;
|
5755 | this.size = {
|
5756 | value: sizeValue
|
5757 | };
|
5758 | this.direction = this.options.move.direction;
|
5759 | this.bubble = {
|
5760 | inRange: false
|
5761 | };
|
5762 | this.initialVelocity = this.calculateVelocity();
|
5763 | this.velocity = this.initialVelocity.copy();
|
5764 | const rotateOptions = this.options.rotate;
|
5765 | this.rotate = {
|
5766 | value: NumberUtils.getRangeValue(rotateOptions.value) * Math.PI / 180
|
5767 | };
|
5768 | let rotateDirection = rotateOptions.direction;
|
5769 |
|
5770 | if (rotateDirection === RotateDirection.random) {
|
5771 | const index = Math.floor(Math.random() * 2);
|
5772 | rotateDirection = index > 0 ? RotateDirection.counterClockwise : RotateDirection.clockwise;
|
5773 | }
|
5774 |
|
5775 | switch (rotateDirection) {
|
5776 | case RotateDirection.counterClockwise:
|
5777 | case "counterClockwise":
|
5778 | this.rotate.status = AnimationStatus.decreasing;
|
5779 | break;
|
5780 |
|
5781 | case RotateDirection.clockwise:
|
5782 | this.rotate.status = AnimationStatus.increasing;
|
5783 | break;
|
5784 | }
|
5785 |
|
5786 | const rotateAnimation = this.options.rotate.animation;
|
5787 |
|
5788 | if (rotateAnimation.enable) {
|
5789 | this.rotate.velocity = rotateAnimation.speed / 360 * container.retina.reduceFactor;
|
5790 |
|
5791 | if (!rotateAnimation.sync) {
|
5792 | this.rotate.velocity *= Math.random();
|
5793 | }
|
5794 | }
|
5795 |
|
5796 | const sizeAnimation = this.options.size.animation;
|
5797 |
|
5798 | if (sizeAnimation.enable) {
|
5799 | this.size.status = AnimationStatus.increasing;
|
5800 |
|
5801 | if (!randomSize) {
|
5802 | switch (sizeAnimation.startValue) {
|
5803 | case StartValueType.min:
|
5804 | this.size.value = sizeAnimation.minimumValue * pxRatio;
|
5805 | break;
|
5806 |
|
5807 | case StartValueType.random:
|
5808 | this.size.value = NumberUtils.randomInRange(NumberUtils.setRangeValue(sizeAnimation.minimumValue * pxRatio, this.size.value));
|
5809 | break;
|
5810 |
|
5811 | case StartValueType.max:
|
5812 | default:
|
5813 | this.size.status = AnimationStatus.decreasing;
|
5814 | break;
|
5815 | }
|
5816 | }
|
5817 |
|
5818 | this.size.velocity = ((_g = this.sizeAnimationSpeed) !== null && _g !== void 0 ? _g : container.retina.sizeAnimationSpeed) / 100 * container.retina.reduceFactor;
|
5819 |
|
5820 | if (!sizeAnimation.sync) {
|
5821 | this.size.velocity *= Math.random();
|
5822 | }
|
5823 | }
|
5824 |
|
5825 | const hslColor = ColorUtils.colorToHsl(color, this.id, reduceDuplicates);
|
5826 |
|
5827 | if (hslColor) {
|
5828 | this.color = {
|
5829 | h: {
|
5830 | value: hslColor.h
|
5831 | },
|
5832 | s: {
|
5833 | value: hslColor.s
|
5834 | },
|
5835 | l: {
|
5836 | value: hslColor.l
|
5837 | }
|
5838 | };
|
5839 | const colorAnimation = this.options.color.animation;
|
5840 | this.setColorAnimation(colorAnimation.h, this.color.h);
|
5841 | this.setColorAnimation(colorAnimation.s, this.color.s);
|
5842 | this.setColorAnimation(colorAnimation.l, this.color.l);
|
5843 | }
|
5844 |
|
5845 | this.position = this.calcPosition(this.container, position);
|
5846 | this.initialPosition = this.position.copy();
|
5847 | this.offset = Vector.create(0, 0);
|
5848 | const opacityOptions = this.options.opacity;
|
5849 | const randomOpacity = typeof opacityOptions.random === "boolean" ? opacityOptions.random : opacityOptions.random.enable;
|
5850 | this.opacity = {
|
5851 | value: NumberUtils.getValue(opacityOptions)
|
5852 | };
|
5853 | const opacityAnimation = opacityOptions.animation;
|
5854 |
|
5855 | if (opacityAnimation.enable) {
|
5856 | this.opacity.status = AnimationStatus.increasing;
|
5857 |
|
5858 | if (!randomOpacity) {
|
5859 | switch (opacityAnimation.startValue) {
|
5860 | case StartValueType.min:
|
5861 | this.opacity.value = opacityAnimation.minimumValue;
|
5862 | break;
|
5863 |
|
5864 | case StartValueType.random:
|
5865 | this.opacity.value = NumberUtils.randomInRange(NumberUtils.setRangeValue(opacityAnimation.minimumValue, this.opacity.value));
|
5866 | break;
|
5867 |
|
5868 | case StartValueType.max:
|
5869 | default:
|
5870 | this.opacity.status = AnimationStatus.decreasing;
|
5871 | break;
|
5872 | }
|
5873 | }
|
5874 |
|
5875 | this.opacity.velocity = opacityAnimation.speed / 100 * container.retina.reduceFactor;
|
5876 |
|
5877 | if (!opacityAnimation.sync) {
|
5878 | this.opacity.velocity *= Math.random();
|
5879 | }
|
5880 | }
|
5881 |
|
5882 | this.sides = 24;
|
5883 | let drawer = container.drawers.get(this.shape);
|
5884 |
|
5885 | if (!drawer) {
|
5886 | drawer = Plugins.getShapeDrawer(this.shape);
|
5887 |
|
5888 | if (drawer) {
|
5889 | container.drawers.set(this.shape, drawer);
|
5890 | }
|
5891 | }
|
5892 |
|
5893 | const sideCountFunc = drawer === null || drawer === void 0 ? void 0 : drawer.getSidesCount;
|
5894 |
|
5895 | if (sideCountFunc) {
|
5896 | this.sides = sideCountFunc(this);
|
5897 | }
|
5898 |
|
5899 | const imageShape = this.loadImageShape(container, drawer);
|
5900 |
|
5901 | if (imageShape) {
|
5902 | this.image = imageShape.image;
|
5903 | this.fill = imageShape.fill;
|
5904 | this.close = imageShape.close;
|
5905 | }
|
5906 |
|
5907 | this.stroke = this.options.stroke instanceof Array ? Utils.itemFromArray(this.options.stroke, this.id, reduceDuplicates) : this.options.stroke;
|
5908 | this.strokeWidth = this.stroke.width * container.retina.pixelRatio;
|
5909 | const strokeHslColor = (_h = ColorUtils.colorToHsl(this.stroke.color)) !== null && _h !== void 0 ? _h : this.getFillColor();
|
5910 |
|
5911 | if (strokeHslColor) {
|
5912 | this.strokeColor = {
|
5913 | h: {
|
5914 | value: strokeHslColor.h
|
5915 | },
|
5916 | s: {
|
5917 | value: strokeHslColor.s
|
5918 | },
|
5919 | l: {
|
5920 | value: strokeHslColor.l
|
5921 | }
|
5922 | };
|
5923 | const strokeColorAnimation = (_j = this.stroke.color) === null || _j === void 0 ? void 0 : _j.animation;
|
5924 |
|
5925 | if (strokeColorAnimation && this.strokeColor) {
|
5926 | this.setColorAnimation(strokeColorAnimation.h, this.strokeColor.h);
|
5927 | this.setColorAnimation(strokeColorAnimation.s, this.strokeColor.s);
|
5928 | this.setColorAnimation(strokeColorAnimation.l, this.strokeColor.l);
|
5929 | }
|
5930 | }
|
5931 |
|
5932 | const lifeOptions = particlesOptions.life;
|
5933 | this.lifeDelay = container.retina.reduceFactor ? NumberUtils.getValue(lifeOptions.delay) * (lifeOptions.delay.sync ? 1 : Math.random()) / container.retina.reduceFactor * 1000 : 0;
|
5934 | this.lifeDelayTime = 0;
|
5935 | this.lifeDuration = container.retina.reduceFactor ? NumberUtils.getValue(lifeOptions.duration) * (lifeOptions.duration.sync ? 1 : Math.random()) / container.retina.reduceFactor * 1000 : 0;
|
5936 | this.lifeTime = 0;
|
5937 | this.livesRemaining = particlesOptions.life.count;
|
5938 | this.spawning = this.lifeDelay > 0;
|
5939 |
|
5940 | if (this.lifeDuration <= 0) {
|
5941 | this.lifeDuration = -1;
|
5942 | }
|
5943 |
|
5944 | if (this.livesRemaining <= 0) {
|
5945 | this.livesRemaining = -1;
|
5946 | }
|
5947 |
|
5948 | this.shadowColor = ColorUtils.colorToRgb(this.options.shadow.color);
|
5949 | this.updater = new Updater(container, this);
|
5950 | this.infecter = new Infecter(container);
|
5951 | this.mover = new Mover(container, this);
|
5952 |
|
5953 | if (drawer && drawer.particleInit) {
|
5954 | drawer.particleInit(container, this);
|
5955 | }
|
5956 | }
|
5957 |
|
5958 | move(delta) {
|
5959 | this.mover.move(delta);
|
5960 | }
|
5961 |
|
5962 | update(delta) {
|
5963 | this.updater.update(delta);
|
5964 | }
|
5965 |
|
5966 | draw(delta) {
|
5967 | this.container.canvas.drawParticle(this, delta);
|
5968 | }
|
5969 |
|
5970 | getPosition() {
|
5971 | return this.position.add(this.offset);
|
5972 | }
|
5973 |
|
5974 | getRadius() {
|
5975 | return this.bubble.radius || this.size.value;
|
5976 | }
|
5977 |
|
5978 | getMass() {
|
5979 | const radius = this.getRadius();
|
5980 | return Math.pow(radius, 2) * Math.PI / 2;
|
5981 | }
|
5982 |
|
5983 | getFillColor() {
|
5984 | var _a;
|
5985 |
|
5986 | return (_a = this.bubble.color) !== null && _a !== void 0 ? _a : ColorUtils.getHslFromAnimation(this.color);
|
5987 | }
|
5988 |
|
5989 | getStrokeColor() {
|
5990 | var _a, _b;
|
5991 |
|
5992 | return (_b = (_a = this.bubble.color) !== null && _a !== void 0 ? _a : ColorUtils.getHslFromAnimation(this.strokeColor)) !== null && _b !== void 0 ? _b : this.getFillColor();
|
5993 | }
|
5994 |
|
5995 | destroy(override) {
|
5996 | this.destroyed = true;
|
5997 | this.bubble.inRange = false;
|
5998 | this.links = [];
|
5999 |
|
6000 | if (this.unbreakable) {
|
6001 | return;
|
6002 | }
|
6003 |
|
6004 | this.destroyed = true;
|
6005 | this.bubble.inRange = false;
|
6006 |
|
6007 | for (const [, plugin] of this.container.plugins) {
|
6008 | if (plugin.particleDestroyed) {
|
6009 | plugin.particleDestroyed(this, override);
|
6010 | }
|
6011 | }
|
6012 |
|
6013 | if (override) {
|
6014 | return;
|
6015 | }
|
6016 |
|
6017 | const destroyOptions = this.options.destroy;
|
6018 |
|
6019 | if (destroyOptions.mode === DestroyMode.split) {
|
6020 | this.split();
|
6021 | }
|
6022 | }
|
6023 |
|
6024 | reset() {
|
6025 | this.loops.opacity = 0;
|
6026 | this.loops.size = 0;
|
6027 | }
|
6028 |
|
6029 | split() {
|
6030 | const splitOptions = this.options.destroy.split;
|
6031 |
|
6032 | if (splitOptions.count >= 0 && this.splitCount++ > splitOptions.count) {
|
6033 | return;
|
6034 | }
|
6035 |
|
6036 | const rate = NumberUtils.getRangeValue(splitOptions.rate.value);
|
6037 |
|
6038 | for (let i = 0; i < rate; i++) {
|
6039 | this.container.particles.addSplitParticle(this);
|
6040 | }
|
6041 | }
|
6042 |
|
6043 | setColorAnimation(colorAnimation, colorValue) {
|
6044 | if (colorAnimation.enable) {
|
6045 | colorValue.velocity = colorAnimation.speed / 100 * this.container.retina.reduceFactor;
|
6046 |
|
6047 | if (colorAnimation.sync) {
|
6048 | return;
|
6049 | }
|
6050 |
|
6051 | colorValue.status = AnimationStatus.increasing;
|
6052 | colorValue.velocity *= Math.random();
|
6053 |
|
6054 | if (colorValue.value) {
|
6055 | colorValue.value *= Math.random();
|
6056 | }
|
6057 | } else {
|
6058 | colorValue.velocity = 0;
|
6059 | }
|
6060 | }
|
6061 |
|
6062 | calcPosition(container, position, tryCount = 0) {
|
6063 | var _a, _b;
|
6064 |
|
6065 | for (const [, plugin] of container.plugins) {
|
6066 | const pluginPos = plugin.particlePosition !== undefined ? plugin.particlePosition(position, this) : undefined;
|
6067 |
|
6068 | if (pluginPos !== undefined) {
|
6069 | return Vector.create(pluginPos.x, pluginPos.y);
|
6070 | }
|
6071 | }
|
6072 |
|
6073 | const pos = Vector.create((_a = position === null || position === void 0 ? void 0 : position.x) !== null && _a !== void 0 ? _a : Math.random() * container.canvas.size.width, (_b = position === null || position === void 0 ? void 0 : position.y) !== null && _b !== void 0 ? _b : Math.random() * container.canvas.size.height);
|
6074 | const outMode = this.options.move.outMode;
|
6075 |
|
6076 | if (Utils.isInArray(outMode, OutMode.bounce) || Utils.isInArray(outMode, OutMode.bounceHorizontal)) {
|
6077 | if (pos.x > container.canvas.size.width - this.size.value * 2) {
|
6078 | pos.x -= this.size.value;
|
6079 | } else if (pos.x < this.size.value * 2) {
|
6080 | pos.x += this.size.value;
|
6081 | }
|
6082 | }
|
6083 |
|
6084 | if (Utils.isInArray(outMode, OutMode.bounce) || Utils.isInArray(outMode, OutMode.bounceVertical)) {
|
6085 | if (pos.y > container.canvas.size.height - this.size.value * 2) {
|
6086 | pos.y -= this.size.value;
|
6087 | } else if (pos.y < this.size.value * 2) {
|
6088 | pos.y += this.size.value;
|
6089 | }
|
6090 | }
|
6091 |
|
6092 | if (this.checkOverlap(pos, tryCount)) {
|
6093 | return this.calcPosition(container, undefined, tryCount + 1);
|
6094 | }
|
6095 |
|
6096 | return pos;
|
6097 | }
|
6098 |
|
6099 | checkOverlap(pos, tryCount = 0) {
|
6100 | const overlapOptions = this.options.collisions.overlap;
|
6101 |
|
6102 | if (!overlapOptions.enable) {
|
6103 | const retries = overlapOptions.retries;
|
6104 |
|
6105 | if (retries >= 0 && tryCount > retries) {
|
6106 | throw new Error("Particle is overlapping and can't be placed");
|
6107 | }
|
6108 |
|
6109 | let overlaps = false;
|
6110 |
|
6111 | for (const particle of this.container.particles.array) {
|
6112 | if (NumberUtils.getDistance(pos, particle.position) < this.size.value + particle.size.value) {
|
6113 | overlaps = true;
|
6114 | break;
|
6115 | }
|
6116 | }
|
6117 |
|
6118 | return overlaps;
|
6119 | }
|
6120 |
|
6121 | return false;
|
6122 | }
|
6123 |
|
6124 | calculateVelocity() {
|
6125 | const baseVelocity = NumberUtils.getParticleBaseVelocity(this.direction);
|
6126 | const res = baseVelocity.copy();
|
6127 | const moveOptions = this.options.move;
|
6128 | let rad;
|
6129 | let radOffset = Math.PI / 4;
|
6130 |
|
6131 | if (typeof moveOptions.angle === "number") {
|
6132 | rad = Math.PI / 180 * moveOptions.angle;
|
6133 | } else {
|
6134 | rad = Math.PI / 180 * moveOptions.angle.value;
|
6135 | radOffset = Math.PI / 180 * moveOptions.angle.offset;
|
6136 | }
|
6137 |
|
6138 | const range = {
|
6139 | left: Math.sin(radOffset + rad / 2) - Math.sin(radOffset - rad / 2),
|
6140 | right: Math.cos(radOffset + rad / 2) - Math.cos(radOffset - rad / 2)
|
6141 | };
|
6142 |
|
6143 | if (!moveOptions.straight || moveOptions.random) {
|
6144 | res.x += NumberUtils.randomInRange(NumberUtils.setRangeValue(range.left, range.right)) / 2;
|
6145 | res.y += NumberUtils.randomInRange(NumberUtils.setRangeValue(range.left, range.right)) / 2;
|
6146 | }
|
6147 |
|
6148 | return res;
|
6149 | }
|
6150 |
|
6151 | loadImageShape(container, drawer) {
|
6152 | var _a, _b, _c, _d, _e;
|
6153 |
|
6154 | if (!(this.shape === ShapeType.image || this.shape === ShapeType.images)) {
|
6155 | return;
|
6156 | }
|
6157 |
|
6158 | const imageDrawer = drawer;
|
6159 | const images = imageDrawer.getImages(container).images;
|
6160 | const imageData = this.shapeData;
|
6161 | const image = (_a = images.find(t => t.source === imageData.src)) !== null && _a !== void 0 ? _a : images[0];
|
6162 | const color = this.getFillColor();
|
6163 | let imageRes;
|
6164 |
|
6165 | if (!image) {
|
6166 | return;
|
6167 | }
|
6168 |
|
6169 | if (image.svgData !== undefined && imageData.replaceColor && color) {
|
6170 | const svgColoredData = ColorUtils.replaceColorSvg(image, color, this.opacity.value);
|
6171 | const svg = new Blob([svgColoredData], {
|
6172 | type: "image/svg+xml"
|
6173 | });
|
6174 | const domUrl = URL || window.URL || window.webkitURL || window;
|
6175 | const url = domUrl.createObjectURL(svg);
|
6176 | const img = new Image();
|
6177 | imageRes = {
|
6178 | data: image,
|
6179 | loaded: false,
|
6180 | ratio: imageData.width / imageData.height,
|
6181 | replaceColor: (_b = imageData.replaceColor) !== null && _b !== void 0 ? _b : imageData.replace_color,
|
6182 | source: imageData.src
|
6183 | };
|
6184 | img.addEventListener("load", () => {
|
6185 | if (this.image) {
|
6186 | this.image.loaded = true;
|
6187 | image.element = img;
|
6188 | }
|
6189 |
|
6190 | domUrl.revokeObjectURL(url);
|
6191 | });
|
6192 | img.addEventListener("error", () => {
|
6193 | domUrl.revokeObjectURL(url);
|
6194 | Utils.loadImage(imageData.src).then(img2 => {
|
6195 | if (this.image && img2) {
|
6196 | image.element = img2.element;
|
6197 | this.image.loaded = true;
|
6198 | }
|
6199 | });
|
6200 | });
|
6201 | img.src = url;
|
6202 | } else {
|
6203 | imageRes = {
|
6204 | data: image,
|
6205 | loaded: true,
|
6206 | ratio: imageData.width / imageData.height,
|
6207 | replaceColor: (_c = imageData.replaceColor) !== null && _c !== void 0 ? _c : imageData.replace_color,
|
6208 | source: imageData.src
|
6209 | };
|
6210 | }
|
6211 |
|
6212 | if (!imageRes.ratio) {
|
6213 | imageRes.ratio = 1;
|
6214 | }
|
6215 |
|
6216 | const fill = (_d = imageData.fill) !== null && _d !== void 0 ? _d : this.fill;
|
6217 | const close = (_e = imageData.close) !== null && _e !== void 0 ? _e : this.close;
|
6218 | return {
|
6219 | image: imageRes,
|
6220 | fill,
|
6221 | close
|
6222 | };
|
6223 | }
|
6224 |
|
6225 | }
|
6226 | ;
|
6227 |
|
6228 |
|
6229 | class Grabber {
|
6230 | constructor(container) {
|
6231 | this.container = container;
|
6232 | }
|
6233 |
|
6234 | isEnabled() {
|
6235 | const container = this.container;
|
6236 | const mouse = container.interactivity.mouse;
|
6237 | const events = container.actualOptions.interactivity.events;
|
6238 |
|
6239 | if (!(events.onHover.enable && mouse.position)) {
|
6240 | return false;
|
6241 | }
|
6242 |
|
6243 | const hoverMode = events.onHover.mode;
|
6244 | return Utils.isInArray(HoverMode.grab, hoverMode);
|
6245 | }
|
6246 |
|
6247 | reset() {}
|
6248 |
|
6249 | interact() {
|
6250 | var _a;
|
6251 |
|
6252 | const container = this.container;
|
6253 | const options = container.actualOptions;
|
6254 | const interactivity = options.interactivity;
|
6255 |
|
6256 | if (interactivity.events.onHover.enable && container.interactivity.status === Constants.mouseMoveEvent) {
|
6257 | const mousePos = container.interactivity.mouse.position;
|
6258 |
|
6259 | if (mousePos === undefined) {
|
6260 | return;
|
6261 | }
|
6262 |
|
6263 | const distance = container.retina.grabModeDistance;
|
6264 | const query = container.particles.quadTree.queryCircle(mousePos, distance);
|
6265 |
|
6266 | for (const particle of query) {
|
6267 | const pos = particle.getPosition();
|
6268 | const pointDistance = NumberUtils.getDistance(pos, mousePos);
|
6269 |
|
6270 | if (pointDistance <= distance) {
|
6271 | const grabLineOptions = interactivity.modes.grab.links;
|
6272 | const lineOpacity = grabLineOptions.opacity;
|
6273 | const opacityLine = lineOpacity - pointDistance * lineOpacity / distance;
|
6274 |
|
6275 | if (opacityLine > 0) {
|
6276 | const optColor = (_a = grabLineOptions.color) !== null && _a !== void 0 ? _a : particle.options.links.color;
|
6277 |
|
6278 | if (!container.particles.grabLineColor) {
|
6279 | const linksOptions = container.actualOptions.interactivity.modes.grab.links;
|
6280 | container.particles.grabLineColor = ColorUtils.getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
|
6281 | }
|
6282 |
|
6283 | const colorLine = ColorUtils.getLinkColor(particle, undefined, container.particles.grabLineColor);
|
6284 |
|
6285 | if (colorLine === undefined) {
|
6286 | return;
|
6287 | }
|
6288 |
|
6289 | container.canvas.drawGrabLine(particle, colorLine, opacityLine, mousePos);
|
6290 | }
|
6291 | }
|
6292 | }
|
6293 | }
|
6294 | }
|
6295 |
|
6296 | }
|
6297 | ;
|
6298 |
|
6299 |
|
6300 |
|
6301 | class Repulser {
|
6302 | constructor(container) {
|
6303 | this.container = container;
|
6304 | }
|
6305 |
|
6306 | isEnabled() {
|
6307 | const container = this.container;
|
6308 | const options = container.actualOptions;
|
6309 | const mouse = container.interactivity.mouse;
|
6310 | const events = options.interactivity.events;
|
6311 | const divs = events.onDiv;
|
6312 | const divRepulse = Utils.isDivModeEnabled(DivMode.repulse, divs);
|
6313 |
|
6314 | if (!(divRepulse || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
|
6315 | return false;
|
6316 | }
|
6317 |
|
6318 | const hoverMode = events.onHover.mode;
|
6319 | const clickMode = events.onClick.mode;
|
6320 | return Utils.isInArray(HoverMode.repulse, hoverMode) || Utils.isInArray(ClickMode.repulse, clickMode) || divRepulse;
|
6321 | }
|
6322 |
|
6323 | reset() {}
|
6324 |
|
6325 | interact() {
|
6326 | const container = this.container;
|
6327 | const options = container.actualOptions;
|
6328 | const mouseMoveStatus = container.interactivity.status === Constants.mouseMoveEvent;
|
6329 | const events = options.interactivity.events;
|
6330 | const hoverEnabled = events.onHover.enable;
|
6331 | const hoverMode = events.onHover.mode;
|
6332 | const clickEnabled = events.onClick.enable;
|
6333 | const clickMode = events.onClick.mode;
|
6334 | const divs = events.onDiv;
|
6335 |
|
6336 | if (mouseMoveStatus && hoverEnabled && Utils.isInArray(HoverMode.repulse, hoverMode)) {
|
6337 | this.hoverRepulse();
|
6338 | } else if (clickEnabled && Utils.isInArray(ClickMode.repulse, clickMode)) {
|
6339 | this.clickRepulse();
|
6340 | } else {
|
6341 | Utils.divModeExecute(DivMode.repulse, divs, (selector, div) => this.singleSelectorRepulse(selector, div));
|
6342 | }
|
6343 | }
|
6344 |
|
6345 | singleSelectorRepulse(selector, div) {
|
6346 | const container = this.container;
|
6347 | const query = document.querySelectorAll(selector);
|
6348 |
|
6349 | if (!query.length) {
|
6350 | return;
|
6351 | }
|
6352 |
|
6353 | query.forEach(item => {
|
6354 | const elem = item;
|
6355 | const pxRatio = container.retina.pixelRatio;
|
6356 | const pos = {
|
6357 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
6358 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
6359 | };
|
6360 | const repulseRadius = elem.offsetWidth / 2 * pxRatio;
|
6361 | const area = div.type === DivType.circle ? new Circle(pos.x, pos.y, repulseRadius) : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio);
|
6362 | const divs = container.actualOptions.interactivity.modes.repulse.divs;
|
6363 | const divRepulse = Utils.divMode(divs, elem);
|
6364 | this.processRepulse(pos, repulseRadius, area, divRepulse);
|
6365 | });
|
6366 | }
|
6367 |
|
6368 | hoverRepulse() {
|
6369 | const container = this.container;
|
6370 | const mousePos = container.interactivity.mouse.position;
|
6371 |
|
6372 | if (!mousePos) {
|
6373 | return;
|
6374 | }
|
6375 |
|
6376 | const repulseRadius = container.retina.repulseModeDistance;
|
6377 | this.processRepulse(mousePos, repulseRadius, new Circle(mousePos.x, mousePos.y, repulseRadius));
|
6378 | }
|
6379 |
|
6380 | processRepulse(position, repulseRadius, area, divRepulse) {
|
6381 | var _a;
|
6382 |
|
6383 | const container = this.container;
|
6384 | const query = container.particles.quadTree.query(area);
|
6385 |
|
6386 | for (const particle of query) {
|
6387 | const {
|
6388 | dx,
|
6389 | dy,
|
6390 | distance
|
6391 | } = NumberUtils.getDistances(particle.position, position);
|
6392 | const normVec = {
|
6393 | x: dx / distance,
|
6394 | y: dy / distance
|
6395 | };
|
6396 | const velocity = ((_a = divRepulse === null || divRepulse === void 0 ? void 0 : divRepulse.speed) !== null && _a !== void 0 ? _a : container.actualOptions.interactivity.modes.repulse.speed) * 100;
|
6397 | const repulseFactor = NumberUtils.clamp((1 - Math.pow(distance / repulseRadius, 2)) * velocity, 0, 50);
|
6398 | particle.position.x += normVec.x * repulseFactor;
|
6399 | particle.position.y += normVec.y * repulseFactor;
|
6400 | }
|
6401 | }
|
6402 |
|
6403 | clickRepulse() {
|
6404 | const container = this.container;
|
6405 |
|
6406 | if (!container.repulse.finish) {
|
6407 | if (!container.repulse.count) {
|
6408 | container.repulse.count = 0;
|
6409 | }
|
6410 |
|
6411 | container.repulse.count++;
|
6412 |
|
6413 | if (container.repulse.count === container.particles.count) {
|
6414 | container.repulse.finish = true;
|
6415 | }
|
6416 | }
|
6417 |
|
6418 | if (container.repulse.clicking) {
|
6419 | const repulseDistance = container.retina.repulseModeDistance;
|
6420 | const repulseRadius = Math.pow(repulseDistance / 6, 3);
|
6421 | const mouseClickPos = container.interactivity.mouse.clickPosition;
|
6422 |
|
6423 | if (mouseClickPos === undefined) {
|
6424 | return;
|
6425 | }
|
6426 |
|
6427 | const range = new Circle(mouseClickPos.x, mouseClickPos.y, repulseRadius);
|
6428 | const query = container.particles.quadTree.query(range);
|
6429 |
|
6430 | for (const particle of query) {
|
6431 | const {
|
6432 | dx,
|
6433 | dy,
|
6434 | distance
|
6435 | } = NumberUtils.getDistances(mouseClickPos, particle.position);
|
6436 | const d = distance * distance;
|
6437 |
|
6438 | if (d <= repulseRadius) {
|
6439 | container.repulse.particles.push(particle);
|
6440 | const velocity = container.actualOptions.interactivity.modes.repulse.speed;
|
6441 | const v = Vector.create(dx, dy);
|
6442 | v.length = -repulseRadius * velocity / d;
|
6443 | particle.velocity.setTo(v);
|
6444 | }
|
6445 | }
|
6446 | } else if (container.repulse.clicking === false) {
|
6447 | for (const particle of container.repulse.particles) {
|
6448 | particle.velocity.setTo(particle.initialVelocity);
|
6449 | }
|
6450 |
|
6451 | container.repulse.particles = [];
|
6452 | }
|
6453 | }
|
6454 |
|
6455 | }
|
6456 | ;
|
6457 |
|
6458 |
|
6459 |
|
6460 | function calculateBubbleValue(particleValue, modeValue, optionsValue, ratio) {
|
6461 | if (modeValue > optionsValue) {
|
6462 | const size = particleValue + (modeValue - optionsValue) * ratio;
|
6463 | return NumberUtils.clamp(size, particleValue, modeValue);
|
6464 | } else if (modeValue < optionsValue) {
|
6465 | const size = particleValue - (optionsValue - modeValue) * ratio;
|
6466 | return NumberUtils.clamp(size, modeValue, particleValue);
|
6467 | }
|
6468 | }
|
6469 |
|
6470 | class Bubbler {
|
6471 | constructor(container) {
|
6472 | this.container = container;
|
6473 | }
|
6474 |
|
6475 | isEnabled() {
|
6476 | const container = this.container;
|
6477 | const options = container.actualOptions;
|
6478 | const mouse = container.interactivity.mouse;
|
6479 | const events = options.interactivity.events;
|
6480 | const divs = events.onDiv;
|
6481 | const divBubble = Utils.isDivModeEnabled(DivMode.bubble, divs);
|
6482 |
|
6483 | if (!(divBubble || events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
|
6484 | return false;
|
6485 | }
|
6486 |
|
6487 | const hoverMode = events.onHover.mode;
|
6488 | const clickMode = events.onClick.mode;
|
6489 | return Utils.isInArray(HoverMode.bubble, hoverMode) || Utils.isInArray(ClickMode.bubble, clickMode) || divBubble;
|
6490 | }
|
6491 |
|
6492 | reset(particle, force) {
|
6493 | if (!particle.bubble.inRange || force) {
|
6494 | delete particle.bubble.div;
|
6495 | delete particle.bubble.opacity;
|
6496 | delete particle.bubble.radius;
|
6497 | delete particle.bubble.color;
|
6498 | }
|
6499 | }
|
6500 |
|
6501 | interact() {
|
6502 | const options = this.container.actualOptions;
|
6503 | const events = options.interactivity.events;
|
6504 | const onHover = events.onHover;
|
6505 | const onClick = events.onClick;
|
6506 | const hoverEnabled = onHover.enable;
|
6507 | const hoverMode = onHover.mode;
|
6508 | const clickEnabled = onClick.enable;
|
6509 | const clickMode = onClick.mode;
|
6510 | const divs = events.onDiv;
|
6511 |
|
6512 | if (hoverEnabled && Utils.isInArray(HoverMode.bubble, hoverMode)) {
|
6513 | this.hoverBubble();
|
6514 | } else if (clickEnabled && Utils.isInArray(ClickMode.bubble, clickMode)) {
|
6515 | this.clickBubble();
|
6516 | } else {
|
6517 | Utils.divModeExecute(DivMode.bubble, divs, (selector, div) => this.singleSelectorHover(selector, div));
|
6518 | }
|
6519 | }
|
6520 |
|
6521 | singleSelectorHover(selector, div) {
|
6522 | const container = this.container;
|
6523 | const selectors = document.querySelectorAll(selector);
|
6524 |
|
6525 | if (!selectors.length) {
|
6526 | return;
|
6527 | }
|
6528 |
|
6529 | selectors.forEach(item => {
|
6530 | const elem = item;
|
6531 | const pxRatio = container.retina.pixelRatio;
|
6532 | const pos = {
|
6533 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
6534 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
6535 | };
|
6536 | const repulseRadius = elem.offsetWidth / 2 * pxRatio;
|
6537 | const area = div.type === DivType.circle ? new Circle(pos.x, pos.y, repulseRadius) : new Rectangle(elem.offsetLeft * pxRatio, elem.offsetTop * pxRatio, elem.offsetWidth * pxRatio, elem.offsetHeight * pxRatio);
|
6538 | const query = container.particles.quadTree.query(area);
|
6539 |
|
6540 | for (const particle of query) {
|
6541 | if (!area.contains(particle.getPosition())) {
|
6542 | continue;
|
6543 | }
|
6544 |
|
6545 | particle.bubble.inRange = true;
|
6546 | const divs = container.actualOptions.interactivity.modes.bubble.divs;
|
6547 | const divBubble = Utils.divMode(divs, elem);
|
6548 |
|
6549 | if (!particle.bubble.div || particle.bubble.div !== elem) {
|
6550 | this.reset(particle, true);
|
6551 | particle.bubble.div = elem;
|
6552 | }
|
6553 |
|
6554 | this.hoverBubbleSize(particle, 1, divBubble);
|
6555 | this.hoverBubbleOpacity(particle, 1, divBubble);
|
6556 | this.hoverBubbleColor(particle, divBubble);
|
6557 | }
|
6558 | });
|
6559 | }
|
6560 |
|
6561 | process(particle, distMouse, timeSpent, data) {
|
6562 | const container = this.container;
|
6563 | const bubbleParam = data.bubbleObj.optValue;
|
6564 |
|
6565 | if (bubbleParam === undefined) {
|
6566 | return;
|
6567 | }
|
6568 |
|
6569 | const options = container.actualOptions;
|
6570 | const bubbleDuration = options.interactivity.modes.bubble.duration;
|
6571 | const bubbleDistance = container.retina.bubbleModeDistance;
|
6572 | const particlesParam = data.particlesObj.optValue;
|
6573 | const pObjBubble = data.bubbleObj.value;
|
6574 | const pObj = data.particlesObj.value || 0;
|
6575 | const type = data.type;
|
6576 |
|
6577 | if (bubbleParam !== particlesParam) {
|
6578 | if (!container.bubble.durationEnd) {
|
6579 | if (distMouse <= bubbleDistance) {
|
6580 | const obj = pObjBubble !== null && pObjBubble !== void 0 ? pObjBubble : pObj;
|
6581 |
|
6582 | if (obj !== bubbleParam) {
|
6583 | const value = pObj - timeSpent * (pObj - bubbleParam) / bubbleDuration;
|
6584 |
|
6585 | if (type === ProcessBubbleType.size) {
|
6586 | particle.bubble.radius = value;
|
6587 | }
|
6588 |
|
6589 | if (type === ProcessBubbleType.opacity) {
|
6590 | particle.bubble.opacity = value;
|
6591 | }
|
6592 | }
|
6593 | } else {
|
6594 | if (type === ProcessBubbleType.size) {
|
6595 | delete particle.bubble.radius;
|
6596 | }
|
6597 |
|
6598 | if (type === ProcessBubbleType.opacity) {
|
6599 | delete particle.bubble.opacity;
|
6600 | }
|
6601 | }
|
6602 | } else if (pObjBubble) {
|
6603 | if (type === ProcessBubbleType.size) {
|
6604 | delete particle.bubble.radius;
|
6605 | }
|
6606 |
|
6607 | if (type === ProcessBubbleType.opacity) {
|
6608 | delete particle.bubble.opacity;
|
6609 | }
|
6610 | }
|
6611 | }
|
6612 | }
|
6613 |
|
6614 | clickBubble() {
|
6615 | const container = this.container;
|
6616 | const options = container.actualOptions;
|
6617 | const mouseClickPos = container.interactivity.mouse.clickPosition;
|
6618 |
|
6619 | if (mouseClickPos === undefined) {
|
6620 | return;
|
6621 | }
|
6622 |
|
6623 | const distance = container.retina.bubbleModeDistance;
|
6624 | const query = container.particles.quadTree.queryCircle(mouseClickPos, distance);
|
6625 |
|
6626 | for (const particle of query) {
|
6627 | if (!container.bubble.clicking) {
|
6628 | continue;
|
6629 | }
|
6630 |
|
6631 | particle.bubble.inRange = !container.bubble.durationEnd;
|
6632 | const pos = particle.getPosition();
|
6633 | const distMouse = NumberUtils.getDistance(pos, mouseClickPos);
|
6634 | const timeSpent = (new Date().getTime() - (container.interactivity.mouse.clickTime || 0)) / 1000;
|
6635 |
|
6636 | if (timeSpent > options.interactivity.modes.bubble.duration) {
|
6637 | container.bubble.durationEnd = true;
|
6638 | }
|
6639 |
|
6640 | if (timeSpent > options.interactivity.modes.bubble.duration * 2) {
|
6641 | container.bubble.clicking = false;
|
6642 | container.bubble.durationEnd = false;
|
6643 | }
|
6644 |
|
6645 | const sizeData = {
|
6646 | bubbleObj: {
|
6647 | optValue: container.retina.bubbleModeSize,
|
6648 | value: particle.bubble.radius
|
6649 | },
|
6650 | particlesObj: {
|
6651 | optValue: NumberUtils.getRangeMax(particle.options.size.value) * container.retina.pixelRatio,
|
6652 | value: particle.size.value
|
6653 | },
|
6654 | type: ProcessBubbleType.size
|
6655 | };
|
6656 | this.process(particle, distMouse, timeSpent, sizeData);
|
6657 | const opacityData = {
|
6658 | bubbleObj: {
|
6659 | optValue: options.interactivity.modes.bubble.opacity,
|
6660 | value: particle.bubble.opacity
|
6661 | },
|
6662 | particlesObj: {
|
6663 | optValue: NumberUtils.getRangeMax(particle.options.opacity.value),
|
6664 | value: particle.opacity.value
|
6665 | },
|
6666 | type: ProcessBubbleType.opacity
|
6667 | };
|
6668 | this.process(particle, distMouse, timeSpent, opacityData);
|
6669 |
|
6670 | if (!container.bubble.durationEnd) {
|
6671 | if (distMouse <= container.retina.bubbleModeDistance) {
|
6672 | this.hoverBubbleColor(particle);
|
6673 | } else {
|
6674 | delete particle.bubble.color;
|
6675 | }
|
6676 | } else {
|
6677 | delete particle.bubble.color;
|
6678 | }
|
6679 | }
|
6680 | }
|
6681 |
|
6682 | hoverBubble() {
|
6683 | const container = this.container;
|
6684 | const mousePos = container.interactivity.mouse.position;
|
6685 |
|
6686 | if (mousePos === undefined) {
|
6687 | return;
|
6688 | }
|
6689 |
|
6690 | const distance = container.retina.bubbleModeDistance;
|
6691 | const query = container.particles.quadTree.queryCircle(mousePos, distance);
|
6692 |
|
6693 | for (const particle of query) {
|
6694 | particle.bubble.inRange = true;
|
6695 | const pos = particle.getPosition();
|
6696 | const pointDistance = NumberUtils.getDistance(pos, mousePos);
|
6697 | const ratio = 1 - pointDistance / distance;
|
6698 |
|
6699 | if (pointDistance <= distance) {
|
6700 | if (ratio >= 0 && container.interactivity.status === Constants.mouseMoveEvent) {
|
6701 | this.hoverBubbleSize(particle, ratio);
|
6702 | this.hoverBubbleOpacity(particle, ratio);
|
6703 | this.hoverBubbleColor(particle);
|
6704 | }
|
6705 | } else {
|
6706 | this.reset(particle);
|
6707 | }
|
6708 |
|
6709 | if (container.interactivity.status === Constants.mouseLeaveEvent) {
|
6710 | this.reset(particle);
|
6711 | }
|
6712 | }
|
6713 | }
|
6714 |
|
6715 | hoverBubbleSize(particle, ratio, divBubble) {
|
6716 | const container = this.container;
|
6717 | const modeSize = (divBubble === null || divBubble === void 0 ? void 0 : divBubble.size) ? divBubble.size * container.retina.pixelRatio : container.retina.bubbleModeSize;
|
6718 |
|
6719 | if (modeSize === undefined) {
|
6720 | return;
|
6721 | }
|
6722 |
|
6723 | const optSize = NumberUtils.getRangeMax(particle.options.size.value) * container.retina.pixelRatio;
|
6724 | const pSize = particle.size.value;
|
6725 | const size = calculateBubbleValue(pSize, modeSize, optSize, ratio);
|
6726 |
|
6727 | if (size !== undefined) {
|
6728 | particle.bubble.radius = size;
|
6729 | }
|
6730 | }
|
6731 |
|
6732 | hoverBubbleOpacity(particle, ratio, divBubble) {
|
6733 | var _a;
|
6734 |
|
6735 | const options = this.container.actualOptions;
|
6736 | const modeOpacity = (_a = divBubble === null || divBubble === void 0 ? void 0 : divBubble.opacity) !== null && _a !== void 0 ? _a : options.interactivity.modes.bubble.opacity;
|
6737 |
|
6738 | if (modeOpacity === undefined) {
|
6739 | return;
|
6740 | }
|
6741 |
|
6742 | const optOpacity = particle.options.opacity.value;
|
6743 | const pOpacity = particle.opacity.value;
|
6744 | const opacity = calculateBubbleValue(pOpacity, modeOpacity, NumberUtils.getRangeMax(optOpacity), ratio);
|
6745 |
|
6746 | if (opacity !== undefined) {
|
6747 | particle.bubble.opacity = opacity;
|
6748 | }
|
6749 | }
|
6750 |
|
6751 | hoverBubbleColor(particle, divBubble) {
|
6752 | var _a;
|
6753 |
|
6754 | const options = this.container.actualOptions;
|
6755 |
|
6756 | if (particle.bubble.color === undefined) {
|
6757 | const modeColor = (_a = divBubble === null || divBubble === void 0 ? void 0 : divBubble.color) !== null && _a !== void 0 ? _a : options.interactivity.modes.bubble.color;
|
6758 |
|
6759 | if (modeColor === undefined) {
|
6760 | return;
|
6761 | }
|
6762 |
|
6763 | const bubbleColor = modeColor instanceof Array ? Utils.itemFromArray(modeColor) : modeColor;
|
6764 | particle.bubble.color = ColorUtils.colorToHsl(bubbleColor);
|
6765 | }
|
6766 | }
|
6767 |
|
6768 | }
|
6769 | ;
|
6770 |
|
6771 |
|
6772 | class Connector {
|
6773 | constructor(container) {
|
6774 | this.container = container;
|
6775 | }
|
6776 |
|
6777 | isEnabled() {
|
6778 | const container = this.container;
|
6779 | const mouse = container.interactivity.mouse;
|
6780 | const events = container.actualOptions.interactivity.events;
|
6781 |
|
6782 | if (!(events.onHover.enable && mouse.position)) {
|
6783 | return false;
|
6784 | }
|
6785 |
|
6786 | const hoverMode = events.onHover.mode;
|
6787 | return Utils.isInArray(HoverMode.connect, hoverMode);
|
6788 | }
|
6789 |
|
6790 | reset() {}
|
6791 |
|
6792 | interact() {
|
6793 | const container = this.container;
|
6794 | const options = container.actualOptions;
|
6795 |
|
6796 | if (options.interactivity.events.onHover.enable && container.interactivity.status === "mousemove") {
|
6797 | const mousePos = container.interactivity.mouse.position;
|
6798 |
|
6799 | if (!mousePos) {
|
6800 | return;
|
6801 | }
|
6802 |
|
6803 | const distance = Math.abs(container.retina.connectModeRadius);
|
6804 | const query = container.particles.quadTree.queryCircle(mousePos, distance);
|
6805 | let i = 0;
|
6806 |
|
6807 | for (const p1 of query) {
|
6808 | const pos1 = p1.getPosition();
|
6809 |
|
6810 | for (const p2 of query.slice(i + 1)) {
|
6811 | const pos2 = p2.getPosition();
|
6812 | const distMax = Math.abs(container.retina.connectModeDistance);
|
6813 | const xDiff = Math.abs(pos1.x - pos2.x);
|
6814 | const yDiff = Math.abs(pos1.y - pos2.y);
|
6815 |
|
6816 | if (xDiff < distMax && yDiff < distMax) {
|
6817 | container.canvas.drawConnectLine(p1, p2);
|
6818 | }
|
6819 | }
|
6820 |
|
6821 | ++i;
|
6822 | }
|
6823 | }
|
6824 | }
|
6825 |
|
6826 | }
|
6827 | ;
|
6828 |
|
6829 | class Linker {
|
6830 | constructor(container) {
|
6831 | this.container = container;
|
6832 | }
|
6833 |
|
6834 | isEnabled(particle) {
|
6835 | return particle.options.links.enable;
|
6836 | }
|
6837 |
|
6838 | reset() {}
|
6839 |
|
6840 | interact(p1) {
|
6841 | var _a;
|
6842 |
|
6843 | const container = this.container;
|
6844 | const linkOpt1 = p1.options.links;
|
6845 | const optOpacity = linkOpt1.opacity;
|
6846 | const optDistance = (_a = p1.linksDistance) !== null && _a !== void 0 ? _a : container.retina.linksDistance;
|
6847 | const canvasSize = container.canvas.size;
|
6848 | const warp = linkOpt1.warp;
|
6849 | const pos1 = p1.getPosition();
|
6850 | const range = warp ? new CircleWarp(pos1.x, pos1.y, optDistance, canvasSize) : new Circle(pos1.x, pos1.y, optDistance);
|
6851 | const query = container.particles.quadTree.query(range);
|
6852 |
|
6853 | for (const p2 of query) {
|
6854 | const linkOpt2 = p2.options.links;
|
6855 |
|
6856 | if (p1 === p2 || !linkOpt2.enable || linkOpt1.id !== linkOpt2.id || p2.spawning || p2.destroyed) {
|
6857 | continue;
|
6858 | }
|
6859 |
|
6860 | const pos2 = p2.getPosition();
|
6861 | let distance = NumberUtils.getDistance(pos1, pos2);
|
6862 |
|
6863 | if (warp) {
|
6864 | if (distance > optDistance) {
|
6865 | const pos2NE = {
|
6866 | x: pos2.x - canvasSize.width,
|
6867 | y: pos2.y
|
6868 | };
|
6869 | distance = NumberUtils.getDistance(pos1, pos2NE);
|
6870 |
|
6871 | if (distance > optDistance) {
|
6872 | const pos2SE = {
|
6873 | x: pos2.x - canvasSize.width,
|
6874 | y: pos2.y - canvasSize.height
|
6875 | };
|
6876 | distance = NumberUtils.getDistance(pos1, pos2SE);
|
6877 |
|
6878 | if (distance > optDistance) {
|
6879 | const pos2SW = {
|
6880 | x: pos2.x,
|
6881 | y: pos2.y - canvasSize.height
|
6882 | };
|
6883 | distance = NumberUtils.getDistance(pos1, pos2SW);
|
6884 | }
|
6885 | }
|
6886 | }
|
6887 | }
|
6888 |
|
6889 | if (distance > optDistance) {
|
6890 | return;
|
6891 | }
|
6892 |
|
6893 | const opacityLine = (1 - distance / optDistance) * optOpacity;
|
6894 | const linksOptions = p1.options.links;
|
6895 | let linkColor = linksOptions.id !== undefined ? container.particles.linksColors.get(linksOptions.id) : container.particles.linksColor;
|
6896 |
|
6897 | if (!linkColor) {
|
6898 | const optColor = linksOptions.color;
|
6899 | linkColor = ColorUtils.getLinkRandomColor(optColor, linksOptions.blink, linksOptions.consent);
|
6900 |
|
6901 | if (linksOptions.id !== undefined) {
|
6902 | container.particles.linksColors.set(linksOptions.id, linkColor);
|
6903 | } else {
|
6904 | container.particles.linksColor = linkColor;
|
6905 | }
|
6906 | }
|
6907 |
|
6908 | if (p2.links.map(t => t.destination).indexOf(p1) === -1 && p1.links.map(t => t.destination).indexOf(p2) === -1) {
|
6909 | p1.links.push({
|
6910 | destination: p2,
|
6911 | opacity: opacityLine
|
6912 | });
|
6913 | }
|
6914 | }
|
6915 | }
|
6916 |
|
6917 | }
|
6918 | ;
|
6919 |
|
6920 | class Attractor {
|
6921 | constructor(container) {
|
6922 | this.container = container;
|
6923 | }
|
6924 |
|
6925 | interact(p1) {
|
6926 | var _a;
|
6927 |
|
6928 | const container = this.container;
|
6929 | const distance = (_a = p1.linksDistance) !== null && _a !== void 0 ? _a : container.retina.linksDistance;
|
6930 | const pos1 = p1.getPosition();
|
6931 | const query = container.particles.quadTree.queryCircle(pos1, distance);
|
6932 |
|
6933 | for (const p2 of query) {
|
6934 | if (p1 === p2 || !p2.options.move.attract.enable || p2.destroyed || p2.spawning) {
|
6935 | continue;
|
6936 | }
|
6937 |
|
6938 | const pos2 = p2.getPosition();
|
6939 | const {
|
6940 | dx,
|
6941 | dy
|
6942 | } = NumberUtils.getDistances(pos1, pos2);
|
6943 | const rotate = p1.options.move.attract.rotate;
|
6944 | const ax = dx / (rotate.x * 1000);
|
6945 | const ay = dy / (rotate.y * 1000);
|
6946 | p1.velocity.x -= ax;
|
6947 | p1.velocity.y -= ay;
|
6948 | p2.velocity.x += ax;
|
6949 | p2.velocity.y += ay;
|
6950 | }
|
6951 | }
|
6952 |
|
6953 | isEnabled(particle) {
|
6954 | return particle.options.move.attract.enable;
|
6955 | }
|
6956 |
|
6957 | reset() {}
|
6958 |
|
6959 | }
|
6960 | ;
|
6961 |
|
6962 |
|
6963 |
|
6964 | function bounce(p1, p2) {
|
6965 | Utils.circleBounce(Utils.circleBounceDataFromParticle(p1), Utils.circleBounceDataFromParticle(p2));
|
6966 | }
|
6967 |
|
6968 | function destroy(p1, p2) {
|
6969 | if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
|
6970 | p1.destroy();
|
6971 | } else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
|
6972 | p2.destroy();
|
6973 | } else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
|
6974 | if (p1.getRadius() >= p2.getRadius()) {
|
6975 | p2.destroy();
|
6976 | } else {
|
6977 | p1.destroy();
|
6978 | }
|
6979 | }
|
6980 | }
|
6981 |
|
6982 | class Collider {
|
6983 | constructor(container) {
|
6984 | this.container = container;
|
6985 | }
|
6986 |
|
6987 | isEnabled(particle) {
|
6988 | return particle.options.collisions.enable;
|
6989 | }
|
6990 |
|
6991 | reset() {}
|
6992 |
|
6993 | interact(p1) {
|
6994 | const container = this.container;
|
6995 | const pos1 = p1.getPosition();
|
6996 | const query = container.particles.quadTree.queryCircle(pos1, p1.getRadius() * 2);
|
6997 |
|
6998 | for (const p2 of query) {
|
6999 | if (p1 === p2 || !p2.options.collisions.enable || p1.options.collisions.mode !== p2.options.collisions.mode || p2.destroyed || p2.spawning) {
|
7000 | continue;
|
7001 | }
|
7002 |
|
7003 | const pos2 = p2.getPosition();
|
7004 | const dist = NumberUtils.getDistance(pos1, pos2);
|
7005 | const radius1 = p1.getRadius();
|
7006 | const radius2 = p2.getRadius();
|
7007 | const distP = radius1 + radius2;
|
7008 |
|
7009 | if (dist <= distP) {
|
7010 | this.resolveCollision(p1, p2);
|
7011 | }
|
7012 | }
|
7013 | }
|
7014 |
|
7015 | resolveCollision(p1, p2) {
|
7016 | switch (p1.options.collisions.mode) {
|
7017 | case CollisionMode.absorb:
|
7018 | {
|
7019 | this.absorb(p1, p2);
|
7020 | break;
|
7021 | }
|
7022 |
|
7023 | case CollisionMode.bounce:
|
7024 | {
|
7025 | bounce(p1, p2);
|
7026 | break;
|
7027 | }
|
7028 |
|
7029 | case CollisionMode.destroy:
|
7030 | {
|
7031 | destroy(p1, p2);
|
7032 | break;
|
7033 | }
|
7034 | }
|
7035 | }
|
7036 |
|
7037 | absorb(p1, p2) {
|
7038 | const container = this.container;
|
7039 | const fps = container.actualOptions.fpsLimit / 1000;
|
7040 |
|
7041 | if (p1.getRadius() === undefined && p2.getRadius() !== undefined) {
|
7042 | p1.destroy();
|
7043 | } else if (p1.getRadius() !== undefined && p2.getRadius() === undefined) {
|
7044 | p2.destroy();
|
7045 | } else if (p1.getRadius() !== undefined && p2.getRadius() !== undefined) {
|
7046 | if (p1.getRadius() >= p2.getRadius()) {
|
7047 | const factor = NumberUtils.clamp(p1.getRadius() / p2.getRadius(), 0, p2.getRadius()) * fps;
|
7048 | p1.size.value += factor;
|
7049 | p2.size.value -= factor;
|
7050 |
|
7051 | if (p2.getRadius() <= container.retina.pixelRatio) {
|
7052 | p2.size.value = 0;
|
7053 | p2.destroy();
|
7054 | }
|
7055 | } else {
|
7056 | const factor = NumberUtils.clamp(p2.getRadius() / p1.getRadius(), 0, p1.getRadius()) * fps;
|
7057 | p1.size.value -= factor;
|
7058 | p2.size.value += factor;
|
7059 |
|
7060 | if (p1.getRadius() <= container.retina.pixelRatio) {
|
7061 | p1.size.value = 0;
|
7062 | p1.destroy();
|
7063 | }
|
7064 | }
|
7065 | }
|
7066 | }
|
7067 |
|
7068 | }
|
7069 | ;
|
7070 | class Infecter_Infecter {
|
7071 | constructor(container) {
|
7072 | this.container = container;
|
7073 | }
|
7074 |
|
7075 | isEnabled() {
|
7076 | return this.container.actualOptions.infection.enable;
|
7077 | }
|
7078 |
|
7079 | reset() {}
|
7080 |
|
7081 | interact(p1, delta) {
|
7082 | var _a, _b;
|
7083 |
|
7084 | const infecter1 = p1.infecter;
|
7085 | infecter1.updateInfection(delta.value);
|
7086 |
|
7087 | if (infecter1.infectionStage === undefined) {
|
7088 | return;
|
7089 | }
|
7090 |
|
7091 | const container = this.container;
|
7092 | const options = container.actualOptions;
|
7093 | const infectionOptions = options.infection;
|
7094 |
|
7095 | if (!infectionOptions.enable || infectionOptions.stages.length < 1) {
|
7096 | return;
|
7097 | }
|
7098 |
|
7099 | const infectionStage1 = infectionOptions.stages[infecter1.infectionStage];
|
7100 | const pxRatio = container.retina.pixelRatio;
|
7101 | const radius = p1.getRadius() * 2 + infectionStage1.radius * pxRatio;
|
7102 | const pos = p1.getPosition();
|
7103 | const infectedStage1 = (_a = infectionStage1.infectedStage) !== null && _a !== void 0 ? _a : infecter1.infectionStage;
|
7104 | const query = container.particles.quadTree.queryCircle(pos, radius);
|
7105 | const infections = infectionStage1.rate;
|
7106 | const neighbors = query.length;
|
7107 |
|
7108 | for (const p2 of query) {
|
7109 | if (p2 === p1 || p2.destroyed || p2.spawning || !(p2.infecter.infectionStage === undefined || p2.infecter.infectionStage !== infecter1.infectionStage)) {
|
7110 | continue;
|
7111 | }
|
7112 |
|
7113 | const infecter2 = p2.infecter;
|
7114 |
|
7115 | if (Math.random() < infections / neighbors) {
|
7116 | if (infecter2.infectionStage === undefined) {
|
7117 | infecter2.startInfection(infectedStage1);
|
7118 | } else if (infecter2.infectionStage < infecter1.infectionStage) {
|
7119 | infecter2.updateInfectionStage(infectedStage1);
|
7120 | } else if (infecter2.infectionStage > infecter1.infectionStage) {
|
7121 | const infectionStage2 = infectionOptions.stages[infecter2.infectionStage];
|
7122 | const infectedStage2 = (_b = infectionStage2 === null || infectionStage2 === void 0 ? void 0 : infectionStage2.infectedStage) !== null && _b !== void 0 ? _b : infecter2.infectionStage;
|
7123 | infecter1.updateInfectionStage(infectedStage2);
|
7124 | }
|
7125 | }
|
7126 | }
|
7127 | }
|
7128 |
|
7129 | }
|
7130 | ;
|
7131 |
|
7132 |
|
7133 | class TrailMaker {
|
7134 | constructor(container) {
|
7135 | this.container = container;
|
7136 | this.delay = 0;
|
7137 | }
|
7138 |
|
7139 | interact(delta) {
|
7140 | if (!this.container.retina.reduceFactor) {
|
7141 | return;
|
7142 | }
|
7143 |
|
7144 | const container = this.container;
|
7145 | const options = container.actualOptions;
|
7146 | const trailOptions = options.interactivity.modes.trail;
|
7147 | const optDelay = trailOptions.delay * 1000 / this.container.retina.reduceFactor;
|
7148 |
|
7149 | if (this.delay < optDelay) {
|
7150 | this.delay += delta.value;
|
7151 | }
|
7152 |
|
7153 | if (this.delay >= optDelay) {
|
7154 | container.particles.push(trailOptions.quantity, container.interactivity.mouse, trailOptions.particles);
|
7155 | this.delay -= optDelay;
|
7156 | }
|
7157 | }
|
7158 |
|
7159 | isEnabled() {
|
7160 | const container = this.container;
|
7161 | const options = container.actualOptions;
|
7162 | const mouse = container.interactivity.mouse;
|
7163 | const events = options.interactivity.events;
|
7164 | return mouse.clicking && mouse.inside && !!mouse.position && Utils.isInArray(ClickMode.trail, events.onClick.mode) || mouse.inside && !!mouse.position && Utils.isInArray(HoverMode.trail, events.onHover.mode);
|
7165 | }
|
7166 |
|
7167 | reset() {}
|
7168 |
|
7169 | }
|
7170 | ;
|
7171 |
|
7172 |
|
7173 | class Attractor_Attractor {
|
7174 | constructor(container) {
|
7175 | this.container = container;
|
7176 | }
|
7177 |
|
7178 | isEnabled() {
|
7179 | const container = this.container;
|
7180 | const options = container.actualOptions;
|
7181 | const mouse = container.interactivity.mouse;
|
7182 | const events = options.interactivity.events;
|
7183 |
|
7184 | if (!(events.onHover.enable && mouse.position || events.onClick.enable && mouse.clickPosition)) {
|
7185 | return false;
|
7186 | }
|
7187 |
|
7188 | const hoverMode = events.onHover.mode;
|
7189 | const clickMode = events.onClick.mode;
|
7190 | return Utils.isInArray(HoverMode.attract, hoverMode) || Utils.isInArray(ClickMode.attract, clickMode);
|
7191 | }
|
7192 |
|
7193 | reset() {}
|
7194 |
|
7195 | interact() {
|
7196 | const container = this.container;
|
7197 | const options = container.actualOptions;
|
7198 | const mouseMoveStatus = container.interactivity.status === Constants.mouseMoveEvent;
|
7199 | const events = options.interactivity.events;
|
7200 | const hoverEnabled = events.onHover.enable;
|
7201 | const hoverMode = events.onHover.mode;
|
7202 | const clickEnabled = events.onClick.enable;
|
7203 | const clickMode = events.onClick.mode;
|
7204 |
|
7205 | if (mouseMoveStatus && hoverEnabled && Utils.isInArray(HoverMode.attract, hoverMode)) {
|
7206 | this.hoverAttract();
|
7207 | } else if (clickEnabled && Utils.isInArray(ClickMode.attract, clickMode)) {
|
7208 | this.clickAttract();
|
7209 | }
|
7210 | }
|
7211 |
|
7212 | hoverAttract() {
|
7213 | const container = this.container;
|
7214 | const mousePos = container.interactivity.mouse.position;
|
7215 |
|
7216 | if (!mousePos) {
|
7217 | return;
|
7218 | }
|
7219 |
|
7220 | const attractRadius = container.retina.attractModeDistance;
|
7221 | this.processAttract(mousePos, attractRadius, new Circle(mousePos.x, mousePos.y, attractRadius));
|
7222 | }
|
7223 |
|
7224 | processAttract(position, attractRadius, area) {
|
7225 | const container = this.container;
|
7226 | const query = container.particles.quadTree.query(area);
|
7227 |
|
7228 | for (const particle of query) {
|
7229 | const {
|
7230 | dx,
|
7231 | dy,
|
7232 | distance
|
7233 | } = NumberUtils.getDistances(particle.position, position);
|
7234 | const normVec = {
|
7235 | x: dx / distance,
|
7236 | y: dy / distance
|
7237 | };
|
7238 | const velocity = container.actualOptions.interactivity.modes.attract.speed;
|
7239 | const attractFactor = NumberUtils.clamp((1 - Math.pow(distance / attractRadius, 2)) * velocity, 0, 50);
|
7240 | particle.position.x -= normVec.x * attractFactor;
|
7241 | particle.position.y -= normVec.y * attractFactor;
|
7242 | }
|
7243 | }
|
7244 |
|
7245 | clickAttract() {
|
7246 | const container = this.container;
|
7247 |
|
7248 | if (!container.attract.finish) {
|
7249 | if (!container.attract.count) {
|
7250 | container.attract.count = 0;
|
7251 | }
|
7252 |
|
7253 | container.attract.count++;
|
7254 |
|
7255 | if (container.attract.count === container.particles.count) {
|
7256 | container.attract.finish = true;
|
7257 | }
|
7258 | }
|
7259 |
|
7260 | if (container.attract.clicking) {
|
7261 | const mousePos = container.interactivity.mouse.clickPosition;
|
7262 |
|
7263 | if (!mousePos) {
|
7264 | return;
|
7265 | }
|
7266 |
|
7267 | const attractRadius = container.retina.attractModeDistance;
|
7268 | this.processAttract(mousePos, attractRadius, new Circle(mousePos.x, mousePos.y, attractRadius));
|
7269 | } else if (container.attract.clicking === false) {
|
7270 | container.attract.particles = [];
|
7271 | }
|
7272 |
|
7273 | return;
|
7274 | }
|
7275 |
|
7276 | }
|
7277 | ;
|
7278 |
|
7279 |
|
7280 | class Lighter {
|
7281 | constructor(container) {
|
7282 | this.container = container;
|
7283 | }
|
7284 |
|
7285 | interact(particle) {
|
7286 | const container = this.container;
|
7287 | const options = container.actualOptions;
|
7288 |
|
7289 | if (options.interactivity.events.onHover.enable && container.interactivity.status === "mousemove") {
|
7290 | const mousePos = this.container.interactivity.mouse.position;
|
7291 |
|
7292 | if (mousePos) {
|
7293 | container.canvas.drawParticleShadow(particle, mousePos);
|
7294 | }
|
7295 | }
|
7296 | }
|
7297 |
|
7298 | isEnabled() {
|
7299 | const container = this.container;
|
7300 | const mouse = container.interactivity.mouse;
|
7301 | const events = container.actualOptions.interactivity.events;
|
7302 |
|
7303 | if (!(events.onHover.enable && mouse.position)) {
|
7304 | return false;
|
7305 | }
|
7306 |
|
7307 | const hoverMode = events.onHover.mode;
|
7308 | return Utils.isInArray(HoverMode.light, hoverMode);
|
7309 | }
|
7310 |
|
7311 | reset() {}
|
7312 |
|
7313 | }
|
7314 | ;
|
7315 |
|
7316 |
|
7317 | class Lighter_Lighter {
|
7318 | constructor(container) {
|
7319 | this.container = container;
|
7320 | }
|
7321 |
|
7322 | interact() {
|
7323 | const container = this.container;
|
7324 | const options = container.actualOptions;
|
7325 |
|
7326 | if (options.interactivity.events.onHover.enable && container.interactivity.status === "mousemove") {
|
7327 | const mousePos = container.interactivity.mouse.position;
|
7328 |
|
7329 | if (!mousePos) {
|
7330 | return;
|
7331 | }
|
7332 |
|
7333 | container.canvas.drawLight(mousePos);
|
7334 | }
|
7335 | }
|
7336 |
|
7337 | isEnabled() {
|
7338 | const container = this.container;
|
7339 | const mouse = container.interactivity.mouse;
|
7340 | const events = container.actualOptions.interactivity.events;
|
7341 |
|
7342 | if (!(events.onHover.enable && mouse.position)) {
|
7343 | return false;
|
7344 | }
|
7345 |
|
7346 | const hoverMode = events.onHover.mode;
|
7347 | return Utils.isInArray(HoverMode.light, hoverMode);
|
7348 | }
|
7349 |
|
7350 | reset() {}
|
7351 |
|
7352 | }
|
7353 | ;
|
7354 |
|
7355 |
|
7356 |
|
7357 | class Bouncer {
|
7358 | constructor(container) {
|
7359 | this.container = container;
|
7360 | }
|
7361 |
|
7362 | isEnabled() {
|
7363 | const container = this.container;
|
7364 | const options = container.actualOptions;
|
7365 | const mouse = container.interactivity.mouse;
|
7366 | const events = options.interactivity.events;
|
7367 | const divs = events.onDiv;
|
7368 | return mouse.position && events.onHover.enable && Utils.isInArray(HoverMode.bounce, events.onHover.mode) || Utils.isDivModeEnabled(DivMode.bounce, divs);
|
7369 | }
|
7370 |
|
7371 | interact() {
|
7372 | const container = this.container;
|
7373 | const options = container.actualOptions;
|
7374 | const events = options.interactivity.events;
|
7375 | const mouseMoveStatus = container.interactivity.status === Constants.mouseMoveEvent;
|
7376 | const hoverEnabled = events.onHover.enable;
|
7377 | const hoverMode = events.onHover.mode;
|
7378 | const divs = events.onDiv;
|
7379 |
|
7380 | if (mouseMoveStatus && hoverEnabled && Utils.isInArray(HoverMode.bounce, hoverMode)) {
|
7381 | this.processMouseBounce();
|
7382 | } else {
|
7383 | Utils.divModeExecute(DivMode.bounce, divs, (selector, div) => this.singleSelectorBounce(selector, div));
|
7384 | }
|
7385 | }
|
7386 |
|
7387 | reset() {}
|
7388 |
|
7389 | processMouseBounce() {
|
7390 | const container = this.container;
|
7391 | const pxRatio = container.retina.pixelRatio;
|
7392 | const tolerance = 10 * pxRatio;
|
7393 | const mousePos = container.interactivity.mouse.position;
|
7394 | const radius = container.retina.bounceModeDistance;
|
7395 |
|
7396 | if (mousePos) {
|
7397 | this.processBounce(mousePos, radius, new Circle(mousePos.x, mousePos.y, radius + tolerance));
|
7398 | }
|
7399 | }
|
7400 |
|
7401 | singleSelectorBounce(selector, div) {
|
7402 | const container = this.container;
|
7403 | const query = document.querySelectorAll(selector);
|
7404 |
|
7405 | if (!query.length) {
|
7406 | return;
|
7407 | }
|
7408 |
|
7409 | query.forEach(item => {
|
7410 | const elem = item;
|
7411 | const pxRatio = container.retina.pixelRatio;
|
7412 | const pos = {
|
7413 | x: (elem.offsetLeft + elem.offsetWidth / 2) * pxRatio,
|
7414 | y: (elem.offsetTop + elem.offsetHeight / 2) * pxRatio
|
7415 | };
|
7416 | const radius = elem.offsetWidth / 2 * pxRatio;
|
7417 | const tolerance = 10 * pxRatio;
|
7418 | const area = div.type === DivType.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);
|
7419 | this.processBounce(pos, radius, area);
|
7420 | });
|
7421 | }
|
7422 |
|
7423 | processBounce(position, radius, area) {
|
7424 | const query = this.container.particles.quadTree.query(area);
|
7425 |
|
7426 | for (const particle of query) {
|
7427 | if (area instanceof Circle) {
|
7428 | Utils.circleBounce(Utils.circleBounceDataFromParticle(particle), {
|
7429 | position,
|
7430 | radius,
|
7431 | mass: Math.pow(radius, 2) * Math.PI / 2,
|
7432 | velocity: Vector.create(0, 0),
|
7433 | factor: {
|
7434 | horizontal: 0,
|
7435 | vertical: 0
|
7436 | }
|
7437 | });
|
7438 | } else if (area instanceof Rectangle) {
|
7439 | Utils.rectBounce(particle, Utils.calculateBounds(position, radius));
|
7440 | }
|
7441 | }
|
7442 | }
|
7443 |
|
7444 | }
|
7445 | ;
|
7446 |
|
7447 |
|
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 |
|
7453 |
|
7454 |
|
7455 |
|
7456 |
|
7457 |
|
7458 |
|
7459 | class InteractionManager {
|
7460 | constructor(container) {
|
7461 | this.container = container;
|
7462 | this.externalInteractors = [new Bouncer(container), new Bubbler(container), new Connector(container), new Grabber(container), new Lighter_Lighter(container), new Attractor_Attractor(container), new Repulser(container), new TrailMaker(container)];
|
7463 | this.particleInteractors = [new Attractor(container), new Lighter(container), new Collider(container), new Infecter_Infecter(container), new Linker(container)];
|
7464 | }
|
7465 |
|
7466 | init() {}
|
7467 |
|
7468 | externalInteract(delta) {
|
7469 | for (const interactor of this.externalInteractors) {
|
7470 | if (interactor.isEnabled()) {
|
7471 | interactor.interact(delta);
|
7472 | }
|
7473 | }
|
7474 | }
|
7475 |
|
7476 | particlesInteract(particle, delta) {
|
7477 | for (const interactor of this.externalInteractors) {
|
7478 | interactor.reset(particle);
|
7479 | }
|
7480 |
|
7481 | for (const interactor of this.particleInteractors) {
|
7482 | if (interactor.isEnabled(particle)) {
|
7483 | interactor.interact(particle, delta);
|
7484 | }
|
7485 | }
|
7486 | }
|
7487 |
|
7488 | }
|
7489 | ;
|
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 | class Particles {
|
7495 | constructor(container) {
|
7496 | this.container = container;
|
7497 | this.nextId = 0;
|
7498 | this.array = [];
|
7499 | this.limit = 0;
|
7500 | this.linksFreq = new Map();
|
7501 | this.trianglesFreq = new Map();
|
7502 | this.interactionManager = new InteractionManager(container);
|
7503 | const canvasSize = this.container.canvas.size;
|
7504 | this.linksColors = new Map();
|
7505 | this.quadTree = new QuadTree(new Rectangle(-canvasSize.width / 4, -canvasSize.height / 4, canvasSize.width * 3 / 2, canvasSize.height * 3 / 2), 4);
|
7506 | }
|
7507 |
|
7508 | get count() {
|
7509 | return this.array.length;
|
7510 | }
|
7511 |
|
7512 | init() {
|
7513 | const container = this.container;
|
7514 | const options = container.actualOptions;
|
7515 | this.linksFreq = new Map();
|
7516 | this.trianglesFreq = new Map();
|
7517 | let handled = false;
|
7518 |
|
7519 | for (const particle of options.manualParticles) {
|
7520 | const pos = particle.position ? {
|
7521 | x: particle.position.x * container.canvas.size.width / 100,
|
7522 | y: particle.position.y * container.canvas.size.height / 100
|
7523 | } : undefined;
|
7524 | this.addParticle(pos, particle.options);
|
7525 | }
|
7526 |
|
7527 | for (const [, plugin] of container.plugins) {
|
7528 | if (plugin.particlesInitialization !== undefined) {
|
7529 | handled = plugin.particlesInitialization();
|
7530 | }
|
7531 |
|
7532 | if (handled) {
|
7533 | break;
|
7534 | }
|
7535 | }
|
7536 |
|
7537 | if (!handled) {
|
7538 | for (let i = this.count; i < options.particles.number.value; i++) {
|
7539 | this.addParticle();
|
7540 | }
|
7541 | }
|
7542 |
|
7543 | if (options.infection.enable) {
|
7544 | for (let i = 0; i < options.infection.infections; i++) {
|
7545 | const notInfected = this.array.filter(p => p.infecter.infectionStage === undefined);
|
7546 | const infected = Utils.itemFromArray(notInfected);
|
7547 | infected.infecter.startInfection(0);
|
7548 | }
|
7549 | }
|
7550 |
|
7551 | this.interactionManager.init();
|
7552 | container.pathGenerator.init();
|
7553 | }
|
7554 |
|
7555 | redraw() {
|
7556 | this.clear();
|
7557 | this.init();
|
7558 | this.draw({
|
7559 | value: 0,
|
7560 | factor: 0
|
7561 | });
|
7562 | }
|
7563 |
|
7564 | removeAt(index, quantity, override) {
|
7565 | if (index >= 0 && index <= this.count) {
|
7566 | for (const particle of this.array.splice(index, quantity !== null && quantity !== void 0 ? quantity : 1)) {
|
7567 | particle.destroy(override);
|
7568 | }
|
7569 | }
|
7570 | }
|
7571 |
|
7572 | remove(particle, override) {
|
7573 | this.removeAt(this.array.indexOf(particle), undefined, override);
|
7574 | }
|
7575 |
|
7576 | update(delta) {
|
7577 | const container = this.container;
|
7578 | const particlesToDelete = [];
|
7579 | container.pathGenerator.update();
|
7580 |
|
7581 | for (const [, plugin] of container.plugins) {
|
7582 | if (plugin.update !== undefined) {
|
7583 | plugin.update(delta);
|
7584 | }
|
7585 | }
|
7586 |
|
7587 | for (const particle of this.array) {
|
7588 | const resizeFactor = this.container.canvas.resizeFactor;
|
7589 |
|
7590 | if (resizeFactor) {
|
7591 | particle.position.x *= resizeFactor.width;
|
7592 | particle.position.y *= resizeFactor.height;
|
7593 | }
|
7594 |
|
7595 | particle.move(delta);
|
7596 |
|
7597 | if (particle.destroyed) {
|
7598 | particlesToDelete.push(particle);
|
7599 | continue;
|
7600 | }
|
7601 |
|
7602 | this.quadTree.insert(new Point(particle.getPosition(), particle));
|
7603 | }
|
7604 |
|
7605 | for (const particle of particlesToDelete) {
|
7606 | this.remove(particle);
|
7607 | }
|
7608 |
|
7609 | this.interactionManager.externalInteract(delta);
|
7610 |
|
7611 | for (const particle of this.container.particles.array) {
|
7612 | particle.update(delta);
|
7613 |
|
7614 | if (!particle.destroyed && !particle.spawning) {
|
7615 | this.interactionManager.particlesInteract(particle, delta);
|
7616 | }
|
7617 | }
|
7618 |
|
7619 | delete container.canvas.resizeFactor;
|
7620 | }
|
7621 |
|
7622 | draw(delta) {
|
7623 | const container = this.container;
|
7624 | container.canvas.clear();
|
7625 | const canvasSize = this.container.canvas.size;
|
7626 | this.quadTree = new QuadTree(new Rectangle(-canvasSize.width / 4, -canvasSize.height / 4, canvasSize.width * 3 / 2, canvasSize.height * 3 / 2), 4);
|
7627 | this.update(delta);
|
7628 |
|
7629 | for (const [, plugin] of container.plugins) {
|
7630 | container.canvas.drawPlugin(plugin, delta);
|
7631 | }
|
7632 |
|
7633 | for (const p of this.array) {
|
7634 | p.draw(delta);
|
7635 | }
|
7636 | }
|
7637 |
|
7638 | clear() {
|
7639 | this.array = [];
|
7640 | }
|
7641 |
|
7642 | push(nb, mouse, overrideOptions) {
|
7643 | const container = this.container;
|
7644 | const options = container.actualOptions;
|
7645 | const limit = options.particles.number.limit * container.density;
|
7646 | this.pushing = true;
|
7647 |
|
7648 | if (limit > 0) {
|
7649 | const countToRemove = this.count + nb - limit;
|
7650 |
|
7651 | if (countToRemove > 0) {
|
7652 | this.removeQuantity(countToRemove);
|
7653 | }
|
7654 | }
|
7655 |
|
7656 | for (let i = 0; i < nb; i++) {
|
7657 | this.addParticle(mouse === null || mouse === void 0 ? void 0 : mouse.position, overrideOptions);
|
7658 | }
|
7659 |
|
7660 | this.pushing = false;
|
7661 | }
|
7662 |
|
7663 | addParticle(position, overrideOptions) {
|
7664 | return this.pushParticle(position, overrideOptions);
|
7665 | }
|
7666 |
|
7667 | addSplitParticle(parent) {
|
7668 | const splitOptions = parent.options.destroy.split;
|
7669 | const options = new ParticlesOptions();
|
7670 | options.load(parent.options);
|
7671 | const factor = NumberUtils.getRangeValue(splitOptions.factor.value);
|
7672 | options.color.load({
|
7673 | value: {
|
7674 | hsl: parent.getFillColor()
|
7675 | }
|
7676 | });
|
7677 |
|
7678 | if (typeof options.size.value === "number") {
|
7679 | options.size.value /= factor;
|
7680 | } else {
|
7681 | options.size.value.min /= factor;
|
7682 | options.size.value.max /= factor;
|
7683 | }
|
7684 |
|
7685 | options.load(splitOptions.particles);
|
7686 | const offset = NumberUtils.setRangeValue(-parent.size.value, parent.size.value);
|
7687 | const position = {
|
7688 | x: parent.position.x + NumberUtils.randomInRange(offset),
|
7689 | y: parent.position.y + NumberUtils.randomInRange(offset)
|
7690 | };
|
7691 | return this.pushParticle(position, options, particle => {
|
7692 | if (particle.size.value < 0.5) {
|
7693 | return false;
|
7694 | }
|
7695 |
|
7696 | particle.velocity.length = NumberUtils.randomInRange(NumberUtils.setRangeValue(parent.velocity.length, particle.velocity.length));
|
7697 | particle.splitCount = parent.splitCount + 1;
|
7698 | particle.unbreakable = true;
|
7699 | setTimeout(() => {
|
7700 | particle.unbreakable = false;
|
7701 | }, 500);
|
7702 | return true;
|
7703 | });
|
7704 | }
|
7705 |
|
7706 | removeQuantity(quantity) {
|
7707 | this.removeAt(0, quantity);
|
7708 | }
|
7709 |
|
7710 | getLinkFrequency(p1, p2) {
|
7711 | const key = `${Math.min(p1.id, p2.id)}_${Math.max(p1.id, p2.id)}`;
|
7712 | let res = this.linksFreq.get(key);
|
7713 |
|
7714 | if (res === undefined) {
|
7715 | res = Math.random();
|
7716 | this.linksFreq.set(key, res);
|
7717 | }
|
7718 |
|
7719 | return res;
|
7720 | }
|
7721 |
|
7722 | getTriangleFrequency(p1, p2, p3) {
|
7723 | let [id1, id2, id3] = [p1.id, p2.id, p3.id];
|
7724 |
|
7725 | if (id1 > id2) {
|
7726 | [id2, id1] = [id1, id2];
|
7727 | }
|
7728 |
|
7729 | if (id2 > id3) {
|
7730 | [id3, id2] = [id2, id3];
|
7731 | }
|
7732 |
|
7733 | if (id1 > id3) {
|
7734 | [id3, id1] = [id1, id3];
|
7735 | }
|
7736 |
|
7737 | const key = `${id1}_${id2}_${id3}`;
|
7738 | let res = this.trianglesFreq.get(key);
|
7739 |
|
7740 | if (res === undefined) {
|
7741 | res = Math.random();
|
7742 | this.trianglesFreq.set(key, res);
|
7743 | }
|
7744 |
|
7745 | return res;
|
7746 | }
|
7747 |
|
7748 | setDensity() {
|
7749 | const options = this.container.actualOptions;
|
7750 | this.applyDensity(options.particles);
|
7751 | }
|
7752 |
|
7753 | applyDensity(options) {
|
7754 | var _a;
|
7755 |
|
7756 | if (!((_a = options.number.density) === null || _a === void 0 ? void 0 : _a.enable)) {
|
7757 | return;
|
7758 | }
|
7759 |
|
7760 | const numberOptions = options.number;
|
7761 | const densityFactor = this.initDensityFactor(numberOptions.density);
|
7762 | const optParticlesNumber = numberOptions.value;
|
7763 | const optParticlesLimit = numberOptions.limit > 0 ? numberOptions.limit : optParticlesNumber;
|
7764 | const particlesNumber = Math.min(optParticlesNumber, optParticlesLimit) * densityFactor;
|
7765 | const particlesCount = this.count;
|
7766 | this.limit = numberOptions.limit * densityFactor;
|
7767 |
|
7768 | if (particlesCount < particlesNumber) {
|
7769 | this.push(Math.abs(particlesNumber - particlesCount), undefined, options);
|
7770 | } else if (particlesCount > particlesNumber) {
|
7771 | this.removeQuantity(particlesCount - particlesNumber);
|
7772 | }
|
7773 | }
|
7774 |
|
7775 | initDensityFactor(densityOptions) {
|
7776 | const container = this.container;
|
7777 |
|
7778 | if (!container.canvas.element || !densityOptions.enable) {
|
7779 | return 1;
|
7780 | }
|
7781 |
|
7782 | const canvas = container.canvas.element;
|
7783 | const pxRatio = container.retina.pixelRatio;
|
7784 | return canvas.width * canvas.height / (densityOptions.factor * pxRatio * pxRatio * densityOptions.area);
|
7785 | }
|
7786 |
|
7787 | pushParticle(position, overrideOptions, initializer) {
|
7788 | try {
|
7789 | const particle = new Particle(this.nextId, this.container, position, overrideOptions);
|
7790 | let canAdd = true;
|
7791 |
|
7792 | if (initializer) {
|
7793 | canAdd = initializer(particle);
|
7794 | }
|
7795 |
|
7796 | if (!canAdd) {
|
7797 | return;
|
7798 | }
|
7799 |
|
7800 | this.array.push(particle);
|
7801 | this.nextId++;
|
7802 | return particle;
|
7803 | } catch (e) {
|
7804 | console.warn(`error adding particle: ${e}`);
|
7805 | return;
|
7806 | }
|
7807 | }
|
7808 |
|
7809 | }
|
7810 | ;
|
7811 |
|
7812 | class Retina {
|
7813 | constructor(container) {
|
7814 | this.container = container;
|
7815 | }
|
7816 |
|
7817 | init() {
|
7818 | const container = this.container;
|
7819 | const options = container.actualOptions;
|
7820 | this.pixelRatio = !options.detectRetina || Utils.isSsr() ? 1 : window.devicePixelRatio;
|
7821 | const motionOptions = this.container.actualOptions.motion;
|
7822 |
|
7823 | if (motionOptions && (motionOptions.disable || motionOptions.reduce.value)) {
|
7824 | if (Utils.isSsr() || typeof matchMedia === "undefined" || !matchMedia) {
|
7825 | this.reduceFactor = 1;
|
7826 | } else {
|
7827 | const mediaQuery = matchMedia("(prefers-reduced-motion: reduce)");
|
7828 |
|
7829 | if (mediaQuery) {
|
7830 | this.handleMotionChange(mediaQuery);
|
7831 |
|
7832 | const handleChange = () => {
|
7833 | this.handleMotionChange(mediaQuery);
|
7834 | container.refresh().catch(() => {});
|
7835 | };
|
7836 |
|
7837 | if (mediaQuery.addEventListener !== undefined) {
|
7838 | mediaQuery.addEventListener("change", handleChange);
|
7839 | } else if (mediaQuery.addListener !== undefined) {
|
7840 | mediaQuery.addListener(handleChange);
|
7841 | }
|
7842 | }
|
7843 | }
|
7844 | } else {
|
7845 | this.reduceFactor = 1;
|
7846 | }
|
7847 |
|
7848 | const ratio = this.pixelRatio;
|
7849 |
|
7850 | if (container.canvas.element) {
|
7851 | const element = container.canvas.element;
|
7852 | container.canvas.size.width = element.offsetWidth * ratio;
|
7853 | container.canvas.size.height = element.offsetHeight * ratio;
|
7854 | }
|
7855 |
|
7856 | const particles = options.particles;
|
7857 | this.linksDistance = particles.links.distance * ratio;
|
7858 | this.linksWidth = particles.links.width * ratio;
|
7859 | this.sizeAnimationSpeed = particles.size.animation.speed * ratio;
|
7860 | const modes = options.interactivity.modes;
|
7861 | this.connectModeDistance = modes.connect.distance * ratio;
|
7862 | this.connectModeRadius = modes.connect.radius * ratio;
|
7863 | this.grabModeDistance = modes.grab.distance * ratio;
|
7864 | this.repulseModeDistance = modes.repulse.distance * ratio;
|
7865 | this.bounceModeDistance = modes.bounce.distance * ratio;
|
7866 | this.attractModeDistance = modes.attract.distance * ratio;
|
7867 | this.slowModeRadius = modes.slow.radius * ratio;
|
7868 | this.bubbleModeDistance = modes.bubble.distance * ratio;
|
7869 |
|
7870 | if (modes.bubble.size) {
|
7871 | this.bubbleModeSize = modes.bubble.size * ratio;
|
7872 | }
|
7873 | }
|
7874 |
|
7875 | initParticle(particle) {
|
7876 | const particlesOptions = particle.options;
|
7877 | const ratio = this.pixelRatio;
|
7878 | particle.linksDistance = particlesOptions.links.distance * ratio;
|
7879 | particle.linksWidth = particlesOptions.links.width * ratio;
|
7880 | particle.moveDrift = NumberUtils.getRangeValue(particlesOptions.move.drift) * ratio;
|
7881 | particle.moveSpeed = NumberUtils.getRangeValue(particlesOptions.move.speed) * ratio;
|
7882 | particle.sizeAnimationSpeed = particlesOptions.size.animation.speed * ratio;
|
7883 | particle.maxDistance = particlesOptions.move.distance * ratio;
|
7884 | }
|
7885 |
|
7886 | handleMotionChange(mediaQuery) {
|
7887 | const options = this.container.actualOptions;
|
7888 |
|
7889 | if (mediaQuery.matches) {
|
7890 | const motion = options.motion;
|
7891 | this.reduceFactor = motion.disable ? 0 : motion.reduce.value ? 1 / motion.reduce.factor : 1;
|
7892 | } else {
|
7893 | this.reduceFactor = 1;
|
7894 | }
|
7895 | }
|
7896 |
|
7897 | }
|
7898 | ;
|
7899 | class FrameManager {
|
7900 | constructor(container) {
|
7901 | this.container = container;
|
7902 | }
|
7903 |
|
7904 | nextFrame(timestamp) {
|
7905 | try {
|
7906 | const container = this.container;
|
7907 |
|
7908 | if (container.lastFrameTime !== undefined && timestamp < container.lastFrameTime + 1000 / container.fpsLimit) {
|
7909 | container.draw();
|
7910 | return;
|
7911 | }
|
7912 |
|
7913 | const deltaValue = timestamp - container.lastFrameTime;
|
7914 | const delta = {
|
7915 | value: deltaValue,
|
7916 | factor: 60 * deltaValue / 1000
|
7917 | };
|
7918 | container.lastFrameTime = timestamp;
|
7919 | container.particles.draw(delta);
|
7920 |
|
7921 | if (container.getAnimationStatus()) {
|
7922 | container.draw();
|
7923 | }
|
7924 | } catch (e) {
|
7925 | console.error("tsParticles error in animation loop", e);
|
7926 | }
|
7927 | }
|
7928 |
|
7929 | }
|
7930 | ;
|
7931 | class ClickEvent {
|
7932 | constructor() {
|
7933 | this.enable = false;
|
7934 | this.mode = [];
|
7935 | }
|
7936 |
|
7937 | load(data) {
|
7938 | if (data === undefined) {
|
7939 | return;
|
7940 | }
|
7941 |
|
7942 | if (data.enable !== undefined) {
|
7943 | this.enable = data.enable;
|
7944 | }
|
7945 |
|
7946 | if (data.mode !== undefined) {
|
7947 | this.mode = data.mode;
|
7948 | }
|
7949 | }
|
7950 |
|
7951 | }
|
7952 | ;
|
7953 |
|
7954 | class DivEvent {
|
7955 | constructor() {
|
7956 | this.selectors = [];
|
7957 | this.enable = false;
|
7958 | this.mode = [];
|
7959 | this.type = DivType.circle;
|
7960 | }
|
7961 |
|
7962 | get elementId() {
|
7963 | return this.ids;
|
7964 | }
|
7965 |
|
7966 | set elementId(value) {
|
7967 | this.ids = value;
|
7968 | }
|
7969 |
|
7970 | get el() {
|
7971 | return this.elementId;
|
7972 | }
|
7973 |
|
7974 | set el(value) {
|
7975 | this.elementId = value;
|
7976 | }
|
7977 |
|
7978 | get ids() {
|
7979 | return this.selectors instanceof Array ? this.selectors.map(t => t.replace("#", "")) : this.selectors.replace("#", "");
|
7980 | }
|
7981 |
|
7982 | set ids(value) {
|
7983 | this.selectors = value instanceof Array ? value.map(t => `#${t}`) : `#${value}`;
|
7984 | }
|
7985 |
|
7986 | load(data) {
|
7987 | var _a, _b;
|
7988 |
|
7989 | if (data === undefined) {
|
7990 | return;
|
7991 | }
|
7992 |
|
7993 | const ids = (_b = (_a = data.ids) !== null && _a !== void 0 ? _a : data.elementId) !== null && _b !== void 0 ? _b : data.el;
|
7994 |
|
7995 | if (ids !== undefined) {
|
7996 | this.ids = ids;
|
7997 | }
|
7998 |
|
7999 | if (data.selectors !== undefined) {
|
8000 | this.selectors = data.selectors;
|
8001 | }
|
8002 |
|
8003 | if (data.enable !== undefined) {
|
8004 | this.enable = data.enable;
|
8005 | }
|
8006 |
|
8007 | if (data.mode !== undefined) {
|
8008 | this.mode = data.mode;
|
8009 | }
|
8010 |
|
8011 | if (data.type !== undefined) {
|
8012 | this.type = data.type;
|
8013 | }
|
8014 | }
|
8015 |
|
8016 | }
|
8017 | ;
|
8018 | class Parallax {
|
8019 | constructor() {
|
8020 | this.enable = false;
|
8021 | this.force = 2;
|
8022 | this.smooth = 10;
|
8023 | }
|
8024 |
|
8025 | load(data) {
|
8026 | if (data === undefined) {
|
8027 | return;
|
8028 | }
|
8029 |
|
8030 | if (data.enable !== undefined) {
|
8031 | this.enable = data.enable;
|
8032 | }
|
8033 |
|
8034 | if (data.force !== undefined) {
|
8035 | this.force = data.force;
|
8036 | }
|
8037 |
|
8038 | if (data.smooth !== undefined) {
|
8039 | this.smooth = data.smooth;
|
8040 | }
|
8041 | }
|
8042 |
|
8043 | }
|
8044 | ;
|
8045 |
|
8046 | class HoverEvent {
|
8047 | constructor() {
|
8048 | this.enable = false;
|
8049 | this.mode = [];
|
8050 | this.parallax = new Parallax();
|
8051 | }
|
8052 |
|
8053 | load(data) {
|
8054 | if (data === undefined) {
|
8055 | return;
|
8056 | }
|
8057 |
|
8058 | if (data.enable !== undefined) {
|
8059 | this.enable = data.enable;
|
8060 | }
|
8061 |
|
8062 | if (data.mode !== undefined) {
|
8063 | this.mode = data.mode;
|
8064 | }
|
8065 |
|
8066 | this.parallax.load(data.parallax);
|
8067 | }
|
8068 |
|
8069 | }
|
8070 | ;
|
8071 |
|
8072 |
|
8073 |
|
8074 | class Events {
|
8075 | constructor() {
|
8076 | this.onClick = new ClickEvent();
|
8077 | this.onDiv = new DivEvent();
|
8078 | this.onHover = new HoverEvent();
|
8079 | this.resize = true;
|
8080 | }
|
8081 |
|
8082 | get onclick() {
|
8083 | return this.onClick;
|
8084 | }
|
8085 |
|
8086 | set onclick(value) {
|
8087 | this.onClick = value;
|
8088 | }
|
8089 |
|
8090 | get ondiv() {
|
8091 | return this.onDiv;
|
8092 | }
|
8093 |
|
8094 | set ondiv(value) {
|
8095 | this.onDiv = value;
|
8096 | }
|
8097 |
|
8098 | get onhover() {
|
8099 | return this.onHover;
|
8100 | }
|
8101 |
|
8102 | set onhover(value) {
|
8103 | this.onHover = value;
|
8104 | }
|
8105 |
|
8106 | load(data) {
|
8107 | var _a, _b, _c;
|
8108 |
|
8109 | if (data === undefined) {
|
8110 | return;
|
8111 | }
|
8112 |
|
8113 | this.onClick.load((_a = data.onClick) !== null && _a !== void 0 ? _a : data.onclick);
|
8114 | const onDiv = (_b = data.onDiv) !== null && _b !== void 0 ? _b : data.ondiv;
|
8115 |
|
8116 | if (onDiv !== undefined) {
|
8117 | if (onDiv instanceof Array) {
|
8118 | this.onDiv = onDiv.map(div => {
|
8119 | const tmp = new DivEvent();
|
8120 | tmp.load(div);
|
8121 | return tmp;
|
8122 | });
|
8123 | } else {
|
8124 | this.onDiv = new DivEvent();
|
8125 | this.onDiv.load(onDiv);
|
8126 | }
|
8127 | }
|
8128 |
|
8129 | this.onHover.load((_c = data.onHover) !== null && _c !== void 0 ? _c : data.onhover);
|
8130 |
|
8131 | if (data.resize !== undefined) {
|
8132 | this.resize = data.resize;
|
8133 | }
|
8134 | }
|
8135 |
|
8136 | }
|
8137 | ;
|
8138 |
|
8139 | class BubbleBase {
|
8140 | constructor() {
|
8141 | this.distance = 200;
|
8142 | this.duration = 0.4;
|
8143 | }
|
8144 |
|
8145 | load(data) {
|
8146 | if (data === undefined) {
|
8147 | return;
|
8148 | }
|
8149 |
|
8150 | if (data.distance !== undefined) {
|
8151 | this.distance = data.distance;
|
8152 | }
|
8153 |
|
8154 | if (data.duration !== undefined) {
|
8155 | this.duration = data.duration;
|
8156 | }
|
8157 |
|
8158 | if (data.opacity !== undefined) {
|
8159 | this.opacity = data.opacity;
|
8160 | }
|
8161 |
|
8162 | if (data.color !== undefined) {
|
8163 | if (data.color instanceof Array) {
|
8164 | this.color = data.color.map(s => OptionsColor.create(undefined, s));
|
8165 | } else {
|
8166 | if (this.color instanceof Array) {
|
8167 | this.color = new OptionsColor();
|
8168 | }
|
8169 |
|
8170 | this.color = OptionsColor.create(this.color, data.color);
|
8171 | }
|
8172 | }
|
8173 |
|
8174 | if (data.size !== undefined) {
|
8175 | this.size = data.size;
|
8176 | }
|
8177 | }
|
8178 |
|
8179 | }
|
8180 | ;
|
8181 |
|
8182 | class BubbleDiv extends BubbleBase {
|
8183 | constructor() {
|
8184 | super();
|
8185 | this.selectors = [];
|
8186 | }
|
8187 |
|
8188 | get ids() {
|
8189 | return this.selectors instanceof Array ? this.selectors.map(t => t.replace("#", "")) : this.selectors.replace("#", "");
|
8190 | }
|
8191 |
|
8192 | set ids(value) {
|
8193 | this.selectors = value instanceof Array ? value.map(t => `#${t}`) : `#${value}`;
|
8194 | }
|
8195 |
|
8196 | load(data) {
|
8197 | super.load(data);
|
8198 |
|
8199 | if (data === undefined) {
|
8200 | return;
|
8201 | }
|
8202 |
|
8203 | if (data.ids !== undefined) {
|
8204 | this.ids = data.ids;
|
8205 | }
|
8206 |
|
8207 | if (data.selectors !== undefined) {
|
8208 | this.selectors = data.selectors;
|
8209 | }
|
8210 | }
|
8211 |
|
8212 | }
|
8213 | ;
|
8214 |
|
8215 |
|
8216 | class Bubble extends BubbleBase {
|
8217 | load(data) {
|
8218 | super.load(data);
|
8219 |
|
8220 | if (!(data !== undefined && data.divs !== undefined)) {
|
8221 | return;
|
8222 | }
|
8223 |
|
8224 | if (data.divs instanceof Array) {
|
8225 | this.divs = data.divs.map(s => {
|
8226 | const tmp = new BubbleDiv();
|
8227 | tmp.load(s);
|
8228 | return tmp;
|
8229 | });
|
8230 | } else {
|
8231 | if (this.divs instanceof Array || !this.divs) {
|
8232 | this.divs = new BubbleDiv();
|
8233 | }
|
8234 |
|
8235 | this.divs.load(data.divs);
|
8236 | }
|
8237 | }
|
8238 |
|
8239 | }
|
8240 | ;
|
8241 | class ConnectLinks {
|
8242 | constructor() {
|
8243 | this.opacity = 0.5;
|
8244 | }
|
8245 |
|
8246 | load(data) {
|
8247 | if (!(data !== undefined && data.opacity !== undefined)) {
|
8248 | return;
|
8249 | }
|
8250 |
|
8251 | this.opacity = data.opacity;
|
8252 | }
|
8253 |
|
8254 | }
|
8255 | ;
|
8256 |
|
8257 | class Connect {
|
8258 | constructor() {
|
8259 | this.distance = 80;
|
8260 | this.links = new ConnectLinks();
|
8261 | this.radius = 60;
|
8262 | }
|
8263 |
|
8264 | get line_linked() {
|
8265 | return this.links;
|
8266 | }
|
8267 |
|
8268 | set line_linked(value) {
|
8269 | this.links = value;
|
8270 | }
|
8271 |
|
8272 | get lineLinked() {
|
8273 | return this.links;
|
8274 | }
|
8275 |
|
8276 | set lineLinked(value) {
|
8277 | this.links = value;
|
8278 | }
|
8279 |
|
8280 | load(data) {
|
8281 | var _a, _b;
|
8282 |
|
8283 | if (data === undefined) {
|
8284 | return;
|
8285 | }
|
8286 |
|
8287 | if (data.distance !== undefined) {
|
8288 | this.distance = data.distance;
|
8289 | }
|
8290 |
|
8291 | this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
|
8292 |
|
8293 | if (data.radius !== undefined) {
|
8294 | this.radius = data.radius;
|
8295 | }
|
8296 | }
|
8297 |
|
8298 | }
|
8299 | ;
|
8300 |
|
8301 | class GrabLinks {
|
8302 | constructor() {
|
8303 | this.blink = false;
|
8304 | this.consent = false;
|
8305 | this.opacity = 1;
|
8306 | }
|
8307 |
|
8308 | load(data) {
|
8309 | if (data === undefined) {
|
8310 | return;
|
8311 | }
|
8312 |
|
8313 | if (data.blink !== undefined) {
|
8314 | this.blink = data.blink;
|
8315 | }
|
8316 |
|
8317 | if (data.color !== undefined) {
|
8318 | this.color = OptionsColor.create(this.color, data.color);
|
8319 | }
|
8320 |
|
8321 | if (data.consent !== undefined) {
|
8322 | this.consent = data.consent;
|
8323 | }
|
8324 |
|
8325 | if (data.opacity !== undefined) {
|
8326 | this.opacity = data.opacity;
|
8327 | }
|
8328 | }
|
8329 |
|
8330 | }
|
8331 | ;
|
8332 |
|
8333 | class Grab {
|
8334 | constructor() {
|
8335 | this.distance = 100;
|
8336 | this.links = new GrabLinks();
|
8337 | }
|
8338 |
|
8339 | get line_linked() {
|
8340 | return this.links;
|
8341 | }
|
8342 |
|
8343 | set line_linked(value) {
|
8344 | this.links = value;
|
8345 | }
|
8346 |
|
8347 | get lineLinked() {
|
8348 | return this.links;
|
8349 | }
|
8350 |
|
8351 | set lineLinked(value) {
|
8352 | this.links = value;
|
8353 | }
|
8354 |
|
8355 | load(data) {
|
8356 | var _a, _b;
|
8357 |
|
8358 | if (data === undefined) {
|
8359 | return;
|
8360 | }
|
8361 |
|
8362 | if (data.distance !== undefined) {
|
8363 | this.distance = data.distance;
|
8364 | }
|
8365 |
|
8366 | this.links.load((_b = (_a = data.links) !== null && _a !== void 0 ? _a : data.lineLinked) !== null && _b !== void 0 ? _b : data.line_linked);
|
8367 | }
|
8368 |
|
8369 | }
|
8370 | ;
|
8371 | class Remove {
|
8372 | constructor() {
|
8373 | this.quantity = 2;
|
8374 | }
|
8375 |
|
8376 | get particles_nb() {
|
8377 | return this.quantity;
|
8378 | }
|
8379 |
|
8380 | set particles_nb(value) {
|
8381 | this.quantity = value;
|
8382 | }
|
8383 |
|
8384 | load(data) {
|
8385 | var _a;
|
8386 |
|
8387 | if (data === undefined) {
|
8388 | return;
|
8389 | }
|
8390 |
|
8391 | const quantity = (_a = data.quantity) !== null && _a !== void 0 ? _a : data.particles_nb;
|
8392 |
|
8393 | if (quantity !== undefined) {
|
8394 | this.quantity = quantity;
|
8395 | }
|
8396 | }
|
8397 |
|
8398 | }
|
8399 | ;
|
8400 | class Push {
|
8401 | constructor() {
|
8402 | this.quantity = 4;
|
8403 | }
|
8404 |
|
8405 | get particles_nb() {
|
8406 | return this.quantity;
|
8407 | }
|
8408 |
|
8409 | set particles_nb(value) {
|
8410 | this.quantity = value;
|
8411 | }
|
8412 |
|
8413 | load(data) {
|
8414 | var _a;
|
8415 |
|
8416 | if (data === undefined) {
|
8417 | return;
|
8418 | }
|
8419 |
|
8420 | const quantity = (_a = data.quantity) !== null && _a !== void 0 ? _a : data.particles_nb;
|
8421 |
|
8422 | if (quantity !== undefined) {
|
8423 | this.quantity = quantity;
|
8424 | }
|
8425 | }
|
8426 |
|
8427 | }
|
8428 | ;
|
8429 | class RepulseBase {
|
8430 | constructor() {
|
8431 | this.distance = 200;
|
8432 | this.duration = 0.4;
|
8433 | this.speed = 1;
|
8434 | }
|
8435 |
|
8436 | load(data) {
|
8437 | if (data === undefined) {
|
8438 | return;
|
8439 | }
|
8440 |
|
8441 | if (data.distance !== undefined) {
|
8442 | this.distance = data.distance;
|
8443 | }
|
8444 |
|
8445 | if (data.duration !== undefined) {
|
8446 | this.duration = data.duration;
|
8447 | }
|
8448 |
|
8449 | if (data.speed !== undefined) {
|
8450 | this.speed = data.speed;
|
8451 | }
|
8452 | }
|
8453 |
|
8454 | }
|
8455 | ;
|
8456 |
|
8457 | class RepulseDiv extends RepulseBase {
|
8458 | constructor() {
|
8459 | super();
|
8460 | this.selectors = [];
|
8461 | }
|
8462 |
|
8463 | get ids() {
|
8464 | if (this.selectors instanceof Array) {
|
8465 | return this.selectors.map(t => t.replace("#", ""));
|
8466 | } else {
|
8467 | return this.selectors.replace("#", "");
|
8468 | }
|
8469 | }
|
8470 |
|
8471 | set ids(value) {
|
8472 | if (value instanceof Array) {
|
8473 | this.selectors = value.map(() => `#${value}`);
|
8474 | } else {
|
8475 | this.selectors = `#${value}`;
|
8476 | }
|
8477 | }
|
8478 |
|
8479 | load(data) {
|
8480 | super.load(data);
|
8481 |
|
8482 | if (data === undefined) {
|
8483 | return;
|
8484 | }
|
8485 |
|
8486 | if (data.ids !== undefined) {
|
8487 | this.ids = data.ids;
|
8488 | }
|
8489 |
|
8490 | if (data.selectors !== undefined) {
|
8491 | this.selectors = data.selectors;
|
8492 | }
|
8493 | }
|
8494 |
|
8495 | }
|
8496 | ;
|
8497 |
|
8498 |
|
8499 | class Repulse extends RepulseBase {
|
8500 | load(data) {
|
8501 | super.load(data);
|
8502 |
|
8503 | if ((data === null || data === void 0 ? void 0 : data.divs) === undefined) {
|
8504 | return;
|
8505 | }
|
8506 |
|
8507 | if (data.divs instanceof Array) {
|
8508 | this.divs = data.divs.map(s => {
|
8509 | const tmp = new RepulseDiv();
|
8510 | tmp.load(s);
|
8511 | return tmp;
|
8512 | });
|
8513 | } else {
|
8514 | if (this.divs instanceof Array || !this.divs) {
|
8515 | this.divs = new RepulseDiv();
|
8516 | }
|
8517 |
|
8518 | this.divs.load(data.divs);
|
8519 | }
|
8520 | }
|
8521 |
|
8522 | }
|
8523 | ;
|
8524 | class Slow {
|
8525 | constructor() {
|
8526 | this.factor = 3;
|
8527 | this.radius = 200;
|
8528 | }
|
8529 |
|
8530 | get active() {
|
8531 | return false;
|
8532 | }
|
8533 |
|
8534 | set active(_value) {}
|
8535 |
|
8536 | load(data) {
|
8537 | if (data === undefined) {
|
8538 | return;
|
8539 | }
|
8540 |
|
8541 | if (data.factor !== undefined) {
|
8542 | this.factor = data.factor;
|
8543 | }
|
8544 |
|
8545 | if (data.radius !== undefined) {
|
8546 | this.radius = data.radius;
|
8547 | }
|
8548 | }
|
8549 |
|
8550 | }
|
8551 | ;
|
8552 |
|
8553 | class Trail_Trail {
|
8554 | constructor() {
|
8555 | this.delay = 1;
|
8556 | this.quantity = 1;
|
8557 | }
|
8558 |
|
8559 | load(data) {
|
8560 | if (data === undefined) {
|
8561 | return;
|
8562 | }
|
8563 |
|
8564 | if (data.delay !== undefined) {
|
8565 | this.delay = data.delay;
|
8566 | }
|
8567 |
|
8568 | if (data.quantity !== undefined) {
|
8569 | this.quantity = data.quantity;
|
8570 | }
|
8571 |
|
8572 | if (data.particles !== undefined) {
|
8573 | this.particles = Utils.deepExtend({}, data.particles);
|
8574 | }
|
8575 | }
|
8576 |
|
8577 | }
|
8578 | ;
|
8579 | class Attract_Attract {
|
8580 | constructor() {
|
8581 | this.distance = 200;
|
8582 | this.duration = 0.4;
|
8583 | this.speed = 1;
|
8584 | }
|
8585 |
|
8586 | load(data) {
|
8587 | if (data === undefined) {
|
8588 | return;
|
8589 | }
|
8590 |
|
8591 | if (data.distance !== undefined) {
|
8592 | this.distance = data.distance;
|
8593 | }
|
8594 |
|
8595 | if (data.duration !== undefined) {
|
8596 | this.duration = data.duration;
|
8597 | }
|
8598 |
|
8599 | if (data.speed !== undefined) {
|
8600 | this.speed = data.speed;
|
8601 | }
|
8602 | }
|
8603 |
|
8604 | }
|
8605 | ;
|
8606 |
|
8607 | class LightGradient {
|
8608 | constructor() {
|
8609 | this.start = new OptionsColor();
|
8610 | this.stop = new OptionsColor();
|
8611 | this.start.value = "#ffffff";
|
8612 | this.stop.value = "#000000";
|
8613 | }
|
8614 |
|
8615 | load(data) {
|
8616 | if (data === undefined) {
|
8617 | return;
|
8618 | }
|
8619 |
|
8620 | this.start = OptionsColor.create(this.start, data.start);
|
8621 | this.stop = OptionsColor.create(this.stop, data.stop);
|
8622 | }
|
8623 |
|
8624 | }
|
8625 | ;
|
8626 |
|
8627 | class LightArea {
|
8628 | constructor() {
|
8629 | this.gradient = new LightGradient();
|
8630 | this.radius = 1000;
|
8631 | }
|
8632 |
|
8633 | load(data) {
|
8634 | if (data === undefined) {
|
8635 | return;
|
8636 | }
|
8637 |
|
8638 | this.gradient.load(data.gradient);
|
8639 |
|
8640 | if (data.radius !== undefined) {
|
8641 | this.radius = data.radius;
|
8642 | }
|
8643 | }
|
8644 |
|
8645 | }
|
8646 | ;
|
8647 |
|
8648 | class LightShadow {
|
8649 | constructor() {
|
8650 | this.color = new OptionsColor();
|
8651 | this.color.value = "#000000";
|
8652 | this.length = 2000;
|
8653 | }
|
8654 |
|
8655 | load(data) {
|
8656 | if (data === undefined) {
|
8657 | return;
|
8658 | }
|
8659 |
|
8660 | this.color = OptionsColor.create(this.color, data.color);
|
8661 |
|
8662 | if (data.length !== undefined) {
|
8663 | this.length = data.length;
|
8664 | }
|
8665 | }
|
8666 |
|
8667 | }
|
8668 | ;
|
8669 |
|
8670 |
|
8671 | class Light {
|
8672 | constructor() {
|
8673 | this.area = new LightArea();
|
8674 | this.shadow = new LightShadow();
|
8675 | }
|
8676 |
|
8677 | load(data) {
|
8678 | if (data === undefined) {
|
8679 | return;
|
8680 | }
|
8681 |
|
8682 | this.area.load(data.area);
|
8683 | this.shadow.load(data.shadow);
|
8684 | }
|
8685 |
|
8686 | }
|
8687 | ;
|
8688 | class Bounce_Bounce {
|
8689 | constructor() {
|
8690 | this.distance = 200;
|
8691 | }
|
8692 |
|
8693 | load(data) {
|
8694 | if (!data) {
|
8695 | return;
|
8696 | }
|
8697 |
|
8698 | if (data.distance !== undefined) {
|
8699 | this.distance = data.distance;
|
8700 | }
|
8701 | }
|
8702 |
|
8703 | }
|
8704 | ;
|
8705 |
|
8706 |
|
8707 |
|
8708 |
|
8709 |
|
8710 |
|
8711 |
|
8712 |
|
8713 |
|
8714 |
|
8715 |
|
8716 | class Modes {
|
8717 | constructor() {
|
8718 | this.attract = new Attract_Attract();
|
8719 | this.bounce = new Bounce_Bounce();
|
8720 | this.bubble = new Bubble();
|
8721 | this.connect = new Connect();
|
8722 | this.grab = new Grab();
|
8723 | this.light = new Light();
|
8724 | this.push = new Push();
|
8725 | this.remove = new Remove();
|
8726 | this.repulse = new Repulse();
|
8727 | this.slow = new Slow();
|
8728 | this.trail = new Trail_Trail();
|
8729 | }
|
8730 |
|
8731 | load(data) {
|
8732 | if (data === undefined) {
|
8733 | return;
|
8734 | }
|
8735 |
|
8736 | this.attract.load(data.attract);
|
8737 | this.bubble.load(data.bubble);
|
8738 | this.connect.load(data.connect);
|
8739 | this.grab.load(data.grab);
|
8740 | this.light.load(data.light);
|
8741 | this.push.load(data.push);
|
8742 | this.remove.load(data.remove);
|
8743 | this.repulse.load(data.repulse);
|
8744 | this.slow.load(data.slow);
|
8745 | this.trail.load(data.trail);
|
8746 | }
|
8747 |
|
8748 | }
|
8749 | ;
|
8750 |
|
8751 |
|
8752 |
|
8753 | class Interactivity {
|
8754 | constructor() {
|
8755 | this.detectsOn = InteractivityDetect.canvas;
|
8756 | this.events = new Events();
|
8757 | this.modes = new Modes();
|
8758 | }
|
8759 |
|
8760 | get detect_on() {
|
8761 | return this.detectsOn;
|
8762 | }
|
8763 |
|
8764 | set detect_on(value) {
|
8765 | this.detectsOn = value;
|
8766 | }
|
8767 |
|
8768 | load(data) {
|
8769 | var _a, _b, _c;
|
8770 |
|
8771 | if (data === undefined) {
|
8772 | return;
|
8773 | }
|
8774 |
|
8775 | const detectsOn = (_a = data.detectsOn) !== null && _a !== void 0 ? _a : data.detect_on;
|
8776 |
|
8777 | if (detectsOn !== undefined) {
|
8778 | this.detectsOn = detectsOn;
|
8779 | }
|
8780 |
|
8781 | this.events.load(data.events);
|
8782 | this.modes.load(data.modes);
|
8783 |
|
8784 | if (((_c = (_b = data.modes) === null || _b === void 0 ? void 0 : _b.slow) === null || _c === void 0 ? void 0 : _c.active) === true) {
|
8785 | if (this.events.onHover.mode instanceof Array) {
|
8786 | if (this.events.onHover.mode.indexOf(HoverMode.slow) < 0) {
|
8787 | this.events.onHover.mode.push(HoverMode.slow);
|
8788 | }
|
8789 | } else if (this.events.onHover.mode !== HoverMode.slow) {
|
8790 | this.events.onHover.mode = [this.events.onHover.mode, HoverMode.slow];
|
8791 | }
|
8792 | }
|
8793 | }
|
8794 |
|
8795 | }
|
8796 | ;
|
8797 |
|
8798 | class BackgroundMaskCover {
|
8799 | constructor() {
|
8800 | this.color = new OptionsColor();
|
8801 | this.opacity = 1;
|
8802 | }
|
8803 |
|
8804 | load(data) {
|
8805 | if (data === undefined) {
|
8806 | return;
|
8807 | }
|
8808 |
|
8809 | if (data.color !== undefined) {
|
8810 | this.color = OptionsColor.create(this.color, data.color);
|
8811 | }
|
8812 |
|
8813 | if (data.opacity !== undefined) {
|
8814 | this.opacity = data.opacity;
|
8815 | }
|
8816 | }
|
8817 |
|
8818 | }
|
8819 | ;
|
8820 |
|
8821 | class BackgroundMask {
|
8822 | constructor() {
|
8823 | this.composite = "destination-out";
|
8824 | this.cover = new BackgroundMaskCover();
|
8825 | this.enable = false;
|
8826 | }
|
8827 |
|
8828 | load(data) {
|
8829 | if (data === undefined) {
|
8830 | return;
|
8831 | }
|
8832 |
|
8833 | if (data.composite !== undefined) {
|
8834 | this.composite = data.composite;
|
8835 | }
|
8836 |
|
8837 | if (data.cover !== undefined) {
|
8838 | const cover = data.cover;
|
8839 | const color = typeof data.cover === "string" ? {
|
8840 | color: data.cover
|
8841 | } : data.cover;
|
8842 | this.cover.load(cover.color !== undefined ? cover : {
|
8843 | color: color
|
8844 | });
|
8845 | }
|
8846 |
|
8847 | if (data.enable !== undefined) {
|
8848 | this.enable = data.enable;
|
8849 | }
|
8850 | }
|
8851 |
|
8852 | }
|
8853 | ;
|
8854 |
|
8855 | class Background {
|
8856 | constructor() {
|
8857 | this.color = new OptionsColor();
|
8858 | this.color.value = "";
|
8859 | this.image = "";
|
8860 | this.position = "";
|
8861 | this.repeat = "";
|
8862 | this.size = "";
|
8863 | this.opacity = 1;
|
8864 | }
|
8865 |
|
8866 | load(data) {
|
8867 | if (data === undefined) {
|
8868 | return;
|
8869 | }
|
8870 |
|
8871 | if (data.color !== undefined) {
|
8872 | this.color = OptionsColor.create(this.color, data.color);
|
8873 | }
|
8874 |
|
8875 | if (data.image !== undefined) {
|
8876 | this.image = data.image;
|
8877 | }
|
8878 |
|
8879 | if (data.position !== undefined) {
|
8880 | this.position = data.position;
|
8881 | }
|
8882 |
|
8883 | if (data.repeat !== undefined) {
|
8884 | this.repeat = data.repeat;
|
8885 | }
|
8886 |
|
8887 | if (data.size !== undefined) {
|
8888 | this.size = data.size;
|
8889 | }
|
8890 |
|
8891 | if (data.opacity !== undefined) {
|
8892 | this.opacity = data.opacity;
|
8893 | }
|
8894 | }
|
8895 |
|
8896 | }
|
8897 | ;
|
8898 |
|
8899 | class InfectionStage {
|
8900 | constructor() {
|
8901 | this.color = new OptionsColor();
|
8902 | this.color.value = "#ff0000";
|
8903 | this.radius = 0;
|
8904 | this.rate = 1;
|
8905 | }
|
8906 |
|
8907 | load(data) {
|
8908 | if (data === undefined) {
|
8909 | return;
|
8910 | }
|
8911 |
|
8912 | if (data.color !== undefined) {
|
8913 | this.color = OptionsColor.create(this.color, data.color);
|
8914 | }
|
8915 |
|
8916 | this.duration = data.duration;
|
8917 | this.infectedStage = data.infectedStage;
|
8918 |
|
8919 | if (data.radius !== undefined) {
|
8920 | this.radius = data.radius;
|
8921 | }
|
8922 |
|
8923 | if (data.rate !== undefined) {
|
8924 | this.rate = data.rate;
|
8925 | }
|
8926 | }
|
8927 |
|
8928 | }
|
8929 | ;
|
8930 |
|
8931 | class Infection {
|
8932 | constructor() {
|
8933 | this.cure = false;
|
8934 | this.delay = 0;
|
8935 | this.enable = false;
|
8936 | this.infections = 0;
|
8937 | this.stages = [];
|
8938 | }
|
8939 |
|
8940 | load(data) {
|
8941 | if (data === undefined) {
|
8942 | return;
|
8943 | }
|
8944 |
|
8945 | if (data.cure !== undefined) {
|
8946 | this.cure = data.cure;
|
8947 | }
|
8948 |
|
8949 | if (data.delay !== undefined) {
|
8950 | this.delay = data.delay;
|
8951 | }
|
8952 |
|
8953 | if (data.enable !== undefined) {
|
8954 | this.enable = data.enable;
|
8955 | }
|
8956 |
|
8957 | if (data.infections !== undefined) {
|
8958 | this.infections = data.infections;
|
8959 | }
|
8960 |
|
8961 | if (data.stages === undefined) {
|
8962 | return;
|
8963 | }
|
8964 |
|
8965 | this.stages = data.stages.map(t => {
|
8966 | const s = new InfectionStage();
|
8967 | s.load(t);
|
8968 | return s;
|
8969 | });
|
8970 | }
|
8971 |
|
8972 | }
|
8973 | ;
|
8974 |
|
8975 | class ThemeDefault {
|
8976 | constructor() {
|
8977 | this.mode = ThemeMode.any;
|
8978 | this.value = false;
|
8979 | }
|
8980 |
|
8981 | load(data) {
|
8982 | if (data === undefined) {
|
8983 | return;
|
8984 | }
|
8985 |
|
8986 | if (data.mode !== undefined) {
|
8987 | this.mode = data.mode;
|
8988 | }
|
8989 |
|
8990 | if (data.value !== undefined) {
|
8991 | this.value = data.value;
|
8992 | }
|
8993 | }
|
8994 |
|
8995 | }
|
8996 | ;
|
8997 |
|
8998 |
|
8999 | class Theme {
|
9000 | constructor() {
|
9001 | this.name = "";
|
9002 | this.default = new ThemeDefault();
|
9003 | }
|
9004 |
|
9005 | load(data) {
|
9006 | if (data === undefined) {
|
9007 | return;
|
9008 | }
|
9009 |
|
9010 | if (data.name !== undefined) {
|
9011 | this.name = data.name;
|
9012 | }
|
9013 |
|
9014 | this.default.load(data.default);
|
9015 |
|
9016 | if (data.options !== undefined) {
|
9017 | this.options = Utils.deepExtend({}, data.options);
|
9018 | }
|
9019 | }
|
9020 |
|
9021 | }
|
9022 | ;
|
9023 | class FullScreen {
|
9024 | constructor() {
|
9025 | this.enable = false;
|
9026 | this.zIndex = -1;
|
9027 | }
|
9028 |
|
9029 | load(data) {
|
9030 | if (!data) {
|
9031 | return;
|
9032 | }
|
9033 |
|
9034 | if (data.enable !== undefined) {
|
9035 | this.enable = data.enable;
|
9036 | }
|
9037 |
|
9038 | if (data.zIndex !== undefined) {
|
9039 | this.zIndex = data.zIndex;
|
9040 | }
|
9041 | }
|
9042 |
|
9043 | }
|
9044 | ;
|
9045 | class MotionReduce {
|
9046 | constructor() {
|
9047 | this.factor = 4;
|
9048 | this.value = true;
|
9049 | }
|
9050 |
|
9051 | load(data) {
|
9052 | if (!data) {
|
9053 | return;
|
9054 | }
|
9055 |
|
9056 | if (data.factor !== undefined) {
|
9057 | this.factor = data.factor;
|
9058 | }
|
9059 |
|
9060 | if (data.value !== undefined) {
|
9061 | this.value = data.value;
|
9062 | }
|
9063 | }
|
9064 |
|
9065 | }
|
9066 | ;
|
9067 |
|
9068 | class Motion {
|
9069 | constructor() {
|
9070 | this.disable = false;
|
9071 | this.reduce = new MotionReduce();
|
9072 | }
|
9073 |
|
9074 | load(data) {
|
9075 | if (!data) {
|
9076 | return;
|
9077 | }
|
9078 |
|
9079 | if (data.disable !== undefined) {
|
9080 | this.disable = data.disable;
|
9081 | }
|
9082 |
|
9083 | this.reduce.load(data.reduce);
|
9084 | }
|
9085 |
|
9086 | }
|
9087 | ;
|
9088 |
|
9089 | class ManualParticle {
|
9090 | load(data) {
|
9091 | var _a, _b;
|
9092 |
|
9093 | if (!data) {
|
9094 | return;
|
9095 | }
|
9096 |
|
9097 | if (data.position !== undefined) {
|
9098 | this.position = {
|
9099 | x: (_a = data.position.x) !== null && _a !== void 0 ? _a : 50,
|
9100 | y: (_b = data.position.y) !== null && _b !== void 0 ? _b : 50
|
9101 | };
|
9102 | }
|
9103 |
|
9104 | if (data.options !== undefined) {
|
9105 | this.options = Utils.deepExtend({}, data.options);
|
9106 | }
|
9107 | }
|
9108 |
|
9109 | }
|
9110 | ;
|
9111 |
|
9112 | class Responsive {
|
9113 | constructor() {
|
9114 | this.maxWidth = Infinity;
|
9115 | this.options = {};
|
9116 | }
|
9117 |
|
9118 | load(data) {
|
9119 | if (!data) {
|
9120 | return;
|
9121 | }
|
9122 |
|
9123 | if (data.maxWidth !== undefined) {
|
9124 | this.maxWidth = data.maxWidth;
|
9125 | }
|
9126 |
|
9127 | if (data.options !== undefined) {
|
9128 | this.options = Utils.deepExtend({}, data.options);
|
9129 | }
|
9130 | }
|
9131 |
|
9132 | }
|
9133 | ;
|
9134 |
|
9135 |
|
9136 |
|
9137 |
|
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 |
|
9144 |
|
9145 |
|
9146 | class Options {
|
9147 | constructor() {
|
9148 | this.autoPlay = true;
|
9149 | this.background = new Background();
|
9150 | this.backgroundMask = new BackgroundMask();
|
9151 | this.fullScreen = new FullScreen();
|
9152 | this.detectRetina = true;
|
9153 | this.fpsLimit = 60;
|
9154 | this.infection = new Infection();
|
9155 | this.interactivity = new Interactivity();
|
9156 | this.manualParticles = [];
|
9157 | this.motion = new Motion();
|
9158 | this.particles = new ParticlesOptions();
|
9159 | this.pauseOnBlur = true;
|
9160 | this.pauseOnOutsideViewport = true;
|
9161 | this.responsive = [];
|
9162 | this.themes = [];
|
9163 | }
|
9164 |
|
9165 | get fps_limit() {
|
9166 | return this.fpsLimit;
|
9167 | }
|
9168 |
|
9169 | set fps_limit(value) {
|
9170 | this.fpsLimit = value;
|
9171 | }
|
9172 |
|
9173 | get retina_detect() {
|
9174 | return this.detectRetina;
|
9175 | }
|
9176 |
|
9177 | set retina_detect(value) {
|
9178 | this.detectRetina = value;
|
9179 | }
|
9180 |
|
9181 | get backgroundMode() {
|
9182 | return this.fullScreen;
|
9183 | }
|
9184 |
|
9185 | set backgroundMode(value) {
|
9186 | this.fullScreen.load(value);
|
9187 | }
|
9188 |
|
9189 | load(data) {
|
9190 | var _a, _b, _c;
|
9191 |
|
9192 | if (data === undefined) {
|
9193 | return;
|
9194 | }
|
9195 |
|
9196 | if (data.preset !== undefined) {
|
9197 | if (data.preset instanceof Array) {
|
9198 | for (const preset of data.preset) {
|
9199 | this.importPreset(preset);
|
9200 | }
|
9201 | } else {
|
9202 | this.importPreset(data.preset);
|
9203 | }
|
9204 | }
|
9205 |
|
9206 | if (data.autoPlay !== undefined) {
|
9207 | this.autoPlay = data.autoPlay;
|
9208 | }
|
9209 |
|
9210 | const detectRetina = (_a = data.detectRetina) !== null && _a !== void 0 ? _a : data.retina_detect;
|
9211 |
|
9212 | if (detectRetina !== undefined) {
|
9213 | this.detectRetina = detectRetina;
|
9214 | }
|
9215 |
|
9216 | const fpsLimit = (_b = data.fpsLimit) !== null && _b !== void 0 ? _b : data.fps_limit;
|
9217 |
|
9218 | if (fpsLimit !== undefined) {
|
9219 | this.fpsLimit = fpsLimit;
|
9220 | }
|
9221 |
|
9222 | if (data.pauseOnBlur !== undefined) {
|
9223 | this.pauseOnBlur = data.pauseOnBlur;
|
9224 | }
|
9225 |
|
9226 | if (data.pauseOnOutsideViewport !== undefined) {
|
9227 | this.pauseOnOutsideViewport = data.pauseOnOutsideViewport;
|
9228 | }
|
9229 |
|
9230 | this.background.load(data.background);
|
9231 | this.fullScreen.load((_c = data.fullScreen) !== null && _c !== void 0 ? _c : data.backgroundMode);
|
9232 | this.backgroundMask.load(data.backgroundMask);
|
9233 | this.infection.load(data.infection);
|
9234 | this.interactivity.load(data.interactivity);
|
9235 |
|
9236 | if (data.manualParticles !== undefined) {
|
9237 | this.manualParticles = data.manualParticles.map(t => {
|
9238 | const tmp = new ManualParticle();
|
9239 | tmp.load(t);
|
9240 | return tmp;
|
9241 | });
|
9242 | }
|
9243 |
|
9244 | this.motion.load(data.motion);
|
9245 | this.particles.load(data.particles);
|
9246 | Plugins.loadOptions(this, data);
|
9247 |
|
9248 | if (data.responsive !== undefined) {
|
9249 | for (const responsive of data.responsive) {
|
9250 | const optResponsive = new Responsive();
|
9251 | optResponsive.load(responsive);
|
9252 | this.responsive.push(optResponsive);
|
9253 | }
|
9254 | }
|
9255 |
|
9256 | this.responsive.sort((a, b) => a.maxWidth - b.maxWidth);
|
9257 |
|
9258 | if (data.themes !== undefined) {
|
9259 | for (const theme of data.themes) {
|
9260 | const optTheme = new Theme();
|
9261 | optTheme.load(theme);
|
9262 | this.themes.push(optTheme);
|
9263 | }
|
9264 | }
|
9265 | }
|
9266 |
|
9267 | setTheme(name) {
|
9268 | if (name) {
|
9269 | const chosenTheme = this.themes.find(theme => theme.name === name);
|
9270 |
|
9271 | if (chosenTheme) {
|
9272 | this.load(chosenTheme.options);
|
9273 | }
|
9274 | } else {
|
9275 | const clientDarkMode = typeof matchMedia !== "undefined" && matchMedia("(prefers-color-scheme: dark)").matches;
|
9276 | let defaultTheme = this.themes.find(theme => theme.default.value && (theme.default.mode === ThemeMode.dark && clientDarkMode || theme.default.mode === ThemeMode.light && !clientDarkMode));
|
9277 |
|
9278 | if (!defaultTheme) {
|
9279 | defaultTheme = this.themes.find(theme => theme.default.value && theme.default.mode === ThemeMode.any);
|
9280 | }
|
9281 |
|
9282 | if (defaultTheme) {
|
9283 | this.load(defaultTheme.options);
|
9284 | }
|
9285 | }
|
9286 | }
|
9287 |
|
9288 | importPreset(preset) {
|
9289 | this.load(Plugins.getPreset(preset));
|
9290 | }
|
9291 |
|
9292 | setResponsive(width, pxRatio, defaultOptions) {
|
9293 | var _a;
|
9294 |
|
9295 | this.load(defaultOptions);
|
9296 | this.load((_a = this.responsive.find(t => t.maxWidth * pxRatio > width)) === null || _a === void 0 ? void 0 : _a.options);
|
9297 | }
|
9298 |
|
9299 | }
|
9300 | ;
|
9301 | var Container_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
9302 | function adopt(value) {
|
9303 | return value instanceof P ? value : new P(function (resolve) {
|
9304 | resolve(value);
|
9305 | });
|
9306 | }
|
9307 |
|
9308 | return new (P || (P = Promise))(function (resolve, reject) {
|
9309 | function fulfilled(value) {
|
9310 | try {
|
9311 | step(generator.next(value));
|
9312 | } catch (e) {
|
9313 | reject(e);
|
9314 | }
|
9315 | }
|
9316 |
|
9317 | function rejected(value) {
|
9318 | try {
|
9319 | step(generator["throw"](value));
|
9320 | } catch (e) {
|
9321 | reject(e);
|
9322 | }
|
9323 | }
|
9324 |
|
9325 | function step(result) {
|
9326 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
9327 | }
|
9328 |
|
9329 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9330 | });
|
9331 | };
|
9332 |
|
9333 |
|
9334 |
|
9335 |
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 | class Container {
|
9341 | constructor(id, sourceOptions, ...presets) {
|
9342 | this.id = id;
|
9343 | this.fpsLimit = 60;
|
9344 | this.firstStart = true;
|
9345 | this.started = false;
|
9346 | this.destroyed = false;
|
9347 | this.paused = true;
|
9348 | this.lastFrameTime = 0;
|
9349 | this.pageHidden = false;
|
9350 | this._sourceOptions = sourceOptions;
|
9351 | this.retina = new Retina(this);
|
9352 | this.canvas = new Canvas(this);
|
9353 | this.particles = new Particles(this);
|
9354 | this.drawer = new FrameManager(this);
|
9355 | this.pathGenerator = {
|
9356 | generate: () => {
|
9357 | const v = Vector.create(0, 0);
|
9358 | v.length = Math.random();
|
9359 | v.angle = Math.random() * Math.PI * 2;
|
9360 | return v;
|
9361 | },
|
9362 | init: () => {},
|
9363 | update: () => {}
|
9364 | };
|
9365 | this.interactivity = {
|
9366 | mouse: {
|
9367 | clicking: false,
|
9368 | inside: false
|
9369 | }
|
9370 | };
|
9371 | this.bubble = {};
|
9372 | this.repulse = {
|
9373 | particles: []
|
9374 | };
|
9375 | this.attract = {
|
9376 | particles: []
|
9377 | };
|
9378 | this.plugins = new Map();
|
9379 | this.drawers = new Map();
|
9380 | this.density = 1;
|
9381 | this._options = new Options();
|
9382 | this.actualOptions = new Options();
|
9383 |
|
9384 | for (const preset of presets) {
|
9385 | this._options.load(Plugins.getPreset(preset));
|
9386 | }
|
9387 |
|
9388 | const shapes = Plugins.getSupportedShapes();
|
9389 |
|
9390 | for (const type of shapes) {
|
9391 | const drawer = Plugins.getShapeDrawer(type);
|
9392 |
|
9393 | if (drawer) {
|
9394 | this.drawers.set(type, drawer);
|
9395 | }
|
9396 | }
|
9397 |
|
9398 | if (this._options) {
|
9399 | this._options.load(this._sourceOptions);
|
9400 | }
|
9401 |
|
9402 | this.eventListeners = new EventListeners(this);
|
9403 |
|
9404 | if (typeof IntersectionObserver !== "undefined" && IntersectionObserver) {
|
9405 | this.intersectionObserver = new IntersectionObserver(entries => this.intersectionManager(entries));
|
9406 | }
|
9407 | }
|
9408 |
|
9409 | get options() {
|
9410 | return this._options;
|
9411 | }
|
9412 |
|
9413 | get sourceOptions() {
|
9414 | return this._sourceOptions;
|
9415 | }
|
9416 |
|
9417 | play(force) {
|
9418 | const needsUpdate = this.paused || force;
|
9419 |
|
9420 | if (this.firstStart && !this.actualOptions.autoPlay) {
|
9421 | this.firstStart = false;
|
9422 | return;
|
9423 | }
|
9424 |
|
9425 | if (this.paused) {
|
9426 | this.paused = false;
|
9427 | }
|
9428 |
|
9429 | if (needsUpdate) {
|
9430 | for (const [, plugin] of this.plugins) {
|
9431 | if (plugin.play) {
|
9432 | plugin.play();
|
9433 | }
|
9434 | }
|
9435 |
|
9436 | this.lastFrameTime = performance.now();
|
9437 | }
|
9438 |
|
9439 | this.draw();
|
9440 | }
|
9441 |
|
9442 | pause() {
|
9443 | if (this.drawAnimationFrame !== undefined) {
|
9444 | Utils.cancelAnimation(this.drawAnimationFrame);
|
9445 | delete this.drawAnimationFrame;
|
9446 | }
|
9447 |
|
9448 | if (this.paused) {
|
9449 | return;
|
9450 | }
|
9451 |
|
9452 | for (const [, plugin] of this.plugins) {
|
9453 | if (plugin.pause) {
|
9454 | plugin.pause();
|
9455 | }
|
9456 | }
|
9457 |
|
9458 | if (!this.pageHidden) {
|
9459 | this.paused = true;
|
9460 | }
|
9461 | }
|
9462 |
|
9463 | draw() {
|
9464 | this.drawAnimationFrame = Utils.animate(timestamp => this.drawer.nextFrame(timestamp));
|
9465 | }
|
9466 |
|
9467 | getAnimationStatus() {
|
9468 | return !this.paused;
|
9469 | }
|
9470 |
|
9471 | setNoise(noiseOrGenerator, init, update) {
|
9472 | this.setPath(noiseOrGenerator, init, update);
|
9473 | }
|
9474 |
|
9475 | setPath(pathOrGenerator, init, update) {
|
9476 | if (!pathOrGenerator) {
|
9477 | return;
|
9478 | }
|
9479 |
|
9480 | if (typeof pathOrGenerator === "function") {
|
9481 | this.pathGenerator.generate = pathOrGenerator;
|
9482 |
|
9483 | if (init) {
|
9484 | this.pathGenerator.init = init;
|
9485 | }
|
9486 |
|
9487 | if (update) {
|
9488 | this.pathGenerator.update = update;
|
9489 | }
|
9490 | } else {
|
9491 | if (pathOrGenerator.generate) {
|
9492 | this.pathGenerator.generate = pathOrGenerator.generate;
|
9493 | }
|
9494 |
|
9495 | if (pathOrGenerator.init) {
|
9496 | this.pathGenerator.init = pathOrGenerator.init;
|
9497 | }
|
9498 |
|
9499 | if (pathOrGenerator.update) {
|
9500 | this.pathGenerator.update = pathOrGenerator.update;
|
9501 | }
|
9502 | }
|
9503 | }
|
9504 |
|
9505 | destroy() {
|
9506 | this.stop();
|
9507 | this.canvas.destroy();
|
9508 |
|
9509 | for (const [, drawer] of this.drawers) {
|
9510 | if (drawer.destroy) {
|
9511 | drawer.destroy(this);
|
9512 | }
|
9513 | }
|
9514 |
|
9515 | for (const key of this.drawers.keys()) {
|
9516 | this.drawers.delete(key);
|
9517 | }
|
9518 |
|
9519 | this.destroyed = true;
|
9520 | }
|
9521 |
|
9522 | exportImg(callback) {
|
9523 | this.exportImage(callback);
|
9524 | }
|
9525 |
|
9526 | exportImage(callback, type, quality) {
|
9527 | var _a;
|
9528 |
|
9529 | return (_a = this.canvas.element) === null || _a === void 0 ? void 0 : _a.toBlob(callback, type !== null && type !== void 0 ? type : "image/png", quality);
|
9530 | }
|
9531 |
|
9532 | exportConfiguration() {
|
9533 | return JSON.stringify(this.actualOptions, undefined, 2);
|
9534 | }
|
9535 |
|
9536 | refresh() {
|
9537 | this.stop();
|
9538 | return this.start();
|
9539 | }
|
9540 |
|
9541 | reset() {
|
9542 | this._options = new Options();
|
9543 | return this.refresh();
|
9544 | }
|
9545 |
|
9546 | stop() {
|
9547 | if (!this.started) {
|
9548 | return;
|
9549 | }
|
9550 |
|
9551 | this.firstStart = true;
|
9552 | this.started = false;
|
9553 | this.eventListeners.removeListeners();
|
9554 | this.pause();
|
9555 | this.particles.clear();
|
9556 | this.canvas.clear();
|
9557 |
|
9558 | if (this.interactivity.element instanceof HTMLElement && this.intersectionObserver) {
|
9559 | this.intersectionObserver.observe(this.interactivity.element);
|
9560 | }
|
9561 |
|
9562 | for (const [, plugin] of this.plugins) {
|
9563 | if (plugin.stop) {
|
9564 | plugin.stop();
|
9565 | }
|
9566 | }
|
9567 |
|
9568 | for (const key of this.plugins.keys()) {
|
9569 | this.plugins.delete(key);
|
9570 | }
|
9571 |
|
9572 | this.particles.linksColors = new Map();
|
9573 | delete this.particles.grabLineColor;
|
9574 | delete this.particles.linksColor;
|
9575 | }
|
9576 |
|
9577 | loadTheme(name) {
|
9578 | return Container_awaiter(this, void 0, void 0, function* () {
|
9579 | this.actualOptions.setTheme(name);
|
9580 | yield this.refresh();
|
9581 | });
|
9582 | }
|
9583 |
|
9584 | start() {
|
9585 | return Container_awaiter(this, void 0, void 0, function* () {
|
9586 | if (this.started) {
|
9587 | return;
|
9588 | }
|
9589 |
|
9590 | yield this.init();
|
9591 | this.started = true;
|
9592 | this.eventListeners.addListeners();
|
9593 |
|
9594 | if (this.interactivity.element instanceof HTMLElement && this.intersectionObserver) {
|
9595 | this.intersectionObserver.observe(this.interactivity.element);
|
9596 | }
|
9597 |
|
9598 | for (const [, plugin] of this.plugins) {
|
9599 | if (plugin.startAsync !== undefined) {
|
9600 | yield plugin.startAsync();
|
9601 | } else if (plugin.start !== undefined) {
|
9602 | plugin.start();
|
9603 | }
|
9604 | }
|
9605 |
|
9606 | this.play();
|
9607 | });
|
9608 | }
|
9609 |
|
9610 | init() {
|
9611 | return Container_awaiter(this, void 0, void 0, function* () {
|
9612 | this.actualOptions = new Options();
|
9613 | this.actualOptions.load(this._options);
|
9614 | this.retina.init();
|
9615 | this.canvas.init();
|
9616 | this.actualOptions.setResponsive(this.canvas.size.width, this.retina.pixelRatio, this._options);
|
9617 | this.actualOptions.setTheme(undefined);
|
9618 | this.fpsLimit = this.actualOptions.fpsLimit > 0 ? this.actualOptions.fpsLimit : 60;
|
9619 | const availablePlugins = Plugins.getAvailablePlugins(this);
|
9620 |
|
9621 | for (const [id, plugin] of availablePlugins) {
|
9622 | this.plugins.set(id, plugin);
|
9623 | }
|
9624 |
|
9625 | for (const [, drawer] of this.drawers) {
|
9626 | if (drawer.init) {
|
9627 | yield drawer.init(this);
|
9628 | }
|
9629 | }
|
9630 |
|
9631 | for (const [, plugin] of this.plugins) {
|
9632 | if (plugin.init) {
|
9633 | plugin.init(this.actualOptions);
|
9634 | } else if (plugin.initAsync !== undefined) {
|
9635 | yield plugin.initAsync(this.actualOptions);
|
9636 | }
|
9637 | }
|
9638 |
|
9639 | this.canvas.resize();
|
9640 | this.particles.init();
|
9641 | this.particles.setDensity();
|
9642 | });
|
9643 | }
|
9644 |
|
9645 | intersectionManager(entries) {
|
9646 | if (!this.actualOptions.pauseOnOutsideViewport) {
|
9647 | return;
|
9648 | }
|
9649 |
|
9650 | for (const entry of entries) {
|
9651 | if (entry.target !== this.interactivity.element) {
|
9652 | continue;
|
9653 | }
|
9654 |
|
9655 | if (entry.isIntersecting) {
|
9656 | this.play();
|
9657 | } else {
|
9658 | this.pause();
|
9659 | }
|
9660 | }
|
9661 | }
|
9662 |
|
9663 | }
|
9664 | ;
|
9665 | var Loader_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
9666 | function adopt(value) {
|
9667 | return value instanceof P ? value : new P(function (resolve) {
|
9668 | resolve(value);
|
9669 | });
|
9670 | }
|
9671 |
|
9672 | return new (P || (P = Promise))(function (resolve, reject) {
|
9673 | function fulfilled(value) {
|
9674 | try {
|
9675 | step(generator.next(value));
|
9676 | } catch (e) {
|
9677 | reject(e);
|
9678 | }
|
9679 | }
|
9680 |
|
9681 | function rejected(value) {
|
9682 | try {
|
9683 | step(generator["throw"](value));
|
9684 | } catch (e) {
|
9685 | reject(e);
|
9686 | }
|
9687 | }
|
9688 |
|
9689 | function step(result) {
|
9690 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
9691 | }
|
9692 |
|
9693 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9694 | });
|
9695 | };
|
9696 |
|
9697 |
|
9698 |
|
9699 | const tsParticlesDom = [];
|
9700 |
|
9701 | function fetchError(statusCode) {
|
9702 | console.error(`Error tsParticles - fetch status: ${statusCode}`);
|
9703 | console.error("Error tsParticles - File config not found");
|
9704 | }
|
9705 |
|
9706 | class Loader {
|
9707 | static dom() {
|
9708 | return tsParticlesDom;
|
9709 | }
|
9710 |
|
9711 | static domItem(index) {
|
9712 | const dom = Loader.dom();
|
9713 | const item = dom[index];
|
9714 |
|
9715 | if (item && !item.destroyed) {
|
9716 | return item;
|
9717 | }
|
9718 |
|
9719 | dom.splice(index, 1);
|
9720 | }
|
9721 |
|
9722 | static load(tagId, options, index) {
|
9723 | return Loader_awaiter(this, void 0, void 0, function* () {
|
9724 | const domContainer = document.getElementById(tagId);
|
9725 |
|
9726 | if (!domContainer) {
|
9727 | return;
|
9728 | }
|
9729 |
|
9730 | return Loader.set(tagId, domContainer, options, index);
|
9731 | });
|
9732 | }
|
9733 |
|
9734 | static set(id, domContainer, options, index) {
|
9735 | return Loader_awaiter(this, void 0, void 0, function* () {
|
9736 | const currentOptions = options instanceof Array ? Utils.itemFromArray(options, index) : options;
|
9737 | const dom = Loader.dom();
|
9738 | const oldIndex = dom.findIndex(v => v.id === id);
|
9739 |
|
9740 | if (oldIndex >= 0) {
|
9741 | const old = Loader.domItem(oldIndex);
|
9742 |
|
9743 | if (old && !old.destroyed) {
|
9744 | old.destroy();
|
9745 | dom.splice(oldIndex, 1);
|
9746 | }
|
9747 | }
|
9748 |
|
9749 | let canvasEl;
|
9750 | let generatedCanvas;
|
9751 |
|
9752 | if (domContainer.tagName.toLowerCase() === "canvas") {
|
9753 | canvasEl = domContainer;
|
9754 | generatedCanvas = false;
|
9755 | } else {
|
9756 | const existingCanvases = domContainer.getElementsByTagName("canvas");
|
9757 |
|
9758 | if (existingCanvases.length) {
|
9759 | canvasEl = existingCanvases[0];
|
9760 |
|
9761 | if (!canvasEl.className) {
|
9762 | canvasEl.className = Constants.canvasClass;
|
9763 | }
|
9764 |
|
9765 | generatedCanvas = false;
|
9766 | } else {
|
9767 | generatedCanvas = true;
|
9768 | canvasEl = document.createElement("canvas");
|
9769 | canvasEl.className = Constants.canvasClass;
|
9770 | canvasEl.style.width = "100%";
|
9771 | canvasEl.style.height = "100%";
|
9772 | domContainer.appendChild(canvasEl);
|
9773 | }
|
9774 | }
|
9775 |
|
9776 | const newItem = new Container(id, currentOptions);
|
9777 |
|
9778 | if (oldIndex >= 0) {
|
9779 | dom.splice(oldIndex, 0, newItem);
|
9780 | } else {
|
9781 | dom.push(newItem);
|
9782 | }
|
9783 |
|
9784 | newItem.canvas.loadCanvas(canvasEl, generatedCanvas);
|
9785 | yield newItem.start();
|
9786 | return newItem;
|
9787 | });
|
9788 | }
|
9789 |
|
9790 | static loadJSON(tagId, jsonUrl, index) {
|
9791 | return Loader_awaiter(this, void 0, void 0, function* () {
|
9792 | const url = jsonUrl instanceof Array ? Utils.itemFromArray(jsonUrl, index) : jsonUrl;
|
9793 | const response = yield fetch(url);
|
9794 |
|
9795 | if (response.ok) {
|
9796 | return Loader.load(tagId, yield response.json());
|
9797 | } else {
|
9798 | fetchError(response.status);
|
9799 | }
|
9800 | });
|
9801 | }
|
9802 |
|
9803 | static setJSON(id, domContainer, jsonUrl) {
|
9804 | return Loader_awaiter(this, void 0, void 0, function* () {
|
9805 | const response = yield fetch(jsonUrl);
|
9806 |
|
9807 | if (response.ok) {
|
9808 | const options = yield response.json();
|
9809 | return Loader.set(id, domContainer, options);
|
9810 | } else {
|
9811 | fetchError(response.status);
|
9812 | }
|
9813 | });
|
9814 | }
|
9815 |
|
9816 | static setOnClickHandler(callback) {
|
9817 | const dom = Loader.dom();
|
9818 |
|
9819 | if (dom.length === 0) {
|
9820 | throw new Error("Can only set click handlers after calling tsParticles.load() or tsParticles.loadJSON()");
|
9821 | }
|
9822 |
|
9823 | for (const domItem of dom) {
|
9824 | const el = domItem.interactivity.element;
|
9825 |
|
9826 | if (!el) {
|
9827 | continue;
|
9828 | }
|
9829 |
|
9830 | const clickOrTouchHandler = (e, pos) => {
|
9831 | if (domItem.destroyed) {
|
9832 | return;
|
9833 | }
|
9834 |
|
9835 | const pxRatio = domItem.retina.pixelRatio;
|
9836 | const posRetina = {
|
9837 | x: pos.x * pxRatio,
|
9838 | y: pos.y * pxRatio
|
9839 | };
|
9840 | const particles = domItem.particles.quadTree.queryCircle(posRetina, domItem.retina.sizeValue);
|
9841 | callback(e, particles);
|
9842 | };
|
9843 |
|
9844 | const clickHandler = e => {
|
9845 | if (domItem.destroyed) {
|
9846 | return;
|
9847 | }
|
9848 |
|
9849 | const mouseEvent = e;
|
9850 | const pos = {
|
9851 | x: mouseEvent.offsetX || mouseEvent.clientX,
|
9852 | y: mouseEvent.offsetY || mouseEvent.clientY
|
9853 | };
|
9854 | clickOrTouchHandler(e, pos);
|
9855 | };
|
9856 |
|
9857 | const touchStartHandler = () => {
|
9858 | if (domItem.destroyed) {
|
9859 | return;
|
9860 | }
|
9861 |
|
9862 | touched = true;
|
9863 | touchMoved = false;
|
9864 | };
|
9865 |
|
9866 | const touchMoveHandler = () => {
|
9867 | if (domItem.destroyed) {
|
9868 | return;
|
9869 | }
|
9870 |
|
9871 | touchMoved = true;
|
9872 | };
|
9873 |
|
9874 | const touchEndHandler = e => {
|
9875 | var _a, _b, _c;
|
9876 |
|
9877 | if (domItem.destroyed) {
|
9878 | return;
|
9879 | }
|
9880 |
|
9881 | if (touched && !touchMoved) {
|
9882 | const touchEvent = e;
|
9883 | const lastTouch = touchEvent.touches[touchEvent.touches.length - 1];
|
9884 | const canvasRect = (_a = domItem.canvas.element) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
9885 | const pos = {
|
9886 | x: lastTouch.clientX - ((_b = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.left) !== null && _b !== void 0 ? _b : 0),
|
9887 | y: lastTouch.clientY - ((_c = canvasRect === null || canvasRect === void 0 ? void 0 : canvasRect.top) !== null && _c !== void 0 ? _c : 0)
|
9888 | };
|
9889 | clickOrTouchHandler(e, pos);
|
9890 | }
|
9891 |
|
9892 | touched = false;
|
9893 | touchMoved = false;
|
9894 | };
|
9895 |
|
9896 | const touchCancelHandler = () => {
|
9897 | if (domItem.destroyed) {
|
9898 | return;
|
9899 | }
|
9900 |
|
9901 | touched = false;
|
9902 | touchMoved = false;
|
9903 | };
|
9904 |
|
9905 | let touched = false;
|
9906 | let touchMoved = false;
|
9907 | el.addEventListener("click", clickHandler);
|
9908 | el.addEventListener("touchstart", touchStartHandler);
|
9909 | el.addEventListener("touchmove", touchMoveHandler);
|
9910 | el.addEventListener("touchend", touchEndHandler);
|
9911 | el.addEventListener("touchcancel", touchCancelHandler);
|
9912 | }
|
9913 | }
|
9914 |
|
9915 | }
|
9916 | ;
|
9917 | var main_slim_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
9918 | function adopt(value) {
|
9919 | return value instanceof P ? value : new P(function (resolve) {
|
9920 | resolve(value);
|
9921 | });
|
9922 | }
|
9923 |
|
9924 | return new (P || (P = Promise))(function (resolve, reject) {
|
9925 | function fulfilled(value) {
|
9926 | try {
|
9927 | step(generator.next(value));
|
9928 | } catch (e) {
|
9929 | reject(e);
|
9930 | }
|
9931 | }
|
9932 |
|
9933 | function rejected(value) {
|
9934 | try {
|
9935 | step(generator["throw"](value));
|
9936 | } catch (e) {
|
9937 | reject(e);
|
9938 | }
|
9939 | }
|
9940 |
|
9941 | function step(result) {
|
9942 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
9943 | }
|
9944 |
|
9945 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9946 | });
|
9947 | };
|
9948 |
|
9949 | var __classPrivateFieldSet = undefined && undefined.__classPrivateFieldSet || function (receiver, privateMap, value) {
|
9950 | if (!privateMap.has(receiver)) {
|
9951 | throw new TypeError("attempted to set private field on non-instance");
|
9952 | }
|
9953 |
|
9954 | privateMap.set(receiver, value);
|
9955 | return value;
|
9956 | };
|
9957 |
|
9958 | var __classPrivateFieldGet = undefined && undefined.__classPrivateFieldGet || function (receiver, privateMap) {
|
9959 | if (!privateMap.has(receiver)) {
|
9960 | throw new TypeError("attempted to get private field on non-instance");
|
9961 | }
|
9962 |
|
9963 | return privateMap.get(receiver);
|
9964 | };
|
9965 |
|
9966 | var _initialized;
|
9967 |
|
9968 |
|
9969 |
|
9970 |
|
9971 |
|
9972 |
|
9973 |
|
9974 |
|
9975 |
|
9976 |
|
9977 |
|
9978 |
|
9979 | class MainSlim {
|
9980 | constructor() {
|
9981 | _initialized.set(this, void 0);
|
9982 |
|
9983 | __classPrivateFieldSet(this, _initialized, false);
|
9984 |
|
9985 | const squareDrawer = new SquareDrawer();
|
9986 | const textDrawer = new TextDrawer();
|
9987 | const imageDrawer = new ImageDrawer();
|
9988 | Plugins.addShapeDrawer(ShapeType.line, new LineDrawer());
|
9989 | Plugins.addShapeDrawer(ShapeType.circle, new CircleDrawer());
|
9990 | Plugins.addShapeDrawer(ShapeType.edge, squareDrawer);
|
9991 | Plugins.addShapeDrawer(ShapeType.square, squareDrawer);
|
9992 | Plugins.addShapeDrawer(ShapeType.triangle, new TriangleDrawer());
|
9993 | Plugins.addShapeDrawer(ShapeType.star, new StarDrawer());
|
9994 | Plugins.addShapeDrawer(ShapeType.polygon, new PolygonDrawer());
|
9995 | Plugins.addShapeDrawer(ShapeType.char, textDrawer);
|
9996 | Plugins.addShapeDrawer(ShapeType.character, textDrawer);
|
9997 | Plugins.addShapeDrawer(ShapeType.image, imageDrawer);
|
9998 | Plugins.addShapeDrawer(ShapeType.images, imageDrawer);
|
9999 | }
|
10000 |
|
10001 | init() {
|
10002 | if (!__classPrivateFieldGet(this, _initialized)) {
|
10003 | __classPrivateFieldSet(this, _initialized, true);
|
10004 | }
|
10005 | }
|
10006 |
|
10007 | loadFromArray(tagId, options, index) {
|
10008 | return main_slim_awaiter(this, void 0, void 0, function* () {
|
10009 | return Loader.load(tagId, options, index);
|
10010 | });
|
10011 | }
|
10012 |
|
10013 | load(tagId, options) {
|
10014 | return main_slim_awaiter(this, void 0, void 0, function* () {
|
10015 | return Loader.load(tagId, options);
|
10016 | });
|
10017 | }
|
10018 |
|
10019 | set(id, element, options) {
|
10020 | return main_slim_awaiter(this, void 0, void 0, function* () {
|
10021 | return Loader.set(id, element, options);
|
10022 | });
|
10023 | }
|
10024 |
|
10025 | loadJSON(tagId, pathConfigJson, index) {
|
10026 | return Loader.loadJSON(tagId, pathConfigJson, index);
|
10027 | }
|
10028 |
|
10029 | setOnClickHandler(callback) {
|
10030 | Loader.setOnClickHandler(callback);
|
10031 | }
|
10032 |
|
10033 | dom() {
|
10034 | return Loader.dom();
|
10035 | }
|
10036 |
|
10037 | domItem(index) {
|
10038 | return Loader.domItem(index);
|
10039 | }
|
10040 |
|
10041 | addShape(shape, drawer, init, afterEffect, destroy) {
|
10042 | let customDrawer;
|
10043 |
|
10044 | if (typeof drawer === "function") {
|
10045 | customDrawer = {
|
10046 | afterEffect: afterEffect,
|
10047 | destroy: destroy,
|
10048 | draw: drawer,
|
10049 | init: init
|
10050 | };
|
10051 | } else {
|
10052 | customDrawer = drawer;
|
10053 | }
|
10054 |
|
10055 | Plugins.addShapeDrawer(shape, customDrawer);
|
10056 | }
|
10057 |
|
10058 | addPreset(preset, options) {
|
10059 | Plugins.addPreset(preset, options);
|
10060 | }
|
10061 |
|
10062 | addPlugin(plugin) {
|
10063 | Plugins.addPlugin(plugin);
|
10064 | }
|
10065 |
|
10066 | addPathGenerator(name, generator) {
|
10067 | Plugins.addPathGenerator(name, generator);
|
10068 | }
|
10069 |
|
10070 | }
|
10071 | _initialized = new WeakMap();
|
10072 | ;
|
10073 |
|
10074 |
|
10075 | class AbsorberInstance {
|
10076 | constructor(absorbers, container, options, position) {
|
10077 | var _a, _b, _c;
|
10078 |
|
10079 | this.absorbers = absorbers;
|
10080 | this.container = container;
|
10081 | this.initialPosition = position ? Vector.create(position.x, position.y) : undefined;
|
10082 | this.options = options;
|
10083 | this.dragging = false;
|
10084 | this.name = this.options.name;
|
10085 | this.opacity = this.options.opacity;
|
10086 | this.size = NumberUtils.getValue(options.size) * container.retina.pixelRatio;
|
10087 | this.mass = this.size * options.size.density * container.retina.reduceFactor;
|
10088 | const limit = options.size.limit;
|
10089 | this.limit = limit !== undefined ? limit * container.retina.pixelRatio * container.retina.reduceFactor : limit;
|
10090 | const color = typeof options.color === "string" ? {
|
10091 | value: options.color
|
10092 | } : options.color;
|
10093 | this.color = (_a = ColorUtils.colorToRgb(color)) !== null && _a !== void 0 ? _a : {
|
10094 | b: 0,
|
10095 | g: 0,
|
10096 | r: 0
|
10097 | };
|
10098 | this.position = (_c = (_b = this.initialPosition) === null || _b === void 0 ? void 0 : _b.copy()) !== null && _c !== void 0 ? _c : this.calcPosition();
|
10099 | }
|
10100 |
|
10101 | attract(particle) {
|
10102 | const options = this.options;
|
10103 |
|
10104 | if (options.draggable) {
|
10105 | const mouse = this.container.interactivity.mouse;
|
10106 |
|
10107 | if (mouse.clicking && mouse.downPosition) {
|
10108 | const mouseDist = NumberUtils.getDistance(this.position, mouse.downPosition);
|
10109 |
|
10110 | if (mouseDist <= this.size) {
|
10111 | this.dragging = true;
|
10112 | }
|
10113 | } else {
|
10114 | this.dragging = false;
|
10115 | }
|
10116 |
|
10117 | if (this.dragging && mouse.position) {
|
10118 | this.position.x = mouse.position.x;
|
10119 | this.position.y = mouse.position.y;
|
10120 | }
|
10121 | }
|
10122 |
|
10123 | const pos = particle.getPosition();
|
10124 | const {
|
10125 | dx,
|
10126 | dy,
|
10127 | distance
|
10128 | } = NumberUtils.getDistances(this.position, pos);
|
10129 | const v = Vector.create(dx, dy);
|
10130 | v.length = this.mass / Math.pow(distance, 2) * this.container.retina.reduceFactor;
|
10131 |
|
10132 | if (distance < this.size + particle.getRadius()) {
|
10133 | const sizeFactor = particle.getRadius() * 0.033 * this.container.retina.pixelRatio;
|
10134 |
|
10135 | if (this.size > particle.getRadius() && distance < this.size - particle.getRadius()) {
|
10136 | if (options.destroy) {
|
10137 | particle.destroy();
|
10138 | } else {
|
10139 | particle.needsNewPosition = true;
|
10140 | this.updateParticlePosition(particle, v);
|
10141 | }
|
10142 | } else {
|
10143 | if (options.destroy) {
|
10144 | particle.size.value -= sizeFactor;
|
10145 | }
|
10146 |
|
10147 | this.updateParticlePosition(particle, v);
|
10148 | }
|
10149 |
|
10150 | if (this.limit === undefined || this.size < this.limit) {
|
10151 | this.size += sizeFactor;
|
10152 | }
|
10153 |
|
10154 | this.mass += sizeFactor * this.options.size.density * this.container.retina.reduceFactor;
|
10155 | } else {
|
10156 | this.updateParticlePosition(particle, v);
|
10157 | }
|
10158 | }
|
10159 |
|
10160 | resize() {
|
10161 | const initialPosition = this.initialPosition;
|
10162 | this.position = initialPosition && Utils.isPointInside(initialPosition, this.container.canvas.size) ? initialPosition : this.calcPosition();
|
10163 | }
|
10164 |
|
10165 | draw(context) {
|
10166 | context.translate(this.position.x, this.position.y);
|
10167 | context.beginPath();
|
10168 | context.arc(0, 0, this.size, 0, Math.PI * 2, false);
|
10169 | context.closePath();
|
10170 | context.fillStyle = ColorUtils.getStyleFromRgb(this.color, this.opacity);
|
10171 | context.fill();
|
10172 | }
|
10173 |
|
10174 | calcPosition() {
|
10175 | var _a, _b;
|
10176 |
|
10177 | const container = this.container;
|
10178 | const percentPosition = this.options.position;
|
10179 | return Vector.create(((_a = percentPosition === null || percentPosition === void 0 ? void 0 : percentPosition.x) !== null && _a !== void 0 ? _a : Math.random() * 100) / 100 * container.canvas.size.width, ((_b = percentPosition === null || percentPosition === void 0 ? void 0 : percentPosition.y) !== null && _b !== void 0 ? _b : Math.random() * 100) / 100 * container.canvas.size.height);
|
10180 | }
|
10181 |
|
10182 | updateParticlePosition(particle, v) {
|
10183 | var _a;
|
10184 |
|
10185 | if (particle.destroyed) {
|
10186 | return;
|
10187 | }
|
10188 |
|
10189 | const canvasSize = this.container.canvas.size;
|
10190 |
|
10191 | if (particle.needsNewPosition) {
|
10192 | const pSize = particle.getRadius();
|
10193 | particle.position.x = Math.random() * (canvasSize.width - pSize * 2) + pSize;
|
10194 | particle.position.y = Math.random() * (canvasSize.height - pSize * 2) + pSize;
|
10195 | particle.needsNewPosition = false;
|
10196 | }
|
10197 |
|
10198 | if (this.options.orbits) {
|
10199 | if (particle.orbit === undefined) {
|
10200 | particle.orbit = Vector.create(0, 0);
|
10201 | particle.orbit.length = NumberUtils.getDistance(particle.getPosition(), this.position);
|
10202 | particle.orbit.angle = Math.random() * Math.PI * 2;
|
10203 | }
|
10204 |
|
10205 | if (particle.orbit.length <= this.size && !this.options.destroy) {
|
10206 | particle.orbit.length = Math.random() * Math.max(canvasSize.width, canvasSize.height);
|
10207 | }
|
10208 |
|
10209 | particle.velocity.x = 0;
|
10210 | particle.velocity.y = 0;
|
10211 | particle.position.setTo(particle.orbit.add(this.position));
|
10212 | particle.orbit.length -= v.length;
|
10213 | particle.orbit.angle += ((_a = particle.moveSpeed) !== null && _a !== void 0 ? _a : NumberUtils.getRangeValue(particle.options.move.speed) * this.container.retina.pixelRatio) / 100 * this.container.retina.reduceFactor;
|
10214 | } else {
|
10215 | particle.velocity.addTo(v);
|
10216 | }
|
10217 | }
|
10218 |
|
10219 | }
|
10220 | ;
|
10221 |
|
10222 | class AbsorberSize extends ValueWithRandom {
|
10223 | constructor() {
|
10224 | super();
|
10225 | this.density = 5;
|
10226 | this.random.minimumValue = 1;
|
10227 | this.value = 50;
|
10228 | }
|
10229 |
|
10230 | load(data) {
|
10231 | if (!data) {
|
10232 | return;
|
10233 | }
|
10234 |
|
10235 | super.load(data);
|
10236 |
|
10237 | if (data.density !== undefined) {
|
10238 | this.density = data.density;
|
10239 | }
|
10240 |
|
10241 | if (data.limit !== undefined) {
|
10242 | this.limit = data.limit;
|
10243 | }
|
10244 |
|
10245 | if (data.limit !== undefined) {
|
10246 | this.limit = data.limit;
|
10247 | }
|
10248 | }
|
10249 |
|
10250 | }
|
10251 | ;
|
10252 |
|
10253 |
|
10254 | class Absorber {
|
10255 | constructor() {
|
10256 | this.color = new OptionsColor();
|
10257 | this.color.value = "#000000";
|
10258 | this.draggable = false;
|
10259 | this.opacity = 1;
|
10260 | this.destroy = true;
|
10261 | this.orbits = false;
|
10262 | this.size = new AbsorberSize();
|
10263 | }
|
10264 |
|
10265 | load(data) {
|
10266 | if (data === undefined) {
|
10267 | return;
|
10268 | }
|
10269 |
|
10270 | if (data.color !== undefined) {
|
10271 | this.color = OptionsColor.create(this.color, data.color);
|
10272 | }
|
10273 |
|
10274 | if (data.draggable !== undefined) {
|
10275 | this.draggable = data.draggable;
|
10276 | }
|
10277 |
|
10278 | this.name = data.name;
|
10279 |
|
10280 | if (data.opacity !== undefined) {
|
10281 | this.opacity = data.opacity;
|
10282 | }
|
10283 |
|
10284 | if (data.position !== undefined) {
|
10285 | this.position = {
|
10286 | x: data.position.x,
|
10287 | y: data.position.y
|
10288 | };
|
10289 | }
|
10290 |
|
10291 | if (data.size !== undefined) {
|
10292 | this.size.load(data.size);
|
10293 | }
|
10294 |
|
10295 | if (data.destroy !== undefined) {
|
10296 | this.destroy = data.destroy;
|
10297 | }
|
10298 |
|
10299 | if (data.orbits !== undefined) {
|
10300 | this.orbits = data.orbits;
|
10301 | }
|
10302 | }
|
10303 |
|
10304 | }
|
10305 | ;
|
10306 | var AbsorberClickMode;
|
10307 |
|
10308 | (function (AbsorberClickMode) {
|
10309 | AbsorberClickMode["absorber"] = "absorber";
|
10310 | })(AbsorberClickMode || (AbsorberClickMode = {}));
|
10311 | ;
|
10312 |
|
10313 | ;
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 | class Absorbers {
|
10319 | constructor(container) {
|
10320 | this.container = container;
|
10321 | this.array = [];
|
10322 | this.absorbers = [];
|
10323 | this.interactivityAbsorbers = [];
|
10324 | const overridableContainer = container;
|
10325 |
|
10326 | overridableContainer.addAbsorber = (options, position) => this.addAbsorber(options, position);
|
10327 | }
|
10328 |
|
10329 | init(options) {
|
10330 | var _a, _b;
|
10331 |
|
10332 | if (!options) {
|
10333 | return;
|
10334 | }
|
10335 |
|
10336 | if (options.absorbers) {
|
10337 | if (options.absorbers instanceof Array) {
|
10338 | this.absorbers = options.absorbers.map(s => {
|
10339 | const tmp = new Absorber();
|
10340 | tmp.load(s);
|
10341 | return tmp;
|
10342 | });
|
10343 | } else {
|
10344 | if (this.absorbers instanceof Array) {
|
10345 | this.absorbers = new Absorber();
|
10346 | }
|
10347 |
|
10348 | this.absorbers.load(options.absorbers);
|
10349 | }
|
10350 | }
|
10351 |
|
10352 | const interactivityAbsorbers = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.absorbers;
|
10353 |
|
10354 | if (interactivityAbsorbers) {
|
10355 | if (interactivityAbsorbers instanceof Array) {
|
10356 | this.interactivityAbsorbers = interactivityAbsorbers.map(s => {
|
10357 | const tmp = new Absorber();
|
10358 | tmp.load(s);
|
10359 | return tmp;
|
10360 | });
|
10361 | } else {
|
10362 | if (this.interactivityAbsorbers instanceof Array) {
|
10363 | this.interactivityAbsorbers = new Absorber();
|
10364 | }
|
10365 |
|
10366 | this.interactivityAbsorbers.load(interactivityAbsorbers);
|
10367 | }
|
10368 | }
|
10369 |
|
10370 | if (this.absorbers instanceof Array) {
|
10371 | for (const absorberOptions of this.absorbers) {
|
10372 | this.addAbsorber(absorberOptions);
|
10373 | }
|
10374 | } else {
|
10375 | this.addAbsorber(this.absorbers);
|
10376 | }
|
10377 | }
|
10378 |
|
10379 | particleUpdate(particle) {
|
10380 | for (const absorber of this.array) {
|
10381 | absorber.attract(particle);
|
10382 |
|
10383 | if (particle.destroyed) {
|
10384 | break;
|
10385 | }
|
10386 | }
|
10387 | }
|
10388 |
|
10389 | draw(context) {
|
10390 | for (const absorber of this.array) {
|
10391 | context.save();
|
10392 | absorber.draw(context);
|
10393 | context.restore();
|
10394 | }
|
10395 | }
|
10396 |
|
10397 | stop() {
|
10398 | this.array = [];
|
10399 | }
|
10400 |
|
10401 | resize() {
|
10402 | for (const absorber of this.array) {
|
10403 | absorber.resize();
|
10404 | }
|
10405 | }
|
10406 |
|
10407 | handleClickMode(mode) {
|
10408 | const container = this.container;
|
10409 | const absorberOptions = this.absorbers;
|
10410 | const modeAbsorbers = this.interactivityAbsorbers;
|
10411 |
|
10412 | if (mode === AbsorberClickMode.absorber) {
|
10413 | let absorbersModeOptions;
|
10414 |
|
10415 | if (modeAbsorbers instanceof Array) {
|
10416 | if (modeAbsorbers.length > 0) {
|
10417 | absorbersModeOptions = Utils.itemFromArray(modeAbsorbers);
|
10418 | }
|
10419 | } else {
|
10420 | absorbersModeOptions = modeAbsorbers;
|
10421 | }
|
10422 |
|
10423 | const absorbersOptions = absorbersModeOptions !== null && absorbersModeOptions !== void 0 ? absorbersModeOptions : absorberOptions instanceof Array ? Utils.itemFromArray(absorberOptions) : absorberOptions;
|
10424 | const aPosition = container.interactivity.mouse.clickPosition;
|
10425 | this.addAbsorber(absorbersOptions, aPosition);
|
10426 | }
|
10427 | }
|
10428 |
|
10429 | addAbsorber(options, position) {
|
10430 | const absorber = new AbsorberInstance(this, this.container, options, position);
|
10431 | this.array.push(absorber);
|
10432 | return absorber;
|
10433 | }
|
10434 |
|
10435 | removeAbsorber(absorber) {
|
10436 | const index = this.array.indexOf(absorber);
|
10437 |
|
10438 | if (index >= 0) {
|
10439 | this.array.splice(index, 1);
|
10440 | }
|
10441 | }
|
10442 |
|
10443 | }
|
10444 | ;
|
10445 |
|
10446 |
|
10447 |
|
10448 |
|
10449 |
|
10450 | class AbsorbersPlugin {
|
10451 | constructor() {
|
10452 | this.id = "absorbers";
|
10453 | }
|
10454 |
|
10455 | getPlugin(container) {
|
10456 | return new Absorbers(container);
|
10457 | }
|
10458 |
|
10459 | needsPlugin(options) {
|
10460 | var _a, _b, _c;
|
10461 |
|
10462 | if (options === undefined) {
|
10463 | return false;
|
10464 | }
|
10465 |
|
10466 | const absorbers = options.absorbers;
|
10467 | let loadAbsorbers = false;
|
10468 |
|
10469 | if (absorbers instanceof Array) {
|
10470 | if (absorbers.length) {
|
10471 | loadAbsorbers = true;
|
10472 | }
|
10473 | } else if (absorbers !== undefined) {
|
10474 | loadAbsorbers = true;
|
10475 | } else if (((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) && Utils.isInArray(AbsorberClickMode.absorber, options.interactivity.events.onClick.mode)) {
|
10476 | loadAbsorbers = true;
|
10477 | }
|
10478 |
|
10479 | return loadAbsorbers;
|
10480 | }
|
10481 |
|
10482 | loadOptions(options, source) {
|
10483 | var _a, _b;
|
10484 |
|
10485 | if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
10486 | return;
|
10487 | }
|
10488 |
|
10489 | const optionsCast = options;
|
10490 |
|
10491 | if (source === null || source === void 0 ? void 0 : source.absorbers) {
|
10492 | if ((source === null || source === void 0 ? void 0 : source.absorbers) instanceof Array) {
|
10493 | optionsCast.absorbers = source === null || source === void 0 ? void 0 : source.absorbers.map(s => {
|
10494 | const tmp = new Absorber();
|
10495 | tmp.load(s);
|
10496 | return tmp;
|
10497 | });
|
10498 | } else {
|
10499 | let absorberOptions = optionsCast.absorbers;
|
10500 |
|
10501 | if ((absorberOptions === null || absorberOptions === void 0 ? void 0 : absorberOptions.load) === undefined) {
|
10502 | optionsCast.absorbers = absorberOptions = new Absorber();
|
10503 | }
|
10504 |
|
10505 | absorberOptions.load(source === null || source === void 0 ? void 0 : source.absorbers);
|
10506 | }
|
10507 | }
|
10508 |
|
10509 | const interactivityAbsorbers = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.absorbers;
|
10510 |
|
10511 | if (interactivityAbsorbers) {
|
10512 | if (interactivityAbsorbers instanceof Array) {
|
10513 | optionsCast.interactivity.modes.absorbers = interactivityAbsorbers.map(s => {
|
10514 | const tmp = new Absorber();
|
10515 | tmp.load(s);
|
10516 | return tmp;
|
10517 | });
|
10518 | } else {
|
10519 | let absorberOptions = optionsCast.interactivity.modes.absorbers;
|
10520 |
|
10521 | if ((absorberOptions === null || absorberOptions === void 0 ? void 0 : absorberOptions.load) === undefined) {
|
10522 | optionsCast.interactivity.modes.absorbers = absorberOptions = new Absorber();
|
10523 | }
|
10524 |
|
10525 | absorberOptions.load(interactivityAbsorbers);
|
10526 | }
|
10527 | }
|
10528 | }
|
10529 |
|
10530 | }
|
10531 |
|
10532 | const AbsorbersPlugin_plugin = new AbsorbersPlugin();
|
10533 |
|
10534 |
|
10535 | ;
|
10536 |
|
10537 | class EmitterSize {
|
10538 | constructor() {
|
10539 | this.mode = SizeMode.percent;
|
10540 | this.height = 0;
|
10541 | this.width = 0;
|
10542 | }
|
10543 |
|
10544 | load(data) {
|
10545 | if (data === undefined) {
|
10546 | return;
|
10547 | }
|
10548 |
|
10549 | if (data.mode !== undefined) {
|
10550 | this.mode = data.mode;
|
10551 | }
|
10552 |
|
10553 | if (data.height !== undefined) {
|
10554 | this.height = data.height;
|
10555 | }
|
10556 |
|
10557 | if (data.width !== undefined) {
|
10558 | this.width = data.width;
|
10559 | }
|
10560 | }
|
10561 |
|
10562 | }
|
10563 | ;
|
10564 |
|
10565 |
|
10566 |
|
10567 |
|
10568 | function randomCoordinate(position, offset) {
|
10569 | return position + offset * (Math.random() - 0.5);
|
10570 | }
|
10571 |
|
10572 | function randomPosition(position, offset) {
|
10573 | return {
|
10574 | x: randomCoordinate(position.x, offset.x),
|
10575 | y: randomCoordinate(position.y, offset.y)
|
10576 | };
|
10577 | }
|
10578 |
|
10579 | class EmitterInstance {
|
10580 | constructor(emitters, container, emitterOptions, position) {
|
10581 | var _a, _b, _c, _d;
|
10582 |
|
10583 | this.emitters = emitters;
|
10584 | this.container = container;
|
10585 | this.firstSpawn = true;
|
10586 | this.currentDuration = 0;
|
10587 | this.currentEmitDelay = 0;
|
10588 | this.currentSpawnDelay = 0;
|
10589 | this.initialPosition = position;
|
10590 | this.emitterOptions = Utils.deepExtend({}, emitterOptions);
|
10591 | this.spawnDelay = ((_a = this.emitterOptions.life.delay) !== null && _a !== void 0 ? _a : 0) * 1000 / this.container.retina.reduceFactor;
|
10592 | this.position = (_b = this.initialPosition) !== null && _b !== void 0 ? _b : this.calcPosition();
|
10593 | this.name = emitterOptions.name;
|
10594 | let particlesOptions = Utils.deepExtend({}, this.emitterOptions.particles);
|
10595 |
|
10596 | if (particlesOptions === undefined) {
|
10597 | particlesOptions = {};
|
10598 | }
|
10599 |
|
10600 | if (particlesOptions.move === undefined) {
|
10601 | particlesOptions.move = {};
|
10602 | }
|
10603 |
|
10604 | if (particlesOptions.move.direction === undefined) {
|
10605 | particlesOptions.move.direction = this.emitterOptions.direction;
|
10606 | }
|
10607 |
|
10608 | if (this.emitterOptions.spawnColor !== undefined) {
|
10609 | this.spawnColor = ColorUtils.colorToHsl(this.emitterOptions.spawnColor);
|
10610 | }
|
10611 |
|
10612 | this.paused = !this.emitterOptions.autoPlay;
|
10613 | this.particlesOptions = particlesOptions;
|
10614 | this.size = (_c = this.emitterOptions.size) !== null && _c !== void 0 ? _c : (() => {
|
10615 | const size = new EmitterSize();
|
10616 | size.load({
|
10617 | height: 0,
|
10618 | mode: SizeMode.percent,
|
10619 | width: 0
|
10620 | });
|
10621 | return size;
|
10622 | })();
|
10623 | this.lifeCount = (_d = this.emitterOptions.life.count) !== null && _d !== void 0 ? _d : -1;
|
10624 | this.immortal = this.lifeCount <= 0;
|
10625 | this.play();
|
10626 | }
|
10627 |
|
10628 | externalPlay() {
|
10629 | this.paused = false;
|
10630 | this.play();
|
10631 | }
|
10632 |
|
10633 | externalPause() {
|
10634 | this.paused = true;
|
10635 | this.pause();
|
10636 | }
|
10637 |
|
10638 | play() {
|
10639 | if (this.paused) {
|
10640 | return;
|
10641 | }
|
10642 |
|
10643 | if (this.container.retina.reduceFactor && (this.lifeCount > 0 || this.immortal || !this.emitterOptions.life.count)) {
|
10644 | if (this.emitDelay === undefined) {
|
10645 | this.emitDelay = 1000 * this.emitterOptions.rate.delay / this.container.retina.reduceFactor;
|
10646 | }
|
10647 |
|
10648 | if (this.lifeCount > 0 || this.immortal) {
|
10649 | this.prepareToDie();
|
10650 | }
|
10651 | }
|
10652 | }
|
10653 |
|
10654 | pause() {
|
10655 | if (this.paused) {
|
10656 | return;
|
10657 | }
|
10658 |
|
10659 | delete this.emitDelay;
|
10660 | }
|
10661 |
|
10662 | resize() {
|
10663 | const initialPosition = this.initialPosition;
|
10664 | this.position = initialPosition && Utils.isPointInside(initialPosition, this.container.canvas.size) ? initialPosition : this.calcPosition();
|
10665 | }
|
10666 |
|
10667 | update(delta) {
|
10668 | var _a, _b, _c;
|
10669 |
|
10670 | if (this.paused) {
|
10671 | return;
|
10672 | }
|
10673 |
|
10674 | if (this.firstSpawn) {
|
10675 | this.firstSpawn = false;
|
10676 | this.currentSpawnDelay = (_a = this.spawnDelay) !== null && _a !== void 0 ? _a : 0;
|
10677 | this.currentEmitDelay = (_b = this.emitDelay) !== null && _b !== void 0 ? _b : 0;
|
10678 | delta.value = 0;
|
10679 | }
|
10680 |
|
10681 | if (this.duration !== undefined) {
|
10682 | this.currentDuration += delta.value;
|
10683 |
|
10684 | if (this.currentDuration >= this.duration) {
|
10685 | this.pause();
|
10686 |
|
10687 | if (this.spawnDelay !== undefined) {
|
10688 | delete this.spawnDelay;
|
10689 | }
|
10690 |
|
10691 | if (!this.immortal) {
|
10692 | this.lifeCount--;
|
10693 | }
|
10694 |
|
10695 | if (this.lifeCount > 0 || this.immortal) {
|
10696 | this.position = this.calcPosition();
|
10697 | this.spawnDelay = ((_c = this.emitterOptions.life.delay) !== null && _c !== void 0 ? _c : 0) * 1000 / this.container.retina.reduceFactor;
|
10698 | } else {
|
10699 | this.destroy();
|
10700 | }
|
10701 |
|
10702 | this.currentDuration -= this.duration;
|
10703 | delete this.duration;
|
10704 | }
|
10705 | }
|
10706 |
|
10707 | if (this.spawnDelay !== undefined) {
|
10708 | this.currentSpawnDelay += delta.value;
|
10709 |
|
10710 | if (this.currentSpawnDelay >= this.spawnDelay) {
|
10711 | this.play();
|
10712 | this.currentSpawnDelay -= this.currentSpawnDelay;
|
10713 | delete this.spawnDelay;
|
10714 | }
|
10715 | }
|
10716 |
|
10717 | if (this.emitDelay !== undefined) {
|
10718 | this.currentEmitDelay += delta.value;
|
10719 |
|
10720 | if (this.currentEmitDelay >= this.emitDelay) {
|
10721 | this.emit();
|
10722 | this.currentEmitDelay -= this.emitDelay;
|
10723 | }
|
10724 | }
|
10725 | }
|
10726 |
|
10727 | prepareToDie() {
|
10728 | var _a;
|
10729 |
|
10730 | if (this.paused) {
|
10731 | return;
|
10732 | }
|
10733 |
|
10734 | const duration = (_a = this.emitterOptions.life) === null || _a === void 0 ? void 0 : _a.duration;
|
10735 |
|
10736 | if (this.container.retina.reduceFactor && (this.lifeCount > 0 || this.immortal) && duration !== undefined && duration > 0) {
|
10737 | this.duration = duration * 1000;
|
10738 | }
|
10739 | }
|
10740 |
|
10741 | destroy() {
|
10742 | this.emitters.removeEmitter(this);
|
10743 | }
|
10744 |
|
10745 | calcPosition() {
|
10746 | var _a, _b;
|
10747 |
|
10748 | const container = this.container;
|
10749 | const percentPosition = this.emitterOptions.position;
|
10750 | return {
|
10751 | x: ((_a = percentPosition === null || percentPosition === void 0 ? void 0 : percentPosition.x) !== null && _a !== void 0 ? _a : Math.random() * 100) / 100 * container.canvas.size.width,
|
10752 | y: ((_b = percentPosition === null || percentPosition === void 0 ? void 0 : percentPosition.y) !== null && _b !== void 0 ? _b : Math.random() * 100) / 100 * container.canvas.size.height
|
10753 | };
|
10754 | }
|
10755 |
|
10756 | emit() {
|
10757 | var _a;
|
10758 |
|
10759 | if (this.paused) {
|
10760 | return;
|
10761 | }
|
10762 |
|
10763 | const container = this.container;
|
10764 | const position = this.position;
|
10765 | const offset = {
|
10766 | x: this.size.mode === SizeMode.percent ? container.canvas.size.width * this.size.width / 100 : this.size.width,
|
10767 | y: this.size.mode === SizeMode.percent ? container.canvas.size.height * this.size.height / 100 : this.size.height
|
10768 | };
|
10769 |
|
10770 | for (let i = 0; i < this.emitterOptions.rate.quantity; i++) {
|
10771 | const particlesOptions = Utils.deepExtend({}, this.particlesOptions);
|
10772 |
|
10773 | if (this.spawnColor !== undefined) {
|
10774 | const colorAnimation = (_a = this.emitterOptions.spawnColor) === null || _a === void 0 ? void 0 : _a.animation;
|
10775 |
|
10776 | if (colorAnimation) {
|
10777 | const hueAnimation = colorAnimation;
|
10778 |
|
10779 | if (hueAnimation.enable) {
|
10780 | this.spawnColor.h = this.setColorAnimation(hueAnimation, this.spawnColor.h, 360);
|
10781 | } else {
|
10782 | const hslAnimation = colorAnimation;
|
10783 | this.spawnColor.h = this.setColorAnimation(hslAnimation.h, this.spawnColor.h, 360);
|
10784 | this.spawnColor.s = this.setColorAnimation(hslAnimation.s, this.spawnColor.s, 100);
|
10785 | this.spawnColor.l = this.setColorAnimation(hslAnimation.l, this.spawnColor.l, 100);
|
10786 | }
|
10787 | }
|
10788 |
|
10789 | if (!particlesOptions.color) {
|
10790 | particlesOptions.color = {
|
10791 | value: this.spawnColor
|
10792 | };
|
10793 | } else {
|
10794 | particlesOptions.color.value = this.spawnColor;
|
10795 | }
|
10796 | }
|
10797 |
|
10798 | container.particles.addParticle(randomPosition(position, offset), particlesOptions);
|
10799 | }
|
10800 | }
|
10801 |
|
10802 | setColorAnimation(animation, initValue, maxValue) {
|
10803 | var _a;
|
10804 |
|
10805 | const container = this.container;
|
10806 |
|
10807 | if (!animation.enable) {
|
10808 | return initValue;
|
10809 | }
|
10810 |
|
10811 | const colorOffset = NumberUtils.randomInRange(animation.offset);
|
10812 | const emitFactor = 1000 * this.emitterOptions.rate.delay / container.retina.reduceFactor;
|
10813 | const colorSpeed = (_a = animation.speed) !== null && _a !== void 0 ? _a : 0;
|
10814 | return (initValue + colorSpeed * container.fpsLimit / emitFactor + colorOffset * 3.6) % maxValue;
|
10815 | }
|
10816 |
|
10817 | }
|
10818 | ;
|
10819 | class EmitterRate {
|
10820 | constructor() {
|
10821 | this.quantity = 1;
|
10822 | this.delay = 0.1;
|
10823 | }
|
10824 |
|
10825 | load(data) {
|
10826 | if (data === undefined) {
|
10827 | return;
|
10828 | }
|
10829 |
|
10830 | if (data.quantity !== undefined) {
|
10831 | this.quantity = data.quantity;
|
10832 | }
|
10833 |
|
10834 | if (data.delay !== undefined) {
|
10835 | this.delay = data.delay;
|
10836 | }
|
10837 | }
|
10838 |
|
10839 | }
|
10840 | ;
|
10841 | class EmitterLife {
|
10842 | load(data) {
|
10843 | if (data === undefined) {
|
10844 | return;
|
10845 | }
|
10846 |
|
10847 | if (data.count !== undefined) {
|
10848 | this.count = data.count;
|
10849 | }
|
10850 |
|
10851 | if (data.delay !== undefined) {
|
10852 | this.delay = data.delay;
|
10853 | }
|
10854 |
|
10855 | if (data.duration !== undefined) {
|
10856 | this.duration = data.duration;
|
10857 | }
|
10858 | }
|
10859 |
|
10860 | }
|
10861 | ;
|
10862 |
|
10863 |
|
10864 |
|
10865 |
|
10866 |
|
10867 |
|
10868 | class Emitter {
|
10869 | constructor() {
|
10870 | this.autoPlay = true;
|
10871 | this.direction = MoveDirection.none;
|
10872 | this.life = new EmitterLife();
|
10873 | this.rate = new EmitterRate();
|
10874 | }
|
10875 |
|
10876 | load(data) {
|
10877 | if (data === undefined) {
|
10878 | return;
|
10879 | }
|
10880 |
|
10881 | if (data.autoPlay !== undefined) {
|
10882 | this.autoPlay = data.autoPlay;
|
10883 | }
|
10884 |
|
10885 | if (data.size !== undefined) {
|
10886 | if (this.size === undefined) {
|
10887 | this.size = new EmitterSize();
|
10888 | }
|
10889 |
|
10890 | this.size.load(data.size);
|
10891 | }
|
10892 |
|
10893 | if (data.direction !== undefined) {
|
10894 | this.direction = data.direction;
|
10895 | }
|
10896 |
|
10897 | this.life.load(data.life);
|
10898 | this.name = data.name;
|
10899 |
|
10900 | if (data.particles !== undefined) {
|
10901 | this.particles = Utils.deepExtend({}, data.particles);
|
10902 | }
|
10903 |
|
10904 | this.rate.load(data.rate);
|
10905 |
|
10906 | if (data.position !== undefined) {
|
10907 | this.position = {
|
10908 | x: data.position.x,
|
10909 | y: data.position.y
|
10910 | };
|
10911 | }
|
10912 |
|
10913 | if (data.spawnColor !== undefined) {
|
10914 | if (this.spawnColor === undefined) {
|
10915 | this.spawnColor = new AnimatableColor();
|
10916 | }
|
10917 |
|
10918 | this.spawnColor.load(data.spawnColor);
|
10919 | }
|
10920 | }
|
10921 |
|
10922 | }
|
10923 | ;
|
10924 | var EmitterClickMode;
|
10925 |
|
10926 | (function (EmitterClickMode) {
|
10927 | EmitterClickMode["emitter"] = "emitter";
|
10928 | })(EmitterClickMode || (EmitterClickMode = {}));
|
10929 | ;
|
10930 |
|
10931 | ;
|
10932 |
|
10933 |
|
10934 |
|
10935 |
|
10936 | class Emitters {
|
10937 | constructor(container) {
|
10938 | this.container = container;
|
10939 | this.array = [];
|
10940 | this.emitters = [];
|
10941 | this.interactivityEmitters = [];
|
10942 | const overridableContainer = container;
|
10943 |
|
10944 | overridableContainer.addEmitter = (options, position) => this.addEmitter(options, position);
|
10945 |
|
10946 | overridableContainer.playEmitter = idxOrName => {
|
10947 | const emitter = idxOrName === undefined || typeof idxOrName === "number" ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
|
10948 |
|
10949 | if (emitter) {
|
10950 | emitter.externalPlay();
|
10951 | }
|
10952 | };
|
10953 |
|
10954 | overridableContainer.pauseEmitter = idxOrName => {
|
10955 | const emitter = idxOrName === undefined || typeof idxOrName === "number" ? this.array[idxOrName || 0] : this.array.find(t => t.name === idxOrName);
|
10956 |
|
10957 | if (emitter) {
|
10958 | emitter.externalPause();
|
10959 | }
|
10960 | };
|
10961 | }
|
10962 |
|
10963 | init(options) {
|
10964 | var _a, _b;
|
10965 |
|
10966 | if (!options) {
|
10967 | return;
|
10968 | }
|
10969 |
|
10970 | if (options.emitters) {
|
10971 | if (options.emitters instanceof Array) {
|
10972 | this.emitters = options.emitters.map(s => {
|
10973 | const tmp = new Emitter();
|
10974 | tmp.load(s);
|
10975 | return tmp;
|
10976 | });
|
10977 | } else {
|
10978 | if (this.emitters instanceof Array) {
|
10979 | this.emitters = new Emitter();
|
10980 | }
|
10981 |
|
10982 | this.emitters.load(options.emitters);
|
10983 | }
|
10984 | }
|
10985 |
|
10986 | const interactivityEmitters = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
|
10987 |
|
10988 | if (interactivityEmitters) {
|
10989 | if (interactivityEmitters instanceof Array) {
|
10990 | this.interactivityEmitters = interactivityEmitters.map(s => {
|
10991 | const tmp = new Emitter();
|
10992 | tmp.load(s);
|
10993 | return tmp;
|
10994 | });
|
10995 | } else {
|
10996 | if (this.interactivityEmitters instanceof Array) {
|
10997 | this.interactivityEmitters = new Emitter();
|
10998 | }
|
10999 |
|
11000 | this.interactivityEmitters.load(interactivityEmitters);
|
11001 | }
|
11002 | }
|
11003 |
|
11004 | if (this.emitters instanceof Array) {
|
11005 | for (const emitterOptions of this.emitters) {
|
11006 | this.addEmitter(emitterOptions);
|
11007 | }
|
11008 | } else {
|
11009 | this.addEmitter(this.emitters);
|
11010 | }
|
11011 | }
|
11012 |
|
11013 | play() {
|
11014 | for (const emitter of this.array) {
|
11015 | emitter.play();
|
11016 | }
|
11017 | }
|
11018 |
|
11019 | pause() {
|
11020 | for (const emitter of this.array) {
|
11021 | emitter.pause();
|
11022 | }
|
11023 | }
|
11024 |
|
11025 | stop() {
|
11026 | this.array = [];
|
11027 | }
|
11028 |
|
11029 | update(delta) {
|
11030 | for (const emitter of this.array) {
|
11031 | emitter.update(delta);
|
11032 | }
|
11033 | }
|
11034 |
|
11035 | handleClickMode(mode) {
|
11036 | const container = this.container;
|
11037 | const emitterOptions = this.emitters;
|
11038 | const modeEmitters = this.interactivityEmitters;
|
11039 |
|
11040 | if (mode === EmitterClickMode.emitter) {
|
11041 | let emitterModeOptions;
|
11042 |
|
11043 | if (modeEmitters instanceof Array) {
|
11044 | if (modeEmitters.length > 0) {
|
11045 | emitterModeOptions = Utils.itemFromArray(modeEmitters);
|
11046 | }
|
11047 | } else {
|
11048 | emitterModeOptions = modeEmitters;
|
11049 | }
|
11050 |
|
11051 | const emittersOptions = emitterModeOptions !== null && emitterModeOptions !== void 0 ? emitterModeOptions : emitterOptions instanceof Array ? Utils.itemFromArray(emitterOptions) : emitterOptions;
|
11052 | const ePosition = container.interactivity.mouse.clickPosition;
|
11053 | this.addEmitter(Utils.deepExtend({}, emittersOptions), ePosition);
|
11054 | }
|
11055 | }
|
11056 |
|
11057 | resize() {
|
11058 | for (const emitter of this.array) {
|
11059 | emitter.resize();
|
11060 | }
|
11061 | }
|
11062 |
|
11063 | addEmitter(options, position) {
|
11064 | const emitter = new EmitterInstance(this, this.container, options, position);
|
11065 | this.array.push(emitter);
|
11066 | return emitter;
|
11067 | }
|
11068 |
|
11069 | removeEmitter(emitter) {
|
11070 | const index = this.array.indexOf(emitter);
|
11071 |
|
11072 | if (index >= 0) {
|
11073 | this.array.splice(index, 1);
|
11074 | }
|
11075 | }
|
11076 |
|
11077 | }
|
11078 | ;
|
11079 |
|
11080 |
|
11081 |
|
11082 |
|
11083 |
|
11084 | class EmittersPlugin {
|
11085 | constructor() {
|
11086 | this.id = "emitters";
|
11087 | }
|
11088 |
|
11089 | getPlugin(container) {
|
11090 | return new Emitters(container);
|
11091 | }
|
11092 |
|
11093 | needsPlugin(options) {
|
11094 | var _a, _b, _c;
|
11095 |
|
11096 | if (options === undefined) {
|
11097 | return false;
|
11098 | }
|
11099 |
|
11100 | const emitters = options.emitters;
|
11101 | let loadEmitters = false;
|
11102 |
|
11103 | if (emitters instanceof Array) {
|
11104 | if (emitters.length) {
|
11105 | loadEmitters = true;
|
11106 | }
|
11107 | } else if (emitters !== undefined) {
|
11108 | loadEmitters = true;
|
11109 | } else if (((_c = (_b = (_a = options.interactivity) === null || _a === void 0 ? void 0 : _a.events) === null || _b === void 0 ? void 0 : _b.onClick) === null || _c === void 0 ? void 0 : _c.mode) && Utils.isInArray(EmitterClickMode.emitter, options.interactivity.events.onClick.mode)) {
|
11110 | loadEmitters = true;
|
11111 | }
|
11112 |
|
11113 | return loadEmitters;
|
11114 | }
|
11115 |
|
11116 | loadOptions(options, source) {
|
11117 | var _a, _b;
|
11118 |
|
11119 | if (!this.needsPlugin(options) && !this.needsPlugin(source)) {
|
11120 | return;
|
11121 | }
|
11122 |
|
11123 | const optionsCast = options;
|
11124 |
|
11125 | if (source === null || source === void 0 ? void 0 : source.emitters) {
|
11126 | if ((source === null || source === void 0 ? void 0 : source.emitters) instanceof Array) {
|
11127 | optionsCast.emitters = source === null || source === void 0 ? void 0 : source.emitters.map(s => {
|
11128 | const tmp = new Emitter();
|
11129 | tmp.load(s);
|
11130 | return tmp;
|
11131 | });
|
11132 | } else {
|
11133 | let emitterOptions = optionsCast.emitters;
|
11134 |
|
11135 | if ((emitterOptions === null || emitterOptions === void 0 ? void 0 : emitterOptions.load) === undefined) {
|
11136 | optionsCast.emitters = emitterOptions = new Emitter();
|
11137 | }
|
11138 |
|
11139 | emitterOptions.load(source === null || source === void 0 ? void 0 : source.emitters);
|
11140 | }
|
11141 | }
|
11142 |
|
11143 | const interactivityEmitters = (_b = (_a = source === null || source === void 0 ? void 0 : source.interactivity) === null || _a === void 0 ? void 0 : _a.modes) === null || _b === void 0 ? void 0 : _b.emitters;
|
11144 |
|
11145 | if (interactivityEmitters) {
|
11146 | if (interactivityEmitters instanceof Array) {
|
11147 | optionsCast.interactivity.modes.emitters = interactivityEmitters.map(s => {
|
11148 | const tmp = new Emitter();
|
11149 | tmp.load(s);
|
11150 | return tmp;
|
11151 | });
|
11152 | } else {
|
11153 | let emitterOptions = optionsCast.interactivity.modes.emitters;
|
11154 |
|
11155 | if ((emitterOptions === null || emitterOptions === void 0 ? void 0 : emitterOptions.load) === undefined) {
|
11156 | optionsCast.interactivity.modes.emitters = emitterOptions = new Emitter();
|
11157 | }
|
11158 |
|
11159 | emitterOptions.load(interactivityEmitters);
|
11160 | }
|
11161 | }
|
11162 | }
|
11163 |
|
11164 | }
|
11165 |
|
11166 | const EmittersPlugin_plugin = new EmittersPlugin();
|
11167 |
|
11168 |
|
11169 | ;
|
11170 | var InlineArrangement;
|
11171 |
|
11172 | (function (InlineArrangement) {
|
11173 | InlineArrangement["equidistant"] = "equidistant";
|
11174 | InlineArrangement["onePerPoint"] = "one-per-point";
|
11175 | InlineArrangement["perPoint"] = "per-point";
|
11176 | InlineArrangement["randomLength"] = "random-length";
|
11177 | InlineArrangement["randomPoint"] = "random-point";
|
11178 | })(InlineArrangement || (InlineArrangement = {}));
|
11179 | ;
|
11180 | var MoveType;
|
11181 |
|
11182 | (function (MoveType) {
|
11183 | MoveType["path"] = "path";
|
11184 | MoveType["radius"] = "radius";
|
11185 | })(MoveType || (MoveType = {}));
|
11186 | ;
|
11187 | var Type;
|
11188 |
|
11189 | (function (Type) {
|
11190 | Type["inline"] = "inline";
|
11191 | Type["inside"] = "inside";
|
11192 | Type["outside"] = "outside";
|
11193 | Type["none"] = "none";
|
11194 | })(Type || (Type = {}));
|
11195 | ;
|
11196 |
|
11197 |
|
11198 |
|
11199 | ;
|
11200 |
|
11201 |
|
11202 | class DrawStroke {
|
11203 | constructor() {
|
11204 | this.color = new OptionsColor();
|
11205 | this.width = 0.5;
|
11206 | this.opacity = 1;
|
11207 | }
|
11208 |
|
11209 | load(data) {
|
11210 | var _a;
|
11211 |
|
11212 | if (data !== undefined) {
|
11213 | this.color = OptionsColor.create(this.color, data.color);
|
11214 |
|
11215 | if (typeof this.color.value === "string") {
|
11216 | this.opacity = (_a = ColorUtils.stringToAlpha(this.color.value)) !== null && _a !== void 0 ? _a : this.opacity;
|
11217 | }
|
11218 |
|
11219 | if (data.opacity !== undefined) {
|
11220 | this.opacity = data.opacity;
|
11221 | }
|
11222 |
|
11223 | if (data.width !== undefined) {
|
11224 | this.width = data.width;
|
11225 | }
|
11226 | }
|
11227 | }
|
11228 |
|
11229 | }
|
11230 | ;
|
11231 |
|
11232 |
|
11233 | class Draw {
|
11234 | constructor() {
|
11235 | this.enable = false;
|
11236 | this.stroke = new DrawStroke();
|
11237 | }
|
11238 |
|
11239 | get lineWidth() {
|
11240 | return this.stroke.width;
|
11241 | }
|
11242 |
|
11243 | set lineWidth(value) {
|
11244 | this.stroke.width = value;
|
11245 | }
|
11246 |
|
11247 | get lineColor() {
|
11248 | return this.stroke.color;
|
11249 | }
|
11250 |
|
11251 | set lineColor(value) {
|
11252 | this.stroke.color = OptionsColor.create(this.stroke.color, value);
|
11253 | }
|
11254 |
|
11255 | load(data) {
|
11256 | var _a;
|
11257 |
|
11258 | if (data !== undefined) {
|
11259 | if (data.enable !== undefined) {
|
11260 | this.enable = data.enable;
|
11261 | }
|
11262 |
|
11263 | const stroke = (_a = data.stroke) !== null && _a !== void 0 ? _a : {
|
11264 | color: data.lineColor,
|
11265 | width: data.lineWidth
|
11266 | };
|
11267 | this.stroke.load(stroke);
|
11268 | }
|
11269 | }
|
11270 |
|
11271 | }
|
11272 | ;
|
11273 |
|
11274 | class Move_Move {
|
11275 | constructor() {
|
11276 | this.radius = 10;
|
11277 | this.type = MoveType.path;
|
11278 | }
|
11279 |
|
11280 | load(data) {
|
11281 | if (data !== undefined) {
|
11282 | if (data.radius !== undefined) {
|
11283 | this.radius = data.radius;
|
11284 | }
|
11285 |
|
11286 | if (data.type !== undefined) {
|
11287 | this.type = data.type;
|
11288 | }
|
11289 | }
|
11290 | }
|
11291 |
|
11292 | }
|
11293 | ;
|
11294 |
|
11295 | class Inline {
|
11296 | constructor() {
|
11297 | this.arrangement = InlineArrangement.onePerPoint;
|
11298 | }
|
11299 |
|
11300 | load(data) {
|
11301 | if (data !== undefined) {
|
11302 | if (data.arrangement !== undefined) {
|
11303 | this.arrangement = data.arrangement;
|
11304 | }
|
11305 | }
|
11306 | }
|
11307 |
|
11308 | }
|
11309 | ;
|
11310 | class LocalSvg {
|
11311 | constructor() {
|
11312 | this.path = [];
|
11313 | this.size = {
|
11314 | height: 0,
|
11315 | width: 0
|
11316 | };
|
11317 | }
|
11318 |
|
11319 | load(data) {
|
11320 | if (data !== undefined) {
|
11321 | if (data.path !== undefined) {
|
11322 | this.path = data.path;
|
11323 | }
|
11324 |
|
11325 | if (data.size !== undefined) {
|
11326 | if (data.size.width !== undefined) {
|
11327 | this.size.width = data.size.width;
|
11328 | }
|
11329 |
|
11330 | if (data.size.height !== undefined) {
|
11331 | this.size.height = data.size.height;
|
11332 | }
|
11333 | }
|
11334 | }
|
11335 | }
|
11336 |
|
11337 | }
|
11338 | ;
|
11339 |
|
11340 |
|
11341 |
|
11342 |
|
11343 |
|
11344 |
|
11345 | class PolygonMask {
|
11346 | constructor() {
|
11347 | this.draw = new Draw();
|
11348 | this.enable = false;
|
11349 | this.inline = new Inline();
|
11350 | this.move = new Move_Move();
|
11351 | this.scale = 1;
|
11352 | this.type = Type.none;
|
11353 | }
|
11354 |
|
11355 | get inlineArrangement() {
|
11356 | return this.inline.arrangement;
|
11357 | }
|
11358 |
|
11359 | set inlineArrangement(value) {
|
11360 | this.inline.arrangement = value;
|
11361 | }
|
11362 |
|
11363 | load(data) {
|
11364 | var _a;
|
11365 |
|
11366 | if (data !== undefined) {
|
11367 | this.draw.load(data.draw);
|
11368 | const inline = (_a = data.inline) !== null && _a !== void 0 ? _a : {
|
11369 | arrangement: data.inlineArrangement
|
11370 | };
|
11371 |
|
11372 | if (inline !== undefined) {
|
11373 | this.inline.load(inline);
|
11374 | }
|
11375 |
|
11376 | this.move.load(data.move);
|
11377 |
|
11378 | if (data.scale !== undefined) {
|
11379 | this.scale = data.scale;
|
11380 | }
|
11381 |
|
11382 | if (data.type !== undefined) {
|
11383 | this.type = data.type;
|
11384 | }
|
11385 |
|
11386 | if (data.enable !== undefined) {
|
11387 | this.enable = data.enable;
|
11388 | } else {
|
11389 | this.enable = this.type !== Type.none;
|
11390 | }
|
11391 |
|
11392 | if (data.url !== undefined) {
|
11393 | this.url = data.url;
|
11394 | }
|
11395 |
|
11396 | if (data.data !== undefined) {
|
11397 | if (typeof data.data === "string") {
|
11398 | this.data = data.data;
|
11399 | } else {
|
11400 | this.data = new LocalSvg();
|
11401 | this.data.load(data.data);
|
11402 | }
|
11403 | }
|
11404 |
|
11405 | if (data.position !== undefined) {
|
11406 | this.position = Utils.deepExtend({}, data.position);
|
11407 | }
|
11408 | }
|
11409 | }
|
11410 |
|
11411 | }
|
11412 | ;
|
11413 | var PolygonMaskInstance_awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
|
11414 | function adopt(value) {
|
11415 | return value instanceof P ? value : new P(function (resolve) {
|
11416 | resolve(value);
|
11417 | });
|
11418 | }
|
11419 |
|
11420 | return new (P || (P = Promise))(function (resolve, reject) {
|
11421 | function fulfilled(value) {
|
11422 | try {
|
11423 | step(generator.next(value));
|
11424 | } catch (e) {
|
11425 | reject(e);
|
11426 | }
|
11427 | }
|
11428 |
|
11429 | function rejected(value) {
|
11430 | try {
|
11431 | step(generator["throw"](value));
|
11432 | } catch (e) {
|
11433 | reject(e);
|
11434 | }
|
11435 | }
|
11436 |
|
11437 | function step(result) {
|
11438 | result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
11439 | }
|
11440 |
|
11441 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
11442 | });
|
11443 | };
|
11444 |
|
11445 |
|
11446 |
|
11447 |
|
11448 |
|
11449 | function polygonBounce(particle) {
|
11450 | particle.velocity.x = particle.velocity.y / 2 - particle.velocity.x;
|
11451 | particle.velocity.y = particle.velocity.x / 2 - particle.velocity.y;
|
11452 | }
|
11453 |
|
11454 | function drawPolygonMask(context, rawData, stroke) {
|
11455 | const color = ColorUtils.colorToRgb(stroke.color);
|
11456 |
|
11457 | if (!color) {
|
11458 | return;
|
11459 | }
|
11460 |
|
11461 | context.beginPath();
|
11462 | context.moveTo(rawData[0].x, rawData[0].y);
|
11463 |
|
11464 | for (const item of rawData) {
|
11465 | context.lineTo(item.x, item.y);
|
11466 | }
|
11467 |
|
11468 | context.closePath();
|
11469 | context.strokeStyle = ColorUtils.getStyleFromRgb(color);
|
11470 | context.lineWidth = stroke.width;
|
11471 | context.stroke();
|
11472 | }
|
11473 |
|
11474 | function drawPolygonMaskPath(context, path, stroke, position) {
|
11475 | context.translate(position.x, position.y);
|
11476 | const color = ColorUtils.colorToRgb(stroke.color);
|
11477 |
|
11478 | if (!color) {
|
11479 | return;
|
11480 | }
|
11481 |
|
11482 | context.strokeStyle = ColorUtils.getStyleFromRgb(color, stroke.opacity);
|
11483 | context.lineWidth = stroke.width;
|
11484 | context.stroke(path);
|
11485 | }
|
11486 |
|
11487 | function parsePaths(paths, scale, offset) {
|
11488 | const res = [];
|
11489 |
|
11490 | for (const path of paths) {
|
11491 | const segments = path.element.pathSegList;
|
11492 | const len = segments.numberOfItems;
|
11493 | const p = {
|
11494 | x: 0,
|
11495 | y: 0
|
11496 | };
|
11497 |
|
11498 | for (let i = 0; i < len; i++) {
|
11499 | const segment = segments.getItem(i);
|
11500 | const svgPathSeg = window.SVGPathSeg;
|
11501 |
|
11502 | switch (segment.pathSegType) {
|
11503 | case svgPathSeg.PATHSEG_MOVETO_ABS:
|
11504 | case svgPathSeg.PATHSEG_LINETO_ABS:
|
11505 | case svgPathSeg.PATHSEG_CURVETO_CUBIC_ABS:
|
11506 | case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_ABS:
|
11507 | case svgPathSeg.PATHSEG_ARC_ABS:
|
11508 | case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
|
11509 | case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
|
11510 | {
|
11511 | const absSeg = segment;
|
11512 | p.x = absSeg.x;
|
11513 | p.y = absSeg.y;
|
11514 | break;
|
11515 | }
|
11516 |
|
11517 | case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_ABS:
|
11518 | p.x = segment.x;
|
11519 | break;
|
11520 |
|
11521 | case svgPathSeg.PATHSEG_LINETO_VERTICAL_ABS:
|
11522 | p.y = segment.y;
|
11523 | break;
|
11524 |
|
11525 | case svgPathSeg.PATHSEG_LINETO_REL:
|
11526 | case svgPathSeg.PATHSEG_MOVETO_REL:
|
11527 | case svgPathSeg.PATHSEG_CURVETO_CUBIC_REL:
|
11528 | case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_REL:
|
11529 | case svgPathSeg.PATHSEG_ARC_REL:
|
11530 | case svgPathSeg.PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
|
11531 | case svgPathSeg.PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
|
11532 | {
|
11533 | const relSeg = segment;
|
11534 | p.x += relSeg.x;
|
11535 | p.y += relSeg.y;
|
11536 | break;
|
11537 | }
|
11538 |
|
11539 | case svgPathSeg.PATHSEG_LINETO_HORIZONTAL_REL:
|
11540 | p.x += segment.x;
|
11541 | break;
|
11542 |
|
11543 | case svgPathSeg.PATHSEG_LINETO_VERTICAL_REL:
|
11544 | p.y += segment.y;
|
11545 | break;
|
11546 |
|
11547 | case svgPathSeg.PATHSEG_UNKNOWN:
|
11548 | case svgPathSeg.PATHSEG_CLOSEPATH:
|
11549 | continue;
|
11550 | }
|
11551 |
|
11552 | res.push({
|
11553 | x: p.x * scale + offset.x,
|
11554 | y: p.y * scale + offset.y
|
11555 | });
|
11556 | }
|
11557 | }
|
11558 |
|
11559 | return res;
|
11560 | }
|
11561 |
|
11562 | class PolygonMaskInstance {
|
11563 | constructor(container) {
|
11564 | this.container = container;
|
11565 | this.dimension = {
|
11566 | height: 0,
|
11567 | width: 0
|
11568 | };
|
11569 | this.path2DSupported = !!window.Path2D;
|
11570 | this.options = new PolygonMask();
|
11571 | this.polygonMaskMoveRadius = this.options.move.radius * container.retina.pixelRatio;
|
11572 | }
|
11573 |
|
11574 | initAsync(options) {
|
11575 | return PolygonMaskInstance_awaiter(this, void 0, void 0, function* () {
|
11576 | this.options.load(options === null || options === void 0 ? void 0 : options.polygon);
|
11577 | const polygonMaskOptions = this.options;
|
11578 | this.polygonMaskMoveRadius = polygonMaskOptions.move.radius * this.container.retina.pixelRatio;
|
11579 |
|
11580 | if (polygonMaskOptions.enable) {
|
11581 | yield this.initRawData();
|
11582 | }
|
11583 | });
|
11584 | }
|
11585 |
|
11586 | resize() {
|
11587 | const container = this.container;
|
11588 | const options = this.options;
|
11589 |
|
11590 | if (!(options.enable && options.type !== Type.none)) {
|
11591 | return;
|
11592 | }
|
11593 |
|
11594 | if (this.redrawTimeout) {
|
11595 | clearTimeout(this.redrawTimeout);
|
11596 | }
|
11597 |
|
11598 | this.redrawTimeout = window.setTimeout(() => PolygonMaskInstance_awaiter(this, void 0, void 0, function* () {
|
11599 | yield this.initRawData(true);
|
11600 | container.particles.redraw();
|
11601 | }), 250);
|
11602 | }
|
11603 |
|
11604 | stop() {
|
11605 | delete this.raw;
|
11606 | delete this.paths;
|
11607 | }
|
11608 |
|
11609 | particlesInitialization() {
|
11610 | const options = this.options;
|
11611 |
|
11612 | if (options.enable && options.type === Type.inline && (options.inline.arrangement === InlineArrangement.onePerPoint || options.inline.arrangement === InlineArrangement.perPoint)) {
|
11613 | this.drawPoints();
|
11614 | return true;
|
11615 | }
|
11616 |
|
11617 | return false;
|
11618 | }
|
11619 |
|
11620 | particlePosition(position) {
|
11621 | var _a, _b;
|
11622 |
|
11623 | const options = this.options;
|
11624 |
|
11625 | if (!(options.enable && ((_b = (_a = this.raw) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0)) {
|
11626 | return;
|
11627 | }
|
11628 |
|
11629 | return Utils.deepExtend({}, position ? position : this.randomPoint());
|
11630 | }
|
11631 |
|
11632 | particleBounce(particle) {
|
11633 | const options = this.options;
|
11634 |
|
11635 | if (options.enable && options.type !== Type.none && options.type !== Type.inline) {
|
11636 | if (!this.checkInsidePolygon(particle.getPosition())) {
|
11637 | polygonBounce(particle);
|
11638 | return true;
|
11639 | }
|
11640 | } else if (options.enable && options.type === Type.inline && particle.initialPosition) {
|
11641 | const dist = NumberUtils.getDistance(particle.initialPosition, particle.getPosition());
|
11642 |
|
11643 | if (dist > this.polygonMaskMoveRadius) {
|
11644 | polygonBounce(particle);
|
11645 | return true;
|
11646 | }
|
11647 | }
|
11648 |
|
11649 | return false;
|
11650 | }
|
11651 |
|
11652 | clickPositionValid(position) {
|
11653 | const options = this.options;
|
11654 | return options.enable && options.type !== Type.none && options.type !== Type.inline && this.checkInsidePolygon(position);
|
11655 | }
|
11656 |
|
11657 | draw(context) {
|
11658 | var _a;
|
11659 |
|
11660 | if (!((_a = this.paths) === null || _a === void 0 ? void 0 : _a.length)) {
|
11661 | return;
|
11662 | }
|
11663 |
|
11664 | const options = this.options;
|
11665 | const polygonDraw = options.draw;
|
11666 |
|
11667 | if (!(options.enable && polygonDraw.enable)) {
|
11668 | return;
|
11669 | }
|
11670 |
|
11671 | const rawData = this.raw;
|
11672 |
|
11673 | for (const path of this.paths) {
|
11674 | const path2d = path.path2d;
|
11675 | const path2dSupported = this.path2DSupported;
|
11676 |
|
11677 | if (!context) {
|
11678 | continue;
|
11679 | }
|
11680 |
|
11681 | if (path2dSupported && path2d && this.offset) {
|
11682 | drawPolygonMaskPath(context, path2d, polygonDraw.stroke, this.offset);
|
11683 | } else if (rawData) {
|
11684 | drawPolygonMask(context, rawData, polygonDraw.stroke);
|
11685 | }
|
11686 | }
|
11687 | }
|
11688 |
|
11689 | checkInsidePolygon(position) {
|
11690 | var _a, _b;
|
11691 |
|
11692 | const container = this.container;
|
11693 | const options = this.options;
|
11694 |
|
11695 | if (!options.enable || options.type === Type.none || options.type === Type.inline) {
|
11696 | return true;
|
11697 | }
|
11698 |
|
11699 | if (!this.raw) {
|
11700 | throw new Error(Constants.noPolygonFound);
|
11701 | }
|
11702 |
|
11703 | const canvasSize = container.canvas.size;
|
11704 | const x = (_a = position === null || position === void 0 ? void 0 : position.x) !== null && _a !== void 0 ? _a : Math.random() * canvasSize.width;
|
11705 | const y = (_b = position === null || position === void 0 ? void 0 : position.y) !== null && _b !== void 0 ? _b : Math.random() * canvasSize.height;
|
11706 | let inside = false;
|
11707 |
|
11708 | for (let i = 0, j = this.raw.length - 1; i < this.raw.length; j = i++) {
|
11709 | const pi = this.raw[i];
|
11710 | const pj = this.raw[j];
|
11711 | const intersect = pi.y > y !== pj.y > y && x < (pj.x - pi.x) * (y - pi.y) / (pj.y - pi.y) + pi.x;
|
11712 |
|
11713 | if (intersect) {
|
11714 | inside = !inside;
|
11715 | }
|
11716 | }
|
11717 |
|
11718 | return options.type === Type.inside ? inside : options.type === Type.outside ? !inside : false;
|
11719 | }
|
11720 |
|
11721 | parseSvgPath(xml, force) {
|
11722 | var _a, _b, _c;
|
11723 |
|
11724 | const forceDownload = force !== null && force !== void 0 ? force : false;
|
11725 |
|
11726 | if (this.paths !== undefined && !forceDownload) {
|
11727 | return this.raw;
|
11728 | }
|
11729 |
|
11730 | const container = this.container;
|
11731 | const options = this.options;
|
11732 | const parser = new DOMParser();
|
11733 | const doc = parser.parseFromString(xml, "image/svg+xml");
|
11734 | const svg = doc.getElementsByTagName("svg")[0];
|
11735 | let svgPaths = svg.getElementsByTagName("path");
|
11736 |
|
11737 | if (!svgPaths.length) {
|
11738 | svgPaths = doc.getElementsByTagName("path");
|
11739 | }
|
11740 |
|
11741 | this.paths = [];
|
11742 |
|
11743 | for (let i = 0; i < svgPaths.length; i++) {
|
11744 | const path = svgPaths.item(i);
|
11745 |
|
11746 | if (path) {
|
11747 | this.paths.push({
|
11748 | element: path,
|
11749 | length: path.getTotalLength()
|
11750 | });
|
11751 | }
|
11752 | }
|
11753 |
|
11754 | const pxRatio = container.retina.pixelRatio;
|
11755 | const scale = options.scale / pxRatio;
|
11756 | this.dimension.width = parseFloat((_a = svg.getAttribute("width")) !== null && _a !== void 0 ? _a : "0") * scale;
|
11757 | this.dimension.height = parseFloat((_b = svg.getAttribute("height")) !== null && _b !== void 0 ? _b : "0") * scale;
|
11758 | const position = (_c = options.position) !== null && _c !== void 0 ? _c : {
|
11759 | x: 50,
|
11760 | y: 50
|
11761 | };
|
11762 | this.offset = {
|
11763 | x: container.canvas.size.width * position.x / (100 * pxRatio) - this.dimension.width / 2,
|
11764 | y: container.canvas.size.height * position.y / (100 * pxRatio) - this.dimension.height / 2
|
11765 | };
|
11766 | return parsePaths(this.paths, scale, this.offset);
|
11767 | }
|
11768 |
|
11769 | downloadSvgPath(svgUrl, force) {
|
11770 | return PolygonMaskInstance_awaiter(this, void 0, void 0, function* () {
|
11771 | const options = this.options;
|
11772 | const url = svgUrl || options.url;
|
11773 | const forceDownload = force !== null && force !== void 0 ? force : false;
|
11774 |
|
11775 | if (!url || this.paths !== undefined && !forceDownload) {
|
11776 | return this.raw;
|
11777 | }
|
11778 |
|
11779 | const req = yield fetch(url);
|
11780 |
|
11781 | if (!req.ok) {
|
11782 | throw new Error("tsParticles Error - Error occurred during polygon mask download");
|
11783 | }
|
11784 |
|
11785 | return this.parseSvgPath(yield req.text(), force);
|
11786 | });
|
11787 | }
|
11788 |
|
11789 | drawPoints() {
|
11790 | if (!this.raw) {
|
11791 | return;
|
11792 | }
|
11793 |
|
11794 | for (const item of this.raw) {
|
11795 | this.container.particles.addParticle({
|
11796 | x: item.x,
|
11797 | y: item.y
|
11798 | });
|
11799 | }
|
11800 | }
|
11801 |
|
11802 | randomPoint() {
|
11803 | const container = this.container;
|
11804 | const options = this.options;
|
11805 | let position;
|
11806 |
|
11807 | if (options.type === Type.inline) {
|
11808 | switch (options.inline.arrangement) {
|
11809 | case InlineArrangement.randomPoint:
|
11810 | position = this.getRandomPoint();
|
11811 | break;
|
11812 |
|
11813 | case InlineArrangement.randomLength:
|
11814 | position = this.getRandomPointByLength();
|
11815 | break;
|
11816 |
|
11817 | case InlineArrangement.equidistant:
|
11818 | position = this.getEquidistantPointByIndex(container.particles.count);
|
11819 | break;
|
11820 |
|
11821 | case InlineArrangement.onePerPoint:
|
11822 | case InlineArrangement.perPoint:
|
11823 | default:
|
11824 | position = this.getPointByIndex(container.particles.count);
|
11825 | }
|
11826 | } else {
|
11827 | position = {
|
11828 | x: Math.random() * container.canvas.size.width,
|
11829 | y: Math.random() * container.canvas.size.height
|
11830 | };
|
11831 | }
|
11832 |
|
11833 | if (this.checkInsidePolygon(position)) {
|
11834 | return position;
|
11835 | } else {
|
11836 | return this.randomPoint();
|
11837 | }
|
11838 | }
|
11839 |
|
11840 | getRandomPoint() {
|
11841 | if (!this.raw || !this.raw.length) {
|
11842 | throw new Error(Constants.noPolygonDataLoaded);
|
11843 | }
|
11844 |
|
11845 | const coords = Utils.itemFromArray(this.raw);
|
11846 | return {
|
11847 | x: coords.x,
|
11848 | y: coords.y
|
11849 | };
|
11850 | }
|
11851 |
|
11852 | getRandomPointByLength() {
|
11853 | var _a, _b, _c;
|
11854 |
|
11855 | const options = this.options;
|
11856 |
|
11857 | if (!this.raw || !this.raw.length || !((_a = this.paths) === null || _a === void 0 ? void 0 : _a.length)) {
|
11858 | throw new Error(Constants.noPolygonDataLoaded);
|
11859 | }
|
11860 |
|
11861 | const path = Utils.itemFromArray(this.paths);
|
11862 | const distance = Math.floor(Math.random() * path.length) + 1;
|
11863 | const point = path.element.getPointAtLength(distance);
|
11864 | return {
|
11865 | x: point.x * options.scale + (((_b = this.offset) === null || _b === void 0 ? void 0 : _b.x) || 0),
|
11866 | y: point.y * options.scale + (((_c = this.offset) === null || _c === void 0 ? void 0 : _c.y) || 0)
|
11867 | };
|
11868 | }
|
11869 |
|
11870 | getEquidistantPointByIndex(index) {
|
11871 | var _a, _b, _c, _d, _e, _f, _g;
|
11872 |
|
11873 | const options = this.container.actualOptions;
|
11874 | const polygonMaskOptions = this.options;
|
11875 | if (!this.raw || !this.raw.length || !((_a = this.paths) === null || _a === void 0 ? void 0 : _a.length)) throw new Error(Constants.noPolygonDataLoaded);
|
11876 | let offset = 0;
|
11877 | let point;
|
11878 | const totalLength = this.paths.reduce((tot, path) => tot + path.length, 0);
|
11879 | const distance = totalLength / options.particles.number.value;
|
11880 |
|
11881 | for (const path of this.paths) {
|
11882 | const pathDistance = distance * index - offset;
|
11883 |
|
11884 | if (pathDistance <= path.length) {
|
11885 | point = path.element.getPointAtLength(pathDistance);
|
11886 | break;
|
11887 | } else {
|
11888 | offset += path.length;
|
11889 | }
|
11890 | }
|
11891 |
|
11892 | return {
|
11893 | x: ((_b = point === null || point === void 0 ? void 0 : point.x) !== null && _b !== void 0 ? _b : 0) * polygonMaskOptions.scale + ((_d = (_c = this.offset) === null || _c === void 0 ? void 0 : _c.x) !== null && _d !== void 0 ? _d : 0),
|
11894 | y: ((_e = point === null || point === void 0 ? void 0 : point.y) !== null && _e !== void 0 ? _e : 0) * polygonMaskOptions.scale + ((_g = (_f = this.offset) === null || _f === void 0 ? void 0 : _f.y) !== null && _g !== void 0 ? _g : 0)
|
11895 | };
|
11896 | }
|
11897 |
|
11898 | getPointByIndex(index) {
|
11899 | if (!this.raw || !this.raw.length) {
|
11900 | throw new Error(Constants.noPolygonDataLoaded);
|
11901 | }
|
11902 |
|
11903 | const coords = this.raw[index % this.raw.length];
|
11904 | return {
|
11905 | x: coords.x,
|
11906 | y: coords.y
|
11907 | };
|
11908 | }
|
11909 |
|
11910 | createPath2D() {
|
11911 | var _a, _b;
|
11912 |
|
11913 | const options = this.options;
|
11914 |
|
11915 | if (!this.path2DSupported || !((_a = this.paths) === null || _a === void 0 ? void 0 : _a.length)) {
|
11916 | return;
|
11917 | }
|
11918 |
|
11919 | for (const path of this.paths) {
|
11920 | const pathData = (_b = path.element) === null || _b === void 0 ? void 0 : _b.getAttribute("d");
|
11921 |
|
11922 | if (pathData) {
|
11923 | const path2d = new Path2D(pathData);
|
11924 | const matrix = document.createElementNS("http://www.w3.org/2000/svg", "svg").createSVGMatrix();
|
11925 | const finalPath = new Path2D();
|
11926 | const transform = matrix.scale(options.scale);
|
11927 |
|
11928 | if (finalPath.addPath) {
|
11929 | finalPath.addPath(path2d, transform);
|
11930 | path.path2d = finalPath;
|
11931 | } else {
|
11932 | delete path.path2d;
|
11933 | }
|
11934 | } else {
|
11935 | delete path.path2d;
|
11936 | }
|
11937 |
|
11938 | if (path.path2d || !this.raw) {
|
11939 | continue;
|
11940 | }
|
11941 |
|
11942 | path.path2d = new Path2D();
|
11943 | path.path2d.moveTo(this.raw[0].x, this.raw[0].y);
|
11944 | this.raw.forEach((pos, i) => {
|
11945 | var _a;
|
11946 |
|
11947 | if (i > 0) {
|
11948 | (_a = path.path2d) === null || _a === void 0 ? void 0 : _a.lineTo(pos.x, pos.y);
|
11949 | }
|
11950 | });
|
11951 | path.path2d.closePath();
|
11952 | }
|
11953 | }
|
11954 |
|
11955 | initRawData(force) {
|
11956 | return PolygonMaskInstance_awaiter(this, void 0, void 0, function* () {
|
11957 | const options = this.options;
|
11958 |
|
11959 | if (options.url) {
|
11960 | this.raw = yield this.downloadSvgPath(options.url, force);
|
11961 | } else if (options.data) {
|
11962 | const data = options.data;
|
11963 | let svg;
|
11964 |
|
11965 | if (typeof data !== "string") {
|
11966 | const path = data.path instanceof Array ? data.path.map(t => `<path d="${t}" />`).join("") : `<path d="${data.path}" />`;
|
11967 | const namespaces = 'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"';
|
11968 | svg = `<svg ${namespaces} width="${data.size.width}" height="${data.size.height}">${path}</svg>`;
|
11969 | } else {
|
11970 | svg = data;
|
11971 | }
|
11972 |
|
11973 | this.raw = this.parseSvgPath(svg, force);
|
11974 | }
|
11975 |
|
11976 | this.createPath2D();
|
11977 | });
|
11978 | }
|
11979 |
|
11980 | }
|
11981 | ;
|
11982 |
|
11983 |
|
11984 |
|
11985 |
|
11986 | class PolygonMaskPlugin {
|
11987 | constructor() {
|
11988 | this.id = "polygonMask";
|
11989 | }
|
11990 |
|
11991 | getPlugin(container) {
|
11992 | return new PolygonMaskInstance(container);
|
11993 | }
|
11994 |
|
11995 | needsPlugin(options) {
|
11996 | var _a, _b, _c;
|
11997 |
|
11998 | return (_b = (_a = options === null || options === void 0 ? void 0 : options.polygon) === null || _a === void 0 ? void 0 : _a.enable) !== null && _b !== void 0 ? _b : ((_c = options === null || options === void 0 ? void 0 : options.polygon) === null || _c === void 0 ? void 0 : _c.type) !== undefined && options.polygon.type !== Type.none;
|
11999 | }
|
12000 |
|
12001 | loadOptions(options, source) {
|
12002 | if (!this.needsPlugin(source)) {
|
12003 | return;
|
12004 | }
|
12005 |
|
12006 | const optionsCast = options;
|
12007 | let polygonOptions = optionsCast.polygon;
|
12008 |
|
12009 | if ((polygonOptions === null || polygonOptions === void 0 ? void 0 : polygonOptions.load) === undefined) {
|
12010 | optionsCast.polygon = polygonOptions = new PolygonMask();
|
12011 | }
|
12012 |
|
12013 | polygonOptions.load(source === null || source === void 0 ? void 0 : source.polygon);
|
12014 | }
|
12015 |
|
12016 | }
|
12017 |
|
12018 | const PolygonMaskPlugin_plugin = new PolygonMaskPlugin();
|
12019 |
|
12020 |
|
12021 | ;
|
12022 |
|
12023 |
|
12024 |
|
12025 |
|
12026 | class Main extends MainSlim {
|
12027 | constructor() {
|
12028 | super();
|
12029 | this.addPlugin(AbsorbersPlugin_plugin);
|
12030 | this.addPlugin(EmittersPlugin_plugin);
|
12031 | this.addPlugin(PolygonMaskPlugin_plugin);
|
12032 | }
|
12033 |
|
12034 | }
|
12035 | ;
|
12036 |
|
12037 |
|
12038 |
|
12039 | const tsParticles = new Main();
|
12040 | tsParticles.init();
|
12041 | const {
|
12042 | particlesJS,
|
12043 | pJSDom
|
12044 | } = initPjs(tsParticles);
|
12045 |
|
12046 |
|
12047 |
|
12048 |
|
12049 |
|
12050 |
|
12051 |
|
12052 |
|
12053 |
|
12054 | return __webpack_exports__;
|
12055 | })()
|
12056 | ;
|
12057 | }); |
\ | No newline at end of file |