page.mdx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. </tbody>
  82. </table>
  83. ## React
  84. Render specs as React component trees in the browser. Supports data binding, streaming, actions, validation, visibility, and computed values.
  85. ```tsx
  86. import { defineRegistry, Renderer } from "@json-render/react";
  87. import { schema } from "@json-render/react/schema";
  88. const { registry } = defineRegistry(catalog, { components });
  89. <Renderer spec={spec} registry={registry} />;
  90. ```
  91. Use `StateProvider`, `VisibilityProvider`, and `ActionProvider` for full interactivity. See the [@json-render/react API reference](/docs/api/react) for details.
  92. ## Vue
  93. Vue 3 renderer with full feature parity with React: data binding, visibility, actions, validation, repeat scopes, and streaming.
  94. ```typescript
  95. import { defineRegistry, Renderer } from "@json-render/vue";
  96. import { schema } from "@json-render/vue/schema";
  97. const { registry } = defineRegistry(catalog, {
  98. components: {
  99. Card: ({ props, children }) =>
  100. h("div", { class: "card" }, [h("h3", null, props.title), children]),
  101. },
  102. });
  103. ```
  104. Uses composables (`useStateStore`, `useStateBinding`, `useActions`, etc.) instead of React hooks. See the [@json-render/vue API reference](/docs/api/vue) for details.
  105. ## Svelte
  106. Svelte 5 renderer with runes-compatible context helpers, visibility conditions, actions, and streaming support.
  107. ```typescript
  108. import { defineRegistry, Renderer } from "@json-render/svelte";
  109. import { schema } from "@json-render/svelte/schema";
  110. const { registry } = defineRegistry(catalog, {
  111. components: {
  112. Card: ({ props, children }) => /* Svelte snippet */,
  113. },
  114. });
  115. ```
  116. See the [@json-render/svelte API reference](/docs/api/svelte) for details.
  117. ## Solid
  118. SolidJS renderer with fine-grained reactivity, state bindings, validation, visibility, and event-driven actions.
  119. ```tsx
  120. import { defineRegistry, Renderer } from "@json-render/solid";
  121. import { schema } from "@json-render/solid/schema";
  122. const { registry } = defineRegistry(catalog, {
  123. components: {
  124. Card: (renderProps) => <div>{renderProps.children}</div>,
  125. },
  126. });
  127. <Renderer spec={spec} registry={registry} />;
  128. ```
  129. See the [@json-render/solid API reference](/docs/api/solid) for details.
  130. ## shadcn/ui
  131. 36 pre-built components using Radix UI and Tailwind CSS. Built on top of `@json-render/react` -- no custom renderer needed.
  132. ```tsx
  133. import { defineCatalog } from "@json-render/core";
  134. import { schema } from "@json-render/react/schema";
  135. import { defineRegistry, Renderer } from "@json-render/react";
  136. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  137. import { shadcnComponents } from "@json-render/shadcn";
  138. const catalog = defineCatalog(schema, {
  139. components: {
  140. Card: shadcnComponentDefinitions.Card,
  141. Button: shadcnComponentDefinitions.Button,
  142. },
  143. });
  144. const { registry } = defineRegistry(catalog, {
  145. components: {
  146. Card: shadcnComponents.Card,
  147. Button: shadcnComponents.Button,
  148. },
  149. });
  150. ```
  151. See the [@json-render/shadcn API reference](/docs/api/shadcn) for the full component list.
  152. ## React Native
  153. Render specs as native mobile views. Includes 25+ standard components and standard action definitions.
  154. ```tsx
  155. import { defineCatalog } from "@json-render/core";
  156. import { schema } from "@json-render/react-native/schema";
  157. import {
  158. standardComponentDefinitions,
  159. standardActionDefinitions,
  160. } from "@json-render/react-native/catalog";
  161. import { defineRegistry, Renderer } from "@json-render/react-native";
  162. const catalog = defineCatalog(schema, {
  163. components: { ...standardComponentDefinitions },
  164. actions: standardActionDefinitions,
  165. });
  166. const { registry } = defineRegistry(catalog, { components: {} });
  167. <Renderer spec={spec} registry={registry} />;
  168. ```
  169. See the [@json-render/react-native API reference](/docs/api/react-native) for details.
  170. ## Image
  171. Generate SVG and PNG images from JSON specs using Satori. Ideal for OG images, social cards, and banners.
  172. ```typescript
  173. import { renderToSvg, renderToPng } from "@json-render/image/render";
  174. const svg = await renderToSvg(spec, { fonts });
  175. const png = await renderToPng(spec, { fonts });
  176. ```
  177. Nine standard components: Frame, Box, Row, Column, Heading, Text, Image, Divider, Spacer. PNG output requires `@resvg/resvg-js` as an optional peer dependency.
  178. See the [@json-render/image API reference](/docs/api/image) for details.
  179. ## React PDF
  180. Generate PDF documents from JSON specs using `@react-pdf/renderer`. Render to buffer, stream, or file.
  181. ```typescript
  182. import {
  183. renderToBuffer,
  184. renderToStream,
  185. renderToFile,
  186. } from "@json-render/react-pdf";
  187. const buffer = await renderToBuffer(spec);
  188. const stream = await renderToStream(spec);
  189. await renderToFile(spec, "./output.pdf");
  190. ```
  191. Standard components include Document, Page, View, Row, Column, Heading, Text, Image, Table, List, Divider, Spacer, Link, and PageNumber.
  192. See the [@json-render/react-pdf API reference](/docs/api/react-pdf) for details.
  193. ## Remotion
  194. Turn JSON timeline specs into video compositions with Remotion.
  195. ```tsx
  196. import { Player } from "@remotion/player";
  197. import { Renderer } from "@json-render/remotion";
  198. <Player
  199. component={Renderer}
  200. inputProps={{ spec }}
  201. durationInFrames={spec.composition.durationInFrames}
  202. fps={spec.composition.fps}
  203. compositionWidth={spec.composition.width}
  204. compositionHeight={spec.composition.height}
  205. />;
  206. ```
  207. Uses a timeline spec format with compositions, tracks, and clips. Includes standard components (TitleCard, TypingText, ImageSlide, etc.), transitions (fade, slide, zoom, wipe), and effects.
  208. See the [@json-render/remotion API reference](/docs/api/remotion) for details.
  209. ## Custom Renderers
  210. 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.