I’m trying to convert a Figma Gradient into a CSS Gradient. I figured out how to calculate degrees, but I can’t figure out how to calculate the CSS stop position .
It appears that Figma and CSS have different way to calculate stop positions.
If you’re using the node object from a Figma Plugin, I highly recommend using this function:
import { extractLinearGradientParamsFromTransform } from "@figma-plugin/helpers";
If you’re using the Figma API, it’s a little more tedious. I implemented this before (its not always perfect, the angle gets messed up sometimes), but you can check out my code here.
the code is quite long since you have to a couple of tedious linear transformations if the node itself is rotated (gets even more annoying if the gradient & node is rotated).
Below are a couple of links that should be extremely helpful in filling in the blanks.
I’ve created a plugin for CSS Gradient => Figma Gradient and found them useful. In particular, the W3C documentation is really helpful and has formulas to use.