@arsedizioni/ars-utils 18.2.339 → 18.2.341

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.
@@ -7,7 +7,7 @@ import { HttpParams } from '@angular/common/http';
7
7
  import { fromZonedTime } from 'date-fns-tz';
8
8
  import { NG_VALIDATORS } from '@angular/forms';
9
9
  import { debounceTime } from 'rxjs/operators';
10
- import { Subject } from 'rxjs';
10
+ import { Subject, BehaviorSubject } from 'rxjs';
11
11
  import { DateAdapter, MAT_DATE_LOCALE, MAT_DATE_FORMATS } from '@angular/material/core';
12
12
  import { SelectionModel } from '@angular/cdk/collections';
13
13
 
@@ -1928,6 +1928,18 @@ class ThemeService {
1928
1928
  this.broadcastMessage = '$theme-changed';
1929
1929
  // per intercettare il cambio di tema a livello di sistema
1930
1930
  this.prefersColorSchemeMediaQueryList = window.matchMedia('(prefers-color-scheme: dark)');
1931
+ /**
1932
+ * Theme changed event.
1933
+ * Notify the consuming component about the incoming theme change.
1934
+ * @example
1935
+ * // React to theme changes
1936
+ * this.themeService.themeChanged
1937
+ * .pipe(takeUntil(this.unsubscribe))
1938
+ * .subscribe((value: ThemeType) => {
1939
+ * // do the job done....
1940
+ * });
1941
+ */
1942
+ this.themeChanged = new BehaviorSubject('auto');
1931
1943
  this.renderFactory2 = inject(RendererFactory2);
1932
1944
  this.renderer = this.renderFactory2.createRenderer(null, null);
1933
1945
  /**
@@ -1982,14 +1994,20 @@ class ThemeService {
1982
1994
  this.broadcastChannel.dispose();
1983
1995
  }
1984
1996
  /**
1985
- * Load current theme
1997
+ * Get the current preferred theme
1986
1998
  */
1987
- loadTheme() {
1999
+ getPreferredTheme() {
1988
2000
  let theme = localStorage.getItem("preferred-theme");
1989
2001
  if (!this.isTheme(theme)) {
1990
2002
  theme = 'auto';
1991
2003
  }
1992
- this.setTheme(theme);
2004
+ return theme;
2005
+ }
2006
+ /**
2007
+ * Load theme
2008
+ */
2009
+ loadTheme() {
2010
+ this.setTheme(this.getPreferredTheme());
1993
2011
  }
1994
2012
  /**
1995
2013
  * Check if a value string is a theme type
@@ -2009,6 +2027,8 @@ class ThemeService {
2009
2027
  this.theme.set(theme);
2010
2028
  localStorage.setItem("preferred-theme", this.theme());
2011
2029
  this.renderer.addClass(document.body, this.auto() ? (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : theme);
2030
+ // Notify that current theme has changed
2031
+ this.themeChanged.next(this.getTheme());
2012
2032
  this.broadcastChannel.sendMessage(this.broadcastMessage, this.theme());
2013
2033
  }
2014
2034
  /**
@@ -2018,14 +2038,12 @@ class ThemeService {
2018
2038
  this.setTheme(this.themeInfo[this.theme()].next);
2019
2039
  }
2020
2040
  /**
2021
- * Get current active theme
2022
- * // Load current theme
2041
+ * Get current real theme: light or dark
2023
2042
  */
2024
2043
  getTheme() {
2025
- this.loadTheme();
2026
2044
  return (this.auto()
2027
2045
  ? (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light")
2028
- : this.theme());
2046
+ : this.getPreferredTheme());
2029
2047
  }
2030
2048
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.1.3", ngImport: i0, type: ThemeService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2031
2049
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.1.3", ngImport: i0, type: ThemeService, providedIn: "root" }); }