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B,IAAwB,EAAE;QAA5C,IAAM,QAAQ,SAAA;QACjB,IAAM,IAAI,GAAc,KAAK,CAAC,KAAK,CAAC,QAA6B,CAAC,CAAC;QAEnE,KAAuB,UAAiB,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"]}
\No newline at end of file