@mdsvex/parse 1.0.0-next.2 → 1.0.0-next.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.
@@ -5,6 +5,13 @@ import { NodeView, type StructureHost, type TextSource } from './node_view.js';
5
5
  import type { ParsePlugin, PluginData, PluginDocument, PluginWarning, DirectiveTable, TaskContext as PublicTaskContext } from './plugin_types.js';
6
6
  import { HeadingIds } from './heading_ids.js';
7
7
  import { Task, type TaskHost } from './plugin_tasks.js';
8
+ /** two tables have an entry for one directive name, which has one owner */
9
+ export declare class DirectiveOwnerError extends Error {
10
+ directive: string;
11
+ /** the names of the two plugins, the earlier first, undefined for a table without one */
12
+ plugins: [string | undefined, string | undefined];
13
+ constructor(directive: string, plugins: [string | undefined, string | undefined]);
14
+ }
8
15
  /** true when a table binds a handler, without one a parse needs no dispatcher for them */
9
16
  export declare function has_directive_handlers(tables: DirectiveTable[] | undefined): boolean;
10
17
  /**
@@ -97,6 +104,8 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
97
104
  private close_with;
98
105
  /** the node whose handler or close callback is running */
99
106
  private running;
107
+ /** the observer whose handler or close callback is running, it changes no node */
108
+ private observing;
100
109
  /** the callbacks of a close that is final are running, their node is settled */
101
110
  private final_close;
102
111
  /** close callbacks are running, not open handlers */
@@ -369,6 +378,13 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
369
378
  * the parse handler of the name runs for any directive
370
379
  */
371
380
  dispatch_name(buf_idx: number, name: unknown, buf: NodeBuffer): void;
381
+ /**
382
+ * observers run after the owner at the open and after every other callback
383
+ * at the close, each with a scope of its own below that of the owner
384
+ */
385
+ private observe;
386
+ /** a close callback of an observer, which changes no node either */
387
+ private observed;
372
388
  /** a scope opened or ended, the kinds an open needs the dispatcher for follow */
373
389
  private scopes_changed;
374
390
  private drop_narrow;
@@ -398,6 +414,8 @@ export declare class PluginDispatcher implements StructureHost, RedirectHost, Da
398
414
  * they opened under the paragraph, so the children handlers of the directive have not seen them
399
415
  */
400
416
  lifted(buf_idx: number, buf: NodeBuffer): number[] | null;
417
+ /** a children handler on the innermost directive, of the owner or of an observer */
418
+ private takes_lifted;
401
419
  /** the children handlers of the innermost scope for each node the repair made its child */
402
420
  dispatch_lifted(nodes: number[], buf: NodeBuffer): void;
403
421
  /**
@@ -84,6 +84,8 @@ export interface TaskHost {
84
84
  /** the view of a node for a task to read */
85
85
  real(task: Task, index: number): NodeView;
86
86
  }
87
+ /** the message of a write to a node by an observer, which changes no node */
88
+ export declare function observer_write(what: string, observing: string): string;
87
89
  /** async work deferred on a node, its changes wait until it settled and the node is committed */
