wc-img-ai 0.0.6 → 0.1.0

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,62 +1,3 @@
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).
8
-
9
- ```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
- />
16
- ```
17
-
18
- ## installation
19
-
20
- ```bash
21
- pnpm i wc-img-ai
22
- ```
23
-
24
- ```html
25
- <script type="module">
26
- import "wc-img-ai"
27
- </script>
28
- ```
29
-
30
- The api server itself needs to receive this body and return a string with the url of the image
31
-
32
- ### Function: POST
33
-
34
- This function sends a request to the an API to generate an image based on a given prompt.
35
-
36
- #### Request Body Format
37
-
38
- - **prompt** (string): The description or prompt based on which the image will be generated.
39
- - **width** (number): The width of the desired image in pixels.
40
- - **height** (number): The height of the desired image in pixels.
41
-
42
- #### Example Request Body
43
-
44
- ```json
45
- {
46
- "prompt": "a sleeping little kitten",
47
- "width": 300,
48
- "height": 300
49
- }
50
- ```
51
-
52
- #### Server Return
53
-
54
- it is expected to return a simple string
55
-
56
- ```json
57
- "https://example.com/path/to/generated/image.jpg"
58
- ```
59
-
60
- #### Demo
61
-
62
- Check it out [running](https://john.ro/lab/img-ai) inside an MDX/Astro framework
3
+ WIP
package/dist/wc-img-ai.js CHANGED
@@ -1,7 +1,898 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2019 Google LLC
4
+ * SPDX-License-Identifier: BSD-3-Clause
5
+ */
6
+ var _a;
7
+ const t$3 = globalThis, e$3 = t$3.ShadowRoot && (void 0 === t$3.ShadyCSS || t$3.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$3.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$2 = globalThis, i$1 = t$2.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$2.litHtmlPolyfillSupport;
538
+ Z == null ? void 0 : Z(V, M), (t$2.litHtmlVersions ?? (t$2.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$1 = (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
+ const t = { ATTRIBUTE: 1, CHILD: 2, PROPERTY: 3, BOOLEAN_ATTRIBUTE: 4, EVENT: 5, ELEMENT: 6 }, e = (t2) => (...e2) => ({ _$litDirective$: t2, values: e2 });
630
+ class i {
631
+ constructor(t2) {
632
+ }
633
+ get _$AU() {
634
+ return this._$AM._$AU;
635
+ }
636
+ _$AT(t2, e2, i2) {
637
+ this._$Ct = t2, this._$AM = e2, this._$Ci = i2;
638
+ }
639
+ _$AS(t2, e2) {
640
+ return this.update(t2, e2);
641
+ }
642
+ update(t2, e2) {
643
+ return this.render(...e2);
644
+ }
645
+ }
646
+ /**
647
+ * @license
648
+ * Copyright 2020 Google LLC
649
+ * SPDX-License-Identifier: BSD-3-Clause
650
+ */
651
+ const f$1 = (o2) => void 0 === o2.strings;
652
+ /**
653
+ * @license
654
+ * Copyright 2017 Google LLC
655
+ * SPDX-License-Identifier: BSD-3-Clause
656
+ */
657
+ const s2 = (i2, t2) => {
658
+ var _a2;
659
+ const e2 = i2._$AN;
660
+ if (void 0 === e2)
661
+ return false;
662
+ for (const i3 of e2)
663
+ (_a2 = i3._$AO) == null ? void 0 : _a2.call(i3, t2, false), s2(i3, t2);
664
+ return true;
665
+ }, o = (i2) => {
666
+ let t2, e2;
667
+ do {
668
+ if (void 0 === (t2 = i2._$AM))
669
+ break;
670
+ e2 = t2._$AN, e2.delete(i2), i2 = t2;
671
+ } while (0 === (e2 == null ? void 0 : e2.size));
672
+ }, r = (i2) => {
673
+ for (let t2; t2 = i2._$AM; i2 = t2) {
674
+ let e2 = t2._$AN;
675
+ if (void 0 === e2)
676
+ t2._$AN = e2 = /* @__PURE__ */ new Set();
677
+ else if (e2.has(i2))
678
+ break;
679
+ e2.add(i2), c(t2);
680
+ }
681
+ };
682
+ function h(i2) {
683
+ void 0 !== this._$AN ? (o(this), this._$AM = i2, r(this)) : this._$AM = i2;
684
+ }
685
+ function n2(i2, t2 = false, e2 = 0) {
686
+ const r2 = this._$AH, h2 = this._$AN;
687
+ if (void 0 !== h2 && 0 !== h2.size)
688
+ if (t2)
689
+ if (Array.isArray(r2))
690
+ for (let i3 = e2; i3 < r2.length; i3++)
691
+ s2(r2[i3], false), o(r2[i3]);
692
+ else
693
+ null != r2 && (s2(r2, false), o(r2));
694
+ else
695
+ s2(this, i2);
696
+ }
697
+ const c = (i2) => {
698
+ i2.type == t.CHILD && (i2._$AP ?? (i2._$AP = n2), i2._$AQ ?? (i2._$AQ = h));
699
+ };
700
+ class f extends i {
701
+ constructor() {
702
+ super(...arguments), this._$AN = void 0;
703
+ }
704
+ _$AT(i2, t2, e2) {
705
+ super._$AT(i2, t2, e2), r(this), this.isConnected = i2._$AU;
706
+ }
707
+ _$AO(i2, t2 = true) {
708
+ var _a2, _b;
709
+ 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));
710
+ }
711
+ setValue(t2) {
712
+ if (f$1(this._$Ct))
713
+ this._$Ct._$AI(t2, this);
714
+ else {
715
+ const i2 = [...this._$Ct._$AH];
716
+ i2[this._$Ci] = t2, this._$Ct._$AI(i2, this, 0);
717
+ }
718
+ }
719
+ disconnected() {
720
+ }
721
+ reconnected() {
722
+ }
723
+ }
724
+ class SpreadPropsDirective extends f {
725
+ constructor() {
726
+ super(...arguments);
727
+ this.prevData = {};
728
+ }
729
+ render(_spreadData) {
730
+ return T;
731
+ }
732
+ update(part, [spreadData]) {
733
+ var _a2;
734
+ if (this.element !== part.element) {
735
+ this.element = part.element;
736
+ }
737
+ this.host = ((_a2 = part.options) === null || _a2 === void 0 ? void 0 : _a2.host) || this.element;
738
+ this.apply(spreadData);
739
+ this.groom(spreadData);
740
+ this.prevData = { ...spreadData };
741
+ }
742
+ apply(data) {
743
+ if (!data)
744
+ return;
745
+ const { prevData, element } = this;
746
+ for (const key in data) {
747
+ const value = data[key];
748
+ if (value === prevData[key]) {
749
+ continue;
750
+ }
751
+ element[key] = value;
752
+ }
753
+ }
754
+ groom(data) {
755
+ const { prevData, element } = this;
756
+ if (!prevData)
757
+ return;
758
+ for (const key in prevData) {
759
+ if (!data || !(key in data) && element[key] === prevData[key]) {
760
+ element[key] = void 0;
761
+ }
762
+ }
763
+ }
764
+ }
765
+ class SpreadEventsDirective extends SpreadPropsDirective {
766
+ constructor() {
767
+ super(...arguments);
768
+ this.eventData = {};
769
+ }
770
+ apply(data) {
771
+ if (!data)
772
+ return;
773
+ for (const key in data) {
774
+ const value = data[key];
775
+ if (value === this.eventData[key]) {
776
+ continue;
777
+ }
778
+ this.applyEvent(key, value);
779
+ }
780
+ }
781
+ applyEvent(eventName, eventValue) {
782
+ const { prevData, element } = this;
783
+ this.eventData[eventName] = eventValue;
784
+ const prevHandler = prevData[eventName];
785
+ if (prevHandler) {
786
+ element.removeEventListener(eventName, this, eventValue);
787
+ }
788
+ element.addEventListener(eventName, this, eventValue);
789
+ }
790
+ groom(data) {
791
+ const { prevData, element } = this;
792
+ if (!prevData)
793
+ return;
794
+ for (const key in prevData) {
795
+ if (!data || !(key in data) && element[key] === prevData[key]) {
796
+ this.groomEvent(key, prevData[key]);
797
+ }
798
+ }
799
+ }
800
+ groomEvent(eventName, eventValue) {
801
+ const { element } = this;
802
+ delete this.eventData[eventName];
803
+ element.removeEventListener(eventName, this, eventValue);
804
+ }
805
+ handleEvent(event) {
806
+ const value = this.eventData[event.type];
807
+ if (typeof value === "function") {
808
+ value.call(this.host, event);
809
+ } else {
810
+ value.handleEvent(event);
811
+ }
812
+ }
813
+ disconnected() {
814
+ const { eventData, element } = this;
815
+ for (const key in eventData) {
816
+ const name = key.slice(1);
817
+ const value = eventData[key];
818
+ element.removeEventListener(name, this, value);
819
+ }
820
+ }
821
+ reconnected() {
822
+ const { eventData, element } = this;
823
+ for (const key in eventData) {
824
+ const name = key.slice(1);
825
+ const value = eventData[key];
826
+ element.addEventListener(name, this, value);
827
+ }
828
+ }
829
+ }
830
+ class SpreadDirective extends SpreadEventsDirective {
831
+ apply(data) {
832
+ if (!data)
833
+ return;
834
+ const { prevData, element } = this;
835
+ for (const key in data) {
836
+ const value = data[key];
837
+ if (value === prevData[key]) {
838
+ continue;
839
+ }
840
+ const name = key.slice(1);
841
+ switch (key[0]) {
842
+ case "@":
843
+ this.eventData[name] = value;
844
+ this.applyEvent(name, value);
845
+ break;
846
+ case ".":
847
+ element[name] = value;
848
+ break;
849
+ case "?":
850
+ if (value) {
851
+ element.setAttribute(name, "");
852
+ } else {
853
+ element.removeAttribute(name);
854
+ }
855
+ break;
856
+ default:
857
+ if (value != null) {
858
+ element.setAttribute(key, String(value));
859
+ } else {
860
+ element.removeAttribute(key);
861
+ }
862
+ break;
863
+ }
864
+ }
865
+ }
866
+ groom(data) {
867
+ const { prevData, element } = this;
868
+ if (!prevData)
869
+ return;
870
+ for (const key in prevData) {
871
+ const name = key.slice(1);
872
+ if (!data || !(key in data) && element[name] === prevData[key]) {
873
+ switch (key[0]) {
874
+ case "@":
875
+ this.groomEvent(name, prevData[key]);
876
+ break;
877
+ case ".":
878
+ element[name] = void 0;
879
+ break;
880
+ case "?":
881
+ element.removeAttribute(name);
882
+ break;
883
+ default:
884
+ element.removeAttribute(key);
885
+ break;
886
+ }
887
+ }
888
+ }
889
+ }
890
+ }
891
+ const spread = e(SpreadDirective);
1
892
  const getGeneratedImage = async (endpoint, prompt, width, height) => {
2
893
  let response;
3
894
  try {
4
- const r = await fetch(endpoint, {
895
+ const r2 = await fetch(endpoint, {
5
896
  method: "POST",
6
897
  headers: {
7
898
  "Content-Type": "application/json"
@@ -12,71 +903,151 @@ const getGeneratedImage = async (endpoint, prompt, width, height) => {
12
903
  height
13
904
  })
14
905
  });
15
- if (!r.ok) {
906
+ if (!r2.ok) {
16
907
  throw new Error("Network response was not ok");
17
908
  }
18
- response = await r.text();
909
+ response = await r2.text();
19
910
  } catch (error) {
20
911
  console.error("There has been a problem with your fetch operation:", error);
21
912
  }
22
913
  return response;
23
914
  };
24
- class AIImage extends HTMLImageElement {
915
+ var __defProp = Object.defineProperty;
916
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
917
+ var __decorateClass = (decorators, target, key, kind) => {
918
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
919
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
920
+ if (decorator = decorators[i2])
921
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
922
+ if (kind && result)
923
+ __defProp(target, key, result);
924
+ return result;
925
+ };
926
+ let AiImg = class extends s$1 {
927
+ // Override createRenderRoot to render in the light DOM
928
+ // createRenderRoot() {
929
+ // return this
930
+ // }
25
931
  constructor() {
26
- var _a;
27
932
  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);
933
+ this.fallback = "";
934
+ this.width = "";
935
+ this.height = "";
936
+ this.src = "";
937
+ this.alt = "";
938
+ this.imgsrc = "";
939
+ this.prompt = "";
940
+ this.imgAttributes = {};
46
941
  setTimeout(async () => {
47
- if (!this._prompt) {
942
+ if (!this.prompt) {
943
+ this.imgsrc = this.fallback;
48
944
  return;
49
945
  }
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 || "";
57
- }, 1);
946
+ try {
947
+ const openAiResponse = await getGeneratedImage(
948
+ this.src,
949
+ this.prompt,
950
+ Number(this.width),
951
+ Number(this.height)
952
+ );
953
+ this.imgsrc = openAiResponse || this.fallback;
954
+ } catch (error) {
955
+ console.error("Error fetching AI image:", error);
956
+ this.imgsrc = this.fallback;
957
+ }
958
+ }, 1e3);
58
959
  }
59
- static get observedAttributes() {
60
- return ["data-fallback"];
960
+ connectedCallback() {
961
+ super.connectedCallback();
962
+ Array.from(this.attributes).forEach((attr) => {
963
+ if (![
964
+ "loading",
965
+ "decoding",
966
+ "src",
967
+ "fallback",
968
+ "prompt",
969
+ "style",
970
+ "width",
971
+ "height"
972
+ ].includes(attr.name)) {
973
+ this.imgAttributes[attr.name] = attr.value;
974
+ }
975
+ if (attr.name === "width") {
976
+ this.width = attr.value;
977
+ }
978
+ if (attr.name === "height") {
979
+ this.height = attr.value;
980
+ }
981
+ });
61
982
  }
62
- get src() {
63
- return this._originalSrc || "";
983
+ render() {
984
+ const hostStyles = {
985
+ width: `${this.width}px`,
986
+ height: `${this.height}px`
987
+ };
988
+ return x`
989
+ <style>
990
+ :host {
991
+ width: ${hostStyles.width};
992
+ height: ${hostStyles.height};
993
+ }
994
+ </style>
995
+
996
+ ${this.imgsrc.length > 0 ? x`
997
+ <img
998
+ src=${this.imgsrc}
999
+ decoding="async"
1000
+ loading="lazy"
1001
+ ${spread(this.imgAttributes)}
1002
+ />
1003
+ ` : ""}
1004
+ `;
64
1005
  }
65
- set src(value) {
66
- if (this._originalSrc !== value && this.src !== void 0) {
67
- super.src = value;
1006
+ };
1007
+ AiImg.styles = i$3`
1008
+ :host {
1009
+ display: inline-block;
68
1010
  }
69
- }
70
- set fallbackSrc(value) {
71
- this._fallbackSrc = value;
72
- }
73
- attributeChangedCallback(name, _oldValue, newValue) {
74
- if (name === "data-fallback") {
75
- this.fallbackSrc = newValue;
1011
+
1012
+ img {
1013
+ display: block;
1014
+ -webkit-user-select: none;
1015
+ width: 100%;
1016
+ height: 100%;
1017
+ object-fit: inherit;
1018
+ object-position: inherit;
1019
+ filter: inherit;
1020
+ transform: inherit;
1021
+ transition: inherit;
1022
+ border-radius: inherit;
1023
+ box-shadow: inherit;
1024
+ clip-path: inherit;
76
1025
  }
77
- }
78
- }
79
- customElements.define("ai-image", AIImage, { extends: "img" });
1026
+ `;
1027
+ __decorateClass([
1028
+ n$1({ type: String })
1029
+ ], AiImg.prototype, "fallback", 2);
1030
+ __decorateClass([
1031
+ n$1({ type: String, reflect: true })
1032
+ ], AiImg.prototype, "width", 2);
1033
+ __decorateClass([
1034
+ n$1({ type: String, reflect: true })
1035
+ ], AiImg.prototype, "height", 2);
1036
+ __decorateClass([
1037
+ n$1({ type: String, reflect: true })
1038
+ ], AiImg.prototype, "src", 2);
1039
+ __decorateClass([
1040
+ n$1({ type: String, reflect: true })
1041
+ ], AiImg.prototype, "alt", 2);
1042
+ __decorateClass([
1043
+ n$1({ type: String, reflect: false })
1044
+ ], AiImg.prototype, "imgsrc", 2);
1045
+ __decorateClass([
1046
+ n$1({ type: String, reflect: true })
1047
+ ], AiImg.prototype, "prompt", 2);
1048
+ AiImg = __decorateClass([
1049
+ t$1("ai-img")
1050
+ ], AiImg);
80
1051
  export {
81
- AIImage
1052
+ AiImg
82
1053
  };
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.0",
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,22 @@
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
+ protected render(): import("lit").TemplateResult<1>;
16
+ static styles: import("lit").CSSResult;
17
+ }
18
+ declare global {
19
+ interface HTMLElementTagNameMap {
20
+ "ai-img": AiImg;
21
+ }
22
+ }