@su-labs/theme 22.2.0 → 22.3.1

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/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [22.3.1] - 2026-11-16
11
+
12
+ ### Changed
13
+ - Uses `@su-labs/core` 1.9.0 (was 1.6.0), the same version as every other `@su-labs` package, so apps using several of them install core once
14
+
15
+ ## [22.3.0] - 2026-11-11
16
+
17
+ ### Added
18
+ - Ready-made palettes as optional themes: list them in the new `palettes` option (none by default), e.g. `palettes: ['solar', 'neon']`; `SU_THEME_PALETTES`, `SU_PALETTE_NAMES` and their types are re-exported from `@su-labs/core/theme`
19
+ - `availableThemes()` and `isAvailable()` on `SuThemeService`
20
+ - A `data-theme-scheme` attribute (`light` or `dark`) beside `data-theme`
21
+
22
+ ### Changed
23
+ - Requires `@su-labs/core` 1.6.0 exactly
24
+
10
25
  ## [22.2.0] - 2026-11-07
11
26
 
12
27
  ### Added
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  A robust and reactive Angular service for managing application themes. It provides a full-featured solution that supports dynamic switching, user preference persistence, and automatic system theme detection.
15
15
 
16
- > **Not using Angular?** The same theme logic is available for React, Svelte, vanilla JavaScript and Node in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
16
+ > **Not using Angular?** The same theme logic is available for React, Vue, Svelte, vanilla JavaScript and Node in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
17
17
 
18
18
  ## Table of Contents
19
19
 
@@ -63,6 +63,38 @@ The service currently supports the following theme names by default:
63
63
 
64
64
  You can provide custom variables for any of these themes via the `themes` property in `SuThemeConfig`.
65
65
 
66
+ ### Ready-made palettes (optional)
67
+
68
+ Eleven palettes ship with the library, none of them shown unless you list them in `palettes`:
69
+
70
+ | Name | Scheme | Look |
71
+ |------|--------|------|
72
+ | `sunset` | dark | Midnight blue, cream and amber |
73
+ | `candy` | dark | Near black, white and pink |
74
+ | `copper` | dark | Black, teal and copper |
75
+ | `solar` | light | Porcelain, midnight navy and solar orange |
76
+ | `neon` | dark | Graphite, silver mist and hyper pink |
77
+ | `sunflower` | dark | Midnight navy, powder blue and sunflower yellow |
78
+ | `tomato` | light | Oat milk, forest green and tomato red |
79
+ | `blossom` | light | Butter cream, forest green and hot pink |
80
+ | `ember` | dark | Midnight black, electric blue and sunset orange |
81
+ | `storm` | dark | Storm grey, near black and safety orange |
82
+ | `racing` | light | Polar white, glacier blue and racing red |
83
+
84
+ ```typescript
85
+ theme.init({ palettes: ['solar', 'neon', 'racing'] });
86
+ theme.setTheme('neon');
87
+ theme.availableThemes(); // ['light', 'dark', 'contrast', 'custom', 'system', 'solar', 'neon', 'racing']
88
+ ```
89
+
90
+ Each palette sets `--su-theme-color`, `--su-theme-background`, `--su-theme-main-accent`, `--su-theme-second-accent`
91
+ and `--su-theme-button-text` (text on the accent). Text is at least 7:1 on the background and button text at least
92
+ 4.5:1 on the accent. Besides `data-theme`, the element gets `data-theme-scheme="light"` or `"dark"`, so your own
93
+ colours can follow: `[data-theme-scheme='dark'] { --shadow: none; }`.
94
+
95
+ A saved palette your site doesn't list falls back to `defaultTheme` without overwriting the saved choice, so sites
96
+ that share one saved theme (see `storage`) can offer different sets.
97
+
66
98
  ## Installation
67
99
 
68
100
  You can install this library via npm:
@@ -71,6 +103,8 @@ You can install this library via npm:
71
103
  npm install @su-labs/theme
72
104
  ```
73
105
 
106
+ On Angular 19 or 20, install the matching version: `npm install @su-labs/theme@ng19` or `npm install @su-labs/theme@ng20`.
107
+
74
108
  ## Peer Dependencies
75
109
 
76
110
  This library requires the following peer dependencies:
@@ -213,11 +247,14 @@ This correctly shows how to use your service's public API to switch between them
213
247
  | `init(config?)` | `SuThemeConfig` | Initialize with custom configuration |
214
248
  | `setTheme(theme, persist?)` | `SuThemeName, boolean` | Change theme (persist defaults to true) |
215
249
  | `getTheme()` | - | Returns current theme name |
250
+ | `availableThemes()` | - | The base themes, then the palettes listed in `palettes` |
251
+ | `isAvailable(theme)` | `string` | Whether a theme can be set here |
216
252
 
217
253
  ### Types
218
254
 
219
255
  ```typescript
220
- type SuThemeName = 'light' | 'dark' | 'contrast' | 'custom' | 'system';
256
+ type SuBaseThemeName = 'light' | 'dark' | 'contrast' | 'custom' | 'system';
257
+ type SuThemeName = SuBaseThemeName | SuPaletteName; // SuPaletteName: 'sunset' | 'candy' | … | 'racing'
221
258
 
222
259
  interface SuThemeConfig {
223
260
  storageKey?: string; // Default: 'su:theme'
@@ -228,6 +265,7 @@ interface SuThemeConfig {
228
265
  themes?: {
229
266
  [key in SuThemeName]?: Record<string, string>;
230
267
  };
268
+ palettes?: SuPaletteName[]; // Default: none
231
269
  }
232
270
  ```
233
271
 
@@ -243,6 +281,7 @@ The service can be configured to fit your application's needs.
243
281
  | `cssVarPrefix` | The prefix for all CSS variables managed by the service. | `'--su-theme-'` |
244
282
  | `defaultTheme` | The theme to use if no preference is saved in `localStorage`. | `'system'` |
245
283
  | `themes` | An object with custom CSS variable overrides for each theme. | `undefined` |
284
+ | `palettes` | Ready-made palettes this site offers as themes, e.g. `['solar', 'neon']`. | none |
246
285
 
247
286
  ## Browser Compatibility
248
287
 
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { Injectable, signal } from "@angular/core";
3
- import { SuThemeController } from "@su-labs/core/theme";
3
+ import { SU_BASE_THEME_NAMES, SU_PALETTE_NAMES, SU_THEME_PALETTES, SuThemeController, isSuBaseThemeName } from "@su-labs/core/theme";
4
4
  var SuThemeService = class SuThemeService {
5
5
  controller = new SuThemeController();
6
6
  currentThemeSignal = signal(this.controller.getTheme(), ...ngDevMode ? [{ debugName: "currentThemeSignal" }] : /* istanbul ignore next */ []);
@@ -15,6 +15,12 @@ var SuThemeService = class SuThemeService {
15
15
  getUserPreference() {
16
16
  return this.controller.getUserPreference();
17
17
  }
18
+ availableThemes() {
19
+ return this.controller.availableThemes();
20
+ }
21
+ isAvailable(theme) {
22
+ return this.controller.isAvailable(theme);
23
+ }
18
24
  setTheme(theme, persist = true) {
19
25
  this.controller.setTheme(theme, persist);
20
26
  }
@@ -48,6 +54,6 @@ i0.ɵɵngDeclareClassMetadata({
48
54
  args: [{ providedIn: "root" }]
49
55
  }]
50
56
  });
51
- export { SuThemeService };
57
+ export { SU_BASE_THEME_NAMES, SU_PALETTE_NAMES, SU_THEME_PALETTES, SuThemeService, isSuBaseThemeName };
52
58
 
53
59
  //# sourceMappingURL=su-labs-theme.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"su-labs-theme.mjs","names":[],"sources":["../../../../projects/su-labs/theme/src/lib/theme.service.ts"],"sourcesContent":["import { Injectable, OnDestroy, signal } from '@angular/core';\nimport { SuThemeConfig, SuThemeController, SuThemeName } from '@su-labs/core/theme';\n\n/**\n * Angular service for managing application themes.\n *\n * Thin wrapper around the framework-agnostic `SuThemeController` from `@su-labs/core/theme`\n * that exposes the resolved theme as an Angular signal.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SuThemeService implements OnDestroy {\n /** Framework-agnostic theme logic */\n private readonly controller = new SuThemeController();\n\n /** Current resolved theme signal, kept in sync with the controller */\n private readonly currentThemeSignal = signal<SuThemeName>(this.controller.getTheme());\n\n /** Read-only access to the resolved theme signal */\n readonly theme = this.currentThemeSignal.asReadonly();\n\n /** Stops syncing the controller's theme into the signal */\n private readonly unsubscribe = this.controller.theme.subscribe((theme) => this.currentThemeSignal.set(theme));\n\n /**\n * Initialize the service with optional configuration.\n * Should be called from an app initializer for default setup.\n * @param config Optional configuration object.\n */\n public init(config?: SuThemeConfig): void {\n this.controller.init(config);\n }\n\n /**\n * Get the currently active, resolved theme.\n * @returns The resolved theme name ('light', 'dark', 'contrast', 'custom').\n */\n public getTheme(): SuThemeName {\n return this.currentThemeSignal();\n }\n\n /**\n * Get the user's theme preference (may be 'system').\n * @returns The user preference ('light', 'dark', 'contrast', 'custom', 'system').\n */\n public getUserPreference(): SuThemeName {\n return this.controller.getUserPreference();\n }\n\n /**\n * Set a new theme.\n * @param theme The theme to set ('light', 'dark', 'contrast', 'custom', 'system').\n * @param persist Whether to store the preference in localStorage (default: true).\n */\n public setTheme(theme: SuThemeName, persist: boolean = true): void {\n this.controller.setTheme(theme, persist);\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n this.controller.destroy();\n }\n}\n"],"mappings":";;;AAYA,IAAa,iBAAb,MAAa,eAAc;CAER,aAAa,IAAI,kBAAiB;CAGlC,qBAAqB,OAAoB,KAAK,WAAW,SAAQ,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,qBAAA,CAAA,+BAAA,CAAA,CAAA;CAG5E,QAAQ,KAAK,mBAAmB,WAAU;CAGlC,cAAc,KAAK,WAAW,MAAM,WAAW,UAAU,KAAK,mBAAmB,IAAI,KAAK,CAAC;CAOrG,KAAK,QAAsB;EAChC,KAAK,WAAW,KAAK,MAAM;CAC7B;CAMO,WAAQ;EACb,OAAO,KAAK,mBAAkB;CAChC;CAMO,oBAAiB;EACtB,OAAO,KAAK,WAAW,kBAAiB;CAC1C;CAOO,SAAS,OAAoB,UAAmB,MAAI;EACzD,KAAK,WAAW,SAAS,OAAO,OAAO;CACzC;CAGA,cAAW;EACT,KAAK,YAAW;EAChB,KAAK,WAAW,QAAO;CACzB;CAnDW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAc,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAd,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAc,YAFb;CAAM,CAAA;;AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAc,YAAA,CAAA;EAH1B,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA"}
1
+ {"version":3,"file":"su-labs-theme.mjs","names":[],"sources":["../../../../projects/su-labs/theme/src/lib/theme.service.ts"],"sourcesContent":["import { Injectable, OnDestroy, signal } from '@angular/core';\nimport { SuThemeConfig, SuThemeController, SuThemeName } from '@su-labs/core/theme';\n\n/**\n * Angular service for managing application themes.\n *\n * Thin wrapper around the framework-agnostic `SuThemeController` from `@su-labs/core/theme`\n * that exposes the resolved theme as an Angular signal.\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class SuThemeService implements OnDestroy {\n /** Framework-agnostic theme logic */\n private readonly controller = new SuThemeController();\n\n /** Current resolved theme signal, kept in sync with the controller */\n private readonly currentThemeSignal = signal<SuThemeName>(this.controller.getTheme());\n\n /** Read-only access to the resolved theme signal */\n readonly theme = this.currentThemeSignal.asReadonly();\n\n /** Stops syncing the controller's theme into the signal */\n private readonly unsubscribe = this.controller.theme.subscribe((theme) => this.currentThemeSignal.set(theme));\n\n /**\n * Initialize the service with optional configuration.\n * Should be called from an app initializer for default setup.\n * @param config Optional configuration object.\n */\n public init(config?: SuThemeConfig): void {\n this.controller.init(config);\n }\n\n /**\n * Get the currently active, resolved theme.\n * @returns The resolved theme name ('light', 'dark', 'contrast', 'custom').\n */\n public getTheme(): SuThemeName {\n return this.currentThemeSignal();\n }\n\n /**\n * Get the user's theme preference (may be 'system').\n * @returns The user preference ('light', 'dark', 'contrast', 'custom', 'system').\n */\n public getUserPreference(): SuThemeName {\n return this.controller.getUserPreference();\n }\n\n /** The themes this site offers: the base themes, then the palettes listed in the config's `palettes` */\n public availableThemes(): SuThemeName[] {\n return this.controller.availableThemes();\n }\n\n /**\n * Whether a theme can be set here: a base theme, or a listed palette.\n * @param theme Any theme name.\n */\n public isAvailable(theme: string): theme is SuThemeName {\n return this.controller.isAvailable(theme);\n }\n\n /**\n * Set a new theme. A palette the config doesn't list is ignored.\n * @param theme The theme to set ('light', 'dark', 'contrast', 'custom', 'system', or a listed palette).\n * @param persist Whether to store the preference in localStorage (default: true).\n */\n public setTheme(theme: SuThemeName, persist: boolean = true): void {\n this.controller.setTheme(theme, persist);\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n this.controller.destroy();\n }\n}\n"],"mappings":";;;AAYA,IAAa,iBAAb,MAAa,eAAc;CAER,aAAa,IAAI,kBAAiB;CAGlC,qBAAqB,OAAoB,KAAK,WAAW,SAAQ,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,qBAAA,CAAA,+BAAA,CAAA,CAAA;CAG5E,QAAQ,KAAK,mBAAmB,WAAU;CAGlC,cAAc,KAAK,WAAW,MAAM,WAAW,UAAU,KAAK,mBAAmB,IAAI,KAAK,CAAC;CAOrG,KAAK,QAAsB;EAChC,KAAK,WAAW,KAAK,MAAM;CAC7B;CAMO,WAAQ;EACb,OAAO,KAAK,mBAAkB;CAChC;CAMO,oBAAiB;EACtB,OAAO,KAAK,WAAW,kBAAiB;CAC1C;CAGO,kBAAe;EACpB,OAAO,KAAK,WAAW,gBAAe;CACxC;CAMO,YAAY,OAAa;EAC9B,OAAO,KAAK,WAAW,YAAY,KAAK;CAC1C;CAOO,SAAS,OAAoB,UAAmB,MAAI;EACzD,KAAK,WAAW,SAAS,OAAO,OAAO;CACzC;CAGA,cAAW;EACT,KAAK,YAAW;EAChB,KAAK,WAAW,QAAO;CACzB;CAhEW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAc,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAd,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAc,YAFb;CAAM,CAAA;;AAEP,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAc,YAAA,CAAA;EAH1B,MAAA;EAAW,MAAA,CAAA,EACV,YAAY,OACb,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/theme",
3
- "version": "22.2.0",
3
+ "version": "22.3.1",
4
4
  "keywords": [
5
5
  "angular",
6
6
  "theme",
@@ -37,7 +37,7 @@
37
37
  "@angular/core": "^22.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@su-labs/core": "^1.1.0",
40
+ "@su-labs/core": "1.9.0",
41
41
  "tslib": "^2.3.0"
42
42
  },
43
43
  "sideEffects": false,
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { OnDestroy } from "@angular/core";
3
- import { SuThemeConfig, SuThemeConfig as SuThemeConfig$1, SuThemeName, SuThemeName as SuThemeName$1, ThemeCssVariables } from "@su-labs/core/theme";
3
+ import { SU_BASE_THEME_NAMES, SU_PALETTE_NAMES, SU_THEME_PALETTES, SuBaseThemeName, SuPaletteName, SuThemeConfig, SuThemeConfig as SuThemeConfig$1, SuThemeName, SuThemeName as SuThemeName$1, SuThemePalette, SuThemeScheme, ThemeCssVariables, isSuBaseThemeName } from "@su-labs/core/theme";
4
4
  /**
5
5
  * Angular service for managing application themes.
6
6
  *
@@ -32,9 +32,16 @@ export declare class SuThemeService implements OnDestroy {
32
32
  * @returns The user preference ('light', 'dark', 'contrast', 'custom', 'system').
33
33
  */
34
34
  getUserPreference(): SuThemeName$1;
35
+ /** The themes this site offers: the base themes, then the palettes listed in the config's `palettes` */
36
+ availableThemes(): SuThemeName$1[];
35
37
  /**
36
- * Set a new theme.
37
- * @param theme The theme to set ('light', 'dark', 'contrast', 'custom', 'system').
38
+ * Whether a theme can be set here: a base theme, or a listed palette.
39
+ * @param theme Any theme name.
40
+ */
41
+ isAvailable(theme: string): theme is SuThemeName$1;
42
+ /**
43
+ * Set a new theme. A palette the config doesn't list is ignored.
44
+ * @param theme The theme to set ('light', 'dark', 'contrast', 'custom', 'system', or a listed palette).
38
45
  * @param persist Whether to store the preference in localStorage (default: true).
39
46
  */
40
47
  setTheme(theme: SuThemeName$1, persist?: boolean): void;
@@ -43,4 +50,4 @@ export declare class SuThemeService implements OnDestroy {
43
50
  static ɵfac: i0.ɵɵFactoryDeclaration<SuThemeService, never>;
44
51
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
45
52
  }
46
- export type { SuThemeConfig, SuThemeName, ThemeCssVariables };
53
+ export { SU_BASE_THEME_NAMES, SU_PALETTE_NAMES, SU_THEME_PALETTES, type SuBaseThemeName, type SuPaletteName, type SuThemeConfig, type SuThemeName, type SuThemePalette, type SuThemeScheme, type ThemeCssVariables, isSuBaseThemeName };