satteri 0.1.0 → 0.1.1

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.
Files changed (52) hide show
  1. package/dist/command-buffer.js +1 -13
  2. package/dist/compile.d.ts +1 -1
  3. package/dist/compile.js +1 -8
  4. package/dist/hast/hast-materializer.js +0 -1
  5. package/dist/hast/hast-reader.d.ts +1 -1
  6. package/dist/hast/hast-reader.js +1 -2
  7. package/dist/hast/hast-visitor.d.ts +3 -3
  8. package/dist/hast/hast-visitor.js +7 -12
  9. package/dist/hast-types.d.ts +1 -3
  10. package/dist/hast-types.js +0 -1
  11. package/dist/index.js +1 -2
  12. package/dist/lazy-props.js +0 -1
  13. package/dist/mdast/mdast-materializer.js +0 -1
  14. package/dist/mdast/mdast-reader.js +0 -4
  15. package/dist/mdast/mdast-visitor.d.ts +9 -4
  16. package/dist/mdast/mdast-visitor.js +11 -6
  17. package/dist/mdast-types.d.ts +1 -3
  18. package/dist/mdast-types.js +0 -1
  19. package/dist/mdx-types.d.ts +140 -0
  20. package/dist/mdx-types.js +7 -0
  21. package/dist/plugin.js +0 -1
  22. package/dist/types.d.ts +4 -6
  23. package/dist/types.js +0 -1
  24. package/index.d.ts +21 -4
  25. package/index.js +54 -53
  26. package/package.json +3 -6
  27. package/satteri_napi.linux-x64-gnu.node +0 -0
  28. package/satteri_napi.wasi-browser.js +2 -0
  29. package/satteri_napi.wasi.cjs +1 -0
  30. package/dist/command-buffer.js.map +0 -1
  31. package/dist/compile.js.map +0 -1
  32. package/dist/data-map.d.ts +0 -10
  33. package/dist/data-map.js +0 -26
  34. package/dist/data-map.js.map +0 -1
  35. package/dist/hast/hast-materializer.js.map +0 -1
  36. package/dist/hast/hast-reader.js.map +0 -1
  37. package/dist/hast/hast-visitor.js.map +0 -1
  38. package/dist/hast-types.js.map +0 -1
  39. package/dist/index.js.map +0 -1
  40. package/dist/lazy-props.js.map +0 -1
  41. package/dist/mdast/mdast-materializer.js.map +0 -1
  42. package/dist/mdast/mdast-reader.js.map +0 -1
  43. package/dist/mdast/mdast-visitor.js.map +0 -1
  44. package/dist/mdast-types.js.map +0 -1
  45. package/dist/pipeline.d.ts +0 -29
  46. package/dist/pipeline.js +0 -87
  47. package/dist/pipeline.js.map +0 -1
  48. package/dist/plugin.js.map +0 -1
  49. package/dist/processor.d.ts +0 -33
  50. package/dist/processor.js +0 -49
  51. package/dist/processor.js.map +0 -1
  52. package/dist/types.js.map +0 -1
@@ -8,9 +8,7 @@
8
8
  * All multi-byte integers are little-endian to match native x86/ARM layout and
9
9
  * avoid byte-swapping on the Rust side.
10
10
  */
11
- // ---------------------------------------------------------------------------
12
11
  // Command bytes (0x01–0x0F)
13
- // ---------------------------------------------------------------------------
14
12
  const CMD_REMOVE = 0x01;
15
13
  const CMD_INSERT_BEFORE = 0x05;
16
14
  const CMD_INSERT_AFTER = 0x06;
@@ -19,15 +17,11 @@ const CMD_APPEND_CHILD = 0x08;
19
17
  const CMD_WRAP = 0x09;
20
18
  const CMD_REPLACE = 0x0b;
21
19
  const CMD_SET_PROPERTY = 0x0c;
22
- // ---------------------------------------------------------------------------
23
20
  // Payload types (0x10+, distinct range from commands)
24
- // ---------------------------------------------------------------------------
25
21
  const PAYLOAD_RAW_MARKDOWN = 0x10;
26
22
  const PAYLOAD_RAW_HTML = 0x11;
27
23
  const PAYLOAD_SERDE_JSON = 0x12;
28
- // ---------------------------------------------------------------------------
29
24
  // Value types for CMD_SET_PROPERTY (must match commands.rs PROP_* constants)
30
- // ---------------------------------------------------------------------------
31
25
  const PROP_STRING = 0;
32
26
  const PROP_BOOL_TRUE = 1;
33
27
  const PROP_BOOL_FALSE = 2;
@@ -46,9 +40,7 @@ export function classifyReturn(value) {
46
40
  return "structured_node";
47
41
  throw new Error("Invalid return value from visitor: must have raw, rawHtml, or type");
48
42
  }
49
- // ---------------------------------------------------------------------------
50
43
  // CommandBuffer
51
- // ---------------------------------------------------------------------------
52
44
  const INITIAL_SIZE = 4096;
