@ferrlabs/ui-ng 1.68.5 → 1.69.0

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/README.md CHANGED
@@ -164,8 +164,29 @@ list in place and emits `localeChange` with the chosen code. The app applies the
164
164
  `ThemeService` (root) holds the preference as a signal (`preference()`, `resolved()`,
165
165
  `setPreference()`), stores it in `localStorage` under `flr-theme`, sets `data-theme="dark"` on
166
166
  `<html>` for dark and removes the attribute for light, and follows `prefers-color-scheme` while the
167
- preference is `system`. It runs once something injects it. To avoid a light flash before Angular
168
- starts, an app can set the attribute from the same key in an inline script in `index.html`.
167
+ preference is `system`. It runs once something injects it, so every app must call `provideTheme()`
168
+ in its application config. Without it the stored theme is only applied when `flr-user-menu` first
169
+ renders, and routes outside the authenticated layout (login, callback, onboarding, public pages)
170
+ load light and flip to dark mid-session.
171
+
172
+ ```ts
173
+ import { provideTheme } from '@ferrlabs/ui-ng';
174
+
175
+ export const appConfig: ApplicationConfig = {
176
+ providers: [provideTheme()],
177
+ };
178
+ ```
179
+
180
+ To avoid a light frame before Angular bootstraps, paste this into the `<head>` of `index.html`,
181
+ before the stylesheets. It reads `localStorage['flr-theme']` and `prefers-color-scheme` and sets
182
+ `data-theme="dark"` on `<html>`, with the same resolution as `ThemeService`. It is exported as
183
+ `THEME_PREPAINT_SCRIPT` (generated from the same storage key and rule as the service), and a test
184
+ checks it against `ThemeService`. Under a strict CSP, allow it with a hash or nonce.
185
+
186
+ <!-- prettier-ignore -->
187
+ ```html
188
+ <script>(function(){var s=null,d=false;try{s=localStorage.getItem("flr-theme")}catch(e){}try{d=matchMedia("(prefers-color-scheme: dark)").matches}catch(e){}var p=["system","light","dark"].indexOf(s)<0?"system":s;if(p==="dark"||(p==="system"&&d))document.documentElement.setAttribute("data-theme","dark")})()</script>
189
+ ```
169
190
 
170
191
  To add a row of your own to a `flr-menu`, provide `MENU_FOCUSABLE` (`focus()`, `disabled()`) on it so
171
192
  the arrow keys reach it. `flr-menu-item` takes `keepOpen` (the click does not close the menu) and
@@ -1,6 +1,6 @@
1
1
  import { DOCUMENT, Location, NgTemplateOutlet, isPlatformBrowser } from "@angular/common";
2
2
  import * as i0 from "@angular/core";
3
- import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, Injectable, InjectionToken, Injector, LOCALE_ID, PLATFORM_ID, ViewContainerRef, ViewEncapsulation, afterNextRender, afterRenderEffect, booleanAttribute, computed, contentChildren, effect, forwardRef, inject, input, linkedSignal, makeEnvironmentProviders, model, numberAttribute, output, signal, untracked, viewChild, viewChildren } from "@angular/core";
3
+ import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, Injectable, InjectionToken, Injector, LOCALE_ID, PLATFORM_ID, ViewContainerRef, ViewEncapsulation, afterNextRender, afterRenderEffect, booleanAttribute, computed, contentChildren, effect, forwardRef, inject, input, linkedSignal, makeEnvironmentProviders, model, numberAttribute, output, provideEnvironmentInitializer, signal, untracked, viewChild, viewChildren } from "@angular/core";
4
4
  import * as i1 from "@angular/forms";
5
5
  import { FormsModule, NG_VALUE_ACCESSOR } from "@angular/forms";
6
6
  import * as i1$2 from "@angular/cdk/overlay";
@@ -12672,11 +12672,28 @@ i0.ɵɵngDeclareClassMetadata({
12672
12672
  }
12673
12673
  });
12674
12674
  const THEME_STORAGE_KEY = "flr-theme";
