satteri 0.1.3 → 0.2.0

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/README.md CHANGED
@@ -231,6 +231,8 @@ const js = mdxToJs("# Hello\n\nWorld", {
231
231
 
232
232
  The `ignoreElements` option can be used to exclude specific elements from collapsing.
233
233
 
234
+ Shoutout to [Bjorn Lu](https://bjornlu.com) for originally developing this optimization for [Astro](https://astro.build/).
235
+
234
236
  ### `markdownToMdast(source: string)`
235
237
 
236
238
  Parse Markdown and return a complete mdast tree. This can be useful if you wanted to benefit from the fast native parsing of Sätteri, but ultimately wanted another pipeline to handle transformations and compilation, e.g. using remark plugins and `remark-stringify` to convert back to Markdown after processing.
@@ -0,0 +1 @@
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
@@ -0,0 +1,2 @@
1
+ // @ts-nocheck — WASM browser binding has no type declarations
2
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
@@ -0,0 +1 @@
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
@@ -0,0 +1 @@
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
package/dist/compile.d.ts CHANGED
@@ -7,21 +7,69 @@ export interface OptimizeStaticConfig {
7
7
  wrapPropValue?: boolean;
8
8
  ignoreElements?: string[];
9
9
  }
10
+ /** Parser feature toggles. All default to their documented value when omitted. */
11
+ export interface Features {
12
+ /** GFM: tables, footnotes, strikethrough, task lists, blockquote tags. Default: true. */
13
+ gfm?: boolean;
14
+ /** Frontmatter: YAML (`--- ... ---`) and TOML (`+++ ... +++`). Default: true. */
15
+ frontmatter?: boolean;
16
+ /** Math blocks and inline math. Default: true. */
17
+ math?: boolean;
18
+ /** Heading attributes (`# text { #id .class }`). Default: true. */
19
+ headingAttributes?: boolean;
20
+ /** Colon-delimited container directive blocks (`:::`). Default: false. */
21
+ directive?: boolean;
22
+ /** Superscript (`^super^`). Default: false. */
23
+ superscript?: boolean;
24
+ /** Subscript (`~sub~`). Default: false. */
25
+ subscript?: boolean;
26
+ /** Obsidian-style wikilinks (`[[link]]`). Default: false. */
27
+ wikilinks?: boolean;
28
+ /** Smart punctuation à la SmartyPants. Default: false. */
29
+ smartPunctuation?: boolean;
30
+ /** Definition lists. Default: false. */
31
+ definitionList?: boolean;
32
+ }
10
33
  export interface CompileOptions {
11
34
  mdastPlugins?: MdastPluginDefinition[];
12
35
  hastPlugins?: HastPluginDefinition[];
36
+ features?: Features;
13
37
  filename?: string;
14
38
  }
15
39
  export interface MdxCompileOptions extends CompileOptions {
16
40
  optimizeStatic?: OptimizeStaticConfig;
41
+ /** Place to import automatic JSX runtimes from (e.g. "react", "preact"). Default: "react". */
42
+ jsxImportSource?: string;
43
+ /** Whether to keep JSX instead of compiling it to functions. Default: false. */
44
+ jsx?: boolean;
45
+ /** JSX runtime: "automatic" (default) or "classic". */
46
+ jsxRuntime?: "automatic" | "classic";
47
+ /** Enable development mode. Default: false. */
48
+ development?: boolean;
49
+ /** Place to import the component provider from. */
50
+ providerImportSource?: string;
51
+ /** Pragma for JSX in classic runtime (default: "React.createElement"). */
52
+ pragma?: string;
53
+ /** Pragma for JSX fragments in classic runtime (default: "React.Fragment"). */
54
+ pragmaFrag?: string;
55
+ /** Where to import the pragma from in classic runtime (default: "react"). */
56
+ pragmaImportSource?: string;
17
57
  }
18
58
  export declare function markdownToHtml(source: string, options?: CompileOptions): string | Promise<string>;
19
59
  export declare function mdxToJs(source: string, options?: MdxCompileOptions): string | Promise<string>;
20
60
  /** Parse Markdown source into a materialized mdast tree. */
21
- export declare function markdownToMdast(source: string): MdastNode;
61
+ export declare function markdownToMdast(source: string, options?: {
62
+ features?: Features;
63
+ }): MdastNode;
22
64
  /** Parse MDX source into a materialized mdast tree. */
23
- export declare function mdxToMdast(source: string): MdastNode;
65
+ export declare function mdxToMdast(source: string, options?: {
66
+ features?: Features;
67
+ }): MdastNode;
24
68
  /** Convert Markdown source to a materialized hast tree. */
25
- export declare function markdownToHast(source: string): HastNode;
69
+ export declare function markdownToHast(source: string, options?: {
70
+ features?: Features;
71
+ }): HastNode;
26
72
  /** Convert MDX source to a materialized hast tree. */
27
- export declare function mdxToHast(source: string): HastNode;
73
+ export declare function mdxToHast(source: string, options?: {
74
+ features?: Features;
75
+ }): HastNode;
package/dist/compile.js CHANGED
@@ -1,10 +1,37 @@
1
1
  import { visitHastHandle, resolveSubscriptions } from "./hast/hast-visitor.js";
2
2
  import { visitMdastHandle, resolveMdastSubscriptions, } from "./mdast/mdast-visitor.js";
3
- import { parseToHtml, compileMdx, createHastHandle, createMdxHastHandle, renderHandle, compileHandle, applyCommandsToHandle, dropHandle, createMdastHandle, createMdxMdastHandle, applyCommandsToMdastHandle, convertMdastToHastHandle, applyCommandsAndConvertToHastHandle, getHandleSource, serializeHandle, serializeMdastHandle, } from "../index.js";
4
- import { ArenaReader } from "./mdast/mdast-reader.js";
5
- import { materializeTree } from "./mdast/mdast-materializer.js";
3
+ import { parseToHtml, compileMdx, createHastHandle, createMdxHastHandle, renderHandle, compileHandle, applyCommandsToHandle, dropHandle, createMdastHandle, createMdxMdastHandle, applyCommandsToMdastHandle, convertMdastToHastHandle, applyCommandsAndConvertToHastHandle, getHandleSource, serializeHandle, serializeMdastHandle, } from "#binding";
4
+ import { MdastReader } from "./mdast/mdast-reader.js";
5
+ import { materializeMdastTree } from "./mdast/mdast-materializer.js";
6
6
  import { HastReader } from "./hast/hast-reader.js";
7
7
  import { materializeHastTree } from "./hast/hast-materializer.js";
8
+ function featuresToNative(features) {
9
+ if (!features)
10
+ return undefined;
11
+ // Build object with only defined keys to satisfy exactOptionalPropertyTypes
12
+ const result = {};
13
+ if (features.gfm !== undefined)
14
+ result.gfm = features.gfm;
15
+ if (features.frontmatter !== undefined)
16
+ result.frontmatter = features.frontmatter;
17
+ if (features.math !== undefined)
18
+ result.math = features.math;
19
+ if (features.headingAttributes !== undefined)
20
+ result.headingAttributes = features.headingAttributes;
21
+ if (features.directive !== undefined)
22
+ result.directive = features.directive;
23
+ if (features.superscript !== undefined)
24
+ result.superscript = features.superscript;
25
+ if (features.subscript !== undefined)
26
+ result.subscript = features.subscript;
27
+ if (features.wikilinks !== undefined)
28
+ result.wikilinks = features.wikilinks;
29
+ if (features.smartPunctuation !== undefined)
30
+ result.smartPunctuation = features.smartPunctuation;
31
+ if (features.definitionList !== undefined)
32
+ result.definitionList = features.definitionList;
33
+ return result;
34
+ }
8
35
  function runMdastPluginsOnHandle(handle, plugins, filename) {
9
36
  let pendingCommands = null;
10
37
  const source = getHandleSource(handle);
@@ -54,12 +81,47 @@ function runHastPluginsOnHandle(handle, plugins, source, filename) {
54
81
  };
55
82
  return runNext();
56
83
  }
84
+ // Public API
85
+ function mdxOptionsToNative(opts) {
86
+ const hasAny = opts.optimizeStatic ||
87
+ opts.jsxImportSource !== undefined ||
88
+ opts.jsx !== undefined ||
89
+ opts.jsxRuntime !== undefined ||
90
+ opts.development !== undefined ||
91
+ opts.providerImportSource !== undefined ||
92
+ opts.pragma !== undefined ||
93
+ opts.pragmaFrag !== undefined ||
94
+ opts.pragmaImportSource !== undefined;
95
+ if (!hasAny)
96
+ return undefined;
97
+ const result = {};
98
+ if (opts.optimizeStatic)
99
+ result.optimizeStatic = opts.optimizeStatic;
100
+ if (opts.jsxImportSource !== undefined)
101
+ result.jsxImportSource = opts.jsxImportSource;
102
+ if (opts.jsx !== undefined)
103
+ result.jsx = opts.jsx;
104
+ if (opts.jsxRuntime !== undefined)
105
+ result.jsxRuntime = opts.jsxRuntime;
106
+ if (opts.development !== undefined)
107
+ result.development = opts.development;
108
+ if (opts.providerImportSource !== undefined)
109
+ result.providerImportSource = opts.providerImportSource;
110
+ if (opts.pragma !== undefined)
111
+ result.pragma = opts.pragma;
112
+ if (opts.pragmaFrag !== undefined)
113
+ result.pragmaFrag = opts.pragmaFrag;
114
+ if (opts.pragmaImportSource !== undefined)
115
+ result.pragmaImportSource = opts.pragmaImportSource;
116
+ return result;
117
+ }
57
118
  export function markdownToHtml(source, options = {}) {
58
- const { mdastPlugins = [], hastPlugins = [], filename = "<unknown>" } = options;
119
+ const { mdastPlugins = [], hastPlugins = [], features, filename = "<unknown>" } = options;
120
+ const nativeFeatures = featuresToNative(features);
59
121
  if (mdastPlugins.length === 0 && hastPlugins.length === 0) {
60
- return parseToHtml(source);
122
+ return parseToHtml(source, nativeFeatures);
61
123
  }
62
- const handleResult = createHastHandleFromMdast(source, mdastPlugins, false, filename);
124
+ const handleResult = createHastHandleFromMdast(source, mdastPlugins, false, filename, nativeFeatures);
63
125
  const finish = (hastHandle) => {
64
126
  const asyncResult = runHastPluginsOnHandle(hastHandle, hastPlugins, source, filename);
65
127
  if (asyncResult instanceof Promise) {
@@ -79,12 +141,13 @@ export function markdownToHtml(source, options = {}) {
79
141
  return finish(handleResult);
80
142
  }
81
143
  export function mdxToJs(source, options = {}) {
82
- const { mdastPlugins = [], hastPlugins = [], optimizeStatic, filename = "<unknown>" } = options;
83
- const mdxOptions = optimizeStatic ? { optimizeStatic } : undefined;
144
+ const { mdastPlugins = [], hastPlugins = [], features, filename = "<unknown>", ...mdxFields } = options;
145
+ const mdxOptions = mdxOptionsToNative(mdxFields);
146
+ const nativeFeatures = featuresToNative(features);
84
147
  if (mdastPlugins.length === 0 && hastPlugins.length === 0) {
85
- return compileMdx(source, mdxOptions);
148
+ return compileMdx(source, mdxOptions, nativeFeatures);
86
149
  }
87
- const handleResult = createHastHandleFromMdast(source, mdastPlugins, true, filename);
150
+ const handleResult = createHastHandleFromMdast(source, mdastPlugins, true, filename, nativeFeatures);
88
151
  const finish = (hastHandle) => {
89
152
  const asyncResult = runHastPluginsOnHandle(hastHandle, hastPlugins, source, filename);
90
153
  if (asyncResult instanceof Promise) {
@@ -106,11 +169,17 @@ export function mdxToJs(source, options = {}) {
106
169
  // Pipeline: parse → mdast plugins → hast conversion → hast plugins
107
170
  // All arenas stay in Rust. No intermediate buffer copies to JS.
108
171
  /** Parse + mdast plugins + convert to HAST handle. */
109
- function createHastHandleFromMdast(source, mdastPlugins, mdx, filename) {
172
+ function createHastHandleFromMdast(source, mdastPlugins, mdx, filename,
173
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
174
+ nativeFeatures) {
110
175
  if (mdastPlugins.length === 0) {
111
- return mdx ? createMdxHastHandle(source) : createHastHandle(source);
176
+ return mdx
177
+ ? createMdxHastHandle(source, nativeFeatures)
178
+ : createHastHandle(source, nativeFeatures);
112
179
  }
113
- const mdastHandle = mdx ? createMdxMdastHandle(source) : createMdastHandle(source);
180
+ const mdastHandle = mdx
181
+ ? createMdxMdastHandle(source, nativeFeatures)
182
+ : createMdastHandle(source, nativeFeatures);
114
183
  const mdastResult = runMdastPluginsOnHandle(mdastHandle, mdastPlugins, filename);
115
184
  const convert = (r) => {
116
185
  if (r.pendingCommands) {
@@ -125,27 +194,27 @@ function createHastHandleFromMdast(source, mdastPlugins, mdx, filename) {
125
194
  }
126
195
  // Step-by-step API: individual pipeline stages with materialized trees
127
196
  /** Parse Markdown source into a materialized mdast tree. */
128
- export function markdownToMdast(source) {
129
- const handle = createMdastHandle(source);
197
+ export function markdownToMdast(source, options = {}) {
198
+ const handle = createMdastHandle(source, featuresToNative(options.features));
130
199
  const buf = serializeMdastHandle(handle);
131
- return materializeTree(new ArenaReader(buf));
200
+ return materializeMdastTree(new MdastReader(buf));
132
201
  }
133
202
  /** Parse MDX source into a materialized mdast tree. */
134
- export function mdxToMdast(source) {
135
- const handle = createMdxMdastHandle(source);
203
+ export function mdxToMdast(source, options = {}) {
204
+ const handle = createMdxMdastHandle(source, featuresToNative(options.features));
136
205
  const buf = serializeMdastHandle(handle);
137
- return materializeTree(new ArenaReader(buf));
206
+ return materializeMdastTree(new MdastReader(buf));
138
207
  }
139
208
  /** Convert Markdown source to a materialized hast tree. */
140
- export function markdownToHast(source) {
141
- const handle = createHastHandle(source);
209
+ export function markdownToHast(source, options = {}) {
210
+ const handle = createHastHandle(source, featuresToNative(options.features));
142
211
  const buf = serializeHandle(handle);
143
212
  dropHandle(handle);
144
213
  return materializeHastTree(new HastReader(buf));
145
214
  }
146
215
  /** Convert MDX source to a materialized hast tree. */
147
- export function mdxToHast(source) {
148
- const handle = createMdxHastHandle(source);
216
+ export function mdxToHast(source, options = {}) {
217
+ const handle = createMdxHastHandle(source, featuresToNative(options.features));
149
218
  const buf = serializeHandle(handle);
150
219
  dropHandle(handle);
151
220
  return materializeHastTree(new HastReader(buf));
@@ -51,7 +51,8 @@ export function materializeHastNode(reader, nodeId) {
51
51
  typeName = `unknown(${nodeType})`;
52
52
  break;
53
53
  }
54
- const node = { type: typeName };
54
+ const position = reader.getPosition(nodeId);
55
+ const node = (position ? { type: typeName, position } : { type: typeName });
55
56
  // _nodeId: non-enumerable internal reference
56
57
  Object.defineProperty(node, "_nodeId", {
57
58
  value: nodeId,
@@ -25,6 +25,19 @@ export declare class HastReader {
25
25
  getSource(): string;
26
26
  /** Read a substring from the string pool by byte offset and length. */
27
27
  getString(offset: number, len: number): string;
28
+ /** Get position data for a node. */
29
+ getPosition(nodeId: number): {
30
+ start: {
31
+ offset: number;
32
+ line: number;
33
+ column: number;
34
+ };
35
+ end: {
36
+ offset: number;
37
+ line: number;
38
+ column: number;
39
+ };
40
+ } | undefined;
28
41
  /** Get the node_type byte for a given node ID. */
29
42
  getNodeType(nodeId: number): number;
30
43
  /** Get child node IDs for a given node. */
@@ -34,6 +34,12 @@ const MDX_ATTR_SPREAD = 3;
34
34
  // Total: 52 bytes
35
35
  const FIELD = {
36
36
  node_type: 4,
37
+ start_offset: 12,
38
+ end_offset: 16,
39
+ start_line: 20,
40
+ start_column: 24,
41
+ end_line: 28,
42
+ end_column: 32,
37
43
  children_start: 36,
38
44
  children_count: 40,
39
45
  data_offset: 44,
@@ -102,6 +108,27 @@ export class HastReader {
102
108
  const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset + sourceOffset + offset, len);
103
109
  return this.#textDecoder.decode(bytes);
104
110
  }
111
+ /** Get position data for a node. */
112
+ getPosition(nodeId) {
113
+ const base = this.#header.nodesOffset + nodeId * this.#header.nodeStructSize;
114
+ const v = this.#view;
115
+ const startLine = v.getUint32(base + FIELD.start_line, true);
116
+ const startOffset = v.getUint32(base + FIELD.start_offset, true);
117
+ if (startLine === 0 && startOffset === 0)
118
+ return undefined;
119
+ return {
120
+ start: {
121
+ offset: startOffset,
122
+ line: startLine,
123
+ column: v.getUint32(base + FIELD.start_column, true),
124
+ },
125
+ end: {
126
+ offset: v.getUint32(base + FIELD.end_offset, true),
127
+ line: v.getUint32(base + FIELD.end_line, true),
128
+ column: v.getUint32(base + FIELD.end_column, true),
129
+ },
130
+ };
131
+ }
105
132
  /** Get the node_type byte for a given node ID. */
106
133
  getNodeType(nodeId) {
107
134
  const { nodesOffset, nodeStructSize } = this.#header;
@@ -1,7 +1,7 @@
1
1
  import { materializeHastNode } from "./hast-materializer.js";
2
2
  import { HastReader, HAST_ELEMENT, HAST_TEXT, HAST_COMMENT, HAST_RAW, HAST_MDX_JSX_ELEMENT, HAST_MDX_JSX_TEXT_ELEMENT, HAST_MDX_FLOW_EXPRESSION, HAST_MDX_TEXT_EXPRESSION, HAST_MDX_ESM, } from "./hast-reader.js";
3
3
  import { CommandBuffer } from "../command-buffer.js";
4
- import { walkHandle, applyCommandsToHandle, serializeHandle, textContentHandle, getNodeData as napiGetNodeData, parseExpression as napiParseExpression, } from "../../index.js";
4
+ import { walkHandle, applyCommandsToHandle, serializeHandle, textContentHandle, getNodeData as napiGetNodeData, parseExpression as napiParseExpression, } from "#binding";
5
5
  /** Maps HastNode objects to their arena node IDs without Object.defineProperty overhead. */
6
6
  const nodeIdMap = new WeakMap();
7
7
  /** Attach `parseExpression()` to an MDX expression node. */
@@ -374,7 +374,8 @@ function readMatchedNode(view, buf, offset, nodeId, nodeType, resolver) {
374
374
  nodeType === HAST_COMMENT ||
375
375
  nodeType === HAST_RAW ||
376
376
  nodeType === HAST_MDX_FLOW_EXPRESSION ||
377
- nodeType === HAST_MDX_TEXT_EXPRESSION) {
377
+ nodeType === HAST_MDX_TEXT_EXPRESSION ||
378
+ nodeType === HAST_MDX_ESM) {
378
379
  return readTextFromBinary(view, buf, offset, nodeId, nodeType);
379
380
  }
380
381
  else if (nodeType === HAST_MDX_JSX_ELEMENT || nodeType === HAST_MDX_JSX_TEXT_ELEMENT) {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,14 @@
1
1
  export { markdownToHtml, mdxToJs, markdownToMdast, mdxToMdast, markdownToHast, mdxToHast, } from "./compile.js";
2
- export type { CompileOptions, MdxCompileOptions, OptimizeStaticConfig } from "./compile.js";
2
+ export type { CompileOptions, MdxCompileOptions, OptimizeStaticConfig, Features, } from "./compile.js";
3
3
  export { defineMdastPlugin, defineHastPlugin } from "./plugin.js";
4
4
  export type { MdastPluginDefinition, HastPluginDefinition } from "./plugin.js";
5
5
  export type { HastVisitorInstance, HastVisitorContext, HastFilteredVisitor, EstreeProgram, } from "./hast/hast-visitor.js";
6
6
  export type { MdastNode, HastNode, Position, Point, MdxJsxAttributeNode, MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpressionNode, MdxJsxAttributeUnion, } from "./types.js";
7
+ export { visitMdastHandle, resolveMdastSubscriptions } from "./mdast/mdast-visitor.js";
8
+ export type { MdastPluginInstance } from "./mdast/mdast-visitor.js";
9
+ export { visitHastHandle, resolveSubscriptions as resolveHastSubscriptions, } from "./hast/hast-visitor.js";
10
+ export { MdastReader } from "./mdast/mdast-reader.js";
11
+ export { materializeMdastTree } from "./mdast/mdast-materializer.js";
12
+ export { HastReader } from "./hast/hast-reader.js";
13
+ export { materializeHastTree } from "./hast/hast-materializer.js";
14
+ export { createMdastHandle, createMdxMdastHandle, createHastHandle, createMdxHastHandle, convertMdastToHastHandle, serializeMdastHandle, serializeHandle, renderHandle, compileHandle, dropHandle, applyCommandsToMdastHandle, applyCommandsAndConvertToHastHandle, getHandleSource, } from "#binding";
package/dist/index.js CHANGED
@@ -2,3 +2,12 @@
2
2
  export { markdownToHtml, mdxToJs, markdownToMdast, mdxToMdast, markdownToHast, mdxToHast, } from "./compile.js";
3
3
  // Plugin definitions
4
4
  export { defineMdastPlugin, defineHastPlugin } from "./plugin.js";
5
+ // Visitor pipeline (for manual plugin execution)
6
+ export { visitMdastHandle, resolveMdastSubscriptions } from "./mdast/mdast-visitor.js";
7
+ export { visitHastHandle, resolveSubscriptions as resolveHastSubscriptions, } from "./hast/hast-visitor.js";
8
+ // Step-by-step API: readers, materializers, and handle functions
9
+ export { MdastReader } from "./mdast/mdast-reader.js";
10
+ export { materializeMdastTree } from "./mdast/mdast-materializer.js";
11
+ export { HastReader } from "./hast/hast-reader.js";
12
+ export { materializeHastTree } from "./hast/hast-materializer.js";
13
+ export { createMdastHandle, createMdxMdastHandle, createHastHandle, createMdxHastHandle, convertMdastToHastHandle, serializeMdastHandle, serializeHandle, renderHandle, compileHandle, dropHandle, applyCommandsToMdastHandle, applyCommandsAndConvertToHastHandle, getHandleSource, } from "#binding";
@@ -1,9 +1,9 @@
1
1
  import type { MdastNode } from "../types.js";
2
- import type { ArenaReader } from "./mdast-reader.js";
2
+ import type { MdastReader } from "./mdast-reader.js";
3
3
  export declare const TYPE_NAMES: Record<number, string>;
4
4
  /**
5
5
  * Materialize a single MDAST node from a binary buffer as a lazy JS object.
6
6
  */
7
- export declare function materializeNode(reader: ArenaReader, nodeId: number): MdastNode;
7
+ export declare function materializeNode(reader: MdastReader, nodeId: number): MdastNode;
8
8
  /** Materialize the full tree from root (nodeId=0). */
9
- export declare function materializeTree(reader: ArenaReader): MdastNode;
9
+ export declare function materializeMdastTree(reader: MdastReader): MdastNode;
@@ -156,6 +156,6 @@ export function materializeNode(reader, nodeId) {
156
156
  return node;
157
157
  }
158
158
  /** Materialize the full tree from root (nodeId=0). */
159
- export function materializeTree(reader) {
159
+ export function materializeMdastTree(reader) {
160
160
  return materializeNode(reader, 0);
161
161
  }
@@ -36,7 +36,7 @@ export declare const NodeType: Readonly<{
36
36
  readonly MdxjsEsm: 104;
37
37
  }>;
38
38
  export declare const NodeTypeName: Record<number, string>;
39
- export declare class ArenaReader {
39
+ export declare class MdastReader {
40
40
  #private;
41
41
  constructor(buffer: ArrayBuffer | Uint8Array);
42
42
  get nodeCount(): number;
@@ -84,7 +84,7 @@ const FIELD = {
84
84
  // source_offset: u32 @ 40
85
85
  // Total: 44 bytes
86
86
  const MAGIC = 0x5241444d; // "MDAR" bytes [0x4d,0x44,0x41,0x52] read as little-endian u32
87
- export class ArenaReader {
87
+ export class MdastReader {
88
88
  #view;
89
89
  #header;
90
90
  #textDecoder;
@@ -1,7 +1,7 @@
1
1
  import { materializeNode, TYPE_NAMES } from "./mdast-materializer.js";
2
- import { ArenaReader } from "./mdast-reader.js";
2
+ import { MdastReader } from "./mdast-reader.js";
3
3
  import { CommandBuffer, classifyReturn } from "../command-buffer.js";
4
- import { walkMdastHandle, serializeMdastHandle, getNodeData as napiGetNodeData, mdastTextContentHandle, } from "../../index.js";
4
+ import { walkMdastHandle, serializeMdastHandle, getNodeData as napiGetNodeData, mdastTextContentHandle, } from "#binding";
5
5
  const MutationType = {
6
6
  Replace: "replace",
7
7
  Remove: "remove",
@@ -169,7 +169,7 @@ function rstr(buf, off, len) {
169
169
  /**
170
170
  * Lazy child materializer for the MDAST handle walk path.
171
171
  * Serializes the handle once on first child access, then materializes
172
- * children via ArenaReader + materializeNode.
172
+ * children via MdastReader + materializeNode.
173
173
  */
174
174
  class MdastLazyChildResolver {
175
175
  #handle;
@@ -179,7 +179,7 @@ class MdastLazyChildResolver {
179
179
  }
180
180
  #ensure() {
181
181
  if (!this.#reader) {
182
- this.#reader = new ArenaReader(serializeMdastHandle(this.#handle));
182
+ this.#reader = new MdastReader(serializeMdastHandle(this.#handle));
183
183
  }
184
184
  return this.#reader;
185
185
  }
package/index.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare function applyCommandsToMdastHandle(handle: ArenaHandle, commandB
16
16
  export declare function compileHandle(handle: ArenaHandle, options?: JsMdxOptions | undefined | null): string
17
17
 
18
18
  /** Compile MDX source directly to JavaScript. */
19
- export declare function compileMdx(source: string, options?: JsMdxOptions | undefined | null): string
19
+ export declare function compileMdx(source: string, options?: JsMdxOptions | undefined | null, features?: JsFeatures | undefined | null): string
20
20
 
21
21
  /** Convert an MDAST handle to a HAST handle. The MDAST handle is consumed (emptied). */
22
22
  export declare function convertMdastToHastHandle(handle: ArenaHandle): ArenaHandle
@@ -25,16 +25,16 @@ export declare function convertMdastToHastHandle(handle: ArenaHandle): ArenaHand
25
25
  * Parse markdown source and convert to HAST. Returns an opaque handle.
26
26
  * The arena stays in Rust memory, no buffer is copied to JS.
27
27
  */
28
- export declare function createHastHandle(source: string): ArenaHandle
28
+ export declare function createHastHandle(source: string, features?: JsFeatures | undefined | null): ArenaHandle
29
29
 
30
30
  /** Parse markdown source into an MDAST arena handle. */
31
- export declare function createMdastHandle(source: string): ArenaHandle
31
+ export declare function createMdastHandle(source: string, features?: JsFeatures | undefined | null): ArenaHandle
32
32
 
33
33
  /** Parse MDX source and convert to HAST. Returns an opaque handle. */
34
- export declare function createMdxHastHandle(source: string): ArenaHandle
34
+ export declare function createMdxHastHandle(source: string, features?: JsFeatures | undefined | null): ArenaHandle
35
35
 
36
36
  /** Parse MDX source into an MDAST arena handle. */
37
- export declare function createMdxMdastHandle(source: string): ArenaHandle
37
+ export declare function createMdxMdastHandle(source: string, features?: JsFeatures | undefined | null): ArenaHandle
38
38
 
39
39
  /**
40
40
  * Release the arena memory held by a handle. The handle becomes empty
@@ -48,6 +48,33 @@ export declare function getHandleSource(handle: ArenaHandle): string
48
48
  /** Read the node_data JSON blob for a node. Returns null if none is set. */
49
49
  export declare function getNodeData(handle: ArenaHandle, nodeId: number): string | null
50
50
 
51
+ /** Feature toggles for the Markdown/MDX parser, passed from JavaScript. */
52
+ export interface JsFeatures {
53
+ /**
54
+ * GFM: tables, footnotes, strikethrough, task lists, blockquote tags.
55
+ * Default: true.
56
+ */
57
+ gfm?: boolean
58
+ /** Frontmatter: YAML (`--- ... ---`) and TOML (`+++ ... +++`). Default: true. */
59
+ frontmatter?: boolean
60
+ /** Math blocks and inline math (`$$ ... $$`, `$ ... $`). Default: true. */
61
+ math?: boolean
62
+ /** Heading attributes (`# text { #id .class }`). Default: true. */
63
+ headingAttributes?: boolean
64
+ /** Colon-delimited container directive blocks (`:::`). Default: false. */
65
+ directive?: boolean
66
+ /** Superscript (`^super^`). Default: false. */
67
+ superscript?: boolean
68
+ /** Subscript (`~sub~`). Default: false. */
69
+ subscript?: boolean
70
+ /** Obsidian-style wikilinks (`[[link]]`). Default: false. */
71
+ wikilinks?: boolean
72
+ /** Smart punctuation (ligatures, smart quotes). Default: false. */
73
+ smartPunctuation?: boolean
74
+ /** Definition lists. Default: false. */
75
+ definitionList?: boolean
76
+ }
77
+
51
78
  /** MDX compile options passed from JavaScript. */
52
79
  export interface JsMdxOptions {
53
80
  /**
@@ -55,6 +82,28 @@ export interface JsMdxOptions {
55
82
  * into raw HTML strings using the specified component and prop.
56
83
  */
57
84
  optimizeStatic?: JsOptimizeStaticConfig
85
+ /**
86
+ * Place to import automatic JSX runtimes from (e.g. "react", "preact").
87
+ * Default: "react".
88
+ */
89
+ jsxImportSource?: string
90
+ /** Whether to keep JSX instead of compiling it away. Default: false. */
91
+ jsx?: boolean
92
+ /** JSX runtime: "automatic" (default) or "classic". */
93
+ jsxRuntime?: string
94
+ /**
95
+ * Whether to add extra info to error messages and use the development
96
+ * JSX runtime. Default: false.
97
+ */
98
+ development?: boolean
99
+ /** Place to import a provider from (e.g. "@mdx-js/react"). */
100
+ providerImportSource?: string
101
+ /** Pragma for JSX in classic runtime (default: "React.createElement"). */
102
+ pragma?: string
103
+ /** Pragma for JSX fragments in classic runtime (default: "React.Fragment"). */
104
+ pragmaFrag?: string
105
+ /** Where to import the pragma from in classic runtime (default: "react"). */
106
+ pragmaImportSource?: string
58
107
  }
59
108
 
60
109
  /** Static optimization config passed from JavaScript. */
@@ -99,7 +148,7 @@ export declare function parseExpression(source: string): string | null
99
148
  * Parse Markdown source and return HTML string directly.
100
149
  * Uses pulldown-cmark's streaming renderer, skipping the arena entirely.
101
150
  */
102
- export declare function parseToHtml(source: string): string
151
+ export declare function parseToHtml(source: string, features?: JsFeatures | undefined | null): string
103
152
 
104
153
  /** Render a handle's HAST arena to HTML. Does not consume the handle. */
105
154
  export declare function renderHandle(handle: ArenaHandle): string
package/index.js CHANGED
@@ -81,8 +81,8 @@ function requireNative() {
81
81
  try {
82
82
  const binding = require('@bruits/satteri-android-arm64')
83
83
  const bindingPackageVersion = require('@bruits/satteri-android-arm64/package.json').version
84
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
84
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
85
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
86
86
  }
87
87
  return binding
88
88
  } catch (e) {
@@ -97,8 +97,8 @@ function requireNative() {
97
97
  try {
98
98
  const binding = require('@bruits/satteri-android-arm-eabi')
99
99
  const bindingPackageVersion = require('@bruits/satteri-android-arm-eabi/package.json').version
100
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
101
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
102
102
  }
103
103
  return binding
104
104
  } catch (e) {
@@ -118,8 +118,8 @@ function requireNative() {
118
118
  try {
119
119
  const binding = require('@bruits/satteri-win32-x64-gnu')
120
120
  const bindingPackageVersion = require('@bruits/satteri-win32-x64-gnu/package.json').version
121
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
121
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
122
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
123
123
  }
124
124
  return binding
125
125
  } catch (e) {
@@ -134,8 +134,8 @@ function requireNative() {
134
134
  try {
135
135
  const binding = require('@bruits/satteri-win32-x64-msvc')
136
136
  const bindingPackageVersion = require('@bruits/satteri-win32-x64-msvc/package.json').version
137
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
138
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
139
139
  }
140
140
  return binding
141
141
  } catch (e) {
@@ -151,8 +151,8 @@ function requireNative() {
151
151
  try {
152
152
  const binding = require('@bruits/satteri-win32-ia32-msvc')
153
153
  const bindingPackageVersion = require('@bruits/satteri-win32-ia32-msvc/package.json').version
154
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
154
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
155
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
156
156
  }
157
157
  return binding
158
158
  } catch (e) {
@@ -167,8 +167,8 @@ function requireNative() {
167
167
  try {
168
168
  const binding = require('@bruits/satteri-win32-arm64-msvc')
169
169
  const bindingPackageVersion = require('@bruits/satteri-win32-arm64-msvc/package.json').version
170
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
170
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
171
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
172
172
  }
173
173
  return binding
174
174
  } catch (e) {
@@ -186,8 +186,8 @@ function requireNative() {
186
186
  try {
187
187
  const binding = require('@bruits/satteri-darwin-universal')
188
188
  const bindingPackageVersion = require('@bruits/satteri-darwin-universal/package.json').version
189
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
189
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
190
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
191
191
  }
192
192
  return binding
193
193
  } catch (e) {
@@ -202,8 +202,8 @@ function requireNative() {
202
202
  try {
203
203
  const binding = require('@bruits/satteri-darwin-x64')
204
204
  const bindingPackageVersion = require('@bruits/satteri-darwin-x64/package.json').version
205
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
206
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
207
207
  }
208
208
  return binding
209
209
  } catch (e) {
@@ -218,8 +218,8 @@ function requireNative() {
218
218
  try {
219
219
  const binding = require('@bruits/satteri-darwin-arm64')
220
220
  const bindingPackageVersion = require('@bruits/satteri-darwin-arm64/package.json').version
221
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
221
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
222
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
223
223
  }
224
224
  return binding
225
225
  } catch (e) {
@@ -238,8 +238,8 @@ function requireNative() {
238
238
  try {
239
239
  const binding = require('@bruits/satteri-freebsd-x64')
240
240
  const bindingPackageVersion = require('@bruits/satteri-freebsd-x64/package.json').version
241
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
241
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
242
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
243
243
  }
244
244
  return binding
245
245
  } catch (e) {
@@ -254,8 +254,8 @@ function requireNative() {
254
254
  try {
255
255
  const binding = require('@bruits/satteri-freebsd-arm64')
256
256
  const bindingPackageVersion = require('@bruits/satteri-freebsd-arm64/package.json').version
257
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
257
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
258
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
259
259
  }
260
260
  return binding
261
261
  } catch (e) {
@@ -275,8 +275,8 @@ function requireNative() {
275
275
  try {
276
276
  const binding = require('@bruits/satteri-linux-x64-musl')
277
277
  const bindingPackageVersion = require('@bruits/satteri-linux-x64-musl/package.json').version
278
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
278
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
279
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
280
280
  }
281
281
  return binding
282
282
  } catch (e) {
@@ -291,8 +291,8 @@ function requireNative() {
291
291
  try {
292
292
  const binding = require('@bruits/satteri-linux-x64-gnu')
293
293
  const bindingPackageVersion = require('@bruits/satteri-linux-x64-gnu/package.json').version
294
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
294
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
295
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
296
296
  }
297
297
  return binding
298
298
  } catch (e) {
@@ -309,8 +309,8 @@ function requireNative() {
309
309
  try {
310
310
  const binding = require('@bruits/satteri-linux-arm64-musl')
311
311
  const bindingPackageVersion = require('@bruits/satteri-linux-arm64-musl/package.json').version
312
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
312
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
313
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
314
314
  }
315
315
  return binding
316
316
  } catch (e) {
@@ -325,8 +325,8 @@ function requireNative() {
325
325
  try {
326
326
  const binding = require('@bruits/satteri-linux-arm64-gnu')
327
327
  const bindingPackageVersion = require('@bruits/satteri-linux-arm64-gnu/package.json').version
328
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
328
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
329
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
330
330
  }
331
331
  return binding
332
332
  } catch (e) {
@@ -343,8 +343,8 @@ function requireNative() {
343
343
  try {
344
344
  const binding = require('@bruits/satteri-linux-arm-musleabihf')
345
345
  const bindingPackageVersion = require('@bruits/satteri-linux-arm-musleabihf/package.json').version
346
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
347
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
348
348
  }
349
349
  return binding
350
350
  } catch (e) {
@@ -359,8 +359,8 @@ function requireNative() {
359
359
  try {
360
360
  const binding = require('@bruits/satteri-linux-arm-gnueabihf')
361
361
  const bindingPackageVersion = require('@bruits/satteri-linux-arm-gnueabihf/package.json').version
362
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
362
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
363
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
364
364
  }
365
365
  return binding
366
366
  } catch (e) {
@@ -377,8 +377,8 @@ function requireNative() {
377
377
  try {
378
378
  const binding = require('@bruits/satteri-linux-loong64-musl')
379
379
  const bindingPackageVersion = require('@bruits/satteri-linux-loong64-musl/package.json').version
380
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
381
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
382
382
  }
383
383
  return binding
384
384
  } catch (e) {
@@ -393,8 +393,8 @@ function requireNative() {
393
393
  try {
394
394
  const binding = require('@bruits/satteri-linux-loong64-gnu')
395
395
  const bindingPackageVersion = require('@bruits/satteri-linux-loong64-gnu/package.json').version
396
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
396
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
397
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
398
398
  }
399
399
  return binding
400
400
  } catch (e) {
@@ -411,8 +411,8 @@ function requireNative() {
411
411
  try {
412
412
  const binding = require('@bruits/satteri-linux-riscv64-musl')
413
413
  const bindingPackageVersion = require('@bruits/satteri-linux-riscv64-musl/package.json').version
414
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
414
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
415
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
416
416
  }
417
417
  return binding
418
418
  } catch (e) {
@@ -427,8 +427,8 @@ function requireNative() {
427
427
  try {
428
428
  const binding = require('@bruits/satteri-linux-riscv64-gnu')
429
429
  const bindingPackageVersion = require('@bruits/satteri-linux-riscv64-gnu/package.json').version
430
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
430
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
431
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
432
432
  }
433
433
  return binding
434
434
  } catch (e) {
@@ -444,8 +444,8 @@ function requireNative() {
444
444
  try {
445
445
  const binding = require('@bruits/satteri-linux-ppc64-gnu')
446
446
  const bindingPackageVersion = require('@bruits/satteri-linux-ppc64-gnu/package.json').version
447
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
447
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
448
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
449
449
  }
450
450
  return binding
451
451
  } catch (e) {
@@ -460,8 +460,8 @@ function requireNative() {
460
460
  try {
461
461
  const binding = require('@bruits/satteri-linux-s390x-gnu')
462
462
  const bindingPackageVersion = require('@bruits/satteri-linux-s390x-gnu/package.json').version
463
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
463
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
464
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
465
465
  }
466
466
  return binding
467
467
  } catch (e) {
@@ -480,8 +480,8 @@ function requireNative() {
480
480
  try {
481
481
  const binding = require('@bruits/satteri-openharmony-arm64')
482
482
  const bindingPackageVersion = require('@bruits/satteri-openharmony-arm64/package.json').version
483
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
483
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
484
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
485
485
  }
486
486
  return binding
487
487
  } catch (e) {
@@ -496,8 +496,8 @@ function requireNative() {
496
496
  try {
497
497
  const binding = require('@bruits/satteri-openharmony-x64')
498
498
  const bindingPackageVersion = require('@bruits/satteri-openharmony-x64/package.json').version
499
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
499
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
500
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
501
501
  }
502
502
  return binding
503
503
  } catch (e) {
@@ -512,8 +512,8 @@ function requireNative() {
512
512
  try {
513
513
  const binding = require('@bruits/satteri-openharmony-arm')
514
514
  const bindingPackageVersion = require('@bruits/satteri-openharmony-arm/package.json').version
515
- if (bindingPackageVersion !== '0.1.3' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
- throw new Error(`Native binding package version mismatch, expected 0.1.3 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
515
+ if (bindingPackageVersion !== '0.2.0' && process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
516
+ throw new Error(`Native binding package version mismatch, expected 0.2.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
517
  }
518
518
  return binding
519
519
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satteri",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "High-performance Markdown and MDX processing",
5
5
  "files": [
6
6
  "dist",
@@ -10,19 +10,34 @@
10
10
  "satteri_napi.wasi.cjs",
11
11
  "satteri_napi.wasi-browser.js",
12
12
  "wasi-worker.mjs",
13
- "wasi-worker-browser.js"
13
+ "wasi-worker-browser.mjs"
14
14
  ],
15
15
  "type": "module",
16
16
  "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "imports": {
19
+ "#binding": {
20
+ "browser": "./dist/binding.browser.js",
21
+ "default": "./dist/binding.js"
22
+ }
23
+ },
17
24
  "exports": {
18
- ".": "./dist/index.js"
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "browser": "./dist/index.js",
28
+ "import": "./dist/index.js",
29
+ "default": "./dist/index.js"
30
+ }
19
31
  },
20
32
  "scripts": {
33
+ "build:wasm": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --target wasm32-wasip1-threads",
21
34
  "build:native": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip",
35
+ "build:native:cross": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --cross-compile",
22
36
  "build:native:debug": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --esm",
23
37
  "build:ts": "tsc --project tsconfig.build.json",
24
38
  "build": "pnpm build:native && pnpm build:ts",
25
- "artifacts": "napi create-npm-dirs && napi artifacts",
39
+ "artifacts": "napi create-npm-dirs && napi artifacts --output-dir .",
40
+ "prepublishOnly": "pnpm run build:ts && napi create-npm-dirs && napi artifacts --output-dir .",
26
41
  "dev": "tsc --watch",
27
42
  "vitest": "vitest",
28
43
  "test": "vitest run",
@@ -35,12 +50,20 @@
35
50
  },
36
51
  "devDependencies": {
37
52
  "@codspeed/vitest-plugin": "^5.2.0",
53
+ "@emnapi/core": "^1.9.1",
38
54
  "@emnapi/runtime": "^1.9.1",
39
55
  "@napi-rs/wasm-runtime": "^1.1.2",
40
56
  "@types/node": "^25.5.0",
41
57
  "shiki": "^4.0.2",
42
58
  "vitest": "^4"
43
59
  },
60
+ "optionalDependencies": {
61
+ "@bruits/satteri-linux-x64-gnu": "0.2.0",
62
+ "@bruits/satteri-darwin-x64": "0.2.0",
63
+ "@bruits/satteri-darwin-arm64": "0.2.0",
64
+ "@bruits/satteri-win32-x64-msvc": "0.2.0",
65
+ "@bruits/satteri-wasm32-wasi": "0.2.0"
66
+ },
44
67
  "napi": {
45
68
  "binaryName": "satteri_napi",
46
69
  "packageName": "@bruits/satteri",
@@ -51,12 +74,5 @@
51
74
  "x86_64-pc-windows-msvc",
52
75
  "wasm32-wasip1-threads"
53
76
  ]
54
- },
55
- "optionalDependencies": {
56
- "@bruits/satteri-linux-x64-gnu": "0.1.3",
57
- "@bruits/satteri-darwin-x64": "0.1.3",
58
- "@bruits/satteri-darwin-arm64": "0.1.3",
59
- "@bruits/satteri-win32-x64-msvc": "0.1.3",
60
- "@bruits/satteri-wasm32-wasi": "0.1.3"
61
77
  }
62
78
  }
@@ -0,0 +1,36 @@
1
+ import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'
2
+
3
+ const errorOutputs = []
4
+
5
+ const handler = new MessageHandler({
6
+ onLoad({ wasmModule, wasmMemory }) {
7
+ const wasi = new WASI({
8
+ print: function () {
9
+ // eslint-disable-next-line no-console
10
+ console.log.apply(console, arguments)
11
+ },
12
+ printErr: function() {
13
+ // eslint-disable-next-line no-console
14
+ console.error.apply(console, arguments)
15
+
16
+ },
17
+ })
18
+ return instantiateNapiModuleSync(wasmModule, {
19
+ childThread: true,
20
+ wasi,
21
+ overwriteImports(importObject) {
22
+ importObject.env = {
23
+ ...importObject.env,
24
+ ...importObject.napi,
25
+ ...importObject.emnapi,
26
+ memory: wasmMemory,
27
+ }
28
+ },
29
+ })
30
+ },
31
+
32
+ })
33
+
34
+ globalThis.onmessage = function (e) {
35
+ handler.handle(e)
36
+ }
@@ -1,3 +0,0 @@
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, MdxFlowExpressionHast, MdxTextExpressionHast, MdxjsEsmHast, } from "./mdx-types.js";
3
- export type { HastRaw } from "./types.js";
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
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, MdxFlowExpression, MdxTextExpression, MdxjsEsm, } from "./mdx-types.js";
3
- export type { Toml, MathNode, InlineMath } from "./types.js";
@@ -1 +0,0 @@
1
- export {};