* Copies an Element into a VNode representation. * (Interpretation into VNode is not recursive, so it excludes children.) * @param {Element} element * @return {import('preact').VNode}
(element)
| 285 | * @return {import('preact').VNode} |
| 286 | */ |
| 287 | function createShallowVNodeCopy(element) { |
| 288 | /** @type {JsonObject} */ |
| 289 | const props = { |
| 290 | // Setting `key` to an object is fine in Preact, but not React. |
| 291 | 'key': element, |
| 292 | }; |
| 293 | // We need to read element.attributes and element.attributes.length only once, |
| 294 | // since reading a live NamedNodeMap repeatedly is expensive. |
| 295 | const {attributes, localName} = element; |
| 296 | const {length} = attributes; |
| 297 | for (let i = 0; i < length; i++) { |
| 298 | const {name, value} = attributes[i]; |
| 299 | props[name] = value; |
| 300 | } |
| 301 | return Preact.createElement(localName, props); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * @param {HTMLElement} element |