0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-05 06:10:52 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformFills.ts

46 lines
1.3 KiB
TypeScript
Raw Normal View History

import { translateFillStyleId, translateFills } from '@plugin/translators/fills';
import { TextSegment } from '@plugin/translators/text/paragraph';
2024-05-06 01:06:14 -05:00
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';
import { TextStyle } from '@ui/lib/types/shapes/textShape';
export const transformFills = (
node: (MinimalFillsMixin & DimensionAndPositionMixin) | VectorRegion | VectorNode | TextSegment
): Pick<ShapeAttributes, 'fills' | 'fillStyleId'> | Pick<TextStyle, 'fills' | 'fillStyleId'> => {
if (hasFillStyle(node)) {
return {
fills: [],
fillStyleId: translateFillStyleId(node.fillStyleId)
};
}
return {
fills: translateFills(node.fills)
};
};
export const transformVectorFills = (
node: VectorNode,
vectorPath: VectorPath,
vectorRegion: VectorRegion | undefined
): Pick<ShapeAttributes, 'fills' | 'fillStyleId'> => {
if (vectorPath.windingRule === 'NONE') {
return {
fills: []
};
}
const fillsNode = vectorRegion?.fills ? vectorRegion : node;
return transformFills(fillsNode);
};
const hasFillStyle = (
node: (MinimalFillsMixin & DimensionAndPositionMixin) | VectorRegion | VectorNode | TextSegment
): boolean => {
return (
node.fillStyleId !== figma.mixed &&
node.fillStyleId !== undefined &&
node.fillStyleId.length > 0
);
};