@primestyleai/tryon 5.10.194 → 5.10.196
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/PrimeStyleTryon.d.ts +6 -0
- package/dist/api-client.d.ts +42 -1
- package/dist/clarity.d.ts +13 -0
- package/dist/{index-BiotPzcm.js → index-8lZs7T93.js} +292 -156
- package/dist/index-8lZs7T93.js.map +1 -0
- package/dist/primestyle-tryon.js +173 -94
- package/dist/primestyle-tryon.js.map +1 -1
- package/dist/react/PrimeStyleTryonInner.d.ts +1 -1
- package/dist/react/index.js +5902 -5518
- package/dist/react/index.js.map +1 -1
- package/dist/react/styles.d.ts +1 -1
- package/dist/react/types.d.ts +2 -0
- package/dist/replay.d.ts +9 -0
- package/dist/storefront/primestyle-tryon.js +737 -117
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/index-BiotPzcm.js.map +0 -1
package/dist/primestyle-tryon.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { c as l, A as c,
|
|
3
|
-
import { P as
|
|
4
|
-
function
|
|
2
|
+
import { c as l, A as c, s as h, t as u, i as m, a as g, S as y } from "./index-8lZs7T93.js";
|
|
3
|
+
import { P as C, b as S, T as k, d as E, e as U, r as I } from "./index-8lZs7T93.js";
|
|
4
|
+
function p() {
|
|
5
5
|
const i = document.querySelector(
|
|
6
6
|
'meta[property="og:image"]'
|
|
7
7
|
);
|
|
@@ -9,9 +9,9 @@ function d() {
|
|
|
9
9
|
const t = document.querySelectorAll(
|
|
10
10
|
'script[type="application/ld+json"]'
|
|
11
11
|
);
|
|
12
|
-
for (const
|
|
12
|
+
for (const r of t)
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
14
|
+
const s = JSON.parse(r.textContent || ""), o = d(s);
|
|
15
15
|
if (o) return o;
|
|
16
16
|
} catch {
|
|
17
17
|
}
|
|
@@ -26,21 +26,21 @@ function d() {
|
|
|
26
26
|
".woocommerce-product-gallery img",
|
|
27
27
|
".product-media img"
|
|
28
28
|
];
|
|
29
|
-
for (const
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
const o =
|
|
29
|
+
for (const r of e) {
|
|
30
|
+
const s = document.querySelector(r);
|
|
31
|
+
if (s) {
|
|
32
|
+
const o = s.src || s.dataset.src || s.dataset.zoom;
|
|
33
33
|
if (o) return o;
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function d(i) {
|
|
39
39
|
if (!i || typeof i != "object") return null;
|
|
40
40
|
if (Array.isArray(i)) {
|
|
41
41
|
for (const e of i) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
42
|
+
const r = d(e);
|
|
43
|
+
if (r) return r;
|
|
44
44
|
}
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
@@ -50,14 +50,14 @@ function p(i) {
|
|
|
50
50
|
if (typeof e == "string") return e;
|
|
51
51
|
if (Array.isArray(e) && typeof e[0] == "string") return e[0];
|
|
52
52
|
if (e && typeof e == "object") {
|
|
53
|
-
const
|
|
54
|
-
if (typeof
|
|
55
|
-
if (typeof
|
|
53
|
+
const r = e;
|
|
54
|
+
if (typeof r.url == "string") return r.url;
|
|
55
|
+
if (typeof r.contentUrl == "string") return r.contentUrl;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
return Array.isArray(t["@graph"]) ?
|
|
58
|
+
return Array.isArray(t["@graph"]) ? d(t["@graph"]) : null;
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function b() {
|
|
61
61
|
return `
|
|
62
62
|
:host {
|
|
63
63
|
display: inline-block;
|
|
@@ -440,9 +440,9 @@ const n = {
|
|
|
440
440
|
x: '<svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>',
|
|
441
441
|
alert: '<svg viewBox="0 0 24 24"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>'
|
|
442
442
|
};
|
|
443
|
-
class
|
|
443
|
+
class v extends HTMLElement {
|
|
444
444
|
constructor() {
|
|
445
|
-
super(), this.apiClient = null, this.sseClient = null, this.sseUnsubscribe = null, this.state = "idle", this.selectedFile = null, this.previewUrl = null, this.resultImageUrl = null, this.errorMessage = null, this.currentJobId = null, this.productImageUrl = null, this.t = l(), this.buttonStyles = {}, this.modalStyles = {}, this.savedScrollY = 0, this.shadow = this.attachShadow({ mode: "open" });
|
|
445
|
+
super(), this.apiClient = null, this.sseClient = null, this.sseUnsubscribe = null, this.state = "idle", this.selectedFile = null, this.previewUrl = null, this.resultImageUrl = null, this.errorMessage = null, this.currentJobId = null, this.productImageUrl = null, this.productViewReportedFor = null, this.t = l(), this.buttonStyles = {}, this.modalStyles = {}, this.savedScrollY = 0, this.shadow = this.attachShadow({ mode: "open" });
|
|
446
446
|
}
|
|
447
447
|
static get observedAttributes() {
|
|
448
448
|
return [
|
|
@@ -452,6 +452,7 @@ class b extends HTMLElement {
|
|
|
452
452
|
"button-text",
|
|
453
453
|
"locale",
|
|
454
454
|
"show-powered-by",
|
|
455
|
+
"clarity-project-id",
|
|
455
456
|
"button-styles",
|
|
456
457
|
"modal-styles"
|
|
457
458
|
];
|
|
@@ -462,15 +463,15 @@ class b extends HTMLElement {
|
|
|
462
463
|
disconnectedCallback() {
|
|
463
464
|
this.cleanup();
|
|
464
465
|
}
|
|
465
|
-
attributeChangedCallback(t, e,
|
|
466
|
-
if ((t === "api-key" || t === "api-url") && this.initApi(), t === "locale" && (this.t = l(
|
|
466
|
+
attributeChangedCallback(t, e, r) {
|
|
467
|
+
if ((t === "api-key" || t === "api-url") && this.initApi(), t === "locale" && (this.t = l(r || void 0)), t === "product-image" && (this.productImageUrl = r), t === "button-styles")
|
|
467
468
|
try {
|
|
468
|
-
this.buttonStyles = JSON.parse(
|
|
469
|
+
this.buttonStyles = JSON.parse(r);
|
|
469
470
|
} catch {
|
|
470
471
|
}
|
|
471
472
|
if (t === "modal-styles")
|
|
472
473
|
try {
|
|
473
|
-
this.modalStyles = JSON.parse(
|
|
474
|
+
this.modalStyles = JSON.parse(r);
|
|
474
475
|
} catch {
|
|
475
476
|
}
|
|
476
477
|
this.isConnected && this.render();
|
|
@@ -492,7 +493,7 @@ class b extends HTMLElement {
|
|
|
492
493
|
}
|
|
493
494
|
/** Open the try-on modal */
|
|
494
495
|
open() {
|
|
495
|
-
this.state = "upload", this.lockBodyScroll(), this.render(), this.emit("ps:open");
|
|
496
|
+
this.reportEvent("SDK_OPENED", { metadata: { component: "PrimeStyleTryonElement" } }), this.state = "upload", this.tagClarity("upload"), this.lockBodyScroll(), this.render(), this.emit("ps:open");
|
|
496
497
|
}
|
|
497
498
|
/** Close the try-on modal */
|
|
498
499
|
close() {
|
|
@@ -500,7 +501,7 @@ class b extends HTMLElement {
|
|
|
500
501
|
}
|
|
501
502
|
/** Detect product image from the current page */
|
|
502
503
|
detectProduct() {
|
|
503
|
-
const t =
|
|
504
|
+
const t = p();
|
|
504
505
|
return t && (this.productImageUrl = t, this.emit("ps:product-detected", { imageUrl: t })), t;
|
|
505
506
|
}
|
|
506
507
|
// ── Private ─────────────────────────────────
|
|
@@ -517,12 +518,12 @@ class b extends HTMLElement {
|
|
|
517
518
|
this.modalStyles = JSON.parse(e);
|
|
518
519
|
} catch {
|
|
519
520
|
}
|
|
520
|
-
const
|
|
521
|
-
|
|
521
|
+
const r = this.getAttribute("locale");
|
|
522
|
+
r && (this.t = l(r)), this.productImageUrl = this.getAttribute("product-image") || null, this.productImageUrl || (this.productImageUrl = p(), this.productImageUrl && this.emit("ps:product-detected", { imageUrl: this.productImageUrl })), this.initApi(), this.reportProductView();
|
|
522
523
|
}
|
|
523
524
|
initApi() {
|
|
524
525
|
const t = this.getAttribute("api-key") || void 0, e = this.getAttribute("api-url") || void 0;
|
|
525
|
-
this.apiClient = new c(t, e), this.sseClient =
|
|
526
|
+
this.apiClient = new c(t, e), this.sseClient = null;
|
|
526
527
|
}
|
|
527
528
|
cleanup() {
|
|
528
529
|
this.state !== "idle" && this.unlockBodyScroll(), this.sseUnsubscribe && (this.sseUnsubscribe(), this.sseUnsubscribe = null), this.sseClient && (this.sseClient.disconnect(), this.sseClient = null), this.previewUrl && URL.revokeObjectURL(this.previewUrl);
|
|
@@ -532,6 +533,42 @@ class b extends HTMLElement {
|
|
|
532
533
|
new CustomEvent(t, { bubbles: !0, composed: !0, detail: e })
|
|
533
534
|
);
|
|
534
535
|
}
|
|
536
|
+
get eventProductContext() {
|
|
537
|
+
return {
|
|
538
|
+
productId: this.getAttribute("product-id") || this.productImageUrl || void 0,
|
|
539
|
+
productTitle: this.getAttribute("product-title") || document.title || void 0,
|
|
540
|
+
productUrl: typeof window < "u" ? window.location.href : void 0
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
reportProductView() {
|
|
544
|
+
const t = `${this.eventProductContext.productId || ""}|${this.eventProductContext.productUrl || ""}`;
|
|
545
|
+
!t.trim() || this.productViewReportedFor === t || (this.productViewReportedFor = t, this.tagClarity("idle"), this.reportEvent("PRODUCT_VIEW", { metadata: { component: "PrimeStyleTryonElement" } }));
|
|
546
|
+
}
|
|
547
|
+
tagClarity(t, e) {
|
|
548
|
+
const r = {
|
|
549
|
+
projectId: this.getAttribute("clarity-project-id"),
|
|
550
|
+
...this.eventProductContext,
|
|
551
|
+
view: t,
|
|
552
|
+
jobId: e,
|
|
553
|
+
source: "custom-element-sdk"
|
|
554
|
+
};
|
|
555
|
+
h(r), u(r);
|
|
556
|
+
}
|
|
557
|
+
reportEvent(t, e = {}) {
|
|
558
|
+
this.apiClient?.reportEvent({
|
|
559
|
+
eventType: t,
|
|
560
|
+
...this.eventProductContext,
|
|
561
|
+
...e
|
|
562
|
+
}).catch(() => {
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
reportClientError(t) {
|
|
566
|
+
this.apiClient?.reportClientError({
|
|
567
|
+
...this.eventProductContext,
|
|
568
|
+
...t
|
|
569
|
+
}).catch(() => {
|
|
570
|
+
});
|
|
571
|
+
}
|
|
535
572
|
get buttonText() {
|
|
536
573
|
return this.getAttribute("button-text") || this.t("Virtual Try-On");
|
|
537
574
|
}
|
|
@@ -542,11 +579,11 @@ class b extends HTMLElement {
|
|
|
542
579
|
render() {
|
|
543
580
|
this.shadow.innerHTML = "";
|
|
544
581
|
const t = document.createElement("style");
|
|
545
|
-
t.textContent =
|
|
582
|
+
t.textContent = b(), this.shadow.appendChild(t);
|
|
546
583
|
const e = this.createButton();
|
|
547
584
|
if (this.shadow.appendChild(e), this.state !== "idle") {
|
|
548
|
-
const
|
|
549
|
-
this.shadow.appendChild(
|
|
585
|
+
const r = this.createModal();
|
|
586
|
+
this.shadow.appendChild(r), requestAnimationFrame(() => r.classList.add("ps-open"));
|
|
550
587
|
}
|
|
551
588
|
this.applyButtonStyles(), this.applyModalStyles();
|
|
552
589
|
}
|
|
@@ -556,19 +593,19 @@ class b extends HTMLElement {
|
|
|
556
593
|
}
|
|
557
594
|
createModal() {
|
|
558
595
|
const t = document.createElement("div");
|
|
559
|
-
t.className = "ps-overlay", t.addEventListener("click", (a) => {
|
|
596
|
+
t.className = "ps-overlay", t.setAttribute("data-clarity-unmask", "true"), t.addEventListener("click", (a) => {
|
|
560
597
|
a.target === t && this.close();
|
|
561
598
|
});
|
|
562
599
|
const e = document.createElement("div");
|
|
563
|
-
e.className = "ps-modal";
|
|
564
|
-
const
|
|
565
|
-
|
|
600
|
+
e.className = "ps-modal", e.setAttribute("data-clarity-unmask", "true");
|
|
601
|
+
const r = document.createElement("div");
|
|
602
|
+
r.className = "ps-header", r.innerHTML = `
|
|
566
603
|
<span class="ps-header-title">${this.t("Virtual Try-On")}</span>
|
|
567
604
|
`;
|
|
568
|
-
const
|
|
569
|
-
|
|
605
|
+
const s = document.createElement("button");
|
|
606
|
+
s.className = "ps-close", s.innerHTML = n.x, s.addEventListener("click", () => this.close()), r.appendChild(s), e.appendChild(r);
|
|
570
607
|
const o = document.createElement("div");
|
|
571
|
-
switch (o.className = "ps-body", this.state) {
|
|
608
|
+
switch (o.className = "ps-body", o.setAttribute("data-clarity-unmask", "true"), this.state) {
|
|
572
609
|
case "upload":
|
|
573
610
|
o.appendChild(this.createUploadView());
|
|
574
611
|
break;
|
|
@@ -593,32 +630,32 @@ class b extends HTMLElement {
|
|
|
593
630
|
if (this.selectedFile && this.previewUrl) {
|
|
594
631
|
const e = document.createElement("div");
|
|
595
632
|
e.className = "ps-preview";
|
|
596
|
-
const
|
|
597
|
-
|
|
598
|
-
const
|
|
599
|
-
|
|
633
|
+
const r = document.createElement("img");
|
|
634
|
+
r.src = this.previewUrl, r.alt = this.t("Your photo"), e.appendChild(r);
|
|
635
|
+
const s = document.createElement("button");
|
|
636
|
+
s.className = "ps-preview-remove", s.textContent = "×", s.addEventListener("click", () => {
|
|
600
637
|
this.resetUpload(), this.render();
|
|
601
|
-
}), e.appendChild(
|
|
638
|
+
}), e.appendChild(s), t.appendChild(e);
|
|
602
639
|
const o = document.createElement("button");
|
|
603
640
|
o.className = "ps-submit", o.textContent = this.t("Try It On"), o.addEventListener("click", () => this.handleSubmit()), t.appendChild(o);
|
|
604
641
|
} else {
|
|
605
642
|
const e = document.createElement("div");
|
|
606
643
|
e.className = "ps-upload-zone";
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
const o =
|
|
644
|
+
const r = document.createElement("input");
|
|
645
|
+
r.type = "file", r.accept = "image/jpeg,image/png,image/webp", r.addEventListener("change", (s) => {
|
|
646
|
+
const o = s.target.files?.[0];
|
|
610
647
|
o && this.handleFileSelect(o);
|
|
611
648
|
}), e.innerHTML = `
|
|
612
649
|
<svg class="ps-upload-icon" viewBox="0 0 24 24">${n.upload.replace(/<\/?svg[^>]*>/g, "")}</svg>
|
|
613
650
|
<p class="ps-upload-text">${this.t("Drop your photo here or click to upload")}</p>
|
|
614
651
|
<p class="ps-upload-hint">${this.t("JPEG, PNG or WebP (max 10MB)")}</p>
|
|
615
|
-
`, e.appendChild(
|
|
616
|
-
|
|
652
|
+
`, e.appendChild(r), e.addEventListener("click", () => r.click()), e.addEventListener("dragover", (s) => {
|
|
653
|
+
s.preventDefault(), e.classList.add("ps-drag-over");
|
|
617
654
|
}), e.addEventListener("dragleave", () => {
|
|
618
655
|
e.classList.remove("ps-drag-over");
|
|
619
|
-
}), e.addEventListener("drop", (
|
|
620
|
-
|
|
621
|
-
const o =
|
|
656
|
+
}), e.addEventListener("drop", (s) => {
|
|
657
|
+
s.preventDefault(), e.classList.remove("ps-drag-over");
|
|
658
|
+
const o = s.dataTransfer?.files?.[0];
|
|
622
659
|
o && this.handleFileSelect(o);
|
|
623
660
|
}), t.appendChild(e);
|
|
624
661
|
}
|
|
@@ -640,12 +677,12 @@ class b extends HTMLElement {
|
|
|
640
677
|
}
|
|
641
678
|
const e = document.createElement("div");
|
|
642
679
|
e.className = "ps-result-actions";
|
|
643
|
-
const s = document.createElement("button");
|
|
644
|
-
s.className = "ps-btn-download", s.textContent = this.t("Download"), s.addEventListener("click", () => this.handleDownload()), e.appendChild(s);
|
|
645
680
|
const r = document.createElement("button");
|
|
646
|
-
|
|
681
|
+
r.className = "ps-btn-download", r.textContent = this.t("Download"), r.addEventListener("click", () => this.handleDownload()), e.appendChild(r);
|
|
682
|
+
const s = document.createElement("button");
|
|
683
|
+
return s.className = "ps-btn-retry", s.textContent = this.t("Try Another"), s.addEventListener("click", () => {
|
|
647
684
|
this.resetUpload(), this.state = "upload", this.render();
|
|
648
|
-
}), e.appendChild(
|
|
685
|
+
}), e.appendChild(s), t.appendChild(e), t;
|
|
649
686
|
}
|
|
650
687
|
createErrorView() {
|
|
651
688
|
const t = document.createElement("div");
|
|
@@ -660,55 +697,97 @@ class b extends HTMLElement {
|
|
|
660
697
|
}
|
|
661
698
|
// ── Handlers ────────────────────────────────
|
|
662
699
|
handleFileSelect(t) {
|
|
663
|
-
if (!
|
|
664
|
-
this.errorMessage = this.t("Please upload a JPEG, PNG, or WebP image."), this.state = "error", this.
|
|
700
|
+
if (!m(t)) {
|
|
701
|
+
this.errorMessage = this.t("Please upload a JPEG, PNG, or WebP image."), this.state = "error", this.reportClientError({
|
|
702
|
+
message: "Invalid image file type",
|
|
703
|
+
code: "INVALID_FILE",
|
|
704
|
+
component: "PrimeStyleTryonElement",
|
|
705
|
+
view: "upload",
|
|
706
|
+
severity: "low",
|
|
707
|
+
metadata: { fileType: t.type, fileSize: t.size }
|
|
708
|
+
}), this.render();
|
|
665
709
|
return;
|
|
666
710
|
}
|
|
667
711
|
if (t.size > 10 * 1024 * 1024) {
|
|
668
|
-
this.errorMessage = this.t("Image must be under 10MB."), this.state = "error", this.
|
|
712
|
+
this.errorMessage = this.t("Image must be under 10MB."), this.state = "error", this.reportClientError({
|
|
713
|
+
message: "Image file too large",
|
|
714
|
+
code: "FILE_TOO_LARGE",
|
|
715
|
+
component: "PrimeStyleTryonElement",
|
|
716
|
+
view: "upload",
|
|
717
|
+
severity: "low",
|
|
718
|
+
metadata: { fileType: t.type, fileSize: t.size }
|
|
719
|
+
}), this.render();
|
|
669
720
|
return;
|
|
670
721
|
}
|
|
671
|
-
this.selectedFile = t, this.previewUrl = URL.createObjectURL(t), this.
|
|
722
|
+
this.selectedFile = t, this.previewUrl = URL.createObjectURL(t), this.reportEvent("PHOTO_UPLOADED", {
|
|
723
|
+
metadata: { fileType: t.type, fileSize: t.size, component: "PrimeStyleTryonElement" }
|
|
724
|
+
}), this.emit("ps:upload", { file: t }), this.render();
|
|
672
725
|
}
|
|
673
726
|
async handleSubmit() {
|
|
674
|
-
if (!this.selectedFile || !this.apiClient
|
|
675
|
-
this.errorMessage = this.t("SDK not configured. Please provide an API key."), this.state = "error", this.
|
|
727
|
+
if (!this.selectedFile || !this.apiClient) {
|
|
728
|
+
this.errorMessage = this.t("SDK not configured. Please provide an API key."), this.state = "error", this.reportClientError({
|
|
729
|
+
message: this.errorMessage,
|
|
730
|
+
code: this.apiClient ? "PHOTO_MISSING" : "SDK_NOT_CONFIGURED",
|
|
731
|
+
component: "PrimeStyleTryonElement",
|
|
732
|
+
view: "upload",
|
|
733
|
+
severity: this.apiClient ? "low" : "high"
|
|
734
|
+
}), this.render();
|
|
676
735
|
return;
|
|
677
736
|
}
|
|
678
737
|
if (!this.productImageUrl) {
|
|
679
|
-
this.errorMessage = this.t("No product image found. Please set the product-image attribute."), this.state = "error", this.
|
|
738
|
+
this.errorMessage = this.t("No product image found. Please set the product-image attribute."), this.state = "error", this.reportClientError({
|
|
739
|
+
message: this.errorMessage,
|
|
740
|
+
code: "PRODUCT_IMAGE_MISSING",
|
|
741
|
+
component: "PrimeStyleTryonElement",
|
|
742
|
+
view: "upload",
|
|
743
|
+
severity: "medium"
|
|
744
|
+
}), this.render();
|
|
680
745
|
return;
|
|
681
746
|
}
|
|
682
|
-
this.state = "processing", this.render();
|
|
747
|
+
this.state = "processing", this.tagClarity("processing"), this.render();
|
|
683
748
|
try {
|
|
684
|
-
const t = await
|
|
749
|
+
const t = await g(this.selectedFile), e = await this.apiClient.submitTryOn(
|
|
685
750
|
t,
|
|
686
751
|
this.productImageUrl
|
|
687
752
|
);
|
|
688
|
-
this.currentJobId = e.jobId, this.emit("ps:processing", { jobId: e.jobId }), this.sseUnsubscribe = this.sseClient.onJob(
|
|
753
|
+
this.currentJobId = e.jobId, this.tagClarity("processing", e.jobId), this.emit("ps:processing", { jobId: e.jobId }), this.sseClient?.disconnect(), this.sseClient = new y(e.streamUrl || this.apiClient.getStreamUrl(e.jobId)), this.sseUnsubscribe = this.sseClient.onJob(
|
|
689
754
|
e.jobId,
|
|
690
|
-
(
|
|
755
|
+
(r) => this.handleVtoUpdate(r)
|
|
691
756
|
), this.startPolling(e.jobId);
|
|
692
757
|
} catch (t) {
|
|
693
758
|
const e = t instanceof Error ? t.message : this.t("Failed to start try-on");
|
|
694
|
-
this.errorMessage = e, this.state = "error", this.
|
|
759
|
+
this.errorMessage = e, this.state = "error", this.reportClientError({
|
|
760
|
+
message: e,
|
|
761
|
+
code: t?.code || "TRYON_SUBMIT_FAILED",
|
|
762
|
+
stack: t instanceof Error ? t.stack : void 0,
|
|
763
|
+
component: "PrimeStyleTryonElement",
|
|
764
|
+
view: "processing",
|
|
765
|
+
severity: "medium"
|
|
766
|
+
}), this.emit("ps:error", { message: e, code: t?.code }), this.render();
|
|
695
767
|
}
|
|
696
768
|
}
|
|
697
769
|
handleVtoUpdate(t) {
|
|
698
|
-
t.status === "completed" && t.imageUrl ? (this.state !== "result" || this.resultImageUrl?.startsWith("data:") && !t.imageUrl.startsWith("data:")) && (this.resultImageUrl = t.imageUrl, this.state = "result", this.emit("ps:complete", {
|
|
770
|
+
t.status === "completed" && t.imageUrl ? (this.state !== "result" || this.resultImageUrl?.startsWith("data:") && !t.imageUrl.startsWith("data:")) && (this.resultImageUrl = t.imageUrl, this.state = "result", this.tagClarity("result", t.galleryId), this.emit("ps:complete", {
|
|
699
771
|
jobId: t.galleryId,
|
|
700
772
|
imageUrl: t.imageUrl
|
|
701
|
-
}), this.render()) : t.status === "failed" && (this.errorMessage = t.error || this.t("Try-on generation failed"), this.state = "error", this.
|
|
773
|
+
}), this.render()) : t.status === "failed" && (this.errorMessage = t.error || this.t("Try-on generation failed"), this.state = "error", this.tagClarity("error", t.galleryId), this.reportClientError({
|
|
774
|
+
message: this.errorMessage,
|
|
775
|
+
code: "TRYON_GENERATION_FAILED",
|
|
776
|
+
component: "PrimeStyleTryonElement",
|
|
777
|
+
view: "processing",
|
|
778
|
+
severity: "medium",
|
|
779
|
+
jobId: t.galleryId
|
|
780
|
+
}), this.emit("ps:error", { message: this.errorMessage }), this.render());
|
|
702
781
|
}
|
|
703
782
|
startPolling(t) {
|
|
704
783
|
let e = 0;
|
|
705
|
-
const
|
|
706
|
-
if (e++, e >
|
|
707
|
-
clearInterval(
|
|
784
|
+
const r = 60, s = setInterval(async () => {
|
|
785
|
+
if (e++, e > r || this.state === "result" || this.state === "idle") {
|
|
786
|
+
clearInterval(s);
|
|
708
787
|
return;
|
|
709
788
|
}
|
|
710
789
|
if (!this.apiClient) {
|
|
711
|
-
clearInterval(
|
|
790
|
+
clearInterval(s);
|
|
712
791
|
return;
|
|
713
792
|
}
|
|
714
793
|
try {
|
|
@@ -719,13 +798,13 @@ class b extends HTMLElement {
|
|
|
719
798
|
imageUrl: o.imageUrl,
|
|
720
799
|
error: null,
|
|
721
800
|
timestamp: Date.now()
|
|
722
|
-
}), clearInterval(
|
|
801
|
+
}), clearInterval(s)) : o.status === "failed" && (this.state === "processing" && this.handleVtoUpdate({
|
|
723
802
|
galleryId: t,
|
|
724
803
|
status: "failed",
|
|
725
804
|
imageUrl: null,
|
|
726
805
|
error: o.message,
|
|
727
806
|
timestamp: Date.now()
|
|
728
|
-
}), clearInterval(
|
|
807
|
+
}), clearInterval(s));
|
|
729
808
|
} catch {
|
|
730
809
|
}
|
|
731
810
|
}, 2e3);
|
|
@@ -734,8 +813,8 @@ class b extends HTMLElement {
|
|
|
734
813
|
if (!this.resultImageUrl) return;
|
|
735
814
|
const t = document.createElement("a");
|
|
736
815
|
t.href = this.resultImageUrl, t.download = `primestyle-tryon-${Date.now()}.png`, t.target = "_blank", this.resultImageUrl.startsWith("data:") ? t.click() : fetch(this.resultImageUrl).then((e) => e.blob()).then((e) => {
|
|
737
|
-
const
|
|
738
|
-
t.href =
|
|
816
|
+
const r = URL.createObjectURL(e);
|
|
817
|
+
t.href = r, t.click(), setTimeout(() => URL.revokeObjectURL(r), 100);
|
|
739
818
|
}).catch(() => {
|
|
740
819
|
window.open(this.resultImageUrl, "_blank");
|
|
741
820
|
});
|
|
@@ -770,9 +849,9 @@ class b extends HTMLElement {
|
|
|
770
849
|
iconColor: "--ps-btn-icon-color",
|
|
771
850
|
boxShadow: "--ps-btn-shadow"
|
|
772
851
|
};
|
|
773
|
-
for (const [
|
|
774
|
-
const o = this.buttonStyles[
|
|
775
|
-
o && this.style.setProperty(
|
|
852
|
+
for (const [r, s] of Object.entries(e)) {
|
|
853
|
+
const o = this.buttonStyles[r];
|
|
854
|
+
o && this.style.setProperty(s, o);
|
|
776
855
|
}
|
|
777
856
|
}
|
|
778
857
|
applyModalStyles() {
|
|
@@ -808,26 +887,26 @@ class b extends HTMLElement {
|
|
|
808
887
|
successColor: "--ps-success-color",
|
|
809
888
|
logoHeight: "--ps-logo-height"
|
|
810
889
|
};
|
|
811
|
-
for (const [e,
|
|
812
|
-
const
|
|
813
|
-
|
|
890
|
+
for (const [e, r] of Object.entries(t)) {
|
|
891
|
+
const s = this.modalStyles[e];
|
|
892
|
+
s && this.style.setProperty(r, s);
|
|
814
893
|
}
|
|
815
894
|
}
|
|
816
895
|
}
|
|
817
|
-
typeof window < "u" && !customElements.get("primestyle-tryon") && customElements.define("primestyle-tryon",
|
|
896
|
+
typeof window < "u" && !customElements.get("primestyle-tryon") && customElements.define("primestyle-tryon", v);
|
|
818
897
|
export {
|
|
819
898
|
c as ApiClient,
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
899
|
+
C as PrimeStyleError,
|
|
900
|
+
v as PrimeStyleTryon,
|
|
901
|
+
S as SUPPORTED_LOCALES,
|
|
902
|
+
y as SseClient,
|
|
903
|
+
k as TRANSLATION_KEYS,
|
|
904
|
+
E as checkAgeBeforeUpload,
|
|
905
|
+
g as compressImage,
|
|
827
906
|
l as createT,
|
|
828
907
|
U as detectLanguage,
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
908
|
+
p as detectProductImage,
|
|
909
|
+
m as isValidImageFile,
|
|
910
|
+
I as registerLocale
|
|
832
911
|
};
|
|
833
912
|
//# sourceMappingURL=primestyle-tryon.js.map
|