-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: show and export theme css #1007
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
zeevenn
wants to merge
7
commits into
main
Choose a base branch
from
feat/theme-export
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+351
−28
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🎊 PR Preview has been successfully built and deployed to https://doocs-md-preview-pr-1007.surge.sh |
Deploying doocs-md with
|
Latest commit: |
0e6a674
|
Status: | ✅ Deploy successful! |
Preview URL: | https://37ed02de.doocs-md.pages.dev |
Branch Preview URL: | https://feat-theme-export.doocs-md.pages.dev |
@M-Kepler 可以再提供一个我导出的版本,方便我 diff |
方案1-merged-theme.css 这个是导出的 |
好的,稍等修复 |
当前问题内置主题为 JS 对象,需要动态转换为 CSS 内联样式,而自定义样式为 CSS 字符串,需要转换为 JS 对象再和内置主题合并,最终再转换为内联对象。 纯 CSS 主题
伪代码: export class PureCSSThemeManager {
private styleElement: HTMLStyleElement | null = null
/**
* 生成动态配置CSS
*/
private generateDynamicCSS(config: DynamicConfig): string {
return `
:root {
--md-font-family: ${config.fonts};
--md-font-size: ${config.size};
--md-text-indent: ${config.isUseIndent ? '2em' : '0'};
--md-text-align: ${config.isUseJustify ? 'justify' : 'left'};
--md-primary-color: ${config.primaryColor};
}
.md-container {
font-family: var(--md-font-family);
font-size: var(--md-font-size);
}
.md-p {
text-indent: var(--md-text-indent);
text-align: var(--md-text-align);
}
`
}
/**
* 更新主题
*/
updateTheme(baseThemeCSS: string, customCSS: string, config: DynamicConfig): void {
const dynamicCSS = this.generateDynamicCSS(config)
// 直接拼接CSS字符串
const finalCSS = `
${baseThemeCSS}
${dynamicCSS}
${customCSS}
`
this.injectStyles(finalCSS)
}
private injectStyles(css: string): void {
if (this.styleElement) {
this.styleElement.remove()
}
this.styleElement = document.createElement('style')
this.styleElement.id = 'md-pure-css-theme'
this.styleElement.textContent = css
document.head.appendChild(this.styleElement)
}
} |
921b284
to
0e6a674
Compare
好像导出的css不包含暗色。 /* 暗色主题支持 */
/* 支持通过.dark类、VSCode暗色主题和高对比度主题触发 */
.dark,
body.vscode-dark,
body.vscode-high-contrast {
--background: 0 0% 3.9%;
--foreground: 0 0% 98%;
--card: 0 0% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 0 0% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 0 0% 9%;
--secondary: 0 0% 14.9%;
--secondary-foreground: 0 0% 98%;
--muted: 0 0% 14.9%;
--muted-foreground: 0 0% 63.9%;
--accent: 0 0% 14.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 0 0% 14.9%;
--input: 0 0% 14.9%;
--ring: 0 0% 83.1%;
--blockquote-background: #212121;
} |
应该是导出的时候我根据 内置主题 key 去合并了,所以丢失了一些内容,需要先重构主题系统,这块可能需要一点时间。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes: #1004 closes: #875