@rxap/ngx-theme 19.0.4-dev.0 → 19.1.0-dev.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 +12 -0
- package/README.md +86 -1
- package/compodoc/changelog.html +10 -0
- package/compodoc/classes/ThemeColor.html +874 -0
- package/compodoc/dependencies.html +6 -4
- package/compodoc/index.html +70 -2
- package/compodoc/injectables/ThemeModeService.html +1256 -0
- package/compodoc/injectables/ThemeService.html +82 -265
- package/compodoc/interfaces/BasePalette.html +844 -0
- package/compodoc/interfaces/ColorPaletteConfig.html +6 -71
- package/compodoc/interfaces/ColorPaletteConfigWithName.html +6 -71
- package/compodoc/interfaces/ThemeColors.html +898 -0
- package/compodoc/interfaces/ThemeConfig.html +6 -71
- package/compodoc/js/menu-wc.js +25 -0
- package/compodoc/js/menu-wc_es5.js +1 -1
- package/compodoc/js/search/search_index.js +2 -2
- package/compodoc/miscellaneous/functions.html +60 -1
- package/compodoc/miscellaneous/typealiases.html +364 -0
- package/compodoc/miscellaneous/variables.html +193 -0
- package/compodoc/overview.html +10 -2
- package/compodoc/properties.html +1 -1
- package/docs/documentation.json +2294 -530
- 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/ThemeColor.html +4 -0
- 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/applyThemeColorBootstrapHook.html +1 -0
- package/docs/html/functions/provideTheme.html +1 -1
- package/docs/html/hierarchy.html +1 -1
- package/docs/html/index.html +61 -3
- 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/ThemeColors.html +7 -0
- 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 +87 -2
- package/docs/markdown/classes/ThemeColor.md +83 -0
- 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/applyThemeColorBootstrapHook.md +31 -0
- package/docs/markdown/functions/provideTheme.md +2 -2
- package/docs/markdown/globals.md +15 -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/ThemeColors.md +57 -0
- 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.ThemeColor.md +79 -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.applyThemeColorBootstrapHook.md +27 -0
- package/docs/wiki/Function.provideTheme.md +1 -1
- package/docs/wiki/Home.md +86 -1
- 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.ThemeColors.md +53 -0
- 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 +13 -0
- package/docs/wiki/globals.md +14 -1
- package/fesm2022/rxap-ngx-theme.mjs +392 -61
- package/fesm2022/rxap-ngx-theme.mjs.map +1 -1
- package/index.d.ts +2 -0
- package/lib/theme-color.d.ts +29 -0
- package/lib/theme-mode.service.d.ts +61 -0
- package/lib/theme.service.d.ts +3 -5
- package/package.json +13 -12
|
@@ -1,11 +1,13 @@
|
|
|
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';
|
|
10
|
+
import { CorePalette } from '@material/material-color-utilities';
|
|
9
11
|
|
|
10
12
|
var ColorPaletteAlgorithm;
|
|
11
13
|
(function (ColorPaletteAlgorithm) {
|
|
@@ -103,33 +105,156 @@ function ObserveCurrentThemeDensity() {
|
|
|
103
105
|
});
|
|
104
106
|
}
|
|
105
107
|
|
|
108
|
+
const THEME_SETTING_KEY = 'rxap_theme_settings';
|
|
109
|
+
/**
|
|
110
|
+
* Service to manage theme mode (light/dark/system) for the application.
|
|
111
|
+
* It provides functionality to handle theme preferences, persist them, and synchronize changes.
|
|
112
|
+
*
|
|
113
|
+
* This service integrates with media queries to detect system-level theme changes and allows the user
|
|
114
|
+
* or application logic to toggle or set a specific theme.
|
|
115
|
+
*
|
|
116
|
+
* It utilizes dependency injection to access various required services and the document object.
|
|
117
|
+
* Additionally, it publishes theme-related events for other parts of the application to react to
|
|
118
|
+
* theme changes.
|
|
119
|
+
*/
|
|
120
|
+
class ThemeModeService {
|
|
121
|
+
constructor(mediaMatcher, document) {
|
|
122
|
+
this.mediaMatcher = mediaMatcher;
|
|
123
|
+
this.document = document;
|
|
124
|
+
this.config = inject(ConfigService);
|
|
125
|
+
this.pubSub = inject(PubSubService);
|
|
126
|
+
this.darkMode = computed(() => this.activeTheme() === 'dark');
|
|
127
|
+
this.subscriptions = null;
|
|
128
|
+
this.darkColorSchemaMediaQuery = this.mediaMatcher.matchMedia('(prefers-color-scheme: dark)');
|
|
129
|
+
this.themeSetting = signal(this.restoreThemeSetting());
|
|
130
|
+
let activeTheme;
|
|
131
|
+
const themeSetting = this.themeSetting();
|
|
132
|
+
switch (themeSetting) {
|
|
133
|
+
case 'system':
|
|
134
|
+
activeTheme = this.darkColorSchemaMediaQuery.matches ? 'dark' : 'light';
|
|
135
|
+
break;
|
|
136
|
+
case 'light':
|
|
137
|
+
activeTheme = 'light';
|
|
138
|
+
break;
|
|
139
|
+
case 'dark':
|
|
140
|
+
activeTheme = 'dark';
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
activeTheme = this.config.get('theme.active', 'light');
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
this.activeTheme = signal(activeTheme);
|
|
147
|
+
effect(() => {
|
|
148
|
+
const setting = this.themeSetting();
|
|
149
|
+
this.storeThemeSetting(setting);
|
|
150
|
+
});
|
|
151
|
+
effect(() => {
|
|
152
|
+
const active = this.activeTheme();
|
|
153
|
+
this.setThemeClasses(active);
|
|
154
|
+
});
|
|
155
|
+
this.mediaQueryListener = (event) => {
|
|
156
|
+
if (this.themeSetting() === 'system') {
|
|
157
|
+
this.activeTheme.set(event.matches ? 'dark' : 'light');
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
this.darkColorSchemaMediaQuery.addEventListener('change', this.mediaQueryListener);
|
|
161
|
+
this.restoreFromPubSub();
|
|
162
|
+
}
|
|
163
|
+
get darkModeLocalStorageKey() {
|
|
164
|
+
return window?.['__rxap__']?.['ngx']?.['theme']?.['darkMode']?.['key'] ?? THEME_SETTING_KEY;
|
|
165
|
+
}
|
|
166
|
+
restoreFromPubSub() {
|
|
167
|
+
if (this.syncSubscription) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this.syncSubscription = new Subscription();
|
|
171
|
+
this.syncSubscription.add(this.pubSub.subscribe(RXAP_TOPICS.theme.darkMode.restore).pipe(debounceTime(1000), map(event => event.data), isDefined(), tap(data => {
|
|
172
|
+
const active = data ? 'dark' : 'light';
|
|
173
|
+
this.themeSetting.set(active);
|
|
174
|
+
this.activeTheme.set(active);
|
|
175
|
+
})).subscribe());
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Cleans up subscriptions and event listeners when the service is destroyed.
|
|
179
|
+
*/
|
|
180
|
+
ngOnDestroy() {
|
|
181
|
+
// Remove the media query listener if it exists.
|
|
182
|
+
this.darkColorSchemaMediaQuery.removeEventListener('change', this.mediaQueryListener);
|
|
183
|
+
// Unsubscribe from all RxJS subscriptions.
|
|
184
|
+
this.subscriptions?.unsubscribe();
|
|
185
|
+
this.syncSubscription?.unsubscribe();
|
|
186
|
+
}
|
|
187
|
+
restoreThemeSetting() {
|
|
188
|
+
const setting = localStorage.getItem(this.darkModeLocalStorageKey) ?? this.config.get('theme.setting', 'system');
|
|
189
|
+
if (setting && ['system', 'dark', 'light'].includes(setting)) {
|
|
190
|
+
return setting;
|
|
191
|
+
}
|
|
192
|
+
return 'system';
|
|
193
|
+
}
|
|
194
|
+
storeThemeSetting(setting) {
|
|
195
|
+
localStorage.setItem(this.darkModeLocalStorageKey, setting);
|
|
196
|
+
}
|
|
197
|
+
removeThemeClasses() {
|
|
198
|
+
this.document.body.classList.remove('light');
|
|
199
|
+
this.document.body.classList.remove('dark');
|
|
200
|
+
}
|
|
201
|
+
setThemeClasses(active) {
|
|
202
|
+
this.document.body.classList.remove(active === 'light' ? 'dark' : 'light');
|
|
203
|
+
this.document.body.classList.add(active);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Toggles the application theme between 'light' and 'dark' modes.
|
|
207
|
+
* It checks the currently active theme and switches to the opposite mode.
|
|
208
|
+
*
|
|
209
|
+
* @return {void} Does not return a value.
|
|
210
|
+
*/
|
|
211
|
+
toggleTheme() {
|
|
212
|
+
const currentActive = this.activeTheme();
|
|
213
|
+
// Determine the new setting based on the *currently active* theme.
|
|
214
|
+
const newActive = currentActive === 'light' ? 'dark' : 'light';
|
|
215
|
+
this.themeSetting.set(newActive);
|
|
216
|
+
this.activeTheme.set(newActive);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Sets the active theme for the application and optionally publishes the change.
|
|
220
|
+
*
|
|
221
|
+
* @param {ActiveTheme} active - The theme to be set as active.
|
|
222
|
+
* @param {boolean} [publish=true] - Indicates whether to publish the theme change event.
|
|
223
|
+
* @return {void}
|
|
224
|
+
*/
|
|
225
|
+
setTheme(active, publish = true) {
|
|
226
|
+
this.themeSetting.set(active);
|
|
227
|
+
this.activeTheme.set(active);
|
|
228
|
+
if (publish) {
|
|
229
|
+
this.pubSub.publish(RXAP_TOPICS.theme.darkMode.changed, this.darkMode());
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
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 }); }
|
|
233
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeModeService, providedIn: 'root' }); }
|
|
234
|
+
}
|
|
235
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.1", ngImport: i0, type: ThemeModeService, decorators: [{
|
|
236
|
+
type: Injectable,
|
|
237
|
+
args: [{ providedIn: 'root' }]
|
|
238
|
+
}], ctorParameters: () => [{ type: i1.MediaMatcher }, { type: Document, decorators: [{
|
|
239
|
+
type: Inject,
|
|
240
|
+
args: [DOCUMENT]
|
|
241
|
+
}] }] });
|
|
242
|
+
|
|
106
243
|
class ThemeService {
|
|
107
244
|
constructor(mediaMatcher) {
|
|
108
245
|
this.mediaMatcher = mediaMatcher;
|
|
109
246
|
this.config = inject(ConfigService);
|
|
110
247
|
this.pubSub = inject(PubSubService);
|
|
111
|
-
this.
|
|
112
|
-
this.darkMode =
|
|
248
|
+
this.themeModeService = inject(ThemeModeService);
|
|
249
|
+
this.darkMode = this.themeModeService.darkMode;
|
|
113
250
|
this.themeName = signal(this.getTheme());
|
|
114
251
|
this.density = signal(this.getDensity());
|
|
115
252
|
this.typography = signal(this.getTypography());
|
|
116
|
-
this.darkModeMediaQuery.addEventListener('change', (event) => {
|
|
117
|
-
this.setDarkTheme(event.matches, true);
|
|
118
|
-
});
|
|
119
253
|
}
|
|
120
254
|
restore() {
|
|
121
255
|
if (isDevMode()) {
|
|
122
256
|
console.log('Restore theme settings from local storage');
|
|
123
257
|
}
|
|
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
258
|
this.restoreThemeName();
|
|
134
259
|
this.restoreDensity();
|
|
135
260
|
this.restoreTypography();
|
|
@@ -143,10 +268,6 @@ class ThemeService {
|
|
|
143
268
|
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
269
|
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
270
|
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
271
|
}
|
|
151
272
|
get themeNameLocalStorageKey() {
|
|
152
273
|
return window?.['__rxap__']?.['ngx']?.['theme']?.['name']?.['key'] ?? `rxap-theme-name`;
|
|
@@ -158,20 +279,6 @@ class ThemeService {
|
|
|
158
279
|
return window?.['__rxap__']?.['ngx']?.['theme']?.['typography']?.['key'] ?? `rxap-theme-typography`;
|
|
159
280
|
}
|
|
160
281
|
// 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
282
|
restoreThemeName() {
|
|
176
283
|
const themeName = localStorage.getItem(this.themeNameLocalStorageKey);
|
|
177
284
|
if (themeName) {
|
|
@@ -199,20 +306,11 @@ class ThemeService {
|
|
|
199
306
|
}
|
|
200
307
|
// endregion
|
|
201
308
|
toggleDarkTheme() {
|
|
202
|
-
this.
|
|
309
|
+
this.themeModeService.toggleTheme();
|
|
203
310
|
}
|
|
204
311
|
// region set theme configuration state
|
|
205
312
|
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
|
-
}
|
|
313
|
+
this.themeModeService.setTheme(darkMode ? 'dark' : 'light', publish);
|
|
216
314
|
}
|
|
217
315
|
setDensity(density, silent = false, publish = true) {
|
|
218
316
|
this.applyDensity(density);
|
|
@@ -254,22 +352,6 @@ class ThemeService {
|
|
|
254
352
|
}
|
|
255
353
|
// endregion
|
|
256
354
|
// 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
355
|
applyDensity(density) {
|
|
274
356
|
document.body.classList.remove('density-0', 'density-1', 'density-2', 'density-3');
|
|
275
357
|
if (density < 0) {
|
|
@@ -444,6 +526,255 @@ function provideTheme() {
|
|
|
444
526
|
];
|
|
445
527
|
}
|
|
446
528
|
|
|
529
|
+
// --- Mappings from System Roles to Reference Palette Keys ---
|
|
530
|
+
const lightRoleToRefKeyMap = {
|
|
531
|
+
background: 'neutral98',
|
|
532
|
+
error: 'error40',
|
|
533
|
+
'error-container': 'error90',
|
|
534
|
+
'inverse-on-surface': 'neutral95',
|
|
535
|
+
'inverse-primary': 'primary80',
|
|
536
|
+
'inverse-surface': 'neutral20',
|
|
537
|
+
'on-background': 'neutral10',
|
|
538
|
+
'on-error': 'error100',
|
|
539
|
+
'on-error-container': 'error10',
|
|
540
|
+
'on-primary': 'primary100',
|
|
541
|
+
'on-primary-container': 'primary10',
|
|
542
|
+
'on-primary-fixed': 'primary10',
|
|
543
|
+
'on-primary-fixed-variant': 'primary30',
|
|
544
|
+
'on-secondary': 'secondary100',
|
|
545
|
+
'on-secondary-container': 'secondary10',
|
|
546
|
+
'on-secondary-fixed': 'secondary10',
|
|
547
|
+
'on-secondary-fixed-variant': 'secondary30',
|
|
548
|
+
'on-surface': 'neutral10',
|
|
549
|
+
'on-surface-variant': 'neutral-variant30',
|
|
550
|
+
'on-tertiary': 'tertiary100',
|
|
551
|
+
'on-tertiary-container': 'tertiary10',
|
|
552
|
+
'on-tertiary-fixed': 'tertiary10',
|
|
553
|
+
'on-tertiary-fixed-variant': 'tertiary30',
|
|
554
|
+
outline: 'neutral-variant50',
|
|
555
|
+
'outline-variant': 'neutral-variant80',
|
|
556
|
+
primary: 'primary40',
|
|
557
|
+
'primary-container': 'primary90',
|
|
558
|
+
'primary-fixed': 'primary90',
|
|
559
|
+
'primary-fixed-dim': 'primary80',
|
|
560
|
+
scrim: 'neutral0',
|
|
561
|
+
secondary: 'secondary40',
|
|
562
|
+
'secondary-container': 'secondary90',
|
|
563
|
+
'secondary-fixed': 'secondary90',
|
|
564
|
+
'secondary-fixed-dim': 'secondary80',
|
|
565
|
+
shadow: 'neutral0',
|
|
566
|
+
surface: 'neutral98',
|
|
567
|
+
'surface-bright': 'neutral98',
|
|
568
|
+
'surface-container': 'neutral94',
|
|
569
|
+
'surface-container-high': 'neutral92',
|
|
570
|
+
'surface-container-highest': 'neutral90',
|
|
571
|
+
'surface-container-low': 'neutral96',
|
|
572
|
+
'surface-container-lowest': 'neutral100',
|
|
573
|
+
'surface-dim': 'neutral87',
|
|
574
|
+
'surface-tint': 'primary40',
|
|
575
|
+
'surface-variant': 'neutral-variant90',
|
|
576
|
+
tertiary: 'tertiary40',
|
|
577
|
+
'tertiary-container': 'tertiary90',
|
|
578
|
+
'tertiary-fixed': 'tertiary90',
|
|
579
|
+
'tertiary-fixed-dim': 'tertiary80',
|
|
580
|
+
};
|
|
581
|
+
const darkRoleToRefKeyMap = {
|
|
582
|
+
background: 'neutral6',
|
|
583
|
+
error: 'error80',
|
|
584
|
+
'error-container': 'error30',
|
|
585
|
+
'inverse-on-surface': 'neutral20',
|
|
586
|
+
'inverse-primary': 'primary40',
|
|
587
|
+
'inverse-surface': 'neutral90',
|
|
588
|
+
'on-background': 'neutral90',
|
|
589
|
+
'on-error': 'error20',
|
|
590
|
+
'on-error-container': 'error90',
|
|
591
|
+
'on-primary': 'primary20',
|
|
592
|
+
'on-primary-container': 'primary90',
|
|
593
|
+
'on-primary-fixed': 'primary10',
|
|
594
|
+
'on-primary-fixed-variant': 'primary30',
|
|
595
|
+
'on-secondary': 'secondary20',
|
|
596
|
+
'on-secondary-container': 'secondary90',
|
|
597
|
+
'on-secondary-fixed': 'secondary10',
|
|
598
|
+
'on-secondary-fixed-variant': 'secondary30',
|
|
599
|
+
'on-surface': 'neutral90',
|
|
600
|
+
'on-surface-variant': 'neutral-variant90',
|
|
601
|
+
'on-tertiary': 'tertiary20',
|
|
602
|
+
'on-tertiary-container': 'tertiary90',
|
|
603
|
+
'on-tertiary-fixed': 'tertiary10',
|
|
604
|
+
'on-tertiary-fixed-variant': 'tertiary30',
|
|
605
|
+
outline: 'neutral-variant60',
|
|
606
|
+
'outline-variant': 'neutral-variant30',
|
|
607
|
+
primary: 'primary80',
|
|
608
|
+
'primary-container': 'primary30',
|
|
609
|
+
'primary-fixed': 'primary90',
|
|
610
|
+
'primary-fixed-dim': 'primary80',
|
|
611
|
+
scrim: 'neutral0',
|
|
612
|
+
secondary: 'secondary80',
|
|
613
|
+
'secondary-container': 'secondary30',
|
|
614
|
+
'secondary-fixed': 'secondary90',
|
|
615
|
+
'secondary-fixed-dim': 'secondary80',
|
|
616
|
+
shadow: 'neutral0',
|
|
617
|
+
surface: 'neutral6',
|
|
618
|
+
'surface-bright': 'neutral24',
|
|
619
|
+
'surface-container': 'neutral12',
|
|
620
|
+
'surface-container-high': 'neutral17',
|
|
621
|
+
'surface-container-highest': 'neutral24',
|
|
622
|
+
'surface-container-low': 'neutral10',
|
|
623
|
+
'surface-container-lowest': 'neutral4',
|
|
624
|
+
'surface-dim': 'neutral6',
|
|
625
|
+
'surface-tint': 'primary80',
|
|
626
|
+
'surface-variant': 'neutral-variant30',
|
|
627
|
+
tertiary: 'tertiary80',
|
|
628
|
+
'tertiary-container': 'tertiary30',
|
|
629
|
+
'tertiary-fixed': 'tertiary90',
|
|
630
|
+
'tertiary-fixed-dim': 'tertiary80',
|
|
631
|
+
};
|
|
632
|
+
class ThemeColor {
|
|
633
|
+
static apply(document, { primary, secondary, tertiary, neutral, neutralVariant, error, }) {
|
|
634
|
+
const themeColor = new ThemeColor();
|
|
635
|
+
themeColor.apply(document, primary, secondary, tertiary, neutral, neutralVariant, error);
|
|
636
|
+
}
|
|
637
|
+
generateSystemLevelColors(primaryPalette, themeType, tertiaryPalette, cssVarPrefix = '--mat-sys-') {
|
|
638
|
+
const tertiary = tertiaryPalette ?? primaryPalette; // Default tertiary to primary
|
|
639
|
+
const output = {};
|
|
640
|
+
// 1. Create the flattened reference palette (md-ref-palette equivalent)
|
|
641
|
+
// We use kebab-case for keys like 'neutral-variant' to match the role maps.
|
|
642
|
+
const refPalette = {};
|
|
643
|
+
const palettesToFlatten = {
|
|
644
|
+
primary: primaryPalette,
|
|
645
|
+
secondary: primaryPalette.secondary,
|
|
646
|
+
tertiary: tertiary, // Use the resolved tertiary palette (just tones)
|
|
647
|
+
neutral: primaryPalette.neutral,
|
|
648
|
+
'neutral-variant': primaryPalette.neutralVariant,
|
|
649
|
+
error: primaryPalette.error,
|
|
650
|
+
};
|
|
651
|
+
for (const [name, palette] of Object.entries(palettesToFlatten)) {
|
|
652
|
+
if (!palette) {
|
|
653
|
+
console.warn(`Warning: Palette source '${name}' is missing or undefined.`);
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
for (const [tone, value] of Object.entries(palette)) {
|
|
657
|
+
// Check if the key is a valid tone number (string representation) and value is a string color
|
|
658
|
+
if (!isNaN(Number(tone)) && typeof value === 'string') {
|
|
659
|
+
const key = `${name}${tone}`; // e.g., primary40, neutral98, neutral-variant30
|
|
660
|
+
refPalette[key] = value;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
// 2. Select the correct role mapping based on theme type
|
|
665
|
+
const roleToRefKeyMap = themeType === 'light' ? lightRoleToRefKeyMap : darkRoleToRefKeyMap;
|
|
666
|
+
// 3. Generate CSS variables from the mapping
|
|
667
|
+
for (const [role, refKey] of Object.entries(roleToRefKeyMap)) {
|
|
668
|
+
const colorValue = refPalette[refKey];
|
|
669
|
+
if (colorValue === undefined) {
|
|
670
|
+
// Log a warning if a required reference color is missing in the provided palettes
|
|
671
|
+
console.warn(`Warning: Reference color key '${refKey}' not found in generated reference palette for CSS variable role '${role}'. Skipping variable '${cssVarPrefix}${role}'.`);
|
|
672
|
+
continue; // Skip this variable if the color isn't found
|
|
673
|
+
}
|
|
674
|
+
output[`${cssVarPrefix}${role}`] = colorValue;
|
|
675
|
+
}
|
|
676
|
+
// 4. Add the extra manually inserted colors (as per _m3-system.scss logic)
|
|
677
|
+
// These seem to be directly used sometimes instead of going through roles.
|
|
678
|
+
const extraRefKeys = {
|
|
679
|
+
'neutral-variant20': 'neutral-variant20', // Role name maps directly to ref key
|
|
680
|
+
neutral10: 'neutral10',
|
|
681
|
+
};
|
|
682
|
+
for (const [role, refKey] of Object.entries(extraRefKeys)) {
|
|
683
|
+
const colorValue = refPalette[refKey];
|
|
684
|
+
if (colorValue !== undefined) {
|
|
685
|
+
// Check if it wasn't already added via the main mapping (unlikely but safe)
|
|
686
|
+
if (!output[`${cssVarPrefix}${role}`]) {
|
|
687
|
+
output[`${cssVarPrefix}${role}`] = colorValue;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
console.warn(`Warning: Extra color key '${refKey}' not found in generated reference palette for role '${role}'.`);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return output;
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Helper function to convert a TonalPalette to a TonePalette.
|
|
698
|
+
* @param tonalPalette TonalPalette instance
|
|
699
|
+
* @returns TonePalette object
|
|
700
|
+
*/
|
|
701
|
+
convertTonalPalette(tonalPalette) {
|
|
702
|
+
const tones = [
|
|
703
|
+
0, 4, 6, 10, 12, 17, 20, 22, 24, 25, 30, 35, 40, 50, 60, 70, 80, 87, 90,
|
|
704
|
+
92, 94, 95, 96, 98, 99, 100,
|
|
705
|
+
];
|
|
706
|
+
const result = {};
|
|
707
|
+
for (const tone of tones) {
|
|
708
|
+
result[tone] = tonalPalette.tone(tone).toString(16).replace(/^ff/i, '#'); // Convert ARGB to HEX
|
|
709
|
+
}
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Converts a CorePalette into a BasePalette structure.
|
|
714
|
+
* @param corePalette CorePalette instance
|
|
715
|
+
* @returns BasePalette object
|
|
716
|
+
*/
|
|
717
|
+
convertCorePaletteToBasePalette(corePalette) {
|
|
718
|
+
return {
|
|
719
|
+
...this.convertTonalPalette(corePalette.a1), // Primary tones
|
|
720
|
+
secondary: this.convertTonalPalette(corePalette.a2),
|
|
721
|
+
tertiary: this.convertTonalPalette(corePalette.a3),
|
|
722
|
+
neutral: this.convertTonalPalette(corePalette.n1),
|
|
723
|
+
neutralVariant: this.convertTonalPalette(corePalette.n2),
|
|
724
|
+
error: this.convertTonalPalette(corePalette.error),
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
mergeLightAndDarkVars(lightVars, darkVars) {
|
|
728
|
+
const output = {};
|
|
729
|
+
for (const [key, value] of Object.entries(lightVars)) {
|
|
730
|
+
output[key] = value;
|
|
731
|
+
}
|
|
732
|
+
for (const [key, value] of Object.entries(darkVars)) {
|
|
733
|
+
output[key] = `light-dark(${output[key]}, ${value})`;
|
|
734
|
+
}
|
|
735
|
+
return output;
|
|
736
|
+
}
|
|
737
|
+
convertBasePaletteToCss(lightDarkVars) {
|
|
738
|
+
return `:root {
|
|
739
|
+
${Object.entries(lightDarkVars)
|
|
740
|
+
.map(([key, value]) => `${key}: ${value};`)
|
|
741
|
+
.join('\n ')}
|
|
742
|
+
}
|
|
743
|
+
`;
|
|
744
|
+
}
|
|
745
|
+
apply(document, primary, secondary, tertiary, neutral, neutralVariant, error) {
|
|
746
|
+
const corePalette = CorePalette.fromColors({
|
|
747
|
+
primary: parseInt(primary.replace('#', 'FF'), 16),
|
|
748
|
+
secondary: secondary
|
|
749
|
+
? parseInt(secondary.replace('#', 'FF'), 16)
|
|
750
|
+
: undefined,
|
|
751
|
+
tertiary: tertiary
|
|
752
|
+
? parseInt(tertiary.replace('#', 'FF'), 16)
|
|
753
|
+
: undefined,
|
|
754
|
+
neutral: neutral ? parseInt(neutral.replace('#', 'FF'), 16) : undefined,
|
|
755
|
+
neutralVariant: neutralVariant
|
|
756
|
+
? parseInt(neutralVariant.replace('#', 'FF'), 16)
|
|
757
|
+
: undefined,
|
|
758
|
+
error: error ? parseInt(error.replace('#', 'FF'), 16) : undefined,
|
|
759
|
+
});
|
|
760
|
+
const basePalette = this.convertCorePaletteToBasePalette(corePalette);
|
|
761
|
+
const lightVars = this.generateSystemLevelColors(basePalette, 'light');
|
|
762
|
+
const darkVars = this.generateSystemLevelColors(basePalette, 'dark');
|
|
763
|
+
const lightDarkVars = this.mergeLightAndDarkVars(lightVars, darkVars);
|
|
764
|
+
for (const [key, value] of Object.entries(lightDarkVars)) {
|
|
765
|
+
document.documentElement.style.setProperty(key, value);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function applyThemeColorBootstrapHook(defaultThemeControls) {
|
|
770
|
+
return (config) => {
|
|
771
|
+
const themeColors = config.get('theme.colors', defaultThemeControls);
|
|
772
|
+
if (themeColors) {
|
|
773
|
+
ThemeColor.apply(window.document, themeColors);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
447
778
|
// region
|
|
448
779
|
// endregion
|
|
449
780
|
|
|
@@ -451,5 +782,5 @@ function provideTheme() {
|
|
|
451
782
|
* Generated bundle index. Do not edit.
|
|
452
783
|
*/
|
|
453
784
|
|
|
454
|
-
export { ColorPaletteAlgorithm, ComputeColorPalette, ObserveCurrentThemeDensity, ThemeService, provideTheme };
|
|
785
|
+
export { ColorPaletteAlgorithm, ComputeColorPalette, ObserveCurrentThemeDensity, THEME_SETTING_KEY, ThemeColor, ThemeModeService, ThemeService, applyThemeColorBootstrapHook, provideTheme };
|
|
455
786
|
//# sourceMappingURL=rxap-ngx-theme.mjs.map
|