UNPKG

namillum

Version:
65 lines (50 loc) 2.08 kB
// Copyright (C) 2020 Zilliqa // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <https:www.gnu.org/licenses/>. function animateCSS(element, animationName, callback) { const node = document.querySelector(element); node.classList.add("animated", animationName); function handleAnimationEnd() { node.classList.remove("animated", animationName); node.removeEventListener("animationend", handleAnimationEnd); if (typeof callback === "function") callback(); } node.addEventListener("animationend", handleAnimationEnd); } function lightOrDark(color) { // Variables for red, green, blue values var r, g, b, hsp; // Check the format of the color, HEX or RGB? if (color.match(/^rgb/)) { // If RGB --> store the red, green, blue values in separate variables color = color.match( /^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/ ); r = color[1]; g = color[2]; b = color[3]; } else { // If hex --> Convert it to RGB: http://gist.github.com/983661 color = +("0x" + color.slice(1).replace(color.length < 5 && /./g, "$&$&")); r = color >> 16; g = (color >> 8) & 255; b = color & 255; } // HSP (Highly Sensitive Poo) equation from http://alienryderflex.com/hsp.html hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b)); // Using the HSP value, determine whether the color is light or dark if (hsp > 127.5) { return "light"; } else { return "dark"; } } export { animateCSS, lightOrDark };