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/translateShadowEffects.ts
2024-04-22 14:35:59 +02:00

45 lines
1.1 KiB
TypeScript

import { rgbToHex } from '@plugin/utils';
import { Shadow, ShadowStyle } from '@ui/lib/types/utils/shadow';
export const translateShadowEffect = (effect: Effect): Shadow | undefined => {
if (effect.type !== 'DROP_SHADOW' && effect.type !== 'INNER_SHADOW') {
return;
}
return {
style: translateShadowType(effect),
offsetX: effect.offset.x,
offsetY: effect.offset.y,
blur: effect.radius,
spread: effect.spread ?? 0,
hidden: !effect.visible,
color: {
color: rgbToHex(effect.color),
opacity: effect.color.a
}
};
};
export const translateShadowEffects = (effects: readonly Effect[]): Shadow[] => {
const shadows: Shadow[] = [];
for (const effect of effects) {
const shadow = translateShadowEffect(effect);
if (shadow) {
// effects are applied in reverse order in Figma, that's why we unshift
shadows.unshift(shadow);
}
}
return shadows;
};
const translateShadowType = (effect: DropShadowEffect | InnerShadowEffect): ShadowStyle => {
switch (effect.type) {
case 'DROP_SHADOW':
return 'drop-shadow';
case 'INNER_SHADOW':
return 'inner-shadow';
}
};