VerticalRhythm

VerticalRhythm Class for calculate rhythm sizes ans convert units.

Source:
Version:
  • 1.0
Author:
  • Grigory Vasilyev <postcss.hamster@gmail.com> https://github.com/h0tc0d3
License:
  • Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0

Members

(static) default

Source:

Export Vertical Rhythm Class.

Methods

(static) VerticalRhythm(settings)

Source:

Constructor for class VerticalRhythm.

Parameters:
Name Type Description
settings

settings hash.

Use: settings.fontSize - base font size in pixels. settings.pxFallback - boolean pixel fallback. Convert relative sizes to pixels. If rhythm unit rem then rem value doubled with pixels values. If rhythm unit px and option will be set then in line height will be pixels like 24px, else relative size like 1.45(without em or rem) settings.lineHeight - base line height in pixels or relative value(without em or rem).

(static) VerticalRhythm#convert(value, valueUnit, format, fromContext, toContext) → {number}

Source:

Convert values from unit to unit.

Parameters:
Name Type Description
value number

input value

valueUnit

input value unit

format

output value unit

fromContext

from base font size

toContext

to new base font size

Returns:
  • output value.
Type
number

(static) VerticalRhythm#leading(value, fontSize) → {number}

Source:

1 leading(in pixels) = base line height(in pixels) - base font size(in pixels).

Parameters:
Name Type Description
value

input lines, before output 1 line height will be multiply with value.

fontSize

font size in pixels, em, rem like 1.5em.

Returns:
  • leading in rhythm unit.
Type
number

(static) VerticalRhythm#lineHeight(fontSize, value, baseFontSize, pxFallback) → {number}

Source:

Calculate line height value in rhythm units for font size. Generate line height from font size or input lines.

Parameters:
Name Type Description
fontSize

font size in pixels, em, rem like 1.5em.

value

input lines, before output 1 line height will be multiply with value.

baseFontSize

base font size for calculation relative sizes for px or em.

pxFallback

boolean pixel fallback option. Ignore settings.pxFallback option. Convert relative sizes to pixels. If rhythm unit rem then rem value doubled with pixels values. If rhythm unit px and option will be set then in line height will be pixels like 24px, else relative size like 1.45(without em or rem).

Returns:
  • line height in rhythm unit.
Type
number

(static) VerticalRhythm#lines(fontSize, unit) → {number}

Source:

Calculate the minimum multiple rhythm units(lines) needed to contain the font-size. 1 rhythm unit = base line height in pixels.

Parameters:
Name Type Description
fontSize

font size in pixels, em, rem like 1.5em.

unit

input value unit.

Returns:
  • number of lines.
Type
number

(static) VerticalRhythm#rhythm(value, fontSize, increase, outputUnit) → {number}

Source:

If value 450px, and base font size 16, line-height 1.5, increase = false then return 432px. If value 450px, and base font size 16, line-height 1.5, increase = true then return 456px.

Parameters:
Name Type Description
value

input value like 450px; 10em; 100rem;.

fontSize

font size in pixels, em, rem like 1.5em.

increase

increase or decrease size. Default decrease. increase = false.

outputUnit

output value unit.

Returns:
  • rhythmd value rhythm unit.
Type
number