@depict-ai/portal-components 2.7.31 → 2.7.33

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.d.ts CHANGED
@@ -4,7 +4,7 @@ import { SearchFilter } from "@depict-ai/types/api/SearchResponse";
4
4
  import { Locale } from "@depict-ai/react-ui/locales/latest";
5
5
  import { ReactNode } from "react";
6
6
  import { FeaturedInDisplay } from "@depict-ai/types/api/FeaturedInResponseV3";
7
- export const version = "2.7.31";
7
+ export const version = "2.7.33";
8
8
  type TextOptions = {
9
9
  /** Enabled */
10
10
  enabled: boolean;
package/dist/main.js CHANGED
@@ -20,7 +20,7 @@ $parcel$export(module.exports, "ExpandingSection", () => $2214dc111b9e2866$expor
20
20
  $parcel$export(module.exports, "ReactLookCard", () => $35bab9ff48bfe404$export$48787da2a5568bc);
21
21
  $parcel$export(module.exports, "version", () => $0a017be3a74fcc94$export$83d89fbfd8236492);
22
22
  /*! Depict.ai portal components */ // This is where the actual source of your React stuff should live
23
- const $0a017be3a74fcc94$export$83d89fbfd8236492 = "2.7.31";
23
+ const $0a017be3a74fcc94$export$83d89fbfd8236492 = "2.7.33";
24
24
 
25
25
 
26
26
 
@@ -196,8 +196,6 @@ overrideAspectRatio) {
196
196
  "--alignment": alignment
197
197
  };
198
198
  };
199
- (0, $7jsgb$solidjs.createEffect)(()=>(0, $7jsgb$depictaiutilisharedlatest.dlog)("Got passed options", JSON.parse(JSON.stringify(configuredOptions_()))));
200
- (0, $7jsgb$solidjs.createEffect)(()=>(0, $7jsgb$depictaiutilisharedlatest.dlog)("Got passed display", JSON.parse(JSON.stringify(display()))));
201
199
  (0, $7jsgb$solidjs.createEffect)(()=>noHoverSupport_() && setCardIsHovered(false));
202
200
  // For switch from placeholders to product
203
201
  (0, $7jsgb$solidjs.createEffect)(()=>!showVariantIndex() && defaultVariantIndex() != undefined && setShowVariantIndex(defaultVariantIndex()));
@@ -639,12 +637,22 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
639
637
  ];
640
638
  const productCardIsVisible = (0, $7jsgb$depictaiuilatest.useProductCardIsVisible)();
641
639
  const hasBeenVisible = (0, $7jsgb$solidjs.createMemo)((prev)=>prev || productCardIsVisible() || forceIsVisible_());
640
+ const video_urls = ()=>video_()?.video_urls;
641
+ const hasVideo = (0, $7jsgb$solidjs.createMemo)(()=>video_urls()?.length);
642
+ const hoverImageDisabled = (0, $7jsgb$solidjs.createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
643
+ const hasEnoughImagesForSlider = (0, $7jsgb$solidjs.createMemo)((prev)=>{
644
+ if (prev) return prev; // If we had it once, keep the slider (since removing it is not expected by some code IIRC and could look glitchy)
645
+ let minImagesAvailableToEnableSwipe = 2;
646
+ if (hasVideo()) minImagesAvailableToEnableSwipe--;
647
+ else if (!hoverImageDisabled()) minImagesAvailableToEnableSwipe++;
648
+ return image_urls_()?.length >= minImagesAvailableToEnableSwipe;
649
+ });
642
650
  const slidable = (0, $7jsgb$solidjs.createMemo)(()=>// Don't make cards swipable inside of sliders (PLP slider or recs slider)
643
651
  !((0, $7jsgb$depictaiuilatest.useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")) && configuredOptions_().image_carousel && // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
644
- hasBeenVisible());
645
- const hoverImageDisabled = (0, $7jsgb$solidjs.createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
646
- const video_urls = ()=>video_()?.video_urls;
652
+ // Don't delay the creation of the slider if there's a video, since (contrary to what I've observed with images) the move of the video in the DOM will abort the playback, which will abort the network request, which delays the playback of the video significantly
653
+ (hasBeenVisible() || hasVideo()) && hasEnoughImagesForSlider());
647
654
  const [userTriedSliding, setUserTriedSliding] = (0, $7jsgb$solidjs.createSignal)(false);
655
+ const [swipedPastVideo_, setSwipedPastVideo] = (0, $7jsgb$solidjs.createSignal)(false);
648
656
  const Container = (props)=>{
649
657
  const resolved = (0, $7jsgb$solidjs.children)(()=>props.children);
650
658
  return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
@@ -704,8 +712,13 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
704
712
  // Actually render (and load) the other images when the slider gets swiped
705
713
  slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
706
714
  const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
707
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
708
715
  if (1 in intersectingsObject) setUserTriedSliding(true);
716
+ // Pause video when swiping to the next image
717
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
718
+ if (!intersectingsObject || !Object.keys(intersectingsObject).length) return;
719
+ // Video is always the first card in the slider
720
+ const ratio = intersectingsObject?.[0]?.intersectionRatio;
721
+ setSwipedPastVideo(!ratio);
709
722
  });
710
723
  return resolved;
711
724
  })();
