2024-06-14 03:33:23 -05:00
|
|
|
import {
|
|
|
|
transformBlend,
|
|
|
|
transformConstraints,
|
|
|
|
transformEffects,
|
|
|
|
transformFigmaIds,
|
|
|
|
transformLayoutAttributes,
|
2024-06-17 02:58:23 -05:00
|
|
|
transformOverrides,
|
2024-06-14 03:33:23 -05:00
|
|
|
transformProportion,
|
|
|
|
transformSceneNode,
|
|
|
|
transformStrokes
|
|
|
|
} from '@plugin/transformers/partials';
|
2024-06-17 05:14:16 -05:00
|
|
|
import { translateCommands } from '@plugin/translators/vectors';
|
2024-06-14 03:33:23 -05:00
|
|
|
|
|
|
|
import { PathShape } from '@ui/lib/types/shapes/pathShape';
|
2024-06-17 05:14:16 -05:00
|
|
|
import { Segment } from '@ui/lib/types/shapes/pathShape';
|
2024-06-14 03:33:23 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* In order to match the normal representation of a line in Penpot, we will assume that
|
|
|
|
* the line is never rotated, so we calculate its normal position.
|
|
|
|
*
|
|
|
|
* To represent the line rotated we do take into account the rotation of the line, but only in its content.
|
|
|
|
*/
|
2024-06-14 09:28:01 -05:00
|
|
|
export const transformLineNode = (node: LineNode, baseRotation: number): PathShape => {
|
2024-06-14 03:33:23 -05:00
|
|
|
return {
|
|
|
|
type: 'path',
|
|
|
|
name: node.name,
|
2024-06-14 09:28:01 -05:00
|
|
|
content: translateLineNode(node, baseRotation),
|
2024-06-14 03:33:23 -05:00
|
|
|
...transformFigmaIds(node),
|
|
|
|
...transformStrokes(node),
|
|
|
|
...transformEffects(node),
|
|
|
|
...transformSceneNode(node),
|
|
|
|
...transformBlend(node),
|
|
|
|
...transformProportion(node),
|
|
|
|
...transformLayoutAttributes(node),
|
2024-06-17 02:58:23 -05:00
|
|
|
...transformConstraints(node),
|
|
|
|
...transformOverrides(node)
|
2024-06-14 03:33:23 -05:00
|
|
|
};
|
|
|
|
};
|
2024-06-17 05:14:16 -05:00
|
|
|
|
|
|
|
const translateLineNode = (node: LineNode, baseRotation: number): Segment[] => {
|
|
|
|
return translateCommands(
|
|
|
|
node,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
x: 0,
|
|
|
|
y: 0,
|
|
|
|
command: 'moveto',
|
|
|
|
code: 'M'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: node.width,
|
|
|
|
y: 0,
|
|
|
|
command: 'lineto',
|
|
|
|
code: 'L'
|
|
|
|
}
|
|
|
|
],
|
|
|
|
baseRotation
|
|
|
|
);
|
|
|
|
};
|