Improve SVG
This commit is contained in:
10
sigpro2.js
10
sigpro2.js
@@ -1,4 +1,4 @@
|
|||||||
// sigpro 1.2.1
|
// sigpro 1.2.2
|
||||||
const isFunc = f => typeof f === "function"
|
const isFunc = f => typeof f === "function"
|
||||||
const isObj = o => o && typeof o === "object"
|
const isObj = o => o && typeof o === "object"
|
||||||
const isArr = Array.isArray
|
const isArr = Array.isArray
|
||||||
@@ -292,7 +292,8 @@ const Tag = (tag, props = {}, children = []) => {
|
|||||||
isArr(node) ? node.forEach(attach) : attach(node)
|
isArr(node) ? node.forEach(attach) : attach(node)
|
||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
const isSVG = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use)$/.test(tag)
|
const SVG_TAGS = /^(svg|path|circle|rect|line|polyline|polygon|g|defs|text|tspan|use|image|ellipse|foreignObject|linearGradient|radialGradient|stop|pattern|mask|clipPath|filter|feColorMatrix|feBlend|feGaussianBlur|animate|animateTransform|set|metadata|desc|title|symbol|marker|view|switch|a|altGlyph|altGlyphDef|altGlyphItem|glyph|glyphRef|hkern|vkern|font|font-face|font-face-format|font-face-name|font-face-src|font-face-uri|missing-glyph|mpath|textPath|tref|tbreak)$/i;
|
||||||
|
const isSVG = SVG_TAGS.test(tag);
|
||||||
const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag)
|
const el = isSVG ? doc.createElementNS("http://www.w3.org/2000/svg", tag) : doc.createElement(tag)
|
||||||
el._cleanups = new Set()
|
el._cleanups = new Set()
|
||||||
|
|
||||||
@@ -303,6 +304,11 @@ const Tag = (tag, props = {}, children = []) => {
|
|||||||
isFunc(v) ? v(el) : (v.current = el)
|
isFunc(v) ? v(el) : (v.current = el)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if (isSVG && k.startsWith("xlink:")) {
|
||||||
|
const ns = "http://www.w3.org/1999/xlink"
|
||||||
|
val == null ? el.removeAttributeNS(ns, k.slice(6)) : el.setAttributeNS(ns, k.slice(6), val)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (k.startsWith("on")) {
|
if (k.startsWith("on")) {
|
||||||
const ev = k.slice(2).toLowerCase()
|
const ev = k.slice(2).toLowerCase()
|
||||||
el.addEventListener(ev, v)
|
el.addEventListener(ev, v)
|
||||||
|
|||||||
Reference in New Issue
Block a user