@thefittingroom/shop-ui 3.0.0-alpha-5 → 3.0.0-alpha-7

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.
@@ -1,6 +1,8 @@
1
1
  export declare class VtoComponent {
2
2
  private readonly vtoMainDivId;
3
3
  private isInit;
4
+ private currentSliderValue;
5
+ private slider;
4
6
  constructor(vtoMainDivId: string);
5
7
  init(): void;
6
8
  onNewFramesReady(frames: string[]): void;
@@ -11,6 +11,7 @@ declare var L: {
11
11
  EnterPhoneNumber: string;
12
12
  FailedToLoadLocale: string;
13
13
  ForgotPasswordWithSymbol: string;
14
+ GetVirtualTryOnFramesErrorText: string;
14
15
  HaveAcc: string;
15
16
  Loading: string;
16
17
  LoadingAvatar: string;
@@ -1,3 +1,3 @@
1
1
  export declare const InitImageSlider: (sliderID: string, onChange: (slider: HTMLInputElement, imageUrl: string) => void) => {
2
- Load(imageURLs: string[]): Error | (() => void);
2
+ Load(imageURLs: string[], initialValue?: number): Error | (() => void);
3
3
  };
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * thefittingroom v3.0.0-alpha-5 (2025-04-18T16:10:37.729Z)
2
+ * thefittingroom v3.0.0-alpha-7 (2025-04-18T19:07:37.264Z)
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
- const slider = InitImageSlider('tfr-slider', onChange);
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
- const e = slider.Load(frames);
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
  }
@@ -26636,6 +26651,7 @@ var L = {
26636
26651
  EnterPhoneNumber: 'Enter your number for download link',
26637
26652
  FailedToLoadLocale: 'Something went wrong when fetching another language.',
26638
26653
  ForgotPasswordWithSymbol: 'Forgot password?',
26654
+ GetVirtualTryOnFramesErrorText: 'The try-on request timed out. Please try again!',
26639
26655
  HaveAcc: 'Have an account? Sign in',
26640
26656
  Loading: 'Loading...',
26641
26657
  LoadingAvatar: 'Your avatar is loading...',
@@ -27602,15 +27618,15 @@ class SizeRecComponent {
27602
27618
  try {
27603
27619
  // Get all size buttons
27604
27620
  const allSizeButtons = Array.from(document.querySelectorAll('.tfr-size-rec-select-button'));
27605
- // Request frames for all sizes
27606
- for (const button of allSizeButtons) {
27621
+ // Request frames for all sizes concurrently
27622
+ await Promise.all(allSizeButtons.map(async (button) => {
27607
27623
  const sizeId = Number(button.getAttribute('data-size-id'));
27608
27624
  if (Number.isNaN(sizeId))
27609
- continue;
27625
+ return;
27610
27626
  // Only display the active size, others are just requested
27611
27627
  const shouldDisplay = button === activeButton;
27612
27628
  await this.onTryOnClick(this.styleId, sizeId, shouldDisplay);
27613
- }
27629
+ }));
27614
27630
  }
27615
27631
  catch (error) {
27616
27632
  console.error('Error during try-on:', error);
@@ -28103,14 +28119,26 @@ class FittingRoom {
28103
28119
  async onTryOnClick(styleId, sizeId, shouldDisplay = true) {
28104
28120
  if (!this.vtoComponent)
28105
28121
  return console.error('VtoComponent is not initialized');
28106
- const frames = await this.shop.tryOn(styleId, sizeId);
28107
- if (shouldDisplay) {
28108
- try {
28109
- this.vtoComponent.init();
28110
- this.vtoComponent.onNewFramesReady(frames);
28122
+ try {
28123
+ const frames = await this.shop.tryOn(styleId, sizeId);
28124
+ if (shouldDisplay) {
28125
+ try {
28126
+ this.vtoComponent.init();
28127
+ this.vtoComponent.onNewFramesReady(frames);
28128
+ }
28129
+ catch (e) {
28130
+ console.error('Error initializing VTO:', e);
28131
+ this.tfrModal.onError(L.SomethingWentWrong);
28132
+ }
28111
28133
  }
28112
- catch (e) {
28113
- console.error(e);
28134
+ }
28135
+ catch (error) {
28136
+ console.error('Error during try-on:', error);
28137
+ if (error instanceof Error && error.name === 'TimeoutError') {
28138
+ this.tfrModal.onError(L.GetVirtualTryOnFramesErrorText);
28139
+ }
28140
+ else {
28141
+ this.tfrModal.onError(L.SomethingWentWrong);
28114
28142
  }
28115
28143
  }
28116
28144
  }