@kosatyi/ejs 0.0.106 → 0.0.108
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -7
- package/bin/bundler.js +21 -9
- package/dist/cjs/browser.js +532 -650
- package/dist/cjs/bundler.js +110 -78
- package/dist/cjs/element.js +28 -63
- package/dist/cjs/index.js +540 -667
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/worker.js +553 -976
- package/dist/esm/browser.js +565 -588
- package/dist/esm/bundler.js +109 -78
- package/dist/esm/element.js +16 -50
- package/dist/esm/index.js +569 -604
- package/dist/esm/worker.js +563 -611
- package/dist/kosatyi-ejs-0.0.107.tgz +0 -0
- package/dist/umd/browser.js +533 -651
- package/dist/umd/browser.js.map +7 -0
- package/dist/umd/browser.min.js +1 -1
- package/dist/umd/browser.min.js.map +7 -0
- package/dist/umd/element.js +28 -63
- package/dist/umd/element.min.js +1 -1
- package/dist/umd/index.js +541 -668
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/worker.js +819 -1242
- package/dist/umd/worker.min.js +1 -3
- package/package.json +80 -71
- package/types/browser.d.ts +10 -0
- package/types/bundler.d.ts +11 -12
- package/types/context.d.ts +96 -0
- package/types/ejs.d.ts +111 -73
- package/types/element.d.ts +9 -0
- package/types/error.d.ts +14 -0
- package/types/global.d.ts +6 -6
- package/types/index.d.ts +16 -0
- package/types/worker.d.ts +31 -0
package/dist/umd/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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).ejs={})}(this,(function(t){"use strict";var e=function(){var t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},n=function(t){return Array.isArray(t)},r=function(t){return"function"==typeof t},o=function(t){return"string"==typeof t},i=function(t){return"boolean"==typeof t},c=function(t){return void 0===t},u="[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),a={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},s={"&":"&","<":"<",">":">",'"':""","'":"'"},f=function(t){return new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g")},l=f(s),p=f(a),h=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(l,(function(t){return s[t]}))},v=function(t,e){var n=t;return null==n?"":!0===Boolean(e)?h(n):n},g=function(t,e,n){for(var o=t,i=String(e).split("."),c=i.pop(),u=0;u<i.length;u++){var a=i[u];if(r(o.toJSON)&&(o=o.toJSON()),n&&!1===o.hasOwnProperty(a)){o={};break}o=o[a]=o[a]||{}}return r(o.toJSON)&&(o=o.toJSON()),[o,c]},d=function(t){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];return n.filter((function(t){return t})).reduce((function(t,e){return Object.assign(t,e)}),t)},b=function(){},m=function(t,e){var n;for(n in t)E(t,n)&&e(t[n],n,t)},y=function(t,e){return function(t,e){var n=t instanceof Array,r=n?[]:{};return m(t,(function(t,o,i){var u=e(t,o,i);!1===c(u)&&(n?r.push(u):r[o]=u)})),r}(t,(function(t,n){if(-1===e.indexOf(n))return t}))},E=function(t,e){return t&&t.hasOwnProperty(e)},j={export:"ejsPrecompiled",cache:!0,chokidar:null,path:"views",resolver:function(t,e){return Promise.resolve(["resolver is not defined",t,e].join(" "))},extension:"ejs",rmWhitespace:!0,withObject:!0,globalHelpers:[],vars:{SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},token:{start:"<%",end:"%>",regex:"([\\s\\S]+?)"}},O=function(t,c){return d(t,{path:e(o,j.path,t.path,c.path),export:e(o,j.export,t.export,c.export),resolver:e(r,j.resolver,t.resolver,c.resolver),extension:e(o,j.extension,t.extension,c.extension),withObject:e(i,j.withObject,t.withObject,c.withObject),rmWhitespace:e(i,j.rmWhitespace,t.rmWhitespace,c.rmWhitespace),cache:e(i,j.cache,t.cache,c.cache),token:d({},j.token,t.token,c.token),vars:d({},j.vars,t.vars,c.vars),globalHelpers:e(n,j.globalHelpers,t.globalHelpers,c.globalHelpers)})},x=function(t,e,n){var o={path:null,resolver:null},i=function(t,e){return r(t)?t:n.compile(t,e)},c=function(t){o.path=t.path,r(t.resolver)&&(o.resolver=t.resolver)};return c(t),{get:function(t){return e.exist(t)?e.resolve(t):function(t){return o.resolver(o.path,t)}(t).then((function(n){return function(t,n){return e.set(t,n),n}(t,i(n,t))}))},configure:c,compile:i}},w=[{symbol:"-",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,",1))\n").concat(this.BUFFER,"('")}},{symbol:"=",format:function(t){return"')\n".concat(this.BUFFER,"(").concat(this.SAFE,"(").concat(t,"))\n").concat(this.BUFFER,"('")}},{symbol:"#",format:function(t){return"')\n/**".concat(t,"**/\n").concat(this.BUFFER,"('")}},{symbol:"",format:function(t){return"')\n".concat(t.trim(),"\n").concat(this.BUFFER,"('")}}],P=function(t){var e={},n=function(t){e.withObject=t.withObject,e.rmWhitespace=t.rmWhitespace,e.token=t.token,e.vars=t.vars,e.globalHelpers=t.globalHelpers,e.matches=[],e.formats=[],e.slurp={match:"[s\t\n]*",start:[e.token.start,"_"],end:["_",e.token.end]},w.forEach((function(t){e.matches.push(e.token.start.concat(t.symbol).concat(e.token.regex).concat(e.token.end)),e.formats.push(t.format.bind(e.vars))})),e.regex=new RegExp(e.matches.join("|").concat("|$"),"g"),e.slurpStart=new RegExp([e.slurp.match,e.slurp.start.join("")].join(""),"gm"),e.slurpEnd=new RegExp([e.slurp.end.join(""),e.slurp.match].join(""),"gm")};return n(t),{configure:n,compile:function(t,n){var r=e.vars,o=r.SCOPE,i=r.SAFE,c=r.BUFFER,u=r.COMPONENT,s=r.ELEMENT,f=e.globalHelpers;e.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(e.slurpStart,e.token.start).replace(e.slurpEnd,e.token.end);var l,h,v,g="".concat(c,"('");l=e.regex,h=function(n,r,o){g+=(""+t.slice(r,o)).replace(p,(function(t){return"\\"+a[t]})),n.forEach((function(t,n){t&&(g+=e.formats[n](t))}))},v=0,t.replace(l,(function(){var t=[].slice.call(arguments,0,-1),e=t.pop(),n=t.shift();return h(t,v,e),v=e+n.length,n})),g="try{".concat(g+="');","}catch(e){return ").concat(c,".error(e)}"),e.withObject&&(g="with(".concat(o,"){").concat(g,"}")),g="".concat(c,".start();").concat(g,"return ").concat(c,".end();"),g+="\n//# sourceURL=".concat(n);var d=null,b=[o,u,s,c,i].concat(f);try{(d=Function.apply(null,b.concat(g))).source="(function(".concat(b.join(","),"){\n").concat(g,"\n});")}catch(t){throw t.filename=n,t.source=g,t}return d}}},S="undefined"!=typeof globalThis?globalThis:window||self,k=function(){var t={},e={},n=function(n){t.enabled&&d(e,n||{})},r=function(n){if(t.enabled)return e[n]},o=function(t){delete e[t]},i=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.enabled=e.cache,t.export=e.export,!1===u&&n(S[t.export])};return i(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{configure:i,load:n,set:function(n,r){t.enabled&&(e[n]=r)},get:r,exist:function(n){if(t.enabled)return E(e,n)},clear:function(){Object.keys(e).forEach(o)},remove:o,resolve:function(t){return Promise.resolve(r(t))}}},F=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],T=" ",B='"',C="/",N="<",R=">",M=function(t,e,n){var r=[],o=-1===F.indexOf(t),i=function(t,e){var n=[];return m(t,(function(t,r,o){var i=e(t,r,o);!1===c(i)&&n.push(i)})),n}(e,(function(t,e){if(null!=t)return[h(e),[B,h(t),B].join("")].join("=")})).join(T);return r.push([N,t,T,i,R].join("")),n&&o&&r.push(n instanceof Array?n.join(""):n),o&&r.push([N,C,t,R].join("")),r.join("")};function A(){A.call(this)}function $(){A.call(this)}function L(){A.call(this)}function U(t){return Promise.all(t||[]).then((function(t){return t.join("")})).catch((function(t){return t}))}function H(){var t=[],e=[],n=function(t){e.push(t)};return n.start=function(){e=[]},n.backup=function(){t.push(e.concat()),e=[]},n.restore=function(){var n=e.concat();return e=t.pop(),U(n)},n.error=function(t){return e=t,Promise.reject(new L(e.message));var e},n.end=function(){return U(e)},n}Object.setPrototypeOf(A.prototype,Error.prototype),Object.assign(A.prototype,{code:0,getCode:function(){return this.code},getMessage:function(){return this.message},toString:function(){return this.getMessage()}}),Object.setPrototypeOf($.prototype,A.prototype),Object.assign($.prototype,{code:404}),Object.setPrototypeOf(L.prototype,A.prototype),Object.assign(L.prototype,{code:500});var W=Symbol("ContextScope.parentTemplate"),q=function(t,e){var n,i=function(t,e){n=function(t,e){var n=t.vars,i=n.BLOCKS,c=n.MACRO,u=n.EXTEND,a=n.LAYOUT,s=n.BUFFER,f=n.SAFE,l=n.SCOPE,p=n.COMPONENT,h=n.ELEMENT;function j(t){this[W]=null,this[i]={},this[c]={},Object.assign(this,y(t,[l,s,f,p,h]))}return Object.assign(j.prototype,e),Object.defineProperty(j.prototype,s,{value:H()}),Object.defineProperty(j.prototype,i,{value:{},writable:!0}),Object.defineProperty(j.prototype,c,{value:{},writable:!0}),Object.defineProperty(j.prototype,a,{value:!1,writable:!0}),Object.defineProperty(j.prototype,u,{value:!1,writable:!0}),Object.defineProperty(j.prototype,W,{value:null,writable:!0}),Object.defineProperties(j.prototype,{setParentTemplate:{value:function(t){return this[W]=t,this}},getParentTemplate:{value:function(){return this[W]}},useSafeValue:{get:function(){return v}},useComponent:{get:function(){return r(this[p])?this[p].bind(this):function(){throw new Error("".concat(p," must be a function"))}}},useElement:{get:function(){return r(this[h])?this[h].bind(this):function(){throw new Error("".concat(h," must be a function"))}}},getMacro:{value:function(){return this[c]}},getBuffer:{value:function(){return this[s]}},getBlocks:{value:function(){return this[i]}},setExtend:{value:function(t){return this[u]=t,this}},getExtend:{value:function(){return this[u]}},setLayout:{value:function(t){return this[a]=t,this}},getLayout:{value:function(){return this[a]}},clone:{value:function(t){var e=[a,u,s];return!0===t&&e.push(i),y(this,e)}},extend:{value:function(t){this.setExtend(!0),this.setLayout(t)}},echo:{value:function(t){var e=this.getBuffer();[].slice.call(arguments).forEach(e)}},fn:{value:function(t){var e=this.getBuffer(),n=this;return function(){if(r(t))return e.backup(),e(t.apply(n,arguments)),e.restore()}}},macro:{value:function(t,e){var n=this.getMacro(),r=this.fn(e),o=this;n[t]=function(){return o.echo(r.apply(void 0,arguments))}}},call:{value:function(t){var e=this.getMacro()[t],n=[].slice.call(arguments,1);if(r(e))return e.apply(e,n)}},block:{value:function(t,e){var n=this,r=this.getBlocks();if(r[t]=r[t]||[],r[t].push(this.fn(e)),!this.getExtend()){var o=Object.assign([],r[t]),i=function(){return o.shift()},c=function(){var t=i();return t?function(){n.echo(t(c()))}:b};this.echo(i()(c()))}}},hasBlock:{value:function(t){return this.getBlocks().hasOwnProperty(t)}},include:{value:function(t,e,n){var r=!1===n?{}:this.clone(!0),o=d(r,e||{}),i=this.render(t,o);this.echo(i)}},use:{value:function(t,e){var n=this;this.echo(Promise.resolve(this.require(t)).then((function(t){var r=n.getMacro();m(t,(function(t,n){r[[e,n].join(".")]=t}))})))}},async:{value:function(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value:function(t,e){var n=g(this,t,!0),r=n.shift(),o=n.pop();return E(r,o)?r[o]:e}},set:{value:function(t,e){var n=g(this,t,!1),r=n.shift(),o=n.pop();return this.getParentTemplate()&&E(r,o)?r[o]:r[o]=e}},each:{value:function(t,e){o(t)&&(t=this.get(t,[])),m(t,e)},writable:!0},el:{value:function(t,e,n){n=r(n)?this.fn(n)():n,this.echo(Promise.resolve(n).then((function(n){return M(t,e,n)})))},writable:!0},ui:{value:function(t){},writable:!0}}),j}(t,e)};return i(t,e),{configure:i,create:function(t){return new n(t)},helpers:function(t){d(n.prototype,t||{})}}},J=function(){var t=O({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),e={},n=q(t,e),o=P(t),i=k(t),c=x(t,i,o),u=function(e){return function(t,e){var n=t.split(".").pop();return n!==e&&(t=[t,e].join(".")),t}(e,t.extension)},a=function(t){var e=h({});return v(u(t),e).then((function(){return e.getMacro()}))},s=function(t,e){var n=h(e);return v(u(t),n).then(f(t,n))},f=function(t,e){return function(n){return e.getExtend()?(e.setExtend(!1),l(e.getLayout(),e,t)):n}},l=function(t,e,n){var r=h(e);return n&&r.setParentTemplate(n),v(u(t),r).then(f(t,r))},p=function(t){n.helpers(d(e,t))},h=function(t){return n.create(t)},v=function(e,n){var o=[n,n.useComponent,n.useElement,n.getBuffer(),n.useSafeValue],i=t.globalHelpers.filter((function(t){return r(n[t])})).map((function(t){return n[t].bind(n)}));return c.get(e).then((function(t){return t.apply(n,o.concat(i))}))};return p({render:s,require:a}),{configure:function(){return O(t,(arguments.length>0&&void 0!==arguments[0]?arguments[0]:{})||{}),n.configure(t,e),o.configure(t),i.configure(t),c.configure(t),t},create:function(t){return J(t)},createContext:h,render:s,require:a,preload:function(t){return i.load(t||{})},compile:function(t,e){return o.compile(t,e)},helpers:p}},_={},D=J({resolver:function(t,e){return new Promise((function(n,r){_.readFile(function(t,e){return(e=[t,e].join("/")).replace(/\/\//g,"/")}(t,e),(function(t,e){t?r(new A):n(e.toString())}))}))}}),K=D.render,V=D.createContext,X=D.compile,Y=D.helpers,z=D.preload,G=D.configure,I=D.create,Q=function(t,n){return function(c,u,a){r(u)&&(a=u,u={});var s=d({},(u=u||{}).settings),f=e(o,j.path,s.views),l=e(i,j.cache,s["view cache"]),p=d({},s["view options"]),h=_.relative(f,c);return p.path=f,p.cache=l,t(p),n(h,u).then((function(t){a(null,t)})).catch((function(t){a(t)}))}}(G,K);t.TemplateError=A,t.TemplateNotFound=$,t.TemplateSyntaxError=L,t.__express=Q,t.compile=X,t.configure=G,t.create=I,t.createContext=V,t.helpers=Y,t.preload=z,t.render=K}));
|
|
1
|
+
!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).ejsInstance={})}(this,(function(t){"use strict";const e="ejsPrecompiled",s=!0,i="views",r="ejs",o=!0,n=!0,c=(t,e)=>Promise.resolve(["resolver is not defined",t,e].join(" ")),h=[],a={SCOPE:"ejs",COMPONENT:"ui",ELEMENT:"el",EXTEND:"$$e",BUFFER:"$$a",LAYOUT:"$$l",BLOCKS:"$$b",MACRO:"$$m",SAFE:"$$v"},l={start:"<%",end:"%>",regex:"([\\s\\S]+?)"},u=/^[a-zA-Z_$][0-9a-zA-Z_$]*$/,p=function(){const t=[].slice.call(arguments),e=t.shift();return t.filter(e).pop()},f=t=>Array.isArray(t),g=t=>"function"==typeof t,m=t=>"string"==typeof t,d=t=>"boolean"==typeof t,v=(t,v)=>{return Object.assign(t,{path:p(m,i,t.path,v.path),precompiled:p(m,e,t.export,v.export),resolver:p(g,c,t.resolver,v.resolver),extension:p(m,r,t.extension,v.extension),strict:p(d,n,t.strict,v.strict),rmWhitespace:p(d,o,t.rmWhitespace,v.rmWhitespace),cache:p(d,s,t.cache,v.cache),globals:p(f,h,t.globals,(b=v.globals,!!f(b)&&b.filter((t=>{const e=u.test(t);return!1===e&&console.log(`ejsConfig.globals: expected '${t}' to be valid variable name --\x3e skipped`),e})))),token:Object.assign({},l,t.token,v.token),vars:Object.assign({},a,t.vars,v.vars)});var b},b={"'":"'","\\":"\\","\r":"r","\n":"n","\t":"t","\u2028":"u2028","\u2029":"u2029"},x={"&":"&","<":"<",">":">",'"':""","'":"'"},y=t=>new RegExp(["[",Object.keys(t).join(""),"]"].join(""),"g"),j=y(x),E=y(b),$=function(){return(""+(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"")).replace(j,(t=>x[t]))},O=(t,e)=>{const s=t;return null==s?"":!0===Boolean(e)?$(s):s},w=(t,e,s)=>{let i=t,r=String(e).split("."),o=r.pop();for(let t=0;t<r.length;t++){const e=r[t];if(g(i.toJSON)&&(i=i.toJSON()),s&&!1===i.hasOwnProperty(e)){i={};break}i=i[e]=i[e]||{}}return g(i.toJSON)&&(i=i.toJSON()),[i,o]},P=(t,e)=>{let s;for(s in t)S(t,s)&&e(t[s],s,t)},k=(t,e)=>{const s={...t};for(const t of e)delete s[t];return s},S=(t,e)=>t&&Object.hasOwn(t,e),C=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for(let s=0,i=e.length;s<i;s++){const i=e[s];i in t&&(t[i]=t[i].bind(t))}};class T{#t;#e;#s;#i;static exports=["configure","get","compile"];constructor(t,e,s){C(this,this.constructor.exports),this.#s=e,this.#i=s,this.configure(t??{})}configure(t){this.#t=t.path,g(t.resolver)&&(this.#e=t.resolver)}#r(t){const e=this.#s.get(t);if(e instanceof Promise)return e;const s=Promise.resolve(this.#e(this.#t,t));return this.#s.set(t,s),s}compile(t,e){const s=this.#s.get(e);return"function"==typeof s?s:("string"==typeof t&&(t=this.#i.compile(t,e)),"function"==typeof t?(this.#s.set(e,t),t):void 0)}get(t){return this.#r(t).then((e=>this.compile(e,t)))}}const N=[["-",(t,e,s)=>`')\n${e}(${s}(${t},1))\n${e}('`],["=",(t,e,s)=>`')\n${e}(${s}(${t}))\n${e}('`],["#",(t,e)=>`')\n/**${t}**/\n${e}('`],["",(t,e)=>`')\n${t}\n${e}('`]];class B{#o={};static exports=["compile"];constructor(t){C(this,this.constructor.exports),this.configure(t)}configure(t){this.#o.strict=t.strict,this.#o.rmWhitespace=t.rmWhitespace,this.#o.token=t.token,this.#o.vars=t.vars,this.#o.globals=t.globals,this.#o.legacy=t.legacy??!0,this.#o.slurp={match:"[s\t\n]*",start:[this.#o.token.start,"_"],end:["_",this.#o.token.end]},this.#o.matches=[],this.#o.formats=[];for(const[t,e]of N)this.#o.matches.push(this.#o.token.start.concat(t).concat(this.#o.token.regex).concat(this.#o.token.end)),this.#o.formats.push(e);this.#o.regex=new RegExp(this.#o.matches.join("|").concat("|$"),"g"),this.#o.slurpStart=new RegExp([this.#o.slurp.match,this.#o.slurp.start.join("")].join(""),"gm"),this.#o.slurpEnd=new RegExp([this.#o.slurp.end.join(""),this.#o.slurp.match].join(""),"gm"),this.#o.globals.length&&(this.#o.legacy?this.#o.globalVariables=`const ${this.#o.globals.map((t=>`${t}=${this.#o.vars.SCOPE}.${t}`)).join(",")};`:this.#o.globalVariables=`const {${this.#o.globals.join(",")}} = ${this.#o.vars.SCOPE};`)}compile(t,e){const s=this.#o.globalVariables,{SCOPE:i,SAFE:r,BUFFER:o,COMPONENT:n,ELEMENT:c}=this.#o.vars;this.#o.rmWhitespace&&(t=String(t).replace(/[\r\n]+/g,"\n").replace(/^\s+|\s+$/gm,"")),t=String(t).replace(this.#o.slurpStart,this.#o.token.start).replace(this.#o.slurpEnd,this.#o.token.end);let h=`${o}('`;((t,e,s)=>{let i=0;e.replace(t,(function(){const t=[].slice.call(arguments,0,-1),e=t.pop(),r=t.shift();return s(t,i,e),i=e+r.length,r}))})(this.#o.regex,t,((e,s,i)=>{h+=(""+t.slice(s,i)).replace(E,(t=>"\\"+b[t])),e.forEach(((t,e)=>{t&&(h+=this.#o.formats[e](t.trim(),o,r))}))})),h+="');",h=`try{${h}}catch(e){return ${o}.error(e,'${e}')}`,!1===this.#o.strict&&(h=`with(${i}){${h}}`),h=`${o}.start();${h}return ${o}.end();`,h+=`\n//# sourceURL=${e}`,s&&(h=`${s}\n${h}`);try{const t=[i,n,c,o,r],e=Function.apply(null,t.concat(h));return e.source=`(function(${t.join(",")}){\n${h}\n});`,e}catch(t){throw t.filename=e,t.source=h,t}}}class L{static exports=["load","set","get","exist","clear","remove","resolve"];#s=!0;#n;#c={};constructor(t){C(this,this.constructor.exports),this.configure(t)}get(t){if(this.#s)return this.#c[t]}set(t,e){this.#s&&(this.#c[t]=e)}exist(t){if(this.#s)return this.#c.hasOwnProperty(t)}clear(){Object.keys(this.#c).forEach(this.remove)}remove(t){delete this.#c[t]}resolve(t){return Promise.resolve(this.get(t))}load(t){this.#s&&Object.assign(this.#c,t||{})}configure(t){this.#s=t.cache,this.#n=t.precompiled,"object"==typeof window&&this.load(window[this.#n])}}const A=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],F=" ",M='"',R="/",q="<",U=">",W=t=>{let[e,s]=t;if(null!=s)return[$(e),[M,$(s),M].join("")].join("=")};class _ extends Error{name="TemplateError";constructor(t){super(t),t instanceof Error&&(this.stack=t.stack,this.filename=t.filename,this.lineno=t.lineno)}}class V extends _{name="TemplateSyntaxError";code=500}const J=t=>Promise.all(t||[]).then((t=>t.join(""))).catch((t=>t)),z=()=>{let t=[],e=[];const s=t=>{e.push(t)};return s.start=()=>{e=[]},s.backup=()=>{t.push(e.concat()),e=[]},s.restore=()=>{const s=e.concat();return e=t.pop(),J(s)},s.error=(t,e)=>{return s=t,Promise.reject(new V(s));var s},s.end=()=>J(e),s},D=Symbol("EjsContext.parentTemplate"),K=(t,e)=>{const{BLOCKS:s,MACRO:i,EXTEND:r,LAYOUT:o,BUFFER:n,SAFE:c,SCOPE:h,COMPONENT:a,ELEMENT:l}=t.vars,u=t.globals||[];function p(t){this[D]=null,this[s]={},this[i]={},Object.assign(this,k(t,[h,n,c,a,l]))}return Object.entries(e).forEach((t=>{let[e,s]=t;g(s)&&u.includes(e)&&(s=s.bind(p.prototype)),p.prototype[e]=s})),Object.defineProperty(p.prototype,n,{value:z()}),Object.defineProperty(p.prototype,s,{value:{},writable:!0}),Object.defineProperty(p.prototype,i,{value:{},writable:!0}),Object.defineProperty(p.prototype,o,{value:!1,writable:!0}),Object.defineProperty(p.prototype,r,{value:!1,writable:!0}),Object.defineProperty(p.prototype,D,{value:null,writable:!0}),Object.defineProperties(p.prototype,{setParentTemplate:{value(t){return this[D]=t,this}},getParentTemplate:{value(){return this[D]}},useSafeValue:{get:()=>O},useComponent:{get(){return g(this[a])?this[a].bind(this):()=>{throw new Error(`${a} must be a function`)}}},useElement:{get(){return g(this[l])?this[l].bind(this):()=>{throw new Error(`${l} must be a function`)}}},useBuffer:{get(){return this[n]}},getMacro:{value(){return this[i]}},getBlocks:{value(){return this[s]}},setExtend:{value(t){return this[r]=t,this}},getExtend:{value(){return this[r]}},setLayout:{value(t){return this[o]=t,this}},getLayout:{value(){return this[o]}},clone:{value(t){const e=[o,r,n];return!0===t&&e.push(s),k(this,e)}},extend:{value(t){this.setExtend(!0),this.setLayout(t)}},echo:{value(){return[].slice.call(arguments).forEach(this.useBuffer)}},fn:{value(t){return()=>{if(g(t))return this.useBuffer.backup(),this.useBuffer(t.apply(this,arguments)),this.useBuffer.restore()}}},macro:{value(t,e){const s=this.getMacro(),i=this.fn(e),r=this;s[t]=function(){return r.echo(i.apply(void 0,arguments))}}},call:{value(t){const e=this.getMacro()[t],s=[].slice.call(arguments,1);if(g(e))return e.apply(e,s)}},block:{value(t,e){const s=this.getBlocks();if(s[t]=s[t]||[],s[t].push(this.fn(e)),this.getExtend())return;const i=Object.assign([],s[t]),r=()=>i.shift(),o=()=>{const t=r();return t?()=>{this.echo(t(o()))}:()=>{}};this.echo(r()(o()))}},hasBlock:{value(t){return this.getBlocks().hasOwnProperty(t)}},include:{value(t,e,s){const i=!1===s?{}:this.clone(!0),r=Object.assign(i,e||{}),o=this.render(t,r);this.echo(o)}},use:{value(t,e){this.echo(Promise.resolve(this.require(t)).then((t=>{const s=this.getMacro();P(t,((t,i)=>{s[[e,i].join(".")]=t}))})))}},async:{value(t,e){this.echo(Promise.resolve(t).then(e))}},get:{value(t,e){const s=w(this,t,!0),i=s.shift(),r=s.pop();return S(i,r)?i[r]:e}},set:{value(t,e){const s=w(this,t,!1),i=s.shift(),r=s.pop();return this.getParentTemplate()&&S(i,r)?i[r]:i[r]=e}},each:{value(t,e){m(t)&&(t=this.get(t,[])),P(t,e)},writable:!0},el:{value(t,e,s){s=g(s)?this.fn(s)():s,this.echo(Promise.resolve(s).then((s=>((t,e,s)=>{const i=[],r=-1===A.indexOf(t),o=Object.entries(e??{}).map(W).filter((t=>t)).join(F);return i.push([q,t,F,o,U].join("")),s&&r&&i.push(Array.isArray(s)?s.join(""):s),r&&i.push([q,R,t,U].join("")),i.join("")})(t,e,s))))},writable:!0},ui:{value(t){},writable:!0}}),p};class X{#h;static exports=["create","globals","helpers"];constructor(t,e){C(this,this.constructor.exports),this.configure(t,e)}create(t){return new this.#h(t)}helpers(t){Object.assign(this.#h.prototype,t)}configure(t,e){this.#h=K(t,e)}}var Y={};const{render:Z,createContext:I,compile:G,helpers:H,preload:Q,configure:tt,create:et}=new class{#s;#h;#i;#a;#o={};#l={};static exports=["configure","create","createContext","render","require","preload","compile","helpers"];constructor(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};C(this,this.constructor.exports),this.#l={},this.#o=v({},t),this.#h=new X(this.#o,this.#l),this.#i=new B(this.#o),this.#s=new L(this.#o),this.#a=new T(this.#o,this.#s,this.#i),this.helpers({render:this.render,require:this.require})}create(t){return new this.constructor(t)}configure(t){return t&&(v(this.#o,t),this.#h.configure(this.#o,this.#l),this.#i.configure(this.#o),this.#s.configure(this.#o),this.#a.configure(this.#o)),this.#o}createContext(t){return this.#h.create(t)}preload(t){return this.#s.load(t||{})}compile(t,e){return this.#i.compile(t,e)}helpers(t){this.#h.helpers(Object.assign(this.#l,t))}async render(t,e){const s=this.createContext(e);return this.#u(this.#t(t),s).then(this.#p(t,s))}async require(t){const e=this.createContext({});return this.#u(this.#t(t),e).then((()=>e.getMacro()))}#t(t){return t.split(".").pop()!==this.#o.extension&&(t=[t,this.#o.extension].join(".")),t}#u(t,e){return this.#a.get(t).then((t=>t.apply(e,[e,e.useComponent,e.useElement,e.useBuffer,e.useSafeValue])))}#f(t,e,s){const i=this.createContext(e);return s&&i.setParentTemplate(s),this.#u(this.#t(t),i).then(this.#p(t,i))}#p(t,e){return s=>e.getExtend()?(e.setExtend(!1),this.#f(e.getLayout(),e,t)):s}}({resolver:(t,e)=>Y.readFile(((t,e)=>(e=[t,e].join("/")).replace(/\/\//g,"/"))(t,e)).then((t=>t.toString())).then((t=>String(t)))}),st=((t,e)=>function(r,o,n){g(o)&&(n=o,o={}),o=o||{};const c=Object.assign({},o.settings),h=p(m,i,c.views),a=p(d,s,c["view cache"]),l=Object.assign({},c["view options"]),u=Y.relative(h,r);return l.path=h,l.cache=a,t(l),e(u,o).then((t=>{n(null,t)})).catch((t=>{n(t)}))})(tt,Z);t.TemplateError=_,t.TemplateNotFound=class extends _{name="TemplateNotFound";code=404},t.TemplateSyntaxError=V,t.__express=st,t.compile=G,t.configure=tt,t.create=et,t.createContext=I,t.helpers=H,t.preload=Q,t.render=Z}));
|