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 = responsiveFontSizes;
|
8 | var _formatMuiErrorMessage2 = _interopRequireDefault(require("@mui/utils/formatMuiErrorMessage"));
|
9 | var _cssUtils = require("./cssUtils");
|
10 | function responsiveFontSizes(themeInput, options = {}) {
|
11 | const {
|
12 | breakpoints = ['sm', 'md', 'lg'],
|
13 | disableAlign = false,
|
14 | factor = 2,
|
15 | variants = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'subtitle1', 'subtitle2', 'body1', 'body2', 'caption', 'button', 'overline']
|
16 | } = options;
|
17 | const theme = {
|
18 | ...themeInput
|
19 | };
|
20 | theme.typography = {
|
21 | ...theme.typography
|
22 | };
|
23 | const typography = theme.typography;
|
24 |
|
25 |
|
26 |
|
27 | const convert = (0, _cssUtils.convertLength)(typography.htmlFontSize);
|
28 | const breakpointValues = breakpoints.map(x => theme.breakpoints.values[x]);
|
29 | variants.forEach(variant => {
|
30 | const style = typography[variant];
|
31 | if (!style) {
|
32 | return;
|
33 | }
|
34 | const remFontSize = parseFloat(convert(style.fontSize, 'rem'));
|
35 | if (remFontSize <= 1) {
|
36 | return;
|
37 | }
|
38 | const maxFontSize = remFontSize;
|
39 | const minFontSize = 1 + (maxFontSize - 1) / factor;
|
40 | let {
|
41 | lineHeight
|
42 | } = style;
|
43 | if (!(0, _cssUtils.isUnitless)(lineHeight) && !disableAlign) {
|
44 | throw new Error(process.env.NODE_ENV !== "production" ? 'MUI: Unsupported non-unitless line height with grid alignment.\n' + 'Use unitless line heights instead.' : (0, _formatMuiErrorMessage2.default)(6));
|
45 | }
|
46 | if (!(0, _cssUtils.isUnitless)(lineHeight)) {
|
47 |
|
48 | lineHeight = parseFloat(convert(lineHeight, 'rem')) / parseFloat(remFontSize);
|
49 | }
|
50 | let transform = null;
|
51 | if (!disableAlign) {
|
52 | transform = value => (0, _cssUtils.alignProperty)({
|
53 | size: value,
|
54 | grid: (0, _cssUtils.fontGrid)({
|
55 | pixels: 4,
|
56 | lineHeight,
|
57 | htmlFontSize: typography.htmlFontSize
|
58 | })
|
59 | });
|
60 | }
|
61 | typography[variant] = {
|
62 | ...style,
|
63 | ...(0, _cssUtils.responsiveProperty)({
|
64 | cssProperty: 'fontSize',
|
65 | min: minFontSize,
|
66 | max: maxFontSize,
|
67 | unit: 'rem',
|
68 | breakpoints: breakpointValues,
|
69 | transform
|
70 | })
|
71 | };
|
72 | });
|
73 | return theme;
|
74 | } |
\ | No newline at end of file |