@@ -718,7 +731,7 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
718
731
  const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $7jsgb$solidjs.createSignal)([], {
719
732
  equals: false
720
733
  });
721
- // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
734
+ // When slidable, only render extra items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
722
735
  const MaybeShowLazily = (props)=>{
723
736
  const us = Symbol();
724
737
  setItemsWantingToBeRendered((prev)=>{
@@ -726,14 +739,15 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
726
739
  return prev;
727
740
  });
728
741
  (0, $7jsgb$solidjs.onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
729
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
742
+ return(// After it has been swiped, render (and fetch the images) for the rest.
743
+ (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
730
744
  get when () {
731
- return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
745
+ return !slidable() || userTriedSliding() || itemsWantingToBeRendered().indexOf(us) < 2;
732
746
  },
733
747
  get children () {
734
748
  return props.children;
735
749
  }
736
- });
750
+ }));
737
751
  };
738
752
  return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
739
753
  get when () {
@@ -752,7 +766,7 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
752
766
  return [
753
767
  (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
754
768
  get when () {
755
- return video_urls()?.length;
769
+ return hasVideo();
756
770
  },
757
771
  get children () {
758
772
  return (0, $7jsgb$solidjsweb.createComponent)(MaybeShowLazily, {
@@ -772,6 +786,9 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
772
786
  },
773
787
  get forceIsVisible_ () {
774
788
  return forceIsVisible_();
789
+ },
790
+ get swipedPastVideo_ () {
791
+ return swipedPastVideo_();
775
792
  }
776
793
  });
777
794
  }
@@ -783,7 +800,7 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
783
800
  }),
784
801
  (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
785
802
  get when () {
786
- return !video_urls()?.length || slidable();
803
+ return !hasVideo() || slidable();
787
804
  },
788
805
  get children () {
789
806
  return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.For), {
@@ -835,17 +852,6 @@ function $3375ddd88f77967d$var$ImagesAndVideos({ image_urls_: image_urls_, video
835
852
  })
836
853
  });
837
854
  }
838
- }),
839
- (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$solidjs.Show), {
840
- get when () {
841
- return (0, $7jsgb$solidjsweb.memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
842
- },
843
- get children () {
844
- return (0, $7jsgb$solidjsweb.createComponent)((0, $7jsgb$depictaiuilatest.ImagePlaceholder), {
845
- width: "100%",
846
- height: ""
847
- });
848
- }
849
855
  })
850
856
  ];
851
857
  }
@@ -868,24 +874,13 @@ function $3375ddd88f77967d$var$Video(props) {
868
874
  return sources;
869
875
  });
870
876
  const productCardIndexAccessor = (0, $7jsgb$depictaiuilatest.useProductCardIndex)();
