This repository contains a Next.js application that serves as an iframe for rendering React components passed as strings through messages. It's designed to be embedded in another application and provides functionality for dynamic component rendering and screen capture.
This is my attempt at figuring out how Claude.ai implements the Artifact viewer. If you find flaws or have ideas to improve please raise an issue or a Pull Request 🙏
INIT_COMPLETE
message to the parent window.UPDATE_COMPONENT
: Updates the rendered component with new code.CAPTURE_SELECTION
: Captures a specific area of the rendered component.To use this component renderer in your application:
Home
: The main component that handles message passing and component rendering.getReactComponentFromCode
: A utility function that converts string code into a React component using babel
.html2canvas
: Used for capturing the rendered component as an image.INIT_COMPLETE
: Sent when the iframe is ready to receive messages.UPDATE_COMPONENT
: Received to update the rendered component.CAPTURE_SELECTION
: Received to capture a specific area of the rendered component.SELECTION_DATA
: Sent with captured image data.Clone the repository:
git clone https://github.com/13point5/open-artifacts-renderer.git
Navigate to the project directory:
cd open-artifacts-renderer
Install dependencies:
npm install
Run the development server:
npm run dev
Set the NEXT_PUBLIC_ARTIFACT_RENDERER_URL
env variable in the Open Artifacts app to the URL of this app
This project is licensed under the MIT License.