mustache.js
7.86 KB
module.exports=(()=>{var r={272:function(r){(function(e,t){true?r.exports=t():0})(this,function(){"use strict";var r=Object.prototype.toString;var e=Array.isArray||function isArrayPolyfill(e){return r.call(e)==="[object Array]"};function isFunction(r){return typeof r==="function"}function typeStr(r){return e(r)?"array":typeof r}function escapeRegExp(r){return r.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function hasProperty(r,e){return r!=null&&typeof r==="object"&&e in r}function primitiveHasOwnProperty(r,e){return r!=null&&typeof r!=="object"&&r.hasOwnProperty&&r.hasOwnProperty(e)}var t=RegExp.prototype.test;function testRegExp(r,e){return t.call(r,e)}var i=/\S/;function isWhitespace(r){return!testRegExp(i,r)}var n={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};function escapeHtml(r){return String(r).replace(/[&<>"'`=\/]/g,function fromEntityMap(r){return n[r]})}var s=/\s*/;var p=/\s+/;var f=/\s*=/;var h=/\s*\}/;var a=/#|\^|\/|>|\{|&|=|!/;function parseTemplate(r,t){if(!r)return[];var i=false;var n=[];var o=[];var c=[];var l=false;var d=false;var w="";var v=0;function stripSpace(){if(l&&!d){while(c.length)delete o[c.pop()]}else{c=[]}l=false;d=false}var y,g,C;function compileTags(r){if(typeof r==="string")r=r.split(p,2);if(!e(r)||r.length!==2)throw new Error("Invalid tags: "+r);y=new RegExp(escapeRegExp(r[0])+"\\s*");g=new RegExp("\\s*"+escapeRegExp(r[1]));C=new RegExp("\\s*"+escapeRegExp("}"+r[1]))}compileTags(t||u.tags);var _=new Scanner(r);var b,E,W,P,U,S;while(!_.eos()){b=_.pos;W=_.scanUntil(y);if(W){for(var O=0,A=W.length;O<A;++O){P=W.charAt(O);if(isWhitespace(P)){c.push(o.length);w+=P}else{d=true;i=true;w+=" "}o.push(["text",P,b,b+1]);b+=1;if(P==="\n"){stripSpace();w="";v=0;i=false}}}if(!_.scan(y))break;l=true;E=_.scan(a)||"name";_.scan(s);if(E==="="){W=_.scanUntil(f);_.scan(f);_.scanUntil(g)}else if(E==="{"){W=_.scanUntil(C);_.scan(h);_.scanUntil(g);E="&"}else{W=_.scanUntil(g)}if(!_.scan(g))throw new Error("Unclosed tag at "+_.pos);if(E==">"){U=[E,W,b,_.pos,w,v,i]}else{U=[E,W,b,_.pos]}v++;o.push(U);if(E==="#"||E==="^"){n.push(U)}else if(E==="/"){S=n.pop();if(!S)throw new Error('Unopened section "'+W+'" at '+b);if(S[1]!==W)throw new Error('Unclosed section "'+S[1]+'" at '+b)}else if(E==="name"||E==="{"||E==="&"){d=true}else if(E==="="){compileTags(W)}}stripSpace();S=n.pop();if(S)throw new Error('Unclosed section "'+S[1]+'" at '+_.pos);return nestTokens(squashTokens(o))}function squashTokens(r){var e=[];var t,i;for(var n=0,s=r.length;n<s;++n){t=r[n];if(t){if(t[0]==="text"&&i&&i[0]==="text"){i[1]+=t[1];i[3]=t[3]}else{e.push(t);i=t}}}return e}function nestTokens(r){var e=[];var t=e;var i=[];var n,s;for(var p=0,f=r.length;p<f;++p){n=r[p];switch(n[0]){case"#":case"^":t.push(n);i.push(n);t=n[4]=[];break;case"/":s=i.pop();s[5]=n[2];t=i.length>0?i[i.length-1][4]:e;break;default:t.push(n)}}return e}function Scanner(r){this.string=r;this.tail=r;this.pos=0}Scanner.prototype.eos=function eos(){return this.tail===""};Scanner.prototype.scan=function scan(r){var e=this.tail.match(r);if(!e||e.index!==0)return"";var t=e[0];this.tail=this.tail.substring(t.length);this.pos+=t.length;return t};Scanner.prototype.scanUntil=function scanUntil(r){var e=this.tail.search(r),t;switch(e){case-1:t=this.tail;this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,e);this.tail=this.tail.substring(e)}this.pos+=t.length;return t};function Context(r,e){this.view=r;this.cache={".":this.view};this.parent=e}Context.prototype.push=function push(r){return new Context(r,this)};Context.prototype.lookup=function lookup(r){var e=this.cache;var t;if(e.hasOwnProperty(r)){t=e[r]}else{var i=this,n,s,p,f=false;while(i){if(r.indexOf(".")>0){n=i.view;s=r.split(".");p=0;while(n!=null&&p<s.length){if(p===s.length-1)f=hasProperty(n,s[p])||primitiveHasOwnProperty(n,s[p]);n=n[s[p++]]}}else{n=i.view[r];f=hasProperty(i.view,r)}if(f){t=n;break}i=i.parent}e[r]=t}if(isFunction(t))t=t.call(this.view);return t};function Writer(){this.templateCache={_cache:{},set:function set(r,e){this._cache[r]=e},get:function get(r){return this._cache[r]},clear:function clear(){this._cache={}}}}Writer.prototype.clearCache=function clearCache(){if(typeof this.templateCache!=="undefined"){this.templateCache.clear()}};Writer.prototype.parse=function parse(r,e){var t=this.templateCache;var i=r+":"+(e||u.tags).join(":");var n=typeof t!=="undefined";var s=n?t.get(i):undefined;if(s==undefined){s=parseTemplate(r,e);n&&t.set(i,s)}return s};Writer.prototype.render=function render(r,e,t,i){var n=this.getConfigTags(i);var s=this.parse(r,n);var p=e instanceof Context?e:new Context(e,undefined);return this.renderTokens(s,p,t,r,i)};Writer.prototype.renderTokens=function renderTokens(r,e,t,i,n){var s="";var p,f,h;for(var a=0,u=r.length;a<u;++a){h=undefined;p=r[a];f=p[0];if(f==="#")h=this.renderSection(p,e,t,i,n);else if(f==="^")h=this.renderInverted(p,e,t,i,n);else if(f===">")h=this.renderPartial(p,e,t,n);else if(f==="&")h=this.unescapedValue(p,e);else if(f==="name")h=this.escapedValue(p,e,n);else if(f==="text")h=this.rawValue(p);if(h!==undefined)s+=h}return s};Writer.prototype.renderSection=function renderSection(r,t,i,n,s){var p=this;var f="";var h=t.lookup(r[1]);function subRender(r){return p.render(r,t,i,s)}if(!h)return;if(e(h)){for(var a=0,u=h.length;a<u;++a){f+=this.renderTokens(r[4],t.push(h[a]),i,n,s)}}else if(typeof h==="object"||typeof h==="string"||typeof h==="number"){f+=this.renderTokens(r[4],t.push(h),i,n,s)}else if(isFunction(h)){if(typeof n!=="string")throw new Error("Cannot use higher-order sections without the original template");h=h.call(t.view,n.slice(r[3],r[5]),subRender);if(h!=null)f+=h}else{f+=this.renderTokens(r[4],t,i,n,s)}return f};Writer.prototype.renderInverted=function renderInverted(r,t,i,n,s){var p=t.lookup(r[1]);if(!p||e(p)&&p.length===0)return this.renderTokens(r[4],t,i,n,s)};Writer.prototype.indentPartial=function indentPartial(r,e,t){var i=e.replace(/[^ \t]/g,"");var n=r.split("\n");for(var s=0;s<n.length;s++){if(n[s].length&&(s>0||!t)){n[s]=i+n[s]}}return n.join("\n")};Writer.prototype.renderPartial=function renderPartial(r,e,t,i){if(!t)return;var n=this.getConfigTags(i);var s=isFunction(t)?t(r[1]):t[r[1]];if(s!=null){var p=r[6];var f=r[5];var h=r[4];var a=s;if(f==0&&h){a=this.indentPartial(s,h,p)}var u=this.parse(a,n);return this.renderTokens(u,e,t,a,i)}};Writer.prototype.unescapedValue=function unescapedValue(r,e){var t=e.lookup(r[1]);if(t!=null)return t};Writer.prototype.escapedValue=function escapedValue(r,e,t){var i=this.getConfigEscape(t)||u.escape;var n=e.lookup(r[1]);if(n!=null)return typeof n==="number"&&i===u.escape?String(n):i(n)};Writer.prototype.rawValue=function rawValue(r){return r[1]};Writer.prototype.getConfigTags=function getConfigTags(r){if(e(r)){return r}else if(r&&typeof r==="object"){return r.tags}else{return undefined}};Writer.prototype.getConfigEscape=function getConfigEscape(r){if(r&&typeof r==="object"&&!e(r)){return r.escape}else{return undefined}};var u={name:"mustache.js",version:"4.1.0",tags:["{{","}}"],clearCache:undefined,escape:undefined,parse:undefined,render:undefined,Scanner:undefined,Context:undefined,Writer:undefined,set templateCache(r){o.templateCache=r},get templateCache(){return o.templateCache}};var o=new Writer;u.clearCache=function clearCache(){return o.clearCache()};u.parse=function parse(r,e){return o.parse(r,e)};u.render=function render(r,e,t,i){if(typeof r!=="string"){throw new TypeError('Invalid template! Template should be a "string" '+'but "'+typeStr(r)+'" was given as the first '+"argument for mustache#render(template, view, partials)")}return o.render(r,e,t,i)};u.escape=escapeHtml;u.Scanner=Scanner;u.Context=Context;u.Writer=Writer;return u})}};var e={};function __nccwpck_require__(t){if(e[t]){return e[t].exports}var i=e[t]={exports:{}};var n=true;try{r[t].call(i.exports,i,i.exports,__nccwpck_require__);n=false}finally{if(n)delete e[t]}return i.exports}__nccwpck_require__.ab=__dirname+"/";return __nccwpck_require__(272)})();