( /** 搜索构造器 */ wrapper: E, root: HTMLElement | Document = window.document )
| 7 | * @returns |
| 8 | */ |
| 9 | export function domSearch<E extends RawElements>( |
| 10 | /** 搜索构造器 */ |
| 11 | wrapper: E, |
| 12 | root: HTMLElement | Document = window.document |
| 13 | ): SearchedElements<E, HTMLElement | null> { |
| 14 | const obj = Object.create({}); |
| 15 | Reflect.ownKeys(wrapper).forEach((key) => { |
| 16 | const item = wrapper[key.toString()]; |
| 17 | Reflect.set( |
| 18 | obj, |
| 19 | key, |
| 20 | typeof item === 'string' |
| 21 | ? root.querySelector(item) |
| 22 | : typeof item === 'function' |
| 23 | ? item(root) |
| 24 | : item.map((fun) => fun(root)) |
| 25 | ); |
| 26 | }); |
| 27 | return obj; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * 元素搜索 |
no test coverage detected