2024-04-12 09:52:36 -05:00
|
|
|
import { Fill } from '@ui/lib/types/utils/fill';
|
|
|
|
|
2024-04-15 03:06:19 -05:00
|
|
|
import { translateGradientLinearFill } from './translateGradientLinearFill';
|
2024-04-12 06:55:42 -05:00
|
|
|
import { translateSolidFill } from './translateSolidFill';
|
|
|
|
|
2024-04-15 03:06:19 -05:00
|
|
|
const translateFill = (fill: Paint, width: number, height: number): Fill | undefined => {
|
2024-04-12 06:55:42 -05:00
|
|
|
switch (fill.type) {
|
|
|
|
case 'SOLID':
|
|
|
|
return translateSolidFill(fill);
|
2024-04-15 03:06:19 -05:00
|
|
|
case 'GRADIENT_LINEAR':
|
|
|
|
return translateGradientLinearFill(fill, width, height);
|
2024-04-12 06:55:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
console.error('Color type ' + fill.type + ' not supported yet');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const translateFills = (
|
2024-04-15 03:06:19 -05:00
|
|
|
fills: readonly Paint[] | typeof figma.mixed,
|
|
|
|
width: number,
|
|
|
|
height: number
|
2024-04-12 06:55:42 -05:00
|
|
|
): 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) {
|
2024-04-15 03:06:19 -05:00
|
|
|
const penpotFill = translateFill(fill, width, height);
|
2024-04-12 06:55:42 -05:00
|
|
|
|
|
|
|
if (penpotFill) {
|
|
|
|
penpotFills.unshift(penpotFill);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return penpotFills;
|
|
|
|
};
|