/** * Vue 3 composable that resolves responsive image variants for DCS CDN-hosted assets. * * Wraps the framework-agnostic `resolveResponsiveImage` from `@duffcloudservices/cms-core` * with reactive Vue refs so it can be used directly in ` * * * ``` */ import { computed, type MaybeRefOrGetter, toValue } from 'vue' import { resolveResponsiveImage, type ImageContext, type ResponsiveImageResult, } from '@duffcloudservices/cms-core' export interface UseResponsiveImageOptions { /** Source URL — can be a reactive ref, getter, or plain string. */ src: MaybeRefOrGetter /** Alt text — can be a reactive ref, getter, or plain string. */ alt: MaybeRefOrGetter /** Sizing context — determines which variants to include. */ context?: MaybeRefOrGetter /** Optional `sizes` attribute override. */ sizes?: MaybeRefOrGetter /** Skip variant resolution and use the original URL only. */ original?: MaybeRefOrGetter /** Intrinsic width — emitted as a layout-shift hint when paired with `height`. */ width?: MaybeRefOrGetter /** Intrinsic height — emitted as a layout-shift hint when paired with `width`. */ height?: MaybeRefOrGetter } /** * Reactively resolves responsive image metadata for a DCS CDN URL. * * The returned object is a computed ref that recomputes whenever any * of the input refs change. Spread `imgProps` onto an `` or * combine with `sources` inside a `` element. */ export function useResponsiveImage(options: UseResponsiveImageOptions): ResponsiveImageResult { const result = computed(() => resolveResponsiveImage({ src: toValue(options.src), alt: toValue(options.alt), context: toValue(options.context), sizes: toValue(options.sizes), original: toValue(options.original) ?? undefined, width: toValue(options.width) ?? undefined, height: toValue(options.height) ?? undefined, }), ) // Return a reactive proxy that delegates to the computed return { get imgProps() { return result.value.imgProps }, get sources() { return result.value.sources }, get hasVariants() { return result.value.hasVariants }, } }