@unifast/react 0.0.4 → 0.0.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.
Files changed (3) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +73 -0
  3. package/package.json +21 -3
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 kenzwada
3
+ Copyright (c) 2025 Kenzo-Wada
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # @unifast/react
2
+
3
+ Convert [unifast](https://kenzo-pj.github.io/unifast/) compilation output to React elements.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @unifast/react @unifast/node react
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```tsx
14
+ import { compileToReact } from "@unifast/react";
15
+ import { createElement, Fragment } from "react";
16
+
17
+ const { element, frontmatter, toc } = compileToReact("# Hello\n\nWorld", {
18
+ createElement,
19
+ Fragment,
20
+ });
21
+
22
+ // Use `element` directly in JSX
23
+ function MyPage() {
24
+ return <article>{element}</article>;
25
+ }
26
+ ```
27
+
28
+ ### Custom Components
29
+
30
+ ```tsx
31
+ const { element } = compileToReact(markdown, {
32
+ createElement,
33
+ Fragment,
34
+ components: {
35
+ h1: ({ children }) => <h1 className="title">{children}</h1>,
36
+ a: ({ href, children }) => <Link to={href}>{children}</Link>,
37
+ code: ({ children }) => <CodeBlock>{children}</CodeBlock>,
38
+ },
39
+ });
40
+ ```
41
+
42
+ ## API
43
+
44
+ ### `compileToReact(input, options)`
45
+
46
+ Compile Markdown to a React element tree.
47
+
48
+ - **`input`** (`string`) — Markdown/MDX source
49
+ - **`options`** (`CompileToReactOptions`) — Extends `CompileOptions` with:
50
+ - `createElement` — React's `createElement` function
51
+ - `Fragment` — React's `Fragment` component
52
+ - `components` — Map of tag names to custom React components
53
+
54
+ Returns `CompileToReactResult`:
55
+
56
+ | Property | Type | Description |
57
+ |----------|------|-------------|
58
+ | `element` | `ReactElement` | Rendered React element tree |
59
+ | `frontmatter` | `Record<string, unknown>` | Extracted metadata |
60
+ | `diagnostics` | `Diagnostic[]` | Compilation diagnostics |
61
+ | `stats` | `object` | Performance timing |
62
+ | `toc` | `TocEntry[]` | Table of contents |
63
+
64
+ ### `hastToReact(hast, options)`
65
+
66
+ Lower-level API: convert a HAST tree directly to React elements.
67
+
68
+ - **`hast`** (`HastRoot`) — HAST tree from unifast compilation
69
+ - **`options`** (`HastToReactOptions`) — `createElement`, `Fragment`, `components`
70
+
71
+ ## License
72
+
73
+ [MIT](https://github.com/kenzo-pj/unifast/blob/main/LICENSE)
package/package.json CHANGED
@@ -1,7 +1,25 @@
1
1
  {
2
2
  "name": "@unifast/react",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Convert HAST to React elements for unifast",
5
+ "license": "MIT",
6
+ "author": "Kenzo-Wada",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kenzo-pj/unifast",
10
+ "directory": "packages/react"
11
+ },
12
+ "homepage": "https://kenzo-pj.github.io/unifast/",
13
+ "bugs": {
14
+ "url": "https://github.com/kenzo-pj/unifast/issues"
15
+ },
16
+ "keywords": [
17
+ "unifast",
18
+ "markdown",
19
+ "mdx",
20
+ "react",
21
+ "hast"
22
+ ],
5
23
  "files": [
6
24
  "dist"
7
25
  ],
@@ -20,8 +38,8 @@
20
38
  },
21
39
  "dependencies": {
22
40
  "style-to-object": "^1.0.14",
23
- "@unifast/core": "0.0.4",
24
- "@unifast/node": "0.0.4"
41
+ "@unifast/node": "0.0.5",
42
+ "@unifast/core": "0.0.5"
25
43
  },
26
44
  "devDependencies": {
27
45
  "@types/react": "^19.2.14",