license import { getData , initData } from "./node_data" ; import { Key , NameOrCtorDef } from "./types" ; param tag param parent returns function getNamespaceForTag ( tag , parent ) { if ( tag === "svg" ) { return "http://www.w3.org/2000/svg" ; } if ( tag === "math" ) { return "http://www.w3.org/1998/Math/MathML" ; } if ( parent == null ) { return null ; } if ( getData ( parent ) . nameOrCtor === "foreignObject" ) { return null ; } return ( parent as any ) . namespaceURI ; } param doc param parent param nameOrCtor param key returns function createElement ( doc , parent , nameOrCtor , key ) { let el ; if ( typeof nameOrCtor === "function" ) { el = new nameOrCtor ( ) ; } else { const namespace = getNamespaceForTag ( nameOrCtor , parent ) ; if ( namespace ) { el = doc . createElementNS ( namespace , nameOrCtor ) ; } else { el = doc . createElement ( nameOrCtor ) ; } } initData ( el , nameOrCtor , key ) ; return el ; } param doc returns function createText ( doc ) { const node = doc . createTextNode ( "" ) ; initData ( node , "#text" , null ) ; return node ; } export { createElement , createText } ;