Skip to content

Commit

Permalink
Reorder private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
sculpt0r committed Dec 11, 2020
1 parent 58c1b69 commit 33992fa
Showing 1 changed file with 43 additions and 44 deletions.
87 changes: 43 additions & 44 deletions core/tools/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,19 +345,16 @@
},

/**
* TODO
* Convert 3-characters hexadecimal color format to 6-characters one.
*
* @param {Number} red
* @param {Number} green
* @param {Number} blue
* @param {Number} alpha
* @returns {Boolean}
* @private
* @param {String} hex3ColorCode 3-characters hexadecimal color, e.g. `#F0F`.
* @returns {String} 6-characters hexadecimal color e.g. `#FF00FF`.
*/
areColorChannelsValid: function( red, green, blue, alpha ) {
return isValueWithinRange( red, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( green, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( blue, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( alpha, 0, CKEDITOR.tools.color.MAX_ALPHA_CHANNEL_VALUE );
hex3ToHex6: function( hex3ColorCode ) {
var parts = hex3ColorCode.split( '' );

return '#' + parts[ 1 ] + parts[ 1 ] + parts[ 2 ] + parts[ 2 ] + parts[ 3 ] + parts[ 3 ];
},

/**
Expand Down Expand Up @@ -385,16 +382,44 @@
},

/**
* Convert 3-characters hexadecimal color format to 6-characters one.
* TODO
*
* @param {Number} red
* @param {Number} green
* @param {Number} blue
* @param {Number} alpha
* @returns {Boolean}
*/
areColorChannelsValid: function( red, green, blue, alpha ) {
return isValueWithinRange( red, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( green, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( blue, 0, CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE ) &&
isValueWithinRange( alpha, 0, CKEDITOR.tools.color.MAX_ALPHA_CHANNEL_VALUE );
},

/**
* Convert hsl values into rgb.
*
* @private
* @param {String} hex3ColorCode 3-characters hexadecimal color, e.g. `#F0F`.
* @returns {String} 6-characters hexadecimal color e.g. `#FF00FF`.
* @param {Number} hue
* @param {Number} saturation
* @param {Number} lightness
* @returns {Array} Array of decimal rgb values.
*/
hex3ToHex6: function( hex3ColorCode ) {
var parts = hex3ColorCode.split( '' );
hslToRgb: function( hue, saturation, lightness ) {
// Based on https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB.
var calculateValueFromConst = function( fixValue ) {
var k = ( fixValue + ( hue / 30 ) ) % 12,
a = saturation * Math.min( lightness, 1 - lightness );

return '#' + parts[ 1 ] + parts[ 1 ] + parts[ 2 ] + parts[ 2 ] + parts[ 3 ] + parts[ 3 ];
var min = Math.min( k - 3, 9 - k, 1 ),
max = Math.max( -1, min ),
normalizedValue = lightness - ( a * max );

return Math.round( normalizedValue * CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE );
};

return [ calculateValueFromConst( 0 ), calculateValueFromConst( 8 ), calculateValueFromConst( 4 ) ];
},

/**
Expand Down Expand Up @@ -441,33 +466,9 @@
lightness = lightness * 100;

return [ hue, saturation, lightness ];
},

/**
* Convert hsl values into rgb.
*
* @private
* @param {Number} hue
* @param {Number} saturation
* @param {Number} lightness
* @returns {Array} Array of decimal rgb values.
*/
hslToRgb: function( hue, saturation, lightness ) {
// Based on https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB.
var calculateValueFromConst = function( fixValue ) {
var k = ( fixValue + ( hue / 30 ) ) % 12,
a = saturation * Math.min( lightness, 1 - lightness );

var min = Math.min( k - 3, 9 - k, 1 ),
max = Math.max( -1, min ),
normalizedValue = lightness - ( a * max );

return Math.round( normalizedValue * CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE );
};

return [ calculateValueFromConst( 0 ), calculateValueFromConst( 8 ), calculateValueFromConst( 4 ) ];
}
},

statics: {
/**
* Regular expression to match three characters long hexadecimal color value.
Expand Down Expand Up @@ -674,7 +675,6 @@
}
} );


CKEDITOR.tools.color.MAX_RGB_CHANNEL_VALUE = 255;

CKEDITOR.tools.color.MAX_ALPHA_CHANNEL_VALUE = 1;
Expand Down Expand Up @@ -729,7 +729,6 @@
return value;
}


// Validate if given value is string type and ends with `%` character.
// @param {*} value any value.
// @returns {Boolean}
Expand Down

0 comments on commit 33992fa

Please sign in to comment.