(opts: OptionsType)
| 8 | import type { OptionsType } from "Types" |
| 9 | |
| 10 | const typography = function (opts: OptionsType) { |
| 11 | const defaults: OptionsType = { |
| 12 | baseFontSize: "16px", |
| 13 | baseLineHeight: 1.45, |
| 14 | headerLineHeight: 1.1, |
| 15 | scaleRatio: 2, |
| 16 | googleFonts: [], |
| 17 | headerFontFamily: [ |
| 18 | "-apple-system", |
| 19 | "BlinkMacSystemFont", |
| 20 | "Segoe UI", |
| 21 | "Roboto", |
| 22 | "Oxygen", |
| 23 | "Ubuntu", |
| 24 | "Cantarell", |
| 25 | "Fira Sans", |
| 26 | "Droid Sans", |
| 27 | "Helvetica Neue", |
| 28 | "sans-serif", |
| 29 | ], |
| 30 | bodyFontFamily: ["georgia", "serif"], |
| 31 | headerColor: "inherit", |
| 32 | bodyColor: "hsla(0,0%,0%,0.8)", |
| 33 | headerWeight: "bold", |
| 34 | bodyWeight: "normal", |
| 35 | boldWeight: "bold", |
| 36 | includeNormalize: true, |
| 37 | blockMarginBottom: 1, |
| 38 | } |
| 39 | |
| 40 | const options = objectAssign({}, defaults, opts) |
| 41 | |
| 42 | const vr = verticalRhythm(options) |
| 43 | |
| 44 | // Add this function to the vertical rhythm object so it'll be passed around |
| 45 | // as well and be available. Not related really but this is the easiest |
| 46 | // way to pass around extra utility functions atm... :-\ |
| 47 | vr.scale = (value: number) => { |
| 48 | // This doesn't pick the right scale ratio if a theme has more than one ratio. |
| 49 | // Perhaps add optional parameter for a width and it'll get the ratio |
| 50 | // for this width. Tricky part is maxWidth could be set in non-pixels. |
| 51 | const baseFont = parseInt(options.baseFontSize, 10) |
| 52 | const newFontSize = `${ms(value, options.scaleRatio) * baseFont}px` |
| 53 | return vr.adjustFontSizeTo(newFontSize) |
| 54 | } |
| 55 | |
| 56 | return { |
| 57 | options, |
| 58 | ...vr, |
| 59 | createStyles() { |
| 60 | return this.toString() |
| 61 | }, // TODO remove in next breaking release. |
| 62 | toJSON() { |
| 63 | return createStyles(vr, options) |
| 64 | }, |
| 65 | toString() { |
| 66 | return compileStyles(vr, options, this.toJSON()) |
| 67 | }, |
no outgoing calls