871
- const isVisible = (0, $7jsgb$depictaiuilatest.useProductCardIsVisible)();
872
- const slidableInformation = (0, $7jsgb$depictaiuilatest.useSlidableInformation)();
873
- const hiddenInImageCarousel = (0, $7jsgb$solidjs.createMemo)(()=>{
874
- // Pause video when swiping to the next image
875
- slidableInformation?.intersectionEntries_(); // Re-check when intersecting entries change
876
- const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
877
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
878
- if (!intersectingsObject || !Object.keys(intersectingsObject).length) return false;
879
- // Video is always the first card in the slider
880
- const ratio = intersectingsObject?.[0]?.intersectionRatio;
881
- return !ratio;
882
- });
877
+ const cardIsVisible = (0, $7jsgb$depictaiuilatest.useProductCardIsVisible)();
883
878
  return (()=>{
884
879
  var _el$17 = $3375ddd88f77967d$var$_tmpl$15();
885
880
  (0, $7jsgb$solidjsweb.use)((element)=>{
886
881
  element.disablePictureInPicture = true;
887
882
  (0, $7jsgb$solidjs.createEffect)(()=>{
888
- if ((isVisible() || props.forceIsVisible_) && tabIsVisible() && !hiddenInImageCarousel()) element.play().catch((e)=>(0, $7jsgb$depictaiutilisharedlatest.dwarn)("Error playing video", e));
883
+ if ((cardIsVisible() || props.forceIsVisible_) && tabIsVisible() && !props.swipedPastVideo_) element.play().catch((e)=>(0, $7jsgb$depictaiutilisharedlatest.dwarn)("Error playing video", e));
889
884
  else element.pause();
890
885
  });
891
886
  }, _el$17);
package/dist/module.js CHANGED
@@ -7,7 +7,7 @@ import {createContext as $2MCgq$createContext, createMemo as $2MCgq$createMemo,
7
7
  import {createPortal as $2MCgq$createPortal} from "react-dom";
8
8
 
9
9
  /*! Depict.ai portal components */ // This is where the actual source of your React stuff should live
10
- const $91c11b750e80ede3$export$83d89fbfd8236492 = "2.7.31";
10
+ const $91c11b750e80ede3$export$83d89fbfd8236492 = "2.7.33";
11
11
 
12
12
 
13
13
 
@@ -183,8 +183,6 @@ overrideAspectRatio) {
183
183
  "--alignment": alignment
184
184
  };
185
185
  };
186
- (0, $2MCgq$createEffect)(()=>(0, $2MCgq$dlog)("Got passed options", JSON.parse(JSON.stringify(configuredOptions_()))));
187
- (0, $2MCgq$createEffect)(()=>(0, $2MCgq$dlog)("Got passed display", JSON.parse(JSON.stringify(display()))));
188
186
  (0, $2MCgq$createEffect)(()=>noHoverSupport_() && setCardIsHovered(false));
189
187
  // For switch from placeholders to product
190
188
  (0, $2MCgq$createEffect)(()=>!showVariantIndex() && defaultVariantIndex() != undefined && setShowVariantIndex(defaultVariantIndex()));
@@ -626,12 +624,22 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
626
624
  ];
627
625
  const productCardIsVisible = (0, $2MCgq$useProductCardIsVisible)();
628
626
  const hasBeenVisible = (0, $2MCgq$createMemo)((prev)=>prev || productCardIsVisible() || forceIsVisible_());
627
+ const video_urls = ()=>video_()?.video_urls;
628
+ const hasVideo = (0, $2MCgq$createMemo)(()=>video_urls()?.length);
629
+ const hoverImageDisabled = (0, $2MCgq$createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
630
+ const hasEnoughImagesForSlider = (0, $2MCgq$createMemo)((prev)=>{
631
+ if (prev) return prev; // If we had it once, keep the slider (since removing it is not expected by some code IIRC and could look glitchy)
632
+ let minImagesAvailableToEnableSwipe = 2;
633
+ if (hasVideo()) minImagesAvailableToEnableSwipe--;
634
+ else if (!hoverImageDisabled()) minImagesAvailableToEnableSwipe++;
635
+ return image_urls_()?.length >= minImagesAvailableToEnableSwipe;
636
+ });
629
637
  const slidable = (0, $2MCgq$createMemo)(()=>// Don't make cards swipable inside of sliders (PLP slider or recs slider)
630
638
  !((0, $2MCgq$useSlidableInformation)() || PLPLayout?.()?.startsWith("slider")) && configuredOptions_().image_carousel && // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
631
- hasBeenVisible());
632
- const hoverImageDisabled = (0, $2MCgq$createMemo)(()=>!configuredOptions_().use_hover_image || noHoverSupport_());
633
- const video_urls = ()=>video_()?.video_urls;
639
+ // Don't delay the creation of the slider if there's a video, since (contrary to what I've observed with images) the move of the video in the DOM will abort the playback, which will abort the network request, which delays the playback of the video significantly
640
+ (hasBeenVisible() || hasVideo()) && hasEnoughImagesForSlider());
634
641
  const [userTriedSliding, setUserTriedSliding] = (0, $2MCgq$createSignal)(false);
642
+ const [swipedPastVideo_, setSwipedPastVideo] = (0, $2MCgq$createSignal)(false);
635
643
  const Container = (props)=>{
636
644
  const resolved = (0, $2MCgq$children)(()=>props.children);
637
645
  return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
@@ -691,8 +699,13 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
691
699
  // Actually render (and load) the other images when the slider gets swiped
692
700
  slidableInformation.intersectionEntries_(); // Re-check when intersecting entries change
693
701
  const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
694
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
695
702
  if (1 in intersectingsObject) setUserTriedSliding(true);
703
+ // Pause video when swiping to the next image
704
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
705
+ if (!intersectingsObject || !Object.keys(intersectingsObject).length) return;
706
+ // Video is always the first card in the slider
707
+ const ratio = intersectingsObject?.[0]?.intersectionRatio;
708
+ setSwipedPastVideo(!ratio);
696
709
  });
697
710
  return resolved;
698
711
  })();
@@ -705,7 +718,7 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
705
718
  const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = (0, $2MCgq$createSignal)([], {
706
719
  equals: false
707
720
  });
708
- // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
721
+ // When slidable, only render extra items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
709
722
  const MaybeShowLazily = (props)=>{
710
723
  const us = Symbol();
711
724
  setItemsWantingToBeRendered((prev)=>{
@@ -713,14 +726,15 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
713
726
  return prev;
714
727
  });
715
728
  (0, $2MCgq$onCleanup)(()=>setItemsWantingToBeRendered((prev)=>prev.filter((item)=>item !== us)));
716
- return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
729
+ return(// After it has been swiped, render (and fetch the images) for the rest.
730
+ (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
717
731
  get when () {
718
- return !slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding();
732
+ return !slidable() || userTriedSliding() || itemsWantingToBeRendered().indexOf(us) < 2;
719
733
  },
720
734
  get children () {
721
735
  return props.children;
722
736
  }
723
- });
737
+ }));
724
738
  };
725
739
  return (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
726
740
  get when () {
@@ -739,7 +753,7 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
739
753
  return [
740
754
  (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
741
755
  get when () {
742
- return video_urls()?.length;
756
+ return hasVideo();
743
757
  },
744
758
  get children () {
745
759
  return (0, $2MCgq$createComponent)(MaybeShowLazily, {
@@ -759,6 +773,9 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
759
773
  },
760
774
  get forceIsVisible_ () {
761
775
  return forceIsVisible_();
776
+ },
777
+ get swipedPastVideo_ () {
778
+ return swipedPastVideo_();
762
779
  }
763
780
  });
764
781
  }
@@ -770,7 +787,7 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
770
787
  }),
771
788
  (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
772
789
  get when () {
773
- return !video_urls()?.length || slidable();
790
+ return !hasVideo() || slidable();
774
791
  },
775
792
  get children () {
776
793
  return (0, $2MCgq$createComponent)((0, $2MCgq$For), {
@@ -822,17 +839,6 @@ function $29535f590238371c$var$ImagesAndVideos({ image_urls_: image_urls_, video
822
839
  })
823
840
  });
824
841
  }
825
- }),
826
- (0, $2MCgq$createComponent)((0, $2MCgq$Show), {
827
- get when () {
828
- return (0, $2MCgq$memo)(()=>!!(slidable() && itemsWantingToBeRendered().length > 1))() && !userTriedSliding();
829
- },
830
- get children () {
831
- return (0, $2MCgq$createComponent)((0, $2MCgq$ImagePlaceholder), {
832
- width: "100%",
833
- height: ""
834
- });
835
- }
836
842
  })
