@wewear/virtual-try-on 1.4.30 → 2.0.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/dist/components/index.d.ts +0 -2
- package/dist/constants.d.ts +0 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.esm.js +363 -531
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +363 -531
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/widget/modal-manager.d.ts +15 -0
- package/dist/widget/vto-api-client.d.ts +20 -0
- package/dist/widget.d.ts +6 -7
- package/package.json +3 -2
- package/dist/api.d.ts +0 -8
- package/dist/camera.d.ts +0 -10
- package/dist/components/alert-overlay.d.ts +0 -2
- package/dist/components/badge.d.ts +0 -1
- package/dist/components/camera-modal.d.ts +0 -7
- package/dist/components/loading-overlay.d.ts +0 -3
- package/dist/components/review-modal.d.ts +0 -8
- package/dist/components/status-badge.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
};
|
|
12
12
|
const Z_INDEX = {
|
|
13
13
|
BUTTON: 10,
|
|
14
|
-
MODAL: 99999,
|
|
15
14
|
};
|
|
16
15
|
|
|
17
16
|
function getPositionStyles(position) {
|
|
@@ -27,140 +26,96 @@
|
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
28
|
|
|
29
|
+
const CAMERA_ICON = `
|
|
30
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block;">
|
|
31
|
+
<path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"></path>
|
|
32
|
+
<circle cx="12" cy="13" r="3"></circle>
|
|
33
|
+
</svg>
|
|
34
|
+
`;
|
|
35
|
+
const SPARKLES_ICON = `
|
|
36
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block; flex-shrink: 0;">
|
|
37
|
+
<path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"/>
|
|
38
|
+
<path d="M20 2v4"/>
|
|
39
|
+
<path d="M22 4h-4"/>
|
|
40
|
+
<circle cx="4" cy="20" r="2"/>
|
|
41
|
+
</svg>
|
|
42
|
+
`;
|
|
43
|
+
const REFRESH_ICON = `
|
|
44
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block;">
|
|
45
|
+
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path>
|
|
46
|
+
<path d="M3 3v5h5"></path>
|
|
47
|
+
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"></path>
|
|
48
|
+
<path d="M16 16h5v5"></path>
|
|
49
|
+
</svg>
|
|
50
|
+
`;
|
|
51
|
+
const CONTAINER_STYLE = `
|
|
52
|
+
position: absolute;
|
|
53
|
+
display: flex;
|
|
54
|
+
gap: 4px;
|
|
55
|
+
border-radius: 100px;
|
|
56
|
+
background: white;
|
|
57
|
+
padding: 4px;
|
|
58
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
59
|
+
z-index: ${Z_INDEX.BUTTON};
|
|
60
|
+
transition: all 0.2s ease;
|
|
61
|
+
`;
|
|
62
|
+
const ICON_BUTTON_STYLE = `
|
|
63
|
+
display: flex;
|
|
64
|
+
width: 40px;
|
|
65
|
+
height: 40px;
|
|
66
|
+
cursor: pointer;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
border-radius: 100px;
|
|
70
|
+
padding: 0;
|
|
71
|
+
border: none;
|
|
72
|
+
transition: all 0.2s ease;
|
|
73
|
+
flex-shrink: 0;
|
|
74
|
+
`;
|
|
75
|
+
const PRIMARY_STYLE = `${ICON_BUTTON_STYLE}
|
|
76
|
+
background: white;
|
|
77
|
+
color: #000000;
|
|
78
|
+
`;
|
|
79
|
+
function createIconButton(className, ariaLabel, iconHtml, styleCss, onClick) {
|
|
80
|
+
const button = document.createElement("button");
|
|
81
|
+
button.type = "button";
|
|
82
|
+
button.className = className;
|
|
83
|
+
button.setAttribute("aria-label", ariaLabel);
|
|
84
|
+
button.style.cssText = styleCss;
|
|
85
|
+
button.innerHTML = iconHtml;
|
|
86
|
+
button.onclick = onClick;
|
|
87
|
+
return button;
|
|
88
|
+
}
|
|
30
89
|
function createButtonContainer(buttonPosition, hasVirtualTryOn = false, onCameraClick, onRefreshClick, onToggleClick, isShowingVirtualTryOn = false) {
|
|
31
90
|
const container = document.createElement("div");
|
|
32
91
|
container.className = `${CSS_CLASSES.BUTTON_CONTAINER} ww-button-group`;
|
|
33
92
|
const positionStyles = getPositionStyles(buttonPosition);
|
|
34
|
-
container.style.cssText =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const cameraButton = document.createElement("button");
|
|
47
|
-
cameraButton.type = "button";
|
|
48
|
-
cameraButton.className = `${CSS_CLASSES.BUTTON} ww-camera-btn`;
|
|
49
|
-
cameraButton.setAttribute("aria-label", "Virtual Try-On");
|
|
50
|
-
if (hasVirtualTryOn) {
|
|
51
|
-
cameraButton.style.cssText = `
|
|
52
|
-
display: flex;
|
|
53
|
-
width: 40px;
|
|
54
|
-
height: 40px;
|
|
55
|
-
cursor: pointer;
|
|
56
|
-
align-items: center;
|
|
57
|
-
justify-content: center;
|
|
58
|
-
border-radius: 100px;
|
|
59
|
-
padding: 0;
|
|
60
|
-
border: none;
|
|
61
|
-
background: white;
|
|
62
|
-
color: #000000;
|
|
63
|
-
transition: all 0.2s ease;
|
|
64
|
-
flex-shrink: 0;
|
|
65
|
-
`;
|
|
66
|
-
cameraButton.innerHTML = `
|
|
67
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block;">
|
|
68
|
-
<path d="M14.5 4h-5L7 7H4a2 2 0 0 0-2 2v9a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V9a2 2 0 0 0-2-2h-3l-2.5-3z"></path>
|
|
69
|
-
<circle cx="12" cy="13" r="3"></circle>
|
|
70
|
-
</svg>
|
|
71
|
-
`;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
cameraButton.style.cssText = `
|
|
75
|
-
display: flex;
|
|
76
|
-
cursor: pointer;
|
|
77
|
-
align-items: center;
|
|
78
|
-
justify-content: center;
|
|
79
|
-
border-radius: 100px;
|
|
80
|
-
padding: 10px 16px;
|
|
81
|
-
border: none;
|
|
82
|
-
background: white;
|
|
83
|
-
color: #000000;
|
|
84
|
-
transition: all 0.2s ease;
|
|
85
|
-
flex-shrink: 0;
|
|
86
|
-
gap: 8px;
|
|
87
|
-
font-size: 14px;
|
|
88
|
-
font-weight: 600;
|
|
89
|
-
white-space: nowrap;
|
|
90
|
-
`;
|
|
91
|
-
cameraButton.innerHTML = `
|
|
92
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block; flex-shrink: 0;">
|
|
93
|
-
<path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"/>
|
|
94
|
-
<path d="M20 2v4"/>
|
|
95
|
-
<path d="M22 4h-4"/>
|
|
96
|
-
<circle cx="4" cy="20" r="2"/>
|
|
97
|
-
</svg>
|
|
98
|
-
<span style="display: block;">TRY THIS LOOK</span>
|
|
99
|
-
`;
|
|
100
|
-
}
|
|
101
|
-
cameraButton.onclick = onCameraClick;
|
|
93
|
+
container.style.cssText = `${CONTAINER_STYLE} ${positionStyles}`;
|
|
94
|
+
const cameraButton = hasVirtualTryOn
|
|
95
|
+
? createIconButton(`${CSS_CLASSES.BUTTON} ww-camera-btn`, "Virtual Try-On", CAMERA_ICON, PRIMARY_STYLE, onCameraClick)
|
|
96
|
+
: createIconButton(`${CSS_CLASSES.BUTTON} ww-camera-btn`, "Virtual Try-On", `${SPARKLES_ICON}<span style="display: block;">TRY THIS LOOK</span>`, `${PRIMARY_STYLE}
|
|
97
|
+
padding: 10px 16px;
|
|
98
|
+
gap: 8px;
|
|
99
|
+
font-size: 14px;
|
|
100
|
+
font-weight: 600;
|
|
101
|
+
white-space: nowrap;
|
|
102
|
+
width: auto;
|
|
103
|
+
height: auto;
|
|
104
|
+
`, onCameraClick);
|
|
102
105
|
container.appendChild(cameraButton);
|
|
103
106
|
if (hasVirtualTryOn) {
|
|
104
107
|
if (onRefreshClick) {
|
|
105
|
-
const refreshButton =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
refreshButton.style.cssText = `
|
|
110
|
-
display: flex;
|
|
111
|
-
width: 40px;
|
|
112
|
-
height: 40px;
|
|
113
|
-
cursor: pointer;
|
|
114
|
-
align-items: center;
|
|
115
|
-
justify-content: center;
|
|
116
|
-
border-radius: 100px;
|
|
117
|
-
padding: 0;
|
|
118
|
-
border: none;
|
|
119
|
-
background: white;
|
|
120
|
-
color: #333333;
|
|
121
|
-
transition: all 0.2s ease;
|
|
122
|
-
flex-shrink: 0;
|
|
123
|
-
`;
|
|
124
|
-
refreshButton.innerHTML = `
|
|
125
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block;">
|
|
126
|
-
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path>
|
|
127
|
-
<path d="M3 3v5h5"></path>
|
|
128
|
-
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"></path>
|
|
129
|
-
<path d="M16 16h5v5"></path>
|
|
130
|
-
</svg>
|
|
131
|
-
`;
|
|
132
|
-
refreshButton.onclick = onRefreshClick;
|
|
133
|
-
refreshButton.onclick = onRefreshClick;
|
|
108
|
+
const refreshButton = createIconButton("ww-refresh-btn", "Refresh virtual try-on", REFRESH_ICON, `${ICON_BUTTON_STYLE}
|
|
109
|
+
background: white;
|
|
110
|
+
color: #333333;
|
|
111
|
+
`, onRefreshClick);
|
|
134
112
|
container.appendChild(refreshButton);
|
|
135
113
|
}
|
|
136
114
|
if (onToggleClick) {
|
|
137
|
-
const toggleButton =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
toggleButton.style.cssText = `
|
|
142
|
-
display: flex;
|
|
143
|
-
width: 40px;
|
|
144
|
-
height: 40px;
|
|
145
|
-
cursor: pointer;
|
|
146
|
-
align-items: center;
|
|
147
|
-
justify-content: center;
|
|
148
|
-
border-radius: 100px;
|
|
149
|
-
padding: 0;
|
|
150
|
-
border: none;
|
|
151
|
-
background: ${isShowingVirtualTryOn ? "#333333" : "#e5e7eb"};
|
|
152
|
-
color: ${isShowingVirtualTryOn ? "white" : "#333333"};
|
|
153
|
-
transition: all 0.2s ease;
|
|
154
|
-
flex-shrink: 0;
|
|
155
|
-
`;
|
|
156
|
-
toggleButton.innerHTML = `
|
|
157
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: block;">
|
|
158
|
-
<path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594z"/>
|
|
159
|
-
<path d="M20 2v4"/>
|
|
160
|
-
<path d="M22 4h-4"/>
|
|
161
|
-
<circle cx="4" cy="20" r="2"/>
|
|
162
|
-
</svg>
|
|
163
|
-
`;
|
|
115
|
+
const toggleButton = createIconButton("ww-toggle-btn", isShowingVirtualTryOn ? "Show Original Image" : "Show Virtual Try-On", SPARKLES_ICON, `${ICON_BUTTON_STYLE}
|
|
116
|
+
background: ${isShowingVirtualTryOn ? "#333333" : "#e5e7eb"};
|
|
117
|
+
color: ${isShowingVirtualTryOn ? "white" : "#333333"};
|
|
118
|
+
`, onToggleClick);
|
|
164
119
|
toggleButton.onmouseover = () => {
|
|
165
120
|
if (isShowingVirtualTryOn) {
|
|
166
121
|
toggleButton.style.background = "#4a4a4a";
|
|
@@ -197,205 +152,253 @@
|
|
|
197
152
|
return container;
|
|
198
153
|
}
|
|
199
154
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
@keyframes ww-dot-bounce {
|
|
246
|
-
0%, 80%, 100% {
|
|
247
|
-
transform: scale(0);
|
|
248
|
-
opacity: 0.5;
|
|
249
|
-
}
|
|
250
|
-
40% {
|
|
251
|
-
transform: scale(1);
|
|
252
|
-
opacity: 1;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
.ww-loading-logo {
|
|
257
|
-
animation: ww-pulse-logo 2s ease-in-out infinite;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
.ww-loading-spinner {
|
|
261
|
-
animation: ww-spinner-rotate 1s linear infinite;
|
|
262
|
-
}
|
|
263
|
-
`;
|
|
264
|
-
document.head.appendChild(style);
|
|
265
|
-
}
|
|
266
|
-
overlay.innerHTML = `
|
|
267
|
-
<div style="display: flex; flex-direction: column; align-items: center; gap: 32px;">
|
|
268
|
-
<div style="position: relative; width: 120px; height: 120px; display: flex; align-items: center; justify-content: center;">
|
|
269
|
-
<!-- Outer spinning circle -->
|
|
270
|
-
<div class="ww-loading-spinner" style="
|
|
271
|
-
position: absolute;
|
|
272
|
-
width: 120px;
|
|
273
|
-
height: 120px;
|
|
274
|
-
border: 3px solid transparent;
|
|
275
|
-
border-top: 3px solid #333333;
|
|
276
|
-
border-right: 3px solid #333333;
|
|
277
|
-
border-radius: 50%;
|
|
278
|
-
"></div>
|
|
279
|
-
|
|
280
|
-
<!-- Logo -->
|
|
281
|
-
<svg class="ww-loading-logo" width="80" height="50" viewBox="0 0 214 135" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
282
|
-
<path d="M102.906 74.8679C102.906 77.9717 101.574 80.7453 98.9104 83.1887C96.6871 85.1918 93.9025 86.6997 90.5566 87.7123C87.695 88.5708 84.6462 89 81.4104 89C73.8821 89 68.0047 87.0189 63.7783 83.0566C59.5519 87.0189 53.6855 89 46.1792 89C42.9434 89 39.9057 88.5708 37.066 87.7123C33.7201 86.6997 30.9245 85.1918 28.6792 83.1887C26.0157 80.7453 24.684 77.9717 24.684 74.8679V41.6509H32.3774V74.8679C32.3774 76.2547 33.489 77.5645 35.7123 78.7972C37.3632 79.7217 39.0692 80.3711 40.8302 80.7453C42.5252 81.1195 44.3082 81.3066 46.1792 81.3066C48.0063 81.3066 49.7673 81.1195 51.4623 80.7453C53.2453 80.3711 54.9623 79.7217 56.6132 78.7972C58.8585 77.5645 59.9811 76.2547 59.9811 74.8679V41.6509H67.6085V74.8679C67.6085 76.2547 68.7311 77.5645 70.9764 78.7972C72.6274 79.7217 74.3443 80.3711 76.1274 80.7453C77.8223 81.1195 79.5833 81.3066 81.4104 81.3066C83.2814 81.3066 85.0755 81.1195 86.7925 80.7453C88.5314 80.3711 90.2264 79.7217 91.8774 78.7972C94.1006 77.5645 95.2123 76.2547 95.2123 74.8679V41.6509H102.906V74.8679ZM189.283 74.8679C189.283 77.9717 187.951 80.7453 185.288 83.1887C183.064 85.1918 180.28 86.6997 176.934 87.7123C174.072 88.5708 171.024 89 167.788 89C160.259 89 154.382 87.0189 150.156 83.0566C145.929 87.0189 140.063 89 132.557 89C129.321 89 126.283 88.5708 123.443 87.7123C120.097 86.6997 117.302 85.1918 115.057 83.1887C112.393 80.7453 111.061 77.9717 111.061 74.8679V41.6509H118.755V74.8679C118.755 76.2547 119.866 77.5645 122.09 78.7972C123.741 79.7217 125.447 80.3711 127.208 80.7453C128.903 81.1195 130.686 81.3066 132.557 81.3066C134.384 81.3066 136.145 81.1195 137.84 80.7453C139.623 80.3711 141.34 79.7217 142.991 78.7972C145.236 77.5645 146.358 76.2547 146.358 74.8679V41.6509H153.986V74.8679C153.986 76.2547 155.108 77.5645 157.354 78.7972C159.005 79.7217 160.722 80.3711 162.505 80.7453C164.2 81.1195 165.961 81.3066 167.788 81.3066C169.659 81.3066 171.453 81.1195 173.17 80.7453C174.909 80.3711 176.604 79.7217 178.255 78.7972C180.478 77.5645 181.59 76.2547 181.59 74.8679V41.6509H189.283V74.8679Z" fill="white"/>
|
|
283
|
-
</svg>
|
|
284
|
-
</div>
|
|
285
|
-
|
|
286
|
-
<div style="font-size: 17px; font-weight: 500; text-align: center; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; color: white; letter-spacing: 0.5px; max-width: 280px;">${text}</div>
|
|
287
|
-
|
|
288
|
-
<div style="display: flex; gap: 10px; margin-top: 4px;">
|
|
289
|
-
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out infinite;"></div>
|
|
290
|
-
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out 0.2s infinite;"></div>
|
|
291
|
-
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out 0.4s infinite;"></div>
|
|
292
|
-
</div>
|
|
293
|
-
</div>
|
|
294
|
-
`;
|
|
295
|
-
return overlay;
|
|
296
|
-
}
|
|
297
|
-
function showProductLoading(container, text = "Generating virtual try-on...") {
|
|
298
|
-
const existingOverlay = container.querySelector(".ww-loading-overlay");
|
|
299
|
-
if (existingOverlay) {
|
|
300
|
-
const textElement = existingOverlay.querySelector('div[style*="font-size: 17px"]');
|
|
301
|
-
if (textElement) {
|
|
302
|
-
textElement.textContent = text;
|
|
155
|
+
class ModalManager {
|
|
156
|
+
constructor(baseUrl) {
|
|
157
|
+
this.modalElement = null;
|
|
158
|
+
this.pendingModalPrefill = null;
|
|
159
|
+
this.modalOrigin = new URL(baseUrl).origin;
|
|
160
|
+
}
|
|
161
|
+
open(url, options, onClose) {
|
|
162
|
+
this.close();
|
|
163
|
+
this.pendingModalPrefill = (options === null || options === void 0 ? void 0 : options.prefillImage)
|
|
164
|
+
? {
|
|
165
|
+
image: options.prefillImage,
|
|
166
|
+
autoSubmit: options.autoSubmit === true,
|
|
167
|
+
}
|
|
168
|
+
: null;
|
|
169
|
+
const modal = document.createElement("div");
|
|
170
|
+
modal.className = CSS_CLASSES.MODAL;
|
|
171
|
+
modal.style.cssText = `
|
|
172
|
+
position: fixed;
|
|
173
|
+
top: 0;
|
|
174
|
+
left: 0;
|
|
175
|
+
right: 0;
|
|
176
|
+
bottom: 0;
|
|
177
|
+
width: 100%;
|
|
178
|
+
height: 100%;
|
|
179
|
+
background-color: rgba(0, 0, 0, 0.8);
|
|
180
|
+
display: flex;
|
|
181
|
+
justify-content: center;
|
|
182
|
+
align-items: center;
|
|
183
|
+
z-index: 999999999;
|
|
184
|
+
animation: ww-modal-fade-in 0.3s ease;
|
|
185
|
+
`;
|
|
186
|
+
if (!document.getElementById("ww-modal-animation")) {
|
|
187
|
+
const style = document.createElement("style");
|
|
188
|
+
style.id = "ww-modal-animation";
|
|
189
|
+
style.textContent = `
|
|
190
|
+
@keyframes ww-modal-fade-in {
|
|
191
|
+
from { opacity: 0; }
|
|
192
|
+
to { opacity: 1; }
|
|
193
|
+
}
|
|
194
|
+
@keyframes ww-modal-scale-in {
|
|
195
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
196
|
+
to { transform: scale(1); opacity: 1; }
|
|
197
|
+
}
|
|
198
|
+
`;
|
|
199
|
+
document.head.appendChild(style);
|
|
303
200
|
}
|
|
304
|
-
|
|
201
|
+
const iframeContainer = document.createElement("div");
|
|
202
|
+
iframeContainer.style.cssText = `
|
|
203
|
+
position: relative;
|
|
204
|
+
width: 90%;
|
|
205
|
+
height: 90%;
|
|
206
|
+
max-width: 480px;
|
|
207
|
+
max-height: 720px;
|
|
208
|
+
border-radius: 20px;
|
|
209
|
+
overflow: hidden;
|
|
210
|
+
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3), 0 12px 24px rgba(0, 0, 0, 0.2);
|
|
211
|
+
animation: ww-modal-scale-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
212
|
+
background: white;
|
|
213
|
+
`;
|
|
214
|
+
const iframe = document.createElement("iframe");
|
|
215
|
+
iframe.src = url;
|
|
216
|
+
iframe.style.cssText = `
|
|
217
|
+
width: 100%;
|
|
218
|
+
height: 100%;
|
|
219
|
+
border: none;
|
|
220
|
+
`;
|
|
221
|
+
const closeButton = document.createElement("button");
|
|
222
|
+
closeButton.innerHTML = `
|
|
223
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
224
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
225
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
226
|
+
</svg>
|
|
227
|
+
`;
|
|
228
|
+
closeButton.setAttribute("aria-label", "Close modal");
|
|
229
|
+
closeButton.style.cssText = `
|
|
230
|
+
position: absolute;
|
|
231
|
+
top: -48px;
|
|
232
|
+
right: 0;
|
|
233
|
+
background: rgba(255, 255, 255, 0.95);
|
|
234
|
+
backdrop-filter: blur(8px);
|
|
235
|
+
-webkit-backdrop-filter: blur(8px);
|
|
236
|
+
border: none;
|
|
237
|
+
border-radius: 50%;
|
|
238
|
+
width: 40px;
|
|
239
|
+
height: 40px;
|
|
240
|
+
cursor: pointer;
|
|
241
|
+
display: flex;
|
|
242
|
+
align-items: center;
|
|
243
|
+
justify-content: center;
|
|
244
|
+
color: #1f2937;
|
|
245
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
246
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
247
|
+
`;
|
|
248
|
+
closeButton.onmouseover = () => {
|
|
249
|
+
closeButton.style.transform = "scale(1.1) rotate(90deg)";
|
|
250
|
+
closeButton.style.background = "#ef4444";
|
|
251
|
+
closeButton.style.color = "white";
|
|
252
|
+
};
|
|
253
|
+
closeButton.onmouseout = () => {
|
|
254
|
+
closeButton.style.transform = "scale(1) rotate(0deg)";
|
|
255
|
+
closeButton.style.background = "rgba(255, 255, 255, 0.95)";
|
|
256
|
+
closeButton.style.color = "#1f2937";
|
|
257
|
+
};
|
|
258
|
+
closeButton.onclick = () => {
|
|
259
|
+
modal.style.opacity = "0";
|
|
260
|
+
iframeContainer.style.transform = "scale(0.95)";
|
|
261
|
+
iframeContainer.style.opacity = "0";
|
|
262
|
+
setTimeout(onClose, 300);
|
|
263
|
+
};
|
|
264
|
+
iframeContainer.appendChild(iframe);
|
|
265
|
+
iframeContainer.appendChild(closeButton);
|
|
266
|
+
modal.appendChild(iframeContainer);
|
|
267
|
+
document.body.appendChild(modal);
|
|
268
|
+
modal.onclick = (e) => {
|
|
269
|
+
if (e.target === modal) {
|
|
270
|
+
closeButton.click();
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
this.modalElement = modal;
|
|
305
274
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
275
|
+
close() {
|
|
276
|
+
if (this.modalElement) {
|
|
277
|
+
this.modalElement.remove();
|
|
278
|
+
this.modalElement = null;
|
|
279
|
+
}
|
|
280
|
+
this.pendingModalPrefill = null;
|
|
309
281
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
282
|
+
sendPendingPrefillToModal() {
|
|
283
|
+
if (!this.pendingModalPrefill || !this.modalElement) {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const iframe = this.modalElement.querySelector("iframe");
|
|
287
|
+
if (!(iframe instanceof HTMLIFrameElement) || !iframe.contentWindow) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
iframe.contentWindow.postMessage({
|
|
291
|
+
type: "VTO_PREFILL_IMAGE",
|
|
292
|
+
image: this.pendingModalPrefill.image,
|
|
293
|
+
autoSubmit: this.pendingModalPrefill.autoSubmit,
|
|
294
|
+
}, this.modalOrigin);
|
|
295
|
+
this.pendingModalPrefill = null;
|
|
296
|
+
}
|
|
297
|
+
postMessageToModal(type) {
|
|
298
|
+
if (!this.modalElement) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const iframe = this.modalElement.querySelector("iframe");
|
|
302
|
+
if (!(iframe instanceof HTMLIFrameElement) || !iframe.contentWindow) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
iframe.contentWindow.postMessage({ type }, this.modalOrigin);
|
|
317
306
|
}
|
|
318
307
|
}
|
|
319
308
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
gap: 10px;
|
|
342
|
-
animation: ww-badge-fade-in 0.3s ease;
|
|
343
|
-
letter-spacing: 0.3px;
|
|
344
|
-
`;
|
|
345
|
-
if (!document.getElementById("ww-status-badge-animation")) {
|
|
346
|
-
const style = document.createElement("style");
|
|
347
|
-
style.id = "ww-status-badge-animation";
|
|
348
|
-
style.textContent = `
|
|
349
|
-
@keyframes ww-badge-fade-in {
|
|
350
|
-
from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
|
|
351
|
-
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
@keyframes ww-badge-pulse {
|
|
355
|
-
0%, 100% { opacity: 0.6; }
|
|
356
|
-
50% { opacity: 1; }
|
|
357
|
-
}
|
|
358
|
-
`;
|
|
359
|
-
document.head.appendChild(style);
|
|
360
|
-
}
|
|
361
|
-
badge.innerHTML = `
|
|
362
|
-
<div style="display: flex; gap: 4px;">
|
|
363
|
-
<div style="width: 6px; height: 6px; border-radius: 50%; background: white; animation: ww-badge-pulse 1.4s ease-in-out infinite;"></div>
|
|
364
|
-
<div style="width: 6px; height: 6px; border-radius: 50%; background: white; animation: ww-badge-pulse 1.4s ease-in-out 0.2s infinite;"></div>
|
|
365
|
-
<div style="width: 6px; height: 6px; border-radius: 50%; background: white; animation: ww-badge-pulse 1.4s ease-in-out 0.4s infinite;"></div>
|
|
366
|
-
</div>
|
|
367
|
-
<span>${message}</span>
|
|
368
|
-
`;
|
|
369
|
-
return badge;
|
|
370
|
-
}
|
|
371
|
-
function showStatusBadge(container, message) {
|
|
372
|
-
const existingBadge = container.querySelector(".ww-status-badge");
|
|
373
|
-
if (existingBadge) {
|
|
374
|
-
const textElement = existingBadge.querySelector("span");
|
|
375
|
-
if (textElement) {
|
|
376
|
-
textElement.textContent = message;
|
|
309
|
+
class VtoApiClient {
|
|
310
|
+
constructor(baseUrl) {
|
|
311
|
+
this.baseUrl = baseUrl;
|
|
312
|
+
}
|
|
313
|
+
async fetchVtoData(outfitId) {
|
|
314
|
+
try {
|
|
315
|
+
const vtoDataUrl = new URL("/api/vto/data", this.baseUrl);
|
|
316
|
+
vtoDataUrl.searchParams.set("outfit_id", outfitId);
|
|
317
|
+
const response = await fetch(vtoDataUrl.toString());
|
|
318
|
+
if (response.status === 404)
|
|
319
|
+
return null;
|
|
320
|
+
if (!response.ok) {
|
|
321
|
+
const errorText = await response.text();
|
|
322
|
+
console.warn(`[WeWear VTO] Failed to retrieve VTO data (${response.status}): ${errorText}`);
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return (await response.json());
|
|
326
|
+
}
|
|
327
|
+
catch (error) {
|
|
328
|
+
console.warn("[WeWear VTO] Error retrieving VTO data:", error);
|
|
329
|
+
return null;
|
|
377
330
|
}
|
|
378
|
-
return;
|
|
379
331
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
332
|
+
async submitTryOn(modelImage, productImages, options) {
|
|
333
|
+
var _a;
|
|
334
|
+
const outfitID = (_a = options.outfitID) === null || _a === void 0 ? void 0 : _a.trim();
|
|
335
|
+
let resolvedProductImages = productImages;
|
|
336
|
+
let resolvedGeminiModel = null;
|
|
337
|
+
let resolvedAdditionalPrompt = null;
|
|
338
|
+
if (outfitID) {
|
|
339
|
+
const vtoData = await this.fetchVtoData(outfitID);
|
|
340
|
+
if (vtoData) {
|
|
341
|
+
if (Array.isArray(vtoData.images) && vtoData.images.length > 0) {
|
|
342
|
+
resolvedProductImages = vtoData.images;
|
|
343
|
+
}
|
|
344
|
+
if (typeof vtoData.gemini_model === "string" && vtoData.gemini_model) {
|
|
345
|
+
resolvedGeminiModel = vtoData.gemini_model;
|
|
346
|
+
}
|
|
347
|
+
if (typeof vtoData.additional_prompt === "string" &&
|
|
348
|
+
vtoData.additional_prompt) {
|
|
349
|
+
resolvedAdditionalPrompt = vtoData.additional_prompt;
|
|
350
|
+
}
|
|
351
|
+
console.log(`[WeWear VTO] Using stored VTO data for outfit_id=${outfitID}`);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
const formData = new FormData();
|
|
355
|
+
formData.append("model_image", modelImage, "model_image.png");
|
|
356
|
+
formData.append("product_image_urls", JSON.stringify(resolvedProductImages));
|
|
357
|
+
formData.append("page_url", window.location.href);
|
|
358
|
+
formData.append("model_tier", options.modelTier);
|
|
359
|
+
if (resolvedGeminiModel)
|
|
360
|
+
formData.append("gemini_model", resolvedGeminiModel);
|
|
361
|
+
if (resolvedAdditionalPrompt) {
|
|
362
|
+
formData.append("additional_prompt", resolvedAdditionalPrompt);
|
|
363
|
+
}
|
|
364
|
+
if (outfitID)
|
|
365
|
+
formData.append("outfit_id", outfitID);
|
|
366
|
+
const res = await fetch(`${this.baseUrl}/api/vto`, {
|
|
367
|
+
method: "POST",
|
|
368
|
+
body: formData,
|
|
369
|
+
});
|
|
370
|
+
if (!res.ok) {
|
|
371
|
+
const errorText = await res.text();
|
|
372
|
+
console.error("[WeWear VTO] API submission failed:", res.status, errorText);
|
|
373
|
+
throw new Error(`API submission failed: ${res.status}`);
|
|
374
|
+
}
|
|
375
|
+
return res.json();
|
|
376
|
+
}
|
|
377
|
+
async fetchJobStatus(jobId) {
|
|
378
|
+
const res = await fetch(`${this.baseUrl}/api/vto/status?job_id=${jobId}`);
|
|
379
|
+
if (!res.ok)
|
|
380
|
+
throw new Error(`Status check failed: ${res.status}`);
|
|
381
|
+
return res.json();
|
|
382
|
+
}
|
|
383
|
+
async fetchJobImage(jobId) {
|
|
384
|
+
const url = `${this.baseUrl}/api/vto/image?job_id=${jobId}`;
|
|
385
|
+
const res = await fetch(url);
|
|
386
|
+
if (res.status === 202)
|
|
387
|
+
throw new Error("202_PROCESSING");
|
|
388
|
+
if (!res.ok)
|
|
389
|
+
throw new Error(`Image fetch failed: ${res.status}`);
|
|
390
|
+
const blob = await res.blob();
|
|
391
|
+
return URL.createObjectURL(blob);
|
|
387
392
|
}
|
|
388
393
|
}
|
|
389
394
|
|
|
390
395
|
class VirtualTryOnWidget {
|
|
391
396
|
constructor(config) {
|
|
392
397
|
this.virtualTryOnImageUrl = null;
|
|
393
|
-
this.originalProductImageUrl = null;
|
|
394
398
|
this.originalProductImages = []; // Store all original product images
|
|
395
399
|
this.isShowingVirtualTryOn = false;
|
|
396
400
|
this.lastModelImage = null;
|
|
397
401
|
this.cameraButton = null;
|
|
398
|
-
this.modalElement = null;
|
|
399
402
|
this.iframeMessageListener = null;
|
|
400
403
|
this.instanceId = ++VirtualTryOnWidget.instanceCounter;
|
|
401
404
|
this.config = {
|
|
@@ -409,6 +412,8 @@
|
|
|
409
412
|
singleton: config.singleton,
|
|
410
413
|
galleryElement: config.galleryElement,
|
|
411
414
|
};
|
|
415
|
+
this.modal = new ModalManager(this.config.baseUrl);
|
|
416
|
+
this.vtoApiClient = new VtoApiClient(this.config.baseUrl);
|
|
412
417
|
}
|
|
413
418
|
getContainer() {
|
|
414
419
|
const configContainer = this.config.galleryElement;
|
|
@@ -462,17 +467,40 @@
|
|
|
462
467
|
console.warn("[WeWear VTO] Product images not found:", this.config.productImageSelector);
|
|
463
468
|
return;
|
|
464
469
|
}
|
|
465
|
-
|
|
466
|
-
this.originalProductImageUrl = this.originalProductImages[0];
|
|
467
|
-
}
|
|
468
|
-
const photoUploadUrl = new URL(`${this.config.baseUrl}`);
|
|
469
|
-
photoUploadUrl.searchParams.append("ww_product_images", this.originalProductImages.join(","));
|
|
470
|
+
const photoUploadUrl = this.buildPhotoUploadUrl();
|
|
470
471
|
this.showPhotoUploadModal(photoUploadUrl.toString());
|
|
471
472
|
}
|
|
472
473
|
catch (error) {
|
|
473
474
|
console.error("[WeWear VTO] Try-on request failed:", error);
|
|
474
475
|
}
|
|
475
476
|
}
|
|
477
|
+
async handleRegenerateClick() {
|
|
478
|
+
if (!this.lastModelImage) {
|
|
479
|
+
await this.handleTryOnClick();
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
if (this.originalProductImages.length === 0) {
|
|
483
|
+
this.originalProductImages = this.getAllProductImages();
|
|
484
|
+
}
|
|
485
|
+
if (this.originalProductImages.length === 0) {
|
|
486
|
+
console.warn("[WeWear VTO] No product images found for regenerate.");
|
|
487
|
+
return;
|
|
488
|
+
}
|
|
489
|
+
const photoUploadUrl = this.buildPhotoUploadUrl({ startAtConfirm: true });
|
|
490
|
+
this.showPhotoUploadModal(photoUploadUrl.toString(), {
|
|
491
|
+
prefillImage: this.lastModelImage,
|
|
492
|
+
autoSubmit: true,
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
buildPhotoUploadUrl(options) {
|
|
496
|
+
const photoUploadUrl = new URL(`${this.config.baseUrl}`);
|
|
497
|
+
photoUploadUrl.searchParams.append("ww_product_images", this.originalProductImages.join(","));
|
|
498
|
+
if (options === null || options === void 0 ? void 0 : options.startAtConfirm) {
|
|
499
|
+
photoUploadUrl.searchParams.append("ww_step", "2");
|
|
500
|
+
photoUploadUrl.searchParams.append("ww_regenerate", "1");
|
|
501
|
+
}
|
|
502
|
+
return photoUploadUrl;
|
|
503
|
+
}
|
|
476
504
|
getAllProductImages() {
|
|
477
505
|
const container = this.getContainer();
|
|
478
506
|
const scopedElements = container === null || container === void 0 ? void 0 : container.querySelectorAll(this.config.productImageSelector);
|
|
@@ -492,124 +520,23 @@
|
|
|
492
520
|
});
|
|
493
521
|
return images;
|
|
494
522
|
}
|
|
495
|
-
showPhotoUploadModal(url) {
|
|
523
|
+
showPhotoUploadModal(url, options) {
|
|
496
524
|
this.closeModal();
|
|
497
525
|
VirtualTryOnWidget.activeWidgetId = this.instanceId;
|
|
498
|
-
|
|
499
|
-
modal.className = CSS_CLASSES.MODAL;
|
|
500
|
-
modal.style.cssText = `
|
|
501
|
-
position: fixed;
|
|
502
|
-
top: 0;
|
|
503
|
-
left: 0;
|
|
504
|
-
right: 0;
|
|
505
|
-
bottom: 0;
|
|
506
|
-
width: 100%;
|
|
507
|
-
height: 100%;
|
|
508
|
-
background-color: rgba(0, 0, 0, 0.8);
|
|
509
|
-
display: flex;
|
|
510
|
-
justify-content: center;
|
|
511
|
-
align-items: center;
|
|
512
|
-
z-index: 999999999;
|
|
513
|
-
animation: ww-modal-fade-in 0.3s ease;
|
|
514
|
-
`;
|
|
515
|
-
if (!document.getElementById("ww-modal-animation")) {
|
|
516
|
-
const style = document.createElement("style");
|
|
517
|
-
style.id = "ww-modal-animation";
|
|
518
|
-
style.textContent = `
|
|
519
|
-
@keyframes ww-modal-fade-in {
|
|
520
|
-
from { opacity: 0; }
|
|
521
|
-
to { opacity: 1; }
|
|
522
|
-
}
|
|
523
|
-
@keyframes ww-modal-scale-in {
|
|
524
|
-
from { transform: scale(0.95); opacity: 0; }
|
|
525
|
-
to { transform: scale(1); opacity: 1; }
|
|
526
|
-
}
|
|
527
|
-
`;
|
|
528
|
-
document.head.appendChild(style);
|
|
529
|
-
}
|
|
530
|
-
const iframeContainer = document.createElement("div");
|
|
531
|
-
iframeContainer.style.cssText = `
|
|
532
|
-
position: relative;
|
|
533
|
-
width: 90%;
|
|
534
|
-
height: 90%;
|
|
535
|
-
max-width: 480px;
|
|
536
|
-
max-height: 720px;
|
|
537
|
-
border-radius: 20px;
|
|
538
|
-
overflow: hidden;
|
|
539
|
-
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3), 0 12px 24px rgba(0, 0, 0, 0.2);
|
|
540
|
-
animation: ww-modal-scale-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
541
|
-
background: white;
|
|
542
|
-
`;
|
|
543
|
-
const iframe = document.createElement("iframe");
|
|
544
|
-
iframe.src = url;
|
|
545
|
-
iframe.style.cssText = `
|
|
546
|
-
width: 100%;
|
|
547
|
-
height: 100%;
|
|
548
|
-
border: none;
|
|
549
|
-
`;
|
|
550
|
-
const closeButton = document.createElement("button");
|
|
551
|
-
closeButton.innerHTML = `
|
|
552
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
553
|
-
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
554
|
-
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
555
|
-
</svg>
|
|
556
|
-
`;
|
|
557
|
-
closeButton.setAttribute("aria-label", "Close modal");
|
|
558
|
-
closeButton.style.cssText = `
|
|
559
|
-
position: absolute;
|
|
560
|
-
top: -48px;
|
|
561
|
-
right: 0;
|
|
562
|
-
background: rgba(255, 255, 255, 0.95);
|
|
563
|
-
backdrop-filter: blur(8px);
|
|
564
|
-
-webkit-backdrop-filter: blur(8px);
|
|
565
|
-
border: none;
|
|
566
|
-
border-radius: 50%;
|
|
567
|
-
width: 40px;
|
|
568
|
-
height: 40px;
|
|
569
|
-
cursor: pointer;
|
|
570
|
-
display: flex;
|
|
571
|
-
align-items: center;
|
|
572
|
-
justify-content: center;
|
|
573
|
-
color: #1f2937;
|
|
574
|
-
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
575
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
576
|
-
`;
|
|
577
|
-
closeButton.onmouseover = () => {
|
|
578
|
-
closeButton.style.transform = "scale(1.1) rotate(90deg)";
|
|
579
|
-
closeButton.style.background = "#ef4444";
|
|
580
|
-
closeButton.style.color = "white";
|
|
581
|
-
};
|
|
582
|
-
closeButton.onmouseout = () => {
|
|
583
|
-
closeButton.style.transform = "scale(1) rotate(0deg)";
|
|
584
|
-
closeButton.style.background = "rgba(255, 255, 255, 0.95)";
|
|
585
|
-
closeButton.style.color = "#1f2937";
|
|
586
|
-
};
|
|
587
|
-
closeButton.onclick = () => {
|
|
588
|
-
modal.style.opacity = "0";
|
|
589
|
-
iframeContainer.style.transform = "scale(0.95)";
|
|
590
|
-
iframeContainer.style.opacity = "0";
|
|
591
|
-
setTimeout(() => this.closeModal(), 300);
|
|
592
|
-
};
|
|
593
|
-
iframeContainer.appendChild(iframe);
|
|
594
|
-
iframeContainer.appendChild(closeButton);
|
|
595
|
-
modal.appendChild(iframeContainer);
|
|
596
|
-
document.body.appendChild(modal);
|
|
597
|
-
modal.onclick = (e) => {
|
|
598
|
-
if (e.target === modal) {
|
|
599
|
-
closeButton.click();
|
|
600
|
-
}
|
|
601
|
-
};
|
|
602
|
-
this.modalElement = modal;
|
|
526
|
+
this.modal.open(url, options, () => this.closeModal());
|
|
603
527
|
}
|
|
604
528
|
closeModal() {
|
|
605
|
-
|
|
606
|
-
this.modalElement.remove();
|
|
607
|
-
this.modalElement = null;
|
|
608
|
-
}
|
|
529
|
+
this.modal.close();
|
|
609
530
|
if (VirtualTryOnWidget.activeWidgetId === this.instanceId) {
|
|
610
531
|
VirtualTryOnWidget.activeWidgetId = null;
|
|
611
532
|
}
|
|
612
533
|
}
|
|
534
|
+
sendPendingPrefillToModal() {
|
|
535
|
+
this.modal.sendPendingPrefillToModal();
|
|
536
|
+
}
|
|
537
|
+
postMessageToModal(type) {
|
|
538
|
+
this.modal.postMessageToModal(type);
|
|
539
|
+
}
|
|
613
540
|
setupIframeListener() {
|
|
614
541
|
if (this.iframeMessageListener) {
|
|
615
542
|
window.removeEventListener("message", this.iframeMessageListener);
|
|
@@ -622,9 +549,13 @@
|
|
|
622
549
|
return;
|
|
623
550
|
}
|
|
624
551
|
switch (event.data.type) {
|
|
552
|
+
case "VTO_CONFIRM_READY":
|
|
553
|
+
this.sendPendingPrefillToModal();
|
|
554
|
+
break;
|
|
625
555
|
case "VTO_IMAGE_SELECTED":
|
|
626
556
|
if (event.data.image) {
|
|
627
557
|
this.lastModelImage = event.data.image;
|
|
558
|
+
this.postMessageToModal("VTO_SCAN_START");
|
|
628
559
|
this.startVirtualTryOn();
|
|
629
560
|
}
|
|
630
561
|
break;
|
|
@@ -650,142 +581,45 @@
|
|
|
650
581
|
console.warn("[WeWear VTO] No product images found.");
|
|
651
582
|
return;
|
|
652
583
|
}
|
|
653
|
-
const modal = document.querySelector(`.${CSS_CLASSES.MODAL}`);
|
|
654
|
-
if (modal && modal instanceof HTMLElement) {
|
|
655
|
-
modal.style.display = "none";
|
|
656
|
-
}
|
|
657
584
|
const container = this.getContainer();
|
|
658
|
-
if (container) {
|
|
659
|
-
showProductLoading(container, "Preparing your personalized look");
|
|
660
|
-
}
|
|
661
585
|
try {
|
|
662
|
-
const submitResponse = await this.
|
|
663
|
-
|
|
586
|
+
const submitResponse = await this.vtoApiClient.submitTryOn(this.lastModelImage, this.originalProductImages, {
|
|
587
|
+
modelTier: this.config.modelTier,
|
|
588
|
+
outfitID: this.config.outfitID,
|
|
589
|
+
});
|
|
590
|
+
let status = await this.vtoApiClient.fetchJobStatus(submitResponse.job_id);
|
|
664
591
|
while (status.status !== "COMPLETED" && status.status !== "FAILED") {
|
|
665
|
-
if (container instanceof HTMLElement) {
|
|
666
|
-
const statusMessage = "Preparing your personalized look";
|
|
667
|
-
showProductLoading(container, statusMessage);
|
|
668
|
-
}
|
|
669
592
|
await new Promise((r) => setTimeout(r, 3000));
|
|
670
|
-
status = await this.fetchJobStatus(submitResponse.job_id);
|
|
593
|
+
status = await this.vtoApiClient.fetchJobStatus(submitResponse.job_id);
|
|
671
594
|
}
|
|
672
595
|
if (status.status === "COMPLETED") {
|
|
673
|
-
const finalImage = await this.fetchJobImage(submitResponse.job_id);
|
|
596
|
+
const finalImage = await this.vtoApiClient.fetchJobImage(submitResponse.job_id);
|
|
674
597
|
if (finalImage) {
|
|
598
|
+
this.postMessageToModal("VTO_SCAN_COMPLETE");
|
|
599
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
675
600
|
this.replaceProductImage(finalImage);
|
|
676
601
|
}
|
|
677
602
|
if (container instanceof HTMLElement) {
|
|
678
|
-
removeStatusBadge(container);
|
|
679
603
|
this.showButtonContainer(container);
|
|
680
604
|
}
|
|
681
605
|
}
|
|
682
606
|
if (status.status === "FAILED") {
|
|
683
607
|
console.error("[WeWear VTO] VTO process failed:", status.message);
|
|
684
|
-
if (container instanceof HTMLElement) {
|
|
685
|
-
showStatusBadge(container, "We are experiencing some technical issues and apologise for any inconvenience caused. Please come back later again");
|
|
686
|
-
}
|
|
687
608
|
await new Promise((r) => setTimeout(r, 5000));
|
|
688
609
|
}
|
|
689
610
|
}
|
|
690
611
|
catch (error) {
|
|
691
612
|
console.error("[WeWear VTO] Error during virtual try-on process:", error);
|
|
692
|
-
if (container instanceof HTMLElement) {
|
|
693
|
-
showProductLoading(container, "We are experiencing technical issues and apologise for any inconvenience caused. Please come back later again");
|
|
694
|
-
}
|
|
695
613
|
await new Promise((r) => setTimeout(r, 5000));
|
|
696
614
|
}
|
|
697
615
|
finally {
|
|
616
|
+
this.postMessageToModal("VTO_SCAN_STOP");
|
|
698
617
|
if (container instanceof HTMLElement) {
|
|
699
|
-
removeProductLoading(container);
|
|
700
|
-
removeStatusBadge(container);
|
|
701
618
|
this.showButtonContainer(container);
|
|
702
619
|
}
|
|
703
620
|
this.closeModal();
|
|
704
621
|
}
|
|
705
622
|
}
|
|
706
|
-
async fetchVtoData(outfitId) {
|
|
707
|
-
try {
|
|
708
|
-
const vtoDataUrl = new URL("/api/vto/data", this.config.baseUrl);
|
|
709
|
-
vtoDataUrl.searchParams.set("outfit_id", outfitId);
|
|
710
|
-
const response = await fetch(vtoDataUrl.toString());
|
|
711
|
-
if (response.status === 404)
|
|
712
|
-
return null;
|
|
713
|
-
if (!response.ok) {
|
|
714
|
-
const errorText = await response.text();
|
|
715
|
-
console.warn(`[WeWear VTO] Failed to retrieve VTO data (${response.status}): ${errorText}`);
|
|
716
|
-
return null;
|
|
717
|
-
}
|
|
718
|
-
return (await response.json());
|
|
719
|
-
}
|
|
720
|
-
catch (error) {
|
|
721
|
-
console.warn("[WeWear VTO] Error retrieving VTO data:", error);
|
|
722
|
-
return null;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
async callVtoApi(modelImage, productImages) {
|
|
726
|
-
var _a;
|
|
727
|
-
const outfitID = (_a = this.config.outfitID) === null || _a === void 0 ? void 0 : _a.trim();
|
|
728
|
-
let resolvedProductImages = productImages;
|
|
729
|
-
let resolvedGeminiModel = null;
|
|
730
|
-
let resolvedAdditionalPrompt = null;
|
|
731
|
-
if (outfitID) {
|
|
732
|
-
const vtoData = await this.fetchVtoData(outfitID);
|
|
733
|
-
if (vtoData) {
|
|
734
|
-
if (Array.isArray(vtoData.images) && vtoData.images.length > 0) {
|
|
735
|
-
resolvedProductImages = vtoData.images;
|
|
736
|
-
}
|
|
737
|
-
if (typeof vtoData.gemini_model === "string" && vtoData.gemini_model) {
|
|
738
|
-
resolvedGeminiModel = vtoData.gemini_model;
|
|
739
|
-
}
|
|
740
|
-
if (typeof vtoData.additional_prompt === "string" &&
|
|
741
|
-
vtoData.additional_prompt) {
|
|
742
|
-
resolvedAdditionalPrompt = vtoData.additional_prompt;
|
|
743
|
-
}
|
|
744
|
-
console.log(`[WeWear VTO] Using stored VTO data for outfit_id=${outfitID}`);
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
const formData = new FormData();
|
|
748
|
-
formData.append("model_image", modelImage, "model_image.png");
|
|
749
|
-
formData.append("product_image_urls", JSON.stringify(resolvedProductImages));
|
|
750
|
-
formData.append("page_url", window.location.href);
|
|
751
|
-
formData.append("model_tier", this.config.modelTier);
|
|
752
|
-
if (resolvedGeminiModel)
|
|
753
|
-
formData.append("gemini_model", resolvedGeminiModel);
|
|
754
|
-
if (resolvedAdditionalPrompt) {
|
|
755
|
-
formData.append("additional_prompt", resolvedAdditionalPrompt);
|
|
756
|
-
}
|
|
757
|
-
if (outfitID)
|
|
758
|
-
formData.append("outfit_id", outfitID);
|
|
759
|
-
const res = await fetch(`${this.config.baseUrl}/api/vto`, {
|
|
760
|
-
method: "POST",
|
|
761
|
-
body: formData,
|
|
762
|
-
});
|
|
763
|
-
if (!res.ok) {
|
|
764
|
-
const errorText = await res.text();
|
|
765
|
-
console.error("[WeWear VTO] API submission failed:", res.status, errorText);
|
|
766
|
-
throw new Error(`API submission failed: ${res.status}`);
|
|
767
|
-
}
|
|
768
|
-
return res.json();
|
|
769
|
-
}
|
|
770
|
-
async fetchJobStatus(jobId) {
|
|
771
|
-
const res = await fetch(`${this.config.baseUrl}/api/vto/status?job_id=${jobId}`);
|
|
772
|
-
if (!res.ok)
|
|
773
|
-
throw new Error(`Status check failed: ${res.status}`);
|
|
774
|
-
return res.json();
|
|
775
|
-
}
|
|
776
|
-
async fetchJobImage(jobId) {
|
|
777
|
-
const url = `${this.config.baseUrl}/api/vto/image?job_id=${jobId}`;
|
|
778
|
-
const res = await fetch(url);
|
|
779
|
-
if (res.status === 202)
|
|
780
|
-
throw new Error("202_PROCESSING");
|
|
781
|
-
if (!res.ok)
|
|
782
|
-
throw new Error(`Image fetch failed: ${res.status}`);
|
|
783
|
-
const blob = await res.blob();
|
|
784
|
-
return URL.createObjectURL(blob);
|
|
785
|
-
}
|
|
786
|
-
async refreshVirtualTryOn() {
|
|
787
|
-
await this.startVirtualTryOn(true);
|
|
788
|
-
}
|
|
789
623
|
replaceProductImage(imageUrl) {
|
|
790
624
|
try {
|
|
791
625
|
this.virtualTryOnImageUrl = imageUrl;
|
|
@@ -841,7 +675,7 @@
|
|
|
841
675
|
const buttonContainer = createButtonContainer(this.config.buttonPosition, this.virtualTryOnImageUrl !== null, async () => {
|
|
842
676
|
await this.handleTryOnClick();
|
|
843
677
|
}, async () => {
|
|
844
|
-
await this.
|
|
678
|
+
await this.handleRegenerateClick();
|
|
845
679
|
}, () => {
|
|
846
680
|
if (this.isShowingVirtualTryOn) {
|
|
847
681
|
this.showOriginalImage(container);
|
|
@@ -849,7 +683,6 @@
|
|
|
849
683
|
else {
|
|
850
684
|
this.showVirtualTryOnImage(container);
|
|
851
685
|
}
|
|
852
|
-
removeProductLoading(container);
|
|
853
686
|
this.updateButtonContainer(container);
|
|
854
687
|
}, this.isShowingVirtualTryOn);
|
|
855
688
|
container.appendChild(buttonContainer);
|
|
@@ -931,7 +764,6 @@
|
|
|
931
764
|
this.virtualTryOnImageUrl = null;
|
|
932
765
|
this.isShowingVirtualTryOn = false;
|
|
933
766
|
this.lastModelImage = null;
|
|
934
|
-
this.originalProductImageUrl = null;
|
|
935
767
|
this.originalProductImages = [];
|
|
936
768
|
console.log("[WeWear VTO] Widget destroyed successfully");
|
|
937
769
|
}
|