UNPKG

@alegendstale/holly-components

Version:

Reusable UI components created using lit

40 lines (39 loc) 1.04 kB
class n { constructor(t, r, s) { this.host = t, this.getValue = r, this.normalizedMap = {}, t.addController(this); for (const e of s) typeof e == "string" ? this.normalizedMap[e] = e : Object.assign(this.normalizedMap, e); } hostUpdated() { const t = this.getValue(); t !== this.lastValue && (this.lastValue = t, this._apply()); } /** Applies the parts in the map to the relevant elements. */ _apply() { const t = this.host.shadowRoot; if (t) for (const [r, s] of Object.entries(this.normalizedMap)) { const e = t.querySelectorAll(r), i = this._prefix(s); for (const a of e) a.getAttribute("part") !== i && a.setAttribute("part", i); } } /** Sanitizes name (removes CSS selectors), and prefixes partName */ _prefix(t) { return `__${t.replace(/[.#]/g, "")}`; } } function l(o) { return (t, r) => { t.constructor.addInitializer((e) => { new n( e, () => e[r], o ); }); }; } export { l as exposeParts };