wc-img-ai 0.0.6 → 0.1.1

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.
package/README.md CHANGED
@@ -1,18 +1,15 @@
1
1
  # AI based img-tags
2
2
 
3
- By simply providing an src to an api that does the AI for you, and you can simply get ai-rendered images anywhere you need based on the alt-attribute.
4
-
5
- ## Browser Compatibility Note
6
-
7
- As of the current state of browser implementations, there are known limitations in Safari when extending native HTML elements, such as `<img>`, using Web Components. This may affect the functionality of AI-based img-tags in Safari. For more details, see the related [WebKit bug report](https://bugs.webkit.org/show_bug.cgi?id=182671).
3
+ By simply providing a src to an api that does the AI for you, and you can simply get ai-rendered images anywhere you need based on the prompt-attribute.
8
4
 
9
5
  ```html
10
- <img
11
- is="ai-image"
12
- src="/api/myimage"
13
- alt="a sleeping little kitten"
14
- data-fallback="https://placekitten.com/12/12"
15
- />
6
+ <ai-img
7
+ src="http://localhost:4321/api/openai/img"
8
+ width="256"
9
+ height="256"
10
+ prompt="funny dolphin up to no good"
11
+ fallback="https://placekitten.com/200/300"
12
+ ></ai-img>
16
13
  ```
17
14
 
18
15
  ## installation
@@ -31,7 +28,7 @@ The api server itself needs to receive this body and return a string with the ur
31
28
 
32
29
  ### Function: POST
33
30
 
34
- This function sends a request to the an API to generate an image based on a given prompt.
31
+ The web-component sends a POST request to the API to generate an image and expects an image in return.
35
32
 
36
33
  #### Request Body Format
37
34
 
@@ -44,8 +41,8 @@ This function sends a request to the an API to generate an image based on a give
44
41
  ```json
45
42
  {
46
43
  "prompt": "a sleeping little kitten",
47
- "width": 300,
48
- "height": 300
44
+ "width": 256,
45
+ "height": 256
49
46
  }
50
47
  ```
51
48
 
package/dist/wc-img-ai.js CHANGED
@@ -1,7 +1,909 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ var _a;
7
+ const t$4 = globalThis, e$3 = t$4.ShadowRoot && (void 0 === t$4.ShadyCSS || t$4.ShadyCSS.nativeShadow) && "adoptedStyleSheets" in Document.prototype && "replace" in CSSStyleSheet.prototype, s$3 = Symbol(), o$4 = /* @__PURE__ */ new WeakMap();
8
+ let n$4 = class n {
9
+ constructor(t2, e2, o2) {
10
+ if (this._$cssResult$ = true, o2 !== s$3)
11
+ throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");
12
+ this.cssText = t2, this.t = e2;
13
+ }
14
+ get styleSheet() {
15
+ let t2 = this.o;
16
+ const s3 = this.t;
17
+ if (e$3 && void 0 === t2) {
18
+ const e2 = void 0 !== s3 && 1 === s3.length;
19
+ e2 && (t2 = o$4.get(s3)), void 0 === t2 && ((this.o = t2 = new CSSStyleSheet()).replaceSync(this.cssText), e2 && o$4.set(s3, t2));
20
+ }
21
+ return t2;
22
+ }
23
+ toString() {
24
+ return this.cssText;
25
+ }
26
+ };
27
+ const r$5 = (t2) => new n$4("string" == typeof t2 ? t2 : t2 + "", void 0, s$3), i$3 = (t2, ...e2) => {
28
+ const o2 = 1 === t2.length ? t2[0] : e2.reduce((e3, s3, o3) => e3 + ((t3) => {
29
+ if (true === t3._$cssResult$)
30
+ return t3.cssText;
31
+ if ("number" == typeof t3)
32
+ return t3;
33
+ throw Error("Value passed to 'css' function must be a 'css' function result: " + t3 + ". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.");
34
+ })(s3) + t2[o3 + 1], t2[0]);
35
+ return new n$4(o2, t2, s$3);
36
+ }, S$1 = (s3, o2) => {
37
+ if (e$3)
38
+ s3.adoptedStyleSheets = o2.map((t2) => t2 instanceof CSSStyleSheet ? t2 : t2.styleSheet);
39
+ else
40
+ for (const e2 of o2) {
41
+ const o3 = document.createElement("style"), n3 = t$4.litNonce;
42
+ void 0 !== n3 && o3.setAttribute("nonce", n3), o3.textContent = e2.cssText, s3.appendChild(o3);
43
+ }
44
+ }, c$3 = e$3 ? (t2) => t2 : (t2) => t2 instanceof CSSStyleSheet ? ((t3) => {
45
+ let e2 = "";
46
+ for (const s3 of t3.cssRules)
47
+ e2 += s3.cssText;
48
+ return r$5(e2);
49
+ })(t2) : t2;
50
+ /**
51
+ * @license
52
+ * Copyright 2017 Google LLC
53
+ * SPDX-License-Identifier: BSD-3-Clause
54
+ */
55
+ const { is: i$2, defineProperty: e$2, getOwnPropertyDescriptor: r$4, getOwnPropertyNames: h$2, getOwnPropertySymbols: o$3, getPrototypeOf: n$3 } = Object, a$1 = globalThis, c$2 = a$1.trustedTypes, l$1 = c$2 ? c$2.emptyScript : "", p$1 = a$1.reactiveElementPolyfillSupport, d$1 = (t2, s3) => t2, u$1 = { toAttribute(t2, s3) {
56
+ switch (s3) {
57
+ case Boolean:
58
+ t2 = t2 ? l$1 : null;
59
+ break;
60
+ case Object:
61
+ case Array:
62
+ t2 = null == t2 ? t2 : JSON.stringify(t2);
63
+ }
64
+ return t2;
65
+ }, fromAttribute(t2, s3) {
66
+ let i2 = t2;
67
+ switch (s3) {
68
+ case Boolean:
69
+ i2 = null !== t2;
70
+ break;
71
+ case Number:
72
+ i2 = null === t2 ? null : Number(t2);
73
+ break;
74
+ case Object:
75
+ case Array:
76
+ try {
77
+ i2 = JSON.parse(t2);
78
+ } catch (t3) {
79
+ i2 = null;
80
+ }
81
+ }
82
+ return i2;
83
+ } }, f$3 = (t2, s3) => !i$2(t2, s3), y$1 = { attribute: true, type: String, converter: u$1, reflect: false, hasChanged: f$3 };
84
+ Symbol.metadata ?? (Symbol.metadata = Symbol("metadata")), a$1.litPropertyMetadata ?? (a$1.litPropertyMetadata = /* @__PURE__ */ new WeakMap());
85
+ class b extends HTMLElement {
86
+ static addInitializer(t2) {
87
+ this._$Ei(), (this.l ?? (this.l = [])).push(t2);
88
+ }
89
+ static get observedAttributes() {
90
+ return this.finalize(), this._$Eh && [...this._$Eh.keys()];
91
+ }
92
+ static createProperty(t2, s3 = y$1) {
93
+ if (s3.state && (s3.attribute = false), this._$Ei(), this.elementProperties.set(t2, s3), !s3.noAccessor) {
94
+ const i2 = Symbol(), r2 = this.getPropertyDescriptor(t2, i2, s3);
95
+ void 0 !== r2 && e$2(this.prototype, t2, r2);
96
+ }
97
+ }
98
+ static getPropertyDescriptor(t2, s3, i2) {
99
+ const { get: e2, set: h2 } = r$4(this.prototype, t2) ?? { get() {
100
+ return this[s3];
101
+ }, set(t3) {
102
+ this[s3] = t3;
103
+ } };
104
+ return { get() {
105
+ return e2 == null ? void 0 : e2.call(this);
106
+ }, set(s4) {
107
+ const r2 = e2 == null ? void 0 : e2.call(this);
108
+ h2.call(this, s4), this.requestUpdate(t2, r2, i2);
109
+ }, configurable: true, enumerable: true };
110
+ }
111
+ static getPropertyOptions(t2) {
112
+ return this.elementProperties.get(t2) ?? y$1;
113
+ }
114
+ static _$Ei() {
115
+ if (this.hasOwnProperty(d$1("elementProperties")))
116
+ return;
117
+ const t2 = n$3(this);
118
+ t2.finalize(), void 0 !== t2.l && (this.l = [...t2.l]), this.elementProperties = new Map(t2.elementProperties);
119
+ }
120
+ static finalize() {
121
+ if (this.hasOwnProperty(d$1("finalized")))
122
+ return;
123
+ if (this.finalized = true, this._$Ei(), this.hasOwnProperty(d$1("properties"))) {
124
+ const t3 = this.properties, s3 = [...h$2(t3), ...o$3(t3)];
125
+ for (const i2 of s3)
126
+ this.createProperty(i2, t3[i2]);
127
+ }
128
+ const t2 = this[Symbol.metadata];
129
+ if (null !== t2) {
130
+ const s3 = litPropertyMetadata.get(t2);
131
+ if (void 0 !== s3)
132
+ for (const [t3, i2] of s3)
133
+ this.elementProperties.set(t3, i2);
134
+ }
135
+ this._$Eh = /* @__PURE__ */ new Map();
136
+ for (const [t3, s3] of this.elementProperties) {
137
+ const i2 = this._$Eu(t3, s3);
138
+ void 0 !== i2 && this._$Eh.set(i2, t3);
139
+ }
140
+ this.elementStyles = this.finalizeStyles(this.styles);
141
+ }
142
+ static finalizeStyles(s3) {
143
+ const i2 = [];
144
+ if (Array.isArray(s3)) {
145
+ const e2 = new Set(s3.flat(1 / 0).reverse());
146
+ for (const s4 of e2)
147
+ i2.unshift(c$3(s4));
148
+ } else
149
+ void 0 !== s3 && i2.push(c$3(s3));
150
+ return i2;
151
+ }
152
+ static _$Eu(t2, s3) {
153
+ const i2 = s3.attribute;
154
+ return false === i2 ? void 0 : "string" == typeof i2 ? i2 : "string" == typeof t2 ? t2.toLowerCase() : void 0;
155
+ }
156
+ constructor() {
157
+ super(), this._$Ep = void 0, this.isUpdatePending = false, this.hasUpdated = false, this._$Em = null, this._$Ev();
158
+ }
159
+ _$Ev() {
160
+ var _a2;
161
+ this._$Eg = new Promise((t2) => this.enableUpdating = t2), this._$AL = /* @__PURE__ */ new Map(), this._$ES(), this.requestUpdate(), (_a2 = this.constructor.l) == null ? void 0 : _a2.forEach((t2) => t2(this));
162
+ }
163
+ addController(t2) {
164
+ var _a2;
165
+ (this._$E_ ?? (this._$E_ = /* @__PURE__ */ new Set())).add(t2), void 0 !== this.renderRoot && this.isConnected && ((_a2 = t2.hostConnected) == null ? void 0 : _a2.call(t2));
166
+ }
167
+ removeController(t2) {
168
+ var _a2;
169
+ (_a2 = this._$E_) == null ? void 0 : _a2.delete(t2);
170
+ }
171
+ _$ES() {
172
+ const t2 = /* @__PURE__ */ new Map(), s3 = this.constructor.elementProperties;
173
+ for (const i2 of s3.keys())
174
+ this.hasOwnProperty(i2) && (t2.set(i2, this[i2]), delete this[i2]);
175
+ t2.size > 0 && (this._$Ep = t2);
176
+ }
177
+ createRenderRoot() {
178
+ const t2 = this.shadowRoot ?? this.attachShadow(this.constructor.shadowRootOptions);
179
+ return S$1(t2, this.constructor.elementStyles), t2;
180
+ }
181
+ connectedCallback() {
182
+ var _a2;
183
+ this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this.enableUpdating(true), (_a2 = this._$E_) == null ? void 0 : _a2.forEach((t2) => {
184
+ var _a3;
185
+ return (_a3 = t2.hostConnected) == null ? void 0 : _a3.call(t2);
186
+ });
187
+ }
188
+ enableUpdating(t2) {
189
+ }
190
+ disconnectedCallback() {
191
+ var _a2;
192
+ (_a2 = this._$E_) == null ? void 0 : _a2.forEach((t2) => {
193
+ var _a3;
194
+ return (_a3 = t2.hostDisconnected) == null ? void 0 : _a3.call(t2);
195
+ });
196
+ }
197
+ attributeChangedCallback(t2, s3, i2) {
198
+ this._$AK(t2, i2);
199
+ }
200
+ _$EO(t2, s3) {
201
+ var _a2;
202
+ const i2 = this.constructor.elementProperties.get(t2), e2 = this.constructor._$Eu(t2, i2);
203
+ if (void 0 !== e2 && true === i2.reflect) {
204
+ const r2 = (void 0 !== ((_a2 = i2.converter) == null ? void 0 : _a2.toAttribute) ? i2.converter : u$1).toAttribute(s3, i2.type);
205
+ this._$Em = t2, null == r2 ? this.removeAttribute(e2) : this.setAttribute(e2, r2), this._$Em = null;
206
+ }
207
+ }
208
+ _$AK(t2, s3) {
209
+ var _a2;
210
+ const i2 = this.constructor, e2 = i2._$Eh.get(t2);
211
+ if (void 0 !== e2 && this._$Em !== e2) {
212
+ const t3 = i2.getPropertyOptions(e2), r2 = "function" == typeof t3.converter ? { fromAttribute: t3.converter } : void 0 !== ((_a2 = t3.converter) == null ? void 0 : _a2.fromAttribute) ? t3.converter : u$1;
213
+ this._$Em = e2, this[e2] = r2.fromAttribute(s3, t3.type), this._$Em = null;
214
+ }
215
+ }
216
+ requestUpdate(t2, s3, i2, e2 = false, r2) {
217
+ if (void 0 !== t2) {
218
+ if (i2 ?? (i2 = this.constructor.getPropertyOptions(t2)), !(i2.hasChanged ?? f$3)(e2 ? r2 : this[t2], s3))
219
+ return;
220
+ this.C(t2, s3, i2);
221
+ }
222
+ false === this.isUpdatePending && (this._$Eg = this._$EP());
223
+ }
224
+ C(t2, s3, i2) {
225
+ this._$AL.has(t2) || this._$AL.set(t2, s3), true === i2.reflect && this._$Em !== t2 && (this._$Ej ?? (this._$Ej = /* @__PURE__ */ new Set())).add(t2);
226
+ }
227
+ async _$EP() {
228
+ this.isUpdatePending = true;
229
+ try {
230
+ await this._$Eg;
231
+ } catch (t3) {
232
+ Promise.reject(t3);
233
+ }
234
+ const t2 = this.scheduleUpdate();
235
+ return null != t2 && await t2, !this.isUpdatePending;
236
+ }
237
+ scheduleUpdate() {
238
+ return this.performUpdate();
239
+ }
240
+ performUpdate() {
241
+ var _a2;
242
+ if (!this.isUpdatePending)
243
+ return;
244
+ if (!this.hasUpdated) {
245
+ if (this.renderRoot ?? (this.renderRoot = this.createRenderRoot()), this._$Ep) {
246
+ for (const [t4, s4] of this._$Ep)
247
+ this[t4] = s4;
248
+ this._$Ep = void 0;
249
+ }
250
+ const t3 = this.constructor.elementProperties;
251
+ if (t3.size > 0)
252
+ for (const [s4, i2] of t3)
253
+ true !== i2.wrapped || this._$AL.has(s4) || void 0 === this[s4] || this.C(s4, this[s4], i2);
254
+ }
255
+ let t2 = false;
256
+ const s3 = this._$AL;
257
+ try {
258
+ t2 = this.shouldUpdate(s3), t2 ? (this.willUpdate(s3), (_a2 = this._$E_) == null ? void 0 : _a2.forEach((t3) => {
259
+ var _a3;
260
+ return (_a3 = t3.hostUpdate) == null ? void 0 : _a3.call(t3);
261
+ }), this.update(s3)) : this._$ET();
262
+ } catch (s4) {
263
+ throw t2 = false, this._$ET(), s4;
264
+ }
265
+ t2 && this._$AE(s3);
266
+ }
267
+ willUpdate(t2) {
268
+ }
269
+ _$AE(t2) {
270
+ var _a2;
271
+ (_a2 = this._$E_) == null ? void 0 : _a2.forEach((t3) => {
272
+ var _a3;
273
+ return (_a3 = t3.hostUpdated) == null ? void 0 : _a3.call(t3);
274
+ }), this.hasUpdated || (this.hasUpdated = true, this.firstUpdated(t2)), this.updated(t2);
275
+ }
276
+ _$ET() {
277
+ this._$AL = /* @__PURE__ */ new Map(), this.isUpdatePending = false;
278
+ }
279
+ get updateComplete() {
280
+ return this.getUpdateComplete();
281
+ }
282
+ getUpdateComplete() {
283
+ return this._$Eg;
284
+ }
285
+ shouldUpdate(t2) {
286
+ return true;
287
+ }
288
+ update(t2) {
289
+ this._$Ej && (this._$Ej = this._$Ej.forEach((t3) => this._$EO(t3, this[t3]))), this._$ET();
290
+ }
291
+ updated(t2) {
292
+ }
293
+ firstUpdated(t2) {
294
+ }
295
+ }
296
+ b.elementStyles = [], b.shadowRootOptions = { mode: "open" }, b[d$1("elementProperties")] = /* @__PURE__ */ new Map(), b[d$1("finalized")] = /* @__PURE__ */ new Map(), p$1 == null ? void 0 : p$1({ ReactiveElement: b }), (a$1.reactiveElementVersions ?? (a$1.reactiveElementVersions = [])).push("2.0.2");
297
+ /**
298
+ * @license
299
+ * Copyright 2017 Google LLC
300
+ * SPDX-License-Identifier: BSD-3-Clause
301
+ */
302
+ const t$3 = globalThis, i$1 = t$3.trustedTypes, s$2 = i$1 ? i$1.createPolicy("lit-html", { createHTML: (t2) => t2 }) : void 0, e$1 = "$lit$", h$1 = `lit$${(Math.random() + "").slice(9)}$`, o$2 = "?" + h$1, n$2 = `<${o$2}>`, r$3 = document, l = () => r$3.createComment(""), c$1 = (t2) => null === t2 || "object" != typeof t2 && "function" != typeof t2, a = Array.isArray, u = (t2) => a(t2) || "function" == typeof (t2 == null ? void 0 : t2[Symbol.iterator]), d = "[ \n\f\r]", f$2 = /<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g, v = /-->/g, _ = />/g, m = RegExp(`>|${d}(?:([^\\s"'>=/]+)(${d}*=${d}*(?:[^
303
+ \f\r"'\`<>=]|("|')|))|$)`, "g"), p = /'/g, g = /"/g, $ = /^(?:script|style|textarea|title)$/i, y = (t2) => (i2, ...s3) => ({ _$litType$: t2, strings: i2, values: s3 }), x = y(1), w = Symbol.for("lit-noChange"), T = Symbol.for("lit-nothing"), A = /* @__PURE__ */ new WeakMap(), E = r$3.createTreeWalker(r$3, 129);
304
+ function C(t2, i2) {
305
+ if (!Array.isArray(t2) || !t2.hasOwnProperty("raw"))
306
+ throw Error("invalid template strings array");
307
+ return void 0 !== s$2 ? s$2.createHTML(i2) : i2;
308
+ }
309
+ const P = (t2, i2) => {
310
+ const s3 = t2.length - 1, o2 = [];
311
+ let r2, l2 = 2 === i2 ? "<svg>" : "", c2 = f$2;
312
+ for (let i3 = 0; i3 < s3; i3++) {
313
+ const s4 = t2[i3];
314
+ let a2, u2, d2 = -1, y2 = 0;
315
+ for (; y2 < s4.length && (c2.lastIndex = y2, u2 = c2.exec(s4), null !== u2); )
316
+ y2 = c2.lastIndex, c2 === f$2 ? "!--" === u2[1] ? c2 = v : void 0 !== u2[1] ? c2 = _ : void 0 !== u2[2] ? ($.test(u2[2]) && (r2 = RegExp("</" + u2[2], "g")), c2 = m) : void 0 !== u2[3] && (c2 = m) : c2 === m ? ">" === u2[0] ? (c2 = r2 ?? f$2, d2 = -1) : void 0 === u2[1] ? d2 = -2 : (d2 = c2.lastIndex - u2[2].length, a2 = u2[1], c2 = void 0 === u2[3] ? m : '"' === u2[3] ? g : p) : c2 === g || c2 === p ? c2 = m : c2 === v || c2 === _ ? c2 = f$2 : (c2 = m, r2 = void 0);
317
+ const x2 = c2 === m && t2[i3 + 1].startsWith("/>") ? " " : "";
318
+ l2 += c2 === f$2 ? s4 + n$2 : d2 >= 0 ? (o2.push(a2), s4.slice(0, d2) + e$1 + s4.slice(d2) + h$1 + x2) : s4 + h$1 + (-2 === d2 ? i3 : x2);
319
+ }
320
+ return [C(t2, l2 + (t2[s3] || "<?>") + (2 === i2 ? "</svg>" : "")), o2];
321
+ };
322
+ class V {
323
+ constructor({ strings: t2, _$litType$: s3 }, n3) {
324
+ let r2;
325
+ this.parts = [];
326
+ let c2 = 0, a2 = 0;
327
+ const u2 = t2.length - 1, d2 = this.parts, [f2, v2] = P(t2, s3);
328
+ if (this.el = V.createElement(f2, n3), E.currentNode = this.el.content, 2 === s3) {
329
+ const t3 = this.el.content.firstChild;
330
+ t3.replaceWith(...t3.childNodes);
331
+ }
332
+ for (; null !== (r2 = E.nextNode()) && d2.length < u2; ) {
333
+ if (1 === r2.nodeType) {
334
+ if (r2.hasAttributes())
335
+ for (const t3 of r2.getAttributeNames())
336
+ if (t3.endsWith(e$1)) {
337
+ const i2 = v2[a2++], s4 = r2.getAttribute(t3).split(h$1), e2 = /([.?@])?(.*)/.exec(i2);
338
+ d2.push({ type: 1, index: c2, name: e2[2], strings: s4, ctor: "." === e2[1] ? k : "?" === e2[1] ? H : "@" === e2[1] ? I : R }), r2.removeAttribute(t3);
339
+ } else
340
+ t3.startsWith(h$1) && (d2.push({ type: 6, index: c2 }), r2.removeAttribute(t3));
341
+ if ($.test(r2.tagName)) {
342
+ const t3 = r2.textContent.split(h$1), s4 = t3.length - 1;
343
+ if (s4 > 0) {
344
+ r2.textContent = i$1 ? i$1.emptyScript : "";
345
+ for (let i2 = 0; i2 < s4; i2++)
346
+ r2.append(t3[i2], l()), E.nextNode(), d2.push({ type: 2, index: ++c2 });
347
+ r2.append(t3[s4], l());
348
+ }
349
+ }
350
+ } else if (8 === r2.nodeType)
351
+ if (r2.data === o$2)
352
+ d2.push({ type: 2, index: c2 });
353
+ else {
354
+ let t3 = -1;
355
+ for (; -1 !== (t3 = r2.data.indexOf(h$1, t3 + 1)); )
356
+ d2.push({ type: 7, index: c2 }), t3 += h$1.length - 1;
357
+ }
358
+ c2++;
359
+ }
360
+ }
361
+ static createElement(t2, i2) {
362
+ const s3 = r$3.createElement("template");
363
+ return s3.innerHTML = t2, s3;
364
+ }
365
+ }
366
+ function N(t2, i2, s3 = t2, e2) {
367
+ var _a2, _b;
368
+ if (i2 === w)
369
+ return i2;
370
+ let h2 = void 0 !== e2 ? (_a2 = s3._$Co) == null ? void 0 : _a2[e2] : s3._$Cl;
371
+ const o2 = c$1(i2) ? void 0 : i2._$litDirective$;
372
+ return (h2 == null ? void 0 : h2.constructor) !== o2 && ((_b = h2 == null ? void 0 : h2._$AO) == null ? void 0 : _b.call(h2, false), void 0 === o2 ? h2 = void 0 : (h2 = new o2(t2), h2._$AT(t2, s3, e2)), void 0 !== e2 ? (s3._$Co ?? (s3._$Co = []))[e2] = h2 : s3._$Cl = h2), void 0 !== h2 && (i2 = N(t2, h2._$AS(t2, i2.values), h2, e2)), i2;
373
+ }
374
+ class S {
375
+ constructor(t2, i2) {
376
+ this._$AV = [], this._$AN = void 0, this._$AD = t2, this._$AM = i2;
377
+ }
378
+ get parentNode() {
379
+ return this._$AM.parentNode;
380
+ }
381
+ get _$AU() {
382
+ return this._$AM._$AU;
383
+ }
384
+ u(t2) {
385
+ const { el: { content: i2 }, parts: s3 } = this._$AD, e2 = ((t2 == null ? void 0 : t2.creationScope) ?? r$3).importNode(i2, true);
386
+ E.currentNode = e2;
387
+ let h2 = E.nextNode(), o2 = 0, n3 = 0, l2 = s3[0];
388
+ for (; void 0 !== l2; ) {
389
+ if (o2 === l2.index) {
390
+ let i3;
391
+ 2 === l2.type ? i3 = new M(h2, h2.nextSibling, this, t2) : 1 === l2.type ? i3 = new l2.ctor(h2, l2.name, l2.strings, this, t2) : 6 === l2.type && (i3 = new L(h2, this, t2)), this._$AV.push(i3), l2 = s3[++n3];
392
+ }
393
+ o2 !== (l2 == null ? void 0 : l2.index) && (h2 = E.nextNode(), o2++);
394
+ }
395
+ return E.currentNode = r$3, e2;
396
+ }
397
+ p(t2) {
398
+ let i2 = 0;
399
+ for (const s3 of this._$AV)
400
+ void 0 !== s3 && (void 0 !== s3.strings ? (s3._$AI(t2, s3, i2), i2 += s3.strings.length - 2) : s3._$AI(t2[i2])), i2++;
401
+ }
402
+ }
403
+ class M {
404
+ get _$AU() {
405
+ var _a2;
406
+ return ((_a2 = this._$AM) == null ? void 0 : _a2._$AU) ?? this._$Cv;
407
+ }
408
+ constructor(t2, i2, s3, e2) {
409
+ this.type = 2, this._$AH = T, this._$AN = void 0, this._$AA = t2, this._$AB = i2, this._$AM = s3, this.options = e2, this._$Cv = (e2 == null ? void 0 : e2.isConnected) ?? true;
410
+ }
411
+ get parentNode() {
412
+ let t2 = this._$AA.parentNode;
413
+ const i2 = this._$AM;
414
+ return void 0 !== i2 && 11 === (t2 == null ? void 0 : t2.nodeType) && (t2 = i2.parentNode), t2;
415
+ }
416
+ get startNode() {
417
+ return this._$AA;
418
+ }
419
+ get endNode() {
420
+ return this._$AB;
421
+ }
422
+ _$AI(t2, i2 = this) {
423
+ t2 = N(this, t2, i2), c$1(t2) ? t2 === T || null == t2 || "" === t2 ? (this._$AH !== T && this._$AR(), this._$AH = T) : t2 !== this._$AH && t2 !== w && this._(t2) : void 0 !== t2._$litType$ ? this.g(t2) : void 0 !== t2.nodeType ? this.$(t2) : u(t2) ? this.T(t2) : this._(t2);
424
+ }
425
+ k(t2) {
426
+ return this._$AA.parentNode.insertBefore(t2, this._$AB);
427
+ }
428
+ $(t2) {
429
+ this._$AH !== t2 && (this._$AR(), this._$AH = this.k(t2));
430
+ }
431
+ _(t2) {
432
+ this._$AH !== T && c$1(this._$AH) ? this._$AA.nextSibling.data = t2 : this.$(r$3.createTextNode(t2)), this._$AH = t2;
433
+ }
434
+ g(t2) {
435
+ var _a2;
436
+ const { values: i2, _$litType$: s3 } = t2, e2 = "number" == typeof s3 ? this._$AC(t2) : (void 0 === s3.el && (s3.el = V.createElement(C(s3.h, s3.h[0]), this.options)), s3);
437
+ if (((_a2 = this._$AH) == null ? void 0 : _a2._$AD) === e2)
438
+ this._$AH.p(i2);
439
+ else {
440
+ const t3 = new S(e2, this), s4 = t3.u(this.options);
441
+ t3.p(i2), this.$(s4), this._$AH = t3;
442
+ }
443
+ }
444
+ _$AC(t2) {
445
+ let i2 = A.get(t2.strings);
446
+ return void 0 === i2 && A.set(t2.strings, i2 = new V(t2)), i2;
447
+ }
448
+ T(t2) {
449
+ a(this._$AH) || (this._$AH = [], this._$AR());
450
+ const i2 = this._$AH;
451
+ let s3, e2 = 0;
452
+ for (const h2 of t2)
453
+ e2 === i2.length ? i2.push(s3 = new M(this.k(l()), this.k(l()), this, this.options)) : s3 = i2[e2], s3._$AI(h2), e2++;
454
+ e2 < i2.length && (this._$AR(s3 && s3._$AB.nextSibling, e2), i2.length = e2);
455
+ }
456
+ _$AR(t2 = this._$AA.nextSibling, i2) {
457
+ var _a2;
458
+ for ((_a2 = this._$AP) == null ? void 0 : _a2.call(this, false, true, i2); t2 && t2 !== this._$AB; ) {
459
+ const i3 = t2.nextSibling;
460
+ t2.remove(), t2 = i3;
461
+ }
462
+ }
463
+ setConnected(t2) {
464
+ var _a2;
465
+ void 0 === this._$AM && (this._$Cv = t2, (_a2 = this._$AP) == null ? void 0 : _a2.call(this, t2));
466
+ }
467
+ }
468
+ class R {
469
+ get tagName() {
470
+ return this.element.tagName;
471
+ }
472
+ get _$AU() {
473
+ return this._$AM._$AU;
474
+ }
475
+ constructor(t2, i2, s3, e2, h2) {
476
+ this.type = 1, this._$AH = T, this._$AN = void 0, this.element = t2, this.name = i2, this._$AM = e2, this.options = h2, s3.length > 2 || "" !== s3[0] || "" !== s3[1] ? (this._$AH = Array(s3.length - 1).fill(new String()), this.strings = s3) : this._$AH = T;
477
+ }
478
+ _$AI(t2, i2 = this, s3, e2) {
479
+ const h2 = this.strings;
480
+ let o2 = false;
481
+ if (void 0 === h2)
482
+ t2 = N(this, t2, i2, 0), o2 = !c$1(t2) || t2 !== this._$AH && t2 !== w, o2 && (this._$AH = t2);
483
+ else {
484
+ const e3 = t2;
485
+ let n3, r2;
486
+ for (t2 = h2[0], n3 = 0; n3 < h2.length - 1; n3++)
487
+ r2 = N(this, e3[s3 + n3], i2, n3), r2 === w && (r2 = this._$AH[n3]), o2 || (o2 = !c$1(r2) || r2 !== this._$AH[n3]), r2 === T ? t2 = T : t2 !== T && (t2 += (r2 ?? "") + h2[n3 + 1]), this._$AH[n3] = r2;
488
+ }
489
+ o2 && !e2 && this.O(t2);
490
+ }
491
+ O(t2) {
492
+ t2 === T ? this.element.removeAttribute(this.name) : this.element.setAttribute(this.name, t2 ?? "");
493
+ }
494
+ }
495
+ class k extends R {
496
+ constructor() {
497
+ super(...arguments), this.type = 3;
498
+ }
499
+ O(t2) {
500
+ this.element[this.name] = t2 === T ? void 0 : t2;
501
+ }
502
+ }
503
+ class H extends R {
504
+ constructor() {
505
+ super(...arguments), this.type = 4;
506
+ }
507
+ O(t2) {
508
+ this.element.toggleAttribute(this.name, !!t2 && t2 !== T);
509
+ }
510
+ }
511
+ class I extends R {
512
+ constructor(t2, i2, s3, e2, h2) {
513
+ super(t2, i2, s3, e2, h2), this.type = 5;
514
+ }
515
+ _$AI(t2, i2 = this) {
516
+ if ((t2 = N(this, t2, i2, 0) ?? T) === w)
517
+ return;
518
+ const s3 = this._$AH, e2 = t2 === T && s3 !== T || t2.capture !== s3.capture || t2.once !== s3.once || t2.passive !== s3.passive, h2 = t2 !== T && (s3 === T || e2);
519
+ e2 && this.element.removeEventListener(this.name, this, s3), h2 && this.element.addEventListener(this.name, this, t2), this._$AH = t2;
520
+ }
521
+ handleEvent(t2) {
522
+ var _a2;
523
+ "function" == typeof this._$AH ? this._$AH.call(((_a2 = this.options) == null ? void 0 : _a2.host) ?? this.element, t2) : this._$AH.handleEvent(t2);
524
+ }
525
+ }
526
+ class L {
527
+ constructor(t2, i2, s3) {
528
+ this.element = t2, this.type = 6, this._$AN = void 0, this._$AM = i2, this.options = s3;
529
+ }
530
+ get _$AU() {
531
+ return this._$AM._$AU;
532
+ }
533
+ _$AI(t2) {
534
+ N(this, t2);
535
+ }
536
+ }
537
+ const Z = t$3.litHtmlPolyfillSupport;
538
+ Z == null ? void 0 : Z(V, M), (t$3.litHtmlVersions ?? (t$3.litHtmlVersions = [])).push("3.1.0");
539
+ const j = (t2, i2, s3) => {
540
+ const e2 = (s3 == null ? void 0 : s3.renderBefore) ?? i2;
541
+ let h2 = e2._$litPart$;
542
+ if (void 0 === h2) {
543
+ const t3 = (s3 == null ? void 0 : s3.renderBefore) ?? null;
544
+ e2._$litPart$ = h2 = new M(i2.insertBefore(l(), t3), t3, void 0, s3 ?? {});
545
+ }
546
+ return h2._$AI(t2), h2;
547
+ };
548
+ /**
549
+ * @license
550
+ * Copyright 2017 Google LLC
551
+ * SPDX-License-Identifier: BSD-3-Clause
552
+ */
553
+ let s$1 = class s extends b {
554
+ constructor() {
555
+ super(...arguments), this.renderOptions = { host: this }, this._$Do = void 0;
556
+ }
557
+ createRenderRoot() {
558
+ var _a2;
559
+ const t2 = super.createRenderRoot();
560
+ return (_a2 = this.renderOptions).renderBefore ?? (_a2.renderBefore = t2.firstChild), t2;
561
+ }
562
+ update(t2) {
563
+ const i2 = this.render();
564
+ this.hasUpdated || (this.renderOptions.isConnected = this.isConnected), super.update(t2), this._$Do = j(i2, this.renderRoot, this.renderOptions);
565
+ }
566
+ connectedCallback() {
567
+ var _a2;
568
+ super.connectedCallback(), (_a2 = this._$Do) == null ? void 0 : _a2.setConnected(true);
569
+ }
570
+ disconnectedCallback() {
571
+ var _a2;
572
+ super.disconnectedCallback(), (_a2 = this._$Do) == null ? void 0 : _a2.setConnected(false);
573
+ }
574
+ render() {
575
+ return w;
576
+ }
577
+ };
578
+ s$1._$litElement$ = true, s$1["finalized"] = true, (_a = globalThis.litElementHydrateSupport) == null ? void 0 : _a.call(globalThis, { LitElement: s$1 });
579
+ const r$2 = globalThis.litElementPolyfillSupport;
580
+ r$2 == null ? void 0 : r$2({ LitElement: s$1 });
581
+ (globalThis.litElementVersions ?? (globalThis.litElementVersions = [])).push("4.0.2");
582
+ /**
583
+ * @license
584
+ * Copyright 2017 Google LLC
585
+ * SPDX-License-Identifier: BSD-3-Clause
586
+ */
587
+ const t$2 = (t2) => (e2, o2) => {
588
+ void 0 !== o2 ? o2.addInitializer(() => {
589
+ customElements.define(t2, e2);
590
+ }) : customElements.define(t2, e2);
591
+ };
592
+ /**
593
+ * @license
594
+ * Copyright 2017 Google LLC
595
+ * SPDX-License-Identifier: BSD-3-Clause
596
+ */
597
+ const o$1 = { attribute: true, type: String, converter: u$1, reflect: false, hasChanged: f$3 }, r$1 = (t2 = o$1, e2, r2) => {
598
+ const { kind: n3, metadata: i2 } = r2;
599
+ let s3 = globalThis.litPropertyMetadata.get(i2);
600
+ if (void 0 === s3 && globalThis.litPropertyMetadata.set(i2, s3 = /* @__PURE__ */ new Map()), s3.set(r2.name, t2), "accessor" === n3) {
601
+ const { name: o2 } = r2;
602
+ return { set(r3) {
603
+ const n4 = e2.get.call(this);
604
+ e2.set.call(this, r3), this.requestUpdate(o2, n4, t2);
605
+ }, init(e3) {
606
+ return void 0 !== e3 && this.C(o2, void 0, t2), e3;
607
+ } };
608
+ }
609
+ if ("setter" === n3) {
610
+ const { name: o2 } = r2;
611
+ return function(r3) {
612
+ const n4 = this[o2];
613
+ e2.call(this, r3), this.requestUpdate(o2, n4, t2);
614
+ };
615
+ }
616
+ throw Error("Unsupported decorator location: " + n3);
617
+ };
618
+ function n$1(t2) {
619
+ return (e2, o2) => "object" == typeof o2 ? r$1(t2, e2, o2) : ((t3, e3, o3) => {
620
+ const r2 = e3.hasOwnProperty(o3);
621
+ return e3.constructor.createProperty(o3, r2 ? { ...t3, wrapped: true } : t3), r2 ? Object.getOwnPropertyDescriptor(e3, o3) : void 0;
622
+ })(t2, e2, o2);
623
+ }
624
+ /**
625
+ * @license
626
+ * Copyright 2017 Google LLC
627
+ * SPDX-License-Identifier: BSD-3-Clause
628
+ */
629
+ function t$1(t2) {
630
+ return (n3, o2) => {
631
+ const c2 = "function" == typeof n3 ? n3 : n3[o2];
632
+ Object.assign(c2, t2);
633
+ };
634
+ }
635
+ /**
636
+ * @license
637
+ * Copyright 2017 Google LLC
638
+ * SPDX-License-Identifier: BSD-3-Clause
639
+ */
640
+ const t = { ATTRIBUTE: 1, CHILD: 2, PROPERTY: 3, BOOLEAN_ATTRIBUTE: 4, EVENT: 5, ELEMENT: 6 }, e = (t2) => (...e2) => ({ _$litDirective$: t2, values: e2 });
641
+ class i {
642
+ constructor(t2) {
643
+ }
644
+ get _$AU() {
645
+ return this._$AM._$AU;
646
+ }
647
+ _$AT(t2, e2, i2) {
648
+ this._$Ct = t2, this._$AM = e2, this._$Ci = i2;
649
+ }
650
+ _$AS(t2, e2) {
651
+ return this.update(t2, e2);
652
+ }
653
+ update(t2, e2) {
654
+ return this.render(...e2);
655
+ }
656
+ }
657
+ /**
658
+ * @license
659
+ * Copyright 2020 Google LLC
660
+ * SPDX-License-Identifier: BSD-3-Clause
661
+ */
662
+ const f$1 = (o2) => void 0 === o2.strings;
663
+ /**
664
+ * @license
665
+ * Copyright 2017 Google LLC
666
+ * SPDX-License-Identifier: BSD-3-Clause
667
+ */
668
+ const s2 = (i2, t2) => {
669
+ var _a2;
670
+ const e2 = i2._$AN;
671
+ if (void 0 === e2)
672
+ return false;
673
+ for (const i3 of e2)
674
+ (_a2 = i3._$AO) == null ? void 0 : _a2.call(i3, t2, false), s2(i3, t2);
675
+ return true;
676
+ }, o = (i2) => {
677
+ let t2, e2;
678
+ do {
679
+ if (void 0 === (t2 = i2._$AM))
680
+ break;
681
+ e2 = t2._$AN, e2.delete(i2), i2 = t2;
682
+ } while (0 === (e2 == null ? void 0 : e2.size));
683
+ }, r = (i2) => {
684
+ for (let t2; t2 = i2._$AM; i2 = t2) {
685
+ let e2 = t2._$AN;
686
+ if (void 0 === e2)
687
+ t2._$AN = e2 = /* @__PURE__ */ new Set();
688
+ else if (e2.has(i2))
689
+ break;
690
+ e2.add(i2), c(t2);
691
+ }
692
+ };
693
+ function h(i2) {
694
+ void 0 !== this._$AN ? (o(this), this._$AM = i2, r(this)) : this._$AM = i2;
695
+ }
696
+ function n2(i2, t2 = false, e2 = 0) {
697
+ const r2 = this._$AH, h2 = this._$AN;
698
+ if (void 0 !== h2 && 0 !== h2.size)
699
+ if (t2)
700
+ if (Array.isArray(r2))
701
+ for (let i3 = e2; i3 < r2.length; i3++)
702
+ s2(r2[i3], false), o(r2[i3]);
703
+ else
704
+ null != r2 && (s2(r2, false), o(r2));
705
+ else
706
+ s2(this, i2);
707
+ }
708
+ const c = (i2) => {
709
+ i2.type == t.CHILD && (i2._$AP ?? (i2._$AP = n2), i2._$AQ ?? (i2._$AQ = h));
710
+ };
711
+ class f extends i {
712
+ constructor() {
713
+ super(...arguments), this._$AN = void 0;
714
+ }
715
+ _$AT(i2, t2, e2) {
716
+ super._$AT(i2, t2, e2), r(this), this.isConnected = i2._$AU;
717
+ }
718
+ _$AO(i2, t2 = true) {
719
+ var _a2, _b;
720
+ i2 !== this.isConnected && (this.isConnected = i2, i2 ? (_a2 = this.reconnected) == null ? void 0 : _a2.call(this) : (_b = this.disconnected) == null ? void 0 : _b.call(this)), t2 && (s2(this, i2), o(this));
721
+ }
722
+ setValue(t2) {
723
+ if (f$1(this._$Ct))
724
+ this._$Ct._$AI(t2, this);
725
+ else {
726
+ const i2 = [...this._$Ct._$AH];
727
+ i2[this._$Ci] = t2, this._$Ct._$AI(i2, this, 0);
728
+ }
729
+ }
730
+ disconnected() {
731
+ }
732
+ reconnected() {
733
+ }
734
+ }
735
+ class SpreadPropsDirective extends f {
736
+ constructor() {
737
+ super(...arguments);
738
+ this.prevData = {};
739
+ }
740
+ render(_spreadData) {
741
+ return T;
742
+ }
743
+ update(part, [spreadData]) {
744
+ var _a2;
745
+ if (this.element !== part.element) {
746
+ this.element = part.element;
747
+ }
748
+ this.host = ((_a2 = part.options) === null || _a2 === void 0 ? void 0 : _a2.host) || this.element;
749
+ this.apply(spreadData);
750
+ this.groom(spreadData);
751
+ this.prevData = { ...spreadData };
752
+ }
753
+ apply(data) {
754
+ if (!data)
755
+ return;
756
+ const { prevData, element } = this;
757
+ for (const key in data) {
758
+ const value = data[key];
759
+ if (value === prevData[key]) {
760
+ continue;
761
+ }
762
+ element[key] = value;
763
+ }
764
+ }
765
+ groom(data) {
766
+ const { prevData, element } = this;
767
+ if (!prevData)
768
+ return;
769
+ for (const key in prevData) {
770
+ if (!data || !(key in data) && element[key] === prevData[key]) {
771
+ element[key] = void 0;
772
+ }
773
+ }
774
+ }
775
+ }
776
+ class SpreadEventsDirective extends SpreadPropsDirective {
777
+ constructor() {
778
+ super(...arguments);
779
+ this.eventData = {};
780
+ }
781
+ apply(data) {
782
+ if (!data)
783
+ return;
784
+ for (const key in data) {
785
+ const value = data[key];
786
+ if (value === this.eventData[key]) {
787
+ continue;
788
+ }
789
+ this.applyEvent(key, value);
790
+ }
791
+ }
792
+ applyEvent(eventName, eventValue) {
793
+ const { prevData, element } = this;
794
+ this.eventData[eventName] = eventValue;
795
+ const prevHandler = prevData[eventName];
796
+ if (prevHandler) {
797
+ element.removeEventListener(eventName, this, eventValue);
798
+ }
799
+ element.addEventListener(eventName, this, eventValue);
800
+ }
801
+ groom(data) {
802
+ const { prevData, element } = this;
803
+ if (!prevData)
804
+ return;
805
+ for (const key in prevData) {
806
+ if (!data || !(key in data) && element[key] === prevData[key]) {
807
+ this.groomEvent(key, prevData[key]);
808
+ }
809
+ }
810
+ }
811
+ groomEvent(eventName, eventValue) {
812
+ const { element } = this;
813
+ delete this.eventData[eventName];
814
+ element.removeEventListener(eventName, this, eventValue);
815
+ }
816
+ handleEvent(event) {
817
+ const value = this.eventData[event.type];
818
+ if (typeof value === "function") {
819
+ value.call(this.host, event);
820
+ } else {
821
+ value.handleEvent(event);
822
+ }
823
+ }
824
+ disconnected() {
825
+ const { eventData, element } = this;
826
+ for (const key in eventData) {
827
+ const name = key.slice(1);
828
+ const value = eventData[key];
829
+ element.removeEventListener(name, this, value);
830
+ }
831
+ }
832
+ reconnected() {
833
+ const { eventData, element } = this;
834
+ for (const key in eventData) {
835
+ const name = key.slice(1);
836
+ const value = eventData[key];
837
+ element.addEventListener(name, this, value);
838
+ }
839
+ }
840
+ }
841
+ class SpreadDirective extends SpreadEventsDirective {
842
+ apply(data) {
843
+ if (!data)
844
+ return;
845
+ const { prevData, element } = this;
846
+ for (const key in data) {
847
+ const value = data[key];
848
+ if (value === prevData[key]) {
849
+ continue;
850
+ }
851
+ const name = key.slice(1);
852
+ switch (key[0]) {
853
+ case "@":
854
+ this.eventData[name] = value;
855
+ this.applyEvent(name, value);
856
+ break;
857
+ case ".":
858
+ element[name] = value;
859
+ break;
860
+ case "?":
861
+ if (value) {
862
+ element.setAttribute(name, "");
863
+ } else {
864
+ element.removeAttribute(name);
865
+ }
866
+ break;
867
+ default:
868
+ if (value != null) {
869
+ element.setAttribute(key, String(value));
870
+ } else {
871
+ element.removeAttribute(key);
872
+ }
873
+ break;
874
+ }
875
+ }
876
+ }
877
+ groom(data) {
878
+ const { prevData, element } = this;
879
+ if (!prevData)
880
+ return;
881
+ for (const key in prevData) {
882
+ const name = key.slice(1);
883
+ if (!data || !(key in data) && element[name] === prevData[key]) {
884
+ switch (key[0]) {
885
+ case "@":
886
+ this.groomEvent(name, prevData[key]);
887
+ break;
888
+ case ".":
889
+ element[name] = void 0;
890
+ break;
891
+ case "?":
892
+ element.removeAttribute(name);
893
+ break;
894
+ default:
895
+ element.removeAttribute(key);
896
+ break;
897
+ }
898
+ }
899
+ }
900
+ }
901
+ }
902
+ const spread = e(SpreadDirective);
1
903
  const getGeneratedImage = async (endpoint, prompt, width, height) => {
2
904
  let response;
3
905
  try {
4
- const r = await fetch(endpoint, {
906
+ const r2 = await fetch(endpoint, {
5
907
  method: "POST",
6
908
  headers: {
7
909
  "Content-Type": "application/json"
@@ -12,71 +914,175 @@ const getGeneratedImage = async (endpoint, prompt, width, height) => {
12
914
  height
13
915
  })
14
916
  });
15
- if (!r.ok) {
917
+ if (!r2.ok) {
16
918
  throw new Error("Network response was not ok");
17
919
  }
18
- response = await r.text();
920
+ response = await r2.text();
19
921
  } catch (error) {
20
922
  console.error("There has been a problem with your fetch operation:", error);
21
923
  }
22
924
  return response;
23
925
  };
24
- class AIImage extends HTMLImageElement {
926
+ var __defProp = Object.defineProperty;
927
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
928
+ var __decorateClass = (decorators, target, key, kind) => {
929
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
930
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
931
+ if (decorator = decorators[i2])
932
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
933
+ if (kind && result)
934
+ __defProp(target, key, result);
935
+ return result;
936
+ };
937
+ let AiImg = class extends s$1 {
938
+ // Override createRenderRoot to render in the light DOM
939
+ // createRenderRoot() {
940
+ // return this
941
+ // }
25
942
  constructor() {
26
- var _a;
27
943
  super();
28
- this._fallbackSrc = null;
29
- this._prompt = null;
30
- this._originalSrc = null;
31
- this.svgPlaceholder = null;
32
- this._endpoint = null;
33
- this.ph_w = 256;
34
- this.ph_h = 256;
35
- this.getGeneratedImage = getGeneratedImage;
36
- this.ph_w = Number(super.getAttribute("width")) || 256;
37
- this.ph_h = Number(super.getAttribute("height")) || 256;
38
- this.svgPlaceholder = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.ph_w} ${this.ph_h}"><rect width="${this.ph_w}" height="${this.ph_h}" fill="#ddd"/></svg>`;
39
- this._originalSrc = this.getAttribute("currentSrc");
40
- this._prompt = this.getAttribute("alt");
41
- this._endpoint = ((_a = super.getAttribute("src")) == null ? void 0 : _a.toString()) || null;
42
- this.addEventListener("error", (_event) => {
43
- super.src = "data:image/svg+xml;utf8," + encodeURIComponent(this.svgPlaceholder);
44
- });
45
- super.src = "data:image/svg+xml;utf8," + encodeURIComponent(this.svgPlaceholder);
944
+ this.fallback = "";
945
+ this.width = "";
946
+ this.height = "";
947
+ this.src = "";
948
+ this.alt = "";
949
+ this.imgsrc = "";
950
+ this.prompt = "";
951
+ this.imgAttributes = {};
46
952
  setTimeout(async () => {
47
- if (!this._prompt) {
953
+ var _a2;
954
+ if (!this.prompt) {
955
+ this.imgsrc = this.fallback;
48
956
  return;
49
957
  }
50
- const openAiResponse = await this.getGeneratedImage(
51
- this._endpoint,
52
- this._prompt,
53
- this.ph_w,
54
- this.ph_h
55
- );
56
- super.src = openAiResponse || this._fallbackSrc || "";
958
+ try {
959
+ const openAiResponse = await getGeneratedImage(
960
+ this.src,
961
+ this.prompt,
962
+ Number(this.width),
963
+ Number(this.height)
964
+ );
965
+ this.imgsrc = openAiResponse || this.fallback;
966
+ } catch (error) {
967
+ console.error("Error fetching AI image:", error);
968
+ this.imgsrc = this.fallback;
969
+ }
970
+ const img = (_a2 = this.shadowRoot) == null ? void 0 : _a2.querySelector("img");
971
+ img == null ? void 0 : img.addEventListener("error", this._onImgError.bind(this));
57
972
  }, 1);
58
973
  }
59
- static get observedAttributes() {
60
- return ["data-fallback"];
61
- }
62
- get src() {
63
- return this._originalSrc || "";
974
+ connectedCallback() {
975
+ super.connectedCallback();
976
+ Array.from(this.attributes).forEach((attr) => {
977
+ if (![
978
+ "loading",
979
+ "decoding",
980
+ "src",
981
+ "fallback",
982
+ "prompt",
983
+ "style",
984
+ "width",
985
+ "height"
986
+ ].includes(attr.name)) {
987
+ this.imgAttributes[attr.name] = attr.value;
988
+ }
989
+ if (attr.name === "width") {
990
+ this.width = attr.value;
991
+ }
992
+ if (attr.name === "height") {
993
+ this.height = attr.value;
994
+ }
995
+ });
996
+ this.imgsrc = "data:image/svg+xml;utf8," + encodeURIComponent(
997
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${this.width} ${this.height}"><rect width="${this.width}" height="${this.height}" fill="#ddd"/></svg>`
998
+ );
64
999
  }
65
- set src(value) {
66
- if (this._originalSrc !== value && this.src !== void 0) {
67
- super.src = value;
68
- }
1000
+ _onImgError() {
1001
+ this.imgsrc = this.fallback;
69
1002
  }
70
- set fallbackSrc(value) {
71
- this._fallbackSrc = value;
1003
+ render() {
1004
+ const hostStyles = {
1005
+ width: `${this.width}px`,
1006
+ height: `${this.height}px`
1007
+ };
1008
+ return x`
1009
+ <style>
1010
+ :host {
1011
+ width: ${hostStyles.width};
1012
+ height: ${hostStyles.height};
1013
+ }
1014
+ </style>
1015
+
1016
+ ${this.imgsrc.length > 0 ? x`
1017
+ <img
1018
+ src=${this.imgsrc}
1019
+ decoding="async"
1020
+ loading="eager"
1021
+ ${spread(this.imgAttributes)}
1022
+ @onerror=${() => {
1023
+ console.log("onerror");
1024
+ }}
1025
+ @onabort=${() => {
1026
+ console.log("onabort");
1027
+ }}
1028
+ @onloadend=${() => {
1029
+ console.log("onloadend");
1030
+ }}
1031
+ @onprogress=${() => {
1032
+ console.log("onprogress");
1033
+ }}
1034
+ />
1035
+ ` : x`<div>fail</div>`}
1036
+ `;
72
1037
  }
73
- attributeChangedCallback(name, _oldValue, newValue) {
74
- if (name === "data-fallback") {
75
- this.fallbackSrc = newValue;
1038
+ };
1039
+ AiImg.styles = i$3`
1040
+ :host {
1041
+ display: inline-block;
76
1042
  }
77
- }
78
- }
79
- customElements.define("ai-image", AIImage, { extends: "img" });
1043
+
1044
+ img {
1045
+ display: block;
1046
+ -webkit-user-select: none;
1047
+ width: 100%;
1048
+ height: 100%;
1049
+ object-fit: inherit;
1050
+ object-position: inherit;
1051
+ filter: inherit;
1052
+ transform: inherit;
1053
+ transition: inherit;
1054
+ border-radius: inherit;
1055
+ box-shadow: inherit;
1056
+ clip-path: inherit;
1057
+ }
1058
+ `;
1059
+ __decorateClass([
1060
+ n$1({ type: String })
1061
+ ], AiImg.prototype, "fallback", 2);
1062
+ __decorateClass([
1063
+ n$1({ type: String, reflect: true })
1064
+ ], AiImg.prototype, "width", 2);
1065
+ __decorateClass([
1066
+ n$1({ type: String, reflect: true })
1067
+ ], AiImg.prototype, "height", 2);
1068
+ __decorateClass([
1069
+ n$1({ type: String, reflect: true })
1070
+ ], AiImg.prototype, "src", 2);
1071
+ __decorateClass([
1072
+ n$1({ type: String, reflect: true })
1073
+ ], AiImg.prototype, "alt", 2);
1074
+ __decorateClass([
1075
+ n$1({ type: String, reflect: false })
1076
+ ], AiImg.prototype, "imgsrc", 2);
1077
+ __decorateClass([
1078
+ n$1({ type: String, reflect: true })
1079
+ ], AiImg.prototype, "prompt", 2);
1080
+ __decorateClass([
1081
+ t$1({ passive: true })
1082
+ ], AiImg.prototype, "_onImgError", 1);
1083
+ AiImg = __decorateClass([
1084
+ t$2("ai-img")
1085
+ ], AiImg);
80
1086
  export {
81
- AIImage
1087
+ AiImg
82
1088
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wc-img-ai",
3
3
  "private": false,
4
- "version": "0.0.6",
4
+ "version": "0.1.1",
5
5
  "description": "Use AI to generate images for your img tags.",
6
6
  "author": {
7
7
  "name": "John Romani",
@@ -34,6 +34,14 @@
34
34
  "typescript": "^5.2.2",
35
35
  "vite": "^5.0.8"
36
36
  },
37
+ "dependencies": {
38
+ "@lit-labs/observers": "^2.0.2",
39
+ "@open-wc/lit-helpers": "^0.6.0",
40
+ "lit": "^3.1.0"
41
+ },
42
+ "peerDependencies": {
43
+ "lit": "^3.0.0"
44
+ },
37
45
  "scripts": {
38
46
  "dev": "vite",
39
47
  "build": "tsc && vite build",
@@ -0,0 +1,23 @@
1
+ import { LitElement } from "lit";
2
+ export declare class AiImg extends LitElement {
3
+ fallback: string;
4
+ width: string;
5
+ height: string;
6
+ src: string;
7
+ alt: string;
8
+ imgsrc: string;
9
+ prompt: string;
10
+ imgAttributes: {
11
+ [key: string]: string;
12
+ };
13
+ connectedCallback(): void;
14
+ protected constructor();
15
+ private _onImgError;
16
+ protected render(): import("lit").TemplateResult<1>;
17
+ static styles: import("lit").CSSResult;
18
+ }
19
+ declare global {
20
+ interface HTMLElementTagNameMap {
21
+ "ai-img": AiImg;
22
+ }
23
+ }