@wewear/virtual-try-on 1.4.2 → 1.4.3
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/camera.d.ts +9 -2
- package/dist/components/camera-modal.d.ts +4 -1
- package/dist/components/review-modal.d.ts +6 -3
- package/dist/index.d.ts +11 -1
- package/dist/index.esm.js +381 -212
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +381 -212
- package/dist/index.js.map +1 -1
- package/dist/widget.d.ts +0 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -19,37 +19,35 @@ function createPreviewBadge() {
|
|
|
19
19
|
if (!document.getElementById(styleId)) {
|
|
20
20
|
const styles = document.createElement("style");
|
|
21
21
|
styles.id = styleId;
|
|
22
|
-
styles.innerHTML = `
|
|
23
|
-
.${CSS_CLASSES.PREVIEW_BADGE} {
|
|
24
|
-
position: absolute;
|
|
25
|
-
top:
|
|
26
|
-
right:
|
|
27
|
-
background
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
}
|
|
22
|
+
styles.innerHTML = `
|
|
23
|
+
.${CSS_CLASSES.PREVIEW_BADGE} {
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: 20px;
|
|
26
|
+
right: 20px;
|
|
27
|
+
background: rgba(31, 41, 55, 0.9);
|
|
28
|
+
backdrop-filter: blur(4px);
|
|
29
|
+
-webkit-backdrop-filter: blur(4px);
|
|
30
|
+
color: white;
|
|
31
|
+
padding: 6px 14px;
|
|
32
|
+
border-radius: 6px;
|
|
33
|
+
font-size: 12px;
|
|
34
|
+
font-weight: 600;
|
|
35
|
+
letter-spacing: 0.5px;
|
|
36
|
+
z-index: 10;
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
|
39
|
+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
|
|
40
|
+
animation: ww-vto-pulse 2s ease-in-out infinite;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@keyframes ww-vto-pulse {
|
|
44
|
+
0%, 100% {
|
|
45
|
+
opacity: 0.9;
|
|
46
|
+
}
|
|
47
|
+
50% {
|
|
48
|
+
opacity: 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
53
51
|
`;
|
|
54
52
|
document.head.appendChild(styles);
|
|
55
53
|
}
|
|
@@ -79,39 +77,43 @@ function createButtonContainer(buttonPosition, hasVirtualTryOn = false, onCamera
|
|
|
79
77
|
const container = document.createElement("div");
|
|
80
78
|
container.className = `${CSS_CLASSES.BUTTON_CONTAINER} ww-button-group`;
|
|
81
79
|
const positionStyles = getPositionStyles(buttonPosition);
|
|
82
|
-
container.style.cssText = `
|
|
83
|
-
position: absolute;
|
|
84
|
-
${positionStyles}
|
|
85
|
-
display: flex;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
container.style.cssText = `
|
|
81
|
+
position: absolute;
|
|
82
|
+
${positionStyles}
|
|
83
|
+
display: flex;
|
|
84
|
+
gap: 4px;
|
|
85
|
+
border-radius: 100px;
|
|
86
|
+
background: white;
|
|
87
|
+
padding: 4px;
|
|
88
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
89
|
+
z-index: ${Z_INDEX.BUTTON};
|
|
90
|
+
transition: all 0.2s ease;
|
|
91
91
|
`;
|
|
92
92
|
// Camera button
|
|
93
93
|
const cameraButton = document.createElement("button");
|
|
94
94
|
cameraButton.type = "button";
|
|
95
95
|
cameraButton.className = `${CSS_CLASSES.BUTTON} ww-camera-btn`;
|
|
96
96
|
cameraButton.setAttribute("aria-label", "Virtual Try-On");
|
|
97
|
-
cameraButton.style.cssText = `
|
|
98
|
-
display: flex;
|
|
99
|
-
width:
|
|
100
|
-
height:
|
|
101
|
-
cursor: pointer;
|
|
102
|
-
align-items: center;
|
|
103
|
-
justify-content: center;
|
|
104
|
-
border-radius:
|
|
105
|
-
padding:
|
|
106
|
-
border: none;
|
|
107
|
-
background:
|
|
108
|
-
color:
|
|
97
|
+
cameraButton.style.cssText = `
|
|
98
|
+
display: flex;
|
|
99
|
+
width: 40px;
|
|
100
|
+
height: 40px;
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
align-items: center;
|
|
103
|
+
justify-content: center;
|
|
104
|
+
border-radius: 100px;
|
|
105
|
+
padding: 0;
|
|
106
|
+
border: none;
|
|
107
|
+
background: white;
|
|
108
|
+
color: #000000;
|
|
109
|
+
transition: all 0.2s ease;
|
|
110
|
+
flex-shrink: 0;
|
|
109
111
|
`;
|
|
110
|
-
cameraButton.innerHTML = `
|
|
111
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
112
|
-
<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>
|
|
113
|
-
<circle cx="12" cy="13" r="3"></circle>
|
|
114
|
-
</svg>
|
|
112
|
+
cameraButton.innerHTML = `
|
|
113
|
+
<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;">
|
|
114
|
+
<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>
|
|
115
|
+
<circle cx="12" cy="13" r="3"></circle>
|
|
116
|
+
</svg>
|
|
115
117
|
`;
|
|
116
118
|
cameraButton.onclick = onCameraClick;
|
|
117
119
|
container.appendChild(cameraButton);
|
|
@@ -123,27 +125,30 @@ function createButtonContainer(buttonPosition, hasVirtualTryOn = false, onCamera
|
|
|
123
125
|
refreshButton.type = "button";
|
|
124
126
|
refreshButton.className = "ww-refresh-btn";
|
|
125
127
|
refreshButton.setAttribute("aria-label", "Refresh virtual try-on");
|
|
126
|
-
refreshButton.style.cssText = `
|
|
127
|
-
display: flex;
|
|
128
|
-
width:
|
|
129
|
-
height:
|
|
130
|
-
cursor: pointer;
|
|
131
|
-
align-items: center;
|
|
132
|
-
justify-content: center;
|
|
133
|
-
border-radius:
|
|
134
|
-
padding:
|
|
135
|
-
border: none;
|
|
136
|
-
background:
|
|
137
|
-
color:
|
|
128
|
+
refreshButton.style.cssText = `
|
|
129
|
+
display: flex;
|
|
130
|
+
width: 40px;
|
|
131
|
+
height: 40px;
|
|
132
|
+
cursor: pointer;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: center;
|
|
135
|
+
border-radius: 100px;
|
|
136
|
+
padding: 0;
|
|
137
|
+
border: none;
|
|
138
|
+
background: white;
|
|
139
|
+
color: #333333;
|
|
140
|
+
transition: all 0.2s ease;
|
|
141
|
+
flex-shrink: 0;
|
|
138
142
|
`;
|
|
139
|
-
refreshButton.innerHTML = `
|
|
140
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
141
|
-
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path>
|
|
142
|
-
<path d="M3 3v5h5"></path>
|
|
143
|
-
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"></path>
|
|
144
|
-
<path d="M16 16h5v5"></path>
|
|
145
|
-
</svg>
|
|
143
|
+
refreshButton.innerHTML = `
|
|
144
|
+
<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;">
|
|
145
|
+
<path d="M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"></path>
|
|
146
|
+
<path d="M3 3v5h5"></path>
|
|
147
|
+
<path d="M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16"></path>
|
|
148
|
+
<path d="M16 16h5v5"></path>
|
|
149
|
+
</svg>
|
|
146
150
|
`;
|
|
151
|
+
refreshButton.onclick = onRefreshClick;
|
|
147
152
|
refreshButton.onclick = onRefreshClick;
|
|
148
153
|
container.appendChild(refreshButton);
|
|
149
154
|
}
|
|
@@ -153,30 +158,48 @@ function createButtonContainer(buttonPosition, hasVirtualTryOn = false, onCamera
|
|
|
153
158
|
toggleButton.type = "button";
|
|
154
159
|
toggleButton.className = "ww-toggle-btn";
|
|
155
160
|
toggleButton.setAttribute("aria-label", isShowingVirtualTryOn ? "Show Original Image" : "Show Virtual Try-On");
|
|
156
|
-
toggleButton.style.cssText = `
|
|
157
|
-
display: flex;
|
|
158
|
-
width:
|
|
159
|
-
height:
|
|
160
|
-
cursor: pointer;
|
|
161
|
-
align-items: center;
|
|
162
|
-
justify-content: center;
|
|
163
|
-
border-radius:
|
|
164
|
-
padding:
|
|
165
|
-
border: none;
|
|
166
|
-
background: ${isShowingVirtualTryOn ? "
|
|
167
|
-
color: ${isShowingVirtualTryOn ? "white" : "
|
|
161
|
+
toggleButton.style.cssText = `
|
|
162
|
+
display: flex;
|
|
163
|
+
width: 40px;
|
|
164
|
+
height: 40px;
|
|
165
|
+
cursor: pointer;
|
|
166
|
+
align-items: center;
|
|
167
|
+
justify-content: center;
|
|
168
|
+
border-radius: 100px;
|
|
169
|
+
padding: 0;
|
|
170
|
+
border: none;
|
|
171
|
+
background: ${isShowingVirtualTryOn ? "#333333" : "#e5e7eb"};
|
|
172
|
+
color: ${isShowingVirtualTryOn ? "white" : "#333333"};
|
|
173
|
+
transition: all 0.2s ease;
|
|
174
|
+
flex-shrink: 0;
|
|
168
175
|
`;
|
|
169
|
-
toggleButton.innerHTML = `
|
|
170
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="
|
|
171
|
-
<path d="M3 7V5a2 2 0 0 1 2-2h2"></path>
|
|
172
|
-
<path d="M17 3h2a2 2 0 0 1 2 2v2"></path>
|
|
173
|
-
<path d="M21 17v2a2 2 0 0 1-2 2h-2"></path>
|
|
174
|
-
<path d="M7 21H5a2 2 0 0 1-2-2v-2"></path>
|
|
175
|
-
<path d="M8 14s1.5 2 4 2 4-2 4-2"></path>
|
|
176
|
-
<path d="M9 9h.01"></path>
|
|
177
|
-
<path d="M15 9h.01"></path>
|
|
178
|
-
</svg>
|
|
176
|
+
toggleButton.innerHTML = `
|
|
177
|
+
<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;">
|
|
178
|
+
<path d="M3 7V5a2 2 0 0 1 2-2h2"></path>
|
|
179
|
+
<path d="M17 3h2a2 2 0 0 1 2 2v2"></path>
|
|
180
|
+
<path d="M21 17v2a2 2 0 0 1-2 2h-2"></path>
|
|
181
|
+
<path d="M7 21H5a2 2 0 0 1-2-2v-2"></path>
|
|
182
|
+
<path d="M8 14s1.5 2 4 2 4-2 4-2"></path>
|
|
183
|
+
<path d="M9 9h.01"></path>
|
|
184
|
+
<path d="M15 9h.01"></path>
|
|
185
|
+
</svg>
|
|
179
186
|
`;
|
|
187
|
+
toggleButton.onmouseover = () => {
|
|
188
|
+
if (isShowingVirtualTryOn) {
|
|
189
|
+
toggleButton.style.background = "#4a4a4a";
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
toggleButton.style.background = "#d1d5db";
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
toggleButton.onmouseout = () => {
|
|
196
|
+
if (isShowingVirtualTryOn) {
|
|
197
|
+
toggleButton.style.background = "#333333";
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
toggleButton.style.background = "#e5e7eb";
|
|
201
|
+
}
|
|
202
|
+
};
|
|
180
203
|
toggleButton.onclick = onToggleClick;
|
|
181
204
|
container.appendChild(toggleButton);
|
|
182
205
|
}
|
|
@@ -203,49 +226,98 @@ function createButton(buttonPosition, onClick, disabled = false) {
|
|
|
203
226
|
function createLoadingOverlay(text = "Processing...") {
|
|
204
227
|
const overlay = document.createElement("div");
|
|
205
228
|
overlay.className = "ww-loading-overlay";
|
|
206
|
-
overlay.style.cssText = `
|
|
207
|
-
position: absolute;
|
|
208
|
-
top: 0;
|
|
209
|
-
left: 0;
|
|
210
|
-
width: 100%;
|
|
211
|
-
height: 100%;
|
|
212
|
-
background
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
229
|
+
overlay.style.cssText = `
|
|
230
|
+
position: absolute;
|
|
231
|
+
top: 0;
|
|
232
|
+
left: 0;
|
|
233
|
+
width: 100%;
|
|
234
|
+
height: 100%;
|
|
235
|
+
background: linear-gradient(135deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.88) 100%);
|
|
236
|
+
backdrop-filter: blur(8px);
|
|
237
|
+
-webkit-backdrop-filter: blur(8px);
|
|
238
|
+
display: flex;
|
|
239
|
+
flex-direction: column;
|
|
240
|
+
align-items: center;
|
|
241
|
+
justify-content: center;
|
|
242
|
+
z-index: ${Z_INDEX.MODAL + 1};
|
|
243
|
+
border-radius: inherit;
|
|
244
|
+
animation: ww-fade-in 0.3s ease;
|
|
219
245
|
`;
|
|
220
246
|
// Add CSS animation to the document if not already added
|
|
221
247
|
if (!document.getElementById("ww-loading-animation")) {
|
|
222
248
|
const style = document.createElement("style");
|
|
223
249
|
style.id = "ww-loading-animation";
|
|
224
|
-
style.textContent = `
|
|
225
|
-
@keyframes ww-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
250
|
+
style.textContent = `
|
|
251
|
+
@keyframes ww-fade-in {
|
|
252
|
+
from { opacity: 0; }
|
|
253
|
+
to { opacity: 1; }
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
@keyframes ww-pulse-logo {
|
|
257
|
+
0%, 100% {
|
|
258
|
+
opacity: 0.8;
|
|
259
|
+
transform: scale(1);
|
|
260
|
+
}
|
|
261
|
+
50% {
|
|
262
|
+
opacity: 1;
|
|
263
|
+
transform: scale(1.05);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
@keyframes ww-spinner-rotate {
|
|
268
|
+
0% { transform: rotate(0deg); }
|
|
269
|
+
100% { transform: rotate(360deg); }
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@keyframes ww-dot-bounce {
|
|
273
|
+
0%, 80%, 100% {
|
|
274
|
+
transform: scale(0);
|
|
275
|
+
opacity: 0.5;
|
|
276
|
+
}
|
|
277
|
+
40% {
|
|
278
|
+
transform: scale(1);
|
|
279
|
+
opacity: 1;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
.ww-loading-logo {
|
|
284
|
+
animation: ww-pulse-logo 2s ease-in-out infinite;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
.ww-loading-spinner {
|
|
288
|
+
animation: ww-spinner-rotate 1s linear infinite;
|
|
289
|
+
}
|
|
232
290
|
`;
|
|
233
291
|
document.head.appendChild(style);
|
|
234
292
|
}
|
|
235
|
-
overlay.innerHTML = `
|
|
236
|
-
<div style="display: flex; flex-direction: column; align-items: center; gap:
|
|
237
|
-
<
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
293
|
+
overlay.innerHTML = `
|
|
294
|
+
<div style="display: flex; flex-direction: column; align-items: center; gap: 32px;">
|
|
295
|
+
<div style="position: relative; width: 120px; height: 120px; display: flex; align-items: center; justify-content: center;">
|
|
296
|
+
<!-- Outer spinning circle -->
|
|
297
|
+
<div class="ww-loading-spinner" style="
|
|
298
|
+
position: absolute;
|
|
299
|
+
width: 120px;
|
|
300
|
+
height: 120px;
|
|
301
|
+
border: 3px solid transparent;
|
|
302
|
+
border-top: 3px solid #333333;
|
|
303
|
+
border-right: 3px solid #333333;
|
|
304
|
+
border-radius: 50%;
|
|
305
|
+
"></div>
|
|
306
|
+
|
|
307
|
+
<!-- Logo -->
|
|
308
|
+
<svg class="ww-loading-logo" width="80" height="50" viewBox="0 0 214 135" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
309
|
+
<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"/>
|
|
310
|
+
</svg>
|
|
311
|
+
</div>
|
|
312
|
+
|
|
313
|
+
<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>
|
|
314
|
+
|
|
315
|
+
<div style="display: flex; gap: 10px; margin-top: 4px;">
|
|
316
|
+
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out infinite;"></div>
|
|
317
|
+
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out 0.2s infinite;"></div>
|
|
318
|
+
<div style="width: 10px; height: 10px; border-radius: 50%; background: #333333; animation: ww-dot-bounce 1.4s ease-in-out 0.4s infinite;"></div>
|
|
319
|
+
</div>
|
|
320
|
+
</div>
|
|
249
321
|
`;
|
|
250
322
|
return overlay;
|
|
251
323
|
}
|
|
@@ -280,42 +352,63 @@ function showAlert(container, message, type) {
|
|
|
280
352
|
alertDiv.className = `ww-alert ww-alert-${type}`;
|
|
281
353
|
alertDiv.setAttribute("role", "alert" );
|
|
282
354
|
alertDiv.setAttribute("aria-live", "assertive");
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
355
|
+
const bgColor = "linear-gradient(135deg, #fee2e2 0%, #fecaca 100%)"
|
|
356
|
+
;
|
|
357
|
+
const textColor = "#991b1b" ;
|
|
358
|
+
const borderColor = "#f87171" ;
|
|
359
|
+
const iconColor = "#dc2626" ;
|
|
360
|
+
alertDiv.style.cssText = `
|
|
361
|
+
position: absolute;
|
|
362
|
+
top: 24px;
|
|
363
|
+
left: 50%;
|
|
364
|
+
transform: translateX(-50%) translateY(-20px);
|
|
365
|
+
background: ${bgColor};
|
|
366
|
+
color: ${textColor};
|
|
367
|
+
border: 1px solid ${borderColor};
|
|
368
|
+
border-radius: 12px;
|
|
369
|
+
padding: 16px 20px;
|
|
370
|
+
z-index: 9999;
|
|
371
|
+
font-size: 15px;
|
|
372
|
+
font-weight: 500;
|
|
373
|
+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
|
|
374
|
+
backdrop-filter: blur(8px);
|
|
375
|
+
-webkit-backdrop-filter: blur(8px);
|
|
376
|
+
display: flex;
|
|
377
|
+
align-items: center;
|
|
378
|
+
gap: 12px;
|
|
379
|
+
min-width: 280px;
|
|
380
|
+
max-width: 90%;
|
|
381
|
+
opacity: 0;
|
|
382
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
303
383
|
`;
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
384
|
+
const icon = `<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="${iconColor}" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
385
|
+
<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"/>
|
|
386
|
+
</svg>`
|
|
387
|
+
;
|
|
388
|
+
alertDiv.innerHTML = `
|
|
389
|
+
${icon}
|
|
390
|
+
<span style="flex: 1; line-height: 1.5;">${message}</span>
|
|
391
|
+
<button type="button" aria-label="Close alert"
|
|
392
|
+
style="
|
|
393
|
+
background: none;
|
|
394
|
+
border: none;
|
|
395
|
+
font-size: 22px;
|
|
396
|
+
color: ${textColor};
|
|
397
|
+
cursor: pointer;
|
|
398
|
+
padding: 0;
|
|
399
|
+
line-height: 1;
|
|
400
|
+
opacity: 0.7;
|
|
401
|
+
transition: opacity 0.2s ease;
|
|
402
|
+
width: 24px;
|
|
403
|
+
height: 24px;
|
|
404
|
+
display: flex;
|
|
405
|
+
align-items: center;
|
|
406
|
+
justify-content: center;
|
|
407
|
+
"
|
|
408
|
+
onmouseover="this.style.opacity='1'"
|
|
409
|
+
onmouseout="this.style.opacity='0.7'">
|
|
410
|
+
×
|
|
411
|
+
</button>
|
|
319
412
|
`;
|
|
320
413
|
// Close on button click
|
|
321
414
|
(_a = alertDiv.querySelector("button")) === null || _a === void 0 ? void 0 : _a.addEventListener("click", () => {
|
|
@@ -327,10 +420,16 @@ function showAlert(container, message, type) {
|
|
|
327
420
|
alertDiv.style.opacity = "1";
|
|
328
421
|
alertDiv.style.transform = "translateX(-50%) translateY(0)";
|
|
329
422
|
});
|
|
423
|
+
// Auto-dismiss after 8 seconds
|
|
424
|
+
setTimeout(() => {
|
|
425
|
+
if (alertDiv.parentElement) {
|
|
426
|
+
fadeOutAndRemove(alertDiv);
|
|
427
|
+
}
|
|
428
|
+
}, 8000);
|
|
330
429
|
}
|
|
331
430
|
function fadeOutAndRemove(element) {
|
|
332
431
|
element.style.opacity = "0";
|
|
333
|
-
element.style.transform = "translateX(-50%) translateY(-
|
|
432
|
+
element.style.transform = "translateX(-50%) translateY(-20px)";
|
|
334
433
|
setTimeout(() => {
|
|
335
434
|
element.remove();
|
|
336
435
|
}, 300);
|
|
@@ -347,7 +446,6 @@ class VirtualTryOnWidget {
|
|
|
347
446
|
this.originalProductImageUrl = null;
|
|
348
447
|
this.isShowingVirtualTryOn = false;
|
|
349
448
|
this.lastModelImage = null;
|
|
350
|
-
this.cookieCheckInterval = null;
|
|
351
449
|
this.cameraButton = null;
|
|
352
450
|
this.iframeMessageListener = null;
|
|
353
451
|
this.previewBadge = null;
|
|
@@ -437,47 +535,110 @@ class VirtualTryOnWidget {
|
|
|
437
535
|
removeElements(`.${CSS_CLASSES.MODAL}`);
|
|
438
536
|
const modal = document.createElement("div");
|
|
439
537
|
modal.className = CSS_CLASSES.MODAL;
|
|
440
|
-
modal.style.cssText = `
|
|
441
|
-
position: fixed;
|
|
442
|
-
top: 0;
|
|
443
|
-
left: 0;
|
|
444
|
-
width: 100%;
|
|
445
|
-
height: 100%;
|
|
446
|
-
background
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
538
|
+
modal.style.cssText = `
|
|
539
|
+
position: fixed;
|
|
540
|
+
top: 0;
|
|
541
|
+
left: 0;
|
|
542
|
+
width: 100%;
|
|
543
|
+
height: 100%;
|
|
544
|
+
background: linear-gradient(135deg, rgba(0, 0, 0, 0.6) 0%, rgba(0, 0, 0, 0.7) 100%);
|
|
545
|
+
backdrop-filter: blur(8px);
|
|
546
|
+
-webkit-backdrop-filter: blur(8px);
|
|
547
|
+
display: flex;
|
|
548
|
+
justify-content: center;
|
|
549
|
+
align-items: center;
|
|
550
|
+
z-index: 1000;
|
|
551
|
+
animation: ww-modal-fade-in 0.3s ease;
|
|
451
552
|
`;
|
|
553
|
+
// Add fade-in animation
|
|
554
|
+
if (!document.getElementById("ww-modal-animation")) {
|
|
555
|
+
const style = document.createElement("style");
|
|
556
|
+
style.id = "ww-modal-animation";
|
|
557
|
+
style.textContent = `
|
|
558
|
+
@keyframes ww-modal-fade-in {
|
|
559
|
+
from { opacity: 0; }
|
|
560
|
+
to { opacity: 1; }
|
|
561
|
+
}
|
|
562
|
+
@keyframes ww-modal-scale-in {
|
|
563
|
+
from { transform: scale(0.95); opacity: 0; }
|
|
564
|
+
to { transform: scale(1); opacity: 1; }
|
|
565
|
+
}
|
|
566
|
+
`;
|
|
567
|
+
document.head.appendChild(style);
|
|
568
|
+
}
|
|
569
|
+
const iframeContainer = document.createElement("div");
|
|
570
|
+
iframeContainer.style.cssText = `
|
|
571
|
+
position: relative;
|
|
572
|
+
width: 90%;
|
|
573
|
+
height: 90%;
|
|
574
|
+
max-width: 480px;
|
|
575
|
+
max-height: 720px;
|
|
576
|
+
border-radius: 20px;
|
|
577
|
+
overflow: hidden;
|
|
578
|
+
box-shadow: 0 24px 48px rgba(0, 0, 0, 0.3), 0 12px 24px rgba(0, 0, 0, 0.2);
|
|
579
|
+
animation: ww-modal-scale-in 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
580
|
+
background: white;
|
|
581
|
+
`;
|
|
452
582
|
const iframe = document.createElement("iframe");
|
|
453
583
|
iframe.src = url;
|
|
454
|
-
iframe.style.cssText = `
|
|
455
|
-
width:
|
|
456
|
-
height:
|
|
457
|
-
|
|
458
|
-
max-height: 600px;
|
|
459
|
-
border: none;
|
|
460
|
-
border-radius: 8px;
|
|
584
|
+
iframe.style.cssText = `
|
|
585
|
+
width: 100%;
|
|
586
|
+
height: 100%;
|
|
587
|
+
border: none;
|
|
461
588
|
`;
|
|
462
589
|
const closeButton = document.createElement("button");
|
|
463
|
-
closeButton.
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
590
|
+
closeButton.innerHTML = `
|
|
591
|
+
<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">
|
|
592
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
593
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
594
|
+
</svg>
|
|
595
|
+
`;
|
|
596
|
+
closeButton.setAttribute("aria-label", "Close modal");
|
|
597
|
+
closeButton.style.cssText = `
|
|
598
|
+
position: absolute;
|
|
599
|
+
top: -48px;
|
|
600
|
+
right: 0;
|
|
601
|
+
background: rgba(255, 255, 255, 0.95);
|
|
602
|
+
backdrop-filter: blur(8px);
|
|
603
|
+
-webkit-backdrop-filter: blur(8px);
|
|
604
|
+
border: none;
|
|
605
|
+
border-radius: 50%;
|
|
606
|
+
width: 40px;
|
|
607
|
+
height: 40px;
|
|
608
|
+
cursor: pointer;
|
|
609
|
+
display: flex;
|
|
610
|
+
align-items: center;
|
|
611
|
+
justify-content: center;
|
|
612
|
+
color: #1f2937;
|
|
613
|
+
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
|
614
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
474
615
|
`;
|
|
616
|
+
closeButton.onmouseover = () => {
|
|
617
|
+
closeButton.style.transform = "scale(1.1) rotate(90deg)";
|
|
618
|
+
closeButton.style.background = "#ef4444";
|
|
619
|
+
closeButton.style.color = "white";
|
|
620
|
+
};
|
|
621
|
+
closeButton.onmouseout = () => {
|
|
622
|
+
closeButton.style.transform = "scale(1) rotate(0deg)";
|
|
623
|
+
closeButton.style.background = "rgba(255, 255, 255, 0.95)";
|
|
624
|
+
closeButton.style.color = "#1f2937";
|
|
625
|
+
};
|
|
475
626
|
closeButton.onclick = () => {
|
|
476
|
-
modal.
|
|
627
|
+
modal.style.opacity = "0";
|
|
628
|
+
iframeContainer.style.transform = "scale(0.95)";
|
|
629
|
+
iframeContainer.style.opacity = "0";
|
|
630
|
+
setTimeout(() => modal.remove(), 300);
|
|
477
631
|
};
|
|
478
|
-
|
|
479
|
-
|
|
632
|
+
iframeContainer.appendChild(iframe);
|
|
633
|
+
iframeContainer.appendChild(closeButton);
|
|
634
|
+
modal.appendChild(iframeContainer);
|
|
480
635
|
document.body.appendChild(modal);
|
|
636
|
+
// Close on backdrop click
|
|
637
|
+
modal.onclick = (e) => {
|
|
638
|
+
if (e.target === modal) {
|
|
639
|
+
closeButton.click();
|
|
640
|
+
}
|
|
641
|
+
};
|
|
481
642
|
}
|
|
482
643
|
/**
|
|
483
644
|
* Sets up listener for messages from the iframe
|
|
@@ -630,6 +791,19 @@ class VirtualTryOnWidget {
|
|
|
630
791
|
if (!container.hasAttribute("data-ww-original-content")) {
|
|
631
792
|
container.setAttribute("data-ww-original-content", container.innerHTML);
|
|
632
793
|
}
|
|
794
|
+
// Capture and lock container dimensions before replacement to prevent layout shift
|
|
795
|
+
if (!container.hasAttribute("data-ww-container-locked")) {
|
|
796
|
+
const containerRect = container.getBoundingClientRect();
|
|
797
|
+
// Store original dimensions
|
|
798
|
+
container.setAttribute("data-ww-container-width", containerRect.width.toString());
|
|
799
|
+
container.setAttribute("data-ww-container-height", containerRect.height.toString());
|
|
800
|
+
// Lock the container dimensions
|
|
801
|
+
container.style.width = `${containerRect.width}px`;
|
|
802
|
+
container.style.height = `${containerRect.height}px`;
|
|
803
|
+
container.style.minWidth = `${containerRect.width}px`;
|
|
804
|
+
container.style.minHeight = `${containerRect.height}px`;
|
|
805
|
+
container.setAttribute("data-ww-container-locked", "true");
|
|
806
|
+
}
|
|
633
807
|
// Capture original image dimensions before replacement to prevent layout shift
|
|
634
808
|
const originalImg = container.querySelector("img");
|
|
635
809
|
if (originalImg &&
|
|
@@ -720,11 +894,10 @@ class VirtualTryOnWidget {
|
|
|
720
894
|
else if (originalRectHeight && originalRectHeight !== "0") {
|
|
721
895
|
heightStyle = `${originalRectHeight}px`;
|
|
722
896
|
}
|
|
723
|
-
image.style.cssText = `
|
|
724
|
-
width: ${widthStyle};
|
|
725
|
-
height: ${heightStyle};
|
|
726
|
-
object-fit:
|
|
727
|
-
border-radius: 8px;
|
|
897
|
+
image.style.cssText = `
|
|
898
|
+
width: ${widthStyle};
|
|
899
|
+
height: ${heightStyle};
|
|
900
|
+
object-fit: contain;
|
|
728
901
|
`;
|
|
729
902
|
// Prepend the image to ensure buttons are rendered on top
|
|
730
903
|
container.prepend(image);
|
|
@@ -759,11 +932,7 @@ class VirtualTryOnWidget {
|
|
|
759
932
|
removeElements(`.${CSS_CLASSES.BUTTON_CONTAINER}`);
|
|
760
933
|
// Remove all modals
|
|
761
934
|
removeElements(`.${CSS_CLASSES.MODAL}`);
|
|
762
|
-
// Clear
|
|
763
|
-
if (this.cookieCheckInterval !== null) {
|
|
764
|
-
clearInterval(this.cookieCheckInterval);
|
|
765
|
-
this.cookieCheckInterval = null;
|
|
766
|
-
}
|
|
935
|
+
// Clear references
|
|
767
936
|
this.cameraButton = null;
|
|
768
937
|
// Remove message listener
|
|
769
938
|
if (this.iframeMessageListener) {
|