chore(core): Make generatePartTransform a named export
This commit is contained in:
parent
20440b9830
commit
7a33cf1783
3 changed files with 30 additions and 25 deletions
|
@ -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}`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue