-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsx-runtime.js
35 lines (25 loc) · 962 Bytes
/
jsx-runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export {jsx, jsx as jsxs, jsx as Fragment}
let definitions = new Map()
function jsx(node, props, key) {
if (node === jsx) node = document.createDocumentFragment()
else if (typeof node === 'function') {
let definition = definitions.get(node)
if (!definition) {
let is = node.name.replace(/(.)([A-Z])/g, '$1-$2').toLowerCase()
let name = Object.getPrototypeOf(node).name.replace(/^HTML|Element$/g, '').toLowerCase()
definition = name ? [name, {is}] : [is]
customElements.define(is, node, name ? {extends: name} : null)
definitions.set(...definition)
}
node = document.createElement(...definition)
}
else node = document.createElement(node)
if (key) node.setAttribute('key', key)
for (let name in props) {
if (name !== 'children') node.setAttribute(name, props[name])
else Array.isArray(props[name])
? node.append(...props[name])
: node.append(props[name])
}
return node
}