{"version":3,"sources":["../src/render.tsx","../src/components/standard.tsx"],"sourcesContent":["import React from \"react\";\nimport { render } from \"@react-email/render\";\nimport type { Spec, UIElement } from \"@json-render/core\";\nimport {\n  resolveElementProps,\n  resolveRepeatItemStatePath,\n  resolveRepeatStatePath,\n  evaluateVisibility,\n  getByPath,\n  type PropResolutionContext,\n} from \"@json-render/core\";\nimport { standardComponents } from \"./components/standard\";\n\n// Re-export the standard components for use in custom registries\nexport { standardComponents };\n\nexport type RenderComponentRegistry = Record<string, React.ComponentType<any>>;\n\nexport interface RenderOptions {\n  registry?: RenderComponentRegistry;\n  includeStandard?: boolean;\n  state?: Record<string, unknown>;\n}\n\nconst noopEmit = () => {};\n\nfunction renderElement(\n  elementKey: string,\n  spec: Spec,\n  registry: RenderComponentRegistry,\n  stateModel: Record<string, unknown>,\n  repeatItem?: unknown,\n  repeatIndex?: number,\n  repeatBasePath?: string,\n): React.ReactElement | null {\n  const element = spec.elements[elementKey];\n  if (!element) return null;\n\n  const ctx: PropResolutionContext = {\n    stateModel,\n    repeatItem,\n    repeatIndex,\n    repeatBasePath,\n  };\n\n  if (element.visible !== undefined) {\n    if (!evaluateVisibility(element.visible, ctx)) {\n      return null;\n    }\n  }\n\n  const resolvedProps = resolveElementProps(\n    element.props as Record<string, unknown>,\n    ctx,\n  );\n  const resolvedElement: UIElement = { ...element, props: resolvedProps };\n\n  const Component = registry[resolvedElement.type];\n  if (!Component) return null;\n\n  if (resolvedElement.repeat) {\n    const repeat = resolvedElement.repeat;\n    const statePath = resolveRepeatStatePath(repeat.statePath, repeatBasePath);\n    if (statePath === undefined) {\n      console.warn(\n        \"[json-render/react-email] $item in repeat.statePath used outside of a repeat scope\",\n      );\n      return null;\n    }\n\n    const items =\n      (getByPath(stateModel, statePath) as unknown[] | undefined) ?? [];\n\n    const fragments = items.map((item, index) => {\n      const repeatKey = repeat.key;\n      const key =\n        repeatKey && typeof item === \"object\" && item !== null\n          ? String((item as Record<string, unknown>)[repeatKey] ?? index)\n          : String(index);\n\n      const childPath = resolveRepeatItemStatePath(statePath, index);\n      const children = resolvedElement.children?.map((childKey) =>\n        renderElement(\n          childKey,\n          spec,\n          registry,\n          stateModel,\n          item,\n          index,\n          childPath,\n        ),\n      );\n\n      return (\n        <Component key={key} element={resolvedElement} emit={noopEmit}>\n          {children}\n        </Component>\n      );\n    });\n\n    return <>{fragments}</>;\n  }\n\n  const children = resolvedElement.children?.map((childKey) =>\n    renderElement(\n      childKey,\n      spec,\n      registry,\n      stateModel,\n      repeatItem,\n      repeatIndex,\n      repeatBasePath,\n    ),\n  );\n\n  return (\n    <Component key={elementKey} element={resolvedElement} emit={noopEmit}>\n      {children && children.length > 0 ? children : undefined}\n    </Component>\n  );\n}\n\nfunction buildDocument(\n  spec: Spec,\n  options: RenderOptions = {},\n): React.ReactElement {\n  const {\n    registry: customRegistry,\n    includeStandard = true,\n    state = {},\n  } = options;\n\n  const mergedState: Record<string, unknown> = {\n    ...spec.state,\n    ...state,\n  };\n\n  const registry: RenderComponentRegistry = {\n    ...(includeStandard ? standardComponents : {}),\n    ...customRegistry,\n  };\n\n  const root = renderElement(spec.root, spec, registry, mergedState);\n  if (!root) {\n    console.warn(\n      `[json-render/react-email] Root element \"${spec.root}\" not found in spec.elements`,\n    );\n  }\n  return root ?? <></>;\n}\n\n/**\n * Render a json-render spec to an HTML email string.\n *\n * This is a standalone server-side function that resolves the spec tree\n * without React hooks or contexts, making it safe to import in Next.js\n * route handlers and other server-only environments.\n */\nexport async function renderToHtml(\n  spec: Spec,\n  options?: RenderOptions,\n): Promise<string> {\n  const document = buildDocument(spec, options);\n  return render(document);\n}\n\n/**\n * Render a json-render spec to a plain text email string.\n */\nexport async function renderToPlainText(\n  spec: Spec,\n  options?: RenderOptions,\n): Promise<string> {\n  const document = buildDocument(spec, options);\n  return render(document, { plainText: true });\n}\n","import React from \"react\";\nimport {\n  Html as EmailHtml,\n  Head as EmailHead,\n  Body as EmailBody,\n  Container as EmailContainer,\n  Section as EmailSection,\n  Row as EmailRow,\n  Column as EmailColumn,\n  Heading as EmailHeading,\n  Text as EmailText,\n  Link as EmailLink,\n  Button as EmailButton,\n  Img as EmailImg,\n  Hr as EmailHr,\n  Preview as EmailPreview,\n  Markdown as EmailMarkdown,\n} from \"@react-email/components\";\nimport type { ComponentRenderProps } from \"../renderer\";\nimport type { ComponentRegistry } from \"../renderer\";\nimport type { StandardComponentProps } from \"../catalog\";\n\n// =============================================================================\n// Document Structure\n// =============================================================================\n\nfunction HtmlComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Html\">>) {\n  const p = element.props;\n\n  return (\n    <EmailHtml lang={p.lang ?? undefined} dir={p.dir ?? undefined}>\n      {children}\n    </EmailHtml>\n  );\n}\n\nfunction HeadComponent({\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Head\">>) {\n  return <EmailHead>{children}</EmailHead>;\n}\n\nfunction BodyComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Body\">>) {\n  const p = element.props;\n\n  return <EmailBody style={p.style ?? undefined}>{children}</EmailBody>;\n}\n\nfunction ContainerComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Container\">>) {\n  const p = element.props;\n\n  return (\n    <EmailContainer style={p.style ?? undefined}>{children}</EmailContainer>\n  );\n}\n\nfunction SectionComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Section\">>) {\n  const p = element.props;\n\n  return <EmailSection style={p.style ?? undefined}>{children}</EmailSection>;\n}\n\nfunction RowComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Row\">>) {\n  const p = element.props;\n\n  return <EmailRow style={p.style ?? undefined}>{children}</EmailRow>;\n}\n\nfunction ColumnComponent({\n  element,\n  children,\n}: ComponentRenderProps<StandardComponentProps<\"Column\">>) {\n  const p = element.props;\n\n  return <EmailColumn style={p.style ?? undefined}>{children}</EmailColumn>;\n}\n\n// =============================================================================\n// Content Components\n// =============================================================================\n\nfunction HeadingComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Heading\">>) {\n  const p = element.props;\n\n  return (\n    <EmailHeading as={p.as ?? \"h2\"} style={p.style ?? undefined}>\n      {p.text}\n    </EmailHeading>\n  );\n}\n\nfunction TextComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Text\">>) {\n  const p = element.props;\n\n  return <EmailText style={p.style ?? undefined}>{p.text}</EmailText>;\n}\n\nfunction LinkComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Link\">>) {\n  const p = element.props;\n\n  return (\n    <EmailLink href={p.href} style={p.style ?? undefined}>\n      {p.text}\n    </EmailLink>\n  );\n}\n\nfunction ButtonComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Button\">>) {\n  const p = element.props;\n\n  return (\n    <EmailButton href={p.href} style={p.style ?? undefined}>\n      {p.text}\n    </EmailButton>\n  );\n}\n\nfunction ImageComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Image\">>) {\n  const p = element.props;\n\n  return (\n    <EmailImg\n      src={p.src}\n      alt={p.alt ?? undefined}\n      width={p.width ?? undefined}\n      height={p.height ?? undefined}\n      style={p.style ?? undefined}\n    />\n  );\n}\n\nfunction HrComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Hr\">>) {\n  const p = element.props;\n\n  return <EmailHr style={p.style ?? undefined} />;\n}\n\n// =============================================================================\n// Utility Components\n// =============================================================================\n\nfunction PreviewComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Preview\">>) {\n  const p = element.props;\n\n  return <EmailPreview>{p.text}</EmailPreview>;\n}\n\nfunction MarkdownComponent({\n  element,\n}: ComponentRenderProps<StandardComponentProps<\"Markdown\">>) {\n  const p = element.props;\n\n  return (\n    <EmailMarkdown\n      markdownContainerStyles={p.markdownContainerStyles ?? undefined}\n      markdownCustomStyles={p.markdownCustomStyles ?? undefined}\n    >\n      {p.content}\n    </EmailMarkdown>\n  );\n}\n\n// =============================================================================\n// Registry\n// =============================================================================\n\nexport const standardComponents: ComponentRegistry = {\n  Html: HtmlComponent,\n  Head: HeadComponent,\n  Body: BodyComponent,\n  Container: ContainerComponent,\n  Section: SectionComponent,\n  Row: RowComponent,\n  Column: ColumnComponent,\n  Heading: HeadingComponent,\n  Text: TextComponent,\n  Link: LinkComponent,\n  Button: ButtonComponent,\n  Image: ImageComponent,\n  Hr: HrComponent,\n  Preview: PreviewComponent,\n  Markdown: MarkdownComponent,\n};\n"],"mappings":";AACA,SAAS,cAAc;AAEvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;;;ACTP;AAAA,EACE,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,WAAW;AAAA,EACX,OAAO;AAAA,EACP,UAAU;AAAA,EACV,WAAW;AAAA,EACX,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,YAAY;AAAA,OACP;AAgBH;AAPJ,SAAS,cAAc;AAAA,EACrB;AAAA,EACA;AACF,GAAyD;AACvD,QAAM,IAAI,QAAQ;AAElB,SACE,oBAAC,aAAU,MAAM,EAAE,QAAQ,QAAW,KAAK,EAAE,OAAO,QACjD,UACH;AAEJ;AAEA,SAAS,cAAc;AAAA,EACrB;AACF,GAAyD;AACvD,SAAO,oBAAC,aAAW,UAAS;AAC9B;AAEA,SAAS,cAAc;AAAA,EACrB;AAAA,EACA;AACF,GAAyD;AACvD,QAAM,IAAI,QAAQ;AAElB,SAAO,oBAAC,aAAU,OAAO,EAAE,SAAS,QAAY,UAAS;AAC3D;AAEA,SAAS,mBAAmB;AAAA,EAC1B;AAAA,EACA;AACF,GAA8D;AAC5D,QAAM,IAAI,QAAQ;AAElB,SACE,oBAAC,kBAAe,OAAO,EAAE,SAAS,QAAY,UAAS;AAE3D;AAEA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