Componentes · Contenido
Imagen <Media>
Fotos con proporción fija, punto focal y carga diferida; nunca una URL de Cloudinary a mano.
import Media from '@vivla-cms/ds/primitives/Media.astro'Ejemplos
Proporciones
aspect fija la caja y recorta la foto (fit="cover"). De panorámica a retrato: 21/9 (sobre nosotros), 16/9, 3/2, 4/3, 5/4, 1/1, 4/5, 3/4 (equipo), 2/3 (Casa Ribes). auto respeta la proporción del archivo.
---
import Media from '@vivla-cms/ds/primitives/Media.astro'
const aspects = ['21/9', '16/9', '3/2', '4/3', '5/4', '1/1', '4/5', '3/4', '2/3', 'auto'] as const
---
<div class="grid grid-cols-2 items-start gap-4 sm:grid-cols-3 lg:grid-cols-5">
{
aspects.map((aspect) => (
<figure class="flex flex-col gap-2">
<Media src="/assets/home/dest-menorca-640.webp" alt="" aspect={aspect} />
<figcaption class="font-mono text-small text-on-surface-muted">{aspect}</figcaption>
</figure>
))
}
</div> Punto focal
position mueve el recorte dentro de una proporción fija: una palabra (top, bottom, left, right, center), un punto en porcentaje ({ x: 50, y: 30 }) o el texto que guardan los campos de foco del CMS ('center 30%'). Con aspect="auto" no hace nada: no hay recorte.
---
import Media from '@vivla-cms/ds/primitives/Media.astro'
const positions = [
{ label: 'top', position: 'top' },
{ label: 'center', position: 'center' },
{ label: 'bottom', position: 'bottom' },
{ label: '{ x: 80, y: 50 }', position: { x: 80, y: 50 } },
{ label: "'center 30%'", position: 'center 30%' },
] as const
---
<div class="grid grid-cols-2 gap-4 sm:grid-cols-3 lg:grid-cols-5">
{
positions.map(({ label, position }) => (
<figure class="flex flex-col gap-2">
<Media src="/assets/vivla-studio/maria-rivero.webp" alt="" aspect="21/9" position={position} />
<figcaption class="font-mono text-small text-on-surface-muted">{label}</figcaption>
</figure>
))
}
</div> Encaje y radio
fit="contain" mete la imagen entera en la caja (planos, gráficos) sobre el marcador surface-alt; cover (por defecto) la recorta. radius acepta none, media y card: los tres son 0 en Foundations, pero la prop queda por si diseño lo cambia.
---
import Media from '@vivla-cms/ds/primitives/Media.astro'
---
<figure class="flex w-64 flex-col gap-2">
<Media src="/assets/vivla-studio/blueprint.webp" alt="Plano de una casa" aspect="1/1" fit="cover" />
<figcaption class="font-mono text-small text-on-surface-muted">fit="cover"</figcaption>
</figure>
<figure class="flex w-64 flex-col gap-2">
<Media src="/assets/vivla-studio/blueprint.webp" alt="Plano de una casa" aspect="1/1" fit="contain" />
<figcaption class="font-mono text-small text-on-surface-muted">fit="contain"</figcaption>
</figure>
<figure class="flex w-64 flex-col gap-2">
<Media src="/assets/vivla-studio/interior.webp" alt="" aspect="1/1" radius="media" />
<figcaption class="font-mono text-small text-on-surface-muted">radius="media"</figcaption>
</figure> Imágenes adaptables: srcset y dirección de arte
srcset + sizes dejan que el navegador elija el ancho. sources crea un <picture>: aquí el móvil recibe otro recorte. Media nunca construye URLs de Cloudinary: el que la llama transforma primero (cloudinarySrcset en los bloques, deliverUrl en la web). La primera imagen de una página va con loading="eager" y fetchpriority="high".
---
import Media from '@vivla-cms/ds/primitives/Media.astro'
---
<Media
src="/assets/home/hero-1024.webp"
srcset="/assets/home/hero-640.webp 640w, /assets/home/hero-1024.webp 1024w, /assets/home/hero-1600.webp 1600w"
sizes="(min-width: 62rem) 60vw, 100vw"
sources={[
{
media: '(max-width: 47.9375rem)',
srcset: '/assets/home/dest-menorca-640.webp 640w, /assets/home/dest-menorca-1024.webp 1024w',
sizes: '100vw',
type: 'image/webp',
},
]}
alt="Una casa VIVLA frente al mar"
aspect="16/9"
loading="eager"
fetchpriority="high"
class="max-w-3xl"
/> Capa a sangre (fill)
aspect="fill" estira la imagen al padre (que necesita alto) y la fija en absoluto: es la foto fija bajo un vídeo de hero o el fondo de una banda con texto encima.
Tu casa, seis semanas al año
---
import Heading from '@vivla-cms/ds/primitives/Heading.astro'
import Media from '@vivla-cms/ds/primitives/Media.astro'
---
<div class="relative h-80">
<Media src="/assets/home/feat-flexibility-1024.webp" alt="" aspect="fill" radius="none" />
<div class="absolute inset-0 flex items-end bg-linear-to-t from-surface/70 to-transparent p-6 md:p-10">
<Heading level={3} size="h2">Tu casa, seis semanas al año</Heading>
</div>
</div> Props
| Prop | Valores | Por defecto | Para qué |
|---|---|---|---|
| src * | string | — | — |
| alt * | string | — | — |
| srcset | string | — | — |
| sizes | string | — | — |
| sources | { media: string; srcset: string; sizes?: string; type?: string }[] | [] | Art-direction <source>s (e.g. a portrait crop under 48rem); non-empty renders a <picture>. |
| width | number | — | — |
| height | number | — | — |
| aspect | | '16/9' | '4/3' | '3/2' | '5/4' | '1/1' | '4/5' | '3/4' | '2/3' | '21/9' | 'auto' | 'fill' | 'auto' | — |
| fit | covercontain | 'cover' | — |
| position | PositionKeyword | FocalPoint | string | null | — | Crop anchor (object-position): keyword, focal point in percent, or a CSS object-position string such as 'center 30%'. Default: centre. |
| radius | nonemediacard | 'media' | — |
| loading | lazyeager | 'lazy' | — |
| fetchpriority | highlowauto | — | — |
| poster | string | — | Video src only: the poster image URL (already transformed), shown before the first frame. |
| decoding | asyncsyncauto | 'async' | — |
| imgClass | string | '' | — |
Notas del código
El comentario de cabecera de Media.astro, tal cual (en inglés, como el código): si cambia el código, cambia esto.
thin <img> wrapper with aspect ratio, radius and a surface-alt placeholder while the image loads.
It REQUIRES an already-transformed src (and srcset) — this primitive never builds Cloudinary URLs itself (house rule: no raw Cloudinary URLs in markup). Callers transform first:
import { cloudinaryTransform, cloudinarySrcset, CARD_WIDTHS }
from '@vivla-cms/cms-blocks/image' // packages / blocks
import { deliverUrl, resolveImageUrl } from '@/lib/cms-image' // apps/web
<Media src={cloudinaryTransform(url, 1280)} srcset={cloudinarySrcset(url, CARD_WIDTHS)}
sizes="(min-width: 62rem) 50vw, 100vw" alt={alt} aspect="4/3" /> Art direction: sources renders a <picture> whose <source>s win over the <img> (which stays the fallback with its own src / srcset / sizes). Order them most specific first, exactly like hand-written <picture> markup:
<Media src={cloudinaryTransform(wide, 1600)} srcset={cloudinarySrcset(wide, HERO_WIDTHS)}
sizes="100vw" alt={alt} aspect="fill" loading="eager" fetchpriority="high"
sources={[{ media: '(max-width: 47.9375rem)',
srcset: cloudinarySrcset(tall, MOBILE_WIDTHS), sizes: '100vw' }]} /> aspect="fill" stretches the wrapper to its parent (h-full w-full, no ratio) and pins the image absolutely: use it for full-bleed layers such as the still under a hero <Video>. The parent must have a height.
Portrait and panoramic crops (Figma evidence): 2/3 Casa Ribes 383:1904, 272:2666 (647×965); 3/4 about-us team 456:2131 (464×607), 332:4547; 21/9 about-us 452:2109 / 456:2133 (1512×718, plan D30 snap).
position moves the crop inside a fixed aspect (it has no effect with auto, where nothing is cropped): a keyword, a focal point in percent (0 = left / top; numeric strings accepted), or a CSS object-position string as CMS focal-point fields store it (stepPanel.imageFocal). Keywords render a utility class; anything else an inline object-position. A string that cannot be read in percent (lengths, calc()) renders the default centre and logs a dev warning.
<Media {...img} aspect="3/4" position="top" />
<Media {...img} aspect="21/9" position={{ x: 50, y: 30 }} />
<Media {...img} aspect="16/9" position={block.imageFocal} /> // 'center 30%' A video file as src (.mp4/.webm/.mov, or a Cloudinary /video/upload/ URL) renders a muted loop video in the same frame instead of the <img> (10/11/2026: any CMS photo field without its own «Vídeo» also takes a video). poster (an already-transformed image URL: cms-blocks mediaPoster()) shows at once and the file waits until the frame is near the viewport; without one the video's first frame is the poster. It plays only while in view and never for reduced-motion or Save-Data visitors (DS Video, firstFrame). alt names it; srcset / sources are ignored.
<Media src={mediaUrl(field)} poster={mediaPoster(field)} alt={alt} aspect="4/5" /> In dev a raw Cloudinary URL logs a warning so it is caught before review.
Dónde se usa
82 veces en 47 archivos de la web y los bloques del CMS.
Ver los archivos
- packages/cms-blocks/src/renderers/LogoCloud.astro ×8
- apps/web/src/pages/dev/kit.astro ×7
- apps/web/src/pages/dev/kit/video-parts.astro ×6
- apps/web/src/sections/listing/ListingIntro.astro ×5
- packages/cms-blocks/src/renderers/Chapter/story.astro ×3
- packages/cms-blocks/src/renderers/parts/HomeCard.astro ×3
- apps/web/src/sections/listing/ListingDesign.astro ×2
- apps/web/src/sections/listing/ListingGallery.astro ×2
- apps/web/src/sections/listing/ListingNearby.astro ×2
- apps/web/src/sections/owner-stories/OwnerStoriesHero.astro ×2
- packages/cms-blocks/src/renderers/CardGrid/team.astro ×2
- packages/cms-blocks/src/renderers/Chapter/inset.astro ×2
- packages/cms-blocks/src/renderers/LandingPress.astro ×2
- packages/cms-blocks/src/renderers/MediaCollage/orbital.astro ×2
- packages/cms-blocks/src/renderers/Testimonials/scattered.astro ×2
- apps/web/src/components/NotFoundPage.astro ×1
- apps/web/src/layouts/chrome/ContactFormBand.astro ×1
- apps/web/src/layouts/chrome/menu/MenuFeature.astro ×1
- apps/web/src/layouts/chrome/menu/MenuStories.astro ×1
- apps/web/src/pages/dev/kit/media.astro ×1
- apps/web/src/pages/dev/kit/type.astro ×1
- apps/web/src/sections/blog/PostCard.astro ×1
- apps/web/src/sections/blog/PostHeader.astro ×1
- apps/web/src/sections/destinations/DestinationPanels.astro ×1
- apps/web/src/sections/faqs/FaqAnswerVideo.astro ×1
- apps/web/src/sections/listing/ListingFinishes.astro ×1
- apps/web/src/sections/listing/ListingShare.astro ×1
- apps/web/src/sections/press/PressRow.astro ×1
- packages/cms-blocks/src/renderers/CardGrid/overlay.astro ×1
- packages/cms-blocks/src/renderers/CardGrid/parts/Card.astro ×1
- packages/cms-blocks/src/renderers/Chapter/split.astro ×1
- packages/cms-blocks/src/renderers/EditorialFeatures/parts/ItemImage.astro ×1
- packages/cms-blocks/src/renderers/FeatureList/list.astro ×1
- packages/cms-blocks/src/renderers/FeatureList/panel.astro ×1
- packages/cms-blocks/src/renderers/FeatureList/reveal.astro ×1
- packages/cms-blocks/src/renderers/Gallery.astro ×1
- packages/cms-blocks/src/renderers/HomeShowcase/Slide.astro ×1
- packages/cms-blocks/src/renderers/LandingGallery.astro ×1
- packages/cms-blocks/src/renderers/LandingOwners.astro ×1
- packages/cms-blocks/src/renderers/LandingQuote.astro ×1
- packages/cms-blocks/src/renderers/Media/parts/MediaFrame.astro ×1
- packages/cms-blocks/src/renderers/MediaCollage/drift.astro ×1
- packages/cms-blocks/src/renderers/NumberedList/columns.astro ×1
- packages/cms-blocks/src/renderers/NumberedList/rows.astro ×1
- packages/cms-blocks/src/renderers/parts/HomeRail.astro ×1
- packages/cms-blocks/src/renderers/parts/MediaLayer.astro ×1
- packages/cms-blocks/src/renderers/StepPanel/single.astro ×1