Ajustes antes de produccion

This commit is contained in:
2026-10-22 00:07:21 -06:00
parent f9666c4088
commit 1be9d16c83
124 changed files with 3540 additions and 772 deletions
+207 -39
View File
@@ -13,12 +13,56 @@
assign cover_mobile = 'mascara-vido-mobile.avif' | asset_url
endif
comment
Video hero: use the video's own first frame as the cover (LCP image). It is tiny
(AVIF ~20 KB desktop / ~8 KB mobile) and identical to frame 0, so the switch to video is seamless.
endcomment
assign cover_w = 1920
assign cover_h = 650
if media_type == 'video' and section.settings.poster_from_video
comment
Shopify's video preview image is frame 0 of the video, served as AVIF/WebP by the CDN.
endcomment
if section.settings.video.preview_image
assign cover_desktop = section.settings.video.preview_image | image_url: width: 1280
assign cover_w = section.settings.video.preview_image.width | at_most: 1280
assign cover_h = section.settings.video.preview_image.height | times: cover_w | divided_by: section.settings.video.preview_image.width
else
assign cover_desktop = 'hero-frame-desktop.avif' | asset_url
assign cover_w = 1280
assign cover_h = 720
endif
if section.settings.video_mobile.preview_image
assign cover_mobile = section.settings.video_mobile.preview_image | image_url: width: 720
elsif section.settings.use_light_mobile_video
assign cover_mobile = 'hero-frame-mobile.avif' | asset_url
elsif section.settings.video.preview_image
assign cover_mobile = section.settings.video.preview_image | image_url: width: 900
else
assign cover_mobile = cover_desktop
endif
endif
assign video_src = blank
assign video_src_mobile = blank
if media_type == 'video'
if section.settings.video != blank
comment
Desktop: the largest MP4 up to 1080p. Mobile: the smallest MP4 that is at least 480p.
endcomment
assign best_h = 0
assign mobile_h = 99999
for source in section.settings.video.sources
if source.mime_type == 'video/mp4' or source.format == 'mp4'
assign video_src = source.url
assign h = source.height | default: 0
if h <= 1080 and h >= best_h
assign best_h = h
assign video_src = source.url
endif
if h >= 480 and h < mobile_h
assign mobile_h = h
assign video_src_mobile = source.url
endif
endif
endfor
endif
@@ -26,6 +70,39 @@
if video_src == blank
assign video_src = 'home-video-op.mp4' | asset_url
endif
comment
Mobile: a dedicated vertical, light video (setting) or the theme's hero-mobile.mp4 (~450 KB, cropped 516x720).
endcomment
if section.settings.video_mobile != blank
assign mobile_h = 99999
for source in section.settings.video_mobile.sources
if source.mime_type == 'video/mp4' or source.format == 'mp4'
assign h = source.height | default: 0
if h >= 480 and h < mobile_h
assign mobile_h = h
assign video_src_mobile = source.url
endif
endif
endfor
elsif section.settings.use_light_mobile_video
assign video_src_mobile = 'hero-mobile.mp4' | asset_url
endif
comment
Theme-hosted optimized videos (no Shopify re-encoding: ~1 MB desktop / ~0.4 MB mobile)
plus their first frames as the cover. These files must match the videos picked above.
endcomment
if section.settings.theme_hosted_videos
assign video_src = 'seasons-hero-desktop.mp4' | asset_url
assign video_src_mobile = 'seasons-hero-mobile.mp4' | asset_url
if section.settings.poster_from_video
assign cover_desktop = 'hero-frame-desktop.avif' | asset_url
assign cover_mobile = 'hero-frame-mobile.avif' | asset_url
assign cover_w = 1280
assign cover_h = 720
endif
endif
endif
if section.settings.social_label != blank
@@ -70,8 +147,6 @@
data-cart-add-url="{{ routes.cart_add_url }}.js"
data-cart-url="{{ routes.cart_url }}.js"
>
<link rel="preload" as="image" href="{{ cover_desktop }}" media="(min-width: 1024px)" fetchpriority="high">
<link rel="preload" as="image" href="{{ cover_mobile }}" media="(max-width: 1023px)" fetchpriority="high">
<div class="hero__media" aria-hidden="true">
{% if media_type == 'image' %}
@@ -90,22 +165,24 @@
<video
class="hero__video"
data-hero-video
data-src-desktop="{{ video_src }}"
data-src-mobile="{{ video_src_mobile | default: video_src }}"
muted
loop
playsinline
preload="none"
>
<source src="{{ video_src }}" type="video/mp4">
</video>
<picture class="hero__poster">
<source media="(max-width: 1023px)" srcset="{{ cover_mobile }}">
<img
class="hero__poster-image"
src="{{ cover_desktop }}"
alt=""
width="1920"
height="650"
alt=""
width="{{ cover_w }}"
height="{{ cover_h }}"
fetchpriority="high"
decoding="sync"
>
</picture>
{% endif %}
@@ -134,6 +211,11 @@
{% for block in section.blocks %}
{% liquid
assign featured_product = block.settings.product
if featured_product != blank
unless featured_product.available
assign featured_product = blank
endunless
endif
if featured_product == blank and forloop.first
assign featured_product = fallback_product
endif
@@ -204,24 +286,61 @@
window.__seasonHeroVideo = true;
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
const events = ['keydown', 'mousedown', 'mousemove', 'touchstart', 'wheel'];
const start = () => {
events.forEach((eventName) => window.removeEventListener(eventName, start));
// The cover (first frame of the video) is the LCP image. Once the page has loaded we
// start buffering the video, and it starts playing 3 s after the cover was shown.
const HOLD_MS = 3000;
const shownAt = performance.now();
let buffering = false;
const buffer = () => {
if (buffering) return;
buffering = true;
events.forEach((eventName) => window.removeEventListener(eventName, buffer));
const mobile = window.matchMedia('(max-width: 1023px)').matches;
document.querySelectorAll('[data-hero-video]').forEach((video) => {
const src = (mobile ? video.dataset.srcMobile : video.dataset.srcDesktop) || video.dataset.srcDesktop;
if (!src) return;
const hero = video.closest('[data-hero]');
video.addEventListener('playing', () => hero?.classList.add('is-playing'));
if (!video.getAttribute('src')) video.src = src;
video.preload = 'auto';
video.load();
const play = () => {
const attempt = video.play();
if (attempt && typeof attempt.catch === 'function') attempt.catch(() => {});
};
video.addEventListener('playing', () => hero?.classList.add('is-playing'));
video.preload = 'auto';
if (video.readyState >= 2) play();
else video.addEventListener('canplay', play, { once: true });
video.load();
const wait = Math.max(0, HOLD_MS - (performance.now() - shownAt));
window.setTimeout(() => {
if (video.readyState >= 3) play();
else video.addEventListener('canplay', play, { once: true });
}, wait);
});
};
events.forEach((eventName) => window.addEventListener(eventName, start, { passive: true }));
// Buffering begins after load (so it never competes with the cover image) or on the first interaction.
const events = ['keydown', 'mousedown', 'touchstart', 'wheel', 'scroll'];
events.forEach((eventName) => window.addEventListener(eventName, buffer, { passive: true }));
const conn = navigator.connection;
const slow = conn && (conn.saveData || /2g/.test(conn.effectiveType || ''));
if (!slow) {
// Wait for the page load AND for the cover (LCP image) to be painted, then an idle moment,
// so the video download never competes with the cover.
const cover = document.querySelector('.hero__poster-image');
const coverReady = () => new Promise((resolve) => {
if (!cover || cover.complete) return resolve();
cover.addEventListener('load', resolve, { once: true });
cover.addEventListener('error', resolve, { once: true });
});
const pageLoaded = () => new Promise((resolve) => {
if (document.readyState === 'complete') resolve();
else window.addEventListener('load', resolve, { once: true });
});
const idle = () => new Promise((resolve) => {
if ('requestIdleCallback' in window) window.requestIdleCallback(() => resolve(), { timeout: 1500 });
else window.setTimeout(resolve, 300);
});
Promise.all([pageLoaded(), coverReady()]).then(idle).then(buffer);
}
})();
</script>
@@ -253,22 +372,11 @@
const markPlaying = () => hero.classList.add('is-playing');
video.addEventListener('playing', markPlaying);
const tryPlay = () => {
const playAttempt = video.play();
if (playAttempt && typeof playAttempt.catch === 'function') {
playAttempt.catch(() => {});
}
};
if (video.readyState >= 2) {
tryPlay();
} else {
video.addEventListener('canplay', tryPlay, { once: true });
}
// Playback timing (3 s hold on the first-frame cover) is handled by the inline hero script.
});
document.addEventListener('submit', async (event) => {
if (event.defaultPrevented) return;
const form = event.target;
if (!(form instanceof HTMLFormElement) || !form.classList.contains('hero__form')) return;
@@ -319,7 +427,10 @@
"class": "hero-section",
"max_blocks": 2,
"disabled_on": {
"groups": ["header", "footer"]
"groups": [
"header",
"footer"
]
},
"settings": [
{
@@ -338,8 +449,14 @@
"label": "t:hero.line_1_weight",
"default": "light",
"options": [
{ "value": "light", "label": "t:hero.weight_light" },
{ "value": "medium", "label": "t:hero.weight_medium" }
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
@@ -354,8 +471,14 @@
"label": "t:hero.line_2_weight",
"default": "medium",
"options": [
{ "value": "light", "label": "t:hero.weight_light" },
{ "value": "medium", "label": "t:hero.weight_medium" }
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
@@ -370,8 +493,14 @@
"label": "t:hero.line_3_weight",
"default": "light",
"options": [
{ "value": "light", "label": "t:hero.weight_light" },
{ "value": "medium", "label": "t:hero.weight_medium" }
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
@@ -390,8 +519,14 @@
"label": "t:hero.media_type",
"default": "video",
"options": [
{ "value": "video", "label": "t:hero.media_video" },
{ "value": "image", "label": "t:hero.media_image" }
{
"value": "video",
"label": "t:hero.media_video"
},
{
"value": "image",
"label": "t:hero.media_image"
}
]
},
{
@@ -401,6 +536,37 @@
"info": "t:hero.video_info",
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "video",
"id": "video_mobile",
"label": "Video móvil (vertical, ligero)",
"info": "Opcional. Recomendado: vertical, sin audio, menos de 1 MB.",
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "use_light_mobile_video",
"label": "Usar versión ligera incluida en el tema para móvil",
"info": "Recorte vertical del video actual (~450 KB). Desactívalo si cambias el video principal y no subes uno móvil.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "poster_from_video",
"label": "Portada = primer cuadro del video",
"info": "Muestra el primer cuadro del video (imagen ligera precargada) 3 s antes de reproducir. Desactívalo para usar las portadas de abajo.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "theme_hosted_videos",
"label": "Usar videos optimizados del tema",
"info": "Sirve seasons-hero-desktop.mp4 (~1 MB) y seasons-hero-mobile.mp4 (~0.4 MB) desde el tema, sin la recompresión de Shopify (que los vuelve ~2 MB). Si cambias los videos, actualiza esos archivos o desactiva esta opción.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "image_picker",
"id": "cover_desktop",
@@ -456,7 +622,9 @@
{
"name": "t:hero.name",
"blocks": [
{ "type": "featured_product" }
{
"type": "featured_product"
}
]
}
]