mutorjs 1.5.2 → 1.5.3

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/index.d.cts CHANGED
@@ -1,3 +1,161 @@
1
+ declare enum TokenType {
2
+ IDENT = 0,
3
+ KEYWORD = 1,
4
+ NUMBER = 2,
5
+ STRING = 3,
6
+ OPERATOR = 4
7
+ }
8
+ declare enum ExprType {
9
+ BINARY = 0,
10
+ TERNARY = 1,
11
+ UNARY = 2,
12
+ CALL = 3,
13
+ STRING = 4,
14
+ NUMBER = 5,
15
+ NAMESPACE = 6,
16
+ IDENT = 7,
17
+ PROP_ACCESS = 8,
18
+ GROUP = 9,
19
+ BOOLEAN = 10,
20
+ UNDEFINED = 11,
21
+ NULL = 12,
22
+ FOR = 13,
23
+ IF = 14,
24
+ ELSE_IF = 15,
25
+ ELSE = 16,
26
+ END = 17
27
+ }
28
+ declare enum LoopType {
29
+ OF = 0,
30
+ IN = 1
31
+ }
32
+ declare enum BlockType {
33
+ LOOP = 0,
34
+ NON_LOOP = 1
35
+ }
36
+
37
+ type BaseToken = {
38
+ type: TokenType;
39
+ value: string;
40
+ pos: number;
41
+ };
42
+ type KeywordToken = BaseToken & {
43
+ type: TokenType.KEYWORD;
44
+ };
45
+ type IdentToken = BaseToken & {
46
+ type: TokenType.IDENT;
47
+ };
48
+ type StringToken = BaseToken & {
49
+ type: TokenType.STRING;
50
+ };
51
+ type NumberToken = BaseToken & {
52
+ type: TokenType.NUMBER;
53
+ };
54
+ type OperatorToken = BaseToken & {
55
+ type: TokenType.OPERATOR;
56
+ };
57
+ type Token = BaseToken | KeywordToken | IdentToken | StringToken | NumberToken | OperatorToken;
58
+ type EndExpr = {
59
+ type: ExprType.END;
60
+ pos: number;
61
+ };
62
+ type ForExpr = {
63
+ pos: number;
64
+ type: ExprType.FOR;
65
+ variable: string;
66
+ iterable: Expr;
67
+ loopType: LoopType;
68
+ };
69
+ type IfExpr = {
70
+ pos: number;
71
+ type: ExprType.IF;
72
+ condition: Expr;
73
+ };
74
+ type ElseExpr = {
75
+ pos: number;
76
+ type: ExprType.ELSE;
77
+ };
78
+ type ElseIfExpr = {
79
+ pos: number;
80
+ type: ExprType.ELSE_IF;
81
+ condition: Expr;
82
+ };
83
+ type BooleanExpr = {
84
+ pos: number;
85
+ type: ExprType.BOOLEAN;
86
+ true: boolean;
87
+ };
88
+ type UndefinedExpr = {
89
+ pos: number;
90
+ type: ExprType.UNDEFINED;
91
+ };
92
+ type NullExpr = {
93
+ pos: number;
94
+ type: ExprType.NULL;
95
+ };
96
+ type PropAccessExpr = {
97
+ pos: number;
98
+ type: ExprType.PROP_ACCESS;
99
+ left: Expr;
100
+ right: Expr;
101
+ bracketNotation?: boolean;
102
+ optional?: boolean;
103
+ };
104
+ type BinaryExpr = {
105
+ pos: number;
106
+ type: ExprType.BINARY;
107
+ left: Expr;
108
+ right: Expr;
109
+ operator: string;
110
+ };
111
+ type UnaryExpr = {
112
+ pos: number;
113
+ type: ExprType.UNARY;
114
+ operator: string;
115
+ expr: Expr;
116
+ isPostfix?: boolean;
117
+ };
118
+ type TernaryExpr = {
119
+ pos: number;
120
+ type: ExprType.TERNARY;
121
+ condition: Expr;
122
+ left: Expr;
123
+ right: Expr;
124
+ };
125
+ type CallExpr = {
126
+ pos: number;
127
+ type: ExprType.CALL;
128
+ expr: Expr;
129
+ args: Expr[];
130
+ optional?: boolean;
131
+ };
132
+ type IdentExpr = {
133
+ pos: number;
134
+ type: ExprType.IDENT;
135
+ value: string;
136
+ };
137
+ type GroupExpr = {
138
+ pos: number;
139
+ type: ExprType.GROUP;
140
+ expr: Expr;
141
+ };
142
+ type StringExpr = {
143
+ pos: number;
144
+ type: ExprType.STRING;
145
+ value: string;
146
+ };
147
+ type NumberExpr = {
148
+ pos: number;
149
+ type: ExprType.NUMBER;
150
+ value: string;
151
+ };
152
+ type NamespaceExpr = {
153
+ pos: number;
154
+ type: ExprType.NAMESPACE;
155
+ left: Expr;
156
+ right: Expr;
157
+ };
158
+ type Expr = ForExpr | IfExpr | ElseIfExpr | ElseExpr | EndExpr | BooleanExpr | NullExpr | UndefinedExpr | PropAccessExpr | IdentExpr | BinaryExpr | UnaryExpr | TernaryExpr | CallExpr | GroupExpr | StringExpr | NumberExpr | NamespaceExpr;
1
159
  interface MutorConfig {
2
160
  cache: {
3
161
  active: boolean;
@@ -34,15 +192,42 @@ type PartialMutorConfig = Partial<Omit<MutorConfig, "delimiters">> & {
34
192
  exclude?: Set<string>;
35
193
  };
36
194
  };
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
- */
195
+ type BuildContext = {
196
+ scope: string[];
197
+ forbiddenProps: Set<string>;
198
+ allowedProps: Set<string>;
199
+ };
200
+ type CompileMetadata = {
201
+ path: string;
202
+ };
203
+ type CommandStruct = {
204
+ command: string;
205
+ commandData: string;
206
+ "--out"?: string;
207
+ "--data"?: string;
208
+ "--config"?: string;
209
+ };
210
+ type CleanupFn = () => void;
211
+ type ExitCode = 0 | 1 | 2;
41
212
  interface RuntimeFrame {
42
213
  context: any;
43
214
  renderedPath: string;
44
215
  includeStack: Set<string>;
45
216
  }
217
+ interface ParseState {
218
+ cursor: number;
219
+ tokens: Token[];
220
+ config: {
221
+ allowFnCalls: boolean;
222
+ };
223
+ generatingNamespace: boolean;
224
+ }
225
+ interface BuildState {
226
+ scope: string[];
227
+ forbiddenProps: Set<string>;
228
+ allowedProps: Set<string>;
229
+ context: BuildContext;
230
+ }
46
231
 
47
232
  declare class MutorBase {
48
233
  protected __cacheSize: number;
@@ -86,4 +271,4 @@ declare class Mutor extends MutorBase {
86
271
  registerComponent(identifier: string, template: string): void;
87
272
  }
88
273
 
89
- export { Mutor as default };
274
+ export { type BaseToken, type BinaryExpr, BlockType, type BooleanExpr, type BuildContext, type BuildState, type CallExpr, type CleanupFn, type CommandStruct, type CompileMetadata, type ElseExpr, type ElseIfExpr, type EndExpr, type ExitCode, type Expr, ExprType, type ForExpr, type GroupExpr, type IdentExpr, type IdentToken, type IfExpr, type KeywordToken, LoopType, type MutorConfig, type NamespaceExpr, type NullExpr, type NumberExpr, type NumberToken, type OperatorToken, type ParseState, type PartialMutorConfig, type PropAccessExpr, type RuntimeFrame, type StringExpr, type StringToken, type TernaryExpr, type Token, TokenType, type UnaryExpr, type UndefinedExpr, Mutor as default };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,161 @@
1
+ declare enum TokenType {
2
+ IDENT = 0,
3
+ KEYWORD = 1,
4
+ NUMBER = 2,
5
+ STRING = 3,
6
+ OPERATOR = 4
7
+ }
8
+ declare enum ExprType {
9
+ BINARY = 0,
10
+ TERNARY = 1,
11
+ UNARY = 2,
12
+ CALL = 3,
13
+ STRING = 4,
14
+ NUMBER = 5,
15
+ NAMESPACE = 6,
16
+ IDENT = 7,
17
+ PROP_ACCESS = 8,
18
+ GROUP = 9,
19
+ BOOLEAN = 10,
20
+ UNDEFINED = 11,
21
+ NULL = 12,
22
+ FOR = 13,
23
+ IF = 14,
24
+ ELSE_IF = 15,
25
+ ELSE = 16,
26
+ END = 17
27
+ }
28
+ declare enum LoopType {
29
+ OF = 0,
30
+ IN = 1
31
+ }
32
+ declare enum BlockType {
33
+ LOOP = 0,
34
+ NON_LOOP = 1
35
+ }
36
+
37
+ type BaseToken = {
38
+ type: TokenType;
39
+ value: string;
40
+ pos: number;
41
+ };
42
+ type KeywordToken = BaseToken & {
43
+ type: TokenType.KEYWORD;
44
+ };
45
+ type IdentToken = BaseToken & {
46
+ type: TokenType.IDENT;
47
+ };
48
+ type StringToken = BaseToken & {
49
+ type: TokenType.STRING;
50
+ };
51
+ type NumberToken = BaseToken & {
52
+ type: TokenType.NUMBER;
53
+ };
54
+ type OperatorToken = BaseToken & {
55
+ type: TokenType.OPERATOR;
56
+ };
57
+ type Token = BaseToken | KeywordToken | IdentToken | StringToken | NumberToken | OperatorToken;
58
+ type EndExpr = {
59
+ type: ExprType.END;
60
+ pos: number;
61
+ };
62
+ type ForExpr = {
63
+ pos: number;
64
+ type: ExprType.FOR;
65
+ variable: string;
66
+ iterable: Expr;
67
+ loopType: LoopType;
68
+ };
69
+ type IfExpr = {
70
+ pos: number;
71
+ type: ExprType.IF;
72
+ condition: Expr;
73
+ };
74
+ type ElseExpr = {
75
+ pos: number;
76
+ type: ExprType.ELSE;
77
+ };
78
+ type ElseIfExpr = {
79
+ pos: number;
80
+ type: ExprType.ELSE_IF;
81
+ condition: Expr;
82
+ };
83
+ type BooleanExpr = {
84
+ pos: number;
85
+ type: ExprType.BOOLEAN;
86
+ true: boolean;
87
+ };
88
+ type UndefinedExpr = {
89
+ pos: number;
90
+ type: ExprType.UNDEFINED;
91
+ };
92
+ type NullExpr = {
93
+ pos: number;
94
+ type: ExprType.NULL;
95
+ };
96
+ type PropAccessExpr = {
97
+ pos: number;
98
+ type: ExprType.PROP_ACCESS;
99
+ left: Expr;
100
+ right: Expr;
101
+ bracketNotation?: boolean;
102
+ optional?: boolean;
103
+ };
104
+ type BinaryExpr = {
105
+ pos: number;
106
+ type: ExprType.BINARY;
107
+ left: Expr;
108
+ right: Expr;
109
+ operator: string;
110
+ };
111
+ type UnaryExpr = {
112
+ pos: number;
113
+ type: ExprType.UNARY;
114
+ operator: string;
115
+ expr: Expr;
116
+ isPostfix?: boolean;
117
+ };
118
+ type TernaryExpr = {
119
+ pos: number;
120
+ type: ExprType.TERNARY;
121
+ condition: Expr;
122
+ left: Expr;
123
+ right: Expr;
124
+ };
125
+ type CallExpr = {
126
+ pos: number;
127
+ type: ExprType.CALL;
128
+ expr: Expr;
129
+ args: Expr[];
130
+ optional?: boolean;
131
+ };
132
+ type IdentExpr = {
133
+ pos: number;
134
+ type: ExprType.IDENT;
135
+ value: string;
136
+ };
137
+ type GroupExpr = {
138
+ pos: number;
139
+ type: ExprType.GROUP;
140
+ expr: Expr;
141
+ };
142
+ type StringExpr = {
143
+ pos: number;
144
+ type: ExprType.STRING;
145
+ value: string;
146
+ };
147
+ type NumberExpr = {
148
+ pos: number;
149
+ type: ExprType.NUMBER;
150
+ value: string;
151
+ };
152
+ type NamespaceExpr = {
153
+ pos: number;
154
+ type: ExprType.NAMESPACE;
155
+ left: Expr;
156
+ right: Expr;
157
+ };
158
+ type Expr = ForExpr | IfExpr | ElseIfExpr | ElseExpr | EndExpr | BooleanExpr | NullExpr | UndefinedExpr | PropAccessExpr | IdentExpr | BinaryExpr | UnaryExpr | TernaryExpr | CallExpr | GroupExpr | StringExpr | NumberExpr | NamespaceExpr;
1
159
  interface MutorConfig {
2
160
  cache: {
3
161
  active: boolean;
@@ -34,15 +192,42 @@ type PartialMutorConfig = Partial<Omit<MutorConfig, "delimiters">> & {
34
192
  exclude?: Set<string>;
35
193
  };
36
194
  };
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
- */
195
+ type BuildContext = {
196
+ scope: string[];
197
+ forbiddenProps: Set<string>;
198
+ allowedProps: Set<string>;
199
+ };
200
+ type CompileMetadata = {
201
+ path: string;
202
+ };
203
+ type CommandStruct = {
204
+ command: string;
205
+ commandData: string;
206
+ "--out"?: string;
207
+ "--data"?: string;
208
+ "--config"?: string;
209
+ };
210
+ type CleanupFn = () => void;
211
+ type ExitCode = 0 | 1 | 2;
41
212
  interface RuntimeFrame {
42
213
  context: any;
43
214
  renderedPath: string;
44
215
  includeStack: Set<string>;
45
216
  }
217
+ interface ParseState {
218
+ cursor: number;
219
+ tokens: Token[];
220
+ config: {
221
+ allowFnCalls: boolean;
222
+ };
223
+ generatingNamespace: boolean;
224
+ }
225
+ interface BuildState {
226
+ scope: string[];
227
+ forbiddenProps: Set<string>;
228
+ allowedProps: Set<string>;
229
+ context: BuildContext;
230
+ }
46
231
 
47
232
  declare class MutorBase {
48
233
  protected __cacheSize: number;
@@ -86,4 +271,4 @@ declare class Mutor extends MutorBase {
86
271
  registerComponent(identifier: string, template: string): void;
87
272
  }
88
273
 
89
- export { Mutor as default };
274
+ export { type BaseToken, type BinaryExpr, BlockType, type BooleanExpr, type BuildContext, type BuildState, type CallExpr, type CleanupFn, type CommandStruct, type CompileMetadata, type ElseExpr, type ElseIfExpr, type EndExpr, type ExitCode, type Expr, ExprType, type ForExpr, type GroupExpr, type IdentExpr, type IdentToken, type IfExpr, type KeywordToken, LoopType, type MutorConfig, type NamespaceExpr, type NullExpr, type NumberExpr, type NumberToken, type OperatorToken, type ParseState, type PartialMutorConfig, type PropAccessExpr, type RuntimeFrame, type StringExpr, type StringToken, type TernaryExpr, type Token, TokenType, type UnaryExpr, type UndefinedExpr, Mutor as default };
package/dist/index.js CHANGED
@@ -1,15 +1,14 @@
1
- function $(e,r=""){return{context:e,renderedPath:r,includeStack:new Set([r&&r])}}function V(e,r){return`${" ".repeat(e+r)}^`}var u=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},C=class e extends u{constructor(t,o,s,c,f){let d=o.toString().length+2,a=`${t}
1
+ function N(e,r=""){return{context:e,renderedPath:r,includeStack:new Set([r&&r])}}function J(e,r){return`${" ".repeat(e+r)}^`}var i=class e extends Error{constructor(t){super(t);this.name="MutorError";Object.setPrototypeOf(this,e.prototype)}},R=class e extends i{constructor(t,n,s,o,a){let h=n.toString().length+2,p=`${t}
2
2
 
3
- `;a+=`at ${f}:${o}:${c+1}
4
- `,o>1&&(a+=`${(o-1).toString().padStart(d-2)} | ...
5
- `),a+=`${o} | ${s}
6
- `,a+=V(c,d+1);super(a);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ne=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),D=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var oe=new Set(["==","!="]),Z=new Set([">","<",">=","<="]);var se=new Set(["+","-"]),ie=new Set(["*","/","%"]),ae=new Set([".","?.","[","::"]),ce=new Set(["-","+","!"]),pe={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},A={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}},ue={JSON:{stringify(e,r){try{return JSON.stringify(e,null,r)}catch{throw new u("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new u("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new u("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new u("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new u("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new u("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new u("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new u("Object::fromEntries expects an array");return Object.fromEntries(e)},pick(e,r){if(!e||typeof e!="object")throw new u("Object::pick expects an object");if(!Array.isArray(r))throw new u("Object::pick expects an array of keys");let t={};for(let o of r)Object.hasOwn(e,o)&&(t[o]=e[o]);return t},omit(e,r){if(!e||typeof e!="object")throw new u("Object::omit expects an object");if(!Array.isArray(r))throw new u("Object::omit expects an array of keys");let t={...e};for(let o of r)delete t[o];return t}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)},of(...e){return Array.of(...e)},unique(e){if(!Array.isArray(e))throw new u("Array::unique expects an array");return[...new Set(e)]},compact(e){if(!Array.isArray(e))throw new u("Array::compact expects an array");return e.filter(Boolean)},chunk(e,r){if(!Array.isArray(e))throw new u("Array::chunk expects an array");if(!Number.isInteger(r)||r<=0)throw new u("Array::chunk expects a positive integer size");let t=[];for(let o=0;o<e.length;o+=r)t.push(e.slice(o,o+r));return t},range(e,r,t=1){if(!Number.isFinite(e)||!Number.isFinite(r)||!Number.isFinite(t))throw new u("Array::range expects finite numbers");if(t===0)throw new u("Array::range step cannot be 0");let o=[];if(e<=r)for(let s=e;s<=r;s+=t)o.push(s);else for(let s=e;s>=r;s-=Math.abs(t))o.push(s);return o}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},isInteger(e){return Number.isInteger(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)},clamp(e,r,t){return Math.min(Math.max(e,r),t)},toFixed(e,r=0){if(typeof e!="number")throw new u("Number::toFixed expects a number");return e.toFixed(r)},random(e=0,r=1){return Math.random()*(r-e)+e}},String:{fromCharCode(...e){return String.fromCharCode(...e)},capitalize(e){if(typeof e!="string")throw new u("String::capitalize expects a string");return e.length?e[0].toUpperCase()+e.slice(1):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)},trunc(e){return Math.trunc(e)},sign(e){return Math.sign(e)},sqrt(e){return Math.sqrt(e)},pow(e,r){return e**r},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 u("Date::parse expects a string");return Date.parse(e)},new(e){return e===void 0?new Date:new Date(e)},iso(e){return new Date(e??Date.now()).toISOString()},timestamp(e){return new Date(e??Date.now()).getTime()}},Boolean:{valueOf(e){return!!e}},RegExp:{test(e,r,t=""){if(typeof e!="string")throw new u("RegExp::test expects a pattern string");if(typeof r!="string")throw new u("RegExp::test expects a value string");return new RegExp(e,t).test(r)},match(e,r,t=""){if(typeof e!="string")throw new u("RegExp::match expects a pattern string");if(typeof r!="string")throw new u("RegExp::match expects a value string");return r.match(new RegExp(e,t))}},URL:{encode(e){if(typeof e!="string")throw new u("URL::encode expects a string");return encodeURIComponent(e)},decode(e){if(typeof e!="string")throw new u("URL::decode expects a string");return decodeURIComponent(e)}}},le=/('|"|`)use\s+async\1/,fe=(async()=>{}).constructor;function U(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>pe[r]):e}function L(e,r,t){if(t.has(e)&&!r.has(e))throw new u(`Forbidden property access.
7
- Access to this computed property '${e}' is forbidden.`);return e}var j="object",me=Symbol("__mutor_safe_context");function B(e){if(!e||typeof e!==j||me in e)return e;let r=new WeakSet;function t(s,c=""){if(!s||typeof s!==j||r.has(s))return s;r.add(s);let f=Object.getPrototypeOf(s);if(f&&f!==Object.prototype&&f!==Array.prototype)throw new u(`Unsafe prototype detected at ${c||"root"} in context.`);if(Array.isArray(s)){for(let a=0;a<s.length;a++)s[a]=t(s[a],`${c}[${a}]`);return s}if(s instanceof Map){for(let[a,m]of s.entries())typeof a===j&&t(a,`${c}.mapKey`),s.set(a,t(m,`${c}.mapValue`));return s}if(s instanceof Set){let a=new Set;for(let m of s.values())a.add(t(m,c));s.clear();for(let m of a)s.add(m);return s}let d=Object.getOwnPropertyDescriptors(s);for(let a of Object.keys(d)){let m=d[a];if(m.get||m.set)throw new u(`Getter/setter not allowed at '${c}.${a}' in context.`);let h=s[a];h&&typeof h===j&&(s[a]=t(h,`${c}.${a}`))}return s}let o=t(e);return o&&typeof o===j&&Object.defineProperty(o,me,{value:!0,enumerable:!1,writable:!1,configurable:!1}),o}function F(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function W(e,r){let o=e.slice(0,r).split(`
3
+ `;p+=`at ${a}:${n}:${o+1}
4
+ `,n>1&&(p+=`${(n-1).toString().padStart(h-2)} | ...
5
+ `),p+=`${n} | ${s}
6
+ `,p+=J(o,h+1);super(p);this.name="MutorCompilerError";Object.setPrototypeOf(this,e.prototype)}};var ae=new Set(["for","if","else","true","false","null","undefined","end","in","of"]),C=new Set(["::","||","??","&&","**","^","|","&","!","-","%","+","*","/",">","<",">=","<=","==","!=",">>","<<",".","?.","(",")","[","]",",",":","?"]);var pe=new Set(["==","!="]),V=new Set([">","<",">=","<="]);var ue=new Set(["+","-"]),le=new Set(["*","/","%"]),fe=new Set([".","?.","[","::"]),me=new Set(["-","+","!"]),ge={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},g={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}},de={JSON:{stringify(e,r){try{return JSON.stringify(e,null,r)}catch{throw new i("JSON::stringify failed")}},parse(e){if(typeof e!="string")throw new i("JSON::parse expects a string");try{return JSON.parse(e)}catch{throw new i("JSON::parse failed: invalid JSON string")}}},Object:{keys(e){if(!e||typeof e!="object")throw new i("Object::keys expects an object");return Object.keys(e)},values(e){if(!e||typeof e!="object")throw new i("Object::values expects an object");return Object.values(e)},entries(e){if(!e||typeof e!="object")throw new i("Object::entries expects an object");return Object.entries(e)},hasOwn(e,r){if(!e||typeof e!="object")throw new i("Object::hasOwn expects an object");return Object.hasOwn(e,r)},fromEntries(e){if(!Array.isArray(e))throw new i("Object::fromEntries expects an array");return Object.fromEntries(e)},pick(e,r){if(!e||typeof e!="object")throw new i("Object::pick expects an object");if(!Array.isArray(r))throw new i("Object::pick expects an array of keys");let t={};for(let n of r)Object.hasOwn(e,n)&&(t[n]=e[n]);return t},omit(e,r){if(!e||typeof e!="object")throw new i("Object::omit expects an object");if(!Array.isArray(r))throw new i("Object::omit expects an array of keys");let t={...e};for(let n of r)delete t[n];return t}},Array:{isArray(e){return Array.isArray(e)},from(e){return Array.from(e)},of(...e){return Array.of(...e)},unique(e){if(!Array.isArray(e))throw new i("Array::unique expects an array");return[...new Set(e)]},compact(e){if(!Array.isArray(e))throw new i("Array::compact expects an array");return e.filter(Boolean)},chunk(e,r){if(!Array.isArray(e))throw new i("Array::chunk expects an array");if(!Number.isInteger(r)||r<=0)throw new i("Array::chunk expects a positive integer size");let t=[];for(let n=0;n<e.length;n+=r)t.push(e.slice(n,n+r));return t},range(e,r,t=1){if(!Number.isFinite(e)||!Number.isFinite(r)||!Number.isFinite(t))throw new i("Array::range expects finite numbers");if(t===0)throw new i("Array::range step cannot be 0");let n=[];if(e<=r)for(let s=e;s<=r;s+=t)n.push(s);else for(let s=e;s>=r;s-=Math.abs(t))n.push(s);return n}},Number:{isFinite(e){return Number.isFinite(e)},isNaN(e){return Number.isNaN(e)},isInteger(e){return Number.isInteger(e)},parseInt(e,r=10){return Number.parseInt(e,r)},parseFloat(e){return Number.parseFloat(e)},clamp(e,r,t){return Math.min(Math.max(e,r),t)},toFixed(e,r=0){if(typeof e!="number")throw new i("Number::toFixed expects a number");return e.toFixed(r)},random(e=0,r=1){return Math.random()*(r-e)+e}},String:{fromCharCode(...e){return String.fromCharCode(...e)},capitalize(e){if(typeof e!="string")throw new i("String::capitalize expects a string");return e.length?e[0].toUpperCase()+e.slice(1):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)},trunc(e){return Math.trunc(e)},sign(e){return Math.sign(e)},sqrt(e){return Math.sqrt(e)},pow(e,r){return e**r},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 i("Date::parse expects a string");return Date.parse(e)},new(e){return e===void 0?new Date:new Date(e)},iso(e){return new Date(e??Date.now()).toISOString()},timestamp(e){return new Date(e??Date.now()).getTime()}},Boolean:{valueOf(e){return!!e}},RegExp:{test(e,r,t=""){if(typeof e!="string")throw new i("RegExp::test expects a pattern string");if(typeof r!="string")throw new i("RegExp::test expects a value string");return new RegExp(e,t).test(r)},match(e,r,t=""){if(typeof e!="string")throw new i("RegExp::match expects a pattern string");if(typeof r!="string")throw new i("RegExp::match expects a value string");return r.match(new RegExp(e,t))}},URL:{encode(e){if(typeof e!="string")throw new i("URL::encode expects a string");return encodeURIComponent(e)},decode(e){if(typeof e!="string")throw new i("URL::decode expects a string");return decodeURIComponent(e)}}},he=(async()=>{}).constructor;function I(e){return typeof e!="string"?e:/[&<>"']/.test(e)?e.replace(/[&<>"']/g,r=>ge[r]):e}function $(e,r,t){if(t.has(e)&&!r.has(e))throw new i(`Forbidden property access.
7
+ Access to this computed property '${e}' is forbidden.`);return e}var F="object",ye=Symbol("__mutor_safe_context");function Te(e){return e&&(typeof e===F||typeof e=="function")&&typeof e.then=="function"}function k(e,r="",t=new Set){if(!e||typeof e!==F||Te(e)||t.has(e))return e;if(t.add(e),e instanceof Map){for(let[o,a]of e.entries())typeof o===F&&k(o,`${r}.mapKey`,t),e.set(o,k(a,`${r}.mapValue`,t));return e}if(e instanceof Set){let o=new Set;for(let a of e.values())o.add(k(a,r,t));e.clear();for(let a of o)e.add(a);return e}let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==Array.prototype)throw new i(`Unsafe prototype detected at ${r||"root"} in context.`);if(Array.isArray(e)){for(let o=0;o<e.length;o++)e[o]=k(e[o],`${r}[${o}]`,t);return e}let s=Object.getOwnPropertyDescriptors(e);for(let o of Object.keys(s)){let a=s[o];if(a.get||a.set)throw new i(`Getter/setter not allowed at '${r}.${o}' in context.`);e[o]=k(e[o],`${r}.${o}`,t)}return e}function M(e){if(!e||typeof e!==F||ye in e)return e;let r=k(e);return r&&typeof r===F&&Object.defineProperty(r,ye,{value:!0,enumerable:!1,writable:!1,configurable:!1}),r}var Y=(o=>(o[o.IDENT=0]="IDENT",o[o.KEYWORD=1]="KEYWORD",o[o.NUMBER=2]="NUMBER",o[o.STRING=3]="STRING",o[o.OPERATOR=4]="OPERATOR",o))(Y||{}),Z=(c=>(c[c.BINARY=0]="BINARY",c[c.TERNARY=1]="TERNARY",c[c.UNARY=2]="UNARY",c[c.CALL=3]="CALL",c[c.STRING=4]="STRING",c[c.NUMBER=5]="NUMBER",c[c.NAMESPACE=6]="NAMESPACE",c[c.IDENT=7]="IDENT",c[c.PROP_ACCESS=8]="PROP_ACCESS",c[c.GROUP=9]="GROUP",c[c.BOOLEAN=10]="BOOLEAN",c[c.UNDEFINED=11]="UNDEFINED",c[c.NULL=12]="NULL",c[c.FOR=13]="FOR",c[c.IF=14]="IF",c[c.ELSE_IF=15]="ELSE_IF",c[c.ELSE=16]="ELSE",c[c.END=17]="END",c))(Z||{}),H=(t=>(t[t.OF=0]="OF",t[t.IN=1]="IN",t))(H||{}),Ee=(t=>(t[t.LOOP=0]="LOOP",t[t.NON_LOOP=1]="NON_LOOP",t))(Ee||{});function A(e){return e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$")}function v(e,r){let n=e.slice(0,r).split(`
8
8
  `).length,s=e.lastIndexOf(`
9
- `,r-1)+1;return[o,s]}function z(e,r){let t=e.indexOf(`
10
- `,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function v(e,r){let{scope:t,forbiddenProps:o,allowedProps:s}=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)?F(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 a(i);case 3:return m(i);case 6:return d(i);case 13:return h(i);case 16:return"} else {";case 14:return w(i);case 15:return E(i);default:throw new u(`Unsupported expression type '${i.type}'`)}}function d(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 R=f(i.left);if(i.bracketNotation){let g=f(i.right),O=i.optional?"?.":"";return i.right.type===4||i.right.type===5?`${R}${O}[${g}]`:`${R}${O}[validateComputedProps(${g}, allowedProps, forbiddenProps)]`}else{let g=i.right.value,O=i.optional?"?.":".";if(o.has(g)&&!s.has(g))throw{message:"Forbidden property access.",pos:i.right.pos};return`${R}${O}${g}`}}function m(i){let R=f(i.expr),g=i.optional?"?.":"",O=i.args.map(N=>f(N)).join(", ");return`${R}${g}(${O})`}function h(i){let{iterable:R,loopType:g,variable:O}=i;return`for(const ${O} ${g===1?"in":"of"} ${v(R,r)}){`}function w(i){let{condition:R}=i;return`if(${v(R,r)}){`}function E(i){let{condition:R}=i;return`}else if(${v(R,r)}){`}let x=f(e);return x.includes("namespaces.Mutor.await")?x.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):x}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 X(e,r){let t=0,o=!1;function s(n,p){let l=e[t],P=e[e.length-1];if(!l)throw{message:`Unexpected end of expression. Expected ${p?`'${p}'`:`${n===0?"an":"a"} ${Y(n)}`}.`,pos:P.pos+P.value.length-1};if(l.type!==n)throw{message:`Unexpected token type. Expected ${p?`'${p}'`:Y(n)} but got ${Y(l.type)} instead.`,pos:l.pos};if(p!==void 0&&l.value!==p)throw{message:`Unexpected token '${l?.value}'. Expected ${n===0?"an":"a"} ${Y(n)} instead.`,pos:l.pos};return e[t++]}function c(){let n=e[t-1].pos,p=s(0).value,l;try{l=s(1,"in")}catch{l=s(1,"of")}let P=l.value==="in"?1:0,M=b();return{type:13,loopType:P,iterable:M,variable:p,pos:n}}function f(){let n=b();return{condition:n,pos:n.pos,type:14}}function d(){let n=e[t-1].pos;try{return s(1,"if"),{...f(),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(b());e[t]?.type===4&&e[t]?.value===","&&e[t]?.value!==")";)t++,n.push(b());return n}function m(){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 d()}if(n?.type===0)return{type:7,value:n.value,pos:n.pos};if(n?.type===4&&n.value==="("){let p=b();return s(4,")"),{type:9,expr:p,pos:n.pos}}if(n?.type===4&&ce.has(n.value)){let p=n.value,l=b();return{type:2,operator:p,expr:l,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 h(){let n=m();for(;e[t];){let p=e[t];if(p?.type===4&&p?.value==="("){if(t++,!o&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let l=a();s(4,")"),n={type:3,expr:n,args:l,pos:e[t-1].pos}}else if(p?.type===4&&p?.value==="?."&&e[t+1]?.type===4&&e[t+1]?.value==="("){if(t++,t++,!o&&!r.allowFnCalls)throw{message:"Function calls are not allowed.",pos:e[t-1].pos};let l=a();s(4,")"),n={type:3,expr:n,args:l,optional:!0,pos:e[t-1].pos}}else if(p?.type===4&&ae.has(p?.value)){let l=p?.value==="::",P=p?.value==="[",M=p?.value==="?.";if(t++,l&&(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(l){o=!0;let _=m();n={type:6,left:n,right:_,pos:e[t-1].pos}}else if(P){let _=b();s(4,"]"),n={type:8,right:_,left:n,bracketNotation:!0,pos:e[t-1].pos}}else if(M)if(e[t]?.type===4&&e[t]?.value==="["){t++;let _=b();s(4,"]"),n={type:8,left:n,right:_,bracketNotation:!0,optional:!0,pos:e[t-1].pos}}else{let _=m();n={type:8,left:n,right:_,optional:!0,pos:e[t-1].pos}}else{let _=m();n={type:8,left:n,right:_,pos:e[t-1].pos}}}else break}return o=!1,n}function w(){let n=h();for(;e[t]?.type===4&&ie.has(e[t]?.value);){let p=e[t++].value,l=h();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function E(){let n=w();for(;e[t]?.type===4&&se.has(e[t]?.value);){let p=e[t++].value,l=w();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function x(){let n=E();for(;e[t]?.type===4&&Z.has(e[t]?.value);){let p=e[t++].value,l=E();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function i(){let n=x();for(;e[t]?.type===4&&Z.has(e[t]?.value);){let p=e[t++].value,l=x();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function R(){let n=i();for(;e[t]?.type===4&&oe.has(e[t]?.value);){let p=e[t++].value,l=i();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function g(){let n=O();for(;e[t]?.type===4&&e[t]?.value==="||";){let p=e[t++].value,l=O();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function O(){let n=N();for(;e[t]?.type===4&&e[t]?.value==="&&";){let p=e[t++].value,l=N();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function N(){let n=R();for(;e[t]?.type===4&&e[t]?.value==="??";){let p=e[t++].value,l=R();n={type:0,left:n,right:l,operator:p,pos:e[t-1].pos}}return n}function b(){let n=g();if(e[t]?.type!==4||e[t]?.value!=="?")return n;t++;let p=b();s(4,":");let l=b();return{type:1,left:p,right:l,condition:n,pos:e[t-1].pos}}let J=b();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 J}function H(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,o=`${r.whitespaceTrim}${r.closingTag}`,s=e.startsWith(t),c=e.endsWith(o),f=e.startsWith(s?t+r.commentTag:r.openingTag+r.commentTag),d=e.slice(s?t.length:r.openingTag.length,e.length-(c?o.length:r.closingTag.length));if(f)return{isComment:f,leftTrim:s,rightTrim:c,async:le.test(d)};let a=d.trim(),m=a.startsWith("for")||a.startsWith("if")||a.startsWith("else"),h=a.startsWith("for")||a.startsWith("if"),w=a==="end",E=a.startsWith("for");return{leftTrim:s,rightTrim:c,inner:d,isBlock:m,isBlockEnd:w,hasContext:E,requiresBlockClose:h,usesAwait:d.includes("Mutor::await")}}function Q(e){let r=0,t="",o=[];function s(){let a="";if(/[a-zA-Z$_]/.test(t)){let m=r;for(;/[a-zA-Z$_0-9]/.test(e[m])&&m<e.length;)a+=e[m],m++;o.push({type:ne.has(a)?1:0,value:a,pos:r}),r=m,t=e[r]}}function c(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let a=t,m=r,h=r+1,w="";for(;h<e.length;){let E=e[h];if(E==="\\"){if(h+1>=e.length)throw{pos:h,message:"Unexpected end of string after escape character."};w+=E,w+=e[h+1],h+=2;continue}if(E===a)break;w+=E,h++}if(h>=e.length||e[h]!==a)throw{pos:m,message:`String literal missing closing ${a}.`};o.push({type:3,value:w,pos:m}),r=h}function f(){if(/[0-9]/.test(t)){let a=r,m="";for(;/[0-9.oxe]/.test(e[a])&&a<e.length;)m+=e[a],a++;let h=Number(m);if(Number.isNaN(h))throw{pos:r,message:"Found invalid number literal."};o.push({type:2,value:`${h}`,pos:r}),r=a-1,t=e[r]}}function d(){let a=`${t}${e[r+1]}`;if(D.has(a)){o.push({type:4,value:a,pos:r}),r++;return}if(D.has(t)){o.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],f(),s(),c(),d(),!/[a-zA-Z$_0-9\s\t\r\n'"`]/.test(t)&&!D.has(t)&&!D.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return o.length?o:[{type:3,value:"",pos:0}]}function k(e,r,t){let o=[],s=[],{delimiters:c,keepOpeningTagEscapeDelimiter:f,allowFnCalls:d,allowedProps:a,forbiddenProps:m,autoEscape:h}=r,w="sync",E=!1,x=0,i='let acc="";';for(;x<e.length;){let O=function(){let y=g,S=0;for(;y>=c.openingTagEscape.length&&e.slice(y-c.openingTagEscape.length,y)===c.openingTagEscape;)S++,y-=c.openingTagEscape.length;return S%2===1};var R=O;let g=e.indexOf(c.openingTag,x);if(g===-1){let y=e.slice(x);E&&(y=y.trimStart()),y&&(i+=`acc+=\`${F(y)}\`;`);break}if(O()){let y=e.slice(x,f?g+c.openingTagEscape.length+1:g-c.openingTag.length+1);E&&(y=y.trimStart(),E=!1),i+=`acc+=\`${F(y)}\`;`,f||(i+=`acc+=\`${c.openingTag}\`;`),x=g+c.openingTag.length;continue}let N=e.indexOf(c.closingTag,g);if(N===-1){let[y,S]=W(e,g),I=z(e,S);throw new C("No closing tag found.",y,I,g,t.path)}let b=e.slice(g,N+c.closingTag.length),{async:J,inner:n,leftTrim:p,rightTrim:l,isBlock:P,isBlockEnd:M,hasContext:_,requiresBlockClose:ee,isComment:he,usesAwait:de}=H(b,{delimiters:c});if(de&&w!=="async")throw{pos:g,message:`Mutor::await() requires async mode.
12
- Add {{# 'use async' }} at the top of the template.`};let T=e.slice(x,g);T&&(E&&(T=T.trimStart()),p&&(T=T.trimEnd()),T&&(i+=`acc+=\`${F(T)}\`;`)),E=!1,x=N+c.closingTag.length;try{if(he)J&&(w="async");else{let y=Q(n),S=X(y,{allowFnCalls:d});if(P&&ee&&_?(o.push(S.variable),s.push({type:0,pos:g})):P&&ee&&!_&&s.push({type:1,pos:g}),M){let K=s.pop();if(K?.type===0&&o.pop(),K===void 0)throw{message:"Unexpected end of block",pos:g}}let I=v(S,{allowedProps:a,forbiddenProps:m,scope:o});P||M?i+=I:i+=h&&!I.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${I});`:`acc+=${I};`}l&&(E=!0)}catch(y){let{message:S,pos:I}=y,K=p?c.whitespaceTrim.length+c.openingTag.length:c.openingTag.length,te=g+I+K,[ye,re]=W(e,te),we=z(e,re);throw new C(S,ye,we,te-re,t.path)}}if(s.length){let g=s.pop()?.pos,[O,N]=W(e,g),b=z(e,N);throw new C("Unclosed block detected.",O,b,g-N,t.path)}return i+="return acc;",w==="async"?new fe("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",i)}var G=class{constructor(r={}){this.__cacheSize=0;this.__config={...A};this.__compiledTemplatesMap=new Map;this.__namespaces={...ue,Mutor:{await:async r=>await r}};this.addConfig(r)}addConfig(r){let{autoEscape:t,delimiters:o,allowedProps:s,forbiddenProps:c,keepOpeningTagEscapeDelimiter:f,allowFnCalls:d,cache:a,build:m,onIncludeFail:h,onIncludeError:w}=r;return this.__config={build:{include:new Set([...m?.include||A.build.include]),exclude:new Set([...A.build.exclude,...m?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:s||A.allowedProps,allowFnCalls:!!d,onIncludeFail:h||A.onIncludeFail,onIncludeError:w||A.onIncludeError,cache:{...A.cache,...a||{}},forbiddenProps:new Set([...A.forbiddenProps,...c||[]]),keepOpeningTagEscapeDelimiter:f===!0?!0:f!==!1,delimiters:{...A.delimiters,...o||{}}},this.__config}restoreDefaultConfig(){this.__config={...A}}compile(r,t){return k(r,this.__config,{path:t?.renderedPath||"anonymous"})}renderAsync(r,t){return new Promise(o=>{o(this.render(r,t))})}render(r,t){let o=$(t,"anonymous");return this.__renderWithRuntime(r,o)}__renderWithRuntime(r,t){return this.compile(r,t)(B(t.context),this.__createNamespacesWithRuntime(t),this.__config.allowedProps,this.__config.forbiddenProps,U,L)}__createNamespacesWithRuntime(r){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:r.context}}}handleError(r,t,o,s){if(this.__config.onIncludeFail==="throw")throw r instanceof C?r:new u(r.message);let c={from:t,path:o,absolutePath:s};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(r instanceof C?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[o,s]=t;this.__compiledTemplatesMap.delete(o),this.__cacheSize-=s.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 o=t.length*2+500;if(this.__cacheSize+o>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(o))throw new u(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let s=$(null,r);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t,s),size:o})}reset(){this.__config={...A},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var q=class extends G{constructor(r={}){super(r)}__setupIncludeForRuntime(r){this.__namespaces.Mutor.include=(t,o)=>{if(r.includeStack.has(t))throw new u(`Circular include detected.
14
- ${Array.from(r.includeStack).join(" -> ")} -> ${t}`);let s=r.renderedPath;r.includeStack.add(t),r.renderedPath=t;try{return this.__renderComponent(t,o??r.context,r)}catch(c){return this.handleError(c,s,t,void 0)}finally{r.includeStack.delete(t),r.renderedPath=s}}}render(r,t){let o=$(t,"anonymous");return this.__setupIncludeForRuntime(o),this.__renderWithRuntime(r,o)}renderAsync(r,t){return new Promise(o=>{o(this.render(r,t))})}__renderComponent(r,t,o){if(!this.__compiledTemplatesMap.has(r))throw new u(`No template exists with the identifier '${r}'`);let s=this.__compiledTemplatesMap.get(r),c=o.context,f=o.renderedPath;o.context=t??c,o.renderedPath=r;try{return s.fn(B(o.context),this.__createNamespacesWithRuntime(o),this.__config.allowedProps,this.__config.forbiddenProps,U,L)}finally{o.context=c,o.renderedPath=f}}renderComponent(r,t){return this.__renderComponent(r,t,$(t,r))}renderAsyncComponent(r,t){return new Promise(o=>{o(this.renderComponent(r,t))})}registerComponent(r,t){return this.register(r,t)}};var Nt=q;export{Nt as default};
9
+ `,r-1)+1;return[n,s]}function D(e,r){let t=e.indexOf(`
10
+ `,r);return e.slice(r,t===-1?void 0:t).replaceAll(" "," ")}function Ce(e,r){return e.scope.includes(r)?r:`ctx.${r}`}function Ie(e){if(e.left.type!==7)throw{message:"Invalid usage of namespace operator.",pos:e.pos};let r=e.left.value,t=e.right.value;return`namespaces.${r}.${t}`}function $e(e,r){let t=d(e,r.left),n=r.optional?"?.":"";if(r.bracketNotation){let o=d(e,r.right);return r.right.type===4||r.right.type===5?`${t}${n}[${o}]`:`${t}${n}[validateComputedProps(${o}, ${e.allowedProps}, ${e.forbiddenProps})]`}let s=r.right.value;if(e.forbiddenProps.has(s)&&!e.allowedProps.has(s))throw{message:"Forbidden property access.",pos:r.right.pos};return`${t}${n}.${s}`}function Fe(e,r){let t=d(e,r.expr),n=r.optional?"?.":"",s=r.args.map(o=>d(e,o)).join(", ");return`${t}${n}(${s})`}function Me(e,r){let{iterable:t,loopType:n,variable:s}=r,o=n===1?"in":"of";return`for(const ${s} ${o} ${T(t,e.context)}){`}function ve(e,r){let{condition:t}=r;return`if(${T(t,e.context)}){`}function De(e,r){let{condition:t}=r;return`}else if(${T(t,e.context)}){`}function d(e,r){let{type:t}=r;if(t===5)return r.value;if(t===12)return"null";if(t===11)return"undefined";if(t===10)return r.true?"true":"false";switch(t){case 17:return"}";case 4:return`\`${/\$\\/.test(r.value)?A(r.value):r.value}\``;case 7:return Ce(e,r.value);case 9:return`(${d(e,r.expr)})`;case 2:{let{operator:n,expr:s}=r;return`${n}${d(e,s)}`}case 0:{let{left:n,operator:s,right:o}=r;return`${d(e,n)} ${s} ${d(e,o)}`}case 1:{let{condition:n,left:s,right:o}=r;return`${d(e,n)} ? ${d(e,s)} : ${d(e,o)}`}case 8:return $e(e,r);case 3:return Fe(e,r);case 6:return Ie(r);case 13:return Me(e,r);case 16:return"} else {";case 14:return ve(e,r);case 15:return De(e,r);default:throw new i(`Unsupported expression type '${t}'`)}}function T(e,r){let t={scope:r.scope,forbiddenProps:r.forbiddenProps,allowedProps:r.allowedProps,context:r},n=d(t,e);return n.includes("namespaces.Mutor.await")?n.replaceAll("namespaces.Mutor.await","await namespaces.Mutor.await"):n}function B(e){switch(e){case 0:return"identifier";case 1:return"keyword";case 2:return"number";case 4:return"operator";case 3:return"string"}}function O(e,r,t){let n=e.tokens[e.cursor],s=e.tokens[e.tokens.length-1];if(!n)throw{message:`Unexpected end of expression. Expected ${t?`'${t}'`:`${r===0?"an":"a"} ${B(r)}`}.`,pos:s.pos+s.value.length-1};if(n.type!==r)throw{message:`Unexpected token type. Expected ${t?`'${t}'`:B(r)} but got ${B(n.type)} instead.`,pos:n.pos};if(t!==void 0&&n.value!==t)throw{message:`Unexpected token '${n.value}'. Expected ${r===0?"an":"a"} ${B(r)} instead.`,pos:n.pos};return e.tokens[e.cursor++]}function Be(e){let r=e.tokens[e.cursor-1].pos,t=O(e,0).value,n;try{n=O(e,1,"in")}catch{n=O(e,1,"of")}let s=n.value==="in"?1:0,o=w(e);return{type:13,loopType:s,iterable:o,variable:t,pos:r}}function Re(e){let r=w(e);return{condition:r,pos:r.pos,type:14}}function Le(e){let r=e.tokens[e.cursor-1].pos;try{return O(e,1,"if"),{...Re(e),type:15,pos:r}}catch{return{type:16,pos:r}}}function we(e){let r=[];if(e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===")")return r;for(r.push(w(e));e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value===",";)e.cursor++,r.push(w(e));return r}function G(e){let r=e.tokens[e.cursor++];if(!r)throw{message:"Unexpected end of expression.",pos:e.tokens[e.tokens.length-1].pos};if(r.type===2)return{type:5,value:r.value,pos:r.pos};if(r.type===3)return{type:4,value:r.value,pos:r.pos};if(r.type===1){if(r.value==="for"&&e.cursor===1)return Be(e);if(r.value==="true")return{type:10,true:!0,pos:r.pos};if(r.value==="false")return{type:10,true:!1,pos:r.pos};if(r.value==="undefined")return{type:11,pos:r.pos};if(r.value==="null")return{type:12,pos:r.pos};if(r.value==="end"&&e.tokens.length===1)return{type:17,pos:r.pos};if(r.value==="if"&&e.cursor===1)return Re(e);if(r.value==="else"&&e.cursor===1)return Le(e)}if(r.type===0)return{type:7,value:r.value,pos:r.pos};if(r.type===4&&r.value==="("){let t=w(e);return O(e,4,")"),{type:9,expr:t,pos:r.pos}}if(r.type===4&&me.has(r.value)){let t=w(e);return{type:2,operator:r.value,expr:t,pos:r.pos}}throw{message:`Unexpected token '${r.value}'.`,pos:r.pos}}function Ue(e){let r=G(e);for(;e.tokens[e.cursor];){let t=e.tokens[e.cursor];if(t?.type===4&&t?.value==="("){if(e.cursor++,!e.generatingNamespace&&!e.config.allowFnCalls)throw{message:"Function calls are not allowed.",pos:t.pos};let n=we(e);O(e,4,")"),r={type:3,expr:r,args:n,pos:e.tokens[e.cursor-1].pos}}else if(t?.type===4&&t?.value==="?."&&e.tokens[e.cursor+1]?.type===4&&e.tokens[e.cursor+1]?.value==="("){if(e.cursor+=2,!e.generatingNamespace&&!e.config.allowFnCalls)throw{message:"Function calls are not allowed.",pos:t.pos};let n=we(e);O(e,4,")"),r={type:3,expr:r,args:n,optional:!0,pos:e.tokens[e.cursor-1].pos}}else if(t?.type===4&&fe.has(t?.value)){let n=t.value==="::",s=t.value==="[",o=t.value==="?.";if(e.cursor++,n&&(e.tokens[e.cursor-2]?.type!==0||e.tokens[e.cursor]?.type!==0))throw{message:`Invalid namespaces access. Expected syntax <IDENTIFIER>::<IDENTIFIER>, but got '${e.tokens[e.cursor-2]?.value}::${e.tokens[e.cursor]?.value??""}' instead.`,pos:e.tokens[e.cursor]?.pos??e.tokens[e.cursor-1].pos};if(n){e.generatingNamespace=!0;let a=G(e);r={type:6,left:r,right:a,pos:e.tokens[e.cursor-1].pos}}else if(s){let a=w(e);O(e,4,"]"),r={type:8,left:r,right:a,bracketNotation:!0,pos:e.tokens[e.cursor-1].pos}}else if(o)if(e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="["){e.cursor++;let a=w(e);O(e,4,"]"),r={type:8,left:r,right:a,bracketNotation:!0,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let a=G(e);r={type:8,left:r,right:a,optional:!0,pos:e.tokens[e.cursor-1].pos}}else{let a=G(e);r={type:8,left:r,right:a,pos:e.tokens[e.cursor-1].pos}}}else break}return e.generatingNamespace=!1,r}function L(e,r,t){let n=r(e);for(;e.tokens[e.cursor]?.type===4&&t.has(e.tokens[e.cursor]?.value);){let s=e.tokens[e.cursor++].value,o=r(e);n={type:0,left:n,right:o,operator:s,pos:e.tokens[e.cursor-1].pos}}return n}function je(e){return L(e,Ue,le)}function We(e){return L(e,je,ue)}function ze(e){return L(e,We,V)}function Ye(e){return L(e,ze,V)}function Oe(e){return L(e,Ye,pe)}function xe(e){let r=Oe(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="&&";){e.cursor++;let t=Oe(e);r={type:0,left:r,right:t,operator:"&&",pos:e.tokens[e.cursor-1].pos}}return r}function be(e){let r=xe(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="||";){e.cursor++;let t=xe(e);r={type:0,left:r,right:t,operator:"||",pos:e.tokens[e.cursor-1].pos}}return r}function Ge(e){let r=be(e);for(;e.tokens[e.cursor]?.type===4&&e.tokens[e.cursor]?.value==="??";){e.cursor++;let t=be(e);r={type:0,left:r,right:t,operator:"??",pos:e.tokens[e.cursor-1].pos}}return r}function w(e){let r=Ge(e);if(e.tokens[e.cursor]?.type!==4||e.tokens[e.cursor]?.value!=="?")return r;e.cursor++;let t=w(e);O(e,4,":");let n=w(e);return{type:1,condition:r,left:t,right:n,pos:e.tokens[e.cursor-1].pos}}function Q(e,r){let t={cursor:0,tokens:e,config:r,generatingNamespace:!1},n=w(t);if(t.cursor!==t.tokens.length)throw{pos:t.tokens[t.cursor].pos,message:`Expected token '${t.tokens[t.cursor].value}'.
11
+ Expected an operator or the end of the expression.`};return n}function X(e,{delimiters:r}){let t=`${r.openingTag}${r.whitespaceTrim}`,n=`${r.whitespaceTrim}${r.closingTag}`,s=e.startsWith(t),o=e.endsWith(n),a=s?t.length:r.openingTag.length,h=o?n.length:r.closingTag.length,p=e.slice(a,e.length-h),u=p.trim(),l=u.startsWith(r.commentTag);return l?{isComment:l,leftTrim:s,rightTrim:o}:{leftTrim:s,rightTrim:o,inner:p,isBlock:u.startsWith("for")||u.startsWith("if")||u.startsWith("else"),isBlockEnd:u==="end",hasContext:u.startsWith("for"),requiresBlockClose:u.startsWith("for")||u.startsWith("if"),usesAwait:p.includes("Mutor::await")}}var qe=/[a-zA-Z$_]/,Ke=/[a-zA-Z$_0-9]/,Je=/[0-9]/,Ve=/[0-9.oxe]/,Ze=/[a-zA-Z$_0-9\s\t\r\n'"`]/;function ee(e){let r=0,t="",n=[];function s(){let p="";if(qe.test(t)){let u=r;for(;Ke.test(e[u])&&u<e.length;)p+=e[u],u++;n.push({type:ae.has(p)?1:0,value:p,pos:r}),r=u,t=e[r]}}function o(){if(t!=='"'&&t!=="'"&&t!=="`")return!1;let p=t,u=r,l=r+1,y="";for(;l<e.length;){let E=e[l];if(E==="\\"){if(l+1>=e.length)throw{pos:l,message:"Unexpected end of string after escape character."};y+=E,y+=e[l+1],l+=2;continue}if(E===p)break;y+=E,l++}if(l>=e.length||e[l]!==p)throw{pos:u,message:`String literal missing closing ${p}.`};n.push({type:3,value:y,pos:u}),r=l}function a(){if(Je.test(t)){let p=r,u="";for(;Ve.test(e[p])&&p<e.length;)u+=e[p],p++;let l=Number(u);if(Number.isNaN(l))throw{pos:r,message:"Found invalid number literal."};n.push({type:2,value:`${l}`,pos:r}),r=p-1,t=e[r]}}function h(){let p=`${t}${e[r+1]}`;if(C.has(p)){n.push({type:4,value:p,pos:r}),r++;return}if(C.has(t)){n.push({type:4,value:t,pos:r});return}}for(;r<e.length;){if(t=e[r],a(),s(),o(),h(),!Ze.test(t)&&!C.has(t)&&!C.has(e[r-1]+t))throw{message:`Unexpected token '${t}' in expression.`,pos:r};r++}return n.length?n:[{type:3,value:"",pos:0}]}function re(e,r,t){let n=[],s=[],{delimiters:o,keepOpeningTagEscapeDelimiter:a,allowFnCalls:h,allowedProps:p,forbiddenProps:u,autoEscape:l}=r,y="sync",E=!1,S=0,x='let acc="";';for(;S<e.length;){let W=function(){let f=m,b=0;for(;f>=o.openingTagEscape.length&&e.slice(f-o.openingTagEscape.length,f)===o.openingTagEscape;)b++,f-=o.openingTagEscape.length;return b%2===1};var He=W;let m=e.indexOf(o.openingTag,S);if(m===-1){let f=e.slice(S);E&&(f=f.trimStart()),f&&(x+=`acc+=\`${A(f)}\`;`);break}if(W()){let f=e.slice(S,a?m+o.openingTagEscape.length+1:m-o.openingTag.length+1);E&&(f=f.trimStart(),E=!1),x+=`acc+=\`${A(f)}\`;`,a||(x+=`acc+=\`${o.openingTag}\`;`),S=m+o.openingTag.length;continue}let c=e.indexOf(o.closingTag,m);if(c===-1){let[f,b]=v(e,m),P=D(e,b);throw new R("No closing tag found.",f,P,m,t.path)}let q=e.slice(m,c+o.closingTag.length),{inner:Pe,leftTrim:te,rightTrim:Se,isBlock:K,isBlockEnd:ne,hasContext:oe,requiresBlockClose:se,isComment:_e,usesAwait:Ne}=X(q,{delimiters:o});Ne&&y!=="async"&&(y="async");let _=e.slice(S,m);_&&(E&&(_=_.trimStart()),te&&(_=_.trimEnd()),_&&(x+=`acc+=\`${A(_)}\`;`)),E=!1,S=c+o.closingTag.length;try{if(!_e){let f=ee(Pe),b=Q(f,{allowFnCalls:h});if(K&&se&&oe?(n.push(b.variable),s.push({type:0,pos:m})):K&&se&&!oe&&s.push({type:1,pos:m}),ne){let z=s.pop();if(z?.type===0&&n.pop(),z===void 0)throw{message:"Unexpected end of block",pos:m}}let P=T(b,{allowedProps:p,forbiddenProps:u,scope:n});K||ne?x+=P:x+=l&&!P.startsWith("namespaces.Mutor.include")?`acc+=escapeFn(${P});`:`acc+=${P};`}Se&&(E=!0)}catch(f){let{message:b,pos:P}=f,z=te?o.whitespaceTrim.length+o.openingTag.length:o.openingTag.length,ie=m+P+z,[Ae,ce]=v(e,ie),ke=D(e,ce);throw new R(b,Ae,ke,ie-ce,t.path)}}if(s.length){let m=s.pop()?.pos,[W,c]=v(e,m),q=D(e,c);throw new R("Unclosed block detected.",W,q,m-c,t.path)}return x+="return acc;",y==="async"?new he("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",x):new Function("ctx","namespaces","allowedProps","forbiddenProps","escapeFn","validateComputedProps",x)}var U=class{constructor(r={}){this.__cacheSize=0;this.__config={...g};this.__compiledTemplatesMap=new Map;this.__namespaces={...de,Mutor:{await:async r=>await r}};this.addConfig(r)}addConfig(r){let{autoEscape:t,delimiters:n,allowedProps:s,forbiddenProps:o,keepOpeningTagEscapeDelimiter:a,allowFnCalls:h,cache:p,build:u,onIncludeFail:l,onIncludeError:y}=r;return this.__config={build:{include:new Set([...u?.include||g.build.include]),exclude:new Set([...g.build.exclude,...u?.exclude||[]])},autoEscape:t===!0?!0:t!==!1,allowedProps:s||g.allowedProps,allowFnCalls:!!h,onIncludeFail:l||g.onIncludeFail,onIncludeError:y||g.onIncludeError,cache:{...g.cache,...p||{}},forbiddenProps:new Set([...g.forbiddenProps,...o||[]]),keepOpeningTagEscapeDelimiter:a===!0?!0:a!==!1,delimiters:{...g.delimiters,...n||{}}},this.__config}restoreDefaultConfig(){this.__config={...g}}compile(r,t){return re(r,this.__config,{path:t?.renderedPath||"anonymous"})}renderAsync(r,t){return new Promise(n=>{n(this.render(r,t))})}render(r,t){let n=N(t,"anonymous");return this.__renderWithRuntime(r,n)}__renderWithRuntime(r,t){return this.compile(r,t)(M(t.context),this.__createNamespacesWithRuntime(t),this.__config.allowedProps,this.__config.forbiddenProps,I,$)}__createNamespacesWithRuntime(r){return{...this.__namespaces,Mutor:{...this.__namespaces.Mutor,$$context:r.context}}}handleError(r,t,n,s){if(this.__config.onIncludeFail==="throw")throw r instanceof R?r:new i(r.message);let o={from:t,path:n,absolutePath:s};return this.__config.onIncludeFail==="ignoreLog"&&!this.__config.onIncludeError&&(r instanceof R?console.log(r):console.log(`[Mutor.js]
12
+ ${r.message}`)),this.__config.onIncludeError?.(o,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[n,s]=t;this.__compiledTemplatesMap.delete(n),this.__cacheSize-=s.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 n=t.length*2+500;if(this.__cacheSize+n>this.__config.cache.maxSize&&!this.createEntrySpaceForTemplate(n))throw new i(`The template for the component '${r}' is too large and will not fit in the cache. Consider increasing 'cache.maxSize' in the config`);let s=N(null,r);this.__cacheSize+=t.length*2+500,this.__compiledTemplatesMap.set(r,{fn:this.compile(t,s),size:n})}reset(){this.__config={...g},this.__compiledTemplatesMap.clear(),this.__cacheSize=0}};var j=class extends U{constructor(r={}){super(r)}__setupIncludeForRuntime(r){this.__namespaces.Mutor.include=(t,n)=>{if(r.includeStack.has(t))throw new i(`Circular include detected.
13
+ ${Array.from(r.includeStack).join(" -> ")} -> ${t}`);let s=r.renderedPath;r.includeStack.add(t),r.renderedPath=t;try{return this.__renderComponent(t,n??r.context,r)}catch(o){return this.handleError(o,s,t,void 0)}finally{r.includeStack.delete(t),r.renderedPath=s}}}render(r,t){let n=N(t,"anonymous");return this.__setupIncludeForRuntime(n),this.__renderWithRuntime(r,n)}renderAsync(r,t){return new Promise(n=>{n(this.render(r,t))})}__renderComponent(r,t,n){if(!this.__compiledTemplatesMap.has(r))throw new i(`No template exists with the identifier '${r}'`);let s=this.__compiledTemplatesMap.get(r),o=n.context,a=n.renderedPath;n.context=t??o,n.renderedPath=r;try{return s.fn(M(n.context),this.__createNamespacesWithRuntime(n),this.__config.allowedProps,this.__config.forbiddenProps,I,$)}finally{n.context=o,n.renderedPath=a}}renderComponent(r,t){return this.__renderComponent(r,t,N(t,r))}renderAsyncComponent(r,t){return new Promise(n=>{n(this.renderComponent(r,t))})}registerComponent(r,t){return this.register(r,t)}};var rt=j;export{Ee as BlockType,Z as ExprType,H as LoopType,Y as TokenType,rt as default};
15
14
  //# sourceMappingURL=index.js.map