{"version":3,"file":"chunk-useThemeContext.mjs","names":["Theme.ThemeContext"],"sources":["../../src/hooks/useSafeArea.ts","../../src/util/mobile.ts","../../src/providers/ThemeProvider/IconRegistry.tsx","../../src/providers/ThemeProvider/TranslationsProvider.tsx","../../src/hooks/useTranslationsContext.ts","../../src/theme/bindTheme.ts","../../src/theme/defaultTheme.ts","../../src/providers/ThemeProvider/Theme.tsx","../../src/hooks/useThemeContext.ts"],"sourcesContent":["//\n// Copyright 2025 DXOS.org\n//\n\nimport { useCallback, useState } from 'react';\n\nimport { useViewportResize } from '@dxos/react-hooks';\n\nexport type SafeAreaPadding = Record<'top' | 'right' | 'bottom' | 'left', number>;\n\nexport const initialSafeArea = { top: NaN, right: NaN, bottom: NaN, left: NaN };\n\nexport const useSafeArea = (): SafeAreaPadding => {\n  const [padding, setPadding] = useState<SafeAreaPadding>(initialSafeArea);\n  const handleResize = useCallback(() => {\n    setPadding({\n      top: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--safe-area-top')),\n      right: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--safe-area-right')),\n      bottom: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--safe-area-bottom')),\n      left: parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--safe-area-left')),\n    });\n  }, []);\n\n  useViewportResize(handleResize);\n  return padding;\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\n/**\n * Determines whether the on-screen keyboard will appear on `focus` outside of a click handler.\n */\nexport const hasIosKeyboard = () => {\n  // TODO(burdon): Better way to detect iOS keyboard?\n  return !!navigator.userAgent.match(/iP(ad|od|hone).+Safari/);\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport React, { type PropsWithChildren, useEffect, useState } from 'react';\n\nimport {\n  type IconRegistry,\n  IconRegistryContext,\n  type IconSource,\n  NoopRegistry,\n  acquireRegistry,\n  defaultSources,\n} from './icon-registry.ts';\n\nexport type IconRegistryProviderProps = PropsWithChildren<{\n  /**\n   * Icon sets resolvable at runtime; defaults to Phosphor at `/phosphor`. Only the first\n   * mounted provider's sources apply, since the registry is shared across a document.\n   */\n  sources?: IconSource[];\n}>;\n\n/**\n * Provides the shared icon registry to descendants (consumed by `useIconHref`), acquiring\n * the refcounted document-level singleton on mount and releasing it on unmount.\n */\nexport const IconRegistryProvider = ({ children, sources = defaultSources }: IconRegistryProviderProps) => {\n  const [registry, setRegistry] = useState<IconRegistry>(NoopRegistry);\n\n  useEffect(() => {\n    if (typeof document === 'undefined') {\n      return;\n    }\n    const { registry, release } = acquireRegistry(sources);\n    setRegistry(registry);\n    return release;\n    // Sources are read once when the shared registry is created; later changes are ignored by design.\n  }, []);\n\n  return <IconRegistryContext.Provider value={registry}>{children}</IconRegistryContext.Provider>;\n};\n","//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Locale } from 'date-fns';\nimport React, { type ReactNode, Suspense, useEffect, useState } from 'react';\nimport { I18nextProvider } from 'react-i18next';\n\nimport { type Resource, addResources, i18n } from '@dxos/i18n';\n\nimport { TranslationsContext, initialDtLocale, initialNs } from './TranslationsContext.ts';\n\nexport interface TranslationsProviderProps {\n  children?: ReactNode;\n  // TODO(wittjosiah): Rename to `placeholder` to match ClientProvider?\n  //   Placeholder => loading, fallback => error.\n  fallback?: ReactNode;\n  resourceExtensions?: Resource[];\n  appNs?: string;\n  dtLocale?: Locale;\n}\n\nexport const TranslationsProvider = ({\n  fallback,\n  resourceExtensions,\n  children,\n  appNs,\n  dtLocale,\n}: TranslationsProviderProps) => {\n  const [loaded, setLoaded] = useState(false);\n  useEffect(() => {\n    setLoaded(false);\n    // Convenience for standalone/storybook callers; the i18next instance lifecycle is owned by `@dxos/i18n`.\n    if (resourceExtensions && resourceExtensions.length) {\n      addResources(resourceExtensions);\n    }\n\n    setLoaded(true);\n  }, [resourceExtensions]);\n\n  // TODO(thure): This is not ideal, but i18next was causing `Suspense` to not render the fallback even when the child was asking for namespaces yet to be added.\n  // TODO(burdon): Fallbacks should only appear after a short delay, and if the displayed then be visible for 500mx to avoid startup flickering.\n  return (\n    <I18nextProvider i18n={i18n}>\n      <TranslationsContext.Provider value={{ appNs: appNs ?? initialNs, dtLocale: dtLocale ?? initialDtLocale }}>\n        <Suspense fallback={fallback}>{loaded ? children : fallback}</Suspense>\n      </TranslationsContext.Provider>\n    </I18nextProvider>\n  );\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { TranslationsContext } from '../providers/ThemeProvider/TranslationsContext.ts';\n\nexport const useTranslationsContext = () => useContext(TranslationsContext);\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { type ClassNameArray, type ComponentFunction, type Theme, type ThemeFunction } from '@dxos/ui-types';\nimport { getDeep } from '@dxos/util';\n\nexport const bindTheme = <P extends Record<string, any>>(theme: Theme<Record<string, any>>): ThemeFunction<P> => {\n  return (path: string, styleProps?: P, ...etc: ClassNameArray) => {\n    const result = getDeep<Theme<P> | ComponentFunction<P>>(theme, path.split('.'));\n    return typeof result === 'function' ? result(styleProps ?? ({} as P), ...etc) : undefined;\n  };\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Theme } from '@dxos/ui-types';\n\nimport { bindTheme } from './bindTheme.ts';\n\n/** Next styles through `.dx-*` CSS, so the bound theme holds no component tables. */\nexport const defaultTheme: Theme<Record<string, any>> = {\n  themeName: () => 'default',\n};\n\nexport const defaultTx = bindTheme(defaultTheme);\n","//\n// Copyright 2022 DXOS.org\n//\n\n// @import-as-namespace\n\nimport React, { type PropsWithChildren, createContext, useEffect, useMemo } from 'react';\n\nimport { trackKeyboardModality } from '@dxos/react-focus';\nimport { type ThemeFunction, type ThemeMode } from '@dxos/ui-types';\n\nimport { type SafeAreaPadding, useSafeArea } from '../../hooks/useSafeArea.ts';\nimport { hasIosKeyboard } from '../../util/mobile.ts';\nimport { IconRegistryProvider } from './IconRegistry.tsx';\nimport { TranslationsProvider, type TranslationsProviderProps } from './TranslationsProvider.tsx';\n\nexport type ThemeContextValue<P extends Record<string, any> = Record<string, any>> = {\n  tx: ThemeFunction<P>;\n  themeMode: ThemeMode;\n  hasIosKeyboard: boolean;\n  safeAreaPadding?: SafeAreaPadding;\n  platform?: 'mobile' | 'desktop';\n};\n\n/**\n * @internal\n */\nexport const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);\n\ntype ThemeProviderProps<P extends Record<string, any> = Record<string, any>> = Omit<\n  TranslationsProviderProps,\n  'children'\n> &\n  Partial<Omit<ThemeContextValue<P>, 'safeAreaPadding'>> &\n  PropsWithChildren;\n\nconst ThemeProvider = ({\n  children,\n  fallback = null,\n  resourceExtensions,\n  appNs,\n  tx = (_path, _styleProps, ..._options) => undefined,\n  themeMode = 'dark',\n  platform,\n}: ThemeProviderProps) => {\n  useEffect(() => {\n    return document.defaultView ? trackKeyboardModality(document.defaultView) : undefined;\n  }, []);\n\n  const safeAreaPadding = useSafeArea();\n  // Destructure all props explicitly so useMemo deps are stable primitives, not a new `rest` object every render.\n  const contextValue = useMemo(\n    () => ({ tx, themeMode, hasIosKeyboard: hasIosKeyboard(), safeAreaPadding, platform }),\n    [tx, themeMode, safeAreaPadding, platform],\n  );\n\n  return (\n    <ThemeContext.Provider value={contextValue}>\n      <IconRegistryProvider>\n        <TranslationsProvider\n          {...{\n            fallback,\n            resourceExtensions,\n            appNs,\n          }}\n        >\n          {children}\n        </TranslationsProvider>\n      </IconRegistryProvider>\n    </ThemeContext.Provider>\n  );\n};\n\nexport { type Label, isLabel, toLocalizedString } from '@dxos/ui-types/translations';\nexport {\n  type IconRegistry,\n  type IconSource,\n  extendedIconSource,\n  getIconRegistry,\n  phosphorIconSource,\n  useIconRegistry,\n} from './icon-registry.ts';\nexport * from './IconRegistry.tsx';\nexport { TranslationsContext, useTranslation } from './TranslationsContext.ts';\nexport * from '../../hooks/useThemeContext.ts';\nexport * from '../../hooks/useTranslationsContext.ts';\nexport * from '../../theme/bindTheme.ts';\nexport * from '../../theme/defaultTheme.ts';\nexport * from '../../util/mobile.ts';\nexport { type Resource, type TFunction } from '@dxos/i18n';\nexport { Trans } from 'react-i18next';\n\nexport { ThemeProvider as Provider };\nexport type { ThemeProviderProps as ProviderProps };\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { log } from '@dxos/log';\n\nimport * as Theme from '../providers/ThemeProvider/Theme.tsx';\nimport { defaultTx } from '../theme/defaultTheme.ts';\nimport { initialSafeArea } from './useSafeArea.ts';\n\n// Failing soft (rather than throwing) keeps error-reporting surfaces renderable:\n// the fatal dialog itself consumes this hook, and a missing provider — including\n// the vite dev dual-module split, where the mounted ThemeProvider holds a\n// different ThemeContext identity than this consumer — would otherwise crash the\n// dialog meant to report the original error.\nconst fallbackContextValue: Theme.ThemeContextValue = {\n  tx: defaultTx,\n  themeMode: 'dark',\n  hasIosKeyboard: false,\n  // Every field a real context carries: a consumer that reads one the fallback omits crashes on the\n  // path meant to keep it renderable. The unmeasured insets are what a mounted provider starts with.\n  safeAreaPadding: initialSafeArea,\n};\n\nlet warned = false;\n\nexport const useThemeContext = (): Theme.ThemeContextValue => {\n  const contextValue = useContext(Theme.ThemeContext);\n  if (!contextValue) {\n    if (!warned) {\n      warned = true;\n      log.warn('Missing ThemeContext; falling back to the default theme.');\n    }\n    return fallbackContextValue;\n  }\n\n  return contextValue;\n};\n"],"mappings":";;;;;;;;;;;;;AAUA,IAAa,kBAAkB;CAAE,KAAK;CAAK,OAAO;CAAK,QAAQ;CAAK,MAAM;AAAI;AAE9E,IAAa,oBAAqC;CAChD,MAAM,CAAC,SAAS,cAAc,SAA0B,eAAe;CACvE,MAAM,eAAe,kBAAkB;EACrC,WAAW;GACT,KAAK,WAAW,iBAAiB,SAAS,eAAe,CAAC,CAAC,iBAAiB,iBAAiB,CAAC;GAC9F,OAAO,WAAW,iBAAiB,SAAS,eAAe,CAAC,CAAC,iBAAiB,mBAAmB,CAAC;GAClG,QAAQ,WAAW,iBAAiB,SAAS,eAAe,CAAC,CAAC,iBAAiB,oBAAoB,CAAC;G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