@uploadcare/ai-enhancer 0.1.3 → 0.1.4

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./UcAiEnhancer-Co-HZ72E.cjs"),r=require("./errors.cjs");Object.defineProperty(exports,"UcAiEnhancer",{enumerable:!0,get:()=>e.UcAiEnhancer});exports.enLocale=e.enLocale;exports.AiEnhancerError=r.AiEnhancerError;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./UcAiEnhancer-h1VGkbGn.cjs"),r=require("./errors.cjs");Object.defineProperty(exports,"UcAiEnhancer",{enumerable:!0,get:()=>e.UcAiEnhancer});exports.enLocale=e.enLocale;exports.AiEnhancerError=r.AiEnhancerError;
@@ -116,6 +116,17 @@ export declare type AspectRatio = readonly [number, number];
116
116
  */
117
117
  export declare type CanvasFit = 'full' | 'available';
118
118
 
119
+ /**
120
+ * Detail of the `uc:change` event: the current generation result, or `null`
121
+ * when the editor no longer holds one (Start over). Fires whenever the
122
+ * current result changes — a finished generation, a history-strip selection,
123
+ * or a reset — so a host can drive its own chrome (see
124
+ * {@link UcAiEnhancer.toolbarPlacement} `none`).
125
+ */
126
+ export declare type ChangeDetail = {
127
+ result: DoneDetail | null;
128
+ };
129
+
119
130
  /** Which edge the composer (prompt + chips + aspect ratio) sits on. */
120
131
  export declare type ComposerPlacement = 'top' | 'bottom';
121
132
 
@@ -266,8 +277,12 @@ export declare type SecureDeliveryUrlParts = {
266
277
 
267
278
  /* Excluded from this release type: ShimmerConfig */
268
279
 
269
- /** Where the toolbar (Cancel / Done) sits within the editor. */
270
- export declare type ToolbarPlacement = 'bottom' | 'top';
280
+ /**
281
+ * Where the toolbar (Cancel / Done) sits within the editor — or `none` to
282
+ * render no toolbar at all (host-driven chrome: observe `uc:change` and close
283
+ * the editor yourself).
284
+ */
285
+ export declare type ToolbarPlacement = 'bottom' | 'top' | 'none';
271
286
 
272
287
  /**
273
288
  * `<uc-ai-enhancer>` — the standalone AI image generate/edit editor.
@@ -282,6 +297,10 @@ export declare type ToolbarPlacement = 'bottom' | 'top';
282
297
  * result (the Done button). `detail` carries the result `url`, `uuid`,
283
298
  * `prompt`, `mode`, optional `aspectRatio`, and the `file` object.
284
299
  * @fires uc:cancel - Fired when the user cancels (the Cancel button). No detail.
300
+ * @fires uc:change - A `CustomEvent<ChangeDetail>` fired whenever the current
301
+ * generation result changes (finished generation, history selection, or
302
+ * reset — then `detail.result` is `null`). Lets a host drive its own chrome
303
+ * when the toolbar is hidden (`toolbar-placement="none"`).
285
304
  * @fires uc:error - A `CustomEvent<ErrorDetail>` fired when a generation
286
305
  * throws. `detail.error` is always an `AiEnhancerError` — its `code` maps to
287
306
  * a localized message and the original thrown value is on `.cause`.
@@ -392,7 +411,11 @@ export declare class UcAiEnhancer extends LitElement {
392
411
  */
393
412
  historyPlacement: HistoryPlacement;
394
413
  /* Excluded from this release type: composerAutoHide */
395
- /** Where the toolbar (Cancel / Done) sits: `bottom` (default) or `top`. */
414
+ /**
415
+ * Where the toolbar (Cancel / Done) sits: `bottom` (default) or `top`.
416
+ * `none` hides the toolbar entirely — the host provides its own chrome,
417
+ * tracking the current result via the `uc:change` event.
418
+ */
396
419
  toolbarPlacement: ToolbarPlacement;
397
420
  /* Excluded from this release type: shimmerConfig */
398
421
  private _prompt;
@@ -504,8 +527,12 @@ export declare class UcAiEnhancer extends LitElement {
504
527
  private _onSelectHistoryEntry;
505
528
  private _onSelectAspectRatio;
506
529
  private _onSelectPreset;
530
+ /** Snapshot of the current generation result in the `uc:done` payload shape. */
531
+ private _resultDetail;
507
532
  private _onPrimary;
508
533
  private _onCancel;
534
+ private _lastResult;
535
+ /* Excluded from this release type: updated */
509
536
  /* Excluded from this release type: render */
510
537
  }
511
538
 
@@ -1,4 +1,4 @@
1
- import { U as o, e as a } from "./UcAiEnhancer-DK6rhHp7.js";
1
+ import { U as o, e as a } from "./UcAiEnhancer-BZeCfJ6W.js";
2
2
  import { AiEnhancerError as c } from "./errors.js";
3
3
  export {
4
4
  c as AiEnhancerError,
package/dist/plugin.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./UcAiEnhancer-Co-HZ72E.cjs"),L="free";function A(o){return o?o.split(/[\s,]+/).filter(Boolean):[]}function N(o){const r=A(o);if(r.length===0)return[];const c=[];for(const e of r){const i=e.trim();if(!i)continue;const f=i===L,y=i.indexOf(":");if(y===-1&&!f){console.warn(`Invalid crop preset: ${i}`);continue}const g=f?0:Number(i.slice(0,y)),t=f?0:Number(i.slice(y+1));if(!f&&(!Number.isFinite(g)||!Number.isFinite(t)||g<=0||t<=0)){console.warn(`Invalid crop preset: ${i}`);continue}c.push({id:crypto.randomUUID(),type:"aspect-ratio",width:g,height:t,hasFreeform:f})}return c}const d="ai-enhancer",O=[["--uc-ai-foreground","--uc-foreground"],["--uc-ai-background","--uc-background"],["--uc-ai-muted","--uc-muted"],["--uc-ai-muted-foreground","--uc-muted-foreground"],["--uc-ai-primary","--uc-primary"],["--uc-ai-primary-hover","--uc-primary-hover"],["--uc-ai-primary-foreground","--uc-primary-foreground"],["--uc-ai-primary-transparent","--uc-primary-transparent"],["--uc-ai-secondary","--uc-secondary"],["--uc-ai-secondary-hover","--uc-secondary-hover"],["--uc-ai-secondary-foreground","--uc-secondary-foreground"],["--uc-ai-border","--uc-border"],["--uc-ai-destructive","--uc-destructive"],["--uc-ai-dialog-shadow","--uc-dialog-shadow"],["--uc-ai-radius","--uc-radius"],["--uc-ai-padding","--uc-padding"],["--uc-ai-button-size","--uc-button-size"],["--uc-ai-font-family","--uc-font-family"],["--uc-ai-font-size","--uc-font-size"],["--uc-ai-transition","--uc-transition"]];function R(o){for(const[r,c]of O)o.style.setProperty(r,`var(${c})`)}const P="uc-ai-enhancer-activity-size";function U(){if(typeof document>"u"||document.getElementById(P))return;const o=document.createElement("style");o.id=P,o.textContent=[`[uc-modal]:not(#\\#) > dialog:has([activity="${d}"][active]) {`," --uc-dialog-max-width: 1440px;"," --uc-dialog-max-height: 900px;"," width: 100%;"," height: 100%;","}"].join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./UcAiEnhancer-h1VGkbGn.cjs"),L="free";function A(o){return o?o.split(/[\s,]+/).filter(Boolean):[]}function N(o){const r=A(o);if(r.length===0)return[];const c=[];for(const e of r){const i=e.trim();if(!i)continue;const f=i===L,y=i.indexOf(":");if(y===-1&&!f){console.warn(`Invalid crop preset: ${i}`);continue}const g=f?0:Number(i.slice(0,y)),t=f?0:Number(i.slice(y+1));if(!f&&(!Number.isFinite(g)||!Number.isFinite(t)||g<=0||t<=0)){console.warn(`Invalid crop preset: ${i}`);continue}c.push({id:crypto.randomUUID(),type:"aspect-ratio",width:g,height:t,hasFreeform:f})}return c}const d="ai-enhancer",O=[["--uc-ai-foreground","--uc-foreground"],["--uc-ai-background","--uc-background"],["--uc-ai-muted","--uc-muted"],["--uc-ai-muted-foreground","--uc-muted-foreground"],["--uc-ai-primary","--uc-primary"],["--uc-ai-primary-hover","--uc-primary-hover"],["--uc-ai-primary-foreground","--uc-primary-foreground"],["--uc-ai-primary-transparent","--uc-primary-transparent"],["--uc-ai-secondary","--uc-secondary"],["--uc-ai-secondary-hover","--uc-secondary-hover"],["--uc-ai-secondary-foreground","--uc-secondary-foreground"],["--uc-ai-border","--uc-border"],["--uc-ai-destructive","--uc-destructive"],["--uc-ai-dialog-shadow","--uc-dialog-shadow"],["--uc-ai-radius","--uc-radius"],["--uc-ai-padding","--uc-padding"],["--uc-ai-button-size","--uc-button-size"],["--uc-ai-font-family","--uc-font-family"],["--uc-ai-font-size","--uc-font-size"],["--uc-ai-transition","--uc-transition"]];function R(o){for(const[r,c]of O)o.style.setProperty(r,`var(${c})`)}const P="uc-ai-enhancer-activity-size";function U(){if(typeof document>"u"||document.getElementById(P))return;const o=document.createElement("style");o.id=P,o.textContent=[`[uc-modal]:not(#\\#) > dialog:has([activity="${d}"][active]) {`," --uc-dialog-max-width: 1440px;"," --uc-dialog-max-height: 900px;"," width: 100%;"," height: 100%;","}"].join(`
2
2
  `),document.head.appendChild(o)}function v(o){const r=N(o);if(r.length===0)return null;const c=r.some(i=>i.hasFreeform),e=r.filter(i=>!i.hasFreeform).map(i=>[i.width,i.height]).filter(m.isValidAspectRatio);return c&&e.length===0?[...m.POPULAR_ASPECT_RATIOS]:c||e.length>0?e:null}const w={id:d,setup:({pluginApi:o,uploaderApi:r})=>{const{registry:c,config:e}=o;U(),c.registerIcon({name:"ai-generate",svg:m.ICON_GENERATE}),c.registerIcon({name:"ai-edit",svg:m.ICON_EDIT_AI}),c.registerConfig({name:"useAiEditor",defaultValue:!0,fromAttribute:t=>t!=="false",toAttribute:t=>t?null:"false",normalize:t=>t!==!1}),c.registerL10n({en:m.enLocale});const i=new Map([["en",m.enLocale]]),f=new Set(["en"]),y=async t=>{const u=t,a=i.get(u);if(a)return a;const n=m.LOCALE_LOADERS[u];if(!n)return null;const l=await n();return i.set(u,l),l},g=async t=>{const u=t||"en";if(f.has(u))return;const a=await y(u);a&&(f.add(u),c.registerL10n({[u]:a}))};g(e.get("localeName")),e.subscribe("localeName",t=>{g(t)}),c.registerSource({id:d,label:"ai-enhancer-source-label",icon:"ai-generate",onSelect:()=>{r.setCurrentActivity(d,{}),r.setModalState(!0)}}),c.registerFileAction({id:d,icon:"ai-edit",label:"ai-enhancer-file-action-label",shouldRender:t=>!!(e.get("useAiEditor")&&t.isImage&&t.uuid&&!t.cdnUrlModifiers),onClick:t=>{r.setCurrentActivity(d,{sourceInternalId:t.internalId}),r.setModalState(!0)}}),c.registerActivity({id:d,render:(t,u)=>{if(!e.get("pubkey"))return console.warn("[ai-enhancer] No `pubkey` configured; the AI editor is disabled."),()=>{};const a=u??{},n=document.createElement("uc-ai-enhancer");if(a.sourceInternalId)try{const s=r.getOutputItem(a.sourceInternalId);n.sourceFileInfo=s.fileInfo??void 0}catch{}R(n);const l=()=>{n.pubkey=e.get("pubkey"),n.baseUrl=e.get("baseUrl"),n.cdnCname=e.get("cdnCname"),n.cdnCnamePrefixed=e.get("cdnCnamePrefixed"),n.secureDeliveryProxyUrlResolver=e.get("secureDeliveryProxyUrlResolver")??void 0};l();const p=()=>{const s=e.get("metadata");if(typeof s!="function"){n.metadata=s;return}const h=a.sourceInternalId;n.metadata=()=>h?s(r.getOutputItem(h)):{}};p();const b=()=>{n.localeName=e.get("localeName")||"en",n.localeDefinitionOverride=e.get("localeDefinitionOverride")??{}};b();const I=v(e.get("cropPreset")??"");I&&(n.aspectRatios=I);const F=[e.subscribe("pubkey",l),e.subscribe("baseUrl",l),e.subscribe("cdnCname",l),e.subscribe("cdnCnamePrefixed",l),e.subscribe("secureDeliveryProxyUrlResolver",l),e.subscribe("metadata",p),e.subscribe("localeName",b),e.subscribe("localeDefinitionOverride",b),e.subscribe("cropPreset",s=>{n.aspectRatios=v(s??"")})],C=s=>{const{file:h}=s.detail;if(a.sourceInternalId)try{r.replaceFile(a.sourceInternalId,h,{source:d})}catch{r.addFileFromUploadcareFile(h,{source:d})}else r.addFileFromUploadcareFile(h,{source:d});r.setCurrentActivity("upload-list"),r.setModalState(!0)},E=()=>{r.setCurrentActivity("upload-list"),r.setModalState(!0)};return n.addEventListener("uc:done",C),n.addEventListener("uc:cancel",E),t.replaceChildren(n),()=>{n.removeEventListener("uc:done",C),n.removeEventListener("uc:cancel",E);for(const s of F)s();t.replaceChildren()}}})}};exports.AiEnhancerPlugin=w;exports.aspectRatiosFromCropPreset=v;
package/dist/plugin.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as L, I as N, e as C, i as O, P as R, L as w } from "./UcAiEnhancer-DK6rhHp7.js";
1
+ import { a as L, I as N, e as C, i as O, P as R, L as w } from "./UcAiEnhancer-BZeCfJ6W.js";
2
2
  const A = "free";
3
3
  function U(o) {
4
4
  return o ? o.split(/[\s,]+/).filter(Boolean) : [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uploadcare/ai-enhancer",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "AI image generation and editing web component for Uploadcare",
5
5
  "type": "module",
6
6
  "files": [