rem method

Dimension rem (
  1. Node fontSize,
  2. [Node baseFont]
)

Converts from px, pt or em to rem units

Parameters: number: a number with or without units (px by default). base: (optional) number (16px, 12pt, 1em) Returns: the number converted to em Example: rem(16), rem(32px), rem(28pt, 14) Output: 1rem, 2rem, 2rem

Implementation

Dimension rem(Node fontSize, [Node baseFont]) {
  num base = 16; //px
  if (fontSize is Dimension) {
    switch (fontSize.unit.toCSS(null)) {
      case 'px':
        base = 16;
        break;
      case 'pt':
        base = 12;
        break;
      case 'em':
        base = 1;
        break;
      default:
    }
  }
  base = baseFont?.value ?? base;
  return Dimension(fontSize.value / base, 'rem');
}