From 43fcff12fc45aae102dde1f99fded66e67f0b8fa Mon Sep 17 00:00:00 2001 From: zombieFox Date: Sun, 22 Dec 2019 17:12:19 +0000 Subject: [PATCH] [refactor] helper colour convert naming --- src/js/helper.js | 19 +++++++++---------- src/js/theme.js | 10 +++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/js/helper.js b/src/js/helper.js index 957625ef..55d12fa9 100644 --- a/src/js/helper.js +++ b/src/js/helper.js @@ -659,13 +659,13 @@ var helper = (function() { }; }; - var convert = { + var convertColor = { rgb: {}, hsl: {}, hex: {} }; - convert.rgb.hsl = function(rgb) { + convertColor.rgb.hsl = function(rgb) { const r = rgb[0] / 255; const g = rgb[1] / 255; const b = rgb[2] / 255; @@ -704,8 +704,8 @@ var helper = (function() { return [h, s * 100, l * 100]; }; - convert.rgb.lab = function(rgb) { - const xyz = convert.rgb.xyz(rgb); + convertColor.rgb.lab = function(rgb) { + const xyz = convertColor.rgb.xyz(rgb); let x = xyz[0]; let y = xyz[1]; let z = xyz[2]; @@ -725,7 +725,7 @@ var helper = (function() { return [l, a, b]; }; - convert.rgb.xyz = function(rgb) { + convertColor.rgb.xyz = function(rgb) { let r = rgb[0] / 255; let g = rgb[1] / 255; let b = rgb[2] / 255; @@ -742,7 +742,7 @@ var helper = (function() { return [x * 100, y * 100, z * 100]; }; - convert.rgb.hex = function(args) { + convertColor.rgb.hex = function(args) { const integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF); @@ -751,7 +751,7 @@ var helper = (function() { return '000000'.substring(string.length) + string; }; - convert.hsl.rgb = function(hsl) { + convertColor.hsl.rgb = function(hsl) { const h = hsl[0] / 360; const s = hsl[1] / 100; const l = hsl[2] / 100; @@ -799,7 +799,7 @@ var helper = (function() { return rgb; }; - convert.hex.rgb = function(args) { + convertColor.hex.rgb = function(args) { const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); if (!match) { return [0, 0, 0]; @@ -821,7 +821,6 @@ var helper = (function() { return [r, g, b]; }; - // exposed methods return { e: e, @@ -850,7 +849,7 @@ var helper = (function() { ordinalNumber: ordinalNumber, isJsonString: isJsonString, isHexNumber: isHexNumber, - convert: convert + convertColor: convertColor }; })(); diff --git a/src/js/theme.js b/src/js/theme.js index 8e122785..c02ed83a 100644 --- a/src/js/theme.js +++ b/src/js/theme.js @@ -21,13 +21,13 @@ var theme = (function() { mod.color = { hsl: function() { - var hsl = helper.convert.rgb.hsl([state.get.current().theme.color.rgb.r, state.get.current().theme.color.rgb.g, state.get.current().theme.color.rgb.b]); + var hsl = helper.convertColor.rgb.hsl([state.get.current().theme.color.rgb.r, state.get.current().theme.color.rgb.g, state.get.current().theme.color.rgb.b]); state.get.current().theme.color.hsl.h = parseInt(hsl[0], 10); state.get.current().theme.color.hsl.s = parseInt(hsl[1], 10); state.get.current().theme.color.hsl.l = parseInt(hsl[2], 10); }, rgb: function() { - var rgb = helper.convert.hsl.rgb([state.get.current().theme.color.hsl.h, state.get.current().theme.color.hsl.s, state.get.current().theme.color.hsl.l]); + var rgb = helper.convertColor.hsl.rgb([state.get.current().theme.color.hsl.h, state.get.current().theme.color.hsl.s, state.get.current().theme.color.hsl.l]); state.get.current().theme.color.rgb.r = parseInt(rgb[0], 10); state.get.current().theme.color.rgb.g = parseInt(rgb[1], 10); state.get.current().theme.color.rgb.b = parseInt(rgb[2], 10); @@ -133,7 +133,7 @@ var theme = (function() { var lMod = 4; var html = helper.e("html"); - var hsl = helper.convert.rgb.hsl([state.get.current().theme.color.rgb.r, state.get.current().theme.color.rgb.g, state.get.current().theme.color.rgb.b]); + var hsl = helper.convertColor.rgb.hsl([state.get.current().theme.color.rgb.r, state.get.current().theme.color.rgb.g, state.get.current().theme.color.rgb.b]); // base color html.style.setProperty("--theme-shade", state.get.current().theme.color.rgb.r + ", " + state.get.current().theme.color.rgb.g + ", " + state.get.current().theme.color.rgb.b); @@ -142,7 +142,7 @@ var theme = (function() { var h = hsl[0]; var s = (hsl[1] - (sMod * i)); var l = (hsl[2] - (lMod * i)); - var rgb = helper.convert.hsl.rgb([h, s, l]); + var rgb = helper.convertColor.hsl.rgb([h, s, l]); var number; if (i < 10) { number = "0" + i; @@ -156,7 +156,7 @@ var theme = (function() { var h = hsl[0]; var s = (hsl[1] + (sMod * i)); var l = (hsl[2] + (lMod * i)); - var rgb = helper.convert.hsl.rgb([h, s, l]); + var rgb = helper.convertColor.hsl.rgb([h, s, l]); var number; if (i < 10) { number = "0" + i;