Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Apr 18, 2024
1 parent 8c2291b commit b062110
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 29 deletions.
29 changes: 2 additions & 27 deletions plugin-src/transformers/partials/transformStrokes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ import { translateStrokes } from '@plugin/translators';

import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes';

export type NodeStrokes = {
strokes: readonly Paint[];
strokeWeight: number | typeof figma.mixed;
strokeAlign: 'CENTER' | 'INSIDE' | 'OUTSIDE';
dashPattern: readonly number[];
};

const isVectorLike = (node: GeometryMixin | VectorLikeMixin): node is VectorLikeMixin => {
return 'vectorNetwork' in node;
};
Expand All @@ -23,33 +16,15 @@ const hasFillGeometry = (node: GeometryMixin): boolean => {
return node.fillGeometry.length > 0;
};

const getNodeStrokes = (node: GeometryMixin): NodeStrokes => {
return {
strokes: node.strokes,
strokeWeight: node.strokeWeight,
strokeAlign: node.strokeAlign,
dashPattern: node.dashPattern
};
};

const getIndividualStrokes = (node: IndividualStrokesMixin): IndividualStrokesMixin => {
return {
strokeTopWeight: node.strokeTopWeight,
strokeRightWeight: node.strokeRightWeight,
strokeBottomWeight: node.strokeBottomWeight,
strokeLeftWeight: node.strokeLeftWeight
};
};

export const transformStrokes = (
node: GeometryMixin | (GeometryMixin & IndividualStrokesMixin)
): Partial<ShapeAttributes> => {
return {
strokes: translateStrokes(
getNodeStrokes(node),
node,
hasFillGeometry(node),
isVectorLike(node) ? node.vectorNetwork : undefined,
isIndividualStrokes(node) ? getIndividualStrokes(node) : undefined
isIndividualStrokes(node) ? node : undefined
)
};
};
3 changes: 1 addition & 2 deletions plugin-src/translators/translateStrokes.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { NodeStrokes } from '@plugin/transformers/partials';
import { translateFill } from '@plugin/translators/translateFills';

import { Stroke, StrokeAlignment, StrokeCaps } from '@ui/lib/types/utils/stroke';

export const translateStrokes = (
nodeStrokes: NodeStrokes,
nodeStrokes: MinimalStrokesMixin,
hasFillGeometry?: boolean,
vectorNetwork?: VectorNetwork,
individualStrokes?: IndividualStrokesMixin
Expand Down

0 comments on commit b062110

Please sign in to comment.