0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-22 23:38:42 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/symbols/symbolFills.ts

52 lines
1.2 KiB
TypeScript
Raw Normal View History

import { imagesLibrary } from '@plugin/ImageLibrary';
import { Fill } from '@ui/lib/types/utils/fill';
2024-05-06 08:06:14 +02:00
import { Gradient, LINEAR_TYPE, RADIAL_TYPE } from '@ui/lib/types/utils/gradient';
import { ImageColor } from '@ui/lib/types/utils/imageColor';
export const symbolFills = (fills?: Fill[]): Fill[] | undefined => {
if (!fills) return;
2024-05-06 08:06:14 +02:00
return fills.map(fill => {
if (fill.fillColorGradient) {
fill.fillColorGradient = symbolFillGradient(fill.fillColorGradient);
}
if (fill.fillImage) {
fill.fillImage = symbolFillImage(fill.fillImage);
}
return fill;
});
};
2024-05-06 08:06:14 +02:00
const symbolFillGradient = ({ type, ...rest }: Gradient): Gradient | undefined => {
2024-05-06 08:06:14 +02:00
switch (type) {
case 'linear':
return {
type: LINEAR_TYPE,
...rest
};
case 'radial':
return {
type: RADIAL_TYPE,
...rest
};
}
console.error(`Unsupported gradient type: ${String(type)}`);
};
const symbolFillImage = ({ imageHash, ...rest }: ImageColor): ImageColor | undefined => {
if (!imageHash) return;
const imageColor = imagesLibrary.get(imageHash);
if (!imageColor) return;
return {
...rest,
dataUri: imageColor?.dataUri
};
};