Skip to content

Documentation / @ripl/core / getGradientBounds

Function: getGradientBounds() ​

getGradientBounds(box, width, height): GradientBounds

Defined in: packages/core/src/gradient/bounds.ts:30

Resolves the rectangle a gradient's coordinates map onto: the given bounding box, falling back to the full surface when no box is supplied or it has no area.

Every backend resolves gradients through this, so a gradient painted onto the same element renders identically whichever context draws it — including elements that paint as several paths, where each path's own box would otherwise restart the ramp.

Parameters ​

ParameterTypeDescription
boxBox | undefinedThe element's local bounding box, when it has one.
widthnumberWidth of the rendering surface, used as the fallback.
heightnumberHeight of the rendering surface, used as the fallback.

Returns ​

GradientBounds

The rectangle to resolve gradient coordinates against.