@rohal12/spindle 0.64.12 → 0.64.14

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.
@@ -13254,6 +13254,7 @@ var BLOCK_MACROS = new NameSet([
13254
13254
  "do",
13255
13255
  "button",
13256
13256
  "link",
13257
+ "dialog",
13257
13258
  "listbox",
13258
13259
  "cycle",
13259
13260
  "switch",
@@ -15543,7 +15544,7 @@ function widgetDefinitions(passages, parametersOf = registeredParameters) {
15543
15544
  });
15544
15545
  }
15545
15546
  } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks, budget))) open[open.length - 1].isBlock = true;
15546
- done.push(...open);
15547
+ for (const def of open) done.push(def);
15547
15548
  const defs = [];
15548
15549
  for (const { token, isBlock, closeStart } of done) try {
15549
15550
  const [from, to] = nameSpan(token.rawArgs);
@@ -15558,7 +15559,8 @@ function widgetDefinitions(passages, parametersOf = registeredParameters) {
15558
15559
  ...closeStart === void 0 ? {} : { closeStart }
15559
15560
  });
15560
15561
  } catch {}
15561
- found.push(...defs.sort((a, b) => a.start - b.start));
15562
+ defs.sort((a, b) => a.start - b.start);
15563
+ for (const def of defs) found.push(def);
15562
15564
  }
15563
15565
  return found;
15564
15566
  };
@@ -20475,13 +20477,25 @@ function tabIndexAttr(el) {
20475
20477
  if (raw === null || !/^\s*[+-]?\d+\s*$/.test(raw)) return null;
20476
20478
  return parseInt(raw, 10);
20477
20479
  }
20480
+ /** Eligible radio stops in one DOM tree, including external form controls. */
20481
+ function radioTabStops(root) {
20482
+ const groups = /* @__PURE__ */ new Map();
20483
+ for (const radio of root.querySelectorAll("input[type=\"radio\"]")) {
20484
+ if (!radio.name || (tabIndexAttr(radio) ?? 0) < 0 || !isAvailable(radio)) continue;
20485
+ let names = groups.get(radio.form);
20486
+ if (!names) groups.set(radio.form, names = /* @__PURE__ */ new Map());
20487
+ const stop = names.get(radio.name);
20488
+ if (!stop || !stop.checked && radio.checked) names.set(radio.name, radio);
20489
+ }
20490
+ return new Set([...groups.values()].flatMap((names) => [...names.values()]));
20491
+ }
20478
20492
  /**
20479
20493
  * Whether the tab key can reach `el`, an available element (see
20480
20494
  * isAvailable): a negative tabindex only allows scripted focus, and of a
20481
20495
  * radio group the browser tabs to the checked member only (the first one
20482
20496
  * when none is checked), of the members it can reach.
20483
20497
  */
