Bundled output for commit 203df39c30 [skip ci]
This commit is contained in:
parent
203df39c30
commit
ec43ca089c
3 changed files with 109 additions and 204 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.74 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.34 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 👍.
|
||||
|
||||
|
|
|
|||
219
mithril.js
219
mithril.js
|
|
@ -570,8 +570,6 @@ var coreRenderer = function($window) {
|
|||
* @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
|
||||
|
|
@ -585,8 +583,7 @@ var coreRenderer = function($window) {
|
|||
//
|
||||
// 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.
|
||||
// 3. discuss DOM node operations.
|
||||
// ## Overview:
|
||||
//
|
||||
// The updateNodes() function:
|
||||
|
|
@ -599,17 +596,13 @@ var coreRenderer = function($window) {
|
|||
// - 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.
|
||||
// There's first a simple diff for unkeyed lists of equal length.
|
||||
//
|
||||
// Then comes the main diff algorithm that is split in four parts (simplifying a bit).
|
||||
//
|
||||
|
|
@ -637,103 +630,66 @@ var coreRenderer = function($window) {
|
|||
// 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).
|
||||
// this is not the case if the node moved (second and fourth part of the diff algo).
|
||||
//
|
||||
// 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
|
||||
function updateNodes(parent, old, vnodes, hooks, nextSibling, ns) {
|
||||
if (old === vnodes || 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, recyclingParent)
|
||||
else if (vnodes == null) removeNodes(old, 0, old.length)
|
||||
else {
|
||||
var start = 0, commonLength = Math.min(old.length, vnodes.length), originalOldLength = old.length, hasPool = false, isUnkeyed = false
|
||||
var start = 0, commonLength = Math.min(old.length, vnodes.length), 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
|
||||
}
|
||||
}
|
||||
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)
|
||||
if (isUnkeyed && old.length === vnodes.length) {
|
||||
for (start = 0; start < vnodes.length; start++) {
|
||||
if (old[start] === vnodes[start] || old[start] == null && vnodes[start] == null) continue
|
||||
else if (old[start] == null) createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, start + 1, nextSibling))
|
||||
else if (vnodes[start] == null) removeNodes(old, start, start + 1)
|
||||
else updateNode(parent, old[start], vnodes[start], hooks, getNextSibling(old, start + 1, nextSibling), ns)
|
||||
}
|
||||
return
|
||||
}
|
||||
if (isRecyclable(old, vnodes)) {
|
||||
hasPool = true
|
||||
old = old.concat(old.pool)
|
||||
}
|
||||
var oldStart = start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map, o, v, oFromPool
|
||||
var oldStart = start = 0, oldEnd = old.length - 1, end = vnodes.length - 1, map, o, v
|
||||
while (oldEnd >= oldStart && end >= start) {
|
||||
o = old[oldStart]
|
||||
v = vnodes[start]
|
||||
oFromPool = hasPool && oldStart >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent || o == null && v == null) oldStart++, start++
|
||||
if (o === v || 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))
|
||||
createNode(parent, vnodes[start], hooks, ns, getNextSibling(old, ++start, nextSibling))
|
||||
}
|
||||
oldStart++
|
||||
} else if (v == null) {
|
||||
if (isUnkeyed || o.key == null) {
|
||||
removeNodes(old, start, start + 1, vnodes, recyclingParent)
|
||||
removeNodes(old, start, start + 1)
|
||||
oldStart++
|
||||
}
|
||||
start++
|
||||
} else if (o.key === v.key) {
|
||||
oldStart++, 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)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldStart, nextSibling), ns)
|
||||
} else {
|
||||
o = old[oldEnd]
|
||||
oFromPool = hasPool && oldEnd >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent) oldEnd--, start++
|
||||
if (o === v) oldEnd--, start++
|
||||
else if (o == null) oldEnd--
|
||||
else if (v == null) start++
|
||||
else if (o.key === v.key) {
|
||||
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))
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), ns)
|
||||
if (start < end) insertNode(parent, toFragment(v), getNextSibling(old, oldStart, nextSibling))
|
||||
oldEnd--, start++
|
||||
}
|
||||
else break
|
||||
|
|
@ -742,13 +698,11 @@ var coreRenderer = function($window) {
|
|||
while (oldEnd >= oldStart && end >= start) {
|
||||
o = old[oldEnd]
|
||||
v = vnodes[end]
|
||||
oFromPool = hasPool && oldEnd >= originalOldLength
|
||||
if (o === v && !oFromPool && !recyclingParent) oldEnd--, end--
|
||||
if (o === v) oldEnd--, end--
|
||||
else if (o == null) oldEnd--
|
||||
else if (v == null) end--
|
||||
else if (o.key === v.key) {
|
||||
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)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), ns)
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
oldEnd--, end--
|
||||
} else {
|
||||
|
|
@ -757,8 +711,7 @@ var coreRenderer = function($window) {
|
|||
var oldIndex = map[v.key]
|
||||
if (oldIndex != null) {
|
||||
o = old[oldIndex]
|
||||
oFromPool = hasPool && oldIndex >= originalOldLength
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, originalOldLength, nextSibling), oFromPool || recyclingParent, ns)
|
||||
updateNode(parent, o, v, hooks, getNextSibling(old, oldEnd + 1, nextSibling), ns)
|
||||
insertNode(parent, toFragment(v), nextSibling)
|
||||
o.skip = true
|
||||
if (o.dom != null) nextSibling = o.dom
|
||||
|
|
@ -772,43 +725,30 @@ var coreRenderer = function($window) {
|
|||
if (end < start) break
|
||||
}
|
||||
createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns)
|
||||
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)
|
||||
}
|
||||
}
|
||||
removeNodes(old, oldStart, oldEnd + 1)
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
function updateNode(parent, old, vnode, hooks, nextSibling, ns) {
|
||||
var oldTag = old.tag, tag = vnode.tag
|
||||
if (oldTag === tag) {
|
||||
vnode.state = old.state
|
||||
vnode.events = old.events
|
||||
if (!recycling && shouldNotUpdate(vnode, old)) return
|
||||
if (shouldNotUpdate(vnode, old)) return
|
||||
if (typeof oldTag === "string") {
|
||||
if (vnode.attrs != null) {
|
||||
if (recycling) {
|
||||
vnode.state = {}
|
||||
initLifecycle(vnode.attrs, vnode, hooks)
|
||||
}
|
||||
else updateLifecycle(vnode.attrs, vnode, hooks)
|
||||
updateLifecycle(vnode.attrs, vnode, hooks)
|
||||
}
|
||||
switch (oldTag) {
|
||||
case "#": updateText(old, vnode); break
|
||||
case "<": updateHTML(parent, old, vnode, ns, nextSibling); break
|
||||
case "[": updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns); break
|
||||
default: updateElement(old, vnode, recycling, hooks, ns)
|
||||
case "[": updateFragment(parent, old, vnode, hooks, nextSibling, ns); break
|
||||
default: updateElement(old, vnode, hooks, ns)
|
||||
}
|
||||
}
|
||||
else updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns)
|
||||
else updateComponent(parent, old, vnode, hooks, nextSibling, ns)
|
||||
}
|
||||
else {
|
||||
removeNode(old, null, recycling)
|
||||
removeNode(old)
|
||||
createNode(parent, vnode, hooks, ns, nextSibling)
|
||||
}
|
||||
}
|
||||
|
|
@ -825,8 +765,8 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
else vnode.dom = old.dom, vnode.domSize = old.domSize
|
||||
}
|
||||
function updateFragment(parent, old, vnode, recycling, hooks, nextSibling, ns) {
|
||||
updateNodes(parent, old.children, vnode.children, recycling, hooks, nextSibling, ns)
|
||||
function updateFragment(parent, old, vnode, hooks, nextSibling, ns) {
|
||||
updateNodes(parent, old.children, vnode.children, hooks, nextSibling, ns)
|
||||
var domSize = 0, children = vnode.children
|
||||
vnode.dom = null
|
||||
if (children != null) {
|
||||
|
|
@ -840,7 +780,7 @@ var coreRenderer = function($window) {
|
|||
if (domSize !== 1) vnode.domSize = domSize
|
||||
}
|
||||
}
|
||||
function updateElement(old, vnode, recycling, hooks, ns) {
|
||||
function updateElement(old, vnode, hooks, ns) {
|
||||
var element = vnode.dom = old.dom
|
||||
ns = getNameSpace(vnode) || ns
|
||||
if (vnode.tag === "textarea") {
|
||||
|
|
@ -860,26 +800,22 @@ var coreRenderer = function($window) {
|
|||
else {
|
||||
if (old.text != null) old.children = [Vnode("#", undefined, undefined, old.text, undefined, old.dom.firstChild)]
|
||||
if (vnode.text != null) vnode.children = [Vnode("#", undefined, undefined, vnode.text, undefined, undefined)]
|
||||
updateNodes(element, old.children, vnode.children, recycling, hooks, null, ns)
|
||||
updateNodes(element, old.children, vnode.children, hooks, null, ns)
|
||||
}
|
||||
}
|
||||
function updateComponent(parent, old, vnode, hooks, nextSibling, recycling, ns) {
|
||||
if (recycling) {
|
||||
initComponent(vnode, hooks)
|
||||
} else {
|
||||
vnode.instance = Vnode.normalize(callHook.call(vnode.state.view, vnode))
|
||||
if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
|
||||
if (vnode.attrs != null) updateLifecycle(vnode.attrs, vnode, hooks)
|
||||
updateLifecycle(vnode.state, vnode, hooks)
|
||||
}
|
||||
function updateComponent(parent, old, vnode, hooks, nextSibling, ns) {
|
||||
vnode.instance = Vnode.normalize(callHook.call(vnode.state.view, vnode))
|
||||
if (vnode.instance === vnode) throw Error("A view cannot return the vnode it received as argument")
|
||||
if (vnode.attrs != null) updateLifecycle(vnode.attrs, vnode, hooks)
|
||||
updateLifecycle(vnode.state, vnode, hooks)
|
||||
if (vnode.instance != null) {
|
||||
if (old.instance == null) createNode(parent, vnode.instance, hooks, ns, nextSibling)
|
||||
else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, recycling, ns)
|
||||
else updateNode(parent, old.instance, vnode.instance, hooks, nextSibling, ns)
|
||||
vnode.dom = vnode.instance.dom
|
||||
vnode.domSize = vnode.instance.domSize
|
||||
}
|
||||
else if (old.instance != null) {
|
||||
removeNode(old.instance, null, recycling)
|
||||
removeNode(old.instance)
|
||||
vnode.dom = undefined
|
||||
vnode.domSize = 0
|
||||
}
|
||||
|
|
@ -888,17 +824,6 @@ var coreRenderer = function($window) {
|
|||
vnode.domSize = old.domSize
|
||||
}
|
||||
}
|
||||
function isRecyclable(old, vnodes) {
|
||||
if (old.pool != null && Math.abs(old.pool.length - vnodes.length) <= Math.abs(old.length - vnodes.length)) {
|
||||
var oldChildrenLength = old[0] && old[0].children && old[0].children.length || 0
|
||||
var poolChildrenLength = old.pool[0] && old.pool[0].children && old.pool[0].children.length || 0
|
||||
var vnodesChildrenLength = vnodes[0] && vnodes[0].children && vnodes[0].children.length || 0
|
||||
if (Math.abs(poolChildrenLength - vnodesChildrenLength) <= Math.abs(oldChildrenLength - vnodesChildrenLength)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
function getKeyMap(vnodes, end) {
|
||||
var map = {}, i = 0
|
||||
for (var i = 0; i < end; i++) {
|
||||
|
|
@ -923,10 +848,8 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
else return vnode.dom
|
||||
}
|
||||
// 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++) {
|
||||
function getNextSibling(vnodes, i, nextSibling) {
|
||||
for (; i < vnodes.length; i++) {
|
||||
if (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom
|
||||
}
|
||||
return nextSibling
|
||||
|
|
@ -944,43 +867,37 @@ 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, recycling) {
|
||||
function removeNodes(vnodes, start, end) {
|
||||
for (var i = start; i < end; i++) {
|
||||
var vnode = vnodes[i]
|
||||
if (vnode != null) {
|
||||
if (vnode.skip) vnode.skip = false
|
||||
else removeNode(vnode, context, recycling)
|
||||
else removeNode(vnode)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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) {
|
||||
function removeNode(vnode) {
|
||||
var expected = 1, called = 0
|
||||
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)
|
||||
}
|
||||
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) {
|
||||
if (!recycling) {
|
||||
checkState(vnode, original)
|
||||
onremove(vnode)
|
||||
}
|
||||
checkState(vnode, original)
|
||||
onremove(vnode)
|
||||
if (vnode.dom) {
|
||||
var count0 = vnode.domSize || 1
|
||||
if (count0 > 1) {
|
||||
|
|
@ -990,7 +907,6 @@ var coreRenderer = function($window) {
|
|||
}
|
||||
}
|
||||
removeNodeFromDOM(vnode.dom)
|
||||
addToPool(vnode, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -999,12 +915,6 @@ 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") {
|
||||
|
|
@ -1103,9 +1013,6 @@ var coreRenderer = function($window) {
|
|||
function isCustomElement(vnode){
|
||||
return vnode.attrs.is || vnode.tag.indexOf("-") > -1
|
||||
}
|
||||
function hasIntegrationMethods(source) {
|
||||
return source != null && (source.oncreate || source.onupdate || source.onbeforeremove || source.onremove)
|
||||
}
|
||||
//style
|
||||
function updateStyle(element, old, style) {
|
||||
if (old != null && style != null && typeof old === "object" && typeof style === "object" && style !== old) {
|
||||
|
|
@ -1196,7 +1103,7 @@ var coreRenderer = function($window) {
|
|||
// First time rendering0 into a node clears it out
|
||||
if (dom.vnodes == null) dom.textContent = ""
|
||||
if (!Array.isArray(vnodes)) vnodes = [vnodes]
|
||||
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
|
||||
updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace)
|
||||
dom.vnodes = vnodes
|
||||
// document.activeElement can return null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement
|
||||
if (active != null && $doc.activeElement !== active) active.focus()
|
||||
|
|
|
|||
92
mithril.min.js
vendored
92
mithril.min.js
vendored
|
|
@ -1,47 +1,45 @@
|
|||
(function(){function x(b,c,e,h,p,l){return{tag:b,key:c,attrs:e,children:h,text:p,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function R(b){for(var c in b)if(G.call(b,c))return!1;return!0}function w(b){var c=arguments[1],e=2;if(null==b||"string"!==typeof b&&"function"!==typeof b&&"function"!==typeof b.view)throw Error("The selector must be either a string or a component.");if("string"===typeof b){var h;if(!(h=S[b])){var p="div";for(var l=[],k={};h=W.exec(b);){var q=h[1],
|
||||
t=h[2];""===q&&""!==t?p=t:"#"===q?k.id=t:"."===q?l.push(t):"["===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=S[b]={tag:p,attrs:k}}}if(null==c)c={};else if("object"!==typeof c||null!=c.tag||Array.isArray(c))c={},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=x.normalizeChildren(p);if("string"===typeof b){p=
|
||||
!1;var m,A;l=c.className||c["class"];if(!R(h.attrs)&&!R(c)){k={};for(var a in c)G.call(c,a)&&(k[a]=c[a]);c=k}for(a in h.attrs)G.call(h.attrs,a)&&(c[a]=h.attrs[a]);void 0!==l&&(void 0!==c["class"]&&(c["class"]=void 0,c.className=l),null!=h.attrs.className&&(c.className=h.attrs.className+" "+l));for(a in c)if(G.call(c,a)&&"key"!==a){p=!0;break}Array.isArray(e)&&1===e.length&&null!=e[0]&&"#"===e[0].tag?A=e[0].children:m=e;return x(h.tag,c.key,p?c:void 0,m,A)}return x(b,c.key,c,e)}function X(b){var c=
|
||||
0,e=null,h="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var p=Date.now()-c;null===e&&(e=h(function(){e=null;b();c=Date.now()},16-p))}}x.normalize=function(b){return Array.isArray(b)?x("[",void 0,void 0,x.normalizeChildren(b),void 0,void 0):null!=b&&"object"!==typeof b?x("#",void 0,void 0,!1===b?"":b,void 0,void 0):b};x.normalizeChildren=function(b){for(var c=0;c<b.length;c++)b[c]=x.normalize(b[c]);return b};var W=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
|
||||
S={},G={}.hasOwnProperty;w.trust=function(b){null==b&&(b="");return x("<",void 0,void 0,b,void 0,void 0)};w.fragment=function(b,c){return x("[",b.key,b,x.normalizeChildren(c),void 0,void 0)};var r=function(b){function c(b,a){return function M(c){var z;try{if(!a||null==c||"object"!==typeof c&&"function"!==typeof c||"function"!==typeof(z=c.then))m(function(){a||0!==b.length||console.error("Possible unhandled promise rejection:",c);for(var e=0;e<b.length;e++)b[e](c);p.length=0;l.length=0;t.state=a;t.retry=
|
||||
function(){M(c)}});else{if(c===h)throw new TypeError("Promise can't be resolved w/ itself");e(z.bind(c))}}catch(Y){q(Y)}}}function e(b){function a(a){return function(b){0<c++||a(b)}}var c=0,t=a(q);try{b(a(k),t)}catch(M){t(M)}}if(!(this instanceof r))throw Error("Promise must be called with `new`");if("function"!==typeof b)throw new TypeError("executor must be a function");var h=this,p=[],l=[],k=c(p,!0),q=c(l,!1),t=h._instance={resolvers:p,rejectors:l},m="function"===typeof setImmediate?setImmediate:
|
||||
setTimeout;e(b)};r.prototype.then=function(b,c){function e(b,c,e,k){c.push(function(a){if("function"!==typeof b)e(a);else try{p(b(a))}catch(B){l&&l(B)}});"function"===typeof h.retry&&k===h.state&&h.retry()}var h=this._instance,p,l,k=new r(function(b,c){p=b;l=c});e(b,h.resolvers,p,!0);e(c,h.rejectors,l,!1);return k};r.prototype["catch"]=function(b){return this.then(null,b)};r.prototype["finally"]=function(b){return this.then(function(c){return r.resolve(b()).then(function(){return c})},function(c){return r.resolve(b()).then(function(){return r.reject(c)})})};
|
||||
r.resolve=function(b){return b instanceof r?b:new r(function(c){c(b)})};r.reject=function(b){return new r(function(c,e){e(b)})};r.all=function(b){return new r(function(c,e){var h=b.length,p=0,l=[];if(0===b.length)c([]);else for(var k=0;k<b.length;k++)(function(k){function t(b){p++;l[k]=b;p===h&&c(l)}null==b[k]||"object"!==typeof b[k]&&"function"!==typeof b[k]||"function"!==typeof b[k].then?t(b[k]):b[k].then(t,e)})(k)})};r.race=function(b){return new r(function(c,e){for(var h=0;h<b.length;h++)b[h].then(c,
|
||||
e)})};"undefined"!==typeof window?("undefined"===typeof window.Promise?window.Promise=r:window.Promise.prototype["finally"]||(window.Promise.prototype["finally"]=r.prototype["finally"]),r=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise?global.Promise=r:global.Promise.prototype["finally"]||(global.Promise.prototype["finally"]=r.prototype["finally"]),r=global.Promise);var E=function(b){function c(b,h){if(Array.isArray(h))for(var k=0;k<h.length;k++)c(b+"["+k+"]",h[k]);
|
||||
else if("[object Object]"===Object.prototype.toString.call(h))for(k in h)c(b+"["+k+"]",h[k]);else e.push(encodeURIComponent(b)+(null!=h&&""!==h?"="+encodeURIComponent(h):""))}if("[object Object]"!==Object.prototype.toString.call(b))return"";var e=[],h;for(h in b)c(h,b[h]);return e.join("&")},Z=/^file:\/\//i,P=function(b,c){function e(){function a(){0===--b&&"function"===typeof A&&A()}var b=0;return function J(c){var e=c.then;c.then=function(){b++;var t=e.apply(c,arguments);t.then(a,function(c){a();
|
||||
if(0===b)throw c;});return J(t)};return c}}function h(a,b){if("string"===typeof a){var c=a;a=b||{};null==a.url&&(a.url=c)}return a}function p(a,b){if(null==b)return a;for(var c=a.match(/:[^\/]+/gi)||[],e=0;e<c.length;e++){var t=c[e].slice(1);null!=b[t]&&(a=a.replace(c[e],b[t]))}return a}function l(a,b){var c=E(b);if(""!==c){var e=0>a.indexOf("?")?"?":"&";a+=e+c}return a}function k(a){try{return""!==a?JSON.parse(a):null}catch(B){throw Error(a);}}function q(a){return a.responseText}function t(a,b){if("function"===
|
||||
typeof a)if(Array.isArray(b))for(var c=0;c<b.length;c++)b[c]=new a(b[c]);else return new a(b);return b}var m=0,A;return{request:function(a,m){var z=e();a=h(a,m);var B=new c(function(c,e){null==a.method&&(a.method="GET");a.method=a.method.toUpperCase();var h="GET"===a.method||"TRACE"===a.method?!1:"boolean"===typeof a.useBody?a.useBody:!0;"function"!==typeof a.serialize&&(a.serialize="undefined"!==typeof FormData&&a.data instanceof FormData?function(a){return a}:JSON.stringify);"function"!==typeof a.deserialize&&
|
||||
(a.deserialize=k);"function"!==typeof a.extract&&(a.extract=q);a.url=p(a.url,a.data);h?a.data=a.serialize(a.data):a.url=l(a.url,a.data);var m=new b.XMLHttpRequest,z=!1,B=m.abort;m.abort=function(){z=!0;B.call(m)};m.open(a.method,a.url,"boolean"===typeof a.async?a.async:!0,"string"===typeof a.user?a.user:void 0,"string"===typeof a.password?a.password:void 0);a.serialize!==JSON.stringify||!h||a.headers&&a.headers.hasOwnProperty("Content-Type")||m.setRequestHeader("Content-Type","application/json; charset=utf-8");
|
||||
a.deserialize!==k||a.headers&&a.headers.hasOwnProperty("Accept")||m.setRequestHeader("Accept","application/json, text/*");a.withCredentials&&(m.withCredentials=a.withCredentials);a.timeout&&(m.timeout=a.timeout);for(var A in a.headers)({}).hasOwnProperty.call(a.headers,A)&&m.setRequestHeader(A,a.headers[A]);"function"===typeof a.config&&(m=a.config(m,a)||m);m.onreadystatechange=function(){if(!z&&4===m.readyState)try{var b=a.extract!==q?a.extract(m,a):a.deserialize(a.extract(m,a));if(a.extract!==q||
|
||||
200<=m.status&&300>m.status||304===m.status||Z.test(a.url))c(t(a.type,b));else{var h=Error(m.responseText);h.code=m.status;h.response=b;e(h)}}catch(I){e(I)}};h&&null!=a.data?m.send(a.data):m.send()});return!0===a.background?B:z(B)},jsonp:function(a,k){var z=e();a=h(a,k);var q=new c(function(c,e){var h=a.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+m++,k=b.document.createElement("script");b[h]=function(e){k.parentNode.removeChild(k);c(t(a.type,e));delete b[h]};k.onerror=function(){k.parentNode.removeChild(k);
|
||||
e(Error("JSONP request failed"));delete b[h]};null==a.data&&(a.data={});a.url=p(a.url,a.data);a.data[a.callbackKey||"callback"]=h;k.src=l(a.url,a.data);b.document.documentElement.appendChild(k)});return!0===a.background?q:z(q)},setCompletionCallback:function(a){A=a}}}(window,r),V=function(b){function c(g,d){if(g.state!==d)throw Error("`vnode.state` must not be modified");}function e(g){var d=g.state;try{return this.apply(d,arguments)}finally{c(g,d)}}function h(g,d,f,a,b,c,e){for(;f<a;f++){var h=d[f];
|
||||
null!=h&&p(g,h,b,e,c)}}function p(g,d,f,b,c){var e=d.tag;if("string"===typeof e)switch(d.state={},null!=d.attrs&&L(d.attrs,d,f),e){case "#":return d.dom=C.createTextNode(d.children),a(g,d.dom,c),d.dom;case "<":return l(g,d,b,c);case "[":var t=C.createDocumentFragment();null!=d.children&&(e=d.children,h(t,e,0,e.length,f,null,b));d.dom=t.firstChild;d.domSize=t.childNodes.length;a(g,t,c);return t;default:var n=d.tag,m=(e=d.attrs)&&e.is;n=(b=d.attrs&&d.attrs.xmlns||G[d.tag]||b)?m?C.createElementNS(b,
|
||||
n,{is:m}):C.createElementNS(b,n):m?C.createElement(n,{is:m}):C.createElement(n);d.dom=n;if(null!=e)for(t in m=b,e)K(d,t,null,e[t],m);a(g,n,c);null!=d.attrs&&null!=d.attrs.contenteditable?B(d):(null!=d.text&&(""!==d.text?n.textContent=d.text:d.children=[x("#",void 0,void 0,d.text,void 0,void 0)]),null!=d.children&&(g=d.children,h(n,g,0,g.length,f,null,b),g=d.attrs,"select"===d.tag&&null!=g&&("value"in g&&K(d,"value",null,g.value,void 0),"selectedIndex"in g&&K(d,"selectedIndex",null,g.selectedIndex,
|
||||
void 0))));return n}else return k(d,f),null!=d.instance?(f=p(g,d.instance,f,b,c),d.dom=d.instance.dom,d.domSize=null!=d.dom?d.instance.domSize:0,a(g,f,c),d=f):(d.domSize=0,d=I),d}function l(g,d,f,b){var c=d.children.match(/^\s*?<(\w+)/im)||[];c=C.createElement(H[c[1]]||"div");"http://www.w3.org/2000/svg"===f?(c.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+d.children+"</svg>",c=c.firstChild):c.innerHTML=d.children;d.dom=c.firstChild;d.domSize=c.childNodes.length;for(d=C.createDocumentFragment();f=
|
||||
c.firstChild;)d.appendChild(f);a(g,d,b);return d}function k(g,d){if("function"===typeof g.tag.view){g.state=Object.create(g.tag);var f=g.state.view;if(null!=f.$$reentrantLock$$)return I;f.$$reentrantLock$$=!0}else{g.state=void 0;f=g.tag;if(null!=f.$$reentrantLock$$)return I;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&&L(g.attrs,g,d);L(g.state,g,d);g.instance=x.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,d,f,b,c,e,k){if(!(d===f&&!b||null==d&&null==f))if(null==d)h(g,f,0,f.length,c,e,k);else if(null==f)z(d,0,d.length,f,b);else{for(var n=0,l=Math.min(d.length,f.length),q=d.length,B=!1,D=!1;n<l;n++)if(null!=d[n]&&null!=f[n]){null==d[n].key&&null==f[n].key&&(D=!0);break}if(D&&q===f.length)for(n=0;n<q;n++)d[n]===f[n]&&!b||null==d[n]&&null==f[n]||(null==d[n]?p(g,f[n],c,k,A(d,n+1,q,e)):null==f[n]?z(d,n,n+1,f,b):t(g,d[n],f[n],c,A(d,n+1,q,e),b,k));else{a:{if(null!=d.pool&&
|
||||
Math.abs(d.pool.length-f.length)<=Math.abs(d.length-f.length)&&(n=f[0]&&f[0].children&&f[0].children.length||0,Math.abs((d.pool[0]&&d.pool[0].children&&d.pool[0].children.length||0)-n)<=Math.abs((d[0]&&d[0].children&&d[0].children.length||0)-n))){n=!0;break a}n=!1}n&&(B=!0,d=d.concat(d.pool));var r=n=0;l=d.length-1;for(var F=f.length-1,x,v,y,u;l>=r&&F>=n;)if(v=d[r],y=f[n],u=B&&r>=q,v===y&&!u&&!b||null==v&&null==y)r++,n++;else if(null==v)(D||null==y.key)&&p(g,f[n],c,k,A(d,++n,q,e)),r++;else if(null==
|
||||
y){if(D||null==v.key)z(d,n,n+1,f,b),r++;n++}else if(v.key===y.key)r++,n++,t(g,v,y,c,A(d,r,q,e),u||b,k),u&&v.tag===y.tag&&a(g,m(y),e);else if(v=d[l],u=B&&l>=q,v!==y||u||b)if(null==v)l--;else if(null==y)n++;else if(v.key===y.key)t(g,v,y,c,A(d,l+1,q,e),u||b,k),(u&&v.tag===y.tag||n<F)&&a(g,m(y),A(d,r,q,e)),l--,n++;else break;else l--,n++;for(;l>=r&&F>=n;){v=d[l];y=f[F];u=B&&l>=q;if(v!==y||u||b)if(null==v)l--;else{if(null!=y)if(v.key===y.key)t(g,v,y,c,A(d,l+1,q,e),u||b,k),u&&v.tag===y.tag&&a(g,m(y),e),
|
||||
null!=v.dom&&(e=v.dom),l--;else{if(!x){x=d;D=l;v={};for(u=0;u<D;u++){var w=x[u];null!=w&&(w=w.key,null!=w&&(v[w]=u))}x=v}null!=y&&(D=x[y.key],null!=D?(v=d[D],u=B&&D>=q,t(g,v,y,c,A(d,l+1,q,e),u||b,k),a(g,m(y),e),v.skip=!0,null!=v.dom&&(e=v.dom)):e=p(g,y,c,k,e))}F--}else l--,F--;if(F<n)break}h(g,f,n,F+1,c,e,k);z(d,r,Math.min(l+1,q),f,b);if(B)for(g=Math.max(r,q);l>=g;l--)d[l].skip?d[l].skip=!1:J(d[l],f)}}}function t(g,d,f,b,a,c,h){var n=d.tag;if(n===f.tag){f.state=d.state;f.events=d.events;var z;if(z=
|
||||
!c){var A,D;null!=f.attrs&&"function"===typeof f.attrs.onbeforeupdate&&(A=e.call(f.attrs.onbeforeupdate,f,d));"string"!==typeof f.tag&&"function"===typeof f.state.onbeforeupdate&&(D=e.call(f.state.onbeforeupdate,f,d));void 0===A&&void 0===D||A||D?z=!1:(f.dom=d.dom,f.domSize=d.domSize,f.instance=d.instance,z=!0)}if(!z)if("string"===typeof n)switch(null!=f.attrs&&(c?(f.state={},L(f.attrs,f,b)):N(f.attrs,f,b)),n){case "#":d.children.toString()!==f.children.toString()&&(d.dom.nodeValue=f.children);f.dom=
|
||||
d.dom;break;case "<":d.children!==f.children?(m(d),l(g,f,h,a)):(f.dom=d.dom,f.domSize=d.domSize);break;case "[":q(g,d.children,f.children,c,b,a,h);d=0;b=f.children;f.dom=null;if(null!=b){for(c=0;c<b.length;c++){var u=b[c];null!=u&&null!=u.dom&&(null==f.dom&&(f.dom=u.dom),d+=u.domSize||1)}1!==d&&(f.domSize=d)}break;default:g=f.dom=d.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));a=d.attrs;n=f.attrs;z=h;
|
||||
if(null!=n)for(u in n)K(f,u,a&&a[u],n[u],z);if(null!=a)for(u in a)null!=n&&u in n||("className"===u&&(u="class"),"o"!==u[0]||"n"!==u[1]||T(u)?"key"!==u&&f.dom.removeAttribute(u):U(f,u,void 0));null!=f.attrs&&null!=f.attrs.contenteditable?B(f):null!=d.text&&null!=f.text&&""!==f.text?d.text.toString()!==f.text.toString()&&(d.dom.firstChild.nodeValue=f.text):(null!=d.text&&(d.children=[x("#",void 0,void 0,d.text,void 0,d.dom.firstChild)]),null!=f.text&&(f.children=[x("#",void 0,void 0,f.text,void 0,
|
||||
void 0)]),q(g,d.children,f.children,c,b,null,h))}else{if(c)k(f,b);else{f.instance=x.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&&N(f.attrs,f,b);N(f.state,f,b)}null!=f.instance?(null==d.instance?p(g,f.instance,b,h,a):t(g,d.instance,f.instance,b,a,c,h),f.dom=f.instance.dom,f.domSize=f.instance.domSize):null!=d.instance?(r(d.instance,null,c),f.dom=void 0,f.domSize=0):(f.dom=d.dom,f.domSize=d.domSize)}}else r(d,
|
||||
null,c),p(g,f,b,h,a)}function m(g){var d=g.domSize;if(null!=d||null==g.dom){var b=C.createDocumentFragment();if(0<d){for(g=g.dom;--d;)b.appendChild(g.nextSibling);b.insertBefore(g,b.firstChild)}return b}return g.dom}function A(g,d,b,a){for(;d<b;d++)if(null!=g[d]&&null!=g[d].dom)return g[d].dom;return a}function a(g,d,b){b?g.insertBefore(d,b):g.appendChild(d)}function B(g){var d=g.children;if(null!=d&&1===d.length&&"<"===d[0].tag)d=d[0].children,g.dom.innerHTML!==d&&(g.dom.innerHTML=d);else if(null!=
|
||||
g.text||null!=d&&0!==d.length)throw Error("Child node of a contenteditable must be trusted");}function z(g,d,b,a,c){for(;d<b;d++){var f=g[d];null!=f&&(f.skip?f.skip=!1:r(f,a,c))}}function r(g,d,b){function a(){if(++h===f&&(b||(c(g,t),w(g)),g.dom)){var a=g.domSize||1;if(1<a)for(var e=g.dom;--a;){var n=e.nextSibling,k=n.parentNode;null!=k&&k.removeChild(n)}a=g.dom;e=a.parentNode;null!=e&&e.removeChild(a);J(g,d)}}var f=1,h=0;if(!b){var t=g.state;if(g.attrs&&"function"===typeof g.attrs.onbeforeremove){var k=
|
||||
e.call(g.attrs.onbeforeremove,g);null!=k&&"function"===typeof k.then&&(f++,k.then(a,a))}"string"!==typeof g.tag&&"function"===typeof g.state.onbeforeremove&&(k=e.call(g.state.onbeforeremove,g),null!=k&&"function"===typeof k.then&&(f++,k.then(a,a)))}a()}function J(b,d){var a;if(a=null!=d&&null==b.domSize)a=b.attrs,a=!(null!=a&&(a.oncreate||a.onupdate||a.onbeforeremove||a.onremove));a&&"string"===typeof b.tag&&(d.pool?d.pool.push(b):d.pool=[b])}function w(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&&w(a.instance);else if(a=a.children,Array.isArray(a))for(var d=0;d<a.length;d++){var b=a[d];null!=b&&w(b)}}function K(a,d,b,c,e){if("key"!==d&&"is"!==d&&!T(d)){if("o"===d[0]&&"n"===d[1])return U(a,d,c);if("undefined"===typeof c&&"value"===d&&b!==c)a.dom.value="";else if((b!==c||"value"===d||"checked"===d||"selectedIndex"===d||"selected"===d&&a.dom===C.activeElement||
|
||||
"option"===a.tag&&a.dom.parentNode===C.activeElement||"object"===typeof c)&&void 0!==c){var f=a.dom;if("xlink:"===d.slice(0,6))f.setAttributeNS("http://www.w3.org/1999/xlink",d,c);else if("style"===d)if(a=b,null!=a&&null!=c&&"object"===typeof a&&"object"===typeof c&&c!==a){for(var g in c)c[g]!==a[g]&&(f.style[g]=c[g]);for(g in a)g in c||(f.style[g]="")}else if(a===c&&(f.style.cssText="",a=null),null==c)f.style.cssText="";else if("string"===typeof c)f.style.cssText=c;else for(g in"string"===typeof a&&
|
||||
(f.style.cssText=""),c)f.style[g]=c[g];else if(d in f&&"href"!==d&&"list"!==d&&"form"!==d&&"width"!==d&&"height"!==d&&void 0===e&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===d){g=""+c;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===g&&a.dom===C.activeElement)return;if("select"===a.tag)if(null===c){if(-1===a.dom.selectedIndex&&a.dom===C.activeElement)return}else if(null!==b&&a.dom.value===g&&a.dom===C.activeElement)return;if("option"===a.tag&&null!=b&&a.dom.value===g)return}"input"===
|
||||
a.tag&&"type"===d?f.setAttribute(d,c):f[d]=c}else"boolean"===typeof c?c?f.setAttribute(d,""):f.removeAttribute(d):f.setAttribute("className"===d?"class":d,c)}}}function T(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function O(){}function U(a,d,b){null!=a.events?a.events[d]!==b&&(null==b||"function"!==typeof b&&"object"!==typeof b?(null!=a.events[d]&&a.dom.removeEventListener(d.slice(2),a.events,!1),a.events[d]=void 0):(null==a.events[d]&&
|
||||
a.dom.addEventListener(d.slice(2),a.events,!1),a.events[d]=b)):null==b||"function"!==typeof b&&"object"!==typeof b||(a.events=new O,a.dom.addEventListener(d.slice(2),a.events,!1),a.events[d]=b)}function L(a,d,b){"function"===typeof a.oninit&&e.call(a.oninit,d);"function"===typeof a.oncreate&&b.push(e.bind(a.oncreate,d))}function N(a,d,b){"function"===typeof a.onupdate&&b.push(e.bind(a.onupdate,d))}var C=b.document,I=C.createDocumentFragment(),G={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},
|
||||
E,H={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};O.prototype=Object.create(null);O.prototype.handleEvent=function(a){var d=this["on"+a.type];"function"===typeof d?d.call(a.target,a):"function"===typeof d.handleEvent&&d.handleEvent(a);"function"===typeof E&&E.call(a.target,a)};return{render:function(a,d){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var b=[],c=C.activeElement,
|
||||
e=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(d)||(d=[d]);q(a,a.vnodes,x.normalizeChildren(d),!1,b,null,"http://www.w3.org/1999/xhtml"===e?void 0:e);a.vnodes=d;null!=c&&C.activeElement!==c&&c.focus();for(c=0;c<b.length;c++)b[c]()},setEventCallback:function(a){return E=a}}},H=function(b,c){function e(b){b=l.indexOf(b);-1<b&&l.splice(b,2)}function h(){if(k)throw Error("Nested m.redraw.sync() call");k=!0;for(var b=1;b<l.length;b+=2)try{l[b]()}catch(m){"undefined"!==typeof console&&
|
||||
console.error(m)}k=!1}var p=V(b);p.setEventCallback(function(b){!1===b.redraw?b.redraw=void 0:q()});var l=[],k=!1,q=(c||X)(h);q.sync=h;return{subscribe:function(b,c){e(b);l.push(b,c)},unsubscribe:e,redraw:q,render:p.render}}(window);P.setCompletionCallback(H.redraw);w.mount=function(b){return function(c,e){if(null===e)b.render(c,[]),b.unsubscribe(c);else{if(null==e.view&&"function"!==typeof e)throw Error("m.mount(element, component) expects a component, not a vnode");var h=function(){b.render(c,x(e))};
|
||||
b.subscribe(c,h);h()}}}(H);var aa=r,Q=function(b){if(""===b||null==b)return{};"?"===b.charAt(0)&&(b=b.slice(1));b=b.split("&");for(var c={},e={},h=0;h<b.length;h++){var p=b[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=c;-1<l.indexOf("[")&&k.pop();for(var t=0;t<k.length;t++){l=k[t];var m=k[t+1];m=""==m||!isNaN(parseInt(m,10));var r=t===k.length-1;""===l&&(l=k.slice(0,t).join(),null==e[l]&&(e[l]=0),
|
||||
l=e[l]++);null==q[l]&&(q[l]=r?p:m?[]:{});q=q[l]}}return c},ba=function(b){function c(c){var e=b.location[c].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===c&&"/"!==e[0]&&(e="/"+e);return e}function e(b){return function(){null==k&&(k=l(function(){k=null;b()}))}}function h(b,c,e){var a=b.indexOf("?"),h=b.indexOf("#"),k=-1<a?a:-1<h?h:b.length;if(-1<a){a=Q(b.slice(a+1,-1<h?h:b.length));for(var l in a)c[l]=a[l]}if(-1<h)for(l in c=Q(b.slice(h+1)),c)e[l]=c[l];return b.slice(0,k)}var p=
|
||||
"function"===typeof b.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,k,q={prefix:"#!",getPath:function(){switch(q.prefix.charAt(0)){case "#":return c("hash").slice(q.prefix.length);case "?":return c("search").slice(q.prefix.length)+c("hash");default:return c("pathname").slice(q.prefix.length)+c("search")+c("hash")}},setPath:function(c,e,k){var a={},l={};c=h(c,a,l);if(null!=e){for(var m in e)a[m]=e[m];c=c.replace(/:([^\/]+)/g,function(b,c){delete a[c];return e[c]})}(m=
|
||||
E(a))&&(c+="?"+m);(l=E(l))&&(c+="#"+l);p?(l=k?k.state:null,m=k?k.title:null,b.onpopstate(),k&&k.replace?b.history.replaceState(l,m,q.prefix+c):b.history.pushState(l,m,q.prefix+c)):b.location.href=q.prefix+c},defineRoutes:function(c,k,l){function a(){var a=q.getPath(),e={},m=h(a,e,e),p=b.history.state;if(null!=p)for(var t in p)e[t]=p[t];for(var r in c)if(p=new RegExp("^"+r.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),p.test(m)){m.replace(p,function(){for(var b=r.match(/:[^\/]+/g)||
|
||||
[],h=[].slice.call(arguments,1,-2),l=0;l<b.length;l++)e[b[l].replace(/:|\./g,"")]=decodeURIComponent(h[l]);k(c[r],e,a,r)});return}l(a,e)}p?b.onpopstate=e(a):"#"===q.prefix.charAt(0)&&(b.onhashchange=a);a()}};return q};w.route=function(b,c){var e=ba(b),h=function(a){return a},p,l,k,q,t,m=function(a,b,m){function r(){null!=p&&c.render(a,p(x(l,k.key,k)))}if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var z=function(){r();z=c.redraw};c.subscribe(a,r);var w=
|
||||
function(a){if(a!==b)e.setPath(b,null,{replace:!0});else throw Error("Could not resolve default route "+b);};e.defineRoutes(m,function(a,b,c){var e=t=function(a,m){e===t&&(l=null==m||"function"!==typeof m.view&&"function"!==typeof m?"div":m,k=b,q=c,t=null,p=(a.render||h).bind(a),z())};a.view||"function"===typeof a?e({},a):a.onmatch?aa.resolve(a.onmatch(b,c)).then(function(b){e(a,b)},w):e(a,"div")},w)};m.set=function(a,b,c){null!=t&&(c=c||{},c.replace=!0);t=null;e.setPath(a,b,c)};m.get=function(){return q};
|
||||
m.prefix=function(a){e.prefix=a};var r=function(a,b){b.dom.setAttribute("href",e.prefix+b.attrs.href);b.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)),m.set(b,void 0,a))}};m.link=function(a){return null==a.tag?r.bind(r,a):r({},a)};m.param=function(a){return"undefined"!==typeof k&&"undefined"!==typeof a?k[a]:k};return m}(window,H);w.withAttr=function(b,c,e){return function(h){c.call(e||
|
||||
this,b in h.currentTarget?h.currentTarget[b]:h.currentTarget.getAttribute(b))}};var ca=V(window);w.render=ca.render;w.redraw=H.redraw;w.request=P.request;w.jsonp=P.jsonp;w.parseQueryString=Q;w.buildQueryString=E;w.version="1.1.3";w.vnode=x;w.PromisePolyfill=r;"undefined"!==typeof module?module.exports=w:window.m=w})();
|
||||
(function(){function w(a,b,f,g,r,l){return{tag:a,key:b,attrs:f,children:g,text:r,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function N(a){for(var b in a)if(B.call(a,b))return!1;return!0}function u(a){var b=arguments[1],f=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 g;if(!(g=O[a])){var r="div";for(var l=[],k={};g=R.exec(a);){var m=g[1],
|
||||
t=g[2];""===m&&""!==t?r=t:"#"===m?k.id=t:"."===m?l.push(t):"["===g[3][0]&&((m=g[6])&&(m=m.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===g[4]?l.push(m):k[g[4]]=""===m?m:m||!0)}0<l.length&&(k.className=l.join(" "));g=O[a]={tag:r,attrs:k}}}if(null==b)b={};else if("object"!==typeof b||null!=b.tag||Array.isArray(b))b={},f=1;if(arguments.length===f+1)r=arguments[f],Array.isArray(r)||(r=[r]);else for(r=[];f<arguments.length;)r.push(arguments[f++]);f=w.normalizeChildren(r);if("string"===typeof a){r=
|
||||
!1;var e,y;l=b.className||b["class"];if(!N(g.attrs)&&!N(b)){k={};for(var d in b)B.call(b,d)&&(k[d]=b[d]);b=k}for(d in g.attrs)B.call(g.attrs,d)&&(b[d]=g.attrs[d]);void 0!==l&&(void 0!==b["class"]&&(b["class"]=void 0,b.className=l),null!=g.attrs.className&&(b.className=g.attrs.className+" "+l));for(d in b)if(B.call(b,d)&&"key"!==d){r=!0;break}Array.isArray(f)&&1===f.length&&null!=f[0]&&"#"===f[0].tag?y=f[0].children:e=f;return w(g.tag,b.key,r?b:void 0,e,y)}return w(a,b.key,b,f)}function S(a){var b=
|
||||
0,f=null,g="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var r=Date.now()-b;null===f&&(f=g(function(){f=null;a();b=Date.now()},16-r))}}w.normalize=function(a){return Array.isArray(a)?w("[",void 0,void 0,w.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?w("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};w.normalizeChildren=function(a){for(var b=0;b<a.length;b++)a[b]=w.normalize(a[b]);return a};var R=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
|
||||
O={},B={}.hasOwnProperty;u.trust=function(a){null==a&&(a="");return w("<",void 0,void 0,a,void 0,void 0)};u.fragment=function(a,b){return w("[",a.key,a,w.normalizeChildren(b),void 0,void 0)};var h=function(a){function b(a,d){return function H(b){var x;try{if(!d||null==b||"object"!==typeof b&&"function"!==typeof b||"function"!==typeof(x=b.then))e(function(){d||0!==a.length||console.error("Possible unhandled promise rejection:",b);for(var f=0;f<a.length;f++)a[f](b);r.length=0;l.length=0;t.state=d;t.retry=
|
||||
function(){H(b)}});else{if(b===g)throw new TypeError("Promise can't be resolved w/ itself");f(x.bind(b))}}catch(T){m(T)}}}function f(a){function d(d){return function(a){0<b++||d(a)}}var b=0,f=d(m);try{a(d(k),f)}catch(H){f(H)}}if(!(this instanceof h))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var g=this,r=[],l=[],k=b(r,!0),m=b(l,!1),t=g._instance={resolvers:r,rejectors:l},e="function"===typeof setImmediate?setImmediate:
|
||||
setTimeout;f(a)};h.prototype.then=function(a,b){function f(a,b,f,k){b.push(function(d){if("function"!==typeof a)f(d);else try{r(a(d))}catch(A){l&&l(A)}});"function"===typeof g.retry&&k===g.state&&g.retry()}var g=this._instance,r,l,k=new h(function(a,b){r=a;l=b});f(a,g.resolvers,r,!0);f(b,g.rejectors,l,!1);return k};h.prototype["catch"]=function(a){return this.then(null,a)};h.prototype["finally"]=function(a){return this.then(function(b){return h.resolve(a()).then(function(){return b})},function(b){return h.resolve(a()).then(function(){return h.reject(b)})})};
|
||||
h.resolve=function(a){return a instanceof h?a:new h(function(b){b(a)})};h.reject=function(a){return new h(function(b,f){f(a)})};h.all=function(a){return new h(function(b,f){var g=a.length,r=0,l=[];if(0===a.length)b([]);else for(var k=0;k<a.length;k++)(function(m){function t(a){r++;l[m]=a;r===g&&b(l)}null==a[m]||"object"!==typeof a[m]&&"function"!==typeof a[m]||"function"!==typeof a[m].then?t(a[m]):a[m].then(t,f)})(k)})};h.race=function(a){return new h(function(b,f){for(var g=0;g<a.length;g++)a[g].then(b,
|
||||
f)})};"undefined"!==typeof window?("undefined"===typeof window.Promise?window.Promise=h:window.Promise.prototype["finally"]||(window.Promise.prototype["finally"]=h.prototype["finally"]),h=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise?global.Promise=h:global.Promise.prototype["finally"]||(global.Promise.prototype["finally"]=h.prototype["finally"]),h=global.Promise);var D=function(a){function b(a,g){if(Array.isArray(g))for(var r=0;r<g.length;r++)b(a+"["+r+"]",g[r]);
|
||||
else if("[object Object]"===Object.prototype.toString.call(g))for(r in g)b(a+"["+r+"]",g[r]);else f.push(encodeURIComponent(a)+(null!=g&&""!==g?"="+encodeURIComponent(g):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var f=[],g;for(g in a)b(g,a[g]);return f.join("&")},U=/^file:\/\//i,L=function(a,b){function f(){function d(){0===--a&&"function"===typeof y&&y()}var a=0;return function C(b){var f=b.then;b.then=function(){a++;var g=f.apply(b,arguments);g.then(d,function(b){d();
|
||||
if(0===a)throw b;});return C(g)};return b}}function g(d,a){if("string"===typeof d){var b=d;d=a||{};null==d.url&&(d.url=b)}return d}function r(d,a){if(null==a)return d;for(var b=d.match(/:[^\/]+/gi)||[],f=0;f<b.length;f++){var g=b[f].slice(1);null!=a[g]&&(d=d.replace(b[f],a[g]))}return d}function l(d,a){var b=D(a);if(""!==b){var f=0>d.indexOf("?")?"?":"&";d+=f+b}return d}function k(d){try{return""!==d?JSON.parse(d):null}catch(A){throw Error(d);}}function m(d){return d.responseText}function t(d,a){if("function"===
|
||||
typeof d)if(Array.isArray(a))for(var b=0;b<a.length;b++)a[b]=new d(a[b]);else return new d(a);return a}var e=0,y;return{request:function(d,e){var x=f();d=g(d,e);var A=new b(function(b,f){null==d.method&&(d.method="GET");d.method=d.method.toUpperCase();var g="GET"===d.method||"TRACE"===d.method?!1:"boolean"===typeof d.useBody?d.useBody:!0;"function"!==typeof d.serialize&&(d.serialize="undefined"!==typeof FormData&&d.data instanceof FormData?function(d){return d}:JSON.stringify);"function"!==typeof d.deserialize&&
|
||||
(d.deserialize=k);"function"!==typeof d.extract&&(d.extract=m);d.url=r(d.url,d.data);g?d.data=d.serialize(d.data):d.url=l(d.url,d.data);var e=new a.XMLHttpRequest,x=!1,A=e.abort;e.abort=function(){x=!0;A.call(e)};e.open(d.method,d.url,"boolean"===typeof d.async?d.async:!0,"string"===typeof d.user?d.user:void 0,"string"===typeof d.password?d.password:void 0);d.serialize!==JSON.stringify||!g||d.headers&&d.headers.hasOwnProperty("Content-Type")||e.setRequestHeader("Content-Type","application/json; charset=utf-8");
|
||||
d.deserialize!==k||d.headers&&d.headers.hasOwnProperty("Accept")||e.setRequestHeader("Accept","application/json, text/*");d.withCredentials&&(e.withCredentials=d.withCredentials);d.timeout&&(e.timeout=d.timeout);for(var y in d.headers)({}).hasOwnProperty.call(d.headers,y)&&e.setRequestHeader(y,d.headers[y]);"function"===typeof d.config&&(e=d.config(e,d)||e);e.onreadystatechange=function(){if(!x&&4===e.readyState)try{var a=d.extract!==m?d.extract(e,d):d.deserialize(d.extract(e,d));if(d.extract!==m||
|
||||
200<=e.status&&300>e.status||304===e.status||U.test(d.url))b(t(d.type,a));else{var g=Error(e.responseText);g.code=e.status;g.response=a;f(g)}}catch(E){f(E)}};g&&null!=d.data?e.send(d.data):e.send()});return!0===d.background?A:x(A)},jsonp:function(d,m){var x=f();d=g(d,m);var k=new b(function(b,f){var g=d.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+e++,m=a.document.createElement("script");a[g]=function(f){m.parentNode.removeChild(m);b(t(d.type,f));delete a[g]};m.onerror=function(){m.parentNode.removeChild(m);
|
||||
f(Error("JSONP request failed"));delete a[g]};null==d.data&&(d.data={});d.url=r(d.url,d.data);d.data[d.callbackKey||"callback"]=g;m.src=l(d.url,d.data);a.document.documentElement.appendChild(m)});return!0===d.background?k:x(k)},setCompletionCallback:function(d){y=d}}}(window,h),Q=function(a){function b(q,c){if(q.state!==c)throw Error("`vnode.state` must not be modified");}function f(q){var c=q.state;try{return this.apply(c,arguments)}finally{b(q,c)}}function g(q,c,d,a,b,f,g){for(;d<a;d++){var n=c[d];
|
||||
null!=n&&r(q,n,b,g,f)}}function r(q,c,n,a,b){var e=c.tag;if("string"===typeof e)switch(c.state={},null!=c.attrs&&J(c.attrs,c,n),e){case "#":return c.dom=p.createTextNode(c.children),y(q,c.dom,b),c.dom;case "<":return l(q,c,a,b);case "[":var z=p.createDocumentFragment();null!=c.children&&(e=c.children,g(z,e,0,e.length,n,null,a));c.dom=z.firstChild;c.domSize=z.childNodes.length;y(q,z,b);return z;default:var t=c.tag,v=(e=c.attrs)&&e.is;t=(a=c.attrs&&c.attrs.xmlns||B[c.tag]||a)?v?p.createElementNS(a,
|
||||
t,{is:v}):p.createElementNS(a,t):v?p.createElement(t,{is:v}):p.createElement(t);c.dom=t;if(null!=e)for(z in v=a,e)C(c,z,null,e[z],v);y(q,t,b);null!=c.attrs&&null!=c.attrs.contenteditable?d(c):(null!=c.text&&(""!==c.text?t.textContent=c.text:c.children=[w("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(q=c.children,g(t,q,0,q.length,n,null,a),q=c.attrs,"select"===c.tag&&null!=q&&("value"in q&&C(c,"value",null,q.value,void 0),"selectedIndex"in q&&C(c,"selectedIndex",null,q.selectedIndex,
|
||||
void 0))));return t}else{b:{if("function"===typeof c.tag.view){c.state=Object.create(c.tag);z=c.state.view;if(null!=z.$$reentrantLock$$)break b;z.$$reentrantLock$$=!0}else{c.state=void 0;z=c.tag;if(null!=z.$$reentrantLock$$)break b;z.$$reentrantLock$$=!0;c.state=null!=c.tag.prototype&&"function"===typeof c.tag.prototype.view?new c.tag(c):c.tag(c)}null!=c.attrs&&J(c.attrs,c,n);J(c.state,c,n);c.instance=w.normalize(f.call(c.state.view,c));if(c.instance===c)throw Error("A view cannot return the vnode it received as argument");
|
||||
z.$$reentrantLock$$=null}null!=c.instance?(n=r(q,c.instance,n,a,b),c.dom=c.instance.dom,c.domSize=null!=c.dom?c.instance.domSize:0,y(q,n,b),c=n):(c.domSize=0,c=V);return c}}function l(d,c,a,b){var q=c.children.match(/^\s*?<(\w+)/im)||[];q=p.createElement(D[q[1]]||"div");"http://www.w3.org/2000/svg"===a?(q.innerHTML='<svg xmlns="http://www.w3.org/2000/svg">'+c.children+"</svg>",q=q.firstChild):q.innerHTML=c.children;c.dom=q.firstChild;c.domSize=q.childNodes.length;for(c=p.createDocumentFragment();a=
|
||||
q.firstChild;)c.appendChild(a);y(d,c,b);return c}function k(q,c,d,a,b,f){if(c!==d&&(null!=c||null!=d))if(null==c)g(q,d,0,d.length,a,b,f);else if(null==d)A(c,0,c.length);else{for(var n=0,v=Math.min(c.length,d.length),l=!1;n<v;n++)if(null!=c[n]&&null!=d[n]){null==c[n].key&&null==d[n].key&&(l=!0);break}if(l&&c.length===d.length)for(n=0;n<d.length;n++)c[n]===d[n]||null==c[n]&&null==d[n]||(null==c[n]?r(q,d[n],a,f,e(c,n+1,b)):null==d[n]?A(c,n,n+1):m(q,c[n],d[n],a,e(c,n+1,b),f));else{v=n=0;for(var k=c.length-
|
||||
1,x=d.length-1,F,h,p;k>=v&&x>=n;)if(h=c[v],p=d[n],h===p||null==h&&null==p)v++,n++;else if(null==h)(l||null==p.key)&&r(q,d[n],a,f,e(c,++n,b)),v++;else if(null==p){if(l||null==h.key)A(c,n,n+1),v++;n++}else if(h.key===p.key)v++,n++,m(q,h,p,a,e(c,v,b),f);else if(h=c[k],h===p)k--,n++;else if(null==h)k--;else if(null==p)n++;else if(h.key===p.key)m(q,h,p,a,e(c,k+1,b),f),n<x&&y(q,t(p),e(c,v,b)),k--,n++;else break;for(;k>=v&&x>=n;){h=c[k];p=d[x];if(h===p)k--,x--;else if(null==h)k--;else{if(null!=p)if(h.key===
|
||||
p.key)m(q,h,p,a,e(c,k+1,b),f),null!=h.dom&&(b=h.dom),k--;else{if(!F){F=c;l=k;h={};var w;for(w=0;w<l;w++){var u=F[w];null!=u&&(u=u.key,null!=u&&(h[u]=w))}F=h}null!=p&&(l=F[p.key],null!=l?(h=c[l],m(q,h,p,a,e(c,k+1,b),f),y(q,t(p),b),h.skip=!0,null!=h.dom&&(b=h.dom)):b=r(q,p,a,f,b))}x--}if(x<n)break}g(q,d,n,x+1,a,b,f);A(c,v,k+1)}}}function m(q,c,a,b,g,e){var n=c.tag;if(n===a.tag){a.state=c.state;a.events=c.events;var v;var h;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&(v=f.call(a.attrs.onbeforeupdate,
|
||||
a,c));"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeupdate&&(h=f.call(a.state.onbeforeupdate,a,c));void 0===v&&void 0===h||v||h?v=!1:(a.dom=c.dom,a.domSize=c.domSize,a.instance=c.instance,v=!0);if(!v)if("string"===typeof n)switch(null!=a.attrs&&K(a.attrs,a,b),n){case "#":c.children.toString()!==a.children.toString()&&(c.dom.nodeValue=a.children);a.dom=c.dom;break;case "<":c.children!==a.children?(t(c),l(q,a,e,g)):(a.dom=c.dom,a.domSize=c.domSize);break;case "[":k(q,c.children,a.children,
|
||||
b,g,e);c=0;b=a.children;a.dom=null;if(null!=b){for(var p=0;p<b.length;p++)e=b[p],null!=e&&null!=e.dom&&(null==a.dom&&(a.dom=e.dom),c+=e.domSize||1);1!==c&&(a.domSize=c)}break;default:q=a.dom=c.dom;e=a.attrs&&a.attrs.xmlns||B[a.tag]||e;"textarea"===a.tag&&(null==a.attrs&&(a.attrs={}),null!=a.text&&(a.attrs.value=a.text,a.text=void 0));g=c.attrs;n=a.attrs;v=e;if(null!=n)for(p in n)C(a,p,g&&g[p],n[p],v);if(null!=g)for(p in g)null!=n&&p in n||("className"===p&&(p="class"),"o"!==p[0]||"n"!==p[1]||u(p)?
|
||||
"key"!==p&&a.dom.removeAttribute(p):P(a,p,void 0));null!=a.attrs&&null!=a.attrs.contenteditable?d(a):null!=c.text&&null!=a.text&&""!==a.text?c.text.toString()!==a.text.toString()&&(c.dom.firstChild.nodeValue=a.text):(null!=c.text&&(c.children=[w("#",void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=a.text&&(a.children=[w("#",void 0,void 0,a.text,void 0,void 0)]),k(q,c.children,a.children,b,null,e))}else{a.instance=w.normalize(f.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==c.instance?r(q,a.instance,b,e,g):m(q,c.instance,a.instance,b,g,e),a.dom=a.instance.dom,a.domSize=a.instance.domSize):null!=c.instance?(x(c.instance),a.dom=void 0,a.domSize=0):(a.dom=c.dom,a.domSize=c.domSize)}}else x(c),r(q,a,b,e,g)}function t(a){var c=a.domSize;if(null!=c||null==a.dom){var d=p.createDocumentFragment();if(0<c){for(a=a.dom;--c;)d.appendChild(a.nextSibling);d.insertBefore(a,d.firstChild)}return d}return a.dom}function e(a,
|
||||
c,d){for(;c<a.length;c++)if(null!=a[c]&&null!=a[c].dom)return a[c].dom;return d}function y(a,c,d){d?a.insertBefore(c,d):a.appendChild(c)}function d(a){var c=a.children;if(null!=c&&1===c.length&&"<"===c[0].tag)c=c[0].children,a.dom.innerHTML!==c&&(a.dom.innerHTML=c);else if(null!=a.text||null!=c&&0!==c.length)throw Error("Child node of a contenteditable must be trusted");}function A(a,c,d){for(;c<d;c++){var b=a[c];null!=b&&(b.skip?b.skip=!1:x(b))}}function x(a){function c(){if(++q===d&&(b(a,g),h(a),
|
||||
a.dom)){var c=a.domSize||1;if(1<c)for(var f=a.dom;--c;){var e=f.nextSibling,n=e.parentNode;null!=n&&n.removeChild(e)}c=a.dom;f=c.parentNode;null!=f&&f.removeChild(c)}}var d=1,q=0,g=a.state;if(a.attrs&&"function"===typeof a.attrs.onbeforeremove){var e=f.call(a.attrs.onbeforeremove,a);null!=e&&"function"===typeof e.then&&(d++,e.then(c,c))}"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeremove&&(e=f.call(a.state.onbeforeremove,a),null!=e&&"function"===typeof e.then&&(d++,e.then(c,c)));c()}
|
||||
function h(a){a.attrs&&"function"===typeof a.attrs.onremove&&f.call(a.attrs.onremove,a);if("string"!==typeof a.tag)"function"===typeof a.state.onremove&&f.call(a.state.onremove,a),null!=a.instance&&h(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var d=a[c];null!=d&&h(d)}}function C(a,c,d,b,f){if("key"!==c&&"is"!==c&&!u(c)){if("o"===c[0]&&"n"===c[1])return P(a,c,b);if("undefined"===typeof b&&"value"===c&&d!==b)a.dom.value="";else if((d!==b||"value"===c||"checked"===
|
||||
c||"selectedIndex"===c||"selected"===c&&a.dom===p.activeElement||"option"===a.tag&&a.dom.parentNode===p.activeElement||"object"===typeof b)&&void 0!==b){var e=a.dom;if("xlink:"===c.slice(0,6))e.setAttributeNS("http://www.w3.org/1999/xlink",c,b);else if("style"===c)if(a=d,null!=a&&null!=b&&"object"===typeof a&&"object"===typeof b&&b!==a){for(var g in b)b[g]!==a[g]&&(e.style[g]=b[g]);for(g in a)g in b||(e.style[g]="")}else if(a===b&&(e.style.cssText="",a=null),null==b)e.style.cssText="";else if("string"===
|
||||
typeof b)e.style.cssText=b;else for(g in"string"===typeof a&&(e.style.cssText=""),b)e.style[g]=b[g];else if(c in e&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===f&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===c){g=""+b;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===g&&a.dom===p.activeElement)return;if("select"===a.tag)if(null===b){if(-1===a.dom.selectedIndex&&a.dom===p.activeElement)return}else if(null!==d&&a.dom.value===g&&a.dom===p.activeElement)return;
|
||||
if("option"===a.tag&&null!=d&&a.dom.value===g)return}"input"===a.tag&&"type"===c?e.setAttribute(c,b):e[c]=b}else"boolean"===typeof b?b?e.setAttribute(c,""):e.removeAttribute(c):e.setAttribute("className"===c?"class":c,b)}}}function u(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function I(){}function P(a,c,d){null!=a.events?a.events[c]!==d&&(null==d||"function"!==typeof d&&"object"!==typeof d?(null!=a.events[c]&&a.dom.removeEventListener(c.slice(2),
|
||||
a.events,!1),a.events[c]=void 0):(null==a.events[c]&&a.dom.addEventListener(c.slice(2),a.events,!1),a.events[c]=d)):null==d||"function"!==typeof d&&"object"!==typeof d||(a.events=new I,a.dom.addEventListener(c.slice(2),a.events,!1),a.events[c]=d)}function J(a,c,d){"function"===typeof a.oninit&&f.call(a.oninit,c);"function"===typeof a.oncreate&&d.push(f.bind(a.oncreate,c))}function K(a,c,d){"function"===typeof a.onupdate&&d.push(f.bind(a.onupdate,c))}var p=a.document,V=p.createDocumentFragment(),B=
|
||||
{svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},E,D={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};I.prototype=Object.create(null);I.prototype.handleEvent=function(a){var c=this["on"+a.type];"function"===typeof c?c.call(a.target,a):"function"===typeof c.handleEvent&&c.handleEvent(a);"function"===typeof E&&E.call(a.target,a)};return{render:function(a,c){if(!a)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");
|
||||
var d=[],b=p.activeElement,e=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(c)||(c=[c]);k(a,a.vnodes,w.normalizeChildren(c),d,null,"http://www.w3.org/1999/xhtml"===e?void 0:e);a.vnodes=c;null!=b&&p.activeElement!==b&&b.focus();for(b=0;b<d.length;b++)d[b]()},setEventCallback:function(a){return E=a}}},G=function(a,b){function f(a){a=h.indexOf(a);-1<a&&h.splice(a,2)}function g(){if(k)throw Error("Nested m.redraw.sync() call");k=!0;for(var a=1;a<h.length;a+=2)try{h[a]()}catch(e){"undefined"!==
|
||||
typeof console&&console.error(e)}k=!1}var r=Q(a);r.setEventCallback(function(a){!1===a.redraw?a.redraw=void 0:m()});var h=[],k=!1,m=(b||S)(g);m.sync=g;return{subscribe:function(a,b){f(a);h.push(a,b)},unsubscribe:f,redraw:m,render:r.render}}(window);L.setCompletionCallback(G.redraw);u.mount=function(a){return function(b,f){if(null===f)a.render(b,[]),a.unsubscribe(b);else{if(null==f.view&&"function"!==typeof f)throw Error("m.mount(element, component) expects a component, not a vnode");var g=function(){a.render(b,
|
||||
w(f))};a.subscribe(b,g);g()}}}(G);var W=h,M=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var b={},f={},g=0;g<a.length;g++){var h=a[g].split("="),l=decodeURIComponent(h[0]);h=2===h.length?decodeURIComponent(h[1]):"";"true"===h?h=!0:"false"===h&&(h=!1);var k=l.split(/\]\[?|\[/),m=b;-1<l.indexOf("[")&&k.pop();for(var t=0;t<k.length;t++){l=k[t];var e=k[t+1];e=""==e||!isNaN(parseInt(e,10));var y=t===k.length-1;""===l&&(l=k.slice(0,t).join(),null==f[l]&&(f[l]=
|
||||
0),l=f[l]++);null==m[l]&&(m[l]=y?h:e?[]:{});m=m[l]}}return b},X=function(a){function b(b){var e=a.location[b].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===b&&"/"!==e[0]&&(e="/"+e);return e}function f(a){return function(){null==k&&(k=l(function(){k=null;a()}))}}function g(a,b,g){var d=a.indexOf("?"),e=a.indexOf("#"),f=-1<d?d:-1<e?e:a.length;if(-1<d){d=M(a.slice(d+1,-1<e?e:a.length));for(var h in d)b[h]=d[h]}if(-1<e)for(h in b=M(a.slice(e+1)),b)g[h]=b[h];return a.slice(0,f)}var h=
|
||||
"function"===typeof a.history.pushState,l="function"===typeof setImmediate?setImmediate:setTimeout,k,m={prefix:"#!",getPath:function(){switch(m.prefix.charAt(0)){case "#":return b("hash").slice(m.prefix.length);case "?":return b("search").slice(m.prefix.length)+b("hash");default:return b("pathname").slice(m.prefix.length)+b("search")+b("hash")}},setPath:function(b,e,f){var d={},k={};b=g(b,d,k);if(null!=e){for(var l in e)d[l]=e[l];b=b.replace(/:([^\/]+)/g,function(a,b){delete d[b];return e[b]})}(l=
|
||||
D(d))&&(b+="?"+l);(k=D(k))&&(b+="#"+k);h?(k=f?f.state:null,l=f?f.title:null,a.onpopstate(),f&&f.replace?a.history.replaceState(k,l,m.prefix+b):a.history.pushState(k,l,m.prefix+b)):a.location.href=m.prefix+b},defineRoutes:function(b,e,k){function d(){var d=m.getPath(),f={},h=g(d,f,f),l=a.history.state;if(null!=l)for(var r in l)f[r]=l[r];for(var t in b)if(l=new RegExp("^"+t.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),l.test(h)){h.replace(l,function(){for(var a=t.match(/:[^\/]+/g)||
|
||||
[],g=[].slice.call(arguments,1,-2),h=0;h<a.length;h++)f[a[h].replace(/:|\./g,"")]=decodeURIComponent(g[h]);e(b[t],f,d,t)});return}k(d,f)}h?a.onpopstate=f(d):"#"===m.prefix.charAt(0)&&(a.onhashchange=d);d()}};return m};u.route=function(a,b){var f=X(a),g=function(a){return a},h,l,k,m,t,e=function(a,e,r){function d(){null!=h&&b.render(a,h(w(l,k.key,k)))}if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var x=function(){d();x=b.redraw};b.subscribe(a,d);var u=
|
||||
function(a){if(a!==e)f.setPath(e,null,{replace:!0});else throw Error("Could not resolve default route "+e);};f.defineRoutes(r,function(a,d,b){var f=t=function(a,e){f===t&&(l=null==e||"function"!==typeof e.view&&"function"!==typeof e?"div":e,k=d,m=b,t=null,h=(a.render||g).bind(a),x())};a.view||"function"===typeof a?f({},a):a.onmatch?W.resolve(a.onmatch(d,b)).then(function(d){f(a,d)},u):f(a,"div")},u)};e.set=function(a,b,e){null!=t&&(e=e||{},e.replace=!0);t=null;f.setPath(a,b,e)};e.get=function(){return m};
|
||||
e.prefix=function(a){f.prefix=a};var u=function(a,b){b.dom.setAttribute("href",f.prefix+b.attrs.href);b.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(f.prefix)&&(b=b.slice(f.prefix.length)),e.set(b,void 0,a))}};e.link=function(a){return null==a.tag?u.bind(u,a):u({},a)};e.param=function(a){return"undefined"!==typeof k&&"undefined"!==typeof a?k[a]:k};return e}(window,G);u.withAttr=function(a,b,f){return function(g){b.call(f||
|
||||
this,a in g.currentTarget?g.currentTarget[a]:g.currentTarget.getAttribute(a))}};var Y=Q(window);u.render=Y.render;u.redraw=G.redraw;u.request=L.request;u.jsonp=L.jsonp;u.parseQueryString=M;u.buildQueryString=D;u.version="1.1.3";u.vnode=w;u.PromisePolyfill=h;"undefined"!==typeof module?module.exports=u:window.m=u})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue