| 12345678910111213141516171819202122232425262728293031323334 |
- /**
- * Theme bootstrap row for the browser's pre-plugin interval. Each index
- * render embeds the current durable built-in preference; the browser resolves
- * only `system`, then writes the same DOM fields ui-layout's ThemePresenter
- * owns after the client plugin tree activates.
- */
- import type { IndexInjection } from '@deepseek-ai/dsh-host-webserver'
- import { DEFAULT_PREFERENCE, type ThemePreference } from './theme-settings.ts'
- /** Build the inline script body for one schema-validated built-in preference. */
- function bootThemeScript(preference: ThemePreference): string {
- return `(() => {
- const preference = ${JSON.stringify(preference)}
- const systemDark = preference === 'system'
- && typeof matchMedia !== 'undefined'
- && matchMedia('(prefers-color-scheme: dark)').matches
- const dark = preference === 'dark' || systemDark
- document.documentElement.style.colorScheme = dark ? 'dark' : 'light'
- document.body.toggleAttribute('data-ds-dark-theme', dark)
- })()`
- }
- /**
- * The theme bootstrap as an injection row: an inline script immediately after
- * the opening body tag, before the shell mount and module script.
- * @param preference - Current Host-backed built-in preference.
- * @returns the body script row.
- */
- export function bootThemeInjection(
- preference: ThemePreference = DEFAULT_PREFERENCE,
- ): IndexInjection {
- return { kind: 'script', placement: 'body', text: bootThemeScript(preference) }
- }
|