1 | 'use client';
|
2 |
|
3 | import * as React from 'react';
|
4 | import PropTypes from 'prop-types';
|
5 | import { globalCss } from "../zero-styled/index.js";
|
6 | import { useDefaultProps } from "../DefaultPropsProvider/index.js";
|
7 |
|
8 |
|
9 | import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
10 | const isDynamicSupport = typeof globalCss({}) === 'function';
|
11 | export const html = (theme, enableColorScheme) => ({
|
12 | WebkitFontSmoothing: 'antialiased',
|
13 |
|
14 | MozOsxFontSmoothing: 'grayscale',
|
15 |
|
16 |
|
17 |
|
18 | boxSizing: 'border-box',
|
19 |
|
20 | WebkitTextSizeAdjust: '100%',
|
21 |
|
22 | ...(enableColorScheme && !theme.vars && {
|
23 | colorScheme: theme.palette.mode
|
24 | })
|
25 | });
|
26 | export const body = theme => ({
|
27 | color: (theme.vars || theme).palette.text.primary,
|
28 | ...theme.typography.body1,
|
29 | backgroundColor: (theme.vars || theme).palette.background.default,
|
30 | '@media print': {
|
31 |
|
32 | backgroundColor: (theme.vars || theme).palette.common.white
|
33 | }
|
34 | });
|
35 | export const styles = (theme, enableColorScheme = false) => {
|
36 | const colorSchemeStyles = {};
|
37 | if (enableColorScheme && theme.colorSchemes && typeof theme.getColorSchemeSelector === 'function') {
|
38 | Object.entries(theme.colorSchemes).forEach(([key, scheme]) => {
|
39 | const selector = theme.getColorSchemeSelector(key);
|
40 | if (selector.startsWith('@')) {
|
41 |
|
42 | colorSchemeStyles[selector] = {
|
43 | ':root': {
|
44 | colorScheme: scheme.palette?.mode
|
45 | }
|
46 | };
|
47 | } else {
|
48 |
|
49 | colorSchemeStyles[selector.replace(/\s*&/, '')] = {
|
50 | colorScheme: scheme.palette?.mode
|
51 | };
|
52 | }
|
53 | });
|
54 | }
|
55 | let defaultStyles = {
|
56 | html: html(theme, enableColorScheme),
|
57 | '*, *::before, *::after': {
|
58 | boxSizing: 'inherit'
|
59 | },
|
60 | 'strong, b': {
|
61 | fontWeight: theme.typography.fontWeightBold
|
62 | },
|
63 | body: {
|
64 | margin: 0,
|
65 |
|
66 | ...body(theme),
|
67 |
|
68 |
|
69 | '&::backdrop': {
|
70 | backgroundColor: (theme.vars || theme).palette.background.default
|
71 | }
|
72 | },
|
73 | ...colorSchemeStyles
|
74 | };
|
75 | const themeOverrides = theme.components?.MuiCssBaseline?.styleOverrides;
|
76 | if (themeOverrides) {
|
77 | defaultStyles = [defaultStyles, themeOverrides];
|
78 | }
|
79 | return defaultStyles;
|
80 | };
|
81 |
|
82 |
|
83 | const SELECTOR = 'mui-ecs';
|
84 | const staticStyles = theme => {
|
85 | const result = styles(theme, false);
|
86 | const baseStyles = Array.isArray(result) ? result[0] : result;
|
87 | if (!theme.vars && baseStyles) {
|
88 | baseStyles.html[`:root:has(${SELECTOR})`] = {
|
89 | colorScheme: theme.palette.mode
|
90 | };
|
91 | }
|
92 | if (theme.colorSchemes) {
|
93 | Object.entries(theme.colorSchemes).forEach(([key, scheme]) => {
|
94 | const selector = theme.getColorSchemeSelector(key);
|
95 | if (selector.startsWith('@')) {
|
96 |
|
97 | baseStyles[selector] = {
|
98 | [`:root:not(:has(.${SELECTOR}))`]: {
|
99 | colorScheme: scheme.palette?.mode
|
100 | }
|
101 | };
|
102 | } else {
|
103 |
|
104 | baseStyles[selector.replace(/\s*&/, '')] = {
|
105 | [`&:not(:has(.${SELECTOR}))`]: {
|
106 | colorScheme: scheme.palette?.mode
|
107 | }
|
108 | };
|
109 | }
|
110 | });
|
111 | }
|
112 | return result;
|
113 | };
|
114 | const GlobalStyles = globalCss(isDynamicSupport ? ({
|
115 | theme,
|
116 | enableColorScheme
|
117 | }) => styles(theme, enableColorScheme) : ({
|
118 | theme
|
119 | }) => staticStyles(theme));
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | function CssBaseline(inProps) {
|
125 | const props = useDefaultProps({
|
126 | props: inProps,
|
127 | name: 'MuiCssBaseline'
|
128 | });
|
129 | const {
|
130 | children,
|
131 | enableColorScheme = false
|
132 | } = props;
|
133 | return _jsxs(React.Fragment, {
|
134 | children: [isDynamicSupport && _jsx(GlobalStyles, {
|
135 | enableColorScheme: enableColorScheme
|
136 | }), !isDynamicSupport && !enableColorScheme && _jsx("span", {
|
137 | className: SELECTOR,
|
138 | style: {
|
139 | display: 'none'
|
140 | }
|
141 | }), children]
|
142 | });
|
143 | }
|
144 | process.env.NODE_ENV !== "production" ? CssBaseline.propTypes = {
|
145 |
|
146 |
|
147 |
|
148 |
|
149 | |
150 |
|
151 |
|
152 | children: PropTypes.node,
|
153 | |
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 | enableColorScheme: PropTypes.bool
|
160 | } : void 0;
|
161 | export default CssBaseline; |
\ | No newline at end of file |