@thefittingroom/shop-ui 3.0.0-alpha-5 → 3.0.0-alpha-6
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/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* thefittingroom v3.0.0-alpha-
|
|
2
|
+
* thefittingroom v3.0.0-alpha-6 (2025-04-18T16:48:31.249Z)
|
|
3
3
|
* Copyright 2022-present, TheFittingRoom, Inc. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
function loadImageRecursive(imageURL, imageURLs) {
|
|
@@ -23,13 +23,13 @@ const InitImageSlider = (sliderID, onChange) => {
|
|
|
23
23
|
throw new Error(`Slider with id ${sliderID} not found`);
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
|
-
Load(imageURLs) {
|
|
26
|
+
Load(imageURLs, initialValue) {
|
|
27
27
|
if (!Array.isArray(imageURLs) || !imageURLs.length) {
|
|
28
28
|
console.debug('slider has no images to load');
|
|
29
29
|
return new Error('slider has no images to load');
|
|
30
30
|
}
|
|
31
31
|
loadImages(imageURLs);
|
|
32
|
-
const defaultScrollValue = 0;
|
|
32
|
+
const defaultScrollValue = initialValue !== undefined ? initialValue : 0;
|
|
33
33
|
slider.value = defaultScrollValue.toString();
|
|
34
34
|
slider.max = (imageURLs.length - 1).toString();
|
|
35
35
|
const handleSliderChange = () => {
|
|
@@ -26591,6 +26591,8 @@ class VtoComponent {
|
|
|
26591
26591
|
constructor(vtoMainDivId) {
|
|
26592
26592
|
this.vtoMainDivId = vtoMainDivId;
|
|
26593
26593
|
this.isInit = false;
|
|
26594
|
+
this.currentSliderValue = 0;
|
|
26595
|
+
this.slider = null;
|
|
26594
26596
|
}
|
|
26595
26597
|
init() {
|
|
26596
26598
|
if (this.isInit)
|
|
@@ -26604,21 +26606,34 @@ class VtoComponent {
|
|
|
26604
26606
|
<input type="range" id="tfr-slider" />
|
|
26605
26607
|
</div>
|
|
26606
26608
|
`;
|
|
26607
|
-
this.isInit = true;
|
|
26608
|
-
}
|
|
26609
|
-
onNewFramesReady(frames) {
|
|
26610
26609
|
const tryOnImage = document.getElementById('tfr-tryon-image');
|
|
26611
26610
|
const onChange = (slider, imageUrl) => {
|
|
26612
26611
|
console.debug('slider change', slider, imageUrl);
|
|
26613
26612
|
tryOnImage.src = imageUrl;
|
|
26613
|
+
this.currentSliderValue = parseInt(slider.value);
|
|
26614
26614
|
};
|
|
26615
|
-
|
|
26615
|
+
this.slider = InitImageSlider('tfr-slider', onChange);
|
|
26616
|
+
this.isInit = true;
|
|
26617
|
+
}
|
|
26618
|
+
onNewFramesReady(frames) {
|
|
26619
|
+
if (!this.isInit) {
|
|
26620
|
+
this.init();
|
|
26621
|
+
}
|
|
26616
26622
|
if (Array.isArray(frames) && frames.length > 0) {
|
|
26617
|
-
|
|
26623
|
+
// Ensure the current slider value is within bounds of the new frames array
|
|
26624
|
+
const boundedValue = Math.min(this.currentSliderValue, frames.length - 1);
|
|
26625
|
+
const e = this.slider.Load(frames, boundedValue);
|
|
26618
26626
|
if (e instanceof Error) {
|
|
26619
26627
|
console.error(e);
|
|
26620
26628
|
return;
|
|
26621
26629
|
}
|
|
26630
|
+
// Restore previous slider position if it's within bounds
|
|
26631
|
+
const sliderElement = document.getElementById('tfr-slider');
|
|
26632
|
+
if (sliderElement && this.currentSliderValue < frames.length) {
|
|
26633
|
+
sliderElement.value = this.currentSliderValue.toString();
|
|
26634
|
+
const tryOnImage = document.getElementById('tfr-tryon-image');
|
|
26635
|
+
tryOnImage.src = frames[this.currentSliderValue];
|
|
26636
|
+
}
|
|
26622
26637
|
}
|
|
26623
26638
|
}
|
|
26624
26639
|
}
|
|
@@ -27602,15 +27617,15 @@ class SizeRecComponent {
|
|
|
27602
27617
|
try {
|
|
27603
27618
|
// Get all size buttons
|
|
27604
27619
|
const allSizeButtons = Array.from(document.querySelectorAll('.tfr-size-rec-select-button'));
|
|
27605
|
-
// Request frames for all sizes
|
|
27606
|
-
|
|
27620
|
+
// Request frames for all sizes concurrently
|
|
27621
|
+
await Promise.all(allSizeButtons.map(async (button) => {
|
|
27607
27622
|
const sizeId = Number(button.getAttribute('data-size-id'));
|
|
27608
27623
|
if (Number.isNaN(sizeId))
|
|
27609
|
-
|
|
27624
|
+
return;
|
|
27610
27625
|
// Only display the active size, others are just requested
|
|
27611
27626
|
const shouldDisplay = button === activeButton;
|
|
27612
27627
|
await this.onTryOnClick(this.styleId, sizeId, shouldDisplay);
|
|
27613
|
-
}
|
|
27628
|
+
}));
|
|
27614
27629
|
}
|
|
27615
27630
|
catch (error) {
|
|
27616
27631
|
console.error('Error during try-on:', error);
|