{"version":3,"sources":["dist/hyperapp.js"],"names":["global","factory","exports","module","define","amd","hyperapp","this","h","name","props","node","stack","children","i","arguments","length","push","Array","isArray","pop","app","state","actions","view","container","vnode","element","map","nodeName","toLowerCase","call","childNodes","nodeType","nodeValue","render","next","lock","root","patch","repaint","setTimeout","copy","a","b","target","set","path","value","source","slice","get","init","key","action","data","then","concat","getKey","setElementProp","oldValue","attributeIsEmpty","_","setAttribute","removeAttribute","createElement","isSVG","document","createTextNode","createElementNS","oncreate","appendChild","removeChildren","ondestroy","removeElement","parent","cb","done","removeChild","onremove","oldNode","nextSibling","insertBefore","oldProps","onupdate","updateElement","oldElements","oldKeyed","newKeyed","oldKey","oldChild","j","newChild","newKey","recyledNode"],"mappings":"CAAC,SAAUA,EAAQC,GACC,iBAAZC,SAA0C,oBAAXC,OAAyBF,EAAQC,SACrD,mBAAXE,QAAyBA,OAAOC,KACtCJ,EAASD,EAAOM,aAHlB,CAIEC,KAAM,SAAWL,GAAW,aA0T9BA,EAAQM,EAxTR,SAAWC,EAAMC,GAKf,IAAK,IAJDC,EACAC,KACAC,KAEKC,EAAIC,UAAUC,OAAQF,KAAM,GACnCF,EAAMK,KAAKF,UAAUD,IAGvB,KAAOF,EAAMI,QACX,GAAIE,MAAMC,QAASR,EAAOC,EAAMQ,OAC9B,IAAKN,EAAIH,EAAKK,OAAQF,KACpBF,EAAMK,KAAKN,EAAKG,SAET,MAAQH,IAAQ,IAASA,IAAQ,IAAUA,GAEpDE,EAASI,KAAqB,iBAATN,EAAoBA,EAAO,GAAKA,GAIzD,MAAuB,iBAATF,GAERA,KAAMA,EACNC,MAAOA,MACPG,SAAUA,GAEZJ,EAAKC,MAAaG,IA+RxBX,EAAQmB,IA5RR,SAAaC,EAAOC,EAASC,EAAMC,GAUjC,SAASC,EAAMC,EAASC,GACtB,OACED,IACElB,KAAMkB,EAAQE,SAASC,cACvBpB,SACAG,SAAUe,EAAIG,KAAKJ,EAAQK,WAAY,SAASL,GAC9C,OAAO,IA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AASC,GACX3E,SAIF,GAAI,MAAQ+E,EACN,MAAQJ,IACVlD,EAAMZ,EAAS2D,EAAYxE,GAAI4E,EAAUE,EAAU1B,GACnDyB,KAEF7E,QACK,CACL,IAAIgF,EAAcP,EAASM,OAEvBJ,IAAWI,GACbtD,EAAMZ,EAASmE,EAAY,GAAIA,EAAY,GAAIF,EAAU1B,GACzDpD,KACSgF,EAAY,GACrBvD,EACEZ,EACAA,EAAQuD,aAAaY,EAAY,GAAIR,EAAYxE,IACjDgF,EAAY,GACZF,EACA1B,GAGF3B,EAAMZ,EAAS2D,EAAYxE,GAAI,KAAM8E,EAAU1B,GAGjDyB,IACAH,EAASK,GAAUD,GAIvB,KAAO9E,EAAIkE,EAAQnE,SAASG,QAEtB,MAAQ0C,EADRgC,EAAWV,EAAQnE,SAASC,KAE9B4D,EAAc/C,EAAS2D,EAAYxE,GAAI4E,GAEzC5E,IAGF,IAAK,IAAIA,KAAKyE,EACPC,EAASD,EAASzE,GAAG,GAAGJ,MAAM2C,MACjCqB,EAAc/C,EAAS4D,EAASzE,GAAG,GAAIyE,EAASzE,GAAG,SAG9CH,EAAKF,OAASuE,EAAQvE,KAC/BkB,EAAQO,UAAYvB,GAEpBgB,EAAUgD,EAAOO,aACfjB,EAActD,EAAMuD,GACnBe,EAActD,GAEjB+C,EAAcC,EAAQM,EAAaD,IAErC,OAAOrD,EAtRT,IAAIU,EACAC,EAAOb,GAAaA,EAAUZ,SAAS,GACvCF,EAAOe,EAAMY,KAASV,KACtBhB,KAIJ,OAFA4B,EAAQY,KAAU9B,EAAQoB,EAAKpB,GAAUC,EAAUmB,EAAKnB,KAEjDA","sourcesContent":["(function (global, factory) {\n\ttypeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :\n\ttypeof define === 'function' && define.amd ? define(['exports'], factory) :\n\t(factory((global.hyperapp = {})));\n}(this, (function (exports) { 'use strict';\n\nfunction h(name, props) {\n var node;\n var stack = [];\n var children = [];\n\n for (var i = arguments.length; i-- > 2; ) {\n stack.push(arguments[i]);\n }\n\n while (stack.length) {\n if (Array.isArray((node = stack.pop()))) {\n for (i = node.length; i--; ) {\n stack.push(node[i]);\n }\n } else if (null == node || true === node || false === node) {\n } else {\n children.push(typeof node === \"number\" ? node + \"\" : node);\n }\n }\n\n return typeof name === \"string\"\n ? {\n name: name,\n props: props || {},\n children: children\n }\n : name(props || {}, children)\n}\n\nfunction app(state, actions, view, container) {\n var lock;\n var root = container && container.children[0];\n var node = vnode(root, [].map);\n var stack = [];\n\n repaint(init([], (state = copy(state)), (actions = copy(actions))));\n\n return actions\n\n function vnode(element, map) {\n return (\n element && {\n name: element.nodeName.toLowerCase(),\n props: {},\n children: map.call(element.childNodes, function(element) {\n return 3 === element.nodeType\n ? element.nodeValue\n : vnode(element, map)\n })\n }\n )\n }\n\n function render(next) {\n lock = !lock;\n next = view(state, actions);\n\n if (container && !lock) {\n root = patch(container, root, node, (node = next));\n }\n\n while ((next = stack.pop())) next();\n }\n\n function repaint() {\n if (!lock) {\n lock = !lock;\n setTimeout(render);\n }\n }\n\n function copy(a, b) {\n var target = {};\n\n for (var i in a) target[i] = a[i];\n for (var i in b) target[i] = b[i];\n\n return target\n }\n\n function set(path, value, source, target) {\n if (path.length) {\n target[path[0]] =\n 1 < path.length ? set(path.slice(1), value, source[path[0]], {}) : value;\n return copy(source, target)\n }\n return value\n }\n\n function get(path, source) {\n for (var i = 0; i < path.length; i++) {\n source = source[path[i]];\n }\n return source\n }\n\n function init(path, slice, actions) {\n for (var key in actions) {\n typeof actions[key] === \"function\"\n ? (function(key, action) {\n actions[key] = function(data) {\n slice = get(path, state);\n\n if (typeof (data = action(data)) === \"function\") {\n data = data(slice, actions);\n }\n\n if (data && data !== slice && !data.then) {\n repaint((state = set(path, copy(slice, data), state, {})));\n }\n\n return data\n };\n })(key, actions[key])\n : init(\n path.concat(key),\n (slice[key] = slice[key] || {}),\n (actions[key] = copy(actions[key]))\n );\n }\n }\n\n function getKey(node) {\n return node && node.props ? node.props.key : null\n }\n\n function setElementProp(element, name, value, oldValue) {\n if (name === \"key\") {\n } else if (name === \"style\") {\n for (var i in copy(oldValue, value)) {\n element[name][i] = null == value || null == value[i] ? \"\" : value[i];\n }\n } else {\n var attributeIsEmpty = null == value || false === value;\n\n if (name in element) {\n try {\n element[name] = null == value ? \"\" : value;\n } catch (_) {}\n } else if (!attributeIsEmpty && typeof value !== \"function\") {\n element.setAttribute(name, true === value ? \"\" : value);\n }\n\n if (attributeIsEmpty) {\n element.removeAttribute(name);\n }\n }\n }\n\n function createElement(node, isSVG) {\n if (typeof node === \"string\") {\n var element = document.createTextNode(node);\n } else {\n var element = (isSVG = isSVG || \"svg\" === node.name)\n ? document.createElementNS(\"http://www.w3.org/2000/svg\", node.name)\n : document.createElement(node.name);\n\n if (node.props.oncreate) {\n stack.push(function() {\n node.props.oncreate(element);\n });\n }\n\n for (var i = 0; i < node.children.length; i++) {\n element.appendChild(createElement(node.children[i], isSVG));\n }\n\n for (var name in node.props) {\n setElementProp(element, name, node.props[name]);\n }\n }\n return element\n }\n\n function updateElement(element, oldProps, props, oldValue) {\n for (var name in copy(oldProps, props)) {\n if (\n (oldValue =\n \"value\" === name || \"checked\" === name\n ? element[name]\n : oldProps[name]) !== props[name]\n ) {\n setElementProp(element, name, props[name], oldValue);\n }\n }\n\n if (props.onupdate) {\n stack.push(function() {\n props.onupdate(element, oldProps);\n });\n }\n }\n\n function removeChildren(element, node, props) {\n if ((props = node.props)) {\n for (var i = 0; i < node.children.length; i++) {\n removeChildren(element.childNodes[i], node.children[i]);\n }\n\n if (props.ondestroy) {\n props.ondestroy(element);\n }\n }\n return element\n }\n\n function removeElement(parent, element, node, cb) {\n function done() {\n parent.removeChild(removeChildren(element, node));\n }\n\n if (node.props && (cb = node.props.onremove)) {\n cb(element, done);\n } else {\n done();\n }\n }\n\n function patch(parent, element, oldNode, node, isSVG, nextSibling) {\n if (node === oldNode) {\n } else if (null == oldNode) {\n element = parent.insertBefore(createElement(node, isSVG), element);\n } else if (node.name && node.name === oldNode.name) {\n isSVG = isSVG || \"svg\" === node.name;\n\n updateElement(element, oldNode.props, node.props);\n\n var oldElements = [];\n var oldKeyed = {};\n var newKeyed = {};\n\n for (var i = 0; i < oldNode.children.length; i++) {\n oldElements[i] = element.childNodes[i];\n\n var oldChild = oldNode.children[i];\n var oldKey = getKey(oldChild);\n\n if (null != oldKey) {\n oldKeyed[oldKey] = [oldElements[i], oldChild];\n }\n }\n\n var i = 0;\n var j = 0;\n\n while (j < node.children.length) {\n var oldChild = oldNode.children[i];\n var newChild = node.children[j];\n\n var oldKey = getKey(oldChild);\n var newKey = getKey(newChild);\n\n if (newKeyed[oldKey]) {\n i++;\n continue\n }\n\n if (null == newKey) {\n if (null == oldKey) {\n patch(element, oldElements[i], oldChild, newChild, isSVG);\n j++;\n }\n i++;\n } else {\n var recyledNode = oldKeyed[newKey] || [];\n\n if (oldKey === newKey) {\n patch(element, recyledNode[0], recyledNode[1], newChild, isSVG);\n i++;\n } else if (recyledNode[0]) {\n patch(\n element,\n element.insertBefore(recyledNode[0], oldElements[i]),\n recyledNode[1],\n newChild,\n isSVG\n );\n } else {\n patch(element, oldElements[i], null, newChild, isSVG);\n }\n\n j++;\n newKeyed[newKey] = newChild;\n }\n }\n\n while (i < oldNode.children.length) {\n var oldChild = oldNode.children[i];\n if (null == getKey(oldChild)) {\n removeElement(element, oldElements[i], oldChild);\n }\n i++;\n }\n\n for (var i in oldKeyed) {\n if (!newKeyed[oldKeyed[i][1].props.key]) {\n removeElement(element, oldKeyed[i][0], oldKeyed[i][1]);\n }\n }\n } else if (node.name === oldNode.name) {\n element.nodeValue = node;\n } else {\n element = parent.insertBefore(\n createElement(node, isSVG),\n (nextSibling = element)\n );\n removeElement(parent, nextSibling, oldNode);\n }\n return element\n }\n}\n\nexports.h = h;\nexports.app = app;\n\nObject.defineProperty(exports, '__esModule', { value: true });\n\n})));\n//# sourceMappingURL=hyperapp.js.map\n"]}