@uploadcare/ai-enhancer 0.1.2 → 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-OUmStG-E.cjs");Object.defineProperty(exports,"UcAiEnhancer",{enumerable:!0,get:()=>e.UcAiEnhancer});exports.enLocale=e.enLocale;
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;
@@ -13,6 +13,35 @@ import { UploadcareFile } from '@uploadcare/upload-client';
13
13
  */
14
14
  export declare type AiEditorMode = 'generate' | 'edit';
15
15
 
16
+ /**
17
+ * The one error type carried by `uc:error`'s `detail.error`. Every value
18
+ * thrown out of a generation/edit run is normalized into this class at the
19
+ * dispatch site; the original thrown value is always preserved on `.cause`.
20
+ * The UI maps `code` to a localized message (`ai-enhancer-error-<code>`).
21
+ */
22
+ export declare class AiEnhancerError extends Error {
23
+ readonly code: AiEnhancerErrorCode;
24
+ readonly source?: string;
25
+ readonly cause?: unknown;
26
+ constructor(message: string, options?: AiEnhancerErrorOptions);
27
+ }
28
+
29
+ /**
30
+ * The known error codes (see {@link KNOWN_ERROR_CODES} in shared/lib), plus an
31
+ * escape hatch: the backend can introduce codes the frontend hasn't heard of,
32
+ * and frontend-originated failures use their own codes (e.g. the React
33
+ * wrapper's `engine_load_failed`).
34
+ */
35
+ export declare type AiEnhancerErrorCode = KnownErrorCode | (string & {});
36
+
37
+ export declare type AiEnhancerErrorOptions = {
38
+ code?: AiEnhancerErrorCode;
39
+ /** Job/platform `error_source`, when the failure reports one. */
40
+ source?: string;
41
+ /** The original thrown value. */
42
+ cause?: unknown;
43
+ };
44
+
16
45
  /**
17
46
  * A locale's strings. Core keys are required; the per-error-code messages are
18
47
  * optional (they fall back to English / the generic message), so translations
@@ -87,6 +116,17 @@ export declare type AspectRatio = readonly [number, number];
87
116
  */
88
117
  export declare type CanvasFit = 'full' | 'available';
89
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
+
90
130
  /** Which edge the composer (prompt + chips + aspect ratio) sits on. */
91
131
  export declare type ComposerPlacement = 'top' | 'bottom';
92
132
 
@@ -130,26 +170,26 @@ export declare type DoneDetail = {
130
170
  };
131
171
 
