fit
Places content in a box like CSS object-fit and object-position, e.g. to show a design
frame in a viewport of another size.
The result is the matrix from content coordinates to box coordinates: its a and d are
the scales, e and f the position of the content’s top-left corner. Combine it with
multiply, map points with applyToPoint, or write it with matrixToCss.
Sizes are expected to be positive.
Available since v3.1.5
Import
Section titled “Import”Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
content | Size | The size of the content |
box | Size | The size of the box |
options | FitOptions | Mode and alignment — see FitOptions |
Returns
Section titled “Returns”Matrix — The content-to-box matrix
Examples
Section titled “Examples”Show a frame in a viewport
Section titled “Show a frame in a viewport”contain (the default) keeps the whole frame visible, centered.
Cover, aligned to the left
Section titled “Cover, aligned to the left”Like object-fit: cover; object-position: left.
Related Types
Section titled “Related Types”FitAlign
Section titled “FitAlign”Where fit places content in the space left over (or overflowing), as CSS
object-position: 0 is left / top, 0.5 centered, 1 right / bottom.
FitOptions
Section titled “FitOptions”Options for fit.
Matrix
Section titled “Matrix”A 2D affine transformation, in the layout of CSS and SVG matrix(a, b, c, d, e, f):
A width and a height.
FitMode
Section titled “FitMode”How fit sizes content in a box, as CSS object-fit:
'contain': as large as possible while staying entirely inside (bands remain on two sides);'cover': as small as possible while covering the whole box (it overflows on two sides);'fill': stretched to the box on each axis, proportions not kept;'none': not scaled;'scale-down': like'contain', but never enlarged.
