import { html, nothing, type TemplateResult } from 'lit'; import type { NuiType } from '../../types/nui-type.js'; import type { ImageFetchPriority, ImageFit, ImageLoading } from './types.js'; export interface NuiImageViewState { src: string; alt: string; width: string; height: string; fit: ImageFit | ''; loading: ImageLoading | ''; fetchpriority: ImageFetchPriority | ''; preview: boolean; imageClass: string; imageStyle: string; nuiType: NuiType; previewVisible: boolean; } export interface NuiImageRenderHandlers { onPreviewOpen: (event: Event) => void; onPreviewClose: (event: Event) => void; onDialogClose: (event: Event) => void; onError: (event: Event) => void; } export function getImageWrapperClass(): string { return 'nui-image'; } export function getImageClass(imageClass: string): string { return ['nui-image-img', imageClass].filter(Boolean).join(' '); } export function hasImageDimensions( state: Pick, ): boolean { return Boolean(state.width || state.height); } export function getImageInlineStyle( state: Pick, ): string { const styles: string[] = []; if (state.width) { styles.push(`width:${state.width}`); } if (state.height) { styles.push(`height:${state.height}`); } if (state.imageStyle) { styles.push(state.imageStyle); } return styles.join(';'); } export function renderImage( state: NuiImageViewState, handlers: NuiImageRenderHandlers, ): TemplateResult { const inlineStyle = getImageInlineStyle(state); const sized = hasImageDimensions(state); return html` ${state.alt ${ state.preview ? html` ` : nothing } ${ state.preview ? html` ${state.alt event.stopPropagation()} /> ` : nothing } `; }