UNPKG

662 BJavaScriptView Raw
1import namespace from "./namespace";
2import {xhtml} from "./namespaces";
3
4function creatorInherit(name) {
5 return function() {
6 var document = this.ownerDocument,
7 uri = this.namespaceURI;
8 return uri === xhtml && document.documentElement.namespaceURI === xhtml
9 ? document.createElement(name)
10 : document.createElementNS(uri, name);
11 };
12}
13
14function creatorFixed(fullname) {
15 return function() {
16 return this.ownerDocument.createElementNS(fullname.space, fullname.local);
17 };
18}
19
20export default function(name) {
21 var fullname = namespace(name);
22 return (fullname.local
23 ? creatorFixed
24 : creatorInherit)(fullname);
25}