|
1 | 1 | import "../index.css"; |
2 | 2 | import React, { useEffect } from "react"; |
3 | | -import { applyDocumentTheme, applyHostFonts, applyHostStyleVariables } from "@modelcontextprotocol/ext-apps"; |
| 3 | +import type { McpUiStyles, McpUiTheme } from "@modelcontextprotocol/ext-apps"; |
4 | 4 | import { UiDependencyProvider } from "@apify/ui-library"; |
5 | 5 | import { cssColorsVariablesLight, cssColorsVariablesDark } from "@apify/ui-library"; |
6 | 6 | import { ThemeProvider } from "styled-components"; |
7 | 7 | import { createRoot } from "react-dom/client"; |
8 | 8 | import { McpAppProvider, useMcpApp } from "../context/mcp-app-context"; |
9 | 9 |
|
| 10 | +function applyDocumentTheme(theme: McpUiTheme): void { |
| 11 | + document.documentElement.setAttribute("data-theme", theme); |
| 12 | + document.documentElement.style.colorScheme = theme; |
| 13 | +} |
| 14 | + |
| 15 | +function applyHostStyleVariables(styles: McpUiStyles, root: HTMLElement = document.documentElement): void { |
| 16 | + for (const [key, value] of Object.entries(styles)) { |
| 17 | + if (value !== undefined) { |
| 18 | + root.style.setProperty(key, value); |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +let _fontsInjected = false; |
| 24 | +function applyHostFonts(fontCss: string): void { |
| 25 | + if (_fontsInjected) return; |
| 26 | + const style = document.createElement("style"); |
| 27 | + style.textContent = fontCss; |
| 28 | + document.head.appendChild(style); |
| 29 | + _fontsInjected = true; |
| 30 | +} |
| 31 | + |
10 | 32 | function resolveSystemTheme(): "light" | "dark" { |
11 | 33 | return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light"; |
12 | 34 | } |
|
0 commit comments