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