lion/packages/overlays/test-helpers/local-positioning-helpers.js
Thijs Louisse 364f185ad8 feat(overlays): release new overlay system
Co-authored-by: Thomas Allmer <Thomas.Allmer@ing.com>
Co-authored-by: Joren Broekema <Joren.Broekema@ing.com>
Co-authored-by: Mikhail Bashkirov <Mikhail.Bashkirov@ing.com>
2019-10-10 17:14:24 +02:00

16 lines
613 B
JavaScript

/**
* @desc Compensates for browsers that use floats in output
* - from: 'transform3d(12.25px, 6.75px, 0px)'
* - to: 'transform3d(12px, 7px, 0px)'
* @param {string} cssValue
*/
export function normalizeTransformStyle(cssValue) {
// eslint-disable-next-line no-unused-vars
const [_, transformType, positionPart] = cssValue.match(/(.*)\((.*?)\)/);
const normalizedNumbers = positionPart
.split(',')
.map(p => Math.round(Number(p.replace('px', ''))));
return `${transformType}(${normalizedNumbers
.map((n, i) => `${n}px${normalizedNumbers.length - 1 === i ? '' : ', '}`)
.join('')})`;
}