-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschnauzer.min.js
2 lines (2 loc) · 11.2 KB
/
schnauzer.min.js
1
2
/**! @license schnauzer v3.0.1; Copyright (C) 2017-2025 by Peter Dematté */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(e):"function"==typeof define&&define.amd?define([],function(){return t(e)},"schnauzer"):"object"==typeof exports?exports.Schnauzer=t(e):e.Schnauzer=t(e)}(this&&this.window||global,function(e){"use strict";var s=e.console,d={start:/^\s+/,end:/\s+$/,whitespace:/\s+/},i=Object.keys||function(e){var t=[],r="";for(r in e)hasOwnProperty.call(e,r)&&t.push(r);return t},p=Object.assign||function(e,t){for(var r in t)n=t,e[s=r]=n[s];var n,s;return e},y=function(){throw"Schnauzer Error: Incorrect template"},t=function(e,t){this.version="3.0.1",this.partials={},this.exports={},this.helpers={lookup:c,log:function(e){if(s){for(var t=0,r=arguments.length,n=[];t<r;t++)t===r-1?e=arguments[t]:n.push(arguments[t]);(s[e.hash.level]||s.log).apply(s,n)}}},this.regex={tags:null,entity:null},this.controls={partialBlocks:[]},this.options={entityMap:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="},helpers:{},partials:{},self:"self",escapeHTML:!0,limitPartialScope:!0,strictArguments:!0,loopHelper:null,renderHook:null,evaluationHook:null,dynamic:null},r(this,t||{},e,this.exports)},r=function(e,t,r,n){"string"!=typeof r&&(t=r,r=void 0),t=p(e.options,t),e.regex.tags=/({{2,3})([#~^/!>*-]*)\s*([^~}]*)([~}]{2,4})/,e.regex.entity=new RegExp("["+i(t.entityMap).join("")+"]","g"),e.helpers=p(e.helpers,t.helpers),e.registerPartial(t.partials),void 0!==r&&e.parse(r),t.dynamic&&(n.render=A,n.renderBlock=f,n.renderHelper=M,n.renderEach=L),delete t.helpers,delete t.partials},u=function(e){this.string=e};return u.prototype.toString=u.prototype.toHTML=function(){return""+this.string},t.extend=p,t.getKeys=i,t.prototype={render:function(e,t){var r=[{context:e,helpers:x([{context:e}],e),vars:{}}];return A(this,this.partials[this.options.self],{scopes:r,extra:t||{},$vars:{},$alias:{}})},parse:function(e){return this.registerPartial(this.options.self,e)},registerHelper:function(e,t){if("string"==typeof e)return this.helpers[e]=t;for(var r in e)this.helpers[r]=e[r]},unregisterHelper:function(e){delete this.helpers[e]},registerPartial:function(e,t){if("string"==typeof e)return this.partials[e]=this.partials[e]||(t.constructor===Array?t:function(e,t){for(var r=t.split(e.regex.tags),n=[{text:P(r[0],"",r[2])}],s="",a="",l=[],i="",o=!1,p=!1,u="",h={if:!0,unless:!0,each:!0,with:!0},c=[],f=e.options.strictArguments,v=1,g=r.length;v<g;v+=5)s=r[v],a=r[v+1].replace("~",""),"\\"!==r[v-1].slice(-1)?("^~"===a&&(a="^",r[v+3]+="~"),i=P(r[v+4],r[v+3],r[v+6]||""),"!"!==a[0]?(l=r[v+2].split(d.whitespace),o=-1!==a.indexOf(">"),p=-1!==a.indexOf("#"),"/"===a&&l[0]===c[0]||"#*"===a?n=E(e,c,n,l,i):("^"!==a||l[0]?"^"===a&&l.unshift("unless"):(a="",l=["else"]),n=S(n,"/"===a?{close:l[0],text:i}:{block:p||"^"===a,partial:o,alts:"else"===l[0]?!!l.shift()&&null:[],helper:u=h[l[0]]?l.shift():"",vars:O(l.join(" "),[],o,!!u,f),escape:s.lastIndexOf("{{")<1&&!o,text:p?"":i,children:p?[{text:i}]:[]}))):n.push({text:i})):H(r,n,v);n.__parent&&y();return n}(this,t));for(var r in e)this.registerPartial(r,e[r])},unregisterPartial:function(e){delete this.partials[e]}},t;function h(t,e,r){return null==e?"":e.constructor===u?e.toString():r&&t.options.escapeHTML?String(e).replace(t.regex.entity,function(e){return t.options.entityMap[e]}):e}function c(e,t){var r=e[t];return null==r?r:Object.prototype.hasOwnProperty.call(e,t)?r:void 0}function w(e,t,r){var n=e.scopes[0],s={},a=p({},e.$vars);if(r)for(var l in n.$vars)a[l]=s[l]=n.$vars[l],n.vars[l]=void 0;if(n.$alias)for(var l in n.$alias)e.$alias.hasOwnProperty(l)||(e.$alias[l]=n.vars[l]);return p(a,e.$alias),e.scopes.unshift({context:void 0===t?{}:t,helpers:n.helpers,vars:a,$alias:e.$alias,$vars:e.$vars}),e.$vars={},e.$alias={},function(){e.scopes.shift(),r&&p(n.vars,s)}}function x(e,t,r,n,s,a){return a?{"@index":n,"@number":n+1,"@key":s,"@odd":n%2!=0,"@last":n===a-1,"@first":0===n,"@length":a,"@depth":0<=e.length-2?e.length-2:0,"@parent":e[1].context,"@root":e[e.length-1].context,this:t}:{"@parent":r,"@root":e[e.length-1].context,this:t}}function k(e,t,r,n){if(e.name){if("includeZero"===e.name)return n[0].zero=e.value;t.$vars[e.name]=r.value,r.alias=e.name}else for(var s=0,a=e.alias.length;s<a;s++)t.$alias[e.alias[s]]=n[s]?n[s].value:void 0}function b(e,t,r){var n=e.value,s=e.type,a="key"!==s&&"helper"!==s,l="this"===n,i=a||l;return e.path.length&&(t=m(e,t,{}).parent),{value:l?t:a?n:t&&t[n],type:a?s:void 0,parent:i?void 0:t,active:i||"helper"===s?0:e.active,key:a?"":n,alias:"",args:[],isLoop:r||!1,helper:e.enclosed}}function m(e,t,r){for(var n,s=0,a=e.path.length;s<a;s++)if(!(t=t[e.path[s]]))return r;return void 0===(n=t[e.value])||(r.value=n,r.parent=t),r}function j(e,t,r){for(var n,s,a,l,i=[],o={},p=null,u={},h={},c=null,f=!1,v="each"===t.helper,g=0,d=t.vars.length;g<d;g++)f=!!(o=t.vars[g]).name||!!o.alias.length,(p=r.scopes[o.depth])?((c=o.strict?null:e.helpers[o.value])&&"string"!==o.type&&(o.type="helper"),u="@"===o.value[0]||"@"===(o.path[0]||"")[0]?p.helpers:c?e.helpers:p.context,i.push(h=b(o,u,v)),"helper"===o.type&&(n=e,s=r,a=h,l=o,!g&&(l.helper=!0),a.args=j(n,{vars:l.args},s)),f&&void 0!==h.value||m(o,p.vars,h),void 0===h.value&&m(o,r.extra,h),h.type||(h.type=h.value&&h.value.constructor===Array?"array":typeof h.value),g||"array"!==h.type||t.helper||(h.isLoop=!0),f&&k(o,r,h,i)):i.push(b(o,u));return i}function _(e,t,r,n){var s="if"===r||"unless"===r,a="number"===e.type||"string"===e.type,l="object"===e.type&&null!==e.value;return n||(n={}),"array"===e.type?!!e.value.length:l?"each"!==r||!!(n.keys=i(e.value)).length:!(!e.zero||0!==e.value)||(!s&&a?void 0!==t:!!t)}function l(e,t,r,n){var s=r.scopes,a="",l=t[0],i=l.key||l.value,o=l.helper?M(e,n,l,r):i,p="@partial-block"===o,u=e.controls.partialBlocks,h=p?u[0]:n.children,c=p?null:e.partials[o],f=e.options.limitPartialScope,v=w(r,t[1]&&!t[1].alias?t[1].value:s[0].context,!c);return n.block&&c||(a=A(e,h,r)),n.block&&u.unshift(n.children),f&&(r.scopes=[s[0]]),c&&(a+=A(e,c,r)),f&&(r.scopes=s),n.block&&u.shift(),v&&v(),a}function z(e,t,r,n,s){var a,l=w(r,t);if(s&&s.data&&!s.SafeString)for(var i in s.data)r.scopes[0].vars["@"+i]=s.data[i];return a=A(e,n,r),l(),a}function L(e,t,r,n,s){for(var a="",l=r.value,i=e.options.loopHelper,o=w(t,l),p=t.scopes,u=p[0],h="array"===r.type,c=h?l:s.keys,f=n.vars[0].alias,v=0,g="",d=c.length;v<d;v++)i&&void 0===c[v]||(g=h?v:c[v],u.helpers=x(p,l[g],l,v,g,d),u.context=l[g],f[0]&&(u.vars[f[0]]=l[g]),f[1]&&(u.vars[f[1]]=g),a+=i?i(e,n,t,r,v):A(e,n.children,t));return o(),a}function M(e,t,r,n){var s=[],a=null,l=0,i=r.args.length,o=n.scopes[0].context;if(!r.value||!r.value.apply)return r.value;for(;l<i;l++)(a=r.args[l]).helper?s.push(M(e,t,a,n)):a.alias||s.push(a.value);return"$"!==r.key[0]&&"helper"===t.vars[0].type&&s.push(function(s,a,e,l){var t=l.scopes[0].helpers,i={name:e.key,data:{},hash:{},lookupProperty:c,createFrame:function(e){return p({},e)},escapeExpression:function(e){return h(s,e,!0)},SafeString:u},r=null;for(var n in t)"@"===n[0]&&void 0!==t[n]&&(i.data[n.substring(1)]=t[n]);for(var o=e.args.length;o--;)(r=e.args[o]).alias&&(i.hash[r.alias]=r.value);return a.block&&a.alts&&(i.fn=function(e,t){return z(s,e,l,a.children,t||i)},i.inverse=a.alts[0]?function(e,t){var r=a.alts,n=r[1]?p({},r[0]):null;return n&&(n.alts=r.slice(1),r=[n]),z(s,e,l,r,t||i)}:function(){return""}),i}(e,t,r,n)),r.value.apply(o,s)}function o(e,t,r,n){var s,a,l,i,o,p,u,h,c,f,v,g,d,y=t[0],x="unless"===n.helper,k=M(e,n,y,r),b={keys:[]},m=_(y,k,n.helper,b),$=n.alts,O=e.options.evaluationHook,H=O&&(a=y,l=O,i=(s=$).length?a.alts=a.alts||[]:null,o=s.length-1,p=s[o]&&0===s[o].vars.length?o:-1,i?(a.index=0,function(e,t){if(!e)return l(a);i[t]||(i[t]=t===p?{args:[]}:e),t!==p&&(i[t].type=e.type),a.index=t+1}):function(){});if(m===x)for(var P=0,S=$.length;P<S&&(x="unless"===(n=$[P]).helper,k=n.helper?M(e,n,y=j(e,n,r)[0],r):A(e,n.children,r),H&&H(y,P),(m=_(y,k,n.helper))===x);P++);return"with"===n.helper&&k?z(e,k,r,n.children):y.isLoop&&k?L(e,r,y,n,b):H&&H()||m===x?n.alts||n.helper?"":n.text:(u=e,c=r,f=k,v=0!==(h=n).vars.length&&"helper"!==h.vars[0].type,g=v&&!h.helper?w(c,f):null,d=h.text,d+=h.helper||v?A(u,h.children,c):f,g&&g(),d)}function f(e,t,r,n){var s=e.options.renderHook,a=t.partial?l(e,n,r,t):o(e,n,r,t);return s?s(e,r,t,n,a):a}function v(e,t,r,n){var s=e.options.renderHook,a=t.partial?l(e,n,r,t):"function"===n[0].type?M(e,t,n[0],r):n[0].value;return a=h(e,a,t.escape),s&&(a=s(e,r,t,n,a)),a+t.text}function A(e,t,r){for(var n="",s={},a=0,l=t.length;a<l;a++)(s=t[a]).vars?n+=(s.block?f:v)(e,s,r,j(e,s,r)):n+=s.text;return n}function g(e,t,r){return!((e&&" "!==e||t&&" "!==t)&&")"!==t&&"="!==r)}function $(e,t,r,n){return t?(e.value=(a=e,"true"===(s=t)?(a.type="boolean",!0):"false"===s?!(a.type="boolean"):isNaN(s)||""===s?s:(a.type="number",+s)),"helper"!==e.type&&n.length?n[0].push(e):r.push(e),{active:0,alias:[],args:[],depth:0,name:"",helper:!1,path:[],strict:!1,type:"key",value:"",enclosed:!1}):e;var s,a}function O(e,t,r,n,s){for(var a={active:0,alias:[],args:[],depth:0,name:"",helper:!1,path:[],strict:!1,type:"key",value:"",enclosed:!1},l="",i="",o="",p="",u=!1,h=[],c=0,f=e.length;c<f;c++)if('"'===(i=e[c])||"'"===i)"\\"!==e[c-1]||'"'!==i&&"'"!==i?i===p?(g(o,e[c+1],o)&&(a.type="string",a=$(a,l,t,h),l=""),p=""):p?l+=i:(p=i,o=e[c-1]):l=l.substring(0,l.length-1)+i;else if(p)l+=i;else if("["===i||"]"===i)u="["===i;else if(u)l+=i;else if(-1===" a./@=()%|".indexOf(i))l+=i;else if("a"===i)" as "===e.substring(c-1,c+3)?c+=2:l+=i;else if(" "===i)a=$(a,l,t,h),l="";else if("."===i&&"../"===e.substring(c,c+3))a.depth++,a.strict=!0,c+=2;else if("/"===i||"."===i){if("."===i&&g(e[c-1],e[c+1])){a=$(a,"this",t,h);continue}l&&"this"!==l&&a.path.push(l),a.strict=!0,l=""}else"@"===i&&"@parent"===e.substring(c,c+7)?(-1!=="./".indexOf(e[c+7])?(a.depth++,a.strict=!0):l+="@parent",c+=6):"="===i?(a.name=l||t.pop().value,l=""):"("===i?(a.type="helper",a.enclosed=!0,h.unshift(a.args)):")"===i?(a=$(a,l,t,h),h.shift(),h.length&&h[0].push(t.pop()),l=""):"%"===i?a.active++:"|"===i?(c+=(l=(l=e.substring(c+1)).substring(0,l.indexOf(i))).length+1,t[t.length-1].alias=P(l,"~","~").split(" "),l=""):l+=i;if(h.length&&y(),$(a,l,t,h),r||!t.length)return t;if(n||(t[0].type="key"),t[1]&&"key"===t[0].type){if(t[0].type="helper",s)for(c=1,f=t.length;c<f;c++)"key"===t[c].type&&(t[c].strict=!0);t[0].args=t.splice(1)}return t}function H(e,t,r){var n=t[t.length-1],s=n.text;n.text=s.substring(0,s.length-1),t.push({text:e.slice(r,r+5).join("")})}function P(e,t,r){return-1!==t.indexOf("~")&&(e=e.replace(d.start,"")),r&&-1!==r.indexOf("~")?e.replace(d.end,""):e}function n(e,t){return t.children.__parent=e,t.children}function a(e){var t=e.__parent;return t||y(),delete e.__parent,t}function S(e,t){var r;return t.close?(function(e,t){for(var r=e.length;r--&&!e[r].alts;);return t===e[r].helper||t===e[r].block||t===e[r].vars[0].value}(e=a(e),t.close)||y(),e[e.length-1].partial&&((r=e[e.length-1]).children.unshift({text:r.text}),r.text=""),e.push({text:t.text})):t.block?(e.push(t),e=n(e,t)):t.alts?e.push(t):(t.block=!0,(e=a(e))[e.length-1].alts.push(t),e=n(e,t)),e}function E(e,t,r,n,s){var a={};return n[1]?(t.unshift(n[0]),S(r,{block:n[0],name:n[1].replace(/['"]/g,""),children:[],text:s,alts:[]})):((a=(r=S(r,{close:n[0],text:s})).splice(-2,1)[0]).children.unshift({text:a.text}),e.registerPartial(a.name,a.children),t.shift(),r)}});