@rohal12/spindle 0.64.10 → 0.64.12

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.
@@ -9,51 +9,6 @@ var __exportAll = (all, no_symbols) => {
9
9
  if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
10
10
  return target;
11
11
  };
12
- // src/utils/macro-names.ts
13
- /**
14
- * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
15
- * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
16
- * name.
17
- */
18
- var NameMap = class extends Map {
19
- get(name) {
20
- return super.get(name.toLowerCase());
21
- }
22
- set(name, value) {
23
- return super.set(name.toLowerCase(), value);
24
- }
25
- has(name) {
26
- return super.has(name.toLowerCase());
27
- }
28
- delete(name) {
29
- return super.delete(name.toLowerCase());
30
- }
31
- };
32
- /** The latest definition of each name, using runtime replacement precedence. */
33
- function effectiveNamedDefinitions(definitions) {
34
- const latest = new NameMap();
35
- for (const definition of definitions) latest.set(definition.name, definition);
36
- return [...latest.values()];
37
- }
38
- /** A set of macro or widget names (see NameMap). */
39
- var NameSet = class {
40
- constructor(names = []) {
41
- this.names = new NameMap();
42
- for (const name of names) this.add(name);
43
- }
44
- add(name) {
45
- this.names.set(name, true);
46
- }
47
- has(name) {
48
- return this.names.has(name);
49
- }
50
- delete(name) {
51
- this.names.delete(name);
52
- }
53
- clear() {
54
- this.names.clear();
55
- }
56
- };
57
12
  /** Text-only bodies recognize their own end tag, never nested HTML tags. */
58
13
  var HTML_TEXT_ELEMENTS$1 = /* @__PURE__ */ new Set([
59
14
  .../* @__PURE__ */ new Set([
@@ -331,11 +286,14 @@ var peg$SyntaxError = class extends SyntaxError {
331
286
  if (nonPrintable) return s.replace(nonPrintable, (ch) => "\\u{" + hex(ch) + "}");
332
287
  return s;
333
288
  }
289
+ function escape(s, special) {
290
+ return unicodeEscape(s.replace(special, "\\$&").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)));
291
+ }
334
292
  function literalEscape(s) {
335
- return unicodeEscape(s.replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)));
293
+ return escape(s, /[\\"]/g);
336
294
  }
337
295
  function classEscape(s) {
338
- return unicodeEscape(s.replace(/\\/g, "\\\\").replace(/\]/g, "\\]").replace(/\^/g, "\\^").replace(/-/g, "\\-").replace(/\0/g, "\\0").replace(/\t/g, "\\t").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/[\x00-\x0F]/g, (ch) => "\\x0" + hex(ch)).replace(/[\x10-\x1F\x7F-\x9F]/g, (ch) => "\\x" + hex(ch)));
296
+ return escape(s, /[\\\]^-]/g);
339
297
  }
