Skip to content

Commit

Permalink
opti: 优化svg tags:兼容小写,删掉了废弃的animateColor,添加了linearGradient,radialGrad…
Browse files Browse the repository at this point in the history
…ient,stop等渐变相关标签,fix #621
  • Loading branch information
jinzhan committed Jun 23, 2021
1 parent 14e4183 commit 6d2efb3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/browser/create-el.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var svgTags = require('./svg-tags');
*/
function createEl(tagName) {
if (svgTags[tagName] && document.createElementNS) {
return document.createElementNS('http://www.w3.org/2000/svg', tagName);
return document.createElementNS('http://www.w3.org/2000/svg', svgTags[tagName]);
}

return document.createElement(tagName);
Expand Down
45 changes: 33 additions & 12 deletions src/browser/svg-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,39 @@ var splitStr2Obj = require('../util/split-str-2-obj');
* @type {Object}
*/
var svgTags = splitStr2Obj(''
// structure
+ 'svg,g,defs,desc,metadata,symbol,use,'
// image & shape
+ 'image,path,rect,circle,line,ellipse,polyline,polygon,'
// text
+ 'text,tspan,tref,textpath,'
// other
+ 'marker,pattern,clippath,mask,filter,cursor,view,animate,'
// font
+ 'font,font-face,glyph,missing-glyph,'
// camel
+ 'animateColor,animateMotion,animateTransform,textPath,foreignObject'
// Animation elements
+ 'animate,animateMotion,animateTransform,'

// Basic shapes
+ 'circle,ellipse,line,polygon,polyline,rect,'

// Container elements
+ 'defs,g,marker,mask,missing-glyph,pattern,svg,symbol,'

// Descriptive elements
+ 'desc,metadata,'

// Font elements
+ 'font,font-face,'

// Gradient elements
+ 'linearGradient,radialGradient,stop,'

// Graphics elements
+ 'image,path,use,'

// Text elements
+ 'glyph,textPath,text,tref,tspan,'

// Others
+ 'clipPath,cursor,filter,foreignObject,view'
);

// 把小写转驼峰:HTML中的svg标签不区分大小写,但通过document.createElementNS创建需要区分
for (var tag in svgTags) {
if (/[A-Z]/.test(tag)) {
svgTags[tag.toLowerCase()] = svgTags[tag];
}
}

exports = module.exports = svgTags;

0 comments on commit 6d2efb3

Please sign in to comment.