satteri 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/browser.js +1 -0
- package/dist/command-buffer.d.ts +75 -0
- package/dist/command-buffer.js +231 -0
- package/dist/command-buffer.js.map +1 -0
- package/dist/compile.d.ts +22 -0
- package/dist/compile.js +144 -0
- package/dist/compile.js.map +1 -0
- package/dist/data-map.d.ts +10 -0
- package/dist/data-map.js +26 -0
- package/dist/data-map.js.map +1 -0
- package/dist/hast/hast-materializer.d.ts +11 -0
- package/dist/hast/hast-materializer.js +150 -0
- package/dist/hast/hast-materializer.js.map +1 -0
- package/dist/hast/hast-reader.d.ts +65 -0
- package/dist/hast/hast-reader.js +280 -0
- package/dist/hast/hast-reader.js.map +1 -0
- package/dist/hast/hast-visitor.d.ts +71 -0
- package/dist/hast/hast-visitor.js +537 -0
- package/dist/hast/hast-visitor.js.map +1 -0
- package/dist/hast-types.d.ts +5 -0
- package/dist/hast-types.js +2 -0
- package/dist/hast-types.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lazy-props.d.ts +10 -0
- package/dist/lazy-props.js +51 -0
- package/dist/lazy-props.js.map +1 -0
- package/dist/mdast/mdast-materializer.d.ts +9 -0
- package/dist/mdast/mdast-materializer.js +162 -0
- package/dist/mdast/mdast-materializer.js.map +1 -0
- package/dist/mdast/mdast-reader.d.ts +174 -0
- package/dist/mdast/mdast-reader.js +481 -0
- package/dist/mdast/mdast-reader.js.map +1 -0
- package/dist/mdast/mdast-visitor.d.ts +98 -0
- package/dist/mdast/mdast-visitor.js +543 -0
- package/dist/mdast/mdast-visitor.js.map +1 -0
- package/dist/mdast-types.d.ts +5 -0
- package/dist/mdast-types.js +2 -0
- package/dist/mdast-types.js.map +1 -0
- package/dist/pipeline.d.ts +29 -0
- package/dist/pipeline.js +87 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/plugin.d.ts +12 -0
- package/dist/plugin.js +19 -0
- package/dist/plugin.js.map +1 -0
- package/dist/processor.d.ts +33 -0
- package/dist/processor.js +49 -0
- package/dist/processor.js.map +1 -0
- package/dist/types.d.ts +86 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/index.d.ts +109 -0
- package/index.js +604 -0
- package/package.json +60 -0
- package/satteri_napi.linux-x64-gnu.node +0 -0
- package/satteri_napi.wasi-browser.js +80 -0
- package/satteri_napi.wasi.cjs +132 -0
- package/wasi-worker.mjs +63 -0
package/dist/pipeline.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { visitMdast } from "./mdast/mdast-visitor.js";
|
|
2
|
+
import { DataMap } from "./data-map.js";
|
|
3
|
+
import { MdastReader } from "./mdast/mdast-reader.js";
|
|
4
|
+
import { materializeNode } from "./mdast/mdast-materializer.js";
|
|
5
|
+
// applyMutations is the NAPI function that takes an arena buffer + command
|
|
6
|
+
// buffer and returns a new arena buffer with all mutations applied.
|
|
7
|
+
import { applyMutations } from "../index.js";
|
|
8
|
+
export class ProcessorContext {
|
|
9
|
+
#diagnostics = [];
|
|
10
|
+
report(diagnostic) {
|
|
11
|
+
this.#diagnostics.push(diagnostic);
|
|
12
|
+
}
|
|
13
|
+
getDiagnostics() {
|
|
14
|
+
return [...this.#diagnostics];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Process one arena buffer through an ordered list of initialized plugin instances.
|
|
19
|
+
*/
|
|
20
|
+
export function runPluginsOnBuffer(buffer, pluginInstances, { filename = "<unknown>", dataMap, deferLast = false, } = {}) {
|
|
21
|
+
const dm = dataMap ?? new DataMap();
|
|
22
|
+
const allMdastDiagnostics = [];
|
|
23
|
+
let totalMutations = 0;
|
|
24
|
+
let structuralMutations = 0;
|
|
25
|
+
let currentBuffer = buffer;
|
|
26
|
+
for (let i = 0; i < pluginInstances.length; i++) {
|
|
27
|
+
const { instance } = pluginInstances[i];
|
|
28
|
+
const reader = new MdastReader(currentBuffer);
|
|
29
|
+
const fileContext = {
|
|
30
|
+
source: reader.getSource(),
|
|
31
|
+
filename,
|
|
32
|
+
get root() {
|
|
33
|
+
return materializeNode(reader, 0, dm);
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const wrappedPlugin = wrapInstance(instance, fileContext);
|
|
37
|
+
const result = visitMdast(reader, wrappedPlugin, dm);
|
|
38
|
+
allMdastDiagnostics.push(...result.diagnostics);
|
|
39
|
+
if (result.hasMutations) {
|
|
40
|
+
totalMutations += 1;
|
|
41
|
+
structuralMutations += 1;
|
|
42
|
+
if (deferLast && i === pluginInstances.length - 1) {
|
|
43
|
+
// Last plugin — defer mutations for fusion with the next pipeline step
|
|
44
|
+
return {
|
|
45
|
+
buffer: currentBuffer,
|
|
46
|
+
pendingCommands: result.commandBuffer,
|
|
47
|
+
dataMap: dm,
|
|
48
|
+
diagnostics: allMdastDiagnostics,
|
|
49
|
+
mutationCount: totalMutations,
|
|
50
|
+
structuralMutationCount: structuralMutations,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const arenaBuf = currentBuffer instanceof Uint8Array ? currentBuffer : new Uint8Array(currentBuffer);
|
|
54
|
+
currentBuffer = applyMutations(arenaBuf, result.commandBuffer);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
buffer: currentBuffer,
|
|
59
|
+
pendingCommands: null,
|
|
60
|
+
dataMap: dm,
|
|
61
|
+
diagnostics: allMdastDiagnostics,
|
|
62
|
+
mutationCount: totalMutations,
|
|
63
|
+
structuralMutationCount: structuralMutations,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function wrapInstance(instance, fileContext) {
|
|
67
|
+
const wrapped = {};
|
|
68
|
+
for (const [key, val] of Object.entries(instance)) {
|
|
69
|
+
if (key !== "before" && key !== "after" && key !== "transformRoot") {
|
|
70
|
+
if (typeof val === "function") {
|
|
71
|
+
wrapped[key] = val;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const inst = instance;
|
|
76
|
+
if (typeof inst.before === "function") {
|
|
77
|
+
wrapped.before = (visitorContext) => inst.before(fileContext, visitorContext);
|
|
78
|
+
}
|
|
79
|
+
if (typeof inst.after === "function") {
|
|
80
|
+
wrapped.after = (visitorContext) => inst.after(fileContext, visitorContext);
|
|
81
|
+
}
|
|
82
|
+
if (typeof inst.transformRoot === "function") {
|
|
83
|
+
wrapped.transformRoot = (root, visitorContext) => inst.transformRoot(root, fileContext, visitorContext);
|
|
84
|
+
}
|
|
85
|
+
return wrapped;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pipeline.js","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKhE,2EAA2E;AAC3E,oEAAoE;AACpE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,OAAO,gBAAgB;IAClB,YAAY,GAAsB,EAAE,CAAC;IAE9C,MAAM,CAAC,UAA2B;QAChC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACrC,CAAC;IAED,cAAc;QACZ,OAAO,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC;IAChC,CAAC;CACF;AAkBD;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAgC,EAChC,eAA8F,EAC9F,EACE,QAAQ,GAAG,WAAW,EACtB,OAAO,EACP,SAAS,GAAG,KAAK,MACgD,EAAE;IAErE,MAAM,EAAE,GAAG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;IACD,IAAI,OAAO,IAAI,CAAC,aAAa,KAAK,UAAU,EAAE,CAAC;QAC7C,OAAO,CAAC,aAAa,GAAG,CAAC,IAAe,EAAE,cAAuB,EAAE,EAAE,CAClE,IAAI,CAAC,aAAyE,CAC7E,IAAI,EACJ,WAAW,EACX,cAAc,CACf,CAAC;IACN,CAAC;IAED,OAAO,OAA0D,CAAC;AACpE,CAAC"}
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MdastPluginInstance } from "./mdast/mdast-visitor.js";
|
|
2
|
+
import type { HastVisitorInstance } from "./hast/hast-visitor.js";
|
|
3
|
+
export interface MdastPluginDefinition {
|
|
4
|
+
name: string;
|
|
5
|
+
createOnce(): MdastPluginInstance;
|
|
6
|
+
}
|
|
7
|
+
export interface HastPluginDefinition {
|
|
8
|
+
name: string;
|
|
9
|
+
createOnce(): HastVisitorInstance;
|
|
10
|
+
}
|
|
11
|
+
export declare function defineMdastPlugin(definition: MdastPluginDefinition): MdastPluginDefinition;
|
|
12
|
+
export declare function defineHastPlugin(definition: HastPluginDefinition): HastPluginDefinition;
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function defineMdastPlugin(definition) {
|
|
2
|
+
if (!definition.name) {
|
|
3
|
+
throw new Error("Plugin definition must have a name");
|
|
4
|
+
}
|
|
5
|
+
if (typeof definition.createOnce !== "function") {
|
|
6
|
+
throw new Error("Plugin definition must have a createOnce function");
|
|
7
|
+
}
|
|
8
|
+
return definition;
|
|
9
|
+
}
|
|
10
|
+
export function defineHastPlugin(definition) {
|
|
11
|
+
if (!definition.name) {
|
|
12
|
+
throw new Error("Plugin definition must have a name");
|
|
13
|
+
}
|
|
14
|
+
if (typeof definition.createOnce !== "function") {
|
|
15
|
+
throw new Error("Plugin definition must have a createOnce function");
|
|
16
|
+
}
|
|
17
|
+
return definition;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAaA,MAAM,UAAU,iBAAiB,CAAC,UAAiC;IACjE,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,UAAgC;IAC/D,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IACD,IAAI,OAAO,UAAU,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAChD,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ProcessorContext } from "./pipeline.js";
|
|
2
|
+
import { DataMap } from "./data-map.js";
|
|
3
|
+
import type { MdastPluginDefinition } from "./plugin.js";
|
|
4
|
+
import type { MdastNode } from "./types.js";
|
|
5
|
+
import type { MdastDiagnostic } from "./mdast/mdast-visitor.js";
|
|
6
|
+
export { ProcessorContext };
|
|
7
|
+
interface ProcessBufferResult {
|
|
8
|
+
buffer: ArrayBuffer | Uint8Array;
|
|
9
|
+
dataMap: DataMap;
|
|
10
|
+
diagnostics: MdastDiagnostic[];
|
|
11
|
+
mutationCount: number;
|
|
12
|
+
structuralMutationCount: number;
|
|
13
|
+
}
|
|
14
|
+
interface ProcessTreeResult {
|
|
15
|
+
tree: MdastNode;
|
|
16
|
+
dataMap: DataMap;
|
|
17
|
+
diagnostics: MdastDiagnostic[];
|
|
18
|
+
mutationCount: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function createProcessor({ plugins, }?: {
|
|
21
|
+
plugins?: MdastPluginDefinition[];
|
|
22
|
+
}): Processor;
|
|
23
|
+
declare class Processor {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(pluginDefs: MdastPluginDefinition[]);
|
|
26
|
+
processBuffer(buffer: ArrayBuffer | Uint8Array, options?: {
|
|
27
|
+
filename?: string;
|
|
28
|
+
}): ProcessBufferResult;
|
|
29
|
+
processBufferToTree(buffer: ArrayBuffer | Uint8Array, options?: {
|
|
30
|
+
filename?: string;
|
|
31
|
+
}): ProcessTreeResult;
|
|
32
|
+
getDiagnostics(): MdastDiagnostic[];
|
|
33
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ProcessorContext, runPluginsOnBuffer } from "./pipeline.js";
|
|
2
|
+
import { MdastReader } from "./mdast/mdast-reader.js";
|
|
3
|
+
import { materializeTree } from "./mdast/mdast-materializer.js";
|
|
4
|
+
import { DataMap } from "./data-map.js";
|
|
5
|
+
export { ProcessorContext };
|
|
6
|
+
export function createProcessor({ plugins = [], } = {}) {
|
|
7
|
+
return new Processor(plugins);
|
|
8
|
+
}
|
|
9
|
+
class Processor {
|
|
10
|
+
#pluginDefs;
|
|
11
|
+
#processorCtx;
|
|
12
|
+
#initializedPlugins = null;
|
|
13
|
+
constructor(pluginDefs) {
|
|
14
|
+
for (const def of pluginDefs) {
|
|
15
|
+
if (!def.name || typeof def.createOnce !== "function") {
|
|
16
|
+
throw new Error(`Invalid plugin: ${JSON.stringify(def.name)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
this.#pluginDefs = pluginDefs;
|
|
20
|
+
this.#processorCtx = new ProcessorContext();
|
|
21
|
+
}
|
|
22
|
+
#getPluginInstances() {
|
|
23
|
+
if (this.#initializedPlugins === null) {
|
|
24
|
+
this.#initializedPlugins = this.#pluginDefs.map((def) => ({
|
|
25
|
+
instance: def.createOnce(this.#processorCtx),
|
|
26
|
+
name: def.name,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
return this.#initializedPlugins;
|
|
30
|
+
}
|
|
31
|
+
processBuffer(buffer, options = {}) {
|
|
32
|
+
return runPluginsOnBuffer(buffer, this.#getPluginInstances(), options);
|
|
33
|
+
}
|
|
34
|
+
processBufferToTree(buffer, options = {}) {
|
|
35
|
+
const result = this.processBuffer(buffer, options);
|
|
36
|
+
const reader = new MdastReader(result.buffer);
|
|
37
|
+
const tree = materializeTree(reader, result.dataMap);
|
|
38
|
+
return {
|
|
39
|
+
tree,
|
|
40
|
+
dataMap: result.dataMap,
|
|
41
|
+
diagnostics: result.diagnostics,
|
|
42
|
+
mutationCount: result.mutationCount,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
getDiagnostics() {
|
|
46
|
+
return this.#processorCtx.getDiagnostics();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=processor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAKxC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAiB5B,MAAM,UAAU,eAAe,CAAC,EAC9B,OAAO,GAAG,EAAE,MAC6B,EAAE;IAC3C,OAAO,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC;AAED,MAAM,SAAS;IACJ,WAAW,CAA0B;IACrC,aAAa,CAAmB;IACzC,mBAAmB,GAER,IAAI,CAAC;IAEhB,YAAY,UAAmC;QAC7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W,EAAE,MAAM,CAAC,WAAW;YAC/B,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC;IACJ,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { Position } from "unist";
|
|
2
|
+
import type { Literal as MdastLiteral, Nodes as MdastStdNodes } from "mdast";
|
|
3
|
+
import type { Nodes as HastStdNodes } from "hast";
|
|
4
|
+
export type { Position, Point } from "unist";
|
|
5
|
+
export type { MdxJsxFlowElement, MdxJsxTextElement, MdxJsxAttribute as MdxJsxAttributeNode, MdxJsxExpressionAttribute as MdxJsxExpressionAttributeNode, MdxJsxAttributeValueExpression as MdxJsxAttributeValueExpressionNode, } from "mdast-util-mdx-jsx";
|
|
6
|
+
export type { MdxFlowExpression, MdxTextExpression } from "mdast-util-mdx-expression";
|
|
7
|
+
export type { MdxjsEsm } from "mdast-util-mdxjs-esm";
|
|
8
|
+
import type { MdxJsxAttribute, MdxJsxExpressionAttribute } from "mdast-util-mdx-jsx";
|
|
9
|
+
export type MdxJsxAttributeUnion = MdxJsxAttribute | MdxJsxExpressionAttribute;
|
|
10
|
+
export interface Toml extends MdastLiteral {
|
|
11
|
+
type: "toml";
|
|
12
|
+
}
|
|
13
|
+
export interface MathNode extends MdastLiteral {
|
|
14
|
+
type: "math";
|
|
15
|
+
meta?: string | null | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface InlineMath extends MdastLiteral {
|
|
18
|
+
type: "inlineMath";
|
|
19
|
+
}
|
|
20
|
+
declare module "mdast" {
|
|
21
|
+
interface FrontmatterContentMap {
|
|
22
|
+
toml: Toml;
|
|
23
|
+
}
|
|
24
|
+
interface RootContentMap {
|
|
25
|
+
toml: Toml;
|
|
26
|
+
math: MathNode;
|
|
27
|
+
inlineMath: InlineMath;
|
|
28
|
+
}
|
|
29
|
+
interface PhrasingContentMap {
|
|
30
|
+
inlineMath: InlineMath;
|
|
31
|
+
}
|
|
32
|
+
interface BlockContentMap {
|
|
33
|
+
math: MathNode;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export interface HastRaw {
|
|
37
|
+
type: "raw";
|
|
38
|
+
value: string;
|
|
39
|
+
}
|
|
40
|
+
declare module "hast" {
|
|
41
|
+
interface RootContentMap {
|
|
42
|
+
raw: HastRaw;
|
|
43
|
+
}
|
|
44
|
+
interface ElementContentMap {
|
|
45
|
+
raw: HastRaw;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Materialized mdast node — a standard `mdast.Nodes` discriminated union.
|
|
50
|
+
* Narrow by `node.type` to access type-specific properties
|
|
51
|
+
* (e.g. `depth` on `"heading"`, `url` on `"link"`).
|
|
52
|
+
*/
|
|
53
|
+
export type MdastNode = MdastStdNodes;
|
|
54
|
+
/**
|
|
55
|
+
* Materialized hast node — a standard `hast.Nodes` discriminated union.
|
|
56
|
+
* Narrow by `node.type` to access type-specific properties
|
|
57
|
+
* (e.g. `tagName` on `"element"`, `value` on `"text"`).
|
|
58
|
+
*/
|
|
59
|
+
export type HastNode = HastStdNodes;
|
|
60
|
+
export interface StringRefRaw {
|
|
61
|
+
offset: number;
|
|
62
|
+
len: number;
|
|
63
|
+
}
|
|
64
|
+
export interface MdastNodeRaw {
|
|
65
|
+
id: number;
|
|
66
|
+
type: number;
|
|
67
|
+
typeName: string;
|
|
68
|
+
parent: number;
|
|
69
|
+
position: Position;
|
|
70
|
+
childrenStart: number;
|
|
71
|
+
childrenCount: number;
|
|
72
|
+
dataOffset: number;
|
|
73
|
+
dataLen: number;
|
|
74
|
+
}
|
|
75
|
+
export interface BufferHeader {
|
|
76
|
+
version: number;
|
|
77
|
+
nodeStructSize: number;
|
|
78
|
+
nodeCount: number;
|
|
79
|
+
nodesOffset: number;
|
|
80
|
+
childrenCount: number;
|
|
81
|
+
childrenOffset: number;
|
|
82
|
+
typeDataLen: number;
|
|
83
|
+
typeDataOffset: number;
|
|
84
|
+
sourceLen: number;
|
|
85
|
+
sourceOffset: number;
|
|
86
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,EAAE;AACF,yEAAyE;AACzE,4EAA4E"}
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/* auto-generated by NAPI-RS */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Apply MDAST commands and convert to HAST handle in one step.
|
|
5
|
+
* The MDAST handle is consumed (emptied).
|
|
6
|
+
*/
|
|
7
|
+
export declare function applyCommandsAndConvertToHastHandle(handle: ArenaHandle, commandBuf: Uint8Array): ArenaHandle
|
|
8
|
+
|
|
9
|
+
/** Apply a command buffer to a handle's arena in-place. No serialize/deserialize. */
|
|
10
|
+
export declare function applyCommandsToHandle(handle: ArenaHandle, commandBuf: Uint8Array): void
|
|
11
|
+
|
|
12
|
+
/** Apply a command buffer to an MDAST handle in-place. */
|
|
13
|
+
export declare function applyCommandsToMdastHandle(handle: ArenaHandle, commandBuf: Uint8Array): void
|
|
14
|
+
|
|
15
|
+
/** Compile a handle's HAST arena to MDX JavaScript. Does not consume the handle. */
|
|
16
|
+
export declare function compileHandle(handle: ArenaHandle, options?: JsMdxOptions | undefined | null): string
|
|
17
|
+
|
|
18
|
+
/** Compile MDX source directly to JavaScript. */
|
|
19
|
+
export declare function compileMdx(source: string, options?: JsMdxOptions | undefined | null): string
|
|
20
|
+
|
|
21
|
+
/** Convert an MDAST handle to a HAST handle. The MDAST handle is consumed (emptied). */
|
|
22
|
+
export declare function convertMdastToHastHandle(handle: ArenaHandle): ArenaHandle
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Parse markdown source and convert to HAST. Returns an opaque handle.
|
|
26
|
+
* The arena stays in Rust memory — no buffer is copied to JS.
|
|
27
|
+
*/
|
|
28
|
+
export declare function createHastHandle(source: string): ArenaHandle
|
|
29
|
+
|
|
30
|
+
/** Parse markdown source into an MDAST arena handle. */
|
|
31
|
+
export declare function createMdastHandle(source: string): ArenaHandle
|
|
32
|
+
|
|
33
|
+
/** Parse MDX source and convert to HAST. Returns an opaque handle. */
|
|
34
|
+
export declare function createMdxHastHandle(source: string): ArenaHandle
|
|
35
|
+
|
|
36
|
+
/** Parse MDX source into an MDAST arena handle. */
|
|
37
|
+
export declare function createMdxMdastHandle(source: string): ArenaHandle
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Release the arena memory held by a handle. The handle becomes empty
|
|
41
|
+
* but remains valid (subsequent calls are no-ops or return empty results).
|
|
42
|
+
*/
|
|
43
|
+
export declare function dropHandle(handle: ArenaHandle): void
|
|
44
|
+
|
|
45
|
+
/** Get the source string from an MDAST handle. */
|
|
46
|
+
export declare function getHandleSource(handle: ArenaHandle): string
|
|
47
|
+
|
|
48
|
+
/** Read the node_data JSON blob for a node. Returns null if none is set. */
|
|
49
|
+
export declare function getNodeData(handle: ArenaHandle, nodeId: number): string | null
|
|
50
|
+
|
|
51
|
+
/** MDX compile options passed from JavaScript. */
|
|
52
|
+
export interface JsMdxOptions {
|
|
53
|
+
/**
|
|
54
|
+
* Static subtree optimization. If provided, static subtrees are collapsed
|
|
55
|
+
* into raw HTML strings using the specified component and prop.
|
|
56
|
+
*/
|
|
57
|
+
optimizeStatic?: JsOptimizeStaticConfig
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Static optimization config passed from JavaScript. */
|
|
61
|
+
export interface JsOptimizeStaticConfig {
|
|
62
|
+
/** Component/element name to wrap collapsed HTML in (e.g. "Fragment", "div"). */
|
|
63
|
+
component: string
|
|
64
|
+
/** Prop name for the HTML string (e.g. "set:html", "dangerouslySetInnerHTML"). */
|
|
65
|
+
prop: string
|
|
66
|
+
/** If true, prop value is wrapped as `{ __html: "..." }` (React-style). */
|
|
67
|
+
wrapPropValue?: boolean
|
|
68
|
+
/** Element tag names to exclude from collapsing. */
|
|
69
|
+
ignoreElements?: Array<string>
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A subscription passed from JS. */
|
|
73
|
+
export interface JsSubscription {
|
|
74
|
+
nodeType: number
|
|
75
|
+
tagFilter: Array<string>
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Parse a JavaScript expression and return its ESTree-compatible AST as a JSON string.
|
|
80
|
+
* Returns null if parsing fails. The JS layer calls JSON.parse (faster than serde_json → NAPI).
|
|
81
|
+
*/
|
|
82
|
+
export declare function parseExpression(source: string): string | null
|
|
83
|
+
|
|
84
|
+
/** Parse Markdown source and return HTML string directly. */
|
|
85
|
+
export declare function parseToHtml(source: string): string
|
|
86
|
+
|
|
87
|
+
/** Render a handle's HAST arena to HTML. Does not consume the handle. */
|
|
88
|
+
export declare function renderHandle(handle: ArenaHandle): string
|
|
89
|
+
|
|
90
|
+
/** Serialize a handle's arena to a binary buffer (for fallback paths like transformRoot). */
|
|
91
|
+
export declare function serializeHandle(handle: ArenaHandle): Uint8Array
|
|
92
|
+
|
|
93
|
+
/** Serialize an MDAST handle to a binary buffer (read-only snapshot for JS visitor). */
|
|
94
|
+
export declare function serializeMdastHandle(handle: ArenaHandle): Uint8Array
|
|
95
|
+
|
|
96
|
+
/** Set the `data` blob (JSON bytes) for a node in the handle's arena. */
|
|
97
|
+
export declare function setNodeData(handle: ArenaHandle, nodeId: number, json: Uint8Array): void
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Collect the concatenated text content of a node and all its descendants.
|
|
101
|
+
* Walks entirely in Rust — no per-child NAPI round-trips.
|
|
102
|
+
*/
|
|
103
|
+
export declare function textContentHandle(handle: ArenaHandle, nodeId: number): string
|
|
104
|
+
|
|
105
|
+
/** Walk a handle's arena and return matched nodes as a flat binary buffer. */
|
|
106
|
+
export declare function walkHandle(handle: ArenaHandle, subscriptions: Array<JsSubscription>): Uint8Array
|
|
107
|
+
|
|
108
|
+
/** Walk an MDAST handle's arena and return matched nodes as a flat binary buffer. */
|
|
109
|
+
export declare function walkMdastHandle(handle: ArenaHandle, subscriptions: Array<JsSubscription>): Uint8Array
|