340
298
  const DESCRIBE_EXPECTATION_FNS = {
341
299
  literal(expectation) {
@@ -409,28 +367,6 @@ function peg$parse(input, options) {
409
367
  const peg$c16 = "=";
410
368
  const peg$c17 = "\"";
411
369
  const peg$c18 = "'";
412
- const peg$r0 = /^[^\\{[<]/;
413
- const peg$r1 = /^[{}]/;
414
- const peg$r2 = /^[$_@%(!\/a-zA-Z]/;
415
- const peg$r3 = /^[.#]/;
416
- const peg$r4 = /^[a-zA-Z0-9_\-]/;
417
- const peg$r5 = /^[$_@%]/;
418
- const peg$r6 = /^[a-zA-Z0-9_.]/;
419
- const peg$r7 = /^[$_@%(!]/;
420
- const peg$r8 = /^[a-zA-Z]/;
421
- const peg$r9 = /^[^ \t\n\r\v\f\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF}]/;
422
- const peg$r10 = /^[a-zA-Z0-9.!#$%&'*+\/=?\^_`|~\-]/;
423
- const peg$r11 = /^[a-zA-Z0-9.\-]/;
424
- const peg$r12 = /^[a-zA-Z0-9+.\-]/;
425
- const peg$r13 = /^[^\0- \x7F<>{}]/;
426
- const peg$r14 = /^[\t-\r \/>\xA0\u1680\u2000-\u200A\u2028-\u2029\u202F\u205F\u3000\uFEFF]/;
427
- const peg$r15 = /^[a-zA-Z0-9\-]/;
428
- const peg$r16 = /^[\t-\r "'\/<->{}\xA0\u1680\u2000-\u200A\u2028-\u2029\u202F\u205F\u3000\uFEFF]/;
429
- const peg$r17 = /^[^"]/;
430
- const peg$r18 = /^[^']/;
431
- const peg$r19 = /^["']/;
432
- const peg$r20 = /^[^ \t\n\r\v\f\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF>]/;
433
- const peg$r21 = /^[ \t\n\r\v\f\xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]/;
434
370
  const peg$e0 = peg$anyExpectation();
435
371
  const peg$e1 = peg$classExpectation([
436
372
  "\\",
@@ -995,6 +931,7 @@ function peg$parse(input, options) {
995
931
  let peg$maxFailExpected = options.peg$maxFailExpected || [];
996
932
  let peg$silentFails = options.peg$silentFails | 0;
997
933
  let peg$result;
934
+ let peg$charCode;
998
935
  if (options.startRule) {
999
936
  if (!(options.startRule in peg$startRuleFunctions)) throw new Error("Can't start parsing from rule \"" + options.startRule + "\".");
1000
937
  peg$startRuleFunction = peg$startRuleFunctions[options.startRule];
@@ -1102,10 +1039,10 @@ function peg$parse(input, options) {
1102
1039
  let s0, s1, s2;
1103
1040
  s0 = peg$currPos;
1104
1041
  s1 = [];
1105
- s2 = peg$parseTokenItem();
1106
- while (s2 !== peg$FAILED) {
1107
- s1.push(s2);
1042
+ for (;;) {
1108
1043
  s2 = peg$parseTokenItem();
1044
+ if (s2 === peg$FAILED) break;
1045
+ s1.push(s2);
1109
1046
  }
1110
1047
  peg$savedPos = s0;
1111
1048
  s1 = peg$f0(s1);
@@ -1390,15 +1327,7 @@ function peg$parse(input, options) {
1390
1327
  if (s1 !== peg$FAILED) {
1391
1328
  s2 = peg$currPos;
1392
1329
  s3 = [];
1393
- if (input.length > peg$currPos) {
1394
- s4 = input.charAt(peg$currPos);
1395
- peg$currPos++;
1396
- } else {
1397
- s4 = peg$FAILED;
1398
- if (peg$silentFails === 0) peg$fail(peg$e0);
1399
- }
1400
- while (s4 !== peg$FAILED) {
1401
- s3.push(s4);
1330
+ for (;;) {
1402
1331
  if (input.length > peg$currPos) {
1403
1332
  s4 = input.charAt(peg$currPos);
1404
1333
  peg$currPos++;
@@ -1406,6 +1335,8 @@ function peg$parse(input, options) {
1406
1335
  s4 = peg$FAILED;
1407
1336
  if (peg$silentFails === 0) peg$fail(peg$e0);
1408
1337
  }
1338
+ if (s4 === peg$FAILED) break;
1339
+ s3.push(s4);
1409
1340
  }
1410
1341
  s2 = input.substring(s2, peg$currPos);
1411
1342
  peg$savedPos = s0;
@@ -1431,22 +1362,17 @@ function peg$parse(input, options) {
1431
1362
  s0 = peg$currPos;
1432
1363
  s1 = peg$currPos;
1433
1364
  s2 = [];
1434
- s3 = input.charAt(peg$currPos);
1435
- if (peg$r0.test(s3)) peg$currPos++;
1436
- else {
1437
- s3 = peg$FAILED;
1438
- if (peg$silentFails === 0) peg$fail(peg$e1);
1439
- }
1440
- if (s3 !== peg$FAILED) while (s3 !== peg$FAILED) {
1441
- s2.push(s3);
1365
+ for (;;) {
1442
1366
  s3 = input.charAt(peg$currPos);
1443
- if (peg$r0.test(s3)) peg$currPos++;
1367
+ if (s3 !== "" && !(peg$charCode = s3.charCodeAt(0), peg$charCode === 92 || peg$charCode === 123 || peg$charCode === 91 || peg$charCode === 60)) peg$currPos++;
1444
1368
  else {
1445
1369
  s3 = peg$FAILED;
1446
1370
  if (peg$silentFails === 0) peg$fail(peg$e1);
1447
1371
  }
1372
+ if (s3 === peg$FAILED) break;
1373
+ s2.push(s3);
1448
1374
  }
1449
- else s2 = peg$FAILED;
1375
+ if (s2.length < 1) s2 = peg$FAILED;
1450
1376
  if (s2 !== peg$FAILED) s1 = input.substring(s1, peg$currPos);
1451
1377
  else s1 = s2;
1452
1378
  if (s1 !== peg$FAILED) {
@@ -1492,43 +1418,7 @@ function peg$parse(input, options) {
1492
1418
  else s5 = peg$FAILED;
1493
1419
  if (s5 !== peg$FAILED) {
1494
1420
  s6 = [];
1495
- s7 = peg$currPos;
1496
- s8 = peg$currPos;
1497
- peg$silentFails++;
1498
- if (input.substr(peg$currPos, 3) === peg$c3) {
1499
- s9 = peg$c3;
1500
- peg$currPos += 3;
1501
- } else {
1502
- s9 = peg$FAILED;
1503
- if (peg$silentFails === 0) peg$fail(peg$e5);
1504
- }
1505
- peg$silentFails--;
1506
- if (s9 === peg$FAILED) s8 = void 0;
1507
- else {
1508
- peg$currPos = s8;
1509
- s8 = peg$FAILED;
1510
- }
1511
- if (s8 !== peg$FAILED) {
1512
- if (input.length > peg$currPos) {
1513
- s9 = input.charAt(peg$currPos);
1514
- peg$currPos++;
1515
- } else {
1516
- s9 = peg$FAILED;
1517
- if (peg$silentFails === 0) peg$fail(peg$e0);
1518
- }
1519
- if (s9 !== peg$FAILED) {
1520
- s8 = [s8, s9];
1521
- s7 = s8;
1522
- } else {
1523
- peg$currPos = s7;
1524
- s7 = peg$FAILED;
1525
- }
1526
- } else {
1527
- peg$currPos = s7;
1528
- s7 = peg$FAILED;
1529
- }
1530
- while (s7 !== peg$FAILED) {
1531
- s6.push(s7);
1421
+ for (;;) {
1532
1422
  s7 = peg$currPos;
1533
1423
  s8 = peg$currPos;
1534
1424
  peg$silentFails++;
@@ -1564,6 +1454,8 @@ function peg$parse(input, options) {
1564
1454
  peg$currPos = s7;
1565
1455
  s7 = peg$FAILED;
1566
1456
  }
1457
+ if (s7 === peg$FAILED) break;
1458
+ s6.push(s7);
1567
1459
  }
1568
1460
  if (input.substr(peg$currPos, 3) === peg$c3) {
1569
1461
  s7 = peg$c3;
@@ -1615,15 +1507,7 @@ function peg$parse(input, options) {
1615
1507
  s0 = peg$currPos;
1616
1508
  s1 = peg$currPos;
1617
1509
  s2 = [];
1618
- if (input.charCodeAt(peg$currPos) === 92) {
1619
- s3 = peg$c4;
1620
- peg$currPos++;
1621
- } else {
1622
- s3 = peg$FAILED;
1623
- if (peg$silentFails === 0) peg$fail(peg$e6);
1624
- }
1625
- if (s3 !== peg$FAILED) while (s3 !== peg$FAILED) {
1626
- s2.push(s3);
1510
+ for (;;) {
1627
1511
  if (input.charCodeAt(peg$currPos) === 92) {
1628
1512
  s3 = peg$c4;
1629
1513
  peg$currPos++;
@@ -1631,8 +1515,10 @@ function peg$parse(input, options) {
1631
1515
  s3 = peg$FAILED;
1632
1516
  if (peg$silentFails === 0) peg$fail(peg$e6);
1633
1517
  }
1518
+ if (s3 === peg$FAILED) break;
1519
+ s2.push(s3);
1634
1520
  }
1635
- else s2 = peg$FAILED;
1521
+ if (s2.length < 1) s2 = peg$FAILED;
1636
1522
  if (s2 !== peg$FAILED) s1 = input.substring(s1, peg$currPos);
1637
1523
  else s1 = s2;
1638
1524
  if (s1 !== peg$FAILED) {
@@ -1643,7 +1529,7 @@ function peg$parse(input, options) {
1643
1529
  else s3 = peg$FAILED;
1644
1530
  if (s3 !== peg$FAILED) {
1645
1531
  s4 = input.charAt(peg$currPos);
1646
- if (peg$r1.test(s4)) peg$currPos++;
1532
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode === 123 || peg$charCode === 125) peg$currPos++;
1647
1533
  else {
1648
1534
  s4 = peg$FAILED;
1649
1535
  if (peg$silentFails === 0) peg$fail(peg$e7);
@@ -1685,7 +1571,7 @@ function peg$parse(input, options) {
1685
1571
  s4 = peg$parseSelectors();
1686
1572
  if (s4 !== peg$FAILED) {
1687
1573
  s5 = input.charAt(peg$currPos);
1688
- if (peg$r2.test(s5)) peg$currPos++;
1574
+ if (peg$charCode = s5.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37 || peg$charCode === 40 || peg$charCode === 33 || peg$charCode === 47 || peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90) peg$currPos++;
1689
1575
  else {
1690
1576
  s5 = peg$FAILED;
1691
1577
  if (peg$silentFails === 0) peg$fail(peg$e9);
@@ -1864,52 +1750,7 @@ function peg$parse(input, options) {
1864
1750
  function peg$parseLinkText() {
1865
1751
  let s0, s1, s2, s3;
1866
1752
  s0 = [];
1867
- s1 = peg$currPos;
1868
- s2 = peg$currPos;
1869
- peg$silentFails++;
1870
- if (input.substr(peg$currPos, 2) === peg$c9) {
1871
- s3 = peg$c9;
1872
- peg$currPos += 2;
1873
- } else {
1874
- s3 = peg$FAILED;
1875
- if (peg$silentFails === 0) peg$fail(peg$e13);
1876
- }
1877
- if (s3 === peg$FAILED) {
1878
- if (input.substr(peg$currPos, 2) === peg$c8) {
1879
- s3 = peg$c8;
1880
- peg$currPos += 2;
1881
- } else {
1882
- s3 = peg$FAILED;
1883
- if (peg$silentFails === 0) peg$fail(peg$e12);
1884
- }
1885
- }
1886
- peg$silentFails--;
1887
- if (s3 === peg$FAILED) s2 = void 0;
1888
- else {
1889
- peg$currPos = s2;
1890
- s2 = peg$FAILED;
1891
- }
1892
- if (s2 !== peg$FAILED) {
1893
- if (input.length > peg$currPos) {
1894
- s3 = input.charAt(peg$currPos);
1895
- peg$currPos++;
1896
- } else {
1897
- s3 = peg$FAILED;
1898
- if (peg$silentFails === 0) peg$fail(peg$e0);
1899
- }
1900
- if (s3 !== peg$FAILED) {
1901
- s2 = [s2, s3];
1902
- s1 = s2;
1903
- } else {
1904
- peg$currPos = s1;
1905
- s1 = peg$FAILED;
1906
- }
1907
- } else {
1908
- peg$currPos = s1;
1909
- s1 = peg$FAILED;
1910
- }
1911
- while (s1 !== peg$FAILED) {
1912
- s0.push(s1);
1753
+ for (;;) {
1913
1754
  s1 = peg$currPos;
1914
1755
  s2 = peg$currPos;
1915
1756
  peg$silentFails++;
@@ -1954,6 +1795,8 @@ function peg$parse(input, options) {
1954
1795
  peg$currPos = s1;
1955
1796
  s1 = peg$FAILED;
1956
1797
  }
1798
+ if (s1 === peg$FAILED) break;
1799
+ s0.push(s1);
1957
1800
  }
1958
1801
  return s0;
1959
1802
  }
@@ -1961,12 +1804,12 @@ function peg$parse(input, options) {
1961
1804
  let s0, s1, s2;
1962
1805
  s0 = peg$currPos;
1963
1806
  s1 = [];
1964
- s2 = peg$parseSelectorPart();
1965
- if (s2 !== peg$FAILED) while (s2 !== peg$FAILED) {
1966
- s1.push(s2);
1807
+ for (;;) {
1967
1808
  s2 = peg$parseSelectorPart();
1809
+ if (s2 === peg$FAILED) break;
1810
+ s1.push(s2);
1968
1811
  }
1969
- else s1 = peg$FAILED;
1812
+ if (s1.length < 1) s1 = peg$FAILED;
1970
1813
  if (s1 !== peg$FAILED) {
1971
1814
  if (input.charCodeAt(peg$currPos) === 32) {
1972
1815
  s2 = peg$c10;
@@ -1998,15 +1841,7 @@ function peg$parse(input, options) {
1998
1841
  if (s1 !== peg$FAILED) {
1999
1842
  s2 = peg$parseHere();
2000
1843
  s3 = [];
2001
- if (input.length > peg$currPos) {
2002
- s4 = input.charAt(peg$currPos);
2003
- peg$currPos++;
2004
- } else {
2005
- s4 = peg$FAILED;
2006
- if (peg$silentFails === 0) peg$fail(peg$e0);
2007
- }
2008
- while (s4 !== peg$FAILED) {
2009
- s3.push(s4);
1844
+ for (;;) {
2010
1845
  if (input.length > peg$currPos) {
2011
1846
  s4 = input.charAt(peg$currPos);
2012
1847
  peg$currPos++;
@@ -2014,6 +1849,8 @@ function peg$parse(input, options) {
2014
1849
  s4 = peg$FAILED;
2015
1850
  if (peg$silentFails === 0) peg$fail(peg$e0);
2016
1851
  }
1852
+ if (s4 === peg$FAILED) break;
1853
+ s3.push(s4);
2017
1854
  }
2018
1855
  peg$savedPos = s0;
2019
1856
  s0 = peg$f39(s1, s2);
@@ -2027,7 +1864,7 @@ function peg$parse(input, options) {
2027
1864
  let s0, s1, s2, s3, s4;
2028
1865
  s0 = peg$currPos;
2029
1866
  s1 = input.charAt(peg$currPos);
2030
- if (peg$r3.test(s1)) peg$currPos++;
1867
+ if (peg$charCode = s1.charCodeAt(0), peg$charCode === 46 || peg$charCode === 35) peg$currPos++;
2031
1868
  else {
2032
1869
  s1 = peg$FAILED;
2033
1870
  if (peg$silentFails === 0) peg$fail(peg$e15);
@@ -2035,10 +1872,10 @@ function peg$parse(input, options) {
2035
1872
  if (s1 !== peg$FAILED) {
2036
1873
  s2 = peg$currPos;
2037
1874
  s3 = [];
2038
- s4 = peg$parseSelectorChar();
2039
- while (s4 !== peg$FAILED) {
2040
- s3.push(s4);
1875
+ for (;;) {
2041
1876
  s4 = peg$parseSelectorChar();
1877
+ if (s4 === peg$FAILED) break;
1878
+ s3.push(s4);
2042
1879
  }
2043
1880
  s2 = input.substring(s2, peg$currPos);
2044
1881
  peg$savedPos = s0;
@@ -2052,7 +1889,7 @@ function peg$parse(input, options) {
2052
1889
  function peg$parseSelectorChar() {
2053
1890
  let s0, s1, s2, s3, s4;
2054
1891
  s0 = input.charAt(peg$currPos);
2055
- if (peg$r4.test(s0)) peg$currPos++;
1892
+ if (peg$charCode = s0.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 95 || peg$charCode === 45) peg$currPos++;
2056
1893
  else {
2057
1894
  s0 = peg$FAILED;
2058
1895
  if (peg$silentFails === 0) peg$fail(peg$e16);
@@ -2068,27 +1905,22 @@ function peg$parse(input, options) {
2068
1905
  }
2069
1906
  if (s1 !== peg$FAILED) {
2070
1907
  s2 = input.charAt(peg$currPos);
2071
- if (peg$r5.test(s2)) peg$currPos++;
1908
+ if (peg$charCode = s2.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37) peg$currPos++;
2072
1909
  else {
2073
1910
  s2 = peg$FAILED;
2074
1911
  if (peg$silentFails === 0) peg$fail(peg$e17);
2075
1912
  }
2076
1913
  if (s2 !== peg$FAILED) {
2077
1914
  s3 = [];
2078
- s4 = input.charAt(peg$currPos);
2079
- if (peg$r6.test(s4)) peg$currPos++;
2080
- else {
2081
- s4 = peg$FAILED;
2082
- if (peg$silentFails === 0) peg$fail(peg$e18);
2083
- }
2084
- while (s4 !== peg$FAILED) {
2085
- s3.push(s4);
1915
+ for (;;) {
2086
1916
  s4 = input.charAt(peg$currPos);
2087
- if (peg$r6.test(s4)) peg$currPos++;
1917
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 95 || peg$charCode === 46) peg$currPos++;
2088
1918
  else {
2089
1919
  s4 = peg$FAILED;
2090
1920
  if (peg$silentFails === 0) peg$fail(peg$e18);
2091
1921
  }
1922
+ if (s4 === peg$FAILED) break;
1923
+ s3.push(s4);
2092
1924
  }
2093
1925
  if (input.charCodeAt(peg$currPos) === 125) {
2094
1926
  s4 = peg$c11;
@@ -2135,7 +1967,7 @@ function peg$parse(input, options) {
2135
1967
  s3 = peg$parseSelectors();
2136
1968
  if (s3 !== peg$FAILED) {
2137
1969
  s4 = input.charAt(peg$currPos);
2138
- if (peg$r5.test(s4)) peg$currPos++;
1970
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37) peg$currPos++;
2139
1971
  else {
2140
1972
  s4 = peg$FAILED;
2141
1973
  if (peg$silentFails === 0) peg$fail(peg$e17);
@@ -2144,20 +1976,15 @@ function peg$parse(input, options) {
2144
1976
  s5 = peg$parseHere();
2145
1977
  s6 = peg$currPos;
2146
1978
  s7 = [];
2147
- s8 = input.charAt(peg$currPos);
2148
- if (peg$r6.test(s8)) peg$currPos++;
2149
- else {
2150
- s8 = peg$FAILED;
2151
- if (peg$silentFails === 0) peg$fail(peg$e18);
2152
- }
2153
- while (s8 !== peg$FAILED) {
2154
- s7.push(s8);
1979
+ for (;;) {
2155
1980
  s8 = input.charAt(peg$currPos);
2156
- if (peg$r6.test(s8)) peg$currPos++;
1981
+ if (peg$charCode = s8.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 95 || peg$charCode === 46) peg$currPos++;
2157
1982
  else {
2158
1983
  s8 = peg$FAILED;
2159
1984
  if (peg$silentFails === 0) peg$fail(peg$e18);
2160
1985
  }
1986
+ if (s8 === peg$FAILED) break;
1987
+ s7.push(s8);
2161
1988
  }
2162
1989
  s6 = input.substring(s6, peg$currPos);
2163
1990
  s7 = peg$parseBraceEnd();
@@ -2197,7 +2024,7 @@ function peg$parse(input, options) {
2197
2024
  s5 = peg$currPos;
2198
2025
  peg$silentFails++;
2199
2026
  s6 = input.charAt(peg$currPos);
2200
- if (peg$r7.test(s6)) peg$currPos++;
2027
+ if (peg$charCode = s6.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37 || peg$charCode === 40 || peg$charCode === 33) peg$currPos++;
2201
2028
  else {
2202
2029
  s6 = peg$FAILED;
2203
2030
  if (peg$silentFails === 0) peg$fail(peg$e20);
@@ -2249,7 +2076,7 @@ function peg$parse(input, options) {
2249
2076
  s3 = peg$currPos;
2250
2077
  peg$silentFails++;
2251
2078
  s4 = input.charAt(peg$currPos);
2252
- if (peg$r7.test(s4)) peg$currPos++;
2079
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37 || peg$charCode === 40 || peg$charCode === 33) peg$currPos++;
2253
2080
  else {
2254
2081
  s4 = peg$FAILED;
2255
2082
  if (peg$silentFails === 0) peg$fail(peg$e20);
@@ -2514,27 +2341,22 @@ function peg$parse(input, options) {
2514
2341
  s0 = peg$currPos;
2515
2342
  s1 = peg$currPos;
2516
2343
  s2 = input.charAt(peg$currPos);
2517
- if (peg$r8.test(s2)) peg$currPos++;
2344
+ if (peg$charCode = s2.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90) peg$currPos++;
2518
2345
  else {
2519
2346
  s2 = peg$FAILED;
2520
2347
  if (peg$silentFails === 0) peg$fail(peg$e22);
2521
2348
  }
2522
2349
  if (s2 !== peg$FAILED) {
2523
2350
  s3 = [];
2524
- s4 = input.charAt(peg$currPos);
2525
- if (peg$r9.test(s4)) peg$currPos++;
2526
- else {
2527
- s4 = peg$FAILED;
2528
- if (peg$silentFails === 0) peg$fail(peg$e23);
2529
- }
2530
- while (s4 !== peg$FAILED) {
2531
- s3.push(s4);
2351
+ for (;;) {
2532
2352
  s4 = input.charAt(peg$currPos);
2533
- if (peg$r9.test(s4)) peg$currPos++;
2353
+ if (s4 !== "" && !(peg$charCode = s4.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13 || peg$charCode === 11 || peg$charCode === 12 || peg$charCode === 160 || peg$charCode === 5760 || peg$charCode >= 8192 && peg$charCode <= 8202 || peg$charCode === 8232 || peg$charCode === 8233 || peg$charCode === 8239 || peg$charCode === 8287 || peg$charCode === 12288 || peg$charCode === 65279 || peg$charCode === 125)) peg$currPos++;
2534
2354
  else {
2535
2355
  s4 = peg$FAILED;
2536
2356
  if (peg$silentFails === 0) peg$fail(peg$e23);
2537
2357
  }
2358
+ if (s4 === peg$FAILED) break;
2359
+ s3.push(s4);
2538
2360
  }
2539
2361
  s2 = [s2, s3];
2540
2362
  s1 = s2;
@@ -2560,22 +2382,17 @@ function peg$parse(input, options) {
2560
2382
  }
2561
2383
  if (s3 !== peg$FAILED) {
2562
2384
  s4 = [];
2563
- s5 = input.charAt(peg$currPos);
2564
- if (peg$r10.test(s5)) peg$currPos++;
2565
- else {
2566
- s5 = peg$FAILED;
2567
- if (peg$silentFails === 0) peg$fail(peg$e24);
2568
- }
2569
- if (s5 !== peg$FAILED) while (s5 !== peg$FAILED) {
2570
- s4.push(s5);
2385
+ for (;;) {
2571
2386
  s5 = input.charAt(peg$currPos);
2572
- if (peg$r10.test(s5)) peg$currPos++;
2387
+ if (peg$charCode = s5.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 46 || peg$charCode === 33 || peg$charCode === 35 || peg$charCode === 36 || peg$charCode === 37 || peg$charCode === 38 || peg$charCode === 39 || peg$charCode === 42 || peg$charCode === 43 || peg$charCode === 47 || peg$charCode === 61 || peg$charCode === 63 || peg$charCode === 94 || peg$charCode === 95 || peg$charCode === 96 || peg$charCode === 124 || peg$charCode === 126 || peg$charCode === 45) peg$currPos++;
2573
2388
  else {
2574
2389
  s5 = peg$FAILED;
2575
2390
  if (peg$silentFails === 0) peg$fail(peg$e24);
2576
2391
  }
2392
+ if (s5 === peg$FAILED) break;
2393
+ s4.push(s5);
2577
2394
  }
2578
- else s4 = peg$FAILED;
2395
+ if (s4.length < 1) s4 = peg$FAILED;
2579
2396
  if (s4 !== peg$FAILED) {
2580
2397
  if (input.charCodeAt(peg$currPos) === 64) {
2581
2398
  s5 = peg$c13;
@@ -2586,22 +2403,17 @@ function peg$parse(input, options) {
2586
2403
  }
2587
2404
  if (s5 !== peg$FAILED) {
2588
2405
  s6 = [];
2589
- s7 = input.charAt(peg$currPos);
2590
- if (peg$r11.test(s7)) peg$currPos++;
2591
- else {
2592
- s7 = peg$FAILED;
2593
- if (peg$silentFails === 0) peg$fail(peg$e26);
2594
- }
2595
- if (s7 !== peg$FAILED) while (s7 !== peg$FAILED) {
2596
- s6.push(s7);
2406
+ for (;;) {
2597
2407
  s7 = input.charAt(peg$currPos);
2598
- if (peg$r11.test(s7)) peg$currPos++;
2408
+ if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 46 || peg$charCode === 45) peg$currPos++;
2599
2409
  else {
2600
2410
  s7 = peg$FAILED;
2601
2411
  if (peg$silentFails === 0) peg$fail(peg$e26);
2602
2412
  }
2413
+ if (s7 === peg$FAILED) break;
2414
+ s6.push(s7);
2603
2415
  }
2604
- else s6 = peg$FAILED;
2416
+ if (s6.length < 1) s6 = peg$FAILED;
2605
2417
  if (s6 !== peg$FAILED) {
2606
2418
  if (input.charCodeAt(peg$currPos) === 62) {
2607
2419
  s7 = peg$c1;
@@ -2673,7 +2485,7 @@ function peg$parse(input, options) {
2673
2485
  }
2674
2486
  if (s3 !== peg$FAILED) {
2675
2487
  s4 = input.charAt(peg$currPos);
2676
- if (peg$r8.test(s4)) peg$currPos++;
2488
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90) peg$currPos++;
2677
2489
  else {
2678
2490
  s4 = peg$FAILED;
2679
2491
  if (peg$silentFails === 0) peg$fail(peg$e22);
@@ -2682,7 +2494,7 @@ function peg$parse(input, options) {
2682
2494
  s5 = peg$currPos;
2683
2495
  s6 = [];
2684
2496
  s7 = input.charAt(peg$currPos);
2685
- if (peg$r12.test(s7)) peg$currPos++;
2497
+ if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 43 || peg$charCode === 46 || peg$charCode === 45) peg$currPos++;
2686
2498
  else {
2687
2499
  s7 = peg$FAILED;
2688
2500
  if (peg$silentFails === 0) peg$fail(peg$e27);
@@ -2692,7 +2504,7 @@ function peg$parse(input, options) {
2692
2504
  if (s6.length >= 31) s7 = peg$FAILED;
2693
2505
  else {
2694
2506
  s7 = input.charAt(peg$currPos);
2695
- if (peg$r12.test(s7)) peg$currPos++;
2507
+ if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 43 || peg$charCode === 46 || peg$charCode === 45) peg$currPos++;
2696
2508
  else {
2697
2509
  s7 = peg$FAILED;
2698
2510
  if (peg$silentFails === 0) peg$fail(peg$e27);
@@ -2713,42 +2525,7 @@ function peg$parse(input, options) {
2713
2525
  }
2714
2526
  if (s6 !== peg$FAILED) {
2715
2527
  s7 = [];
2716
- s8 = peg$currPos;
2717
- s9 = peg$currPos;
2718
- peg$silentFails++;
2719
- if (input.substr(peg$currPos, 2) === peg$c8) {
2720
- s10 = peg$c8;
2721
- peg$currPos += 2;
2722
- } else {
2723
- s10 = peg$FAILED;
2724
- if (peg$silentFails === 0) peg$fail(peg$e12);
2725
- }
2726
- peg$silentFails--;
2727
- if (s10 === peg$FAILED) s9 = void 0;
2728
- else {
2729
- peg$currPos = s9;
2730
- s9 = peg$FAILED;
2731
- }
2732
- if (s9 !== peg$FAILED) {
2733
- s10 = input.charAt(peg$currPos);
2734
- if (peg$r13.test(s10)) peg$currPos++;
2735
- else {
2736
- s10 = peg$FAILED;
2737
- if (peg$silentFails === 0) peg$fail(peg$e29);
2738
- }
2739
- if (s10 !== peg$FAILED) {
2740
- s9 = [s9, s10];
2741
- s8 = s9;
2742
- } else {
2743
- peg$currPos = s8;
2744
- s8 = peg$FAILED;
2745
- }
2746
- } else {
2747
- peg$currPos = s8;
2748
- s8 = peg$FAILED;
2749
- }
2750
- while (s8 !== peg$FAILED) {
2751
- s7.push(s8);
2528
+ for (;;) {
2752
2529
  s8 = peg$currPos;
2753
2530
  s9 = peg$currPos;
2754
2531
  peg$silentFails++;
@@ -2767,7 +2544,7 @@ function peg$parse(input, options) {
2767
2544
  }
2768
2545
  if (s9 !== peg$FAILED) {
2769
2546
  s10 = input.charAt(peg$currPos);
2770
- if (peg$r13.test(s10)) peg$currPos++;
2547
+ if (s10 !== "" && !(peg$charCode = s10.charCodeAt(0), peg$charCode >= 0 && peg$charCode <= 32 || peg$charCode === 127 || peg$charCode === 60 || peg$charCode === 62 || peg$charCode === 123 || peg$charCode === 125)) peg$currPos++;
2771
2548
  else {
2772
2549
  s10 = peg$FAILED;
2773
2550
  if (peg$silentFails === 0) peg$fail(peg$e29);
@@ -2783,6 +2560,8 @@ function peg$parse(input, options) {
2783
2560
  peg$currPos = s8;
2784
2561
  s8 = peg$FAILED;
2785
2562
  }
2563
+ if (s8 === peg$FAILED) break;
2564
+ s7.push(s8);
2786
2565
  }
2787
2566
  if (input.charCodeAt(peg$currPos) === 62) {
2788
2567
  s8 = peg$c1;
@@ -2845,10 +2624,10 @@ function peg$parse(input, options) {
2845
2624
  s3 = peg$parseTagName();
2846
2625
  if (s3 !== peg$FAILED) {
2847
2626
  s4 = [];
2848
- s5 = peg$parseAttribute();
2849
- while (s5 !== peg$FAILED) {
2850
- s4.push(s5);
2627
+ for (;;) {
2851
2628
  s5 = peg$parseAttribute();
2629
+ if (s5 === peg$FAILED) break;
2630
+ s4.push(s5);
2852
2631
  }
2853
2632
  s5 = peg$parse_();
2854
2633
  if (input.charCodeAt(peg$currPos) === 47) {
@@ -2897,7 +2676,7 @@ function peg$parse(input, options) {
2897
2676
  s3 = peg$currPos;
2898
2677
  peg$silentFails++;
2899
2678
  s4 = input.charAt(peg$currPos);
2900
- if (peg$r14.test(s4)) peg$currPos++;
2679
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode >= 9 && peg$charCode <= 13 || peg$charCode === 32 || peg$charCode === 47 || peg$charCode === 62 || peg$charCode === 160 || peg$charCode === 5760 || peg$charCode >= 8192 && peg$charCode <= 8202 || peg$charCode >= 8232 && peg$charCode <= 8233 || peg$charCode === 8239 || peg$charCode === 8287 || peg$charCode === 12288 || peg$charCode === 65279) peg$currPos++;
2901
2680
  else {
2902
2681
  s4 = peg$FAILED;
2903
2682
  if (peg$silentFails === 0) peg$fail(peg$e30);
@@ -2926,10 +2705,10 @@ function peg$parse(input, options) {
2926
2705
  } else s3 = peg$FAILED;
2927
2706
  if (s3 !== peg$FAILED) {
2928
2707
  s4 = [];
2929
- s5 = peg$parseAttribute();
2930
- while (s5 !== peg$FAILED) {
2931
- s4.push(s5);
2708
+ for (;;) {
2932
2709
  s5 = peg$parseAttribute();
2710
+ if (s5 === peg$FAILED) break;
2711
+ s4.push(s5);
2933
2712
  }
2934
2713
  s5 = peg$parse_();
2935
2714
  s6 = peg$parseHere();
@@ -2994,27 +2773,22 @@ function peg$parse(input, options) {
2994
2773
  s0 = peg$currPos;
2995
2774
  s1 = peg$currPos;
2996
2775
  s2 = input.charAt(peg$currPos);
2997
- if (peg$r8.test(s2)) peg$currPos++;
2776
+ if (peg$charCode = s2.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90) peg$currPos++;
2998
2777
  else {
2999
2778
  s2 = peg$FAILED;
3000
2779
  if (peg$silentFails === 0) peg$fail(peg$e22);
3001
2780
  }
3002
2781
  if (s2 !== peg$FAILED) {
3003
2782
  s3 = [];
3004
- s4 = input.charAt(peg$currPos);
3005
- if (peg$r15.test(s4)) peg$currPos++;
3006
- else {
3007
- s4 = peg$FAILED;
3008
- if (peg$silentFails === 0) peg$fail(peg$e32);
3009
- }
3010
- while (s4 !== peg$FAILED) {
3011
- s3.push(s4);
2783
+ for (;;) {
3012
2784
  s4 = input.charAt(peg$currPos);
3013
- if (peg$r15.test(s4)) peg$currPos++;
2785
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90 || peg$charCode >= 48 && peg$charCode <= 57 || peg$charCode === 45) peg$currPos++;
3014
2786
  else {
3015
2787
  s4 = peg$FAILED;
3016
2788
  if (peg$silentFails === 0) peg$fail(peg$e32);
3017
2789
  }
2790
+ if (s4 === peg$FAILED) break;
2791
+ s3.push(s4);
3018
2792
  }
3019
2793
  s2 = [s2, s3];
3020
2794
  s1 = s2;
@@ -3033,47 +2807,12 @@ function peg$parse(input, options) {
3033
2807
  s2 = peg$parseHere();
3034
2808
  s3 = peg$currPos;
3035
2809
  s4 = [];
3036
- s5 = peg$currPos;
3037
- s6 = peg$currPos;
3038
- peg$silentFails++;
3039
- s7 = input.charAt(peg$currPos);
3040
- if (peg$r16.test(s7)) peg$currPos++;
3041
- else {
3042
- s7 = peg$FAILED;
3043
- if (peg$silentFails === 0) peg$fail(peg$e33);
3044
- }
3045
- peg$silentFails--;
3046
- if (s7 === peg$FAILED) s6 = void 0;
3047
- else {
3048
- peg$currPos = s6;
3049
- s6 = peg$FAILED;
3050
- }
3051
- if (s6 !== peg$FAILED) {
3052
- if (input.length > peg$currPos) {
3053
- s7 = input.charAt(peg$currPos);
3054
- peg$currPos++;
3055
- } else {
3056
- s7 = peg$FAILED;
3057
- if (peg$silentFails === 0) peg$fail(peg$e0);
3058
- }
3059
- if (s7 !== peg$FAILED) {
3060
- s6 = [s6, s7];
3061
- s5 = s6;
3062
- } else {
3063
- peg$currPos = s5;
3064
- s5 = peg$FAILED;
3065
- }
3066
- } else {
3067
- peg$currPos = s5;
3068
- s5 = peg$FAILED;
3069
- }
3070
- if (s5 !== peg$FAILED) while (s5 !== peg$FAILED) {
3071
- s4.push(s5);
2810
+ for (;;) {
3072
2811
  s5 = peg$currPos;
3073
2812
  s6 = peg$currPos;
3074
2813
  peg$silentFails++;
3075
2814
  s7 = input.charAt(peg$currPos);
3076
- if (peg$r16.test(s7)) peg$currPos++;
2815
+ if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 9 && peg$charCode <= 13 || peg$charCode === 32 || peg$charCode === 34 || peg$charCode === 39 || peg$charCode === 47 || peg$charCode >= 60 && peg$charCode <= 62 || peg$charCode === 123 || peg$charCode === 125 || peg$charCode === 160 || peg$charCode === 5760 || peg$charCode >= 8192 && peg$charCode <= 8202 || peg$charCode >= 8232 && peg$charCode <= 8233 || peg$charCode === 8239 || peg$charCode === 8287 || peg$charCode === 12288 || peg$charCode === 65279) peg$currPos++;
3077
2816
  else {
3078
2817
  s7 = peg$FAILED;
3079
2818
  if (peg$silentFails === 0) peg$fail(peg$e33);
@@ -3103,8 +2842,10 @@ function peg$parse(input, options) {
3103
2842
  peg$currPos = s5;
3104
2843
  s5 = peg$FAILED;
3105
2844
  }
2845
+ if (s5 === peg$FAILED) break;
2846
+ s4.push(s5);
3106
2847
  }
3107
- else s4 = peg$FAILED;
2848
+ if (s4.length < 1) s4 = peg$FAILED;
3108
2849
  if (s4 !== peg$FAILED) s3 = input.substring(s3, peg$currPos);
3109
2850
  else s3 = s4;
3110
2851
  if (s3 !== peg$FAILED) {
@@ -3163,26 +2904,18 @@ function peg$parse(input, options) {
3163
2904
  s2 = peg$parseHere();
3164
2905
  s3 = peg$currPos;
3165
2906
  s4 = [];
3166
- s5 = peg$parseValuePart();
3167
- if (s5 === peg$FAILED) {
3168
- s5 = input.charAt(peg$currPos);
3169
- if (peg$r17.test(s5)) peg$currPos++;
3170
- else {
3171
- s5 = peg$FAILED;
3172
- if (peg$silentFails === 0) peg$fail(peg$e36);
3173
- }
3174
- }
3175
- while (s5 !== peg$FAILED) {
3176
- s4.push(s5);
2907
+ for (;;) {
3177
2908
  s5 = peg$parseValuePart();
3178
2909
  if (s5 === peg$FAILED) {
3179
2910
  s5 = input.charAt(peg$currPos);
3180
- if (peg$r17.test(s5)) peg$currPos++;
2911
+ if (s5 !== "" && !(peg$charCode = s5.charCodeAt(0), peg$charCode === 34)) peg$currPos++;
3181
2912
  else {
3182
2913
  s5 = peg$FAILED;
3183
2914
  if (peg$silentFails === 0) peg$fail(peg$e36);
3184
2915
  }
3185
2916
  }
2917
+ if (s5 === peg$FAILED) break;
2918
+ s4.push(s5);
3186
2919
  }
3187
2920
  s3 = input.substring(s3, peg$currPos);
3188
2921
  s4 = peg$parseHere();
@@ -3218,26 +2951,18 @@ function peg$parse(input, options) {
3218
2951
  s2 = peg$parseHere();
3219
2952
  s3 = peg$currPos;
3220
2953
  s4 = [];
3221
- s5 = peg$parseValuePart();
3222
- if (s5 === peg$FAILED) {
3223
- s5 = input.charAt(peg$currPos);
3224
- if (peg$r18.test(s5)) peg$currPos++;
3225
- else {
3226
- s5 = peg$FAILED;
3227
- if (peg$silentFails === 0) peg$fail(peg$e38);
3228
- }
3229
- }
3230
- while (s5 !== peg$FAILED) {
3231
- s4.push(s5);
2954
+ for (;;) {
3232
2955
  s5 = peg$parseValuePart();
3233
2956
  if (s5 === peg$FAILED) {
3234
2957
  s5 = input.charAt(peg$currPos);
3235
- if (peg$r18.test(s5)) peg$currPos++;
2958
+ if (s5 !== "" && !(peg$charCode = s5.charCodeAt(0), peg$charCode === 39)) peg$currPos++;
3236
2959
  else {
3237
2960
  s5 = peg$FAILED;
3238
2961
  if (peg$silentFails === 0) peg$fail(peg$e38);
3239
2962
  }
3240
2963
  }
2964
+ if (s5 === peg$FAILED) break;
2965
+ s4.push(s5);
3241
2966
  }
3242
2967
  s3 = input.substring(s3, peg$currPos);
3243
2968
  s4 = peg$parseHere();
@@ -3263,7 +2988,7 @@ function peg$parse(input, options) {
3263
2988
  if (s0 === peg$FAILED) {
3264
2989
  s0 = peg$currPos;
3265
2990
  s1 = input.charAt(peg$currPos);
3266
- if (peg$r19.test(s1)) peg$currPos++;
2991
+ if (peg$charCode = s1.charCodeAt(0), peg$charCode === 34 || peg$charCode === 39) peg$currPos++;
3267
2992
  else {
3268
2993
  s1 = peg$FAILED;
3269
2994
  if (peg$silentFails === 0) peg$fail(peg$e39);
@@ -3278,20 +3003,15 @@ function peg$parse(input, options) {
3278
3003
  s1 = peg$parseHere();
3279
3004
  s2 = peg$currPos;
3280
3005
  s3 = [];
3281
- s4 = input.charAt(peg$currPos);
3282
- if (peg$r20.test(s4)) peg$currPos++;
3283
- else {
3284
- s4 = peg$FAILED;
3285
- if (peg$silentFails === 0) peg$fail(peg$e40);
3286
- }
3287
- while (s4 !== peg$FAILED) {
3288
- s3.push(s4);
3006
+ for (;;) {
3289
3007
  s4 = input.charAt(peg$currPos);
3290
- if (peg$r20.test(s4)) peg$currPos++;
3008
+ if (s4 !== "" && !(peg$charCode = s4.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13 || peg$charCode === 11 || peg$charCode === 12 || peg$charCode === 160 || peg$charCode === 5760 || peg$charCode >= 8192 && peg$charCode <= 8202 || peg$charCode === 8232 || peg$charCode === 8233 || peg$charCode === 8239 || peg$charCode === 8287 || peg$charCode === 12288 || peg$charCode === 65279 || peg$charCode === 62)) peg$currPos++;
3291
3009
  else {
3292
3010
  s4 = peg$FAILED;
3293
3011
  if (peg$silentFails === 0) peg$fail(peg$e40);
3294
3012
  }
3013
+ if (s4 === peg$FAILED) break;
3014
+ s3.push(s4);
3295
3015
  }
3296
3016
  s2 = input.substring(s2, peg$currPos);
3297
3017
  s3 = peg$parseHere();
@@ -3312,15 +3032,7 @@ function peg$parse(input, options) {
3312
3032
  if (s1 !== peg$FAILED) {
3313
3033
  s2 = peg$currPos;
3314
3034
  s3 = [];
3315
- if (input.charCodeAt(peg$currPos) === 92) {
3316
- s4 = peg$c4;
3317
- peg$currPos++;
3318
- } else {
3319
- s4 = peg$FAILED;
3320
- if (peg$silentFails === 0) peg$fail(peg$e6);
3321
- }
3322
- if (s4 !== peg$FAILED) while (s4 !== peg$FAILED) {
3323
- s3.push(s4);
3035
+ for (;;) {
3324
3036
  if (input.charCodeAt(peg$currPos) === 92) {
3325
3037
  s4 = peg$c4;
3326
3038
  peg$currPos++;
@@ -3328,8 +3040,10 @@ function peg$parse(input, options) {
3328
3040
  s4 = peg$FAILED;
3329
3041
  if (peg$silentFails === 0) peg$fail(peg$e6);
3330
3042
  }
3043
+ if (s4 === peg$FAILED) break;
3044
+ s3.push(s4);
3331
3045
  }
3332
- else s3 = peg$FAILED;
3046
+ if (s3.length < 1) s3 = peg$FAILED;
3333
3047
  if (s3 !== peg$FAILED) s2 = input.substring(s2, peg$currPos);
3334
3048
  else s2 = s3;
3335
3049
  if (s2 !== peg$FAILED) {
@@ -3340,7 +3054,7 @@ function peg$parse(input, options) {
3340
3054
  else s4 = peg$FAILED;
3341
3055
  if (s4 !== peg$FAILED) {
3342
3056
  s5 = input.charAt(peg$currPos);
3343
- if (peg$r1.test(s5)) peg$currPos++;
3057
+ if (peg$charCode = s5.charCodeAt(0), peg$charCode === 123 || peg$charCode === 125) peg$currPos++;
3344
3058
  else {
3345
3059
  s5 = peg$FAILED;
3346
3060
  if (peg$silentFails === 0) peg$fail(peg$e7);
@@ -3508,7 +3222,7 @@ function peg$parse(input, options) {
3508
3222
  }
3509
3223
  if (s6 === peg$FAILED) s6 = null;
3510
3224
  s7 = input.charAt(peg$currPos);
3511
- if (peg$r8.test(s7)) peg$currPos++;
3225
+ if (peg$charCode = s7.charCodeAt(0), peg$charCode >= 97 && peg$charCode <= 122 || peg$charCode >= 65 && peg$charCode <= 90) peg$currPos++;
3512
3226
  else {
3513
3227
  s7 = peg$FAILED;
3514
3228
  if (peg$silentFails === 0) peg$fail(peg$e22);
@@ -3582,7 +3296,7 @@ function peg$parse(input, options) {
3582
3296
  s3 = peg$currPos;
3583
3297
  peg$silentFails++;
3584
3298
  s4 = input.charAt(peg$currPos);
3585
- if (peg$r5.test(s4)) peg$currPos++;
3299
+ if (peg$charCode = s4.charCodeAt(0), peg$charCode === 36 || peg$charCode === 95 || peg$charCode === 64 || peg$charCode === 37) peg$currPos++;
3586
3300
  else {
3587
3301
  s4 = peg$FAILED;
3588
3302
  if (peg$silentFails === 0) peg$fail(peg$e17);
@@ -3633,17 +3347,17 @@ function peg$parse(input, options) {
3633
3347
  function peg$parse_() {
3634
3348
  let s0, s1;
3635
3349
  s0 = [];
3636
- s1 = peg$parse_c();
3637
- while (s1 !== peg$FAILED) {
3638
- s0.push(s1);
3350
+ for (;;) {
3639
3351
  s1 = peg$parse_c();
3352
+ if (s1 === peg$FAILED) break;
3353
+ s0.push(s1);
3640
3354
  }
3641
3355
  return s0;
3642
3356
  }
3643
3357
  function peg$parse_c() {
3644
3358
  let s0;
3645
3359
  s0 = input.charAt(peg$currPos);
3646
- if (peg$r21.test(s0)) peg$currPos++;
3360
+ if (peg$charCode = s0.charCodeAt(0), peg$charCode === 32 || peg$charCode === 9 || peg$charCode === 10 || peg$charCode === 13 || peg$charCode === 11 || peg$charCode === 12 || peg$charCode === 160 || peg$charCode === 5760 || peg$charCode >= 8192 && peg$charCode <= 8202 || peg$charCode === 8232 || peg$charCode === 8233 || peg$charCode === 8239 || peg$charCode === 8287 || peg$charCode === 12288 || peg$charCode === 65279) peg$currPos++;
3647
3361
  else {
3648
3362
  s0 = peg$FAILED;
3649
3363
  if (peg$silentFails === 0) peg$fail(peg$e41);
@@ -3739,6 +3453,51 @@ function peg$parse(input, options) {
3739
3453
  if (peg$success) return peg$result;
3740
3454
  else peg$throw();
3741
3455
  }
3456
+ // src/utils/macro-names.ts
3457
+ /**
3458
+ * Macro and widget names are case-insensitive: `{StatusBar}` invokes the
3459
+ * widget defined as `statusbar`. A NameMap keys its entries by the lowercased
3460
+ * name.
3461
+ */
3462
+ var NameMap = class extends Map {
3463
+ get(name) {
3464
+ return super.get(name.toLowerCase());
3465
+ }
3466
+ set(name, value) {
3467
+ return super.set(name.toLowerCase(), value);
3468
+ }
3469
+ has(name) {
3470
+ return super.has(name.toLowerCase());
3471
+ }
3472
+ delete(name) {
3473
+ return super.delete(name.toLowerCase());
3474
+ }
3475
+ };
3476
+ /** The latest definition of each name, using runtime replacement precedence. */
3477
+ function effectiveNamedDefinitions(definitions) {
3478
+ const latest = new NameMap();
3479
+ for (const definition of definitions) latest.set(definition.name, definition);
3480
+ return [...latest.values()];
3481
+ }
3482
+ /** A set of macro or widget names (see NameMap). */
3483
+ var NameSet = class {
3484
+ constructor(names = []) {
3485
+ this.names = new NameMap();
3486
+ for (const name of names) this.add(name);
3487
+ }
3488
+ add(name) {
3489
+ this.names.set(name, true);
3490
+ }
3491
+ has(name) {
3492
+ return this.names.has(name);
3493
+ }
3494
+ delete(name) {
3495
+ this.names.delete(name);
3496
+ }
3497
+ clear() {
3498
+ this.names.clear();
3499
+ }
3500
+ };
3742
3501
  // src/components/macros/option-clauses.ts
3743
3502
  /** The direct value clauses read by the built-in choice controls. */
3744
3503
  var OPTION_CLAUSE = "option";
@@ -9489,9 +9248,7 @@ var SigilParser = class extends Parser {
9489
9248
  if (name) {
9490
9249
  const end = at + 1 + name.length;
9491
9250
  const afterPrefix = self.type === types$1.incDec && (this.operandBeforeLast || this.breakBeforeLast);
9492
- const forced = code === 37 ? this.percentAt?.get(at) : void 0;
9493
- if (code === 64 || (forced ?? (self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)))) {
9494
- if (code === 37) this.transientsRead?.add(at);
9251
+ if (code === 64 || self.exprAllowed || afterPrefix || this.lookahead && transientAssignment(self, end)) {
9495
9252
  self.pos = end;
9496
9253
  self.finishToken(types$1.name, self.input.charAt(at) + name);
9497
9254
  return;
@@ -9514,16 +9271,31 @@ var SigilParser = class extends Parser {
9514
9271
  }
9515
9272
  const self = this;
9516
9273
  const prevType = self.type;
9274
+ const beforePreviousValue = this.prevValue;
9517
9275
  this.prevValue = isMemberDot(this.typeBeforeLast) ? void 0 : self.value;
9518
9276
  const property = type.keyword !== void 0 && isMemberDot(prevType) || (type === types$1._function || type === types$1._class) && notABody(self.input, self.pos);
9519
9277
  if (!property && (type === types$1._function || type === types$1._class)) {
9520
- const before = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere ? this.typeBeforeLast : prevType;
9521
- self.type = before === types$1.colon && this.colonEndsTernary ? types$1.parenL : before;
9278
+ const afterAsync = type === types$1._function && prevType === types$1.name && this.prevValue === "async" && !this.breakHere;
9279
+ const before = afterAsync ? this.typeBeforeLast : prevType;
9280
+ const contextualOperand = before === types$1.name && (afterAsync ? this.operandBeforeLast : self.exprAllowed) && ((afterAsync ? beforePreviousValue : this.prevValue) !== "yield" || !(afterAsync ? this.breakBeforeLast : this.breakHere));
9281
+ self.type = before === types$1.colon && this.colonEndsTernary || contextualOperand ? types$1.parenL : before;
9522
9282
  }
9523
9283
  this.typeBeforeLast = prevType;
9524
9284
  super.finishToken(property ? types$1.name : type, value);
9525
9285
  if (type === types$1.name && (isMemberDot(prevType) || value === "of" && (prevType === types$1._const || prevType === types$1._var || this.prevValue === "let"))) self.exprAllowed = false;
9526
9286
  }
9287
+ parseIdent(liberal) {
9288
+ this.exprAllowed = false;
9289
+ return super.parseIdent(liberal);
9290
+ }
9291
+ parseForIn(node, init) {
9292
+ this.exprAllowed = true;
9293
+ return super.parseForIn(node, init);
9294
+ }
9295
+ parseAwait(forInit) {
9296
+ this.exprAllowed = true;
9297
+ return super.parseAwait(forInit);
9298
+ }
9527
9299
  braceIsBlock(prevType) {
9528
9300
  if (prevType === types$1.colon && this.colonEndsTernary) return false;
9529
9301
  if (prevType === types$1.braceR && this.closedBlock) return true;
@@ -9587,10 +9359,14 @@ var CLOSERS$1 = /* @__PURE__ */ new Set([
9587
9359
  * After an operand, a `/` divides.
9588
9360
  */
9589
9361
  function tokenizerAt(src, start, goal, { onComment, afterOperand = false } = {}) {
9590
- const p = new SigilParser(onComment ? {
9362
+ const p = new SigilParser({
9591
9363
  ...OPTIONS,
9364
+ startLocation: {
9365
+ line: 1,
9366
+ column: 0
9367
+ },
9592
9368
  onComment
9593
- } : OPTIONS, src, start);
9369
+ }, src, start);
9594
9370
  if (goal === "expression") p.type = types$1.parenL;
9595
9371
  if (afterOperand) p.exprAllowed = false;
9596
9372
  return p;
@@ -9708,29 +9484,17 @@ function parseCode(src, goal = "expression") {
9708
9484
  }
9709
9485
  /** What parseCode finds in `src`, and the syntax tree it is in. */
9710
9486
  function parseWithAst(src, goal) {
9711
- const percentAt = /* @__PURE__ */ new Map();
9712
- for (;;) {
9713
- const transientsRead = /* @__PURE__ */ new Set();
9714
- try {
9715
- const ast = parseAst(src, goal, percentAt, transientsRead);
9716
- const out = {
9717
- refs: [],
9718
- strings: []
9719
- };
9720
- walk(ast, src, out, false, false);
9721
- out.refs.sort((a, b) => a.start - b.start);
9722
- return {
9723
- out,
9724
- ast
9725
- };
9726
- } catch (error) {
9727
- const pos = error.pos ?? -1;
9728
- if (!(error instanceof SyntaxError) || percentAt.has(pos)) throw error;
9729
- TRANS_NAME_RE.lastIndex = pos + 1;
9730
- if (src.charAt(pos) !== "%" || !TRANS_NAME_RE.test(src)) throw error;
9731
- percentAt.set(pos, !transientsRead.has(pos));
9732
- }
9733
- }
9487
+ const ast = parseAst(src, goal);
9488
+ const out = {
9489
+ refs: [],
9490
+ strings: []
9491
+ };
9492
+ walk(ast, src, out, false, false);
9493
+ out.refs.sort((a, b) => a.start - b.start);
9494
+ return {
9495
+ out,
9496
+ ast
9497
+ };
9734
9498
  }
9735
9499
  /**
9736
9500
  * Read `src` as a reference path: a variable with any number of `.name` and
@@ -9788,15 +9552,10 @@ function readMemberPath(src, end) {
9788
9552
  end
9789
9553
  };
9790
9554
  }
9791
- /**
9792
- * Parse `src` as `goal`, reading `%` as `percentAt` says where it says, and
9793
- * noting where it read a transient in `transientsRead`.
9794
- */
9795
- function parseAst(src, goal, percentAt, transientsRead) {
9555
+ /** Parse `src` as `goal`, using the parser's context for `%name`. */
9556
+ function parseAst(src, goal) {
9796
9557
  try {
9797
9558
  const p = tokenizerAt(src, 0, goal);
9798
- p.percentAt = percentAt;
9799
- p.transientsRead = transientsRead;
9800
9559
  if (goal === "statements") return p.parse();
9801
9560
  p.nextToken();
9802
9561
  const ast = p.parseExpression();
@@ -10009,33 +9768,54 @@ var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
10009
9768
  * what in it is no JavaScript.
10010
9769
  */
10011
9770
  function findCodeEnd(src, start, { goal = "expression", stop, onRunOut } = {}) {
10012
- const end = scanCodeEnd(src, start, goal, stop, onRunOut);
10013
- return end < 0 && !stop ? parsedCodeEnd(src, start, goal) : end;
9771
+ let verifyStop = false;
9772
+ const end = scanCodeEnd(src, start, goal, stop, onRunOut, () => {
9773
+ verifyStop = true;
9774
+ });
9775
+ if (end < 0 || verifyStop) {
9776
+ const parsed = parsedCodeEnd(src, start, goal, stop);
9777
+ if (parsed >= 0) return parsed;
9778
+ }
9779
+ return end;
10014
9780
  }
10015
9781
  /**
10016
9782
  * Where the code from `start` ends, as the parser finds it: the `}` it
10017
- * stops at, or -1. The token scan of `findCodeEnd` guesses whether a `/`
10018
- * opens a regex from the tokens before it, and a few rare constructs (a
10019
- * class field named `class` inside a template literal) mislead it; the
10020
- * parser knows. Only asked when the scan finds no end.
9783
+ * stops at (or the `{` matching `stop`), or -1. The token scan of
9784
+ * `findCodeEnd` guesses whether a `/` opens a regex from the tokens before
9785
+ * it, and class fields inside template literals can mislead it. The parser
9786
+ * knows the context. Asked when the scan finds no end or a stop that might
9787
+ * still be template text.
10021
9788
  */
10022
- function parsedCodeEnd(src, start, goal) {
9789
+ function parsedCodeEnd(src, start, goal, stop) {
10023
9790
  const p = tokenizerAt(src, start, goal);
9791
+ const stopped = {};
9792
+ let stoppedAt = -1;
9793
+ if (stop) {
9794
+ const nextToken = p.nextToken;
9795
+ p.nextToken = () => {
9796
+ nextToken.call(p);
9797
+ if (p.type === types$1.braceL && stop(p.start)) {
9798
+ stoppedAt = p.start;
9799
+ throw stopped;
9800
+ }
9801
+ };
9802
+ }
10024
9803
  try {
10025
9804
  if (goal === "statements") p.parse();
10026
9805
  else {
10027
9806
  p.nextToken();
10028
9807
  p.parseExpression();
10029
- if (p.type === types$1.braceR) return p.start;
9808
+ if (!stop && p.type === types$1.braceR) return p.start;
10030
9809
  }
10031
9810
  } catch (error) {
9811
+ if (error === stopped) return stoppedAt;
10032
9812
  const pos = error.pos ?? -1;
10033
- if (src.charAt(pos) === "}") return pos;
9813
+ if (!stop && src.charAt(pos) === "}") return pos;
10034
9814
  }
10035
9815
  return -1;
10036
9816
  }
10037
9817
  /** `findCodeEnd` by the tokens: see there. */
10038
- function scanCodeEnd(src, start, goal, stop, onRunOut) {
9818
+ function scanCodeEnd(src, start, goal, stop, onRunOut, onTemplateStop) {
10039
9819
  /** No end: the code runs to the end of `src`. */
10040
9820
  const ranOut = () => {
10041
9821
  onRunOut?.();
@@ -10047,6 +9827,7 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
10047
9827
  let from = start;
10048
9828
  let afterOperand = false;
10049
9829
  let templateSlip = false;
9830
+ let interpolated = false;
10050
9831
  for (;;) {
10051
9832
  let resumeAt = -1;
10052
9833
  for (const tok of tokens(src, from, goal, { afterOperand })) {
@@ -10075,10 +9856,15 @@ function scanCodeEnd(src, start, goal, stop, onRunOut) {
10075
9856
  prevWord = t === types$1.name && !WORDS_BEFORE_STRING.has(tok.value) || t === types$1.num;
10076
9857
  prevEnd = tok.end;
10077
9858
  if (t === types$1.braceL) {
10078
- if (stop?.(tok.start)) return tok.start;
9859
+ if (stop?.(tok.start)) {
9860
+ if (interpolated) onTemplateStop();
9861
+ return tok.start;
9862
+ }
10079
9863
  stack.push("{");
10080
- } else if (t === types$1.dollarBraceL) stack.push("${");
10081
- else if (t === types$1.parenL) stack.push("(");
9864
+ } else if (t === types$1.dollarBraceL) {
9865
+ interpolated = true;
9866
+ stack.push("${");
9867
+ } else if (t === types$1.parenL) stack.push("(");
10082
9868
  else if (t === types$1.bracketL) stack.push("[");
10083
9869
  else if (t === types$1.parenR || t === types$1.bracketR) {
10084
9870
  if (last(stack) === (t === types$1.parenR ? "(" : "[")) stack.pop();
@@ -10156,7 +9942,8 @@ function* tokens(src, start, goal, options = {}) {
10156
9942
  type: p.type,
10157
9943
  start: p.start,
10158
9944
  end: p.end,
10159
- value: p.value
9945
+ value: p.value,
9946
+ operand: p.operandHere
10160
9947
  };
10161
9948
  if (p.type === types$1.eof) return;
10162
9949
  }
@@ -10335,6 +10122,59 @@ function scanStringLiteral(src, start) {
10335
10122
  closed: false
10336
10123
  };
10337
10124
  }
10125
+ /** Read completion boundaries with the same tokenizer as runtime code. */
10126
+ function completionIdentifier(source, cursor, goal = "expression") {
10127
+ let previous;
10128
+ for (const token of tokens(source, 0, goal)) {
10129
+ if ("error" in token) {
10130
+ if (source[token.pos] === "@" && cursor === token.pos + 1) return {
10131
+ kind: "root",
10132
+ name: "",
10133
+ start: token.pos,
10134
+ end: cursor
10135
+ };
10136
+ return;
10137
+ }
10138
+ const member = previous && isMemberDot(previous.type) ? previous : void 0;
10139
+ if (token.start <= cursor && cursor <= token.end) {
10140
+ if (member && (token.type === types$1.name || token.type.keyword)) return {
10141
+ kind: "member",
10142
+ name: token.value,
10143
+ start: token.start,
10144
+ end: token.end,
10145
+ dotStart: member.start
10146
+ };
10147
+ if (token.type === types$1.name && !member) {
10148
+ const value = token.value;
10149
+ if ((sigilAt(source, token.start, value) || value === "$" || value === "_") && !keyPosition(source, token.end, previous?.type)) return {
10150
+ kind: "root",
10151
+ name: value.slice(1),
10152
+ start: token.start,
10153
+ end: token.end
10154
+ };
10155
+ }
10156
+ if (token.type === types$1.modulo && source.slice(token.start, token.end) === "%" && cursor === token.end && token.operand) return {
10157
+ kind: "root",
10158
+ name: "",
10159
+ start: token.start,
10160
+ end: token.end
10161
+ };
10162
+ }
10163
+ if (isMemberDot(token.type) && token.end === cursor) {
10164
+ previous = token;
10165
+ continue;
10166
+ }
10167
+ if (member && member.end === cursor && token.start >= cursor) return {
10168
+ kind: "member",
10169
+ name: "",
10170
+ start: cursor,
10171
+ end: cursor,
10172
+ dotStart: member.start
10173
+ };
10174
+ if (token.start > cursor || token.type === types$1.eof) return;
10175
+ previous = token;
10176
+ }
10177
+ }
10338
10178
  // src/markup/code-end.ts
10339
10179
  /**
10340
10180
  * A quote directly after a letter/digit is an apostrophe (don't), not a
@@ -12099,12 +11939,26 @@ var LITERAL = { kind: "literal" };
12099
11939
  * kind is literal when the cursor itself is inside one, a comment, or prose.
12100
11940
  */
12101
11941
  function completionContext(source, cursor, macros = []) {
12102
- if (!Number.isInteger(cursor) || cursor < 0 || cursor > source.length) throw new RangeError("cursor must be a UTF-16 offset within source");
11942
+ return readCompletion(source.slice(0, cursor), cursor, macros, false, source.length);
11943
+ }
11944
+ /** Includes the identifier suffix and its mappings through enclosing markup. */
11945
+ function completionTarget(source, cursor, macros = []) {
11946
+ return readCompletion(source, cursor, macros, true);
11947
+ }
11948
+ /** Visit the markup scopes enclosing a cursor, from outermost to innermost. */
11949
+ function completionScopes(source, cursor, macros, visit) {
11950
+ readCompletion(source, cursor, macros, true, source.length, visit);
11951
+ }
11952
+ function readCompletion(source, cursor, macros, full, sourceLength = source.length, visit) {
11953
+ if (!Number.isInteger(cursor) || cursor < 0 || cursor > sourceLength) throw new RangeError("cursor must be a UTF-16 offset within source");
12103
11954
  const parametersOf = parameterLookup(macros);
12104
11955
  const codeContext = (code, goal, map, containers) => {
12105
- const probe = code.length + 1;
11956
+ let position = 0;
11957
+ while (position < code.length && map(position) < cursor) position++;
11958
+ const prefix = code.slice(0, position);
11959
+ const probe = prefix.length + 1;
12106
11960
  let executable = false;
12107
- lexJs(code + " __spindle_cursor__", {
11961
+ lexJs(prefix + " __spindle_cursor__", {
12108
11962
  code(_ch, at) {
12109
11963
  if (at >= probe) executable = true;
12110
11964
  },
@@ -12113,6 +11967,7 @@ function completionContext(source, cursor, macros = []) {
12113
11967
  }
12114
11968
  }, goal);
12115
11969
  if (!executable) return LITERAL;
11970
+ const identifier = full ? completionIdentifier(code, position, goal) : void 0;
12116
11971
  const offset = map(0);
12117
11972
  const offsets = Array.from({ length: code.length + 1 }, (_, i) => map(i));
12118
11973
  return {
@@ -12120,7 +11975,8 @@ function completionContext(source, cursor, macros = []) {
12120
11975
  code,
12121
11976
  goal,
12122
11977
  offset,
12123
- cursor: code.length,
11978
+ cursor: position,
11979
+ ...identifier && { identifier },
12124
11980
  ...containers.length ? { containers } : {},
12125
11981
  ...offsets.some((at, i) => at !== offset + i) ? { sourceOffsets: offsets } : {}
12126
11982
  };
@@ -12130,7 +11986,7 @@ function completionContext(source, cursor, macros = []) {
12130
11986
  if (sigilsOnly) {
12131
11987
  let at = 0;
12132
11988
  for (const part of splitSigilTemplate(src, true)) if ("expr" in part) {
12133
- if (at + 1 + part.expr.length === src.length) return codeContext(part.expr, "expression", (i) => map(at + 1 + i), containers);
11989
+ if (map(at + 1) <= cursor && cursor <= map(at + 1 + part.expr.length)) return codeContext(part.expr, "expression", (i) => map(at + 1 + i), containers);
12134
11990
  at += part.expr.length + 2;
12135
11991
  } else at += ("text" in part ? part.text : part.verbatim).length;
12136
11992
  return LITERAL;
@@ -12139,14 +11995,17 @@ function completionContext(source, cursor, macros = []) {
12139
11995
  text,
12140
11996
  hooks: { isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0) }
12141
11997
  });
12142
- const token = tokens[tokens.length - 1];
12143
- if (!token || token.end !== src.length) return LITERAL;
11998
+ if (visit && !visit(tokens, map)) return LITERAL;
11999
+ const contains = (start, end) => map(start) <= cursor && cursor <= map(end);
12000
+ const index = tokens.findIndex((token) => map(token.start) < cursor && cursor <= map(token.end));
12001
+ const token = tokens[index];
12002
+ if (!token) return LITERAL;
12144
12003
  const codeAt = (code, at, goal = "expression") => codeContext(code, goal, (i) => map(at + i), containers);
12145
12004
  const nested = (value, at, offsets, onlySigils = false, container) => read(value, (i) => map(offsets?.[i] ?? at + i), true, depth + 1, onlySigils, container ? [...containers, container] : containers);
12146
- if (token.type === "variable" && token.nameEnd === src.length) return codeAt(src.slice(token.nameStart - 1), token.nameStart - 1);
12147
- if (token.type === "expression" && token.expressionEnd === src.length) return codeAt(token.expression, token.expressionStart);
12005
+ if (token.type === "variable" && contains(token.nameStart - 1, token.nameEnd)) return codeAt(src.slice(token.nameStart - 1, token.nameEnd), token.nameStart - 1);
12006
+ if (token.type === "expression" && contains(token.expressionStart, token.expressionEnd)) return codeAt(token.expression, token.expressionStart);
12148
12007
  if (token.type === "html") {
12149
- for (const { name, value, at } of attributeValues(src, token)) if (at + value.length === src.length) {
12008
+ for (const { name, value, at } of attributeValues(src, token)) if (contains(at, at + value.length)) {
12150
12009
  const span = token.attributeSpans.find((span) => span.valueStart === at);
12151
12010
  return nested(value, at, void 0, isCodeAttribute(name), {
12152
12011
  kind: "attribute",
@@ -12155,11 +12014,11 @@ function completionContext(source, cursor, macros = []) {
12155
12014
  code: isCodeAttribute(name)
12156
12015
  });
12157
12016
  }
12158
- } else if (token.type === "link" && token.displayEnd === src.length) return nested(token.display, token.displayStart, void 0, false, { kind: "link-label" });
12017
+ } else if (token.type === "link" && contains(token.displayStart, token.displayEnd)) return nested(token.display, token.displayStart, void 0, false, { kind: "link-label" });
12159
12018
  else if (token.type === "text" && !token.comment) {
12160
- const opener = tokens[tokens.length - 2];
12019
+ const opener = tokens[index - 1];
12161
12020
  if (opener?.type === "macro" && !opener.isClose && executesRawBody(opener.name, parametersOf)) return codeAt(token.value, token.start, "statements");
12162
- } else if (token.type === "macro" && !token.isClose && token.argsEnd === src.length) {
12021
+ } else if (token.type === "macro" && !token.isClose && contains(token.argsStart, token.argsEnd)) {
12163
12022
  const name = token.name.toLowerCase();
12164
12023
  const args = token.rawArgs;
12165
12024
  const widget = parametersOf.widget?.(name);
@@ -12172,29 +12031,32 @@ function completionContext(source, cursor, macros = []) {
12172
12031
  if (holds === "expression" || holds === "statements") return codeAt(raw, at, holds);
12173
12032
  return holds === "markup" ? nested(raw, at) : LITERAL;
12174
12033
  }
12175
- if (scanStringLiteral(raw, 0).closed) return LITERAL;
12176
- const value = escapes === "javascript" ? stringLiteralValue(raw + raw[0]) : quoted.value;
12034
+ const scan = scanStringLiteral(raw, 0);
12035
+ const bodyEnd = scan.closed ? scan.end - 1 : scan.end;
12036
+ if (!contains(at + 1, at + bodyEnd)) return LITERAL;
12037
+ const value = escapes === "javascript" ? stringLiteralValue(raw.slice(0, scan.end) + (scan.closed ? "" : raw[0])) : quoted.value;
12177
12038
  if (value == null) return LITERAL;
12178
12039
  const container = {
12179
12040
  kind: "string",
12180
12041
  quote: raw[0],
12181
12042
  escapes
12182
12043
  };
12183
- const offsets = escapeOffsets(raw.slice(1), at + 1, value, escapes);
12044
+ const offsets = escapeOffsets(raw.slice(1, bodyEnd), at + 1, value, escapes);
12184
12045
  if (holds === "expression" || holds === "statements") return codeContext(value, holds, (i) => map(offsets?.[i] ?? at + 1 + i), [...containers, container]);
12185
12046
  return holds === "markup" ? nested(value, at + 1, offsets, false, container) : LITERAL;
12186
12047
  };
12187
12048
  if (widget) {
12188
12049
  const spans = splitArgSpans(args);
12189
- const span = spans[spans.length - 1];
12050
+ const which = spans.findIndex(([start, end]) => contains(token.argsStart + start, token.argsStart + end));
12051
+ const span = spans[which];
12190
12052
  if (!span) return LITERAL;
12191
- const raw = args.slice(span[0]);
12192
- const holds = widget[spans.length - 1]?.holds;
12053
+ const raw = args.slice(...span);
12054
+ const holds = widget[which]?.holds;
12193
12055
  return /^["']/.test(raw) && holds ? stringContext(raw, token.argsStart + span[0], holds, "javascript") : codeAt(raw, token.argsStart + span[0]);
12194
12056
  }
12195
12057
  const params = parametersOf(name);
12196
12058
  if (!params) return LITERAL;
12197
- const spans = macroArgumentSpans(args, params).filter((span) => span.parameter.type !== "options" && span.end === args.trimEnd().length);
12059
+ const spans = macroArgumentSpans(args, params).filter((span) => span.parameter.type !== "options" && contains(token.argsStart + span.start, token.argsStart + span.end));
12198
12060
  const span = spans[spans.length - 1];
12199
12061
  if (!span) return LITERAL;
12200
12062
  const param = span.parameter;
@@ -12203,7 +12065,7 @@ function completionContext(source, cursor, macros = []) {
12203
12065
  at += param.name.length;
12204
12066
  while (/\s/.test(args.charAt(at))) at++;
12205
12067
  }
12206
- const raw = args.slice(at);
12068
+ const raw = args.slice(at, span.end);
12207
12069
  const offset = token.argsStart + at;
12208
12070
  if (param.type === "expression" || param.type === "passage") return codeAt(raw, offset);
12209
12071
  if (param.type === "statements") return codeAt(raw, offset, "statements");
@@ -12211,7 +12073,7 @@ function completionContext(source, cursor, macros = []) {
12211
12073
  }
12212
12074
  return LITERAL;
12213
12075
  };
12214
- return read(source.slice(0, cursor), (i) => i);
12076
+ return read(source, (i) => i);
12215
12077
  }
12216
12078
  // src/widgets/ast-scanner.ts
12217
12079
  /** The declared parameters of the macros registered so far. */
@@ -14376,23 +14238,13 @@ function discoverMacros(source) {
14376
14238
  }
14377
14239
  return found;
14378
14240
  }
14241
+ // src/format/source-lines.ts
14242
+ /** Index a source once; locate zero-based lines without rescanning its prefixes. */
14243
+ function sourceLines(source) {
14244
+ const position = sourcePositions(source);
14245
+ return (offset) => position(offset).line - 1;
14246
+ }
14379
14247
  // src/format/segment.ts
14380
- var VOID_ELEMENTS = /* @__PURE__ */ new Set([
14381
- "area",
14382
- "base",
14383
- "br",
14384
- "col",
14385
- "embed",
14386
- "hr",
14387
- "img",
14388
- "input",
14389
- "link",
14390
- "meta",
14391
- "param",
14392
- "source",
14393
- "track",
14394
- "wbr"
14395
- ]);
14396
14248
  /**
14397
14249
  * Segment a passage body into regions: spindle (markdown/macros), html blocks, script blocks.
14398
14250
  */
@@ -14400,6 +14252,16 @@ function segmentRegions(body) {
14400
14252
  const lines = body.split("\n");
14401
14253
  if (lines.length > 0 && lines[lines.length - 1] === "") lines.pop();
14402
14254
  if (lines.length === 0) return [];
14255
+ const tags = lines.map(() => []);
14256
+ const tagEndLines = lines.map((_, line) => line);
14257
+ const lineAt = sourceLines(body);
14258
+ for (const token of tokenizeMarkupTolerant$1(body).tokens) {
14259
+ if (token.type !== "html") continue;
14260
+ const line = lineAt(token.start);
14261
+ tags[line].push(token);
14262
+ tagEndLines[line] = Math.max(tagEndLines[line], lineAt(token.end - 1));
14263
+ }
14264
+ const depthOnLine = (line, name) => tags[line].reduce((depth, token) => token.tag.toLowerCase() === name && !token.isSelfClose ? depth + (token.isClose ? -1 : 1) : depth, 0);
14403
14265
  const regions = [];
14404
14266
  let i = 0;
14405
14267
  while (i < lines.length) {
@@ -14425,24 +14287,19 @@ function segmentRegions(body) {
14425
14287
  }
14426
14288
  if (/^<([a-zA-Z][\w-]*)/.test(trimmed)) {
14427
14289
  const tagName = trimmed.match(/^<([a-zA-Z][\w-]*)/)[1].toLowerCase();
14428
- if (VOID_ELEMENTS.has(tagName) && !lines[i + 1]?.trim().startsWith("<")) {
14429
- pushSpindleLine(regions, line);
14430
- i++;
14431
- continue;
14432
- }
14433
- if (new RegExp(`</${tagName}\\s*>`, "i").test(trimmed)) {
14290
+ let depth = depthOnLine(i, tagName);
14291
+ let endLine = tagEndLines[i];
14292
+ if (depth <= 0 && endLine === i) {
14434
14293
  pushSpindleLine(regions, line);
14435
14294
  i++;
14436
14295
  continue;
14437
14296
  }
14438
14297
  const htmlLines = [line];
14439
- let depth = 1;
14440
14298
  i++;
14441
- while (i < lines.length && depth > 0) {
14299
+ while (i < lines.length && (depth > 0 || i <= endLine)) {
14442
14300
  htmlLines.push(lines[i]);
14443
- const opens = (lines[i].match(new RegExp(`<${tagName}(?:[\\s>]|$)`, "gi")) ?? []).length;
14444
- const closes = (lines[i].match(new RegExp(`</${tagName}\\s*>`, "gi")) ?? []).length;
14445
- depth += opens - closes;
14301
+ endLine = Math.max(endLine, tagEndLines[i]);
14302
+ depth += depthOnLine(i, tagName);
14446
14303
  i++;
14447
14304
  }
14448
14305
  regions.push({
@@ -25319,12 +25176,6 @@ function unclosedHtml(text) {
25319
25176
  }
25320
25177
  } } };
25321
25178
  }
25322
- // src/format/source-lines.ts
25323
- /** Index a source once; locate zero-based lines without rescanning its prefixes. */
25324
- function sourceLines(source) {
25325
- const position = sourcePositions(source);
25326
- return (offset) => position(offset).line - 1;
25327
- }
25328
25179
  // src/format/markdown-lines.ts
25329
25180
  /** Source lines belonging to the given constructs in runtime Markdown documents. */
25330
25181
  function markdownLines(source, isBlock, types) {
@@ -26275,7 +26126,6 @@ function blockLookup(macros, includeRuntime = true) {
26275
26126
  */
26276
26127
  function macroCalls(source, macros = []) {
26277
26128
  const all = effectiveToolingMacros(macros);
26278
- const definitions = new NameMap(all.map((macro) => [macro.name, macro]));
26279
26129
  const parametersOf = parameterLookup(all);
26280
26130
  const options = tokenizationOptions({
26281
26131
  macros: all,
@@ -26284,7 +26134,31 @@ function macroCalls(source, macros = []) {
26284
26134
  const hooks = options.hooks;
26285
26135
  const tokens = tokenizeMarkupTolerant$1(source, options).tokens;
26286
26136
  const calls = [];
26137
+ const classifier = macroClassifier(all);
26287
26138
  const classify = (tokens) => {
26139
+ for (const call of classifier(tokens)) calls.push(call);
26140
+ };
26141
+ classify(tokens);
26142
+ for (const piece of passagePiecesOf(source, tokens, parametersOf, { isBlock: hooks.isBlock })) {
26143
+ if (piece.kind !== "text" || !piece.tokens.length) continue;
26144
+ classify(piece.tokens);
26145
+ }
26146
+ let literalEnd = -1;
26147
+ return calls.sort((a, b) => a.token.start - b.token.start).filter((call) => {
26148
+ if (call.token.start < literalEnd) return false;
26149
+ if (call.kind === "value" || call.kind === "branch") literalEnd = call.token.argsEnd;
26150
+ return true;
26151
+ });
26152
+ }
26153
+ /** Shared contextual dispatch for complete and unfinished grammar tokens. */
26154
+ function macroClassifier(all) {
26155
+ const definitions = new NameMap(all.map((macro) => [macro.name, macro]));
26156
+ const hooks = tokenizationOptions({
26157
+ macros: all,
26158
+ hooks: { isBlock: blockLookup(all, false) }
26159
+ }).hooks;
26160
+ return (tokens) => {
26161
+ const calls = [];
26288
26162
  const found = /* @__PURE__ */ new Map();
26289
26163
  const pending = pairMarkup(tokens, hooks).nodes.map((node) => ({ node }));
26290
26164
  while (pending.length) {
@@ -26325,18 +26199,24 @@ function macroCalls(source, macros = []) {
26325
26199
  };
26326
26200
  calls.push(call);
26327
26201
  }
26202
+ return calls;
26328
26203
  };
26329
- classify(tokens);
26330
- for (const piece of passagePiecesOf(source, tokens, parametersOf, { isBlock: hooks.isBlock })) {
26331
- if (piece.kind !== "text" || !piece.tokens.length) continue;
26332
- classify(piece.tokens);
26333
- }
26334
- let literalEnd = -1;
26335
- return calls.sort((a, b) => a.token.start - b.token.start).filter((call) => {
26336
- if (call.token.start < literalEnd) return false;
26337
- if (call.kind === "value" || call.kind === "branch") literalEnd = call.token.argsEnd;
26338
- return true;
26204
+ }
26205
+ /** The opening macro head containing a cursor, including unfinished heads. */
26206
+ function macroCallAt(source, cursor, macros = []) {
26207
+ const all = effectiveToolingMacros(macros);
26208
+ const classify = macroClassifier(all);
26209
+ let selected;
26210
+ completionScopes(source, cursor, all, (tokens, map) => {
26211
+ const call = classify(tokens).find(({ token }) => map(token.start) < cursor && cursor <= map(token.end));
26212
+ if (call) selected = {
26213
+ ...call,
26214
+ token: mapOffsets(call.token, map),
26215
+ ...call.owner && { owner: mapOffsets(call.owner, map) }
26216
+ };
26217
+ return !call || call.kind === "invocation";
26339
26218
  });
26219
+ return selected;
26340
26220
  }
26341
26221
  /**
26342
26222
  * What a passage's markup runs and names, and where: the pieces of code
@@ -26434,4 +26314,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
26434
26314
  const list = [...passages];
26435
26315
  return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
26436
26316
  }
26437
- export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
26317
+ export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, completionTarget, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCallAt, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };