/*!
 * VisualEditor common LESS mixins.
 *
 * @copyright See AUTHORS.txt
 * @license The MIT License (MIT); see LICENSE.txt
 */

/* stylelint-disable-next-line selector-class-pattern */
.solid-to-opacity( @color, @opacity, @background: #fff ) {
	@result: fade( ( ( @color - ( 1 - @opacity ) * ( @background ) ) / @opacity ), @opacity * 100 );
}

/**
 * Compute the most transparent color that appears the same as @color
 * when overlaid on the given @background.
 *
 * @example
 *   background-color: .solid-to-minimum-opacity( #eaecf0 )[ @result ];
 *
 * @param {Color} @color The solid color to approximate with transparency
 * @param {Color} [@background=white] The background color to overlay on
 * @return {Color} @result
 */
/* stylelint-disable-next-line selector-class-pattern */
.solid-to-minimum-opacity( @color, @background: #fff ) {
	@opacity: 1 - ( min( red( @color ), green( @color ), blue( @color ) ) / 255 );
	@result: .solid-to-opacity( @color, @opacity, @background )[ @result ];
}
