satteri 0.10.4 → 0.11.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.
- package/README.md +11 -0
- package/dist/arena-reader.d.ts +13 -0
- package/dist/arena-reader.js +104 -0
- package/dist/binding.browser.d.ts +1 -1
- package/dist/binding.browser.js +1 -1
- package/dist/binding.d.ts +1 -1
- package/dist/binding.js +1 -1
- package/dist/byte-writer.d.ts +0 -18
- package/dist/byte-writer.js +6 -30
- package/dist/child-stub.d.ts +0 -17
- package/dist/child-stub.js +6 -22
- package/dist/command-buffer.d.ts +5 -26
- package/dist/command-buffer.js +28 -39
- package/dist/compile-options.d.ts +11 -0
- package/dist/compile-options.js +99 -0
- package/dist/compile-types.d.ts +330 -0
- package/dist/compile-types.js +1 -0
- package/dist/compile.d.ts +22 -328
- package/dist/compile.js +129 -379
- package/dist/directive-types.d.ts +1 -0
- package/dist/directive-types.js +1 -6
- package/dist/generated/arena-layout.d.ts +6 -4
- package/dist/generated/arena-layout.js +6 -7
- package/dist/generated/fused-wire.d.ts +3 -0
- package/dist/generated/fused-wire.js +229 -0
- package/dist/generated/parse-options.js +0 -5
- package/dist/generated/wire-constants.d.ts +3 -0
- package/dist/generated/wire-constants.js +33 -42
- package/dist/handles.d.ts +0 -7
- package/dist/hast/child-stub.d.ts +1 -8
- package/dist/hast/child-stub.js +14 -13
- package/dist/hast/element-props.d.ts +13 -0
- package/dist/hast/element-props.js +52 -6
- package/dist/hast/generated/node-types.d.ts +1 -9
- package/dist/hast/generated/node-types.js +1 -9
- package/dist/hast/generated/walk-decode.d.ts +10 -0
- package/dist/hast/generated/walk-decode.js +61 -0
- package/dist/hast/hast-materializer.d.ts +3 -10
- package/dist/hast/hast-materializer.js +73 -47
- package/dist/hast/hast-reader.d.ts +9 -38
- package/dist/hast/hast-reader.js +82 -271
- package/dist/hast/hast-visitor.d.ts +29 -16
- package/dist/hast/hast-visitor.js +197 -508
- package/dist/hast/hast-walk.d.ts +18 -0
- package/dist/hast/hast-walk.js +264 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -12
- package/dist/lazy-child-resolver.d.ts +1 -21
- package/dist/lazy-child-resolver.js +11 -32
- package/dist/materializer-cache.d.ts +5 -29
- package/dist/materializer-cache.js +29 -101
- package/dist/mdast/child-stub.d.ts +1 -12
- package/dist/mdast/child-stub.js +18 -28
- package/dist/mdast/column-align.d.ts +1 -1
- package/dist/mdast/column-align.js +0 -2
- package/dist/mdast/generated/layout.d.ts +0 -16
- package/dist/mdast/generated/layout.js +6 -47
- package/dist/mdast/generated/node-types.d.ts +1 -9
- package/dist/mdast/generated/node-types.js +3 -9
- package/dist/mdast/mdast-materializer.d.ts +3 -11
- package/dist/mdast/mdast-materializer.js +91 -63
- package/dist/mdast/mdast-reader.d.ts +15 -63
- package/dist/mdast/mdast-reader.js +132 -269
- package/dist/mdast/mdast-visitor.d.ts +23 -15
- package/dist/mdast/mdast-visitor.js +188 -294
- package/dist/mdast/mdast-walk.d.ts +13 -0
- package/dist/mdast/mdast-walk.js +144 -0
- package/dist/mdx-attr.js +0 -3
- package/dist/mdx-types.js +1 -6
- package/dist/op-stream.d.ts +1 -15
- package/dist/op-stream.js +3 -19
- package/dist/phantom.d.ts +0 -1
- package/dist/phantom.js +1 -9
- package/dist/plugin-pipeline.d.ts +32 -0
- package/dist/plugin-pipeline.js +177 -0
- package/dist/plugin.d.ts +8 -7
- package/dist/plugin.js +3 -9
- package/dist/types.d.ts +0 -1
- package/dist/visitor-node.d.ts +12 -0
- package/dist/visitor-node.js +23 -0
- package/dist/visitor-shared.d.ts +26 -30
- package/dist/visitor-shared.js +34 -36
- package/dist/wire-read.d.ts +0 -22
- package/dist/wire-read.js +3 -24
- package/index.d.ts +19 -10
- package/index.js +56 -53
- package/package.json +3 -12
- package/dist/string-pool.d.ts +0 -13
- package/dist/string-pool.js +0 -91
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { ENABLE_DEFINITION_LIST, ENABLE_DIRECTIVE, ENABLE_FOOTNOTES, ENABLE_GFM, ENABLE_HEADING_ATTRIBUTES, ENABLE_MATH, ENABLE_MATH_MULTI_DOLLAR, ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS, ENABLE_SMART_DASHES, ENABLE_SMART_ELLIPSES, ENABLE_SMART_PUNCTUATION, ENABLE_SMART_QUOTES, ENABLE_STRIKETHROUGH, ENABLE_SUBSCRIPT, ENABLE_SUPERSCRIPT, ENABLE_TABLES, ENABLE_TASKLISTS, ENABLE_WIKILINKS, ENABLE_YAML_STYLE_METADATA_BLOCKS, } from "./generated/parse-options.js";
|
|
2
|
+
const GFM_PARSE_OPTIONS = ENABLE_TABLES | ENABLE_STRIKETHROUGH | ENABLE_TASKLISTS | ENABLE_GFM;
|
|
3
|
+
const FRONTMATTER_PARSE_OPTIONS = ENABLE_YAML_STYLE_METADATA_BLOCKS | ENABLE_PLUSES_DELIMITED_METADATA_BLOCKS;
|
|
4
|
+
export const DEFAULT_PARSE_OPTIONS = GFM_PARSE_OPTIONS | ENABLE_FOOTNOTES | FRONTMATTER_PARSE_OPTIONS;
|
|
5
|
+
function featuresToParseOptions(features) {
|
|
6
|
+
let options = 0;
|
|
7
|
+
const { gfm } = features;
|
|
8
|
+
if (typeof gfm === "object") {
|
|
9
|
+
options |= GFM_PARSE_OPTIONS;
|
|
10
|
+
if (gfm.footnotes !== false)
|
|
11
|
+
options |= ENABLE_FOOTNOTES;
|
|
12
|
+
}
|
|
13
|
+
else if (gfm ?? true) {
|
|
14
|
+
options |= GFM_PARSE_OPTIONS | ENABLE_FOOTNOTES;
|
|
15
|
+
}
|
|
16
|
+
if (features.frontmatter ?? true)
|
|
17
|
+
options |= FRONTMATTER_PARSE_OPTIONS;
|
|
18
|
+
const { math } = features;
|
|
19
|
+
if (typeof math === "object") {
|
|
20
|
+
options |= math.singleDollarTextMath === false ? ENABLE_MATH_MULTI_DOLLAR : ENABLE_MATH;
|
|
21
|
+
}
|
|
22
|
+
else if (math) {
|
|
23
|
+
options |= ENABLE_MATH;
|
|
24
|
+
}
|
|
25
|
+
if (features.headingAttributes)
|
|
26
|
+
options |= ENABLE_HEADING_ATTRIBUTES;
|
|
27
|
+
if (features.directive)
|
|
28
|
+
options |= ENABLE_DIRECTIVE;
|
|
29
|
+
if (features.superscript)
|
|
30
|
+
options |= ENABLE_SUPERSCRIPT;
|
|
31
|
+
if (features.subscript)
|
|
32
|
+
options |= ENABLE_SUBSCRIPT;
|
|
33
|
+
if (features.wikilinks)
|
|
34
|
+
options |= ENABLE_WIKILINKS;
|
|
35
|
+
if (features.definitionList)
|
|
36
|
+
options |= ENABLE_DEFINITION_LIST;
|
|
37
|
+
const smartPunctuation = features.smartPunctuation;
|
|
38
|
+
if (typeof smartPunctuation === "object") {
|
|
39
|
+
if (smartPunctuation.quotes ?? true)
|
|
40
|
+
options |= ENABLE_SMART_QUOTES;
|
|
41
|
+
if (smartPunctuation.dashes ?? true)
|
|
42
|
+
options |= ENABLE_SMART_DASHES;
|
|
43
|
+
if (smartPunctuation.ellipses ?? true)
|
|
44
|
+
options |= ENABLE_SMART_ELLIPSES;
|
|
45
|
+
}
|
|
46
|
+
else if (smartPunctuation) {
|
|
47
|
+
options |= ENABLE_SMART_PUNCTUATION;
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
export function featuresToNative(features) {
|
|
52
|
+
if (!features)
|
|
53
|
+
return { parseOptions: DEFAULT_PARSE_OPTIONS, convertOptions: undefined };
|
|
54
|
+
let convertOptions;
|
|
55
|
+
const { gfm } = features;
|
|
56
|
+
if (typeof gfm === "object" && typeof gfm.footnotes === "object") {
|
|
57
|
+
const { label, backContent, backLabel, clobberPrefix } = gfm.footnotes;
|
|
58
|
+
convertOptions = {};
|
|
59
|
+
if (label !== undefined)
|
|
60
|
+
convertOptions.footnoteLabel = label;
|
|
61
|
+
if (backContent !== undefined)
|
|
62
|
+
convertOptions.footnoteBackContent = backContent;
|
|
63
|
+
if (backLabel !== undefined)
|
|
64
|
+
convertOptions.footnoteBackLabel = backLabel;
|
|
65
|
+
if (clobberPrefix !== undefined)
|
|
66
|
+
convertOptions.clobberPrefix = clobberPrefix;
|
|
67
|
+
}
|
|
68
|
+
if (features.rawHtml !== undefined) {
|
|
69
|
+
// Conversion options must carry rawHtml so tree APIs and compile pipelines apply the same reparse.
|
|
70
|
+
convertOptions = convertOptions ?? {};
|
|
71
|
+
convertOptions.rawHtml = features.rawHtml;
|
|
72
|
+
}
|
|
73
|
+
return { parseOptions: featuresToParseOptions(features), convertOptions };
|
|
74
|
+
}
|
|
75
|
+
const MDX_NATIVE_OPTION_KEYS = [
|
|
76
|
+
"optimizeStatic",
|
|
77
|
+
"jsxImportSource",
|
|
78
|
+
"jsx",
|
|
79
|
+
"jsxRuntime",
|
|
80
|
+
"development",
|
|
81
|
+
"providerImportSource",
|
|
82
|
+
"pragma",
|
|
83
|
+
"pragmaFrag",
|
|
84
|
+
"pragmaImportSource",
|
|
85
|
+
"outputFormat",
|
|
86
|
+
"elementAttributeNameCase",
|
|
87
|
+
"stylePropertyNameCase",
|
|
88
|
+
];
|
|
89
|
+
export function mdxOptionsToNative(opts) {
|
|
90
|
+
let result;
|
|
91
|
+
const copyOption = (key) => {
|
|
92
|
+
const value = opts[key];
|
|
93
|
+
if (value === undefined || (key === "optimizeStatic" && !value))
|
|
94
|
+
return;
|
|
95
|
+
(result ??= {})[key] = value;
|
|
96
|
+
};
|
|
97
|
+
MDX_NATIVE_OPTION_KEYS.forEach(copyOption);
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
import type { HastPluginList, MdastPluginList } from "./plugin.js";
|
|
2
|
+
import type { Data } from "./types.js";
|
|
3
|
+
/** Configuration for static subtree collapsing during MDX compilation. */
|
|
4
|
+
export interface OptimizeStaticConfig {
|
|
5
|
+
component: string;
|
|
6
|
+
prop: string;
|
|
7
|
+
wrapPropValue?: boolean;
|
|
8
|
+
ignoreElements?: string[];
|
|
9
|
+
}
|
|
10
|
+
/** Granular smart-punctuation toggles. Omitted fields default to true. */
|
|
11
|
+
export interface SmartPunctuationOptions {
|
|
12
|
+
/** Replace straight quotes with curly/smart quotes. Default: true. */
|
|
13
|
+
quotes?: boolean;
|
|
14
|
+
/** Replace `--`/`---` with en-dash/em-dash. Default: true. */
|
|
15
|
+
dashes?: boolean;
|
|
16
|
+
/** Replace `...` with ellipsis (`…`). Default: true. */
|
|
17
|
+
ellipses?: boolean;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Per-backref callback. Invoked once per anchor in the footnotes section
|
|
21
|
+
* with 1-based `referenceNumber` and `rerunIndex` (1 on the first backref
|
|
22
|
+
* to that definition, 2 on the second, and so on). Must return the final
|
|
23
|
+
* string used as the backref content or `aria-label`.
|
|
24
|
+
*/
|
|
25
|
+
export type FootnoteBackrefCallback = (referenceNumber: number, rerunIndex: number) => string;
|
|
26
|
+
/**
|
|
27
|
+
* i18n strings for the GFM footnotes section. Mirrors `footnoteLabel`,
|
|
28
|
+
* `footnoteBackLabel`, and `footnoteBackContent` from remark-rehype.
|
|
29
|
+
*
|
|
30
|
+
* `backContent` and `backLabel` each accept either a template string with
|
|
31
|
+
* the `{reference}` placeholder (substituted with `1` or `1-2` to match
|
|
32
|
+
* remark-rehype's default suffix), or a callback receiving the raw
|
|
33
|
+
* `(referenceNumber, rerunIndex)` pair.
|
|
34
|
+
*
|
|
35
|
+
* Passing this object enables footnotes. To turn them off, use
|
|
36
|
+
* `gfm: { footnotes: false }`.
|
|
37
|
+
*/
|
|
38
|
+
export interface FootnoteOptions {
|
|
39
|
+
/** `<h2>` label opening the footnotes section. Default: `"Footnotes"`. */
|
|
40
|
+
label?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Backref `<a>` content. Default: `"↩"`.
|
|
43
|
+
*
|
|
44
|
+
* Template form: the string is used as-is, and a `<sup>K</sup>` marker
|
|
45
|
+
* is auto-appended on reruns (k > 1). Callback form: returns the full
|
|
46
|
+
* content for each backref; no auto-sup is added.
|
|
47
|
+
*/
|
|
48
|
+
backContent?: string | FootnoteBackrefCallback;
|
|
49
|
+
/**
|
|
50
|
+
* Backref `aria-label`. Default: `"Back to reference {reference}"`.
|
|
51
|
+
*
|
|
52
|
+
* Template form: `{reference}` becomes `n` for the first backref, `n-K`
|
|
53
|
+
* for subsequent ones. Callback form: returns the `aria-label` string
|
|
54
|
+
* for each backref.
|
|
55
|
+
*/
|
|
56
|
+
backLabel?: string | FootnoteBackrefCallback;
|
|
57
|
+
/** Prefix applied to footnote IDs to prevent DOM clobbering. Default: `"user-content-"`. */
|
|
58
|
+
clobberPrefix?: string;
|
|
59
|
+
}
|
|
60
|
+
/** Granular GFM toggles, nested under {@link Features.gfm}. */
|
|
61
|
+
export interface GfmOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Enable GFM footnotes (`[^id]`). Default: true.
|
|
64
|
+
*
|
|
65
|
+
* Pass `false` to drop footnote parsing while keeping the rest of GFM;
|
|
66
|
+
* pass an object to enable footnotes with custom i18n strings (see
|
|
67
|
+
* {@link FootnoteOptions}).
|
|
68
|
+
*/
|
|
69
|
+
footnotes?: boolean | FootnoteOptions;
|
|
70
|
+
}
|
|
71
|
+
/** Granular math toggles, nested under {@link Features.math}. */
|
|
72
|
+
export interface MathOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Treat single-dollar runs (`$ ... $`) as inline math. Default: true.
|
|
75
|
+
*
|
|
76
|
+
* Set `false` to keep single `$` as literal text while still parsing
|
|
77
|
+
* `$$ ... $$` display math. Mirrors `singleDollarTextMath` from
|
|
78
|
+
* remark-math.
|
|
79
|
+
*/
|
|
80
|
+
singleDollarTextMath?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/** Parser feature toggles. All default to their documented value when omitted. */
|
|
83
|
+
export interface Features {
|
|
84
|
+
/**
|
|
85
|
+
* GFM: tables, footnotes, strikethrough, task lists. Default: true.
|
|
86
|
+
*
|
|
87
|
+
* Pass an options object for granular control:
|
|
88
|
+
* ```ts
|
|
89
|
+
* gfm: { footnotes: false } // skip footnotes only
|
|
90
|
+
* gfm: { footnotes: { label: "Notes" } } // localize footnotes
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
gfm?: boolean | GfmOptions;
|
|
94
|
+
/** Frontmatter: YAML (`--- ... ---`) and TOML (`+++ ... +++`). Default: true. */
|
|
95
|
+
frontmatter?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Math blocks and inline math. Default: false.
|
|
98
|
+
*
|
|
99
|
+
* Pass an options object for granular control:
|
|
100
|
+
* ```ts
|
|
101
|
+
* math: { singleDollarTextMath: false } // $$..$$ only, $..$ literal
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
math?: boolean | MathOptions;
|
|
105
|
+
/** Heading attributes (`# text { #id .class }`). Default: false. */
|
|
106
|
+
headingAttributes?: boolean;
|
|
107
|
+
/** Colon-delimited container directive blocks (`:::`). Default: false. */
|
|
108
|
+
directive?: boolean;
|
|
109
|
+
/** Superscript (`^super^`). Default: false. */
|
|
110
|
+
superscript?: boolean;
|
|
111
|
+
/** Subscript (`~sub~`). Default: false. */
|
|
112
|
+
subscript?: boolean;
|
|
113
|
+
/** Obsidian-style wikilinks (`[[link]]`). Default: false. */
|
|
114
|
+
wikilinks?: boolean;
|
|
115
|
+
/** Definition lists (a term line then a `: definition`). Default: false. */
|
|
116
|
+
definitionList?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* Smart punctuation à la SmartyPants. Default: false.
|
|
119
|
+
*
|
|
120
|
+
* Pass `true` to enable all categories, or an options object for granular control:
|
|
121
|
+
* ```ts
|
|
122
|
+
* smartPunctuation: { dashes: false } // quotes + ellipses only
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
smartPunctuation?: boolean | SmartPunctuationOptions;
|
|
126
|
+
/**
|
|
127
|
+
* Parse raw HTML embedded in Markdown into real HAST element nodes.
|
|
128
|
+
* Default: false.
|
|
129
|
+
*
|
|
130
|
+
* By default, inline and block HTML is kept as opaque `raw` nodes
|
|
131
|
+
* (re-emitted verbatim on stringify). With `rawHtml: true`, the tree is
|
|
132
|
+
* reparsed so raw HTML becomes structured `element`/`text`/`comment` nodes
|
|
133
|
+
* with normalized properties, including tags that open in one raw block
|
|
134
|
+
* and close in another. Positions are not preserved through the reparse.
|
|
135
|
+
*/
|
|
136
|
+
rawHtml?: boolean;
|
|
137
|
+
}
|
|
138
|
+
export interface CompileOptions {
|
|
139
|
+
/** MDAST plugins, in run order. A nested array runs its own plugins, in
|
|
140
|
+
* their own order, at the array's position. */
|
|
141
|
+
mdastPlugins?: MdastPluginList;
|
|
142
|
+
/** HAST plugins, in run order. Nests like `mdastPlugins`. */
|
|
143
|
+
hastPlugins?: HastPluginList;
|
|
144
|
+
features?: Features;
|
|
145
|
+
/**
|
|
146
|
+
* The document being processed, surfaced to plugins as `ctx.fileURL`. Must
|
|
147
|
+
* be a `URL` (e.g. Astro's `fileURL`); convert a filesystem path with Node's
|
|
148
|
+
* `pathToFileURL` before passing it.
|
|
149
|
+
*/
|
|
150
|
+
fileURL?: URL;
|
|
151
|
+
/**
|
|
152
|
+
* Initial document-level data bag, seeding `ctx.data` before any plugin runs.
|
|
153
|
+
* It is the same object plugins mutate and the caller reads back as
|
|
154
|
+
* `result.data`, so values flow both into and out of a compile. Defaults to a
|
|
155
|
+
* fresh empty object. Used by reference and mutated in place, so pass a
|
|
156
|
+
* throwaway object per compile rather than a shared one.
|
|
157
|
+
*/
|
|
158
|
+
data?: Data;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* JS/JSX output options, accepted by both {@link mdxToJs} and
|
|
162
|
+
* {@link markdownToJs}. Exported on its own so wrappers can expose the codegen
|
|
163
|
+
* knobs without the shared pipeline fields.
|
|
164
|
+
*/
|
|
165
|
+
export interface MdxOnlyOptions {
|
|
166
|
+
optimizeStatic?: OptimizeStaticConfig;
|
|
167
|
+
/** Place to import automatic JSX runtimes from (e.g. "react", "preact"). Default: "react". */
|
|
168
|
+
jsxImportSource?: string;
|
|
169
|
+
/** Whether to keep JSX instead of compiling it to functions. Default: false. */
|
|
170
|
+
jsx?: boolean;
|
|
171
|
+
/** JSX runtime: "automatic" (default) or "classic". */
|
|
172
|
+
jsxRuntime?: "automatic" | "classic";
|
|
173
|
+
/** Enable development mode. Default: false. */
|
|
174
|
+
development?: boolean;
|
|
175
|
+
/** Place to import the component provider from. */
|
|
176
|
+
providerImportSource?: string;
|
|
177
|
+
/** Pragma for JSX in classic runtime (default: "React.createElement"). */
|
|
178
|
+
pragma?: string;
|
|
179
|
+
/** Pragma for JSX fragments in classic runtime (default: "React.Fragment"). */
|
|
180
|
+
pragmaFrag?: string;
|
|
181
|
+
/** Where to import the pragma from in classic runtime (default: "react"). */
|
|
182
|
+
pragmaImportSource?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Output format: "program" (default) or "function-body".
|
|
185
|
+
*
|
|
186
|
+
* - `"program"`: ES module with `import`/`export` statements.
|
|
187
|
+
* - `"function-body"`: Function body that reads runtime from `arguments[0]`
|
|
188
|
+
* and returns `{ default: MDXContent, ...exports }`. Suitable for
|
|
189
|
+
* `new Function()` or `evaluate()`.
|
|
190
|
+
*/
|
|
191
|
+
outputFormat?: "program" | "function-body";
|
|
192
|
+
/**
|
|
193
|
+
* Casing for HTML/SVG attribute names on plain (rehype-produced) elements.
|
|
194
|
+
*
|
|
195
|
+
* - `"react"` (default): `className`, `htmlFor`, `strokeLinecap`, `xmlLang`.
|
|
196
|
+
* - `"html"`: `class`, `for`, `stroke-linecap`, `xml:lang`.
|
|
197
|
+
*
|
|
198
|
+
* Does not affect attributes on user-written MDX JSX; those are emitted as
|
|
199
|
+
* the author wrote them.
|
|
200
|
+
*/
|
|
201
|
+
elementAttributeNameCase?: "react" | "html";
|
|
202
|
+
/**
|
|
203
|
+
* Casing for keys in `style` objects parsed from `style="…"` strings on
|
|
204
|
+
* plain (rehype-produced) elements.
|
|
205
|
+
*
|
|
206
|
+
* - `"dom"` (default): `{backgroundColor: …, WebkitLineClamp: …}`.
|
|
207
|
+
* - `"css"`: `{"background-color": …, "-webkit-line-clamp": …}`.
|
|
208
|
+
*/
|
|
209
|
+
stylePropertyNameCase?: "dom" | "css";
|
|
210
|
+
}
|
|
211
|
+
export interface MdxCompileOptions extends CompileOptions, MdxOnlyOptions {
|
|
212
|
+
}
|
|
213
|
+
export interface MarkdownToJsOptions extends CompileOptions, MdxOnlyOptions {
|
|
214
|
+
}
|
|
215
|
+
/** Frontmatter block extracted from the parsed Markdown/MDX source. */
|
|
216
|
+
export interface Frontmatter {
|
|
217
|
+
/** Delimiter syntax used for the block. */
|
|
218
|
+
kind: "yaml" | "toml";
|
|
219
|
+
/** Raw content between the delimiters (`---`/`+++` lines excluded). */
|
|
220
|
+
value: string;
|
|
221
|
+
}
|
|
222
|
+
/** Result of {@link markdownToHtml}. */
|
|
223
|
+
export interface MarkdownToHtmlResult {
|
|
224
|
+
/** Rendered HTML string. */
|
|
225
|
+
html: string;
|
|
226
|
+
/** Frontmatter block at the start of the document, or `null` if none. */
|
|
227
|
+
frontmatter: Frontmatter | null;
|
|
228
|
+
/** Document-level data bag shared with plugins via `ctx.data`; the seeded `data` option if provided, else a fresh `{}`. */
|
|
229
|
+
data: Data;
|
|
230
|
+
}
|
|
231
|
+
/** Result of {@link mdxToJs}. */
|
|
232
|
+
export interface MdxToJsResult {
|
|
233
|
+
/** Compiled JavaScript module source. */
|
|
234
|
+
code: string;
|
|
235
|
+
/** Frontmatter block at the start of the document, or `null` if none. */
|
|
236
|
+
frontmatter: Frontmatter | null;
|
|
237
|
+
/** Document-level data bag shared with plugins via `ctx.data`; the seeded `data` option if provided, else a fresh `{}`. */
|
|
238
|
+
data: Data;
|
|
239
|
+
}
|
|
240
|
+
/** Result of {@link markdownToJs}. */
|
|
241
|
+
export interface MarkdownToJsResult {
|
|
242
|
+
/** Compiled JavaScript module source. */
|
|
243
|
+
code: string;
|
|
244
|
+
/** Frontmatter block at the start of the document, or `null` if none. */
|
|
245
|
+
frontmatter: Frontmatter | null;
|
|
246
|
+
/** Document-level data bag shared with plugins via `ctx.data`; the seeded `data` option if provided, else a fresh `{}`. */
|
|
247
|
+
data: Data;
|
|
248
|
+
}
|
|
249
|
+
export interface EvaluateOptions extends Omit<MdxCompileOptions, "jsx" | "outputFormat"> {
|
|
250
|
+
Fragment: unknown;
|
|
251
|
+
jsx: (type: unknown, props: unknown, key?: unknown) => unknown;
|
|
252
|
+
jsxs: (type: unknown, props: unknown, key?: unknown) => unknown;
|
|
253
|
+
jsxDEV?: (type: unknown, props: unknown, key: unknown, isStaticChildren: boolean, source: unknown, self: unknown) => unknown;
|
|
254
|
+
useMDXComponents?: () => Record<string, unknown>;
|
|
255
|
+
}
|
|
256
|
+
/** Options for the step-by-step tree functions. */
|
|
257
|
+
export interface TreeOptions {
|
|
258
|
+
features?: Features;
|
|
259
|
+
/**
|
|
260
|
+
* Record `position` on every node. Default: `true`.
|
|
261
|
+
*
|
|
262
|
+
* A unist position is three objects per node and roughly half a materialized
|
|
263
|
+
* tree's memory, on top of the parser's line-index build. Pass `false` when
|
|
264
|
+
* nothing downstream reads `node.position`.
|
|
265
|
+
*/
|
|
266
|
+
position?: boolean;
|
|
267
|
+
}
|
|
268
|
+
/** Options for the tree functions that stop at mdast. */
|
|
269
|
+
export interface MdastTreeOptions extends TreeOptions {
|
|
270
|
+
/** MDAST plugins, in run order. A nested array runs its own plugins, in
|
|
271
|
+
* their own order, at the array's position. */
|
|
272
|
+
mdastPlugins?: MdastPluginList;
|
|
273
|
+
/** The document being processed, surfaced to plugins as `ctx.fileURL`. */
|
|
274
|
+
fileURL?: URL;
|
|
275
|
+
/** Initial document-level data bag, seeding `ctx.data` before any plugin
|
|
276
|
+
* runs. Used by reference and mutated in place. */
|
|
277
|
+
data?: Data;
|
|
278
|
+
}
|
|
279
|
+
/** Options for the tree functions that run through to hast. */
|
|
280
|
+
export interface HastTreeOptions extends MdastTreeOptions {
|
|
281
|
+
/** HAST plugins, in run order. Nests like `mdastPlugins`. */
|
|
282
|
+
hastPlugins?: HastPluginList;
|
|
283
|
+
}
|
|
284
|
+
export interface HtmlToHastOptions {
|
|
285
|
+
/**
|
|
286
|
+
* Parse as a fragment, so the returned `root` holds the string's own
|
|
287
|
+
* top-level nodes instead of an implied `<html>`/`<head>`/`<body>`.
|
|
288
|
+
*
|
|
289
|
+
* @default false
|
|
290
|
+
*/
|
|
291
|
+
fragment?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* The namespace a fragment's own top-level content parses in. `"svg"` reads
|
|
294
|
+
* it as foreign content, so `<circle />` self-closes and lands in the SVG
|
|
295
|
+
* namespace instead of being treated as an unknown HTML element.
|
|
296
|
+
*
|
|
297
|
+
* Ignored without `fragment: true`: a document always starts in HTML.
|
|
298
|
+
*
|
|
299
|
+
* @default "html"
|
|
300
|
+
*/
|
|
301
|
+
space?: "html" | "svg";
|
|
302
|
+
}
|
|
303
|
+
type CombineAsync<A> = "async" extends A ? "async" : "maybe" extends A ? "maybe" : "sync";
|
|
304
|
+
type AnyFn = (...args: never[]) => unknown;
|
|
305
|
+
type ReturnsPromise<F> = F extends AnyFn ? [Extract<ReturnType<F>, Promise<unknown>>] extends [never] ? "sync" : [Exclude<ReturnType<F>, Promise<unknown>>] extends [never] ? "async" : "maybe" : "sync";
|
|
306
|
+
type FieldIsAsync<V> = V extends AnyFn ? ReturnsPromise<V> : V extends {
|
|
307
|
+
visit: infer F;
|
|
308
|
+
} ? ReturnsPromise<F> : V extends ReadonlyArray<infer Item> ? Item extends {
|
|
309
|
+
visit: infer F;
|
|
310
|
+
} ? ReturnsPromise<F> : "sync" : "sync";
|
|
311
|
+
type AnyVisitorAsync<P> = {
|
|
312
|
+
[K in keyof P]-?: FieldIsAsync<NonNullable<P[K]>>;
|
|
313
|
+
}[keyof P];
|
|
314
|
+
type IsPluginAsync<P> = P extends unknown ? CombineAsync<AnyVisitorAsync<P>> : never;
|
|
315
|
+
type ResolveInput<P, D extends readonly unknown[] = [0, 0, 0, 0, 0, 0, 0, 0]> = D extends readonly [
|
|
316
|
+
unknown,
|
|
317
|
+
...infer Rest
|
|
318
|
+
] ? P extends ReadonlyArray<infer Item> ? ResolveInput<Item, Rest> : P extends (...args: never[]) => infer Def ? ResolveInput<Def, Rest> : P : never;
|
|
319
|
+
type AnyInputAsync<Ps> = Ps extends ReadonlyArray<infer P> ? CombineAsync<IsPluginAsync<ResolveInput<P>>> : "sync";
|
|
320
|
+
type PluginBearingOptions = {
|
|
321
|
+
mdastPlugins?: MdastPluginList;
|
|
322
|
+
hastPlugins?: HastPluginList;
|
|
323
|
+
};
|
|
324
|
+
type OptionsAsync<O extends PluginBearingOptions> = CombineAsync<AnyInputAsync<NonNullable<O["mdastPlugins"]>> | AnyInputAsync<NonNullable<O["hastPlugins"]>>>;
|
|
325
|
+
export type ResultFor<O extends PluginBearingOptions, R> = {
|
|
326
|
+
sync: R;
|
|
327
|
+
async: Promise<R>;
|
|
328
|
+
maybe: R | Promise<R>;
|
|
329
|
+
}[OptionsAsync<O>];
|
|
330
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|