88
90
  export declare class Task {
89
91
  /** the node it was deferred on, the owner of what it writes */
@@ -100,6 +102,8 @@ export declare class Task {
100
102
  /** the node went, or the document did, the task is forgotten */
101
103
  dropped: boolean;
102
104
  applied: boolean;
105
+ /** for the task of an observer, who observes what, a write to a node then throws */
106
+ observing: string | null;
103
107
  ops: Op[];
104
108
  /** resolves once the task settled, never rejects */
105
109
  done: Promise<void>;
@@ -172,9 +172,15 @@ export interface ParsePlugin {
172
172
  * the text of an element that holds code, such as code or kbd
173
173
  */
174
174
  all_text?: boolean;
175
+ /**
176
+ * directives the plugin observes by name, whoever owns them, entries as
177
+ * those of a table of bound handlers, they run in the fused pass after the
178
+ * handlers of the owner and change no node, a write to one is a TypeError
179
+ */
180
+ observe?: DirectiveHandlers;
175
181
  [nodeType: string]: {
176
182
  parse: NodeHandler['parse'];
177
- } | TextHandler | ((root: NodeView, ctx: PluginContext) => void | Promise<void>) | boolean | string | undefined;
183
+ } | TextHandler | ((root: NodeView, ctx: PluginContext) => void | Promise<void>) | DirectiveHandlers | boolean | string | undefined;
178
184
  }
179
185
  /** what a handler bound to a directive gets in place of the plugin context */
180
186
  export interface DirectiveContext extends DocumentContext {
package/dist/utils.d.ts CHANGED
@@ -102,6 +102,69 @@ export declare function take_math(): boolean;
102
102
  * between documents as the note of take_src is
103
103
  */
104
104
  export declare function take_info(source: string, text: string, other?: string): boolean;
105
+ /**
106
+ * @internal the attributes of an open tag as the scan found them, five words
107
+ * per attribute in rec from at, kind then name and value ranges
108
+ */
109
+ export declare class AttrSpans {
110
+ readonly source: string;
111
+ readonly base: number;
112
+ readonly rec: Int32Array;
113
+ readonly at: number;
114
+ readonly n: number;
115
+ /** where the tag name starts, one past the < */
116
+ readonly name_start: number;
117
+ /** past the last attribute, before the space ahead of > or /> */
118
+ readonly attrs_end: number;
119
+ /** past the > */
120
+ readonly open_end: number;
121
+ /** past the tag name, where the attributes start */
122
+ readonly attrs_start: number;
123
+ /** the source from attrs_start to attrs_end is what fold writes for the record */
124
+ readonly canonical: boolean;
125
+ constructor(source: string, base: number, rec: Int32Array, at: number, n: number,
126
+ /** where the tag name starts, one past the < */
127
+ name_start: number,
128
+ /** past the last attribute, before the space ahead of > or /> */
129
+ attrs_end: number,
130
+ /** past the > */
131
+ open_end: number,
132
+ /** past the tag name, where the attributes start */
133
+ attrs_start: number,
134
+ /** the source from attrs_start to attrs_end is what fold writes for the record */
135
+ canonical: boolean);
136
+ /** the canonical attribute text, sliced once */
137
+ text: string | undefined;
138
+ }
139
+ /** @internal the attributes of a canonical tag as written */
140
+ export declare function spans_text(s: AttrSpans): string;
141
+ /** @internal copies n words of a scan record into the shared store, attr_at says where */
142
+ export declare function store_attr_rec(rec: Int32Array, n: number): Int32Array;
143
+ /** @internal where the last store_attr_rec put its words */
144
+ export declare function stored_attr_at(): number;
145
+ /** the record the eager path builds, for a tag with no repeated names and no framed values */
146
+ export declare function build_attrs(s: AttrSpans): Record<string, unknown>;
147
+ /** @internal whether a lazy tag writes an attribute named name, without building the record */
148
+ export declare function spans_have(s: AttrSpans, name: string): boolean;
149
+ declare const ATTRS: unique symbol;
150
+ /**
151
+ * the metadata of a tagged node, attributes is built from its spans on first
152
+ * read, a symbol key keeps the store out of keys, for in and json
153
+ */
154
+ export declare class HtmlMeta {
155
+ tag: unknown;
156
+ [ATTRS]: AttrSpans | Record<string, unknown> | undefined;
157
+ constructor(tag: unknown);
158
+ get attributes(): Record<string, unknown> | undefined;
159
+ set attributes(value: AttrSpans | Record<string, unknown> | undefined);
160
+ }
161
+ /** metadata as own string keys, a spread leaves out the getter and keeps the symbol */
162
+ export declare function plain_meta(meta: any): any;
163
+ /**
164
+ * @internal the spans of a typed tag whose attributes nobody has read, they
165
+ * spell the source as written, undefined otherwise
166
+ */
167
+ export declare function unread_spans(meta: unknown): AttrSpans | undefined;
105
168
  /**
106
169
  * a computed key literal takes a slow generic define, so known keys get
107
170
  * constant key literals and other keys a store into an empty literal
@@ -344,3 +407,4 @@ export declare class ErrorCollector {
344
407
  /** double the backing storage when capacity is exhausted. */
345
408
  private grow;
346
409
  }
410
+ export {};