ngx-theme-stack 3.4.0 → 3.5.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/README.md +71 -20
- package/fesm2022/ngx-theme-stack.mjs +2 -5
- package/fesm2022/ngx-theme-stack.mjs.map +1 -1
- package/package.json +21 -2
- package/schematics/ng-add/app-config.js +26 -33
- package/schematics/ng-add/app-config.js.map +1 -1
- package/schematics/ng-add/index.d.ts +0 -3
- package/schematics/ng-add/index.js +74 -64
- package/schematics/ng-add/index.js.map +1 -1
- package/schematics/ng-add/utils.js.map +1 -1
- package/schematics/sync/index.js +26 -44
- package/schematics/sync/index.js.map +1 -1
- package/types/ngx-theme-stack.d.ts +4 -4
package/README.md
CHANGED
|
@@ -49,7 +49,7 @@ When running `ng add`, you will be presented with two configuration options:
|
|
|
49
49
|
- Configure the default theme upon app startup.
|
|
50
50
|
- Change the `localStorage` key where the theme choice is saved.
|
|
51
51
|
- Decide how to apply themes: via classes (`class`), attributes (`data-theme`), or both.
|
|
52
|
-
- **Pick your strategy**: `critters` for
|
|
52
|
+
- **Pick your strategy**: `critters` (default) inlines all theme CSS — works for CSR, SSR, and SSG. Use `blocking` if you have a strict CSP or prefer a standard external stylesheet.
|
|
53
53
|
|
|
54
54
|
## 🤖 What does `ng add` do for you?
|
|
55
55
|
|
|
@@ -256,46 +256,96 @@ The `ng add` command automatically creates a **`src/themes.css`** file. This is
|
|
|
256
256
|
|
|
257
257
|
## 🌪️ Tailwind CSS v4 Integration
|
|
258
258
|
|
|
259
|
-
If you are using **Tailwind CSS v4**, you can
|
|
259
|
+
If you are using **Tailwind CSS v4**, you can map your `themes.css` variables directly to Tailwind design tokens for a clean, theme-aware utility class experience.
|
|
260
260
|
|
|
261
|
-
### 1.
|
|
261
|
+
### 1. Map Semantic Variables ✅ Recommended
|
|
262
|
+
|
|
263
|
+
In your `src/styles.css`, expose your theme variables as Tailwind tokens:
|
|
262
264
|
|
|
263
265
|
```css
|
|
264
|
-
/* src/styles.css */
|
|
265
266
|
@import 'tailwindcss';
|
|
266
267
|
|
|
267
|
-
/* If using Class mode */
|
|
268
|
-
@custom-variant dark (&:where(.dark, .dark *));
|
|
269
|
-
|
|
270
|
-
/* If using Attribute mode */
|
|
271
|
-
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### 2. Map Semantic Variables
|
|
275
|
-
|
|
276
|
-
```css
|
|
277
268
|
@theme {
|
|
278
269
|
--color-main-bg: var(--bg-color);
|
|
279
270
|
--color-main-text: var(--text-color);
|
|
280
271
|
}
|
|
281
272
|
```
|
|
282
273
|
|
|
283
|
-
###
|
|
274
|
+
### 2. Usage in Components
|
|
284
275
|
|
|
285
|
-
Now you can write clean, theme-aware classes:
|
|
276
|
+
Now you can write clean, theme-aware classes. Colors update **automatically** whenever `ngx-theme-stack` switches the active theme — no `dark:` prefix needed:
|
|
286
277
|
|
|
287
278
|
```html
|
|
288
279
|
<div class="bg-main-bg text-main-text shadow-xl">
|
|
289
|
-
<!--
|
|
280
|
+
<!-- Automatically reflects the active theme (dark, light, sunset, etc.) -->
|
|
290
281
|
</div>
|
|
291
282
|
```
|
|
292
283
|
|
|
284
|
+
> **✅ Why this works:** The CSS variables on `<html>` are already set before Angular boots (see [Performance Strategies](#-performance-strategies)). Since the Tailwind tokens (`--color-main-bg`) point directly to those variables, **this single approach covers manual toggling + all themes** (dark, light, sunset, etc.) — without any extra Tailwind configuration.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
---
|
|
288
|
+
|
|
289
|
+
### (Optional) Enable the `dark:` Tailwind Prefix
|
|
290
|
+
|
|
291
|
+
Only needed if you want to use `dark:` utilities directly (e.g. `dark:bg-black`) tied to ngx-theme-stack's toggle instead of the OS system preference.
|
|
292
|
+
|
|
293
|
+
```css
|
|
294
|
+
/* src/styles.css */
|
|
295
|
+
@import 'tailwindcss';
|
|
296
|
+
|
|
297
|
+
/* Class mode */
|
|
298
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
299
|
+
|
|
300
|
+
/* Attribute mode */
|
|
301
|
+
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
> **⚠️** Overriding `@custom-variant dark` disconnects `dark:` from the OS preference and only covers the `dark` theme. For multi-theme support, prefer the CSS variable approach above.
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
|
|
293
309
|
## ⚡ Performance Strategies
|
|
294
310
|
|
|
295
|
-
|
|
311
|
+
### How the theme is applied on first load
|
|
312
|
+
|
|
313
|
+
`ng add` injects a minimal blocking script as the **first child of `<head>`** in your `index.html`. This script runs before any stylesheet or Angular bundle:
|
|
314
|
+
|
|
315
|
+
```
|
|
316
|
+
1. Reads the stored theme from localStorage
|
|
317
|
+
2. If the theme (or defaultTheme) is 'system' →
|
|
318
|
+
resolves OS preference via matchMedia('prefers-color-scheme: dark')
|
|
319
|
+
3. Applies the theme to <html> (class, attribute, or both)
|
|
320
|
+
4. Sets color-scheme CSS property for native browser adaptation
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
This script **always runs regardless of strategy** — it eliminates the flash of incorrect theme class. However, the CSS variables (your actual colors) still need to be delivered. That's where the strategy matters.
|
|
324
|
+
|
|
325
|
+
### Anti-flash strategies
|
|
326
|
+
|
|
327
|
+
There are two layers to prevent a flash:
|
|
328
|
+
|
|
329
|
+
| Layer | What it prevents | Always active? |
|
|
330
|
+
|---|---|---|
|
|
331
|
+
| Anti-flash script | Wrong theme class on `<html>` | ✅ Yes, always |
|
|
332
|
+
| Strategy | Unstyled variables flash | Depends on chosen strategy |
|
|
333
|
+
|
|
334
|
+
**1. Critters (Default)**
|
|
335
|
+
|
|
336
|
+
Injects hidden `<div>`s for each theme into `<body>`, forcing Angular's Critters optimizer to inline **all** CSS variables directly into `<head>`. When the anti-flash script sets the class, the variables are already there — **zero network requests, zero flash**. Works equally for CSR, SSR, and SSG apps.
|
|
337
|
+
|
|
338
|
+
**2. Blocking**
|
|
339
|
+
|
|
340
|
+
Disables Critters (`inlineCritical: false`) and loads `themes.css` as a render-blocking stylesheet. The browser blocks rendering until it's downloaded, so there's no visible flash — but it requires one network round-trip. The file is HTTP-cacheable after the first load.
|
|
341
|
+
|
|
342
|
+
**When to choose Blocking over Critters:**
|
|
343
|
+
|
|
344
|
+
- **Strict CSP** — Critters generates inline `<style>` tags, which require `'unsafe-inline'` in `style-src`. A blocking stylesheet avoids this.
|
|
345
|
+
- **Many themes** — All theme variables get inlined into the HTML on every request with Critters. If you have many themes with many variables, a cached external file is more efficient.
|
|
346
|
+
- **Critters conflicts** — Complex CSS pipelines (PostCSS, CSS Modules, etc.) can conflict with Critters. Blocking is the safe fallback.
|
|
347
|
+
- **Simpler debugging** — An explicit stylesheet is easier to inspect in DevTools than inlined styles.
|
|
296
348
|
|
|
297
|
-
1. **Critters (Default)**: Best for SSR/Static sites. Inlines CSS variables directly in the HTML `<head>`. Result: **Zero network requests for theme variables.**
|
|
298
|
-
2. **Blocking**: Best for standard SPAs. Loads `themes.css` as a traditional blocking resource.
|
|
299
349
|
|
|
300
350
|
Use the **Sync Command** to refresh your `index.html` if you change your configuration:
|
|
301
351
|
|
|
@@ -303,6 +353,7 @@ Use the **Sync Command** to refresh your `index.html` if you change your configu
|
|
|
303
353
|
ng generate ngx-theme-stack:sync --project YOUR_PROJECT_NAME
|
|
304
354
|
```
|
|
305
355
|
|
|
356
|
+
|
|
306
357
|
## 📄 License
|
|
307
358
|
|
|
308
359
|
[MIT](./LICENSE)
|
|
@@ -99,7 +99,7 @@ const NGX_THEME_STACK_CONFIG = new InjectionToken('NGX_THEME_STACK_CONFIG', {
|
|
|
99
99
|
* provideThemeStack()
|
|
100
100
|
*
|
|
101
101
|
* @example
|
|
102
|
-
* //
|
|
102
|
+
* // Critters strategy — inlines all theme CSS in <head> (works for CSR, SSR, and SSG)
|
|
103
103
|
* provideThemeStack({
|
|
104
104
|
* strategy: 'critters',
|
|
105
105
|
* mode: 'class',
|
|
@@ -157,10 +157,7 @@ class CoreThemeService {
|
|
|
157
157
|
#document = inject(DOCUMENT);
|
|
158
158
|
#isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
159
159
|
// ── Theme configuration ───────────────────────────────────────────────────
|
|
160
|
-
/**
|
|
161
|
-
* The initial stored theme read from localStorage.
|
|
162
|
-
* This is used to determine the initial theme of the application.
|
|
163
|
-
*/
|
|
160
|
+
/** The initial stored theme read from localStorage on startup. */
|
|
164
161
|
#initialStoredTheme = this.readStoredTheme();
|
|
165
162
|
/** List of available themes for Select/Cycle services. Defaults to ['system', 'light', 'dark']. */
|
|
166
163
|
availableThemes = this.#config.themes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngx-theme-stack.mjs","sources":["../../../projects/ngx-theme-stack/src/lib/errors.ts","../../../projects/ngx-theme-stack/src/lib/types.ts","../../../projects/ngx-theme-stack/src/lib/config/index.ts","../../../projects/ngx-theme-stack/src/lib/core/core-theme.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-cycle.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-select.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-toggle.service.ts","../../../projects/ngx-theme-stack/src/public-api.ts","../../../projects/ngx-theme-stack/src/ngx-theme-stack.ts"],"sourcesContent":["/**\n * Base error class for `ngx-theme-stack`.\n *\n * Thrown when the library configuration is invalid.\n * Consumers can use `instanceof NgxThemeStackError` to catch only\n * errors originating from this library.\n *\n * @example\n * try {\n * bootstrapApplication(AppComponent, appConfig);\n * } catch (e) {\n * if (e instanceof NgxThemeStackError) {\n * console.error('Bad ngx-theme-stack config:', e.message);\n * }\n * }\n */\nexport class NgxThemeStackError extends Error {\n override readonly name = 'NgxThemeStackError';\n\n constructor(message: string) {\n super(`[ngx-theme-stack] ${message}`);\n // Restore prototype chain (required when targeting ES5 or older)\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","/**\n * Runtime list of built-in themes.\n *\n * Lives here (and not in config/index.ts) because it defines a type:\n * config/index.ts already imports from types.ts, so placing DEFAULT_THEMES\n * here avoids any circular dependency.\n *\n * ⚠ KEEP IN SYNC with the duplicate in:\n * projects/ngx-theme-stack/schematics/ng-add/constants.ts → DEFAULT_THEMES\n *\n * Schematics compile to CommonJS and cannot import from this ESM file,\n * so the values are intentionally duplicated. Change both at the same time.\n */\nexport const DEFAULT_THEMES = ['system', 'light', 'dark'] as const;\n\n/** Literal union of built-in themes: `'system' | 'light' | 'dark'`. */\nexport type DefaultNgTheme = (typeof DEFAULT_THEMES)[number];\n\n/**\n * Theme type.\n *\n * - **Without** `T`: open union — accepts any `string` with IDE autocomplete\n * hints for the built-in themes (`'system' | 'light' | 'dark'`).\n * - **With** `T`: closed union — exactly `DefaultNgTheme | T`, enabling\n * full type-safety for custom theme sets.\n *\n * @example\n * NgTheme // 'system' | 'light' | 'dark' | (string & {})\n * NgTheme<'sepia'> // 'system' | 'light' | 'dark' | 'sepia'\n */\nexport type NgTheme<T extends string = string & {}> = DefaultNgTheme | T;\n\n/**\n * Resolved theme — always `'light'` or `'dark'`, never `'system'`.\n * Represents the value that comes from `matchMedia`, not user selection.\n */\nexport type NgSystemTheme = Exclude<DefaultNgTheme, 'system'>;\n\n/**\n * Theme application mode.\n * - `'attribute'`: sets `data-theme` attribute on `<html>`\n * - `'class'`: adds theme class to `<html>`\n * - `'both'`: uses both attribute and class\n */\nexport type NgMode = 'attribute' | 'class' | 'both';\n\n/**\n * Theme application strategy.\n * - `'blocking'`: theme CSS is loaded synchronously before rendering\n * - `'critters'`: theme CSS is inlined using Critters for SSR/SSG\n */\nexport type NgStrategy = 'blocking' | 'critters';\n\n/**\n * Library configuration.\n *\n * @typeParam T - Custom theme literals. Defaults to open `string`, preserving\n * backwards compatibility. Pass specific literals (e.g. `'sepia' | 'ocean'`)\n * via {@link provideThemeStack} to get a closed, type-safe theme union.\n */\nexport interface NgConfig<T extends string = string & {}> {\n /** The theme to use on first visit or when no preference is saved. Default: 'system'. */\n defaultTheme: NgTheme<T>;\n\n /** Key used to persist theme preference in localStorage. Default: 'ngx-theme-stack-theme'. */\n storageKey: string;\n\n /** \n * How the theme should be applied to the document (via class, attribute or both). \n * Default: 'class'.\n */\n mode: NgMode;\n\n /** \n * Performance strategy for anti-flash. \n * Use 'critters' for SSG/SSR builds with inlined CSS, 'blocking' for standard CSS files.\n * Default: 'critters'.\n */\n strategy: NgStrategy;\n\n /** List of supported theme identifiers. Default: ['light', 'dark', 'system']. */\n themes: NgTheme<T>[];\n}\n","import { InjectionToken } from '@angular/core';\nimport { NgxThemeStackError } from '../errors';\nimport { DEFAULT_THEMES, DefaultNgTheme, NgConfig } from '../types';\n\n/**\n * ⚠ ATTENTION: SHARED CONFIGURATION VALUES\n *\n * These defaults MUST match the schematic defaults in:\n * projects/ngx-theme-stack/schematics/ng-add/constants.ts → DEFAULTS\n *\n * Schematics compile to CommonJS and cannot import from this ESM file,\n * so the values are intentionally duplicated. Change both at the same time.\n *\n * If you change defaults here, also update:\n * schematics/ng-add/constants.ts → DEFAULTS + DEFAULT_THEMES\n */\n\nexport const DEFAULT_NG_CONFIG = {\n defaultTheme: 'system',\n storageKey: 'ngx-theme-stack',\n mode: 'class',\n strategy: 'critters',\n themes: [...DEFAULT_THEMES],\n} satisfies NgConfig;\n\n// The token uses NgConfig<string> because Angular DI resolves types at runtime\n// and cannot carry generic parameters. Type-safety is enforced at the\n// provideThemeStack() call site instead.\nexport const NGX_THEME_STACK_CONFIG = new InjectionToken<NgConfig<string>>(\n 'NGX_THEME_STACK_CONFIG',\n {\n factory: () => DEFAULT_NG_CONFIG,\n },\n);\n\n/**\n * Provides Theme Stack configuration to Angular's DI system.\n *\n * Custom `themes` are **merged** with the built-in defaults\n * (`'light'`, `'dark'`, `'system'`), so you never lose the base themes.\n *\n * **Defaults:**\n * - `themes`: `['light', 'dark', 'system']`\n * - `defaultTheme`: `'system'`\n * - `storageKey`: `'ngx-theme-stack'`\n * - `mode`: `'class'`\n * - `strategy`: `'critters'`\n\n *\n * The type parameter `T` is **inferred automatically** from the `themes` array\n * when passed as a `const` — no need to specify it manually.\n *\n * @typeParam T - Custom theme string literals, inferred from the `themes` option.\n *\n * @param config - Optional partial configuration. Omitted fields fall back to\n * {@link DEFAULT_NG_CONFIG}.\n *\n * @throws {@link NgxThemeStackError}\n * - If any entry in `themes` is an empty or whitespace-only string.\n * - If `defaultTheme` is not present in the resolved (merged) themes array.\n * - If `storageKey` is an empty or whitespace-only string.\n *\n * @example\n * // Default — uses built-in themes and sensible defaults\n * provideThemeStack()\n *\n * @example\n * // SSR/SSG Optimization — uses Critters inlining strategy\n * provideThemeStack({\n * strategy: 'critters',\n * mode: 'class',\n * })\n *\n * @example\n * // Closed union: TypeScript infers 'sepia' | 'ocean' from the array\n * provideThemeStack({\n * themes: ['sepia', 'ocean'] as const,\n * defaultTheme: 'sepia', // ✅ in resolved themes\n * // defaultTheme: 'nope', // ❌ throws NgxThemeStackError at runtime\n * })\n *\n * @example\n * // Custom storage key and mode\n * provideThemeStack({\n * storageKey: 'my-app-theme',\n * mode: 'attribute',\n * })\n */\nexport function provideThemeStack<const T extends string = DefaultNgTheme>(\n config: Partial<NgConfig<T>> = {},\n) {\n config.themes?.forEach((t) => {\n if (t.trim() === '') throw new NgxThemeStackError('Theme cannot be empty or whitespace.');\n });\n\n const themes = config.themes\n ? Array.from(new Set([...DEFAULT_NG_CONFIG.themes, ...config.themes]))\n : DEFAULT_NG_CONFIG.themes;\n\n if (config.defaultTheme && !(themes as string[]).includes(config.defaultTheme as string)) {\n throw new NgxThemeStackError(\n `\"defaultTheme\" must be one of the resolved themes: [${themes.join(', ')}].`,\n );\n }\n\n if (config.storageKey !== undefined && config.storageKey.trim() === '') {\n throw new NgxThemeStackError('\"storageKey\" cannot be empty or whitespace.');\n }\n\n return {\n provide: NGX_THEME_STACK_CONFIG,\n useValue: {\n ...DEFAULT_NG_CONFIG,\n ...config,\n themes,\n } as NgConfig<string>,\n };\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n computed,\n DestroyRef,\n DOCUMENT,\n effect,\n inject,\n Injectable,\n PLATFORM_ID,\n signal,\n} from '@angular/core';\nimport { NGX_THEME_STACK_CONFIG } from '../config';\nimport { NgxThemeStackError } from '../errors';\nimport { NgSystemTheme, NgTheme } from '../types';\n\n/**\n * Core service for managing the application's color theme.\n *\n * Handles theme persistence, system preference detection, and DOM updates.\n * Supports built-in themes ('dark', 'light', 'system') and custom extensions.\n */\n@Injectable({ providedIn: 'root' })\nexport class CoreThemeService {\n // ── Dependencies ──────────────────────────────────────────────────────────\n\n readonly #config = inject(NGX_THEME_STACK_CONFIG);\n readonly #destroyRef = inject(DestroyRef);\n readonly #document = inject(DOCUMENT);\n readonly #isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n // ── Theme configuration ───────────────────────────────────────────────────\n\n /**\n * The initial stored theme read from localStorage.\n * This is used to determine the initial theme of the application.\n */\n readonly #initialStoredTheme = this.readStoredTheme();\n\n /** List of available themes for Select/Cycle services. Defaults to ['system', 'light', 'dark']. */\n readonly availableThemes = this.#config.themes;\n\n /** Internal Set for O(1) existence checks. */\n readonly #validThemes = new Set<NgTheme>(this.availableThemes);\n\n /**\n * The anti-flash class to remove from the host element.\n * Internal mechanism to bridge the gap between the blocking script's\n * initial DOM state and Angular's first effect run.\n */\n #antiFlashClass: string | null = null;\n\n // ── System preference ─────────────────────────────────────────────────────\n\n /** MediaQueryList for OS color scheme, created once and reused. Null in SSR. */\n readonly #mediaQuery: MediaQueryList | null = this.#isBrowser\n ? (this.#document.defaultView?.matchMedia('(prefers-color-scheme: dark)') ?? null)\n : null;\n\n readonly #systemPreference = signal<NgSystemTheme>(this.resolveSystemPreference());\n\n // ── Theme state ───────────────────────────────────────────────────────────\n\n readonly #selectedTheme = signal<NgTheme>(this.resolveInitialTheme());\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#selectedTheme.asReadonly();\n\n /** Resolved theme applied to the DOM. Always `'dark'` or `'light'` (or custom) — never `'system'`. */\n readonly resolvedTheme = computed(() => {\n const theme = this.#selectedTheme();\n return theme === 'system' ? this.#systemPreference() : theme;\n });\n\n /** Whether the currently applied theme is dark. */\n readonly isDark = computed(() => this.resolvedTheme() === 'dark');\n\n /** Whether the currently applied theme is light. */\n readonly isLight = computed(() => this.resolvedTheme() === 'light');\n\n /** Whether the currently applied theme is system. */\n readonly isSystem = computed(() => this.selectedTheme() === 'system');\n\n /**\n * Whether the service has completed client-side initialization.\n *\n * `false` during SSR and on the very first render pass before the initial theme\n * is resolved from `localStorage`. Becomes `true` immediately after the\n * first browser render pass.\n *\n * **Important:** Guard template elements that display `selectedTheme()` or\n * `resolvedTheme()` behind this signal to prevent hydration-mismatch flashes\n * (e.g. if the server renders the default 'system' but the user has 'dark' stored).\n *\n * @example\n * ```html\n * {{ theme.isHydrated() ? theme.selectedTheme() : '...' }}\n * ```\n */\n readonly isHydrated = signal(false);\n\n // ── Event handler ─────────────────────────────────────────────────────────\n\n readonly #onSystemPreferenceChange = () =>\n this.#systemPreference.set(this.resolveSystemPreference());\n\n // ── Lifecycle ─────────────────────────────────────────────────────────────\n\n constructor() {\n this.captureAntiFlashClass();\n\n if (this.#isBrowser && this.#selectedTheme() === 'system') {\n this.startSystemThemeListener();\n }\n\n effect(() => this.applyThemeToDOM(this.resolvedTheme()));\n afterNextRender(() => this.isHydrated.set(true));\n this.#destroyRef.onDestroy(() => this.stopSystemThemeListener());\n }\n\n // ── Public API ────────────────────────────────────────────────────────────\n\n /**\n * Changes the active theme.\n *\n * Persists the choice explicitly so that switching e.g. from `'system'` to\n * `'light'` is saved even when the resolved theme did not change\n * (system preference was already `'light'`).\n *\n * @param theme - The theme to apply: `'dark'`, `'light'`, `'system'`, or a custom theme name.\n * @throws If `theme` is not a valid theme according to library configuration.\n */\n public setTheme(theme: NgTheme): void {\n if (!this.#validThemes.has(theme)) {\n throw new NgxThemeStackError(\n `Invalid theme: \"${theme}\". Valid values are: ${[...this.#validThemes].join(', ')}.`,\n );\n }\n if (!this.#isBrowser) return;\n if (theme === this.#selectedTheme()) return;\n if (theme === 'system') {\n this.#systemPreference.set(this.resolveSystemPreference());\n this.startSystemThemeListener();\n } else {\n this.stopSystemThemeListener();\n }\n\n this.#selectedTheme.set(theme);\n this.saveTheme(theme);\n }\n\n // ── Private ───────────────────────────────────────────────────────────────\n\n private resolveSystemPreference(): NgSystemTheme {\n return this.#mediaQuery?.matches ? 'dark' : 'light';\n }\n\n private resolveInitialTheme(): NgTheme {\n const theme = this.#initialStoredTheme;\n if (theme && this.#validThemes.has(theme as NgTheme)) {\n return theme as NgTheme;\n }\n return this.#config.defaultTheme;\n }\n\n private startSystemThemeListener(): void {\n if (!this.#mediaQuery) return;\n this.stopSystemThemeListener();\n this.#mediaQuery.addEventListener('change', this.#onSystemPreferenceChange);\n }\n\n private stopSystemThemeListener(): void {\n this.#mediaQuery?.removeEventListener('change', this.#onSystemPreferenceChange);\n }\n\n private applyThemeToDOM(theme: NgTheme): void {\n if (!this.#isBrowser) return;\n\n const host = this.#document.documentElement;\n\n if (this.#antiFlashClass) {\n host.classList.remove(this.#antiFlashClass);\n this.#antiFlashClass = null;\n }\n\n const { mode } = this.#config;\n\n if (mode === 'attribute' || mode === 'both') {\n this.applyThemeAttribute(host, theme);\n }\n\n if (mode === 'class' || mode === 'both') {\n this.applyThemeClasses(host, theme);\n }\n\n this.applyColorSchemeHint(host, theme);\n }\n\n private applyThemeAttribute(host: HTMLElement, theme: NgTheme): void {\n host.setAttribute('data-theme', theme);\n }\n\n private applyThemeClasses(host: HTMLElement, theme: NgTheme): void {\n host.classList.remove(...this.availableThemes);\n host.classList.add(theme);\n }\n\n private applyColorSchemeHint(host: HTMLElement, theme: NgTheme): void {\n if (theme === 'dark' || theme === 'light') {\n host.style.setProperty('color-scheme', theme);\n return;\n }\n\n host.style.removeProperty('color-scheme');\n }\n\n private captureAntiFlashClass(): void {\n if (!this.#isBrowser || !this.#initialStoredTheme) return;\n\n if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(this.#initialStoredTheme)) {\n this.#antiFlashClass = null;\n return;\n }\n\n if (this.#initialStoredTheme === 'system') {\n this.#antiFlashClass = this.resolveSystemPreference();\n return;\n }\n\n this.#antiFlashClass = this.#initialStoredTheme;\n }\n\n private readStoredTheme(): string | null {\n if (!this.#isBrowser) return null;\n\n try {\n return localStorage.getItem(this.#config.storageKey);\n } catch (e) {\n console.warn('[ngx-theme-stack] Could not read theme from localStorage.', e);\n return null;\n }\n }\n\n private saveTheme(theme: NgTheme): void {\n if (!this.#isBrowser) return;\n\n try {\n localStorage.setItem(this.#config.storageKey, theme);\n } catch (e) {\n console.warn('[ngx-theme-stack] Could not save theme to localStorage.', e);\n }\n }\n}\n","import { computed, inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\n\n/**\n * Convenience service for cycling through themes in a fixed order.\n *\n * Default cycle: `'system'` → `'light'` → `'dark'` → `'system'` → ...\n *\n * Use this when you want to offer users a single button that rotates\n * through all available theme options.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeCycleService {\n readonly #core = inject(CoreThemeService);\n\n /** List of all configured themes for cycling. Defaults to `['light', 'dark', 'system']`. */\n readonly availableThemes = this.#core.availableThemes;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** Index of the currently selected theme in the cycle. */\n readonly cycleIndex = computed(() => {\n return this.availableThemes.indexOf(this.selectedTheme());\n });\n\n /** The theme that comes before the currently selected theme in the cycle. */\n readonly preceding = computed(() => {\n const index = this.cycleIndex();\n const len = this.availableThemes.length;\n return this.availableThemes[(index - 1 + len) % len];\n });\n\n /** The theme that comes after the currently selected theme in the cycle. */\n readonly upcoming = computed(() => {\n const index = this.cycleIndex();\n return this.availableThemes[(index + 1) % this.availableThemes.length];\n });\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and\n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Advances to the next theme in the cycle.\n *\n * Cycle order is determined by the configured `themes` property in `NgConfig`.\n *\n * If the current theme is not found in the cycle (e.g. set externally),\n * the cycle restarts from the first theme.\n */\n cycle(): void {\n this.#core.setTheme(this.upcoming());\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\nimport { NgTheme } from '../types';\n\n/**\n * Convenience service for selecting a theme from a list.\n *\n * Use this when you want to bind a `<select>` or a group of radio/tab\n * buttons to the full set of available themes.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeSelectService {\n readonly #core = inject(CoreThemeService);\n\n /** List of all configured themes. Defaults to `['light', 'dark', 'system']`. */\n readonly availableThemes = this.#core.availableThemes;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and \n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Applies the given theme.\n *\n * @param theme - The theme to apply: `'dark'`, `'light'`, `'system'`, or custom.\n * @throws If `theme` is not a valid theme according to library configuration.\n */\n select(theme: NgTheme): void {\n this.#core.setTheme(theme);\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\n\n/**\n * Convenience service for toggling between `'dark'` and `'light'`.\n *\n * Use this when you only need a simple on/off switch and do not\n * need to manage `'system'` or cycle through themes.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeToggleService {\n readonly #core = inject(CoreThemeService);\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and \n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Toggles between `'dark'` and `'light'`.\n *\n * If the selected theme is explicitly `'dark'`, switches to `'light'`.\n * Otherwise (including `'system'`), switches to `'dark'`.\n */\n toggle(): void {\n const next = this.#core.resolvedTheme() === 'dark' ? 'light' : 'dark';\n this.#core.setTheme(next);\n }\n}\n","/*\n * Public API Surface of ngx-theme-stack\n */\n\nexport * from './lib/core/core-theme.service';\nexport * from './lib/config';\nexport * from './lib/services/theme-cycle.service';\nexport * from './lib/services/theme-select.service';\nexport * from './lib/services/theme-toggle.service';\nexport * from './lib/types';\nexport * from './lib/errors';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;AAeG;AACG,MAAO,kBAAmB,SAAQ,KAAK,CAAA;IACzB,IAAI,GAAG,oBAAoB;AAE7C,IAAA,WAAA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AA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,kBAAkB,cADL,MAAM,EAAA,CAAA;;2FACnB,kBAAkB,EAAA,UAAA,EAAA,CAAA;kBAD9B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACTlC;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngx-theme-stack.mjs","sources":["../../../projects/ngx-theme-stack/src/lib/errors.ts","../../../projects/ngx-theme-stack/src/lib/types.ts","../../../projects/ngx-theme-stack/src/lib/config/index.ts","../../../projects/ngx-theme-stack/src/lib/core/core-theme.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-cycle.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-select.service.ts","../../../projects/ngx-theme-stack/src/lib/services/theme-toggle.service.ts","../../../projects/ngx-theme-stack/src/public-api.ts","../../../projects/ngx-theme-stack/src/ngx-theme-stack.ts"],"sourcesContent":["/**\n * Base error class for `ngx-theme-stack`.\n *\n * Thrown when the library configuration is invalid.\n * Consumers can use `instanceof NgxThemeStackError` to catch only\n * errors originating from this library.\n *\n * @example\n * try {\n * bootstrapApplication(AppComponent, appConfig);\n * } catch (e) {\n * if (e instanceof NgxThemeStackError) {\n * console.error('Bad ngx-theme-stack config:', e.message);\n * }\n * }\n */\nexport class NgxThemeStackError extends Error {\n override readonly name = 'NgxThemeStackError';\n\n constructor(message: string) {\n super(`[ngx-theme-stack] ${message}`);\n // Restore prototype chain (required when targeting ES5 or older)\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","/**\n * Runtime list of built-in themes.\n *\n * Lives here (and not in config/index.ts) because it defines a type:\n * config/index.ts already imports from types.ts, so placing DEFAULT_THEMES\n * here avoids any circular dependency.\n *\n * ⚠ KEEP IN SYNC with the duplicate in:\n * projects/ngx-theme-stack/schematics/ng-add/constants.ts → DEFAULT_THEMES\n *\n * Schematics compile to CommonJS and cannot import from this ESM file,\n * so the values are intentionally duplicated. Change both at the same time.\n */\nexport const DEFAULT_THEMES = ['system', 'light', 'dark'] as const;\n\n/** Literal union of built-in themes: `'system' | 'light' | 'dark'`. */\nexport type DefaultNgTheme = (typeof DEFAULT_THEMES)[number];\n\n/**\n * Theme type.\n *\n * - **Without** `T`: open union — accepts any `string` with IDE autocomplete\n * hints for the built-in themes (`'system' | 'light' | 'dark'`).\n * - **With** `T`: closed union — exactly `DefaultNgTheme | T`, enabling\n * full type-safety for custom theme sets.\n *\n * @example\n * NgTheme // 'system' | 'light' | 'dark' | (string & {})\n * NgTheme<'sepia'> // 'system' | 'light' | 'dark' | 'sepia'\n */\nexport type NgTheme<T extends string = string & {}> = DefaultNgTheme | T;\n\n/**\n * Resolved theme — always `'light'` or `'dark'`, never `'system'`.\n * Represents the value that comes from `matchMedia`, not user selection.\n */\nexport type NgSystemTheme = Exclude<DefaultNgTheme, 'system'>;\n\n/**\n * Theme application mode.\n * - `'attribute'`: sets `data-theme` attribute on `<html>`\n * - `'class'`: adds theme class to `<html>`\n * - `'both'`: uses both attribute and class\n */\nexport type NgMode = 'attribute' | 'class' | 'both';\n\n/**\n * Theme application strategy.\n * - `'blocking'`: theme CSS is loaded synchronously before rendering\n * - `'critters'`: theme CSS is inlined using Critters for SSR/SSG\n */\nexport type NgStrategy = 'blocking' | 'critters';\n\n/**\n * Library configuration.\n *\n * @typeParam T - Custom theme literals. Defaults to open `string`, preserving\n * backwards compatibility. Pass specific literals (e.g. `'sepia' | 'ocean'`)\n * via {@link provideThemeStack} to get a closed, type-safe theme union.\n */\nexport interface NgConfig<T extends string = string & {}> {\n /** The theme to use on first visit or when no preference is saved. Default: 'system'. */\n defaultTheme: NgTheme<T>;\n\n /** Key used to persist theme preference in localStorage. Default: 'ngx-theme-stack'. */\n storageKey: string;\n\n /** \n * How the theme should be applied to the document (via class, attribute or both). \n * Default: 'class'.\n */\n mode: NgMode;\n\n /** \n * Performance strategy for anti-flash.\n * Use 'critters' (default) to inline all theme CSS in <head> — works for CSR, SSR, and SSG.\n * Use 'blocking' to load themes.css as a render-blocking stylesheet (HTTP-cacheable).\n */\n strategy: NgStrategy;\n\n /** List of supported theme identifiers. Default: ['light', 'dark', 'system']. */\n themes: NgTheme<T>[];\n}\n","import { InjectionToken } from '@angular/core';\nimport { NgxThemeStackError } from '../errors';\nimport { DEFAULT_THEMES, DefaultNgTheme, NgConfig } from '../types';\n\n/**\n * ⚠ ATTENTION: SHARED CONFIGURATION VALUES\n *\n * These defaults MUST match the schematic defaults in:\n * projects/ngx-theme-stack/schematics/ng-add/constants.ts → DEFAULTS\n *\n * Schematics compile to CommonJS and cannot import from this ESM file,\n * so the values are intentionally duplicated. Change both at the same time.\n *\n * If you change defaults here, also update:\n * schematics/ng-add/constants.ts → DEFAULTS + DEFAULT_THEMES\n */\n\nexport const DEFAULT_NG_CONFIG = {\n defaultTheme: 'system',\n storageKey: 'ngx-theme-stack',\n mode: 'class',\n strategy: 'critters',\n themes: [...DEFAULT_THEMES],\n} satisfies NgConfig;\n\n// The token uses NgConfig<string> because Angular DI resolves types at runtime\n// and cannot carry generic parameters. Type-safety is enforced at the\n// provideThemeStack() call site instead.\nexport const NGX_THEME_STACK_CONFIG = new InjectionToken<NgConfig<string>>(\n 'NGX_THEME_STACK_CONFIG',\n {\n factory: () => DEFAULT_NG_CONFIG,\n },\n);\n\n/**\n * Provides Theme Stack configuration to Angular's DI system.\n *\n * Custom `themes` are **merged** with the built-in defaults\n * (`'light'`, `'dark'`, `'system'`), so you never lose the base themes.\n *\n * **Defaults:**\n * - `themes`: `['light', 'dark', 'system']`\n * - `defaultTheme`: `'system'`\n * - `storageKey`: `'ngx-theme-stack'`\n * - `mode`: `'class'`\n * - `strategy`: `'critters'`\n\n *\n * The type parameter `T` is **inferred automatically** from the `themes` array\n * when passed as a `const` — no need to specify it manually.\n *\n * @typeParam T - Custom theme string literals, inferred from the `themes` option.\n *\n * @param config - Optional partial configuration. Omitted fields fall back to\n * {@link DEFAULT_NG_CONFIG}.\n *\n * @throws {@link NgxThemeStackError}\n * - If any entry in `themes` is an empty or whitespace-only string.\n * - If `defaultTheme` is not present in the resolved (merged) themes array.\n * - If `storageKey` is an empty or whitespace-only string.\n *\n * @example\n * // Default — uses built-in themes and sensible defaults\n * provideThemeStack()\n *\n * @example\n * // Critters strategy — inlines all theme CSS in <head> (works for CSR, SSR, and SSG)\n * provideThemeStack({\n * strategy: 'critters',\n * mode: 'class',\n * })\n *\n * @example\n * // Closed union: TypeScript infers 'sepia' | 'ocean' from the array\n * provideThemeStack({\n * themes: ['sepia', 'ocean'] as const,\n * defaultTheme: 'sepia', // ✅ in resolved themes\n * // defaultTheme: 'nope', // ❌ throws NgxThemeStackError at runtime\n * })\n *\n * @example\n * // Custom storage key and mode\n * provideThemeStack({\n * storageKey: 'my-app-theme',\n * mode: 'attribute',\n * })\n */\nexport function provideThemeStack<const T extends string = DefaultNgTheme>(\n config: Partial<NgConfig<T>> = {},\n) {\n config.themes?.forEach((t) => {\n if (t.trim() === '') throw new NgxThemeStackError('Theme cannot be empty or whitespace.');\n });\n\n const themes = config.themes\n ? Array.from(new Set([...DEFAULT_NG_CONFIG.themes, ...config.themes]))\n : DEFAULT_NG_CONFIG.themes;\n\n if (config.defaultTheme && !(themes as string[]).includes(config.defaultTheme as string)) {\n throw new NgxThemeStackError(\n `\"defaultTheme\" must be one of the resolved themes: [${themes.join(', ')}].`,\n );\n }\n\n if (config.storageKey !== undefined && config.storageKey.trim() === '') {\n throw new NgxThemeStackError('\"storageKey\" cannot be empty or whitespace.');\n }\n\n return {\n provide: NGX_THEME_STACK_CONFIG,\n useValue: {\n ...DEFAULT_NG_CONFIG,\n ...config,\n themes,\n } as NgConfig<string>,\n };\n}\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n afterNextRender,\n computed,\n DestroyRef,\n DOCUMENT,\n effect,\n inject,\n Injectable,\n PLATFORM_ID,\n signal,\n} from '@angular/core';\nimport { NGX_THEME_STACK_CONFIG } from '../config';\nimport { NgxThemeStackError } from '../errors';\nimport { NgSystemTheme, NgTheme } from '../types';\n\n/**\n * Core service for managing the application's color theme.\n *\n * Handles theme persistence, system preference detection, and DOM updates.\n * Supports built-in themes ('dark', 'light', 'system') and custom extensions.\n */\n@Injectable({ providedIn: 'root' })\nexport class CoreThemeService {\n // ── Dependencies ──────────────────────────────────────────────────────────\n\n readonly #config = inject(NGX_THEME_STACK_CONFIG);\n readonly #destroyRef = inject(DestroyRef);\n readonly #document = inject(DOCUMENT);\n readonly #isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n // ── Theme configuration ───────────────────────────────────────────────────\n\n /** The initial stored theme read from localStorage on startup. */\n readonly #initialStoredTheme = this.readStoredTheme();\n\n /** List of available themes for Select/Cycle services. Defaults to ['system', 'light', 'dark']. */\n readonly availableThemes = this.#config.themes;\n\n /** Internal Set for O(1) existence checks. */\n readonly #validThemes = new Set<NgTheme>(this.availableThemes);\n\n /**\n * The anti-flash class to remove from the host element.\n * Internal mechanism to bridge the gap between the blocking script's\n * initial DOM state and Angular's first effect run.\n */\n #antiFlashClass: string | null = null;\n\n // ── System preference ─────────────────────────────────────────────────────\n\n /** MediaQueryList for OS color scheme, created once and reused. Null in SSR. */\n readonly #mediaQuery: MediaQueryList | null = this.#isBrowser\n ? (this.#document.defaultView?.matchMedia('(prefers-color-scheme: dark)') ?? null)\n : null;\n\n readonly #systemPreference = signal<NgSystemTheme>(this.resolveSystemPreference());\n\n // ── Theme state ───────────────────────────────────────────────────────────\n\n readonly #selectedTheme = signal<NgTheme>(this.resolveInitialTheme());\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#selectedTheme.asReadonly();\n\n /** Resolved theme applied to the DOM. Always `'dark'` or `'light'` (or custom) — never `'system'`. */\n readonly resolvedTheme = computed(() => {\n const theme = this.#selectedTheme();\n return theme === 'system' ? this.#systemPreference() : theme;\n });\n\n /** Whether the currently applied theme is dark. */\n readonly isDark = computed(() => this.resolvedTheme() === 'dark');\n\n /** Whether the currently applied theme is light. */\n readonly isLight = computed(() => this.resolvedTheme() === 'light');\n\n /** Whether the currently applied theme is system. */\n readonly isSystem = computed(() => this.selectedTheme() === 'system');\n\n /**\n * Whether the service has completed client-side initialization.\n *\n * `false` during SSR and on the very first render pass before the initial theme\n * is resolved from `localStorage`. Becomes `true` immediately after the\n * first browser render pass.\n *\n * **Important:** Guard template elements that display `selectedTheme()` or\n * `resolvedTheme()` behind this signal to prevent hydration-mismatch flashes\n * (e.g. if the server renders the default 'system' but the user has 'dark' stored).\n *\n * @example\n * ```html\n * {{ theme.isHydrated() ? theme.selectedTheme() : '...' }}\n * ```\n */\n readonly isHydrated = signal(false);\n\n // ── Event handler ─────────────────────────────────────────────────────────\n\n readonly #onSystemPreferenceChange = () =>\n this.#systemPreference.set(this.resolveSystemPreference());\n\n // ── Lifecycle ─────────────────────────────────────────────────────────────\n\n constructor() {\n this.captureAntiFlashClass();\n\n if (this.#isBrowser && this.#selectedTheme() === 'system') {\n this.startSystemThemeListener();\n }\n\n effect(() => this.applyThemeToDOM(this.resolvedTheme()));\n afterNextRender(() => this.isHydrated.set(true));\n this.#destroyRef.onDestroy(() => this.stopSystemThemeListener());\n }\n\n // ── Public API ────────────────────────────────────────────────────────────\n\n /**\n * Changes the active theme.\n *\n * Persists the choice explicitly so that switching e.g. from `'system'` to\n * `'light'` is saved even when the resolved theme did not change\n * (system preference was already `'light'`).\n *\n * @param theme - The theme to apply: `'dark'`, `'light'`, `'system'`, or a custom theme name.\n * @throws If `theme` is not a valid theme according to library configuration.\n */\n public setTheme(theme: NgTheme): void {\n if (!this.#validThemes.has(theme)) {\n throw new NgxThemeStackError(\n `Invalid theme: \"${theme}\". Valid values are: ${[...this.#validThemes].join(', ')}.`,\n );\n }\n if (!this.#isBrowser) return;\n if (theme === this.#selectedTheme()) return;\n if (theme === 'system') {\n this.#systemPreference.set(this.resolveSystemPreference());\n this.startSystemThemeListener();\n } else {\n this.stopSystemThemeListener();\n }\n\n this.#selectedTheme.set(theme);\n this.saveTheme(theme);\n }\n\n // ── Private ───────────────────────────────────────────────────────────────\n\n private resolveSystemPreference(): NgSystemTheme {\n return this.#mediaQuery?.matches ? 'dark' : 'light';\n }\n\n private resolveInitialTheme(): NgTheme {\n const theme = this.#initialStoredTheme;\n if (theme && this.#validThemes.has(theme as NgTheme)) {\n return theme as NgTheme;\n }\n return this.#config.defaultTheme;\n }\n\n private startSystemThemeListener(): void {\n if (!this.#mediaQuery) return;\n this.stopSystemThemeListener();\n this.#mediaQuery.addEventListener('change', this.#onSystemPreferenceChange);\n }\n\n private stopSystemThemeListener(): void {\n this.#mediaQuery?.removeEventListener('change', this.#onSystemPreferenceChange);\n }\n\n private applyThemeToDOM(theme: NgTheme): void {\n if (!this.#isBrowser) return;\n\n const host = this.#document.documentElement;\n\n if (this.#antiFlashClass) {\n host.classList.remove(this.#antiFlashClass);\n this.#antiFlashClass = null;\n }\n\n const { mode } = this.#config;\n\n if (mode === 'attribute' || mode === 'both') {\n this.applyThemeAttribute(host, theme);\n }\n\n if (mode === 'class' || mode === 'both') {\n this.applyThemeClasses(host, theme);\n }\n\n this.applyColorSchemeHint(host, theme);\n }\n\n private applyThemeAttribute(host: HTMLElement, theme: NgTheme): void {\n host.setAttribute('data-theme', theme);\n }\n\n private applyThemeClasses(host: HTMLElement, theme: NgTheme): void {\n host.classList.remove(...this.availableThemes);\n host.classList.add(theme);\n }\n\n private applyColorSchemeHint(host: HTMLElement, theme: NgTheme): void {\n if (theme === 'dark' || theme === 'light') {\n host.style.setProperty('color-scheme', theme);\n return;\n }\n\n host.style.removeProperty('color-scheme');\n }\n\n private captureAntiFlashClass(): void {\n if (!this.#isBrowser || !this.#initialStoredTheme) return;\n\n if (!/^[a-zA-Z][a-zA-Z0-9_-]*$/.test(this.#initialStoredTheme)) {\n this.#antiFlashClass = null;\n return;\n }\n\n if (this.#initialStoredTheme === 'system') {\n this.#antiFlashClass = this.resolveSystemPreference();\n return;\n }\n\n this.#antiFlashClass = this.#initialStoredTheme;\n }\n\n private readStoredTheme(): string | null {\n if (!this.#isBrowser) return null;\n\n try {\n return localStorage.getItem(this.#config.storageKey);\n } catch (e) {\n console.warn('[ngx-theme-stack] Could not read theme from localStorage.', e);\n return null;\n }\n }\n\n private saveTheme(theme: NgTheme): void {\n if (!this.#isBrowser) return;\n\n try {\n localStorage.setItem(this.#config.storageKey, theme);\n } catch (e) {\n console.warn('[ngx-theme-stack] Could not save theme to localStorage.', e);\n }\n }\n}\n","import { computed, inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\n\n/**\n * Convenience service for cycling through themes in a fixed order.\n *\n * Default cycle: `'system'` → `'light'` → `'dark'` → `'system'` → ...\n *\n * Use this when you want to offer users a single button that rotates\n * through all available theme options.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeCycleService {\n readonly #core = inject(CoreThemeService);\n\n /** List of all configured themes for cycling. Defaults to `['light', 'dark', 'system']`. */\n readonly availableThemes = this.#core.availableThemes;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** Index of the currently selected theme in the cycle. */\n readonly cycleIndex = computed(() => {\n return this.availableThemes.indexOf(this.selectedTheme());\n });\n\n /** The theme that comes before the currently selected theme in the cycle. */\n readonly preceding = computed(() => {\n const index = this.cycleIndex();\n const len = this.availableThemes.length;\n return this.availableThemes[(index - 1 + len) % len];\n });\n\n /** The theme that comes after the currently selected theme in the cycle. */\n readonly upcoming = computed(() => {\n const index = this.cycleIndex();\n return this.availableThemes[(index + 1) % this.availableThemes.length];\n });\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and\n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Advances to the next theme in the cycle.\n *\n * Cycle order is determined by the configured `themes` property in `NgConfig`.\n *\n * If the current theme is not found in the cycle (e.g. set externally),\n * the cycle restarts from the first theme.\n */\n cycle(): void {\n this.#core.setTheme(this.upcoming());\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\nimport { NgTheme } from '../types';\n\n/**\n * Convenience service for selecting a theme from a list.\n *\n * Use this when you want to bind a `<select>` or a group of radio/tab\n * buttons to the full set of available themes.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeSelectService {\n readonly #core = inject(CoreThemeService);\n\n /** List of all configured themes. Defaults to `['light', 'dark', 'system']`. */\n readonly availableThemes = this.#core.availableThemes;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and\n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Applies the given theme.\n *\n * @param theme - The theme to apply: `'dark'`, `'light'`, `'system'`, or custom.\n * @throws If `theme` is not a valid theme according to library configuration.\n */\n select(theme: NgTheme): void {\n this.#core.setTheme(theme);\n }\n}\n","import { inject, Injectable } from '@angular/core';\nimport { CoreThemeService } from '../core/core-theme.service';\n\n/**\n * Convenience service for toggling between `'dark'` and `'light'`.\n *\n * Use this when you only need a simple on/off switch and do not\n * need to manage `'system'` or cycle through themes.\n */\n@Injectable({ providedIn: 'root' })\nexport class ThemeToggleService {\n readonly #core = inject(CoreThemeService);\n\n /** Resolved theme currently applied to the DOM. Always concrete — never `'system'`. */\n readonly resolvedTheme = this.#core.resolvedTheme;\n\n /** The theme explicitly selected by the user. May be `'system'`. */\n readonly selectedTheme = this.#core.selectedTheme;\n\n /** Whether the currently applied theme is `'dark'`. */\n readonly isDark = this.#core.isDark;\n\n /** Whether the currently applied theme is `'light'`. */\n readonly isLight = this.#core.isLight;\n\n /** Whether the user has explicitly selected `'system'` preference. */\n readonly isSystem = this.#core.isSystem;\n\n /**\n * Whether the service has completed client-side initialization and\n * resolved the real persisted theme. Use to prevent hydration flashes.\n */\n readonly isHydrated = this.#core.isHydrated.asReadonly();\n\n /**\n * Toggles between `'dark'` and `'light'`.\n *\n * If the selected theme is explicitly `'dark'`, switches to `'light'`.\n * Otherwise (including `'system'`), switches to `'dark'`.\n */\n toggle(): void {\n const next = this.#core.resolvedTheme() === 'dark' ? 'light' : 'dark';\n this.#core.setTheme(next);\n }\n}\n","/*\n * Public API Surface of ngx-theme-stack\n */\n\nexport * from './lib/core/core-theme.service';\nexport * from './lib/config';\nexport * from './lib/services/theme-cycle.service';\nexport * from './lib/services/theme-select.service';\nexport * from './lib/services/theme-toggle.service';\nexport * from './lib/types';\nexport * from './lib/errors';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;;;;;;AAeG;AACG,MAAO,kBAAmB,SAAQ,KAAK,CAAA;IACzB,IAAI,GAAG,oBAAoB;AAE7C,IAAA,WAAA,CAAY,OAAe,EAAA;AACzB,QAAA,KAAK,CAAC,CAAA,kBAAA,EAAqB,OAAO,CAAA,CAAE,CAAC;;QAErC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;IACnD;AACD;;ACxBD;;;;;;;;;;;;AAYG;AACI,MAAM,cAAc,G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"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngx-theme-stack",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "A stack of themes for Angular applications.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"angular",
|
|
7
|
+
"theme",
|
|
8
|
+
"dark-mode",
|
|
9
|
+
"light-mode",
|
|
10
|
+
"theming",
|
|
11
|
+
"angular-library",
|
|
12
|
+
"css-variables",
|
|
13
|
+
"tailwindcss"
|
|
14
|
+
],
|
|
15
|
+
"author": "WanderleeDev",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/WanderleeDev/ngx-theme-stack.git"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/WanderleeDev/ngx-theme-stack/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://ngx-theme-stack-docs.wanderlee.site/",
|
|
5
24
|
"schematics": "./schematics/collection.json",
|
|
6
25
|
"ng-add": {
|
|
7
26
|
"save": "devDependencies"
|
|
@@ -26,4 +45,4 @@
|
|
|
26
45
|
"default": "./fesm2022/ngx-theme-stack.mjs"
|
|
27
46
|
}
|
|
28
47
|
}
|
|
29
|
-
}
|
|
48
|
+
}
|
|
@@ -24,12 +24,15 @@ function patchAppConfig(tree, context, projectSourceRoot, provideCall, projectNa
|
|
|
24
24
|
var _a, _b;
|
|
25
25
|
const mainPath = `${projectSourceRoot}/main.ts`.replace(/^\//, '');
|
|
26
26
|
const appConfigPath = `${projectSourceRoot}/app/app.config.ts`.replace(/^\//, '');
|
|
27
|
-
|
|
27
|
+
let startFile = null;
|
|
28
|
+
if (tree.exists(appConfigPath))
|
|
29
|
+
startFile = appConfigPath;
|
|
30
|
+
else if (tree.exists(mainPath))
|
|
31
|
+
startFile = mainPath;
|
|
28
32
|
if (!startFile) {
|
|
29
33
|
context.logger.warn('⚠ Could not find app.config.ts or main.ts. Please add provideThemeStack() manually.');
|
|
30
34
|
return;
|
|
31
35
|
}
|
|
32
|
-
// Check if already present to decide between "Inject" or "Update"
|
|
33
36
|
const content = ((_a = tree.read(startFile)) === null || _a === void 0 ? void 0 : _a.toString()) || '';
|
|
34
37
|
const alreadyHasProvider = content.includes('provideThemeStack');
|
|
35
38
|
// ── Strategy 1: Standard addRootProvider (Only if NOT already present) ─────
|
|
@@ -37,7 +40,6 @@ function patchAppConfig(tree, context, projectSourceRoot, provideCall, projectNa
|
|
|
37
40
|
try {
|
|
38
41
|
const rule = (0, utility_1.addRootProvider)(projectName, ({ code, external }) => code `${external('provideThemeStack', 'ngx-theme-stack')}(${provideCall.replace(/^provideThemeStack\(/, '').replace(/\)$/, '')})`);
|
|
39
42
|
yield Promise.resolve(rule(tree, context));
|
|
40
|
-
// Re-read content to see if it worked
|
|
41
43
|
const updatedContent = ((_b = tree.read(startFile)) === null || _b === void 0 ? void 0 : _b.toString()) || '';
|
|
42
44
|
if (updatedContent.includes('provideThemeStack'))
|
|
43
45
|
return;
|
|
@@ -118,45 +120,36 @@ function applySmartPatch(tree_1, context_1, filePath_1, provideCall_1, targetIde
|
|
|
118
120
|
return false;
|
|
119
121
|
});
|
|
120
122
|
}
|
|
121
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Generic depth-first walker. Returns the first value for which `match` returns
|
|
125
|
+
* a non-null result, or null if the whole tree is exhausted.
|
|
126
|
+
*/
|
|
127
|
+
function walkFirst(root, match) {
|
|
122
128
|
let result = null;
|
|
123
129
|
function visit(n) {
|
|
124
|
-
if (
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
130
|
+
if (result !== null)
|
|
131
|
+
return;
|
|
132
|
+
result = match(n);
|
|
133
|
+
if (result === null)
|
|
128
134
|
ts.forEachChild(n, visit);
|
|
129
135
|
}
|
|
130
|
-
visit(
|
|
136
|
+
visit(root);
|
|
131
137
|
return result;
|
|
132
138
|
}
|
|
139
|
+
function findProvideThemeStackCall(node) {
|
|
140
|
+
return walkFirst(node, (n) => ts.isCallExpression(n) && ts.isIdentifier(n.expression) && n.expression.text === 'provideThemeStack'
|
|
141
|
+
? n
|
|
142
|
+
: null);
|
|
143
|
+
}
|
|
133
144
|
function findProvidersArrayLiteral(node) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
if (ts.isArrayLiteralExpression(n.initializer)) {
|
|
138
|
-
result = n.initializer;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (!result)
|
|
142
|
-
ts.forEachChild(n, visit);
|
|
143
|
-
}
|
|
144
|
-
visit(node);
|
|
145
|
-
return result;
|
|
145
|
+
return walkFirst(node, (n) => ts.isPropertyAssignment(n) && ts.isIdentifier(n.name) && n.name.text === 'providers' && ts.isArrayLiteralExpression(n.initializer)
|
|
146
|
+
? n.initializer
|
|
147
|
+
: null);
|
|
146
148
|
}
|
|
147
149
|
function findProvidersIdentifier(node) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (ts.isIdentifier(n.initializer)) {
|
|
152
|
-
result = n.initializer.text;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
if (!result)
|
|
156
|
-
ts.forEachChild(n, visit);
|
|
157
|
-
}
|
|
158
|
-
visit(node);
|
|
159
|
-
return result;
|
|
150
|
+
return walkFirst(node, (n) => ts.isPropertyAssignment(n) && ts.isIdentifier(n.name) && n.name.text === 'providers' && ts.isIdentifier(n.initializer)
|
|
151
|
+
? n.initializer.text
|
|
152
|
+
: null);
|
|
160
153
|
}
|
|
161
154
|
function findImportPathForIdentifier(sourceFile, identifier) {
|
|
162
155
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-config.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/ng-add/app-config.ts"],"names":[],"mappings":";;;;;;;;;;;AAWA,
|
|
1
|
+
{"version":3,"file":"app-config.js","sourceRoot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
const app_config_1 = require("./app-config");
|
|
16
16
|
const constants_1 = require("./constants");
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
|
-
/**
|
|
19
|
-
* Interactively prompts the user for custom configuration options.
|
|
20
|
-
*/
|
|
21
18
|
function collectCustomOptions() {
|
|
22
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
20
|
const rl = (0, utils_1.createRl)();
|
|
@@ -25,7 +22,10 @@ function collectCustomOptions() {
|
|
|
25
22
|
process.stdout.write('\n');
|
|
26
23
|
const rawThemes = yield (0, utils_1.ask)(rl, ' Custom themes (comma-separated, Enter to skip): ');
|
|
27
24
|
const customThemes = rawThemes
|
|
28
|
-
? rawThemes
|
|
25
|
+
? rawThemes
|
|
26
|
+
.split(',')
|
|
27
|
+
.map((t) => t.trim())
|
|
28
|
+
.filter(Boolean)
|
|
29
29
|
: [];
|
|
30
30
|
const themes = [...constants_1.DEFAULT_THEMES, ...customThemes];
|
|
31
31
|
const defaultTheme = yield (0, utils_1.askList)(rl, 'Default theme:', themes, 0);
|
|
@@ -35,8 +35,11 @@ function collectCustomOptions() {
|
|
|
35
35
|
const mode = yield (0, utils_1.askList)(rl, 'How to apply theme on <html>:', MODES, 0);
|
|
36
36
|
const STRATEGIES = ['critters', 'blocking'];
|
|
37
37
|
process.stdout.write('\n Anti-flash strategy:\n');
|
|
38
|
-
process.stdout.write(' - critters:
|
|
39
|
-
process.stdout.write('
|
|
38
|
+
process.stdout.write(' - critters (default): Inlines all theme CSS in <head> — zero network requests.\n');
|
|
39
|
+
process.stdout.write(' Works for CSR, SSR, and SSG apps.\n');
|
|
40
|
+
process.stdout.write(' Use blocking instead if you have a strict CSP or many themes.\n');
|
|
41
|
+
process.stdout.write(' - blocking: Loads themes.css as a render-blocking stylesheet.\n');
|
|
42
|
+
process.stdout.write(' HTTP-cacheable. Choose if Critters conflicts with your setup.\n');
|
|
40
43
|
const strategy = (yield (0, utils_1.askList)(rl, 'Choose strategy:', STRATEGIES, 0));
|
|
41
44
|
const provideCall = (0, utils_1.buildProvideCall)(defaultTheme, storageKey, mode, themes, strategy);
|
|
42
45
|
process.stdout.write('\n');
|
|
@@ -47,9 +50,6 @@ function collectCustomOptions() {
|
|
|
47
50
|
}
|
|
48
51
|
});
|
|
49
52
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Main schematic factory for the 'ng-add' command.
|
|
52
|
-
*/
|
|
53
53
|
function ngAdd(options) {
|
|
54
54
|
return (tree, context) => __awaiter(this, void 0, void 0, function* () {
|
|
55
55
|
const workspaceConfig = tree.read('/angular.json');
|
|
@@ -86,63 +86,67 @@ function ngAdd(options) {
|
|
|
86
86
|
}
|
|
87
87
|
const changeset = [];
|
|
88
88
|
const themesToScaffold = config.themes.filter((t) => t !== 'system');
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
89
|
+
// Computed once and shared across steps to avoid duplication
|
|
90
|
+
const themesPath = `${projectSourceRoot}/themes.css`.replace(/^\//, '');
|
|
91
|
+
function scaffoldThemesCss(t) {
|
|
92
|
+
if (t.exists(themesPath)) {
|
|
93
|
+
changeset.push(` \u001b[90mℹ\u001b[0m ${themesPath} (already exists)`);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
let content = '/* ngx-theme-stack tokens */\n\n';
|
|
97
|
+
themesToScaffold.forEach((theme) => {
|
|
98
|
+
const selector = config.mode === 'attribute' ? `[data-theme="${theme}"]` : `.${theme}`;
|
|
99
|
+
content +=
|
|
100
|
+
theme === 'light'
|
|
101
|
+
? `:root, ${selector} {\n /* Add your light theme variables here */\n}\n\n`
|
|
102
|
+
: `${selector} {\n /* Add your ${theme} theme variables here */\n}\n\n`;
|
|
103
|
+
});
|
|
104
|
+
t.create(themesPath, content);
|
|
105
|
+
changeset.push(` \u001b[36mA\u001b[0m ${themesPath} (theme tokens)`);
|
|
106
|
+
}
|
|
107
|
+
function patchPrebuildScript(t) {
|
|
108
|
+
const pkgPath = '/package.json';
|
|
109
|
+
const buffer = t.read(pkgPath);
|
|
110
|
+
if (!buffer)
|
|
111
|
+
return;
|
|
112
|
+
const pkg = JSON.parse(buffer.toString());
|
|
113
|
+
pkg.scripts = pkg.scripts || {};
|
|
114
|
+
const syncCmd = `ng generate ngx-theme-stack:sync --project ${projectName}`;
|
|
115
|
+
const existing = pkg.scripts.prebuild;
|
|
116
|
+
if (!existing) {
|
|
117
|
+
pkg.scripts.prebuild = syncCmd;
|
|
118
|
+
changeset.push(' \u001b[33mM\u001b[0m package.json (prebuild script added)');
|
|
119
|
+
}
|
|
120
|
+
else if (!existing.includes('ngx-theme-stack:sync')) {
|
|
121
|
+
pkg.scripts.prebuild = `${existing} && ${syncCmd}`;
|
|
122
|
+
changeset.push(' \u001b[33mM\u001b[0m package.json (sync appended to existing prebuild)');
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
changeset.push(' \u001b[90mℹ\u001b[0m package.json (prebuild already contains sync — skipped)');
|
|
126
|
+
}
|
|
127
|
+
t.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
|
|
128
|
+
}
|
|
129
|
+
function patchAngularJson(t) {
|
|
130
|
+
var _a;
|
|
131
|
+
const target = project.architect.build.options;
|
|
132
|
+
if (target.styles && !target.styles.includes(themesPath)) {
|
|
133
|
+
target.styles.unshift(themesPath);
|
|
134
|
+
}
|
|
135
|
+
const prodConfig = (_a = project.architect.build.configurations) === null || _a === void 0 ? void 0 : _a.production;
|
|
136
|
+
if (prodConfig && config.strategy === 'blocking') {
|
|
137
|
+
if (typeof prodConfig.optimization === 'object') {
|
|
138
|
+
prodConfig.optimization.styles = prodConfig.optimization.styles || {};
|
|
139
|
+
prodConfig.optimization.styles.inlineCritical = false;
|
|
106
140
|
}
|
|
107
141
|
else {
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
// 2. Add prebuild script to package.json
|
|
112
|
-
(t) => {
|
|
113
|
-
const pkgPath = '/package.json';
|
|
114
|
-
const buffer = t.read(pkgPath);
|
|
115
|
-
if (buffer) {
|
|
116
|
-
const pkg = JSON.parse(buffer.toString());
|
|
117
|
-
pkg.scripts = pkg.scripts || {};
|
|
118
|
-
pkg.scripts.prebuild = `ng generate ngx-theme-stack:sync --project ${projectName}`;
|
|
119
|
-
t.overwrite(pkgPath, JSON.stringify(pkg, null, 2));
|
|
120
|
-
changeset.push(' \u001b[33mM\u001b[0m package.json (prebuild script)');
|
|
121
|
-
}
|
|
122
|
-
},
|
|
123
|
-
// 3. Update angular.json (styles & optimization)
|
|
124
|
-
(t) => {
|
|
125
|
-
var _a;
|
|
126
|
-
const themesPath = `${projectSourceRoot}/themes.css`.replace(/^\//, '');
|
|
127
|
-
const target = project.architect.build.options;
|
|
128
|
-
if (target.styles && !target.styles.includes(themesPath)) {
|
|
129
|
-
target.styles.unshift(themesPath);
|
|
142
|
+
prodConfig.optimization = { styles: { inlineCritical: false } };
|
|
130
143
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
else {
|
|
138
|
-
prodConfig.optimization = { styles: { inlineCritical: false } };
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
t.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
|
|
142
|
-
changeset.push(' \u001b[33mM\u001b[0m angular.json (styles & optimization)');
|
|
143
|
-
},
|
|
144
|
-
// 4. Patch App Config and Index HTML
|
|
145
|
-
(t, ctx) => __awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
}
|
|
145
|
+
t.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
|
|
146
|
+
changeset.push(' \u001b[33mM\u001b[0m angular.json (styles & optimization)');
|
|
147
|
+
}
|
|
148
|
+
function patchProviderAndIndexHtml(t, ctx) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
146
150
|
yield (0, app_config_1.patchAppConfig)(t, ctx, projectSourceRoot, config.provideCall, projectName);
|
|
147
151
|
changeset.push(' \u001b[33mM\u001b[0m app.config.ts (provided theme stack)');
|
|
148
152
|
(0, anti_flash_1.patchIndexHtml)(t, ctx, projectSourceRoot, {
|
|
@@ -156,7 +160,13 @@ function ngAdd(options) {
|
|
|
156
160
|
ctx.logger.info('\n\u001b[1mChangeset:\u001b[0m');
|
|
157
161
|
changeset.forEach((entry) => ctx.logger.info(entry));
|
|
158
162
|
ctx.logger.info('\n\u001b[1m\u001b[32m🏁 Done.\u001b[0m\n');
|
|
159
|
-
})
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return (0, schematics_1.chain)([
|
|
166
|
+
scaffoldThemesCss,
|
|
167
|
+
patchPrebuildScript,
|
|
168
|
+
patchAngularJson,
|
|
169
|
+
patchProviderAndIndexHtml,
|
|
160
170
|
]);
|
|
161
171
|
});
|
|
162
172
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/ng-add/index.ts"],"names":[],"mappings":";;;;;;;;;;;AA2DA,sBAsIC;AAjMD,2DAAiF;AACjF,6CAA8C;AAC9C,6CAA8C;AAC9C,2CAAuD;AAEvD,mCAAmE;AAWnE,SAAe,oBAAoB;;QACjC,MAAM,EAAE,GAAG,IAAA,gBAAQ,GAAE,CAAC;QAEtB,IAAI,CAAC;YACH,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAE3B,MAAM,SAAS,GAAG,MAAM,IAAA,WAAG,EAAC,EAAE,EAAE,oDAAoD,CAAC,CAAC;YAC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AAS,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;QAC/E,CAAC;QAED,SAAe,yBAAyB,CAAC,CAAO,EAAE,GAAqB;;gBACrE,MAAM,IAAA,2BAAc,EAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;gBACjF,SAAS,CAAC,IAAI,CAAC,4DAA4D,CAAC,CAAC;gBAE7E,IAAA,2BAAc,EAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE;oBACxC,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;oBACjC,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;iBAC1B,CAAC,CAAC;gBACH,SAAS,CAAC,IAAI,CAAC,wDAAwD,CAAC,CAAC;gBAEzE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,gCAAgC,CAAC,CAAC;gBAClD,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;gBACrD,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,0CAA0C,CAAC,CAAC;YAC9D,CAAC;SAAA;QAED,OAAO,IAAA,kBAAK,EAAC;YACX,iBAAiB;YACjB,mBAAmB;YACnB,gBAAgB;YAChB,yBAAyB;SAC1B,CAAC,CAAC;IACL,CAAC,CAAA,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/ng-add/utils.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/ng-add/utils.ts"],"names":[],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;CAAA;AAED,SAAgB,gBAAgB,CAC9B,YAAoB,EACpB,UAAkB,EAClB,IAAY,EACZ,MAAgB,EAChB,QAAgB;IAEhB,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,OAAO;QACL,qBAAqB;QACrB,kBAAkB,SAAS,IAAI;QAC/B,wBAAwB,YAAY,IAAI;QACxC,sBAAsB,UAAU,IAAI;QACpC,gBAAgB,IAAI,IAAI;QACxB,oBAAoB,QAAQ,IAAI;QAChC,QAAQ;KACT,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC"}
|
package/schematics/sync/index.js
CHANGED
|
@@ -33,6 +33,7 @@ const OPTION_MODE_RE = /mode\s*:\s*['"]([^'"]+)['"]/;
|
|
|
33
33
|
const OPTION_KEY_RE = /storageKey\s*:\s*['"]([^'"]+)['"]/;
|
|
34
34
|
/** Extracts "defaultTheme" value from the captured options string. */
|
|
35
35
|
const OPTION_DEFAULT_THEME_RE = /defaultTheme\s*:\s*['"]([^'"]+)['"]/;
|
|
36
|
+
/** Extracts "strategy" value from the captured options string. */
|
|
36
37
|
const OPTION_STRATEGY_RE = /strategy\s*:\s*['"]([^'"]+)['"]/;
|
|
37
38
|
/**
|
|
38
39
|
* Extracts the themes array from the options string.
|
|
@@ -72,7 +73,6 @@ function extractConfig(tree, sourceRoot, context) {
|
|
|
72
73
|
const storageKey = (_d = (_c = OPTION_KEY_RE.exec(opts)) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : constants_1.DEFAULTS.storageKey;
|
|
73
74
|
const defaultTheme = (_f = (_e = OPTION_DEFAULT_THEME_RE.exec(opts)) === null || _e === void 0 ? void 0 : _e[1]) !== null && _f !== void 0 ? _f : constants_1.DEFAULTS.defaultTheme;
|
|
74
75
|
const strategy = (_h = (_g = OPTION_STRATEGY_RE.exec(opts)) === null || _g === void 0 ? void 0 : _g[1]) !== null && _h !== void 0 ? _h : undefined;
|
|
75
|
-
// Extract themes array: ['light', 'dark', 'sunset'] → ['light', 'dark', 'sunset']
|
|
76
76
|
const themesRaw = (_k = (_j = OPTION_THEMES_RE.exec(opts)) === null || _j === void 0 ? void 0 : _j[1]) !== null && _k !== void 0 ? _k : '';
|
|
77
77
|
const themes = themesRaw
|
|
78
78
|
? themesRaw
|
|
@@ -134,16 +134,14 @@ function buildCrittersDivs(themes, mode) {
|
|
|
134
134
|
return ` <div data-theme="${theme}"></div>`;
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
137
|
-
// 'both'
|
|
138
137
|
return ` <div class="${theme}" data-theme="${theme}"></div>`;
|
|
139
138
|
}
|
|
140
139
|
})
|
|
141
140
|
.join('\n');
|
|
142
141
|
return (`<!-- ngx-theme-stack critters-trick -->\n` +
|
|
143
|
-
` <div id="ngx-theme-stack-critters-trick" hidden>\n${divs}\n </div>\n` +
|
|
142
|
+
` <div id="ngx-theme-stack-critters-trick" hidden aria-hidden="true" style="display: none; overflow: hidden; clip-path: inset(50%); position: absolute;">\n${divs}\n </div>\n` +
|
|
144
143
|
` <!-- /ngx-theme-stack critters-trick -->`);
|
|
145
144
|
}
|
|
146
|
-
// ── index.html patching ───────────────────────────────────────────────────────
|
|
147
145
|
// ── Schematic factory ─────────────────────────────────────────────────────────
|
|
148
146
|
/**
|
|
149
147
|
* `ng generate ngx-theme-stack:sync`
|
|
@@ -155,25 +153,14 @@ function buildCrittersDivs(themes, mode) {
|
|
|
155
153
|
* `defaultTheme`, and `mode` in sync with the Angular provider.
|
|
156
154
|
*
|
|
157
155
|
* 2. **The Critters Trick divs** (if `strategy: 'critters'`) — hidden `<div>`
|
|
158
|
-
* elements that trick Angular's built-in CSS inliner
|
|
159
|
-
*
|
|
160
|
-
* at build time. This achieves zero-flash without any extra network requests.
|
|
156
|
+
* elements that trick Angular's built-in CSS inliner into treating all theme
|
|
157
|
+
* token blocks as "critical CSS", inlining them in `<head>` at build time.
|
|
161
158
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* so it runs automatically before every build.
|
|
165
|
-
*
|
|
166
|
-
* @example
|
|
167
|
-
* // One-off sync
|
|
168
|
-
* ng generate ngx-theme-stack:sync
|
|
159
|
+
* Auto-detects the strategy from the existing `index.html` markers so the
|
|
160
|
+
* prebuild command runs with zero extra flags.
|
|
169
161
|
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* "prebuild": "ng generate ngx-theme-stack:sync"
|
|
173
|
-
*/
|
|
174
|
-
/**
|
|
175
|
-
* Auto-detects the strategy by checking if a Critters marker exists in index.html.
|
|
176
|
-
* This allows the prebuild command to run with zero extra flags.
|
|
162
|
+
* Run this whenever you change `mode`, `storageKey`, `defaultTheme`, or `themes`
|
|
163
|
+
* inside `provideThemeStack()`. Tip: add it as a `prebuild` script in package.json.
|
|
177
164
|
*/
|
|
178
165
|
function detectStrategy(tree, sourceRoot, explicitStrategy) {
|
|
179
166
|
if (explicitStrategy)
|
|
@@ -271,34 +258,29 @@ function sync(options) {
|
|
|
271
258
|
}
|
|
272
259
|
}
|
|
273
260
|
// ── 2. angular.json ──
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (typeof prodConfig.optimization === 'object') {
|
|
283
|
-
prodConfig.optimization.styles = prodConfig.optimization.styles || {};
|
|
284
|
-
if (prodConfig.optimization.styles.inlineCritical !== false) {
|
|
285
|
-
prodConfig.optimization.styles.inlineCritical = false;
|
|
286
|
-
changed = true;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else {
|
|
290
|
-
prodConfig.optimization = { styles: { inlineCritical: false } };
|
|
261
|
+
const prodConfig = (_e = (_d = (_c = project.architect) === null || _c === void 0 ? void 0 : _c.build) === null || _d === void 0 ? void 0 : _d.configurations) === null || _e === void 0 ? void 0 : _e.production;
|
|
262
|
+
if (prodConfig) {
|
|
263
|
+
let changed = false;
|
|
264
|
+
if (strategy === 'blocking') {
|
|
265
|
+
if (typeof prodConfig.optimization === 'object') {
|
|
266
|
+
prodConfig.optimization.styles = prodConfig.optimization.styles || {};
|
|
267
|
+
if (prodConfig.optimization.styles.inlineCritical !== false) {
|
|
268
|
+
prodConfig.optimization.styles.inlineCritical = false;
|
|
291
269
|
changed = true;
|
|
292
270
|
}
|
|
293
271
|
}
|
|
294
|
-
else
|
|
295
|
-
prodConfig.optimization
|
|
272
|
+
else {
|
|
273
|
+
prodConfig.optimization = { styles: { inlineCritical: false } };
|
|
296
274
|
changed = true;
|
|
297
275
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
276
|
+
}
|
|
277
|
+
else if (typeof prodConfig.optimization === 'object' && ((_f = prodConfig.optimization.styles) === null || _f === void 0 ? void 0 : _f.inlineCritical) === false) {
|
|
278
|
+
prodConfig.optimization.styles.inlineCritical = true;
|
|
279
|
+
changed = true;
|
|
280
|
+
}
|
|
281
|
+
if (changed) {
|
|
282
|
+
tree.overwrite('/angular.json', JSON.stringify(workspace, null, 2));
|
|
283
|
+
changeset.push(' \u001b[33mM\u001b[0m angular.json (optimization synced)');
|
|
302
284
|
}
|
|
303
285
|
}
|
|
304
286
|
context.logger.info('\u001b[1mChangeset:\u001b[0m');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/sync/index.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../projects/ngx-theme-stack/schematics/sync/index.ts"],"names":[],"mappings":";;;;;;;;;;;AA4NA,oBA8HC;AAzVD,qDAAsD;AACtD,2CAAmD;AACnD,mDAA+C;AAG/C,iFAAiF;AAEjF;;;;;;;;;;;GAWG;AACH,MAAM,eAAe,G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C,CAAC;QAC/C,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACxB,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QAC5D,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC,CAAA,CAAC;AACJ,CAAC"}
|
|
@@ -59,7 +59,7 @@ type NgStrategy = 'blocking' | 'critters';
|
|
|
59
59
|
interface NgConfig<T extends string = string & {}> {
|
|
60
60
|
/** The theme to use on first visit or when no preference is saved. Default: 'system'. */
|
|
61
61
|
defaultTheme: NgTheme<T>;
|
|
62
|
-
/** Key used to persist theme preference in localStorage. Default: 'ngx-theme-stack
|
|
62
|
+
/** Key used to persist theme preference in localStorage. Default: 'ngx-theme-stack'. */
|
|
63
63
|
storageKey: string;
|
|
64
64
|
/**
|
|
65
65
|
* How the theme should be applied to the document (via class, attribute or both).
|
|
@@ -68,8 +68,8 @@ interface NgConfig<T extends string = string & {}> {
|
|
|
68
68
|
mode: NgMode;
|
|
69
69
|
/**
|
|
70
70
|
* Performance strategy for anti-flash.
|
|
71
|
-
* Use 'critters'
|
|
72
|
-
*
|
|
71
|
+
* Use 'critters' (default) to inline all theme CSS in <head> — works for CSR, SSR, and SSG.
|
|
72
|
+
* Use 'blocking' to load themes.css as a render-blocking stylesheet (HTTP-cacheable).
|
|
73
73
|
*/
|
|
74
74
|
strategy: NgStrategy;
|
|
75
75
|
/** List of supported theme identifiers. Default: ['light', 'dark', 'system']. */
|
|
@@ -192,7 +192,7 @@ declare const NGX_THEME_STACK_CONFIG: InjectionToken<NgConfig<string>>;
|
|
|
192
192
|
* provideThemeStack()
|
|
193
193
|
*
|
|
194
194
|
* @example
|
|
195
|
-
* //
|
|
195
|
+
* // Critters strategy — inlines all theme CSS in <head> (works for CSR, SSR, and SSG)
|
|
196
196
|
* provideThemeStack({
|
|
197
197
|
* strategy: 'critters',
|
|
198
198
|
* mode: 'class',
|