The /client entry of a UI plugin exports no values beyond what cordis loading needs; the theme constants block returns to type-only re-exports, the per-namespace schemas move into the shared *-settings modules instead of widening the host entries, and same-package specs import those internals directly per the export discipline in packages/client/AGENTS.md.
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
/** Theme preferences stored in the Host user-settings document. */
|
|
|
|
import z from 'schemastery'
|
|
|
|
/** Built-in preferences accepted at the registry and settings boundaries. */
|
|
export const THEME_PREFERENCES = ['light', 'dark', 'system'] as const
|
|
|
|
/** Settings namespace owned by the theme plugin. */
|
|
export const THEME_SETTINGS_NAMESPACE = 'ui-theme'
|
|
|
|
/** Field carrying the selected built-in theme preference. */
|
|
export const THEME_PREFERENCE_FIELD = 'preference'
|
|
|
|
/** Theme preference persisted by the product Appearance row. */
|
|
export type ThemePreference = typeof THEME_PREFERENCES[number]
|
|
|
|
/** Default preference when the user-settings document has no override. */
|
|
export const DEFAULT_PREFERENCE: ThemePreference = 'system'
|
|
|
|
/** Durable theme section shared by the Host schema and the browser scope. */
|
|
export interface ThemeSettings {
|
|
/** Selected built-in preference. */
|
|
preference: ThemePreference
|
|
}
|
|
|
|
/** Durable theme schema; also the wire envelope the browser scope validates against. */
|
|
export const ThemeSettingsSchema: z<ThemeSettings> = z.object({
|
|
[THEME_PREFERENCE_FIELD]: z.union([...THEME_PREFERENCES]).default(DEFAULT_PREFERENCE),
|
|
})
|
|
|
|
/**
|
|
* Narrow one wire or registry value to a persistable preference.
|
|
* @param value - value crossing the settings or registry boundary.
|
|
* @returns whether the value is a built-in preference.
|
|
*/
|
|
export function isThemePreference(value: unknown): value is ThemePreference {
|
|
return THEME_PREFERENCES.some(preference => preference === value)
|
|
}
|