2022-04-12 15:16:00 +00:00
|
|
|
export function calculateBackgroundImagePosition( coords ) {
|
|
|
|
if ( ! coords ) return {};
|
2019-08-02 11:56:53 +00:00
|
|
|
|
2022-04-12 15:16:00 +00:00
|
|
|
const x = Math.round( coords.x * 100 );
|
|
|
|
const y = Math.round( coords.y * 100 );
|
2019-08-02 11:56:53 +00:00
|
|
|
|
2022-04-12 15:16:00 +00:00
|
|
|
return {
|
|
|
|
objectPosition: `${ x }% ${ y }%`,
|
|
|
|
};
|
2019-08-02 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert the selected ratio to the correct background class.
|
|
|
|
*
|
|
|
|
* @param {number} ratio Selected opacity from 0 to 100.
|
2022-04-12 15:16:00 +00:00
|
|
|
* @return {string?} The class name, if applicable (not used for ratio 0 or 50).
|
2019-08-02 11:56:53 +00:00
|
|
|
*/
|
2022-04-12 15:16:00 +00:00
|
|
|
export function dimRatioToClass( ratio ) {
|
2019-09-05 15:09:31 +00:00
|
|
|
return ratio === 0 || ratio === 50
|
|
|
|
? null
|
|
|
|
: `has-background-dim-${ 10 * Math.round( ratio / 10 ) }`;
|
2019-08-02 11:56:53 +00:00
|
|
|
}
|