0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/translateFills.ts
2024-04-15 10:06:19 +02:00

37 lines
1,003 B
TypeScript

import { Fill } from '@ui/lib/types/utils/fill';
import { translateGradientLinearFill } from './translateGradientLinearFill';
import { translateSolidFill } from './translateSolidFill';
const translateFill = (fill: Paint, width: number, height: number): Fill | undefined => {
switch (fill.type) {
case 'SOLID':
return translateSolidFill(fill);
case 'GRADIENT_LINEAR':
return translateGradientLinearFill(fill, width, height);
}
console.error('Color type ' + fill.type + ' not supported yet');
};
export const translateFills = (
fills: readonly Paint[] | typeof figma.mixed,
width: number,
height: number
): Fill[] => {
// @TODO: think better variable name
// @TODO: make it work with figma.mixed
const fills2 = fills === figma.mixed ? [] : fills;
const penpotFills = [];
for (const fill of fills2) {
const penpotFill = translateFill(fill, width, height);
if (penpotFill) {
penpotFills.unshift(penpotFill);
}
}
return penpotFills;
};