2024-06-14 03:33:23 -05:00
|
|
|
import { applyInverseRotation, hasRotation } from '@plugin/utils';
|
|
|
|
|
2024-05-29 03:30:56 -05:00
|
|
|
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;
|
|
|
|
|
2024-06-14 03:33:23 -05:00
|
|
|
if (!hasRotation(rotation) || !node.absoluteBoundingBox) {
|
2024-05-29 03:30:56 -05:00
|
|
|
return {
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
rotation,
|
|
|
|
transform: undefined,
|
|
|
|
transformInverse: undefined
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-06-14 03:33:23 -05:00
|
|
|
const referencePoint = applyInverseRotation(
|
|
|
|
{ x, y },
|
|
|
|
node.absoluteTransform,
|
|
|
|
node.absoluteBoundingBox
|
|
|
|
);
|
2024-05-29 03:30:56 -05:00
|
|
|
|
|
|
|
return {
|
2024-06-14 03:33:23 -05:00
|
|
|
...referencePoint,
|
2024-05-29 03:30:56 -05:00
|
|
|
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
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|