2025-10-13 22:15:42 +08:00
|
|
|
import { css, keyframes } from "@emotion/css";
|
2025-09-21 19:51:57 +08:00
|
|
|
import {
|
|
|
|
|
OPT_STYLE_NONE,
|
|
|
|
|
OPT_STYLE_LINE,
|
|
|
|
|
OPT_STYLE_DOTLINE,
|
|
|
|
|
OPT_STYLE_DASHLINE,
|
|
|
|
|
OPT_STYLE_WAVYLINE,
|
|
|
|
|
OPT_STYLE_DASHBOX,
|
|
|
|
|
OPT_STYLE_FUZZY,
|
|
|
|
|
OPT_STYLE_HIGHLIGHT,
|
|
|
|
|
OPT_STYLE_BLOCKQUOTE,
|
2025-10-13 22:15:42 +08:00
|
|
|
OPT_STYLE_GRADIENT,
|
|
|
|
|
OPT_STYLE_BLINK,
|
|
|
|
|
OPT_STYLE_GLOW,
|
2025-09-21 19:51:57 +08:00
|
|
|
OPT_STYLE_DIY,
|
2025-10-11 11:19:33 +08:00
|
|
|
DEFAULT_DIY_STYLE,
|
2025-09-21 19:51:57 +08:00
|
|
|
DEFAULT_COLOR,
|
2025-11-01 15:10:39 +08:00
|
|
|
OPT_STYLE_MARKER,
|
|
|
|
|
OPT_STYLE_GRADIENT_MARKER,
|
2025-09-21 19:51:57 +08:00
|
|
|
} from "../config";
|
|
|
|
|
|
2025-10-13 22:15:42 +08:00
|
|
|
const gradientFlow = keyframes`
|
|
|
|
|
to {
|
|
|
|
|
background-position: 200% center;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const blink = keyframes`
|
|
|
|
|
0%, 100% {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
50% {
|
|
|
|
|
opacity: 0;
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const glow = keyframes`
|
|
|
|
|
from {
|
|
|
|
|
text-shadow: 0 0 10px #fff,
|
|
|
|
|
0 0 20px #fff,
|
|
|
|
|
0 0 30px #0073e6,
|
|
|
|
|
0 0 40px #0073e6;
|
|
|
|
|
}
|
|
|
|
|
to {
|
|
|
|
|
text-shadow: 0 0 20px #fff,
|
|
|
|
|
0 0 30px #ff4da6,
|
|
|
|
|
0 0 40px #ff4da6,
|
|
|
|
|
0 0 50px #ff4da6;
|
|
|
|
|
}
|
2025-10-14 19:15:53 +08:00
|
|
|
`;
|
2025-10-13 22:15:42 +08:00
|
|
|
|
2025-09-21 19:51:57 +08:00
|
|
|
const genLineStyle = (style, color) => `
|
|
|
|
|
text-decoration-line: underline;
|
|
|
|
|
text-decoration-style: ${style};
|
|
|
|
|
text-decoration-color: ${color};
|
2025-11-01 15:10:39 +08:00
|
|
|
text-decoration-thickness: 1px;
|
2025-09-21 19:51:57 +08:00
|
|
|
text-underline-offset: 0.3em;
|
|
|
|
|
-webkit-text-decoration-line: underline;
|
|
|
|
|
-webkit-text-decoration-style: ${style};
|
|
|
|
|
-webkit-text-decoration-color: ${color};
|
2025-11-01 15:10:39 +08:00
|
|
|
-webkit-text-decoration-thickness: 1px;
|
2025-09-21 19:51:57 +08:00
|
|
|
-webkit-text-underline-offset: 0.3em;
|
2025-10-14 19:15:53 +08:00
|
|
|
|
2025-11-01 15:10:39 +08:00
|
|
|
opacity: 0.8;
|
2025-10-14 19:15:53 +08:00
|
|
|
-webkit-opacity: 0.8;
|
2025-09-21 19:51:57 +08:00
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
-webkit-opacity: 1;
|
2025-11-01 15:10:39 +08:00
|
|
|
}
|
2025-09-21 19:51:57 +08:00
|
|
|
`;
|
|
|
|
|
|
2025-10-11 12:01:36 +08:00
|
|
|
const genStyles = ({
|
2025-10-11 11:19:33 +08:00
|
|
|
textDiyStyle = DEFAULT_DIY_STYLE,
|
2025-11-01 15:10:39 +08:00
|
|
|
color = DEFAULT_COLOR,
|
2025-10-11 12:01:36 +08:00
|
|
|
} = {}) => ({
|
2025-09-21 19:51:57 +08:00
|
|
|
// 无样式
|
|
|
|
|
[OPT_STYLE_NONE]: ``,
|
|
|
|
|
// 下划线
|
2025-11-01 15:10:39 +08:00
|
|
|
[OPT_STYLE_LINE]: genLineStyle("solid", color),
|
2025-09-21 19:51:57 +08:00
|
|
|
// 点状线
|
2025-11-01 15:10:39 +08:00
|
|
|
[OPT_STYLE_DOTLINE]: genLineStyle("dotted", color),
|
2025-09-21 19:51:57 +08:00
|
|
|
// 虚线
|
2025-11-01 15:10:39 +08:00
|
|
|
[OPT_STYLE_DASHLINE]: genLineStyle("dashed", color),
|
2025-09-21 19:51:57 +08:00
|
|
|
// 波浪线
|
2025-11-01 15:10:39 +08:00
|
|
|
[OPT_STYLE_WAVYLINE]: genLineStyle("wavy", color),
|
2025-09-21 19:51:57 +08:00
|
|
|
// 虚线框
|
|
|
|
|
[OPT_STYLE_DASHBOX]: `
|
2025-11-01 15:10:39 +08:00
|
|
|
border: 1px dashed ${color};
|
2025-10-26 20:10:13 +08:00
|
|
|
display: block;
|
2025-10-11 11:19:33 +08:00
|
|
|
padding: 0.2em 0.4em;
|
2025-09-21 19:51:57 +08:00
|
|
|
box-sizing: border-box;
|
|
|
|
|
`,
|
2025-11-01 15:10:39 +08:00
|
|
|
// 马克笔
|
|
|
|
|
[OPT_STYLE_MARKER]: `
|
|
|
|
|
background: linear-gradient(to top, ${color} 50%, transparent 50%);
|
|
|
|
|
`,
|
|
|
|
|
// 渐变马克笔
|
|
|
|
|
[OPT_STYLE_GRADIENT_MARKER]: `
|
|
|
|
|
background: linear-gradient(to top, transparent, ${color} 20%, transparent 60%);
|
|
|
|
|
`,
|
2025-09-21 19:51:57 +08:00
|
|
|
// 模糊
|
|
|
|
|
[OPT_STYLE_FUZZY]: `
|
|
|
|
|
filter: blur(0.2em);
|
|
|
|
|
-webkit-filter: blur(0.2em);
|
|
|
|
|
&:hover {
|
|
|
|
|
filter: none;
|
|
|
|
|
-webkit-filter: none;
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
// 高亮
|
|
|
|
|
[OPT_STYLE_HIGHLIGHT]: `
|
|
|
|
|
color: #fff;
|
2025-11-01 15:10:39 +08:00
|
|
|
background-color: ${color};
|
2025-09-21 19:51:57 +08:00
|
|
|
`,
|
|
|
|
|
// 引用
|
|
|
|
|
[OPT_STYLE_BLOCKQUOTE]: `
|
2025-09-25 01:02:38 +08:00
|
|
|
opacity: 0.8;
|
|
|
|
|
-webkit-opacity: 0.8;
|
2025-09-21 19:51:57 +08:00
|
|
|
display: block;
|
2025-09-25 01:13:40 +08:00
|
|
|
padding: 0.25em 0.5em;
|
2025-11-01 15:25:40 +08:00
|
|
|
border-left: 0.25em solid ${color};
|
2025-09-25 01:02:38 +08:00
|
|
|
background: rgb(32, 156, 238, 0.2);
|
2025-09-21 19:51:57 +08:00
|
|
|
&:hover {
|
|
|
|
|
opacity: 1;
|
|
|
|
|
-webkit-opacity: 1;
|
|
|
|
|
}
|
|
|
|
|
`,
|
2025-10-13 22:15:42 +08:00
|
|
|
// 渐变
|
|
|
|
|
[OPT_STYLE_GRADIENT]: `
|
|
|
|
|
background-image: linear-gradient(
|
|
|
|
|
90deg,
|
|
|
|
|
#3b82f6,
|
|
|
|
|
#9333ea,
|
|
|
|
|
#ec4899,
|
|
|
|
|
#3b82f6
|
|
|
|
|
);
|
|
|
|
|
background-size: 200% auto;
|
|
|
|
|
color: transparent;
|
|
|
|
|
-webkit-background-clip: text;
|
|
|
|
|
background-clip: text;
|
|
|
|
|
animation: ${gradientFlow} 4s linear infinite;
|
|
|
|
|
`,
|
|
|
|
|
// 闪现
|
|
|
|
|
[OPT_STYLE_BLINK]: `
|
|
|
|
|
animation: ${blink} 1s infinite;
|
|
|
|
|
`,
|
|
|
|
|
// 发光
|
|
|
|
|
[OPT_STYLE_GLOW]: `
|
|
|
|
|
animation: ${glow} 2s ease-in-out infinite alternate;
|
|
|
|
|
`,
|
2025-09-21 19:51:57 +08:00
|
|
|
// 自定义
|
2025-10-11 12:01:36 +08:00
|
|
|
[OPT_STYLE_DIY]: `
|
|
|
|
|
${textDiyStyle}
|
|
|
|
|
`,
|
2025-09-21 19:51:57 +08:00
|
|
|
});
|
|
|
|
|
|
2025-11-01 15:10:39 +08:00
|
|
|
export const genTextClass = ({ textDiyStyle, bgColor }) => {
|
|
|
|
|
const styles = genStyles({ textDiyStyle, color: bgColor || DEFAULT_COLOR });
|
2025-09-21 19:51:57 +08:00
|
|
|
const textClass = {};
|
|
|
|
|
let textStyles = "";
|
|
|
|
|
Object.entries(styles).forEach(([k, v]) => {
|
|
|
|
|
textClass[k] = css`
|
|
|
|
|
${v}
|
|
|
|
|
`;
|
|
|
|
|
});
|
|
|
|
|
Object.entries(styles).forEach(([k, v]) => {
|
|
|
|
|
textStyles += `
|
|
|
|
|
.${textClass[k]} {
|
|
|
|
|
${v}
|
|
|
|
|
}
|
|
|
|
|
`;
|
|
|
|
|
});
|
|
|
|
|
return [textClass, textStyles];
|
|
|
|
|
};
|
2025-10-11 12:01:36 +08:00
|
|
|
|
|
|
|
|
export const defaultStyles = genStyles();
|