demoo / assets /AiStyleTransfer-C0syujQ9.js
admin08077's picture
Upload 85 files
edfe4af verified
import{r as t,j as e}from"./react-D_B_5QVd.js";import{t as b,S as y,L as u}from"./index-QBya0NjG.js";import{m as N}from"./marked-CesSW9Du.js";import"./jszip-C9ownNzX.js";import"./react-dom-EAO2-NBm.js";import"./scheduler-DYLXRpC5.js";import"./@google-4tyssLU_.js";import"./idb-Dob3nYDb.js";const v="function my_func(x,y){return x+y;}",w=`- Use camelCase for function names.
- Add a space after commas in argument lists.
- Use semicolons at the end of statements.`,L=()=>{const[o,f]=t.useState(v),[n,p]=t.useState(w),[a,c]=t.useState(""),[r,m]=t.useState(!1),[d,i]=t.useState(""),[h,x]=t.useState("");t.useEffect(()=>{(async()=>{if(a){const l=await N.parse(a);x(l)}else x("")})()},[a]);const g=t.useCallback(async()=>{if(!o.trim()||!n.trim()){i("Please provide both code and a style guide.");return}m(!0),i(""),c("");try{const s=b({code:o,styleGuide:n});let l="";for await(const j of s)l+=j,c(l)}catch(s){const l=s instanceof Error?s.message:"An unknown error occurred.";i(`Failed to transfer style: ${l}`)}finally{m(!1)}},[o,n]);return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold text-slate-100 flex items-center",children:[e.jsx(y,{}),e.jsx("span",{className:"ml-3",children:"AI Code Style Transfer"})]}),e.jsx("p",{className:"text-slate-400 mt-1",children:"Rewrite code to match a specific style guide using AI."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 h-full overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col h-full gap-4",children:[e.jsxs("div",{className:"flex flex-col flex-1",children:[e.jsx("label",{htmlFor:"input-code",className:"text-sm font-medium text-slate-400 mb-2",children:"Original Code"}),e.jsx("textarea",{id:"input-code",value:o,onChange:s=>f(s.target.value),className:"flex-grow p-4 bg-slate-900 border border-slate-700 rounded-md resize-none font-mono text-sm"})]}),e.jsxs("div",{className:"flex flex-col flex-1",children:[e.jsx("label",{htmlFor:"style-guide",className:"text-sm font-medium text-slate-400 mb-2",children:"Style Guide"}),e.jsx("textarea",{id:"style-guide",value:n,onChange:s=>p(s.target.value),className:"flex-grow p-4 bg-slate-900 border border-slate-700 rounded-md resize-none font-mono text-sm"})]})]}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("label",{className:"text-sm font-medium text-slate-400 mb-2",children:"Rewritten Code"}),e.jsxs("div",{className:"flex-grow p-1 bg-slate-800/50 border border-slate-700/50 rounded-md overflow-y-auto",children:[r&&e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx(u,{})}),d&&e.jsx("p",{className:"p-4 text-red-400",children:d}),a&&!r&&e.jsx("div",{className:"prose prose-sm prose-invert max-w-none prose-pre:bg-transparent prose-pre:p-4 prose-pre:m-0",dangerouslySetInnerHTML:{__html:h}}),!r&&!a&&!d&&e.jsx("div",{className:"text-slate-500 h-full flex items-center justify-center",children:"Rewritten code will appear here."})]})]})]}),e.jsx("div",{className:"flex-shrink-0 pt-4",children:e.jsx("button",{onClick:g,disabled:r,className:"w-full max-w-md mx-auto flex items-center justify-center px-6 py-3 bg-cyan-500 text-slate-900 font-bold rounded-md hover:bg-cyan-400 disabled:bg-slate-600",children:r?e.jsx(u,{}):"Rewrite Code"})})]})};export{L as AiStyleTransfer};
//# sourceMappingURL=AiStyleTransfer-C0syujQ9.js.map