Spaces:
Running
Running
| import{r as a,j as e}from"./react-CIdJ77ke.js";import{ab as k,ac as C,ad as A,ae as G,L as b,S,J as P}from"./index-CX7Qxd1D.js";import{b as U,f as F}from"./fileUtils-DLahR3l0.js";import"./@braintree-DzxiOROe.js";import"./react-dom-R9L8nDNe.js";import"./scheduler-CoSDG3-6.js";import"./@google-CcUHq7Ay.js";import"./idb-Dob3nYDb.js";import"./marked-BrGMJkBT.js";import"./mermaid-KwKZWwy0.js";import"./dayjs-CeEF-NGT.js";import"./d3-transition-CiCB8KJE.js";import"./d3-timer-DdKHrDhs.js";import"./d3-dispatch-kxCwF96_.js";import"./d3-interpolate-CtIaNujU.js";import"./d3-color-amxIadob.js";import"./d3-selection-C52G7wmG.js";import"./d3-ease-DRPgKoYJ.js";import"./d3-zoom-BYoC3mS3.js";import"./dompurify-J5RlrwSC.js";import"./dagre-d3-es-CTpFWynZ.js";import"./lodash-es-Dt6r0yiR.js";import"./d3-shape-CX8xTzfR.js";import"./d3-path-CimkQT29.js";import"./d3-fetch-BOsq7VnW.js";import"./khroma-DUX6PT6k.js";import"./uuid-DhYbOkY1.js";import"./d3-scale-DRZz3QW5.js";import"./internmap-BkD7Hj8s.js";import"./d3-array-DGRYoJHh.js";import"./d3-format-CzD4bSOQ.js";import"./d3-time-format-CUNN4Ell.js";import"./d3-time-6cSPyVSY.js";import"./d3-axis-DSWTncID.js";import"./elkjs-oKFFZvz7.js";import"./cytoscape-DtBltrT8.js";import"./cytoscape-cose-bilkent-Cgr1thlj.js";import"./cose-base-CwCxnKwh.js";import"./layout-base-CMXQqlmj.js";import"./d3-sankey-DgqkLiUE.js";import"./d3-scale-chromatic-B-NsZVaP.js";import"./ts-dedent-DrFu-skq.js";import"./stylis-D5iaQeiq.js";import"./mdast-util-from-markdown-CLAsVoWb.js";import"./micromark-CTBPIv-_.js";import"./micromark-util-combine-extensions-Bka6Sc1c.js";import"./micromark-util-chunked-DrRIdSP-.js";import"./micromark-factory-space-x2vfxbz5.js";import"./micromark-util-character-Bcm1tP9o.js";import"./micromark-core-commonmark-AH8VCgT7.js";import"./micromark-util-classify-character-Cq7Fg3xE.js";import"./micromark-util-resolve-all-PQCKh0dx.js";import"./decode-named-character-reference-C3-224fz.js";import"./micromark-util-subtokenize-QwsxNXk2.js";import"./micromark-factory-destination-CypD_wgM.js";import"./micromark-factory-label-CRHH4ZHP.js";import"./micromark-factory-title-B7kCBvC9.js";import"./micromark-factory-whitespace-B322EA6O.js";import"./micromark-util-normalize-identifier-C9ANKk3v.js";import"./micromark-util-html-tag-name-DbKNfynz.js";import"./micromark-util-decode-numeric-character-reference-DRnCnno4.js";import"./micromark-util-decode-string-DJl8Y_PO.js";import"./unist-util-stringify-position-Ch_qCilz.js";import"./mdast-util-to-string-C_aolqmU.js";import"./jszip-CFFhfFtd.js";import"./octokit-B6bKu3NB.js";import"./@octokit-MBEWYTsi.js";import"./bottleneck-D_vuF9V7.js";import"./universal-user-agent-CLgqIJsR.js";import"./before-after-hook-y8XtM9xW.js";import"./fast-content-type-parse-3SwieiST.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."],Ke=()=>{const[o,d]=a.useState("A photorealistic image of a futuristic city at sunset, with flying cars."),[s,p]=a.useState(null),[l,x]=a.useState(null),[i,u]=a.useState(!1),[c,n]=a.useState(""),g=a.useRef(null),y=a.useCallback(async()=>{if(!o.trim()){n("Please enter a prompt to generate an image.");return}u(!0),n(""),x(null);try{let t;s?t=await k(o,s.base64,s.mimeType):t=await C(o),x(t)}catch(t){const r=t instanceof Error?t.message:"An unknown error occurred.";n(`Failed to generate image: ${r}`)}finally{u(!1)}},[o,s]),w=()=>{const t=j[Math.floor(Math.random()*j.length)];d(t)},h=async t=>{try{const[r,m]=await Promise.all([U(t),F(t)]);p({dataUrl:r,base64:m,mimeType:t.type})}catch{n("Could not process the image.")}},N=a.useCallback(async t=>{const r=t.clipboardData.items;for(const m of r)if(m.type.indexOf("image")!==-1){const f=m.getAsFile();if(f){await h(f);return}}},[]),I=async t=>{const r=t.target.files?.[0];r&&await h(r)},v=()=>{if(!l)return;const t=document.createElement("a");t.href=l,t.download=`${o.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:o,onChange:t=>d(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:s?e.jsxs(e.Fragment,{children:[e.jsx("img",{src:s.dataUrl,alt:"Uploaded content",className:"max-w-full max-h-full object-contain rounded-md shadow-lg"}),e.jsx("button",{onClick:()=>p(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:()=>g.current?.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:i,className:"btn-primary w-full flex items-center justify-center px-6 py-3",children:i?e.jsx(b,{}):"Generate Image"}),e.jsx("button",{onClick:w,disabled:i,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:[i&&e.jsx(b,{}),c&&e.jsx("p",{className:"text-red-500 text-center",children:c}),l&&!i&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:l,alt:o||"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,{})})]}),!i&&!l&&!c&&e.jsx("div",{className:"text-center text-text-secondary",children:e.jsx("p",{children:"Your generated image will appear here."})})]})]})]})]})};export{Ke as AiImageGenerator}; | |
| //# sourceMappingURL=AiImageGenerator-DdG4FXBe.js.map | |