@@ -4,9 +4,13 @@ export class CarouselComponent extends HTMLElement {
44 constructor ( ) {
55 super ( ) ;
66 this . attachShadow ( { mode : "open" } ) ;
7+ this . isPortrait = false ;
8+ this . PORTRAIT_WIDTH = 250 ;
9+ this . LANDSCAPE_WIDTH = 500 ;
710 }
811
9- connectedCallback ( ) {
12+ async connectedCallback ( ) {
13+ await this . checkImageOrientation ( ) ;
1014 this . render ( ) ;
1115 this . setupCarousel ( ) ;
1216 }
@@ -37,7 +41,9 @@ export class CarouselComponent extends HTMLElement {
3741 }
3842
3943 .carousel-item {
40- flex: 0 0 500px;
44+ flex: 0 0 ${
45+ this . isPortrait ? this . PORTRAIT_WIDTH : this . LANDSCAPE_WIDTH
46+ } px;
4147 max-inline-size: 100%;
4248 scroll-snap-align: center;
4349 display: flex;
@@ -93,6 +99,33 @@ export class CarouselComponent extends HTMLElement {
9399 return [ data . carousel_assets , data . base_url ] ;
94100 }
95101
102+ async checkImageOrientation ( ) {
103+ const assets = this . carouselAssets [ 0 ] ;
104+ const baseUrl = this . carouselAssets [ 1 ] ;
105+
106+ const firstWebpImage = assets . find ( ( asset ) => asset . endsWith ( ".webp" ) ) ;
107+
108+ if ( firstWebpImage ) {
109+ const imageUrl = `https://raw.githubusercontent.com/LiquidGalaxyLAB/Data/refs/heads/main${
110+ baseUrl + firstWebpImage
111+ } `;
112+
113+ try {
114+ const img = new Image ( ) ;
115+ await new Promise ( ( resolve , reject ) => {
116+ img . onload = ( ) => resolve ( ) ;
117+ img . onerror = ( ) => reject ( ) ;
118+ img . src = imageUrl ;
119+ } ) ;
120+
121+ this . isPortrait = img . height > img . width ;
122+ } catch ( error ) {
123+ console . warn ( "Could not load image for orientation check:" , error ) ;
124+ this . isPortrait = false ;
125+ }
126+ }
127+ }
128+
96129 setupCarousel ( ) {
97130 const carousel = this . shadowRoot . querySelector ( ".carousel" ) ;
98131 const prevButton = this . shadowRoot . querySelector ( ".prev" ) ;
@@ -105,7 +138,9 @@ export class CarouselComponent extends HTMLElement {
105138 scrollToNext ( carousel ) {
106139 const prevButton = this . shadowRoot . querySelector ( ".prev" ) ;
107140 const nextButton = this . shadowRoot . querySelector ( ".next" ) ;
108- const itemWidth = 500 ;
141+ const itemWidth = this . isPortrait
142+ ? this . PORTRAIT_WIDTH
143+ : this . LANDSCAPE_WIDTH ;
109144 const maxScrollLeft = carousel . scrollWidth - carousel . clientWidth ;
110145 if ( carousel . scrollLeft + itemWidth >= maxScrollLeft )
111146 nextButton . setAttribute ( "disabled" , "true" ) ;
@@ -117,7 +152,9 @@ export class CarouselComponent extends HTMLElement {
117152 scrollToPrev ( carousel ) {
118153 const prevButton = this . shadowRoot . querySelector ( ".prev" ) ;
119154 const nextButton = this . shadowRoot . querySelector ( ".next" ) ;
120- const itemWidth = 500 ;
155+ const itemWidth = this . isPortrait
156+ ? this . PORTRAIT_WIDTH
157+ : this . LANDSCAPE_WIDTH ;
121158 if ( carousel . scrollLeft <= 0 ) prevButton . setAttribute ( "disabled" , "true" ) ;
122159 nextButton ?. removeAttribute ( "disabled" ) ;
123160
0 commit comments