0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 13:20:37 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/vectors/translateLineNode.ts
Jordi Sala Morales af81fc7e92
Implement rotation for vector lines (#160)
* Implement rotation for vector lines

* wip

* Improve rotations for lines

* add changelog

* add layout attributes to line
2024-06-14 10:33:23 +02:00

65 lines
1.4 KiB
TypeScript

import { Command } from 'svg-path-parser';
import { applyInverseRotation, applyRotation, hasRotation } from '@plugin/utils';
import { Segment } from '@ui/lib/types/shapes/pathShape';
import { translateCommandsToSegments } from '.';
export const translateLineNode = (node: LineNode, baseX: number, baseY: number): Segment[] => {
if (!hasRotation(node.rotation) || !node.absoluteBoundingBox) {
return translateCommandsToSegments(
[
{
x: 0,
y: 0,
command: 'moveto',
code: 'M'
},
{
x: node.width,
y: 0,
command: 'lineto',
code: 'L'
}
],
baseX + node.x,
baseY + node.y
);
}
const startPoint = applyRotation(
{ x: 0, y: 0 },
node.absoluteTransform,
node.absoluteBoundingBox
);
const endPoint = applyRotation(
{ x: node.width, y: 0 },
node.absoluteTransform,
node.absoluteBoundingBox
);
const commands: Command[] = [
{
x: startPoint.x,
y: startPoint.y,
command: 'moveto',
code: 'M'
},
{
x: endPoint.x,
y: endPoint.y,
command: 'lineto',
code: 'L'
}
];
const referencePoint = applyInverseRotation(
{ x: node.x, y: node.y },
node.absoluteTransform,
node.absoluteBoundingBox
);
return translateCommandsToSegments(commands, baseX + referencePoint.x, baseY + referencePoint.y);
};