@wewear/virtual-try-on 1.4.29 → 2.0.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/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
- position: absolute;
36
- ${positionStyles}
37
- display: flex;
38
- gap: 4px;
39
- border-radius: 100px;
40
- background: white;
41
- padding: 4px;
42
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
43
- z-index: ${Z_INDEX.BUTTON};
44
- transition: all 0.2s ease;
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 = document.createElement("button");
106
- refreshButton.type = "button";
107
- refreshButton.className = "ww-refresh-btn";
108
- refreshButton.setAttribute("aria-label", "Refresh virtual try-on");
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 = document.createElement("button");
138
- toggleButton.type = "button";
139
- toggleButton.className = "ww-toggle-btn";
140
- toggleButton.setAttribute("aria-label", isShowingVirtualTryOn ? "Show Original Image" : "Show Virtual Try-On");
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
- function createLoadingOverlay(text = "Processing...") {
201
- const overlay = document.createElement("div");
202
- overlay.className = "ww-loading-overlay";
203
- overlay.style.cssText = `
204
- position: absolute;
205
- top: 0;
206
- left: 0;
207
- width: 100%;
208
- height: 100%;
209
- background: linear-gradient(135deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.88) 100%);
210
- backdrop-filter: blur(8px);
211
- -webkit-backdrop-filter: blur(8px);
212
- display: flex;
213
- flex-direction: column;
214
- align-items: center;
215
- justify-content: center;
216
- z-index: ${Z_INDEX.MODAL + 1};
217
- border-radius: inherit;
218
- animation: ww-fade-in 0.3s ease;
219
- `;
220
- if (!document.getElementById("ww-loading-animation")) {
221
- const style = document.createElement("style");
222
- style.id = "ww-loading-animation";
223
- style.textContent = `
224
- @keyframes ww-fade-in {
225
- from { opacity: 0; }
226
- to { opacity: 1; }
227
- }
228
-
229
- @keyframes ww-pulse-logo {
230
- 0%, 100% {
231
- opacity: 0.8;
232
- transform: scale(1);
233
- }
234
- 50% {
235
- opacity: 1;
236
- transform: scale(1.05);
237
- }
238
- }
239
-
240
- @keyframes ww-spinner-rotate {
241
- 0% { transform: rotate(0deg); }
242
- 100% { transform: rotate(360deg); }
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
- return;
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
- const computedStyle = window.getComputedStyle(container);
307
- if (computedStyle.position === "static") {
308
- container.style.position = "relative";
275
+ close() {
276
+ if (this.modalElement) {
277
+ this.modalElement.remove();
278
+ this.modalElement = null;
279
+ }
280
+ this.pendingModalPrefill = null;
309
281
  }
310
- const loadingOverlay = createLoadingOverlay(text);
311
- container.appendChild(loadingOverlay);
312
- }
313
- function removeProductLoading(container) {
314
- const existingOverlay = container.querySelector(".ww-loading-overlay");
315
- if (existingOverlay) {
316
- existingOverlay.remove();
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
- function createStatusBadge(message) {
321
- const badge = document.createElement("div");
322
- badge.className = "ww-status-badge";
323
- badge.style.cssText = `
324
- position: absolute;
325
- bottom: 16px;
326
- left: 50%;
327
- transform: translateX(-50%);
328
- background: linear-gradient(135deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.88) 100%);
329
- backdrop-filter: blur(12px);
330
- -webkit-backdrop-filter: blur(12px);
331
- color: white;
332
- padding: 12px 24px;
333
- border-radius: 24px;
334
- font-size: 14px;
335
- font-weight: 500;
336
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
337
- box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
338
- z-index: 1000;
339
- display: flex;
340
- align-items: center;
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
- const badge = createStatusBadge(message);
381
- container.appendChild(badge);
382
- }
383
- function removeStatusBadge(container) {
384
- const badge = container.querySelector(".ww-status-badge");
385
- if (badge) {
386
- badge.remove();
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
- if (!this.originalProductImageUrl) {
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
- const modal = document.createElement("div");
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
- if (this.modalElement) {
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,144 +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.callVtoApi(this.lastModelImage, this.originalProductImages);
663
- let status = await this.fetchJobStatus(submitResponse.job_id);
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, userBrand) {
707
- try {
708
- const vtoDataUrl = new URL("/api/vto/data", this.config.baseUrl);
709
- vtoDataUrl.searchParams.set("outfit_id", outfitId);
710
- vtoDataUrl.searchParams.set("user_brand", userBrand);
711
- const response = await fetch(vtoDataUrl.toString());
712
- if (response.status === 404)
713
- return null;
714
- if (!response.ok) {
715
- const errorText = await response.text();
716
- console.warn(`[WeWear VTO] Failed to retrieve VTO data (${response.status}): ${errorText}`);
717
- return null;
718
- }
719
- return (await response.json());
720
- }
721
- catch (error) {
722
- console.warn("[WeWear VTO] Error retrieving VTO data:", error);
723
- return null;
724
- }
725
- }
726
- async callVtoApi(modelImage, productImages) {
727
- var _a;
728
- const outfitID = (_a = this.config.outfitID) === null || _a === void 0 ? void 0 : _a.trim();
729
- let resolvedProductImages = productImages;
730
- let resolvedGeminiModel = null;
731
- let resolvedAdditionalPrompt = null;
732
- if (outfitID) {
733
- const userBrand = window.location.href.split("#")[0];
734
- const vtoData = await this.fetchVtoData(outfitID, userBrand);
735
- if (vtoData) {
736
- if (Array.isArray(vtoData.images) && vtoData.images.length > 0) {
737
- resolvedProductImages = vtoData.images;
738
- }
739
- if (typeof vtoData.gemini_model === "string" && vtoData.gemini_model) {
740
- resolvedGeminiModel = vtoData.gemini_model;
741
- }
742
- if (typeof vtoData.additional_prompt === "string" &&
743
- vtoData.additional_prompt) {
744
- resolvedAdditionalPrompt = vtoData.additional_prompt;
745
- }
746
- console.log(`[WeWear VTO] Using stored VTO data for outfit_id=${outfitID}, user_brand=${userBrand}`);
747
- }
748
- }
749
- const formData = new FormData();
750
- formData.append("model_image", modelImage, "model_image.png");
751
- formData.append("product_image_urls", JSON.stringify(resolvedProductImages));
752
- formData.append("page_url", window.location.href);
753
- formData.append("model_tier", this.config.modelTier);
754
- if (resolvedGeminiModel)
755
- formData.append("gemini_model", resolvedGeminiModel);
756
- if (resolvedAdditionalPrompt) {
757
- formData.append("additional_prompt", resolvedAdditionalPrompt);
758
- }
759
- if (outfitID)
760
- formData.append("outfit_id", outfitID);
761
- const res = await fetch(`${this.config.baseUrl}/api/vto`, {
762
- method: "POST",
763
- body: formData,
764
- });
765
- if (!res.ok) {
766
- const errorText = await res.text();
767
- console.error("[WeWear VTO] API submission failed:", res.status, errorText);
768
- throw new Error(`API submission failed: ${res.status}`);
769
- }
770
- return res.json();
771
- }
772
- async fetchJobStatus(jobId) {
773
- const res = await fetch(`${this.config.baseUrl}/api/vto/status?job_id=${jobId}`);
774
- if (!res.ok)
775
- throw new Error(`Status check failed: ${res.status}`);
776
- return res.json();
777
- }
778
- async fetchJobImage(jobId) {
779
- const url = `${this.config.baseUrl}/api/vto/image?job_id=${jobId}`;
780
- const res = await fetch(url);
781
- if (res.status === 202)
782
- throw new Error("202_PROCESSING");
783
- if (!res.ok)
784
- throw new Error(`Image fetch failed: ${res.status}`);
785
- const blob = await res.blob();
786
- return URL.createObjectURL(blob);
787
- }
788
- async refreshVirtualTryOn() {
789
- await this.startVirtualTryOn(true);
790
- }
791
623
  replaceProductImage(imageUrl) {
792
624
  try {
793
625
  this.virtualTryOnImageUrl = imageUrl;
@@ -843,7 +675,7 @@
843
675
  const buttonContainer = createButtonContainer(this.config.buttonPosition, this.virtualTryOnImageUrl !== null, async () => {
844
676
  await this.handleTryOnClick();
845
677
  }, async () => {
846
- await this.refreshVirtualTryOn();
678
+ await this.handleRegenerateClick();
847
679
  }, () => {
848
680
  if (this.isShowingVirtualTryOn) {
849
681
  this.showOriginalImage(container);
@@ -851,7 +683,6 @@
851
683
  else {
852
684
  this.showVirtualTryOnImage(container);
853
685
  }
854
- removeProductLoading(container);
855
686
  this.updateButtonContainer(container);
856
687
  }, this.isShowingVirtualTryOn);
857
688
  container.appendChild(buttonContainer);
@@ -933,7 +764,6 @@
933
764
  this.virtualTryOnImageUrl = null;
934
765
  this.isShowingVirtualTryOn = false;
935
766
  this.lastModelImage = null;
936
- this.originalProductImageUrl = null;
937
767
  this.originalProductImages = [];
938
768
  console.log("[WeWear VTO] Widget destroyed successfully");
939
769
  }