@sujalchoudhari/solaris-ui
Version:
A UI framework to create HTML pages with just JavaScript.
76 lines • 2.54 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = __importDefault(require("./logger"));
/**
* The StyleManager class manages styles that are added to the page dynamically.
*/
class StyleManager {
/**
* An array of styles that have been added to the page.
*/
static styles = [];
/**
* Adds a style to the page.
* @param {Style} style - The style to add.
*/
static addStyle(style) {
if (this.isStyleAdded(style))
return;
logger_1.default.info(__filename, "Adding style", style.url || " ");
this.styles.push(style);
}
/**
* Removes a style from the page.
* @param {Style} style - The style to remove.
*/
static removeStyle(style) {
this.styles = this.styles.filter(s => s != style);
}
/**
* Returns the CSS text for all styles that have been added to the page.
* @returns {string} - The CSS text for all styles.
*/
static toString() {
let css = "";
this.styles.forEach(style => {
if (!style.type || style.type == "external")
return;
Object.keys(style.cssClasses).forEach((className) => {
css += `${className} {\n`;
Object.keys(style.cssClasses[className]).forEach((property) => {
css += ` ${property}: ${style.cssClasses[className][property]};\n`;
});
css += "}\n\n";
});
});
return css;
}
/**
* Checks if a style has already been added to the page.
* @param {Style} style - The style to check.
* @returns {boolean} - true if the style has already been added, false otherwise.
*/
static isStyleAdded(style) {
return this.styles.find(s => s == style) != undefined;
}
/**
* Returns an array of all external styles that have been added to the page.
* @returns {Array<Style>} - An array of all external styles.
*/
static getExternalStyles() {
let styles = [];
this.styles.forEach(style => {
if (!style.type || style.type !== "external")
return;
if (!style.url)
return;
styles.push(style);
});
return styles;
}
}
exports.default = StyleManager;
//# sourceMappingURL=stylemanager.js.map