preact-render-to-string
Advanced tools
Comparing version 3.3.0 to 3.4.0
@@ -5,278 +5,278 @@ (function (global, factory) { | ||
(global.preactRenderToString = factory()); | ||
}(this, function () { | ||
}(this, (function () { | ||
var NON_DIMENSION_PROPS = { | ||
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1, | ||
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1, | ||
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1 | ||
}; | ||
var NON_DIMENSION_PROPS = { | ||
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1, | ||
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1, | ||
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1 | ||
}; | ||
var ESC = { | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'&': '&' | ||
}; | ||
var ESC = { | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'&': '&' | ||
}; | ||
var objectKeys = Object.keys || function (obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) keys.push(i); | ||
}return keys; | ||
}; | ||
var objectKeys = Object.keys || function (obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) keys.push(i); | ||
}return keys; | ||
}; | ||
var encodeEntities = function (s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var encodeEntities = function (s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var escapeChar = function (a) { | ||
return ESC[a] || a; | ||
}; | ||
var escapeChar = function (a) { | ||
return ESC[a] || a; | ||
}; | ||
var falsey = function (v) { | ||
return v == null || v === false; | ||
}; | ||
var falsey = function (v) { | ||
return v == null || v === false; | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return function (v) { | ||
return mem[v] || (mem[v] = fn(v)); | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return function (v) { | ||
return mem[v] || (mem[v] = fn(v)); | ||
}; | ||
}; | ||
var indent = function (s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var indent = function (s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
}; | ||
function styleObjToCss(s) { | ||
var str = ''; | ||
for (var prop in s) { | ||
var val = s[prop]; | ||
if (val != null) { | ||
if (str) str += ' '; | ||
str += jsToCss(prop); | ||
str += ': '; | ||
str += val; | ||
if (typeof val === 'number' && !NON_DIMENSION_PROPS[prop]) { | ||
str += 'px'; | ||
} | ||
str += ';'; | ||
function styleObjToCss(s) { | ||
var str = ''; | ||
for (var prop in s) { | ||
var val = s[prop]; | ||
if (val != null) { | ||
if (str) str += ' '; | ||
str += jsToCss(prop); | ||
str += ': '; | ||
str += val; | ||
if (typeof val === 'number' && !NON_DIMENSION_PROPS[prop]) { | ||
str += 'px'; | ||
} | ||
str += ';'; | ||
} | ||
return str; | ||
} | ||
return str; | ||
} | ||
function hashToClassName(c) { | ||
var str = ''; | ||
for (var prop in c) { | ||
if (c[prop]) { | ||
if (str) str += ' '; | ||
str += prop; | ||
} | ||
function hashToClassName(c) { | ||
var str = ''; | ||
for (var prop in c) { | ||
if (c[prop]) { | ||
if (str) str += ' '; | ||
str += prop; | ||
} | ||
return str; | ||
} | ||
return str; | ||
} | ||
var jsToCss = memoize(function (s) { | ||
return s.replace(/([A-Z])/g, '-$1').toLowerCase(); | ||
}); | ||
var jsToCss = memoize(function (s) { | ||
return s.replace(/([A-Z])/g, '-$1').toLowerCase(); | ||
}); | ||
function assign(obj, props) { | ||
for (var i in props) { | ||
obj[i] = props[i]; | ||
}return obj; | ||
} | ||
function assign(obj, props) { | ||
for (var i in props) { | ||
obj[i] = props[i]; | ||
}return obj; | ||
} | ||
function getNodeProps(vnode) { | ||
var defaultProps = vnode.nodeName.defaultProps, | ||
props = assign({}, defaultProps || vnode.attributes); | ||
if (defaultProps) assign(props, vnode.attributes); | ||
if (vnode.children) props.children = vnode.children; | ||
return props; | ||
} | ||
function getNodeProps(vnode) { | ||
var defaultProps = vnode.nodeName.defaultProps, | ||
props = assign({}, defaultProps || vnode.attributes); | ||
if (defaultProps) assign(props, vnode.attributes); | ||
if (vnode.children) props.children = vnode.children; | ||
return props; | ||
} | ||
var SHALLOW = { shallow: true }; | ||
var SHALLOW = { shallow: true }; | ||
var UNNAMED = []; | ||
var UNNAMED = []; | ||
var EMPTY = {}; | ||
var EMPTY = {}; | ||
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; | ||
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; | ||
renderToString.render = renderToString; | ||
renderToString.render = renderToString; | ||
var shallowRender = function (vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
}; | ||
var shallowRender = function (vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
}; | ||
function renderToString(vnode, context, opts, inner) { | ||
var _ref = vnode || EMPTY; | ||
function renderToString(vnode, context, opts, inner) { | ||
var _ref = vnode || EMPTY; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
opts = opts || {}; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
opts = opts || {}; | ||
var pretty = opts.pretty, | ||
indentChar = typeof pretty === 'string' ? pretty : '\t'; | ||
var pretty = opts.pretty, | ||
indentChar = typeof pretty === 'string' ? pretty : '\t'; | ||
if (vnode == null) { | ||
return ''; | ||
} | ||
if (vnode == null) { | ||
return ''; | ||
} | ||
if (!nodeName) { | ||
return encodeEntities(vnode); | ||
} | ||
if (!nodeName) { | ||
return encodeEntities(vnode); | ||
} | ||
if (typeof nodeName === 'function') { | ||
isComponent = true; | ||
if (opts.shallow && (inner || opts.renderRootComponent === false)) { | ||
nodeName = getComponentName(nodeName); | ||
if (typeof nodeName === 'function') { | ||
isComponent = true; | ||
if (opts.shallow && (inner || opts.renderRootComponent === false)) { | ||
nodeName = getComponentName(nodeName); | ||
} else { | ||
var props = getNodeProps(vnode), | ||
rendered = void 0; | ||
if (!nodeName.prototype || typeof nodeName.prototype.render !== 'function') { | ||
rendered = nodeName(props, context); | ||
} else { | ||
var props = getNodeProps(vnode), | ||
rendered = void 0; | ||
var c = new nodeName(props, context); | ||
c.props = props; | ||
c.context = context; | ||
if (c.componentWillMount) c.componentWillMount(); | ||
rendered = c.render(c.props, c.state, c.context); | ||
if (!nodeName.prototype || typeof nodeName.prototype.render !== 'function') { | ||
rendered = nodeName(props, context); | ||
} else { | ||
var c = new nodeName(props, context); | ||
c.props = props; | ||
c.context = context; | ||
if (c.componentWillMount) c.componentWillMount(); | ||
rendered = c.render(c.props, c.state, c.context); | ||
if (c.getChildContext) { | ||
context = assign(assign({}, context), c.getChildContext()); | ||
} | ||
if (c.getChildContext) { | ||
context = assign(assign({}, context), c.getChildContext()); | ||
} | ||
} | ||
return renderToString(rendered, context, opts, opts.shallowHighOrder !== false); | ||
} | ||
return renderToString(rendered, context, opts, opts.shallowHighOrder !== false); | ||
} | ||
} | ||
var s = '', | ||
html = void 0; | ||
var s = '', | ||
html = void 0; | ||
if (attributes) { | ||
var attrs = objectKeys(attributes); | ||
if (attributes) { | ||
var attrs = objectKeys(attributes); | ||
if (opts && opts.sortAttributes === true) attrs.sort(); | ||
if (opts && opts.sortAttributes === true) attrs.sort(); | ||
for (var i = 0; i < attrs.length; i++) { | ||
var name = attrs[i], | ||
v = attributes[name]; | ||
if (name === 'children') continue; | ||
if (!(opts && opts.allAttributes) && (name === 'key' || name === 'ref')) continue; | ||
for (var i = 0; i < attrs.length; i++) { | ||
var name = attrs[i], | ||
v = attributes[name]; | ||
if (name === 'children') continue; | ||
if (!(opts && opts.allAttributes) && (name === 'key' || name === 'ref')) continue; | ||
if (name === 'className') { | ||
if (attributes['class']) continue; | ||
name = 'class'; | ||
} | ||
if (name === 'className') { | ||
if (attributes['class']) continue; | ||
name = 'class'; | ||
} | ||
if (name === 'class' && v && typeof v === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
v = styleObjToCss(v); | ||
} | ||
if (name === 'class' && v && typeof v === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
v = styleObjToCss(v); | ||
} | ||
var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); | ||
if (hooked || hooked === '') { | ||
s += hooked; | ||
continue; | ||
} | ||
var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); | ||
if (hooked || hooked === '') { | ||
s += hooked; | ||
continue; | ||
} | ||
if (name === 'dangerouslySetInnerHTML') { | ||
html = v && v.__html; | ||
} else if ((v || v === 0) && typeof v !== 'function') { | ||
if (v === true) { | ||
v = name; | ||
if (name === 'dangerouslySetInnerHTML') { | ||
html = v && v.__html; | ||
} else if ((v || v === 0 || v === '') && typeof v !== 'object' && typeof v !== 'function') { | ||
if (v === true || v === '') { | ||
v = name; | ||
if (!opts || !opts.xml) { | ||
s += ' ' + name; | ||
continue; | ||
} | ||
if (!opts || !opts.xml) { | ||
s += ' ' + name; | ||
continue; | ||
} | ||
s += ' ' + name + '="' + encodeEntities(v) + '"'; | ||
} | ||
s += ' ' + name + '="' + encodeEntities(v) + '"'; | ||
} | ||
} | ||
} | ||
var sub = s.replace(/^\n\s*/, ' '); | ||
if (sub !== s && !~sub.indexOf('\n')) s = sub;else if (~s.indexOf('\n')) s += '\n'; | ||
var sub = s.replace(/^\n\s*/, ' '); | ||
if (sub !== s && !~sub.indexOf('\n')) s = sub;else if (~s.indexOf('\n')) s += '\n'; | ||
s = '<' + nodeName + s + '>'; | ||
s = '<' + nodeName + s + '>'; | ||
if (html) { | ||
if (pretty && isLargeString(html)) { | ||
html = '\n' + indentChar + indent(html, indentChar); | ||
if (html) { | ||
if (pretty && isLargeString(html)) { | ||
html = '\n' + indentChar + indent(html, indentChar); | ||
} | ||
s += html; | ||
} else { | ||
var len = children && children.length, | ||
pieces = [], | ||
hasLarge = ~s.indexOf('\n'); | ||
for (var _i = 0; _i < len; _i++) { | ||
var child = children[_i]; | ||
if (!falsey(child)) { | ||
var ret = renderToString(child, context, opts, true); | ||
if (!hasLarge && pretty && isLargeString(ret)) hasLarge = true; | ||
pieces.push(ret); | ||
} | ||
s += html; | ||
} else { | ||
var len = children && children.length, | ||
pieces = [], | ||
hasLarge = ~s.indexOf('\n'); | ||
for (var _i = 0; _i < len; _i++) { | ||
var child = children[_i]; | ||
if (!falsey(child)) { | ||
var ret = renderToString(child, context, opts, true); | ||
if (!hasLarge && pretty && isLargeString(ret)) hasLarge = true; | ||
pieces.push(ret); | ||
} | ||
} | ||
if (hasLarge) { | ||
for (var _i2 = pieces.length; _i2--;) { | ||
pieces[_i2] = '\n' + indentChar + indent(pieces[_i2], indentChar); | ||
} | ||
if (hasLarge) { | ||
for (var _i2 = pieces.length; _i2--;) { | ||
pieces[_i2] = '\n' + indentChar + indent(pieces[_i2], indentChar); | ||
} | ||
} | ||
if (pieces.length) { | ||
s += pieces.join(''); | ||
} else if (opts && opts.xml) { | ||
return s.substring(0, s.length - 1) + ' />'; | ||
} | ||
} | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
s += '</' + nodeName + '>'; | ||
if (pieces.length) { | ||
s += pieces.join(''); | ||
} else if (opts && opts.xml) { | ||
return s.substring(0, s.length - 1) + ' />'; | ||
} | ||
return s; | ||
} | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
s += '</' + nodeName + '>'; | ||
} | ||
function getFallbackComponentName(component) { | ||
var str = Function.prototype.toString.call(component), | ||
name = (str.match(/^\s*function\s+([^\( ]+)/) || EMPTY)[1]; | ||
if (!name) { | ||
var index = -1; | ||
for (var i = UNNAMED.length; i--;) { | ||
if (UNNAMED[i] === component) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
return s; | ||
} | ||
if (index < 0) { | ||
index = UNNAMED.push(component) - 1; | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
} | ||
function getFallbackComponentName(component) { | ||
var str = Function.prototype.toString.call(component), | ||
name = (str.match(/^\s*function\s+([^\( ]+)/) || EMPTY)[1]; | ||
if (!name) { | ||
var index = -1; | ||
for (var i = UNNAMED.length; i--;) { | ||
if (UNNAMED[i] === component) { | ||
index = i; | ||
break; | ||
} | ||
name = 'UnnamedComponent' + index; | ||
} | ||
return name; | ||
if (index < 0) { | ||
index = UNNAMED.push(component) - 1; | ||
} | ||
name = 'UnnamedComponent' + index; | ||
} | ||
renderToString.shallowRender = shallowRender; | ||
return name; | ||
} | ||
renderToString.shallowRender = shallowRender; | ||
return renderToString; | ||
return renderToString; | ||
})); | ||
}))); | ||
//# sourceMappingURL=index.js.map |
1068
dist/jsx.js
@@ -5,687 +5,703 @@ (function (global, factory) { | ||
(global.preactRenderToString = factory()); | ||
}(this, function () { | ||
}(this, (function () { | ||
if (typeof Symbol !== 'function') { | ||
(function () { | ||
var c = 0; | ||
Symbol = function (s) { | ||
return '@@' + s + ++c; | ||
}; | ||
Symbol.for = function (s) { | ||
return '@@' + s; | ||
}; | ||
})(); | ||
} | ||
if (typeof Symbol !== 'function') { | ||
(function () { | ||
var c = 0; | ||
Symbol = function (s) { | ||
return '@@' + s + ++c; | ||
}; | ||
Symbol.for = function (s) { | ||
return '@@' + s; | ||
}; | ||
})(); | ||
} | ||
var NON_DIMENSION_PROPS = { | ||
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1, | ||
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1, | ||
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1 | ||
}; | ||
var NON_DIMENSION_PROPS = { | ||
boxFlex: 1, boxFlexGroup: 1, columnCount: 1, fillOpacity: 1, flex: 1, flexGrow: 1, | ||
flexPositive: 1, flexShrink: 1, flexNegative: 1, fontWeight: 1, lineClamp: 1, lineHeight: 1, | ||
opacity: 1, order: 1, orphans: 1, strokeOpacity: 1, widows: 1, zIndex: 1, zoom: 1 | ||
}; | ||
var ESC = { | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'&': '&' | ||
}; | ||
var ESC = { | ||
'<': '<', | ||
'>': '>', | ||
'"': '"', | ||
'&': '&' | ||
}; | ||
var objectKeys = Object.keys || function (obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) keys.push(i); | ||
}return keys; | ||
}; | ||
var objectKeys = Object.keys || function (obj) { | ||
var keys = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) keys.push(i); | ||
}return keys; | ||
}; | ||
var encodeEntities = function (s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var encodeEntities = function (s) { | ||
return String(s).replace(/[<>"&]/g, escapeChar); | ||
}; | ||
var escapeChar = function (a) { | ||
return ESC[a] || a; | ||
}; | ||
var escapeChar = function (a) { | ||
return ESC[a] || a; | ||
}; | ||
var falsey = function (v) { | ||
return v == null || v === false; | ||
}; | ||
var falsey = function (v) { | ||
return v == null || v === false; | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return function (v) { | ||
return mem[v] || (mem[v] = fn(v)); | ||
}; | ||
}; | ||
var memoize = function (fn) { | ||
var mem = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
return function (v) { | ||
return mem[v] || (mem[v] = fn(v)); | ||
}; | ||
}; | ||
var indent = function (s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var indent = function (s, char) { | ||
return String(s).replace(/(\n+)/g, '$1' + (char || '\t')); | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
}; | ||
var isLargeString = function (s, length, ignoreLines) { | ||
return String(s).length > (length || 40) || !ignoreLines && String(s).indexOf('\n') !== -1 || String(s).indexOf('<') !== -1; | ||
}; | ||
function styleObjToCss(s) { | ||
var str = ''; | ||
for (var prop in s) { | ||
var val = s[prop]; | ||
if (val != null) { | ||
if (str) str += ' '; | ||
str += jsToCss(prop); | ||
str += ': '; | ||
str += val; | ||
if (typeof val === 'number' && !NON_DIMENSION_PROPS[prop]) { | ||
str += 'px'; | ||
} | ||
str += ';'; | ||
} | ||
} | ||
return str; | ||
} | ||
function styleObjToCss(s) { | ||
var str = ''; | ||
for (var prop in s) { | ||
var val = s[prop]; | ||
if (val != null) { | ||
if (str) str += ' '; | ||
str += jsToCss(prop); | ||
str += ': '; | ||
str += val; | ||
if (typeof val === 'number' && !NON_DIMENSION_PROPS[prop]) { | ||
str += 'px'; | ||
} | ||
str += ';'; | ||
} | ||
} | ||
return str; | ||
} | ||
function hashToClassName(c) { | ||
var str = ''; | ||
for (var prop in c) { | ||
if (c[prop]) { | ||
if (str) str += ' '; | ||
str += prop; | ||
} | ||
} | ||
return str; | ||
} | ||
function hashToClassName(c) { | ||
var str = ''; | ||
for (var prop in c) { | ||
if (c[prop]) { | ||
if (str) str += ' '; | ||
str += prop; | ||
} | ||
} | ||
return str; | ||
} | ||
var jsToCss = memoize(function (s) { | ||
return s.replace(/([A-Z])/g, '-$1').toLowerCase(); | ||
}); | ||
var jsToCss = memoize(function (s) { | ||
return s.replace(/([A-Z])/g, '-$1').toLowerCase(); | ||
}); | ||
function assign(obj, props) { | ||
for (var i in props) { | ||
obj[i] = props[i]; | ||
}return obj; | ||
} | ||
function assign(obj, props) { | ||
for (var i in props) { | ||
obj[i] = props[i]; | ||
}return obj; | ||
} | ||
function getNodeProps(vnode) { | ||
var defaultProps = vnode.nodeName.defaultProps, | ||
props = assign({}, defaultProps || vnode.attributes); | ||
if (defaultProps) assign(props, vnode.attributes); | ||
if (vnode.children) props.children = vnode.children; | ||
return props; | ||
} | ||
function getNodeProps(vnode) { | ||
var defaultProps = vnode.nodeName.defaultProps, | ||
props = assign({}, defaultProps || vnode.attributes); | ||
if (defaultProps) assign(props, vnode.attributes); | ||
if (vnode.children) props.children = vnode.children; | ||
return props; | ||
} | ||
var SHALLOW = { shallow: true }; | ||
var SHALLOW = { shallow: true }; | ||
var UNNAMED = []; | ||
var UNNAMED = []; | ||
var EMPTY = {}; | ||
var EMPTY = {}; | ||
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; | ||
var VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']; | ||
renderToString.render = renderToString; | ||
renderToString.render = renderToString; | ||
var shallowRender = function (vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
}; | ||
var shallowRender = function (vnode, context) { | ||
return renderToString(vnode, context, SHALLOW); | ||
}; | ||
function renderToString(vnode, context, opts, inner) { | ||
var _ref = vnode || EMPTY; | ||
function renderToString(vnode, context, opts, inner) { | ||
var _ref = vnode || EMPTY; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
opts = opts || {}; | ||
var nodeName = _ref.nodeName; | ||
var attributes = _ref.attributes; | ||
var children = _ref.children; | ||
var isComponent = false; | ||
context = context || {}; | ||
opts = opts || {}; | ||
var pretty = opts.pretty, | ||
indentChar = typeof pretty === 'string' ? pretty : '\t'; | ||
var pretty = opts.pretty, | ||
indentChar = typeof pretty === 'string' ? pretty : '\t'; | ||
if (vnode == null) { | ||
return ''; | ||
} | ||
if (vnode == null) { | ||
return ''; | ||
} | ||
if (!nodeName) { | ||
return encodeEntities(vnode); | ||
} | ||
if (!nodeName) { | ||
return encodeEntities(vnode); | ||
} | ||
if (typeof nodeName === 'function') { | ||
isComponent = true; | ||
if (opts.shallow && (inner || opts.renderRootComponent === false)) { | ||
nodeName = getComponentName(nodeName); | ||
} else { | ||
var props = getNodeProps(vnode), | ||
rendered = void 0; | ||
if (typeof nodeName === 'function') { | ||
isComponent = true; | ||
if (opts.shallow && (inner || opts.renderRootComponent === false)) { | ||
nodeName = getComponentName(nodeName); | ||
} else { | ||
var props = getNodeProps(vnode), | ||
rendered = void 0; | ||
if (!nodeName.prototype || typeof nodeName.prototype.render !== 'function') { | ||
rendered = nodeName(props, context); | ||
} else { | ||
var c = new nodeName(props, context); | ||
c.props = props; | ||
c.context = context; | ||
if (c.componentWillMount) c.componentWillMount(); | ||
rendered = c.render(c.props, c.state, c.context); | ||
if (!nodeName.prototype || typeof nodeName.prototype.render !== 'function') { | ||
rendered = nodeName(props, context); | ||
} else { | ||
var c = new nodeName(props, context); | ||
c.props = props; | ||
c.context = context; | ||
if (c.componentWillMount) c.componentWillMount(); | ||
rendered = c.render(c.props, c.state, c.context); | ||
if (c.getChildContext) { | ||
context = assign(assign({}, context), c.getChildContext()); | ||
} | ||
} | ||
if (c.getChildContext) { | ||
context = assign(assign({}, context), c.getChildContext()); | ||
} | ||
} | ||
return renderToString(rendered, context, opts, opts.shallowHighOrder !== false); | ||
} | ||
} | ||
return renderToString(rendered, context, opts, opts.shallowHighOrder !== false); | ||
} | ||
} | ||
var s = '', | ||
html = void 0; | ||
var s = '', | ||
html = void 0; | ||
if (attributes) { | ||
var attrs = objectKeys(attributes); | ||
if (attributes) { | ||
var attrs = objectKeys(attributes); | ||
if (opts && opts.sortAttributes === true) attrs.sort(); | ||
if (opts && opts.sortAttributes === true) attrs.sort(); | ||
for (var i = 0; i < attrs.length; i++) { | ||
var name = attrs[i], | ||
v = attributes[name]; | ||
if (name === 'children') continue; | ||
if (!(opts && opts.allAttributes) && (name === 'key' || name === 'ref')) continue; | ||
for (var i = 0; i < attrs.length; i++) { | ||
var name = attrs[i], | ||
v = attributes[name]; | ||
if (name === 'children') continue; | ||
if (!(opts && opts.allAttributes) && (name === 'key' || name === 'ref')) continue; | ||
if (name === 'className') { | ||
if (attributes['class']) continue; | ||
name = 'class'; | ||
} | ||
if (name === 'className') { | ||
if (attributes['class']) continue; | ||
name = 'class'; | ||
} | ||
if (name === 'class' && v && typeof v === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
v = styleObjToCss(v); | ||
} | ||
if (name === 'class' && v && typeof v === 'object') { | ||
v = hashToClassName(v); | ||
} else if (name === 'style' && v && typeof v === 'object') { | ||
v = styleObjToCss(v); | ||
} | ||
var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); | ||
if (hooked || hooked === '') { | ||
s += hooked; | ||
continue; | ||
} | ||
var hooked = opts.attributeHook && opts.attributeHook(name, v, context, opts, isComponent); | ||
if (hooked || hooked === '') { | ||
s += hooked; | ||
continue; | ||
} | ||
if (name === 'dangerouslySetInnerHTML') { | ||
html = v && v.__html; | ||
} else if ((v || v === 0) && typeof v !== 'function') { | ||
if (v === true) { | ||
v = name; | ||
if (name === 'dangerouslySetInnerHTML') { | ||
html = v && v.__html; | ||
} else if ((v || v === 0 || v === '') && typeof v !== 'object' && typeof v !== 'function') { | ||
if (v === true || v === '') { | ||
v = name; | ||
if (!opts || !opts.xml) { | ||
s += ' ' + name; | ||
continue; | ||
} | ||
} | ||
s += ' ' + name + '="' + encodeEntities(v) + '"'; | ||
} | ||
} | ||
} | ||
if (!opts || !opts.xml) { | ||
s += ' ' + name; | ||
continue; | ||
} | ||
} | ||
s += ' ' + name + '="' + encodeEntities(v) + '"'; | ||
} | ||
} | ||
} | ||
var sub = s.replace(/^\n\s*/, ' '); | ||
if (sub !== s && !~sub.indexOf('\n')) s = sub;else if (~s.indexOf('\n')) s += '\n'; | ||
var sub = s.replace(/^\n\s*/, ' '); | ||
if (sub !== s && !~sub.indexOf('\n')) s = sub;else if (~s.indexOf('\n')) s += '\n'; | ||
s = '<' + nodeName + s + '>'; | ||
s = '<' + nodeName + s + '>'; | ||
if (html) { | ||
if (pretty && isLargeString(html)) { | ||
html = '\n' + indentChar + indent(html, indentChar); | ||
} | ||
s += html; | ||
} else { | ||
var len = children && children.length, | ||
pieces = [], | ||
hasLarge = ~s.indexOf('\n'); | ||
for (var _i = 0; _i < len; _i++) { | ||
var child = children[_i]; | ||
if (!falsey(child)) { | ||
var ret = renderToString(child, context, opts, true); | ||
if (!hasLarge && pretty && isLargeString(ret)) hasLarge = true; | ||
pieces.push(ret); | ||
} | ||
} | ||
if (hasLarge) { | ||
for (var _i2 = pieces.length; _i2--;) { | ||
pieces[_i2] = '\n' + indentChar + indent(pieces[_i2], indentChar); | ||
} | ||
} | ||
if (pieces.length) { | ||
s += pieces.join(''); | ||
} else if (opts && opts.xml) { | ||
return s.substring(0, s.length - 1) + ' />'; | ||
} | ||
} | ||
if (html) { | ||
if (pretty && isLargeString(html)) { | ||
html = '\n' + indentChar + indent(html, indentChar); | ||
} | ||
s += html; | ||
} else { | ||
var len = children && children.length, | ||
pieces = [], | ||
hasLarge = ~s.indexOf('\n'); | ||
for (var _i = 0; _i < len; _i++) { | ||
var child = children[_i]; | ||
if (!falsey(child)) { | ||
var ret = renderToString(child, context, opts, true); | ||
if (!hasLarge && pretty && isLargeString(ret)) hasLarge = true; | ||
pieces.push(ret); | ||
} | ||
} | ||
if (hasLarge) { | ||
for (var _i2 = pieces.length; _i2--;) { | ||
pieces[_i2] = '\n' + indentChar + indent(pieces[_i2], indentChar); | ||
} | ||
} | ||
if (pieces.length) { | ||
s += pieces.join(''); | ||
} else if (opts && opts.xml) { | ||
return s.substring(0, s.length - 1) + ' />'; | ||
} | ||
} | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
s += '</' + nodeName + '>'; | ||
} | ||
if (opts.jsx || VOID_ELEMENTS.indexOf(nodeName) === -1) { | ||
if (pretty && ~s.indexOf('\n')) s += '\n'; | ||
s += '</' + nodeName + '>'; | ||
} | ||
return s; | ||
} | ||
return s; | ||
} | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
} | ||
function getComponentName(component) { | ||
var proto = component.prototype, | ||
ctor = proto && proto.constructor; | ||
return component.displayName || component.name || proto && (proto.displayName || proto.name) || getFallbackComponentName(component); | ||
} | ||
function getFallbackComponentName(component) { | ||
var str = Function.prototype.toString.call(component), | ||
name = (str.match(/^\s*function\s+([^\( ]+)/) || EMPTY)[1]; | ||
if (!name) { | ||
var index = -1; | ||
for (var i = UNNAMED.length; i--;) { | ||
if (UNNAMED[i] === component) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
function getFallbackComponentName(component) { | ||
var str = Function.prototype.toString.call(component), | ||
name = (str.match(/^\s*function\s+([^\( ]+)/) || EMPTY)[1]; | ||
if (!name) { | ||
var index = -1; | ||
for (var i = UNNAMED.length; i--;) { | ||
if (UNNAMED[i] === component) { | ||
index = i; | ||
break; | ||
} | ||
} | ||
if (index < 0) { | ||
index = UNNAMED.push(component) - 1; | ||
} | ||
name = 'UnnamedComponent' + index; | ||
} | ||
return name; | ||
} | ||
renderToString.shallowRender = shallowRender; | ||
if (index < 0) { | ||
index = UNNAMED.push(component) - 1; | ||
} | ||
name = 'UnnamedComponent' + index; | ||
} | ||
return name; | ||
} | ||
renderToString.shallowRender = shallowRender; | ||
function interopDefault(ex) { | ||
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; | ||
} | ||
function interopDefault(ex) { | ||
return ex && typeof ex === 'object' && 'default' in ex ? ex['default'] : ex; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var printString = createCommonjsModule(function (module) { | ||
'use strict'; | ||
var printString = createCommonjsModule(function (module) { | ||
'use strict'; | ||
var ESCAPED_CHARACTERS = /(\\|\"|\')/g; | ||
var ESCAPED_CHARACTERS = /(\\|\"|\')/g; | ||
module.exports = function printString(val) { | ||
return val.replace(ESCAPED_CHARACTERS, '\\$1'); | ||
}; | ||
}); | ||
module.exports = function printString(val) { | ||
return val.replace(ESCAPED_CHARACTERS, '\\$1'); | ||
}; | ||
}); | ||
var printString$1 = interopDefault(printString); | ||
var printString$1 = interopDefault(printString); | ||
var require$$0 = Object.freeze({ | ||
default: printString$1 | ||
}); | ||
default: printString$1 | ||
}); | ||
var index = createCommonjsModule(function (module) { | ||
'use strict'; | ||
var index = createCommonjsModule(function (module) { | ||
'use strict'; | ||
var printString = interopDefault(require$$0); | ||
var printString = interopDefault(require$$0); | ||
var toString = Object.prototype.toString; | ||
var toISOString = Date.prototype.toISOString; | ||
var errorToString = Error.prototype.toString; | ||
var regExpToString = RegExp.prototype.toString; | ||
var symbolToString = Symbol.prototype.toString; | ||
var toString = Object.prototype.toString; | ||
var toISOString = Date.prototype.toISOString; | ||
var errorToString = Error.prototype.toString; | ||
var regExpToString = RegExp.prototype.toString; | ||
var symbolToString = Symbol.prototype.toString; | ||
var SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; | ||
var NEWLINE_REGEXP = /\n/ig; | ||
var SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; | ||
var NEWLINE_REGEXP = /\n/ig; | ||
var getSymbols = Object.getOwnPropertySymbols || function (obj) { | ||
return []; | ||
}; | ||
var getSymbols = Object.getOwnPropertySymbols || function (obj) { | ||
return []; | ||
}; | ||
function isToStringedArrayType(toStringed) { | ||
return toStringed === '[object Array]' || toStringed === '[object ArrayBuffer]' || toStringed === '[object DataView]' || toStringed === '[object Float32Array]' || toStringed === '[object Float64Array]' || toStringed === '[object Int8Array]' || toStringed === '[object Int16Array]' || toStringed === '[object Int32Array]' || toStringed === '[object Uint8Array]' || toStringed === '[object Uint8ClampedArray]' || toStringed === '[object Uint16Array]' || toStringed === '[object Uint32Array]'; | ||
} | ||
function isToStringedArrayType(toStringed) { | ||
return toStringed === '[object Array]' || toStringed === '[object ArrayBuffer]' || toStringed === '[object DataView]' || toStringed === '[object Float32Array]' || toStringed === '[object Float64Array]' || toStringed === '[object Int8Array]' || toStringed === '[object Int16Array]' || toStringed === '[object Int32Array]' || toStringed === '[object Uint8Array]' || toStringed === '[object Uint8ClampedArray]' || toStringed === '[object Uint16Array]' || toStringed === '[object Uint32Array]'; | ||
} | ||
function printNumber(val) { | ||
if (val != +val) return 'NaN'; | ||
var isNegativeZero = val === 0 && 1 / val < 0; | ||
return isNegativeZero ? '-0' : '' + val; | ||
} | ||
function printNumber(val) { | ||
if (val != +val) return 'NaN'; | ||
var isNegativeZero = val === 0 && 1 / val < 0; | ||
return isNegativeZero ? '-0' : '' + val; | ||
} | ||
function printFunction(val) { | ||
if (val.name === '') { | ||
return '[Function anonymous]'; | ||
} else { | ||
return '[Function ' + val.name + ']'; | ||
} | ||
function printFunction(val) { | ||
if (val.name === '') { | ||
return '[Function anonymous]'; | ||
} else { | ||
return '[Function ' + val.name + ']'; | ||
} | ||
} | ||
function printSymbol(val) { | ||
return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); | ||
} | ||
function printSymbol(val) { | ||
return symbolToString.call(val).replace(SYMBOL_REGEXP, 'Symbol($1)'); | ||
} | ||
function printError(val) { | ||
return '[' + errorToString.call(val) + ']'; | ||
} | ||
function printError(val) { | ||
return '[' + errorToString.call(val) + ']'; | ||
} | ||
function printBasicValue(val) { | ||
if (val === true || val === false) return '' + val; | ||
if (val === undefined) return 'undefined'; | ||
if (val === null) return 'null'; | ||
function printBasicValue(val) { | ||
if (val === true || val === false) return '' + val; | ||
if (val === undefined) return 'undefined'; | ||
if (val === null) return 'null'; | ||
var typeOf = typeof val; | ||
var typeOf = typeof val; | ||
if (typeOf === 'number') return printNumber(val); | ||
if (typeOf === 'string') return '"' + printString(val) + '"'; | ||
if (typeOf === 'function') return printFunction(val); | ||
if (typeOf === 'symbol') return printSymbol(val); | ||
if (typeOf === 'number') return printNumber(val); | ||
if (typeOf === 'string') return '"' + printString(val) + '"'; | ||
if (typeOf === 'function') return printFunction(val); | ||
if (typeOf === 'symbol') return printSymbol(val); | ||
var toStringed = toString.call(val); | ||
var toStringed = toString.call(val); | ||
if (toStringed === '[object WeakMap]') return 'WeakMap {}'; | ||
if (toStringed === '[object WeakSet]') return 'WeakSet {}'; | ||
if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val); | ||
if (toStringed === '[object Symbol]') return printSymbol(val); | ||
if (toStringed === '[object Date]') return toISOString.call(val); | ||
if (toStringed === '[object Error]') return printError(val); | ||
if (toStringed === '[object RegExp]') return regExpToString.call(val); | ||
if (toStringed === '[object Arguments]' && val.length === 0) return 'Arguments []'; | ||
if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + ' []'; | ||
if (toStringed === '[object WeakMap]') return 'WeakMap {}'; | ||
if (toStringed === '[object WeakSet]') return 'WeakSet {}'; | ||
if (toStringed === '[object Function]' || toStringed === '[object GeneratorFunction]') return printFunction(val, min); | ||
if (toStringed === '[object Symbol]') return printSymbol(val); | ||
if (toStringed === '[object Date]') return toISOString.call(val); | ||
if (toStringed === '[object Error]') return printError(val); | ||
if (toStringed === '[object RegExp]') return regExpToString.call(val); | ||
if (toStringed === '[object Arguments]' && val.length === 0) return 'Arguments []'; | ||
if (isToStringedArrayType(toStringed) && val.length === 0) return val.constructor.name + ' []'; | ||
if (val instanceof Error) return printError(val); | ||
if (val instanceof Error) return printError(val); | ||
return false; | ||
} | ||
return false; | ||
} | ||
function printList(list, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var body = ''; | ||
function printList(list, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var body = ''; | ||
if (list.length) { | ||
body += '\n'; | ||
if (list.length) { | ||
body += edgeSpacing; | ||
var innerIndent = prevIndent + indent; | ||
var innerIndent = prevIndent + indent; | ||
for (var i = 0; i < list.length; i++) { | ||
body += innerIndent + print(list[i], indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
for (var i = 0; i < list.length; i++) { | ||
body += innerIndent + print(list[i], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
if (i < list.length - 1) { | ||
body += ',\n'; | ||
} | ||
if (i < list.length - 1) { | ||
body += ',' + spacing; | ||
} | ||
body += '\n' + prevIndent; | ||
} | ||
return '[' + body + ']'; | ||
body += edgeSpacing + prevIndent; | ||
} | ||
function printArguments(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
return 'Arguments ' + printList(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} | ||
return '[' + body + ']'; | ||
} | ||
function printArray(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
return val.constructor.name + ' ' + printList(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} | ||
function printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
return (min ? '' : 'Arguments ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
function printMap(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var result = 'Map {'; | ||
var iterator = val.entries(); | ||
var current = iterator.next(); | ||
function printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
return (min ? '' : val.constructor.name + ' ') + printList(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
if (!current.done) { | ||
result += '\n'; | ||
function printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var result = 'Map {'; | ||
var iterator = val.entries(); | ||
var current = iterator.next(); | ||
var innerIndent = prevIndent + indent; | ||
if (!current.done) { | ||
result += edgeSpacing; | ||
while (!current.done) { | ||
var key = print(current.value[0], indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
var value = print(current.value[1], indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
var innerIndent = prevIndent + indent; | ||
result += innerIndent + key + ' => ' + value; | ||
while (!current.done) { | ||
var key = print(current.value[0], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
var value = print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
current = iterator.next(); | ||
result += innerIndent + key + ' => ' + value; | ||
if (!current.done) { | ||
result += ',\n'; | ||
} | ||
current = iterator.next(); | ||
if (!current.done) { | ||
result += ',' + spacing; | ||
} | ||
result += '\n' + prevIndent; | ||
} | ||
return result + '}'; | ||
result += edgeSpacing + prevIndent; | ||
} | ||
function printObject(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var constructor = val.constructor ? val.constructor.name + ' ' : 'Object '; | ||
var result = constructor + '{'; | ||
var keys = Object.keys(val).sort(); | ||
var symbols = getSymbols(val); | ||
return result + '}'; | ||
} | ||
if (symbols.length) { | ||
keys = keys.filter(function (key) { | ||
return !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]'); | ||
}).concat(symbols); | ||
} | ||
function printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var constructor = min ? '' : val.constructor ? val.constructor.name + ' ' : 'Object '; | ||
var result = constructor + '{'; | ||
var keys = Object.keys(val).sort(); | ||
var symbols = getSymbols(val); | ||
if (keys.length) { | ||
result += '\n'; | ||
if (symbols.length) { | ||
keys = keys.filter(function (key) { | ||
return !(typeof key === 'symbol' || toString.call(key) === '[object Symbol]'); | ||
}).concat(symbols); | ||
} | ||
var innerIndent = prevIndent + indent; | ||
if (keys.length) { | ||
result += edgeSpacing; | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var name = print(key, indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
var value = print(val[key], indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
var innerIndent = prevIndent + indent; | ||
result += innerIndent + name + ': ' + value; | ||
for (var i = 0; i < keys.length; i++) { | ||
var key = keys[i]; | ||
var name = print(key, indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
var value = print(val[key], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
if (i < keys.length - 1) { | ||
result += ',\n'; | ||
} | ||
result += innerIndent + name + ': ' + value; | ||
if (i < keys.length - 1) { | ||
result += ',' + spacing; | ||
} | ||
result += '\n' + prevIndent; | ||
} | ||
return result + '}'; | ||
result += edgeSpacing + prevIndent; | ||
} | ||
function printSet(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var result = 'Set {'; | ||
var iterator = val.entries(); | ||
var current = iterator.next(); | ||
return result + '}'; | ||
} | ||
if (!current.done) { | ||
result += '\n'; | ||
function printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var result = 'Set {'; | ||
var iterator = val.entries(); | ||
var current = iterator.next(); | ||
var innerIndent = prevIndent + indent; | ||
if (!current.done) { | ||
result += edgeSpacing; | ||
while (!current.done) { | ||
result += innerIndent + print(current.value[1], indent, innerIndent, refs, maxDepth, currentDepth, plugins); | ||
var innerIndent = prevIndent + indent; | ||
current = iterator.next(); | ||
while (!current.done) { | ||
result += innerIndent + print(current.value[1], indent, innerIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
if (!current.done) { | ||
result += ',\n'; | ||
} | ||
current = iterator.next(); | ||
if (!current.done) { | ||
result += ',' + spacing; | ||
} | ||
result += '\n' + prevIndent; | ||
} | ||
return result + '}'; | ||
result += edgeSpacing + prevIndent; | ||
} | ||
function printComplexValue(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var toStringed = toString.call(val); | ||
return result + '}'; | ||
} | ||
refs = refs.slice(); | ||
function printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
refs = refs.slice(); | ||
if (refs.indexOf(val) > -1) { | ||
return '[Circular]'; | ||
} else { | ||
refs.push(val); | ||
} | ||
if (refs.indexOf(val) > -1) { | ||
return '[Circular]'; | ||
} else { | ||
refs.push(val); | ||
} | ||
currentDepth++; | ||
currentDepth++; | ||
var hitMaxDepth = currentDepth > maxDepth; | ||
var hitMaxDepth = currentDepth > maxDepth; | ||
if (!hitMaxDepth && val.toJSON && typeof val.toJSON === 'function') { | ||
return print(val.toJSON(), indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
if (toStringed === '[object Arguments]') { | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} else if (isToStringedArrayType(toStringed)) { | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} else if (toStringed === '[object Map]') { | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} else if (toStringed === '[object Set]') { | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} else if (typeof val === 'object') { | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} | ||
var toStringed = toString.call(val); | ||
if (toStringed === '[object Arguments]') { | ||
return hitMaxDepth ? '[Arguments]' : printArguments(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} else if (isToStringedArrayType(toStringed)) { | ||
return hitMaxDepth ? '[Array]' : printArray(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} else if (toStringed === '[object Map]') { | ||
return hitMaxDepth ? '[Map]' : printMap(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} else if (toStringed === '[object Set]') { | ||
return hitMaxDepth ? '[Set]' : printSet(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} else if (typeof val === 'object') { | ||
return hitMaxDepth ? '[Object]' : printObject(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
} | ||
function printPlugin(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var match = false; | ||
var plugin = void 0; | ||
function printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var match = false; | ||
var plugin = void 0; | ||
for (var p = 0; p < plugins.length; p++) { | ||
plugin = plugins[p]; | ||
for (var p = 0; p < plugins.length; p++) { | ||
plugin = plugins[p]; | ||
if (plugin.test(val)) { | ||
match = true; | ||
break; | ||
} | ||
if (plugin.test(val)) { | ||
match = true; | ||
break; | ||
} | ||
} | ||
if (!match) { | ||
return false; | ||
} | ||
if (!match) { | ||
return false; | ||
} | ||
function boundPrint(val) { | ||
return print(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} | ||
function boundPrint(val) { | ||
return print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
function boundIndent(str) { | ||
var indentation = prevIndent + indent; | ||
return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation); | ||
} | ||
return plugin.print(val, boundPrint, boundIndent); | ||
function boundIndent(str) { | ||
var indentation = prevIndent + indent; | ||
return indentation + str.replace(NEWLINE_REGEXP, '\n' + indentation); | ||
} | ||
function print(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins) { | ||
var basic = printBasicValue(val); | ||
if (basic) return basic; | ||
return plugin.print(val, boundPrint, boundIndent, { | ||
edgeSpacing: edgeSpacing, | ||
spacing: spacing | ||
}); | ||
} | ||
var plugin = printPlugin(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
if (plugin) return plugin; | ||
function print(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min) { | ||
var basic = printBasicValue(val); | ||
if (basic) return basic; | ||
return printComplexValue(val, indent, prevIndent, refs, maxDepth, currentDepth, plugins); | ||
} | ||
var plugin = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
if (plugin) return plugin; | ||
var DEFAULTS = { | ||
indent: 2, | ||
maxDepth: Infinity, | ||
plugins: [] | ||
}; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, maxDepth, currentDepth, plugins, min); | ||
} | ||
function validateOptions(opts) { | ||
Object.keys(opts).forEach(function (key) { | ||
if (!DEFAULTS.hasOwnProperty(key)) { | ||
throw new Error('prettyFormat: Invalid option: ' + key); | ||
} | ||
}); | ||
var DEFAULTS = { | ||
indent: 2, | ||
min: false, | ||
maxDepth: Infinity, | ||
plugins: [] | ||
}; | ||
function validateOptions(opts) { | ||
Object.keys(opts).forEach(function (key) { | ||
if (!DEFAULTS.hasOwnProperty(key)) { | ||
throw new Error('prettyFormat: Invalid option: ' + key); | ||
} | ||
}); | ||
if (opts.min && opts.indent !== undefined && opts.indent !== 0) { | ||
throw new Error('prettyFormat: Cannot run with min option and indent'); | ||
} | ||
} | ||
function normalizeOptions(opts) { | ||
var result = {}; | ||
function normalizeOptions(opts) { | ||
var result = {}; | ||
Object.keys(DEFAULTS).forEach(function (key) { | ||
return result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key]; | ||
}); | ||
Object.keys(DEFAULTS).forEach(function (key) { | ||
return result[key] = opts.hasOwnProperty(key) ? opts[key] : DEFAULTS[key]; | ||
}); | ||
return result; | ||
if (result.min) { | ||
result.indent = 0; | ||
} | ||
function createIndent(indent) { | ||
return new Array(indent + 1).join(' '); | ||
return result; | ||
} | ||
function createIndent(indent) { | ||
return new Array(indent + 1).join(' '); | ||
} | ||
function prettyFormat(val, opts) { | ||
if (!opts) { | ||
opts = DEFAULTS; | ||
} else { | ||
validateOptions(opts); | ||
opts = normalizeOptions(opts); | ||
} | ||
function prettyFormat(val, opts) { | ||
if (!opts) { | ||
opts = DEFAULTS; | ||
} else { | ||
validateOptions(opts); | ||
opts = normalizeOptions(opts); | ||
} | ||
var indent = void 0; | ||
var refs = void 0; | ||
var prevIndent = ''; | ||
var currentDepth = 0; | ||
var spacing = opts.min ? ' ' : '\n'; | ||
var edgeSpacing = opts.min ? '' : '\n'; | ||
var indent = void 0; | ||
var refs = void 0; | ||
var prevIndent = ''; | ||
var currentDepth = 0; | ||
if (opts && opts.plugins.length) { | ||
indent = createIndent(opts.indent); | ||
refs = []; | ||
var pluginsResult = printPlugin(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min); | ||
if (pluginsResult) return pluginsResult; | ||
} | ||
if (opts && opts.plugins.length) { | ||
indent = createIndent(opts.indent); | ||
refs = []; | ||
var pluginsResult = printPlugin(val, indent, prevIndent, refs, opts.maxDepth, currentDepth, opts.plugins); | ||
if (pluginsResult) return pluginsResult; | ||
} | ||
var basicResult = printBasicValue(val); | ||
if (basicResult) return basicResult; | ||
var basicResult = printBasicValue(val); | ||
if (basicResult) return basicResult; | ||
if (!indent) indent = createIndent(opts.indent); | ||
if (!refs) refs = []; | ||
return printComplexValue(val, indent, prevIndent, spacing, edgeSpacing, refs, opts.maxDepth, currentDepth, opts.plugins, opts.min); | ||
} | ||
if (!indent) indent = createIndent(opts.indent); | ||
if (!refs) refs = []; | ||
return printComplexValue(val, indent, prevIndent, refs, opts.maxDepth, currentDepth, opts.plugins); | ||
} | ||
module.exports = prettyFormat; | ||
}); | ||
module.exports = prettyFormat; | ||
}); | ||
var prettyFormat = interopDefault(index); | ||
var prettyFormat = interopDefault(index); | ||
var preactPlugin = { | ||
test: function (object) { | ||
return object && typeof object === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object); | ||
}, | ||
print: function (val, print, indent) { | ||
return renderToString(val, preactPlugin.context, preactPlugin.opts, true); | ||
} | ||
}; | ||
var preactPlugin = { | ||
test: function (object) { | ||
return object && typeof object === 'object' && 'nodeName' in object && 'attributes' in object && 'children' in object && !('nodeType' in object); | ||
}, | ||
print: function (val, print, indent) { | ||
return renderToString(val, preactPlugin.context, preactPlugin.opts, true); | ||
} | ||
}; | ||
var prettyFormatOpts = { | ||
plugins: [preactPlugin] | ||
}; | ||
var prettyFormatOpts = { | ||
plugins: [preactPlugin] | ||
}; | ||
function attributeHook(name, value, context, opts, isComponent) { | ||
var type = typeof value; | ||
function attributeHook(name, value, context, opts, isComponent) { | ||
var type = typeof value; | ||
if (value == null || type === 'function' && !opts.functions) return ''; | ||
if (value == null || type === 'function' && !opts.functions) return ''; | ||
if (opts.skipFalseAttributes && !isComponent && (value === false || (name === 'class' || name === 'style') && value === '')) return ''; | ||
if (opts.skipFalseAttributes && !isComponent && (value === false || (name === 'class' || name === 'style') && value === '')) return ''; | ||
var indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t'; | ||
if (type !== 'string') { | ||
if (type === 'function' && !opts.functionNames) { | ||
value = 'Function'; | ||
} else { | ||
preactPlugin.context = context; | ||
preactPlugin.opts = opts; | ||
value = prettyFormat(value, prettyFormatOpts); | ||
if (~value.indexOf('\n')) { | ||
value = indent('\n' + value, indentChar) + '\n'; | ||
} | ||
} | ||
return indent('\n' + name + '={' + value + '}', indentChar); | ||
} | ||
return '\n' + indentChar + name + '="' + encodeEntities(value) + '"'; | ||
} | ||
var indentChar = typeof opts.pretty === 'string' ? opts.pretty : '\t'; | ||
if (type !== 'string') { | ||
if (type === 'function' && !opts.functionNames) { | ||
value = 'Function'; | ||
} else { | ||
preactPlugin.context = context; | ||
preactPlugin.opts = opts; | ||
value = prettyFormat(value, prettyFormatOpts); | ||
if (~value.indexOf('\n')) { | ||
value = indent('\n' + value, indentChar) + '\n'; | ||
} | ||
} | ||
return indent('\n' + name + '={' + value + '}', indentChar); | ||
} | ||
return '\n' + indentChar + name + '="' + encodeEntities(value) + '"'; | ||
} | ||
var defaultOpts = { | ||
attributeHook: attributeHook, | ||
jsx: true, | ||
xml: false, | ||
functions: true, | ||
functionNames: true, | ||
skipFalseAttributes: true, | ||
pretty: ' ' | ||
}; | ||
var defaultOpts = { | ||
attributeHook: attributeHook, | ||
jsx: true, | ||
xml: false, | ||
functions: true, | ||
functionNames: true, | ||
skipFalseAttributes: true, | ||
pretty: ' ' | ||
}; | ||
function renderToJsxString(vnode, context, opts, inner) { | ||
opts = assign(assign({}, defaultOpts), opts || {}); | ||
return renderToString(vnode, context, opts, inner); | ||
} | ||
function renderToJsxString(vnode, context, opts, inner) { | ||
opts = assign(assign({}, defaultOpts), opts || {}); | ||
return renderToString(vnode, context, opts, inner); | ||
} | ||
return renderToJsxString; | ||
return renderToJsxString; | ||
})); | ||
}))); | ||
//# sourceMappingURL=jsx.js.map |
{ | ||
"name": "preact-render-to-string", | ||
"amdName": "preactRenderToString", | ||
"version": "3.3.0", | ||
"version": "3.4.0", | ||
"description": "Render JSX to an HTML string, with support for Preact components.", | ||
@@ -43,3 +43,3 @@ "main": "dist/index.js", | ||
"babel-preset-es2015-minimal": "^2.0.0", | ||
"babel-preset-es2015-minimal-rollup": "^2.0.0", | ||
"babel-preset-es2015-minimal-rollup": "^2.1.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
@@ -50,3 +50,3 @@ "babel-register": "^6.9.0", | ||
"mocha": "^3.0.0", | ||
"preact": "^6.1.0", | ||
"preact": "^7.1.0", | ||
"rollup": "^0.34.3", | ||
@@ -53,0 +53,0 @@ "rollup-plugin-babel": "^2.6.1", |
@@ -137,4 +137,4 @@ import { objectKeys, encodeEntities, falsey, memoize, indent, isLargeString, styleObjToCss, hashToClassName, assign, getNodeProps } from './util'; | ||
} | ||
else if ((v || v===0) && typeof v!=='function') { | ||
if (v===true) { | ||
else if ((v || v===0 || v==='') && typeof v!=='object' && typeof v!=='function') { | ||
if (v===true || v==='') { | ||
v = name; | ||
@@ -141,0 +141,0 @@ // in non-xml mode, allow boolean attributes |
@@ -28,3 +28,3 @@ import { render, shallowRender } from '../src'; | ||
let rendered = render(<div class="" style="" foo={true} bar />), | ||
expected = `<div foo bar></div>`; | ||
expected = `<div class style foo bar></div>`; | ||
@@ -258,3 +258,3 @@ expect(rendered).to.equal(expected); | ||
expect(Outer.prototype.getChildContext).to.have.been.calledOnce; | ||
expect(Inner.prototype.render).to.have.been.calledWith({}, {}, CONTEXT); | ||
expect(Inner.prototype.render).to.have.been.calledWith(match({}), {}, CONTEXT); | ||
@@ -265,3 +265,3 @@ CONTEXT.foo = 'bar'; | ||
expect(Outer.prototype.getChildContext).to.have.been.calledTwice; | ||
expect(Inner.prototype.render).to.have.been.calledWith(PROPS, {}, CONTEXT); | ||
expect(Inner.prototype.render).to.have.been.calledWith(match(PROPS), {}, CONTEXT); | ||
}); | ||
@@ -293,3 +293,3 @@ | ||
expect(Outer.prototype.getChildContext).to.have.been.calledOnce; | ||
expect(Inner.prototype.render).to.have.been.calledWith({}, {}, CONTEXT); | ||
expect(Inner.prototype.render).to.have.been.calledWith(match({}), {}, CONTEXT); | ||
@@ -300,3 +300,3 @@ CONTEXT.foo = 'bar'; | ||
expect(Outer.prototype.getChildContext).to.have.been.calledTwice; | ||
expect(Inner.prototype.render).to.have.been.calledWith(PROPS, {}, CONTEXT); | ||
expect(Inner.prototype.render).to.have.been.calledWith(match(PROPS), {}, CONTEXT); | ||
@@ -339,4 +339,4 @@ // make sure render() could make use of context.a | ||
expect(Inner.prototype.render).to.have.been.calledWith({}, {}, { outerContext }); | ||
expect(InnerMost.prototype.render).to.have.been.calledWith({}, {}, { outerContext, innerContext }); | ||
expect(Inner.prototype.render).to.have.been.calledWith(match({}), {}, { outerContext }); | ||
expect(InnerMost.prototype.render).to.have.been.calledWith(match({}), {}, { outerContext, innerContext }); | ||
}); | ||
@@ -343,0 +343,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
126304
1751