wc-img-ai 0.2.0 → 0.2.2
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/dist/wc-img-ai.js +54 -69
- package/package.json +1 -1
- package/types/ai-img.d.ts +2 -2
- package/types/get-generated-image.d.ts +1 -0
package/dist/wc-img-ai.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
6
|
var _a;
|
|
7
|
-
const t$
|
|
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
8
|
let n$4 = class n {
|
|
9
9
|
constructor(t2, e2, o2) {
|
|
10
10
|
if (this._$cssResult$ = true, o2 !== s$3)
|
|
@@ -38,7 +38,7 @@ const r$5 = (t2) => new n$4("string" == typeof t2 ? t2 : t2 + "", void 0, s$3),
|
|
|
38
38
|
s3.adoptedStyleSheets = o2.map((t2) => t2 instanceof CSSStyleSheet ? t2 : t2.styleSheet);
|
|
39
39
|
else
|
|
40
40
|
for (const e2 of o2) {
|
|
41
|
-
const o3 = document.createElement("style"), n3 = t$
|
|
41
|
+
const o3 = document.createElement("style"), n3 = t$3.litNonce;
|
|
42
42
|
void 0 !== n3 && o3.setAttribute("nonce", n3), o3.textContent = e2.cssText, s3.appendChild(o3);
|
|
43
43
|
}
|
|
44
44
|
}, c$3 = e$3 ? (t2) => t2 : (t2) => t2 instanceof CSSStyleSheet ? ((t3) => {
|
|
@@ -299,7 +299,7 @@ b.elementStyles = [], b.shadowRootOptions = { mode: "open" }, b[d$1("elementProp
|
|
|
299
299
|
* Copyright 2017 Google LLC
|
|
300
300
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
301
301
|
*/
|
|
302
|
-
const t$
|
|
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
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
304
|
function C(t2, i2) {
|
|
305
305
|
if (!Array.isArray(t2) || !t2.hasOwnProperty("raw"))
|
|
@@ -534,8 +534,8 @@ class L {
|
|
|
534
534
|
N(this, t2);
|
|
535
535
|
}
|
|
536
536
|
}
|
|
537
|
-
const Z = t$
|
|
538
|
-
Z == null ? void 0 : Z(V, M), (t$
|
|
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
539
|
const j = (t2, i2, s3) => {
|
|
540
540
|
const e2 = (s3 == null ? void 0 : s3.renderBefore) ?? i2;
|
|
541
541
|
let h2 = e2._$litPart$;
|
|
@@ -584,7 +584,7 @@ r$2 == null ? void 0 : r$2({ LitElement: s$1 });
|
|
|
584
584
|
* Copyright 2017 Google LLC
|
|
585
585
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
586
586
|
*/
|
|
587
|
-
const t$
|
|
587
|
+
const t$1 = (t2) => (e2, o2) => {
|
|
588
588
|
void 0 !== o2 ? o2.addInitializer(() => {
|
|
589
589
|
customElements.define(t2, e2);
|
|
590
590
|
}) : customElements.define(t2, e2);
|
|
@@ -621,17 +621,6 @@ function n$1(t2) {
|
|
|
621
621
|
return e3.constructor.createProperty(o3, r2 ? { ...t3, wrapped: true } : t3), r2 ? Object.getOwnPropertyDescriptor(e3, o3) : void 0;
|
|
622
622
|
})(t2, e2, o2);
|
|
623
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
624
|
/**
|
|
636
625
|
* @license
|
|
637
626
|
* Copyright 2017 Google LLC
|
|
@@ -900,6 +889,7 @@ class SpreadDirective extends SpreadEventsDirective {
|
|
|
900
889
|
}
|
|
901
890
|
}
|
|
902
891
|
const spread = e(SpreadDirective);
|
|
892
|
+
const spinner = `<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.a{animation:b .8s linear infinite;fill:#888}.c{animation-delay:-.65s}.d{animation-delay:-.5s}@keyframes b{93.75%,100%{r:3px}46.875%{r:.2px}}</style><circle class="a" cx="4" cy="12" r="3"/><circle class="a c" cx="12" cy="12" r="3"/><circle class="a d" cx="20" cy="12" r="3"/></svg>`;
|
|
903
893
|
const getGeneratedImage = async (endpoint, prompt, width, height) => {
|
|
904
894
|
let response;
|
|
905
895
|
try {
|
|
@@ -935,12 +925,8 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
935
925
|
return result;
|
|
936
926
|
};
|
|
937
927
|
let AiImg = class extends s$1 {
|
|
938
|
-
// Override createRenderRoot to render in the light DOM
|
|
939
|
-
// createRenderRoot() {
|
|
940
|
-
// return this
|
|
941
|
-
// }
|
|
942
928
|
constructor() {
|
|
943
|
-
super();
|
|
929
|
+
super(...arguments);
|
|
944
930
|
this.fallback = "";
|
|
945
931
|
this.width = "";
|
|
946
932
|
this.height = "";
|
|
@@ -949,30 +935,33 @@ let AiImg = class extends s$1 {
|
|
|
949
935
|
this.imgsrc = "";
|
|
950
936
|
this.prompt = "";
|
|
951
937
|
this.imgAttributes = {};
|
|
952
|
-
setTimeout(async () => {
|
|
953
|
-
var _a2;
|
|
954
|
-
if (!this.prompt) {
|
|
955
|
-
this.imgsrc = this.fallback;
|
|
956
|
-
return;
|
|
957
|
-
}
|
|
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));
|
|
972
|
-
}, 1);
|
|
973
938
|
}
|
|
974
939
|
connectedCallback() {
|
|
975
940
|
super.connectedCallback();
|
|
941
|
+
this.initAttributes();
|
|
942
|
+
this.fetchImage();
|
|
943
|
+
}
|
|
944
|
+
async fetchImage() {
|
|
945
|
+
if (!this.prompt) {
|
|
946
|
+
this.imgsrc = this.fallback;
|
|
947
|
+
return;
|
|
948
|
+
}
|
|
949
|
+
try {
|
|
950
|
+
const openAiResponse = await getGeneratedImage(
|
|
951
|
+
this.src,
|
|
952
|
+
this.prompt,
|
|
953
|
+
Number(this.width),
|
|
954
|
+
Number(this.height)
|
|
955
|
+
);
|
|
956
|
+
this.imgsrc = openAiResponse || this.fallback;
|
|
957
|
+
this.classList.remove("spin");
|
|
958
|
+
} catch (error) {
|
|
959
|
+
console.error("Error fetching AI image:", error);
|
|
960
|
+
this.imgsrc = this.fallback;
|
|
961
|
+
this.classList.remove("spin");
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
initAttributes() {
|
|
976
965
|
Array.from(this.attributes).forEach((attr) => {
|
|
977
966
|
if (![
|
|
978
967
|
"loading",
|
|
@@ -996,20 +985,31 @@ let AiImg = class extends s$1 {
|
|
|
996
985
|
this.imgsrc = "data:image/svg+xml;utf8," + encodeURIComponent(
|
|
997
986
|
`<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
987
|
);
|
|
999
|
-
|
|
1000
|
-
_onImgError() {
|
|
1001
|
-
this.imgsrc = this.fallback;
|
|
988
|
+
this.classList.add("spin");
|
|
1002
989
|
}
|
|
1003
990
|
render() {
|
|
1004
|
-
const hostStyles = {
|
|
1005
|
-
width: `${this.width}px`,
|
|
1006
|
-
height: `${this.height}px`
|
|
1007
|
-
};
|
|
1008
991
|
return x`
|
|
1009
992
|
<style>
|
|
1010
|
-
:host {
|
|
1011
|
-
|
|
1012
|
-
|
|
993
|
+
:host(.spin) {
|
|
994
|
+
position: relative;
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
:host(.spin):before {
|
|
998
|
+
content: "";
|
|
999
|
+
position: absolute;
|
|
1000
|
+
margin: auto 0;
|
|
1001
|
+
width: 100%;
|
|
1002
|
+
height: 100%;
|
|
1003
|
+
display: inline-flex;
|
|
1004
|
+
justify-content: center;
|
|
1005
|
+
align-items: center;
|
|
1006
|
+
color: red;
|
|
1007
|
+
background-image: url("data:image/svg+xml;utf8,${encodeURIComponent(
|
|
1008
|
+
spinner
|
|
1009
|
+
)}");
|
|
1010
|
+
background-repeat: no-repeat;
|
|
1011
|
+
background-position: center;
|
|
1012
|
+
background-size: 25%;
|
|
1013
1013
|
}
|
|
1014
1014
|
</style>
|
|
1015
1015
|
|
|
@@ -1019,18 +1019,6 @@ let AiImg = class extends s$1 {
|
|
|
1019
1019
|
decoding="async"
|
|
1020
1020
|
loading="eager"
|
|
1021
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
1022
|
/>
|
|
1035
1023
|
` : x`<div>fail</div>`}
|
|
1036
1024
|
`;
|
|
@@ -1077,11 +1065,8 @@ __decorateClass([
|
|
|
1077
1065
|
__decorateClass([
|
|
1078
1066
|
n$1({ type: String, reflect: true })
|
|
1079
1067
|
], AiImg.prototype, "prompt", 2);
|
|
1080
|
-
__decorateClass([
|
|
1081
|
-
t$1({ passive: true })
|
|
1082
|
-
], AiImg.prototype, "_onImgError", 1);
|
|
1083
1068
|
AiImg = __decorateClass([
|
|
1084
|
-
t$
|
|
1069
|
+
t$1("ai-img")
|
|
1085
1070
|
], AiImg);
|
|
1086
1071
|
export {
|
|
1087
1072
|
AiImg
|
package/package.json
CHANGED
package/types/ai-img.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class AiImg extends LitElement {
|
|
|
11
11
|
[key: string]: string;
|
|
12
12
|
};
|
|
13
13
|
connectedCallback(): void;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
fetchImage(): Promise<void>;
|
|
15
|
+
initAttributes(): void;
|
|
16
16
|
protected render(): import("lit").TemplateResult<1>;
|
|
17
17
|
static styles: import("lit").CSSResult;
|
|
18
18
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
+
export declare const spinner = "<svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><style>.a{animation:b .8s linear infinite;fill:#888}.c{animation-delay:-.65s}.d{animation-delay:-.5s}@keyframes b{93.75%,100%{r:3px}46.875%{r:.2px}}</style><circle class=\"a\" cx=\"4\" cy=\"12\" r=\"3\"/><circle class=\"a c\" cx=\"12\" cy=\"12\" r=\"3\"/><circle class=\"a d\" cx=\"20\" cy=\"12\" r=\"3\"/></svg>";
|
|
1
2
|
export declare const getGeneratedImage: (endpoint: string, prompt: string, width: number, height: number) => Promise<string | undefined>;
|