-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* lines & arrows draft * simplify vectors * try to refactor * remove comments * add more clarity to code * fix translate strokes * minor style fix * fix for vectors without geometry * reduce code --------- Co-authored-by: Alex Sánchez <[email protected]> Co-authored-by: Jordi Sala Morales <[email protected]>
- Loading branch information
1 parent
73ccf83
commit c9f8a0d
Showing
11 changed files
with
126 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { translateStrokes } from '@plugin/translators'; | ||
|
||
import { ShapeAttributes } from '@ui/lib/types/shape/shapeAttributes'; | ||
|
||
const isVectorLike = (node: GeometryMixin | VectorLikeMixin): node is VectorLikeMixin => { | ||
return 'vectorNetwork' in node; | ||
}; | ||
|
||
const hasFillGeometry = (node: GeometryMixin | (GeometryMixin & VectorLikeMixin)): boolean => { | ||
return node.fillGeometry.length > 0; | ||
}; | ||
|
||
export const transformStrokes = ( | ||
node: GeometryMixin | (GeometryMixin & VectorLikeMixin) | ||
): Partial<ShapeAttributes> => { | ||
return { | ||
strokes: translateStrokes( | ||
node.strokes, | ||
node.strokeWeight, | ||
hasFillGeometry(node), | ||
isVectorLike(node) ? node.vectorNetwork : undefined | ||
) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { translateVectorPaths } from '@plugin/translators'; | ||
|
||
import { PathAttributes } from '@ui/lib/types/path/pathAttributes'; | ||
|
||
const getVectorPaths = (node: VectorNode | StarNode | LineNode | PolygonNode): VectorPaths => { | ||
switch (node.type) { | ||
case 'STAR': | ||
case 'POLYGON': | ||
return node.fillGeometry; | ||
case 'VECTOR': | ||
return node.vectorPaths; | ||
case 'LINE': | ||
return node.strokeGeometry; | ||
} | ||
}; | ||
|
||
export const transformVectorPaths = ( | ||
node: VectorNode | StarNode | LineNode | PolygonNode, | ||
baseX: number, | ||
baseY: number | ||
): PathAttributes => { | ||
const vectorPaths = getVectorPaths(node); | ||
|
||
return { | ||
type: 'path', | ||
content: translateVectorPaths(vectorPaths, baseX + node.x, baseY + node.y) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 11 additions & 6 deletions
17
...n-src/transformers/transformVectorNode.ts → plugin-src/transformers/transformPathNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,49 @@ | ||
import { translateFill } from '@plugin/translators/translateFills'; | ||
|
||
import { Stroke } from '@ui/lib/types/utils/stroke'; | ||
import { Stroke, StrokeCaps } from '@ui/lib/types/utils/stroke'; | ||
|
||
export const translateStrokes = (node: MinimalStrokesMixin): Stroke[] => { | ||
return node.strokes.map(stroke => { | ||
const fill = translateFill(stroke, 0, 0); | ||
return { | ||
export const translateStrokes = ( | ||
paints: readonly Paint[], | ||
strokeWeight: number | typeof figma.mixed, | ||
hasFillGeometry?: boolean, | ||
vectorNetwork?: VectorNetwork | ||
): Stroke[] => { | ||
return paints.map((paint, index) => { | ||
const fill = translateFill(paint, 0, 0); | ||
const stroke: Stroke = { | ||
strokeColor: fill?.fillColor, | ||
strokeOpacity: fill?.fillOpacity, | ||
strokeWidth: node.strokeWeight === figma.mixed ? 1 : node.strokeWeight | ||
strokeWidth: strokeWeight === figma.mixed ? 1 : strokeWeight | ||
}; | ||
|
||
if (!hasFillGeometry && index === 0 && vectorNetwork && vectorNetwork.vertices.length) { | ||
stroke.strokeCapStart = translateStrokeCap(vectorNetwork.vertices[0]); | ||
stroke.strokeCapEnd = translateStrokeCap( | ||
vectorNetwork.vertices[vectorNetwork.vertices.length - 1] | ||
); | ||
} | ||
|
||
return stroke; | ||
}); | ||
}; | ||
|
||
const translateStrokeCap = (vertex: VectorVertex): StrokeCaps | undefined => { | ||
switch (vertex.strokeCap as StrokeCap | ConnectorStrokeCap) { | ||
case 'NONE': | ||
return; | ||
case 'ROUND': | ||
return 'round'; | ||
case 'ARROW_EQUILATERAL': | ||
case 'TRIANGLE_FILLED': | ||
return 'triangle-arrow'; | ||
case 'SQUARE': | ||
return 'square'; | ||
case 'CIRCLE_FILLED': | ||
return 'circle-marker'; | ||
case 'DIAMOND_FILLED': | ||
return 'diamond-marker'; | ||
case 'ARROW_LINES': | ||
default: | ||
return 'line-arrow'; | ||
} | ||
}; |