// @flow

// inlehmansterms.net/2014/06/09/groove-to-a-vertical-rhythm
// 24ways.org/2011/composing-the-new-canon
// modularscale.com
// type-scale.com

const scale = {
  step0: 1,
  step1: 15 / 16,
  step2: 8 / 9,
  step3: 5 / 6,
  step4: 4 / 5,
  step5: 3 / 4,
  step6: 1 / Math.SQRT2,
  step7: 2 / 3,
  step8: 5 / 8,
  step9: 3 / 5,
  step10: 9 / 16,
  step11: 8 / 15,
  step12: 1 / 2,
  step13: 2 / 5,
  step14: 3 / 8,
  step15: 1 / 3,
  step16: 1 / 4,
};

const typography = ({
  fontSize,
  fontSizeScale,
  lineHeight,
}: {|
  fontSize: number,
  fontSizeScale: number | $Keys<typeof scale>,
  lineHeight: number,
|}) => ({
  fontSize: (level: number) =>
    Array.from(Array(Math.abs(level))).reduce(size => {
      const scaleRatio =
        typeof fontSizeScale === 'string'
          ? scale[fontSizeScale]
          : fontSizeScale;
      return level > 0 ? size * (1 / scaleRatio) : size / (1 / scaleRatio);
    }, fontSize),
  lineHeight,
  rhythm: (ratio: number) => lineHeight * ratio,
});

export default typography;

@@ -625,102 +625,10 @@
  =%3E 
-(
 %7B%0A
-  fontSize: (level: number) =%3E%0A    Array.from(Array(Math.abs(level))).reduce(size =%3E %7B%0A    
   co
@@ -644,20 +644,16 @@
 Ratio =%0A
-    
     type
@@ -688,20 +688,16 @@
 '%0A      
-  
-  
 ? scale%5B
@@ -717,20 +717,16 @@
 %5D%0A      
-    
 : fontSi
@@ -734,20 +734,16 @@
 eScale;%0A
-    
   return
@@ -747,89 +747,79 @@
 urn 
-level %3E 0 ? size * (1 / scaleRatio) : size / (1 / scaleRatio);%0A    %7D, fontSize
+%7B%0A    fontSize: (level: number) =%3E fontSize ** (scaleRatio, -level
 ),%0A
+  
   li
@@ -828,16 +828,18 @@
 Height,%0A
+  
   rhythm
@@ -879,18 +879,22 @@
  ratio,%0A
+  %7D;%0A
 %7D
-)
 ;%0A%0Aexpor

Simplify typography calculations (#1413)