function invertHex(hexnum) { if (hexnum.indexOf("#")===0) { hexnum = hexnum.substring(1, hexnum.length); } if(hexnum.length !== 6) { return "000000"; } hexnum = hexnum.toUpperCase(); let splitnum = hexnum.split(""); let resultnum = ""; let simplenum = "FEDCBA9876".split(""); let complexnum = new Array(); complexnum.A = "5"; complexnum.B = "4"; complexnum.C = "3"; complexnum.D = "2"; complexnum.E = "1"; complexnum.F = "0"; for(i=0; i<6; i++){ if(!isNaN(splitnum[i])) { resultnum += simplenum[splitnum[i]]; } else if(complexnum[splitnum[i]]){ resultnum += complexnum[splitnum[i]]; } else { return false; } } return resultnum; } function b64EncodeUnicode(str){ return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { return String.fromCharCode('0x' + p1); })); } function b64DecodeUnicode(str) { return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) }).join('')) } function rgbToHex(rgb) { if (/^#[0-9A-F]{6}$/i.test(rgb)) return rgb.replace("#", ""); rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/); function hex(x) { return ("0" + parseInt(x).toString(16)).slice(-2); } return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); } function hexToRgba(hex, opacity) { let h = hex.replace('#', ''); let r = parseInt(h.substring(0, 2), 16); let g = parseInt(h.substring(2, 4), 16); let b = parseInt(h.substring(4, 6), 16); return 'rgba(' + r + ',' + g + ',' + b + ',' + opacity / 100 + ')'; } function hexToRgb(hex) { let h = hex.replace('#', ''); let color = []; color[0] = parseInt(h.substring(0, 2), 16); color[1] = parseInt(h.substring(2, 4), 16); color[2] = parseInt(h.substring(4, 6), 16); return color; } function hex2Hsla(hexColor,alpha) { let hexStr = hexColor.replace('#',''); let hexApply = hexStr; if (hexStr.length === 3){ hexApply = ''; for (let i = 3;i>0;i--){ hexApply += hexStr[hexStr.length-i] + hexStr[hexStr.length-i]; } } let result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hexApply); r = parseInt(result[1], 16); g = parseInt(result[2], 16); b = parseInt(result[3], 16); r /= 255, g /= 255, b /= 255; let max = Math.max(r, g, b), min = Math.min(r, g, b); let h, s, l = (max + min) / 2; if(max === min){ h = s = 0; // achromatic }else{ var d = max - min; s = l > 0.5 ? d / (2 - max - min) : d / (max + min); switch(max){ case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } let HSLA = {}; HSLA.h=h; HSLA.s=s; HSLA.l=l; HSLA.a= typeof alpha !== 'undefined'? alpha:1; return HSLA; } function hex2Hsl(hex){ return hex2Hsla(hex,1); } function hex2HslaGradePercentages(hexColor,alpha){ let hsla = hex2Hsla(hexColor,alpha); return { h: Math.ceil(hsla.h*360), s: hsla.s*100, l: hsla.l*100, a: typeof alpha !== 'undefined'?alpha*100:100 } } function hex(c) { let s = '0123456789abcdef'; let i = parseInt(c, 10); if (i === 0 || isNaN(c)) { return '00'; } i = Math.round(Math.min(Math.max(0, i), 255)); return s.charAt((i - i % 16) / 16) + s.charAt(i % 16); } function convertToHex(rgb) { return this.hex(rgb[0]) + this.hex(rgb[1]) + this.hex(rgb[2]); } function convertRgbTextToHex(rgb) { rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); return convertToHex(_.slice(rgb,1)); } function countDecimals(value) { if (Math.floor(value) !== value) return value.toString().split(".")[1].length || 0; return 0; } function convertValueDecToBin(value){ return (+value).toString(2); } function convertValueBinToDec(value){ return parseInt(value,2); } function convertValueDecToHex(value){ return (+value).toString(16).toUpperCase(); } function convertValueDecToBinMask(value, mask){ let arrayMask = mask.split(","); let binValue = convertValueDecToBin(value); let result = ""; for (let i=0; i= binValue.length){ result += "0"; } else { result += binValue.charAt(binValue.length - arrayMask[i] - 1); } } return result; } function convertValueHexToDec(value){ return parseInt(value,16); } function convertValueHexToBinMask(value, mask){ let decValue = convertValueHexToDec(value); return convertValueDecToBinMask(decValue, mask); } function convertValueBinMaskToDec(value, mask){ let arrayMask = mask.split(","); let result = 0; for (let i=0; i