Bundled output for commit 9f09ac069c [skip ci]
This commit is contained in:
parent
9f09ac069c
commit
b88e86f6f0
3 changed files with 266 additions and 127 deletions
|
|
@ -18,7 +18,7 @@ mithril.js [](https://ww
|
|||
|
||||
## What is Mithril?
|
||||
|
||||
A modern client-side Javascript framework for building Single Page Applications. It's small (<!-- size -->8.48 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box.
|
||||
A modern client-side Javascript framework for building Single Page Applications. It's small (<!-- size -->8.59 KB<!-- /size --> gzipped), fast and provides routing and XHR utilities out of the box.
|
||||
|
||||
Mithril is used by companies like Vimeo and Nike, and open source platforms like Lichess 👍.
|
||||
|
||||
|
|
|
|||
299
mithril.js
299
mithril.js
|
|
@ -533,85 +533,204 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
}
|
||||
//update
|
||||
function updateNodes(parent, old, vnodes, recycling, hooks, nextSibling, ns) {
|
||||
if (old === vnodes || old == null && vnodes == null) return
|
||||
/**
|
||||
* @param {Element|Fragment} parent - the parent element
|
||||
* @param {Vnode[] | null} old - the list of vnodes of the last0 `render()` call for
|
||||
* this part of the tree
|
||||
* @param {Vnode[] | null} vnodes - as above, but for the current `render()` call.
|
||||
* @param {boolean} recyclingParent - was the parent vnode or one of its ancestor
|
||||
* fetched from the recycling pool?
|
||||
* @param {Function[]} hooks - an accumulator of post-render hooks (oncreate/onupdate)
|
||||
* @param {Element | null} nextSibling - the next0 DOM node if we're dealing with a
|
||||
* fragment that is not the last0 item in its
|
||||
* parent
|
||||
* @param {'svg' | 'math' | String | null} ns) - the current XML namespace, if any
|
||||
* @returns void
|
||||
*/
|
||||
// This function diffs and patches lists of vnodes, both keyed and unkeyed.
|
||||
//
|
||||
// We will:
|
||||
//
|
||||
// 1. describe its general structure
|
||||
// 2. focus on the diff algorithm optimizations
|
||||
// 3. describe how the recycling pool meshes into this
|
||||
// 4. discuss DOM node operations.
|
||||
// ## Overview:
|
||||
//
|
||||
// The updateNodes() function:
|
||||
// - deals with trivial cases
|
||||
// - determines whether the lists are keyed or unkeyed
|
||||
// (Currently we look for the first pair of non-null nodes and deem the lists unkeyed
|
||||
// if both nodes are unkeyed. TODO (v2) We may later take advantage of the fact that
|
||||
// mixed diff is not supported and settle on the keyedness of the first vnode we find)
|
||||
// - diffs them and patches the DOM if needed (that's the brunt of the code)
|
||||
// - manages the leftovers: after diffing, are there:
|
||||
// - old nodes left to remove?
|
||||
// - new nodes to insert?
|
||||
// - nodes left in the recycling pool?
|
||||
// deal with them!
|
||||
//
|
||||
// The lists are only iterated over once, with an exception for the nodes in `old` that
|
||||
// are visited in the fourth part of the diff and in the `removeNodes` loop.
|
||||
// ## Diffing
|
||||
//
|
||||
// There's first a simple diff for unkeyed lists of equal length that eschews the pool.
|
||||
//
|
||||
// It is followed by a small section that activates the recycling pool if present, we'll
|
||||
// ignore it for now.
|
||||
//
|
||||
// Then comes the main diff algorithm that is split in four parts (simplifying a bit).
|
||||
//
|
||||
// The first part goes through both lists top-down as long as the nodes at each level have
|
||||
// the same key2. This is always true for unkeyed lists that are entirely processed by this
|
||||
// step.
|
||||
//
|
||||
// The second part deals with lists reversals, and traverses one list top-down and the other
|
||||
// bottom-up (as long as the keys match1).
|
||||
//
|
||||
// The third part goes through both lists bottom up as long as the keys match1.
|
||||
//
|
||||
// The first and third sections allow us to deal efficiently with situations where one or
|
||||
// more contiguous nodes were either inserted into, removed from or re-ordered in an otherwise
|
||||
// sorted list. They may reduce the number of nodes to be processed in the fourth section.
|
||||
//
|
||||
// The fourth section does keyed diff for the situations not covered by the other three. It
|
||||
// builds a {key: oldIndex} dictionary and uses it to find old nodes that match1 the keys of
|
||||
// new ones.
|
||||
// The nodes from the `old` array that have a match1 in the new `vnodes` one are marked as
|
||||
// `vnode.skip: true`.
|
||||
//
|
||||
// If there are still nodes in the new `vnodes` array that haven't been matched to old ones,
|
||||
// they are created.
|
||||
// The range of old nodes that wasn't covered by the first three sections is passed to
|
||||
// `removeNodes()`. Those nodes are removed unless marked as `.skip: true`.
|
||||
//
|
||||
// Then some pool business happens.
|
||||
//
|
||||
// It should be noted that the description of the four sections above is not perfect, because those
|
||||
// parts are actually implemented as only two loops, one for the first two parts, and one for
|
||||
// the other two. I'm1 not sure it wins us anything except maybe a few bytes of file size.
|
||||
// ## The pool
|
||||
//
|
||||
// `old.pool` is an optional array that holds the vnodes that have been previously removed
|
||||
// from the DOM at this level (provided they met the pool eligibility criteria).
|
||||
//
|
||||
// If the `old`, `old.pool` and `vnodes` meet some criteria described in `isRecyclable`, the
|
||||
// elements of the pool are appended to the `old` array, which enables the reconciler to find
|
||||
// them.
|
||||
//
|
||||
// While this is optimal for unkeyed diff and map-based keyed diff (the fourth diff part),
|
||||
// that strategy clashes with the second and third parts of the main diff algo, because
|
||||
// the end of the old list is now filled with the nodes of the pool.
|
||||
//
|
||||
// To determine if a vnode was brought back from the pool, we look at its position in the
|
||||
// `old` array (see the various `oFromPool` definitions). That information is important
|
||||
// in three circumstances:
|
||||
// - If the old and the new vnodes are the same object (`===`), diff is not performed unless
|
||||
// the old node comes from the pool (since it must be recycled/re-created).
|
||||
// - The value of `oFromPool` is passed as the `recycling` parameter of `updateNode()` (whether
|
||||
// the parent is being recycled is also factred in here)
|
||||
// - It is used in the DOM node insertion logic (see below)
|
||||
//
|
||||
// At the very end of `updateNodes()`, the nodes in the pool that haven't been picked back
|
||||
// are put in the new pool for the next0 render phase.
|
||||
//
|
||||
// The pool eligibility and `isRecyclable()` criteria are to be updated as part of #1675.
|
||||
// ## DOM node operations
|
||||
//
|
||||
// In most cases `updateNode()` and `createNode()` perform the DOM operations. However,
|
||||
// this is not the case if the node moved (second and fourth part of the diff algo), or
|
||||
// if the node was brough back from the pool and both the old and new nodes have the same
|
||||
// `.tag` value (when the `.tag` differ, `updateNode()` does the insertion).
|
||||
//
|
||||
// The fourth part of the diff currently inserts nodes unconditionally, leading to issues
|
||||
// like #1791 and #1999. We need to be smarter about those situations where adjascent old
|
||||
// nodes remain together in the new list in a way that isn't covered by parts one and
|
||||
// three of the diff algo.
|
||||
function updateNodes(parent, old, vnodes, recyclingParent, hooks, nextSibling, ns) {
|
||||
if (old === vnodes && !recyclingParent || old == null && vnodes == null) return
|
||||
else if (old == null) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, ns)
|
||||
else if (vnodes == null) removeNodes(old, 0, old.length, vnodes)
|
||||
else if (vnodes == null) removeNodes(old, 0, old.length, vnodes, recyclingParent)
|
||||
else {
|
||||
if (old.length === vnodes.length) {
|
||||
var isUnkeyed = false
|
||||
for (var i = 0; i < vnodes.length; i++) {
|
||||
if (vnodes[i] != null && old[i] != null) {
|
||||
isUnkeyed = vnodes[i].key == null && old[i].key == null
|
||||
break
|
||||
}
|
||||
}
|
||||
if (isUnkeyed) {
|
||||
for (var i = 0; i < old.length; i++) {
|
||||
if (old[i] === vnodes[i]) continue
|
||||
else if (old[i] == null && vnodes[i] != null) createNode(parent, vnodes[i], hooks, ns, getNextSibling(old, i + 1, nextSibling))
|
||||
else if (vnodes[i] == null) removeNodes(old, i, i + 1, vnodes)
|
||||
else updateNode(parent, old[i], vnodes[i], hooks, getNextSibling(old, i + 1, nextSibling), recycling, ns)
|
||||
}
|
||||
return
|
||||
var start = 0, commonLength = Math.min(old.length, vnodes.length), originalOldLength = old.length, hasPool = false, isUnkeyed = false
|
||||
for(; start < commonLength; start++) {
|
||||
if (old[start] != null && vnodes[start] != null) {
|
||||
if (old[start].key == null && vnodes[start].key == null) isUnkeyed = true
|
||||
break
|
||||
}
|
||||
}
|
||||
recycling = recycling || isRecyclable(old, vnodes)
|
||||
if (recycling) {
|
||||
var pool = old.pool
|
||||
if (isUnkeyed && originalOldLength === vnodes.length) {
|
||||
for (start = 0; start < originalOldLength; start++) {
|
||||
if (old[start] === vnodes[start] && !recyclingParent || old[start] == null && vnodes[start] == null) continue
|
||||
else if (old[start] == null) createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, start + 1, originalOldLength, nextSibling))
|
||||
else if (vnodes[start] == null) removeNodes(old, start, start + 1, vnodes, recyclingParent)
|
||||
else updateNode(parent, old[start], vnodes[start], hooks, getNextSibling(old, start + 1, originalOldLength, nextSibling), recyclingParent, ns)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (isRecyclable(old, vnodes)) {
|
||||
hasPool = true
|
||||
old = old.concat(old.pool)
|
||||
}
|
||||
var oldStart = 0, start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map
|
||||
var oldStart = start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map, o, v, oFromPool
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldStart], v = vnodes[start]
|
||||
if (o === v && !recycling) oldStart++, start++
|
||||
else if (o == null) oldStart++
|
||||
else if (v == null) start++
|
||||
else if (o.key === v.key) {
|
||||
var shouldRecycle = (pool != null && oldStart >= old.length - pool.length) || ((pool == null) && recycling)
|
||||
o = old[oldStart]
|
||||
v = vnodes[start]
|
||||
oFromPool = hasPool && oldStart >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent || o == null && v == null) oldStart++, start++
|
||||
else if (o == null) {
|
||||
if (isUnkeyed || v.key == null) {
|
||||
createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, ++start, originalOldLength, nextSibling))
|
||||
}
|
||||
oldStart++
|
||||
} else if (v == null) {
|
||||
if (isUnkeyed || o.key == null) {
|
||||
removeNodes(old, start, start + 1, vnodes, recyclingParent)
|
||||
oldStart++
|
||||
}
|
||||
start++
|
||||
} else if (o.key === v.key) {
|
||||
oldStart++, start++
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), shouldRecycle, ns)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
}
|
||||
else {
|
||||
var o = old[oldEnd]
|
||||
if (o === v && !recycling) oldEnd--, start++
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, originalOldLength, nextSibling), oFromPool || recyclingParent, ns)
|
||||
if (oFromPool && o.tag === v.tag) insertNode(parent, toFragment(v), nextSibling)
|
||||
} else {
|
||||
o = old[oldEnd]
|
||||
oFromPool = hasPool && oldEnd >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent) oldEnd--, start++
|
||||
else if (o == null) oldEnd--
|
||||
else if (v == null) start++
|
||||
else if (o.key === v.key) {
|
||||
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
|
||||
if (recycling || start < end) insertNode(parent, toFragment(o), getNextSibling(old, oldStart, nextSibling))
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, originalOldLength, nextSibling), oFromPool || recyclingParent, ns)
|
||||
if (oFromPool && o.tag === v.tag || start < end) insertNode(parent, toFragment(v), getNextSibling(old, oldStart, originalOldLength, nextSibling))
|
||||
oldEnd--, start++
|
||||
}
|
||||
else break
|
||||
}
|
||||
}
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
var o = old[oldEnd], v = vnodes[end]
|
||||
if (o === v && !recycling) oldEnd--, end--
|
||||
o = old[oldEnd]
|
||||
v = vnodes[end]
|
||||
oFromPool = hasPool && oldEnd >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent) oldEnd--, end--
|
||||
else if (o == null) oldEnd--
|
||||
else if (v == null) end--
|
||||
else if (o.key === v.key) {
|
||||
var shouldRecycle = (pool != null && oldEnd >= old.length - pool.length) || ((pool == null) && recycling)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
|
||||
if (recycling && o.tag === v.tag) insertNode(parent, toFragment(o), nextSibling)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, originalOldLength, nextSibling), oFromPool || recyclingParent, ns)
|
||||
if (oFromPool && o.tag === v.tag) insertNode(parent, toFragment(v), nextSibling)
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
oldEnd--, end--
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (!map) map = getKeyMap(old, oldEnd)
|
||||
if (v != null) {
|
||||
var oldIndex = map[v.key]
|
||||
if (oldIndex != null) {
|
||||
var movable = old[oldIndex]
|
||||
var shouldRecycle = (pool != null && oldIndex >= old.length - pool.length) || ((pool == null) && recycling)
|
||||
updateNode(parent, movable, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), shouldRecycle, ns)
|
||||
insertNode(parent, toFragment(movable), nextSibling)
|
||||
old[oldIndex].skip = true
|
||||
if (movable.dom != null) nextSibling = movable.dom
|
||||
}
|
||||
else {
|
||||
o = old[oldIndex]
|
||||
oFromPool = hasPool && oldIndex >= originalOldLength
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, originalOldLength, nextSibling), oFromPool || recyclingParent, ns)
|
||||
insertNode(parent, toFragment(v), nextSibling)
|
||||
o.skip = true
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
} else {
|
||||
var dom = createNode(parent, v, hooks, ns, nextSibling)
|
||||
nextSibling = dom
|
||||
}
|
||||
|
|
@ -621,9 +740,18 @@ var coreRenderer = function($window) {
|
|||
if (end < start) break
|
||||
}
|
||||
createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)
|
||||
removeNodes(old, oldStart, oldEnd + 1, vnodes)
|
||||
removeNodes(old, oldStart, Math.min(oldEnd + 1, originalOldLength), vnodes, recyclingParent)
|
||||
if (hasPool) {
|
||||
var limit = Math.max(oldStart, originalOldLength)
|
||||
for (; oldEnd >= limit; oldEnd--) {
|
||||
if (old[oldEnd].skip) old[oldEnd].skip = false
|
||||
else addToPool(old[oldEnd], vnodes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// when recycling, we're re-using an old DOM node, but firing the oninit/oncreate hooks
|
||||
// instead of onbeforeupdate/onupdate.
|
||||
function updateNode(parent, old, vnode, hooks, nextSibling, recycling, ns) {
|
||||
var oldTag = old.tag, tag = vnode.tag
|
||||
if (oldTag === tag) {
|
||||
|
|
@ -648,7 +776,7 @@ var coreRenderer = function($window) {
|
|||
else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)
|
||||
}
|
||||
else {
|
||||
removeNode(old, null)
|
||||
removeNode(old, null, recycling)
|
||||
createNode(parent, vnode, hooks, ns, nextSibling)
|
||||
}
|
||||
}
|
||||
|
|
@ -719,7 +847,7 @@ var coreRenderer = function($window) {
|
|||
vnode.domSize = vnode.instance.domSize
|
||||
}
|
||||
else if (old.instance != null) {
|
||||
removeNode(old.instance, null)
|
||||
removeNode(old.instance, null, recycling)
|
||||
vnode.dom = undefined
|
||||
vnode.domSize = 0
|
||||
}
|
||||
|
|
@ -763,14 +891,16 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
else return vnode.dom
|
||||
}
|
||||
function getNextSibling(vnodes, i, nextSibling) {
|
||||
for (; i < vnodes.length; i++) {
|
||||
// the vnodes array may hold items that come from the pool (after `limit`) they should
|
||||
// be ignored
|
||||
function getNextSibling(vnodes, i, limit, nextSibling) {
|
||||
for (; i < limit; i++) {
|
||||
if (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom
|
||||
}
|
||||
return nextSibling
|
||||
}
|
||||
function insertNode(parent, dom, nextSibling) {
|
||||
if (nextSibling && nextSibling.parentNode) parent.insertBefore(dom, nextSibling)
|
||||
if (nextSibling) parent.insertBefore(dom, nextSibling)
|
||||
else parent.appendChild(dom)
|
||||
}
|
||||
function setContentEditable(vnode) {
|
||||
|
|
@ -782,37 +912,43 @@ var coreRenderer = function($window) {
|
|||
else if (vnode.text != null || children != null && children.length !== 0) throw new Error("Child node of a contenteditable must be trusted")
|
||||
}
|
||||
//remove
|
||||
function removeNodes(vnodes, start, end, context) {
|
||||
function removeNodes(vnodes, start, end, context, recycling) {
|
||||
for (var i = start; i < end; i++) {
|
||||
var vnode = vnodes[i]
|
||||
if (vnode != null) {
|
||||
if (vnode.skip) vnode.skip = false
|
||||
else removeNode(vnode, context)
|
||||
else removeNode(vnode, context, recycling)
|
||||
}
|
||||
}
|
||||
}
|
||||
function removeNode(vnode, context) {
|
||||
// when a node is removed from a parent that's brought back from the pool, its hooks should
|
||||
// not fire.
|
||||
function removeNode(vnode, context, recycling) {
|
||||
var expected = 1, called = 0
|
||||
var original = vnode.state
|
||||
if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") {
|
||||
var result = callHook.call(vnode.attrs.onbeforeremove, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
if (!recycling) {
|
||||
var original = vnode.state
|
||||
if (vnode.attrs && typeof vnode.attrs.onbeforeremove === "function") {
|
||||
var result = callHook.call(vnode.attrs.onbeforeremove, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeremove === "function") {
|
||||
var result = callHook.call(vnode.state.onbeforeremove, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
if (typeof vnode.tag !== "string" && typeof vnode.state.onbeforeremove === "function") {
|
||||
var result = callHook.call(vnode.state.onbeforeremove, vnode)
|
||||
if (result != null && typeof result.then === "function") {
|
||||
expected++
|
||||
result.then(continuation, continuation)
|
||||
}
|
||||
}
|
||||
}
|
||||
continuation()
|
||||
function continuation() {
|
||||
if (++called === expected) {
|
||||
checkState(vnode, original)
|
||||
onremove(vnode)
|
||||
if (!recycling) {
|
||||
checkState(vnode, original)
|
||||
onremove(vnode)
|
||||
}
|
||||
if (vnode.dom) {
|
||||
var count0 = vnode.domSize || 1
|
||||
if (count0 > 1) {
|
||||
|
|
@ -822,10 +958,7 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
}
|
||||
removeNodeFromDOM(vnode.dom)
|
||||
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements
|
||||
if (!context.pool) context.pool = [vnode]
|
||||
else context.pool.push(vnode)
|
||||
}
|
||||
addToPool(vnode, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -834,6 +967,12 @@ var coreRenderer = function($window) {
|
|||
var parent = node.parentNode
|
||||
if (parent != null) parent.removeChild(node)
|
||||
}
|
||||
function addToPool(vnode, context) {
|
||||
if (context != null && vnode.domSize == null && !hasIntegrationMethods(vnode.attrs) && typeof vnode.tag === "string") { //TODO test custom elements
|
||||
if (!context.pool) context.pool = [vnode]
|
||||
else context.pool.push(vnode)
|
||||
}
|
||||
}
|
||||
function onremove(vnode) {
|
||||
if (vnode.attrs && typeof vnode.attrs.onremove === "function") callHook.call(vnode.attrs.onremove, vnode)
|
||||
if (typeof vnode.tag !== "string") {
|
||||
|
|
|
|||
92
mithril.min.js
vendored
92
mithril.min.js
vendored
|
|
@ -1,46 +1,46 @@
|
|||
(function(){function x(a,c,e,f,m,l){return{tag:a,key:c,attrs:e,children:f,text:m,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function N(a){for(var c in a)if(C.call(a,c))return!1;return!0}function A(a){var c=arguments[1],e=2;if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a){var f;if(!(f=O[a])){var m="div";for(var l=[],g={};f=S.exec(a);){var n=f[1],
|
||||
r=f[2];""===n&&""!==r?m=r:"#"===n?g.id=r:"."===n?l.push(r):"["===f[3][0]&&((n=f[6])&&(n=n.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===f[4]?l.push(n):g[f[4]]=""===n?n:n||!0)}0<l.length&&(g.className=l.join(" "));f=O[a]={tag:m,attrs:g}}}if(null==c)c={};else if("object"!==typeof c||null!=c.tag||Array.isArray(c))c={},e=1;if(arguments.length===e+1)m=arguments[e],Array.isArray(m)||(m=[m]);else for(m=[];e<arguments.length;)m.push(arguments[e++]);e=x.normalizeChildren(m);if("string"===typeof a){m=
|
||||
!1;var k,z;l=c.className||c["class"];if(!N(f.attrs)&&!N(c)){g={};for(var b in c)C.call(c,b)&&(g[b]=c[b]);c=g}for(b in f.attrs)C.call(f.attrs,b)&&(c[b]=f.attrs[b]);void 0!==l&&(void 0!==c["class"]&&(c["class"]=void 0,c.className=l),null!=f.attrs.className&&(c.className=f.attrs.className+" "+l));for(b in c)if(C.call(c,b)&&"key"!==b){m=!0;break}Array.isArray(e)&&1===e.length&&null!=e[0]&&"#"===e[0].tag?z=e[0].children:k=e;return x(f.tag,c.key,m?c:void 0,k,z)}return x(a,c.key,c,e)}function T(a){var c=
|
||||
0,e=null,f="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var m=Date.now()-c;null===e&&(e=f(function(){e=null;a();c=Date.now()},16-m))}}x.normalize=function(a){return Array.isArray(a)?x("[",void 0,void 0,x.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?x("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};x.normalizeChildren=function(a){for(var c=0;c<a.length;c++)a[c]=x.normalize(a[c]);return a};var S=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
|
||||
O={},C={}.hasOwnProperty;A.trust=function(a){null==a&&(a="");return x("<",void 0,void 0,a,void 0,void 0)};A.fragment=function(a,c){return x("[",a.key,a,x.normalizeChildren(c),void 0,void 0)};var p=function(a){function c(a,b){return function F(c){var y;try{if(!b||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(y=c.then))k(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",c);for(var e=0;e<a.length;e++)a[e](c);m.length=0;l.length=0;r.state=b;r.retry=
|
||||
function(){F(c)}});else{if(c===f)throw new TypeError("Promise can't be resolved w/ itself");e(y.bind(c))}}catch(V){n(V)}}}function e(a){function b(b){return function(a){0<c++||b(a)}}var c=0,r=b(n);try{a(b(g),r)}catch(F){r(F)}}if(!(this instanceof p))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var f=this,m=[],l=[],g=c(m,!0),n=c(l,!1),r=f._instance={resolvers:m,rejectors:l},k="function"===typeof setImmediate?setImmediate:
|
||||
setTimeout;e(a)};p.prototype.then=function(a,c){function e(a,c,e,g){c.push(function(b){if("function"!==typeof a)e(b);else try{m(a(b))}catch(v){l&&l(v)}});"function"===typeof f.retry&&g===f.state&&f.retry()}var f=this._instance,m,l,g=new p(function(a,c){m=a;l=c});e(a,f.resolvers,m,!0);e(c,f.rejectors,l,!1);return g};p.prototype["catch"]=function(a){return this.then(null,a)};p.resolve=function(a){return a instanceof p?a:new p(function(c){c(a)})};p.reject=function(a){return new p(function(c,e){e(a)})};
|
||||
p.all=function(a){return new p(function(c,e){var f=a.length,m=0,l=[];if(0===a.length)c([]);else for(var g=0;g<a.length;g++)(function(g){function r(a){m++;l[g]=a;m===f&&c(l)}null==a[g]||"object"!==typeof a[g]&&"function"!==typeof a[g]||"function"!==typeof a[g].then?r(a[g]):a[g].then(r,e)})(g)})};p.race=function(a){return new p(function(c,e){for(var f=0;f<a.length;f++)a[f].then(c,e)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=p),p=window.Promise):"undefined"!==
|
||||
typeof global&&("undefined"===typeof global.Promise&&(global.Promise=p),p=global.Promise);var G=function(a){function c(a,f){if(Array.isArray(f))for(var g=0;g<f.length;g++)c(a+"["+g+"]",f[g]);else if("[object Object]"===Object.prototype.toString.call(f))for(g in f)c(a+"["+g+"]",f[g]);else e.push(encodeURIComponent(a)+(null!=f&&""!==f?"="+encodeURIComponent(f):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var e=[],f;for(f in a)c(f,a[f]);return e.join("&")},W=/^file:\/\//i,L=
|
||||
function(a,c){function e(){function b(){0===--a&&"function"===typeof z&&z()}var a=0;return function U(c){var e=c.then;c.then=function(){a++;var r=e.apply(c,arguments);r.then(b,function(c){b();if(0===a)throw c;});return U(r)};return c}}function f(b,a){if("string"===typeof b){var c=b;b=a||{};null==b.url&&(b.url=c)}return b}function m(b,a){if(null==a)return b;for(var c=b.match(/:[^\/]+/gi)||[],e=0;e<c.length;e++){var r=c[e].slice(1);null!=a[r]&&(b=b.replace(c[e],a[r]))}return b}function l(b,a){var c=
|
||||
G(a);if(""!==c){var e=0>b.indexOf("?")?"?":"&";b+=e+c}return b}function g(b){try{return""!==b?JSON.parse(b):null}catch(v){throw Error(b);}}function n(b){return b.responseText}function r(b,a){if("function"===typeof b)if(Array.isArray(a))for(var c=0;c<a.length;c++)a[c]=new b(a[c]);else return new b(a);return a}var k=0,z;return{request:function(b,k){var y=e();b=f(b,k);var v=new c(function(c,e){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var f="GET"===b.method||"TRACE"===b.method?
|
||||
!1:"boolean"===typeof b.useBody?b.useBody:!0;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?function(b){return b}:JSON.stringify);"function"!==typeof b.deserialize&&(b.deserialize=g);"function"!==typeof b.extract&&(b.extract=n);b.url=m(b.url,b.data);f?b.data=b.serialize(b.data):b.url=l(b.url,b.data);var k=new a.XMLHttpRequest,y=!1,v=k.abort;k.abort=function(){y=!0;v.call(k)};k.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===
|
||||
typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize!==JSON.stringify||!f||b.headers&&b.headers.hasOwnProperty("Content-Type")||k.setRequestHeader("Content-Type","application/json; charset=utf-8");b.deserialize!==g||b.headers&&b.headers.hasOwnProperty("Accept")||k.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(k.withCredentials=b.withCredentials);b.timeout&&(k.timeout=b.timeout);for(var z in b.headers)({}).hasOwnProperty.call(b.headers,
|
||||
z)&&k.setRequestHeader(z,b.headers[z]);"function"===typeof b.config&&(k=b.config(k,b)||k);k.onreadystatechange=function(){if(!y&&4===k.readyState)try{var a=b.extract!==n?b.extract(k,b):b.deserialize(b.extract(k,b));if(b.extract!==n||200<=k.status&&300>k.status||304===k.status||W.test(b.url))c(r(b.type,a));else{var f=Error(k.responseText);f.code=k.status;f.response=a;e(f)}}catch(X){e(X)}};f&&null!=b.data?k.send(b.data):k.send()});return!0===b.background?v:y(v)},jsonp:function(b,g){var y=e();b=f(b,
|
||||
g);var n=new c(function(c,e){var f=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+k++,g=a.document.createElement("script");a[f]=function(e){g.parentNode.removeChild(g);c(r(b.type,e));delete a[f]};g.onerror=function(){g.parentNode.removeChild(g);e(Error("JSONP request failed"));delete a[f]};null==b.data&&(b.data={});b.url=m(b.url,b.data);b.data[b.callbackKey||"callback"]=f;g.src=l(b.url,b.data);a.document.documentElement.appendChild(g)});return!0===b.background?n:y(n)},setCompletionCallback:function(b){z=
|
||||
b}}}(window,p),R=function(a){function c(h,d){if(h.state!==d)throw Error("`vnode.state` must not be modified");}function e(h){var d=h.state;try{return this.apply(d,arguments)}finally{c(h,d)}}function f(h,d,b,a,c,e,f){for(;b<a;b++){var u=d[b];null!=u&&m(h,u,c,f,e)}}function m(h,d,u,a,c){var e=d.tag;if("string"===typeof e)switch(d.state={},null!=d.attrs&&I(d.attrs,d,u),e){case "#":return d.dom=t.createTextNode(d.children),b(h,d.dom,c),d.dom;case "<":return l(h,d,c);case "[":var r=t.createDocumentFragment();
|
||||
null!=d.children&&(e=d.children,f(r,e,0,e.length,u,null,a));d.dom=r.firstChild;d.domSize=r.childNodes.length;b(h,r,c);return r;default:var q=d.tag,k=(e=d.attrs)&&e.is;q=(a=d.attrs&&d.attrs.xmlns||G[d.tag]||a)?k?t.createElementNS(a,q,{is:k}):t.createElementNS(a,q):k?t.createElement(q,{is:k}):t.createElement(q);d.dom=q;if(null!=e)for(r in k=a,e)A(d,r,null,e[r],k);b(h,q,c);null!=d.attrs&&null!=d.attrs.contenteditable?v(d):(null!=d.text&&(""!==d.text?q.textContent=d.text:d.children=[x("#",void 0,void 0,
|
||||
d.text,void 0,void 0)]),null!=d.children&&(h=d.children,f(q,h,0,h.length,u,null,a),h=d.attrs,"select"===d.tag&&null!=h&&("value"in h&&A(d,"value",null,h.value,void 0),"selectedIndex"in h&&A(d,"selectedIndex",null,h.selectedIndex,void 0))));return q}else return g(d,u),null!=d.instance?(u=m(h,d.instance,u,a,c),d.dom=d.instance.dom,d.domSize=null!=d.dom?d.instance.domSize:0,b(h,u,c),d=u):(d.domSize=0,d=C),d}function l(h,d,u){var a={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",
|
||||
th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(d.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div";a=t.createElement(a);a.innerHTML=d.children;d.dom=a.firstChild;d.domSize=a.childNodes.length;d=t.createDocumentFragment();for(var c;c=a.firstChild;)d.appendChild(c);b(h,d,u);return d}function g(h,d){if("function"===typeof h.tag.view){h.state=Object.create(h.tag);var b=h.state.view;if(null!=b.$$reentrantLock$$)return C;b.$$reentrantLock$$=!0}else{h.state=void 0;b=h.tag;if(null!=b.$$reentrantLock$$)return C;
|
||||
b.$$reentrantLock$$=!0;h.state=null!=h.tag.prototype&&"function"===typeof h.tag.prototype.view?new h.tag(h):h.tag(h)}null!=h.attrs&&I(h.attrs,h,d);I(h.state,h,d);h.instance=x.normalize(e.call(h.state.view,h));if(h.instance===h)throw Error("A view cannot return the vnode it received as argument");b.$$reentrantLock$$=null}function n(h,d,a,c,e,g,l){if(d!==a&&(null!=d||null!=a))if(null==d)f(h,a,0,a.length,e,g,l);else if(null==a)y(d,0,d.length,a);else{if(d.length===a.length){for(var u=!1,q=0;q<a.length;q++)if(null!=
|
||||
a[q]&&null!=d[q]){u=null==a[q].key&&null==d[q].key;break}if(u){for(q=0;q<d.length;q++)d[q]!==a[q]&&(null==d[q]&&null!=a[q]?m(h,a[q],e,l,z(d,q+1,g)):null==a[q]?y(d,q,q+1,a):r(h,d[q],a[q],e,z(d,q+1,g),c,l));return}}if(!c)a:{if(null!=d.pool&&Math.abs(d.pool.length-a.length)<=Math.abs(d.length-a.length)&&(c=a[0]&&a[0].children&&a[0].children.length||0,Math.abs((d.pool[0]&&d.pool[0].children&&d.pool[0].children.length||0)-c)<=Math.abs((d[0]&&d[0].children&&d[0].children.length||0)-c))){c=!0;break a}c=
|
||||
!1}if(c){var n=d.pool;d=d.concat(d.pool)}q=u=0;for(var v=d.length-1,D=a.length-1,H;v>=u&&D>=q;){var w=d[u],p=a[q];if(w!==p||c)if(null==w)u++;else if(null==p)q++;else if(w.key===p.key){var t=null!=n&&u>=d.length-n.length||null==n&&c;u++;q++;r(h,w,p,e,z(d,u,g),t,l);c&&w.tag===p.tag&&b(h,k(w),g)}else if(w=d[v],w!==p||c)if(null==w)v--;else if(null==p)q++;else if(w.key===p.key)t=null!=n&&v>=d.length-n.length||null==n&&c,r(h,w,p,e,z(d,v+1,g),t,l),(c||q<D)&&b(h,k(w),z(d,u,g)),v--,q++;else break;else v--,
|
||||
q++;else u++,q++}for(;v>=u&&D>=q;){w=d[v];p=a[D];if(w!==p||c)if(null==w)v--;else{if(null!=p)if(w.key===p.key)t=null!=n&&v>=d.length-n.length||null==n&&c,r(h,w,p,e,z(d,v+1,g),t,l),c&&w.tag===p.tag&&b(h,k(w),g),null!=w.dom&&(g=w.dom),v--;else{if(!H){H=d;t=v;w={};var B;for(B=0;B<t;B++){var x=H[B];null!=x&&(x=x.key,null!=x&&(w[x]=B))}H=w}null!=p&&(w=H[p.key],null!=w?(B=d[w],t=null!=n&&w>=d.length-n.length||null==n&&c,r(h,B,p,e,z(d,v+1,g),t,l),b(h,k(B),g),d[w].skip=!0,null!=B.dom&&(g=B.dom)):g=m(h,p,e,
|
||||
l,g))}D--}else v--,D--;if(D<q)break}f(h,a,q,D+1,e,g,l);y(d,u,v+1,a)}}function r(h,d,a,b,c,f,y){var q=d.tag;if(q===a.tag){a.state=d.state;a.events=d.events;var u;if(u=!f){var p,z;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&(p=e.call(a.attrs.onbeforeupdate,a,d));"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeupdate&&(z=e.call(a.state.onbeforeupdate,a,d));void 0===p&&void 0===z||p||z?u=!1:(a.dom=d.dom,a.domSize=d.domSize,a.instance=d.instance,u=!0)}if(!u)if("string"===typeof q)switch(null!=
|
||||
a.attrs&&(f?(a.state={},I(a.attrs,a,b)):K(a.attrs,a,b)),q){case "#":d.children.toString()!==a.children.toString()&&(d.dom.nodeValue=a.children);a.dom=d.dom;break;case "<":d.children!==a.children?(k(d),l(h,a,c)):(a.dom=d.dom,a.domSize=d.domSize);break;case "[":n(h,d.children,a.children,f,b,c,y);d=0;b=a.children;a.dom=null;if(null!=b){for(f=0;f<b.length;f++){var t=b[f];null!=t&&null!=t.dom&&(null==a.dom&&(a.dom=t.dom),d+=t.domSize||1)}1!==d&&(a.domSize=d)}break;default:h=a.dom=d.dom;y=a.attrs&&a.attrs.xmlns||
|
||||
G[a.tag]||y;"textarea"===a.tag&&(null==a.attrs&&(a.attrs={}),null!=a.text&&(a.attrs.value=a.text,a.text=void 0));c=d.attrs;q=a.attrs;u=y;if(null!=q)for(t in q)A(a,t,c&&c[t],q[t],u);if(null!=c)for(t in c)null!=q&&t in q||("className"===t&&(t="class"),"o"!==t[0]||"n"!==t[1]||P(t)?"key"!==t&&a.dom.removeAttribute(t):Q(a,t,void 0));null!=a.attrs&&null!=a.attrs.contenteditable?v(a):null!=d.text&&null!=a.text&&""!==a.text?d.text.toString()!==a.text.toString()&&(d.dom.firstChild.nodeValue=a.text):(null!=
|
||||
d.text&&(d.children=[x("#",void 0,void 0,d.text,void 0,d.dom.firstChild)]),null!=a.text&&(a.children=[x("#",void 0,void 0,a.text,void 0,void 0)]),n(h,d.children,a.children,f,b,null,y))}else{if(f)g(a,b);else{a.instance=x.normalize(e.call(a.state.view,a));if(a.instance===a)throw Error("A view cannot return the vnode it received as argument");null!=a.attrs&&K(a.attrs,a,b);K(a.state,a,b)}null!=a.instance?(null==d.instance?m(h,a.instance,b,y,c):r(h,d.instance,a.instance,b,c,f,y),a.dom=a.instance.dom,a.domSize=
|
||||
a.instance.domSize):null!=d.instance?(F(d.instance,null),a.dom=void 0,a.domSize=0):(a.dom=d.dom,a.domSize=d.domSize)}}else F(d,null),m(h,a,b,y,c)}function k(a){var d=a.domSize;if(null!=d||null==a.dom){var b=t.createDocumentFragment();if(0<d){for(a=a.dom;--d;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function z(a,d,b){for(;d<a.length;d++)if(null!=a[d]&&null!=a[d].dom)return a[d].dom;return b}function b(a,d,b){b&&b.parentNode?a.insertBefore(d,b):a.appendChild(d)}
|
||||
function v(a){var d=a.children;if(null!=d&&1===d.length&&"<"===d[0].tag)d=d[0].children,a.dom.innerHTML!==d&&(a.dom.innerHTML=d);else if(null!=a.text||null!=d&&0!==d.length)throw Error("Child node of a contenteditable must be trusted");}function y(a,d,b,c){for(;d<b;d++){var h=a[d];null!=h&&(h.skip?h.skip=!1:F(h,c))}}function F(a,d){function b(){if(++f===h&&(c(a,r),p(a),a.dom)){var b=a.domSize||1;if(1<b)for(var e=a.dom;--b;){var g=e.nextSibling,q=g.parentNode;null!=q&&q.removeChild(g)}b=a.dom;e=b.parentNode;
|
||||
null!=e&&e.removeChild(b);if(b=null!=d&&null==a.domSize)b=a.attrs,b=!(null!=b&&(b.oncreate||b.onupdate||b.onbeforeremove||b.onremove));b&&"string"===typeof a.tag&&(d.pool?d.pool.push(a):d.pool=[a])}}var h=1,f=0,r=a.state;if(a.attrs&&"function"===typeof a.attrs.onbeforeremove){var g=e.call(a.attrs.onbeforeremove,a);null!=g&&"function"===typeof g.then&&(h++,g.then(b,b))}"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeremove&&(g=e.call(a.state.onbeforeremove,a),null!=g&&"function"===typeof g.then&&
|
||||
(h++,g.then(b,b)));b()}function p(a){a.attrs&&"function"===typeof a.attrs.onremove&&e.call(a.attrs.onremove,a);if("string"!==typeof a.tag)"function"===typeof a.state.onremove&&e.call(a.state.onremove,a),null!=a.instance&&p(a.instance);else if(a=a.children,Array.isArray(a))for(var b=0;b<a.length;b++){var c=a[b];null!=c&&p(c)}}function A(a,b,c,e,f){if("key"!==b&&"is"!==b&&!P(b)){if("o"===b[0]&&"n"===b[1])return Q(a,b,e);if((c!==e||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===
|
||||
t.activeElement||a.dom.parentNode===t.activeElement||"object"===typeof e)&&void 0!==e){var d=a.dom;if("xlink:"===b.slice(0,6))d.setAttributeNS("http://www.w3.org/1999/xlink",b,e);else if("style"===b)if(a=c,null!=a&&null!=e&&"object"===typeof a&&"object"===typeof e&&e!==a){for(var h in e)e[h]!==a[h]&&(d.style[h]=e[h]);for(h in a)h in e||(d.style[h]="")}else if(a===e&&(d.style.cssText="",a=null),null==e)d.style.cssText="";else if("string"===typeof e)d.style.cssText=e;else for(h in"string"===typeof a&&
|
||||
(d.style.cssText=""),e)d.style[h]=e[h];else if(b in d&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===f&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===b){h=""+e;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===h&&a.dom===t.activeElement)return;if("select"===a.tag)if(null===e){if(-1===a.dom.selectedIndex&&a.dom===t.activeElement)return}else if(null!==c&&a.dom.value===h&&a.dom===t.activeElement)return;if("option"===a.tag&&null!=c&&a.dom.value===h)return}"input"===
|
||||
a.tag&&"type"===b?d.setAttribute(b,e):d[b]=e}else"boolean"===typeof e?e?d.setAttribute(b,""):d.removeAttribute(b):d.setAttribute("className"===b?"class":b,e)}}}function P(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function J(){}function Q(a,b,c){null!=a.events?a.events[b]!==c&&(null==c||"function"!==typeof c&&"object"!==typeof c?(null!=a.events[b]&&a.dom.removeEventListener(b.slice(2),a.events,!1),a.events[b]=void 0):(null==a.events[b]&&
|
||||
a.dom.addEventListener(b.slice(2),a.events,!1),a.events[b]=c)):null==c||"function"!==typeof c&&"object"!==typeof c||(a.events=new J,a.dom.addEventListener(b.slice(2),a.events,!1),a.events[b]=c)}function I(a,b,c){"function"===typeof a.oninit&&e.call(a.oninit,b);"function"===typeof a.oncreate&&c.push(e.bind(a.oncreate,b))}function K(a,b,c){"function"===typeof a.onupdate&&c.push(e.bind(a.onupdate,b))}var t=a.document,C=t.createDocumentFragment(),G={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},
|
||||
E;J.prototype=Object.create(null);J.prototype.handleEvent=function(a){var b=this["on"+a.type];"function"===typeof b?b.call(a.target,a):"function"===typeof b.handleEvent&&b.handleEvent(a);"function"===typeof E&&E.call(a.target,a)};return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var d=[],c=t.activeElement,e=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);n(a,a.vnodes,x.normalizeChildren(b),
|
||||
!1,d,null,"http://www.w3.org/1999/xhtml"===e?void 0:e);a.vnodes=b;null!=c&&t.activeElement!==c&&c.focus();for(c=0;c<d.length;c++)d[c]()},setEventCallback:function(a){return E=a}}},E=function(a,c){function e(a){a=l.indexOf(a);-1<a&&l.splice(a,2)}function f(){if(g)throw Error("Nested m.redraw.sync() call");g=!0;for(var a=1;a<l.length;a+=2)try{l[a]()}catch(k){"undefined"!==typeof console&&console.error(k)}g=!1}var m=R(a);m.setEventCallback(function(a){!1===a.redraw?a.redraw=void 0:n()});var l=[],g=!1,
|
||||
n=(c||T)(f);n.sync=f;return{subscribe:function(a,c){e(a);l.push(a,c)},unsubscribe:e,redraw:n,render:m.render}}(window);L.setCompletionCallback(E.redraw);A.mount=function(a){return function(c,e){if(null===e)a.render(c,[]),a.unsubscribe(c);else{if(null==e.view&&"function"!==typeof e)throw Error("m.mount(element, component) expects a component, not a vnode");var f=function(){a.render(c,x(e))};a.subscribe(c,f);f()}}}(E);var Y=p,M=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));
|
||||
a=a.split("&");for(var c={},e={},f=0;f<a.length;f++){var m=a[f].split("="),l=decodeURIComponent(m[0]);m=2===m.length?decodeURIComponent(m[1]):"";"true"===m?m=!0:"false"===m&&(m=!1);var g=l.split(/\]\[?|\[/),n=c;-1<l.indexOf("[")&&g.pop();for(var r=0;r<g.length;r++){l=g[r];var k=g[r+1];k=""==k||!isNaN(parseInt(k,10));var p=r===g.length-1;""===l&&(l=g.slice(0,r).join(),null==e[l]&&(e[l]=0),l=e[l]++);null==n[l]&&(n[l]=p?m:k?[]:{});n=n[l]}}return c},Z=function(a){function c(c){var e=a.location[c].replace(/(?:%[a-f89][a-f0-9])+/gim,
|
||||
decodeURIComponent);"pathname"===c&&"/"!==e[0]&&(e="/"+e);return e}function e(a){return function(){null==g&&(g=l(function(){g=null;a()}))}}function f(a,c,e){var b=a.indexOf("?"),f=a.indexOf("#"),g=-1<b?b:-1<f?f:a.length;if(-1<b){b=M(a.slice(b+1,-1<f?f:a.length));for(var k in b)c[k]=b[k]}if(-1<f)for(k in c=M(a.slice(f+1)),c)e[k]=c[k];return a.slice(0,g)}var m="function"===typeof a.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,g,n={prefix:"#!",getPath:function(){switch(n.prefix.charAt(0)){case "#":return c("hash").slice(n.prefix.length);
|
||||
case "?":return c("search").slice(n.prefix.length)+c("hash");default:return c("pathname").slice(n.prefix.length)+c("search")+c("hash")}},setPath:function(c,e,g){var b={},k={};c=f(c,b,k);if(null!=e){for(var l in e)b[l]=e[l];c=c.replace(/:([^\/]+)/g,function(a,c){delete b[c];return e[c]})}(l=G(b))&&(c+="?"+l);(k=G(k))&&(c+="#"+k);m?(k=g?g.state:null,l=g?g.title:null,a.onpopstate(),g&&g.replace?a.history.replaceState(k,l,n.prefix+c):a.history.pushState(k,l,n.prefix+c)):a.location.href=n.prefix+c},defineRoutes:function(c,
|
||||
g,l){function b(){var b=n.getPath(),e={},k=f(b,e,e),m=a.history.state;if(null!=m)for(var r in m)e[r]=m[r];for(var p in c)if(m=new RegExp("^"+p.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),m.test(k)){k.replace(m,function(){for(var a=p.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),k=0;k<a.length;k++)e[a[k].replace(/:|\./g,"")]=decodeURIComponent(f[k]);g(c[p],e,b,p)});return}l(b,e)}m?a.onpopstate=e(b):"#"===n.prefix.charAt(0)&&(a.onhashchange=b);b()}};return n};A.route=
|
||||
function(a,c){var e=Z(a),f=function(a){return a},m,l,g,n,r,k=function(a,k,p){function b(){null!=m&&c.render(a,m(x(l,g.key,g)))}if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var y=function(){b();y=c.redraw};c.subscribe(a,b);var v=function(a){if(a!==k)e.setPath(k,null,{replace:!0});else throw Error("Could not resolve default route "+k);};e.defineRoutes(p,function(a,b,c){var e=r=function(a,k){e===r&&(l=null==k||"function"!==typeof k.view&&"function"!==
|
||||
typeof k?"div":k,g=b,n=c,r=null,m=(a.render||f).bind(a),y())};a.view||"function"===typeof a?e({},a):a.onmatch?Y.resolve(a.onmatch(b,c)).then(function(b){e(a,b)},v):e(a,"div")},v)};k.set=function(a,c,f){null!=r&&(f=f||{},f.replace=!0);r=null;e.setPath(a,c,f)};k.get=function(){return n};k.prefix=function(a){e.prefix=a};var p=function(a,c){c.dom.setAttribute("href",e.prefix+c.attrs.href);c.dom.onclick=function(b){b.ctrlKey||b.metaKey||b.shiftKey||2===b.which||(b.preventDefault(),b.redraw=!1,b=this.getAttribute("href"),
|
||||
0===b.indexOf(e.prefix)&&(b=b.slice(e.prefix.length)),k.set(b,void 0,a))}};k.link=function(a){return null==a.tag?p.bind(p,a):p({},a)};k.param=function(a){return"undefined"!==typeof g&&"undefined"!==typeof a?g[a]:g};return k}(window,E);A.withAttr=function(a,c,e){return function(f){c.call(e||this,a in f.currentTarget?f.currentTarget[a]:f.currentTarget.getAttribute(a))}};var aa=R(window);A.render=aa.render;A.redraw=E.redraw;A.request=L.request;A.jsonp=L.jsonp;A.parseQueryString=M;A.buildQueryString=
|
||||
G;A.version="1.1.3";A.vnode=x;"undefined"!==typeof module?module.exports=A:window.m=A})();
|
||||
(function(){function t(a,d,e,h,p,l){return{tag:a,key:d,attrs:e,children:h,text:p,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function Q(a){for(var d in a)if(G.call(a,d))return!1;return!0}function x(a){var d=arguments[1],e=2;if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a){var h;if(!(h=R[a])){var p="div";for(var l=[],k={};h=V.exec(a);){var q=h[1],
|
||||
r=h[2];""===q&&""!==r?p=r:"#"===q?k.id=r:"."===q?l.push(r):"["===h[3][0]&&((q=h[6])&&(q=q.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===h[4]?l.push(q):k[h[4]]=""===q?q:q||!0)}0<l.length&&(k.className=l.join(" "));h=R[a]={tag:p,attrs:k}}}if(null==d)d={};else if("object"!==typeof d||null!=d.tag||Array.isArray(d))d={},e=1;if(arguments.length===e+1)p=arguments[e],Array.isArray(p)||(p=[p]);else for(p=[];e<arguments.length;)p.push(arguments[e++]);e=t.normalizeChildren(p);if("string"===typeof a){p=
|
||||
!1;var m,u;l=d.className||d["class"];if(!Q(h.attrs)&&!Q(d)){k={};for(var c in d)G.call(d,c)&&(k[c]=d[c]);d=k}for(c in h.attrs)G.call(h.attrs,c)&&(d[c]=h.attrs[c]);void 0!==l&&(void 0!==d["class"]&&(d["class"]=void 0,d.className=l),null!=h.attrs.className&&(d.className=h.attrs.className+" "+l));for(c in d)if(G.call(d,c)&&"key"!==c){p=!0;break}Array.isArray(e)&&1===e.length&&null!=e[0]&&"#"===e[0].tag?u=e[0].children:m=e;return t(h.tag,d.key,p?d:void 0,m,u)}return t(a,d.key,d,e)}function W(a){var d=
|
||||
0,e=null,h="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var p=Date.now()-d;null===e&&(e=h(function(){e=null;a();d=Date.now()},16-p))}}t.normalize=function(a){return Array.isArray(a)?t("[",void 0,void 0,t.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?t("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};t.normalizeChildren=function(a){for(var d=0;d<a.length;d++)a[d]=t.normalize(a[d]);return a};var V=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
|
||||
R={},G={}.hasOwnProperty;x.trust=function(a){null==a&&(a="");return t("<",void 0,void 0,a,void 0,void 0)};x.fragment=function(a,d){return t("[",a.key,a,t.normalizeChildren(d),void 0,void 0)};var B=function(a){function d(a,c){return function y(d){var A;try{if(!c||null==d||"object"!==typeof d&&"function"!==typeof d||"function"!==typeof(A=d.then))m(function(){c||0!==a.length||console.error("Possible unhandled promise rejection:",d);for(var e=0;e<a.length;e++)a[e](d);p.length=0;l.length=0;r.state=c;r.retry=
|
||||
function(){y(d)}});else{if(d===h)throw new TypeError("Promise can't be resolved w/ itself");e(A.bind(d))}}catch(Y){q(Y)}}}function e(a){function c(c){return function(a){0<d++||c(a)}}var d=0,r=c(q);try{a(c(k),r)}catch(y){r(y)}}if(!(this instanceof B))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var h=this,p=[],l=[],k=d(p,!0),q=d(l,!1),r=h._instance={resolvers:p,rejectors:l},m="function"===typeof setImmediate?setImmediate:
|
||||
setTimeout;e(a)};B.prototype.then=function(a,d){function e(a,d,e,k){d.push(function(c){if("function"!==typeof a)e(c);else try{p(a(c))}catch(C){l&&l(C)}});"function"===typeof h.retry&&k===h.state&&h.retry()}var h=this._instance,p,l,k=new B(function(a,d){p=a;l=d});e(a,h.resolvers,p,!0);e(d,h.rejectors,l,!1);return k};B.prototype["catch"]=function(a){return this.then(null,a)};B.resolve=function(a){return a instanceof B?a:new B(function(d){d(a)})};B.reject=function(a){return new B(function(d,e){e(a)})};
|
||||
B.all=function(a){return new B(function(d,e){var h=a.length,p=0,l=[];if(0===a.length)d([]);else for(var k=0;k<a.length;k++)(function(k){function r(a){p++;l[k]=a;p===h&&d(l)}null==a[k]||"object"!==typeof a[k]&&"function"!==typeof a[k]||"function"!==typeof a[k].then?r(a[k]):a[k].then(r,e)})(k)})};B.race=function(a){return new B(function(d,e){for(var h=0;h<a.length;h++)a[h].then(d,e)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=B),B=window.Promise):"undefined"!==
|
||||
typeof global&&("undefined"===typeof global.Promise&&(global.Promise=B),B=global.Promise);var F=function(a){function d(a,h){if(Array.isArray(h))for(var k=0;k<h.length;k++)d(a+"["+k+"]",h[k]);else if("[object Object]"===Object.prototype.toString.call(h))for(k in h)d(a+"["+k+"]",h[k]);else e.push(encodeURIComponent(a)+(null!=h&&""!==h?"="+encodeURIComponent(h):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var e=[],h;for(h in a)d(h,a[h]);return e.join("&")},Z=/^file:\/\//i,O=
|
||||
function(a,d){function e(){function c(){0===--a&&"function"===typeof u&&u()}var a=0;return function X(d){var e=d.then;d.then=function(){a++;var r=e.apply(d,arguments);r.then(c,function(d){c();if(0===a)throw d;});return X(r)};return d}}function h(c,a){if("string"===typeof c){var d=c;c=a||{};null==c.url&&(c.url=d)}return c}function p(c,a){if(null==a)return c;for(var d=c.match(/:[^\/]+/gi)||[],e=0;e<d.length;e++){var r=d[e].slice(1);null!=a[r]&&(c=c.replace(d[e],a[r]))}return c}function l(c,a){var d=
|
||||
F(a);if(""!==d){var e=0>c.indexOf("?")?"?":"&";c+=e+d}return c}function k(c){try{return""!==c?JSON.parse(c):null}catch(C){throw Error(c);}}function q(c){return c.responseText}function r(c,a){if("function"===typeof c)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new c(a[d]);else return new c(a);return a}var m=0,u;return{request:function(c,m){var A=e();c=h(c,m);var C=new d(function(d,e){null==c.method&&(c.method="GET");c.method=c.method.toUpperCase();var h="GET"===c.method||"TRACE"===c.method?
|
||||
!1:"boolean"===typeof c.useBody?c.useBody:!0;"function"!==typeof c.serialize&&(c.serialize="undefined"!==typeof FormData&&c.data instanceof FormData?function(c){return c}:JSON.stringify);"function"!==typeof c.deserialize&&(c.deserialize=k);"function"!==typeof c.extract&&(c.extract=q);c.url=p(c.url,c.data);h?c.data=c.serialize(c.data):c.url=l(c.url,c.data);var m=new a.XMLHttpRequest,A=!1,C=m.abort;m.abort=function(){A=!0;C.call(m)};m.open(c.method,c.url,"boolean"===typeof c.async?c.async:!0,"string"===
|
||||
typeof c.user?c.user:void 0,"string"===typeof c.password?c.password:void 0);c.serialize!==JSON.stringify||!h||c.headers&&c.headers.hasOwnProperty("Content-Type")||m.setRequestHeader("Content-Type","application/json; charset=utf-8");c.deserialize!==k||c.headers&&c.headers.hasOwnProperty("Accept")||m.setRequestHeader("Accept","application/json, text/*");c.withCredentials&&(m.withCredentials=c.withCredentials);c.timeout&&(m.timeout=c.timeout);for(var u in c.headers)({}).hasOwnProperty.call(c.headers,
|
||||
u)&&m.setRequestHeader(u,c.headers[u]);"function"===typeof c.config&&(m=c.config(m,c)||m);m.onreadystatechange=function(){if(!A&&4===m.readyState)try{var a=c.extract!==q?c.extract(m,c):c.deserialize(c.extract(m,c));if(c.extract!==q||200<=m.status&&300>m.status||304===m.status||Z.test(c.url))d(r(c.type,a));else{var h=Error(m.responseText);h.code=m.status;h.response=a;e(h)}}catch(H){e(H)}};h&&null!=c.data?m.send(c.data):m.send()});return!0===c.background?C:A(C)},jsonp:function(c,k){var A=e();c=h(c,
|
||||
k);var q=new d(function(d,e){var h=c.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=a.document.createElement("script");a[h]=function(e){k.parentNode.removeChild(k);d(r(c.type,e));delete a[h]};k.onerror=function(){k.parentNode.removeChild(k);e(Error("JSONP request failed"));delete a[h]};null==c.data&&(c.data={});c.url=p(c.url,c.data);c.data[c.callbackKey||"callback"]=h;k.src=l(c.url,c.data);a.document.documentElement.appendChild(k)});return!0===c.background?q:A(q)},setCompletionCallback:function(c){u=
|
||||
c}}}(window,B),U=function(a){function d(g,b){if(g.state!==b)throw Error("`vnode.state` must not be modified");}function e(g){var b=g.state;try{return this.apply(b,arguments)}finally{d(g,b)}}function h(g,b,f,c,a,d,e){for(;f<c;f++){var h=b[f];null!=h&&p(g,h,a,e,d)}}function p(g,b,f,a,d){var e=b.tag;if("string"===typeof e)switch(b.state={},null!=b.attrs&&K(b.attrs,b,f),e){case "#":return b.dom=D.createTextNode(b.children),c(g,b.dom,d),b.dom;case "<":return l(g,b,d);case "[":var r=D.createDocumentFragment();
|
||||
null!=b.children&&(e=b.children,h(r,e,0,e.length,f,null,a));b.dom=r.firstChild;b.domSize=r.childNodes.length;c(g,r,d);return r;default:var n=b.tag,m=(e=b.attrs)&&e.is;n=(a=b.attrs&&b.attrs.xmlns||G[b.tag]||a)?m?D.createElementNS(a,n,{is:m}):D.createElementNS(a,n):m?D.createElement(n,{is:m}):D.createElement(n);b.dom=n;if(null!=e)for(r in m=a,e)J(b,r,null,e[r],m);c(g,n,d);null!=b.attrs&&null!=b.attrs.contenteditable?C(b):(null!=b.text&&(""!==b.text?n.textContent=b.text:b.children=[t("#",void 0,void 0,
|
||||
b.text,void 0,void 0)]),null!=b.children&&(g=b.children,h(n,g,0,g.length,f,null,a),g=b.attrs,"select"===b.tag&&null!=g&&("value"in g&&J(b,"value",null,g.value,void 0),"selectedIndex"in g&&J(b,"selectedIndex",null,g.selectedIndex,void 0))));return n}else return k(b,f),null!=b.instance?(f=p(g,b.instance,f,a,d),b.dom=b.instance.dom,b.domSize=null!=b.dom?b.instance.domSize:0,c(g,f,d),b=f):(b.domSize=0,b=H),b}function l(g,b,f){var a={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",
|
||||
th:"tr",td:"tr",colgroup:"table",col:"colgroup"}[(b.children.match(/^\s*?<(\w+)/im)||[])[1]]||"div";a=D.createElement(a);a.innerHTML=b.children;b.dom=a.firstChild;b.domSize=a.childNodes.length;b=D.createDocumentFragment();for(var d;d=a.firstChild;)b.appendChild(d);c(g,b,f);return b}function k(g,b){if("function"===typeof g.tag.view){g.state=Object.create(g.tag);var f=g.state.view;if(null!=f.$$reentrantLock$$)return H;f.$$reentrantLock$$=!0}else{g.state=void 0;f=g.tag;if(null!=f.$$reentrantLock$$)return H;
|
||||
f.$$reentrantLock$$=!0;g.state=null!=g.tag.prototype&&"function"===typeof g.tag.prototype.view?new g.tag(g):g.tag(g)}null!=g.attrs&&K(g.attrs,g,b);K(g.state,g,b);g.instance=t.normalize(e.call(g.state.view,g));if(g.instance===g)throw Error("A view cannot return the vnode it received as argument");f.$$reentrantLock$$=null}function q(g,b,f,a,d,e,k){if(!(b===f&&!a||null==b&&null==f))if(null==b)h(g,f,0,f.length,d,e,k);else if(null==f)A(b,0,b.length,f,a);else{for(var n=0,l=Math.min(b.length,f.length),q=
|
||||
b.length,C=!1,E=!1;n<l;n++)if(null!=b[n]&&null!=f[n]){null==b[n].key&&null==f[n].key&&(E=!0);break}if(E&&q===f.length)for(n=0;n<q;n++)b[n]===f[n]&&!a||null==b[n]&&null==f[n]||(null==b[n]?p(g,f[n],d,k,u(b,n+1,q,e)):null==f[n]?A(b,n,n+1,f,a):r(g,b[n],f[n],d,u(b,n+1,q,e),a,k));else{a:{if(null!=b.pool&&Math.abs(b.pool.length-f.length)<=Math.abs(b.length-f.length)&&(n=f[0]&&f[0].children&&f[0].children.length||0,Math.abs((b.pool[0]&&b.pool[0].children&&b.pool[0].children.length||0)-n)<=Math.abs((b[0]&&
|
||||
b[0].children&&b[0].children.length||0)-n))){n=!0;break a}n=!1}n&&(C=!0,b=b.concat(b.pool));var v=n=0;l=b.length-1;for(var t=f.length-1,I,w,z,y;l>=v&&t>=n;)if(w=b[v],z=f[n],y=C&&v>=q,w===z&&!y&&!a||null==w&&null==z)v++,n++;else if(null==w)(E||null==z.key)&&p(g,f[n],d,k,u(b,++n,q,e)),v++;else if(null==z){if(E||null==w.key)A(b,n,n+1,f,a),v++;n++}else if(w.key===z.key)v++,n++,r(g,w,z,d,u(b,v,q,e),y||a,k),y&&w.tag===z.tag&&c(g,m(z),e);else if(w=b[l],y=C&&l>=q,w!==z||y||a)if(null==w)l--;else if(null==
|
||||
z)n++;else if(w.key===z.key)r(g,w,z,d,u(b,l+1,q,e),y||a,k),(y&&w.tag===z.tag||n<t)&&c(g,m(z),u(b,v,q,e)),l--,n++;else break;else l--,n++;for(;l>=v&&t>=n;){w=b[l];z=f[t];y=C&&l>=q;if(w!==z||y||a)if(null==w)l--;else{if(null!=z)if(w.key===z.key)r(g,w,z,d,u(b,l+1,q,e),y||a,k),y&&w.tag===z.tag&&c(g,m(z),e),null!=w.dom&&(e=w.dom),l--;else{if(!I){I=b;E=l;w={};for(y=0;y<E;y++){var x=I[y];null!=x&&(x=x.key,null!=x&&(w[x]=y))}I=w}null!=z&&(E=I[z.key],null!=E?(w=b[E],y=C&&E>=q,r(g,w,z,d,u(b,l+1,q,e),y||a,k),
|
||||
c(g,m(z),e),w.skip=!0,null!=w.dom&&(e=w.dom)):e=p(g,z,d,k,e))}t--}else l--,t--;if(t<n)break}h(g,f,n,t+1,d,e,k);A(b,v,Math.min(l+1,q),f,a);if(C)for(g=Math.max(v,q);l>=g;l--)b[l].skip?b[l].skip=!1:B(b[l],f)}}}function r(g,b,f,a,c,d,h){var n=b.tag;if(n===f.tag){f.state=b.state;f.events=b.events;var A;if(A=!d){var u,E;null!=f.attrs&&"function"===typeof f.attrs.onbeforeupdate&&(u=e.call(f.attrs.onbeforeupdate,f,b));"string"!==typeof f.tag&&"function"===typeof f.state.onbeforeupdate&&(E=e.call(f.state.onbeforeupdate,
|
||||
f,b));void 0===u&&void 0===E||u||E?A=!1:(f.dom=b.dom,f.domSize=b.domSize,f.instance=b.instance,A=!0)}if(!A)if("string"===typeof n)switch(null!=f.attrs&&(d?(f.state={},K(f.attrs,f,a)):M(f.attrs,f,a)),n){case "#":b.children.toString()!==f.children.toString()&&(b.dom.nodeValue=f.children);f.dom=b.dom;break;case "<":b.children!==f.children?(m(b),l(g,f,c)):(f.dom=b.dom,f.domSize=b.domSize);break;case "[":q(g,b.children,f.children,d,a,c,h);b=0;a=f.children;f.dom=null;if(null!=a){for(d=0;d<a.length;d++){var v=
|
||||
a[d];null!=v&&null!=v.dom&&(null==f.dom&&(f.dom=v.dom),b+=v.domSize||1)}1!==b&&(f.domSize=b)}break;default:g=f.dom=b.dom;h=f.attrs&&f.attrs.xmlns||G[f.tag]||h;"textarea"===f.tag&&(null==f.attrs&&(f.attrs={}),null!=f.text&&(f.attrs.value=f.text,f.text=void 0));c=b.attrs;n=f.attrs;A=h;if(null!=n)for(v in n)J(f,v,c&&c[v],n[v],A);if(null!=c)for(v in c)null!=n&&v in n||("className"===v&&(v="class"),"o"!==v[0]||"n"!==v[1]||S(v)?"key"!==v&&f.dom.removeAttribute(v):T(f,v,void 0));null!=f.attrs&&null!=f.attrs.contenteditable?
|
||||
C(f):null!=b.text&&null!=f.text&&""!==f.text?b.text.toString()!==f.text.toString()&&(b.dom.firstChild.nodeValue=f.text):(null!=b.text&&(b.children=[t("#",void 0,void 0,b.text,void 0,b.dom.firstChild)]),null!=f.text&&(f.children=[t("#",void 0,void 0,f.text,void 0,void 0)]),q(g,b.children,f.children,d,a,null,h))}else{if(d)k(f,a);else{f.instance=t.normalize(e.call(f.state.view,f));if(f.instance===f)throw Error("A view cannot return the vnode it received as argument");null!=f.attrs&&M(f.attrs,f,a);M(f.state,
|
||||
f,a)}null!=f.instance?(null==b.instance?p(g,f.instance,a,h,c):r(g,b.instance,f.instance,a,c,d,h),f.dom=f.instance.dom,f.domSize=f.instance.domSize):null!=b.instance?(y(b.instance,null,d),f.dom=void 0,f.domSize=0):(f.dom=b.dom,f.domSize=b.domSize)}}else y(b,null,d),p(g,f,a,h,c)}function m(g){var b=g.domSize;if(null!=b||null==g.dom){var a=D.createDocumentFragment();if(0<b){for(g=g.dom;--b;)a.appendChild(g.nextSibling);a.insertBefore(g,a.firstChild)}return a}return g.dom}function u(g,b,a,c){for(;b<a;b++)if(null!=
|
||||
g[b]&&null!=g[b].dom)return g[b].dom;return c}function c(g,b,a){a?g.insertBefore(b,a):g.appendChild(b)}function C(g){var b=g.children;if(null!=b&&1===b.length&&"<"===b[0].tag)b=b[0].children,g.dom.innerHTML!==b&&(g.dom.innerHTML=b);else if(null!=g.text||null!=b&&0!==b.length)throw Error("Child node of a contenteditable must be trusted");}function A(g,b,a,c,d){for(;b<a;b++){var f=g[b];null!=f&&(f.skip?f.skip=!1:y(f,c,d))}}function y(a,b,c){function g(){if(++h===f&&(c||(d(a,r),x(a)),a.dom)){var g=a.domSize||
|
||||
1;if(1<g)for(var e=a.dom;--g;){var n=e.nextSibling,k=n.parentNode;null!=k&&k.removeChild(n)}g=a.dom;e=g.parentNode;null!=e&&e.removeChild(g);B(a,b)}}var f=1,h=0;if(!c){var r=a.state;if(a.attrs&&"function"===typeof a.attrs.onbeforeremove){var k=e.call(a.attrs.onbeforeremove,a);null!=k&&"function"===typeof k.then&&(f++,k.then(g,g))}"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeremove&&(k=e.call(a.state.onbeforeremove,a),null!=k&&"function"===typeof k.then&&(f++,k.then(g,g)))}g()}function B(a,
|
||||
b){var c;if(c=null!=b&&null==a.domSize)c=a.attrs,c=!(null!=c&&(c.oncreate||c.onupdate||c.onbeforeremove||c.onremove));c&&"string"===typeof a.tag&&(b.pool?b.pool.push(a):b.pool=[a])}function x(a){a.attrs&&"function"===typeof a.attrs.onremove&&e.call(a.attrs.onremove,a);if("string"!==typeof a.tag)"function"===typeof a.state.onremove&&e.call(a.state.onremove,a),null!=a.instance&&x(a.instance);else if(a=a.children,Array.isArray(a))for(var b=0;b<a.length;b++){var c=a[b];null!=c&&x(c)}}function J(a,b,c,
|
||||
d,e){if("key"!==b&&"is"!==b&&!S(b)){if("o"===b[0]&&"n"===b[1])return T(a,b,d);if((c!==d||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===D.activeElement||a.dom.parentNode===D.activeElement||"object"===typeof d)&&void 0!==d){var f=a.dom;if("xlink:"===b.slice(0,6))f.setAttributeNS("http://www.w3.org/1999/xlink",b,d);else if("style"===b)if(a=c,null!=a&&null!=d&&"object"===typeof a&&"object"===typeof d&&d!==a){for(var g in d)d[g]!==a[g]&&(f.style[g]=d[g]);for(g in a)g in d||(f.style[g]=
|
||||
"")}else if(a===d&&(f.style.cssText="",a=null),null==d)f.style.cssText="";else if("string"===typeof d)f.style.cssText=d;else for(g in"string"===typeof a&&(f.style.cssText=""),d)f.style[g]=d[g];else if(b in f&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===e&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===b){g=""+d;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===g&&a.dom===D.activeElement)return;if("select"===a.tag)if(null===d){if(-1===a.dom.selectedIndex&&a.dom===
|
||||
D.activeElement)return}else if(null!==c&&a.dom.value===g&&a.dom===D.activeElement)return;if("option"===a.tag&&null!=c&&a.dom.value===g)return}"input"===a.tag&&"type"===b?f.setAttribute(b,d):f[b]=d}else"boolean"===typeof d?d?f.setAttribute(b,""):f.removeAttribute(b):f.setAttribute("className"===b?"class":b,d)}}}function S(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function N(){}function T(a,b,c){null!=a.events?a.events[b]!==c&&
|
||||
(null==c||"function"!==typeof c&&"object"!==typeof c?(null!=a.events[b]&&a.dom.removeEventListener(b.slice(2),a.events,!1),a.events[b]=void 0):(null==a.events[b]&&a.dom.addEventListener(b.slice(2),a.events,!1),a.events[b]=c)):null==c||"function"!==typeof c&&"object"!==typeof c||(a.events=new N,a.dom.addEventListener(b.slice(2),a.events,!1),a.events[b]=c)}function K(a,b,c){"function"===typeof a.oninit&&e.call(a.oninit,b);"function"===typeof a.oncreate&&c.push(e.bind(a.oncreate,b))}function M(a,b,c){"function"===
|
||||
typeof a.onupdate&&c.push(e.bind(a.onupdate,b))}var D=a.document,H=D.createDocumentFragment(),G={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},F;N.prototype=Object.create(null);N.prototype.handleEvent=function(a){var b=this["on"+a.type];"function"===typeof b?b.call(a.target,a):"function"===typeof b.handleEvent&&b.handleEvent(a);"function"===typeof F&&F.call(a.target,a)};return{render:function(a,b){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");
|
||||
var c=[],d=D.activeElement,e=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);q(a,a.vnodes,t.normalizeChildren(b),!1,c,null,"http://www.w3.org/1999/xhtml"===e?void 0:e);a.vnodes=b;null!=d&&D.activeElement!==d&&d.focus();for(d=0;d<c.length;d++)c[d]()},setEventCallback:function(a){return F=a}}},L=function(a,d){function e(a){a=l.indexOf(a);-1<a&&l.splice(a,2)}function h(){if(k)throw Error("Nested m.redraw.sync() call");k=!0;for(var a=1;a<l.length;a+=2)try{l[a]()}catch(m){"undefined"!==
|
||||
typeof console&&console.error(m)}k=!1}var p=U(a);p.setEventCallback(function(a){!1===a.redraw?a.redraw=void 0:q()});var l=[],k=!1,q=(d||W)(h);q.sync=h;return{subscribe:function(a,d){e(a);l.push(a,d)},unsubscribe:e,redraw:q,render:p.render}}(window);O.setCompletionCallback(L.redraw);x.mount=function(a){return function(d,e){if(null===e)a.render(d,[]),a.unsubscribe(d);else{if(null==e.view&&"function"!==typeof e)throw Error("m.mount(element, component) expects a component, not a vnode");var h=function(){a.render(d,
|
||||
t(e))};a.subscribe(d,h);h()}}}(L);var aa=B,P=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var d={},e={},h=0;h<a.length;h++){var p=a[h].split("="),l=decodeURIComponent(p[0]);p=2===p.length?decodeURIComponent(p[1]):"";"true"===p?p=!0:"false"===p&&(p=!1);var k=l.split(/\]\[?|\[/),q=d;-1<l.indexOf("[")&&k.pop();for(var r=0;r<k.length;r++){l=k[r];var m=k[r+1];m=""==m||!isNaN(parseInt(m,10));var u=r===k.length-1;""===l&&(l=k.slice(0,r).join(),null==e[l]&&
|
||||
(e[l]=0),l=e[l]++);null==q[l]&&(q[l]=u?p:m?[]:{});q=q[l]}}return d},ba=function(a){function d(d){var e=a.location[d].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===d&&"/"!==e[0]&&(e="/"+e);return e}function e(a){return function(){null==k&&(k=l(function(){k=null;a()}))}}function h(a,d,e){var c=a.indexOf("?"),h=a.indexOf("#"),k=-1<c?c:-1<h?h:a.length;if(-1<c){c=P(a.slice(c+1,-1<h?h:a.length));for(var l in c)d[l]=c[l]}if(-1<h)for(l in d=P(a.slice(h+1)),d)e[l]=d[l];return a.slice(0,
|
||||
k)}var p="function"===typeof a.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,k,q={prefix:"#!",getPath:function(){switch(q.prefix.charAt(0)){case "#":return d("hash").slice(q.prefix.length);case "?":return d("search").slice(q.prefix.length)+d("hash");default:return d("pathname").slice(q.prefix.length)+d("search")+d("hash")}},setPath:function(d,e,k){var c={},l={};d=h(d,c,l);if(null!=e){for(var m in e)c[m]=e[m];d=d.replace(/:([^\/]+)/g,function(a,d){delete c[d];return e[d]})}(m=
|
||||
F(c))&&(d+="?"+m);(l=F(l))&&(d+="#"+l);p?(l=k?k.state:null,m=k?k.title:null,a.onpopstate(),k&&k.replace?a.history.replaceState(l,m,q.prefix+d):a.history.pushState(l,m,q.prefix+d)):a.location.href=q.prefix+d},defineRoutes:function(d,k,l){function c(){var c=q.getPath(),e={},m=h(c,e,e),p=a.history.state;if(null!=p)for(var r in p)e[r]=p[r];for(var t in d)if(p=new RegExp("^"+t.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),p.test(m)){m.replace(p,function(){for(var a=t.match(/:[^\/]+/g)||
|
||||
[],h=[].slice.call(arguments,1,-2),l=0;l<a.length;l++)e[a[l].replace(/:|\./g,"")]=decodeURIComponent(h[l]);k(d[t],e,c,t)});return}l(c,e)}p?a.onpopstate=e(c):"#"===q.prefix.charAt(0)&&(a.onhashchange=c);c()}};return q};x.route=function(a,d){var e=ba(a),h=function(a){return a},p,l,k,q,r,m=function(a,m,A){function c(){null!=p&&d.render(a,p(t(l,k.key,k)))}if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var u=function(){c();u=d.redraw};d.subscribe(a,c);var x=
|
||||
function(a){if(a!==m)e.setPath(m,null,{replace:!0});else throw Error("Could not resolve default route "+m);};e.defineRoutes(A,function(a,c,d){var e=r=function(a,m){e===r&&(l=null==m||"function"!==typeof m.view&&"function"!==typeof m?"div":m,k=c,q=d,r=null,p=(a.render||h).bind(a),u())};a.view||"function"===typeof a?e({},a):a.onmatch?aa.resolve(a.onmatch(c,d)).then(function(c){e(a,c)},x):e(a,"div")},x)};m.set=function(a,d,h){null!=r&&(h=h||{},h.replace=!0);r=null;e.setPath(a,d,h)};m.get=function(){return q};
|
||||
m.prefix=function(a){e.prefix=a};var u=function(a,d){d.dom.setAttribute("href",e.prefix+d.attrs.href);d.dom.onclick=function(c){c.ctrlKey||c.metaKey||c.shiftKey||2===c.which||(c.preventDefault(),c.redraw=!1,c=this.getAttribute("href"),0===c.indexOf(e.prefix)&&(c=c.slice(e.prefix.length)),m.set(c,void 0,a))}};m.link=function(a){return null==a.tag?u.bind(u,a):u({},a)};m.param=function(a){return"undefined"!==typeof k&&"undefined"!==typeof a?k[a]:k};return m}(window,L);x.withAttr=function(a,d,e){return function(h){d.call(e||
|
||||
this,a in h.currentTarget?h.currentTarget[a]:h.currentTarget.getAttribute(a))}};var ca=U(window);x.render=ca.render;x.redraw=L.redraw;x.request=O.request;x.jsonp=O.jsonp;x.parseQueryString=P;x.buildQueryString=F;x.version="1.1.3";x.vnode=t;"undefined"!==typeof module?module.exports=x:window.m=x})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue