-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
development + production build system
- Loading branch information
Showing
4 changed files
with
24 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/** | ||
* Moon v0.11.0 | ||
* Moon v1.0.0-alpha | ||
* Copyright 2016-2018 Kabir Shah | ||
* Released under the MIT License | ||
* http://moonjs.ga | ||
* https://kbrsh.github.io/moon | ||
*/ | ||
!function(e,t){"undefined"==typeof module?e.Moon=t():module.exports=t()}(this,function(){"use strict";function e(){this.target=void 0,this.cache={},this.map={}}function t(t){void 0===t&&(t={}),this.options=t,v(this,"name",t.name,"Root"),this.root=void 0;var n=t.data;this.data=void 0===n?{}:"function"==typeof n?n():n;var r=t.methods;this.methods={},void 0!==r&&N(this,r),v(this,"compiledRender",t.render,d),v(this,"hooks",t.hooks,{}),this.events={},this.dom={},this.observer=new e,this.queued=!0;var o=t.computed;void 0!==o&&C(this,o),this.init()}var n={},r={},o={},i=function(e){!1===t.config.silent&&console.log(e)},a=function(e){!1===t.config.silent&&console.error("[Moon] ERROR: "+e)},s=function(e,t){var n=e.hooks[t];void 0!==n&&n.call(e)},v=function(e,t,n,r){e[t]=void 0===n?r:n},d=function(){},f=function(e,t){var n=function(n){var r=function(e){for(var t=r.handlers,n=0;n<t.length;n++)t[n](e)};r.handlers=t[n],t[n]=r,e.addEventListener(n,r)};for(var r in t)n(r)},u=function(e){var t,n=e.type,r=e.data;if("#text"===n)t=document.createTextNode(e.value);else{var o=e.children;t=(r.flags&$)===$?document.createElementNS("http://www.w3.org/2000/svg",n):document.createElement(n);for(var i=0;i<o.length;i++)p(o[i],t);var a=r.events;void 0!==a&&f(t,a),x(t,void 0,e,e.props)}return r.node=t,t},l=function(e,t,n){var r=n.options.props,o=t.props.attrs,i={};if(void 0!==r&&void 0!==o)for(var a=0;a<r.length;a++){var s=r[a];i[s]=o[s]}var v={root:e,props:i,insert:t.children},d=t.data.events;v.events=void 0===d?{}:d;var f=new n.CTor(v),u=t.data;u.component=f,u.node=f.root},c=function(e,t){t.appendChild(e)},p=function(e,t){var n=e.data.component;if(void 0===n)c(u(e),t);else{var r=document.createElement(e.type);c(r,t),l(r,e,n)}},h=function(e,t){t.removeChild(e)},m=function(e,t){var n=e.data,r=n.component;void 0!==r&&r.destroy(),h(n.node,t)},g=function(e,t,n){n.replaceChild(e,t)},y=function(e,t,n){var r=t.data,o=r.component;void 0!==o&&o.destroy();var i=e.data.component;void 0===i?g(u(e),r.node,n):l(r.node,e,i)},b=function(e,t,n,r){if("#text"===e)return{type:e,data:t,value:n};var i=o[e];return void 0!==i&&(n.component=i),{type:e,props:t,data:n,children:r}};b.flatten=function(e){for(var t=0;t<e.length;){var n=e[t];if(!0===Array.isArray(n)){var r=n.length;n.unshift(t,1),e.splice.apply(e,n),n.slice(2,0),t+=r}else t++}return e},b.renderClass=function(e){if("string"==typeof e)return e;var t="",n="";if(!0===Array.isArray(e))for(var r=0;r<e.length;r++)t+=n+b.renderClass(e[r]),n=" ";else if("object"==typeof e)for(var o in e)!0===e[o]&&(t+=n+o,n=" ");return t},b.renderLoop=function(e,t){var n;if(Array.isArray(e)){var r=e.length;n=new Array(r);for(var o=0;o<r;o++)n[o]=t(e[o],o)}else if("object"==typeof e){n=[];for(var i in e)n.push(t(e[i],i))}else if("number"==typeof e){n=new Array(e);for(var a=0;a<e;a++)n[a]=t(a+1,a)}return n};var x=function(e,t,r,o){var i=o.attrs;if(void 0===i){if(void 0!==t)for(var a in t)e.removeAttribute(a)}else if(void 0===t)for(var s in i){var v=i[s];e.setAttribute(s,!0===v?"":v)}else{for(var d in i){var f=i[d],u=t[d];!1===f||void 0!==u&&f===u||e.setAttribute(d,!0===f?"":f)}for(var l in t){var c=i[l];void 0!==c&&!1!==c||e.removeAttribute(l)}}var p=o.directives;if(void 0!==p)for(var h in p){var m=n[h];void 0!==m&&m(e,p[h],r)}var g=o.dom;if(void 0!==g)for(var y in g)e[y]=g[y]},A=function(e,t){for(var n in e)t[n].handlers=e[n]},O=function(e,t){var n=t.data;n.node=e;for(var r=t.props,o=e.attributes,i={},a=0;a<o.length;a++){var s=o[a];i[s.name]=s.value}x(e,i,t,r);var v=n.events;void 0!==v&&f(e,v);var d=r.dom;if(void 0===d||void 0===d.innerHTML&&void 0===d.textContent)for(var c=t.children,m=c.length,y=0,b=y===m?void 0:c[y],A=e.firstChild;void 0!==b||null!==A;){if(null===A)p(b,e);else{var w=A.nextSibling;if(void 0===b)h(A,e);else{var N=b.data.component;if(void 0!==N)l(A,b,N);else{var C=b.type;A.nodeName.toLowerCase()!==C?g(u(b),A,e):"#text"===C?(A.textContent=b.value,b.data.node=A):O(A,b)}}A=w}b=++y<m?c[y]:void 0}},w=function(e,t){var n=t.data,r=n.node,o=e.props;x(r,t.props.attrs,e,o),t.props=o;var i=e.data.events;void 0!==i&&A(i,n.events),function(e,t,n){for(var r=e.length,o=t.length,i=r>o?r:o,a=0;a<i;a++)if(a>=r)m(t.pop(),n);else if(a>=o)p(t[a]=e[a],n);else{var v=e[a],d=t[a];if(v!==d){var f=v.type;if(f!==d.type)y(v,d,n),t[a]=v;else{var u=d.data,l=u.component;if(void 0!==l){var c=!1,h=l.options.props;if(void 0!==h){for(var g=v.props.attrs,b=l.observer,x=l.data,O=0;O<h.length;O++){var N=h[O];x[N]=g[N],b.notify(N)}c=!0}var C=v.data.events;void 0!==C&&A(C,u.events);var k=v.children;0!==k.length&&(l.insert=k,c=!0),!0===c&&(l.build(),s(l,"updated"))}else if("#text"===f){var T=v.value;u.node.textContent=T,d.value=T}else w(v,d)}}}}(e.children,t.children,r)},N=function(e,t){var n=e.methods,r=function(r){n[r]=function(){return t[r].apply(e,arguments)}};for(var o in t)r(o)},C=function(e,t){var n=e.data,r=e.observer,o=function(o){var i=t[o],a=i.get,s=i.set;Object.defineProperty(n,o,{get:function(){var t;return void 0===r.cache[o]?(r.target=o,t=a.call(e),r.target=void 0,r.cache[o]=t):t=r.cache[o],t},set:void 0===s?d:function(t){s.call(e,t)}})};for(var i in t)o(i)};e.prototype.notify=function(e){var t=this.map[e];if(void 0!==t)for(var n=0;n<t.length;n++)this.notify(t[n]);var r=this.cache;void 0!==r[e]&&(r[e]=void 0)};var k=/\{\{\s*/,T=/\s*\}\}/,R=/[\s\n]/,q=/[\s\n]/g,j=/<\/?(?:[A-Za-z]+\w*)|<!--/,E=/"[^"]*"|'[^']*'|\d+[a-zA-Z$_]\w*|\.[a-zA-Z$_]\w*|[a-zA-Z$_]\w*:|([a-zA-Z$_]\w*)(?:\s*\()?/g,L=/(?:(?:&(?:amp|gt|lt|nbsp|quot);)|"|\\|\n)/g,z={"&":"&",">":">","<":"<"," ":" ",""":'\\"',"\\":"\\\\",'"':'\\"',"\n":"\\n"},M=["NaN","false","in","instance","m","null","staticNodes","true","typeof","undefined"],S=["area","base","br","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],Z=["animate","circle","clippath","cursor","defs","desc","ellipse","filter","font-face","foreignObject","g","glyph","image","line","marker","mask","missing-glyph","path","pattern","polygon","polyline","rect","svg","switch","symbol","text","textpath","tspan","use","view"],$=2,_=function(e){return e.replace(q,"")},I=function(e,t){for(var n,r=t.dependencies,o=r.props,i=r.methods,a=t.exclude,s=t.locals,v=!1;null!==(n=E.exec(e));){var d=n[0],f=n[1];void 0!==f&&-1===a.indexOf(f)&&("("===d[d.length-1]?-1===i.indexOf(f)&&i.push(f):(-1===s.indexOf(f)&&-1===o.indexOf(f)&&o.push(f),v=!0))}return v},V=function(e,t){var n=e.length,r=0,o=!1,i="";if(0===n)i='""';else for(;r<n;){var a=e.substring(r),s=a.match(k);if(null===s){i+='"'+a+'"';break}var v=s.index;0!==v&&(i+='"'+a.substring(0,v)+'"',r+=v),o=!0,0!==r&&(i+=" + "),r+=s[0].length;var d=e.substring(r),f=d.match(T),u=f.index,l=d.substring(0,u);I(l,t),i+="("+l+")",(r+=l.length+f[0].length)!==n&&(i+=" + ")}return{output:i,dynamic:o}},D=function(e,t){var n=t.length;return t[n]=e,"staticNodes["+n+"]"},H=function(e){var t="{",n="",r=e.events,o="";if(void 0!==r){t+="events: {";for(var i in r){t+=n+'"'+i+'": [';for(var a=r[i],s=0;s<a.length;s++)t+=o+a[s],o=", ";n=", ",o="",t+="]"}t+="}",delete e.events}0===e.flags&&delete e.flags;for(var v in e)t+=""+n+v+": "+e[v],n=", ";return t+"}"},F=function(e,t){for(var n=e+": {",r="",o=0;o<t.length;o++){var i=t[o],a=i.value;0===a.length&&(a='""'),n+=r+'"'+i.name+'": '+a,r=", "}return n+"}"},P=function(e,t,n){var o=e.type;if("#text"===o){var i=V(e.value,n);return e.value=i.output,i.dynamic}if("m-insert"===o)return t.deep=!0,!0;var a=n.locals,s=!1,v=e.data;-1!==Z.indexOf(o)&&(v.flags=v.flags|$);var d=e.props,f=d.length,u=[],l=[],c=[];e.props={attrs:u,dom:[],directives:l,specialDirectivesAfter:c};for(var p=0;p<f;p++){var h=d[p],m=r[h.name];if(void 0!==m){var g=m.after;void 0!==g&&c.push({prop:h,after:g});var y=m.before;void 0!==y&&!0===y(h,e,t,n)&&(s=!0)}}for(var b=0;b<f;b++){var x=d[b],A=x.name,O=r[A];if(void 0!==O){var w=O.during;void 0!==w&&(!0===w(x,e,t,n)&&(s=!0),u.push(x))}else if("m"===A[0]&&"-"===A[1])!0===I(x.value,n)&&(s=!0),l.push(x);else{var N=V(x.value,n);!0===N.dynamic&&(s=!0),x.value=N.output,u.push(x)}}for(var C=e.children,k=[],T=0;T<C.length;T++){var R=P(C[T],e,n);!0===R&&(s=!0),k.push(R)}for(var q=0;q<C.length;q++)if(!0===s&&!1===k[q]){var j=C[q].data;j.flags=1|j.flags}return n.locals=a,s},B=function(e,t,n){var r,o=e.type,i=e.data;if("#text"===o)r='m("#text", '+H(i)+", "+e.value+")";else if("m-insert"===o)r="instance.insert";else{r='m("'+o+'", {';var a=e.props,s="",v=a.attrs;0!==v.length&&(r+=F("attrs",v),s=", ");var d=a.directives;0!==d.length&&(r+=F(s+"directives",d),s=", ");var f=a.dom;0!==f.length&&(r+=F(s+"dom",f)),r+="}, "+H(i)+", ";for(var u="",l="",c=e.children,p=0;p<c.length;p++)u+=l+B(c[p],e,n),l=", ";!0===e.deep?r+="m.flatten(["+u+"]))":r+="["+u+"])";for(var h=a.specialDirectivesAfter,m=0;m<h.length;m++){var g=h[m];r=g.after(g.prop,r,e,t,n)}}return 1==(1&i.flags)?D(r,n.staticNodes):r},G=function(e){return function(e){var t={staticNodes:[],dependencies:{props:[],methods:[]},exclude:M,locals:[]};if(!1===P(e,void 0,t)){var n=e.data;n.flags=1|n.flags}for(var r=B(e,void 0,t),o=t.dependencies,i=o.props,s=o.methods,v="",f=t.staticNodes,u="",l=0,c="";l<i.length;l++){var p=i[l];v+="var "+p+' = instance.get("'+p+'");'}for(l=0;l<s.length;l++){var h=s[l];v+="var "+h+' = instance.methods["'+h+'"];'}for(l=0;l<f.length;l++)u+=c+f[l],c=", ";try{return new Function("m","var instance = this;var staticNodes = instance.compiledRender.staticNodes;"+v+"if(staticNodes === undefined) {staticNodes = instance.compiledRender.staticNodes = ["+u+"];}return "+r+";")}catch(e){return a("Could not create render function"),d}}(function(e){for(var t={type:"ROOT",props:{},children:[]},n=[t],r=0,o=0;o<e.length;o++){var i=e[o];if("Text"===i.type)n[r].children.push({type:"#text",data:{flags:0},value:i.value});else if("Tag"===i.type)if(!0===i.closeStart)n.pop(),r--;else{var a=i.value,s=n[r].children,v=s.length,d={type:a,index:v,props:i.attributes,data:{flags:0},children:[]};s[v]=d,!1===i.closeEnd&&-1===S.indexOf(a)&&(n.push(d),r++)}}return t.children[0]}(function(e){for(var t=e.length,n=[],r=0;r<t;){var o=e[r];if("<"===o)if(r++,"!--"===e.substring(r,r+3)){r+=3;var i=e.indexOf("--\x3e",r);r=-1===i?t:i+3}else{var a={type:"Tag",value:""},s="",v=[],d=!1,f=!1;for("/"===(o=e[r])&&(o=e[++r],d=!0);r<t&&">"!==o&&"/"!==o&&!1===R.test(o);)s+=o,o=e[++r];for(;r<t&&">"!==o&&("/"!==o||">"!==e[r+1]);)if(!0===R.test(o))o=e[++r];else{for(var u="",l="";r<t&&"="!==o&&!1===R.test(o)&&">"!==o&&("/"!==o||">"!==e[r+1]);)u+=o,o=e[++r];if("="===o){var c=" ";for('"'!==(o=e[++r])&&"'"!==o&&" "!==o&&"\n"!==o||(c=o,o=e[++r]);r<t&&">"!==o&&("/"!==o||">"!==e[r+1]);){if(o===c){o=e[++r];break}l+=o,o=e[++r]}}u=u.split(":"),v.push({name:u[0],value:l,argument:u[1],data:{}})}"/"===o?(r+=2,f=!0):r++,a.value=s,a.attributes=v,a.closeStart=d,a.closeEnd=f,n.push(a)}else{var p=e.substring(r),h=p.search(j),m=void 0;-1===h?(m=p,r=t):(m=p.substring(0,h),r+=h),0!==_(m).length&&n.push({type:"Text",value:m.replace(L,function(e){return z[e]})})}}return n}(e)))};t.prototype.get=function(e){var t=this.observer,n=t.map,r=t.target;return void 0!==r&&(void 0===n[e]?n[e]=[r]:-1===n[e].indexOf(r)&&n[e].push(r)),this.data[e]},t.prototype.set=function(e,t){var n=this.observer;if("object"==typeof e){var r=this.data;for(var o in e)r[o]=e[o],n.notify(o)}else this.data[e]=t,n.notify(e);!function(e){!1===e.queued&&(e.queued=!0,setTimeout(function(){e.build(),e.queued=!1,s(e,"updated")},0))}(this)},t.prototype.destroy=function(){this.off(),this.root=void 0,this.queued=!0,s(this,"destroyed")},t.prototype.on=function(e,t){var n=this.events,r=n[e];void 0===r?n[e]=[t]:r.push(t)},t.prototype.off=function(e,t){if(void 0===e)this.events={};else if(void 0===t)this.events[e]=[];else{var n=this.events[e],r=n.indexOf(t);n.splice(r,1)}},t.prototype.emit=function(e,t){var n,r=this.events,o=r[e],i=r["*"];if(void 0!==o)for(n=0;n<o.length;n++)o[n](t);if(void 0!==i)for(n=0;n<i.length;n++)i[n](e,t)},t.prototype.mount=function(e){var n=this.root="string"==typeof e?document.querySelector(e):e;v(this,"template",this.options.template,n.outerHTML),this.compiledRender===d&&(this.compiledRender=t.compile(this.template)),this.queued=!1;var r=this.render();if(n.nodeName.toLowerCase()===r.type)O(n,r);else{var o=u(r);g(o,n,n.parentNode),this.root=o}this.dom=r,s(this,"mounted")},t.prototype.render=function(){return this.compiledRender(b)},t.prototype.build=function(){var e=this.render(),t=this.dom;e!==t&&w(e,t)},t.prototype.init=function(){i("======= Moon ======="),s(this,"init");var e=this.options.root;void 0!==e&&this.mount(e)},t.config={silent:!0},t.version="0.11.0",t.util={noop:d,log:i,error:a,m:b},t.use=function(e,n){e.init(t,n)},t.compile=function(e){return G(e)},t.nextTick=function(e){setTimeout(e,0)},t.directive=function(e,t){n["m-"+e]=t},t.extend=function(e,n){function r(e){this.componentOptions=e,t.apply(this,[n])}return n.name=e,void 0!==n.data&&"function"!=typeof n.data&&a("In components, data must be a function returning an object"),r.prototype=Object.create(t.prototype),r.prototype.constructor=r,r.prototype.init=function(){var e=this.componentOptions,t=e.props,n=this.data;for(var r in t)n[r]=t[r];this.events=e.events,this.insert=e.insert,s(this,"init");var o=e.root;void 0!==o&&this.mount(o)},o[e]={CTor:r,options:n},r};var J=/\.|\[/,K=function(e,t,n){var r=n.data,o=r.events;if(void 0===o)(o=r.events={})[e]=[t];else{var i=o[e];void 0===i?o[e]=[t]:i.push(t)}},Q=function(e,t,n){n.props.dom.push({name:e,value:t})};return r["m-if"]={before:function(e,t,n,r){var o=n.children,i=t.index+1,a=o[i];if(I(e.value,r),void 0!==a)for(var s=a.props,v=0;v<s.length;v++){if("m-else"===s[v].name){if(s.splice(v,1),!1===P(a,n,r))for(var d=a.children,f=0;f<d.length;f++){var u=d[f].data;u.flags=1|u.flags}e.data.elseOutput=B(a,n,r),o.splice(i,1);break}}return!0},after:function(e,t,n,r,o){var i=e.data.elseOutput;return void 0===i&&(i=D("m(\"#text\", {flags: 1}, '')",o.staticNodes)),e.value+" ? "+t+" : "+i}},r["m-for"]={before:function(e,t,n,r){n.deep=!0;var o=e.value.split(" in "),i=_(o[0]),a=o[1],s=e.data;return s.forIteratable=a,s.forAliases=i,r.locals=r.locals.concat(i.split(",")),I(a,r),!0},after:function(e,t,n,r,o){var i=e.data;return"m.renderLoop("+i.forIteratable+", function("+i.forAliases+") {return "+t+";})"}},r["m-on"]={before:function(e,t,n,r){var o=r.exclude,i=e.value;-1===i.indexOf("(")&&(i+="()"),K(e.argument,"function(event) {"+i+";}",t),o.push("event");var a=I(i,r);return o.pop(),a}},r["m-bind"]={before:function(e,t,n,r){var o,i,a=e.value,s=a.search(J);-1!==s&&(a='instance.get("'+(o=a.substring(0,s))+'")'+(i=a.substring(s)));var v="event.target.value",d=a,f="";return f=-1===s?'function(event) {instance.set("'+a+'", '+v+");}":'function(event) {var boundValue = instance.get("'+o+'");boundValue'+i+" = "+v+';instance.set("'+o+'", boundValue);}',K("input",f,t),Q("value",d,t),I(a,r)}},r["m-dom"]={before:function(e,t,n,r){var o=e.value;return Q(e.argument,o,t),I(o,r)}},r["m-literal"]={during:function(e,t,n,r){var o=e.argument;return e.name=o,"class"===o&&(e.value="m.renderClass("+e.value+")"),I(e.value,r)}},r["m-mask"]={},t}); | ||
!function(n,o){"undefined"==typeof module?n.Moon=o():module.exports=o()}(this,function(){"use strict";return function(){}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters