{"version":3,"file":"ThemeProvider.cjs","sources":["../../../src/components/theme-provider/ThemeProvider.tsx"],"sourcesContent":["import { type CSSProperties, type FC, useMemo } from 'react'\r\nimport { TooltipProvider } from '@components/overlay/tooltip'\r\nimport { ThemeContext } from '@components/theme-provider/ThemeProvider.context.ts'\r\nimport type { ThemeProviderProps } from '@components/theme-provider/types/ThemeProvider.props.ts'\r\nimport { useThemeProvider } from '@components/theme-provider/hooks/use-theme-provider/useThemeProvider.hook.ts'\r\nimport {\r\n    THEME_TRANSITION_ATTRIBUTE,\r\n    THEME_TRANSITION_DURATION_VAR,\r\n} from '@constants/theme'\r\n\r\n/**\r\n * `ThemeProvider` wraps a subtree and manages the active color-scheme.\r\n *\r\n * ### What it does\r\n * - Manages the active color scheme and runtime token overrides.\r\n * - Applies the theme to `<html>` by default so body-mounted portals inherit it.\r\n * - Applies the theme to its wrapper when `scope=\"subtree\"`.\r\n * - Temporarily forces all transitions to the configured theme duration.\r\n *\r\n * ### Controlled vs uncontrolled\r\n * - **Uncontrolled** (default): omit the `theme` prop.  The component manages\r\n *   its own state; use `defaultTheme` to set the initial value.\r\n * - **Controlled**: pass `theme` and handle `onThemeChange` in the parent.\r\n *\r\n * ### Placing in your app\r\n * Wrap your whole application to enable global theming:\r\n * ```tsx\r\n * <ThemeProvider defaultTheme=\"system\">\r\n *   <App />\r\n * </ThemeProvider>\r\n * ```\r\n * Or scope it to a single subtree:\r\n * ```tsx\r\n * <ThemeProvider scope=\"subtree\" theme=\"dark\" tokens={{ primary: 'oklch(0.70 0.16 185)' }}>\r\n *   <DarkWidget />\r\n * </ThemeProvider>\r\n * ```\r\n */\r\nconst ThemeProvider: FC<ThemeProviderProps> = ({\r\n    theme: controlledTheme,\r\n    defaultTheme = 'system',\r\n    scope = 'document',\r\n    themeTransitionDuration = 0,\r\n    onThemeChange,\r\n    tokens,\r\n    style,\r\n    children,\r\n    ...divProps\r\n}) => {\r\n    const { activeTheme, resolvedTheme, setTheme, tokenStyles, isTransitioning } =\r\n    useThemeProvider({\r\n        controlledTheme,\r\n        defaultTheme,\r\n        onThemeChange,\r\n        scope,\r\n        tokens,\r\n        themeTransitionDuration,\r\n    })\r\n    const transitionStyle = useMemo<CSSProperties>(\r\n        () =>\r\n            isTransitioning\r\n                ? ({\r\n                    [THEME_TRANSITION_DURATION_VAR]: `${Math.max(0, themeTransitionDuration)}ms`,\r\n                } as CSSProperties)\r\n                : {},\r\n        [isTransitioning, themeTransitionDuration],\r\n    )\r\n    const containerStyle = useMemo(\r\n        () => ({\r\n            ...(scope === 'subtree' ? tokenStyles : {}),\r\n            ...style,\r\n            ...(scope === 'subtree' ? transitionStyle : {}),\r\n        }),\r\n        [scope, style, tokenStyles, transitionStyle],\r\n    )\r\n    const contextValue = useMemo(\r\n        () => ({ theme: activeTheme, resolvedTheme, setTheme }),\r\n        [activeTheme, resolvedTheme, setTheme],\r\n    )\r\n    const content = useMemo(\r\n        () => <TooltipProvider>{children}</TooltipProvider>,\r\n        [children],\r\n    )\r\n\r\n    return (\r\n        <ThemeContext.Provider value={contextValue}>\r\n            <div\r\n                {...(scope === 'subtree' ? { 'data-theme': resolvedTheme } : {})}\r\n                {...(\r\n                    scope === 'subtree' && isTransitioning\r\n                        ? { [THEME_TRANSITION_ATTRIBUTE]: '' }\r\n                        : {}\r\n                )}\r\n                style={containerStyle}\r\n                {...divProps}\r\n            >\r\n                {content}\r\n            </div>\r\n        </ThemeContext.Provider>\r\n    )\r\n}\r\n\r\nThemeProvider.displayName = 'ThemeProvider'\r\n\r\nexport default ThemeProvider\r\n"],"names":["ThemeProvider","controlledTheme","defaultTheme","scope","themeTransitionDuration","onThemeChange","tokens","style","children","divProps","activeTheme","resolvedTheme","setTheme","tokenStyles","isTransitioning","useThemeProvider","transitionStyle","useMemo","THEME_TRANSITION_DURATION_VAR","containerStyle","contextValue","content","jsx","TooltipProvider","ThemeContext","THEME_TRANSITION_ATTRIBUTE"],"mappings":"wdAsCMA,EAAwC,CAAC,CAC3C,MAAOC,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