diff --git a/app/api/toHtml/route.ts b/app/api/toHtml/route.ts
new file mode 100644
index 0000000..5c1abfc
--- /dev/null
+++ b/app/api/toHtml/route.ts
@@ -0,0 +1,78 @@
+const systemPrompt = `You are an expert tailwind developer. A user will provide you with a
+ low-fidelity wireframe of an application and you will return
+ a single html file that uses tailwind to create the website. Use creative license to make the application more fleshed out.
+if you need to insert an image, use placehold.co to create a placeholder image. Respond only with the html file.`;
+
+export async function POST(request: Request) {
+ const { image } = await request.json();
+ const body: GPT4VCompletionRequest = {
+ model: "gpt-4-vision-preview",
+ max_tokens: 4096,
+ messages: [
+ {
+ role: "system",
+ content: systemPrompt,
+ },
+ {
+ role: "user",
+ content: [
+ {
+ type: "image_url",
+ image_url: image,
+ },
+ "Turn this into a single html file using tailwind.",
+ ],
+ },
+ ],
+ };
+
+ let json = null;
+ try {
+ const resp = await fetch("https://api.openai.com/v1/chat/completions", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
+ },
+ body: JSON.stringify(body),
+ });
+ json = await resp.json();
+ } catch (e) {
+ console.log(e);
+ }
+
+ return new Response(JSON.stringify(json), {
+ headers: {
+ "content-type": "application/json; charset=UTF-8",
+ },
+ });
+}
+
+type MessageContent =
+ | string
+ | (string | { type: "image_url"; image_url: string })[];
+
+export type GPT4VCompletionRequest = {
+ model: "gpt-4-vision-preview";
+ messages: {
+ role: "system" | "user" | "assistant" | "function";
+ content: MessageContent;
+ name?: string | undefined;
+ }[];
+ functions?: any[] | undefined;
+ function_call?: any | undefined;
+ stream?: boolean | undefined;
+ temperature?: number | undefined;
+ top_p?: number | undefined;
+ max_tokens?: number | undefined;
+ n?: number | undefined;
+ best_of?: number | undefined;
+ frequency_penalty?: number | undefined;
+ presence_penalty?: number | undefined;
+ logit_bias?:
+ | {
+ [x: string]: number;
+ }
+ | undefined;
+ stop?: (string[] | string) | undefined;
+};
diff --git a/app/globals.css b/app/globals.css
index fd81e88..0400eb4 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -2,26 +2,10 @@
@tailwind components;
@tailwind utilities;
-:root {
- --foreground-rgb: 0, 0, 0;
- --background-start-rgb: 214, 219, 220;
- --background-end-rgb: 255, 255, 255;
+.tlui-help-menu {
+ display: none !important;
}
-@media (prefers-color-scheme: dark) {
- :root {
- --foreground-rgb: 255, 255, 255;
- --background-start-rgb: 0, 0, 0;
- --background-end-rgb: 0, 0, 0;
- }
-}
-
-body {
- color: rgb(var(--foreground-rgb));
- background: linear-gradient(
- to bottom,
- transparent,
- rgb(var(--background-end-rgb))
- )
- rgb(var(--background-start-rgb));
+.tlui-debug-panel {
+ display: none !important;
}
diff --git a/app/layout.tsx b/app/layout.tsx
index 40e027f..fa6cad5 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -1,22 +1,28 @@
-import type { Metadata } from 'next'
-import { Inter } from 'next/font/google'
-import './globals.css'
+import type { Metadata } from "next";
+import { Inter } from "next/font/google";
+import "./globals.css";
-const inter = Inter({ subsets: ['latin'] })
+const inter = Inter({ subsets: ["latin"] });
export const metadata: Metadata = {
- title: 'Create Next App',
- description: 'Generated by create next app',
-}
+ title: "Create Next App",
+ description: "Generated by create next app",
+};
export default function RootLayout({
children,
}: {
- children: React.ReactNode
+ children: React.ReactNode;
}) {
return (
+
+
+
{children}
- )
+ );
}
diff --git a/app/page.tsx b/app/page.tsx
index 7a8286b..2136283 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -1,113 +1,106 @@
-import Image from 'next/image'
+"use client";
-export default function Home() {
- return (
-
-
-
- Get started by editing
- app/page.tsx
-
-
-
+import dynamic from "next/dynamic";
+import "@tldraw/tldraw/tldraw.css";
+import { useEditor } from "@tldraw/tldraw";
+import { getSvgAsImage } from "@/lib/getSvgAsImage";
+import { blobToBase64 } from "@/lib/blobToBase64";
+import React, { useEffect, useState } from "react";
+import ReactDOM from "react-dom";
+import { PreviewModal } from "@/components/PreviewModal";
-
-
-
+const Tldraw = dynamic(async () => (await import("@tldraw/tldraw")).Tldraw, {
+ ssr: false,
+});
-
-
-
- Docs{' '}
-
- ->
-
-
-
- Find in-depth information about Next.js features and API.
-
-
+export default function Home() {
+ const [html, setHtml] = useState
(null);
-
-
- Learn{' '}
-
- ->
-
-
-
- Learn about Next.js in an interactive course with quizzes!
-
-
+ useEffect(() => {
+ const listener = (e: KeyboardEvent) => {
+ if (e.key === "Escape") {
+ setHtml(null);
+ }
+ };
+ window.addEventListener("keydown", listener);
-
-
- Templates{' '}
-
- ->
-
-
-
- Explore the Next.js 13 playground.
-
-
+ return () => {
+ window.removeEventListener("keydown", listener);
+ };
+ });
-
-
- Deploy{' '}
-
- ->
-
-
-
- Instantly deploy your Next.js site to a shareable URL with Vercel.
-
-
+ return (
+ <>
+
+
+
+
-
- )
+ {html &&
+ ReactDOM.createPortal(
+ ,
+ document.body
+ )}
+ >
+ );
+}
+
+function ExportButton({ setHtml }: { setHtml: (html: string) => void }) {
+ const editor = useEditor();
+ const [loading, setLoading] = useState(false);
+ // A tailwind styled button that is pinned to the bottom right of the screen
+ return (
+