1 | import { __assign } from "tslib";
|
2 | import { Customizations, getWindow } from '@uifabric/utilities';
|
3 | import { loadTheme as legacyLoadTheme } from '@microsoft/load-themed-styles';
|
4 | import { createTheme } from '@fluentui/theme/lib/createTheme';
|
5 | export { createTheme } from '@fluentui/theme/lib/createTheme';
|
6 | var _theme = createTheme({});
|
7 | var _onThemeChangeCallbacks = [];
|
8 | export var ThemeSettingName = 'theme';
|
9 | export function initializeThemeInCustomizations() {
|
10 | var _a;
|
11 | var _b, _c, _d, _e;
|
12 |
|
13 | var win = getWindow();
|
14 | if ((_c = (_b = win) === null || _b === void 0 ? void 0 : _b.FabricConfig) === null || _c === void 0 ? void 0 : _c.legacyTheme) {
|
15 |
|
16 | loadTheme(win.FabricConfig.legacyTheme);
|
17 | }
|
18 | else if (!Customizations.getSettings([ThemeSettingName]).theme) {
|
19 | if ((_e = (_d = win) === null || _d === void 0 ? void 0 : _d.FabricConfig) === null || _e === void 0 ? void 0 : _e.theme) {
|
20 | _theme = createTheme(win.FabricConfig.theme);
|
21 | }
|
22 |
|
23 | Customizations.applySettings((_a = {}, _a[ThemeSettingName] = _theme, _a));
|
24 | }
|
25 | }
|
26 |
|
27 | initializeThemeInCustomizations();
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | export function getTheme(depComments) {
|
33 | if (depComments === void 0) { depComments = false; }
|
34 | if (depComments === true) {
|
35 | _theme = createTheme({}, depComments);
|
36 | }
|
37 | return _theme;
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | export function registerOnThemeChangeCallback(callback) {
|
45 | if (_onThemeChangeCallbacks.indexOf(callback) === -1) {
|
46 | _onThemeChangeCallbacks.push(callback);
|
47 | }
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 |
|
53 | export function removeOnThemeChangeCallback(callback) {
|
54 | var i = _onThemeChangeCallbacks.indexOf(callback);
|
55 | if (i === -1) {
|
56 | return;
|
57 | }
|
58 | _onThemeChangeCallbacks.splice(i, 1);
|
59 | }
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | export function loadTheme(theme, depComments) {
|
66 | var _a;
|
67 | if (depComments === void 0) { depComments = false; }
|
68 | _theme = createTheme(theme, depComments);
|
69 |
|
70 | legacyLoadTheme(__assign(__assign(__assign(__assign({}, _theme.palette), _theme.semanticColors), _theme.effects), _loadFonts(_theme)));
|
71 | Customizations.applySettings((_a = {}, _a[ThemeSettingName] = _theme, _a));
|
72 | _onThemeChangeCallbacks.forEach(function (callback) {
|
73 | try {
|
74 | callback(_theme);
|
75 | }
|
76 | catch (e) {
|
77 |
|
78 | }
|
79 | });
|
80 | return _theme;
|
81 | }
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | function _loadFonts(theme) {
|
87 | var lines = {};
|
88 | for (var _i = 0, _a = Object.keys(theme.fonts); _i < _a.length; _i++) {
|
89 | var fontName = _a[_i];
|
90 | var font = theme.fonts[fontName];
|
91 | for (var _b = 0, _c = Object.keys(font); _b < _c.length; _b++) {
|
92 | var propName = _c[_b];
|
93 | var name_1 = fontName + propName.charAt(0).toUpperCase() + propName.slice(1);
|
94 | var value = font[propName];
|
95 | if (propName === 'fontSize' && typeof value === 'number') {
|
96 |
|
97 | value = value + 'px';
|
98 | }
|
99 | lines[name_1] = value;
|
100 | }
|
101 | }
|
102 | return lines;
|
103 | }
|
104 |
|
\ | No newline at end of file |