@ecodev/natural 66.0.0 → 66.0.2

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.
@@ -8,8 +8,8 @@ import * as i1 from '@angular/material/dialog';
8
8
  import { MAT_DIALOG_DATA, MatDialogModule, MatDialog, MatDialogRef } from '@angular/material/dialog';
9
9
  import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar';
10
10
  import { MatButton, MatIconButton, MatFabButton } from '@angular/material/button';
11
- import { Observable, switchMap, take, BehaviorSubject, of, timer, tap, endWith, last, EMPTY, finalize, Subject, merge as merge$1, first as first$1, takeUntil as takeUntil$1, map as map$1, ReplaySubject, debounceTime, raceWith, mergeMap, shareReplay, catchError, forkJoin, combineLatest, from, filter as filter$1, startWith as startWith$1, asyncScheduler, throwError } from 'rxjs';
12
- import { takeUntilDestroyed, outputFromObservable } from '@angular/core/rxjs-interop';
11
+ import { Observable, switchMap, take, BehaviorSubject, of, timer, tap, endWith, last, EMPTY, finalize, Subject, merge as merge$1, first as first$1, takeUntil as takeUntil$1, map as map$1, ReplaySubject, debounceTime, raceWith, mergeMap, shareReplay, catchError, forkJoin, combineLatest, from, fromEvent, filter as filter$1, startWith as startWith$1, asyncScheduler, throwError } from 'rxjs';
12
+ import { takeUntilDestroyed, toSignal, outputFromObservable } from '@angular/core/rxjs-interop';
13
13
  import { filter, switchMap as switchMap$1, first, map, takeUntil, takeWhile, debounceTime as debounceTime$1, tap as tap$1, shareReplay as shareReplay$1, startWith, distinctUntilChanged, finalize as finalize$1, throttleTime } from 'rxjs/operators';
14
14
  import { mergeWith, defaultsDeep, pick, defaults, isEmpty, isEqual as isEqual$1 } from 'es-toolkit/compat';
15
15
  import { MatTableDataSource, MatTable, MatHeaderCellDef, MatHeaderRowDef, MatColumnDef, MatCellDef, MatRowDef, MatHeaderCell, MatCell, MatHeaderRow, MatRow } from '@angular/material/table';
@@ -5327,9 +5327,22 @@ class NaturalThemeService {
5327
5327
  storage = inject(LOCAL_STORAGE);
5328
5328
  platformId = inject(PLATFORM_ID);
5329
5329
  document = inject(DOCUMENT);
5330
- isDark = signal(false, ...(ngDevMode ? [{ debugName: "isDark" }] : []));
5330
+ isDarkSystem = toSignal(isPlatformBrowser(this.platformId)
5331
+ ? fromEvent(this.document.defaultView.matchMedia('(prefers-color-scheme: dark)'), 'change').pipe(startWith(this.document.defaultView.matchMedia('(prefers-color-scheme: dark)')), map$1(e => e.matches))
5332
+ : of(false), { initialValue: false });
5333
+ isDark = computed(() => {
5334
+ return (this.colorScheme() === ColorScheme.Dark || (this.colorScheme() === ColorScheme.Auto && this.isDarkSystem()));
5335
+ }, ...(ngDevMode ? [{ debugName: "isDark" }] : []));
5331
5336
  theme = signal(this.allThemes[0], ...(ngDevMode ? [{ debugName: "theme" }] : []));
5332
- colorScheme = signal(ColorScheme.Light, ...(ngDevMode ? [{ debugName: "colorScheme" }] : []));
5337
+ colorScheme = signal(ColorScheme.Auto, ...(ngDevMode ? [{ debugName: "colorScheme" }] : []));
5338
+ constructor() {
5339
+ effect(() => {
5340
+ this.document.documentElement.setAttribute('data-is-dark', this.isDark() ? 'true' : 'false');
5341
+ });
5342
+ const storedScheme = this.storage.getItem('color-scheme');
5343
+ const isValidScheme = storedScheme && Object.values(ColorScheme).includes(storedScheme);
5344
+ this.colorScheme.set(isValidScheme ? storedScheme : ColorScheme.Auto);
5345
+ }
5333
5346
  /**
5334
5347
  * Set theme in memory, local storage and dom
5335
5348
  */
@@ -5339,18 +5352,11 @@ class NaturalThemeService {
5339
5352
  this.document.documentElement.setAttribute('data-theme', name);
5340
5353
  }
5341
5354
  /**
5342
- * Set color scheme in memory, local storage and dom and keep in sync isDark property
5355
+ * Set dark/light/auto
5343
5356
  */
5344
5357
  setColorScheme(scheme, persistInStorage = true) {
5345
5358
  this.colorScheme.set(scheme); // memory
5346
5359
  this.document.documentElement.setAttribute('data-color-scheme', scheme); // dom
5347
- // If manual dark, or auto + dark system
5348
- const dark = scheme === ColorScheme.Dark ||
5349
- (scheme === ColorScheme.Auto &&
5350
- isPlatformBrowser(this.platformId) &&
5351
- !!this.document.defaultView?.matchMedia('(prefers-color-scheme: dark)').matches);
5352
- this.isDark.set(dark); // memory
5353
- this.document.documentElement.setAttribute('data-is-dark', dark ? 'true' : 'false'); // dom;
5354
5360
  if (persistInStorage) {
5355
5361
  this.storage.setItem('color-scheme', this.colorScheme()); // storage
5356
5362
  }
@@ -5363,7 +5369,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImpor
5363
5369
  args: [{
5364
5370
  providedIn: 'root',
5365
5371
  }]
5366
- }] });
5372
+ }], ctorParameters: () => [] });
5367
5373
 
5368
5374
  const patterns = [
5369
5375
  /^(?<day>\d{1,2})\.(?<month>\d{1,2})\.(?<year>\d{4}|\d{2})$/,