Files
LCUI/scripts/postcss-lcui-dark.js
Liu 9217b1ca3a feat(styles): add light and dark theme support
- share shadcn neutral color tokens between both Tailwind configs
- rewrite Tailwind dark selectors into LCUI-compatible descendant selectors
- theme style-nova components and doc-viewer surfaces for dark mode
- generate GitHub Light and GitHub Dark syntax line pairs for code blocks
- support alpha channels in text style tag colors
- keep focus rings and scrollbars visible on dark surfaces
- use a neutral code surface instead of GitHub's blue-tinted background
2026-11-15 23:40:42 +08:00

37 lines
963 B
JavaScript

const DARK_IS = ":is(.dark *)";
const DARK_WHERE = ":where(.dark, .dark *)";
function rewriteSelector(selector) {
if (!selector.includes(DARK_IS) && !selector.includes(DARK_WHERE)) {
return selector;
}
const normalized = selector.replaceAll(DARK_WHERE, DARK_IS);
return normalized
.split(",")
.map((part) => {
const trimmed = part.trim();
if (!trimmed.includes(DARK_IS)) {
return trimmed;
}
const base = trimmed.replaceAll(DARK_IS, "").trim();
if (!base || base === ".dark" || base.startsWith(".dark ")) {
return base || ".dark";
}
return `.dark ${base}`;
})
.join(", ");
}
module.exports = () => ({
postcssPlugin: "lcui-dark-selectors",
Rule(rule) {
const selector = rewriteSelector(rule.selector);
if (selector !== rule.selector) {
rule.selector = selector;
}
},
});
module.exports.rewriteSelector = rewriteSelector;
module.exports.postcss = true;