Extend skooma to support SVG as well as HTML
This commit is contained in:
parent
4aa9a658b4
commit
b789242c4c
1 changed files with 9 additions and 3 deletions
12
skooma.js
12
skooma.js
|
@ -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")
|
||||||
|
|
Loading…
Reference in a new issue