From af6aba089ad10c8ffbc5c36655a990db52ff4102 Mon Sep 17 00:00:00 2001 From: Lu Wilson Date: Tue, 14 Nov 2023 12:36:42 +0000 Subject: [PATCH] Add embedded shape experiments (#1) * push latest changes * tweaks * send the html back --- app/api/toHtml/route.ts | 42 +++++++++-- app/page.tsx | 150 ++++++++++++++++++++++++++++++++++------ package-lock.json | 10 +-- 3 files changed, 169 insertions(+), 33 deletions(-) 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 ( + +