import type { InferredContentReference } from '../infer.js'; import type { PublicImageAsset, PublicVideoAsset, PublicRawFileAsset } from '../model/assets.js'; /** * Creates a responsive srcset string from your image renditions. * * This handles all the messy details: * - Removes duplicate widths if you have multiple renditions at the same size * - Adds preview tokens automatically when in edit mode * - Returns undefined if there's no image or no renditions (attribute won't be rendered) * * @param content - Your content object with __context for preview tokens * @param property - The image reference from your content (e.g., content.image) * @returns A srcset string like "url1 100w, url2 500w" or undefined if no renditions * * @example * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function MyComponent({ content }) { * const { getSrcset } = damAssets(content); * * return ( * * ); * } * ``` * * @example * Works with any image property: * ```tsx * const { getSrcset, getAlt } = damAssets(content); * Hero * ``` */ export declare function getSrcset>(content: T & { __context?: { preview_token?: string; }; }, property: InferredContentReference | null | undefined): string | undefined; /** * Gets the alt text for an image or video. * * It checks: * 1. Uses the AltText from the asset if it exists * 2. Falls back to your custom text if AltText is null/undefined * 3. Returns empty string if no alt text or fallback is available * * Note: By default, this returns an empty string when no alt text is available, which marks * the image as decorative. To avoid accidentally creating inaccessible content, always provide * a fallback or ensure your assets have AltText set in the CMS. * * @param input - Your image or video reference * @param fallback - Text to use if there's no AltText (defaults to empty string) * @returns The alt text to use * * @example * With a AltText present in the asset: * ```tsx * const { getAlt } = damAssets(content); * {getAlt(content.image)} * ``` * * @example * Using a custom fallback: * ```tsx * const { getAlt } = damAssets(content); * {getAlt(content.image, * ``` * * @example * Explicitly marking an image as decorative: * ```tsx * const { getAlt } = damAssets(content); * {getAlt(content.icon)} // Will be alt="" if no AltText exists * ``` */ export declare function getAlt(input: InferredContentReference | null | undefined, fallback?: string): string; /** * Type guard that checks if a content reference is an image asset (cmp_PublicImageAsset). * * This function provides TypeScript type narrowing, allowing safe access to image-specific * properties such as Renditions, AltText, Width, Height, and FocalPoint after the check. * * @param property - Content reference to check * @returns True if the property is an image asset, with TypeScript type narrowing applied * * @example * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function MediaComponent({ content }) { * const { isDamImageAsset } = damAssets(content); * * if (isDamImageAsset(content.media)) { * // TypeScript knows content.media.item is PublicImageAsset * const renditions = content.media.item.Renditions; * const altText = content.media.item.AltText; * const width = content.media.item.Width; * * return {altText}; * } * return null; * } * ``` */ export declare function isDamImageAsset(property: InferredContentReference | null | undefined): property is InferredContentReference & { item: PublicImageAsset; }; /** * Type guard that checks if a content reference is a video asset (cmp_PublicVideoAsset). * * This function provides TypeScript type narrowing, allowing safe access to video-specific * properties such as Renditions and AltText after the check. * * @param property - Content reference to check * @returns True if the property is a video asset, with TypeScript type narrowing applied * * @example * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function MediaComponent({ content }) { * const { isDamVideoAsset } = damAssets(content); * * if (isDamVideoAsset(content.media)) { * // TypeScript knows content.media.item is PublicVideoAsset * const videoUrl = content.media.item.Url; * const altText = content.media.item.AltText; * const renditions = content.media.item.Renditions; * * return ( * * ); * } * return null; * } * ``` */ export declare function isDamVideoAsset(property: InferredContentReference | null | undefined): property is InferredContentReference & { item: PublicVideoAsset; }; /** * Type guard that checks if a content reference is a raw file asset (cmp_PublicRawFileAsset). * * This function provides TypeScript type narrowing, allowing safe access to file-specific * properties such as Url, Title, Description, and MimeType after the check. Raw file assets * represent general files like PDFs, documents, or other downloadable content. * * @param property - Content reference to check * @returns True if the property is a raw file asset, with TypeScript type narrowing applied * * @example * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function MediaComponent({ content }) { * const { isDamRawFileAsset } = damAssets(content); * * if (isDamRawFileAsset(content.media)) { * // TypeScript knows content.media.item is PublicRawFileAsset * const fileUrl = content.media.item.Url; * const title = content.media.item.Title; * const mimeType = content.media.item.MimeType; * * return ( * * {title || 'Download File'} ({mimeType}) * * ); * } * return null; * } * ``` */ export declare function isDamRawFileAsset(property: InferredContentReference | null | undefined): property is InferredContentReference & { item: PublicRawFileAsset; }; /** * Checks if a content reference is any type of DAM asset (image, video, or file). * * This is useful for validating that a content reference contains a valid DAM asset * before attempting to render or process it. Returns false for null, undefined, or * content references without a valid asset item. * * @param property - Content reference to check * @returns True if the property is any type of DAM asset (image, video, or file) * * @example * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function MediaComponent({ content }) { * const { isDamAsset, getDamAssetType } = damAssets(content); * * if (!isDamAsset(content.media)) { * return
No media uploaded
; * } * * const assetType = getDamAssetType(content.media); * return
Valid {assetType} asset detected
; * } * ``` */ export declare function isDamAsset(property: InferredContentReference | null | undefined): boolean; /** * Returns the type of a DAM asset as a string literal. * * This function is useful for implementing switch-case logic or displaying the asset type * to users. Returns 'unknown' for null, undefined, or unrecognized asset types. * * @param property - Content reference to check * @returns Asset type: 'image', 'video', 'file', or 'unknown' * * @example * Switch-case pattern for rendering different asset types: * ```tsx * import { damAssets } from '@optimizely/cms-sdk'; * * export default function AssetRenderer({ content }) { * const { getSrcset, getAlt, getDamAssetType } = damAssets(content); * const assetType = getDamAssetType(content.media); * * switch (assetType) { * case 'image': * return ( * {getAlt(content.media, * ); * case 'video': * return