@rxap/ngx-theme 19.0.3 → 19.1.0-dev.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/CHANGELOG.md +10 -0
- package/README.md +85 -0
- package/compodoc/changelog.html +7 -0
- package/compodoc/dependencies.html +6 -6
- package/compodoc/index.html +69 -1
- package/compodoc/injectables/ThemeModeService.html +1256 -0
- package/compodoc/injectables/ThemeService.html +82 -265
- package/compodoc/interfaces/ColorPaletteConfig.html +6 -71
- package/compodoc/interfaces/ColorPaletteConfigWithName.html +6 -71
- package/compodoc/interfaces/ThemeConfig.html +6 -71
- package/compodoc/js/menu-wc.js +6 -0
- package/compodoc/js/menu-wc_es5.js +1 -1
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/miscellaneous/typealiases.html +235 -0
- package/compodoc/miscellaneous/variables.html +32 -0
- package/compodoc/overview.html +1 -1
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +1672 -532
- package/docs/html/assets/hierarchy.js +1 -1
- package/docs/html/assets/highlight.css +28 -0
- package/docs/html/assets/navigation.js +1 -1
- package/docs/html/assets/search.js +1 -1
- package/docs/html/classes/ThemeModeService.html +35 -0
- package/docs/html/classes/ThemeService.html +4 -6
- package/docs/html/enums/ColorPaletteAlgorithm.html +2 -2
- package/docs/html/functions/ComputeColorPalette.html +1 -1
- package/docs/html/functions/ObserveCurrentThemeDensity.html +1 -1
- package/docs/html/functions/provideTheme.html +1 -1
- package/docs/html/hierarchy.html +1 -1
- package/docs/html/index.html +60 -2
- package/docs/html/interfaces/ColorPalette.html +2 -2
- package/docs/html/interfaces/ColorPaletteConfig.html +2 -2
- package/docs/html/interfaces/ColorPaletteConfigWithName.html +2 -2
- package/docs/html/interfaces/ThemeConfig.html +2 -2
- package/docs/html/modules.html +1 -1
- package/docs/html/types/ActiveTheme.html +1 -0
- package/docs/html/types/ThemeSetting.html +1 -0
- package/docs/html/variables/THEME_SETTING_KEY.html +1 -0
- package/docs/markdown/README.md +86 -1
- package/docs/markdown/classes/ThemeModeService.md +282 -0
- package/docs/markdown/classes/ThemeService.md +39 -69
- package/docs/markdown/enumerations/ColorPaletteAlgorithm.md +4 -4
- package/docs/markdown/functions/ComputeColorPalette.md +2 -2
- package/docs/markdown/functions/ObserveCurrentThemeDensity.md +2 -2
- package/docs/markdown/functions/provideTheme.md +2 -2
- package/docs/markdown/globals.md +12 -2
- package/docs/markdown/interfaces/ColorPalette.md +16 -16
- package/docs/markdown/interfaces/ColorPaletteConfig.md +5 -5
- package/docs/markdown/interfaces/ColorPaletteConfigWithName.md +6 -6
- package/docs/markdown/interfaces/ThemeConfig.md +7 -7
- package/docs/markdown/type-aliases/ActiveTheme.md +11 -0
- package/docs/markdown/type-aliases/ThemeSetting.md +11 -0
- package/docs/markdown/variables/THEME_SETTING_KEY.md +11 -0
- package/docs/wiki/Class.ThemeModeService.md +278 -0
- package/docs/wiki/Class.ThemeService.md +38 -68
- package/docs/wiki/Enumeration.ColorPaletteAlgorithm.md +3 -3
- package/docs/wiki/Function.ComputeColorPalette.md +1 -1
- package/docs/wiki/Function.ObserveCurrentThemeDensity.md +1 -1
- package/docs/wiki/Function.provideTheme.md +1 -1
- package/docs/wiki/Home.md +85 -0
- package/docs/wiki/Interface.ColorPalette.md +15 -15
- package/docs/wiki/Interface.ColorPaletteConfig.md +4 -4
- package/docs/wiki/Interface.ColorPaletteConfigWithName.md +5 -5
- package/docs/wiki/Interface.ThemeConfig.md +6 -6
- package/docs/wiki/TypeAlias.ActiveTheme.md +7 -0
- package/docs/wiki/TypeAlias.ThemeSetting.md +7 -0
- package/docs/wiki/Variable.THEME_SETTING_KEY.md +7 -0
- package/docs/wiki/_Sidebar.md +10 -0
- package/docs/wiki/globals.md +11 -1
- package/fesm2022/rxap-ngx-theme.mjs +145 -64
- package/fesm2022/rxap-ngx-theme.mjs.map +1 -1
- package/index.d.ts +1 -0
- package/lib/theme-mode.service.d.ts +61 -0
- package/lib/theme.service.d.ts +3 -5
- package/package.json +16 -16
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Interface: ColorPaletteConfigWithName
|
|
4
4
|
|
|
5
|
-
Defined in: [theme.service.ts:
|
|
5
|
+
Defined in: [theme.service.ts:28](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L28)
|
|
6
6
|
|
|
7
7
|
## Extends
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ Defined in: [theme.service.ts:27](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
14
14
|
|
|
15
15
|
> `optional` **algorithm**: `string`
|
|
16
16
|
|
|
17
|
-
Defined in: [theme.service.ts:
|
|
17
|
+
Defined in: [theme.service.ts:41](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L41)
|
|
18
18
|
|
|
19
19
|
#### Inherited from
|
|
20
20
|
|
|
@@ -26,7 +26,7 @@ Defined in: [theme.service.ts:40](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
26
26
|
|
|
27
27
|
> `optional` **base**: `string`
|
|
28
28
|
|
|
29
|
-
Defined in: [theme.service.ts:
|
|
29
|
+
Defined in: [theme.service.ts:42](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L42)
|
|
30
30
|
|
|
31
31
|
#### Inherited from
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ Defined in: [theme.service.ts:41](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
38
38
|
|
|
39
39
|
> `optional` **color**: `Partial`\<[`ColorPalette`](../wiki/Interface.ColorPalette)\>
|
|
40
40
|
|
|
41
|
-
Defined in: [theme.service.ts:
|
|
41
|
+
Defined in: [theme.service.ts:43](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L43)
|
|
42
42
|
|
|
43
43
|
#### Inherited from
|
|
44
44
|
|
|
@@ -50,4 +50,4 @@ Defined in: [theme.service.ts:42](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
50
50
|
|
|
51
51
|
> `optional` **name**: `string`
|
|
52
52
|
|
|
53
|
-
Defined in: [theme.service.ts:
|
|
53
|
+
Defined in: [theme.service.ts:29](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L29)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Interface: ThemeConfig
|
|
4
4
|
|
|
5
|
-
Defined in: [theme.service.ts:
|
|
5
|
+
Defined in: [theme.service.ts:32](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L32)
|
|
6
6
|
|
|
7
7
|
## Properties
|
|
8
8
|
|
|
@@ -10,7 +10,7 @@ Defined in: [theme.service.ts:31](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
10
10
|
|
|
11
11
|
> `optional` **accentColor**: [`ColorPaletteConfigWithName`](../wiki/Interface.ColorPaletteConfigWithName)
|
|
12
12
|
|
|
13
|
-
Defined in: [theme.service.ts:
|
|
13
|
+
Defined in: [theme.service.ts:34](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L34)
|
|
14
14
|
|
|
15
15
|
***
|
|
16
16
|
|
|
@@ -18,7 +18,7 @@ Defined in: [theme.service.ts:33](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
18
18
|
|
|
19
19
|
> `optional` **density**: `ThemeDensity`
|
|
20
20
|
|
|
21
|
-
Defined in: [theme.service.ts:
|
|
21
|
+
Defined in: [theme.service.ts:36](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L36)
|
|
22
22
|
|
|
23
23
|
***
|
|
24
24
|
|
|
@@ -26,7 +26,7 @@ Defined in: [theme.service.ts:35](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
26
26
|
|
|
27
27
|
> `optional` **primaryColor**: [`ColorPaletteConfigWithName`](../wiki/Interface.ColorPaletteConfigWithName)
|
|
28
28
|
|
|
29
|
-
Defined in: [theme.service.ts:
|
|
29
|
+
Defined in: [theme.service.ts:33](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L33)
|
|
30
30
|
|
|
31
31
|
***
|
|
32
32
|
|
|
@@ -34,7 +34,7 @@ Defined in: [theme.service.ts:32](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
34
34
|
|
|
35
35
|
> `optional` **typography**: `string`
|
|
36
36
|
|
|
37
|
-
Defined in: [theme.service.ts:
|
|
37
|
+
Defined in: [theme.service.ts:37](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L37)
|
|
38
38
|
|
|
39
39
|
***
|
|
40
40
|
|
|
@@ -42,4 +42,4 @@ Defined in: [theme.service.ts:36](https://gitlab.com/rxap/packages/-/blob/15b5fa
|
|
|
42
42
|
|
|
43
43
|
> `optional` **warnColor**: [`ColorPaletteConfigWithName`](../wiki/Interface.ColorPaletteConfigWithName)
|
|
44
44
|
|
|
45
|
-
Defined in: [theme.service.ts:
|
|
45
|
+
Defined in: [theme.service.ts:35](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme.service.ts#L35)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[@rxap/ngx-theme](../wiki/globals) / ActiveTheme
|
|
2
|
+
|
|
3
|
+
# Type Alias: ActiveTheme
|
|
4
|
+
|
|
5
|
+
> **ActiveTheme**: `"light"` \| `"dark"`
|
|
6
|
+
|
|
7
|
+
Defined in: [theme-mode.service.ts:30](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme-mode.service.ts#L30)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[@rxap/ngx-theme](../wiki/globals) / ThemeSetting
|
|
2
|
+
|
|
3
|
+
# Type Alias: ThemeSetting
|
|
4
|
+
|
|
5
|
+
> **ThemeSetting**: `"system"` \| `"light"` \| `"dark"`
|
|
6
|
+
|
|
7
|
+
Defined in: [theme-mode.service.ts:28](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme-mode.service.ts#L28)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
[@rxap/ngx-theme](../wiki/globals) / THEME\_SETTING\_KEY
|
|
2
|
+
|
|
3
|
+
# Variable: THEME\_SETTING\_KEY
|
|
4
|
+
|
|
5
|
+
> `const` **THEME\_SETTING\_KEY**: `"rxap_theme_settings"` = `'rxap_theme_settings'`
|
|
6
|
+
|
|
7
|
+
Defined in: [theme-mode.service.ts:32](https://gitlab.com/rxap/packages/-/blob/b32f110144dafee760d535d217a2855e77f154a5/packages/angular/theme/src/lib/theme-mode.service.ts#L32)
|
package/docs/wiki/_Sidebar.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
### Classes
|
|
8
8
|
|
|
9
|
+
- [ThemeModeService](../wiki/Class.ThemeModeService)
|
|
9
10
|
- [ThemeService](../wiki/Class.ThemeService)
|
|
10
11
|
|
|
11
12
|
### Interfaces
|
|
@@ -15,6 +16,15 @@
|
|
|
15
16
|
- [ColorPaletteConfigWithName](../wiki/Interface.ColorPaletteConfigWithName)
|
|
16
17
|
- [ThemeConfig](../wiki/Interface.ThemeConfig)
|
|
17
18
|
|
|
19
|
+
### Type Aliases
|
|
20
|
+
|
|
21
|
+
- [ActiveTheme](../wiki/TypeAlias.ActiveTheme)
|
|
22
|
+
- [ThemeSetting](../wiki/TypeAlias.ThemeSetting)
|
|
23
|
+
|
|
24
|
+
### Variables
|
|
25
|
+
|
|
26
|
+
- [THEME_SETTING_KEY](../wiki/Variable.THEME_SETTING_KEY)
|
|
27
|
+
|
|
18
28
|
### Functions
|
|
19
29
|
|
|
20
30
|
- [ComputeColorPalette](../wiki/Function.ComputeColorPalette)
|
package/docs/wiki/globals.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# @rxap/ngx-theme v19.0.
|
|
1
|
+
# @rxap/ngx-theme v19.1.0-dev.0
|
|
2
2
|
|
|
3
3
|
## Enumerations
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
## Classes
|
|
8
8
|
|
|
9
|
+
- [ThemeModeService](../wiki/Class.ThemeModeService)
|
|
9
10
|
- [ThemeService](../wiki/Class.ThemeService)
|
|
10
11
|
|
|
11
12
|
## Interfaces
|
|
@@ -15,6 +16,15 @@
|
|
|
15
16
|
- [ColorPaletteConfigWithName](../wiki/Interface.ColorPaletteConfigWithName)
|
|
16
17
|
- [ThemeConfig](../wiki/Interface.ThemeConfig)
|
|
17
18
|
|
|
19
|
+
## Type Aliases
|
|
20
|
+
|
|
21
|
+
- [ActiveTheme](../wiki/TypeAlias.ActiveTheme)
|
|
22
|
+
- [ThemeSetting](../wiki/TypeAlias.ThemeSetting)
|
|
23
|
+
|
|
24
|
+
## Variables
|
|
25
|
+
|
|
26
|
+
- [THEME\_SETTING\_KEY](../wiki/Variable.THEME_SETTING_KEY)
|
|
27
|
+
|
|
18
28
|
## Functions
|
|
19
29
|
|
|
20
30
|
- [ComputeColorPalette](../wiki/Function.ComputeColorPalette)
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { TinyColor } from '@ctrl/tinycolor';
|
|
2
2
|
import { Observable, Subscription, debounceTime, map, tap } from 'rxjs';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
|
-
import { inject, signal,
|
|
4
|
+
import { inject, computed, signal, effect, Injectable, Inject, isDevMode, provideAppInitializer } from '@angular/core';
|
|
5
5
|
import * as i1 from '@angular/cdk/layout';
|
|
6
6
|
import { ConfigService } from '@rxap/config';
|
|
7
7
|
import { PubSubService, RXAP_TOPICS } from '@rxap/ngx-pub-sub';
|
|
8
8
|
import { isDefined } from '@rxap/rxjs';
|
|
9
|
+
import { DOCUMENT } from '@angular/common';
|
|
9
10
|
|
|
10
11
|
var ColorPaletteAlgorithm;
|
|
11
12
|
(function (ColorPaletteAlgorithm) {
|
|
@@ -103,33 +104,156 @@ function ObserveCurrentThemeDensity() {
|
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
const THEME_SETTING_KEY = 'rxap_theme_settings';
|
|
108
|
+
/**
|
|
109
|
+
* Service to manage theme mode (light/dark/system) for the application.
|
|
110
|
+
* It provides functionality to handle theme preferences, persist them, and synchronize changes.
|
|
111
|
+
*
|
|
112
|
+
* This service integrates with media queries to detect system-level theme changes and allows the user
|
|
113
|
+
* or application logic to toggle or set a specific theme.
|
|
114
|
+
*
|
|
115
|
+
* It utilizes dependency injection to access various required services and the document object.
|
|
116
|
+
* Additionally, it publishes theme-related events for other parts of the application to react to
|
|
117
|
+
* theme changes.
|
|
118
|
+
*/
|
|
119
|
+
class ThemeModeService {
|
|
120
|
+
constructor(mediaMatcher, document) {
|
|
121
|
+
this.mediaMatcher = mediaMatcher;
|
|
122
|
+
this.document = document;
|
|
123
|
+
this.config = inject(ConfigService);
|
|
124
|
+
this.pubSub = inject(PubSubService);
|
|
125
|
+
this.darkMode = computed(() => this.activeTheme() === 'dark');
|
|
126
|
+
this.subscriptions = null;
|
|
127
|
+
this.darkColorSchemaMediaQuery = this.mediaMatcher.matchMedia('(prefers-color-scheme: dark)');
|
|
128
|
+
this.themeSetting = signal(this.restoreThemeSetting());
|
|
129
|
+
let activeTheme;
|
|
130
|
+
const themeSetting = this.themeSetting();
|
|
131
|
+
switch (themeSetting) {
|
|
132
|
+
case 'system':
|
|
133
|
+
activeTheme = this.darkColorSchemaMediaQuery.matches ? 'dark' : 'light';
|
|
134
|
+
break;
|
|
135
|
+
case 'light':
|
|
136
|
+
activeTheme = 'light';
|
|
137
|
+
break;
|
|
138
|
+
case 'dark':
|
|
139
|
+
activeTheme = 'dark';
|
|
140
|
+
break;
|
|
141
|
+
default:
|
|
142
|
+
activeTheme = this.config.get('theme.active', 'light');
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
this.activeTheme = signal(activeTheme);
|
|
146
|
+
effect(() => {
|
|
147
|
+
const setting = this.themeSetting();
|
|
148
|
+
this.storeThemeSetting(setting);
|
|
149
|
+
});
|
|
150
|
+
effect(() => {
|
|
151
|
+
const active = this.activeTheme();
|
|
152
|
+
this.setThemeClasses(active);
|
|
153
|
+
});
|
|
154
|
+
this.mediaQueryListener = (event) => {
|
|
155
|
+
if (this.themeSetting() === 'system') {
|
|
156
|
+
this.activeTheme.set(event.matches ? 'dark' : 'light');
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
this.darkColorSchemaMediaQuery.addEventListener('change', this.mediaQueryListener);
|
|
160
|
+
this.restoreFromPubSub();
|
|
161
|
+
}
|
|
162
|
+
get darkModeLocalStorageKey() {
|
|
163
|
+
return window?.['__rxap__']?.['ngx']?.['theme']?.['darkMode']?.['key'] ?? THEME_SETTING_KEY;
|
|
164
|
+
}
|
|
165
|
+
restoreFromPubSub() {
|
|
166
|
+
if (this.syncSubscription) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
this.syncSubscription = new Subscription();
|
|
170
|
+
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.darkMode.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => {
|
|
171
|
+
const active = data ? 'dark' : 'light';
|
|
172
|
+
this.themeSetting.set(active);
|
|
173
|
+
this.activeTheme.set(active);
|
|
174
|
+
})).subscribe());
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Cleans up subscriptions and event listeners when the service is destroyed.
|
|
178
|
+
*/
|
|
179
|
+
ngOnDestroy() {
|
|
180
|
+
// Remove the media query listener if it exists.
|
|
181
|
+
this.darkColorSchemaMediaQuery.removeEventListener('change', this.mediaQueryListener);
|
|
182
|
+
// Unsubscribe from all RxJS subscriptions.
|
|
183
|
+
this.subscriptions?.unsubscribe();
|
|
184
|
+
this.syncSubscription?.unsubscribe();
|
|
185
|
+
}
|
|
186
|
+
restoreThemeSetting() {
|
|
187
|
+
const setting = localStorage.getItem(this.darkModeLocalStorageKey) ?? this.config.get('theme.setting', 'system');
|
|
188
|
+
if (setting && ['system', 'dark', 'light'].includes(setting)) {
|
|
189
|
+
return setting;
|
|
190
|
+
}
|
|
191
|
+
return 'system';
|
|
192
|
+
}
|
|
193
|
+
storeThemeSetting(setting) {
|
|
194
|
+
localStorage.setItem(this.darkModeLocalStorageKey, setting);
|
|
195
|
+
}
|
|
196
|
+
removeThemeClasses() {
|
|
197
|
+
this.document.body.classList.remove('light');
|
|
198
|
+
this.document.body.classList.remove('dark');
|
|
199
|
+
}
|
|
200
|
+
setThemeClasses(active) {
|
|
201
|
+
this.document.body.classList.remove(active === 'light' ? 'dark' : 'light');
|
|
202
|
+
this.document.body.classList.add(active);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Toggles the application theme between 'light' and 'dark' modes.
|
|
206
|
+
* It checks the currently active theme and switches to the opposite mode.
|
|
207
|
+
*
|
|
208
|
+
* @return {void} Does not return a value.
|
|
209
|
+
*/
|
|
210
|
+
toggleTheme() {
|
|
211
|
+
const currentActive = this.activeTheme();
|
|
212
|
+
// Determine the new setting based on the *currently active* theme.
|
|
213
|
+
const newActive = currentActive === 'light' ? 'dark' : 'light';
|
|
214
|
+
this.themeSetting.set(newActive);
|
|
215
|
+
this.activeTheme.set(newActive);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Sets the active theme for the application and optionally publishes the change.
|
|
219
|
+
*
|
|
220
|
+
* @param {ActiveTheme} active - The theme to be set as active.
|
|
221
|
+
* @param {boolean} [publish=true] - Indicates whether to publish the theme change event.
|
|
222
|
+
* @return {void}
|
|
223
|
+
*/
|
|
224
|
+
setTheme(active, publish = true) {
|
|
225
|
+
this.themeSetting.set(active);
|
|
226
|
+
this.activeTheme.set(active);
|
|
227
|
+
if (publish) {
|
|
228
|
+
this.pubSub.publish(RXAP_TOPICS.theme.darkMode.changed, this.darkMode());
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeModeService, deps: [{ token: i1.MediaMatcher }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
232
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeModeService, providedIn: 'root' }); }
|
|
233
|
+
}
|
|
234
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeModeService, decorators: [{
|
|
235
|
+
type: Injectable,
|
|
236
|
+
args: [{ providedIn: 'root' }]
|
|
237
|
+
}], ctorParameters: () => [{ type: i1.MediaMatcher }, { type: Document, decorators: [{
|
|
238
|
+
type: Inject,
|
|
239
|
+
args: [DOCUMENT]
|
|
240
|
+
}] }] });
|
|
241
|
+
|
|
106
242
|
class ThemeService {
|
|
107
243
|
constructor(mediaMatcher) {
|
|
108
244
|
this.mediaMatcher = mediaMatcher;
|
|
109
245
|
this.config = inject(ConfigService);
|
|
110
246
|
this.pubSub = inject(PubSubService);
|
|
111
|
-
this.
|
|
112
|
-
this.darkMode =
|
|
247
|
+
this.themeModeService = inject(ThemeModeService);
|
|
248
|
+
this.darkMode = this.themeModeService.darkMode;
|
|
113
249
|
this.themeName = signal(this.getTheme());
|
|
114
250
|
this.density = signal(this.getDensity());
|
|
115
251
|
this.typography = signal(this.getTypography());
|
|
116
|
-
this.darkModeMediaQuery.addEventListener('change', (event) => {
|
|
117
|
-
this.setDarkTheme(event.matches, true);
|
|
118
|
-
});
|
|
119
252
|
}
|
|
120
253
|
restore() {
|
|
121
254
|
if (isDevMode()) {
|
|
122
255
|
console.log('Restore theme settings from local storage');
|
|
123
256
|
}
|
|
124
|
-
// region restore dark mode
|
|
125
|
-
let darkMode = this.restoreDarkMode();
|
|
126
|
-
// if the dark/light mode is not restored from the local storage
|
|
127
|
-
if (darkMode === null) {
|
|
128
|
-
// set the dark mode based on the media query
|
|
129
|
-
darkMode = this.darkModeMediaQuery.matches;
|
|
130
|
-
this.setDarkTheme(darkMode, true);
|
|
131
|
-
}
|
|
132
|
-
// endregion
|
|
133
257
|
this.restoreThemeName();
|
|
134
258
|
this.restoreDensity();
|
|
135
259
|
this.restoreTypography();
|
|
@@ -143,10 +267,6 @@ class ThemeService {
|
|
|
143
267
|
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.density.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => this.setDensity(data, false, false))).subscribe());
|
|
144
268
|
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.preset.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => this.setTheme(data, false, false))).subscribe());
|
|
145
269
|
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.typography.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => this.setTypography(data, false, false))).subscribe());
|
|
146
|
-
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.darkMode.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => this.setDarkTheme(data, false, false))).subscribe());
|
|
147
|
-
}
|
|
148
|
-
get darkModeLocalStorageKey() {
|
|
149
|
-
return window?.['__rxap__']?.['ngx']?.['theme']?.['darkMode']?.['key'] ?? `rxap-dark-mode`;
|
|
150
270
|
}
|
|
151
271
|
get themeNameLocalStorageKey() {
|
|
152
272
|
return window?.['__rxap__']?.['ngx']?.['theme']?.['name']?.['key'] ?? `rxap-theme-name`;
|
|
@@ -158,20 +278,6 @@ class ThemeService {
|
|
|
158
278
|
return window?.['__rxap__']?.['ngx']?.['theme']?.['typography']?.['key'] ?? `rxap-theme-typography`;
|
|
159
279
|
}
|
|
160
280
|
// region restore
|
|
161
|
-
restoreDarkMode() {
|
|
162
|
-
let darkMode = null;
|
|
163
|
-
const darkModeCached = localStorage.getItem(this.darkModeLocalStorageKey);
|
|
164
|
-
if (darkModeCached === 'true') {
|
|
165
|
-
darkMode = true;
|
|
166
|
-
}
|
|
167
|
-
if (darkModeCached === 'false') {
|
|
168
|
-
darkMode = false;
|
|
169
|
-
}
|
|
170
|
-
if (darkMode !== null) {
|
|
171
|
-
this.setDarkTheme(darkMode, true);
|
|
172
|
-
}
|
|
173
|
-
return darkMode;
|
|
174
|
-
}
|
|
175
281
|
restoreThemeName() {
|
|
176
282
|
const themeName = localStorage.getItem(this.themeNameLocalStorageKey);
|
|
177
283
|
if (themeName) {
|
|
@@ -199,20 +305,11 @@ class ThemeService {
|
|
|
199
305
|
}
|
|
200
306
|
// endregion
|
|
201
307
|
toggleDarkTheme() {
|
|
202
|
-
this.
|
|
308
|
+
this.themeModeService.toggleTheme();
|
|
203
309
|
}
|
|
204
310
|
// region set theme configuration state
|
|
205
311
|
setDarkTheme(darkMode, silent = false, publish = true) {
|
|
206
|
-
this.
|
|
207
|
-
if (this.darkMode() !== darkMode) {
|
|
208
|
-
this.darkMode.set(darkMode);
|
|
209
|
-
if (!silent) {
|
|
210
|
-
localStorage.setItem(this.darkModeLocalStorageKey, String(darkMode));
|
|
211
|
-
if (publish) {
|
|
212
|
-
this.pubSub.publish(RXAP_TOPICS.theme.darkMode.changed, darkMode);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
312
|
+
this.themeModeService.setTheme(darkMode ? 'dark' : 'light', publish);
|
|
216
313
|
}
|
|
217
314
|
setDensity(density, silent = false, publish = true) {
|
|
218
315
|
this.applyDensity(density);
|
|
@@ -254,22 +351,6 @@ class ThemeService {
|
|
|
254
351
|
}
|
|
255
352
|
// endregion
|
|
256
353
|
// region apply theme configuration state
|
|
257
|
-
applyDarkMode(darkMode) {
|
|
258
|
-
if (darkMode) {
|
|
259
|
-
// region deprecated
|
|
260
|
-
document.body.classList.add('dark-theme');
|
|
261
|
-
localStorage.removeItem('rxap-light-theme');
|
|
262
|
-
// endregion
|
|
263
|
-
document.body.classList.add('dark');
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
// region deprecated
|
|
267
|
-
document.body.classList.remove('dark-theme');
|
|
268
|
-
localStorage.setItem('rxap-light-theme', 'true');
|
|
269
|
-
// endregion
|
|
270
|
-
document.body.classList.remove('dark');
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
354
|
applyDensity(density) {
|
|
274
355
|
document.body.classList.remove('density-0', 'density-1', 'density-2', 'density-3');
|
|
275
356
|
if (density < 0) {
|
|
@@ -427,10 +508,10 @@ class ThemeService {
|
|
|
427
508
|
localStorage.removeItem(this.densityLocalStorageKey);
|
|
428
509
|
localStorage.removeItem(this.typographyLocalStorageKey);
|
|
429
510
|
}
|
|
430
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.1
|
|
431
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.1
|
|
511
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeService, deps: [{ token: i1.MediaMatcher }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
512
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeService, providedIn: 'root' }); }
|
|
432
513
|
}
|
|
433
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1
|
|
514
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeService, decorators: [{
|
|
434
515
|
type: Injectable,
|
|
435
516
|
args: [{ providedIn: 'root' }]
|
|
436
517
|
}], ctorParameters: () => [{ type: i1.MediaMatcher }] });
|
|
@@ -451,5 +532,5 @@ function provideTheme() {
|
|
|
451
532
|
* Generated bundle index. Do not edit.
|
|
452
533
|
*/
|
|
453
534
|
|
|
454
|
-
export { ColorPaletteAlgorithm, ComputeColorPalette, ObserveCurrentThemeDensity, ThemeService, provideTheme };
|
|
535
|
+
export { ColorPaletteAlgorithm, ComputeColorPalette, ObserveCurrentThemeDensity, THEME_SETTING_KEY, ThemeModeService, ThemeService, provideTheme };
|
|
455
536
|
//# sourceMappingURL=rxap-ngx-theme.mjs.map
|