[ Index ]

Search

title

Body

[close]

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

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

 Generated : Sat Jun 19 08:20:01 2021 Cross-referenced by PHPXref