satteri 0.9.3 → 0.9.5
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 +4 -12
- package/dist/binding.browser.d.ts +1 -1
- package/dist/binding.browser.js +1 -1
- package/dist/compile.js +8 -7
- package/dist/generated/arena-layout.d.ts +2 -2
- package/dist/generated/arena-layout.js +2 -2
- package/dist/hast/hast-reader.d.ts +3 -2
- package/dist/hast/hast-reader.js +13 -12
- package/dist/hast/hast-visitor.d.ts +8 -2
- package/dist/hast/hast-visitor.js +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/mdast/mdast-reader.d.ts +3 -1
- package/dist/mdast/mdast-reader.js +13 -11
- package/dist/mdast/mdast-visitor.d.ts +9 -3
- package/dist/mdast/mdast-visitor.js +10 -3
- package/dist/types.d.ts +8 -2
- package/package.json +11 -14
- package/satteri_napi.wasi-browser.js +0 -83
- package/satteri_napi.wasi.cjs +0 -134
- package/wasi-worker-browser.mjs +0 -36
- package/wasi-worker.mjs +0 -63
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Native-enhanced Markdown parsing and processing for JavaScript. Parse and compile in Rust, create flexible plugins in JavaScript.
|
|
4
4
|
|
|
5
|
+
Check out the [documentation](https://satteri.bruits.org/docs/) for [installation instructions](https://satteri.bruits.org/docs/installation/), the [API reference](https://satteri.bruits.org/docs/entry-points/), and [usage examples](https://satteri.bruits.org/docs/quick-start/), try it online on the [playground](https://satteri.bruits.org/playground), or join us on [Discord](https://discord.com/invite/84pd4QtmzA)!
|
|
6
|
+
|
|
5
7
|
## Install
|
|
6
8
|
|
|
7
9
|
```sh
|
|
@@ -51,16 +53,6 @@ const { html } = markdownToHtml("Use `let` instead of `var`.", {
|
|
|
51
53
|
|
|
52
54
|
If you're familiar with the unified ecosystem, mdast and hast plugins are similar to remark and rehype plugins, respectively, reusing the same AST shapes.
|
|
53
55
|
|
|
54
|
-
##
|
|
55
|
-
|
|
56
|
-
This README covers the basics. The full documentation covers the complete API, the plugin system, every parser feature, and framework integration:
|
|
57
|
-
|
|
58
|
-
- **[Documentation home](https://satteri.bruits.org/docs/)** — start here
|
|
59
|
-
- [Quick start](https://satteri.bruits.org/docs/quick-start/)
|
|
60
|
-
- [Compiling](https://satteri.bruits.org/docs/compile/) — functions, options, and MDX settings
|
|
61
|
-
- [Plugins](https://satteri.bruits.org/docs/plugins/) and [Plugin API](https://satteri.bruits.org/docs/plugin-api/)
|
|
62
|
-
- [Features](https://satteri.bruits.org/docs/features/) — GFM, math, directives, and more
|
|
63
|
-
|
|
64
|
-
## License
|
|
56
|
+
## Development
|
|
65
57
|
|
|
66
|
-
|
|
58
|
+
Refer to [CONTRIBUTING.md](https://github.com/bruits/satteri/blob/main/CONTRIBUTING.md) for development setup and workflow details.
|
|
@@ -1 +1 @@
|
|
|
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 "../
|
|
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 "../browser.js";
|
package/dist/binding.browser.js
CHANGED
|
@@ -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, getMdastFrontmatter, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../
|
|
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 "../browser.js";
|
package/dist/compile.js
CHANGED
|
@@ -89,7 +89,7 @@ function warnDroppedTransforms(plugin, dropped, kind) {
|
|
|
89
89
|
console.warn(`satteri: plugin "${name}" queued ${dropped} ${kind} ${noun} on node(s) that were removed or ` +
|
|
90
90
|
`replaced earlier in the same pass; ${dropped === 1 ? "it was" : "they were"} dropped.`);
|
|
91
91
|
}
|
|
92
|
-
function runMdastPluginsOnHandle(handle, plugins, fileURL, data) {
|
|
92
|
+
function runMdastPluginsOnHandle(handle, plugins, fileURL, data, sourceFormat) {
|
|
93
93
|
// Each plugin runs once over the tree. A transform that passes a child
|
|
94
94
|
// through (returning it inside the replacement) keeps that child's identity,
|
|
95
95
|
// so a patch the same pass queued on it still applies — nesting composes in
|
|
@@ -97,7 +97,7 @@ function runMdastPluginsOnHandle(handle, plugins, fileURL, data) {
|
|
|
97
97
|
// them up front, or hand off to a later plugin that sees the materialized tree.
|
|
98
98
|
const runPlugin = (plugin) => {
|
|
99
99
|
const subs = resolveMdastSubscriptions(plugin);
|
|
100
|
-
const result = visitMdastHandle(handle, plugin, subs, () => getHandleSource(handle), fileURL, data);
|
|
100
|
+
const result = visitMdastHandle(handle, plugin, subs, () => getHandleSource(handle), fileURL, data, sourceFormat);
|
|
101
101
|
const apply = (r) => {
|
|
102
102
|
if (!r.hasMutations)
|
|
103
103
|
return;
|
|
@@ -121,7 +121,7 @@ function runMdastPluginsOnHandle(handle, plugins, fileURL, data) {
|
|
|
121
121
|
};
|
|
122
122
|
return runNext();
|
|
123
123
|
}
|
|
124
|
-
function runHastPluginsOnHandle(handle, plugins, source, fileURL, data) {
|
|
124
|
+
function runHastPluginsOnHandle(handle, plugins, source, fileURL, data, sourceFormat) {
|
|
125
125
|
if (plugins.length === 0)
|
|
126
126
|
return;
|
|
127
127
|
let i = 0;
|
|
@@ -131,7 +131,7 @@ function runHastPluginsOnHandle(handle, plugins, source, fileURL, data) {
|
|
|
131
131
|
i++;
|
|
132
132
|
const plugin = typeof raw === "function" ? raw() : raw;
|
|
133
133
|
const subs = resolveSubscriptions(plugin);
|
|
134
|
-
const result = visitHastHandle(handle, plugin, subs, source, fileURL, data);
|
|
134
|
+
const result = visitHastHandle(handle, plugin, subs, source, fileURL, data, sourceFormat);
|
|
135
135
|
const warnIfDropped = (dropped) => {
|
|
136
136
|
if (dropped)
|
|
137
137
|
warnDroppedTransforms(plugin, dropped, "hast");
|
|
@@ -207,7 +207,7 @@ export function markdownToHtml(source, options = {}) {
|
|
|
207
207
|
const runHastThenRender = (r) => {
|
|
208
208
|
let hastResult;
|
|
209
209
|
try {
|
|
210
|
-
hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, fileURL, data);
|
|
210
|
+
hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, fileURL, data, "markdown");
|
|
211
211
|
}
|
|
212
212
|
catch (err) {
|
|
213
213
|
releaseHandle(r.hastHandle, hastMayHaveStubs);
|
|
@@ -243,7 +243,7 @@ export function mdxToJs(source, options = {}) {
|
|
|
243
243
|
const runHastThenCompile = (r) => {
|
|
244
244
|
let hastResult;
|
|
245
245
|
try {
|
|
246
|
-
hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, fileURL, data);
|
|
246
|
+
hastResult = runHastPluginsOnHandle(r.hastHandle, hastPlugins, source, fileURL, data, "mdx");
|
|
247
247
|
}
|
|
248
248
|
catch (err) {
|
|
249
249
|
releaseHandle(r.hastHandle, hastMayHaveStubs);
|
|
@@ -296,6 +296,7 @@ nativeConvertOptions, data) {
|
|
|
296
296
|
const mdastHandle = mdx
|
|
297
297
|
? createMdxMdastHandle(source, nativeFeatures)
|
|
298
298
|
: createMdastHandle(source, nativeFeatures);
|
|
299
|
+
const sourceFormat = mdx ? "mdx" : "markdown";
|
|
299
300
|
const mdastMayHaveStubs = mdastPlugins.length > 0;
|
|
300
301
|
// finally{release} is intentional: convertMdastToHastHandle empties the arena
|
|
301
302
|
// on success, but if any step here throws the handle would otherwise leak.
|
|
@@ -316,7 +317,7 @@ nativeConvertOptions, data) {
|
|
|
316
317
|
if (mdastPlugins.length === 0) {
|
|
317
318
|
return finalize({ handle: mdastHandle });
|
|
318
319
|
}
|
|
319
|
-
const mdastResult = runMdastPluginsOnHandle(mdastHandle, mdastPlugins, fileURL, data);
|
|
320
|
+
const mdastResult = runMdastPluginsOnHandle(mdastHandle, mdastPlugins, fileURL, data, sourceFormat);
|
|
320
321
|
if (mdastResult instanceof Promise) {
|
|
321
322
|
return mdastResult.then(finalize, (err) => {
|
|
322
323
|
releaseHandle(mdastHandle, mdastMayHaveStubs);
|
|
@@ -30,8 +30,8 @@ export declare const HEADER: {
|
|
|
30
30
|
readonly children_offset: 24;
|
|
31
31
|
readonly type_data_len: 28;
|
|
32
32
|
readonly type_data_offset: 32;
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
33
|
+
readonly string_pool_len: 36;
|
|
34
|
+
readonly string_pool_offset: 40;
|
|
35
35
|
readonly node_data_count: 44;
|
|
36
36
|
readonly node_data_offset: 48;
|
|
37
37
|
};
|
|
@@ -29,8 +29,9 @@ export declare class HastReader {
|
|
|
29
29
|
getNodeData(nodeId: number): string | null;
|
|
30
30
|
get nodeCount(): number;
|
|
31
31
|
get header(): BufferHeader;
|
|
32
|
-
/**
|
|
33
|
-
|
|
32
|
+
/** The full string pool (original input + interning heap). Not the document
|
|
33
|
+
* source as written; for that, read `ctx.source` from a plugin. */
|
|
34
|
+
getStringPool(): string;
|
|
34
35
|
/** Read a substring from the string pool by byte offset and length. */
|
|
35
36
|
getString(offset: number, len: number): string;
|
|
36
37
|
/** Get position data for a node. */
|
package/dist/hast/hast-reader.js
CHANGED
|
@@ -19,7 +19,7 @@ export class HastReader {
|
|
|
19
19
|
#view;
|
|
20
20
|
#header;
|
|
21
21
|
#textDecoder;
|
|
22
|
-
#
|
|
22
|
+
#stringPoolCache = null;
|
|
23
23
|
constructor(buffer) {
|
|
24
24
|
if (buffer instanceof Uint8Array) {
|
|
25
25
|
this.#view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
@@ -49,8 +49,8 @@ export class HastReader {
|
|
|
49
49
|
childrenOffset: v.getUint32(HEADER.children_offset, true),
|
|
50
50
|
typeDataLen: v.getUint32(HEADER.type_data_len, true),
|
|
51
51
|
typeDataOffset: v.getUint32(HEADER.type_data_offset, true),
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
stringPoolLen: v.getUint32(HEADER.string_pool_len, true),
|
|
53
|
+
stringPoolOffset: v.getUint32(HEADER.string_pool_offset, true),
|
|
54
54
|
nodeDataCount: v.getUint32(HEADER.node_data_count, true),
|
|
55
55
|
nodeDataOffset: v.getUint32(HEADER.node_data_offset, true),
|
|
56
56
|
};
|
|
@@ -87,21 +87,22 @@ export class HastReader {
|
|
|
87
87
|
get header() {
|
|
88
88
|
return { ...this.#header };
|
|
89
89
|
}
|
|
90
|
-
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
90
|
+
/** The full string pool (original input + interning heap). Not the document
|
|
91
|
+
* source as written; for that, read `ctx.source` from a plugin. */
|
|
92
|
+
getStringPool() {
|
|
93
|
+
if (this.#stringPoolCache === null) {
|
|
94
|
+
const { stringPoolOffset, stringPoolLen } = this.#header;
|
|
95
|
+
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset + stringPoolOffset, stringPoolLen);
|
|
96
|
+
this.#stringPoolCache = this.#textDecoder.decode(bytes);
|
|
96
97
|
}
|
|
97
|
-
return this.#
|
|
98
|
+
return this.#stringPoolCache;
|
|
98
99
|
}
|
|
99
100
|
/** Read a substring from the string pool by byte offset and length. */
|
|
100
101
|
getString(offset, len) {
|
|
101
102
|
if (len === 0)
|
|
102
103
|
return "";
|
|
103
|
-
const {
|
|
104
|
-
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset +
|
|
104
|
+
const { stringPoolOffset } = this.#header;
|
|
105
|
+
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset + stringPoolOffset + offset, len);
|
|
105
106
|
return this.#textDecoder.decode(bytes);
|
|
106
107
|
}
|
|
107
108
|
/** Get position data for a node. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HastNode } from "./hast-materializer.js";
|
|
2
|
-
import type { HastRaw, Data } from "../types.js";
|
|
2
|
+
import type { HastRaw, Data, SourceFormat } from "../types.js";
|
|
3
3
|
import type { Element, Text, Comment, Doctype, Parents as HastParents, Root as HastRoot } from "hast";
|
|
4
4
|
import type { Program } from "estree-jsx";
|
|
5
5
|
import type { MdxJsxFlowElementHast, MdxJsxTextElementHast } from "../mdx-types.js";
|
|
@@ -30,6 +30,12 @@ export interface HastVisitorContext {
|
|
|
30
30
|
* instances. Returned to the caller as `result.data`.
|
|
31
31
|
*/
|
|
32
32
|
readonly data: Data;
|
|
33
|
+
/**
|
|
34
|
+
* The source format this compile is processing: `"markdown"` for a plain
|
|
35
|
+
* Markdown compile, `"mdx"` for an MDX one. Lets a plugin shared between both
|
|
36
|
+
* pipelines branch on which it is handling.
|
|
37
|
+
*/
|
|
38
|
+
readonly sourceFormat: SourceFormat;
|
|
33
39
|
removeNode(node: Readonly<HastNode>): void;
|
|
34
40
|
replaceNode(node: Readonly<HastNode>, newNode: HastContent): void;
|
|
35
41
|
insertBefore(node: Readonly<HastNode>, newNode: HastContent | HastContent[]): void;
|
|
@@ -109,4 +115,4 @@ export declare function resolveSubscriptions(plugin: HastVisitorInstance): Resol
|
|
|
109
115
|
* replaced earlier in the same pass (the caller warns when non-zero), or a
|
|
110
116
|
* Promise of that count if any visitor is async.
|
|
111
117
|
*/
|
|
112
|
-
export declare function visitHastHandle(handle: HastHandle, plugin: HastVisitorInstance, subs: ResolvedSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data): number | Promise<number>;
|
|
118
|
+
export declare function visitHastHandle(handle: HastHandle, plugin: HastVisitorInstance, subs: ResolvedSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data, sourceFormat?: SourceFormat): number | Promise<number>;
|
|
@@ -200,12 +200,14 @@ class HastVisitorContextImpl {
|
|
|
200
200
|
#parentsById = null;
|
|
201
201
|
fileURL;
|
|
202
202
|
data;
|
|
203
|
-
|
|
203
|
+
sourceFormat;
|
|
204
|
+
constructor(handle, getSource, fileURL, resolver, data, sourceFormat) {
|
|
204
205
|
this.#handle = handle;
|
|
205
206
|
this.#getSource = getSource;
|
|
206
207
|
this.fileURL = fileURL;
|
|
207
208
|
this.#resolver = resolver;
|
|
208
209
|
this.data = data;
|
|
210
|
+
this.sourceFormat = sourceFormat;
|
|
209
211
|
}
|
|
210
212
|
get source() {
|
|
211
213
|
const value = this.#getSource();
|
|
@@ -691,10 +693,10 @@ function dispatchMatches(matchBuf, subs, ctx, returnBuffer, resolver) {
|
|
|
691
693
|
* replaced earlier in the same pass (the caller warns when non-zero), or a
|
|
692
694
|
* Promise of that count if any visitor is async.
|
|
693
695
|
*/
|
|
694
|
-
export function visitHastHandle(handle, plugin, subs, source, fileURL, data = {}) {
|
|
696
|
+
export function visitHastHandle(handle, plugin, subs, source, fileURL, data = {}, sourceFormat = "markdown") {
|
|
695
697
|
const getSource = typeof source === "function" ? source : () => source;
|
|
696
698
|
const resolver = new HastLazyChildResolver(handle);
|
|
697
|
-
const ctx = new HastVisitorContextImpl(handle, getSource, fileURL, resolver, data);
|
|
699
|
+
const ctx = new HastVisitorContextImpl(handle, getSource, fileURL, resolver, data, sourceFormat);
|
|
698
700
|
const returnBuffer = new CommandBuffer();
|
|
699
701
|
const rustSubs = subs.map((s) => ({ nodeType: s.nodeType, tagFilter: s.tagFilter }));
|
|
700
702
|
const deferred = dispatchMatches(walkHandle(handle, rustSubs), subs, ctx, returnBuffer, resolver);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export type { CompileOptions, MdxCompileOptions, MdxOnlyOptions, EvaluateOptions
|
|
|
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, HastContent, EstreeProgram, } from "./hast/hast-visitor.js";
|
|
6
|
-
export type { MdastNode, HastNode, DataMap, Data, Position, Point, MdxJsxAttributeNode, MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpressionNode, MdxJsxAttributeUnion, MdxJsxFlowElement, MdxJsxTextElement, MdxFlowExpression, MdxTextExpression, MdxjsEsm, MdxJsxFlowElementHast, MdxJsxTextElementHast, MdxFlowExpressionHast, MdxTextExpressionHast, MdxjsEsmHast, } from "./types.js";
|
|
6
|
+
export type { MdastNode, HastNode, DataMap, Data, SourceFormat, Position, Point, MdxJsxAttributeNode, MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpressionNode, MdxJsxAttributeUnion, MdxJsxFlowElement, MdxJsxTextElement, MdxFlowExpression, MdxTextExpression, MdxjsEsm, MdxJsxFlowElementHast, MdxJsxTextElementHast, MdxFlowExpressionHast, MdxTextExpressionHast, MdxjsEsmHast, } from "./types.js";
|
|
7
7
|
export { visitMdastHandle, resolveMdastSubscriptions } from "./mdast/mdast-visitor.js";
|
|
8
|
-
export type { MdastPluginInstance, MdastContent } from "./mdast/mdast-visitor.js";
|
|
8
|
+
export type { MdastPluginInstance, MdastVisitorContext, MdastContent, } from "./mdast/mdast-visitor.js";
|
|
9
9
|
export { visitHastHandle, resolveSubscriptions as resolveHastSubscriptions, } from "./hast/hast-visitor.js";
|
|
10
10
|
export { MdastReader } from "./mdast/mdast-reader.js";
|
|
11
11
|
export { materializeMdastTree } from "./mdast/mdast-materializer.js";
|
|
@@ -9,7 +9,9 @@ export declare class MdastReader {
|
|
|
9
9
|
getNodeData(nodeId: number): string | null;
|
|
10
10
|
get nodeCount(): number;
|
|
11
11
|
get header(): BufferHeader;
|
|
12
|
-
|
|
12
|
+
/** The full string pool (original input + interning heap). Not the document
|
|
13
|
+
* source as written; for that, read `ctx.source` from a plugin. */
|
|
14
|
+
getStringPool(): string;
|
|
13
15
|
getString(offset: number, len: number): string;
|
|
14
16
|
getNode(nodeId: number): MdastNodeRaw;
|
|
15
17
|
/** Fast path: read only the type byte for a node. */
|
|
@@ -8,7 +8,7 @@ export class MdastReader {
|
|
|
8
8
|
#view;
|
|
9
9
|
#header;
|
|
10
10
|
#textDecoder;
|
|
11
|
-
#
|
|
11
|
+
#stringPoolCache = null;
|
|
12
12
|
constructor(buffer) {
|
|
13
13
|
if (buffer instanceof Uint8Array) {
|
|
14
14
|
this.#view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
@@ -38,8 +38,8 @@ export class MdastReader {
|
|
|
38
38
|
childrenOffset: v.getUint32(HEADER.children_offset, true),
|
|
39
39
|
typeDataLen: v.getUint32(HEADER.type_data_len, true),
|
|
40
40
|
typeDataOffset: v.getUint32(HEADER.type_data_offset, true),
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
stringPoolLen: v.getUint32(HEADER.string_pool_len, true),
|
|
42
|
+
stringPoolOffset: v.getUint32(HEADER.string_pool_offset, true),
|
|
43
43
|
nodeDataCount: v.getUint32(HEADER.node_data_count, true),
|
|
44
44
|
nodeDataOffset: v.getUint32(HEADER.node_data_offset, true),
|
|
45
45
|
};
|
|
@@ -73,19 +73,21 @@ export class MdastReader {
|
|
|
73
73
|
get header() {
|
|
74
74
|
return { ...this.#header };
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
/** The full string pool (original input + interning heap). Not the document
|
|
77
|
+
* source as written; for that, read `ctx.source` from a plugin. */
|
|
78
|
+
getStringPool() {
|
|
79
|
+
if (this.#stringPoolCache === null) {
|
|
80
|
+
const { stringPoolOffset, stringPoolLen } = this.#header;
|
|
81
|
+
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset + stringPoolOffset, stringPoolLen);
|
|
82
|
+
this.#stringPoolCache = this.#textDecoder.decode(bytes);
|
|
81
83
|
}
|
|
82
|
-
return this.#
|
|
84
|
+
return this.#stringPoolCache;
|
|
83
85
|
}
|
|
84
86
|
getString(offset, len) {
|
|
85
87
|
if (len === 0)
|
|
86
88
|
return "";
|
|
87
|
-
const {
|
|
88
|
-
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset +
|
|
89
|
+
const { stringPoolOffset } = this.#header;
|
|
90
|
+
const bytes = new Uint8Array(this.#view.buffer, this.#view.byteOffset + stringPoolOffset + offset, len);
|
|
89
91
|
return this.#textDecoder.decode(bytes);
|
|
90
92
|
}
|
|
91
93
|
getNode(nodeId) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MdastReader } from "./mdast-reader.js";
|
|
2
2
|
import { CommandBuffer } from "../command-buffer.js";
|
|
3
|
-
import type { MdastNode, Toml, MathNode, InlineMath, Superscript, Subscript, Data } from "../types.js";
|
|
3
|
+
import type { MdastNode, Toml, MathNode, InlineMath, Superscript, Subscript, Data, SourceFormat } from "../types.js";
|
|
4
4
|
import { LazyChildResolver } from "../lazy-child-resolver.js";
|
|
5
5
|
import type { MdastHandle } from "../handles.js";
|
|
6
6
|
import type { 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, Parents as MdastParents, Root as MdastRoot } from "mdast";
|
|
@@ -38,7 +38,13 @@ export declare class MdastVisitorContext {
|
|
|
38
38
|
* instances. Returned to the caller as `result.data`.
|
|
39
39
|
*/
|
|
40
40
|
readonly data: Data;
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
|
+
* The source format this compile is processing: `"markdown"` for a plain
|
|
43
|
+
* Markdown compile, `"mdx"` for an MDX one. Lets a plugin shared between both
|
|
44
|
+
* pipelines branch on which it is handling.
|
|
45
|
+
*/
|
|
46
|
+
readonly sourceFormat: SourceFormat;
|
|
47
|
+
constructor(handle: MdastHandle, getSource: () => string, fileURL: URL | undefined, resolver: LazyChildResolver<MdastReader, MdastNode>, data: Data, sourceFormat: SourceFormat);
|
|
42
48
|
get source(): string;
|
|
43
49
|
removeNode(node: Readonly<MdastNode>): void;
|
|
44
50
|
insertBefore(node: Readonly<MdastNode>, newNode: MdastContent | MdastContent[]): void;
|
|
@@ -154,4 +160,4 @@ export declare function resolveMdastSubscriptions(plugin: MdastPluginInstance):
|
|
|
154
160
|
* Returns MdastVisitResult synchronously if all visitors are sync,
|
|
155
161
|
* or Promise<MdastVisitResult> if any visitor is async.
|
|
156
162
|
*/
|
|
157
|
-
export declare function visitMdastHandle(handle: MdastHandle, plugin: MdastPluginInstance, subs: MdastSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data): MdastVisitResult | Promise<MdastVisitResult>;
|
|
163
|
+
export declare function visitMdastHandle(handle: MdastHandle, plugin: MdastPluginInstance, subs: MdastSubscription[], source: string | (() => string), fileURL: URL | undefined, data?: Data, sourceFormat?: SourceFormat): MdastVisitResult | Promise<MdastVisitResult>;
|
|
@@ -49,12 +49,19 @@ export class MdastVisitorContext {
|
|
|
49
49
|
* instances. Returned to the caller as `result.data`.
|
|
50
50
|
*/
|
|
51
51
|
data;
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* The source format this compile is processing: `"markdown"` for a plain
|
|
54
|
+
* Markdown compile, `"mdx"` for an MDX one. Lets a plugin shared between both
|
|
55
|
+
* pipelines branch on which it is handling.
|
|
56
|
+
*/
|
|
57
|
+
sourceFormat;
|
|
58
|
+
constructor(handle, getSource, fileURL, resolver, data, sourceFormat) {
|
|
53
59
|
this.#handle = handle;
|
|
54
60
|
this.#getSource = getSource;
|
|
55
61
|
this.fileURL = fileURL;
|
|
56
62
|
this.#resolver = resolver;
|
|
57
63
|
this.data = data;
|
|
64
|
+
this.sourceFormat = sourceFormat;
|
|
58
65
|
}
|
|
59
66
|
get source() {
|
|
60
67
|
const value = this.#getSource();
|
|
@@ -525,10 +532,10 @@ function applyMdastVisitResult(result, nodeId, returnBuffer, originalNode) {
|
|
|
525
532
|
* Returns MdastVisitResult synchronously if all visitors are sync,
|
|
526
533
|
* or Promise<MdastVisitResult> if any visitor is async.
|
|
527
534
|
*/
|
|
528
|
-
export function visitMdastHandle(handle, plugin, subs, source, fileURL, data = {}) {
|
|
535
|
+
export function visitMdastHandle(handle, plugin, subs, source, fileURL, data = {}, sourceFormat = "markdown") {
|
|
529
536
|
const getSource = typeof source === "function" ? source : () => source;
|
|
530
537
|
const resolver = new MdastLazyChildResolver(handle);
|
|
531
|
-
const context = new MdastVisitorContext(handle, getSource, fileURL, resolver, data);
|
|
538
|
+
const context = new MdastVisitorContext(handle, getSource, fileURL, resolver, data, sourceFormat);
|
|
532
539
|
const returnBuffer = new CommandBuffer();
|
|
533
540
|
const rustSubs = subs.map((s) => ({ nodeType: s.nodeType, tagFilter: [] }));
|
|
534
541
|
const matchBuf = walkMdastHandle(handle, rustSubs);
|
package/dist/types.d.ts
CHANGED
|
@@ -86,6 +86,12 @@ export interface DataMap {
|
|
|
86
86
|
* string key holding any value, plus the typed keys registered in {@link DataMap}.
|
|
87
87
|
*/
|
|
88
88
|
export type Data = Record<string, unknown> & Partial<DataMap>;
|
|
89
|
+
/**
|
|
90
|
+
* The source format a plugin is running against, surfaced as `ctx.sourceFormat`:
|
|
91
|
+
* `"markdown"` for a plain Markdown compile, `"mdx"` for an MDX one. Lets a
|
|
92
|
+
* plugin shared between both pipelines branch on which it is handling.
|
|
93
|
+
*/
|
|
94
|
+
export type SourceFormat = "markdown" | "mdx";
|
|
89
95
|
export interface StringRefRaw {
|
|
90
96
|
offset: number;
|
|
91
97
|
len: number;
|
|
@@ -109,8 +115,8 @@ export interface BufferHeader {
|
|
|
109
115
|
childrenOffset: number;
|
|
110
116
|
typeDataLen: number;
|
|
111
117
|
typeDataOffset: number;
|
|
112
|
-
|
|
113
|
-
|
|
118
|
+
stringPoolLen: number;
|
|
119
|
+
stringPoolOffset: number;
|
|
114
120
|
/** Number of nodes that carry an extra JSON `data` blob. */
|
|
115
121
|
nodeDataCount: number;
|
|
116
122
|
/** Offset of the node-data section: `[id u32][len u32][bytes...]` repeated. */
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "satteri",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"description": "High-performance Markdown and MDX processing",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
7
8
|
"url": "git+https://github.com/bruits/satteri.git"
|
|
@@ -11,10 +12,6 @@
|
|
|
11
12
|
"browser.js",
|
|
12
13
|
"index.js",
|
|
13
14
|
"index.d.ts",
|
|
14
|
-
"satteri_napi.wasi.cjs",
|
|
15
|
-
"satteri_napi.wasi-browser.js",
|
|
16
|
-
"wasi-worker.mjs",
|
|
17
|
-
"wasi-worker-browser.mjs",
|
|
18
15
|
"webcontainer-fallback.cjs"
|
|
19
16
|
],
|
|
20
17
|
"type": "module",
|
|
@@ -84,15 +81,15 @@
|
|
|
84
81
|
]
|
|
85
82
|
},
|
|
86
83
|
"optionalDependencies": {
|
|
87
|
-
"@bruits/satteri-linux-x64-gnu": "0.9.
|
|
88
|
-
"@bruits/satteri-linux-arm64-gnu": "0.9.
|
|
89
|
-
"@bruits/satteri-linux-x64-musl": "0.9.
|
|
90
|
-
"@bruits/satteri-linux-arm64-musl": "0.9.
|
|
91
|
-
"@bruits/satteri-darwin-x64": "0.9.
|
|
92
|
-
"@bruits/satteri-darwin-arm64": "0.9.
|
|
93
|
-
"@bruits/satteri-win32-x64-msvc": "0.9.
|
|
94
|
-
"@bruits/satteri-win32-arm64-msvc": "0.9.
|
|
95
|
-
"@bruits/satteri-wasm32-wasi": "0.9.
|
|
84
|
+
"@bruits/satteri-linux-x64-gnu": "0.9.5",
|
|
85
|
+
"@bruits/satteri-linux-arm64-gnu": "0.9.5",
|
|
86
|
+
"@bruits/satteri-linux-x64-musl": "0.9.5",
|
|
87
|
+
"@bruits/satteri-linux-arm64-musl": "0.9.5",
|
|
88
|
+
"@bruits/satteri-darwin-x64": "0.9.5",
|
|
89
|
+
"@bruits/satteri-darwin-arm64": "0.9.5",
|
|
90
|
+
"@bruits/satteri-win32-x64-msvc": "0.9.5",
|
|
91
|
+
"@bruits/satteri-win32-arm64-msvc": "0.9.5",
|
|
92
|
+
"@bruits/satteri-wasm32-wasi": "0.9.5"
|
|
96
93
|
},
|
|
97
94
|
"scripts": {
|
|
98
95
|
"build:binary:wasm": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --target wasm32-wasip1-threads",
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createOnMessage as __wasmCreateOnMessageForFsProxy,
|
|
3
|
-
getDefaultContext as __emnapiGetDefaultContext,
|
|
4
|
-
instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync,
|
|
5
|
-
WASI as __WASI,
|
|
6
|
-
} from '@napi-rs/wasm-runtime'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const __wasi = new __WASI({
|
|
11
|
-
version: 'preview1',
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const __wasmUrl = new URL('./satteri_napi.wasm32-wasi.wasm', import.meta.url).href
|
|
15
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const __sharedMemory = new WebAssembly.Memory({
|
|
19
|
-
initial: 4000,
|
|
20
|
-
maximum: 65536,
|
|
21
|
-
shared: true,
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
const __wasmFile = await fetch(__wasmUrl).then((res) => res.arrayBuffer())
|
|
25
|
-
|
|
26
|
-
const {
|
|
27
|
-
instance: __napiInstance,
|
|
28
|
-
module: __wasiModule,
|
|
29
|
-
napiModule: __napiModule,
|
|
30
|
-
} = __emnapiInstantiateNapiModuleSync(__wasmFile, {
|
|
31
|
-
context: __emnapiContext,
|
|
32
|
-
asyncWorkPoolSize: 4,
|
|
33
|
-
wasi: __wasi,
|
|
34
|
-
onCreateWorker() {
|
|
35
|
-
const worker = new Worker(new URL('./wasi-worker-browser.mjs', import.meta.url), {
|
|
36
|
-
type: 'module',
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return worker
|
|
41
|
-
},
|
|
42
|
-
overwriteImports(importObject) {
|
|
43
|
-
importObject.env = {
|
|
44
|
-
...importObject.env,
|
|
45
|
-
...importObject.napi,
|
|
46
|
-
...importObject.emnapi,
|
|
47
|
-
memory: __sharedMemory,
|
|
48
|
-
}
|
|
49
|
-
return importObject
|
|
50
|
-
},
|
|
51
|
-
beforeInit({ instance }) {
|
|
52
|
-
for (const name of Object.keys(instance.exports)) {
|
|
53
|
-
if (name.startsWith('__napi_register__')) {
|
|
54
|
-
instance.exports[name]()
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
})
|
|
59
|
-
export default __napiModule.exports
|
|
60
|
-
export const applyCommandsAndConvertToHastHandle = __napiModule.exports.applyCommandsAndConvertToHastHandle
|
|
61
|
-
export const applyCommandsToHandle = __napiModule.exports.applyCommandsToHandle
|
|
62
|
-
export const applyCommandsToMdastHandle = __napiModule.exports.applyCommandsToMdastHandle
|
|
63
|
-
export const compileHandle = __napiModule.exports.compileHandle
|
|
64
|
-
export const compileMdx = __napiModule.exports.compileMdx
|
|
65
|
-
export const convertMdastToHastHandle = __napiModule.exports.convertMdastToHastHandle
|
|
66
|
-
export const createHastHandle = __napiModule.exports.createHastHandle
|
|
67
|
-
export const createMdastHandle = __napiModule.exports.createMdastHandle
|
|
68
|
-
export const createMdxHastHandle = __napiModule.exports.createMdxHastHandle
|
|
69
|
-
export const createMdxMdastHandle = __napiModule.exports.createMdxMdastHandle
|
|
70
|
-
export const dropHandle = __napiModule.exports.dropHandle
|
|
71
|
-
export const getHandleSource = __napiModule.exports.getHandleSource
|
|
72
|
-
export const getMdastFrontmatter = __napiModule.exports.getMdastFrontmatter
|
|
73
|
-
export const getNodeData = __napiModule.exports.getNodeData
|
|
74
|
-
export const mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
|
|
75
|
-
export const parseEsm = __napiModule.exports.parseEsm
|
|
76
|
-
export const parseExpression = __napiModule.exports.parseExpression
|
|
77
|
-
export const parseToHtml = __napiModule.exports.parseToHtml
|
|
78
|
-
export const renderHandle = __napiModule.exports.renderHandle
|
|
79
|
-
export const serializeHandle = __napiModule.exports.serializeHandle
|
|
80
|
-
export const setNodeData = __napiModule.exports.setNodeData
|
|
81
|
-
export const textContentHandle = __napiModule.exports.textContentHandle
|
|
82
|
-
export const walkHandle = __napiModule.exports.walkHandle
|
|
83
|
-
export const walkMdastHandle = __napiModule.exports.walkMdastHandle
|
package/satteri_napi.wasi.cjs
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
/* prettier-ignore */
|
|
3
|
-
|
|
4
|
-
/* auto-generated by NAPI-RS */
|
|
5
|
-
|
|
6
|
-
const __nodeFs = require('node:fs')
|
|
7
|
-
const __nodePath = require('node:path')
|
|
8
|
-
const { WASI: __nodeWASI } = require('node:wasi')
|
|
9
|
-
const { Worker } = require('node:worker_threads')
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
createOnMessage: __wasmCreateOnMessageForFsProxy,
|
|
13
|
-
getDefaultContext: __emnapiGetDefaultContext,
|
|
14
|
-
instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
|
|
15
|
-
} = require('@napi-rs/wasm-runtime')
|
|
16
|
-
|
|
17
|
-
const __rootDir = __nodePath.parse(process.cwd()).root
|
|
18
|
-
|
|
19
|
-
const __wasi = new __nodeWASI({
|
|
20
|
-
version: 'preview1',
|
|
21
|
-
env: process.env,
|
|
22
|
-
preopens: {
|
|
23
|
-
[__rootDir]: __rootDir,
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
const __emnapiContext = __emnapiGetDefaultContext()
|
|
28
|
-
|
|
29
|
-
const __sharedMemory = new WebAssembly.Memory({
|
|
30
|
-
initial: 4000,
|
|
31
|
-
maximum: 65536,
|
|
32
|
-
shared: true,
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
let __wasmFilePath = __nodePath.join(__dirname, 'satteri_napi.wasm32-wasi.wasm')
|
|
36
|
-
const __wasmDebugFilePath = __nodePath.join(__dirname, 'satteri_napi.wasm32-wasi.debug.wasm')
|
|
37
|
-
|
|
38
|
-
if (__nodeFs.existsSync(__wasmDebugFilePath)) {
|
|
39
|
-
__wasmFilePath = __wasmDebugFilePath
|
|
40
|
-
} else if (!__nodeFs.existsSync(__wasmFilePath)) {
|
|
41
|
-
try {
|
|
42
|
-
__wasmFilePath = require.resolve('@bruits/satteri-wasm32-wasi/satteri_napi.wasm32-wasi.wasm')
|
|
43
|
-
} catch {
|
|
44
|
-
throw new Error('Cannot find satteri_napi.wasm32-wasi.wasm file, and @bruits/satteri-wasm32-wasi package is not installed.')
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule } = __emnapiInstantiateNapiModuleSync(__nodeFs.readFileSync(__wasmFilePath), {
|
|
49
|
-
context: __emnapiContext,
|
|
50
|
-
asyncWorkPoolSize: (function() {
|
|
51
|
-
const threadsSizeFromEnv = Number(process.env.NAPI_RS_ASYNC_WORK_POOL_SIZE ?? process.env.UV_THREADPOOL_SIZE)
|
|
52
|
-
// NaN > 0 is false
|
|
53
|
-
if (threadsSizeFromEnv > 0) {
|
|
54
|
-
return threadsSizeFromEnv
|
|
55
|
-
} else {
|
|
56
|
-
return 4
|
|
57
|
-
}
|
|
58
|
-
})(),
|
|
59
|
-
reuseWorker: true,
|
|
60
|
-
wasi: __wasi,
|
|
61
|
-
onCreateWorker() {
|
|
62
|
-
const worker = new Worker(__nodePath.join(__dirname, 'wasi-worker.mjs'), {
|
|
63
|
-
env: process.env,
|
|
64
|
-
})
|
|
65
|
-
worker.onmessage = ({ data }) => {
|
|
66
|
-
__wasmCreateOnMessageForFsProxy(__nodeFs)(data)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// The main thread of Node.js waits for all the active handles before exiting.
|
|
70
|
-
// But Rust threads are never waited without `thread::join`.
|
|
71
|
-
// So here we hack the code of Node.js to prevent the workers from being referenced (active).
|
|
72
|
-
// According to https://github.com/nodejs/node/blob/19e0d472728c79d418b74bddff588bea70a403d0/lib/internal/worker.js#L415,
|
|
73
|
-
// a worker is consist of two handles: kPublicPort and kHandle.
|
|
74
|
-
{
|
|
75
|
-
const kPublicPort = Object.getOwnPropertySymbols(worker).find(s =>
|
|
76
|
-
s.toString().includes("kPublicPort")
|
|
77
|
-
);
|
|
78
|
-
if (kPublicPort) {
|
|
79
|
-
worker[kPublicPort].ref = () => {};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const kHandle = Object.getOwnPropertySymbols(worker).find(s =>
|
|
83
|
-
s.toString().includes("kHandle")
|
|
84
|
-
);
|
|
85
|
-
if (kHandle) {
|
|
86
|
-
worker[kHandle].ref = () => {};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
worker.unref();
|
|
90
|
-
}
|
|
91
|
-
return worker
|
|
92
|
-
},
|
|
93
|
-
overwriteImports(importObject) {
|
|
94
|
-
importObject.env = {
|
|
95
|
-
...importObject.env,
|
|
96
|
-
...importObject.napi,
|
|
97
|
-
...importObject.emnapi,
|
|
98
|
-
memory: __sharedMemory,
|
|
99
|
-
}
|
|
100
|
-
return importObject
|
|
101
|
-
},
|
|
102
|
-
beforeInit({ instance }) {
|
|
103
|
-
for (const name of Object.keys(instance.exports)) {
|
|
104
|
-
if (name.startsWith('__napi_register__')) {
|
|
105
|
-
instance.exports[name]()
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
},
|
|
109
|
-
})
|
|
110
|
-
module.exports = __napiModule.exports
|
|
111
|
-
module.exports.applyCommandsAndConvertToHastHandle = __napiModule.exports.applyCommandsAndConvertToHastHandle
|
|
112
|
-
module.exports.applyCommandsToHandle = __napiModule.exports.applyCommandsToHandle
|
|
113
|
-
module.exports.applyCommandsToMdastHandle = __napiModule.exports.applyCommandsToMdastHandle
|
|
114
|
-
module.exports.compileHandle = __napiModule.exports.compileHandle
|
|
115
|
-
module.exports.compileMdx = __napiModule.exports.compileMdx
|
|
116
|
-
module.exports.convertMdastToHastHandle = __napiModule.exports.convertMdastToHastHandle
|
|
117
|
-
module.exports.createHastHandle = __napiModule.exports.createHastHandle
|
|
118
|
-
module.exports.createMdastHandle = __napiModule.exports.createMdastHandle
|
|
119
|
-
module.exports.createMdxHastHandle = __napiModule.exports.createMdxHastHandle
|
|
120
|
-
module.exports.createMdxMdastHandle = __napiModule.exports.createMdxMdastHandle
|
|
121
|
-
module.exports.dropHandle = __napiModule.exports.dropHandle
|
|
122
|
-
module.exports.getHandleSource = __napiModule.exports.getHandleSource
|
|
123
|
-
module.exports.getMdastFrontmatter = __napiModule.exports.getMdastFrontmatter
|
|
124
|
-
module.exports.getNodeData = __napiModule.exports.getNodeData
|
|
125
|
-
module.exports.mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
|
|
126
|
-
module.exports.parseEsm = __napiModule.exports.parseEsm
|
|
127
|
-
module.exports.parseExpression = __napiModule.exports.parseExpression
|
|
128
|
-
module.exports.parseToHtml = __napiModule.exports.parseToHtml
|
|
129
|
-
module.exports.renderHandle = __napiModule.exports.renderHandle
|
|
130
|
-
module.exports.serializeHandle = __napiModule.exports.serializeHandle
|
|
131
|
-
module.exports.setNodeData = __napiModule.exports.setNodeData
|
|
132
|
-
module.exports.textContentHandle = __napiModule.exports.textContentHandle
|
|
133
|
-
module.exports.walkHandle = __napiModule.exports.walkHandle
|
|
134
|
-
module.exports.walkMdastHandle = __napiModule.exports.walkMdastHandle
|
package/wasi-worker-browser.mjs
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
}
|
package/wasi-worker.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { parse } from "node:path";
|
|
4
|
-
import { WASI } from "node:wasi";
|
|
5
|
-
import { parentPort, Worker } from "node:worker_threads";
|
|
6
|
-
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
|
|
9
|
-
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
|
|
10
|
-
|
|
11
|
-
if (parentPort) {
|
|
12
|
-
parentPort.on("message", (data) => {
|
|
13
|
-
globalThis.onmessage({ data });
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
Object.assign(globalThis, {
|
|
18
|
-
self: globalThis,
|
|
19
|
-
require,
|
|
20
|
-
Worker,
|
|
21
|
-
importScripts: function (f) {
|
|
22
|
-
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
23
|
-
},
|
|
24
|
-
postMessage: function (msg) {
|
|
25
|
-
if (parentPort) {
|
|
26
|
-
parentPort.postMessage(msg);
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const emnapiContext = getDefaultContext();
|
|
32
|
-
|
|
33
|
-
const __rootDir = parse(process.cwd()).root;
|
|
34
|
-
|
|
35
|
-
const handler = new MessageHandler({
|
|
36
|
-
onLoad({ wasmModule, wasmMemory }) {
|
|
37
|
-
const wasi = new WASI({
|
|
38
|
-
version: 'preview1',
|
|
39
|
-
env: process.env,
|
|
40
|
-
preopens: {
|
|
41
|
-
[__rootDir]: __rootDir,
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
return instantiateNapiModuleSync(wasmModule, {
|
|
46
|
-
childThread: true,
|
|
47
|
-
wasi,
|
|
48
|
-
context: emnapiContext,
|
|
49
|
-
overwriteImports(importObject) {
|
|
50
|
-
importObject.env = {
|
|
51
|
-
...importObject.env,
|
|
52
|
-
...importObject.napi,
|
|
53
|
-
...importObject.emnapi,
|
|
54
|
-
memory: wasmMemory
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
globalThis.onmessage = function (e) {
|
|
62
|
-
handler.handle(e);
|
|
63
|
-
};
|