forked from MithrilJS/mithril.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mithril.min.js
45 lines (45 loc) · 22.3 KB
/
mithril.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
(function(){function x(a,d,e,f,k,l){return{tag:a,key:d,attrs:e,children:f,text:k,dom:l,domSize:void 0,state:void 0,events:void 0,instance:void 0,skip:!1}}function M(a){for(var d in a)if(C.call(a,d))return!1;return!0}function w(a){var d=arguments[1],e=2;if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a){var f;if(!(f=N[a])){var k="div";for(var l=[],m={};f=R.exec(a);){var p=f[1],
u=f[2];""===p&&""!==u?k=u:"#"===p?m.id=u:"."===p?l.push(u):"["===f[3][0]&&((p=f[6])&&(p=p.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===f[4]?l.push(p):m[f[4]]=""===p?p:p||!0)}0<l.length&&(m.className=l.join(" "));f=N[a]={tag:k,attrs:m}}}if(null==d)d={};else if("object"!==typeof d||null!=d.tag||Array.isArray(d))d={},e=1;if(arguments.length===e+1)k=arguments[e],Array.isArray(k)||(k=[k]);else for(k=[];e<arguments.length;)k.push(arguments[e++]);e=x.normalizeChildren(k);if("string"===typeof a){k=
!1;var r,z;l=d.className||d["class"];if(!M(f.attrs)&&!M(d)){m={};for(var b in d)C.call(d,b)&&(m[b]=d[b]);d=m}for(b in f.attrs)C.call(f.attrs,b)&&(d[b]=f.attrs[b]);void 0!==l&&(void 0!==d["class"]&&(d["class"]=void 0,d.className=l),null!=f.attrs.className&&(d.className=f.attrs.className+" "+l));for(b in d)if(C.call(d,b)&&"key"!==b){k=!0;break}Array.isArray(e)&&1===e.length&&null!=e[0]&&"#"===e[0].tag?z=e[0].children:r=e;return x(f.tag,d.key,k?d:void 0,r,z)}return x(a,d.key,d,e)}function S(a){var d=
0,e=null,f="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var k=Date.now()-d;null===e&&(e=f(function(){e=null;a();d=Date.now()},16-k))}}x.normalize=function(a){return Array.isArray(a)?x("[",void 0,void 0,x.normalizeChildren(a),void 0,void 0):null!=a&&"object"!==typeof a?x("#",void 0,void 0,!1===a?"":a,void 0,void 0):a};x.normalizeChildren=function(a){for(var d=0;d<a.length;d++)a[d]=x.normalize(a[d]);return a};var R=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
N={},C={}.hasOwnProperty;w.trust=function(a){null==a&&(a="");return x("<",void 0,void 0,a,void 0,void 0)};w.fragment=function(a,d){return x("[",a.key,a,x.normalizeChildren(d),void 0,void 0)};var n=function(a){function d(a,b){return function G(d){var h;try{if(!b||null==d||"object"!==typeof d&&"function"!==typeof d||"function"!==typeof(h=d.then))r(function(){b||0!==a.length||console.error("Possible unhandled promise rejection:",d);for(var e=0;e<a.length;e++)a[e](d);k.length=0;l.length=0;u.state=b;u.retry=
function(){G(d)}});else{if(d===f)throw new TypeError("Promise can't be resolved w/ itself");e(h.bind(d))}}catch(T){p(T)}}}function e(a){function b(b){return function(a){0<d++||b(a)}}var d=0,e=b(p);try{a(b(m),e)}catch(G){e(G)}}if(!(this instanceof n))throw Error("Promise must be called with `new`");if("function"!==typeof a)throw new TypeError("executor must be a function");var f=this,k=[],l=[],m=d(k,!0),p=d(l,!1),u=f._instance={resolvers:k,rejectors:l},r="function"===typeof setImmediate?setImmediate:
setTimeout;e(a)};n.prototype.then=function(a,d){function e(a,d,e,m){d.push(function(b){if("function"!==typeof a)e(b);else try{k(a(b))}catch(A){l&&l(A)}});"function"===typeof f.retry&&m===f.state&&f.retry()}var f=this._instance,k,l,m=new n(function(a,d){k=a;l=d});e(a,f.resolvers,k,!0);e(d,f.rejectors,l,!1);return m};n.prototype["catch"]=function(a){return this.then(null,a)};n.prototype["finally"]=function(a){return this.then(function(d){return n.resolve(a()).then(function(){return d})},function(d){return n.resolve(a()).then(function(){return n.reject(d)})})};
n.resolve=function(a){return a instanceof n?a:new n(function(d){d(a)})};n.reject=function(a){return new n(function(d,e){e(a)})};n.all=function(a){return new n(function(d,e){var f=a.length,k=0,l=[];if(0===a.length)d([]);else for(var m=0;m<a.length;m++)(function(p){function u(a){k++;l[p]=a;k===f&&d(l)}null==a[p]||"object"!==typeof a[p]&&"function"!==typeof a[p]||"function"!==typeof a[p].then?u(a[p]):a[p].then(u,e)})(m)})};n.race=function(a){return new n(function(d,e){for(var f=0;f<a.length;f++)a[f].then(d,
e)})};"undefined"!==typeof window?("undefined"===typeof window.Promise?window.Promise=n:window.Promise.prototype["finally"]||(window.Promise.prototype["finally"]=n.prototype["finally"]),n=window.Promise):"undefined"!==typeof global&&("undefined"===typeof global.Promise?global.Promise=n:global.Promise.prototype["finally"]||(global.Promise.prototype["finally"]=n.prototype["finally"]),n=global.Promise);var E=function(a){function d(a,f){if(Array.isArray(f))for(var k=0;k<f.length;k++)d(a+"["+k+"]",f[k]);
else if("[object Object]"===Object.prototype.toString.call(f))for(k in f)d(a+"["+k+"]",f[k]);else e.push(encodeURIComponent(a)+(null!=f&&""!==f?"="+encodeURIComponent(f):""))}if("[object Object]"!==Object.prototype.toString.call(a))return"";var e=[],f;for(f in a)d(f,a[f]);return e.join("&")},U=/^file:\/\//i,K=function(a,d){function e(){function b(){0===--a&&"function"===typeof z&&z()}var a=0;return function D(d){var e=d.then;d.then=function(){a++;var f=e.apply(d,arguments);f.then(b,function(d){b();
if(0===a)throw d;});return D(f)};return d}}function f(b,a){if("string"===typeof b){var d=b;b=a||{};null==b.url&&(b.url=d)}return b}function k(b,a){if(null==a)return b;for(var d=b.match(/:[^\/]+/gi)||[],e=0;e<d.length;e++){var f=d[e].slice(1);null!=a[f]&&(b=b.replace(d[e],a[f]))}return b}function l(b,a){var d=E(a);if(""!==d){var e=0>b.indexOf("?")?"?":"&";b+=e+d}return b}function m(b){try{return""!==b?JSON.parse(b):null}catch(A){throw Error(b);}}function p(b){return b.responseText}function u(b,a){if("function"===
typeof b)if(Array.isArray(a))for(var d=0;d<a.length;d++)a[d]=new b(a[d]);else return new b(a);return a}var r=0,z;return{request:function(b,r){var h=e();b=f(b,r);var A=new d(function(d,e){null==b.method&&(b.method="GET");b.method=b.method.toUpperCase();var f="GET"===b.method||"TRACE"===b.method?!1:"boolean"===typeof b.useBody?b.useBody:!0;"function"!==typeof b.serialize&&(b.serialize="undefined"!==typeof FormData&&b.data instanceof FormData?function(b){return b}:JSON.stringify);"function"!==typeof b.deserialize&&
(b.deserialize=m);"function"!==typeof b.extract&&(b.extract=p);b.url=k(b.url,b.data);f?b.data=b.serialize(b.data):b.url=l(b.url,b.data);var h=new a.XMLHttpRequest,r=!1,A=h.abort;h.abort=function(){r=!0;A.call(h)};h.open(b.method,b.url,"boolean"===typeof b.async?b.async:!0,"string"===typeof b.user?b.user:void 0,"string"===typeof b.password?b.password:void 0);b.serialize!==JSON.stringify||!f||b.headers&&b.headers.hasOwnProperty("Content-Type")||h.setRequestHeader("Content-Type","application/json; charset=utf-8");
b.deserialize!==m||b.headers&&b.headers.hasOwnProperty("Accept")||h.setRequestHeader("Accept","application/json, text/*");b.withCredentials&&(h.withCredentials=b.withCredentials);b.timeout&&(h.timeout=b.timeout);for(var z in b.headers)({}).hasOwnProperty.call(b.headers,z)&&h.setRequestHeader(z,b.headers[z]);"function"===typeof b.config&&(h=b.config(h,b)||h);h.onreadystatechange=function(){if(!r&&4===h.readyState)try{var a=b.extract!==p?b.extract(h,b):b.deserialize(b.extract(h,b));if(b.extract!==p||
200<=h.status&&300>h.status||304===h.status||U.test(b.url))d(u(b.type,a));else{var f=Error(h.responseText);f.code=h.status;f.response=a;e(f)}}catch(V){e(V)}};f&&null!=b.data?h.send(b.data):h.send()});return!0===b.background?A:h(A)},jsonp:function(b,p){var h=e();b=f(b,p);var m=new d(function(d,e){var f=b.callbackName||"_mithril_"+Math.round(1E16*Math.random())+"_"+r++,h=a.document.createElement("script");a[f]=function(e){h.parentNode.removeChild(h);d(u(b.type,e));delete a[f]};h.onerror=function(){h.parentNode.removeChild(h);
e(Error("JSONP request failed"));delete a[f]};null==b.data&&(b.data={});b.url=k(b.url,b.data);b.data[b.callbackKey||"callback"]=f;h.src=l(b.url,b.data);a.document.documentElement.appendChild(h)});return!0===b.background?m:h(m)},setCompletionCallback:function(b){z=b}}}(window,n),Q=function(a){function d(b,c){if(b.state!==c)throw Error("`vnode.state` must not be modified");}function e(b){var c=b.state;try{return this.apply(c,arguments)}finally{d(b,c)}}function f(b,c,g,a,d,e,f){for(;g<a;g++){var q=c[g];
null!=q&&k(b,q,d,f,e)}}function k(q,c,g,a,d){var h=c.tag;if("string"===typeof h)switch(c.state={},null!=c.attrs&&I(c.attrs,c,g),h){case "#":c.dom=y.createTextNode(c.children);z(q,c.dom,d);break;case "<":l(q,c,a,d);break;case "[":var u=y.createDocumentFragment();null!=c.children&&(h=c.children,f(u,h,0,h.length,g,null,a));c.dom=u.firstChild;c.domSize=u.childNodes.length;z(q,u,d);break;default:var t=c.tag,p=(h=c.attrs)&&h.is;t=(a=c.attrs&&c.attrs.xmlns||P[c.tag]||a)?p?y.createElementNS(a,t,{is:p}):y.createElementNS(a,
t):p?y.createElement(t,{is:p}):y.createElement(t);c.dom=t;if(null!=h)for(u in p=a,h)D(c,u,null,h[u],p);z(q,t,d);null!=c.attrs&&null!=c.attrs.contenteditable?b(c):(null!=c.text&&(""!==c.text?t.textContent=c.text:c.children=[x("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(q=c.children,f(t,q,0,q.length,g,null,a),g=c.attrs,"select"===c.tag&&null!=g&&("value"in g&&D(c,"value",null,g.value,void 0),"selectedIndex"in g&&D(c,"selectedIndex",null,g.selectedIndex,void 0))))}else{a:{if("function"===
typeof c.tag.view){c.state=Object.create(c.tag);u=c.state.view;if(null!=u.$$reentrantLock$$)break a;u.$$reentrantLock$$=!0}else{c.state=void 0;u=c.tag;if(null!=u.$$reentrantLock$$)break a;u.$$reentrantLock$$=!0;c.state=null!=c.tag.prototype&&"function"===typeof c.tag.prototype.view?new c.tag(c):c.tag(c)}null!=c.attrs&&I(c.attrs,c,g);I(c.state,c,g);c.instance=x.normalize(e.call(c.state.view,c));if(c.instance===c)throw Error("A view cannot return the vnode it received as argument");u.$$reentrantLock$$=
null}null!=c.instance?(k(q,c.instance,g,a,d),c.dom=c.instance.dom,c.domSize=null!=c.dom?c.instance.domSize:0):c.domSize=0}}function l(b,c,a,d){var q=c.children.match(/^\s*?<(\w+)/im)||[];q=y.createElement(E[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=y.createDocumentFragment();a=q.firstChild;)c.appendChild(a);z(b,c,d)}function m(b,
c,a,d,e,l){if(c!==a&&(null!=c||null!=a))if(null==c)f(b,a,0,a.length,d,e,l);else if(null==a)A(c,0,c.length);else{for(var q=0,g=0,t=!0,m=!0;g<c.length;g++)if(null!=c[g]){t=null!=c[g].key;break}for(;q<a.length;q++)if(null!=a[q]){m=null!=a[q].key;break}if(t!==m)A(c,g,c.length),f(b,a,q,a.length,d,e,l);else if(m){m=c.length-1;for(var B=a.length-1,n,v;m>=g&&B>=q;)if(v=c[g],t=a[q],null==v)g++;else if(null==t)q++;else if(v.key===t.key)g++,q++,v!==t&&p(b,v,t,d,r(c,g,e),l);else if(t=a[B],null==v)g++;else if(null==
t)B--;else if(v.key===t.key)g++,q<B--&&z(b,u(v),e),v!==t&&p(b,v,t,d,e,l),null!=t.dom&&(e=t.dom);else break;for(;m>=g&&B>=q;){v=c[m];t=a[B];if(null==v)m--;else{if(null!=t)if(v.key===t.key)v!==t&&p(b,v,t,d,e,l),null!=t.dom&&(e=t.dom),m--;else{if(null==n){n=c;v=g;for(var y=m,x={};v<y;v++){var w=n[v];null!=w&&(w=w.key,null!=w&&(x[w]=v))}n=x}null!=t&&(v=n[t.key],null==v?k(b,t,d,l,e):(v=c[v],z(b,u(v),e),v!==t&&p(b,v,t,d,e,l),v.skip=!0),null!=t.dom&&(e=t.dom))}B--}if(B<q)break}f(b,a,q,B+1,d,e,l);A(c,g,m+
1)}else{m=c.length<a.length?c.length:a.length;for(q=q<g?q:g;q<m;q++)v=c[q],t=a[q],v===t||null==v&&null==t||(null==v?k(b,t,d,l,r(c,q+1,e)):null==t?h(v):p(b,v,t,d,r(c,q+1,e),l));c.length>m&&A(c,q,c.length);a.length>m&&f(b,a,q,a.length,d,e,l)}}}function p(a,c,g,d,f,r){var q=c.tag;if(q===g.tag){g.state=c.state;g.events=c.events;var t;var A;null!=g.attrs&&"function"===typeof g.attrs.onbeforeupdate&&(t=e.call(g.attrs.onbeforeupdate,g,c));"string"!==typeof g.tag&&"function"===typeof g.state.onbeforeupdate&&
(A=e.call(g.state.onbeforeupdate,g,c));void 0===t&&void 0===A||t||A?t=!1:(g.dom=c.dom,g.domSize=c.domSize,g.instance=c.instance,t=!0);if(!t)if("string"===typeof q)switch(null!=g.attrs&&J(g.attrs,g,d),q){case "#":c.children.toString()!==g.children.toString()&&(c.dom.nodeValue=g.children);g.dom=c.dom;break;case "<":c.children!==g.children?(u(c),l(a,g,r,f)):(g.dom=c.dom,g.domSize=c.domSize);break;case "[":m(a,c.children,g.children,d,f,r);c=0;d=g.children;g.dom=null;if(null!=d){for(var n=0;n<d.length;n++)r=
d[n],null!=r&&null!=r.dom&&(null==g.dom&&(g.dom=r.dom),c+=r.domSize||1);1!==c&&(g.domSize=c)}break;default:a=g.dom=c.dom;r=g.attrs&&g.attrs.xmlns||P[g.tag]||r;"textarea"===g.tag&&(null==g.attrs&&(g.attrs={}),null!=g.text&&(g.attrs.value=g.text,g.text=void 0));f=c.attrs;q=g.attrs;t=r;if(null!=q)for(n in q)D(g,n,f&&f[n],q[n],t);if(null!=f)for(n in f)null!=q&&n in q||("className"===n&&(n="class"),"o"!==n[0]||"n"!==n[1]||w(n)?"key"!==n&&g.dom.removeAttribute(n):O(g,n,void 0));null!=g.attrs&&null!=g.attrs.contenteditable?
b(g):null!=c.text&&null!=g.text&&""!==g.text?c.text.toString()!==g.text.toString()&&(c.dom.firstChild.nodeValue=g.text):(null!=c.text&&(c.children=[x("#",void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=g.text&&(g.children=[x("#",void 0,void 0,g.text,void 0,void 0)]),m(a,c.children,g.children,d,null,r))}else{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");null!=g.attrs&&J(g.attrs,g,d);J(g.state,g,d);null!=
g.instance?(null==c.instance?k(a,g.instance,d,r,f):p(a,c.instance,g.instance,d,f,r),g.dom=g.instance.dom,g.domSize=g.instance.domSize):null!=c.instance?(h(c.instance),g.dom=void 0,g.domSize=0):(g.dom=c.dom,g.domSize=c.domSize)}}else h(c),k(a,g,d,r,f)}function u(a){var c=a.domSize;if(null!=c||null==a.dom){var b=y.createDocumentFragment();if(0<c){for(a=a.dom;--c;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function r(a,c,b){for(;c<a.length;c++)if(null!=a[c]&&null!=
a[c].dom)return a[c].dom;return b}function z(a,c,b){null!=b?a.insertBefore(c,b):a.appendChild(c)}function b(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,b){for(;c<b;c++){var q=a[c];null!=q&&(q.skip?q.skip=!1:h(q))}}function h(a){function c(){if(++q===b&&(d(a,f),n(a),a.dom)){var c=a.domSize||1;if(1<c)for(var g=
a.dom;--c;){var e=g.nextSibling,h=e.parentNode;null!=h&&h.removeChild(e)}c=a.dom;g=c.parentNode;null!=g&&g.removeChild(c)}}var b=1,q=0,f=a.state;if(a.attrs&&"function"===typeof a.attrs.onbeforeremove){var h=e.call(a.attrs.onbeforeremove,a);null!=h&&"function"===typeof h.then&&(b++,h.then(c,c))}"string"!==typeof a.tag&&"function"===typeof a.state.onbeforeremove&&(h=e.call(a.state.onbeforeremove,a),null!=h&&"function"===typeof h.then&&(b++,h.then(c,c)));c()}function n(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&&n(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var b=a[c];null!=b&&n(b)}}function D(a,c,b,d,e){if("key"!==c&&"is"!==c&&!w(c)){if("o"===c[0]&&"n"===c[1])return O(a,c,d);if("undefined"===typeof d&&"value"===c&&b!==d)a.dom.value="";else if((b!==d||"value"===c||"checked"===c||"selectedIndex"===c||"selected"===c&&a.dom===y.activeElement||
"option"===a.tag&&a.dom.parentNode===y.activeElement||"object"===typeof d)&&void 0!==d){var g=a.dom;if("xlink:"===c.slice(0,6))g.setAttributeNS("http://www.w3.org/1999/xlink",c,d);else if("style"===c)if(a=b,null!=a&&null!=d&&"object"===typeof a&&"object"===typeof d&&d!==a){for(var f in d)d[f]!==a[f]&&(g.style[f]=d[f]);for(f in a)f in d||(g.style[f]="")}else if(a===d&&(g.style.cssText="",a=null),null==d)g.style.cssText="";else if("string"===typeof d)g.style.cssText=d;else for(f in"string"===typeof a&&
(g.style.cssText=""),d)g.style[f]=d[f];else if(c in g&&"href"!==c&&"list"!==c&&"form"!==c&&"width"!==c&&"height"!==c&&void 0===e&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===c){f=""+d;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===f&&a.dom===y.activeElement)return;if("select"===a.tag)if(null===d){if(-1===a.dom.selectedIndex&&a.dom===y.activeElement)return}else if(null!==b&&a.dom.value===f&&a.dom===y.activeElement)return;if("option"===a.tag&&null!=b&&a.dom.value===f)return}"input"===
a.tag&&"type"===c?g.setAttribute(c,d):g[c]=d}else"boolean"===typeof d?d?g.setAttribute(c,""):g.removeAttribute(c):g.setAttribute("className"===c?"class":c,d)}}}function w(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===a||"onbeforeupdate"===a}function H(){}function O(a,c,b){null!=a.events?a.events[c]!==b&&(null==b||"function"!==typeof b&&"object"!==typeof b?(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]=b)):null==b||"function"!==typeof b&&"object"!==typeof b||(a.events=new H,a.dom.addEventListener(c.slice(2),a.events,!1),a.events[c]=b)}function I(a,c,b){"function"===typeof a.oninit&&e.call(a.oninit,c);"function"===typeof a.oncreate&&b.push(e.bind(a.oncreate,c))}function J(a,c,b){"function"===typeof a.onupdate&&b.push(e.bind(a.onupdate,c))}var y=a.document;y.createDocumentFragment();var P={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},
C,E={caption:"table",thead:"table",tbody:"table",tfoot:"table",tr:"tbody",th:"tr",td:"tr",colgroup:"table",col:"colgroup"};H.prototype=Object.create(null);H.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 C&&C.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 b=[],d=y.activeElement,
f=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(c)||(c=[c]);m(a,a.vnodes,x.normalizeChildren(c),b,null,"http://www.w3.org/1999/xhtml"===f?void 0:f);a.vnodes=c;null!=d&&y.activeElement!==d&&d.focus();for(d=0;d<b.length;d++)b[d]()},setEventCallback:function(a){return C=a}}},F=function(a,d){function e(a){a=l.indexOf(a);-1<a&&l.splice(a,2)}function f(){if(m)throw Error("Nested m.redraw.sync() call");m=!0;for(var a=1;a<l.length;a+=2)try{l[a]()}catch(r){"undefined"!==typeof console&&console.error(r)}m=
!1}var k=Q(a);k.setEventCallback(function(a){!1===a.redraw?a.redraw=void 0:p()});var l=[],m=!1,p=(d||S)(f);p.sync=f;return{subscribe:function(a,d){e(a);l.push(a,d)},unsubscribe:e,redraw:p,render:k.render}}(window);K.setCompletionCallback(F.redraw);w.mount=function(a){return function(d,e){if(null===e)a.render(d,[]),a.unsubscribe(d);else{if(null==e.view&&"function"!==typeof e)throw Error("m.mount(element, component) expects a component, not a vnode");var f=function(){a.render(d,x(e))};a.subscribe(d,
f);f()}}}(F);var W=n,L=function(a){if(""===a||null==a)return{};"?"===a.charAt(0)&&(a=a.slice(1));a=a.split("&");for(var d={},e={},f=0;f<a.length;f++){var k=a[f].split("="),l=decodeURIComponent(k[0]);k=2===k.length?decodeURIComponent(k[1]):"";"true"===k?k=!0:"false"===k&&(k=!1);var m=l.split(/\]\[?|\[/),p=d;-1<l.indexOf("[")&&m.pop();for(var u=0;u<m.length;u++){l=m[u];var r=m[u+1];r=""==r||!isNaN(parseInt(r,10));var n=u===m.length-1;""===l&&(l=m.slice(0,u).join(),null==e[l]&&(e[l]=0),l=e[l]++);null==
p[l]&&(p[l]=n?k:r?[]:{});p=p[l]}}return d},X=function(a){function d(d){var f=a.location[d].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===d&&"/"!==f[0]&&(f="/"+f);return f}function e(a){return function(){null==m&&(m=l(function(){m=null;a()}))}}function f(a,d,f){var b=a.indexOf("?"),e=a.indexOf("#"),h=-1<b?b:-1<e?e:a.length;if(-1<b){b=L(a.slice(b+1,-1<e?e:a.length));for(var k in b)d[k]=b[k]}if(-1<e)for(k in d=L(a.slice(e+1)),d)f[k]=d[k];return a.slice(0,h)}var k="function"===typeof a.history.pushState,
l="function"===typeof setImmediate?setImmediate:setTimeout,m,p={prefix:"#!",getPath:function(){switch(p.prefix.charAt(0)){case "#":return d("hash").slice(p.prefix.length);case "?":return d("search").slice(p.prefix.length)+d("hash");default:return d("pathname").slice(p.prefix.length)+d("search")+d("hash")}},setPath:function(d,e,m){var b={},l={};d=f(d,b,l);if(null!=e){for(var h in e)b[h]=e[h];d=d.replace(/:([^\/]+)/g,function(a,d){delete b[d];return e[d]})}(h=E(b))&&(d+="?"+h);(l=E(l))&&(d+="#"+l);
k?(l=m?m.state:null,h=m?m.title:null,a.onpopstate(),m&&m.replace?a.history.replaceState(l,h,p.prefix+d):a.history.pushState(l,h,p.prefix+d)):a.location.href=p.prefix+d},defineRoutes:function(d,l,m){function b(){var b=p.getPath(),e={},k=f(b,e,e),n=a.history.state;if(null!=n)for(var u in n)e[u]=n[u];for(var r in d)if(n=new RegExp("^"+r.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),n.test(k)){k.replace(n,function(){for(var a=r.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,
1,-2),h=0;h<a.length;h++)e[a[h].replace(/:|\./g,"")]=decodeURIComponent(f[h]);l(d[r],e,b,r)});return}m(b,e)}k?a.onpopstate=e(b):"#"===p.prefix.charAt(0)&&(a.onhashchange=b);b()}};return p};w.route=function(a,d){var e=X(a),f=function(a){return a},k,l,m,p,n,r=function(a,r,h){function b(){null!=k&&d.render(a,k(x(l,m.key,m)))}if(null==a)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");var u=function(){b();u=d.redraw};d.subscribe(a,b);var w=function(a){if(a!==r)e.setPath(r,
null,{replace:!0});else throw Error("Could not resolve default route "+r);};e.defineRoutes(h,function(a,b,d){var e=n=function(a,h){e===n&&(l=null==h||"function"!==typeof h.view&&"function"!==typeof h?"div":h,m=b,p=d,n=null,k=(a.render||f).bind(a),u())};a.view||"function"===typeof a?e({},a):a.onmatch?W.resolve(a.onmatch(b,d)).then(function(b){e(a,b)},w):e(a,"div")},w)};r.set=function(a,d,f){null!=n&&(f=f||{},f.replace=!0);n=null;e.setPath(a,d,f)};r.get=function(){return p};r.prefix=function(a){e.prefix=
a};var w=function(a,d){d.dom.setAttribute("href",e.prefix+d.attrs.href);d.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)),r.set(b,void 0,a))}};r.link=function(a){return null==a.tag?w.bind(w,a):w({},a)};r.param=function(a){return"undefined"!==typeof m&&"undefined"!==typeof a?m[a]:m};return r}(window,F);w.withAttr=function(a,d,e){return function(f){d.call(e||this,
a in f.currentTarget?f.currentTarget[a]:f.currentTarget.getAttribute(a))}};var Y=Q(window);w.render=Y.render;w.redraw=F.redraw;w.request=K.request;w.jsonp=K.jsonp;w.parseQueryString=L;w.buildQueryString=E;w.version="1.1.3";w.vnode=x;w.PromisePolyfill=n;"undefined"!==typeof module?module.exports=w:window.m=w})();