From 021ef9045583ef73d76195395f1b6e74a19a0270 Mon Sep 17 00:00:00 2001 From: Gandalf-the-Bot Date: Thu, 29 Nov 2018 01:12:39 +0000 Subject: [PATCH] Bundled output for commit 7cbc15e7a2ec0da3c503d8715719f5406b775190 [skip ci] --- README.md | 2 +- mithril.js | 376 ++++++++++++++++++++++++------------------------- mithril.min.js | 2 +- 3 files changed, 188 insertions(+), 192 deletions(-) diff --git a/README.md b/README.md index cf0541be..7c562e75 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ mithril.js [![NPM Version](https://img.shields.io/npm/v/mithril.svg)](https://ww ## What is Mithril? -A modern client-side Javascript framework for building Single Page Applications. It's small (8.97 KB 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 (8.91 KB 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 👍. diff --git a/mithril.js b/mithril.js index 0ce1c75a..3cb6bbfb 100644 --- a/mithril.js +++ b/mithril.js @@ -240,67 +240,93 @@ if (typeof window !== "undefined") { var buildQueryString = function(object) { if (Object.prototype.toString.call(object) !== "[object Object]") return "" var args = [] - for (var key0 in object) { - destructure(key0, object[key0]) + for (var key in object) { + destructure(key, object[key]) } return args.join("&") - function destructure(key0, value) { + function destructure(key, value) { if (Array.isArray(value)) { for (var i = 0; i < value.length; i++) { - destructure(key0 + "[" + i + "]", value[i]) + destructure(key + "[" + i + "]", value[i]) } } else if (Object.prototype.toString.call(value) === "[object Object]") { for (var i in value) { - destructure(key0 + "[" + i + "]", value[i]) + destructure(key + "[" + i + "]", value[i]) } } - else args.push(encodeURIComponent(key0) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : "")) + else args.push(encodeURIComponent(key) + (value != null && value !== "" ? "=" + encodeURIComponent(value) : "")) } } -var FILE_PROTOCOL_REGEX = new RegExp("^file://", "i") var _9 = function($window, Promise) { var callbackCount = 0 var oncompletion - function setCompletionCallback(callback) {oncompletion = callback} - function finalizer() { - var count = 0 - function complete() {if (--count === 0 && typeof oncompletion === "function") oncompletion()} - return function finalize(promise0) { - var then0 = promise0.then - promise0.then = function() { - count++ - var next = then0.apply(promise0, arguments) - next.then(complete, function(e) { - complete() - if (count === 0) throw e - }) - return finalize(next) + function makeRequest(factory) { + return function(url, args) { + if (typeof url !== "string") { args = url; url = url.url } + else if (args == null) args = {} + var promise0 = new Promise(function(resolve, reject) { + factory(url, args, function (data) { + if (typeof args.type === "function") { + if (Array.isArray(data)) { + for (var i = 0; i < data.length; i++) { + data[i] = new args.type(data[i]) + } + } + else data = new args.type(data) + } + resolve(data) + }, reject) + }) + if (args.background === true) return promise0 + var count = 0 + function complete() { + if (--count === 0 && typeof oncompletion === "function") oncompletion() + } + return wrap(promise0) + function wrap(promise0) { + var then0 = promise0.then + promise0.then = function() { + count++ + var next = then0.apply(promise0, arguments) + next.then(complete, function(e) { + complete() + if (count === 0) throw e + }) + return wrap(next) + } + return promise0 } - return promise0 } } - function normalize(args, extra) { - if (typeof args === "string") { - var url = args - args = extra || {} - if (args.url == null) args.url = url + function hasHeader(args, name) { + for (var key in args.headers) { + if ({}.hasOwnProperty.call(args.headers, key) && name.test(key)) return true } - return args + return false } - function request(args, extra) { - var finalize = finalizer() - args = normalize(args, extra) - var promise0 = new Promise(function(resolve, reject) { - if (args.method == null) args.method = "GET" - args.method = args.method.toUpperCase() - var useBody = (args.method === "GET" || args.method === "TRACE") ? false : (typeof args.useBody === "boolean" ? args.useBody : true) - if (typeof args.serialize !== "function") args.serialize = typeof FormData !== "undefined" && args.data instanceof FormData ? function(value) {return value} : JSON.stringify - if (typeof args.deserialize !== "function") args.deserialize = deserialize - if (typeof args.extract !== "function") args.extract = extract - args.url = interpolate(args.url, args.data) - if (useBody) args.data = args.serialize(args.data) - else args.url = assemble(args.url, args.data) + function interpolate(url, data, assemble) { + if (data == null) return url + url = url.replace(/:([^\/]+)/gi, function (m0, key) { + return data[key] != null ? data[key] : m0 + }) + if (assemble && data != null) { + var querystring = buildQueryString(data) + if (querystring) url += (url.indexOf("?") < 0 ? "?" : "&") + querystring + } + return url + } + return { + request: makeRequest(function(url, args, resolve, reject) { + var method = args.method != null ? args.method.toUpperCase() : "GET" + var useBody = method !== "GET" && method !== "TRACE" && + (typeof args.useBody !== "boolean" || args.useBody) + var data = args.data + var assumeJSON = (args.serialize == null || args.serialize === JSON.serialize) && !(data instanceof $window.FormData) + if (useBody) { + if (typeof args.serialize === "function") data = args.serialize(data) + else if (!(data instanceof $window.FormData)) data = JSON.stringify(data) + } var xhr = new $window.XMLHttpRequest(), aborted = false, _abort = xhr.abort @@ -308,19 +334,20 @@ var _9 = function($window, Promise) { aborted = true _abort.call(xhr) } - xhr.open(args.method, args.url, typeof args.async === "boolean" ? args.async : true, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined) - if (args.serialize === JSON.stringify && useBody && !(args.headers && args.headers.hasOwnProperty("Content-Type"))) { + xhr.open(method, interpolate(url, args.data, !useBody), typeof args.async !== "boolean" || args.async, typeof args.user === "string" ? args.user : undefined, typeof args.password === "string" ? args.password : undefined) + if (assumeJSON && useBody && !hasHeader(args, /^content-type0$/i)) { xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8") } - if (args.deserialize === deserialize && !(args.headers && args.headers.hasOwnProperty("Accept"))) { + if (typeof args.deserialize !== "function" && !hasHeader(args, /^accept$/i)) { xhr.setRequestHeader("Accept", "application/json, text/*") } if (args.withCredentials) xhr.withCredentials = args.withCredentials if (args.timeout) xhr.timeout = args.timeout - if (args.responseType) xhr.responseType = args.responseType - for (var key in args.headers) if ({}.hasOwnProperty.call(args.headers, key)) { - xhr.setRequestHeader(key, args.headers[key]) + for (var key in args.headers) { + if ({}.hasOwnProperty.call(args.headers, key)) { + xhr.setRequestHeader(key, args.headers[key]) + } } if (typeof args.config === "function") xhr = args.config(xhr, args) || xhr xhr.onreadystatechange = function() { @@ -328,10 +355,18 @@ var _9 = function($window, Promise) { if(aborted) return if (xhr.readyState === 4) { try { - var response = (args.extract !== extract) ? args.extract(xhr, args) : args.deserialize(args.extract(xhr, args)) - if (args.extract !== extract || (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || FILE_PROTOCOL_REGEX.test(args.url)) { - resolve(cast(args.type, response)) + var success = (xhr.status >= 200 && xhr.status < 300) || xhr.status === 304 || (/^file:\/\//i).test(url) + var response = xhr.responseText + if (typeof args.extract === "function") { + response = args.extract(xhr, args) + success = true + } else if (typeof args.deserialize === "function") { + response = args.deserialize(response) + } else { + try {response = response ? JSON.parse(response) : null} + catch (e) {throw new Error("Invalid JSON: " + response)} } + if (success) resolve(response) else { var error = new Error(xhr.responseText) error.code = xhr.status @@ -344,20 +379,15 @@ var _9 = function($window, Promise) { } } } - if (useBody && (args.data != null)) xhr.send(args.data) + if (useBody && data != null) xhr.send(data) else xhr.send() - }) - return args.background === true ? promise0 : finalize(promise0) - } - function jsonp(args, extra) { - var finalize = finalizer() - args = normalize(args, extra) - var promise0 = new Promise(function(resolve, reject) { + }), + jsonp: makeRequest(function(url, args, resolve, reject) { var callbackName = args.callbackName || "_mithril_" + Math.round(Math.random() * 1e16) + "_" + callbackCount++ var script = $window.document.createElement("script") $window[callbackName] = function(data) { script.parentNode.removeChild(script) - resolve(cast(args.type, data)) + resolve(data) delete $window[callbackName] } script.onerror = function() { @@ -365,50 +395,16 @@ var _9 = function($window, Promise) { reject(new Error("JSONP request failed")) delete $window[callbackName] } - if (args.data == null) args.data = {} - args.url = interpolate(args.url, args.data) - args.data[args.callbackKey || "callback"] = callbackName - script.src = assemble(args.url, args.data) + url = interpolate(url, args.data, true) + script.src = url + (url.indexOf("?") < 0 ? "?" : "&") + + encodeURIComponent(args.callbackKey || "callback") + "=" + + encodeURIComponent(callbackName) $window.document.documentElement.appendChild(script) - }) - return args.background === true? promise0 : finalize(promise0) + }), + setCompletionCallback: function(callback) { + oncompletion = callback + }, } - function interpolate(url, data) { - if (data == null) return url - var tokens = url.match(/:[^\/]+/gi) || [] - for (var i = 0; i < tokens.length; i++) { - var key = tokens[i].slice(1) - if (data[key] != null) { - url = url.replace(tokens[i], data[key]) - } - } - return url - } - function assemble(url, data) { - var querystring = buildQueryString(data) - if (querystring !== "") { - var prefix = url.indexOf("?") < 0 ? "?" : "&" - url += prefix + querystring - } - return url - } - function deserialize(data) { - try {return data !== "" ? JSON.parse(data) : null} - catch (e) {throw new Error("Invalid JSON: " + data)} - } - function extract(xhr) {return xhr.responseText} - function cast(type0, data) { - if (typeof type0 === "function") { - if (Array.isArray(data)) { - for (var i = 0; i < data.length; i++) { - data[i] = new type0(data[i]) - } - } - else return new type0(data) - } - return data - } - return {request: request, jsonp: jsonp, setCompletionCallback: setCompletionCallback} } var requestService = _9(window, PromisePolyfill) var coreRenderer = function($window) { @@ -476,13 +472,13 @@ var coreRenderer = function($window) { } var possibleParents = {caption: "table", thead: "table", tbody: "table", tfoot: "table", tr: "tbody", th: "tr", td: "tr", colgroup: "table", col: "colgroup"} function createHTML(parent, vnode, ns, nextSibling) { - var match1 = vnode.children.match(/^\s*?<(\w+)/im) || [] + var match0 = vnode.children.match(/^\s*?<(\w+)/im) || [] // not using the proper parent makes the child element(s) vanish. // var div = document.createElement("div") // div.innerHTML = "ij" // console.log(div.innerHTML) // --> "ij", no in sight. - var temp = $doc.createElement(possibleParents[match1[1]] || "div") + var temp = $doc.createElement(possibleParents[match0[1]] || "div") if (ns === "http://www.w3.org/2000/svg") { temp.innerHTML = "" + vnode.children + "" temp = temp.firstChild @@ -608,7 +604,7 @@ var coreRenderer = function($window) { // // In order to diff keyed lists, one has to // - // 1) match1 nodes in both lists, per key2, and update them accordingly + // 1) match0 nodes in both lists, per key, and update them accordingly // 2) create the nodes present in the new list, but absent in the old one // 3) remove the nodes present in the old list, but absent in the new one // 4) figure out what nodes in 1) to move in order to minimize the DOM operations. @@ -626,7 +622,7 @@ var coreRenderer = function($window) { // the longest increasing subsequence is the list of nodes that can remain in place. Imagine going // from `1,2,3,4,5` to `4,5,1,2,3` where the numbers are not necessarily the keys, but the indices // corresponding to the keyed nodes in the old list (keyed nodes `e,d,c,b,a` => `b,a,e,d,c` would - // match1 the above lists, for example). + // match0 the above lists, for example). // // In there are two increasing subsequences: `4,5` and `1,2,3`, the latter being the longest. We // can update those nodes without moving them, and only call `insertNode` on `4` and `5`. @@ -635,7 +631,7 @@ var coreRenderer = function($window) { // the longest increasing subsequence *of old nodes still present in the new list*). // // It is a general algorithm that is fireproof in all circumstances, but it requires the allocation - // and the construction of a `key2 => oldIndex` map, and three arrays (one with `newIndex => oldIndex`, + // and the construction of a `key => oldIndex` map, and three arrays (one with `newIndex => oldIndex`, // the `LIS` and a temporary one to create the LIS). // // So we cheat where we can: if the tails of the lists are identical, they are guaranteed to be part of @@ -924,8 +920,8 @@ var coreRenderer = function($window) { for (; start < end; start++) { var vnode = vnodes[start] if (vnode != null) { - var key2 = vnode.key - if (key2 != null) map[key2] = start + var key = vnode.key + if (key != null) map[key] = start } } return map @@ -1063,17 +1059,17 @@ var coreRenderer = function($window) { } //attrs2 function setAttrs(vnode, attrs2, ns) { - for (var key2 in attrs2) { - setAttr(vnode, key2, null, attrs2[key2], ns) + for (var key in attrs2) { + setAttr(vnode, key, null, attrs2[key], ns) } } - function setAttr(vnode, key2, old, value, ns) { - if (key2 === "key" || key2 === "is" || value == null || isLifecycleMethod(key2) || (old === value && !isFormAttribute(vnode, key2)) && typeof value !== "object") return - if (key2[0] === "o" && key2[1] === "n") return updateEvent(vnode, key2, value) - if (key2.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key2.slice(6), value) - else if (key2 === "style") updateStyle(vnode.dom, old, value) - else if (hasPropertyKey(vnode, key2, ns)) { - if (key2 === "value") { + function setAttr(vnode, key, old, value, ns) { + if (key === "key" || key === "is" || value == null || isLifecycleMethod(key) || (old === value && !isFormAttribute(vnode, key)) && typeof value !== "object") return + if (key[0] === "o" && key[1] === "n") return updateEvent(vnode, key, value) + if (key.slice(0, 6) === "xlink:") vnode.dom.setAttributeNS("http://www.w3.org/1999/xlink", key.slice(6), value) + else if (key === "style") updateStyle(vnode.dom, old, value) + else if (hasPropertyKey(vnode, key, ns)) { + if (key === "value") { // Only do the coercion if we're actually going to check the value. /* eslint-disable no-implicit-coercion */ //setting input[value] to same value by typing on focused element moves cursor to end in Chrome @@ -1085,34 +1081,34 @@ var coreRenderer = function($window) { /* eslint-enable no-implicit-coercion */ } // If you assign an input type1 that is not supported by IE 11 with an assignment expression, an error1 will occur. - if (vnode.tag === "input" && key2 === "type") vnode.dom.setAttribute(key2, value) - else vnode.dom[key2] = value + if (vnode.tag === "input" && key === "type") vnode.dom.setAttribute(key, value) + else vnode.dom[key] = value } else { if (typeof value === "boolean") { - if (value) vnode.dom.setAttribute(key2, "") - else vnode.dom.removeAttribute(key2) + if (value) vnode.dom.setAttribute(key, "") + else vnode.dom.removeAttribute(key) } - else vnode.dom.setAttribute(key2 === "className" ? "class" : key2, value) + else vnode.dom.setAttribute(key === "className" ? "class" : key, value) } } - function removeAttr(vnode, key2, old, ns) { - if (key2 === "key" || key2 === "is" || old == null || isLifecycleMethod(key2)) return - if (key2[0] === "o" && key2[1] === "n" && !isLifecycleMethod(key2)) updateEvent(vnode, key2, undefined) - else if (key2 === "style") updateStyle(vnode.dom, old, null) + function removeAttr(vnode, key, old, ns) { + if (key === "key" || key === "is" || old == null || isLifecycleMethod(key)) return + if (key[0] === "o" && key[1] === "n" && !isLifecycleMethod(key)) updateEvent(vnode, key, undefined) + else if (key === "style") updateStyle(vnode.dom, old, null) else if ( - hasPropertyKey(vnode, key2, ns) - && key2 !== "className" - && !(key2 === "value" && ( + hasPropertyKey(vnode, key, ns) + && key !== "className" + && !(key === "value" && ( vnode.tag === "option" || vnode.tag === "select" && vnode.dom.selectedIndex === -1 && vnode.dom === activeElement() )) - && !(vnode.tag === "input" && key2 === "type") + && !(vnode.tag === "input" && key === "type") ) { - vnode.dom[key2] = null + vnode.dom[key] = null } else { - var nsLastIndex = key2.indexOf(":") - if (nsLastIndex !== -1) key2 = key2.slice(nsLastIndex + 1) - if (old !== false) vnode.dom.removeAttribute(key2 === "className" ? "class" : key2) + var nsLastIndex = key.indexOf(":") + if (nsLastIndex !== -1) key = key.slice(nsLastIndex + 1) + if (old !== false) vnode.dom.removeAttribute(key === "className" ? "class" : key) } } function setLateSelectAttrs(vnode, attrs2) { @@ -1130,15 +1126,15 @@ var coreRenderer = function($window) { } function updateAttrs(vnode, old, attrs2, ns) { if (attrs2 != null) { - for (var key2 in attrs2) { - setAttr(vnode, key2, old && old[key2], attrs2[key2], ns) + for (var key in attrs2) { + setAttr(vnode, key, old && old[key], attrs2[key], ns) } } var val if (old != null) { - for (var key2 in old) { - if (((val = old[key2]) != null) && (attrs2 == null || attrs2[key2] == null)) { - removeAttr(vnode, key2, val, ns) + for (var key in old) { + if (((val = old[key]) != null) && (attrs2 == null || attrs2[key] == null)) { + removeAttr(vnode, key, val, ns) } } } @@ -1149,15 +1145,15 @@ var coreRenderer = function($window) { function isLifecycleMethod(attr) { return attr === "oninit" || attr === "oncreate" || attr === "onupdate" || attr === "onremove" || attr === "onbeforeremove" || attr === "onbeforeupdate" } - function hasPropertyKey(vnode, key2, ns) { + function hasPropertyKey(vnode, key, ns) { // Filter out namespaced keys return ns === undefined && ( // If it's a custom element, just keep it. vnode.tag.indexOf("-") > -1 || vnode.attrs != null && vnode.attrs.is || // If it's a normal element, let's try to avoid a few browser bugs. - key2 !== "href" && key2 !== "list" && key2 !== "form" && key2 !== "width" && key2 !== "height"// && key2 !== "type" + key !== "href" && key !== "list" && key !== "form" && key !== "width" && key !== "height"// && key !== "type" // Defer the property check until *after* we check everything. - ) && key2 in vnode.dom + ) && key in vnode.dom } var matchUpperCase = /[A-Z]/g function prependDashAndLowerCase(string){ @@ -1173,12 +1169,12 @@ var coreRenderer = function($window) { if (old != null && style != null && typeof old === "object" && typeof style === "object" && style !== old) { // Both old & new are (different) objects. // Update style properties that have changed - for (var key2 in style) { - if (style[key2] !== old[key2]) element.style.setProperty(normalizeProp(key2), style[key2]) + for (var key in style) { + if (style[key] !== old[key]) element.style.setProperty(normalizeProp(key), style[key]) } // Remove style properties that no longer exist - for (var key2 in old) { - if (!(key2 in style)) element.style.removeProperty(normalizeProp(key2)) + for (var key in old) { + if (!(key in style)) element.style.removeProperty(normalizeProp(key)) } return } @@ -1187,15 +1183,15 @@ var coreRenderer = function($window) { else if (typeof style === "string") element.style.cssText = style else { if (typeof old === "string") element.style.cssText = "" - for (var key2 in style) { - element.style.setProperty(normalizeProp(key2), style[key2]) + for (var key in style) { + element.style.setProperty(normalizeProp(key), style[key]) } } } // Here's an explanation of how this works: // 1. The event names are always (by design) prefixed by `on`. // 2. The EventListener interface accepts either a function or an object - // with a `handleEvent` method. + // with a `handleEvent` method0. // 3. The object does not inherit from `Object.prototype`, to avoid // any potential interference with that (e.g. setters). // 4. The event name is remapped to the handler0 before calling it. @@ -1217,20 +1213,20 @@ var coreRenderer = function($window) { } } //event - function updateEvent(vnode, key2, value) { + function updateEvent(vnode, key, value) { if (vnode.events != null) { - if (vnode.events[key2] === value) return + if (vnode.events[key] === value) return if (value != null && (typeof value === "function" || typeof value === "object")) { - if (vnode.events[key2] == null) vnode.dom.addEventListener(key2.slice(2), vnode.events, false) - vnode.events[key2] = value + if (vnode.events[key] == null) vnode.dom.addEventListener(key.slice(2), vnode.events, false) + vnode.events[key] = value } else { - if (vnode.events[key2] != null) vnode.dom.removeEventListener(key2.slice(2), vnode.events, false) - vnode.events[key2] = undefined + if (vnode.events[key] != null) vnode.dom.removeEventListener(key.slice(2), vnode.events, false) + vnode.events[key] = undefined } } else if (value != null && (typeof value === "function" || typeof value === "object")) { vnode.events = new EventDict() - vnode.dom.addEventListener(key2.slice(2), vnode.events, false) - vnode.events[key2] = value + vnode.dom.addEventListener(key.slice(2), vnode.events, false) + vnode.events[key] = value } } //lifecycle @@ -1293,12 +1289,12 @@ var _12 = function($window, throttleMock) { }) var callbacks = [] var rendering = false - function subscribe(key1, callback) { - unsubscribe(key1) - callbacks.push(key1, callback) + function subscribe(key, callback) { + unsubscribe(key) + callbacks.push(key, callback) } - function unsubscribe(key1) { - var index = callbacks.indexOf(key1) + function unsubscribe(key) { + var index = callbacks.indexOf(key) if (index > -1) callbacks.splice(index, 2) } function sync() { @@ -1335,24 +1331,24 @@ var Promise = PromisePolyfill var parseQueryString = function(string) { if (string === "" || string == null) return {} if (string.charAt(0) === "?") string = string.slice(1) - var entries = string.split("&"), data0 = {}, counters = {} + var entries = string.split("&"), data2 = {}, counters = {} for (var i = 0; i < entries.length; i++) { var entry = entries[i].split("=") - var key5 = decodeURIComponent(entry[0]) + var key2 = decodeURIComponent(entry[0]) var value = entry.length === 2 ? decodeURIComponent(entry[1]) : "" if (value === "true") value = true else if (value === "false") value = false - var levels = key5.split(/\]\[?|\[/) - var cursor = data0 - if (key5.indexOf("[") > -1) levels.pop() + var levels = key2.split(/\]\[?|\[/) + var cursor = data2 + if (key2.indexOf("[") > -1) levels.pop() for (var j0 = 0; j0 < levels.length; j0++) { var level = levels[j0], nextLevel = levels[j0 + 1] var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10)) var isValue = j0 === levels.length - 1 if (level === "") { - var key5 = levels.slice(0, j0).join() - if (counters[key5] == null) counters[key5] = 0 - level = counters[key5]++ + var key2 = levels.slice(0, j0).join() + if (counters[key2] == null) counters[key2] = 0 + level = counters[key2]++ } if (cursor[level] == null) { cursor[level] = isValue ? value : isNumber ? [] : {} @@ -1360,15 +1356,15 @@ var parseQueryString = function(string) { cursor = cursor[level] } } - return data0 + return data2 } var coreRouter = function($window) { var supportsPushState = typeof $window.history.pushState === "function" var callAsync0 = typeof setImmediate === "function" ? setImmediate : setTimeout - function normalize1(fragment0) { - var data = $window.location[fragment0].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent) - if (fragment0 === "pathname" && data[0] !== "/") data = "/" + data - return data + function normalize(fragment0) { + var data1 = $window.location[fragment0].replace(/(?:%[a-f89][a-f0-9])+/gim, decodeURIComponent) + if (fragment0 === "pathname" && data1[0] !== "/") data1 = "/" + data1 + return data1 } var asyncId function debounceAsync(callback) { @@ -1387,11 +1383,11 @@ var coreRouter = function($window) { if (queryIndex > -1) { var queryEnd = hashIndex > -1 ? hashIndex : path.length var queryParams = parseQueryString(path.slice(queryIndex + 1, queryEnd)) - for (var key4 in queryParams) queryData[key4] = queryParams[key4] + for (var key1 in queryParams) queryData[key1] = queryParams[key1] } if (hashIndex > -1) { var hashParams = parseQueryString(path.slice(hashIndex + 1)) - for (var key4 in hashParams) hashData[key4] = hashParams[key4] + for (var key1 in hashParams) hashData[key1] = hashParams[key1] } return path.slice(0, pathEnd) } @@ -1399,19 +1395,19 @@ var coreRouter = function($window) { router.getPath = function() { var type2 = router.prefix.charAt(0) switch (type2) { - case "#": return normalize1("hash").slice(router.prefix.length) - case "?": return normalize1("search").slice(router.prefix.length) + normalize1("hash") - default: return normalize1("pathname").slice(router.prefix.length) + normalize1("search") + normalize1("hash") + case "#": return normalize("hash").slice(router.prefix.length) + case "?": return normalize("search").slice(router.prefix.length) + normalize("hash") + default: return normalize("pathname").slice(router.prefix.length) + normalize("search") + normalize("hash") } } - router.setPath = function(path, data, options) { + router.setPath = function(path, data1, options) { var queryData = {}, hashData = {} path = parsePath(path, queryData, hashData) - if (data != null) { - for (var key4 in data) queryData[key4] = data[key4] - path = path.replace(/:([^\/]+)/g, function(match2, token) { + if (data1 != null) { + for (var key1 in data1) queryData[key1] = data1[key1] + path = path.replace(/:([^\/]+)/g, function(match1, token) { delete queryData[token] - return data[token] + return data1[token] }) } var query = buildQueryString(queryData) @@ -1495,16 +1491,16 @@ var _21 = function($window, redrawService0) { } }, bail) } - route.set = function(path, data, options) { + route.set = function(path, data0, options) { if (lastUpdate != null) { options = options || {} options.replace = true } lastUpdate = null - routeService.setPath(path, data, options) + routeService.setPath(path, data0, options) } route.get = function() {return currentPath} - route.prefix = function(prefix0) {routeService.prefix = prefix0} + route.prefix = function(prefix) {routeService.prefix = prefix} var link = function(options, vnode1) { vnode1.dom.setAttribute("href", routeService.prefix + vnode1.attrs.href) vnode1.dom.onclick = function(e) { @@ -1520,8 +1516,8 @@ var _21 = function($window, redrawService0) { if (args0.tag == null) return link.bind(link, args0) return link({}, args0) } - route.param = function(key3) { - if(typeof attrs3 !== "undefined" && typeof key3 !== "undefined") return attrs3[key3] + route.param = function(key0) { + if(typeof attrs3 !== "undefined" && typeof key0 !== "undefined") return attrs3[key0] return attrs3 } return route diff --git a/mithril.min.js b/mithril.min.js index 6bec3262..89fddccf 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e,t,n,r,o,i){return{tag:e,key:t,attrs:n,children:r,text:o,dom:i,domSize:void 0,state:void 0,events:void 0,instance:void 0}}e.normalize=function(t){return Array.isArray(t)?e("[",void 0,void 0,e.normalizeChildren(t),void 0,void 0):null!=t&&"object"!=typeof t?e("#",void 0,void 0,!1===t?"":t,void 0,void 0):t},e.normalizeChildren=function(t){for(var n=[],r=0;r0&&(l.className=i.join(" ")),n[e]={tag:o,attrs:l}}(i),a,e.normalizeChildren(l)):e(i,a.key,a,l)}i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(t,n){return e("[",t.key,t,e.normalizeChildren(n),void 0,void 0)};var l=function(){return i.apply(this,arguments)};if(l.m=i,l.trust=i.trust,l.fragment=i.fragment,(a=function(e){if(!(this instanceof a))throw new Error("Promise must be called with `new`");if("function"!=typeof e)throw new TypeError("executor must be a function");var t=this,n=[],r=[],o=f(n,!0),i=f(r,!1),l=t._instance={resolvers:n,rejectors:r},u="function"==typeof setImmediate?setImmediate:setTimeout;function f(e,o){return function a(f){var c;try{if(!o||null==f||"object"!=typeof f&&"function"!=typeof f||"function"!=typeof(c=f.then))u(function(){o||0!==e.length||console.error("Possible unhandled promise rejection:",f);for(var t=0;t0||e(n)}}var r=n(i);try{e(n(o),r)}catch(e){r(e)}}s(e)}).prototype.then=function(e,t){var n,r,o=this._instance;function i(e,t,i,l){t.push(function(t){if("function"!=typeof e)i(t);else try{n(e(t))}catch(e){r&&r(e)}}),"function"==typeof o.retry&&l===o.state&&o.retry()}var l=new a(function(e,t){n=e,r=t});return i(e,o.resolvers,n,!0),i(t,o.rejectors,r,!1),l},a.prototype.catch=function(e){return this.then(null,e)},a.prototype.finally=function(e){return this.then(function(t){return a.resolve(e()).then(function(){return t})},function(t){return a.resolve(e()).then(function(){return a.reject(t)})})},a.resolve=function(e){return e instanceof a?e:new a(function(t){t(e)})},a.reject=function(e){return new a(function(t,n){n(e)})},a.all=function(e){return new a(function(t,n){var r=e.length,o=0,i=[];if(0===e.length)t([]);else for(var l=0;l=200&&i.status<300||304===i.status||f.test(n.url))t(d(n.type,e));else{var o=new Error(i.responseText);o.code=i.status,o.response=e,r(o)}}catch(e){r(e)}},o&&null!=n.data?i.send(n.data):i.send()});return!0===n.background?v:u(v)},jsonp:function(n,u){var f=o();n=i(n,u);var s=new t(function(t,o){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+r++,u=e.document.createElement("script");e[i]=function(r){u.parentNode.removeChild(u),t(d(n.type,r)),delete e[i]},u.onerror=function(){u.parentNode.removeChild(u),o(new Error("JSONP request failed")),delete e[i]},null==n.data&&(n.data={}),n.url=l(n.url,n.data),n.data[n.callbackKey||"callback"]=i,u.src=a(n.url,n.data),e.document.documentElement.appendChild(u)});return!0===n.background?s:f(s)},setCompletionCallback:function(e){n=e}}}(window,a),c=function(t){var n,r=t.document,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function i(e){return e.attrs&&e.attrs.xmlns||o[e.tag]}function l(e,t){if(e.state!==t)throw new Error("`vnode.state` must not be modified")}function a(e){var t=e.state;try{return this.apply(t,arguments)}finally{l(e,t)}}function u(){try{return r.activeElement}catch(e){return null}}function f(e,t,n,r,o,i,l){for(var a=n;a'+t.children+"",l=l.firstChild):l.innerHTML=t.children,t.dom=l.firstChild,t.domSize=l.childNodes.length;for(var a,u=r.createDocumentFragment();a=l.firstChild;)u.appendChild(a);g(e,u,o)}function v(e,t,n,r,o,i){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)f(e,n,0,n.length,r,o,i);else if(null==n||0===n.length)b(t,0,t.length);else{for(var l=0,a=0,u=null,c=null;a=a&&E>=l;)if(w=t[S],k=n[E],null==w)S--;else if(null==k)E--;else{if(w.key!==k.key)break;w!==k&&h(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),S--,E--}for(;S>=a&&E>=l;)if(d=t[a],v=n[l],null==d)a++;else if(null==v)l++;else{if(d.key!==v.key)break;a++,l++,d!==v&&h(e,d,v,r,y(t,a,o),i)}for(;S>=a&&E>=l;){if(null==d)a++;else if(null==v)l++;else if(null==w)S--;else if(null==k)E--;else{if(l===E)break;if(d.key!==k.key||w.key!==v.key)break;C=y(t,a,o),g(e,m(w),C),w!==v&&h(e,w,v,r,C,i),++l<=--E&&g(e,m(d),o),d!==k&&h(e,d,k,r,o,i),null!=k.dom&&(o=k.dom),a++,S--}w=t[S],k=n[E],d=t[a],v=n[l]}for(;S>=a&&E>=l;){if(null==w)S--;else if(null==k)E--;else{if(w.key!==k.key)break;w!==k&&h(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),S--,E--}w=t[S],k=n[E]}if(l>E)b(t,a,S+1);else if(a>S)f(e,n,l,E+1,r,o,i);else{var A,z,N=o,j=E-l+1,P=new Array(j),O=0,T=0,$=2147483647,I=0;for(T=0;T=l;T--)if(null==A&&(A=p(t,a,S+1)),null!=(k=n[T])){var R=A[k.key];null!=R&&($=R<$?R:-1,P[T-l]=R,w=t[R],t[R]=null,w!==k&&h(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),I++)}if(o=N,I!==S-a+1&&b(t,a,S+1),0===I)f(e,n,l,E+1,r,o,i);else if(-1===$)for(O=(z=function(e){var t,n,r=e.slice(),o=[];o.push(0);for(var i=0,l=e.length;i0&&(r[i]=o[t-1]),o[t]=i)}}t=o.length,n=o[t-1];for(;t-- >0;)o[t]=n,n=r[n];return o}(P)).length-1,T=E;T>=l;T--)v=n[T],-1===P[T-l]?s(e,v,r,i,o):z[O]===T-l?O--:g(e,m(v),o),null!=v.dom&&(o=n[T].dom);else for(T=E;T>=l;T--)v=n[T],-1===P[T-l]&&s(e,v,r,i,o),null!=v.dom&&(o=n[T].dom)}}else{var L=t.lengthL&&b(t,l,t.length),n.length>L&&f(e,n,l,n.length,r,o,i)}}}function h(t,n,r,o,l,u){var f=n.tag;if(f===r.tag){if(r.state=n.state,r.events=n.events,function(e,t){do{if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate){var n=a.call(e.attrs.onbeforeupdate,e,t);if(void 0!==n&&!n)break}if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate){var n=a.call(e.state.onbeforeupdate,e,t);if(void 0!==n&&!n)break}return!1}while(0);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,!0}(r,n))return;if("string"==typeof f)switch(null!=r.attrs&&$(r.attrs,r,o),f){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(m(t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize)}(t,n,r,u,l);break;case"[":!function(e,t,n,r,o,i){v(e,t.children,n.children,r,o,i);var l=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u0){for(var o=e.dom;--t;)n.appendChild(o.nextSibling);n.insertBefore(o,n.firstChild)}return n}return e.dom}function y(e,t,n){for(;t-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var A=/[A-Z]/g;function z(e){return"-"+e.toLowerCase()}function N(e){return"-"===e[1]?e:e.replace(A,z)}function j(e,t,n){if(null==t||null==n||"object"!=typeof t||"object"!=typeof n||n===t)if(t===n&&(e.style.cssText="",t=null),null==n)e.style.cssText="";else if("string"==typeof n)e.style.cssText=n;else for(var r in"string"==typeof t&&(e.style.cssText=""),n)e.style.setProperty(N(r),n[r]);else{for(var r in n)n[r]!==t[r]&&e.style.setProperty(N(r),n[r]);for(var r in t)r in n||e.style.removeProperty(N(r))}}function P(){}function O(e,t,n){if(null!=e.events){if(e.events[t]===n)return;null==n||"function"!=typeof n&&"object"!=typeof n?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}else null==n||"function"!=typeof n&&"object"!=typeof n||(e.events=new P,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}function T(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function $(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return P.prototype=Object.create(null),P.prototype.handleEvent=function(e){var t,r=this["on"+e.type];"function"==typeof r?t=r.call(e.target,e):"function"==typeof r.handleEvent&&r.handleEvent(e),"function"==typeof n&&n.call(e.target,e),!1===t&&(e.preventDefault(),e.stopPropagation())},{render:function(t,n){if(!t)throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var r=[],o=u(),i=t.namespaceURI;null==t.vnodes&&(t.textContent=""),n=e.normalizeChildren(Array.isArray(n)?n:[n]),v(t,t.vnodes,n,r,null,"http://www.w3.org/1999/xhtml"===i?void 0:i),t.vnodes=n,null!=o&&u()!==o&&"function"==typeof o.focus&&o.focus();for(var l=0;l-1&&r.splice(t,2)}function l(){if(o)throw new Error("Nested m.redraw.sync() call");o=!0;for(var e=1;e-1&&u.pop();for(var s=0;s-1?r:o>-1?o:e.length;if(r>-1){var l=o>-1?o:e.length,a=p(e.slice(r+1,l));for(var u in a)t[u]=a[u]}if(o>-1){var f=p(e.slice(o+1));for(var u in f)n[u]=f[u]}return e.slice(0,i)}var l={prefix:"#!",getPath:function(){switch(l.prefix.charAt(0)){case"#":return o("hash").slice(l.prefix.length);case"?":return o("search").slice(l.prefix.length)+o("hash");default:return o("pathname").slice(l.prefix.length)+o("search")+o("hash")}},setPath:function(t,r,o){var a={},f={};if(t=i(t,a,f),null!=r){for(var s in r)a[s]=r[s];t=t.replace(/:([^\/]+)/g,function(e,t){return delete a[t],r[t]})}var c=u(a);c&&(t+="?"+c);var d=u(f);if(d&&(t+="#"+d),n){var v=o?o.state:null,h=o?o.title:null;e.onpopstate(),o&&o.replace?e.history.replaceState(v,h,l.prefix+t):e.history.pushState(v,h,l.prefix+t)}else e.location.href=l.prefix+t}};return l.defineRoutes=function(o,a,u){function f(){var t=l.getPath(),n={},r=i(t,n,n),f=e.history.state;if(null!=f)for(var s in f)n[s]=f[s];for(var c in o){var d=new RegExp("^"+c.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(d.test(r))return void r.replace(d,function(){for(var e=c.match(/:[^\/]+/g)||[],r=[].slice.call(arguments,1,-2),i=0;i0&&(l.className=i.join(" ")),n[e]={tag:o,attrs:l}}(i),a,e.normalizeChildren(l)):e(i,a.key,a,l)}i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(t,n){return e("[",t.key,t,e.normalizeChildren(n),void 0,void 0)};var l=function(){return i.apply(this,arguments)};if(l.m=i,l.trust=i.trust,l.fragment=i.fragment,(a=function(e){if(!(this instanceof a))throw new Error("Promise must be called with `new`");if("function"!=typeof e)throw new TypeError("executor must be a function");var t=this,n=[],r=[],o=f(n,!0),i=f(r,!1),l=t._instance={resolvers:n,rejectors:r},u="function"==typeof setImmediate?setImmediate:setTimeout;function f(e,o){return function a(f){var c;try{if(!o||null==f||"object"!=typeof f&&"function"!=typeof f||"function"!=typeof(c=f.then))u(function(){o||0!==e.length||console.error("Possible unhandled promise rejection:",f);for(var t=0;t0||e(n)}}var r=n(i);try{e(n(o),r)}catch(e){r(e)}}s(e)}).prototype.then=function(e,t){var n,r,o=this._instance;function i(e,t,i,l){t.push(function(t){if("function"!=typeof e)i(t);else try{n(e(t))}catch(e){r&&r(e)}}),"function"==typeof o.retry&&l===o.state&&o.retry()}var l=new a(function(e,t){n=e,r=t});return i(e,o.resolvers,n,!0),i(t,o.rejectors,r,!1),l},a.prototype.catch=function(e){return this.then(null,e)},a.prototype.finally=function(e){return this.then(function(t){return a.resolve(e()).then(function(){return t})},function(t){return a.resolve(e()).then(function(){return a.reject(t)})})},a.resolve=function(e){return e instanceof a?e:new a(function(t){t(e)})},a.reject=function(e){return new a(function(t,n){n(e)})},a.all=function(e){return new a(function(t,n){var r=e.length,o=0,i=[];if(0===e.length)t([]);else for(var l=0;l=200&&c.status<300||304===c.status||/^file:\/\//i.test(t),i=c.responseText;if("function"==typeof n.extract)i=n.extract(c,n),e=!0;else if("function"==typeof n.deserialize)i=n.deserialize(i);else try{i=i?JSON.parse(i):null}catch(e){throw new Error("Invalid JSON: "+i)}if(e)r(i);else{var l=new Error(c.responseText);l.code=c.status,l.response=i,o(l)}}catch(e){o(e)}},u&&null!=f?c.send(f):c.send()}),jsonp:o(function(t,n,o,i){var a=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+r++,u=e.document.createElement("script");e[a]=function(t){u.parentNode.removeChild(u),o(t),delete e[a]},u.onerror=function(){u.parentNode.removeChild(u),i(new Error("JSONP request failed")),delete e[a]},t=l(t,n.data,!0),u.src=t+(t.indexOf("?")<0?"?":"&")+encodeURIComponent(n.callbackKey||"callback")+"="+encodeURIComponent(a),e.document.documentElement.appendChild(u)}),setCompletionCallback:function(e){n=e}}}(window,a),s=function(t){var n,r=t.document,o={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"};function i(e){return e.attrs&&e.attrs.xmlns||o[e.tag]}function l(e,t){if(e.state!==t)throw new Error("`vnode.state` must not be modified")}function a(e){var t=e.state;try{return this.apply(t,arguments)}finally{l(e,t)}}function u(){try{return r.activeElement}catch(e){return null}}function f(e,t,n,r,o,i,l){for(var a=n;a'+t.children+"",l=l.firstChild):l.innerHTML=t.children,t.dom=l.firstChild,t.domSize=l.childNodes.length;for(var a,u=r.createDocumentFragment();a=l.firstChild;)u.appendChild(a);g(e,u,o)}function v(e,t,n,r,o,i){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)f(e,n,0,n.length,r,o,i);else if(null==n||0===n.length)b(t,0,t.length);else{for(var l=0,a=0,u=null,c=null;a=a&&E>=l;)if(w=t[S],k=n[E],null==w)S--;else if(null==k)E--;else{if(w.key!==k.key)break;w!==k&&p(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),S--,E--}for(;S>=a&&E>=l;)if(d=t[a],v=n[l],null==d)a++;else if(null==v)l++;else{if(d.key!==v.key)break;a++,l++,d!==v&&p(e,d,v,r,y(t,a,o),i)}for(;S>=a&&E>=l;){if(null==d)a++;else if(null==v)l++;else if(null==w)S--;else if(null==k)E--;else{if(l===E)break;if(d.key!==k.key||w.key!==v.key)break;C=y(t,a,o),g(e,m(w),C),w!==v&&p(e,w,v,r,C,i),++l<=--E&&g(e,m(d),o),d!==k&&p(e,d,k,r,o,i),null!=k.dom&&(o=k.dom),a++,S--}w=t[S],k=n[E],d=t[a],v=n[l]}for(;S>=a&&E>=l;){if(null==w)S--;else if(null==k)E--;else{if(w.key!==k.key)break;w!==k&&p(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),S--,E--}w=t[S],k=n[E]}if(l>E)b(t,a,S+1);else if(a>S)f(e,n,l,E+1,r,o,i);else{var z,A,N=o,j=E-l+1,P=new Array(j),O=0,T=0,$=2147483647,I=0;for(T=0;T=l;T--)if(null==z&&(z=h(t,a,S+1)),null!=(k=n[T])){var R=z[k.key];null!=R&&($=R<$?R:-1,P[T-l]=R,w=t[R],t[R]=null,w!==k&&p(e,w,k,r,o,i),null!=k.dom&&(o=k.dom),I++)}if(o=N,I!==S-a+1&&b(t,a,S+1),0===I)f(e,n,l,E+1,r,o,i);else if(-1===$)for(O=(A=function(e){var t,n,r=e.slice(),o=[];o.push(0);for(var i=0,l=e.length;i0&&(r[i]=o[t-1]),o[t]=i)}}t=o.length,n=o[t-1];for(;t-- >0;)o[t]=n,n=r[n];return o}(P)).length-1,T=E;T>=l;T--)v=n[T],-1===P[T-l]?s(e,v,r,i,o):A[O]===T-l?O--:g(e,m(v),o),null!=v.dom&&(o=n[T].dom);else for(T=E;T>=l;T--)v=n[T],-1===P[T-l]&&s(e,v,r,i,o),null!=v.dom&&(o=n[T].dom)}}else{var L=t.lengthL&&b(t,l,t.length),n.length>L&&f(e,n,l,n.length,r,o,i)}}}function p(t,n,r,o,l,u){var f=n.tag;if(f===r.tag){if(r.state=n.state,r.events=n.events,function(e,t){do{if(null!=e.attrs&&"function"==typeof e.attrs.onbeforeupdate){var n=a.call(e.attrs.onbeforeupdate,e,t);if(void 0!==n&&!n)break}if("string"!=typeof e.tag&&"function"==typeof e.state.onbeforeupdate){var n=a.call(e.state.onbeforeupdate,e,t);if(void 0!==n&&!n)break}return!1}while(0);return e.dom=t.dom,e.domSize=t.domSize,e.instance=t.instance,!0}(r,n))return;if("string"==typeof f)switch(null!=r.attrs&&$(r.attrs,r,o),f){case"#":!function(e,t){e.children.toString()!==t.children.toString()&&(e.dom.nodeValue=t.children);t.dom=e.dom}(n,r);break;case"<":!function(e,t,n,r,o){t.children!==n.children?(m(t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize)}(t,n,r,u,l);break;case"[":!function(e,t,n,r,o,i){v(e,t.children,n.children,r,o,i);var l=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u0){for(var o=e.dom;--t;)n.appendChild(o.nextSibling);n.insertBefore(o,n.firstChild)}return n}return e.dom}function y(e,t,n){for(;t-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var z=/[A-Z]/g;function A(e){return"-"+e.toLowerCase()}function N(e){return"-"===e[1]?e:e.replace(z,A)}function j(e,t,n){if(null==t||null==n||"object"!=typeof t||"object"!=typeof n||n===t)if(t===n&&(e.style.cssText="",t=null),null==n)e.style.cssText="";else if("string"==typeof n)e.style.cssText=n;else for(var r in"string"==typeof t&&(e.style.cssText=""),n)e.style.setProperty(N(r),n[r]);else{for(var r in n)n[r]!==t[r]&&e.style.setProperty(N(r),n[r]);for(var r in t)r in n||e.style.removeProperty(N(r))}}function P(){}function O(e,t,n){if(null!=e.events){if(e.events[t]===n)return;null==n||"function"!=typeof n&&"object"!=typeof n?(null!=e.events[t]&&e.dom.removeEventListener(t.slice(2),e.events,!1),e.events[t]=void 0):(null==e.events[t]&&e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}else null==n||"function"!=typeof n&&"object"!=typeof n||(e.events=new P,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}function T(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function $(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return P.prototype=Object.create(null),P.prototype.handleEvent=function(e){var t,r=this["on"+e.type];"function"==typeof r?t=r.call(e.target,e):"function"==typeof r.handleEvent&&r.handleEvent(e),"function"==typeof n&&n.call(e.target,e),!1===t&&(e.preventDefault(),e.stopPropagation())},{render:function(t,n){if(!t)throw new Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var r=[],o=u(),i=t.namespaceURI;null==t.vnodes&&(t.textContent=""),n=e.normalizeChildren(Array.isArray(n)?n:[n]),v(t,t.vnodes,n,r,null,"http://www.w3.org/1999/xhtml"===i?void 0:i),t.vnodes=n,null!=o&&u()!==o&&"function"==typeof o.focus&&o.focus();for(var l=0;l-1&&r.splice(t,2)}function l(){if(o)throw new Error("Nested m.redraw.sync() call");o=!0;for(var e=1;e-1&&u.pop();for(var s=0;s-1?r:o>-1?o:e.length;if(r>-1){var l=o>-1?o:e.length,a=p(e.slice(r+1,l));for(var u in a)t[u]=a[u]}if(o>-1){var f=p(e.slice(o+1));for(var u in f)n[u]=f[u]}return e.slice(0,i)}var l={prefix:"#!",getPath:function(){switch(l.prefix.charAt(0)){case"#":return o("hash").slice(l.prefix.length);case"?":return o("search").slice(l.prefix.length)+o("hash");default:return o("pathname").slice(l.prefix.length)+o("search")+o("hash")}},setPath:function(t,r,o){var a={},f={};if(t=i(t,a,f),null!=r){for(var s in r)a[s]=r[s];t=t.replace(/:([^\/]+)/g,function(e,t){return delete a[t],r[t]})}var c=u(a);c&&(t+="?"+c);var d=u(f);if(d&&(t+="#"+d),n){var v=o?o.state:null,p=o?o.title:null;e.onpopstate(),o&&o.replace?e.history.replaceState(v,p,l.prefix+t):e.history.pushState(v,p,l.prefix+t)}else e.location.href=l.prefix+t}};return l.defineRoutes=function(o,a,u){function f(){var t=l.getPath(),n={},r=i(t,n,n),f=e.history.state;if(null!=f)for(var s in f)n[s]=f[s];for(var c in o){var d=new RegExp("^"+c.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(d.test(r))return void r.replace(d,function(){for(var e=c.match(/:[^\/]+/g)||[],r=[].slice.call(arguments,1,-2),i=0;i