-
Notifications
You must be signed in to change notification settings - Fork 0
/
compiler.min.js
1 lines (1 loc) · 4.82 KB
/
compiler.min.js
1
(function(e){var r=("allowfullscreen,async,autofocus,autoplay,checked,compact,controls,declare,default,"+"defaultchecked,defaultmuted,defaultselected,defer,disabled,draggable,enabled,formnovalidate,hidden,"+"indeterminate,inert,ismap,itemscope,loop,multiple,muted,nohref,noresize,noshade,novalidate,nowrap,open,"+"pauseonexit,readonly,required,reversed,scoped,seamless,selected,sortable,spellcheck,translate,truespeed,"+"typemustmatch,visible").split(",");var t="area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",");var n=["style","src","d"];var i={jade:O};var c={coffeescript:y,none:E,cs:y,es6:w,typescript:k,livescript:q,ls:q};var o=/^<([\w\-]+)>(.*)<\/\1>/gim,a=/=({[^}]+})([\s\/\>])/g,s=/([\w\-]+)=(["'])([^\2]+?)\2/g,u=/{\s*([^}]+)\s*}/g,l=/^<([\w\-]+)>([^\x00]*[\w\/}]>$)?([^\x00]*?)^<\/\1>/gim,f=/<script(\s+type=['"]?([^>'"]+)['"]?)?>([^\x00]*?)<\/script>/gm,p=/<style(\s+type=['"]?([^>'"]+)['"]?|\s+scoped)?>([^\x00]*?)<\/style>/gm,d=/(^|\}|\{)\s*([^\{\}]+)\s*(?=\{)/g,m=/\/\*[^\x00]*?\*\//gm,g=/<!--.*?-->/g,v=/<([\w\-]+)([^>]*)\/\s*>/g,h=/^\s*\/\/.*$/gm,b=/\/\*[^\x00]*?\*\//gm;function x(e,i,c){var o=riot.util.brackets;e=i.whitespace?e.replace(/\n/g,"\\n"):e.replace(/\s+/g," ");e=e.trim().replace(g,"");e=e.replace(o(a),'="$1"$2');e=e.replace(s,function(e,t,i,c){if(c.indexOf(o(0))>=0){t=t.toLowerCase();if(n.indexOf(t)>=0)t="riot-"+t;else if(r.indexOf(t)>=0)t="__"+t}return t+'="'+c+'"'});if(i.expr){e=e.replace(o(u),function(e,r){var t=L(r,i,c).trim().replace(/\r?\n|\r/g,"").trim();if(t.slice(-1)==";")t=t.slice(0,-1);return o(0)+t+o(1)})}e=e.replace(v,function(e,r,n){var i="<"+r+(n?" "+n.trim():"")+">";if(t.indexOf(r.toLowerCase())==-1)i+="</"+r+">";return i});e=e.replace(/'/g,"\\'");e=e.replace(o(/\\{|\\}/g),"\\$&");if(i.compact)e=e.replace(/> </g,"><");return e}function y(e){return require("coffee-script").compile(e,{bare:true})}function w(e){return require("babel").transform(e,{blacklist:["useStrict"]}).code}function k(e){return require("typescript-simple")(e)}function q(e){return require("LiveScript").compile(e,{bare:true,header:false})}function E(e){return e}function O(e){return require("jade").render(e,{pretty:true})}function T(e){e=e.replace(h,"").replace(b,"");var r=e.split("\n"),t="";r.forEach(function(e,n){var i=e.trim();if(i[0]!="}"&&i.indexOf("(")>0&&i.indexOf("function")==-1){var c=/[{}]/.exec(i.slice(-1)),o=c&&/(\s+)([\w]+)\s*\(([\w,\s]*)\)\s*\{/.exec(e);if(o&&!/^(if|while|switch|for)$/.test(o[2])){r[n]=o[1]+"this."+o[2]+" = function("+o[3]+") {";if(c[0]=="}"){r[n]+=" "+i.slice(o[0].length-1,-1)+"}.bind(this)"}else{t=o[1]}}}if(e.slice(0,t.length+1)==t+"}"){r[n]=t+"}.bind(this);";t=""}});return r.join("\n")}function $(e,r){return r.replace(m,"").replace(d,function(r,t,n){return t+" "+n.split(/\s*,\s*/g).map(function(r){return r[0]=="@"?r:e+" "+r.replace(/:scope\s*/,"")}).join(",")}).trim()}function L(e,r,t){var n=r.parser||(t?c[t]:T);if(!n)throw new Error('Parser not found "'+t+'"');return n(e,r)}function j(e,r){var t=i[e];if(!t)throw new Error('Template parser not found "'+e+'"');return t(r)}function C(e,r,t){if(t=="scoped-css")e=$(r,e);return e.replace(/\s+/g," ").replace(/\\/g,"\\\\").replace(/'/g,"\\'").trim()}function S(e,r,t,n){return"riot.tag('"+e+"', '"+r+"'"+(t?", '"+t+"'":"")+", function(opts) {"+n+"\n});"}function R(e,r){r=r||{};if(r.brackets)riot.settings.brackets=r.brackets;if(r.template)e=j(r.template,e);e=e.replace(o,function(e,t,n){return S(t,x(n,r),"","")});return e.replace(l,function(e,t,n,i){n=n||"";var c=r.type;if(!i.trim()){n=n.replace(f,function(e,r,t,n){if(t)c=t.replace("text/","");i=n;return""})}var o="";var a="css";n=n.replace(p,function(e,r,t,n){if(r&&"scoped"==r.trim())a="scoped-css";else if(t)a=t.replace("text/","");o=n;return""});return S(t,x(n,r,c),C(o,t,a),L(i,r,c))})}if(e){this.riot=require(process.env.RIOT||"../riot");return module.exports={html:x,compile:R,style:C}}var A=document,H,M;function _(e,r){var t=new XMLHttpRequest;t.onreadystatechange=function(){if(t.readyState==4&&t.status==200)r(t.responseText)};t.open("GET",e,true);t.send("")}function z(e){var r=/[ \t]+/.exec(e);if(r)e=e.replace(new RegExp("^"+r[0],"gm"),"");return e}function G(e){var r=A.createElement("script"),t=A.documentElement;r.text=R(e);t.appendChild(r);t.removeChild(r)}function I(e){var r=A.querySelectorAll('script[type="riot/tag"]');[].map.call(r,function(t,n){var i=t.getAttribute("src");function c(t){G(t);if(n+1==r.length){H.trigger("ready");M=true;e&&e()}}return i?_(i,c):c(z(t.innerHTML))})}riot.compile=function(e,r){if(typeof e=="string"){if(e.trim()[0]=="<"){var t=z(R(e));if(!r)G(t);return t}else{return _(e,function(e){var t=z(R(e));G(t);r&&r(t,e)})}}if(typeof e!="function")e=undefined;if(M)return e&&e();if(H){e&&H.on("ready",e)}else{H=riot.observable();I(e)}};var P=riot.mount;riot.mount=function(e,r,t){var n;riot.compile(function(){n=P(e,r,t)});return n};riot.mountTo=riot.mount})(!this.top);