UNPKG

6.44 kBJavaScriptView Raw
1"use strict";
2'use client';
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6Object.defineProperty(exports, "__esModule", {
7 value: true
8});
9exports.styles = exports.html = exports.default = exports.body = void 0;
10var React = _interopRequireWildcard(require("react"));
11var _propTypes = _interopRequireDefault(require("prop-types"));
12var _zeroStyled = require("../zero-styled");
13var _DefaultPropsProvider = require("../DefaultPropsProvider");
14var _jsxRuntime = require("react/jsx-runtime");
15// to determine if the global styles are static or dynamic
16const isDynamicSupport = typeof (0, _zeroStyled.globalCss)({}) === 'function';
17const html = (theme, enableColorScheme) => ({
18 WebkitFontSmoothing: 'antialiased',
19 // Antialiasing.
20 MozOsxFontSmoothing: 'grayscale',
21 // Antialiasing.
22 // Change from `box-sizing: content-box` so that `width`
23 // is not affected by `padding` or `border`.
24 boxSizing: 'border-box',
25 // Fix font resize problem in iOS
26 WebkitTextSizeAdjust: '100%',
27 // When used under CssVarsProvider, colorScheme should not be applied dynamically because it will generate the stylesheet twice for server-rendered applications.
28 ...(enableColorScheme && !theme.vars && {
29 colorScheme: theme.palette.mode
30 })
31});
32exports.html = html;
33const body = theme => ({
34 color: (theme.vars || theme).palette.text.primary,
35 ...theme.typography.body1,
36 backgroundColor: (theme.vars || theme).palette.background.default,
37 '@media print': {
38 // Save printer ink.
39 backgroundColor: (theme.vars || theme).palette.common.white
40 }
41});
42exports.body = body;
43const styles = (theme, enableColorScheme = false) => {
44 const colorSchemeStyles = {};
45 if (enableColorScheme && theme.colorSchemes && typeof theme.getColorSchemeSelector === 'function') {
46 Object.entries(theme.colorSchemes).forEach(([key, scheme]) => {
47 const selector = theme.getColorSchemeSelector(key);
48 if (selector.startsWith('@')) {
49 // for @media (prefers-color-scheme), we need to target :root
50 colorSchemeStyles[selector] = {
51 ':root': {
52 colorScheme: scheme.palette?.mode
53 }
54 };
55 } else {
56 // else, it's likely that the selector already target an element with a class or data attribute
57 colorSchemeStyles[selector.replace(/\s*&/, '')] = {
58 colorScheme: scheme.palette?.mode
59 };
60 }
61 });
62 }
63 let defaultStyles = {
64 html: html(theme, enableColorScheme),
65 '*, *::before, *::after': {
66 boxSizing: 'inherit'
67 },
68 'strong, b': {
69 fontWeight: theme.typography.fontWeightBold
70 },
71 body: {
72 margin: 0,
73 // Remove the margin in all browsers.
74 ...body(theme),
75 // Add support for document.body.requestFullScreen().
76 // Other elements, if background transparent, are not supported.
77 '&::backdrop': {
78 backgroundColor: (theme.vars || theme).palette.background.default
79 }
80 },
81 ...colorSchemeStyles
82 };
83 const themeOverrides = theme.components?.MuiCssBaseline?.styleOverrides;
84 if (themeOverrides) {
85 defaultStyles = [defaultStyles, themeOverrides];
86 }
87 return defaultStyles;
88};
89
90// `ecs` stands for enableColorScheme. This is internal logic to make it work with Pigment CSS, so shorter is better.
91exports.styles = styles;
92const SELECTOR = 'mui-ecs';
93const staticStyles = theme => {
94 const result = styles(theme, false);
95 const baseStyles = Array.isArray(result) ? result[0] : result;
96 if (!theme.vars && baseStyles) {
97 baseStyles.html[`:root:has(${SELECTOR})`] = {
98 colorScheme: theme.palette.mode
99 };
100 }
101 if (theme.colorSchemes) {
102 Object.entries(theme.colorSchemes).forEach(([key, scheme]) => {
103 const selector = theme.getColorSchemeSelector(key);
104 if (selector.startsWith('@')) {
105 // for @media (prefers-color-scheme), we need to target :root
106 baseStyles[selector] = {
107 [`:root:not(:has(.${SELECTOR}))`]: {
108 colorScheme: scheme.palette?.mode
109 }
110 };
111 } else {
112 // else, it's likely that the selector already target an element with a class or data attribute
113 baseStyles[selector.replace(/\s*&/, '')] = {
114 [`&:not(:has(.${SELECTOR}))`]: {
115 colorScheme: scheme.palette?.mode
116 }
117 };
118 }
119 });
120 }
121 return result;
122};
123const GlobalStyles = (0, _zeroStyled.globalCss)(isDynamicSupport ? ({
124 theme,
125 enableColorScheme
126}) => styles(theme, enableColorScheme) : ({
127 theme
128}) => staticStyles(theme));
129
130/**
131 * Kickstart an elegant, consistent, and simple baseline to build upon.
132 */
133function CssBaseline(inProps) {
134 const props = (0, _DefaultPropsProvider.useDefaultProps)({
135 props: inProps,
136 name: 'MuiCssBaseline'
137 });
138 const {
139 children,
140 enableColorScheme = false
141 } = props;
142 return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
143 children: [isDynamicSupport && /*#__PURE__*/(0, _jsxRuntime.jsx)(GlobalStyles, {
144 enableColorScheme: enableColorScheme
145 }), !isDynamicSupport && !enableColorScheme && /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
146 className: SELECTOR,
147 style: {
148 display: 'none'
149 }
150 }), children]
151 });
152}
153process.env.NODE_ENV !== "production" ? CssBaseline.propTypes /* remove-proptypes */ = {
154 // ┌────────────────────────────── Warning ──────────────────────────────┐
155 // │ These PropTypes are generated from the TypeScript type definitions. │
156 // │ To update them, edit the d.ts file and run `pnpm proptypes`. │
157 // └─────────────────────────────────────────────────────────────────────┘
158 /**
159 * You can wrap a node.
160 */
161 children: _propTypes.default.node,
162 /**
163 * Enable `color-scheme` CSS property to use `theme.palette.mode`.
164 * For more details, check out https://developer.mozilla.org/en-US/docs/Web/CSS/color-scheme
165 * For browser support, check out https://caniuse.com/?search=color-scheme
166 * @default false
167 */
168 enableColorScheme: _propTypes.default.bool
169} : void 0;
170var _default = exports.default = CssBaseline;
\No newline at end of file