license import { AttrMutatorConfig } from "./types" ; import { assert } from "./assertions" ; import { createMap , has } from "./util" ; import { symbols } from "./symbols" ; param name returns function getNamespace ( name ) { if ( name . lastIndexOf ( "xml:" , 0 ) === 0 ) { return "http://www.w3.org/XML/1998/namespace" ; } if ( name . lastIndexOf ( "xlink:" , 0 ) === 0 ) { return "http://www.w3.org/1999/xlink" ; } return null ; } param el param name param value function applyAttr ( el , name , value ) { if ( value == null ) { el . removeAttribute ( name ) ; } else { const attrNS = getNamespace ( name ) ; if ( attrNS ) { el . setAttributeNS ( attrNS , name , value as string ) ; } else { el . setAttribute ( name , value as string ) ; } } } param el param name param value function applyProp ( el , name , value ) { ( el as any ) [ name ] = value ; } param style param prop param value function setStyleValue ( style , prop , value ) { if ( prop . indexOf ( "-" ) >= 0 ) { style . setProperty ( prop , value ) ; } else { ( style as any ) [ prop ] = value ; } } param el param name param style function applyStyle ( el , name , style ) { assert ( "style" in el ) ; const elStyle = ( < HTMLElement | SVGElement > el ) . style ; if ( typeof style === "string" ) { elStyle . cssText = style ; } else { elStyle . cssText = "" ; for ( const prop in style ) { if ( has ( style , prop ) ) { setStyleValue ( elStyle , prop , style [ prop ] ) ; } } } } param el param name param value function applyAttributeTyped ( el , name , value ) { const type = typeof value ; if ( type === "object" || type === "function" ) { applyProp ( el , name , value ) ; } else { applyAttr ( el , name , value ) ; } } function createAttributeMap ( ) { const attributes = createMap ( ) as AttrMutatorConfig ; attributes [ symbols . default ] = applyAttributeTyped ; attributes [ "style" ] = applyStyle ; return attributes ; } /**
 * A publicly mutable object to provide custom mutators for attributes.
 * NB: The result of createMap() has to be recast since closure compiler
 * will just assume attributes is "any" otherwise and throws away
 * the type annotation set by tsickle.
 */ const attributes = createAttributeMap ( ) ; param el param name param value param attrs function updateAttribute ( el , name , value , attrs ) { const mutator = attrs [ name ] || attrs [ symbols . default ] ; mutator ( el , name , value ) ; } export { createAttributeMap , updateAttribute , applyProp , applyAttr , attributes } ;