From 9355f282d00562aad1adef50fce61829ae9b08ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20S=C3=A1nchez?= Date: Fri, 10 May 2024 11:08:00 +0200 Subject: [PATCH] Fixed line nodes (#96) * fixed line nodes * fixed line nodes * changeset * changeset * Update .changeset/new-spiders-travel.md Co-authored-by: Jordi Sala Morales --------- Co-authored-by: Jordi Sala Morales --- .changeset/many-lamps-stare.md | 5 ++++ .changeset/new-spiders-travel.md | 5 ++++ .../partials/transformVectorPaths.ts | 4 +-- .../translators/translateVectorPaths.ts | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 .changeset/many-lamps-stare.md create mode 100644 .changeset/new-spiders-travel.md diff --git a/.changeset/many-lamps-stare.md b/.changeset/many-lamps-stare.md new file mode 100644 index 0000000..e22ad22 --- /dev/null +++ b/.changeset/many-lamps-stare.md @@ -0,0 +1,5 @@ +--- +"penpot-exporter": patch +--- + +Fixed correct size for line nodes diff --git a/.changeset/new-spiders-travel.md b/.changeset/new-spiders-travel.md new file mode 100644 index 0000000..82fffd9 --- /dev/null +++ b/.changeset/new-spiders-travel.md @@ -0,0 +1,5 @@ +--- +"penpot-exporter": patch +--- + +Fixed line node export when using opacity 0 on the line diff --git a/plugin-src/transformers/partials/transformVectorPaths.ts b/plugin-src/transformers/partials/transformVectorPaths.ts index ef7ee16..a18ce09 100644 --- a/plugin-src/transformers/partials/transformVectorPaths.ts +++ b/plugin-src/transformers/partials/transformVectorPaths.ts @@ -1,4 +1,4 @@ -import { translateVectorPaths } from '@plugin/translators'; +import { createLineGeometry, translateVectorPaths } from '@plugin/translators'; import { PathAttributes } from '@ui/lib/types/shapes/pathShape'; @@ -10,7 +10,7 @@ const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): V case 'VECTOR': return node.vectorPaths; case 'LINE': - return node.strokeGeometry; + return createLineGeometry(node); } }; diff --git a/plugin-src/translators/translateVectorPaths.ts b/plugin-src/translators/translateVectorPaths.ts index 7228f8b..503eee8 100644 --- a/plugin-src/translators/translateVectorPaths.ts +++ b/plugin-src/translators/translateVectorPaths.ts @@ -16,6 +16,31 @@ export const translateVectorPaths = ( return segments; }; +export const createLineGeometry = (node: LineNode): VectorPaths => { + const commands: (MoveToCommand | LineToCommand)[] = []; + + commands.push({ + command: 'moveto', + code: 'M', + x: 0, + y: 0 + }); + + commands.push({ + command: 'lineto', + code: 'L', + x: node.width, + y: node.height + }); + + return [ + { + windingRule: 'NONZERO', + data: commands.map(({ code, x, y }) => `${code} ${x} ${y}`).join(' ') + ' Z' + } + ]; +}; + const translateVectorPath = (path: VectorPath, baseX: number, baseY: number): Segment[] => { const normalizedPaths = parseSVG(path.data);