page.mdx 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. import { pageMetadata } from "@/lib/page-metadata";
  2. export const metadata = pageMetadata("docs/renderers");
  3. # Renderers
  4. json-render supports multiple output targets. Each renderer takes the same core concept -- a JSON spec constrained to a catalog -- and renders it natively on a different platform or into a different format.
  5. All renderers share the same workflow:
  6. 1. Define a catalog with `defineCatalog`
  7. 2. AI generates a JSON spec
  8. 3. The renderer turns the spec into platform-native output
  9. <table>
  10. <thead>
  11. <tr>
  12. <th>Renderer</th>
  13. <th>Package</th>
  14. <th>Output</th>
  15. </tr>
  16. </thead>
  17. <tbody>
  18. <tr>
  19. <td>React</td>
  20. <td>
  21. <code>@json-render/react</code>
  22. </td>
  23. <td>React component tree</td>
  24. </tr>
  25. <tr>
  26. <td>Vue</td>
  27. <td>
  28. <code>@json-render/vue</code>
  29. </td>
  30. <td>Vue 3 component tree</td>
  31. </tr>
  32. <tr>
  33. <td>Svelte</td>
  34. <td>
  35. <code>@json-render/svelte</code>
  36. </td>
  37. <td>Svelte 5 component tree</td>
  38. </tr>
  39. <tr>
  40. <td>Solid</td>
  41. <td>
  42. <code>@json-render/solid</code>
  43. </td>
  44. <td>SolidJS component tree</td>
  45. </tr>
  46. <tr>
  47. <td>shadcn/ui</td>
  48. <td>
  49. <code>@json-render/shadcn</code>
  50. </td>
  51. <td>Pre-built Radix UI + Tailwind components (uses React renderer)</td>
  52. </tr>
  53. <tr>
  54. <td>React Native</td>
  55. <td>
  56. <code>@json-render/react-native</code>
  57. </td>
  58. <td>Native mobile views</td>
  59. </tr>
  60. <tr>
  61. <td>Image</td>
  62. <td>
  63. <code>@json-render/image</code>
  64. </td>
  65. <td>SVG / PNG (via Satori)</td>
  66. </tr>
  67. <tr>
  68. <td>React PDF</td>
  69. <td>
  70. <code>@json-render/react-pdf</code>
  71. </td>
  72. <td>PDF documents</td>
  73. </tr>
  74. <tr>
  75. <td>Remotion</td>
  76. <td>
  77. <code>@json-render/remotion</code>
  78. </td>
  79. <td>Video compositions</td>
  80. </tr>
  81. <tr>
  82. <td>Ink</td>
  83. <td>
  84. <code>@json-render/ink</code>
  85. </td>
  86. <td>Terminal UI (via Ink)</td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. ## React
  91. Render specs as React component trees in the browser. Supports data binding, streaming, actions, validation, visibility, and computed values.
  92. ```tsx
  93. import { defineRegistry, Renderer } from "@json-render/react";
  94. import { schema } from "@json-render/react/schema";
  95. const { registry } = defineRegistry(catalog, { components });
  96. <Renderer spec={spec} registry={registry} />;
  97. ```
  98. Use `StateProvider`, `VisibilityProvider`, and `ActionProvider` for full interactivity. See the [@json-render/react API reference](/docs/api/react) for details.
  99. ## Vue
  100. Vue 3 renderer with full feature parity with React: data binding, visibility, actions, validation, repeat scopes, and streaming.
  101. ```typescript
  102. import { defineRegistry, Renderer } from "@json-render/vue";
  103. import { schema } from "@json-render/vue/schema";
  104. const { registry } = defineRegistry(catalog, {
  105. components: {
  106. Card: ({ props, children }) =>
  107. h("div", { class: "card" }, [h("h3", null, props.title), children]),
  108. },
  109. });
  110. ```
  111. Uses composables (`useStateStore`, `useStateBinding`, `useActions`, etc.) instead of React hooks. See the [@json-render/vue API reference](/docs/api/vue) for details.
  112. ## Svelte
  113. Svelte 5 renderer with runes-compatible context helpers, visibility conditions, actions, and streaming support.
  114. ```typescript
  115. import { defineRegistry, Renderer } from "@json-render/svelte";
  116. import { schema } from "@json-render/svelte/schema";
  117. const { registry } = defineRegistry(catalog, {
  118. components: {
  119. Card: ({ props, children }) => /* Svelte snippet */,
  120. },
  121. });
  122. ```
  123. See the [@json-render/svelte API reference](/docs/api/svelte) for details.
  124. ## Solid
  125. SolidJS renderer with fine-grained reactivity, state bindings, validation, visibility, and event-driven actions.
  126. ```tsx
  127. import { defineRegistry, Renderer } from "@json-render/solid";
  128. import { schema } from "@json-render/solid/schema";
  129. const { registry } = defineRegistry(catalog, {
  130. components: {
  131. Card: (renderProps) => <div>{renderProps.children}</div>,
  132. },
  133. });
  134. <Renderer spec={spec} registry={registry} />;
  135. ```
  136. See the [@json-render/solid API reference](/docs/api/solid) for details.
  137. ## shadcn/ui
  138. 36 pre-built components using Radix UI and Tailwind CSS. Built on top of `@json-render/react` -- no custom renderer needed.
  139. ```tsx
  140. import { defineCatalog } from "@json-render/core";
  141. import { schema } from "@json-render/react/schema";
  142. import { defineRegistry, Renderer } from "@json-render/react";
  143. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  144. import { shadcnComponents } from "@json-render/shadcn";
  145. const catalog = defineCatalog(schema, {
  146. components: {
  147. Card: shadcnComponentDefinitions.Card,
  148. Button: shadcnComponentDefinitions.Button,
  149. },
  150. });
  151. const { registry } = defineRegistry(catalog, {
  152. components: {
  153. Card: shadcnComponents.Card,
  154. Button: shadcnComponents.Button,
  155. },
  156. });
  157. ```
  158. See the [@json-render/shadcn API reference](/docs/api/shadcn) for the full component list.
  159. ## React Native
  160. Render specs as native mobile views. Includes 25+ standard components and standard action definitions.
  161. ```tsx
  162. import { defineCatalog } from "@json-render/core";
  163. import { schema } from "@json-render/react-native/schema";
  164. import {
  165. standardComponentDefinitions,
  166. standardActionDefinitions,
  167. } from "@json-render/react-native/catalog";
  168. import { defineRegistry, Renderer } from "@json-render/react-native";
  169. const catalog = defineCatalog(schema, {
  170. components: { ...standardComponentDefinitions },
  171. actions: standardActionDefinitions,
  172. });
  173. const { registry } = defineRegistry(catalog, { components: {} });
  174. <Renderer spec={spec} registry={registry} />;
  175. ```
  176. See the [@json-render/react-native API reference](/docs/api/react-native) for details.
  177. ## Image
  178. Generate SVG and PNG images from JSON specs using Satori. Ideal for OG images, social cards, and banners.
  179. ```typescript
  180. import { renderToSvg, renderToPng } from "@json-render/image/render";
  181. const svg = await renderToSvg(spec, { fonts });
  182. const png = await renderToPng(spec, { fonts });
  183. ```
  184. Nine standard components: Frame, Box, Row, Column, Heading, Text, Image, Divider, Spacer. PNG output requires `@resvg/resvg-js` as an optional peer dependency.
  185. See the [@json-render/image API reference](/docs/api/image) for details.
  186. ## React PDF
  187. Generate PDF documents from JSON specs using `@react-pdf/renderer`. Render to buffer, stream, or file.
  188. ```typescript
  189. import {
  190. renderToBuffer,
  191. renderToStream,
  192. renderToFile,
  193. } from "@json-render/react-pdf";
  194. const buffer = await renderToBuffer(spec);
  195. const stream = await renderToStream(spec);
  196. await renderToFile(spec, "./output.pdf");
  197. ```
  198. Standard components include Document, Page, View, Row, Column, Heading, Text, Image, Table, List, Divider, Spacer, Link, and PageNumber.
  199. See the [@json-render/react-pdf API reference](/docs/api/react-pdf) for details.
  200. ## Remotion
  201. Turn JSON timeline specs into video compositions with Remotion.
  202. ```tsx
  203. import { Player } from "@remotion/player";
  204. import { Renderer } from "@json-render/remotion";
  205. <Player
  206. component={Renderer}
  207. inputProps={{ spec }}
  208. durationInFrames={spec.composition.durationInFrames}
  209. fps={spec.composition.fps}
  210. compositionWidth={spec.composition.width}
  211. compositionHeight={spec.composition.height}
  212. />;
  213. ```
  214. Uses a timeline spec format with compositions, tracks, and clips. Includes standard components (TitleCard, TypingText, ImageSlide, etc.), transitions (fade, slide, zoom, wipe), and effects.
  215. See the [@json-render/remotion API reference](/docs/api/remotion) for details.
  216. ## Ink (Terminal)
  217. Render specs as terminal UIs using [Ink](https://github.com/vadimdemedes/ink). Multiple standard components including tables, progress bars, spinners, tabs, multi-select, and interactive inputs with Tab-cycling focus.
  218. ```tsx
  219. import { defineCatalog } from "@json-render/core";
  220. import { schema } from "@json-render/ink/schema";
  221. import {
  222. standardComponentDefinitions,
  223. standardActionDefinitions,
  224. } from "@json-render/ink/catalog";
  225. import { defineRegistry, Renderer } from "@json-render/ink";
  226. const catalog = defineCatalog(schema, {
  227. components: { ...standardComponentDefinitions },
  228. actions: standardActionDefinitions,
  229. });
  230. const { registry } = defineRegistry(catalog, { components: {} });
  231. <Renderer spec={spec} registry={registry} />;
  232. ```
  233. See the [@json-render/ink API reference](/docs/api/ink) for details.
  234. ## Custom Renderers
  235. You can build your own renderer for any output target. See the [Custom Schema & Renderer](/docs/custom-schema) guide for how to define a custom schema and wire it to your own rendering logic.