20484
- function isTabStop(el) {
20498
+ function isTabStop(el, radioStops) {
20485
20499
  const tabIndex = tabIndexAttr(el);
20486
20500
  if (tabIndex !== null && tabIndex < 0) return false;
20487
20501
  if (tabIndex === null && el.hasAttribute("contenteditable") && !el.matches("a[href], button, input, select, textarea, iframe, summary") && (!el.isContentEditable || el.parentElement?.isContentEditable)) return false;
@@ -20491,8 +20505,13 @@ function isTabStop(el) {
20491
20505
  }
20492
20506
  const input = el;
20493
20507
  if (el.localName === "input" && input.type === "radio" && input.name) {
20494
- const group = Array.from(el.getRootNode().querySelectorAll("input[type=\"radio\"]")).filter((r) => r.name === input.name && r.form === input.form && (tabIndexAttr(r) ?? 0) >= 0 && isAvailable(r));
20495
- return el === (group.find((r) => r.checked) ?? group[0]);
20508
+ const tree = el.getRootNode();
20509
+ let stops = radioStops.get(tree);
20510
+ if (!stops) {
20511
+ stops = radioTabStops(tree);
20512
+ radioStops.set(tree, stops);
20513
+ }
20514
+ return stops.has(input);
20496
20515
  }
20497
20516
  return true;
20498
20517
  }
@@ -20501,18 +20520,18 @@ function isTabStop(el) {
20501
20520
  * order Tab visits them: positive tabindexes first, ascending, then the
20502
20521
  * others in document order.
20503
20522
  */
20504
- function focusables(root) {
20523
+ function focusables(root, radioStops = /* @__PURE__ */ new Map()) {
20505
20524
  const scopes = [];
20506
20525
  const collect = (parent) => {
20507
20526
  for (const element of composedChildren(parent)) {
20508
20527
  const el = element;
20509
20528
  const nested = el.shadowRoot ?? (el.localName === "slot" ? el : null);
20510
- const stop = el.matches(FOCUSABLE) && isAvailable(el) && isTabStop(el);
20529
+ const stop = el.matches(FOCUSABLE) && isAvailable(el) && isTabStop(el, radioStops);
20511
20530
  if (nested) {
20512
20531
  if ((tabIndexAttr(el) ?? 0) < 0) continue;
20513
20532
  scopes.push({
20514
20533
  el,
20515
- stops: [...stop && !el.shadowRoot?.delegatesFocus ? [el] : [], ...focusables(nested)]
20534
+ stops: [...stop && !el.shadowRoot?.delegatesFocus ? [el] : [], ...focusables(nested, radioStops)]
20516
20535
  });
20517
20536
  } else {
20518
20537
  if (stop) scopes.push({
@@ -3633,6 +3633,7 @@ var BLOCK_MACROS = new NameSet([
3633
3633
  "do",
3634
3634
  "button",
3635
3635
  "link",
3636
+ "dialog",
3636
3637
  "listbox",
3637
3638
  "cycle",
3638
3639
  "switch",
@@ -12240,7 +12241,7 @@ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
12240
12241
  });
12241
12242
  }
12242
12243
  } else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks, budget))) open[open.length - 1].isBlock = true;
12243
- done.push(...open);
12244
+ for (const def of open) done.push(def);
12244
12245
  const defs = [];
12245
12246
  for (const { token, isBlock, closeStart } of done) try {
12246
12247
  const [from, to] = nameSpan(token.rawArgs);
@@ -12255,7 +12256,8 @@ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
12255
12256
  ...closeStart === void 0 ? {} : { closeStart }
12256
12257
  });
12257
12258
  } catch {}
12258
- found.push(...defs.sort((a, b) => a.start - b.start));
12259
+ defs.sort((a, b) => a.start - b.start);
12260
+ for (const def of defs) found.push(def);
12259
12261
  }
12260
12262
  return found;
12261
12263
  };
