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
1 changed files with 9 additions and 3 deletions

View File

@ -21,10 +21,16 @@ const parseArgs = (element, args) => {
element.setAttribute(key.replace("_", "-"), parseAttribute(arg[key])) element.setAttribute(key.replace("_", "-"), parseAttribute(arg[key]))
} }
export const node = (name, args) => { const node = (name, args, xmlns) => {
const element = document.createElement(name.replace("_", "-")) if (xmlns)
element = document.createElementNS(xmlns, name.replace("_", "-"))
else
element = document.createElement(name.replace("_", "-"))
parseArgs(element, args) parseArgs(element, args)
return element 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")