1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import { deepmerge } from '@material-ui/utils';
|
4 |
|
5 | function round(value) {
|
6 | return Math.round(value * 1e5) / 1e5;
|
7 | }
|
8 |
|
9 | let warnedOnce = false;
|
10 |
|
11 | function roundWithDeprecationWarning(value) {
|
12 | if (process.env.NODE_ENV !== 'production') {
|
13 | if (!warnedOnce) {
|
14 | console.warn(['Material-UI: The `theme.typography.round` helper is deprecated.', 'Head to https://material-ui.com/r/migration-v4/#theme for a migration path.'].join('\n'));
|
15 | warnedOnce = true;
|
16 | }
|
17 | }
|
18 |
|
19 | return round(value);
|
20 | }
|
21 |
|
22 | const caseAllCaps = {
|
23 | textTransform: 'uppercase'
|
24 | };
|
25 | const defaultFontFamily = '"Roboto", "Helvetica", "Arial", sans-serif';
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | export default function createTypography(palette, typography) {
|
32 | const _ref = typeof typography === 'function' ? typography(palette) : typography,
|
33 | {
|
34 | fontFamily = defaultFontFamily,
|
35 |
|
36 | fontSize = 14,
|
37 |
|
38 | fontWeightLight = 300,
|
39 | fontWeightRegular = 400,
|
40 | fontWeightMedium = 500,
|
41 | fontWeightBold = 700,
|
42 |
|
43 |
|
44 | htmlFontSize = 16,
|
45 |
|
46 | allVariants,
|
47 | pxToRem: pxToRem2
|
48 | } = _ref,
|
49 | other = _objectWithoutPropertiesLoose(_ref, ["fontFamily", "fontSize", "fontWeightLight", "fontWeightRegular", "fontWeightMedium", "fontWeightBold", "htmlFontSize", "allVariants", "pxToRem"]);
|
50 |
|
51 | if (process.env.NODE_ENV !== 'production') {
|
52 | if (typeof fontSize !== 'number') {
|
53 | console.error('Material-UI: `fontSize` is required to be a number.');
|
54 | }
|
55 |
|
56 | if (typeof htmlFontSize !== 'number') {
|
57 | console.error('Material-UI: `htmlFontSize` is required to be a number.');
|
58 | }
|
59 | }
|
60 |
|
61 | const coef = fontSize / 14;
|
62 |
|
63 | const pxToRem = pxToRem2 || (size => `${size / htmlFontSize * coef}rem`);
|
64 |
|
65 | const buildVariant = (fontWeight, size, lineHeight, letterSpacing, casing) => _extends({
|
66 | fontFamily,
|
67 | fontWeight,
|
68 | fontSize: pxToRem(size),
|
69 |
|
70 | lineHeight
|
71 | }, fontFamily === defaultFontFamily ? {
|
72 | letterSpacing: `${round(letterSpacing / size)}em`
|
73 | } : {}, casing, allVariants);
|
74 |
|
75 | const variants = {
|
76 | h1: buildVariant(fontWeightLight, 96, 1.167, -1.5),
|
77 | h2: buildVariant(fontWeightLight, 60, 1.2, -0.5),
|
78 | h3: buildVariant(fontWeightRegular, 48, 1.167, 0),
|
79 | h4: buildVariant(fontWeightRegular, 34, 1.235, 0.25),
|
80 | h5: buildVariant(fontWeightRegular, 24, 1.334, 0),
|
81 | h6: buildVariant(fontWeightMedium, 20, 1.6, 0.15),
|
82 | subtitle1: buildVariant(fontWeightRegular, 16, 1.75, 0.15),
|
83 | subtitle2: buildVariant(fontWeightMedium, 14, 1.57, 0.1),
|
84 | body1: buildVariant(fontWeightRegular, 16, 1.5, 0.15),
|
85 | body2: buildVariant(fontWeightRegular, 14, 1.43, 0.15),
|
86 | button: buildVariant(fontWeightMedium, 14, 1.75, 0.4, caseAllCaps),
|
87 | caption: buildVariant(fontWeightRegular, 12, 1.66, 0.4),
|
88 | overline: buildVariant(fontWeightRegular, 12, 2.66, 1, caseAllCaps)
|
89 | };
|
90 | return deepmerge(_extends({
|
91 | htmlFontSize,
|
92 | pxToRem,
|
93 | round: roundWithDeprecationWarning,
|
94 |
|
95 | fontFamily,
|
96 | fontSize,
|
97 | fontWeightLight,
|
98 | fontWeightRegular,
|
99 | fontWeightMedium,
|
100 | fontWeightBold
|
101 | }, variants), other, {
|
102 | clone: false
|
103 |
|
104 | });
|
105 | } |
\ | No newline at end of file |