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