@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.
Files changed (89) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +86 -1
  3. package/compodoc/changelog.html +10 -0
  4. package/compodoc/classes/ThemeColor.html +874 -0
  5. package/compodoc/dependencies.html +6 -4
  6. package/compodoc/index.html +70 -2
  7. package/compodoc/injectables/ThemeModeService.html +1256 -0
  8. package/compodoc/injectables/ThemeService.html +82 -265
  9. package/compodoc/interfaces/BasePalette.html +844 -0
  10. package/compodoc/interfaces/ColorPaletteConfig.html +6 -71
  11. package/compodoc/interfaces/ColorPaletteConfigWithName.html +6 -71
  12. package/compodoc/interfaces/ThemeColors.html +898 -0
  13. package/compodoc/interfaces/ThemeConfig.html +6 -71
  14. package/compodoc/js/menu-wc.js +25 -0
  15. package/compodoc/js/menu-wc_es5.js +1 -1
  16. package/compodoc/js/search/search_index.js +2 -2
  17. package/compodoc/miscellaneous/functions.html +60 -1
  18. package/compodoc/miscellaneous/typealiases.html +364 -0
  19. package/compodoc/miscellaneous/variables.html +193 -0
  20. package/compodoc/overview.html +10 -2
  21. package/compodoc/properties.html +1 -1
  22. package/docs/documentation.json +2294 -530
  23. package/docs/html/assets/hierarchy.js +1 -1
  24. package/docs/html/assets/highlight.css +28 -0
  25. package/docs/html/assets/navigation.js +1 -1
  26. package/docs/html/assets/search.js +1 -1
  27. package/docs/html/classes/ThemeColor.html +4 -0
  28. package/docs/html/classes/ThemeModeService.html +35 -0
  29. package/docs/html/classes/ThemeService.html +4 -6
  30. package/docs/html/enums/ColorPaletteAlgorithm.html +2 -2
  31. package/docs/html/functions/ComputeColorPalette.html +1 -1
  32. package/docs/html/functions/ObserveCurrentThemeDensity.html +1 -1
  33. package/docs/html/functions/applyThemeColorBootstrapHook.html +1 -0
  34. package/docs/html/functions/provideTheme.html +1 -1
  35. package/docs/html/hierarchy.html +1 -1
  36. package/docs/html/index.html +61 -3
  37. package/docs/html/interfaces/ColorPalette.html +2 -2
  38. package/docs/html/interfaces/ColorPaletteConfig.html +2 -2
  39. package/docs/html/interfaces/ColorPaletteConfigWithName.html +2 -2
  40. package/docs/html/interfaces/ThemeColors.html +7 -0
  41. package/docs/html/interfaces/ThemeConfig.html +2 -2
  42. package/docs/html/modules.html +1 -1
  43. package/docs/html/types/ActiveTheme.html +1 -0
  44. package/docs/html/types/ThemeSetting.html +1 -0
  45. package/docs/html/variables/THEME_SETTING_KEY.html +1 -0
  46. package/docs/markdown/README.md +87 -2
  47. package/docs/markdown/classes/ThemeColor.md +83 -0
  48. package/docs/markdown/classes/ThemeModeService.md +282 -0
  49. package/docs/markdown/classes/ThemeService.md +39 -69
  50. package/docs/markdown/enumerations/ColorPaletteAlgorithm.md +4 -4
  51. package/docs/markdown/functions/ComputeColorPalette.md +2 -2
  52. package/docs/markdown/functions/ObserveCurrentThemeDensity.md +2 -2
  53. package/docs/markdown/functions/applyThemeColorBootstrapHook.md +31 -0
  54. package/docs/markdown/functions/provideTheme.md +2 -2
  55. package/docs/markdown/globals.md +15 -2
  56. package/docs/markdown/interfaces/ColorPalette.md +16 -16
  57. package/docs/markdown/interfaces/ColorPaletteConfig.md +5 -5
  58. package/docs/markdown/interfaces/ColorPaletteConfigWithName.md +6 -6
  59. package/docs/markdown/interfaces/ThemeColors.md +57 -0
  60. package/docs/markdown/interfaces/ThemeConfig.md +7 -7
  61. package/docs/markdown/type-aliases/ActiveTheme.md +11 -0
  62. package/docs/markdown/type-aliases/ThemeSetting.md +11 -0
  63. package/docs/markdown/variables/THEME_SETTING_KEY.md +11 -0
  64. package/docs/wiki/Class.ThemeColor.md +79 -0
  65. package/docs/wiki/Class.ThemeModeService.md +278 -0
  66. package/docs/wiki/Class.ThemeService.md +38 -68
  67. package/docs/wiki/Enumeration.ColorPaletteAlgorithm.md +3 -3
  68. package/docs/wiki/Function.ComputeColorPalette.md +1 -1
  69. package/docs/wiki/Function.ObserveCurrentThemeDensity.md +1 -1
  70. package/docs/wiki/Function.applyThemeColorBootstrapHook.md +27 -0
  71. package/docs/wiki/Function.provideTheme.md +1 -1
  72. package/docs/wiki/Home.md +86 -1
  73. package/docs/wiki/Interface.ColorPalette.md +15 -15
  74. package/docs/wiki/Interface.ColorPaletteConfig.md +4 -4
  75. package/docs/wiki/Interface.ColorPaletteConfigWithName.md +5 -5
  76. package/docs/wiki/Interface.ThemeColors.md +53 -0
  77. package/docs/wiki/Interface.ThemeConfig.md +6 -6
  78. package/docs/wiki/TypeAlias.ActiveTheme.md +7 -0
  79. package/docs/wiki/TypeAlias.ThemeSetting.md +7 -0
  80. package/docs/wiki/Variable.THEME_SETTING_KEY.md +7 -0
  81. package/docs/wiki/_Sidebar.md +13 -0
  82. package/docs/wiki/globals.md +14 -1
  83. package/fesm2022/rxap-ngx-theme.mjs +392 -61
  84. package/fesm2022/rxap-ngx-theme.mjs.map +1 -1
  85. package/index.d.ts +2 -0
  86. package/lib/theme-color.d.ts +29 -0
  87. package/lib/theme-mode.service.d.ts +61 -0
  88. package/lib/theme.service.d.ts +3 -5
  89. package/package.json +13 -12
