{"version":3,"file":"ngwr-theme.mjs","sources":["../../../projects/lib/theme/colors.ts","../../../projects/lib/theme/wr-theme-config.ts","../../../projects/lib/theme/services/wr-theme.ts","../../../projects/lib/theme/provide-wr-theme.ts","../../../projects/lib/theme/ngwr-theme.ts"],"sourcesContent":["/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\n/**\n * Built-in color variants available to NGWR components.\n *\n * Kept in sync manually with the SCSS `$base-colors` map in\n * `theme/styles/_colors.scss`. Both sources must stay aligned —\n * adding a color requires updating both this array and the SCSS map.\n *\n * @example\n * ```ts\n * import { WR_COLORS } from 'ngwr/theme';\n *\n * // Iterate all colors for demos or documentation\n * WR_COLORS.forEach(color => console.log(color));\n * ```\n */\nexport const WR_COLORS = ['primary', 'secondary', 'success', 'warning', 'danger', 'light', 'medium', 'dark'] as const;\n\n/**\n * A color variant name.\n *\n * Use as an input type on components that accept a color:\n *\n * @example\n * ```ts\n * import type { WrColor } from 'ngwr/theme';\n *\n * @Component({...})\n * export class MyComponent {\n *   readonly color = input<WrColor>('primary');\n * }\n * ```\n */\nexport type WrColor = (typeof WR_COLORS)[number];\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { InjectionToken } from '@angular/core';\n\n/** Mode the user explicitly selected. `auto` follows `prefers-color-scheme`. */\nexport type WrThemeMode = 'light' | 'dark' | 'auto';\n\n/** Resolved theme — what's actually applied to the DOM. */\nexport type WrResolvedTheme = 'light' | 'dark';\n\n/** Configuration for {@link WrTheme}. */\nexport interface WrThemeConfig {\n  /** Initial mode used when no persisted value is present. @default 'auto' */\n  readonly defaultMode: WrThemeMode;\n  /** localStorage key for persistence. Set to `null` to disable persistence. @default 'wr-theme' */\n  readonly storageKey: string | null;\n  /** Attribute applied to `<html>` to expose the resolved theme. @default 'data-theme' */\n  readonly attribute: string;\n}\n\nexport const DEFAULT_WR_THEME_CONFIG: WrThemeConfig = {\n  defaultMode: 'auto',\n  storageKey: 'wr-theme',\n  attribute: 'data-theme',\n};\n\nexport const WR_THEME_CONFIG = new InjectionToken<WrThemeConfig>('WR_THEME_CONFIG', {\n  factory: (): WrThemeConfig => DEFAULT_WR_THEME_CONFIG,\n});\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { DOCUMENT } from '@angular/common';\nimport { Service, type Signal, computed, effect, inject, signal } from '@angular/core';\n\nimport { WrPlatform } from 'ngwr/platform';\nimport { WrStorage } from 'ngwr/storage';\n\nimport { WR_THEME_CONFIG, type WrResolvedTheme, type WrThemeMode } from '../wr-theme-config';\n\nconst VALID_MODES: readonly WrThemeMode[] = ['light', 'dark', 'auto'];\n\nfunction isThemeMode(v: unknown): v is WrThemeMode {\n  return typeof v === 'string' && (VALID_MODES as readonly string[]).includes(v);\n}\n\n/**\n * Light / dark theme manager.\n *\n * - `mode` is what the user picked (`light` | `dark` | `auto`).\n * - `resolved` is what's actually applied — `auto` resolves through\n *   {@link WrPlatform.prefersDark}.\n * - Writes `[data-theme]` (or your configured attribute) on `<html>`.\n * - Persists the selected mode via {@link WrStorage} (defaults to\n *   `localStorage`; swap the storage engine globally to change where).\n *\n * @example\n * ```ts\n * const theme = inject(WrTheme);\n * theme.set('dark');\n * theme.toggle();\n * theme.resolved();  // 'dark'\n * ```\n *\n * @see https://ngwr.dev/services/theme\n */\n@Service()\nexport class WrTheme {\n  private readonly doc = inject(DOCUMENT);\n  private readonly platform = inject(WrPlatform);\n  private readonly storage = inject(WrStorage);\n  private readonly config = inject(WR_THEME_CONFIG);\n\n  /** User-selected mode. */\n  readonly mode = signal<WrThemeMode>(this.readPersisted() ?? this.config.defaultMode);\n\n  /** Resolved theme actually applied to the DOM. */\n  readonly resolved: Signal<WrResolvedTheme> = computed(() => {\n    const m = this.mode();\n    if (m === 'auto') return this.platform.prefersDark() ? 'dark' : 'light';\n    return m;\n  });\n\n  constructor() {\n    // Whenever the resolved theme changes, mirror it to the DOM + persist mode.\n    effect(() => {\n      const value = this.resolved();\n      const html = this.doc.documentElement;\n      if (html) html.setAttribute(this.config.attribute, value);\n      this.persist(this.mode());\n    });\n  }\n\n  /** Switch to a specific mode. */\n  set(mode: WrThemeMode): void {\n    this.mode.set(mode);\n  }\n\n  /** Cycle: light → dark → light (skips auto). */\n  toggle(): void {\n    this.mode.set(this.resolved() === 'dark' ? 'light' : 'dark');\n  }\n\n  // Persistence\n\n  private readPersisted(): WrThemeMode | null {\n    if (!this.config.storageKey) return null;\n    const raw = this.storage.get<WrThemeMode>(this.config.storageKey);\n    return isThemeMode(raw) ? raw : null;\n  }\n\n  private persist(mode: WrThemeMode): void {\n    if (!this.config.storageKey) return;\n    this.storage.set(this.config.storageKey, mode);\n  }\n}\n","/**\n * @license\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/thekhegay/ngwr/blob/main/LICENSE\n */\n\nimport { type EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';\n\nimport { DEFAULT_WR_THEME_CONFIG, WR_THEME_CONFIG, type WrThemeConfig } from './wr-theme-config';\n\n/**\n * Configure {@link WrTheme}. Partial — merged with defaults.\n *\n * @example\n * ```ts\n * provideWrTheme({ defaultMode: 'dark', storageKey: 'my-app-theme' })\n * ```\n */\nexport function provideWrTheme(config: Partial<WrThemeConfig> = {}): EnvironmentProviders {\n  const merged: WrThemeConfig = { ...DEFAULT_WR_THEME_CONFIG, ...config };\n  return makeEnvironmentProviders([{ provide: WR_THEME_CONFIG, useValue: merged }]);\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;AAKG;AAEH;;;;;;;;;;;;;;AAcG;MACU,SAAS,GAAG,CAAC,SAAS,EAAE,WAAW,EAAE,SAAS,E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