-
Notifications
You must be signed in to change notification settings - Fork 0
/
riot+compiler.min.js
2 lines (2 loc) · 12.6 KB
/
riot+compiler.min.js
1
2
/* Riot v2.0.12, @license MIT, (c) 2015 Muut Inc. + contributors */
(function(){var e={version:"v2.0.12",settings:{}};"use strict";e.observable=function(e){e=e||{};var t={},n=0;e.on=function(r,i){if(typeof i=="function"){i._id=typeof i._id=="undefined"?n++:i._id;r.replace(/\S+/g,function(e,n){(t[e]=t[e]||[]).push(i);i.typed=n>0})}return e};e.off=function(n,r){if(n=="*")t={};else{n.replace(/\S+/g,function(e){if(r){var n=t[e];for(var i=0,o;o=n&&n[i];++i){if(o._id==r._id){n.splice(i,1);i--}}}else{t[e]=[]}})}return e};e.one=function(t,n){if(n)n.one=1;return e.on(t,n)};e.trigger=function(n){var r=[].slice.call(arguments,1),i=t[n]||[];for(var o=0,u;u=i[o];++o){if(!u.busy){u.busy=1;u.apply(e,u.typed?[n].concat(r):r);if(u.one){i.splice(o,1);o--}else if(i[o]!==u){o--}u.busy=0}}return e};return e};(function(e,t){if(!this.top)return;var n=location,r=e.observable(),i=window,o;function u(){return n.hash.slice(1)}function a(e){return e.split("/")}function f(e){if(e.type)e=u();if(e!=o){r.trigger.apply(null,["H"].concat(a(e)));o=e}}var c=e.route=function(e){if(e[0]){n.hash=e;f(e)}else{r.on("H",e)}};c.exec=function(e){e.apply(null,a(u()))};c.parser=function(e){a=e};i.addEventListener?i.addEventListener(t,f,false):i.attachEvent("on"+t,f)})(e,"hashchange");var t=function(t,n,r){return function(i){n=e.settings.brackets||t;if(r!=n)r=n.split(" ");return i&&i.test?n==t?i:RegExp(i.source.replace(/\{/g,r[0].replace(/(?=.)/g,"\\")).replace(/\}/g,r[1].replace(/(?=.)/g,"\\")),i.global?"g":""):r[i]}}("{ }");var n=function(){var e={},n=/(['"\/]).*?[^\\]\1|\.\w*|\w*:|\b(?:(?:new|typeof|in|instanceof) |(?:this|true|false|null|undefined)\b|function *\()|([a-z_$]\w*)/gi;return function(t,n){return t&&(e[t]=e[t]||r(t))(n)};function r(e,n){e=(e||t(0)+t(1)).replace(t(/\\{/g),"").replace(t(/\\}/g),"");n=u(e,t(/{[\s\S]*?}/g));return new Function("d","return "+(!n[0]&&!n[2]&&!n[3]?i(n[1]):"["+n.map(function(e,t){return t%2?i(e,true):'"'+e.replace(/\n/g,"\\n").replace(/"/g,'\\"')+'"'}).join(",")+'].join("")').replace(/\uFFF0/g,t(0)).replace(/\uFFF1/g,t(1))+";")}function i(e,n){e=e.replace(/\n/g," ").replace(t(/^[{ ]+|[ }]+$|\/\*.+?\*\//g),"");return/^\s*[\w- "']+ *:/.test(e)?"["+e.replace(/\W*([\w- ]+)\W*:([^,]+)/g,function(e,t,n){return n.replace(/[^&|=!><]+/g,o)+'?"'+t.trim()+'":"",'})+'].join(" ").trim()':o(e,n)}function o(e,t){e=e.trim();return!e?"":"(function(v){try{v="+(e.replace(n,function(e,t,n){return n?"(d."+n+"===undefined?window."+n+":d."+n+")":e})||"x")+"}finally{return "+(t===true?'!v&&v!==0?"":v':"v")+"}}).call(d)"}function u(e,t){var n=[],r=0;e.replace(t,function(t,i){n.push(e.slice(r,i),t);r=i+t.length});return n.concat(e.slice(r))}}();function r(e){var n={val:e},r=e.split(/\s+in\s+/);if(r[1]){n.val=t(0)+r[1];r=r[0].slice(t(0).length).trim().split(/,\s*/);n.key=r[0];n.pos=r[1]}return n}function i(e,t,n){var r={};r[e.key]=t;if(e.pos)r[e.pos]=n;return r}function o(e,t,o){d(e,"each");var u=e.outerHTML,a=e.previousSibling,c=e.parentNode,s=[],l=[],m;o=r(o);function v(e,t,n){s.splice(e,0,t);l.splice(e,0,n)}t.one("update",function(){c.removeChild(e)}).one("premount",function(){if(c.stub)c=t.root}).on("update",function(){var e=n(o.val,t);if(!e)return;if(!Array.isArray(e)){var r=JSON.stringify(e);if(r==m)return;m=r;p(l,function(e){e.unmount()});s=[];l=[];e=Object.keys(e).map(function(t){return i(o,t,e[t])})}p(h(s,e),function(e){var t=s.indexOf(e),n=l[t];if(n){n.unmount();s.splice(t,1);l.splice(t,1)}});var d=c.childNodes,g=[].indexOf.call(d,a);p(e,function(n,r){var a=e.indexOf(n,r),p=s.indexOf(n,r);a<0&&(a=e.lastIndexOf(n,r));p<0&&(p=s.lastIndexOf(n,r));if(p<0){if(!m&&o.key)n=i(o,n,a);var h=new f({tmpl:u},{before:d[g+1+a],parent:t,root:c,item:n});h.mount();return v(a,n,h)}if(o.pos&&l[p][o.pos]!=a){l[p].one("update",function(e){e[o.pos]=a});l[p].update()}if(a!=p){c.insertBefore(d[g+p+1],d[g+a+1]);return v(a,s.splice(p,1)[0],l.splice(p,1)[0])}});s=e.slice()})}function u(e,t,n){g(e,function(e){if(e.nodeType==1){var r=x(e);if(r&&!e.getAttribute("each")){var i=new f(r,{root:e,parent:t});t.tags[e.getAttribute("name")||r.name]=i;n.push(i)}p(e.attributes,function(n){if(/^(name|id)$/.test(n.name))t[n.value]=e})}})}function a(e,n,r){function i(e,n,i){if(n.indexOf(t(0))>=0){var o={dom:e,expr:n};r.push(m(o,i))}}g(e,function(e){var t=e.nodeType;if(t==3&&e.parentNode.tagName!="STYLE")i(e,e.nodeValue);if(t!=1)return;var r=e.getAttribute("each");if(r){o(e,n,r);return false}p(e.attributes,function(t){var n=t.name,r=n.split("__")[1];i(e,t.value,{attr:r||n,bool:r});if(r){d(e,n);return false}});if(x(e))return false})}function f(t,r){var i=e.observable(this),o=b(r.opts)||{},f=v(t.tmpl),c=r.parent,s=[],d=[],g=r.root,h=r.item,y=t.fn,w={},x;if(y&&g.riot)return;g.riot=true;m(this,{parent:c,root:g,opts:o,tags:{}},h);p(g.attributes,function(e){w[e.name]=e.value});function k(e){p(Object.keys(w),function(e){o[e]=n(w[e],c||i)})}this.update=function(e,t){m(i,e,h);k();i.trigger("update",h);l(s,i,h);i.trigger("updated")};this.mount=function(){k();y&&y.call(i,o);C(true);a(f,i,s);i.update();i.trigger("premount");if(y){while(f.firstChild)g.appendChild(f.firstChild)}else{x=f.firstChild;g.insertBefore(x,r.before||null)}if(g.stub)i.root=g=c.root;i.trigger("mount")};this.unmount=function(){var e=y?g:x,t=e.parentNode;if(t){if(c)t.removeChild(e);else while(g.firstChild)g.removeChild(g.firstChild);C();i.trigger("unmount");i.off("*");delete g.riot}};function C(e){p(d,function(t){t[e?"mount":"unmount"]()});if(c){var t=e?"on":"off";c[t]("update",i.update)[t]("unmount",i.unmount)}}u(f,this,d)}function c(e,t,n,r,i){n[e]=function(e){e=e||window.event;e.which=e.which||e.charCode||e.keyCode;e.target=e.target||e.srcElement;e.currentTarget=n;e.item=i;if(t.call(r,e)!==true){e.preventDefault&&e.preventDefault();e.returnValue=false}var o=i?r.parent:r;o.update()}}function s(e,t,n){if(e){e.insertBefore(n,t);e.removeChild(t)}}function l(e,t,r){p(e,function(e){var i=e.dom,o=e.attr,u=n(e.expr,t),a=e.dom.parentNode;if(u==null)u="";if(a&&a.tagName=="TEXTAREA")u=u.replace(/riot-/g,"");if(e.value===u)return;e.value=u;if(!o)return i.nodeValue=u;d(i,o);if(typeof u=="function"){c(o,u,i,t,r)}else if(o=="if"){var f=e.stub;if(u){f&&s(f.parentNode,f,i)}else{f=e.stub=f||document.createTextNode("");s(i.parentNode,i,f)}}else if(/^(show|hide)$/.test(o)){if(o=="hide")u=!u;i.style.display=u?"":"none"}else if(o=="value"){i.value=u}else if(o.slice(0,5)=="riot-"){o=o.slice(5);u?i.setAttribute(o,u):d(i,o)}else{if(e.bool){i[o]=u;if(!u)return;u=o}if(typeof u!="object")i.setAttribute(o,u)}})}function p(e,t){for(var n=0,r=(e||[]).length,i;n<r;n++){i=e[n];if(i!=null&&t(i,n)===false)n--}return e}function d(e,t){e.removeAttribute(t)}function m(e,t,n){t&&p(Object.keys(t),function(n){e[n]=t[n]});return n?m(e,n):e}function v(e){var t=e.trim().slice(1,3).toLowerCase(),n=/td|th/.test(t)?"tr":t=="tr"?"tbody":"div",r=document.createElement(n);r.stub=true;r.innerHTML=e;return r}function g(e,t){if(e){if(t(e)===false)g(e.nextSibling,t);else{e=e.firstChild;while(e){g(e,t);e=e.nextSibling}}}}function h(e,t){return e.filter(function(e){return t.indexOf(e)<0})}function b(e){function t(){}t.prototype=e;return new t}var y=[],w={};function x(e){return w[e.tagName.toLowerCase()]}function k(e){var t=document.createElement("style");t.innerHTML=e;document.head.appendChild(t)}function C(e,t,n){var r=w[t];if(r&&e)r=new f(r,{root:e,opts:n});if(r&&r.mount){r.mount();y.push(r);return r.on("unmount",function(){y.splice(y.indexOf(r),1)})}}e.tag=function(e,t,n,r){if(typeof n=="function")r=n;else if(n)k(n);w[e]={name:e,tmpl:t,fn:r}};e.mount=function(e,t,n){if(e=="*")e=Object.keys(w).join(", ");if(typeof t=="object"){n=t;t=0}var r=[];function i(e){var i=t||e.tagName.toLowerCase(),o=C(e,i,n);if(o)r.push(o)}if(e.tagName){i(e);return r[0]}else{p(document.querySelectorAll(e),i);return r}};e.update=function(){return p(y,function(e){e.update()})};e.mountTo=e.mount;(function(t){var n=("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 r="area,base,br,col,command,embed,hr,img,input,keygen,link,meta,param,source,track,wbr".split(",");var i=["style","src","d"];var o={jade:T};var u={coffeescript:x,none:E,cs:x,es6:k,typescript:C,livescript:O,ls:O};var a=/^<([\w\-]+)>(.*)<\/\1>/gim,f=/=({[^}]+})([\s\/\>])/g,c=/([\w\-]+)=(["'])([^\2]+?)\2/g,s=/{\s*([^}]+)\s*}/g,l=/^<([\w\-]+)>([^\x00]*[\w\/}]>$)?([^\x00]*?)^<\/\1>/gim,p=/<script(\s+type=['"]?([^>'"]+)['"]?)?>([^\x00]*?)<\/script>/gm,d=/<style(\s+type=['"]?([^>'"]+)['"]?|\s+scoped)?>([^\x00]*?)<\/style>/gm,m=/(^|\}|\{)\s*([^\{\}]+)\s*(?=\{)/g,v=/\/\*[^\x00]*?\*\//gm,g=/<!--.*?-->/g,h=/<([\w\-]+)([^>]*)\/\s*>/g,b=/^\s*\/\/.*$/gm,y=/\/\*[^\x00]*?\*\//gm;function w(t,o,u){var a=e.util.brackets;t=o.whitespace?t.replace(/\n/g,"\\n"):t.replace(/\s+/g," ");t=t.trim().replace(g,"");t=t.replace(a(f),'="$1"$2');t=t.replace(c,function(e,t,r,o){if(o.indexOf(a(0))>=0){t=t.toLowerCase();if(i.indexOf(t)>=0)t="riot-"+t;else if(n.indexOf(t)>=0)t="__"+t}return t+'="'+o+'"'});if(o.expr){t=t.replace(a(s),function(e,t){var n=N(t,o,u).trim().replace(/\r?\n|\r/g,"").trim();if(n.slice(-1)==";")n=n.slice(0,-1);return a(0)+n+a(1)})}t=t.replace(h,function(e,t,n){var i="<"+t+(n?" "+n.trim():"")+">";if(r.indexOf(t.toLowerCase())==-1)i+="</"+t+">";return i});t=t.replace(/'/g,"\\'");t=t.replace(a(/\\{|\\}/g),"\\$&");if(o.compact)t=t.replace(/> </g,"><");return t}function x(e){return require("coffee-script").compile(e,{bare:true})}function k(e){return require("babel").transform(e,{blacklist:["useStrict"]}).code}function C(e){return require("typescript-simple")(e)}function O(e){return require("LiveScript").compile(e,{bare:true,header:false})}function E(e){return e}function T(e){return require("jade").render(e,{pretty:true})}function j(e){e=e.replace(b,"").replace(y,"");var t=e.split("\n"),n="";t.forEach(function(e,r){var i=e.trim();if(i[0]!="}"&&i.indexOf("(")>0&&i.indexOf("function")==-1){var o=/[{}]/.exec(i.slice(-1)),u=o&&/(\s+)([\w]+)\s*\(([\w,\s]*)\)\s*\{/.exec(e);if(u&&!/^(if|while|switch|for)$/.test(u[2])){t[r]=u[1]+"this."+u[2]+" = function("+u[3]+") {";if(o[0]=="}"){t[r]+=" "+i.slice(u[0].length-1,-1)+"}.bind(this)"}else{n=u[1]}}}if(e.slice(0,n.length+1)==n+"}"){t[r]=n+"}.bind(this);";n=""}});return t.join("\n")}function L(e,t){return t.replace(v,"").replace(m,function(t,n,r){return n+" "+r.split(/\s*,\s*/g).map(function(t){return t[0]=="@"?t:e+" "+t.replace(/:scope\s*/,"")}).join(",")}).trim()}function N(e,t,n){var r=t.parser||(n?u[n]:j);if(!r)throw new Error('Parser not found "'+n+'"');return r(e,t)}function A(e,t){var n=o[e];if(!n)throw new Error('Template parser not found "'+e+'"');return n(t)}function S(e,t,n){if(n=="scoped-css")e=L(t,e);return e.replace(/\s+/g," ").replace(/\\/g,"\\\\").replace(/'/g,"\\'").trim()}function q(e,t,n,r){return"riot.tag('"+e+"', '"+t+"'"+(n?", '"+n+"'":"")+", function(opts) {"+r+"\n});"}function $(t,n){n=n||{};if(n.brackets)e.settings.brackets=n.brackets;if(n.template)t=A(n.template,t);t=t.replace(a,function(e,t,r){return q(t,w(r,n),"","")});return t.replace(l,function(e,t,r,i){r=r||"";var o=n.type;if(!i.trim()){r=r.replace(p,function(e,t,n,r){if(n)o=n.replace("text/","");i=r;return""})}var u="";var a="css";r=r.replace(d,function(e,t,n,r){if(t&&"scoped"==t.trim())a="scoped-css";else if(n)a=n.replace("text/","");u=r;return""});return q(t,w(r,n,o),S(u,t,a),N(i,n,o))})}if(t){this.riot=require(process.env.RIOT||"../riot");return module.exports={html:w,compile:$,style:S}}var _=document,F,H;function M(e,t){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(n.readyState==4&&n.status==200)t(n.responseText)};n.open("GET",e,true);n.send("")}function R(e){var t=/[ \t]+/.exec(e);if(t)e=e.replace(new RegExp("^"+t[0],"gm"),"");return e}function I(e){var t=_.createElement("script"),n=_.documentElement;t.text=$(e);n.appendChild(t);n.removeChild(t)}function B(e){var t=_.querySelectorAll('script[type="riot/tag"]');[].map.call(t,function(n,r){var i=n.getAttribute("src");function o(n){I(n);if(r+1==t.length){F.trigger("ready");H=true;e&&e()}}return i?M(i,o):o(R(n.innerHTML))})}e.compile=function(t,n){if(typeof t=="string"){if(t.trim()[0]=="<"){var r=R($(t));if(!n)I(r);return r}else{return M(t,function(e){var t=R($(e));I(t);n&&n(t,e)})}}if(typeof t!="function")t=undefined;if(H)return t&&t();if(F){t&&F.on("ready",t)}else{F=e.observable();B(t)}};var V=e.mount;e.mount=function(t,n,r){var i;e.compile(function(){i=V(t,n,r)});return i};e.mountTo=e.mount})(!this.top);e.util={brackets:t,tmpl:n};if(typeof exports==="object")module.exports=e;else if(typeof define==="function"&&define.amd)define(function(){return e});else this.riot=e})();