@@ -316,6 +316,7 @@ import {
316
316
  ColorPalette,
317
317
  ComputeColorPalette,
318
318
  } from './compute-color-palette';
319
+ import { ThemeModeService } from './theme-mode.service';
319
320
 
320
321
  export interface ColorPaletteConfigWithName extends ColorPaletteConfig {
321
322
  name?: string;
@@ -341,39 +342,25 @@ export class ThemeService {
341
342
  public readonly config = inject(ConfigService);
342
343
  public readonly pubSub = inject(PubSubService);
343
344
 
344
- public readonly darkMode: WritableSignal<boolean>;
345
+ public readonly themeModeService = inject(ThemeModeService);
346
+
347
+ public readonly darkMode = this.themeModeService.darkMode;
345
348
  public readonly themeName: WritableSignal<string>;
346
349
  public readonly density: WritableSignal<ThemeDensity>;
347
350
  public readonly typography: WritableSignal<string>;
348
351
 
349
- protected readonly darkModeMediaQuery: MediaQueryList;
350
-
351
352
  protected syncSubscription?: Subscription;
352
353
 
353
354
  constructor(private readonly mediaMatcher: MediaMatcher) {
354
- this.darkModeMediaQuery = this.mediaMatcher.matchMedia('(prefers-color-scheme: dark)');
355
- this.darkMode = signal(this.darkModeMediaQuery.matches);
356
355
  this.themeName = signal(this.getTheme());
357
356
  this.density = signal(this.getDensity());
358
357
  this.typography = signal(this.getTypography());
359
- this.darkModeMediaQuery.addEventListener('change', (event) => {
360
- this.setDarkTheme(event.matches, true);
361
- });
362
358
  }
363
359
 
364
360
  public restore() {
365
361
  if (isDevMode()) {
366
362
  console.log('Restore theme settings from local storage');
367
363
  }
368
- // region restore dark mode
369
- let darkMode = this.restoreDarkMode();
370
- // if the dark/light mode is not restored from the local storage
371
- if (darkMode === null) {
372
- // set the dark mode based on the media query
373
- darkMode = this.darkModeMediaQuery.matches;
374
- this.setDarkTheme(darkMode, true);
375
- }
376
- // endregion
377
364
 
378
365
  this.restoreThemeName();
379
366
  this.restoreDensity();
@@ -405,18 +392,6 @@ export class ThemeService {
405
392
  isDefined(),
406
393
  tap(data => this.setTypography(data, false, false))
407
394
  ).subscribe());
408
- this.syncSubscription.add(this.pubSub.subscribe<boolean>(RXAP_TOPICS.theme.darkMode.restore).pipe(
409
- debounceTime(1000),
410
- map(event => event.data),
411
- isDefined(),
412
- tap(data => this.setDarkTheme(data, false, false))
413
- ).subscribe());
414
- }
415
-
416
- private get darkModeLocalStorageKey() {
417
- return (
418
- window as any
419
- )?.['__rxap__']?.['ngx']?.['theme']?.['darkMode']?.['key'] ?? `rxap-dark-mode`;
420
395
  }
421
396
 
422
397
  private get themeNameLocalStorageKey() {
@@ -439,21 +414,6 @@ export class ThemeService {
439
414
 
440
415
  // region restore
441
416
 
442
- public restoreDarkMode() {
443
- let darkMode: boolean | null = null;
444
- const darkModeCached = localStorage.getItem(this.darkModeLocalStorageKey);
445
- if (darkModeCached === 'true') {
446
- darkMode = true;
447
- }
448
- if (darkModeCached === 'false') {
449
- darkMode = false;
450
- }
451
- if (darkMode !== null) {
452
- this.setDarkTheme(darkMode, true);
453
- }
454
- return darkMode;
455
- }
456
-
457
417
  public restoreThemeName() {
458
418
  const themeName = localStorage.getItem(this.themeNameLocalStorageKey);
459
419
  if (themeName) {
@@ -485,22 +445,13 @@ export class ThemeService {
485
445
  // endregion
486
446
 
487
447
  public toggleDarkTheme(): void {
488
- this.setDarkTheme(!this.darkMode());
448
+ this.themeModeService.toggleTheme();
489
449
  }
490
450
 
491
451
  // region set theme configuration state
492
452
 
493
453
  public setDarkTheme(darkMode: boolean, silent = false, publish = true): void {
494
- this.applyDarkMode(darkMode);
495
- if (this.darkMode() !== darkMode) {
496
- this.darkMode.set(darkMode);
497
- if (!silent) {
498
- localStorage.setItem(this.darkModeLocalStorageKey, String(darkMode));
499
- if (publish) {
500
- this.pubSub.publish(RXAP_TOPICS.theme.darkMode.changed, darkMode);
501
- }
502
- }
503
- }
454
+ this.themeModeService.setTheme(darkMode ? 'dark' : 'light', publish);
504
455
  }
505
456
 
506
457
  public setDensity(density: ThemeDensity, silent = false, publish = true): void {
@@ -548,22 +499,6 @@ export class ThemeService {
548
499
 
549
500
  // region apply theme configuration state
550
501
 
551
- public applyDarkMode(darkMode: boolean): void {
552
- if (darkMode) {
553
- // region deprecated
554
- document.body.classList.add('dark-theme');
555
- localStorage.removeItem('rxap-light-theme');
556
- // endregion
557
- document.body.classList.add('dark');
558
- } else {
559
- // region deprecated
560
- document.body.classList.remove('dark-theme');
561
- localStorage.setItem('rxap-light-theme', 'true');
562
- // endregion
563
- document.body.classList.remove('dark');
564
- }
565
- }
566
-
567
502
  public applyDensity(density: ThemeDensity): void {
568
503
  document.body.classList.remove('density-0', 'density-1', 'density-2', 'density-3');
569
504
  if (density < 0) {
@@ -232,6 +232,7 @@ import {
232
232
  ColorPalette,
233
233
  ComputeColorPalette,
234
234
  } from './compute-color-palette';
235
+ import { ThemeModeService } from './theme-mode.service';
235
236
 
236
237
  export interface ColorPaletteConfigWithName extends ColorPaletteConfig {
237
238
  name?: string;
@@ -257,39 +258,25 @@ export class ThemeService {
257
258
  public readonly config = inject(ConfigService);
258
259
  public readonly pubSub = inject(PubSubService);
259
260
 
260
- public readonly darkMode: WritableSignal<boolean>;
261
+ public readonly themeModeService = inject(ThemeModeService);
262
+
263
+ public readonly darkMode = this.themeModeService.darkMode;
261
264
  public readonly themeName: WritableSignal<string>;
262
265
  public readonly density: WritableSignal<ThemeDensity>;
263
266
  public readonly typography: WritableSignal<string>;
264
267
 
265
- protected readonly darkModeMediaQuery: MediaQueryList;
266
-
267
268
  protected syncSubscription?: Subscription;
268
269
 
269
270
  constructor(private readonly mediaMatcher: MediaMatcher) {
270
- this.darkModeMediaQuery = this.mediaMatcher.matchMedia('(prefers-color-scheme: dark)');
271
- this.darkMode = signal(this.darkModeMediaQuery.matches);
272
271
  this.themeName = signal(this.getTheme());
273
272
  this.density = signal(this.getDensity());
274
273
  this.typography = signal(this.getTypography());
275
- this.darkModeMediaQuery.addEventListener('change', (event) => {
276
- this.setDarkTheme(event.matches, true);
277
- });
278
274
  }
279
275
 
280
276
  public restore() {
281
277
  if (isDevMode()) {
282
278
  console.log('Restore theme settings from local storage');
283
279
  }
284
- // region restore dark mode
285
- let darkMode = this.restoreDarkMode();
286
- // if the dark/light mode is not restored from the local storage
287
- if (darkMode === null) {
288
- // set the dark mode based on the media query
289
- darkMode = this.darkModeMediaQuery.matches;
290
- this.setDarkTheme(darkMode, true);
291
- }
292
- // endregion
293
280
 
294
281
  this.restoreThemeName();
295
282
  this.restoreDensity();
@@ -321,18 +308,6 @@ export class ThemeService {
321
308
  isDefined(),
322
309
  tap(data => this.setTypography(data, false, false))
323
310
  ).subscribe());
324
- this.syncSubscription.add(this.pubSub.subscribe<boolean>(RXAP_TOPICS.theme.darkMode.restore).pipe(
325
- debounceTime(1000),
326
- map(event => event.data),
327
- isDefined(),
328
- tap(data => this.setDarkTheme(data, false, false))
329
- ).subscribe());
330
- }
331
-
332
- private get darkModeLocalStorageKey() {
333
- return (
334
- window as any
335
- )?.['__rxap__']?.['ngx']?.['theme']?.['darkMode']?.['key'] ?? `rxap-dark-mode`;
336
311
  }
337
312
 
338
313
  private get themeNameLocalStorageKey() {
@@ -355,21 +330,6 @@ export class ThemeService {
355
330
 
356
331
  // region restore
357
332
 
358
- public restoreDarkMode() {
359
- let darkMode: boolean | null = null;
360
- const darkModeCached = localStorage.getItem(this.darkModeLocalStorageKey);
361
- if (darkModeCached === 'true') {
362
- darkMode = true;
363
- }
364
- if (darkModeCached === 'false') {
365
- darkMode = false;
366
- }
367
- if (darkMode !== null) {
368
- this.setDarkTheme(darkMode, true);
369
- }
370
- return darkMode;
371
- }
372
-
373
333
  public restoreThemeName() {
374
334
  const themeName = localStorage.getItem(this.themeNameLocalStorageKey);
375
335
  if (themeName) {
@@ -401,22 +361,13 @@ export class ThemeService {
401
361
  // endregion
402
362
 
403
363
  public toggleDarkTheme(): void {
404
- this.setDarkTheme(!this.darkMode());
364
+ this.themeModeService.toggleTheme();
405
365
  }
406
366
 
407
367
  // region set theme configuration state
408
368
 
409
369
  public setDarkTheme(darkMode: boolean, silent = false, publish = true): void {
410
- this.applyDarkMode(darkMode);
411
- if (this.darkMode() !== darkMode) {
412
- this.darkMode.set(darkMode);
413
- if (!silent) {
414
- localStorage.setItem(this.darkModeLocalStorageKey, String(darkMode));
415
- if (publish) {
416
- this.pubSub.publish(RXAP_TOPICS.theme.darkMode.changed, darkMode);
417
- }
418
- }
419
- }
370
+ this.themeModeService.setTheme(darkMode ? 'dark' : 'light', publish);
420
371
  }
421
372
 
422
373
  public setDensity(density: ThemeDensity, silent = false, publish = true): void {
@@ -464,22 +415,6 @@ export class ThemeService {
464
415
 
465
416
  // region apply theme configuration state
466
417
 
467
- public applyDarkMode(darkMode: boolean): void {
468
- if (darkMode) {
469
- // region deprecated
470
- document.body.classList.add('dark-theme');
471
- localStorage.removeItem('rxap-light-theme');
472
- // endregion
473
- document.body.classList.add('dark');
474
- } else {
475
- // region deprecated
476
- document.body.classList.remove('dark-theme');
477
- localStorage.setItem('rxap-light-theme', 'true');
478
- // endregion
479
- document.body.classList.remove('dark');
480
- }
481
- }
482
-
483
418
  public applyDensity(density: ThemeDensity): void {
484
419
  document.body.classList.remove('density-0', 'density-1', 'density-2', 'density-3');
485
420
  if (density < 0) {