page.mdx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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><code>@json-render/react</code></td>
  21. <td>React component tree</td>
  22. </tr>
  23. <tr>
  24. <td>Vue</td>
  25. <td><code>@json-render/vue</code></td>
  26. <td>Vue 3 component tree</td>
  27. </tr>
  28. <tr>
  29. <td>shadcn/ui</td>
  30. <td><code>@json-render/shadcn</code></td>
  31. <td>Pre-built Radix UI + Tailwind components (uses React renderer)</td>
  32. </tr>
  33. <tr>
  34. <td>React Native</td>
  35. <td><code>@json-render/react-native</code></td>
  36. <td>Native mobile views</td>
  37. </tr>
  38. <tr>
  39. <td>Image</td>
  40. <td><code>@json-render/image</code></td>
  41. <td>SVG / PNG (via Satori)</td>
  42. </tr>
  43. <tr>
  44. <td>React PDF</td>
  45. <td><code>@json-render/react-pdf</code></td>
  46. <td>PDF documents</td>
  47. </tr>
  48. <tr>
  49. <td>Remotion</td>
  50. <td><code>@json-render/remotion</code></td>
  51. <td>Video compositions</td>
  52. </tr>
  53. </tbody>
  54. </table>
  55. ## React
  56. Render specs as React component trees in the browser. Supports data binding, streaming, actions, validation, visibility, and computed values.
  57. ```tsx
  58. import { defineRegistry, Renderer } from "@json-render/react";
  59. import { schema } from "@json-render/react/schema";
  60. const { registry } = defineRegistry(catalog, { components });
  61. <Renderer spec={spec} registry={registry} />
  62. ```
  63. Use `StateProvider`, `VisibilityProvider`, and `ActionProvider` for full interactivity. See the [@json-render/react API reference](/docs/api/react) for details.
  64. ## Vue
  65. Vue 3 renderer with full feature parity with React: data binding, visibility, actions, validation, repeat scopes, and streaming.
  66. ```typescript
  67. import { defineRegistry, Renderer } from "@json-render/vue";
  68. import { schema } from "@json-render/vue/schema";
  69. const { registry } = defineRegistry(catalog, {
  70. components: {
  71. Card: ({ props, children }) =>
  72. h("div", { class: "card" }, [h("h3", null, props.title), children]),
  73. },
  74. });
  75. ```
  76. Uses composables (`useStateStore`, `useStateBinding`, `useActions`, etc.) instead of React hooks. See the [@json-render/vue API reference](/docs/api/vue) for details.
  77. ## shadcn/ui
  78. 36 pre-built components using Radix UI and Tailwind CSS. Built on top of `@json-render/react` -- no custom renderer needed.
  79. ```tsx
  80. import { defineCatalog } from "@json-render/core";
  81. import { schema } from "@json-render/react/schema";
  82. import { defineRegistry, Renderer } from "@json-render/react";
  83. import { shadcnComponentDefinitions } from "@json-render/shadcn/catalog";
  84. import { shadcnComponents } from "@json-render/shadcn";
  85. const catalog = defineCatalog(schema, {
  86. components: {
  87. Card: shadcnComponentDefinitions.Card,
  88. Button: shadcnComponentDefinitions.Button,
  89. },
  90. });
  91. const { registry } = defineRegistry(catalog, {
  92. components: {
  93. Card: shadcnComponents.Card,
  94. Button: shadcnComponents.Button,
  95. },
  96. });
  97. ```
  98. See the [@json-render/shadcn API reference](/docs/api/shadcn) for the full component list.
  99. ## React Native
  100. Render specs as native mobile views. Includes 25+ standard components and standard action definitions.
  101. ```tsx
  102. import { defineCatalog } from "@json-render/core";
  103. import { schema } from "@json-render/react-native/schema";
  104. import { standardComponentDefinitions, standardActionDefinitions } from "@json-render/react-native/catalog";
  105. import { defineRegistry, Renderer } from "@json-render/react-native";
  106. const catalog = defineCatalog(schema, {
  107. components: { ...standardComponentDefinitions },
  108. actions: standardActionDefinitions,
  109. });
  110. const { registry } = defineRegistry(catalog, { components: {} });
  111. <Renderer spec={spec} registry={registry} />
  112. ```
  113. See the [@json-render/react-native API reference](/docs/api/react-native) for details.
  114. ## Image
  115. Generate SVG and PNG images from JSON specs using Satori. Ideal for OG images, social cards, and banners.
  116. ```typescript
  117. import { renderToSvg, renderToPng } from "@json-render/image/render";
  118. const svg = await renderToSvg(spec, { fonts });
  119. const png = await renderToPng(spec, { fonts });
  120. ```
  121. Nine standard components: Frame, Box, Row, Column, Heading, Text, Image, Divider, Spacer. PNG output requires `@resvg/resvg-js` as an optional peer dependency.
  122. See the [@json-render/image API reference](/docs/api/image) for details.
  123. ## React PDF
  124. Generate PDF documents from JSON specs using `@react-pdf/renderer`. Render to buffer, stream, or file.
  125. ```typescript
  126. import { renderToBuffer, renderToStream, renderToFile } from "@json-render/react-pdf";
  127. const buffer = await renderToBuffer(spec);
  128. const stream = await renderToStream(spec);
  129. await renderToFile(spec, "./output.pdf");
  130. ```
  131. Standard components include Document, Page, View, Row, Column, Heading, Text, Image, Table, List, Divider, Spacer, Link, and PageNumber.
  132. See the [@json-render/react-pdf API reference](/docs/api/react-pdf) for details.
  133. ## Remotion
  134. Turn JSON timeline specs into video compositions with Remotion.
  135. ```tsx
  136. import { Player } from "@remotion/player";
  137. import { Renderer } from "@json-render/remotion";
  138. <Player
  139. component={Renderer}
  140. inputProps={{ spec }}
  141. durationInFrames={spec.composition.durationInFrames}
  142. fps={spec.composition.fps}
  143. compositionWidth={spec.composition.width}
  144. compositionHeight={spec.composition.height}
  145. />
  146. ```
  147. Uses a timeline spec format with compositions, tracks, and clips. Includes standard components (TitleCard, TypingText, ImageSlide, etc.), transitions (fade, slide, zoom, wipe), and effects.
  148. See the [@json-render/remotion API reference](/docs/api/remotion) for details.
  149. ## Custom Renderers
  150. 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.