@alegendstale/holly-components
Version:
Reusable UI components created using lit
21 lines (20 loc) • 777 B
JavaScript
import i from "../node_modules/style-observer/src/style-observer.js";
import "../node_modules/style-observer/src/element-style-observer.js";
class l {
constructor(s, t, e) {
this.host = s, this.property = t, this.callback = e, this.value = "", this.host.addController(this);
}
hostConnected() {
const s = window.getComputedStyle(this.host).getPropertyValue(this.property);
this.value = s.trim(), this.callback?.(this.value), this.observer = new i((t) => {
const e = t[t.length - 1].value.trim();
e !== this.value && (this.value = e, this.callback?.(this.value), this.host.requestUpdate());
}), this.observer.observe(this.host, this.property);
}
hostDisconnected() {
this.observer?.unobserve();
}
}
export {
l as StyleController
};