@b4moss/hyogen-md 0.10.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.js ADDED
@@ -0,0 +1,3109 @@
1
+ import { stat as te, readFile as Ee, mkdir as qe, writeFile as Pe } from "node:fs/promises";
2
+ import u from "node:path";
3
+ import { existsSync as we, statSync as Ve } from "node:fs";
4
+ import { parse as Ke } from "yaml";
5
+ import Ye from "fast-glob";
6
+ import Ge from "picomatch";
7
+ function b(...t) {
8
+ const e = {};
9
+ for (const n of t)
10
+ n != null && Object.assign(e, n);
11
+ return e;
12
+ }
13
+ const Xe = { file_not_found: "File not found: {path} (referenced from {from} via {via})", frontmatter_too_large: "Front matter exceeds size limit in {path} ({size} bytes, limit {limit})", duplicate_component_alias: 'Duplicate component alias "{alias}" in {path}', alias_collision: 'Component alias "{alias}" collides with an existing binding in {path}', forbidden_property_access: 'Forbidden property access "{property}" in {path}', parse_error: "Parse error in {path}: {message}", component_multiline_output: 'Component "{alias}" returned multiline output (single line required)', server_context_on_client: "serverContext is not allowed with renderClient", load_failed: "Failed to load {path}: {reason}" }, Je = { circular_include: "Circular reference detected; skipped {path} (referenced from {from} via {via})", nest_limit_exceeded: "Nesting limit exceeded ({limit}); skipped block in {path}", extend_in_component: "extend is not allowed inside a component; skipped in {path}", prop_type_mismatch: 'Prop "{prop}" type mismatch in component "{component}"; expected {expected}, got {actual}', prop_missing: 'Required prop "{prop}" is missing for component "{component}"', prop_unknown: 'Unknown prop "{prop}" passed to component "{component}"; ignored', suspicious_context_value: 'Suspicious value in context key "{key}" ({reason})' }, Qe = { contains_html_script_tag: "contains HTML script tag", contains_event_handler: "contains inline event handler", contains_dangerous_scheme: "contains dangerous URL scheme", contains_embed_tag: "contains embeddable HTML tag", contains_meta_refresh: "contains meta refresh" }, ne = {
14
+ errors: Xe,
15
+ warnings: Je,
16
+ warningReasons: Qe
17
+ }, et = ne.errors, tt = ne.warnings;
18
+ function Te(t, e) {
19
+ return t === void 0 ? "" : t.replace(/\{([^}]+)\}/g, (n, r) => {
20
+ if (e === void 0 || !(r in e))
21
+ return n;
22
+ const i = e[r];
23
+ return i == null ? "" : String(i);
24
+ });
25
+ }
26
+ function nt(t, e) {
27
+ return Te(et[t], e);
28
+ }
29
+ function O(t, e) {
30
+ return Te(tt[t], e);
31
+ }
32
+ function d(t) {
33
+ const e = t.message ?? nt(t.code, t.details), n = new Error(e);
34
+ return n.name = "HyogenError", n.code = t.code, n.message = e, n.path = t.path, n.details = t.details, n;
35
+ }
36
+ function rt(t) {
37
+ return t instanceof Error && t.name === "HyogenError" && "code" in t && typeof t.code == "string";
38
+ }
39
+ function it(t = {}) {
40
+ const { from: e, via: n = "include" } = t;
41
+ return async (r) => {
42
+ try {
43
+ if (!(await te(r)).isFile())
44
+ throw d({
45
+ code: "load_failed",
46
+ path: e,
47
+ details: {
48
+ path: r,
49
+ reason: "not a file"
50
+ }
51
+ });
52
+ return await Ee(r, "utf8");
53
+ } catch (i) {
54
+ if (rt(i))
55
+ throw i;
56
+ const s = i;
57
+ throw s.code === "ENOENT" ? d({
58
+ code: "file_not_found",
59
+ path: e,
60
+ details: {
61
+ path: r,
62
+ from: e ?? r,
63
+ via: n
64
+ }
65
+ }) : d({
66
+ code: "load_failed",
67
+ path: e,
68
+ details: {
69
+ path: r,
70
+ reason: s.message ?? "unknown load error"
71
+ }
72
+ });
73
+ }
74
+ };
75
+ }
76
+ function j(t) {
77
+ return /^https?:\/\//i.test(t);
78
+ }
79
+ function st(t) {
80
+ return t instanceof Error && t.name === "HyogenError" && "code" in t && typeof t.code == "string";
81
+ }
82
+ function $e(t = {}) {
83
+ const { from: e, via: n = "include" } = t, r = it(t);
84
+ return async (i) => {
85
+ if (!j(i))
86
+ return r(i);
87
+ try {
88
+ const s = await fetch(i);
89
+ if (!s.ok)
90
+ throw s.status === 404 ? d({
91
+ code: "file_not_found",
92
+ path: e,
93
+ details: {
94
+ path: i,
95
+ from: e ?? i,
96
+ via: n
97
+ }
98
+ }) : d({
99
+ code: "load_failed",
100
+ path: e,
101
+ details: {
102
+ path: i,
103
+ reason: `HTTP ${s.status}`
104
+ }
105
+ });
106
+ return await s.text();
107
+ } catch (s) {
108
+ if (st(s))
109
+ throw s;
110
+ const o = s instanceof Error ? s.message : "unknown fetch error";
111
+ throw d({
112
+ code: "load_failed",
113
+ path: e,
114
+ details: {
115
+ path: i,
116
+ reason: o
117
+ }
118
+ });
119
+ }
120
+ };
121
+ }
122
+ const ot = ".doc_root";
123
+ function z(t) {
124
+ let e;
125
+ for (we(t) ? e = Ve(t).isFile() ? u.dirname(t) : u.resolve(t) : e = u.dirname(u.resolve(t)); ; ) {
126
+ const n = u.join(e, ot);
127
+ if (we(n))
128
+ return e;
129
+ const r = u.dirname(e);
130
+ if (r === e)
131
+ return;
132
+ e = r;
133
+ }
134
+ }
135
+ async function at(t, e) {
136
+ if (typeof t == "string")
137
+ return {
138
+ source: t,
139
+ rootDir: e?.root
140
+ };
141
+ const n = u.resolve(t.path);
142
+ let r;
143
+ try {
144
+ r = await te(n);
145
+ } catch (a) {
146
+ const c = a;
147
+ throw c.code === "ENOENT" ? d({
148
+ code: "file_not_found",
149
+ path: n,
150
+ details: {
151
+ path: n,
152
+ from: n,
153
+ via: "include"
154
+ }
155
+ }) : d({
156
+ code: "load_failed",
157
+ path: n,
158
+ details: {
159
+ path: n,
160
+ reason: c.message ?? "unknown load error"
161
+ }
162
+ });
163
+ }
164
+ if (!r.isFile())
165
+ throw d({
166
+ code: "parse_error",
167
+ path: n,
168
+ details: { message: "path is not a file" }
169
+ });
170
+ let i;
171
+ try {
172
+ i = await Ee(n, "utf8");
173
+ } catch (a) {
174
+ throw d({
175
+ code: "load_failed",
176
+ path: n,
177
+ details: {
178
+ path: n,
179
+ reason: a.message ?? "unknown load error"
180
+ }
181
+ });
182
+ }
183
+ const s = z(n), o = e?.root ?? s;
184
+ return {
185
+ source: i,
186
+ rootDir: o,
187
+ entryPath: n,
188
+ constrainToRoot: s !== void 0
189
+ };
190
+ }
191
+ class Ae {
192
+ components = /* @__PURE__ */ new Map();
193
+ register(e, n, r) {
194
+ if (this.components.has(e.alias))
195
+ throw d({
196
+ code: "duplicate_component_alias",
197
+ path: r ?? e.definedAt,
198
+ details: { alias: e.alias }
199
+ });
200
+ if (n.includes(e.alias))
201
+ throw d({
202
+ code: "alias_collision",
203
+ path: r ?? e.definedAt,
204
+ details: { alias: e.alias }
205
+ });
206
+ this.components.set(e.alias, e);
207
+ }
208
+ get(e) {
209
+ return this.components.get(e);
210
+ }
211
+ has(e) {
212
+ return this.components.has(e);
213
+ }
214
+ }
215
+ const xe = 64 * 1024;
216
+ function U(t, e) {
217
+ if (!t.startsWith("---"))
218
+ return { context: {}, body: t };
219
+ const n = t.indexOf(`
220
+ `);
221
+ if (n === -1)
222
+ return { context: {}, body: t };
223
+ const r = t.indexOf(`
224
+ ---`, n);
225
+ if (r === -1)
226
+ return { context: {}, body: t };
227
+ const i = t.slice(n + 1, r), s = Buffer.byteLength(i, "utf8");
228
+ if (s > xe)
229
+ throw d({
230
+ code: "frontmatter_too_large",
231
+ path: e,
232
+ details: {
233
+ size: s,
234
+ limit: xe
235
+ }
236
+ });
237
+ if (i.trim().length === 0)
238
+ throw d({
239
+ code: "parse_error",
240
+ path: e,
241
+ details: { message: "empty front matter" }
242
+ });
243
+ let o;
244
+ try {
245
+ const h = Ke(i);
246
+ if (h == null)
247
+ o = {};
248
+ else if (typeof h == "object" && !Array.isArray(h))
249
+ o = h;
250
+ else
251
+ throw new Error("front matter must be a YAML mapping");
252
+ } catch (h) {
253
+ throw d({
254
+ code: "parse_error",
255
+ path: e,
256
+ details: {
257
+ message: h instanceof Error ? h.message : "invalid YAML front matter"
258
+ }
259
+ });
260
+ }
261
+ const a = r + 4;
262
+ let c = t.slice(a);
263
+ return c.startsWith(`
264
+ `) ? c = c.slice(1) : c.startsWith(`\r
265
+ `) && (c = c.slice(2)), {
266
+ context: o,
267
+ body: c,
268
+ rawFrontMatter: `---
269
+ ${i}
270
+ ---`
271
+ };
272
+ }
273
+ const ct = /* @__PURE__ */ new Set([
274
+ "string",
275
+ "number",
276
+ "boolean",
277
+ "object",
278
+ "array"
279
+ ]);
280
+ function ht(t, e) {
281
+ const n = t.props;
282
+ if (n === void 0)
283
+ return {};
284
+ if (typeof n != "object" || n === null || Array.isArray(n))
285
+ throw d({
286
+ code: "parse_error",
287
+ path: e,
288
+ details: { message: "props must be a YAML mapping" }
289
+ });
290
+ const r = {};
291
+ for (const [i, s] of Object.entries(n)) {
292
+ if (typeof s != "object" || s === null || Array.isArray(s)) {
293
+ r[i] = {};
294
+ continue;
295
+ }
296
+ const o = s, a = {};
297
+ if ("type" in o && o.type !== void 0) {
298
+ const c = String(o.type);
299
+ ct.has(c) ? a.type = c : a.type = void 0;
300
+ }
301
+ "isRequired" in o && (a.isRequired = !!o.isRequired), "default" in o && (a.default = o.default), r[i] = a;
302
+ }
303
+ return r;
304
+ }
305
+ function lt(t) {
306
+ if (t != null) {
307
+ if (typeof t == "string") return "string";
308
+ if (typeof t == "number") return "number";
309
+ if (typeof t == "boolean") return "boolean";
310
+ if (Array.isArray(t)) return "array";
311
+ if (typeof t == "object") return "object";
312
+ }
313
+ }
314
+ function dt(t, e) {
315
+ return e === "array" ? Array.isArray(t) : e === "object" ? typeof t == "object" && t !== null && !Array.isArray(t) : typeof t === e;
316
+ }
317
+ function K(t, e) {
318
+ return {
319
+ code: t,
320
+ message: O(t, e),
321
+ details: e
322
+ };
323
+ }
324
+ function pt(t, e, n) {
325
+ const r = [], i = {}, s = new Set(Object.keys(e));
326
+ for (const [o, a] of Object.entries(e)) {
327
+ const c = Object.prototype.hasOwnProperty.call(t, o);
328
+ let h = c ? t[o] : void 0;
329
+ if (c || (a.default !== void 0 ? h = a.default : (a.isRequired && r.push(
330
+ K("prop_missing", {
331
+ prop: o,
332
+ component: n
333
+ })
334
+ ), h = void 0)), c && h !== void 0 && h !== null) {
335
+ const l = a.type ?? lt(h);
336
+ l && !dt(h, l) && (r.push(
337
+ K("prop_type_mismatch", {
338
+ prop: o,
339
+ component: n,
340
+ expected: l,
341
+ actual: typeof h
342
+ })
343
+ ), h = void 0);
344
+ }
345
+ i[o] = h;
346
+ }
347
+ for (const o of Object.keys(t))
348
+ s.has(o) || (Object.keys(e).length > 0 ? r.push(
349
+ K("prop_unknown", {
350
+ prop: o,
351
+ component: n
352
+ })
353
+ ) : i[o] = t[o]);
354
+ return { values: i, warnings: r };
355
+ }
356
+ function ut(t, e) {
357
+ const n = u.relative(e, t);
358
+ return n === "" || !n.startsWith("..") && !u.isAbsolute(n);
359
+ }
360
+ function ft(t, e, n) {
361
+ const r = u.resolve(e), i = u.resolve(t);
362
+ if (!ut(i, r))
363
+ throw d({
364
+ code: "parse_error",
365
+ path: n,
366
+ details: { message: "path resolves outside root directory" }
367
+ });
368
+ }
369
+ function re(t, e = {}) {
370
+ const { rootDir: n, fromPath: r, documentPath: i, constrainToRoot: s = !1, hyogenPath: o = !1 } = e;
371
+ if (t.length === 0)
372
+ throw d({
373
+ code: "parse_error",
374
+ path: i,
375
+ details: { message: "empty template path" }
376
+ });
377
+ let a;
378
+ if (t.startsWith("/"))
379
+ if (n)
380
+ a = u.resolve(n, t.slice(1));
381
+ else {
382
+ if (o)
383
+ throw d({
384
+ code: "parse_error",
385
+ path: i,
386
+ details: { message: "root-relative paths require a doc root" }
387
+ });
388
+ if (u.isAbsolute(t))
389
+ a = u.resolve(t);
390
+ else
391
+ throw d({
392
+ code: "parse_error",
393
+ path: i,
394
+ details: { message: "root-relative paths require a doc root" }
395
+ });
396
+ }
397
+ else if (t.startsWith("./") || t.startsWith("../"))
398
+ if (r)
399
+ a = u.resolve(u.dirname(r), t);
400
+ else if (n)
401
+ a = u.resolve(n, t);
402
+ else
403
+ throw d({
404
+ code: "parse_error",
405
+ path: i,
406
+ details: { message: "root is required for relative template paths" }
407
+ });
408
+ else if (u.isAbsolute(t))
409
+ a = u.resolve(t);
410
+ else if (n)
411
+ a = u.resolve(n, t);
412
+ else
413
+ throw d({
414
+ code: "parse_error",
415
+ path: i,
416
+ details: { message: "root is required for relative template paths" }
417
+ });
418
+ return n && s && ft(a, n, i), a;
419
+ }
420
+ async function mt(t) {
421
+ const e = t.registry.get(t.alias);
422
+ if (!e)
423
+ throw d({
424
+ code: "parse_error",
425
+ path: t.path,
426
+ details: {
427
+ message: `unregistered component: ${t.alias}`
428
+ }
429
+ });
430
+ const n = j(e.componentPath) ? e.componentPath : re(e.componentPath, {
431
+ rootDir: t.rootDir,
432
+ fromPath: e.definedAt,
433
+ documentPath: t.path,
434
+ constrainToRoot: t.constrainToRoot,
435
+ hyogenPath: !0
436
+ }), r = await t.loader(n), { context: i, body: s } = U(r, n), o = ht(i, n), { values: a, warnings: c } = pt(
437
+ t.props,
438
+ o,
439
+ t.alias
440
+ );
441
+ t.warnings.push(...c);
442
+ const { props: h, ...l } = i, p = b(
443
+ t.parentContext,
444
+ l,
445
+ a
446
+ ), g = (await me(s, {
447
+ context: p,
448
+ loader: t.loader,
449
+ root: t.rootDir,
450
+ path: n,
451
+ registry: t.registry,
452
+ warnings: t.warnings,
453
+ visitStack: t.visitStack,
454
+ inComponent: !0,
455
+ preserveFrontMatter: !1,
456
+ preserveHgComments: t.preserveHgComments,
457
+ constrainToRoot: t.constrainToRoot
458
+ })).trim();
459
+ if (g.includes(`
460
+ `))
461
+ throw d({
462
+ code: "component_multiline_output",
463
+ path: n,
464
+ details: { alias: t.alias }
465
+ });
466
+ return g;
467
+ }
468
+ const gt = /* @__PURE__ */ new Set([
469
+ "__proto__",
470
+ "prototype",
471
+ "constructor",
472
+ "__defineGetter__"
473
+ ]);
474
+ function wt(t) {
475
+ return gt.has(t);
476
+ }
477
+ function ke(t, e) {
478
+ if (wt(t))
479
+ throw d({
480
+ code: "forbidden_property_access",
481
+ path: e,
482
+ details: { property: t }
483
+ });
484
+ }
485
+ function R(t) {
486
+ return !t;
487
+ }
488
+ function xt(t, e) {
489
+ if (t != null && typeof t == "object")
490
+ return t[e];
491
+ }
492
+ function kt(t, e, n) {
493
+ switch (t) {
494
+ case "+":
495
+ return e + n;
496
+ case "-":
497
+ return e - n;
498
+ case "*":
499
+ return e * n;
500
+ case "/":
501
+ return e / n;
502
+ case "===":
503
+ return e === n;
504
+ case "!==":
505
+ return e !== n;
506
+ case "==":
507
+ return e == n;
508
+ case "!=":
509
+ return e != n;
510
+ case ">=":
511
+ return e >= n;
512
+ case "<=":
513
+ return e <= n;
514
+ case ">":
515
+ return e > n;
516
+ case "<":
517
+ return e < n;
518
+ case "&&":
519
+ return R(e) ? e : n;
520
+ case "||":
521
+ return R(e) ? n : e;
522
+ default:
523
+ return;
524
+ }
525
+ }
526
+ async function k(t, e) {
527
+ const { context: n, path: r } = e;
528
+ switch (t.type) {
529
+ case "literal":
530
+ return t.value;
531
+ case "identifier":
532
+ return ke(t.name, r), n[t.name];
533
+ case "member": {
534
+ ke(t.property, r);
535
+ const i = await k(t.object, e);
536
+ return xt(i, t.property);
537
+ }
538
+ case "default": {
539
+ const i = await k(t.left, e);
540
+ return R(i) ? k(t.right, e) : i;
541
+ }
542
+ case "unary": {
543
+ const i = await k(t.operand, e);
544
+ return t.op === "!" ? !i : void 0;
545
+ }
546
+ case "binary": {
547
+ if (t.op === "&&") {
548
+ const o = await k(t.left, e);
549
+ return R(o) ? o : k(t.right, e);
550
+ }
551
+ if (t.op === "||") {
552
+ const o = await k(t.left, e);
553
+ return R(o) ? k(t.right, e) : o;
554
+ }
555
+ const i = await k(t.left, e), s = await k(t.right, e);
556
+ return kt(t.op, i, s);
557
+ }
558
+ case "call": {
559
+ if (!e.registry || !e.loader || !e.visitStack)
560
+ throw d({
561
+ code: "parse_error",
562
+ path: r,
563
+ details: {
564
+ message: `function calls are not allowed: ${t.callee}()`
565
+ }
566
+ });
567
+ if (!e.registry.has(t.callee))
568
+ throw d({
569
+ code: "parse_error",
570
+ path: r,
571
+ details: {
572
+ message: `unregistered component: ${t.callee}`
573
+ }
574
+ });
575
+ const i = {};
576
+ for (const [s, o] of Object.entries(t.args))
577
+ i[s] = await k(o, e);
578
+ return mt({
579
+ alias: t.callee,
580
+ props: i,
581
+ parentContext: e.parentContext ?? n,
582
+ registry: e.registry,
583
+ loader: e.loader,
584
+ rootDir: e.rootDir,
585
+ path: r,
586
+ warnings: e.warnings ?? [],
587
+ visitStack: e.visitStack,
588
+ preserveHgComments: e.preserveHgComments,
589
+ constrainToRoot: e.constrainToRoot
590
+ });
591
+ }
592
+ case "method": {
593
+ if (t.method !== "toLocaleString")
594
+ throw d({
595
+ code: "parse_error",
596
+ path: r,
597
+ details: { message: `unsupported method: ${t.method}()` }
598
+ });
599
+ const i = await k(t.object, e);
600
+ return i == null || typeof i.toLocaleString != "function" ? void 0 : i.toLocaleString(
601
+ ...t.args
602
+ );
603
+ }
604
+ case "ternary": {
605
+ const i = await k(t.condition, e);
606
+ return R(i) ? k(t.alternate, e) : k(t.consequent, e);
607
+ }
608
+ case "template": {
609
+ let i = "";
610
+ for (const s of t.parts)
611
+ if (typeof s == "string")
612
+ i += s;
613
+ else {
614
+ const o = await k(s, e);
615
+ o != null && (i += String(o));
616
+ }
617
+ return i;
618
+ }
619
+ default:
620
+ return;
621
+ }
622
+ }
623
+ function Y(t) {
624
+ return /[A-Za-z_$]/.test(t);
625
+ }
626
+ function yt(t) {
627
+ return /[A-Za-z0-9_$]/.test(t);
628
+ }
629
+ function S(t, e, n = {}) {
630
+ const r = t.trim();
631
+ if (r.length === 0)
632
+ throw m(e, "empty expression");
633
+ const i = new bt(r, e, n), s = i.parseExpression();
634
+ if (i.skipWhitespace(), i.hasMore())
635
+ throw m(e, `unexpected token at position ${i.position}`);
636
+ return s;
637
+ }
638
+ function m(t, e) {
639
+ throw d({
640
+ code: "parse_error",
641
+ path: t,
642
+ details: { message: e }
643
+ });
644
+ }
645
+ class bt {
646
+ constructor(e, n, r = {}) {
647
+ this.input = e, this.path = n, this.allowCalls = r.allowCalls !== !1;
648
+ }
649
+ input;
650
+ path;
651
+ index = 0;
652
+ allowCalls;
653
+ get position() {
654
+ return this.index;
655
+ }
656
+ hasMore() {
657
+ return this.skipWhitespace(), this.index < this.input.length;
658
+ }
659
+ skipWhitespace() {
660
+ for (; this.index < this.input.length && /\s/.test(this.input[this.index]); )
661
+ this.index++;
662
+ }
663
+ parseExpression() {
664
+ return this.parsePipe();
665
+ }
666
+ parsePipe() {
667
+ let e = this.parseTernary();
668
+ for (; this.skipWhitespace(), !(this.peek() !== "|" || this.input[this.index + 1] === "|"); ) {
669
+ this.index++;
670
+ const n = this.parseTernary();
671
+ e = { type: "default", left: e, right: n };
672
+ }
673
+ return e;
674
+ }
675
+ parseTernary() {
676
+ const e = this.parseLogicalOr();
677
+ if (this.skipWhitespace(), this.peek() !== "?")
678
+ return e;
679
+ this.index++;
680
+ const n = this.parseTernary();
681
+ if (this.skipWhitespace(), this.peek() !== ":")
682
+ throw m(this.path, "expected ':' in ternary expression");
683
+ this.index++;
684
+ const r = this.parseTernary();
685
+ return { type: "ternary", condition: e, consequent: n, alternate: r };
686
+ }
687
+ parseLogicalOr() {
688
+ let e = this.parseLogicalAnd();
689
+ for (; this.skipWhitespace(), !!this.match("||"); ) {
690
+ const n = this.parseLogicalAnd();
691
+ e = { type: "binary", op: "||", left: e, right: n };
692
+ }
693
+ return e;
694
+ }
695
+ parseLogicalAnd() {
696
+ let e = this.parseComparison();
697
+ for (; this.skipWhitespace(), !!this.match("&&"); ) {
698
+ const n = this.parseComparison();
699
+ e = { type: "binary", op: "&&", left: e, right: n };
700
+ }
701
+ return e;
702
+ }
703
+ parseComparison() {
704
+ let e = this.parseAdditive();
705
+ for (; ; ) {
706
+ this.skipWhitespace();
707
+ const n = this.readComparisonOp();
708
+ if (!n)
709
+ break;
710
+ const r = this.parseAdditive();
711
+ e = { type: "binary", op: n, left: e, right: r };
712
+ }
713
+ return e;
714
+ }
715
+ readComparisonOp() {
716
+ const e = [
717
+ "===",
718
+ "!==",
719
+ "==",
720
+ "!=",
721
+ ">=",
722
+ "<=",
723
+ ">",
724
+ "<"
725
+ ];
726
+ for (const n of e)
727
+ if (this.input.startsWith(n, this.index))
728
+ return this.index += n.length, n;
729
+ return null;
730
+ }
731
+ parseAdditive() {
732
+ let e = this.parseMultiplicative();
733
+ for (; ; ) {
734
+ this.skipWhitespace();
735
+ const n = this.peek();
736
+ if (n !== "+" && n !== "-")
737
+ break;
738
+ this.index++;
739
+ const r = this.parseMultiplicative();
740
+ e = { type: "binary", op: n, left: e, right: r };
741
+ }
742
+ return e;
743
+ }
744
+ parseMultiplicative() {
745
+ let e = this.parseUnary();
746
+ for (; ; ) {
747
+ this.skipWhitespace();
748
+ const n = this.peek();
749
+ if (n !== "*" && n !== "/")
750
+ break;
751
+ this.index++;
752
+ const r = this.parseUnary();
753
+ e = { type: "binary", op: n, left: e, right: r };
754
+ }
755
+ return e;
756
+ }
757
+ parseUnary() {
758
+ return this.skipWhitespace(), this.peek() === "!" ? (this.index++, { type: "unary", op: "!", operand: this.parseUnary() }) : this.parsePostfix();
759
+ }
760
+ parsePostfix() {
761
+ let e = this.parsePrimary();
762
+ for (; ; ) {
763
+ if (this.skipWhitespace(), this.peek() === ".") {
764
+ this.index++, e = this.parseAfterDot(e);
765
+ continue;
766
+ }
767
+ break;
768
+ }
769
+ return e;
770
+ }
771
+ parseAfterDot(e) {
772
+ this.skipWhitespace();
773
+ const n = this.readIdentifier();
774
+ if (!n)
775
+ throw m(this.path, "expected property name after '.'");
776
+ if (this.skipWhitespace(), this.peek() === "(") {
777
+ if (n !== "toLocaleString")
778
+ throw m(this.path, `unsupported method: ${n}()`);
779
+ this.index++;
780
+ const r = this.parseMethodArgs();
781
+ return { type: "method", object: e, method: n, args: r };
782
+ }
783
+ return { type: "member", object: e, property: n };
784
+ }
785
+ parseMethodArgs() {
786
+ this.skipWhitespace();
787
+ const e = [];
788
+ if (this.peek() === ")")
789
+ return this.index++, e;
790
+ for (e.push(this.parseLiteralValue()), this.skipWhitespace(); this.peek() === ","; )
791
+ this.index++, e.push(this.parseLiteralValue()), this.skipWhitespace();
792
+ if (this.peek() !== ")")
793
+ throw m(this.path, "expected ')' after method arguments");
794
+ return this.index++, e;
795
+ }
796
+ parsePrimary() {
797
+ this.skipWhitespace();
798
+ const e = this.peek();
799
+ if (e === "(") {
800
+ this.index++;
801
+ const n = this.parseExpression();
802
+ if (this.skipWhitespace(), this.peek() !== ")")
803
+ throw m(this.path, "expected ')'");
804
+ return this.index++, n;
805
+ }
806
+ if (e === "`")
807
+ return this.parseTemplateLiteral();
808
+ if (e === '"' || e === "'")
809
+ return { type: "literal", value: this.readString() };
810
+ if (e === "-" || e >= "0" && e <= "9")
811
+ return { type: "literal", value: this.readNumber() };
812
+ if (e === "{")
813
+ return { type: "literal", value: this.parseObjectLiteral() };
814
+ if (e === "[")
815
+ return { type: "literal", value: this.parseArrayLiteral() };
816
+ if (Y(e)) {
817
+ const n = this.readIdentifier();
818
+ if (n === "true" || n === "false" || n === "null" || n === "undefined")
819
+ return { type: "literal", value: n === "true" ? !0 : n === "false" ? !1 : n === "null" ? null : void 0 };
820
+ if (this.skipWhitespace(), this.peek() === "(") {
821
+ if (!this.allowCalls)
822
+ throw m(
823
+ this.path,
824
+ "component calls are not allowed in template literals"
825
+ );
826
+ this.index++;
827
+ const r = this.parseCallArgs();
828
+ return { type: "call", callee: n, args: r };
829
+ }
830
+ if (this.peek() === "[")
831
+ throw m(this.path, "bracket access is not allowed");
832
+ return { type: "identifier", name: n };
833
+ }
834
+ throw m(this.path, `unexpected character '${e}'`);
835
+ }
836
+ parseTemplateLiteral() {
837
+ this.index++;
838
+ const e = [];
839
+ let n = "";
840
+ for (; this.index < this.input.length; ) {
841
+ const r = this.input[this.index];
842
+ if (r === "`")
843
+ return this.index++, e.push(n), { type: "template", parts: e };
844
+ if (r === "\\") {
845
+ if (this.index++, this.index >= this.input.length)
846
+ throw m(this.path, "unterminated template literal escape");
847
+ n += this.input[this.index], this.index++;
848
+ continue;
849
+ }
850
+ if (r === "$" && this.input[this.index + 1] === "{") {
851
+ e.push(n), n = "", this.index += 2;
852
+ const i = this.readTemplateExpression(), s = S(i, this.path, {
853
+ allowCalls: !1
854
+ });
855
+ e.push(s);
856
+ continue;
857
+ }
858
+ n += r, this.index++;
859
+ }
860
+ throw m(this.path, "unterminated template literal");
861
+ }
862
+ readTemplateExpression() {
863
+ let e = 1;
864
+ const n = this.index;
865
+ let r = null;
866
+ for (; this.index < this.input.length; ) {
867
+ const i = this.input[this.index];
868
+ if (r) {
869
+ if (i === "\\") {
870
+ this.index += 2;
871
+ continue;
872
+ }
873
+ i === r && (r = null), this.index++;
874
+ continue;
875
+ }
876
+ if (i === '"' || i === "'" || i === "`") {
877
+ r = i, this.index++;
878
+ continue;
879
+ }
880
+ if (i === "{") {
881
+ e++, this.index++;
882
+ continue;
883
+ }
884
+ if (i === "}") {
885
+ if (e--, e === 0) {
886
+ const s = this.input.slice(n, this.index);
887
+ return this.index++, s;
888
+ }
889
+ this.index++;
890
+ continue;
891
+ }
892
+ this.index++;
893
+ }
894
+ throw m(this.path, "unterminated template expression");
895
+ }
896
+ parseCallArgs() {
897
+ if (this.skipWhitespace(), this.peek() === ")")
898
+ return this.index++, {};
899
+ if (this.peek() !== "{")
900
+ throw m(this.path, "expected object literal");
901
+ this.index++, this.skipWhitespace();
902
+ const e = {};
903
+ if (this.peek() === "}") {
904
+ if (this.index++, this.skipWhitespace(), this.peek() !== ")")
905
+ throw m(this.path, "expected ')' after call arguments");
906
+ return this.index++, e;
907
+ }
908
+ for (; ; ) {
909
+ this.skipWhitespace();
910
+ const n = this.readIdentifier();
911
+ if (!n)
912
+ throw m(this.path, "expected property name in object literal");
913
+ if (this.skipWhitespace(), this.peek() !== ":")
914
+ throw m(this.path, "expected ':' in object literal");
915
+ if (this.index++, this.skipWhitespace(), e[n] = this.parseTernary(), this.skipWhitespace(), this.peek() === "}") {
916
+ this.index++;
917
+ break;
918
+ }
919
+ if (this.peek() === ",") {
920
+ if (this.index++, this.skipWhitespace(), this.peek() === "}") {
921
+ this.index++;
922
+ break;
923
+ }
924
+ continue;
925
+ }
926
+ throw m(this.path, "expected ',' or '}' in object literal");
927
+ }
928
+ if (this.skipWhitespace(), this.peek() !== ")")
929
+ throw m(this.path, "expected ')' after call arguments");
930
+ return this.index++, e;
931
+ }
932
+ parseObjectLiteral() {
933
+ if (this.peek() !== "{")
934
+ throw m(this.path, "expected object literal");
935
+ this.index++, this.skipWhitespace();
936
+ const e = {};
937
+ if (this.peek() === "}")
938
+ return this.index++, e;
939
+ for (; ; ) {
940
+ this.skipWhitespace();
941
+ const n = this.readIdentifier();
942
+ if (!n)
943
+ throw m(this.path, "expected property name in object literal");
944
+ if (this.skipWhitespace(), this.peek() !== ":")
945
+ throw m(this.path, "expected ':' in object literal");
946
+ if (this.index++, this.skipWhitespace(), e[n] = this.parseLiteralValue(), this.skipWhitespace(), this.peek() === "}") {
947
+ this.index++;
948
+ break;
949
+ }
950
+ if (this.peek() === ",") {
951
+ if (this.index++, this.skipWhitespace(), this.peek() === "}") {
952
+ this.index++;
953
+ break;
954
+ }
955
+ } else
956
+ throw m(this.path, "expected ',' or '}' in object literal");
957
+ }
958
+ return e;
959
+ }
960
+ parseArrayLiteral() {
961
+ if (this.peek() !== "[")
962
+ throw m(this.path, "expected array literal");
963
+ this.index++, this.skipWhitespace();
964
+ const e = [];
965
+ if (this.peek() === "]")
966
+ return this.index++, e;
967
+ for (; ; ) {
968
+ if (this.skipWhitespace(), e.push(this.parseLiteralValue()), this.skipWhitespace(), this.peek() === "]") {
969
+ this.index++;
970
+ break;
971
+ }
972
+ if (this.peek() === ",") {
973
+ if (this.index++, this.skipWhitespace(), this.peek() === "]") {
974
+ this.index++;
975
+ break;
976
+ }
977
+ } else
978
+ throw m(this.path, "expected ',' or ']' in array literal");
979
+ }
980
+ return e;
981
+ }
982
+ parseLiteralValue() {
983
+ this.skipWhitespace();
984
+ const e = this.peek();
985
+ if (e === '"' || e === "'")
986
+ return this.readString();
987
+ if (e === "-" || e >= "0" && e <= "9")
988
+ return this.readNumber();
989
+ if (e === "{")
990
+ return this.parseObjectLiteral();
991
+ if (e === "[")
992
+ return this.parseArrayLiteral();
993
+ if (Y(e)) {
994
+ const n = this.readIdentifier();
995
+ if (n === "true") return !0;
996
+ if (n === "false") return !1;
997
+ if (n === "null") return null;
998
+ throw m(this.path, "object literal values must be literals");
999
+ }
1000
+ throw m(this.path, "object literal values must be literals");
1001
+ }
1002
+ match(e) {
1003
+ return this.skipWhitespace(), this.input.startsWith(e, this.index) ? (this.index += e.length, !0) : !1;
1004
+ }
1005
+ peek() {
1006
+ return this.input[this.index] ?? "";
1007
+ }
1008
+ readIdentifier() {
1009
+ this.skipWhitespace();
1010
+ const e = this.index;
1011
+ if (!Y(this.peek()))
1012
+ return "";
1013
+ for (this.index++; this.index < this.input.length && yt(this.peek()); )
1014
+ this.index++;
1015
+ return this.input.slice(e, this.index);
1016
+ }
1017
+ readString() {
1018
+ const e = this.peek();
1019
+ this.index++;
1020
+ let n = "";
1021
+ for (; this.index < this.input.length; ) {
1022
+ const r = this.input[this.index];
1023
+ if (r === e)
1024
+ return this.index++, n;
1025
+ if (r === "\\") {
1026
+ if (this.index++, this.index >= this.input.length)
1027
+ throw m(this.path, "unterminated string escape");
1028
+ const i = this.input[this.index];
1029
+ n += i, this.index++;
1030
+ continue;
1031
+ }
1032
+ n += r, this.index++;
1033
+ }
1034
+ throw m(this.path, "unterminated string literal");
1035
+ }
1036
+ readNumber() {
1037
+ const e = this.index;
1038
+ for (this.peek() === "-" && this.index++; this.index < this.input.length && /[0-9.]/.test(this.peek()); )
1039
+ this.index++;
1040
+ const n = this.input.slice(e, this.index), r = Number(n);
1041
+ if (Number.isNaN(r))
1042
+ throw m(this.path, `invalid number '${n}'`);
1043
+ return r;
1044
+ }
1045
+ }
1046
+ async function Re(t, e, n = {}) {
1047
+ const r = n.path;
1048
+ let i = "", s = 0;
1049
+ for (; s < t.length; ) {
1050
+ const o = t.indexOf("{", s);
1051
+ if (o === -1) {
1052
+ i += t.slice(s);
1053
+ break;
1054
+ }
1055
+ i += t.slice(s, o);
1056
+ const a = t[o + 1] === "{" && t[o + 2] === "{" && (o === 0 || t[o - 1] !== "\\");
1057
+ if (!(!a && t[o + 1] === "{" && (o === 0 || t[o - 1] !== "\\")) && !a) {
1058
+ i += "{", s = o + 1;
1059
+ continue;
1060
+ }
1061
+ const h = a ? 3 : 2, l = a ? "}}}" : "}}", p = t.indexOf(l, o + h);
1062
+ if (p === -1)
1063
+ throw d({
1064
+ code: "parse_error",
1065
+ path: r,
1066
+ details: { message: "unclosed expression" }
1067
+ });
1068
+ const f = t.slice(o + h, p).trim(), g = S(f, r), w = await k(g, {
1069
+ ...n,
1070
+ context: e,
1071
+ path: r,
1072
+ parentContext: n.parentContext ?? e
1073
+ });
1074
+ i += w == null ? "" : String(w), s = p + l.length;
1075
+ }
1076
+ return i;
1077
+ }
1078
+ function vt(t, e) {
1079
+ let n = 0, r = 0;
1080
+ for (; r < t.length; ) {
1081
+ const i = t.indexOf(e, r);
1082
+ if (i === -1)
1083
+ break;
1084
+ n++, r = i + e.length;
1085
+ }
1086
+ return n;
1087
+ }
1088
+ function ie(t) {
1089
+ const e = t.includes("@hg"), n = t.includes("@endhg"), r = vt(t, "@@");
1090
+ return e && n ? r > 0 ? "mixed" : "hg" : r >= 2 && !e && !n ? "at-at" : (e || n) && r > 0 ? "mixed" : e && !n || r === 1 && !n ? "unclosed" : "none";
1091
+ }
1092
+ function se(t) {
1093
+ return t.replace(/@endhg/g, "").replace(/@hg/g, "").replace(/@@/g, "");
1094
+ }
1095
+ function oe(t, e) {
1096
+ let n = 0, r = !1;
1097
+ for (; n < e; ) {
1098
+ const i = t.indexOf("```", n);
1099
+ if (i === -1 || i >= e)
1100
+ break;
1101
+ r = !r, n = i + 3;
1102
+ }
1103
+ return r;
1104
+ }
1105
+ function C(t) {
1106
+ const e = [];
1107
+ let n = 0;
1108
+ for (; n < t.length; ) {
1109
+ const r = t.indexOf("<!--", n);
1110
+ if (r === -1)
1111
+ break;
1112
+ if (oe(t, r)) {
1113
+ n = r + 4;
1114
+ continue;
1115
+ }
1116
+ const i = t.indexOf("-->", r + 4);
1117
+ if (i === -1)
1118
+ break;
1119
+ const s = t.slice(r, i + 3), o = s.slice(4, s.length - 3), a = ie(o);
1120
+ (a === "hg" || a === "at-at") && e.push({
1121
+ start: r,
1122
+ end: i + 3,
1123
+ inner: o,
1124
+ raw: s
1125
+ }), n = i + 3;
1126
+ }
1127
+ return e;
1128
+ }
1129
+ function ae(t) {
1130
+ let e = 0;
1131
+ for (; e < t.length; ) {
1132
+ const n = t.indexOf("<!--", e);
1133
+ if (n === -1)
1134
+ return !1;
1135
+ if (oe(t, n)) {
1136
+ e = n + 4;
1137
+ continue;
1138
+ }
1139
+ const r = t.indexOf("-->", n + 4);
1140
+ if (r === -1)
1141
+ return !1;
1142
+ const i = t.slice(n + 4, r), s = ie(i);
1143
+ if (s === "unclosed" || s === "mixed")
1144
+ return !0;
1145
+ e = r + 3;
1146
+ }
1147
+ return !1;
1148
+ }
1149
+ function ce(t) {
1150
+ let e = 0;
1151
+ for (; e < t.length; ) {
1152
+ const n = t.indexOf("<!--", e);
1153
+ if (n === -1)
1154
+ return null;
1155
+ if (oe(t, n)) {
1156
+ e = n + 4;
1157
+ continue;
1158
+ }
1159
+ const r = t.indexOf("-->", n + 4);
1160
+ if (r === -1)
1161
+ return null;
1162
+ const i = t.slice(n + 4, r), s = ie(i);
1163
+ if (s === "mixed")
1164
+ return "mixed @hg and @@ markers are not allowed";
1165
+ if (s === "unclosed")
1166
+ return "unclosed hyogen block (missing closing marker)";
1167
+ e = r + 3;
1168
+ }
1169
+ return null;
1170
+ }
1171
+ function W(t) {
1172
+ return se(t).trim().split(/\r?\n/).map((n) => n.trim()).filter((n) => n.length > 0);
1173
+ }
1174
+ const _t = /^(if\s+.+|else\s+if\s+.+|else|endif|each\s+[A-Za-z_$][A-Za-z0-9_$]*\s+in\s+.+|endeach)$/i;
1175
+ function he(t) {
1176
+ return _t.test(t.trim());
1177
+ }
1178
+ function G(t, e) {
1179
+ throw d({
1180
+ code: "parse_error",
1181
+ path: t,
1182
+ details: { message: e }
1183
+ });
1184
+ }
1185
+ function St(t, e) {
1186
+ let n = t;
1187
+ const r = /^<!--([\s\S]*?)-->$/.exec(t.trim());
1188
+ r && (n = r[1]);
1189
+ const i = W(n);
1190
+ if (i.length !== 1)
1191
+ return null;
1192
+ const s = i[0];
1193
+ if (/^include\s+/i.test(s) || /^component\s+/i.test(s) || /^const\s+/i.test(s) || /^let\s+/i.test(s) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*=/.test(s))
1194
+ return null;
1195
+ if (s === "else")
1196
+ return { kind: "else" };
1197
+ if (s === "endif")
1198
+ return { kind: "endif" };
1199
+ if (s === "endeach")
1200
+ return { kind: "endeach" };
1201
+ if (/^IF\b/.test(s) || /^ELSE\b/.test(s) || /^ENDIF\b/.test(s))
1202
+ throw G(e, "control keywords must be lowercase");
1203
+ const o = /^else\s+if\s+(.+)$/.exec(s);
1204
+ if (o)
1205
+ return {
1206
+ kind: "else_if",
1207
+ expr: S(o[1], e)
1208
+ };
1209
+ const a = /^if\s+(.+)$/.exec(s);
1210
+ if (a)
1211
+ return {
1212
+ kind: "if",
1213
+ expr: S(a[1], e)
1214
+ };
1215
+ const c = /^each\s+([A-Za-z_$][A-Za-z0-9_$]*)\s+in\s+(.+)$/.exec(s);
1216
+ if (c)
1217
+ return {
1218
+ kind: "each",
1219
+ item: c[1],
1220
+ expr: S(c[2], e)
1221
+ };
1222
+ if (s === "if")
1223
+ throw G(e, "if requires an expression");
1224
+ if (/^each\s+/.test(s))
1225
+ throw G(e, "invalid each directive");
1226
+ return null;
1227
+ }
1228
+ function M(t) {
1229
+ return { start: t.start, end: t.end, raw: t.raw };
1230
+ }
1231
+ function _(t, e) {
1232
+ throw d({
1233
+ code: "parse_error",
1234
+ path: t,
1235
+ details: { message: e }
1236
+ });
1237
+ }
1238
+ function Ct(t, e) {
1239
+ const n = [];
1240
+ for (const r of C(t)) {
1241
+ const i = St(r.inner, e);
1242
+ i && n.push({
1243
+ start: r.start,
1244
+ end: r.end,
1245
+ raw: r.raw,
1246
+ opener: i
1247
+ });
1248
+ }
1249
+ return n;
1250
+ }
1251
+ function Me(t) {
1252
+ return t.kind === "if" || t.kind === "each";
1253
+ }
1254
+ function Wt(t, e) {
1255
+ const n = Ct(t, e);
1256
+ if (n.length === 0)
1257
+ return t.length > 0 ? [{ kind: "text", content: t }] : [];
1258
+ const { nodes: r, nextIndex: i } = N(t, n, 0, n.length, e);
1259
+ if (i < n.length) {
1260
+ const s = n[i];
1261
+ if (s.opener.kind === "endif")
1262
+ throw _(e, "endif without matching if");
1263
+ if (s.opener.kind === "endeach")
1264
+ throw _(e, "endeach without matching each");
1265
+ if (s.opener.kind === "else" || s.opener.kind === "else_if")
1266
+ throw _(e, "else without matching if");
1267
+ }
1268
+ return r;
1269
+ }
1270
+ function N(t, e, n, r, i, s = 0, o) {
1271
+ const a = o ?? t.length, c = [];
1272
+ let h = s, l = n;
1273
+ for (; l < r; ) {
1274
+ const p = e[l];
1275
+ if (p.start >= a)
1276
+ break;
1277
+ if (p.end <= s) {
1278
+ l++;
1279
+ continue;
1280
+ }
1281
+ if (p.start > h && c.push({
1282
+ kind: "text",
1283
+ content: t.slice(h, p.start)
1284
+ }), p.opener.kind === "if") {
1285
+ const f = Et(t, e, l, r, i);
1286
+ c.push(f.node), h = f.endPos, l = f.nextIndex;
1287
+ continue;
1288
+ }
1289
+ if (p.opener.kind === "each") {
1290
+ const f = Tt(t, e, l, r, i);
1291
+ c.push(f.node), h = f.endPos, l = f.nextIndex;
1292
+ continue;
1293
+ }
1294
+ if (p.opener.kind === "else" || p.opener.kind === "else_if")
1295
+ throw _(i, "else without matching if");
1296
+ if (p.opener.kind === "endif")
1297
+ throw _(i, "endif without matching if");
1298
+ if (p.opener.kind === "endeach")
1299
+ throw _(i, "endeach without matching each");
1300
+ l++;
1301
+ }
1302
+ return h < a && c.push({ kind: "text", content: t.slice(h, a) }), { nodes: c, nextIndex: l };
1303
+ }
1304
+ function Et(t, e, n, r, i) {
1305
+ const s = e[n];
1306
+ if (s.opener.kind !== "if")
1307
+ throw _(i, "expected if");
1308
+ const o = [];
1309
+ let a = n, c = s.end, h = 0;
1310
+ for (; a < r; ) {
1311
+ const l = e[a];
1312
+ if (a === n) {
1313
+ if (l.opener.kind !== "if")
1314
+ throw _(i, "expected if");
1315
+ o.push({
1316
+ kind: "if",
1317
+ expr: l.opener.expr,
1318
+ opener: M(l),
1319
+ body: []
1320
+ }), a++;
1321
+ continue;
1322
+ }
1323
+ if (Me(l.opener)) {
1324
+ h++, a++;
1325
+ continue;
1326
+ }
1327
+ if (l.opener.kind === "endif") {
1328
+ if (h === 0)
1329
+ return o[o.length - 1].body = N(
1330
+ t,
1331
+ e,
1332
+ n + 1,
1333
+ a,
1334
+ i,
1335
+ c,
1336
+ l.start
1337
+ ).nodes, {
1338
+ node: { kind: "if", branches: o, closer: M(l) },
1339
+ nextIndex: a + 1,
1340
+ endPos: l.end
1341
+ };
1342
+ h--, a++;
1343
+ continue;
1344
+ }
1345
+ if (l.opener.kind === "endeach") {
1346
+ h--, a++;
1347
+ continue;
1348
+ }
1349
+ if (h === 0) {
1350
+ if (l.opener.kind === "else_if") {
1351
+ o[o.length - 1].body = N(
1352
+ t,
1353
+ e,
1354
+ n + 1,
1355
+ a,
1356
+ i,
1357
+ c,
1358
+ l.start
1359
+ ).nodes, o.push({
1360
+ kind: "else_if",
1361
+ expr: l.opener.expr,
1362
+ opener: M(l),
1363
+ body: []
1364
+ }), c = l.end, a++;
1365
+ continue;
1366
+ }
1367
+ if (l.opener.kind === "else") {
1368
+ o[o.length - 1].body = N(
1369
+ t,
1370
+ e,
1371
+ n + 1,
1372
+ a,
1373
+ i,
1374
+ c,
1375
+ l.start
1376
+ ).nodes, o.push({
1377
+ kind: "else",
1378
+ opener: M(l),
1379
+ body: []
1380
+ }), c = l.end, a++;
1381
+ continue;
1382
+ }
1383
+ }
1384
+ a++;
1385
+ }
1386
+ throw _(i, "unclosed if block (missing endif)");
1387
+ }
1388
+ function Tt(t, e, n, r, i) {
1389
+ const s = e[n];
1390
+ if (s.opener.kind !== "each")
1391
+ throw _(i, "expected each");
1392
+ let o = n + 1;
1393
+ const a = s.end;
1394
+ let c = 0;
1395
+ for (; o < r; ) {
1396
+ const h = e[o];
1397
+ if (Me(h.opener)) {
1398
+ c++, o++;
1399
+ continue;
1400
+ }
1401
+ if (h.opener.kind === "endeach") {
1402
+ if (c === 0) {
1403
+ const l = N(
1404
+ t,
1405
+ e,
1406
+ n + 1,
1407
+ o,
1408
+ i,
1409
+ a,
1410
+ h.start
1411
+ ).nodes;
1412
+ return {
1413
+ node: {
1414
+ kind: "each",
1415
+ item: s.opener.item,
1416
+ expr: s.opener.expr,
1417
+ opener: M(s),
1418
+ body: l,
1419
+ closer: M(h)
1420
+ },
1421
+ nextIndex: o + 1,
1422
+ endPos: h.end
1423
+ };
1424
+ }
1425
+ c--, o++;
1426
+ continue;
1427
+ }
1428
+ if (h.opener.kind === "endif") {
1429
+ c--, o++;
1430
+ continue;
1431
+ }
1432
+ o++;
1433
+ }
1434
+ throw _(i, "unclosed each block (missing endeach)");
1435
+ }
1436
+ const ye = 20;
1437
+ class $t {
1438
+ depth = 0;
1439
+ get currentDepth() {
1440
+ return this.depth;
1441
+ }
1442
+ enter() {
1443
+ return this.depth >= ye ? { exceeded: !0, limit: ye } : (this.depth++, { exceeded: !1, depth: this.depth });
1444
+ }
1445
+ exit() {
1446
+ this.depth > 0 && this.depth--;
1447
+ }
1448
+ }
1449
+ function At(t) {
1450
+ return !!t;
1451
+ }
1452
+ function Rt(t) {
1453
+ return t != null && typeof t[Symbol.iterator] == "function";
1454
+ }
1455
+ function Oe(t) {
1456
+ return {
1457
+ code: "nest_limit_exceeded",
1458
+ message: "structure nest limit exceeded",
1459
+ path: t,
1460
+ details: { limit: 20 }
1461
+ };
1462
+ }
1463
+ function le(t) {
1464
+ return t.startsWith(`
1465
+ `) ? t.slice(1) : t;
1466
+ }
1467
+ async function Mt(t, e) {
1468
+ const n = e.path, r = e.warnings ?? [], i = Wt(t, n), s = new $t();
1469
+ return de(i, e, s, r);
1470
+ }
1471
+ async function de(t, e, n, r) {
1472
+ const i = e.preserveHgComments === !0;
1473
+ let s = "", o = !1;
1474
+ for (const a of t) {
1475
+ let c = await Ot(a, e, n, r);
1476
+ o && (c = le(c)), s += c, o = !i && (a.kind === "if" || a.kind === "each");
1477
+ }
1478
+ return s;
1479
+ }
1480
+ async function Ot(t, e, n, r) {
1481
+ switch (t.kind) {
1482
+ case "text":
1483
+ return t.content;
1484
+ case "if":
1485
+ return Lt(t, e, n, r);
1486
+ case "each":
1487
+ return Dt(t, e, n, r);
1488
+ default:
1489
+ return "";
1490
+ }
1491
+ }
1492
+ async function Lt(t, e, n, r) {
1493
+ if (n.enter().exceeded)
1494
+ return r.push(Oe(e.path)), "";
1495
+ try {
1496
+ let s = -1;
1497
+ for (let c = 0; c < t.branches.length; c++) {
1498
+ const h = t.branches[c];
1499
+ if (h.kind === "else") {
1500
+ s = c;
1501
+ break;
1502
+ }
1503
+ const l = await k(h.expr, e);
1504
+ if (At(l)) {
1505
+ s = c;
1506
+ break;
1507
+ }
1508
+ }
1509
+ const o = e.preserveHgComments === !0;
1510
+ let a = "";
1511
+ for (let c = 0; c < t.branches.length; c++) {
1512
+ const h = t.branches[c];
1513
+ if (o && (a += h.opener.raw), c === s) {
1514
+ let l = await de(h.body, e, n, r);
1515
+ o || (l = le(l)), a += l;
1516
+ }
1517
+ }
1518
+ return o && (a += t.closer.raw), a;
1519
+ } finally {
1520
+ n.exit();
1521
+ }
1522
+ }
1523
+ async function Dt(t, e, n, r) {
1524
+ if (n.enter().exceeded)
1525
+ return r.push(Oe(e.path)), "";
1526
+ try {
1527
+ const s = await k(t.expr, e);
1528
+ if (!Rt(s))
1529
+ return "";
1530
+ const o = e.preserveHgComments === !0;
1531
+ let a = "";
1532
+ for (const c of s) {
1533
+ const h = { ...e.context, [t.item]: c };
1534
+ o && (a += t.opener.raw);
1535
+ let l = await de(t.body, {
1536
+ ...e,
1537
+ context: h
1538
+ }, n, r);
1539
+ o || (l = le(l));
1540
+ const p = await Re(l, h, {
1541
+ path: e.path,
1542
+ registry: e.registry,
1543
+ loader: e.loader,
1544
+ rootDir: e.rootDir,
1545
+ warnings: r,
1546
+ visitStack: e.visitStack,
1547
+ parentContext: e.parentContext ?? e.context,
1548
+ preserveHgComments: e.preserveHgComments,
1549
+ constrainToRoot: e.constrainToRoot
1550
+ });
1551
+ a += p, o && (a += t.closer.raw);
1552
+ }
1553
+ return a;
1554
+ } finally {
1555
+ n.exit();
1556
+ }
1557
+ }
1558
+ function J(t, e, n, r, i = !1, s = !1) {
1559
+ return j(e) ? e : re(e, {
1560
+ rootDir: t,
1561
+ fromPath: r,
1562
+ documentPath: n,
1563
+ constrainToRoot: i,
1564
+ hyogenPath: s
1565
+ });
1566
+ }
1567
+ function Le(t) {
1568
+ let e = 0;
1569
+ for (let n = t.length - 1; n >= 0 && t[n] === `
1570
+ `; n--)
1571
+ e++;
1572
+ return e;
1573
+ }
1574
+ function De(t) {
1575
+ let e = 0;
1576
+ for (; e < t.length && t[e] === `
1577
+ `; )
1578
+ e++;
1579
+ return e;
1580
+ }
1581
+ function L(t, e) {
1582
+ const n = Le(t), r = De(e), i = Math.max(n, r);
1583
+ return t.slice(0, t.length - n) + `
1584
+ `.repeat(i) + e.slice(r);
1585
+ }
1586
+ function pe(t, e) {
1587
+ const n = Le(t), r = De(e);
1588
+ return n + r - Math.max(n, r);
1589
+ }
1590
+ function be(t, e, n) {
1591
+ const r = t.indexOf(e);
1592
+ if (r < 0)
1593
+ return t;
1594
+ const i = t.slice(0, r), s = t.slice(r + e.length);
1595
+ return L(L(i, n), s);
1596
+ }
1597
+ async function Nt(t) {
1598
+ let e = t.source;
1599
+ for (const n of t.directives) {
1600
+ const r = J(
1601
+ t.root,
1602
+ n.path,
1603
+ t.path,
1604
+ t.path,
1605
+ t.constrainToRoot,
1606
+ !0
1607
+ );
1608
+ if (t.visitStack) {
1609
+ const i = t.visitStack.check(r);
1610
+ if (i.circular) {
1611
+ t.warnings?.push({
1612
+ code: "circular_include",
1613
+ message: O("circular_include", {
1614
+ path: r,
1615
+ from: i.from,
1616
+ via: "include"
1617
+ }),
1618
+ path: t.path,
1619
+ details: {
1620
+ path: r,
1621
+ from: i.from,
1622
+ via: "include"
1623
+ }
1624
+ }), e = be(e, n.marker, "");
1625
+ continue;
1626
+ }
1627
+ t.visitStack.push(r);
1628
+ }
1629
+ try {
1630
+ const i = await t.loader(r), s = await on(i, {
1631
+ context: t.context,
1632
+ loader: t.loader,
1633
+ root: t.root,
1634
+ path: r,
1635
+ preserveFrontMatter: t.preserveFrontMatter,
1636
+ preserveHgComments: t.preserveHgComments,
1637
+ visitStack: t.visitStack,
1638
+ warnings: t.warnings,
1639
+ registry: t.registry
1640
+ }), o = t.preserveHgComments && n.raw ? `${n.raw}
1641
+ ${s}` : s;
1642
+ e = be(e, n.marker, o);
1643
+ } finally {
1644
+ t.visitStack?.pop();
1645
+ }
1646
+ }
1647
+ return e;
1648
+ }
1649
+ class Ne {
1650
+ stack = [];
1651
+ check(e) {
1652
+ return e.length === 0 ? { circular: !1 } : this.stack.indexOf(e) !== -1 ? {
1653
+ circular: !0,
1654
+ path: e,
1655
+ from: this.stack[this.stack.length - 1] ?? e
1656
+ } : { circular: !1 };
1657
+ }
1658
+ push(e) {
1659
+ this.stack.push(e);
1660
+ }
1661
+ pop() {
1662
+ this.stack.pop();
1663
+ }
1664
+ }
1665
+ async function Ht(t, e, n = {}) {
1666
+ const { path: r, constBindings: i = /* @__PURE__ */ new Set() } = n, s = await k(t.expr, { context: e, path: r });
1667
+ switch (t.kind) {
1668
+ case "const": {
1669
+ if (i.has(t.name))
1670
+ throw d({
1671
+ code: "parse_error",
1672
+ path: r,
1673
+ details: {
1674
+ message: `cannot reassign const binding: ${t.name}`
1675
+ }
1676
+ });
1677
+ e[t.name] = s, i.add(t.name);
1678
+ break;
1679
+ }
1680
+ case "let": {
1681
+ e[t.name] = s;
1682
+ break;
1683
+ }
1684
+ case "assign": {
1685
+ if (i.has(t.name))
1686
+ throw d({
1687
+ code: "parse_error",
1688
+ path: r,
1689
+ details: {
1690
+ message: `cannot reassign const binding: ${t.name}`
1691
+ }
1692
+ });
1693
+ if (!(t.name in e))
1694
+ throw d({
1695
+ code: "parse_error",
1696
+ path: r,
1697
+ details: {
1698
+ message: `assignment to undeclared variable: ${t.name}`
1699
+ }
1700
+ });
1701
+ e[t.name] = s;
1702
+ break;
1703
+ }
1704
+ }
1705
+ }
1706
+ function ve(t) {
1707
+ return !t;
1708
+ }
1709
+ async function D(t, e, n = {}) {
1710
+ const { path: r, constBindings: i = /* @__PURE__ */ new Set(), onUpdate: s } = n;
1711
+ switch (t.kind) {
1712
+ case "const":
1713
+ case "let":
1714
+ case "assign": {
1715
+ await Ht(t, e, { path: r, constBindings: i }), s?.(t.name);
1716
+ return;
1717
+ }
1718
+ case "update": {
1719
+ if (i.has(t.name))
1720
+ throw d({
1721
+ code: "parse_error",
1722
+ path: r,
1723
+ details: {
1724
+ message: `cannot reassign const binding: ${t.name}`
1725
+ }
1726
+ });
1727
+ if (!(t.name in e))
1728
+ throw d({
1729
+ code: "parse_error",
1730
+ path: r,
1731
+ details: {
1732
+ message: `assignment to undeclared variable: ${t.name}`
1733
+ }
1734
+ });
1735
+ const o = Number(e[t.name]), a = t.op === "++" ? o + 1 : o - 1;
1736
+ e[t.name] = a, s?.(t.name);
1737
+ return;
1738
+ }
1739
+ case "compound_assign": {
1740
+ if (i.has(t.name))
1741
+ throw d({
1742
+ code: "parse_error",
1743
+ path: r,
1744
+ details: {
1745
+ message: `cannot reassign const binding: ${t.name}`
1746
+ }
1747
+ });
1748
+ if (!(t.name in e))
1749
+ throw d({
1750
+ code: "parse_error",
1751
+ path: r,
1752
+ details: {
1753
+ message: `assignment to undeclared variable: ${t.name}`
1754
+ }
1755
+ });
1756
+ const o = await k(t.expr, { context: e, path: r }), a = Number(e[t.name]), c = Number(o);
1757
+ let h;
1758
+ switch (t.op) {
1759
+ case "+=":
1760
+ h = a + c;
1761
+ break;
1762
+ case "-=":
1763
+ h = a - c;
1764
+ break;
1765
+ case "*=":
1766
+ h = a * c;
1767
+ break;
1768
+ case "/=":
1769
+ h = a / c;
1770
+ break;
1771
+ }
1772
+ e[t.name] = h, s?.(t.name);
1773
+ return;
1774
+ }
1775
+ case "for": {
1776
+ for (t.init && await D(t.init, e, n); ; ) {
1777
+ const o = await k(t.cond, {
1778
+ context: e,
1779
+ path: r
1780
+ });
1781
+ if (ve(o))
1782
+ break;
1783
+ for (const a of t.body)
1784
+ await D(a, e, n);
1785
+ t.update && await D(t.update, e, n);
1786
+ }
1787
+ return;
1788
+ }
1789
+ case "do_while": {
1790
+ do {
1791
+ for (const a of t.body)
1792
+ await D(a, e, n);
1793
+ const o = await k(t.cond, {
1794
+ context: e,
1795
+ path: r
1796
+ });
1797
+ if (ve(o))
1798
+ break;
1799
+ } while (!0);
1800
+ return;
1801
+ }
1802
+ }
1803
+ }
1804
+ async function _e(t, e, n = {}) {
1805
+ for (const r of t)
1806
+ await D(r, e, n);
1807
+ }
1808
+ const jt = /* @__PURE__ */ new Set([
1809
+ "if",
1810
+ "else",
1811
+ "endif",
1812
+ "const",
1813
+ "let",
1814
+ "for",
1815
+ "do",
1816
+ "while",
1817
+ "each",
1818
+ "endeach",
1819
+ "block",
1820
+ "endblock",
1821
+ "extend",
1822
+ "include",
1823
+ "component",
1824
+ "as"
1825
+ ]);
1826
+ function He(t) {
1827
+ return jt.has(t);
1828
+ }
1829
+ function ue(t) {
1830
+ let e = "", n = 0, r = null;
1831
+ for (; n < t.length; ) {
1832
+ const i = t[n];
1833
+ if (r) {
1834
+ if (e += i, i === "\\" && n + 1 < t.length) {
1835
+ e += t[++n], n++;
1836
+ continue;
1837
+ }
1838
+ i === r && (r = null), n++;
1839
+ continue;
1840
+ }
1841
+ if (i === '"' || i === "'" || i === "`") {
1842
+ r = i, e += i, n++;
1843
+ continue;
1844
+ }
1845
+ if (t.startsWith("//", n)) {
1846
+ for (; n < t.length && t[n] !== `
1847
+ `; )
1848
+ n++;
1849
+ continue;
1850
+ }
1851
+ if (t.startsWith("/*", n)) {
1852
+ const s = t.indexOf("*/", n + 2);
1853
+ if (s === -1)
1854
+ break;
1855
+ n = s + 2;
1856
+ continue;
1857
+ }
1858
+ e += i, n++;
1859
+ }
1860
+ return e;
1861
+ }
1862
+ function x(t, e) {
1863
+ throw d({
1864
+ code: "parse_error",
1865
+ path: t,
1866
+ details: { message: e }
1867
+ });
1868
+ }
1869
+ function Se(t, e) {
1870
+ const n = ue(t).trim();
1871
+ if (n.length === 0)
1872
+ throw x(e, "empty statement block");
1873
+ const r = new fe(n, e), i = r.parseStatementList();
1874
+ if (r.skipWhitespace(), r.hasMore())
1875
+ throw x(
1876
+ e,
1877
+ `unexpected token at position ${r.position}`
1878
+ );
1879
+ if (i.length === 0)
1880
+ throw x(e, "empty statement block");
1881
+ return i;
1882
+ }
1883
+ function I(t) {
1884
+ const e = ue(t).trim();
1885
+ return e.length === 0 ? !1 : /^const\s+/.test(e) || /^let\s+/.test(e) || /^for\s*\(/.test(e) || /^do\b/.test(e) || /^(\+\+|--)/.test(e) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*(\+\+|--|[+\-*/]=|=)/.test(e);
1886
+ }
1887
+ class fe {
1888
+ constructor(e, n) {
1889
+ this.input = e, this.path = n;
1890
+ }
1891
+ input;
1892
+ path;
1893
+ index = 0;
1894
+ get position() {
1895
+ return this.index;
1896
+ }
1897
+ hasMore() {
1898
+ return this.skipWhitespace(), this.index < this.input.length;
1899
+ }
1900
+ skipWhitespace() {
1901
+ for (; this.index < this.input.length && /\s/.test(this.input[this.index]); )
1902
+ this.index++;
1903
+ }
1904
+ parseStatementList() {
1905
+ const e = [];
1906
+ for (; this.hasMore() && this.peek() !== "}"; )
1907
+ e.push(this.parseStatement()), this.skipOptionalSemicolon();
1908
+ return e;
1909
+ }
1910
+ parseStatement() {
1911
+ if (this.skipWhitespace(), this.matchWord("for"))
1912
+ return this.parseFor();
1913
+ if (this.matchWord("do"))
1914
+ return this.parseDoWhile();
1915
+ if (this.matchWord("while"))
1916
+ throw x(
1917
+ this.path,
1918
+ "bare while loops are not allowed (use do…while)"
1919
+ );
1920
+ return this.parseSimpleStatement();
1921
+ }
1922
+ parseSimpleStatement() {
1923
+ this.skipWhitespace();
1924
+ const e = this.readPrefixUpdate();
1925
+ if (e)
1926
+ return e;
1927
+ if (this.matchWord("const"))
1928
+ return this.parseBindingDeclaration("const");
1929
+ if (this.matchWord("let"))
1930
+ return this.parseBindingDeclaration("let");
1931
+ const n = this.readIdentifier();
1932
+ if (!n)
1933
+ throw x(this.path, "expected statement");
1934
+ if (this.assertAssignableName(n), this.skipWhitespace(), this.match("++") || this.match("--")) {
1935
+ const i = this.input.slice(this.index - 2, this.index);
1936
+ return { kind: "update", name: n, op: i, position: "postfix" };
1937
+ }
1938
+ const r = this.readCompoundOp();
1939
+ if (r) {
1940
+ const i = this.readExpressionSourceUntilTerminator();
1941
+ return {
1942
+ kind: "compound_assign",
1943
+ name: n,
1944
+ op: r,
1945
+ expr: S(i, this.path)
1946
+ };
1947
+ }
1948
+ if (this.match("=")) {
1949
+ if (this.peek() === "=")
1950
+ throw x(this.path, "unexpected '==' in assignment");
1951
+ const i = this.readExpressionSourceUntilTerminator();
1952
+ return {
1953
+ kind: "assign",
1954
+ name: n,
1955
+ expr: S(i, this.path)
1956
+ };
1957
+ }
1958
+ throw x(this.path, `invalid statement starting with: ${n}`);
1959
+ }
1960
+ readPrefixUpdate() {
1961
+ if (this.skipWhitespace(), this.match("++") || this.match("--")) {
1962
+ const e = this.input.slice(this.index - 2, this.index), n = this.readIdentifier();
1963
+ if (!n)
1964
+ throw x(this.path, `expected identifier after ${e}`);
1965
+ return this.assertAssignableName(n), { kind: "update", name: n, op: e, position: "prefix" };
1966
+ }
1967
+ return null;
1968
+ }
1969
+ parseBindingDeclaration(e) {
1970
+ const n = this.readIdentifier();
1971
+ if (!n)
1972
+ throw x(this.path, `expected identifier after ${e}`);
1973
+ if (this.assertAssignableName(n), this.skipWhitespace(), !this.match("="))
1974
+ throw x(this.path, `expected '=' in ${e} declaration`);
1975
+ const r = this.readExpressionSourceUntilTerminator();
1976
+ return {
1977
+ kind: e,
1978
+ name: n,
1979
+ expr: S(r, this.path)
1980
+ };
1981
+ }
1982
+ parseFor() {
1983
+ if (this.skipWhitespace(), !this.match("("))
1984
+ throw x(this.path, "expected '(' after for");
1985
+ const e = this.readBalanced(")"), n = Ft(e);
1986
+ if (n.length !== 3)
1987
+ throw x(
1988
+ this.path,
1989
+ "for…of / for…in are not allowed; use for (init; cond; update)"
1990
+ );
1991
+ const [r, i, s] = n;
1992
+ if (i.trim().length === 0)
1993
+ throw x(this.path, "for loop condition cannot be empty");
1994
+ if (/^\s*[A-Za-z_$][A-Za-z0-9_$]*\s+(of|in)\s+/.test(r))
1995
+ throw x(
1996
+ this.path,
1997
+ "for…of / for…in are not allowed; use for (init; cond; update)"
1998
+ );
1999
+ const o = r.trim().length === 0 ? null : this.parseClauseStatement(r.trim()), a = S(i.trim(), this.path), c = s.trim().length === 0 ? null : this.parseClauseStatement(s.trim());
2000
+ if (this.skipWhitespace(), !this.match("{"))
2001
+ throw x(this.path, "expected '{' after for (...)");
2002
+ const h = this.parseStatementList();
2003
+ if (this.skipWhitespace(), !this.match("}"))
2004
+ throw x(this.path, "expected '}' to close for body");
2005
+ return { kind: "for", init: o, cond: a, update: c, body: h };
2006
+ }
2007
+ parseDoWhile() {
2008
+ if (this.skipWhitespace(), !this.match("{"))
2009
+ throw x(this.path, "expected '{' after do");
2010
+ const e = this.parseStatementList();
2011
+ if (this.skipWhitespace(), !this.match("}"))
2012
+ throw x(this.path, "expected '}' to close do body");
2013
+ if (this.skipWhitespace(), !this.matchWord("while"))
2014
+ throw x(this.path, "expected 'while' after do body");
2015
+ if (this.skipWhitespace(), !this.match("("))
2016
+ throw x(this.path, "expected '(' after while");
2017
+ const n = this.readBalanced(")");
2018
+ if (n.trim().length === 0)
2019
+ throw x(this.path, "do…while condition cannot be empty");
2020
+ const r = S(n.trim(), this.path);
2021
+ return { kind: "do_while", body: e, cond: r };
2022
+ }
2023
+ parseClauseStatement(e) {
2024
+ const n = new fe(e, this.path), r = n.parseSimpleStatement();
2025
+ if (n.skipWhitespace(), n.hasMore())
2026
+ throw x(
2027
+ this.path,
2028
+ `unexpected token in for clause at position ${n.position}`
2029
+ );
2030
+ return r;
2031
+ }
2032
+ assertAssignableName(e) {
2033
+ if (He(e))
2034
+ throw x(
2035
+ this.path,
2036
+ `reserved word cannot be used as identifier: ${e}`
2037
+ );
2038
+ }
2039
+ readExpressionSourceUntilTerminator() {
2040
+ this.skipWhitespace();
2041
+ const e = this.index;
2042
+ let n = 0, r = 0, i = 0, s = null;
2043
+ for (; this.index < this.input.length; ) {
2044
+ const a = this.input[this.index];
2045
+ if (s) {
2046
+ if (a === "\\") {
2047
+ this.index += 2;
2048
+ continue;
2049
+ }
2050
+ a === s && (s = null), this.index++;
2051
+ continue;
2052
+ }
2053
+ if (a === '"' || a === "'" || a === "`") {
2054
+ s = a, this.index++;
2055
+ continue;
2056
+ }
2057
+ if (a === "(" && n++, a === ")" && (n = Math.max(0, n - 1)), a === "{" && r++, a === "}") {
2058
+ if (r === 0 && n === 0 && i === 0)
2059
+ break;
2060
+ r = Math.max(0, r - 1);
2061
+ }
2062
+ if (a === "[" && i++, a === "]" && (i = Math.max(0, i - 1)), (a === ";" || a === `
2063
+ `) && n === 0 && r === 0 && i === 0)
2064
+ break;
2065
+ this.index++;
2066
+ }
2067
+ const o = this.input.slice(e, this.index).trim();
2068
+ if (o.length === 0)
2069
+ throw x(this.path, "expected expression");
2070
+ return o;
2071
+ }
2072
+ readBalanced(e) {
2073
+ const n = e === ")" ? "(" : "{";
2074
+ let r = 1;
2075
+ const i = this.index;
2076
+ let s = null;
2077
+ for (; this.index < this.input.length; ) {
2078
+ const o = this.input[this.index];
2079
+ if (s) {
2080
+ if (o === "\\") {
2081
+ this.index += 2;
2082
+ continue;
2083
+ }
2084
+ o === s && (s = null), this.index++;
2085
+ continue;
2086
+ }
2087
+ if (o === '"' || o === "'" || o === "`") {
2088
+ s = o, this.index++;
2089
+ continue;
2090
+ }
2091
+ if (o === n) {
2092
+ r++, this.index++;
2093
+ continue;
2094
+ }
2095
+ if (o === e) {
2096
+ if (r--, r === 0) {
2097
+ const a = this.input.slice(i, this.index);
2098
+ return this.index++, a;
2099
+ }
2100
+ this.index++;
2101
+ continue;
2102
+ }
2103
+ this.index++;
2104
+ }
2105
+ throw x(this.path, `expected '${e}'`);
2106
+ }
2107
+ readCompoundOp() {
2108
+ this.skipWhitespace();
2109
+ const e = ["+=", "-=", "*=", "/="];
2110
+ for (const n of e)
2111
+ if (this.match(n))
2112
+ return n;
2113
+ return null;
2114
+ }
2115
+ skipOptionalSemicolon() {
2116
+ this.skipWhitespace(), this.peek() === ";" && this.index++;
2117
+ }
2118
+ match(e) {
2119
+ return this.skipWhitespace(), this.input.startsWith(e, this.index) ? (this.index += e.length, !0) : !1;
2120
+ }
2121
+ matchWord(e) {
2122
+ if (this.skipWhitespace(), !this.input.startsWith(e, this.index))
2123
+ return !1;
2124
+ const n = this.input[this.index + e.length];
2125
+ return n && /[A-Za-z0-9_$]/.test(n) ? !1 : (this.index += e.length, !0);
2126
+ }
2127
+ peek() {
2128
+ return this.input[this.index] ?? "";
2129
+ }
2130
+ readIdentifier() {
2131
+ this.skipWhitespace();
2132
+ const e = this.index, n = this.peek();
2133
+ if (!/[A-Za-z_$]/.test(n))
2134
+ return "";
2135
+ for (this.index++; this.index < this.input.length && /[A-Za-z0-9_$]/.test(this.input[this.index]); )
2136
+ this.index++;
2137
+ return this.input.slice(e, this.index);
2138
+ }
2139
+ }
2140
+ function Ft(t) {
2141
+ const e = [];
2142
+ let n = "", r = 0, i = null;
2143
+ for (let s = 0; s < t.length; s++) {
2144
+ const o = t[s];
2145
+ if (i) {
2146
+ if (n += o, o === "\\" && s + 1 < t.length) {
2147
+ n += t[++s];
2148
+ continue;
2149
+ }
2150
+ o === i && (i = null);
2151
+ continue;
2152
+ }
2153
+ if (o === '"' || o === "'" || o === "`") {
2154
+ i = o, n += o;
2155
+ continue;
2156
+ }
2157
+ if (o === "(" || o === "[" || o === "{") {
2158
+ r++, n += o;
2159
+ continue;
2160
+ }
2161
+ if (o === ")" || o === "]" || o === "}") {
2162
+ r = Math.max(0, r - 1), n += o;
2163
+ continue;
2164
+ }
2165
+ if (o === ";" && r === 0) {
2166
+ e.push(n), n = "";
2167
+ continue;
2168
+ }
2169
+ n += o;
2170
+ }
2171
+ return e.push(n), e;
2172
+ }
2173
+ function H(t, e) {
2174
+ const n = t.trim();
2175
+ if (!/^extend\b/i.test(n)) return null;
2176
+ if (!/^extend\s+/i.test(n))
2177
+ throw d({
2178
+ code: "parse_error",
2179
+ path: e,
2180
+ details: { message: "missing extend path" }
2181
+ });
2182
+ const r = /^extend\s+(\S+)\s*$/.exec(n);
2183
+ if (!r)
2184
+ throw d({
2185
+ code: "parse_error",
2186
+ path: e,
2187
+ details: { message: "invalid extend directive" }
2188
+ });
2189
+ const i = r[1];
2190
+ if (i.length === 0)
2191
+ throw d({
2192
+ code: "parse_error",
2193
+ path: e,
2194
+ details: { message: "invalid extend path" }
2195
+ });
2196
+ return { path: i };
2197
+ }
2198
+ function Bt(t, e) {
2199
+ const n = W(t);
2200
+ if (n.length === 0) return null;
2201
+ const r = n[0], i = H(r, e);
2202
+ if (!i) return null;
2203
+ for (const s of n.slice(1))
2204
+ if (/^extend\s+/i.test(s))
2205
+ throw d({
2206
+ code: "parse_error",
2207
+ path: e,
2208
+ details: { message: "extend must be the first line of extend block" }
2209
+ });
2210
+ return {
2211
+ path: i.path,
2212
+ declarationsSource: n.slice(1).join(`
2213
+ `)
2214
+ };
2215
+ }
2216
+ async function It(t, e = {}) {
2217
+ const n = e.path, r = e.context ?? {};
2218
+ if (ae(t))
2219
+ throw d({
2220
+ code: "parse_error",
2221
+ path: n,
2222
+ details: {
2223
+ message: ce(t) ?? "unclosed hyogen block (missing closing marker)"
2224
+ }
2225
+ });
2226
+ const i = C(t);
2227
+ if (i.length === 0)
2228
+ return { source: t, context: r, declarationUpdates: {} };
2229
+ const s = /* @__PURE__ */ new Set(), o = {}, a = (l) => {
2230
+ o[l] = r[l];
2231
+ };
2232
+ let c = t, h = 0;
2233
+ for (const l of i) {
2234
+ const p = W(l.inner);
2235
+ if (p.length === 1 && he(p[0]) || p.length === 1 && /^include\s+/i.test(p[0]) || p.length === 1 && /^component\s+/i.test(p[0]))
2236
+ continue;
2237
+ const f = Bt(l.inner, n);
2238
+ if (f) {
2239
+ if (f.declarationsSource.trim().length > 0) {
2240
+ const Z = Se(
2241
+ f.declarationsSource,
2242
+ n
2243
+ );
2244
+ await _e(Z, r, {
2245
+ path: n,
2246
+ constBindings: s,
2247
+ onUpdate: a
2248
+ });
2249
+ }
2250
+ const v = l.start - h, E = l.end - h, T = `<!--@hg
2251
+ extend ${f.path}
2252
+ @endhg-->`;
2253
+ c = c.slice(0, v) + T + c.slice(E), h += l.raw.length - T.length;
2254
+ continue;
2255
+ }
2256
+ const g = p.join(`
2257
+ `);
2258
+ if (!I(g)) {
2259
+ if (p.length === 1)
2260
+ continue;
2261
+ throw d({
2262
+ code: "parse_error",
2263
+ path: n,
2264
+ details: { message: `unsupported hyogen directive: ${p[0]}` }
2265
+ });
2266
+ }
2267
+ const w = Se(g, n);
2268
+ await _e(w, r, {
2269
+ path: n,
2270
+ constBindings: s,
2271
+ onUpdate: a
2272
+ });
2273
+ const y = l.start - h, A = l.end - h, F = c.slice(0, y), $ = c.slice(A);
2274
+ c = L(F, $), h += l.raw.length + pe(F, $);
2275
+ }
2276
+ return { source: c, context: r, declarationUpdates: o };
2277
+ }
2278
+ const zt = /^component\s+(\S+)\s+as\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*$/;
2279
+ function je(t, e) {
2280
+ const n = se(t).trim();
2281
+ if (n.length === 0)
2282
+ throw d({
2283
+ code: "parse_error",
2284
+ path: e,
2285
+ details: { message: "empty hyogen block" }
2286
+ });
2287
+ const r = n.split(/\r?\n/).map((a) => a.trim()).filter((a) => a.length > 0);
2288
+ if (r.length !== 1)
2289
+ throw d({
2290
+ code: "parse_error",
2291
+ path: e,
2292
+ details: {
2293
+ message: "hyogen block must contain a single component directive"
2294
+ }
2295
+ });
2296
+ const i = r[0];
2297
+ if (/^include\s+/i.test(i))
2298
+ throw d({
2299
+ code: "parse_error",
2300
+ path: e,
2301
+ details: { message: "include and component cannot coexist in one block" }
2302
+ });
2303
+ const s = zt.exec(i);
2304
+ if (!s)
2305
+ throw d({
2306
+ code: "parse_error",
2307
+ path: e,
2308
+ details: { message: `unsupported component directive: ${i}` }
2309
+ });
2310
+ const o = s[1];
2311
+ if (o.length === 0)
2312
+ throw d({
2313
+ code: "parse_error",
2314
+ path: e,
2315
+ details: { message: "empty component path" }
2316
+ });
2317
+ return {
2318
+ kind: "component",
2319
+ path: o,
2320
+ alias: s[2]
2321
+ };
2322
+ }
2323
+ function Fe(t, e) {
2324
+ const n = se(t).trim();
2325
+ if (n.length === 0)
2326
+ throw d({
2327
+ code: "parse_error",
2328
+ path: e,
2329
+ details: { message: "empty hyogen block" }
2330
+ });
2331
+ const r = n.split(/\r?\n/).map((o) => o.trim()).filter((o) => o.length > 0);
2332
+ if (r.length !== 1)
2333
+ throw d({
2334
+ code: "parse_error",
2335
+ path: e,
2336
+ details: { message: "hyogen block must contain a single include directive" }
2337
+ });
2338
+ const i = r[0], s = /^include\s+(\S+)\s*$/.exec(i);
2339
+ if (s)
2340
+ return { kind: "include", path: s[1] };
2341
+ throw d({
2342
+ code: "parse_error",
2343
+ path: e,
2344
+ details: { message: `unsupported hyogen directive: ${i}` }
2345
+ });
2346
+ }
2347
+ function Q(t) {
2348
+ const e = ue(t).trim();
2349
+ return e.length === 0 ? !1 : /^const\s+/.test(e) || /^let\s+/.test(e) || /^[A-Za-z_$][A-Za-z0-9_$]*\s*=/.test(e);
2350
+ }
2351
+ const Ut = "\0HYOGEN_INCLUDE_";
2352
+ function Zt(t) {
2353
+ return `${Ut}${t}\0`;
2354
+ }
2355
+ function qt(t, e) {
2356
+ const n = W(t);
2357
+ if (n.length === 1 && he(n[0]))
2358
+ return { kind: "control" };
2359
+ if (n.length === 1 && (Q(n[0]) || I(n[0])))
2360
+ return null;
2361
+ if (n.length !== 1)
2362
+ throw d({
2363
+ code: "parse_error",
2364
+ path: e,
2365
+ details: { message: "hyogen block must contain a single directive" }
2366
+ });
2367
+ const r = n[0];
2368
+ if (/^include\s+/i.test(r) && /\bcomponent\s+/i.test(r))
2369
+ throw d({
2370
+ code: "parse_error",
2371
+ path: e,
2372
+ details: { message: "include and component cannot coexist in one block" }
2373
+ });
2374
+ if (/^include\s+/i.test(r))
2375
+ return Fe(t, e);
2376
+ if (/^component\s+/i.test(r))
2377
+ return je(t, e);
2378
+ if (r === "endblock" || /^block\s+/.test(r) || /^extend\s+/.test(r))
2379
+ return null;
2380
+ throw d({
2381
+ code: "parse_error",
2382
+ path: e,
2383
+ details: { message: `unsupported hyogen directive: ${r}` }
2384
+ });
2385
+ }
2386
+ function Pt(t, e = {}) {
2387
+ const n = e.path;
2388
+ if (ae(t))
2389
+ throw d({
2390
+ code: "parse_error",
2391
+ path: n,
2392
+ details: {
2393
+ message: ce(t) ?? "unclosed hyogen block (missing closing marker)"
2394
+ }
2395
+ });
2396
+ const r = C(t);
2397
+ if (r.length === 0)
2398
+ return { source: t, directives: [] };
2399
+ const i = [];
2400
+ let s = t, o = 0, a = 0;
2401
+ for (const c of r) {
2402
+ const h = qt(c.inner, n);
2403
+ if (!h || h.kind === "control")
2404
+ continue;
2405
+ const l = c.start - o, p = c.end - o;
2406
+ if (h.kind === "component") {
2407
+ e.registry && e.registry.register(
2408
+ {
2409
+ alias: h.alias,
2410
+ componentPath: h.path,
2411
+ definedAt: n
2412
+ },
2413
+ Object.keys(e.context ?? {}),
2414
+ n
2415
+ );
2416
+ const g = s.slice(0, l), w = s.slice(p);
2417
+ s = L(g, w), o += c.raw.length + pe(g, w);
2418
+ continue;
2419
+ }
2420
+ const f = Zt(a++);
2421
+ i.push({ ...h, marker: f, raw: c.raw }), s = s.slice(0, l) + f + s.slice(p), o += c.raw.length - f.length;
2422
+ }
2423
+ return { source: s, directives: i };
2424
+ }
2425
+ function Vt(t, e) {
2426
+ return !e.preserveFrontMatter || !e.rawFrontMatter ? t : t.length === 0 ? `${e.rawFrontMatter}
2427
+ ` : `${e.rawFrontMatter}
2428
+ ${t}`;
2429
+ }
2430
+ function Kt(t, e = !1) {
2431
+ if (e)
2432
+ return t;
2433
+ const n = C(t);
2434
+ if (n.length === 0)
2435
+ return t;
2436
+ let r = t, i = 0;
2437
+ for (const s of n) {
2438
+ const o = s.start - i, a = s.end - i, c = r.slice(0, o), h = r.slice(a);
2439
+ r = L(c, h), i += s.raw.length + pe(c, h);
2440
+ }
2441
+ return r;
2442
+ }
2443
+ const Yt = /^block\s+([A-Za-z_$][A-Za-z0-9_$]*)$/;
2444
+ function Gt(t, e) {
2445
+ const n = t.trim();
2446
+ if (n === "endblock")
2447
+ return { kind: "endblock" };
2448
+ const r = Yt.exec(n);
2449
+ if (!r)
2450
+ throw d({
2451
+ code: "parse_error",
2452
+ path: e,
2453
+ details: { message: "invalid block directive" }
2454
+ });
2455
+ const i = r[1];
2456
+ if (He(i))
2457
+ throw d({
2458
+ code: "parse_error",
2459
+ path: e,
2460
+ details: { message: `reserved word cannot be used as block name: ${i}` }
2461
+ });
2462
+ return { kind: "block", name: i };
2463
+ }
2464
+ function Ce(t, e) {
2465
+ const { path: n, mode: r, hasExtend: i = !1 } = e, s = C(t);
2466
+ if (s.length === 0) return [];
2467
+ const o = [], a = [], c = /* @__PURE__ */ new Set();
2468
+ for (const h of s) {
2469
+ const l = W(h.inner);
2470
+ if (l.length !== 1) continue;
2471
+ const p = l[0];
2472
+ if (!(p === "endblock" || p.startsWith("block "))) continue;
2473
+ if (r === "child" && !i)
2474
+ throw d({
2475
+ code: "parse_error",
2476
+ path: n,
2477
+ details: { message: "orphan block without extend" }
2478
+ });
2479
+ const g = Gt(p, n);
2480
+ if (g.kind === "endblock") {
2481
+ const w = a.pop();
2482
+ if (!w)
2483
+ throw d({
2484
+ code: "parse_error",
2485
+ path: n,
2486
+ details: { message: "endblock without matching block opener" }
2487
+ });
2488
+ const y = t.slice(w.openerEnd, h.start);
2489
+ o.push({
2490
+ name: w.name,
2491
+ body: y,
2492
+ start: w.start,
2493
+ end: h.end
2494
+ });
2495
+ continue;
2496
+ }
2497
+ if (a.length > 0)
2498
+ throw d({
2499
+ code: "parse_error",
2500
+ path: n,
2501
+ details: { message: "nested block structures are not supported" }
2502
+ });
2503
+ if (c.has(g.name))
2504
+ throw d({
2505
+ code: "parse_error",
2506
+ path: n,
2507
+ details: { message: `duplicate block: ${g.name}` }
2508
+ });
2509
+ c.add(g.name), a.push({
2510
+ name: g.name,
2511
+ openerEnd: h.end,
2512
+ start: h.start
2513
+ });
2514
+ }
2515
+ if (a.length > 0)
2516
+ throw d({
2517
+ code: "parse_error",
2518
+ path: n,
2519
+ details: { message: "missing endblock" }
2520
+ });
2521
+ return o;
2522
+ }
2523
+ function We(t) {
2524
+ const e = C(t), n = [];
2525
+ for (const r of e) {
2526
+ const i = W(r.inner);
2527
+ if (i.length === 0) continue;
2528
+ const s = H(i[0]);
2529
+ s && n.push({ path: s.path, start: r.start });
2530
+ }
2531
+ return n;
2532
+ }
2533
+ function Xt(t) {
2534
+ const e = C(t);
2535
+ for (const n of e) {
2536
+ const r = W(n.inner);
2537
+ if (r.length !== 1) continue;
2538
+ const i = r[0];
2539
+ if (i === "endblock" || i.startsWith("block ")) return !0;
2540
+ }
2541
+ return !1;
2542
+ }
2543
+ function X(t) {
2544
+ return t.map((e) => e.body).join("");
2545
+ }
2546
+ function Jt(t, e, n) {
2547
+ const r = [...e].sort((o, a) => o.start - a.start), i = [];
2548
+ let s = 0;
2549
+ for (const o of r)
2550
+ i.push(t.slice(s, o.start)), i.push(n.get(o.name) ?? o.body), s = o.end;
2551
+ return i.push(t.slice(s)), i.reduce((o, a) => L(o, a));
2552
+ }
2553
+ function Qt(t) {
2554
+ if (t instanceof Error && "code" in t && "details" in t) {
2555
+ const e = t;
2556
+ if (e.code === "file_not_found" && e.details && e.details.via === "include")
2557
+ return e.details.via = "extend", { errorToThrow: e, adjusted: !0 };
2558
+ }
2559
+ return { errorToThrow: t, adjusted: !1 };
2560
+ }
2561
+ async function en(t, e) {
2562
+ const {
2563
+ path: n,
2564
+ context: r,
2565
+ declarationUpdates: i,
2566
+ loader: s,
2567
+ root: o,
2568
+ constrainToRoot: a,
2569
+ visitStack: c,
2570
+ warnings: h,
2571
+ inComponent: l = !1
2572
+ } = e, p = We(t);
2573
+ if (p.length === 0) {
2574
+ if (Xt(t))
2575
+ throw d({
2576
+ code: "parse_error",
2577
+ path: n,
2578
+ details: { message: "orphan block without extend" }
2579
+ });
2580
+ return { source: t, context: b(r, i) };
2581
+ }
2582
+ const g = C(t)[0];
2583
+ if (!g)
2584
+ return { source: t, context: b(r, i) };
2585
+ if (!s)
2586
+ throw new Error("loader is required when processing extend directives");
2587
+ const w = W(g.inner);
2588
+ if (!(w.length > 0 ? H(w[0]) : null))
2589
+ throw d({
2590
+ code: "parse_error",
2591
+ path: n,
2592
+ details: { message: "extend must be the first hyogen block" }
2593
+ });
2594
+ if (p.length > 1)
2595
+ throw d({
2596
+ code: "parse_error",
2597
+ path: n,
2598
+ details: { message: "multiple extend directives are not supported" }
2599
+ });
2600
+ const A = Ce(t, {
2601
+ path: n,
2602
+ mode: "child",
2603
+ hasExtend: !0
2604
+ });
2605
+ if (l)
2606
+ return h?.push({
2607
+ code: "extend_in_component",
2608
+ message: O("extend_in_component", { path: n }),
2609
+ path: n,
2610
+ details: { path: n }
2611
+ }), {
2612
+ source: X(A),
2613
+ context: b(r, i)
2614
+ };
2615
+ const F = p[0].path, $ = n, v = J(
2616
+ o,
2617
+ F,
2618
+ n,
2619
+ n,
2620
+ a,
2621
+ !0
2622
+ );
2623
+ $ && c.push($);
2624
+ try {
2625
+ const E = $ ? c.check(v) : { circular: !1 };
2626
+ if (E.circular)
2627
+ return h?.push({
2628
+ code: "circular_include",
2629
+ message: O("circular_include", {
2630
+ path: v,
2631
+ from: E.from,
2632
+ via: "extend"
2633
+ }),
2634
+ path: n,
2635
+ details: { path: v, from: E.from, via: "extend" }
2636
+ }), {
2637
+ source: X(A),
2638
+ context: b(r, i)
2639
+ };
2640
+ c.push(v);
2641
+ try {
2642
+ const T = await s(v);
2643
+ if (T === void 0)
2644
+ throw new Error("loader returned undefined");
2645
+ const { context: Z, body: q } = U(
2646
+ T,
2647
+ v
2648
+ ), ge = We(q);
2649
+ if (ge.length > 0) {
2650
+ const B = ge[0].path, P = J(
2651
+ o,
2652
+ B,
2653
+ v,
2654
+ v,
2655
+ a,
2656
+ !0
2657
+ ), V = c.check(P);
2658
+ if (V.circular)
2659
+ return h?.push({
2660
+ code: "circular_include",
2661
+ message: O("circular_include", {
2662
+ path: P,
2663
+ from: V.from,
2664
+ via: "extend"
2665
+ }),
2666
+ path: n,
2667
+ details: { path: P, from: V.from, via: "extend" }
2668
+ }), {
2669
+ source: X(A),
2670
+ context: b(r, i)
2671
+ };
2672
+ throw d({
2673
+ code: "parse_error",
2674
+ path: v,
2675
+ details: { message: "layout extend is not supported" }
2676
+ });
2677
+ }
2678
+ const Ie = Ce(q, {
2679
+ path: v,
2680
+ mode: "layout"
2681
+ }), ze = new Map(
2682
+ A.map((B) => [B.name, B.body])
2683
+ ), Ue = Jt(
2684
+ q,
2685
+ Ie,
2686
+ ze
2687
+ ), Ze = b(
2688
+ r,
2689
+ Z,
2690
+ i
2691
+ );
2692
+ return { source: Ue, context: Ze };
2693
+ } finally {
2694
+ c.pop();
2695
+ }
2696
+ } catch (E) {
2697
+ const T = Qt(E);
2698
+ throw T.adjusted ? T.errorToThrow : E;
2699
+ } finally {
2700
+ $ && c.pop();
2701
+ }
2702
+ }
2703
+ const tn = ne.warningReasons, nn = [
2704
+ {
2705
+ reason: "contains_html_script_tag",
2706
+ test: (t) => /<\/?script\b/i.test(t)
2707
+ },
2708
+ {
2709
+ reason: "contains_event_handler",
2710
+ test: (t) => /\bon(?:error|click|load)\s*=/i.test(t)
2711
+ },
2712
+ {
2713
+ reason: "contains_dangerous_scheme",
2714
+ test: (t) => /(?:javascript|vbscript)\s*:/i.test(t)
2715
+ },
2716
+ {
2717
+ reason: "contains_embed_tag",
2718
+ test: (t) => /<(?:iframe|object|embed)\b/i.test(t)
2719
+ },
2720
+ {
2721
+ reason: "contains_meta_refresh",
2722
+ test: (t) => /<meta\b[^>]*\bhttp-equiv\b/i.test(t)
2723
+ }
2724
+ ];
2725
+ function rn(t) {
2726
+ return tn[t] ?? t;
2727
+ }
2728
+ function ee(t, e, n, r) {
2729
+ if (typeof t == "string") {
2730
+ for (const i of nn)
2731
+ i.test(t) && n.push({
2732
+ code: "suspicious_context_value",
2733
+ message: O("suspicious_context_value", {
2734
+ key: e,
2735
+ reason: rn(i.reason)
2736
+ }),
2737
+ path: r,
2738
+ details: { key: e, reason: i.reason }
2739
+ });
2740
+ return;
2741
+ }
2742
+ if (t != null) {
2743
+ if (Array.isArray(t)) {
2744
+ for (let i = 0; i < t.length; i++)
2745
+ ee(t[i], `${e}[${i}]`, n, r);
2746
+ return;
2747
+ }
2748
+ if (typeof t == "object")
2749
+ for (const [i, s] of Object.entries(
2750
+ t
2751
+ )) {
2752
+ const o = e.length > 0 ? `${e}.${i}` : i;
2753
+ ee(s, o, n, r);
2754
+ }
2755
+ }
2756
+ }
2757
+ function sn(t, e, n) {
2758
+ for (const [r, i] of Object.entries(t))
2759
+ ee(i, r, e, n);
2760
+ }
2761
+ async function me(t, e) {
2762
+ const n = e.path, r = e.context, i = e.registry ?? new Ae(), s = e.warnings ?? [], o = e.visitStack ?? new Ne(), {
2763
+ source: a,
2764
+ declarationUpdates: c
2765
+ } = await It(t, { path: n, context: { ...r } });
2766
+ sn(
2767
+ b(r, c ?? {}),
2768
+ s,
2769
+ n
2770
+ );
2771
+ const h = await en(a, {
2772
+ path: n,
2773
+ context: r,
2774
+ declarationUpdates: c ?? {},
2775
+ loader: e.loader,
2776
+ root: e.root,
2777
+ constrainToRoot: e.constrainToRoot,
2778
+ visitStack: o,
2779
+ warnings: s,
2780
+ inComponent: e.inComponent ?? !1
2781
+ }), { source: l, context: p } = h, { source: f, directives: g } = Pt(l, {
2782
+ path: n,
2783
+ registry: i,
2784
+ context: p
2785
+ }), w = e.loader;
2786
+ if (g.length > 0 && !w)
2787
+ throw new Error("loader is required when processing include directives");
2788
+ let y = f;
2789
+ return g.length > 0 && w && (y = await Nt({
2790
+ source: f,
2791
+ directives: g,
2792
+ context: p,
2793
+ loader: w,
2794
+ root: e.root,
2795
+ path: n,
2796
+ preserveFrontMatter: e.preserveFrontMatter,
2797
+ preserveHgComments: e.preserveHgComments,
2798
+ visitStack: o,
2799
+ warnings: s,
2800
+ registry: i,
2801
+ constrainToRoot: e.constrainToRoot
2802
+ })), y = await Mt(y, {
2803
+ context: p,
2804
+ path: n,
2805
+ registry: i,
2806
+ loader: w,
2807
+ rootDir: e.root,
2808
+ warnings: s,
2809
+ visitStack: o,
2810
+ parentContext: p,
2811
+ preserveHgComments: e.preserveHgComments,
2812
+ constrainToRoot: e.constrainToRoot
2813
+ }), y = await Re(y, p, {
2814
+ path: n,
2815
+ registry: i,
2816
+ loader: w,
2817
+ rootDir: e.root,
2818
+ warnings: s,
2819
+ visitStack: o,
2820
+ parentContext: p,
2821
+ preserveHgComments: e.preserveHgComments,
2822
+ constrainToRoot: e.constrainToRoot
2823
+ }), y = Kt(y, e.preserveHgComments), y;
2824
+ }
2825
+ async function Be(t, e = {}) {
2826
+ const n = e.path, r = b(e.context), i = e.registry ?? new Ae(), s = e.warnings ?? [], o = e.visitStack ?? new Ne(), { context: a, body: c, rawFrontMatter: h } = U(
2827
+ t,
2828
+ n
2829
+ ), l = b(r, a);
2830
+ let p = await me(c, {
2831
+ ...e,
2832
+ context: l,
2833
+ registry: i,
2834
+ warnings: s,
2835
+ visitStack: o
2836
+ });
2837
+ return p = Vt(p, {
2838
+ preserveFrontMatter: e.preserveFrontMatter,
2839
+ rawFrontMatter: h
2840
+ }), {
2841
+ markdown: p,
2842
+ warnings: s
2843
+ };
2844
+ }
2845
+ async function on(t, e) {
2846
+ const n = e.path, { context: r, body: i } = U(t, n), s = b(e.context, r);
2847
+ return me(i, {
2848
+ ...e,
2849
+ context: s,
2850
+ preserveFrontMatter: !1
2851
+ });
2852
+ }
2853
+ async function an(t, e, n) {
2854
+ const r = b(e, n?.serverContext), i = n?.loader ?? $e(), s = await at(t, { root: n?.root });
2855
+ return Be(s.source, {
2856
+ context: r,
2857
+ loader: i,
2858
+ root: s.rootDir ?? n?.root,
2859
+ path: s.entryPath ?? n?.path,
2860
+ constrainToRoot: s.constrainToRoot,
2861
+ preserveFrontMatter: n?.preserveFrontMatter,
2862
+ preserveHgComments: n?.preserveHgComments
2863
+ });
2864
+ }
2865
+ async function _n(t, e, n) {
2866
+ if (n != null && "serverContext" in n && n.serverContext != null)
2867
+ throw d({
2868
+ code: "server_context_on_client"
2869
+ });
2870
+ const r = n?.loader;
2871
+ if (!r)
2872
+ throw d({
2873
+ code: "parse_error",
2874
+ details: { message: "loader is required for renderClient" }
2875
+ });
2876
+ let i, s;
2877
+ typeof t == "string" ? i = t : (s = t.path, i = await r(t.path));
2878
+ const o = b(e);
2879
+ return Be(i, {
2880
+ context: o,
2881
+ loader: r,
2882
+ root: n?.root,
2883
+ path: s ?? n?.path,
2884
+ preserveFrontMatter: n?.preserveFrontMatter,
2885
+ preserveHgComments: n?.preserveHgComments,
2886
+ constrainToRoot: n?.constrainToRoot
2887
+ });
2888
+ }
2889
+ function cn(t, e) {
2890
+ if (ae(t))
2891
+ throw d({
2892
+ code: "parse_error",
2893
+ path: e,
2894
+ details: {
2895
+ message: ce(t) ?? "unclosed hyogen block (missing closing marker)"
2896
+ }
2897
+ });
2898
+ const n = [], r = C(t);
2899
+ for (const i of r) {
2900
+ const s = W(i.inner);
2901
+ if (s.length === 0)
2902
+ throw d({
2903
+ code: "parse_error",
2904
+ path: e,
2905
+ details: { message: "empty hyogen block" }
2906
+ });
2907
+ if (s.length === 1 && he(s[0]) || s.length === 1 && (Q(s[0]) || I(s[0])))
2908
+ continue;
2909
+ const o = s[0];
2910
+ if (o === "endblock" || /^block\s+/.test(o))
2911
+ continue;
2912
+ const a = H(o, e);
2913
+ if (a) {
2914
+ n.push({ kind: "extend", path: a.path });
2915
+ continue;
2916
+ }
2917
+ if (s.length !== 1) {
2918
+ const c = s.join(`
2919
+ `);
2920
+ if (I(c) || s.every(
2921
+ (l) => Q(l) || H(l) !== null
2922
+ ))
2923
+ continue;
2924
+ throw d({
2925
+ code: "parse_error",
2926
+ path: e,
2927
+ details: { message: "hyogen block must contain a single directive" }
2928
+ });
2929
+ }
2930
+ if (/^include\s+/i.test(o)) {
2931
+ const c = Fe(i.inner, e);
2932
+ n.push({ kind: "include", path: c.path });
2933
+ continue;
2934
+ }
2935
+ if (/^component\s+/i.test(o)) {
2936
+ const c = je(i.inner, e);
2937
+ n.push({ kind: "component", path: c.path });
2938
+ continue;
2939
+ }
2940
+ throw d({
2941
+ code: "parse_error",
2942
+ path: e,
2943
+ details: { message: `unsupported hyogen directive: ${o}` }
2944
+ });
2945
+ }
2946
+ return n;
2947
+ }
2948
+ function hn(t, e, n) {
2949
+ return j(t) ? t : re(t, {
2950
+ rootDir: n.root,
2951
+ fromPath: e,
2952
+ documentPath: e,
2953
+ constrainToRoot: n.constrainToRoot,
2954
+ hyogenPath: !0
2955
+ });
2956
+ }
2957
+ async function ln(t, e, n = {}) {
2958
+ const r = t.map(
2959
+ (l) => j(l) ? l : u.resolve(l)
2960
+ ), i = new Set(r), s = /* @__PURE__ */ new Set(), o = [], a = [...r];
2961
+ for (; a.length > 0; ) {
2962
+ const l = a.shift();
2963
+ if (s.has(l))
2964
+ continue;
2965
+ s.add(l);
2966
+ const p = await e(l), f = cn(p, l);
2967
+ for (const g of f) {
2968
+ const w = hn(g.path, l, n);
2969
+ o.push({ from: l, to: w, kind: g.kind }), s.has(w) || a.push(w);
2970
+ }
2971
+ }
2972
+ const c = [...s], h = c.filter((l) => !i.has(l));
2973
+ return {
2974
+ entries: r,
2975
+ dependencies: h,
2976
+ nodes: c,
2977
+ edges: o
2978
+ };
2979
+ }
2980
+ function dn(t) {
2981
+ return t.replace(/\\/g, "/").split("/").filter((r) => r.length > 0).some((r) => r.startsWith("_"));
2982
+ }
2983
+ function pn(t) {
2984
+ return Ge.scan(t).isGlob;
2985
+ }
2986
+ function un(t) {
2987
+ return t.root ? u.resolve(t.root) : t.cwd ? u.resolve(t.cwd) : z(process.cwd()) ?? process.cwd();
2988
+ }
2989
+ async function fn(t, e = {}) {
2990
+ const n = Array.isArray(t) ? t : [t], r = un(e), i = e.includeUnderscoreEntries === !0, s = /* @__PURE__ */ new Map();
2991
+ for (const o of n) {
2992
+ if (!pn(o)) {
2993
+ const c = u.isAbsolute(o) ? u.resolve(o) : u.resolve(r, o);
2994
+ try {
2995
+ if (!(await te(c)).isFile())
2996
+ throw d({
2997
+ code: "file_not_found",
2998
+ path: c,
2999
+ details: {
3000
+ path: c,
3001
+ from: c,
3002
+ via: "include"
3003
+ }
3004
+ });
3005
+ } catch (l) {
3006
+ throw l instanceof Error && "code" in l && l.code === "file_not_found" ? l : l.code === "ENOENT" ? d({
3007
+ code: "file_not_found",
3008
+ path: c,
3009
+ details: {
3010
+ path: c,
3011
+ from: c,
3012
+ via: "include"
3013
+ }
3014
+ }) : l;
3015
+ }
3016
+ const h = u.relative(r, c).replace(/\\/g, "/");
3017
+ s.set(h, c);
3018
+ continue;
3019
+ }
3020
+ const a = await Ye(o, {
3021
+ cwd: r,
3022
+ absolute: !0,
3023
+ onlyFiles: !0,
3024
+ dot: !1
3025
+ });
3026
+ for (const c of a) {
3027
+ const h = u.relative(r, c).replace(/\\/g, "/");
3028
+ !i && dn(h) || s.set(h, u.resolve(c));
3029
+ }
3030
+ }
3031
+ return [...s.values()];
3032
+ }
3033
+ function mn(t) {
3034
+ return t instanceof Error && t.name === "HyogenError" && "code" in t && typeof t.code == "string";
3035
+ }
3036
+ function gn(t, e) {
3037
+ if (t)
3038
+ return u.resolve(t);
3039
+ for (const n of e) {
3040
+ const r = z(n);
3041
+ if (r)
3042
+ return r;
3043
+ }
3044
+ return e.length > 0 ? u.dirname(u.resolve(e[0])) : process.cwd();
3045
+ }
3046
+ async function Sn(t) {
3047
+ const e = await fn(t.input, {
3048
+ root: t.root,
3049
+ includeUnderscoreEntries: t.includeUnderscoreEntries
3050
+ }), n = gn(t.root, e), r = t.loader ?? $e(), i = z(n) !== void 0;
3051
+ e.length > 0 && await ln(e, r, {
3052
+ root: n,
3053
+ constrainToRoot: i
3054
+ });
3055
+ const s = [], o = [];
3056
+ for (const a of e) {
3057
+ const c = u.resolve(a), h = u.relative(n, c).replace(/\\/g, "/"), l = await an(
3058
+ { path: c },
3059
+ t.context,
3060
+ {
3061
+ loader: r,
3062
+ root: n,
3063
+ serverContext: t.serverContext,
3064
+ preserveFrontMatter: t.preserveFrontMatter,
3065
+ preserveHgComments: t.preserveHgComments
3066
+ }
3067
+ ), p = u.join(t.outDir, h);
3068
+ try {
3069
+ await qe(u.dirname(p), { recursive: !0 }), await Pe(p, l.markdown, "utf8");
3070
+ } catch (f) {
3071
+ if (mn(f))
3072
+ throw f;
3073
+ const g = f instanceof Error ? f.message : "unknown write error";
3074
+ throw d({
3075
+ code: "load_failed",
3076
+ path: p,
3077
+ details: {
3078
+ path: p,
3079
+ reason: g
3080
+ }
3081
+ });
3082
+ }
3083
+ s.push({ path: h, markdown: l.markdown }), o.push(...l.warnings);
3084
+ }
3085
+ return { files: s, warnings: o };
3086
+ }
3087
+ function Cn(t, e) {
3088
+ const n = [`[hyogen:${t}] ${e.code}`], r = {};
3089
+ if (e.details)
3090
+ for (const [i, s] of Object.entries(e.details))
3091
+ s !== void 0 && (r[i] = s);
3092
+ r.path === void 0 && e.path !== void 0 && (r.path = e.path);
3093
+ for (const [i, s] of Object.entries(r))
3094
+ n.push(` ${i}: ${String(s)}`);
3095
+ return n.join(`
3096
+ `);
3097
+ }
3098
+ export {
3099
+ Sn as build,
3100
+ it as createFsLoader,
3101
+ d as createHyogenError,
3102
+ $e as createNodeLoader,
3103
+ Cn as formatDiagnosticLog,
3104
+ nt as formatMessage,
3105
+ j as isRemotePath,
3106
+ _n as renderClient,
3107
+ an as renderServer
3108
+ };
3109
+ //# sourceMappingURL=index.js.map