[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentytwentyone/assets/js/ -> customize-helpers.js (source)

   1  /**
   2   * Get luminance from a HEX color.
   3   *
   4   * @since Twenty Twenty-One 1.0
   5   *
   6   * @param {string} hex - The hex color.
   7   *
   8   * @return {number} - Returns the luminance, number between 0 and 255.
   9   */
  10  function twentytwentyoneGetHexLum( hex ) { // jshint ignore:line
  11      var rgb = twentytwentyoneGetRgbFromHex( hex );
  12      return Math.round( ( 0.2126 * rgb.r ) + ( 0.7152 * rgb.g ) + ( 0.0722 * rgb.b ) );
  13  }
  14  
  15  /**
  16   * Get RGB from HEX.
  17   *
  18   * @since Twenty Twenty-One 1.0
  19   *
  20   * @param {string} hex - The hex color.
  21   *
  22   * @return {Object} - Returns an object {r, g, b}
  23   */
  24  function twentytwentyoneGetRgbFromHex( hex ) {
  25      var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i,
  26          result;
  27  
  28      // Expand shorthand form (e.g. "03F") to full form (e.g. "0033FF").
  29      hex = hex.replace( shorthandRegex, function( m, r, g, b ) {
  30          return r.toString() + r.toString() + g.toString() + g.toString() + b.toString() + b.toString();
  31      } );
  32  
  33      result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec( hex );
  34      return result ? {
  35          r: parseInt( result[1], 16 ),
  36          g: parseInt( result[2], 16 ),
  37          b: parseInt( result[3], 16 )
  38      } : null;
  39  }


Generated: Wed Apr 24 01:00:03 2024 Cross-referenced by PHPXref 0.7.1