@rohal12/spindle 0.62.2 → 0.62.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1087,23 +1087,29 @@ function peg$parse(input, options) {
1087
1087
  return [body ? lexeme("text", loc, { value: body }) : null, end];
1088
1088
  }
1089
1089
  function peg$f16() {
1090
+ return completionMode;
1091
+ }
1092
+ function peg$f17(body) {
1093
+ return lexeme("text", location(), { value: body });
1094
+ }
1095
+ function peg$f18() {
1090
1096
  return offset();
1091
1097
  }
1092
- function peg$f17(value) {
1098
+ function peg$f19(value) {
1093
1099
  return lexeme("text", location(), { value });
1094
1100
  }
1095
- function peg$f18(value) {
1101
+ function peg$f20(value) {
1096
1102
  const node = lexeme("text", location(), { value });
1097
1103
  node.comment = true;
1098
1104
  return node;
1099
1105
  }
1100
- function peg$f19(bs) {
1106
+ function peg$f21(bs) {
1101
1107
  return bs.length % 2 === 1;
1102
1108
  }
1103
- function peg$f20(bs, c) {
1109
+ function peg$f22(bs, c) {
1104
1110
  return c;
1105
1111
  }
1106
- function peg$f21(bs, brace) {
1112
+ function peg$f23(bs, brace) {
1107
1113
  const loc = location();
1108
1114
  const next = input.charAt(loc.end.offset);
1109
1115
  if (textMode) {
@@ -1120,48 +1126,48 @@ function peg$parse(input, options) {
1120
1126
  escaped.escape = true;
1121
1127
  return bs.length > 1 ? [before, escaped] : escaped;
1122
1128
  }
1123
- function peg$f22() {
1129
+ function peg$f24() {
1124
1130
  return lexeme("text", location(), { value: LB });
1125
1131
  }
1126
- function peg$f23() {
1132
+ function peg$f25() {
1127
1133
  return !textMode;
1128
1134
  }
1129
- function peg$f24() {
1135
+ function peg$f26() {
1130
1136
  return lexeme("text", location(), { value: "<" });
1131
1137
  }
1132
- function peg$f25() {
1138
+ function peg$f27() {
1133
1139
  return lexeme("text", location(), { value: "[" });
1134
1140
  }
1135
- function peg$f26() {
1141
+ function peg$f28() {
1136
1142
  return !textMode;
1137
1143
  }
1138
- function peg$f27(ss, s, at, inner) {
1144
+ function peg$f29(ss, s, at, inner) {
1139
1145
  const link = lexeme("link", location(), parseLink(inner, at, (separator) => linkSeparatorIndex(inner, at, separator)));
1140
1146
  link.selectorSpan = selectorSpan(s, ss, at);
1141
1147
  return withSelectors(link, s);
1142
1148
  }
1143
- function peg$f28() {
1149
+ function peg$f30() {
1144
1150
  return !textMode;
1145
1151
  }
1146
- function peg$f29() {
1152
+ function peg$f31() {
1147
1153
  fail("Unclosed link: [[ without ]]", location(), "unclosed-link");
1148
1154
  }
1149
- function peg$f30(parts) {
1155
+ function peg$f32(parts) {
1150
1156
  return selectorsOf(parts);
1151
1157
  }
1152
- function peg$f31() {
1158
+ function peg$f33() {
1153
1159
  return NO_SELECTORS;
1154
1160
  }
1155
- function peg$f32(s, end) {
1161
+ function peg$f34(s, end) {
1156
1162
  return {
1157
1163
  ...s,
1158
1164
  end
1159
1165
  };
1160
1166
  }
1161
- function peg$f33(prefix, name) {
1167
+ function peg$f35(prefix, name) {
1162
1168
  return [prefix, name];
1163
1169
  }
1164
- function peg$f34(ss, s, sigil, nameStart, name) {
1170
+ function peg$f36(ss, s, sigil, nameStart, name) {
1165
1171
  const variable = lexeme("variable", location(), {
1166
1172
  name,
1167
1173
  nameStart,
@@ -1171,7 +1177,7 @@ function peg$parse(input, options) {
1171
1177
  variable.selectorSpan = selectorSpan(s, ss, nameStart - 1);
1172
1178
  return withSelectors(variable, s);
1173
1179
  }
1174
- function peg$f35(ss, s, after, expression) {
1180
+ function peg$f37(ss, s, after, expression) {
1175
1181
  const node = lexeme("expression", location(), {
1176
1182
  expression,
1177
1183
  expressionStart: after,
@@ -1180,28 +1186,33 @@ function peg$parse(input, options) {
1180
1186
  node.selectorSpan = selectorSpan(s, ss, after);
1181
1187
  return withSelectors(node, s);
1182
1188
  }
1183
- function peg$f36() {
1189
+ function peg$f38() {
1184
1190
  fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
1185
1191
  }
1186
- function peg$f37(start) {
1187
- return skipTo(hooks.closeBrace(input, start, start));
1192
+ function peg$f39(start) {
1193
+ const end = hooks.closeBrace(input, start, start);
1194
+ return skipTo(end < 0 && completionMode ? input.length : end);
1188
1195
  }
1189
- function peg$f38(start) {
1196
+ function peg$f40(start) {
1190
1197
  return skipEnd - offset();
1191
1198
  }
1192
- function peg$f39(start, code) {
1199
+ function peg$f41(start, code) {
1193
1200
  return code;
1194
1201
  }
1195
- function peg$f40(ss, s, start, close, name, nameEnd) {
1196
- return skipTo(hooks.closeBrace(input, nameEnd, start));
1202
+ function peg$f42() {
1203
+ return completionMode;
1204
+ }
1205
+ function peg$f43(ss, s, start, close, name, nameEnd) {
1206
+ const end = hooks.closeBrace(input, nameEnd, start);
1207
+ return skipTo(end < 0 && completionMode ? input.length : end);
1197
1208
  }
1198
- function peg$f41(ss, s, start, close, name, nameEnd) {
1209
+ function peg$f44(ss, s, start, close, name, nameEnd) {
1199
1210
  return skipEnd - offset();
1200
1211
  }
1201
- function peg$f42(ss, s, start, close, name, nameEnd, args) {
1212
+ function peg$f45(ss, s, start, close, name, nameEnd, args) {
1202
1213
  return args;
1203
1214
  }
1204
- function peg$f43(ss, s, start, close, name, nameEnd, tail) {
1215
+ function peg$f46(ss, s, start, close, name, nameEnd, tail) {
1205
1216
  const loc = location();
1206
1217
  const lower = name.toLowerCase();
1207
1218
  const tag = lexeme("macro", loc, {
@@ -1214,7 +1225,7 @@ function peg$parse(input, options) {
1214
1225
  tag.nameEnd = nameEnd;
1215
1226
  tag.selectorSpan = selectorSpan(s, ss, start);
1216
1227
  if (tail === null) fail("Unclosed {" + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
1217
- tag.rawArgs = tail.trim();
1228
+ tag.rawArgs = completionMode ? tail.trimStart() : tail.trim();
1218
1229
  tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
1219
1230
  tag.argsEnd = tag.argsStart + tag.rawArgs.length;
1220
1231
  if (close) {
@@ -1227,19 +1238,19 @@ function peg$parse(input, options) {
1227
1238
  }
1228
1239
  return tag;
1229
1240
  }
1230
- function peg$f44(s) {
1241
+ function peg$f47(s) {
1231
1242
  fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
1232
1243
  }
1233
- function peg$f45(value) {
1244
+ function peg$f48(value) {
1234
1245
  return EMAIL_AUTOLINK.test(value);
1235
1246
  }
1236
- function peg$f46(value) {
1247
+ function peg$f49(value) {
1237
1248
  return lexeme("text", location(), { value });
1238
1249
  }
1239
- function peg$f47(value) {
1250
+ function peg$f50(value) {
1240
1251
  return lexeme("text", location(), { value });
1241
1252
  }
1242
- function peg$f48(tagStart, tag, list, slash) {
1253
+ function peg$f51(tagStart, tag, list, slash) {
1243
1254
  const lower = tag.toLowerCase();
1244
1255
  return lexeme("html", location(), {
1245
1256
  tag,
@@ -1252,7 +1263,7 @@ function peg$parse(input, options) {
1252
1263
  isSelfClose: !!slash || VOID_TAGS.has(lower)
1253
1264
  });
1254
1265
  }
1255
- function peg$f49(tag, bad) {
1266
+ function peg$f52(tag, bad) {
1256
1267
  const c = input.charAt(bad);
1257
1268
  if (!c) fail("Unclosed tag <" + tag + ": no > ends it (write &lt; for a < that starts no tag)", location(), "unclosed-tag");
1258
1269
  const at = {
@@ -1270,7 +1281,7 @@ function peg$parse(input, options) {
1270
1281
  };
1271
1282
  fail("Unexpected " + JSON.stringify(c) + " in the tag <" + tag + ">: expected an attribute, or > to end the tag", at, "unexpected-character");
1272
1283
  }
1273
- function peg$f50(tagStart, tag) {
1284
+ function peg$f53(tagStart, tag) {
1274
1285
  return lexeme("html", location(), {
1275
1286
  tag,
1276
1287
  lower: tag.toLowerCase(),
@@ -1282,14 +1293,14 @@ function peg$parse(input, options) {
1282
1293
  isSelfClose: false
1283
1294
  });
1284
1295
  }
1285
- function peg$f51(nameStart, name) {
1296
+ function peg$f54(nameStart, name) {
1286
1297
  attrCode = hooks.isCodeAttribute(name);
1287
1298
  return true;
1288
1299
  }
1289
- function peg$f52(nameStart, name, v) {
1300
+ function peg$f55(nameStart, name, v) {
1290
1301
  return v;
1291
1302
  }
1292
- function peg$f53(nameStart, name, value) {
1303
+ function peg$f56(nameStart, name, value) {
1293
1304
  const attribute = {
1294
1305
  name,
1295
1306
  value: value ? value.value : "",
@@ -1303,7 +1314,7 @@ function peg$parse(input, options) {
1303
1314
  }
1304
1315
  return attribute;
1305
1316
  }
1306
- function peg$f54(start, value, end) {
1317
+ function peg$f57(start, value, end) {
1307
1318
  return {
1308
1319
  value,
1309
1320
  start,
@@ -1311,7 +1322,7 @@ function peg$parse(input, options) {
1311
1322
  quote: "\""
1312
1323
  };
1313
1324
  }
1314
- function peg$f55(start, value, end) {
1325
+ function peg$f58(start, value, end) {
1315
1326
  return {
1316
1327
  value,
1317
1328
  start,
@@ -1319,35 +1330,36 @@ function peg$parse(input, options) {
1319
1330
  quote: "'"
1320
1331
  };
1321
1332
  }
1322
- function peg$f56(q) {
1333
+ function peg$f59(q) {
1323
1334
  fail("Unclosed attribute value: the " + q + " here has no closing " + q, location(), "unclosed-attribute");
1324
1335
  }
1325
- function peg$f57(start, value, end) {
1336
+ function peg$f60(start, value, end) {
1326
1337
  return {
1327
1338
  value,
1328
1339
  start,
1329
1340
  end
1330
1341
  };
1331
1342
  }
1332
- function peg$f58() {
1343
+ function peg$f61() {
1333
1344
  return !attrCode;
1334
1345
  }
1335
- function peg$f59(bs) {
1346
+ function peg$f62(bs) {
1336
1347
  return bs.length % 2 === 1;
1337
1348
  }
1338
- function peg$f60() {
1349
+ function peg$f63() {
1339
1350
  return !attrCode;
1340
1351
  }
1341
- function peg$f61(start, nameEnd) {
1342
- return skipTo(hooks.closeBrace(input, nameEnd, start));
1352
+ function peg$f64(start, nameEnd) {
1353
+ const end = hooks.closeBrace(input, nameEnd, start);
1354
+ return skipTo(end < 0 && completionMode ? input.length : end);
1343
1355
  }
1344
- function peg$f62(start, nameEnd) {
1356
+ function peg$f65(start, nameEnd) {
1345
1357
  return skipEnd - offset();
1346
1358
  }
1347
- function peg$f63() {
1359
+ function peg$f66() {
1348
1360
  return !attrCode;
1349
1361
  }
1350
- function peg$f64() {
1362
+ function peg$f67() {
1351
1363
  return attrCode;
1352
1364
  }
1353
1365
  let peg$currPos = options.peg$currPos | 0;
@@ -1686,6 +1698,40 @@ function peg$parse(input, options) {
1686
1698
  peg$currPos = s0;
1687
1699
  s0 = peg$FAILED;
1688
1700
  }
1701
+ if (s0 === peg$FAILED) {
1702
+ s0 = peg$currPos;
1703
+ peg$savedPos = peg$currPos;
1704
+ s1 = peg$f16();
1705
+ if (s1) s1 = void 0;
1706
+ else s1 = peg$FAILED;
1707
+ if (s1 !== peg$FAILED) {
1708
+ s2 = peg$currPos;
1709
+ s3 = [];
1710
+ if (input.length > peg$currPos) {
1711
+ s4 = input.charAt(peg$currPos);
1712
+ peg$currPos++;
1713
+ } else {
1714
+ s4 = peg$FAILED;
1715
+ if (peg$silentFails === 0) peg$fail(peg$e0);
1716
+ }
1717
+ while (s4 !== peg$FAILED) {
1718
+ s3.push(s4);
1719
+ if (input.length > peg$currPos) {
1720
+ s4 = input.charAt(peg$currPos);
1721
+ peg$currPos++;
1722
+ } else {
1723
+ s4 = peg$FAILED;
1724
+ if (peg$silentFails === 0) peg$fail(peg$e0);
1725
+ }
1726
+ }
1727
+ s2 = input.substring(s2, peg$currPos);
1728
+ peg$savedPos = s0;
1729
+ s0 = peg$f17(s2);
1730
+ } else {
1731
+ peg$currPos = s0;
1732
+ s0 = peg$FAILED;
1733
+ }
1734
+ }
1689
1735
  return s0;
1690
1736
  }
1691
1737
  function peg$parseHere() {
@@ -1693,7 +1739,7 @@ function peg$parse(input, options) {
1693
1739
  s0 = peg$currPos;
1694
1740
  s1 = "";
1695
1741
  peg$savedPos = s0;
1696
- s1 = peg$f16();
1742
+ s1 = peg$f18();
1697
1743
  s0 = s1;
1698
1744
  return s0;
1699
1745
  }
@@ -1722,7 +1768,7 @@ function peg$parse(input, options) {
1722
1768
  else s1 = s2;
1723
1769
  if (s1 !== peg$FAILED) {
1724
1770
  peg$savedPos = s0;
1725
- s1 = peg$f17(s1);
1771
+ s1 = peg$f19(s1);
1726
1772
  }
1727
1773
  s0 = s1;
1728
1774
  return s0;
@@ -1838,6 +1884,7 @@ function peg$parse(input, options) {
1838
1884
  s6 = peg$FAILED;
1839
1885
  if (peg$silentFails === 0) peg$fail(peg$e5);
1840
1886
  }
1887
+ if (s6 === peg$FAILED) s6 = peg$parseOpenEnd();
1841
1888
  if (s6 !== peg$FAILED) {
1842
1889
  s5 = [s5, s6];
1843
1890
  s4 = s5;
@@ -1862,7 +1909,7 @@ function peg$parse(input, options) {
1862
1909
  else s1 = s2;
1863
1910
  if (s1 !== peg$FAILED) {
1864
1911
  peg$savedPos = s0;
1865
- s1 = peg$f18(s1);
1912
+ s1 = peg$f20(s1);
1866
1913
  }
1867
1914
  s0 = s1;
1868
1915
  return s0;
@@ -1895,7 +1942,7 @@ function peg$parse(input, options) {
1895
1942
  if (s1 !== peg$FAILED) {
1896
1943
  s2 = peg$currPos;
1897
1944
  peg$savedPos = peg$currPos;
1898
- s3 = peg$f19(s1);
1945
+ s3 = peg$f21(s1);
1899
1946
  if (s3) s3 = void 0;
1900
1947
  else s3 = peg$FAILED;
1901
1948
  if (s3 !== peg$FAILED) {
@@ -1907,7 +1954,7 @@ function peg$parse(input, options) {
1907
1954
  }
1908
1955
  if (s4 !== peg$FAILED) {
1909
1956
  peg$savedPos = s2;
1910
- s2 = peg$f20(s1, s4);
1957
+ s2 = peg$f22(s1, s4);
1911
1958
  } else {
1912
1959
  peg$currPos = s2;
1913
1960
  s2 = peg$FAILED;
@@ -1918,7 +1965,7 @@ function peg$parse(input, options) {
1918
1965
  }
1919
1966
  if (s2 === peg$FAILED) s2 = null;
1920
1967
  peg$savedPos = s0;
1921
- s0 = peg$f21(s1, s2);
1968
+ s0 = peg$f23(s1, s2);
1922
1969
  } else {
1923
1970
  peg$currPos = s0;
1924
1971
  s0 = peg$FAILED;
@@ -1966,7 +2013,7 @@ function peg$parse(input, options) {
1966
2013
  }
1967
2014
  if (s2 !== peg$FAILED) {
1968
2015
  peg$savedPos = s0;
1969
- s0 = peg$f22();
2016
+ s0 = peg$f24();
1970
2017
  } else {
1971
2018
  peg$currPos = s0;
1972
2019
  s0 = peg$FAILED;
@@ -1981,7 +2028,7 @@ function peg$parse(input, options) {
1981
2028
  peg$silentFails++;
1982
2029
  s2 = peg$currPos;
1983
2030
  peg$savedPos = peg$currPos;
1984
- s3 = peg$f23();
2031
+ s3 = peg$f25();
1985
2032
  if (s3) s3 = void 0;
1986
2033
  else s3 = peg$FAILED;
1987
2034
  if (s3 !== peg$FAILED) {
@@ -2013,7 +2060,7 @@ function peg$parse(input, options) {
2013
2060
  }
2014
2061
  if (s2 !== peg$FAILED) {
2015
2062
  peg$savedPos = s0;
2016
- s0 = peg$f24();
2063
+ s0 = peg$f26();
2017
2064
  } else {
2018
2065
  peg$currPos = s0;
2019
2066
  s0 = peg$FAILED;
@@ -2033,7 +2080,7 @@ function peg$parse(input, options) {
2033
2080
  }
2034
2081
  if (s1 !== peg$FAILED) {
2035
2082
  peg$savedPos = s0;
2036
- s1 = peg$f25();
2083
+ s1 = peg$f27();
2037
2084
  }
2038
2085
  s0 = s1;
2039
2086
  }
@@ -2044,7 +2091,7 @@ function peg$parse(input, options) {
2044
2091
  let s0, s1, s2, s3, s4, s5, s6, s7;
2045
2092
  s0 = peg$currPos;
2046
2093
  peg$savedPos = peg$currPos;
2047
- s1 = peg$f26();
2094
+ s1 = peg$f28();
2048
2095
  if (s1) s1 = void 0;
2049
2096
  else s1 = peg$FAILED;
2050
2097
  if (s1 !== peg$FAILED) {
@@ -2070,9 +2117,10 @@ function peg$parse(input, options) {
2070
2117
  s7 = peg$FAILED;
2071
2118
  if (peg$silentFails === 0) peg$fail(peg$e13);
2072
2119
  }
2120
+ if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
2073
2121
  if (s7 !== peg$FAILED) {
2074
2122
  peg$savedPos = s0;
2075
- s0 = peg$f27(s3, s4, s5, s6);
2123
+ s0 = peg$f29(s3, s4, s5, s6);
2076
2124
  } else {
2077
2125
  peg$currPos = s0;
2078
2126
  s0 = peg$FAILED;
@@ -2092,7 +2140,7 @@ function peg$parse(input, options) {
2092
2140
  if (s0 === peg$FAILED) {
2093
2141
  s0 = peg$currPos;
2094
2142
  peg$savedPos = peg$currPos;
2095
- s1 = peg$f28();
2143
+ s1 = peg$f30();
2096
2144
  if (s1) s1 = void 0;
2097
2145
  else s1 = peg$FAILED;
2098
2146
  if (s1 !== peg$FAILED) {
@@ -2105,7 +2153,7 @@ function peg$parse(input, options) {
2105
2153
  }
2106
2154
  if (s2 !== peg$FAILED) {
2107
2155
  peg$savedPos = s0;
2108
- s0 = peg$f29();
2156
+ s0 = peg$f31();
2109
2157
  } else {
2110
2158
  peg$currPos = s0;
2111
2159
  s0 = peg$FAILED;
@@ -2233,7 +2281,7 @@ function peg$parse(input, options) {
2233
2281
  }
2234
2282
  if (s2 === peg$FAILED) s2 = null;
2235
2283
  peg$savedPos = s0;
2236
- s0 = peg$f30(s1);
2284
+ s0 = peg$f32(s1);
2237
2285
  } else {
2238
2286
  peg$currPos = s0;
2239
2287
  s0 = peg$FAILED;
@@ -2242,7 +2290,7 @@ function peg$parse(input, options) {
2242
2290
  s0 = peg$currPos;
2243
2291
  s1 = "";
2244
2292
  peg$savedPos = s0;
2245
- s1 = peg$f31();
2293
+ s1 = peg$f33();
2246
2294
  s0 = s1;
2247
2295
  }
2248
2296
  return s0;
@@ -2272,7 +2320,7 @@ function peg$parse(input, options) {
2272
2320
  }
2273
2321
  }
2274
2322
  peg$savedPos = s0;
2275
- s0 = peg$f32(s1, s2);
2323
+ s0 = peg$f34(s1, s2);
2276
2324
  } else {
2277
2325
  peg$currPos = s0;
2278
2326
  s0 = peg$FAILED;
@@ -2298,7 +2346,7 @@ function peg$parse(input, options) {
2298
2346
  }
2299
2347
  s2 = input.substring(s2, peg$currPos);
2300
2348
  peg$savedPos = s0;
2301
- s0 = peg$f33(s1, s2);
2349
+ s0 = peg$f35(s1, s2);
2302
2350
  } else {
2303
2351
  peg$currPos = s0;
2304
2352
  s0 = peg$FAILED;
@@ -2416,16 +2464,10 @@ function peg$parse(input, options) {
2416
2464
  }
2417
2465
  }
2418
2466
  s6 = input.substring(s6, peg$currPos);
2419
- if (input.charCodeAt(peg$currPos) === 125) {
2420
- s7 = peg$c11;
2421
- peg$currPos++;
2422
- } else {
2423
- s7 = peg$FAILED;
2424
- if (peg$silentFails === 0) peg$fail(peg$e19);
2425
- }
2467
+ s7 = peg$parseBraceEnd();
2426
2468
  if (s7 !== peg$FAILED) {
2427
2469
  peg$savedPos = s0;
2428
- s0 = peg$f34(s2, s3, s4, s5, s6);
2470
+ s0 = peg$f36(s2, s3, s4, s5, s6);
2429
2471
  } else {
2430
2472
  peg$currPos = s0;
2431
2473
  s0 = peg$FAILED;
@@ -2472,16 +2514,10 @@ function peg$parse(input, options) {
2472
2514
  if (s5 !== peg$FAILED) {
2473
2515
  s6 = peg$parseCodeToBrace();
2474
2516
  if (s6 !== peg$FAILED) {
2475
- if (input.charCodeAt(peg$currPos) === 125) {
2476
- s7 = peg$c11;
2477
- peg$currPos++;
2478
- } else {
2479
- s7 = peg$FAILED;
2480
- if (peg$silentFails === 0) peg$fail(peg$e19);
2481
- }
2517
+ s7 = peg$parseBraceEnd();
2482
2518
  if (s7 !== peg$FAILED) {
2483
2519
  peg$savedPos = s0;
2484
- s0 = peg$f35(s2, s3, s4, s6);
2520
+ s0 = peg$f37(s2, s3, s4, s6);
2485
2521
  } else {
2486
2522
  peg$currPos = s0;
2487
2523
  s0 = peg$FAILED;
@@ -2529,7 +2565,7 @@ function peg$parse(input, options) {
2529
2565
  } else s3 = peg$FAILED;
2530
2566
  if (s3 !== peg$FAILED) {
2531
2567
  peg$savedPos = s0;
2532
- s0 = peg$f36();
2568
+ s0 = peg$f38();
2533
2569
  } else {
2534
2570
  peg$currPos = s0;
2535
2571
  s0 = peg$FAILED;
@@ -2551,12 +2587,12 @@ function peg$parse(input, options) {
2551
2587
  s0 = peg$currPos;
2552
2588
  s1 = peg$parseHere();
2553
2589
  peg$savedPos = peg$currPos;
2554
- s2 = peg$f37(s1);
2590
+ s2 = peg$f39(s1);
2555
2591
  if (s2) s2 = void 0;
2556
2592
  else s2 = peg$FAILED;
2557
2593
  if (s2 !== peg$FAILED) {
2558
2594
  s3 = peg$currPos;
2559
- s4 = peg$f38(s1);
2595
+ s4 = peg$f40(s1);
2560
2596
  s5 = peg$currPos;
2561
2597
  s6 = [];
2562
2598
  if (s6.length >= (s4 | 0)) s7 = peg$FAILED;
@@ -2587,7 +2623,7 @@ function peg$parse(input, options) {
2587
2623
  else s3 = s4;
2588
2624
  if (s3 !== peg$FAILED) {
2589
2625
  peg$savedPos = s0;
2590
- s0 = peg$f39(s1, s3);
2626
+ s0 = peg$f41(s1, s3);
2591
2627
  } else {
2592
2628
  peg$currPos = s0;
2593
2629
  s0 = peg$FAILED;
@@ -2598,6 +2634,54 @@ function peg$parse(input, options) {
2598
2634
  }
2599
2635
  return s0;
2600
2636
  }
2637
+ function peg$parseOpenEnd() {
2638
+ let s0, s1, s2, s3;
2639
+ s0 = peg$currPos;
2640
+ peg$savedPos = peg$currPos;
2641
+ s1 = peg$f42();
2642
+ if (s1) s1 = void 0;
2643
+ else s1 = peg$FAILED;
2644
+ if (s1 !== peg$FAILED) {
2645
+ s2 = peg$currPos;
2646
+ peg$silentFails++;
2647
+ if (input.length > peg$currPos) {
2648
+ s3 = input.charAt(peg$currPos);
2649
+ peg$currPos++;
2650
+ } else {
2651
+ s3 = peg$FAILED;
2652
+ if (peg$silentFails === 0) peg$fail(peg$e0);
2653
+ }
2654
+ peg$silentFails--;
2655
+ if (s3 === peg$FAILED) s2 = void 0;
2656
+ else {
2657
+ peg$currPos = s2;
2658
+ s2 = peg$FAILED;
2659
+ }
2660
+ if (s2 !== peg$FAILED) {
2661
+ s1 = [s1, s2];
2662
+ s0 = s1;
2663
+ } else {
2664
+ peg$currPos = s0;
2665
+ s0 = peg$FAILED;
2666
+ }
2667
+ } else {
2668
+ peg$currPos = s0;
2669
+ s0 = peg$FAILED;
2670
+ }
2671
+ return s0;
2672
+ }
2673
+ function peg$parseBraceEnd() {
2674
+ let s0;
2675
+ if (input.charCodeAt(peg$currPos) === 125) {
2676
+ s0 = peg$c11;
2677
+ peg$currPos++;
2678
+ } else {
2679
+ s0 = peg$FAILED;
2680
+ if (peg$silentFails === 0) peg$fail(peg$e19);
2681
+ }
2682
+ if (s0 === peg$FAILED) s0 = peg$parseOpenEnd();
2683
+ return s0;
2684
+ }
2601
2685
  function peg$parseMacroTag() {
2602
2686
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
2603
2687
  s0 = peg$currPos;
@@ -2626,12 +2710,12 @@ function peg$parse(input, options) {
2626
2710
  s7 = peg$parseHere();
2627
2711
  s8 = peg$currPos;
2628
2712
  peg$savedPos = peg$currPos;
2629
- s9 = peg$f40(s2, s3, s4, s5, s6, s7);
2713
+ s9 = peg$f43(s2, s3, s4, s5, s6, s7);
2630
2714
  if (s9) s9 = void 0;
2631
2715
  else s9 = peg$FAILED;
2632
2716
  if (s9 !== peg$FAILED) {
2633
2717
  s10 = peg$currPos;
2634
- s11 = peg$f41(s2, s3, s4, s5, s6, s7);
2718
+ s11 = peg$f44(s2, s3, s4, s5, s6, s7);
2635
2719
  s12 = peg$currPos;
2636
2720
  s13 = [];
2637
2721
  if (s13.length >= (s11 | 0)) s14 = peg$FAILED;
@@ -2661,16 +2745,10 @@ function peg$parse(input, options) {
2661
2745
  if (s11 !== peg$FAILED) s10 = input.substring(s10, peg$currPos);
2662
2746
  else s10 = s11;
2663
2747
  if (s10 !== peg$FAILED) {
2664
- if (input.charCodeAt(peg$currPos) === 125) {
2665
- s11 = peg$c11;
2666
- peg$currPos++;
2667
- } else {
2668
- s11 = peg$FAILED;
2669
- if (peg$silentFails === 0) peg$fail(peg$e19);
2670
- }
2748
+ s11 = peg$parseBraceEnd();
2671
2749
  if (s11 !== peg$FAILED) {
2672
2750
  peg$savedPos = s8;
2673
- s8 = peg$f42(s2, s3, s4, s5, s6, s7, s10);
2751
+ s8 = peg$f45(s2, s3, s4, s5, s6, s7, s10);
2674
2752
  } else {
2675
2753
  peg$currPos = s8;
2676
2754
  s8 = peg$FAILED;
@@ -2685,7 +2763,7 @@ function peg$parse(input, options) {
2685
2763
  }
2686
2764
  if (s8 === peg$FAILED) s8 = null;
2687
2765
  peg$savedPos = s0;
2688
- s0 = peg$f43(s2, s3, s4, s5, s6, s7, s8);
2766
+ s0 = peg$f46(s2, s3, s4, s5, s6, s7, s8);
2689
2767
  } else {
2690
2768
  peg$currPos = s0;
2691
2769
  s0 = peg$FAILED;
@@ -2719,7 +2797,7 @@ function peg$parse(input, options) {
2719
2797
  }
2720
2798
  if (s3 !== peg$FAILED) {
2721
2799
  peg$savedPos = s0;
2722
- s0 = peg$f44(s2);
2800
+ s0 = peg$f47(s2);
2723
2801
  } else {
2724
2802
  peg$currPos = s0;
2725
2803
  s0 = peg$FAILED;
@@ -2869,12 +2947,12 @@ function peg$parse(input, options) {
2869
2947
  else s1 = s2;
2870
2948
  if (s1 !== peg$FAILED) {
2871
2949
  peg$savedPos = peg$currPos;
2872
- s2 = peg$f45(s1);
2950
+ s2 = peg$f48(s1);
2873
2951
  if (s2) s2 = void 0;
2874
2952
  else s2 = peg$FAILED;
2875
2953
  if (s2 !== peg$FAILED) {
2876
2954
  peg$savedPos = s0;
2877
- s0 = peg$f46(s1);
2955
+ s0 = peg$f49(s1);
2878
2956
  } else {
2879
2957
  peg$currPos = s0;
2880
2958
  s0 = peg$FAILED;
@@ -3051,7 +3129,7 @@ function peg$parse(input, options) {
3051
3129
  else s1 = s2;
3052
3130
  if (s1 !== peg$FAILED) {
3053
3131
  peg$savedPos = s0;
3054
- s1 = peg$f47(s1);
3132
+ s1 = peg$f50(s1);
3055
3133
  }
3056
3134
  s0 = s1;
3057
3135
  return s0;
@@ -3092,9 +3170,10 @@ function peg$parse(input, options) {
3092
3170
  s7 = peg$FAILED;
3093
3171
  if (peg$silentFails === 0) peg$fail(peg$e3);
3094
3172
  }
3173
+ if (s7 === peg$FAILED) s7 = peg$parseOpenEnd();
3095
3174
  if (s7 !== peg$FAILED) {
3096
3175
  peg$savedPos = s0;
3097
- s0 = peg$f48(s2, s3, s4, s6);
3176
+ s0 = peg$f51(s2, s3, s4, s6);
3098
3177
  } else {
3099
3178
  peg$currPos = s0;
3100
3179
  s0 = peg$FAILED;
@@ -3159,7 +3238,7 @@ function peg$parse(input, options) {
3159
3238
  s5 = peg$parse_();
3160
3239
  s6 = peg$parseHere();
3161
3240
  peg$savedPos = s0;
3162
- s0 = peg$f49(s2, s6);
3241
+ s0 = peg$f52(s2, s6);
3163
3242
  } else {
3164
3243
  peg$currPos = s0;
3165
3244
  s0 = peg$FAILED;
@@ -3199,7 +3278,7 @@ function peg$parse(input, options) {
3199
3278
  }
3200
3279
  if (s5 !== peg$FAILED) {
3201
3280
  peg$savedPos = s0;
3202
- s0 = peg$f50(s2, s3);
3281
+ s0 = peg$f53(s2, s3);
3203
3282
  } else {
3204
3283
  peg$currPos = s0;
3205
3284
  s0 = peg$FAILED;
@@ -3334,7 +3413,7 @@ function peg$parse(input, options) {
3334
3413
  else s3 = s4;
3335
3414
  if (s3 !== peg$FAILED) {
3336
3415
  peg$savedPos = peg$currPos;
3337
- s4 = peg$f51(s2, s3);
3416
+ s4 = peg$f54(s2, s3);
3338
3417
  if (s4) s4 = void 0;
3339
3418
  else s4 = peg$FAILED;
3340
3419
  if (s4 !== peg$FAILED) {
@@ -3352,7 +3431,7 @@ function peg$parse(input, options) {
3352
3431
  s9 = peg$parseAttrValue();
3353
3432
  if (s9 !== peg$FAILED) {
3354
3433
  peg$savedPos = s5;
3355
- s5 = peg$f52(s2, s3, s9);
3434
+ s5 = peg$f55(s2, s3, s9);
3356
3435
  } else {
3357
3436
  peg$currPos = s5;
3358
3437
  s5 = peg$FAILED;
@@ -3363,7 +3442,7 @@ function peg$parse(input, options) {
3363
3442
  }
3364
3443
  if (s5 === peg$FAILED) s5 = null;
3365
3444
  peg$savedPos = s0;
3366
- s0 = peg$f53(s2, s3, s5);
3445
+ s0 = peg$f56(s2, s3, s5);
3367
3446
  } else {
3368
3447
  peg$currPos = s0;
3369
3448
  s0 = peg$FAILED;
@@ -3418,9 +3497,10 @@ function peg$parse(input, options) {
3418
3497
  s5 = peg$FAILED;
3419
3498
  if (peg$silentFails === 0) peg$fail(peg$e35);
3420
3499
  }
3500
+ if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3421
3501
  if (s5 !== peg$FAILED) {
3422
3502
  peg$savedPos = s0;
3423
- s0 = peg$f54(s2, s3, s4);
3503
+ s0 = peg$f57(s2, s3, s4);
3424
3504
  } else {
3425
3505
  peg$currPos = s0;
3426
3506
  s0 = peg$FAILED;
@@ -3472,9 +3552,10 @@ function peg$parse(input, options) {
3472
3552
  s5 = peg$FAILED;
3473
3553
  if (peg$silentFails === 0) peg$fail(peg$e37);
3474
3554
  }
3555
+ if (s5 === peg$FAILED) s5 = peg$parseOpenEnd();
3475
3556
  if (s5 !== peg$FAILED) {
3476
3557
  peg$savedPos = s0;
3477
- s0 = peg$f55(s2, s3, s4);
3558
+ s0 = peg$f58(s2, s3, s4);
3478
3559
  } else {
3479
3560
  peg$currPos = s0;
3480
3561
  s0 = peg$FAILED;
@@ -3493,7 +3574,7 @@ function peg$parse(input, options) {
3493
3574
  }
3494
3575
  if (s1 !== peg$FAILED) {
3495
3576
  peg$savedPos = s0;
3496
- s1 = peg$f56(s1);
3577
+ s1 = peg$f59(s1);
3497
3578
  }
3498
3579
  s0 = s1;
3499
3580
  if (s0 === peg$FAILED) {
@@ -3519,7 +3600,7 @@ function peg$parse(input, options) {
3519
3600
  s2 = input.substring(s2, peg$currPos);
3520
3601
  s3 = peg$parseHere();
3521
3602
  peg$savedPos = s0;
3522
- s0 = peg$f57(s1, s2, s3);
3603
+ s0 = peg$f60(s1, s2, s3);
3523
3604
  }
3524
3605
  }
3525
3606
  }
@@ -3529,7 +3610,7 @@ function peg$parse(input, options) {
3529
3610
  let s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13;
3530
3611
  s0 = peg$currPos;
3531
3612
  peg$savedPos = peg$currPos;
3532
- s1 = peg$f58();
3613
+ s1 = peg$f61();
3533
3614
  if (s1) s1 = void 0;
3534
3615
  else s1 = peg$FAILED;
3535
3616
  if (s1 !== peg$FAILED) {
@@ -3558,7 +3639,7 @@ function peg$parse(input, options) {
3558
3639
  if (s2 !== peg$FAILED) {
3559
3640
  s3 = peg$currPos;
3560
3641
  peg$savedPos = peg$currPos;
3561
- s4 = peg$f59(s2);
3642
+ s4 = peg$f62(s2);
3562
3643
  if (s4) s4 = void 0;
3563
3644
  else s4 = peg$FAILED;
3564
3645
  if (s4 !== peg$FAILED) {
@@ -3597,7 +3678,7 @@ function peg$parse(input, options) {
3597
3678
  if (s0 === peg$FAILED) {
3598
3679
  s0 = peg$currPos;
3599
3680
  peg$savedPos = peg$currPos;
3600
- s1 = peg$f60();
3681
+ s1 = peg$f63();
3601
3682
  if (s1) s1 = void 0;
3602
3683
  else s1 = peg$FAILED;
3603
3684
  if (s1 !== peg$FAILED) {
@@ -3624,12 +3705,12 @@ function peg$parse(input, options) {
3624
3705
  if (s6 !== peg$FAILED) {
3625
3706
  s7 = peg$parseHere();
3626
3707
  peg$savedPos = peg$currPos;
3627
- s8 = peg$f61(s4, s7);
3708
+ s8 = peg$f64(s4, s7);
3628
3709
  if (s8) s8 = void 0;
3629
3710
  else s8 = peg$FAILED;
3630
3711
  if (s8 !== peg$FAILED) {
3631
3712
  s9 = peg$currPos;
3632
- s10 = peg$f62(s4, s7);
3713
+ s10 = peg$f65(s4, s7);
3633
3714
  s11 = peg$currPos;
3634
3715
  s12 = [];
3635
3716
  if (s12.length >= (s10 | 0)) s13 = peg$FAILED;
@@ -3659,13 +3740,7 @@ function peg$parse(input, options) {
3659
3740
  if (s10 !== peg$FAILED) s9 = input.substring(s9, peg$currPos);
3660
3741
  else s9 = s10;
3661
3742
  if (s9 !== peg$FAILED) {
3662
- if (input.charCodeAt(peg$currPos) === 125) {
3663
- s10 = peg$c11;
3664
- peg$currPos++;
3665
- } else {
3666
- s10 = peg$FAILED;
3667
- if (peg$silentFails === 0) peg$fail(peg$e19);
3668
- }
3743
+ s10 = peg$parseBraceEnd();
3669
3744
  if (s10 !== peg$FAILED) {
3670
3745
  s1 = [
3671
3746
  s1,
@@ -3711,7 +3786,7 @@ function peg$parse(input, options) {
3711
3786
  if (s0 === peg$FAILED) {
3712
3787
  s0 = peg$currPos;
3713
3788
  peg$savedPos = peg$currPos;
3714
- s1 = peg$f63();
3789
+ s1 = peg$f66();
3715
3790
  if (s1) s1 = void 0;
3716
3791
  else s1 = peg$FAILED;
3717
3792
  if (s1 !== peg$FAILED) {
@@ -3758,13 +3833,7 @@ function peg$parse(input, options) {
3758
3833
  if (s4 !== peg$FAILED) {
3759
3834
  s5 = peg$parseCodeToBrace();
3760
3835
  if (s5 !== peg$FAILED) {
3761
- if (input.charCodeAt(peg$currPos) === 125) {
3762
- s6 = peg$c11;
3763
- peg$currPos++;
3764
- } else {
3765
- s6 = peg$FAILED;
3766
- if (peg$silentFails === 0) peg$fail(peg$e19);
3767
- }
3836
+ s6 = peg$parseBraceEnd();
3768
3837
  if (s6 !== peg$FAILED) {
3769
3838
  s1 = [
3770
3839
  s1,
@@ -3802,7 +3871,7 @@ function peg$parse(input, options) {
3802
3871
  if (s0 === peg$FAILED) {
3803
3872
  s0 = peg$currPos;
3804
3873
  peg$savedPos = peg$currPos;
3805
- s1 = peg$f64();
3874
+ s1 = peg$f67();
3806
3875
  if (s1) s1 = void 0;
3807
3876
  else s1 = peg$FAILED;
3808
3877
  if (s1 !== peg$FAILED) {
@@ -3830,13 +3899,7 @@ function peg$parse(input, options) {
3830
3899
  if (s3 !== peg$FAILED) {
3831
3900
  s4 = peg$parseCodeToBrace();
3832
3901
  if (s4 !== peg$FAILED) {
3833
- if (input.charCodeAt(peg$currPos) === 125) {
3834
- s5 = peg$c11;
3835
- peg$currPos++;
3836
- } else {
3837
- s5 = peg$FAILED;
3838
- if (peg$silentFails === 0) peg$fail(peg$e19);
3839
- }
3902
+ s5 = peg$parseBraceEnd();
3840
3903
  if (s5 !== peg$FAILED) {
3841
3904
  s1 = [
3842
3905
  s1,
@@ -3892,6 +3955,7 @@ function peg$parse(input, options) {
3892
3955
  return s0;
3893
3956
  }
3894
3957
  const textMode = options.text === true;
3958
+ const completionMode = options.completion === true;
3895
3959
  const hooks = options.hooks;
3896
3960
  /** End of the stretch a `.|n|` repetition consumes (see skipTo). */
3897
3961
  let skipEnd = -1;
@@ -10704,7 +10768,7 @@ function isCodeAttribute(name) {
10704
10768
  * sigil is not followed by a word character (`{$(…)}`) is code, kept
10705
10769
  * verbatim: not resolved, and not decoded like text.
10706
10770
  */
10707
- function splitSigilTemplate(template) {
10771
+ function splitSigilTemplate(template, incomplete = false) {
10708
10772
  const parts = [];
10709
10773
  let text = "";
10710
10774
  let i = 0;
@@ -10716,7 +10780,8 @@ function splitSigilTemplate(template) {
10716
10780
  }
10717
10781
  text += template.slice(i, brace);
10718
10782
  i = brace + 1;
10719
- const end = isSigil(template[i]) ? defaultCodeEnd.closeBrace(template, i, i) : -1;
10783
+ let end = isSigil(template[i]) ? defaultCodeEnd.closeBrace(template, i, i) : -1;
10784
+ if (end === -1 && incomplete && isSigil(template[i])) end = template.length;
10720
10785
  if (end === -1) {
10721
10786
  text += "{";
10722
10787
  continue;
@@ -10724,7 +10789,7 @@ function splitSigilTemplate(template) {
10724
10789
  if (text) parts.push({ text });
10725
10790
  text = "";
10726
10791
  const block = template.slice(i, end);
10727
- parts.push(/^.\w/.test(block) ? { expr: block } : { verbatim: `{${block}}` });
10792
+ parts.push(/^.\w/.test(block) || incomplete && block.length === 1 && end === template.length ? { expr: block } : { verbatim: `{${block}}` });
10728
10793
  i = end + 1;
10729
10794
  }
10730
10795
  if (text) parts.push({ text });
@@ -10757,7 +10822,7 @@ var MarkupError = class extends Error {
10757
10822
  this.name = "MarkupError";
10758
10823
  }
10759
10824
  };
10760
- function run$2(source, startRule, options) {
10825
+ function run$2(source, startRule, options, completion = false) {
10761
10826
  const hooks = options.hooks ? {
10762
10827
  ...defaultHooks,
10763
10828
  ...options.hooks
@@ -10766,7 +10831,8 @@ function run$2(source, startRule, options) {
10766
10831
  return peg$parse(source, {
10767
10832
  startRule,
10768
10833
  text: options.text === true,
10769
- hooks
10834
+ hooks,
10835
+ completion
10770
10836
  });
10771
10837
  } catch (err) {
10772
10838
  const { location, code } = err;
@@ -10855,7 +10921,7 @@ function tokenizeMarkupTolerant(source, options = {}) {
10855
10921
  * each error starts (`damage[i]` for `errors[i]`): the tag that is
10856
10922
  * malformed, which an error inside it (an attribute value) is after.
10857
10923
  */
10858
- function scanMarkupTolerant(source, options = {}) {
10924
+ function scanMarkupTolerant(source, options = {}, completion = false) {
10859
10925
  const tokens = [];
10860
10926
  const errors = [];
10861
10927
  const damage = [];
@@ -10872,10 +10938,10 @@ function scanMarkupTolerant(source, options = {}) {
10872
10938
  closeBrace: (input, codeStart, lenientStart) => base + Math.min(codeStart, lenientStart) > lastBrace ? -1 : closeBrace(input, codeStart, lenientStart)
10873
10939
  };
10874
10940
  try {
10875
- return tokenizeMarkup(text, {
10941
+ return run$2(text, "Tokens", {
10876
10942
  ...options,
10877
10943
  hooks
10878
- }).map((token) => shiftOffsets(token, base));
10944
+ }, completion).map((token) => shiftOffsets(token, base));
10879
10945
  } catch (error) {
10880
10946
  if (!(error instanceof MarkupError)) throw error;
10881
10947
  return error;
@@ -12227,25 +12293,29 @@ var registeredParameters = (name) => parameterLookup(getMacroRegistry())(name);
12227
12293
  * Whether the text of an attribute value or macro label renders a
12228
12294
  * `{@children}`: it is markup, parsed as the renderer parses it.
12229
12295
  */
12230
- function textContainsChildren(text, parametersOf) {
12296
+ function textContainsChildren(text, parametersOf, hooks) {
12231
12297
  if (!text.includes("{")) return false;
12232
12298
  let nodes;
12233
12299
  try {
12234
- nodes = parseMarkup(text, { text: true });
12300
+ nodes = parseMarkup(text, {
12301
+ text: true,
12302
+ hooks
12303
+ });
12235
12304
  } catch {
12236
12305
  return false;
12237
12306
  }
12238
- return astContainsChildren(nodes, parametersOf);
12307
+ return astContainsChildren(nodes, parametersOf, hooks);
12239
12308
  }
12240
12309
  /**
12241
12310
  * Whether a tag renders a `{@children}` in an attribute value or a macro
12242
12311
  * argument that holds markup (`<span title="{@children}">`,
12243
12312
  * `{button "{@children}"}`). Literal arguments and code are not markup.
12244
12313
  * `src` is the text a flat token's offsets index into (its attribute values
12245
- * are read from it); a token made from an AST has none.
12314
+ * are read from it); a token made from an AST has none. Discovery hooks
12315
+ * also apply inside these texts, before widgets have been registered.
12246
12316
  */
12247
- function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "") {
12248
- for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf)) return true;
12317
+ function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks) {
12318
+ for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks)) return true;
12249
12319
  return false;
12250
12320
  }
12251
12321
  /**
@@ -12255,36 +12325,33 @@ function tokenTextContainsChildren(token, parametersOf = registeredParameters, s
12255
12325
  * entered: its slot belongs to the innermost widget (as widgetDefinitions
12256
12326
  * reads it), and a definition renders nothing of its own.
12257
12327
  */
12258
- function astContainsChildren(nodes, parametersOf = registeredParameters) {
12328
+ function astContainsChildren(nodes, parametersOf = registeredParameters, hooks) {
12259
12329
  for (const node of nodes) {
12260
12330
  if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
12261
- if (node.type === "html") {
12262
- if (tokenTextContainsChildren({
12263
- isClose: false,
12264
- isSelfClose: false,
12265
- tagNameStart: 0,
12266
- tagNameEnd: 0,
12267
- attributeSpans: [],
12268
- ...node,
12269
- start: 0,
12270
- end: 0
12271
- }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
12272
- }
12273
- if (node.type === "macro") {
12274
- if (node.name.toLowerCase() === "widget") continue;
12275
- if (tokenTextContainsChildren({
12276
- isClose: false,
12277
- nameStart: 0,
12278
- nameEnd: 0,
12279
- argsStart: 0,
12280
- argsEnd: 0,
12281
- ...node,
12282
- start: 0,
12283
- end: 0
12284
- }, parametersOf) || astContainsChildren(node.children, parametersOf)) return true;
12285
- if (node.branches) {
12286
- for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf)) return true;
12287
- }
12331
+ if (node.type !== "html" && node.type !== "macro") continue;
12332
+ if (node.type === "macro" && node.name.toLowerCase() === "widget") continue;
12333
+ const span = {
12334
+ isClose: false,
12335
+ start: 0,
12336
+ end: 0
12337
+ };
12338
+ if (tokenTextContainsChildren(node.type === "html" ? {
12339
+ ...node,
12340
+ ...span,
12341
+ isSelfClose: false,
12342
+ tagNameStart: 0,
12343
+ tagNameEnd: 0,
12344
+ attributeSpans: []
12345
+ } : {
12346
+ ...node,
12347
+ ...span,
12348
+ nameStart: 0,
12349
+ nameEnd: 0,
12350
+ argsStart: 0,
12351
+ argsEnd: 0
12352
+ }, parametersOf, "", hooks) || astContainsChildren(node.children, parametersOf, hooks)) return true;
12353
+ if (node.type === "macro" && node.branches) {
12354
+ for (const branch of node.branches) if (astContainsChildren(branch.children, parametersOf, hooks)) return true;
12288
12355
  }
12289
12356
  }
12290
12357
  return false;
@@ -12366,42 +12433,48 @@ function nameSpan(rawArgs) {
12366
12433
  * nested definitions, it belongs to the innermost.
12367
12434
  */
12368
12435
  function widgetDefinitions(passages, parametersOf = registeredParameters) {
12369
- const found = [];
12370
- for (const passage of passages) {
12371
- if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
12372
- const open = [];
12373
- const done = [];
12374
- for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
12375
- if (!token.isClose) open.push({
12376
- token,
12377
- isBlock: false
12378
- });
12379
- else {
12380
- const def = open.pop();
12381
- if (def) done.push({
12382
- ...def,
12383
- closeStart: token.start
12436
+ const list = [...passages];
12437
+ const scan = (replacesDo) => {
12438
+ const found = [];
12439
+ const hooks = { isRaw: (name) => isRawMacro(name, replacesDo || parametersOf.widget?.(name) !== void 0) };
12440
+ for (const passage of list) {
12441
+ if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
12442
+ const open = [];
12443
+ const done = [];
12444
+ for (const token of tokenizeMarkupTolerant(passage.content, { hooks }).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
12445
+ if (!token.isClose) open.push({
12446
+ token,
12447
+ isBlock: false
12384
12448
  });
12385
- }
12386
- } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content))) open[open.length - 1].isBlock = true;
12387
- done.push(...open);
12388
- const defs = [];
12389
- for (const { token, isBlock, closeStart } of done) try {
12390
- const [from, to] = nameSpan(token.rawArgs);
12391
- defs.push({
12392
- ...parseWidgetDef(token.rawArgs),
12393
- block: isBlock,
12394
- passage: passage.name,
12395
- start: token.start,
12396
- end: token.end,
12397
- nameStart: token.argsStart + from,
12398
- nameEnd: token.argsStart + to,
12399
- ...closeStart === void 0 ? {} : { closeStart }
12400
- });
12401
- } catch {}
12402
- found.push(...defs.sort((a, b) => a.start - b.start));
12403
- }
12404
- return found;
12449
+ else {
12450
+ const def = open.pop();
12451
+ if (def) done.push({
12452
+ ...def,
12453
+ closeStart: token.start
12454
+ });
12455
+ }
12456
+ } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks))) open[open.length - 1].isBlock = true;
12457
+ done.push(...open);
12458
+ const defs = [];
12459
+ for (const { token, isBlock, closeStart } of done) try {
12460
+ const [from, to] = nameSpan(token.rawArgs);
12461
+ defs.push({
12462
+ ...parseWidgetDef(token.rawArgs),
12463
+ block: isBlock,
12464
+ passage: passage.name,
12465
+ start: token.start,
12466
+ end: token.end,
12467
+ nameStart: token.argsStart + from,
12468
+ nameEnd: token.argsStart + to,
12469
+ ...closeStart === void 0 ? {} : { closeStart }
12470
+ });
12471
+ } catch {}
12472
+ found.push(...defs.sort((a, b) => a.start - b.start));
12473
+ }
12474
+ return found;
12475
+ };
12476
+ const initial = scan(false);
12477
+ return effectiveWidgetDefinitions(initial).some((def) => def.name.toLowerCase() === "do") ? scan(true) : initial;
12405
12478
  }
12406
12479
  /**
12407
12480
  * The definitions the runtime ends up with, one per widget name: the closed
@@ -17077,7 +17150,25 @@ function executeMutation(code, mergedLocals, scopeUpdate) {
17077
17150
  for (const key of Object.keys(mergedLocals)) if (!hasOwn(localsClone, key)) scopeUpdate(key, void 0);
17078
17151
  }
17079
17152
  //#endregion
17153
+ //#region src/passage-render-state.ts
17154
+ /** Initial render of a deferred passage subtree, until its first commit. */
17155
+ var EntryRenderContext = createContext(null);
17156
+ /**
17157
+ * Navigation id (the store's `navigationId`) of the passage most recently
17158
+ * mounted by <Passage> (null until the first render, e.g. when the story
17159
+ * interface has no {passage}). Lets Story.waitForActions() tell whether the
17160
+ * current navigation is on screen, also when it revisits the passage shown.
17161
+ */
17162
+ var renderedNavigationId = null;
17163
+ function markPassageRendered(navigationId) {
17164
+ renderedNavigationId = navigationId;
17165
+ }
17166
+ function getRenderedNavigationId() {
17167
+ return renderedNavigationId;
17168
+ }
17169
+ //#endregion
17080
17170
  //#region src/triggers.ts
17171
+ var registrations = 0;
17081
17172
  var triggers = [];
17082
17173
  var checking = false;
17083
17174
  var dialogQueue = [];
@@ -17097,6 +17188,7 @@ function registerTrigger(condition, callbackOrOptions, macroKey) {
17097
17188
  const options = isCallback ? void 0 : callbackOrOptions;
17098
17189
  const callback = isCallback ? callbackOrOptions : void 0;
17099
17190
  const trigger = {
17191
+ order: registrations++,
17100
17192
  name: options?.name,
17101
17193
  condition,
17102
17194
  callback,
@@ -17128,6 +17220,73 @@ function addMacroTrigger(condition, options) {
17128
17220
  if (triggers.some((t) => t.macroKey === macroKey)) return;
17129
17221
  registerTrigger(condition, options, macroKey);
17130
17222
  }
17223
+ var macroRenderDepth = 0;
17224
+ var entryRenderDepth = 0;
17225
+ var replayNavigation = -1;
17226
+ var replayRemoved = /* @__PURE__ */ new Map();
17227
+ /** Entry lifecycle callbacks and deferred initial passage subtrees replay on load. */
17228
+ function duringEntryRender(render) {
17229
+ entryRenderDepth++;
17230
+ try {
17231
+ return render();
17232
+ } finally {
17233
+ entryRenderDepth--;
17234
+ }
17235
+ }
17236
+ function isEntryRender() {
17237
+ return entryRenderDepth > 0 || macroRenderDepth > 0 && getRenderedNavigationId() !== useStoryStore.getState().navigationId;
17238
+ }
17239
+ function duringMacroRender(render) {
17240
+ macroRenderDepth++;
17241
+ try {
17242
+ return render();
17243
+ } finally {
17244
+ macroRenderDepth--;
17245
+ }
17246
+ }
17247
+ /** Forget replay removals whose effects have become part of a recorded entry. */
17248
+ function clearReplayWatchers() {
17249
+ replayRemoved.clear();
17250
+ }
17251
+ function replayRemovals() {
17252
+ const navigation = useStoryStore.getState().navigationId;
17253
+ if (navigation !== replayNavigation) {
17254
+ replayRemoved.clear();
17255
+ replayNavigation = navigation;
17256
+ }
17257
+ return replayRemoved;
17258
+ }
17259
+ function rememberRemoval(trigger) {
17260
+ const removed = replayRemovals();
17261
+ if (!trigger.macroKey || !trigger.options) return;
17262
+ if (isEntryRender()) {
17263
+ if (removed.has(trigger.macroKey)) return;
17264
+ removed.set(trigger.macroKey, {
17265
+ watcher: {
17266
+ condition: trigger.condition,
17267
+ options: { ...trigger.options }
17268
+ },
17269
+ order: trigger.order
17270
+ });
17271
+ } else removed.delete(trigger.macroKey);
17272
+ }
17273
+ /** Entry-render removals plus still active watchers, absent when none need replay. */
17274
+ function savedReplayWatchers() {
17275
+ const removed = replayRemovals();
17276
+ if (!removed.size) return void 0;
17277
+ const all = new Map(removed);
17278
+ for (const trigger of triggers) {
17279
+ if (!trigger.macroKey || !trigger.options || all.has(trigger.macroKey)) continue;
17280
+ all.set(trigger.macroKey, {
17281
+ watcher: {
17282
+ condition: trigger.condition,
17283
+ options: { ...trigger.options }
17284
+ },
17285
+ order: trigger.order
17286
+ });
17287
+ }
17288
+ return [...all.values()].sort((a, b) => a.order - b.order).map(({ watcher }) => watcher);
17289
+ }
17131
17290
  /** Canonical identity includes every option, so an imported action cannot change it. */
17132
17291
  function watcherKey(condition, options) {
17133
17292
  const sorted = Object.fromEntries(Object.entries(options).sort(([a], [b]) => a < b ? -1 : 1));
@@ -17215,6 +17374,10 @@ function restoreMacroWatchers(watchers, interfaceSaved) {
17215
17374
  for (const { condition, options } of interfaceWatches) addMacroTrigger(condition, options);
17216
17375
  }
17217
17376
  function removeTrigger(name) {
17377
+ for (const trigger of triggers) if (trigger.name === name) rememberRemoval(trigger);
17378
+ if (!isEntryRender()) {
17379
+ for (const [key, { watcher }] of replayRemovals()) if (watcher.options.name === name) replayRemoved.delete(key);
17380
+ }
17218
17381
  triggers = triggers.filter((t) => t.name !== name);
17219
17382
  }
17220
17383
  function fireTrigger(trigger) {
@@ -17247,7 +17410,10 @@ function runCheckLoop() {
17247
17410
  trigger.lastResult = result;
17248
17411
  if (result && wasFalse) {
17249
17412
  anyFired = true;
17250
- if (trigger.options?.once) triggers = triggers.filter((t) => t !== trigger);
17413
+ if (trigger.options?.once) {
17414
+ rememberRemoval(trigger);
17415
+ triggers = triggers.filter((t) => t !== trigger);
17416
+ }
17251
17417
  fireTrigger(trigger);
17252
17418
  }
17253
17419
  }
@@ -17317,6 +17483,7 @@ function reinitTriggerState() {
17317
17483
  */
17318
17484
  function resetTriggers() {
17319
17485
  triggers = [];
17486
+ replayRemoved.clear();
17320
17487
  resets++;
17321
17488
  closeAllOpenDialogs();
17322
17489
  resetListeners.notify();
@@ -17501,7 +17668,7 @@ function isPayload(value) {
17501
17668
  if (!Array.isArray(history) || history.length === 0) return false;
17502
17669
  if (!everyEntry(history, isMoment)) return false;
17503
17670
  if (typeof historyIndex !== "number" || !Number.isInteger(historyIndex) || historyIndex < 0 || historyIndex >= history.length || history[historyIndex].passage !== value.passage) return false;
17504
- return isCountsMap(value.visitCounts) && isCountsMap(value.renderCounts) && isOptionalPRNGSnapshot(value.prng) && isWatchers(value.watchers) && (value.interfaceWatchers === void 0 || typeof value.interfaceWatchers === "boolean");
17671
+ return isCountsMap(value.visitCounts) && isCountsMap(value.renderCounts) && isOptionalPRNGSnapshot(value.prng) && isWatchers(value.watchers) && isWatchers(value.replayWatchers) && (value.interfaceWatchers === void 0 || typeof value.interfaceWatchers === "boolean");
17505
17672
  }
17506
17673
  var mapToCounts = (counts) => counts instanceof Map ? createCounts(Object.fromEntries(counts)) : void 0;
17507
17674
  /**
@@ -17519,6 +17686,7 @@ function decodePayload(encoded) {
17519
17686
  if (!isPayload(body)) throw invalid();
17520
17687
  assertArrayLengths(body, MAX_SAVE_ARRAY_LENGTH);
17521
17688
  assertTrustedWatchers(body.watchers ?? []);
17689
+ assertTrustedWatchers(body.replayWatchers ?? []);
17522
17690
  const payload = {
17523
17691
  ...body,
17524
17692
  visitCounts: mapToCounts(body.visitCounts),
@@ -18891,6 +19059,7 @@ function computeVarPatches(prev, curr) {
18891
19059
  * applyPatches copies each value, and recurses forever on a cycle).
18892
19060
  */
18893
19061
  function applyVarPatches(vars, changes) {
19062
+ if (changes.length === 0) return vars;
18894
19063
  const next = Object.create(Object.getPrototypeOf(vars));
18895
19064
  for (const key of Object.keys(vars)) setOwn(next, key, vars[key]);
18896
19065
  for (const change of changes) if (change.deleted) delete next[change.key];
@@ -18964,6 +19133,7 @@ function persistSession(get) {
18964
19133
  renderCounts,
18965
19134
  prng: snapshotPRNG(),
18966
19135
  watchers: savedMacroWatchers(),
19136
+ replayWatchers: savedReplayWatchers(),
18967
19137
  interfaceWatchers: interfaceMounted()
18968
19138
  });
18969
19139
  }
@@ -19035,6 +19205,7 @@ function finishEnteredMoment(get, set) {
19035
19205
  const moment = enteredMoment;
19036
19206
  enteredMoment = null;
19037
19207
  if (!moment || get().navigationId !== moment.navigationId) return;
19208
+ clearReplayWatchers();
19038
19209
  if (get().variables !== moment.variables) rerecordNewestMoment(get().variables);
19039
19210
  lastNavigationVars = get().variables;
19040
19211
  const prng = snapshotPRNG();
@@ -19143,6 +19314,7 @@ function recordStoryInitState() {
19143
19314
  const { history, historyIndex, variables } = useStoryStore.getState();
19144
19315
  if (history.length !== 1 || historyIndex !== 0) return;
19145
19316
  resetModuleState(variables);
19317
+ clearReplayWatchers();
19146
19318
  const prng = snapshotPRNG();
19147
19319
  useStoryStore.setState((state) => {
19148
19320
  state.history[0].prng = prng;
@@ -19907,6 +20079,7 @@ var useStoryStore = create()(storyStore((set, get) => ({
19907
20079
  renderCounts: { ...renderCounts },
19908
20080
  prng: snapshotPRNG(),
19909
20081
  watchers: savedMacroWatchers(),
20082
+ replayWatchers: savedReplayWatchers(),
19910
20083
  interfaceWatchers: interfaceMounted()
19911
20084
  };
19912
20085
  },
@@ -19935,6 +20108,7 @@ var useStoryStore = create()(storyStore((set, get) => ({
19935
20108
  }
19936
20109
  assertPassagesExist(get().storyData, payload);
19937
20110
  assertTrustedWatchers(payload.watchers ?? []);
20111
+ assertTrustedWatchers(payload.replayWatchers ?? []);
19938
20112
  applyReplacement(replacement);
19939
20113
  leavingPlaythrough = leaving;
19940
20114
  try {
@@ -19946,27 +20120,37 @@ var useStoryStore = create()(storyStore((set, get) => ({
19946
20120
  const ifid = get().storyData?.ifid;
19947
20121
  if (playthroughId && ifid) switchToLoadedPlaythrough(ifid, playthroughId);
19948
20122
  const entry = loadedEntryMoment(payload);
19949
- const snapshots = deepClone(payload.history.map((m) => m.variables)).map((vars) => createNamespace(vars));
20123
+ const index = Math.max(0, Math.min(payload.historyIndex, payload.history.length - 1));
20124
+ const start = Math.min(index, Math.max(0, payload.history.length - get().maxHistory));
20125
+ const retained = payload.history.slice(start, start + get().maxHistory);
20126
+ const namespaces = /* @__PURE__ */ new Map();
20127
+ const snapshots = deepClone(retained.map((m) => m.variables)).map((vars) => {
20128
+ let normalized = namespaces.get(vars);
20129
+ if (!normalized) {
20130
+ normalized = createNamespace(vars);
20131
+ namespaces.set(vars, normalized);
20132
+ }
20133
+ return normalized;
20134
+ });
19950
20135
  variableBase = deepClone(snapshots[0]);
19951
- patchEntries = snapshots.slice(1).map((curr, i) => computeVarPatches(snapshots[i], curr));
19952
- sessionMoments = payload.history.map((m, i) => savedMoment(m, snapshots[i]));
20136
+ patchEntries = snapshots.slice(1).map((curr, i) => curr === snapshots[i] ? { forward: [] } : computeVarPatches(snapshots[i], curr));
20137
+ sessionMoments = retained.map((m, i) => savedMoment(m, snapshots[i]));
19953
20138
  set((state) => {
19954
20139
  state.currentPassage = payload.passage;
19955
20140
  state.navigationId++;
19956
20141
  state.variables = createNamespace(deepClone(entry?.variables ?? payload.variables));
19957
- state.history = payload.history.map((m) => ({
20142
+ state.history = retained.map((m) => ({
19958
20143
  passage: m.passage,
19959
20144
  timestamp: m.timestamp,
19960
20145
  prng: m.prng
19961
20146
  }));
19962
- state.historyIndex = Math.max(0, Math.min(payload.historyIndex, state.history.length - 1));
19963
- trimHistory(state);
20147
+ state.historyIndex = index - start;
19964
20148
  state.visitCounts = createCounts(payload.visitCounts);
19965
20149
  state.renderCounts = createCounts(payload.renderCounts);
19966
20150
  state.temporary = createNamespace();
19967
20151
  state.transient = freshTransients(get().transientDefaults);
19968
20152
  });
19969
- if (payload.watchers) restoreMacroWatchers(payload.watchers, payload.interfaceWatchers);
20153
+ if (payload.watchers) restoreMacroWatchers(payload.replayWatchers ?? payload.watchers, payload.interfaceWatchers);
19970
20154
  reinitTriggerState();
19971
20155
  lastNavigationVars = reconstructVarsAt(get().historyIndex);
19972
20156
  restorePRNGFrom(entry?.prng !== void 0 ? entry.prng : payload.prng);
@@ -21022,6 +21206,7 @@ function defineMacro(config, source = "builtin") {
21022
21206
  checkParameterTypes(config.name, parameters);
21023
21207
  const acts = actingMacros.has(config.name);
21024
21208
  function Wrapper(props) {
21209
+ const entryRender = useContext(EntryRenderContext);
21025
21210
  const displayOnly = useContext(DisplayOnlyContext);
21026
21211
  if (displayOnly && acts) return h(MacroError, {
21027
21212
  macro: config.name,
@@ -21124,7 +21309,7 @@ function defineMacro(config, source = "builtin") {
21124
21309
  };
21125
21310
  }
21126
21311
  try {
21127
- return config.render(props, ctx);
21312
+ return entryRender?.pending ? duringEntryRender(() => config.render(props, ctx)) : duringMacroRender(() => config.render(props, ctx));
21128
21313
  } catch (error) {
21129
21314
  if (error instanceof MacroArgumentError) return h(MacroError, {
21130
21315
  macro: config.name,
@@ -21154,21 +21339,6 @@ function defineMacro(config, source = "builtin") {
21154
21339
  setDefinedBlockMacro(config.name, isBlock);
21155
21340
  }
21156
21341
  //#endregion
21157
- //#region src/passage-render-state.ts
21158
- /**
21159
- * Navigation id (the store's `navigationId`) of the passage most recently
21160
- * mounted by <Passage> (null until the first render, e.g. when the story
21161
- * interface has no {passage}). Lets Story.waitForActions() tell whether the
21162
- * current navigation is on screen, also when it revisits the passage shown.
21163
- */
21164
- var renderedNavigationId = null;
21165
- function markPassageRendered(navigationId) {
21166
- renderedNavigationId = navigationId;
21167
- }
21168
- function getRenderedNavigationId() {
21169
- return renderedNavigationId;
21170
- }
21171
- //#endregion
21172
21342
  //#region src/story-context-passage.ts
21173
21343
  /**
21174
21344
  * The macros a display-only passage may not use besides the input macros:
@@ -22450,22 +22620,40 @@ var Reader = class {
22450
22620
  }
22451
22621
  /** Skip an array literal (or any bracketed group) at the cursor. */
22452
22622
  skipBalanced() {
22453
- const { src } = this;
22454
22623
  const close = {
22455
22624
  "[": "]",
22456
22625
  "{": "}",
22457
22626
  "(": ")"
22458
- }[src.charAt(this.i)];
22459
- if (!close) return false;
22627
+ }[this.src.charAt(this.i)];
22628
+ return close ? this.skipNested(close) : false;
22629
+ }
22630
+ /** Skip groups and template interpolations with an explicit stack. */
22631
+ skipNested(close) {
22632
+ const { src } = this;
22633
+ const stack = [close];
22460
22634
  this.i++;
22461
- while (this.i < src.length) {
22462
- if (src.charAt(this.i) === close) {
22635
+ while (this.i < src.length && stack.length) {
22636
+ const c = src.charAt(this.i);
22637
+ const top = stack[stack.length - 1];
22638
+ if (c === top) {
22639
+ stack.pop();
22463
22640
  this.i++;
22464
- return true;
22465
- }
22466
- if (!this.skipOne()) return false;
22641
+ } else if (top === "`") {
22642
+ if (c === "\\") this.i += 2;
22643
+ else if (c === "$" && src.charAt(this.i + 1) === "{") {
22644
+ stack.push("}");
22645
+ this.i += 2;
22646
+ } else this.i++;
22647
+ } else if (c === "`" || c === "[" || c === "{" || c === "(") {
22648
+ stack.push(c === "`" ? "`" : {
22649
+ "[": "]",
22650
+ "{": "}",
22651
+ "(": ")"
22652
+ }[c]);
22653
+ this.i++;
22654
+ } else if (!this.skipOne()) return false;
22467
22655
  }
22468
- return false;
22656
+ return stack.length === 0;
22469
22657
  }
22470
22658
  /** Skip one character, or one string, template, comment or group. */
22471
22659
  skipOne() {
@@ -22492,20 +22680,7 @@ var Reader = class {
22492
22680
  }
22493
22681
  /** Skip a template literal, with the expressions in it. */
22494
22682
  skipTemplate() {
22495
- const { src } = this;
22496
- this.i++;
22497
- while (this.i < src.length) {
22498
- const c = src.charAt(this.i);
22499
- if (c === "\\") this.i += 2;
22500
- else if (c === "`") {
22501
- this.i++;
22502
- return true;
22503
- } else if (c === "$" && src.charAt(this.i + 1) === "{") {
22504
- this.i++;
22505
- if (!this.skipBalanced()) return false;
22506
- } else this.i++;
22507
- }
22508
- return false;
22683
+ return this.skipNested("`");
22509
22684
  }
22510
22685
  };
22511
22686
  //#endregion
@@ -23077,6 +23252,17 @@ var CODE_PASSAGES = /* @__PURE__ */ new Set([
23077
23252
  "PassageFooter",
23078
23253
  "PassageDone"
23079
23254
  ]);
23255
+ /** PassageDone mounts after the main passage committed, but replays on load. */
23256
+ function EntryRenderBoundary({ children }) {
23257
+ const phase = useRef({ pending: true });
23258
+ useLayoutEffect(() => {
23259
+ phase.current.pending = false;
23260
+ }, []);
23261
+ return /* @__PURE__ */ jsx(EntryRenderContext.Provider, {
23262
+ value: phase.current,
23263
+ children
23264
+ });
23265
+ }
23080
23266
  function Passage({ passage, dataTransition, navigationId }) {
23081
23267
  const { storyData } = useStoryFields("storyData");
23082
23268
  const isCodePassage = CODE_PASSAGES.has(passage.name);
@@ -23112,7 +23298,12 @@ function Passage({ passage, dataTransition, navigationId }) {
23112
23298
  const elRef = useRef(null);
23113
23299
  useLayoutEffect(() => {
23114
23300
  if (navigationId !== void 0) markPassageRendered(navigationId);
23115
- if (elRef.current) emitFromRender("passagerender", passage.name, elRef.current);
23301
+ if (elRef.current) {
23302
+ const element = elRef.current;
23303
+ const emit = () => emitFromRender("passagerender", passage.name, element);
23304
+ if (navigationId !== void 0) duringEntryRender(emit);
23305
+ else emit();
23306
+ }
23116
23307
  }, [passage.name, navigationId]);
23117
23308
  const nobr = passage.tags.includes("nobr");
23118
23309
  const viewScope = useViewScope();
@@ -23136,10 +23327,10 @@ function Passage({ passage, dataTransition, navigationId }) {
23136
23327
  class: "passage-footer",
23137
23328
  children: footerContent
23138
23329
  }),
23139
- doneContent && /* @__PURE__ */ jsx("div", {
23330
+ doneContent && /* @__PURE__ */ jsx(EntryRenderBoundary, { children: /* @__PURE__ */ jsx("div", {
23140
23331
  hidden: true,
23141
23332
  children: doneContent
23142
- })
23333
+ }) })
23143
23334
  ]
23144
23335
  })
23145
23336
  })