diff --git a/app/api/toHtml/route.ts b/app/api/toHtml/route.ts
index 5c1abfc..75969e2 100644
--- a/app/api/toHtml/route.ts
+++ b/app/api/toHtml/route.ts
@@ -1,13 +1,18 @@
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.`;
+ a single html file that uses tailwind to create the website.
+ They may also provide you with the html of a previous design that they want you to iterate from.
+ Carry out any changes they request from you.
+ In the wireframe, the previous design's html will appear as a white rectangle.
+ Use creative license to make the application more fleshed out.
+if you need to insert an image, use a colored fill rectangle as a placeholder. Respond only with the html file.`;
export async function POST(request: Request) {
- const { image } = await request.json();
+ const { image, html } = await request.json();
const body: GPT4VCompletionRequest = {
model: "gpt-4-vision-preview",
max_tokens: 4096,
+ temperature: 0,
messages: [
{
role: "system",
@@ -18,9 +23,19 @@ export async function POST(request: Request) {
content: [
{
type: "image_url",
- image_url: image,
+ image_url: {
+ url: image,
+ detail: "high",
+ },
+ },
+ {
+ type: "text",
+ text: "Turn this into a single html file using tailwind.",
+ },
+ {
+ type: "text",
+ text: html,
},
- "Turn this into a single html file using tailwind.",
],
},
],
@@ -50,7 +65,22 @@ export async function POST(request: Request) {
type MessageContent =
| string
- | (string | { type: "image_url"; image_url: string })[];
+ | (
+ | string
+ | {
+ type: "image_url";
+ image_url:
+ | string
+ | {
+ url: string;
+ detail: "low" | "high" | "auto";
+ };
+ }
+ | {
+ type: "text";
+ text: string;
+ }
+ )[];
export type GPT4VCompletionRequest = {
model: "gpt-4-vision-preview";
diff --git a/app/page.tsx b/app/page.tsx
index 5fdb7f9..6612aa8 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -1,42 +1,108 @@
+/* eslint-disable react-hooks/rules-of-hooks */
+
"use client";
import dynamic from "next/dynamic";
import "@tldraw/tldraw/tldraw.css";
-import { useEditor } from "@tldraw/tldraw";
+import {
+ BaseBoxShapeUtil,
+ Geometry2d,
+ HTMLContainer,
+ Rectangle2d,
+ ShapeUtil,
+ TLBaseShape,
+ TLEmbedShape,
+ TLImageShape,
+ TLShapeUtilFlag,
+ toDomPrecision,
+ useEditor,
+ useExportAs,
+ useIsEditing,
+} 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";
+import { format } from "path";
+
+type PreviewShapeType = TLBaseShape<
+ "preview",
+ {
+ html: string;
+ w: number;
+ h: number;
+ }
+>;
+
+class PreviewShape extends BaseBoxShapeUtil {
+ static override type = "preview" as const;
+
+ getDefaultProps(): PreviewShapeType["props"] {
+ return {
+ html: "",
+ w: (960 * 2) / 3,
+ h: (540 * 2) / 3,
+ };
+ }
+
+ override canEdit = () => true;
+ override isAspectRatioLocked = (_shape: PreviewShapeType) => false;
+ override canResize = (_shape: PreviewShapeType) => true;
+ override canBind = (_shape: PreviewShapeType) => false;
+
+ override component(shape: PreviewShapeType) {
+ const isEditing = useIsEditing(shape.id);
+ return (
+
+
+
+ );
+ }
+
+ indicator(shape: PreviewShapeType) {
+ return ;
+ }
+}
const Tldraw = dynamic(async () => (await import("@tldraw/tldraw")).Tldraw, {
ssr: false,
});
export default function Home() {
- const [html, setHtml] = useState(null);
+ // const [html, setHtml] = useState(null);
- useEffect(() => {
- const listener = (e: KeyboardEvent) => {
- if (e.key === "Escape") {
- setHtml(null);
- }
- };
- window.addEventListener("keydown", listener);
+ // useEffect(() => {
+ // const listener = (e: KeyboardEvent) => {
+ // if (e.key === "Escape") {
+ // setHtml(null);
+ // }
+ // };
+ // window.addEventListener("keydown", listener);
- return () => {
- window.removeEventListener("keydown", listener);
- };
- });
+ // return () => {
+ // window.removeEventListener("keydown", listener);
+ // };
+ // });
return (
<>
-
-
+
+
- {html &&
+ {/* {html &&
ReactDOM.createPortal(
,
document.body
- )}
+ )} */}
>
);
}
-function ExportButton({ setHtml }: { setHtml: (html: string) => void }) {
+function ExportButton(/*{ setHtml }: { setHtml: (html: string) => void }*/) {
const editor = useEditor();
const [loading, setLoading] = useState(false);
+ const exportAs = useExportAs();
// A tailwind styled button that is pinned to the bottom right of the screen
return (