@reteps/tree-sitter-htmlmustache 0.0.31 → 0.0.34

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.
@@ -0,0 +1,3613 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __commonJS = (cb, mod) => function __require() {
10
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+
29
+ // node_modules/color-name/index.js
30
+ var require_color_name = __commonJS({
31
+ "node_modules/color-name/index.js"(exports2, module2) {
32
+ "use strict";
33
+ module2.exports = {
34
+ "aliceblue": [240, 248, 255],
35
+ "antiquewhite": [250, 235, 215],
36
+ "aqua": [0, 255, 255],
37
+ "aquamarine": [127, 255, 212],
38
+ "azure": [240, 255, 255],
39
+ "beige": [245, 245, 220],
40
+ "bisque": [255, 228, 196],
41
+ "black": [0, 0, 0],
42
+ "blanchedalmond": [255, 235, 205],
43
+ "blue": [0, 0, 255],
44
+ "blueviolet": [138, 43, 226],
45
+ "brown": [165, 42, 42],
46
+ "burlywood": [222, 184, 135],
47
+ "cadetblue": [95, 158, 160],
48
+ "chartreuse": [127, 255, 0],
49
+ "chocolate": [210, 105, 30],
50
+ "coral": [255, 127, 80],
51
+ "cornflowerblue": [100, 149, 237],
52
+ "cornsilk": [255, 248, 220],
53
+ "crimson": [220, 20, 60],
54
+ "cyan": [0, 255, 255],
55
+ "darkblue": [0, 0, 139],
56
+ "darkcyan": [0, 139, 139],
57
+ "darkgoldenrod": [184, 134, 11],
58
+ "darkgray": [169, 169, 169],
59
+ "darkgreen": [0, 100, 0],
60
+ "darkgrey": [169, 169, 169],
61
+ "darkkhaki": [189, 183, 107],
62
+ "darkmagenta": [139, 0, 139],
63
+ "darkolivegreen": [85, 107, 47],
64
+ "darkorange": [255, 140, 0],
65
+ "darkorchid": [153, 50, 204],
66
+ "darkred": [139, 0, 0],
67
+ "darksalmon": [233, 150, 122],
68
+ "darkseagreen": [143, 188, 143],
69
+ "darkslateblue": [72, 61, 139],
70
+ "darkslategray": [47, 79, 79],
71
+ "darkslategrey": [47, 79, 79],
72
+ "darkturquoise": [0, 206, 209],
73
+ "darkviolet": [148, 0, 211],
74
+ "deeppink": [255, 20, 147],
75
+ "deepskyblue": [0, 191, 255],
76
+ "dimgray": [105, 105, 105],
77
+ "dimgrey": [105, 105, 105],
78
+ "dodgerblue": [30, 144, 255],
79
+ "firebrick": [178, 34, 34],
80
+ "floralwhite": [255, 250, 240],
81
+ "forestgreen": [34, 139, 34],
82
+ "fuchsia": [255, 0, 255],
83
+ "gainsboro": [220, 220, 220],
84
+ "ghostwhite": [248, 248, 255],
85
+ "gold": [255, 215, 0],
86
+ "goldenrod": [218, 165, 32],
87
+ "gray": [128, 128, 128],
88
+ "green": [0, 128, 0],
89
+ "greenyellow": [173, 255, 47],
90
+ "grey": [128, 128, 128],
91
+ "honeydew": [240, 255, 240],
92
+ "hotpink": [255, 105, 180],
93
+ "indianred": [205, 92, 92],
94
+ "indigo": [75, 0, 130],
95
+ "ivory": [255, 255, 240],
96
+ "khaki": [240, 230, 140],
97
+ "lavender": [230, 230, 250],
98
+ "lavenderblush": [255, 240, 245],
99
+ "lawngreen": [124, 252, 0],
100
+ "lemonchiffon": [255, 250, 205],
101
+ "lightblue": [173, 216, 230],
102
+ "lightcoral": [240, 128, 128],
103
+ "lightcyan": [224, 255, 255],
104
+ "lightgoldenrodyellow": [250, 250, 210],
105
+ "lightgray": [211, 211, 211],
106
+ "lightgreen": [144, 238, 144],
107
+ "lightgrey": [211, 211, 211],
108
+ "lightpink": [255, 182, 193],
109
+ "lightsalmon": [255, 160, 122],
110
+ "lightseagreen": [32, 178, 170],
111
+ "lightskyblue": [135, 206, 250],
112
+ "lightslategray": [119, 136, 153],
113
+ "lightslategrey": [119, 136, 153],
114
+ "lightsteelblue": [176, 196, 222],
115
+ "lightyellow": [255, 255, 224],
116
+ "lime": [0, 255, 0],
117
+ "limegreen": [50, 205, 50],
118
+ "linen": [250, 240, 230],
119
+ "magenta": [255, 0, 255],
120
+ "maroon": [128, 0, 0],
121
+ "mediumaquamarine": [102, 205, 170],
122
+ "mediumblue": [0, 0, 205],
123
+ "mediumorchid": [186, 85, 211],
124
+ "mediumpurple": [147, 112, 219],
125
+ "mediumseagreen": [60, 179, 113],
126
+ "mediumslateblue": [123, 104, 238],
127
+ "mediumspringgreen": [0, 250, 154],
128
+ "mediumturquoise": [72, 209, 204],
129
+ "mediumvioletred": [199, 21, 133],
130
+ "midnightblue": [25, 25, 112],
131
+ "mintcream": [245, 255, 250],
132
+ "mistyrose": [255, 228, 225],
133
+ "moccasin": [255, 228, 181],
134
+ "navajowhite": [255, 222, 173],
135
+ "navy": [0, 0, 128],
136
+ "oldlace": [253, 245, 230],
137
+ "olive": [128, 128, 0],
138
+ "olivedrab": [107, 142, 35],
139
+ "orange": [255, 165, 0],
140
+ "orangered": [255, 69, 0],
141
+ "orchid": [218, 112, 214],
142
+ "palegoldenrod": [238, 232, 170],
143
+ "palegreen": [152, 251, 152],
144
+ "paleturquoise": [175, 238, 238],
145
+ "palevioletred": [219, 112, 147],
146
+ "papayawhip": [255, 239, 213],
147
+ "peachpuff": [255, 218, 185],
148
+ "peru": [205, 133, 63],
149
+ "pink": [255, 192, 203],
150
+ "plum": [221, 160, 221],
151
+ "powderblue": [176, 224, 230],
152
+ "purple": [128, 0, 128],
153
+ "rebeccapurple": [102, 51, 153],
154
+ "red": [255, 0, 0],
155
+ "rosybrown": [188, 143, 143],
156
+ "royalblue": [65, 105, 225],
157
+ "saddlebrown": [139, 69, 19],
158
+ "salmon": [250, 128, 114],
159
+ "sandybrown": [244, 164, 96],
160
+ "seagreen": [46, 139, 87],
161
+ "seashell": [255, 245, 238],
162
+ "sienna": [160, 82, 45],
163
+ "silver": [192, 192, 192],
164
+ "skyblue": [135, 206, 235],
165
+ "slateblue": [106, 90, 205],
166
+ "slategray": [112, 128, 144],
167
+ "slategrey": [112, 128, 144],
168
+ "snow": [255, 250, 250],
169
+ "springgreen": [0, 255, 127],
170
+ "steelblue": [70, 130, 180],
171
+ "tan": [210, 180, 140],
172
+ "teal": [0, 128, 128],
173
+ "thistle": [216, 191, 216],
174
+ "tomato": [255, 99, 71],
175
+ "turquoise": [64, 224, 208],
176
+ "violet": [238, 130, 238],
177
+ "wheat": [245, 222, 179],
178
+ "white": [255, 255, 255],
179
+ "whitesmoke": [245, 245, 245],
180
+ "yellow": [255, 255, 0],
181
+ "yellowgreen": [154, 205, 50]
182
+ };
183
+ }
184
+ });
185
+
186
+ // node_modules/color-convert/conversions.js
187
+ var require_conversions = __commonJS({
188
+ "node_modules/color-convert/conversions.js"(exports2, module2) {
189
+ var cssKeywords = require_color_name();
190
+ var reverseKeywords = {};
191
+ for (const key of Object.keys(cssKeywords)) {
192
+ reverseKeywords[cssKeywords[key]] = key;
193
+ }
194
+ var convert = {
195
+ rgb: { channels: 3, labels: "rgb" },
196
+ hsl: { channels: 3, labels: "hsl" },
197
+ hsv: { channels: 3, labels: "hsv" },
198
+ hwb: { channels: 3, labels: "hwb" },
199
+ cmyk: { channels: 4, labels: "cmyk" },
200
+ xyz: { channels: 3, labels: "xyz" },
201
+ lab: { channels: 3, labels: "lab" },
202
+ lch: { channels: 3, labels: "lch" },
203
+ hex: { channels: 1, labels: ["hex"] },
204
+ keyword: { channels: 1, labels: ["keyword"] },
205
+ ansi16: { channels: 1, labels: ["ansi16"] },
206
+ ansi256: { channels: 1, labels: ["ansi256"] },
207
+ hcg: { channels: 3, labels: ["h", "c", "g"] },
208
+ apple: { channels: 3, labels: ["r16", "g16", "b16"] },
209
+ gray: { channels: 1, labels: ["gray"] }
210
+ };
211
+ module2.exports = convert;
212
+ for (const model of Object.keys(convert)) {
213
+ if (!("channels" in convert[model])) {
214
+ throw new Error("missing channels property: " + model);
215
+ }
216
+ if (!("labels" in convert[model])) {
217
+ throw new Error("missing channel labels property: " + model);
218
+ }
219
+ if (convert[model].labels.length !== convert[model].channels) {
220
+ throw new Error("channel and label counts mismatch: " + model);
221
+ }
222
+ const { channels, labels } = convert[model];
223
+ delete convert[model].channels;
224
+ delete convert[model].labels;
225
+ Object.defineProperty(convert[model], "channels", { value: channels });
226
+ Object.defineProperty(convert[model], "labels", { value: labels });
227
+ }
228
+ convert.rgb.hsl = function(rgb) {
229
+ const r = rgb[0] / 255;
230
+ const g = rgb[1] / 255;
231
+ const b = rgb[2] / 255;
232
+ const min = Math.min(r, g, b);
233
+ const max = Math.max(r, g, b);
234
+ const delta = max - min;
235
+ let h;
236
+ let s;
237
+ if (max === min) {
238
+ h = 0;
239
+ } else if (r === max) {
240
+ h = (g - b) / delta;
241
+ } else if (g === max) {
242
+ h = 2 + (b - r) / delta;
243
+ } else if (b === max) {
244
+ h = 4 + (r - g) / delta;
245
+ }
246
+ h = Math.min(h * 60, 360);
247
+ if (h < 0) {
248
+ h += 360;
249
+ }
250
+ const l = (min + max) / 2;
251
+ if (max === min) {
252
+ s = 0;
253
+ } else if (l <= 0.5) {
254
+ s = delta / (max + min);
255
+ } else {
256
+ s = delta / (2 - max - min);
257
+ }
258
+ return [h, s * 100, l * 100];
259
+ };
260
+ convert.rgb.hsv = function(rgb) {
261
+ let rdif;
262
+ let gdif;
263
+ let bdif;
264
+ let h;
265
+ let s;
266
+ const r = rgb[0] / 255;
267
+ const g = rgb[1] / 255;
268
+ const b = rgb[2] / 255;
269
+ const v = Math.max(r, g, b);
270
+ const diff = v - Math.min(r, g, b);
271
+ const diffc = function(c) {
272
+ return (v - c) / 6 / diff + 1 / 2;
273
+ };
274
+ if (diff === 0) {
275
+ h = 0;
276
+ s = 0;
277
+ } else {
278
+ s = diff / v;
279
+ rdif = diffc(r);
280
+ gdif = diffc(g);
281
+ bdif = diffc(b);
282
+ if (r === v) {
283
+ h = bdif - gdif;
284
+ } else if (g === v) {
285
+ h = 1 / 3 + rdif - bdif;
286
+ } else if (b === v) {
287
+ h = 2 / 3 + gdif - rdif;
288
+ }
289
+ if (h < 0) {
290
+ h += 1;
291
+ } else if (h > 1) {
292
+ h -= 1;
293
+ }
294
+ }
295
+ return [
296
+ h * 360,
297
+ s * 100,
298
+ v * 100
299
+ ];
300
+ };
301
+ convert.rgb.hwb = function(rgb) {
302
+ const r = rgb[0];
303
+ const g = rgb[1];
304
+ let b = rgb[2];
305
+ const h = convert.rgb.hsl(rgb)[0];
306
+ const w = 1 / 255 * Math.min(r, Math.min(g, b));
307
+ b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
308
+ return [h, w * 100, b * 100];
309
+ };
310
+ convert.rgb.cmyk = function(rgb) {
311
+ const r = rgb[0] / 255;
312
+ const g = rgb[1] / 255;
313
+ const b = rgb[2] / 255;
314
+ const k = Math.min(1 - r, 1 - g, 1 - b);
315
+ const c = (1 - r - k) / (1 - k) || 0;
316
+ const m = (1 - g - k) / (1 - k) || 0;
317
+ const y = (1 - b - k) / (1 - k) || 0;
318
+ return [c * 100, m * 100, y * 100, k * 100];
319
+ };
320
+ function comparativeDistance(x, y) {
321
+ return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
322
+ }
323
+ convert.rgb.keyword = function(rgb) {
324
+ const reversed = reverseKeywords[rgb];
325
+ if (reversed) {
326
+ return reversed;
327
+ }
328
+ let currentClosestDistance = Infinity;
329
+ let currentClosestKeyword;
330
+ for (const keyword of Object.keys(cssKeywords)) {
331
+ const value = cssKeywords[keyword];
332
+ const distance = comparativeDistance(rgb, value);
333
+ if (distance < currentClosestDistance) {
334
+ currentClosestDistance = distance;
335
+ currentClosestKeyword = keyword;
336
+ }
337
+ }
338
+ return currentClosestKeyword;
339
+ };
340
+ convert.keyword.rgb = function(keyword) {
341
+ return cssKeywords[keyword];
342
+ };
343
+ convert.rgb.xyz = function(rgb) {
344
+ let r = rgb[0] / 255;
345
+ let g = rgb[1] / 255;
346
+ let b = rgb[2] / 255;
347
+ r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
348
+ g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
349
+ b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
350
+ const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
351
+ const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
352
+ const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
353
+ return [x * 100, y * 100, z * 100];
354
+ };
355
+ convert.rgb.lab = function(rgb) {
356
+ const xyz = convert.rgb.xyz(rgb);
357
+ let x = xyz[0];
358
+ let y = xyz[1];
359
+ let z = xyz[2];
360
+ x /= 95.047;
361
+ y /= 100;
362
+ z /= 108.883;
363
+ x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
364
+ y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
365
+ z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
366
+ const l = 116 * y - 16;
367
+ const a = 500 * (x - y);
368
+ const b = 200 * (y - z);
369
+ return [l, a, b];
370
+ };
371
+ convert.hsl.rgb = function(hsl) {
372
+ const h = hsl[0] / 360;
373
+ const s = hsl[1] / 100;
374
+ const l = hsl[2] / 100;
375
+ let t2;
376
+ let t3;
377
+ let val;
378
+ if (s === 0) {
379
+ val = l * 255;
380
+ return [val, val, val];
381
+ }
382
+ if (l < 0.5) {
383
+ t2 = l * (1 + s);
384
+ } else {
385
+ t2 = l + s - l * s;
386
+ }
387
+ const t1 = 2 * l - t2;
388
+ const rgb = [0, 0, 0];
389
+ for (let i = 0; i < 3; i++) {
390
+ t3 = h + 1 / 3 * -(i - 1);
391
+ if (t3 < 0) {
392
+ t3++;
393
+ }
394
+ if (t3 > 1) {
395
+ t3--;
396
+ }
397
+ if (6 * t3 < 1) {
398
+ val = t1 + (t2 - t1) * 6 * t3;
399
+ } else if (2 * t3 < 1) {
400
+ val = t2;
401
+ } else if (3 * t3 < 2) {
402
+ val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
403
+ } else {
404
+ val = t1;
405
+ }
406
+ rgb[i] = val * 255;
407
+ }
408
+ return rgb;
409
+ };
410
+ convert.hsl.hsv = function(hsl) {
411
+ const h = hsl[0];
412
+ let s = hsl[1] / 100;
413
+ let l = hsl[2] / 100;
414
+ let smin = s;
415
+ const lmin = Math.max(l, 0.01);
416
+ l *= 2;
417
+ s *= l <= 1 ? l : 2 - l;
418
+ smin *= lmin <= 1 ? lmin : 2 - lmin;
419
+ const v = (l + s) / 2;
420
+ const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
421
+ return [h, sv * 100, v * 100];
422
+ };
423
+ convert.hsv.rgb = function(hsv) {
424
+ const h = hsv[0] / 60;
425
+ const s = hsv[1] / 100;
426
+ let v = hsv[2] / 100;
427
+ const hi = Math.floor(h) % 6;
428
+ const f = h - Math.floor(h);
429
+ const p = 255 * v * (1 - s);
430
+ const q = 255 * v * (1 - s * f);
431
+ const t = 255 * v * (1 - s * (1 - f));
432
+ v *= 255;
433
+ switch (hi) {
434
+ case 0:
435
+ return [v, t, p];
436
+ case 1:
437
+ return [q, v, p];
438
+ case 2:
439
+ return [p, v, t];
440
+ case 3:
441
+ return [p, q, v];
442
+ case 4:
443
+ return [t, p, v];
444
+ case 5:
445
+ return [v, p, q];
446
+ }
447
+ };
448
+ convert.hsv.hsl = function(hsv) {
449
+ const h = hsv[0];
450
+ const s = hsv[1] / 100;
451
+ const v = hsv[2] / 100;
452
+ const vmin = Math.max(v, 0.01);
453
+ let sl;
454
+ let l;
455
+ l = (2 - s) * v;
456
+ const lmin = (2 - s) * vmin;
457
+ sl = s * vmin;
458
+ sl /= lmin <= 1 ? lmin : 2 - lmin;
459
+ sl = sl || 0;
460
+ l /= 2;
461
+ return [h, sl * 100, l * 100];
462
+ };
463
+ convert.hwb.rgb = function(hwb) {
464
+ const h = hwb[0] / 360;
465
+ let wh = hwb[1] / 100;
466
+ let bl = hwb[2] / 100;
467
+ const ratio = wh + bl;
468
+ let f;
469
+ if (ratio > 1) {
470
+ wh /= ratio;
471
+ bl /= ratio;
472
+ }
473
+ const i = Math.floor(6 * h);
474
+ const v = 1 - bl;
475
+ f = 6 * h - i;
476
+ if ((i & 1) !== 0) {
477
+ f = 1 - f;
478
+ }
479
+ const n = wh + f * (v - wh);
480
+ let r;
481
+ let g;
482
+ let b;
483
+ switch (i) {
484
+ default:
485
+ case 6:
486
+ case 0:
487
+ r = v;
488
+ g = n;
489
+ b = wh;
490
+ break;
491
+ case 1:
492
+ r = n;
493
+ g = v;
494
+ b = wh;
495
+ break;
496
+ case 2:
497
+ r = wh;
498
+ g = v;
499
+ b = n;
500
+ break;
501
+ case 3:
502
+ r = wh;
503
+ g = n;
504
+ b = v;
505
+ break;
506
+ case 4:
507
+ r = n;
508
+ g = wh;
509
+ b = v;
510
+ break;
511
+ case 5:
512
+ r = v;
513
+ g = wh;
514
+ b = n;
515
+ break;
516
+ }
517
+ return [r * 255, g * 255, b * 255];
518
+ };
519
+ convert.cmyk.rgb = function(cmyk) {
520
+ const c = cmyk[0] / 100;
521
+ const m = cmyk[1] / 100;
522
+ const y = cmyk[2] / 100;
523
+ const k = cmyk[3] / 100;
524
+ const r = 1 - Math.min(1, c * (1 - k) + k);
525
+ const g = 1 - Math.min(1, m * (1 - k) + k);
526
+ const b = 1 - Math.min(1, y * (1 - k) + k);
527
+ return [r * 255, g * 255, b * 255];
528
+ };
529
+ convert.xyz.rgb = function(xyz) {
530
+ const x = xyz[0] / 100;
531
+ const y = xyz[1] / 100;
532
+ const z = xyz[2] / 100;
533
+ let r;
534
+ let g;
535
+ let b;
536
+ r = x * 3.2406 + y * -1.5372 + z * -0.4986;
537
+ g = x * -0.9689 + y * 1.8758 + z * 0.0415;
538
+ b = x * 0.0557 + y * -0.204 + z * 1.057;
539
+ r = r > 31308e-7 ? 1.055 * r ** (1 / 2.4) - 0.055 : r * 12.92;
540
+ g = g > 31308e-7 ? 1.055 * g ** (1 / 2.4) - 0.055 : g * 12.92;
541
+ b = b > 31308e-7 ? 1.055 * b ** (1 / 2.4) - 0.055 : b * 12.92;
542
+ r = Math.min(Math.max(0, r), 1);
543
+ g = Math.min(Math.max(0, g), 1);
544
+ b = Math.min(Math.max(0, b), 1);
545
+ return [r * 255, g * 255, b * 255];
546
+ };
547
+ convert.xyz.lab = function(xyz) {
548
+ let x = xyz[0];
549
+ let y = xyz[1];
550
+ let z = xyz[2];
551
+ x /= 95.047;
552
+ y /= 100;
553
+ z /= 108.883;
554
+ x = x > 8856e-6 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
555
+ y = y > 8856e-6 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
556
+ z = z > 8856e-6 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
557
+ const l = 116 * y - 16;
558
+ const a = 500 * (x - y);
559
+ const b = 200 * (y - z);
560
+ return [l, a, b];
561
+ };
562
+ convert.lab.xyz = function(lab) {
563
+ const l = lab[0];
564
+ const a = lab[1];
565
+ const b = lab[2];
566
+ let x;
567
+ let y;
568
+ let z;
569
+ y = (l + 16) / 116;
570
+ x = a / 500 + y;
571
+ z = y - b / 200;
572
+ const y2 = y ** 3;
573
+ const x2 = x ** 3;
574
+ const z2 = z ** 3;
575
+ y = y2 > 8856e-6 ? y2 : (y - 16 / 116) / 7.787;
576
+ x = x2 > 8856e-6 ? x2 : (x - 16 / 116) / 7.787;
577
+ z = z2 > 8856e-6 ? z2 : (z - 16 / 116) / 7.787;
578
+ x *= 95.047;
579
+ y *= 100;
580
+ z *= 108.883;
581
+ return [x, y, z];
582
+ };
583
+ convert.lab.lch = function(lab) {
584
+ const l = lab[0];
585
+ const a = lab[1];
586
+ const b = lab[2];
587
+ let h;
588
+ const hr = Math.atan2(b, a);
589
+ h = hr * 360 / 2 / Math.PI;
590
+ if (h < 0) {
591
+ h += 360;
592
+ }
593
+ const c = Math.sqrt(a * a + b * b);
594
+ return [l, c, h];
595
+ };
596
+ convert.lch.lab = function(lch) {
597
+ const l = lch[0];
598
+ const c = lch[1];
599
+ const h = lch[2];
600
+ const hr = h / 360 * 2 * Math.PI;
601
+ const a = c * Math.cos(hr);
602
+ const b = c * Math.sin(hr);
603
+ return [l, a, b];
604
+ };
605
+ convert.rgb.ansi16 = function(args, saturation = null) {
606
+ const [r, g, b] = args;
607
+ let value = saturation === null ? convert.rgb.hsv(args)[2] : saturation;
608
+ value = Math.round(value / 50);
609
+ if (value === 0) {
610
+ return 30;
611
+ }
612
+ let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
613
+ if (value === 2) {
614
+ ansi += 60;
615
+ }
616
+ return ansi;
617
+ };
618
+ convert.hsv.ansi16 = function(args) {
619
+ return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
620
+ };
621
+ convert.rgb.ansi256 = function(args) {
622
+ const r = args[0];
623
+ const g = args[1];
624
+ const b = args[2];
625
+ if (r === g && g === b) {
626
+ if (r < 8) {
627
+ return 16;
628
+ }
629
+ if (r > 248) {
630
+ return 231;
631
+ }
632
+ return Math.round((r - 8) / 247 * 24) + 232;
633
+ }
634
+ const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
635
+ return ansi;
636
+ };
637
+ convert.ansi16.rgb = function(args) {
638
+ let color = args % 10;
639
+ if (color === 0 || color === 7) {
640
+ if (args > 50) {
641
+ color += 3.5;
642
+ }
643
+ color = color / 10.5 * 255;
644
+ return [color, color, color];
645
+ }
646
+ const mult = (~~(args > 50) + 1) * 0.5;
647
+ const r = (color & 1) * mult * 255;
648
+ const g = (color >> 1 & 1) * mult * 255;
649
+ const b = (color >> 2 & 1) * mult * 255;
650
+ return [r, g, b];
651
+ };
652
+ convert.ansi256.rgb = function(args) {
653
+ if (args >= 232) {
654
+ const c = (args - 232) * 10 + 8;
655
+ return [c, c, c];
656
+ }
657
+ args -= 16;
658
+ let rem;
659
+ const r = Math.floor(args / 36) / 5 * 255;
660
+ const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
661
+ const b = rem % 6 / 5 * 255;
662
+ return [r, g, b];
663
+ };
664
+ convert.rgb.hex = function(args) {
665
+ const integer = ((Math.round(args[0]) & 255) << 16) + ((Math.round(args[1]) & 255) << 8) + (Math.round(args[2]) & 255);
666
+ const string = integer.toString(16).toUpperCase();
667
+ return "000000".substring(string.length) + string;
668
+ };
669
+ convert.hex.rgb = function(args) {
670
+ const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
671
+ if (!match) {
672
+ return [0, 0, 0];
673
+ }
674
+ let colorString = match[0];
675
+ if (match[0].length === 3) {
676
+ colorString = colorString.split("").map((char) => {
677
+ return char + char;
678
+ }).join("");
679
+ }
680
+ const integer = parseInt(colorString, 16);
681
+ const r = integer >> 16 & 255;
682
+ const g = integer >> 8 & 255;
683
+ const b = integer & 255;
684
+ return [r, g, b];
685
+ };
686
+ convert.rgb.hcg = function(rgb) {
687
+ const r = rgb[0] / 255;
688
+ const g = rgb[1] / 255;
689
+ const b = rgb[2] / 255;
690
+ const max = Math.max(Math.max(r, g), b);
691
+ const min = Math.min(Math.min(r, g), b);
692
+ const chroma = max - min;
693
+ let grayscale;
694
+ let hue;
695
+ if (chroma < 1) {
696
+ grayscale = min / (1 - chroma);
697
+ } else {
698
+ grayscale = 0;
699
+ }
700
+ if (chroma <= 0) {
701
+ hue = 0;
702
+ } else if (max === r) {
703
+ hue = (g - b) / chroma % 6;
704
+ } else if (max === g) {
705
+ hue = 2 + (b - r) / chroma;
706
+ } else {
707
+ hue = 4 + (r - g) / chroma;
708
+ }
709
+ hue /= 6;
710
+ hue %= 1;
711
+ return [hue * 360, chroma * 100, grayscale * 100];
712
+ };
713
+ convert.hsl.hcg = function(hsl) {
714
+ const s = hsl[1] / 100;
715
+ const l = hsl[2] / 100;
716
+ const c = l < 0.5 ? 2 * s * l : 2 * s * (1 - l);
717
+ let f = 0;
718
+ if (c < 1) {
719
+ f = (l - 0.5 * c) / (1 - c);
720
+ }
721
+ return [hsl[0], c * 100, f * 100];
722
+ };
723
+ convert.hsv.hcg = function(hsv) {
724
+ const s = hsv[1] / 100;
725
+ const v = hsv[2] / 100;
726
+ const c = s * v;
727
+ let f = 0;
728
+ if (c < 1) {
729
+ f = (v - c) / (1 - c);
730
+ }
731
+ return [hsv[0], c * 100, f * 100];
732
+ };
733
+ convert.hcg.rgb = function(hcg) {
734
+ const h = hcg[0] / 360;
735
+ const c = hcg[1] / 100;
736
+ const g = hcg[2] / 100;
737
+ if (c === 0) {
738
+ return [g * 255, g * 255, g * 255];
739
+ }
740
+ const pure = [0, 0, 0];
741
+ const hi = h % 1 * 6;
742
+ const v = hi % 1;
743
+ const w = 1 - v;
744
+ let mg = 0;
745
+ switch (Math.floor(hi)) {
746
+ case 0:
747
+ pure[0] = 1;
748
+ pure[1] = v;
749
+ pure[2] = 0;
750
+ break;
751
+ case 1:
752
+ pure[0] = w;
753
+ pure[1] = 1;
754
+ pure[2] = 0;
755
+ break;
756
+ case 2:
757
+ pure[0] = 0;
758
+ pure[1] = 1;
759
+ pure[2] = v;
760
+ break;
761
+ case 3:
762
+ pure[0] = 0;
763
+ pure[1] = w;
764
+ pure[2] = 1;
765
+ break;
766
+ case 4:
767
+ pure[0] = v;
768
+ pure[1] = 0;
769
+ pure[2] = 1;
770
+ break;
771
+ default:
772
+ pure[0] = 1;
773
+ pure[1] = 0;
774
+ pure[2] = w;
775
+ }
776
+ mg = (1 - c) * g;
777
+ return [
778
+ (c * pure[0] + mg) * 255,
779
+ (c * pure[1] + mg) * 255,
780
+ (c * pure[2] + mg) * 255
781
+ ];
782
+ };
783
+ convert.hcg.hsv = function(hcg) {
784
+ const c = hcg[1] / 100;
785
+ const g = hcg[2] / 100;
786
+ const v = c + g * (1 - c);
787
+ let f = 0;
788
+ if (v > 0) {
789
+ f = c / v;
790
+ }
791
+ return [hcg[0], f * 100, v * 100];
792
+ };
793
+ convert.hcg.hsl = function(hcg) {
794
+ const c = hcg[1] / 100;
795
+ const g = hcg[2] / 100;
796
+ const l = g * (1 - c) + 0.5 * c;
797
+ let s = 0;
798
+ if (l > 0 && l < 0.5) {
799
+ s = c / (2 * l);
800
+ } else if (l >= 0.5 && l < 1) {
801
+ s = c / (2 * (1 - l));
802
+ }
803
+ return [hcg[0], s * 100, l * 100];
804
+ };
805
+ convert.hcg.hwb = function(hcg) {
806
+ const c = hcg[1] / 100;
807
+ const g = hcg[2] / 100;
808
+ const v = c + g * (1 - c);
809
+ return [hcg[0], (v - c) * 100, (1 - v) * 100];
810
+ };
811
+ convert.hwb.hcg = function(hwb) {
812
+ const w = hwb[1] / 100;
813
+ const b = hwb[2] / 100;
814
+ const v = 1 - b;
815
+ const c = v - w;
816
+ let g = 0;
817
+ if (c < 1) {
818
+ g = (v - c) / (1 - c);
819
+ }
820
+ return [hwb[0], c * 100, g * 100];
821
+ };
822
+ convert.apple.rgb = function(apple) {
823
+ return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
824
+ };
825
+ convert.rgb.apple = function(rgb) {
826
+ return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
827
+ };
828
+ convert.gray.rgb = function(args) {
829
+ return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
830
+ };
831
+ convert.gray.hsl = function(args) {
832
+ return [0, 0, args[0]];
833
+ };
834
+ convert.gray.hsv = convert.gray.hsl;
835
+ convert.gray.hwb = function(gray) {
836
+ return [0, 100, gray[0]];
837
+ };
838
+ convert.gray.cmyk = function(gray) {
839
+ return [0, 0, 0, gray[0]];
840
+ };
841
+ convert.gray.lab = function(gray) {
842
+ return [gray[0], 0, 0];
843
+ };
844
+ convert.gray.hex = function(gray) {
845
+ const val = Math.round(gray[0] / 100 * 255) & 255;
846
+ const integer = (val << 16) + (val << 8) + val;
847
+ const string = integer.toString(16).toUpperCase();
848
+ return "000000".substring(string.length) + string;
849
+ };
850
+ convert.rgb.gray = function(rgb) {
851
+ const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
852
+ return [val / 255 * 100];
853
+ };
854
+ }
855
+ });
856
+
857
+ // node_modules/color-convert/route.js
858
+ var require_route = __commonJS({
859
+ "node_modules/color-convert/route.js"(exports2, module2) {
860
+ var conversions = require_conversions();
861
+ function buildGraph() {
862
+ const graph = {};
863
+ const models = Object.keys(conversions);
864
+ for (let len = models.length, i = 0; i < len; i++) {
865
+ graph[models[i]] = {
866
+ // http://jsperf.com/1-vs-infinity
867
+ // micro-opt, but this is simple.
868
+ distance: -1,
869
+ parent: null
870
+ };
871
+ }
872
+ return graph;
873
+ }
874
+ function deriveBFS(fromModel) {
875
+ const graph = buildGraph();
876
+ const queue = [fromModel];
877
+ graph[fromModel].distance = 0;
878
+ while (queue.length) {
879
+ const current = queue.pop();
880
+ const adjacents = Object.keys(conversions[current]);
881
+ for (let len = adjacents.length, i = 0; i < len; i++) {
882
+ const adjacent = adjacents[i];
883
+ const node = graph[adjacent];
884
+ if (node.distance === -1) {
885
+ node.distance = graph[current].distance + 1;
886
+ node.parent = current;
887
+ queue.unshift(adjacent);
888
+ }
889
+ }
890
+ }
891
+ return graph;
892
+ }
893
+ function link(from, to) {
894
+ return function(args) {
895
+ return to(from(args));
896
+ };
897
+ }
898
+ function wrapConversion(toModel, graph) {
899
+ const path5 = [graph[toModel].parent, toModel];
900
+ let fn = conversions[graph[toModel].parent][toModel];
901
+ let cur = graph[toModel].parent;
902
+ while (graph[cur].parent) {
903
+ path5.unshift(graph[cur].parent);
904
+ fn = link(conversions[graph[cur].parent][cur], fn);
905
+ cur = graph[cur].parent;
906
+ }
907
+ fn.conversion = path5;
908
+ return fn;
909
+ }
910
+ module2.exports = function(fromModel) {
911
+ const graph = deriveBFS(fromModel);
912
+ const conversion = {};
913
+ const models = Object.keys(graph);
914
+ for (let len = models.length, i = 0; i < len; i++) {
915
+ const toModel = models[i];
916
+ const node = graph[toModel];
917
+ if (node.parent === null) {
918
+ continue;
919
+ }
920
+ conversion[toModel] = wrapConversion(toModel, graph);
921
+ }
922
+ return conversion;
923
+ };
924
+ }
925
+ });
926
+
927
+ // node_modules/color-convert/index.js
928
+ var require_color_convert = __commonJS({
929
+ "node_modules/color-convert/index.js"(exports2, module2) {
930
+ var conversions = require_conversions();
931
+ var route = require_route();
932
+ var convert = {};
933
+ var models = Object.keys(conversions);
934
+ function wrapRaw(fn) {
935
+ const wrappedFn = function(...args) {
936
+ const arg0 = args[0];
937
+ if (arg0 === void 0 || arg0 === null) {
938
+ return arg0;
939
+ }
940
+ if (arg0.length > 1) {
941
+ args = arg0;
942
+ }
943
+ return fn(args);
944
+ };
945
+ if ("conversion" in fn) {
946
+ wrappedFn.conversion = fn.conversion;
947
+ }
948
+ return wrappedFn;
949
+ }
950
+ function wrapRounded(fn) {
951
+ const wrappedFn = function(...args) {
952
+ const arg0 = args[0];
953
+ if (arg0 === void 0 || arg0 === null) {
954
+ return arg0;
955
+ }
956
+ if (arg0.length > 1) {
957
+ args = arg0;
958
+ }
959
+ const result = fn(args);
960
+ if (typeof result === "object") {
961
+ for (let len = result.length, i = 0; i < len; i++) {
962
+ result[i] = Math.round(result[i]);
963
+ }
964
+ }
965
+ return result;
966
+ };
967
+ if ("conversion" in fn) {
968
+ wrappedFn.conversion = fn.conversion;
969
+ }
970
+ return wrappedFn;
971
+ }
972
+ models.forEach((fromModel) => {
973
+ convert[fromModel] = {};
974
+ Object.defineProperty(convert[fromModel], "channels", { value: conversions[fromModel].channels });
975
+ Object.defineProperty(convert[fromModel], "labels", { value: conversions[fromModel].labels });
976
+ const routes = route(fromModel);
977
+ const routeModels = Object.keys(routes);
978
+ routeModels.forEach((toModel) => {
979
+ const fn = routes[toModel];
980
+ convert[fromModel][toModel] = wrapRounded(fn);
981
+ convert[fromModel][toModel].raw = wrapRaw(fn);
982
+ });
983
+ });
984
+ module2.exports = convert;
985
+ }
986
+ });
987
+
988
+ // node_modules/ansi-styles/index.js
989
+ var require_ansi_styles = __commonJS({
990
+ "node_modules/ansi-styles/index.js"(exports2, module2) {
991
+ "use strict";
992
+ var wrapAnsi16 = (fn, offset) => (...args) => {
993
+ const code = fn(...args);
994
+ return `\x1B[${code + offset}m`;
995
+ };
996
+ var wrapAnsi256 = (fn, offset) => (...args) => {
997
+ const code = fn(...args);
998
+ return `\x1B[${38 + offset};5;${code}m`;
999
+ };
1000
+ var wrapAnsi16m = (fn, offset) => (...args) => {
1001
+ const rgb = fn(...args);
1002
+ return `\x1B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
1003
+ };
1004
+ var ansi2ansi = (n) => n;
1005
+ var rgb2rgb = (r, g, b) => [r, g, b];
1006
+ var setLazyProperty = (object, property, get) => {
1007
+ Object.defineProperty(object, property, {
1008
+ get: () => {
1009
+ const value = get();
1010
+ Object.defineProperty(object, property, {
1011
+ value,
1012
+ enumerable: true,
1013
+ configurable: true
1014
+ });
1015
+ return value;
1016
+ },
1017
+ enumerable: true,
1018
+ configurable: true
1019
+ });
1020
+ };
1021
+ var colorConvert;
1022
+ var makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
1023
+ if (colorConvert === void 0) {
1024
+ colorConvert = require_color_convert();
1025
+ }
1026
+ const offset = isBackground ? 10 : 0;
1027
+ const styles = {};
1028
+ for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
1029
+ const name = sourceSpace === "ansi16" ? "ansi" : sourceSpace;
1030
+ if (sourceSpace === targetSpace) {
1031
+ styles[name] = wrap(identity, offset);
1032
+ } else if (typeof suite === "object") {
1033
+ styles[name] = wrap(suite[targetSpace], offset);
1034
+ }
1035
+ }
1036
+ return styles;
1037
+ };
1038
+ function assembleStyles() {
1039
+ const codes = /* @__PURE__ */ new Map();
1040
+ const styles = {
1041
+ modifier: {
1042
+ reset: [0, 0],
1043
+ // 21 isn't widely supported and 22 does the same thing
1044
+ bold: [1, 22],
1045
+ dim: [2, 22],
1046
+ italic: [3, 23],
1047
+ underline: [4, 24],
1048
+ inverse: [7, 27],
1049
+ hidden: [8, 28],
1050
+ strikethrough: [9, 29]
1051
+ },
1052
+ color: {
1053
+ black: [30, 39],
1054
+ red: [31, 39],
1055
+ green: [32, 39],
1056
+ yellow: [33, 39],
1057
+ blue: [34, 39],
1058
+ magenta: [35, 39],
1059
+ cyan: [36, 39],
1060
+ white: [37, 39],
1061
+ // Bright color
1062
+ blackBright: [90, 39],
1063
+ redBright: [91, 39],
1064
+ greenBright: [92, 39],
1065
+ yellowBright: [93, 39],
1066
+ blueBright: [94, 39],
1067
+ magentaBright: [95, 39],
1068
+ cyanBright: [96, 39],
1069
+ whiteBright: [97, 39]
1070
+ },
1071
+ bgColor: {
1072
+ bgBlack: [40, 49],
1073
+ bgRed: [41, 49],
1074
+ bgGreen: [42, 49],
1075
+ bgYellow: [43, 49],
1076
+ bgBlue: [44, 49],
1077
+ bgMagenta: [45, 49],
1078
+ bgCyan: [46, 49],
1079
+ bgWhite: [47, 49],
1080
+ // Bright color
1081
+ bgBlackBright: [100, 49],
1082
+ bgRedBright: [101, 49],
1083
+ bgGreenBright: [102, 49],
1084
+ bgYellowBright: [103, 49],
1085
+ bgBlueBright: [104, 49],
1086
+ bgMagentaBright: [105, 49],
1087
+ bgCyanBright: [106, 49],
1088
+ bgWhiteBright: [107, 49]
1089
+ }
1090
+ };
1091
+ styles.color.gray = styles.color.blackBright;
1092
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
1093
+ styles.color.grey = styles.color.blackBright;
1094
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
1095
+ for (const [groupName, group2] of Object.entries(styles)) {
1096
+ for (const [styleName, style] of Object.entries(group2)) {
1097
+ styles[styleName] = {
1098
+ open: `\x1B[${style[0]}m`,
1099
+ close: `\x1B[${style[1]}m`
1100
+ };
1101
+ group2[styleName] = styles[styleName];
1102
+ codes.set(style[0], style[1]);
1103
+ }
1104
+ Object.defineProperty(styles, groupName, {
1105
+ value: group2,
1106
+ enumerable: false
1107
+ });
1108
+ }
1109
+ Object.defineProperty(styles, "codes", {
1110
+ value: codes,
1111
+ enumerable: false
1112
+ });
1113
+ styles.color.close = "\x1B[39m";
1114
+ styles.bgColor.close = "\x1B[49m";
1115
+ setLazyProperty(styles.color, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, false));
1116
+ setLazyProperty(styles.color, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, false));
1117
+ setLazyProperty(styles.color, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, false));
1118
+ setLazyProperty(styles.bgColor, "ansi", () => makeDynamicStyles(wrapAnsi16, "ansi16", ansi2ansi, true));
1119
+ setLazyProperty(styles.bgColor, "ansi256", () => makeDynamicStyles(wrapAnsi256, "ansi256", ansi2ansi, true));
1120
+ setLazyProperty(styles.bgColor, "ansi16m", () => makeDynamicStyles(wrapAnsi16m, "rgb", rgb2rgb, true));
1121
+ return styles;
1122
+ }
1123
+ Object.defineProperty(module2, "exports", {
1124
+ enumerable: true,
1125
+ get: assembleStyles
1126
+ });
1127
+ }
1128
+ });
1129
+
1130
+ // node_modules/has-flag/index.js
1131
+ var require_has_flag = __commonJS({
1132
+ "node_modules/has-flag/index.js"(exports2, module2) {
1133
+ "use strict";
1134
+ module2.exports = (flag, argv = process.argv) => {
1135
+ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
1136
+ const position = argv.indexOf(prefix + flag);
1137
+ const terminatorPosition = argv.indexOf("--");
1138
+ return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
1139
+ };
1140
+ }
1141
+ });
1142
+
1143
+ // node_modules/supports-color/index.js
1144
+ var require_supports_color = __commonJS({
1145
+ "node_modules/supports-color/index.js"(exports2, module2) {
1146
+ "use strict";
1147
+ var os = require("os");
1148
+ var tty = require("tty");
1149
+ var hasFlag = require_has_flag();
1150
+ var { env } = process;
1151
+ var forceColor;
1152
+ if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
1153
+ forceColor = 0;
1154
+ } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) {
1155
+ forceColor = 1;
1156
+ }
1157
+ if ("FORCE_COLOR" in env) {
1158
+ if (env.FORCE_COLOR === "true") {
1159
+ forceColor = 1;
1160
+ } else if (env.FORCE_COLOR === "false") {
1161
+ forceColor = 0;
1162
+ } else {
1163
+ forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
1164
+ }
1165
+ }
1166
+ function translateLevel(level) {
1167
+ if (level === 0) {
1168
+ return false;
1169
+ }
1170
+ return {
1171
+ level,
1172
+ hasBasic: true,
1173
+ has256: level >= 2,
1174
+ has16m: level >= 3
1175
+ };
1176
+ }
1177
+ function supportsColor(haveStream, streamIsTTY) {
1178
+ if (forceColor === 0) {
1179
+ return 0;
1180
+ }
1181
+ if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) {
1182
+ return 3;
1183
+ }
1184
+ if (hasFlag("color=256")) {
1185
+ return 2;
1186
+ }
1187
+ if (haveStream && !streamIsTTY && forceColor === void 0) {
1188
+ return 0;
1189
+ }
1190
+ const min = forceColor || 0;
1191
+ if (env.TERM === "dumb") {
1192
+ return min;
1193
+ }
1194
+ if (process.platform === "win32") {
1195
+ const osRelease = os.release().split(".");
1196
+ if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
1197
+ return Number(osRelease[2]) >= 14931 ? 3 : 2;
1198
+ }
1199
+ return 1;
1200
+ }
1201
+ if ("CI" in env) {
1202
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE"].some((sign) => sign in env) || env.CI_NAME === "codeship") {
1203
+ return 1;
1204
+ }
1205
+ return min;
1206
+ }
1207
+ if ("TEAMCITY_VERSION" in env) {
1208
+ return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
1209
+ }
1210
+ if (env.COLORTERM === "truecolor") {
1211
+ return 3;
1212
+ }
1213
+ if ("TERM_PROGRAM" in env) {
1214
+ const version = parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
1215
+ switch (env.TERM_PROGRAM) {
1216
+ case "iTerm.app":
1217
+ return version >= 3 ? 3 : 2;
1218
+ case "Apple_Terminal":
1219
+ return 2;
1220
+ }
1221
+ }
1222
+ if (/-256(color)?$/i.test(env.TERM)) {
1223
+ return 2;
1224
+ }
1225
+ if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
1226
+ return 1;
1227
+ }
1228
+ if ("COLORTERM" in env) {
1229
+ return 1;
1230
+ }
1231
+ return min;
1232
+ }
1233
+ function getSupportLevel(stream) {
1234
+ const level = supportsColor(stream, stream && stream.isTTY);
1235
+ return translateLevel(level);
1236
+ }
1237
+ module2.exports = {
1238
+ supportsColor: getSupportLevel,
1239
+ stdout: translateLevel(supportsColor(true, tty.isatty(1))),
1240
+ stderr: translateLevel(supportsColor(true, tty.isatty(2)))
1241
+ };
1242
+ }
1243
+ });
1244
+
1245
+ // node_modules/chalk/source/util.js
1246
+ var require_util = __commonJS({
1247
+ "node_modules/chalk/source/util.js"(exports2, module2) {
1248
+ "use strict";
1249
+ var stringReplaceAll = (string, substring, replacer) => {
1250
+ let index = string.indexOf(substring);
1251
+ if (index === -1) {
1252
+ return string;
1253
+ }
1254
+ const substringLength = substring.length;
1255
+ let endIndex = 0;
1256
+ let returnValue = "";
1257
+ do {
1258
+ returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
1259
+ endIndex = index + substringLength;
1260
+ index = string.indexOf(substring, endIndex);
1261
+ } while (index !== -1);
1262
+ returnValue += string.substr(endIndex);
1263
+ return returnValue;
1264
+ };
1265
+ var stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
1266
+ let endIndex = 0;
1267
+ let returnValue = "";
1268
+ do {
1269
+ const gotCR = string[index - 1] === "\r";
1270
+ returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? "\r\n" : "\n") + postfix;
1271
+ endIndex = index + 1;
1272
+ index = string.indexOf("\n", endIndex);
1273
+ } while (index !== -1);
1274
+ returnValue += string.substr(endIndex);
1275
+ return returnValue;
1276
+ };
1277
+ module2.exports = {
1278
+ stringReplaceAll,
1279
+ stringEncaseCRLFWithFirstIndex
1280
+ };
1281
+ }
1282
+ });
1283
+
1284
+ // node_modules/chalk/source/templates.js
1285
+ var require_templates = __commonJS({
1286
+ "node_modules/chalk/source/templates.js"(exports2, module2) {
1287
+ "use strict";
1288
+ var TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
1289
+ var STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
1290
+ var STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
1291
+ var ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
1292
+ var ESCAPES = /* @__PURE__ */ new Map([
1293
+ ["n", "\n"],
1294
+ ["r", "\r"],
1295
+ ["t", " "],
1296
+ ["b", "\b"],
1297
+ ["f", "\f"],
1298
+ ["v", "\v"],
1299
+ ["0", "\0"],
1300
+ ["\\", "\\"],
1301
+ ["e", "\x1B"],
1302
+ ["a", "\x07"]
1303
+ ]);
1304
+ function unescape(c) {
1305
+ const u = c[0] === "u";
1306
+ const bracket = c[1] === "{";
1307
+ if (u && !bracket && c.length === 5 || c[0] === "x" && c.length === 3) {
1308
+ return String.fromCharCode(parseInt(c.slice(1), 16));
1309
+ }
1310
+ if (u && bracket) {
1311
+ return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
1312
+ }
1313
+ return ESCAPES.get(c) || c;
1314
+ }
1315
+ function parseArguments(name, arguments_) {
1316
+ const results = [];
1317
+ const chunks = arguments_.trim().split(/\s*,\s*/g);
1318
+ let matches;
1319
+ for (const chunk of chunks) {
1320
+ const number = Number(chunk);
1321
+ if (!Number.isNaN(number)) {
1322
+ results.push(number);
1323
+ } else if (matches = chunk.match(STRING_REGEX)) {
1324
+ results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
1325
+ } else {
1326
+ throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
1327
+ }
1328
+ }
1329
+ return results;
1330
+ }
1331
+ function parseStyle(style) {
1332
+ STYLE_REGEX.lastIndex = 0;
1333
+ const results = [];
1334
+ let matches;
1335
+ while ((matches = STYLE_REGEX.exec(style)) !== null) {
1336
+ const name = matches[1];
1337
+ if (matches[2]) {
1338
+ const args = parseArguments(name, matches[2]);
1339
+ results.push([name].concat(args));
1340
+ } else {
1341
+ results.push([name]);
1342
+ }
1343
+ }
1344
+ return results;
1345
+ }
1346
+ function buildStyle(chalk4, styles) {
1347
+ const enabled = {};
1348
+ for (const layer of styles) {
1349
+ for (const style of layer.styles) {
1350
+ enabled[style[0]] = layer.inverse ? null : style.slice(1);
1351
+ }
1352
+ }
1353
+ let current = chalk4;
1354
+ for (const [styleName, styles2] of Object.entries(enabled)) {
1355
+ if (!Array.isArray(styles2)) {
1356
+ continue;
1357
+ }
1358
+ if (!(styleName in current)) {
1359
+ throw new Error(`Unknown Chalk style: ${styleName}`);
1360
+ }
1361
+ current = styles2.length > 0 ? current[styleName](...styles2) : current[styleName];
1362
+ }
1363
+ return current;
1364
+ }
1365
+ module2.exports = (chalk4, temporary) => {
1366
+ const styles = [];
1367
+ const chunks = [];
1368
+ let chunk = [];
1369
+ temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
1370
+ if (escapeCharacter) {
1371
+ chunk.push(unescape(escapeCharacter));
1372
+ } else if (style) {
1373
+ const string = chunk.join("");
1374
+ chunk = [];
1375
+ chunks.push(styles.length === 0 ? string : buildStyle(chalk4, styles)(string));
1376
+ styles.push({ inverse, styles: parseStyle(style) });
1377
+ } else if (close) {
1378
+ if (styles.length === 0) {
1379
+ throw new Error("Found extraneous } in Chalk template literal");
1380
+ }
1381
+ chunks.push(buildStyle(chalk4, styles)(chunk.join("")));
1382
+ chunk = [];
1383
+ styles.pop();
1384
+ } else {
1385
+ chunk.push(character);
1386
+ }
1387
+ });
1388
+ chunks.push(chunk.join(""));
1389
+ if (styles.length > 0) {
1390
+ const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? "" : "s"} (\`}\`)`;
1391
+ throw new Error(errMessage);
1392
+ }
1393
+ return chunks.join("");
1394
+ };
1395
+ }
1396
+ });
1397
+
1398
+ // node_modules/chalk/source/index.js
1399
+ var require_source = __commonJS({
1400
+ "node_modules/chalk/source/index.js"(exports2, module2) {
1401
+ "use strict";
1402
+ var ansiStyles = require_ansi_styles();
1403
+ var { stdout: stdoutColor, stderr: stderrColor } = require_supports_color();
1404
+ var {
1405
+ stringReplaceAll,
1406
+ stringEncaseCRLFWithFirstIndex
1407
+ } = require_util();
1408
+ var { isArray } = Array;
1409
+ var levelMapping = [
1410
+ "ansi",
1411
+ "ansi",
1412
+ "ansi256",
1413
+ "ansi16m"
1414
+ ];
1415
+ var styles = /* @__PURE__ */ Object.create(null);
1416
+ var applyOptions = (object, options = {}) => {
1417
+ if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
1418
+ throw new Error("The `level` option should be an integer from 0 to 3");
1419
+ }
1420
+ const colorLevel = stdoutColor ? stdoutColor.level : 0;
1421
+ object.level = options.level === void 0 ? colorLevel : options.level;
1422
+ };
1423
+ var ChalkClass = class {
1424
+ constructor(options) {
1425
+ return chalkFactory(options);
1426
+ }
1427
+ };
1428
+ var chalkFactory = (options) => {
1429
+ const chalk5 = {};
1430
+ applyOptions(chalk5, options);
1431
+ chalk5.template = (...arguments_) => chalkTag(chalk5.template, ...arguments_);
1432
+ Object.setPrototypeOf(chalk5, Chalk.prototype);
1433
+ Object.setPrototypeOf(chalk5.template, chalk5);
1434
+ chalk5.template.constructor = () => {
1435
+ throw new Error("`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.");
1436
+ };
1437
+ chalk5.template.Instance = ChalkClass;
1438
+ return chalk5.template;
1439
+ };
1440
+ function Chalk(options) {
1441
+ return chalkFactory(options);
1442
+ }
1443
+ for (const [styleName, style] of Object.entries(ansiStyles)) {
1444
+ styles[styleName] = {
1445
+ get() {
1446
+ const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
1447
+ Object.defineProperty(this, styleName, { value: builder });
1448
+ return builder;
1449
+ }
1450
+ };
1451
+ }
1452
+ styles.visible = {
1453
+ get() {
1454
+ const builder = createBuilder(this, this._styler, true);
1455
+ Object.defineProperty(this, "visible", { value: builder });
1456
+ return builder;
1457
+ }
1458
+ };
1459
+ var usedModels = ["rgb", "hex", "keyword", "hsl", "hsv", "hwb", "ansi", "ansi256"];
1460
+ for (const model of usedModels) {
1461
+ styles[model] = {
1462
+ get() {
1463
+ const { level } = this;
1464
+ return function(...arguments_) {
1465
+ const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
1466
+ return createBuilder(this, styler, this._isEmpty);
1467
+ };
1468
+ }
1469
+ };
1470
+ }
1471
+ for (const model of usedModels) {
1472
+ const bgModel = "bg" + model[0].toUpperCase() + model.slice(1);
1473
+ styles[bgModel] = {
1474
+ get() {
1475
+ const { level } = this;
1476
+ return function(...arguments_) {
1477
+ const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
1478
+ return createBuilder(this, styler, this._isEmpty);
1479
+ };
1480
+ }
1481
+ };
1482
+ }
1483
+ var proto = Object.defineProperties(() => {
1484
+ }, {
1485
+ ...styles,
1486
+ level: {
1487
+ enumerable: true,
1488
+ get() {
1489
+ return this._generator.level;
1490
+ },
1491
+ set(level) {
1492
+ this._generator.level = level;
1493
+ }
1494
+ }
1495
+ });
1496
+ var createStyler = (open, close, parent) => {
1497
+ let openAll;
1498
+ let closeAll;
1499
+ if (parent === void 0) {
1500
+ openAll = open;
1501
+ closeAll = close;
1502
+ } else {
1503
+ openAll = parent.openAll + open;
1504
+ closeAll = close + parent.closeAll;
1505
+ }
1506
+ return {
1507
+ open,
1508
+ close,
1509
+ openAll,
1510
+ closeAll,
1511
+ parent
1512
+ };
1513
+ };
1514
+ var createBuilder = (self, _styler, _isEmpty) => {
1515
+ const builder = (...arguments_) => {
1516
+ if (isArray(arguments_[0]) && isArray(arguments_[0].raw)) {
1517
+ return applyStyle(builder, chalkTag(builder, ...arguments_));
1518
+ }
1519
+ return applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" "));
1520
+ };
1521
+ Object.setPrototypeOf(builder, proto);
1522
+ builder._generator = self;
1523
+ builder._styler = _styler;
1524
+ builder._isEmpty = _isEmpty;
1525
+ return builder;
1526
+ };
1527
+ var applyStyle = (self, string) => {
1528
+ if (self.level <= 0 || !string) {
1529
+ return self._isEmpty ? "" : string;
1530
+ }
1531
+ let styler = self._styler;
1532
+ if (styler === void 0) {
1533
+ return string;
1534
+ }
1535
+ const { openAll, closeAll } = styler;
1536
+ if (string.indexOf("\x1B") !== -1) {
1537
+ while (styler !== void 0) {
1538
+ string = stringReplaceAll(string, styler.close, styler.open);
1539
+ styler = styler.parent;
1540
+ }
1541
+ }
1542
+ const lfIndex = string.indexOf("\n");
1543
+ if (lfIndex !== -1) {
1544
+ string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
1545
+ }
1546
+ return openAll + string + closeAll;
1547
+ };
1548
+ var template;
1549
+ var chalkTag = (chalk5, ...strings) => {
1550
+ const [firstString] = strings;
1551
+ if (!isArray(firstString) || !isArray(firstString.raw)) {
1552
+ return strings.join(" ");
1553
+ }
1554
+ const arguments_ = strings.slice(1);
1555
+ const parts = [firstString.raw[0]];
1556
+ for (let i = 1; i < firstString.length; i++) {
1557
+ parts.push(
1558
+ String(arguments_[i - 1]).replace(/[{}\\]/g, "\\$&"),
1559
+ String(firstString.raw[i])
1560
+ );
1561
+ }
1562
+ if (template === void 0) {
1563
+ template = require_templates();
1564
+ }
1565
+ return template(chalk5, parts.join(""));
1566
+ };
1567
+ Object.defineProperties(Chalk.prototype, styles);
1568
+ var chalk4 = Chalk();
1569
+ chalk4.supportsColor = stdoutColor;
1570
+ chalk4.stderr = Chalk({ level: stderrColor ? stderrColor.level : 0 });
1571
+ chalk4.stderr.supportsColor = stderrColor;
1572
+ module2.exports = chalk4;
1573
+ }
1574
+ });
1575
+
1576
+ // cli/src/main.ts
1577
+ var import_chalk3 = __toESM(require_source());
1578
+
1579
+ // cli/src/check.ts
1580
+ var import_node_fs = __toESM(require("node:fs"));
1581
+ var import_node_path = __toESM(require("node:path"));
1582
+ var import_chalk = __toESM(require_source());
1583
+ function loadParser() {
1584
+ let Parser2;
1585
+ try {
1586
+ Parser2 = require("tree-sitter");
1587
+ } catch {
1588
+ console.error(
1589
+ import_chalk.default.red("Error: tree-sitter is not installed.\n") + "Install it with: npm install tree-sitter"
1590
+ );
1591
+ process.exit(1);
1592
+ }
1593
+ let language;
1594
+ try {
1595
+ language = require(import_node_path.default.resolve(__dirname, "..", ".."));
1596
+ } catch {
1597
+ console.error(
1598
+ import_chalk.default.red("Error: could not load tree-sitter-htmlmustache bindings.\n") + 'Run "npm install" in the tree-sitter-htmlmustache root first.'
1599
+ );
1600
+ process.exit(1);
1601
+ }
1602
+ const parser2 = new Parser2();
1603
+ parser2.setLanguage(language);
1604
+ return parser2;
1605
+ }
1606
+ function errorMessageForNode(nodeType, node) {
1607
+ if (nodeType === "mustache_erroneous_section_end" || nodeType === "mustache_erroneous_inverted_section_end") {
1608
+ const tagNameNode = node.children.find((c) => c.type === "mustache_erroneous_tag_name");
1609
+ return `Mismatched mustache section: {{/${tagNameNode?.text || "?"}}}`;
1610
+ }
1611
+ if (nodeType === "html_erroneous_end_tag") {
1612
+ const tagNameNode = node.children.find((c) => c.type === "html_erroneous_end_tag_name");
1613
+ return `Mismatched HTML end tag: </${tagNameNode?.text || "?"}>`;
1614
+ }
1615
+ if (nodeType === "ERROR") {
1616
+ return "Syntax error";
1617
+ }
1618
+ return `Missing ${nodeType}`;
1619
+ }
1620
+ var ERROR_NODE_TYPES = /* @__PURE__ */ new Set([
1621
+ "ERROR",
1622
+ "mustache_erroneous_section_end",
1623
+ "mustache_erroneous_inverted_section_end",
1624
+ "html_erroneous_end_tag"
1625
+ ]);
1626
+ function collectErrors(tree, file) {
1627
+ const errors = [];
1628
+ const cursor = tree.walk();
1629
+ function visit() {
1630
+ const node = cursor.currentNode;
1631
+ const nodeType = cursor.nodeType;
1632
+ if (ERROR_NODE_TYPES.has(nodeType) || cursor.nodeIsMissing) {
1633
+ errors.push({
1634
+ file,
1635
+ line: node.startPosition.row + 1,
1636
+ column: node.startPosition.column + 1,
1637
+ endLine: node.endPosition.row + 1,
1638
+ endColumn: node.endPosition.column + 1,
1639
+ message: errorMessageForNode(nodeType, node),
1640
+ nodeText: node.text
1641
+ });
1642
+ if (nodeType === "ERROR") return;
1643
+ }
1644
+ if (cursor.gotoFirstChild()) {
1645
+ do {
1646
+ visit();
1647
+ } while (cursor.gotoNextSibling());
1648
+ cursor.gotoParent();
1649
+ }
1650
+ }
1651
+ visit();
1652
+ return errors;
1653
+ }
1654
+ function formatError(error, source) {
1655
+ const lines = source.split("\n");
1656
+ const errorLine = error.line - 1;
1657
+ const header = import_chalk.default.bold(`${error.file}:${error.line}:${error.column}`) + " " + import_chalk.default.red("error") + ": " + error.message;
1658
+ const contextStart = Math.max(0, errorLine - 2);
1659
+ const contextEnd = Math.min(lines.length - 1, error.endLine - 1);
1660
+ const gutterWidth = String(contextEnd + 1).length;
1661
+ const pad = (n) => String(n).padStart(gutterWidth);
1662
+ const outputLines = [header];
1663
+ outputLines.push(import_chalk.default.dim(" ".repeat(gutterWidth) + " |"));
1664
+ for (let i = contextStart; i <= contextEnd; i++) {
1665
+ const lineNum = i + 1;
1666
+ outputLines.push(import_chalk.default.dim(`${pad(lineNum)} |`) + " " + lines[i]);
1667
+ }
1668
+ const lastErrorLineIdx = error.endLine - 1;
1669
+ const lastLine = lines[lastErrorLineIdx] || "";
1670
+ let underlineStart;
1671
+ let underlineEnd;
1672
+ if (error.line === error.endLine) {
1673
+ underlineStart = error.column - 1;
1674
+ underlineEnd = error.endColumn - 1;
1675
+ } else {
1676
+ underlineStart = 0;
1677
+ underlineEnd = lastLine.length;
1678
+ }
1679
+ const underlineLength = Math.max(1, underlineEnd - underlineStart);
1680
+ const underline = " ".repeat(underlineStart) + "^".repeat(underlineLength) + " " + error.message;
1681
+ outputLines.push(import_chalk.default.dim(" ".repeat(gutterWidth) + " |") + " " + import_chalk.default.red(underline));
1682
+ return outputLines.join("\n");
1683
+ }
1684
+ function formatSummary(totalErrors, filesWithErrors, totalFiles) {
1685
+ if (totalErrors === 0) {
1686
+ return import_chalk.default.green(`No errors found (${totalFiles} ${totalFiles === 1 ? "file" : "files"} checked)`);
1687
+ }
1688
+ const errStr = totalErrors === 1 ? "error" : "errors";
1689
+ const errFileStr = filesWithErrors === 1 ? "file" : "files";
1690
+ const totalStr = totalFiles === 1 ? "file" : "files";
1691
+ return import_chalk.default.red(`${totalErrors} ${errStr} in ${filesWithErrors} ${errFileStr}`) + ` (${totalFiles} ${totalStr} checked)`;
1692
+ }
1693
+ function expandGlobs(patterns) {
1694
+ const files = /* @__PURE__ */ new Set();
1695
+ const cwd = process.cwd();
1696
+ for (const pattern of patterns) {
1697
+ if (!pattern.includes("*") && !pattern.includes("?")) {
1698
+ const resolved = import_node_path.default.resolve(cwd, pattern);
1699
+ if (import_node_fs.default.existsSync(resolved)) {
1700
+ files.add(resolved);
1701
+ }
1702
+ } else {
1703
+ for (const match of import_node_fs.default.globSync(pattern, { cwd })) {
1704
+ files.add(import_node_path.default.resolve(cwd, match));
1705
+ }
1706
+ }
1707
+ }
1708
+ return [...files].sort();
1709
+ }
1710
+ var USAGE = `Usage: htmlmustache check <patterns...>
1711
+
1712
+ Check HTML Mustache templates for errors.
1713
+
1714
+ Arguments:
1715
+ patterns One or more glob patterns (e.g. '**/*.mustache' '**/*.hbs')
1716
+
1717
+ Options:
1718
+ --help Show this help message
1719
+
1720
+ Examples:
1721
+ htmlmustache check '**/*.mustache'
1722
+ htmlmustache check 'templates/**/*.hbs' 'partials/**/*.mustache'`;
1723
+ function run(args) {
1724
+ if (args[0] === "check") {
1725
+ args = args.slice(1);
1726
+ }
1727
+ if (args.includes("--help") || args.length === 0) {
1728
+ console.log(USAGE);
1729
+ return args.includes("--help") ? 0 : 1;
1730
+ }
1731
+ const files = expandGlobs(args);
1732
+ if (files.length === 0) {
1733
+ console.error(import_chalk.default.yellow("No files matched the given patterns:"));
1734
+ for (const arg of args) {
1735
+ console.error(import_chalk.default.yellow(` ${arg}`));
1736
+ }
1737
+ return 1;
1738
+ }
1739
+ const parser2 = loadParser();
1740
+ let totalErrors = 0;
1741
+ let filesWithErrors = 0;
1742
+ const cwd = process.cwd();
1743
+ const errorOutput = [];
1744
+ for (const file of files) {
1745
+ const displayPath = import_node_path.default.relative(cwd, file) || file;
1746
+ const source = import_node_fs.default.readFileSync(file, "utf-8");
1747
+ const tree = parser2.parse(source);
1748
+ const errors = collectErrors(tree, displayPath);
1749
+ if (errors.length > 0) {
1750
+ filesWithErrors++;
1751
+ totalErrors += errors.length;
1752
+ for (const error of errors) {
1753
+ errorOutput.push(formatError(error, source));
1754
+ }
1755
+ }
1756
+ console.log(errors.length > 0 ? import_chalk.default.red(displayPath) : import_chalk.default.dim(displayPath));
1757
+ }
1758
+ if (errorOutput.length > 0) {
1759
+ console.log();
1760
+ for (const output of errorOutput) {
1761
+ console.log(output);
1762
+ console.log();
1763
+ }
1764
+ }
1765
+ console.log(formatSummary(totalErrors, filesWithErrors, files.length));
1766
+ return totalErrors > 0 ? 1 : 0;
1767
+ }
1768
+
1769
+ // cli/src/format.ts
1770
+ var import_node_fs2 = __toESM(require("node:fs"));
1771
+ var import_node_path2 = __toESM(require("node:path"));
1772
+ var import_node_url = require("node:url");
1773
+ var import_chalk2 = __toESM(require_source());
1774
+
1775
+ // node_modules/vscode-languageserver-textdocument/lib/esm/main.js
1776
+ var FullTextDocument = class _FullTextDocument {
1777
+ constructor(uri, languageId, version, content) {
1778
+ this._uri = uri;
1779
+ this._languageId = languageId;
1780
+ this._version = version;
1781
+ this._content = content;
1782
+ this._lineOffsets = void 0;
1783
+ }
1784
+ get uri() {
1785
+ return this._uri;
1786
+ }
1787
+ get languageId() {
1788
+ return this._languageId;
1789
+ }
1790
+ get version() {
1791
+ return this._version;
1792
+ }
1793
+ getText(range) {
1794
+ if (range) {
1795
+ const start = this.offsetAt(range.start);
1796
+ const end = this.offsetAt(range.end);
1797
+ return this._content.substring(start, end);
1798
+ }
1799
+ return this._content;
1800
+ }
1801
+ update(changes, version) {
1802
+ for (const change of changes) {
1803
+ if (_FullTextDocument.isIncremental(change)) {
1804
+ const range = getWellformedRange(change.range);
1805
+ const startOffset = this.offsetAt(range.start);
1806
+ const endOffset = this.offsetAt(range.end);
1807
+ this._content = this._content.substring(0, startOffset) + change.text + this._content.substring(endOffset, this._content.length);
1808
+ const startLine = Math.max(range.start.line, 0);
1809
+ const endLine = Math.max(range.end.line, 0);
1810
+ let lineOffsets = this._lineOffsets;
1811
+ const addedLineOffsets = computeLineOffsets(change.text, false, startOffset);
1812
+ if (endLine - startLine === addedLineOffsets.length) {
1813
+ for (let i = 0, len = addedLineOffsets.length; i < len; i++) {
1814
+ lineOffsets[i + startLine + 1] = addedLineOffsets[i];
1815
+ }
1816
+ } else {
1817
+ if (addedLineOffsets.length < 1e4) {
1818
+ lineOffsets.splice(startLine + 1, endLine - startLine, ...addedLineOffsets);
1819
+ } else {
1820
+ this._lineOffsets = lineOffsets = lineOffsets.slice(0, startLine + 1).concat(addedLineOffsets, lineOffsets.slice(endLine + 1));
1821
+ }
1822
+ }
1823
+ const diff = change.text.length - (endOffset - startOffset);
1824
+ if (diff !== 0) {
1825
+ for (let i = startLine + 1 + addedLineOffsets.length, len = lineOffsets.length; i < len; i++) {
1826
+ lineOffsets[i] = lineOffsets[i] + diff;
1827
+ }
1828
+ }
1829
+ } else if (_FullTextDocument.isFull(change)) {
1830
+ this._content = change.text;
1831
+ this._lineOffsets = void 0;
1832
+ } else {
1833
+ throw new Error("Unknown change event received");
1834
+ }
1835
+ }
1836
+ this._version = version;
1837
+ }
1838
+ getLineOffsets() {
1839
+ if (this._lineOffsets === void 0) {
1840
+ this._lineOffsets = computeLineOffsets(this._content, true);
1841
+ }
1842
+ return this._lineOffsets;
1843
+ }
1844
+ positionAt(offset) {
1845
+ offset = Math.max(Math.min(offset, this._content.length), 0);
1846
+ const lineOffsets = this.getLineOffsets();
1847
+ let low = 0, high = lineOffsets.length;
1848
+ if (high === 0) {
1849
+ return { line: 0, character: offset };
1850
+ }
1851
+ while (low < high) {
1852
+ const mid = Math.floor((low + high) / 2);
1853
+ if (lineOffsets[mid] > offset) {
1854
+ high = mid;
1855
+ } else {
1856
+ low = mid + 1;
1857
+ }
1858
+ }
1859
+ const line2 = low - 1;
1860
+ offset = this.ensureBeforeEOL(offset, lineOffsets[line2]);
1861
+ return { line: line2, character: offset - lineOffsets[line2] };
1862
+ }
1863
+ offsetAt(position) {
1864
+ const lineOffsets = this.getLineOffsets();
1865
+ if (position.line >= lineOffsets.length) {
1866
+ return this._content.length;
1867
+ } else if (position.line < 0) {
1868
+ return 0;
1869
+ }
1870
+ const lineOffset = lineOffsets[position.line];
1871
+ if (position.character <= 0) {
1872
+ return lineOffset;
1873
+ }
1874
+ const nextLineOffset = position.line + 1 < lineOffsets.length ? lineOffsets[position.line + 1] : this._content.length;
1875
+ const offset = Math.min(lineOffset + position.character, nextLineOffset);
1876
+ return this.ensureBeforeEOL(offset, lineOffset);
1877
+ }
1878
+ ensureBeforeEOL(offset, lineOffset) {
1879
+ while (offset > lineOffset && isEOL(this._content.charCodeAt(offset - 1))) {
1880
+ offset--;
1881
+ }
1882
+ return offset;
1883
+ }
1884
+ get lineCount() {
1885
+ return this.getLineOffsets().length;
1886
+ }
1887
+ static isIncremental(event) {
1888
+ const candidate = event;
1889
+ return candidate !== void 0 && candidate !== null && typeof candidate.text === "string" && candidate.range !== void 0 && (candidate.rangeLength === void 0 || typeof candidate.rangeLength === "number");
1890
+ }
1891
+ static isFull(event) {
1892
+ const candidate = event;
1893
+ return candidate !== void 0 && candidate !== null && typeof candidate.text === "string" && candidate.range === void 0 && candidate.rangeLength === void 0;
1894
+ }
1895
+ };
1896
+ var TextDocument;
1897
+ (function(TextDocument2) {
1898
+ function create(uri, languageId, version, content) {
1899
+ return new FullTextDocument(uri, languageId, version, content);
1900
+ }
1901
+ TextDocument2.create = create;
1902
+ function update(document, changes, version) {
1903
+ if (document instanceof FullTextDocument) {
1904
+ document.update(changes, version);
1905
+ return document;
1906
+ } else {
1907
+ throw new Error("TextDocument.update: document must be created by TextDocument.create");
1908
+ }
1909
+ }
1910
+ TextDocument2.update = update;
1911
+ function applyEdits(document, edits) {
1912
+ const text2 = document.getText();
1913
+ const sortedEdits = mergeSort(edits.map(getWellformedEdit), (a, b) => {
1914
+ const diff = a.range.start.line - b.range.start.line;
1915
+ if (diff === 0) {
1916
+ return a.range.start.character - b.range.start.character;
1917
+ }
1918
+ return diff;
1919
+ });
1920
+ let lastModifiedOffset = 0;
1921
+ const spans = [];
1922
+ for (const e of sortedEdits) {
1923
+ const startOffset = document.offsetAt(e.range.start);
1924
+ if (startOffset < lastModifiedOffset) {
1925
+ throw new Error("Overlapping edit");
1926
+ } else if (startOffset > lastModifiedOffset) {
1927
+ spans.push(text2.substring(lastModifiedOffset, startOffset));
1928
+ }
1929
+ if (e.newText.length) {
1930
+ spans.push(e.newText);
1931
+ }
1932
+ lastModifiedOffset = document.offsetAt(e.range.end);
1933
+ }
1934
+ spans.push(text2.substr(lastModifiedOffset));
1935
+ return spans.join("");
1936
+ }
1937
+ TextDocument2.applyEdits = applyEdits;
1938
+ })(TextDocument || (TextDocument = {}));
1939
+ function mergeSort(data, compare) {
1940
+ if (data.length <= 1) {
1941
+ return data;
1942
+ }
1943
+ const p = data.length / 2 | 0;
1944
+ const left = data.slice(0, p);
1945
+ const right = data.slice(p);
1946
+ mergeSort(left, compare);
1947
+ mergeSort(right, compare);
1948
+ let leftIdx = 0;
1949
+ let rightIdx = 0;
1950
+ let i = 0;
1951
+ while (leftIdx < left.length && rightIdx < right.length) {
1952
+ const ret = compare(left[leftIdx], right[rightIdx]);
1953
+ if (ret <= 0) {
1954
+ data[i++] = left[leftIdx++];
1955
+ } else {
1956
+ data[i++] = right[rightIdx++];
1957
+ }
1958
+ }
1959
+ while (leftIdx < left.length) {
1960
+ data[i++] = left[leftIdx++];
1961
+ }
1962
+ while (rightIdx < right.length) {
1963
+ data[i++] = right[rightIdx++];
1964
+ }
1965
+ return data;
1966
+ }
1967
+ function computeLineOffsets(text2, isAtLineStart, textOffset = 0) {
1968
+ const result = isAtLineStart ? [textOffset] : [];
1969
+ for (let i = 0; i < text2.length; i++) {
1970
+ const ch = text2.charCodeAt(i);
1971
+ if (isEOL(ch)) {
1972
+ if (ch === 13 && i + 1 < text2.length && text2.charCodeAt(i + 1) === 10) {
1973
+ i++;
1974
+ }
1975
+ result.push(textOffset + i + 1);
1976
+ }
1977
+ }
1978
+ return result;
1979
+ }
1980
+ function isEOL(char) {
1981
+ return char === 13 || char === 10;
1982
+ }
1983
+ function getWellformedRange(range) {
1984
+ const start = range.start;
1985
+ const end = range.end;
1986
+ if (start.line > end.line || start.line === end.line && start.character > end.character) {
1987
+ return { start: end, end: start };
1988
+ }
1989
+ return range;
1990
+ }
1991
+ function getWellformedEdit(textEdit) {
1992
+ const range = getWellformedRange(textEdit.range);
1993
+ if (range !== textEdit.range) {
1994
+ return { newText: textEdit.newText, range };
1995
+ }
1996
+ return textEdit;
1997
+ }
1998
+
1999
+ // lsp/server/src/formatting/printer.ts
2000
+ function print(doc, options) {
2001
+ const output = [];
2002
+ const state = { indentLevel: 0, mode: "break" };
2003
+ printDoc(doc, state, output, options);
2004
+ return output.join("");
2005
+ }
2006
+ function currentColumn(output) {
2007
+ let col = 0;
2008
+ for (let i = output.length - 1; i >= 0; i--) {
2009
+ const chunk = output[i];
2010
+ const nlIndex = chunk.lastIndexOf("\n");
2011
+ if (nlIndex !== -1) {
2012
+ col += chunk.length - nlIndex - 1;
2013
+ return col;
2014
+ }
2015
+ col += chunk.length;
2016
+ }
2017
+ return col;
2018
+ }
2019
+ function containsBreakParent(doc) {
2020
+ if (typeof doc === "string") return false;
2021
+ switch (doc.type) {
2022
+ case "breakParent":
2023
+ return true;
2024
+ case "concat":
2025
+ return doc.parts.some(containsBreakParent);
2026
+ case "indent":
2027
+ return containsBreakParent(doc.contents);
2028
+ case "group":
2029
+ return containsBreakParent(doc.contents);
2030
+ case "fill":
2031
+ return doc.parts.some(containsBreakParent);
2032
+ case "ifBreak":
2033
+ return containsBreakParent(doc.breakContents) || containsBreakParent(doc.flatContents);
2034
+ default:
2035
+ return false;
2036
+ }
2037
+ }
2038
+ function printDoc(doc, state, output, options) {
2039
+ if (typeof doc === "string") {
2040
+ output.push(doc);
2041
+ return;
2042
+ }
2043
+ switch (doc.type) {
2044
+ case "concat":
2045
+ for (const part of doc.parts) {
2046
+ printDoc(part, state, output, options);
2047
+ }
2048
+ break;
2049
+ case "indent":
2050
+ state.indentLevel++;
2051
+ printDoc(doc.contents, state, output, options);
2052
+ state.indentLevel--;
2053
+ break;
2054
+ case "hardline":
2055
+ output.push("\n");
2056
+ output.push(makeIndent(state.indentLevel, options));
2057
+ break;
2058
+ case "softline":
2059
+ if (state.mode === "break") {
2060
+ output.push("\n");
2061
+ output.push(makeIndent(state.indentLevel, options));
2062
+ }
2063
+ break;
2064
+ case "line":
2065
+ if (state.mode === "break") {
2066
+ output.push("\n");
2067
+ output.push(makeIndent(state.indentLevel, options));
2068
+ } else {
2069
+ output.push(" ");
2070
+ }
2071
+ break;
2072
+ case "group": {
2073
+ if (doc.break || containsBreakParent(doc.contents)) {
2074
+ const prevMode = state.mode;
2075
+ state.mode = "break";
2076
+ printDoc(doc.contents, state, output, options);
2077
+ state.mode = prevMode;
2078
+ } else {
2079
+ const flatOutput = [];
2080
+ const flatState = { ...state, mode: "flat" };
2081
+ printDoc(doc.contents, flatState, flatOutput, options);
2082
+ const flatContent = flatOutput.join("");
2083
+ const printWidth = options.printWidth ?? 80;
2084
+ const col = currentColumn(output);
2085
+ if (!flatContent.includes("\n") && col + flatContent.length <= printWidth) {
2086
+ output.push(flatContent);
2087
+ } else {
2088
+ const prevMode = state.mode;
2089
+ state.mode = "break";
2090
+ printDoc(doc.contents, state, output, options);
2091
+ state.mode = prevMode;
2092
+ }
2093
+ }
2094
+ break;
2095
+ }
2096
+ case "fill":
2097
+ printFill(doc.parts, state, output, options);
2098
+ break;
2099
+ case "ifBreak":
2100
+ if (state.mode === "break") {
2101
+ printDoc(doc.breakContents, state, output, options);
2102
+ } else {
2103
+ printDoc(doc.flatContents, state, output, options);
2104
+ }
2105
+ break;
2106
+ case "breakParent":
2107
+ state.mode = "break";
2108
+ break;
2109
+ }
2110
+ }
2111
+ function printFill(parts, state, output, options) {
2112
+ if (parts.length === 0) return;
2113
+ const printWidth = options.printWidth ?? 80;
2114
+ for (let i = 0; i < parts.length; i++) {
2115
+ const content = parts[i];
2116
+ const separator = i + 1 < parts.length ? parts[i + 1] : null;
2117
+ printDoc(content, state, output, options);
2118
+ if (separator === null) break;
2119
+ const nextContent = i + 2 < parts.length ? parts[i + 2] : null;
2120
+ if (nextContent !== null) {
2121
+ const testOutput = [];
2122
+ const flatState = { ...state, mode: "flat" };
2123
+ printDoc(separator, flatState, testOutput, options);
2124
+ printDoc(nextContent, flatState, testOutput, options);
2125
+ const testStr = testOutput.join("");
2126
+ const col = currentColumn(output);
2127
+ if (!testStr.includes("\n") && col + testStr.length <= printWidth) {
2128
+ const sepOutput = [];
2129
+ printDoc(separator, flatState, sepOutput, options);
2130
+ output.push(sepOutput.join(""));
2131
+ } else {
2132
+ printDoc(separator, { ...state, mode: "break" }, output, options);
2133
+ }
2134
+ } else {
2135
+ printDoc(separator, state, output, options);
2136
+ }
2137
+ i++;
2138
+ }
2139
+ }
2140
+ function makeIndent(level, options) {
2141
+ return options.indentUnit.repeat(level);
2142
+ }
2143
+
2144
+ // lsp/server/src/formatting/ir.ts
2145
+ var hardline = { type: "hardline" };
2146
+ var softline = { type: "softline" };
2147
+ var line = { type: "line" };
2148
+ var empty = "";
2149
+ function text(value) {
2150
+ return value;
2151
+ }
2152
+ function concat(parts) {
2153
+ const flattened = [];
2154
+ for (const part of parts) {
2155
+ if (part === "") continue;
2156
+ if (typeof part === "object" && part.type === "concat") {
2157
+ flattened.push(...part.parts);
2158
+ } else {
2159
+ flattened.push(part);
2160
+ }
2161
+ }
2162
+ if (flattened.length === 0) return "";
2163
+ if (flattened.length === 1) return flattened[0];
2164
+ return { type: "concat", parts: flattened };
2165
+ }
2166
+ function indent(contents) {
2167
+ if (contents === "") return "";
2168
+ return { type: "indent", contents };
2169
+ }
2170
+ function group(contents, shouldBreak = false) {
2171
+ if (contents === "") return "";
2172
+ return { type: "group", contents, break: shouldBreak || void 0 };
2173
+ }
2174
+ function ifBreak(breakContents, flatContents) {
2175
+ return { type: "ifBreak", breakContents, flatContents };
2176
+ }
2177
+ function fill(parts) {
2178
+ const filtered = parts.filter((p) => p !== "");
2179
+ if (filtered.length === 0) return "";
2180
+ if (filtered.length === 1) return filtered[0];
2181
+ return { type: "fill", parts: filtered };
2182
+ }
2183
+ function isLine(doc) {
2184
+ return typeof doc === "object" && doc.type === "line";
2185
+ }
2186
+
2187
+ // lsp/server/src/formatting/utils.ts
2188
+ function getTagName(node) {
2189
+ for (let i = 0; i < node.childCount; i++) {
2190
+ const child = node.child(i);
2191
+ if (!child) continue;
2192
+ if (child.type === "html_start_tag" || child.type === "html_self_closing_tag") {
2193
+ for (let j = 0; j < child.childCount; j++) {
2194
+ const tagChild = child.child(j);
2195
+ if (tagChild && tagChild.type === "html_tag_name") {
2196
+ return tagChild.text;
2197
+ }
2198
+ }
2199
+ }
2200
+ }
2201
+ return null;
2202
+ }
2203
+ function normalizeText(text2) {
2204
+ return text2.split("\n").map((line2) => line2.replace(/[ \t]+/g, " ").trim()).filter((line2, i, arr) => line2 || i > 0 && i < arr.length - 1).join("\n");
2205
+ }
2206
+ function getVisibleChildren(node) {
2207
+ const children = [];
2208
+ for (let i = 0; i < node.childCount; i++) {
2209
+ const child = node.child(i);
2210
+ if (child && !child.type.startsWith("_")) {
2211
+ children.push(child);
2212
+ }
2213
+ }
2214
+ return children;
2215
+ }
2216
+ function normalizeMustacheWhitespace(raw, addSpaces) {
2217
+ const space = addSpaces ? " " : "";
2218
+ const tripleMatch = raw.match(/^\{\{\{([\s\S]*)\}\}\}$/);
2219
+ if (tripleMatch) {
2220
+ const inner = tripleMatch[1].trim();
2221
+ return `{{{${space}${inner}${space}}}}`;
2222
+ }
2223
+ const prefixedMatch = raw.match(/^\{\{([#/^!>])([\s\S]*)\}\}$/);
2224
+ if (prefixedMatch) {
2225
+ const prefix = prefixedMatch[1];
2226
+ const inner = prefixedMatch[2];
2227
+ if (prefix === "!" && inner.includes("\n")) {
2228
+ const lines = inner.split("\n");
2229
+ const first = lines[0].trimStart();
2230
+ const last = lines[lines.length - 1].trimEnd();
2231
+ if (lines.length === 1) {
2232
+ return `{{${prefix}${space}${first}${space}}}`;
2233
+ }
2234
+ const middle = lines.slice(1, -1);
2235
+ return `{{${prefix}${space}${first}
2236
+ ${middle.join("\n")}
2237
+ ${last}${space}}}`;
2238
+ }
2239
+ const trimmed = inner.trim();
2240
+ return `{{${prefix}${space}${trimmed}${space}}}`;
2241
+ }
2242
+ const plainMatch = raw.match(/^\{\{([\s\S]*)\}\}$/);
2243
+ if (plainMatch) {
2244
+ const inner = plainMatch[1].trim();
2245
+ return `{{${space}${inner}${space}}}`;
2246
+ }
2247
+ return raw;
2248
+ }
2249
+ function normalizeMustacheWhitespaceAll(raw, addSpaces) {
2250
+ return raw.replace(/\{\{\{[\s\S]*?\}\}\}|\{\{[\s\S]*?\}\}/g, (match) => {
2251
+ return normalizeMustacheWhitespace(match, addSpaces);
2252
+ });
2253
+ }
2254
+
2255
+ // lsp/server/src/formatting/classifier.ts
2256
+ var customCodeTags = /* @__PURE__ */ new Set();
2257
+ function setCustomCodeTags(tags) {
2258
+ customCodeTags = new Set(tags.map((t) => t.toLowerCase()));
2259
+ }
2260
+ var CSS_DISPLAY_MAP = {
2261
+ // Block elements
2262
+ address: "block",
2263
+ article: "block",
2264
+ aside: "block",
2265
+ blockquote: "block",
2266
+ body: "block",
2267
+ center: "block",
2268
+ dd: "block",
2269
+ details: "block",
2270
+ dialog: "block",
2271
+ dir: "block",
2272
+ div: "block",
2273
+ dl: "block",
2274
+ dt: "block",
2275
+ fieldset: "block",
2276
+ figcaption: "block",
2277
+ figure: "block",
2278
+ footer: "block",
2279
+ form: "block",
2280
+ h1: "block",
2281
+ h2: "block",
2282
+ h3: "block",
2283
+ h4: "block",
2284
+ h5: "block",
2285
+ h6: "block",
2286
+ header: "block",
2287
+ hgroup: "block",
2288
+ hr: "block",
2289
+ html: "block",
2290
+ legend: "block",
2291
+ listing: "block",
2292
+ main: "block",
2293
+ menu: "block",
2294
+ nav: "block",
2295
+ ol: "block",
2296
+ p: "block",
2297
+ plaintext: "block",
2298
+ pre: "block",
2299
+ search: "block",
2300
+ section: "block",
2301
+ summary: "block",
2302
+ ul: "block",
2303
+ xmp: "block",
2304
+ // List items
2305
+ li: "list-item",
2306
+ // Table elements
2307
+ table: "table",
2308
+ caption: "table-caption",
2309
+ colgroup: "table-column-group",
2310
+ col: "table-column",
2311
+ thead: "table-header-group",
2312
+ tbody: "table-row-group",
2313
+ tfoot: "table-footer-group",
2314
+ tr: "table-row",
2315
+ td: "table-cell",
2316
+ th: "table-cell",
2317
+ // Inline-block elements
2318
+ button: "inline-block",
2319
+ img: "inline-block",
2320
+ input: "inline-block",
2321
+ select: "inline-block",
2322
+ textarea: "inline-block",
2323
+ video: "inline-block",
2324
+ audio: "inline-block",
2325
+ canvas: "inline-block",
2326
+ embed: "inline-block",
2327
+ iframe: "inline-block",
2328
+ object: "inline-block",
2329
+ // None
2330
+ head: "none",
2331
+ link: "none",
2332
+ meta: "none",
2333
+ script: "none",
2334
+ style: "none",
2335
+ title: "none",
2336
+ template: "none",
2337
+ // Ruby
2338
+ ruby: "ruby",
2339
+ rb: "ruby-base",
2340
+ rt: "ruby-text",
2341
+ rp: "none"
2342
+ };
2343
+ var PRESERVE_CONTENT_ELEMENTS = /* @__PURE__ */ new Set([
2344
+ "pre",
2345
+ "code",
2346
+ "textarea",
2347
+ "script",
2348
+ "style"
2349
+ ]);
2350
+ function getCSSDisplay(node) {
2351
+ const type = node.type;
2352
+ if (type === "html_element") {
2353
+ const tagName = getTagName(node);
2354
+ if (tagName) {
2355
+ if (customCodeTags.has(tagName.toLowerCase())) {
2356
+ return "block";
2357
+ }
2358
+ return CSS_DISPLAY_MAP[tagName.toLowerCase()] ?? "inline";
2359
+ }
2360
+ return "block";
2361
+ }
2362
+ if (type === "html_script_element" || type === "html_style_element" || type === "html_raw_element") {
2363
+ return "block";
2364
+ }
2365
+ if (type === "mustache_section" || type === "mustache_inverted_section") {
2366
+ return hasBlockContent(node) ? "block" : "inline";
2367
+ }
2368
+ return "inline";
2369
+ }
2370
+ function isWhitespaceInsensitive(display) {
2371
+ switch (display) {
2372
+ case "block":
2373
+ case "list-item":
2374
+ case "table":
2375
+ case "table-row":
2376
+ case "table-row-group":
2377
+ case "table-header-group":
2378
+ case "table-footer-group":
2379
+ case "table-column":
2380
+ case "table-column-group":
2381
+ case "table-caption":
2382
+ case "table-cell":
2383
+ case "none":
2384
+ return true;
2385
+ default:
2386
+ return false;
2387
+ }
2388
+ }
2389
+ function isBlockLevel(node) {
2390
+ const type = node.type;
2391
+ if (type === "mustache_section" || type === "mustache_inverted_section") {
2392
+ return hasBlockContent(node);
2393
+ }
2394
+ if (type === "html_element") {
2395
+ const display = getCSSDisplay(node);
2396
+ return isWhitespaceInsensitive(display);
2397
+ }
2398
+ if (type === "html_script_element" || type === "html_style_element" || type === "html_raw_element") {
2399
+ return true;
2400
+ }
2401
+ return false;
2402
+ }
2403
+ function shouldPreserveContent(node) {
2404
+ const type = node.type;
2405
+ if (type === "html_script_element" || type === "html_style_element" || type === "html_raw_element") {
2406
+ return true;
2407
+ }
2408
+ if (type === "html_element") {
2409
+ const tagName = getTagName(node);
2410
+ if (!tagName) return false;
2411
+ const lower = tagName.toLowerCase();
2412
+ return PRESERVE_CONTENT_ELEMENTS.has(lower) || customCodeTags.has(lower);
2413
+ }
2414
+ return false;
2415
+ }
2416
+ function hasBlockContent(sectionNode) {
2417
+ const contentNodes = getContentNodes(sectionNode);
2418
+ if (hasImplicitEndTags(contentNodes)) {
2419
+ return true;
2420
+ }
2421
+ for (const node of contentNodes) {
2422
+ if (isBlockLevelContent(node)) {
2423
+ return true;
2424
+ }
2425
+ }
2426
+ return false;
2427
+ }
2428
+ function isBlockLevelContent(node) {
2429
+ const type = node.type;
2430
+ if (type === "html_element") {
2431
+ return true;
2432
+ }
2433
+ if (type === "html_script_element" || type === "html_style_element" || type === "html_raw_element") {
2434
+ return true;
2435
+ }
2436
+ if (type === "mustache_section" || type === "mustache_inverted_section") {
2437
+ return hasBlockContent(node);
2438
+ }
2439
+ return false;
2440
+ }
2441
+ function getContentNodes(sectionNode) {
2442
+ const isInverted = sectionNode.type === "mustache_inverted_section";
2443
+ const beginType = isInverted ? "mustache_inverted_section_begin" : "mustache_section_begin";
2444
+ const endType = isInverted ? "mustache_inverted_section_end" : "mustache_section_end";
2445
+ const contentNodes = [];
2446
+ for (let i = 0; i < sectionNode.childCount; i++) {
2447
+ const child = sectionNode.child(i);
2448
+ if (!child) continue;
2449
+ if (child.type !== beginType && child.type !== endType && child.type !== "mustache_erroneous_section_end" && child.type !== "mustache_erroneous_inverted_section_end" && !child.type.startsWith("_")) {
2450
+ contentNodes.push(child);
2451
+ }
2452
+ }
2453
+ return contentNodes;
2454
+ }
2455
+ function hasImplicitEndTags(nodes) {
2456
+ for (const node of nodes) {
2457
+ if (hasImplicitEndTagsRecursive(node)) {
2458
+ return true;
2459
+ }
2460
+ }
2461
+ return false;
2462
+ }
2463
+ function hasImplicitEndTagsRecursive(node) {
2464
+ if (node.type === "html_element") {
2465
+ let hasStartTag = false;
2466
+ let hasEndTag = false;
2467
+ for (let i = 0; i < node.childCount; i++) {
2468
+ const child = node.child(i);
2469
+ if (!child) continue;
2470
+ if (child.type === "html_start_tag") hasStartTag = true;
2471
+ if (child.type === "html_end_tag") hasEndTag = true;
2472
+ if (child.type === "html_forced_end_tag") return true;
2473
+ }
2474
+ if (hasStartTag && !hasEndTag) return true;
2475
+ }
2476
+ for (let i = 0; i < node.childCount; i++) {
2477
+ const child = node.child(i);
2478
+ if (child && hasImplicitEndTagsRecursive(child)) {
2479
+ return true;
2480
+ }
2481
+ }
2482
+ return false;
2483
+ }
2484
+ function isInTextFlow(node, index, nodes) {
2485
+ if (index > 0) {
2486
+ const prev = nodes[index - 1];
2487
+ if (prev.type === "text" && prev.text.trim().length > 0) {
2488
+ return true;
2489
+ }
2490
+ }
2491
+ if (index < nodes.length - 1) {
2492
+ const next = nodes[index + 1];
2493
+ if (next.type === "text" && next.text.trim().length > 0) {
2494
+ return true;
2495
+ }
2496
+ }
2497
+ return false;
2498
+ }
2499
+ function shouldHtmlElementStayInline(node, index, nodes) {
2500
+ if (node.type !== "html_element") {
2501
+ return false;
2502
+ }
2503
+ if (isInTextFlow(node, index, nodes)) {
2504
+ return true;
2505
+ }
2506
+ if (index > 0) {
2507
+ const prev = nodes[index - 1];
2508
+ if (prev.type === "html_element" && isInTextFlow(prev, index - 1, nodes)) {
2509
+ return true;
2510
+ }
2511
+ }
2512
+ if (index < nodes.length - 1) {
2513
+ const next = nodes[index + 1];
2514
+ if (next.type === "html_element" && isInTextFlow(next, index + 1, nodes)) {
2515
+ return true;
2516
+ }
2517
+ }
2518
+ return false;
2519
+ }
2520
+ function shouldTreatAsBlock(node, index, nodes) {
2521
+ const isHtmlElement = node.type === "html_element" || node.type === "html_script_element" || node.type === "html_style_element" || node.type === "html_raw_element";
2522
+ const isMustacheSection = node.type === "mustache_section" || node.type === "mustache_inverted_section";
2523
+ return isHtmlElement && !shouldHtmlElementStayInline(node, index, nodes) || isMustacheSection && !isInTextFlow(node, index, nodes) || isBlockLevel(node) && !isInTextFlow(node, index, nodes);
2524
+ }
2525
+
2526
+ // lsp/server/src/customCodeTags.ts
2527
+ var VALID_INDENT_MODES = /* @__PURE__ */ new Set(["never", "always", "attribute"]);
2528
+ function parseCustomCodeTagSettings(tags) {
2529
+ const tagNames = [];
2530
+ const configs = [];
2531
+ for (const tag of tags) {
2532
+ if (tag && typeof tag === "object" && "name" in tag && typeof tag.name === "string") {
2533
+ const t = tag;
2534
+ const config = { name: t.name };
2535
+ if (typeof t.languageAttribute === "string") config.languageAttribute = t.languageAttribute;
2536
+ if (t.languageMap && typeof t.languageMap === "object") config.languageMap = t.languageMap;
2537
+ if (typeof t.languageDefault === "string") config.languageDefault = t.languageDefault;
2538
+ if (typeof t.indent === "string" && VALID_INDENT_MODES.has(t.indent)) {
2539
+ config.indent = t.indent;
2540
+ }
2541
+ if (typeof t.indentAttribute === "string") config.indentAttribute = t.indentAttribute;
2542
+ tagNames.push(config.name);
2543
+ configs.push(config);
2544
+ }
2545
+ }
2546
+ return { tagNames, configs };
2547
+ }
2548
+ function getAttributeValue(node, attrName) {
2549
+ for (let i = 0; i < node.childCount; i++) {
2550
+ const child = node.child(i);
2551
+ if (child?.type === "html_start_tag") {
2552
+ for (let j = 0; j < child.childCount; j++) {
2553
+ const attr = child.child(j);
2554
+ if (attr?.type === "html_attribute") {
2555
+ let name = "";
2556
+ let value = "";
2557
+ for (let k = 0; k < attr.childCount; k++) {
2558
+ const part = attr.child(k);
2559
+ if (part?.type === "html_attribute_name") name = part.text.toLowerCase();
2560
+ if (part?.type === "html_quoted_attribute_value") value = part.text.replace(/^["']|["']$/g, "");
2561
+ if (part?.type === "html_attribute_value") value = part.text;
2562
+ }
2563
+ if (name === attrName.toLowerCase()) {
2564
+ return value;
2565
+ }
2566
+ }
2567
+ }
2568
+ }
2569
+ }
2570
+ return null;
2571
+ }
2572
+
2573
+ // lsp/server/src/formatting/formatters.ts
2574
+ function isAttributeTruthy(value) {
2575
+ if (value === null || value === "" || value === "false" || value === "0") {
2576
+ return false;
2577
+ }
2578
+ return true;
2579
+ }
2580
+ function dedentContent(rawContent) {
2581
+ const lines = rawContent.split("\n");
2582
+ while (lines.length > 0 && lines[0].trim() === "") {
2583
+ lines.shift();
2584
+ }
2585
+ while (lines.length > 0 && lines[lines.length - 1].trim() === "") {
2586
+ lines.pop();
2587
+ }
2588
+ if (lines.length === 0) return "";
2589
+ let minIndent = Infinity;
2590
+ for (const l of lines) {
2591
+ if (l.trim() === "") continue;
2592
+ const match = l.match(/^(\s*)/);
2593
+ if (match && match[1].length < minIndent) {
2594
+ minIndent = match[1].length;
2595
+ }
2596
+ }
2597
+ if (minIndent === Infinity) minIndent = 0;
2598
+ return lines.map((l) => l.trim() === "" ? "" : l.slice(minIndent)).join("\n");
2599
+ }
2600
+ function resolveIndentMode(node, config) {
2601
+ const mode = config.indent ?? "never";
2602
+ if (mode === "never") return false;
2603
+ if (mode === "always") return true;
2604
+ if (!config.indentAttribute) return false;
2605
+ const value = getAttributeValue(node, config.indentAttribute);
2606
+ return isAttributeTruthy(value);
2607
+ }
2608
+ function getTagNameFromStartTag(startTag) {
2609
+ for (let i = 0; i < startTag.childCount; i++) {
2610
+ const child = startTag.child(i);
2611
+ if (child?.type === "html_tag_name") return child.text.toLowerCase();
2612
+ }
2613
+ return null;
2614
+ }
2615
+ function mustacheText(raw, context) {
2616
+ if (context.mustacheSpaces !== void 0) {
2617
+ return normalizeMustacheWhitespace(raw, context.mustacheSpaces);
2618
+ }
2619
+ return raw;
2620
+ }
2621
+ function formatDocument(node, context) {
2622
+ const children = getVisibleChildren(node);
2623
+ const content = formatBlockChildren(children, context);
2624
+ return concat([content, hardline]);
2625
+ }
2626
+ function formatNode(node, context, forceInline = false) {
2627
+ const type = node.type;
2628
+ switch (type) {
2629
+ case "document":
2630
+ return formatDocument(node, context);
2631
+ case "html_element":
2632
+ return formatHtmlElement(node, context);
2633
+ case "html_script_element":
2634
+ case "html_style_element":
2635
+ case "html_raw_element":
2636
+ return formatScriptStyleElement(node, context);
2637
+ case "mustache_section":
2638
+ case "mustache_inverted_section":
2639
+ if (forceInline) {
2640
+ if (context.mustacheSpaces !== void 0) {
2641
+ return text(normalizeMustacheWhitespaceAll(node.text, context.mustacheSpaces));
2642
+ }
2643
+ return text(node.text);
2644
+ }
2645
+ return formatMustacheSection(node, context);
2646
+ case "mustache_interpolation":
2647
+ case "mustache_triple":
2648
+ case "mustache_partial":
2649
+ case "mustache_comment":
2650
+ return text(mustacheText(node.text, context));
2651
+ case "html_comment":
2652
+ case "html_doctype":
2653
+ case "html_entity":
2654
+ case "html_erroneous_end_tag":
2655
+ return text(node.text);
2656
+ case "text":
2657
+ return formatText(node);
2658
+ default:
2659
+ return text(node.text);
2660
+ }
2661
+ }
2662
+ function formatText(node) {
2663
+ return text(normalizeText(node.text));
2664
+ }
2665
+ function formatHtmlElement(node, context) {
2666
+ const display = getCSSDisplay(node);
2667
+ const isBlock = isWhitespaceInsensitive(display);
2668
+ const preserveContent = shouldPreserveContent(node);
2669
+ const selfClosing = node.childCount === 1 && node.child(0)?.type === "html_self_closing_tag";
2670
+ if (selfClosing) {
2671
+ const tag = node.child(0);
2672
+ return formatStartTag(tag, context);
2673
+ }
2674
+ let startTag = null;
2675
+ let endTag = null;
2676
+ let hasRealEndTag = false;
2677
+ const contentNodes = [];
2678
+ for (let i = 0; i < node.childCount; i++) {
2679
+ const child = node.child(i);
2680
+ if (!child) continue;
2681
+ if (child.type === "html_start_tag") {
2682
+ startTag = child;
2683
+ } else if (child.type === "html_end_tag") {
2684
+ endTag = child;
2685
+ hasRealEndTag = true;
2686
+ } else if (child.type === "html_forced_end_tag") {
2687
+ endTag = child;
2688
+ } else if (!child.type.startsWith("_")) {
2689
+ contentNodes.push(child);
2690
+ }
2691
+ }
2692
+ const parts = [];
2693
+ if (startTag) {
2694
+ parts.push(formatStartTag(startTag, context));
2695
+ }
2696
+ const hasHtmlElementChildren = contentNodes.some(
2697
+ (child) => child.type === "html_element" || child.type === "html_script_element" || child.type === "html_style_element" || child.type === "html_raw_element" || isBlockLevel(child)
2698
+ );
2699
+ if (preserveContent) {
2700
+ const tagNameLower = startTag ? getTagNameFromStartTag(startTag) : null;
2701
+ const tagConfig = tagNameLower ? context.customCodeTagConfigs?.get(tagNameLower) : void 0;
2702
+ const shouldIndent = tagConfig ? resolveIndentMode(node, tagConfig) : false;
2703
+ if (shouldIndent && startTag && endTag) {
2704
+ const rawContent = context.document.getText().slice(
2705
+ startTag.endIndex,
2706
+ endTag.startIndex
2707
+ );
2708
+ const dedented = dedentContent(rawContent);
2709
+ if (dedented.length > 0) {
2710
+ const contentLines = dedented.split("\n");
2711
+ const lineDocs = [];
2712
+ for (let j = 0; j < contentLines.length; j++) {
2713
+ if (j > 0) {
2714
+ if (contentLines[j] === "") {
2715
+ lineDocs.push("\n");
2716
+ } else {
2717
+ lineDocs.push(hardline);
2718
+ }
2719
+ }
2720
+ if (contentLines[j] !== "") {
2721
+ lineDocs.push(text(contentLines[j]));
2722
+ }
2723
+ }
2724
+ parts.push(indent(concat([hardline, ...lineDocs])));
2725
+ parts.push(hardline);
2726
+ }
2727
+ } else if (startTag && endTag) {
2728
+ const rawContent = context.document.getText().slice(
2729
+ startTag.endIndex,
2730
+ endTag.startIndex
2731
+ );
2732
+ const trailingMatch = isBlock ? rawContent.match(/\n[\t ]*$/) : null;
2733
+ if (trailingMatch) {
2734
+ parts.push(text(rawContent.slice(0, -trailingMatch[0].length)));
2735
+ parts.push(hardline);
2736
+ } else {
2737
+ parts.push(text(rawContent));
2738
+ }
2739
+ } else {
2740
+ for (const child of contentNodes) {
2741
+ parts.push(text(child.text));
2742
+ }
2743
+ }
2744
+ } else if (!isBlock && !hasHtmlElementChildren) {
2745
+ for (const child of contentNodes) {
2746
+ parts.push(formatNode(child, context));
2747
+ }
2748
+ } else {
2749
+ const formattedContent = formatBlockChildren(contentNodes, context);
2750
+ const hasContent = hasDocContent(formattedContent);
2751
+ if (hasContent) {
2752
+ const hasBlockChildren = contentNodes.some((child, i) => {
2753
+ if (!shouldTreatAsBlock(child, i, contentNodes)) {
2754
+ return false;
2755
+ }
2756
+ const childDisplay = getCSSDisplay(child);
2757
+ return isWhitespaceInsensitive(childDisplay) || child.type === "html_script_element" || child.type === "html_style_element" || child.type === "html_raw_element";
2758
+ });
2759
+ if (isBlock && !hasBlockChildren) {
2760
+ const doc = group(
2761
+ concat([
2762
+ indent(concat([softline, formattedContent])),
2763
+ softline
2764
+ ])
2765
+ );
2766
+ parts.push(doc);
2767
+ if (!hasRealEndTag && endTag) {
2768
+ parts.pop();
2769
+ parts.push(
2770
+ group(
2771
+ concat([
2772
+ indent(concat([softline, formattedContent]))
2773
+ ])
2774
+ )
2775
+ );
2776
+ }
2777
+ } else {
2778
+ parts.push(indent(concat([hardline, formattedContent])));
2779
+ if (hasRealEndTag) {
2780
+ parts.push(hardline);
2781
+ }
2782
+ }
2783
+ } else if (contentNodes.length === 0 && hasRealEndTag) {
2784
+ parts.push(hardline);
2785
+ }
2786
+ }
2787
+ if (endTag) {
2788
+ parts.push(formatEndTag(endTag));
2789
+ }
2790
+ return concat(parts);
2791
+ }
2792
+ function formatScriptStyleElement(node, context) {
2793
+ const parts = [];
2794
+ for (let i = 0; i < node.childCount; i++) {
2795
+ const child = node.child(i);
2796
+ if (!child) continue;
2797
+ if (child.type === "html_start_tag") {
2798
+ parts.push(formatStartTag(child, context));
2799
+ } else if (child.type === "html_end_tag") {
2800
+ parts.push(formatEndTag(child));
2801
+ } else if (child.type === "html_raw_text") {
2802
+ const formatted = context.embeddedFormatted?.get(child.startIndex);
2803
+ if (formatted !== void 0) {
2804
+ const trimmed = formatted.replace(/^\n+/, "").replace(/\n+$/, "");
2805
+ if (trimmed.length === 0) {
2806
+ } else {
2807
+ const lines = trimmed.split("\n");
2808
+ const lineDocs = [];
2809
+ for (let j = 0; j < lines.length; j++) {
2810
+ if (j > 0) {
2811
+ lineDocs.push(hardline);
2812
+ }
2813
+ lineDocs.push(text(lines[j]));
2814
+ }
2815
+ parts.push(indent(concat([hardline, ...lineDocs])));
2816
+ parts.push(hardline);
2817
+ }
2818
+ } else {
2819
+ if (node.type === "html_raw_element") {
2820
+ const startTagNode = node.child(0);
2821
+ const tagNameLower = startTagNode?.type === "html_start_tag" ? getTagNameFromStartTag(startTagNode) : null;
2822
+ const tagConfig = tagNameLower ? context.customCodeTagConfigs?.get(tagNameLower) : void 0;
2823
+ if (tagConfig && resolveIndentMode(node, tagConfig)) {
2824
+ const dedented = dedentContent(child.text);
2825
+ if (dedented.length > 0) {
2826
+ const contentLines = dedented.split("\n");
2827
+ const lineDocs = [];
2828
+ for (let j = 0; j < contentLines.length; j++) {
2829
+ if (j > 0) {
2830
+ if (contentLines[j] === "") {
2831
+ lineDocs.push("\n");
2832
+ } else {
2833
+ lineDocs.push(hardline);
2834
+ }
2835
+ }
2836
+ if (contentLines[j] !== "") {
2837
+ lineDocs.push(text(contentLines[j]));
2838
+ }
2839
+ }
2840
+ parts.push(indent(concat([hardline, ...lineDocs])));
2841
+ parts.push(hardline);
2842
+ }
2843
+ } else {
2844
+ parts.push(text(child.text));
2845
+ }
2846
+ } else {
2847
+ parts.push(text(child.text));
2848
+ }
2849
+ }
2850
+ }
2851
+ }
2852
+ return concat(parts);
2853
+ }
2854
+ function formatMustacheSection(node, context) {
2855
+ const isInverted = node.type === "mustache_inverted_section";
2856
+ const beginType = isInverted ? "mustache_inverted_section_begin" : "mustache_section_begin";
2857
+ const endType = isInverted ? "mustache_inverted_section_end" : "mustache_section_end";
2858
+ let beginNode = null;
2859
+ let endNode = null;
2860
+ const contentNodes = [];
2861
+ for (let i = 0; i < node.childCount; i++) {
2862
+ const child = node.child(i);
2863
+ if (!child) continue;
2864
+ if (child.type === beginType) {
2865
+ beginNode = child;
2866
+ } else if (child.type === endType || child.type === "mustache_erroneous_section_end" || child.type === "mustache_erroneous_inverted_section_end") {
2867
+ endNode = child;
2868
+ } else if (!child.type.startsWith("_")) {
2869
+ contentNodes.push(child);
2870
+ }
2871
+ }
2872
+ const parts = [];
2873
+ if (beginNode) {
2874
+ parts.push(text(mustacheText(beginNode.text, context)));
2875
+ }
2876
+ const hasImplicit = hasImplicitEndTags(contentNodes);
2877
+ const formattedContent = formatBlockChildren(contentNodes, context);
2878
+ const hasContent = hasDocContent(formattedContent);
2879
+ if (hasContent) {
2880
+ if (hasImplicit) {
2881
+ parts.push(hardline);
2882
+ parts.push(formattedContent);
2883
+ parts.push(hardline);
2884
+ } else {
2885
+ const hasBlockChildren = contentNodes.some((child, i) => {
2886
+ if (!shouldTreatAsBlock(child, i, contentNodes)) {
2887
+ return false;
2888
+ }
2889
+ const childDisplay = getCSSDisplay(child);
2890
+ return isWhitespaceInsensitive(childDisplay) || child.type === "html_script_element" || child.type === "html_style_element" || child.type === "html_raw_element";
2891
+ });
2892
+ if (!hasBlockChildren) {
2893
+ parts.push(indent(concat([softline, formattedContent])));
2894
+ parts.push(softline);
2895
+ } else {
2896
+ parts.push(indent(concat([hardline, formattedContent])));
2897
+ parts.push(hardline);
2898
+ }
2899
+ }
2900
+ }
2901
+ if (endNode) {
2902
+ parts.push(text(mustacheText(endNode.text, context)));
2903
+ }
2904
+ return group(concat(parts));
2905
+ }
2906
+ function formatStartTag(node, context) {
2907
+ let tagNameText = "";
2908
+ const attrs = [];
2909
+ for (let i = 0; i < node.childCount; i++) {
2910
+ const child = node.child(i);
2911
+ if (!child) continue;
2912
+ if (child.type === "html_tag_name") {
2913
+ tagNameText = child.text;
2914
+ } else if (child.type === "html_attribute") {
2915
+ attrs.push(formatAttribute(child, context));
2916
+ } else if (child.type === "mustache_attribute") {
2917
+ if (context?.mustacheSpaces !== void 0) {
2918
+ attrs.push(text(normalizeMustacheWhitespaceAll(child.text, context.mustacheSpaces)));
2919
+ } else {
2920
+ attrs.push(text(child.text));
2921
+ }
2922
+ } else if (child.type === "mustache_interpolation" || child.type === "mustache_triple") {
2923
+ attrs.push(text(context ? mustacheText(child.text, context) : child.text));
2924
+ }
2925
+ }
2926
+ const isSelfClosing = node.type === "html_self_closing_tag";
2927
+ const closingBracket = isSelfClosing ? " />" : ">";
2928
+ if (attrs.length === 0) {
2929
+ return text("<" + tagNameText + closingBracket);
2930
+ }
2931
+ const attrParts = [];
2932
+ for (let i = 0; i < attrs.length; i++) {
2933
+ if (i > 0) {
2934
+ attrParts.push(line);
2935
+ }
2936
+ attrParts.push(attrs[i]);
2937
+ }
2938
+ return group(
2939
+ concat([
2940
+ text("<"),
2941
+ text(tagNameText),
2942
+ indent(concat([line, concat(attrParts)])),
2943
+ ifBreak(concat([hardline, text(closingBracket)]), text(closingBracket))
2944
+ ])
2945
+ );
2946
+ }
2947
+ function formatEndTag(node) {
2948
+ for (let i = 0; i < node.childCount; i++) {
2949
+ const child = node.child(i);
2950
+ if (child && child.type === "html_tag_name") {
2951
+ return text("</" + child.text + ">");
2952
+ }
2953
+ }
2954
+ return text(node.text);
2955
+ }
2956
+ function formatAttribute(node, context) {
2957
+ const parts = [];
2958
+ for (let i = 0; i < node.childCount; i++) {
2959
+ const child = node.child(i);
2960
+ if (!child) continue;
2961
+ if (child.type === "html_attribute_name") {
2962
+ parts.push(text(child.text));
2963
+ } else if (child.type === "html_attribute_value") {
2964
+ parts.push(text("="));
2965
+ parts.push(text(child.text));
2966
+ } else if (child.type === "html_quoted_attribute_value") {
2967
+ parts.push(text("="));
2968
+ if (context?.mustacheSpaces !== void 0) {
2969
+ parts.push(text(normalizeMustacheWhitespaceAll(child.text, context.mustacheSpaces)));
2970
+ } else {
2971
+ parts.push(text(child.text));
2972
+ }
2973
+ } else if (child.type === "mustache_interpolation") {
2974
+ parts.push(text("="));
2975
+ parts.push(text(context ? mustacheText(child.text, context) : child.text));
2976
+ }
2977
+ }
2978
+ return concat(parts);
2979
+ }
2980
+ function textWords(str) {
2981
+ const words = str.split(/\s+/).filter((w) => w.length > 0);
2982
+ if (words.length === 0) return [];
2983
+ const parts = [words[0]];
2984
+ for (let i = 1; i < words.length; i++) {
2985
+ parts.push(line);
2986
+ parts.push(words[i]);
2987
+ }
2988
+ return parts;
2989
+ }
2990
+ function inlineContentToFill(parts) {
2991
+ if (parts.length === 0) return empty;
2992
+ if (parts.length === 1) return parts[0];
2993
+ const fillParts = [];
2994
+ for (const item of parts) {
2995
+ if (isLine(item)) {
2996
+ if (fillParts.length > 0 && !isLine(fillParts[fillParts.length - 1])) {
2997
+ fillParts.push(item);
2998
+ }
2999
+ } else {
3000
+ const lastIdx = fillParts.length - 1;
3001
+ if (lastIdx >= 0 && !isLine(fillParts[lastIdx])) {
3002
+ fillParts[lastIdx] = concat([fillParts[lastIdx], item]);
3003
+ } else if (typeof item === "string" && /^[,.:;!?)\]]/.test(item) && lastIdx >= 0 && isLine(fillParts[lastIdx])) {
3004
+ fillParts.pop();
3005
+ if (fillParts.length > 0) {
3006
+ fillParts[fillParts.length - 1] = concat([
3007
+ fillParts[fillParts.length - 1],
3008
+ item
3009
+ ]);
3010
+ } else {
3011
+ fillParts.push(item);
3012
+ }
3013
+ } else {
3014
+ fillParts.push(item);
3015
+ }
3016
+ }
3017
+ }
3018
+ if (fillParts.length > 0 && isLine(fillParts[fillParts.length - 1])) {
3019
+ fillParts.pop();
3020
+ }
3021
+ return fill(fillParts);
3022
+ }
3023
+ function formatBlockChildren(nodes, context) {
3024
+ const lines = [];
3025
+ let currentLine = [];
3026
+ let lastNodeEnd = -1;
3027
+ let pendingBlankLine = false;
3028
+ let blankLineBeforeCurrentLine = false;
3029
+ for (let i = 0; i < nodes.length; i++) {
3030
+ const node = nodes[i];
3031
+ const treatAsBlock = shouldTreatAsBlock(node, i, nodes);
3032
+ if (lastNodeEnd >= 0 && node.startIndex > lastNodeEnd) {
3033
+ const gap = context.document.getText().slice(lastNodeEnd, node.startIndex);
3034
+ const prevNode = nodes[i - 1];
3035
+ const prevTreatAsBlock = shouldTreatAsBlock(prevNode, i - 1, nodes);
3036
+ const newlineCount = (gap.match(/\n/g) || []).length;
3037
+ if (newlineCount >= 2) {
3038
+ pendingBlankLine = true;
3039
+ }
3040
+ if (!prevTreatAsBlock && !treatAsBlock) {
3041
+ if (/\s/.test(gap)) {
3042
+ currentLine.push(line);
3043
+ }
3044
+ }
3045
+ }
3046
+ if (treatAsBlock) {
3047
+ if (currentLine.length > 0) {
3048
+ const lineContent = trimDoc(inlineContentToFill(currentLine));
3049
+ if (hasDocContent(lineContent)) {
3050
+ lines.push({ doc: lineContent, blankLineBefore: blankLineBeforeCurrentLine });
3051
+ }
3052
+ currentLine = [];
3053
+ blankLineBeforeCurrentLine = false;
3054
+ }
3055
+ lines.push({ doc: formatNode(node, context), blankLineBefore: pendingBlankLine });
3056
+ pendingBlankLine = false;
3057
+ } else if (node.type === "html_comment" || node.type === "mustache_comment") {
3058
+ const isMultiline = node.startPosition.row !== node.endPosition.row;
3059
+ if (isMultiline) {
3060
+ if (currentLine.length > 0) {
3061
+ const lineContent = trimDoc(inlineContentToFill(currentLine));
3062
+ if (hasDocContent(lineContent)) {
3063
+ lines.push({ doc: lineContent, blankLineBefore: blankLineBeforeCurrentLine });
3064
+ }
3065
+ currentLine = [];
3066
+ blankLineBeforeCurrentLine = false;
3067
+ }
3068
+ const commentText = node.type === "mustache_comment" ? mustacheText(node.text, context) : node.text;
3069
+ lines.push({ doc: text(commentText), blankLineBefore: pendingBlankLine });
3070
+ pendingBlankLine = false;
3071
+ } else {
3072
+ if (currentLine.length === 0) {
3073
+ blankLineBeforeCurrentLine = pendingBlankLine;
3074
+ pendingBlankLine = false;
3075
+ }
3076
+ const commentText = node.type === "mustache_comment" ? mustacheText(node.text, context) : node.text;
3077
+ currentLine.push(text(commentText));
3078
+ }
3079
+ } else {
3080
+ if (currentLine.length === 0) {
3081
+ blankLineBeforeCurrentLine = pendingBlankLine;
3082
+ pendingBlankLine = false;
3083
+ }
3084
+ const forceInline = isInTextFlow(node, i, nodes);
3085
+ const formatted = formatNode(node, context, forceInline);
3086
+ if (typeof formatted === "string" && formatted.includes("\n")) {
3087
+ const contentLines = formatted.split("\n");
3088
+ const isTextNode = node.type === "text";
3089
+ if (isTextNode) {
3090
+ for (let j = 0; j < contentLines.length; j++) {
3091
+ const trimmed = contentLines[j].trim();
3092
+ if (!trimmed) {
3093
+ if (currentLine.length > 0) {
3094
+ const lineContent = trimDoc(inlineContentToFill(currentLine));
3095
+ if (hasDocContent(lineContent)) {
3096
+ lines.push({ doc: lineContent, blankLineBefore: blankLineBeforeCurrentLine });
3097
+ blankLineBeforeCurrentLine = false;
3098
+ }
3099
+ currentLine = [];
3100
+ }
3101
+ pendingBlankLine = true;
3102
+ } else {
3103
+ if (currentLine.length === 0) {
3104
+ blankLineBeforeCurrentLine = pendingBlankLine;
3105
+ pendingBlankLine = false;
3106
+ }
3107
+ if (j > 0 && currentLine.length > 0) {
3108
+ currentLine.push(line);
3109
+ }
3110
+ currentLine.push(...textWords(trimmed));
3111
+ }
3112
+ }
3113
+ } else {
3114
+ const firstTrimmed = contentLines[0].trim();
3115
+ if (firstTrimmed) {
3116
+ currentLine.push(firstTrimmed);
3117
+ }
3118
+ if (currentLine.length > 0) {
3119
+ const lineContent = trimDoc(inlineContentToFill(currentLine));
3120
+ if (hasDocContent(lineContent)) {
3121
+ lines.push({ doc: lineContent, blankLineBefore: blankLineBeforeCurrentLine });
3122
+ blankLineBeforeCurrentLine = pendingBlankLine;
3123
+ pendingBlankLine = false;
3124
+ }
3125
+ currentLine = [];
3126
+ }
3127
+ let sawBlankLine = false;
3128
+ for (let j = 1; j < contentLines.length - 1; j++) {
3129
+ const trimmed = contentLines[j].trim();
3130
+ if (trimmed) {
3131
+ lines.push({ doc: text(trimmed), blankLineBefore: blankLineBeforeCurrentLine || sawBlankLine });
3132
+ blankLineBeforeCurrentLine = false;
3133
+ sawBlankLine = false;
3134
+ } else {
3135
+ sawBlankLine = true;
3136
+ }
3137
+ }
3138
+ if (contentLines.length > 1) {
3139
+ const lastTrimmed = contentLines[contentLines.length - 1].trim();
3140
+ if (lastTrimmed) {
3141
+ blankLineBeforeCurrentLine = sawBlankLine;
3142
+ sawBlankLine = false;
3143
+ currentLine = [lastTrimmed];
3144
+ }
3145
+ if (sawBlankLine) {
3146
+ pendingBlankLine = true;
3147
+ }
3148
+ }
3149
+ }
3150
+ } else {
3151
+ if (node.type === "text" && typeof formatted === "string") {
3152
+ currentLine.push(...textWords(formatted));
3153
+ } else {
3154
+ currentLine.push(formatted);
3155
+ }
3156
+ }
3157
+ }
3158
+ lastNodeEnd = node.endIndex;
3159
+ }
3160
+ if (currentLine.length > 0) {
3161
+ const lineContent = trimDoc(inlineContentToFill(currentLine));
3162
+ if (hasDocContent(lineContent)) {
3163
+ lines.push({ doc: lineContent, blankLineBefore: blankLineBeforeCurrentLine });
3164
+ }
3165
+ }
3166
+ if (lines.length === 0) {
3167
+ return empty;
3168
+ }
3169
+ const parts = [];
3170
+ for (let i = 0; i < lines.length; i++) {
3171
+ if (i > 0) {
3172
+ if (lines[i].blankLineBefore) {
3173
+ parts.push("\n");
3174
+ }
3175
+ parts.push(hardline);
3176
+ }
3177
+ parts.push(lines[i].doc);
3178
+ }
3179
+ return concat(parts);
3180
+ }
3181
+ function hasDocContent(doc) {
3182
+ if (typeof doc === "string") {
3183
+ return doc.trim().length > 0;
3184
+ }
3185
+ if (doc.type === "concat") {
3186
+ return doc.parts.some(hasDocContent);
3187
+ }
3188
+ if (doc.type === "indent") {
3189
+ return hasDocContent(doc.contents);
3190
+ }
3191
+ if (doc.type === "group") {
3192
+ return hasDocContent(doc.contents);
3193
+ }
3194
+ if (doc.type === "fill") {
3195
+ return doc.parts.some(hasDocContent);
3196
+ }
3197
+ if (doc.type === "ifBreak") {
3198
+ return hasDocContent(doc.breakContents) || hasDocContent(doc.flatContents);
3199
+ }
3200
+ return false;
3201
+ }
3202
+ function trimDoc(doc) {
3203
+ if (typeof doc === "string") {
3204
+ return doc.trim();
3205
+ }
3206
+ return doc;
3207
+ }
3208
+
3209
+ // lsp/server/src/formatting/editorconfig.ts
3210
+ var import_editorconfig = require("editorconfig");
3211
+ var import_url = require("url");
3212
+ function getEditorConfigOptions(uri) {
3213
+ try {
3214
+ if (!uri.startsWith("file://")) {
3215
+ return {};
3216
+ }
3217
+ const filePath = (0, import_url.fileURLToPath)(uri);
3218
+ const config = (0, import_editorconfig.parseSync)(filePath);
3219
+ const result = {};
3220
+ if (config.indent_style === "space") {
3221
+ result.insertSpaces = true;
3222
+ } else if (config.indent_style === "tab") {
3223
+ result.insertSpaces = false;
3224
+ }
3225
+ if (typeof config.indent_size === "number") {
3226
+ result.tabSize = config.indent_size;
3227
+ } else if (config.indent_size === "tab" && typeof config.tab_width === "number") {
3228
+ result.tabSize = config.tab_width;
3229
+ }
3230
+ return result;
3231
+ } catch {
3232
+ return {};
3233
+ }
3234
+ }
3235
+ function mergeOptions(lspOptions, uri, configFile) {
3236
+ let tabSize = lspOptions.tabSize;
3237
+ let insertSpaces = lspOptions.insertSpaces;
3238
+ if (configFile?.indentSize !== void 0) tabSize = configFile.indentSize;
3239
+ const ec = getEditorConfigOptions(uri);
3240
+ if (ec.tabSize !== void 0) tabSize = ec.tabSize;
3241
+ if (ec.insertSpaces !== void 0) insertSpaces = ec.insertSpaces;
3242
+ return { tabSize, insertSpaces };
3243
+ }
3244
+ function createIndentUnit(options) {
3245
+ return options.insertSpaces ? " ".repeat(options.tabSize) : " ";
3246
+ }
3247
+
3248
+ // lsp/server/src/formatting/index.ts
3249
+ function formatDocument2(tree, document, options, params = {}) {
3250
+ const { customCodeTags: customCodeTags2, printWidth = 80, embeddedFormatted, mustacheSpaces, customCodeTagConfigs, configFile } = params;
3251
+ const mergedOptions = mergeOptions(options, document.uri, configFile);
3252
+ const indentUnit = createIndentUnit(mergedOptions);
3253
+ if (customCodeTags2) {
3254
+ setCustomCodeTags(customCodeTags2);
3255
+ }
3256
+ const configMap = buildConfigMap(customCodeTagConfigs);
3257
+ const context = {
3258
+ document,
3259
+ customCodeTags: customCodeTags2 ? new Set(customCodeTags2.map((t) => t.toLowerCase())) : void 0,
3260
+ customCodeTagConfigs: configMap,
3261
+ embeddedFormatted,
3262
+ mustacheSpaces
3263
+ };
3264
+ const doc = formatDocument(tree.rootNode, context);
3265
+ const formatted = print(doc, { indentUnit, printWidth });
3266
+ const fullRange = {
3267
+ start: { line: 0, character: 0 },
3268
+ end: document.positionAt(document.getText().length)
3269
+ };
3270
+ return [{ range: fullRange, newText: formatted }];
3271
+ }
3272
+ function buildConfigMap(configs) {
3273
+ if (!configs || configs.length === 0) return void 0;
3274
+ const map = /* @__PURE__ */ new Map();
3275
+ for (const config of configs) {
3276
+ map.set(config.name.toLowerCase(), config);
3277
+ }
3278
+ return map;
3279
+ }
3280
+
3281
+ // lsp/server/src/configFile.ts
3282
+ var fs2 = __toESM(require("fs"));
3283
+ var path2 = __toESM(require("path"));
3284
+ var CONFIG_FILENAME = ".htmlmustache.jsonc";
3285
+ function parseJsonc(text2) {
3286
+ let result = "";
3287
+ let i = 0;
3288
+ while (i < text2.length) {
3289
+ if (text2[i] === '"') {
3290
+ result += '"';
3291
+ i++;
3292
+ while (i < text2.length && text2[i] !== '"') {
3293
+ if (text2[i] === "\\") {
3294
+ result += text2[i] + (text2[i + 1] ?? "");
3295
+ i += 2;
3296
+ } else {
3297
+ result += text2[i];
3298
+ i++;
3299
+ }
3300
+ }
3301
+ if (i < text2.length) {
3302
+ result += '"';
3303
+ i++;
3304
+ }
3305
+ continue;
3306
+ }
3307
+ if (text2[i] === "/" && text2[i + 1] === "/") {
3308
+ while (i < text2.length && text2[i] !== "\n") i++;
3309
+ continue;
3310
+ }
3311
+ if (text2[i] === "/" && text2[i + 1] === "*") {
3312
+ i += 2;
3313
+ while (i < text2.length && !(text2[i] === "*" && text2[i + 1] === "/")) i++;
3314
+ i += 2;
3315
+ continue;
3316
+ }
3317
+ result += text2[i];
3318
+ i++;
3319
+ }
3320
+ result = result.replace(/,\s*([}\]])/g, "$1");
3321
+ return JSON.parse(result);
3322
+ }
3323
+ function findConfigFile(startDir) {
3324
+ let dir = path2.resolve(startDir);
3325
+ const root = path2.parse(dir).root;
3326
+ while (true) {
3327
+ const candidate = path2.join(dir, CONFIG_FILENAME);
3328
+ try {
3329
+ fs2.accessSync(candidate, fs2.constants.R_OK);
3330
+ return candidate;
3331
+ } catch {
3332
+ }
3333
+ const parent = path2.dirname(dir);
3334
+ if (parent === dir || dir === root) return null;
3335
+ dir = parent;
3336
+ }
3337
+ }
3338
+ var VALID_INDENT_MODES2 = /* @__PURE__ */ new Set(["never", "always", "attribute"]);
3339
+ function validateConfig(raw) {
3340
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return {};
3341
+ const obj = raw;
3342
+ const config = {};
3343
+ if (typeof obj.printWidth === "number" && obj.printWidth > 0) {
3344
+ config.printWidth = obj.printWidth;
3345
+ }
3346
+ if (typeof obj.indentSize === "number" && obj.indentSize > 0) {
3347
+ config.indentSize = obj.indentSize;
3348
+ }
3349
+ if (typeof obj.mustacheSpaces === "boolean") {
3350
+ config.mustacheSpaces = obj.mustacheSpaces;
3351
+ }
3352
+ if (Array.isArray(obj.customCodeTags)) {
3353
+ const tags = [];
3354
+ for (const entry of obj.customCodeTags) {
3355
+ if (entry && typeof entry === "object" && "name" in entry) {
3356
+ const e = entry;
3357
+ if (typeof e.name !== "string" || e.name.length === 0) continue;
3358
+ const tag = { name: e.name };
3359
+ if (typeof e.languageAttribute === "string") tag.languageAttribute = e.languageAttribute;
3360
+ if (e.languageMap && typeof e.languageMap === "object" && !Array.isArray(e.languageMap)) {
3361
+ tag.languageMap = e.languageMap;
3362
+ }
3363
+ if (typeof e.languageDefault === "string") tag.languageDefault = e.languageDefault;
3364
+ if (typeof e.indent === "string" && VALID_INDENT_MODES2.has(e.indent)) {
3365
+ tag.indent = e.indent;
3366
+ }
3367
+ if (typeof e.indentAttribute === "string") tag.indentAttribute = e.indentAttribute;
3368
+ tags.push(tag);
3369
+ }
3370
+ }
3371
+ if (tags.length > 0) config.customCodeTags = tags;
3372
+ }
3373
+ return config;
3374
+ }
3375
+ function loadConfigFileForPath(filePath) {
3376
+ const dir = path2.dirname(path2.resolve(filePath));
3377
+ const configPath = findConfigFile(dir);
3378
+ if (!configPath) return null;
3379
+ try {
3380
+ const text2 = fs2.readFileSync(configPath, "utf-8");
3381
+ const raw = parseJsonc(text2);
3382
+ return validateConfig(raw);
3383
+ } catch {
3384
+ return null;
3385
+ }
3386
+ }
3387
+
3388
+ // cli/src/wasm.ts
3389
+ var path3 = __toESM(require("node:path"));
3390
+ var import_web_tree_sitter = require("web-tree-sitter");
3391
+ var parser;
3392
+ async function initializeParser() {
3393
+ await import_web_tree_sitter.Parser.init();
3394
+ parser = new import_web_tree_sitter.Parser();
3395
+ const wasmPath = path3.resolve(__dirname, "..", "..", "tree-sitter-htmlmustache.wasm");
3396
+ const language = await import_web_tree_sitter.Language.load(wasmPath);
3397
+ parser.setLanguage(language);
3398
+ }
3399
+ function parseDocument(source) {
3400
+ const tree = parser.parse(source);
3401
+ if (!tree) {
3402
+ throw new Error("Failed to parse document");
3403
+ }
3404
+ return tree;
3405
+ }
3406
+
3407
+ // cli/src/format.ts
3408
+ var USAGE2 = `Usage: htmlmustache format [options] <patterns...>
3409
+
3410
+ Format HTML Mustache templates.
3411
+
3412
+ Arguments:
3413
+ patterns One or more glob patterns (e.g. '**/*.mustache')
3414
+
3415
+ Options:
3416
+ --write Modify files in-place (default: print to stdout)
3417
+ --check Exit 1 if any files would change (for CI)
3418
+ --stdin Read from stdin, write to stdout
3419
+ --indent-size N Spaces per indent level (default: 2)
3420
+ --print-width N Max line width (default: 80)
3421
+ --mustache-spaces Add spaces inside mustache delimiters
3422
+ --help Show this help message
3423
+
3424
+ Examples:
3425
+ htmlmustache format --write '**/*.mustache'
3426
+ htmlmustache format --check 'templates/**/*.hbs'
3427
+ echo '<div><p>hi</p></div>' | htmlmustache format --stdin`;
3428
+ function parseFlags(args) {
3429
+ const flags = {
3430
+ write: false,
3431
+ check: false,
3432
+ stdin: false,
3433
+ indentSize: void 0,
3434
+ printWidth: void 0,
3435
+ mustacheSpaces: void 0,
3436
+ patterns: []
3437
+ };
3438
+ let i = 0;
3439
+ while (i < args.length) {
3440
+ const arg = args[i];
3441
+ switch (arg) {
3442
+ case "--write":
3443
+ flags.write = true;
3444
+ break;
3445
+ case "--check":
3446
+ flags.check = true;
3447
+ break;
3448
+ case "--stdin":
3449
+ flags.stdin = true;
3450
+ break;
3451
+ case "--indent-size":
3452
+ i++;
3453
+ flags.indentSize = parseInt(args[i], 10);
3454
+ if (isNaN(flags.indentSize)) {
3455
+ console.error(import_chalk2.default.red("Error: --indent-size requires a number"));
3456
+ process.exit(1);
3457
+ }
3458
+ break;
3459
+ case "--print-width":
3460
+ i++;
3461
+ flags.printWidth = parseInt(args[i], 10);
3462
+ if (isNaN(flags.printWidth)) {
3463
+ console.error(import_chalk2.default.red("Error: --print-width requires a number"));
3464
+ process.exit(1);
3465
+ }
3466
+ break;
3467
+ case "--mustache-spaces":
3468
+ flags.mustacheSpaces = true;
3469
+ break;
3470
+ default:
3471
+ flags.patterns.push(arg);
3472
+ break;
3473
+ }
3474
+ i++;
3475
+ }
3476
+ return flags;
3477
+ }
3478
+ function resolveSettings(flags, filePath) {
3479
+ let tabSize = 2;
3480
+ let insertSpaces = true;
3481
+ let printWidth = 80;
3482
+ let mustacheSpaces = false;
3483
+ let customCodeTags2;
3484
+ let customCodeTagConfigs;
3485
+ const configFile = filePath ? loadConfigFileForPath(filePath) : null;
3486
+ if (configFile) {
3487
+ if (configFile.indentSize !== void 0) tabSize = configFile.indentSize;
3488
+ if (configFile.printWidth !== void 0) printWidth = configFile.printWidth;
3489
+ if (configFile.mustacheSpaces !== void 0) mustacheSpaces = configFile.mustacheSpaces;
3490
+ if (configFile.customCodeTags && configFile.customCodeTags.length > 0) {
3491
+ const parsed = parseCustomCodeTagSettings(configFile.customCodeTags);
3492
+ customCodeTags2 = parsed.tagNames;
3493
+ customCodeTagConfigs = parsed.configs;
3494
+ }
3495
+ }
3496
+ if (filePath) {
3497
+ const uri = (0, import_node_url.pathToFileURL)(filePath).href;
3498
+ const ecOptions = getEditorConfigOptions(uri);
3499
+ if (ecOptions.tabSize !== void 0) tabSize = ecOptions.tabSize;
3500
+ if (ecOptions.insertSpaces !== void 0) insertSpaces = ecOptions.insertSpaces;
3501
+ }
3502
+ if (flags.indentSize !== void 0) tabSize = flags.indentSize;
3503
+ if (flags.printWidth !== void 0) printWidth = flags.printWidth;
3504
+ if (flags.mustacheSpaces !== void 0) mustacheSpaces = flags.mustacheSpaces;
3505
+ return {
3506
+ options: { tabSize, insertSpaces },
3507
+ printWidth,
3508
+ mustacheSpaces,
3509
+ customCodeTags: customCodeTags2,
3510
+ customCodeTagConfigs,
3511
+ configFile
3512
+ };
3513
+ }
3514
+ function formatSource(source, options, params = {}) {
3515
+ const tree = parseDocument(source);
3516
+ const document = TextDocument.create("file:///stdin", "htmlmustache", 1, source);
3517
+ const edits = formatDocument2(tree, document, options, params);
3518
+ if (edits.length === 0) return source;
3519
+ return edits[0].newText;
3520
+ }
3521
+ async function run2(args) {
3522
+ if (args[0] === "format") {
3523
+ args = args.slice(1);
3524
+ }
3525
+ if (args.includes("--help")) {
3526
+ console.log(USAGE2);
3527
+ return 0;
3528
+ }
3529
+ const flags = parseFlags(args);
3530
+ if (!flags.stdin && flags.patterns.length === 0) {
3531
+ console.log(USAGE2);
3532
+ return 1;
3533
+ }
3534
+ await initializeParser();
3535
+ if (flags.stdin) {
3536
+ const { options, ...params } = resolveSettings(flags);
3537
+ const source = import_node_fs2.default.readFileSync(0, "utf-8");
3538
+ const formatted = formatSource(source, options, params);
3539
+ process.stdout.write(formatted);
3540
+ return 0;
3541
+ }
3542
+ const files = expandGlobs(flags.patterns);
3543
+ if (files.length === 0) {
3544
+ console.error(import_chalk2.default.yellow("No files matched the given patterns:"));
3545
+ for (const pattern of flags.patterns) {
3546
+ console.error(import_chalk2.default.yellow(` ${pattern}`));
3547
+ }
3548
+ return 1;
3549
+ }
3550
+ const cwd = process.cwd();
3551
+ let changedCount = 0;
3552
+ for (const file of files) {
3553
+ const displayPath = import_node_path2.default.relative(cwd, file) || file;
3554
+ const source = import_node_fs2.default.readFileSync(file, "utf-8");
3555
+ const { options, ...params } = resolveSettings(flags, file);
3556
+ const formatted = formatSource(source, options, params);
3557
+ const changed = formatted !== source;
3558
+ if (changed) changedCount++;
3559
+ if (flags.check) {
3560
+ console.log(changed ? import_chalk2.default.red(displayPath) : import_chalk2.default.dim(displayPath));
3561
+ } else if (flags.write) {
3562
+ if (changed) {
3563
+ import_node_fs2.default.writeFileSync(file, formatted);
3564
+ }
3565
+ console.log(changed ? import_chalk2.default.green(displayPath) : import_chalk2.default.dim(displayPath));
3566
+ } else {
3567
+ process.stdout.write(formatted);
3568
+ }
3569
+ }
3570
+ if (flags.check && changedCount > 0) {
3571
+ console.log(
3572
+ import_chalk2.default.red(`
3573
+ ${changedCount} ${changedCount === 1 ? "file" : "files"} would be reformatted`)
3574
+ );
3575
+ return 1;
3576
+ }
3577
+ if (flags.check) {
3578
+ console.log(import_chalk2.default.green(`All ${files.length} ${files.length === 1 ? "file" : "files"} already formatted`));
3579
+ }
3580
+ return 0;
3581
+ }
3582
+
3583
+ // cli/src/main.ts
3584
+ var USAGE3 = `Usage: htmlmustache <command> [options]
3585
+
3586
+ Commands:
3587
+ check Check templates for parse errors
3588
+ format Format templates
3589
+
3590
+ Run 'htmlmustache <command> --help' for command-specific help.`;
3591
+ async function main() {
3592
+ const args = process.argv.slice(2);
3593
+ const command = args[0];
3594
+ switch (command) {
3595
+ case "check":
3596
+ process.exit(run(args));
3597
+ break;
3598
+ case "format":
3599
+ process.exit(await run2(args));
3600
+ break;
3601
+ case "--help":
3602
+ case "-h":
3603
+ case void 0:
3604
+ console.log(USAGE3);
3605
+ process.exit(command ? 0 : 1);
3606
+ break;
3607
+ default:
3608
+ console.error(import_chalk3.default.red(`Unknown command: ${command}`));
3609
+ console.error('Run "htmlmustache --help" for usage.');
3610
+ process.exit(1);
3611
+ }
3612
+ }
3613
+ main();