From b789242c4c22ec83035671ae3225a8eb27d36391 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Tue, 23 Feb 2021 19:11:25 +0100 Subject: [PATCH] Extend skooma to support SVG as well as HTML --- skooma.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/skooma.js b/skooma.js index 0f78246..59fed20 100644 --- a/skooma.js +++ b/skooma.js @@ -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")