forked from bumblebeefr/poppy-monitor
/
riot+compiler.js
6 lines (2 loc) · 13.9 KB
/
riot+compiler.js
1
2
3
4
5
6
(function(e){var t={version:"v2.0.14",settings:{}};t.observable=function(e){e=e||{};var t={},n=0;e.on=function(i,r){if(typeof r=="function"){r._id=typeof r._id=="undefined"?n++:r._id;i.replace(/\S+/g,function(e,n){(t[e]=t[e]||[]).push(r);r.typed=n>0})}return e};e.off=function(n,i){if(n=="*")t={};else{n.replace(/\S+/g,function(e){if(i){var n=t[e];for(var r=0,u;u=n&&n[r];++r){if(u._id==i._id){n.splice(r,1);r--}}}else{t[e]=[]}})}return e};e.one=function(t,n){function i(){e.off(t,i);n.apply(e,arguments)}return e.on(t,i)};e.trigger=function(n){var i=[].slice.call(arguments,1),r=t[n]||[];for(var u=0,o;o=r[u];++u){if(!o.busy){o.busy=1;o.apply(e,o.typed?[n].concat(i):i);if(r[u]!==o){u--}o.busy=0}}if(t.all&&n!="all"){e.trigger.apply(e,["all",n].concat(i))}return e};return e};(function(e,t,n){if(!n)return;var i=n.location,r=e.observable(),u=n,o;function f(){return i.href.split("#")[1]||""}function a(e){return e.split("/")}function c(e){if(e.type)e=f();if(e!=o){r.trigger.apply(null,["H"].concat(a(e)));o=e}}var l=e.route=function(e){if(e[0]){i.hash=e;c(e)}else{r.on("H",e)}};l.exec=function(e){e.apply(null,a(f()))};l.parser=function(e){a=e};u.addEventListener?u.addEventListener(t,c,false):u.attachEvent("on"+t,c)})(t,"hashchange",e);var n=function(e,n,i){return function(r){n=t.settings.brackets||e;if(i!=n)i=n.split(" ");return r&&r.test?n==e?r:RegExp(r.source.replace(/\{/g,i[0].replace(/(?=.)/g,"\\")).replace(/\}/g,i[1].replace(/(?=.)/g,"\\")),r.global?"g":""):i[r]}}("{ }");var i=function(){var t={},i=/(['"\/]).*?[^\\]\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function *\()|([a-z_$]\w*)/gi;return function(e,n){return e&&(t[e]=t[e]||r(e))(n)};function r(e,t){e=(e||n(0)+n(1)).replace(n(/\\{/g),"").replace(n(/\\}/g),"");t=f(e,a(e,n(/{/),n(/}/)));return new Function("d","return "+(!t[0]&&!t[2]&&!t[3]?u(t[1]):"["+t.map(function(e,t){return t%2?u(e,true):'"'+e.replace(/\n/g,"\\n").replace(/"/g,'\\"')+'"'}).join(",")+'].join("")').replace(/\uFFF0/g,n(0)).replace(/\uFFF1/g,n(1))+";")}function u(e,t){e=e.replace(/\n/g," ").replace(n(/^[{ ]+|[ }]+$|\/\*.+?\*\//g),"");return/^\s*[\w- "']+ *:/.test(e)?"["+a(e,/["' ]*[\w- ]+["' ]*:/,/,(?=["' ]*[\w- ]+["' ]*:)|}|$/).map(function(e){return e.replace(/^[ "']*(.+?)[ "']*: *(.+?),? *$/,function(e,t,n){return n.replace(/[^&|=!><]+/g,o)+'?"'+t+'":"",'})}).join("")+'].join(" ").trim()':o(e,t)}function o(t,n){t=t.trim();return!t?"":"(function(v){try{v="+(t.replace(i,function(t,n,i){return i?"(d."+i+"===undefined?"+(typeof e=="undefined"?"global.":"window.")+i+":d."+i+")":t})||"x")+"}finally{return "+(n===true?'!v&&v!==0?"":v':"v")+"}}).call(d)"}function f(e,t){var n=[];t.map(function(t,i){i=e.indexOf(t);n.push(e.slice(0,i),t);e=e.slice(i+t.length)});return n.concat(e)}function a(e,t,n){var i,r=0,u=[],o=new RegExp("("+t.source+")|("+n.source+")","g");e.replace(o,function(t,n,o,f){if(!r&&n)i=f;r+=n?1:-1;if(!r&&o!=null)u.push(e.slice(i,f+o.length))});return u}}();function r(e){var t={val:e},i=e.split(/\s+in\s+/);if(i[1]){t.val=n(0)+i[1];i=i[0].slice(n(0).length).trim().split(/,\s*/);t.key=i[0];t.pos=i[1]}return t}function u(e,t,n){var i={};i[e.key]=t;if(e.pos)i[e.pos]=n;return i}function o(e,t,n){g(e,"each");var o=e.outerHTML,f=e.previousSibling,a=e.parentNode,l=[],s=[],p;n=r(n);function v(e,t,n){l.splice(e,0,t);s.splice(e,0,n)}t.one("update",function(){a.removeChild(e)}).one("premount",function(){if(a.stub)a=t.root}).on("update",function(){var e=i(n.val,t);if(!e)return;if(!Array.isArray(e)){var r=JSON.stringify(e);if(r==p)return;p=r;d(s,function(e){e.unmount()});l=[];s=[];e=Object.keys(e).map(function(t){return u(n,t,e[t])})}d(l,function(t){if(t instanceof Object){if(e.indexOf(t)>-1){return}}else{var n=b(e,t),i=b(l,t);if(n.length>=i.length){return}}var r=l.indexOf(t),u=s[r];if(u){u.unmount();l.splice(r,1);s.splice(r,1);return false}});var g=[].indexOf.call(a.childNodes,f)+1;d(e,function(i,r){var f=e.indexOf(i,r),d=l.indexOf(i,r);f<0&&(f=e.lastIndexOf(i,r));d<0&&(d=l.lastIndexOf(i,r));if(!(i instanceof Object)){var m=b(e,i),h=b(l,i);if(m.length>h.length){d=-1}}var y=a.childNodes;if(d<0){if(!p&&n.key)var w=u(n,i,f);var x=new c({tmpl:o},{before:y[g+f],parent:t,root:a,item:w||i});x.mount();v(f,i,x);return true}if(n.pos&&s[d][n.pos]!=f){s[d].one("update",function(e){e[n.pos]=f});s[d].update()}if(f!=d){a.insertBefore(y[g+d],y[g+(f>d?f+1:f)]);return v(f,l.splice(d,1)[0],s.splice(d,1)[0])}});l=e.slice()})}function f(e,t,n){h(e,function(e){if(e.nodeType==1){var i=O(e);if(i&&!e.getAttribute("each")){var r=new c(i,{root:e,parent:t}),u=e.getAttribute("name")||i.name,o=t.tags[u];if(o){if(!Array.isArray(o))t.tags[u]=[o];t.tags[u].push(r)}else{t.tags[u]=r}e.innerHTML="";n.push(r)}d(e.attributes,function(n){if(/^(name|id)$/.test(n.name))t[n.value]=e})}})}function a(e,t,i){function r(e,t,r){if(t.indexOf(n(0))>=0){var u={dom:e,expr:t};i.push(v(u,r))}}h(e,function(e){var n=e.nodeType;if(n==3&&e.parentNode.tagName!="STYLE")r(e,e.nodeValue);if(n!=1)return;var i=e.getAttribute("each");if(i){o(e,t,i);return false}d(e.attributes,function(t){var n=t.name,i=n.split("__")[1];r(e,t.value,{attr:i||n,bool:i});if(i){g(e,n);return false}});if(O(e))return false})}function c(e,n){var r=t.observable(this),u=w(n.opts)||{},o=m(e.tmpl),c=n.parent,l=[],s=[],g=n.root,h=n.item,y=e.fn,b={},x;if(y&&g.riot)return;g.riot=true;this._id=~~((new Date).getTime()*Math.random());v(this,{parent:c,root:g,opts:u,tags:{}},h);d(g.attributes,function(e){b[e.name]=e.value});function C(e){d(Object.keys(b),function(e){u[e]=i(b[e],c||r)})}this.update=function(e,t){v(r,e,h);C();r.trigger("update",h);p(l,r,h);r.trigger("updated")};this.mount=function(){C();y&&y.call(r,u);O(true);a(o,r,l);r.update();r.trigger("premount");if(y){while(o.firstChild)g.appendChild(o.firstChild)}else{x=o.firstChild;g.insertBefore(x,n.before||null)}if(g.stub)r.root=g=c.root;r.trigger("mount")};this.unmount=function(){var e=y?g:x,t=e.parentNode,n=g.tagName.toLowerCase();if(t){if(c){if(Array.isArray(c.tags[n])){d(c.tags[n],function(e,t){if(e._id==r._id)c.tags[n].splice(t,1)})}else delete c.tags[n];t.removeChild(e)}else{while(e.firstChild)e.removeChild(e.firstChild);t.removeChild(e)}}r.trigger("unmount");O();r.off("*");delete g.riot};function O(e){d(s,function(t){t[e?"mount":"unmount"]()});if(c){var t=e?"on":"off";c[t]("update",r.update)[t]("unmount",r.unmount)}}f(o,this,s)}function l(t,n,i,r,u){i[t]=function(t){t=t||e.event;t.which=t.which||t.charCode||t.keyCode;t.target=t.target||t.srcElement;t.currentTarget=i;t.item=u;if(n.call(r,t)!==true&&!/radio|check/.test(i.type)){t.preventDefault&&t.preventDefault();t.returnValue=false}var o=u?r.parent:r;o.update()}}function s(e,t,n){if(e){e.insertBefore(n,t);e.removeChild(t)}}function p(e,t,n){d(e,function(e){var r=e.dom,u=e.attr,o=i(e.expr,t),f=e.dom.parentNode;if(o==null)o="";if(f&&f.tagName=="TEXTAREA")o=o.replace(/riot-/g,"");if(e.value===o)return;e.value=o;if(!u)return r.nodeValue=o;g(r,u);if(typeof o=="function"){l(u,o,r,t,n)}else if(u=="if"){var a=e.stub;if(o){a&&s(a.parentNode,a,r)}else{a=e.stub=a||document.createTextNode("");s(r.parentNode,r,a)}}else if(/^(show|hide)$/.test(u)){if(u=="hide")o=!o;r.style.display=o?"":"none"}else if(u=="value"){r.value=o}else if(u.slice(0,5)=="riot-"){u=u.slice(5);o?r.setAttribute(u,o):g(r,u)}else{if(e.bool){r[u]=o;if(!o)return;o=u}if(typeof o!="object")r.setAttribute(u,o)}})}function d(e,t){for(var n=0,i=(e||[]).length,r;n<i;n++){r=e[n];if(r!=null&&t(r,n)===false)n--}return e}function g(e,t){e.removeAttribute(t)}function v(e,t,n){t&&d(Object.keys(t),function(n){e[n]=t[n]});return n?v(e,n):e}function m(e){var t=e.trim().slice(1,3).toLowerCase(),n=/td|th/.test(t)?"tr":t=="tr"?"tbody":"div",i=document.createElement(n);i.stub=true;i.innerHTML=e;return i}function h(e,t){if(e){if(t(e)===false)h(e.nextSibling,t);else{e=e.firstChild;while(e){h(e,t);e=e.nextSibling}}}}function y(e,t){return e.filter(function(e){return t.indexOf(e)<0})}function b(e,t){return e.filter(function(e){return e===t})}function w(e){function t(){}t.prototype=e;return new t}var x=[],C={};function O(e){return C[e.tagName.toLowerCase()]}function N(e){var t=document.createElement("style");t.innerHTML=e;document.head.appendChild(t)}function A(e,t,n){var i=C[t];if(i&&e)i=new c(i,{root:e,opts:n});if(i&&i.mount){i.mount();x.push(i);return i.on("unmount",function(){x.splice(x.indexOf(i),1)})}}t.tag=function(e,t,n,i){if(typeof n=="function")i=n;else if(n)N(n);C[e]={name:e,tmpl:t,fn:i};return e};t.mount=function(e,t,n){if(e=="*")e=Object.keys(C).join(", ");if(typeof t=="object"){n=t;t=0}var i=[];function r(e){var r=t||e.tagName.toLowerCase(),u=A(e,r,n);if(u)i.push(u)}if(e.tagName){r(e);return i[0]}else{d(typeof e=="string"?document.querySelectorAll(e):e,r);return i}};t.update=function(){return d(x,function(e){e.update()})};t.mountTo=t.mount;t.util={brackets:n,tmpl:i};if(typeof exports==="object")module.exports=t;else if(typeof define==="function"&&define.amd)define(function(){return t});else e.riot=t})(typeof window!="undefined"?window:undefined);
(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:w,none:E,cs:w,es6:x,typescript:k,livescript:q,ls:q};var o=/^<([\w\-]+)>(.*)<\/\1>/gim,a=/=({[^}]+})([\s\/\>])/g,s=/([\w\-]+)=(["'])([^\2]+?)\2/g,u=/{\s*([^}]+)\s*}/g,f=/^<([\w\-]+)>([^\x00]*[\w\/}"']>$)?([^\x00]*?)^<\/\1>/gim,l=/<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,b=/^\s*\/\/.*$/gm,h=/\/\*[^\x00]*?\*\//gm;function y(e,i,c){var o=riot.util.brackets;e=e.replace(o(a),'="$1"$2');e=i.whitespace?e.replace(/\n/g,"\\n"):e.replace(/\s+/g," ");e=e.trim().replace(g,"");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=$(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 w(e){if(typeof exports==="undefined"){return CoffeeScript.compile(e,{bare:true})}return require("coffee-script").compile(e,{bare:true})}function x(e){if(typeof exports==="undefined"){return babel.transform(e,{blacklist:["useStrict"]}).code}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 S(e){e=e.replace(b,"").replace(h,"");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 T(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 $(e,r,t){var n=r.parser||(t?c[t]:S);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=T(r,e);return e.replace(/\s+/g," ").replace(/\\/g,"\\\\").replace(/'/g,"\\'").trim()}function L(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 L(t,y(n,r),"","")});return e.replace(f,function(e,t,n,i){n=n||"";var c=r.type;if(!i.trim()){n=n.replace(l,function(e,r,t,n){if(t)c=t.replace("text/","");i=n;return""})}var o="css",a="";n=n.replace(p,function(e,r,t,n){if(r&&"scoped"==r.trim())o="scoped-css";else if(t)o=t.replace("text/","");a=n;return""});return L(t,y(n,r,c),C(a,t,o),$(i,r,c))})}if(!e){this.riot=require(process.env.RIOT||"../riot");return module.exports={compile:R,html:y,style:C,js:$}}var A=e.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"]'),t=r.length;[].map.call(r,function(r){var n=r.getAttribute("src");function i(r){G(r);t--;if(!t){H.trigger("ready");M=true;e&&e()}}return n?_(n,i):i(z(r.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})(typeof window!="undefined"?window:undefined);