>(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);
*
* ```
*
* @example
* Using a custom fallback:
* ```tsx
* const { getAlt } = damAssets(content);
*
* ```
*
* @example
* Explicitly marking an image as decorative:
* ```tsx
* const { getAlt } = damAssets(content);
*
// 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
;
* }
* 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 (
*
* );
* case 'video':
* return ;
* case 'file':
* return (
*
* {content.media.item.Title || 'Download'}
*
* );
* default:
* return No media available
;
* }
* }
* ```
*
* @example
* Display asset type information:
* ```tsx
* import { damAssets } from '@optimizely/cms-sdk';
*
* export default function AssetInfo({ content }) {
* const { getDamAssetType } = damAssets(content);
* const type = getDamAssetType(content.media);
* return Asset type: {type};
* }
* ```
*/
export declare function getDamAssetType(property: InferredContentReference | null | undefined): 'image' | 'video' | 'file' | 'unknown';
/**
* Creates a helper object with utility functions for working with Digital Asset Management (DAM) assets.
*
* Returns helper functions for asset manipulation and type checking. The `getSrcset` function
* returned automatically includes preview tokens from the content's __context when in edit mode.
*
* @param content - Content object with optional __context for preview tokens
* @returns Object containing utility functions: getSrcset, getAlt, isDamImageAsset, isDamVideoAsset, isDamRawFileAsset, isDamAsset, getDamAssetType
*
* @example
* ```tsx
* import { damAssets } from '@optimizely/cms-sdk';
*
* export default function MyComponent({ content }) {
* const { getSrcset, getAlt, isDamImageAsset } = damAssets(content);
*
* if (isDamImageAsset(content.image)) {
* return (
*
* );
* }
* return null;
* }
* ```
*/
export declare function damAssets>(content: T & {
__context?: {
preview_token?: string;
};
}): {
getSrcset: (property: InferredContentReference | null | undefined) => string | undefined;
getAlt: typeof getAlt;
getDamAssetType: typeof getDamAssetType;
isDamImageAsset: typeof isDamImageAsset;
isDamVideoAsset: typeof isDamVideoAsset;
isDamRawFileAsset: typeof isDamRawFileAsset;
isDamAsset: typeof isDamAsset;
};