Extend skooma to support SVG as well as HTML

This commit is contained in:
Talia 2021-02-23 19:11:25 +01:00
parent 4aa9a658b4
commit b789242c4c
Signed by: darkwiiplayer
GPG key ID: 7808674088232B3E

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")