2024-04-17 03:53:38 -05:00
|
|
|
import { translateStrokes } from '@plugin/translators';
|
|
|
|
|
2024-05-06 01:06:14 -05:00
|
|
|
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';
|
2024-04-17 03:53:38 -05:00
|
|
|
|
|
|
|
const isVectorLike = (node: GeometryMixin | VectorLikeMixin): node is VectorLikeMixin => {
|
|
|
|
return 'vectorNetwork' in node;
|
|
|
|
};
|
|
|
|
|
2024-04-18 02:42:45 -05:00
|
|
|
const isIndividualStrokes = (
|
|
|
|
node: GeometryMixin | IndividualStrokesMixin
|
|
|
|
): node is IndividualStrokesMixin => {
|
|
|
|
return 'strokeTopWeight' in node;
|
|
|
|
};
|
|
|
|
|
|
|
|
const hasFillGeometry = (node: GeometryMixin): boolean => {
|
2024-04-17 03:53:38 -05:00
|
|
|
return node.fillGeometry.length > 0;
|
|
|
|
};
|
|
|
|
|
2024-05-09 09:59:27 -05:00
|
|
|
export const transformStrokes = async (
|
2024-04-18 02:42:45 -05:00
|
|
|
node: GeometryMixin | (GeometryMixin & IndividualStrokesMixin)
|
2024-05-09 09:59:27 -05:00
|
|
|
): Promise<Partial<ShapeAttributes>> => {
|
2024-04-17 03:53:38 -05:00
|
|
|
return {
|
2024-05-09 09:59:27 -05:00
|
|
|
strokes: await translateStrokes(
|
2024-04-18 02:42:45 -05:00
|
|
|
node,
|
2024-04-17 03:53:38 -05:00
|
|
|
hasFillGeometry(node),
|
2024-04-18 02:42:45 -05:00
|
|
|
isVectorLike(node) ? node.vectorNetwork : undefined,
|
|
|
|
isIndividualStrokes(node) ? node : undefined
|
2024-04-17 03:53:38 -05:00
|
|
|
)
|
|
|
|
};
|
|
|
|
};
|