UNPKG

@web-atoms/core

Version:
70 lines (69 loc) 2.04 kB
System.register(["../../di/TypeKey"], function (_export, _context) { "use strict"; var TypeKey, AtomStyleSheet; _export("AtomStyleSheet", void 0); return { setters: [function (_diTypeKey) { TypeKey = _diTypeKey.TypeKey; }], execute: function () { _export("AtomStyleSheet", AtomStyleSheet = class AtomStyleSheet { constructor(app, name) { this.app = app; this.name = name; this.styles = {}; this.lastUpdateId = 0; this.isAttaching = false; this.pushUpdate(0); } getNamedStyle(c) { const name = TypeKey.getName(c); return this.createNamedStyle(c, name); } createNamedStyle(c, name, updateTimeout) { const style = this.styles[name] = new c(this, `${this.name}-${name}`); style.build(); this.pushUpdate(updateTimeout); return style; } onPropertyChanging(name, newValue, oldValue) { this.pushUpdate(); } pushUpdate(delay = 1) { if (this.isAttaching) { return; } if (delay === 0) { this.attach(); return; } if (this.lastUpdateId) { clearTimeout(this.lastUpdateId); } this.lastUpdateId = setTimeout(() => { this.attach(); }, delay); } dispose() { if (this.styleElement) { this.styleElement.remove(); } } attach() { this.isAttaching = true; const text = []; for (const key in this.styles) { if (this.styles.hasOwnProperty(key)) { const element = this.styles[key]; text.push(element.toString()); } } const textContent = text.join("\n"); this.app.updateDefaultStyle(textContent); this.isAttaching = false; } }); } }; }); //# sourceMappingURL=AtomStyleSheet.js.map