UNPKG

gd-sprest-bs

Version:

SharePoint JavaScript, TypeScript and Web Components designed using the Bootstrap framework.

105 lines (104 loc) 4.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ThemeManager = void 0; var gd_sprest_1 = require("gd-sprest"); var defaultValues_1 = require("./defaultValues"); /** * Theme manager for the components */ var ThemeManager = /** @class */ (function () { function ThemeManager() { } Object.defineProperty(ThemeManager, "ClassicThemeInfo", { get: function () { return this._classicThemeInfo; }, set: function (value) { this._classicThemeInfo = value; }, enumerable: false, configurable: true }); Object.defineProperty(ThemeManager, "CurrentTheme", { get: function () { return this._currentTheme; }, enumerable: false, configurable: true }); Object.defineProperty(ThemeManager, "ModernThemeInfo", { get: function () { return this._modernThemeInfo; }, set: function (value) { this._modernThemeInfo = value; }, enumerable: false, configurable: true }); Object.defineProperty(ThemeManager, "IsInverted", { // Determines if the theme is currently inverted get: function () { // See if the properties exists if (typeof (this.CurrentTheme.isInverted) === "boolean") { return this.CurrentTheme.isInverted; } // Determine based on the white color var whiteValue = this.CurrentTheme.palette ? this.CurrentTheme.palette["white"] : this.CurrentTheme["white"]; if (typeof (whiteValue) === "string") { return whiteValue.toLowerCase() == "#ffffff" ? false : true; } // Return false by default return false; }, enumerable: false, configurable: true }); // Loads the modern theme, or the classic theme if it's not found ThemeManager.load = function (updateTheme) { var _this = this; if (updateTheme === void 0) { updateTheme = true; } // Return a promise return new Promise(function (resolve, reject) { // Get the current theme gd_sprest_1.Helper.getCurrentTheme().then(function (themeInfo) { // Set the current theme _this._currentTheme = themeInfo; // See if we are applying the classic theme updateTheme ? _this.update() : null; // Resolve the request resolve(); }, reject); }); }; // Sets the current theme ThemeManager.setCurrentTheme = function (value, updateTheme) { if (updateTheme === void 0) { updateTheme = true; } // Set the theme this._currentTheme = value; // Update the theme updateTheme ? this.update() : null; }; // Updates the theme variables ThemeManager.update = function (themeInfo) { if (themeInfo === void 0) { themeInfo = {}; } var root = document.querySelector(':root'); // Get the theme information var palette = themeInfo.palette || this.CurrentTheme.palette || {}; var semanticColors = themeInfo.semanticColors || this.CurrentTheme.semanticColors || {}; // Parse the modern theme values for (var key in this.ModernThemeInfo) { // Set the value var value = palette[this.ModernThemeInfo[key]] || palette[this.ClassicThemeInfo[key]] || semanticColors[this.ModernThemeInfo[key]] || semanticColors[this.ClassicThemeInfo[key]] || themeInfo[this.ModernThemeInfo[key]] || this.CurrentTheme[this.ModernThemeInfo[key]] || themeInfo[this.ClassicThemeInfo[key]] || this.CurrentTheme[this.ClassicThemeInfo[key]]; // See if a value exists if (value) { // Set the variable root.style.setProperty(key, value); } } }; // Classic Theme Information ThemeManager._classicThemeInfo = defaultValues_1.DefaultClassic; /** * Current Theme * Loads the modern theme from the DOM or the classic from the site collection. */ ThemeManager._currentTheme = {}; // Modern Theme Information ThemeManager._modernThemeInfo = defaultValues_1.DefaultModern; return ThemeManager; }()); exports.ThemeManager = ThemeManager;