@proveanything/smartlinks-auth-ui 0.5.20 → 0.5.22

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/dist/index.js CHANGED
@@ -13560,17 +13560,48 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
13560
13560
  }
13561
13561
  };
13562
13562
  // Dark mode detection and theme management
13563
+ // In 'auto' mode we honor (in priority order):
13564
+ // 1. An explicit `.dark` class on <html> or <body> (set by the host portal / SmartLinks theme system)
13565
+ // 2. A SmartLinks theme payload in the URL (?theme=... with m === 'd')
13566
+ // 3. The OS `prefers-color-scheme` preference
13563
13567
  React.useEffect(() => {
13564
13568
  if (theme !== 'auto') {
13565
13569
  setResolvedTheme(theme);
13566
13570
  return;
13567
13571
  }
13568
- // Auto-detect system theme preference
13569
13572
  const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
13570
- const updateTheme = () => setResolvedTheme(mediaQuery.matches ? 'dark' : 'light');
13573
+ const hostHasDarkClass = () => document.documentElement.classList.contains('dark') ||
13574
+ document.body.classList.contains('dark');
13575
+ const urlRequestsDark = () => {
13576
+ try {
13577
+ const search = new URLSearchParams(window.location.search);
13578
+ let themeParam = search.get('theme');
13579
+ if (!themeParam && window.location.hash.includes('?')) {
13580
+ themeParam = new URLSearchParams(window.location.hash.substring(window.location.hash.indexOf('?'))).get('theme');
13581
+ }
13582
+ if (!themeParam)
13583
+ return false;
13584
+ const decoded = JSON.parse(atob(themeParam));
13585
+ return decoded?.m === 'd';
13586
+ }
13587
+ catch {
13588
+ return false;
13589
+ }
13590
+ };
13591
+ const updateTheme = () => {
13592
+ const isDark = hostHasDarkClass() || urlRequestsDark() || mediaQuery.matches;
13593
+ setResolvedTheme(isDark ? 'dark' : 'light');
13594
+ };
13571
13595
  updateTheme();
13572
13596
  mediaQuery.addEventListener('change', updateTheme);
13573
- return () => mediaQuery.removeEventListener('change', updateTheme);
13597
+ // Watch host <html>/<body> class changes (portal toggling dark mode at runtime)
13598
+ const observer = new MutationObserver(updateTheme);
13599
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
13600
+ observer.observe(document.body, { attributes: true, attributeFilter: ['class'] });
13601
+ return () => {
13602
+ mediaQuery.removeEventListener('change', updateTheme);
13603
+ observer.disconnect();
13604
+ };
13574
13605
  }, [theme]);
13575
13606
  // Version tracking for debugging if needed
13576
13607
  // console.log(`${LOG_PREFIX} Component mounted, v${AUTH_UI_VERSION}`);