| 83 | keyof HTMLElementEventMap | Array<keyof HTMLElementEventMap> |
| 84 | > = |
| 85 | (interactions = []) => |
| 86 | (hydrate, forEach) => { |
| 87 | if (isString(interactions)) interactions = [interactions] |
| 88 | let hasHydrated = false |
| 89 | const doHydrate = (e: Event) => { |
| 90 | if (!hasHydrated) { |
| 91 | hasHydrated = true |
| 92 | teardown() |
| 93 | hydrate() |
| 94 | // replay event |
| 95 | e.target!.dispatchEvent(new (e.constructor as any)(e.type, e)) |
| 96 | } |
| 97 | } |
| 98 | const teardown = () => { |
| 99 | forEach(el => { |
| 100 | for (const i of interactions) { |
| 101 | el.removeEventListener(i, doHydrate) |
| 102 | } |
| 103 | }) |
| 104 | } |
| 105 | forEach(el => { |
| 106 | for (const i of interactions) { |
| 107 | el.addEventListener(i, doHydrate, { once: true }) |
| 108 | } |
| 109 | }) |
| 110 | return teardown |
| 111 | } |
| 112 | |
| 113 | export function forEachElement( |
| 114 | node: Node, |