837
843
  ];
838
844
  }
@@ -855,24 +861,13 @@ function $29535f590238371c$var$Video(props) {
855
861
  return sources;
856
862
  });
857
863
  const productCardIndexAccessor = (0, $2MCgq$useProductCardIndex)();
858
- const isVisible = (0, $2MCgq$useProductCardIsVisible)();
859
- const slidableInformation = (0, $2MCgq$useSlidableInformation)();
860
- const hiddenInImageCarousel = (0, $2MCgq$createMemo)(()=>{
861
- // Pause video when swiping to the next image
862
- slidableInformation?.intersectionEntries_(); // Re-check when intersecting entries change
863
- const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
864
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
865
- if (!intersectingsObject || !Object.keys(intersectingsObject).length) return false;
866
- // Video is always the first card in the slider
867
- const ratio = intersectingsObject?.[0]?.intersectionRatio;
868
- return !ratio;
869
- });
864
+ const cardIsVisible = (0, $2MCgq$useProductCardIsVisible)();
870
865
  return (()=>{
871
866
  var _el$17 = $29535f590238371c$var$_tmpl$15();
872
867
  (0, $2MCgq$use)((element)=>{
873
868
  element.disablePictureInPicture = true;
874
869
  (0, $2MCgq$createEffect)(()=>{
875
- if ((isVisible() || props.forceIsVisible_) && tabIsVisible() && !hiddenInImageCarousel()) element.play().catch((e)=>(0, $2MCgq$dwarn)("Error playing video", e));
870
+ if ((cardIsVisible() || props.forceIsVisible_) && tabIsVisible() && !props.swipedPastVideo_) element.play().catch((e)=>(0, $2MCgq$dwarn)("Error playing video", e));
876
871
  else element.pause();
877
872
  });
878
873
  }, _el$17);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@depict-ai/portal-components",
3
- "version": "2.7.31",
3
+ "version": "2.7.33",
4
4
  "packageManager": "yarn@3.2.2",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",
@@ -243,9 +243,6 @@ export function DefaultSolidProductCard(
243
243
  return { "--flex-alignment": flexAlignment, "--alignment": alignment };
244
244
  };
245
245
 
246
- createEffect(() => dlog("Got passed options", JSON.parse(JSON.stringify(configuredOptions_()))));
247
- createEffect(() => dlog("Got passed display", JSON.parse(JSON.stringify(display()))));
248
-
249
246
  createEffect(() => noHoverSupport_() && setCardIsHovered(false));
250
247
  // For switch from placeholders to product
251
248
  createEffect(
@@ -694,17 +691,31 @@ function ImagesAndVideos({
694
691
  const containerClasses = () => ["image-video", "border-radius-" + configuredOptions_().image_radius] as const;
695
692
  const productCardIsVisible = useProductCardIsVisible();
696
693
  const hasBeenVisible = createMemo<boolean | undefined>(prev => prev || productCardIsVisible() || forceIsVisible_());
694
+ const video_urls = () => video_()?.video_urls;
695
+ const hasVideo = createMemo(() => video_urls()?.length);
696
+ const hoverImageDisabled = createMemo(() => !configuredOptions_().use_hover_image || noHoverSupport_());
697
+ const hasEnoughImagesForSlider = createMemo<boolean | undefined>(prev => {
698
+ if (prev) return prev; // If we had it once, keep the slider (since removing it is not expected by some code IIRC and could look glitchy)
699
+ let minImagesAvailableToEnableSwipe = 2;
700
+ if (hasVideo()) {
701
+ minImagesAvailableToEnableSwipe--;
702
+ } else if (!hoverImageDisabled()) {
703
+ minImagesAvailableToEnableSwipe++;
704
+ }
705
+ return (image_urls_()?.length as number) >= minImagesAvailableToEnableSwipe;
706
+ });
697
707
  const slidable = createMemo(
698
708
  () =>
699
709
  // Don't make cards swipable inside of sliders (PLP slider or recs slider)
700
710
  !(useSlidableInformation() || PLPLayout?.()?.startsWith("slider")) &&
701
711
  configuredOptions_().image_carousel &&
702
712
  // Delay creation of slider until card has been visible. We can't do it until the user interacts with it because it sometimes glitches the hover effect, but initialising the slider takes some time (need to compute if the buttons should be shown, there's a Mutationobserver, etc) so it's good to not initialise all at once (for example when going back)
703
- hasBeenVisible()
713
+ // Don't delay the creation of the slider if there's a video, since (contrary to what I've observed with images) the move of the video in the DOM will abort the playback, which will abort the network request, which delays the playback of the video significantly
714
+ (hasBeenVisible() || hasVideo()) &&
715
+ hasEnoughImagesForSlider()
704
716
  );
705
- const hoverImageDisabled = createMemo(() => !configuredOptions_().use_hover_image || noHoverSupport_());
706
- const video_urls = () => video_()?.video_urls;
707
717
  const [userTriedSliding, setUserTriedSliding] = createSignal(false);
718
+ const [swipedPastVideo_, setSwipedPastVideo] = createSignal(false);
708
719
 
709
720
  const Container = (props: { children: JSX.Element }) => {
710
721
  const resolved = children(() => props.children);
@@ -758,10 +769,16 @@ function ImagesAndVideos({
758
769
  // Actually render (and load) the other images when the slider gets swiped
759
770
  slidableInformation!.intersectionEntries_(); // Re-check when intersecting entries change
760
771
  const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
761
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
762
772
  if (1 in intersectingsObject!) {
763
773
  setUserTriedSliding(true);
764
774
  }
775
+
776
+ // Pause video when swiping to the next image
777
+ // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
778
+ if (!intersectingsObject || !Object.keys(intersectingsObject).length) return;
779
+ // Video is always the first card in the slider
780
+ const ratio = intersectingsObject?.[0]?.intersectionRatio;
781
+ setSwipedPastVideo(!ratio);
765
782
  });
766
783
 
767
784
  return resolved as unknown as JSX.Element;
@@ -773,7 +790,7 @@ function ImagesAndVideos({
773
790
  );
774
791
  };
775
792
  const [itemsWantingToBeRendered, setItemsWantingToBeRendered] = createSignal<symbol[]>([], { equals: false });
776
- // When slidable, only render items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
793
+ // When slidable, only render extra items (and therefore fetch images) when the user actually tried swiping -> this is for better network performance
777
794
  const MaybeShowLazily = (props: { children: JSX.Element }) => {
778
795
  const us = Symbol();
779
796
  setItemsWantingToBeRendered(prev => {
@@ -782,14 +799,18 @@ function ImagesAndVideos({
782
799
  });
783
800
  onCleanup(() => setItemsWantingToBeRendered(prev => prev.filter(item => item !== us)));
784
801
  return (
785
- <Show when={!slidable() || itemsWantingToBeRendered()[0] === us || userTriedSliding()}>{props.children}</Show>
802
+ // Render the first two items immediately, so the slider can be swiped and there is an image when it's done.
803
+ // After it has been swiped, render (and fetch the images) for the rest.
804
+ <Show when={!slidable() || userTriedSliding() || itemsWantingToBeRendered().indexOf(us) < 2}>
805
+ {props.children}
806
+ </Show>
786
807
  );
787
808
  };
788
809
 
789
810
  return (
790
811
  <Show when={image_urls_()} fallback={<ImagePlaceholder aspectRatio={aspectRatio_()} />}>
791
812
  <Container>
792
- <Show when={video_urls()?.length}>
813
+ <Show when={hasVideo()}>
793
814
  <MaybeShowLazily>
794
815
  <div class="media-item video">
795
816
  <ImageContainer aspectRatio={aspectRatio_()}>
@@ -797,12 +818,13 @@ function ImagesAndVideos({
797
818
  video_sources_={video_urls() as [string, ...string[]]}
798
819
  poster_={video_()?.preview_image_url || image_urls_()?.[0]}
799
820
  forceIsVisible_={forceIsVisible_()}
821
+ swipedPastVideo_={swipedPastVideo_()}
800
822
  />
801
823
  </ImageContainer>
802
824
  </div>
803
825
  </MaybeShowLazily>
804
826
  </Show>
805
- <Show when={!video_urls()?.length || slidable()}>
827
+ <Show when={!hasVideo() || slidable()}>
806
828
  <For each={slidable() ? image_urls_() : image_urls_()?.slice(0, 1)}>
807
829
  {(image_url, index) => (
808
830
  <Show when={hoverImageDisabled() || index() !== 1}>
@@ -830,15 +852,17 @@ function ImagesAndVideos({
830
852
  )}
831
853
  </For>
832
854
  </Show>
833
- <Show when={slidable() && itemsWantingToBeRendered().length > 1 && !userTriedSliding()}>
834
- <ImagePlaceholder width="100%" height="" />
835
- </Show>
836
855
  </Container>
837
856
  </Show>
838
857
  );
839
858
  }
840
859
 
841
- function Video(props: { video_sources_: [string, ...string[]]; poster_?: string; forceIsVisible_?: boolean }) {
860
+ function Video(props: {
861
+ video_sources_: [string, ...string[]];
862
+ poster_?: string;
863
+ forceIsVisible_?: boolean;
864
+ swipedPastVideo_: boolean;
865
+ }) {
842
866
  // Making some assumptions for shopify here rn, change those if wanting to support other browsers too
843
867
 
844
868
  const tabIsVisible = useVisibilityState();
@@ -854,18 +878,7 @@ function Video(props: { video_sources_: [string, ...string[]]; poster_?: string;
854
878
  return sources;
855
879
  });
856
880
  const productCardIndexAccessor = useProductCardIndex();
857
- const isVisible = useProductCardIsVisible();
858
- const slidableInformation = useSlidableInformation();
859
- const hiddenInImageCarousel = createMemo(() => {
860
- // Pause video when swiping to the next image
861
- slidableInformation?.intersectionEntries_(); // Re-check when intersecting entries change
862
- const intersectingsObject = slidableInformation?.slider_.intersecting_items_object;
863
- // If intersection observers haven't started yet or we aren't in a slider, we count as visible for faster playback
864
- if (!intersectingsObject || !Object.keys(intersectingsObject).length) return false;
865
- // Video is always the first card in the slider
866
- const ratio = intersectingsObject?.[0]?.intersectionRatio;
867
- return !ratio;
868
- });
881
+ const cardIsVisible = useProductCardIsVisible();
869
882
 
870
883
  return (
871
884
  <video
@@ -879,7 +892,7 @@ function Video(props: { video_sources_: [string, ...string[]]; poster_?: string;
879
892
  ref={element => {
880
893
  element.disablePictureInPicture = true;
881
894
  createEffect(() => {
882
- if ((isVisible() || props.forceIsVisible_) && tabIsVisible() && !hiddenInImageCarousel()) {
895
+ if ((cardIsVisible() || props.forceIsVisible_) && tabIsVisible() && !props.swipedPastVideo_) {
883
896
  element.play().catch(e => dwarn("Error playing video", e));
884
897
  } else {
885
898
  element.pause();