0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/vectors/translateRotatedCommands.ts
Jordi Sala Morales 202e7f4fda
Apply rotations to any figure (#168)
* Apply rotations to any figure

* add changelog

* apply rotations to curves too
2024-06-17 12:14:16 +02:00

31 lines
867 B
TypeScript

import { Command } from 'svg-path-parser';
import { applyInverseRotation, applyRotationToSegment } from '@plugin/utils';
import { ClosePath, Segment } from '@ui/lib/types/shapes/pathShape';
import { translateNonRotatedCommand } from '.';
const isClosePath = (segment: Segment): segment is ClosePath => segment.command === 'close-path';
export const translateRotatedCommands = (
commands: Command[],
transform: Transform,
boundingBox: Rect
): Segment[] => {
const referencePoint = applyInverseRotation(
{ x: transform[0][2], y: transform[1][2] },
transform,
boundingBox
);
return commands.map(command => {
const segment = translateNonRotatedCommand(command, referencePoint.x, referencePoint.y);
if (isClosePath(segment)) {
return segment;
}
return applyRotationToSegment(segment, transform, boundingBox);
});
};