fix(ot): use default color constant for hex2rgb fallback
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
committed by
Philip Molares
parent
65bf11554a
commit
c4841575c9
8
public/vendor/ot/hex2rgb.js
vendored
8
public/vendor/ot/hex2rgb.js
vendored
@@ -1,16 +1,18 @@
|
||||
const defaultColor = { red: 0, green: 0, blue: 0 }
|
||||
|
||||
function hex2rgb (hex) {
|
||||
if (!hex || typeof hex !== 'string') return { red: 0, green: 0, blue: 0 }
|
||||
if (!hex || typeof hex !== 'string') return defaultColor
|
||||
if (hex[0] == '#') hex = hex.substr(1)
|
||||
if (hex.length == 3) {
|
||||
var temp = hex
|
||||
hex = ''
|
||||
var match = /^([a-f0-9])([a-f0-9])([a-f0-9])$/i.exec(temp)
|
||||
if (!match) return { red: 0, green: 0, blue: 0 }
|
||||
if (!match) return defaultColor
|
||||
temp = match.slice(1)
|
||||
for (var i = 0; i < 3; i++) hex += temp[i] + temp[i]
|
||||
}
|
||||
var result = /^([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i.exec(hex)
|
||||
if (!result) return { red: 0, green: 0, blue: 0 }
|
||||
if (!result) return defaultColor
|
||||
var triplets = result.slice(1)
|
||||
return {
|
||||
red: parseInt(triplets[0], 16),
|
||||
|
||||
Reference in New Issue
Block a user