0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-03 13:20:37 -05:00
penpot-exporter-figma-plugin/ui-src/translators/translateFillGradients.ts

32 lines
759 B
TypeScript
Raw Permalink Normal View History

import { Fill } from '@ui/lib/types/utils/fill';
2024-05-06 01:06:14 -05:00
import { Gradient, LINEAR_TYPE, RADIAL_TYPE } from '@ui/lib/types/utils/gradient';
export const translateFillGradients = (fills?: Fill[]): Fill[] | undefined => {
if (!fills) return;
2024-05-06 01:06:14 -05:00
return fills.map(fill => {
if (fill.fillColorGradient) {
2024-05-06 01:06:14 -05:00
fill.fillColorGradient = translateFillGradient(fill.fillColorGradient);
}
return fill;
});
};
2024-05-06 01:06:14 -05:00
const translateFillGradient = ({ type, ...rest }: Gradient): Gradient | undefined => {
switch (type) {
case 'linear':
return {
type: LINEAR_TYPE,
...rest
};
case 'radial':
return {
type: RADIAL_TYPE,
...rest
};
}
console.error(`Unsupported gradient type: ${String(type)}`);
};