0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-09 00:20:05 -05:00
penpot-exporter-figma-plugin/ui-src/parser/creators/symbols/symbolFills.ts
2024-06-26 08:11:57 +02:00

31 lines
881 B
TypeScript

import { Fill } from '@ui/lib/types/utils/fill';
import { ImageColor, PartialImageColor } from '@ui/lib/types/utils/imageColor';
import { colors, images } from '@ui/parser';
export const symbolFills = (fillStyleId?: string, fills?: Fill[]): Fill[] | undefined => {
const nodeFills = fillStyleId ? colors.get(fillStyleId)?.fills : fills;
if (!nodeFills) return;
return nodeFills.map(fill => {
if (fill.fillImage) {
fill.fillImage = symbolFillImage(fill.fillImage);
}
return fill;
});
};
export const symbolFillImage = (
fillImage: ImageColor | PartialImageColor
): ImageColor | undefined => {
if (!isPartialFillColor(fillImage)) return fillImage;
return images.get(fillImage.imageHash);
};
const isPartialFillColor = (
imageColor: ImageColor | PartialImageColor
): imageColor is PartialImageColor => {
return 'imageHash' in imageColor;
};