Skip to content

fitNone

Places content in a box, at its own size, only positioned (CSS object-fit: none). Shortcut for fit(content, box, { mode: 'none', align }).

Available since v3.1.5

import { fitNone } from '@helpers4/geometry';
// or, from the all-in-one package (same code, one install):
import { fitNone } from 'helpers4/geometry';
fitNone(content: Size, box: Size, align?: FitAlign): Matrix
ParameterTypeDescription
contentSizeThe size of the content
boxSizeThe size of the box
alignFitAlignWhere to place it, centered by default — see FitAlign (optional)

Matrix — The content-to-box matrix (a/d scales, e/f position)

Same as fit(content, box, { mode: ‘none’ }).

fitNone({ width: 200, height: 100 }, { width: 100, height: 100 })
// => { a: 1, b: 0, c: 0, d: 1, e: -50, f: 0 }

The third argument is the alignment, like CSS object-position.

fitNone({ width: 200, height: 100 }, { width: 100, height: 100 }, { x: 0, y: 0 })

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.

interface FitAlign {
  x?: number;
  y?: number;
}

A 2D affine transformation, in the layout of CSS and SVG matrix(a, b, c, d, e, f):

x' = a·x + c·y + e
y' = b·x + d·y + f
interface Matrix {
  a: number;
  b: number;
  c: number;
  d: number;
  e: number;
  f: number;
}

A width and a height.

interface Size {
  height: number;
  width: number;
}

View source on GitHub