@web-atoms/core
Version:
82 lines (81 loc) • 2.74 kB
JavaScript
System.register(["../../core/StringHelper"], function (_export, _context) {
"use strict";
var StringHelper, AtomStyle, emptyPrototype;
_export("AtomStyle", void 0);
return {
setters: [function (_coreStringHelper) {
StringHelper = _coreStringHelper.StringHelper;
}],
execute: function () {
emptyPrototype = Object.getPrototypeOf({});
_export("AtomStyle", AtomStyle = class AtomStyle {
constructor(styleSheet, name) {
this.styleSheet = styleSheet;
this.name = name;
this.styleText = null;
this.name = this.name + "-root";
}
getBaseProperty(tc, name) {
let c = tc;
do {
c = Object.getPrototypeOf(c);
if (!c) {
throw new Error("No property descriptor found for " + name);
}
const pd = Object.getOwnPropertyDescriptor(c.prototype, name);
if (!pd) {
continue;
}
return pd.get.apply(this);
} while (true);
}
build() {
if (this.styleText) {
return;
}
this.styleText = this.createStyleText("", [], this.root).join("\n");
}
toString() {
return this.styleText;
}
createStyleText(name, pairs, styles) {
const styleList = [];
for (const key in styles) {
if (styles.hasOwnProperty(key)) {
if (/^(\_\$\_|className$|toString$)/i.test(key)) {
continue;
}
const element = styles[key];
if (element === undefined || element === null) {
continue;
}
const keyName = StringHelper.fromCamelToHyphen(key);
if (key === "subclasses") {
const n = name;
for (const subclassKey in element) {
if (element.hasOwnProperty(subclassKey)) {
const ve = element[subclassKey];
pairs = this.createStyleText(`${n}${subclassKey}`, pairs, ve);
}
}
} else {
if (element.url) {
styleList.push(`${keyName}: url(${element})`);
} else {
styleList.push(`${keyName}: ${element}`);
}
}
}
}
const cname = StringHelper.fromCamelToHyphen(name);
const styleClassName = `${this.name}${cname}`;
if (styleList.length) {
pairs.push(`.${styleClassName} { ${styleList.join(";\r\n")}; }`);
}
return pairs;
}
});
}
};
});
//# sourceMappingURL=AtomStyle.js.map