@@ -13557,7 +13559,7 @@ var Bindings = class {
13557
13559
  innermostVisible(bindings, at) {
13558
13560
  const useFunction = this.functionStart(at);
13559
13561
  const visible = bindings.filter((b) => b.scope.start <= at && at < b.scope.end && (!b.ordered || b.at < at || this.functionStart(b.at) !== useFunction));
13560
- const innermost = Math.max(...visible.map((b) => b.scope.start));
13562
+ const innermost = visible.reduce((start, b) => Math.max(start, b.scope.start), -Infinity);
13561
13563
  return visible.filter((b) => b.scope.start === innermost);
13562
13564
  }
13563
13565
  readGroups() {
@@ -25603,13 +25605,13 @@ async function formatLf(text, options) {
25603
25605
  if (region.type !== "spindle") region.lines = region.lines.map((l) => replaceAll(l, sentinel, "\n"));
25604
25606
  if (region.type === "script") {
25605
25607
  if (region.lines.length === 1) {
25606
- lines.push(...region.lines);
25608
+ for (const line of region.lines) lines.push(line);
25607
25609
  continue;
25608
25610
  }
25609
25611
  const innerCode = region.lines.slice(1, -1).join("\n");
25610
25612
  const formatted = await formatJS(innerCode.trim(), prettier, prettierOptions);
25611
25613
  if (formatted === void 0 || !sameSpindleTokens(innerCode, formatted)) {
25612
- lines.push(...region.lines);
25614
+ for (const line of region.lines) lines.push(line);
25613
25615
  continue;
25614
25616
  }
25615
25617
  lines.push(region.lines[0]);
@@ -25618,25 +25620,25 @@ async function formatLf(text, options) {
25618
25620
  continue;
25619
25621
  }
25620
25622
  if (region.type === "svg") {
25621
- lines.push(...region.lines);
25623
+ for (const line of region.lines) lines.push(line);
25622
25624
  continue;
25623
25625
  }
25624
25626
  if (region.type === "html") {
25625
25627
  const htmlText = region.lines.join("\n");
25626
25628
  if (WHITESPACE_AS_WRITTEN.test(htmlText) || region.lines.some((line) => literalLines.has(line.trim())) || hasMarkdownBoundaries(htmlText, isBlock)) {
25627
25629
  for (let i = 0; i < region.lines.length; i++) preservedLines.add(lines.length + i);
25628
- lines.push(...region.lines);
25630
+ for (const line of region.lines) lines.push(line);
25629
25631
  continue;
25630
25632
  }
25631
25633
  const { text: svgPlaceholdered, tokens: svgTokens } = replaceSvgBlocks(htmlText);
25632
25634
  if (!placeholdersIntact(svgPlaceholdered, svgTokens, SVG_PLACEHOLDERS)) {
25633
- lines.push(...region.lines);
25635
+ for (const line of region.lines) lines.push(line);
25634
25636
  continue;
25635
25637
  }
25636
25638
  const { text: placeholdered, tokens } = replaceSpindleTokens(svgPlaceholdered);
25637
25639
  const formatted = await formatHTML(placeholdered, prettier, prettierOptions);
25638
25640
  if (formatted === void 0 || !placeholdersIntact(formatted, tokens, SPINDLE_PLACEHOLDERS) || !placeholdersIntact(formatted, svgTokens, SVG_PLACEHOLDERS)) {
25639
- lines.push(...region.lines);
25641
+ for (const line of region.lines) lines.push(line);
25640
25642
  continue;
25641
25643
  }
25642
25644
  const restored = restoreHtmlTokens(formatted.trim(), tokens.map((t) => replaceAll(t, "\n", sentinel)), svgTokens);
@@ -25656,6 +25658,14 @@ async function formatLf(text, options) {
25656
25658
  }
25657
25659
  /** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
25658
25660
  var WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
25661
+ /** JavaScript MIME types (including legacy aliases) and module scripts. */
25662
+ var JAVASCRIPT_TYPE = /^(?:module|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:javascript1\.[0-5]|jscript|livescript))$/i;
25663
+ /** Data scripts have opaque bodies, even inside a larger HTML region. */
25664
+ function isDataScript(token) {
25665
+ if (token.tag.toLowerCase() !== "script") return false;
25666
+ const type = Object.entries(token.attributes).find(([name]) => name.toLowerCase() === "type")?.[1].trim();
25667
+ return !!type && !JAVASCRIPT_TYPE.test(type);
25668
+ }
25659
25669
  /** HTML whitespace formatting must not collapse the Markdown in its bodies. */
25660
25670
  var HTML_MARKDOWN_BOUNDARIES = /* @__PURE__ */ new Set([
25661
25671
  "hardBreakTrailing",
@@ -25683,13 +25693,13 @@ function hasMarkdownBoundaries(source, isBlock) {
25683
25693
  /** Preserve whole literal elements, including openers beside nested tags. */
25684
25694
  function whitespaceSensitiveLines(source, isBlock) {
25685
25695
  const lines = /* @__PURE__ */ new Set();
25686
- if (!WHITESPACE_AS_WRITTEN.test(source)) return lines;
25696
+ if (!WHITESPACE_AS_WRITTEN.test(source) && !/<script[\s>]/i.test(source)) return lines;
25687
25697
  const lineAt = sourceLines(source);
25688
25698
  const { nodes } = analyzeMarkup(source, { hooks: { isBlock } });
25689
25699
  function visit(nodes) {
25690
25700
  for (const node of nodes) {
25691
25701
  const { token, body } = node;
25692
- if (token.type === "html" && ([
25702
+ if (token.type === "html" && (isDataScript(token) || [
25693
25703
  "pre",
25694
25704
  "textarea",
25695
25705
  "svg"
@@ -25889,7 +25899,7 @@ function wrapLines(lines, maxLen, literalLines, isBlock) {
25889
25899
  continue;
25890
25900
  }
25891
25901
  if (line.endsWith(" ")) wrapped[wrapped.length - 1] += " ";
25892
- result.push(...wrapped);
25902
+ for (const line of wrapped) result.push(line);
25893
25903
  }
25894
25904
  return result;
25895
25905
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.64.12",
3
+ "version": "0.64.14",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -1,7 +1,7 @@
1
1
  import { isBlockMacro } from '../markup/ast';
2
2
  import { analyzeMarkup, tokenizeMarkupTolerant } from '../markup/parse';
3
3
  import type { PairedNode } from '../markup/pair';
4
- import type { MacroToken } from '../markup/tokens';
4
+ import type { HtmlToken, MacroToken } from '../markup/tokens';
5
5
  import { segmentRegions } from './segment';
6
6
  import { markdownLines } from './markdown-lines';
7
7
  import { sourceLines } from './source-lines';
@@ -246,7 +246,7 @@ async function formatLf(
246
246
  if (region.type === 'script') {
247
247
  // Same-line <script>…</script> — leave as written
248
248
  if (region.lines.length === 1) {
249
- lines.push(...region.lines);
249
+ for (const line of region.lines) lines.push(line);
250
250
  continue;
251
251
  }
252
252
  // Inline <script> — format JS content between tags
@@ -259,7 +259,7 @@ async function formatLf(
259
259
  // Without Prettier, where it fails, or where it changed a Spindle
260
260
  // token (`{$a}` is an object literal to it), the region stays as written
261
261
  if (formatted === undefined || !sameSpindleTokens(innerCode, formatted)) {
262
- lines.push(...region.lines);
262
+ for (const line of region.lines) lines.push(line);
263
263
  continue;
264
264
  }
265
265
  lines.push(region.lines[0]!);
@@ -277,7 +277,7 @@ async function formatLf(
277
277
 
278
278
  if (region.type === 'svg') {
279
279
  // SVG block — leave untouched (Prettier would break rendering)
280
- lines.push(...region.lines);
280
+ for (const line of region.lines) lines.push(line);
281
281
  continue;
282
282
  }
283
283
 
@@ -293,7 +293,7 @@ async function formatLf(
293
293
  ) {
294
294
  for (let i = 0; i < region.lines.length; i++)
295
295
  preservedLines.add(lines.length + i);
296
- lines.push(...region.lines);
296
+ for (const line of region.lines) lines.push(line);
297
297
  continue;
298
298
  }
299
299
  // HTML block — placeholder substitution + Prettier
@@ -302,7 +302,7 @@ async function formatLf(
302
302
  // A later whole-line Spindle token may hide an SVG marker. Check
303
303
  // before that pass so a literal marker cannot stand in for it.
304
304
  if (!placeholdersIntact(svgPlaceholdered, svgTokens, SVG_PLACEHOLDERS)) {
305
- lines.push(...region.lines);
305
+ for (const line of region.lines) lines.push(line);
306
306
  continue;
307
307
  }
308
308
  const { text: placeholdered, tokens } =
@@ -320,7 +320,7 @@ async function formatLf(
320
320
  !placeholdersIntact(formatted, tokens, SPINDLE_PLACEHOLDERS) ||
321
321
  !placeholdersIntact(formatted, svgTokens, SVG_PLACEHOLDERS)
322
322
  ) {
323
- lines.push(...region.lines);
323
+ for (const line of region.lines) lines.push(line);
324
324
  continue;
325
325
  }
326
326
  // A token's line breaks are its payload: keep them out of the line steps below
@@ -379,6 +379,19 @@ async function formatLf(
379
379
  /** Literal HTML and opaque SVG, whose text can inherit significant whitespace. */
380
380
  const WHITESPACE_AS_WRITTEN = /<(?:pre|textarea|svg)[\s>]|white-space\s*:/i;
381
381
 
382
+ /** JavaScript MIME types (including legacy aliases) and module scripts. */
383
+ const JAVASCRIPT_TYPE =
384
+ /^(?:module|(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/(?:javascript1\.[0-5]|jscript|livescript))$/i;
385
+
386
+ /** Data scripts have opaque bodies, even inside a larger HTML region. */
387
+ function isDataScript(token: HtmlToken): boolean {
388
+ if (token.tag.toLowerCase() !== 'script') return false;
389
+ const type = Object.entries(token.attributes)
390
+ .find(([name]) => name.toLowerCase() === 'type')?.[1]
391
+ .trim();
392
+ return !!type && !JAVASCRIPT_TYPE.test(type);
393
+ }
394
+
382
395
  /** HTML whitespace formatting must not collapse the Markdown in its bodies. */
383
396
  const HTML_MARKDOWN_BOUNDARIES = new Set([
384
397
  'hardBreakTrailing',
@@ -420,7 +433,8 @@ function whitespaceSensitiveLines(
420
433
  isBlock: (name: string) => boolean,
421
434
  ): Set<number> {
422
435
  const lines = new Set<number>();
423
- if (!WHITESPACE_AS_WRITTEN.test(source)) return lines;
436
+ if (!WHITESPACE_AS_WRITTEN.test(source) && !/<script[\s>]/i.test(source))
437
+ return lines;
424
438
  const lineAt = sourceLines(source);
425
439
  const { nodes } = analyzeMarkup(source, { hooks: { isBlock } });
426
440
  function visit(nodes: PairedNode[]): void {
@@ -428,7 +442,8 @@ function whitespaceSensitiveLines(
428
442
  const { token, body } = node;
429
443
  if (
430
444
  token.type === 'html' &&
431
- (['pre', 'textarea', 'svg'].includes(token.tag.toLowerCase()) ||
445
+ (isDataScript(token) ||
446
+ ['pre', 'textarea', 'svg'].includes(token.tag.toLowerCase()) ||
432
447
  Object.entries(token.attributes).some(
433
448
  ([name, value]) =>
434
449
  name.toLowerCase() === 'style' && /white-space\s*:/i.test(value),
@@ -722,7 +737,7 @@ function wrapLines(
722
737
  }
723
738
  // Keep a Markdown hard break on the last wrapped line
724
739
  if (line.endsWith(' ')) wrapped[wrapped.length - 1] += ' ';
725
- result.push(...wrapped);
740
+ for (const line of wrapped) result.push(line);
726
741
  }
727
742
 
728
743
  return result;
@@ -55,13 +55,36 @@ function tabIndexAttr(el: HTMLElement): number | null {
55
55
  return parseInt(raw, 10);
56
56
  }
57
57
 
58
+ /** Eligible radio stops in one DOM tree, including external form controls. */
59
+ function radioTabStops(root: ParentNode): Set<HTMLInputElement> {
60
+ const groups = new Map<
61
+ HTMLFormElement | null,
62
+ Map<string, HTMLInputElement>
63
+ >();
64
+ for (const radio of root.querySelectorAll<HTMLInputElement>(
65
+ 'input[type="radio"]',
66
+ )) {
67
+ if (!radio.name || (tabIndexAttr(radio) ?? 0) < 0 || !isAvailable(radio)) {
68
+ continue;
69
+ }
70
+ let names = groups.get(radio.form);
71
+ if (!names) groups.set(radio.form, (names = new Map()));
72
+ const stop = names.get(radio.name);
73
+ // First eligible checked member, otherwise first eligible member (#390).
74
+ if (!stop || (!stop.checked && radio.checked)) names.set(radio.name, radio);
75
+ }
76
+ return new Set([...groups.values()].flatMap((names) => [...names.values()]));
77
+ }
78
+
79
+ type RadioStops = Map<Node, Set<HTMLInputElement>>;
80
+
58
81
  /**
59
82
  * Whether the tab key can reach `el`, an available element (see
60
83
  * isAvailable): a negative tabindex only allows scripted focus, and of a
61
84
  * radio group the browser tabs to the checked member only (the first one
62
85
  * when none is checked), of the members it can reach.
63
86
  */
64
- function isTabStop(el: HTMLElement): boolean {
87
+ function isTabStop(el: HTMLElement, radioStops: RadioStops): boolean {
65
88
  const tabIndex = tabIndexAttr(el);
66
89
  if (tabIndex !== null && tabIndex < 0) return false;
67
90
  // Only an editing host takes focus of its own, not `contenteditable="false"`
@@ -89,22 +112,15 @@ function isTabStop(el: HTMLElement): boolean {
89
112
  // another realm's classes
90
113
  const input = el as HTMLInputElement;
91
114
  if (el.localName === 'input' && input.type === 'radio' && input.name) {
92
- const group = Array.from(
93
- // Form ownership does not imply DOM ancestry: `form="id"` controls
94
- // elsewhere in the same tree belong to the group too (#688).
95
- (el.getRootNode() as ParentNode).querySelectorAll<HTMLInputElement>(
96
- 'input[type="radio"]',
97
- ),
98
- ).filter(
99
- (r) =>
100
- r.name === input.name &&
101
- r.form === input.form &&
102
- // Of the members Tab can reach (#390)
103
- (tabIndexAttr(r) ?? 0) >= 0 &&
104
- isAvailable(r),
105
- );
106
- const stop = group.find((r) => r.checked) ?? group[0];
107
- return el === stop;
115
+ const tree = el.getRootNode();
116
+ let stops = radioStops.get(tree);
117
+ if (!stops) {
118
+ // Form ownership is independent of DOM ancestry (#688). Index the
119
+ // entire tree once, shared across shadow/slot tabindex scopes (#718).
120
+ stops = radioTabStops(tree as ParentNode);
121
+ radioStops.set(tree, stops);
122
+ }
123
+ return stops.has(input);
108
124
  }
109
125
  return true;
110
126
  }
@@ -114,7 +130,10 @@ function isTabStop(el: HTMLElement): boolean {
114
130
  * order Tab visits them: positive tabindexes first, ascending, then the
115
131
  * others in document order.
116
132
  */
117
- function focusables(root: ParentNode): HTMLElement[] {
133
+ function focusables(
134
+ root: ParentNode,
135
+ radioStops: RadioStops = new Map(),
136
+ ): HTMLElement[] {
118
137
  // Each shadow host/slot owns a separate tabindex scope. Sort the owners in
119
138
  // this scope, then expand their contents in place, as native Tab does.
120
139
  const scopes: { el: HTMLElement; stops: HTMLElement[] }[] = [];
@@ -122,7 +141,8 @@ function focusables(root: ParentNode): HTMLElement[] {
122
141
  for (const element of composedChildren(parent)) {
123
142
  const el = element as HTMLElement;
124
143
  const nested = el.shadowRoot ?? (el.localName === 'slot' ? el : null);
125
- const stop = el.matches(FOCUSABLE) && isAvailable(el) && isTabStop(el);
144
+ const stop =
145
+ el.matches(FOCUSABLE) && isAvailable(el) && isTabStop(el, radioStops);
126
146
  if (nested) {
127
147
  // A visibility:hidden host can contain explicitly visible controls.
128
148
  // Each stop checks its own visibility and its ancestors' subtree gates.
@@ -131,7 +151,7 @@ function focusables(root: ParentNode): HTMLElement[] {
131
151
  el,
132
152
  stops: [
133
153
  ...(stop && !el.shadowRoot?.delegatesFocus ? [el] : []),
134
- ...focusables(nested),
154
+ ...focusables(nested, radioStops),
135
155
  ],
136
156
  });
137
157
  } else {
@@ -152,7 +152,10 @@ export class Bindings {
152
152
  at < b.scope.end &&
153
153
  (!b.ordered || b.at < at || this.functionStart(b.at) !== useFunction),
154
154
  );
155
- const innermost = Math.max(...visible.map((b) => b.scope.start));
155
+ const innermost = visible.reduce(
156
+ (start, b) => Math.max(start, b.scope.start),
157
+ -Infinity,
158
+ );
156
159
  return visible.filter((b) => b.scope.start === innermost);
157
160
  }
158
161
 
package/src/markup/ast.ts CHANGED
@@ -55,6 +55,7 @@ const BLOCK_MACROS = new NameSet([
55
55
  'do',
56
56
  'button',
57
57
  'link',
58
+ 'dialog',
58
59
  'listbox',
59
60
  'cycle',
60
61
  'switch',
@@ -365,8 +365,16 @@ function spansOf(text: string, reading: Reading): StyledSpan[] {
365
365
  const canvas = new Canvas(text.length);
366
366
  const comment = openComment(tokens);
367
367
  if (comment >= 0) canvas.paint(comment, text.length, 'comment');
368
- for (const start of unclosedStarts(text, reading)) {
369
- canvas.paint(start, text.length, 'error');
368
+ const starts = unclosedStarts(text, reading);
369
+ // Later suffix paints cover earlier ones. Paint only their visible parts,
370
+ // retaining each paint's span boundary without repeatedly filling the tail.
371
+ let end = text.length;
372
+ for (let i = starts.length - 1; i >= 0; i--) {
373
+ const start = starts[i]!;
374
+ if (start < end) {
375
+ canvas.paint(start, end, 'error');
376
+ end = start;
377
+ }
370
378
  }
371
379
  for (const error of errors) {
372
380
  if (!isUnclosed(error)) {
@@ -423,7 +431,9 @@ function openStartOf(text: string, reading: Reading): number {
423
431
  openDo(tokens)?.start ?? -1,
424
432
  openTag(text, tokens),
425
433
  ].filter((start) => start >= 0);
426
- return starts.length > 0 ? Math.min(...starts) : -1;
434
+ return starts.length > 0
435
+ ? starts.reduce((first, start) => Math.min(first, start), Infinity)
436
+ : -1;
427
437
  }
428
438
 
429
439
  /**
@@ -180,7 +180,7 @@ export function widgetDefinitions(
180
180
  open[open.length - 1]!.isBlock = true;
181
181
  }
182
182
  }
183
- done.push(...open);
183
+ for (const def of open) done.push(def);
184
184
  const defs: WidgetDefinition[] = [];
185
185
  for (const { token, isBlock, closeStart } of done) {
186
186
  try {
@@ -199,7 +199,8 @@ export function widgetDefinitions(
199
199
  // The {widget} macro reports a definition it cannot read
200
200
  }
201
201
  }
202
- found.push(...defs.sort((a, b) => a.start - b.start));
202
+ defs.sort((a, b) => a.start - b.start);
203
+ for (const def of defs) found.push(def);
203
204
  }
204
205
  return found;
205
206
  };