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/fills/translateFills.ts
Alex Sánchez a079f168df
Analytics (#228)
* metricts-sentry

* fixes

* refactor

* mixpanel integration

* improvements

* improvements

* fixes

* changeset

* fixes

* fixes

* Update .changeset/few-scissors-sleep.md

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>

* Update manifest.json

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>

* Update vite.config.ts

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>

* fixes

* fixes

* fixes

* lint

---------

Co-authored-by: Jordi Sala Morales <jordism91@gmail.com>
2024-10-28 11:22:50 +01:00

64 lines
1.7 KiB
TypeScript

import { paintStyles } from '@plugin/libraries';
import { translateImageFill, translateSolidFill } from '@plugin/translators/fills';
import {
translateGradientLinearFill,
translateGradientRadialFill
} from '@plugin/translators/fills/gradients';
import { rgbToHex } from '@plugin/utils';
import { Fill } from '@ui/lib/types/utils/fill';
export const translateFill = (fill: Paint): Fill | undefined => {
switch (fill.type) {
case 'SOLID':
return translateSolidFill(fill);
case 'GRADIENT_LINEAR':
return translateGradientLinearFill(fill);
case 'GRADIENT_RADIAL':
return translateGradientRadialFill(fill);
case 'IMAGE':
return translateImageFill(fill);
}
console.warn(`Unsupported fill type: ${fill.type}`);
};
export const translateFills = (
fills: readonly Paint[] | typeof figma.mixed | undefined
): Fill[] => {
if (fills === undefined || fills === figma.mixed) return [];
const penpotFills: Fill[] = [];
for (const fill of fills) {
const penpotFill = translateFill(fill);
if (penpotFill) {
// fills are applied in reverse order in Figma, that's why we unshift
penpotFills.unshift(penpotFill);
}
}
return penpotFills;
};
export const translateFillStyleId = (
fillStyleId: string | typeof figma.mixed | undefined
): string | undefined => {
if (fillStyleId === figma.mixed || fillStyleId === undefined) return;
if (!paintStyles.has(fillStyleId)) {
paintStyles.set(fillStyleId, undefined);
}
return fillStyleId;
};
export const translatePageFill = (fill: Paint): string | undefined => {
switch (fill.type) {
case 'SOLID':
return rgbToHex(fill.color);
}
console.warn(`Unsupported page fill type: ${fill.type}`);
};