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/gradients/translateGradientLinearFill.ts
Alex Sánchez 3118d36f0a
Fills Refactor (#109)
* refactor

* changeset

* fixes
2024-05-13 17:04:13 +02:00

24 lines
693 B
TypeScript

import { calculateLinearGradient, rgbToHex } from '@plugin/utils';
import { Fill } from '@ui/lib/types/utils/fill';
export const translateGradientLinearFill = (fill: GradientPaint): Fill => {
const points = calculateLinearGradient(fill.gradientTransform);
return {
fillColorGradient: {
type: 'linear',
startX: points.start[0],
startY: points.start[1],
endX: points.end[0],
endY: points.end[1],
width: 1,
stops: fill.gradientStops.map(stop => ({
color: rgbToHex(stop.color),
offset: stop.position,
opacity: stop.color.a * (fill.opacity ?? 1)
}))
},
fillOpacity: !fill.visible ? 0 : fill.opacity
};
};