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iB,EAAjB,KAAA,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAjB,cAAiB,EAAjB,IAAiB,EAAE;YAArC,IAAM,QAAQ,SAAA;YACjB,IAAM,MAAI,GAAW,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACrF,IAAI,KAAK,GAAG,IAAI,CAAC,QAA2B,CAAW,CAAC;YAExD,IAAI,QAAQ,KAAK,UAAU,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBACxD,6EAA6E;gBAC7E,KAAK,GAAG,KAAK,GAAG,IAAI,CAAC;aACtB;YACD,KAAK,CAAC,MAAI,CAAC,GAAG,KAAK,CAAC;SACrB;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { Customizations, getWindow } from '@uifabric/utilities';\nimport { ITheme, IPartialTheme, IFontStyles } from '../interfaces/index';\nimport { loadTheme as legacyLoadTheme } from '@microsoft/load-themed-styles';\nimport { IRawStyle } from '@uifabric/merge-styles';\nimport { createTheme } from '@fluentui/theme/lib/createTheme';\n\nexport { createTheme } from '@fluentui/theme/lib/createTheme';\n\nlet _theme: ITheme = createTheme({});\nlet _onThemeChangeCallbacks: Array<(theme: ITheme) => void> = [];\n\nexport const ThemeSettingName = 'theme';\n\nexport function initializeThemeInCustomizations(): void {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const win: any = getWindow();\n\n if (win?.FabricConfig?.legacyTheme) {\n // does everything the `else` clause does and more, such as invoke legacy theming\n loadTheme(win.FabricConfig.legacyTheme);\n } else if (!Customizations.getSettings([ThemeSettingName]).theme) {\n if (win?.FabricConfig?.theme) {\n _theme = createTheme(win.FabricConfig.theme);\n }\n\n // Set the default theme.\n Customizations.applySettings({ [ThemeSettingName]: _theme });\n }\n}\n\ninitializeThemeInCustomizations();\n\n/**\n * Gets the theme object\n * @param depComments - Whether to include deprecated tags as comments for deprecated slots.\n */\nexport function getTheme(depComments: boolean = false): ITheme {\n if (depComments === true) {\n _theme = createTheme({}, depComments);\n }\n return _theme;\n}\n\n/**\n * Registers a callback that gets called whenever the theme changes.\n * This should only be used when the component cannot automatically get theme changes through its state.\n * This will not register duplicate callbacks.\n */\nexport function registerOnThemeChangeCallback(callback: (theme: ITheme) => void): void {\n if (_onThemeChangeCallbacks.indexOf(callback) === -1) {\n _onThemeChangeCallbacks.push(callback);\n }\n}\n\n/**\n * See registerOnThemeChangeCallback().\n * Removes previously registered callbacks.\n */\nexport function removeOnThemeChangeCallback(callback: (theme: ITheme) => void): void {\n const i = _onThemeChangeCallbacks.indexOf(callback);\n if (i === -1) {\n return;\n }\n\n _onThemeChangeCallbacks.splice(i, 1);\n}\n\n/**\n * Applies the theme, while filling in missing slots.\n * @param theme - Partial theme object.\n * @param depComments - Whether to include deprecated tags as comments for deprecated slots.\n */\nexport function loadTheme(theme: IPartialTheme, depComments: boolean = false): ITheme {\n _theme = createTheme(theme, depComments);\n\n // Invoke the legacy method of theming the page as well.\n legacyLoadTheme({ ..._theme.palette, ..._theme.semanticColors, ..._theme.effects, ..._loadFonts(_theme) });\n\n Customizations.applySettings({ [ThemeSettingName]: _theme });\n\n _onThemeChangeCallbacks.forEach((callback: (theme: ITheme) => void) => {\n try {\n callback(_theme);\n } catch (e) {\n // don't let a bad callback break everything else\n }\n });\n\n return _theme;\n}\n\n/**\n * Loads font variables into a JSON object.\n * @param theme - The theme object\n */\nfunction _loadFonts(theme: ITheme): { [name: string]: string } {\n const lines: { [key: string]: string } = {};\n\n for (const fontName of Object.keys(theme.fonts)) {\n const font: IRawStyle = theme.fonts[fontName as keyof IFontStyles];\n\n for (const propName of Object.keys(font)) {\n const name: string = fontName + propName.charAt(0).toUpperCase() + propName.slice(1);\n let value = font[propName as keyof IRawStyle] as string;\n\n if (propName === 'fontSize' && typeof value === 'number') {\n // if it's a number, convert it to px by default like our theming system does\n value = value + 'px';\n }\n lines[name] = value;\n }\n }\n return lines;\n}\n"]} |