@lit-roa/hero 0.1.1 → 0.2.0

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/src/hero.ts CHANGED
@@ -1,556 +1,587 @@
1
- import { LitElement, css, html, nothing } from 'lit';
2
- import { customElement, property, state } from 'lit/decorators.js';
3
- import { emitir, estilosBase, tokens } from '@lit-roa/base';
4
- import '@lit-roa/carrusel';
5
- import type { DetalleCambioDiapositiva } from '@lit-roa/carrusel';
6
-
7
- export interface BotonHero {
8
- texto: string;
9
- href: string;
10
- /** `principal` (relleno, por omisión) o `secundario` (contorno). */
11
- variante?: 'principal' | 'secundario';
12
- }
13
-
14
- export interface AnuncioHero {
15
- /** Identificador libre que viaja en `clic-hero`. */
16
- id?: string;
17
- titulo: string;
18
- texto?: string;
19
- /** Texto chico arriba del título (por ejemplo "Anuncio"). */
20
- antetitulo?: string;
21
- /** Etiqueta resaltada arriba del título (por ejemplo la fecha de un evento). */
22
- etiqueta?: string;
23
- imagen?: string;
24
- /** Imagen para pantallas de hasta 640 px. */
25
- imagenCelular?: string;
26
- imagenAlt?: string;
27
- /** Texto del botón; sin él no hay botón. */
28
- boton?: string;
29
- href?: string;
30
- }
31
-
32
- export interface DetalleClicHero {
33
- /** `id` del anuncio; no viene en los botones de la bienvenida. */
34
- id?: string;
35
- href: string;
36
- }
37
-
38
- export type DisposicionHero = 'portada' | 'dividido' | 'escaparate';
39
-
40
- /**
41
- * Carrusel principal de la página de inicio: siempre empieza con una
42
- * diapositiva de bienvenida (antetítulo, título, texto, logo y hasta dos
43
- * botones) y le siguen los anuncios. La portada de la tienda queda de fondo
44
- * fijo de todo el carrusel; sin portada, un degradado del color principal.
45
- *
46
- * Tres disposiciones:
47
- * - `portada` (por omisión): la portada a todo lo ancho; en los anuncios se
48
- * tiñe del color principal y la imagen va en una tarjeta a la derecha. En
49
- * celular los anuncios no muestran imagen.
50
- * - `dividido`: la portada desenfocada de marco, el texto en una tarjeta
51
- * blanca y la imagen al lado (arriba en celular).
52
- * - `escaparate`: la portada desenfocada, la imagen nítida en una tarjeta y
53
- * pestañas con el título de cada diapositiva y barra de avance.
54
- *
55
- * @fires clic-hero - Al tocar un botón. `detail`: `{ id, href }`. El sitio navega.
56
- * @cssprop --lr-hero-alto - Alto mínimo en escritorio (30rem).
57
- * @cssprop --lr-hero-alto-celular - Alto mínimo en celular (32rem).
58
- * @cssprop --lr-hero-acento - Color de la etiqueta de los anuncios (#facc15).
59
- */
60
- @customElement('lr-hero')
61
- export class LrHero extends LitElement {
62
- static override styles = [
63
- tokens,
64
- estilosBase,
65
- css`
66
- :host {
67
- display: block;
68
- --_oscuro: color-mix(in srgb, var(--_color-primario), #000 50%);
69
- --_acento: var(--lr-hero-acento, #facc15);
70
- --_alto: var(--lr-hero-alto, 30rem);
71
- }
72
- .marco {
73
- position: relative;
74
- isolation: isolate;
75
- overflow: hidden;
76
- border-radius: var(--_radio);
77
- background: linear-gradient(135deg, var(--_oscuro), var(--_color-primario));
78
- color: #fff;
79
- }
80
- .fondo,
81
- .tinte,
82
- .tinte::before,
83
- .tinte::after {
84
- position: absolute;
85
- inset: 0;
86
- z-index: -1;
87
- }
88
- .fondo img {
89
- width: 100%;
90
- height: 100%;
91
- object-fit: cover;
92
- display: block;
93
- }
94
- :host([disposicion='dividido']) .fondo,
95
- :host([disposicion='escaparate']) .fondo {
96
- inset: -3rem;
97
- filter: blur(32px) saturate(1.25);
98
- }
99
- .tinte::before,
100
- .tinte::after {
101
- content: '';
102
- transition: opacity 0.6s;
103
- }
104
- .tinte::after {
105
- opacity: 0;
106
- }
107
- .marco[data-activa='anuncio'] .tinte::before {
108
- opacity: 0;
109
- }
110
- .marco[data-activa='anuncio'] .tinte::after {
111
- opacity: 1;
112
- }
113
- /* Portada: velo oscuro del lado del texto en la bienvenida, color de la marca en los anuncios. */
114
- .tinte::before {
115
- background: linear-gradient(90deg, rgb(10 12 30 / 0.82) 0%, rgb(10 12 30 / 0.55) 45%, rgb(10 12 30 / 0) 80%);
116
- }
117
- .tinte::after {
118
- background: linear-gradient(
119
- 105deg,
120
- color-mix(in srgb, var(--_oscuro) 94%, transparent) 0%,
121
- color-mix(in srgb, var(--_color-primario) 82%, transparent) 45%,
122
- color-mix(in srgb, var(--_oscuro) 50%, transparent) 100%
123
- );
124
- }
125
- :host([disposicion='dividido']) .tinte::before,
126
- :host([disposicion='dividido']) .tinte::after,
127
- :host([disposicion='escaparate']) .tinte::before,
128
- :host([disposicion='escaparate']) .tinte::after {
129
- background: rgb(10 12 30 / 0.45);
130
- }
131
- lr-carrusel {
132
- --lr-carrusel-radio: 0;
133
- --lr-carrusel-avance: var(--_acento);
134
- /* El carrusel pone el color de texto del sitio; aquí manda el del hero. */
135
- color: inherit;
136
- }
137
-
138
- /* ---- Diapositivas ---- */
139
- .diapositiva {
140
- position: relative;
141
- display: flex;
142
- min-height: var(--_alto);
143
- padding: clamp(1.5rem, 5vw, 4rem);
144
- padding-bottom: max(clamp(1.5rem, 5vw, 4rem), var(--lr-carrusel-reserva-abajo, 0px));
145
- gap: 3rem;
146
- align-items: center;
147
- }
148
- .texto {
149
- display: flex;
150
- flex-direction: column;
151
- align-items: flex-start;
152
- gap: 1rem;
153
- max-width: 36rem;
154
- min-width: 0;
155
- }
156
- .antetitulo {
157
- font-size: 0.8125rem;
158
- font-weight: 800;
159
- letter-spacing: 0.08em;
160
- text-transform: uppercase;
161
- color: var(--_acento);
162
- }
163
- .etiqueta {
164
- display: inline-flex;
165
- padding: 0.375rem 0.75rem;
166
- border-radius: 999px;
167
- background: var(--_acento);
168
- color: #1f2937;
169
- font-size: 0.8125rem;
170
- font-weight: 700;
171
- }
172
- h2 {
173
- margin: 0;
174
- font-size: clamp(1.875rem, 4.5vw, 3.25rem);
175
- line-height: 1.06;
176
- font-weight: 800;
177
- letter-spacing: -0.02em;
178
- text-wrap: balance;
179
- }
180
- .anuncio h2 {
181
- font-size: clamp(1.75rem, 4vw, 2.875rem);
182
- }
183
- p {
184
- margin: 0;
185
- font-size: clamp(1rem, 1.8vw, 1.1875rem);
186
- line-height: 1.5;
187
- opacity: 0.92;
188
- }
189
- .botones {
190
- display: flex;
191
- flex-wrap: wrap;
192
- gap: 0.75rem;
193
- margin-top: 0.5rem;
194
- }
195
- .boton {
196
- display: inline-flex;
197
- align-items: center;
198
- justify-content: center;
199
- height: 3rem;
200
- padding: 0 1.375rem;
201
- border-radius: calc(var(--_radio) / 1.5);
202
- font-weight: 700;
203
- text-decoration: none;
204
- white-space: nowrap;
205
- background: var(--_color-primario);
206
- color: var(--_color-sobre-primario);
207
- border: 1.5px solid transparent;
208
- }
209
- .boton.secundario {
210
- background: transparent;
211
- color: #fff;
212
- border-color: rgb(255 255 255 / 0.85);
213
- }
214
- .anuncio .boton {
215
- background: #fff;
216
- color: #111827;
217
- }
218
- .boton:hover {
219
- filter: brightness(0.94);
220
- }
221
- .boton:focus-visible {
222
- outline: 2px solid #fff;
223
- outline-offset: 3px;
224
- }
225
- .imagen {
226
- position: relative;
227
- flex: 1 1 0;
228
- align-self: stretch;
229
- min-width: 0;
230
- max-height: calc(var(--_alto) - 5rem);
231
- border-radius: calc(var(--_radio) * 1.25);
232
- overflow: hidden;
233
- box-shadow: 0 24px 60px rgb(0 0 0 / 0.4), 0 0 0 1px rgb(255 255 255 / 0.15);
234
- }
235
- .imagen img:not(.logo) {
236
- position: absolute;
237
- inset: 0;
238
- width: 100%;
239
- height: 100%;
240
- object-fit: cover;
241
- }
242
- .anuncio .texto {
243
- flex: 1 1 0;
244
- }
245
- .logo {
246
- width: 5.25rem;
247
- height: 5.25rem;
248
- border-radius: 1.25rem;
249
- object-fit: contain;
250
- background: #fff;
251
- box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
252
- }
253
-
254
- /* ---- Dividido ---- */
255
- :host([disposicion='dividido']) .diapositiva {
256
- padding: 1.75rem;
257
- padding-bottom: max(1.75rem, var(--lr-carrusel-reserva-abajo, 0px));
258
- gap: 1.5rem;
259
- align-items: stretch;
260
- }
261
- :host([disposicion='dividido']) .texto {
262
- flex: 1 1 0;
263
- max-width: none;
264
- justify-content: center;
265
- padding: clamp(1.5rem, 4vw, 3rem);
266
- border-radius: calc(var(--_radio) * 1.25);
267
- background: #fff;
268
- color: var(--_color-texto);
269
- box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
270
- }
271
- :host([disposicion='dividido']) .antetitulo {
272
- color: var(--_color-primario);
273
- }
274
- :host([disposicion='dividido']) p {
275
- color: var(--_color-texto-suave);
276
- opacity: 1;
277
- }
278
- :host([disposicion='dividido']) .boton.secundario {
279
- color: var(--_color-primario);
280
- border-color: var(--_color-primario);
281
- }
282
- :host([disposicion='dividido']) .anuncio .boton {
283
- background: var(--_color-primario);
284
- color: var(--_color-sobre-primario);
285
- }
286
- :host([disposicion='dividido']) .imagen {
287
- max-height: none;
288
- box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
289
- }
290
- :host([disposicion='dividido']) .imagen.sin-imagen {
291
- background: linear-gradient(135deg, var(--_oscuro), var(--_color-primario));
292
- }
293
- :host([disposicion='dividido']) .imagen .logo {
294
- position: absolute;
295
- left: 1.5rem;
296
- bottom: 1.5rem;
297
- }
298
- :host([disposicion='dividido']) .imagen.sin-imagen .logo {
299
- left: calc(50% - 2.625rem);
300
- bottom: calc(50% - 2.625rem);
301
- }
302
-
303
- /* ---- Escaparate ---- */
304
- :host([disposicion='escaparate']) .bienvenida {
305
- justify-content: center;
306
- text-align: center;
307
- }
308
- :host([disposicion='escaparate']) .bienvenida .texto {
309
- align-items: center;
310
- max-width: 40rem;
311
- }
312
- :host([disposicion='escaparate']) .bienvenida .botones {
313
- justify-content: center;
314
- }
315
- :host([disposicion='escaparate']) .bienvenida .boton.principal {
316
- background: #fff;
317
- color: #111827;
318
- }
319
- :host([disposicion='escaparate']) .imagen {
320
- flex: 0 1 46%;
321
- align-self: center;
322
- aspect-ratio: 3 / 2;
323
- }
324
-
325
- @media (max-width: 640px) {
326
- :host {
327
- --_alto: var(--lr-hero-alto-celular, 32rem);
328
- }
329
- .diapositiva {
330
- flex-direction: column;
331
- justify-content: flex-end;
332
- align-items: stretch;
333
- gap: 1.25rem;
334
- padding: 1.5rem 1.375rem;
335
- padding-bottom: max(1.5rem, var(--lr-carrusel-reserva-abajo, 0px));
336
- }
337
- .tinte::before {
338
- background: linear-gradient(0deg, rgb(10 12 30 / 0.92) 0%, rgb(10 12 30 / 0.6) 45%, rgb(10 12 30 / 0.05) 85%);
339
- }
340
- .tinte::after {
341
- background: linear-gradient(
342
- 0deg,
343
- color-mix(in srgb, var(--_oscuro) 96%, transparent) 0%,
344
- color-mix(in srgb, var(--_color-primario) 85%, transparent) 50%,
345
- color-mix(in srgb, var(--_oscuro) 55%, transparent) 100%
346
- );
347
- }
348
- .texto,
349
- .anuncio .texto {
350
- flex: none;
351
- }
352
- .botones {
353
- flex-direction: column;
354
- align-self: stretch;
355
- }
356
- .boton {
357
- width: 100%;
358
- }
359
- /* Portada: los anuncios no muestran imagen en celular. */
360
- :host(:not([disposicion])) .anuncio .imagen,
361
- :host([disposicion='portada']) .anuncio .imagen,
362
- :host([ocultar-imagen-celular]) .anuncio .imagen {
363
- display: none;
364
- }
365
- .imagen {
366
- flex: none;
367
- order: -1;
368
- height: 9.5rem;
369
- max-height: none;
370
- }
371
- :host([disposicion='escaparate']) .diapositiva {
372
- justify-content: center;
373
- text-align: center;
374
- }
375
- :host([disposicion='escaparate']) .texto {
376
- align-items: center;
377
- align-self: center;
378
- }
379
- :host([disposicion='escaparate']) .imagen {
380
- flex: none;
381
- aspect-ratio: auto;
382
- align-self: stretch;
383
- }
384
- :host([disposicion='dividido']) .diapositiva {
385
- gap: 0;
386
- padding: 0.875rem;
387
- padding-bottom: max(0.875rem, var(--lr-carrusel-reserva-abajo, 0px));
388
- justify-content: flex-start;
389
- }
390
- :host([disposicion='dividido']) .texto {
391
- flex: 1 0 auto;
392
- justify-content: flex-start;
393
- padding: 1.25rem;
394
- }
395
- :host([disposicion='dividido']) .anuncio:not(:has(.imagen)) .texto,
396
- :host([ocultar-imagen-celular][disposicion='dividido']) .anuncio .texto {
397
- justify-content: center;
398
- }
399
- :host([disposicion='dividido']) .imagen {
400
- height: 11rem;
401
- border-radius: calc(var(--_radio) * 1.25) calc(var(--_radio) * 1.25) 0 0;
402
- box-shadow: none;
403
- }
404
- :host([disposicion='dividido']) .imagen + .texto,
405
- :host([disposicion='dividido']) .texto:has(+ .imagen) {
406
- border-radius: 0 0 calc(var(--_radio) * 1.25) calc(var(--_radio) * 1.25);
407
- }
408
- :host([ocultar-imagen-celular][disposicion='dividido']) .anuncio .texto {
409
- border-radius: calc(var(--_radio) * 1.25);
410
- }
411
- :host([disposicion='dividido']) .imagen .logo {
412
- width: 4rem;
413
- height: 4rem;
414
- border-radius: 0.875rem;
415
- left: 1rem;
416
- bottom: 1rem;
417
- }
418
- :host([disposicion='dividido']) .imagen.sin-imagen .logo {
419
- left: calc(50% - 2rem);
420
- bottom: calc(50% - 2rem);
421
- }
422
- }
423
- `,
424
- ];
425
-
426
- @property({ reflect: true }) disposicion: DisposicionHero = 'portada';
427
-
428
- /** Portada de la tienda: fondo fijo de todo el carrusel. */
429
- @property() portada = '';
430
-
431
- /** Portada para pantallas de hasta 640 px. */
432
- @property({ attribute: 'portada-celular' }) portadaCelular = '';
433
-
434
- /** Logo de la tienda (bienvenida de `dividido` y `escaparate`). */
435
- @property() logo = '';
436
-
437
- @property({ attribute: 'logo-alt' }) logoAlt = '';
438
-
439
- @property() antetitulo = '';
440
-
441
- @property() titulo = '';
442
-
443
- @property() texto = '';
444
-
445
- /** Hasta dos botones de la bienvenida (por ejemplo Productos y Eventos). */
446
- @property({ attribute: false }) botones: BotonHero[] = [];
447
-
448
- @property({ attribute: false }) anuncios: AnuncioHero[] = [];
449
-
450
- /** Milisegundos entre diapositivas; `0` = no avanza solo. */
451
- @property({ type: Number }) intervalo = 7000;
452
-
453
- /** Oculta la imagen de los anuncios en celular también en `dividido` y `escaparate`. */
454
- @property({ type: Boolean, reflect: true, attribute: 'ocultar-imagen-celular' }) ocultarImagenCelular = false;
455
-
456
- @property() etiqueta = 'Inicio';
457
-
458
- @state() private activa = 0;
459
-
460
- override render() {
461
- const escaparate = this.disposicion === 'escaparate';
462
- return html`
463
- <div class="marco" data-activa=${this.activa === 0 ? 'bienvenida' : 'anuncio'}>
464
- ${this.portada
465
- ? html`<picture class="fondo" aria-hidden="true">
466
- ${this.portadaCelular ? html`<source media="(max-width: 640px)" srcset=${this.portadaCelular} />` : nothing}
467
- <img src=${this.portada} alt="" fetchpriority="high" />
468
- </picture>`
469
- : nothing}
470
- <div class="tinte" aria-hidden="true"></div>
471
- <lr-carrusel
472
- etiqueta=${this.etiqueta}
473
- intervalo=${this.intervalo}
474
- ?puntos-encima=${!escaparate}
475
- ?pestanas=${escaparate}
476
- efecto=${escaparate ? 'desvanecer' : 'deslizar'}
477
- @cambio-diapositiva=${this.alCambiar}
478
- >
479
- ${this.bienvenida()} ${this.anuncios.map((a) => this.anuncio(a))}
480
- </lr-carrusel>
481
- </div>
482
- `;
483
- }
484
-
485
- private bienvenida() {
486
- const dividido = this.disposicion === 'dividido';
487
- const logo = this.logo ? html`<img class="logo" src=${this.logo} alt=${this.logoAlt} />` : nothing;
488
- const botones = this.botones.slice(0, 2);
489
- return html`<article class="diapositiva bienvenida" data-pestana=${this.titulo || 'Bienvenida'} data-pestana-detalle="Inicio">
490
- <div class="texto">
491
- ${this.disposicion === 'escaparate' ? logo : nothing}
492
- ${this.antetitulo ? html`<span class="antetitulo">${this.antetitulo}</span>` : nothing}
493
- ${this.titulo ? html`<h2>${this.titulo}</h2>` : nothing}
494
- ${this.texto ? html`<p>${this.texto}</p>` : nothing}
495
- ${botones.length
496
- ? html`<div class="botones">
497
- ${botones.map(
498
- (b, i) => html`<a
499
- class="boton ${b.variante ?? (i === 0 ? 'principal' : 'secundario')}"
500
- href=${b.href}
501
- @click=${(e: MouseEvent) => this.alClic(e, b.href)}
502
- >${b.texto}</a
503
- >`
504
- )}
505
- </div>`
506
- : nothing}
507
- </div>
508
- ${dividido
509
- ? html`<div class="imagen ${this.portada ? '' : 'sin-imagen'}">
510
- ${this.portada ? html`<img src=${this.portadaCelular || this.portada} alt="" />` : nothing} ${logo}
511
- </div>`
512
- : nothing}
513
- </article>`;
514
- }
515
-
516
- private anuncio(a: AnuncioHero) {
517
- return html`<article class="diapositiva anuncio" data-pestana=${a.titulo} data-pestana-detalle=${a.etiqueta || a.antetitulo || 'Anuncio'}>
518
- <div class="texto">
519
- ${a.etiqueta ? html`<span class="etiqueta">${a.etiqueta}</span>` : nothing}
520
- ${a.antetitulo ? html`<span class="antetitulo">${a.antetitulo}</span>` : nothing}
521
- <h2>${a.titulo}</h2>
522
- ${a.texto ? html`<p>${a.texto}</p>` : nothing}
523
- ${a.boton && a.href
524
- ? html`<div class="botones">
525
- <a class="boton" href=${a.href} @click=${(e: MouseEvent) => this.alClic(e, a.href!, a.id)}>${a.boton}</a>
526
- </div>`
527
- : nothing}
528
- </div>
529
- ${a.imagen
530
- ? html`<div class="imagen">
531
- <picture>
532
- ${a.imagenCelular ? html`<source media="(max-width: 640px)" srcset=${a.imagenCelular} />` : nothing}
533
- <img src=${a.imagen} alt=${a.imagenAlt ?? ''} loading="lazy" />
534
- </picture>
535
- </div>`
536
- : nothing}
537
- </article>`;
538
- }
539
-
540
- private alCambiar(evento: CustomEvent<DetalleCambioDiapositiva>) {
541
- evento.stopPropagation();
542
- this.activa = evento.detail.indice;
543
- }
544
-
545
- private alClic(evento: MouseEvent, href: string, id?: string) {
546
- if (evento.ctrlKey || evento.metaKey) return;
547
- evento.preventDefault();
548
- emitir<DetalleClicHero>(this, 'clic-hero', { id, href });
549
- }
550
- }
551
-
552
- declare global {
553
- interface HTMLElementTagNameMap {
554
- 'lr-hero': LrHero;
555
- }
556
- }
1
+ import { LitElement, css, html, nothing } from 'lit';
2
+ import { customElement, property, state } from 'lit/decorators.js';
3
+ import { emitir, estilosBase, tokens } from '@lit-roa/base';
4
+ import '@lit-roa/carrusel';
5
+ import type { DetalleCambioDiapositiva } from '@lit-roa/carrusel';
6
+
7
+ export interface BotonHero {
8
+ texto: string;
9
+ href: string;
10
+ /** `principal` (relleno, por omisión) o `secundario` (contorno). */
11
+ variante?: 'principal' | 'secundario';
12
+ }
13
+
14
+ export interface AnuncioHero {
15
+ /** Identificador libre que viaja en `clic-hero`. */
16
+ id?: string;
17
+ titulo: string;
18
+ texto?: string;
19
+ /** Texto chico arriba del título (por ejemplo "Anuncio"). */
20
+ antetitulo?: string;
21
+ /** Etiqueta resaltada arriba del título (por ejemplo la fecha de un evento). */
22
+ etiqueta?: string;
23
+ imagen?: string;
24
+ /** Imagen para pantallas de hasta 640 px. */
25
+ imagenCelular?: string;
26
+ imagenAlt?: string;
27
+ /** Texto del botón; sin él no hay botón. */
28
+ boton?: string;
29
+ href?: string;
30
+ }
31
+
32
+ export interface DetalleClicHero {
33
+ /** `id` del anuncio; no viene en los botones de la bienvenida. */
34
+ id?: string;
35
+ href: string;
36
+ }
37
+
38
+ export type DisposicionHero = 'portada' | 'dividido' | 'escaparate';
39
+
40
+ /**
41
+ * Carrusel principal de la página de inicio: siempre empieza con una
42
+ * diapositiva de bienvenida (antetítulo, título, texto, logo y hasta dos
43
+ * botones) y le siguen los anuncios. La portada de la tienda queda de fondo
44
+ * fijo de todo el carrusel; sin portada, un degradado del color principal.
45
+ *
46
+ * Tres disposiciones:
47
+ * - `portada` (por omisión): la portada a todo lo ancho; en los anuncios se
48
+ * tiñe del color principal y la imagen va en una tarjeta a la derecha. En
49
+ * celular los anuncios no muestran imagen.
50
+ * - `dividido`: la portada desenfocada de marco, el texto en una tarjeta
51
+ * blanca y la imagen al lado (arriba en celular).
52
+ * - `escaparate`: la portada desenfocada, la imagen nítida en una tarjeta y
53
+ * pestañas con el título de cada diapositiva y barra de avance.
54
+ *
55
+ * Con `ancho-completo` va de orilla a orilla (sin redondeo) y el contenido
56
+ * queda alineado con el ancho del sitio; se combina con cualquier disposición.
57
+ *
58
+ * @fires clic-hero - Al tocar un botón. `detail`: `{ id, href }`. El sitio navega.
59
+ * @cssprop --lr-hero-alto - Alto mínimo en escritorio (30rem; 34rem con `ancho-completo`).
60
+ * @cssprop --lr-hero-ancho-contenido - Ancho del contenido con `ancho-completo` (1160px).
61
+ * @cssprop --lr-hero-alto-celular - Alto mínimo en celular (32rem).
62
+ * @cssprop --lr-hero-acento - Color de la etiqueta de los anuncios (#facc15).
63
+ */
64
+ @customElement('lr-hero')
65
+ export class LrHero extends LitElement {
66
+ static override styles = [
67
+ tokens,
68
+ estilosBase,
69
+ css`
70
+ :host {
71
+ display: block;
72
+ --_oscuro: color-mix(in srgb, var(--_color-primario), #000 50%);
73
+ --_acento: var(--lr-hero-acento, #facc15);
74
+ --_alto: var(--lr-hero-alto, 30rem);
75
+ }
76
+ .marco {
77
+ position: relative;
78
+ isolation: isolate;
79
+ overflow: hidden;
80
+ border-radius: var(--_radio);
81
+ background: linear-gradient(135deg, var(--_oscuro), var(--_color-primario));
82
+ color: #fff;
83
+ }
84
+ .fondo,
85
+ .tinte,
86
+ .tinte::before,
87
+ .tinte::after {
88
+ position: absolute;
89
+ inset: 0;
90
+ z-index: -1;
91
+ }
92
+ .fondo img {
93
+ width: 100%;
94
+ height: 100%;
95
+ object-fit: cover;
96
+ display: block;
97
+ }
98
+ :host([disposicion='dividido']) .fondo,
99
+ :host([disposicion='escaparate']) .fondo {
100
+ inset: -3rem;
101
+ filter: blur(32px) saturate(1.25);
102
+ }
103
+ .tinte::before,
104
+ .tinte::after {
105
+ content: '';
106
+ transition: opacity 0.6s;
107
+ }
108
+ .tinte::after {
109
+ opacity: 0;
110
+ }
111
+ .marco[data-activa='anuncio'] .tinte::before {
112
+ opacity: 0;
113
+ }
114
+ .marco[data-activa='anuncio'] .tinte::after {
115
+ opacity: 1;
116
+ }
117
+ /* Portada: velo oscuro del lado del texto en la bienvenida, color de la marca en los anuncios. */
118
+ .tinte::before {
119
+ background: linear-gradient(90deg, rgb(10 12 30 / 0.82) 0%, rgb(10 12 30 / 0.55) 45%, rgb(10 12 30 / 0) 80%);
120
+ }
121
+ .tinte::after {
122
+ background: linear-gradient(
123
+ 105deg,
124
+ color-mix(in srgb, var(--_oscuro) 94%, transparent) 0%,
125
+ color-mix(in srgb, var(--_color-primario) 82%, transparent) 45%,
126
+ color-mix(in srgb, var(--_oscuro) 50%, transparent) 100%
127
+ );
128
+ }
129
+ :host([disposicion='dividido']) .tinte::before,
130
+ :host([disposicion='dividido']) .tinte::after,
131
+ :host([disposicion='escaparate']) .tinte::before,
132
+ :host([disposicion='escaparate']) .tinte::after {
133
+ background: rgb(10 12 30 / 0.45);
134
+ }
135
+ lr-carrusel {
136
+ --lr-carrusel-radio: 0;
137
+ --lr-carrusel-avance: var(--_acento);
138
+ /* El carrusel pone el color de texto del sitio; aquí manda el del hero. */
139
+ color: inherit;
140
+ }
141
+
142
+ /* ---- Diapositivas ---- */
143
+ .diapositiva {
144
+ position: relative;
145
+ display: flex;
146
+ min-height: var(--_alto);
147
+ padding: clamp(1.5rem, 5vw, 4rem);
148
+ padding-bottom: max(clamp(1.5rem, 5vw, 4rem), var(--lr-carrusel-reserva-abajo, 0px));
149
+ gap: 3rem;
150
+ align-items: center;
151
+ }
152
+ .texto {
153
+ display: flex;
154
+ flex-direction: column;
155
+ align-items: flex-start;
156
+ gap: 1rem;
157
+ max-width: 36rem;
158
+ min-width: 0;
159
+ }
160
+ .antetitulo {
161
+ font-size: 0.8125rem;
162
+ font-weight: 800;
163
+ letter-spacing: 0.08em;
164
+ text-transform: uppercase;
165
+ color: var(--_acento);
166
+ }
167
+ .etiqueta {
168
+ display: inline-flex;
169
+ padding: 0.375rem 0.75rem;
170
+ border-radius: 999px;
171
+ background: var(--_acento);
172
+ color: #1f2937;
173
+ font-size: 0.8125rem;
174
+ font-weight: 700;
175
+ }
176
+ h2 {
177
+ margin: 0;
178
+ font-size: clamp(1.875rem, 4.5vw, 3.25rem);
179
+ line-height: 1.06;
180
+ font-weight: 800;
181
+ letter-spacing: -0.02em;
182
+ text-wrap: balance;
183
+ }
184
+ .anuncio h2 {
185
+ font-size: clamp(1.75rem, 4vw, 2.875rem);
186
+ }
187
+ p {
188
+ margin: 0;
189
+ font-size: clamp(1rem, 1.8vw, 1.1875rem);
190
+ line-height: 1.5;
191
+ opacity: 0.92;
192
+ }
193
+ .botones {
194
+ display: flex;
195
+ flex-wrap: wrap;
196
+ gap: 0.75rem;
197
+ margin-top: 0.5rem;
198
+ }
199
+ .boton {
200
+ display: inline-flex;
201
+ align-items: center;
202
+ justify-content: center;
203
+ height: 3rem;
204
+ padding: 0 1.375rem;
205
+ border-radius: calc(var(--_radio) / 1.5);
206
+ font-weight: 700;
207
+ text-decoration: none;
208
+ white-space: nowrap;
209
+ background: var(--_color-primario);
210
+ color: var(--_color-sobre-primario);
211
+ border: 1.5px solid transparent;
212
+ }
213
+ .boton.secundario {
214
+ background: transparent;
215
+ color: #fff;
216
+ border-color: rgb(255 255 255 / 0.85);
217
+ }
218
+ .anuncio .boton {
219
+ background: #fff;
220
+ color: #111827;
221
+ }
222
+ .boton:hover {
223
+ filter: brightness(0.94);
224
+ }
225
+ .boton:focus-visible {
226
+ outline: 2px solid #fff;
227
+ outline-offset: 3px;
228
+ }
229
+ .imagen {
230
+ position: relative;
231
+ flex: 1 1 0;
232
+ align-self: stretch;
233
+ min-width: 0;
234
+ max-height: calc(var(--_alto) - 5rem);
235
+ border-radius: calc(var(--_radio) * 1.25);
236
+ overflow: hidden;
237
+ box-shadow: 0 24px 60px rgb(0 0 0 / 0.4), 0 0 0 1px rgb(255 255 255 / 0.15);
238
+ }
239
+ .imagen img:not(.logo) {
240
+ position: absolute;
241
+ inset: 0;
242
+ width: 100%;
243
+ height: 100%;
244
+ object-fit: cover;
245
+ }
246
+ .anuncio .texto {
247
+ flex: 1 1 0;
248
+ }
249
+ .logo {
250
+ width: 5.25rem;
251
+ height: 5.25rem;
252
+ border-radius: 1.25rem;
253
+ object-fit: contain;
254
+ background: #fff;
255
+ box-shadow: 0 10px 30px rgb(0 0 0 / 0.3);
256
+ }
257
+
258
+ /* ---- Dividido ---- */
259
+ :host([disposicion='dividido']) .diapositiva {
260
+ padding: 1.75rem;
261
+ padding-bottom: max(1.75rem, var(--lr-carrusel-reserva-abajo, 0px));
262
+ gap: 1.5rem;
263
+ align-items: stretch;
264
+ }
265
+ :host([disposicion='dividido']) .texto {
266
+ flex: 1 1 0;
267
+ max-width: none;
268
+ justify-content: center;
269
+ padding: clamp(1.5rem, 4vw, 3rem);
270
+ border-radius: calc(var(--_radio) * 1.25);
271
+ background: #fff;
272
+ color: var(--_color-texto);
273
+ box-shadow: 0 20px 50px rgb(0 0 0 / 0.3);
274
+ }
275
+ :host([disposicion='dividido']) .antetitulo {
276
+ color: var(--_color-primario);
277
+ }
278
+ :host([disposicion='dividido']) p {
279
+ color: var(--_color-texto-suave);
280
+ opacity: 1;
281
+ }
282
+ :host([disposicion='dividido']) .boton.secundario {
283
+ color: var(--_color-primario);
284
+ border-color: var(--_color-primario);
285
+ }
286
+ :host([disposicion='dividido']) .anuncio .boton {
287
+ background: var(--_color-primario);
288
+ color: var(--_color-sobre-primario);
289
+ }
290
+ :host([disposicion='dividido']) .imagen {
291
+ max-height: none;
292
+ box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
293
+ }
294
+ :host([disposicion='dividido']) .imagen.sin-imagen {
295
+ background: linear-gradient(135deg, var(--_oscuro), var(--_color-primario));
296
+ }
297
+ :host([disposicion='dividido']) .imagen .logo {
298
+ position: absolute;
299
+ left: 1.5rem;
300
+ bottom: 1.5rem;
301
+ }
302
+ :host([disposicion='dividido']) .imagen.sin-imagen .logo {
303
+ left: calc(50% - 2.625rem);
304
+ bottom: calc(50% - 2.625rem);
305
+ }
306
+
307
+ /* ---- Escaparate ---- */
308
+ :host([disposicion='escaparate']) .bienvenida {
309
+ justify-content: center;
310
+ text-align: center;
311
+ }
312
+ :host([disposicion='escaparate']) .bienvenida .texto {
313
+ align-items: center;
314
+ max-width: 40rem;
315
+ }
316
+ :host([disposicion='escaparate']) .bienvenida .botones {
317
+ justify-content: center;
318
+ }
319
+ :host([disposicion='escaparate']) .bienvenida .boton.principal {
320
+ background: #fff;
321
+ color: #111827;
322
+ }
323
+ :host([disposicion='escaparate']) .imagen {
324
+ flex: 0 1 46%;
325
+ align-self: center;
326
+ aspect-ratio: 3 / 2;
327
+ }
328
+
329
+ /* ---- Ancho completo ---- */
330
+ :host([ancho-completo]) {
331
+ --_alto: var(--lr-hero-alto, 34rem);
332
+ --_lateral: max(0px, calc((100% - var(--lr-hero-ancho-contenido, 1160px)) / 2));
333
+ }
334
+ :host([ancho-completo]) .marco {
335
+ border-radius: 0;
336
+ }
337
+ :host([ancho-completo]) lr-carrusel {
338
+ --lr-carrusel-pestanas-relleno: var(--_lateral);
339
+ }
340
+ @media (min-width: 641px) {
341
+ /* El contenido se alinea con el ancho del sitio; el fondo llega a las orillas. */
342
+ :host([ancho-completo]) .diapositiva {
343
+ padding-inline: max(clamp(1.5rem, 5vw, 4rem), calc(var(--_lateral) + 1rem));
344
+ }
345
+ :host([ancho-completo][disposicion='dividido']) .diapositiva {
346
+ padding-inline: max(1.75rem, calc(var(--_lateral) + 1rem));
347
+ }
348
+ }
349
+
350
+ @media (max-width: 640px) {
351
+ :host {
352
+ --_alto: var(--lr-hero-alto-celular, 32rem);
353
+ }
354
+ .diapositiva {
355
+ flex-direction: column;
356
+ justify-content: flex-end;
357
+ align-items: stretch;
358
+ gap: 1.25rem;
359
+ padding: 1.5rem 1.375rem;
360
+ padding-bottom: max(1.5rem, var(--lr-carrusel-reserva-abajo, 0px));
361
+ }
362
+ .tinte::before {
363
+ background: linear-gradient(0deg, rgb(10 12 30 / 0.92) 0%, rgb(10 12 30 / 0.6) 45%, rgb(10 12 30 / 0.05) 85%);
364
+ }
365
+ .tinte::after {
366
+ background: linear-gradient(
367
+ 0deg,
368
+ color-mix(in srgb, var(--_oscuro) 96%, transparent) 0%,
369
+ color-mix(in srgb, var(--_color-primario) 85%, transparent) 50%,
370
+ color-mix(in srgb, var(--_oscuro) 55%, transparent) 100%
371
+ );
372
+ }
373
+ .texto,
374
+ .anuncio .texto {
375
+ flex: none;
376
+ }
377
+ .botones {
378
+ flex-direction: column;
379
+ align-self: stretch;
380
+ }
381
+ .boton {
382
+ width: 100%;
383
+ }
384
+ /* Portada: los anuncios no muestran imagen en celular. */
385
+ :host(:not([disposicion])) .anuncio .imagen,
386
+ :host([disposicion='portada']) .anuncio .imagen,
387
+ :host([ocultar-imagen-celular]) .anuncio .imagen {
388
+ display: none;
389
+ }
390
+ .imagen {
391
+ flex: none;
392
+ order: -1;
393
+ height: 9.5rem;
394
+ max-height: none;
395
+ }
396
+ :host([disposicion='escaparate']) .diapositiva {
397
+ justify-content: center;
398
+ text-align: center;
399
+ }
400
+ :host([disposicion='escaparate']) .texto {
401
+ align-items: center;
402
+ align-self: center;
403
+ }
404
+ :host([disposicion='escaparate']) .imagen {
405
+ flex: none;
406
+ aspect-ratio: auto;
407
+ align-self: stretch;
408
+ }
409
+ :host([disposicion='dividido']) .diapositiva {
410
+ gap: 0;
411
+ padding: 0.875rem;
412
+ padding-bottom: max(0.875rem, var(--lr-carrusel-reserva-abajo, 0px));
413
+ justify-content: flex-start;
414
+ }
415
+ :host([disposicion='dividido']) .texto {
416
+ flex: 1 0 auto;
417
+ justify-content: flex-start;
418
+ padding: 1.25rem;
419
+ }
420
+ :host([disposicion='dividido']) .anuncio:not(:has(.imagen)) .texto,
421
+ :host([ocultar-imagen-celular][disposicion='dividido']) .anuncio .texto {
422
+ justify-content: center;
423
+ }
424
+ :host([disposicion='dividido']) .imagen {
425
+ height: 11rem;
426
+ border-radius: calc(var(--_radio) * 1.25) calc(var(--_radio) * 1.25) 0 0;
427
+ box-shadow: none;
428
+ }
429
+ :host([disposicion='dividido']) .imagen + .texto,
430
+ :host([disposicion='dividido']) .texto:has(+ .imagen) {
431
+ border-radius: 0 0 calc(var(--_radio) * 1.25) calc(var(--_radio) * 1.25);
432
+ }
433
+ :host([ocultar-imagen-celular][disposicion='dividido']) .anuncio .texto {
434
+ border-radius: calc(var(--_radio) * 1.25);
435
+ }
436
+ :host([disposicion='dividido']) .imagen .logo {
437
+ width: 4rem;
438
+ height: 4rem;
439
+ border-radius: 0.875rem;
440
+ left: 1rem;
441
+ bottom: 1rem;
442
+ }
443
+ :host([disposicion='dividido']) .imagen.sin-imagen .logo {
444
+ left: calc(50% - 2rem);
445
+ bottom: calc(50% - 2rem);
446
+ }
447
+ }
448
+ `,
449
+ ];
450
+
451
+ /**
452
+ * A todo lo ancho de la pantalla, sin esquinas redondeadas; el contenido se
453
+ * alinea con `--lr-hero-ancho-contenido`. El sitio lo pone fuera de su contenedor.
454
+ */
455
+ @property({ type: Boolean, reflect: true, attribute: 'ancho-completo' }) anchoCompleto = false;
456
+
457
+ @property({ reflect: true }) disposicion: DisposicionHero = 'portada';
458
+
459
+ /** Portada de la tienda: fondo fijo de todo el carrusel. */
460
+ @property() portada = '';
461
+
462
+ /** Portada para pantallas de hasta 640 px. */
463
+ @property({ attribute: 'portada-celular' }) portadaCelular = '';
464
+
465
+ /** Logo de la tienda (bienvenida de `dividido` y `escaparate`). */
466
+ @property() logo = '';
467
+
468
+ @property({ attribute: 'logo-alt' }) logoAlt = '';
469
+
470
+ @property() antetitulo = '';
471
+
472
+ @property() titulo = '';
473
+
474
+ @property() texto = '';
475
+
476
+ /** Hasta dos botones de la bienvenida (por ejemplo Productos y Eventos). */
477
+ @property({ attribute: false }) botones: BotonHero[] = [];
478
+
479
+ @property({ attribute: false }) anuncios: AnuncioHero[] = [];
480
+
481
+ /** Milisegundos entre diapositivas; `0` = no avanza solo. */
482
+ @property({ type: Number }) intervalo = 7000;
483
+
484
+ /** Oculta la imagen de los anuncios en celular también en `dividido` y `escaparate`. */
485
+ @property({ type: Boolean, reflect: true, attribute: 'ocultar-imagen-celular' }) ocultarImagenCelular = false;
486
+
487
+ @property() etiqueta = 'Inicio';
488
+
489
+ @state() private activa = 0;
490
+
491
+ override render() {
492
+ const escaparate = this.disposicion === 'escaparate';
493
+ return html`
494
+ <div class="marco" data-activa=${this.activa === 0 ? 'bienvenida' : 'anuncio'}>
495
+ ${this.portada
496
+ ? html`<picture class="fondo" aria-hidden="true">
497
+ ${this.portadaCelular ? html`<source media="(max-width: 640px)" srcset=${this.portadaCelular} />` : nothing}
498
+ <img src=${this.portada} alt="" fetchpriority="high" />
499
+ </picture>`
500
+ : nothing}
501
+ <div class="tinte" aria-hidden="true"></div>
502
+ <lr-carrusel
503
+ etiqueta=${this.etiqueta}
504
+ intervalo=${this.intervalo}
505
+ ?puntos-encima=${!escaparate}
506
+ ?pestanas=${escaparate}
507
+ efecto=${escaparate ? 'desvanecer' : 'deslizar'}
508
+ @cambio-diapositiva=${this.alCambiar}
509
+ >
510
+ ${this.bienvenida()} ${this.anuncios.map((a) => this.anuncio(a))}
511
+ </lr-carrusel>
512
+ </div>
513
+ `;
514
+ }
515
+
516
+ private bienvenida() {
517
+ const dividido = this.disposicion === 'dividido';
518
+ const logo = this.logo ? html`<img class="logo" src=${this.logo} alt=${this.logoAlt} />` : nothing;
519
+ const botones = this.botones.slice(0, 2);
520
+ return html`<article class="diapositiva bienvenida" data-pestana=${this.titulo || 'Bienvenida'} data-pestana-detalle="Inicio">
521
+ <div class="texto">
522
+ ${this.disposicion === 'escaparate' ? logo : nothing}
523
+ ${this.antetitulo ? html`<span class="antetitulo">${this.antetitulo}</span>` : nothing}
524
+ ${this.titulo ? html`<h2>${this.titulo}</h2>` : nothing}
525
+ ${this.texto ? html`<p>${this.texto}</p>` : nothing}
526
+ ${botones.length
527
+ ? html`<div class="botones">
528
+ ${botones.map(
529
+ (b, i) => html`<a
530
+ class="boton ${b.variante ?? (i === 0 ? 'principal' : 'secundario')}"
531
+ href=${b.href}
532
+ @click=${(e: MouseEvent) => this.alClic(e, b.href)}
533
+ >${b.texto}</a
534
+ >`
535
+ )}
536
+ </div>`
537
+ : nothing}
538
+ </div>
539
+ ${dividido
540
+ ? html`<div class="imagen ${this.portada ? '' : 'sin-imagen'}">
541
+ ${this.portada ? html`<img src=${this.portadaCelular || this.portada} alt="" />` : nothing} ${logo}
542
+ </div>`
543
+ : nothing}
544
+ </article>`;
545
+ }
546
+
547
+ private anuncio(a: AnuncioHero) {
548
+ return html`<article class="diapositiva anuncio" data-pestana=${a.titulo} data-pestana-detalle=${a.etiqueta || a.antetitulo || 'Anuncio'}>
549
+ <div class="texto">
550
+ ${a.etiqueta ? html`<span class="etiqueta">${a.etiqueta}</span>` : nothing}
551
+ ${a.antetitulo ? html`<span class="antetitulo">${a.antetitulo}</span>` : nothing}
552
+ <h2>${a.titulo}</h2>
553
+ ${a.texto ? html`<p>${a.texto}</p>` : nothing}
554
+ ${a.boton && a.href
555
+ ? html`<div class="botones">
556
+ <a class="boton" href=${a.href} @click=${(e: MouseEvent) => this.alClic(e, a.href!, a.id)}>${a.boton}</a>
557
+ </div>`
558
+ : nothing}
559
+ </div>
560
+ ${a.imagen
561
+ ? html`<div class="imagen">
562
+ <picture>
563
+ ${a.imagenCelular ? html`<source media="(max-width: 640px)" srcset=${a.imagenCelular} />` : nothing}
564
+ <img src=${a.imagen} alt=${a.imagenAlt ?? ''} loading="lazy" />
565
+ </picture>
566
+ </div>`
567
+ : nothing}
568
+ </article>`;
569
+ }
570
+
571
+ private alCambiar(evento: CustomEvent<DetalleCambioDiapositiva>) {
572
+ evento.stopPropagation();
573
+ this.activa = evento.detail.indice;
574
+ }
575
+
576
+ private alClic(evento: MouseEvent, href: string, id?: string) {
577
+ if (evento.ctrlKey || evento.metaKey) return;
578
+ evento.preventDefault();
579
+ emitir<DetalleClicHero>(this, 'clic-hero', { id, href });
580
+ }
581
+ }
582
+
583
+ declare global {
584
+ interface HTMLElementTagNameMap {
585
+ 'lr-hero': LrHero;
586
+ }
587
+ }