UNPKG

@osaedasia/oresume

Version:

A user-friendly library for generating complete Single Page Applications (SPAs)

2 lines (1 loc) 938 B
import{InvalidThemePropertyError as e,MissingThemePropertyError as t}from"../../domain/exceptions/Theme.js";class r{cssContent;_name;_properties;_propertiesKeys;constructor(e,t){this._name=e,this._properties=t,this._propertiesKeys=Object.keys(this._properties),this.cssContent=this._generateTheme()}get name(){return this._name}_generateTheme(){const t=["value"],r=new Set;for(const s of this._propertiesKeys){this._validateThemeProperty(s);const o=this._properties[s];for(const r of t)if(!o.hasOwnProperty(r))throw new e(`[${s}] Inner property '${r}' does not exist in theme '${this._name}'`);const n=this._generateCSSForProperty(s,o);r.add(n)}return` .${this._name} { ${[...r].join(" ")} }`}_generateCSSForProperty(e,t){return`--${e}: ${t.value}${t.important?" !important":""};`}_validateThemeProperty(e){if(!this._properties.hasOwnProperty(e))throw new t(`Property '${e}' does not exist in theme '${this._name}'`)}}export{r as Theme};