UNPKG

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,843 lines (1,550 loc) 316 kB
/*! * Author : Matteo Bruni - https://www.matteobruni.it * 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.26.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), "AnimationStatus": () => (/* reexport */ AnimationStatus), "CanvasUtils": () => (/* reexport */ CanvasUtils), "ClickMode": () => (/* reexport */ ClickMode), "CollisionMode": () => (/* reexport */ CollisionMode), "ColorUtils": () => (/* reexport */ ColorUtils), "Constants": () => (/* reexport */ Constants), "Container": () => (/* reexport */ Container), "DestroyMode": () => (/* reexport */ DestroyMode), "DestroyType": () => (/* reexport */ DestroyType), "DivMode": () => (/* reexport */ DivMode), "DivType": () => (/* reexport */ DivType), "EmitterClickMode": () => (/* reexport */ EmitterClickMode), "HoverMode": () => (/* reexport */ HoverMode), "InlineArrangement": () => (/* reexport */ InlineArrangement), "InteractivityDetect": () => (/* reexport */ InteractivityDetect), "Main": () => (/* reexport */ Main), "MoveDirection": () => (/* reexport */ MoveDirection), "MoveType": () => (/* reexport */ MoveType), "OutMode": () => (/* reexport */ OutMode), "ProcessBubbleType": () => (/* reexport */ ProcessBubbleType), "RotateDirection": () => (/* reexport */ RotateDirection), "ShapeType": () => (/* reexport */ ShapeType), "SizeMode": () => (/* reexport */ SizeMode), "StartValueType": () => (/* reexport */ StartValueType), "ThemeMode": () => (/* reexport */ ThemeMode), "Type": () => (/* reexport */ Type), "Utils": () => (/* reexport */ Utils), "Vector": () => (/* reexport */ Vector), "pJSDom": () => (/* binding */ pJSDom), "particlesJS": () => (/* binding */ particlesJS), "tsParticles": () => (/* binding */ tsParticles) }); ;// 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); } }); }; particlesJS.setOnClickHandler = callback => { main.setOnClickHandler(callback); }; const pJSDom = main.dom(); return { particlesJS, pJSDom }; }; ;// CONCATENATED MODULE: ./dist/browser/ShapeDrawers/SquareDrawer.js class SquareDrawer { getSidesCount() { return 4; } draw(context, particle, radius) { context.rect(-radius, -radius, radius * 2, radius * 2); } } ;// 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/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/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); } 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; } } Vector.origin = Vector.create(0, 0); ;// CONCATENATED MODULE: ./dist/browser/Utils/NumberUtils.js class NumberUtils { static clamp(num, min, max) { return Math.min(Math.max(num, min), max); } static mix(comp1, comp2, weight1, weight2) { return Math.floor((comp1 * weight1 + comp2 * weight2) / (weight1 + weight2)); } static randomInRange(r) { const max = NumberUtils.getRangeMax(r); let min = NumberUtils.getRangeMin(r); if (max === min) { min = 0; } return Math.random() * (max - min) + min; } static getRangeValue(value) { return typeof value === "number" ? value : NumberUtils.randomInRange(value); } static getRangeMin(value) { return typeof value === "number" ? value : value.min; } static getRangeMax(value) { return typeof value === "number" ? value : value.max; } static setRangeValue(source, value) { if (source === value || value === undefined && typeof source === "number") { return source; } const min = NumberUtils.getRangeMin(source), max = NumberUtils.getRangeMax(source); return value !== undefined ? { min: Math.min(min, value), max: Math.max(max, value) } : NumberUtils.setRangeValue(min, max); } static getValue(options) { const random = options.random; const { enable, minimumValue } = typeof random === "boolean" ? { enable: random, minimumValue: 0 } : random; return enable ? NumberUtils.getRangeValue(NumberUtils.setRangeValue(options.value, minimumValue)) : NumberUtils.getRangeValue(options.value); } static 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) }; } static getDistance(pointA, pointB) { return NumberUtils.getDistances(pointA, pointB).distance; } static getParticleBaseVelocity(direction) { const baseVelocity = Vector.origin; baseVelocity.length = 1; switch (direction) { case MoveDirection.top: baseVelocity.angle = -Math.PI / 2; break; case MoveDirection.topRight: baseVelocity.angle = -Math.PI / 4; break; case MoveDirection.right: baseVelocity.angle = 0; break; case MoveDirection.bottomRight: baseVelocity.angle = Math.PI / 4; break; case MoveDirection.bottom: baseVelocity.angle = Math.PI / 2; break; case MoveDirection.bottomLeft: baseVelocity.angle = 3 * Math.PI / 4; break; case MoveDirection.left: baseVelocity.angle = Math.PI; break; case MoveDirection.topLeft: baseVelocity.angle = -3 * Math.PI / 4; break; case MoveDirection.none: default: baseVelocity.angle = Math.random() * Math.PI * 2; break; } return baseVelocity; } static rotateVelocity(velocity, angle) { return { horizontal: velocity.horizontal * Math.cos(angle) - velocity.vertical * Math.sin(angle), vertical: velocity.horizontal * Math.sin(angle) + velocity.vertical * Math.cos(angle) }; } static collisionVelocity(v1, v2, m1, m2) { return Vector.create(v1.x * (m1 - m2) / (m1 + m2) + v2.x * 2 * m2 / (m1 + m2), v1.y); } } ;// 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); } } class Utils { static isSsr() { return typeof window === "undefined" || !window; } static get animate() { return Utils.isSsr() ? callback => setTimeout(callback) : callback => (window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || window.setTimeout)(callback); } static get cancelAnimation() { return Utils.isSsr() ? handle => clearTimeout(handle) : handle => (window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.mozCancelRequestAnimationFrame || window.oCancelRequestAnimationFrame || window.msCancelRequestAnimationFrame || window.clearTimeout)(handle); } static isInArray(value, array) { return value === array || array instanceof Array && array.indexOf(value) > -1; } static loadFont(character) { return __awaiter(this, void 0, void 0, function* () { try { yield document.fonts.load(`${character.weight} 36px '${character.font}'`); } catch (_a) {} }); } static arrayRandomIndex(array) { return Math.floor(Math.random() * array.length); } static itemFromArray(array, index, useIndex = true) { const fixedIndex = index !== undefined && useIndex ? index % array.length : Utils.arrayRandomIndex(array); return array[fixedIndex]; } static isPointInside(point, size, radius, direction) { return Utils.areBoundsInside(Utils.calculateBounds(point, radius !== null && radius !== void 0 ? radius : 0), size, direction); } static 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; } static calculateBounds(point, radius) { return { bottom: point.y + radius, left: point.x - radius, right: point.x + radius, top: point.y - radius }; } static loadImage(source) { return new Promise((resolve, reject) => { if (!source) { reject("Error tsParticles - No image.src"); return; } const image = { source: source, type: source.substr(source.length - 3) }; const img = new Image(); img.addEventListener("load", () => { image.element = img; resolve(image); }); img.addEventListener("error", () => { reject(`Error tsParticles - loading image: ${source}`); }); img.src = source; }); } static downloadSvgImage(source) { return __awaiter(this, void 0, void 0, function* () { if (!source) { throw new Error("Error tsParticles - No image.src"); } const image = { source: source, type: source.substr(source.length - 3) }; if (image.type !== "svg") { return Utils.loadImage(source); } const response = yield fetch(image.source); if (!response.ok) { throw new Error("Error tsParticles - Image not found"); } image.svgData = yield response.text(); return image; }); } static 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 => Utils.deepExtend(destDict[key], v)) : Utils.deepExtend(destDict[key], value); } } return destination; } static isDivModeEnabled(mode, divs) { return divs instanceof Array ? !!divs.find(t => t.enable && Utils.isInArray(mode, t.mode)) : Utils.isInArray(mode, divs.mode); } static divModeExecute(mode, divs, callback) { if (divs instanceof Array) { for (const div of divs) { const divMode = div.mode; const divEnabled = div.enable; if (divEnabled && Utils.isInArray(mode, divMode)) { Utils.singleDivModeExecute(div, callback); } } } else { const divMode = divs.mode; const divEnabled = divs.enable; if (divEnabled && Utils.isInArray(mode, divMode)) { Utils.singleDivModeExecute(divs, callback); } } } static singleDivModeExecute(div, callback) { const selectors = div.selectors; if (selectors instanceof Array) { for (const selector of selectors) { callback(selector, div); } } else { callback(selectors, div); } } static 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; } } static circleBounceDataFromParticle(p) { return { position: p.getPosition(), radius: p.getRadius(), mass: p.getMass(), velocity: p.velocity, factor: { horizontal: NumberUtils.getValue(p.options.bounce.horizontal), vertical: NumberUtils.getValue(p.options.bounce.vertical) } }; } static 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 = NumberUtils.collisionVelocity(u1, u2, m1, m2); const v2 = NumberUtils.collisionVelocity(u2, u1, m1, m2); const vFinal1 = v1.rotate(-angle); const vFinal2 = v2.rotate(-angle); p1.velocity.x = vFinal1.x * p1.factor.horizontal; p1.velocity.y = vFinal1.y * p1.factor.vertical; p2.velocity.x = vFinal2.x * p2.factor.horizontal; p2.velocity.y = vFinal2.y * p2.factor.vertical; } } static rectBounce(particle, divBounds) { const pPos = particle.getPosition(); const size = particle.getRadius(); const bounds = Utils.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, NumberUtils.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, NumberUtils.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 ? ColorUtils.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 ? ColorUtils.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; } } class ColorUtils { static 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 = ColorUtils.getRandomRgbColor(); } else { res = ColorUtils.stringToRgb(color.value); } } else { if (color.value instanceof Array) { const colorSelected = Utils.itemFromArray(color.value, index, useIndex); res = ColorUtils.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 = ColorUtils.hslToRgb(hslColor); } else { const hsvColor = (_c = colorValue.hsv) !== null && _c !== void 0 ? _c : color.value; if (hsvColor.h !== undefined && hsvColor.v !== undefined) { res = ColorUtils.hsvToRgb(hsvColor); } } } } } return res; } static colorToHsl(color, index, useIndex = true) { const rgb = ColorUtils.colorToRgb(color, index, useIndex); return rgb !== undefined ? ColorUtils.rgbToHsl(rgb) : undefined; } static 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; } static stringToAlpha(input) { var _a; return (_a = stringToRgba(input)) === null || _a === void 0 ? void 0 : _a.a; } static stringToRgb(input) { return stringToRgba(input); } static 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; } static hslaToRgba(hsla) { const rgbResult = ColorUtils.hslToRgb(hsla); return { a: hsla.a, b: rgbResult.b, g: rgbResult.g, r: rgbResult.r }; } static 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 }; } static hslaToHsva(hsla) { const hsvResult = ColorUtils.hslToHsv(hsla); return { a: hsla.a, h: hsvResult.h, s: hsvResult.s, v: hsvResult.v }; } static 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 }; } static hsvaToHsla(hsva) { const hslResult = ColorUtils.hsvToHsl(hsva); return { a: hsva.a, h: hslResult.h, l: hslResult.l, s: hslResult.s }; } static 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; } static hsvaToRgba(hsva) { const rgbResult = ColorUtils.hsvToRgb(hsva); return { a: hsva.a, b: rgbResult.b, g: rgbResult.g, r: rgbResult.r }; } static 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 }; } static rgbaToHsva(rgba) { const hsvResult = ColorUtils.rgbToHsv(rgba); return { a: rgba.a, h: hsvResult.h, s: hsvResult.s, v: hsvResult.v }; } static getRandomRgbColor(min) { const fixedMin = min !== null && min !== void 0 ? min : 0; return { b: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256))), g: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256))), r: Math.floor(NumberUtils.randomInRange(NumberUtils.setRangeValue(fixedMin, 256))) }; } static getStyleFromRgb(color, opacity) { return `rgba(${color.r}, ${color.g}, ${color.b}, ${opacity !== null && opacity !== void 0 ? opacity : 1})`; } static getStyleFromHsl(color, opacity) { return `hsla(${color.h}, ${color.s}%, ${color.l}%, ${opacity !== null && opacity !== void 0 ? opacity : 1})`; } static getStyleFromHsv(color, opacity) { return ColorUtils.getStyleFromHsl(ColorUtils.hsvToHsl(color), opacity); } static mix(color1, color2, size1, size2) { let rgb1 = color1; let rgb2 = color2; if (rgb1.r === undefined) { rgb1 = ColorUtils.hslToRgb(color1); } if (rgb2.r === undefined) { rgb2 = ColorUtils.hslToRgb(color2); } return { b: NumberUtils.mix(rgb1.b, rgb2.b, size1, size2), g: NumberUtils.mix(rgb1.g, rgb2.g, size1, size2), r: NumberUtils.mix(rgb1.r, rgb2.r, size1, size2) }; } static replaceColorSvg(image, color, opacity) { if (!image.svgData) { return ""; } const svgXml = image.svgData; const rgbHex = /#([0-9A-F]{3,6})/gi; return svgXml.replace(rgbHex, () => ColorUtils.getStyleFromHsl(color, opacity)); } static getLinkColor(p1, p2, linkColor) { var _a, _b; if (linkColor === Constants.randomColorValue) { return ColorUtils.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 ColorUtils.mix(sourceColor, destColor, p1.getRadius(), p2.getRadius()); } else { const hslColor = sourceColor !== null && sourceColor !== void 0 ? sourceColor : destColor; if (hslColor) { return ColorUtils.hslToRgb(hslColor); } } } else { return linkColor; } } static getLinkRandomColor(optColor, blink, consent) { const color = typeof optColor === "string" ? optColor : optColor.value; if (color === Constants.randomColorValue) { if (consent) { return ColorUtils.colorToRgb({ value: color }); } else if (blink) { return Constants.randomColorValue; } else { return Constants.midColorValue; } } else { return ColorUtils.colorToRgb({ value: color }); } } static getHslFromAnimation(animation) { return animation !== undefined ? { h: animation.h.value, s: animation.s.value, l: animation.l.value } : undefined; } } ;// 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(); } class CanvasUtils { static 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(); } static clear(context, dimension) { context.clearRect(0, 0, dimension.width, dimension.height); } static drawLinkLine(context, width, begin, end, maxDistance, canvasSize, warp, backgroundMask, composite, colorLine, opacity, shadow) { let drawn = false; if (NumberUtils.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 = NumberUtils.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 = NumberUtils.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 = NumberUtils.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 = ColorUtils.getStyleFromRgb(colorLine, opacity); if (shadow.enable) { const shadowColor = ColorUtils.colorToRgb(shadow.color); if (shadowColor) { context.shadowBlur = shadow.blur; context.shadowColor = ColorUtils.getStyleFromRgb(shadowColor); } } context.stroke(); } static drawLinkTriangle(context, pos1, pos2, pos3, backgroundMask, composite, colorTriangle, opacityTriangle) { drawTriangle(context, pos1, pos2, pos3); if (backgroundMask) { context.globalCompositeOperation = composite; } context.fillStyle = ColorUtils.getStyleFromRgb(colorTriangle, opacityTriangle); context.fill(); } static drawConnectLine(context, width, lineStyle, begin, end) { context.save(); drawLine(context, begin, end); context.lineWidth = width; context.strokeStyle = lineStyle; context.stroke(); context.restore(); } static 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 = ColorUtils.mix(color1, color2, p1.getRadius(), p2.getRadius()); const grad = context.createLinearGradient(sourcePos.x, sourcePos.y, destPos.x, destPos.y); grad.addColorStop(0, ColorUtils.getStyleFromHsl(color1, opacity)); grad.addColorStop(gradStop > 1 ? 1 : gradStop, ColorUtils.getStyleFromRgb(midRgb, opacity)); grad.addColorStop(1, ColorUtils.getStyleFromHsl(color2, opacity)); return grad; } static drawGrabLine(context, width, begin, end, colorLine, opacity) { context.save(); drawLine(context, begin, end); context.strokeStyle = ColorUtils.getStyleFromRgb(colorLine, opacity); context.lineWidth = width; context.stroke(); context.restore(); } static drawLight(container, context, mousePos) { const lightOptions = container.actualOptions.interactivity.modes.light.area; context.beginPath(); context.arc(mousePos.x, mousePos.y, lightOptions.radius, 0, 2 * Math.PI); const gradientAmbientLight = context.createRadialGradient(mousePos.x, mousePos.y, 0, mousePos.x, mousePos.y, lightOptions.radius); const gradient = lightOptions.gradient; const gradientRgb = { start: ColorUtils.colorToRgb(gradient.start), stop: ColorUtils.colorToRgb(gradient.stop) }; if (!gradientRgb.start || !gradientRgb.stop) { return; } gradientAmbientLight.addColorStop(0, ColorUtils.getStyleFromRgb(gradientRgb.start)); gradientAmbientLight.addColorStop(1, ColorUtils.getStyleFromRgb(gradientRgb.stop)); context.fillStyle = gradientAmbientLight; context.fill(); } static drawParticleShadow(container, context, particle, mousePos) { const pos = particle.getPosition(); const shadowOptions = container.actualOptions.interactivity.modes.light.shadow; context.save(); const radius = particle.getRadius(); const sides = particle.sides; const full = Math.PI * 2 / sides; const angle = -particle.rotate.value + Math.PI / 4; const factor = 1; const dots = []; for (let i = 0; i < sides; i++) { dots.push({ x: pos.x + radius * Math.sin(angle + full * i) * factor, y: pos.y + radius * Math.cos(angle + full * i) * factor }); } const points = []; const shadowLength = shadowOptions.length; for (const dot of dots) { const dotAngle = Math.atan2(mousePos.y - dot.y, mousePos.x - dot.x); const endX = dot.x + shadowLength * Math.sin(-dotAngle - Math.PI / 2); const endY = dot.y + shadowLength * Math.cos(-dotAngle - Math.PI / 2); points.push({ endX: endX, endY: endY, startX: dot.x, startY: dot.y }); } const shadowRgb = ColorUtils.colorToRgb(shadowOptions.color); if (!shadowRgb) { return; } const shadowColor = ColorUtils.getStyleFromRgb(shadowRgb); for (let i = points.length - 1; i >= 0; i--) { const n = i == points.length - 1 ? 0 : i + 1; context.beginPath(); context.moveTo(points[i].startX, points[i].startY); context.lineTo(points[n].startX, points[n].startY); context.lineTo(points[n].endX, points[n].endY); context.lineTo(points[i].endX, points[i].endY); context.fillStyle = shadowColor; context.fill(); } context.restore(); } static drawParticle(container, context, particle, delta, fillColorValue, strokeColorValue, backgroundMask, composite, radius, opacity, shadow) { const pos = particle.getPosition(); context.save(); 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 = ColorUtils.getStyleFromRgb(shadowColor); context.shadowOffsetX = shadow.offset.x; context.shadowOffsetY = shadow.offset.y; } if (fillColorValue) { context.fillStyle = fillColorValue; } const stroke = particle.stroke; context.lineWidth = particle.strokeWidth; if (strokeColorValue) { context.strokeStyle = strokeColorValue; } CanvasUtils.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(); context.translate(pos.x, pos.y); if (angle !== 0) { context.rotate(angle); } if (backgroundMask) { context.globalCompositeOperation = composite; } CanvasUtils.drawShapeAfterEffect(container, context, particle, radius, opacity, delta); context.restore(); } static drawShape(container, context, particle, radius, opacity, delta) { if (!particle.shape) { return; } const drawer = container.drawers.get(particle.shape); if (!drawer) { return; } drawer.draw(context, particle, radius, opacity, delta, container.retina.pixelRatio); } static drawShapeAfterEffect(container, context, particle, radius, opacity, delta) { if (!particle.shape) { return; } const drawer = container.drawers.get(particle.shape); if (!(drawer === null || drawer === void 0 ? void 0 : drawer.afterEffect)) { return; } drawer.afterEffect(context, particle, radius, opacity, delta, container.retina.pixelRatio); } static drawPlugin(context, plugin, delta) { if (plugin.draw !== undefined) { context.save(); plugin.draw(context, delta); context.restore(); } } } ;// CONCATENATED MODULE: ./dist/browser/Utils/Range.js class Range { constructor(x, y) { this.position = { x: x, y: y }; } } ;// CONCATENATED MODULE: ./dist/browser/Utils/Circle.js class Circle extends Range { constructor(x, y, radius) { super(x, y); this.radius = radius; } contains(point) { const d = Math.pow(point.x - this.position.x, 2) + Math.pow(point.y - this.position.y, 2); return d <= this.radius * this.radius; } intersects(range) { const rect = range; const circle = range; const pos1 = this.position; const pos2 = range.position; const xDist = Math.abs(pos2.x - pos1.x); const yDist = Math.abs(pos2.y - pos1.y); const r = this.radius; if (circle.radius !== undefined) { const rSum = r + circle.radius; const dist = Math.sqrt(xDist * xDist + yDist + yDist); return rSum > dist; } else if (rect.size !== undefined) { const w = rect.size.width; const h = rect.size.height; const edges = Math.pow(xDist - w, 2) + Math.pow(yDist - h, 2); if (xDist > r + w || yDist > r + h) { return false; } if (xDist <= w || yDist <= h) { return true; } return edges <= r * r; } return false; } } ;// CONCATENATED MODULE: ./dist/browser/Utils/Rectangle.js class Rectangle extends Range { constructor(x, y, width, height) { super(x, y); this.size = { height: height, width: width }; } contains(point) { const w = this.size.width; const h = this.size.height; const pos = this.position; return point.x >= pos.x && point.x <= pos.x + w && point.y >= pos.y && point.y <= pos.y + h; } intersects(range) { const rect = range; const circle = range; const w = this.size.width; const h = this.size.height; const pos1 = this.position; const pos2 = range.position; if (circle.radius !== undefined) { return circle.intersects(this); } else if (rect.size !== undefined) { const size2 = rect.size; const w2 = size2.width; const h2 = size2.height; return pos2.x < pos1.x + w && pos2.x + w2 > pos1.x && pos2.y < pos1.y + h && pos2.y + h2 > pos1.y; } return false; } } ;// CONCATENATED MODULE: ./dist/browser/Utils/CircleWarp.js class CircleWarp extends Circle { constructor(x, y, radius, canvasSize) { super(x, y, radius); this.canvasSize = canvasSize; this.canvasSize = { height: canvasSize.height, width: canvasSize.width }; } contains(point) { if (super.contains(point)) { return true; } const posNE = { x: point.x - this.canvasSize.width, y: point.y }; if (super.contains(posNE)) { return true; } const posSE = { x: point.x - this.canvasSize.width, y: point.y - this.canvasSize.height }; if (super.contains(posSE)) { return true; } const posSW = { x: point.x, y: point.y - this.canvasSize.height }; return super.contains(posSW); } intersects(range) { if (super.intersects(range)) { return true; } const rect = range; const circle = range; const newPos = { x: range.position.x - this.canvasSize.width, y: range.position.y - this.canvasSize.height }; if (circle.radius !== undefined) { const biggerCircle = new Circle(newPos.x, newPos.y, circle.radius * 2); return super.intersects(biggerCircle); } else if (rect.size !== undefined) { const rectSW = new Rectangle(newPos.x, newPos.y, rect.size.width * 2, rect.size.height * 2); return super.intersects(rectSW); } return false; } } ;// 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["l