2024-04-16 09:08:39 -05:00
|
|
|
import { translateFill } from '@plugin/translators/translateFills';
|
|
|
|
|
2024-04-17 03:53:38 -05:00
|
|
|
import { Stroke, StrokeCaps } from '@ui/lib/types/utils/stroke';
|
2024-04-16 09:08:39 -05:00
|
|
|
|
2024-04-17 03:53:38 -05:00
|
|
|
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 = {
|
2024-04-16 09:08:39 -05:00
|
|
|
strokeColor: fill?.fillColor,
|
|
|
|
strokeOpacity: fill?.fillOpacity,
|
2024-04-17 03:53:38 -05:00
|
|
|
strokeWidth: strokeWeight === figma.mixed ? 1 : strokeWeight
|
2024-04-16 09:08:39 -05:00
|
|
|
};
|
2024-04-17 03:53:38 -05:00
|
|
|
|
|
|
|
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;
|
2024-04-16 09:08:39 -05:00
|
|
|
});
|
|
|
|
};
|
2024-04-17 03:53:38 -05:00
|
|
|
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
};
|