janja 4.2.0 → 4.3.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/index.cjs +106 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +106 -34
- package/dist/index.js +106 -34
- package/dist/index.min.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -344,6 +344,9 @@ const WRITE = 'w';
|
|
|
344
344
|
const UNKNOWN_FILTER = 'u_';
|
|
345
345
|
// Holds the result of a filter call while checking whether to await it
|
|
346
346
|
const RESULT = 'r_';
|
|
347
|
+
// Top-level render context; plain include always receives this, even when
|
|
348
|
+
// nested inside a for/with or an `include … with` partial.
|
|
349
|
+
const TOP_CONTEXT = 'tc_';
|
|
347
350
|
|
|
348
351
|
/**
|
|
349
352
|
* Contains the source map information.
|
|
@@ -611,6 +614,7 @@ const expTokenTypes = {
|
|
|
611
614
|
in: 'IN',
|
|
612
615
|
ni: 'NI',
|
|
613
616
|
of: 'OF',
|
|
617
|
+
with: 'WITH',
|
|
614
618
|
'+': 'ADD',
|
|
615
619
|
'-': 'SUB',
|
|
616
620
|
'*': 'MUL',
|
|
@@ -902,6 +906,7 @@ const expTokenPrecedences = {
|
|
|
902
906
|
IN: 40,
|
|
903
907
|
NI: 40,
|
|
904
908
|
OF: 40,
|
|
909
|
+
WITH: 40,
|
|
905
910
|
ADD: 50,
|
|
906
911
|
SUB: 50,
|
|
907
912
|
MUL: 60,
|
|
@@ -1049,36 +1054,12 @@ class ExpParser {
|
|
|
1049
1054
|
}
|
|
1050
1055
|
continue;
|
|
1051
1056
|
}
|
|
1052
|
-
if (token.type
|
|
1053
|
-
token.type === 'OR' ||
|
|
1054
|
-
token.type === 'IS' ||
|
|
1055
|
-
token.type === 'EQ' ||
|
|
1056
|
-
token.type === 'NE' ||
|
|
1057
|
-
token.type === 'GT' ||
|
|
1058
|
-
token.type === 'LT' ||
|
|
1059
|
-
token.type === 'GE' ||
|
|
1060
|
-
token.type === 'LE' ||
|
|
1061
|
-
token.type === 'IN' ||
|
|
1062
|
-
token.type === 'NI' ||
|
|
1063
|
-
token.type === 'OF' ||
|
|
1064
|
-
token.type === 'ADD' ||
|
|
1065
|
-
token.type === 'SUB' ||
|
|
1066
|
-
token.type === 'MUL' ||
|
|
1067
|
-
token.type === 'DIV' ||
|
|
1068
|
-
token.type === 'MOD' ||
|
|
1069
|
-
token.type === 'ASSIGN') {
|
|
1057
|
+
if (isBinaryOp(token.type)) {
|
|
1070
1058
|
if (!left) {
|
|
1071
1059
|
throw new ExpError(`No left operand for "${token.type}"`, token.loc);
|
|
1072
1060
|
}
|
|
1073
1061
|
if (token.type === 'ASSIGN') {
|
|
1074
|
-
|
|
1075
|
-
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1076
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1080
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1081
|
-
}
|
|
1062
|
+
assertAssignableLeft(left, token);
|
|
1082
1063
|
}
|
|
1083
1064
|
const right = this.parseExp((t) => isHigher(token, t) ? 'BACK' : undefined);
|
|
1084
1065
|
if (!right) {
|
|
@@ -1181,12 +1162,46 @@ class ExpParser {
|
|
|
1181
1162
|
}
|
|
1182
1163
|
}
|
|
1183
1164
|
}
|
|
1165
|
+
const BINARY_OPS = new Set([
|
|
1166
|
+
'AND',
|
|
1167
|
+
'OR',
|
|
1168
|
+
'IS',
|
|
1169
|
+
'EQ',
|
|
1170
|
+
'NE',
|
|
1171
|
+
'GT',
|
|
1172
|
+
'LT',
|
|
1173
|
+
'GE',
|
|
1174
|
+
'LE',
|
|
1175
|
+
'IN',
|
|
1176
|
+
'NI',
|
|
1177
|
+
'OF',
|
|
1178
|
+
'WITH',
|
|
1179
|
+
'ADD',
|
|
1180
|
+
'SUB',
|
|
1181
|
+
'MUL',
|
|
1182
|
+
'DIV',
|
|
1183
|
+
'MOD',
|
|
1184
|
+
'ASSIGN',
|
|
1185
|
+
]);
|
|
1186
|
+
function isBinaryOp(type) {
|
|
1187
|
+
return BINARY_OPS.has(type);
|
|
1188
|
+
}
|
|
1184
1189
|
// Two operands in a row, e.g. `a b`
|
|
1185
1190
|
function assertNotOperand(token) {
|
|
1186
1191
|
if (token.type === 'ID' || token.type === 'LIT' || token.type === 'LP') {
|
|
1187
1192
|
throw new ExpError(`Unexpected "${token.raw ?? token.value}"`, token.loc);
|
|
1188
1193
|
}
|
|
1189
1194
|
}
|
|
1195
|
+
function assertAssignableLeft(left, token) {
|
|
1196
|
+
if (left.type === 'SEQ') {
|
|
1197
|
+
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1198
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1202
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1190
1205
|
function isHigher(a, b) {
|
|
1191
1206
|
// "(" starts an operand; it is not an operator to compare against
|
|
1192
1207
|
if (b.type === 'LP') {
|
|
@@ -1933,9 +1948,13 @@ class Compiler extends Context {
|
|
|
1933
1948
|
if (this.isRoot) {
|
|
1934
1949
|
if (this.partials.size) {
|
|
1935
1950
|
const { maxIncludeDepth } = resolveSecurityLimits(this.options.security);
|
|
1936
|
-
|
|
1951
|
+
// Alias the render data before partials shadow `c` with their argument.
|
|
1952
|
+
this.pushRaw(null, `const ${TOP_CONTEXT}=${CONTEXT};`, 'let d_=0;', 'const p={');
|
|
1937
1953
|
for (const [path, code] of this.partials) {
|
|
1938
|
-
this.pushRaw(null,
|
|
1954
|
+
this.pushRaw(null,
|
|
1955
|
+
// Partials take the context they should render with: plain include
|
|
1956
|
+
// passes the top-level `tc_`; `include … with` passes a merged scope.
|
|
1957
|
+
`${JSON.stringify(path)}:async(c)=>{`, `if(d_>=${maxIncludeDepth})throw new Error(${JSON.stringify(`Includes of ${JSON.stringify(path)} are nested too deeply`)});`, 'd_++;', 'try{return await(async()=>{', code, '})();}finally{d_--;}', '},');
|
|
1939
1958
|
}
|
|
1940
1959
|
this.pushRaw(null, '};');
|
|
1941
1960
|
}
|
|
@@ -2652,6 +2671,7 @@ const expTokenOperators$1 = {
|
|
|
2652
2671
|
IN: ' in ',
|
|
2653
2672
|
NI: ' in ',
|
|
2654
2673
|
OF: ' of ',
|
|
2674
|
+
WITH: ' with ',
|
|
2655
2675
|
ADD: '+',
|
|
2656
2676
|
SUB: '-',
|
|
2657
2677
|
MUL: '*',
|
|
@@ -3537,15 +3557,23 @@ const plugin$9 = {
|
|
|
3537
3557
|
parsers: parsers$9,
|
|
3538
3558
|
};
|
|
3539
3559
|
|
|
3540
|
-
async function compileInclude({ val: { value }, loc }, compiler) {
|
|
3541
|
-
|
|
3560
|
+
async function compileInclude({ val: { value }, loc, withExp }, compiler) {
|
|
3561
|
+
const path = JSON.stringify(value);
|
|
3562
|
+
if (withExp) {
|
|
3563
|
+
const expCompiler = new ExpCompiler();
|
|
3564
|
+
const merged = `{...${compiler.context},...${expCompiler.compile(withExp, compiler.context)}}`;
|
|
3565
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${merged})??"";`);
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
// Plain include always sees the top-level context, not loop/with scopes.
|
|
3569
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${TOP_CONTEXT})??"";`);
|
|
3542
3570
|
}
|
|
3543
3571
|
const compilers$8 = {
|
|
3544
3572
|
INCLUDE: compileInclude,
|
|
3545
3573
|
};
|
|
3546
3574
|
|
|
3547
3575
|
class IncludeNode extends Traversal {
|
|
3548
|
-
constructor(val, loc, strip) {
|
|
3576
|
+
constructor(val, loc, strip, withExp = null) {
|
|
3549
3577
|
super();
|
|
3550
3578
|
Object.defineProperty(this, "val", {
|
|
3551
3579
|
enumerable: true,
|
|
@@ -3565,6 +3593,12 @@ class IncludeNode extends Traversal {
|
|
|
3565
3593
|
writable: true,
|
|
3566
3594
|
value: strip
|
|
3567
3595
|
});
|
|
3596
|
+
Object.defineProperty(this, "withExp", {
|
|
3597
|
+
enumerable: true,
|
|
3598
|
+
configurable: true,
|
|
3599
|
+
writable: true,
|
|
3600
|
+
value: withExp
|
|
3601
|
+
});
|
|
3568
3602
|
Object.defineProperty(this, "type", {
|
|
3569
3603
|
enumerable: true,
|
|
3570
3604
|
configurable: true,
|
|
@@ -3574,13 +3608,31 @@ class IncludeNode extends Traversal {
|
|
|
3574
3608
|
}
|
|
3575
3609
|
}
|
|
3576
3610
|
|
|
3611
|
+
function isStringLit(exp) {
|
|
3612
|
+
return exp.type === 'LIT' && typeof exp.value === 'string';
|
|
3613
|
+
}
|
|
3577
3614
|
function* parseInclude(token, parser) {
|
|
3578
3615
|
if (!token.expression) {
|
|
3579
3616
|
parser.emitExpErr(token);
|
|
3580
3617
|
return;
|
|
3581
3618
|
}
|
|
3582
3619
|
yield 'NEXT';
|
|
3583
|
-
|
|
3620
|
+
const exp = parser.parseExp(token.expression);
|
|
3621
|
+
if (!exp) {
|
|
3622
|
+
return;
|
|
3623
|
+
}
|
|
3624
|
+
if (isStringLit(exp)) {
|
|
3625
|
+
yield new IncludeNode(exp, token.loc, token.strip);
|
|
3626
|
+
return;
|
|
3627
|
+
}
|
|
3628
|
+
if (exp.type === 'WITH') {
|
|
3629
|
+
const { left, right } = exp;
|
|
3630
|
+
if (isStringLit(left)) {
|
|
3631
|
+
yield new IncludeNode(left, token.loc, token.strip, right);
|
|
3632
|
+
return;
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
parser.options.debug?.(new CompileError('"include" expects "path" or "path" with expr', parser.template, token.loc));
|
|
3584
3636
|
}
|
|
3585
3637
|
const parsers$8 = {
|
|
3586
3638
|
include: parseInclude,
|
|
@@ -4616,6 +4668,9 @@ class Analyzer {
|
|
|
4616
4668
|
await this.nodes(node.body, scope);
|
|
4617
4669
|
break;
|
|
4618
4670
|
case 'INCLUDE':
|
|
4671
|
+
if (node.withExp) {
|
|
4672
|
+
this.exp(node.withExp, scope);
|
|
4673
|
+
}
|
|
4619
4674
|
await this.include(node.val.value, scope);
|
|
4620
4675
|
break;
|
|
4621
4676
|
default:
|
|
@@ -5298,6 +5353,7 @@ const expTokenOperators = {
|
|
|
5298
5353
|
IN: 'in',
|
|
5299
5354
|
NI: 'ni',
|
|
5300
5355
|
OF: 'of',
|
|
5356
|
+
WITH: 'with',
|
|
5301
5357
|
ADD: '+',
|
|
5302
5358
|
SUB: '-',
|
|
5303
5359
|
MUL: '*',
|
|
@@ -5338,6 +5394,7 @@ class ExpFormatter {
|
|
|
5338
5394
|
case 'IN':
|
|
5339
5395
|
case 'NI':
|
|
5340
5396
|
case 'OF':
|
|
5397
|
+
case 'WITH':
|
|
5341
5398
|
case 'ADD':
|
|
5342
5399
|
case 'SUB':
|
|
5343
5400
|
case 'MUL':
|
|
@@ -5408,6 +5465,8 @@ const DIR_OPEN = new Set([
|
|
|
5408
5465
|
'with',
|
|
5409
5466
|
'stylesheet',
|
|
5410
5467
|
]);
|
|
5468
|
+
/** Directives whose bodies keep leading whitespace (like `<style>`). */
|
|
5469
|
+
const DIR_SENSITIVE = new Set(['stylesheet']);
|
|
5411
5470
|
const DIR_MID = new Set(['else', 'elif', 'elseif', 'elsif']);
|
|
5412
5471
|
const DIR_CLOSE = new Set([
|
|
5413
5472
|
'endif',
|
|
@@ -5542,13 +5601,26 @@ function readDirective(line, start, options) {
|
|
|
5542
5601
|
return { end };
|
|
5543
5602
|
}
|
|
5544
5603
|
if (DIR_CLOSE.has(name)) {
|
|
5545
|
-
|
|
5604
|
+
const base = name.startsWith('end') ? name.slice(3) : name;
|
|
5605
|
+
return {
|
|
5606
|
+
end,
|
|
5607
|
+
piece: {
|
|
5608
|
+
kind: 'close',
|
|
5609
|
+
sensitive: DIR_SENSITIVE.has(base) ? base : undefined,
|
|
5610
|
+
},
|
|
5611
|
+
};
|
|
5546
5612
|
}
|
|
5547
5613
|
if (DIR_MID.has(name)) {
|
|
5548
5614
|
return { end, piece: { kind: 'mid' } };
|
|
5549
5615
|
}
|
|
5550
5616
|
if (DIR_OPEN.has(name)) {
|
|
5551
|
-
return {
|
|
5617
|
+
return {
|
|
5618
|
+
end,
|
|
5619
|
+
piece: {
|
|
5620
|
+
kind: 'open',
|
|
5621
|
+
sensitive: DIR_SENSITIVE.has(name) ? name : undefined,
|
|
5622
|
+
},
|
|
5623
|
+
};
|
|
5552
5624
|
}
|
|
5553
5625
|
return { end };
|
|
5554
5626
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -99,7 +99,7 @@ declare class Context extends OutScript {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
type UnaryExpTokenType = 'NOT';
|
|
102
|
-
type BinaryExpTokenType = 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'ASSIGN';
|
|
102
|
+
type BinaryExpTokenType = 'AND' | 'OR' | 'IS' | 'EQ' | 'NE' | 'GT' | 'LT' | 'GE' | 'LE' | 'IN' | 'NI' | 'OF' | 'WITH' | 'ADD' | 'SUB' | 'MUL' | 'DIV' | 'MOD' | 'PIPE' | 'ASSIGN';
|
|
103
103
|
type TernaryExpTokenType = 'IF' | 'ELSE';
|
|
104
104
|
type ExpTokenType = UnaryExpTokenType | BinaryExpTokenType | TernaryExpTokenType | 'LP' | 'RP' | 'COMMA' | 'DOT' | 'ID' | 'LIT';
|
|
105
105
|
type UnaryExpType = UnaryExpTokenType;
|
package/dist/index.esm.js
CHANGED
|
@@ -342,6 +342,9 @@ const WRITE = 'w';
|
|
|
342
342
|
const UNKNOWN_FILTER = 'u_';
|
|
343
343
|
// Holds the result of a filter call while checking whether to await it
|
|
344
344
|
const RESULT = 'r_';
|
|
345
|
+
// Top-level render context; plain include always receives this, even when
|
|
346
|
+
// nested inside a for/with or an `include … with` partial.
|
|
347
|
+
const TOP_CONTEXT = 'tc_';
|
|
345
348
|
|
|
346
349
|
/**
|
|
347
350
|
* Contains the source map information.
|
|
@@ -609,6 +612,7 @@ const expTokenTypes = {
|
|
|
609
612
|
in: 'IN',
|
|
610
613
|
ni: 'NI',
|
|
611
614
|
of: 'OF',
|
|
615
|
+
with: 'WITH',
|
|
612
616
|
'+': 'ADD',
|
|
613
617
|
'-': 'SUB',
|
|
614
618
|
'*': 'MUL',
|
|
@@ -900,6 +904,7 @@ const expTokenPrecedences = {
|
|
|
900
904
|
IN: 40,
|
|
901
905
|
NI: 40,
|
|
902
906
|
OF: 40,
|
|
907
|
+
WITH: 40,
|
|
903
908
|
ADD: 50,
|
|
904
909
|
SUB: 50,
|
|
905
910
|
MUL: 60,
|
|
@@ -1047,36 +1052,12 @@ class ExpParser {
|
|
|
1047
1052
|
}
|
|
1048
1053
|
continue;
|
|
1049
1054
|
}
|
|
1050
|
-
if (token.type
|
|
1051
|
-
token.type === 'OR' ||
|
|
1052
|
-
token.type === 'IS' ||
|
|
1053
|
-
token.type === 'EQ' ||
|
|
1054
|
-
token.type === 'NE' ||
|
|
1055
|
-
token.type === 'GT' ||
|
|
1056
|
-
token.type === 'LT' ||
|
|
1057
|
-
token.type === 'GE' ||
|
|
1058
|
-
token.type === 'LE' ||
|
|
1059
|
-
token.type === 'IN' ||
|
|
1060
|
-
token.type === 'NI' ||
|
|
1061
|
-
token.type === 'OF' ||
|
|
1062
|
-
token.type === 'ADD' ||
|
|
1063
|
-
token.type === 'SUB' ||
|
|
1064
|
-
token.type === 'MUL' ||
|
|
1065
|
-
token.type === 'DIV' ||
|
|
1066
|
-
token.type === 'MOD' ||
|
|
1067
|
-
token.type === 'ASSIGN') {
|
|
1055
|
+
if (isBinaryOp(token.type)) {
|
|
1068
1056
|
if (!left) {
|
|
1069
1057
|
throw new ExpError(`No left operand for "${token.type}"`, token.loc);
|
|
1070
1058
|
}
|
|
1071
1059
|
if (token.type === 'ASSIGN') {
|
|
1072
|
-
|
|
1073
|
-
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1074
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1078
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1079
|
-
}
|
|
1060
|
+
assertAssignableLeft(left, token);
|
|
1080
1061
|
}
|
|
1081
1062
|
const right = this.parseExp((t) => isHigher(token, t) ? 'BACK' : undefined);
|
|
1082
1063
|
if (!right) {
|
|
@@ -1179,12 +1160,46 @@ class ExpParser {
|
|
|
1179
1160
|
}
|
|
1180
1161
|
}
|
|
1181
1162
|
}
|
|
1163
|
+
const BINARY_OPS = new Set([
|
|
1164
|
+
'AND',
|
|
1165
|
+
'OR',
|
|
1166
|
+
'IS',
|
|
1167
|
+
'EQ',
|
|
1168
|
+
'NE',
|
|
1169
|
+
'GT',
|
|
1170
|
+
'LT',
|
|
1171
|
+
'GE',
|
|
1172
|
+
'LE',
|
|
1173
|
+
'IN',
|
|
1174
|
+
'NI',
|
|
1175
|
+
'OF',
|
|
1176
|
+
'WITH',
|
|
1177
|
+
'ADD',
|
|
1178
|
+
'SUB',
|
|
1179
|
+
'MUL',
|
|
1180
|
+
'DIV',
|
|
1181
|
+
'MOD',
|
|
1182
|
+
'ASSIGN',
|
|
1183
|
+
]);
|
|
1184
|
+
function isBinaryOp(type) {
|
|
1185
|
+
return BINARY_OPS.has(type);
|
|
1186
|
+
}
|
|
1182
1187
|
// Two operands in a row, e.g. `a b`
|
|
1183
1188
|
function assertNotOperand(token) {
|
|
1184
1189
|
if (token.type === 'ID' || token.type === 'LIT' || token.type === 'LP') {
|
|
1185
1190
|
throw new ExpError(`Unexpected "${token.raw ?? token.value}"`, token.loc);
|
|
1186
1191
|
}
|
|
1187
1192
|
}
|
|
1193
|
+
function assertAssignableLeft(left, token) {
|
|
1194
|
+
if (left.type === 'SEQ') {
|
|
1195
|
+
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1196
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1200
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1188
1203
|
function isHigher(a, b) {
|
|
1189
1204
|
// "(" starts an operand; it is not an operator to compare against
|
|
1190
1205
|
if (b.type === 'LP') {
|
|
@@ -1931,9 +1946,13 @@ class Compiler extends Context {
|
|
|
1931
1946
|
if (this.isRoot) {
|
|
1932
1947
|
if (this.partials.size) {
|
|
1933
1948
|
const { maxIncludeDepth } = resolveSecurityLimits(this.options.security);
|
|
1934
|
-
|
|
1949
|
+
// Alias the render data before partials shadow `c` with their argument.
|
|
1950
|
+
this.pushRaw(null, `const ${TOP_CONTEXT}=${CONTEXT};`, 'let d_=0;', 'const p={');
|
|
1935
1951
|
for (const [path, code] of this.partials) {
|
|
1936
|
-
this.pushRaw(null,
|
|
1952
|
+
this.pushRaw(null,
|
|
1953
|
+
// Partials take the context they should render with: plain include
|
|
1954
|
+
// passes the top-level `tc_`; `include … with` passes a merged scope.
|
|
1955
|
+
`${JSON.stringify(path)}:async(c)=>{`, `if(d_>=${maxIncludeDepth})throw new Error(${JSON.stringify(`Includes of ${JSON.stringify(path)} are nested too deeply`)});`, 'd_++;', 'try{return await(async()=>{', code, '})();}finally{d_--;}', '},');
|
|
1937
1956
|
}
|
|
1938
1957
|
this.pushRaw(null, '};');
|
|
1939
1958
|
}
|
|
@@ -2650,6 +2669,7 @@ const expTokenOperators$1 = {
|
|
|
2650
2669
|
IN: ' in ',
|
|
2651
2670
|
NI: ' in ',
|
|
2652
2671
|
OF: ' of ',
|
|
2672
|
+
WITH: ' with ',
|
|
2653
2673
|
ADD: '+',
|
|
2654
2674
|
SUB: '-',
|
|
2655
2675
|
MUL: '*',
|
|
@@ -3535,15 +3555,23 @@ const plugin$9 = {
|
|
|
3535
3555
|
parsers: parsers$9,
|
|
3536
3556
|
};
|
|
3537
3557
|
|
|
3538
|
-
async function compileInclude({ val: { value }, loc }, compiler) {
|
|
3539
|
-
|
|
3558
|
+
async function compileInclude({ val: { value }, loc, withExp }, compiler) {
|
|
3559
|
+
const path = JSON.stringify(value);
|
|
3560
|
+
if (withExp) {
|
|
3561
|
+
const expCompiler = new ExpCompiler();
|
|
3562
|
+
const merged = `{...${compiler.context},...${expCompiler.compile(withExp, compiler.context)}}`;
|
|
3563
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${merged})??"";`);
|
|
3564
|
+
return;
|
|
3565
|
+
}
|
|
3566
|
+
// Plain include always sees the top-level context, not loop/with scopes.
|
|
3567
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${TOP_CONTEXT})??"";`);
|
|
3540
3568
|
}
|
|
3541
3569
|
const compilers$8 = {
|
|
3542
3570
|
INCLUDE: compileInclude,
|
|
3543
3571
|
};
|
|
3544
3572
|
|
|
3545
3573
|
class IncludeNode extends Traversal {
|
|
3546
|
-
constructor(val, loc, strip) {
|
|
3574
|
+
constructor(val, loc, strip, withExp = null) {
|
|
3547
3575
|
super();
|
|
3548
3576
|
Object.defineProperty(this, "val", {
|
|
3549
3577
|
enumerable: true,
|
|
@@ -3563,6 +3591,12 @@ class IncludeNode extends Traversal {
|
|
|
3563
3591
|
writable: true,
|
|
3564
3592
|
value: strip
|
|
3565
3593
|
});
|
|
3594
|
+
Object.defineProperty(this, "withExp", {
|
|
3595
|
+
enumerable: true,
|
|
3596
|
+
configurable: true,
|
|
3597
|
+
writable: true,
|
|
3598
|
+
value: withExp
|
|
3599
|
+
});
|
|
3566
3600
|
Object.defineProperty(this, "type", {
|
|
3567
3601
|
enumerable: true,
|
|
3568
3602
|
configurable: true,
|
|
@@ -3572,13 +3606,31 @@ class IncludeNode extends Traversal {
|
|
|
3572
3606
|
}
|
|
3573
3607
|
}
|
|
3574
3608
|
|
|
3609
|
+
function isStringLit(exp) {
|
|
3610
|
+
return exp.type === 'LIT' && typeof exp.value === 'string';
|
|
3611
|
+
}
|
|
3575
3612
|
function* parseInclude(token, parser) {
|
|
3576
3613
|
if (!token.expression) {
|
|
3577
3614
|
parser.emitExpErr(token);
|
|
3578
3615
|
return;
|
|
3579
3616
|
}
|
|
3580
3617
|
yield 'NEXT';
|
|
3581
|
-
|
|
3618
|
+
const exp = parser.parseExp(token.expression);
|
|
3619
|
+
if (!exp) {
|
|
3620
|
+
return;
|
|
3621
|
+
}
|
|
3622
|
+
if (isStringLit(exp)) {
|
|
3623
|
+
yield new IncludeNode(exp, token.loc, token.strip);
|
|
3624
|
+
return;
|
|
3625
|
+
}
|
|
3626
|
+
if (exp.type === 'WITH') {
|
|
3627
|
+
const { left, right } = exp;
|
|
3628
|
+
if (isStringLit(left)) {
|
|
3629
|
+
yield new IncludeNode(left, token.loc, token.strip, right);
|
|
3630
|
+
return;
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
parser.options.debug?.(new CompileError('"include" expects "path" or "path" with expr', parser.template, token.loc));
|
|
3582
3634
|
}
|
|
3583
3635
|
const parsers$8 = {
|
|
3584
3636
|
include: parseInclude,
|
|
@@ -4614,6 +4666,9 @@ class Analyzer {
|
|
|
4614
4666
|
await this.nodes(node.body, scope);
|
|
4615
4667
|
break;
|
|
4616
4668
|
case 'INCLUDE':
|
|
4669
|
+
if (node.withExp) {
|
|
4670
|
+
this.exp(node.withExp, scope);
|
|
4671
|
+
}
|
|
4617
4672
|
await this.include(node.val.value, scope);
|
|
4618
4673
|
break;
|
|
4619
4674
|
default:
|
|
@@ -5296,6 +5351,7 @@ const expTokenOperators = {
|
|
|
5296
5351
|
IN: 'in',
|
|
5297
5352
|
NI: 'ni',
|
|
5298
5353
|
OF: 'of',
|
|
5354
|
+
WITH: 'with',
|
|
5299
5355
|
ADD: '+',
|
|
5300
5356
|
SUB: '-',
|
|
5301
5357
|
MUL: '*',
|
|
@@ -5336,6 +5392,7 @@ class ExpFormatter {
|
|
|
5336
5392
|
case 'IN':
|
|
5337
5393
|
case 'NI':
|
|
5338
5394
|
case 'OF':
|
|
5395
|
+
case 'WITH':
|
|
5339
5396
|
case 'ADD':
|
|
5340
5397
|
case 'SUB':
|
|
5341
5398
|
case 'MUL':
|
|
@@ -5406,6 +5463,8 @@ const DIR_OPEN = new Set([
|
|
|
5406
5463
|
'with',
|
|
5407
5464
|
'stylesheet',
|
|
5408
5465
|
]);
|
|
5466
|
+
/** Directives whose bodies keep leading whitespace (like `<style>`). */
|
|
5467
|
+
const DIR_SENSITIVE = new Set(['stylesheet']);
|
|
5409
5468
|
const DIR_MID = new Set(['else', 'elif', 'elseif', 'elsif']);
|
|
5410
5469
|
const DIR_CLOSE = new Set([
|
|
5411
5470
|
'endif',
|
|
@@ -5540,13 +5599,26 @@ function readDirective(line, start, options) {
|
|
|
5540
5599
|
return { end };
|
|
5541
5600
|
}
|
|
5542
5601
|
if (DIR_CLOSE.has(name)) {
|
|
5543
|
-
|
|
5602
|
+
const base = name.startsWith('end') ? name.slice(3) : name;
|
|
5603
|
+
return {
|
|
5604
|
+
end,
|
|
5605
|
+
piece: {
|
|
5606
|
+
kind: 'close',
|
|
5607
|
+
sensitive: DIR_SENSITIVE.has(base) ? base : undefined,
|
|
5608
|
+
},
|
|
5609
|
+
};
|
|
5544
5610
|
}
|
|
5545
5611
|
if (DIR_MID.has(name)) {
|
|
5546
5612
|
return { end, piece: { kind: 'mid' } };
|
|
5547
5613
|
}
|
|
5548
5614
|
if (DIR_OPEN.has(name)) {
|
|
5549
|
-
return {
|
|
5615
|
+
return {
|
|
5616
|
+
end,
|
|
5617
|
+
piece: {
|
|
5618
|
+
kind: 'open',
|
|
5619
|
+
sensitive: DIR_SENSITIVE.has(name) ? name : undefined,
|
|
5620
|
+
},
|
|
5621
|
+
};
|
|
5550
5622
|
}
|
|
5551
5623
|
return { end };
|
|
5552
5624
|
}
|
package/dist/index.js
CHANGED
|
@@ -345,6 +345,9 @@ ${output
|
|
|
345
345
|
const UNKNOWN_FILTER = 'u_';
|
|
346
346
|
// Holds the result of a filter call while checking whether to await it
|
|
347
347
|
const RESULT = 'r_';
|
|
348
|
+
// Top-level render context; plain include always receives this, even when
|
|
349
|
+
// nested inside a for/with or an `include … with` partial.
|
|
350
|
+
const TOP_CONTEXT = 'tc_';
|
|
348
351
|
|
|
349
352
|
/**
|
|
350
353
|
* Contains the source map information.
|
|
@@ -612,6 +615,7 @@ ${suggestionText}`;
|
|
|
612
615
|
in: 'IN',
|
|
613
616
|
ni: 'NI',
|
|
614
617
|
of: 'OF',
|
|
618
|
+
with: 'WITH',
|
|
615
619
|
'+': 'ADD',
|
|
616
620
|
'-': 'SUB',
|
|
617
621
|
'*': 'MUL',
|
|
@@ -903,6 +907,7 @@ ${suggestionText}`;
|
|
|
903
907
|
IN: 40,
|
|
904
908
|
NI: 40,
|
|
905
909
|
OF: 40,
|
|
910
|
+
WITH: 40,
|
|
906
911
|
ADD: 50,
|
|
907
912
|
SUB: 50,
|
|
908
913
|
MUL: 60,
|
|
@@ -1050,36 +1055,12 @@ ${suggestionText}`;
|
|
|
1050
1055
|
}
|
|
1051
1056
|
continue;
|
|
1052
1057
|
}
|
|
1053
|
-
if (token.type
|
|
1054
|
-
token.type === 'OR' ||
|
|
1055
|
-
token.type === 'IS' ||
|
|
1056
|
-
token.type === 'EQ' ||
|
|
1057
|
-
token.type === 'NE' ||
|
|
1058
|
-
token.type === 'GT' ||
|
|
1059
|
-
token.type === 'LT' ||
|
|
1060
|
-
token.type === 'GE' ||
|
|
1061
|
-
token.type === 'LE' ||
|
|
1062
|
-
token.type === 'IN' ||
|
|
1063
|
-
token.type === 'NI' ||
|
|
1064
|
-
token.type === 'OF' ||
|
|
1065
|
-
token.type === 'ADD' ||
|
|
1066
|
-
token.type === 'SUB' ||
|
|
1067
|
-
token.type === 'MUL' ||
|
|
1068
|
-
token.type === 'DIV' ||
|
|
1069
|
-
token.type === 'MOD' ||
|
|
1070
|
-
token.type === 'ASSIGN') {
|
|
1058
|
+
if (isBinaryOp(token.type)) {
|
|
1071
1059
|
if (!left) {
|
|
1072
1060
|
throw new ExpError(`No left operand for "${token.type}"`, token.loc);
|
|
1073
1061
|
}
|
|
1074
1062
|
if (token.type === 'ASSIGN') {
|
|
1075
|
-
|
|
1076
|
-
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1077
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1078
|
-
}
|
|
1079
|
-
}
|
|
1080
|
-
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1081
|
-
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1082
|
-
}
|
|
1063
|
+
assertAssignableLeft(left, token);
|
|
1083
1064
|
}
|
|
1084
1065
|
const right = this.parseExp((t) => isHigher(token, t) ? 'BACK' : undefined);
|
|
1085
1066
|
if (!right) {
|
|
@@ -1182,12 +1163,46 @@ ${suggestionText}`;
|
|
|
1182
1163
|
}
|
|
1183
1164
|
}
|
|
1184
1165
|
}
|
|
1166
|
+
const BINARY_OPS = new Set([
|
|
1167
|
+
'AND',
|
|
1168
|
+
'OR',
|
|
1169
|
+
'IS',
|
|
1170
|
+
'EQ',
|
|
1171
|
+
'NE',
|
|
1172
|
+
'GT',
|
|
1173
|
+
'LT',
|
|
1174
|
+
'GE',
|
|
1175
|
+
'LE',
|
|
1176
|
+
'IN',
|
|
1177
|
+
'NI',
|
|
1178
|
+
'OF',
|
|
1179
|
+
'WITH',
|
|
1180
|
+
'ADD',
|
|
1181
|
+
'SUB',
|
|
1182
|
+
'MUL',
|
|
1183
|
+
'DIV',
|
|
1184
|
+
'MOD',
|
|
1185
|
+
'ASSIGN',
|
|
1186
|
+
]);
|
|
1187
|
+
function isBinaryOp(type) {
|
|
1188
|
+
return BINARY_OPS.has(type);
|
|
1189
|
+
}
|
|
1185
1190
|
// Two operands in a row, e.g. `a b`
|
|
1186
1191
|
function assertNotOperand(token) {
|
|
1187
1192
|
if (token.type === 'ID' || token.type === 'LIT' || token.type === 'LP') {
|
|
1188
1193
|
throw new ExpError(`Unexpected "${token.raw ?? token.value}"`, token.loc);
|
|
1189
1194
|
}
|
|
1190
1195
|
}
|
|
1196
|
+
function assertAssignableLeft(left, token) {
|
|
1197
|
+
if (left.type === 'SEQ') {
|
|
1198
|
+
if (left.elements.some((el) => el.type !== 'ID' || el.path || el.args)) {
|
|
1199
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
else if (left.type !== 'ID' || left.path || left.args) {
|
|
1203
|
+
throw new ExpError('Left operand of assignment must be an identifier or a sequence of identifiers', token.loc);
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1191
1206
|
function isHigher(a, b) {
|
|
1192
1207
|
// "(" starts an operand; it is not an operator to compare against
|
|
1193
1208
|
if (b.type === 'LP') {
|
|
@@ -1934,9 +1949,13 @@ ${suggestionText}`;
|
|
|
1934
1949
|
if (this.isRoot) {
|
|
1935
1950
|
if (this.partials.size) {
|
|
1936
1951
|
const { maxIncludeDepth } = resolveSecurityLimits(this.options.security);
|
|
1937
|
-
|
|
1952
|
+
// Alias the render data before partials shadow `c` with their argument.
|
|
1953
|
+
this.pushRaw(null, `const ${TOP_CONTEXT}=${CONTEXT};`, 'let d_=0;', 'const p={');
|
|
1938
1954
|
for (const [path, code] of this.partials) {
|
|
1939
|
-
this.pushRaw(null,
|
|
1955
|
+
this.pushRaw(null,
|
|
1956
|
+
// Partials take the context they should render with: plain include
|
|
1957
|
+
// passes the top-level `tc_`; `include … with` passes a merged scope.
|
|
1958
|
+
`${JSON.stringify(path)}:async(c)=>{`, `if(d_>=${maxIncludeDepth})throw new Error(${JSON.stringify(`Includes of ${JSON.stringify(path)} are nested too deeply`)});`, 'd_++;', 'try{return await(async()=>{', code, '})();}finally{d_--;}', '},');
|
|
1940
1959
|
}
|
|
1941
1960
|
this.pushRaw(null, '};');
|
|
1942
1961
|
}
|
|
@@ -2653,6 +2672,7 @@ ${suggestionText}`;
|
|
|
2653
2672
|
IN: ' in ',
|
|
2654
2673
|
NI: ' in ',
|
|
2655
2674
|
OF: ' of ',
|
|
2675
|
+
WITH: ' with ',
|
|
2656
2676
|
ADD: '+',
|
|
2657
2677
|
SUB: '-',
|
|
2658
2678
|
MUL: '*',
|
|
@@ -3538,15 +3558,23 @@ ${suggestionText}`;
|
|
|
3538
3558
|
parsers: parsers$9,
|
|
3539
3559
|
};
|
|
3540
3560
|
|
|
3541
|
-
async function compileInclude({ val: { value }, loc }, compiler) {
|
|
3542
|
-
|
|
3561
|
+
async function compileInclude({ val: { value }, loc, withExp }, compiler) {
|
|
3562
|
+
const path = JSON.stringify(value);
|
|
3563
|
+
if (withExp) {
|
|
3564
|
+
const expCompiler = new ExpCompiler();
|
|
3565
|
+
const merged = `{...${compiler.context},...${expCompiler.compile(withExp, compiler.context)}}`;
|
|
3566
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${merged})??"";`);
|
|
3567
|
+
return;
|
|
3568
|
+
}
|
|
3569
|
+
// Plain include always sees the top-level context, not loop/with scopes.
|
|
3570
|
+
compiler.pushRaw(loc, `s+=await p[${path}]?.(${TOP_CONTEXT})??"";`);
|
|
3543
3571
|
}
|
|
3544
3572
|
const compilers$8 = {
|
|
3545
3573
|
INCLUDE: compileInclude,
|
|
3546
3574
|
};
|
|
3547
3575
|
|
|
3548
3576
|
class IncludeNode extends Traversal {
|
|
3549
|
-
constructor(val, loc, strip) {
|
|
3577
|
+
constructor(val, loc, strip, withExp = null) {
|
|
3550
3578
|
super();
|
|
3551
3579
|
Object.defineProperty(this, "val", {
|
|
3552
3580
|
enumerable: true,
|
|
@@ -3566,6 +3594,12 @@ ${suggestionText}`;
|
|
|
3566
3594
|
writable: true,
|
|
3567
3595
|
value: strip
|
|
3568
3596
|
});
|
|
3597
|
+
Object.defineProperty(this, "withExp", {
|
|
3598
|
+
enumerable: true,
|
|
3599
|
+
configurable: true,
|
|
3600
|
+
writable: true,
|
|
3601
|
+
value: withExp
|
|
3602
|
+
});
|
|
3569
3603
|
Object.defineProperty(this, "type", {
|
|
3570
3604
|
enumerable: true,
|
|
3571
3605
|
configurable: true,
|
|
@@ -3575,13 +3609,31 @@ ${suggestionText}`;
|
|
|
3575
3609
|
}
|
|
3576
3610
|
}
|
|
3577
3611
|
|
|
3612
|
+
function isStringLit(exp) {
|
|
3613
|
+
return exp.type === 'LIT' && typeof exp.value === 'string';
|
|
3614
|
+
}
|
|
3578
3615
|
function* parseInclude(token, parser) {
|
|
3579
3616
|
if (!token.expression) {
|
|
3580
3617
|
parser.emitExpErr(token);
|
|
3581
3618
|
return;
|
|
3582
3619
|
}
|
|
3583
3620
|
yield 'NEXT';
|
|
3584
|
-
|
|
3621
|
+
const exp = parser.parseExp(token.expression);
|
|
3622
|
+
if (!exp) {
|
|
3623
|
+
return;
|
|
3624
|
+
}
|
|
3625
|
+
if (isStringLit(exp)) {
|
|
3626
|
+
yield new IncludeNode(exp, token.loc, token.strip);
|
|
3627
|
+
return;
|
|
3628
|
+
}
|
|
3629
|
+
if (exp.type === 'WITH') {
|
|
3630
|
+
const { left, right } = exp;
|
|
3631
|
+
if (isStringLit(left)) {
|
|
3632
|
+
yield new IncludeNode(left, token.loc, token.strip, right);
|
|
3633
|
+
return;
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
parser.options.debug?.(new CompileError('"include" expects "path" or "path" with expr', parser.template, token.loc));
|
|
3585
3637
|
}
|
|
3586
3638
|
const parsers$8 = {
|
|
3587
3639
|
include: parseInclude,
|
|
@@ -4617,6 +4669,9 @@ ${suggestionText}`;
|
|
|
4617
4669
|
await this.nodes(node.body, scope);
|
|
4618
4670
|
break;
|
|
4619
4671
|
case 'INCLUDE':
|
|
4672
|
+
if (node.withExp) {
|
|
4673
|
+
this.exp(node.withExp, scope);
|
|
4674
|
+
}
|
|
4620
4675
|
await this.include(node.val.value, scope);
|
|
4621
4676
|
break;
|
|
4622
4677
|
default:
|
|
@@ -5299,6 +5354,7 @@ export default script;
|
|
|
5299
5354
|
IN: 'in',
|
|
5300
5355
|
NI: 'ni',
|
|
5301
5356
|
OF: 'of',
|
|
5357
|
+
WITH: 'with',
|
|
5302
5358
|
ADD: '+',
|
|
5303
5359
|
SUB: '-',
|
|
5304
5360
|
MUL: '*',
|
|
@@ -5339,6 +5395,7 @@ export default script;
|
|
|
5339
5395
|
case 'IN':
|
|
5340
5396
|
case 'NI':
|
|
5341
5397
|
case 'OF':
|
|
5398
|
+
case 'WITH':
|
|
5342
5399
|
case 'ADD':
|
|
5343
5400
|
case 'SUB':
|
|
5344
5401
|
case 'MUL':
|
|
@@ -5409,6 +5466,8 @@ export default script;
|
|
|
5409
5466
|
'with',
|
|
5410
5467
|
'stylesheet',
|
|
5411
5468
|
]);
|
|
5469
|
+
/** Directives whose bodies keep leading whitespace (like `<style>`). */
|
|
5470
|
+
const DIR_SENSITIVE = new Set(['stylesheet']);
|
|
5412
5471
|
const DIR_MID = new Set(['else', 'elif', 'elseif', 'elsif']);
|
|
5413
5472
|
const DIR_CLOSE = new Set([
|
|
5414
5473
|
'endif',
|
|
@@ -5543,13 +5602,26 @@ export default script;
|
|
|
5543
5602
|
return { end };
|
|
5544
5603
|
}
|
|
5545
5604
|
if (DIR_CLOSE.has(name)) {
|
|
5546
|
-
|
|
5605
|
+
const base = name.startsWith('end') ? name.slice(3) : name;
|
|
5606
|
+
return {
|
|
5607
|
+
end,
|
|
5608
|
+
piece: {
|
|
5609
|
+
kind: 'close',
|
|
5610
|
+
sensitive: DIR_SENSITIVE.has(base) ? base : undefined,
|
|
5611
|
+
},
|
|
5612
|
+
};
|
|
5547
5613
|
}
|
|
5548
5614
|
if (DIR_MID.has(name)) {
|
|
5549
5615
|
return { end, piece: { kind: 'mid' } };
|
|
5550
5616
|
}
|
|
5551
5617
|
if (DIR_OPEN.has(name)) {
|
|
5552
|
-
return {
|
|
5618
|
+
return {
|
|
5619
|
+
end,
|
|
5620
|
+
piece: {
|
|
5621
|
+
kind: 'open',
|
|
5622
|
+
sensitive: DIR_SENSITIVE.has(name) ? name : undefined,
|
|
5623
|
+
},
|
|
5624
|
+
};
|
|
5553
5625
|
}
|
|
5554
5626
|
return { end };
|
|
5555
5627
|
}
|
package/dist/index.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){"use strict";class t{constructor(e={}){Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ttl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache=new Map,this.maxSize=e.maxSize??1e3,this.ttl=e.ttl??36e5,this.stats={hits:0,misses:0,evictions:0}}get(e){const t=this.cache.get(e);return t?this.ttl>0&&Date.now()-t.timestamp>this.ttl?(this.cache.delete(e),this.stats.misses++,null):(this.cache.delete(e),this.cache.set(e,t),t.hits++,this.stats.hits++,t.value):(this.stats.misses++,null)}peek(e){const t=this.cache.get(e);return!t||this.ttl>0&&Date.now()-t.timestamp>this.ttl?null:t.value}set(e,t){if(this.cache.size>=this.maxSize&&!this.cache.has(e)){const e=this.cache.keys().next().value;void 0!==e&&(this.cache.delete(e),this.stats.evictions++)}this.cache.set(e,{value:t,timestamp:Date.now(),hits:0})}has(e){const t=this.cache.get(e);return!!t&&(!(this.ttl>0&&Date.now()-t.timestamp>this.ttl)||(this.cache.delete(e),!1))}delete(e){return this.cache.delete(e)}clear(){this.cache.clear(),this.stats={hits:0,misses:0,evictions:0}}invalidate(e){if(e)for(const t of this.cache.keys())e(t)&&this.cache.delete(t);else this.clear()}getStats(){return{...this.stats,size:this.cache.size,hitRate:this.stats.hits+this.stats.misses>0?this.stats.hits/(this.stats.hits+this.stats.misses):0}}resetStats(){this.stats={hits:0,misses:0,evictions:0}}}function n(e,t,n){const r=[];if("ExpError"===e&&(t.includes("Unexpected end of expression")&&r.push({message:"The expression is incomplete. Make sure you have closed all parentheses, brackets, and quotes.",fix:"Check for missing closing characters: ), ], }"}),t.includes('Expected "RP" after "LP"')&&r.push({message:"Missing closing parenthesis in your expression.",fix:"Add a closing parenthesis ) to match the opening one.",example:"(foo.bar) instead of (foo.bar"}),t.includes("No left operand")&&r.push({message:"An operator is missing its left operand.",fix:"Add a value or variable before the operator.",example:"x + 1 instead of + 1"}),t.includes("No right operand")&&r.push({message:"An operator is missing its right operand.",fix:"Add a value or variable after the operator.",example:"x + 1 instead of x +"}),t.includes('Expected "ID" after "PIPE"')&&r.push({message:"The pipe operator | must be followed by a filter name.",fix:"Add a filter name after the pipe.",example:"value|upper instead of value|"}),t.includes('Expected "ID" after "DOT"')&&r.push({message:"The dot operator . must be followed by a property name.",fix:"Add a property name after the dot.",example:"object.property instead of object."}),t.includes("Left operand of assignment must be an identifier")&&r.push({message:"Assignment targets must be valid identifiers.",fix:"Use a simple variable name or sequence of variable names.",example:"x = 1 or (a, b) = [1, 2]"}),t.includes("Expected test expression")&&r.push({message:"The conditional expression is missing its test condition.",fix:"Add a condition after the if keyword.",example:"if x > 0 then y else z"}),t.includes("Expected alternative expression")&&r.push({message:"The conditional expression is missing its else clause.",fix:"Add an alternative expression after then.",example:"if x > 0 then y else z"}),t.startsWith("Unexpect")&&r.push({message:"An unexpected character was found in the expression.",fix:"Check for typos or invalid characters in your expression."})),"CompileError"===e){if(t.includes("Unclosed")){const e=t.match(/Unclosed "([^"]+)"/),n=e?e[1]:"marker";r.push({message:`The ${n} marker is not closed properly.`,fix:`Add the closing marker for ${n}.`,example:"{%"===n?"{% ... %}":"{#"===n?"{# ... #}":"{{ ... }}"})}t.includes("Unexpected")&&r.push({message:"An unexpected token was found in the template.",fix:"Check your template syntax and ensure all markers are properly formatted."})}return n&&r.push({message:"Context information:",fix:n}),r}class r extends SyntaxError{constructor(e,t,n,i){super(e),Object.defineProperty(this,"src",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:i}),this.name="CompileError",r.captureStackTrace?.(this,this.constructor)}get details(){const e=this.loc?function(e,t,{start:{line:n,column:r},end:{line:i,column:s}}){const o=[],a=new Set,l=e=>{a.add(e-2),a.add(e-1),a.add(e),a.add(e+1),a.add(e+2)},c=t.split("\n"),u=String(c.length).length+2;let p=0;c.forEach((e,t)=>{if(e){if(o.push(`${`${t+1}│ `.padStart(u," ")}${e}`),n===t+1){const e=`${" ".repeat(u-2)}│ ${" ".repeat(r-1)}^${n===i&&s>r+1?`${" ".repeat(s-r-2)}^`:""}`;/\S/.test(e)&&o.push(e),l(++p+t)}if(n!==i&&i===t+1){const e=`${" ".repeat(u-2)}│ ${" ".repeat(s-1)}${"^".repeat(1)}`;/\S/.test(e)&&o.push(e),l(++p+t)}}});const h=`${" ".repeat(u)}...`;return`${e}\n\n${o.map((e,t)=>a.has(t)?e:h).reduce((e,t)=>t===h&&e.at(-1)===t?e:[...e,t],[]).join("\n")}\n`}(this.message,this.src,this.loc):this.message;return function(e,t,r,i){const s=n(e,t,i);return 0===s.length?r:`${r}\n\nSuggestions:\n${s.map((e,t)=>{let n=` ${t+1}. ${e.message}`;return e.fix&&(n+=`\n Fix: ${e.fix}`),e.example&&(n+=`\n Example: ${e.example}`),n}).join("\n")}`}(this.name,this.message,e,this.context)}get suggestions(){return n(this.name,this.message,this.context)}}const i="c",s="f",o="r_";class a{constructor(){Object.defineProperty(this,"mappings",{enumerable:!0,configurable:!0,writable:!0,value:[]})}addMapping(e,t){this.mappings.push({source:e,target:t})}getSourceLoc({line:e,column:t}){return this.mappings.filter(({target:{start:n,end:r}})=>n.line<=e&&r.line>=e&&(n.line<e||n.column<=t)&&(r.line>e||r.column>=t)).map(({source:e})=>e)}}class l extends a{constructor(){super(...arguments),Object.defineProperty(this,"codeParts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"codeLength",{enumerable:!0,configurable:!0,writable:!0,value:0})}get code(){return this.codeParts.join("")}set code(e){this.codeParts=[e],this.codeLength=e.length}get script(){return new Function(i,"e",s,"w",this.code)}checkpoint(){return[this.codeParts.length,this.mappings.length,this.codeLength]}rollback(e){const[t,n,r]=e;this.codeParts.length=t,this.mappings.length=n,this.codeLength=r}start(e=!0){this.pushRaw(null,"return(async()=>{",`let s="",${o};`),e&&this.pushRaw(null,"const u_=(n)=>{throw new Error('Unknown filter \"'+n+'\"')};")}end(){this.pushRaw(null,"return s;","})();")}pushRaw(e,...t){const n=this.codeLength;for(const e of t)this.codeParts.push(e),this.codeLength+=e.length;e&&this.addMapping(e,{start:{line:1,column:n},end:{line:1,column:this.codeLength}})}pushStr(e,t){t&&this.pushRaw(e,`s+=${JSON.stringify(t)};`)}pushFlush(){this.pushRaw(null,'if(s.length>1024){await w(s);s="";}')}pushVar(e,t){this.pushRaw(e,`s+=e(${t});`)}}class c extends l{constructor(){super(...arguments),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"stack",{enumerable:!0,configurable:!0,writable:!0,value:[i]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0})}checkpoint(){return[super.checkpoint(),this.context,[...this.stack]]}rollback(e){const[t,n,r]=e;super.rollback(t),this.context=n,this.stack=r}in(){return this.context=`${this.context}_${this.index++}`,this.stack.push(this.context),this.context}out(){this.context!==i&&(this.stack.pop(),this.context=this.stack.at(-1))}}class u extends SyntaxError{constructor(e,t,n){super(e),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="ExpError",u.captureStackTrace?.(this,this.constructor)}get suggestions(){return n(this.name,this.message,this.context)}get details(){const{suggestions:e}=this;if(0===e.length)return this.message;const t=e.map((e,t)=>{let n=` ${t+1}. ${e.message}`;return e.fix&&(n+=`\n Fix: ${e.fix}`),e.example&&(n+=`\n Example: ${e.example}`),n}).join("\n");return`${this.message}\n\nSuggestions:\n${t}`}}function p(e,t){const n=(e.match(/\n/g)||[]).length;if(n>0){t.line+=n;const r=e.lastIndexOf("\n");t.column=e.length-r}else t.column+=e.length;return{line:t.line,column:t.column}}const h={and:"AND",or:"OR",not:"NOT",is:"IS",eq:"EQ",ne:"NE",gt:"GT",lt:"LT",ge:"GE",le:"LE",in:"IN",ni:"NI",of:"OF","+":"ADD","-":"SUB","*":"MUL","/":"DIV","%":"MOD",if:"IF",else:"ELSE",true:"LIT",false:"LIT",null:"LIT",undefined:"LIT","|":"PIPE","=":"ASSIGN","(":"LP",")":"RP",",":"COMMA",".":"DOT"},f=new Set(["constructor","prototype","__proto__","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]);function d(e){return"string"==typeof e&&f.has(e)}const b={n:"\n",t:"\t",r:"\r","\\":"\\",'"':'"',"'":"'","`":"`"};function m(e){switch(e){case"true":return!0;case"false":return!1;case"null":return null;case"undefined":return;default:return e}}class y{constructor(){Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1})}tokenize(e,t){for(this.val=e,this.index=0,this.line=t.start.line,this.column=t.start.column,this.tokens=[];this.index<this.val.length;){const e=this.val[this.index];if(g(e))"\n"===e?(this.line++,this.column=1):this.column++,this.index++;else if("'"!==e&&'"'!==e&&"`"!==e)if(v(e)||"-"===e&&v(this.val[this.index+1]??"")&&!this.afterOperand())this.readNumber(e);else if(x(e))this.readIdentifier(e);else{if(!w(e))throw new u(`Unexpected "${e}"`,{start:{line:this.line,column:this.column},end:{line:this.line,column:this.column+1}});this.readSymbol(e)}else this.readString(e)}return this.tokens}afterOperand(){const e=this.tokens.at(-1)?.type;return"ID"===e||"LIT"===e||"RP"===e}readString(e){let t="",n="",r=!1;const i={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const i=this.val[this.index];if(r)t+=b[i]??`\\${i}`,n+=i,r=!1;else if("\\"===i)n+=i,r=!0;else{if(i===e)break;t+=i,n+=i}this.index++}this.index++,this.tokens.push({type:"LIT",value:t,loc:{start:i,end:p(`${e}${n}${e}`,this)},raw:`${e}${n}${e}`})}readNumber(e){let t=e,n=!1;const r={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const e=this.val[this.index];if(v(e))t+=e;else{if("."!==e||n)break;t+=e,n=!0}this.index++}this.tokens.push({type:"LIT",value:Number.parseFloat(t),loc:{start:r,end:p(t,this)},raw:t})}readIdentifier(e){let t=e;const n={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const e=this.val[this.index];if(!O(e))break;t+=e,this.index++}if(d(t))throw new u(`"${t}" is not allowed in expressions`,{start:n,end:{line:this.line,column:this.column+t.length}});const r=Object.prototype.hasOwnProperty.call(h,t)?h[t]:"ID";this.tokens.push({type:r,value:"LIT"===r?m(t):t,loc:{start:n,end:p(t,this)},raw:t})}readSymbol(e){const t={line:this.line,column:this.column};this.index++,this.tokens.push({type:h[e],value:e,loc:{start:t,end:p(e,this)},raw:e})}}function g(e){return/\s/.test(e)}function w(e){return/[+\-*/%|=(),.]/.test(e)}function v(e){return/\d/.test(e)}function x(e){return/[a-z_$]/i.test(e)}function O(e){return/[\w$]/.test(e)}const E={COMMA:5,IF:10,ELSE:10,ASSIGN:15,LP:20,RP:20,OR:25,AND:30,IS:40,EQ:40,NE:40,GT:40,LT:40,GE:40,LE:40,IN:40,NI:40,OF:40,ADD:50,SUB:50,MUL:60,DIV:60,MOD:60,NOT:70,PIPE:80,DOT:90,ID:90,LIT:90};class P{constructor(){Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1})}parse(e,t){return this.val=e,this.index=0,this.line=t.start.line,this.column=t.start.column,this.tokens=(new y).tokenize(e,t),this.val?this.parseExp():null}parseExp(e){let t=null;for(;;){const n=this.next();if(!n)break;const r=e?.(n);if("BACK"===r){this.back();break}if("BREAK"===r)break;if(t&&j(n),"LP"===n.type){if(!this.peek())throw new u("Unexpected end of expression",n.loc);const e=this.parseSequence(),r=this.consume("RP");if(!r)throw new u('Expected "RP" after "LP"',n.loc);t={...n,type:"SEQ",elements:e,loc:{start:n.loc.start,end:r.loc.end}};continue}if("NOT"!==n.type){if("ID"===n.type){t={...n,type:"ID",value:n.value},this.match("DOT")&&(t.path=this.parsePath());const e=this.consume("LP");if(e){if(t.args=this.parseSequence(),!this.consume("RP"))throw new u('Expected "RP" after "LP"',e.loc);continue}continue}if("LIT"!==n.type){if("IF"===n.type){const e=this.parseExp(e=>"ELSE"===e.type||T(n,e)?"BACK":void 0);if(!e)throw new u("Expected test expression",n.loc);if(t={...n,type:"IF",test:e,consequent:t},this.consume("ELSE")){const e=this.parseExp(e=>T(n,e)?"BACK":void 0);if(!e)throw new u("Expected alternative expression",n.loc);t.alternative=e}continue}if("AND"===n.type||"OR"===n.type||"IS"===n.type||"EQ"===n.type||"NE"===n.type||"GT"===n.type||"LT"===n.type||"GE"===n.type||"LE"===n.type||"IN"===n.type||"NI"===n.type||"OF"===n.type||"ADD"===n.type||"SUB"===n.type||"MUL"===n.type||"DIV"===n.type||"MOD"===n.type||"ASSIGN"===n.type){if(!t)throw new u(`No left operand for "${n.type}"`,n.loc);if("ASSIGN"===n.type)if("SEQ"===t.type){if(t.elements.some(e=>"ID"!==e.type||e.path||e.args))throw new u("Left operand of assignment must be an identifier or a sequence of identifiers",n.loc)}else if("ID"!==t.type||t.path||t.args)throw new u("Left operand of assignment must be an identifier or a sequence of identifiers",n.loc);const e=this.parseExp(e=>T(n,e)?"BACK":void 0);if(!e)throw new u(`No right operand for "${n.type}"`,n.loc);t={...n,type:n.type,left:t,right:e};continue}if("PIPE"!==n.type){this.back();break}if(!t)throw new u(`No left operand for "${n.type}"`,n.loc);if(!this.match("ID"))throw new u('Expected "ID" after "PIPE"',n.loc);t={...n,type:"PIPE",left:t,right:this.parsePipe()}}else t={...n,type:"LIT"}}else{if(!this.peek())throw new u("Unexpected end of expression",n.loc);t={...n,type:"NOT",argument:this.parseExp(e=>T(n,e)?"BACK":void 0)}}}return t}parsePath(){const e=[];for(;;){const t=this.consume("DOT");if(!t)break;const n=this.next();if(!n)throw new u('Expected "ID" after "DOT"',t.loc);if("ID"!==n.type)throw new u('Expected "ID" after "DOT"',t.loc);e.push({...n,type:"ID",value:n.value})}return e}parseSequence(){const e=[];for(;!this.match("RP");){const t=this.parseExp(e=>"COMMA"===e.type?"BREAK":void 0);if(!t)break;e.push(t)}return e}parsePipe(){const e=this.next(),t={...e,type:"ID",value:e.value},n=this.consume("LP");if(n&&(t.args=this.parseSequence(),!this.consume("RP")))throw new u('Expected "RP" after "LP"',n.loc);return t}next(){return this.tokens[this.index++]??null}back(){return this.tokens[this.index--]}peek(){return this.tokens.at(this.index)??null}match(e){return this.peek()?.type===e}consume(e){if(this.match(e))return this.next()}}function j(e){if("ID"===e.type||"LIT"===e.type||"LP"===e.type)throw new u(`Unexpected "${e.raw??e.value}"`,e.loc)}function T(e,t){return"LP"!==t.type&&E[e.type]>E[t.type]}class ${constructor(){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}traverse(e){this.body?.forEach(e)}}class k extends ${constructor(e,t){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"TEMPLATE"})}}var S;function N(e){return e.replace(/\\([{}])/g,"$1")}e.TokenType=void 0,(S=e.TokenType||(e.TokenType={})).TEXT="TEXT",S.OUTPUT="OUTPUT",S.DIRECTIVE="DIRECTIVE",S.COMMENT="COMMENT";class I{constructor(t){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"length",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokenPatterns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"markerIndices",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1});const{commentOpen:n,commentClose:r,directiveOpen:i,directiveClose:s,outputOpen:o,outputClose:a}=this.options;this.tokenPatterns=[[e.TokenType.COMMENT,n,r],[e.TokenType.DIRECTIVE,i,s],[e.TokenType.OUTPUT,o,a]].sort(([,e],[,t])=>e.length>t.length?-1:1),this.markerIndices=new Map;for(const[,e]of this.tokenPatterns)e.length>0&&this.markerIndices.set(e[0],this.markerIndices.get(e[0])||0)}tokenize(e){for(this.template=e,this.length=e.length,this.index=0,this.line=1,this.column=1,this.tokens=[];this.index<this.length;)this.consumeSpecialTokens()||this.consumeTextToken();return this.tokens}consumeSpecialTokens(){return this.tokenPatterns.some(([t,n,i])=>{if(!this.lookahead(n))return!1;const s={line:this.line,column:this.column},o=this.template.indexOf(i,this.index+n.length);if(-1===o)throw new r(`Unclosed "${n}"`,this.template,{start:s,end:p(n,{...s})});const a=this.lookahead("-",n.length),l="-"===this.template[o-1],c=this.template.slice(this.index+n.length+ +a,o-+l),u=p(this.template.slice(this.index,this.index=o+i.length),this),h={type:t,val:N(c),strip:{before:a,after:l},loc:{start:s,end:u}};if(t===e.TokenType.DIRECTIVE){let e=0,t="";for(;e<c.length;){const n=c[e];if(/\S/.test(n))t+=n;else if(t)break;e++}Object.assign(h,{name:t,expression:e===c.length||/^\s*$/m.test(c.slice(e+1))?null:{val:c.slice(e+1),loc:{start:p(c.slice(0,e+1),p(`${n}${a?"-":""}`,{...s})),end:{line:this.line,column:this.column-i.length-+l}}}})}return this.tokens.push(h),!0})}consumeTextToken(){const t=this.findNextSpecialIndex(),n={line:this.line,column:this.column},r=this.template.slice(this.index,t);this.tokens.push({type:e.TokenType.TEXT,val:N(r),loc:{start:n,end:p(r,this)},strip:{}}),this.index=t}lookahead(e,t=0){return this.template.startsWith(e,this.index+t)}findNextSpecialIndex(){const{outputOpen:e,directiveOpen:t,commentOpen:n}=this.options;let r=this.length;for(let i=this.index;i<this.length;i++){if(this.template.startsWith(n,i)){r=i;break}if(this.template.startsWith(t,i)){r=i;break}if(this.template.startsWith(e,i)){r=i;break}}return r}}class L extends I{constructor(){super(...arguments),Object.defineProperty(this,"expParser",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cursor",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}parse(t){this.tokenize(t),this.tokens.forEach((t,n)=>{t.type===e.TokenType.TEXT&&(this.tokens[n-1]?.strip?.after&&(t.strip.start=!0),this.tokens[n+1]?.strip?.before&&(t.strip.end=!0))});const n=this.tokens[0]?.loc.start??{line:1,column:1},r=this.tokens.at(-1)?.loc.end??{line:1,column:1};return this.expParser=new P,this.cursor=0,new k(this.parseUntil(),{start:n,end:r})}parseUntil(t){const n=[];let r=null;for(;;){const i=this.peek();if(!i||i.type===e.TokenType.DIRECTIVE&&t&&this.match(t,i))break;r?.strip?.after&&i.type===e.TokenType.TEXT&&(i.strip.start=!0),i.strip?.before&&r?.type===e.TokenType.TEXT&&(r.strip.end=!0);let s=this.options.parsers[i.name?.toLowerCase()??i.type?.toLowerCase()];"string"==typeof s&&(s=this.options.parsers[s]),s||(s=this.options.parsers.unknown);const{cursor:o}=this,a=s?.(i,this);if(a)for(;;){const{value:e,done:t}=a.next();if(t)break;"NEXT"===e?this.advance():e&&n.push(e)}this.cursor===o&&this.advance(),r=i}return n}parseExp({val:e,loc:t}){try{return this.expParser.parse(e,t)}catch(e){this.options.debug(e.loc?new r(e.message,this.template,e.loc):e)}}peek(){return this.tokens.at(this.cursor)??null}advance(){this.cursor++}match(e,t=this.peek()){return e.includes(t?.name?.toLowerCase())}emitExpErr({name:e,loc:t},n=!0){this.options.debug(new r(n?`"${e}" requires expression`:`"${e}" should not have expression`,this.template,t))}}const C=/[&<>"']/,R=/[&<>"']/g,D={"&":"&",'"':""","'":"'","<":"<",">":">"},A=e=>D[e];function U(e){const t="string"==typeof e?e:`${e}`;return C.test(t)?t.replace(R,A):t}class M extends String{constructor(e){super(`${e}`)}}function _(e={}){return{maxIncludeDepth:e.maxIncludeDepth??100,maxLoopIterations:e.maxLoopIterations,maxCallDepth:e.maxCallDepth,timeoutMs:e.timeoutMs}}class F{constructor(e={}){Object.defineProperty(this,"allowedGlobals",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cspNonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.allowedGlobals=new Set(e.allowedGlobals||[]),this.cspNonce=e.cspNonce}sanitizeGlobals(e){const t={};for(const[n,r]of Object.entries(e))this.allowedGlobals.has(n)&&(t[n]=r);return t}validateExpression(e){const t=[/\bprocess\b/,/\brequire\b/,/\bimport\b/,/\bexport\b/,/\beval\b/,/\bFunction\b/,/\b__proto__\b/,/\bconstructor\b/];for(const n of t)if(n.test(e))return!1;return!0}createSecureContext(e){return{...this.sanitizeGlobals(e),Math:Math,Date:Date,JSON:JSON}}getCSPNonce(){return this.cspNonce}generateCSPHeaders(){const e={};return this.cspNonce&&(e["Content-Security-Policy"]=`script-src 'nonce-${this.cspNonce}'`),e}}function X(e,t=new WeakSet){if(null==e)return"";if(e instanceof M)return`${e}`;if("object"==typeof e){if(t.has(e))return"";t.add(e);return(Array.isArray(e)?e:Object.values(e)).map(e=>X(e,t)).join("")}return U(e)}class W{auditTemplate(e){const t=[],n=[{pattern:/\beval\s*\(/,type:"dangerous-eval",message:"Use of eval() is dangerous and should be avoided",severity:"critical"},{pattern:/\bFunction\s*\(/,type:"dangerous-function",message:"Use of Function constructor is dangerous",severity:"critical"},{pattern:/\brequire\s*\(/,type:"require-usage",message:"Direct require() usage in templates is unsafe",severity:"high"},{pattern:/\bimport\s*\(/,type:"dynamic-import",message:"Dynamic import() usage in templates may be unsafe",severity:"high"}];for(const{pattern:r,type:i,message:s,severity:o}of n){const n=e.match(r);n&&t.push({type:i,message:s,location:`at index ${n.index}`,severity:o})}return{issues:t,severity:this.calculateOverallSeverity(t)}}calculateOverallSeverity(e){if(0===e.length)return"low";const t={critical:4,high:3,medium:2,low:1},n=Math.max(...e.map(e=>t[e.severity]));return Object.entries(t).find(([,e])=>e===n)[0]}}const G=new WeakMap,z=new Set(["IF","FOR"]);function B(e,t=!1){return t?`\0stream:${e}`:e}function q(e){let t=G.get(e);if(void 0===t){const{trimWhitespace:n,stripComments:r,commentOpen:i,commentClose:s,directiveOpen:o,directiveClose:a,outputOpen:l,outputClose:c}=e,{maxIncludeDepth:u,maxLoopIterations:p,maxCallDepth:h}=_(e.security);t=JSON.stringify([n,r,i,s,o,a,l,c,u,p??null,h??null]),G.set(e,t)}return t}class K extends c{constructor(e,t,n=!0,r=!1){super(),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"revalidate",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isRoot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"rootNode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"partials",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"blocks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stylesheets",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stylesheetKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sources",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"compiled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.cache=t}async compile(e,t=!0,n=new Map,r=new Map,i=new Map,s=new Map,o="\0root"){this.template=e,this.isRoot=t,this.partials=n,this.blocks=r,this.stylesheets=s,this.stylesheetKey=o,this.sources=i;const a=this.generateCacheKey(e);if(this.cache&&t){const e=this.cache.get(a);if(e){if(e.fingerprint===this.fingerprint()&&await this.isFresh(e))return this.code=e.code,this.mappings=e.mappings,this.compiled=e,this;this.cache.delete(a)}}if(this.rootNode=new L(this.options).parse(e),this.state={},this.start(this.isRoot),this.isRoot&&(this.pushResourceLimitCounters(),this.pushRaw(null,"let ss_u=0;")),await this.parseTemplates(),this.isRoot){if(this.partials.size){const{maxIncludeDepth:e}=_(this.options.security);this.pushRaw(null,"let d_=0;","const p={");for(const[t,n]of this.partials)this.pushRaw(null,`${JSON.stringify(t)}:async()=>{`,`if(d_>=${e})throw new Error(${JSON.stringify(`Includes of ${JSON.stringify(t)} are nested too deeply`)});`,"d_++;","try{return await(async()=>{",n,"})();}finally{d_--;}","},");this.pushRaw(null,"};")}if(this.blocks.size){this.pushRaw(null,"const b={");for(const[e,t]of this.blocks){this.pushRaw(null,`${JSON.stringify(e)}:{`,"u:0,","s:["),this.state.block=e;for(const e of t)this.pushRaw(null,"async()=>{",'let s="";'),await this.compileNodes(e.body),this.pushRaw(null,"return s;","},");this.state.block=void 0,this.pushRaw(null,"],","},")}this.pushRaw(null,"};")}this.pushRaw(null,"const ss_=[");for(const[,e]of this.stylesheets){this.pushRaw(null,"async()=>{",'let s="";');for(const t of e)await this.compileNodes(t.body);this.pushRaw(null,"return s;","},")}this.pushRaw(null,"];")}return this.flushable=this.isRoot&&this.stream,await this.compileNode(this.rootNode),this.flushable=!1,this.end(),this.cache&&t&&(this.compiled={code:this.code,mappings:this.mappings,sources:this.sources,fingerprint:this.fingerprint()},this.cache.set(a,this.compiled)),this}get script(){var e;return this.compiled?(e=this.compiled).script??(e.script=super.script):super.script}generateCacheKey(e){return B(e,this.stream)}fingerprint(){return q(this.options)}pushResourceLimitCounters(){const{maxLoopIterations:e,maxCallDepth:t}=_(this.options.security);null!=e&&this.pushRaw(null,"let li_=0;"),null!=t&&this.pushRaw(null,"let cd_=0;")}async isFresh({sources:e}){if(!this.revalidate)return!0;try{for(const[t,n]of e)if(await this.options.loader(t)!==n)return!1}catch{return!1}return!0}async parseTemplates(){const{partials:e,blocks:t,stylesheets:n}=this.collectPartialsAndBlocks();for(const[t,n]of e)if(!this.partials.has(t)){let e;try{e=await this.options.loader(t)}catch{throw new r(`Failed to load template from "${t}"`,this.template,n.loc)}this.sources.set(t,e??""),this.partials.set(t,""),e&&await this.compilePartial(t,n,e)}for(const e of t){const{val:{value:t}}=e;this.blocks.has(t)||this.blocks.set(t,[]),this.blocks.get(t).push(e)}n.length&&!this.stylesheets.has(this.stylesheetKey)&&this.stylesheets.set(this.stylesheetKey,n)}collectPartialsAndBlocks(){const e=new Map,t=[],n=[],r=i=>{"INCLUDE"===i.type&&(e.has(i.val.value)||e.set(i.val.value,i)),"BLOCK"===i.type&&t.push(i),"STYLESHEET"===i.type&&n.push(i),i.traverse(r)};return r(this.rootNode),{partials:e,blocks:t,stylesheets:n}}async compileNode(e){if("TEMPLATE"===e.type){for(const t of e.body)await this.compileNode(t),this.flushable&&"TEXT"!==t.type&&this.pushFlush();return}let t=this.options.compilers[e.type];"string"==typeof t&&(t=this.options.compilers[t]),t||(t=this.options.compilers.UNKNOWN);const n=this.checkpoint(),{flushable:i}=this;z.has(e.type)||(this.flushable=!1);try{await(t?.(e,this))}catch(t){if(this.flushable=i,"CompileError"===t?.name)throw t;this.rollback(n),this.options.debug(new r(`Invalid "${e.type.toLowerCase()}" directive`,this.template,e.loc))}this.flushable=i}async compileNodes(e){for(const t of e)await this.compileNode(t)}async compilePartial(e,t,n){try{const{code:t}=await new K(this.options).compile(n,!1,this.partials,this.blocks,this.sources,this.stylesheets,e);this.partials.set(e,t)}catch{this.options.debug(new r("Failed to compile template",this.template,t.loc))}}}var J=Object.freeze({__proto__:null,abs:function(e=0){return Math.abs(e)},add:function(e=0,t=0){return e+t},capitalize:function(e=""){return e.replace(/\b\w/g,e=>e.toUpperCase())},ceil:function(e=0){return Math.ceil(e)},chunk:function(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},compact:function(e=[]){return e.filter(e=>null!=e)},currency:function(e,t="USD",n="en-US"){return new Intl.NumberFormat(n,{style:"currency",currency:t}).format(e)},date:function(e,t="ISO"){const n=e instanceof Date?e:new Date(e);if(isNaN(n.getTime()))return"";switch(t){case"ISO":default:return n.toISOString();case"date":return n.toISOString().split("T")[0];case"time":return n.toTimeString().split(" ")[0];case"locale":return n.toLocaleDateString();case"locale-time":return n.toLocaleTimeString();case"locale-datetime":return n.toLocaleString()}},defaults:function(e,t){return{...t,...e}},delay:async function(e,t){return await new Promise(e=>setTimeout(e,t)),e},div:function(e=0,t=1){return e/t},entries:function(e={}){return Object.entries(e)},escape:U,even:function(e=0){return+e%2==0},fallback:function(e,t,n=!1){return n?e||t:e??t},fetchUrl:async function(e,t={}){return(await fetch(e,t)).text()},first:function(e=[]){return[...e][0]},fixed:function(e,t=2){return Number(e).toFixed(t)},get:function(e,...t){return t.reduce((e,t)=>e&&"object"==typeof e&&!d(t)&&t in e?e[t]:void 0,e)},groupby:function(e=[],t){return e.reduce((e,n)=>{const r=n[t];return{...e,[r]:[...e[r]||[],n]}},{})},invert:function(e){return Object.entries(e).reduce((e,[t,n])=>({...e,[String(n)]:t}),{})},join:function(e=[],t=""){return[...e].join(t)},json:function(e=null,t=0){return new M(JSON.stringify(e,null,t))},keys:function(e={}){return Object.keys(e)},last:function(e=[]){return[...e].reverse()[0]},length:function(e=""){return e.length},lower:function(e=""){return e.toLowerCase()},map:function(e=[],t,n){return e.map(e=>d(t)?n:e[t]??n)},max:function(e=0,...t){return Math.max(e,...t)},merge:function(e,...t){return Object.assign({},e,...t)},min:function(e=0,...t){return Math.min(e,...t)},mul:function(e=0,t=1){return e*t},odd:function(e=0){return+e%2==1},omit:function(e={},...t){return Object.entries(e).reduce((e,[n,r])=>t.includes(n)?e:{...e,[n]:r},{})},percent:function(e,t=0){return`${(100*e).toFixed(t)}%`},pick:function(e={},...t){return t.reduce((t,n)=>d(n)?t:{...t,[n]:e[n]},{})},pluck:function(e,t){return e.map(e=>e[t])},repeat:function(e="",t=0){return e.repeat(t)},replace:function(e="",t,n){return e.replace(new RegExp(t,"g"),n)},reverse:function(e=[]){return Array.isArray(e)?[...e].reverse():[...e].reverse().join("")},round:function(e,t=0){return Number(`${Math.round(Number(`${e}e${t}`))}e-${t}`)},safe:function(e=""){return new M(e)},shuffle:function(e){const t=[...e];for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},slice:function(e="",t=0,n){return e.slice(t,n)},slugify:function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")},sort:function(e=[]){return Array.isArray(e)?[...e].sort():[...e].sort().join("")},split:function(e="",t=""){return e.split(t)},stripTags:function(e){return e.replace(/<[^>]*>/g,"")},sub:function(e=0,t=0){return e-t},sum:function(e=[]){return e.reduce((e,t)=>e+t,0)},timeAgo:function(e){const t=e instanceof Date?e:new Date(e),n=new Date,r=Math.floor((n.getTime()-t.getTime())/1e3),i=[{label:"year",seconds:31536e3},{label:"month",seconds:2592e3},{label:"day",seconds:86400},{label:"hour",seconds:3600},{label:"minute",seconds:60}];for(const e of i){const t=Math.floor(r/e.seconds);if(t>=1)return`${t} ${e.label}${t>1?"s":""} ago`}return"just now"},trim:function(e=""){return e.trim()},truncate:function(e="",t=0,n="..."){return e.slice(0,t)+(e.length>t?n:"")},unique:function(e=""){return Array.isArray(e)?Array.from(new Set(e)):Array.from(new Set(e)).join("")},upper:function(e=""){return e.toUpperCase()},urldecode:function(e=""){return decodeURIComponent(e)},urlencode:function(e=""){return encodeURIComponent(e)},values:function(e={}){return Object.values(e)},wordCount:function(e){return e.trim().split(/\s+/).filter(Boolean).length}});const V={filters:{},parsers:{},compilers:{},plugins:[],debug:e=>{throw e}},H={...V,commentOpen:"{{#",commentClose:"#}}",directiveOpen:"{{",directiveClose:"}}",outputOpen:"{{=",outputClose:"}}"},Q={...H,trimWhitespace:!1,stripComments:!1,loader:async()=>""},Y={...Q,globals:{},autoEscape:!0,cache:{enabled:!0,maxSize:1e3,ttl:36e5,revalidate:!0},security:{}},Z=(e,...t)=>{const n={...e},r=e=>{n.filters={...n.filters,...e.filters},n.parsers={...n.parsers,...e.parsers},n.compilers={...n.compilers,...e.compilers}};return e.plugins?.forEach(r),t.forEach(({plugins:e,filters:t,parsers:i,compilers:s,...o})=>{for(const[e,t]of Object.entries(o))void 0!==t&&(n[e]=t);r({filters:t,parsers:i,compilers:s}),e?.forEach(r)}),n};const ee={BLOCK:async function({val:{value:e},loc:t},n){const r=JSON.stringify(e);n.pushRaw(t,`if(b[${r}]&&!(b[${r}].u++)){`,`s+=await b[${r}].s?.pop()?.()??"";`,"}")},SUPER:async function({loc:e},t){t.state.block?t.pushRaw(e,`s+=await b[${JSON.stringify(t.state.block)}]?.s?.pop()?.()??"";`):t.options.debug?.(new r('"super" should be used inside a block',t.template,e))}};class te extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"BLOCK"})}}class ne extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"SUPER"})}}const re={compilers:ee,parsers:{block:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endblock"]);t.match(["endblock"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new te(t.parseExp(e.expression),n,e.loc,e.strip)},super:function*(e,t){e.expression?t.emitExpErr(e,!1):(yield"NEXT",yield new ne(e.val,e.loc,e.strip))},endblock:"unexpected"}},ie={AND:"&&",OR:"||",IS:"",NOT:"!",EQ:"===",NE:"!==",GT:">",LT:"<",GE:">=",LE:"<=",IN:" in ",NI:" in ",OF:" of ",ADD:"+",SUB:"-",MUL:"*",DIV:"/",MOD:"%",PIPE:"",ASSIGN:"=",LP:"(",RP:")",COMMA:",",DOT:".",ID:"",LIT:"",IF:"",ELSE:""},se=new Set(Object.getOwnPropertyNames(Object.prototype));class oe{constructor(){Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}compile(e,t=i,n=s){return this.context=t,this.filters=n,e?this.compileExp(e):'""'}compileExp(e){switch(e.type){case"NOT":return this.compileNot(e);case"ID":return this.compileId(e);case"LIT":return this.compileLit(e);case"PIPE":return this.compilePipe(e);case"ASSIGN":return this.compileAssign(e);case"IS":return this.compileIs(e);case"AND":case"OR":case"EQ":case"NE":case"GT":case"LT":case"GE":case"LE":case"IN":case"NI":case"ADD":case"SUB":case"MUL":case"DIV":case"MOD":return this.compileBinary(e);case"IF":return this.compileTernary(e);case"SEQ":return this.compileSeq(e);default:return""}}compileNot({argument:e}){return`!${this.compileExp(e)}`}compileId({value:e,path:t,args:n}){let r=se.has(e)?`(Object.hasOwn(${this.context},"${e}")?${this.context}.${e}:undefined)`:`${this.context}.${e}`;return t&&(r+=t.map(e=>`.${e.value}`).join("")),n&&(r+=`(${this.compileArgs(n).join(",")})`),r}compileArgs(e){const t=[],n=[];for(const r of e)if("ASSIGN"===r.type){const{left:e,right:t}=r;n.push(`${e.value}:${this.compileExp(t)}`)}else t.push(this.compileExp(r));return n.length&&t.push(`{${n.join(",")}}`),t}compileLit({value:e}){return void 0===e?"undefined":"number"==typeof e&&e<0?`(${e})`:JSON.stringify(e)}compileSeq({elements:e}){return`(${e.map(e=>this.compileExp(e)).join(",")})`}compilePipe({left:e,right:t}){const{value:n,args:r=[]}=t,i=`(${this.filters}.${n}||u_("${n}")).call(${[this.context,this.compileExp(e),...this.compileArgs(r)].join(",")})`;return`(${o}=${i},${o} instanceof Promise?await ${o}:${o})`}compileAssign({left:e,right:t}){return"ID"===e.type?`Object.assign(${this.context},{${e.value}:${this.compileExp(t)}});`:`Object.assign(${this.context},${this.filters}.pick.call(${this.context},${this.compileExp(t)},${e.elements.map(({value:e})=>`"${e}"`).join(",")}));`}compileIs({left:e,right:t}){return`typeof ${this.compileExp(e)}===${this.compileExp(t)}`}compileBinary({type:e,left:t,right:n}){const r=`${this.compileExp(t)}${ie[e]}${this.compileExp(n)}`;return"NI"===e?`!(${r})`:r}compileTernary({test:e,consequent:t,alternative:n}){return`${this.compileExp(e)}?${this.compileExp(t)}:${n?this.compileExp(n):'""'}`}}const ae={CALL:async function({val:e,body:t,loc:n},r){r.pushRaw(n,`s+=await ${(new oe).compile(e,r.context)}(async()=>{`,'let s="";'),await r.compileNodes(t),r.pushRaw(null,"return s;",'})??"";')}};class le extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CALL"})}}const ce={compilers:ae,parsers:{call:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endcall"]);t.match(["endcall"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new le(t.parseExp(e.expression),n,e.loc,e.strip)},endcall:"unexpected"}};const ue={CAPTURE:async function({val:e,body:t,loc:n},r){r.pushRaw(n,`${r.context}.${e.value}=${s}.safe.call(${r.context},await(async(s)=>{`),await r.compileNodes(t),r.pushRaw(null,'return s;})(""));')}};class pe extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CAPTURE"})}}const he={compilers:ue,parsers:{capture:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endcapture"]);t.match(["endcapture"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new pe(t.parseExp(e.expression),n,e.loc,e.strip)},endcapture:"unexpected"}};const fe={COMMENT:async function({val:e,loc:t},n){n.options.stripComments||n.pushStr(t,`\x3c!--${e}--\x3e`)}};class de extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"COMMENT"})}}const be={compilers:fe,parsers:{comment:function*({val:e,loc:t,strip:n}){yield"NEXT",yield new de(e,t,n)}}},me="loop:{first:i_===0,index:i_++,last:i_===n_}";function ye(e,t=new Set){return!(!e||"object"!=typeof e||t.has(e))&&(t.add(e),"ASSIGN"===e.type||Object.entries(e).some(([e,n])=>"args"===e&&Array.isArray(n)?n.some(e=>ye("ASSIGN"===e.type?e.right:e,t)):ye(n,t)))}function ge(e){return e.every(e=>{switch(e.type){case"TEXT":case"COMMENT":case"BREAK":case"CONTINUE":return!0;case"OUTPUT":return!ye(e.val);case"IF":return!ye(e.test)&&ge(e.body)&&e.alternatives.every(e=>!ye(e.test)&&ge(e.body));case"FOR":return!ye(e.loop.right)&&ge(e.alternative?.body??[]);default:return!1}})}const we={FOR:async function({loop:{left:e,right:t,loc:n},body:r,alternative:i},s){const{context:o}=s,a=new oe;s.pushRaw(n,"{",`const t_=${a.compile(t,o)},`,"a_=Array.isArray(t_)?t_:Array.from(t_??[]),n_=a_.length;"),i&&(s.pushRaw(n,"if(!n_){"),await s.compileNodes(i.body),s.pushRaw(n,"}else{"));const l="SEQ"===e.type?e.elements.map(e=>"ASSIGN"===e.type?[e.left.value,`v_.${e.left.value}===undefined?${a.compile(e.right,o)}:v_.${e.left.value}`]:[e.value,`v_.${e.value}`]):[[e.value,"v_"]],c=s.in();s.pushRaw(n,"let i_=0;");const{maxLoopIterations:u}=_(s.options.security),p=null==u?[]:[`if(++li_>${u})throw new Error(${JSON.stringify(`Loop iteration limit of ${u} exceeded`)});`];ge(r)?s.pushRaw(n,`const ${c}={...${o}};`,"for(const v_ of a_){",...p,`${c}.loop={${me.slice(6)};`,...l.map(([e,t])=>`${c}.${e}=${t};`)):s.pushRaw(n,"for(const v_ of a_){",...p,`const ${c}={`,`...${o},`,`${me},`,...l.map(([e,t])=>`${e}:${t},`),"};"),await s.compileNodes(r),s.out(),s.flushable&&s.pushFlush(),s.pushRaw(null,i?"}}}":"}}")},BREAK:function({loc:e},t){t.pushRaw(e,"break;")},CONTINUE:function({loc:e},t){t.pushRaw(e,"continue;")}};class ve extends ${constructor(e,t,n,r,i){super(),Object.defineProperty(this,"loop",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"alternative",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"FOR"})}traverse(e){this.body.forEach(e),this.alternative?.body.forEach(e)}}let xe=class extends ${constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE"})}};class Oe extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"BREAK"})}}class Ee extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CONTINUE"})}}const Pe=new WeakMap;const je={for:function*(e,t){if(!e.expression)return void t.emitExpErr(e);Pe.set(t,!0),yield"NEXT";const n=t.parseUntil(["else","endfor"]);Pe.set(t,!1);let i=null;if(t.match(["else"])){const e=function*(e,t){if(e.expression)return t.emitExpErr(e,!1),yield"NEXT",void t.parseUntil(["endfor"]);yield"NEXT",yield new xe(t.parseUntil(["endfor"]),e.loc,e.strip)}(t.peek(),t);for(;;){const{value:t,done:n}=e.next();if(n)break;if(t){if("NEXT"===t){yield"NEXT";continue}i=t}}}t.match(["endfor"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc));const s=t.parseExp(e.expression);"OF"===s?.type?yield new ve(s,n,i,e.loc,e.strip):s&&t.options.debug?.(new r(`"${e.name}" expects "item of items"`,t.template,e.loc))},break:function*(e,t){e.expression?t.emitExpErr(e,!1):Pe.get(t)?(yield"NEXT",yield new Oe(e.val,e.loc,e.strip)):t.options.debug?.(new r('"break" directive used outside of a loop',t.template,e.loc))},continue:function*(e,t){e.expression?t.emitExpErr(e,!1):Pe.get(t)?(yield"NEXT",yield new Ee(e.val,e.loc,e.strip)):t.options.debug?.(new r('"continue" directive used outside of a loop',t.template,e.loc))},endfor:"unexpected"},Te={compilers:we,parsers:je};const $e={IF:async function({test:e,body:t,alternatives:n},r){r.pushRaw(e.loc,`if(${(new oe).compile(e,r.context)}){`),await r.compileNodes(t),r.pushRaw(null,"}");for(const e of n)"ELSE_IF"===e.type?r.pushRaw(e.test.loc,`else if(${(new oe).compile(e.test,r.context)}){`):r.pushRaw(null,"else{"),await r.compileNodes(e.body),r.pushRaw(null,"}")}};class ke extends ${constructor(e,t,n,r,i){super(),Object.defineProperty(this,"test",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"alternatives",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"IF"})}traverse(e){this.body?.forEach(e),this.alternatives?.forEach(t=>t.body?.forEach(e))}}class Se extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"test",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE_IF"})}}class Ne extends ${constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE"})}}function*Ie(e,t){if(!e.expression)return t.emitExpErr(e),yield"NEXT",void t.parseUntil(["else","elseif","elsif","elif","endif"]);yield"NEXT",yield new Se(t.parseExp(e.expression),t.parseUntil(["else","elseif","elsif","elif","endif"]),e.loc,e.strip)}function*Le(e,t){if(e.expression)return t.emitExpErr(e,!1),yield"NEXT",void t.parseUntil(["endif"]);yield"NEXT",yield new Ne(t.parseUntil(["endif"]),e.loc,e.strip)}const Ce={compilers:$e,parsers:{if:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["else","elseif","elsif","elif","endif"]),i=[];for(;t.match(["else","elseif","elsif","elif"]);){const e=t.peek();if("else"===e.name.toLowerCase()){const n=Le(e,t);for(;;){const{value:e,done:t}=n.next();if(t)break;if(e){if("NEXT"===e){yield"NEXT";continue}i.push(e)}}}else{const n=Ie(e,t);for(;;){const{value:e,done:t}=n.next();if(t)break;if(e){if("NEXT"===e){yield"NEXT";continue}i.push(e)}}}}t.match(["endif"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new ke(t.parseExp(e.expression),n,i,e.loc,e.strip)},elseif:"unexpected",elsif:"unexpected",elif:"unexpected",endif:"unexpected"}};const Re={INCLUDE:async function({val:{value:e},loc:t},n){n.pushRaw(t,`s+=await p[${JSON.stringify(e)}]?.()??"";`)}};class De extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"INCLUDE"})}}const Ae={compilers:Re,parsers:{include:function*(e,t){e.expression?(yield"NEXT",yield new De(t.parseExp(e.expression),e.loc,e.strip)):t.emitExpErr(e)}}};const Ue={MACRO:async function({val:{value:e,args:t},loc:n,body:r},i){const{context:s}=i,o=new oe,{maxCallDepth:a}=_(i.options.security);i.pushRaw(n,`${s}.${e}=(...a_)=>async(_c)=>{`,...null==a?[]:[`if(cd_>=${a})throw new Error(${JSON.stringify(`Macro call depth limit of ${a} exceeded`)});`,"cd_++;","try{"],'let s="";',`const ${i.in()}={`,`...${s},`,...(t??[]).map((e,t)=>"ASSIGN"===e.type?`${e.left.value}:a_[${t}]===undefined?${o.compile(e.right)}:a_[${t}],`:`${e.value}:a_[${t}],`),"};"),await i.compileNodes(r),i.out(),i.pushRaw(null,"return s;",...null==a?[]:["}finally{cd_--;}"],"};")},CALLER:function({loc:e},t){t.pushRaw(e,'s+=await _c?.()??"";')}};class Me extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"MACRO"})}}class _e extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CALLER"})}}const Fe=new WeakMap;const Xe={compilers:Ue,parsers:{macro:function*(e,t){if(!e.expression)return void t.emitExpErr(e);Fe.set(t,!0),yield"NEXT";const n=t.parseUntil(["endmacro"]);Fe.set(t,!1),t.match(["endmacro"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc));const i=t.parseExp(e.expression);if("ID"===i.type){if(i.args?.length)for(const n of i.args)if("ASSIGN"===n.type){if("ID"!==n.left.type)return void t.options.debug?.(new r("Invalid macro parameter definition",t.template,e.loc))}else if("ID"!==n.type)return void t.options.debug?.(new r("Invalid macro parameter definition",t.template,e.loc));yield new Me(i,n,e.loc,e.strip)}else t.options.debug?.(new r("Invalid macro definition",t.template,e.loc))},caller:function*(e,t){e.expression?t.emitExpErr(e,!1):Fe.get(t)?(yield"NEXT",yield new _e(e.val,e.loc,e.strip)):t.options.debug?.(new r('"caller" directive used outside of a macro',t.template,e.loc))},endmacro:"unexpected"}};const We={OUTPUT:async function({val:e},t){t.pushVar(e.loc,(new oe).compile(e,t.context))}};class Ge extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"OUTPUT"})}}const ze={compilers:We,parsers:{output:function*(e,t){yield"NEXT";const n=p(`${t.options.outputOpen}${e.strip.before?"-":""}`,{...e.loc.start});yield new Ge(t.parseExp({val:e.val,loc:{start:n,end:e.loc.end}}),e.loc,e.strip)}}};const Be={SET:async function({val:e,loc:t},n){n.pushRaw(t,(new oe).compile(e,n.context))}};class qe extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"SET"})}}const Ke={compilers:Be,parsers:{set:function*(e,t){e.expression?(yield"NEXT",yield new qe(t.parseExp(e.expression),e.loc,e.strip)):t.emitExpErr(e)}}};const Je={STYLESHEET:async function(){},STYLESHEETS:async function({loc:e},t){t.pushRaw(e,"if(!ss_u++){",'s+="<style>";',"for(const f_ of ss_)s+=await f_();",'s+="</style>";',"}")}};class Ve extends ${constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"STYLESHEET"})}}class He extends ${constructor(e,t){super(),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"STYLESHEETS"})}}const Qe={compilers:Je,parsers:{stylesheet:function*(e,t){if(e.expression)return void t.emitExpErr(e,!1);yield"NEXT";const n=t.parseUntil(["endstylesheet"]);t.match(["endstylesheet"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new Ve(n,e.loc,e.strip)},endstylesheet:"unexpected",stylesheets:function*(e,t){e.expression?t.emitExpErr(e,!1):(yield"NEXT",yield new He(e.loc,e.strip))}}};const Ye={TEXT:async function({val:e,loc:t,strip:{start:n,end:r}},i){(n||i.options.trimWhitespace)&&(e=e.replace(/^\s+/,"")),(r||i.options.trimWhitespace)&&(e=e.replace(/\s+$/,"")),i.pushStr(t,e)}};class Ze extends ${constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"TEXT"})}}const et={compilers:Ye,parsers:{text:function*(e){yield"NEXT",yield new Ze(e.val,e.loc,e.strip)}}};const tt={UNEXPECTED:async function({name:e,loc:t},n){n.pushStr(t,`\x3c!--Unexpected "${e}"--\x3e`)}};class nt extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"UNEXPECTED"})}}const rt={compilers:tt,parsers:{unexpected:function*(e,t){const n=e.name??e.type;t.options.debug?.(new r(`Unexpected "${n}"`,t.template,e.loc)),yield"NEXT",yield new nt(n,e.val,e.loc,e.strip)}}};const it={UNKNOWN:async function({name:e,loc:t},n){n.pushStr(t,`\x3c!--Unknown "${e}"--\x3e`)}};class st extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"UNKNOWN"})}}const ot={compilers:it,parsers:{unknown:function*(e,t){const n=e.name??e.type;t.options.debug?.(new r(`Unknown "${n}"`,t.template,e.loc)),yield"NEXT",yield new st(n,e.val,e.loc,e.strip)}}};const at={WITH:async function(e,t){const{context:n}=t,r=new oe;t.pushRaw(e.loc,`const ${t.in()}={...${r.compile(e.expression,n)}};`),await t.compileNodes(e.body),t.out()}};class lt extends ${constructor(e,t,n,r){super(),Object.defineProperty(this,"expression",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"WITH"})}traverse(e){this.body?.forEach(e)}}const ct=[re,ce,be,he,Te,Ce,Ae,Xe,Ke,Qe,et,ze,rt,ot,{parsers:{with:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endwith"]);t.match(["endwith"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new lt(t.parseExp(e.expression),n,e.loc,e.strip)},endwith:"unexpected"},compilers:at}];class ut extends r{constructor(e,t,n,r){super(e,t,void 0,r),Object.defineProperty(this,"src",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"getLoc",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="RenderError",ut.captureStackTrace?.(this,this.constructor)}get details(){return this.loc=this.getLoc(),super.details}}const pt=new Error("Stream cancelled");class ht{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sandbox",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"escape",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"compiling",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.options=Z(Y,{filters:J,plugins:ct},e),this.filters=Object.assign(Object.create(null),this.options.filters);const n=this.options.security?.deepEscape?X:U,{autoEscape:r}=this.options;this.escape=e=>"string"==typeof e?r?U(e):e:null==e?"":e instanceof M?`${e}`:r?n(e):e,!1!==this.options.cache?.enabled&&(this.cache=new t(this.options.cache)),this.options.security?.sandbox&&(this.sandbox=new F(this.options.security))}async render(e,t){const n=this.cache?.peek(B(e));if(n?.script&&0===n.sources.size&&n.fingerprint===q(this.options)){this.cache.get(B(e));try{return await this.run(n.script,t)}catch(t){const r=new a;return r.mappings=n.mappings,this.options.debug(this.wrapError(t,e,r)),""}}let r;try{return r=await this.compile(e),await this.run(r.script,t)}catch(t){this.options.debug(this.wrapError(t,e,r??new a))}return""}template(e){return t=>this.render(e,t)}async renderCompiled(e,t={}){try{return await this.run(e,t)}catch(e){this.options.debug(e)}return""}renderStream(e,t={}){let n,r=!1;return new ReadableStream({start:i=>{const s=e=>{if(r)throw pt;if(i.enqueue(e),(i.desiredSize??1)<=0)return new Promise(e=>{n=e})};let o;(async()=>{try{o=await this.compile(e,!0);const n=await this.run(o.script,t,s);n&&!r&&i.enqueue(n),i.close()}catch(t){if(t===pt)return;try{this.options.debug(this.wrapError(t,e,o??new a)),i.close()}catch(e){i.error(e)}}})()},pull:()=>{n?.(),n=void 0},cancel:()=>{r=!0,n?.()}})}compile(e,t=!1){const n=B(e,t);let r=this.compiling.get(n);return r||(r=new K(this.options,this.cache,this.options.cache?.revalidate??!0,t).compile(e).finally(()=>this.compiling.delete(n)),this.compiling.set(n,r)),r}wrapError(e,t,n){return"CompileError"===e?.name?e:new ut(`${e?.message??e}`,t,()=>{const t=e?.stack?.match(/<anonymous>:(\d+):(\d+)\)/);if(!t)return e?.stack??"";const[r]=n.getSourceLoc({line:+t[1]-2,column:+t[2]});return r})}run(e,t,n){const r=e(this.sandbox?{...this.sandbox.createSecureContext(this.options.globals),...t}:{...this.options.globals,...t},this.escape,this.filters,n),{timeoutMs:i}=this.options.security??{};if(null==i)return r;let s;return Promise.race([Promise.resolve(r).finally(()=>{clearTimeout(s)}),new Promise((e,t)=>{s=setTimeout(()=>{t(new Error(`Render timed out after ${i}ms`))},i)})])}async renderFile(e,t){return this.render(await this.options.loader(e),t)}clearCache(){this.cache?.clear()}invalidateCache(e){this.cache?.invalidate(e)}getCacheStats(){return this.cache?this.cache.getStats():null}resetCacheStats(){this.cache?.resetStats()}auditTemplate(e){return(new W).auditTemplate(e)}getCSPHeaders(){return new F(this.options.security).generateCSPHeaders()}}class ft{constructor(e){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"variables",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"includes",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"blocks",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"macros",{enumerable:!0,configurable:!0,writable:!0,value:new Set})}async analyze(e,t=new Set){const n=new L(this.options).parse(e);await this.nodes(n.body,t)}async nodes(e=[],t){for(const n of e)await this.node(n,t)}async node(e,t){switch(e.type){case"OUTPUT":this.exp(e.val,t);break;case"IF":this.exp(e.test,t),await this.nodes(e.body,t);for(const n of e.alternatives)this.exp(n.test,t),await this.nodes(n.body,t);break;case"FOR":{this.exp(e.loop.right,t),await this.nodes(e.alternative?.body,t);const n=new Set(t).add("loop");this.bind(e.loop.left,n,t),await this.nodes(e.body,n);break}case"SET":this.exp(e.val.right,t),this.bind(e.val.left,t,t);break;case"CAPTURE":await this.nodes(e.body,t),t.add(e.val.value);break;case"MACRO":{const n=new Set(t);for(const r of e.val.args??[])this.bind(r,n,t);t.add(e.val.value),this.macros.add(e.val.value),await this.nodes(e.body,n);break}case"CALL":this.exp(e.val,t),await this.nodes(e.body,t);break;case"WITH":this.exp(e.expression,t),await this.nodes(e.body,dt);break;case"BLOCK":this.blocks.add(e.val.value),await this.nodes(e.body,t);break;case"STYLESHEET":default:await this.nodes(e.body,t);break;case"INCLUDE":await this.include(e.val.value,t)}}async include(e,t){if(this.includes.has(e))return;let n;this.includes.add(e);try{n=await this.options.loader(e)}catch{}n&&await this.analyze(n,new Set(t))}bind(e,t,n){"ID"===e.type?t.add(e.value):"SEQ"===e.type?e.elements.forEach(e=>this.bind(e,t,n)):"ASSIGN"===e.type&&(this.exp(e.right,n),this.bind(e.left,t,n))}exp(e,t){if(e)switch(e.type){case"ID":t===dt||t.has(e.value)||this.variables.add(e.value),e.args?.forEach(e=>this.exp(e,t));break;case"LIT":break;case"NOT":this.exp(e.argument,t);break;case"IF":this.exp(e.test,t),this.exp(e.consequent,t),this.exp(e.alternative,t);break;case"SEQ":e.elements.forEach(e=>this.exp(e,t));break;case"PIPE":{const{left:n,right:r}=e;this.exp(n,t),this.filters.add(r.value);for(const e of r.args??[])this.exp("ASSIGN"===e.type?e.right:e,t);break}default:this.exp(e.left,t),this.exp(e.right,t)}}}const dt=new Set;async function bt(e,t={}){const n=new ft(Z(Q,{filters:J,plugins:ct},t));await n.analyze(e);const r=e=>[...e].sort();return{variables:r(n.variables),filters:r(n.filters),includes:r(n.includes),blocks:r(n.blocks),macros:r(n.macros)}}function mt({variables:e},{includeRuntime:t=!1}={}){const n=e.map(e=>` ${e}?: unknown;`).join("\n");return`// Generated by the Janja precompiler. Do not edit.\nimport type { ${t?"RendererOptions, ":""}Script } from 'janja';\n\n/** The data this template reads. */\nexport interface TemplateData {${n?`\n${n}\n`:""}}\n\nexport declare const script: Script;\n\n${t?"export default function render(\n data?: TemplateData,\n options?: RendererOptions,\n): Promise<string>;":"export default script;"}\n`}function yt(e){let t=e<0?-e<<1|1:e<<1,n="";do{let e=31&t;t>>>=5,t>0&&(e|=32),n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[e]}while(t>0);return n}function gt(e,{file:t,source:n,sourceContent:r,line:i}){const s=new Map;for(const t of e)s.set(t.target.start.column,t.source.start);let o=0,a=0,l=0;const c=[...s.entries()].sort(([e],[t])=>e-t).map(([e,t])=>{const n=t.line-1,r=t.column-1,i=yt(e-o)+yt(0)+yt(n-a)+yt(r-l);return o=e,a=n,l=r,i}).join(",");return{version:3,...t?{file:t}:{},sources:[n],sourcesContent:[r],names:[],mappings:`${";".repeat(i)}${c}`}}async function wt(e,{includeRuntime:t,sourceMap:n,filename:r,dts:o,...a}={}){const l=new K(Z(Q,{filters:J,plugins:ct},a));await l.compile(e);const c=`// Generated by the Janja precompiler. Do not edit.${t?"\nimport { renderCompiled } from 'janja';\n":""}\nexport function script(${i}, e, ${s}, w) {\n`,u=t?"\n}\n\nexport default function render(globals = {}, options) {\n return renderCompiled(script, globals, options);\n}\n":"\n}\n\nexport default script;\n";return{code:`${c}${l.code}${u}`,map:n?gt(l.mappings,{source:r??"template.janja",sourceContent:e,line:c.split("\n").length-1}):void 0,dts:o?mt(await bt(e,a),{includeRuntime:t}):void 0}}class vt{constructor(e={}){Object.defineProperty(this,"defaultLocale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"currentLocale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"translations",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pluralRules",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.defaultLocale=e.defaultLocale||"en",this.currentLocale=e.locale||this.defaultLocale,this.translations=e.translations||{},this.pluralRules=e.pluralRules||this.getDefaultPluralRules()}setLocale(e){this.currentLocale=e}getLocale(){return this.currentLocale}addTranslations(e,t){this.translations[e]||(this.translations[e]={}),this.translations[e]=this.mergeDeep(this.translations[e],t)}translate(e,t={}){const n=this.getTranslation(e);return n?this.interpolate(n,t):e}t(e,t={}){return this.translate(e,t)}pluralize(e,t,n={}){const r=`${e}.${this.getPluralForm(t)}`,i=this.getTranslation(r);if(i)return this.interpolate(i,{...n,count:t});const s=this.getTranslation(e);return s?this.interpolate(s,{...n,count:t}):e}formatDate(e,t){const n="string"==typeof e?new Date(e):e;return new Intl.DateTimeFormat(this.currentLocale,t).format(n)}formatNumber(e,t){return new Intl.NumberFormat(this.currentLocale,t).format(e)}formatCurrency(e,t,n){return new Intl.NumberFormat(this.currentLocale,{...n,style:"currency",currency:t}).format(e)}getTranslation(e){const t=e.split(".");let n=this.translations[this.currentLocale];for(const e of t){if(!n||"object"!=typeof n||!(e in n))return null;n=n[e]}return"string"==typeof n?n:null}interpolate(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>void 0!==t[n]?String(t[n]):n)}getPluralForm(e){const t=this.pluralRules[this.currentLocale];return t?t(e):this.pluralRules[this.defaultLocale](e)}getDefaultPluralRules(){return{en:e=>1===e?"one":"other",es:e=>1===e?"one":"other",fr:e=>0===e||1===e?"one":"other",de:e=>1===e?"one":"other",ru:e=>{const t=e%10,n=e%100;return 1===t&&11!==n?"one":t>=2&&t<=4&&!(n>=12&&n<=14)?"few":0===t||t>=5&&t<=9?"many":"other"},ja:()=>"other",zh:()=>"other",ar:e=>0===e?"zero":1===e?"one":2===e?"two":e%100>=3&&e%100<=10?"few":e%100>=11&&e%100<=99?"many":"other"}}mergeDeep(e,t){const n={...e};return this.isObject(e)&&this.isObject(t)&&Object.keys(t).forEach(r=>{this.isObject(t[r])?r in e?n[r]=this.mergeDeep(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}isObject(e){return e&&"object"==typeof e&&!Array.isArray(e)}}const xt=new vt;async function Ot(e,t={}){let n="";const{data:r={},options:i}=t,s=new ht(i);for(const t of e)n=await s.render(t,{...r,_content:n});return n}const Et={trim:!1,stripComments:!1,collapseWhitespace:!1,preserveNewlines:!0};function Pt(e){return{...Et,...e}}class jt{constructor(){Object.defineProperty(this,"mixins",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}register(e){this.mixins.set(e.name,e)}registerMultiple(e){for(const t of e)this.register(t)}get(e){return this.mixins.get(e)}has(e){return this.mixins.has(e)}delete(e){return this.mixins.delete(e)}clear(){this.mixins.clear()}list(){return Array.from(this.mixins.keys())}}const Tt=new jt;async function $t(e,t={},n=Tt){const r=n.get(e);if(!r)throw new Error(`Mixin "${e}" not found in registry`);const{data:i={},options:s}=t,o={...r.data,...i};return new ht(s).render(r.template,o)}class kt{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e})}async validate(e){const t=[],n=[],r=e=>{const[n]=e?.suggestions??[];t.push({type:"error",message:`${e?.message??e}`,line:e?.loc?.start.line,column:e?.loc?.start.column,suggestion:n?.fix??n?.message})},i=Z(Q,{filters:J,plugins:ct},this.options,{debug:r});try{const t=new L(i).parse(e);this.checkFilters(t,i.filters,n)}catch(e){r(e)}return{valid:0===t.length,errors:t,warnings:n}}checkFilters(e,t,n,r=new Set){if(e&&"object"==typeof e&&!r.has(e)){r.add(e),"PIPE"!==e.type||"ID"!==e.right?.type||Object.prototype.hasOwnProperty.call(t,e.right.value)||n.push({type:"warning",message:`Unknown filter "${e.right.value}"`,line:e.right.loc?.start.line,column:e.right.loc?.start.column});for(const i of Object.values(e))this.checkFilters(i,t,n,r)}}}const St={AND:"and",OR:"or",IS:"is",NOT:"not",EQ:"eq",NE:"ne",GT:"gt",LT:"lt",GE:"ge",LE:"le",IN:"in",NI:"ni",OF:"of",ADD:"+",SUB:"-",MUL:"*",DIV:"/",MOD:"%",PIPE:"|",ASSIGN:"=",LP:"(",RP:")",COMMA:",",DOT:".",IF:"if",ELSE:"else"};class Nt{format(e){return e?this.formatExp(e):'""'}formatExp(e){switch(e.type){case"NOT":return this.formatNot(e);case"ID":return this.formatId(e);case"LIT":return this.formatLit(e);case"PIPE":case"IS":case"ASSIGN":case"AND":case"OR":case"EQ":case"NE":case"GT":case"LT":case"GE":case"LE":case"IN":case"NI":case"OF":case"ADD":case"SUB":case"MUL":case"DIV":case"MOD":return this.formatBinary(e);case"IF":return this.formatTernary(e);case"SEQ":return this.formatSeq(e);default:return""}}formatNot({argument:e}){return`${St.NOT} ${this.formatExp(e)}`}formatId({value:e,path:t,args:n}){let r=e;return t&&(r+=t.map(e=>`.${e.value}`).join("")),n&&(r+=this.formatSeq({elements:n})),r}formatLit({value:e}){return void 0===e?"undefined":JSON.stringify(e)}formatSeq({elements:e}){return`(${e.map(e=>this.formatExp(e)).join(", ")})`}formatBinary({type:e,left:t,right:n}){return`${this.formatExp(t)} ${St[e]} ${this.formatExp(n)}`}formatTernary({test:e,consequent:t,alternative:n}){return`${this.formatExp(t)} ${St.IF} ${this.formatExp(e)}${n?` ${St.ELSE} ${this.formatExp(n)}`:""}`}}const It=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),Lt=new Set(["pre","textarea","script","style"]),Ct=new Set(["if","for","macro","block","call","capture","with","stylesheet"]),Rt=new Set(["else","elif","elseif","elsif"]),Dt=new Set(["endif","endfor","endmacro","endblock","endcall","endcapture","endwith","endstylesheet"]);function At(e,t){const n=[];let r=0,i=!0,s=0;for(;s<e.length;){if(/\s/.test(e[s])){s+=1;continue}const o=Ut(e,s,t);o?(o.piece?(n.push(o.piece),!i||"close"!==o.piece.kind&&"mid"!==o.piece.kind?i=!1:r+=1):i=!1,s=o.end):(i=!1,s+=1)}return{pieces:n,prefixClosers:r}}function Ut(e,t,n){const{commentOpen:r,directiveOpen:i,outputOpen:s}=n;if(e.startsWith(r,t))return{end:Ft(e,t+r.length,n.commentClose)};if(e.startsWith(s,t))return{end:Ft(e,t+s.length,n.outputClose)};if(e.startsWith(i,t))return function(e,t,n){const{directiveOpen:r,directiveClose:i}=n,s=Ft(e,t+r.length,i),o=e.slice(t+r.length,s-i.length),a=o.replace(/^\s*-?\s*/,"").match(/^([A-Za-z_]\w*)/)?.[1]?.toLowerCase();if(!a)return{end:s};if(Dt.has(a))return{end:s,piece:{kind:"close"}};if(Rt.has(a))return{end:s,piece:{kind:"mid"}};if(Ct.has(a))return{end:s,piece:{kind:"open"}};return{end:s}}(e,t,n);if(e.startsWith("\x3c!--",t)){const n=e.indexOf("--\x3e",t+4);return{end:-1===n?e.length:n+3}}return"<"===e[t]?function(e,t,n){if(e.startsWith("</",t)){let r=t+2;for(;r<e.length&&/\s/.test(e[r]);)r+=1;const i=r;for(;r<e.length&&/[A-Za-z0-9:-]/.test(e[r]);)r+=1;const s=e.slice(i,r).toLowerCase(),o=Mt(e,r,n);return!s||It.has(s)?{end:o}:{end:o,piece:{kind:"close",sensitive:Lt.has(s)?s:void 0}}}if(e.startsWith("<!",t)||e.startsWith("<?",t))return{end:Mt(e,t+2,n)};let r=t+1;for(;r<e.length&&/\s/.test(e[r]);)r+=1;const i=r;for(;r<e.length&&/[A-Za-z0-9:-]/.test(e[r]);)r+=1;const s=e.slice(i,r).toLowerCase(),o=Mt(e,r,n),a=e.slice(t,o),l=/\/\s*>$/.test(a)||It.has(s);if(!s||l)return{end:o};return{end:o,piece:{kind:"open",sensitive:Lt.has(s)?s:void 0}}}(e,t,n):null}function Mt(e,t,n){let r=t,i=null;for(;r<e.length;){const t=e[r];if(i){if(t===i)i=null;else{const t=_t(e,r,n);if(null!==t){r=t;continue}}r+=1;continue}const s=_t(e,r,n);if(null===s)if('"'!==t&&"'"!==t){if(">"===t)return r+1;r+=1}else i=t,r+=1;else r=s}return e.length}function _t(e,t,n){const{commentOpen:r,commentClose:i,outputOpen:s,outputClose:o,directiveOpen:a,directiveClose:l}=n;return e.startsWith(r,t)?Ft(e,t+r.length,i):e.startsWith(s,t)?Ft(e,t+s.length,o):e.startsWith(a,t)?Ft(e,t+a.length,l):null}function Ft(e,t,n){const r=e.indexOf(n,t);return-1===r?e.length:r+n.length}const Xt=e=>JSON.stringify(e,(e,t)=>"loc"===e||"raw"===e?void 0:t??null);class Wt{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options={continueOnError:!1,undefinedFallback:"",ignoreMissingFilters:!1,onError:()=>{},...e}}safeEvaluate(e,t,n={}){try{const n=this.evaluateExpression(e,t);return void 0===n&&void 0!==this.options.undefinedFallback?this.options.undefinedFallback:n}catch(r){const i={template:n.template||"",data:t,expression:e},s=this.options.onError(r,i);if(this.options.continueOnError)return s;throw r}}safeApplyFilter(e,t,n,r=[],i={}){try{if(!n){if(this.options.ignoreMissingFilters)return e;throw new Error(`Filter "${t}" is not defined`)}return n(e,...r)}catch(e){const n={template:i.template||"",data:i.data||{},filter:t},r=this.options.onError(e,n);if(this.options.continueOnError)return r;throw e}}wrapRender(e,t={}){return(...n)=>{try{return e(...n)}catch(e){const r={template:t.template||"",data:n[1]||{}},i=this.options.onError(e,r);if(this.options.continueOnError)return i;throw e}}}evaluateExpression(e,t){try{const n=e.split(".");let r=t;for(const e of n){if(null==r)return;r=r[e]}return r}catch{return}}createSafeAccessor(e){return t=>{try{const n=t.split(".");let r=e;for(const e of n){if(null==r)return this.options.undefinedFallback;r=r[e]}return void 0===r?this.options.undefinedFallback:r}catch{return this.options.undefinedFallback}}}}let Gt;const zt=new WeakMap;function Bt(e){if(!e)return Gt??(Gt=new ht);let t=zt.get(e);return t||(t=new ht(e),zt.set(e,t)),t}e.CompileError=r,e.Compiler=K,e.ErrorRecovery=Wt,e.ExpCompiler=oe,e.ExpError=u,e.ExpParser=P,e.ExpTokenizer=y,e.I18n=vt,e.MAX_INCLUDE_DEPTH=100,e.MixinRegistry=jt,e.Parser=L,e.RenderError=ut,e.Renderer=ht,e.RootNode=k,e.Safe=M,e.SecurityAuditor=W,e.SecuritySandbox=F,e.TemplatePipeline=class{constructor(e){Object.defineProperty(this,"templates",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options=e}addTemplate(e){return this.templates.push(e),this}setData(e){return this.data={...this.data,...e},this}setOptions(e){return this.options={...this.options,...e},this}async execute(){return Ot(this.templates,{data:this.data,options:this.options})}},e.TemplateValidator=kt,e.Tokenizer=I,e.Traversal=$,e.analyzeTemplate=bt,e.applyMixin=$t,e.applyMixins=async function(e,t={},n=Tt){const r=[];for(const i of e){const e=await $t(i,t,n);r.push(e)}return r},e.applyWhitespaceControl=function(e,t){let n=e;return t.stripComments&&(n=n.replace(/<!--[\s\S]*?-->/g,"")),t.collapseWhitespace&&(n=t.preserveNewlines?n.replace(/[ \t]+/g," "):n.replace(/\s+/g," ")),t.trim&&(n=n.trim()),n},e.baseOptions=V,e.compilerOptions=Q,e.composeLayout=async function(e,t,n={}){const{data:r={},options:i}=n,s=new ht({...i,autoEscape:!1}),o=await s.render(t,r);return s.render(e,{...r,content:o})},e.composeTemplates=Ot,e.composeTemplatesWithData=async function(e,t={}){let n="";const{options:r}=t,i=new ht(r);for(const t of e){const e={...t.data,_content:n};n=await i.render(t.template,e)}return n},e.composeWithSlots=async function(e,t,n={}){const{data:r={},options:i}=n,s=new ht({...i,autoEscape:!1}),o={};for(const[e,n]of Object.entries(t))o[e]=await s.render(n,r);return s.render(e,{...r,slots:o})},e.createErrorRecovery=function(e={}){return new Wt(e)},e.createFileLoader=function(e,{extensions:t=[".janja",".html"]}={}){return async n=>{const{readFile:r}=await(import("node:fs/promises")),i=await(import("node:path")),s=i.resolve(e),o=i.extname(n)?[n]:[...t.map(e=>`${n}${e}`),n];for(const e of o){const t=i.resolve(s,e);if(!t.startsWith(s+i.sep))break;try{return await r(t,"utf-8")}catch{}}throw new Error(`Template "${n}" not found in ${e}`)}},e.createMixin=function(e,t,n){return{name:e,template:t,data:n}},e.deepEscape=X,e.defaultErrorHandler=function(e,t){console.error("[Janja Error]",e.message),t.expression&&console.error(" Expression:",t.expression),t.filter&&console.error(" Filter:",t.filter)},e.defaultWhitespaceOptions=Et,e.defineFilters=function(e){return e},e.definePlugin=function(e){return e},e.expTokenTypes=h,e.extendTemplateWithMixin=async function(e,t,n={},r=Tt){const i=await $t(t,n,r);return new ht({...n.options,autoEscape:!1}).render(e,{_mixin:i})},e.filters=J,e.formatTemplate=function(t,n={}){const r={...H,...n},i=new I(r).tokenize(t),s=[0];for(let e=0;e<t.length;e++)"\n"===t[e]&&s.push(e+1);const o=({line:e,column:t})=>s[e-1]+t-1,a=new P,l=new Nt,c=(e,t)=>{try{const n=a.parse(e,t),r=l.format(n);return Xt(a.parse(r,t))!==Xt(n)?null:r.replace(/[{}]/g,"\\$&")}catch{return null}},u=i.map(n=>{const i=t.slice(o(n.loc.start),o(n.loc.end));return n.type===e.TokenType.TEXT||n.type===e.TokenType.COMMENT&&n.val.includes("\n")?i:(t=>{const n=t.strip.before?"-":"",i=t.strip.after?"-":"";if(t.type===e.TokenType.COMMENT)return`${r.commentOpen}${n} ${t.val.trim()} ${i}${r.commentClose}`;if(t.type===e.TokenType.OUTPUT){const e=c(t.val,t.loc);return e&&`${r.outputOpen}${n} ${e} ${i}${r.outputClose}`}const{name:s,expression:o}=t;if(!s)return null;const a=o?c(o.val,o.loc):"";return null!==a&&`${r.directiveOpen}${n} ${s}${a&&` ${a}`} ${i}${r.directiveClose}`})(n)||i}).join("");return!1===n.html?u:function(e,t){const n=t.tabWidth??2,r=" ".repeat(Math.max(0,n)),i=e.includes("\r\n")?"\r\n":"\n",s=e.split(/\r?\n/);let o=0,a=null;const l=[];for(const e of s){const n=e.match(/^[ \t]*/)?.[0].length??0,i=e.slice(n),{pieces:s,prefixClosers:u}=At(i,t),p=a,h=null!==p&&s.some(e=>"close"===e.kind&&e.sensitive===p);if(a&&!h){l.push(e),c(s);continue}const f=Math.max(0,o-u);l.push(0===i.length?"":r.repeat(f)+i),c(s)}return l.join(i);function c(e){for(const t of e)"open"===t.kind?(o+=1,t.sensitive&&!a&&({sensitive:a}=t)):"close"===t.kind?(o=Math.max(0,o-1),t.sensitive&&a===t.sensitive&&(a=null)):t.kind}}(u,{tabWidth:n.tabWidth,commentOpen:r.commentOpen,commentClose:r.commentClose,directiveOpen:r.directiveOpen,directiveClose:r.directiveClose,outputOpen:r.outputOpen,outputClose:r.outputClose})},e.generateDeclarations=mt,e.generateSourceMap=gt,e.getWhitespaceCompilerOptions=function(e){const t=Pt(e);return{trimWhitespace:t.trim,stripComments:t.stripComments}},e.getWhitespaceRendererOptions=function(e){const t=Pt(e),n={};return t.trim!==Et.trim&&(n.trimWhitespace=t.trim),t.stripComments!==Et.stripComments&&(n.stripComments=t.stripComments),n},e.globalMixinRegistry=Tt,e.i18n=xt,e.isForbiddenIdentifier=d,e.mergeOptions=Z,e.mergeWhitespaceOptions=Pt,e.optionsFingerprint=q,e.parserOptions=H,e.precompile=wt,e.precompileTemplate=async function(e,t={}){return(await wt(e,t)).code},e.render=async function(e,t,n){return Bt(n).render(e,t)},e.renderCompiled=async function(e,t={},n){return Bt(n).renderCompiled(e,t)},e.renderFile=async function(e,t,n){return Bt(n).renderFile(e,t)},e.renderOptions=Y,e.renderStream=function(e,t={},n){return Bt(n).renderStream(e,t)},e.resolveSecurityLimits=_,e.templateCacheKey=B,e.validateTemplate=async function(e,t){return new kt(t).validate(e)}}(this.janja=this.janja||{});
|
|
1
|
+
!function(e){"use strict";class t{constructor(e={}){Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ttl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.cache=new Map,this.maxSize=e.maxSize??1e3,this.ttl=e.ttl??36e5,this.stats={hits:0,misses:0,evictions:0}}get(e){const t=this.cache.get(e);return t?this.ttl>0&&Date.now()-t.timestamp>this.ttl?(this.cache.delete(e),this.stats.misses++,null):(this.cache.delete(e),this.cache.set(e,t),t.hits++,this.stats.hits++,t.value):(this.stats.misses++,null)}peek(e){const t=this.cache.get(e);return!t||this.ttl>0&&Date.now()-t.timestamp>this.ttl?null:t.value}set(e,t){if(this.cache.size>=this.maxSize&&!this.cache.has(e)){const e=this.cache.keys().next().value;void 0!==e&&(this.cache.delete(e),this.stats.evictions++)}this.cache.set(e,{value:t,timestamp:Date.now(),hits:0})}has(e){const t=this.cache.get(e);return!!t&&(!(this.ttl>0&&Date.now()-t.timestamp>this.ttl)||(this.cache.delete(e),!1))}delete(e){return this.cache.delete(e)}clear(){this.cache.clear(),this.stats={hits:0,misses:0,evictions:0}}invalidate(e){if(e)for(const t of this.cache.keys())e(t)&&this.cache.delete(t);else this.clear()}getStats(){return{...this.stats,size:this.cache.size,hitRate:this.stats.hits+this.stats.misses>0?this.stats.hits/(this.stats.hits+this.stats.misses):0}}resetStats(){this.stats={hits:0,misses:0,evictions:0}}}function n(e,t,n){const r=[];if("ExpError"===e&&(t.includes("Unexpected end of expression")&&r.push({message:"The expression is incomplete. Make sure you have closed all parentheses, brackets, and quotes.",fix:"Check for missing closing characters: ), ], }"}),t.includes('Expected "RP" after "LP"')&&r.push({message:"Missing closing parenthesis in your expression.",fix:"Add a closing parenthesis ) to match the opening one.",example:"(foo.bar) instead of (foo.bar"}),t.includes("No left operand")&&r.push({message:"An operator is missing its left operand.",fix:"Add a value or variable before the operator.",example:"x + 1 instead of + 1"}),t.includes("No right operand")&&r.push({message:"An operator is missing its right operand.",fix:"Add a value or variable after the operator.",example:"x + 1 instead of x +"}),t.includes('Expected "ID" after "PIPE"')&&r.push({message:"The pipe operator | must be followed by a filter name.",fix:"Add a filter name after the pipe.",example:"value|upper instead of value|"}),t.includes('Expected "ID" after "DOT"')&&r.push({message:"The dot operator . must be followed by a property name.",fix:"Add a property name after the dot.",example:"object.property instead of object."}),t.includes("Left operand of assignment must be an identifier")&&r.push({message:"Assignment targets must be valid identifiers.",fix:"Use a simple variable name or sequence of variable names.",example:"x = 1 or (a, b) = [1, 2]"}),t.includes("Expected test expression")&&r.push({message:"The conditional expression is missing its test condition.",fix:"Add a condition after the if keyword.",example:"if x > 0 then y else z"}),t.includes("Expected alternative expression")&&r.push({message:"The conditional expression is missing its else clause.",fix:"Add an alternative expression after then.",example:"if x > 0 then y else z"}),t.startsWith("Unexpect")&&r.push({message:"An unexpected character was found in the expression.",fix:"Check for typos or invalid characters in your expression."})),"CompileError"===e){if(t.includes("Unclosed")){const e=t.match(/Unclosed "([^"]+)"/),n=e?e[1]:"marker";r.push({message:`The ${n} marker is not closed properly.`,fix:`Add the closing marker for ${n}.`,example:"{%"===n?"{% ... %}":"{#"===n?"{# ... #}":"{{ ... }}"})}t.includes("Unexpected")&&r.push({message:"An unexpected token was found in the template.",fix:"Check your template syntax and ensure all markers are properly formatted."})}return n&&r.push({message:"Context information:",fix:n}),r}class r extends SyntaxError{constructor(e,t,n,i){super(e),Object.defineProperty(this,"src",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:i}),this.name="CompileError",r.captureStackTrace?.(this,this.constructor)}get details(){const e=this.loc?function(e,t,{start:{line:n,column:r},end:{line:i,column:s}}){const o=[],a=new Set,l=e=>{a.add(e-2),a.add(e-1),a.add(e),a.add(e+1),a.add(e+2)},c=t.split("\n"),u=String(c.length).length+2;let p=0;c.forEach((e,t)=>{if(e){if(o.push(`${`${t+1}│ `.padStart(u," ")}${e}`),n===t+1){const e=`${" ".repeat(u-2)}│ ${" ".repeat(r-1)}^${n===i&&s>r+1?`${" ".repeat(s-r-2)}^`:""}`;/\S/.test(e)&&o.push(e),l(++p+t)}if(n!==i&&i===t+1){const e=`${" ".repeat(u-2)}│ ${" ".repeat(s-1)}${"^".repeat(1)}`;/\S/.test(e)&&o.push(e),l(++p+t)}}});const h=`${" ".repeat(u)}...`;return`${e}\n\n${o.map((e,t)=>a.has(t)?e:h).reduce((e,t)=>t===h&&e.at(-1)===t?e:[...e,t],[]).join("\n")}\n`}(this.message,this.src,this.loc):this.message;return function(e,t,r,i){const s=n(e,t,i);return 0===s.length?r:`${r}\n\nSuggestions:\n${s.map((e,t)=>{let n=` ${t+1}. ${e.message}`;return e.fix&&(n+=`\n Fix: ${e.fix}`),e.example&&(n+=`\n Example: ${e.example}`),n}).join("\n")}`}(this.name,this.message,e,this.context)}get suggestions(){return n(this.name,this.message,this.context)}}const i="c",s="f",o="r_";class a{constructor(){Object.defineProperty(this,"mappings",{enumerable:!0,configurable:!0,writable:!0,value:[]})}addMapping(e,t){this.mappings.push({source:e,target:t})}getSourceLoc({line:e,column:t}){return this.mappings.filter(({target:{start:n,end:r}})=>n.line<=e&&r.line>=e&&(n.line<e||n.column<=t)&&(r.line>e||r.column>=t)).map(({source:e})=>e)}}class l extends a{constructor(){super(...arguments),Object.defineProperty(this,"codeParts",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"codeLength",{enumerable:!0,configurable:!0,writable:!0,value:0})}get code(){return this.codeParts.join("")}set code(e){this.codeParts=[e],this.codeLength=e.length}get script(){return new Function(i,"e",s,"w",this.code)}checkpoint(){return[this.codeParts.length,this.mappings.length,this.codeLength]}rollback(e){const[t,n,r]=e;this.codeParts.length=t,this.mappings.length=n,this.codeLength=r}start(e=!0){this.pushRaw(null,"return(async()=>{",`let s="",${o};`),e&&this.pushRaw(null,"const u_=(n)=>{throw new Error('Unknown filter \"'+n+'\"')};")}end(){this.pushRaw(null,"return s;","})();")}pushRaw(e,...t){const n=this.codeLength;for(const e of t)this.codeParts.push(e),this.codeLength+=e.length;e&&this.addMapping(e,{start:{line:1,column:n},end:{line:1,column:this.codeLength}})}pushStr(e,t){t&&this.pushRaw(e,`s+=${JSON.stringify(t)};`)}pushFlush(){this.pushRaw(null,'if(s.length>1024){await w(s);s="";}')}pushVar(e,t){this.pushRaw(e,`s+=e(${t});`)}}class c extends l{constructor(){super(...arguments),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"stack",{enumerable:!0,configurable:!0,writable:!0,value:[i]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0})}checkpoint(){return[super.checkpoint(),this.context,[...this.stack]]}rollback(e){const[t,n,r]=e;super.rollback(t),this.context=n,this.stack=r}in(){return this.context=`${this.context}_${this.index++}`,this.stack.push(this.context),this.context}out(){this.context!==i&&(this.stack.pop(),this.context=this.stack.at(-1))}}class u extends SyntaxError{constructor(e,t,n){super(e),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="ExpError",u.captureStackTrace?.(this,this.constructor)}get suggestions(){return n(this.name,this.message,this.context)}get details(){const{suggestions:e}=this;if(0===e.length)return this.message;const t=e.map((e,t)=>{let n=` ${t+1}. ${e.message}`;return e.fix&&(n+=`\n Fix: ${e.fix}`),e.example&&(n+=`\n Example: ${e.example}`),n}).join("\n");return`${this.message}\n\nSuggestions:\n${t}`}}function p(e,t){const n=(e.match(/\n/g)||[]).length;if(n>0){t.line+=n;const r=e.lastIndexOf("\n");t.column=e.length-r}else t.column+=e.length;return{line:t.line,column:t.column}}const h={and:"AND",or:"OR",not:"NOT",is:"IS",eq:"EQ",ne:"NE",gt:"GT",lt:"LT",ge:"GE",le:"LE",in:"IN",ni:"NI",of:"OF",with:"WITH","+":"ADD","-":"SUB","*":"MUL","/":"DIV","%":"MOD",if:"IF",else:"ELSE",true:"LIT",false:"LIT",null:"LIT",undefined:"LIT","|":"PIPE","=":"ASSIGN","(":"LP",")":"RP",",":"COMMA",".":"DOT"},f=new Set(["constructor","prototype","__proto__","__defineGetter__","__defineSetter__","__lookupGetter__","__lookupSetter__"]);function d(e){return"string"==typeof e&&f.has(e)}const b={n:"\n",t:"\t",r:"\r","\\":"\\",'"':'"',"'":"'","`":"`"};function m(e){switch(e){case"true":return!0;case"false":return!1;case"null":return null;case"undefined":return;default:return e}}class y{constructor(){Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1})}tokenize(e,t){for(this.val=e,this.index=0,this.line=t.start.line,this.column=t.start.column,this.tokens=[];this.index<this.val.length;){const e=this.val[this.index];if(g(e))"\n"===e?(this.line++,this.column=1):this.column++,this.index++;else if("'"!==e&&'"'!==e&&"`"!==e)if(v(e)||"-"===e&&v(this.val[this.index+1]??"")&&!this.afterOperand())this.readNumber(e);else if(x(e))this.readIdentifier(e);else{if(!w(e))throw new u(`Unexpected "${e}"`,{start:{line:this.line,column:this.column},end:{line:this.line,column:this.column+1}});this.readSymbol(e)}else this.readString(e)}return this.tokens}afterOperand(){const e=this.tokens.at(-1)?.type;return"ID"===e||"LIT"===e||"RP"===e}readString(e){let t="",n="",r=!1;const i={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const i=this.val[this.index];if(r)t+=b[i]??`\\${i}`,n+=i,r=!1;else if("\\"===i)n+=i,r=!0;else{if(i===e)break;t+=i,n+=i}this.index++}this.index++,this.tokens.push({type:"LIT",value:t,loc:{start:i,end:p(`${e}${n}${e}`,this)},raw:`${e}${n}${e}`})}readNumber(e){let t=e,n=!1;const r={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const e=this.val[this.index];if(v(e))t+=e;else{if("."!==e||n)break;t+=e,n=!0}this.index++}this.tokens.push({type:"LIT",value:Number.parseFloat(t),loc:{start:r,end:p(t,this)},raw:t})}readIdentifier(e){let t=e;const n={line:this.line,column:this.column};for(this.index++;this.index<this.val.length;){const e=this.val[this.index];if(!O(e))break;t+=e,this.index++}if(d(t))throw new u(`"${t}" is not allowed in expressions`,{start:n,end:{line:this.line,column:this.column+t.length}});const r=Object.prototype.hasOwnProperty.call(h,t)?h[t]:"ID";this.tokens.push({type:r,value:"LIT"===r?m(t):t,loc:{start:n,end:p(t,this)},raw:t})}readSymbol(e){const t={line:this.line,column:this.column};this.index++,this.tokens.push({type:h[e],value:e,loc:{start:t,end:p(e,this)},raw:e})}}function g(e){return/\s/.test(e)}function w(e){return/[+\-*/%|=(),.]/.test(e)}function v(e){return/\d/.test(e)}function x(e){return/[a-z_$]/i.test(e)}function O(e){return/[\w$]/.test(e)}const E={COMMA:5,IF:10,ELSE:10,ASSIGN:15,LP:20,RP:20,OR:25,AND:30,IS:40,EQ:40,NE:40,GT:40,LT:40,GE:40,LE:40,IN:40,NI:40,OF:40,WITH:40,ADD:50,SUB:50,MUL:60,DIV:60,MOD:60,NOT:70,PIPE:80,DOT:90,ID:90,LIT:90};class P{constructor(){Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:""}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1})}parse(e,t){return this.val=e,this.index=0,this.line=t.start.line,this.column=t.start.column,this.tokens=(new y).tokenize(e,t),this.val?this.parseExp():null}parseExp(e){let t=null;for(;;){const n=this.next();if(!n)break;const r=e?.(n);if("BACK"===r){this.back();break}if("BREAK"===r)break;if(t&&$(n),"LP"===n.type){if(!this.peek())throw new u("Unexpected end of expression",n.loc);const e=this.parseSequence(),r=this.consume("RP");if(!r)throw new u('Expected "RP" after "LP"',n.loc);t={...n,type:"SEQ",elements:e,loc:{start:n.loc.start,end:r.loc.end}};continue}if("NOT"!==n.type){if("ID"===n.type){t={...n,type:"ID",value:n.value},this.match("DOT")&&(t.path=this.parsePath());const e=this.consume("LP");if(e){if(t.args=this.parseSequence(),!this.consume("RP"))throw new u('Expected "RP" after "LP"',e.loc);continue}continue}if("LIT"!==n.type){if("IF"===n.type){const e=this.parseExp(e=>"ELSE"===e.type||S(n,e)?"BACK":void 0);if(!e)throw new u("Expected test expression",n.loc);if(t={...n,type:"IF",test:e,consequent:t},this.consume("ELSE")){const e=this.parseExp(e=>S(n,e)?"BACK":void 0);if(!e)throw new u("Expected alternative expression",n.loc);t.alternative=e}continue}if(j(n.type)){if(!t)throw new u(`No left operand for "${n.type}"`,n.loc);"ASSIGN"===n.type&&k(t,n);const e=this.parseExp(e=>S(n,e)?"BACK":void 0);if(!e)throw new u(`No right operand for "${n.type}"`,n.loc);t={...n,type:n.type,left:t,right:e};continue}if("PIPE"!==n.type){this.back();break}if(!t)throw new u(`No left operand for "${n.type}"`,n.loc);if(!this.match("ID"))throw new u('Expected "ID" after "PIPE"',n.loc);t={...n,type:"PIPE",left:t,right:this.parsePipe()}}else t={...n,type:"LIT"}}else{if(!this.peek())throw new u("Unexpected end of expression",n.loc);t={...n,type:"NOT",argument:this.parseExp(e=>S(n,e)?"BACK":void 0)}}}return t}parsePath(){const e=[];for(;;){const t=this.consume("DOT");if(!t)break;const n=this.next();if(!n)throw new u('Expected "ID" after "DOT"',t.loc);if("ID"!==n.type)throw new u('Expected "ID" after "DOT"',t.loc);e.push({...n,type:"ID",value:n.value})}return e}parseSequence(){const e=[];for(;!this.match("RP");){const t=this.parseExp(e=>"COMMA"===e.type?"BREAK":void 0);if(!t)break;e.push(t)}return e}parsePipe(){const e=this.next(),t={...e,type:"ID",value:e.value},n=this.consume("LP");if(n&&(t.args=this.parseSequence(),!this.consume("RP")))throw new u('Expected "RP" after "LP"',n.loc);return t}next(){return this.tokens[this.index++]??null}back(){return this.tokens[this.index--]}peek(){return this.tokens.at(this.index)??null}match(e){return this.peek()?.type===e}consume(e){if(this.match(e))return this.next()}}const T=new Set(["AND","OR","IS","EQ","NE","GT","LT","GE","LE","IN","NI","OF","WITH","ADD","SUB","MUL","DIV","MOD","ASSIGN"]);function j(e){return T.has(e)}function $(e){if("ID"===e.type||"LIT"===e.type||"LP"===e.type)throw new u(`Unexpected "${e.raw??e.value}"`,e.loc)}function k(e,t){if("SEQ"===e.type){if(e.elements.some(e=>"ID"!==e.type||e.path||e.args))throw new u("Left operand of assignment must be an identifier or a sequence of identifiers",t.loc)}else if("ID"!==e.type||e.path||e.args)throw new u("Left operand of assignment must be an identifier or a sequence of identifiers",t.loc)}function S(e,t){return"LP"!==t.type&&E[e.type]>E[t.type]}class N{constructor(){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}traverse(e){this.body?.forEach(e)}}class I extends N{constructor(e,t){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"TEMPLATE"})}}var L;function C(e){return e.replace(/\\([{}])/g,"$1")}e.TokenType=void 0,(L=e.TokenType||(e.TokenType={})).TEXT="TEXT",L.OUTPUT="OUTPUT",L.DIRECTIVE="DIRECTIVE",L.COMMENT="COMMENT";class R{constructor(t){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"length",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"index",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tokenPatterns",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"markerIndices",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"line",{enumerable:!0,configurable:!0,writable:!0,value:1}),Object.defineProperty(this,"column",{enumerable:!0,configurable:!0,writable:!0,value:1});const{commentOpen:n,commentClose:r,directiveOpen:i,directiveClose:s,outputOpen:o,outputClose:a}=this.options;this.tokenPatterns=[[e.TokenType.COMMENT,n,r],[e.TokenType.DIRECTIVE,i,s],[e.TokenType.OUTPUT,o,a]].sort(([,e],[,t])=>e.length>t.length?-1:1),this.markerIndices=new Map;for(const[,e]of this.tokenPatterns)e.length>0&&this.markerIndices.set(e[0],this.markerIndices.get(e[0])||0)}tokenize(e){for(this.template=e,this.length=e.length,this.index=0,this.line=1,this.column=1,this.tokens=[];this.index<this.length;)this.consumeSpecialTokens()||this.consumeTextToken();return this.tokens}consumeSpecialTokens(){return this.tokenPatterns.some(([t,n,i])=>{if(!this.lookahead(n))return!1;const s={line:this.line,column:this.column},o=this.template.indexOf(i,this.index+n.length);if(-1===o)throw new r(`Unclosed "${n}"`,this.template,{start:s,end:p(n,{...s})});const a=this.lookahead("-",n.length),l="-"===this.template[o-1],c=this.template.slice(this.index+n.length+ +a,o-+l),u=p(this.template.slice(this.index,this.index=o+i.length),this),h={type:t,val:C(c),strip:{before:a,after:l},loc:{start:s,end:u}};if(t===e.TokenType.DIRECTIVE){let e=0,t="";for(;e<c.length;){const n=c[e];if(/\S/.test(n))t+=n;else if(t)break;e++}Object.assign(h,{name:t,expression:e===c.length||/^\s*$/m.test(c.slice(e+1))?null:{val:c.slice(e+1),loc:{start:p(c.slice(0,e+1),p(`${n}${a?"-":""}`,{...s})),end:{line:this.line,column:this.column-i.length-+l}}}})}return this.tokens.push(h),!0})}consumeTextToken(){const t=this.findNextSpecialIndex(),n={line:this.line,column:this.column},r=this.template.slice(this.index,t);this.tokens.push({type:e.TokenType.TEXT,val:C(r),loc:{start:n,end:p(r,this)},strip:{}}),this.index=t}lookahead(e,t=0){return this.template.startsWith(e,this.index+t)}findNextSpecialIndex(){const{outputOpen:e,directiveOpen:t,commentOpen:n}=this.options;let r=this.length;for(let i=this.index;i<this.length;i++){if(this.template.startsWith(n,i)){r=i;break}if(this.template.startsWith(t,i)){r=i;break}if(this.template.startsWith(e,i)){r=i;break}}return r}}class D extends R{constructor(){super(...arguments),Object.defineProperty(this,"expParser",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cursor",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}parse(t){this.tokenize(t),this.tokens.forEach((t,n)=>{t.type===e.TokenType.TEXT&&(this.tokens[n-1]?.strip?.after&&(t.strip.start=!0),this.tokens[n+1]?.strip?.before&&(t.strip.end=!0))});const n=this.tokens[0]?.loc.start??{line:1,column:1},r=this.tokens.at(-1)?.loc.end??{line:1,column:1};return this.expParser=new P,this.cursor=0,new I(this.parseUntil(),{start:n,end:r})}parseUntil(t){const n=[];let r=null;for(;;){const i=this.peek();if(!i||i.type===e.TokenType.DIRECTIVE&&t&&this.match(t,i))break;r?.strip?.after&&i.type===e.TokenType.TEXT&&(i.strip.start=!0),i.strip?.before&&r?.type===e.TokenType.TEXT&&(r.strip.end=!0);let s=this.options.parsers[i.name?.toLowerCase()??i.type?.toLowerCase()];"string"==typeof s&&(s=this.options.parsers[s]),s||(s=this.options.parsers.unknown);const{cursor:o}=this,a=s?.(i,this);if(a)for(;;){const{value:e,done:t}=a.next();if(t)break;"NEXT"===e?this.advance():e&&n.push(e)}this.cursor===o&&this.advance(),r=i}return n}parseExp({val:e,loc:t}){try{return this.expParser.parse(e,t)}catch(e){this.options.debug(e.loc?new r(e.message,this.template,e.loc):e)}}peek(){return this.tokens.at(this.cursor)??null}advance(){this.cursor++}match(e,t=this.peek()){return e.includes(t?.name?.toLowerCase())}emitExpErr({name:e,loc:t},n=!0){this.options.debug(new r(n?`"${e}" requires expression`:`"${e}" should not have expression`,this.template,t))}}const A=/[&<>"']/,U=/[&<>"']/g,M={"&":"&",'"':""","'":"'","<":"<",">":">"},_=e=>M[e];function F(e){const t="string"==typeof e?e:`${e}`;return A.test(t)?t.replace(U,_):t}class X extends String{constructor(e){super(`${e}`)}}function W(e={}){return{maxIncludeDepth:e.maxIncludeDepth??100,maxLoopIterations:e.maxLoopIterations,maxCallDepth:e.maxCallDepth,timeoutMs:e.timeoutMs}}class G{constructor(e={}){Object.defineProperty(this,"allowedGlobals",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cspNonce",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.allowedGlobals=new Set(e.allowedGlobals||[]),this.cspNonce=e.cspNonce}sanitizeGlobals(e){const t={};for(const[n,r]of Object.entries(e))this.allowedGlobals.has(n)&&(t[n]=r);return t}validateExpression(e){const t=[/\bprocess\b/,/\brequire\b/,/\bimport\b/,/\bexport\b/,/\beval\b/,/\bFunction\b/,/\b__proto__\b/,/\bconstructor\b/];for(const n of t)if(n.test(e))return!1;return!0}createSecureContext(e){return{...this.sanitizeGlobals(e),Math:Math,Date:Date,JSON:JSON}}getCSPNonce(){return this.cspNonce}generateCSPHeaders(){const e={};return this.cspNonce&&(e["Content-Security-Policy"]=`script-src 'nonce-${this.cspNonce}'`),e}}function z(e,t=new WeakSet){if(null==e)return"";if(e instanceof X)return`${e}`;if("object"==typeof e){if(t.has(e))return"";t.add(e);return(Array.isArray(e)?e:Object.values(e)).map(e=>z(e,t)).join("")}return F(e)}class B{auditTemplate(e){const t=[],n=[{pattern:/\beval\s*\(/,type:"dangerous-eval",message:"Use of eval() is dangerous and should be avoided",severity:"critical"},{pattern:/\bFunction\s*\(/,type:"dangerous-function",message:"Use of Function constructor is dangerous",severity:"critical"},{pattern:/\brequire\s*\(/,type:"require-usage",message:"Direct require() usage in templates is unsafe",severity:"high"},{pattern:/\bimport\s*\(/,type:"dynamic-import",message:"Dynamic import() usage in templates may be unsafe",severity:"high"}];for(const{pattern:r,type:i,message:s,severity:o}of n){const n=e.match(r);n&&t.push({type:i,message:s,location:`at index ${n.index}`,severity:o})}return{issues:t,severity:this.calculateOverallSeverity(t)}}calculateOverallSeverity(e){if(0===e.length)return"low";const t={critical:4,high:3,medium:2,low:1},n=Math.max(...e.map(e=>t[e.severity]));return Object.entries(t).find(([,e])=>e===n)[0]}}const q=new WeakMap,K=new Set(["IF","FOR"]);function H(e,t=!1){return t?`\0stream:${e}`:e}function J(e){let t=q.get(e);if(void 0===t){const{trimWhitespace:n,stripComments:r,commentOpen:i,commentClose:s,directiveOpen:o,directiveClose:a,outputOpen:l,outputClose:c}=e,{maxIncludeDepth:u,maxLoopIterations:p,maxCallDepth:h}=W(e.security);t=JSON.stringify([n,r,i,s,o,a,l,c,u,p??null,h??null]),q.set(e,t)}return t}class V extends c{constructor(e,t,n=!0,r=!1){super(),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"revalidate",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"stream",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"template",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isRoot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"rootNode",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"partials",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"blocks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stylesheets",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"stylesheetKey",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sources",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"compiled",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flushable",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.cache=t}async compile(e,t=!0,n=new Map,r=new Map,s=new Map,o=new Map,a="\0root"){this.template=e,this.isRoot=t,this.partials=n,this.blocks=r,this.stylesheets=o,this.stylesheetKey=a,this.sources=s;const l=this.generateCacheKey(e);if(this.cache&&t){const e=this.cache.get(l);if(e){if(e.fingerprint===this.fingerprint()&&await this.isFresh(e))return this.code=e.code,this.mappings=e.mappings,this.compiled=e,this;this.cache.delete(l)}}if(this.rootNode=new D(this.options).parse(e),this.state={},this.start(this.isRoot),this.isRoot&&(this.pushResourceLimitCounters(),this.pushRaw(null,"let ss_u=0;")),await this.parseTemplates(),this.isRoot){if(this.partials.size){const{maxIncludeDepth:e}=W(this.options.security);this.pushRaw(null,`const tc_=${i};`,"let d_=0;","const p={");for(const[t,n]of this.partials)this.pushRaw(null,`${JSON.stringify(t)}:async(c)=>{`,`if(d_>=${e})throw new Error(${JSON.stringify(`Includes of ${JSON.stringify(t)} are nested too deeply`)});`,"d_++;","try{return await(async()=>{",n,"})();}finally{d_--;}","},");this.pushRaw(null,"};")}if(this.blocks.size){this.pushRaw(null,"const b={");for(const[e,t]of this.blocks){this.pushRaw(null,`${JSON.stringify(e)}:{`,"u:0,","s:["),this.state.block=e;for(const e of t)this.pushRaw(null,"async()=>{",'let s="";'),await this.compileNodes(e.body),this.pushRaw(null,"return s;","},");this.state.block=void 0,this.pushRaw(null,"],","},")}this.pushRaw(null,"};")}this.pushRaw(null,"const ss_=[");for(const[,e]of this.stylesheets){this.pushRaw(null,"async()=>{",'let s="";');for(const t of e)await this.compileNodes(t.body);this.pushRaw(null,"return s;","},")}this.pushRaw(null,"];")}return this.flushable=this.isRoot&&this.stream,await this.compileNode(this.rootNode),this.flushable=!1,this.end(),this.cache&&t&&(this.compiled={code:this.code,mappings:this.mappings,sources:this.sources,fingerprint:this.fingerprint()},this.cache.set(l,this.compiled)),this}get script(){var e;return this.compiled?(e=this.compiled).script??(e.script=super.script):super.script}generateCacheKey(e){return H(e,this.stream)}fingerprint(){return J(this.options)}pushResourceLimitCounters(){const{maxLoopIterations:e,maxCallDepth:t}=W(this.options.security);null!=e&&this.pushRaw(null,"let li_=0;"),null!=t&&this.pushRaw(null,"let cd_=0;")}async isFresh({sources:e}){if(!this.revalidate)return!0;try{for(const[t,n]of e)if(await this.options.loader(t)!==n)return!1}catch{return!1}return!0}async parseTemplates(){const{partials:e,blocks:t,stylesheets:n}=this.collectPartialsAndBlocks();for(const[t,n]of e)if(!this.partials.has(t)){let e;try{e=await this.options.loader(t)}catch{throw new r(`Failed to load template from "${t}"`,this.template,n.loc)}this.sources.set(t,e??""),this.partials.set(t,""),e&&await this.compilePartial(t,n,e)}for(const e of t){const{val:{value:t}}=e;this.blocks.has(t)||this.blocks.set(t,[]),this.blocks.get(t).push(e)}n.length&&!this.stylesheets.has(this.stylesheetKey)&&this.stylesheets.set(this.stylesheetKey,n)}collectPartialsAndBlocks(){const e=new Map,t=[],n=[],r=i=>{"INCLUDE"===i.type&&(e.has(i.val.value)||e.set(i.val.value,i)),"BLOCK"===i.type&&t.push(i),"STYLESHEET"===i.type&&n.push(i),i.traverse(r)};return r(this.rootNode),{partials:e,blocks:t,stylesheets:n}}async compileNode(e){if("TEMPLATE"===e.type){for(const t of e.body)await this.compileNode(t),this.flushable&&"TEXT"!==t.type&&this.pushFlush();return}let t=this.options.compilers[e.type];"string"==typeof t&&(t=this.options.compilers[t]),t||(t=this.options.compilers.UNKNOWN);const n=this.checkpoint(),{flushable:i}=this;K.has(e.type)||(this.flushable=!1);try{await(t?.(e,this))}catch(t){if(this.flushable=i,"CompileError"===t?.name)throw t;this.rollback(n),this.options.debug(new r(`Invalid "${e.type.toLowerCase()}" directive`,this.template,e.loc))}this.flushable=i}async compileNodes(e){for(const t of e)await this.compileNode(t)}async compilePartial(e,t,n){try{const{code:t}=await new V(this.options).compile(n,!1,this.partials,this.blocks,this.sources,this.stylesheets,e);this.partials.set(e,t)}catch{this.options.debug(new r("Failed to compile template",this.template,t.loc))}}}var Q=Object.freeze({__proto__:null,abs:function(e=0){return Math.abs(e)},add:function(e=0,t=0){return e+t},capitalize:function(e=""){return e.replace(/\b\w/g,e=>e.toUpperCase())},ceil:function(e=0){return Math.ceil(e)},chunk:function(e,t){const n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n},compact:function(e=[]){return e.filter(e=>null!=e)},currency:function(e,t="USD",n="en-US"){return new Intl.NumberFormat(n,{style:"currency",currency:t}).format(e)},date:function(e,t="ISO"){const n=e instanceof Date?e:new Date(e);if(isNaN(n.getTime()))return"";switch(t){case"ISO":default:return n.toISOString();case"date":return n.toISOString().split("T")[0];case"time":return n.toTimeString().split(" ")[0];case"locale":return n.toLocaleDateString();case"locale-time":return n.toLocaleTimeString();case"locale-datetime":return n.toLocaleString()}},defaults:function(e,t){return{...t,...e}},delay:async function(e,t){return await new Promise(e=>setTimeout(e,t)),e},div:function(e=0,t=1){return e/t},entries:function(e={}){return Object.entries(e)},escape:F,even:function(e=0){return+e%2==0},fallback:function(e,t,n=!1){return n?e||t:e??t},fetchUrl:async function(e,t={}){return(await fetch(e,t)).text()},first:function(e=[]){return[...e][0]},fixed:function(e,t=2){return Number(e).toFixed(t)},get:function(e,...t){return t.reduce((e,t)=>e&&"object"==typeof e&&!d(t)&&t in e?e[t]:void 0,e)},groupby:function(e=[],t){return e.reduce((e,n)=>{const r=n[t];return{...e,[r]:[...e[r]||[],n]}},{})},invert:function(e){return Object.entries(e).reduce((e,[t,n])=>({...e,[String(n)]:t}),{})},join:function(e=[],t=""){return[...e].join(t)},json:function(e=null,t=0){return new X(JSON.stringify(e,null,t))},keys:function(e={}){return Object.keys(e)},last:function(e=[]){return[...e].reverse()[0]},length:function(e=""){return e.length},lower:function(e=""){return e.toLowerCase()},map:function(e=[],t,n){return e.map(e=>d(t)?n:e[t]??n)},max:function(e=0,...t){return Math.max(e,...t)},merge:function(e,...t){return Object.assign({},e,...t)},min:function(e=0,...t){return Math.min(e,...t)},mul:function(e=0,t=1){return e*t},odd:function(e=0){return+e%2==1},omit:function(e={},...t){return Object.entries(e).reduce((e,[n,r])=>t.includes(n)?e:{...e,[n]:r},{})},percent:function(e,t=0){return`${(100*e).toFixed(t)}%`},pick:function(e={},...t){return t.reduce((t,n)=>d(n)?t:{...t,[n]:e[n]},{})},pluck:function(e,t){return e.map(e=>e[t])},repeat:function(e="",t=0){return e.repeat(t)},replace:function(e="",t,n){return e.replace(new RegExp(t,"g"),n)},reverse:function(e=[]){return Array.isArray(e)?[...e].reverse():[...e].reverse().join("")},round:function(e,t=0){return Number(`${Math.round(Number(`${e}e${t}`))}e-${t}`)},safe:function(e=""){return new X(e)},shuffle:function(e){const t=[...e];for(let e=t.length-1;e>0;e--){const n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}return t},slice:function(e="",t=0,n){return e.slice(t,n)},slugify:function(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")},sort:function(e=[]){return Array.isArray(e)?[...e].sort():[...e].sort().join("")},split:function(e="",t=""){return e.split(t)},stripTags:function(e){return e.replace(/<[^>]*>/g,"")},sub:function(e=0,t=0){return e-t},sum:function(e=[]){return e.reduce((e,t)=>e+t,0)},timeAgo:function(e){const t=e instanceof Date?e:new Date(e),n=new Date,r=Math.floor((n.getTime()-t.getTime())/1e3),i=[{label:"year",seconds:31536e3},{label:"month",seconds:2592e3},{label:"day",seconds:86400},{label:"hour",seconds:3600},{label:"minute",seconds:60}];for(const e of i){const t=Math.floor(r/e.seconds);if(t>=1)return`${t} ${e.label}${t>1?"s":""} ago`}return"just now"},trim:function(e=""){return e.trim()},truncate:function(e="",t=0,n="..."){return e.slice(0,t)+(e.length>t?n:"")},unique:function(e=""){return Array.isArray(e)?Array.from(new Set(e)):Array.from(new Set(e)).join("")},upper:function(e=""){return e.toUpperCase()},urldecode:function(e=""){return decodeURIComponent(e)},urlencode:function(e=""){return encodeURIComponent(e)},values:function(e={}){return Object.values(e)},wordCount:function(e){return e.trim().split(/\s+/).filter(Boolean).length}});const Y={filters:{},parsers:{},compilers:{},plugins:[],debug:e=>{throw e}},Z={...Y,commentOpen:"{{#",commentClose:"#}}",directiveOpen:"{{",directiveClose:"}}",outputOpen:"{{=",outputClose:"}}"},ee={...Z,trimWhitespace:!1,stripComments:!1,loader:async()=>""},te={...ee,globals:{},autoEscape:!0,cache:{enabled:!0,maxSize:1e3,ttl:36e5,revalidate:!0},security:{}},ne=(e,...t)=>{const n={...e},r=e=>{n.filters={...n.filters,...e.filters},n.parsers={...n.parsers,...e.parsers},n.compilers={...n.compilers,...e.compilers}};return e.plugins?.forEach(r),t.forEach(({plugins:e,filters:t,parsers:i,compilers:s,...o})=>{for(const[e,t]of Object.entries(o))void 0!==t&&(n[e]=t);r({filters:t,parsers:i,compilers:s}),e?.forEach(r)}),n};const re={BLOCK:async function({val:{value:e},loc:t},n){const r=JSON.stringify(e);n.pushRaw(t,`if(b[${r}]&&!(b[${r}].u++)){`,`s+=await b[${r}].s?.pop()?.()??"";`,"}")},SUPER:async function({loc:e},t){t.state.block?t.pushRaw(e,`s+=await b[${JSON.stringify(t.state.block)}]?.s?.pop()?.()??"";`):t.options.debug?.(new r('"super" should be used inside a block',t.template,e))}};class ie extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"BLOCK"})}}class se extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"SUPER"})}}const oe={compilers:re,parsers:{block:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endblock"]);t.match(["endblock"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new ie(t.parseExp(e.expression),n,e.loc,e.strip)},super:function*(e,t){e.expression?t.emitExpErr(e,!1):(yield"NEXT",yield new se(e.val,e.loc,e.strip))},endblock:"unexpected"}},ae={AND:"&&",OR:"||",IS:"",NOT:"!",EQ:"===",NE:"!==",GT:">",LT:"<",GE:">=",LE:"<=",IN:" in ",NI:" in ",OF:" of ",WITH:" with ",ADD:"+",SUB:"-",MUL:"*",DIV:"/",MOD:"%",PIPE:"",ASSIGN:"=",LP:"(",RP:")",COMMA:",",DOT:".",ID:"",LIT:"",IF:"",ELSE:""},le=new Set(Object.getOwnPropertyNames(Object.prototype));class ce{constructor(){Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}compile(e,t=i,n=s){return this.context=t,this.filters=n,e?this.compileExp(e):'""'}compileExp(e){switch(e.type){case"NOT":return this.compileNot(e);case"ID":return this.compileId(e);case"LIT":return this.compileLit(e);case"PIPE":return this.compilePipe(e);case"ASSIGN":return this.compileAssign(e);case"IS":return this.compileIs(e);case"AND":case"OR":case"EQ":case"NE":case"GT":case"LT":case"GE":case"LE":case"IN":case"NI":case"ADD":case"SUB":case"MUL":case"DIV":case"MOD":return this.compileBinary(e);case"IF":return this.compileTernary(e);case"SEQ":return this.compileSeq(e);default:return""}}compileNot({argument:e}){return`!${this.compileExp(e)}`}compileId({value:e,path:t,args:n}){let r=le.has(e)?`(Object.hasOwn(${this.context},"${e}")?${this.context}.${e}:undefined)`:`${this.context}.${e}`;return t&&(r+=t.map(e=>`.${e.value}`).join("")),n&&(r+=`(${this.compileArgs(n).join(",")})`),r}compileArgs(e){const t=[],n=[];for(const r of e)if("ASSIGN"===r.type){const{left:e,right:t}=r;n.push(`${e.value}:${this.compileExp(t)}`)}else t.push(this.compileExp(r));return n.length&&t.push(`{${n.join(",")}}`),t}compileLit({value:e}){return void 0===e?"undefined":"number"==typeof e&&e<0?`(${e})`:JSON.stringify(e)}compileSeq({elements:e}){return`(${e.map(e=>this.compileExp(e)).join(",")})`}compilePipe({left:e,right:t}){const{value:n,args:r=[]}=t,i=`(${this.filters}.${n}||u_("${n}")).call(${[this.context,this.compileExp(e),...this.compileArgs(r)].join(",")})`;return`(${o}=${i},${o} instanceof Promise?await ${o}:${o})`}compileAssign({left:e,right:t}){return"ID"===e.type?`Object.assign(${this.context},{${e.value}:${this.compileExp(t)}});`:`Object.assign(${this.context},${this.filters}.pick.call(${this.context},${this.compileExp(t)},${e.elements.map(({value:e})=>`"${e}"`).join(",")}));`}compileIs({left:e,right:t}){return`typeof ${this.compileExp(e)}===${this.compileExp(t)}`}compileBinary({type:e,left:t,right:n}){const r=`${this.compileExp(t)}${ae[e]}${this.compileExp(n)}`;return"NI"===e?`!(${r})`:r}compileTernary({test:e,consequent:t,alternative:n}){return`${this.compileExp(e)}?${this.compileExp(t)}:${n?this.compileExp(n):'""'}`}}const ue={CALL:async function({val:e,body:t,loc:n},r){r.pushRaw(n,`s+=await ${(new ce).compile(e,r.context)}(async()=>{`,'let s="";'),await r.compileNodes(t),r.pushRaw(null,"return s;",'})??"";')}};class pe extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CALL"})}}const he={compilers:ue,parsers:{call:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endcall"]);t.match(["endcall"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new pe(t.parseExp(e.expression),n,e.loc,e.strip)},endcall:"unexpected"}};const fe={CAPTURE:async function({val:e,body:t,loc:n},r){r.pushRaw(n,`${r.context}.${e.value}=${s}.safe.call(${r.context},await(async(s)=>{`),await r.compileNodes(t),r.pushRaw(null,'return s;})(""));')}};class de extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CAPTURE"})}}const be={compilers:fe,parsers:{capture:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endcapture"]);t.match(["endcapture"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new de(t.parseExp(e.expression),n,e.loc,e.strip)},endcapture:"unexpected"}};const me={COMMENT:async function({val:e,loc:t},n){n.options.stripComments||n.pushStr(t,`\x3c!--${e}--\x3e`)}};class ye extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"COMMENT"})}}const ge={compilers:me,parsers:{comment:function*({val:e,loc:t,strip:n}){yield"NEXT",yield new ye(e,t,n)}}},we="loop:{first:i_===0,index:i_++,last:i_===n_}";function ve(e,t=new Set){return!(!e||"object"!=typeof e||t.has(e))&&(t.add(e),"ASSIGN"===e.type||Object.entries(e).some(([e,n])=>"args"===e&&Array.isArray(n)?n.some(e=>ve("ASSIGN"===e.type?e.right:e,t)):ve(n,t)))}function xe(e){return e.every(e=>{switch(e.type){case"TEXT":case"COMMENT":case"BREAK":case"CONTINUE":return!0;case"OUTPUT":return!ve(e.val);case"IF":return!ve(e.test)&&xe(e.body)&&e.alternatives.every(e=>!ve(e.test)&&xe(e.body));case"FOR":return!ve(e.loop.right)&&xe(e.alternative?.body??[]);default:return!1}})}const Oe={FOR:async function({loop:{left:e,right:t,loc:n},body:r,alternative:i},s){const{context:o}=s,a=new ce;s.pushRaw(n,"{",`const t_=${a.compile(t,o)},`,"a_=Array.isArray(t_)?t_:Array.from(t_??[]),n_=a_.length;"),i&&(s.pushRaw(n,"if(!n_){"),await s.compileNodes(i.body),s.pushRaw(n,"}else{"));const l="SEQ"===e.type?e.elements.map(e=>"ASSIGN"===e.type?[e.left.value,`v_.${e.left.value}===undefined?${a.compile(e.right,o)}:v_.${e.left.value}`]:[e.value,`v_.${e.value}`]):[[e.value,"v_"]],c=s.in();s.pushRaw(n,"let i_=0;");const{maxLoopIterations:u}=W(s.options.security),p=null==u?[]:[`if(++li_>${u})throw new Error(${JSON.stringify(`Loop iteration limit of ${u} exceeded`)});`];xe(r)?s.pushRaw(n,`const ${c}={...${o}};`,"for(const v_ of a_){",...p,`${c}.loop={${we.slice(6)};`,...l.map(([e,t])=>`${c}.${e}=${t};`)):s.pushRaw(n,"for(const v_ of a_){",...p,`const ${c}={`,`...${o},`,`${we},`,...l.map(([e,t])=>`${e}:${t},`),"};"),await s.compileNodes(r),s.out(),s.flushable&&s.pushFlush(),s.pushRaw(null,i?"}}}":"}}")},BREAK:function({loc:e},t){t.pushRaw(e,"break;")},CONTINUE:function({loc:e},t){t.pushRaw(e,"continue;")}};class Ee extends N{constructor(e,t,n,r,i){super(),Object.defineProperty(this,"loop",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"alternative",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"FOR"})}traverse(e){this.body.forEach(e),this.alternative?.body.forEach(e)}}let Pe=class extends N{constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE"})}};class Te extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"BREAK"})}}class je extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CONTINUE"})}}const $e=new WeakMap;const ke={for:function*(e,t){if(!e.expression)return void t.emitExpErr(e);$e.set(t,!0),yield"NEXT";const n=t.parseUntil(["else","endfor"]);$e.set(t,!1);let i=null;if(t.match(["else"])){const e=function*(e,t){if(e.expression)return t.emitExpErr(e,!1),yield"NEXT",void t.parseUntil(["endfor"]);yield"NEXT",yield new Pe(t.parseUntil(["endfor"]),e.loc,e.strip)}(t.peek(),t);for(;;){const{value:t,done:n}=e.next();if(n)break;if(t){if("NEXT"===t){yield"NEXT";continue}i=t}}}t.match(["endfor"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc));const s=t.parseExp(e.expression);"OF"===s?.type?yield new Ee(s,n,i,e.loc,e.strip):s&&t.options.debug?.(new r(`"${e.name}" expects "item of items"`,t.template,e.loc))},break:function*(e,t){e.expression?t.emitExpErr(e,!1):$e.get(t)?(yield"NEXT",yield new Te(e.val,e.loc,e.strip)):t.options.debug?.(new r('"break" directive used outside of a loop',t.template,e.loc))},continue:function*(e,t){e.expression?t.emitExpErr(e,!1):$e.get(t)?(yield"NEXT",yield new je(e.val,e.loc,e.strip)):t.options.debug?.(new r('"continue" directive used outside of a loop',t.template,e.loc))},endfor:"unexpected"},Se={compilers:Oe,parsers:ke};const Ne={IF:async function({test:e,body:t,alternatives:n},r){r.pushRaw(e.loc,`if(${(new ce).compile(e,r.context)}){`),await r.compileNodes(t),r.pushRaw(null,"}");for(const e of n)"ELSE_IF"===e.type?r.pushRaw(e.test.loc,`else if(${(new ce).compile(e.test,r.context)}){`):r.pushRaw(null,"else{"),await r.compileNodes(e.body),r.pushRaw(null,"}")}};class Ie extends N{constructor(e,t,n,r,i){super(),Object.defineProperty(this,"test",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"alternatives",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"IF"})}traverse(e){this.body?.forEach(e),this.alternatives?.forEach(t=>t.body?.forEach(e))}}class Le extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"test",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE_IF"})}}class Ce extends N{constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"ELSE"})}}function*Re(e,t){if(!e.expression)return t.emitExpErr(e),yield"NEXT",void t.parseUntil(["else","elseif","elsif","elif","endif"]);yield"NEXT",yield new Le(t.parseExp(e.expression),t.parseUntil(["else","elseif","elsif","elif","endif"]),e.loc,e.strip)}function*De(e,t){if(e.expression)return t.emitExpErr(e,!1),yield"NEXT",void t.parseUntil(["endif"]);yield"NEXT",yield new Ce(t.parseUntil(["endif"]),e.loc,e.strip)}const Ae={compilers:Ne,parsers:{if:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["else","elseif","elsif","elif","endif"]),i=[];for(;t.match(["else","elseif","elsif","elif"]);){const e=t.peek();if("else"===e.name.toLowerCase()){const n=De(e,t);for(;;){const{value:e,done:t}=n.next();if(t)break;if(e){if("NEXT"===e){yield"NEXT";continue}i.push(e)}}}else{const n=Re(e,t);for(;;){const{value:e,done:t}=n.next();if(t)break;if(e){if("NEXT"===e){yield"NEXT";continue}i.push(e)}}}}t.match(["endif"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new Ie(t.parseExp(e.expression),n,i,e.loc,e.strip)},elseif:"unexpected",elsif:"unexpected",elif:"unexpected",endif:"unexpected"}};const Ue={INCLUDE:async function({val:{value:e},loc:t,withExp:n},r){const i=JSON.stringify(e);if(n){const e=new ce,s=`{...${r.context},...${e.compile(n,r.context)}}`;return void r.pushRaw(t,`s+=await p[${i}]?.(${s})??"";`)}r.pushRaw(t,`s+=await p[${i}]?.(tc_)??"";`)}};class Me extends N{constructor(e,t,n,r=null){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"withExp",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"INCLUDE"})}}function _e(e){return"LIT"===e.type&&"string"==typeof e.value}const Fe={compilers:Ue,parsers:{include:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseExp(e.expression);if(n)if(_e(n))yield new Me(n,e.loc,e.strip);else{if("WITH"===n.type){const{left:t,right:r}=n;if(_e(t))return void(yield new Me(t,e.loc,e.strip,r))}t.options.debug?.(new r('"include" expects "path" or "path" with expr',t.template,e.loc))}}}};const Xe={MACRO:async function({val:{value:e,args:t},loc:n,body:r},i){const{context:s}=i,o=new ce,{maxCallDepth:a}=W(i.options.security);i.pushRaw(n,`${s}.${e}=(...a_)=>async(_c)=>{`,...null==a?[]:[`if(cd_>=${a})throw new Error(${JSON.stringify(`Macro call depth limit of ${a} exceeded`)});`,"cd_++;","try{"],'let s="";',`const ${i.in()}={`,`...${s},`,...(t??[]).map((e,t)=>"ASSIGN"===e.type?`${e.left.value}:a_[${t}]===undefined?${o.compile(e.right)}:a_[${t}],`:`${e.value}:a_[${t}],`),"};"),await i.compileNodes(r),i.out(),i.pushRaw(null,"return s;",...null==a?[]:["}finally{cd_--;}"],"};")},CALLER:function({loc:e},t){t.pushRaw(e,'s+=await _c?.()??"";')}};class We extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"MACRO"})}}class Ge extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"CALLER"})}}const ze=new WeakMap;const Be={compilers:Xe,parsers:{macro:function*(e,t){if(!e.expression)return void t.emitExpErr(e);ze.set(t,!0),yield"NEXT";const n=t.parseUntil(["endmacro"]);ze.set(t,!1),t.match(["endmacro"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc));const i=t.parseExp(e.expression);if("ID"===i.type){if(i.args?.length)for(const n of i.args)if("ASSIGN"===n.type){if("ID"!==n.left.type)return void t.options.debug?.(new r("Invalid macro parameter definition",t.template,e.loc))}else if("ID"!==n.type)return void t.options.debug?.(new r("Invalid macro parameter definition",t.template,e.loc));yield new We(i,n,e.loc,e.strip)}else t.options.debug?.(new r("Invalid macro definition",t.template,e.loc))},caller:function*(e,t){e.expression?t.emitExpErr(e,!1):ze.get(t)?(yield"NEXT",yield new Ge(e.val,e.loc,e.strip)):t.options.debug?.(new r('"caller" directive used outside of a macro',t.template,e.loc))},endmacro:"unexpected"}};const qe={OUTPUT:async function({val:e},t){t.pushVar(e.loc,(new ce).compile(e,t.context))}};class Ke extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"OUTPUT"})}}const He={compilers:qe,parsers:{output:function*(e,t){yield"NEXT";const n=p(`${t.options.outputOpen}${e.strip.before?"-":""}`,{...e.loc.start});yield new Ke(t.parseExp({val:e.val,loc:{start:n,end:e.loc.end}}),e.loc,e.strip)}}};const Je={SET:async function({val:e,loc:t},n){n.pushRaw(t,(new ce).compile(e,n.context))}};class Ve extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"SET"})}}const Qe={compilers:Je,parsers:{set:function*(e,t){e.expression?(yield"NEXT",yield new Ve(t.parseExp(e.expression),e.loc,e.strip)):t.emitExpErr(e)}}};const Ye={STYLESHEET:async function(){},STYLESHEETS:async function({loc:e},t){t.pushRaw(e,"if(!ss_u++){",'s+="<style>";',"for(const f_ of ss_)s+=await f_();",'s+="</style>";',"}")}};class Ze extends N{constructor(e,t,n){super(),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"STYLESHEET"})}}class et extends N{constructor(e,t){super(),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"STYLESHEETS"})}}const tt={compilers:Ye,parsers:{stylesheet:function*(e,t){if(e.expression)return void t.emitExpErr(e,!1);yield"NEXT";const n=t.parseUntil(["endstylesheet"]);t.match(["endstylesheet"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new Ze(n,e.loc,e.strip)},endstylesheet:"unexpected",stylesheets:function*(e,t){e.expression?t.emitExpErr(e,!1):(yield"NEXT",yield new et(e.loc,e.strip))}}};const nt={TEXT:async function({val:e,loc:t,strip:{start:n,end:r}},i){(n||i.options.trimWhitespace)&&(e=e.replace(/^\s+/,"")),(r||i.options.trimWhitespace)&&(e=e.replace(/\s+$/,"")),i.pushStr(t,e)}};class rt extends N{constructor(e,t,n){super(),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"TEXT"})}}const it={compilers:nt,parsers:{text:function*(e){yield"NEXT",yield new rt(e.val,e.loc,e.strip)}}};const st={UNEXPECTED:async function({name:e,loc:t},n){n.pushStr(t,`\x3c!--Unexpected "${e}"--\x3e`)}};class ot extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"UNEXPECTED"})}}const at={compilers:st,parsers:{unexpected:function*(e,t){const n=e.name??e.type;t.options.debug?.(new r(`Unexpected "${n}"`,t.template,e.loc)),yield"NEXT",yield new ot(n,e.val,e.loc,e.strip)}}};const lt={UNKNOWN:async function({name:e,loc:t},n){n.pushStr(t,`\x3c!--Unknown "${e}"--\x3e`)}};class ct extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"val",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"UNKNOWN"})}}const ut={compilers:lt,parsers:{unknown:function*(e,t){const n=e.name??e.type;t.options.debug?.(new r(`Unknown "${n}"`,t.template,e.loc)),yield"NEXT",yield new ct(n,e.val,e.loc,e.strip)}}};const pt={WITH:async function(e,t){const{context:n}=t,r=new ce;t.pushRaw(e.loc,`const ${t.in()}={...${r.compile(e.expression,n)}};`),await t.compileNodes(e.body),t.out()}};class ht extends N{constructor(e,t,n,r){super(),Object.defineProperty(this,"expression",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"body",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"loc",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"strip",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:"WITH"})}traverse(e){this.body?.forEach(e)}}const ft=[oe,he,ge,be,Se,Ae,Fe,Be,Qe,tt,it,He,at,ut,{parsers:{with:function*(e,t){if(!e.expression)return void t.emitExpErr(e);yield"NEXT";const n=t.parseUntil(["endwith"]);t.match(["endwith"])?yield"NEXT":t.options.debug?.(new r(`Unclosed "${e.name}"`,t.template,e.loc)),yield new ht(t.parseExp(e.expression),n,e.loc,e.strip)},endwith:"unexpected"},compilers:pt}];class dt extends r{constructor(e,t,n,r){super(e,t,void 0,r),Object.defineProperty(this,"src",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"getLoc",{enumerable:!0,configurable:!0,writable:!0,value:n}),this.name="RenderError",dt.captureStackTrace?.(this,this.constructor)}get details(){return this.loc=this.getLoc(),super.details}}const bt=new Error("Stream cancelled");class mt{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sandbox",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"escape",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"compiling",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.options=ne(te,{filters:Q,plugins:ft},e),this.filters=Object.assign(Object.create(null),this.options.filters);const n=this.options.security?.deepEscape?z:F,{autoEscape:r}=this.options;this.escape=e=>"string"==typeof e?r?F(e):e:null==e?"":e instanceof X?`${e}`:r?n(e):e,!1!==this.options.cache?.enabled&&(this.cache=new t(this.options.cache)),this.options.security?.sandbox&&(this.sandbox=new G(this.options.security))}async render(e,t){const n=this.cache?.peek(H(e));if(n?.script&&0===n.sources.size&&n.fingerprint===J(this.options)){this.cache.get(H(e));try{return await this.run(n.script,t)}catch(t){const r=new a;return r.mappings=n.mappings,this.options.debug(this.wrapError(t,e,r)),""}}let r;try{return r=await this.compile(e),await this.run(r.script,t)}catch(t){this.options.debug(this.wrapError(t,e,r??new a))}return""}template(e){return t=>this.render(e,t)}async renderCompiled(e,t={}){try{return await this.run(e,t)}catch(e){this.options.debug(e)}return""}renderStream(e,t={}){let n,r=!1;return new ReadableStream({start:i=>{const s=e=>{if(r)throw bt;if(i.enqueue(e),(i.desiredSize??1)<=0)return new Promise(e=>{n=e})};let o;(async()=>{try{o=await this.compile(e,!0);const n=await this.run(o.script,t,s);n&&!r&&i.enqueue(n),i.close()}catch(t){if(t===bt)return;try{this.options.debug(this.wrapError(t,e,o??new a)),i.close()}catch(e){i.error(e)}}})()},pull:()=>{n?.(),n=void 0},cancel:()=>{r=!0,n?.()}})}compile(e,t=!1){const n=H(e,t);let r=this.compiling.get(n);return r||(r=new V(this.options,this.cache,this.options.cache?.revalidate??!0,t).compile(e).finally(()=>this.compiling.delete(n)),this.compiling.set(n,r)),r}wrapError(e,t,n){return"CompileError"===e?.name?e:new dt(`${e?.message??e}`,t,()=>{const t=e?.stack?.match(/<anonymous>:(\d+):(\d+)\)/);if(!t)return e?.stack??"";const[r]=n.getSourceLoc({line:+t[1]-2,column:+t[2]});return r})}run(e,t,n){const r=e(this.sandbox?{...this.sandbox.createSecureContext(this.options.globals),...t}:{...this.options.globals,...t},this.escape,this.filters,n),{timeoutMs:i}=this.options.security??{};if(null==i)return r;let s;return Promise.race([Promise.resolve(r).finally(()=>{clearTimeout(s)}),new Promise((e,t)=>{s=setTimeout(()=>{t(new Error(`Render timed out after ${i}ms`))},i)})])}async renderFile(e,t){return this.render(await this.options.loader(e),t)}clearCache(){this.cache?.clear()}invalidateCache(e){this.cache?.invalidate(e)}getCacheStats(){return this.cache?this.cache.getStats():null}resetCacheStats(){this.cache?.resetStats()}auditTemplate(e){return(new B).auditTemplate(e)}getCSPHeaders(){return new G(this.options.security).generateCSPHeaders()}}class yt{constructor(e){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"variables",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"filters",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"includes",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"blocks",{enumerable:!0,configurable:!0,writable:!0,value:new Set}),Object.defineProperty(this,"macros",{enumerable:!0,configurable:!0,writable:!0,value:new Set})}async analyze(e,t=new Set){const n=new D(this.options).parse(e);await this.nodes(n.body,t)}async nodes(e=[],t){for(const n of e)await this.node(n,t)}async node(e,t){switch(e.type){case"OUTPUT":this.exp(e.val,t);break;case"IF":this.exp(e.test,t),await this.nodes(e.body,t);for(const n of e.alternatives)this.exp(n.test,t),await this.nodes(n.body,t);break;case"FOR":{this.exp(e.loop.right,t),await this.nodes(e.alternative?.body,t);const n=new Set(t).add("loop");this.bind(e.loop.left,n,t),await this.nodes(e.body,n);break}case"SET":this.exp(e.val.right,t),this.bind(e.val.left,t,t);break;case"CAPTURE":await this.nodes(e.body,t),t.add(e.val.value);break;case"MACRO":{const n=new Set(t);for(const r of e.val.args??[])this.bind(r,n,t);t.add(e.val.value),this.macros.add(e.val.value),await this.nodes(e.body,n);break}case"CALL":this.exp(e.val,t),await this.nodes(e.body,t);break;case"WITH":this.exp(e.expression,t),await this.nodes(e.body,gt);break;case"BLOCK":this.blocks.add(e.val.value),await this.nodes(e.body,t);break;case"STYLESHEET":default:await this.nodes(e.body,t);break;case"INCLUDE":e.withExp&&this.exp(e.withExp,t),await this.include(e.val.value,t)}}async include(e,t){if(this.includes.has(e))return;let n;this.includes.add(e);try{n=await this.options.loader(e)}catch{}n&&await this.analyze(n,new Set(t))}bind(e,t,n){"ID"===e.type?t.add(e.value):"SEQ"===e.type?e.elements.forEach(e=>this.bind(e,t,n)):"ASSIGN"===e.type&&(this.exp(e.right,n),this.bind(e.left,t,n))}exp(e,t){if(e)switch(e.type){case"ID":t===gt||t.has(e.value)||this.variables.add(e.value),e.args?.forEach(e=>this.exp(e,t));break;case"LIT":break;case"NOT":this.exp(e.argument,t);break;case"IF":this.exp(e.test,t),this.exp(e.consequent,t),this.exp(e.alternative,t);break;case"SEQ":e.elements.forEach(e=>this.exp(e,t));break;case"PIPE":{const{left:n,right:r}=e;this.exp(n,t),this.filters.add(r.value);for(const e of r.args??[])this.exp("ASSIGN"===e.type?e.right:e,t);break}default:this.exp(e.left,t),this.exp(e.right,t)}}}const gt=new Set;async function wt(e,t={}){const n=new yt(ne(ee,{filters:Q,plugins:ft},t));await n.analyze(e);const r=e=>[...e].sort();return{variables:r(n.variables),filters:r(n.filters),includes:r(n.includes),blocks:r(n.blocks),macros:r(n.macros)}}function vt({variables:e},{includeRuntime:t=!1}={}){const n=e.map(e=>` ${e}?: unknown;`).join("\n");return`// Generated by the Janja precompiler. Do not edit.\nimport type { ${t?"RendererOptions, ":""}Script } from 'janja';\n\n/** The data this template reads. */\nexport interface TemplateData {${n?`\n${n}\n`:""}}\n\nexport declare const script: Script;\n\n${t?"export default function render(\n data?: TemplateData,\n options?: RendererOptions,\n): Promise<string>;":"export default script;"}\n`}function xt(e){let t=e<0?-e<<1|1:e<<1,n="";do{let e=31&t;t>>>=5,t>0&&(e|=32),n+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[e]}while(t>0);return n}function Ot(e,{file:t,source:n,sourceContent:r,line:i}){const s=new Map;for(const t of e)s.set(t.target.start.column,t.source.start);let o=0,a=0,l=0;const c=[...s.entries()].sort(([e],[t])=>e-t).map(([e,t])=>{const n=t.line-1,r=t.column-1,i=xt(e-o)+xt(0)+xt(n-a)+xt(r-l);return o=e,a=n,l=r,i}).join(",");return{version:3,...t?{file:t}:{},sources:[n],sourcesContent:[r],names:[],mappings:`${";".repeat(i)}${c}`}}async function Et(e,{includeRuntime:t,sourceMap:n,filename:r,dts:o,...a}={}){const l=new V(ne(ee,{filters:Q,plugins:ft},a));await l.compile(e);const c=`// Generated by the Janja precompiler. Do not edit.${t?"\nimport { renderCompiled } from 'janja';\n":""}\nexport function script(${i}, e, ${s}, w) {\n`,u=t?"\n}\n\nexport default function render(globals = {}, options) {\n return renderCompiled(script, globals, options);\n}\n":"\n}\n\nexport default script;\n";return{code:`${c}${l.code}${u}`,map:n?Ot(l.mappings,{source:r??"template.janja",sourceContent:e,line:c.split("\n").length-1}):void 0,dts:o?vt(await wt(e,a),{includeRuntime:t}):void 0}}class Pt{constructor(e={}){Object.defineProperty(this,"defaultLocale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"currentLocale",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"translations",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pluralRules",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.defaultLocale=e.defaultLocale||"en",this.currentLocale=e.locale||this.defaultLocale,this.translations=e.translations||{},this.pluralRules=e.pluralRules||this.getDefaultPluralRules()}setLocale(e){this.currentLocale=e}getLocale(){return this.currentLocale}addTranslations(e,t){this.translations[e]||(this.translations[e]={}),this.translations[e]=this.mergeDeep(this.translations[e],t)}translate(e,t={}){const n=this.getTranslation(e);return n?this.interpolate(n,t):e}t(e,t={}){return this.translate(e,t)}pluralize(e,t,n={}){const r=`${e}.${this.getPluralForm(t)}`,i=this.getTranslation(r);if(i)return this.interpolate(i,{...n,count:t});const s=this.getTranslation(e);return s?this.interpolate(s,{...n,count:t}):e}formatDate(e,t){const n="string"==typeof e?new Date(e):e;return new Intl.DateTimeFormat(this.currentLocale,t).format(n)}formatNumber(e,t){return new Intl.NumberFormat(this.currentLocale,t).format(e)}formatCurrency(e,t,n){return new Intl.NumberFormat(this.currentLocale,{...n,style:"currency",currency:t}).format(e)}getTranslation(e){const t=e.split(".");let n=this.translations[this.currentLocale];for(const e of t){if(!n||"object"!=typeof n||!(e in n))return null;n=n[e]}return"string"==typeof n?n:null}interpolate(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>void 0!==t[n]?String(t[n]):n)}getPluralForm(e){const t=this.pluralRules[this.currentLocale];return t?t(e):this.pluralRules[this.defaultLocale](e)}getDefaultPluralRules(){return{en:e=>1===e?"one":"other",es:e=>1===e?"one":"other",fr:e=>0===e||1===e?"one":"other",de:e=>1===e?"one":"other",ru:e=>{const t=e%10,n=e%100;return 1===t&&11!==n?"one":t>=2&&t<=4&&!(n>=12&&n<=14)?"few":0===t||t>=5&&t<=9?"many":"other"},ja:()=>"other",zh:()=>"other",ar:e=>0===e?"zero":1===e?"one":2===e?"two":e%100>=3&&e%100<=10?"few":e%100>=11&&e%100<=99?"many":"other"}}mergeDeep(e,t){const n={...e};return this.isObject(e)&&this.isObject(t)&&Object.keys(t).forEach(r=>{this.isObject(t[r])?r in e?n[r]=this.mergeDeep(e[r],t[r]):Object.assign(n,{[r]:t[r]}):Object.assign(n,{[r]:t[r]})}),n}isObject(e){return e&&"object"==typeof e&&!Array.isArray(e)}}const Tt=new Pt;async function jt(e,t={}){let n="";const{data:r={},options:i}=t,s=new mt(i);for(const t of e)n=await s.render(t,{...r,_content:n});return n}const $t={trim:!1,stripComments:!1,collapseWhitespace:!1,preserveNewlines:!0};function kt(e){return{...$t,...e}}class St{constructor(){Object.defineProperty(this,"mixins",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}register(e){this.mixins.set(e.name,e)}registerMultiple(e){for(const t of e)this.register(t)}get(e){return this.mixins.get(e)}has(e){return this.mixins.has(e)}delete(e){return this.mixins.delete(e)}clear(){this.mixins.clear()}list(){return Array.from(this.mixins.keys())}}const Nt=new St;async function It(e,t={},n=Nt){const r=n.get(e);if(!r)throw new Error(`Mixin "${e}" not found in registry`);const{data:i={},options:s}=t,o={...r.data,...i};return new mt(s).render(r.template,o)}class Lt{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e})}async validate(e){const t=[],n=[],r=e=>{const[n]=e?.suggestions??[];t.push({type:"error",message:`${e?.message??e}`,line:e?.loc?.start.line,column:e?.loc?.start.column,suggestion:n?.fix??n?.message})},i=ne(ee,{filters:Q,plugins:ft},this.options,{debug:r});try{const t=new D(i).parse(e);this.checkFilters(t,i.filters,n)}catch(e){r(e)}return{valid:0===t.length,errors:t,warnings:n}}checkFilters(e,t,n,r=new Set){if(e&&"object"==typeof e&&!r.has(e)){r.add(e),"PIPE"!==e.type||"ID"!==e.right?.type||Object.prototype.hasOwnProperty.call(t,e.right.value)||n.push({type:"warning",message:`Unknown filter "${e.right.value}"`,line:e.right.loc?.start.line,column:e.right.loc?.start.column});for(const i of Object.values(e))this.checkFilters(i,t,n,r)}}}const Ct={AND:"and",OR:"or",IS:"is",NOT:"not",EQ:"eq",NE:"ne",GT:"gt",LT:"lt",GE:"ge",LE:"le",IN:"in",NI:"ni",OF:"of",WITH:"with",ADD:"+",SUB:"-",MUL:"*",DIV:"/",MOD:"%",PIPE:"|",ASSIGN:"=",LP:"(",RP:")",COMMA:",",DOT:".",IF:"if",ELSE:"else"};class Rt{format(e){return e?this.formatExp(e):'""'}formatExp(e){switch(e.type){case"NOT":return this.formatNot(e);case"ID":return this.formatId(e);case"LIT":return this.formatLit(e);case"PIPE":case"IS":case"ASSIGN":case"AND":case"OR":case"EQ":case"NE":case"GT":case"LT":case"GE":case"LE":case"IN":case"NI":case"OF":case"WITH":case"ADD":case"SUB":case"MUL":case"DIV":case"MOD":return this.formatBinary(e);case"IF":return this.formatTernary(e);case"SEQ":return this.formatSeq(e);default:return""}}formatNot({argument:e}){return`${Ct.NOT} ${this.formatExp(e)}`}formatId({value:e,path:t,args:n}){let r=e;return t&&(r+=t.map(e=>`.${e.value}`).join("")),n&&(r+=this.formatSeq({elements:n})),r}formatLit({value:e}){return void 0===e?"undefined":JSON.stringify(e)}formatSeq({elements:e}){return`(${e.map(e=>this.formatExp(e)).join(", ")})`}formatBinary({type:e,left:t,right:n}){return`${this.formatExp(t)} ${Ct[e]} ${this.formatExp(n)}`}formatTernary({test:e,consequent:t,alternative:n}){return`${this.formatExp(t)} ${Ct.IF} ${this.formatExp(e)}${n?` ${Ct.ELSE} ${this.formatExp(n)}`:""}`}}const Dt=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]),At=new Set(["pre","textarea","script","style"]),Ut=new Set(["if","for","macro","block","call","capture","with","stylesheet"]),Mt=new Set(["stylesheet"]),_t=new Set(["else","elif","elseif","elsif"]),Ft=new Set(["endif","endfor","endmacro","endblock","endcall","endcapture","endwith","endstylesheet"]);function Xt(e,t){const n=[];let r=0,i=!0,s=0;for(;s<e.length;){if(/\s/.test(e[s])){s+=1;continue}const o=Wt(e,s,t);o?(o.piece?(n.push(o.piece),!i||"close"!==o.piece.kind&&"mid"!==o.piece.kind?i=!1:r+=1):i=!1,s=o.end):(i=!1,s+=1)}return{pieces:n,prefixClosers:r}}function Wt(e,t,n){const{commentOpen:r,directiveOpen:i,outputOpen:s}=n;if(e.startsWith(r,t))return{end:Bt(e,t+r.length,n.commentClose)};if(e.startsWith(s,t))return{end:Bt(e,t+s.length,n.outputClose)};if(e.startsWith(i,t))return function(e,t,n){const{directiveOpen:r,directiveClose:i}=n,s=Bt(e,t+r.length,i),o=e.slice(t+r.length,s-i.length),a=o.replace(/^\s*-?\s*/,"").match(/^([A-Za-z_]\w*)/)?.[1]?.toLowerCase();if(!a)return{end:s};if(Ft.has(a)){const e=a.startsWith("end")?a.slice(3):a;return{end:s,piece:{kind:"close",sensitive:Mt.has(e)?e:void 0}}}if(_t.has(a))return{end:s,piece:{kind:"mid"}};if(Ut.has(a))return{end:s,piece:{kind:"open",sensitive:Mt.has(a)?a:void 0}};return{end:s}}(e,t,n);if(e.startsWith("\x3c!--",t)){const n=e.indexOf("--\x3e",t+4);return{end:-1===n?e.length:n+3}}return"<"===e[t]?function(e,t,n){if(e.startsWith("</",t)){let r=t+2;for(;r<e.length&&/\s/.test(e[r]);)r+=1;const i=r;for(;r<e.length&&/[A-Za-z0-9:-]/.test(e[r]);)r+=1;const s=e.slice(i,r).toLowerCase(),o=Gt(e,r,n);return!s||Dt.has(s)?{end:o}:{end:o,piece:{kind:"close",sensitive:At.has(s)?s:void 0}}}if(e.startsWith("<!",t)||e.startsWith("<?",t))return{end:Gt(e,t+2,n)};let r=t+1;for(;r<e.length&&/\s/.test(e[r]);)r+=1;const i=r;for(;r<e.length&&/[A-Za-z0-9:-]/.test(e[r]);)r+=1;const s=e.slice(i,r).toLowerCase(),o=Gt(e,r,n),a=e.slice(t,o),l=/\/\s*>$/.test(a)||Dt.has(s);if(!s||l)return{end:o};return{end:o,piece:{kind:"open",sensitive:At.has(s)?s:void 0}}}(e,t,n):null}function Gt(e,t,n){let r=t,i=null;for(;r<e.length;){const t=e[r];if(i){if(t===i)i=null;else{const t=zt(e,r,n);if(null!==t){r=t;continue}}r+=1;continue}const s=zt(e,r,n);if(null===s)if('"'!==t&&"'"!==t){if(">"===t)return r+1;r+=1}else i=t,r+=1;else r=s}return e.length}function zt(e,t,n){const{commentOpen:r,commentClose:i,outputOpen:s,outputClose:o,directiveOpen:a,directiveClose:l}=n;return e.startsWith(r,t)?Bt(e,t+r.length,i):e.startsWith(s,t)?Bt(e,t+s.length,o):e.startsWith(a,t)?Bt(e,t+a.length,l):null}function Bt(e,t,n){const r=e.indexOf(n,t);return-1===r?e.length:r+n.length}const qt=e=>JSON.stringify(e,(e,t)=>"loc"===e||"raw"===e?void 0:t??null);class Kt{constructor(e={}){Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options={continueOnError:!1,undefinedFallback:"",ignoreMissingFilters:!1,onError:()=>{},...e}}safeEvaluate(e,t,n={}){try{const n=this.evaluateExpression(e,t);return void 0===n&&void 0!==this.options.undefinedFallback?this.options.undefinedFallback:n}catch(r){const i={template:n.template||"",data:t,expression:e},s=this.options.onError(r,i);if(this.options.continueOnError)return s;throw r}}safeApplyFilter(e,t,n,r=[],i={}){try{if(!n){if(this.options.ignoreMissingFilters)return e;throw new Error(`Filter "${t}" is not defined`)}return n(e,...r)}catch(e){const n={template:i.template||"",data:i.data||{},filter:t},r=this.options.onError(e,n);if(this.options.continueOnError)return r;throw e}}wrapRender(e,t={}){return(...n)=>{try{return e(...n)}catch(e){const r={template:t.template||"",data:n[1]||{}},i=this.options.onError(e,r);if(this.options.continueOnError)return i;throw e}}}evaluateExpression(e,t){try{const n=e.split(".");let r=t;for(const e of n){if(null==r)return;r=r[e]}return r}catch{return}}createSafeAccessor(e){return t=>{try{const n=t.split(".");let r=e;for(const e of n){if(null==r)return this.options.undefinedFallback;r=r[e]}return void 0===r?this.options.undefinedFallback:r}catch{return this.options.undefinedFallback}}}}let Ht;const Jt=new WeakMap;function Vt(e){if(!e)return Ht??(Ht=new mt);let t=Jt.get(e);return t||(t=new mt(e),Jt.set(e,t)),t}e.CompileError=r,e.Compiler=V,e.ErrorRecovery=Kt,e.ExpCompiler=ce,e.ExpError=u,e.ExpParser=P,e.ExpTokenizer=y,e.I18n=Pt,e.MAX_INCLUDE_DEPTH=100,e.MixinRegistry=St,e.Parser=D,e.RenderError=dt,e.Renderer=mt,e.RootNode=I,e.Safe=X,e.SecurityAuditor=B,e.SecuritySandbox=G,e.TemplatePipeline=class{constructor(e){Object.defineProperty(this,"templates",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"data",{enumerable:!0,configurable:!0,writable:!0,value:{}}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.options=e}addTemplate(e){return this.templates.push(e),this}setData(e){return this.data={...this.data,...e},this}setOptions(e){return this.options={...this.options,...e},this}async execute(){return jt(this.templates,{data:this.data,options:this.options})}},e.TemplateValidator=Lt,e.Tokenizer=R,e.Traversal=N,e.analyzeTemplate=wt,e.applyMixin=It,e.applyMixins=async function(e,t={},n=Nt){const r=[];for(const i of e){const e=await It(i,t,n);r.push(e)}return r},e.applyWhitespaceControl=function(e,t){let n=e;return t.stripComments&&(n=n.replace(/<!--[\s\S]*?-->/g,"")),t.collapseWhitespace&&(n=t.preserveNewlines?n.replace(/[ \t]+/g," "):n.replace(/\s+/g," ")),t.trim&&(n=n.trim()),n},e.baseOptions=Y,e.compilerOptions=ee,e.composeLayout=async function(e,t,n={}){const{data:r={},options:i}=n,s=new mt({...i,autoEscape:!1}),o=await s.render(t,r);return s.render(e,{...r,content:o})},e.composeTemplates=jt,e.composeTemplatesWithData=async function(e,t={}){let n="";const{options:r}=t,i=new mt(r);for(const t of e){const e={...t.data,_content:n};n=await i.render(t.template,e)}return n},e.composeWithSlots=async function(e,t,n={}){const{data:r={},options:i}=n,s=new mt({...i,autoEscape:!1}),o={};for(const[e,n]of Object.entries(t))o[e]=await s.render(n,r);return s.render(e,{...r,slots:o})},e.createErrorRecovery=function(e={}){return new Kt(e)},e.createFileLoader=function(e,{extensions:t=[".janja",".html"]}={}){return async n=>{const{readFile:r}=await(import("node:fs/promises")),i=await(import("node:path")),s=i.resolve(e),o=i.extname(n)?[n]:[...t.map(e=>`${n}${e}`),n];for(const e of o){const t=i.resolve(s,e);if(!t.startsWith(s+i.sep))break;try{return await r(t,"utf-8")}catch{}}throw new Error(`Template "${n}" not found in ${e}`)}},e.createMixin=function(e,t,n){return{name:e,template:t,data:n}},e.deepEscape=z,e.defaultErrorHandler=function(e,t){console.error("[Janja Error]",e.message),t.expression&&console.error(" Expression:",t.expression),t.filter&&console.error(" Filter:",t.filter)},e.defaultWhitespaceOptions=$t,e.defineFilters=function(e){return e},e.definePlugin=function(e){return e},e.expTokenTypes=h,e.extendTemplateWithMixin=async function(e,t,n={},r=Nt){const i=await It(t,n,r);return new mt({...n.options,autoEscape:!1}).render(e,{_mixin:i})},e.filters=Q,e.formatTemplate=function(t,n={}){const r={...Z,...n},i=new R(r).tokenize(t),s=[0];for(let e=0;e<t.length;e++)"\n"===t[e]&&s.push(e+1);const o=({line:e,column:t})=>s[e-1]+t-1,a=new P,l=new Rt,c=(e,t)=>{try{const n=a.parse(e,t),r=l.format(n);return qt(a.parse(r,t))!==qt(n)?null:r.replace(/[{}]/g,"\\$&")}catch{return null}},u=i.map(n=>{const i=t.slice(o(n.loc.start),o(n.loc.end));return n.type===e.TokenType.TEXT||n.type===e.TokenType.COMMENT&&n.val.includes("\n")?i:(t=>{const n=t.strip.before?"-":"",i=t.strip.after?"-":"";if(t.type===e.TokenType.COMMENT)return`${r.commentOpen}${n} ${t.val.trim()} ${i}${r.commentClose}`;if(t.type===e.TokenType.OUTPUT){const e=c(t.val,t.loc);return e&&`${r.outputOpen}${n} ${e} ${i}${r.outputClose}`}const{name:s,expression:o}=t;if(!s)return null;const a=o?c(o.val,o.loc):"";return null!==a&&`${r.directiveOpen}${n} ${s}${a&&` ${a}`} ${i}${r.directiveClose}`})(n)||i}).join("");return!1===n.html?u:function(e,t){const n=t.tabWidth??2,r=" ".repeat(Math.max(0,n)),i=e.includes("\r\n")?"\r\n":"\n",s=e.split(/\r?\n/);let o=0,a=null;const l=[];for(const e of s){const n=e.match(/^[ \t]*/)?.[0].length??0,i=e.slice(n),{pieces:s,prefixClosers:u}=Xt(i,t),p=a,h=null!==p&&s.some(e=>"close"===e.kind&&e.sensitive===p);if(a&&!h){l.push(e),c(s);continue}const f=Math.max(0,o-u);l.push(0===i.length?"":r.repeat(f)+i),c(s)}return l.join(i);function c(e){for(const t of e)"open"===t.kind?(o+=1,t.sensitive&&!a&&({sensitive:a}=t)):"close"===t.kind?(o=Math.max(0,o-1),t.sensitive&&a===t.sensitive&&(a=null)):t.kind}}(u,{tabWidth:n.tabWidth,commentOpen:r.commentOpen,commentClose:r.commentClose,directiveOpen:r.directiveOpen,directiveClose:r.directiveClose,outputOpen:r.outputOpen,outputClose:r.outputClose})},e.generateDeclarations=vt,e.generateSourceMap=Ot,e.getWhitespaceCompilerOptions=function(e){const t=kt(e);return{trimWhitespace:t.trim,stripComments:t.stripComments}},e.getWhitespaceRendererOptions=function(e){const t=kt(e),n={};return t.trim!==$t.trim&&(n.trimWhitespace=t.trim),t.stripComments!==$t.stripComments&&(n.stripComments=t.stripComments),n},e.globalMixinRegistry=Nt,e.i18n=Tt,e.isForbiddenIdentifier=d,e.mergeOptions=ne,e.mergeWhitespaceOptions=kt,e.optionsFingerprint=J,e.parserOptions=Z,e.precompile=Et,e.precompileTemplate=async function(e,t={}){return(await Et(e,t)).code},e.render=async function(e,t,n){return Vt(n).render(e,t)},e.renderCompiled=async function(e,t={},n){return Vt(n).renderCompiled(e,t)},e.renderFile=async function(e,t,n){return Vt(n).renderFile(e,t)},e.renderOptions=te,e.renderStream=function(e,t={},n){return Vt(n).renderStream(e,t)},e.resolveSecurityLimits=W,e.templateCacheKey=H,e.validateTemplate=async function(e,t){return new Lt(t).validate(e)}}(this.janja=this.janja||{});
|