mutorjs 1.3.4 → 1.5.0

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/dist/server.d.ts CHANGED
@@ -8,6 +8,12 @@ interface MutorConfig {
8
8
  forbiddenProps: Set<string>;
9
9
  allowFnCalls: boolean;
10
10
  autoEscape: boolean;
11
+ onIncludeFail: "throw" | "ignore" | "ignoreLog";
12
+ onIncludeError?: (meta: {
13
+ from: string;
14
+ path: string;
15
+ absolutePath?: string;
16
+ }, err: any) => void;
11
17
  build: {
12
18
  include: Set<string>;
13
19
  exclude: Set<string>;
@@ -28,26 +34,33 @@ type PartialMutorConfig = Partial<Omit<MutorConfig, "delimiters">> & {
28
34
  exclude?: Set<string>;
29
35
  };
30
36
  };
37
+ /**
38
+ * RuntimeFrame encapsulates all execution-local state for a single render operation.
39
+ * This allows async operations to work correctly by avoiding shared mutable state.
40
+ */
41
+ interface RuntimeFrame {
42
+ context: any;
43
+ renderedPath: string;
44
+ includeStack: Set<string>;
45
+ }
31
46
 
32
- declare class Mutor$1 {
33
- protected __currentRenderedPath: string;
34
- protected __includeStack: Set<string>;
47
+ declare class MutorBase {
35
48
  protected __cacheSize: number;
36
49
  protected __config: MutorConfig;
37
50
  protected __compiledTemplatesMap: Map<string, {
38
51
  fn: Function;
39
52
  size: number;
40
53
  }>;
41
- protected __currentContext: any;
42
54
  protected __namespaces: Record<any, any>;
43
55
  constructor(config?: PartialMutorConfig);
44
56
  addConfig(conf: PartialMutorConfig): MutorConfig;
45
57
  restoreDefaultConfig(): void;
46
- compile(template: string): Function;
58
+ compile(template: string, runtime?: RuntimeFrame): Function;
59
+ renderAsync(template: string, context: any): Promise<string>;
47
60
  render(template: string, context: any): string;
48
- renderComponent(identifier: string, context: any): string;
49
- registerComponent(identifier: string, template: string): void;
50
- reset(): void;
61
+ protected __renderWithRuntime(template: string, runtime: RuntimeFrame): string;
62
+ protected __createNamespacesWithRuntime(runtime: RuntimeFrame): Record<any, any>;
63
+ protected handleError(err: unknown, from: string, path: string, absolutePath?: string): string;
51
64
  protected createEntrySpaceForTemplate(targetSize: number): boolean;
52
65
  getDiagnostics(): {
53
66
  bytesUsed: number;
@@ -58,13 +71,23 @@ declare class Mutor$1 {
58
71
  percentFull: number;
59
72
  avgTemplateSize: number;
60
73
  };
74
+ protected register(identifier: string, template: string): void;
75
+ reset(): void;
61
76
  }
62
77
 
63
- declare class Mutor extends Mutor$1 {
78
+ declare class MutorServer extends MutorBase {
64
79
  constructor(config?: PartialMutorConfig);
80
+ /**
81
+ * Set up the include namespace with the given runtime.
82
+ * This must be done before rendering to ensure includes have access to the runtime.
83
+ */
84
+ private __setupIncludeForRuntime;
85
+ render(template: string, context: any): string;
86
+ renderAsync(template: string, context: any): Promise<string>;
87
+ private __renderFile;
65
88
  renderFile(path: string, context: any): string;
66
89
  buildDir(src: string, destination: string, context: any): Promise<void>;
67
90
  compileDir(src: string): Promise<void>;
68
91
  }
69
92
 
70
- export { Mutor as default };
93
+ export { MutorServer as default };
package/dist/server.js CHANGED
@@ -1,17 +1,17 @@
1
- import{readFileSync as be}from"fs";import{copyFile as Re,mkdir as Pe,readdir as de,readFile as xe,writeFile as Se}from"fs/promises";import{extname as me,join as ee}from"path";function Z(e,r){return`${" ".repeat(e+r)}^`}var m=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},M=class e extends m{constructor(t,a,o,c,f){let g=a.toString().length+2,s=`${t}
1
+ import{readFileSync as Se}from"fs";import{copyFile as Te,mkdir as Ie,readdir as Ee,readFile as Ce,writeFile as Fe}from"fs/promises";import{extname as we,join as te}from"path";function F(e,r=""){return{context:e,renderedPath:r,includeStack:new Set([r&&r])}}function Z(e,r){return`${" ".repeat(e+r)}^`}var g=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},T=class e extends g{constructor(t,s,o,c,l){let h=s.toString().length+2,a=`${t}
2
2
 
3
- `;s+=`at ${f}:${a}:${c+1}
4
- `,a>1&&(s+=`${(a-1).toString().padStart(g-2)} | ...
5
- `),s+=`${a} | ${o}
6
- `,s+=Z(c,g+1);super(s);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ne=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),B=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var oe=new Set(["==","!="]),V=new Set([">","<",">=","<="]);var se=new Set(["+","-"]),ie=new Set(["*","/","%"]),ae=new Set([".","?.","[","::"]),ce=new Set(["-","+","!"]),pe={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},x={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,cache:{active:!0,maxSize:50*1024*1024}},le={JSON:{stringify(e){try{return JSON.stringify(e)}catch{throw new m("JSON.stringify failed: invalid value")}},parse(e){if(typeof e!="string")throw new m("JSON.parse expects a string");try{return JSON.parse(e)}catch{throw new m("JSON.parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new m("Object.keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new m("Object.values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new m("Object.entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new m("Object.hasOwn expects an object");return Object.hasOwn(e,r)},freeze(e){if(!e||typeof e!="object")throw new m("Object.freeze expects an object");return Object.freeze(e)},seal(e){if(!e||typeof e!="object")throw new m("Object.seal expects an object");return Object.seal(e)},fromEntries(e){if(!Array.isArray(e))throw new m("Object.fromEntries expects an array");return Object.fromEntries(e)}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)}},String:{fromCharCode(...e){return String.fromCharCode(...e)}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new m("Date.parse expects a string");return Date.parse(e)}},Boolean:{valueOf(e){return!!e}}};function F(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>pe[r]):e}import{dirname as ye,isAbsolute as Ee,resolve as ue}from"path";function T(e,...r){let t=Ee(e)?e:ue(process.cwd(),e);if(r.length){let a=ye(t);return ue(a,...r)}return t}function D(e,r,t){if(t.has(e)&&!r.has(e))throw new m(`Forbidden property access. Access to this computed property "${e}" is forbidden.`);return e}var L="object",fe=Symbol("__mutor_safe_context");function j(e){if(!e||typeof e!==L||fe in e)return e;let r=new WeakSet;function t(o,c=""){if(!o||typeof o!==L||r.has(o))return o;r.add(o);let f=Object.getPrototypeOf(o);if(f&&f!==Object.prototype&&f!==Array.prototype)throw new m(`Unsafe prototype detected at ${c||"root"}`);if(Array.isArray(o)){for(let s=0;s<o.length;s++)o[s]=t(o[s],`${c}[${s}]`);return o}if(o instanceof Map){for(let[s,p]of o.entries())typeof s===L&&t(s,`${c}.mapKey`),o.set(s,t(p,`${c}.mapValue`));return o}if(o instanceof Set){let s=new Set;for(let p of o.values())s.add(t(p,c));o.clear();for(let p of s)o.add(p);return o}let g=Object.getOwnPropertyDescriptors(o);for(let s of Object.keys(g)){let p=g[s];if(p.get||p.set)throw new m(`Getter/setter not allowed: ${c}.${s}`);let d=o[s];d&&typeof d===L&&(o[s]=t(d,`${c}.${s}`))}return o}let a=t(e);return a&&typeof a===L&&Object.defineProperty(a,fe,{value:!0,enumerable:!1,writable:!1,configurable:!1}),a}function $(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function U(e,r){let a=e.slice(0,r).split(`
3
+ `;a+=`at ${l}:${s}:${c+1}
4
+ `,s>1&&(a+=`${(s-1).toString().padStart(h-2)} | ...
5
+ `),a+=`${s} | ${o}
6
+ `,a+=Z(c,h+1);super(a);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var se=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),L=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var ie=new Set(["==","!="]),X=new Set([">","<",">=","<="]);var ae=new Set(["+","-"]),ce=new Set(["*","/","%"]),pe=new Set([".","?.","[","::"]),le=new Set(["-","+","!"]),ue={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},N={build:{include:new Set([".html",".txt"]),exclude:new Set(["node_modules",".git"])},autoEscape:!0,allowedProps:new Set,forbiddenProps:new Set(["__proto__","constructor","prototype"]),allowFnCalls:!1,delimiters:{closingTag:"}}",openingTag:"{{",openingTagEscape:"\\",whitespaceTrim:"~",commentTag:"#"},keepOpeningTagEscapeDelimiter:!1,onIncludeFail:"throw",cache:{active:!0,maxSize:50*1024*1024}},fe={JSON:{stringify(e){try{return JSON.stringify(e)}catch{throw new g("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new g("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new g("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new g("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new g("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new g("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new g("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new g("Object::fromEntries expects an array");return Object.fromEntries(e)}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)}},String:{fromCharCode(...e){return String.fromCharCode(...e)}},Math:{abs(e){return Math.abs(e)},floor(e){return Math.floor(e)},ceil(e){return Math.ceil(e)},round(e){return Math.round(e)},max(...e){return Math.max(...e)},min(...e){return Math.min(...e)},random(){return Math.random()}},Date:{now(){return Date.now()},parse(e){if(typeof e!="string")throw new g("Date::parse expects a string");return Date.parse(e)}},Boolean:{valueOf(e){return!!e}}},me=/('|"|`)use\s+async\1/,de=(async()=>{}).constructor;function z(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>ue[r]):e}import{dirname as Pe,isAbsolute as Ne,resolve as he}from"path";function $(e,...r){let t=Ne(e)?e:he(process.cwd(),e);if(r.length){let s=Pe(t);return he(s,...r)}return t}function B(e,r,t){if(t.has(e)&&!r.has(e))throw new g(`Forbidden property access.
7
+ Access to this computed property '${e}' is forbidden.`);return e}var U="object",ge=Symbol("__mutor_safe_context");function j(e){if(!e||typeof e!==U||ge in e)return e;let r=new WeakSet;function t(o,c=""){if(!o||typeof o!==U||r.has(o))return o;r.add(o);let l=Object.getPrototypeOf(o);if(l&&l!==Object.prototype&&l!==Array.prototype)throw new g(`Unsafe prototype detected at ${c||"root"} in context.`);if(Array.isArray(o)){for(let a=0;a<o.length;a++)o[a]=t(o[a],`${c}[${a}]`);return o}if(o instanceof Map){for(let[a,u]of o.entries())typeof a===U&&t(a,`${c}.mapKey`),o.set(a,t(u,`${c}.mapValue`));return o}if(o instanceof Set){let a=new Set;for(let u of o.values())a.add(t(u,c));o.clear();for(let u of a)o.add(u);return o}let h=Object.getOwnPropertyDescriptors(o);for(let a of Object.keys(h)){let u=h[a];if(u.get||u.set)throw new g(`Getter/setter not allowed at '${c}.${a}' in context.`);let m=o[a];m&&typeof m===U&&(o[a]=t(m,`${c}.${a}`))}return o}let s=t(e);return s&&typeof s===U&&Object.defineProperty(s,ge,{value:!0,enumerable:!1,writable:!1,configurable:!1}),s}function v(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function W(e,r){let s=e.slice(0,r).split(`
7
8
  `).length,o=e.lastIndexOf(`
8
- `,r-1)+1;return[a,o]}function W(e,r){let t=e.indexOf(`
9
- `,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function z(e,r){let{scope:t,forbiddenProps:a,allowedProps:o}=r;function c(i){return t.includes(i)?i:`ctx.${i}`}function f(i){switch(i.type){case 17:return"}";case 5:return i.value;case 4:return`\`${/\$\\/.test(i.value)?$(i.value):i.value}\``;case 10:return i.true?"true":"false";case 12:return"null";case 11:return"undefined";case 7:return c(i.value);case 9:return`(${f(i.expr)})`;case 2:return`${i.operator}${f(i.expr)}`;case 0:return`${f(i.left)} ${i.operator} ${f(i.right)}`;case 1:return`${f(i.condition)} ? ${f(i.left)} : ${f(i.right)}`;case 8:return s(i);case 3:return p(i);case 6:return g(i);case 13:return d(i);case 16:return"} else {";case 14:return _(i);case 15:return y(i);default:throw new m(`Unsupported expression type: ${i.type}`)}}function g(i){if(i.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:i.pos};return`namespaces.${i.left.value}.${i.right.value}`}function s(i){let O=f(i.left);if(i.bracketNotation){let h=f(i.right),w=i.optional?"?.":"";return i.right.type===4||i.right.type===5?`${O}${w}[${h}]`:`${O}${w}[validateComputedProps(${h}, allowedProps, forbiddenProps)]`}else{let h=i.right.value,w=i.optional?"?.":".";if(a.has(h)&&!o.has(h))throw{message:"Forbidden property access.",pos:i.right.pos};return`${O}${w}${h}`}}function p(i){let O=f(i.expr),h=i.optional?"?.":"",w=i.args.map(R=>f(R)).join(", ");return`${O}${h}(${w})`}function d(i){let{iterable:O,loopType:h,variable:w}=i;return`for(const ${w} ${h===1?"in":"of"} ${z(O,r)}){`}function _(i){let{condition:O}=i;return`if(${z(O,r)}){`}function y(i){let{condition:O}=i;return`}else if(${z(O,r)}){`}return f(e)}function Y(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function H(e,r){let t=0,a=!1;function o(n,l){let u=e[t],S=e[e.length-1];if(!u)throw{message:`Unexpected end of expression. Expected ${l?`'${l}'`:`${n===0?"an":"a"} ${Y(n)}`}.`,pos:S.pos+S.value.length-1};if(u.type!==n)throw{message:`Unexpected token type. Expected ${l?`'${l}'`:Y(n)} but got ${Y(u.type)} instead.`,pos:u.pos};if(l!==void 0&&u.value!==l)throw{message:`Unexpected token '${u?.value}'. Expected ${n===0?"an":"a"} ${Y(n)} instead.`,pos:u.pos};return e[t++]}function c(){let n=e[t-1].pos,l=o(0).value,u;try{u=o(1,"in")}catch{u=o(1,"of")}let S=u.value==="in"?1:0,I=b();return{type:13,loopType:S,iterable:I,variable:l,pos:n}}function f(){let n=b();return{condition:n,pos:n.pos,type:14}}function g(){let n=e[t-1].pos;try{return o(1,"if"),{...f(),type:15,pos:n}}catch{return{type:16,pos:n}}}function s(){let n=[];if(e[t]?.type===4&&e[t]?.value===")")return n;for(n.push(b());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,n.push(b());return n}function p(){let n=e[t++];if(n?.type===2)return{type:5,value:n.value,pos:n.pos};if(n?.type===3)return{type:4,value:n.value,pos:n.pos};if(n?.type===1){if(n.value==="for"&&t===1)return c();if(n.value==="true"||n.value==="false")return{type:10,true:n.value==="true",pos:n.pos};if(n.value==="undefined")return{type:11,pos:n.pos};if(n.value==="null")return{type:12,pos:n.pos};if(n.value==="end"&&e.length===1)return{type:17,pos:n.pos};if(n.value==="if"&&t===1)return f();if(n.value==="else"&&t===1)return g()}if(n?.type===0)return{type:7,value:n.value,pos:n.pos};if(n?.type===4&&n.value==="("){let l=b();return o(4,")"),{type:9,expr:l,pos:n.pos}}if(n?.type===4&&ce.has(n.value)){let l=n.value,u=b();return{type:2,operator:l,expr:u,pos:n.pos}}throw t>e.length?{message:"Unexpected end of expression.",pos:e[e.length-1].pos}:{message:`Unexpected token '${n?.value}'.`,pos:n.pos}}function d(){let n=p();for(;e[t];){let l=e[t];if(l?.type===4&&l?.value==="("){if(t++,!a&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let u=s();o(4,")"),n={type:3,expr:n,args:u,pos:e[t-1].pos}}else if(l?.type===4&&l?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!a&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let u=s();o(4,")"),n={type:3,expr:n,args:u,optional:!0,pos:e[t-1].pos}}else if(l?.type===4&&ae.has(l?.value)){let u=l?.value==="::",S=l?.value==="[",I=l?.value==="?.";if(t++,u&&(e[t-2]?.type!==0||e[t]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e[t-2]?.value}::${e[t]?.value}' instead.`,pos:e[t]?.pos};if(u){a=!0;let P=p();n={type:6,left:n,right:P,pos:e[t-1].pos}}else if(S){let P=b();o(4,"]"),n={type:8,right:P,left:n,bracketNotation:!0,pos:e[t-1].pos}}else if(I)if(e[t]?.type===4&&e[t]?.value==="["){t++;let P=b();o(4,"]"),n={type:8,left:n,right:P,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let P=p();n={type:8,left:n,right:P,optional:!0,pos:e[t-1].pos}}else{let P=p();n={type:8,left:n,right:P,pos:e[t-1].pos}}}else break}return a=!1,n}function _(){let n=d();for(;e[t]?.type===4&&ie.has(e[t]?.value);){let l=e[t++].value,u=d();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function y(){let n=_();for(;e[t]?.type===4&&se.has(e[t]?.value);){let l=e[t++].value,u=_();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function i(){let n=y();for(;e[t]?.type===4&&V.has(e[t]?.value);){let l=e[t++].value,u=y();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function O(){let n=i();for(;e[t]?.type===4&&V.has(e[t]?.value);){let l=e[t++].value,u=i();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function h(){let n=O();for(;e[t]?.type===4&&oe.has(e[t]?.value);){let l=e[t++].value,u=O();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function w(){let n=R();for(;e[t]?.type===4&&e[t]?.value==="||";){let l=e[t++].value,u=R();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function R(){let n=v();for(;e[t]?.type===4&&e[t]?.value==="&&";){let l=e[t++].value,u=v();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function v(){let n=h();for(;e[t]?.type===4&&e[t]?.value==="??";){let l=e[t++].value,u=h();n={type:0,left:n,right:u,operator:l,pos:e[t-1].pos}}return n}function b(){let n=w();if(e[t]?.type!==4||e[t]?.value!=="?")return n;t++;let l=b();o(4,":");let u=b();return{type:1,left:l,right:u,condition:n,pos:e[t-1].pos}}let J=b();if(t!==e.length)throw{pos:e[t].pos,message:`Unexpected end of expression.
10
- Expected end of expression but found "${e[t].value}".`};return J}function Q(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,a=`${r.whitespaceTrim}${r.closingTag}`,o=e.startsWith(t),c=e.endsWith(a),f=e.startsWith(o?t+r.commentTag:r.openingTag+r.commentTag);if(f)return{isComment:f,leftTrim:o,rightTrim:c};let g=e.slice(o?t.length:r.openingTag.length,e.length-(c?a.length:r.closingTag.length)),s=g.trim(),p=s.startsWith("for")||s.startsWith("if")||s.startsWith("else"),d=s.startsWith("for")||s.startsWith("if"),_=s==="end",y=s.startsWith("for");return{leftTrim:o,rightTrim:c,inner:g,isBlock:p,isBlockEnd:_,hasContext:y,requiresBlockClose:d}}function X(e){let r=0,t="",a=[];function o(){let s="";if(/[a-zA-Z$_]/.test(t)){let p=r;for(;/[a-zA-Z$_0-9]/.test(e[p])&&p<e.length;)s+=e[p],p++;a.push({type:ne.has(s)?1:0,value:s,pos:r}),r=p,t=e[r]}}function c(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let s=t,p=r,d=r+1,_="";for(;d<e.length;){let y=e[d];if(y==="\\"){if(d+1>=e.length)throw{pos:d,message:"Unexpected end of string after escape character."};_+=y,_+=e[d+1],d+=2;continue}if(y===s)break;_+=y,d++}if(d>=e.length||e[d]!==s)throw{pos:p,message:`String literal missing closing ${s}.`};a.push({type:3,value:_,pos:p}),r=d}function f(){if(/[0-9]/.test(t)){let s=r,p="";for(;/[0-9.oxe]/.test(e[s])&&s<e.length;)p+=e[s],s++;let d=Number(p);if(Number.isNaN(d))throw{pos:r,message:"Found invalid number literal."};a.push({type:2,value:`${d}`,pos:r}),r=s-1,t=e[r]}}function g(){let s=`${t}${e[r+1]}`;if(B.has(s)){a.push({type:4,value:s,pos:r}),r++;return}if(B.has(t)){a.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],f(),o(),c(),g(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!B.has(t)&&!B.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return a}function k(e,r,t){let a=[],o=[],{delimiters:c,keepOpeningTagEscapeDelimiter:f,allowFnCalls:g,allowedProps:s,forbiddenProps:p,autoEscape:d}=r,_=!1,y=0,i='let acc="";';for(;y<e.length;){let w=function(){let E=h,N=0;for(;E>=c.openingTagEscape.length&&e.slice(E-c.openingTagEscape.length,E)===c.openingTagEscape;)N++,E-=c.openingTagEscape.length;return N%2===1};var O=w;let h=e.indexOf(c.openingTag,y);if(h===-1){let E=e.slice(y);_&&(E=E.trimStart()),E&&(i+=`acc+=\`${$(E)}\`;`);break}if(w()){let E=e.slice(y,f?h+c.openingTagEscape.length+1:h-c.openingTag.length+1);_&&(E=E.trimStart(),_=!1),i+=`acc+=\`${$(E)}\`;`,f||(i+=`acc+=\`${c.openingTag}\`;`),y=h+c.openingTag.length;continue}let R=e.indexOf(c.closingTag,h);if(R===-1){let[E,N]=U(e,h),C=W(e,N);throw new M("No closing tag found.",E,C,h,t.path)}let v=e.slice(h,R+c.closingTag.length),{inner:b,leftTrim:J,rightTrim:n,isBlock:l,isBlockEnd:u,hasContext:S,requiresBlockClose:I,isComment:P}=Q(v,{delimiters:c}),A=e.slice(y,h);A&&(_&&(A=A.trimStart()),J&&(A=A.trimEnd()),A&&(i+=`acc+=\`${$(A)}\`;`)),_=!1,y=R+c.closingTag.length;try{if(!P){let E=X(b),N=H(E,{allowFnCalls:g});if(l&&I&&S?(a.push(N.variable),o.push({type:0,pos:h})):l&&I&&!S&&o.push({type:1,pos:h}),u){let q=o.pop();if(q?.type===0&&a.pop(),q===void 0)throw{message:"Unexpected end of block",pos:h}}let C=z(N,{allowedProps:s,forbiddenProps:p,scope:a});l||u?i+=C:i+=d&&!C.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${C});`:`acc+=${C};`}n&&(_=!0)}catch(E){let{message:N,pos:C}=E,q=J?c.whitespaceTrim.length+c.openingTag.length:c.openingTag.length,te=h+C+q,[ge,re]=U(e,te),_e=W(e,re);throw new M(N,ge,_e,te-re,t.path)}}if(o.length){let h=o.pop()?.pos,[w,R]=U(e,h),v=W(e,R);throw new M("Unclosed block detected.",w,v,h-R,t.path)}return i+="return acc;",new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i)}var G=class{constructor(r={}){this.__currentRenderedPath="";this.__includeStack=new Set;this.__cacheSize=0;this.__config={...x};this.__compiledTemplatesMap=new Map;this.__currentContext=null;this.__namespaces={...le,Mutor:{include:(r,t)=>{if(this.__includeStack.has(r))throw new m(`Circular include detected:
11
- ${Array.from(this.__includeStack).join(`
9
+ `,r-1)+1;return[s,o]}function Y(e,r){let t=e.indexOf(`
10
+ `,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function D(e,r){let{scope:t,forbiddenProps:s,allowedProps:o}=r;function c(i){return t.includes(i)?i:`ctx.${i}`}function l(i){switch(i.type){case 17:return"}";case 5:return i.value;case 4:return`\`${/\$\\/.test(i.value)?v(i.value):i.value}\``;case 10:return i.true?"true":"false";case 12:return"null";case 11:return"undefined";case 7:return c(i.value);case 9:return`(${l(i.expr)})`;case 2:return`${i.operator}${l(i.expr)}`;case 0:return`${l(i.left)} ${i.operator} ${l(i.right)}`;case 1:return`${l(i.condition)} ? ${l(i.left)} : ${l(i.right)}`;case 8:return a(i);case 3:return u(i);case 6:return h(i);case 13:return m(i);case 16:return"} else {";case 14:return y(i);case 15:return w(i);default:throw new g(`Unsupported expression type '${i.type}'`)}}function h(i){if(i.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:i.pos};return`namespaces.${i.left.value}.${i.right.value}`}function a(i){let _=l(i.left);if(i.bracketNotation){let d=l(i.right),O=i.optional?"?.":"";return i.right.type===4||i.right.type===5?`${_}${O}[${d}]`:`${_}${O}[validateComputedProps(${d}, allowedProps, forbiddenProps)]`}else{let d=i.right.value,O=i.optional?"?.":".";if(s.has(d)&&!o.has(d))throw{message:"Forbidden property access.",pos:i.right.pos};return`${_}${O}${d}`}}function u(i){let _=l(i.expr),d=i.optional?"?.":"",O=i.args.map(x=>l(x)).join(", ");return`${_}${d}(${O})`}function m(i){let{iterable:_,loopType:d,variable:O}=i;return`for(const ${O} ${d===1?"in":"of"} ${D(_,r)}){`}function y(i){let{condition:_}=i;return`if(${D(_,r)}){`}function w(i){let{condition:_}=i;return`}else if(${D(_,r)}){`}let b=l(e);return b.includes("namespaces.Mutor.await")?b.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):b}function G(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function H(e,r){let t=0,s=!1;function o(n,p){let f=e[t],A=e[e.length-1];if(!f)throw{message:`Unexpected end of expression. Expected ${p?`'${p}'`:`${n===0?"an":"a"} ${G(n)}`}.`,pos:A.pos+A.value.length-1};if(f.type!==n)throw{message:`Unexpected token type. Expected ${p?`'${p}'`:G(n)} but got ${G(f.type)} instead.`,pos:f.pos};if(p!==void 0&&f.value!==p)throw{message:`Unexpected token '${f?.value}'. Expected ${n===0?"an":"a"} ${G(n)} instead.`,pos:f.pos};return e[t++]}function c(){let n=e[t-1].pos,p=o(0).value,f;try{f=o(1,"in")}catch{f=o(1,"of")}let A=f.value==="in"?1:0,M=R();return{type:13,loopType:A,iterable:M,variable:p,pos:n}}function l(){let n=R();return{condition:n,pos:n.pos,type:14}}function h(){let n=e[t-1].pos;try{return o(1,"if"),{...l(),type:15,pos:n}}catch{return{type:16,pos:n}}}function a(){let n=[];if(e[t]?.type===4&&e[t]?.value===")")return n;for(n.push(R());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,n.push(R());return n}function u(){let n=e[t++];if(n?.type===2)return{type:5,value:n.value,pos:n.pos};if(n?.type===3)return{type:4,value:n.value,pos:n.pos};if(n?.type===1){if(n.value==="for"&&t===1)return c();if(n.value==="true"||n.value==="false")return{type:10,true:n.value==="true",pos:n.pos};if(n.value==="undefined")return{type:11,pos:n.pos};if(n.value==="null")return{type:12,pos:n.pos};if(n.value==="end"&&e.length===1)return{type:17,pos:n.pos};if(n.value==="if"&&t===1)return l();if(n.value==="else"&&t===1)return h()}if(n?.type===0)return{type:7,value:n.value,pos:n.pos};if(n?.type===4&&n.value==="("){let p=R();return o(4,")"),{type:9,expr:p,pos:n.pos}}if(n?.type===4&&le.has(n.value)){let p=n.value,f=R();return{type:2,operator:p,expr:f,pos:n.pos}}throw t>e.length?{message:"Unexpected end of expression.",pos:e[e.length-1].pos}:{message:`Unexpected token '${n?.value}'.`,pos:n.pos}}function m(){let n=u();for(;e[t];){let p=e[t];if(p?.type===4&&p?.value==="("){if(t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let f=a();o(4,")"),n={type:3,expr:n,args:f,pos:e[t-1].pos}}else if(p?.type===4&&p?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!s&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let f=a();o(4,")"),n={type:3,expr:n,args:f,optional:!0,pos:e[t-1].pos}}else if(p?.type===4&&pe.has(p?.value)){let f=p?.value==="::",A=p?.value==="[",M=p?.value==="?.";if(t++,f&&(e[t-2]?.type!==0||e[t]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e[t-2]?.value}::${e[t]?.value??""}' instead.`,pos:e[t]?.pos??e[t-1].pos};if(f){s=!0;let P=u();n={type:6,left:n,right:P,pos:e[t-1].pos}}else if(A){let P=R();o(4,"]"),n={type:8,right:P,left:n,bracketNotation:!0,pos:e[t-1].pos}}else if(M)if(e[t]?.type===4&&e[t]?.value==="["){t++;let P=R();o(4,"]"),n={type:8,left:n,right:P,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let P=u();n={type:8,left:n,right:P,optional:!0,pos:e[t-1].pos}}else{let P=u();n={type:8,left:n,right:P,pos:e[t-1].pos}}}else break}return s=!1,n}function y(){let n=m();for(;e[t]?.type===4&&ce.has(e[t]?.value);){let p=e[t++].value,f=m();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function w(){let n=y();for(;e[t]?.type===4&&ae.has(e[t]?.value);){let p=e[t++].value,f=y();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function b(){let n=w();for(;e[t]?.type===4&&X.has(e[t]?.value);){let p=e[t++].value,f=w();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function i(){let n=b();for(;e[t]?.type===4&&X.has(e[t]?.value);){let p=e[t++].value,f=b();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function _(){let n=i();for(;e[t]?.type===4&&ie.has(e[t]?.value);){let p=e[t++].value,f=i();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function d(){let n=O();for(;e[t]?.type===4&&e[t]?.value==="||";){let p=e[t++].value,f=O();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function O(){let n=x();for(;e[t]?.type===4&&e[t]?.value==="&&";){let p=e[t++].value,f=x();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function x(){let n=_();for(;e[t]?.type===4&&e[t]?.value==="??";){let p=e[t++].value,f=_();n={type:0,left:n,right:f,operator:p,pos:e[t-1].pos}}return n}function R(){let n=d();if(e[t]?.type!==4||e[t]?.value!=="?")return n;t++;let p=R();o(4,":");let f=R();return{type:1,left:p,right:f,condition:n,pos:e[t-1].pos}}let V=R();if(t!==e.length)throw{pos:e[t].pos,message:`Expected token '${e[t].value}'.
11
+ Expected an operator or the end of the expression.`};return V}function Q(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,s=`${r.whitespaceTrim}${r.closingTag}`,o=e.startsWith(t),c=e.endsWith(s),l=e.startsWith(o?t+r.commentTag:r.openingTag+r.commentTag),h=e.slice(o?t.length:r.openingTag.length,e.length-(c?s.length:r.closingTag.length));if(l)return{isComment:l,leftTrim:o,rightTrim:c,async:me.test(h)};let a=h.trim(),u=a.startsWith("for")||a.startsWith("if")||a.startsWith("else"),m=a.startsWith("for")||a.startsWith("if"),y=a==="end",w=a.startsWith("for");return{leftTrim:o,rightTrim:c,inner:h,isBlock:u,isBlockEnd:y,hasContext:w,requiresBlockClose:m,usesAwait:h.includes("Mutor::await")}}function k(e){let r=0,t="",s=[];function o(){let a="";if(/[a-zA-Z$_]/.test(t)){let u=r;for(;/[a-zA-Z$_0-9]/.test(e[u])&&u<e.length;)a+=e[u],u++;s.push({type:se.has(a)?1:0,value:a,pos:r}),r=u,t=e[r]}}function c(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let a=t,u=r,m=r+1,y="";for(;m<e.length;){let w=e[m];if(w==="\\"){if(m+1>=e.length)throw{pos:m,message:"Unexpected end of string after escape character."};y+=w,y+=e[m+1],m+=2;continue}if(w===a)break;y+=w,m++}if(m>=e.length||e[m]!==a)throw{pos:u,message:`String literal missing closing ${a}.`};s.push({type:3,value:y,pos:u}),r=m}function l(){if(/[0-9]/.test(t)){let a=r,u="";for(;/[0-9.oxe]/.test(e[a])&&a<e.length;)u+=e[a],a++;let m=Number(u);if(Number.isNaN(m))throw{pos:r,message:"Found invalid number literal."};s.push({type:2,value:`${m}`,pos:r}),r=a-1,t=e[r]}}function h(){let a=`${t}${e[r+1]}`;if(L.has(a)){s.push({type:4,value:a,pos:r}),r++;return}if(L.has(t)){s.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],l(),o(),c(),h(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!L.has(t)&&!L.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return s.length?s:[{type:3,value:"",pos:0}]}function ee(e,r,t){let s=[],o=[],{delimiters:c,keepOpeningTagEscapeDelimiter:l,allowFnCalls:h,allowedProps:a,forbiddenProps:u,autoEscape:m}=r,y="sync",w=!1,b=0,i='let acc="";';for(;b<e.length;){let O=function(){let E=d,S=0;for(;E>=c.openingTagEscape.length&&e.slice(E-c.openingTagEscape.length,E)===c.openingTagEscape;)S++,E-=c.openingTagEscape.length;return S%2===1};var _=O;let d=e.indexOf(c.openingTag,b);if(d===-1){let E=e.slice(b);w&&(E=E.trimStart()),E&&(i+=`acc+=\`${v(E)}\`;`);break}if(O()){let E=e.slice(b,l?d+c.openingTagEscape.length+1:d-c.openingTag.length+1);w&&(E=E.trimStart(),w=!1),i+=`acc+=\`${v(E)}\`;`,l||(i+=`acc+=\`${c.openingTag}\`;`),b=d+c.openingTag.length;continue}let x=e.indexOf(c.closingTag,d);if(x===-1){let[E,S]=W(e,d),I=Y(e,S);throw new T("No closing tag found.",E,I,d,t.path)}let R=e.slice(d,x+c.closingTag.length),{async:V,inner:n,leftTrim:p,rightTrim:f,isBlock:A,isBlockEnd:M,hasContext:P,requiresBlockClose:re,isComment:Oe,usesAwait:_e}=Q(R,{delimiters:c});if(_e&&y!=="async")throw{pos:d,message:`Mutor::await() requires async mode.
12
+ Add {{# 'use async' }} at the top of the template.`};let C=e.slice(b,d);C&&(w&&(C=C.trimStart()),p&&(C=C.trimEnd()),C&&(i+=`acc+=\`${v(C)}\`;`)),w=!1,b=x+c.closingTag.length;try{if(Oe)V&&(y="async");else{let E=k(n),S=H(E,{allowFnCalls:h});if(A&&re&&P?(s.push(S.variable),o.push({type:0,pos:d})):A&&re&&!P&&o.push({type:1,pos:d}),M){let J=o.pop();if(J?.type===0&&s.pop(),J===void 0)throw{message:"Unexpected end of block",pos:d}}let I=D(S,{allowedProps:a,forbiddenProps:u,scope:s});A||M?i+=I:i+=m&&!I.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${I});`:`acc+=${I};`}f&&(w=!0)}catch(E){let{message:S,pos:I}=E,J=p?c.whitespaceTrim.length+c.openingTag.length:c.openingTag.length,ne=d+I+J,[Re,oe]=W(e,ne),be=Y(e,oe);throw new T(S,Re,be,ne-oe,t.path)}}if(o.length){let d=o.pop()?.pos,[O,x]=W(e,d),R=Y(e,x);throw new T("Unclosed block detected.",O,R,d-x,t.path)}return i+="return acc;",y==="async"?new de("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i)}var K=class{constructor(r={}){this.__cacheSize=0;this.__config={...N};this.__compiledTemplatesMap=new Map;this.__namespaces={...fe,Mutor:{await:async r=>await r}};this.addConfig(r)}addConfig(r){let{autoEscape:t,delimiters:s,allowedProps:o,forbiddenProps:c,keepOpeningTagEscapeDelimiter:l,allowFnCalls:h,cache:a,build:u,onIncludeFail:m,onIncludeError:y}=r;return this.__config={build:{include:new Set([...u?.include||N.build.include]),exclude:new Set([...N.build.exclude,...u?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:o||N.allowedProps,allowFnCalls:!!h,onIncludeFail:m||N.onIncludeFail,onIncludeError:y||N.onIncludeError,cache:{...N.cache,...a||{}},forbiddenProps:new Set([...N.forbiddenProps,...c||[]]),keepOpeningTagEscapeDelimiter:l===!0?!0:l!==!1,delimiters:{...N.delimiters,...s||{}}},this.__config}restoreDefaultConfig(){this.__config={...N}}compile(r,t){return ee(r,this.__config,{path:t?.renderedPath||"anonymous"})}renderAsync(r,t){return new Promise(s=>{s(this.render(r,t))})}render(r,t){let s=F(t,"anonymous");return this.__renderWithRuntime(r,s)}__renderWithRuntime(r,t){return this.compile(r,t)(j(t.context),this.__createNamespacesWithRuntime(t),this.__config.allowedProps,this.__config.forbiddenProps,z,B)}__createNamespacesWithRuntime(r){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:r.context}}}handleError(r,t,s,o){if(this.__config.onIncludeFail==="throw")throw r instanceof T?r:new g(r.message);let c={from:t,path:s,absolutePath:o};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(r instanceof T?console.log(r):console.log(`[Mutor.js]
13
+ ${r.message}`)),this.__config.onIncludeError?.(c,r)??""}createEntrySpaceForTemplate(r){if(this.__cacheSize+r<this.__config.cache.maxSize)return!0;if(r>this.__config.cache.maxSize)return!1;let t=this.__compiledTemplatesMap.entries().next().value;if(t){let[s,o]=t;this.__compiledTemplatesMap.delete(s),this.__cacheSize-=o.size}return this.createEntrySpaceForTemplate(r)}getDiagnostics(){let r=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:r,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(r/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:r>0?Math.min(100,Math.round(this.__cacheSize/r*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}register(r,t){let s=t.length*2+500;if(this.__cacheSize+s>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(s))throw new g(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let o=F(null,r);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t,o),size:s})}reset(){this.__config={...N},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var q=class extends K{constructor(r={}){super(r)}__setupIncludeForRuntime(r){this.__namespaces.Mutor.include=(t,s)=>{let o=$(r.renderedPath,t);if(r.includeStack.has(o))throw new g(`Circular include detected.
14
+ ${Array.from(r.includeStack).join(`
12
15
  `)}
13
- ${r}`);try{return this.__includeStack.add(r),this.renderComponent(r,t??this.__currentContext)}finally{this.__includeStack.delete(r)}}}};this.addConfig(r),Object.defineProperty(this.__namespaces.Mutor,"$$context",{get:()=>this.__currentContext})}addConfig(r){let{autoEscape:t,delimiters:a,allowedProps:o,forbiddenProps:c,keepOpeningTagEscapeDelimiter:f,allowFnCalls:g,cache:s,build:p}=r;return this.__config={build:{include:new Set([...p?.include||x.build.include]),exclude:new Set([...x.build.exclude,...p?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:o||x.allowedProps,allowFnCalls:!!g,cache:{...x.cache,...s||{}},forbiddenProps:new Set([...x.forbiddenProps,...c||[]]),keepOpeningTagEscapeDelimiter:f===!0?!0:f!==!1,delimiters:{...x.delimiters,...a||{}}},this.__config}restoreDefaultConfig(){this.__config={...x}}compile(r){return k(r,this.__config,{path:this.__currentRenderedPath||"anonymous"})}render(r,t){let a=this.__currentContext;a!==t&&(this.__currentContext=t);let o=this.compile(r)(j(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=a,o}renderComponent(r,t){if(!this.__compiledTemplatesMap.has(r))throw new m(`No template exists with the identifier '${r}'`);let a=this.__currentRenderedPath,o=this.__currentContext,c=this.__compiledTemplatesMap.get(r);this.__currentContext=t,this.__currentRenderedPath=r;let f=c.fn(j(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=o,this.__currentRenderedPath=a,f}registerComponent(r,t){let a=t.length*2+500;if(this.__cacheSize+a>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(a))throw new m(`The template for the component '${r}' is too large. Consider increasing 'cache.maxSize' in the config`);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t),size:a})}reset(){this.__config={...x},this.__compiledTemplatesMap.clear(),this.__currentContext=null,this.__cacheSize=0}createEntrySpaceForTemplate(r){if(this.__cacheSize+r<this.__config.cache.maxSize)return!0;if(r>this.__config.cache.maxSize)return!1;let t=this.__compiledTemplatesMap.entries().next().value;if(t){let[a,o]=t;this.__compiledTemplatesMap.delete(a),this.__cacheSize-=o.size}return this.createEntrySpaceForTemplate(r)}getDiagnostics(){let r=this.__config.cache.maxSize;return{bytesUsed:this.__cacheSize,bytesMax:r,readableUsed:`${(this.__cacheSize/1024/1024).toFixed(2)} MB`,readableMax:`${(r/1024/1024).toFixed(2)} MB`,totalEntries:this.__compiledTemplatesMap.size,percentFull:r>0?Math.min(100,Math.round(this.__cacheSize/r*100)):0,avgTemplateSize:this.__compiledTemplatesMap.size>0?Math.round(this.__cacheSize/this.__compiledTemplatesMap.size):0}}};var K=class extends G{constructor(r={}){super(r),this.__namespaces.Mutor.include=(t,a)=>{let o=T(this.__currentRenderedPath,t);if(this.__includeStack.has(o))throw new m(`Circular include detected:
14
- ${Array.from(this.__includeStack).join(`
15
- `)}
16
- ${o}`);try{return this.__includeStack.add(o),this.renderFile(o,a??this.__currentContext)}finally{this.__includeStack.delete(o)}}}renderFile(r,t){let a=T(r),o,c=this.__currentContext,f=this.__currentRenderedPath;if(this.__currentContext=t,this.__currentRenderedPath=r,this.__config.cache.active&&this.__compiledTemplatesMap.has(a))o=this.__compiledTemplatesMap.get(a).fn;else{let s=be(a,"utf-8");if(o=this.compile(s),this.__config.cache.active){let p=s.length*2+500;this.__cacheSize+p>this.__config.cache.maxSize?this.createEntrySpaceForTemplate(p)&&(this.__compiledTemplatesMap.set(a,{fn:o,size:p}),this.__cacheSize+=p):(this.__compiledTemplatesMap.set(a,{fn:o,size:p}),this.__cacheSize+=p)}}let g=o(j(t),this.__namespaces,this.__config.allowedProps,this.__config.forbiddenProps,F,D);return this.__currentContext=c,this.__currentRenderedPath=f,g}async buildDir(r,t,a){let o=T(t),c=T(r);await Pe(o,{recursive:!0});let f=await de(c,{withFileTypes:!0});await Promise.all(f.map(async g=>{let s=ee(c,g.name),p=ee(o,g.name);if(this.__config.build.exclude.has(g.name))return;if(g.isDirectory())return this.buildDir(s,p,a);let d=me(s);if(this.__config.build.include.has(d)){let _=this.renderFile(s,a);await Se(p,_,"utf-8")}else return await Re(s,p)}))}async compileDir(r){let t=T(r),a=await de(t,{withFileTypes:!0});await Promise.all(a.map(async o=>{let c=ee(t,o.name);if(this.__config.build.exclude.has(o.name))return;if(o.isDirectory())return this.compileDir(c);let f=me(c);if(this.__config.build.include.has(f))try{let g=await xe(c,"utf-8");this.registerComponent(c,g)}catch{}}))}};var It=K;export{It as default};
16
+ ${o}`);let c=r.renderedPath;r.includeStack.add(o),r.renderedPath=o;try{return this.__renderFile(o,s??r.context,r)}catch(l){return this.handleError(l,c,t,o)}finally{r.includeStack.delete(o),r.renderedPath=c}}}render(r,t){let s=F(t,"anonymous");return this.__setupIncludeForRuntime(s),this.__renderWithRuntime(r,s)}renderAsync(r,t){return new Promise(s=>{s(this.render(r,t))})}__renderFile(r,t,s){this.__setupIncludeForRuntime(s);let o=$(r),c,l=s.context,h=s.renderedPath;s.context=t??l,s.renderedPath=o;try{if(this.__config.cache.active&&this.__compiledTemplatesMap.has(o))c=this.__compiledTemplatesMap.get(o).fn;else{let u=Se(o,"utf-8");if(c=this.compile(u,s),this.__config.cache.active){let m=u.length*2+500;this.__cacheSize+m>this.__config.cache.maxSize?this.createEntrySpaceForTemplate(m)&&(this.__compiledTemplatesMap.set(o,{fn:c,size:m}),this.__cacheSize+=m):(this.__compiledTemplatesMap.set(o,{fn:c,size:m}),this.__cacheSize+=m)}}return c(j(s.context),this.__createNamespacesWithRuntime(s),this.__config.allowedProps,this.__config.forbiddenProps,z,B)}finally{s.context=l,s.renderedPath=h}}renderFile(r,t){return this.__renderFile(r,t,F(null,r))}async buildDir(r,t,s){let o=$(t),c=$(r);await Ie(o,{recursive:!0});let l=await Ee(c,{withFileTypes:!0});await Promise.all(l.map(async h=>{let a=te(c,h.name),u=te(o,h.name);if(this.__config.build.exclude.has(h.name))return;if(h.isDirectory())return this.buildDir(a,u,s);let m=we(a);if(this.__config.build.include.has(m)){let y=this.renderFile(a,s);await Fe(u,y,"utf-8")}else return await Te(a,u)}))}async compileDir(r){let t=$(r),s=await Ee(t,{withFileTypes:!0});await Promise.all(s.map(async o=>{let c=te(t,o.name);if(this.__config.build.exclude.has(o.name))return;if(o.isDirectory())return this.compileDir(c);let l=we(c);if(this.__config.build.include.has(l))try{let h=await Ce(c,"utf-8");this.register(c,h)}catch{}}))}};var Gt=q;export{Gt as default};
17
17
  //# sourceMappingURL=server.js.map