!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).jinja={})}(this,function(n){"use strict";var u=/'(\\.|[^'])*'|"(\\.|[^"'"])*"/g,o=/([$_a-z][$\w]*)|([+-]?\d+(\.\d+)?)/g,c=/^[+-]?\d+(\.\d+)?$/,e=/\[[@#~](,[@#~])*\]|\[\]|\{([@i]:[@#~])(,[@i]:[@#~])*\}|\{\}/g,a=/[$_a-z][$\w]*/gi,p=/i(\.i|\[[@#i]\])*/g,r=/(\.i|\[[@#i]\])/g,l=/(===?|!==?|>=?|<=?|&&|\|\||[+\-\*\/%])/g,h=/(^|[^$\w])(and|or|not|is|isnot)([^$\w]|$)/g,i=/^\s+/,f=/\s+$/,s=/\{\{\{|\{\{|\{%|\{#/,d={"{{{":/^('(\\.|[^'])*'|"(\\.|[^"'"])*"|.)+?\}\}\}/,"{{":/^('(\\.|[^'])*'|"(\\.|[^"'"])*"|.)+?\}\}/,"{%":/^('(\\.|[^'])*'|"(\\.|[^"'"])*"|.)+?%\}/,"{#":/^('(\\.|[^'])*'|"(\\.|[^"'"])*"|.)+?#\}/},g={"{%":"directive","{{":"output","{#":"comment"},v={and:"&&",or:"||",not:"!",is:"==",isnot:"!="},m={true:!0,false:!1,null:null};function y(){this.nest=[],this.compiled=[],this.childBlocks=0,this.parentBlocks=0,this.isSilent=!1}y.prototype.push=function(t){this.isSilent||this.compiled.push(t)},y.prototype.parse=function(t){return this.tokenize(t),this.compiled},y.prototype.tokenize=function(t){var c=0,a=this,p=!1;!function(t,e,i){for(e=new RegExp(e.source,"g"+(e.ignoreCase?"i":"")+(e.multiline?"m":""));n=e.exec(t);){var n=i(n[0],n.index,t);"number"==typeof n&&(e.lastIndex=n)}}(t,s,function(t,e,i){var n=i.slice(e+t.length).match(d[t]),r=(n=n?n[0]:"").replace(u,"@");if(!n||~r.indexOf(t))return e+1;var s,o,r=n.slice(0,0-t.length);if("-"===r.charAt(0)&&(s=!0),"-"===r.slice(-1)&&(o=!0),r=r.replace(/^-|-$/g,"").trim(),a.rawMode&&t+r!=="{%endraw")return e+1;i=i.slice(c,e);c=e+t.length+n.length,p&&(i=j(i)),s&&(i=i.replace(f,"")),o&&(p=!0),"{{{"===t&&(t="{{",r+="|safe"),a.textHandler(i),a.tokenHandler(t,r)});t=t.slice(c);p&&(t=j(t)),this.textHandler(t)},y.prototype.textHandler=function(t){this.push("write("+JSON.stringify(t)+");")},y.prototype.tokenHandler=function(t,e){t=g[t];"directive"===t?this.compileTag(e):"output"===t&&((t=this.extractEnt(e,u,"@")).src=t.src.replace(/\|\|/g,"~").split("|"),t.src=t.src.map(function(t){return t.split("~").join("||")}),1<(e=this.injectEnt(t,"@")).length?(t=e.slice(1).map(this.parseFilter.bind(this)),this.push("filter("+this.parseExpr(e[0])+","+t.join(",")+");")):this.push("filter("+this.parseExpr(e[0])+");"))},y.prototype.compileTag=function(t){var e=t.split(" ")[0],i=x[e];if(!i)throw new Error("Invalid tag: "+t);i.call(this,t.slice(e.length).trim())},y.prototype.parseFilter=function(t){var e=(t=t.trim()).match(/[:(]/),i=e?e.index:-1;if(i<0)return JSON.stringify([t]);e=t.slice(0,i),i=":"===t.charAt(i)?t.slice(i+1):t.slice(i+1,-1),i=this.parseExpr(i,{terms:!0});return"["+JSON.stringify(e)+","+i+"]"},y.prototype.extractEnt=function(t,e,i){var n=[],r="function"==typeof i;return{src:t=t.replace(e,function(t){var e=r?i(t):i;return e?(n.push(t),e):t}),subs:n}},y.prototype.injectEnt=function(t,e){var i=t.src,n=t.subs,t=Array.isArray(i),r=t?i:[i],s=new RegExp("["+e+"]","g"),o=0;return r.forEach(function(t,e){r[e]=t.replace(s,function(){return n[o++]})}),t?r:r[0]},y.prototype.replaceComplex=function(t){t=this.extractEnt(t,/i(\.i|\[[@#i]\])+/g,"v");return t.src=t.src.replace(e,"~"),this.injectEnt(t,"v")},y.prototype.parseExpr=function(e,t){t=t||{};var i=this.extractEnt(e,u,"@");i.src=i.src.replace(h,function(t,e,i,n){return i in v?e+v[i]+n:t});var n=this.extractEnt(i.src,o,function(t){return t in m||c.test(t)?"#":null}),r=this.extractEnt(n.src,a,"i");r.src=r.src.replace(/\s+/g,"");for(var s=r.src;s!==(s=this.replaceComplex(s)););for(;s!==(s=s.replace(/i(\.i|\[[@#i]\])+/,"v")););return s=(s=(s=(s=s.replace(/[iv]\[v?\]/g,"x")).replace(/[@#~v]/g,"i")).replace(l,"%")).replace(/!+[i]/g,"i"),(t.terms?s.split(","):[s]).forEach(function(t){for(;t!==(t=t.replace(/\(i(%i)*\)/g,"i")););if(!t.match(/^i(%i)*/))throw new Error("Invalid expression: "+e+" "+t)}),r.src=r.src.replace(p,this.parseVar.bind(this)),n.src=this.injectEnt(r,"i"),i.src=this.injectEnt(n,"#"),this.injectEnt(i,"@")},y.prototype.parseVar=function(t){var e=Array.prototype.slice.call(arguments),i=e.pop(),e=e.pop();if("i"===t&&":"===i.charAt(e+1))return'"i"';var n=['"i"'];return t.replace(r,function(t){".i"===t?n.push('"i"'):"[i]"===t?n.push('get("i")'):n.push(t.slice(1,-1))}),"get("+n.join(",")+")"},y.prototype.escName=function(t){return t.replace(/\W/g,function(t){return"$"+t.charCodeAt(0).toString(16)})},y.prototype.parseQuoted=function(t){return"'"===t.charAt(0)&&(t='"'+(t=t.slice(1,-1).replace(/\\.|"/,function(t){return"\\'"===t?"'":"\\"===t.charAt(0)?t:"\\"+t}))+'"'),JSON.parse(t)};var x={if:function(t){this.push("if ("+this.parseExpr(t)+") {"),this.nest.unshift("if")},else:function(){"for"===this.nest[0]?this.push("}, function() {"):this.push("} else {")},elseif:function(t){this.push("} else if ("+this.parseExpr(t)+") {")},endif:function(){this.nest.shift(),this.push("}")},for:function(t){var e=t.indexOf(" in "),i=t.slice(0,e).trim(),e=t.slice(e+4).trim();this.push("each("+this.parseExpr(e)+","+JSON.stringify(i)+",function() {"),this.nest.unshift("for")},endfor:function(){this.nest.shift(),this.push("});")},raw:function(){this.rawMode=!0},endraw:function(){this.rawMode=!1},set:function(t){var e=t.indexOf("="),i=t.slice(0,e).trim(),e=t.slice(e+1).trim();this.push("set("+JSON.stringify(i)+","+this.parseExpr(e)+");")},block:function(t){var e;this.isParent?(++this.parentBlocks,e="block_"+(this.escName(t)||this.parentBlocks),this.push("block(typeof "+e+' == "function" ? '+e+" : function() {")):this.hasParent&&(this.isSilent=!1,++this.childBlocks,e="block_"+(this.escName(t)||this.childBlocks),this.push("function "+e+"() {")),this.nest.unshift("block")},endblock:function(){this.nest.shift(),this.isParent?this.push("});"):this.hasParent&&(this.push("}"),this.isSilent=!0)},extends:function(t){t=this.parseQuoted(t);t=this.readTemplateFile(t);this.isParent=!0,this.tokenize(t),this.isParent=!1,this.hasParent=!0,this.isSilent=!0},include:function(t){t=this.parseQuoted(t);t=this.readTemplateFile(t);this.isInclude=!0,this.tokenize(t),this.isInclude=!1}};x.assign=x.set,x.elif=x.elseif;function E(o,c){function e(t){return null==t?"":"function"==typeof t.toString?t.toString():i.call(t)}function a(t,e){for(var i=l(e),n=0,r=i.length;n").join(">").split('"').join(""")},safe:function(t){return t},toJson:function(t){return"object"==typeof t?JSON.stringify(t):e(t)}},c.filters||{}),d=[t(o||{})],g=[];return{get:function(){for(var t,e=arguments[0],i=d.length;i--&&void 0===(t=d[i][e]););for(var n=1,r=arguments.length;n