1
0
Fork 0

chore(core): Make generatePartTransform a named export

This commit is contained in:
Joost De Cock 2022-07-02 20:05:31 +02:00
parent 20440b9830
commit 7a33cf1783
3 changed files with 30 additions and 25 deletions

View file

@ -359,3 +359,28 @@ export function pctBasedOn(measurement) {
fromAbs: (val, { measurements }) => Math.round((10 * val) / measurements[measurement]) / 10,
}
}
/** Generates the transform attributes needed for a given part */
export const generatePartTransform = (x, y, rotate, flipX, flipY, part) => {
const center = {
x: part.topLeft.x + (part.bottomRight.x - part.topLeft.x)/2,
y: part.topLeft.y + (part.bottomRight.y - part.topLeft.y)/2,
}
const transforms = [`translate(${x},${y})`]
if (flipX) transforms.push(
'scale(-1, 1)',
)
if (flipY) transforms.push(
'scale(1, -1)',
)
if (rotate) transforms.push(
`rotate(${rotate})`
)
return {
transform: transforms.join(' '),
'transform-origin': `${center.x} ${center.y}`
}
}