@novility/react-converter-core 1.0.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 +76 -0
- package/dist/index.js +1338 -0
- package/dist/runtime/dom.js +114 -0
- package/dist/runtime/hooks.js +223 -0
- package/package.json +51 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# @novility/react-converter-core
|
|
2
|
+
|
|
3
|
+
The core conversion engine for `react-converter`. This library provides the logic for parsing JSX, transforming ASTs, and generating framework-free vanilla JavaScript components.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **JSX Parsing**: Uses Babel to parse JSX and TypeScript.
|
|
8
|
+
- **AST Transformations**: Converts React-style JSX into DOM-manipulation logic.
|
|
9
|
+
- **TailwindCSS Integration**: Automatically extracts Tailwind classes and builds a minimal CSS bundle.
|
|
10
|
+
- **Web Component Support**: Can wrap components into native Web Components with Shadow DOM.
|
|
11
|
+
- **Hooks Runtime**: Provides a lightweight runtime for `useState`, `useEffect`, and `useRef`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @novility/react-converter-core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## API Usage
|
|
20
|
+
|
|
21
|
+
### `convert(code, options)`
|
|
22
|
+
|
|
23
|
+
The main function to transform React code into vanilla JS.
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
import { convert } from '@novility/react-converter-core';
|
|
27
|
+
|
|
28
|
+
const code = `
|
|
29
|
+
function Greeting({ name }) {
|
|
30
|
+
return <h1 className="text-blue-500">Hello {name}</h1>;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const result = await convert(code, {
|
|
35
|
+
fileName: 'Greeting.jsx',
|
|
36
|
+
tailwindConfig: './tailwind.config.js',
|
|
37
|
+
webComponent: true,
|
|
38
|
+
webComponentTag: 'my-greeting'
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
console.log(result.code);
|
|
42
|
+
// Output: Vanilla JS code implementing the component
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
#### Options
|
|
46
|
+
| Option | Type | Default | Description |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| `fileName` | `string` | `'component.jsx'` | Used for identifying the component and naming. |
|
|
49
|
+
| `tailwindConfig` | `string` | `null` | Path to your tailwind.config.js file. |
|
|
50
|
+
| `webComponent` | `boolean` | `false` | Whether to emit a Web Component. |
|
|
51
|
+
| `webComponentTag` | `string` | `null` | Custom tag name for the Web Component. |
|
|
52
|
+
| `usePlaceholders` | `boolean` | `false` | Use $prefix for props as placeholders. |
|
|
53
|
+
|
|
54
|
+
### Advanced Exports
|
|
55
|
+
|
|
56
|
+
The core also exports individual modules for more granular control:
|
|
57
|
+
|
|
58
|
+
- `parseFile(code)`: Parses code into a Babel AST.
|
|
59
|
+
- `transform(ast, options)`: Transforms the AST into an intermediate representation.
|
|
60
|
+
- `generateCode(components, fileName, options)`: Generates final JS code.
|
|
61
|
+
- `buildTailwindCSS({ configPath, content })`: Compiles Tailwind CSS.
|
|
62
|
+
- `findTailwindConfig(inputDir)`: Helper to locate tailwind.config.js.
|
|
63
|
+
|
|
64
|
+
## Architecture
|
|
65
|
+
|
|
66
|
+
The core is divided into several modules:
|
|
67
|
+
|
|
68
|
+
1. **Parser**: Babel-based parser for modern JS/TS/JSX.
|
|
69
|
+
2. **Transformer**: Traverses the AST to extract component logic and prepare it for generation.
|
|
70
|
+
3. **Generator**: Takes the transformed data and produces the final string output.
|
|
71
|
+
4. **Tailwind**: Handles class extraction and CSS compilation using PostCSS.
|
|
72
|
+
5. **Runtime**: Minimalistic JS snippets for DOM manipulation and hooks support, which are embedded into the output.
|
|
73
|
+
|
|
74
|
+
## License
|
|
75
|
+
|
|
76
|
+
Proprietary. See main repository for details.
|