From 9d3ce5fa6dd7bce9679de7cc5588f5680dd3d058 Mon Sep 17 00:00:00 2001 From: Isiah Meadows Date: Sat, 27 Jul 2019 20:29:19 -0400 Subject: [PATCH] v2.0.2 --- README.md | 2 +- mithril.js | 208 +++++++++++++++++++++++++++------------ mithril.min.js | 2 +- package-lock.json | 2 +- package.json | 2 +- scripts/generate-docs.js | 2 + scripts/release.js | 2 +- 7 files changed, 151 insertions(+), 69 deletions(-) diff --git a/README.md b/README.md index 0370747b..f08bfcbe 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 (9.55 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 (9.77 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 161bf135..14c514d1 100644 --- a/mithril.js +++ b/mithril.js @@ -363,9 +363,12 @@ var _12 = function($window) { } vnode3.dom = temp.firstChild vnode3.domSize = temp.childNodes.length + // Capture nodes to remove, so we don't confuse them. + vnode3.instance = [] var fragment = $doc.createDocumentFragment() var child while (child = temp.firstChild) { + vnode3.instance.push(child) fragment.appendChild(child) } insertNode(parent, fragment, nextSibling) @@ -538,7 +541,7 @@ var _12 = function($window) { function updateNodes(parent, old, vnodes, hooks, nextSibling, ns) { if (old === vnodes || old == null && vnodes == null) return else if (old == null || old.length === 0) createNodes(parent, vnodes, 0, vnodes.length, hooks, nextSibling, ns) - else if (vnodes == null || vnodes.length === 0) removeNodes(old, 0, old.length) + else if (vnodes == null || vnodes.length === 0) removeNodes(parent, old, 0, old.length) else { var isOldKeyed = old[0] != null && old[0].key != null var isKeyed0 = vnodes[0] != null && vnodes[0].key != null @@ -547,7 +550,7 @@ var _12 = function($window) { if (!isKeyed0) while (start < vnodes.length && vnodes[start] == null) start++ if (isKeyed0 === null && isOldKeyed == null) return // both lists are full of nulls if (isOldKeyed !== isKeyed0) { - removeNodes(old, oldStart, old.length) + removeNodes(parent, old, oldStart, old.length) createNodes(parent, vnodes, start, vnodes.length, hooks, nextSibling, ns) } else if (!isKeyed0) { // Don't index past the end of either list (causes deopts). @@ -561,10 +564,10 @@ var _12 = function($window) { v = vnodes[start] if (o === v || o == null && v == null) continue else if (o == null) createNode(parent, v, hooks, ns, getNextSibling(old, start + 1, nextSibling)) - else if (v == null) removeNode(o) + else if (v == null) removeNode(parent, o) else updateNode(parent, o, v, hooks, getNextSibling(old, start + 1, nextSibling), ns) } - if (old.length > commonLength) removeNodes(old, start, old.length) + if (old.length > commonLength) removeNodes(parent, old, start, old.length) if (vnodes.length > commonLength) createNodes(parent, vnodes, start, vnodes.length, hooks, nextSibling, ns) } else { // keyed diff @@ -591,9 +594,9 @@ var _12 = function($window) { if (start === end) break if (o.key !== ve.key || oe.key !== v.key) break topSibling = getNextSibling(old, oldStart, nextSibling) - insertNode(parent, toFragment(oe), topSibling) + moveNodes(parent, oe, topSibling) if (oe !== v) updateNode(parent, oe, v, hooks, topSibling, ns) - if (++start <= --end) insertNode(parent, toFragment(o), nextSibling) + if (++start <= --end) moveNodes(parent, o, nextSibling) if (o !== ve) updateNode(parent, o, ve, hooks, nextSibling, ns) if (ve.dom != null) nextSibling = ve.dom oldStart++; oldEnd-- @@ -611,7 +614,7 @@ var _12 = function($window) { oe = old[oldEnd] ve = vnodes[end] } - if (start > end) removeNodes(old, oldStart, oldEnd + 1) + if (start > end) removeNodes(parent, old, oldStart, oldEnd + 1) else if (oldStart > oldEnd) createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns) else { // inspired by ivi https://github.com/ivijs/ivi/ by Boris Kaul @@ -632,7 +635,7 @@ var _12 = function($window) { } } nextSibling = originalNextSibling - if (matched !== oldEnd - oldStart + 1) removeNodes(old, oldStart, oldEnd + 1) + if (matched !== oldEnd - oldStart + 1) removeNodes(parent, old, oldStart, oldEnd + 1) if (matched === 0) createNodes(parent, vnodes, start, end + 1, hooks, nextSibling, ns) else { if (pos === -1) { @@ -645,7 +648,7 @@ var _12 = function($window) { if (oldIndices[i-start] === -1) createNode(parent, v, hooks, ns, nextSibling) else { if (lisIndices[li] === i - start) li-- - else insertNode(parent, toFragment(v), nextSibling) + else moveNodes(parent, v, nextSibling) } if (v.dom != null) nextSibling = vnodes[i].dom } @@ -681,7 +684,7 @@ var _12 = function($window) { else updateComponent(parent, old, vnode3, hooks, nextSibling, ns) } else { - removeNode(old) + removeNode(parent, old) createNode(parent, vnode3, hooks, ns, nextSibling) } } @@ -693,7 +696,7 @@ var _12 = function($window) { } function updateHTML(parent, old, vnode3, ns, nextSibling) { if (old.children !== vnode3.children) { - toFragment(old) + removeHTML(parent, old) createHTML(parent, vnode3, ns, nextSibling) } else vnode3.dom = old.dom, vnode3.domSize = old.domSize @@ -747,7 +750,7 @@ var _12 = function($window) { vnode3.domSize = vnode3.instance.domSize } else if (old.instance != null) { - removeNode(old.instance) + removeNode(parent, old.instance) vnode3.dom = undefined vnode3.domSize = 0 } @@ -813,25 +816,50 @@ var _12 = function($window) { lisTemp.length = 0 return result } - function toFragment(vnode3) { - var count = vnode3.domSize - if (count != null || vnode3.dom == null) { - var fragment = $doc.createDocumentFragment() - if (count > 0) { - var dom = vnode3.dom - while (--count) fragment.appendChild(dom.nextSibling) - fragment.insertBefore(dom, fragment.firstChild) - } - return fragment - } - else return vnode3.dom - } function getNextSibling(vnodes, i, nextSibling) { for (; i < vnodes.length; i++) { if (vnodes[i] != null && vnodes[i].dom != null) return vnodes[i].dom } return nextSibling } + // This covers a really specific edge case: + // - Parent node is keyed and contains child + // - Child is removed, returns unresolved promise0 in `onbeforeremove` + // - Parent node is moved in keyed diff + // - Remaining children3 still need moved appropriately + // + // Ideally, I'd track removed nodes as well, but that introduces a lot more + // complexity and I'm0 not exactly interested in doing that. + function moveNodes(parent, vnode3, nextSibling) { + var frag = $doc.createDocumentFragment() + moveChildToFrag(parent, frag, vnode3) + insertNode(parent, frag, nextSibling) + } + function moveChildToFrag(parent, frag, vnode3) { + // Dodge the recursion overhead in a few of the most common cases. + while (vnode3.dom != null && vnode3.dom.parentNode === parent) { + if (typeof vnode3.tag !== "string") { + vnode3 = vnode3.instance + if (vnode3 != null) continue + } else if (vnode3.tag === "<") { + for (var i = 0; i < vnode3.instance.length; i++) { + frag.appendChild(vnode3.instance[i]) + } + } else if (vnode3.tag !== "[") { + // Don't recurse for text nodes *or* elements, just fragments + frag.appendChild(vnode3.dom) + } else if (vnode3.children.length === 1) { + vnode3 = vnode3.children[0] + if (vnode3 != null) continue + } else { + for (var i = 0; i < vnode3.children.length; i++) { + var child = vnode3.children[i] + if (child != null) moveChildToFrag(parent, frag, child) + } + } + break + } + } function insertNode(parent, dom, nextSibling) { if (nextSibling != null) parent.insertBefore(dom, nextSibling) else parent.appendChild(dom) @@ -849,41 +877,87 @@ var _12 = function($window) { else if (vnode3.text != null || children3 != null && children3.length !== 0) throw new Error("Child node of a contenteditable must be trusted") } //remove - function removeNodes(vnodes, start, end) { + function removeNodes(parent, vnodes, start, end) { for (var i = start; i < end; i++) { var vnode3 = vnodes[i] - if (vnode3 != null) removeNode(vnode3) + if (vnode3 != null) removeNode(parent, vnode3) } } - function removeNode(vnode3) { - var expected = 1, called = 0 + function removeNode(parent, vnode3) { + var mask = 0 var original = vnode3.state + var stateResult, attrsResult if (typeof vnode3.tag !== "string" && typeof vnode3.state.onbeforeremove === "function") { var result = callHook.call(vnode3.state.onbeforeremove, vnode3) if (result != null && typeof result.then === "function") { - expected++ - result.then(continuation, continuation) + mask = 1 + stateResult = result } } if (vnode3.attrs && typeof vnode3.attrs.onbeforeremove === "function") { var result = callHook.call(vnode3.attrs.onbeforeremove, vnode3) if (result != null && typeof result.then === "function") { - expected++ - result.then(continuation, continuation) + // eslint-disable-next-line no-bitwise + mask |= 2 + attrsResult = result } } - continuation() - function continuation() { - if (++called === expected) { - checkState(vnode3, original) - onremove(vnode3) - if (vnode3.dom) { - var parent = vnode3.dom.parentNode - var count = vnode3.domSize || 1 - while (--count) parent.removeChild(vnode3.dom.nextSibling) + checkState(vnode3, original) + // If we can, try to fast-path it and avoid all the overhead of awaiting + if (!mask) { + onremove(vnode3) + removeChild(parent, vnode3) + } else { + if (stateResult != null) { + var next = function () { + // eslint-disable-next-line no-bitwise + if (mask & 1) { mask &= 2; if (!mask) reallyRemove() } + } + stateResult.then(next, next) + } + if (attrsResult != null) { + var next = function () { + // eslint-disable-next-line no-bitwise + if (mask & 2) { mask &= 1; if (!mask) reallyRemove() } + } + attrsResult.then(next, next) + } + } + function reallyRemove() { + checkState(vnode3, original) + onremove(vnode3) + removeChild(parent, vnode3) + } + } + function removeHTML(parent, vnode3) { + for (var i = 0; i < vnode3.instance.length; i++) { + parent.removeChild(vnode3.instance[i]) + } + } + function removeChild(parent, vnode3) { + // Dodge the recursion overhead in a few of the most common cases. + while (vnode3.dom != null && vnode3.dom.parentNode === parent) { + if (typeof vnode3.tag !== "string") { + vnode3 = vnode3.instance + if (vnode3 != null) continue + } else if (vnode3.tag === "<") { + removeHTML(parent, vnode3) + } else { + if (vnode3.tag !== "[") { parent.removeChild(vnode3.dom) + if (!Array.isArray(vnode3.children)) break + } + if (vnode3.children.length === 1) { + vnode3 = vnode3.children[0] + if (vnode3 != null) continue + } else { + for (var i = 0; i < vnode3.children.length; i++) { + var child = vnode3.children[i] + if (child != null) removeChild(parent, child) + } } } + break } } function onremove(vnode3) { @@ -1254,7 +1328,7 @@ var _18 = function($window, Promise, oncompletion) { 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) { + var promise1 = new Promise(function(resolve, reject) { factory(buildPathname(url, args.params), args, function (data) { if (typeof args.type === "function") { if (Array.isArray(data)) { @@ -1267,32 +1341,32 @@ var _18 = function($window, Promise, oncompletion) { resolve(data) }, reject) }) - if (args.background === true) return promise0 - var count0 = 0 + if (args.background === true) return promise1 + var count = 0 function complete() { - if (--count0 === 0 && typeof oncompletion === "function") oncompletion() + if (--count === 0 && typeof oncompletion === "function") oncompletion() } - return wrap(promise0) - function wrap(promise0) { - var then1 = promise0.then + return wrap(promise1) + function wrap(promise1) { + var then1 = promise1.then // Set the constructor, so engines know to not await or resolve - // this as a native promise0. At the time of writing, this is0 + // this as a native promise1. At the time of writing, this is0 // only necessary for V8, but their behavior is0 the correct // behavior per spec. See this spec issue for more details: // https://github.com/tc39/ecma262/issues/1577. Also, see the // corresponding comment in `request0/tests/test-request0.js` for // a bit more background on the issue at hand. - promise0.constructor = PromiseProxy - promise0.then = function() { - count0++ - var next = then1.apply(promise0, arguments) - next.then(complete, function(e) { + promise1.constructor = PromiseProxy + promise1.then = function() { + count++ + var next0 = then1.apply(promise1, arguments) + next0.then(complete, function(e) { complete() - if (count0 === 0) throw e + if (count === 0) throw e }) - return wrap(next) + return wrap(next0) } - return promise0 + return promise1 } } } @@ -1420,8 +1494,6 @@ m.fragment = hyperscript.fragment m.mount = mountRedraw.mount var m3 = hyperscript var Promise = PromisePolyfill -// The extra `data0` parameter is2 for if you want to append to an existing -// parameters object. var parseQueryString = function(string) { if (string === "" || string == null) return {} if (string.charAt(0) === "?") string = string.slice(1) @@ -1446,9 +1518,17 @@ var parseQueryString = function(string) { } level = counters[key5]++ } + // Disallow direct prototype pollution + else if (level === "__proto__") break if (isValue) cursor[level] = value2 - else if (cursor[level] == null) cursor[level] = isNumber ? [] : {} - cursor = cursor[level] + else { + // Read own properties exclusively to disallow indirect + // prototype pollution + value2 = Object.getOwnPropertyDescriptor(cursor, level) + if (value2 != null) value2 = value2.value + if (value2 == null) value2 = cursor[level] = isNumber ? [] : {} + } + cursor = value2 } } return data0 @@ -1483,7 +1563,7 @@ var compileTemplate = function(template) { var keys = [] var regexp = new RegExp("^" + templateData.path.replace( // I escape literal text so people can use things like `:file.:ext` or - // `:lang-:locale` in routes. This is3 all merged into one pass so I + // `:lang-:locale` in routes. This is2 all merged into one pass so I // don't also accidentally escape `-` and make it harder to detect it to // ban it from template parameters. /:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g, @@ -1710,7 +1790,7 @@ var _25 = function($window, mountRedraw00) { onclick.handleEvent(e) } // Adapted from React Router's implementation: - // https://github.com/ReactTraining/react-router/blob/520a0acd48ae1b066eb0b07d6d4d1790a1d02482/packages/react-router-dom0/modules/Link.js + // https://github.com/ReactTraining/react-router/blob/520a0acd48ae1b066eb0b07d6d4d1790a1d02482/packages/react-router-dom/modules/Link.js // // Try to be flexible and intuitive in how we handle1 links. // Fun fact: links aren't as obvious to get right as you diff --git a/mithril.min.js b/mithril.min.js index 853b4c0f..69abb147 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1 +1 @@ -!function(){"use strict";function e(e,t,n,r,o,l){return{tag:e,key:t,attrs:n,children:r,text:o,dom:l,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||"boolean"==typeof t?null:"object"==typeof t?t:e("#",void 0,void 0,String(t),void 0,void 0)},e.normalizeChildren=function(t){var n=[];if(t.length){for(var r=null!=t[0]&&null!=t[0].key,o=1;o0&&(i.className=l.join(" ")),r[e]={tag:o,attrs:i}}(i),a):(a.tag=i,a)}if(i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n},(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=s(n,!0),l=s(r,!1),i=t._instance={resolvers:n,rejectors:r},u="function"==typeof setImmediate?setImmediate:setTimeout;function s(e,o){return function a(s){var f;try{if(!o||null==s||"object"!=typeof s&&"function"!=typeof s||"function"!=typeof(f=s.then))u(function(){o||0!==e.length||console.error("Possible unhandled promise rejection:",s);for(var t=0;t0||e(n)}}var r=n(l);try{e(n(o),r)}catch(e){r(e)}}c(e)}).prototype.then=function(e,t){var n,r,o=this._instance;function l(e,t,l,i){t.push(function(t){if("function"!=typeof e)l(t);else try{n(e(t))}catch(e){r&&r(e)}}),"function"==typeof o.retry&&i===o.state&&o.retry()}var i=new a(function(e,t){n=e,r=t});return l(e,o.resolvers,n,!0),l(t,o.rejectors,r,!1),i},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,l=[];if(0===e.length)t([]);else for(var i=0;i'+t.children+"",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length;for(var a,u=r.createDocumentFragment();a=i.firstChild;)u.appendChild(a);w(e,u,o)}function h(e,t,n,r,o,l){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)s(e,n,0,n.length,r,o,l);else if(null==n||0===n.length)x(t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,u=0,f=0;if(!i)for(;f=f&&j>=u&&(b=t[C],S=n[j],b.key===S.key);)b!==S&&p(e,b,S,r,o,l),null!=S.dom&&(o=S.dom),C--,j--;for(;C>=f&&j>=u&&(d=t[f],h=n[u],d.key===h.key);)f++,u++,d!==h&&p(e,d,h,r,g(t,f,o),l);for(;C>=f&&j>=u&&u!==j&&d.key===S.key&&b.key===h.key;)E=g(t,f,o),w(e,y(b),E),b!==h&&p(e,b,h,r,E,l),++u<=--j&&w(e,y(d),o),d!==S&&p(e,d,S,r,o,l),null!=S.dom&&(o=S.dom),f++,b=t[--C],S=n[j],d=t[f],h=n[u];for(;C>=f&&j>=u&&b.key===S.key;)b!==S&&p(e,b,S,r,o,l),null!=S.dom&&(o=S.dom),j--,b=t[--C],S=n[j];if(u>j)x(t,f,C+1);else if(f>C)s(e,n,u,j+1,r,o,l);else{var z,A,O=o,N=j-u+1,T=new Array(N),P=0,$=0,I=2147483647,L=0;for($=0;$=u;$--){null==z&&(z=v(t,f,C+1));var R=z[(S=n[$]).key];null!=R&&(I=R>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(m[o]=t[n-1]),t[n]=o)}}for(n=t.length,r=t[n-1];n-- >0;)t[n]=r,r=m[r];return m.length=0,t}(T)).length-1,$=j;$>=u;$--)h=n[$],-1===T[$-u]?c(e,h,r,l,o):A[P]===$-u?P--:w(e,y(h),o),null!=h.dom&&(o=n[$].dom);else for($=j;$>=u;$--)h=n[$],-1===T[$-u]&&c(e,h,r,l,o),null!=h.dom&&(o=n[$].dom)}}else{var _=t.length_&&x(t,u,t.length),n.length>_&&s(e,n,u,n.length,r,o,l)}}}function p(t,n,r,o,i,u){var s=n.tag;if(s===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,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}(r,n))return;if("string"==typeof s)switch(null!=r.attrs&&I(r.attrs,r,o),s){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?(y(t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize)}(t,n,r,u,i);break;case"[":!function(e,t,n,r,o,l){h(e,t.children,n.children,r,o,l);var i=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 g(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 O(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(z,A)}function N(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n)null!=(o=n[r])&&e.style.setProperty(O(r),String(o));else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(O(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(O(r))}}function T(){this._=n}function P(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 T,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}function $(e,t,n){"function"==typeof e.oninit&&a.call(e.oninit,t),"function"==typeof e.oncreate&&n.push(a.bind(e.oncreate,t))}function I(e,t,n){"function"==typeof e.onupdate&&n.push(a.bind(e.onupdate,t))}return T.prototype=Object.create(null),T.prototype.handleEvent=function(e){var t,n=this["on"+e.type];"function"==typeof n?t=n.call(e.currentTarget,e):"function"==typeof n.handleEvent&&n.handleEvent(e),this._&&!1!==e.redraw&&(0,this._)(),!1===t&&(e.preventDefault(),e.stopPropagation())},function(t,r,o){if(!t)throw new TypeError("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var l=[],i=u(),a=t.namespaceURI;null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]);var s=n;try{n="function"==typeof o?o:void 0,h(t,t.vnodes,r,l,null,"http://www.w3.org/1999/xhtml"===a?void 0:a)}finally{n=s}t.vnodes=r,null!=i&&u()!==i&&"function"==typeof i.focus&&i.focus();for(var c=0;c=0&&(o.splice(l,2),t(n,[],u)),null!=r&&(o.push(n,r),t(n,e(r),u))},redraw:u}}(u,requestAnimationFrame,console),c=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(v+=e.slice(n,o)),s>=0&&(v+=(n<0?"?":"&")+u.slice(s,h));var m=c(a);return m&&(v+=(n<0&&s<0?"?":"&")+m),r>=0&&(v+=e.slice(r)),d>=0&&(v+=(r<0?"":"&")+u.slice(d)),v},h=function(e,t,n){var r=0;function o(e){return new t(e)}function l(e){return function(r,l){"string"!=typeof r?(l=r,r=r.url):null==l&&(l={});var i=new t(function(t,n){e(d(r,l.params),l,function(e){if("function"==typeof l.type)if(Array.isArray(e))for(var n=0;n=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===c?e.target.responseType||"function"==typeof n.extract||(a=JSON.parse(e.target.responseText)):c&&"text"!==c||null==a&&(a=e.target.responseText),"function"==typeof n.extract?(a=n.extract(e.target,n),i=!0):"function"==typeof n.deserialize&&(a=n.deserialize(a)),i)r(a);else{try{l=e.target.responseText}catch(e){l=a}var u=new Error(l);u.code=e.target.status,u.response=a,o(u)}}catch(e){o(e)}},"function"==typeof n.config&&(f=n.config(f,n,t)||f)!==h&&(l=f.abort,f.abort=function(){d=!0,l.call(this)}),null==u?f.send():"function"==typeof n.serialize?f.send(n.serialize(u)):u instanceof e.FormData?f.send(u):f.send(JSON.stringify(u))}),jsonp:l(function(t,n,o,l){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+r++,a=e.document.createElement("script");e[i]=function(t){delete e[i],a.parentNode.removeChild(a),o(t)},a.onerror=function(){delete e[i],a.parentNode.removeChild(a),l(new Error("JSONP request failed"))},a.src=t+(t.indexOf("?")<0?"?":"&")+encodeURIComponent(n.callbackKey||"callback")+"="+encodeURIComponent(i),e.document.documentElement.appendChild(a)})}}(window,a,s.redraw),p=s,v=function(){return i.apply(this,arguments)};v.m=i,v.trust=i.trust,v.fragment=i.fragment,v.mount=p.mount;var m=i,y=a,g=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},o=0;o-1&&u.pop();for(var c=0;c1&&"/"===l[l.length-1]&&(l=l.slice(0,-1))):l="/",{path:l,params:t<0?{}:g(e.slice(t+1,r))}},b=function(e){var t=w(e),n=Object.keys(t.params),r=[],o=new RegExp("^"+t.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,function(e,t,n){return null==t?"\\"+e:(r.push({k:t,r:"..."===n}),"..."===n?"(.*)":"."===n?"([^/]+)\\.":"([^/]+)"+(n||""))})+"$");return function(e){for(var l=0;l0&&(i.className=l.join(" ")),r[e]={tag:o,attrs:i}}(i),a):(a.tag=i,a)}if(i.trust=function(t){return null==t&&(t=""),e("<",void 0,void 0,t,void 0,void 0)},i.fragment=function(){var n=t.apply(0,arguments);return n.tag="[",n.children=e.normalizeChildren(n.children),n},(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=s(n,!0),l=s(r,!1),i=t._instance={resolvers:n,rejectors:r},u="function"==typeof setImmediate?setImmediate:setTimeout;function s(e,o){return function a(s){var f;try{if(!o||null==s||"object"!=typeof s&&"function"!=typeof s||"function"!=typeof(f=s.then))u(function(){o||0!==e.length||console.error("Possible unhandled promise rejection:",s);for(var t=0;t0||e(n)}}var r=n(l);try{e(n(o),r)}catch(e){r(e)}}c(e)}).prototype.then=function(e,t){var n,r,o=this._instance;function l(e,t,l,i){t.push(function(t){if("function"!=typeof e)l(t);else try{n(e(t))}catch(e){r&&r(e)}}),"function"==typeof o.retry&&i===o.state&&o.retry()}var i=new a(function(e,t){n=e,r=t});return l(e,o.resolvers,n,!0),l(t,o.rejectors,r,!1),i},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,l=[];if(0===e.length)t([]);else for(var i=0;i'+t.children+"",i=i.firstChild):i.innerHTML=t.children,t.dom=i.firstChild,t.domSize=i.childNodes.length,t.instance=[];for(var a,u=r.createDocumentFragment();a=i.firstChild;)t.instance.push(a),u.appendChild(a);w(e,u,o)}function h(e,t,n,r,o,l){if(t!==n&&(null!=t||null!=n))if(null==t||0===t.length)s(e,n,0,n.length,r,o,l);else if(null==n||0===n.length)x(e,t,0,t.length);else{var i=null!=t[0]&&null!=t[0].key,a=null!=n[0]&&null!=n[0].key,u=0,f=0;if(!i)for(;f=f&&C>=u&&(w=t[S],b=n[C],w.key===b.key);)w!==b&&p(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),S--,C--;for(;S>=f&&C>=u&&(d=t[f],h=n[u],d.key===h.key);)f++,u++,d!==h&&p(e,d,h,r,y(t,f,o),l);for(;S>=f&&C>=u&&u!==C&&d.key===b.key&&w.key===h.key;)g(e,w,E=y(t,f,o)),w!==h&&p(e,w,h,r,E,l),++u<=--C&&g(e,d,o),d!==b&&p(e,d,b,r,o,l),null!=b.dom&&(o=b.dom),f++,w=t[--S],b=n[C],d=t[f],h=n[u];for(;S>=f&&C>=u&&w.key===b.key;)w!==b&&p(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),C--,w=t[--S],b=n[C];if(u>C)x(e,t,f,S+1);else if(f>S)s(e,n,u,C+1,r,o,l);else{var j,z,A=o,O=C-u+1,N=new Array(O),T=0,P=0,$=2147483647,I=0;for(P=0;P=u;P--){null==j&&(j=v(t,f,S+1));var L=j[(b=n[P]).key];null!=L&&($=L<$?L:-1,N[P-u]=L,w=t[L],t[L]=null,w!==b&&p(e,w,b,r,o,l),null!=b.dom&&(o=b.dom),I++)}if(o=A,I!==S-f+1&&x(e,t,f,S+1),0===I)s(e,n,u,C+1,r,o,l);else if(-1===$)for(T=(z=function(e){for(var t=[0],n=0,r=0,o=0,l=m.length=e.length,o=0;o>>1)+(r>>>1)+(n&r&1);e[t[a]]0&&(m[o]=t[n-1]),t[n]=o)}}for(n=t.length,r=t[n-1];n-- >0;)t[n]=r,r=m[r];return m.length=0,t}(N)).length-1,P=C;P>=u;P--)h=n[P],-1===N[P-u]?c(e,h,r,l,o):z[T]===P-u?T--:g(e,h,o),null!=h.dom&&(o=n[P].dom);else for(P=C;P>=u;P--)h=n[P],-1===N[P-u]&&c(e,h,r,l,o),null!=h.dom&&(o=n[P].dom)}}else{var R=t.lengthR&&x(e,t,u,t.length),n.length>R&&s(e,n,u,n.length,r,o,l)}}}function p(t,n,r,o,i,u){var s=n.tag;if(s===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,e.attrs=t.attrs,e.children=t.children,e.text=t.text,!0}(r,n))return;if("string"==typeof s)switch(null!=r.attrs&&_(r.attrs,r,o),s){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?(E(e,t),d(e,n,r,o)):(n.dom=t.dom,n.domSize=t.domSize)}(t,n,r,u,i);break;case"[":!function(e,t,n,r,o,l){h(e,t.children,n.children,r,o,l);var i=0,a=n.children;if(n.dom=null,null!=a){for(var u=0;u-1||null!=e.attrs&&e.attrs.is||"href"!==t&&"list"!==t&&"form"!==t&&"width"!==t&&"height"!==t)&&t in e.dom}var N=/[A-Z]/g;function T(e){return"-"+e.toLowerCase()}function P(e){return"-"===e[0]&&"-"===e[1]?e:"cssFloat"===e?"float":e.replace(N,T)}function $(e,t,n){if(t===n);else if(null==n)e.style.cssText="";else if("object"!=typeof n)e.style.cssText=n;else if(null==t||"object"!=typeof t)for(var r in e.style.cssText="",n)null!=(o=n[r])&&e.style.setProperty(P(r),String(o));else{for(var r in n){var o;null!=(o=n[r])&&(o=String(o))!==String(t[r])&&e.style.setProperty(P(r),o)}for(var r in t)null!=t[r]&&null==n[r]&&e.style.removeProperty(P(r))}}function I(){this._=n}function L(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 I,e.dom.addEventListener(t.slice(2),e.events,!1),e.events[t]=n)}function R(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 I.prototype=Object.create(null),I.prototype.handleEvent=function(e){var t,n=this["on"+e.type];"function"==typeof n?t=n.call(e.currentTarget,e):"function"==typeof n.handleEvent&&n.handleEvent(e),this._&&!1!==e.redraw&&(0,this._)(),!1===t&&(e.preventDefault(),e.stopPropagation())},function(t,r,o){if(!t)throw new TypeError("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var l=[],i=u(),a=t.namespaceURI;null==t.vnodes&&(t.textContent=""),r=e.normalizeChildren(Array.isArray(r)?r:[r]);var s=n;try{n="function"==typeof o?o:void 0,h(t,t.vnodes,r,l,null,"http://www.w3.org/1999/xhtml"===a?void 0:a)}finally{n=s}t.vnodes=r,null!=i&&u()!==i&&"function"==typeof i.focus&&i.focus();for(var c=0;c=0&&(o.splice(l,2),t(n,[],u)),null!=r&&(o.push(n,r),t(n,e(r),u))},redraw:u}}(u,requestAnimationFrame,console),c=function(e){if("[object Object]"!==Object.prototype.toString.call(e))return"";var t=[];for(var n in e)r(n,e[n]);return t.join("&");function r(e,n){if(Array.isArray(n))for(var o=0;o=0&&(v+=e.slice(n,o)),s>=0&&(v+=(n<0?"?":"&")+u.slice(s,h));var m=c(a);return m&&(v+=(n<0&&s<0?"?":"&")+m),r>=0&&(v+=e.slice(r)),d>=0&&(v+=(r<0?"":"&")+u.slice(d)),v},h=function(e,t,n){var r=0;function o(e){return new t(e)}function l(e){return function(r,l){"string"!=typeof r?(l=r,r=r.url):null==l&&(l={});var i=new t(function(t,n){e(d(r,l.params),l,function(e){if("function"==typeof l.type)if(Array.isArray(e))for(var n=0;n=200&&e.target.status<300||304===e.target.status||/^file:\/\//i.test(t),a=e.target.response;if("json"===c?e.target.responseType||"function"==typeof n.extract||(a=JSON.parse(e.target.responseText)):c&&"text"!==c||null==a&&(a=e.target.responseText),"function"==typeof n.extract?(a=n.extract(e.target,n),i=!0):"function"==typeof n.deserialize&&(a=n.deserialize(a)),i)r(a);else{try{l=e.target.responseText}catch(e){l=a}var u=new Error(l);u.code=e.target.status,u.response=a,o(u)}}catch(e){o(e)}},"function"==typeof n.config&&(f=n.config(f,n,t)||f)!==h&&(l=f.abort,f.abort=function(){d=!0,l.call(this)}),null==u?f.send():"function"==typeof n.serialize?f.send(n.serialize(u)):u instanceof e.FormData?f.send(u):f.send(JSON.stringify(u))}),jsonp:l(function(t,n,o,l){var i=n.callbackName||"_mithril_"+Math.round(1e16*Math.random())+"_"+r++,a=e.document.createElement("script");e[i]=function(t){delete e[i],a.parentNode.removeChild(a),o(t)},a.onerror=function(){delete e[i],a.parentNode.removeChild(a),l(new Error("JSONP request failed"))},a.src=t+(t.indexOf("?")<0?"?":"&")+encodeURIComponent(n.callbackKey||"callback")+"="+encodeURIComponent(i),e.document.documentElement.appendChild(a)})}}(window,a,s.redraw),p=s,v=function(){return i.apply(this,arguments)};v.m=i,v.trust=i.trust,v.fragment=i.fragment,v.mount=p.mount;var m=i,y=a,g=function(e){if(""===e||null==e)return{};"?"===e.charAt(0)&&(e=e.slice(1));for(var t=e.split("&"),n={},r={},o=0;o-1&&u.pop();for(var c=0;c1&&"/"===l[l.length-1]&&(l=l.slice(0,-1))):l="/",{path:l,params:t<0?{}:g(e.slice(t+1,r))}},b=function(e){var t=w(e),n=Object.keys(t.params),r=[],o=new RegExp("^"+t.path.replace(/:([^\/.-]+)(\.{3}|\.(?!\.)|-)?|[\\^$*+.()|\[\]{}]/g,function(e,t,n){return null==t?"\\"+e:(r.push({k:t,r:"..."===n}),"..."===n?"(.*)":"."===n?"([^/]+)\\.":"([^/]+)"+(n||""))})+"$");return function(e){for(var l=0;l