0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-20 14:32:31 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/fills/translatePaintStyles.ts
Alex Sánchez a58f9e913d
Color libraries (#183)
* wip

* color library

* fixes

* fixes

* fixes

* fixes

* changeset

* fixes

* fixes

* fixes

* fixes
2024-06-25 14:12:37 +02:00

35 lines
933 B
TypeScript

import { translateFill } from '@plugin/translators/fills/translateFills';
import { FillStyle } from '@ui/lib/types/utils/fill';
export const translatePaintStyles = (figmaStyle: PaintStyle): FillStyle => {
const fillStyle: FillStyle = {
name: figmaStyle.name,
fills: [],
colors: []
};
const colorName = (figmaStyle: PaintStyle, index: number): string => {
// @TODO: Think something better
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : figmaStyle.name;
};
let index = 0;
const path =
(figmaStyle.remote ? 'Remote / ' : '') + (figmaStyle.paints.length > 1 ? figmaStyle.name : '');
for (const fill of figmaStyle.paints) {
const penpotFill = translateFill(fill);
if (penpotFill) {
fillStyle.fills.unshift(penpotFill);
fillStyle.colors.unshift({
path,
name: colorName(figmaStyle, index)
});
}
index++;
}
return fillStyle;
};