Extend skooma to support SVG as well as HTML

This commit is contained in:
Talia 2021-02-23 19:11:25 +01:00
parent 5f27242b3f
commit c16eb29161
No known key found for this signature in database
GPG key ID: AD727AD22802D0D6

View file

@ -21,10 +21,16 @@ const parseArgs = (element, args) => {
element.setAttribute(key.replace("_", "-"), parseAttribute(arg[key]))
}
export const node = (name, args) => {
const element = document.createElement(name.replace("_", "-"))
const node = (name, args, xmlns) => {
if (xmlns)
element = document.createElementNS(xmlns, name.replace("_", "-"))
else
element = document.createElement(name.replace("_", "-"))
parseArgs(element, args)
return element
}
export const html = new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args) }})
const nameSpacedProxy = (xmlns) => new Proxy(Window, { get: (target, prop, receiver) => { return (...args) => node(prop, args, xmlns) }})
export const html = nameSpacedProxy()
export const svg = nameSpacedProxy("http://www.w3.org/2000/svg")