MCPcopy Create free account
hub / github.com/JacobLinCool/LeetCode-Stats-Card / ThemeExtension

Function ThemeExtension

packages/core/src/exts/theme.ts:35–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33};
34
35export function ThemeExtension(): Extension {
36 return async function Theme(generator, data, body, styles) {
37 if (!generator.config?.theme) {
38 return;
39 }
40
41 if (typeof generator.config.theme === "string" && supported[generator.config.theme]) {
42 const theme = supported[generator.config.theme];
43 styles.push(css(theme));
44 if (theme.extends) {
45 body["theme-ext"] = () => theme.extends as Item;
46 }
47 }
48
49 if (
50 typeof generator.config.theme?.light === "string" &&
51 supported[generator.config.theme.light]
52 ) {
53 const theme = supported[generator.config.theme.light];
54 styles.push(`@media (prefers-color-scheme: light) {${css(theme)}}`);
55 if (theme.extends) {
56 body["theme-ext-light"] = () => theme.extends as Item;
57 }
58 }
59
60 if (
61 typeof generator.config.theme?.dark === "string" &&
62 supported[generator.config.theme.dark]
63 ) {
64 const theme = supported[generator.config.theme.dark];
65 styles.push(`@media (prefers-color-scheme: dark) {${css(theme)}}`);
66 if (theme.extends) {
67 body["theme-ext-dark"] = () => theme.extends as Item;
68 }
69 }
70
71 // If explicit colors are provided, apply them as an overriding theme
72 const colors = (generator.config as Config | undefined)?.colors;
73 if (Array.isArray(colors) && colors.length > 0) {
74 const t = themeFromColors(colors);
75 styles.push(css(t)); // push LAST = highest precedence
76 }
77 };
78}
79
80function css(theme: Theme): string {
81 let css = ":root{";

Callers

nothing calls this directly

Calls 2

themeFromColorsFunction · 0.85
cssFunction · 0.70

Tested by

no test coverage detected