{"version":3,"file":"preact-compat.js","sources":["../src/index.js"],"sourcesContent":["import PropTypes from 'proptypes';\nimport SVG from 'preact-svg';\nimport { render as preactRender, h, Component as PreactComponent, hooks } from 'preact';\n\n\nconst ELEMENTS = 'a abbr address area article aside audio b base bdi bdo big blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param picture pre progress q rp rt ruby s samp script section select small source span strong style sub summary sup table tbody td textarea tfoot th thead time title tr track u ul var video wbr circle clipPath defs ellipse g image line linearGradient mask path pattern polygon polyline radialGradient rect stop svg text tspan'.split(' ');\n\nconst REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && Symbol.for && Symbol.for('react.element')) || 0xeac7;\n\n// make react think we're react.\nlet VNode = h('').constructor;\nVNode.prototype.$$typeof = REACT_ELEMENT_TYPE;\n\nObject.defineProperty(VNode.prototype, 'type', {\n\tget() { return this.nodeName; },\n\tset(v) { this.nodeName = v; }\n});\n\nObject.defineProperty(VNode.prototype, 'props', {\n\tget() { return this.attributes; },\n\tset(v) { this.attributes = v; }\n});\n\n\n// don't autobind these methods since they already have guaranteed context.\nconst AUTOBIND_BLACKLIST = {\n\tconstructor: 1,\n\trender: 1,\n\tshouldComponentUpdate: 1,\n\tcomponentWillRecieveProps: 1,\n\tcomponentWillUpdate: 1,\n\tcomponentDidUpdate: 1,\n\tcomponentWillMount: 1,\n\tcomponentDidMount: 1,\n\tcomponentWillUnmount: 1,\n\tcomponentDidUnmount: 1\n};\n\n\nconst BYPASS_HOOK = {};\n\n\nconst DEV = !isProd();\n\nfunction isProd() {\n\tlet prod;\n\t/*global process*/\n\ttry { prod = process.env.NODE_ENV==='production'; } catch (e) {}\n\treturn !!prod;\n}\n\n\nconst EmptyComponent = () => null;\n\n\n// proxy render() since React returns a Component reference.\nfunction render(vnode, parent, callback) {\n\tlet prev = parent._preactCompatRendered;\n\tif (prev && prev.parentNode!==parent) prev = null;\n\tlet out = preactRender(vnode, parent, prev);\n\tparent._preactCompatRendered = out;\n\tif (typeof callback==='function') callback();\n\treturn out && out._component;\n}\n\n\nfunction unmountComponentAtNode(container) {\n\tlet existing = container._preactCompatRendered;\n\tif (existing && existing.parentNode===container) {\n\t\tpreactRender(h(EmptyComponent), container, existing);\n\t\treturn true;\n\t}\n\treturn false;\n}\n\n\n\nconst ARR = [];\n\n// This API is completely unnecessary for Preact, so it's basically passthrough.\nlet Children = {\n\tmap(children, fn, ctx) {\n\t\tchildren = Children.toArray(children);\n\t\tif (ctx && ctx!==children) fn = fn.bind(ctx);\n\t\treturn children.map(fn);\n\t},\n\tforEach(children, fn, ctx) {\n\t\tchildren = Children.toArray(children);\n\t\tif (ctx && ctx!==children) fn = fn.bind(ctx);\n\t\tchildren.forEach(fn);\n\t},\n\tcount(children) {\n\t\tchildren = Children.toArray(children);\n\t\treturn children.length;\n\t},\n\tonly(children) {\n\t\tchildren = Children.toArray(children);\n\t\tif (children.length!==1) throw new Error('Children.only() expects only one child.');\n\t\treturn children[0];\n\t},\n\ttoArray(children) {\n\t\treturn Array.isArray && Array.isArray(children) ? children : ARR.concat(children);\n\t}\n};\n\n\n/** Track current render() component for ref assignment */\nlet currentComponent;\n\n\nfunction createFactory(type) {\n\treturn (...args) => createElement(type, ...args);\n}\n\n\nlet DOM = {};\nfor (let i=ELEMENTS.length; i--; ) {\n\tDOM[ELEMENTS[i]] = createFactory(ELEMENTS[i]);\n}\n\n\nfunction createElement(...args) {\n\tlet vnode = h(...args);\n\n\tif (vnode.nodeName==='svg') {\n\t\tvnode.nodeName = SVG;\n\t}\n\n\tapplyClassName(vnode);\n\n\tlet ref = vnode.attributes && vnode.attributes.ref;\n\tif (currentComponent && ref && typeof ref==='string') {\n\t\tvnode.attributes.ref = createStringRefProxy(ref, currentComponent);\n\t}\n\n\treturn vnode;\n}\n\n\nfunction cloneElement(element, props, ...children) {\n\treturn createElement(\n\t\telement.nodeName || element.type,\n\t\textend({}, element.attributes || element.props || {}, props),\n\t\t...children\n\t);\n}\n\n\nfunction isValidElement(element) {\n\treturn (element instanceof VNode) || element.$$typeof===REACT_ELEMENT_TYPE;\n}\n\n\nfunction createStringRefProxy(name, component) {\n\treturn component._refProxies[name] || (component._refProxies[name] = resolved => {\n\t\tif (component && component.refs) {\n\t\t\tcomponent.refs[name] = resolved;\n\t\t\tif (resolved===null) {\n\t\t\t\tdelete component._refProxies[name];\n\t\t\t\tcomponent = null;\n\t\t\t}\n\t\t}\n\t});\n}\n\n\nfunction applyClassName({ attributes }) {\n\tif (!attributes) return;\n\tlet cl = attributes.className || attributes.class;\n\tif (cl) attributes.className = cl;\n}\n\n\nfunction extend(base, ...objs) {\n\tfor (let i=0; i component.base || component;\n\n\nfunction F(){}\n\nfunction createClass(obj) {\n\tlet cl = function(props, context) {\n\t\tComponent.call(this, props, context, BYPASS_HOOK);\n\t\textend(this, obj);\n\t\tbindAll(this);\n\t\tnewComponentHook.call(this, props, context);\n\t};\n\n\tif (obj.propTypes) {\n\t\tcl.propTypes = obj.propTypes;\n\t}\n\tif (obj.defaultProps) {\n\t\tcl.defaultProps = obj.defaultProps;\n\t}\n\tif (obj.getDefaultProps) {\n\t\tcl.defaultProps = obj.getDefaultProps();\n\t}\n\n\tF.prototype = Component.prototype;\n\tcl.prototype = new F();\n\tcl.prototype.constructor = cl;\n\n\tcl.displayName = obj.displayName || 'Component';\n\n\treturn cl;\n}\n\n\nfunction bindAll(ctx) {\n\t/*eslint guard-for-in:0*/\n\tfor (let i in ctx) {\n\t\tlet v = ctx[i];\n\t\tif (typeof v==='function' && !v.__bound && !AUTOBIND_BLACKLIST.hasOwnProperty(i)) {\n\t\t\t(ctx[i] = v.bind(ctx)).__bound = true;\n\t\t}\n\t}\n}\n\n\nfunction callMethod(ctx, m, args) {\n\tif (typeof m==='string') {\n\t\tm = ctx.constructor.prototype[m];\n\t}\n\tif (typeof m==='function') {\n\t\treturn m.apply(ctx, args);\n\t}\n}\n\nfunction multihook(...hooks) {\n\treturn function(...args) {\n\t\tlet ret;\n\t\tfor (let i=0; i