@ecodev/natural 66.0.14 → 66.0.15

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, Component, Injectable, DestroyRef, HostListener, HostBinding, Directive, InjectionToken, ElementRef, viewChild, ViewEncapsulation, Injector, Input, input, PLATFORM_ID, signal, provideAppInitializer, DOCUMENT, computed, effect, output, Pipe, LOCALE_ID, contentChild, TemplateRef, EnvironmentInjector, createEnvironmentInjector, createComponent, runInInjectionContext, ChangeDetectionStrategy, linkedSignal, ErrorHandler, importProvidersFrom } from '@angular/core';
2
+ import { inject, Component, Injectable, DestroyRef, HostListener, HostBinding, Directive, InjectionToken, ElementRef, viewChild, ViewEncapsulation, Injector, Input, input, PLATFORM_ID, signal, makeEnvironmentProviders, provideAppInitializer, DOCUMENT, computed, effect, output, Pipe, LOCALE_ID, contentChild, TemplateRef, EnvironmentInjector, createEnvironmentInjector, createComponent, runInInjectionContext, ChangeDetectionStrategy, linkedSignal, ErrorHandler, importProvidersFrom } from '@angular/core';
3
3
  import * as i1$1 from '@angular/forms';
4
4
  import { FormGroup, FormArray, Validators, UntypedFormGroup, UntypedFormArray, FormControl, FormsModule, ReactiveFormsModule, UntypedFormControl, NgControl, FormControlDirective, FormControlName } from '@angular/forms';
5
5
  import { NavigationStart, NavigationEnd, ActivatedRoute, Router, RouteConfigLoadStart, RouteConfigLoadEnd, PRIMARY_OUTLET, RouterLink, NavigationError, DefaultUrlSerializer, UrlTree } from '@angular/router';
@@ -196,17 +196,18 @@ function formatIsoDateTime(date) {
196
196
  const timezoneOffsetInMinutes = Math.round(date.getTimezoneOffset());
197
197
  const timezoneOffsetInHours = -Math.trunc(timezoneOffsetInMinutes / 60); // UTC minus local time
198
198
  const sign = timezoneOffsetInHours >= 0 ? '+' : '-';
199
- const remainderMinutes = -(timezoneOffsetInMinutes % 60);
199
+ const remainderMinutes = -timezoneOffsetInMinutes % 60;
200
200
  // It's a bit unfortunate that we need to construct a new Date instance,
201
201
  // but we don't want the original Date instance to be modified
202
202
  const correctedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
203
203
  correctedDate.setHours(date.getHours() + timezoneOffsetInHours);
204
+ correctedDate.setMinutes(date.getMinutes() + remainderMinutes);
204
205
  const iso = correctedDate
205
206
  .toISOString()
206
207
  .replace(/\.\d{3}Z/, '')
207
208
  .replace('Z', '');
208
209
  const hours = Math.abs(timezoneOffsetInHours).toString().padStart(2, '0');
209
- const minutes = remainderMinutes.toString().padStart(2, '0');
210
+ const minutes = Math.abs(remainderMinutes).toString().padStart(2, '0');
210
211
  return iso + sign + hours + ':' + minutes;
211
212
  }
212
213
  /**
@@ -5329,8 +5330,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.7", ngImpor
5329
5330
  }] });
5330
5331
 
5331
5332
  const NATURAL_THEMES_CONFIG = new InjectionToken('Configuration for Natural Theme');
5333
+ /**
5334
+ * If you are using themes, or color scheme, then you must provide themes at the application level.
5335
+ *
5336
+ * If there is a only one theme, you still need to provide a name for it (eg: "my-app"), even if
5337
+ * it is not used in the SCSS.
5338
+ */
5332
5339
  function provideThemes(config) {
5333
- return [
5340
+ return makeEnvironmentProviders([
5334
5341
  {
5335
5342
  provide: NATURAL_THEMES_CONFIG,
5336
5343
  useValue: config,
@@ -5338,7 +5345,7 @@ function provideThemes(config) {
5338
5345
  provideAppInitializer(() => {
5339
5346
  inject(NaturalThemeService);
5340
5347
  }),
5341
- ];
5348
+ ]);
5342
5349
  }
5343
5350
  var ColorScheme;
5344
5351
  (function (ColorScheme) {
@@ -5351,11 +5358,17 @@ const colorSchemeOptions = [
5351
5358
  { value: ColorScheme.Light, label: $localize `Thème clair`, icon: 'light_mode' },
5352
5359
  { value: ColorScheme.Dark, label: $localize `Thème sombre`, icon: 'dark_mode' },
5353
5360
  ];
5361
+ /**
5362
+ * The source of truth is the DOM. And thus the index.html (or equivalent) must use vanilla JavaScript
5363
+ * to restore `data-color-scheme` and `data-theme` attributes on the `<html>` element (eg: from
5364
+ * local storage, or from DB).
5365
+ */
5354
5366
  class NaturalThemeService {
5355
5367
  allThemes = inject(NATURAL_THEMES_CONFIG);
5356
5368
  storage = inject(LOCAL_STORAGE);
5357
5369
  platformId = inject(PLATFORM_ID);
5358
5370
  document = inject(DOCUMENT);
5371
+ htmlElement = this.document.documentElement;
5359
5372
  isDarkSystem = toSignal(isPlatformBrowser(this.platformId)
5360
5373
  ? fromEvent(this.document.defaultView.matchMedia('(prefers-color-scheme: dark)'), 'change').pipe(startWith$1(this.document.defaultView.matchMedia('(prefers-color-scheme: dark)')), map$1(e => e.matches))
5361
5374
  : of(false), { initialValue: false });
@@ -5374,28 +5387,28 @@ class NaturalThemeService {
5374
5387
  colorScheme = this._colorScheme.asReadonly();
5375
5388
  constructor() {
5376
5389
  effect(() => {
5377
- this.document.documentElement.setAttribute('data-is-dark', this.isDark() ? 'true' : 'false');
5390
+ this.htmlElement.setAttribute('data-is-dark', this.isDark() ? 'true' : 'false');
5378
5391
  });
5379
5392
  const storedScheme = this.storage.getItem('color-scheme');
5380
5393
  const isValidScheme = storedScheme && Object.values(ColorScheme).includes(storedScheme);
5381
5394
  this._colorScheme.set(isValidScheme ? storedScheme : ColorScheme.Auto);
5382
5395
  }
5383
5396
  /**
5384
- * Set theme in memory, local storage and dom
5397
+ * Set theme in memory and dom
5385
5398
  */
5386
5399
  setTheme(theme) {
5387
5400
  if (!this.allThemes.includes(theme)) {
5388
5401
  throw new Error(`Expecting one of the configured themes: ${this.allThemes.map(t => `'${t}'`).join(', ')}. But got invalid: '${theme}'`);
5389
5402
  }
5390
5403
  this._theme.set(theme);
5391
- this.document.documentElement.setAttribute('data-theme', theme);
5404
+ this.htmlElement.setAttribute('data-theme', theme);
5392
5405
  }
5393
5406
  /**
5394
5407
  * Set dark/light/auto
5395
5408
  */
5396
5409
  setColorScheme(scheme, persistInStorage = true) {
5397
5410
  this._colorScheme.set(scheme); // memory
5398
- this.document.documentElement.setAttribute('data-color-scheme', scheme); // dom
5411
+ this.htmlElement.setAttribute('data-color-scheme', scheme); // dom
5399
5412
  if (persistInStorage) {
5400
5413
  this.storage.setItem('color-scheme', this.colorScheme()); // storage
5401
5414
  }