     guard let (r, g, b, _) = self.rgba else { fatalError("Couldn't calculate RGBA values") }
     return (UInt32(r) << 16) | (UInt32(g) << 8) | UInt32(b)
   }
-
+  
   /// **Mechanica**
   ///
   /// Returns an UInt32 representation of `self` in the sRGB space with alpha channel.

  ///   - hex: The hex component of the color object, specified as a value from 0x000000 to 0xFFFFFF
  ///   - alpha: The opacity component of the color object, specified as a value from 0.0 to 1.0 (optional).
  public convenience init(hex: UInt32, alpha: CGFloat = 1) {

    let red   = CGFloat((hex & 0xFF0000) >> 16) / 255
    let green = CGFloat((hex & 0x00FF00) >> 8) / 255
    let blue  = CGFloat(hex & 0x0000FF) / 255

    #if os(iOS) || os(tvOS) || os(watchOS)
      self.init(red: red, green: green, blue: blue, alpha: alpha)
    #else
      self.init(srgbRed: red, green: green, blue: blue, alpha: alpha)
    #endif
  }

  /// **Mechanica**
  ///
  /// Returns a color from a given hex color string.

// MARK: - iOS, tvOS, watchOS

#if os(iOS) || os(tvOS) || os(watchOS)
  
  extension Color {
    
    /// **Mechanica**
    ///
    /// Returns the components that make up the color in the sRGB color space.
    public final var rgba: (red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8)? {
      
      guard let space = self.cgColor.colorSpace, let colorSpaceName = space.name else { return nil}
      
      let compatibleSRGBColor = (colorSpaceName == CGColorSpace.sRGB) ? self: self.convertingToCompatibleSRGBColor()
      guard let color = compatibleSRGBColor else { return nil }
      
      var r : CGFloat = .nan, g : CGFloat = .nan, b : CGFloat = .nan, a : CGFloat = .nan
      guard color.getRed(&r, green: &g, blue: &b, alpha: &a)  else { return nil } // could not be converted
      
      //guard (0.0...1.0 ~= r && 0.0...1.0 ~= g && 0.0...1.0 ~= b && 0.0...1.0 ~= a) else { return nil } // invalid sRGB color
      
      return (red: UInt8(r * 255), green: UInt8(g * 255), blue: UInt8(b * 255), alpha: UInt8(a * 255))
    }
    
  }
  
#endif

// MARK: - macOS

#if os(OSX)
  
  extension Color {
    
    /// **Mechanica**
    ///
    /// Returns the components that make up the color in the sRGB color space.
    public final var rgba: (red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8)? {
      
      let rgbColorSpaces: [NSColorSpace] = [.sRGB, .deviceRGB, .genericRGB]
      let compatibleSRGBColor = (rgbColorSpaces.contains(self.colorSpace)) ? self : self.usingColorSpace(.sRGB)
      
      guard let color = compatibleSRGBColor else { return nil } // Could not be converted
      
      var r : CGFloat = .nan, g : CGFloat = .nan, b : CGFloat = .nan, a : CGFloat = .nan
      color.getRed(&r, green: &g, blue: &b, alpha: &a)
      
      //guard (0.0...1.0 ~= r && 0.0...1.0 ~= g && 0.0...1.0 ~= b && 0.0...1.0 ~= a) else { return nil } // invalid sRGB color
      
      return (red: UInt8(r * 255), green: UInt8(g * 255), blue: UInt8(b * 255), alpha: UInt8(a * 255))
    }
    
  }
  
#endif

// MARK: - Universal

extension Color {
  
  // MARK: - sRGBA
  
  /// **Mechanica**
  ///
  /// Creates a `new` color in the **sRGB** color space that matches (or *closely approximates*) the current color.
  /// - Note: [WWDC 2016 - 712](https://developer.apple.com/videos/play/wwdc2016/712/?time=2368)
  public final func convertingToCompatibleSRGBColor() -> Color? {
    
    #if os(iOS) || os(tvOS) || os(watchOS)
      guard let colorSpace = CGColorSpace(name: CGColorSpace.sRGB) else { return nil }
      let compatibleSRGBColor = self.cgColor.converted(to: colorSpace, intent: CGColorRenderingIntent.defaultIntent, options: nil)!
