Compare commits

..

4 Commits

6 changed files with 79 additions and 19 deletions

View File

@@ -62,7 +62,13 @@
(click)="selectImage(idx)" (click)="selectImage(idx)"
[attr.aria-label]="'Select image ' + (idx + 1)" [attr.aria-label]="'Select image ' + (idx + 1)"
> >
<img [src]="image" alt="Product thumbnail" class="w-100 h-100 object-fit-cover" /> <img
[src]="image"
alt="Product thumbnail"
loading="lazy"
decoding="async"
class="w-100 h-100 object-fit-cover"
/>
</button> </button>
} }
</div> </div>

View File

@@ -23,6 +23,32 @@
</p> </p>
} @else { } @else {
@for (group of catalog(); track group.id; let first = $first) { @for (group of catalog(); track group.id; let first = $first) {
@if (first) {
<ng-container
[ngTemplateOutlet]="catalogGroup"
[ngTemplateOutletContext]="{ $implicit: group, prioritizeFirstImage: true }"
/>
} @else {
@defer (on viewport; prefetch on idle) {
<ng-container
[ngTemplateOutlet]="catalogGroup"
[ngTemplateOutletContext]="{ $implicit: group, prioritizeFirstImage: false }"
/>
} @placeholder {
<section
class="store-home__deferred-group-placeholder"
[attr.aria-label]="group.title"
></section>
}
}
}
}
<ng-template
#catalogGroup
let-group
let-prioritizeFirstImage="prioritizeFirstImage"
>
<app-store-section [attr.id]="group.code" [title]="group.title"> <app-store-section [attr.id]="group.code" [title]="group.title">
<app-product-list <app-product-list
[layout]="group.layout" [layout]="group.layout"
@@ -30,7 +56,7 @@
[items]="group.items" [items]="group.items"
[loading]="isGroupLoading(group.id)" [loading]="isGroupLoading(group.id)"
[loadImages]="!hasMainCarouselImages() || mainCarouselReady()" [loadImages]="!hasMainCarouselImages() || mainCarouselReady()"
[prioritizeFirstImage]="first && !hasMainCarouselImages()" [prioritizeFirstImage]="prioritizeFirstImage && !hasMainCarouselImages()"
[unavailableVariantIds]="unavailableVariantIds()" [unavailableVariantIds]="unavailableVariantIds()"
[savingProductIds]="savingProductIds()" [savingProductIds]="savingProductIds()"
(buy)="onBuyProduct($event)" (buy)="onBuyProduct($event)"
@@ -38,8 +64,7 @@
(pageChange)="onPageChange(group.id, $event)" (pageChange)="onPageChange(group.id, $event)"
/> />
</app-store-section> </app-store-section>
} </ng-template>
}
@if (additionalInfo(); as content) { @if (additionalInfo(); as content) {
<app-store-section class="store-home__additional-info" title="Información adicional"> <app-store-section class="store-home__additional-info" title="Información adicional">

View File

@@ -15,6 +15,13 @@ app-store-section[id] {
scroll-margin-top: 8rem; scroll-margin-top: 8rem;
} }
.store-home__deferred-group-placeholder {
display: block;
min-height: clamp(24rem, 42vw, 34rem);
content-visibility: auto;
contain-intrinsic-size: auto 30rem;
}
:host > .store-home__additional-info:not(:first-child) { :host > .store-home__additional-info:not(:first-child) {
margin-top: clamp(3rem, 6vw, 5rem); margin-top: clamp(3rem, 6vw, 5rem);
} }

View File

@@ -8,6 +8,7 @@ import {
inject, inject,
signal, signal,
} from '@angular/core'; } from '@angular/core';
import { NgTemplateOutlet } from '@angular/common';
import { HttpErrorResponse } from '@angular/common/http'; import { HttpErrorResponse } from '@angular/common/http';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { finalize, Subscription } from 'rxjs'; import { finalize, Subscription } from 'rxjs';
@@ -44,6 +45,7 @@ import {
ProductListComponent, ProductListComponent,
HeroBannerComponent, HeroBannerComponent,
MainCarouselComponent, MainCarouselComponent,
NgTemplateOutlet,
], ],
templateUrl: './store-home-page.component.html', templateUrl: './store-home-page.component.html',
styleUrl: './store-home-page.component.scss', styleUrl: './store-home-page.component.scss',

View File

@@ -59,6 +59,16 @@ describe('CarouselComponent', () => {
expect(articles[1].getAttribute('data-index')).toBe('1'); expect(articles[1].getAttribute('data-index')).toBe('1');
}); });
it('permite inspeccionar las páginas antes de medir el viewport sin generar listas enormes', () => {
const carousel = fixture.componentInstance.carousel();
fixture.componentInstance.circular.set(true);
carousel['itemsPerPage'].set(Number.MAX_SAFE_INTEGER);
expect(carousel['circularPages']()).toEqual([]);
expect(carousel['createPage']('current', 0).items.map((entry) => entry.item.id))
.toEqual([1, 2, 3]);
});
it('expone una región accesible y controles con etiquetas', () => { it('expone una región accesible y controles con etiquetas', () => {
const region = fixture.nativeElement.querySelector('[role="region"]'); const region = fixture.nativeElement.querySelector('[role="region"]');
const buttons = fixture.nativeElement.querySelectorAll('button'); const buttons = fixture.nativeElement.querySelectorAll('button');

View File

@@ -70,6 +70,10 @@ export class CarouselComponent<T> implements AfterViewInit {
); );
protected readonly isCircularLayout = computed(() => this.circular() && this.pageCount() > 1); protected readonly isCircularLayout = computed(() => this.circular() && this.pageCount() > 1);
protected readonly circularPages = computed<CarouselPage<T>[]>(() => { protected readonly circularPages = computed<CarouselPage<T>[]>(() => {
if (!this.isCircularLayout()) {
return [];
}
const pageCount = this.pageCount(); const pageCount = this.pageCount();
const currentPage = this.normalizePage(this.currentPage(), pageCount); const currentPage = this.normalizePage(this.currentPage(), pageCount);
@@ -270,14 +274,20 @@ export class CarouselComponent<T> implements AfterViewInit {
} }
private createPage(slot: CarouselPage<T>['slot'], page: number): CarouselPage<T> { private createPage(slot: CarouselPage<T>['slot'], page: number): CarouselPage<T> {
const sourceItems = this.items();
// Layout has not necessarily been measured when a computed value is inspected.
const pageSize = Math.min(this.itemsPerPage(), sourceItems.length);
if (pageSize === 0) {
return { slot, items: [] };
}
const pageCount = this.pageCount(); const pageCount = this.pageCount();
const normalizedPage = this.normalizePage(page, pageCount); const normalizedPage = this.normalizePage(page, pageCount);
const start = normalizedPage * this.itemsPerPage(); const start = normalizedPage * pageSize;
const items: CarouselPageItem<T>[] = []; const items: CarouselPageItem<T>[] = [];
for (let offset = 0; offset < this.itemsPerPage(); offset += 1) { for (let offset = 0; offset < pageSize; offset += 1) {
const index = (start + offset) % this.items().length; const index = (start + offset) % sourceItems.length;
items.push({ item: this.items()[index], index }); items.push({ item: sourceItems[index], index });
} }
return { slot, items }; return { slot, items };