@cudoment/cudoc 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/LICENSE +21 -0
- package/README.md +58 -0
- package/dist/ast.d.ts +2 -0
- package/dist/ast.d.ts.map +1 -0
- package/dist/ast.js +2 -0
- package/dist/ast.js.map +1 -0
- package/dist/embed.d.ts +5 -0
- package/dist/embed.d.ts.map +1 -0
- package/dist/embed.js +5 -0
- package/dist/embed.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/core/ast/guards.d.ts +13 -0
- package/dist/internal/core/ast/guards.d.ts.map +1 -0
- package/dist/internal/core/ast/guards.js +21 -0
- package/dist/internal/core/ast/guards.js.map +1 -0
- package/dist/internal/core/ast/index.d.ts +6 -0
- package/dist/internal/core/ast/index.d.ts.map +1 -0
- package/dist/internal/core/ast/index.js +4 -0
- package/dist/internal/core/ast/index.js.map +1 -0
- package/dist/internal/core/ast/types.d.ts +49 -0
- package/dist/internal/core/ast/types.d.ts.map +1 -0
- package/dist/internal/core/ast/types.js +25 -0
- package/dist/internal/core/ast/types.js.map +1 -0
- package/dist/internal/core/ast/validate.d.ts +16 -0
- package/dist/internal/core/ast/validate.d.ts.map +1 -0
- package/dist/internal/core/ast/validate.js +90 -0
- package/dist/internal/core/ast/validate.js.map +1 -0
- package/dist/internal/core/index.d.ts +9 -0
- package/dist/internal/core/index.d.ts.map +1 -0
- package/dist/internal/core/index.js +7 -0
- package/dist/internal/core/index.js.map +1 -0
- package/dist/internal/core/mdx/index.d.ts +2 -0
- package/dist/internal/core/mdx/index.d.ts.map +1 -0
- package/dist/internal/core/mdx/index.js +2 -0
- package/dist/internal/core/mdx/index.js.map +1 -0
- package/dist/internal/core/mdx/jsx.d.ts +25 -0
- package/dist/internal/core/mdx/jsx.d.ts.map +1 -0
- package/dist/internal/core/mdx/jsx.js +43 -0
- package/dist/internal/core/mdx/jsx.js.map +1 -0
- package/dist/internal/core/query/index.d.ts +7 -0
- package/dist/internal/core/query/index.d.ts.map +1 -0
- package/dist/internal/core/query/index.js +4 -0
- package/dist/internal/core/query/index.js.map +1 -0
- package/dist/internal/core/query/nodes.d.ts +61 -0
- package/dist/internal/core/query/nodes.d.ts.map +1 -0
- package/dist/internal/core/query/nodes.js +151 -0
- package/dist/internal/core/query/nodes.js.map +1 -0
- package/dist/internal/core/query/sections.d.ts +72 -0
- package/dist/internal/core/query/sections.d.ts.map +1 -0
- package/dist/internal/core/query/sections.js +178 -0
- package/dist/internal/core/query/sections.js.map +1 -0
- package/dist/internal/core/query/tables.d.ts +32 -0
- package/dist/internal/core/query/tables.d.ts.map +1 -0
- package/dist/internal/core/query/tables.js +46 -0
- package/dist/internal/core/query/tables.js.map +1 -0
- package/dist/internal/core/selectors.d.ts +41 -0
- package/dist/internal/core/selectors.d.ts.map +1 -0
- package/dist/internal/core/selectors.js +87 -0
- package/dist/internal/core/selectors.js.map +1 -0
- package/dist/internal/core/syntax/delimiters.d.ts +45 -0
- package/dist/internal/core/syntax/delimiters.d.ts.map +1 -0
- package/dist/internal/core/syntax/delimiters.js +81 -0
- package/dist/internal/core/syntax/delimiters.js.map +1 -0
- package/dist/internal/core/syntax/heading-metadata.d.ts +59 -0
- package/dist/internal/core/syntax/heading-metadata.d.ts.map +1 -0
- package/dist/internal/core/syntax/heading-metadata.js +178 -0
- package/dist/internal/core/syntax/heading-metadata.js.map +1 -0
- package/dist/internal/core/syntax/index.d.ts +5 -0
- package/dist/internal/core/syntax/index.d.ts.map +1 -0
- package/dist/internal/core/syntax/index.js +3 -0
- package/dist/internal/core/syntax/index.js.map +1 -0
- package/dist/internal/core/walk.d.ts +40 -0
- package/dist/internal/core/walk.d.ts.map +1 -0
- package/dist/internal/core/walk.js +53 -0
- package/dist/internal/core/walk.js.map +1 -0
- package/dist/mdx.d.ts +2 -0
- package/dist/mdx.d.ts.map +1 -0
- package/dist/mdx.js +2 -0
- package/dist/mdx.js.map +1 -0
- package/dist/node/export-ast.d.ts +52 -0
- package/dist/node/export-ast.d.ts.map +1 -0
- package/dist/node/export-ast.js +117 -0
- package/dist/node/export-ast.js.map +1 -0
- package/dist/node/index.d.ts +7 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +4 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/load-ast-file.d.ts +9 -0
- package/dist/node/load-ast-file.d.ts.map +1 -0
- package/dist/node/load-ast-file.js +32 -0
- package/dist/node/load-ast-file.js.map +1 -0
- package/dist/node/load-ast.d.ts +11 -0
- package/dist/node/load-ast.d.ts.map +1 -0
- package/dist/node/load-ast.js +17 -0
- package/dist/node/load-ast.js.map +1 -0
- package/dist/node/paths.d.ts +31 -0
- package/dist/node/paths.d.ts.map +1 -0
- package/dist/node/paths.js +54 -0
- package/dist/node/paths.js.map +1 -0
- package/dist/query.d.ts +2 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +2 -0
- package/dist/query.js.map +1 -0
- package/dist/syntax.d.ts +2 -0
- package/dist/syntax.d.ts.map +1 -0
- package/dist/syntax.js +2 -0
- package/dist/syntax.js.map +1 -0
- package/package.json +94 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 cudoment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @cudoment/cudoc
|
|
2
|
+
|
|
3
|
+
Reuse document sections and tables from compiled MDX ASTs. Export a snapshot during compilation, load it on the server, select content by a stable anchor and render it with your site's components.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @cudoment/cudoc
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Embedding
|
|
10
|
+
|
|
11
|
+
Add the export plugin after the transforms whose results you want to store:
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import exportAst from "@cudoment/cudoc/embed"
|
|
15
|
+
|
|
16
|
+
const remarkPlugins = [
|
|
17
|
+
// Your remark transforms go here.
|
|
18
|
+
[exportAst, { sourceRoot: "docs", outDir: ".cudoc/ast" }],
|
|
19
|
+
]
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Once the source document has compiled, read it in a server component or build script:
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import { loadAst, sliceSectionByAnchorId } from "@cudoment/cudoc/embed"
|
|
26
|
+
|
|
27
|
+
const document = loadAst("guide/limits", { outDir: ".cudoc/ast" })
|
|
28
|
+
const section = sliceSectionByAnchorId(document, "rate-limits")
|
|
29
|
+
if (!section) throw new Error("Missing section: rate-limits")
|
|
30
|
+
// Render section.children with your site's components.
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The snapshot is the host's remark tree at the export plugin. Later host transforms and MDX component execution are outside it. Export and load validate the same AST contract and schema version. Section slices preserve referenced link, image and footnote definitions.
|
|
34
|
+
|
|
35
|
+
Source compilation must finish before loading an embed. Keep compiler caches and exported ASTs together, and include the JSON files in deployments that read them at runtime. Queries do not execute MDX expressions; rendering and missing-reference policy belong to the consuming site.
|
|
36
|
+
|
|
37
|
+
## Entry points
|
|
38
|
+
|
|
39
|
+
| Import | Runtime | Purpose |
|
|
40
|
+
| ---------------------------------------------------------------------- | --------------- | ------------------------------------------------------- |
|
|
41
|
+
| `@cudoment/cudoc` | Browser or Node | AST contract, validation, traversal, syntax and queries |
|
|
42
|
+
| `@cudoment/cudoc/query` | Browser or Node | Sections, headings, text and table queries |
|
|
43
|
+
| `@cudoment/cudoc/ast`, `@cudoment/cudoc/syntax`, `@cudoment/cudoc/mdx` | Browser or Node | Focused common APIs |
|
|
44
|
+
| `@cudoment/cudoc/embed` | Node | AST export, loading and queries together |
|
|
45
|
+
| `@cudoment/cudoc/node/load-ast-file` | Node | Load a known JSON file without build-time path mapping |
|
|
46
|
+
| `@cudoment/cudoc/node/export-ast`, `@cudoment/cudoc/node/paths` | Node | Focused export and path APIs |
|
|
47
|
+
|
|
48
|
+
All entries share one internal core. Internal source paths are not public exports and the core is not a separate npm package. Browser imports never depend on the Node entry points.
|
|
49
|
+
|
|
50
|
+
For a server bundle that traces files, use `loadAstFile` from `@cudoment/cudoc/node/load-ast-file` with a concrete file path and configure your host's output file tracing.
|
|
51
|
+
|
|
52
|
+
The optional `cudoc-remark`, `cudoc-docusaurus` and `cudoc-nextra` packages provide syntax transforms and host integration. Their publication is separate from this package.
|
|
53
|
+
|
|
54
|
+
See the [embedding guide](https://github.com/cudoment/cudoc/blob/main/docs/embedding.md) and [project README](https://github.com/cudoment/cudoc#readme).
|
|
55
|
+
|
|
56
|
+
## License
|
|
57
|
+
|
|
58
|
+
[MIT](./LICENSE)
|
package/dist/ast.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA"}
|
package/dist/ast.js
ADDED
package/dist/ast.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAA"}
|
package/dist/embed.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.d.ts","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gCAAgC,CAAA"}
|
package/dist/embed.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embed.js","sourceRoot":"","sources":["../src/embed.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gCAAgC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,cAAc,0BAA0B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAClE,cAAc,0BAA0B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { List, ListItem } from "mdast";
|
|
2
|
+
import type { Node, Parent } from "unist";
|
|
3
|
+
import type { CudocTableCell, CudocTableCellElement } from "./types.js";
|
|
4
|
+
export declare const isParent: (node: Node) => node is Parent;
|
|
5
|
+
export declare const isList: (node: Node) => node is List;
|
|
6
|
+
export declare const isListItem: (node: Node) => node is ListItem;
|
|
7
|
+
export declare const isTableCell: (node: Node) => node is CudocTableCell;
|
|
8
|
+
/**
|
|
9
|
+
* A generated cell element. The element name is configurable because a host
|
|
10
|
+
* may map table cells onto its own component.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isTableCellElement: (node: Node, elementName?: string | readonly string[]) => node is CudocTableCellElement;
|
|
13
|
+
//# sourceMappingURL=guards.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/ast/guards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAGvE,eAAO,MAAM,QAAQ,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,MACkB,CAAA;AAEhE,eAAO,MAAM,MAAM,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,IAA4B,CAAA;AAExE,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,QACtB,CAAA;AAE1B,eAAO,MAAM,WAAW,GAAI,MAAM,IAAI,KAAG,IAAI,IAAI,cACtB,CAAA;AAE3B;;;GAGG;AACH,eAAO,MAAM,kBAAkB,GAC7B,MAAM,IAAI,EACV,cAAa,MAAM,GAAG,SAAS,MAAM,EAIpC,KACA,IAAI,IAAI,qBASR,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CUDOC_TABLE_CELL_ELEMENT } from "./types.js";
|
|
2
|
+
export const isParent = (node) => "children" in node && Array.isArray(node.children);
|
|
3
|
+
export const isList = (node) => node.type === "list";
|
|
4
|
+
export const isListItem = (node) => node.type === "listItem";
|
|
5
|
+
export const isTableCell = (node) => node.type === "tableCell";
|
|
6
|
+
/**
|
|
7
|
+
* A generated cell element. The element name is configurable because a host
|
|
8
|
+
* may map table cells onto its own component.
|
|
9
|
+
*/
|
|
10
|
+
export const isTableCellElement = (node, elementName = [
|
|
11
|
+
"td",
|
|
12
|
+
"th",
|
|
13
|
+
CUDOC_TABLE_CELL_ELEMENT,
|
|
14
|
+
]) => (node.type === "mdxJsxTextElement" || node.type === "mdxJsxFlowElement") &&
|
|
15
|
+
// The MDX compiler marks source-authored JSX before user plugins run.
|
|
16
|
+
// Its ordinary lists (including task lists) belong to the host, not cudoc's
|
|
17
|
+
// generated table-list contract.
|
|
18
|
+
node.data?._mdxExplicitJsx !==
|
|
19
|
+
true &&
|
|
20
|
+
(typeof elementName === "string" ? [elementName] : elementName).includes(node.name ?? "");
|
|
21
|
+
//# sourceMappingURL=guards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../src/internal/core/ast/guards.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAErD,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,IAAU,EAAkB,EAAE,CACrD,UAAU,IAAI,IAAI,IAAI,KAAK,CAAC,OAAO,CAAE,IAAe,CAAC,QAAQ,CAAC,CAAA;AAEhE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAU,EAAgB,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAA;AAExE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAU,EAAoB,EAAE,CACzD,IAAI,CAAC,IAAI,KAAK,UAAU,CAAA;AAE1B,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAU,EAA0B,EAAE,CAChE,IAAI,CAAC,IAAI,KAAK,WAAW,CAAA;AAE3B;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,cAA0C;IACxC,IAAI;IACJ,IAAI;IACJ,wBAAwB;CACzB,EAC8B,EAAE,CACjC,CAAC,IAAI,CAAC,IAAI,KAAK,mBAAmB,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,CAAC;IACxE,sEAAsE;IACtE,4EAA4E;IAC5E,iCAAiC;IAChC,IAAI,CAAC,IAAkD,EAAE,eAAe;QACvE,IAAI;IACN,CAAC,OAAO,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,CACrE,IAAiC,CAAC,IAAI,IAAI,EAAE,CAC9C,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { CUDOC_AST_VERSION, CUDOC_AST_VERSION_FIELD, CUDOC_TABLE_CELL_ELEMENT, resolveAstVersion, } from "./types.js";
|
|
2
|
+
export type { AstVersionOptions, CudocAstRoot, CudocTable, CudocTableCell, CudocTableCellContent, CudocTableCellElement, CudocTableRow, ExportedCudocAstRoot, ResolvedAstVersion, } from "./types.js";
|
|
3
|
+
export { isList, isListItem, isParent, isTableCell, isTableCellElement, } from "./guards.js";
|
|
4
|
+
export { validateAstContract } from "./validate.js";
|
|
5
|
+
export type { ValidateAstOptions } from "./validate.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AACnB,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA;AACnD,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CUDOC_AST_VERSION, CUDOC_AST_VERSION_FIELD, CUDOC_TABLE_CELL_ELEMENT, resolveAstVersion, } from "./types.js";
|
|
2
|
+
export { isList, isListItem, isParent, isTableCell, isTableCellElement, } from "./guards.js";
|
|
3
|
+
export { validateAstContract } from "./validate.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/core/ast/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,YAAY,CAAA;AAYnB,OAAO,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AST contract shared by the render tree and any stored JSON.
|
|
3
|
+
*
|
|
4
|
+
* Standard mdast `list`, `listItem` and `paragraph` are reused inside table
|
|
5
|
+
* cells rather than introducing cudoc-specific node types, so a consumer that
|
|
6
|
+
* understands mdast understands a cudoc tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { List, PhrasingContent, Root, Table, TableCell, TableRow } from "mdast";
|
|
9
|
+
import type { MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx-jsx";
|
|
10
|
+
/** Schema version written by this release when the caller does not choose one. */
|
|
11
|
+
export declare const CUDOC_AST_VERSION = 1;
|
|
12
|
+
/** The field under `root.data` that carries the schema version. */
|
|
13
|
+
export declare const CUDOC_AST_VERSION_FIELD = "cudocAstVersion";
|
|
14
|
+
/** The generated element name a table cell takes when a table is rendered as JSX. */
|
|
15
|
+
export declare const CUDOC_TABLE_CELL_ELEMENT = "TableCell";
|
|
16
|
+
export type CudocTableCellContent = PhrasingContent | List;
|
|
17
|
+
export type CudocTableCell = Omit<TableCell, "children"> & {
|
|
18
|
+
children: CudocTableCellContent[];
|
|
19
|
+
};
|
|
20
|
+
export type CudocTableRow = Omit<TableRow, "children"> & {
|
|
21
|
+
children: CudocTableCell[];
|
|
22
|
+
};
|
|
23
|
+
export type CudocTable = Omit<Table, "children"> & {
|
|
24
|
+
children: CudocTableRow[];
|
|
25
|
+
};
|
|
26
|
+
export type CudocTableCellElement = Omit<MdxJsxTextElement | MdxJsxFlowElement, "children"> & {
|
|
27
|
+
children: CudocTableCellContent[];
|
|
28
|
+
};
|
|
29
|
+
type CudocAstData = NonNullable<Root["data"]> & Record<string, unknown>;
|
|
30
|
+
export type CudocAstRoot = Omit<Root, "data"> & {
|
|
31
|
+
data?: CudocAstData;
|
|
32
|
+
};
|
|
33
|
+
export type ExportedCudocAstRoot = Omit<CudocAstRoot, "data"> & {
|
|
34
|
+
data: CudocAstData;
|
|
35
|
+
};
|
|
36
|
+
/** How a tree identifies its schema version. Both halves are serializable. */
|
|
37
|
+
export type AstVersionOptions = {
|
|
38
|
+
/** Field name under `root.data`. Defaults to `cudocAstVersion`. */
|
|
39
|
+
field?: string;
|
|
40
|
+
/** Value written and expected. Defaults to {@link CUDOC_AST_VERSION}. */
|
|
41
|
+
value?: number;
|
|
42
|
+
};
|
|
43
|
+
export type ResolvedAstVersion = {
|
|
44
|
+
field: string;
|
|
45
|
+
value: number;
|
|
46
|
+
};
|
|
47
|
+
export declare const resolveAstVersion: (options?: AstVersionOptions) => ResolvedAstVersion;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/ast/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACT,MAAM,OAAO,CAAA;AACd,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAE9E,kFAAkF;AAClF,eAAO,MAAM,iBAAiB,IAAI,CAAA;AAElC,mEAAmE;AACnE,eAAO,MAAM,uBAAuB,oBAAoB,CAAA;AAExD,qFAAqF;AACrF,eAAO,MAAM,wBAAwB,cAAc,CAAA;AAEnD,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,IAAI,CAAA;AAE1D,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG;IACzD,QAAQ,EAAE,qBAAqB,EAAE,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,GAAG;IACvD,QAAQ,EAAE,cAAc,EAAE,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG;IACjD,QAAQ,EAAE,aAAa,EAAE,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,iBAAiB,GAAG,iBAAiB,EACrC,UAAU,CACX,GAAG;IACF,QAAQ,EAAE,qBAAqB,EAAE,CAAA;CAClC,CAAA;AAED,KAAK,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEvE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG;IAC9C,IAAI,CAAC,EAAE,YAAY,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,GAAG;IAC9D,IAAI,EAAE,YAAY,CAAA;CACnB,CAAA;AAED,8EAA8E;AAC9E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,UAAS,iBAAsB,KAC9B,kBAYF,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AST contract shared by the render tree and any stored JSON.
|
|
3
|
+
*
|
|
4
|
+
* Standard mdast `list`, `listItem` and `paragraph` are reused inside table
|
|
5
|
+
* cells rather than introducing cudoc-specific node types, so a consumer that
|
|
6
|
+
* understands mdast understands a cudoc tree.
|
|
7
|
+
*/
|
|
8
|
+
/** Schema version written by this release when the caller does not choose one. */
|
|
9
|
+
export const CUDOC_AST_VERSION = 1;
|
|
10
|
+
/** The field under `root.data` that carries the schema version. */
|
|
11
|
+
export const CUDOC_AST_VERSION_FIELD = "cudocAstVersion";
|
|
12
|
+
/** The generated element name a table cell takes when a table is rendered as JSX. */
|
|
13
|
+
export const CUDOC_TABLE_CELL_ELEMENT = "TableCell";
|
|
14
|
+
export const resolveAstVersion = (options = {}) => {
|
|
15
|
+
const field = options.field ?? CUDOC_AST_VERSION_FIELD;
|
|
16
|
+
const value = options.value ?? CUDOC_AST_VERSION;
|
|
17
|
+
if (typeof field !== "string" || !field) {
|
|
18
|
+
throw new TypeError("version.field must be a non-empty string");
|
|
19
|
+
}
|
|
20
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
21
|
+
throw new TypeError("version.value must be a safe integer");
|
|
22
|
+
}
|
|
23
|
+
return { field, value };
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/internal/core/ast/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,kFAAkF;AAClF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAElC,mEAAmE;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,iBAAiB,CAAA;AAExD,qFAAqF;AACrF,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAA;AA8CnD,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,UAA6B,EAAE,EACX,EAAE;IACtB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,uBAAuB,CAAA;IACtD,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,iBAAiB,CAAA;IAEhD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACxC,MAAM,IAAI,SAAS,CAAC,0CAA0C,CAAC,CAAA;IACjE,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAA;IAC7D,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AACzB,CAAC,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates the root envelope and the table-list rules that the render tree and
|
|
3
|
+
* the stored JSON must both satisfy. It does not validate the whole mdast
|
|
4
|
+
* schema, and it does not narrow the input type.
|
|
5
|
+
*/
|
|
6
|
+
import { type AstVersionOptions } from "./types.js";
|
|
7
|
+
export type ValidateAstOptions = {
|
|
8
|
+
/** Require the version field to be present and to match. Defaults to false. */
|
|
9
|
+
requireVersion?: boolean;
|
|
10
|
+
/** Where the version lives and what it must be. */
|
|
11
|
+
version?: AstVersionOptions;
|
|
12
|
+
/** Generated cell names. Defaults to `td`, `th` and legacy `TableCell`. */
|
|
13
|
+
tableCellElement?: string | readonly string[];
|
|
14
|
+
};
|
|
15
|
+
export declare function validateAstContract(value: unknown, { requireVersion, version, tableCellElement, }?: ValidateAstOptions): void;
|
|
16
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/ast/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EAAqB,KAAK,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAEtE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,mDAAmD;IACnD,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAA;CAC9C,CAAA;AAiID,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,OAAO,EACd,EACE,cAAsB,EACtB,OAAO,EACP,gBAAgB,GACjB,GAAE,kBAAuB,GACzB,IAAI,CAgBN"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates the root envelope and the table-list rules that the render tree and
|
|
3
|
+
* the stored JSON must both satisfy. It does not validate the whole mdast
|
|
4
|
+
* schema, and it does not narrow the input type.
|
|
5
|
+
*/
|
|
6
|
+
import { isList, isListItem, isParent, isTableCell, isTableCellElement, } from "./guards.js";
|
|
7
|
+
import { resolveAstVersion } from "./types.js";
|
|
8
|
+
const formatPath = (path) => path.join(" > ") || "root";
|
|
9
|
+
const isAstRootEnvelope = (value) => Boolean(value &&
|
|
10
|
+
typeof value === "object" &&
|
|
11
|
+
value.type === "root" &&
|
|
12
|
+
Array.isArray(value.children));
|
|
13
|
+
const getNodeType = (value) => value &&
|
|
14
|
+
typeof value === "object" &&
|
|
15
|
+
typeof value.type === "string"
|
|
16
|
+
? value.type
|
|
17
|
+
: "unknown";
|
|
18
|
+
const assertTableListItem = (item, path) => {
|
|
19
|
+
if (item.spread !== false) {
|
|
20
|
+
throw new Error(`cudoc AST validation failed: table listItem spread must be false (${formatPath(path)})`);
|
|
21
|
+
}
|
|
22
|
+
if (item.checked !== null) {
|
|
23
|
+
throw new Error(`cudoc AST validation failed: table listItem checked must be null (${formatPath(path)})`);
|
|
24
|
+
}
|
|
25
|
+
for (const child of item.children) {
|
|
26
|
+
if (child.type !== "paragraph" && child.type !== "list") {
|
|
27
|
+
throw new Error(`cudoc AST validation failed: table listItem children must be paragraph or list (${formatPath(path)})`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const assertTableList = (list, path) => {
|
|
32
|
+
if (list.spread !== false) {
|
|
33
|
+
throw new Error(`cudoc AST validation failed: table list spread must be false (${formatPath(path)})`);
|
|
34
|
+
}
|
|
35
|
+
if (typeof list.ordered !== "boolean") {
|
|
36
|
+
throw new Error(`cudoc AST validation failed: table list ordered must be boolean (${formatPath(path)})`);
|
|
37
|
+
}
|
|
38
|
+
if (list.ordered) {
|
|
39
|
+
if (typeof list.start !== "number" || !Number.isSafeInteger(list.start)) {
|
|
40
|
+
throw new Error(`cudoc AST validation failed: ordered table list requires a safe integer start (${formatPath(path)})`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (list.start !== null) {
|
|
44
|
+
throw new Error(`cudoc AST validation failed: unordered table list start must be null (${formatPath(path)})`);
|
|
45
|
+
}
|
|
46
|
+
for (const child of list.children) {
|
|
47
|
+
if (!isListItem(child)) {
|
|
48
|
+
throw new Error(`cudoc AST validation failed: table list children must be listItem (${formatPath(path)})`);
|
|
49
|
+
}
|
|
50
|
+
assertTableListItem(child, [...path, "listItem"]);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const validateNode = (value, parent, path, inTableCell, inTableList, tableCellElement) => {
|
|
54
|
+
if (getNodeType(value) === "unknown")
|
|
55
|
+
return;
|
|
56
|
+
const node = value;
|
|
57
|
+
if (isListItem(node) && (!parent || !isList(parent))) {
|
|
58
|
+
throw new Error(`cudoc AST validation failed: listItem must be a direct child of list (${formatPath(path)})`);
|
|
59
|
+
}
|
|
60
|
+
const isCell = isTableCell(node) || isTableCellElement(node, tableCellElement);
|
|
61
|
+
const isWithinTableCell = inTableCell || isCell;
|
|
62
|
+
const parentAllowsTableList = Boolean(parent && isTableCell(parent)) ||
|
|
63
|
+
Boolean(parent && isTableCellElement(parent, tableCellElement)) ||
|
|
64
|
+
(inTableList && parent?.type === "listItem");
|
|
65
|
+
const isCurrentTableList = isList(node) && parentAllowsTableList;
|
|
66
|
+
if (isList(node) && isWithinTableCell && !parentAllowsTableList) {
|
|
67
|
+
throw new Error(`cudoc AST validation failed: table list is not allowed under ${parent?.type ?? "root"} (${formatPath(path)})`);
|
|
68
|
+
}
|
|
69
|
+
if (isCurrentTableList)
|
|
70
|
+
assertTableList(node, path);
|
|
71
|
+
if (!isParent(node))
|
|
72
|
+
return;
|
|
73
|
+
node.children.forEach((child, index) => {
|
|
74
|
+
validateNode(child, node, [...path, `${getNodeType(child)}[${index}]`], isWithinTableCell, inTableList || isCurrentTableList, tableCellElement);
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export function validateAstContract(value, { requireVersion = false, version, tableCellElement, } = {}) {
|
|
78
|
+
if (!isAstRootEnvelope(value)) {
|
|
79
|
+
throw new Error("cudoc AST validation failed: invalid root node");
|
|
80
|
+
}
|
|
81
|
+
if (requireVersion) {
|
|
82
|
+
const { field, value: expected } = resolveAstVersion(version);
|
|
83
|
+
const actual = value.data?.[field];
|
|
84
|
+
if (actual !== expected) {
|
|
85
|
+
throw new Error(`cudoc AST validation failed: expected ${field} ${expected}, received ${String(actual)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
validateNode(value, undefined, ["root"], false, false, tableCellElement);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../../../../src/internal/core/ast/validate.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,WAAW,EACX,kBAAkB,GACnB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,iBAAiB,EAA0B,MAAM,YAAY,CAAA;AAWtE,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAA;AAQjE,MAAM,iBAAiB,GAAG,CAAC,KAAc,EAA4B,EAAE,CACrE,OAAO,CACL,KAAK;IACL,OAAO,KAAK,KAAK,QAAQ;IACxB,KAA4B,CAAC,IAAI,KAAK,MAAM;IAC7C,KAAK,CAAC,OAAO,CAAE,KAAgC,CAAC,QAAQ,CAAC,CAC1D,CAAA;AAEH,MAAM,WAAW,GAAG,CAAC,KAAc,EAAU,EAAE,CAC7C,KAAK;IACL,OAAO,KAAK,KAAK,QAAQ;IACzB,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;IACpD,CAAC,CAAE,KAA0B,CAAC,IAAI;IAClC,CAAC,CAAC,SAAS,CAAA;AAEf,MAAM,mBAAmB,GAAG,CAAC,IAAc,EAAE,IAAc,EAAE,EAAE;IAC7D,IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qEAAqE,UAAU,CAAC,IAAI,CAAC,GAAG,CACzF,CAA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,CAAC,CAAA;AAC1E,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./ast/index.js";
|
|
2
|
+
export * from "./syntax/index.js";
|
|
3
|
+
export * from "./mdx/index.js";
|
|
4
|
+
export * from "./query/index.js";
|
|
5
|
+
export { walk } from "./walk.js";
|
|
6
|
+
export type { AncestorLocation, Transform, TransformContext, TransformState, } from "./walk.js";
|
|
7
|
+
export { assertSectionSelector, compactTitle, findPreviousHeading, getInlineText, matchesSectionHeading, normalizeHeaderText, normalizeTitle, } from "./selectors.js";
|
|
8
|
+
export type { SectionSelector } from "./selectors.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/internal/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,YAAY,EACV,gBAAgB,EAChB,SAAS,EACT,gBAAgB,EAChB,cAAc,GACf,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACf,MAAM,gBAAgB,CAAA;AACvB,YAAY,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from "./ast/index.js";
|
|
2
|
+
export * from "./syntax/index.js";
|
|
3
|
+
export * from "./mdx/index.js";
|
|
4
|
+
export * from "./query/index.js";
|
|
5
|
+
export { walk } from "./walk.js";
|
|
6
|
+
export { assertSectionSelector, compactTitle, findPreviousHeading, getInlineText, matchesSectionHeading, normalizeHeaderText, normalizeTitle, } from "./selectors.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/internal/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAOhC,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,GACf,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/mdx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/core/mdx/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACpB,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,UAAU,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Factories and guards for the MDX JSX nodes cudoc produces. */
|
|
2
|
+
import type { PhrasingContent } from "mdast";
|
|
3
|
+
import type { MdxJsxAttribute, MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx-jsx";
|
|
4
|
+
import type { Node } from "unist";
|
|
5
|
+
export declare const createMdxAttribute: (name: string, value: string) => MdxJsxAttribute;
|
|
6
|
+
export declare const createMdxTextElement: (name: string, children: PhrasingContent[], attributes?: MdxJsxAttribute[]) => MdxJsxTextElement;
|
|
7
|
+
type NamedMdxJsxTextElement<Name extends string> = MdxJsxTextElement & {
|
|
8
|
+
name: Name;
|
|
9
|
+
};
|
|
10
|
+
export declare const isMdxTextElementNamed: <Name extends string>(node: Node, name: Name) => node is NamedMdxJsxTextElement<Name>;
|
|
11
|
+
/**
|
|
12
|
+
* The element an author uses for an explicit line break inside a cell. The name
|
|
13
|
+
* is configurable because it is host markup, not cudoc syntax.
|
|
14
|
+
*/
|
|
15
|
+
export declare const createLineBreakElement: (name: string) => MdxJsxTextElement;
|
|
16
|
+
export declare const isLineBreakElement: (node: Node, name: string) => boolean;
|
|
17
|
+
type MdxJsxTextElementLike = Omit<MdxJsxTextElement, "children"> & {
|
|
18
|
+
children: unknown[];
|
|
19
|
+
};
|
|
20
|
+
export declare const asFlowChildren: (children: MdxJsxTextElementLike[]) => MdxJsxFlowElement["children"];
|
|
21
|
+
export declare const createMdxFlowElement: (name: string, children?: MdxJsxFlowElement["children"], attributes?: MdxJsxAttribute[]) => MdxJsxFlowElement;
|
|
22
|
+
export declare const setStringAttribute: (attributes: MdxJsxTextElement["attributes"], name: string, value: string) => void;
|
|
23
|
+
export declare const readStringAttribute: (element: MdxJsxTextElement | undefined, name: string) => string | undefined;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=jsx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/mdx/jsx.ts"],"names":[],"mappings":"AAAA,iEAAiE;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAC5C,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAEjC,eAAO,MAAM,kBAAkB,GA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= (name, value) => ({
|
|
3
|
+
type: "mdxJsxAttribute",
|
|
4
|
+
name,
|
|
5
|
+
value,
|
|
6
|
+
});
|
|
7
|
+
export const createMdxTextElement = (name, children, attributes = []) => ({
|
|
8
|
+
type: "mdxJsxTextElement",
|
|
9
|
+
name,
|
|
10
|
+
attributes,
|
|
11
|
+
children,
|
|
12
|
+
});
|
|
13
|
+
export const isMdxTextElementNamed = (node, name) => node.type === "mdxJsxTextElement" && node.name === name;
|
|
14
|
+
/**
|
|
15
|
+
* The element an author uses for an explicit line break inside a cell. The name
|
|
16
|
+
* is configurable because it is host markup, not cudoc syntax.
|
|
17
|
+
*/
|
|
18
|
+
export const createLineBreakElement = (name) => createMdxTextElement(name, []);
|
|
19
|
+
export const isLineBreakElement = (node, name) => isMdxTextElementNamed(node, name);
|
|
20
|
+
export const asFlowChildren = (children) => children;
|
|
21
|
+
export const createMdxFlowElement = (name, children = [], attributes = []) => ({
|
|
22
|
+
type: "mdxJsxFlowElement",
|
|
23
|
+
name,
|
|
24
|
+
attributes,
|
|
25
|
+
children,
|
|
26
|
+
});
|
|
27
|
+
export const setStringAttribute = (attributes, name, value) => {
|
|
28
|
+
const attribute = createMdxAttribute(name, value);
|
|
29
|
+
const index = attributes.findIndex((candidate) => candidate.type === "mdxJsxAttribute" && candidate.name === name);
|
|
30
|
+
if (index === -1)
|
|
31
|
+
attributes.push(attribute);
|
|
32
|
+
else
|
|
33
|
+
attributes[index] = attribute;
|
|
34
|
+
};
|
|
35
|
+
export const readStringAttribute = (element, name) => {
|
|
36
|
+
if (!element)
|
|
37
|
+
return undefined;
|
|
38
|
+
const attribute = element.attributes.find((candidate) => "name" in candidate && candidate.name === name);
|
|
39
|
+
if (!attribute || typeof attribute.value !== "string")
|
|
40
|
+
return undefined;
|
|
41
|
+
return attribute.value;
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=jsx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx.js","sourceRoot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K,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,UAAU,CAAC,SAAS,CAChC,CAAC,SAAS,EAAgC,EAAE,CAC1C,SAAS,CAAC,IAAI,KAAK,iBAAiB,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAClE,CAAA;IACD,IAAI,KAAK,KAAK,CAAC,CAAC;QAAE,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;;QACvC,UAAU,CAAC,KAAK,CAAC,GAAG,SAAS,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,OAAsC,EACtC,IAAY,EACQ,EAAE;IACtB,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAE9B,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,IAAI,CACvC,CAAC,SAAS,EAAE,EAAE,CAAC,MAAM,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,IAAI,CAC9D,CAAA;IACD,IAAI,CAAC,SAAS,IAAI,OAAO,SAAS,CAAC,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAA;IAEvE,OAAO,SAAS,CAAC,KAAK,CAAA;AACxB,CAAC,CAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { findSiblingNode, getNodeText } from "./nodes.js";
|
|
2
|
+
export type { Direction, FindSiblingOptions, NodeTextOptions } from "./nodes.js";
|
|
3
|
+
export { findHeadingByAnchorId, findParentHeading, findSectionEnd, getHeadingAnchorId, getHeadingBadge, normalizeAnchorId, sliceSectionByAnchorId, } from "./sections.js";
|
|
4
|
+
export type { AnchorLookupOptions, HeadingLocation, SliceSectionOptions, } from "./sections.js";
|
|
5
|
+
export { findTableColumnIndex, getTableCellNodes, getTableCellText, getTableHeaderTexts, } from "./tables.js";
|
|
6
|
+
export type { CellPosition } from "./tables.js";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/internal/core/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACzD,YAAY,EAAE,SAAS,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAChF,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,eAAe,CAAA;AACtB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,mBAAmB,GACpB,MAAM,eAAe,CAAA;AACtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { findSiblingNode, getNodeText } from "./nodes.js";
|
|
2
|
+
export { findHeadingByAnchorId, findParentHeading, findSectionEnd, getHeadingAnchorId, getHeadingBadge, normalizeAnchorId, sliceSectionByAnchorId, } from "./sections.js";
|
|
3
|
+
export { findTableColumnIndex, getTableCellNodes, getTableCellText, getTableHeaderTexts, } from "./tables.js";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/internal/core/query/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEzD,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,eAAe,CAAA;AAMtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,aAAa,CAAA"}
|