12675
- const PREFERENCES$1 = [
12675
+ const THEME_DARK_QUERY = "(prefers-color-scheme: dark)";
12676
+ const THEME_PREFERENCES = [
12676
12677
  "system",
12677
12678
  "light",
12678
12679
  "dark"
12679
12680
  ];
12681
+ function parseThemePreference(value) {
12682
+ return THEME_PREFERENCES.find((preference) => preference === value) ?? "system";
12683
+ }
12684
+ function resolveTheme(preference, systemDark) {
12685
+ if (preference !== "system") return preference;
12686
+ return systemDark ? "dark" : "light";
12687
+ }
12688
+ const THEME_PREPAINT_SCRIPT = [
12689
+ "(function(){",
12690
+ "var s=null,d=false;",
12691
+ `try{s=localStorage.getItem(${JSON.stringify(THEME_STORAGE_KEY)})}catch(e){}`,
12692
+ `try{d=matchMedia(${JSON.stringify(THEME_DARK_QUERY)}).matches}catch(e){}`,
12693
+ `var p=${JSON.stringify(THEME_PREFERENCES)}.indexOf(s)<0?"system":s;`,
12694
+ "if(p===\"dark\"||(p===\"system\"&&d))document.documentElement.setAttribute(\"data-theme\",\"dark\")",
12695
+ "})()"
12696
+ ].join("");
12680
12697
  var ThemeService = class ThemeService {
12681
12698
  constructor() {
12682
12699
  this.document = inject(DOCUMENT);
@@ -12684,12 +12701,8 @@ var ThemeService = class ThemeService {
12684
12701
  this.systemDark = signal(false, ...ngDevMode ? [{ debugName: "systemDark" }] : /* istanbul ignore next */ []);
12685
12702
  this.stored = signal(this.read(), ...ngDevMode ? [{ debugName: "stored" }] : /* istanbul ignore next */ []);
12686
12703
  this.preference = this.stored.asReadonly();
12687
- this.resolved = computed(() => {
12688
- const preference = this.stored();
12689
- if (preference !== "system") return preference;
12690
- return this.systemDark() ? "dark" : "light";
12691
- }, ...ngDevMode ? [{ debugName: "resolved" }] : /* istanbul ignore next */ []);
12692
- const query = this.window?.matchMedia?.("(prefers-color-scheme: dark)");
12704
+ this.resolved = computed(() => resolveTheme(this.stored(), this.systemDark()), ...ngDevMode ? [{ debugName: "resolved" }] : /* istanbul ignore next */ []);
12705
+ const query = this.window?.matchMedia?.(THEME_DARK_QUERY);
12693
12706
  if (query) {
12694
12707
  this.systemDark.set(query.matches);
12695
12708
  const follow = (event) => {
@@ -12712,8 +12725,7 @@ var ThemeService = class ThemeService {
12712
12725
  }
12713
12726
  read() {
12714
12727
  try {
12715
- const value = this.window?.localStorage.getItem(THEME_STORAGE_KEY);
12716
- return PREFERENCES$1.find((preference) => preference === value) ?? "system";
12728
+ return parseThemePreference(this.window?.localStorage.getItem(THEME_STORAGE_KEY));
12717
12729
  } catch {
12718
12730
  return "system";
12719
12731
  }
@@ -13287,6 +13299,11 @@ i0.ɵɵngDeclareClassMetadata({
13287
13299
  }]
13288
13300
  }
13289
13301
  });
13302
+ function provideTheme() {
13303
+ return provideEnvironmentInitializer(() => {
13304
+ inject(ThemeService);
13305
+ });
13306
+ }
13290
13307
  const DEFAULT_APPS = [
13291
13308
  {
13292
13309
  id: "ferrlabs",
@@ -19452,6 +19469,6 @@ i0.ɵɵngDeclareClassMetadata({
19452
19469
  }]
19453
19470
  }
19454
19471
  });
19455
- export { ACCESS_PICKER_LABELS_EN, ACCESS_PICKER_LABELS_FR, ALL_SITE_LOCALES, AccessPickerComponent, AnnotatedTextareaComponent, AppRailComponent, AppSwitcherComponent, AvatarComponent, BannerComponent, BarChartComponent, BrandDropdownComponent, ButtonComponent, CONTACT_FORM_LABELS_EN, CONTACT_FORM_LABELS_FR, CONTACT_KINDS, CONTACT_PRODUCTS, CardComponent, CardHeaderComponent, CheckboxComponent, ComboboxComponent, ComparisonTableComponent, ConnectionCardComponent, ContactFormComponent, ContainerComponent, CopyIconComponent, DEFAULT_APPS, DEFAULT_LOCALE, DEFAULT_PAGE_SIZE, DEFAULT_PAGINATION_LABELS, DEFAULT_USER_MENU_LABELS, DividerComponent, DrawerComponent, EmptyStateComponent, ErrorStateComponent, FieldComponent, InputComponent, LOCALE_CATALOG, LoadingStateComponent, LogoMarkComponent, MENU_FOCUSABLE, MenuComponent, MenuItemComponent, MenuLabelComponent, MenuSeparatorComponent, ModalComponent, MultiSelectComponent, PageHeaderComponent, PaginationComponent, ProgressBarComponent, ProjectSwitcherComponent, RadioComponent, RadioGroupComponent, RailToggleComponent, SHELL_CONTEXT, SITE_CHROME, SITE_LOCALES, SearchFieldComponent, SectionComponent, SegmentedComponent, SelectComponent, ShellComponent, SidebarComponent, SidebarItemComponent, SidebarSectionComponent, SiteCardComponent, SiteFooterComponent, SiteLocaleBannerComponent, SiteLocalePickerComponent, SiteNavbarComponent, SiteShellComponent, SiteSwitcherComponent, SkeletonComponent, SpinnerComponent, SplitterComponent, SplitterPaneComponent, StatComponent, StatusBarsComponent, SubmitComponent, SwitchComponent, THEME_STORAGE_KEY, TabComponent, TabsComponent, TagComponent, TextareaComponent, ThemeService, ToastContainerComponent, ToastService, TreeSelectComponent, UserMenuComponent, WAITLIST_FORM_LABELS_EN, WAITLIST_FORM_LABELS_FR, WaitlistFormComponent, accountUrl, brandApps, entitledApps, hiddenAppsFromPreferences, injectSitePath, isSiteLocale, localeBase, localeEntry, localeSwitchHref, marketingUrl, matchSiteLocale, orgCreateUrl, paged, provideSiteChrome, readContactPrefill, readRuntimeEnv, resolveLocale, resolveSiteLocale, runtimeUrl, siteLocales, stripLocalePrefix, switcherState, toLocaleOptions, userMenuItems, withHiddenApps, withLocaleBase };
19472
+ export { ACCESS_PICKER_LABELS_EN, ACCESS_PICKER_LABELS_FR, ALL_SITE_LOCALES, AccessPickerComponent, AnnotatedTextareaComponent, AppRailComponent, AppSwitcherComponent, AvatarComponent, BannerComponent, BarChartComponent, BrandDropdownComponent, ButtonComponent, CONTACT_FORM_LABELS_EN, CONTACT_FORM_LABELS_FR, CONTACT_KINDS, CONTACT_PRODUCTS, CardComponent, CardHeaderComponent, CheckboxComponent, ComboboxComponent, ComparisonTableComponent, ConnectionCardComponent, ContactFormComponent, ContainerComponent, CopyIconComponent, DEFAULT_APPS, DEFAULT_LOCALE, DEFAULT_PAGE_SIZE, DEFAULT_PAGINATION_LABELS, DEFAULT_USER_MENU_LABELS, DividerComponent, DrawerComponent, EmptyStateComponent, ErrorStateComponent, FieldComponent, InputComponent, LOCALE_CATALOG, LoadingStateComponent, LogoMarkComponent, MENU_FOCUSABLE, MenuComponent, MenuItemComponent, MenuLabelComponent, MenuSeparatorComponent, ModalComponent, MultiSelectComponent, PageHeaderComponent, PaginationComponent, ProgressBarComponent, ProjectSwitcherComponent, RadioComponent, RadioGroupComponent, RailToggleComponent, SHELL_CONTEXT, SITE_CHROME, SITE_LOCALES, SearchFieldComponent, SectionComponent, SegmentedComponent, SelectComponent, ShellComponent, SidebarComponent, SidebarItemComponent, SidebarSectionComponent, SiteCardComponent, SiteFooterComponent, SiteLocaleBannerComponent, SiteLocalePickerComponent, SiteNavbarComponent, SiteShellComponent, SiteSwitcherComponent, SkeletonComponent, SpinnerComponent, SplitterComponent, SplitterPaneComponent, StatComponent, StatusBarsComponent, SubmitComponent, SwitchComponent, THEME_PREPAINT_SCRIPT, THEME_STORAGE_KEY, TabComponent, TabsComponent, TagComponent, TextareaComponent, ThemeService, ToastContainerComponent, ToastService, TreeSelectComponent, UserMenuComponent, WAITLIST_FORM_LABELS_EN, WAITLIST_FORM_LABELS_FR, WaitlistFormComponent, accountUrl, brandApps, entitledApps, hiddenAppsFromPreferences, injectSitePath, isSiteLocale, localeBase, localeEntry, localeSwitchHref, marketingUrl, matchSiteLocale, orgCreateUrl, paged, provideSiteChrome, provideTheme, readContactPrefill, readRuntimeEnv, resolveLocale, resolveSiteLocale, runtimeUrl, siteLocales, stripLocalePrefix, switcherState, toLocaleOptions, userMenuItems, withHiddenApps, withLocaleBase };
19456
19473
 
19457
19474
  //# sourceMappingURL=ferrlabs-ui-ng.mjs.map