Spaces:
Running
Running
| import{r,j as e}from"./react-B-lWpQRQ.js";import{an as k,ao as C,ap as A,X as G,L as b,S,T as P}from"./index-DyMS-nC-.js";import"./@google-xfXoiafW.js";import{b as U,f as F}from"./fileUtils-DLahR3l0.js";import"./marked-CesSW9Du.js";import"./@braintree-DY5JYOZd.js";import"./react-dom-CU2yWD-Y.js";import"./scheduler-DYLXRpC5.js";import"./idb-Dob3nYDb.js";import"./axe-core-CA05Kxsw.js";import"./@mermaid-js-Ce0__7Tp.js";import"./langium-B_PGe6V2.js";import"./vscode-jsonrpc-2tvYB2ki.js";import"./chevrotain-D5DQZOif.js";import"./@chevrotain-DMYZVohV.js";import"./lodash-es-CKTcnrxn.js";import"./chevrotain-allstar-eFSt8-qu.js";import"./vscode-languageserver-types-NoPvPymt.js";import"./vscode-languageserver-textdocument-CKBVUiR3.js";import"./vscode-uri-CoxP0whD.js";const j=["A majestic lion wearing a crown, painted in the style of Van Gogh.","A futuristic cityscape on another planet with two moons in the sky.","A cozy, magical library inside a giant tree.","A surreal image of a ship sailing on a sea of clouds.","An astronaut riding a space-themed bicycle on the moon."],Z=()=>{const[s,m]=r.useState("A photorealistic image of a futuristic city at sunset, with flying cars."),[l,x]=r.useState(null),[i,p]=r.useState(null),[n,u]=r.useState(!1),[d,c]=r.useState(""),g=r.useRef(null),y=r.useCallback(async()=>{if(!s.trim()){c("Please enter a prompt to generate an image.");return}u(!0),c(""),p(null);try{let t;l?t=await k(s,l.base64,l.mimeType):t=await C(s),p(t)}catch(t){const a=t instanceof Error?t.message:"An unknown error occurred.";c(`Failed to generate image: ${a}`)}finally{u(!1)}},[s,l]),w=()=>{const t=j[Math.floor(Math.random()*j.length)];m(t)},h=async t=>{try{const[a,o]=await Promise.all([U(t),F(t)]);x({dataUrl:a,base64:o,mimeType:t.type})}catch{c("Could not process the image.")}},N=r.useCallback(async t=>{const a=t.clipboardData.items;for(const o of a)if(o.type.indexOf("image")!==-1){const f=o.getAsFile();if(f){await h(f);return}}},[]),I=async t=>{var o;const a=(o=t.target.files)==null?void 0:o[0];a&&await h(a)},v=()=>{if(!i)return;const t=document.createElement("a");t.href=i,t.download=`${s.slice(0,30).replace(/\s/g,"_")}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)};return e.jsxs("div",{className:"h-full flex flex-col p-4 sm:p-6 lg:p-8 text-text-primary",children:[e.jsxs("header",{className:"mb-6",children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center",children:[e.jsx(A,{}),e.jsx("span",{className:"ml-3",children:"AI Image Generator"})]}),e.jsx("p",{className:"text-text-secondary mt-1",children:"Generate images from text, or provide an image for inspiration."})]}),e.jsxs("div",{className:"flex-grow grid grid-cols-1 lg:grid-cols-2 gap-6 min-h-0",children:[e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"prompt-input",className:"text-sm font-medium text-text-secondary",children:"Your Prompt"}),e.jsx("textarea",{id:"prompt-input",value:s,onChange:t=>m(t.target.value),placeholder:"e.g., A cute cat wearing a wizard hat",className:"w-full p-3 mt-1 rounded-md bg-surface border border-border focus:ring-2 focus:ring-primary focus:outline-none resize-y",rows:3})]}),e.jsxs("div",{className:"flex flex-col flex-grow min-h-[200px]",children:[e.jsx("label",{className:"text-sm font-medium text-text-secondary mb-1",children:"Inspiration Image (Optional)"}),e.jsx("div",{onPaste:N,className:"relative flex-grow flex flex-col items-center justify-center bg-surface p-4 rounded-lg border-2 border-dashed border-border focus:outline-none focus:border-primary",tabIndex:0,children:l?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:l.dataUrl,alt:"Uploaded content",className:"max-w-full max-h-full object-contain rounded-md shadow-lg"}),e.jsx("button",{onClick:()=>x(null),className:"absolute top-2 right-2 p-1 bg-black/30 text-white rounded-full hover:bg-black/50",children:e.jsx(G,{})})]}):e.jsxs("div",{className:"text-center text-text-secondary",children:[e.jsx("h2",{className:"text-lg font-bold text-text-primary",children:"Paste an image here"}),e.jsx("p",{className:"text-sm",children:"(Cmd/Ctrl + V)"}),e.jsx("p",{className:"text-xs my-1",children:"or"}),e.jsx("button",{onClick:()=>{var t;return(t=g.current)==null?void 0:t.click()},className:"text-sm font-semibold text-primary hover:underline",children:"Upload File"}),e.jsx("input",{type:"file",ref:g,onChange:I,accept:"image/*",className:"hidden"})]})})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:y,disabled:n,className:"btn-primary w-full flex items-center justify-center px-6 py-3",children:n?e.jsx(b,{}):"Generate Image"}),e.jsx("button",{onClick:w,disabled:n,className:"px-4 py-3 bg-surface border border-border rounded-md hover:bg-gray-100 transition-colors",title:"Surprise Me!",children:e.jsx(S,{})})]})]}),e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx("label",{className:"text-sm font-medium text-text-secondary mb-2",children:"Generated Image"}),e.jsxs("div",{className:"flex-grow flex items-center justify-center bg-background border-2 border-dashed border-border rounded-lg p-4 relative overflow-auto",children:[n&&e.jsx(b,{}),d&&e.jsx("p",{className:"text-red-500 text-center",children:d}),i&&!n&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:i,alt:s||"Generated by AI",className:"max-w-full max-h-full object-contain rounded-md shadow-lg"}),e.jsx("button",{onClick:v,className:"absolute top-4 right-4 p-2 bg-black/30 text-white rounded-full hover:bg-black/50 backdrop-blur-sm",title:"Download Image",children:e.jsx(P,{})})]}),!n&&!i&&!d&&e.jsx("div",{className:"text-center text-text-secondary",children:e.jsx("p",{children:"Your generated image will appear here."})})]})]})]})]})};export{Z as AiImageGenerator}; | |
| //# sourceMappingURL=AiImageGenerator-BuAzPwpb.js.map | |