55 */
66'use strict' ;
77
8+ var NS = {
9+ xlink : 'http://www.w3.org/1999/xlink' ,
10+ xml : 'http://www.w3.org/XML/1998/namespace'
11+ } ;
12+
13+ var DOMNamespaces = {
14+ html : 'http://www.w3.org/1999/xhtml' ,
15+ mathml : 'http://www.w3.org/1998/Math/MathML' ,
16+ svg : 'http://www.w3.org/2000/svg'
17+ } ;
18+
19+ var propAlias = {
20+ // svg attributes alias
21+ clipPath : 'clip-path' ,
22+ fillOpacity : 'fill-opacity' ,
23+ fontFamily : 'font-family' ,
24+ fontSize : 'font-size' ,
25+ markerEnd : 'marker-end' ,
26+ markerMid : 'marker-mid' ,
27+ markerStart : 'marker-start' ,
28+ stopColor : 'stop-color' ,
29+ stopOpacity : 'stop-opacity' ,
30+ strokeDasharray : 'stroke-dasharray' ,
31+ strokeLinecap : 'stroke-linecap' ,
32+ strokeOpacity : 'stroke-opacity' ,
33+ strokeWidth : 'stroke-width' ,
34+ textAnchor : 'text-anchor' ,
35+ xlinkActuate : 'xlink:actuate' ,
36+ xlinkArcrole : 'xlink:arcrole' ,
37+ xlinkHref : 'xlink:href' ,
38+ xlinkRole : 'xlink:role' ,
39+ xlinkShow : 'xlink:show' ,
40+ xlinkTitle : 'xlink:title' ,
41+ xlinkType : 'xlink:type' ,
42+ xmlBase : 'xml:base' ,
43+ xmlLang : 'xml:lang' ,
44+ xmlSpace : 'xml:space' ,
45+ // DOM attributes alias
46+ acceptCharset : 'accept-charset' ,
47+ className : 'class' ,
48+ htmlFor : 'for' ,
49+ httpEquiv : 'http-equiv' ,
50+ // DOM property alias
51+ autoComplete : 'autocomplete' ,
52+ autoFocus : 'autofocus' ,
53+ autoPlay : 'autoplay' ,
54+ autoSave : 'autosave' ,
55+ hrefLang : 'hreflang' ,
56+ radioGroup : 'radiogroup' ,
57+ spellCheck : 'spellcheck' ,
58+ srcDoc : 'srcdoc' ,
59+ srcSet : 'srcset'
60+ } ;
61+
62+ var attributesNS = {
63+ xlinkActuate : NS . xlink ,
64+ xlinkArcrole : NS . xlink ,
65+ xlinkHref : NS . xlink ,
66+ xlinkRole : NS . xlink ,
67+ xlinkShow : NS . xlink ,
68+ xlinkTitle : NS . xlink ,
69+ xlinkType : NS . xlink ,
70+ xmlBase : NS . xml ,
71+ xmlLang : NS . xml ,
72+ xmlSpace : NS . xml
73+ } ;
74+
875var VNODE_TYPE = {
976 ELEMENT : 1 ,
1077 COMPONENT : 2 ,
@@ -249,10 +316,6 @@ var isInnerHTMLKey = function isInnerHTMLKey(key) {
249316var isStyleKey = function isStyleKey ( key ) {
250317 return key === 'style' ;
251318} ;
252- // Setting .type throws on non-<input> tags
253- var isTypeKey = function isTypeKey ( key ) {
254- return key === 'type' ;
255- } ;
256319
257320/*
258321 DOM Properties which are only getter
@@ -262,7 +325,22 @@ var readOnlys = {};
262325eachItem ( readOnlyProps . split ( '|' ) , function ( key ) {
263326 readOnlys [ key ] = true ;
264327} ) ;
328+
329+ var attrbutesConfigs = {
330+ width : true ,
331+ height : true ,
332+ type : true ,
333+ preserveAspectRatio : true ,
334+ viewBox : true ,
335+ viewport : true ,
336+ x : true ,
337+ y : true ,
338+ transform : true
339+ } ;
340+
265341var setProp = function setProp ( elem , key , value ) {
342+ var namespace = attributesNS [ key ] ;
343+ key = propAlias [ key ] || key ;
266344 switch ( true ) {
267345 case ignoreKeys [ key ] === true :
268346 break ;
@@ -275,13 +353,20 @@ var setProp = function setProp(elem, key, value) {
275353 case isInnerHTMLKey ( key ) :
276354 value && value . __html != null && ( elem . innerHTML = value . __html ) ;
277355 break ;
278- case key in elem && ! isTypeKey ( key ) :
279- if ( readOnlys [ key ] !== true && ! ( key === 'title' && value == null ) ) {
356+ case key in elem && ! attrbutesConfigs [ key ] :
357+ if ( readOnlys [ key ] !== true ) {
358+ if ( key === 'className' && elem . nodeName . toLowerCase ( ) === 'svg' ) {
359+ elem . setAttribute ( 'class' , value ) ;
360+ break ;
361+ }
362+ if ( key === 'title' && value == null ) {
363+ value = '' ;
364+ }
280365 elem [ key ] = value ;
281366 }
282367 break ;
283368 default :
284- elem . setAttribute ( key , '' + value ) ;
369+ ! namespace ? elem . setAttribute ( key , '' + value ) : elem . setAttributeNS ( key , '' + value ) ;
285370 }
286371} ;
287372var setProps = function setProps ( elem , props ) {
@@ -295,6 +380,7 @@ var removeProps = function removeProps(elem, oldProps) {
295380 } ) ;
296381} ;
297382var removeProp = function removeProp ( elem , key , oldValue ) {
383+ key = propAlias [ key ] || key ;
298384 switch ( true ) {
299385 case ignoreKeys [ key ] === true :
300386 break ;
@@ -307,7 +393,7 @@ var removeProp = function removeProp(elem, key, oldValue) {
307393 case isInnerHTMLKey ( key ) :
308394 elem . innerHTML = '' ;
309395 break ;
310- case ! ( key in elem ) || isTypeKey ( key ) :
396+ case ! ( key in elem ) || ! attrbutesConfigs [ key ] :
311397 elem . removeAttribute ( key ) ;
312398 break ;
313399 case isFn ( oldValue ) :
@@ -625,7 +711,8 @@ Velem.prototype = new Vtree({
625711 var type = this . type ;
626712 var props = this . props ;
627713
628- var node = document . createElement ( type ) ;
714+ var namespace = type === 'svg' ? DOMNamespaces . svg : type === 'math' ? DOMNamespaces . mathml : null ;
715+ var node = namespace ? document . createElementNS ( namespace , type ) : document . createElement ( type ) ;
629716 this . eachChildren ( function ( vchild ) {
630717 vchild . initTree ( node , parentContext ) ;
631718 } ) ;
0 commit comments