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AAAD,CAAC,AA5ED,IA4EC","sourcesContent":["import { GlobalSettings } from '../GlobalSettings';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type ISettings = { [key: string]: any };\nexport type ISettingsFunction = (settings: ISettings) => ISettings;\n\n/**\n * @deprecated Use ISettings.\n */\nexport type Settings = ISettings;\n\n/**\n * @deprecated Use ISettingsFunction.\n */\nexport type SettingsFunction = ISettingsFunction;\n\nexport interface ICustomizations {\n settings: ISettings;\n scopedSettings: { [key: string]: ISettings };\n inCustomizerContext?: boolean;\n}\n\nconst CustomizationsGlobalKey = 'customizations';\nconst NO_CUSTOMIZATIONS = { settings: {}, scopedSettings: {}, inCustomizerContext: false };\n\nlet _allSettings = GlobalSettings.getValue<ICustomizations>(CustomizationsGlobalKey, {\n settings: {},\n scopedSettings: {},\n inCustomizerContext: false,\n});\n\nlet _events: (() => void)[] = [];\n\nexport class Customizations {\n private static _suppressUpdates: boolean;\n\n public static reset(): void {\n _allSettings.settings = {};\n _allSettings.scopedSettings = {};\n }\n\n /** Apply global Customization settings.\n * @example Customizations.applySettings(\\{ theme: \\{...\\} \\});\n */\n public static applySettings(settings: ISettings): void {\n _allSettings.settings = { ..._allSettings.settings, ...settings };\n Customizations._raiseChange();\n }\n\n /** Apply Customizations to a particular named scope, like a component.\n * @example Customizations.applyScopedSettings('Nav', \\{ styles: () =\\> \\{\\} \\});\n */\n public static applyScopedSettings(scopeName: string, settings: ISettings): void {\n _allSettings.scopedSettings[scopeName] = { ..._allSettings.scopedSettings[scopeName], ...settings };\n Customizations._raiseChange();\n }\n\n public static getSettings(\n properties: string[],\n scopeName?: string,\n localSettings: ICustomizations = NO_CUSTOMIZATIONS,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): any {\n const settings: ISettings = {};\n const localScopedSettings = (scopeName && localSettings.scopedSettings[scopeName]) || {};\n const globalScopedSettings = (scopeName && _allSettings.scopedSettings[scopeName]) || {};\n\n for (let property of properties) {\n settings[property] =\n localScopedSettings[property] ||\n localSettings.settings[property] ||\n globalScopedSettings[property] ||\n _allSettings.settings[property];\n }\n\n return settings;\n }\n\n /** Used to run some code that sets Customizations without triggering an update until the end.\n * Useful for applying Customizations that don't affect anything currently rendered, or for\n * applying many customizations at once.\n * @param suppressUpdate - Do not raise the change event at the end, preventing all updates\n */\n public static applyBatchedUpdates(code: () => void, suppressUpdate?: boolean): void {\n Customizations._suppressUpdates = true;\n try {\n code();\n } catch {\n /* do nothing */\n }\n Customizations._suppressUpdates = false;\n if (!suppressUpdate) {\n Customizations._raiseChange();\n }\n }\n\n public static observe(onChange: () => void): void {\n _events.push(onChange);\n }\n\n public static unobserve(onChange: () => void): void {\n _events = _events.filter((cb: () => void) => cb !== onChange);\n }\n\n private static _raiseChange(): void {\n if (!Customizations._suppressUpdates) {\n _events.forEach((cb: () => void) => cb());\n }\n }\n}\n"]}
\No newline at end of file