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