0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-05 06:10:52 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformRotationAndPosition.ts
Alex Sánchez 3da80b4c26
Fix transformed shapes (#236)
* fix transformed shapes

* minor fix
2024-11-14 15:42:45 +01:00

43 lines
1.2 KiB
TypeScript

import { translateRotation, translateZeroRotation } from '@plugin/translators';
import { applyInverseRotation, getRotation, isTransformed } from '@plugin/utils';
import { ShapeBaseAttributes, ShapeGeomAttributes } from '@ui/lib/types/shapes/shape';
export const transformRotation = (
node: LayoutMixin
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> => {
const rotation = getRotation(node.absoluteTransform);
return translateRotation(node.absoluteTransform, rotation);
};
export const transformRotationAndPosition = (
node: LayoutMixin
): Pick<ShapeBaseAttributes, 'transform' | 'transformInverse' | 'rotation'> &
Pick<ShapeGeomAttributes, 'x' | 'y'> => {
const x = node.absoluteTransform[0][2];
const y = node.absoluteTransform[1][2];
const rotation = getRotation(node.absoluteTransform);
if (
!node.absoluteBoundingBox ||
!isTransformed(node.absoluteTransform, node.absoluteBoundingBox)
) {
return {
x,
y,
...translateZeroRotation()
};
}
const referencePoint = applyInverseRotation(
{ x, y },
node.absoluteTransform,
node.absoluteBoundingBox
);
return {
...referencePoint,
...translateRotation(node.absoluteTransform, rotation)
};
};