132
172
  export declare const enLocale: {
133
- 'ai-enhancer-error-invalid_request': string;
134
- 'ai-enhancer-error-invalid_source': string;
135
- 'ai-enhancer-error-source_not_found': string;
136
- 'ai-enhancer-error-source_not_image': string;
137
- 'ai-enhancer-error-source_url_unavailable': string;
138
- 'ai-enhancer-error-invalid_aspect_ratio': string;
139
- 'ai-enhancer-error-canvas_too_large': string;
140
- 'ai-enhancer-error-canvas_dimension_too_small': string;
141
- 'ai-enhancer-error-source_extends_beyond_canvas': string;
142
- 'ai-enhancer-error-derivative_disabled': string;
143
- 'ai-enhancer-error-job_id_required': string;
144
- 'ai-enhancer-error-job_not_found': string;
145
- 'ai-enhancer-error-content_moderated': string;
146
- 'ai-enhancer-error-provider_unavailable': string;
147
- 'ai-enhancer-error-generation_timeout': string;
148
- 'ai-enhancer-error-invalid_input': string;
149
- 'ai-enhancer-error-RequestThrottledError': string;
150
- 'ai-enhancer-error-DownloadFileHTTPClientError': string;
151
- 'ai-enhancer-error-DownloadFileNotFoundError': string;
152
- 'ai-enhancer-error-DownloadFileTaskFailedError': string;
173
+ "ai-enhancer-error-invalid_request": string;
174
+ "ai-enhancer-error-invalid_source": string;
175
+ "ai-enhancer-error-source_not_found": string;
176
+ "ai-enhancer-error-source_not_image": string;
177
+ "ai-enhancer-error-source_url_unavailable": string;
178
+ "ai-enhancer-error-invalid_aspect_ratio": string;
179
+ "ai-enhancer-error-canvas_too_large": string;
180
+ "ai-enhancer-error-canvas_dimension_too_small": string;
181
+ "ai-enhancer-error-source_extends_beyond_canvas": string;
182
+ "ai-enhancer-error-derivative_disabled": string;
183
+ "ai-enhancer-error-job_id_required": string;
184
+ "ai-enhancer-error-job_not_found": string;
185
+ "ai-enhancer-error-content_moderated": string;
186
+ "ai-enhancer-error-provider_unavailable": string;
187
+ "ai-enhancer-error-generation_timeout": string;
188
+ "ai-enhancer-error-invalid_input": string;
189
+ "ai-enhancer-error-RequestThrottledError": string;
190
+ "ai-enhancer-error-DownloadFileHTTPClientError": string;
191
+ "ai-enhancer-error-DownloadFileNotFoundError": string;
192
+ "ai-enhancer-error-DownloadFileTaskFailedError": string;
153
193
  'ai-enhancer-source-label': string;
154
194
  'ai-enhancer-file-action-label': string;
155
195
  'ai-enhancer-generate-title': string;
@@ -176,34 +216,18 @@ export declare const enLocale: {
176
216
  'ai-enhancer-aspect-widescreen': string;
177
217
  };
178
218
 
219
+ /** Detail of the `uc:error` event: the normalized {@link AiEnhancerError}. */
220
+ export declare type ErrorDetail = {
221
+ error: AiEnhancerError;
222
+ };
223
+
179
224
  /**
180
225
  * Friendly messages for known platform/job `error_code`s, keyed
181
226
  * `ai-enhancer-error-<code>`. The editor looks these up by code and falls back
182
227
  * to the generic `ai-enhancer-error`. They're optional per locale (English here
183
228
  * is the default) and overridable via the `l10n` property like any other string.
184
229
  */
185
- declare const errorLocale: {
186
- 'ai-enhancer-error-invalid_request': string;
187
- 'ai-enhancer-error-invalid_source': string;
188
- 'ai-enhancer-error-source_not_found': string;
189
- 'ai-enhancer-error-source_not_image': string;
190
- 'ai-enhancer-error-source_url_unavailable': string;
191
- 'ai-enhancer-error-invalid_aspect_ratio': string;
192
- 'ai-enhancer-error-canvas_too_large': string;
193
- 'ai-enhancer-error-canvas_dimension_too_small': string;
194
- 'ai-enhancer-error-source_extends_beyond_canvas': string;
195
- 'ai-enhancer-error-derivative_disabled': string;
196
- 'ai-enhancer-error-job_id_required': string;
197
- 'ai-enhancer-error-job_not_found': string;
198
- 'ai-enhancer-error-content_moderated': string;
199
- 'ai-enhancer-error-provider_unavailable': string;
200
- 'ai-enhancer-error-generation_timeout': string;
201
- 'ai-enhancer-error-invalid_input': string;
202
- 'ai-enhancer-error-RequestThrottledError': string;
203
- 'ai-enhancer-error-DownloadFileHTTPClientError': string;
204
- 'ai-enhancer-error-DownloadFileNotFoundError': string;
205
- 'ai-enhancer-error-DownloadFileTaskFailedError': string;
206
- };
230
+ declare const errorLocale: Record<`ai-enhancer-error-${KnownErrorCode}`, string>;
207
231
 
208
232
  /**
209
233
  * Where the history strip sits.
@@ -212,6 +236,18 @@ declare const errorLocale: {
212
236
  */
213
237
  export declare type HistoryPlacement = 'composer-above' | 'composer-below' | 'canvas-top' | 'canvas-bottom';
214
238
 
239
+ /**
240
+ * Single source of truth for the known `uc:error` codes — shared between
241
+ * `AiEnhancerErrorCode` (entities/error) and the `ai-enhancer-error-<code>`
242
+ * locale keys (shared/i18n). The list mirrors what the platform/job APIs are
243
+ * known to send; it is not a closed contract — unknown codes still flow
244
+ * through as plain strings. Frontend-originated codes (e.g. the React
245
+ * wrapper's `engine_load_failed`) deliberately stay out of this list.
246
+ */
247
+ declare const KNOWN_ERROR_CODES: readonly ["invalid_request", "invalid_source", "source_not_found", "source_not_image", "source_url_unavailable", "invalid_aspect_ratio", "canvas_too_large", "canvas_dimension_too_small", "source_extends_beyond_canvas", "derivative_disabled", "job_id_required", "job_not_found", "content_moderated", "provider_unavailable", "generation_timeout", "invalid_input", "RequestThrottledError", "DownloadFileHTTPClientError", "DownloadFileNotFoundError", "DownloadFileTaskFailedError"];
248
+
249
+ declare type KnownErrorCode = (typeof KNOWN_ERROR_CODES)[number];
250
+
215
251
  /**
216
252
  * Per-file metadata callback, mirroring the file uploader's `metadata` config
217
253
  * option. Called at generation time with the source image's file info (the
@@ -241,8 +277,12 @@ export declare type SecureDeliveryUrlParts = {
241
277
 
242
278
  /* Excluded from this release type: ShimmerConfig */
243
279
 
244
- /** Where the toolbar (Cancel / Done) sits within the editor. */
245
- 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';
246
286
 
247
287
  /**
248
288
  * `<uc-ai-enhancer>` — the standalone AI image generate/edit editor.
@@ -257,8 +297,13 @@ export declare type ToolbarPlacement = 'bottom' | 'top';
257
297
  * result (the Done button). `detail` carries the result `url`, `uuid`,
258
298
  * `prompt`, `mode`, optional `aspectRatio`, and the `file` object.
259
299
  * @fires uc:cancel - Fired when the user cancels (the Cancel button). No detail.
260
- * @fires uc:error - A `CustomEvent<{ error: unknown }>` fired when a generation
261
- * throws.
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"`).
304
+ * @fires uc:error - A `CustomEvent<ErrorDetail>` fired when a generation
305
+ * throws. `detail.error` is always an `AiEnhancerError` — its `code` maps to
306
+ * a localized message and the original thrown value is on `.cause`.
262
307
  *
263
308
  * @cssprop [--uc-ai-background] - Editor surface background.
264
309
  * @cssprop [--uc-ai-foreground] - Primary text/icon colour.
@@ -356,8 +401,7 @@ export declare class UcAiEnhancer extends LitElement {
356
401
  * How the canvas sizes relative to the composer. `available` (default) shrinks
357
402
  * the canvas to the space left by the composer, which is docked outside the
358
403
  * image (history chips still overlay the canvas). `full` lets the canvas fill
359
- * the whole area with the composer floating over it. Auto-hide always floats,
360
- * so {@link composerAutoHide} implies `full`.
404
+ * the whole area with the composer floating over it.
361
405
  */
362
406
  canvasFit: CanvasFit;
363
407
  /**
@@ -366,14 +410,12 @@ export declare class UcAiEnhancer extends LitElement {
366
410
  * canvas edge.
367
411
  */
368
412
  historyPlacement: HistoryPlacement;
413
+ /* Excluded from this release type: composerAutoHide */
369
414
  /**
370
- * Auto-hide ("dock") the floating composer once an image exists: it drops to a
371
- * small peek at the edge and raises when the pointer approaches its edge or it
372
- * gains focus. Always floats the composer (implies {@link canvasFit} `full`);
373
- * off by default.
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.
374
418
  */
375
- composerAutoHide: boolean;
376
- /** Where the toolbar (Cancel / Done) sits: `bottom` (default) or `top`. */
377
419
  toolbarPlacement: ToolbarPlacement;
378
420
  /* Excluded from this release type: shimmerConfig */
379
421
  private _prompt;
@@ -485,8 +527,12 @@ export declare class UcAiEnhancer extends LitElement {
485
527
  private _onSelectHistoryEntry;
486
528
  private _onSelectAspectRatio;
487
529
  private _onSelectPreset;
530
+ /** Snapshot of the current generation result in the `uc:done` payload shape. */
531
+ private _resultDetail;
488
532
  private _onPrimary;
489
533
  private _onCancel;
534
+ private _lastResult;
535
+ /* Excluded from this release type: updated */
490
536
  /* Excluded from this release type: render */
491
537
  }
492
538
 
@@ -1,5 +1,7 @@
1
- import { U as c, e as n } from "./UcAiEnhancer-qk-y4FHK.js";
1
+ import { U as o, e as a } from "./UcAiEnhancer-BZeCfJ6W.js";
2
+ import { AiEnhancerError as c } from "./errors.js";
2
3
  export {
3
- c as UcAiEnhancer,
4
- n as enLocale
4
+ c as AiEnhancerError,
5
+ o as UcAiEnhancer,
6
+ a as enLocale
5
7
  };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class c extends Error{constructor(e,r={}){super(e),this.name="AiEnhancerError",this.code=r.code??"unknown",this.source=r.source,this.cause=r.cause}}exports.AiEnhancerError=c;
@@ -0,0 +1,81 @@
1
+ /**
2
+ * The one error type carried by `uc:error`'s `detail.error`. Every value
3
+ * thrown out of a generation/edit run is normalized into this class at the
4
+ * dispatch site; the original thrown value is always preserved on `.cause`.
5
+ * The UI maps `code` to a localized message (`ai-enhancer-error-<code>`).
6
+ */
7
+ export declare class AiEnhancerError extends Error {
8
+ readonly code: AiEnhancerErrorCode;
9
+ readonly source?: string;
10
+ readonly cause?: unknown;
11
+ constructor(message: string, options?: AiEnhancerErrorOptions);
12
+ }
13
+
14
+ /**
15
+ * The known error codes (see {@link KNOWN_ERROR_CODES} in shared/lib), plus an
16
+ * escape hatch: the backend can introduce codes the frontend hasn't heard of,
17
+ * and frontend-originated failures use their own codes (e.g. the React
18
+ * wrapper's `engine_load_failed`).
19
+ */
20
+ export declare type AiEnhancerErrorCode = KnownErrorCode | (string & {});
21
+
22
+ export declare type AiEnhancerErrorOptions = {
23
+ code?: AiEnhancerErrorCode;
24
+ /** Job/platform `error_source`, when the failure reports one. */
25
+ source?: string;
26
+ /** The original thrown value. */
27
+ cause?: unknown;
28
+ };
29
+
30
+ /**
31
+ * Single source of truth for the known `uc:error` codes — shared between
32
+ * `AiEnhancerErrorCode` (entities/error) and the `ai-enhancer-error-<code>`
33
+ * locale keys (shared/i18n). The list mirrors what the platform/job APIs are
34
+ * known to send; it is not a closed contract — unknown codes still flow
35
+ * through as plain strings. Frontend-originated codes (e.g. the React
36
+ * wrapper's `engine_load_failed`) deliberately stay out of this list.
37
+ */
38
+ declare const KNOWN_ERROR_CODES: readonly ["invalid_request", "invalid_source", "source_not_found", "source_not_image", "source_url_unavailable", "invalid_aspect_ratio", "canvas_too_large", "canvas_dimension_too_small", "source_extends_beyond_canvas", "derivative_disabled", "job_id_required", "job_not_found", "content_moderated", "provider_unavailable", "generation_timeout", "invalid_input", "RequestThrottledError", "DownloadFileHTTPClientError", "DownloadFileNotFoundError", "DownloadFileTaskFailedError"];
39
+
40
+ declare type KnownErrorCode = (typeof KNOWN_ERROR_CODES)[number];
41
+
42
+ export { }
43
+
44
+
45
+ /**
46
+ * Augment the file-uploader's type system so plugin-specific config is checked
47
+ * instead of cast: the custom activity params for
48
+ * `setCurrentActivity(AI_ENHANCER_ID, params)`, the editor's locale keys so
49
+ * `localeDefinitionOverride` is typed for them, and the plugin's own config
50
+ * options on `<uc-config>`.
51
+ *
52
+ * Importing the plugin brings these augmentations into scope. If your project
53
+ * doesn't pick them up automatically, reference the plugin's types once, e.g.
54
+ * `/// <reference types="@uploadcare/ai-enhancer/plugin" />`.
55
+ */
56
+ declare module '@uploadcare/file-uploader' {
57
+ interface CustomActivities {
58
+ [AI_ENHANCER_ID]: {
59
+ params: AiEditorActivityParams;
60
+ };
61
+ }
62
+ interface CustomLocaleDefinition extends AiEnhancerLocale {
63
+ }
64
+ interface CustomConfig {
65
+ /**
66
+ * Show the **AI Edit** file action on uploaded images (default `true`); set
67
+ * `false` (attribute `use-ai-editor="false"`) to hide it. Mirrors the
68
+ * uploader's `useCloudImageEditor`. Note: the action also hides itself for
69
+ * images that already carry CDN modifiers (e.g. edited with the Cloud Image
70
+ * Editor), regardless of this flag.
71
+ */
72
+ useAiEditor: boolean;
73
+ }
74
+ }
75
+
76
+
77
+ declare module 'vitest/browser' {
78
+ interface BrowserPage {
79
+ render: typeof render;
80
+ }
81
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,8 @@
1
+ class s extends Error {
2
+ constructor(e, r = {}) {
3
+ super(e), this.name = "AiEnhancerError", this.code = r.code ?? "unknown", this.source = r.source, this.cause = r.cause;
4
+ }
5
+ }
6
+ export {
7
+ s as AiEnhancerError
8
+ };
package/dist/plugin.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("./UcAiEnhancer-OUmStG-E.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-qk-y4FHK.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.2",
3
+ "version": "0.1.4",
4
4
  "description": "AI image generation and editing web component for Uploadcare",
5
5
  "type": "module",
6
6
  "files": [
@@ -19,6 +19,11 @@
19
19
  "types": "./dist/plugin.d.ts",
20
20
  "import": "./dist/plugin.js",
21
21
  "require": "./dist/plugin.cjs"
22
+ },
23
+ "./errors": {
24
+ "types": "./dist/errors.d.ts",
25
+ "import": "./dist/errors.js",
26
+ "require": "./dist/errors.cjs"
22
27
  }
23
28
  },
24
29
  "scripts": {