UNPKG

@ou-imdt/utils

Version:

Utility library for interactive media development

15 lines (13 loc) 476 B
/** * Generator function that yields all composed descendants of a node. * @param {Node} node - The root node. * @yields {Node} Each composed descendant node. */ export default function* composedDescendants(node) { const root = node.shadowRoot ? node.shadowRoot : node; const children = (node instanceof HTMLSlotElement) ? root.assignedElements() : [...root.children]; yield* children; for (const child of children) { yield* composedDescendants(child); } }