Commit 36097df8 authored by MrMan's avatar MrMan

Initial commit, basic boilerplate + mitrhil

parents
# Emacs
*~
\#*
*\#
# Vim
*.swp
# Build artifacts
dist/*
# NPM
node_modules
\ No newline at end of file
# MithMail - A demo mail client written in Mithril #
[ TODO: MithMail webp ]
This project goes with the [Mithril SystemJS and Rollup guide post over @ vadosware.io](). It's meant to be a demo of how to run the relatively simple combination of [Mithril](https://mithril.js.org/), [SystemJS](https://github.com/systemjs/systemjs)
, and [Rollup](https://rollupjs.org/) all together to write modern [Single Page Applications (SPAs)](https://en.wikipedia.org/wiki/Single-page_application).
Here are the pieces and how they fit together:
- **Mithril**: minimal yet capable component-driven library (more complete than others, since it includes routing and AJAX facilities)
- **SystemJS**: module loader
- **Rollup**: bundler that integrates with and uses SystemJS
For more background on these tools, check out their doucmentation/websites below:
[Mithril](https://mithril.js.org/)
[SystemJS (v2.0+)](https://github.com/systemjs/systemjs)
[Rollup](https://rollupjs.org/)
var App = {
view: function() {
return m("div", [
m("h1", "MithMail"),
m("span", "Hello world"),
]);
}
};
m.mount(document.body, App);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MithMail</title>
</head>
<body>
<script src="static/vendor/mithril/1.1.6/mithril.min.js"></script>
<script src="app.js"></script>
</body>
</html>
{
"name": "mithmail",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"async": {
"version": "1.5.2",
"resolved": "https://registry.npmjs.org/async/-/async-1.5.2.tgz",
"integrity": "sha1-7GphrlZIDAw8skHJVhjiCJL5Zyo=",
"dev": true
},
"colors": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
"integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=",
"dev": true
},
"corser": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/corser/-/corser-2.0.1.tgz",
"integrity": "sha1-jtolLsqrWEDc2XXOuQ2TcMgZ/4c=",
"dev": true
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"ecstatic": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/ecstatic/-/ecstatic-3.3.0.tgz",
"integrity": "sha512-EblWYTd+wPIAMQ0U4oYJZ7QBypT9ZUIwpqli0bKDjeIIQnXDBK2dXtZ9yzRCOlkW1HkO8gn7/FxLK1yPIW17pw==",
"dev": true,
"requires": {
"he": "^1.1.1",
"mime": "^1.6.0",
"minimist": "^1.1.0",
"url-join": "^2.0.5"
}
},
"eventemitter3": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.0.tgz",
"integrity": "sha512-ivIvhpq/Y0uSjcHDcOIccjmYjGLcP09MFGE7ysAwkAvkXfpZlC985pH2/ui64DKazbTW/4kN3yqozUxlXzI6cA==",
"dev": true
},
"follow-redirects": {
"version": "1.6.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.6.1.tgz",
"integrity": "sha512-t2JCjbzxQpWvbhts3l6SH1DKzSrx8a+SsaVf4h6bG4kOXUuPYS/kg2Lr4gQSb7eemaHqJkOThF1BGyjlUkO1GQ==",
"dev": true,
"requires": {
"debug": "=3.1.0"
}
},
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true
},
"http-proxy": {
"version": "1.17.0",
"resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.17.0.tgz",
"integrity": "sha512-Taqn+3nNvYRfJ3bGvKfBSRwy1v6eePlm3oc/aWVxZp57DQr5Eq3xhKJi7Z4hZpS8PC3H4qI+Yly5EmFacGuA/g==",
"dev": true,
"requires": {
"eventemitter3": "^3.0.0",
"follow-redirects": "^1.0.0",
"requires-port": "^1.0.0"
}
},
"http-server": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/http-server/-/http-server-0.11.1.tgz",
"integrity": "sha512-6JeGDGoujJLmhjiRGlt8yK8Z9Kl0vnl/dQoQZlc4oeqaUoAKQg94NILLfrY3oWzSyFaQCVNTcKE5PZ3cH8VP9w==",
"dev": true,
"requires": {
"colors": "1.0.3",
"corser": "~2.0.0",
"ecstatic": "^3.0.0",
"http-proxy": "^1.8.1",
"opener": "~1.4.0",
"optimist": "0.6.x",
"portfinder": "^1.0.13",
"union": "~0.4.3"
}
},
"mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==",
"dev": true
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
"mkdirp": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
"integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
"dev": true,
"requires": {
"minimist": "0.0.8"
},
"dependencies": {
"minimist": {
"version": "0.0.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=",
"dev": true
}
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
},
"opener": {
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/opener/-/opener-1.4.3.tgz",
"integrity": "sha1-XG2ixdflgx6P+jlklQ+NZnSskLg=",
"dev": true
},
"optimist": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/optimist/-/optimist-0.6.1.tgz",
"integrity": "sha1-2j6nRob6IaGaERwybpDrFaAZZoY=",
"dev": true,
"requires": {
"minimist": "~0.0.1",
"wordwrap": "~0.0.2"
},
"dependencies": {
"minimist": {
"version": "0.0.10",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.10.tgz",
"integrity": "sha1-3j+YVD2/lggr5IrRoMfNqDYwHc8=",
"dev": true
}
}
},
"portfinder": {
"version": "1.0.20",
"resolved": "https://registry.npmjs.org/portfinder/-/portfinder-1.0.20.tgz",
"integrity": "sha512-Yxe4mTyDzTd59PZJY4ojZR8F+E5e97iq2ZOHPz3HDgSvYC5siNad2tLooQ5y5QHyQhc3xVqvyk/eNA3wuoa7Sw==",
"dev": true,
"requires": {
"async": "^1.5.2",
"debug": "^2.2.0",
"mkdirp": "0.5.x"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
}
}
},
"qs": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/qs/-/qs-2.3.3.tgz",
"integrity": "sha1-6eha2+ddoLvkyOBHaghikPhjtAQ=",
"dev": true
},
"requires-port": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz",
"integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=",
"dev": true
},
"union": {
"version": "0.4.6",
"resolved": "https://registry.npmjs.org/union/-/union-0.4.6.tgz",
"integrity": "sha1-GY+9rrolTniLDvy2MLwR8kopWeA=",
"dev": true,
"requires": {
"qs": "~2.3.3"
}
},
"url-join": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-2.0.5.tgz",
"integrity": "sha1-WvIvGMBSoACkjXuCxenC4v7tpyg=",
"dev": true
},
"wordwrap": {
"version": "0.0.3",
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.3.tgz",
"integrity": "sha1-o9XabNXAvAAI03I0u68b7WMFkQc=",
"dev": true
}
}
}
{
"name": "mithmail",
"version": "1.0.0",
"description": "Demo project to showcase Mithril+SystemJS+Rollup",
"main": "index.html",
"repository": "git@gitlab.com:mrman/mithmail.git",
"author": "vados <vados@vadosware.io>",
"license": "MIT",
"private": true,
"scripts": {
"build": "npm run build-html && npm run build-js",
"build-html": "cp index.html dist/",
"build-js": "cp app.js dist/",
"build-static": "mkdir -p dist && cp -r static dist/",
"build-watch": "ls index.html app.js | entr -rc npm run build",
"serve": "./node_modules/.bin/http-server dist/"
},
"devDependencies": {
"http-server": "^0.11.1"
}
}
(function(){function B(b,d,f,g,e,n){return{tag:b,key:d,attrs:f,children:g,text:e,dom:n,domSize:void 0,state:void 0,_state:void 0,events:void 0,instance:void 0,skip:!1}}function N(b){for(var d in b)if(G.call(b,d))return!1;return!0}function D(b){var d=arguments[1],f=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 g;if(!(g=O[b])){var e="div";for(var n=[],h={};g=Q.exec(b);){var q=
g[1],m=g[2];""===q&&""!==m?e=m:"#"===q?h.id=m:"."===q?n.push(m):"["===g[3][0]&&((q=g[6])&&(q=q.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===g[4]?n.push(q):h[g[4]]=""===q?q:q||!0)}0<n.length&&(h.className=n.join(" "));g=O[b]={tag:e,attrs:h}}}if(null==d)d={};else if("object"!==typeof d||null!=d.tag||Array.isArray(d))d={},f=1;if(arguments.length===f+1)e=arguments[f],Array.isArray(e)||(e=[e]);else for(e=[];f<arguments.length;)e.push(arguments[f++]);f=B.normalizeChildren(e);if("string"===
typeof b){e=!1;var k,t;n=d.className||d["class"];if(!N(g.attrs)&&!N(d)){h={};for(var a in d)G.call(d,a)&&(h[a]=d[a]);d=h}for(a in g.attrs)G.call(g.attrs,a)&&(d[a]=g.attrs[a]);void 0!==n&&(void 0!==d["class"]&&(d["class"]=void 0,d.className=n),null!=g.attrs.className&&(d.className=g.attrs.className+" "+n));for(a in d)if(G.call(d,a)&&"key"!==a){e=!0;break}Array.isArray(f)&&1===f.length&&null!=f[0]&&"#"===f[0].tag?t=f[0].children:k=f;return B(g.tag,d.key,e?d:void 0,k,t)}return B(b,d.key,d,f)}function R(b){var d=
0,f=null,g="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(){var e=Date.now();0===d||16<=e-d?(d=e,b()):null===f&&(f=g(function(){f=null;b();d=Date.now()},16-(e-d)))}}B.normalize=function(b){return Array.isArray(b)?B("[",void 0,void 0,B.normalizeChildren(b),void 0,void 0):null!=b&&"object"!==typeof b?B("#",void 0,void 0,!1===b?"":b,void 0,void 0):b};B.normalizeChildren=function(b){for(var d=0;d<b.length;d++)b[d]=B.normalize(b[d]);return b};var Q=/(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g,
O={},G={}.hasOwnProperty;D.trust=function(b){null==b&&(b="");return B("<",void 0,void 0,b,void 0,void 0)};D.fragment=function(b,d){return B("[",b.key,b,B.normalizeChildren(d),void 0,void 0)};var x=function(b){function d(b,a){return function E(d){var h;try{if(!a||null==d||"object"!==typeof d&&"function"!==typeof d||"function"!==typeof(h=d.then))k(function(){a||0!==b.length||console.error("Possible unhandled promise rejection:",d);for(var f=0;f<b.length;f++)b[f](d);e.length=0;n.length=0;m.state=a;m.retry=
function(){E(d)}});else{if(d===g)throw new TypeError("Promise can't be resolved w/ itself");f(h.bind(d))}}catch(S){q(S)}}}function f(b){function a(a){return function(b){0<d++||a(b)}}var d=0,f=a(q);try{b(a(h),f)}catch(E){f(E)}}if(!(this instanceof x))throw Error("Promise must be called with `new`");if("function"!==typeof b)throw new TypeError("executor must be a function");var g=this,e=[],n=[],h=d(e,!0),q=d(n,!1),m=g._instance={resolvers:e,rejectors:n},k="function"===typeof setImmediate?setImmediate:
setTimeout;f(b)};x.prototype.then=function(b,d){function f(b,d,f,h){d.push(function(a){if("function"!==typeof b)f(a);else try{e(b(a))}catch(w){n&&n(w)}});"function"===typeof g.retry&&h===g.state&&g.retry()}var g=this._instance,e,n,h=new x(function(b,d){e=b;n=d});f(b,g.resolvers,e,!0);f(d,g.rejectors,n,!1);return h};x.prototype["catch"]=function(b){return this.then(null,b)};x.resolve=function(b){return b instanceof x?b:new x(function(d){d(b)})};x.reject=function(b){return new x(function(d,f){f(b)})};
x.all=function(b){return new x(function(d,f){var g=b.length,e=0,n=[];if(0===b.length)d([]);else for(var h=0;h<b.length;h++)(function(h){function m(b){e++;n[h]=b;e===g&&d(n)}null==b[h]||"object"!==typeof b[h]&&"function"!==typeof b[h]||"function"!==typeof b[h].then?m(b[h]):b[h].then(m,f)})(h)})};x.race=function(b){return new x(function(d,f){for(var g=0;g<b.length;g++)b[g].then(d,f)})};"undefined"!==typeof window?("undefined"===typeof window.Promise&&(window.Promise=x),x=window.Promise):"undefined"!==
typeof global&&("undefined"===typeof global.Promise&&(global.Promise=x),x=global.Promise);var F=function(b){function d(b,g){if(Array.isArray(g))for(var e=0;e<g.length;e++)d(b+"["+e+"]",g[e]);else if("[object Object]"===Object.prototype.toString.call(g))for(e in g)d(b+"["+e+"]",g[e]);else f.push(encodeURIComponent(b)+(null!=g&&""!==g?"="+encodeURIComponent(g):""))}if("[object Object]"!==Object.prototype.toString.call(b))return"";var f=[],g;for(g in b)d(g,b[g]);return f.join("&")},T=/^file:\/\//i,L=
function(b,d){function f(){function a(){0===--b&&"function"===typeof t&&t()}var b=0;return function u(d){var f=d.then;d.then=function(){b++;var e=f.apply(d,arguments);e.then(a,function(d){a();if(0===b)throw d;});return u(e)};return d}}function g(a,b){if("string"===typeof a){var d=a;a=b||{};null==a.url&&(a.url=d)}return a}function e(a,b){if(null==b)return a;for(var d=a.match(/:[^\/]+/gi)||[],f=0;f<d.length;f++){var e=d[f].slice(1);null!=b[e]&&(a=a.replace(d[f],b[e]))}return a}function n(a,b){var d=
F(b);if(""!==d){var f=0>a.indexOf("?")?"?":"&";a+=f+d}return a}function h(a){try{return""!==a?JSON.parse(a):null}catch(w){throw Error(a);}}function q(a){return a.responseText}function m(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 k=0,t;return{request:function(a,k){var t=f();a=g(a,k);var w=new d(function(d,f){null==a.method&&(a.method="GET");a.method=a.method.toUpperCase();var g="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=h);"function"!==typeof a.extract&&(a.extract=q);a.url=e(a.url,a.data);g?a.data=a.serialize(a.data):a.url=n(a.url,a.data);var k=new b.XMLHttpRequest,t=!1,w=k.abort;k.abort=function(){t=!0;w.call(k)};k.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||!g||a.headers&&a.headers.hasOwnProperty("Content-Type")||k.setRequestHeader("Content-Type","application/json; charset=utf-8");a.deserialize!==h||a.headers&&a.headers.hasOwnProperty("Accept")||k.setRequestHeader("Accept","application/json, text/*");a.withCredentials&&(k.withCredentials=a.withCredentials);for(var u in a.headers)({}).hasOwnProperty.call(a.headers,u)&&k.setRequestHeader(u,a.headers[u]);
"function"===typeof a.config&&(k=a.config(k,a)||k);k.onreadystatechange=function(){if(!t&&4===k.readyState)try{var b=a.extract!==q?a.extract(k,a):a.deserialize(a.extract(k,a));if(200<=k.status&&300>k.status||304===k.status||T.test(a.url))d(m(a.type,b));else{var l=Error(k.responseText),c;for(c in b)l[c]=b[c];f(l)}}catch(p){f(p)}};g&&null!=a.data?k.send(a.data):k.send()});return!0===a.background?w:t(w)},jsonp:function(a,h){var t=f();a=g(a,h);var q=new d(function(d,f){var g=a.callbackName||"_mithril_"+
Math.round(1E16*Math.random())+"_"+k++,h=b.document.createElement("script");b[g]=function(f){h.parentNode.removeChild(h);d(m(a.type,f));delete b[g]};h.onerror=function(){h.parentNode.removeChild(h);f(Error("JSONP request failed"));delete b[g]};null==a.data&&(a.data={});a.url=e(a.url,a.data);a.data[a.callbackKey||"callback"]=g;h.src=n(a.url,a.data);b.document.documentElement.appendChild(h)});return!0===a.background?q:t(q)},setCompletionCallback:function(a){t=a}}}(window,x),P=function(b){function d(l,
c,p,a,b,d,g){for(;p<a;p++){var v=c[p];null!=v&&f(l,v,b,g,d)}}function f(l,c,p,a,b){var v=c.tag;if("string"===typeof v)switch(c.state={},null!=c.attrs&&D(c.attrs,c,p),v){case "#":return c.dom=A.createTextNode(c.children),k(l,c.dom,b),c.dom;case "<":return g(l,c,b);case "[":var h=A.createDocumentFragment();null!=c.children&&(v=c.children,d(h,v,0,v.length,p,null,a));c.dom=h.firstChild;c.domSize=h.childNodes.length;k(l,h,b);return h;default:var m=c.tag,r=(v=c.attrs)&&v.is;m=(a=c.attrs&&c.attrs.xmlns||
G[c.tag]||a)?r?A.createElementNS(a,m,{is:r}):A.createElementNS(a,m):r?A.createElement(m,{is:r}):A.createElement(m);c.dom=m;if(null!=v)for(h in r=a,v)E(c,h,null,v[h],r);k(l,m,b);null!=c.attrs&&null!=c.attrs.contenteditable?t(c):(null!=c.text&&(""!==c.text?m.textContent=c.text:c.children=[B("#",void 0,void 0,c.text,void 0,void 0)]),null!=c.children&&(l=c.children,d(m,l,0,l.length,p,null,a),l=c.attrs,"select"===c.tag&&null!=l&&("value"in l&&E(c,"value",null,l.value,void 0),"selectedIndex"in l&&E(c,"selectedIndex",
null,l.selectedIndex,void 0))));return m}else return e(c,p),null!=c.instance?(p=f(l,c.instance,p,a,b),c.dom=c.instance.dom,c.domSize=null!=c.dom?c.instance.domSize:0,k(l,p,b),c=p):(c.domSize=0,c=K),c}function g(l,c,a){var p={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";p=A.createElement(p);p.innerHTML=c.children;c.dom=p.firstChild;c.domSize=p.childNodes.length;c=A.createDocumentFragment();
for(var b;b=p.firstChild;)c.appendChild(b);k(l,c,a);return c}function e(l,c){if("function"===typeof l.tag.view){l.state=Object.create(l.tag);var a=l.state.view;if(null!=a.$$reentrantLock$$)return K;a.$$reentrantLock$$=!0}else{l.state=void 0;a=l.tag;if(null!=a.$$reentrantLock$$)return K;a.$$reentrantLock$$=!0;l.state=null!=l.tag.prototype&&"function"===typeof l.tag.prototype.view?new l.tag(l):l.tag(l)}l._state=l.state;null!=l.attrs&&D(l.attrs,l,c);D(l._state,l,c);l.instance=B.normalize(l._state.view.call(l.state,
l));if(l.instance===l)throw Error("A view cannot return the vnode it received as argument");a.$$reentrantLock$$=null}function n(l,c,p,b,g,e,n){if(c!==p&&(null!=c||null!=p))if(null==c)d(l,p,0,p.length,g,e,n);else if(null==p)a(c,0,c.length,p);else{if(c.length===p.length){for(var v=!1,r=0;r<p.length;r++)if(null!=p[r]&&null!=c[r]){v=null==p[r].key&&null==c[r].key;break}if(v){for(r=0;r<c.length;r++)c[r]!==p[r]&&(null==c[r]&&null!=p[r]?f(l,p[r],g,n,m(c,r+1,e)):null==p[r]?a(c,r,r+1,p):h(l,c[r],p[r],g,m(c,
r+1,e),b,n));return}}if(!b)a:{if(null!=c.pool&&Math.abs(c.pool.length-p.length)<=Math.abs(c.length-p.length)&&(b=p[0]&&p[0].children&&p[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 t=c.pool;c=c.concat(c.pool)}r=v=0;for(var w=c.length-1,y=p.length-1,H;w>=v&&y>=r;){var u=c[v],z=p[r];if(u!==z||b)if(null==u)v++;else if(null==z)r++;else if(u.key===z.key){var C=null!=
t&&v>=c.length-t.length||null==t&&b;v++;r++;h(l,u,z,g,m(c,v,e),C,n);b&&u.tag===z.tag&&k(l,q(u),e)}else if(u=c[w],u!==z||b)if(null==u)w--;else if(null==z)r++;else if(u.key===z.key)C=null!=t&&w>=c.length-t.length||null==t&&b,h(l,u,z,g,m(c,w+1,e),C,n),(b||r<y)&&k(l,q(u),m(c,v,e)),w--,r++;else break;else w--,r++;else v++,r++}for(;w>=v&&y>=r;){u=c[w];z=p[y];if(u!==z||b)if(null==u)w--;else{if(null!=z)if(u.key===z.key)C=null!=t&&w>=c.length-t.length||null==t&&b,h(l,u,z,g,m(c,w+1,e),C,n),b&&u.tag===z.tag&&
k(l,q(u),e),null!=u.dom&&(e=u.dom),w--;else{if(!H){H=c;u=w;C={};var A;for(A=0;A<u;A++){var x=H[A];null!=x&&(x=x.key,null!=x&&(C[x]=A))}H=C}null!=z&&(u=H[z.key],null!=u?(C=c[u],h(l,C,z,g,m(c,w+1,e),b,n),k(l,q(C),e),c[u].skip=!0,null!=C.dom&&(e=C.dom)):e=f(l,z,g,n,e))}y--}else w--,y--;if(y<r)break}d(l,p,r,y+1,g,e,n);a(c,v,w+1,p)}}function h(l,c,a,b,d,m,k){var p=c.tag;if(p===a.tag){a.state=c.state;a._state=c._state;a.events=c.events;var v;if(v=!m){var C,z;null!=a.attrs&&"function"===typeof a.attrs.onbeforeupdate&&
(C=a.attrs.onbeforeupdate.call(a.state,a,c));"string"!==typeof a.tag&&"function"===typeof a._state.onbeforeupdate&&(z=a._state.onbeforeupdate.call(a.state,a,c));void 0===C&&void 0===z||C||z?v=!1:(a.dom=c.dom,a.domSize=c.domSize,a.instance=c.instance,v=!0)}if(!v)if("string"===typeof p)switch(null!=a.attrs&&(m?(a.state={},D(a.attrs,a,b)):J(a.attrs,a,b)),p){case "#":c.children.toString()!==a.children.toString()&&(c.dom.nodeValue=a.children);a.dom=c.dom;break;case "<":c.children!==a.children?(q(c),g(l,
a,d)):(a.dom=c.dom,a.domSize=c.domSize);break;case "[":n(l,c.children,a.children,m,b,d,k);c=0;b=a.children;a.dom=null;if(null!=b){for(m=0;m<b.length;m++){var y=b[m];null!=y&&null!=y.dom&&(null==a.dom&&(a.dom=y.dom),c+=y.domSize||1)}1!==c&&(a.domSize=c)}break;default:l=a.dom=c.dom;k=a.attrs&&a.attrs.xmlns||G[a.tag]||k;"textarea"===a.tag&&(null==a.attrs&&(a.attrs={}),null!=a.text&&(a.attrs.value=a.text,a.text=void 0));d=c.attrs;p=a.attrs;v=k;if(null!=p)for(y in p)E(a,y,d&&d[y],p[y],v);if(null!=d)for(y in d)null!=
p&&y in p||("className"===y&&(y="class"),"o"!==y[0]||"n"!==y[1]||u(y)?"key"!==y&&a.dom.removeAttribute(y):x(a,y,void 0));null!=a.attrs&&null!=a.attrs.contenteditable?t(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=[B("#",void 0,void 0,c.text,void 0,c.dom.firstChild)]),null!=a.text&&(a.children=[B("#",void 0,void 0,a.text,void 0,void 0)]),n(l,c.children,a.children,m,b,null,k))}else{if(m)e(a,b);else{a.instance=
B.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&&J(a.attrs,a,b);J(a._state,a,b)}null!=a.instance?(null==c.instance?f(l,a.instance,b,k,d):h(l,c.instance,a.instance,b,d,m,k),a.dom=a.instance.dom,a.domSize=a.instance.domSize):null!=c.instance?(w(c.instance,null),a.dom=void 0,a.domSize=0):(a.dom=c.dom,a.domSize=c.domSize)}}else w(c,null),f(l,a,b,k,d)}function q(a){var c=a.domSize;if(null!=c||null==a.dom){var b=
A.createDocumentFragment();if(0<c){for(a=a.dom;--c;)b.appendChild(a.nextSibling);b.insertBefore(a,b.firstChild)}return b}return a.dom}function m(a,c,b){for(;c<a.length;c++)if(null!=a[c]&&null!=a[c].dom)return a[c].dom;return b}function k(a,c,b){b&&b.parentNode?a.insertBefore(c,b):a.appendChild(c)}function t(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 l=a[c];null!=l&&(l.skip?l.skip=!1:w(l,d))}}function w(a,c){function b(){if(++d===l&&(C(a),a.dom)){var b=a.domSize||1;if(1<b)for(var e=a.dom;--b;){var g=e.nextSibling,f=g.parentNode;null!=f&&f.removeChild(g)}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 l=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&&(l++,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&&(l++,e.then(b,b)));b()}function C(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&&C(a.instance);else if(a=a.children,Array.isArray(a))for(var c=0;c<a.length;c++){var b=a[c];null!=b&&C(b)}}function E(a,b,d,e,g){var c=a.dom;if("key"!==b&&"is"!==b&&(d!==e||"value"===b||"checked"===b||"selectedIndex"===b||"selected"===b&&a.dom===A.activeElement||"object"===typeof e)&&"undefined"!==typeof e&&!u(b)){var l=b.indexOf(":");if(-1<l&&"xlink"===b.substr(0,l))c.setAttributeNS("http://www.w3.org/1999/xlink",b.slice(l+1),e);else if("o"===b[0]&&"n"===b[1]&&"function"===typeof e)x(a,
b,e);else if("style"===b)if(a=d,a===e&&(c.style.cssText="",a=null),null==e)c.style.cssText="";else if("string"===typeof e)c.style.cssText=e;else{"string"===typeof a&&(c.style.cssText="");for(var f in e)c.style[f]=e[f];if(null!=a&&"string"!==typeof a)for(f in a)f in e||(c.style[f]="")}else if(b in c&&"href"!==b&&"list"!==b&&"form"!==b&&"width"!==b&&"height"!==b&&void 0===g&&!(a.attrs.is||-1<a.tag.indexOf("-"))){if("value"===b){f=""+e;if(("input"===a.tag||"textarea"===a.tag)&&a.dom.value===f&&a.dom===
A.activeElement)return;if("select"===a.tag)if(null===e){if(-1===a.dom.selectedIndex&&a.dom===A.activeElement)return}else if(null!==d&&a.dom.value===f&&a.dom===A.activeElement)return;if("option"===a.tag&&null!=d&&a.dom.value===f)return}"input"===a.tag&&"type"===b?c.setAttribute(b,e):c[b]=e}else"boolean"===typeof e?e?c.setAttribute(b,""):c.removeAttribute(b):c.setAttribute("className"===b?"class":b,e)}}function u(a){return"oninit"===a||"oncreate"===a||"onupdate"===a||"onremove"===a||"onbeforeremove"===
a||"onbeforeupdate"===a}function x(a,b,d){var c=a.dom,e="function"!==typeof F?d:function(a){var b=d.call(c,a);F.call(c,a);return b};if(b in c)c[b]="function"===typeof d?e:null;else{var f=b.slice(2);void 0===a.events&&(a.events={});a.events[b]!==e&&(null!=a.events[b]&&c.removeEventListener(f,a.events[b],!1),"function"===typeof d&&(a.events[b]=e,c.addEventListener(f,a.events[b],!1)))}}function D(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 J(a,b,d){"function"===typeof a.onupdate&&d.push(a.onupdate.bind(b.state,b))}var A=b.document,K=A.createDocumentFragment(),G={svg:"http://www.w3.org/2000/svg",math:"http://www.w3.org/1998/Math/MathML"},F;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=A.activeElement,e=a.namespaceURI;null==a.vnodes&&(a.textContent="");Array.isArray(b)||(b=[b]);n(a,a.vnodes,B.normalizeChildren(b),!1,c,null,"http://www.w3.org/1999/xhtml"===
e?void 0:e);a.vnodes=b;null!=d&&A.activeElement!==d&&d.focus();for(d=0;d<c.length;d++)c[d]()},setEventCallback:function(a){return F=a}}},I=function(b){function d(b){b=g.indexOf(b);-1<b&&g.splice(b,2)}function f(){for(var b=1;b<g.length;b+=2)g[b]()}b=P(b);b.setEventCallback(function(b){!1===b.redraw?b.redraw=void 0:f()});var g=[];return{subscribe:function(b,f){d(b);g.push(b,R(f))},unsubscribe:d,redraw:f,render:b.render}}(window);L.setCompletionCallback(I.redraw);D.mount=function(b){return function(d,
f){if(null===f)b.render(d,[]),b.unsubscribe(d);else{if(null==f.view&&"function"!==typeof f)throw Error("m.mount(element, component) expects a component, not a vnode");b.subscribe(d,function(){b.render(d,B(f))});b.redraw()}}}(I);var U=x,M=function(b){if(""===b||null==b)return{};"?"===b.charAt(0)&&(b=b.slice(1));b=b.split("&");for(var d={},f={},g=0;g<b.length;g++){var e=b[g].split("="),n=decodeURIComponent(e[0]);e=2===e.length?decodeURIComponent(e[1]):"";"true"===e?e=!0:"false"===e&&(e=!1);var h=n.split(/\]\[?|\[/),
q=d;-1<n.indexOf("[")&&h.pop();for(var m=0;m<h.length;m++){n=h[m];var k=h[m+1];k=""==k||!isNaN(parseInt(k,10));var t=m===h.length-1;""===n&&(n=h.slice(0,m).join(),null==f[n]&&(f[n]=0),n=f[n]++);null==q[n]&&(q[n]=t?e:k?[]:{});q=q[n]}}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 f(b){return function(){null==h&&(h=n(function(){h=null;b()}))}}function g(b,d,e){var a=b.indexOf("?"),
f=b.indexOf("#"),g=-1<a?a:-1<f?f:b.length;if(-1<a){a=M(b.slice(a+1,-1<f?f:b.length));for(var h in a)d[h]=a[h]}if(-1<f)for(h in d=M(b.slice(f+1)),d)e[h]=d[h];return b.slice(0,g)}var e="function"===typeof b.history.pushState,n="function"===typeof setImmediate?setImmediate:setTimeout,h,q={prefix:"#!",getPath:function(){switch(q.prefix.charAt(0)){case "#":return d("hash").slice(q.prefix.length);case "?":return d("search").slice(q.prefix.length)+d("hash");default:return d("pathname").slice(q.prefix.length)+
d("search")+d("hash")}},setPath:function(d,f,h){var a={},k={};d=g(d,a,k);if(null!=f){for(var m in f)a[m]=f[m];d=d.replace(/:([^\/]+)/g,function(b,d){delete a[d];return f[d]})}(m=F(a))&&(d+="?"+m);(k=F(k))&&(d+="#"+k);e?(k=h?h.state:null,m=h?h.title:null,b.onpopstate(),h&&h.replace?b.history.replaceState(k,m,q.prefix+d):b.history.pushState(k,m,q.prefix+d)):b.location.href=q.prefix+d},defineRoutes:function(d,h,n){function a(){var a=q.getPath(),e={},f=g(a,e,e),k=b.history.state;if(null!=k)for(var m in k)e[m]=
k[m];for(var t in d)if(k=new RegExp("^"+t.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$"),k.test(f)){f.replace(k,function(){for(var b=t.match(/:[^\/]+/g)||[],f=[].slice.call(arguments,1,-2),g=0;g<b.length;g++)e[b[g].replace(/:|\./g,"")]=decodeURIComponent(f[g]);h(d[t],e,a,t)});return}n(a,e)}e?b.onpopstate=f(a):"#"===q.prefix.charAt(0)&&(b.onhashchange=a);a()}};return q};D.route=function(b,d){var f=V(b),g=function(b){return b},e,n,h,q,m,k=function(b,a,k){if(null==b)throw Error("Ensure the DOM element that was passed to `m.route` is not undefined");
var t=function(){null!=e&&d.render(b,e(B(n,h.key,h)))},w=function(b){if(b!==a)f.setPath(a,null,{replace:!0});else throw Error("Could not resolve default route "+a);};f.defineRoutes(k,function(a,b,d){var f=m=function(a,k){f===m&&(n=null==k||"function"!==typeof k.view&&"function"!==typeof k?"div":k,h=b,q=d,m=null,e=(a.render||g).bind(a),t())};a.view||"function"===typeof a?f({},a):a.onmatch?U.resolve(a.onmatch(b,d)).then(function(b){f(a,b)},w):f(a,"div")},w);d.subscribe(b,t)};k.set=function(b,a,d){null!=
m&&(d=d||{},d.replace=!0);m=null;f.setPath(b,a,d)};k.get=function(){return q};k.prefix=function(b){f.prefix=b};k.link=function(b){b.dom.setAttribute("href",f.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(f.prefix)&&(a=a.slice(f.prefix.length)),k.set(a,void 0,void 0))}};k.param=function(b){return"undefined"!==typeof h&&"undefined"!==typeof b?h[b]:h};return k}(window,I);D.withAttr=
function(b,d,f){return function(g){d.call(f||this,b in g.currentTarget?g.currentTarget[b]:g.currentTarget.getAttribute(b))}};var W=P(window);D.render=W.render;D.redraw=I.redraw;D.request=L.request;D.jsonp=L.jsonp;D.parseQueryString=M;D.buildQueryString=F;D.version="1.1.6";D.vnode=B;"undefined"!==typeof module?module.exports=D:window.m=D})();
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment