@imgly/plugin-ai-image-generation-web 0.2.7 → 0.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -128,38 +128,15 @@ var Nt=`
128
128
  `;var Ct={ImageUrl:Dn,StyleTransfer:Gs};var Et={openapi:"3.0.0",components:{schemas:{GptImage1Input:{title:"TextToImageInput",type:"object",properties:{prompt:{title:"Prompt",type:"string","x-imgly-builder":{component:"TextArea"}},style:{title:"Style",type:"string",description:"The style of the generated images."},size:{enum:["1024x1024","1536x1024","1024x1536"],type:"string",title:"Format",default:"1024x1024","x-imgly-enum-labels":{"1024x1024":"Square","1536x1024":"Landscape","1024x1536":"Portrait"},"x-imgly-enum-icons":{"1024x1024":"@imgly/plugin/formats/ratio1by1","1024x1536":"@imgly/plugin/formats/ratio3by4","1536x1024":"@imgly/plugin/formats/ratio4by3"}},background:{enum:["auto","transparent","opaque"],type:"string",title:"Background",default:"auto","x-imgly-enum-labels":{auto:"Auto",transparent:"Transparent",opaque:"Opaque"}}},"x-order-properties":["prompt","style","size","background"],required:["prompt"]}}}};function ue(e,t){let r=e.split(",")[1]||e,i=atob(r),a=[];for(let l=0;l<i.length;l++)a.push(i.charCodeAt(l));let n=new Uint8Array(a);return new Blob([n],{type:t})}var X=[{id:"none",label:"None",prompt:""},{id:"anime-celshaded",label:"Anime",prompt:"anime cel\u2011shaded, bright pastel palette, expressive eyes, clean line art "},{id:"cyberpunk-neon",label:"Cyberpunk",prompt:"cyberpunk cityscape, glowing neon signage, reflective puddles, dark atmosphere"},{id:"kodak-portra-400",label:"Kodak 400",prompt:"shot on Kodak Portra 400, soft grain, golden\u2011hour warmth, 35 mm photo"},{id:"watercolor-storybook",label:"Watercolor",prompt:"loose watercolor washes, gentle gradients, dreamy storybook feel"},{id:"dark-fantasy-realism",label:"Dark Fantasy",prompt:"dark fantasy realm, moody chiaroscuro lighting, hyper\u2011real textures"},{id:"vaporwave-retrofuturism",label:"Vaporwave",prompt:"retro\u2011futuristic vaporwave, pastel sunset gradient, chrome text, VHS scanlines"},{id:"minimal-vector-flat",label:"Vector Flat",prompt:"minimalist flat vector illustration, bold geometry, two\u2011tone palette"},{id:"pixarstyle-3d-render",label:"3D Animation",prompt:"Pixar\u2011style 3D render, oversized eyes, subtle subsurface scattering, cinematic lighting"},{id:"ukiyoe-woodblock",label:"Ukiyo\u2011e",prompt:"ukiyo\u2011e woodblock print, Edo\u2011period style, visible washi texture, limited color ink"},{id:"surreal-dreamscape",label:"Surreal",prompt:"surreal dreamscape, floating objects, impossible architecture, vivid clouds"},{id:"steampunk-victorian",label:"Steampunk",prompt:"Victorian steampunk world, ornate brass gears, leather attire, atmospheric fog"},{id:"nightstreet-photo-bokeh",label:"Night Bokeh",prompt:"night\u2011time street shot, large aperture bokeh lights, candid urban mood"},{id:"comicbook-pop-art",label:"Pop Art",prompt:"classic comic\u2011book panel, halftone shading, exaggerated action lines, CMYK pop colors"}],Mt=(e,t)=>{let r=X.map(n=>n.id==="none"?t.includeNone?{id:n.id,label:n.label,thumbUri:`${t.baseURL}/thumbnails/None.svg`}:void 0:{id:n.id,label:n.label,thumbUri:`${t.baseURL}/thumbnails/${n.id}.jpeg`}).filter(ne),i=new ee(e,r),a=X[0];return i.setAssetActive(a.id),i},jt=(e,t)=>{t.cesdk.engine.asset.addSource(e),t.cesdk.ui.addAssetLibraryEntry({id:e.id,sourceIds:[e.id],gridItemHeight:"square",gridBackgroundType:"cover",cardLabel:({label:r})=>r,cardLabelPosition:()=>"below"})};function $t(e){return async({cesdk:t})=>Ys(t,e)}function Ys(e,t){let r="open-ai/gpt-image-1/text2image",i="https://cdn.img.ly/assets/plugins/plugin-ai-image-generation-web/v1/gpt-image-1/",a=`${r}/styles`,n=Mt(a,{baseURL:i,includeNone:!0});return jt(n,{cesdk:e}),e.ui.registerPanel(`${J(r)}.styleSelection`,({builder:l,payload:v})=>{if(v==null)return null;l.Library(`${r}.library.style`,{entries:[a],onSelect:async g=>{v.onSelect(g)}})}),e.ui.addIconSet("@imgly/plugin/formats",ae.Formats),e.i18n.setTranslations({en:{[`panel.${J(r)}.styleSelection`]:"Style Selection","panel.gpt-image-1.imageSelection":"Select Image To Change"}}),{id:"open-ai/gpt-image-1/text2image",kind:"image",name:"GPT Image 1",input:{panel:{type:"schema",document:Et,inputReference:"#/components/schemas/GptImage1Input",includeHistoryLibrary:!0,orderExtensionKeyword:"x-order-properties",renderCustomProperty:{style:({builder:l,state:v},g)=>{let p=v("style",n.getAssetSelectValue(n.getActiveAssetIds()[0])??X[0]);return l.Button(`${g.id}`,{inputLabel:[`ly.img.plugin-ai-image-generation-web.${r}.property.${g.id}`,`ly.img.plugin-ai-generation-web.property.${g.id}`,`ly.img.plugin-ai-image-generation-web.${r}.defaults.property.${g.id}`,`ly.img.plugin-ai-generation-web.defaults.property.${g.id}`],icon:"@imgly/Appearance",trailingIcon:"@imgly/ChevronRight",label:p.value.label,labelAlignment:"left",onClick:()=>{let u={onSelect:async w=>{let h={id:w.id,label:w.label??w.id};n.clearActiveAssets(),n.setAssetActive(w.id),p.setValue(h),e.ui.closePanel(`${J(r)}.styleSelection`)}};e.ui.openPanel(`${J(r)}.styleSelection`,{payload:u})}}),()=>({id:g.id,type:"string",value:p.value.id??n.getActiveAssetIds()[0]})}},getBlockInput:l=>{switch(l.size){case"auto":return Promise.resolve({image:{width:512,height:512}});case"1024x1024":return Promise.resolve({image:{width:1024,height:1024}});case"1536x1024":return Promise.resolve({image:{width:1536,height:1024}});case"1024x1536":return Promise.resolve({image:{width:1024,height:1536}});default:throw new Error("Invalid image size")}},userFlow:"placeholder"}},output:{abortable:!0,history:"@imgly/indexedDB",middleware:t.middlewares??t.middleware??[],generate:async(l,{abortSignal:v})=>{let g=X.find(c=>c.id===l.style),p=l.prompt;g!=null&&g.id!=="none"&&g.prompt&&(p=`${p}, ${g.prompt}`);let u=e.ui.experimental.hasGlobalStateValue("OPENAI_API_KEY"),w=u?"https://api.openai.com/v1":t.proxyUrl,f=(await(await fetch(`${w}/images/generations`,{signal:v,method:"POST",headers:u?{Authorization:`Bearer ${e.ui.experimental.getGlobalStateValue("OPENAI_API_KEY")}`,"Content-Type":"application/json",...t.headers??{}}:{"Content-Type":"application/json",...t.headers??{}},body:JSON.stringify({model:"gpt-image-1",prompt:p,n:1,size:l.size,background:l.background})})).json()).data?.[0].b64_json;if(f==null)throw new Error("No image data returned");let k=ue(f,"image/png");return{kind:"image",url:URL.createObjectURL(k)}}}}}var Lt={openapi:"3.0.0",components:{schemas:{GptImage1Input:{title:"ImageToImageInput",type:"object",properties:{prompt:{title:"Prompt",type:"string","x-imgly-builder":{component:"TextArea"}},image_url:{title:"Image Url",type:"string",description:"Optional URL of an input image for editing."}},"x-order-properties":["image_url","prompt","background"],required:["image_url","prompt"]}}}};import{MimeType as Xs}from"@cesdk/cesdk-js";var Pt="gpt-image-1.changeStyleLibrary",Le=`ly.img.${Pt}`,ce=`ly.img.plugin-ai-image-generation-web.quickAction.${Pt}`,Pe=[{id:"none",label:"None",prompt:""},{id:"anime-celshaded",label:"Anime",prompt:"anime cel\u2011shaded, bright pastel palette, expressive eyes, clean line art "},{id:"cyberpunk-neon",label:"Cyberpunk",prompt:"cyberpunk cityscape, glowing neon signage, reflective puddles, dark atmosphere"},{id:"kodak-portra-400",label:"Kodak 400",prompt:"shot on Kodak Portra 400, soft grain, golden\u2011hour warmth, 35 mm photo"},{id:"watercolor-storybook",label:"Watercolor",prompt:"loose watercolor washes, gentle gradients, dreamy storybook feel"},{id:"dark-fantasy-realism",label:"Dark Fantasy",prompt:"dark fantasy realm, moody chiaroscuro lighting, hyper\u2011real textures"},{id:"vaporwave-retrofuturism",label:"Vaporwave",prompt:"retro\u2011futuristic vaporwave, pastel sunset gradient, chrome text, VHS scanlines"},{id:"minimal-vector-flat",label:"Vector Flat",prompt:"minimalist flat vector illustration, bold geometry, two\u2011tone palette"},{id:"pixarstyle-3d-render",label:"3D Animation",prompt:"Pixar\u2011style 3D render, oversized eyes, subtle subsurface scattering, cinematic lighting"},{id:"ukiyoe-woodblock",label:"Ukiyo\u2011e",prompt:"ukiyo\u2011e woodblock print, Edo\u2011period style, visible washi texture, limited color ink"},{id:"surreal-dreamscape",label:"Surreal",prompt:"surreal dreamscape, floating objects, impossible architecture, vivid clouds"},{id:"steampunk-victorian",label:"Steampunk",prompt:"Victorian steampunk world, ornate brass gears, leather attire, atmospheric fog"},{id:"nightstreet-photo-bokeh",label:"Night Bokeh",prompt:"night\u2011time street shot, large aperture bokeh lights, candid urban mood"},{id:"comicbook-pop-art",label:"Pop Art",prompt:"classic comic\u2011book panel, halftone shading, exaggerated action lines, CMYK pop colors"}],Qs=(e,t)=>{let r=Pe.map(n=>n.id==="none"?t.includeNone?{id:n.id,label:n.label,thumbUri:`${t.baseURL}/thumbnails/None.svg`}:void 0:{id:n.id,label:n.label,thumbUri:`${t.baseURL}/thumbnails/${n.id}.jpeg`}).filter(ne),i=new ee(e,r),a=Pe[0];return i.setAssetActive(a.id),i},Ws=(e,t)=>{t.cesdk.engine.asset.addSource(e),t.cesdk.ui.addAssetLibraryEntry({id:e.id,sourceIds:[e.id],gridItemHeight:"square",gridBackgroundType:"cover",cardLabel:({label:r})=>r,cardLabelPosition:()=>"below"})},Js=e=>{let{cesdk:t,modelKey:r,baseURL:i}=e,a=`${r}/styles`,s=Qs(a,{baseURL:i??"https://cdn.img.ly/assets/plugins/plugin-ai-image-generation-web/v1/gpt-image-1/"});return Ws(s,{cesdk:t}),t.i18n.setTranslations({en:{[`${ce}`]:"Change Style",[`${ce}.description`]:"Apply different art styles to your image"}}),{id:Le,type:"quick",kind:"image",label:`${ce}`,enable:xt(),scopes:["fill/change"],render:({builder:v,experimental:g,generate:p,engine:u,close:w})=>{g.builder.Popover(`${Le}.popover`,{label:`${ce}`,icon:"@imgly/Appearance",labelAlignment:"left",variant:"plain",trailingIcon:"@imgly/ChevronRight",placement:"right",children:()=>{v.Library(`${Le}.popover.library`,{entries:[`${r}/styles`],onSelect:async h=>{try{let[I]=u.block.findAllSelected(),f=await tt(I,u,{throwErrorIfSvg:!0}),k=h.id,o=Pe.find(({id:c})=>c===k);if(o==null)throw new Error(`Style not found: ${k}`);await p({prompt:o.prompt,uri:f}),w()}catch(I){console.error("Generation error:",I)}}})}})}}},_t=Js;function Tt(e){return async({cesdk:t})=>el(t,e)}function el(e,t){let r="open-ai/gpt-image-1/image2image";return e.ui.addIconSet("@imgly/plugin/formats",ae.Formats),At.get().register(_t({cesdk:e,modelKey:r,baseURL:"https://cdn.img.ly/assets/plugins/plugin-ai-image-generation-web/v1/gpt-image-1/"})),{id:r,kind:"image",name:"GPT Image 1",input:{panel:{type:"schema",document:Lt,inputReference:"#/components/schemas/GptImage1Input",includeHistoryLibrary:!0,orderExtensionKeyword:"x-order-properties",renderCustomProperty:{...e!=null?Ct.ImageUrl("gpt-image-1",{cesdk:e}):{}},getBlockInput:async n=>{if(n.image_url==null||Array.isArray(n.image_url))throw new Error("Cannot process getBlockInput for multiple images");let{width:s,height:l}=await et(n.image_url,e.engine);return Promise.resolve({image:{width:s,height:l}})},userFlow:"placeholder"},quickActions:{supported:{"ly.img.gpt-image-1.changeStyleLibrary":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})},"ly.img.editImage":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})},"ly.img.swapBackground":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})},"ly.img.createVariant":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})},"ly.img.combineImages":{mapInput:n=>({prompt:n.prompt,image_url:n.uris,exportFromBlockIds:n.exportFromBlockIds})},"ly.img.remixPage":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})},"ly.img.remixPageWithPrompt":{mapInput:n=>({prompt:n.prompt,image_url:n.uri})}}}},output:{abortable:!0,history:"@imgly/indexedDB",middleware:t.middlewares??t.middleware??[],generate:async(n,{abortSignal:s})=>{let l=new FormData;if(Array.isArray(n.image_url))n.exportFromBlockIds!=null?await Promise.all(n.exportFromBlockIds.map(async f=>{let k=await e.engine.block.export(f,Xs.Jpeg,{targetHeight:1024,targetWidth:1024});l.append("image[]",k,`image_${f}.jpeg`)})):await Promise.all(n.image_url.map(async f=>{let k=await e.engine.editor.getMimeType(f),o=await q(f,e.engine),d=await(await fetch(o)).blob();l.append("image[]",d,`image.${we(k)}`)}));else{let f=await e.engine.editor.getMimeType(n.image_url),k=await q(n.image_url,e.engine),c=await(await fetch(k)).blob();l.append("image",c,`image.${we(f)}`)}l.append("prompt",n.prompt),l.append("model","gpt-image-1"),l.append("size","auto"),l.append("n","1");let v=e.ui.experimental.hasGlobalStateValue("OPENAI_API_KEY"),g=v?"https://api.openai.com/v1":t.proxyUrl,w=(await(await fetch(`${g}/images/edits`,{signal:s,method:"POST",headers:v?{Authorization:`Bearer ${e.ui.experimental.getGlobalStateValue("OPENAI_API_KEY")}`,...t.headers??{}}:{...t.headers??{}},body:l})).json()).data?.[0].b64_json;if(w==null)throw new Error("No image data returned");let h=ue(w,"image/png");return{kind:"image",url:URL.createObjectURL(h)}}}}}var tl={GptImage1:{Text2Image:$t,Image2Image:Tt}},gu=tl;export{gu as default};
