UNPKG

@joist/element

Version:

Intelligently apply styles to WebComponents

36 lines 964 B
export function query(query, root) { let res = null; return function (updates) { if (res) { return patchNode(res, updates); } if (root) { res = root.querySelector(query); } else if (this.shadowRoot) { res = this.shadowRoot.querySelector(query); } else { res = this.querySelector(query); } if (!res) { throw new Error(`could not find ${query}`); } return patchNode(res, updates); }; } function patchNode(target, update) { if (!update) { return target; } const patch = typeof update === "function" ? update(target) : update; for (const key in patch) { const newValue = patch[key]; const oldValue = target[key]; if (newValue !== oldValue) { Reflect.set(target, key, newValue); } } return target; } //# sourceMappingURL=query.js.map