Gest Invert Color
by lmcdevloper
HTML
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"></script>
<p class="color-1">
Hellow World!
</p>
CSS
.color-1{
background-color: red;
}
JavaScript
/*! @license https://github.com/onury/invert-color */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.invert = factory());
}(this, (function () { 'use strict';
// -------------------------------
// TYPES / INTERFACES
// -------------------------------
// -------------------------------
// CONSTANTS
// -------------------------------
var DEFAULT_THRESHOLD = Math.sqrt(1.05 * 0.05) - 0.05;
var RE_HEX = /^(?:[0-9a-f]{3}){1,2}$/i;
var DEFAULT_BW = {
black: '#000000',
white: '#ffffff',
threshold: DEFAULT_THRESHOLD
};
// -------------------------------
// HELPER METHODS
// -------------------------------
function padz(str, len) {
if (len === void 0) { len = 2; }
return (new Array(len).join('0') + str).slice(-len);
}
function hexToRgbArray(hex) {
if (hex.slice(0, 1) === '#')
hex = hex.slice(1);
if (!RE_HEX.test(hex))
throw new Error("Invalid HEX color: \"" + hex + "\"");
// normalize / convert 3-chars hex to 6-chars.
if (hex.length === 3) {
hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
}
return [
parseInt(hex.slice(0, 2), 16),
parseInt(hex.slice(2, 4), 16),
parseInt(hex.slice(4, 6), 16) // b
];
}
function toRGB(c) {
return { r: c[0], g: c[1], b: c[2] };
}
function toRgbArray(c) {
if (!c)
throw new Error('Invalid color value');
if (Array.isArray(c))
return c;
return typeof c === 'string' ? hexToRgbArray(c) : [c.r, c.g, c.b];
}
// http://stackoverflow.com/a/3943023/112731
function getLuminance(c) {
var i, x;
var a = []; // so we don't mutate
for (i = 0; i < c.length; i++)...