@mdsvex/render 1.0.0-next.0 → 1.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Node.svelte CHANGED
@@ -1,127 +1,251 @@
1
1
  <script lang="ts">
2
- import type { NodeBuffer } from "@mdsvex/parse/utils";
3
- import {
4
- buf_children,
5
- buf_text,
6
- buf_text_content,
7
- } from "@mdsvex/parse/buf-utils";
8
- import type { Component } from "svelte";
9
- import Node from "./Node.svelte";
10
-
11
- type ComponentMap = Record<string, Component<any>>;
12
-
13
- let {
14
- buf,
15
- idx,
16
- source,
17
- components,
18
- }: {
19
- buf: NodeBuffer;
20
- idx: number;
21
- source: string;
22
- components?: ComponentMap;
23
- } = $props();
24
-
25
- const NONE = 0xffffffff;
26
-
27
- // kind constants
28
- const K_ROOT = 0;
29
- const K_TEXT = 1;
30
- const K_HTML = 2;
31
- const K_HEADING = 3;
32
- const K_CODE_FENCE = 5;
33
- const K_LINE_BREAK = 6;
34
- const K_PARAGRAPH = 7;
35
- const K_CODE_SPAN = 8;
36
- const K_EMPHASIS = 9;
37
- const K_STRONG = 10;
38
- const K_THEMATIC_BREAK = 11;
39
- const K_LINK = 12;
40
- const K_IMAGE = 13;
41
- const K_BLOCK_QUOTE = 14;
42
- const K_LIST = 15;
43
- const K_LIST_ITEM = 16;
44
- const K_HARD_BREAK = 17;
45
- const K_SOFT_BREAK = 18;
46
- const K_STRIKETHROUGH = 19;
47
- const K_SUPERSCRIPT = 20;
48
- const K_SUBSCRIPT = 21;
49
- const K_TABLE = 22;
50
- const K_TABLE_HEADER = 23;
51
- const K_TABLE_ROW = 24;
52
- const K_TABLE_CELL = 25;
53
- const K_HTML_COMMENT = 26;
54
-
55
- const NEWLINE = "\n";
56
-
57
- /** metadata keys that are structural and should not become html attributes. */
58
- const INTERNAL_KEYS = new Set([
59
- "ordered", "tight", "start",
60
- "info", "info_start", "info_end",
61
- "tag", "attributes", "self_closing",
62
- "alignments", "col_count",
63
- "src",
64
- ]);
65
- const LINK_SKIP = new Set(["href", "title"]);
66
- const IMAGE_SKIP = new Set(["title"]);
67
-
68
- /** extract plugin-set attrs from metadata as a spreadable object. */
69
- function get_attrs(meta: Record<string, unknown> | undefined, skip?: Set<string>): Record<string, any> {
70
- if (!meta) return {};
71
- const result: Record<string, any> = {};
72
- for (const key in meta) {
73
- if (INTERNAL_KEYS.has(key)) continue;
74
- if (skip !== undefined && skip.has(key)) continue;
75
- const val = meta[key];
76
- if (val === true) {
77
- result[key] = true;
78
- } else if (val !== false && val != null) {
79
- result[key] = String(val);
2
+ import { is_raw_text_tag } from '@mdsvex/parse/utils';
3
+ import type { NodeBuffer } from '@mdsvex/parse/utils';
4
+ import {
5
+ buf_children,
6
+ buf_code,
7
+ buf_text,
8
+ buf_text_content,
9
+ } from '@mdsvex/parse/buf-utils';
10
+ import { setContext } from 'svelte';
11
+ import type { Component } from 'svelte';
12
+ import Node from './Node.svelte';
13
+
14
+ type ComponentMap = Record<string, Component<any>>;
15
+
16
+ let {
17
+ buf,
18
+ idx,
19
+ source,
20
+ components,
21
+ directives,
22
+ plugin_data,
23
+ }: {
24
+ buf: NodeBuffer;
25
+ idx: number;
26
+ source: string;
27
+ /** a component for an element by its tag */
28
+ components?: ComponentMap;
29
+ /** a component for a directive by its name, args are its props, label and children snippets */
30
+ directives?: ComponentMap;
31
+ /** what plugins wrote, a component reads it from the context, see PluginStream */
32
+ plugin_data?: { readonly current: unknown };
33
+ } = $props();
34
+
35
+ // the key of @mdsvex/render/stream and of a compiled document, Symbol.for so every copy agrees
36
+ // svelte-ignore state_referenced_locally
37
+ if (plugin_data !== undefined)
38
+ setContext(Symbol.for('mdsvex.plugin_data'), plugin_data);
39
+
40
+ const NONE = 0xffffffff;
41
+
42
+ // kind constants
43
+ const K_ROOT = 0;
44
+ const K_TEXT = 1;
45
+ const K_HTML = 2;
46
+ const K_HEADING = 3;
47
+ const K_CODE_FENCE = 5;
48
+ const K_LINE_BREAK = 6;
49
+ const K_PARAGRAPH = 7;
50
+ const K_CODE_SPAN = 8;
51
+ const K_EMPHASIS = 9;
52
+ const K_STRONG = 10;
53
+ const K_THEMATIC_BREAK = 11;
54
+ const K_LINK = 12;
55
+ const K_IMAGE = 13;
56
+ const K_BLOCK_QUOTE = 14;
57
+ const K_LIST = 15;
58
+ const K_LIST_ITEM = 16;
59
+ const K_HARD_BREAK = 17;
60
+ const K_SOFT_BREAK = 18;
61
+ const K_STRIKETHROUGH = 19;
62
+ const K_SUPERSCRIPT = 20;
63
+ const K_SUBSCRIPT = 21;
64
+ const K_TABLE = 22;
65
+ const K_TABLE_HEADER = 23;
66
+ const K_TABLE_ROW = 24;
67
+ // a cell extra is its grid column, merged cells leave gaps in a row
68
+ const K_TABLE_CELL = 25;
69
+ const K_HTML_COMMENT = 26;
70
+ const K_DIRECTIVE_INLINE = 30;
71
+ const K_DIRECTIVE_LEAF = 31;
72
+ const K_DIRECTIVE_CONTAINER = 32;
73
+ const K_DIRECTIVE_LABEL = 35;
74
+ const K_FOOTNOTE_REFERENCE = 36;
75
+ const K_FOOTNOTE_DEFINITION = 37;
76
+ const K_DEFINITION = 38;
77
+
78
+ const NEWLINE = '\n';
79
+
80
+ /** metadata keys that are structural and should not become html attributes. */
81
+ const INTERNAL_KEYS = new Set([
82
+ 'ordered',
83
+ 'tight',
84
+ 'start',
85
+ 'checked',
86
+ 'info',
87
+ 'info_start',
88
+ 'info_end',
89
+ 'tag',
90
+ 'attributes',
91
+ 'self_closing',
92
+ 'alignments',
93
+ 'col_count',
94
+ 'header_columns',
95
+ 'spans',
96
+ 'src',
97
+ ]);
98
+ const LINK_SKIP = new Set(['href', 'title']);
99
+ const IMAGE_SKIP = new Set(['title']);
100
+
101
+ /** extract plugin-set attrs from metadata as a spreadable object. */
102
+ function get_attrs(
103
+ meta: Record<string, unknown> | undefined,
104
+ skip?: Set<string>
105
+ ): Record<string, any> {
106
+ if (!meta) return {};
107
+ const result: Record<string, any> = {};
108
+ for (const key in meta) {
109
+ if (INTERNAL_KEYS.has(key)) continue;
110
+ if (skip !== undefined && skip.has(key)) continue;
111
+ const val = meta[key];
112
+ if (val === true) {
113
+ result[key] = true;
114
+ } else if (val !== false && val != null) {
115
+ result[key] = String(val);
116
+ }
117
+ }
118
+ return result;
119
+ }
120
+
121
+ let kind = $derived(buf.kind_at(idx));
122
+ let extra = $derived(buf.extra_at(idx));
123
+ let meta = $derived(buf.metadata_at(idx));
124
+
125
+ // a pending paragraph inside a list_item is a speculative wrapper for
126
+ // a list that may still become loose. render its children transparently
127
+ // so the tight-list default matches the common case and avoids a
128
+ // <p> flash before the list closes.
129
+ let skip_list_item_paragraph_wrapper = $derived(
130
+ kind === K_PARAGRAPH &&
131
+ buf.pending_at(idx) === 1 &&
132
+ buf.kind_at(buf.parent_at(idx)) === K_LIST_ITEM
133
+ );
134
+
135
+ /** true when the checkbox of a task item goes inside its first paragraph, as github renders a loose list */
136
+ function box_in_paragraph(item: number): boolean {
137
+ const first = buf.first_child_at(item);
138
+ return (
139
+ first !== NONE &&
140
+ buf.kind_at(first) === K_PARAGRAPH &&
141
+ buf.pending_at(first) !== 1
142
+ );
143
+ }
144
+
145
+ // the checkbox state this node renders, undefined for no checkbox
146
+ let checked = $derived.by(() => {
147
+ if (kind === K_LIST_ITEM) {
148
+ return box_in_paragraph(idx) ? undefined : meta?.checked;
149
+ }
150
+ if (kind !== K_PARAGRAPH || skip_list_item_paragraph_wrapper) {
151
+ return undefined;
80
152
  }
153
+ const parent = buf.parent_at(idx);
154
+ if (
155
+ parent === NONE ||
156
+ buf.kind_at(parent) !== K_LIST_ITEM ||
157
+ buf.first_child_at(parent) !== idx
158
+ ) {
159
+ return undefined;
160
+ }
161
+ return buf.metadata_at(parent)?.checked;
162
+ });
163
+
164
+ /** the directive_label of a leaf or container, its first child, or NONE */
165
+ function label_of(node: number): number {
166
+ if (kind === K_DIRECTIVE_INLINE) return NONE;
167
+ const first = buf.first_child_at(node);
168
+ return first !== NONE &&
169
+ buf.parent_at(first) === node &&
170
+ buf.kind_at(first) === K_DIRECTIVE_LABEL
171
+ ? first
172
+ : NONE;
81
173
  }
82
- return result;
83
- }
84
-
85
- let kind = $derived(buf._kinds[idx]);
86
- let extra = $derived(buf._extras[idx]);
87
- let meta = $derived(buf.metadata_at(idx));
88
-
89
- // a pending paragraph inside a list_item is a speculative wrapper for
90
- // a list that may still become loose. render its children transparently
91
- // so the tight-list default matches the common case and avoids a
92
- // <p> flash before the list closes.
93
- let skip_list_item_paragraph_wrapper = $derived(
94
- kind === K_PARAGRAPH &&
95
- buf._pending_nodes[idx] === 1 &&
96
- buf._kinds[buf._parents[idx]] === K_LIST_ITEM,
97
- );
174
+
175
+ /** a child other than the label and line breaks, a component gets no empty children */
176
+ function has_body(node: number): boolean {
177
+ for (const child of buf_children(buf, node)) {
178
+ const k = buf.kind_at(child);
179
+ if (k !== K_LINE_BREAK && k !== K_DIRECTIVE_LABEL) return true;
180
+ }
181
+ return false;
182
+ }
183
+
184
+ let directive = $derived(
185
+ kind === K_DIRECTIVE_INLINE ||
186
+ kind === K_DIRECTIVE_LEAF ||
187
+ kind === K_DIRECTIVE_CONTAINER
188
+ ? directives?.[meta?.name as string]
189
+ : undefined
190
+ );
98
191
  </script>
99
192
 
193
+ {#snippet task_box()}
194
+ {#if typeof checked === 'boolean'}
195
+ <input type="checkbox" disabled {checked} />{' '}
196
+ {/if}
197
+ {/snippet}
198
+
100
199
  {#snippet child_nodes(parent_idx: number)}
101
200
  {#each buf_children(buf, parent_idx) as child_idx (child_idx)}
102
- {@const kind = buf._kinds[child_idx]}
201
+ {@const kind = buf.kind_at(child_idx)}
103
202
  {#if kind === K_TEXT}
104
203
  {buf_text(buf, child_idx, source)}
105
204
  {:else if kind === K_LINE_BREAK}
106
205
  <!-- skip -->
107
206
  {:else}
108
- <Node {buf} idx={child_idx} {source} {components} />
207
+ <Node
208
+ {buf}
209
+ idx={child_idx}
210
+ {source}
211
+ {components}
212
+ {directives}
213
+ {plugin_data}
214
+ />
109
215
  {/if}
110
216
  {/each}
111
217
  {/snippet}
112
218
 
219
+ {#snippet directive_label()}
220
+ {@render child_nodes(label_of(idx))}
221
+ {/snippet}
222
+
223
+ {#snippet directive_body()}
224
+ {@render child_nodes(idx)}
225
+ {/snippet}
226
+
113
227
  {#snippet table_body(table_idx: number)}
114
228
  {@const meta = buf.metadata_at(table_idx)}
115
229
  {@const alignments = (meta?.alignments as string[]) ?? []}
230
+ {@const header_columns = meta?.header_columns as number[] | undefined}
231
+ {@const spans = meta?.spans === true}
232
+ {@const col_count = (meta?.col_count as number | undefined) ?? alignments.length}
233
+ {@const row_l = header_columns ? header_columns[0] : 0}
234
+ {@const row_r = header_columns ? col_count - header_columns[1] : col_count}
116
235
  {@const rows = buf_children(buf, table_idx)}
117
236
  <table>
118
237
  {#each rows as row_idx (row_idx)}
119
- {#if buf._kinds[row_idx] === K_TABLE_HEADER}
238
+ {#if buf.kind_at(row_idx) === K_TABLE_HEADER}
120
239
  <thead>
121
240
  <tr>
122
- {#each buf_children(buf, row_idx).filter((c) => buf._kinds[c] === K_TABLE_CELL) as cell_idx, col (cell_idx)}
123
- {@const align = alignments[col]}
124
- <th align={align && align !== 'none' ? align : undefined}>
241
+ {#each buf_children(buf, row_idx).filter((c) => buf.kind_at(c) === K_TABLE_CELL) as cell_idx (cell_idx)}
242
+ {@const align = alignments[buf.extra_at(cell_idx)]}
243
+ {@const cell_meta = spans ? buf.metadata_at(cell_idx) : undefined}
244
+ <th
245
+ align={align && align !== 'none' ? align : undefined}
246
+ colspan={cell_meta?.colspan as number | undefined}
247
+ rowspan={cell_meta?.rowspan as number | undefined}
248
+ >
125
249
  {@render child_nodes(cell_idx)}
126
250
  </th>
127
251
  {/each}
@@ -131,13 +255,30 @@ let skip_list_item_paragraph_wrapper = $derived(
131
255
  {/each}
132
256
  <tbody>
133
257
  {#each rows as row_idx (row_idx)}
134
- {#if buf._kinds[row_idx] === K_TABLE_ROW}
258
+ {#if buf.kind_at(row_idx) === K_TABLE_ROW}
135
259
  <tr>
136
- {#each buf_children(buf, row_idx).filter((c) => buf._kinds[c] === K_TABLE_CELL) as cell_idx, col (cell_idx)}
260
+ {#each buf_children(buf, row_idx).filter((c) => buf.kind_at(c) === K_TABLE_CELL) as cell_idx (cell_idx)}
261
+ {@const col = buf.extra_at(cell_idx)}
137
262
  {@const align = alignments[col]}
138
- <td align={align && align !== 'none' ? align : undefined}>
139
- {@render child_nodes(cell_idx)}
140
- </td>
263
+ {@const cell_meta = spans ? buf.metadata_at(cell_idx) : undefined}
264
+ {#if col < row_l || col >= row_r}
265
+ <th
266
+ scope="row"
267
+ align={align && align !== 'none' ? align : undefined}
268
+ colspan={cell_meta?.colspan as number | undefined}
269
+ rowspan={cell_meta?.rowspan as number | undefined}
270
+ >
271
+ {@render child_nodes(cell_idx)}
272
+ </th>
273
+ {:else}
274
+ <td
275
+ align={align && align !== 'none' ? align : undefined}
276
+ colspan={cell_meta?.colspan as number | undefined}
277
+ rowspan={cell_meta?.rowspan as number | undefined}
278
+ >
279
+ {@render child_nodes(cell_idx)}
280
+ </td>
281
+ {/if}
141
282
  {/each}
142
283
  </tr>
143
284
  {/if}
@@ -146,7 +287,14 @@ let skip_list_item_paragraph_wrapper = $derived(
146
287
  </table>
147
288
  {/snippet}
148
289
 
149
- {#if kind === K_ROOT}
290
+ {#if directive}
291
+ {@const Directive = directive}
292
+ <Directive
293
+ {...meta?.args}
294
+ label={label_of(idx) !== NONE ? directive_label : undefined}
295
+ children={has_body(idx) ? directive_body : undefined}
296
+ />
297
+ {:else if kind === K_ROOT}
150
298
  {@render child_nodes(idx)}
151
299
  {:else if kind === K_HEADING}
152
300
  <svelte:element this={'h' + extra} {...get_attrs(meta)}>
@@ -156,14 +304,16 @@ let skip_list_item_paragraph_wrapper = $derived(
156
304
  {#if skip_list_item_paragraph_wrapper}
157
305
  {@render child_nodes(idx)}
158
306
  {:else}
159
- <p {...get_attrs(meta)}>{@render child_nodes(idx)}</p>
307
+ <p {...get_attrs(meta)}>{@render task_box()}{@render child_nodes(idx)}</p>
160
308
  {/if}
161
309
  {:else if kind === K_EMPHASIS}
162
310
  <em {...get_attrs(meta)}>{@render child_nodes(idx)}</em>
163
311
  {:else if kind === K_STRONG}
164
312
  <strong {...get_attrs(meta)}>{@render child_nodes(idx)}</strong>
165
313
  {:else if kind === K_CODE_SPAN}
166
- <code {...get_attrs(meta)}>{buf_text(buf, idx, source).replace(/\n/g, ' ')}</code>
314
+ <code {...get_attrs(meta)}
315
+ >{buf_code(buf, idx, source).replace(/\n/g, ' ')}</code
316
+ >
167
317
  {:else if kind === K_CODE_FENCE}
168
318
  {@const info =
169
319
  (meta?.info as string | undefined) ??
@@ -171,12 +321,16 @@ let skip_list_item_paragraph_wrapper = $derived(
171
321
  ? source.slice(meta.info_start as number, meta.info_end as number)
172
322
  : undefined)}
173
323
  <pre><code class={info ? 'language-' + info : undefined} {...get_attrs(meta)}
174
- >{buf_text(buf, idx, source)}</code
324
+ >{buf_code(buf, idx, source)}</code
175
325
  ></pre>
176
326
  {:else if kind === K_BLOCK_QUOTE}
177
327
  <blockquote {...get_attrs(meta)}>{@render child_nodes(idx)}</blockquote>
178
328
  {:else if kind === K_LINK}
179
- <a href={meta?.href as string} title={(meta?.title as string) || undefined} {...get_attrs(meta, LINK_SKIP)}>
329
+ <a
330
+ href={meta?.href as string}
331
+ title={(meta?.title as string) || undefined}
332
+ {...get_attrs(meta, LINK_SKIP)}
333
+ >
180
334
  {@render child_nodes(idx)}
181
335
  </a>
182
336
  {:else if kind === K_IMAGE}
@@ -189,14 +343,17 @@ let skip_list_item_paragraph_wrapper = $derived(
189
343
  {:else if kind === K_LIST}
190
344
  {#if meta?.ordered}
191
345
  {@const start = meta?.start as number | undefined}
192
- <ol start={start != null && start !== 1 ? start : undefined} {...get_attrs(meta)}>
346
+ <ol
347
+ start={start != null && start !== 1 ? start : undefined}
348
+ {...get_attrs(meta)}
349
+ >
193
350
  {@render child_nodes(idx)}
194
351
  </ol>
195
352
  {:else}
196
353
  <ul {...get_attrs(meta)}>{@render child_nodes(idx)}</ul>
197
354
  {/if}
198
355
  {:else if kind === K_LIST_ITEM}
199
- <li {...get_attrs(meta)}>{@render child_nodes(idx)}</li>
356
+ <li {...get_attrs(meta)}>{@render task_box()}{@render child_nodes(idx)}</li>
200
357
  {:else if kind === K_THEMATIC_BREAK}
201
358
  <hr {...get_attrs(meta)} />
202
359
  {:else if kind === K_HARD_BREAK}
@@ -214,11 +371,18 @@ let skip_list_item_paragraph_wrapper = $derived(
214
371
  {@const attrs = meta?.attributes as Record | undefined}
215
372
  {@const spread = attrs
216
373
  ? Object.fromEntries(
217
- Object.entries(attrs).map(([k, v]) => [k, v === true ? true : typeof v === 'object' && v?.type === 'expression' ? v.value : v])
374
+ Object.entries(attrs).map(([k, v]) => [
375
+ k,
376
+ v === true
377
+ ? true
378
+ : typeof v === 'object' && v?.type === 'expression'
379
+ ? v.value
380
+ : v,
381
+ ])
218
382
  )
219
383
  : {}}
220
384
  {@const CustomComponent = components?.[tag]}
221
- {@const is_raw_text = tag === 'script' || tag === 'style'}
385
+ {@const is_raw_text = is_raw_text_tag(tag)}
222
386
  {#if CustomComponent}
223
387
  <CustomComponent {...spread}>
224
388
  {#if !meta?.self_closing}
@@ -240,6 +404,18 @@ let skip_list_item_paragraph_wrapper = $derived(
240
404
  <!-- {buf_text(buf, idx, source)} -->
241
405
  {:else if kind === K_TABLE}
242
406
  {@render table_body(idx)}
407
+ {:else if kind === K_DIRECTIVE_LABEL}
408
+ <!-- a directive renders as its children, its label is not one of them -->
409
+ {:else if kind === K_FOOTNOTE_REFERENCE}
410
+ <!-- a stream has no number for it yet, so the label stands in -->
411
+ <sup class="footnote-reference">{meta?.label}</sup>
412
+ {:else if kind === K_FOOTNOTE_DEFINITION}
413
+ <div class="footnote">
414
+ <sup class="footnote-reference">{meta?.label}</sup>
415
+ {@render child_nodes(idx)}
416
+ </div>
417
+ {:else if kind === K_DEFINITION}
418
+ <!-- a link reference definition renders nothing, the links that use it carry its url -->
243
419
  {:else}
244
420
  {@render child_nodes(idx)}
245
421
  {/if}
package/src/component.ts CHANGED
@@ -17,11 +17,22 @@
17
17
  * with fresh content.
18
18
  */
19
19
 
20
- import type { NodeBuffer } from "@mdsvex/parse/utils";
20
+ import type { NodeBuffer } from '@mdsvex/parse/utils';
21
21
 
22
22
  const NONE = 0xffffffff;
23
23
  const K_LINE_BREAK = 6;
24
24
 
25
+ /** the child of the root that holds a node, NONE for a node out of the tree */
26
+ export function top_block(buf: NodeBuffer, node: number): number {
27
+ if (node === 0) return NONE;
28
+ for (;;) {
29
+ const parent = buf.parent_at(node);
30
+ if (parent === 0) return node;
31
+ if (parent === NONE) return NONE;
32
+ node = parent;
33
+ }
34
+ }
35
+
25
36
  // block entry
26
37
 
27
38
  export interface ComponentBlock {
@@ -38,7 +49,7 @@ export class ComponentRenderer {
38
49
  /** The current buffer reference (for passing to Node.svelte). */
39
50
  buf: NodeBuffer | null = null;
40
51
  /** The current source/text string (for passing to Node.svelte). */
41
- source = "";
52
+ source = '';
42
53
  private closed: Set<number> = new Set();
43
54
 
44
55
  update(buf: NodeBuffer, source: string): ComponentBlock[] {
@@ -49,14 +60,14 @@ export class ComponentRenderer {
49
60
  let changed = false;
50
61
 
51
62
  // walk root's children via sibling chain
52
- let child = buf._children_starts[0]; // root is index 0
63
+ let child = buf.first_child_at(0);
53
64
  while (child !== NONE) {
54
- const kind = buf._kinds[child];
55
- const next = buf._next_siblings[child];
56
- const is_sibling = next !== NONE && buf._parents[next] === 0;
65
+ const kind = buf.kind_at(child);
66
+ const next = buf.next_at(child);
67
+ const is_sibling = next !== NONE && buf.parent_at(next) === 0;
57
68
 
58
69
  if (kind !== K_LINE_BREAK) {
59
- const closed = buf._ends[child] !== NONE;
70
+ const closed = buf.end_at(child) !== NONE;
60
71
 
61
72
  if (block_idx >= this.blocks.length) {
62
73
  this.blocks.push({ idx: child, v: 0 });
@@ -79,10 +90,22 @@ export class ComponentRenderer {
79
90
  return changed ? (this.blocks = [...this.blocks]) : this.blocks;
80
91
  }
81
92
 
93
+ /**
94
+ * the nodes changed after their block closed, as the node of a deferred
95
+ * task that applied does, apply_ready gives them, each block that holds
96
+ * one renders again at the next update
97
+ */
98
+ invalidate(buf: NodeBuffer, nodes: readonly number[]): void {
99
+ for (let i = 0; i < nodes.length; i++) {
100
+ const block = top_block(buf, nodes[i]);
101
+ if (block !== NONE) this.closed.delete(block);
102
+ }
103
+ }
104
+
82
105
  reset(): void {
83
106
  this.blocks = [];
84
107
  this.buf = null;
85
- this.source = "";
108
+ this.source = '';
86
109
  this.closed.clear();
87
110
  }
88
111
  }