mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 21:53:27 -05:00
af81fc7e92
* Implement rotation for vector lines * wip * Improve rotations for lines * add changelog * add layout attributes to line
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import { applyInverseRotation, hasRotation } from '@plugin/utils';
|
|
|
|
import { ShapeBaseAttributes, ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';
|
|
|
|
export const transformRotationAndPosition = (
|
|
node: LayoutMixin,
|
|
baseX: number,
|
|
baseY: number
|
|
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> &
|
|
Pick<ShapeGeomAttributes, 'x' | 'y'> => {
|
|
const rotation = node.rotation;
|
|
const x = node.x + baseX;
|
|
const y = node.y + baseY;
|
|
|
|
if (!hasRotation(rotation) || !node.absoluteBoundingBox) {
|
|
return {
|
|
x,
|
|
y,
|
|
rotation,
|
|
transform: undefined,
|
|
transformInverse: undefined
|
|
};
|
|
}
|
|
|
|
const referencePoint = applyInverseRotation(
|
|
{ x, y },
|
|
node.absoluteTransform,
|
|
node.absoluteBoundingBox
|
|
);
|
|
|
|
return {
|
|
...referencePoint,
|
|
rotation: -rotation < 0 ? -rotation + 360 : -rotation,
|
|
transform: {
|
|
a: node.absoluteTransform[0][0],
|
|
b: node.absoluteTransform[1][0],
|
|
c: node.absoluteTransform[0][1],
|
|
d: node.absoluteTransform[1][1],
|
|
e: 0,
|
|
f: 0
|
|
},
|
|
transformInverse: {
|
|
a: node.absoluteTransform[0][0],
|
|
b: node.absoluteTransform[0][1],
|
|
c: node.absoluteTransform[1][0],
|
|
d: node.absoluteTransform[1][1],
|
|
e: 0,
|
|
f: 0
|
|
}
|
|
};
|
|
};
|