!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self,e.Mustache=t())}(this,function(){"use strict";function e(e){return"function"==typeof e}function t(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function n(e,t){return null!=e&&"object"==typeof e&&t in e}function r(e,t){return null!=e&&"object"!=typeof e&&e.hasOwnProperty&&e.hasOwnProperty(t)}function i(e){return!function(e,t){return p.call(e,t)}(l,e)}function o(e){this.string=e,this.tail=e,this.pos=0}function s(e,t){this.view=e,this.cache={".":this.view},this.parent=t}function a(){this.cache={}}var u=Object.prototype.toString,c=Array.isArray||function(e){return"[object Array]"===u.call(e)},p=RegExp.prototype.test,l=/\S/,h={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"},f=/\s*/,d=/\s+/,v=/\s*=/,g=/\s*\}/,y=/#|\^|\/|>|\{|&|=|!/;o.prototype.eos=function(){return""===this.tail},o.prototype.scan=function(e){var t=this.tail.match(e);if(!t||0!==t.index)return"";var n=t[0];return this.tail=this.tail.substring(n.length),this.pos+=n.length,n},o.prototype.scanUntil=function(e){var t,n=this.tail.search(e);switch(n){case-1:t=this.tail,this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,n),this.tail=this.tail.substring(n)}return this.pos+=t.length,t},s.prototype.push=function(e){return new s(e,this)},s.prototype.lookup=function(t){var i,o=this.cache;if(o.hasOwnProperty(t))i=o[t];else{for(var s,a,u,c=this,p=!1;c;){if(t.indexOf(".")>0)for(s=c.view,a=t.split("."),u=0;null!=s&&u<a.length;)u===a.length-1&&(p=n(s,a[u])||r(s,a[u])),s=s[a[u++]];else s=c.view[t],p=n(c.view,t);if(p){i=s;break}c=c.parent}o[t]=i}return e(i)&&(i=i.call(this.view)),i},a.prototype.clearCache=function(){this.cache={}},a.prototype.parse=function(e,n){var r=this.cache,s=e+":"+(n||w.tags).join(":"),a=r[s];return null==a&&(a=r[s]=function(e,n){function r(){if(k&&!x)for(;b.length;)delete m[b.pop()];else b=[];k=!1,x=!1}function s(e){if("string"==typeof e&&(e=e.split(d,2)),!c(e)||2!==e.length)throw new Error("Invalid tags: "+e);a=new RegExp(t(e[0])+"\\s*"),u=new RegExp("\\s*"+t(e[1])),p=new RegExp("\\s*"+t("}"+e[1]))}if(!e)return[];var a,u,p,l=!1,h=[],m=[],b=[],k=!1,x=!1,E="",U=0;s(n||w.tags);for(var j,T,C,P,S,V,O=new o(e);!O.eos();){if(j=O.pos,C=O.scanUntil(a))for(var A=0,I=C.length;A<I;++A)i(P=C.charAt(A))?(b.push(m.length),E+=P):(x=!0,l=!0,E+=" "),m.push(["text",P,j,j+1]),j+=1,"\n"===P&&(r(),E="",U=0,l=!1);if(!O.scan(a))break;if(k=!0,T=O.scan(y)||"name",O.scan(f),"="===T?(C=O.scanUntil(v),O.scan(v),O.scanUntil(u)):"{"===T?(C=O.scanUntil(p),O.scan(g),O.scanUntil(u),T="&"):C=O.scanUntil(u),!O.scan(u))throw new Error("Unclosed tag at "+O.pos);if(S=">"==T?[T,C,j,O.pos,E,U,l]:[T,C,j,O.pos],U++,m.push(S),"#"===T||"^"===T)h.push(S);else if("/"===T){if(!(V=h.pop()))throw new Error('Unopened section "'+C+'" at '+j);if(V[1]!==C)throw new Error('Unclosed section "'+V[1]+'" at '+j)}else"name"===T||"{"===T||"&"===T?x=!0:"="===T&&s(C)}if(r(),V=h.pop())throw new Error('Unclosed section "'+V[1]+'" at '+O.pos);return function(e){for(var t,n=[],r=n,i=[],o=0,s=e.length;o<s;++o)switch((t=e[o])[0]){case"#":case"^":r.push(t),i.push(t),r=t[4]=[];break;case"/":i.pop()[5]=t[2],r=i.length>0?i[i.length-1][4]:n;break;default:r.push(t)}return n}(function(e){for(var t,n,r=[],i=0,o=e.length;i<o;++i)(t=e[i])&&("text"===t[0]&&n&&"text"===n[0]?(n[1]+=t[1],n[3]=t[3]):(r.push(t),n=t));return r}(m))}(e,n)),a},a.prototype.render=function(e,t,n,r){var i=this.parse(e,r),o=t instanceof s?t:new s(t,void 0);return this.renderTokens(i,o,n,e,r)},a.prototype.renderTokens=function(e,t,n,r,i){for(var o,s,a,u="",c=0,p=e.length;c<p;++c)a=void 0,"#"===(s=(o=e[c])[0])?a=this.renderSection(o,t,n,r):"^"===s?a=this.renderInverted(o,t,n,r):">"===s?a=this.renderPartial(o,t,n,i):"&"===s?a=this.unescapedValue(o,t):"name"===s?a=this.escapedValue(o,t):"text"===s&&(a=this.rawValue(o)),void 0!==a&&(u+=a);return u},a.prototype.renderSection=function(t,n,r,i){var o=this,s="",a=n.lookup(t[1]);if(a){if(c(a))for(var u=0,p=a.length;u<p;++u)s+=this.renderTokens(t[4],n.push(a[u]),r,i);else if("object"==typeof a||"string"==typeof a||"number"==typeof a)s+=this.renderTokens(t[4],n.push(a),r,i);else if(e(a)){if("string"!=typeof i)throw new Error("Cannot use higher-order sections without the original template");null!=(a=a.call(n.view,i.slice(t[3],t[5]),function(e){return o.render(e,n,r)}))&&(s+=a)}else s+=this.renderTokens(t[4],n,r,i);return s}},a.prototype.renderInverted=function(e,t,n,r){var i=t.lookup(e[1]);if(!i||c(i)&&0===i.length)return this.renderTokens(e[4],t,n,r)},a.prototype.indentPartial=function(e,t,n){for(var r=t.replace(/[^ \t]/g,""),i=e.split("\n"),o=0;o<i.length;o++)i[o].length&&(o>0||!n)&&(i[o]=r+i[o]);return i.join("\n")},a.prototype.renderPartial=function(t,n,r,i){if(r){var o=e(r)?r(t[1]):r[t[1]];if(null!=o){var s=t[6],a=t[5],u=t[4],c=o;return 0==a&&u&&(c=this.indentPartial(o,u,s)),this.renderTokens(this.parse(c,i),n,r,c)}}},a.prototype.unescapedValue=function(e,t){var n=t.lookup(e[1]);if(null!=n)return n},a.prototype.escapedValue=function(e,t){var n=t.lookup(e[1]);if(null!=n)return w.escape(n)},a.prototype.rawValue=function(e){return e[1]};var w={name:"mustache.js",version:"3.2.1",tags:["{{","}}"],clearCache:void 0,escape:void 0,parse:void 0,render:void 0,to_html:void 0,Scanner:void 0,Context:void 0,Writer:void 0},m=new a;return w.clearCache=function(){return m.clearCache()},w.parse=function(e,t){return m.parse(e,t)},w.render=function(e,t,n,r){if("string"!=typeof e)throw new TypeError('Invalid template! Template should be a "string" but "'+function(e){return c(e)?"array":typeof e}(e)+'" was given as the first argument for mustache#render(template, view, partials)');return m.render(e,t,n,r)},w.to_html=function(t,n,r,i){var o=w.render(t,n,r);if(!e(i))return o;i(o)},w.escape=function(e){return String(e).replace(/[&<>"'`=\/]/g,function(e){return h[e]})},w.Scanner=o,w.Context=s,w.Writer=a,w});