@kubb/renderer-jsx 5.0.0-beta.4 → 5.0.0-beta.41

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 (45) hide show
  1. package/README.md +134 -0
  2. package/dist/index.cjs +621 -193
  3. package/dist/index.d.ts +326 -90
  4. package/dist/index.js +615 -193
  5. package/dist/jsx-dev-runtime.cjs +1 -1
  6. package/dist/jsx-dev-runtime.d.ts +7 -8
  7. package/dist/jsx-dev-runtime.js +2 -2
  8. package/dist/{jsx-namespace-CNp0arTN.d.ts → jsx-namespace-dmStM1a2.d.ts} +3 -3
  9. package/dist/{jsx-runtime-DdmO3p0U.cjs → jsx-runtime-4M1bV6ub.cjs} +9 -9
  10. package/dist/{jsx-runtime-Cvu_ZYgL.js → jsx-runtime-CQ6-_gue.js} +10 -10
  11. package/dist/jsx-runtime.cjs +1 -1
  12. package/dist/jsx-runtime.d.ts +9 -10
  13. package/dist/jsx-runtime.js +2 -2
  14. package/dist/{types-nAFMiWFw.d.ts → types-B5VGpHs0.d.ts} +11 -10
  15. package/dist/types.d.ts +1 -1
  16. package/package.json +8 -12
  17. package/src/Renderer.ts +1 -5
  18. package/src/Runtime.tsx +7 -18
  19. package/src/SyncRuntime.tsx +309 -0
  20. package/src/components/Callout.tsx +59 -0
  21. package/src/components/CodeBlock.tsx +37 -0
  22. package/src/components/Const.tsx +4 -4
  23. package/src/components/File.tsx +7 -5
  24. package/src/components/Frontmatter.tsx +38 -0
  25. package/src/components/Function.tsx +8 -8
  26. package/src/components/Heading.tsx +34 -0
  27. package/src/components/Jsx.tsx +1 -1
  28. package/src/components/List.tsx +40 -0
  29. package/src/components/Paragraph.tsx +28 -0
  30. package/src/components/Type.tsx +3 -3
  31. package/src/constants.ts +19 -9
  32. package/src/createRenderer.tsx +81 -62
  33. package/src/dom.ts +7 -19
  34. package/src/index.ts +7 -1
  35. package/src/types.ts +9 -8
  36. package/src/utils.ts +153 -174
  37. package/dist/index.cjs.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/jsx-dev-runtime.cjs.map +0 -1
  40. package/dist/jsx-dev-runtime.js.map +0 -1
  41. package/dist/jsx-runtime-Cvu_ZYgL.js.map +0 -1
  42. package/dist/jsx-runtime-DdmO3p0U.cjs.map +0 -1
  43. package/dist/jsx-runtime.cjs.map +0 -1
  44. package/dist/jsx-runtime.js.map +0 -1
  45. /package/dist/{chunk-Bb7HlUDG.js → chunk-DoukXa0m.js} +0 -0
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ <div align="center">
2
+ <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
4
+ </a>
5
+
6
+ [![npm version][npm-version-src]][npm-version-href]
7
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
8
+ [![Stars][stars-src]][stars-href]
9
+ [![License][license-src]][license-href]
10
+ [![Node][node-src]][node-href]
11
+
12
+ <h4>
13
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
14
+ <span> · </span>
15
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
16
+ <span> · </span>
17
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
18
+ </h4>
19
+ </div>
20
+
21
+ <br />
22
+
23
+ # @kubb/renderer-jsx
24
+
25
+ ### JSX-based renderer for Kubb
26
+
27
+ Provides a custom React runtime, reconciler, and built-in components (`File`, `Function`, `Type`, `Const`) for component-based, type-safe code generation inside Kubb plugins.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ bun add @kubb/renderer-jsx
33
+ # or
34
+ pnpm add @kubb/renderer-jsx
35
+ # or
36
+ npm install @kubb/renderer-jsx
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ Use the built-in components inside a Kubb plugin to emit generated files:
42
+
43
+ ```tsx
44
+ import { createRenderer } from '@kubb/renderer-jsx'
45
+ import { File, Function, Type } from '@kubb/renderer-jsx'
46
+
47
+ const renderer = createRenderer()
48
+
49
+ await renderer.render(
50
+ <File baseName="petStore.ts" path="src/gen/petStore.ts">
51
+ <File.Source>
52
+ <Type name="Pet">{'{ id: number; name: string }'}</Type>
53
+ <Function name="getPet" async>
54
+ {"return fetch('/pets')"}
55
+ </Function>
56
+ </File.Source>
57
+ </File>,
58
+ )
59
+
60
+ const files = renderer.files
61
+ renderer.unmount()
62
+ ```
63
+
64
+ ## Built-in Components
65
+
66
+ | Component | Description |
67
+ | --------------- | --------------------------------------------------------------------------- |
68
+ | `<File>` | Declares a generated output file with its path and optional imports/exports |
69
+ | `<File.Source>` | The source content block inside a `<File>` |
70
+ | `<Function>` | Generates a TypeScript function declaration |
71
+ | `<Type>` | Generates a TypeScript type alias |
72
+ | `<Const>` | Generates a `const` variable declaration |
73
+ | `<Jsx>` | Renders JSX expressions inside generated output |
74
+ | `<Root>` | Root container for the renderer tree |
75
+
76
+ ## API
77
+
78
+ ### `createRenderer(options?)`
79
+
80
+ Creates a new renderer instance.
81
+
82
+ ```typescript
83
+ const renderer = createRenderer({ debug: false })
84
+ await renderer.render(<MyComponent />)
85
+ const files = renderer.files // FileNode[]
86
+ renderer.unmount()
87
+ ```
88
+
89
+ ### `jsxRenderer`
90
+
91
+ Pre-built renderer instance for use directly in Kubb plugins as the `jsxRenderer` plugin option.
92
+
93
+ ## JSX Runtime
94
+
95
+ `@kubb/renderer-jsx` ships its own JSX runtime (`jsx-runtime` and `jsx-dev-runtime`). Configure your `tsconfig.json` to use it:
96
+
97
+ ```json
98
+ {
99
+ "compilerOptions": {
100
+ "jsx": "react-jsx",
101
+ "jsxImportSource": "@kubb/renderer-jsx"
102
+ }
103
+ }
104
+ ```
105
+
106
+ ## Supporting Kubb
107
+
108
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
109
+
110
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
111
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
112
+
113
+ <p align="center">
114
+ <a href="https://github.com/sponsors/stijnvanhulle">
115
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
116
+ </a>
117
+ </p>
118
+
119
+ ## License
120
+
121
+ [MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
122
+
123
+ <!-- Badges -->
124
+
125
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/renderer-jsx.svg?variant=secondary&size=xs&theme=zinc&mode=dark
126
+ [npm-version-href]: https://npmx.dev/package/@kubb/renderer-jsx
127
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/renderer-jsx.svg?variant=secondary&size=xs&theme=zinc&mode=dark
128
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/renderer-jsx
129
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
130
+ [stars-href]: https://github.com/kubb-labs/kubb
131
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/renderer-jsx.svg?variant=secondary&size=xs&theme=zinc
132
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
133
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/renderer-jsx.svg?variant=secondary&size=xs&theme=zinc&mode=dark
134
+ [node-href]: https://npmx.dev/package/@kubb/renderer-jsx