129
129
  /*! Bundled license information:
130
130
 
131
- @imgly/plugin-utils/dist/index.mjs:
132
- (*! Bundled license information:
133
-
134
- lodash-es/lodash.js:
135
- (**
136
- * @license
137
- * Lodash (Custom Build) <https://lodash.com/>
138
- * Build: `lodash modularize exports="es" -o ./`
139
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
140
- * Released under MIT license <https://lodash.com/license>
141
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
142
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
143
- *)
144
- *)
145
-
146
- @imgly/plugin-ai-generation-web/dist/index.mjs:
147
- (*! Bundled license information:
148
-
149
- @imgly/plugin-utils/dist/index.mjs:
150
- (*! Bundled license information:
151
-
152
- lodash-es/lodash.js:
153
- (**
154
- * @license
155
- * Lodash (Custom Build) <https://lodash.com/>
156
- * Build: `lodash modularize exports="es" -o ./`
157
- * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
158
- * Released under MIT license <https://lodash.com/license>
159
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
160
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
161
- *)
162
- *)
163
- *)
131
+ lodash-es/lodash.js:
132
+ (**
133
+ * @license
134
+ * Lodash (Custom Build) <https://lodash.com/>
135
+ * Build: `lodash modularize exports="es" -o ./`
136
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
137
+ * Released under MIT license <https://lodash.com/license>
138
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
139
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
140
+ *)
164
141
  */
165
142
  //# sourceMappingURL=index.mjs.map