Skip to content

Commit

Permalink
fix for vectors without geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
Cenadros committed Apr 17, 2024
1 parent 6a0b6bc commit ecb9592
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion plugin-src/transformers/partials/transformStrokes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ const isVectorLike = (node: MinimalStrokesMixin | VectorLikeMixin): node is Vect
return 'vectorNetwork' in node;
};

const hasGeometry = (
node: MinimalStrokesMixin | GeometryMixin | (MinimalStrokesMixin & VectorLikeMixin)
): boolean => {
return 'fillGeometry' in node && node.fillGeometry.length > 0;
};

export const transformStrokes = (
node: MinimalStrokesMixin | (MinimalStrokesMixin & VectorLikeMixin)
node: MinimalStrokesMixin | GeometryMixin | (MinimalStrokesMixin & VectorLikeMixin)
): Partial<ShapeAttributes> => {
return {
strokes: translateStrokes(
node.strokes,
node.strokeWeight,
hasGeometry(node),
isVectorLike(node) ? node.vectorNetwork : undefined
)
};
Expand Down
7 changes: 5 additions & 2 deletions plugin-src/translators/translateStrokes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Stroke, StrokeCaps } from '@ui/lib/types/utils/stroke';
export const translateStrokes = (
paints: readonly Paint[],
strokeWeight: number | typeof figma.mixed,
hasGeometry?: boolean,
vectorNetwork?: VectorNetwork
): Stroke[] => {
return paints.map((paint, index) => {
Expand All @@ -15,9 +16,11 @@ export const translateStrokes = (
strokeWidth: strokeWeight === figma.mixed ? 1 : strokeWeight
};

if (index === 0 && vectorNetwork && vectorNetwork.vertices.length === 2) {
if (!hasGeometry && index === 0 && vectorNetwork && vectorNetwork.vertices.length) {
stroke.strokeCapStart = translateStrokeCap(vectorNetwork.vertices[0]);
stroke.strokeCapEnd = translateStrokeCap(vectorNetwork.vertices[1]);
stroke.strokeCapEnd = translateStrokeCap(
vectorNetwork.vertices[vectorNetwork.vertices.length - 1]
);
}

return stroke;
Expand Down

0 comments on commit ecb9592

Please sign in to comment.