53
45
  const encoder = new TextEncoder();
54
46
  const EMPTY_U8 = new Uint8Array(0);
@@ -62,7 +54,6 @@ export class CommandBuffer {
62
54
  this.view = new DataView(this.buffer);
63
55
  this.bytes = new Uint8Array(this.buffer);
64
56
  }
65
- // -- Public command methods -----------------------------------------------
66
57
  removeNode(nodeId) {
67
58
  this.ensureCapacity(5);
68
59
  this.writeU8(CMD_REMOVE);
@@ -154,7 +145,6 @@ export class CommandBuffer {
154
145
  this.writeU32(encoded.length);
155
146
  this.writeBytes(encoded);
156
147
  }
157
- // -- Result accessors -----------------------------------------------------
158
148
  /** Return a Uint8Array view of the written bytes (no copy). */
159
149
  getBuffer() {
160
150
  return new Uint8Array(this.buffer, 0, this.offset);
@@ -170,7 +160,6 @@ export class CommandBuffer {
170
160
  this.bytes = new Uint8Array(this.buffer);
171
161
  this.offset = 0;
172
162
  }
173
- // -- Private helpers ------------------------------------------------------
174
163
  writeStructuralCommand(cmd, nodeId, node) {
175
164
  const v = node;
176
165
  if (typeof v.raw === "string") {
@@ -192,7 +181,7 @@ export class CommandBuffer {
192
181
  this.writeBytes(encoded);
193
182
  }
194
183
  else {
195
- // Structured node serialize as JSON
184
+ // Structured node, serialize as JSON
196
185
  const json = JSON.stringify(node);
197
186
  const encoded = encoder.encode(json);
198
187
  this.ensureCapacity(10 + encoded.length);
@@ -228,4 +217,3 @@ export class CommandBuffer {
228
217
  this.offset += data.length;
229
218
  }
230
219
  }
231
- //# sourceMappingURL=command-buffer.js.map
package/dist/compile.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Top-level compile functions the primary public API.
2
+ * Top-level compile functions, the primary public API.
3
3
  *
4
4
  * Both MDAST and HAST arenas stay in Rust memory via opaque handles.
5
5
  * Only matched nodes and mutation commands cross the NAPI boundary.
package/dist/compile.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Top-level compile functions the primary public API.
2
+ * Top-level compile functions, the primary public API.
3
3
  *
4
4
  * Both MDAST and HAST arenas stay in Rust memory via opaque handles.
5
5
  * Only matched nodes and mutation commands cross the NAPI boundary.
@@ -7,9 +7,7 @@
7
7
  import { visitHastHandle, resolveSubscriptions } from "./hast/hast-visitor.js";
8
8
  import { visitMdastHandle, resolveMdastSubscriptions, } from "./mdast/mdast-visitor.js";
9
9
  import { parseToHtml, compileMdx, createHastHandle, createMdxHastHandle, renderHandle, compileHandle, applyCommandsToHandle, dropHandle, createMdastHandle, createMdxMdastHandle, applyCommandsToMdastHandle, convertMdastToHastHandle, applyCommandsAndConvertToHastHandle, getHandleSource, } from "../index.js";
10
- // ---------------------------------------------------------------------------
11
10
  // Helpers
12
- // ---------------------------------------------------------------------------
13
11
  function initPlugins(plugins) {
14
12
  return plugins.map((def) => ({
15
13
  instance: def.createOnce(),
@@ -49,9 +47,7 @@ function runMdastPluginsOnHandle(handle, plugins, filename) {
49
47
  }
50
48
  return runNext();
51
49
  }
52
- // ---------------------------------------------------------------------------
53
50
  // HAST plugin runner (handle-based)
54
- // ---------------------------------------------------------------------------
55
51
  function runHastPluginsOnHandle(handle, plugins, source, filename) {
56
52
  if (plugins.length === 0)
57
53
  return;
@@ -119,10 +115,8 @@ export function compileMdxToJs(source, options = {}) {
119
115
  }
120
116
  return finish(handleResult);
121
117
  }
122
- // ---------------------------------------------------------------------------
123
118
  // Pipeline: parse → mdast plugins → hast conversion → hast plugins
124
119
  // All arenas stay in Rust. No intermediate buffer copies to JS.
125
- // ---------------------------------------------------------------------------
126
120
  /** Parse + mdast plugins + convert to HAST handle. */
127
121
  function createHastHandleFromMdast(source, mdastPlugins, mdx, filename) {
128
122
  if (mdastPlugins.length === 0) {
@@ -141,4 +135,3 @@ function createHastHandleFromMdast(source, mdastPlugins, mdx, filename) {
141
135
  }
142
136
  return convert(mdastResult);
143
137
  }
144
- //# sourceMappingURL=compile.js.map
@@ -147,4 +147,3 @@ export function materializeHastNode(reader, nodeId) {
147
147
  export function materializeHastTree(reader) {
148
148
  return materializeHastNode(reader, 0);
149
149
  }
150
- //# sourceMappingURL=hast-materializer.js.map
@@ -1,5 +1,5 @@
1
1
  import type { BufferHeader } from "../types.js";
2
- import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from "mdast-util-mdx-jsx";
2
+ import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from "../mdx-types.js";
3
3
  export type { MdxJsxAttribute, MdxJsxExpressionAttribute };
4
4
  export declare const HAST_ROOT = 0;
5
5
  export declare const HAST_ELEMENT = 1;
@@ -21,7 +21,7 @@ const MDX_ATTR_BOOLEAN_PROP = 0;
21
21
  const MDX_ATTR_LITERAL_PROP = 1;
22
22
  const MDX_ATTR_EXPRESSION_PROP = 2;
23
23
  const MDX_ATTR_SPREAD = 3;
24
- // HastNode field offsets (same layout as MDAST shared binary format)
24
+ // HastNode field offsets (same layout as MDAST, shared binary format)
25
25
  // id: u32 @ 0
26
26
  // node_type: u8 @ 4
27
27
  // _pad: [u8; 3] @ 5
@@ -277,4 +277,3 @@ export class HastReader {
277
277
  return this.getString(ref.offset, ref.len);
278
278
  }
279
279
  }
280
- //# sourceMappingURL=hast-reader.js.map
@@ -1,9 +1,9 @@
1
1
  import { type HastNode } from "./hast-materializer.js";
2
2
  import type { HastRaw } from "../types.js";
3
3
  import type { Element, Text, Comment, Doctype } from "hast";
4
- import type { MdxJsxFlowElementHast, MdxJsxTextElementHast } from "mdast-util-mdx-jsx";
5
- import type { MdxFlowExpressionHast, MdxTextExpressionHast } from "mdast-util-mdx-expression";
6
- import type { MdxjsEsmHast } from "mdast-util-mdxjs-esm";
4
+ import type { MdxJsxFlowElementHast, MdxJsxTextElementHast } from "../mdx-types.js";
5
+ import type { MdxFlowExpressionHast, MdxTextExpressionHast } from "../mdx-types.js";
6
+ import type { MdxjsEsmHast } from "../mdx-types.js";
7
7
  export type HastHandle = any;
8
8
  /** ESTree-compatible Program node returned by `parseExpression()`. */
9
9
  export type EstreeProgram = Record<string, any>;
@@ -82,12 +82,12 @@ class HastVisitorContextImpl {
82
82
  setProperty(node, key, value) {
83
83
  const id = nid(node);
84
84
  if (node.type === "element") {
85
- // Fast binary path no materialization, no JSON serialization
85
+ // Fast binary path, no materialization, no JSON serialization
86
86
  this.#commandBuffer.setProperty(id, key, value);
87
87
  return;
88
88
  }
89
89
  if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") {
90
- // MDX JSX nodes use `attributes`, not `properties` keep replaceNode path
90
+ // MDX JSX nodes use `attributes`, not `properties`, keep replaceNode path
91
91
  const current = this.#pendingNodes.get(id) ?? node;
92
92
  const updated = { ...current };
93
93
  const attrs = [...(updated.attributes ?? [])];
@@ -104,7 +104,7 @@ class HastVisitorContextImpl {
104
104
  this.replaceNode(node, updated);
105
105
  return;
106
106
  }
107
- // Text-like nodes (text, comment, raw, expressions, esm) fast binary path.
107
+ // Text-like nodes (text, comment, raw, expressions, esm), fast binary path.
108
108
  // Rust handles "value" setProperty directly on these types.
109
109
  this.#commandBuffer.setProperty(id, key, value);
110
110
  }
@@ -144,7 +144,7 @@ export function resolveSubscriptions(plugin) {
144
144
  }
145
145
  }
146
146
  else {
147
- // Bare function empty filter matches all nodes of this type
147
+ // Bare function, empty filter matches all nodes of this type
148
148
  subs.push({ nodeType, tagFilter: [], visitFn: value });
149
149
  }
150
150
  }
@@ -201,7 +201,7 @@ function decodeProperties(view, buf, pos) {
201
201
  }
202
202
  /**
203
203
  * Walk-path element node: uses prototype getters instead of per-instance
204
- * Object.defineProperty. V8 optimises shared hidden classes far better
204
+ * Object.defineProperty. V8 optimises shared hidden classes far better,
205
205
  * this is ~16x faster for construction than the defineProperty approach.
206
206
  *
207
207
  * The buffer reference data is stored on private instance fields so the
@@ -279,7 +279,7 @@ function readElementFromBinary(view, buf, offset, nodeId, resolver) {
279
279
  const ids = [];
280
280
  for (let i = 0; i < childCount; i++)
281
281
  ids.push(view.getUint32(childIdsPos + i * 4, true));
282
- // Build node using class (prototype getters no per-instance defineProperty)
282
+ // Build node using class (prototype getters, no per-instance defineProperty)
283
283
  const node = new WalkElement();
284
284
  node.tagName = tagName;
285
285
  node._view = view;
@@ -385,11 +385,9 @@ function readMatchedNode(view, buf, offset, nodeId, nodeType, resolver) {
385
385
  nodeIdMap.set(node, nodeId);
386
386
  return node;
387
387
  }
388
- // ---------------------------------------------------------------------------
389
388
  // Shared helpers
390
- // ---------------------------------------------------------------------------
391
389
  /**
392
- * Lazy child materializer serializes the handle's buffer once when first
390
+ * Lazy child materializer, serializes the handle's buffer once when first
393
391
  * child is accessed, then materializes children from it via HastReader.
394
392
  */
395
393
  class LazyChildResolver {
@@ -501,9 +499,7 @@ function mergeAndReset(returnBuffer, ctx) {
501
499
  ctxCmdBuf.reset();
502
500
  return { merged, hasMutations: totalLen > 0 };
503
501
  }
504
- // ---------------------------------------------------------------------------
505
502
  // Handle-based visitor
506
- // ---------------------------------------------------------------------------
507
503
  /**
508
504
  * Walk a handle's arena in Rust, dispatch matched nodes to JS visitor functions,
509
505
  * and apply mutations back to the handle. No arena buffers cross NAPI.
@@ -534,4 +530,3 @@ function applyMutations(handle, returnBuffer, ctx) {
534
530
  applyCommandsToHandle(handle, merged);
535
531
  }
536
532
  }
537
- //# sourceMappingURL=hast-visitor.js.map
@@ -1,5 +1,3 @@
1
1
  export type { Root, Element, Text, Comment, Doctype, Properties, Nodes, RootContent, ElementContent, Data, Literal, Parent, } from "hast";
2
- export type { MdxJsxFlowElementHast, MdxJsxTextElementHast, MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxAttributeValueExpression, } from "mdast-util-mdx-jsx";
3
- export type { MdxFlowExpressionHast, MdxTextExpressionHast } from "mdast-util-mdx-expression";
4
- export type { MdxjsEsmHast } from "mdast-util-mdxjs-esm";
2
+ export type { MdxJsxFlowElementHast, MdxJsxTextElementHast, MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxAttributeValueExpression, MdxFlowExpressionHast, MdxTextExpressionHast, MdxjsEsmHast, } from "./mdx-types.js";
5
3
  export type { HastRaw } from "./types.js";
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=hast-types.js.map
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
- // Public API compile functions
1
+ // Public API: compile functions
2
2
  export { compileMarkdownToHtml, compileMdxToJs } from "./compile.js";
3
3
  // Plugin definitions
4
4
  export { defineMdastPlugin, defineHastPlugin } from "./plugin.js";
5
- //# sourceMappingURL=index.js.map
@@ -48,4 +48,3 @@ export function lazyGroup(node, keys, resolve) {
48
48
  });
49
49
  }
50
50
  }
51
- //# sourceMappingURL=lazy-props.js.map
@@ -159,4 +159,3 @@ export function materializeNode(reader, nodeId) {
159
159
  export function materializeTree(reader) {
160
160
  return materializeNode(reader, 0);
161
161
  }
162
- //# sourceMappingURL=mdast-materializer.js.map
@@ -211,7 +211,6 @@ export class ArenaReader {
211
211
  const { typeDataOffset } = this.#header;
212
212
  return new Uint8Array(this.#view.buffer, this.#view.byteOffset + typeDataOffset + node.dataOffset, node.dataLen);
213
213
  }
214
- // ── Low-level helpers ──────────────────────────────────────────────────────
215
214
  /** Read a StringRef (offset: u32 LE, len: u32 LE) from type data. */
216
215
  readStringRef(typeData, byteOffset = 0) {
217
216
  const view = new DataView(typeData.buffer, typeData.byteOffset + byteOffset);
@@ -220,7 +219,6 @@ export class ArenaReader {
220
219
  len: view.getUint32(4, true),
221
220
  };
222
221
  }
223
- // ── Type-specific data accessors ───────────────────────────────────────────
224
222
  /** HeadingData: depth u8 @ 0. */
225
223
  getHeadingDepth(nodeId) {
226
224
  return this.getTypeData(nodeId)[0];
@@ -455,7 +453,6 @@ export class ArenaReader {
455
453
  const valueRef = this.readStringRef(data, 0);
456
454
  return this.getString(valueRef.offset, valueRef.len);
457
455
  }
458
- // ── Tree walking ──────────────────────────────────────────────────────────
459
456
  /**
460
457
  * Walk the tree depth-first. Return false from visitor to skip children.
461
458
  */
@@ -478,4 +475,3 @@ export class ArenaReader {
478
475
  this.walk((nodeId) => visitor(this.getNode(nodeId)), rootId);
479
476
  }
480
477
  }
481
- //# sourceMappingURL=mdast-reader.js.map
@@ -1,9 +1,9 @@
1
1
  import { CommandBuffer } from "../command-buffer.js";
2
2
  import type { MdastNode, Toml, MathNode, InlineMath } from "../types.js";
3
3
  import type { Blockquote, Break, Code, Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Html, Image, ImageReference, InlineCode, Link, LinkReference, List, ListItem, Paragraph, Root, Strong, Table, TableRow, TableCell, Text, ThematicBreak, Yaml } from "mdast";
4
- import type { MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx-jsx";
5
- import type { MdxFlowExpression, MdxTextExpression } from "mdast-util-mdx-expression";
6
- import type { MdxjsEsm } from "mdast-util-mdxjs-esm";
4
+ import type { MdxJsxFlowElement, MdxJsxTextElement } from "../mdx-types.js";
5
+ import type { MdxFlowExpression, MdxTextExpression } from "../mdx-types.js";
6
+ import type { MdxjsEsm } from "../mdx-types.js";
7
7
  export interface MdastDiagnostic {
8
8
  message: string;
9
9
  nodeId?: number | undefined;
@@ -14,7 +14,7 @@ export declare class MdastVisitorContext {
14
14
  #private;
15
15
  readonly source: string;
16
16
  readonly filename: string;
17
- constructor(source: string, filename: string);
17
+ constructor(handle: MdastHandle, source: string, filename: string);
18
18
  removeNode(node: MdastNode): void;
19
19
  insertBefore(node: MdastNode, newNode: MdastNode): void;
20
20
  insertAfter(node: MdastNode, newNode: MdastNode): void;
@@ -23,6 +23,11 @@ export declare class MdastVisitorContext {
23
23
  appendChild(node: MdastNode, childNode: MdastNode): void;
24
24
  replaceNode(node: MdastNode, newNode: MdastNode): void;
25
25
  setProperty(node: MdastNode, key: string, value: unknown): void;
26
+ /** Collect the concatenated text of all descendant text nodes (like mdast-util-to-string). */
27
+ textContent(node: MdastNode, options?: {
28
+ includeImageAlt?: boolean;
29
+ includeHtml?: boolean;
30
+ }): string;
26
31
  report({ message, node, severity, }: {
27
32
  message: string;
28
33
  node?: MdastNode;
@@ -1,7 +1,7 @@
1
1
  import { materializeNode, TYPE_NAMES } from "./mdast-materializer.js";
2
2
  import { ArenaReader } from "./mdast-reader.js";
3
3
  import { CommandBuffer, classifyReturn } from "../command-buffer.js";
4
- import { walkMdastHandle, serializeMdastHandle, getNodeData as napiGetNodeData, setNodeData, } from "../../index.js";
4
+ import { walkMdastHandle, serializeMdastHandle, getNodeData as napiGetNodeData, setNodeData, mdastTextContentHandle, } from "../../index.js";
5
5
  const MutationType = {
6
6
  Replace: "replace",
7
7
  Remove: "remove",
@@ -56,9 +56,11 @@ function nid(node) {
56
56
  export class MdastVisitorContext {
57
57
  #commandBuffer = new CommandBuffer();
58
58
  #diagnostics = [];
59
+ #handle;
59
60
  source;
60
61
  filename;
61
- constructor(source, filename) {
62
+ constructor(handle, source, filename) {
63
+ this.#handle = handle;
62
64
  this.source = source;
63
65
  this.filename = filename;
64
66
  }
@@ -86,6 +88,10 @@ export class MdastVisitorContext {
86
88
  setProperty(node, key, value) {
87
89
  this.#commandBuffer.setProperty(nid(node), key, value);
88
90
  }
91
+ /** Collect the concatenated text of all descendant text nodes (like mdast-util-to-string). */
92
+ textContent(node, options) {
93
+ return mdastTextContentHandle(this.#handle, nid(node), options);
94
+ }
89
95
  report({ message, node, severity = "error", }) {
90
96
  this.#diagnostics.push({
91
97
  message,
@@ -205,7 +211,7 @@ class MdastLazyChildResolver {
205
211
  const encoder = new TextEncoder();
206
212
  function readMdastMatchedNode(view, buf, dataOffset, nodeId, nodeType, dirtyData, resolver) {
207
213
  let pos = dataOffset;
208
- // Node data (JSON bytes) always first
214
+ // Node data (JSON bytes), always first
209
215
  const dataJsonLen = ru32(view, pos);
210
216
  pos += 4;
211
217
  let initialData = null;
@@ -225,7 +231,7 @@ function readMdastMatchedNode(view, buf, dataOffset, nodeId, nodeType, dirtyData
225
231
  end: { offset: ru32(view, pos + 4), line: ru32(view, pos + 16), column: ru32(view, pos + 20) },
226
232
  };
227
233
  pos += 24;
228
- // Children read IDs, materialize lazily via resolver
234
+ // Children, read IDs, materialize lazily via resolver
229
235
  const childCount = ru16(view, pos);
230
236
  pos += 2;
231
237
  const childIds = [];
@@ -497,7 +503,7 @@ function applyMdastVisitResult(result, nodeId, returnBuffer, originalNode) {
497
503
  * or Promise<MdastVisitResult> if any visitor is async.
498
504
  */
499
505
  export function visitMdastHandle(handle, plugin, subs, source, filename) {
500
- const context = new MdastVisitorContext(source, filename);
506
+ const context = new MdastVisitorContext(handle, source, filename);
501
507
  const returnBuffer = new CommandBuffer();
502
508
  const dirtyData = new Map();
503
509
  const resolver = new MdastLazyChildResolver(handle);
@@ -540,4 +546,3 @@ function finalizeMdastVisit(handle, context, returnBuffer, dirtyData) {
540
546
  const { merged, hasMutations } = mergeAndReset(returnBuffer, context);
541
547
  return { commandBuffer: merged, diagnostics: context.getDiagnostics(), hasMutations };
542
548
  }
543
- //# sourceMappingURL=mdast-visitor.js.map
@@ -1,5 +1,3 @@
1
1
  export type { Root, Nodes, RootContent, Blockquote, Break, Code, Definition, Delete, Emphasis, FootnoteDefinition, FootnoteReference, Heading, Html, Image, ImageReference, InlineCode, Link, LinkReference, List, ListItem, Paragraph, Strong, Table, TableRow, TableCell, Text, ThematicBreak, Yaml, Data, Literal, Parent, } from "mdast";
2
- export type { MdxJsxFlowElement, MdxJsxTextElement, MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxAttributeValueExpression, } from "mdast-util-mdx-jsx";
3
- export type { MdxFlowExpression, MdxTextExpression } from "mdast-util-mdx-expression";
4
- export type { MdxjsEsm } from "mdast-util-mdxjs-esm";
2
+ export type { MdxJsxFlowElement, MdxJsxTextElement, MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxAttributeValueExpression, MdxFlowExpression, MdxTextExpression, MdxjsEsm, } from "./mdx-types.js";
5
3
  export type { Toml, MathNode, InlineMath } from "./types.js";
@@ -1,2 +1 @@
1
1
  export {};
2
- //# sourceMappingURL=mdast-types.js.map
@@ -0,0 +1,140 @@
1
+ import type { Data as HastData, ElementContent, Literal as HastLiteral, Parent as HastParent } from "hast";
2
+ import type { BlockContent, Data as MdastData, DefinitionContent, Literal as MdastLiteral, Parent as MdastParent, PhrasingContent } from "mdast";
3
+ import type { Data, Node } from "unist";
4
+ export interface MdxJsxAttributeValueExpression extends Node {
5
+ type: "mdxJsxAttributeValueExpression";
6
+ value: string;
7
+ data?: MdxJsxAttributeValueExpressionData | undefined;
8
+ }
9
+ export interface MdxJsxAttributeValueExpressionData extends Data {
10
+ estree?: unknown;
11
+ }
12
+ export interface MdxJsxExpressionAttribute extends Node {
13
+ type: "mdxJsxExpressionAttribute";
14
+ value: string;
15
+ data?: MdxJsxExpressionAttributeData | undefined;
16
+ }
17
+ export interface MdxJsxExpressionAttributeData extends Data {
18
+ estree?: unknown;
19
+ }
20
+ export interface MdxJsxAttribute extends Node {
21
+ type: "mdxJsxAttribute";
22
+ name: string;
23
+ value?: MdxJsxAttributeValueExpression | string | null | undefined;
24
+ data?: MdxJsxAttributeData | undefined;
25
+ }
26
+ export interface MdxJsxAttributeData extends Data {
27
+ }
28
+ export interface MdxJsxFlowElement extends MdastParent {
29
+ type: "mdxJsxFlowElement";
30
+ name: string | null;
31
+ attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>;
32
+ children: Array<BlockContent | DefinitionContent>;
33
+ data?: MdxJsxFlowElementData | undefined;
34
+ }
35
+ export interface MdxJsxFlowElementData extends MdastData {
36
+ }
37
+ export interface MdxJsxTextElement extends MdastParent {
38
+ type: "mdxJsxTextElement";
39
+ name: string | null;
40
+ attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>;
41
+ children: PhrasingContent[];
42
+ data?: MdxJsxTextElementData | undefined;
43
+ }
44
+ export interface MdxJsxTextElementData extends MdastData {
45
+ }
46
+ export interface MdxJsxFlowElementHast extends HastParent {
47
+ type: "mdxJsxFlowElement";
48
+ name: string | null;
49
+ attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>;
50
+ children: ElementContent[];
51
+ data?: MdxJsxFlowElementHastData | undefined;
52
+ }
53
+ export interface MdxJsxFlowElementHastData extends HastData {
54
+ }
55
+ export interface MdxJsxTextElementHast extends HastParent {
56
+ type: "mdxJsxTextElement";
57
+ name: string | null;
58
+ attributes: Array<MdxJsxAttribute | MdxJsxExpressionAttribute>;
59
+ children: ElementContent[];
60
+ data?: MdxJsxTextElementHastData | undefined;
61
+ }
62
+ export interface MdxJsxTextElementHastData extends HastData {
63
+ }
64
+ export interface MdxFlowExpression extends MdastLiteral {
65
+ type: "mdxFlowExpression";
66
+ data?: MdxFlowExpressionData | undefined;
67
+ }
68
+ export interface MdxFlowExpressionData extends MdastData {
69
+ estree?: unknown;
70
+ }
71
+ export interface MdxTextExpression extends MdastLiteral {
72
+ type: "mdxTextExpression";
73
+ data?: MdxTextExpressionData | undefined;
74
+ }
75
+ export interface MdxTextExpressionData extends MdastData {
76
+ estree?: unknown;
77
+ }
78
+ export interface MdxFlowExpressionHast extends HastLiteral {
79
+ type: "mdxFlowExpression";
80
+ data?: MdxFlowExpressionHastData | undefined;
81
+ }
82
+ export interface MdxFlowExpressionHastData extends HastData {
83
+ estree?: unknown;
84
+ }
85
+ export interface MdxTextExpressionHast extends HastLiteral {
86
+ type: "mdxTextExpression";
87
+ data?: MdxTextExpressionHastData | undefined;
88
+ }
89
+ export interface MdxTextExpressionHastData extends HastData {
90
+ estree?: unknown;
91
+ }
92
+ export interface MdxjsEsm extends MdastLiteral {
93
+ type: "mdxjsEsm";
94
+ data?: MdxjsEsmData | undefined;
95
+ }
96
+ export interface MdxjsEsmData extends MdastData {
97
+ estree?: unknown;
98
+ }
99
+ export interface MdxjsEsmHast extends HastLiteral {
100
+ type: "mdxjsEsm";
101
+ data?: MdxjsEsmHastData | undefined;
102
+ }
103
+ export interface MdxjsEsmHastData extends HastData {
104
+ estree?: unknown;
105
+ }
106
+ declare module "mdast" {
107
+ interface BlockContentMap {
108
+ mdxJsxFlowElement: MdxJsxFlowElement;
109
+ mdxFlowExpression: MdxFlowExpression;
110
+ }
111
+ interface PhrasingContentMap {
112
+ mdxJsxTextElement: MdxJsxTextElement;
113
+ mdxTextExpression: MdxTextExpression;
114
+ }
115
+ interface RootContentMap {
116
+ mdxJsxFlowElement: MdxJsxFlowElement;
117
+ mdxJsxTextElement: MdxJsxTextElement;
118
+ mdxTextExpression: MdxTextExpression;
119
+ mdxFlowExpression: MdxFlowExpression;
120
+ mdxjsEsm: MdxjsEsm;
121
+ }
122
+ interface FrontmatterContentMap {
123
+ mdxjsEsm: MdxjsEsm;
124
+ }
125
+ }
126
+ declare module "hast" {
127
+ interface ElementContentMap {
128
+ mdxJsxTextElement: MdxJsxTextElementHast;
129
+ mdxJsxFlowElement: MdxJsxFlowElementHast;
130
+ mdxFlowExpression: MdxFlowExpressionHast;
131
+ mdxTextExpression: MdxTextExpressionHast;
132
+ }
133
+ interface RootContentMap {
134
+ mdxJsxTextElement: MdxJsxTextElementHast;
135
+ mdxJsxFlowElement: MdxJsxFlowElementHast;
136
+ mdxFlowExpression: MdxFlowExpressionHast;
137
+ mdxTextExpression: MdxTextExpressionHast;
138
+ mdxjsEsm: MdxjsEsmHast;
139
+ }
140
+ }
@@ -0,0 +1,7 @@
1
+ // Manually-defined MDX AST node types.
2
+ //
3
+ // These replicate the type definitions from mdast-util-mdx-jsx,
4
+ // mdast-util-mdx-expression, and mdast-util-mdxjs-esm so we can avoid
5
+ // pulling in those packages (and their massive transitive dependency trees)
6
+ // just for a handful of interfaces.
7
+ export {};
package/dist/plugin.js CHANGED
@@ -16,4 +16,3 @@ export function defineHastPlugin(definition) {
16
16
  }
17
17
  return definition;
18
18
  }
19
- //# sourceMappingURL=plugin.js.map
package/dist/types.d.ts CHANGED
@@ -2,10 +2,8 @@ import type { Position } from "unist";
2
2
  import type { Literal as MdastLiteral, Nodes as MdastStdNodes } from "mdast";
3
3
  import type { Nodes as HastStdNodes } from "hast";
4
4
  export type { Position, Point } from "unist";
5
- export type { MdxJsxFlowElement, MdxJsxTextElement, MdxJsxAttribute as MdxJsxAttributeNode, MdxJsxExpressionAttribute as MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpression as MdxJsxAttributeValueExpressionNode, } from "mdast-util-mdx-jsx";
6
- export type { MdxFlowExpression, MdxTextExpression } from "mdast-util-mdx-expression";
7
- export type { MdxjsEsm } from "mdast-util-mdxjs-esm";
8
- import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from "mdast-util-mdx-jsx";
5
+ export type { MdxJsxFlowElement, MdxJsxTextElement, MdxJsxAttribute as MdxJsxAttributeNode, MdxJsxExpressionAttribute as MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpression as MdxJsxAttributeValueExpressionNode, MdxFlowExpression, MdxTextExpression, MdxjsEsm, } from "./mdx-types.js";
6
+ import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from "./mdx-types.js";
9
7
  export type MdxJsxAttributeUnion = MdxJsxAttribute | MdxJsxExpressionAttribute;
10
8
  export interface Toml extends MdastLiteral {
11
9
  type: "toml";
@@ -46,13 +44,13 @@ declare module "hast" {
46
44
  }
47
45
  }
48
46
  /**
49
- * Materialized mdast node a standard `mdast.Nodes` discriminated union.
47
+ * Materialized mdast node, a standard `mdast.Nodes` discriminated union.
50
48
  * Narrow by `node.type` to access type-specific properties
51
49
  * (e.g. `depth` on `"heading"`, `url` on `"link"`).
52
50
  */
53
51
  export type MdastNode = MdastStdNodes;
54
52
  /**
55
- * Materialized hast node a standard `hast.Nodes` discriminated union.
53
+ * Materialized hast node, a standard `hast.Nodes` discriminated union.
56
54
  * Narrow by `node.type` to access type-specific properties
57
55
  * (e.g. `tagName` on `"element"`, `value` on `"text"`).
58
56
  */
package/dist/types.js CHANGED
@@ -3,4 +3,3 @@
3
3
  // Uses standard @types/mdast, @types/hast, and mdast-util-mdx-* packages
4
4
  // for AST node types. Extension types (toml, math, raw) are augmented here.
5
5
  export {};
6
- //# sourceMappingURL=types.js.map
package/index.d.ts CHANGED
@@ -23,7 +23,7 @@ export declare function convertMdastToHastHandle(handle: ArenaHandle): ArenaHand
23
23
 
24
24
  /**
25
25
  * Parse markdown source and convert to HAST. Returns an opaque handle.
26
- * The arena stays in Rust memory no buffer is copied to JS.
26
+ * The arena stays in Rust memory, no buffer is copied to JS.
27
27
  */
28
28
  export declare function createHastHandle(source: string): ArenaHandle
29
29
 
@@ -75,13 +75,30 @@ export interface JsSubscription {
75
75
  tagFilter: Array<string>
76
76
  }
77
77
 
78
+ /** Options for `mdast_text_content_handle`, matching `mdast-util-to-string`. */
79
+ export interface JsTextContentOptions {
80
+ /** Include `alt` text from image nodes. Default: true. */
81
+ includeImageAlt?: boolean
82
+ /** Include `value` from HTML nodes. Default: true. */
83
+ includeHtml?: boolean
84
+ }
85
+
86
+ /**
87
+ * Collect the concatenated text content of an MDAST node and all its descendants.
88
+ * Mirrors `mdast-util-to-string`: collects value from text nodes, alt from images.
89
+ */
90
+ export declare function mdastTextContentHandle(handle: ArenaHandle, nodeId: number, options?: JsTextContentOptions | undefined | null): string
91
+
78
92
  /**
79
93
  * Parse a JavaScript expression and return its ESTree-compatible AST as a JSON string.
80
94
  * Returns null if parsing fails. The JS layer calls JSON.parse (faster than serde_json → NAPI).
81
95
  */
82
96
  export declare function parseExpression(source: string): string | null
83
97
 
84
- /** Parse Markdown source and return HTML string directly. */
98
+ /**
99
+ * Parse Markdown source and return HTML string directly.
100
+ * Uses pulldown-cmark's streaming renderer, skipping the arena entirely.
101
+ */
85
102
  export declare function parseToHtml(source: string): string
86
103
 
87
104
  /** Render a handle's HAST arena to HTML. Does not consume the handle. */
@@ -97,8 +114,8 @@ export declare function serializeMdastHandle(handle: ArenaHandle): Uint8Array
97
114
  export declare function setNodeData(handle: ArenaHandle, nodeId: number, json: Uint8Array): void
98
115
 
99
116
  /**
100
- * Collect the concatenated text content of a node and all its descendants.
101
- * Walks entirely in Rust no per-child NAPI round-trips.
117
+ * Collect the concatenated text content of a HAST node and all its descendants.
118
+ * Walks entirely in Rust, no per-child NAPI round-trips.
102
119
  */
103
120
  export declare function textContentHandle(handle: ArenaHandle, nodeId: number): string
104
121