0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-06 23:00:55 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/partials/transformFills.ts
Alex Sánchez 672567614b
Use Fill Styles to generate fills more efficiently (#180)
* first commit

* change esbuild

* changeset
2024-06-19 15:58:13 +02:00

53 lines
1.3 KiB
TypeScript

import { translateFillStyle, translateFills } from '@plugin/translators/fills';
import { StyleTextSegment } from '@plugin/translators/text/paragraph';
import { ShapeAttributes } from '@ui/lib/types/shapes/shape';
import { TextStyle } from '@ui/lib/types/shapes/textShape';
export const transformFills = (
node:
| (MinimalFillsMixin & DimensionAndPositionMixin)
| VectorRegion
| VectorNode
| StyleTextSegment
): Pick<ShapeAttributes, 'fills' | 'fillStyleId'> | Pick<TextStyle, 'fills' | 'fillStyleId'> => {
if (hasFillStyle(node)) {
return {
fills: [],
fillStyleId: translateFillStyle(node.fillStyleId, node.fills)
};
}
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
| StyleTextSegment
): boolean => {
return (
node.fillStyleId !== figma.mixed &&
node.fillStyleId !== undefined &&
node.fillStyleId.length > 0
);
};