fix html fontsize

This commit is contained in:
Gabe Yuan
2023-11-22 10:23:14 +08:00
parent 013a05201b
commit f8bfcba317
7 changed files with 33 additions and 12 deletions

View File

@@ -12,10 +12,24 @@ import { THEME_DARK, THEME_LIGHT } from "../config";
export default function Theme({ children, options }) { export default function Theme({ children, options }) {
const { darkMode } = useDarkMode(); const { darkMode } = useDarkMode();
const theme = useMemo(() => { const theme = useMemo(() => {
let htmlFontSize = 16;
try {
const s = window.getComputedStyle(document.body.parentNode).fontSize;
const fontSize = parseInt(s.replace("px", ""));
if (fontSize > 0 && fontSize < 1000) {
htmlFontSize = fontSize;
}
} catch (err) {
//
}
return createTheme({ return createTheme({
palette: { palette: {
mode: darkMode ? THEME_DARK : THEME_LIGHT, mode: darkMode ? THEME_DARK : THEME_LIGHT,
}, },
typography: {
htmlFontSize,
},
...options, ...options,
}); });
}, [darkMode, options]); }, [darkMode, options]);

View File

@@ -15,7 +15,7 @@ export const FIXER_ALL = [
FIXER_BN, FIXER_BN,
FIXER_BR_DIV, FIXER_BR_DIV,
FIXER_BN_DIV, FIXER_BN_DIV,
FIXER_FONTSIZE, // FIXER_FONTSIZE,
]; ];
/** /**

View File

@@ -6,6 +6,7 @@ import Box from "@mui/material/Box";
import Link from "@mui/material/Link"; import Link from "@mui/material/Link";
import { useI18n } from "../../hooks/I18n"; import { useI18n } from "../../hooks/I18n";
import DarkModeButton from "./DarkModeButton"; import DarkModeButton from "./DarkModeButton";
import Typography from "@mui/material/Typography";
function Header(props) { function Header(props) {
const i18n = useI18n(); const i18n = useI18n();
@@ -30,14 +31,14 @@ function Header(props) {
<MenuIcon /> <MenuIcon />
</IconButton> </IconButton>
</Box> </Box>
<Box sx={{ flexGrow: 1 }}> <Typography component="div" sx={{ flexGrow: 1, fontWeight: "bold" }}>
<Link <Link
underline="none" underline="none"
color="inherit" color="inherit"
href={process.env.REACT_APP_HOMEPAGE} href={process.env.REACT_APP_HOMEPAGE}
target="_blank" target="_blank"
>{`${i18n("app_name")} v${process.env.REACT_APP_VERSION}`}</Link> >{`${i18n("app_name")} v${process.env.REACT_APP_VERSION}`}</Link>
</Box> </Typography>
<DarkModeButton /> <DarkModeButton />
</Toolbar> </Toolbar>
</AppBar> </AppBar>

View File

@@ -4,6 +4,7 @@ import CloseIcon from "@mui/icons-material/Close";
import HomeIcon from "@mui/icons-material/Home"; import HomeIcon from "@mui/icons-material/Home";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import DarkModeButton from "../Options/DarkModeButton"; import DarkModeButton from "../Options/DarkModeButton";
import Typography from "@mui/material/Typography";
export default function Header({ setShowPopup }) { export default function Header({ setShowPopup }) {
const handleHomepage = () => { const handleHomepage = () => {
@@ -21,14 +22,16 @@ export default function Header({ setShowPopup }) {
<IconButton onClick={handleHomepage}> <IconButton onClick={handleHomepage}>
<HomeIcon /> <HomeIcon />
</IconButton> </IconButton>
<Box <Typography
component="div"
sx={{ sx={{
userSelect: "none", userSelect: "none",
WebkitUserSelect: "none", WebkitUserSelect: "none",
fontWeight: "bold",
}} }}
> >
{`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`} {`${process.env.REACT_APP_NAME} v${process.env.REACT_APP_VERSION}`}
</Box> </Typography>
</Stack> </Stack>
{setShowPopup ? ( {setShowPopup ? (

View File

@@ -2,6 +2,7 @@ import Box from "@mui/material/Box";
import Chip from "@mui/material/Chip"; import Chip from "@mui/material/Chip";
import Stack from "@mui/material/Stack"; import Stack from "@mui/material/Stack";
import FavBtn from "./FavBtn"; import FavBtn from "./FavBtn";
import Typography from "@mui/material/Typography";
const exchangeMap = { const exchangeMap = {
word_third: "第三人称单数", word_third: "第三人称单数",
@@ -24,16 +25,16 @@ export default function DictCont({ dictResult }) {
justifyContent="space-between" justifyContent="space-between"
alignItems="flex-start" alignItems="flex-start"
> >
<div style={{ fontWeight: "bold" }}> <Typography variant="subtitle1" style={{ fontWeight: "bold" }}>
{dictResult.simple_means?.word_name} {dictResult.simple_means?.word_name}
</div> </Typography>
<FavBtn word={dictResult.simple_means?.word_name} /> <FavBtn word={dictResult.simple_means?.word_name} />
</Stack> </Stack>
{dictResult.simple_means?.symbols?.map(({ ph_en, ph_am, parts }, idx) => ( {dictResult.simple_means?.symbols?.map(({ ph_en, ph_am, parts }, idx) => (
<div key={idx}> <Typography key={idx} component="div">
{(ph_en || ph_am) && ( {(ph_en || ph_am) && (
<div>{`英 /${ph_en || ""}/ 美 /${ph_am || ""}/`}</div> <Typography>{`英 /${ph_en || ""}/ 美 /${ph_am || ""}/`}</Typography>
)} )}
<ul style={{ margin: "0.5em 0" }}> <ul style={{ margin: "0.5em 0" }}>
{parts.map(({ part, means }, idx) => ( {parts.map(({ part, means }, idx) => (
@@ -42,14 +43,14 @@ export default function DictCont({ dictResult }) {
</li> </li>
))} ))}
</ul> </ul>
</div> </Typography>
))} ))}
<div> <Typography>
{Object.entries(dictResult.simple_means?.exchange || {}) {Object.entries(dictResult.simple_means?.exchange || {})
.map(([key, val]) => `${exchangeMap[key] || key}: ${val.join(", ")}`) .map(([key, val]) => `${exchangeMap[key] || key}: ${val.join(", ")}`)
.join("; ")} .join("; ")}
</div> </Typography>
<Stack direction="row" spacing={1} flexWrap="wrap" useFlexGap> <Stack direction="row" spacing={1} flexWrap="wrap" useFlexGap>
{Object.values(dictResult.simple_means?.tags || {}) {Object.values(dictResult.simple_means?.tags || {})

View File

@@ -95,6 +95,7 @@ function TranForm({ text, setText, tranboxSetting, transApis }) {
<Box> <Box>
<TextField <TextField
size="small"
label={i18n("original_text")} label={i18n("original_text")}
inputRef={inputRef} inputRef={inputRef}
fullWidth fullWidth

View File

@@ -69,6 +69,7 @@ export default function TranCont({
<> <>
<Box> <Box>
<TextField <TextField
size="small"
label={i18n("translated_text")} label={i18n("translated_text")}
// disabled // disabled
fullWidth fullWidth