@web-atoms/core-docs
Version:
86 lines • 3.32 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "../../core/StringHelper"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AtomStyle = void 0;
const StringHelper_1 = require("../../core/StringHelper");
const emptyPrototype = Object.getPrototypeOf({});
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_1.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_1.StringHelper.fromCamelToHyphen(name);
const styleClassName = `${this.name}${cname}`;
if (styleList.length) {
pairs.push(`.${styleClassName} { ${styleList.join(";\r\n")}; }`);
}
return pairs;
}
}
exports.AtomStyle = AtomStyle;
});
//# sourceMappingURL=AtomStyle.js.map