Skip to content

Commit b74576a

Browse files
committed
feat: remove variable resolver
1 parent 5585769 commit b74576a

File tree

5 files changed

+7
-110
lines changed

5 files changed

+7
-110
lines changed

packages/core/src/theme/cssVariableResolver.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

packages/core/src/theme/cssVariables.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,12 @@ export interface CSSVariableConfig {
1717
* @returns CSS 变量字符串
1818
*/
1919
export function generateCSSVariables(config: CSSVariableConfig): string {
20-
const fontSizeNum = Number.parseFloat(config.fontSize)
21-
2220
return `
2321
:root {
2422
/* 动态配置变量 */
2523
--md-primary-color: ${config.primaryColor};
2624
--md-font-family: ${config.fontFamily};
2725
--md-font-size: ${config.fontSize};
28-
29-
/* 标题大小(绝对值,与旧系统行为一致) */
30-
--md-h1-size: ${fontSizeNum * 1.2}px;
31-
--md-h2-size: ${fontSizeNum * 1.2}px;
32-
--md-h3-size: ${fontSizeNum * 1.1}px;
33-
--md-h4-size: ${fontSizeNum}px;
34-
--md-h5-size: ${fontSizeNum}px;
35-
--md-h6-size: ${fontSizeNum}px;
3626
}
3727
3828
/* 段落缩进和对齐 */

packages/core/src/theme/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './cssProcessor'
22
export * from './cssScopeWrapper'
3-
export * from './cssVariableResolver'
43
export * from './cssVariables'
54
export * from './selectorMapping'
65
export * from './themeApplicator'

packages/core/src/theme/themeExporter.ts

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import type { CSSVariableConfig } from './cssVariables'
77
import { downloadFile } from '@md/shared/utils'
8-
import { extractCSSVariables, resolveCSSVariables } from './cssVariableResolver'
98
import { generateCSSVariables } from './cssVariables'
109

1110
/**
@@ -39,49 +38,7 @@ export function exportMergedTheme(
3938
customCSS,
4039
].filter(Boolean).join(`\n`)
4140

42-
// 3. 提取变量映射
43-
const variablesMap = extractCSSVariables(variablesCSS)
44-
45-
// 4. 解析变量(将 CSS 变量替换为实际值)
46-
const resolvedCSS = resolveCSSVariables(mergedCSS, variablesMap)
47-
48-
// 5. 下载文件
49-
downloadFile(resolvedCSS, `text/css`, `${fileName}.css`)
50-
51-
return resolvedCSS
52-
}
53-
54-
/**
55-
* 导出带变量的主题(推荐)
56-
* @param customCSS - 用户自定义的CSS内容
57-
* @param baseThemeCSS - 基础主题CSS
58-
* @param config - 配置项
59-
* @param fileName - 导出文件名
60-
*/
61-
export function exportThemeWithVariables(
62-
customCSS: string,
63-
baseThemeCSS: string,
64-
config: CSSVariableConfig,
65-
fileName: string,
66-
) {
67-
const variablesCSS = generateCSSVariables(config)
68-
69-
const mergedCSS = [
70-
`/**`,
71-
` * MD 主题导出(包含 CSS 变量)`,
72-
` * 导出时间: ${new Date().toLocaleString()}`,
73-
` * 说明: 该文件使用 CSS 变量,可通过修改 :root 中的变量值来调整主题`,
74-
` */`,
75-
``,
76-
variablesCSS,
77-
``,
78-
baseThemeCSS,
79-
``,
80-
`/* 自定义样式 */`,
81-
customCSS,
82-
].filter(Boolean).join(`\n`)
83-
84-
downloadFile(mergedCSS, `text/css`, `${fileName}.css`)
41+
downloadFile(mergedCSS, `${fileName}.css`, `text/css`)
8542

8643
return mergedCSS
8744
}

packages/shared/src/configs/theme-css/default.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ h1 {
1111
border-bottom: 2px solid var(--md-primary-color);
1212
margin: 2em auto 1em;
1313
color: hsl(var(--foreground));
14-
font-size: var(--md-h1-size);
14+
font-size: calc(var(--md-font-size) * 1.2);
1515
font-weight: bold;
1616
text-align: center;
1717
}
@@ -23,7 +23,7 @@ h2 {
2323
margin: 4em auto 2em;
2424
color: #fff;
2525
background: var(--md-primary-color);
26-
font-size: var(--md-h2-size);
26+
font-size: calc(var(--md-font-size) * 1.2);
2727
font-weight: bold;
2828
text-align: center;
2929
}
@@ -34,7 +34,7 @@ h3 {
3434
border-left: 3px solid var(--md-primary-color);
3535
margin: 2em 8px 0.75em 0;
3636
color: hsl(var(--foreground));
37-
font-size: var(--md-h3-size);
37+
font-size: calc(var(--md-font-size) * 1.1);
3838
font-weight: bold;
3939
line-height: 1.2;
4040
}
@@ -43,22 +43,22 @@ h3 {
4343
h4 {
4444
margin: 2em 8px 0.5em;
4545
color: var(--md-primary-color);
46-
font-size: var(--md-h4-size);
46+
font-size: calc(var(--md-font-size) * 1);
4747
font-weight: bold;
4848
}
4949

5050
/* ==================== 五级标题 ==================== */
5151
h5 {
5252
margin: 1.5em 8px 0.5em;
5353
color: var(--md-primary-color);
54-
font-size: var(--md-h5-size);
54+
font-size: calc(var(--md-font-size) * 1);
5555
font-weight: bold;
5656
}
5757

5858
/* ==================== 六级标题 ==================== */
5959
h6 {
6060
margin: 1.5em 8px 0.5em;
61-
font-size: var(--md-h6-size);
61+
font-size: calc(var(--md-font-size) * 1);
6262
color: var(--md-primary-color);
6363
}
6464

0 commit comments

Comments
 (0)