tsparticles
Version:
Easily create highly customizable particle animations and use them as animated backgrounds for your website. Ready to use components available also for React, Vue.js (2.x and 3.x), Angular, Svelte, jQuery, Preact, Riot.js, Inferno.
1,763 lines (1,533 loc) • 373 kB
JavaScript
/*!
* Author : Matteo Bruni
* MIT license: https://opensource.org/licenses/MIT
* Demo / Generator : https://particles.js.org/
* GitHub : https://www.github.com/matteobruni/tsparticles
* How to use? : Check the GitHub README
* v1.34.1
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else {
var a = factory();
for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
}
})(this, function() {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
"AbsorberClickMode": () => (/* reexport */ AbsorberClickMode),
"AlterType": () => (/* reexport */ AlterType),
"AnimationStatus": () => (/* reexport */ AnimationStatus),
"CanvasUtils": () => (/* reexport */ CanvasUtils_namespaceObject),
"Circle": () => (/* reexport */ Circle),
"CircleWarp": () => (/* reexport */ CircleWarp),
"ClickMode": () => (/* reexport */ ClickMode),
"CollisionMode": () => (/* reexport */ CollisionMode),
"ColorUtils": () => (/* reexport */ ColorUtils_namespaceObject),
"Constants": () => (/* reexport */ Constants),
"Container": () => (/* reexport */ Container),
"DestroyMode": () => (/* reexport */ DestroyMode),
"DestroyType": () => (/* reexport */ DestroyType),
"DivMode": () => (/* reexport */ DivMode),
"DivType": () => (/* reexport */ DivType),
"EasingType": () => (/* reexport */ EasingType),
"EmitterClickMode": () => (/* reexport */ EmitterClickMode),
"EmitterShapeType": () => (/* reexport */ EmitterShapeType),
"ExternalInteractorBase": () => (/* reexport */ ExternalInteractorBase),
"GradientType": () => (/* reexport */ GradientType),
"HoverMode": () => (/* reexport */ HoverMode),
"InlineArrangement": () => (/* reexport */ InlineArrangement),
"InteractivityDetect": () => (/* reexport */ InteractivityDetect),
"InteractorType": () => (/* reexport */ InteractorType),
"Main": () => (/* reexport */ Main),
"MoveDirection": () => (/* reexport */ MoveDirection),
"MoveType": () => (/* reexport */ MoveType),
"NumberUtils": () => (/* reexport */ NumberUtils_namespaceObject),
"OrbitType": () => (/* reexport */ OrbitType),
"OutMode": () => (/* reexport */ OutMode),
"OutModeDirection": () => (/* reexport */ OutModeDirection),
"Particle": () => (/* reexport */ Particle),
"ParticlesInteractorBase": () => (/* reexport */ ParticlesInteractorBase),
"Point": () => (/* reexport */ Point),
"Rectangle": () => (/* reexport */ Rectangle),
"RotateDirection": () => (/* reexport */ RotateDirection),
"ShapeType": () => (/* reexport */ ShapeType),
"SizeMode": () => (/* reexport */ SizeMode),
"StartValueType": () => (/* reexport */ StartValueType),
"ThemeMode": () => (/* reexport */ ThemeMode),
"TiltDirection": () => (/* reexport */ TiltDirection),
"Type": () => (/* reexport */ Type),
"Utils": () => (/* reexport */ Utils_namespaceObject),
"Vector": () => (/* reexport */ Vector),
"loadFull": () => (/* reexport */ loadFull),
"pJSDom": () => (/* binding */ pJSDom),
"particlesJS": () => (/* binding */ particlesJS),
"tsParticles": () => (/* binding */ tsParticles)
});
// NAMESPACE OBJECT: ./dist/browser/Utils/NumberUtils.js
var NumberUtils_namespaceObject = {};
__webpack_require__.r(NumberUtils_namespaceObject);
__webpack_require__.d(NumberUtils_namespaceObject, {
"calcEasing": () => (calcEasing),
"clamp": () => (clamp),
"collisionVelocity": () => (collisionVelocity),
"getDistance": () => (getDistance),
"getDistances": () => (getDistances),
"getParticleBaseVelocity": () => (getParticleBaseVelocity),
"getParticleDirectionAngle": () => (getParticleDirectionAngle),
"getRangeMax": () => (getRangeMax),
"getRangeMin": () => (getRangeMin),
"getRangeValue": () => (getRangeValue),
"getValue": () => (getValue),
"mix": () => (mix),
"randomInRange": () => (randomInRange),
"setRangeValue": () => (setRangeValue)
});
// NAMESPACE OBJECT: ./dist/browser/Utils/Utils.js
var Utils_namespaceObject = {};
__webpack_require__.r(Utils_namespaceObject);
__webpack_require__.d(Utils_namespaceObject, {
"animate": () => (animate),
"areBoundsInside": () => (areBoundsInside),
"arrayRandomIndex": () => (arrayRandomIndex),
"calculateBounds": () => (calculateBounds),
"cancelAnimation": () => (cancelAnimation),
"circleBounce": () => (circleBounce),
"circleBounceDataFromParticle": () => (circleBounceDataFromParticle),
"deepExtend": () => (deepExtend),
"divMode": () => (divMode),
"divModeExecute": () => (divModeExecute),
"isDivModeEnabled": () => (isDivModeEnabled),
"isInArray": () => (isInArray),
"isPointInside": () => (isPointInside),
"isSsr": () => (isSsr),
"itemFromArray": () => (itemFromArray),
"loadFont": () => (loadFont),
"rectBounce": () => (rectBounce),
"singleDivModeExecute": () => (singleDivModeExecute)
});
// NAMESPACE OBJECT: ./dist/browser/Utils/ColorUtils.js
var ColorUtils_namespaceObject = {};
__webpack_require__.r(ColorUtils_namespaceObject);
__webpack_require__.d(ColorUtils_namespaceObject, {
"colorMix": () => (colorMix),
"colorToHsl": () => (colorToHsl),
"colorToRgb": () => (colorToRgb),
"getHslAnimationFromHsl": () => (getHslAnimationFromHsl),
"getHslFromAnimation": () => (getHslFromAnimation),
"getLinkColor": () => (getLinkColor),
"getLinkRandomColor": () => (getLinkRandomColor),
"getRandomRgbColor": () => (getRandomRgbColor),
"getStyleFromHsl": () => (getStyleFromHsl),
"getStyleFromHsv": () => (getStyleFromHsv),
"getStyleFromRgb": () => (getStyleFromRgb),
"hslToHsv": () => (hslToHsv),
"hslToRgb": () => (hslToRgb),
"hslaToHsva": () => (hslaToHsva),
"hslaToRgba": () => (hslaToRgba),
"hsvToHsl": () => (hsvToHsl),
"hsvToRgb": () => (hsvToRgb),
"hsvaToHsla": () => (hsvaToHsla),
"hsvaToRgba": () => (hsvaToRgba),
"rgbToHsl": () => (rgbToHsl),
"rgbToHsv": () => (rgbToHsv),
"rgbaToHsva": () => (rgbaToHsva),
"stringToAlpha": () => (stringToAlpha),
"stringToRgb": () => (stringToRgb)
});
// NAMESPACE OBJECT: ./dist/browser/Utils/CanvasUtils.js
var CanvasUtils_namespaceObject = {};
__webpack_require__.r(CanvasUtils_namespaceObject);
__webpack_require__.d(CanvasUtils_namespaceObject, {
"clear": () => (clear),
"drawConnectLine": () => (drawConnectLine),
"drawEllipse": () => (drawEllipse),
"drawGrabLine": () => (drawGrabLine),
"drawLinkLine": () => (drawLinkLine),
"drawLinkTriangle": () => (drawLinkTriangle),
"drawParticle": () => (drawParticle),
"drawParticlePlugin": () => (drawParticlePlugin),
"drawPlugin": () => (drawPlugin),
"drawShape": () => (drawShape),
"drawShapeAfterEffect": () => (drawShapeAfterEffect),
"gradient": () => (gradient),
"paintBase": () => (paintBase)
});
;// CONCATENATED MODULE: ./dist/browser/pjs.js
const initPjs = main => {
const particlesJS = (tagId, options) => {
return main.load(tagId, options);
};
particlesJS.load = (tagId, pathConfigJson, callback) => {
main.loadJSON(tagId, pathConfigJson).then(container => {
if (container) {
callback(container);
}
}).catch(() => {
callback(undefined);
});
};
particlesJS.setOnClickHandler = callback => {
main.setOnClickHandler(callback);
};
const pJSDom = main.dom();
return {
particlesJS,
pJSDom
};
};
;// CONCATENATED MODULE: ./dist/browser/Enums/Directions/MoveDirection.js
var MoveDirection;
(function (MoveDirection) {
MoveDirection["bottom"] = "bottom";
MoveDirection["bottomLeft"] = "bottom-left";
MoveDirection["bottomRight"] = "bottom-right";
MoveDirection["left"] = "left";
MoveDirection["none"] = "none";
MoveDirection["right"] = "right";
MoveDirection["top"] = "top";
MoveDirection["topLeft"] = "top-left";
MoveDirection["topRight"] = "top-right";
})(MoveDirection || (MoveDirection = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Directions/RotateDirection.js
var RotateDirection;
(function (RotateDirection) {
RotateDirection["clockwise"] = "clockwise";
RotateDirection["counterClockwise"] = "counter-clockwise";
RotateDirection["random"] = "random";
})(RotateDirection || (RotateDirection = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Directions/OutModeDirection.js
var OutModeDirection;
(function (OutModeDirection) {
OutModeDirection["bottom"] = "bottom";
OutModeDirection["left"] = "left";
OutModeDirection["right"] = "right";
OutModeDirection["top"] = "top";
})(OutModeDirection || (OutModeDirection = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Directions/TiltDirection.js
var TiltDirection;
(function (TiltDirection) {
TiltDirection["clockwise"] = "clockwise";
TiltDirection["counterClockwise"] = "counter-clockwise";
TiltDirection["random"] = "random";
})(TiltDirection || (TiltDirection = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Directions/index.js
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/ClickMode.js
var ClickMode;
(function (ClickMode) {
ClickMode["attract"] = "attract";
ClickMode["bubble"] = "bubble";
ClickMode["push"] = "push";
ClickMode["remove"] = "remove";
ClickMode["repulse"] = "repulse";
ClickMode["pause"] = "pause";
ClickMode["trail"] = "trail";
})(ClickMode || (ClickMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/DestroyMode.js
var DestroyMode;
(function (DestroyMode) {
DestroyMode["none"] = "none";
DestroyMode["split"] = "split";
})(DestroyMode || (DestroyMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/DivMode.js
var DivMode;
(function (DivMode) {
DivMode["bounce"] = "bounce";
DivMode["bubble"] = "bubble";
DivMode["repulse"] = "repulse";
})(DivMode || (DivMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/HoverMode.js
var HoverMode;
(function (HoverMode) {
HoverMode["attract"] = "attract";
HoverMode["bounce"] = "bounce";
HoverMode["bubble"] = "bubble";
HoverMode["connect"] = "connect";
HoverMode["grab"] = "grab";
HoverMode["light"] = "light";
HoverMode["repulse"] = "repulse";
HoverMode["slow"] = "slow";
HoverMode["trail"] = "trail";
})(HoverMode || (HoverMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/CollisionMode.js
var CollisionMode;
(function (CollisionMode) {
CollisionMode["absorb"] = "absorb";
CollisionMode["bounce"] = "bounce";
CollisionMode["destroy"] = "destroy";
})(CollisionMode || (CollisionMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/OutMode.js
var OutMode;
(function (OutMode) {
OutMode["bounce"] = "bounce";
OutMode["bounceHorizontal"] = "bounce-horizontal";
OutMode["bounceVertical"] = "bounce-vertical";
OutMode["none"] = "none";
OutMode["out"] = "out";
OutMode["destroy"] = "destroy";
OutMode["split"] = "split";
})(OutMode || (OutMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/SizeMode.js
var SizeMode;
(function (SizeMode) {
SizeMode["precise"] = "precise";
SizeMode["percent"] = "percent";
})(SizeMode || (SizeMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/ThemeMode.js
var ThemeMode;
(function (ThemeMode) {
ThemeMode["any"] = "any";
ThemeMode["dark"] = "dark";
ThemeMode["light"] = "light";
})(ThemeMode || (ThemeMode = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Modes/index.js
;// CONCATENATED MODULE: ./dist/browser/Enums/AnimationStatus.js
var AnimationStatus;
(function (AnimationStatus) {
AnimationStatus[AnimationStatus["increasing"] = 0] = "increasing";
AnimationStatus[AnimationStatus["decreasing"] = 1] = "decreasing";
})(AnimationStatus || (AnimationStatus = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/AlterType.js
var AlterType;
(function (AlterType) {
AlterType["darken"] = "darken";
AlterType["enlighten"] = "enlighten";
})(AlterType || (AlterType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/DestroyType.js
var DestroyType;
(function (DestroyType) {
DestroyType["none"] = "none";
DestroyType["max"] = "max";
DestroyType["min"] = "min";
})(DestroyType || (DestroyType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/GradientType.js
var GradientType;
(function (GradientType) {
GradientType["linear"] = "linear";
GradientType["radial"] = "radial";
GradientType["random"] = "random";
})(GradientType || (GradientType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/InteractorType.js
var InteractorType;
(function (InteractorType) {
InteractorType[InteractorType["External"] = 0] = "External";
InteractorType[InteractorType["Particles"] = 1] = "Particles";
})(InteractorType || (InteractorType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/ShapeType.js
var ShapeType;
(function (ShapeType) {
ShapeType["char"] = "char";
ShapeType["character"] = "character";
ShapeType["circle"] = "circle";
ShapeType["edge"] = "edge";
ShapeType["image"] = "image";
ShapeType["images"] = "images";
ShapeType["line"] = "line";
ShapeType["polygon"] = "polygon";
ShapeType["square"] = "square";
ShapeType["star"] = "star";
ShapeType["triangle"] = "triangle";
})(ShapeType || (ShapeType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/StartValueType.js
var StartValueType;
(function (StartValueType) {
StartValueType["max"] = "max";
StartValueType["min"] = "min";
StartValueType["random"] = "random";
})(StartValueType || (StartValueType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/DivType.js
var DivType;
(function (DivType) {
DivType["circle"] = "circle";
DivType["rectangle"] = "rectangle";
})(DivType || (DivType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/EasingType.js
var EasingType;
(function (EasingType) {
EasingType["easeOutBack"] = "ease-out-back";
EasingType["easeOutCirc"] = "ease-out-circ";
EasingType["easeOutCubic"] = "ease-out-cubic";
EasingType["easeOutQuad"] = "ease-out-quad";
EasingType["easeOutQuart"] = "ease-out-quart";
EasingType["easeOutQuint"] = "ease-out-quint";
EasingType["easeOutExpo"] = "ease-out-expo";
EasingType["easeOutSine"] = "ease-out-sine";
})(EasingType || (EasingType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/OrbitType.js
var OrbitType;
(function (OrbitType) {
OrbitType["front"] = "front";
OrbitType["back"] = "back";
})(OrbitType || (OrbitType = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/Types/index.js
;// CONCATENATED MODULE: ./dist/browser/Enums/InteractivityDetect.js
var InteractivityDetect;
(function (InteractivityDetect) {
InteractivityDetect["canvas"] = "canvas";
InteractivityDetect["parent"] = "parent";
InteractivityDetect["window"] = "window";
})(InteractivityDetect || (InteractivityDetect = {}));
;// CONCATENATED MODULE: ./dist/browser/Enums/index.js
;// CONCATENATED MODULE: ./dist/browser/Core/Particle/Vector.js
class Vector {
constructor(x, y) {
let defX, defY;
if (y === undefined) {
if (typeof x === "number") {
throw new Error("tsParticles - Vector not initialized correctly");
}
const coords = x;
[defX, defY] = [coords.x, coords.y];
} else {
[defX, defY] = [x, y];
}
this.x = defX;
this.y = defY;
}
static clone(source) {
return Vector.create(source.x, source.y);
}
static create(x, y) {
return new Vector(x, y);
}
static get origin() {
return Vector.create(0, 0);
}
get angle() {
return Math.atan2(this.y, this.x);
}
set angle(angle) {
this.updateFromAngle(angle, this.length);
}
get length() {
return Math.sqrt(Math.pow(this.x, 2) + Math.pow(this.y, 2));
}
set length(length) {
this.updateFromAngle(this.angle, length);
}
add(v) {
return Vector.create(this.x + v.x, this.y + v.y);
}
addTo(v) {
this.x += v.x;
this.y += v.y;
}
sub(v) {
return Vector.create(this.x - v.x, this.y - v.y);
}
subFrom(v) {
this.x -= v.x;
this.y -= v.y;
}
mult(n) {
return Vector.create(this.x * n, this.y * n);
}
multTo(n) {
this.x *= n;
this.y *= n;
}
div(n) {
return Vector.create(this.x / n, this.y / n);
}
divTo(n) {
this.x /= n;
this.y /= n;
}
distanceTo(v) {
return this.sub(v).length;
}
getLengthSq() {
return Math.pow(this.x, 2) + Math.pow(this.y, 2);
}
distanceToSq(v) {
return this.sub(v).getLengthSq();
}
manhattanDistanceTo(v) {
return Math.abs(v.x - this.x) + Math.abs(v.y - this.y);
}
copy() {
return Vector.clone(this);
}
setTo(velocity) {
this.x = velocity.x;
this.y = velocity.y;
}
rotate(angle) {
return Vector.create(this.x * Math.cos(angle) - this.y * Math.sin(angle), this.x * Math.sin(angle) + this.y * Math.cos(angle));
}
updateFromAngle(angle, length) {
this.x = Math.cos(angle) * length;
this.y = Math.sin(angle) * length;
}
}
;// CONCATENATED MODULE: ./dist/browser/Utils/NumberUtils.js
function clamp(num, min, max) {
return Math.min(Math.max(num, min), max);
}
function mix(comp1, comp2, weight1, weight2) {
return Math.floor((comp1 * weight1 + comp2 * weight2) / (weight1 + weight2));
}
function randomInRange(r) {
const max = getRangeMax(r);
let min = getRangeMin(r);
if (max === min) {
min = 0;
}
return Math.random() * (max - min) + min;
}
function getRangeValue(value) {
return typeof value === "number" ? value : randomInRange(value);
}
function getRangeMin(value) {
return typeof value === "number" ? value : value.min;
}
function getRangeMax(value) {
return typeof value === "number" ? value : value.max;
}
function setRangeValue(source, value) {
if (source === value || value === undefined && typeof source === "number") {
return source;
}
const min = getRangeMin(source),
max = getRangeMax(source);
return value !== undefined ? {
min: Math.min(min, value),
max: Math.max(max, value)
} : setRangeValue(min, max);
}
function getValue(options) {
const random = options.random;
const {
enable,
minimumValue
} = typeof random === "boolean" ? {
enable: random,
minimumValue: 0
} : random;
return enable ? getRangeValue(setRangeValue(options.value, minimumValue)) : getRangeValue(options.value);
}
function getDistances(pointA, pointB) {
const dx = pointA.x - pointB.x;
const dy = pointA.y - pointB.y;
return {
dx: dx,
dy: dy,
distance: Math.sqrt(dx * dx + dy * dy)
};
}
function getDistance(pointA, pointB) {
return getDistances(pointA, pointB).distance;
}
function getParticleDirectionAngle(direction) {
if (typeof direction === "number") {
return direction * Math.PI / 180;
} else {
switch (direction) {
case MoveDirection.top:
return -Math.PI / 2;
case MoveDirection.topRight:
return -Math.PI / 4;
case MoveDirection.right:
return 0;
case MoveDirection.bottomRight:
return Math.PI / 4;
case MoveDirection.bottom:
return Math.PI / 2;
case MoveDirection.bottomLeft:
return 3 * Math.PI / 4;
case MoveDirection.left:
return Math.PI;
case MoveDirection.topLeft:
return -3 * Math.PI / 4;
case MoveDirection.none:
default:
return Math.random() * Math.PI * 2;
}
}
}
function getParticleBaseVelocity(direction) {
const baseVelocity = Vector.origin;
baseVelocity.length = 1;
baseVelocity.angle = direction;
return baseVelocity;
}
function collisionVelocity(v1, v2, m1, m2) {
return Vector.create(v1.x * (m1 - m2) / (m1 + m2) + v2.x * 2 * m2 / (m1 + m2), v1.y);
}
function calcEasing(value, type) {
switch (type) {
case EasingType.easeOutQuad:
return 1 - Math.pow(1 - value, 2);
case EasingType.easeOutCubic:
return 1 - Math.pow(1 - value, 3);
case EasingType.easeOutQuart:
return 1 - Math.pow(1 - value, 4);
case EasingType.easeOutQuint:
return 1 - Math.pow(1 - value, 5);
case EasingType.easeOutExpo:
return value === 1 ? 1 : 1 - Math.pow(2, -10 * value);
case EasingType.easeOutSine:
return Math.sin(value * Math.PI / 2);
case EasingType.easeOutBack:
{
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(value - 1, 3) + c1 * Math.pow(value - 1, 2);
}
case EasingType.easeOutCirc:
return Math.sqrt(1 - Math.pow(value - 1, 2));
default:
return value;
}
}
;// CONCATENATED MODULE: ./dist/browser/Utils/Utils.js
var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
function rectSideBounce(pSide, pOtherSide, rectSide, rectOtherSide, velocity, factor) {
const res = {
bounced: false
};
if (pOtherSide.min >= rectOtherSide.min && pOtherSide.min <= rectOtherSide.max && pOtherSide.max >= rectOtherSide.min && pOtherSide.max <= rectOtherSide.max) {
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) {
res.velocity = velocity * -factor;
res.bounced = true;
}
}
return res;
}
function checkSelector(element, selectors) {
if (selectors instanceof Array) {
for (const selector of selectors) {
if (element.matches(selector)) {
return true;
}
}
return false;
} else {
return element.matches(selectors);
}
}
function isSsr() {
return typeof window === "undefined" || !window;
}
function animate() {
return isSsr() ? callback => setTimeout(callback) : callback => (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout)(callback);
}
function cancelAnimation() {
return isSsr() ? handle => clearTimeout(handle) : handle => (window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.mozCancelRequestAnimationFrame || window.oCancelRequestAnimationFrame || window.msCancelRequestAnimationFrame || window.clearTimeout)(handle);
}
function isInArray(value, array) {
return value === array || array instanceof Array && array.indexOf(value) > -1;
}
function loadFont(character) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
try {
yield document.fonts.load(`${(_a = character.weight) !== null && _a !== void 0 ? _a : "400"} 36px '${(_b = character.font) !== null && _b !== void 0 ? _b : "Verdana"}'`);
} catch (_c) {}
});
}
function arrayRandomIndex(array) {
return Math.floor(Math.random() * array.length);
}
function itemFromArray(array, index, useIndex = true) {
const fixedIndex = index !== undefined && useIndex ? index % array.length : arrayRandomIndex(array);
return array[fixedIndex];
}
function isPointInside(point, size, radius, direction) {
return areBoundsInside(calculateBounds(point, radius !== null && radius !== void 0 ? radius : 0), size, direction);
}
function areBoundsInside(bounds, size, direction) {
let inside = true;
if (!direction || direction === OutModeDirection.bottom) {
inside = bounds.top < size.height;
}
if (inside && (!direction || direction === OutModeDirection.left)) {
inside = bounds.right > 0;
}
if (inside && (!direction || direction === OutModeDirection.right)) {
inside = bounds.left < size.width;
}
if (inside && (!direction || direction === OutModeDirection.top)) {
inside = bounds.bottom > 0;
}
return inside;
}
function calculateBounds(point, radius) {
return {
bottom: point.y + radius,
left: point.x - radius,
right: point.x + radius,
top: point.y - radius
};
}
function deepExtend(destination, ...sources) {
for (const source of sources) {
if (source === undefined || source === null) {
continue;
}
if (typeof source !== "object") {
destination = source;
continue;
}
const sourceIsArray = Array.isArray(source);
if (sourceIsArray && (typeof destination !== "object" || !destination || !Array.isArray(destination))) {
destination = [];
} else if (!sourceIsArray && (typeof destination !== "object" || !destination || Array.isArray(destination))) {
destination = {};
}
for (const key in source) {
if (key === "__proto__") {
continue;
}
const sourceDict = source;
const value = sourceDict[key];
const isObject = typeof value === "object";
const destDict = destination;
destDict[key] = isObject && Array.isArray(value) ? value.map(v => deepExtend(destDict[key], v)) : deepExtend(destDict[key], value);
}
}
return destination;
}
function isDivModeEnabled(mode, divs) {
return divs instanceof Array ? !!divs.find(t => t.enable && isInArray(mode, t.mode)) : isInArray(mode, divs.mode);
}
function divModeExecute(mode, divs, callback) {
if (divs instanceof Array) {
for (const div of divs) {
const divMode = div.mode;
const divEnabled = div.enable;
if (divEnabled && isInArray(mode, divMode)) {
singleDivModeExecute(div, callback);
}
}
} else {
const divMode = divs.mode;
const divEnabled = divs.enable;
if (divEnabled && isInArray(mode, divMode)) {
singleDivModeExecute(divs, callback);
}
}
}
function singleDivModeExecute(div, callback) {
const selectors = div.selectors;
if (selectors instanceof Array) {
for (const selector of selectors) {
callback(selector, div);
}
} else {
callback(selectors, div);
}
}
function divMode(divs, element) {
if (!element || !divs) {
return;
}
if (divs instanceof Array) {
return divs.find(d => checkSelector(element, d.selectors));
} else if (checkSelector(element, divs.selectors)) {
return divs;
}
}
function circleBounceDataFromParticle(p) {
return {
position: p.getPosition(),
radius: p.getRadius(),
mass: p.getMass(),
velocity: p.velocity,
factor: Vector.create(getValue(p.options.bounce.horizontal), getValue(p.options.bounce.vertical))
};
}
function circleBounce(p1, p2) {
const xVelocityDiff = p1.velocity.x;
const yVelocityDiff = p1.velocity.y;
const pos1 = p1.position;
const pos2 = p2.position;
const xDist = pos2.x - pos1.x;
const yDist = pos2.y - pos1.y;
if (xVelocityDiff * xDist + yVelocityDiff * yDist >= 0) {
const angle = -Math.atan2(pos2.y - pos1.y, pos2.x - pos1.x);
const m1 = p1.mass;
const m2 = p2.mass;
const u1 = p1.velocity.rotate(angle);
const u2 = p2.velocity.rotate(angle);
const v1 = collisionVelocity(u1, u2, m1, m2);
const v2 = collisionVelocity(u2, u1, m1, m2);
const vFinal1 = v1.rotate(-angle);
const vFinal2 = v2.rotate(-angle);
p1.velocity.x = vFinal1.x * p1.factor.x;
p1.velocity.y = vFinal1.y * p1.factor.y;
p2.velocity.x = vFinal2.x * p2.factor.x;
p2.velocity.y = vFinal2.y * p2.factor.y;
}
}
function rectBounce(particle, divBounds) {
const pPos = particle.getPosition();
const size = particle.getRadius();
const bounds = calculateBounds(pPos, size);
const resH = rectSideBounce({
min: bounds.left,
max: bounds.right
}, {
min: bounds.top,
max: bounds.bottom
}, {
min: divBounds.left,
max: divBounds.right
}, {
min: divBounds.top,
max: divBounds.bottom
}, particle.velocity.x, getValue(particle.options.bounce.horizontal));
if (resH.bounced) {
if (resH.velocity !== undefined) {
particle.velocity.x = resH.velocity;
}
if (resH.position !== undefined) {
particle.position.x = resH.position;
}
}
const resV = rectSideBounce({
min: bounds.top,
max: bounds.bottom
}, {
min: bounds.left,
max: bounds.right
}, {
min: divBounds.top,
max: divBounds.bottom
}, {
min: divBounds.left,
max: divBounds.right
}, particle.velocity.y, getValue(particle.options.bounce.vertical));
if (resV.bounced) {
if (resV.velocity !== undefined) {
particle.velocity.y = resV.velocity;
}
if (resV.position !== undefined) {
particle.position.y = resV.position;
}
}
}
;// CONCATENATED MODULE: ./dist/browser/Utils/Constants.js
class Constants {}
Constants.canvasClass = "tsparticles-canvas-el";
Constants.randomColorValue = "random";
Constants.midColorValue = "mid";
Constants.touchEndEvent = "touchend";
Constants.mouseDownEvent = "mousedown";
Constants.mouseUpEvent = "mouseup";
Constants.mouseMoveEvent = "mousemove";
Constants.touchStartEvent = "touchstart";
Constants.touchMoveEvent = "touchmove";
Constants.mouseLeaveEvent = "mouseleave";
Constants.mouseOutEvent = "mouseout";
Constants.touchCancelEvent = "touchcancel";
Constants.resizeEvent = "resize";
Constants.visibilityChangeEvent = "visibilitychange";
Constants.noPolygonDataLoaded = "No polygon data loaded.";
Constants.noPolygonFound = "No polygon found, you need to specify SVG url in config.";
;// CONCATENATED MODULE: ./dist/browser/Utils/ColorUtils.js
function hue2rgb(p, q, t) {
let tCalc = t;
if (tCalc < 0) {
tCalc += 1;
}
if (tCalc > 1) {
tCalc -= 1;
}
if (tCalc < 1 / 6) {
return p + (q - p) * 6 * tCalc;
}
if (tCalc < 1 / 2) {
return q;
}
if (tCalc < 2 / 3) {
return p + (q - p) * (2 / 3 - tCalc) * 6;
}
return p;
}
function stringToRgba(input) {
if (input.startsWith("rgb")) {
const regex = /rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([\d.]+)\s*)?\)/i;
const result = regex.exec(input);
return result ? {
a: result.length > 4 ? parseFloat(result[5]) : 1,
b: parseInt(result[3], 10),
g: parseInt(result[2], 10),
r: parseInt(result[1], 10)
} : undefined;
} else if (input.startsWith("hsl")) {
const regex = /hsla?\(\s*(\d+)\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i;
const result = regex.exec(input);
return result ? hslaToRgba({
a: result.length > 4 ? parseFloat(result[5]) : 1,
h: parseInt(result[1], 10),
l: parseInt(result[3], 10),
s: parseInt(result[2], 10)
}) : undefined;
} else if (input.startsWith("hsv")) {
const regex = /hsva?\(\s*(\d+)°\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(,\s*([\d.]+)\s*)?\)/i;
const result = regex.exec(input);
return result ? hsvaToRgba({
a: result.length > 4 ? parseFloat(result[5]) : 1,
h: parseInt(result[1], 10),
s: parseInt(result[2], 10),
v: parseInt(result[3], 10)
}) : undefined;
} else {
const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])([a-f\d])?$/i;
const hexFixed = input.replace(shorthandRegex, (_m, r, g, b, a) => {
return r + r + g + g + b + b + (a !== undefined ? a + a : "");
});
const regex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})?$/i;
const result = regex.exec(hexFixed);
return result ? {
a: result[4] !== undefined ? parseInt(result[4], 16) / 0xff : 1,
b: parseInt(result[3], 16),
g: parseInt(result[2], 16),
r: parseInt(result[1], 16)
} : undefined;
}
}
function colorToRgb(input, index, useIndex = true) {
var _a, _b, _c;
if (input === undefined) {
return;
}
const color = typeof input === "string" ? {
value: input
} : input;
let res;
if (typeof color.value === "string") {
if (color.value === Constants.randomColorValue) {
res = getRandomRgbColor();
} else {
res = stringToRgb(color.value);
}
} else {
if (color.value instanceof Array) {
const colorSelected = itemFromArray(color.value, index, useIndex);
res = colorToRgb({
value: colorSelected
});
} else {
const colorValue = color.value;
const rgbColor = (_a = colorValue.rgb) !== null && _a !== void 0 ? _a : color.value;
if (rgbColor.r !== undefined) {
res = rgbColor;
} else {
const hslColor = (_b = colorValue.hsl) !== null && _b !== void 0 ? _b : color.value;
if (hslColor.h !== undefined && hslColor.l !== undefined) {
res = hslToRgb(hslColor);
} else {
const hsvColor = (_c = colorValue.hsv) !== null && _c !== void 0 ? _c : color.value;
if (hsvColor.h !== undefined && hsvColor.v !== undefined) {
res = hsvToRgb(hsvColor);
}
}
}
}
}
return res;
}
function colorToHsl(color, index, useIndex = true) {
const rgb = colorToRgb(color, index, useIndex);
return rgb !== undefined ? rgbToHsl(rgb) : undefined;
}
function rgbToHsl(color) {
const r1 = color.r / 255;
const g1 = color.g / 255;
const b1 = color.b / 255;
const max = Math.max(r1, g1, b1);
const min = Math.min(r1, g1, b1);
const res = {
h: 0,
l: (max + min) / 2,
s: 0
};
if (max != min) {
res.s = res.l < 0.5 ? (max - min) / (max + min) : (max - min) / (2.0 - max - min);
res.h = r1 === max ? (g1 - b1) / (max - min) : res.h = g1 === max ? 2.0 + (b1 - r1) / (max - min) : 4.0 + (r1 - g1) / (max - min);
}
res.l *= 100;
res.s *= 100;
res.h *= 60;
if (res.h < 0) {
res.h += 360;
}
return res;
}
function stringToAlpha(input) {
var _a;
return (_a = stringToRgba(input)) === null || _a === void 0 ? void 0 : _a.a;
}
function stringToRgb(input) {
return stringToRgba(input);
}
function hslToRgb(hsl) {
const result = {
b: 0,
g: 0,
r: 0
};
const hslPercent = {
h: hsl.h / 360,
l: hsl.l / 100,
s: hsl.s / 100
};
if (hslPercent.s === 0) {
result.b = hslPercent.l;
result.g = hslPercent.l;
result.r = hslPercent.l;
} else {
const q = hslPercent.l < 0.5 ? hslPercent.l * (1 + hslPercent.s) : hslPercent.l + hslPercent.s - hslPercent.l * hslPercent.s;
const p = 2 * hslPercent.l - q;
result.r = hue2rgb(p, q, hslPercent.h + 1 / 3);
result.g = hue2rgb(p, q, hslPercent.h);
result.b = hue2rgb(p, q, hslPercent.h - 1 / 3);
}
result.r = Math.floor(result.r * 255);
result.g = Math.floor(result.g * 255);
result.b = Math.floor(result.b * 255);
return result;
}
function hslaToRgba(hsla) {
const rgbResult = hslToRgb(hsla);
return {
a: hsla.a,
b: rgbResult.b,
g: rgbResult.g,
r: rgbResult.r
};
}
function hslToHsv(hsl) {
const l = hsl.l / 100,
sl = hsl.s / 100;
const v = l + sl * Math.min(l, 1 - l),
sv = !v ? 0 : 2 * (1 - l / v);
return {
h: hsl.h,
s: sv * 100,
v: v * 100
};
}
function hslaToHsva(hsla) {
const hsvResult = hslToHsv(hsla);
return {
a: hsla.a,
h: hsvResult.h,
s: hsvResult.s,
v: hsvResult.v
};
}
function hsvToHsl(hsv) {
const v = hsv.v / 100,
sv = hsv.s / 100;
const l = v * (1 - sv / 2),
sl = l === 0 || l === 1 ? 0 : (v - l) / Math.min(l, 1 - l);
return {
h: hsv.h,
l: l * 100,
s: sl * 100
};
}
function hsvaToHsla(hsva) {
const hslResult = hsvToHsl(hsva);
return {
a: hsva.a,
h: hslResult.h,
l: hslResult.l,
s: hslResult.s
};
}
function hsvToRgb(hsv) {
const result = {
b: 0,
g: 0,
r: 0
};
const hsvPercent = {
h: hsv.h / 60,
s: hsv.s / 100,
v: hsv.v / 100
};
const c = hsvPercent.v * hsvPercent.s,
x = c * (1 - Math.abs(hsvPercent.h % 2 - 1));
let tempRgb;
if (hsvPercent.h >= 0 && hsvPercent.h <= 1) {
tempRgb = {
r: c,
g: x,
b: 0
};
} else if (hsvPercent.h > 1 && hsvPercent.h <= 2) {
tempRgb = {
r: x,
g: c,
b: 0
};
} else if (hsvPercent.h > 2 && hsvPercent.h <= 3) {
tempRgb = {
r: 0,
g: c,
b: x
};
} else if (hsvPercent.h > 3 && hsvPercent.h <= 4) {
tempRgb = {
r: 0,
g: x,
b: c
};
} else if (hsvPercent.h > 4 && hsvPercent.h <= 5) {
tempRgb = {
r: x,
g: 0,
b: c
};
} else if (hsvPercent.h > 5 && hsvPercent.h <= 6) {
tempRgb = {
r: c,
g: 0,
b: x
};
}
if (tempRgb) {
const m = hsvPercent.v - c;
result.r = Math.floor((tempRgb.r + m) * 255);
result.g = Math.floor((tempRgb.g + m) * 255);
result.b = Math.floor((tempRgb.b + m) * 255);
}
return result;
}
function hsvaToRgba(hsva) {
const rgbResult = hsvToRgb(hsva);
return {
a: hsva.a,
b: rgbResult.b,
g: rgbResult.g,
r: rgbResult.r
};
}
function rgbToHsv(rgb) {
const rgbPercent = {
r: rgb.r / 255,
g: rgb.g / 255,
b: rgb.b / 255
},
xMax = Math.max(rgbPercent.r, rgbPercent.g, rgbPercent.b),
xMin = Math.min(rgbPercent.r, rgbPercent.g, rgbPercent.b),
v = xMax,
c = xMax - xMin;
let h = 0;
if (v === rgbPercent.r) {
h = 60 * ((rgbPercent.g - rgbPercent.b) / c);
} else if (v === rgbPercent.g) {
h = 60 * (2 + (rgbPercent.b - rgbPercent.r) / c);
} else if (v === rgbPercent.b) {
h = 60 * (4 + (rgbPercent.r - rgbPercent.g) / c);
}
const s = !v ? 0 : c / v;
return {
h,
s: s * 100,
v: v * 100
};
}
function rgbaToHsva(rgba) {
const hsvResult = rgbToHsv(rgba);
return {
a: rgba.a,
h: hsvResult.h,
s: hsvResult.s,
v: hsvResult.v
};
}
function getRandomRgbColor(min) {
const fixedMin = min !== null && min !== void 0 ? min : 0;
return {
b: Math.floor(randomInRange(setRangeValue(fixedMin, 256))),
g: Math.floor(randomInRange(setRangeValue(fixedMin, 256))),
r: Math.floor(randomInRange(setRangeValue(fixedMin, 256)))
};
}
function getStyleFromRgb(color, opacity) {
return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
}
function getStyleFromHsl(color, opacity) {
return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity !== null && opacity !== void 0 ? opacity : 1})`;
}
function getStyleFromHsv(color, opacity) {
return getStyleFromHsl(hsvToHsl(color), opacity);
}
function colorMix(color1, color2, size1, size2) {
let rgb1 = color1;
let rgb2 = color2;
if (rgb1.r === undefined) {
rgb1 = hslToRgb(color1);
}
if (rgb2.r === undefined) {
rgb2 = hslToRgb(color2);
}
return {
b: mix(rgb1.b, rgb2.b, size1, size2),
g: mix(rgb1.g, rgb2.g, size1, size2),
r: mix(rgb1.r, rgb2.r, size1, size2)
};
}
function getLinkColor(p1, p2, linkColor) {
var _a, _b;
if (linkColor === Constants.randomColorValue) {
return getRandomRgbColor();
} else if (linkColor === "mid") {
const sourceColor = (_a = p1.getFillColor()) !== null && _a !== void 0 ? _a : p1.getStrokeColor();
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();
if (sourceColor && destColor && p2) {
return colorMix(sourceColor, destColor, p1.getRadius(), p2.getRadius());
} else {
const hslColor = sourceColor !== null && sourceColor !== void 0 ? sourceColor : destColor;
if (hslColor) {
return hslToRgb(hslColor);
}
}
} else {
return linkColor;
}
}
function getLinkRandomColor(optColor, blink, consent) {
const color = typeof optColor === "string" ? optColor : optColor.value;
if (color === Constants.randomColorValue) {
if (consent) {
return colorToRgb({
value: color
});
} else if (blink) {
return Constants.randomColorValue;
} else {
return Constants.midColorValue;
}
} else {
return colorToRgb({
value: color
});
}
}
function getHslFromAnimation(animation) {
return animation !== undefined ? {
h: animation.h.value,
s: animation.s.value,
l: animation.l.value
} : undefined;
}
function getHslAnimationFromHsl(hsl, animationOptions, reduceFactor) {
const resColor = {
h: {
enable: false,
value: hsl.h
},
s: {
enable: false,
value: hsl.s
},
l: {
enable: false,
value: hsl.l
}
};
if (animationOptions) {
setColorAnimation(resColor.h, animationOptions.h, reduceFactor);
setColorAnimation(resColor.s, animationOptions.s, reduceFactor);
setColorAnimation(resColor.l, animationOptions.l, reduceFactor);
}
return resColor;
}
function setColorAnimation(colorValue, colorAnimation, reduceFactor) {
colorValue.enable = colorAnimation.enable;
if (colorValue.enable) {
colorValue.velocity = colorAnimation.speed / 100 * reduceFactor;
if (colorAnimation.sync) {
return;
}
colorValue.status = AnimationStatus.increasing;
colorValue.velocity *= Math.random();
if (colorValue.value) {
colorValue.value *= Math.random();
}
} else {
colorValue.velocity = 0;
}
}
;// CONCATENATED MODULE: ./dist/browser/Utils/CanvasUtils.js
function drawLine(context, begin, end) {
context.beginPath();
context.moveTo(begin.x, begin.y);
context.lineTo(end.x, end.y);
context.closePath();
}
function drawTriangle(context, p1, p2, p3) {
context.beginPath();
context.moveTo(p1.x, p1.y);
context.lineTo(p2.x, p2.y);
context.lineTo(p3.x, p3.y);
context.closePath();
}
function paintBase(context, dimension, baseColor) {
context.save();
context.fillStyle = baseColor !== null && baseColor !== void 0 ? baseColor : "rgba(0,0,0,0)";
context.fillRect(0, 0, dimension.width, dimension.height);
context.restore();
}
function clear(context, dimension) {
context.clearRect(0, 0, dimension.width, dimension.height);
}
function drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) {
let drawn = false;
if (getDistance(begin, end) <= maxDistance) {
drawLine(context, begin, end);
drawn = true;
} else if (warp) {
let pi1;
let pi2;
const endNE = {
x: end.x - canvasSize.width,
y: end.y
};
const d1 = getDistances(begin, endNE);
if (d1.distance <= maxDistance) {
const yi = begin.y - d1.dy / d1.dx * begin.x;
pi1 = {
x: 0,
y: yi
};
pi2 = {
x: canvasSize.width,
y: yi
};
} else {
const endSW = {
x: end.x,
y: end.y - canvasSize.height
};
const d2 = getDistances(begin, endSW);
if (d2.distance <= maxDistance) {
const yi = begin.y - d2.dy / d2.dx * begin.x;
const xi = -yi / (d2.dy / d2.dx);
pi1 = {
x: xi,
y: 0
};
pi2 = {
x: xi,
y: canvasSize.height
};
} else {
const endSE = {
x: end.x - canvasSize.width,
y: end.y - canvasSize.height
};
const d3 = getDistances(begin, endSE);
if (d3.distance <= maxDistance) {
const yi = begin.y - d3.dy / d3.dx * begin.x;
const xi = -yi / (d3.dy / d3.dx);
pi1 = {
x: xi,
y: yi
};
pi2 = {
x: pi1.x + canvasSize.width,
y: pi1.y + canvasSize.height
};
}
}
}
if (pi1 && pi2) {
drawLine(context, begin, pi1);
drawLine(context, end, pi2);
drawn = true;
}
}
if (!drawn) {
return;
}
context.lineWidth = width;
if (backgroundMask) {
context.globalCompositeOperation = composite;
}
context.strokeStyle = getStyleFromRgb(colorLine, opacity);
if (shadow.enable) {
const shadowColor = colorToRgb(shadow.color);
if (shadowColor) {
context.shadowBlur = shadow.blur;
context.shadowColor = getStyleFromRgb(shadowColor);
}
}
context.stroke();
}
function drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) {
drawTriangle(context, pos1, pos2, pos3);
if (backgroundMask) {
context.globalCompositeOperation = composite;
}
context.fillStyle = getStyleFromRgb(colorTriangle, opacityTriangle);
context.fill();
}
function drawConnectLine(context, width, lineStyle, begin, end) {
context.save();
drawLine(context, begin, end);
context.lineWidth = width;
context.strokeStyle = lineStyle;
context.stroke();
context.restore();
}
function gradient(context, p1, p2, opacity) {
const gradStop = Math.floor(p2.getRadius() / p1.getRadius());
const color1 = p1.getFillColor();
const color2 = p2.getFillColor();
if (!color1 || !color2) {
return;
}
const sourcePos = p1.getPosition();
const destPos = p2.getPosition();
const midRgb = colorMix(color1, color2, p1.getRadius(), p2.getRadius());
const grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y);
grad.addColorStop(0, getStyleFromHsl(color1, opacity));
grad.addColorStop(gradStop > 1 ? 1 : gradStop, getStyleFromRgb(midRgb, opacity));
grad.addColorStop(1, getStyleFromHsl(color2, opacity));
return grad;
}
function drawGrabLine(context, width, begin, end, colorLine, opacity) {
context.save();
drawLine(context, begin, end);
context.strokeStyle = getStyleFromRgb(colorLine, opacity);
context.lineWidth = width;
context.stroke();
context.restore();
}
function drawParticle(container, context, particle, delta, fillColorValue, strokeColorValue, backgroundMask, composite, radius, opacity, shadow, gradient) {
var _a, _b;
const pos = particle.getPosition();
const tiltOptions = particle.options.tilt;
const rollOptions = particle.options.roll;
context.save();
if (tiltOptions.enable || rollOptions.enable) {
context.setTransform(rollOptions.enable ? Math.cos(particle.rollAngle) : 1, tiltOptions.enable ? Math.cos(particle.tilt.value) * particle.tilt.cosDirection : 0, tiltOptions.enable ? Math.sin(particle.tilt.value) * particle.tilt.sinDirection : 0, rollOptions.enable ? Math.sin(particle.rollAngle) : 1, pos.x, pos.y);
} else {
context.translate(pos.x, pos.y);
}
context.beginPath();
const angle = particle.rotate.value + (particle.options.rotate.path ? particle.velocity.angle : 0);
if (angle !== 0) {
context.rotate(angle);
}
if (backgroundMask) {
context.globalCompositeOperation = composite;
}
const shadowColor = particle.shadowColor;
if (shadow.enable && shadowColor) {
context.shadowBlur = shadow.blur;
context.shadowColor = getStyleFromRgb(shadowColor);
context.shadowOffsetX = shadow.offset.x;
context.shadowOffsetY = shadow.offset.y;
}
if (gradient) {
const gradientAngle = gradient.angle.value;
const fillGradient = gradient.type === GradientType.radial ? context.createRadialGradient(0, 0, 0, 0, 0, radius) : context.createLinearGradient(Math.cos(gradientAngle) * -radius, Math.sin(gradientAngle) * -radius, Math.cos(gradientAngle) * radius, Math.sin(gradientAngle) * radius);
for (const color of gradient.colors) {
fillGradient.addColorStop(color.stop, getStyleFromHsl({
h: color.value.h.value,
s: color.value.s.value,
l: color.value.l.value
}, (_b = (_a = color.opacity) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : opacity));
}
context.fillStyle = fillGradient;
} else {
if (fillColorValue) {
context.fillStyle = fillColorValue;
}
}
const stroke = particle.stroke;
context.lineWidth = particle.strokeWidth;
if (strokeColorValue) {
context.strokeStyle = strokeColorValue;
}
drawShape(container, context, particle, radius, opacity, delta);
if (stroke.width > 0) {
context.stroke();
}
if (particle.close) {
context.closePath();
}
if (particle.fill) {
context.fill();
}
context.restore();
context.save();
if (tiltOptions.enable) {
context.setTransform(1, Math.cos(particle.tilt.value) * particle.tilt.cosDirection, Math.sin(particle.tilt.value) * particle.tilt.sinDirection, 1, pos.x, pos.y);
} else {
context.translate(pos.x, pos