satteri 0.4.0 → 0.5.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.
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
@@ -1,2 +1,2 @@
1
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, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
2
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
package/dist/binding.d.ts CHANGED
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
package/dist/binding.js CHANGED
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
package/dist/compile.d.ts CHANGED
@@ -50,7 +50,15 @@ export interface CompileOptions {
50
50
  features?: Features;
51
51
  filename?: string;
52
52
  }
53
- export interface MdxCompileOptions extends CompileOptions {
53
+ /**
54
+ * MDX-only compile options.
55
+ *
56
+ * These are the fields specific to MDX compilation, separate from the shared
57
+ * pipeline options in {@link CompileOptions}. Useful for wrappers (Vite/Rollup
58
+ * plugins, framework integrations) that want to expose MDX-specific knobs
59
+ * without re-exposing the shared pipeline fields.
60
+ */
61
+ export interface MdxOnlyOptions {
54
62
  optimizeStatic?: OptimizeStaticConfig;
55
63
  /** Place to import automatic JSX runtimes from (e.g. "react", "preact"). Default: "react". */
56
64
  jsxImportSource?: string;
@@ -78,8 +86,50 @@ export interface MdxCompileOptions extends CompileOptions {
78
86
  */
79
87
  outputFormat?: "program" | "function-body";
80
88
  }
81
- export declare function markdownToHtml(source: string, options?: CompileOptions): string | Promise<string>;
82
- export declare function mdxToJs(source: string, options?: MdxCompileOptions): string | Promise<string>;
89
+ export interface MdxCompileOptions extends CompileOptions, MdxOnlyOptions {
90
+ }
91
+ /** Frontmatter block extracted from the parsed Markdown/MDX source. */
92
+ export interface Frontmatter {
93
+ /** Delimiter syntax used for the block. */
94
+ kind: "yaml" | "toml";
95
+ /** Raw content between the delimiters (`---`/`+++` lines excluded). */
96
+ value: string;
97
+ }
98
+ /** Result of {@link markdownToHtml}. */
99
+ export interface MarkdownToHtmlResult {
100
+ /** Rendered HTML string. */
101
+ html: string;
102
+ /** Frontmatter block at the start of the document, or `null` if none. */
103
+ frontmatter: Frontmatter | null;
104
+ }
105
+ /** Result of {@link mdxToJs}. */
106
+ export interface MdxToJsResult {
107
+ /** Compiled JavaScript module source. */
108
+ code: string;
109
+ /** Frontmatter block at the start of the document, or `null` if none. */
110
+ frontmatter: Frontmatter | null;
111
+ }
112
+ type AnyFn = (...args: any[]) => unknown;
113
+ type ReturnsPromise<F> = F extends AnyFn ? Extract<ReturnType<F>, Promise<unknown>> extends never ? false : true : false;
114
+ type FieldIsAsync<V> = V extends AnyFn ? ReturnsPromise<V> : V extends {
115
+ visit: infer F;
116
+ } ? ReturnsPromise<F> : V extends ReadonlyArray<infer Item> ? Item extends {
117
+ visit: infer F;
118
+ } ? ReturnsPromise<F> : false : false;
119
+ type AnyVisitorAsync<P> = {
120
+ [K in keyof P]-?: FieldIsAsync<NonNullable<P[K]>>;
121
+ }[keyof P];
122
+ type IsPluginAsync<P> = true extends AnyVisitorAsync<P> ? true : false;
123
+ type ResolveInput<P> = P extends () => infer D ? D : P;
124
+ type AnyInputAsync<Ps> = Ps extends ReadonlyArray<infer P> ? true extends IsPluginAsync<ResolveInput<P>> ? true : false : false;
125
+ type OptionsAsync<O> = (O extends {
126
+ mdastPlugins: infer Ps;
127
+ } ? AnyInputAsync<Ps> : false) extends true ? true : (O extends {
128
+ hastPlugins: infer Ps;
129
+ } ? AnyInputAsync<Ps> : false) extends true ? true : false;
130
+ type ResultFor<O, R> = OptionsAsync<O> extends true ? Promise<R> : R;
131
+ export declare function markdownToHtml<O extends CompileOptions>(source: string, options?: O): ResultFor<O, MarkdownToHtmlResult>;
132
+ export declare function mdxToJs<O extends MdxCompileOptions>(source: string, options?: O): ResultFor<O, MdxToJsResult>;
83
133
  export interface EvaluateOptions extends Omit<MdxCompileOptions, "jsx" | "outputFormat"> {
84
134
  Fragment: unknown;
85
135
  jsx: (type: unknown, props: unknown, key?: unknown) => unknown;
@@ -115,3 +165,4 @@ export declare function markdownToHast(source: string, options?: {
115
165
  export declare function mdxToHast(source: string, options?: {
116
166
  features?: Features;
117
167
  }): HastNode;
168
+ export {};
package/dist/compile.js CHANGED
@@ -1,6 +1,6 @@
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, } from "#binding";
3
+ import { createHastHandle, createMdxHastHandle, renderHandle, compileHandle, dropHandle, createMdastHandle, createMdxMdastHandle, applyCommandsToMdastHandle, convertMdastToHastHandle, getHandleSource, getMdastFrontmatter, serializeHandle, } from "#binding";
4
4
  import { MdastReader } from "./mdast/mdast-reader.js";
5
5
  import { materializeMdastTree } from "./mdast/mdast-materializer.js";
6
6
  import { HastReader } from "./hast/hast-reader.js";
@@ -125,52 +125,71 @@ function mdxOptionsToNative(opts) {
125
125
  export function markdownToHtml(source, options = {}) {
126
126
  const { mdastPlugins = [], hastPlugins = [], features, filename = "<unknown>" } = options;
127
127
  const nativeFeatures = featuresToNative(features);
128
- // TODO: When there's no plugins, we shouldn't go through all the steps below, we could just call parseToHtml directly.
129
- // However right now pulldown-cmark's HTML output is super different from our target (unified's). So until that's fixed, we'll do the slower pipeline
130
- const handleResult = createHastHandleFromMdast(source, mdastPlugins, false, filename, nativeFeatures);
131
- const finish = (hastHandle) => {
132
- const asyncResult = runHastPluginsOnHandle(hastHandle, hastPlugins, source, filename);
133
- if (asyncResult instanceof Promise) {
134
- return asyncResult.then(() => {
135
- const html = renderHandle(hastHandle);
136
- dropHandle(hastHandle);
137
- return html;
128
+ const result = createHastHandleFromMdast(source, mdastPlugins, false, filename, nativeFeatures);
129
+ const renderAndDrop = (h, frontmatter) => {
130
+ try {
131
+ const html = renderHandle(h);
132
+ return { html, frontmatter };
133
+ }
134
+ finally {
135
+ dropHandle(h);
136
+ }
137
+ };
138
+ const runHastThenRender = (r) => {
139
+ let hastResult;
140
+ try {
141
+ hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, filename);
142
+ }
143
+ catch (err) {
144
+ dropHandle(r.hastHandle);
145
+ throw err;
146
+ }
147
+ if (hastResult instanceof Promise) {
148
+ return hastResult.then(() => renderAndDrop(r.hastHandle, r.frontmatter), (err) => {
149
+ dropHandle(r.hastHandle);
150
+ throw err;
138
151
  });
139
152
  }
140
- const html = renderHandle(hastHandle);
141
- dropHandle(hastHandle);
142
- return html;
153
+ return renderAndDrop(r.hastHandle, r.frontmatter);
143
154
  };
144
- if (handleResult instanceof Promise) {
145
- return handleResult.then(finish);
146
- }
147
- return finish(handleResult);
155
+ if (result instanceof Promise)
156
+ return result.then(runHastThenRender);
157
+ return runHastThenRender(result);
148
158
  }
149
159
  export function mdxToJs(source, options = {}) {
150
160
  const { mdastPlugins = [], hastPlugins = [], features, filename = "<unknown>", ...mdxFields } = options;
151
161
  const mdxOptions = mdxOptionsToNative(mdxFields);
152
162
  const nativeFeatures = featuresToNative(features);
153
- if (mdastPlugins.length === 0 && hastPlugins.length === 0) {
154
- return compileMdx(source, mdxOptions, nativeFeatures);
155
- }
156
- const handleResult = createHastHandleFromMdast(source, mdastPlugins, true, filename, nativeFeatures);
157
- const finish = (hastHandle) => {
158
- const asyncResult = runHastPluginsOnHandle(hastHandle, hastPlugins, source, filename);
159
- if (asyncResult instanceof Promise) {
160
- return asyncResult.then(() => {
161
- const js = compileHandle(hastHandle, mdxOptions);
162
- dropHandle(hastHandle);
163
- return js;
163
+ const result = createHastHandleFromMdast(source, mdastPlugins, true, filename, nativeFeatures);
164
+ const compileAndDrop = (h, frontmatter) => {
165
+ try {
166
+ const code = compileHandle(h, mdxOptions);
167
+ return { code, frontmatter };
168
+ }
169
+ finally {
170
+ dropHandle(h);
171
+ }
172
+ };
173
+ const runHastThenCompile = (r) => {
174
+ let hastResult;
175
+ try {
176
+ hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, filename);
177
+ }
178
+ catch (err) {
179
+ dropHandle(r.hastHandle);
180
+ throw err;
181
+ }
182
+ if (hastResult instanceof Promise) {
183
+ return hastResult.then(() => compileAndDrop(r.hastHandle, r.frontmatter), (err) => {
184
+ dropHandle(r.hastHandle);
185
+ throw err;
164
186
  });
165
187
  }
166
- const js = compileHandle(hastHandle, mdxOptions);
167
- dropHandle(hastHandle);
168
- return js;
188
+ return compileAndDrop(r.hastHandle, r.frontmatter);
169
189
  };
170
- if (handleResult instanceof Promise) {
171
- return handleResult.then(finish);
172
- }
173
- return finish(handleResult);
190
+ if (result instanceof Promise)
191
+ return result.then(runHastThenCompile);
192
+ return runHastThenCompile(result);
174
193
  }
175
194
  /**
176
195
  * Compile and evaluate MDX in one step.
@@ -186,64 +205,96 @@ export function mdxToJs(source, options = {}) {
186
205
  export function evaluate(source, options) {
187
206
  const { Fragment, jsx, jsxs, jsxDEV, useMDXComponents, ...compileOpts } = options;
188
207
  const runtime = { Fragment, jsx, jsxs, jsxDEV, useMDXComponents };
189
- const code = mdxToJs(source, { ...compileOpts, outputFormat: "function-body" });
190
- if (code instanceof Promise) {
191
- return code.then((resolved) => new Function(resolved)(runtime));
208
+ const result = mdxToJs(source, { ...compileOpts, outputFormat: "function-body" });
209
+ if (result instanceof Promise) {
210
+ return result.then((resolved) => new Function(resolved.code)(runtime));
192
211
  }
193
- return new Function(code)(runtime);
212
+ return new Function(result.code)(runtime);
213
+ }
214
+ function readFrontmatter(handle) {
215
+ const raw = getMdastFrontmatter(handle);
216
+ return raw ? { kind: raw.kind === "toml" ? "toml" : "yaml", value: raw.value } : null;
194
217
  }
195
- // Pipeline: parse → mdast plugins → hast conversion → hast plugins
196
- // All arenas stay in Rust. No intermediate buffer copies to JS.
197
- /** Parse + mdast plugins + convert to HAST handle. */
218
+ /** Parse, run mdast plugins, capture frontmatter, then convert to HAST.
219
+ * Frontmatter is read from the post-plugin MDAST so visitor mutations to
220
+ * the yaml/toml node are reflected in the returned value. */
198
221
  function createHastHandleFromMdast(source, mdastPlugins, mdx, filename,
199
222
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
200
223
  nativeFeatures) {
201
- if (mdastPlugins.length === 0) {
202
- return mdx
203
- ? createMdxHastHandle(source, nativeFeatures)
204
- : createHastHandle(source, nativeFeatures);
205
- }
206
224
  const mdastHandle = mdx
207
225
  ? createMdxMdastHandle(source, nativeFeatures)
208
226
  : createMdastHandle(source, nativeFeatures);
209
- const mdastResult = runMdastPluginsOnHandle(mdastHandle, mdastPlugins, filename);
210
- const convert = (r) => {
211
- if (r.pendingCommands) {
212
- return applyCommandsAndConvertToHastHandle(r.handle, r.pendingCommands);
227
+ // finally{drop} is intentional: convertMdastToHastHandle empties the arena
228
+ // on success, but if any step here throws the handle would otherwise leak.
229
+ const finalize = (r) => {
230
+ try {
231
+ if (r.pendingCommands) {
232
+ applyCommandsToMdastHandle(r.handle, r.pendingCommands);
233
+ }
234
+ const frontmatter = readFrontmatter(r.handle);
235
+ const hastHandle = convertMdastToHastHandle(r.handle);
236
+ return { hastHandle, frontmatter };
237
+ }
238
+ finally {
239
+ dropHandle(r.handle);
213
240
  }
214
- return convertMdastToHastHandle(r.handle);
215
241
  };
216
- if (mdastResult instanceof Promise) {
217
- return mdastResult.then(convert);
242
+ try {
243
+ if (mdastPlugins.length === 0) {
244
+ return finalize({ handle: mdastHandle, pendingCommands: null });
245
+ }
246
+ const mdastResult = runMdastPluginsOnHandle(mdastHandle, mdastPlugins, filename);
247
+ if (mdastResult instanceof Promise) {
248
+ return mdastResult.then(finalize, (err) => {
249
+ dropHandle(mdastHandle);
250
+ throw err;
251
+ });
252
+ }
253
+ return finalize(mdastResult);
254
+ }
255
+ catch (err) {
256
+ dropHandle(mdastHandle);
257
+ throw err;
218
258
  }
219
- return convert(mdastResult);
220
259
  }
221
260
  // Step-by-step API: individual pipeline stages with materialized trees
222
261
  /** Parse Markdown source into a materialized mdast tree. */
223
262
  export function markdownToMdast(source, options = {}) {
224
263
  const handle = createMdastHandle(source, featuresToNative(options.features));
225
- const buf = serializeHandle(handle);
226
- dropHandle(handle);
227
- return materializeMdastTree(new MdastReader(buf));
264
+ try {
265
+ return materializeMdastTree(new MdastReader(serializeHandle(handle)));
266
+ }
267
+ finally {
268
+ dropHandle(handle);
269
+ }
228
270
  }
229
271
  /** Parse MDX source into a materialized mdast tree. */
230
272
  export function mdxToMdast(source, options = {}) {
231
273
  const handle = createMdxMdastHandle(source, featuresToNative(options.features));
232
- const buf = serializeHandle(handle);
233
- dropHandle(handle);
234
- return materializeMdastTree(new MdastReader(buf));
274
+ try {
275
+ return materializeMdastTree(new MdastReader(serializeHandle(handle)));
276
+ }
277
+ finally {
278
+ dropHandle(handle);
279
+ }
235
280
  }
236
281
  /** Convert Markdown source to a materialized hast tree. */
237
282
  export function markdownToHast(source, options = {}) {
238
283
  const handle = createHastHandle(source, featuresToNative(options.features));
239
- const buf = serializeHandle(handle);
240
- dropHandle(handle);
241
- return materializeHastTree(new HastReader(buf));
284
+ try {
285
+ return materializeHastTree(new HastReader(serializeHandle(handle)));
286
+ }
287
+ finally {
288
+ dropHandle(handle);
289
+ }
242
290
  }
243
291
  /** Convert MDX source to a materialized hast tree. */
244
292
  export function mdxToHast(source, options = {}) {
245
293
  const handle = createMdxHastHandle(source, featuresToNative(options.features));
246
- const buf = serializeHandle(handle);
247
- dropHandle(handle);
248
- return materializeHastTree(new HastReader(buf));
294
+ try {
295
+ return materializeHastTree(new HastReader(serializeHandle(handle)));
296
+ }
297
+ finally {
298
+ dropHandle(handle);
299
+ }
249
300
  }
@@ -382,6 +382,7 @@ function readMdxJsxFromBinary(view, buf, offset, nodeId, nodeType, resolver) {
382
382
  const node = { type: typeName, name, attributes };
383
383
  nodeIdMap.set(node, nodeId);
384
384
  makeLazyChildren(node, childIds, resolver);
385
+ resolver.attachLazyData(node, nodeId);
385
386
  return node;
386
387
  }
387
388
  function readMatchedNode(view, buf, offset, nodeId, nodeType, resolver) {
@@ -423,28 +424,31 @@ class LazyChildResolver {
423
424
  }
424
425
  materializeChildren(childIds) {
425
426
  const reader = this.#ensure();
426
- const handle = this.#handle;
427
427
  return childIds.map((id) => {
428
428
  const node = materializeHastNode(reader, id);
429
- // Override data with a lazy getter backed by the Rust arena's node_data.
430
- Object.defineProperty(node, "data", {
431
- get() {
432
- const json = napiGetNodeData(handle, id);
433
- const val = json ? JSON.parse(json) : null;
434
- Object.defineProperty(this, "data", {
435
- value: val,
436
- writable: true,
437
- enumerable: true,
438
- configurable: true,
439
- });
440
- return val;
441
- },
442
- configurable: true,
443
- enumerable: true,
444
- });
429
+ this.attachLazyData(node, id);
445
430
  return node;
446
431
  });
447
432
  }
433
+ /** Attach a lazy `data` getter backed by the Rust arena's node_data. */
434
+ attachLazyData(node, nodeId) {
435
+ const handle = this.#handle;
436
+ Object.defineProperty(node, "data", {
437
+ get() {
438
+ const json = napiGetNodeData(handle, nodeId);
439
+ const val = json ? JSON.parse(json) : null;
440
+ Object.defineProperty(this, "data", {
441
+ value: val,
442
+ writable: true,
443
+ enumerable: true,
444
+ configurable: true,
445
+ });
446
+ return val;
447
+ },
448
+ configurable: true,
449
+ enumerable: true,
450
+ });
451
+ }
448
452
  }
449
453
  /** Create a lazy `children` property backed by the handle. */
450
454
  function makeLazyChildren(node, childIds, resolver) {
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { markdownToHtml, mdxToJs, evaluate, markdownToMdast, mdxToMdast, markdownToHast, mdxToHast, } from "./compile.js";
2
- export type { CompileOptions, MdxCompileOptions, EvaluateOptions, OptimizeStaticConfig, Features, SmartPunctuationOptions, } from "./compile.js";
2
+ export type { CompileOptions, MdxCompileOptions, MdxOnlyOptions, EvaluateOptions, OptimizeStaticConfig, Features, SmartPunctuationOptions, Frontmatter, MarkdownToHtmlResult, MdxToJsResult, } from "./compile.js";
3
3
  export { defineMdastPlugin, defineHastPlugin } from "./plugin.js";
4
4
  export type { MdastPluginDefinition, HastPluginDefinition, MdastPluginInput, HastPluginInput, } from "./plugin.js";
5
5
  export type { HastVisitorInstance, HastVisitorContext, HastFilteredVisitor, EstreeProgram, } from "./hast/hast-visitor.js";
package/dist/plugin.d.ts CHANGED
@@ -16,5 +16,5 @@ export type MdastPluginInput = MdastPluginDefinition | (() => MdastPluginDefinit
16
16
  * or a factory called once per compile so closures reset per document.
17
17
  */
18
18
  export type HastPluginInput = HastPluginDefinition | (() => HastPluginDefinition);
19
- export declare function defineMdastPlugin(definition: MdastPluginDefinition): MdastPluginDefinition;
20
- export declare function defineHastPlugin(definition: HastPluginDefinition): HastPluginDefinition;
19
+ export declare function defineMdastPlugin<P extends MdastPluginDefinition>(definition: P): P;
20
+ export declare function defineHastPlugin<P extends HastPluginDefinition>(definition: P): P;
package/dist/plugin.js CHANGED
@@ -1,3 +1,6 @@
1
+ // Generic so the inferred plugin type preserves each visitor's *actual* return
2
+ // type. That lets call sites of `markdownToHtml`/`mdxToJs` distinguish sync
3
+ // plugins from async ones in their conditional return type.
1
4
  export function defineMdastPlugin(definition) {
2
5
  if (!definition.name) {
3
6
  throw new Error("Plugin definition must have a name");
package/index.d.ts CHANGED
@@ -48,6 +48,12 @@ export declare function dropHandle(handle: AnyHandle): void
48
48
  */
49
49
  export declare function getHandleSource(handle: AnyHandle): string
50
50
 
51
+ /**
52
+ * Return the first YAML or TOML frontmatter block in the MDAST arena, if any.
53
+ * Walks the root node's direct children and returns the first yaml/toml literal.
54
+ */
55
+ export declare function getMdastFrontmatter(handle: MdastHandle): JsFrontmatter | null
56
+
51
57
  /**
52
58
  * Read the node_data JSON blob for a node. Returns null if none is set.
53
59
  * Works for both MDAST and HAST handles.
@@ -78,6 +84,14 @@ export interface JsFeatures {
78
84
  smartPunctuationOptions?: JsSmartPunctuationOptions
79
85
  }
80
86
 
87
+ /** Frontmatter extracted from an MDAST arena. */
88
+ export interface JsFrontmatter {
89
+ /** Either `"yaml"` or `"toml"`. */
90
+ kind: string
91
+ /** Raw frontmatter content between the delimiters (no `---`/`+++` lines). */
92
+ value: string
93
+ }
94
+
81
95
  /** MDX compile options passed from JavaScript. */
82
96
  export interface JsMdxOptions {
83
97
  /**
@@ -169,9 +183,9 @@ export declare function parseToHtml(source: string, features?: JsFeatures | unde
169
183
  export declare function renderHandle(handle: HastHandle): string
170
184
 
171
185
  /**
172
- * Serialize a handle's arena to a binary buffer. Works for both MDAST
173
- * (read-only snapshot for the JS visitor) and HAST (fallback path for
174
- * `transformRoot`) — the kind tag is embedded in the buffer header.
186
+ * Serialize a handle's arena to the wire-format buffer JS instantiates a
187
+ * reader from. The kind tag in the header tells the JS side whether to
188
+ * pick `MdastReader` or `HastReader`.
175
189
  */
176
190
  export declare function serializeHandle(handle: AnyHandle): Uint8Array
177
191
 
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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
84
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
100
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
121
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
137
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
154
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
170
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
189
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
205
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
221
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
241
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
257
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
278
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
294
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
312
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
328
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
346
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
362
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
380
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
396
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
414
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
430
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
447
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
463
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
483
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
499
+ if (bindingPackageVersion !== '0.5.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.5.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.3.4' && 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.3.4 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
515
+ if (bindingPackageVersion !== '0.5.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.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`)
517
517
  }
518
518
  return binding
519
519
  } catch (e) {
@@ -562,6 +562,14 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
562
562
  }
563
563
  }
564
564
 
565
+ if (!nativeBinding && globalThis.process?.versions?.['webcontainer']) {
566
+ try {
567
+ nativeBinding = require('./webcontainer-fallback.cjs');
568
+ } catch (err) {
569
+ loadErrors.push(err)
570
+ }
571
+ }
572
+
565
573
  if (!nativeBinding) {
566
574
  if (loadErrors.length > 0) {
567
575
  throw new Error(
@@ -579,7 +587,7 @@ if (!nativeBinding) {
579
587
  throw new Error(`Failed to load native binding`)
580
588
  }
581
589
 
582
- const { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle } = nativeBinding
590
+ const { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle } = nativeBinding
583
591
  export { applyCommandsAndConvertToHastHandle }
584
592
  export { applyCommandsToHandle }
585
593
  export { applyCommandsToMdastHandle }
@@ -592,6 +600,7 @@ export { createMdxHastHandle }
592
600
  export { createMdxMdastHandle }
593
601
  export { dropHandle }
594
602
  export { getHandleSource }
603
+ export { getMdastFrontmatter }
595
604
  export { getNodeData }
596
605
  export { mdastTextContentHandle }
597
606
  export { parseEsm }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "satteri",
3
- "version": "0.4.0",
3
+ "version": "0.5.1",
4
4
  "description": "High-performance Markdown and MDX processing",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,8 @@
14
14
  "satteri_napi.wasi.cjs",
15
15
  "satteri_napi.wasi-browser.js",
16
16
  "wasi-worker.mjs",
17
- "wasi-worker-browser.mjs"
17
+ "wasi-worker-browser.mjs",
18
+ "webcontainer-fallback.cjs"
18
19
  ],
19
20
  "type": "module",
20
21
  "main": "./dist/index.js",
@@ -78,17 +79,21 @@
78
79
  ]
79
80
  },
80
81
  "optionalDependencies": {
81
- "@bruits/satteri-linux-x64-gnu": "0.4.0",
82
- "@bruits/satteri-darwin-x64": "0.4.0",
83
- "@bruits/satteri-darwin-arm64": "0.4.0",
84
- "@bruits/satteri-win32-x64-msvc": "0.4.0",
85
- "@bruits/satteri-wasm32-wasi": "0.4.0"
82
+ "@bruits/satteri-linux-x64-gnu": "0.5.1",
83
+ "@bruits/satteri-darwin-x64": "0.5.1",
84
+ "@bruits/satteri-darwin-arm64": "0.5.1",
85
+ "@bruits/satteri-win32-x64-msvc": "0.5.1",
86
+ "@bruits/satteri-wasm32-wasi": "0.5.1"
86
87
  },
87
88
  "scripts": {
88
89
  "build:wasm": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --target wasm32-wasip1-threads",
90
+ "postbuild:wasm": "node patch-binding.js",
89
91
  "build:native": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip",
92
+ "postbuild:native": "node patch-binding.js",
90
93
  "build:native:cross": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --cross-compile",
94
+ "postbuild:native:cross": "node patch-binding.js",
91
95
  "build:native:debug": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --esm",
96
+ "postbuild:native:debug": "node patch-binding.js",
92
97
  "build:ts": "tsc --project tsconfig.build.json",
93
98
  "build": "pnpm build:native && pnpm build:ts",
94
99
  "artifacts": "napi create-npm-dirs && napi artifacts",
@@ -69,6 +69,7 @@ export const createMdxHastHandle = __napiModule.exports.createMdxHastHandle
69
69
  export const createMdxMdastHandle = __napiModule.exports.createMdxMdastHandle
70
70
  export const dropHandle = __napiModule.exports.dropHandle
71
71
  export const getHandleSource = __napiModule.exports.getHandleSource
72
+ export const getMdastFrontmatter = __napiModule.exports.getMdastFrontmatter
72
73
  export const getNodeData = __napiModule.exports.getNodeData
73
74
  export const mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
74
75
  export const parseEsm = __napiModule.exports.parseEsm
@@ -120,6 +120,7 @@ module.exports.createMdxHastHandle = __napiModule.exports.createMdxHastHandle
120
120
  module.exports.createMdxMdastHandle = __napiModule.exports.createMdxMdastHandle
121
121
  module.exports.dropHandle = __napiModule.exports.dropHandle
122
122
  module.exports.getHandleSource = __napiModule.exports.getHandleSource
123
+ module.exports.getMdastFrontmatter = __napiModule.exports.getMdastFrontmatter
123
124
  module.exports.getNodeData = __napiModule.exports.getNodeData
124
125
  module.exports.mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
125
126
  module.exports.parseEsm = __napiModule.exports.parseEsm
@@ -0,0 +1,23 @@
1
+ // Adapted from https://github.com/rolldown/rolldown/blob/main/packages/rolldown/src/webcontainer-fallback.cjs
2
+
3
+ const fs = require("node:fs");
4
+ const childProcess = require("node:child_process");
5
+
6
+ const pkg = require("./package.json");
7
+ const version = pkg.version;
8
+
9
+ const baseDir = `/tmp/satteri-${version}`;
10
+ const bindingEntry = `${baseDir}/node_modules/@bruits/satteri-wasm32-wasi/satteri_napi.wasi.cjs`;
11
+
12
+ if (!fs.existsSync(bindingEntry)) {
13
+ const bindingPkg = `@bruits/satteri-wasm32-wasi@${version}`;
14
+ fs.rmSync(baseDir, { recursive: true, force: true });
15
+ fs.mkdirSync(baseDir, { recursive: true });
16
+ console.log(`[satteri] Downloading ${bindingPkg} on WebContainer...`);
17
+ childProcess.execFileSync("pnpm", ["i", bindingPkg], {
18
+ cwd: baseDir,
19
+ stdio: "inherit",
20
+ });
21
+ }
22
+
23
+ module.exports = require(bindingEntry);