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