Comparing version 5.1.6 to 5.2.0
328
index.cjs.js
@@ -1,89 +0,94 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require('tslib'); | ||
var tslib_1 = require("tslib"); | ||
var keys = Object.keys; | ||
function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
return typeof val === "boolean"; | ||
} | ||
function isElement(val) { | ||
return val && typeof val.nodeType === 'number'; | ||
return val && typeof val.nodeType === "number"; | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
return typeof val === "string"; | ||
} | ||
function isNumber(val) { | ||
return typeof val === 'number'; | ||
return typeof val === "number"; | ||
} | ||
function isObject(val) { | ||
return val && (typeof val === 'object' || isFunction(val)); | ||
return typeof val === "object" ? val !== null : isFunction(val); | ||
} | ||
// tslint:disable-next-line:ban-types | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
return typeof val === "function"; | ||
} | ||
function isArrayLike(obj) { | ||
return isObject(obj) && typeof obj.length === 'number' && typeof obj.nodeType !== 'number'; | ||
return ( | ||
isObject(obj) && | ||
typeof obj.length === "number" && | ||
typeof obj.nodeType !== "number" | ||
); | ||
} | ||
function f(tag) { | ||
return function create(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
return function(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
} | ||
/** @type {any} */ | ||
var DOM = function (obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
}({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
thead: 0, | ||
td: 0, | ||
th: 0, | ||
tr: 0, | ||
ul: 0 | ||
var DOM = (function(obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
})({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
td: 0, | ||
th: 0, | ||
thead: 0, | ||
tr: 0, | ||
ul: 0 | ||
}); | ||
var SVGNamespace = 'http://www.w3.org/2000/svg'; | ||
var SVGNamespace = "http://www.w3.org/2000/svg"; | ||
function preventDefault(event) { | ||
event.preventDefault(); | ||
return event; | ||
event.preventDefault(); | ||
return event; | ||
} | ||
function stopPropagation(event) { | ||
event.stopPropagation(); | ||
return event; | ||
event.stopPropagation(); | ||
return event; | ||
} | ||
@@ -93,3 +98,3 @@ // https://facebook.github.io/react/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored | ||
function isVisibleChild(value) { | ||
return !isBoolean(value) && value != null; | ||
return !isBoolean(value) && value != null; | ||
} | ||
@@ -101,113 +106,112 @@ /** | ||
function className(value) { | ||
if (Array.isArray(value)) { | ||
return value.map(className).filter(Boolean).join(' '); | ||
} else if (isObject(value)) { | ||
return keys(value).filter(function (k) { | ||
return value[k]; | ||
}).join(' '); | ||
} else if (isVisibleChild(value)) { | ||
return '' + value; | ||
} else { | ||
return ''; | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.map(className) | ||
.filter(Boolean) | ||
.join(" "); | ||
} else if (isObject(value)) { | ||
return keys(value) | ||
.filter(function(k) { | ||
return value[k]; | ||
}) | ||
.join(" "); | ||
} else if (isVisibleChild(value)) { | ||
return "" + value; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
function createElement(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI ? document.createElementNS(attr.namespaceURI, tag) | ||
// : isProbablySVG(tag) ? document.createElementNS( SVGNamespace, tag ) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(tslib_1.__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI | ||
? document.createElementNS(attr.namespaceURI, tag) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(tslib_1.__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
} | ||
function appendChild(child, node) { | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment('')); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment("")); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
} | ||
function appendChildren(children, node) { | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var value = attr[key]; | ||
switch (key) { | ||
case 'style': | ||
if (isObject(value)) { | ||
for (var _b = 0, _c = keys(value); _b < _c.length; _b++) { | ||
var styleKey = _c[_b]; | ||
node.style[styleKey] = value[styleKey]; | ||
} | ||
continue; | ||
} | ||
break; | ||
case 'dataset': | ||
if (isObject(value)) { | ||
for (var _d = 0, _e = keys(value); _d < _e.length; _d++) { | ||
var dataKey = _e[_d]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
} | ||
} | ||
continue; | ||
case 'innerHTML': | ||
case 'innerText': | ||
case 'textContent': | ||
node[key] = value; | ||
continue; | ||
case 'spellCheck': | ||
node.spellcheck = value; | ||
continue; | ||
case 'class': | ||
case 'className': | ||
node.setAttribute('class', className(value)); | ||
continue; | ||
case 'ref': | ||
case 'namespaceURI': | ||
continue; | ||
function attribute(key, value, node) { | ||
switch (key) { | ||
case "dataset": | ||
for (var _i = 0, _a = keys(value || {}); _i < _a.length; _i++) { | ||
var dataKey = _a[_i]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === 'o' && key[1] === 'n') { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
} else if (node) { | ||
if (value === true) { | ||
node.setAttribute(key, ''); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
} | ||
return; | ||
case "innerHTML": | ||
case "innerText": | ||
case "textContent": | ||
node[key] = value; | ||
return; | ||
case "spellCheck": | ||
node.spellcheck = value; | ||
return; | ||
case "class": | ||
case "className": | ||
node.setAttribute("class", className(value)); | ||
return; | ||
case "ref": | ||
case "namespaceURI": | ||
return; | ||
case "style": | ||
if (isObject(value)) { | ||
tslib_1.__assign(node.style, value); | ||
return; | ||
} | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === "o" && key[1] === "n") { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
return node; | ||
} else if (value === true) { | ||
node.setAttribute(key, ""); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
attribute(key, attr[key], node); | ||
} | ||
return node; | ||
} | ||
function listen(node, eventName, callback) { | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
} | ||
@@ -214,0 +218,0 @@ |
333
index.js
@@ -1,85 +0,90 @@ | ||
import { __assign } from 'tslib'; | ||
import { __assign } from "tslib"; | ||
var keys = Object.keys; | ||
function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
return typeof val === "boolean"; | ||
} | ||
function isElement(val) { | ||
return val && typeof val.nodeType === 'number'; | ||
return val && typeof val.nodeType === "number"; | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
return typeof val === "string"; | ||
} | ||
function isNumber(val) { | ||
return typeof val === 'number'; | ||
return typeof val === "number"; | ||
} | ||
function isObject(val) { | ||
return val && (typeof val === 'object' || isFunction(val)); | ||
return typeof val === "object" ? val !== null : isFunction(val); | ||
} | ||
// tslint:disable-next-line:ban-types | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
return typeof val === "function"; | ||
} | ||
function isArrayLike(obj) { | ||
return isObject(obj) && typeof obj.length === 'number' && typeof obj.nodeType !== 'number'; | ||
return ( | ||
isObject(obj) && | ||
typeof obj.length === "number" && | ||
typeof obj.nodeType !== "number" | ||
); | ||
} | ||
function f(tag) { | ||
return function create(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
return function(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
} | ||
/** @type {any} */ | ||
var DOM = function (obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
}({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
thead: 0, | ||
td: 0, | ||
th: 0, | ||
tr: 0, | ||
ul: 0 | ||
var DOM = (function(obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
})({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
td: 0, | ||
th: 0, | ||
thead: 0, | ||
tr: 0, | ||
ul: 0 | ||
}); | ||
var SVGNamespace = 'http://www.w3.org/2000/svg'; | ||
var SVGNamespace = "http://www.w3.org/2000/svg"; | ||
function preventDefault(event) { | ||
event.preventDefault(); | ||
return event; | ||
event.preventDefault(); | ||
return event; | ||
} | ||
function stopPropagation(event) { | ||
event.stopPropagation(); | ||
return event; | ||
event.stopPropagation(); | ||
return event; | ||
} | ||
@@ -89,3 +94,3 @@ // https://facebook.github.io/react/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored | ||
function isVisibleChild(value) { | ||
return !isBoolean(value) && value != null; | ||
return !isBoolean(value) && value != null; | ||
} | ||
@@ -97,115 +102,121 @@ /** | ||
function className(value) { | ||
if (Array.isArray(value)) { | ||
return value.map(className).filter(Boolean).join(' '); | ||
} else if (isObject(value)) { | ||
return keys(value).filter(function (k) { | ||
return value[k]; | ||
}).join(' '); | ||
} else if (isVisibleChild(value)) { | ||
return '' + value; | ||
} else { | ||
return ''; | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.map(className) | ||
.filter(Boolean) | ||
.join(" "); | ||
} else if (isObject(value)) { | ||
return keys(value) | ||
.filter(function(k) { | ||
return value[k]; | ||
}) | ||
.join(" "); | ||
} else if (isVisibleChild(value)) { | ||
return "" + value; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
function createElement(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI ? document.createElementNS(attr.namespaceURI, tag) | ||
// : isProbablySVG(tag) ? document.createElementNS( SVGNamespace, tag ) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI | ||
? document.createElementNS(attr.namespaceURI, tag) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
} | ||
function appendChild(child, node) { | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment('')); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment("")); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
} | ||
function appendChildren(children, node) { | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var value = attr[key]; | ||
switch (key) { | ||
case 'style': | ||
if (isObject(value)) { | ||
for (var _b = 0, _c = keys(value); _b < _c.length; _b++) { | ||
var styleKey = _c[_b]; | ||
node.style[styleKey] = value[styleKey]; | ||
} | ||
continue; | ||
} | ||
break; | ||
case 'dataset': | ||
if (isObject(value)) { | ||
for (var _d = 0, _e = keys(value); _d < _e.length; _d++) { | ||
var dataKey = _e[_d]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
} | ||
} | ||
continue; | ||
case 'innerHTML': | ||
case 'innerText': | ||
case 'textContent': | ||
node[key] = value; | ||
continue; | ||
case 'spellCheck': | ||
node.spellcheck = value; | ||
continue; | ||
case 'class': | ||
case 'className': | ||
node.setAttribute('class', className(value)); | ||
continue; | ||
case 'ref': | ||
case 'namespaceURI': | ||
continue; | ||
function attribute(key, value, node) { | ||
switch (key) { | ||
case "dataset": | ||
for (var _i = 0, _a = keys(value || {}); _i < _a.length; _i++) { | ||
var dataKey = _a[_i]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === 'o' && key[1] === 'n') { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
} else if (node) { | ||
if (value === true) { | ||
node.setAttribute(key, ''); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
} | ||
return; | ||
case "innerHTML": | ||
case "innerText": | ||
case "textContent": | ||
node[key] = value; | ||
return; | ||
case "spellCheck": | ||
node.spellcheck = value; | ||
return; | ||
case "class": | ||
case "className": | ||
node.setAttribute("class", className(value)); | ||
return; | ||
case "ref": | ||
case "namespaceURI": | ||
return; | ||
case "style": | ||
if (isObject(value)) { | ||
__assign(node.style, value); | ||
return; | ||
} | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === "o" && key[1] === "n") { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
return node; | ||
} else if (value === true) { | ||
node.setAttribute(key, ""); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
attribute(key, attr[key], node); | ||
} | ||
return node; | ||
} | ||
function listen(node, eventName, callback) { | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
} | ||
export { SVGNamespace, preventDefault, stopPropagation, createElement as h, createElement, DOM }; | ||
export { | ||
SVGNamespace, | ||
preventDefault, | ||
stopPropagation, | ||
createElement as h, | ||
createElement, | ||
DOM | ||
}; |
{ | ||
"name": "jsx-dom", | ||
"version": "5.1.6", | ||
"version": "5.2.0", | ||
"description": "JSX to document.createElement.", | ||
@@ -12,3 +12,3 @@ "main": "index.cjs.js", | ||
"postpublish": "rm index.js index.cjs.js svg.js svg.cjs.js", | ||
"test": "nyc --reporter=html mocha ./test/test.tsx --compilers ts:ts-node/register" | ||
"test": "nyc --reporter=html mocha ./test/test.tsx --require ts-node/register" | ||
}, | ||
@@ -20,3 +20,3 @@ "keywords": [ | ||
"author": "@alexlur", | ||
"license": "MIT", | ||
"license": "BSD-3-Clause", | ||
"devDependencies": { | ||
@@ -28,4 +28,5 @@ "@alexlur/rollup-plugin-typescript": "^1.0.4", | ||
"@types/mocha": "^2.2.44", | ||
"@types/node": "^8.0.49", | ||
"@types/node": "^8.0.50", | ||
"babel-core": "^6.26.0", | ||
"babel-preset-minify": "^0.2.0", | ||
"chai": "^4.1.2", | ||
@@ -36,3 +37,5 @@ "coffeescript": "^2.0.2", | ||
"nyc": "^11.3.0", | ||
"rollup": "^0.50.0", | ||
"rollup": "^0.51.1", | ||
"rollup-plugin-prettier": "^0.3.0", | ||
"rollup-plugin-replace": "^2.0.0", | ||
"ts-node": "^3.3.0", | ||
@@ -39,0 +42,0 @@ "typescript": "^2.6.1" |
@@ -77,3 +77,3 @@ # jsx-dom | ||
### Other Attributes | ||
1. `dataset` accepts an object. | ||
1. `dataset` accepts an object, where keys with a `null` or `undefined` value will be ignored. | ||
2. Attributes starts with `on` and has a function value will be treated as an event listener and attached to the node with `addEventListener`. | ||
@@ -80,0 +80,0 @@ 3. `innerHTML`, `innerText` and `textContent` are accepted. |
500
svg.cjs.js
@@ -1,89 +0,96 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require('tslib'); | ||
var tslib_1 = require("tslib"); | ||
var keys = Object.keys; | ||
function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
return typeof val === "boolean"; | ||
} | ||
function isElement(val) { | ||
return val && typeof val.nodeType === 'number'; | ||
return val && typeof val.nodeType === "number"; | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
return typeof val === "string"; | ||
} | ||
function isNumber(val) { | ||
return typeof val === 'number'; | ||
return typeof val === "number"; | ||
} | ||
function isObject(val) { | ||
return val && (typeof val === 'object' || isFunction(val)); | ||
return typeof val === "object" ? val !== null : isFunction(val); | ||
} | ||
// tslint:disable-next-line:ban-types | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
return typeof val === "function"; | ||
} | ||
function isArrayLike(obj) { | ||
return isObject(obj) && typeof obj.length === 'number' && typeof obj.nodeType !== 'number'; | ||
return ( | ||
isObject(obj) && | ||
typeof obj.length === "number" && | ||
typeof obj.nodeType !== "number" | ||
); | ||
} | ||
function f(tag) { | ||
return function create(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement$1(tag, attr, children); | ||
}; | ||
return function(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
} | ||
/** @type {any} */ | ||
var DOM = function (obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
}({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
thead: 0, | ||
td: 0, | ||
th: 0, | ||
tr: 0, | ||
ul: 0 | ||
var DOM = (function(obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
})({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
td: 0, | ||
th: 0, | ||
thead: 0, | ||
tr: 0, | ||
ul: 0 | ||
}); | ||
var SVGNamespace = 'http://www.w3.org/2000/svg'; | ||
var SVGNamespace = "http://www.w3.org/2000/svg"; | ||
var XLinkNamespace = "http://www.w3.org/1999/xlink"; | ||
var XMLNamespace = "http://www.w3.org/XML/1998/namespace"; | ||
function preventDefault(event) { | ||
event.preventDefault(); | ||
return event; | ||
event.preventDefault(); | ||
return event; | ||
} | ||
function stopPropagation(event) { | ||
event.stopPropagation(); | ||
return event; | ||
event.stopPropagation(); | ||
return event; | ||
} | ||
@@ -93,3 +100,3 @@ // https://facebook.github.io/react/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored | ||
function isVisibleChild(value) { | ||
return !isBoolean(value) && value != null; | ||
return !isBoolean(value) && value != null; | ||
} | ||
@@ -101,195 +108,204 @@ /** | ||
function className(value) { | ||
if (Array.isArray(value)) { | ||
return value.map(className).filter(Boolean).join(' '); | ||
} else if (isObject(value)) { | ||
return keys(value).filter(function (k) { | ||
return value[k]; | ||
}).join(' '); | ||
} else if (isVisibleChild(value)) { | ||
return '' + value; | ||
} else { | ||
return ''; | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.map(className) | ||
.filter(Boolean) | ||
.join(" "); | ||
} else if (isObject(value)) { | ||
return keys(value) | ||
.filter(function(k) { | ||
return value[k]; | ||
}) | ||
.join(" "); | ||
} else if (isVisibleChild(value)) { | ||
return "" + value; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
function createElement$1(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI ? document.createElementNS(attr.namespaceURI, tag) | ||
// : isProbablySVG(tag) ? document.createElementNS( SVGNamespace, tag ) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(tslib_1.__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
var svg = { | ||
animate: 0, | ||
circle: 0, | ||
clipPath: 0, | ||
defs: 0, | ||
desc: 0, | ||
ellipse: 0, | ||
feBlend: 0, | ||
feColorMatrix: 0, | ||
feComponentTransfer: 0, | ||
feComposite: 0, | ||
feConvolveMatrix: 0, | ||
feDiffuseLighting: 0, | ||
feDisplacementMap: 0, | ||
feDistantLight: 0, | ||
feFlood: 0, | ||
feFuncA: 0, | ||
feFuncB: 0, | ||
feFuncG: 0, | ||
feFuncR: 0, | ||
feGaussianBlur: 0, | ||
feImage: 0, | ||
feMerge: 0, | ||
feMergeNode: 0, | ||
feMorphology: 0, | ||
feOffset: 0, | ||
fePointLight: 0, | ||
feSpecularLighting: 0, | ||
feSpotLight: 0, | ||
feTile: 0, | ||
feTurbulence: 0, | ||
filter: 0, | ||
foreignObject: 0, | ||
g: 0, | ||
image: 0, | ||
line: 0, | ||
linearGradient: 0, | ||
marker: 0, | ||
mask: 0, | ||
metadata: 0, | ||
path: 0, | ||
pattern: 0, | ||
polygon: 0, | ||
polyline: 0, | ||
radialGradient: 0, | ||
rect: 0, | ||
stop: 0, | ||
svg: 0, | ||
switch: 0, | ||
symbol: 0, | ||
text: 0, | ||
textPath: 0, | ||
tspan: 0, | ||
use: 0, | ||
view: 0 | ||
}; | ||
function createElement(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
if (!attr.namespaceURI && svg[tag] === 0) { | ||
attr = tslib_1.__assign({}, attr, { namespaceURI: SVGNamespace }); | ||
} | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI | ||
? document.createElementNS(attr.namespaceURI, tag) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(tslib_1.__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
} | ||
function appendChild(child, node) { | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment('')); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment("")); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
} | ||
function appendChildren(children, node) { | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
} | ||
var normalizeAttribute = function(s) { | ||
return s.replace(/[A-Z\d]/g, function(match) { | ||
return ":" + match.toLowerCase(); | ||
}); | ||
}; | ||
function attribute(key, value, node) { | ||
{ | ||
switch (key) { | ||
case "xlinkActuate": | ||
case "xlinkArcrole": | ||
case "xlinkHref": | ||
case "xlinkRole": | ||
case "xlinkShow": | ||
case "xlinkTitle": | ||
case "xlinkType": | ||
node.setAttributeNS(XLinkNamespace, normalizeAttribute(key), value); | ||
return; | ||
case "xmlnsXlink": | ||
node.setAttribute(normalizeAttribute(key), value); | ||
return; | ||
case "xmlBase": | ||
case "xmlLang": | ||
case "xmlSpace": | ||
node.setAttributeNS(XMLNamespace, normalizeAttribute(key), value); | ||
return; | ||
} | ||
return node; | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var value = attr[key]; | ||
switch (key) { | ||
case 'style': | ||
if (isObject(value)) { | ||
for (var _b = 0, _c = keys(value); _b < _c.length; _b++) { | ||
var styleKey = _c[_b]; | ||
node.style[styleKey] = value[styleKey]; | ||
} | ||
continue; | ||
} | ||
break; | ||
case 'dataset': | ||
if (isObject(value)) { | ||
for (var _d = 0, _e = keys(value); _d < _e.length; _d++) { | ||
var dataKey = _e[_d]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
} | ||
} | ||
continue; | ||
case 'innerHTML': | ||
case 'innerText': | ||
case 'textContent': | ||
node[key] = value; | ||
continue; | ||
case 'spellCheck': | ||
node.spellcheck = value; | ||
continue; | ||
case 'class': | ||
case 'className': | ||
node.setAttribute('class', className(value)); | ||
continue; | ||
case 'ref': | ||
case 'namespaceURI': | ||
continue; | ||
} | ||
switch (key) { | ||
case "dataset": | ||
for (var _i = 0, _a = keys(value || {}); _i < _a.length; _i++) { | ||
var dataKey = _a[_i]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === 'o' && key[1] === 'n') { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
} else if (node) { | ||
if (value === true) { | ||
node.setAttribute(key, ''); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
} | ||
return; | ||
case "innerHTML": | ||
case "innerText": | ||
case "textContent": | ||
node[key] = value; | ||
return; | ||
case "spellCheck": | ||
node.spellcheck = value; | ||
return; | ||
case "class": | ||
case "className": | ||
node.setAttribute("class", className(value)); | ||
return; | ||
case "ref": | ||
case "namespaceURI": | ||
return; | ||
case "style": | ||
if (isObject(value)) { | ||
tslib_1.__assign(node.style, value); | ||
return; | ||
} | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === "o" && key[1] === "n") { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
return node; | ||
} else if (value === true) { | ||
node.setAttribute(key, ""); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
attribute(key, attr[key], node); | ||
} | ||
return node; | ||
} | ||
function listen(node, eventName, callback) { | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
} | ||
var dom = Object.freeze({ | ||
SVGNamespace: SVGNamespace, | ||
preventDefault: preventDefault, | ||
stopPropagation: stopPropagation, | ||
h: createElement$1, | ||
createElement: createElement$1, | ||
DOM: DOM | ||
}); | ||
var svg = tslib_1.__assign(Object.create(null), { | ||
svg: 0, | ||
animate: 0, | ||
circle: 0, | ||
clipPath: 0, | ||
defs: 0, | ||
desc: 0, | ||
ellipse: 0, | ||
feBlend: 0, | ||
feColorMatrix: 0, | ||
feComponentTransfer: 0, | ||
feComposite: 0, | ||
feConvolveMatrix: 0, | ||
feDiffuseLighting: 0, | ||
feDisplacementMap: 0, | ||
feDistantLight: 0, | ||
feFlood: 0, | ||
feFuncA: 0, | ||
feFuncB: 0, | ||
feFuncG: 0, | ||
feFuncR: 0, | ||
feGaussianBlur: 0, | ||
feImage: 0, | ||
feMerge: 0, | ||
feMergeNode: 0, | ||
feMorphology: 0, | ||
feOffset: 0, | ||
fePointLight: 0, | ||
feSpecularLighting: 0, | ||
feSpotLight: 0, | ||
feTile: 0, | ||
feTurbulence: 0, | ||
filter: 0, | ||
foreignObject: 0, | ||
g: 0, | ||
image: 0, | ||
line: 0, | ||
linearGradient: 0, | ||
marker: 0, | ||
mask: 0, | ||
metadata: 0, | ||
path: 0, | ||
pattern: 0, | ||
polygon: 0, | ||
polyline: 0, | ||
radialGradient: 0, | ||
rect: 0, | ||
stop: 0, | ||
switch: 0, | ||
symbol: 0, | ||
text: 0, | ||
textPath: 0, | ||
tspan: 0, | ||
use: 0, | ||
view: 0 | ||
}); | ||
function createElement(tag, attr) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
if ((!attr || !attr.namespaceURI) && tag in svg) { | ||
attr = tslib_1.__assign({}, attr, { namespaceURI: SVGNamespace }); | ||
} | ||
return createElement$1.apply(dom, [tag, attr].concat(args)); | ||
} | ||
exports.SVGNamespace = SVGNamespace; | ||
exports.preventDefault = preventDefault; | ||
exports.stopPropagation = stopPropagation; | ||
exports.h = createElement; | ||
exports.createElement = createElement; | ||
exports.DOM = DOM; | ||
exports.SVGNamespace = SVGNamespace; | ||
exports.stopPropagation = stopPropagation; | ||
exports.preventDefault = preventDefault; |
498
svg.js
@@ -1,85 +0,92 @@ | ||
import { __assign } from 'tslib'; | ||
import { __assign } from "tslib"; | ||
var keys = Object.keys; | ||
function isBoolean(val) { | ||
return typeof val === 'boolean'; | ||
return typeof val === "boolean"; | ||
} | ||
function isElement(val) { | ||
return val && typeof val.nodeType === 'number'; | ||
return val && typeof val.nodeType === "number"; | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
return typeof val === "string"; | ||
} | ||
function isNumber(val) { | ||
return typeof val === 'number'; | ||
return typeof val === "number"; | ||
} | ||
function isObject(val) { | ||
return val && (typeof val === 'object' || isFunction(val)); | ||
return typeof val === "object" ? val !== null : isFunction(val); | ||
} | ||
// tslint:disable-next-line:ban-types | ||
function isFunction(val) { | ||
return typeof val === 'function'; | ||
return typeof val === "function"; | ||
} | ||
function isArrayLike(obj) { | ||
return isObject(obj) && typeof obj.length === 'number' && typeof obj.nodeType !== 'number'; | ||
return ( | ||
isObject(obj) && | ||
typeof obj.length === "number" && | ||
typeof obj.nodeType !== "number" | ||
); | ||
} | ||
function f(tag) { | ||
return function create(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement$1(tag, attr, children); | ||
}; | ||
return function(attr) { | ||
var children = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
children[_i - 1] = arguments[_i]; | ||
} | ||
if (isElement(attr) || isString(attr)) { | ||
children.unshift(attr); | ||
attr = {}; | ||
} | ||
return createElement(tag, attr, children); | ||
}; | ||
} | ||
/** @type {any} */ | ||
var DOM = function (obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
}({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
thead: 0, | ||
td: 0, | ||
th: 0, | ||
tr: 0, | ||
ul: 0 | ||
var DOM = (function(obj) { | ||
for (var _i = 0, _a = keys(obj); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
obj[key] = f(key); | ||
} | ||
return obj; | ||
})({ | ||
a: 0, | ||
blockquote: 0, | ||
button: 0, | ||
div: 0, | ||
em: 0, | ||
form: 0, | ||
h1: 0, | ||
h2: 0, | ||
h3: 0, | ||
h4: 0, | ||
h5: 0, | ||
h6: 0, | ||
hr: 0, | ||
img: 0, | ||
input: 0, | ||
li: 0, | ||
link: 0, | ||
ol: 0, | ||
p: 0, | ||
script: 0, | ||
span: 0, | ||
strong: 0, | ||
table: 0, | ||
td: 0, | ||
th: 0, | ||
thead: 0, | ||
tr: 0, | ||
ul: 0 | ||
}); | ||
var SVGNamespace = 'http://www.w3.org/2000/svg'; | ||
var SVGNamespace = "http://www.w3.org/2000/svg"; | ||
var XLinkNamespace = "http://www.w3.org/1999/xlink"; | ||
var XMLNamespace = "http://www.w3.org/XML/1998/namespace"; | ||
function preventDefault(event) { | ||
event.preventDefault(); | ||
return event; | ||
event.preventDefault(); | ||
return event; | ||
} | ||
function stopPropagation(event) { | ||
event.stopPropagation(); | ||
return event; | ||
event.stopPropagation(); | ||
return event; | ||
} | ||
@@ -89,3 +96,3 @@ // https://facebook.github.io/react/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored | ||
function isVisibleChild(value) { | ||
return !isBoolean(value) && value != null; | ||
return !isBoolean(value) && value != null; | ||
} | ||
@@ -97,191 +104,206 @@ /** | ||
function className(value) { | ||
if (Array.isArray(value)) { | ||
return value.map(className).filter(Boolean).join(' '); | ||
} else if (isObject(value)) { | ||
return keys(value).filter(function (k) { | ||
return value[k]; | ||
}).join(' '); | ||
} else if (isVisibleChild(value)) { | ||
return '' + value; | ||
} else { | ||
return ''; | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.map(className) | ||
.filter(Boolean) | ||
.join(" "); | ||
} else if (isObject(value)) { | ||
return keys(value) | ||
.filter(function(k) { | ||
return value[k]; | ||
}) | ||
.join(" "); | ||
} else if (isVisibleChild(value)) { | ||
return "" + value; | ||
} else { | ||
return ""; | ||
} | ||
} | ||
function createElement$1(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI ? document.createElementNS(attr.namespaceURI, tag) | ||
// : isProbablySVG(tag) ? document.createElementNS( SVGNamespace, tag ) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
var svg = { | ||
animate: 0, | ||
circle: 0, | ||
clipPath: 0, | ||
defs: 0, | ||
desc: 0, | ||
ellipse: 0, | ||
feBlend: 0, | ||
feColorMatrix: 0, | ||
feComponentTransfer: 0, | ||
feComposite: 0, | ||
feConvolveMatrix: 0, | ||
feDiffuseLighting: 0, | ||
feDisplacementMap: 0, | ||
feDistantLight: 0, | ||
feFlood: 0, | ||
feFuncA: 0, | ||
feFuncB: 0, | ||
feFuncG: 0, | ||
feFuncR: 0, | ||
feGaussianBlur: 0, | ||
feImage: 0, | ||
feMerge: 0, | ||
feMergeNode: 0, | ||
feMorphology: 0, | ||
feOffset: 0, | ||
fePointLight: 0, | ||
feSpecularLighting: 0, | ||
feSpotLight: 0, | ||
feTile: 0, | ||
feTurbulence: 0, | ||
filter: 0, | ||
foreignObject: 0, | ||
g: 0, | ||
image: 0, | ||
line: 0, | ||
linearGradient: 0, | ||
marker: 0, | ||
mask: 0, | ||
metadata: 0, | ||
path: 0, | ||
pattern: 0, | ||
polygon: 0, | ||
polyline: 0, | ||
radialGradient: 0, | ||
rect: 0, | ||
stop: 0, | ||
svg: 0, | ||
switch: 0, | ||
symbol: 0, | ||
text: 0, | ||
textPath: 0, | ||
tspan: 0, | ||
use: 0, | ||
view: 0 | ||
}; | ||
function createElement(tag, attr) { | ||
var children = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
children[_i - 2] = arguments[_i]; | ||
} | ||
attr = attr || {}; | ||
if (!attr.namespaceURI && svg[tag] === 0) { | ||
attr = __assign({}, attr, { namespaceURI: SVGNamespace }); | ||
} | ||
var node; | ||
if (isString(tag)) { | ||
node = attr.namespaceURI | ||
? document.createElementNS(attr.namespaceURI, tag) | ||
: document.createElement(tag); | ||
attributes(attr, node); | ||
appendChildren(children, node); | ||
} else if (isFunction(tag)) { | ||
// Custom elements. | ||
node = tag(__assign({}, attr, { children: children })); | ||
} | ||
if (isFunction(attr.ref)) { | ||
attr.ref(node); | ||
} | ||
return node; | ||
} | ||
function appendChild(child, node) { | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment('')); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
if (isArrayLike(child)) { | ||
appendChildren(child, node); | ||
} else if (isString(child) || isNumber(child)) { | ||
node.appendChild(document.createTextNode(child)); | ||
} else if (child === null) { | ||
node.appendChild(document.createComment("")); | ||
} else if (isElement(child)) { | ||
node.appendChild(child); | ||
} | ||
} | ||
function appendChildren(children, node) { | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
for (var _i = 0, children_1 = children; _i < children_1.length; _i++) { | ||
var child = children_1[_i]; | ||
appendChild(child, node); | ||
} | ||
return node; | ||
} | ||
var normalizeAttribute = function(s) { | ||
return s.replace(/[A-Z\d]/g, function(match) { | ||
return ":" + match.toLowerCase(); | ||
}); | ||
}; | ||
function attribute(key, value, node) { | ||
{ | ||
switch (key) { | ||
case "xlinkActuate": | ||
case "xlinkArcrole": | ||
case "xlinkHref": | ||
case "xlinkRole": | ||
case "xlinkShow": | ||
case "xlinkTitle": | ||
case "xlinkType": | ||
node.setAttributeNS(XLinkNamespace, normalizeAttribute(key), value); | ||
return; | ||
case "xmlnsXlink": | ||
node.setAttribute(normalizeAttribute(key), value); | ||
return; | ||
case "xmlBase": | ||
case "xmlLang": | ||
case "xmlSpace": | ||
node.setAttributeNS(XMLNamespace, normalizeAttribute(key), value); | ||
return; | ||
} | ||
return node; | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var value = attr[key]; | ||
switch (key) { | ||
case 'style': | ||
if (isObject(value)) { | ||
for (var _b = 0, _c = keys(value); _b < _c.length; _b++) { | ||
var styleKey = _c[_b]; | ||
node.style[styleKey] = value[styleKey]; | ||
} | ||
continue; | ||
} | ||
break; | ||
case 'dataset': | ||
if (isObject(value)) { | ||
for (var _d = 0, _e = keys(value); _d < _e.length; _d++) { | ||
var dataKey = _e[_d]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
} | ||
} | ||
continue; | ||
case 'innerHTML': | ||
case 'innerText': | ||
case 'textContent': | ||
node[key] = value; | ||
continue; | ||
case 'spellCheck': | ||
node.spellcheck = value; | ||
continue; | ||
case 'class': | ||
case 'className': | ||
node.setAttribute('class', className(value)); | ||
continue; | ||
case 'ref': | ||
case 'namespaceURI': | ||
continue; | ||
} | ||
switch (key) { | ||
case "dataset": | ||
for (var _i = 0, _a = keys(value || {}); _i < _a.length; _i++) { | ||
var dataKey = _a[_i]; | ||
var dataValue = value[dataKey]; | ||
if (dataValue != null) { | ||
node.dataset[dataKey] = dataValue; | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === 'o' && key[1] === 'n') { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
} else if (node) { | ||
if (value === true) { | ||
node.setAttribute(key, ''); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
} | ||
return; | ||
case "innerHTML": | ||
case "innerText": | ||
case "textContent": | ||
node[key] = value; | ||
return; | ||
case "spellCheck": | ||
node.spellcheck = value; | ||
return; | ||
case "class": | ||
case "className": | ||
node.setAttribute("class", className(value)); | ||
return; | ||
case "ref": | ||
case "namespaceURI": | ||
return; | ||
case "style": | ||
if (isObject(value)) { | ||
__assign(node.style, value); | ||
return; | ||
} | ||
} | ||
if (isFunction(value)) { | ||
if (key[0] === "o" && key[1] === "n") { | ||
var name = key.slice(2).toLowerCase(); | ||
listen(node, name, value); | ||
} | ||
return node; | ||
} else if (value === true) { | ||
node.setAttribute(key, ""); | ||
} else if (value !== false && value != null) { | ||
node.setAttribute(key, value); | ||
} | ||
} | ||
function attributes(attr, node) { | ||
for (var _i = 0, _a = keys(attr); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
attribute(key, attr[key], node); | ||
} | ||
return node; | ||
} | ||
function listen(node, eventName, callback) { | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
node.addEventListener(eventName, callback); | ||
return node; | ||
} | ||
var dom = Object.freeze({ | ||
SVGNamespace: SVGNamespace, | ||
preventDefault: preventDefault, | ||
stopPropagation: stopPropagation, | ||
h: createElement$1, | ||
createElement: createElement$1, | ||
DOM: DOM | ||
}); | ||
var svg = __assign(Object.create(null), { | ||
svg: 0, | ||
animate: 0, | ||
circle: 0, | ||
clipPath: 0, | ||
defs: 0, | ||
desc: 0, | ||
ellipse: 0, | ||
feBlend: 0, | ||
feColorMatrix: 0, | ||
feComponentTransfer: 0, | ||
feComposite: 0, | ||
feConvolveMatrix: 0, | ||
feDiffuseLighting: 0, | ||
feDisplacementMap: 0, | ||
feDistantLight: 0, | ||
feFlood: 0, | ||
feFuncA: 0, | ||
feFuncB: 0, | ||
feFuncG: 0, | ||
feFuncR: 0, | ||
feGaussianBlur: 0, | ||
feImage: 0, | ||
feMerge: 0, | ||
feMergeNode: 0, | ||
feMorphology: 0, | ||
feOffset: 0, | ||
fePointLight: 0, | ||
feSpecularLighting: 0, | ||
feSpotLight: 0, | ||
feTile: 0, | ||
feTurbulence: 0, | ||
filter: 0, | ||
foreignObject: 0, | ||
g: 0, | ||
image: 0, | ||
line: 0, | ||
linearGradient: 0, | ||
marker: 0, | ||
mask: 0, | ||
metadata: 0, | ||
path: 0, | ||
pattern: 0, | ||
polygon: 0, | ||
polyline: 0, | ||
radialGradient: 0, | ||
rect: 0, | ||
stop: 0, | ||
switch: 0, | ||
symbol: 0, | ||
text: 0, | ||
textPath: 0, | ||
tspan: 0, | ||
use: 0, | ||
view: 0 | ||
}); | ||
function createElement(tag, attr) { | ||
var args = []; | ||
for (var _i = 2; _i < arguments.length; _i++) { | ||
args[_i - 2] = arguments[_i]; | ||
} | ||
if ((!attr || !attr.namespaceURI) && tag in svg) { | ||
attr = __assign({}, attr, { namespaceURI: SVGNamespace }); | ||
} | ||
return createElement$1.apply(dom, [tag, attr].concat(args)); | ||
} | ||
export { createElement, DOM, SVGNamespace, stopPropagation, preventDefault }; | ||
export { | ||
SVGNamespace, | ||
preventDefault, | ||
stopPropagation, | ||
createElement as h, | ||
createElement, | ||
DOM | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
10
3340
130573
18