@12nil/theme-registry-package 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +179 -0
- package/dist/app_theme-K3SQNO7I.js +7 -0
- package/dist/app_theme-K3SQNO7I.js.map +1 -0
- package/dist/chunk-GUPUN2GN.js +732 -0
- package/dist/chunk-GUPUN2GN.js.map +1 -0
- package/dist/index.cjs +954 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +291 -0
- package/dist/index.d.ts +291 -0
- package/dist/index.js +172 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../theme-registry.ts","../app_theme.ts","../index.ts","../theme-provider.tsx","../theme-utils.ts"],"sourcesContent":["export const RUNTIME_THEME_REGISTRY_VERSION = '0.2.0'\r\n\r\nexport interface ThemePalette {\r\n primary: string\r\n secondary: string\r\n tertiary?: string\r\n background: string\r\n text: string\r\n accent: string\r\n muted: string\r\n error: string\r\n warning: string\r\n success: string\r\n info: string\r\n}\r\n\r\nexport interface SemanticColorTokens {\r\n primary: string\r\n secondary: string\r\n destructive: string\r\n success: string\r\n warning: string\r\n info: string\r\n}\r\n\r\nexport interface SemanticSurfaceTokens {\r\n page: string\r\n card: string\r\n sidebar: string\r\n modal: string\r\n popover: string\r\n}\r\n\r\nexport interface SemanticTextTokens {\r\n primary: string\r\n secondary: string\r\n tertiary: string\r\n disabled: string\r\n}\r\n\r\nexport interface SemanticBorderTokens {\r\n default: string\r\n subtle: string\r\n strong: string\r\n}\r\n\r\nexport interface ThemeTokensV2 {\r\n colors: SemanticColorTokens\r\n surface: SemanticSurfaceTokens\r\n text: SemanticTextTokens\r\n border: SemanticBorderTokens\r\n}\r\n\r\nexport type ThemeTokenSet = ThemePalette | ThemeTokensV2\r\n\r\nexport interface ThemeCompatibility {\r\n minRegistryVersion?: string\r\n}\r\n\r\nexport interface ThemeMetadata {\r\n author?: string\r\n version?: string\r\n description?: string\r\n homepage?: string\r\n license?: string\r\n compatibility?: ThemeCompatibility\r\n}\r\n\r\nexport interface ThemeDefinition {\r\n name: string\r\n modes: Record<string, ThemeTokenSet>\r\n metadata?: ThemeMetadata\r\n}\r\n\r\nexport type ThemeRegistrationConflict = 'throw' | 'replace' | 'merge'\r\n\r\nexport interface ThemeRegistrationOptions {\r\n ifExists?: ThemeRegistrationConflict\r\n validate?: boolean\r\n}\r\n\r\nexport interface ThemeFallbackConfig {\r\n themeName?: string\r\n modeName?: string\r\n}\r\n\r\nexport interface ThemeValidationIssue {\r\n path: string\r\n message: string\r\n}\r\n\r\nexport interface ThemeValidationResult {\r\n valid: boolean\r\n issues: ThemeValidationIssue[]\r\n}\r\n\r\nexport interface ThemeResolutionResult {\r\n themeName: string | null\r\n modeName: string | null\r\n tokens: ThemeTokenSet | null\r\n}\r\n\r\nexport interface ThemePluginDefinition {\r\n name: string\r\n version?: string\r\n description?: string\r\n author?: string\r\n homepage?: string\r\n license?: string\r\n minRegistryVersion?: string\r\n theme?: ThemeDefinition\r\n themes?: ThemeDefinition[]\r\n icons?: Record<string, string>\r\n fonts?: Record<string, string>\r\n spacing?: Record<string, string | number>\r\n typography?: Record<string, string | number>\r\n metadata?: Record<string, unknown>\r\n}\r\n\r\nexport interface ThemePluginContributions {\r\n icons: Record<string, string>\r\n fonts: Record<string, string>\r\n spacing: Record<string, string | number>\r\n typography: Record<string, string | number>\r\n metadata: Record<string, unknown>\r\n}\r\n\r\nexport type ThemeCompositionLayerType = 'brand' | 'appearance' | 'accessibility'\r\n\r\nexport interface ThemeCompositionLayerDefinition {\r\n type: ThemeCompositionLayerType\r\n name: string\r\n tokens: ThemeTokenSet\r\n metadata?: Record<string, unknown>\r\n}\r\n\r\nexport interface ThemeCompositionSelection {\r\n brand?: string | null\r\n appearance?: string | null\r\n accessibility?: string | null\r\n}\r\n\r\nexport interface ThemeCompositionResult {\r\n selection: ThemeCompositionSelection\r\n tokens: ThemeTokenSet | null\r\n appliedLayers: ThemeCompositionLayerDefinition[]\r\n}\r\n\r\nexport type ThemeLoadSource = string | (() => Promise<ThemeDefinition | ThemeDefinition[]>)\r\n\r\nexport interface ThemeLoadOptions {\r\n ifExists?: ThemeRegistrationConflict\r\n validate?: boolean\r\n cacheKey?: string\r\n maxAgeMs?: number\r\n forceRefresh?: boolean\r\n}\r\n\r\nexport interface ThemeLoadResult {\r\n loaded: number\r\n themes: string[]\r\n source: string\r\n fromCache: boolean\r\n}\r\n\r\nexport interface ThemeLoadCacheEntry {\r\n themes: ThemeDefinition[]\r\n loadedAt: number\r\n source: string\r\n}\r\n\r\nexport interface ThemeDocumentAttributes {\r\n 'data-theme': string\r\n 'data-mode': string\r\n}\r\n\r\nexport type PluginRegistrationConflict = 'throw' | 'replace' | 'merge'\r\n\r\nexport interface PluginRegistrationOptions {\r\n ifExists?: PluginRegistrationConflict\r\n themeIfExists?: ThemeRegistrationConflict\r\n validateThemes?: boolean\r\n}\r\n\r\nexport interface ThemeRegistryEventPayloadMap {\r\n registered: { themeName: string }\r\n replaced: { themeName: string }\r\n merged: { themeName: string }\r\n unregistered: { themeName: string }\r\n variantAdded: { themeName: string; variantName: string }\r\n themeChanged: { themeName: string; modeName: string }\r\n loaded: { source: string; count: number; fromCache: boolean }\r\n composed: { appliedLayers: string[] }\r\n pluginRegistered: { pluginName: string }\r\n pluginUnregistered: { pluginName: string }\r\n destroyed: { timestamp: string }\r\n}\r\n\r\nexport type ThemeRegistryEvent = keyof ThemeRegistryEventPayloadMap\r\nexport type ThemeRegistryEventHandler<K extends ThemeRegistryEvent> = (payload: ThemeRegistryEventPayloadMap[K]) => void\r\n\r\nconst LEGACY_REQUIRED_KEYS = ['primary', 'secondary', 'background', 'text', 'accent', 'muted', 'error', 'warning', 'success', 'info'] as const\r\nconst LEGACY_ALLOWED_KEYS = [...LEGACY_REQUIRED_KEYS, 'tertiary'] as const\r\n\r\nconst SEMANTIC_SCHEMA: Record<string, readonly string[]> = {\r\n colors: ['primary', 'secondary', 'destructive', 'success', 'warning', 'info'],\r\n surface: ['page', 'card', 'sidebar', 'modal', 'popover'],\r\n text: ['primary', 'secondary', 'tertiary', 'disabled'],\r\n border: ['default', 'subtle', 'strong'],\r\n}\r\n\r\nfunction isRecord(value: unknown): value is Record<string, unknown> {\r\n return typeof value === 'object' && value !== null && !Array.isArray(value)\r\n}\r\n\r\nfunction isLikelyColor(value: string): boolean {\r\n const trimmed = value.trim()\r\n return (\r\n /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(trimmed) ||\r\n /^rgba?\\(.+\\)$/.test(trimmed) ||\r\n /^hsla?\\(.+\\)$/.test(trimmed) ||\r\n /^var\\(--.+\\)$/.test(trimmed) ||\r\n /^[a-zA-Z]+$/.test(trimmed)\r\n )\r\n}\r\n\r\nfunction parseSemver(version: string): [number, number, number] | null {\r\n const normalized = version.split('-')[0]\r\n const parts = normalized.split('.')\r\n if (parts.length < 3) return null\r\n\r\n const major = Number(parts[0])\r\n const minor = Number(parts[1])\r\n const patch = Number(parts[2])\r\n\r\n if (Number.isNaN(major) || Number.isNaN(minor) || Number.isNaN(patch)) {\r\n return null\r\n }\r\n\r\n return [major, minor, patch]\r\n}\r\n\r\nfunction compareSemver(a: string, b: string): number {\r\n const av = parseSemver(a)\r\n const bv = parseSemver(b)\r\n if (!av || !bv) return 0\r\n\r\n for (let i = 0; i < 3; i += 1) {\r\n if (av[i] > bv[i]) return 1\r\n if (av[i] < bv[i]) return -1\r\n }\r\n\r\n return 0\r\n}\r\n\r\nfunction assertCompatibility(minVersion: string | undefined, label: string) {\r\n if (!minVersion) return\r\n\r\n if (compareSemver(RUNTIME_THEME_REGISTRY_VERSION, minVersion) < 0) {\r\n throw new Error(\r\n `${label} requires Runtime Theme Registry >= ${minVersion}, current version is ${RUNTIME_THEME_REGISTRY_VERSION}`,\r\n )\r\n }\r\n}\r\n\r\nfunction validateMetadata(metadata: ThemeMetadata | undefined): ThemeValidationIssue[] {\r\n const issues: ThemeValidationIssue[] = []\r\n if (!metadata) return issues\r\n\r\n if (metadata.version && !parseSemver(metadata.version)) {\r\n issues.push({ path: 'theme.metadata.version', message: 'Expected semver format like 1.0.0' })\r\n }\r\n\r\n if (metadata.compatibility?.minRegistryVersion && !parseSemver(metadata.compatibility.minRegistryVersion)) {\r\n issues.push({ path: 'theme.metadata.compatibility.minRegistryVersion', message: 'Expected semver format like 1.0.0' })\r\n }\r\n\r\n return issues\r\n}\r\n\r\nexport function isThemeTokensV2(tokens: ThemeTokenSet): tokens is ThemeTokensV2 {\r\n return isRecord(tokens) && 'colors' in tokens && 'surface' in tokens && 'text' in tokens && 'border' in tokens\r\n}\r\n\r\nfunction validateLegacyTokens(tokens: Record<string, unknown>, modePath: string): ThemeValidationIssue[] {\r\n const issues: ThemeValidationIssue[] = []\r\n\r\n for (const key of LEGACY_REQUIRED_KEYS) {\r\n if (!(key in tokens)) {\r\n issues.push({ path: `${modePath}.${key}`, message: 'Missing required token' })\r\n }\r\n }\r\n\r\n for (const [key, value] of Object.entries(tokens)) {\r\n if (!LEGACY_ALLOWED_KEYS.includes(key as (typeof LEGACY_ALLOWED_KEYS)[number])) {\r\n issues.push({ path: `${modePath}.${key}`, message: 'Unknown token property' })\r\n continue\r\n }\r\n\r\n if (typeof value !== 'string' || !isLikelyColor(value)) {\r\n issues.push({ path: `${modePath}.${key}`, message: 'Invalid color value' })\r\n }\r\n }\r\n\r\n return issues\r\n}\r\n\r\nfunction validateSemanticTokens(tokens: Record<string, unknown>, modePath: string): ThemeValidationIssue[] {\r\n const issues: ThemeValidationIssue[] = []\r\n\r\n for (const category of Object.keys(SEMANTIC_SCHEMA)) {\r\n if (!(category in tokens)) {\r\n issues.push({ path: `${modePath}.${category}`, message: 'Missing required category' })\r\n continue\r\n }\r\n\r\n const categoryValue = tokens[category]\r\n if (!isRecord(categoryValue)) {\r\n issues.push({ path: `${modePath}.${category}`, message: 'Category must be an object' })\r\n continue\r\n }\r\n\r\n const requiredKeys = SEMANTIC_SCHEMA[category]\r\n for (const key of requiredKeys) {\r\n if (!(key in categoryValue)) {\r\n issues.push({ path: `${modePath}.${category}.${key}`, message: 'Missing required token' })\r\n }\r\n }\r\n\r\n for (const [key, value] of Object.entries(categoryValue)) {\r\n if (!requiredKeys.includes(key)) {\r\n issues.push({ path: `${modePath}.${category}.${key}`, message: 'Unknown token property' })\r\n continue\r\n }\r\n\r\n if (typeof value !== 'string' || !isLikelyColor(value)) {\r\n issues.push({ path: `${modePath}.${category}.${key}`, message: 'Invalid color value' })\r\n }\r\n }\r\n }\r\n\r\n for (const key of Object.keys(tokens)) {\r\n if (!(key in SEMANTIC_SCHEMA)) {\r\n issues.push({ path: `${modePath}.${key}`, message: 'Unknown category' })\r\n }\r\n }\r\n\r\n return issues\r\n}\r\n\r\nexport function validateTheme(theme: ThemeDefinition): ThemeValidationResult {\r\n const issues: ThemeValidationIssue[] = []\r\n\r\n if (!theme.name || !theme.name.trim()) {\r\n issues.push({ path: 'theme.name', message: 'Theme name is required' })\r\n }\r\n\r\n issues.push(...validateMetadata(theme.metadata))\r\n\r\n if (!isRecord(theme.modes) || Object.keys(theme.modes).length === 0) {\r\n issues.push({ path: 'theme.modes', message: 'At least one mode is required' })\r\n return { valid: issues.length === 0, issues }\r\n }\r\n\r\n for (const [modeName, tokens] of Object.entries(theme.modes)) {\r\n const modePath = `theme.modes.${modeName}`\r\n\r\n if (!isRecord(tokens)) {\r\n issues.push({ path: modePath, message: 'Mode tokens must be an object' })\r\n continue\r\n }\r\n\r\n if (isThemeTokensV2(tokens as ThemeTokenSet)) {\r\n issues.push(...validateSemanticTokens(tokens, modePath))\r\n } else {\r\n issues.push(...validateLegacyTokens(tokens, modePath))\r\n }\r\n }\r\n\r\n return {\r\n valid: issues.length === 0,\r\n issues,\r\n }\r\n}\r\n\r\nfunction mergeTokenSets(existing: ThemeTokenSet, incoming: ThemeTokenSet): ThemeTokenSet {\r\n if (isThemeTokensV2(existing) && isThemeTokensV2(incoming)) {\r\n return {\r\n colors: { ...existing.colors, ...incoming.colors },\r\n surface: { ...existing.surface, ...incoming.surface },\r\n text: { ...existing.text, ...incoming.text },\r\n border: { ...existing.border, ...incoming.border },\r\n }\r\n }\r\n\r\n return { ...existing, ...incoming }\r\n}\r\n\r\nfunction mergePlugins(existing: ThemePluginDefinition, incoming: ThemePluginDefinition): ThemePluginDefinition {\r\n return {\r\n ...existing,\r\n ...incoming,\r\n icons: { ...(existing.icons ?? {}), ...(incoming.icons ?? {}) },\r\n fonts: { ...(existing.fonts ?? {}), ...(incoming.fonts ?? {}) },\r\n spacing: { ...(existing.spacing ?? {}), ...(incoming.spacing ?? {}) },\r\n typography: { ...(existing.typography ?? {}), ...(incoming.typography ?? {}) },\r\n metadata: { ...(existing.metadata ?? {}), ...(incoming.metadata ?? {}) },\r\n }\r\n}\r\n\r\nfunction toPluginContributions(plugin: ThemePluginDefinition): ThemePluginContributions {\r\n return {\r\n icons: { ...(plugin.icons ?? {}) },\r\n fonts: { ...(plugin.fonts ?? {}) },\r\n spacing: { ...(plugin.spacing ?? {}) },\r\n typography: { ...(plugin.typography ?? {}) },\r\n metadata: { ...(plugin.metadata ?? {}) },\r\n }\r\n}\r\n\r\nfunction mergePluginContributions(\r\n target: ThemePluginContributions,\r\n source: ThemePluginContributions,\r\n): ThemePluginContributions {\r\n return {\r\n icons: { ...target.icons, ...source.icons },\r\n fonts: { ...target.fonts, ...source.fonts },\r\n spacing: { ...target.spacing, ...source.spacing },\r\n typography: { ...target.typography, ...source.typography },\r\n metadata: { ...target.metadata, ...source.metadata },\r\n }\r\n}\r\n\r\nfunction createEmptyContributions(): ThemePluginContributions {\r\n return {\r\n icons: {},\r\n fonts: {},\r\n spacing: {},\r\n typography: {},\r\n metadata: {},\r\n }\r\n}\r\n\r\nfunction createCompositionLayerMaps(): Record<ThemeCompositionLayerType, Map<string, ThemeCompositionLayerDefinition>> {\r\n return {\r\n brand: new Map(),\r\n appearance: new Map(),\r\n accessibility: new Map(),\r\n }\r\n}\r\n\r\nfunction normalizeLoadedThemes(payload: ThemeDefinition | ThemeDefinition[]): ThemeDefinition[] {\r\n return Array.isArray(payload) ? payload : [payload]\r\n}\r\n\r\nfunction tokenSetToCssVariables(tokens: ThemeTokenSet): Record<string, string> {\r\n const variables: Record<string, string> = {}\r\n\r\n if (isThemeTokensV2(tokens)) {\r\n const appendCategory = <T extends { [K in keyof T]: string }>(category: string, categoryValues: T) => {\r\n ;(Object.entries(categoryValues) as Array<[keyof T, string]>).forEach(([key, value]) => {\r\n const keyName = String(key)\r\n variables[`--theme-${category}-${keyName}`] = value\r\n if (category === 'colors') {\r\n variables[`--color-theme-${keyName}`] = value\r\n }\r\n })\r\n }\r\n\r\n appendCategory('colors', tokens.colors)\r\n appendCategory('surface', tokens.surface)\r\n appendCategory('text', tokens.text)\r\n appendCategory('border', tokens.border)\r\n\r\n return variables\r\n }\r\n\r\n Object.entries(tokens).forEach(([key, value]) => {\r\n if (key === 'tertiary' && !value) return\r\n variables[`--color-theme-${key}`] = value\r\n })\r\n\r\n return variables\r\n}\r\n\r\nfunction isCacheEntryFresh(entry: ThemeLoadCacheEntry, maxAgeMs: number | undefined): boolean {\r\n if (typeof maxAgeMs !== 'number') return true\r\n return Date.now() - entry.loadedAt <= maxAgeMs\r\n}\r\n\r\nclass ThemeRegistry {\r\n private themes: Map<string, ThemeDefinition> = new Map()\r\n private plugins: Map<string, ThemePluginDefinition> = new Map()\r\n private compositionLayers = createCompositionLayerMaps()\r\n private loadedThemeCache = new Map<string, ThemeLoadCacheEntry>()\r\n private currentTheme: string | null = null\r\n private currentMode: string | null = null\r\n private fallbackConfig: ThemeFallbackConfig = {}\r\n private listeners = new Map<ThemeRegistryEvent, Set<(payload: unknown) => void>>()\r\n\r\n getVersion() {\r\n return RUNTIME_THEME_REGISTRY_VERSION\r\n }\r\n\r\n on<K extends ThemeRegistryEvent>(event: K, handler: ThemeRegistryEventHandler<K>): () => void {\r\n const existing = this.listeners.get(event) ?? new Set<(payload: unknown) => void>()\r\n existing.add(handler as (payload: unknown) => void)\r\n this.listeners.set(event, existing)\r\n\r\n return () => {\r\n existing.delete(handler as (payload: unknown) => void)\r\n if (existing.size === 0) {\r\n this.listeners.delete(event)\r\n }\r\n }\r\n }\r\n\r\n onRegistered(handler: ThemeRegistryEventHandler<'registered'>) {\r\n return this.on('registered', handler)\r\n }\r\n\r\n onThemeChanged(handler: ThemeRegistryEventHandler<'themeChanged'>) {\r\n return this.on('themeChanged', handler)\r\n }\r\n\r\n onVariantAdded(handler: ThemeRegistryEventHandler<'variantAdded'>) {\r\n return this.on('variantAdded', handler)\r\n }\r\n\r\n onDestroyed(handler: ThemeRegistryEventHandler<'destroyed'>) {\r\n return this.on('destroyed', handler)\r\n }\r\n\r\n onLoaded(handler: ThemeRegistryEventHandler<'loaded'>) {\r\n return this.on('loaded', handler)\r\n }\r\n\r\n onComposed(handler: ThemeRegistryEventHandler<'composed'>) {\r\n return this.on('composed', handler)\r\n }\r\n\r\n private emit<K extends ThemeRegistryEvent>(event: K, payload: ThemeRegistryEventPayloadMap[K]) {\r\n const handlers = this.listeners.get(event)\r\n if (!handlers) return\r\n\r\n handlers.forEach((handler) => {\r\n ;(handler as ThemeRegistryEventHandler<K>)(payload)\r\n })\r\n }\r\n\r\n register(theme: ThemeDefinition, options: ThemeRegistrationOptions = {}) {\r\n const ifExists = options.ifExists ?? 'throw'\r\n const shouldValidate = options.validate ?? true\r\n\r\n assertCompatibility(theme.metadata?.compatibility?.minRegistryVersion, `Theme \"${theme.name}\"`)\r\n\r\n if (shouldValidate) {\r\n const validation = validateTheme(theme)\r\n if (!validation.valid) {\r\n const details = validation.issues.map((issue) => `${issue.path}: ${issue.message}`).join('\\n')\r\n throw new Error(`Theme \"${theme.name}\" failed validation:\\n${details}`)\r\n }\r\n }\r\n\r\n const exists = this.themes.has(theme.name)\r\n if (!exists) {\r\n this.themes.set(theme.name, theme)\r\n this.emit('registered', { themeName: theme.name })\r\n return\r\n }\r\n\r\n if (ifExists === 'throw') {\r\n throw new Error(`Theme \"${theme.name}\" already exists`)\r\n }\r\n\r\n if (ifExists === 'replace') {\r\n this.themes.set(theme.name, theme)\r\n this.emit('replaced', { themeName: theme.name })\r\n return\r\n }\r\n\r\n const existing = this.themes.get(theme.name)\r\n if (!existing) {\r\n this.themes.set(theme.name, theme)\r\n this.emit('registered', { themeName: theme.name })\r\n return\r\n }\r\n\r\n const mergedModes: Record<string, ThemeTokenSet> = { ...existing.modes }\r\n for (const [modeName, tokens] of Object.entries(theme.modes)) {\r\n if (mergedModes[modeName]) {\r\n mergedModes[modeName] = mergeTokenSets(mergedModes[modeName], tokens)\r\n } else {\r\n mergedModes[modeName] = tokens\r\n }\r\n }\r\n\r\n this.themes.set(theme.name, {\r\n ...existing,\r\n ...theme,\r\n metadata: { ...(existing.metadata ?? {}), ...(theme.metadata ?? {}) },\r\n modes: mergedModes,\r\n })\r\n\r\n this.emit('merged', { themeName: theme.name })\r\n }\r\n\r\n replace(themeName: string, theme: ThemeDefinition) {\r\n if (themeName !== theme.name) {\r\n throw new Error('replace() requires matching themeName and theme.name')\r\n }\r\n this.register(theme, { ifExists: 'replace' })\r\n }\r\n\r\n merge(themeName: string, theme: ThemeDefinition) {\r\n if (themeName !== theme.name) {\r\n throw new Error('merge() requires matching themeName and theme.name')\r\n }\r\n this.register(theme, { ifExists: 'merge' })\r\n }\r\n\r\n unregister(themeName: string): boolean {\r\n const removed = this.themes.delete(themeName)\r\n if (removed) {\r\n this.emit('unregistered', { themeName })\r\n }\r\n\r\n if (removed && this.currentTheme === themeName) {\r\n this.currentTheme = null\r\n this.currentMode = null\r\n }\r\n\r\n return removed\r\n }\r\n\r\n setFallback(config: ThemeFallbackConfig) {\r\n this.fallbackConfig = { ...this.fallbackConfig, ...config }\r\n }\r\n\r\n registerPlugin(plugin: ThemePluginDefinition, options: PluginRegistrationOptions = {}) {\r\n const ifExists = options.ifExists ?? 'throw'\r\n const themeIfExists = options.themeIfExists ?? 'merge'\r\n const validateThemes = options.validateThemes ?? true\r\n\r\n assertCompatibility(plugin.minRegistryVersion, `Plugin \"${plugin.name}\"`)\r\n\r\n const exists = this.plugins.has(plugin.name)\r\n if (exists && ifExists === 'throw') {\r\n throw new Error(`Plugin \"${plugin.name}\" already exists`)\r\n }\r\n\r\n let pluginToStore = plugin\r\n if (exists && ifExists === 'merge') {\r\n const existing = this.plugins.get(plugin.name)\r\n if (existing) {\r\n pluginToStore = mergePlugins(existing, plugin)\r\n }\r\n }\r\n\r\n this.plugins.set(plugin.name, pluginToStore)\r\n\r\n const pluginThemes: ThemeDefinition[] = [\r\n ...(pluginToStore.theme ? [pluginToStore.theme] : []),\r\n ...(pluginToStore.themes ?? []),\r\n ]\r\n\r\n for (const theme of pluginThemes) {\r\n this.register(theme, { ifExists: themeIfExists, validate: validateThemes })\r\n }\r\n\r\n this.emit('pluginRegistered', { pluginName: plugin.name })\r\n }\r\n\r\n registerCompositionLayer(layer: ThemeCompositionLayerDefinition, options: ThemeRegistrationOptions = {}) {\r\n const targetMap = this.compositionLayers[layer.type]\r\n const ifExists = options.ifExists ?? 'throw'\r\n\r\n const exists = targetMap.has(layer.name)\r\n if (exists && ifExists === 'throw') {\r\n throw new Error(`Composition layer \"${layer.type}:${layer.name}\" already exists`)\r\n }\r\n\r\n if (exists && ifExists === 'merge') {\r\n const existing = targetMap.get(layer.name)\r\n if (existing) {\r\n targetMap.set(layer.name, {\r\n ...existing,\r\n ...layer,\r\n metadata: { ...(existing.metadata ?? {}), ...(layer.metadata ?? {}) },\r\n tokens: mergeTokenSets(existing.tokens, layer.tokens),\r\n })\r\n return\r\n }\r\n }\r\n\r\n targetMap.set(layer.name, layer)\r\n }\r\n\r\n getCompositionLayer(type: ThemeCompositionLayerType, name: string): ThemeCompositionLayerDefinition | undefined {\r\n return this.compositionLayers[type].get(name)\r\n }\r\n\r\n getCompositionLayers(type?: ThemeCompositionLayerType): ThemeCompositionLayerDefinition[] {\r\n if (type) {\r\n return Array.from(this.compositionLayers[type].values())\r\n }\r\n\r\n return [\r\n ...Array.from(this.compositionLayers.brand.values()),\r\n ...Array.from(this.compositionLayers.appearance.values()),\r\n ...Array.from(this.compositionLayers.accessibility.values()),\r\n ]\r\n }\r\n\r\n compose(selection: ThemeCompositionSelection): ThemeCompositionResult {\r\n const appliedLayers: ThemeCompositionLayerDefinition[] = []\r\n let composedTokens: ThemeTokenSet | null = null\r\n\r\n const resolutionOrder: Array<[ThemeCompositionLayerType, string | null | undefined]> = [\r\n ['brand', selection.brand],\r\n ['appearance', selection.appearance],\r\n ['accessibility', selection.accessibility],\r\n ]\r\n\r\n resolutionOrder.forEach(([type, layerName]) => {\r\n if (!layerName) return\r\n const layer = this.compositionLayers[type].get(layerName)\r\n if (!layer) return\r\n\r\n appliedLayers.push(layer)\r\n composedTokens = composedTokens ? mergeTokenSets(composedTokens, layer.tokens) : layer.tokens\r\n })\r\n\r\n this.emit('composed', {\r\n appliedLayers: appliedLayers.map((layer) => `${layer.type}:${layer.name}`),\r\n })\r\n\r\n return {\r\n selection,\r\n tokens: composedTokens,\r\n appliedLayers,\r\n }\r\n }\r\n\r\n getInitialThemeAttributes(themeName: string | null, modeName: string | null): ThemeDocumentAttributes | null {\r\n const resolved = this.resolveSelection(themeName, modeName)\r\n if (!resolved.themeName || !resolved.modeName) return null\r\n\r\n return {\r\n 'data-theme': resolved.themeName,\r\n 'data-mode': resolved.modeName,\r\n }\r\n }\r\n\r\n hydrateThemeOnDocument(themeName: string | null, modeName: string | null): ThemeResolutionResult {\r\n const resolved = this.resolveSelection(themeName, modeName)\r\n if (!resolved.themeName || !resolved.modeName || !resolved.tokens) {\r\n return resolved\r\n }\r\n\r\n if (typeof document !== 'undefined') {\r\n document.documentElement.setAttribute('data-theme', resolved.themeName)\r\n document.documentElement.setAttribute('data-mode', resolved.modeName)\r\n\r\n const cssVariables = tokenSetToCssVariables(resolved.tokens)\r\n Object.entries(cssVariables).forEach(([name, value]) => {\r\n document.documentElement.style.setProperty(name, value)\r\n })\r\n }\r\n\r\n this.currentTheme = resolved.themeName\r\n this.currentMode = resolved.modeName\r\n this.emit('themeChanged', { themeName: resolved.themeName, modeName: resolved.modeName })\r\n\r\n return resolved\r\n }\r\n\r\n async load(source: ThemeLoadSource, options: ThemeLoadOptions = {}): Promise<ThemeLoadResult> {\r\n const ifExists = options.ifExists ?? 'merge'\r\n const validate = options.validate ?? true\r\n const cacheKey = options.cacheKey ?? (typeof source === 'string' ? source : undefined)\r\n const forceRefresh = options.forceRefresh ?? false\r\n const maxAgeMs = options.maxAgeMs\r\n\r\n if (cacheKey && !forceRefresh && this.loadedThemeCache.has(cacheKey)) {\r\n const entry = this.loadedThemeCache.get(cacheKey)\r\n if (entry && isCacheEntryFresh(entry, maxAgeMs)) {\r\n const names = entry.themes.map((theme) => theme.name)\r\n\r\n this.emit('loaded', {\r\n source: entry.source,\r\n count: names.length,\r\n fromCache: true,\r\n })\r\n\r\n return {\r\n loaded: names.length,\r\n themes: names,\r\n source: entry.source,\r\n fromCache: true,\r\n }\r\n }\r\n }\r\n\r\n let loadedThemes: ThemeDefinition[] = []\r\n if (typeof source === 'string') {\r\n const response = await fetch(source)\r\n if (!response.ok) {\r\n throw new Error(`Failed to load themes from ${source}: ${response.status} ${response.statusText}`)\r\n }\r\n const payload = (await response.json()) as ThemeDefinition | ThemeDefinition[]\r\n loadedThemes = normalizeLoadedThemes(payload)\r\n } else {\r\n const payload = await source()\r\n loadedThemes = normalizeLoadedThemes(payload)\r\n }\r\n\r\n const names: string[] = []\r\n loadedThemes.forEach((theme) => {\r\n this.register(theme, { ifExists, validate })\r\n names.push(theme.name)\r\n })\r\n\r\n const sourceName = typeof source === 'string' ? source : 'loader'\r\n if (cacheKey) {\r\n this.loadedThemeCache.set(cacheKey, {\r\n themes: loadedThemes,\r\n loadedAt: Date.now(),\r\n source: sourceName,\r\n })\r\n }\r\n\r\n this.emit('loaded', {\r\n source: sourceName,\r\n count: names.length,\r\n fromCache: false,\r\n })\r\n\r\n return {\r\n loaded: names.length,\r\n themes: names,\r\n source: sourceName,\r\n fromCache: false,\r\n }\r\n }\r\n\r\n clearLoadCache(cacheKey?: string) {\r\n if (cacheKey) {\r\n this.loadedThemeCache.delete(cacheKey)\r\n return\r\n }\r\n\r\n this.loadedThemeCache.clear()\r\n }\r\n\r\n unregisterPlugin(pluginName: string): boolean {\r\n const removed = this.plugins.delete(pluginName)\r\n if (removed) {\r\n this.emit('pluginUnregistered', { pluginName })\r\n }\r\n return removed\r\n }\r\n\r\n getPlugin(name: string): ThemePluginDefinition | undefined {\r\n return this.plugins.get(name)\r\n }\r\n\r\n getPlugins(): ThemePluginDefinition[] {\r\n return Array.from(this.plugins.values())\r\n }\r\n\r\n getPluginContributions(pluginName: string): ThemePluginContributions | undefined {\r\n const plugin = this.plugins.get(pluginName)\r\n if (!plugin) return undefined\r\n return toPluginContributions(plugin)\r\n }\r\n\r\n getMergedPluginContributions(): ThemePluginContributions {\r\n let merged = createEmptyContributions()\r\n\r\n this.plugins.forEach((plugin) => {\r\n merged = mergePluginContributions(merged, toPluginContributions(plugin))\r\n })\r\n\r\n return merged\r\n }\r\n\r\n /**\r\n * Dynamically register a theme mode - useful for packages to add their own modes\r\n * @param themeName - The name of the existing theme to add the mode to\r\n * @param modeName - The name of the mode (e.g., 'ocean', 'forest', 'high-contrast')\r\n * @param tokens - The tokens for this mode\r\n */\r\n registerMode(themeName: string, modeName: string, tokens: ThemeTokenSet) {\r\n const theme = this.themes.get(themeName)\r\n if (!theme) {\r\n throw new Error(`Theme \"${themeName}\" not found. Register the theme first with themeRegistry.register(theme)`)\r\n }\r\n\r\n theme.modes[modeName] = tokens\r\n const validation = validateTheme(theme)\r\n if (!validation.valid) {\r\n delete theme.modes[modeName]\r\n const details = validation.issues.map((issue) => `${issue.path}: ${issue.message}`).join('\\n')\r\n throw new Error(`Invalid mode \"${modeName}\" for theme \"${themeName}\":\\n${details}`)\r\n }\r\n\r\n this.emit('variantAdded', { themeName, variantName: modeName })\r\n }\r\n\r\n /**\r\n * Register multiple modes at once for a theme\r\n */\r\n registerModes(themeName: string, modes: Record<string, ThemeTokenSet>) {\r\n const theme = this.themes.get(themeName)\r\n if (!theme) {\r\n throw new Error(`Theme \"${themeName}\" not found. Register the theme first with themeRegistry.register(theme)`)\r\n }\r\n\r\n const originalModes = { ...theme.modes }\r\n Object.assign(theme.modes, modes)\r\n\r\n const validation = validateTheme(theme)\r\n if (!validation.valid) {\r\n theme.modes = originalModes\r\n const details = validation.issues.map((issue) => `${issue.path}: ${issue.message}`).join('\\n')\r\n throw new Error(`Invalid modes for theme \"${themeName}\":\\n${details}`)\r\n }\r\n\r\n Object.keys(modes).forEach((modeName) => {\r\n this.emit('variantAdded', { themeName, variantName: modeName })\r\n })\r\n }\r\n\r\n /**\r\n * Create and register a new theme with specific modes\r\n * Useful for packages that want to add their own themes dynamically\r\n */\r\n createTheme(name: string, modes: Record<string, ThemeTokenSet>) {\r\n const theme: ThemeDefinition = { name, modes }\r\n this.register(theme)\r\n }\r\n\r\n private getFallbackThemeName(): string | null {\r\n if (this.fallbackConfig.themeName && this.themes.has(this.fallbackConfig.themeName)) {\r\n return this.fallbackConfig.themeName\r\n }\r\n\r\n const firstTheme = this.themes.keys().next().value\r\n return firstTheme ?? null\r\n }\r\n\r\n private resolveModeName(theme: ThemeDefinition, requestedMode: string | null | undefined): string | null {\r\n if (requestedMode && theme.modes[requestedMode]) {\r\n return requestedMode\r\n }\r\n\r\n if (this.fallbackConfig.modeName && theme.modes[this.fallbackConfig.modeName]) {\r\n return this.fallbackConfig.modeName\r\n }\r\n\r\n const firstMode = Object.keys(theme.modes)[0]\r\n return firstMode ?? null\r\n }\r\n\r\n resolveSelection(themeName: string | null, modeName: string | null): ThemeResolutionResult {\r\n const effectiveThemeName = themeName && this.themes.has(themeName) ? themeName : this.getFallbackThemeName()\r\n if (!effectiveThemeName) {\r\n return { themeName: null, modeName: null, tokens: null }\r\n }\r\n\r\n const theme = this.themes.get(effectiveThemeName)\r\n if (!theme) {\r\n return { themeName: null, modeName: null, tokens: null }\r\n }\r\n\r\n const effectiveModeName = this.resolveModeName(theme, modeName)\r\n if (!effectiveModeName) {\r\n return { themeName: theme.name, modeName: null, tokens: null }\r\n }\r\n\r\n return {\r\n themeName: theme.name,\r\n modeName: effectiveModeName,\r\n tokens: theme.modes[effectiveModeName] ?? null,\r\n }\r\n }\r\n\r\n get(name: string): ThemeDefinition | undefined {\r\n return this.themes.get(name)\r\n }\r\n\r\n getAll(): ThemeDefinition[] {\r\n return Array.from(this.themes.values())\r\n }\r\n\r\n getTokens(themeName: string, modeName: string): ThemeTokenSet | undefined {\r\n const theme = this.themes.get(themeName)\r\n return theme?.modes[modeName]\r\n }\r\n\r\n setCurrent(themeName: string, modeName: string) {\r\n const resolved = this.resolveSelection(themeName, modeName)\r\n if (!resolved.themeName || !resolved.modeName) {\r\n throw new Error(`No valid theme selection for \"${themeName}\" and mode \"${modeName}\"`)\r\n }\r\n\r\n this.currentTheme = resolved.themeName\r\n this.currentMode = resolved.modeName\r\n this.emit('themeChanged', { themeName: resolved.themeName, modeName: resolved.modeName })\r\n }\r\n\r\n getCurrent() {\r\n return {\r\n theme: this.currentTheme,\r\n mode: this.currentMode,\r\n }\r\n }\r\n\r\n has(themeName: string): boolean {\r\n return this.themes.has(themeName)\r\n }\r\n\r\n getModes(themeName: string): string[] {\r\n const theme = this.themes.get(themeName)\r\n return theme ? Object.keys(theme.modes) : []\r\n }\r\n\r\n getVariants(themeName: string): string[] {\r\n return this.getModes(themeName)\r\n }\r\n\r\n destroy() {\r\n this.themes.clear()\r\n this.plugins.clear()\r\n this.compositionLayers = createCompositionLayerMaps()\r\n this.loadedThemeCache.clear()\r\n this.currentTheme = null\r\n this.currentMode = null\r\n this.fallbackConfig = {}\r\n this.emit('destroyed', { timestamp: new Date().toISOString() })\r\n this.listeners.clear()\r\n }\r\n}\r\n\r\nexport const themeRegistry = new ThemeRegistry()\r\n","import { themeRegistry } from './theme-registry'\r\nimport type { ThemePalette } from './theme-registry'\r\n\r\nconst fnpTheme: { name: string; modes: Record<string, ThemePalette> } = {\r\n name: 'fnp',\r\n modes: {\r\n light: {\r\n primary: '#031011',\r\n secondary: '#153e46',\r\n tertiary: '#378d93',\r\n background: '#ffffff',\r\n text: '#031011',\r\n accent: '#378d93',\r\n muted: '#667085',\r\n error: '#DF1C41',\r\n warning: '#F4C790',\r\n success: '#27AE60',\r\n info: '#378d93',\r\n },\r\n dark: {\r\n primary: '#c4e8ee',\r\n secondary: '#378d93',\r\n tertiary: '#153e46',\r\n background: '#031011',\r\n text: '#c4e8ee',\r\n accent: '#378d93',\r\n muted: '#667085',\r\n error: '#DF1C41',\r\n warning: '#F4C790',\r\n success: '#27AE60',\r\n info: '#378d93',\r\n },\r\n },\r\n}\r\n\r\n// Register theme on module load - this is your \"package-like\" registration\r\nthemeRegistry.register(fnpTheme)\r\n\r\nexport { themeRegistry }","export { ThemeProvider, useTheme } from './theme-provider'\r\nexport {\r\n\tthemeRegistry,\r\n\tRUNTIME_THEME_REGISTRY_VERSION,\r\n\tvalidateTheme,\r\n\tisThemeTokensV2,\r\n\ttype ThemeDefinition,\r\n\ttype ThemePalette,\r\n\ttype ThemeTokensV2,\r\n\ttype ThemeTokenSet,\r\n\ttype ThemeMetadata,\r\n\ttype ThemeCompatibility,\r\n\ttype ThemeValidationIssue,\r\n\ttype ThemeValidationResult,\r\n\ttype ThemeRegistrationOptions,\r\n\ttype ThemeRegistrationConflict,\r\n\ttype ThemeFallbackConfig,\r\n\ttype ThemeResolutionResult,\r\n\ttype ThemePluginDefinition,\r\n\ttype ThemePluginContributions,\r\n\ttype PluginRegistrationOptions,\r\n\ttype PluginRegistrationConflict,\r\n\ttype ThemeCompositionLayerType,\r\n\ttype ThemeCompositionLayerDefinition,\r\n\ttype ThemeCompositionSelection,\r\n\ttype ThemeCompositionResult,\r\n\ttype ThemeLoadSource,\r\n\ttype ThemeLoadOptions,\r\n\ttype ThemeLoadResult,\r\n\ttype ThemeLoadCacheEntry,\r\n\ttype ThemeDocumentAttributes,\r\n\ttype ThemeRegistryEvent,\r\n\ttype ThemeRegistryEventPayloadMap,\r\n\ttype ThemeRegistryEventHandler,\r\n} from './theme-registry'\r\nexport {\r\n\tpaletteToCSSVariables,\r\n\ttokenSetToCSSVariables,\r\n\tgenerateThemeCSS,\r\n\tgenerateAllThemesCSS,\r\n\tapplyThemeToDocument,\r\n} from './theme-utils'\r\nexport { themeRegistry as default } from './theme-registry'\r\n\r\n// Export types for package authors\r\nexport type { ThemePalette as ColorModePalette } from './theme-registry'\r\n","'use client'\r\n\r\nimport React, { createContext, useContext, useEffect, useState, useCallback } from 'react'\r\nimport { themeRegistry } from './theme-registry'\r\nimport type { ThemeDefinition, ThemeTokenSet } from './theme-registry'\r\nimport { tokenSetToCSSVariables } from './theme-utils'\r\nimport './app_theme'\r\n\r\ninterface ThemeContextType {\r\n currentTheme: string | null\r\n currentMode: string | null\r\n themes: ThemeDefinition[]\r\n setTheme: (themeName: string, mode: string) => void\r\n setMode: (mode: string) => void\r\n availableModes: string[]\r\n getThemeColors: () => ThemeTokenSet | null\r\n}\r\n\r\nconst ThemeContext = createContext<ThemeContextType | undefined>(undefined)\r\n\r\nexport function ThemeProvider({ children }: { children: React.ReactNode }) {\r\n const [currentTheme, setCurrentTheme] = useState<string | null>(null)\r\n const [currentMode, setCurrentMode] = useState<string | null>(null)\r\n const [themes, setThemes] = useState<ThemeDefinition[]>([])\r\n\r\n useEffect(() => {\r\n // Initialize themes from registry\r\n const registeredThemes = themeRegistry.getAll()\r\n \r\n // If no themes are registered, try to dynamically import app_theme\r\n if (registeredThemes.length === 0) {\r\n import('./app_theme').then(() => {\r\n setThemes(themeRegistry.getAll())\r\n })\r\n } else {\r\n setThemes(registeredThemes)\r\n }\r\n\r\n if (registeredThemes.length > 0) {\r\n // Try to load from localStorage\r\n const saved = localStorage.getItem('fnp-theme') as string | null\r\n const savedMode = localStorage.getItem('fnp-mode') as string | null\r\n\r\n const resolved = themeRegistry.resolveSelection(saved, savedMode)\r\n if (!resolved.themeName || !resolved.modeName || !resolved.tokens) return\r\n\r\n setCurrentTheme(resolved.themeName)\r\n setCurrentMode(resolved.modeName)\r\n themeRegistry.setCurrent(resolved.themeName, resolved.modeName)\r\n applyTheme(resolved.tokens)\r\n\r\n localStorage.setItem('fnp-theme', resolved.themeName)\r\n localStorage.setItem('fnp-mode', resolved.modeName)\r\n }\r\n }, [])\r\n\r\n const applyTheme = useCallback((tokens: ThemeTokenSet) => {\r\n const root = document.documentElement\r\n const variables = tokenSetToCSSVariables(tokens)\r\n Object.entries(variables).forEach(([name, value]) => {\r\n root.style.setProperty(name, value)\r\n })\r\n }, [])\r\n\r\n const setTheme = useCallback((themeName: string, mode: string) => {\r\n const resolved = themeRegistry.resolveSelection(themeName, mode)\r\n if (!resolved.themeName || !resolved.modeName || !resolved.tokens) return\r\n\r\n setCurrentTheme(resolved.themeName)\r\n setCurrentMode(resolved.modeName)\r\n themeRegistry.setCurrent(resolved.themeName, resolved.modeName)\r\n applyTheme(resolved.tokens)\r\n\r\n localStorage.setItem('fnp-theme', resolved.themeName)\r\n localStorage.setItem('fnp-mode', resolved.modeName)\r\n }, [applyTheme])\r\n\r\n const setMode = useCallback((mode: string) => {\r\n if (!currentTheme) return\r\n setTheme(currentTheme, mode)\r\n }, [currentTheme, setTheme])\r\n\r\n const getThemeColors = useCallback(() => {\r\n if (!currentTheme || !currentMode) return null\r\n return themeRegistry.getTokens(currentTheme, currentMode) ?? null\r\n }, [currentTheme, currentMode])\r\n\r\n const availableModes = currentTheme ? themeRegistry.getModes(currentTheme) : []\r\n\r\n return (\r\n <ThemeContext.Provider\r\n value={{\r\n currentTheme,\r\n currentMode,\r\n themes,\r\n setTheme,\r\n setMode,\r\n availableModes,\r\n getThemeColors,\r\n }}\r\n >\r\n {children}\r\n </ThemeContext.Provider>\r\n )\r\n}\r\n\r\nexport function useTheme() {\r\n const context = useContext(ThemeContext)\r\n if (context === undefined) {\r\n throw new Error('useTheme must be used within a ThemeProvider')\r\n }\r\n return context\r\n}","import type { ThemePalette, ThemeDefinition, ThemeTokenSet, ThemeTokensV2 } from './theme-registry'\r\nimport { isThemeTokensV2 } from './theme-registry'\r\n\r\nexport function paletteToCSSVariables(palette: ThemePalette): Record<string, string> {\r\n return tokenSetToCSSVariables(palette)\r\n}\r\n\r\nfunction semanticTokensToCSSVariables(tokens: ThemeTokensV2): Record<string, string> {\r\n const variables: Record<string, string> = {}\r\n\r\n const appendCategory = <T extends { [K in keyof T]: string }>(category: string, categoryValues: T) => {\r\n ;(Object.entries(categoryValues) as Array<[keyof T, string]>).forEach(([key, value]) => {\r\n const keyName = String(key)\r\n variables[`--theme-${category}-${keyName}`] = value\r\n\r\n // Keep color alias vars for easy migration from legacy palettes.\r\n if (category === 'colors') {\r\n variables[`--color-theme-${keyName}`] = value\r\n }\r\n })\r\n }\r\n\r\n appendCategory('colors', tokens.colors)\r\n appendCategory('surface', tokens.surface)\r\n appendCategory('text', tokens.text)\r\n appendCategory('border', tokens.border)\r\n\r\n return variables\r\n}\r\n\r\nfunction legacyTokensToCSSVariables(tokens: ThemePalette): Record<string, string> {\r\n const variables: Record<string, string> = {}\r\n\r\n ;(Object.entries(tokens) as Array<[keyof ThemePalette, string | undefined]>).forEach(([key, value]) => {\r\n if (key === 'tertiary' && !value) return\r\n if (!value) return\r\n variables[`--color-theme-${String(key)}`] = value\r\n })\r\n\r\n return variables\r\n}\r\n\r\nexport function tokenSetToCSSVariables(tokens: ThemeTokenSet): Record<string, string> {\r\n if (isThemeTokensV2(tokens)) {\r\n return semanticTokensToCSSVariables(tokens)\r\n }\r\n\r\n return legacyTokensToCSSVariables(tokens)\r\n}\r\n\r\nexport function generateThemeCSS(theme: ThemeDefinition): string {\r\n const modes = Object.entries(theme.modes)\r\n \r\n let css = `/* Theme: ${theme.name} */\\n`\r\n \r\n modes.forEach(([modeName, tokens]) => {\r\n css += `\\n[data-theme=\"${theme.name}\"][data-mode=\"${modeName}\"] {\\n`\r\n\r\n const variables = tokenSetToCSSVariables(tokens)\r\n Object.entries(variables).forEach(([name, value]) => {\r\n css += ` ${name}: ${value};\\n`\r\n })\r\n\r\n css += `}\\n`\r\n })\r\n\r\n return css\r\n}\r\n\r\nexport function generateAllThemesCSS(themes: ThemeDefinition[]): string {\r\n return themes.map(generateThemeCSS).join('\\n')\r\n}\r\n\r\nexport function applyThemeToDocument(theme: ThemeDefinition, mode: string) {\r\n const tokens = theme.modes[mode]\r\n if (!tokens) return\r\n\r\n document.documentElement.setAttribute('data-theme', theme.name)\r\n document.documentElement.setAttribute('data-mode', mode)\r\n\r\n const variables = tokenSetToCSSVariables(tokens)\r\n Object.entries(variables).forEach(([name, value]) => {\r\n document.documentElement.style.setProperty(name, value)\r\n })\r\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAmNA,SAAS,SAAS,OAAkD;AAClE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,cAAc,OAAwB;AAC7C,QAAM,UAAU,MAAM,KAAK;AAC3B,SACE,oDAAoD,KAAK,OAAO,KAChE,gBAAgB,KAAK,OAAO,KAC5B,gBAAgB,KAAK,OAAO,KAC5B,gBAAgB,KAAK,OAAO,KAC5B,cAAc,KAAK,OAAO;AAE9B;AAEA,SAAS,YAAY,SAAkD;AACrE,QAAM,aAAa,QAAQ,MAAM,GAAG,EAAE,CAAC;AACvC,QAAM,QAAQ,WAAW,MAAM,GAAG;AAClC,MAAI,MAAM,SAAS,EAAG,QAAO;AAE7B,QAAM,QAAQ,OAAO,MAAM,CAAC,CAAC;AAC7B,QAAM,QAAQ,OAAO,MAAM,CAAC,CAAC;AAC7B,QAAM,QAAQ,OAAO,MAAM,CAAC,CAAC;AAE7B,MAAI,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM,KAAK,KAAK,OAAO,MAAM,KAAK,GAAG;AACrE,WAAO;AAAA,EACT;AAEA,S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AAC,SAAiB;AAC5C,QAAI,CAAC,aAAc;AACnB,aAAS,cAAc,IAAI;AAAA,EAC7B,GAAG,CAAC,cAAc,QAAQ,CAAC;AAE3B,QAAM,qBAAiB,0BAAY,MAAM;AACvC,QAAI,CAAC,gBAAgB,CAAC,YAAa,QAAO;AAC1C,WAAO,cAAc,UAAU,cAAc,WAAW,KAAK;AAAA,EAC/D,GAAG,CAAC,cAAc,WAAW,CAAC;AAE9B,QAAM,iBAAiB,eAAe,cAAc,SAAS,YAAY,IAAI,CAAC;AAE9E,SACE;AAAA,IAAC,aAAa;AAAA,IAAb;AAAA,MACC,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MAEC;AAAA;AAAA,EACH;AAEJ;AAEO,SAAS,WAAW;AACzB,QAAM,cAAU,yBAAW,YAAY;AACvC,MAAI,YAAY,QAAW;AACzB,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;;;AD/GA;AAyCA;","names":["names"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
declare const RUNTIME_THEME_REGISTRY_VERSION = "0.2.0";
|
|
4
|
+
interface ThemePalette {
|
|
5
|
+
primary: string;
|
|
6
|
+
secondary: string;
|
|
7
|
+
tertiary?: string;
|
|
8
|
+
background: string;
|
|
9
|
+
text: string;
|
|
10
|
+
accent: string;
|
|
11
|
+
muted: string;
|
|
12
|
+
error: string;
|
|
13
|
+
warning: string;
|
|
14
|
+
success: string;
|
|
15
|
+
info: string;
|
|
16
|
+
}
|
|
17
|
+
interface SemanticColorTokens {
|
|
18
|
+
primary: string;
|
|
19
|
+
secondary: string;
|
|
20
|
+
destructive: string;
|
|
21
|
+
success: string;
|
|
22
|
+
warning: string;
|
|
23
|
+
info: string;
|
|
24
|
+
}
|
|
25
|
+
interface SemanticSurfaceTokens {
|
|
26
|
+
page: string;
|
|
27
|
+
card: string;
|
|
28
|
+
sidebar: string;
|
|
29
|
+
modal: string;
|
|
30
|
+
popover: string;
|
|
31
|
+
}
|
|
32
|
+
interface SemanticTextTokens {
|
|
33
|
+
primary: string;
|
|
34
|
+
secondary: string;
|
|
35
|
+
tertiary: string;
|
|
36
|
+
disabled: string;
|
|
37
|
+
}
|
|
38
|
+
interface SemanticBorderTokens {
|
|
39
|
+
default: string;
|
|
40
|
+
subtle: string;
|
|
41
|
+
strong: string;
|
|
42
|
+
}
|
|
43
|
+
interface ThemeTokensV2 {
|
|
44
|
+
colors: SemanticColorTokens;
|
|
45
|
+
surface: SemanticSurfaceTokens;
|
|
46
|
+
text: SemanticTextTokens;
|
|
47
|
+
border: SemanticBorderTokens;
|
|
48
|
+
}
|
|
49
|
+
type ThemeTokenSet = ThemePalette | ThemeTokensV2;
|
|
50
|
+
interface ThemeCompatibility {
|
|
51
|
+
minRegistryVersion?: string;
|
|
52
|
+
}
|
|
53
|
+
interface ThemeMetadata {
|
|
54
|
+
author?: string;
|
|
55
|
+
version?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
homepage?: string;
|
|
58
|
+
license?: string;
|
|
59
|
+
compatibility?: ThemeCompatibility;
|
|
60
|
+
}
|
|
61
|
+
interface ThemeDefinition {
|
|
62
|
+
name: string;
|
|
63
|
+
modes: Record<string, ThemeTokenSet>;
|
|
64
|
+
metadata?: ThemeMetadata;
|
|
65
|
+
}
|
|
66
|
+
type ThemeRegistrationConflict = 'throw' | 'replace' | 'merge';
|
|
67
|
+
interface ThemeRegistrationOptions {
|
|
68
|
+
ifExists?: ThemeRegistrationConflict;
|
|
69
|
+
validate?: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface ThemeFallbackConfig {
|
|
72
|
+
themeName?: string;
|
|
73
|
+
modeName?: string;
|
|
74
|
+
}
|
|
75
|
+
interface ThemeValidationIssue {
|
|
76
|
+
path: string;
|
|
77
|
+
message: string;
|
|
78
|
+
}
|
|
79
|
+
interface ThemeValidationResult {
|
|
80
|
+
valid: boolean;
|
|
81
|
+
issues: ThemeValidationIssue[];
|
|
82
|
+
}
|
|
83
|
+
interface ThemeResolutionResult {
|
|
84
|
+
themeName: string | null;
|
|
85
|
+
modeName: string | null;
|
|
86
|
+
tokens: ThemeTokenSet | null;
|
|
87
|
+
}
|
|
88
|
+
interface ThemePluginDefinition {
|
|
89
|
+
name: string;
|
|
90
|
+
version?: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
author?: string;
|
|
93
|
+
homepage?: string;
|
|
94
|
+
license?: string;
|
|
95
|
+
minRegistryVersion?: string;
|
|
96
|
+
theme?: ThemeDefinition;
|
|
97
|
+
themes?: ThemeDefinition[];
|
|
98
|
+
icons?: Record<string, string>;
|
|
99
|
+
fonts?: Record<string, string>;
|
|
100
|
+
spacing?: Record<string, string | number>;
|
|
101
|
+
typography?: Record<string, string | number>;
|
|
102
|
+
metadata?: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
interface ThemePluginContributions {
|
|
105
|
+
icons: Record<string, string>;
|
|
106
|
+
fonts: Record<string, string>;
|
|
107
|
+
spacing: Record<string, string | number>;
|
|
108
|
+
typography: Record<string, string | number>;
|
|
109
|
+
metadata: Record<string, unknown>;
|
|
110
|
+
}
|
|
111
|
+
type ThemeCompositionLayerType = 'brand' | 'appearance' | 'accessibility';
|
|
112
|
+
interface ThemeCompositionLayerDefinition {
|
|
113
|
+
type: ThemeCompositionLayerType;
|
|
114
|
+
name: string;
|
|
115
|
+
tokens: ThemeTokenSet;
|
|
116
|
+
metadata?: Record<string, unknown>;
|
|
117
|
+
}
|
|
118
|
+
interface ThemeCompositionSelection {
|
|
119
|
+
brand?: string | null;
|
|
120
|
+
appearance?: string | null;
|
|
121
|
+
accessibility?: string | null;
|
|
122
|
+
}
|
|
123
|
+
interface ThemeCompositionResult {
|
|
124
|
+
selection: ThemeCompositionSelection;
|
|
125
|
+
tokens: ThemeTokenSet | null;
|
|
126
|
+
appliedLayers: ThemeCompositionLayerDefinition[];
|
|
127
|
+
}
|
|
128
|
+
type ThemeLoadSource = string | (() => Promise<ThemeDefinition | ThemeDefinition[]>);
|
|
129
|
+
interface ThemeLoadOptions {
|
|
130
|
+
ifExists?: ThemeRegistrationConflict;
|
|
131
|
+
validate?: boolean;
|
|
132
|
+
cacheKey?: string;
|
|
133
|
+
maxAgeMs?: number;
|
|
134
|
+
forceRefresh?: boolean;
|
|
135
|
+
}
|
|
136
|
+
interface ThemeLoadResult {
|
|
137
|
+
loaded: number;
|
|
138
|
+
themes: string[];
|
|
139
|
+
source: string;
|
|
140
|
+
fromCache: boolean;
|
|
141
|
+
}
|
|
142
|
+
interface ThemeLoadCacheEntry {
|
|
143
|
+
themes: ThemeDefinition[];
|
|
144
|
+
loadedAt: number;
|
|
145
|
+
source: string;
|
|
146
|
+
}
|
|
147
|
+
interface ThemeDocumentAttributes {
|
|
148
|
+
'data-theme': string;
|
|
149
|
+
'data-mode': string;
|
|
150
|
+
}
|
|
151
|
+
type PluginRegistrationConflict = 'throw' | 'replace' | 'merge';
|
|
152
|
+
interface PluginRegistrationOptions {
|
|
153
|
+
ifExists?: PluginRegistrationConflict;
|
|
154
|
+
themeIfExists?: ThemeRegistrationConflict;
|
|
155
|
+
validateThemes?: boolean;
|
|
156
|
+
}
|
|
157
|
+
interface ThemeRegistryEventPayloadMap {
|
|
158
|
+
registered: {
|
|
159
|
+
themeName: string;
|
|
160
|
+
};
|
|
161
|
+
replaced: {
|
|
162
|
+
themeName: string;
|
|
163
|
+
};
|
|
164
|
+
merged: {
|
|
165
|
+
themeName: string;
|
|
166
|
+
};
|
|
167
|
+
unregistered: {
|
|
168
|
+
themeName: string;
|
|
169
|
+
};
|
|
170
|
+
variantAdded: {
|
|
171
|
+
themeName: string;
|
|
172
|
+
variantName: string;
|
|
173
|
+
};
|
|
174
|
+
themeChanged: {
|
|
175
|
+
themeName: string;
|
|
176
|
+
modeName: string;
|
|
177
|
+
};
|
|
178
|
+
loaded: {
|
|
179
|
+
source: string;
|
|
180
|
+
count: number;
|
|
181
|
+
fromCache: boolean;
|
|
182
|
+
};
|
|
183
|
+
composed: {
|
|
184
|
+
appliedLayers: string[];
|
|
185
|
+
};
|
|
186
|
+
pluginRegistered: {
|
|
187
|
+
pluginName: string;
|
|
188
|
+
};
|
|
189
|
+
pluginUnregistered: {
|
|
190
|
+
pluginName: string;
|
|
191
|
+
};
|
|
192
|
+
destroyed: {
|
|
193
|
+
timestamp: string;
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
type ThemeRegistryEvent = keyof ThemeRegistryEventPayloadMap;
|
|
197
|
+
type ThemeRegistryEventHandler<K extends ThemeRegistryEvent> = (payload: ThemeRegistryEventPayloadMap[K]) => void;
|
|
198
|
+
declare function isThemeTokensV2(tokens: ThemeTokenSet): tokens is ThemeTokensV2;
|
|
199
|
+
declare function validateTheme(theme: ThemeDefinition): ThemeValidationResult;
|
|
200
|
+
declare class ThemeRegistry {
|
|
201
|
+
private themes;
|
|
202
|
+
private plugins;
|
|
203
|
+
private compositionLayers;
|
|
204
|
+
private loadedThemeCache;
|
|
205
|
+
private currentTheme;
|
|
206
|
+
private currentMode;
|
|
207
|
+
private fallbackConfig;
|
|
208
|
+
private listeners;
|
|
209
|
+
getVersion(): string;
|
|
210
|
+
on<K extends ThemeRegistryEvent>(event: K, handler: ThemeRegistryEventHandler<K>): () => void;
|
|
211
|
+
onRegistered(handler: ThemeRegistryEventHandler<'registered'>): () => void;
|
|
212
|
+
onThemeChanged(handler: ThemeRegistryEventHandler<'themeChanged'>): () => void;
|
|
213
|
+
onVariantAdded(handler: ThemeRegistryEventHandler<'variantAdded'>): () => void;
|
|
214
|
+
onDestroyed(handler: ThemeRegistryEventHandler<'destroyed'>): () => void;
|
|
215
|
+
onLoaded(handler: ThemeRegistryEventHandler<'loaded'>): () => void;
|
|
216
|
+
onComposed(handler: ThemeRegistryEventHandler<'composed'>): () => void;
|
|
217
|
+
private emit;
|
|
218
|
+
register(theme: ThemeDefinition, options?: ThemeRegistrationOptions): void;
|
|
219
|
+
replace(themeName: string, theme: ThemeDefinition): void;
|
|
220
|
+
merge(themeName: string, theme: ThemeDefinition): void;
|
|
221
|
+
unregister(themeName: string): boolean;
|
|
222
|
+
setFallback(config: ThemeFallbackConfig): void;
|
|
223
|
+
registerPlugin(plugin: ThemePluginDefinition, options?: PluginRegistrationOptions): void;
|
|
224
|
+
registerCompositionLayer(layer: ThemeCompositionLayerDefinition, options?: ThemeRegistrationOptions): void;
|
|
225
|
+
getCompositionLayer(type: ThemeCompositionLayerType, name: string): ThemeCompositionLayerDefinition | undefined;
|
|
226
|
+
getCompositionLayers(type?: ThemeCompositionLayerType): ThemeCompositionLayerDefinition[];
|
|
227
|
+
compose(selection: ThemeCompositionSelection): ThemeCompositionResult;
|
|
228
|
+
getInitialThemeAttributes(themeName: string | null, modeName: string | null): ThemeDocumentAttributes | null;
|
|
229
|
+
hydrateThemeOnDocument(themeName: string | null, modeName: string | null): ThemeResolutionResult;
|
|
230
|
+
load(source: ThemeLoadSource, options?: ThemeLoadOptions): Promise<ThemeLoadResult>;
|
|
231
|
+
clearLoadCache(cacheKey?: string): void;
|
|
232
|
+
unregisterPlugin(pluginName: string): boolean;
|
|
233
|
+
getPlugin(name: string): ThemePluginDefinition | undefined;
|
|
234
|
+
getPlugins(): ThemePluginDefinition[];
|
|
235
|
+
getPluginContributions(pluginName: string): ThemePluginContributions | undefined;
|
|
236
|
+
getMergedPluginContributions(): ThemePluginContributions;
|
|
237
|
+
/**
|
|
238
|
+
* Dynamically register a theme mode - useful for packages to add their own modes
|
|
239
|
+
* @param themeName - The name of the existing theme to add the mode to
|
|
240
|
+
* @param modeName - The name of the mode (e.g., 'ocean', 'forest', 'high-contrast')
|
|
241
|
+
* @param tokens - The tokens for this mode
|
|
242
|
+
*/
|
|
243
|
+
registerMode(themeName: string, modeName: string, tokens: ThemeTokenSet): void;
|
|
244
|
+
/**
|
|
245
|
+
* Register multiple modes at once for a theme
|
|
246
|
+
*/
|
|
247
|
+
registerModes(themeName: string, modes: Record<string, ThemeTokenSet>): void;
|
|
248
|
+
/**
|
|
249
|
+
* Create and register a new theme with specific modes
|
|
250
|
+
* Useful for packages that want to add their own themes dynamically
|
|
251
|
+
*/
|
|
252
|
+
createTheme(name: string, modes: Record<string, ThemeTokenSet>): void;
|
|
253
|
+
private getFallbackThemeName;
|
|
254
|
+
private resolveModeName;
|
|
255
|
+
resolveSelection(themeName: string | null, modeName: string | null): ThemeResolutionResult;
|
|
256
|
+
get(name: string): ThemeDefinition | undefined;
|
|
257
|
+
getAll(): ThemeDefinition[];
|
|
258
|
+
getTokens(themeName: string, modeName: string): ThemeTokenSet | undefined;
|
|
259
|
+
setCurrent(themeName: string, modeName: string): void;
|
|
260
|
+
getCurrent(): {
|
|
261
|
+
theme: string | null;
|
|
262
|
+
mode: string | null;
|
|
263
|
+
};
|
|
264
|
+
has(themeName: string): boolean;
|
|
265
|
+
getModes(themeName: string): string[];
|
|
266
|
+
getVariants(themeName: string): string[];
|
|
267
|
+
destroy(): void;
|
|
268
|
+
}
|
|
269
|
+
declare const themeRegistry: ThemeRegistry;
|
|
270
|
+
|
|
271
|
+
interface ThemeContextType {
|
|
272
|
+
currentTheme: string | null;
|
|
273
|
+
currentMode: string | null;
|
|
274
|
+
themes: ThemeDefinition[];
|
|
275
|
+
setTheme: (themeName: string, mode: string) => void;
|
|
276
|
+
setMode: (mode: string) => void;
|
|
277
|
+
availableModes: string[];
|
|
278
|
+
getThemeColors: () => ThemeTokenSet | null;
|
|
279
|
+
}
|
|
280
|
+
declare function ThemeProvider({ children }: {
|
|
281
|
+
children: React.ReactNode;
|
|
282
|
+
}): React.JSX.Element;
|
|
283
|
+
declare function useTheme(): ThemeContextType;
|
|
284
|
+
|
|
285
|
+
declare function paletteToCSSVariables(palette: ThemePalette): Record<string, string>;
|
|
286
|
+
declare function tokenSetToCSSVariables(tokens: ThemeTokenSet): Record<string, string>;
|
|
287
|
+
declare function generateThemeCSS(theme: ThemeDefinition): string;
|
|
288
|
+
declare function generateAllThemesCSS(themes: ThemeDefinition[]): string;
|
|
289
|
+
declare function applyThemeToDocument(theme: ThemeDefinition, mode: string): void;
|
|
290
|
+
|
|
291
|
+
export { type ThemePalette as ColorModePalette, type PluginRegistrationConflict, type PluginRegistrationOptions, RUNTIME_THEME_REGISTRY_VERSION, type ThemeCompatibility, type ThemeCompositionLayerDefinition, type ThemeCompositionLayerType, type ThemeCompositionResult, type ThemeCompositionSelection, type ThemeDefinition, type ThemeDocumentAttributes, type ThemeFallbackConfig, type ThemeLoadCacheEntry, type ThemeLoadOptions, type ThemeLoadResult, type ThemeLoadSource, type ThemeMetadata, type ThemePalette, type ThemePluginContributions, type ThemePluginDefinition, ThemeProvider, type ThemeRegistrationConflict, type ThemeRegistrationOptions, type ThemeRegistryEvent, type ThemeRegistryEventHandler, type ThemeRegistryEventPayloadMap, type ThemeResolutionResult, type ThemeTokenSet, type ThemeTokensV2, type ThemeValidationIssue, type ThemeValidationResult, applyThemeToDocument, themeRegistry as default, generateAllThemesCSS, generateThemeCSS, isThemeTokensV2, paletteToCSSVariables, themeRegistry, tokenSetToCSSVariables, useTheme, validateTheme };
|