@joist/element
Version:
Intelligently apply styles to WebComponents
40 lines • 1.12 kB
JavaScript
export function queryAll(query, root) {
let res = null;
return function (update) {
if (res) {
return patchNodes(res, update);
}
if (root) {
res = root.querySelectorAll(query);
}
else if (this.shadowRoot) {
res = this.shadowRoot.querySelectorAll(query);
}
else {
res = this.querySelectorAll(query);
}
if (!res) {
throw new Error(`could not find ${query}`);
}
return patchNodes(res, update);
};
}
function patchNodes(target, update) {
if (!update) {
return target;
}
for (const node of target) {
const patch = typeof update === "function" ? update(node) : update;
if (patch) {
for (const update in patch) {
const newValue = patch[update];
const oldValue = node[update];
if (newValue !== oldValue) {
Reflect.set(node, update, newValue);
}
}
}
}
return target;
}
//# sourceMappingURL=query-all.js.map